[gtksourceview/wip/font-scaling] Add support for scale property in gtksourcestyle
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/font-scaling] Add support for scale property in gtksourcestyle
- Date: Thu, 2 Jan 2014 15:14:31 +0000 (UTC)
commit 74bd4f52b8eea3eb94d3b804f70b5c97898a9a0e
Author: Andreas Fuchs <anduchs gmail com>
Date: Fri May 31 10:34:33 2013 +0200
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 | 89 +++++++++++++++++++++++++++++++-
gtksourceview/gtksourcestylescheme.c | 9 +++-
4 files changed, 102 insertions(+), 3 deletions(-)
---
diff --git a/data/styles/styles.rng b/data/styles/styles.rng
index 7821cd5..c25cb1a 100644
--- a/data/styles/styles.rng
+++ b/data/styles/styles.rng
@@ -134,6 +134,9 @@
<ref name="boolean-value"/>
</attribute>
</optional>
+ <optional>
+ <attribute name="scale"/>
+ </optional>
</define>
</grammar>
diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h
index 59c9501..9447e97 100644
--- a/gtksourceview/gtksourcestyle-private.h
+++ b/gtksourceview/gtksourcestyle-private.h
@@ -35,7 +35,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
@@ -48,6 +49,7 @@ struct _GtkSourceStyle
const gchar *foreground;
const gchar *background;
const gchar *line_background;
+ const gchar *scale;
guint italic : 1;
guint bold : 1;
diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c
index 0d86b62..d326f6e 100644
--- a/gtksourceview/gtksourcestyle.c
+++ b/gtksourceview/gtksourcestyle.c
@@ -66,7 +66,9 @@ enum
PROP_UNDERLINE,
PROP_UNDERLINE_SET,
PROP_STRIKETHROUGH,
- PROP_STRIKETHROUGH_SET
+ PROP_STRIKETHROUGH_SET,
+ PROP_SCALE,
+ PROP_SCALE_SET
};
static void
@@ -138,6 +140,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"),
@@ -192,6 +202,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
@@ -289,6 +307,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;
@@ -316,6 +348,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);
@@ -360,6 +395,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);
@@ -388,6 +426,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);
@@ -424,6 +465,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;
}
@@ -513,6 +555,50 @@ _gtk_source_style_apply (const GtkSourceStyle *style,
g_object_set (tag, "strikethrough-set", FALSE, NULL);
}
+ if (style->mask & GTK_SOURCE_STYLE_USE_SCALE)
+ {
+ if (g_ascii_strcasecmp (style->scale, "large") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_LARGE, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "x-large") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_X_LARGE, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "xx-large") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_XX_LARGE, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "small") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_SMALL, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "x-small") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_X_SMALL, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "xx-small") == 0)
+ {
+ g_object_set (tag, "scale", PANGO_SCALE_XX_SMALL, NULL);
+ }
+ else if (g_ascii_strcasecmp (style->scale, "medium") == 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
@@ -525,6 +611,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 02b56f5..1845da7 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -910,6 +910,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");
@@ -956,10 +957,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",
@@ -1002,6 +1004,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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]