]> granicus.if.org Git - imagemagick/commitdiff
Improved GetTypeInfoByFamily when the weight is not specified (zero).
authordirk <dirk@git.imagemagick.org>
Wed, 29 Jul 2015 12:10:38 +0000 (12:10 +0000)
committerdirk <dirk@git.imagemagick.org>
Wed, 29 Jul 2015 12:10:38 +0000 (12:10 +0000)
MagickCore/type.c

index f934e69b60ad8598170d35ca8c2d3597a59d5d65..8b81c62bb036ea6752fe7ab67f091fba4a2d2555 100644 (file)
@@ -369,6 +369,7 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
     };
 
   size_t
+    font_weight,
     max_score,
     score;
 
@@ -378,6 +379,7 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
   (void) GetTypeInfo("*",exception);
   if (type_cache == (SplayTreeInfo *) NULL)
     return((TypeInfo *) NULL);
+  font_weight=weight == 0 ? 400 : weight;
   LockSemaphoreInfo(type_semaphore);
   ResetSplayTreeIterator(type_cache);
   type_info=(const TypeInfo *) NULL;
@@ -415,7 +417,7 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
         p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
         continue;
       }
-    if ((weight != 0) && (p->weight != weight))
+    if (p->weight != font_weight)
       {
         p=(const TypeInfo *) GetNextValueInSplayTree(type_cache);
         continue;
@@ -462,11 +464,8 @@ MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family,
       if (((style == ItalicStyle) || (style == ObliqueStyle)) &&
           ((p->style == ItalicStyle) || (p->style == ObliqueStyle)))
         score+=25;
-    if (weight == 0)
-      score+=16;
-    else
-      score+=(16*(800-((ssize_t) MagickMax(MagickMin(weight,900),p->weight)-
-        (ssize_t) MagickMin(MagickMin(weight,900),p->weight))))/800;
+    score+=(16*(800-((ssize_t) MagickMax(MagickMin(font_weight,900),p->weight)-
+      (ssize_t) MagickMin(MagickMin(font_weight,900),p->weight))))/800;
     if ((stretch == UndefinedStretch) || (stretch == AnyStretch))
       score+=8;
     else