[MPlayer-cvslog] r24000 - in trunk/libass: ass_font.c ass_font.h ass_fontconfig.c ass_fontconfig.h

eugeni subversion at mplayerhq.hu
Fri Aug 3 15:43:11 CEST 2007


Author: eugeni
Date: Fri Aug  3 15:43:11 2007
New Revision: 24000

Log:
More simple and correct font reselection.

Since ass_font_t contains a list of font faces, there is no need to select the
face with maximum charset coverage each time. It is enough to select any face
with the required glyph.


Modified:
   trunk/libass/ass_font.c
   trunk/libass/ass_font.h
   trunk/libass/ass_fontconfig.c
   trunk/libass/ass_fontconfig.h

Modified: trunk/libass/ass_font.c
==============================================================================
--- trunk/libass/ass_font.c	(original)
+++ trunk/libass/ass_font.c	Fri Aug  3 15:43:11 2007
@@ -104,7 +104,7 @@ ass_font_t* ass_font_new(ass_library_t* 
 	if (fontp)
 		return fontp;
 	
-	path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index);
+	path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index, 0);
 	
 	mem_idx = find_font(library, path);
 	if (mem_idx >= 0) {
@@ -135,10 +135,6 @@ ass_font_t* ass_font_new(ass_library_t* 
 	font.v.x = font.v.y = 0;
 	font.size = 0.;
 
-#ifdef HAVE_FONTCONFIG
-	font.charset = FcCharSetCreate();
-#endif
-
 	return ass_font_cache_add(&font);
 }
 
@@ -208,8 +204,8 @@ static void ass_font_reselect(void* font
 	if (font->n_faces == ASS_FONT_MAX_FACES)
 		return;
 	
-	path = fontconfig_select_with_charset(fontconfig_priv, font->desc.family, font->desc.bold,
-					      font->desc.italic, &index, font->charset);
+	path = fontconfig_select(fontconfig_priv, font->desc.family, font->desc.bold,
+					      font->desc.italic, &index, ch);
 
 	error = FT_New_Face(font->ftlibrary, path, index, &face);
 	if (error) {
@@ -282,7 +278,6 @@ FT_Glyph ass_font_get_glyph(void* fontco
 	}
 
 #ifdef HAVE_FONTCONFIG
-	FcCharSetAddChar(font->charset, ch);
 	if (index == 0) {
 		mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_GlyphNotFoundReselectingFont,
 		       ch, font->desc.family, font->desc.bold, font->desc.italic);
@@ -359,8 +354,5 @@ void ass_font_free(ass_font_t* font)
 	for (i = 0; i < font->n_faces; ++i)
 		if (font->faces[i]) FT_Done_Face(font->faces[i]);
 	if (font->desc.family) free(font->desc.family);
-#ifdef HAVE_FONTCONFIG
-	if (font->charset) FcCharSetDestroy(font->charset);
-#endif
 	free(font);
 }

Modified: trunk/libass/ass_font.h
==============================================================================
--- trunk/libass/ass_font.h	(original)
+++ trunk/libass/ass_font.h	Fri Aug  3 15:43:11 2007
@@ -21,10 +21,6 @@
 #ifndef ASS_FONT_H
 #define ASS_FONT_H
 
-#ifdef HAVE_FONTCONFIG
-#include <fontconfig/fontconfig.h>
-#endif
-
 typedef struct ass_font_desc_s {
 	char* family;
 	unsigned bold;
@@ -41,9 +37,6 @@ typedef struct ass_font_s {
 	double scale_x, scale_y; // current transform
 	FT_Vector v; // current shift
 	double size;
-#ifdef HAVE_FONTCONFIG
-	FcCharSet* charset;
-#endif
 } ass_font_t;
 
 ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc);

Modified: trunk/libass/ass_fontconfig.c
==============================================================================
--- trunk/libass/ass_fontconfig.c	(original)
+++ trunk/libass/ass_fontconfig.c	Fri Aug  3 15:43:11 2007
@@ -57,11 +57,11 @@ struct fc_instance_s {
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
- * \param charset: contains the characters that should be present in the font, can be NULL
+ * \param code: the character that should be present in the font, can be 0
  * \return font file path
 */ 
 static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-			  FcCharSet* charset)
+			  uint32_t code)
 {
 	FcBool rc;
 	FcResult result;
@@ -71,7 +71,7 @@ static char* _select_font(fc_instance_t*
 	FcBool val_b;
 	FcCharSet* val_cs;
 	FcFontSet* fset = 0;
-	int curf, bestf, bestdiff = 0;
+	int curf;
 	char* retval = 0;
 	
 	*index = 0;
@@ -93,9 +93,6 @@ static char* _select_font(fc_instance_t*
 
 	fset = FcFontSort(priv->config, pat, FcTrue, NULL, &result);
 
-	bestf = -1;
-	if (charset)
-		bestdiff = FcCharSetCount(charset) + 1;
 	for (curf = 0; curf < fset->nfont; ++curf) {
 		rpat = fset->fonts[curf];
 		
@@ -104,29 +101,19 @@ static char* _select_font(fc_instance_t*
 			continue;
 		if (val_b != FcTrue)
 			continue;
-
-		if (charset) {
-			int diff;
-			result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
-			if (result != FcResultMatch)
-				continue;
-			diff = FcCharSetSubtractCount(charset, val_cs);
-			if (diff < bestdiff) {
-				bestdiff = diff;
-				bestf = curf;
-			}
- 			if (diff == 0)
-				break;
-		} else {
-			bestf = curf;
+		if (!code)
+			break;
+		result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
+		if (result != FcResultMatch)
+			continue;
+		if (FcCharSetHasChar(val_cs, code))
 			break;
-		}
 	}
 
-	if (bestf < 0)
+	if (curf >= fset->nfont)
 		goto error;
 
-	rpat = fset->fonts[bestf];
+	rpat = fset->fonts[curf];
 	
 	result = FcPatternGetInteger(rpat, FC_INDEX, 0, &val_i);
 	if (result != FcResultMatch)
@@ -159,17 +146,17 @@ static char* _select_font(fc_instance_t*
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
- * \param charset: contains the characters that should be present in the font, can be NULL
+ * \param code: the character that should be present in the font, can be 0
  * \return font file path
 */ 
-char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-			FcCharSet* charset)
+char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
+			uint32_t code)
 {
 	char* res = 0;
 	if (family && *family)
-		res = _select_font(priv, family, bold, italic, index, charset);
+		res = _select_font(priv, family, bold, italic, index, code);
 	if (!res && priv->family_default) {
-		res = _select_font(priv, priv->family_default, bold, italic, index, charset);
+		res = _select_font(priv, priv->family_default, bold, italic, index, code);
 		if (res)
 			mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingDefaultFontFamily, 
 					family, bold, italic, res, *index);
@@ -181,7 +168,7 @@ char* fontconfig_select_with_charset(fc_
 		       family, bold, italic, res, *index);
 	}
 	if (!res) {
-		res = _select_font(priv, "Arial", bold, italic, index, charset);
+		res = _select_font(priv, "Arial", bold, italic, index, code);
 		if (res)
 			mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingArialFontFamily, 
 					family, bold, italic, res, *index);
@@ -192,11 +179,6 @@ char* fontconfig_select_with_charset(fc_
 	return res;
 }
 
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
-{
-	return fontconfig_select_with_charset(priv, family, bold, italic, index, 0);
-}
-
 #if (FC_VERSION < 20402)
 static char* validate_fname(char* name)
 {

Modified: trunk/libass/ass_fontconfig.h
==============================================================================
--- trunk/libass/ass_fontconfig.h	(original)
+++ trunk/libass/ass_fontconfig.h	Fri Aug  3 15:43:11 2007
@@ -28,12 +28,8 @@
 typedef struct fc_instance_s fc_instance_t;
 
 fc_instance_t* fontconfig_init(ass_library_t* library, FT_Library ftlibrary, const char* family, const char* path);
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index);
+char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index, uint32_t code);
 void fontconfig_done(fc_instance_t* priv);
 
-#ifdef HAVE_FONTCONFIG
-char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index, FcCharSet* charset);
-#endif
-
 #endif
 



More information about the MPlayer-cvslog mailing list