[pango/redo-attrs: 18/25] Rename PangoUnderline to PangoLineStyle




commit 3f20d1b8ea1730f0ca6ffeb66b1fc462965a877b
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 7 00:55:04 2022 -0500

    Rename PangoUnderline to PangoLineStyle

 pango/pango-attr-list.c  |  4 ++--
 pango/pango-attributes.c |  8 ++++----
 pango/pango-attributes.h | 34 ++++++++++++++--------------------
 pango/pango-layout.c     | 38 ++++++++------------------------------
 pango/pango-markup.c     |  8 ++++----
 pango/pango-renderer.c   | 38 +++++++++++++++++++-------------------
 pango/pango-renderer.h   |  2 +-
 pango/serializer.c       |  9 ++++-----
 tests/testattributes.c   |  8 ++++----
 9 files changed, 60 insertions(+), 89 deletions(-)
---
diff --git a/pango/pango-attr-list.c b/pango/pango-attr-list.c
index 95e500dd..8f31971a 100644
--- a/pango/pango-attr-list.c
+++ b/pango/pango-attr-list.c
@@ -765,7 +765,7 @@ get_attr_value_type (PangoAttrType type)
     case PANGO_ATTR_STRETCH: return PANGO_TYPE_STRETCH;
     case PANGO_ATTR_GRAVITY: return PANGO_TYPE_GRAVITY;
     case PANGO_ATTR_GRAVITY_HINT: return PANGO_TYPE_GRAVITY_HINT;
-    case PANGO_ATTR_UNDERLINE: return PANGO_TYPE_UNDERLINE;
+    case PANGO_ATTR_UNDERLINE: return PANGO_TYPE_LINE_STYLE;
     case PANGO_ATTR_OVERLINE: return PANGO_TYPE_OVERLINE;
     case PANGO_ATTR_BASELINE_SHIFT: return PANGO_TYPE_BASELINE_SHIFT;
     case PANGO_ATTR_FONT_SCALE: return PANGO_TYPE_FONT_SCALE;
@@ -1135,7 +1135,7 @@ pango_attr_list_from_string (const char *text)
           break;
 
         case PANGO_ATTR_UNDERLINE:
-          ENUM_ATTR(underline, PangoUnderline, PANGO_UNDERLINE_NONE, PANGO_UNDERLINE_ERROR);
+          ENUM_ATTR(underline, PangoLineStyle, PANGO_LINE_STYLE_NONE, PANGO_LINE_STYLE_DOTTED);
           break;
 
         case PANGO_ATTR_UNDERLINE_POSITION:
diff --git a/pango/pango-attributes.c b/pango/pango-attributes.c
index 019fa79a..7fcf47e0 100644
--- a/pango/pango-attributes.c
+++ b/pango/pango-attributes.c
@@ -325,18 +325,18 @@ pango_attr_font_desc_new (const PangoFontDescription *desc)
 
 /**
  * pango_attr_underline_new:
- * @underline: the underline style
+ * @style: the line style
  *
- * Create a new underline-style attribute.
+ * Create a new underline attribute.
  *
  * Return value: (transfer full): the newly allocated
  *   `PangoAttribute`, which should be freed with
  *   [method@Pango.Attribute.destroy]
  */
 PangoAttribute *
