[gtk/pango2: 90/91] Pass around a palette quark




commit ffe4d36745277dc415658b8fed836c4f48650abf
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 3 23:45:57 2022 -0400

    Pass around a palette quark
    
    This is needed now that we don't store the palette
    as part of the font anymore.

 demos/gtk-demo/font_features.c    | 19 +++++---
 gsk/gl/gskglglyphlibrary.c        |  3 +-
 gsk/gl/gskglglyphlibraryprivate.h |  5 ++-
 gsk/gl/gskglrenderjob.c           |  2 +
 gsk/gskrendernode.h               |  9 ++--
 gsk/gskrendernodeimpl.c           | 21 +++++++--
 gsk/gskrendernodeparser.c         | 13 +++++-
 gtk/gskpango.c                    | 20 +++++++++
 gtk/gskpango.h                    |  1 +
 gtk/gtkfontbutton.c               |  5 ++-
 gtk/gtkfontchooserwidget.c        | 95 ++++++++++++++++++++++++---------------
 gtk/gtksnapshot.c                 |  6 ++-
 gtk/gtksnapshotprivate.h          |  5 ++-
 tests/rendernode-create-tests.c   |  2 +-
 tests/testfontchooserdialog.c     | 13 ++++++
 15 files changed, 161 insertions(+), 58 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 89db0c8f51..428a27e700 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -37,6 +37,7 @@ typedef struct {
   unsigned int end;
   Pango2FontDescription *desc;
   char *features;
+  char *palette;
   Pango2Language *language;
 } Range;
 
@@ -223,6 +224,7 @@ free_range (gpointer data)
   if (range->desc)
     pango2_font_description_free (range->desc);
   g_free (range->features);
+  g_free (range->palette);
   g_free (range);
 }
 
@@ -249,6 +251,7 @@ ensure_range (unsigned int          start,
               unsigned int          end,
               Pango2FontDescription *desc,
               const char           *features,
+              const char           *palette,
               Pango2Language        *language)
 {
   GList *l;
@@ -278,6 +281,7 @@ set:
     range->desc = pango2_font_description_copy (desc);
   g_free (range->features);
   range->features = g_strdup (features);
+  range->palette = g_strdup (palette);
   range->language = language;
 }
 
@@ -534,10 +538,6 @@ update_display (void)
       g_string_free (s, TRUE);
     }
 
-  palette = g_strdup_printf ("palette%u", demo->palette);
-  pango2_font_description_set_palette (desc, palette);
-  g_free (palette);
-
   font_desc = pango2_font_description_to_string (desc);
 
   s = g_string_new ("");
@@ -583,6 +583,8 @@ update_display (void)
 
   features = g_string_free (s, FALSE);
 
