annotate libass/ass_fontconfig.c @ 33478:a86e08ff3198

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