-pango_attr_underline_new (PangoUnderline underline)
+pango_attr_underline_new (PangoLineStyle style)
 {
-  return pango_attr_int_new (PANGO_ATTR_UNDERLINE, (int)underline);
+  return pango_attr_int_new (PANGO_ATTR_UNDERLINE, (int)style);
 }
 
 /**
diff --git a/pango/pango-attributes.h b/pango/pango-attributes.h
index dc276024..bf309c08 100644
--- a/pango/pango-attributes.h
+++ b/pango/pango-attributes.h
@@ -143,31 +143,25 @@ PANGO_AVAILABLE_IN_ALL
 PangoAttribute *        pango_attr_font_desc_new                (const PangoFontDescription *desc);
 
 /**
- * PangoUnderline:
- * @PANGO_UNDERLINE_NONE: no underline should be drawn
- * @PANGO_UNDERLINE_SINGLE: a single underline should be drawn
- * @PANGO_UNDERLINE_DOUBLE: a double underline should be drawn
- * @PANGO_UNDERLINE_ERROR: an underline indicating an error should
- *   be drawn below. The exact style of rendering is up to the
- *   `PangoRenderer` in use, but typical styles include wavy
- *   or dotted lines.
- *   This underline is typically used to indicate an error such
- *   as a possible mispelling; in some cases a contrasting color
- *   may automatically be used. This type of underlining is
- *   available since Pango 1.4.
+ * PangoLineStyle:
+ * @PANGO_LINE_STYLE_NONE: no line should be drawn
+ * @PANGO_LINE_STYLE_SINGLE: a single line should be drawn
+ * @PANGO_LINE_STYLE_DOUBLE: a double line should be drawn
+ * @PANGO_LINE_STYLE_DOTTED: an dotted line should be drawn
  *
- * The `PangoUnderline` enumeration is used to specify whether text
- * should be underlined, and if so, the type of underlining.
+ * The `PangoLineStyle` enumeration is used to specify how
+ * lines should be drawn.
  */
 typedef enum {
-  PANGO_UNDERLINE_NONE,
-  PANGO_UNDERLINE_SINGLE,
-  PANGO_UNDERLINE_DOUBLE,
-  PANGO_UNDERLINE_ERROR
-} PangoUnderline;
+  PANGO_LINE_STYLE_NONE,
+  PANGO_LINE_STYLE_SINGLE,
+  PANGO_LINE_STYLE_DOUBLE,
+  PANGO_LINE_STYLE_DOTTED
+} PangoLineStyle;
 
 PANGO_AVAILABLE_IN_ALL
-PangoAttribute *        pango_attr_underline_new                (PangoUnderline              underline);
+PangoAttribute *        pango_attr_underline_new                (PangoLineStyle              style);
+
 PANGO_AVAILABLE_IN_1_8
 PangoAttribute *        pango_attr_underline_color_new          (PangoColor                 *color);
 
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 2e8e92e7..848afab9 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -99,16 +99,14 @@ typedef struct _LastTabState LastTabState;
 /* Note that letter_spacing and shape are constant across items,
  * since we pass them into itemization.
  *
- * uline and strikethrough can vary across an item, so we collect
+ * _styleuline and strikethrough can vary across an item, so we collect
  * all the values that we find.
  *
  * See pango_layout_get_item_properties for details.
  */
 struct _ItemProperties
 {
-  guint uline_single   : 1;
-  guint uline_double   : 1;
-  guint uline_error    : 1;
+  PangoLineStyle uline_style;
   PangoUnderlinePosition uline_position;
   guint strikethrough  : 1;
   guint oline_single   : 1;
@@ -5561,9 +5559,7 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
 
   pango_layout_get_item_properties (run->item, &properties);
 
-  has_underline = properties.uline_single ||
-                  properties.uline_double ||
-                  properties.uline_error;
+  has_underline = properties.uline_style != PANGO_LINE_STYLE_NONE;
   has_overline = properties.oline_single;
 
   if (!run_logical && (run->item->analysis.flags & PANGO_ANALYSIS_FLAG_CENTERED_BASELINE))
@@ -5621,7 +5617,7 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
           run_ink->height += underline_thickness;
         }
 
-      if (properties.uline_single)
+      if (properties.uline_style == PANGO_LINE_STYLE_SINGLE)
         {
           if (properties.uline_position == PANGO_UNDERLINE_POSITION_UNDER)
             run_ink->height += 2 * underline_thickness;
@@ -5629,10 +5625,10 @@ pango_layout_run_get_extents_and_height (PangoLayoutRun *run,
             run_ink->height = MAX (run_ink->height,
                                    underline_thickness - underline_position - run_ink->y);
         }
-      else if (properties.uline_double)
+      else if (properties.uline_style == PANGO_LINE_STYLE_DOUBLE)
         run_ink->height = MAX (run_ink->height,
                                  3 * underline_thickness - underline_position - run_ink->y);
-      else if (properties.uline_error)
+      else if (properties.uline_style == PANGO_LINE_STYLE_DOTTED)
         run_ink->height = MAX (run_ink->height,
                                3 * underline_thickness - underline_position - run_ink->y);
     }
