Changeset - r24651:d256fd14817f
[Not reviewed]
master
0 3 0
Patric Stout - 3 years ago 2021-01-12 18:52:30
truebrain@openttd.org
Codechange: nobody was using "str" parameter, so remove it
3 files changed with 8 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/fontdetection.cpp
Show inline comments
 
@@ -344,13 +344,13 @@ static int CALLBACK EnumFontCallback(con
 
	const char *english_name = font_name;
 
#endif /* WITH_FREETYPE */
 

	
 
	PLOGFONT os_data = MallocT<LOGFONT>(1);
 
	*os_data = logfont->elfLogFont;
 
	info->callback->SetFontNames(info->settings, font_name, os_data);
 
	if (info->callback->FindMissingGlyphs(nullptr)) return 1;
 
	if (info->callback->FindMissingGlyphs()) 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)
 
{
 
@@ -474,27 +474,27 @@ bool SetFallbackFont(FreeTypeSettings *s
 
		/* There are some special fonts starting with an '.' and the last
 
		 * resort font that aren't usable. Skip them. */
 
		if (name[0] == '.' || strncmp(name, "LastResort", 10) == 0) continue;
 

	
 
		/* Save result. */
 
		callback->SetFontNames(settings, name);
 
		if (!callback->FindMissingGlyphs(nullptr)) {
 
		if (!callback->FindMissingGlyphs()) {
 
			DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name);
 
			result = true;
 
			break;
 
		}
 
	}
 

	
 
	if (!result) {
 
		/* For some OS versions, the font 'Arial Unicode MS' does not report all languages it
 
		 * supports. If we didn't find any other font, just try it, maybe we get lucky. */
 
		callback->SetFontNames(settings, "Arial Unicode MS");
 
		result = !callback->FindMissingGlyphs(nullptr);
 
		result = !callback->FindMissingGlyphs();
 
	}
 

	
 
	callback->FindMissingGlyphs(nullptr);
 
	callback->FindMissingGlyphs();
 
	return result;
 
}
 

	
 
#elif defined(WITH_FONTCONFIG) /* end ifdef __APPLE__ */
 

	
 
#include <fontconfig/fontconfig.h>
 
@@ -620,13 +620,13 @@ bool SetFallbackFont(FreeTypeSettings *s
 
			/* We want the fatter font as they look better at small sizes. */
 
			FcPatternGetInteger(font, FC_WEIGHT, 0, &value);
 
			if (value <= best_weight) continue;
 

	
 
			callback->SetFontNames(settings, (const char*)file);
 

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

	
 
			if (!missing) {
 
				best_weight = value;
 
				best_font   = (const char *)file;
 
			}
src/strings.cpp
Show inline comments
 
@@ -1995,29 +1995,26 @@ const char *GetCurrentLanguageIsoCode()
 
{
 
	return _langpack.langpack->isocode;
 
}
 

	
 
/**
 
 * Check whether there are glyphs missing in the current language.
 
 * @param[out] str Pointer to an address for storing the text pointer.
 
 * @return If glyphs are missing, return \c true, else return \c false.
 
 * @post If \c true is returned and str is not nullptr, *str points to a string that is found to contain at least one missing glyph.
 
 */
 
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
 
bool MissingGlyphSearcher::FindMissingGlyphs()
 
{
 
	InitFreeType(this->Monospace());
 
	const Sprite *question_mark[FS_END];
 

	
 
	for (FontSize size = this->Monospace() ? FS_MONO : FS_BEGIN; size < (this->Monospace() ? FS_END : FS_MONO); size++) {
 
		question_mark[size] = GetGlyph(size, '?');
 
	}
 

	
 
	this->Reset();
 
	for (const char *text = this->NextString(); text != nullptr; text = this->NextString()) {
 
		FontSize size = this->DefaultSize();
 
		if (str != nullptr) *str = text;
 
		for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
 
			if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
 
				size = (FontSize)(c - SCC_FIRST_FONT);
 
			} else if (!IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable(c) && !IsTextDirectionChar(c) && c != '?' && GetGlyph(size, c) == question_mark[size]) {
 
				/* The character is printable, but not in the normal font. This is the case we were testing for. */
 
				return true;
 
@@ -2092,13 +2089,13 @@ class LanguagePackGlyphSearcher : public
 
 *                  If nullptr the loaded language pack searcher is used.
 
 */
 
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
 
{
 
	static LanguagePackGlyphSearcher pack_searcher;
 
	if (searcher == nullptr) searcher = &pack_searcher;
 
	bool bad_font = !base_font || searcher->FindMissingGlyphs(nullptr);
 
	bool bad_font = !base_font || searcher->FindMissingGlyphs();
 
#if defined(WITH_FREETYPE) || defined(_WIN32)
 
	if (bad_font) {
 
		/* We found an unprintable character... lets try whether we can find
 
		 * a fallback font that can print the characters in the current language. */
 
		FreeTypeSettings backup;
 
		memcpy(&backup, &_freetype, sizeof(backup));
src/strings_func.h
Show inline comments
 
@@ -274,12 +274,12 @@ public:
 
	 * @param settings  The settings to modify.
 
	 * @param font_name The new font name.
 
	 * @param os_data Opaque pointer to OS-specific data.
 
	 */
 
	virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name, const void *os_data = nullptr) = 0;
 

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

	
 
void CheckForMissingGlyphs(bool base_font = true, MissingGlyphSearcher *search = nullptr);
 

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