+  palette = g_strdup_printf ("palette%d", demo->palette);
+
   if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->script_lang), &iter))
     {
       hb_tag_t lang_tag;
@@ -639,12 +641,14 @@ update_display (void)
       pango2_attr_list_insert (attrs, attr);
       attr = pango2_attr_font_features_new (features);
       pango2_attr_list_insert (attrs, attr);
+      attr = pango2_attr_palette_new (palette);
+      pango2_attr_list_insert (attrs, attr);
       attr = pango2_attr_language_new (lang);
       pango2_attr_list_insert (attrs, attr);
     }
   else
     {
-      ensure_range (start, end, desc, features, lang);
+      ensure_range (start, end, desc, features, palette, lang);
 
       for (l = demo->ranges; l; l = l->next)
         {
@@ -658,6 +662,10 @@ update_display (void)
           pango2_attribute_set_range (attr, range->start, range->end);
           pango2_attr_list_insert (attrs, attr);
 
+          attr = pango2_attr_palette_new (range->palette);
+          pango2_attribute_set_range (attr, range->start, range->end);
+          pango2_attr_list_insert (attrs, attr);
+
           if (range->language)
             {
               attr = pango2_attr_language_new (range->language);
@@ -697,6 +705,7 @@ update_display (void)
   g_free (font_desc);
   pango2_font_description_free (desc);
   g_free (features);
+  g_free (palette);
   pango2_attr_list_unref (attrs);
   g_free (text);
 }
diff --git a/gsk/gl/gskglglyphlibrary.c b/gsk/gl/gskglglyphlibrary.c
index 298f36497c..943f4c2655 100644
--- a/gsk/gl/gskglglyphlibrary.c
+++ b/gsk/gl/gskglglyphlibrary.c
@@ -55,6 +55,7 @@ gsk_gl_glyph_key_hash (gconstpointer data)
    */
 
   return GPOINTER_TO_UINT (key->font) ^
+         key->palette ^
          key->glyph ^
          (key->xshift << 24) ^
          (key->yshift << 26) ^
@@ -231,7 +232,7 @@ render_glyph (cairo_surface_t           *surface,
   glyph_string.num_glyphs = 1;
   glyph_string.glyphs = &glyph_info;
 
-  pango2_cairo_show_glyph_string (cr, key->font, &glyph_string);
+  pango2_cairo_show_color_glyph_string (cr, key->font, key->palette, &glyph_string);
   cairo_destroy (cr);
 
   cairo_surface_flush (surface);
diff --git a/gsk/gl/gskglglyphlibraryprivate.h b/gsk/gl/gskglglyphlibraryprivate.h
index 433b9ab298..cc3b43e9f0 100644
--- a/gsk/gl/gskglglyphlibraryprivate.h
+++ b/gsk/gl/gskglglyphlibraryprivate.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 typedef struct _GskGLGlyphKey
 {
   Pango2Font *font;
+  GQuark palette;
   Pango2Glyph glyph;
   guint xshift : 2;
   guint yshift : 2;
@@ -45,9 +46,9 @@ typedef struct _GskGLGlyphValue
 } GskGLGlyphValue;
 
 #if GLIB_SIZEOF_VOID_P == 8
-G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 16);
+G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 24);
 #elif GLIB_SIZEOF_VOID_P == 4
-G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 12);
+G_STATIC_ASSERT (sizeof (GskGLGlyphKey) == 16);
 #endif
 
 G_DECLARE_FINAL_TYPE (GskGLGlyphLibrary, gsk_gl_glyph_library, GSK, GL_GLYPH_LIBRARY, GskGLTextureLibrary)
diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c
index 7db1168bc3..7dd6b58b02 100644
--- a/gsk/gl/gskglrenderjob.c
+++ b/gsk/gl/gskglrenderjob.c
@@ -2936,6 +2936,7 @@ gsk_gl_render_job_visit_text_node (GskGLRenderJob      *job,
                                    gboolean             force_color)
 {
   const Pango2Font *font = gsk_text_node_get_font (node);
+  GQuark palette = gsk_text_node_get_palette (node);
   const Pango2GlyphInfo *glyphs = gsk_text_node_get_glyphs (node, NULL);
   const graphene_point_t *offset = gsk_text_node_get_offset (node);
   float text_scale = MAX (job->scale_x, job->scale_y); /* TODO: Fix for uneven scales? */
@@ -2967,6 +2968,7 @@ gsk_gl_render_job_visit_text_node (GskGLRenderJob      *job,
   rgba_to_half (color, cc);
 
   lookup.font = (Pango2Font *)font;
+  lookup.palette = palette;
   lookup.scale = (guint) (text_scale * 1024);
 
   yshift = compute_phase_and_pos (y, &ypos);
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 23da2cf8a6..b446b1e067 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -490,8 +490,9 @@ GType                   gsk_text_node_get_type                  (void) G_GNUC_CO
 GDK_AVAILABLE_IN_ALL
 GskRenderNode *         gsk_text_node_new                       (Pango2Font                *font,
                                                                  Pango2GlyphString         *glyphs,
-                                                                 const GdkRGBA            *color,
-                                                                 const graphene_point_t   *offset);
+                                                                 GQuark                     palette,
+                                                                 const GdkRGBA             *color,
+                                                                 const graphene_point_t    *offset);
 GDK_AVAILABLE_IN_ALL
 Pango2Font *             gsk_text_node_get_font                  (const GskRenderNode      *node) 
G_GNUC_PURE;
 GDK_AVAILABLE_IN_4_2
@@ -499,9 +500,11 @@ gboolean                gsk_text_node_has_color_glyphs          (const GskRender
 GDK_AVAILABLE_IN_ALL
 guint                   gsk_text_node_get_num_glyphs            (const GskRenderNode      *node) G_GNUC_PURE;
 GDK_AVAILABLE_IN_ALL
-const Pango2GlyphInfo   *gsk_text_node_get_glyphs                (const GskRenderNode      *node,
+const Pango2GlyphInfo   *gsk_text_node_get_glyphs               (const GskRenderNode      *node,
                                                                  guint                    *n_glyphs) 
G_GNUC_PURE;
 GDK_AVAILABLE_IN_ALL
+GQuark                   gsk_text_node_get_palette              (const GskRenderNode      *node) G_GNUC_PURE;
+GDK_AVAILABLE_IN_ALL
 const GdkRGBA *         gsk_text_node_get_color                 (const GskRenderNode      *node) G_GNUC_PURE;
 GDK_AVAILABLE_IN_ALL
 const graphene_point_t *gsk_text_node_get_offset                (const GskRenderNode      *node) G_GNUC_PURE;
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index ddab76efeb..10c94eb0e5 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -4408,12 +4408,13 @@ struct _GskTextNode
 
   Pango2Font *font;
   gboolean has_color_glyphs;
+  GQuark palette;
 
   GdkRGBA color;
   graphene_point_t offset;
 
-  guint num_glyphs;
   Pango2GlyphInfo *glyphs;
+  guint num_glyphs;
 };
 
 static void
@@ -4443,7 +4444,7 @@ gsk_text_node_draw (GskRenderNode *node,
 
   gdk_cairo_set_source_rgba (cr, &self->color);
   cairo_translate (cr, self->offset.x, self->offset.y);
-  pango2_cairo_show_glyph_string (cr, self->font, &glyphs);
+  pango2_cairo_show_color_glyph_string (cr, self->font, self->palette, &glyphs);
 
   cairo_restore (cr);
 }
@@ -4457,6 +4458,7 @@ gsk_text_node_diff (GskRenderNode  *node1,
   GskTextNode *self2 = (GskTextNode *) node2;
 
   if (self1->font == self2->font &&
+      self1->palette == self2->palette &&
       gdk_rgba_equal (&self1->color, &self2->color) &&
       graphene_point_equal (&self1->offset, &self2->offset) &&
       self1->num_glyphs == self2->num_glyphs)
@@ -4490,6 +4492,7 @@ gsk_text_node_diff (GskRenderNode  *node1,
  * gsk_text_node_new:
  * @font: the `Pango2Font` containing the glyphs
  * @glyphs: the `Pango2GlyphString` to render
+ * @palette: the palette to use, as quark
  * @color: the foreground color to render with
  * @offset: offset of the baseline
  *
@@ -4501,8 +4504,9 @@ gsk_text_node_diff (GskRenderNode  *node1,
  * Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
  */
 GskRenderNode *
-gsk_text_node_new (Pango2Font              *font,
-                   Pango2GlyphString       *glyphs,
+gsk_text_node_new (Pango2Font             *font,
+                   Pango2GlyphString      *glyphs,
+                   GQuark                  palette,
                    const GdkRGBA          *color,
                    const graphene_point_t *offset)
 {
@@ -4527,6 +4531,7 @@ gsk_text_node_new (Pango2Font              *font,
   self->color = *color;
   self->offset = *offset;
   self->has_color_glyphs = FALSE;
+  self->palette = palette;
 
   glyph_infos = g_malloc_n (glyphs->num_glyphs, sizeof (Pango2GlyphInfo));
 
@@ -4607,6 +4612,14 @@ gsk_text_node_has_color_glyphs (const GskRenderNode *node)
   return self->has_color_glyphs;
 }
 
+GQuark
+gsk_text_node_get_palette (const GskRenderNode *node)
+{
+  const GskTextNode *self = (const GskTextNode *) node;
+
+  return self->palette;
+}
+
 /**
  * gsk_text_node_get_num_glyphs:
  * @node: (type GskTextNode): a text `GskRenderNode`
diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c
index 48cc9d7522..723568bf9c 100644
--- a/gsk/gskrendernodeparser.c
+++ b/gsk/gskrendernodeparser.c
@@ -1651,11 +1651,13 @@ parse_text_node (GtkCssParser *parser)
   graphene_point_t offset = GRAPHENE_POINT_INIT (0, 0);
   GdkRGBA color = GDK_RGBA("000000");
   Pango2GlyphString *glyphs = NULL;
+  char *palette = NULL;
   const Declaration declarations[] = {
     { "font", parse_font, clear_font, &font },
     { "offset", parse_point, NULL, &offset },
     { "color", parse_color, NULL, &color },
-    { "glyphs", parse_glyphs, clear_glyphs, &glyphs }
+    { "glyphs", parse_glyphs, clear_glyphs, &glyphs },
+    { "palette", parse_string, clear_string, &palette },
   };
   GskRenderNode *result;
 
@@ -1667,6 +1669,9 @@ parse_text_node (GtkCssParser *parser)
       g_assert (font);
     }
 
+  if (palette == NULL)
+    palette = g_strdup ("default");
+
   if (!glyphs)
     {
       const char *text = "Hello";
@@ -1689,7 +1694,7 @@ parse_text_node (GtkCssParser *parser)
     }
   else
     {
-      result = gsk_text_node_new (font, glyphs, &color, &offset);
+      result = gsk_text_node_new (font, glyphs, g_quark_from_string (palette), &color, &offset);
       if (result == NULL)
         {
           gtk_css_parser_error_value (parser, "Glyphs result in empty text");
@@ -2760,6 +2765,7 @@ render_node_print (Printer       *p,
         Pango2Font *font = gsk_text_node_get_font (node);
         Pango2FontDescription *desc;
         char *font_name;
+        const char *palette = g_quark_to_string (gsk_text_node_get_palette (node));
 
         start_node (p, "text");
 
@@ -2784,6 +2790,9 @@ render_node_print (Printer       *p,
         if (!graphene_point_equal (offset, graphene_point_zero ()))
           append_point_param (p, "offset", offset);
 
+        if (strcmp (palette, "default") != 0)
+          append_string_param (p, "palette", palette);
+
         end_node (p);
       }
       break;
diff --git a/gtk/gskpango.c b/gtk/gskpango.c
index 1dae8ffcff..ef9df2d0e0 100644
--- a/gtk/gskpango.c
+++ b/gtk/gskpango.c
@@ -91,6 +91,7 @@ gsk_pango_renderer_draw_run (Pango2Renderer *renderer,
 
   gtk_snapshot_append_text (crenderer->snapshot,
                             pango2_analysis_get_font (pango2_item_get_analysis (item)),
+                            crenderer->palette,
                             glyphs,
                             &color,
                             (float) x / PANGO2_SCALE,
@@ -272,6 +273,23 @@ get_item_appearance (Pango2Item *item)
   return NULL;
 }
 
+static GQuark
+find_palette (Pango2Context *context,
+              Pango2Item    *item)
+{
+  GSList *l;
+
+  for (l = pango2_analysis_get_extra_attributes (pango2_item_get_analysis (item)); l; l = l->next)
+    {
+      Pango2Attribute *attr = l->data;
+
+      if (pango2_attribute_type (attr) == PANGO2_ATTR_PALETTE)
+        return g_quark_from_string (pango2_attribute_get_string (attr));
+    }
+
+  return g_quark_from_string (pango2_context_get_palette (context));
+}
+
 static void
 gsk_pango_renderer_prepare_run (Pango2Renderer *renderer,
                                 Pango2Run      *run)
@@ -283,6 +301,8 @@ gsk_pango_renderer_prepare_run (Pango2Renderer *renderer,
 
   PANGO2_RENDERER_CLASS (gsk_pango_renderer_parent_class)->prepare_run (renderer, run);
 
+  crenderer->palette = find_palette (pango2_renderer_get_context (renderer), pango2_run_get_item (run));
+
   appearance = get_item_appearance (pango2_run_get_item (run));
 
   if (appearance == NULL)
diff --git a/gtk/gskpango.h b/gtk/gskpango.h
index 70a9e05712..e25e75e0bf 100644
--- a/gtk/gskpango.h
+++ b/gtk/gskpango.h
@@ -59,6 +59,7 @@ struct _GskPangoRenderer
   GtkWidget             *widget;
   GtkSnapshot           *snapshot;
   const GdkRGBA         *fg_color;
+  GQuark                 palette;
 
   /* Error underline color for this widget */
   GdkRGBA               *error_color;
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 6600c2e27c..c4c4cd258c 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -1097,7 +1097,10 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
         pango2_attr_list_insert (attrs, pango2_attr_font_features_new (font_button->font_features));
 
       if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_PALETTE) != 0 && font_button->palette != NULL)
-        pango2_attr_list_insert (attrs, pango2_attr_palette_new (font_button->palette));
+        {
+          pango2_attr_list_insert (attrs, pango2_attr_palette_new (font_button->palette));
+          g_print ("using palette %s\n", font_button->palette);
+        }
 
       pango2_attr_list_insert (attrs, pango2_attr_font_desc_new (desc));
       gtk_label_set_attributes (GTK_LABEL (font_button->font_label), attrs);
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index e54e70c2a3..869ad1d72e 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -729,6 +729,8 @@ gtk_font_chooser_widget_update_preview_attributes (GtkFontChooserWidget *fontcho
   if (fontchooser->language)
     pango2_attr_list_insert (attrs, pango2_attr_language_new (fontchooser->language));
 
+  g_print ("setting palette %s\n", fontchooser->palette);
+
   gtk_entry_set_attributes (GTK_ENTRY (fontchooser->preview), attrs);
 
   pango2_attr_list_unref (attrs);
@@ -1664,6 +1666,9 @@ gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchoose
   if ((fontchooser->level & GTK_FONT_CHOOSER_LEVEL_VARIATIONS) == 0)
     return FALSE;
 
+  char *s = pango2_font_description_to_string (fontchooser->font_desc);
+  g_print ("load font: %s\n", s);
+  g_free (s);
   pango2_font = pango2_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
                                         fontchooser->font_desc);
   hb_font = pango2_font_get_hb_font (pango2_font);
@@ -2418,6 +2423,7 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *fontchooser)
 {
   GtkWidget *child;
   Pango2Font *font;
+  Pango2FontFace *face;
   hb_font_t *hb_font;
   hb_face_t *hb_face;
 
@@ -2429,6 +2435,11 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *fontchooser)
 
   font = pango2_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)),
                                    fontchooser->font_desc);
+  face = pango2_font_get_face (font);
+  g_print ("updating palettes for %s %s\n",
+           pango2_font_family_get_name (pango2_font_face_get_family (face)),
+           pango2_font_face_get_name (face));
+
   hb_font = pango2_font_get_hb_font (font);
   hb_face = hb_font_get_face (hb_font);
 
@@ -2442,30 +2453,30 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *fontchooser)
                                  make_title_label (_("Color Palettes")),
                                  0, -2, 3, 1);
 
