From 10cd4a7e5a5043b826abdd6696fa267f942222b9 Mon Sep 17 00:00:00 2001 From: eugeni Date: Fri, 3 Aug 2007 13:43:11 +0000 Subject: 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. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24000 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libass/ass_font.c | 14 +++---------- libass/ass_font.h | 7 ------- libass/ass_fontconfig.c | 52 ++++++++++++++++--------------------------------- libass/ass_fontconfig.h | 6 +----- 4 files changed, 21 insertions(+), 58 deletions(-) (limited to 'libass') diff --git a/libass/ass_font.c b/libass/ass_font.c index 493a283175..a567a2ef30 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -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); } diff --git a/libass/ass_font.h b/libass/ass_font.h index 6d10ad18db..5aeaa49c29 100644 --- a/libass/ass_font.h +++ b/libass/ass_font.h @@ -21,10 +21,6 @@ #ifndef ASS_FONT_H #define ASS_FONT_H -#ifdef HAVE_FONTCONFIG -#include -#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); diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index e1579de4c4..c94434b70e 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -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) { diff --git a/libass/ass_fontconfig.h b/libass/ass_fontconfig.h index 30cd30dbf4..6acb528d3e 100644 --- a/libass/ass_fontconfig.h +++ b/libass/ass_fontconfig.h @@ -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 -- cgit v1.2.3