[pango/pango2-color-palette: 57/71] pangodwrite-fontmap.cpp: Fix up Pango2Stretch mapping




commit 76400dc7d7c25c5484e4ed21a41b38c7ccbfba32
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jun 27 15:52:51 2022 +0800

    pangodwrite-fontmap.cpp: Fix up Pango2Stretch mapping
    
    It seems that we weren't getting the Pango2Stretch values from DirectWrite
    correctly.  Seems like the Pango2Stretch enumerations were largely in line
    with the enumerations indicated by DWRITE_FONT_STRETCH.

 pango2/pangodwrite-fontmap.cpp | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)
---
diff --git a/pango2/pangodwrite-fontmap.cpp b/pango2/pangodwrite-fontmap.cpp
index ffbfbcb07..532c3a381 100644
--- a/pango2/pangodwrite-fontmap.cpp
+++ b/pango2/pangodwrite-fontmap.cpp
@@ -75,13 +75,44 @@ struct _Pango2DirectWriteFontMapClass
 static Pango2Stretch
 util_to_pango2_stretch (DWRITE_FONT_STRETCH stretch)
 {
-  int value = (int) stretch;
+  Pango2Stretch pango2_stretch = PANGO2_STRETCH_NORMAL;
 
-  if G_UNLIKELY (stretch <= DWRITE_FONT_STRETCH_UNDEFINED ||
-                 stretch > DWRITE_FONT_STRETCH_ULTRA_EXPANDED)
-    return PANGO2_STRETCH_NORMAL;
+  switch (stretch)
+    {
+      case DWRITE_FONT_STRETCH_ULTRA_CONDENSED:
+        pango2_stretch = PANGO2_STRETCH_ULTRA_CONDENSED;
+        break;
+      case DWRITE_FONT_STRETCH_EXTRA_CONDENSED:
+        pango2_stretch = PANGO2_STRETCH_EXTRA_CONDENSED;
+        break;
+      case DWRITE_FONT_STRETCH_CONDENSED:
+        pango2_stretch = PANGO2_STRETCH_CONDENSED;
+        break;
+      case DWRITE_FONT_STRETCH_SEMI_CONDENSED:
+        pango2_stretch = PANGO2_STRETCH_SEMI_CONDENSED;
+        break;
+      case DWRITE_FONT_STRETCH_NORMAL:
+        /* also DWRITE_FONT_STRETCH_MEDIUM */
+        pango2_stretch = PANGO2_STRETCH_NORMAL;
+        break;
+      case DWRITE_FONT_STRETCH_SEMI_EXPANDED:
+        pango2_stretch = PANGO2_STRETCH_SEMI_EXPANDED;
+        break;
+      case DWRITE_FONT_STRETCH_EXPANDED:
+        pango2_stretch = PANGO2_STRETCH_EXPANDED;
+        break;
+      case DWRITE_FONT_STRETCH_EXTRA_EXPANDED:
+        pango2_stretch = PANGO2_STRETCH_EXTRA_EXPANDED;
+        break;
+      case DWRITE_FONT_STRETCH_ULTRA_EXPANDED:
+        pango2_stretch = PANGO2_STRETCH_ULTRA_EXPANDED;
+        break;
+      case DWRITE_FONT_STRETCH_UNDEFINED:
+      default:
+        pango2_stretch = PANGO2_STRETCH_NORMAL;
+    }
 
-  return (Pango2Stretch) --value;
+  return pango2_stretch;
 }
 
 static Pango2Style


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