annotate libass/ass_fontconfig.c @ 35422:696a8a165952

Check and set track for DVDs just as for the other StreamTypes.
author ib
date Thu, 29 Nov 2012 15:10:27 +0000
parents 88eebbbbd6a0
children c3aaaf17c721
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
1 /*
26723
0f892cd714b2 Use standard license header.
diego
parents: 26710
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
0f892cd714b2 Use standard license header.
diego
parents: 26710
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: 26710
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: 26710
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: 26710
diff changeset
17 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
18
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
19 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
20
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24 #include <string.h>
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
25 #include <strings.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 #include <sys/types.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #include <sys/stat.h>
22292
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
28 #include <inttypes.h>
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
29 #include <ft2build.h>
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
30 #include FT_FREETYPE_H
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
32 #include "ass_utils.h"
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
33 #include "ass.h"
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
34 #include "ass_library.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 #include "ass_fontconfig.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
37 #ifdef CONFIG_FONTCONFIG
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38 #include <fontconfig/fontconfig.h>
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
39 #include <fontconfig/fcfreetype.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
42 struct fc_instance {
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
43 #ifdef CONFIG_FONTCONFIG
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
44 FcConfig *config;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
46 char *family_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
47 char *path_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 int index_default;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
51 #ifdef CONFIG_FONTCONFIG
26660
ab5729095d68 Define FC_FULLNAME and FC_EMBOLDEN to fix compilation with ancient fontconfig.
eugeni
parents: 26659
diff changeset
52
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53 /**
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
54 * \brief Case-insensitive match ASS/SSA font family against full name. (also
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
55 * known as "name for humans")
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
56 *
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
57 * \param lib library instance
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
58 * \param priv fontconfig instance
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
59 * \param family font fullname
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
60 * \param bold weight attribute
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
61 * \param italic italic attribute
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
62 * \return font set
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
63 */
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
64 static FcFontSet *
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
65 match_fullname(ASS_Library *lib, FCInstance *priv, const char *family,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
66 unsigned bold, unsigned italic)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
67 {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
68 FcFontSet *sets[2];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
69 FcFontSet *result = FcFontSetCreate();
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
70 int nsets = 0;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
71 int i, fi;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
72
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
73 if ((sets[nsets] = FcConfigGetFonts(priv->config, FcSetSystem)))
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
74 nsets++;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
75 if ((sets[nsets] = FcConfigGetFonts(priv->config, FcSetApplication)))
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
76 nsets++;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
77
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
78 // Run over font sets and patterns and try to match against full name
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
79 for (i = 0; i < nsets; i++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
80 FcFontSet *set = sets[i];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
81 for (fi = 0; fi < set->nfont; fi++) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
82 FcPattern *pat = set->fonts[fi];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
83 char *fullname;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
84 int pi = 0, at;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
85 FcBool ol;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
86 while (FcPatternGetString(pat, FC_FULLNAME, pi++,
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
87 (FcChar8 **) &fullname) == FcResultMatch) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
88 if (FcPatternGetBool(pat, FC_OUTLINE, 0, &ol) != FcResultMatch
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
89 || ol != FcTrue)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
90 continue;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
91 if (FcPatternGetInteger(pat, FC_SLANT, 0, &at) != FcResultMatch
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
92 || at < italic)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
93 continue;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
94 if (FcPatternGetInteger(pat, FC_WEIGHT, 0, &at) != FcResultMatch
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
95 || at < bold)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
96 continue;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
97 if (strcasecmp(fullname, family) == 0) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
98 FcFontSetAdd(result, FcPatternDuplicate(pat));
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
99 break;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
100 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
101 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
102 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
103 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
104
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
105 return result;
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
106 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
107
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
108 /**
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 * \brief Low-level font selection.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110 * \param priv private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 * \param family font family
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
112 * \param treat_family_as_pattern treat family as fontconfig pattern
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
115 * \param index out: font index inside a file
23980
27bac14b4ce4 More simple and correct font reselection.
eugeni
parents: 23216
diff changeset
116 * \param code: the character that should be present in the font, can be 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 * \return font file path
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
118 */
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
119 static char *select_font(ASS_Library *library, FCInstance *priv,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
120 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
122 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
124 FcBool rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 FcResult result;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126 FcPattern *pat = NULL, *rpat = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 int r_index, r_slant, r_weight;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
128 FcChar8 *r_family, *r_style, *r_file, *r_fullname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
129 FcBool r_outline, r_embolden;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
130 FcCharSet *r_charset;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
131 FcFontSet *ffullname = NULL, *fsorted = NULL, *fset = NULL;
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
132 int curf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
133 char *retval = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
134 int family_cnt = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
135
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
136 *index = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 if (treat_family_as_pattern)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 pat = FcNameParse((const FcChar8 *) family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 pat = FcPatternCreate();
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
142
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
143 if (!pat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
144 goto error;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
145
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 if (!treat_family_as_pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
147 FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *) family);
26591
0f069e41d8d2 Allow inexact font family matching.
eugeni
parents: 26582
diff changeset
148
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
149 // In SSA/ASS fonts are sometimes referenced by their "full name",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
150 // which is usually a concatenation of family name and font
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
151 // style (ex. Ottawa Bold). Full name is available from
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
152 // FontConfig pattern element FC_FULLNAME, but it is never
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
153 // used for font matching.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
154 // Therefore, I'm removing words from the end of the name one
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
155 // by one, and adding shortened names to the pattern. It seems
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
156 // that the first value (full name in this case) has
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
157 // precedence in matching.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
158 // An alternative approach could be to reimplement FcFontSort
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
159 // using FC_FULLNAME instead of FC_FAMILY.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
160 family_cnt = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
161 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
162 char *s = strdup(family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
163 char *p = s + strlen(s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
164 while (--p > s)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
165 if (*p == ' ' || *p == '-') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
166 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
167 FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *) s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
168 ++family_cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
169 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
170 free(s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
171 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
172 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
173 FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
174 FcPatternAddInteger(pat, FC_SLANT, italic);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
175 FcPatternAddInteger(pat, FC_WEIGHT, bold);
19063
5525af2ee4c7 Use FcPatternAdd-Type instead of FcNameParse. The latter, as it turns out, requires escaping of some characters ('-', maybe more).
eugeni
parents: 19001
diff changeset
176
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
177 FcDefaultSubstitute(pat);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
178
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
179 rc = FcConfigSubstitute(priv->config, pat, FcMatchPattern);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
180 if (!rc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
181 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
182
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
183 fsorted = FcFontSort(priv->config, pat, FcTrue, NULL, &result);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
184 ffullname = match_fullname(library, priv, family, bold, italic);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
185 if (!fsorted || !ffullname)
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
186 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
187
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
188 fset = FcFontSetCreate();
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
189 for (curf = 0; curf < ffullname->nfont; ++curf) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
190 FcPattern *curp = ffullname->fonts[curf];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
191 FcPatternReference(curp);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
192 FcFontSetAdd(fset, curp);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
193 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
194 for (curf = 0; curf < fsorted->nfont; ++curf) {
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
195 FcPattern *curp = fsorted->fonts[curf];
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
196 FcPatternReference(curp);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
197 FcFontSetAdd(fset, curp);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
198 }
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
199
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
200 for (curf = 0; curf < fset->nfont; ++curf) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
201 FcPattern *curp = fset->fonts[curf];
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
202
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
203 result = FcPatternGetBool(curp, FC_OUTLINE, 0, &r_outline);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
204 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
205 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
206 if (r_outline != FcTrue)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
207 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
208 if (!code)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
209 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
210 result = FcPatternGetCharSet(curp, FC_CHARSET, 0, &r_charset);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
211 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
212 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
213 if (FcCharSetHasChar(r_charset, code))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
214 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
215 }
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
216
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
217 if (curf >= fset->nfont)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
218 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
219
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
220 if (!treat_family_as_pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
221 // Remove all extra family names from original pattern.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
222 // After this, FcFontRenderPrepare will select the most relevant family
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
223 // name in case there are more than one of them.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
224 for (; family_cnt > 1; --family_cnt)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
225 FcPatternRemove(pat, FC_FAMILY, family_cnt - 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
226 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
227
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
228 rpat = FcFontRenderPrepare(priv->config, pat, fset->fonts[curf]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
229 if (!rpat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
230 goto error;
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
231
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
232 result = FcPatternGetInteger(rpat, FC_INDEX, 0, &r_index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
233 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
234 goto error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
235 *index = r_index;
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
236
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
237 result = FcPatternGetString(rpat, FC_FILE, 0, &r_file);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
238 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
239 goto error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
240 retval = strdup((const char *) r_file);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
241
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
242 result = FcPatternGetString(rpat, FC_FAMILY, 0, &r_family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
243 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
244 r_family = NULL;
26614
875a7878626c Move font family check to the end of the list.
eugeni
parents: 26613
diff changeset
245
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
246 result = FcPatternGetString(rpat, FC_FULLNAME, 0, &r_fullname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
247 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
248 r_fullname = NULL;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
249
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
250 if (!treat_family_as_pattern &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
251 !(r_family && strcasecmp((const char *) r_family, family) == 0) &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
252 !(r_fullname && strcasecmp((const char *) r_fullname, family) == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
253 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
254 "fontconfig: Selected font is not the requested one: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
255 "'%s' != '%s'",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
256 (const char *) (r_fullname ? r_fullname : r_family), family);
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
257
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
258 result = FcPatternGetString(rpat, FC_STYLE, 0, &r_style);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
259 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
260 r_style = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
261
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
262 result = FcPatternGetInteger(rpat, FC_SLANT, 0, &r_slant);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
263 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
264 r_slant = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
265
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
266 result = FcPatternGetInteger(rpat, FC_WEIGHT, 0, &r_weight);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
267 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
268 r_weight = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
269
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
270 result = FcPatternGetBool(rpat, FC_EMBOLDEN, 0, &r_embolden);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
271 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
272 r_embolden = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
273
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
274 ass_msg(library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
275 "Font info: family '%s', style '%s', fullname '%s',"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
276 " slant %d, weight %d%s", (const char *) r_family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
277 (const char *) r_style, (const char *) r_fullname, r_slant,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
278 r_weight, r_embolden ? ", embolden" : "");
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
279
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
280 error:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
281 if (pat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
282 FcPatternDestroy(pat);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
283 if (rpat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
284 FcPatternDestroy(rpat);
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
285 if (fsorted)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
286 FcFontSetDestroy(fsorted);
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
287 if (ffullname)
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
288 FcFontSetDestroy(ffullname);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
289 if (fset)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
290 FcFontSetDestroy(fset);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
291 return retval;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
292 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
293
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
294 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
295 * \brief Find a font. Use default family or path if necessary.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
296 * \param priv_ private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
297 * \param family font family
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
298 * \param treat_family_as_pattern treat family as fontconfig pattern
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
299 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
300 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
301 * \param index out: font index inside a file
23980
27bac14b4ce4 More simple and correct font reselection.
eugeni
parents: 23216
diff changeset
302 * \param code: the character that should be present in the font, can be 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
303 * \return font file path
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
304 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
305 char *fontconfig_select(ASS_Library *library, FCInstance *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
306 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
307 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
308 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
309 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
310 char *res = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
311 if (!priv->config) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
312 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
313 res = priv->path_default ? strdup(priv->path_default) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
314 return res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
315 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
316 if (family && *family)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
317 res =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
318 select_font(library, priv, family, treat_family_as_pattern,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
319 bold, italic, index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
320 if (!res && priv->family_default) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
321 res =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
322 select_font(library, priv, priv->family_default, 0, bold,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
323 italic, index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
324 if (res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
325 ass_msg(library, MSGL_WARN, "fontconfig_select: Using default "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
326 "font family: (%s, %d, %d) -> %s, %d",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
327 family, bold, italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
328 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
329 if (!res && priv->path_default) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
330 res = strdup(priv->path_default);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
331 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
332 ass_msg(library, MSGL_WARN, "fontconfig_select: Using default font: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
333 "(%s, %d, %d) -> %s, %d", family, bold, italic,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
334 res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
335 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
336 if (!res) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
337 res = select_font(library, priv, "Arial", 0, bold, italic,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
338 index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
339 if (res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
340 ass_msg(library, MSGL_WARN, "fontconfig_select: Using 'Arial' "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
341 "font family: (%s, %d, %d) -> %s, %d", family, bold,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
342 italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
343 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
344 if (res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
345 ass_msg(library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
346 "fontconfig_select: (%s, %d, %d) -> %s, %d", family, bold,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
347 italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
348 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
349 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
350
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
351 /**
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
352 * \brief Process memory font.
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
353 * \param priv private data
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
354 * \param library library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
355 * \param ftlibrary freetype library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
356 * \param idx index of the processed font in library->fontdata
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
357 *
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
358 * Builds a font pattern in memory via FT_New_Memory_Face/FcFreeTypeQueryFace.
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
359 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
360 static void process_fontdata(FCInstance *priv, ASS_Library *library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
361 FT_Library ftlibrary, int idx)
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
362 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
363 int rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
364 const char *name = library->fontdata[idx].name;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
365 const char *data = library->fontdata[idx].data;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
366 int data_size = library->fontdata[idx].size;
23216
b863ed752149 Move variables and a function under #ifdef FC_VERSION to avoid warnings.
eugeni
parents: 23215
diff changeset
367
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
368 FT_Face face;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
369 FcPattern *pattern;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
370 FcFontSet *fset;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
371 FcBool res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
372 int face_index, num_faces = 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
373
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
374 for (face_index = 0; face_index < num_faces; ++face_index) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
375 rc = FT_New_Memory_Face(ftlibrary, (unsigned char *) data,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
376 data_size, face_index, &face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
377 if (rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
378 ass_msg(library, MSGL_WARN, "Error opening memory font: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
379 name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
380 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
381 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
382 num_faces = face->num_faces;
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
383
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
384 pattern =
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
385 FcFreeTypeQueryFace(face, (unsigned char *) name, face_index,
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
386 FcConfigGetBlanks(priv->config));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
387 if (!pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
388 ass_msg(library, MSGL_WARN, "%s failed", "FcFreeTypeQueryFace");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
389 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
390 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
391 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
392
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
393 fset = FcConfigGetFonts(priv->config, FcSetSystem); // somehow it failes when asked for FcSetApplication
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
394 if (!fset) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
395 ass_msg(library, MSGL_WARN, "%s failed", "FcConfigGetFonts");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
396 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
397 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
398 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
399
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
400 res = FcFontSetAdd(fset, pattern);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
401 if (!res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
402 ass_msg(library, MSGL_WARN, "%s failed", "FcFontSetAdd");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
403 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
404 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
405 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
406
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
407 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
408 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
409 }
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
410
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
411 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
412 * \brief Init fontconfig.
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
413 * \param library libass library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
414 * \param ftlibrary freetype library object
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
415 * \param family default font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
416 * \param path default font path
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
417 * \param fc whether fontconfig should be used
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
418 * \param config path to a fontconfig configuration file, or NULL
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
419 * \param update whether the fontconfig cache should be built/updated
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
420 * \return pointer to fontconfig private data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
421 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
422 FCInstance *fontconfig_init(ASS_Library *library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
423 FT_Library ftlibrary, const char *family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
424 const char *path, int fc, const char *config,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
425 int update)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
426 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
427 int rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
428 FCInstance *priv = calloc(1, sizeof(FCInstance));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
429 const char *dir = library->fonts_dir;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
430 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
431
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
432 if (!fc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
433 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
434 "Fontconfig disabled, only default font will be used.");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
435 goto exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
436 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
437
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
438 priv->config = FcConfigCreate();
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
439 rc = FcConfigParseAndLoad(priv->config, (unsigned char *) config, FcTrue);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
440 if (!rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
441 ass_msg(library, MSGL_WARN, "No usable fontconfig configuration "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
442 "file found, using fallback.");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
443 FcConfigDestroy(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
444 priv->config = FcInitLoadConfig();
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
445 rc++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
446 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
447 if (rc && update) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
448 FcConfigBuildFonts(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
449 }
27095
a0e00d065593 Reindent.
eugeni
parents: 27094
diff changeset
450
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
451 if (!rc || !priv->config) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
452 ass_msg(library, MSGL_FATAL,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
453 "No valid fontconfig configuration found!");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
454 FcConfigDestroy(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
455 goto exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
456 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
457
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
458 for (i = 0; i < library->num_fontdata; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
459 process_fontdata(priv, library, ftlibrary, i);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
460
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
461 if (dir) {
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
462 ass_msg(library, MSGL_V, "Updating font cache");
27095
a0e00d065593 Reindent.
eugeni
parents: 27094
diff changeset
463
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
464 rc = FcConfigAppFontAddDir(priv->config, (const FcChar8 *) dir);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
465 if (!rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
466 ass_msg(library, MSGL_WARN, "%s failed", "FcConfigAppFontAddDir");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
467 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
468 }
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
469
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
470 priv->family_default = family ? strdup(family) : NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
471 exit:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
472 priv->path_default = path ? strdup(path) : NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
473 priv->index_default = 0;
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
474
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
475 return priv;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
476 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
477
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
478 int fontconfig_update(FCInstance *priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
479 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
480 return FcConfigBuildFonts(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
481 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
482
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
483 #else /* CONFIG_FONTCONFIG */
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
484
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
485 char *fontconfig_select(ASS_Library *library, FCInstance *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
486 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
487 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
488 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
489 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
490 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
491 char* res = priv->path_default ? strdup(priv->path_default) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
492 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
493 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
494
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
495 FCInstance *fontconfig_init(ASS_Library *library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
496 FT_Library ftlibrary, const char *family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
497 const char *path, int fc, const char *config,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
498 int update)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
499 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
500 FCInstance *priv;
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
501
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
502 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
503 "Fontconfig disabled, only default font will be used.");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
504
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
505 priv = calloc(1, sizeof(FCInstance));
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
506
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
507 priv->path_default = path ? strdup(path) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
508 priv->index_default = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
509 return priv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
510 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
511
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
512 int fontconfig_update(FCInstance *priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
513 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
514 // Do nothing
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
515 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
516 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
517
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
518 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
519
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
520 void fontconfig_done(FCInstance *priv)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
521 {
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
522
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
523 if (priv) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
524 #ifdef CONFIG_FONTCONFIG
34011
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
525 if (priv->config)
88eebbbbd6a0 Update included libass copy to 0.9.13 release.
reimar
parents: 31875
diff changeset
526 FcConfigDestroy(priv->config);
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
527 #endif
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
528 free(priv->path_default);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
529 free(priv->family_default);
31875
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
530 }
ac6e48baa03d Import libass 0.9.11
greg
parents: 31853
diff changeset
531 free(priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
532 }