Mercurial > mplayer.hg
comparison libass/ass_font.c @ 21618:8111d4625194
Avoid storing font file path and index in ass_font_t.
author | eugeni |
---|---|
date | Sat, 16 Dec 2006 19:29:33 +0000 |
parents | 2704273f398d |
children | b4b51eb2904f |
comparison
equal
deleted
inserted
replaced
21617:10f001e35b91 | 21618:8111d4625194 |
---|---|
94 | 94 |
95 charmap_magic(face); | 95 charmap_magic(face); |
96 | 96 |
97 font = calloc(1, sizeof(ass_font_t)); | 97 font = calloc(1, sizeof(ass_font_t)); |
98 font->ftlibrary = ftlibrary; | 98 font->ftlibrary = ftlibrary; |
99 font->path = strdup(path); | |
100 font->index = index; | |
101 font->face = face; | 99 font->face = face; |
102 font->desc.family = strdup(desc->family); | 100 font->desc.family = strdup(desc->family); |
103 font->desc.bold = desc->bold; | 101 font->desc.bold = desc->bold; |
104 font->desc.italic = desc->italic; | 102 font->desc.italic = desc->italic; |
105 | 103 |
135 FT_Set_Pixel_Sizes(font->face, 0, size); | 133 FT_Set_Pixel_Sizes(font->face, 0, size); |
136 } | 134 } |
137 } | 135 } |
138 | 136 |
139 #ifdef HAVE_FONTCONFIG | 137 #ifdef HAVE_FONTCONFIG |
140 static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font) | 138 static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font, uint32_t ch) |
141 { | 139 { |
142 char* path; | 140 char* path; |
143 int index; | 141 int index; |
144 FT_Face face; | 142 FT_Face face; |
145 int error; | 143 int error; |
146 | 144 |
147 path = fontconfig_select_with_charset(fontconfig_priv, font->desc.family, font->desc.bold, | 145 path = fontconfig_select_with_charset(fontconfig_priv, font->desc.family, font->desc.bold, |
148 font->desc.italic, &index, font->charset); | 146 font->desc.italic, &index, font->charset); |
149 if (strcasecmp(path, font->path) == 0 && index == font->index) { | |
150 free(path); | |
151 return; | |
152 } | |
153 | 147 |
154 error = FT_New_Face(font->ftlibrary, path, index, &face); | 148 error = FT_New_Face(font->ftlibrary, path, index, &face); |
155 if (error) { | 149 if (error) { |
156 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); | 150 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); |
157 return; | 151 return; |
158 } | 152 } |
159 charmap_magic(face); | 153 charmap_magic(face); |
160 | 154 |
155 error = FT_Get_Char_Index(face, ch); | |
156 if (error == 0) { // the new font face is not better then the old one | |
157 FT_Done_Face(face); | |
158 return; | |
159 } | |
160 | |
161 if (font->face) FT_Done_Face(font->face); | 161 if (font->face) FT_Done_Face(font->face); |
162 free(font->path); | |
163 | 162 |
164 font->face = face; | 163 font->face = face; |
165 font->path = strdup(path); | |
166 font->index = index; | |
167 | 164 |
168 FT_Set_Transform(font->face, &font->m, &font->v); | 165 FT_Set_Transform(font->face, &font->m, &font->v); |
169 FT_Set_Pixel_Sizes(font->face, 0, font->size); | 166 FT_Set_Pixel_Sizes(font->face, 0, font->size); |
170 } | 167 } |
171 #endif | 168 #endif |
201 #ifdef HAVE_FONTCONFIG | 198 #ifdef HAVE_FONTCONFIG |
202 FcCharSetAddChar(font->charset, ch); | 199 FcCharSetAddChar(font->charset, ch); |
203 if (index == 0) { | 200 if (index == 0) { |
204 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_GlyphNotFoundReselectingFont, | 201 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_GlyphNotFoundReselectingFont, |
205 ch, font->desc.family, font->desc.bold, font->desc.italic); | 202 ch, font->desc.family, font->desc.bold, font->desc.italic); |
206 ass_font_reselect(fontconfig_priv, font); | 203 ass_font_reselect(fontconfig_priv, font, ch); |
207 index = FT_Get_Char_Index(font->face, ch); | 204 index = FT_Get_Char_Index(font->face, ch); |
208 if (index == 0) { | 205 if (index == 0) { |
209 mp_msg(MSGT_ASS, MSGL_ERR, MSGTR_LIBASS_GlyphNotFound, | 206 mp_msg(MSGT_ASS, MSGL_ERR, MSGTR_LIBASS_GlyphNotFound, |
210 ch, font->desc.family, font->desc.bold, font->desc.italic); | 207 ch, font->desc.family, font->desc.bold, font->desc.italic); |
211 } | 208 } |
251 } | 248 } |
252 | 249 |
253 void ass_font_free(ass_font_t* font) | 250 void ass_font_free(ass_font_t* font) |
254 { | 251 { |
255 if (font->face) FT_Done_Face(font->face); | 252 if (font->face) FT_Done_Face(font->face); |
256 if (font->path) free(font->path); | |
257 if (font->desc.family) free(font->desc.family); | 253 if (font->desc.family) free(font->desc.family); |
258 #ifdef HAVE_FONTCONFIG | 254 #ifdef HAVE_FONTCONFIG |
259 if (font->charset) FcCharSetDestroy(font->charset); | 255 if (font->charset) FcCharSetDestroy(font->charset); |
260 #endif | 256 #endif |
261 free(font); | 257 free(font); |