Make overline support conditional

The ci image does not have Pango 1.45, so for the
time being, make the overline support conditional
on Pango being new enough.
This commit is contained in:
Matthias Clasen 2020-03-21 00:44:04 -04:00
parent 72f06abd13
commit 9259efb5d7
3 changed files with 70 additions and 46 deletions

View File

@ -4758,10 +4758,6 @@ get_tag_for_attributes (PangoAttrIterator *iter)
if (attr) if (attr)
g_object_set (tag, "underline", ((PangoAttrInt*)attr)->value, NULL); g_object_set (tag, "underline", ((PangoAttrInt*)attr)->value, NULL);
attr = pango_attr_iterator_get (iter, PANGO_ATTR_OVERLINE);
if (attr)
g_object_set (tag, "overline", ((PangoAttrInt*)attr)->value, NULL);
attr = pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE_COLOR); attr = pango_attr_iterator_get (iter, PANGO_ATTR_UNDERLINE_COLOR);
if (attr) if (attr)
{ {
@ -4776,6 +4772,11 @@ get_tag_for_attributes (PangoAttrIterator *iter)
g_object_set (tag, "underline-rgba", &rgba, NULL); g_object_set (tag, "underline-rgba", &rgba, NULL);
} }
#if PANGO_VERSION_CHECK(1,45,0)
attr = pango_attr_iterator_get (iter, PANGO_ATTR_OVERLINE);
if (attr)
g_object_set (tag, "overline", ((PangoAttrInt*)attr)->value, NULL);
attr = pango_attr_iterator_get (iter, PANGO_ATTR_OVERLINE_COLOR); attr = pango_attr_iterator_get (iter, PANGO_ATTR_OVERLINE_COLOR);
if (attr) if (attr)
{ {
@ -4789,6 +4790,7 @@ get_tag_for_attributes (PangoAttrIterator *iter)
rgba.alpha = 1.; rgba.alpha = 1.;
g_object_set (tag, "overline-rgba", &rgba, NULL); g_object_set (tag, "overline-rgba", &rgba, NULL);
} }
#endif
attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH); attr = pango_attr_iterator_get (iter, PANGO_ATTR_STRIKETHROUGH);
if (attr) if (attr)

View File

