Changeset - r5240:082c55cc478b
[Not reviewed]
master
0 1 0
Darkvater - 18 years ago 2006-12-04 18:57:09
darkvater@openttd.org
(svn r7362) -Fix (r7337): Free the freetype face after any possible error. For win32 do not use the
last font in the registry if no suitable font is found.
1 file changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
fontcache.c
Show inline comments
 
@@ -65,13 +65,13 @@ static FT_Error GetFontByFaceName(const 
 
	for (index = 0;; index++) {
 
		char *s;
 
		DWORD vbuflen = lengthof(vbuffer);
 
		DWORD dbuflen = lengthof(dbuffer);
 

	
 
		ret = RegEnumValue(hKey, index, vbuffer, &vbuflen, NULL, NULL, dbuffer, &dbuflen);
 
		if (ret != ERROR_SUCCESS) break;
 
		if (ret != ERROR_SUCCESS) goto registry_no_font_found;
 

	
 
		/* The font names in the registry are of the following 3 forms:
 
		 * - ADMUI3.fon
 
		 * - Book Antiqua Bold (TrueType)
 
		 * - Batang & BatangChe & Gungsuh & GungsuhChe (TrueType)
 
		 * We will strip the font-type '()' if any and work with the font name
 
@@ -94,13 +94,13 @@ static FT_Error GetFontByFaceName(const 
 
		goto folder_error;
 
	}
 

	
 
	/* Some fonts are contained in .ttc files, TrueType Collection fonts. These
 
	 * contain multiple fonts inside this single file. GetFontData however
 
	 * returns the whole file, so we need to check each font inside to get the
 
	 * proper font. If not found, we will use the last font in the ttc.
 
	 * proper font.
 
	 * Also note that FreeType does not support UNICODE filesnames! */
 
#if defined(UNICODE)
 
	font_path = malloc(MAX_PATH);
 
	font_path = convert_from_fs(vbuffer, font_path, MAX_PATH);
 
#else
 
	font_path = vbuffer;
 
@@ -120,12 +120,13 @@ static FT_Error GetFontByFaceName(const 
 

	
 
#if defined(UNICODE)
 
	free(font_path);
 
#endif
 

	
 
folder_error:
 
registry_no_font_found:
 
	RegCloseKey(hKey);
 
	return err;
 
}
 
#else
 
# ifdef WITH_FONTCONFIG
 
static FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
 
@@ -238,16 +239,16 @@ static void LoadFreeTypeFont(const char 
 

	
 
			if (found != NULL) {
 
				error = FT_Set_Charmap(*face, found);
 
				if (error == FT_Err_Ok) return;
 
			}
 
		}
 
	}
 

	
 
		FT_Done_Face(*face);
 
		*face = NULL;
 
	}
 
	FT_Done_Face(*face);
 
	*face = NULL;
 

	
 
	ShowInfoF("Unable to use '%s' for %s font, FreeType reported error 0x%X, using sprite font instead", font_name, type, error);
 
}
 

	
 

	
 
void InitFreeType(void)
0 comments (0 inline, 0 general)