@@ -6730,10 +6726,8 @@ pango_layout_get_item_properties (PangoItem      *item,
 {
   GSList *tmp_list = item->analysis.extra_attrs;
 
-  properties->uline_single = FALSE;
-  properties->uline_double = FALSE;
+  properties->uline_style = PANGO_LINE_STYLE_NONE;
   properties->uline_position = PANGO_UNDERLINE_POSITION_NORMAL;
-  properties->uline_error = FALSE;
   properties->oline_single = FALSE;
   properties->strikethrough = FALSE;
   properties->showing_space = FALSE;
@@ -6748,23 +6742,7 @@ pango_layout_get_item_properties (PangoItem      *item,
       switch ((int) attr->type)
         {
         case PANGO_ATTR_UNDERLINE:
-          switch (attr->int_value)
-            {
-            case PANGO_UNDERLINE_NONE:
-              break;
-            case PANGO_UNDERLINE_SINGLE:
-              properties->uline_single = TRUE;
-              break;
-            case PANGO_UNDERLINE_DOUBLE:
-              properties->uline_double = TRUE;
-              break;
-            case PANGO_UNDERLINE_ERROR:
-              properties->uline_error = TRUE;
-              break;
-            default:
-              g_assert_not_reached ();
-              break;
-            }
+          properties->uline_style = attr->int_value;
           break;
 
         case PANGO_ATTR_UNDERLINE_POSITION:
diff --git a/pango/pango-markup.c b/pango/pango-markup.c
index f8838d84..3802fa5e 100644
--- a/pango/pango-markup.c
+++ b/pango/pango-markup.c
@@ -500,7 +500,7 @@ text_handler           (GMarkupParseContext *context G_GNUC_UNUSED,
                       /* Add the underline indicating the accelerator */
                       PangoAttribute *attr;
 
-                      attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
+                      attr = pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE);
 
                       uline_index = md->index;
                       uline_len = g_utf8_next_char (p) - p;
@@ -1546,9 +1546,9 @@ span_parse_func     (MarkupData            *md G_GNUC_UNUSED,
 
   if (G_UNLIKELY (underline))
     {
-      PangoUnderline ul = PANGO_UNDERLINE_NONE;
+      PangoLineStyle ul = PANGO_LINE_STYLE_NONE;
 
-      if (!span_parse_enum ("underline", underline, PANGO_TYPE_UNDERLINE, (int*)(void*)&ul, line_number, 
error))
+      if (!span_parse_enum ("underline", underline, PANGO_TYPE_LINE_STYLE, (int*)(void*)&ul, line_number, 
error))
        goto error;
 
       add_attribute (tag, pango_attr_underline_new (ul));
@@ -1916,7 +1916,7 @@ u_parse_func        (MarkupData            *md G_GNUC_UNUSED,
                     GError               **error)
 {
   CHECK_NO_ATTRS("u");
-  add_attribute (tag, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
+  add_attribute (tag, pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
 
   return TRUE;
 }
diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index c4c20a87..a246bb73 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -41,7 +41,7 @@ struct _Point
 
 struct _LineState
 {
-  PangoUnderline underline;
+  PangoLineStyle underline;
   PangoUnderlinePosition underline_position;
   PangoRectangle underline_rect;
 
@@ -216,16 +216,16 @@ draw_underline (PangoRenderer *renderer,
                 LineState     *state)
 {
   PangoRectangle *rect = &state->underline_rect;
-  PangoUnderline underline = state->underline;
+  PangoLineStyle underline = state->underline;
 
-  state->underline = PANGO_UNDERLINE_NONE;
+  state->underline = PANGO_LINE_STYLE_NONE;
   state->underline_position = PANGO_UNDERLINE_POSITION_NORMAL;
 
   switch (underline)
     {
-    case PANGO_UNDERLINE_NONE:
+    case PANGO_LINE_STYLE_NONE:
       break;
-    case PANGO_UNDERLINE_DOUBLE:
+    case PANGO_LINE_STYLE_DOUBLE:
       pango_renderer_draw_rectangle (renderer,
                                      PANGO_RENDER_PART_UNDERLINE,
                                      rect->x,
@@ -233,7 +233,7 @@ draw_underline (PangoRenderer *renderer,
                                      rect->width,
                                      rect->height);
       G_GNUC_FALLTHROUGH;
-    case PANGO_UNDERLINE_SINGLE:
+    case PANGO_LINE_STYLE_SINGLE:
       pango_renderer_draw_rectangle (renderer,
                                      PANGO_RENDER_PART_UNDERLINE,
                                      rect->x,
@@ -241,7 +241,7 @@ draw_underline (PangoRenderer *renderer,
                                      rect->width,
                                      rect->height);
       break;
-    case PANGO_UNDERLINE_ERROR:
+    case PANGO_LINE_STYLE_DOTTED:
       pango_renderer_draw_error_underline (renderer,
                                            rect->x,
                                            rect->y,
@@ -311,7 +311,7 @@ handle_line_state_change (PangoRenderer  *renderer,
     return;
 
   if (part == PANGO_RENDER_PART_UNDERLINE &&
-      state->underline != PANGO_UNDERLINE_NONE)
+      state->underline != PANGO_LINE_STYLE_NONE)
     {
       PangoRectangle *rect = &state->underline_rect;
 
@@ -368,18 +368,18 @@ add_underline (PangoRenderer    *renderer,
 
   switch (renderer->underline)
     {
-    case PANGO_UNDERLINE_NONE:
+    case PANGO_LINE_STYLE_NONE:
       g_assert_not_reached ();
       break;
-    case PANGO_UNDERLINE_SINGLE:
+    case PANGO_LINE_STYLE_SINGLE:
       if (state->underline_position == PANGO_UNDERLINE_POSITION_UNDER)
         {
           new_rect.y += ink_rect->y + ink_rect->height + underline_thickness;
           break;
         }
       G_GNUC_FALLTHROUGH;
-    case PANGO_UNDERLINE_DOUBLE:
-    case PANGO_UNDERLINE_ERROR:
+    case PANGO_LINE_STYLE_DOUBLE:
+    case PANGO_LINE_STYLE_DOTTED:
       new_rect.y -= underline_position;
       if (state->underline == renderer->underline)
         {
@@ -547,7 +547,7 @@ pango_renderer_draw_layout_line (PangoRenderer   *renderer,
   renderer->priv->line = line;
   renderer->priv->line_state = &state;
 
-  state.underline = PANGO_UNDERLINE_NONE;
+  state.underline = PANGO_LINE_STYLE_NONE;
   state.underline_position = PANGO_UNDERLINE_POSITION_NORMAL;
   state.overline = PANGO_OVERLINE_NONE;
   state.strikethrough = FALSE;
@@ -567,7 +567,7 @@ pango_renderer_draw_layout_line (PangoRenderer   *renderer,
 
       pango_renderer_prepare_run (renderer, run);
 
-      if (renderer->underline != PANGO_UNDERLINE_NONE ||
+      if (renderer->underline != PANGO_LINE_STYLE_NONE ||
           renderer->priv->overline != PANGO_OVERLINE_NONE ||
           renderer->strikethrough)
         {
@@ -620,14 +620,14 @@ pango_renderer_draw_layout_line (PangoRenderer   *renderer,
                                       run,
                                       x + x_off, y - y_off);
 
-      if (renderer->underline != PANGO_UNDERLINE_NONE ||
+      if (renderer->underline != PANGO_LINE_STYLE_NONE ||
           renderer->priv->overline != PANGO_OVERLINE_NONE ||
           renderer->strikethrough)
         {
           metrics = pango_font_get_metrics (run->item->analysis.font,
                                             run->item->analysis.language);
 
-          if (renderer->underline != PANGO_UNDERLINE_NONE)
+          if (renderer->underline != PANGO_LINE_STYLE_NONE)
             add_underline (renderer, &state,metrics,
                            x + x_off, y - y_off,
                            ink, logical);
@@ -645,8 +645,8 @@ pango_renderer_draw_layout_line (PangoRenderer   *renderer,
           pango_font_metrics_unref (metrics);
         }
 
-      if (renderer->underline == PANGO_UNDERLINE_NONE &&
-          state.underline != PANGO_UNDERLINE_NONE)
+      if (renderer->underline == PANGO_LINE_STYLE_NONE &&
+          state.underline != PANGO_LINE_STYLE_NONE)
         draw_underline (renderer, &state);
 
       if (renderer->priv->overline == PANGO_OVERLINE_NONE &&
@@ -1403,7 +1403,7 @@ pango_renderer_default_prepare_run (PangoRenderer  *renderer,
   guint16 bg_alpha = 0;
   GSList *l;
 
-  renderer->underline = PANGO_UNDERLINE_NONE;
+  renderer->underline = PANGO_LINE_STYLE_NONE;
   renderer->underline_position = PANGO_UNDERLINE_POSITION_NORMAL;
   renderer->priv->overline = PANGO_OVERLINE_NONE;
   renderer->strikethrough = FALSE;
diff --git a/pango/pango-renderer.h b/pango/pango-renderer.h
index fcad2b3d..6be251cd 100644
--- a/pango/pango-renderer.h
+++ b/pango/pango-renderer.h
@@ -79,7 +79,7 @@ struct _PangoRenderer
   /*< private >*/
   GObject parent_instance;
 
-  PangoUnderline underline;
+  PangoLineStyle underline;
   PangoUnderlinePosition underline_position;
   gboolean strikethrough;
   int active_count;
diff --git a/pango/serializer.c b/pango/serializer.c
index 9a1ee065..6ff7a3a4 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -72,12 +72,11 @@ static const char *stretch_names[] = {
   NULL
 };
 
-static const char *underline_names[] = {
+static const char *line_style_names[] = {
   "none",
   "single",
   "double",
-  "low",
-  "error",
+  "dotted",
   NULL
 };
 
@@ -325,7 +324,7 @@ add_attribute (GtkJsonPrinter *printer,
           break;
 
         case PANGO_ATTR_UNDERLINE:
-          gtk_json_printer_add_string (printer, "value", underline_names[attr->int_value]);
+          gtk_json_printer_add_string (printer, "value", line_style_names[attr->int_value]);
           break;
 
         case PANGO_ATTR_UNDERLINE_POSITION:
@@ -1013,7 +1012,7 @@ attr_for_type (GtkJsonParser *parser,
       break;
 
     case PANGO_ATTR_UNDERLINE:
-      attr = pango_attr_underline_new ((PangoUnderline) parser_select_string (parser, underline_names));
+      attr = pango_attr_underline_new ((PangoLineStyle) parser_select_string (parser, line_style_names));
       break;
 
     case PANGO_ATTR_UNDERLINE_POSITION:
diff --git a/tests/testattributes.c b/tests/testattributes.c
index e07387f4..c308d67c 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -50,8 +50,8 @@ test_attributes_basic (void)
   desc = pango_font_description_from_string ("Computer Modern 12");
   test_copy (pango_attr_font_desc_new (desc));
   pango_font_description_free (desc);
-  test_copy (pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
-  test_copy (pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
+  test_copy (pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
+  test_copy (pango_attr_underline_new (PANGO_LINE_STYLE_DOTTED));
   test_copy (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
   test_copy (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
   test_copy (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));
@@ -230,8 +230,8 @@ test_binding_helpers (void)
   desc = pango_font_description_from_string ("Computer Modern 12");
   test_binding (pango_attr_font_desc_new (desc));
   pango_font_description_free (desc);
-  test_binding (pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
-  test_binding (pango_attr_underline_new (PANGO_UNDERLINE_ERROR));
+  test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_SINGLE));
+  test_binding (pango_attr_underline_new (PANGO_LINE_STYLE_DOTTED));
   test_binding (pango_attr_underline_color_new (&(PangoColor){100, 200, 300}));
   test_binding (pango_attr_overline_new (PANGO_OVERLINE_SINGLE));
   test_binding (pango_attr_overline_color_new (&(PangoColor){100, 200, 300}));


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