]> granicus.if.org Git - libass/commitdiff
Treat -font/-subfont as Fontconfig pattern in libass.
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Sun, 8 Mar 2009 16:13:21 +0000 (16:13 +0000)
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Sun, 8 Mar 2009 16:13:21 +0000 (16:13 +0000)
Patch by Adrian Stutz (adrian sttz ch).

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

libass/ass_cache.c
libass/ass_font.c
libass/ass_font.h
libass/ass_fontconfig.c
libass/ass_fontconfig.h
libass/ass_mp.c
libass/ass_render.c
libass/ass_types.h

index 05618746069030881ceecfc4ebf46f0be8a8ebac..3b90e66e4ccf61435bfd744cfddb4a8c22768256 100644 (file)
@@ -192,6 +192,8 @@ static int font_compare(void* key1, void* key2, size_t key_size) {
                return 0;
        if (a->italic != b->italic)
                return 0;
+       if (a->treat_family_as_pattern != b->treat_family_as_pattern)
+               return 0;
        return 1;
 }
 
index f2214a345d0feddfd5f370d57219bb09985bc630..579e658f14d83d0e79018056f69a446695dc136c 100644 (file)
@@ -125,7 +125,7 @@ static int add_face(void* fc_priv, ass_font_t* font, uint32_t ch)
        if (font->n_faces == ASS_FONT_MAX_FACES)
                return -1;
        
-       path = fontconfig_select(fc_priv, font->desc.family, font->desc.bold,
+       path = fontconfig_select(fc_priv, font->desc.family, font->desc.treat_family_as_pattern, font->desc.bold,
                                              font->desc.italic, &index, ch);
 
        mem_idx = find_font(font->library, path);
@@ -169,6 +169,7 @@ ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_
        font.ftlibrary = ftlibrary;
        font.n_faces = 0;
        font.desc.family = strdup(desc->family);
+       font.desc.treat_family_as_pattern = desc->treat_family_as_pattern;
        font.desc.bold = desc->bold;
        font.desc.italic = desc->italic;
 
index 03396a6f21a7abb6c8246391a5aa9b7c0547ab27..520431821b6f9f961b4da47065b549aa422fa841 100644 (file)
@@ -33,6 +33,7 @@ typedef struct ass_font_desc_s {
        char* family;
        unsigned bold;
        unsigned italic;
+       int treat_family_as_pattern;
 } ass_font_desc_t;
 
 #define ASS_FONT_MAX_FACES 10
index 9a7bddecc42d90b499017124c06e55331d82ad94..9bdca86f31fb597b2bbf0007ab4d7893e9f3386a 100644 (file)
@@ -66,14 +66,15 @@ struct fc_instance_s {
  * \brief Low-level font selection.
  * \param priv private data
  * \param family font family
+ * \param treat_family_as_pattern treat family as fontconfig pattern
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
  * \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,
-                         uint32_t code)
+static char* _select_font(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+                         unsigned bold, unsigned italic, int* index, uint32_t code)
 {
        FcBool rc;
        FcResult result;
@@ -89,10 +90,15 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
        
        *index = 0;
 
-       pat = FcPatternCreate();
+       if (treat_family_as_pattern)
+               pat = FcNameParse((const FcChar8*)family);
+       else
+               pat = FcPatternCreate();
+
        if (!pat)
                goto error;
        
+       if (!treat_family_as_pattern) {
        FcPatternAddString(pat, FC_FAMILY, (const FcChar8*)family);
 
        // In SSA/ASS fonts are sometimes referenced by their "full name",
@@ -118,6 +124,7 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
                        }
                free(s);
        }
+       }
        FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
        FcPatternAddInteger(pat, FC_SLANT, italic);
        FcPatternAddInteger(pat, FC_WEIGHT, bold);
@@ -182,7 +189,8 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
        if (result != FcResultMatch)
                r_fullname = NULL;
 
-       if (!(r_family && strcasecmp((const char*)r_family, family) == 0) &&
+       if (!treat_family_as_pattern &&
+               !(r_family && strcasecmp((const char*)r_family, family) == 0) &&
            !(r_fullname && strcasecmp((const char*)r_fullname, family) == 0))
                mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_SelectedFontFamilyIsNotTheRequestedOne,
                       (const char*)(r_fullname ? r_fullname : r_family), family);
@@ -219,14 +227,15 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
  * \brief Find a font. Use default family or path if necessary.
  * \param priv_ private data
  * \param family font family
