diff options
author | Matthias Clasen <mclasen@redhat.com> | 2018-03-27 16:10:19 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2018-03-27 16:14:21 -0400 |
commit | b1b05bee5393c57cb16cbd4172d467ab96533048 (patch) | |
tree | cdff2fabc9895a7773b551b708cb6f87371c1868 | |
parent | 85a7d0a20123057ff3365726e41e0030d399c4b3 (diff) | |
download | gtk+-b1b05bee5393c57cb16cbd4172d467ab96533048.tar.gz |
font chooser: Make levels flags
Turn the GtkFontChooserLevel field into flags, and
add flags for OpenType variations and features. The
motivation for this is to make font-features in the UI
opt-in, since applications need to support them by
applying the pango attribute.
-rw-r--r-- | gtk/gtkfontbutton.c | 16 | ||||
-rw-r--r-- | gtk/gtkfontchooser.c | 15 | ||||
-rw-r--r-- | gtk/gtkfontchooser.h | 22 | ||||
-rw-r--r-- | gtk/gtkfontchooserwidget.c | 30 |
4 files changed, 52 insertions, 31 deletions
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c index 1046b396ce..d8749e3ac8 100644 --- a/gtk/gtkfontbutton.c +++ b/gtk/gtkfontbutton.c @@ -606,6 +606,10 @@ gtk_font_button_init (GtkFontButton *font_button) font_button->priv->font_face = NULL; font_button->priv->font_size = -1; font_button->priv->title = g_strdup (_("Pick a Font")); + font_button->priv->level = GTK_FONT_CHOOSER_LEVEL_FAMILY | + GTK_FONT_CHOOSER_LEVEL_STYLE | + GTK_FONT_CHOOSER_LEVEL_SIZE | + GTK_FONT_CHOOSER_LEVEL_VARIATION; gtk_font_button_take_font_desc (font_button, NULL); @@ -659,7 +663,7 @@ gtk_font_button_set_property (GObject *object, gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value)); break; case GTK_FONT_CHOOSER_PROP_LEVEL: - gtk_font_button_set_level (font_button, g_value_get_enum (value)); + gtk_font_button_set_level (font_button, g_value_get_flags (value)); break; case GTK_FONT_CHOOSER_PROP_FONT: gtk_font_button_set_font_name (font_button, g_value_get_string (value)); @@ -706,7 +710,7 @@ gtk_font_button_get_property (GObject *object, g_value_set_string (value, priv->language); break; case GTK_FONT_CHOOSER_PROP_LEVEL: - g_value_set_enum (value, priv->level); + g_value_set_flags (value, priv->level); break; case GTK_FONT_CHOOSER_PROP_FONT: g_value_set_string (value, gtk_font_button_get_font_name (font_button)); @@ -1284,15 +1288,15 @@ gtk_font_button_update_font_info (GtkFontButton *font_button) else face_name = ""; - if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY) - family_style = g_strdup (fam_name); - else + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0) family_style = g_strconcat (fam_name, " ", face_name, NULL); + else + family_style = g_strdup (fam_name); gtk_label_set_text (GTK_LABEL (font_button->priv->font_label), family_style); g_free (family_style); - if (priv->level == GTK_FONT_CHOOSER_LEVEL_FONT) + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0) { /* mirror Pango, which doesn't translate this either */ gchar *size = g_strdup_printf ("%2.4g%s", diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c index 078225eb17..23940af7a5 100644 --- a/gtk/gtkfontchooser.c +++ b/gtk/gtkfontchooser.c @@ -112,12 +112,15 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface) */ g_object_interface_install_property (iface, - g_param_spec_enum ("level", - P_("Selection level"), - P_("Whether to select family, face or font"), - GTK_TYPE_FONT_CHOOSER_LEVEL, - GTK_FONT_CHOOSER_LEVEL_FONT, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + g_param_spec_flags ("level", + P_("Selection level"), + P_("Whether to select family, face or font"), + GTK_TYPE_FONT_CHOOSER_LEVEL, + GTK_FONT_CHOOSER_LEVEL_FAMILY | + GTK_FONT_CHOOSER_LEVEL_STYLE | + GTK_FONT_CHOOSER_LEVEL_SIZE | + GTK_FONT_CHOOSER_LEVEL_VARIATION, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); /** * GtkFontChooser:font-features: diff --git a/gtk/gtkfontchooser.h b/gtk/gtkfontchooser.h index 0159e78a2d..204c6ec49a 100644 --- a/gtk/gtkfontchooser.h +++ b/gtk/gtkfontchooser.h @@ -46,20 +46,24 @@ typedef gboolean (*GtkFontFilterFunc) (const PangoFontFamily *family, /** * GtkFontChooserLevel: - * @GTK_FONT_CHOOSER_LEVEL_FONT: Select an individual - * font, including a size. An example would be: "Arial Bold 11" - * @GTK_FONT_CHOOSER_LEVEL_FACE: Select a font face, - * without a size. An example would be: "Arial Bold" - * @GTK_FONT_CHOOSER_LEVEL_FAMILY: Select a font family, without - * specifying the face. An example would be: "Arial" + * @GTK_FONT_CHOOSER_LEVEL_FAMILY: Allow selecting a font family + * @GTK_FONT_CHOOSER_LEVEL_STYLE: Allow selecting a specific font face + * @GTK_FONT_CHOOSER_LEVEL_SIZE: Allow selecting a specific font size + * @GTK_FONT_CHOOSER_LEVEL_VARIATION: Allow changing OpenType font variation axes + * @GTK_FONT_CHOOSER_LEVEL_FEATURES: Allow selecting specific OpenType font features * * This enumeration specifies the granularity of font selection * that is desired in a font chooser. + * + * This enumeration may be extended in the future; applications should + * ignore unknown values. */ typedef enum { - GTK_FONT_CHOOSER_LEVEL_FONT, - GTK_FONT_CHOOSER_LEVEL_FACE, - GTK_FONT_CHOOSER_LEVEL_FAMILY + GTK_FONT_CHOOSER_LEVEL_FAMILY = 0, + GTK_FONT_CHOOSER_LEVEL_STYLE = 1 << 0, + GTK_FONT_CHOOSER_LEVEL_SIZE = 1 << 1, + GTK_FONT_CHOOSER_LEVEL_VARIATION = 1 << 2, + GTK_FONT_CHOOSER_LEVEL_FEATURES = 1 << 3 } GtkFontChooserLevel; #define GTK_TYPE_FONT_CHOOSER (gtk_font_chooser_get_type ()) diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 36088cde2f..0eec375bb0 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -305,7 +305,7 @@ gtk_font_chooser_widget_set_property (GObject *object, gtk_font_chooser_widget_set_show_preview_entry (fontchooser, g_value_get_boolean (value)); break; case GTK_FONT_CHOOSER_PROP_LEVEL: - gtk_font_chooser_widget_set_level (fontchooser, g_value_get_enum (value)); + gtk_font_chooser_widget_set_level (fontchooser, g_value_get_flags (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -339,7 +339,7 @@ gtk_font_chooser_widget_get_property (GObject *object, g_value_set_boolean (value, gtk_font_chooser_widget_get_show_preview_entry (fontchooser)); break; case GTK_FONT_CHOOSER_PROP_LEVEL: - g_value_set_enum (value, gtk_font_chooser_widget_get_level (fontchooser)); + g_value_set_flags (value, gtk_font_chooser_widget_get_level (fontchooser)); break; case GTK_FONT_CHOOSER_PROP_FONT_FEATURES: g_value_set_string (value, fontchooser->priv->font_features); @@ -863,6 +863,10 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser) priv->preview_text = g_strdup (pango_language_get_sample_string (NULL)); priv->show_preview_entry = TRUE; priv->font_desc = pango_font_description_new (); + priv->level = GTK_FONT_CHOOSER_LEVEL_FAMILY | + GTK_FONT_CHOOSER_LEVEL_STYLE | + GTK_FONT_CHOOSER_LEVEL_SIZE | + GTK_FONT_CHOOSER_LEVEL_VARIATION; /* Set default preview text */ gtk_entry_set_text (GTK_ENTRY (priv->preview), priv->preview_text); @@ -981,10 +985,10 @@ gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser, face_name = pango_font_face_get_face_name (faces[j]); - if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY) - title = g_strdup (fam_name); - else + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0) title = g_strconcat (fam_name, " ", face_name, NULL); + else + title = g_strdup (fam_name); desc = gtk_delayed_font_description_new (faces[j]); @@ -998,7 +1002,7 @@ gtk_font_chooser_widget_load_fonts (GtkFontChooserWidget *fontchooser, g_free (title); gtk_delayed_font_description_unref (desc); - if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY) + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) == 0) break; } @@ -1415,10 +1419,10 @@ gtk_font_chooser_widget_update_font_name (GtkFontChooserWidget *fontchooser, g_object_unref (face); gtk_delayed_font_description_unref (desc); - if (priv->level == GTK_FONT_CHOOSER_LEVEL_FAMILY) - title = g_strdup (fam_name); - else + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0) title = g_strconcat (fam_name, " ", face_name, NULL); + else + title = g_strdup (fam_name); attrs = gtk_font_chooser_widget_get_preview_attributes (fontchooser, font_desc); gtk_label_set_attributes (GTK_LABEL (priv->font_name_label), attrs); @@ -1639,6 +1643,9 @@ gtk_font_chooser_widget_update_font_variations (GtkFontChooserWidget *fontchoose g_hash_table_foreach (priv->axes, axis_remove, NULL); g_hash_table_remove_all (priv->axes); + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_VARIATION) == 0) + return FALSE; + pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)), priv->font_desc); ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)); @@ -2042,6 +2049,9 @@ gtk_font_chooser_widget_update_font_features (GtkFontChooserWidget *fontchooser) gtk_widget_hide (gtk_widget_get_parent (item->feat)); } + if ((priv->level & GTK_FONT_CHOOSER_LEVEL_FEATURES) == 0) + return FALSE; + pango_font = pango_context_load_font (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)), priv->font_desc); ft_face = pango_fc_font_lock_face (PANGO_FC_FONT (pango_font)), @@ -2384,7 +2394,7 @@ gtk_font_chooser_widget_set_level (GtkFontChooserWidget *fontchooser, priv->level = level; - if (level == GTK_FONT_CHOOSER_LEVEL_FONT) + if ((level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0) { gtk_widget_show (priv->size_label); gtk_widget_show (priv->size_slider); |