[pango/visible-things: 60/71] markup: Support the new attribute



commit ad258ba236f1b759c04412a06a20563f524654da
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 13 15:49:57 2019 -0400

    markup: Support the new attribute
    
    Add markup support for show="space|ignorables".

 pango/pango-markup.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
---
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index 2b871584..e39730e4 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -158,6 +158,11 @@
  *   not allowed, the range will be kept in a single run as far
  *   as possible. Breaks are allowed by default.
  *
+ * show
+ * : A value determining how invisible characters are treated.
+ *   Possible values are 'spaces', 'line-breaks', 'ignorables'
+ *   or combinations, such as 'spaces|line-breaks'.
+ *
  * lang
  * : A language code, indicating the text language
  *
@@ -1269,6 +1274,32 @@ span_parse_enum (const char *attr_name,
   return TRUE;
 }
 
+static gboolean
+span_parse_flags (const char  *attr_name,
+                  const char  *attr_val,
+                  GType        type,
+                  int         *val,
+                  int          line_number,
+                  GError     **error)
+{
+  char *possible_values = NULL;
+
+  if (!pango_parse_flags (type, attr_val, val, &possible_values))
+    {
+      g_set_error (error,
+                   G_MARKUP_ERROR,
+                   G_MARKUP_ERROR_INVALID_CONTENT,
+                   _("'%s' is not a valid value for the '%s' "
+                     "attribute on <span> tag, line %d; valid "
+                     "values are %s or combinations with |"),
+                   attr_val, attr_name, line_number, possible_values);
+      g_free (possible_values);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
 static gboolean
 span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
                     OpenTag               *tag,
@@ -1303,6 +1334,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
   const char *alpha = NULL;
   const char *background_alpha = NULL;
   const char *allow_breaks = NULL;
+  const char *show = NULL;
 
   g_markup_parse_context_get_position (context,
                                       &line_number, &char_number);
@@ -1364,6 +1396,7 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
        CHECK_ATTRIBUTE (font_features);
        break;
       case 's':
+       CHECK_ATTRIBUTE (show);
        CHECK_ATTRIBUTE (size);
        CHECK_ATTRIBUTE (stretch);
        CHECK_ATTRIBUTE (strikethrough);
@@ -1683,6 +1716,16 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
       add_attribute (tag, pango_attr_fallback_new (b));
     }
 
+  if (G_UNLIKELY (show))
+    {
+      PangoShowFlags flags;
+
+      if (!span_parse_flags ("show", show, PANGO_TYPE_SHOW_FLAGS, (int*)(void*)&flags, line_number, error))
+       goto error;
+
+      add_attribute (tag, pango_attr_show_new (flags));
+    }
+
   if (G_UNLIKELY (rise))
     {
       gint n = 0;


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