]> granicus.if.org Git - libass/commitdiff
Add support for font width property
authorGrigori Goronzy <greg@chown.ath.cx>
Sat, 3 Sep 2011 13:20:00 +0000 (15:20 +0200)
committerGrigori Goronzy <greg@chown.ath.cx>
Fri, 10 Jul 2015 08:42:40 +0000 (10:42 +0200)
Add a width field to metadata. This is used for sorting fonts as
well. Fixes wrong matches with different width variants in the same
font family.

libass/ass_fontconfig.c
libass/ass_fontselect.c
libass/ass_types.h

index a3a371a009484bc298596049e12ae4f8b35dcea0..4fbf824eabc10c609cff3a5fcb14e65f23174c2b 100644 (file)
@@ -82,6 +82,7 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider)
 
         // simple types
         result  = FcPatternGetInteger(pat, FC_SLANT, 0, &meta.slant);
+        result |= FcPatternGetInteger(pat, FC_WIDTH, 0, &meta.width);
         result |= FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight);
         result |= FcPatternGetInteger(pat, FC_INDEX, 0, &index);
         if (result != FcResultMatch)
@@ -98,12 +99,10 @@ static void scan_fonts(FcConfig *config, ASS_FontProvider *provider)
             meta.weight = FONT_WEIGHT_BOLD;
 
         // family name
-        // HACK: get the last family name. that fixes fonts
-        // like Arial Narrow in some versions
-        int n_family = 0;
-        while (FcPatternGetString(pat, FC_FAMILY, n_family,
-                    (FcChar8 **)&meta.family) == FcResultMatch)
-            n_family++;
+        result = FcPatternGetString(pat, FC_FAMILY, 0,
+                (FcChar8 **)&meta.family);
+        if (result != FcResultMatch)
+            continue;
 
         // path
         result = FcPatternGetString(pat, FC_FILE, 0, (FcChar8 **)&path);
index ff2d707efb60a3b0c8e3f4c1a239e60c4feb1fa0..046e8e52bbbb2ad6532d77a45a535ad8816366ae 100644 (file)
@@ -63,6 +63,7 @@ struct font_info {
 
     int slant;
     int weight;         // TrueType scale, 100-900
+    int width;
 
     // how to access this face
     char *path;         // absolute path
@@ -225,18 +226,21 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
                            unsigned int index, void *data)
 {
     int i;
-    int weight, slant;
+    int weight, slant, width;
     ASS_FontSelector *selector = provider->parent;
     ASS_FontInfo *info;
 
     weight = meta->weight;
     slant  = meta->slant;
+    width  = meta->width;
 
     // check slant/weight for validity, use defaults if they're invalid
     if (weight < 100 || weight > 900)
         weight = 400;
     if (slant < 0 || slant > 110)
         slant = 0;
+    if (width < 50 || width > 200)
+        width = 100;
 
     // check size
     if (selector->n_font >= selector->alloc_font) {
@@ -254,6 +258,7 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
 
     info->slant       = slant;
     info->weight      = weight;
+    info->width       = width;
     info->family      = strdup(meta->family);
     info->n_fullname  = meta->n_fullname;
     info->fullnames   = calloc(meta->n_fullname, sizeof(char *));
@@ -384,6 +389,9 @@ static unsigned font_info_similarity(ASS_FontInfo *a, ASS_FontInfo *req)
     // compare weight
     similarity += ABS(a->weight - req->weight);
 
+    // compare width
+    similarity += ABS(a->width - req->width);
+
     return similarity;
 }
 
@@ -448,6 +456,7 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
     memset(&req, 0, sizeof(ASS_FontInfo));
     req.slant   = italic;
     req.weight  = bold;
+    req.width   = 100;
     req.n_fullname   = 1;
     req.fullnames    = &req_fullname;
     req.fullnames[0] = trim_space(strdup(family));
index f52e537097db485793c6613ac060a9e2e34332cc..8411348afaff8908ca90872284f8d79d7e98d053 100644 (file)
@@ -35,6 +35,9 @@
 #define FONT_SLANT_NONE    0
 #define FONT_SLANT_ITALIC  100
 #define FONT_SLANT_OBLIQUE 110
+#define FONT_WIDTH_CONDENSED 75
+#define FONT_WIDTH_NORMAL    100
+#define FONT_WIDTH_EXPANDED  125
 
 
 /* Opaque objects internally used by libass.  Contents are private. */
@@ -68,6 +71,7 @@ typedef struct font_provider_meta_data {
     int n_fullname;     // number of localized full names
     int slant;          // uses the above scale (NONE/ITALIC/OBLIQUE)
     int weight;         // TrueType scale, 100-900
+    int width;          // in percent, normally 100
 } ASS_FontProviderMetaData;