[pango: 1/2] coretext: correctly clamp the core text weights at min/max values




commit 050e321e1e73b6cf12caf7a58a52b58079c9afb1
Author: Jeremy Tan <jtanx outlook com>
Date:   Fri Nov 12 19:54:27 2021 +0800

    coretext: correctly clamp the core text weights at min/max values
    
    Addresses bug found in #624

 pango/pangocoretext-fontmap.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c
index 3d8544c6..6a68003e 100644
--- a/pango/pangocoretext-fontmap.c
+++ b/pango/pangocoretext-fontmap.c
@@ -116,6 +116,7 @@ typedef struct
 /* This map is based on empirical data from analyzing a large collection of
  * fonts and comparing the opentype value with the value that OSX returns.
  * see: https://bugzilla.gnome.org/show_bug.cgi?id=766148
+ * FIXME: This need recalibrating, values outside these bounds do occur!
  */
 
 static const PangoCTWeight ct_weight_map[] = {
@@ -315,6 +316,7 @@ ct_font_descriptor_get_weight (CTFontDescriptorRef desc)
   CFNumberRef cf_number;
   CGFloat value;
   PangoWeight weight = PANGO_WEIGHT_NORMAL;
+  guint i;
 
   dict = CTFontDescriptorCopyAttribute (desc, kCTFontTraitsAttribute);
   cf_number = (CFNumberRef)CFDictionaryGetValue (dict,
@@ -322,14 +324,13 @@ ct_font_descriptor_get_weight (CTFontDescriptorRef desc)
 
   if (cf_number != NULL && CFNumberGetValue (cf_number, kCFNumberCGFloatType, &value))
     {
-    if (value < ct_weight_min || value > ct_weight_max)
+    if (!(value >= ct_weight_min && value <= ct_weight_max))
       {
-        /* This is really an error */
-        weight = PANGO_WEIGHT_NORMAL;
+        i = value > ct_weight_max ? G_N_ELEMENTS (ct_weight_map) - 1 : 0;
+        weight = ct_weight_map[i].ct_weight;
       }
     else
       {
-        guint i;
         for (i = 1; value > ct_weight_map[i].ct_weight; ++i)
           ;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]