From 93c4e8ebf3dea5c9e1978f78a33cb961d6a1aaf7 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Fri, 19 Aug 2011 01:16:24 +0200 Subject: Use TrueType font weight scale fontconfig uses an unusual scale from 0-215 for the font weight. It looks like it is somewhat derived from the typographic scale some font families use, but is still rather nonstandard. Nowadays the TrueType scale from 100-900 seems to be standard. CSS uses it, for example. However, most importantly, VSFilter also uses the TrueType scale. So let's use it in libass, too. --- libass/ass_font.c | 2 +- libass/ass_fontconfig.c | 14 ++++++++++++-- libass/ass_fontselect.c | 4 +++- libass/ass_fontselect.h | 4 ++++ libass/ass_parse.c | 6 +++--- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libass/ass_font.c b/libass/ass_font.c index 7170e10..a6d1b5b 100644 --- a/libass/ass_font.c +++ b/libass/ass_font.c @@ -601,7 +601,7 @@ FT_Glyph ass_font_get_glyph(ASS_Font *font, uint32_t ch, int face_index, } if (!(face->style_flags & FT_STYLE_FLAG_BOLD) && - (font->desc.bold > 80)) { + (font->desc.bold > 400)) { ass_glyph_embolden(face->glyph); } error = FT_Get_Glyph(face->glyph, &glyph); diff --git a/libass/ass_fontconfig.c b/libass/ass_fontconfig.c index c65cd20..a3a371a 100644 --- a/libass/ass_fontconfig.c +++ b/libass/ass_fontconfig.c @@ -71,7 +71,7 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider) for (i = 0; i < fonts->nfont; i++) { FcPattern *pat = fonts->fonts[i]; FcBool outline; - int index; + int index, weight; char *path; char *fullnames[MAX_FULLNAME]; @@ -82,11 +82,21 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider) // simple types result = FcPatternGetInteger(pat, FC_SLANT, 0, &meta.slant); - result |= FcPatternGetInteger(pat, FC_WEIGHT, 0, &meta.weight); + result |= FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight); result |= FcPatternGetInteger(pat, FC_INDEX, 0, &index); if (result != FcResultMatch) continue; + // fontconfig uses its own weight scale, apparently derived + // from typographical weight. we're using truetype weights, so + // convert appropriately + if (weight <= FC_WEIGHT_LIGHT) + meta.weight = FONT_WEIGHT_LIGHT; + else if (weight <= FC_WEIGHT_MEDIUM) + meta.weight = FONT_WEIGHT_MEDIUM; + else + meta.weight = FONT_WEIGHT_BOLD; + // family name // HACK: get the last family name. that fixes fonts // like Arial Narrow in some versions diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 176d0c1..3bf67fd 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -365,6 +365,8 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library, free(req.fullnames[0]); free(req.family); + font_info_dump(font_infos, priv->n_font); + // return best match if (idx == priv->n_font) return NULL; @@ -485,7 +487,7 @@ get_font_info(FT_Library lib, FT_Face face, ASS_FontProviderMetaData *info) // calculate sensible slant and weight from style attributes slant = 110 * !!(face->style_flags & FT_STYLE_FLAG_ITALIC); - weight = 120 * !!(face->style_flags & FT_STYLE_FLAG_BOLD) + 80; + weight = 300 * !!(face->style_flags & FT_STYLE_FLAG_BOLD) + 400; // fill our struct info->family = family; diff --git a/libass/ass_fontselect.h b/libass/ass_fontselect.h index 651968d..05359a8 100644 --- a/libass/ass_fontselect.h +++ b/libass/ass_fontselect.h @@ -49,6 +49,10 @@ typedef struct font_provider_funcs { DestroyProviderFunc destroy_provider; } ASS_FontProviderFuncs; +#define FONT_WEIGHT_LIGHT 300 +#define FONT_WEIGHT_MEDIUM 400 +#define FONT_WEIGHT_BOLD 700 + typedef struct font_provider_meta_data { char *family; char **fullnames; diff --git a/libass/ass_parse.c b/libass/ass_parse.c index 3d94615..9aebf3b 100644 --- a/libass/ass_parse.c +++ b/libass/ass_parse.c @@ -113,10 +113,10 @@ void update_font(ASS_Renderer *render_priv) val = render_priv->state.bold; // 0 = normal, 1 = bold, >1 = exact weight - if (val == 1) - val = 200; // bold + if (val == 1 || val == -1) + val = 700; // bold else if (val <= 0) - val = 80; // normal + val = 400; // normal desc.bold = val; val = render_priv->state.italic; -- cgit v1.2.3