annotate libass/ass_font.c @ 25444:acaa10e43c52

Move ds->current=NULL; further up to the free_demux_packet. This does not change behaviour in the normal case but avoids a double-free if the function is aborted via a signal handler.
author reimar
date Thu, 20 Dec 2007 11:21:02 +0000
parents 810982c2bfb4
children 3993c96eaa95
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
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
28 #include FT_TRUETYPE_TABLES_H
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
29
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
30 #include "ass.h"
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
31 #include "ass_library.h"
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
32 #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
33 #include "ass_bitmap.h"
7b7627ff1937 Move ass_font_desc_t and ass_font_t declarations to ass_font.h.
eugeni
parents: 21320
diff changeset
34 #include "ass_cache.h"
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
35 #include "ass_fontconfig.h"
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
36 #include "ass_utils.h"
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
37 #include "mputils.h"
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 /**
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
40 * Select Microfost Unicode CharMap, if the font has one.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
41 * Otherwise, let FreeType decide.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
42 */
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
43 static void charmap_magic(FT_Face face)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
44 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
45 int i;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
46 for (i = 0; i < face->num_charmaps; ++i) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
47 FT_CharMap cmap = face->charmaps[i];
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
48 unsigned pid = cmap->platform_id;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
49 unsigned eid = cmap->encoding_id;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
50 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
51 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
52 return;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
53 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
54 }
22210
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
55
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
56 if (!face->charmap) {
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
57 if (face->num_charmaps == 0) {
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
58 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
59 return;
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
60 }
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
61 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
62 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
63 return;
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
64 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
65 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
66
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
67 static void update_transform(ass_font_t* font)
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
68 {
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
69 int i;
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
70 FT_Matrix m;
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
71 m.xx = double_to_d16(font->scale_x);
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
72 m.yy = double_to_d16(font->scale_y);
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
73 m.xy = m.yx = 0;
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
74 for (i = 0; i < font->n_faces; ++i)
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
75 FT_Set_Transform(font->faces[i], &m, &font->v);
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
76 }
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
77
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
78 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
79 * \brief find a memory font by name
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
80 */
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
81 static int find_font(ass_library_t* library, char* name)
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
82 {
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
83 int i;
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
84 for (i = 0; i < library->num_fontdata; ++i)
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
85 if (strcasecmp(name, library->fontdata[i].name) == 0)
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
86 return i;
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
87 return -1;
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
88 }
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
89
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
90 static void face_set_size(FT_Face face, double size);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
91
23982
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
92 static void buggy_font_workaround(FT_Face face)
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
93 {
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
94 // Some fonts have zero Ascender/Descender fields in 'hhea' table.
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
95 // In this case, get the information from 'os2' table or, as
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
96 // a last resort, from face.bbox.
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
97 if (face->ascender + face->descender == 0 || face->height == 0) {
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
98 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
99 if (os2) {
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
100 face->ascender = os2->sTypoAscender;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
101 face->descender = os2->sTypoDescender;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
102 face->height = face->ascender - face->descender;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
103 } else {
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
104 face->ascender = face->bbox.yMax;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
105 face->descender = face->bbox.yMin;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
106 face->height = face->ascender - face->descender;
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
107 }
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
108 }
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
109 }
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
110
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
111 /**
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
112 * \brief Select a face with the given charcode and add it to ass_font_t
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
113 * \return index of the new face in font->faces, -1 if failed
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
114 */
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
115 static int add_face(void* fc_priv, ass_font_t* font, uint32_t ch)
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
116 {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
117 char* path;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
118 int index;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
119 FT_Face face;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
120 int error;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
121 int mem_idx;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
122
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
123 if (font->n_faces == ASS_FONT_MAX_FACES)
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
124 return -1;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
125
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
126 path = fontconfig_select(fc_priv, font->desc.family, font->desc.bold,
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
127 font->desc.italic, &index, ch);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
128
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
129 mem_idx = find_font(font->library, path);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
130 if (mem_idx >= 0) {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
131 error = FT_New_Memory_Face(font->ftlibrary, (unsigned char*)font->library->fontdata[mem_idx].data,
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
132 font->library->fontdata[mem_idx].size, 0, &face);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
133 if (error) {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
134 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningMemoryFont, path);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
135 return -1;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
136 }
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
137 } else {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
138 error = FT_New_Face(font->ftlibrary, path, index, &face);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
139 if (error) {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
140 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorOpeningFont, path, index);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
141 return -1;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
142 }
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
143 }
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
144 charmap_magic(face);
23982
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
145 buggy_font_workaround(face);
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
146
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
147 font->faces[font->n_faces++] = face;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
148 update_transform(font);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
149 face_set_size(face, font->size);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
150 return font->n_faces - 1;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
151 }
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
152
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
153 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
154 * \brief Create a new ass_font_t according to "desc" argument
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
155 */
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
156 ass_font_t* ass_font_new(ass_library_t* library, 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
157 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
158 int error;
23212
c932f521344d In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents: 23134
diff changeset
159 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
160 ass_font_t font;
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
161
23212
c932f521344d In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents: 23134
diff changeset
162 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
163 if (fontp)
c932f521344d In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents: 23134
diff changeset
164 return fontp;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
165
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
166 font.library = library;
23212
c932f521344d In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents: 23134
diff changeset
167 font.ftlibrary = ftlibrary;
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
168 font.n_faces = 0;
23212
c932f521344d In ass_font_new, allocate temporary ass_font_t on stack and return the pointer
eugeni
parents: 23134
diff changeset
169 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
170 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
171 font.desc.italic = desc->italic;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
172
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
173 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
174 font.v.x = font.v.y = 0;
23300
04dbd42b3962 Support fractional font sizes.
eugeni
parents: 23299
diff changeset
175 font.size = 0.;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
176
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
177 error = add_face(fc_priv, &font, 0);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
178 if (error == -1) {
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
179 free(font.desc.family);
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
180 return 0;
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
181 } else
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
182 return ass_font_cache_add(&font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
183 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
184
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
185 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
186 * \brief Set font transformation matrix and shift vector
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
187 **/
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
188 void ass_font_set_transform(ass_font_t* font, double scale_x, double scale_y, FT_Vector* v)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
189 {
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
190 font->scale_x = scale_x;
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
191 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
192 font->v.x = v->x;
2704273f398d FT_Set_Transform is fast enough to be called once for each glyph.
eugeni
parents: 21615
diff changeset
193 font->v.y = v->y;
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
194 update_transform(font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
195 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
196
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
197 static void face_set_size(FT_Face face, double size)
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
198 {
23340
15b2b1e8a568 Fix #if condition.
eugeni
parents: 23339
diff changeset
199 #if (FREETYPE_MAJOR > 2) || ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR > 1))
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
200 TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
201 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
202 double mscale = 1.;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
203 FT_Size_RequestRec rq;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
204 FT_Size_Metrics *m = &face->size->metrics;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
205 // VSFilter uses metrics from TrueType OS/2 table
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
206 // The idea was borrowed from asa (http://asa.diac24.net)
23983
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
207 if (hori && os2) {
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
208 int hori_height = hori->Ascender - hori->Descender;
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
209 int os2_height = os2->usWinAscent + os2->usWinDescent;
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
210 if (hori_height && os2_height)
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
211 mscale = (double)hori_height / os2_height;
90038c72d69e Don't apply windows-like font scaling if hhea or os2 tables contain invalid
eugeni
parents: 23982
diff changeset
212 }
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
213 memset(&rq, 0, sizeof(rq));
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
214 rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
215 rq.width = 0;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
216 rq.height = double_to_d6(size * mscale);
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
217 rq.horiResolution = rq.vertResolution = 0;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
218 FT_Request_Size(face, &rq);
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
219 m->ascender /= mscale;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
220 m->descender /= mscale;
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
221 m->height /= mscale;
23339
95bc9f4905f8 FT_Request_Size does not exist in FreeType 2.1.*. Fallback to FT_Set_Char_Size.
eugeni
parents: 23328
diff changeset
222 #else
95bc9f4905f8 FT_Request_Size does not exist in FreeType 2.1.*. Fallback to FT_Set_Char_Size.
eugeni
parents: 23328
diff changeset
223 FT_Set_Char_Size(face, 0, double_to_d6(size), 0, 0);
95bc9f4905f8 FT_Request_Size does not exist in FreeType 2.1.*. Fallback to FT_Set_Char_Size.
eugeni
parents: 23328
diff changeset
224 #endif
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
225 }
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
226
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
227 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
228 * \brief Set font size
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
229 **/
23300
04dbd42b3962 Support fractional font sizes.
eugeni
parents: 23299
diff changeset
230 void ass_font_set_size(ass_font_t* font, double size)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
231 {
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
232 int i;
21319
415e2119e91c Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents: 21317
diff changeset
233 if (font->size != size) {
21320
4a7e96f1eebf Cosmetics: reindent.
eugeni
parents: 21319
diff changeset
234 font->size = size;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
235 for (i = 0; i < font->n_faces; ++i)
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
236 face_set_size(font->faces[i], size);
21319
415e2119e91c Don't call FT_Set_Transform/FT_Set_Pixel_Sizes if values have not changed.
eugeni
parents: 21317
diff changeset
237 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
238 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
239
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
240 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
241 * \brief Get maximal font ascender and descender.
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
242 * \param ch character code
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
243 * The values are extracted from the font face that provides glyphs for the given character
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
244 **/
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
245 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
246 {
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
247 int i;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
248 for (i = 0; i < font->n_faces; ++i) {
21620
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
249 FT_Face face = font->faces[i];
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
250 if (FT_Get_Char_Index(face, ch)) {
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
251 int v, v2;
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
252 v = face->size->metrics.ascender;
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
253 v2 = FT_MulFix(face->bbox.yMax, face->size->metrics.y_scale);
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
254 *asc = (v > v2 * 0.9) ? v : v2;
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
255
21620
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
256 v = - face->size->metrics.descender;
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
257 v2 = - FT_MulFix(face->bbox.yMin, face->size->metrics.y_scale);
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
258 *desc = (v > v2 * 0.9) ? v : v2;
ef93ebaef504 Cosmetics: fix indentation.
eugeni
parents: 21619
diff changeset
259 return;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
260 }
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
261 }
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
262
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
263 *asc = *desc = 0;
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
264 }
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
265
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
266 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
267 * \brief Get a glyph
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
268 * \param ch character code
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
269 **/
23134
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
270 FT_Glyph ass_font_get_glyph(void* fontconfig_priv, ass_font_t* font, uint32_t ch, ass_hinting_t hinting)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
271 {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
272 int error;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
273 int index = 0;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
274 int i;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
275 FT_Glyph glyph;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
276 FT_Face face = 0;
23134
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
277 int flags = 0;
21350
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
278
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
279 if (ch < 0x20)
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
280 return 0;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
281 if (font->n_faces == 0)
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
282 return 0;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
283
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
284 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
285 face = font->faces[i];
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
286 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
287 if (index)
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
288 break;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
289 }
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
290
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
291 #ifdef HAVE_FONTCONFIG
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
292 if (index == 0) {
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
293 int face_idx;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
294 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
295 ch, font->desc.family, font->desc.bold, font->desc.italic);
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
296 face_idx = add_face(fontconfig_priv, font, ch);
24827
4ec67a66ef54 Check return value of add_face.
eugeni
parents: 23983
diff changeset
297 if (face_idx >= 0) {
24828
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
298 face = font->faces[face_idx];
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
299 index = FT_Get_Char_Index(face, ch);
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
300 if (index == 0) {
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
301 mp_msg(MSGT_ASS, MSGL_ERR, MSGTR_LIBASS_GlyphNotFound,
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
302 ch, font->desc.family, font->desc.bold, font->desc.italic);
810982c2bfb4 Cosmetics: fix indentation after last commit.
eugeni
parents: 24827
diff changeset
303 }
24827
4ec67a66ef54 Check return value of add_face.
eugeni
parents: 23983
diff changeset
304 }
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
305 }
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
306 #endif
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
307
23134
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
308 switch (hinting) {
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
309 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
310 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
311 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
312 case ASS_HINTING_NATIVE: flags = 0; break;
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
313 }
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
314
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22210
diff changeset
315 error = FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP | flags);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
316 if (error) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
317 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
318 return 0;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
319 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
320
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
321 #if (FREETYPE_MAJOR > 2) || \
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
322 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR >= 2)) || \
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
323 ((FREETYPE_MAJOR == 2) && (FREETYPE_MINOR == 1) && (FREETYPE_PATCH >= 10))
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
324 // 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
325 if (!(face->style_flags & FT_STYLE_FLAG_ITALIC) &&
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
326 (font->desc.italic > 55)) {
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
327 FT_GlyphSlot_Oblique(face->glyph);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
328 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
329 #endif
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
330 error = FT_Get_Glyph(face->glyph, &glyph);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
331 if (error) {
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
332 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_ErrorLoadingGlyph);
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
333 return 0;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
334 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
335
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
336 return glyph;
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
337 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
338
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
339 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
340 * \brief Get kerning for the pair of glyphs.
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
341 **/
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
342 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
343 {
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
344 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
345 int i;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
346
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
347 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
348 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
349 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
350 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
351 if (i1 && i2) {
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
352 if (FT_HAS_KERNING(face))
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
353 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
354 return v;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
355 }
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
356 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
357 return v;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
358 }
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
359 return v;
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
360 }
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
361
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
362 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
363 * \brief Deallocate ass_font_t
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
364 **/
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
365 void ass_font_free(ass_font_t* font)
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
366 {
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
367 int i;
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
368 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
369 if (font->faces[i]) FT_Done_Face(font->faces[i]);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
370 if (font->desc.family) free(font->desc.family);
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
371 free(font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
372 }