annotate libass/ass_font.c @ 35945:a8baf85f7b6e

configure: Do a proper fallback from internal to external libdvdread.
author diego
date Fri, 22 Mar 2013 15:37:38 +0000
parents 6e7f60f6f9d4
children c3aaaf17c721
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 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 25660
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 25660
diff changeset
3 *
26738
588ce97b44f2 Speak of libass instead of MPlayer in the libass license headers.
diego
parents: 26723
diff changeset
4 * This file is part of libass.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25660
diff changeset
5 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
6 * Permission to use, copy, modify, and distribute this software for any
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
8 * copyright notice and this permission notice appear in all copies.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25660
diff changeset
9 *
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26723
0f892cd714b2 Use standard license header.
diego
parents: 25660
diff changeset
17 */
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
18
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
19 #include "config.h"
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 <inttypes.h>
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
22 #include <ft2build.h>
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
23 #include FT_FREETYPE_H
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
24 #include FT_SYNTHESIS_H
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
25 #include FT_GLYPH_H
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
26 #include FT_TRUETYPE_TABLES_H
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
27 #include FT_OUTLINE_H
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
28 #include <strings.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"
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
33 #include "ass_fontconfig.h"
23299
0ee56ec36a40 Limit ass_font_set_transform to nonrotating transformations.
eugeni
parents: 23212
diff changeset
34 #include "ass_utils.h"
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
35 #include "ass_shaper.h"
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
36
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
37 /**
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
38 * Select a good charmap, prefer Microsoft Unicode charmaps.
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
39 * Otherwise, let FreeType decide.
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
40 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
41 static void charmap_magic(ASS_Library *library, FT_Face face)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
42 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
43 int i;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
44 int ms_cmap = -1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
45
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
46 // Search for a Microsoft Unicode cmap
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
47 for (i = 0; i < face->num_charmaps; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
48 FT_CharMap cmap = face->charmaps[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
49 unsigned pid = cmap->platform_id;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
50 unsigned eid = cmap->encoding_id;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
51 if (pid == 3 /*microsoft */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
52 && (eid == 1 /*unicode bmp */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
53 || eid == 10 /*full unicode */ )) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
54 FT_Set_Charmap(face, cmap);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
55 return;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
56 } else if (pid == 3 && ms_cmap < 0)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
57 ms_cmap = i;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
58 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
59
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
60 // Try the first Microsoft cmap if no Microsoft Unicode cmap was found
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
61 if (ms_cmap >= 0) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
62 FT_CharMap cmap = face->charmaps[ms_cmap];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
63 FT_Set_Charmap(face, cmap);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
64 return;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
65 }
22210
4a958bd08920 Select the first charmap in the font, if FreeType did not autoselect any.
eugeni
parents: 21630
diff changeset
66
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
67 if (!face->charmap) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
68 if (face->num_charmaps == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
69 ass_msg(library, MSGL_WARN, "Font face with no charmaps");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
70 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
71 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
72 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
73 "No charmap autodetected, trying the first one");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
74 FT_Set_Charmap(face, face->charmaps[0]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
75 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
76 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
77 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
78
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
79 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
80 * \brief find a memory font by name
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
81 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
82 static int find_font(ASS_Library *library, char *name)
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
83 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
84 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
85 for (i = 0; i < library->num_fontdata; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
86 if (strcasecmp(name, library->fontdata[i].name) == 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
87 return i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
88 return -1;
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
89 }
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
90
23982
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
91 static void buggy_font_workaround(FT_Face face)
17b5fa69243c Workaround for fonts with zero ascender/descender in horizontal header.
eugeni
parents: 23981
diff changeset
92 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
93 // Some fonts have zero Ascender/Descender fields in 'hhea' table.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
94 // In this case, get the information from 'os2' table or, as
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
95 // a last resort, from face.bbox.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
96 if (face->ascender + face->descender == 0 || face->height == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
97 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
98 if (os2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
99 face->ascender = os2->sTypoAscender;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
100 face->descender = os2->sTypoDescender;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
101 face->height = face->ascender - face->descender;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
102 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
103 face->ascender = face->bbox.yMax;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
104 face->descender = face->bbox.yMin;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
105 face->height = face->ascender - face->descender;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
106 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
107 }
23982
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
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
110 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
111 * \brief Select a face with the given charcode and add it to ASS_Font
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
112 * \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
113 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
114 static int add_face(void *fc_priv, ASS_Font *font, uint32_t ch)
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
115 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
116 char *path;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
117 int index;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
118 FT_Face face;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
119 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
120 int mem_idx;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
121
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
122 if (font->n_faces == ASS_FONT_MAX_FACES)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
123 return -1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
124
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
125 path =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
126 fontconfig_select(font->library, fc_priv, font->desc.family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
127 font->desc.treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
128 font->desc.bold, font->desc.italic, &index, ch);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
129 if (!path)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
130 return -1;
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
131
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
132 mem_idx = find_font(font->library, path);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
133 if (mem_idx >= 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
134 error =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
135 FT_New_Memory_Face(font->ftlibrary,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
136 (unsigned char *) font->library->
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
137 fontdata[mem_idx].data,
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
138 font->library->fontdata[mem_idx].size, index,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
139 &face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
140 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
141 ass_msg(font->library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
142 "Error opening memory font: '%s'", path);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
143 free(path);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
144 return -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
145 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
146 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
147 error = FT_New_Face(font->ftlibrary, path, index, &face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
148 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
149 ass_msg(font->library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
150 "Error opening font: '%s', %d", path, index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
151 free(path);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
152 return -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
153 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
154 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
155 charmap_magic(font->library, face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
156 buggy_font_workaround(face);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
157
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
158 font->faces[font->n_faces++] = face;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
159 ass_face_set_size(face, font->size);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
160 free(path);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
161 return font->n_faces - 1;
23981
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
162 }
705628816d98 Factor out common code from ass_font_new and ass_font_reselect.
eugeni
parents: 23980
diff changeset
163
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
164 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
165 * \brief Create a new ASS_Font according to "desc" argument
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
166 */
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
167 ASS_Font *ass_font_new(Cache *font_cache, ASS_Library *library,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
168 FT_Library ftlibrary, void *fc_priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
169 ASS_FontDesc *desc)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
170 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
171 int error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
172 ASS_Font *fontp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
173 ASS_Font font;
21317
dcfd069efd8f Move ass_font_t allocation to ass_font.h.
eugeni
parents: 21314
diff changeset
174
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
175 fontp = ass_cache_get(font_cache, desc);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
176 if (fontp)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
177 return fontp;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
178
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
179 font.library = library;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
180 font.ftlibrary = ftlibrary;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
181 font.shaper_priv = NULL;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
182 font.n_faces = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
183 font.desc.family = strdup(desc->family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
184 font.desc.treat_family_as_pattern = desc->treat_family_as_pattern;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
185 font.desc.bold = desc->bold;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
186 font.desc.italic = desc->italic;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
187 font.desc.vertical = desc->vertical;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
188
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
189 font.scale_x = font.scale_y = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
190 font.v.x = font.v.y = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
191 font.size = 0.;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
192
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
193 error = add_face(fc_priv, &font, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
194 if (error == -1) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
195 free(font.desc.family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
196 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
197 } else
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
198 return ass_cache_put(font_cache, &font.desc, &font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
199 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
200
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
201 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
202 * \brief Set font transformation matrix and shift vector
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
203 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
204 void ass_font_set_transform(ASS_Font *font, double scale_x,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
205 double scale_y, FT_Vector *v)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
206 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
207 font->scale_x = scale_x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
208 font->scale_y = scale_y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
209 if (v) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
210 font->v.x = v->x;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
211 font->v.y = v->y;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
212 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
213 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
214
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
215 void ass_face_set_size(FT_Face face, double size)
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
216 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
217 TT_HoriHeader *hori = FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
218 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
219 double mscale = 1.;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
220 FT_Size_RequestRec rq;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
221 FT_Size_Metrics *m = &face->size->metrics;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
222 // VSFilter uses metrics from TrueType OS/2 table
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
223 // The idea was borrowed from asa (http://asa.diac24.net)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
224 if (hori && os2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
225 int hori_height = hori->Ascender - hori->Descender;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
226 int os2_height = os2->usWinAscent + os2->usWinDescent;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
227 if (hori_height && os2_height)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
228 mscale = (double) hori_height / os2_height;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
229 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
230 memset(&rq, 0, sizeof(rq));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
231 rq.type = FT_SIZE_REQUEST_TYPE_REAL_DIM;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
232 rq.width = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
233 rq.height = double_to_d6(size * mscale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
234 rq.horiResolution = rq.vertResolution = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
235 FT_Request_Size(face, &rq);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
236 m->ascender /= mscale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
237 m->descender /= mscale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
238 m->height /= mscale;
23328
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
239 }
99ac5d381aed Correct font size in libass.
eugeni
parents: 23300
diff changeset
240
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
241 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
242 * \brief Set font size
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
243 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
244 void ass_font_set_size(ASS_Font *font, double size)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
245 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
246 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
247 if (font->size != size) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
248 font->size = size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
249 for (i = 0; i < font->n_faces; ++i)
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
250 ass_face_set_size(font->faces[i], size);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
251 }
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
252 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
253
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
254 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
255 * \brief Get maximal font ascender and descender.
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
256 * \param ch character code
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
257 * The values are extracted from the font face that provides glyphs for the given character
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
258 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
259 void ass_font_get_asc_desc(ASS_Font *font, uint32_t ch, int *asc,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
260 int *desc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
261 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
262 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
263 for (i = 0; i < font->n_faces; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
264 FT_Face face = font->faces[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
265 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
266 if (FT_Get_Char_Index(face, ch)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
267 int y_scale = face->size->metrics.y_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
268 if (os2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
269 *asc = FT_MulFix(os2->usWinAscent, y_scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
270 *desc = FT_MulFix(os2->usWinDescent, y_scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
271 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
272 *asc = FT_MulFix(face->ascender, y_scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
273 *desc = FT_MulFix(-face->descender, y_scale);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
274 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
275 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
276 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
277 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
278
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
279 *asc = *desc = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
280 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
281
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
282 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
283 * Strike a glyph with a horizontal line; it's possible to underline it
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
284 * and/or strike through it. For the line's position and size, truetype
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
285 * tables are consulted. Obviously this relies on the data in the tables
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
286 * being accurate.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
287 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
288 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
289 static int ass_strike_outline_glyph(FT_Face face, ASS_Font *font,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
290 FT_Glyph glyph, int under, int through)
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
291 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
292 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
293 TT_Postscript *ps = FT_Get_Sfnt_Table(face, ft_sfnt_post);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
294 FT_Outline *ol = &((FT_OutlineGlyph) glyph)->outline;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
295 int bear, advance, y_scale, i, dir;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
296
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
297 if (!under && !through)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
298 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
299
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
300 // Grow outline
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
301 i = (under ? 4 : 0) + (through ? 4 : 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
302 ol->points = realloc(ol->points, sizeof(FT_Vector) *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
303 (ol->n_points + i));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
304 ol->tags = realloc(ol->tags, ol->n_points + i);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
305 i = !!under + !!through;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
306 ol->contours = realloc(ol->contours, sizeof(short) *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
307 (ol->n_contours + i));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
308
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
309 // If the bearing is negative, the glyph starts left of the current
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
310 // pen position
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
311 bear = FFMIN(face->glyph->metrics.horiBearingX, 0);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
312 // We're adding half a pixel to avoid small gaps
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
313 advance = d16_to_d6(glyph->advance.x) + 32;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
314 y_scale = face->size->metrics.y_scale;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
315
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
316 // Reverse drawing direction for non-truetype fonts
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
317 dir = FT_Outline_Get_Orientation(ol);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
318
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
319 // Add points to the outline
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
320 if (under && ps) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
321 int pos, size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
322 pos = FT_MulFix(ps->underlinePosition, y_scale * font->scale_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
323 size = FT_MulFix(ps->underlineThickness,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
324 y_scale * font->scale_y / 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
325
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
326 if (pos > 0 || size <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
327 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
328
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
329 FT_Vector points[4] = {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
330 {.x = bear, .y = pos + size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
331 {.x = advance, .y = pos + size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
332 {.x = advance, .y = pos - size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
333 {.x = bear, .y = pos - size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
334 };
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
335
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
336 if (dir == FT_ORIENTATION_TRUETYPE) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
337 for (i = 0; i < 4; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
338 ol->points[ol->n_points] = points[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
339 ol->tags[ol->n_points++] = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
340 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
341 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
342 for (i = 3; i >= 0; i--) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
343 ol->points[ol->n_points] = points[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
344 ol->tags[ol->n_points++] = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
345 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
346 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
347
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
348 ol->contours[ol->n_contours++] = ol->n_points - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
349 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
350
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
351 if (through && os2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
352 int pos, size;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
353 pos = FT_MulFix(os2->yStrikeoutPosition, y_scale * font->scale_y);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
354 size = FT_MulFix(os2->yStrikeoutSize, y_scale * font->scale_y / 2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
355
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
356 if (pos < 0 || size <= 0)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
357 return 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
358
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
359 FT_Vector points[4] = {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
360 {.x = bear, .y = pos + size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
361 {.x = advance, .y = pos + size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
362 {.x = advance, .y = pos - size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
363 {.x = bear, .y = pos - size},
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
364 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
365
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
366 if (dir == FT_ORIENTATION_TRUETYPE) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
367 for (i = 0; i < 4; i++) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
368 ol->points[ol->n_points] = points[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
369 ol->tags[ol->n_points++] = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
370 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
371 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
372 for (i = 3; i >= 0; i--) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
373 ol->points[ol->n_points] = points[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
374 ol->tags[ol->n_points++] = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
375 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
376 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
377
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
378 ol->contours[ol->n_contours++] = ol->n_points - 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
379 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
380
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
381 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
382 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
383
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
384 void outline_copy(FT_Library lib, FT_Outline *source, FT_Outline **dest)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
385 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
386 if (source == NULL) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
387 *dest = NULL;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
388 return;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
389 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
390 *dest = calloc(1, sizeof(**dest));
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
391
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
392 FT_Outline_New(lib, source->n_points, source->n_contours, *dest);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
393 FT_Outline_Copy(source, *dest);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
394 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
395
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
396 void outline_free(FT_Library lib, FT_Outline *outline)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
397 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
398 if (outline)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
399 FT_Outline_Done(lib, outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
400 free(outline);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
401 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
402
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
403 /**
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
404 * Slightly embold a glyph without touching its metrics
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
405 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
406 static void ass_glyph_embolden(FT_GlyphSlot slot)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
407 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
408 int str;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
409
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
410 if (slot->format != FT_GLYPH_FORMAT_OUTLINE)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
411 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
412
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
413 str = FT_MulFix(slot->face->units_per_EM,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
414 slot->face->size->metrics.y_scale) / 64;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
415
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
416 FT_Outline_Embolden(&slot->outline, str);
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
417 }
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
418
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
419 /**
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
420 * \brief Get glyph and face index
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
421 * Finds a face that has the requested codepoint and returns both face
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
422 * and glyph index.
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
423 */
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
424 int ass_font_get_index(void *fcpriv, ASS_Font *font, uint32_t symbol,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
425 int *face_index, int *glyph_index)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
426 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
427 int index = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
428 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
429 FT_Face face = 0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
430
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
431 *glyph_index = 0;
21350
5337cdeec169 Skip glyphs with char code < 0x20.
eugeni
parents: 21349
diff changeset
432
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
433 if (symbol < 0x20) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
434 *face_index = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
435 return 0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
436 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
437 // Handle NBSP like a regular space when rendering the glyph
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
438 if (symbol == 0xa0)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
439 symbol = ' ';
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
440 if (font->n_faces == 0) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
441 *face_index = 0;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
442 return 0;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
443 }
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
444
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
445 // try with the requested face
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
446 if (*face_index < font->n_faces) {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
447 face = font->faces[*face_index];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
448 index = FT_Get_Char_Index(face, symbol);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
449 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
450
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
451 // not found in requested face, try all others
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
452 for (i = 0; i < font->n_faces && index == 0; ++i) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
453 face = font->faces[i];
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
454 index = FT_Get_Char_Index(face, symbol);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
455 if (index)
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
456 *face_index = i;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
457 }
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
458
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 26738
diff changeset
459 #ifdef CONFIG_FONTCONFIG
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
460 if (index == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
461 int face_idx;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
462 ass_msg(font->library, MSGL_INFO,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
463 "Glyph 0x%X not found, selecting one more "
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
464 "font for (%s, %d, %d)", symbol, font->desc.family,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
465 font->desc.bold, font->desc.italic);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
466 face_idx = *face_index = add_face(fcpriv, font, symbol);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
467 if (face_idx >= 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
468 face = font->faces[face_idx];
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
469 index = FT_Get_Char_Index(face, symbol);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
470 if (index == 0 && face->num_charmaps > 0) {
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
471 int i;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
472 ass_msg(font->library, MSGL_WARN,
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
473 "Glyph 0x%X not found, broken font? Trying all charmaps", symbol);
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
474 for (i = 0; i < face->num_charmaps; i++) {
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
475 FT_Set_Charmap(face, face->charmaps[i]);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
476 if ((index = FT_Get_Char_Index(face, symbol)) != 0) break;
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
477 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
478 }
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
479 if (index == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
480 ass_msg(font->library, MSGL_ERR,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
481 "Glyph 0x%X not found in font for (%s, %d, %d)",
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
482 symbol, font->desc.family, font->desc.bold,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
483 font->desc.italic);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
484 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
485 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
486 }
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
487 #endif
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
488 // FIXME: make sure we have a valid face_index. this is a HACK.
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
489 *face_index = FFMAX(*face_index, 0);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
490 *glyph_index = index;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
491
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
492 return 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
493 }
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
494
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
495 /**
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
496 * \brief Get a glyph
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
497 * \param ch character code
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
498 **/
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
499 FT_Glyph ass_font_get_glyph(void *fontconfig_priv, ASS_Font *font,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
500 uint32_t ch, int face_index, int index,
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
501 ASS_Hinting hinting, int deco)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
502 {
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
503 int error;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
504 FT_Glyph glyph;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
505 FT_Face face = font->faces[face_index];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
506 int flags = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
507 int vertical = font->desc.vertical;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21350
diff changeset
508
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
509 flags = FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
510 | FT_LOAD_IGNORE_TRANSFORM;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
511 switch (hinting) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
512 case ASS_HINTING_NONE:
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
513 flags |= FT_LOAD_NO_HINTING;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
514 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
515 case ASS_HINTING_LIGHT:
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
516 flags |= FT_LOAD_FORCE_AUTOHINT | FT_LOAD_TARGET_LIGHT;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
517 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
518 case ASS_HINTING_NORMAL:
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
519 flags |= FT_LOAD_FORCE_AUTOHINT;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
520 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
521 case ASS_HINTING_NATIVE:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
522 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
523 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
524
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
525 error = FT_Load_Glyph(face, index, flags);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
526 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
527 ass_msg(font->library, MSGL_WARN, "Error loading glyph, index %d",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
528 index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
529 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
530 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
531 if (!(face->style_flags & FT_STYLE_FLAG_ITALIC) &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
532 (font->desc.italic > 55)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
533 FT_GlyphSlot_Oblique(face->glyph);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
534 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28860
diff changeset
535
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
536 if (!(face->style_flags & FT_STYLE_FLAG_BOLD) &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
537 (font->desc.bold > 80)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
538 ass_glyph_embolden(face->glyph);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
539 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
540 error = FT_Get_Glyph(face->glyph, &glyph);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
541 if (error) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
542 ass_msg(font->library, MSGL_WARN, "Error loading glyph, index %d",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
543 index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
544 return 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
545 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
546
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
547 // Rotate glyph, if needed
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
548 if (vertical && ch >= VERTICAL_LOWER_BOUND) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
549 FT_Matrix m = { 0, double_to_d16(-1.0), double_to_d16(1.0), 0 };
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
550 TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
551 int desc = 0;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
552
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
553 if (os2)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
554 desc = FT_MulFix(os2->sTypoDescender, face->size->metrics.y_scale);
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
555
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
556 FT_Outline_Translate(&((FT_OutlineGlyph) glyph)->outline, 0, -desc);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
557 FT_Outline_Transform(&((FT_OutlineGlyph) glyph)->outline, &m);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
558 FT_Outline_Translate(&((FT_OutlineGlyph) glyph)->outline,
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
559 face->glyph->metrics.vertAdvance, desc);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
560 glyph->advance.x = face->glyph->linearVertAdvance;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
561 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
562
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
563 // Apply scaling and shift
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
564 FT_Matrix scale = { double_to_d16(font->scale_x), 0, 0,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
565 double_to_d16(font->scale_y) };
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
566 FT_Outline *outl = &((FT_OutlineGlyph) glyph)->outline;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
567 FT_Outline_Transform(outl, &scale);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
568 FT_Outline_Translate(outl, font->v.x, font->v.y);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
569 glyph->advance.x *= font->scale_x;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
570
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
571 ass_strike_outline_glyph(face, font, glyph, deco & DECO_UNDERLINE,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
572 deco & DECO_STRIKETHROUGH);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
573
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
574 return glyph;
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
575 }
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
576
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
577 /**
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
578 * \brief Get kerning for the pair of glyphs.
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
579 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
580 FT_Vector ass_font_get_kerning(ASS_Font *font, uint32_t c1, uint32_t c2)
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
581 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
582 FT_Vector v = { 0, 0 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
583 int i;
21619
b4b51eb2904f Keep reselected fonts in an array, adding new ones to the end. Glyph
eugeni
parents: 21618
diff changeset
584
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
585 if (font->desc.vertical)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
586 return v;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
587
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
588 for (i = 0; i < font->n_faces; ++i) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
589 FT_Face face = font->faces[i];
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
590 int i1 = FT_Get_Char_Index(face, c1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
591 int i2 = FT_Get_Char_Index(face, c2);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
592 if (i1 && i2) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
593 if (FT_HAS_KERNING(face))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
594 FT_Get_Kerning(face, i1, i2, FT_KERNING_DEFAULT, &v);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
595 return v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
596 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
597 if (i1 || i2) // these glyphs are from different font faces, no kerning information
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
598 return v;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
599 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
600 return v;
21614
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
601 }
5d2ca7ca18b5 Move ascender, descender, and kerning computation to ass_font.c.
eugeni
parents: 21460
diff changeset
602
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
603 /**
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
604 * \brief Deallocate ASS_Font
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21620
diff changeset
605 **/
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
606 void ass_font_free(ASS_Font *font)
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
607 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
608 int i;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
609 for (i = 0; i < font->n_faces; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
610 if (font->faces[i])
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
611 FT_Done_Face(font->faces[i]);
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
612 if (font->shaper_priv)
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
613 ass_shaper_font_data_free(font->shaper_priv);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
614 free(font->desc.family);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29325
diff changeset
615 free(font);
21277
0603972f083c Move fonts-related code to a separate file.
eugeni
parents:
diff changeset
616 }
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
617
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
618 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
619 * \brief Calculate the cbox of a series of points
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
620 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
621 static void
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
622 get_contour_cbox(FT_BBox *box, FT_Vector *points, int start, int end)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
623 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
624 box->xMin = box->yMin = INT_MAX;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
625 box->xMax = box->yMax = INT_MIN;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
626 int i;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
627
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
628 for (i = start; i <= end; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
629 box->xMin = (points[i].x < box->xMin) ? points[i].x : box->xMin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
630 box->xMax = (points[i].x > box->xMax) ? points[i].x : box->xMax;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
631 box->yMin = (points[i].y < box->yMin) ? points[i].y : box->yMin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
632 box->yMax = (points[i].y > box->yMax) ? points[i].y : box->yMax;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
633 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
634 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
635
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
636 /**
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
637 * \brief Determine winding direction of a contour
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
638 * \return direction; 0 = clockwise
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
639 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
640 static int get_contour_direction(FT_Vector *points, int start, int end)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
641 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
642 int i;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
643 long long sum = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
644 int x = points[start].x;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
645 int y = points[start].y;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
646 for (i = start + 1; i <= end; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
647 sum += x * (points[i].y - y) - y * (points[i].x - x);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
648 x = points[i].x;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
649 y = points[i].y;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
650 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
651 sum += x * (points[start].y - y) - y * (points[start].x - x);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
652 return sum > 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
653 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
654
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
655 /**
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
656 * \brief Apply fixups to please the FreeType stroker and improve the
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
657 * rendering result, especially in case the outline has some anomalies.
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
658 * At the moment, the following fixes are done:
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
659 *
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
660 * 1. Reverse contours that have "inside" winding direction but are not
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
661 * contained in any other contours' cbox.
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
662 * 2. Remove "inside" contours depending on border size, so that large
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
663 * borders do not reverse the winding direction, which leads to "holes"
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
664 * inside the border. The inside will be filled by the border of the
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
665 * outside contour anyway in this case.
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
666 *
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
667 * \param outline FreeType outline, modified in-place
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
668 * \param border_x border size, x direction, d6 format
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
669 * \param border_x border size, y direction, d6 format
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
670 */
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
671 void fix_freetype_stroker(FT_Outline *outline, int border_x, int border_y)
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
672 {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
673 int nc = outline->n_contours;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
674 int begin, stop;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
675 char modified = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
676 char *valid_cont = malloc(nc);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
677 int start = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
678 int end = -1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
679 FT_BBox *boxes = malloc(nc * sizeof(FT_BBox));
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
680 int i, j;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
681 int inside_direction;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
682
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
683 inside_direction = FT_Outline_Get_Orientation(outline) ==
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
684 FT_ORIENTATION_TRUETYPE;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
685
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
686 // create a list of cboxes of the contours
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
687 for (i = 0; i < nc; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
688 start = end + 1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
689 end = outline->contours[i];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
690 get_contour_cbox(&boxes[i], outline->points, start, end);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
691 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
692
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
693 // for each contour, check direction and whether it's "outside"
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
694 // or contained in another contour
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
695 end = -1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
696 for (i = 0; i < nc; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
697 start = end + 1;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
698 end = outline->contours[i];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
699 int dir = get_contour_direction(outline->points, start, end);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
700 valid_cont[i] = 1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
701 if (dir == inside_direction) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
702 for (j = 0; j < nc; j++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
703 if (i == j)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
704 continue;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
705 if (boxes[i].xMin >= boxes[j].xMin &&
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
706 boxes[i].xMax <= boxes[j].xMax &&
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
707 boxes[i].yMin >= boxes[j].yMin &&
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
708 boxes[i].yMax <= boxes[j].yMax)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
709 goto check_inside;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
710 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
711 /* "inside" contour but we can't find anything it could be
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
712 * inside of - assume the font is buggy and it should be
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
713 * an "outside" contour, and reverse it */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
714 for (j = 0; j < (end + 1 - start) / 2; j++) {
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
715 FT_Vector temp = outline->points[start + j];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
716 char temp2 = outline->tags[start + j];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
717 outline->points[start + j] = outline->points[end - j];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
718 outline->points[end - j] = temp;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
719 outline->tags[start + j] = outline->tags[end - j];
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
720 outline->tags[end - j] = temp2;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
721 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
722 dir ^= 1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
723 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
724 check_inside:
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
725 if (dir == inside_direction) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
726 FT_BBox box;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
727 get_contour_cbox(&box, outline->points, start, end);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
728 int width = box.xMax - box.xMin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
729 int height = box.yMax - box.yMin;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
730 if (width < border_x * 2 || height < border_y * 2) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
731 valid_cont[i] = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
732 modified = 1;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
733 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
734 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
735 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
736
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
737 // if we need to modify the outline, rewrite it and skip
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
738 // the contours that we determined should be removed.
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
739 if (modified) {
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
740 int p = 0, c = 0;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
741 for (i = 0; i < nc; i++) {
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
742 if (!valid_cont[i])
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
743 continue;
34295
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
744 begin = (i == 0) ? 0 : outline->contours[i - 1] + 1;
6e7f60f6f9d4 Update libass to 0.10 release.
reimar
parents: 34011
diff changeset
745 stop = outline->contours[i];
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
746 for (j = begin; j <= stop; j++) {
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
747 outline->points[p].x = outline->points[j].x;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
748 outline->points[p].y = outline->points[j].y;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
749 outline->tags[p] = outline->tags[j];
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
750 p++;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
751 }
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
752 outline->contours[c] = p - 1;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
753 c++;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
754 }
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
755 outline->n_points = p;
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
756 outline->n_contours = c;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
757 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
758
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
759 free(boxes);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
760 free(valid_cont);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
761 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
762