@ -1585,9 +1585,11 @@ add_generic_attrs (GtkTextLayout *layout,
pango_attr_list_insert (attrs, attr); pango_attr_list_insert (attrs, attr);
} }
if (appearance->overline != PANGO_OVERLINE_NONE) if (appearance->underline_rgba)
{ {
attr = pango_attr_overline_new (appearance->overline); attr = pango_attr_underline_color_new (appearance->underline_rgba->red * 65535,
appearance->underline_rgba->green * 65535,
appearance->underline_rgba->blue * 65535);
attr->start_index = start; attr->start_index = start;
attr->end_index = start + byte_count; attr->end_index = start + byte_count;
@ -1595,11 +1597,10 @@ add_generic_attrs (GtkTextLayout *layout,
pango_attr_list_insert (attrs, attr); pango_attr_list_insert (attrs, attr);
} }
if (appearance->underline_rgba) #if PANGO_VERSION_CHECK(1,45,0)
if (appearance->overline != PANGO_OVERLINE_NONE)
{ {
attr = pango_attr_underline_color_new (appearance->underline_rgba->red * 65535, attr = pango_attr_overline_new (appearance->overline);
appearance->underline_rgba->green * 65535,
appearance->underline_rgba->blue * 65535);
attr->start_index = start; attr->start_index = start;
attr->end_index = start + byte_count; attr->end_index = start + byte_count;
@ -1618,6 +1619,7 @@ add_generic_attrs (GtkTextLayout *layout,
pango_attr_list_insert (attrs, attr); pango_attr_list_insert (attrs, attr);
} }
#endif
if (appearance->strikethrough) if (appearance->strikethrough)
{ {
@ -2131,21 +2133,23 @@ add_preedit_attrs (GtkTextLayout *layout,
case PANGO_ATTR_UNDERLINE: case PANGO_ATTR_UNDERLINE:
appearance.underline = ((PangoAttrInt *)attr)->value; appearance.underline = ((PangoAttrInt *)attr)->value;
break; break;
case PANGO_ATTR_OVERLINE:
appearance.overline = ((PangoAttrInt *)attr)->value;
break;
case PANGO_ATTR_UNDERLINE_COLOR: case PANGO_ATTR_UNDERLINE_COLOR:
convert_color (&rgba, (PangoAttrColor*)attr); convert_color (&rgba, (PangoAttrColor*)attr);
if (appearance.underline_rgba) if (appearance.underline_rgba)
gdk_rgba_free (appearance.underline_rgba); gdk_rgba_free (appearance.underline_rgba);
appearance.underline_rgba = gdk_rgba_copy (&rgba); appearance.underline_rgba = gdk_rgba_copy (&rgba);
break; break;
#if PANGO_VERSION_CHECK(1,45,0)
case PANGO_ATTR_OVERLINE:
appearance.overline = ((PangoAttrInt *)attr)->value;
break;
case PANGO_ATTR_OVERLINE_COLOR: case PANGO_ATTR_OVERLINE_COLOR:
convert_color (&rgba, (PangoAttrColor*)attr); convert_color (&rgba, (PangoAttrColor*)attr);
if (appearance.overline_rgba) if (appearance.overline_rgba)
gdk_rgba_free (appearance.overline_rgba); gdk_rgba_free (appearance.overline_rgba);
appearance.overline_rgba = gdk_rgba_copy (&rgba); appearance.overline_rgba = gdk_rgba_copy (&rgba);
break; break;
#endif
case PANGO_ATTR_STRIKETHROUGH: case PANGO_ATTR_STRIKETHROUGH:
appearance.strikethrough = ((PangoAttrInt *)attr)->value; appearance.strikethrough = ((PangoAttrInt *)attr)->value;
break; break;

View File

@ -116,9 +116,11 @@ enum {
PROP_STRIKETHROUGH_RGBA, PROP_STRIKETHROUGH_RGBA,
PROP_RIGHT_MARGIN, PROP_RIGHT_MARGIN,
PROP_UNDERLINE, PROP_UNDERLINE,
PROP_OVERLINE,
PROP_UNDERLINE_RGBA, PROP_UNDERLINE_RGBA,
#if PANGO_VERSION_CHECK(1,45,0)
PROP_OVERLINE,
PROP_OVERLINE_RGBA, PROP_OVERLINE_RGBA,
#endif
PROP_RISE, PROP_RISE,
PROP_BACKGROUND_FULL_HEIGHT, PROP_BACKGROUND_FULL_HEIGHT,
PROP_LANGUAGE, PROP_LANGUAGE,
@ -158,9 +160,11 @@ enum {
PROP_STRIKETHROUGH_RGBA_SET, PROP_STRIKETHROUGH_RGBA_SET,
PROP_RIGHT_MARGIN_SET, PROP_RIGHT_MARGIN_SET,
PROP_UNDERLINE_SET, PROP_UNDERLINE_SET,
PROP_OVERLINE_SET,
PROP_UNDERLINE_RGBA_SET, PROP_UNDERLINE_RGBA_SET,
#if PANGO_VERSION_CHECK(1,45,0)
PROP_OVERLINE_SET,
PROP_OVERLINE_RGBA_SET, PROP_OVERLINE_RGBA_SET,
#endif
PROP_RISE_SET, PROP_RISE_SET,
PROP_BACKGROUND_FULL_HEIGHT_SET, PROP_BACKGROUND_FULL_HEIGHT_SET,
PROP_LANGUAGE_SET, PROP_LANGUAGE_SET,
@ -492,15 +496,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
PANGO_UNDERLINE_NONE, PANGO_UNDERLINE_NONE,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_OVERLINE,
g_param_spec_enum ("overline",
P_("Overline"),
P_("Style of overline for this text"),
PANGO_TYPE_OVERLINE,
PANGO_OVERLINE_NONE,
GTK_PARAM_READWRITE));
/** /**
* GtkTextTag:underline-rgba: * GtkTextTag:underline-rgba:
* *
@ -519,6 +514,16 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
GDK_TYPE_RGBA, GDK_TYPE_RGBA,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
#if PANGO_VERSION_CHECK(1,45,0)
g_object_class_install_property (object_class,
PROP_OVERLINE,
g_param_spec_enum ("overline",
P_("Overline"),
P_("Style of overline for this text"),
PANGO_TYPE_OVERLINE,
PANGO_OVERLINE_NONE,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_OVERLINE_RGBA, PROP_OVERLINE_RGBA,
g_param_spec_boxed ("overline-rgba", g_param_spec_boxed ("overline-rgba",
@ -526,6 +531,7 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Color of overline for this text"), P_("Color of overline for this text"),
GDK_TYPE_RGBA, GDK_TYPE_RGBA,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
#endif
/** /**
* GtkTextTag:strikethrough-rgba: * GtkTextTag:strikethrough-rgba:
@ -778,10 +784,6 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Underline set"), P_("Underline set"),
P_("Whether this tag affects underlining")); P_("Whether this tag affects underlining"));
ADD_SET_PROP ("overline-set", PROP_OVERLINE_SET,
P_("Overline set"),
P_("Whether this tag affects overlining"));
/** /**
* GtkTextTag:underline-rgba-set: * GtkTextTag:underline-rgba-set:
* *
@ -791,9 +793,15 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Underline RGBA set"), P_("Underline RGBA set"),
P_("Whether this tag affects underlining color")); P_("Whether this tag affects underlining color"));
#if PANGO_VERSION_CHECK(1,45,0)
ADD_SET_PROP ("overline-set", PROP_OVERLINE_SET,
P_("Overline set"),
P_("Whether this tag affects overlining"));
ADD_SET_PROP ("overline-rgba-set", PROP_OVERLINE_RGBA_SET, ADD_SET_PROP ("overline-rgba-set", PROP_OVERLINE_RGBA_SET,
P_("Overline RGBA set"), P_("Overline RGBA set"),
P_("Whether this tag affects overlining color")); P_("Whether this tag affects overlining color"));
#endif
/** /**
* GtkTextTag:strikethrough-rgba-set: * GtkTextTag:strikethrough-rgba-set:
@ -921,6 +929,7 @@ set_underline_rgba (GtkTextTag *tag,
} }
} }
#if PANGO_VERSION_CHECK(1,45,0)
static void static void
set_overline_rgba (GtkTextTag *tag, set_overline_rgba (GtkTextTag *tag,
const GdkRGBA *rgba) const GdkRGBA *rgba)
@ -950,6 +959,7 @@ set_overline_rgba (GtkTextTag *tag,
} }
} }
} }
#endif
static void static void
set_strikethrough_rgba (GtkTextTag *tag, set_strikethrough_rgba (GtkTextTag *tag,
@ -1468,12 +1478,6 @@ gtk_text_tag_set_property (GObject *object,
g_object_notify (object, "underline-set"); g_object_notify (object, "underline-set");
break; break;
case PROP_OVERLINE:
priv->overline_set = TRUE;
priv->values->appearance.overline = g_value_get_enum (value);
g_object_notify (object, "overline-set");
break;
case PROP_UNDERLINE_RGBA: case PROP_UNDERLINE_RGBA:
{ {
GdkRGBA *color = g_value_get_boxed (value); GdkRGBA *color = g_value_get_boxed (value);
@ -1481,12 +1485,20 @@ gtk_text_tag_set_property (GObject *object,
} }
break; break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE:
priv->overline_set = TRUE;
priv->values->appearance.overline = g_value_get_enum (value);
g_object_notify (object, "overline-set");
break;
case PROP_OVERLINE_RGBA: case PROP_OVERLINE_RGBA:
{ {
GdkRGBA *color = g_value_get_boxed (value); GdkRGBA *color = g_value_get_boxed (value);
set_overline_rgba (text_tag, color); set_overline_rgba (text_tag, color);
} }
break; break;
#endif
case PROP_RISE: case PROP_RISE:
priv->rise_set = TRUE; priv->rise_set = TRUE;
@ -1686,17 +1698,19 @@ gtk_text_tag_set_property (GObject *object,
priv->underline_set = g_value_get_boolean (value); priv->underline_set = g_value_get_boolean (value);
break; break;
case PROP_OVERLINE_SET:
priv->overline_set = g_value_get_boolean (value);
break;
case PROP_UNDERLINE_RGBA_SET: case PROP_UNDERLINE_RGBA_SET:
priv->underline_rgba_set = g_value_get_boolean (value); priv->underline_rgba_set = g_value_get_boolean (value);
break; break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE_SET:
priv->overline_set = g_value_get_boolean (value);
break;
case PROP_OVERLINE_RGBA_SET: case PROP_OVERLINE_RGBA_SET:
priv->overline_rgba_set = g_value_get_boolean (value); priv->overline_rgba_set = g_value_get_boolean (value);
break; break;
#endif
case PROP_RISE_SET: case PROP_RISE_SET:
priv->rise_set = g_value_get_boolean (value); priv->rise_set = g_value_get_boolean (value);
@ -1894,19 +1908,21 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_enum (value, priv->values->appearance.underline); g_value_set_enum (value, priv->values->appearance.underline);
break; break;
case PROP_OVERLINE:
g_value_set_enum (value, priv->values->appearance.overline);
break;
case PROP_UNDERLINE_RGBA: case PROP_UNDERLINE_RGBA:
if (priv->underline_rgba_set) if (priv->underline_rgba_set)
g_value_set_boxed (value, priv->values->appearance.underline_rgba); g_value_set_boxed (value, priv->values->appearance.underline_rgba);
break; break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE:
g_value_set_enum (value, priv->values->appearance.overline);
break;
case PROP_OVERLINE_RGBA: case PROP_OVERLINE_RGBA:
if (priv->overline_rgba_set) if (priv->overline_rgba_set)
g_value_set_boxed (value, priv->values->appearance.overline_rgba); g_value_set_boxed (value, priv->values->appearance.overline_rgba);
break; break;
#endif
case PROP_RISE: case PROP_RISE:
g_value_set_int (value, priv->values->appearance.rise); g_value_set_int (value, priv->values->appearance.rise);
@ -2036,17 +2052,19 @@ gtk_text_tag_get_property (GObject *object,
g_value_set_boolean (value, priv->underline_set); g_value_set_boolean (value, priv->underline_set);
break; break;
case PROP_OVERLINE_SET:
g_value_set_boolean (value, priv->overline_set);
break;
case PROP_UNDERLINE_RGBA_SET: case PROP_UNDERLINE_RGBA_SET:
g_value_set_boolean (value, priv->underline_rgba_set); g_value_set_boolean (value, priv->underline_rgba_set);
break; break;
#if PANGO_VERSION_CHECK(1,45,0)
case PROP_OVERLINE_SET:
g_value_set_boolean (value, priv->overline_set);
break;
case PROP_OVERLINE_RGBA_SET: case PROP_OVERLINE_RGBA_SET:
g_value_set_boolean (value, priv->overline_rgba_set); g_value_set_boolean (value, priv->overline_rgba_set);
break; break;
#endif
case PROP_RISE_SET: case PROP_RISE_SET:
g_value_set_boolean (value, priv->rise_set); g_value_set_boolean (value, priv->rise_set);