annotate libass/ass_fontconfig.c @ 31790:224ed68c32e2

sync with en/mplayer.1 rev. 31814
author jrash
date Fri, 30 Jul 2010 14:11:05 +0000
parents 48d020c5ceca
children e64df5862cea
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>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #include <sys/types.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #include <sys/stat.h>
22292
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
29 #include <inttypes.h>
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
30 #include <ft2build.h>
2f3f27a014ef Add some missing includes.
eugeni
parents: 21630
diff changeset
31 #include FT_FREETYPE_H
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
33 #include "ass_utils.h"
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
34 #include "ass.h"
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
35 #include "ass_library.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36 #include "ass_fontconfig.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
38 #ifdef CONFIG_FONTCONFIG
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
39 #include <fontconfig/fontconfig.h>
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
40 #include <fontconfig/fcfreetype.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
43 struct fc_instance {
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
44 #ifdef CONFIG_FONTCONFIG
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
45 FcConfig *config;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46 #endif
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
47 char *family_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
48 char *path_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
49 int index_default;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51
27393
4876c89bafdd Rename font-related preprocessor directives.
diego
parents: 27096
diff changeset
52 #ifdef CONFIG_FONTCONFIG
26660
ab5729095d68 Define FC_FULLNAME and FC_EMBOLDEN to fix compilation with ancient fontconfig.
eugeni
parents: 26659
diff changeset
53
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55 * \brief Low-level font selection.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 * \param priv private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57 * \param family font family
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
58 * \param treat_family_as_pattern treat family as fontconfig pattern
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61 * \param index out: font index inside a file
23980
27bac14b4ce4 More simple and correct font reselection.
eugeni
parents: 23216
diff changeset
62 * \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
63 * \return font file path
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
64 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
65 static char *_select_font(ASS_Library *library, FCInstance *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
66 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
67 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
68 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
70 FcBool rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
71 FcResult result;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
72 FcPattern *pat = NULL, *rpat = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
73 int r_index, r_slant, r_weight;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
74 FcChar8 *r_family, *r_style, *r_file, *r_fullname;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
75 FcBool r_outline, r_embolden;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
76 FcCharSet *r_charset;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
77 FcFontSet *fset = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
78 int curf;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
79 char *retval = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
80 int family_cnt = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
81
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
82 *index = 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
84 if (treat_family_as_pattern)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
85 pat = FcNameParse((const FcChar8 *) family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
86 else
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
87 pat = FcPatternCreate();
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
88
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
89 if (!pat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
90 goto error;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
91
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
92 if (!treat_family_as_pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
93 FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *) family);
26591
0f069e41d8d2 Allow inexact font family matching.
eugeni
parents: 26582
diff changeset
94
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
95 // In SSA/ASS fonts are sometimes referenced by their "full name",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
96 // which is usually a concatenation of family name and font
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
97 // style (ex. Ottawa Bold). Full name is available from
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
98 // FontConfig pattern element FC_FULLNAME, but it is never
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
99 // used for font matching.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
100 // 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
101 // by one, and adding shortened names to the pattern. It seems
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
102 // that the first value (full name in this case) has
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
103 // precedence in matching.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
104 // An alternative approach could be to reimplement FcFontSort
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
105 // using FC_FULLNAME instead of FC_FAMILY.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
106 family_cnt = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
107 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
108 char *s = strdup(family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
109 char *p = s + strlen(s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
110 while (--p > s)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
111 if (*p == ' ' || *p == '-') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
112 *p = '\0';
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
113 FcPatternAddString(pat, FC_FAMILY, (const FcChar8 *) s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
114 ++family_cnt;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
115 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
116 free(s);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
117 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
118 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
119 FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
120 FcPatternAddInteger(pat, FC_SLANT, italic);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
121 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
122
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
123 FcDefaultSubstitute(pat);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
124
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
125 rc = FcConfigSubstitute(priv->config, pat, FcMatchPattern);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
126 if (!rc)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
127 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
128
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
129 fset = FcFontSort(priv->config, pat, FcTrue, NULL, &result);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
130 if (!fset)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
131 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
132
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
133 for (curf = 0; curf < fset->nfont; ++curf) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
134 FcPattern *curp = fset->fonts[curf];
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
135
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
136 result = FcPatternGetBool(curp, FC_OUTLINE, 0, &r_outline);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
137 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
138 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
139 if (r_outline != FcTrue)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
140 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
141 if (!code)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
142 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
143 result = FcPatternGetCharSet(curp, FC_CHARSET, 0, &r_charset);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
144 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
145 continue;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
146 if (FcCharSetHasChar(r_charset, code))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
147 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
148 }
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
149
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
150 if (curf >= fset->nfont)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
151 goto error;
21351
c611dfc4cb85 If a glyph is not found in the current font, switch to another one.
eugeni
parents: 21279
diff changeset
152
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
153 if (!treat_family_as_pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
154 // Remove all extra family names from original pattern.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
155 // After this, FcFontRenderPrepare will select the most relevant family
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
156 // name in case there are more than one of them.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
157 for (; family_cnt > 1; --family_cnt)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
158 FcPatternRemove(pat, FC_FAMILY, family_cnt - 1);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
159 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
160
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
161 rpat = FcFontRenderPrepare(priv->config, pat, fset->fonts[curf]);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
162 if (!rpat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
163 goto error;
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
164
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
165 result = FcPatternGetInteger(rpat, FC_INDEX, 0, &r_index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
166 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
167 goto error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
168 *index = r_index;
26658
1e1ebebc8f5b Remove extra family names from the search pattern after FcFontSort and
eugeni
parents: 26620
diff changeset
169
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
170 result = FcPatternGetString(rpat, FC_FILE, 0, &r_file);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
171 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
172 goto error;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
173 retval = strdup((const char *) r_file);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
175 result = FcPatternGetString(rpat, FC_FAMILY, 0, &r_family);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
176 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
177 r_family = NULL;
26614
875a7878626c Move font family check to the end of the list.
eugeni
parents: 26613
diff changeset
178
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
179 result = FcPatternGetString(rpat, FC_FULLNAME, 0, &r_fullname);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
180 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
181 r_fullname = NULL;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
182
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
183 if (!treat_family_as_pattern &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
184 !(r_family && strcasecmp((const char *) r_family, family) == 0) &&
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
185 !(r_fullname && strcasecmp((const char *) r_fullname, family) == 0))
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
186 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
187 "fontconfig: Selected font is not the requested one: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
188 "'%s' != '%s'",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
189 (const char *) (r_fullname ? r_fullname : r_family), family);
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
190
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
191 result = FcPatternGetString(rpat, FC_STYLE, 0, &r_style);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
192 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
193 r_style = NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
194
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
195 result = FcPatternGetInteger(rpat, FC_SLANT, 0, &r_slant);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
196 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
197 r_slant = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
198
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
199 result = FcPatternGetInteger(rpat, FC_WEIGHT, 0, &r_weight);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
200 if (result != FcResultMatch)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
201 r_weight = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
202
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
203 result = FcPatternGetBool(rpat, FC_EMBOLDEN, 0, &r_embolden);
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 r_embolden = 0;
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
206
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
207 ass_msg(library, MSGL_V,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
208 "Font info: family '%s', style '%s', fullname '%s',"
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
209 " slant %d, weight %d%s", (const char *) r_family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
210 (const char *) r_style, (const char *) r_fullname, r_slant,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
211 r_weight, r_embolden ? ", embolden" : "");
26616
c37a85037fc2 Print more info about selected font.
eugeni
parents: 26615
diff changeset
212
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
213 error:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
214 if (pat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
215 FcPatternDestroy(pat);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
216 if (rpat)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
217 FcPatternDestroy(rpat);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
218 if (fset)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
219 FcFontSetDestroy(fset);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
220 return retval;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224 * \brief Find a font. Use default family or path if necessary.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 * \param priv_ private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226 * \param family font family
28860
7fcc0bf5b27a Treat -font/-subfont as Fontconfig pattern in libass.
eugeni
parents: 27842
diff changeset
227 * \param treat_family_as_pattern treat family as fontconfig pattern
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
228 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
230 * \param index out: font index inside a file
23980
27bac14b4ce4 More simple and correct font reselection.
eugeni
parents: 23216
diff changeset
231 * \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
232 * \return font file path
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
233 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
234 char *fontconfig_select(ASS_Library *library, FCInstance *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
235 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
236 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
237 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
239 char *res = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
240 if (!priv->config) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
241 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
242 res = priv->path_default ? strdup(priv->path_default) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
243 return res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
244 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
245 if (family && *family)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
246 res =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
247 _select_font(library, priv, family, treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
248 bold, italic, index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
249 if (!res && priv->family_default) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
250 res =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
251 _select_font(library, priv, priv->family_default, 0, bold,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
252 italic, index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
253 if (res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
254 ass_msg(library, MSGL_WARN, "fontconfig_select: Using default "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
255 "font family: (%s, %d, %d) -> %s, %d",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
256 family, bold, italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
257 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
258 if (!res && priv->path_default) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
259 res = strdup(priv->path_default);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
260 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
261 ass_msg(library, MSGL_WARN, "fontconfig_select: Using default font: "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
262 "(%s, %d, %d) -> %s, %d", family, bold, italic,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
263 res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
264 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
265 if (!res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
266 res = _select_font(library, priv, "Arial", 0, bold, italic,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
267 index, code);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
268 if (res)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
269 ass_msg(library, MSGL_WARN, "fontconfig_select: Using 'Arial' "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
270 "font family: (%s, %d, %d) -> %s, %d", family, bold,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
271 italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
272 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
273 if (res)
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 "fontconfig_select: (%s, %d, %d) -> %s, %d", family, bold,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
276 italic, res, *index);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
277 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
278 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
279
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
280 /**
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
281 * \brief Process memory font.
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
282 * \param priv private data
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
283 * \param library library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
284 * \param ftlibrary freetype library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
285 * \param idx index of the processed font in library->fontdata
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
286 * With FontConfig >= 2.4.2, builds a font pattern in memory via FT_New_Memory_Face/FcFreeTypeQueryFace.
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
287 * With older FontConfig versions, save the font to ~/.mplayer/fonts.
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
288 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
289 static void process_fontdata(FCInstance *priv, ASS_Library *library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
290 FT_Library ftlibrary, int idx)
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
291 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
292 int rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
293 const char *name = library->fontdata[idx].name;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
294 const char *data = library->fontdata[idx].data;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
295 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
296
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
297 FT_Face face;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
298 FcPattern *pattern;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
299 FcFontSet *fset;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
300 FcBool res;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
301 int face_index, num_faces = 1;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
302
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
303 for (face_index = 0; face_index < num_faces; ++face_index) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
304 rc = FT_New_Memory_Face(ftlibrary, (unsigned char *) data,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
305 data_size, face_index, &face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
306 if (rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
307 ass_msg(library, MSGL_WARN, "Error opening memory font: %s",
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
308 name);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
309 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
310 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
311 num_faces = face->num_faces;
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
312
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
313 pattern =
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
314 FcFreeTypeQueryFace(face, (unsigned char *) name, 0,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
315 FcConfigGetBlanks(priv->config));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
316 if (!pattern) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
317 ass_msg(library, MSGL_WARN, "%s failed", "FcFreeTypeQueryFace");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
318 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
319 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
320 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
321
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
322 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
323 if (!fset) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
324 ass_msg(library, MSGL_WARN, "%s failed", "FcConfigGetFonts");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
325 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
326 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
327 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
328
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
329 res = FcFontSetAdd(fset, pattern);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
330 if (!res) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
331 ass_msg(library, MSGL_WARN, "%s failed", "FcFontSetAdd");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
332 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
333 return;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
334 }
21460
62bd8e0d3a0f Open embedded fonts directly from memory.
eugeni
parents: 21458
diff changeset
335
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
336 FT_Done_Face(face);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
337 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
338 }
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
339
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
340 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
341 * \brief Init fontconfig.
21630
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
342 * \param library libass library object
0d8005d2fe5c Update some comments.
eugeni
parents: 21615
diff changeset
343 * \param ftlibrary freetype library object
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
344 * \param family default font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
345 * \param path default font path
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
346 * \param fc whether fontconfig should be used
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
347 * \param config path to a fontconfig configuration file, or NULL
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
348 * \param update whether the fontconfig cache should be built/updated
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
349 * \return pointer to fontconfig private data
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
350 */
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
351 FCInstance *fontconfig_init(ASS_Library *library,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
352 FT_Library ftlibrary, const char *family,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
353 const char *path, int fc, const char *config,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
354 int update)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
355 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
356 int rc;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
357 FCInstance *priv = calloc(1, sizeof(FCInstance));
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
358 const char *dir = library->fonts_dir;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
359 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
360
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
361 if (!fc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
362 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
363 "Fontconfig disabled, only default font will be used.");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
364 goto exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
365 }
21458
7af6c25a0cfc Keep embedded fonts in ass_library_t and perform actual disk write
eugeni
parents: 21351
diff changeset
366
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
367 priv->config = FcConfigCreate();
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
368 rc = FcConfigParseAndLoad(priv->config, (unsigned char *) config, FcTrue);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
369 if (!rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
370 ass_msg(library, MSGL_WARN, "No usable fontconfig configuration "
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
371 "file found, using fallback.");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
372 FcConfigDestroy(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
373 priv->config = FcInitLoadConfig();
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
374 rc++;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
375 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
376 if (rc && update) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
377 FcConfigBuildFonts(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
378 }
27095
a0e00d065593 Reindent.
eugeni
parents: 27094
diff changeset
379
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
380 if (!rc || !priv->config) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
381 ass_msg(library, MSGL_FATAL,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
382 "No valid fontconfig configuration found!");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
383 FcConfigDestroy(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
384 goto exit;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
385 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
386
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
387 for (i = 0; i < library->num_fontdata; ++i)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
388 process_fontdata(priv, library, ftlibrary, i);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
389
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
390 if (dir) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
391 ass_msg(library, MSGL_INFO, "Updating font cache");
27095
a0e00d065593 Reindent.
eugeni
parents: 27094
diff changeset
392
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
393 rc = FcConfigAppFontAddDir(priv->config, (const FcChar8 *) dir);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
394 if (!rc) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
395 ass_msg(library, MSGL_WARN, "%s failed", "FcConfigAppFontAddDir");
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
396 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
397 }
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
398
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
399 priv->family_default = family ? strdup(family) : NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
400 exit:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
401 priv->path_default = path ? strdup(path) : NULL;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
402 priv->index_default = 0;
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
403
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
404 return priv;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
405 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
406
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
407 int fontconfig_update(FCInstance *priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
408 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
409 return FcConfigBuildFonts(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
410 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
411
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
412 #else /* CONFIG_FONTCONFIG */
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
413
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
414 char *fontconfig_select(ASS_Library *library, FCInstance *priv,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
415 const char *family, int treat_family_as_pattern,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
416 unsigned bold, unsigned italic, int *index,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
417 uint32_t code)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
418 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
419 *index = priv->index_default;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
420 char* res = priv->path_default ? strdup(priv->path_default) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
421 return res;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
422 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
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 FCInstance *priv;
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
430
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
431 ass_msg(library, MSGL_WARN,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
432 "Fontconfig disabled, only default font will be used.");
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 priv = calloc(1, sizeof(FCInstance));
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28942
diff changeset
435
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
436 priv->path_default = path ? strdup(path) : 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
437 priv->index_default = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
438 return priv;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
439 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
440
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
441 int fontconfig_update(FCInstance *priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
442 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
443 // Do nothing
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
444 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
445 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
446
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
447 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
448
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
449 void fontconfig_done(FCInstance *priv)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
450 {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
451 #ifdef CONFIG_FONTCONFIG
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
452 if (priv && priv->config)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
453 FcConfigDestroy(priv->config);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
454 #endif
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
455 if (priv && priv->path_default)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
456 free(priv->path_default);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
457 if (priv && priv->family_default)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
458 free(priv->family_default);
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
459 if (priv)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents: 29263
diff changeset
460 free(priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
461 }