Mercurial > mplayer.hg
annotate libass/ass_font.c @ 21624:78e06aec663a
Fix crashes in loader code: There is still some code that can not handle omitted frame pointers.
And next time think thrice before changing loader Makefiles!!!
author | reimar |
---|---|
date | Sat, 16 Dec 2006 23:59:06 +0000 |
parents | ef93ebaef504 |
children | 0d8005d2fe5c |
rev | line source |
---|---|
21277 | 1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*- |
2 // vim:ts=8:sw=8:noet:ai: | |
3 /* | |
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> | |
5 | |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software | |
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 */ | |
20 | |
21 #include "config.h" | |
22 | |
23 #include <inttypes.h> | |
24 #include <ft2build.h> | |
25 #include FT_FREETYPE_H | |
26 #include FT_SYNTHESIS_H | |
27 #include FT_GLYPH_H | |
28 | |
21458
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
21351
diff
changeset
|
29 #include "ass.h" |
7af6c25a0cfc
Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents:
21351
diff
changeset
|
30 #include "ass_library.h" |
21277 | 31 #include "ass_font.h" |
21321
7b7627ff1937
Move ass_font_desc_t and ass_font_t declarations to ass_font.h.
eugeni
parents:
21320
diff
changeset
|
32 #include "ass_bitmap.h" |
7b7627ff1937
Move ass_font_desc_t and ass_font_t declarations to ass_font.h.
eugeni
parents:
21320
diff
changeset
|
33 #include "ass_cache.h" |
21277 | 34 #include "ass_fontconfig.h" |
35 #include "mputils.h" | |
36 | |
37 /** | |
38 * Select Microfost Unicode CharMap, if the font has one. | |
39 * Otherwise, let FreeType decide. | |
40 */ | |
41 static void charmap_magic(FT_Face face) | |
42 { | |
43 int i; | |
44 for (i = 0; i < face->num_charmaps; ++i) { | |
45 FT_CharMap cmap = face->charmaps[i]; | |
46 unsigned pid = cmap->platform_id; | |
47 unsigned eid = cmap->encoding_id; | |
48 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) { | |
49 FT_Set_Charmap(face, cmap); | |
50 break; | |
51 } | |
52 } | |
53 } | |
54 | |
21460 | 55 static int find_font(ass_library_t* library, char* name) |
56 { | |
57 int i; | |
58 for (i = 0; i < library->num_fontdata; ++i) | |
59 if (strcasecmp(name, library->fontdata[i].name) == 0) | |
60 return i; | |
61 return -1; | |
62 } | |
63 | |
64 ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc) | |
21277 | 65 { |
66 char* path; | |
67 int index; | |
68 FT_Face face; | |
69 int error; | |
21317 | 70 ass_font_t* font; |
21460 | 71 int mem_idx; |
21317 | 72 |
73 font = ass_font_cache_find(desc); | |
74 if (font) | |
75 return font; | |
21277 | 76 |
77 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index); | |
78 | |
21460 | 79 mem_idx = find_font(library, path); |
80 if (mem_idx >= 0) { | |
21615
62989854d340
Avoid "pointer targets differ in signedness" warnings.
eugeni
parents:
21614
diff
changeset
|
81 error = FT_New_Memory_Face(ftlibrary, (unsigned char*)library->fontdata[mem_idx].data, |
21460 | 82 library->fontdata[mem_idx].size, 0, &face); |
83 if (error) { | |
84 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningMemoryFont, path); | |
85 return 0; | |
86 } | |
87 } else { | |
21620 | 88 error = FT_New_Face(ftlibrary, path, index, &face); |
89 if (error) { | |
90 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); | |
91 return 0; | |
92 } | |
21460 | 93 } |
21277 | 94 |
95 charmap_magic(face); | |
96 | |
21317 | 97 font = calloc(1, sizeof(ass_font_t)); |
21349 | 98 font->ftlibrary = ftlibrary; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
99 font->faces[0] = face; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
100 font->n_faces = 1; |
21277 | 101 font->desc.family = strdup(desc->family); |
102 font->desc.bold = desc->bold; | |
103 font->desc.italic = desc->italic; | |
104 | |
105 font->m.xx = font->m.yy = (FT_Fixed)0x10000L; | |
106 font->m.xy = font->m.yy = 0; | |
107 font->v.x = font->v.y = 0; | |
21314 | 108 font->size = 0; |
21277 | 109 |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
110 #ifdef HAVE_FONTCONFIG |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
111 font->charset = FcCharSetCreate(); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
112 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
113 |
21317 | 114 ass_font_cache_add(font); |
115 | |
116 return font; | |
21277 | 117 } |
118 | |
119 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v) | |
120 { | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
121 int i; |
21616
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
122 font->m.xx = m->xx; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
123 font->m.xy = m->xy; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
124 font->m.yx = m->yx; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
125 font->m.yy = m->yy; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
126 font->v.x = v->x; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
127 font->v.y = v->y; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
128 for (i = 0; i < font->n_faces; ++i) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
129 FT_Set_Transform(font->faces[i], &font->m, &font->v); |
21277 | 130 } |
131 | |
132 void ass_font_set_size(ass_font_t* font, int size) | |
133 { | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
134 int i; |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
135 if (font->size != size) { |
21320 | 136 font->size = size; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
137 for (i = 0; i < font->n_faces; ++i) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
138 FT_Set_Pixel_Sizes(font->faces[i], 0, size); |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
139 } |
21277 | 140 } |
141 | |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
142 #ifdef HAVE_FONTCONFIG |
21618
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
143 static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font, uint32_t ch) |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
144 { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
145 char* path; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
146 int index; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
147 FT_Face face; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
148 int error; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
149 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
150 if (font->n_faces == ASS_FONT_MAX_FACES) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
151 return; |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
152 |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
153 path = fontconfig_select_with_charset(fontconfig_priv, font->desc.family, font->desc.bold, |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
154 font->desc.italic, &index, font->charset); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
155 |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
156 error = FT_New_Face(font->ftlibrary, path, index, &face); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
157 if (error) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
158 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
159 return; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
160 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
161 charmap_magic(face); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
162 |
21618
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
163 error = FT_Get_Char_Index(face, ch); |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
164 if (error == 0) { // the new font face is not better then the old one |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
165 FT_Done_Face(face); |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
166 return; |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
167 } |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
168 |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
169 font->faces[font->n_faces++] = face; |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
170 |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
171 FT_Set_Transform(face, &font->m, &font->v); |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
172 FT_Set_Pixel_Sizes(face, 0, font->size); |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
173 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
174 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
175 |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
176 void ass_font_get_asc_desc(ass_font_t* font, uint32_t ch, int* asc, int* desc) |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
177 { |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
178 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
179 for (i = 0; i < font->n_faces; ++i) { |
21620 | 180 FT_Face face = font->faces[i]; |
181 if (FT_Get_Char_Index(face, ch)) { | |
182 int v, v2; | |
183 v = face->size->metrics.ascender; | |
184 v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale); | |
185 *asc = (v > v2 * 0.9) ? v : v2; | |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
186 |
21620 | 187 v = - face->size->metrics.descender; |
188 v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale); | |
189 *desc = (v > v2 * 0.9) ? v : v2; | |
190 return; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
191 } |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
192 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
193 |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
194 *asc = *desc = 0; |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
195 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
196 |
21277 | 197 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch) |
198 { | |
199 int error; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
200 int index = 0; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
201 int i; |
21277 | 202 FT_Glyph glyph; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
203 FT_Face face = 0; |
21350 | 204 |
205 if (ch < 0x20) | |
206 return 0; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
207 if (font->n_faces == 0) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
208 return 0; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
209 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
210 for (i = 0; i < font->n_faces; ++i) { |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
211 face = font->faces[i]; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
212 index = FT_Get_Char_Index(face, ch); |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
213 if (index) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
214 break; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
215 } |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
216 |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
217 #ifdef HAVE_FONTCONFIG |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
218 FcCharSetAddChar(font->charset, ch); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
219 if (index == 0) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
220 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_LIBASS_GlyphNotFoundReselectingFont, |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
221 ch, font->desc.family, font->desc.bold, font->desc.italic); |
21618
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
222 ass_font_reselect(fontconfig_priv, font, ch); |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
223 face = font->faces[font->n_faces - 1]; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
224 index = FT_Get_Char_Index(face, ch); |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
225 if (index == 0) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
226 mp_msg(MSGT_ASS, MSGL_ERR, MSGTR_LIBASS_GlyphNotFound, |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
227 ch, font->desc.family, font->desc.bold, font->desc.italic); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
228 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
229 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
230 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
231 |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
232 error = FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP ); |
21277 | 233 if (error) { |
234 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
235 return 0; | |
236 } | |
237 | |
238 #if (FREETYPE_MAJOR > 2) || \ | |
239 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \ | |
240 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10)) | |
241 // FreeType >= 2.1.10 required | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
242 if (!(face->style_flags & FT_STYLE_FLAG_ITALIC) && |
21277 | 243 (font->desc.italic > 55)) { |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
244 FT_GlyphSlot_Oblique(face->glyph); |
21277 | 245 } |
246 #endif | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
247 error = FT_Get_Glyph(face->glyph, &glyph); |
21277 | 248 if (error) { |
249 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
250 return 0; | |
251 } | |
252 | |
253 return glyph; | |
254 } | |
255 | |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
256 FT_Vector ass_font_get_kerning(ass_font_t* font, uint32_t c1, uint32_t c2) |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
257 { |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
258 FT_Vector v = {0, 0}; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
259 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
260 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
261 for (i = 0; i < font->n_faces; ++i) { |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
262 FT_Face face = font->faces[i]; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
263 int i1 = FT_Get_Char_Index(face, c1); |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
264 int i2 = FT_Get_Char_Index(face, c2); |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
265 if (i1 && i2) { |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
266 if (FT_HAS_KERNING(face)) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
267 FT_Get_Kerning(face, i1, i2, FT_KERNING_DEFAULT, &v); |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
268 return v; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
269 } |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
270 if (i1 || i2) // these glyphs are from different font faces, no kerning information |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
271 return v; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
272 } |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
273 return v; |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
274 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
275 |
21277 | 276 void ass_font_free(ass_font_t* font) |
277 { | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
278 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
279 for (i = 0; i < font->n_faces; ++i) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
280 if (font->faces[i]) FT_Done_Face(font->faces[i]); |
21277 | 281 if (font->desc.family) free(font->desc.family); |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
282 #ifdef HAVE_FONTCONFIG |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
283 if (font->charset) FcCharSetDestroy(font->charset); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
284 #endif |
21317 | 285 free(font); |
21277 | 286 } |