annotate libass/ass_font.c @ 21421:d7b2fa4c39da

Remove superfluous bswap.h include.
author diego
date Sat, 02 Dec 2006 12:32:44 +0000
parents c611dfc4cb85
children 7af6c25a0cfc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
3 /*
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
5
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
9 (at your option) any later version.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
10
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
14 GNU General Public License for more details.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
15
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
17 along with this program; if not, write to the Free Software
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
19 */
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
20
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
21 #include "config.h"
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
22
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
23 #include <inttypes.h>
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
24 #include <ft2build.h>
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
25 #include FT_FREETYPE_H
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
26 #include FT_SYNTHESIS_H
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
27 #include FT_GLYPH_H
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
28
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
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
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
32 #include "ass_fontconfig.h"
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
33 #include "mputils.h"
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
34
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
35 /**
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
36 * Select Microfost Unicode CharMap, if the font has one.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
37 * Otherwise, let FreeType decide.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
38 */
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
39 static void charmap_magic(FT_Face face)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
40 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
41 int i;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
42 for (i = 0; i < face->num_charmaps; ++i) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
43 FT_CharMap cmap = face->charmaps[i];
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
44 unsigned pid = cmap->platform_id;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
45 unsigned eid = cmap->encoding_id;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
46 if (pid == 3 /*microsoft*/ && (eid == 1 /*unicode bmp*/ || eid == 10 /*full unicode*/)) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
47 FT_Set_Charmap(face, cmap);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
48 break;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
49 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
50 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
51 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
52
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
53 ass_font_t* ass_font_new(FT_Library ftlibrary, void* fc_priv, ass_font_desc_t* desc)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
54 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
55 char* path;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
56 int index;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
57 FT_Face face;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
58 int error;
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
59 ass_font_t* font;
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
60
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
61 font = ass_font_cache_find(desc);
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
62 if (font)
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
63 return font;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
64
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
65 path = fontconfig_select(fc_priv, desc->family, desc->bold, desc->italic, &index);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
66
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
67 error = FT_New_Face(ftlibrary, path, index, &face);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
68 if (error) {
21279
9040bce9f768 Remove obsolete "no_more_font_messages" hack.
eugeni
parents: 21277
diff changeset
69 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index);
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
70 return 0;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
71 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
72
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
73 charmap_magic(face);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
74
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
75 font = calloc(1, sizeof(ass_font_t));
21349
11679d93c7d8 Add FT_Library to ass_font_t.
eugeni
parents: 21321
diff changeset
76 font->ftlibrary = ftlibrary;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
77 font->path = strdup(path);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
78 font->index = index;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
79 font->face = face;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
80 font->desc.family = strdup(desc->family);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
81 font->desc.bold = desc->bold;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
82 font->desc.italic = desc->italic;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
83
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
84 font->m.xx = font->m.yy = (FT_Fixed)0x10000L;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
85 font->m.xy = font->m.yy = 0;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
86 font->v.x = font->v.y = 0;
21314
4b2e5a74a2eb Initialize font size with 0.
eugeni
parents: 21279
diff changeset
87 font->size = 0;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
88
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
89 #ifdef HAVE_FONTCONFIG
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
90 font->charset = FcCharSetCreate();
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
91 #endif
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
92
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
93 ass_font_cache_add(font);
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
94
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
95 return font;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
96 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
97
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
98 void ass_font_set_transform(ass_font_t* font, FT_Matrix* m, FT_Vector* v)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
99 {
21319
415e2119e91c Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents: 21317
diff changeset
100 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
101 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
102 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
103 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
104 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
105 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
106 ) {
21320
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
107 font->m.xx = m->xx;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
108 font->m.xy = m->xy;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
109 font->m.yx = m->yx;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
110 font->m.yy = m->yy;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
111 font->v.x = v->x;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
112 font->v.y = v->y;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
113 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
114 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
115 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
116
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
117 void ass_font_set_size(ass_font_t* font, int size)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
118 {
21319
415e2119e91c Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents: 21317
diff changeset
119 if (font->size != size) {
21320
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
120 font->size = size;
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
121 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
122 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
123 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
124
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
125 #ifdef HAVE_FONTCONFIG
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
126 static void ass_font_reselect(void* fontconfig_priv, ass_font_t* font)
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
127 {
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
128 char* path;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
129 int index;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
130 FT_Face face;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
131 int error;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
132
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
133 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
134 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
135 if (strcasecmp(path, font->path) == 0 && index == font->index) {
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
136 free(path);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
137 return;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
138 }
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
139
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
140 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
141 if (error) {
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
142 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
143 return;
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 charmap_magic(face);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
146
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
147 if (font->face) FT_Done_Face(font->face);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
148 free(font->path);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
149
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
150 font->face = face;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
151 font->path = strdup(path);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
152 font->index = index;
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
153
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
154 FT_Set_Transform(font->face, &font->m, &font->v);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
155 FT_Set_Pixel_Sizes(font->face, 0, font->size);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
156 }
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
157 #endif
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
158
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
159 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
160 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
161 int error;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
162 int index;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
163 FT_Glyph glyph;
21350
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
164
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
165 if (ch < 0x20)
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
166 return 0;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
167
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
168 index = FT_Get_Char_Index(font->face, ch);
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
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
170 FcCharSetAddChar(font->charset, ch);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
171 if (index == 0) {
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
172 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
173 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
174 ass_font_reselect(fontconfig_priv, font);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
175 index = FT_Get_Char_Index(font->face, ch);
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
176 if (index == 0) {
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
177 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
178 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
179 }
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
180 }
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
181 #endif
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
182
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
183 error = FT_Load_Glyph(font->face, index, FT_LOAD_NO_BITMAP );
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
184 if (error) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
185 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
186 return 0;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
187 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
188
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
189 #if (FREETYPE_MAJOR > 2) || \
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
190 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
191 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10))
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
192 // FreeType >= 2.1.10 required
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
193 if (!(font->face->style_flags & FT_STYLE_FLAG_ITALIC) &&
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
194 (font->desc.italic > 55)) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
195 FT_GlyphSlot_Oblique(font->face->glyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
196 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
197 #endif
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
198 error = FT_Get_Glyph(font->face->glyph, &glyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
199 if (error) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
200 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
201 return 0;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
202 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
203
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
204 return glyph;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
205 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
206
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
207 void ass_font_free(ass_font_t* font)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
208 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
209 if (font->face) FT_Done_Face(font->face);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
210 if (font->path) free(font->path);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
211 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
212 #ifdef HAVE_FONTCONFIG
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
213 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
214 #endif
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
215 free(font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
216 }