]> granicus.if.org Git - libass/commitdiff
Check weight and slant validity in font provider
authorGrigori Goronzy <greg@chown.ath.cx>
Thu, 18 Aug 2011 23:24:13 +0000 (01:24 +0200)
committerGrigori Goronzy <greg@chown.ath.cx>
Fri, 10 Jul 2015 08:42:40 +0000 (10:42 +0200)
When adding a new font, check that weight and slant are valid. If
they're not, use reasonable defaults.

libass/ass_fontselect.c

index 3bf67fd72e1c7c6c231a5c5f3316e558b814a2a4..ad91bf64f2935c21e858725fa8952175835d6a11 100644 (file)
@@ -62,7 +62,7 @@ struct font_info {
     int n_fullname;
 
     int slant;
-    int weight;
+    int weight;         // TrueType scale, 100-900
 
     // how to access this face
     char *path;
@@ -175,11 +175,21 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
                            unsigned int index, void *data)
 {
     int i;
+    int weight, slant;
     ASS_FontSelector *selector = provider->parent;
     ASS_FontInfo *info;
 
     // TODO: sanity checks. do we have a path or valid get_face function?
 
+    weight = meta->weight;
+    slant  = meta->slant;
+
+    // check slant/weight for validity, use defaults if they're invalid
+    if (weight < 100 || weight > 900)
+        meta->weight = 400;
+    if (slant < 0 || slant > 110)
+        slant = 0;
+
     // check size
     if (selector->n_font >= selector->alloc_font) {
         selector->alloc_font = FFMAX(1, 2 * selector->alloc_font);
@@ -194,8 +204,8 @@ ass_font_provider_add_font(ASS_FontProvider *provider,
     // set uid
     info->uid = selector->uid++;
 
-    info->slant       = meta->slant;
-    info->weight      = meta->weight;
+    info->slant       = slant;
+    info->weight      = weight;
     info->family      = strdup(meta->family);
     info->n_fullname  = meta->n_fullname;
     info->fullnames   = calloc(meta->n_fullname, sizeof(char *));