annotate libass/ass_fontconfig.c @ 20368:10aa009aa75a

r20369: Warn about dangers of -use-filedir-conf option r20375: capitalization at beginning of sentence
author kraymer
date Sun, 22 Oct 2006 17:10:36 +0000
parents bcb586a0800c
children e8885ec63928
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 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
3 /*
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
5
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
6 This program is free software; you can redistribute it and/or modify
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
7 it under the terms of the GNU General Public License as published by
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
8 the Free Software Foundation; either version 2 of the License, or
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
9 (at your option) any later version.
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
10
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
11 This program is distributed in the hope that it will be useful,
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
14 GNU General Public License for more details.
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
15
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
16 You should have received a copy of the GNU General Public License
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
17 along with this program; if not, write to the Free Software
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19902
diff changeset
19 */
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>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 #include "ass_fontconfig.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 #include <fontconfig/fontconfig.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 struct fc_instance_s {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
39 FcConfig* config;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 char* family_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42 char* path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43 int index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46 extern int no_more_font_messages;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 * \brief Low-level font selection.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51 * \param priv private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52 * \param family font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55 * \param index out: font index inside a file
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 * \return font file path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 FcBool rc;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61 FcResult result;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
62 FcPattern *pat, *rpat;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63 int val_i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
64 FcChar8* val_s;
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
65 FcBool val_b;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67 *index = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
68
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
69 pat = FcPatternCreate();
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
70 if (!pat)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
71 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
72
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
73 FcPatternAddString(pat, FC_FAMILY, (const FcChar8*)family);
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
74 FcPatternAddBool(pat, FC_OUTLINE, FcTrue);
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
75 FcPatternAddInteger(pat, FC_SLANT, italic);
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
76 FcPatternAddInteger(pat, FC_WEIGHT, bold);
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
77
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78 FcDefaultSubstitute(pat);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
80 rc = FcConfigSubstitute(priv->config, pat, FcMatchPattern);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81 if (!rc)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
84 rpat = FcFontMatch(priv->config, pat, &result);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
85 if (!rpat)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
88 result = FcPatternGetBool(rpat, FC_OUTLINE, 0, &val_b);
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
89 if (result != FcResultMatch)
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
90 return 0;
19064
1ca92a0b7703 Cosmetics.
eugeni
parents: 19063
diff changeset
91 if (val_b != FcTrue)
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
92 return 0;
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
93
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
94 result = FcPatternGetInteger(rpat, FC_INDEX, 0, &val_i);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
95 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
97 *index = val_i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
99 result = FcPatternGetString(rpat, FC_FAMILY, 0, &val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
100 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
101 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
103 if (strcasecmp((const char*)val_s, family) != 0)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
104 mp_msg(MSGT_GLOBAL, MSGL_WARN, "fontconfig: selected font family is not the requested one: '%s' != '%s'\n",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
105 (const char*)val_s, family);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
106
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
107 result = FcPatternGetString(rpat, FC_FILE, 0, &val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 return strdup((const char*)val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
112 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
115 * \brief Find a font. Use default family or path if necessary.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
116 * \param priv_ private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 * \param family font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
119 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
120 * \param index out: font index inside a file
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
121 * \return font file path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
122 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123 char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
124 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
125 char* res = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
126 if (family && *family)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
127 res = _select_font(priv, family, bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
128 if (!res && priv->family_default) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
129 res = _select_font(priv, priv->family_default, bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130 if (res && !no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131 mp_msg(MSGT_GLOBAL, MSGL_WARN, "fontconfig_select: using default font family: (%s, %d, %d) -> %s, %d\n",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
132 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
133 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
134 if (!res && priv->path_default) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
135 res = priv->path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
136 *index = priv->index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 if (!no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 mp_msg(MSGT_GLOBAL, MSGL_WARN, "fontconfig_select: using default font: (%s, %d, %d) -> %s, %d\n",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
140 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
141 if (!res) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
142 res = _select_font(priv, "Arial", bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
143 if (res && !no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
144 mp_msg(MSGT_GLOBAL, MSGL_WARN, "fontconfig_select: using 'Arial' font family: (%s, %d, %d) -> %s, %d\n",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
145 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
147 if (res)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148 mp_msg(MSGT_GLOBAL, MSGL_V, "fontconfig_select: (%s, %d, %d) -> %s, %d\n",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 return res;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
152
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
153 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
154 * \brief Init fontconfig.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
155 * \param dir additional directoryu for fonts
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
156 * \param family default font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
157 * \param path default font path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
158 * \return pointer to fontconfig private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
159 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
160 fc_instance_t* fontconfig_init(const char* dir, const char* family, const char* path)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
161 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
162 int rc;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
163 struct stat st;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
164 fc_instance_t* priv = calloc(1, sizeof(fc_instance_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
165
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
166 rc = FcInit();
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
167 assert(rc);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
168
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
169 priv->config = FcConfigGetCurrent();
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
170 if (!priv->config) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
171 mp_msg(MSGT_GLOBAL, MSGL_FATAL, "FcInitLoadConfigAndFonts failed\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
172 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
173 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
175 if (FcDirCacheValid((const FcChar8 *)dir) == FcFalse)
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
176 {
19901
27b87a9dc19a Don't call FcDirScan/FcDirSave with FontConfig >= 2.4.
eugeni
parents: 19481
diff changeset
177 mp_msg(MSGT_GLOBAL, MSGL_INFO, "[ass] Updating font cache\n");
20105
bcb586a0800c Avoid crash with fontconfig 2.3.9x (as shipped with SuSE 10.1, FcDirScan is broken)
reimar
parents: 20008
diff changeset
178 if (FcGetVersion() >= 20390 && FcGetVersion() < 20400)
bcb586a0800c Avoid crash with fontconfig 2.3.9x (as shipped with SuSE 10.1, FcDirScan is broken)
reimar
parents: 20008
diff changeset
179 mp_msg(MSGT_GLOBAL, MSGL_WARN,
bcb586a0800c Avoid crash with fontconfig 2.3.9x (as shipped with SuSE 10.1, FcDirScan is broken)
reimar
parents: 20008
diff changeset
180 "[ass] beta versions of fontconfig are not supported\n"
bcb586a0800c Avoid crash with fontconfig 2.3.9x (as shipped with SuSE 10.1, FcDirScan is broken)
reimar
parents: 20008
diff changeset
181 " update before reporting any bugs\n");
19901
27b87a9dc19a Don't call FcDirScan/FcDirSave with FontConfig >= 2.4.
eugeni
parents: 19481
diff changeset
182 // FontConfig >= 2.4.0 updates cache automatically in FcConfigAppFontAddDir()
20105
bcb586a0800c Avoid crash with fontconfig 2.3.9x (as shipped with SuSE 10.1, FcDirScan is broken)
reimar
parents: 20008
diff changeset
183 if (FcGetVersion() < 20390) {
19902
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
184 FcFontSet* fcs;
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
185 FcStrSet* fss;
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
186 fcs = FcFontSetCreate();
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
187 fss = FcStrSetCreate();
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
188 rc = FcStrSetAdd(fss, (const FcChar8*)dir);
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
189 if (!rc) {
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
190 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcStrSetAdd failed\n");
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
191 goto ErrorFontCache;
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
192 }
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
193
19902
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
194 rc = FcDirScan(fcs, fss, NULL, FcConfigGetBlanks(priv->config), (const FcChar8 *)dir, FcFalse);
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
195 if (!rc) {
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
196 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcDirScan failed\n");
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
197 goto ErrorFontCache;
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
198 }
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
199
19902
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
200 rc = FcDirSave(fcs, fss, (const FcChar8 *)dir);
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
201 if (!rc) {
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
202 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcDirSave failed\n");
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
203 goto ErrorFontCache;
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
204 }
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
205 ErrorFontCache:
2c43912bb46a Cosmetics: fix indentation after last commit.
eugeni
parents: 19901
diff changeset
206 ;
19901
27b87a9dc19a Don't call FcDirScan/FcDirSave with FontConfig >= 2.4.
eugeni
parents: 19481
diff changeset
207 }
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
208 }
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
209
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
210 rc = FcConfigAppFontAddDir(priv->config, (const FcChar8*)dir);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
211 if (!rc) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcConfigAppFontAddDir failed\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
213 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
214
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
215 priv->family_default = family ? strdup(family) : 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 priv->index_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
217
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
218 rc = stat(path, &st);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
219 if (!rc && S_ISREG(st.st_mode))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
220 priv->path_default = path ? strdup(path) : 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 else
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222 priv->path_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224 return priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
227 #else
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
228
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
230 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
231 *index = priv->index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
232 return priv->path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
233 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
235 fc_instance_t* fontconfig_init(const char* dir, const char* family, const char* path)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
236 {
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
237 fc_instance_t* priv;
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
238
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
239 mp_msg(MSGT_GLOBAL, MSGL_WARN, "Fontconfig disabled, only default font will be used\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
240
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
241 priv = calloc(1, sizeof(fc_instance_t));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
242
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
243 priv->path_default = strdup(path);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
244 priv->index_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
245 return priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
246 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
247
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
248 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
249
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
250 void fontconfig_done(fc_instance_t* priv)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
251 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
252 // don't call FcFini() here, library can still be used by some code
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
253 if (priv && priv->path_default) free(priv->path_default);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
254 if (priv && priv->family_default) free(priv->family_default);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
255 if (priv) free(priv);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
258