summaryrefslogtreecommitdiffstats
path: root/libass/ass_fontconfig.c
diff options
context:
space:
mode:
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-08-03 13:43:11 +0000
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-08-03 13:43:11 +0000
commit19e1896e09d486fd42e4900abb135620662f4f7d (patch)
treec122d17a177c7de18132f66927afc8f86c97f5fb /libass/ass_fontconfig.c
parent275dff68aeb193ac2872df877f988b7c33b94250 (diff)
downloadlibass-19e1896e09d486fd42e4900abb135620662f4f7d.tar.bz2
libass-19e1896e09d486fd42e4900abb135620662f4f7d.tar.xz
More simple and correct font reselection.
Since ass_font_t contains a list of font faces, there is no need to select the face with maximum charset coverage each time. It is enough to select any face with the required glyph. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24000 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libass/ass_fontconfig.c')
-rw-r--r--libass/ass_fontconfig.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c
index e1579de..c94434b 100644
--- a/libass/ass_fontconfig.c
+++ b/libass/ass_fontconfig.c
@@ -57,11 +57,11 @@ struct fc_instance_s {
* \param bold font weight value
* \param italic font slant value
* \param index out: font index inside a file
- * \param charset: contains the characters that should be present in the font, can be NULL
+ * \param code: the character that should be present in the font, can be 0
* \return font file path
*/
static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
- FcCharSet* charset)
+ uint32_t code)
{
FcBool rc;
FcResult result;
@@ -71,7 +71,7 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
FcBool val_b;
FcCharSet* val_cs;
FcFontSet* fset = 0;
- int curf, bestf, bestdiff = 0;
+ int curf;
char* retval = 0;
*index = 0;
@@ -93,9 +93,6 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
fset = FcFontSort(priv->config, pat, FcTrue, NULL, &result);
- bestf = -1;
- if (charset)
- bestdiff = FcCharSetCount(charset) + 1;
for (curf = 0; curf < fset->nfont; ++curf) {
rpat = fset->fonts[curf];
@@ -104,29 +101,19 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
continue;
if (val_b != FcTrue)
continue;
-
- if (charset) {
- int diff;
- result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
- if (result != FcResultMatch)
- continue;
- diff = FcCharSetSubtractCount(charset, val_cs);
- if (diff < bestdiff) {
- bestdiff = diff;
- bestf = curf;
- }
- if (diff == 0)
- break;
- } else {
- bestf = curf;
+ if (!code)
+ break;
+ result = FcPatternGetCharSet(rpat, FC_CHARSET, 0, &val_cs);
+ if (result != FcResultMatch)
+ continue;
+ if (FcCharSetHasChar(val_cs, code))
break;
- }
}
- if (bestf < 0)
+ if (curf >= fset->nfont)
goto error;
- rpat = fset->fonts[bestf];
+ rpat = fset->fonts[curf];
result = FcPatternGetInteger(rpat, FC_INDEX, 0, &val_i);
if (result != FcResultMatch)
@@ -159,17 +146,17 @@ static char* _select_font(fc_instance_t* priv, const char* family, unsigned bold
* \param bold font weight value
* \param italic font slant value
* \param index out: font index inside a file
- * \param charset: contains the characters that should be present in the font, can be NULL
+ * \param code: the character that should be present in the font, can be 0
* \return font file path
*/
-char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
- FcCharSet* charset)
+char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index,
+ uint32_t code)
{
char* res = 0;
if (family && *family)
- res = _select_font(priv, family, bold, italic, index, charset);
+ res = _select_font(priv, family, bold, italic, index, code);
if (!res && priv->family_default) {
- res = _select_font(priv, priv->family_default, bold, italic, index, charset);
+ res = _select_font(priv, priv->family_default, bold, italic, index, code);
if (res)
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingDefaultFontFamily,
family, bold, italic, res, *index);
@@ -181,7 +168,7 @@ char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, un
family, bold, italic, res, *index);
}
if (!res) {
- res = _select_font(priv, "Arial", bold, italic, index, charset);
+ res = _select_font(priv, "Arial", bold, italic, index, code);
if (res)
mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_LIBASS_UsingArialFontFamily,
family, bold, italic, res, *index);
@@ -192,11 +179,6 @@ char* fontconfig_select_with_charset(fc_instance_t* priv, const char* family, un
return res;
}
-char* fontconfig_select(fc_instance_t* priv, const char* family, unsigned bold, unsigned italic, int* index)
-{
- return fontconfig_select_with_charset(priv, family, bold, italic, index, 0);
-}
-
#if (FC_VERSION < 20402)
static char* validate_fname(char* name)
{