+ * \param treat_family_as_pattern treat family as fontconfig pattern
  * \param bold font weight value
  * \param italic font slant value
  * \param index out: font index inside a file
  * \param code: the character that should be present in the font, can be 0
  * \return font file path
 */ 
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-                       uint32_t code)
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+                       unsigned bold, unsigned italic, int* index, uint32_t code)
 {
        char* res = 0;
        if (!priv->config) {
@@ -234,9 +243,9 @@ char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold,
                return priv->path_default;
        }
        if (family && *family)
-               res = _select_font(priv, family, bold, italic, index, code);
+               res = _select_font(priv, family, treat_family_as_pattern, bold, italic, index, code);
        if (!res && priv->family_default) {
-               res = _select_font(priv, priv->family_default, bold, italic, index, code);
+               res = _select_font(priv, priv->family_default, 0, bold, italic, index, code);
                if (res)
                        mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingDefaultFontFamily, 
                                        family, bold, italic, res, *index);
@@ -248,7 +257,7 @@ char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold,
                       family, bold, italic, res, *index);
        }
        if (!res) {
-               res = _select_font(priv, "Arial", bold, italic, index, code);
+               res = _select_font(priv, "Arial", 0, bold, italic, index, code);
                if (res)
                        mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingArialFontFamily, 
                                        family, bold, italic, res, *index);
@@ -474,8 +483,8 @@ exit:
 
 #else /* CONFIG_FONTCONFIG */
 
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
-                       uint32_t code)
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern,
+                       unsigned bold, unsigned italic, int* index, uint32_t code)
 {
        *index = priv->index_default;
        return priv->path_default;
index e9a1ce15674eba81155a47400e90e90220ae3559..77806909cf6d1288e7e1e6edbcd1b63db9800096 100644 (file)
@@ -35,7 +35,7 @@
 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, int fc);
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index, uint32_t code);
+char* fontconfig_select(fc_instance_t* priv, const char* family, int treat_family_as_pattern, unsigned bold, unsigned italic, int* index, uint32_t code);
 void fontconfig_done(fc_instance_t* priv);
 
 #endif /* LIBASS_FONTCONFIG_H */
index 40da63c348e07449966fe746d2b0f8d5c09e915e..7e25b8e31603109b6c913791e2b6862cef0282ab 100644 (file)
@@ -94,6 +94,7 @@ ass_track_t* ass_default_track(ass_library_t* library) {
                style = track->styles + sid;
                style->Name = strdup("Default");
                style->FontName = (font_fontconfig >= 0 && sub_font_name) ? strdup(sub_font_name) : (font_fontconfig >= 0 && font_name) ? strdup(font_name) : strdup("Sans");
+               style->treat_fontname_as_pattern = 1;
 
                fs = track->PlayResY * text_font_scale_factor / 100.;
                // approximate autoscale coefficients
index dec08e519db91bac140b2bee696f92ef394b7a29..b561b2a82ac3af671e5d09236b31bbb41146c5ed 100644 (file)
@@ -184,6 +184,7 @@ typedef struct render_context_s {
        char* family;
        unsigned bold;
        unsigned italic;
+       int treat_family_as_pattern;
        
 } render_context_t;
 
@@ -676,6 +677,7 @@ static void update_font(void)
        ass_renderer_t* priv = frame_context.ass_priv;
        ass_font_desc_t desc;
        desc.family = strdup(render_context.family);
+       desc.treat_family_as_pattern = render_context.treat_family_as_pattern;
 
        val = render_context.bold;
        // 0 = normal, 1 = bold, >1 = exact weight
@@ -1359,6 +1361,7 @@ static void reset_render_context(void)
        if (render_context.family)
                free(render_context.family);
        render_context.family = strdup(render_context.style->FontName);
+       render_context.treat_family_as_pattern = render_context.style->treat_fontname_as_pattern;
        render_context.bold = render_context.style->Bold;
        render_context.italic = render_context.style->Italic;
        update_font();
index 52aff0fb851a6f342f5430cb742e0f9231c7035b..01c36c57483aa627cf2c134264faa01fe3496d39 100644 (file)
@@ -58,6 +58,7 @@ typedef struct ass_style_s {
        int MarginV;
 //        int AlphaLevel;
        int Encoding;
+       int treat_fontname_as_pattern;
 } ass_style_t;
 
 typedef struct render_priv_s render_priv_t;