[gtk/pango2: 91/91] fontchooser: Cosmetics
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/pango2: 91/91] fontchooser: Cosmetics
- Date: Mon, 4 Jul 2022 14:13:33 +0000 (UTC)
commit 2871c7eb756b6905225fae41622119c3b6ed07e0
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jul 4 08:19:36 2022 -0400
fontchooser: Cosmetics
Clean up the palette handling code.
gtk/gtkfontchooserwidget.c | 120 +++++++++++++++++++--------------------------
1 file changed, 50 insertions(+), 70 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 869ad1d72e..fcdbd169a9 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -63,6 +63,7 @@
#include "gtksortlistmodel.h"
#include "gtkstringsorter.h"
#include "gtkcolorswatchprivate.h"
+#include "gtkpicture.h"
#include <hb-ot.h>
@@ -729,8 +730,6 @@ 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);
@@ -1666,9 +1665,6 @@ 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);
@@ -2436,9 +2432,6 @@ 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);
@@ -2447,19 +2440,23 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *fontchooser)
{
GtkWidget *first_palette = NULL;
GtkWidget *toggle;
- char *palette_name;
+ GtkWidget *box;
gtk_grid_attach (GTK_GRID (fontchooser->palette_grid),
make_title_label (_("Color Palettes")),
0, -2, 3, 1);
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
+ gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), box, 0, -1, 4, 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);
+ gtk_box_append (GTK_BOX (box), toggle);
first_palette = toggle;
toggle = gtk_check_button_new_with_label (_("Light"));
@@ -2468,7 +2465,7 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *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);
+ gtk_box_append (GTK_BOX (box), toggle);
toggle = gtk_check_button_new_with_label (_("Dark"));
g_object_set_data (G_OBJECT (toggle), "palette", (gpointer) "dark");
@@ -2476,97 +2473,80 @@ gtk_font_chooser_widget_update_palettes (GtkFontChooserWidget *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);
+ gtk_box_append (GTK_BOX (box), toggle);
for (unsigned int i = 0; i < hb_ot_color_palette_get_count (hb_face); i++)
{
+ char *palette;
+ char *label;
hb_ot_name_id_t name_id;
- char *name;
unsigned int n_colors;
hb_color_t *colors;
- GtkWidget *palette;
- GtkWidget *swatch;
+ GtkWidget *colors_grid;
- palette_name = pango2_hb_face_get_palette_name (PANGO2_HB_FACE (face), i);
+ palette = g_strdup (pango2_hb_face_get_palette_name (PANGO2_HB_FACE (face), i));
- if (palette_name)
- {
- palette_name = g_strdup (palette_name);
- name = g_strdup (palette_name);
- }
- else
+ /* Look for a display name in the font, unlikely as it is */
+ name_id = hb_ot_color_palette_get_name_id (hb_face, i);
+ if (name_id != HB_OT_NAME_ID_INVALID)
{
- palette_name = g_strdup_printf ("palette%d", i);
- name = NULL;
- }
+ char buf[80];
+ unsigned int len;
- 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];
-
- 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);
+ len = sizeof (buf);
+ hb_ot_name_get_utf8 (hb_face, name_id, HB_LANGUAGE_INVALID, &len, buf);
+ label = g_strdup (buf);
}
+ else if (palette)
+ label = g_strdup_printf (_("Palette %s"), palette);
+ else
+ label = g_strdup_printf (_("Palette %u"), i);
- toggle = gtk_check_button_new_with_label (name);
+ if (!palette)
+ palette = g_strdup_printf ("palette%u", i);
- if (g_strcmp0 (fontchooser->palette, palette_name) == 0)
+ toggle = gtk_check_button_new_with_label (label);
+ g_object_set_data_full (G_OBJECT (toggle), "palette", palette, g_free);
+ if (g_strcmp0 (fontchooser->palette, palette) == 0)
gtk_check_button_set_active (GTK_CHECK_BUTTON (toggle), TRUE);
- g_object_set_data_full (G_OBJECT (toggle), "palette", palette_name, g_free);
g_signal_connect (toggle, "toggled", G_CALLBACK (palette_changed), fontchooser);
gtk_check_button_set_group (GTK_CHECK_BUTTON (toggle), GTK_CHECK_BUTTON (first_palette));
- g_free (name);
-
- gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 0, i, 1, 1);
-
-#if 0
- hb_ot_color_palette_flags_t flags;
- const char *str;
- flags = hb_ot_color_palette_get_flags (hb_face, i);
- if ((flags & (HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_LIGHT_BACKGROUND |
- HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_DARK_BACKGROUND)) ==
- (HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_LIGHT_BACKGROUND |
- HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_DARK_BACKGROUND))
- str = _("(light, dark)");
- else if (flags & HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_LIGHT_BACKGROUND)
- str = _("(light)");
- else if (flags & HB_OT_COLOR_PALETTE_FLAG_USABLE_WITH_DARK_BACKGROUND)
- str = _("(dark)");
- else
- str = NULL;
- if (str)
- gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), gtk_label_new (str), 1, i, 1, 1);
-#endif
+ g_free (label);
+
+ int row = i / 3;
+ int col = i % 3;
+ gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), toggle, 2 * col, row, 1, 1);
n_colors = hb_ot_color_palette_get_colors (hb_face, i, 0, NULL, NULL);
colors = g_new (hb_color_t, n_colors);
n_colors = hb_ot_color_palette_get_colors (hb_face, i, 0, &n_colors, colors);
- palette = gtk_grid_new ();
- gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), palette, 2, i, 1, 1);
+ colors_grid = gtk_grid_new ();
+ gtk_grid_attach (GTK_GRID (fontchooser->palette_grid), colors_grid, 2 * col + 1, row, 1, 1);
+ gtk_widget_set_valign (colors_grid, GTK_ALIGN_CENTER);
+
+ /* HACK - defeat first-child/last-child theming */
+ gtk_grid_attach (GTK_GRID (colors_grid), gtk_picture_new (), -1, 0, 1, 1);
for (int k = 0; k < n_colors; k++)
{
- swatch = gtk_color_swatch_new ();
- gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (swatch),
+ GtkWidget *color;
+
+ color = gtk_color_swatch_new ();
+ gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (color),
&(GdkRGBA){ hb_color_get_red (colors[k])/255.,
hb_color_get_green (colors[k])/255.,
hb_color_get_blue (colors[k])/255.,
hb_color_get_alpha (colors[k])/255.});
- gtk_widget_set_size_request (swatch, 16, 16);
- gtk_grid_attach (GTK_GRID (palette), swatch, k % 8, k / 8, 1, 1);
+ gtk_widget_set_size_request (color, 16, 16);
+ gtk_grid_attach (GTK_GRID (colors_grid), color, k % 5, k / 5, 1, 1);
}
+
+ /* HACK - defeat first-child/last-child theming */
+ gtk_grid_attach (GTK_GRID (colors_grid), gtk_picture_new (), 6, 0, 1, 1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]