Mercurial > mplayer.hg
annotate libass/ass_font.c @ 23299:0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
Rotations are not needed here (they are performed in transform3d) and they
disable autohinter.
author | eugeni |
---|---|
date | Mon, 14 May 2007 20:24:53 +0000 |
parents | c932f521344d |
children | 04dbd42b3962 |
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" |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
35 #include "ass_utils.h" |
21277 | 36 #include "mputils.h" |
37 | |
38 /** | |
39 * Select Microfost Unicode CharMap, if the font has one. | |
40 * Otherwise, let FreeType decide. | |
41 */ | |
42 static void charmap_magic(FT_Face face) | |
43 { | |
44 int i; | |
45 for (i = 0; i < face->num_charmaps; ++i) { | |
46 FT_CharMap cmap = face->charmaps[i]; | |
47 unsigned pid = cmap->platform_id; | |
48 unsigned eid = cmap->encoding_id; | |
49 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) { | |
50 FT_Set_Charmap(face, cmap); | |
22210
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
51 return; |
21277 | 52 } |
53 } | |
22210
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
54 |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
55 if (!face->charmap) { |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
56 if (face->num_charmaps == 0) { |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
57 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_NoCharmaps); |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
58 return; |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
59 } |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
60 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_NoCharmapAutodetected); |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
61 FT_Set_Charmap(face, face->charmaps[0]); |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
62 return; |
4a958bd08920
Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents:
21630
diff
changeset
|
63 } |
21277 | 64 } |
65 | |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
66 static void update_transform(ass_font_t* font) |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
67 { |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
68 int i; |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
69 FT_Matrix m; |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
70 m.xx = double_to_d16(font->scale_x); |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
71 m.yy = double_to_d16(font->scale_y); |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
72 m.xy = m.yx = 0; |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
73 for (i = 0; i < font->n_faces; ++i) |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
74 FT_Set_Transform(font->faces[i], &m, &font->v); |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
75 } |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
76 |
21630 | 77 /** |
78 * \brief find a memory font by name | |
79 */ | |
21460 | 80 static int find_font(ass_library_t* library, char* name) |
81 { | |
82 int i; | |
83 for (i = 0; i < library->num_fontdata; ++i) | |
84 if (strcasecmp(name, library->fontdata[i].name) == 0) | |
85 return i; | |
86 return -1; | |
87 } | |
88 | |
21630 | 89 /** |
90 * \brief Create a new ass_font_t according to "desc" argument | |
91 */ | |
21460 | 92 ass_font_t* ass_font_new(ass_library_t* library, FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc) |
21277 | 93 { |
94 char* path; | |
95 int index; | |
96 FT_Face face; | |
97 int error; | |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
98 ass_font_t* fontp; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
99 ass_font_t font; |
21460 | 100 int mem_idx; |
21317 | 101 |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
102 fontp = ass_font_cache_find(desc); |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
103 if (fontp) |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
104 return fontp; |
21277 | 105 |
106 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index); | |
107 | |
21460 | 108 mem_idx = find_font(library, path); |
109 if (mem_idx >= 0) { | |
21615
62989854d340
Avoid "pointer targets differ in signedness" warnings.
eugeni
parents:
21614
diff
changeset
|
110 error = FT_New_Memory_Face(ftlibrary, (unsigned char*)library->fontdata[mem_idx].data, |
21460 | 111 library->fontdata[mem_idx].size, 0, &face); |
112 if (error) { | |
113 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningMemoryFont, path); | |
114 return 0; | |
115 } | |
116 } else { | |
21620 | 117 error = FT_New_Face(ftlibrary, path, index, &face); |
118 if (error) { | |
119 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); | |
120 return 0; | |
121 } | |
21460 | 122 } |
21277 | 123 |
124 charmap_magic(face); | |
125 | |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
126 font.ftlibrary = ftlibrary; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
127 font.faces[0] = face; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
128 font.n_faces = 1; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
129 font.desc.family = strdup(desc->family); |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
130 font.desc.bold = desc->bold; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
131 font.desc.italic = desc->italic; |
21277 | 132 |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
133 font.scale_x = font.scale_y = 1.; |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
134 font.v.x = font.v.y = 0; |
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
135 font.size = 0; |
21277 | 136 |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
137 #ifdef HAVE_FONTCONFIG |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
138 font.charset = FcCharSetCreate(); |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
139 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
140 |
23212
c932f521344d
In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents:
23134
diff
changeset
|
141 return ass_font_cache_add(&font); |
21277 | 142 } |
143 | |
21630 | 144 /** |
145 * \brief Set font transformation matrix and shift vector | |
146 **/ | |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
147 void ass_font_set_transform(ass_font_t* font, double scale_x, double scale_y, FT_Vector* v) |
21277 | 148 { |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
149 font->scale_x = scale_x; |
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
150 font->scale_y = scale_y; |
21616
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
151 font->v.x = v->x; |
2704273f398d
FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents:
21615
diff
changeset
|
152 font->v.y = v->y; |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
153 update_transform(font); |
21277 | 154 } |
155 | |
21630 | 156 /** |
157 * \brief Set font size | |
158 **/ | |
21277 | 159 void ass_font_set_size(ass_font_t* font, int size) |
160 { | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
161 int i; |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
162 if (font->size != size) { |
21320 | 163 font->size = size; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
164 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
|
165 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
|
166 } |
21277 | 167 } |
168 | |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
169 #ifdef HAVE_FONTCONFIG |
21630 | 170 /** |
171 * \brief Select a new FT_Face with the given character | |
172 * The new face is added to the end of font->faces. | |
173 **/ | |
21618
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
174 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
|
175 { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
176 char* path; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
177 int index; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
178 FT_Face face; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
179 int error; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
180 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
181 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
|
182 return; |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
183 |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
184 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
|
185 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
|
186 |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
187 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
|
188 if (error) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
189 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
|
190 return; |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
191 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
192 charmap_magic(face); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
193 |
21618
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
194 error = FT_Get_Char_Index(face, ch); |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
195 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
|
196 FT_Done_Face(face); |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
197 return; |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
198 } |
8111d4625194
Avoid storing font file path and index in ass_font_t.
eugeni
parents:
21616
diff
changeset
|
199 |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
200 font->faces[font->n_faces++] = face; |
23299
0ee56ec36a40
Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents:
23212
diff
changeset
|
201 update_transform(font); |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
202 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
|
203 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
204 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
205 |
21630 | 206 /** |
207 * \brief Get maximal font ascender and descender. | |
208 * \param ch character code | |
209 * The values are extracted from the font face that provides glyphs for the given character | |
210 **/ | |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
211 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
|
212 { |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
213 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
214 for (i = 0; i < font->n_faces; ++i) { |
21620 | 215 FT_Face face = font->faces[i]; |
216 if (FT_Get_Char_Index(face, ch)) { | |
217 int v, v2; | |
218 v = face->size->metrics.ascender; | |
219 v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale); | |
220 *asc = (v > v2 * 0.9) ? v : v2; | |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
221 |
21620 | 222 v = - face->size->metrics.descender; |
223 v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale); | |
224 *desc = (v > v2 * 0.9) ? v : v2; | |
225 return; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
226 } |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
227 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
228 |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
229 *asc = *desc = 0; |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
230 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
231 |
21630 | 232 /** |
233 * \brief Get a glyph | |
234 * \param ch character code | |
235 **/ | |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
236 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch, ass_hinting_t hinting) |
21277 | 237 { |
238 int error; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
239 int index = 0; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
240 int i; |
21277 | 241 FT_Glyph glyph; |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
242 FT_Face face = 0; |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
243 int flags = 0; |
21350 | 244 |
245 if (ch < 0x20) | |
246 return 0; | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
247 if (font->n_faces == 0) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
248 return 0; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
249 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
250 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
|
251 face = font->faces[i]; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
252 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
|
253 if (index) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
254 break; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
255 } |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
256 |
21351
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
257 #ifdef HAVE_FONTCONFIG |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
258 FcCharSetAddChar(font->charset, ch); |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
259 if (index == 0) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 if (index == 0) { |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
266 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
|
267 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
|
268 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
269 } |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
270 #endif |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
271 |
23134
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
272 switch (hinting) { |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
273 case ASS_HINTING_NONE: flags = FT_LOAD_NO_HINTING; break; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
274 case ASS_HINTING_LIGHT: flags = FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT; break; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
275 case ASS_HINTING_NORMAL: flags = FT_LOAD_FORCE_AUTOHINT; break; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
276 case ASS_HINTING_NATIVE: flags = 0; break; |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
277 } |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
278 |
1de2a46a0987
Add -ass-hinting option for setting font hinting method.
eugeni
parents:
22210
diff
changeset
|
279 error = FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP | flags); |
21277 | 280 if (error) { |
281 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
282 return 0; | |
283 } | |
284 | |
285 #if (FREETYPE_MAJOR > 2) || \ | |
286 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \ | |
287 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10)) | |
288 // 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
|
289 if (!(face->style_flags & FT_STYLE_FLAG_ITALIC) && |
21277 | 290 (font->desc.italic > 55)) { |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
291 FT_GlyphSlot_Oblique(face->glyph); |
21277 | 292 } |
293 #endif | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
294 error = FT_Get_Glyph(face->glyph, &glyph); |
21277 | 295 if (error) { |
296 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
297 return 0; | |
298 } | |
299 | |
300 return glyph; | |
301 } | |
302 | |
21630 | 303 /** |
304 * \brief Get kerning for the pair of glyphs. | |
305 **/ | |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
306 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
|
307 { |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
308 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
|
309 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
310 |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 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
|
315 if (i1 && i2) { |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
316 if (FT_HAS_KERNING(face)) |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
317 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
|
318 return v; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
319 } |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
320 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
|
321 return v; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
322 } |
21614
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
323 return v; |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
324 } |
5d2ca7ca18b5
Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents:
21460
diff
changeset
|
325 |
21630 | 326 /** |
327 * \brief Deallocate ass_font_t | |
328 **/ | |
21277 | 329 void ass_font_free(ass_font_t* font) |
330 { | |
21619
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
331 int i; |
b4b51eb2904f
Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents:
21618
diff
changeset
|
332 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
|
333 if (font->faces[i]) FT_Done_Face(font->faces[i]); |
21277 | 334 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
|
335 #ifdef HAVE_FONTCONFIG |
c611dfc4cb85
If a glyph is not found in the current font, switch to another one.
eugeni
parents:
21350
diff
changeset
|
336 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
|
337 #endif |
21317 | 338 free(font); |
21277 | 339 } |