>From 861ab58ba7249c804f45b1e60afd89695373de60 Mon Sep 17 00:00:00 2001 From: Andreas Fuchs Date: Fri, 31 May 2013 10:34:33 +0200 Subject: [PATCH 1/4] Add support for scale property in gtksourcestyle. - Add scale / scaleset property to gtksourcestyle objects. - Pass scale property to underlying gtktextview/textselection with scale property. - Add code for parsing scale properties from gtksourcestyleschemes. --- data/styles/styles.rng | 3 ++ gtksourceview/gtksourcestyle-private.h | 4 +- gtksourceview/gtksourcestyle.c | 66 +++++++++++++++++++++++++++++++- gtksourceview/gtksourcestylescheme.c | 9 ++++- 4 files changed, 79 insertions(+), 3 deletions(-) diff --git a/data/styles/styles.rng b/data/styles/styles.rng index 7821cd5..94306a8 100644 --- a/data/styles/styles.rng +++ b/data/styles/styles.rng @@ -106,6 +106,9 @@ + + + diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h index d63727a..f160862 100644 --- a/gtksourceview/gtksourcestyle-private.h +++ b/gtksourceview/gtksourcestyle-private.h @@ -38,7 +38,8 @@ enum { GTK_SOURCE_STYLE_USE_ITALIC = 1 << 3, /*< nick=use_italic >*/ GTK_SOURCE_STYLE_USE_BOLD = 1 << 4, /*< nick=use_bold >*/ GTK_SOURCE_STYLE_USE_UNDERLINE = 1 << 5, /*< nick=use_underline >*/ - GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 6 /*< nick=use_strikethrough >*/ + GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 6, /*< nick=use_strikethrough >*/ + GTK_SOURCE_STYLE_USE_SCALE = 1 << 7 /*< nick=use_scale >*/ }; struct _GtkSourceStyle @@ -55,6 +56,7 @@ struct _GtkSourceStyle guint underline : 1; guint strikethrough : 1; guint mask : 12; + const gchar *scale; }; G_GNUC_INTERNAL diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c index 234863f..3f06ea6 100644 --- a/gtksourceview/gtksourcestyle.c +++ b/gtksourceview/gtksourcestyle.c @@ -59,7 +59,9 @@ enum { PROP_UNDERLINE, PROP_UNDERLINE_SET, PROP_STRIKETHROUGH, - PROP_STRIKETHROUGH_SET + PROP_STRIKETHROUGH_SET, + PROP_SCALE, + PROP_SCALE_SET }; static void @@ -131,6 +133,14 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, + PROP_SCALE, + g_param_spec_string ("scale", + _("Scale"), + _("Text scale factor"), + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, PROP_LINE_BACKGROUND_SET, g_param_spec_boolean ("line-background-set", _("Line background set"), @@ -185,6 +195,14 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass) _("Whether strikethrough attribute is set"), FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property (object_class, + PROP_SCALE_SET, + g_param_spec_boolean ("scale-set", + _("Scale set"), + _("Whether scale attribute is set"), + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } static void @@ -279,6 +297,20 @@ gtk_source_style_set_property (GObject *object, SET_MASK (style, STRIKETHROUGH); break; + case PROP_SCALE: + string = g_value_get_string (value); + if (string != NULL) + { + style->scale = g_intern_string (string); + SET_MASK (style, SCALE); + } + else + { + style->scale = NULL; + UNSET_MASK (style, SCALE); + } + break; + case PROP_FOREGROUND_SET: MODIFY_MASK (style, value, FOREGROUND); break; @@ -300,6 +332,9 @@ gtk_source_style_set_property (GObject *object, case PROP_STRIKETHROUGH_SET: MODIFY_MASK (style, value, STRIKETHROUGH); break; + case PROP_SCALE_SET: + MODIFY_MASK (style, value, SCALE); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -338,6 +373,9 @@ gtk_source_style_get_property (GObject *object, case PROP_STRIKETHROUGH: g_value_set_boolean (value, style->strikethrough); break; + case PROP_SCALE: + g_value_set_string (value, style->scale); + break; case PROP_FOREGROUND_SET: GET_MASK (style, value, FOREGROUND); @@ -360,6 +398,9 @@ gtk_source_style_get_property (GObject *object, case PROP_STRIKETHROUGH_SET: GET_MASK (style, value, STRIKETHROUGH); break; + case PROP_SCALE_SET: + GET_MASK (style, value, SCALE); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -397,6 +438,7 @@ gtk_source_style_copy (const GtkSourceStyle *style) copy->underline = style->underline; copy->strikethrough = style->strikethrough; copy->mask = style->mask; + copy->scale = style->scale; return copy; } @@ -458,6 +500,27 @@ _gtk_source_style_apply (const GtkSourceStyle *style, else g_object_set (tag, "strikethrough-set", FALSE, NULL); + if (style->mask & GTK_SOURCE_STYLE_USE_SCALE) + if (g_strcmp0 (style->scale, "L") == 0) + g_object_set (tag, "scale", PANGO_SCALE_LARGE, NULL); + else if (g_strcmp0 (style->scale, "XL") == 0) + g_object_set (tag, "scale", PANGO_SCALE_X_LARGE, NULL); + else if (g_strcmp0 (style->scale, "XXL") == 0) + g_object_set (tag, "scale", PANGO_SCALE_XX_LARGE, NULL); + else if (g_strcmp0 (style->scale, "S") == 0) + g_object_set (tag, "scale", PANGO_SCALE_SMALL, NULL); + else if (g_strcmp0 (style->scale, "XS") == 0) + g_object_set (tag, "scale", PANGO_SCALE_X_SMALL, NULL); + else if (g_strcmp0 (style->scale, "XXS") == 0) + g_object_set (tag, "scale", PANGO_SCALE_XX_SMALL, NULL); + else if (g_strcmp0 (style->scale, "M") == 0) + g_object_set (tag, "scale", PANGO_SCALE_MEDIUM, NULL); + else if (g_ascii_strtod(style->scale, NULL) > 0) + g_object_set (tag, "scale", g_ascii_strtod(style->scale, NULL), NULL); + else g_object_set (tag, "scale-set", FALSE, NULL); + else + g_object_set (tag, "scale-set", FALSE, NULL); + g_object_thaw_notify (G_OBJECT (tag)); } else @@ -470,6 +533,7 @@ _gtk_source_style_apply (const GtkSourceStyle *style, "weight-set", FALSE, "underline-set", FALSE, "strikethrough-set", FALSE, + "scale-set", FALSE, NULL); } } diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c index 2265907..51dcc10 100644 --- a/gtksourceview/gtksourcestylescheme.c +++ b/gtksourceview/gtksourcestylescheme.c @@ -891,6 +891,7 @@ parse_style (GtkSourceStyleScheme *scheme, gboolean italic = FALSE; gboolean underline = FALSE; gboolean strikethrough = FALSE; + xmlChar *scale = NULL; xmlChar *tmp; tmp = xmlGetProp (node, BAD_CAST "name"); @@ -937,10 +938,11 @@ parse_style (GtkSourceStyleScheme *scheme, get_bool (node, "bold", &mask, GTK_SOURCE_STYLE_USE_BOLD, &bold); get_bool (node, "underline", &mask, GTK_SOURCE_STYLE_USE_UNDERLINE, &underline); get_bool (node, "strikethrough", &mask, GTK_SOURCE_STYLE_USE_STRIKETHROUGH, &strikethrough); + scale = xmlGetProp (node, BAD_CAST "scale"); if (use_style) { - if (fg != NULL || bg != NULL || line_bg != NULL || mask != 0) + if (fg != NULL || bg != NULL || line_bg != NULL || mask != 0 || scale != NULL) { g_set_error (error, ERROR_QUARK, 0, "in style '%s': style attributes used along with use-style", @@ -983,6 +985,11 @@ parse_style (GtkSourceStyleScheme *scheme, result->line_background = g_intern_string ((char*) line_bg); result->mask |= GTK_SOURCE_STYLE_USE_LINE_BACKGROUND; } + if (scale != NULL) + { + result->scale = g_intern_string ((char*) scale); + result->mask |= GTK_SOURCE_STYLE_USE_SCALE; + } } *style_p = result; -- 1.7.10.4