[gtk/a11y/atspi] atspi: Export more pango utils



commit ba63daa1d29312924eb4477a356b6a4fec6fd41c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 10 23:50:02 2020 -0400

    atspi: Export more pango utils
    
    We are going to reuse some of the code that does
    the pango -> atspi attribute conversion for text
    tags.

 gtk/a11y/gtkatspipango.c        | 69 ++++++++++++++++++++++++++---------------
 gtk/a11y/gtkatspipangoprivate.h |  8 +++++
 2 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/gtk/a11y/gtkatspipango.c b/gtk/a11y/gtkatspipango.c
index e5d2ff8657..1171c8758b 100644
--- a/gtk/a11y/gtkatspipango.c
+++ b/gtk/a11y/gtkatspipango.c
@@ -19,7 +19,7 @@
 #include "config.h"
 #include "gtkatspipangoprivate.h"
 
-static const char *
+const char *
 pango_style_to_string (PangoStyle style)
 {
   switch (style)
@@ -35,7 +35,7 @@ pango_style_to_string (PangoStyle style)
     }
 }
 
-static const char *
+const char *
 pango_variant_to_string (PangoVariant variant)
 {
   switch (variant)
@@ -49,7 +49,7 @@ pango_variant_to_string (PangoVariant variant)
     }
 }
 
-static const char *
+const char *
 pango_stretch_to_string (PangoStretch stretch)
 {
   switch (stretch)
@@ -77,7 +77,7 @@ pango_stretch_to_string (PangoStretch stretch)
     }
 }
 
-static const char *
+const char *
 pango_underline_to_string (PangoUnderline value)
 {
   switch (value)
@@ -100,6 +100,43 @@ pango_underline_to_string (PangoUnderline value)
     }
 }
 
+const char *
+pango_wrap_mode_to_string (PangoWrapMode mode)
+{
+  switch (mode)
+    {
+    case PANGO_WRAP_WORD:
+      return "word";
+    case PANGO_WRAP_CHAR:
+      return "char";
+    case PANGO_WRAP_WORD_CHAR:
+      return "word-char";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+void
+gtk_pango_get_font_attributes (PangoFontDescription *font,
+                               GVariantBuilder      *builder)
+{
+  char buf[60];
+
+  g_variant_builder_add (builder, "{ss}", "style",
+                         pango_style_to_string (pango_font_description_get_style (font)));
+  g_variant_builder_add (builder, "{ss}", "variant",
+                         pango_variant_to_string (pango_font_description_get_variant (font)));
+  g_variant_builder_add (builder, "{ss}", "stretch",
+                         pango_stretch_to_string (pango_font_description_get_stretch (font)));
+  g_variant_builder_add (builder, "{ss}", "family-name",
+                         pango_font_description_get_family (font));
+
+  g_snprintf (buf, 60, "%d", pango_font_description_get_weight (font));
+  g_variant_builder_add (builder, "{ss}", "weight", buf);
+  g_snprintf (buf, 60, "%i", pango_font_description_get_size (font) / PANGO_SCALE);
+  g_variant_builder_add (builder, "{ss}", "size", buf);
+}
+
 /*
  * gtk_pango_get_default_attributes:
  * @attributes: a #AtkAttributeSet to add the attributes to
@@ -136,22 +173,7 @@ gtk_pango_get_default_attributes (PangoLayout     *layout,
 
       font = pango_context_get_font_description (context);
       if (font)
-        {
-          char buf[60];
-          g_variant_builder_add (builder, "{ss}", "style",
-                                 pango_style_to_string (pango_font_description_get_style (font)));
-          g_variant_builder_add (builder, "{ss}", "variant",
-                                 pango_variant_to_string (pango_font_description_get_variant (font)));
-          g_variant_builder_add (builder, "{ss}", "stretch",
-                                 pango_stretch_to_string (pango_font_description_get_stretch (font)));
-          g_variant_builder_add (builder, "{ss}", "family-name",
-                                 pango_font_description_get_family (font));
-
-          g_snprintf (buf, 60, "%d", pango_font_description_get_weight (font));
-          g_variant_builder_add (builder, "{ss}", "weight", buf);
-          g_snprintf (buf, 60, "%i", pango_font_description_get_size (font) / PANGO_SCALE);
-          g_variant_builder_add (builder, "{ss}", "size", buf);
-        }
+        gtk_pango_get_font_attributes (font, builder);
     }
   if (pango_layout_get_justify (layout))
     {
@@ -170,11 +192,8 @@ gtk_pango_get_default_attributes (PangoLayout     *layout,
   g_variant_builder_add (builder, "{ss}", "justification", val);
 
   mode = pango_layout_get_wrap (layout);
-  if (mode == PANGO_WRAP_WORD)
-    val = "word";
-  else
-    val = "char";
-  g_variant_builder_add (builder, "{ss}", "wrap-mode", val);
+  g_variant_builder_add (builder, "{ss}", "wrap-mode",
+                         pango_wrap_mode_to_string (mode));
 
   g_variant_builder_add (builder, "{ss}", "strikethrough", "false");
   g_variant_builder_add (builder, "{ss}", "underline", "false");
diff --git a/gtk/a11y/gtkatspipangoprivate.h b/gtk/a11y/gtkatspipangoprivate.h
index f5485fef58..e9e91d292f 100644
--- a/gtk/a11y/gtkatspipangoprivate.h
+++ b/gtk/a11y/gtkatspipangoprivate.h
@@ -22,6 +22,14 @@
 
 G_BEGIN_DECLS
 
+const char *pango_wrap_mode_to_string (PangoWrapMode mode);
+const char *pango_underline_to_string (PangoUnderline underline);
+const char *pango_stretch_to_string (PangoStretch stretch);
+const char *pango_style_to_string (PangoStyle style);
+const char *pango_variant_to_string (PangoVariant variant);
+
+void gtk_pango_get_font_attributes (PangoFontDescription *font,
+                                    GVariantBuilder      *builder);
 void gtk_pango_get_default_attributes (PangoLayout     *layout,
                                        GVariantBuilder *builder);
 void gtk_pango_get_run_attributes     (PangoLayout     *layout,


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