[gtksourceview] Support "single", "double" etc for the underline attribute
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Support "single", "double" etc for the underline attribute
- Date: Tue, 12 May 2015 19:38:43 +0000 (UTC)
commit 0dee4f4df4b0e4d91e255adc5023e986a203d6fb
Author: Paolo Borelli <pborelli gnome org>
Date: Tue May 12 10:48:30 2015 +0200
Support "single", "double" etc for the underline attribute
Accept values that are valid for PangoUnderline. The legacy
underline="true" is still supported.
data/styles/classic.xml | 2 +-
data/styles/cobalt.xml | 2 +-
data/styles/kate.xml | 2 +-
data/styles/oblivion.xml | 2 +-
data/styles/solarized-dark.xml | 2 +-
data/styles/solarized-light.xml | 2 +-
data/styles/styles.rng | 4 +--
data/styles/tango.xml | 2 +-
docs/reference/style-reference.xml | 7 ++++-
gtksourceview/gtksourcestyle-private.h | 3 +-
gtksourceview/gtksourcestyle.c | 34 ++++++++++++++++++--
gtksourceview/gtksourcestylescheme.c | 52 +++++++++++++++++++++++++++----
12 files changed, 91 insertions(+), 23 deletions(-)
---
diff --git a/data/styles/classic.xml b/data/styles/classic.xml
index b1be2a4..c838c97 100644
--- a/data/styles/classic.xml
+++ b/data/styles/classic.xml
@@ -81,7 +81,7 @@
<style name="def:error" background="red" bold="true"/>
<style name="def:warning" background="yellow"/>
<style name="def:note" foreground="blue" background="yellow" bold="true"/>
- <style name="def:underlined" italic="true" underline="true"/>
+ <style name="def:underlined" italic="true" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/data/styles/cobalt.xml b/data/styles/cobalt.xml
index a03c5a7..62e7404 100644
--- a/data/styles/cobalt.xml
+++ b/data/styles/cobalt.xml
@@ -102,7 +102,7 @@
<style name="def:error" foreground="white" background="dark_red" bold="true"/>
<style name="def:warning" foreground="white" background="nail_polish_pink"/>
<style name="def:note" foreground="neon_pink" bold="true"/>
- <style name="def:net-address-in-comment" foreground="teal_blue" italic="false" underline="true"/>
+ <style name="def:net-address-in-comment" foreground="teal_blue" italic="false" underline="single"/>
<style name="def:preprocessor" foreground="light_grey"/>
<!-- Heading styles, uncomment to enable -->
diff --git a/data/styles/kate.xml b/data/styles/kate.xml
index 6af229a..d3c5872 100644
--- a/data/styles/kate.xml
+++ b/data/styles/kate.xml
@@ -90,7 +90,7 @@
<style name="def:note" foreground="#BF0303" background="#F7E7E7" bold="true"
italic="false"/>
<style name="def:error" foreground="red" underline="true"/>
<style name="def:warning" foreground="brown" underline="true"/>
- <style name="def:underlined" underline="true"/>
+ <style name="def:underlined" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/data/styles/oblivion.xml b/data/styles/oblivion.xml
index f636b69..a98677f 100644
--- a/data/styles/oblivion.xml
+++ b/data/styles/oblivion.xml
@@ -104,7 +104,7 @@
<style name="def:error" foreground="aluminium1" background="scarletred2" bold="true"/>
<style name="def:warning" foreground="aluminium1" background="plum1"/>
<style name="def:note" background="butter1" foreground="aluminium4" bold="true"/>
- <style name="def:underlined" italic="true" underline="true"/>
+ <style name="def:underlined" italic="true" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/data/styles/solarized-dark.xml b/data/styles/solarized-dark.xml
index bcabb46..64926c7 100644
--- a/data/styles/solarized-dark.xml
+++ b/data/styles/solarized-dark.xml
@@ -88,7 +88,7 @@
<style name="def:preprocessor" foreground="violet"/>
<style name="def:error" foreground="red" bold="true"/>
<style name="def:note" foreground="magenta" bold="true"/>
- <style name="def:underlined" italic="true" underline="true"/>
+ <style name="def:underlined" italic="true" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/data/styles/solarized-light.xml b/data/styles/solarized-light.xml
index 9c9667e..84bf14e 100644
--- a/data/styles/solarized-light.xml
+++ b/data/styles/solarized-light.xml
@@ -88,7 +88,7 @@
<style name="def:preprocessor" foreground="violet"/>
<style name="def:error" foreground="red" bold="true"/>
<style name="def:note" foreground="magenta" bold="true"/>
- <style name="def:underlined" italic="true" underline="true"/>
+ <style name="def:underlined" italic="true" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/data/styles/styles.rng b/data/styles/styles.rng
index c25cb1a..f6632d7 100644
--- a/data/styles/styles.rng
+++ b/data/styles/styles.rng
@@ -125,9 +125,7 @@
</attribute>
</optional>
<optional>
- <attribute name="underline">
- <ref name="boolean-value"/>
- </attribute>
+ <attribute name="underline"/>
</optional>
<optional>
<attribute name="strikethrough">
diff --git a/data/styles/tango.xml b/data/styles/tango.xml
index cd76e14..4eec489 100644
--- a/data/styles/tango.xml
+++ b/data/styles/tango.xml
@@ -94,7 +94,7 @@
<style name="def:error" background="scarletred2" bold="true"/>
<style name="def:warning" background="plum1"/>
<style name="def:note" background="orange1" bold="true"/>
- <style name="def:underlined" italic="true" underline="true"/>
+ <style name="def:underlined" italic="true" underline="single"/>
<!-- Heading styles, uncomment to enable -->
<!--
diff --git a/docs/reference/style-reference.xml b/docs/reference/style-reference.xml
index adc03e0..c15b8f8 100644
--- a/docs/reference/style-reference.xml
+++ b/docs/reference/style-reference.xml
@@ -143,7 +143,12 @@ Background color.
</varlistentry>
<varlistentry>
<term><code>underline</code></term>
-<listitem><para>"true" or "false"</para></listitem>
+<listitem><para>
+Accepts the values supported by PangoUnderline ("none", "single",
+"double", "low", "error"). Up until version 3.18 it only
+supported "true" or "false" and such value are still accepted
+for backward compatibility.
+</para></listitem>
</varlistentry>
<varlistentry>
<term><code>strikethrough</code></term>
diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h
index 9447e97..c0d9a31 100644
--- a/gtksourceview/gtksourcestyle-private.h
+++ b/gtksourceview/gtksourcestyle-private.h
@@ -51,9 +51,10 @@ struct _GtkSourceStyle
const gchar *line_background;
const gchar *scale;
+ PangoUnderline underline;
+
guint italic : 1;
guint bold : 1;
- guint underline : 1;
guint strikethrough : 1;
guint mask : 12;
};
diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c
index 6803387..3b6cf3f 100644
--- a/gtksourceview/gtksourcestyle.c
+++ b/gtksourceview/gtksourcestyle.c
@@ -45,7 +45,7 @@ static void gtk_source_style_get_property (GObject *object,
struct _GtkSourceStyleClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
G_DEFINE_TYPE (GtkSourceStyle, gtk_source_style, G_TYPE_OBJECT)
@@ -64,6 +64,7 @@ enum
PROP_ITALIC,
PROP_ITALIC_SET,
PROP_UNDERLINE,
+ PROP_PANGO_UNDERLINE,
PROP_UNDERLINE_SET,
PROP_STRIKETHROUGH,
PROP_STRIKETHROUGH_SET,
@@ -123,6 +124,11 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ /**
+ * GtkSourceStyle:underline
+ *
+ * Deprecated: 3.18: Use pango-underline.
+ */
g_object_class_install_property (object_class,
PROP_UNDERLINE,
g_param_spec_boolean ("underline",
@@ -132,6 +138,15 @@ gtk_source_style_class_init (GtkSourceStyleClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
+ PROP_PANGO_UNDERLINE,
+ g_param_spec_enum ("pango-underline",
+ "Pango Underline",
+ "Pango Underline",
+ PANGO_TYPE_UNDERLINE,
+ PANGO_UNDERLINE_NONE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (object_class,
PROP_STRIKETHROUGH,
g_param_spec_boolean ("strikethrough",
"Strikethrough",
@@ -298,7 +313,12 @@ gtk_source_style_set_property (GObject *object,
break;
case PROP_UNDERLINE:
- style->underline = g_value_get_boolean (value) != 0;
+ style->underline = g_value_get_boolean (value) ? PANGO_UNDERLINE_SINGLE :
PANGO_UNDERLINE_NONE;
+ SET_MASK (style, UNDERLINE);
+ break;
+
+ case PROP_PANGO_UNDERLINE:
+ style->underline = (PangoUnderline) g_value_get_enum (value);
SET_MASK (style, UNDERLINE);
break;
@@ -389,12 +409,17 @@ gtk_source_style_get_property (GObject *object,
break;
case PROP_UNDERLINE:
- g_value_set_boolean (value, style->underline);
+ g_value_set_boolean (value, style->underline != PANGO_UNDERLINE_NONE);
+ break;
+
+ case PROP_PANGO_UNDERLINE:
+ g_value_set_enum (value, style->underline);
break;
case PROP_STRIKETHROUGH:
g_value_set_boolean (value, style->strikethrough);
break;
+
case PROP_SCALE:
g_value_set_string (value, style->scale);
break;
@@ -426,6 +451,7 @@ 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;
@@ -539,7 +565,7 @@ _gtk_source_style_apply (const GtkSourceStyle *style,
if (style->mask & GTK_SOURCE_STYLE_USE_UNDERLINE)
{
- g_object_set (tag, "underline", style->underline ? PANGO_UNDERLINE_SINGLE :
PANGO_UNDERLINE_NONE, NULL);
+ g_object_set (tag, "underline", style->underline, NULL);
}
else
{
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 90691dd..1f147d8 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -921,6 +921,14 @@ generate_css_style (GtkSourceStyleScheme *scheme)
g_string_free (final_style, TRUE);
}
+static gboolean
+parse_bool (char *value)
+{
+ return (g_ascii_strcasecmp (value, "true") == 0 ||
+ g_ascii_strcasecmp (value, "yes") == 0 ||
+ g_ascii_strcasecmp (value, "1") == 0);
+}
+
static void
get_bool (xmlNode *node,
const char *propname,
@@ -933,9 +941,7 @@ get_bool (xmlNode *node,
if (tmp != NULL)
{
*mask |= mask_value;
- *value = g_ascii_strcasecmp ((char*) tmp, "true") == 0 ||
- g_ascii_strcasecmp ((char*) tmp, "yes") == 0 ||
- g_ascii_strcasecmp ((char*) tmp, "1") == 0;
+ *value = parse_bool ((char*) tmp);
}
xmlFree (tmp);
@@ -957,8 +963,8 @@ parse_style (GtkSourceStyleScheme *scheme,
guint mask = 0;
gboolean bold = FALSE;
gboolean italic = FALSE;
- gboolean underline = FALSE;
gboolean strikethrough = FALSE;
+ xmlChar *underline = NULL;
xmlChar *scale = NULL;
xmlChar *tmp;
@@ -1004,13 +1010,13 @@ parse_style (GtkSourceStyleScheme *scheme,
line_bg = xmlGetProp (node, BAD_CAST "line-background");
get_bool (node, "italic", &mask, GTK_SOURCE_STYLE_USE_ITALIC, &italic);
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);
+ underline = xmlGetProp (node, BAD_CAST "underline");
scale = xmlGetProp (node, BAD_CAST "scale");
if (use_style)
{
- if (fg != NULL || bg != NULL || line_bg != NULL || mask != 0 || scale != NULL)
+ if (fg != NULL || bg != NULL || line_bg != NULL || mask != 0 || underline != NULL || scale !=
NULL)
{
g_set_error (error, ERROR_QUARK, 0,
"in style '%s': style attributes used along with use-style",
@@ -1033,7 +1039,6 @@ parse_style (GtkSourceStyleScheme *scheme,
result->mask = mask;
result->bold = bold;
result->italic = italic;
- result->underline = underline;
result->strikethrough = strikethrough;
if (fg != NULL)
@@ -1053,6 +1058,39 @@ parse_style (GtkSourceStyleScheme *scheme,
result->line_background = g_intern_string ((char*) line_bg);
result->mask |= GTK_SOURCE_STYLE_USE_LINE_BACKGROUND;
}
+
+ if (underline != NULL)
+ {
+ /* Up until 3.16 underline was a "bool", so for backward
+ * compat we accept underline="true" and map it to "single"
+ */
+ if (parse_bool ((char *) underline))
+ {
+ result->underline = PANGO_UNDERLINE_SINGLE;
+ result->mask |= GTK_SOURCE_STYLE_USE_UNDERLINE;
+ }
+ else
+ {
+ GEnumClass *eclass;
+ GEnumValue *evalue;
+ gchar *tmp;
+
+ eclass = G_ENUM_CLASS (g_type_class_ref (PANGO_TYPE_UNDERLINE));
+
+ tmp = g_ascii_strdown ((char*) underline, -1);
+ evalue = g_enum_get_value_by_nick (eclass, tmp);
+ g_free (tmp);
+
+ if (evalue != NULL)
+ {
+ result->underline = evalue->value;
+ result->mask |= GTK_SOURCE_STYLE_USE_UNDERLINE;
+ }
+
+ g_type_class_unref (eclass);
+ }
+ }
+
if (scale != NULL)
{
result->scale = g_intern_string ((char*) scale);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]