pango_font_description_to_css: Handle numeric weight
authorMatthias Clasen <mclasen@redhat.com>
Thu, 14 Jul 2022 13:46:05 +0000 (09:46 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 14 Jul 2022 19:50:06 +0000 (15:50 -0400)
The PangoWeight enum agrees with the numeric values
we use here, so we can do this without a switch and
support numeric weight values at the same time.

gtk/gtkfontbutton.c

index 3cd42e161ccb32192613f5112ba39bece56924cd..4b80b9fe22b8b5bdfec4346aa368c2103181b9ec 100644 (file)
@@ -1206,43 +1206,8 @@ pango_font_description_to_css (PangoFontDescription *desc,
         }
     }
   if (set & PANGO_FONT_MASK_WEIGHT)
-    {
-      switch (pango_font_description_get_weight (desc))
-        {
-        case PANGO_WEIGHT_THIN:
-          g_string_append (s, "font-weight: 100; ");
-          break;
-        case PANGO_WEIGHT_ULTRALIGHT:
-          g_string_append (s, "font-weight: 200; ");
-          break;
-        case PANGO_WEIGHT_LIGHT:
-        case PANGO_WEIGHT_SEMILIGHT:
-          g_string_append (s, "font-weight: 300; ");
-          break;
-        case PANGO_WEIGHT_BOOK:
-        case PANGO_WEIGHT_NORMAL:
-          g_string_append (s, "font-weight: 400; ");
-          break;
-        case PANGO_WEIGHT_MEDIUM:
-          g_string_append (s, "font-weight: 500; ");
-          break;
-        case PANGO_WEIGHT_SEMIBOLD:
-          g_string_append (s, "font-weight: 600; ");
-          break;
-        case PANGO_WEIGHT_BOLD:
-          g_string_append (s, "font-weight: 700; ");
-          break;
-        case PANGO_WEIGHT_ULTRABOLD:
-          g_string_append (s, "font-weight: 800; ");
-          break;
-        case PANGO_WEIGHT_HEAVY:
-        case PANGO_WEIGHT_ULTRAHEAVY:
-          g_string_append (s, "font-weight: 900; ");
-          break;
-        default:
-          break;
-        }
-    }
+    g_string_append_printf (s, "font-weight: %d; ", pango_font_description_get_weight (desc));
+
   if (set & PANGO_FONT_MASK_STRETCH)
     {
       switch (pango_font_description_get_stretch (desc))