Changeset - r18415:6464fa585e60
[Not reviewed]
master
0 3 0
rubidium - 13 years ago 2011-11-19 21:02:37
rubidium@openttd.org
(svn r23267) -Codechange: unify the font name setting of the font cache
3 files changed with 21 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -344,15 +344,13 @@ static int CALLBACK EnumFontCallback(con
 
		FT_Done_FreeType(_library);
 
		_library = NULL;
 
	}
 

	
 
	if (!found) return 1;
 

	
 
	strecpy(info->settings->small_font,  font_name, lastof(info->settings->small_font));
 
	strecpy(info->settings->medium_font, font_name, lastof(info->settings->medium_font));
 
	strecpy(info->settings->large_font,  font_name, lastof(info->settings->large_font));
 
	callback->SetFontNames(info->settings, font_name);
 
	if (info->callback->FindMissingGlyphs(NULL)) return 1;
 
	DEBUG(freetype, 1, "Fallback font: %s (%s)", font_name, english_name);
 
	return 0; // stop enumerating
 
}
 

	
 
bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
 
@@ -484,15 +482,13 @@ bool SetFallbackFont(FreeTypeSettings *s
 
						/* Skip some inappropriate or ugly looking fonts that have better alternatives. */
 
						if (strncmp(name, "Courier", 7) == 0 || strncmp(name, "Apple Symbols", 13) == 0 ||
 
								strncmp(name, ".Aqua", 5) == 0 || strncmp(name, "LastResort", 10) == 0 ||
 
								strncmp(name, "GB18030 Bitmap", 14) == 0) continue;
 

	
 
						/* Save result. */
 
						strecpy(settings->small_font,  name, lastof(settings->small_font));
 
						strecpy(settings->medium_font, name, lastof(settings->medium_font));
 
						strecpy(settings->large_font,  name, lastof(settings->large_font));
 
						callback->SetFontNames(settings, name);
 
						DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name);
 
						result = true;
 
						break;
 
					}
 
				}
 
				CFRelease(langs);
 
@@ -571,15 +567,13 @@ bool SetFallbackFont(FreeTypeSettings *s
 
			 * to leave space for a \0 and terminate it ourselves. */
 
			char name[128];
 
			ATSUFindFontName(font, kFontUniqueName, kFontNoPlatformCode, kFontNoScriptCode, kFontNoLanguageCode, 127, name, &act_len, NULL);
 
			name[act_len > 127 ? 127 : act_len] = '\0';
 

	
 
			/* Save Result. */
 
			strecpy(settings->small_font,  name, lastof(settings->small_font));
 
			strecpy(settings->medium_font, name, lastof(settings->medium_font));
 
			strecpy(settings->large_font,  name, lastof(settings->large_font));
 
			callback->SetFontNames(settings, name);
 
			DEBUG(freetype, 2, "ATSUI-Font for %s: %s", language_isocode, name);
 
			result = true;
 
		}
 

	
 
		ATSUDisposeTextLayout(text_layout);
 
		ATSUDisposeStyle(style);
 
@@ -595,15 +589,13 @@ bool SetFallbackFont(FreeTypeSettings *s
 
		 * substitute the latter for the former if it is loadable. */
 
		bool ft_init = _library != NULL;
 
		FT_Face face;
 
		/* Init FreeType if needed. */
 
		if ((ft_init || FT_Init_FreeType(&_library) == FT_Err_Ok) && GetFontByFaceName("Arial Unicode MS", &face) == FT_Err_Ok) {
 
			FT_Done_Face(face);
 
			strecpy(settings->small_font,  "Arial Unicode MS", lastof(settings->small_font));
 
			strecpy(settings->medium_font, "Arial Unicode MS", lastof(settings->medium_font));
 
			strecpy(settings->large_font,  "Arial Unicode MS", lastof(settings->large_font));
 
			callback->SetFontNames(settings, "Arial Unicode MS");
 
			DEBUG(freetype, 1, "Replacing font 'Geeza Pro' with 'Arial Unicode MS'");
 
		}
 
		if (!ft_init) {
 
			/* Uninit FreeType if we did the init. */
 
			FT_Done_FreeType(_library);
 
			_library = NULL;
 
@@ -716,15 +708,13 @@ bool SetFallbackFont(FreeTypeSettings *s
 
			FcChar8 *file = NULL;
 
			FcResult res = FcPatternGetString(font, FC_FILE, 0, &file);
 
			if (res != FcResultMatch || file == NULL) {
 
				continue;
 
			}
 

	
 
			strecpy(settings->small_font,  (const char*)file, lastof(settings->small_font));
 
			strecpy(settings->medium_font, (const char*)file, lastof(settings->medium_font));
 
			strecpy(settings->large_font,  (const char*)file, lastof(settings->large_font));
 
			callback->SetFontNames(settings, (const char*)file);
 

	
 
			bool missing = callback->FindMissingGlyphs(NULL);
 
			DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no");
 

	
 
			if (!missing) {
 
				ret = true;
src/strings.cpp
Show inline comments
 
@@ -1795,18 +1795,18 @@ class LanguagePackGlyphSearcher : public
 
	/* virtual */ void Reset()
 
	{
 
		this->i = 0;
 
		this->j = 0;
 
	}
 

	
 
	FontSize DefaultSize()
 
	/* virtual */ FontSize DefaultSize()
 
	{
 
		return FS_NORMAL;
 
	}
 

	
 
	const char *NextString()
 
	/* virtual */ const char *NextString()
 
	{
 
		if (this->i >= 32) return NULL;
 

	
 
		const char *ret = _langpack_offs[_langtab_start[i] + j];
 

	
 
		this->j++;
 
@@ -1814,12 +1814,19 @@ class LanguagePackGlyphSearcher : public
 
			i++;
 
			j = 0;
 
		}
 

	
 
		return ret;
 
	}
 

	
 
	/* virtual */ void SetFontNames(FreeTypeSettings *settings, const char *font_name)
 
	{
 
		strecpy(settings->small_font,  font_name, lastof(settings->small_font));
 
		strecpy(settings->medium_font, font_name, lastof(settings->medium_font));
 
		strecpy(settings->large_font,  font_name, lastof(settings->large_font));
 
	}
 
};
 

	
 
/**
 
 * Check whether the currently loaded language pack
 
 * uses characters that the currently loaded font
 
 * does not support. If this is the case an error
src/strings_func.h
Show inline comments
 
@@ -219,12 +219,19 @@ public:
 

	
 
	/**
 
	 * Reset the search, i.e. begin from the beginning again.
 
	 */
 
	virtual void Reset() = 0;
 

	
 
	/**
 
	 * Set the right font names.
 
	 * @param settings  The settings to modify.
 
	 * @param font_name The new font name.
 
	 */
 
	virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0;
 

	
 
	bool FindMissingGlyphs(const char **str);
 
};
 

	
 
void CheckForMissingGlyphsInLoadedLanguagePack(bool base_font = true);
 

	
 
#endif /* STRINGS_FUNC_H */
0 comments (0 inline, 0 general)