-     toggle = gtk_check_button_new_with_label (_("Default"));
-     g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "default");
-     g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
-     if (fontchooser->palette == NULL ||
-         g_strcmp0 (fontchooser->palette, "default") == 0)
-       gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
-     gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 0, -1, 1, 1);
-     first_palette = toggle;
-
-     toggle = gtk_check_button_new_with_label (_("Light"));
-     g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "light");
-     g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
-     if (g_strcmp0 (fontchooser->palette, "light") == 0)
-       gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
-     gtk_check_button_set_group (GTK_CHECK_BUTTON (toggle), GTK_CHECK_BUTTON (first_palette));
-     gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 1, -1, 1, 1);
-
-     toggle = gtk_check_button_new_with_label (_("Dark"));
-     g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "dark");
-     g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
-     if (g_strcmp0 (fontchooser->palette, "dark") == 0)
-       gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
-     gtk_check_button_set_group (GTK_CHECK_BUTTON (toggle), GTK_CHECK_BUTTON (first_palette));
-     gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 2, -1, 1, 1);
+      toggle = gtk_check_button_new_with_label (_("Default"));
+      g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "default");
+      g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
+      if (fontchooser->palette == NULL ||
+        g_strcmp0 (fontchooser->palette, "default") == 0)
+      gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
+      gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 0, -1, 1, 1);
+      first_palette = toggle;
+
+      toggle = gtk_check_button_new_with_label (_("Light"));
+      g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "light");
+      g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
+      if (g_strcmp0 (fontchooser->palette, "light") == 0)
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
+      gtk_check_button_set_group (GTK_CHECK_BUTTON (toggle), GTK_CHECK_BUTTON (first_palette));
+      gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 1, -1, 1, 1);
+
+      toggle = gtk_check_button_new_with_label (_("Dark"));
+      g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "dark");
+      g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
+      if (g_strcmp0 (fontchooser->palette, "dark") == 0)
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
+      gtk_check_button_set_group (GTK_CHECK_BUTTON (toggle), GTK_CHECK_BUTTON (first_palette));
+      gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 2, -1, 1, 1);
 
       for (unsigned int i = 0; i < hb_ot_color_palette_get_count (hb_face); i++)
         {
@@ -2476,22 +2487,36 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *fontchooser)
           GtkWidget *palette;
           GtkWidget *swatch;
 
