font chooser: Add properties for font features and language

These can't be returned as part of the font description,
so we need new api for them. For now, this is just readonly
properties. Maybe these should be writable too, eventually.
This commit is contained in:
Matthias Clasen 2018-03-31 09:57:34 -04:00
parent d60cd1f49f
commit 6271326718
5 changed files with 68 additions and 0 deletions

View File

@ -84,6 +84,8 @@ struct _GtkFontButtonPrivate
PangoFontFace *font_face;
PangoFontMap *font_map;
gint font_size;
char *font_features;
char *language;
gchar *preview_text;
GtkFontFilterFunc font_filter;
gpointer font_filter_data;
@ -162,6 +164,12 @@ clear_font_data (GtkFontButton *font_button)
g_free (priv->fontname);
priv->fontname = NULL;
g_free (priv->font_features);
priv->font_features = NULL;
g_free (priv->language);
priv->language = NULL;
}
static void
@ -721,6 +729,12 @@ gtk_font_button_get_property (GObject *object,
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button));
break;
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
g_value_set_string (value, priv->font_features);
break;
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
g_value_set_string (value, priv->language);
break;
case GTK_FONT_CHOOSER_PROP_LEVEL:
g_value_set_flags (value, priv->level);
break;
@ -1170,6 +1184,10 @@ response_cb (GtkDialog *dialog,
if (priv->font_face)
g_object_ref (priv->font_face);
priv->font_size = gtk_font_chooser_get_font_size (font_chooser);
g_free (priv->font_features);
g_object_get (font_chooser, "font-features", &priv->font_features, NULL);
g_free (priv->language);
g_object_get (font_chooser, "language", &priv->language, NULL);
/* Set label font */
gtk_font_button_update_font_info (font_button);
@ -1177,6 +1195,7 @@ response_cb (GtkDialog *dialog,
g_object_notify (G_OBJECT (font_button), "font");
g_object_notify (G_OBJECT (font_button), "font-desc");
g_object_notify (G_OBJECT (font_button), "font-name");
g_object_notify (G_OBJECT (font_button), "font-features");
g_object_thaw_notify (object);

View File

@ -123,6 +123,39 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
GTK_FONT_CHOOSER_LEVEL_SIZE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkFontChooser:font-features:
*
* The selected font features, in a format that is compatible with
* CSS and with Pango attributes.
*
* Since: 3.22.30
*/
g_object_interface_install_property
(iface,
g_param_spec_string ("font-features",
P_("Font features"),
P_("Font features as a string"),
"",
GTK_PARAM_READABLE));
/**
* GtkFontChooser:language:
*
* The language for which the #GtkFontChooser:font-features were
* selected, in a format that is compatible with CSS and with Pango
* attributes.
*
* Since: 3.22.30
*/
g_object_interface_install_property
(iface,
g_param_spec_string ("language",
P_("Language"),
P_("Language for which features have been selected"),
"",
GTK_PARAM_READABLE));
/**
* GtkFontChooser::font-activated:
* @self: the object which received the signal

View File

@ -137,6 +137,12 @@ _gtk_font_chooser_install_properties (GObjectClass *klass)
g_object_class_override_property (klass,
GTK_FONT_CHOOSER_PROP_LEVEL,
"level");
g_object_class_override_property (klass,
GTK_FONT_CHOOSER_PROP_FONT_FEATURES,
"font-features");
g_object_class_override_property (klass,
GTK_FONT_CHOOSER_PROP_LANGUAGE,
"language");
}
/**

View File

@ -38,6 +38,8 @@ typedef enum {
GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
GTK_FONT_CHOOSER_PROP_LEVEL,
GTK_FONT_CHOOSER_PROP_FONT_FEATURES,
GTK_FONT_CHOOSER_PROP_LANGUAGE,
GTK_FONT_CHOOSER_PROP_LAST
} GtkFontChooserProp;

View File

@ -350,6 +350,12 @@ gtk_font_chooser_widget_get_property (GObject *object,
case GTK_FONT_CHOOSER_PROP_LEVEL:
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);
break;
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
g_value_set_string (value, pango_language_to_string (fontchooser->priv->font_language));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1843,6 +1849,7 @@ update_font_features (GtkFontChooserWidget *fontchooser)
{
g_free (priv->font_features);
priv->font_features = g_string_free (s, FALSE);
g_object_notify (G_OBJECT (fontchooser), "font-features");
}
else
g_string_free (s, TRUE);
@ -1870,6 +1877,7 @@ update_language (GtkFontChooserWidget *fontchooser)
if (priv->font_language != lang)
{
priv->font_language = lang;
g_object_notify (G_OBJECT (fontchooser), "language");
}
}