[gnome-logs] gl-utils: Update pango_font_description_to_css



commit 293006b051da4e18a539c29603d80cbe2dba827e
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Thu Jul 14 12:08:01 2022 +0200

    gl-utils: Update pango_font_description_to_css
    
    It was missing several enum values.

 src/gl-util.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/src/gl-util.c b/src/gl-util.c
index b7469fc..8afb746 100644
--- a/src/gl-util.c
+++ b/src/gl-util.c
@@ -454,6 +454,62 @@ gl_util_can_read_user_journal (void)
     }
 }
 
+static void
+add_css_variations (GString    *s,
+                    const char *variations)
+{
+  const char *p;
+  const char *sep = "";
+
+  if (variations == NULL || variations[0] == '\0')
+    {
+      g_string_append (s, "normal");
+      return;
+    }
+
+  p = variations;
+  while (p && *p)
+    {
+      const char *start;
+      const char *end, *end2;
+      double value;
+      char name[5];
+
+      while (g_ascii_isspace (*p)) p++;
+
+      start = p;
+      end = strchr (p, ',');
+      if (end && (end - p < 6))
+        goto skip;
+
+      name[0] = p[0];
+      name[1] = p[1];
+      name[2] = p[2];
+      name[3] = p[3];
+      name[4] = '\0';
+
+      p += 4;
+      while (g_ascii_isspace (*p)) p++;
+      if (*p == '=') p++;
+
+      if (p - start < 5)
+        goto skip;
+
+      value = g_ascii_strtod (p, (char **) &end2);
+
+      while (end2 && g_ascii_isspace (*end2)) end2++;
+
+      if (end2 && (*end2 != ',' && *end2 != '\0'))
+        goto skip;
+
+      g_string_append_printf (s, "%s\"%s\" %g", sep, name, value);
+      sep = ", ";
+
+skip:
+      p = end ? end + 1 : NULL;
+    }
+}
+
 /**
  * This function is orignally written in gtk/gtkfontbutton.c of gtk+ project.
  */
@@ -463,14 +519,15 @@ pango_font_description_to_css (PangoFontDescription *desc)
   GString *s;
   PangoFontMask set;
 
+  /* This line is modified with respect to gtk/gtkfontbutton.c */
   s = g_string_new ("{ ");
 
   set = pango_font_description_get_set_fields (desc);
   if (set & PANGO_FONT_MASK_FAMILY)
     {
-      g_string_append (s, "font-family: ");
+      g_string_append (s, "font-family: \"");
       g_string_append (s, pango_font_description_get_family (desc));
-      g_string_append (s, "; ");
+      g_string_append (s, "\"; ");
     }
   if (set & PANGO_FONT_MASK_STYLE)
     {
@@ -485,6 +542,8 @@ pango_font_description_to_css (PangoFontDescription *desc)
         case PANGO_STYLE_ITALIC:
           g_string_append (s, "font-style: italic; ");
           break;
+        default:
+          break;
         }
     }
   if (set & PANGO_FONT_MASK_VARIANT)
@@ -497,6 +556,23 @@ pango_font_description_to_css (PangoFontDescription *desc)
         case PANGO_VARIANT_SMALL_CAPS:
           g_string_append (s, "font-variant: small-caps; ");
           break;
+        case PANGO_VARIANT_ALL_SMALL_CAPS:
+          g_string_append (s, "font-variant: all-small-caps; ");
+          break;
+        case PANGO_VARIANT_PETITE_CAPS:
+          g_string_append (s, "font-variant: petite-caps; ");
+          break;
+        case PANGO_VARIANT_ALL_PETITE_CAPS:
+          g_string_append (s, "font-variant: all-petite-caps; ");
+          break;
+        case PANGO_VARIANT_UNICASE:
+          g_string_append (s, "font-variant: unicase; ");
+          break;
+        case PANGO_VARIANT_TITLE_CAPS:
+          g_string_append (s, "font-variant: titling-caps; ");
+          break;
+        default:
+          break;
         }
     }
   if (set & PANGO_FONT_MASK_WEIGHT)
@@ -533,6 +609,8 @@ pango_font_description_to_css (PangoFontDescription *desc)
         case PANGO_WEIGHT_ULTRAHEAVY:
           g_string_append (s, "font-weight: 900; ");
           break;
+        default:
+          break;
         }
     }
   if (set & PANGO_FONT_MASK_STRETCH)
@@ -566,11 +644,23 @@ pango_font_description_to_css (PangoFontDescription *desc)
         case PANGO_STRETCH_ULTRA_EXPANDED:
           g_string_append (s, "font-stretch: ultra-expanded; ");
           break;
+        default:
+          break;
         }
     }
   if (set & PANGO_FONT_MASK_SIZE)
     {
-      g_string_append_printf (s, "font-size: %dpt;", pango_font_description_get_size (desc) / PANGO_SCALE);
+      g_string_append_printf (s, "font-size: %dpt; ", pango_font_description_get_size (desc) / PANGO_SCALE);
+    }
+
+  if (set & PANGO_FONT_MASK_VARIATIONS)
+    {
+      const char *variations;
+
+      g_string_append (s, "font-variation-settings: ");
+      variations = pango_font_description_get_variations (desc);
+      add_css_variations (s, variations);
+      g_string_append (s, "; ");
     }
 
   g_string_append (s, "}");


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