-          name_id = hb_ot_color_palette_get_name_id (hb_face, i);
-          if (name_id != HB_OT_NAME_ID_INVALID)
-            {
-              unsigned int len;
-              char buf[80];
+          palette_name = pango2_hb_face_get_palette_name (PANGO2_HB_FACE (face), i);
 
-              len = sizeof (buf);
-              hb_ot_name_get_utf8 (hb_face, name_id, HB_LANGUAGE_INVALID, &len, buf);
-              name = g_strdup (buf);
+          if (palette_name)
+            {
+              palette_name = g_strdup (palette_name);
+              name = g_strdup (palette_name);
             }
           else
-            name = g_strdup_printf ("Palette %d", i);
+            {
+              palette_name = g_strdup_printf ("palette%d", i);
+              name = NULL;
+            }
 
-          toggle = gtk_check_button_new_with_label (name);
+          if (!name)
+            {
+              name_id = hb_ot_color_palette_get_name_id (hb_face, i);
+              if (name_id != HB_OT_NAME_ID_INVALID)
+                {
+                  unsigned int len;
+                  char buf[80];
 
-          palette_name = g_strdup_printf ("palette%d", i);
+                  len = sizeof (buf);
+                  hb_ot_name_get_utf8 (hb_face, name_id, HB_LANGUAGE_INVALID, &len, buf);
+                  name = g_strdup (buf);
+                }
+              else
+                name = g_strdup_printf ("Palette %d", i);
+            }
+
+          toggle = gtk_check_button_new_with_label (name);
 
           if (g_strcmp0 (fontchooser->palette, palette_name) == 0)
             gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index f700d760cf..7898a28464 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -2125,8 +2125,9 @@ gtk_snapshot_render_layout (GtkSnapshot     *snapshot,
 
 void
 gtk_snapshot_append_text (GtkSnapshot           *snapshot,
-                          Pango2Font             *font,
-                          Pango2GlyphString      *glyphs,
+                          Pango2Font            *font,
+                          GQuark                 palette,
+                          Pango2GlyphString     *glyphs,
                           const GdkRGBA         *color,
                           float                  x,
                           float                  y)
@@ -2138,6 +2139,7 @@ gtk_snapshot_append_text (GtkSnapshot           *snapshot,
 
   node = gsk_text_node_new (font,
                             glyphs,
+                            palette,
                             color,
                             &GRAPHENE_POINT_INIT (x + dx, y + dy));
   if (node == NULL)
diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h
index 1051a94628..0899cb8433 100644
--- a/gtk/gtksnapshotprivate.h
+++ b/gtk/gtksnapshotprivate.h
@@ -25,8 +25,9 @@
 G_BEGIN_DECLS
 
 void                    gtk_snapshot_append_text                (GtkSnapshot            *snapshot,
-                                                                 Pango2Font              *font,
-                                                                 Pango2GlyphString       *glyphs,
+                                                                 Pango2Font             *font,
+                                                                 GQuark                  palette,
+                                                                 Pango2GlyphString      *glyphs,
                                                                  const GdkRGBA          *color,
                                                                  float                   x,
                                                                  float                   y);
diff --git a/tests/rendernode-create-tests.c b/tests/rendernode-create-tests.c
index 62b47466fa..26b8028df0 100644
--- a/tests/rendernode-create-tests.c
+++ b/tests/rendernode-create-tests.c
@@ -431,7 +431,7 @@ text (guint n)
               GskRenderNode *node;
 
               glyphs = pango2_run_get_glyphs (run);
-              node = gsk_text_node_new (font, glyphs, &color, &GRAPHENE_POINT_INIT (x, y));
+              node = gsk_text_node_new (font, glyphs, 0, &color, &GRAPHENE_POINT_INIT (x, y));
               if (node)
                 g_ptr_array_add (nodes, node);
             }
diff --git a/tests/testfontchooserdialog.c b/tests/testfontchooserdialog.c
index cd7289a1ce..b039d041a8 100644
--- a/tests/testfontchooserdialog.c
+++ b/tests/testfontchooserdialog.c
@@ -108,6 +108,9 @@ main (int argc, char *argv[])
   GtkWidget *box;
   GtkWidget *toggle;
   gboolean done = FALSE;
+  Pango2FontMap *map;
+  Pango2FontFamily *family = NULL;
+  Pango2FontFace *face = NULL;
 
   gtk_init ();
 
@@ -133,6 +136,16 @@ main (int argc, char *argv[])
     }
 #endif
 
+  map = pango2_font_map_get_default ();
+  family = pango2_font_map_get_family (map, "Bungee Color");
+  if (family)
+    face = pango2_font_family_get_face (family, "Bold");
+  if (face)
+    {
+      pango2_hb_face_set_palette_name (PANGO2_HB_FACE (face), "day", 0);
+      pango2_hb_face_set_palette_name (PANGO2_HB_FACE (face), "night", 1);
+    }
+
   gtk_font_button_set_use_font (GTK_FONT_BUTTON (font_button), TRUE);
 
   window = gtk_window_new ();


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