]> granicus.if.org Git - libass/commitdiff
More simple and correct font reselection.
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Fri, 3 Aug 2007 13:43:11 +0000 (13:43 +0000)
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Fri, 3 Aug 2007 13:43:11 +0000 (13:43 +0000)
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.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24000 b3059339-0415-0410-9bf9-f77b7e298cf2

libass/ass_font.c
libass/ass_font.h
libass/ass_fontconfig.c
libass/ass_fontconfig.h

index 493a2831755090dd85b7203cc5f97c84fc3c4098..a567a2ef30eafba6d531b1c9d33a5f3c15c3f3cf 100644 (file)
@@ -104,7 +104,7 @@ ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_
        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* library, FT_Library ftlibrary, void* fc_
        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* fontconfig_priv, ass_font_t* font, uint32_t
        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* fontconfig_priv, ass_font_t* font, uint32_t ch
        }
 
 #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);
 }
index 6d10ad18db429d39f24ae9b87b2c07f2d974ed1b..5aeaa49c29505e4239a051716ef830d540b89a24 100644 (file)
 #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);
index e1579de4c48c3bf560867872d5240befe553c418..c94434b70e35478f9e108f8cc1212626504558c9 100644 (file)
@@ -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* priv, const char* family, unsigned bold
        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* priv, const char* family, unsigned bold
 
        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* priv, const char* family, unsigned bold
                        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* priv, const char* family, unsigned bold
  * \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_instance_t* priv, const char* family, un
                       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_instance_t* priv, const char* family, un
        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)
 {
index 30cd30dbf4d513c5ae0af618f40a6ed48ff9ba94..6acb528d3e12f01edb739764fcb46c95abcb9b33 100644 (file)
 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