66
57
* \param bold font weight value
67
58
* \param italic font slant value
68
59
* \param index out: font index inside a file
69
* \param charset: contains the characters that should be present in the font, can be NULL
60
* \param code: the character that should be present in the font, can be 0
70
61
* \return font file path
72
63
static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
103
94
fset = FcFontSort(priv->config, pat, FcTrue, NULL, &result);
107
bestdiff = FcCharSetCount(charset) + 1;
108
96
for (curf = 0; curf < fset->nfont; ++curf) {
109
97
rpat = fset->fonts[curf];
114
102
if (val_b != FcTrue)
119
result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
120
if (result != FcResultMatch)
122
diff = FcCharSetSubtractCount(charset, val_cs);
123
if (diff < bestdiff) {
106
result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
107
if (result != FcResultMatch)
109
if (FcCharSetHasChar(val_cs, code))
113
if (curf >= fset->nfont)
138
rpat = fset->fonts[bestf];
116
rpat = fset->fonts[curf];
140
118
result = FcPatternGetInteger(rpat, FC_INDEX, 0, &val_i);
141
119
if (result != FcResultMatch)
168
146
* \param bold font weight value
169
147
* \param italic font slant value
170
148
* \param index out: font index inside a file
171
* \param charset: contains the characters that should be present in the font, can be NULL
149
* \param code: the character that should be present in the font, can be 0
172
150
* \return font file path
174
char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
152
char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
178
156
if (family && *family)
179
res = _select_font(priv, family, bold, italic, index, charset);
157
res = _select_font(priv, family, bold, italic, index, code);
180
158
if (!res && priv->family_default) {
181
res = _select_font(priv, priv->family_default, bold, italic, index, charset);
159
res = _select_font(priv, priv->family_default, bold, italic, index, code);
183
161
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingDefaultFontFamily,
184
162
family, bold, italic, res, *index);
190
168
family, bold, italic, res, *index);
193
res = _select_font(priv, "Arial", bold, italic, index, charset);
171
res = _select_font(priv, "Arial", bold, italic, index, code);
195
173
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingArialFontFamily,
196
174
family, bold, italic, res, *index);
204
char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
206
return fontconfig_select_with_charset(priv, family, bold, italic, index, 0);
209
182
#if (FC_VERSION < 20402)
210
183
static char* validate_fname(char* name)
408
381
#else // HAVE_FONTCONFIG
410
char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
383
char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
412
386
*index = priv->index_default;
413
387
return priv->path_default;