Mercurial > mplayer.hg
annotate libass/ass_font.c @ 21341:c88f4069c619
Cycling through video tracks works with libavformat as well.
author | diego |
---|---|
date | Tue, 28 Nov 2006 16:50:39 +0000 |
parents | 7b7627ff1937 |
children | 11679d93c7d8 |
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 | |
29 #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
|
30 #include "ass_bitmap.h" |
7b7627ff1937
Move ass_font_desc_t and ass_font_t declarations to ass_font.h.
eugeni
parents:
21320
diff
changeset
|
31 #include "ass_cache.h" |
21277 | 32 #include "ass_fontconfig.h" |
33 #include "mputils.h" | |
34 | |
35 /** | |
36 * Select Microfost Unicode CharMap, if the font has one. | |
37 * Otherwise, let FreeType decide. | |
38 */ | |
39 static void charmap_magic(FT_Face face) | |
40 { | |
41 int i; | |
42 for (i = 0; i < face->num_charmaps; ++i) { | |
43 FT_CharMap cmap = face->charmaps[i]; | |
44 unsigned pid = cmap->platform_id; | |
45 unsigned eid = cmap->encoding_id; | |
46 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) { | |
47 FT_Set_Charmap(face, cmap); | |
48 break; | |
49 } | |
50 } | |
51 } | |
52 | |
21317 | 53 ass_font_t* ass_font_new(FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc) |
21277 | 54 { |
55 char* path; | |
56 int index; | |
57 FT_Face face; | |
58 int error; | |
21317 | 59 ass_font_t* font; |
60 | |
61 font = ass_font_cache_find(desc); | |
62 if (font) | |
63 return font; | |
21277 | 64 |
65 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index); | |
66 | |
67 error = FT_New_Face(ftlibrary, path, index, &face); | |
68 if (error) { | |
21279 | 69 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index); |
21317 | 70 return 0; |
21277 | 71 } |
72 | |
73 charmap_magic(face); | |
74 | |
21317 | 75 font = calloc(1, sizeof(ass_font_t)); |
21277 | 76 font->path = strdup(path); |
77 font->index = index; | |
78 font->face = face; | |
79 font->desc.family = strdup(desc->family); | |
80 font->desc.bold = desc->bold; | |
81 font->desc.italic = desc->italic; | |
82 | |
83 font->m.xx = font->m.yy = (FT_Fixed)0x10000L; | |
84 font->m.xy = font->m.yy = 0; | |
85 font->v.x = font->v.y = 0; | |
21314 | 86 font->size = 0; |
21277 | 87 |
21317 | 88 ass_font_cache_add(font); |
89 | |
90 return font; | |
21277 | 91 } |
92 | |
93 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v) | |
94 { | |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
95 if (font->m.xx != m->xx || |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
96 font->m.xy != m->xy || |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
97 font->m.yx != m->yx || |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
98 font->m.yy != m->yy || |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
99 font->v.x != v->x || |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
100 font->v.y != v->y |
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
101 ) { |
21320 | 102 font->m.xx = m->xx; |
103 font->m.xy = m->xy; | |
104 font->m.yx = m->yx; | |
105 font->m.yy = m->yy; | |
106 font->v.x = v->x; | |
107 font->v.y = v->y; | |
108 FT_Set_Transform(font->face, &font->m, &font->v); | |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
109 } |
21277 | 110 } |
111 | |
112 void ass_font_set_size(ass_font_t* font, int size) | |
113 { | |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
114 if (font->size != size) { |
21320 | 115 font->size = size; |
116 FT_Set_Pixel_Sizes(font->face, 0, size); | |
21319
415e2119e91c
Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents:
21317
diff
changeset
|
117 } |
21277 | 118 } |
119 | |
120 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch) | |
121 { | |
122 int error; | |
123 int index; | |
124 FT_Glyph glyph; | |
125 | |
126 index = FT_Get_Char_Index(font->face, ch); | |
127 error = FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP ); | |
128 if (error) { | |
129 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
130 return 0; | |
131 } | |
132 | |
133 #if (FREETYPE_MAJOR > 2) || \ | |
134 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \ | |
135 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10)) | |
136 // FreeType >= 2.1.10 required | |
137 if (!(font->face->style_flags & FT_STYLE_FLAG_ITALIC) && | |
138 (font->desc.italic > 55)) { | |
139 FT_GlyphSlot_Oblique(font->face->glyph); | |
140 } | |
141 #endif | |
142 error = FT_Get_Glyph(font->face->glyph, &glyph); | |
143 if (error) { | |
144 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph); | |
145 return 0; | |
146 } | |
147 | |
148 return glyph; | |
149 } | |
150 | |
151 void ass_font_free(ass_font_t* font) | |
152 { | |
153 if (font->face) FT_Done_Face(font->face); | |
154 if (font->path) free(font->path); | |
155 if (font->desc.family) free(font->desc.family); | |
21317 | 156 free(font); |
21277 | 157 } |