[pango/line-underline: 5/10] Add an overline attribute



commit 6eb978e36463a7762bf42aeaa183dd7dc7964ff6
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 22 11:44:25 2019 +0200

    Add an overline attribute
    
    Add a new PangoOverline enum, and overline
    and overline_color attributes, which parallel
    the attributes we have for underlines and
    strikethrough.
    
    For now, the enum just has 'none' and 'single'
    values.

 docs/pango-sections.txt  |  3 +++
 pango/pango-attributes.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 pango/pango-attributes.h | 29 ++++++++++++++++++++++++++
 pango/pango-markup.c     | 33 +++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 70c4378c..e87b8750 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -395,6 +395,9 @@ pango_attr_strikethrough_color_new
 pango_attr_underline_new
 pango_attr_underline_color_new
 PangoUnderline
+pango_attr_overline_new
+pango_attr_overline_color_new
+PangoOverline
 pango_attr_shape_new
 pango_attr_shape_new_with_data
 PangoAttrDataCopyFunc
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 9a80f0e1..8ff631ae 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -1258,6 +1258,60 @@ pango_attr_show_new (PangoShowFlags flags)
   return pango_attr_int_new (&klass, (int)flags);
 }
 
+/**
+ * pango_attr_overline_new:
+ * @overline: the overline style
+ *
+ * Create a new overline-style attribute.
+ *
+ * Return value: (transfer full): the newly allocated #PangoAttribute,
+ *               which should be freed with pango_attribute_destroy().
+ *
+ * Since: 1.45
+ **/
+PangoAttribute *
+pango_attr_overline_new (PangoOverline overline)
+{
+  static const PangoAttrClass klass = {
+    PANGO_ATTR_OVERLINE,
+    pango_attr_int_copy,
+    pango_attr_int_destroy,
+    pango_attr_int_equal
+  };
+
+  return pango_attr_int_new (&klass, (int)overline);
+}
+
+/**
+ * pango_attr_overline_color_new:
+ * @red: the red value (ranging from 0 to 65535)
+ * @green: the green value
+ * @blue: the blue value
+ *
+ * Create a new overline color attribute. This attribute
+ * modifies the color of overlines. If not set, overlines
+ * will use the foreground color.
+ *
+ * Return value: (transfer full): the newly allocated #PangoAttribute,
+ *               which should be freed with pango_attribute_destroy().
+ *
+ * Since: 1.45
+ **/
+PangoAttribute *
+pango_attr_overline_color_new (guint16 red,
+                               guint16 green,
+                               guint16 blue)
+{
+  static const PangoAttrClass klass = {
+    PANGO_ATTR_OVERLINE_COLOR,
+    pango_attr_color_copy,
+    pango_attr_color_destroy,
+    pango_attr_color_equal
+  };
+
+  return pango_attr_color_new (&klass, red, green, blue);
+}
+
 /*
  * Attribute List
  */
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index ceb3236a..7def13ab 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -150,6 +150,8 @@ typedef struct _PangoAttrIterator PangoAttrIterator;
  * @PANGO_ATTR_ALLOW_BREAKS: whether breaks are allowed (#PangoAttrInt). Since 1.44
  * @PANGO_ATTR_SHOW: how to render invisible characters (#PangoAttrInt). Since 1.44
  * @PANGO_ATTR_INSERT_HYPHENS: whether to insert hyphens at intra-word line breaks (#PangoAttrInt). Since 
1.44
+ * @PANGO_ATTR_OVERLINE: whether the text has an overline (#PangoAttrInt). Sincd 1.46
+ * @PANGO_ATTR_OVERLINE_COLOR: overline color (#PangoAttrColor). Since 1.46
  *
  * The #PangoAttrType
  * distinguishes between different types of attributes. Along with the
@@ -189,6 +191,8 @@ typedef enum
   PANGO_ATTR_ALLOW_BREAKS,     /* PangoAttrInt */
   PANGO_ATTR_SHOW,             /* PangoAttrInt */
   PANGO_ATTR_INSERT_HYPHENS,   /* PangoAttrInt */
+  PANGO_ATTR_OVERLINE,         /* PangoAttrInt */
+  PANGO_ATTR_OVERLINE_COLOR,   /* PangoAttrColor */
 } PangoAttrType;
 
 /**
@@ -232,6 +236,24 @@ typedef enum {
   PANGO_UNDERLINE_ERROR_LINE
 } PangoUnderline;
 
+
+/**
+ * PangoOverline:
+ * @PANGO_OVERLINE_NONE: no overline should be drawn
+ * @PANGO_OVERLINE_SINGLE: Draw a single line above the ink
+ *     extents of the text being underlined.
+ *
+ * The #PangoOverline enumeration is used to specify
+ * whether text should be overlined, and if so, the type
+ * of line.
+ *
+ * Since: 1.46
+ */
+typedef enum {
+  PANGO_OVERLINE_NONE,
+  PANGO_OVERLINE_SINGLE
+} PangoOverline;
+
 /**
  * PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING:
  *
@@ -545,6 +567,13 @@ PangoAttribute *pango_attr_allow_breaks_new     (gboolean allow_breaks);
 PANGO_AVAILABLE_IN_1_44
 PangoAttribute *pango_attr_insert_hyphens_new   (gboolean insert_hyphens);
 
+PANGO_AVAILABLE_IN_1_46
+PangoAttribute *pango_attr_overline_new         (PangoOverline overline);
+PANGO_AVAILABLE_IN_1_46
+PangoAttribute *pango_attr_overline_color_new   (guint16       red,
+                                                guint16       green,
+                                                guint16       blue);
+
 /**
  * PangoShowFlags:
  * @PANGO_SHOW_NONE: No special treatment for invisible characters
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 49bc5dda..cdea3a98 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -135,6 +135,13 @@
  * : The color of underlines; an RGB color
  *   specification such as '#00FF00' or a color name such as 'red'
  *
+ * overline
+ * : One of 'none' or 'single'
+ *
+ * overline_color
+ * : The color of overlines; an RGB color
+ *   specification such as '#00FF00' or a color name such as 'red'
+ *
  * rise
  * : Vertical displacement, in Pango units. Can be negative for
  *   subscript, positive for superscript.
@@ -1327,6 +1334,8 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
   const char *background = NULL;
   const char *underline = NULL;
   const char *underline_color = NULL;
+  const char *overline = NULL;
+  const char *overline_color = NULL;
   const char *strikethrough = NULL;
   const char *strikethrough_color = NULL;
   const char *rise = NULL;
@@ -1420,6 +1429,10 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
        CHECK_ATTRIBUTE (lang);
        CHECK_ATTRIBUTE (letter_spacing);
        break;
+      case 'o':
+       CHECK_ATTRIBUTE (overline);
+       CHECK_ATTRIBUTE (overline_color);
+       break;
       case 'u':
        CHECK_ATTRIBUTE (underline);
        CHECK_ATTRIBUTE (underline_color);
@@ -1662,6 +1675,26 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       add_attribute (tag, pango_attr_underline_color_new (color.red, color.green, color.blue));
     }
 
+  if (G_UNLIKELY (overline))
+    {
+      PangoOverline ol = PANGO_OVERLINE_NONE;
+
+      if (!span_parse_enum ("overline", overline, PANGO_TYPE_OVERLINE, (int*)(void*)&ol, line_number, error))
+       goto error;
+
+      add_attribute (tag, pango_attr_overline_new (ol));
+    }
+
+  if (G_UNLIKELY (overline_color))
+    {
+      PangoColor color;
+
+      if (!span_parse_color ("overline_color", overline_color, &color, NULL, line_number, error))
+       goto error;
+
+      add_attribute (tag, pango_attr_overline_color_new (color.red, color.green, color.blue));
+    }
+
   if (G_UNLIKELY (gravity))
     {
       PangoGravity gr = PANGO_GRAVITY_SOUTH;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]