inspector: Show the font rendering setting

Replace the font options with the new font rendering setting.
The font options are still available for tweaking in the inspector
as properties of the GtkSettings object.
This commit is contained in:
Matthias Clasen 2024-04-06 16:20:08 +02:00
parent 5f7cab4632
commit 6c5a106d7e
2 changed files with 28 additions and 186 deletions

View File

@ -81,9 +81,7 @@ struct _GtkInspectorVisual
GtkWidget *cursor_size_spin;
GtkWidget *direction_combo;
GtkWidget *font_button;
GtkWidget *font_aa_switch;
GtkWidget *font_hinting_combo;
GtkWidget *metrics_hinting_switch;
GtkWidget *font_rendering_combo;
GtkWidget *animation_switch;
GtkWidget *font_scale_entry;
GtkAdjustment *font_scale_adjustment;
@ -237,108 +235,24 @@ font_scale_adjustment_changed (GtkAdjustment *adjustment,
update_font_scale (vis, factor, FALSE, TRUE, TRUE);
}
static gboolean
get_font_aa (GtkInspectorVisual *vis)
static GtkFontRendering
get_font_rendering (GtkInspectorVisual *vis)
{
int aa;
GtkFontRendering font_rendering;
g_object_get (vis->settings, "gtk-xft-antialias", &aa, NULL);
g_object_get (vis->settings, "gtk-font-rendering", &font_rendering, NULL);
return aa != 0;
}
static gboolean
get_metrics_hinting (GtkInspectorVisual *vis)
{
gboolean hinting;
g_object_get (vis->settings, "gtk-hint-font-metrics", &hinting, NULL);
return hinting;
}
static unsigned int
get_font_hinting (GtkInspectorVisual *vis)
{
int hinting;
char *hint_style_str;
unsigned int hint_style;
g_object_get (vis->settings,
"gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", &hint_style_str,
NULL);
hint_style = 1;
if (hinting == 0)
{
hint_style = 0;
}
else
{
if (strcmp (hint_style_str, "hintnone") == 0)
hint_style = 0;
else if (strcmp (hint_style_str, "hintslight") == 0)
hint_style = 1;
else if (strcmp (hint_style_str, "hintmedium") == 0)
hint_style = 2;
else if (strcmp (hint_style_str, "hintfull") == 0)
hint_style = 3;
}
g_free (hint_style_str);
return hint_style;
return font_rendering;
}
static void
update_font_hinting (GtkInspectorVisual *vis,
unsigned int hint_style)
update_font_rendering (GtkInspectorVisual *vis,
GtkFontRendering font_rendering)
{
const char *styles[] = { "hintnone", "hintslight", "hintmedium", "hintfull" };
int hinting;
const char *style;
if (get_font_rendering (vis) == font_rendering)
return;
g_object_get (vis->settings,
"gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", &style,
NULL);
if (hinting != (hint_style != 0) || strcmp (style, styles[hint_style]) != 0)
g_object_set (vis->settings,
"gtk-xft-hinting", hint_style != 0,
"gtk-xft-hintstyle", styles[hint_style],
NULL);
}
static void
font_aa_activate (GtkSwitch *sw,
GParamSpec *pspec,
GtkInspectorVisual *vis)
{
int val, new_val;
g_object_get (vis->settings, "gtk-xft-antialias", &val, NULL);
new_val = gtk_switch_get_active (sw) ? 1 : 0;
if (val != new_val)
g_object_set (vis->settings, "gtk-xft-antialias", new_val, NULL);
}
static void
metrics_hinting_activate (GtkSwitch *sw,
GParamSpec *pspec,
GtkInspectorVisual *vis)
{
gboolean val, new_val;
g_object_get (vis->settings, "gtk-hint-font-metrics", &val, NULL);
new_val = gtk_switch_get_active (sw);
if (val != new_val)
g_object_set (vis->settings, "gtk-hint-font-metrics", new_val, NULL);
g_object_set (vis->settings, "gtk-font-rendering", font_rendering, NULL);
}
static void
@ -1026,29 +940,17 @@ init_font_scale (GtkInspectorVisual *vis)
}
static void
init_font_aa (GtkInspectorVisual *vis)
font_rendering_changed (GtkDropDown *combo,
GParamSpec *pspec,
GtkInspectorVisual *vis)
{
gtk_switch_set_active (GTK_SWITCH (vis->font_aa_switch), get_font_aa (vis));
update_font_rendering (vis, gtk_drop_down_get_selected (combo));
}
static void
font_hinting_changed (GtkDropDown *combo,
GParamSpec *pspec,
GtkInspectorVisual *vis)
init_font_rendering (GtkInspectorVisual *vis)
{
update_font_hinting (vis, gtk_drop_down_get_selected (combo));
}
static void
init_font_hinting (GtkInspectorVisual *vis)
{
gtk_drop_down_set_selected (GTK_DROP_DOWN (vis->font_hinting_combo), get_font_hinting (vis));
}
static void
init_metrics_hinting (GtkInspectorVisual *vis)
{
gtk_switch_set_active (GTK_SWITCH (vis->metrics_hinting_switch), get_metrics_hinting (vis));
gtk_drop_down_set_selected (GTK_DROP_DOWN (vis->font_rendering_combo), get_font_rendering (vis));
}
static void
@ -1299,9 +1201,7 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, slowdown_adjustment);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, slowdown_entry);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, visual_box);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, font_aa_switch);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, font_hinting_combo);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, metrics_hinting_switch);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, font_rendering_combo);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, debug_box);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, font_button);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, font_scale_entry);
@ -1319,9 +1219,7 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
gtk_widget_class_bind_template_callback (widget_class, updates_activate);
gtk_widget_class_bind_template_callback (widget_class, cairo_activate);
gtk_widget_class_bind_template_callback (widget_class, direction_changed);
gtk_widget_class_bind_template_callback (widget_class, font_aa_activate);
gtk_widget_class_bind_template_callback (widget_class, font_hinting_changed);
gtk_widget_class_bind_template_callback (widget_class, metrics_hinting_activate);
gtk_widget_class_bind_template_callback (widget_class, font_rendering_changed);
gtk_widget_class_bind_template_callback (widget_class, baselines_activate);
gtk_widget_class_bind_template_callback (widget_class, layout_activate);
gtk_widget_class_bind_template_callback (widget_class, focus_activate);
@ -1347,9 +1245,7 @@ gtk_inspector_visual_set_display (GtkInspectorVisual *vis,
init_cursor_size (vis);
init_font (vis);
init_font_scale (vis);
init_font_aa (vis);
init_font_hinting (vis);
init_metrics_hinting (vis);
init_font_rendering (vis);
init_animation (vis);
init_slowdown (vis);
init_gl (vis);

View File

@ -358,51 +358,24 @@
<object class="GtkBox">
<property name="spacing">40</property>
<child>
<object class="GtkLabel" id="font_aa_label">
<property name="label" translatable="yes">Antialiasing</property>
<object class="GtkLabel" id="font_rendering_label">
<property name="label" translatable="yes">Rendering</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="font_aa_switch">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<signal name="notify::active" handler="font_aa_activate"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<child>
<object class="GtkBox">
<property name="spacing">40</property>
<child>
<object class="GtkLabel" id="font_hinting_label">
<property name="label" translatable="yes">Hinting</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkDropDown" id="font_hinting_combo">
<object class="GtkDropDown" id="font_rendering_combo">
<property name="halign">end</property>
<property name="valign">baseline-center</property>
<property name="hexpand">1</property>
<signal name="notify::selected" handler="font_hinting_changed"/>
<signal name="notify::selected" handler="font_rendering_changed"/>
<property name="model">
<object class="GtkStringList">
<items>
<item translatable="yes" context="Font hinting style">None</item>
<item translatable="yes" context="Font hinting style">Slight</item>
<item translatable="yes" context="Font hinting style">Medium</item>
<item translatable="yes" context="Font hinting style">Full</item>
<item translatable="yes" context="Font rendering">Automatic</item>
<item translatable="yes" context="Font rendering">Manual</item>
</items>
</object>
</property>
@ -412,31 +385,6 @@
</child>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<child>
<object class="GtkBox">
<property name="spacing">40</property>
<child>
<object class="GtkLabel" id="metrics_hinting_label">
<property name="label" translatable="yes">Metrics Hinting</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="metrics_hinting_switch">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<signal name="notify::active" handler="metrics_hinting_activate"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
@ -787,9 +735,7 @@
<widget name="cursor_label"/>
<widget name="cursor_size_label"/>
<widget name="font_label"/>
<widget name="font_aa_label"/>
<widget name="font_hinting_label"/>
<widget name="metrics_hinting_label"/>
<widget name="font_rendering_label"/>
<widget name="direction_label"/>
<widget name="animation_label"/>
<widget name="updates_label"/>
@ -813,7 +759,7 @@
<widget name="cursor_combo"/>
<widget name="font_button"/>
<widget name="direction_combo"/>
<widget name="font_hinting_combo"/>
<widget name="font_rendering_combo"/>
</widgets>
</object>
<object class="GtkSizeGroup">