annotate libass/ass_fontconfig.c @ 19696:0b07e95ca082

FFmpeg sync: Fall back on grep if svn client is not installed.
author diego
date Tue, 05 Sep 2006 23:19:22 +0000
parents 5890c54b755c
children 27b87a9dc19a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
3 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
4 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
5 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
6 #include <string.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
7 #include <sys/types.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
8 #include <sys/stat.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
9
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
10 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
11 #include "ass_fontconfig.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
12
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
13 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
14 #include <fontconfig/fontconfig.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
15 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
16
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
17 struct fc_instance_s {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
18 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
19 FcConfig* config;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
20 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 char* family_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 char* path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 int index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 extern int no_more_font_messages;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #ifdef HAVE_FONTCONFIG
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 * \brief Low-level font selection.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 * \param priv private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32 * \param family font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 * \param index out: font index inside a file
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36 * \return font file path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38 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
39 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40 FcBool rc;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 FcResult result;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42 FcPattern *pat, *rpat;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43 int val_i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44 FcChar8* val_s;
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
45 FcBool val_b;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47 *index = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48
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
49 pat = FcPatternCreate();
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 if (!pat)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52
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
53 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
54 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
55 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
56 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
57
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 FcDefaultSubstitute(pat);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 rc = FcConfigSubstitute(priv->config, pat, FcMatchPattern);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61 if (!rc)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
62 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
64 rpat = FcFontMatch(priv->config, pat, &result);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
65 if (!rpat)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
68 result = FcPatternGetBool(rpat, FC_OUTLINE, 0, &val_b);
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
69 if (result != FcResultMatch)
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
70 return 0;
19064
1ca92a0b7703 Cosmetics.
eugeni
parents: 19063
diff changeset
71 if (val_b != FcTrue)
19001
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
72 return 0;
31b7033c573e Only match outline fonts.
eugeni
parents: 18937
diff changeset
73
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
74 result = FcPatternGetInteger(rpat, FC_INDEX, 0, &val_i);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
75 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
76 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
77 *index = val_i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79 result = FcPatternGetString(rpat, FC_FAMILY, 0, &val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
80 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83 if (strcasecmp((const char*)val_s, family) != 0)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
84 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
85 (const char*)val_s, family);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87 result = FcPatternGetString(rpat, FC_FILE, 0, &val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 if (result != FcResultMatch)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
89 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
90
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
91 return strdup((const char*)val_s);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
92 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
93
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
94 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
95 * \brief Find a font. Use default family or path if necessary.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96 * \param priv_ private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
97 * \param family font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98 * \param bold font weight value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
99 * \param italic font slant value
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
100 * \param index out: font index inside a file
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
101 * \return font file path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
103 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
104 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
105 char* res = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
106 if (family && *family)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
107 res = _select_font(priv, family, bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 if (!res && priv->family_default) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 res = _select_font(priv, priv->family_default, bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110 if (res && !no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 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
112 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114 if (!res && priv->path_default) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
115 res = priv->path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
116 *index = priv->index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 if (!no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118 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
119 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
120 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
121 if (!res) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
122 res = _select_font(priv, "Arial", bold, italic, index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123 if (res && !no_more_font_messages)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
124 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
125 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
126 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
127 if (res)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
128 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
129 family, bold, italic, res, *index);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130 return res;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
132
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
133 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
134 * \brief Init fontconfig.
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
135 * \param dir additional directoryu for fonts
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
136 * \param family default font family
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 * \param path default font path
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 * \return pointer to fontconfig private data
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
140 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
141 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
142 int rc;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
143 struct stat st;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
144 fc_instance_t* priv = calloc(1, sizeof(fc_instance_t));
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
145
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 rc = FcInit();
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
147 assert(rc);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149 priv->config = FcConfigGetCurrent();
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 if (!priv->config) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151 mp_msg(MSGT_GLOBAL, MSGL_FATAL, "FcInitLoadConfigAndFonts failed\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
152 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
153 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
154
19340
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
155 if (FcDirCacheValid((const FcChar8 *)dir) == FcFalse)
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
156 {
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
157 FcFontSet* fcs;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
158 FcStrSet* fss;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
159 mp_msg(MSGT_GLOBAL, MSGL_INFO, "[ass] Updating font cache\n");
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
160 fcs = FcFontSetCreate();
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
161 fss = FcStrSetCreate();
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
162 rc = FcStrSetAdd(fss, (const FcChar8*)dir);
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
163 if (!rc) {
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
164 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcStrSetAdd failed\n");
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
165 goto ErrorFontCache;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
166 }
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
167
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
168 rc = FcDirScan(fcs, fss, NULL, FcConfigGetBlanks(priv->config), (const FcChar8 *)dir, FcFalse);
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
169 if (!rc) {
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
170 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcDirScan failed\n");
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
171 goto ErrorFontCache;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
172 }
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
173
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
174 rc = FcDirSave(fcs, fss, (const FcChar8 *)dir);
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
175 if (!rc) {
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
176 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcDirSave failed\n");
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
177 goto ErrorFontCache;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
178 }
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
179 ErrorFontCache:
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
180 ;
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
181 }
f0d49f38ce97 Use FontConfig cache to speedup mplayer startup.
eugeni
parents: 19064
diff changeset
182
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
183 rc = FcConfigAppFontAddDir(priv->config, (const FcChar8*)dir);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
184 if (!rc) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
185 mp_msg(MSGT_GLOBAL, MSGL_WARN, "FcConfigAppFontAddDir failed\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
186 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
187
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
188 priv->family_default = family ? strdup(family) : 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
189 priv->index_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
190
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
191 rc = stat(path, &st);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
192 if (!rc && S_ISREG(st.st_mode))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
193 priv->path_default = path ? strdup(path) : 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
194 else
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 priv->path_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
196
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
197 return priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
199
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200 #else
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
201
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
202 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
203 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
204 *index = priv->index_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
205 return priv->path_default;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
206 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
207
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
208 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
209 {
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
210 fc_instance_t* priv;
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
211
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 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
213
19481
5890c54b755c no c++ decls!
rfelker
parents: 19340
diff changeset
214 priv = calloc(1, sizeof(fc_instance_t));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
215
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 priv->path_default = strdup(path);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
217 priv->index_default = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
218 return priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
219 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
220
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 #endif
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223 void fontconfig_done(fc_instance_t* priv)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 // don't call FcFini() here, library can still be used by some code
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226 if (priv && priv->path_default) free(priv->path_default);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
227 if (priv && priv->family_default) free(priv->family_default);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
228 if (priv) free(priv);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
230
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
231