[gtk/ebassi/textbuffer-private-api: 1/2] Move private function out of the AT-SPI a11y backend




commit d030c92d6347444b1cb0bfb59ad950436d79dd66
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Aug 4 23:34:41 2022 +0100

    Move private function out of the AT-SPI a11y backend
    
    The textbuffer test is calling into a function defined by the AT-SPI
    accessibility backend. As of commit 4ddf1b70 we only build and run the
    test on Linux, but the function in question isn't really
    accessibility-related: it's just a serialization function.

 gtk/a11y/gtkatspipango.c             | 125 +-------
 gtk/a11y/gtkatspipangoprivate.h      |   6 -
 gtk/a11y/gtkatspitext.c              |   8 +-
 gtk/a11y/gtkatspitextbuffer.c        | 555 +---------------------------------
 gtk/a11y/gtkatspitextbufferprivate.h |   5 -
 gtk/gtkpango.c                       | 124 ++++++++
 gtk/gtkpango.h                       |   7 +
 gtk/gtktextbuffer.c                  | 570 +++++++++++++++++++++++++++++++++++
 gtk/gtktextbufferprivate.h           |  11 +
 testsuite/gtk/textbuffer.c           | 168 +++++------
 10 files changed, 804 insertions(+), 775 deletions(-)
---
diff --git a/gtk/a11y/gtkatspipango.c b/gtk/a11y/gtkatspipango.c
index b353027cc4..f0f3ed746f 100644
--- a/gtk/a11y/gtkatspipango.c
+++ b/gtk/a11y/gtkatspipango.c
@@ -18,130 +18,7 @@
 
 #include "config.h"
 #include "gtkatspipangoprivate.h"
-
-const char *
-pango_style_to_string (PangoStyle style)
-{
-  switch (style)
-    {
-    case PANGO_STYLE_NORMAL:
-      return "normal";
-    case PANGO_STYLE_OBLIQUE:
-      return "oblique";
-    case PANGO_STYLE_ITALIC:
-      return "italic";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-const char *
-pango_variant_to_string (PangoVariant variant)
-{
-  switch (variant)
-    {
-    case PANGO_VARIANT_NORMAL:
-      return "normal";
-    case PANGO_VARIANT_SMALL_CAPS:
-      return "small_caps";
-    case PANGO_VARIANT_ALL_SMALL_CAPS:
-      return "all_small_caps";
-    case PANGO_VARIANT_PETITE_CAPS:
-      return "petite_caps";
-    case PANGO_VARIANT_ALL_PETITE_CAPS:
-      return "all_petite_caps";
-    case PANGO_VARIANT_UNICASE:
-      return "unicase";
-    case PANGO_VARIANT_TITLE_CAPS:
-      return "title_caps";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-const char *
-pango_stretch_to_string (PangoStretch stretch)
-{
-  switch (stretch)
-    {
-    case PANGO_STRETCH_ULTRA_CONDENSED:
-      return "ultra_condensed";
-    case PANGO_STRETCH_EXTRA_CONDENSED:
-      return "extra_condensed";
-    case PANGO_STRETCH_CONDENSED:
-      return "condensed";
-    case PANGO_STRETCH_SEMI_CONDENSED:
-      return "semi_condensed";
-    case PANGO_STRETCH_NORMAL:
-      return "normal";
-    case PANGO_STRETCH_SEMI_EXPANDED:
-      return "semi_expanded";
-    case PANGO_STRETCH_EXPANDED:
-      return "expanded";
-    case PANGO_STRETCH_EXTRA_EXPANDED:
-      return "extra_expanded";
-    case PANGO_STRETCH_ULTRA_EXPANDED:
-      return "ultra_expanded";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-const char *
-pango_underline_to_string (PangoUnderline value)
-{
-  switch (value)
-    {
-    case PANGO_UNDERLINE_NONE:
-      return "none";
-    case PANGO_UNDERLINE_SINGLE:
-    case PANGO_UNDERLINE_SINGLE_LINE:
-      return "single";
-    case PANGO_UNDERLINE_DOUBLE:
-    case PANGO_UNDERLINE_DOUBLE_LINE:
-      return "double";
-    case PANGO_UNDERLINE_LOW:
-      return "low";
-    case PANGO_UNDERLINE_ERROR:
-    case PANGO_UNDERLINE_ERROR_LINE:
-      return "error";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-const char *
-pango_wrap_mode_to_string (PangoWrapMode mode)
-{
-  /* Keep these in sync with gtk_wrap_mode_to_string() */
-  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 ();
-    }
-}
-
-static const char *
-pango_align_to_string (PangoAlignment align)
-{
-  switch (align)
-    {
-    case PANGO_ALIGN_LEFT:
-      return "left";
-    case PANGO_ALIGN_CENTER:
-      return "center";
-    case PANGO_ALIGN_RIGHT:
-      return "right";
-    default:
-      g_assert_not_reached ();
-    }
-}
+#include "gtkpango.h"
 
 void
 gtk_pango_get_font_attributes (PangoFontDescription *font,
diff --git a/gtk/a11y/gtkatspipangoprivate.h b/gtk/a11y/gtkatspipangoprivate.h
index e9e91d292f..8b97016948 100644
--- a/gtk/a11y/gtkatspipangoprivate.h
+++ b/gtk/a11y/gtkatspipangoprivate.h
@@ -22,12 +22,6 @@
 
 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,
diff --git a/gtk/a11y/gtkatspitext.c b/gtk/a11y/gtkatspitext.c
index e7bd9275be..1e6c8c5ae7 100644
--- a/gtk/a11y/gtkatspitext.c
+++ b/gtk/a11y/gtkatspitext.c
@@ -32,13 +32,15 @@
 #include "gtkatcontextprivate.h"
 #include "gtkdebug.h"
 #include "gtkeditable.h"
+#include "gtkentryprivate.h"
 #include "gtkinscriptionprivate.h"
 #include "gtklabelprivate.h"
-#include "gtkentryprivate.h"
-#include "gtksearchentryprivate.h"
+#include "gtkpango.h"
 #include "gtkpasswordentryprivate.h"
+#include "gtksearchentryprivate.h"
 #include "gtkspinbuttonprivate.h"
-#include "gtktextview.h"
+#include "gtktextbufferprivate.h"
+#include "gtktextviewprivate.h"
 
 #include <gio/gio.h>
 
diff --git a/gtk/a11y/gtkatspitextbuffer.c b/gtk/a11y/gtkatspitextbuffer.c
index 40fd05fa1f..bb8869db62 100644
--- a/gtk/a11y/gtkatspitextbuffer.c
+++ b/gtk/a11y/gtkatspitextbuffer.c
@@ -19,62 +19,9 @@
 #include "config.h"
 #include "gtkatspitextbufferprivate.h"
 #include "gtkatspipangoprivate.h"
+#include "gtktextbufferprivate.h"
 #include "gtktextviewprivate.h"
-
-static const char *
-gtk_justification_to_string (GtkJustification just)
-{
-  switch (just)
-    {
-    case GTK_JUSTIFY_LEFT:
-      return "left";
-    case GTK_JUSTIFY_RIGHT:
-      return "right";
-    case GTK_JUSTIFY_CENTER:
-      return "center";
-    case GTK_JUSTIFY_FILL:
-      return "fill";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-static const char *
-gtk_text_direction_to_string (GtkTextDirection direction)
-{
-  switch (direction)
-    {
-    case GTK_TEXT_DIR_NONE:
-      return "none";
-    case GTK_TEXT_DIR_LTR:
-      return "ltr";
-    case GTK_TEXT_DIR_RTL:
-      return "rtl";
-    default:
-      g_assert_not_reached ();
-    }
-}
-
-static const char *
-gtk_wrap_mode_to_string (GtkWrapMode wrap_mode)
-{
-  /* Keep these in sync with pango_wrap_mode_to_string(); note that
-   * here we have an extra case for NONE.
-   */
-  switch (wrap_mode)
-    {
-    case GTK_WRAP_NONE:
-      return "none";
-    case GTK_WRAP_CHAR:
-      return "char";
-    case GTK_WRAP_WORD:
-      return "word";
-    case GTK_WRAP_WORD_CHAR:
-      return "word-char";
-    default:
-      g_assert_not_reached ();
-    }
-}
+#include "gtkpango.h"
 
 void
 gtk_text_view_add_default_attributes (GtkTextView     *view,
@@ -161,504 +108,6 @@ gtk_text_view_add_default_attributes (GtkTextView     *view,
   gtk_text_attributes_unref (text_attrs);
 }
 
-void
-gtk_text_buffer_get_run_attributes (GtkTextBuffer   *buffer,
-                                    GVariantBuilder *builder,
-                                    int              offset,
-                                    int             *start_offset,
-                                    int             *end_offset)
-{
-  GtkTextIter iter;
-  GSList *tags, *temp_tags;
-  double scale = 1;
-  gboolean val_set = FALSE;
-
-  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
-
-  gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
-  *end_offset = gtk_text_iter_get_offset (&iter);
-
-  gtk_text_iter_backward_to_tag_toggle (&iter, NULL);
-  *start_offset = gtk_text_iter_get_offset (&iter);
-
-  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
-
-  tags = gtk_text_iter_get_tags (&iter);
-  tags = g_slist_reverse (tags);
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      PangoStyle style;
-
-      g_object_get (tag,
-                    "style-set", &val_set,
-                    "style", &style,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "style", pango_style_to_string (style));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      PangoVariant variant;
-
-      g_object_get (tag,
-                    "variant-set", &val_set,
-                    "variant", &variant,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "variant", pango_variant_to_string (variant));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      PangoStretch stretch;
-
-      g_object_get (tag,
-                    "stretch-set", &val_set,
-                    "stretch", &stretch,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "stretch", pango_stretch_to_string (stretch));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      GtkJustification justification;
-
-      g_object_get (tag,
-                    "justification-set", &val_set,
-                    "justification", &justification,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "justification", gtk_justification_to_string 
(justification));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      GtkTextDirection direction;
-
-      g_object_get (tag, "direction", &direction, NULL);
-      if (direction != GTK_TEXT_DIR_NONE)
-        {
-          val_set = TRUE;
-          g_variant_builder_add (builder, "{ss}", "direction", gtk_text_direction_to_string (direction));
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      GtkWrapMode wrap_mode;
-
-      g_object_get (tag,
-                    "wrap-mode-set", &val_set,
-                    "wrap-mode", &wrap_mode,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "wrap-mode", gtk_wrap_mode_to_string (wrap_mode));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-
-      g_object_get (tag, "foreground-set", &val_set, NULL);
-      if (val_set)
-        {
-          GdkRGBA *rgba;
-          char *value;
-
-          g_object_get (tag, "foreground", &rgba, NULL);
-          value = g_strdup_printf ("%u,%u,%u",
-                                   (guint) rgba->red * 65535,
-                                   (guint) rgba->green * 65535,
-                                   (guint) rgba->blue * 65535);
-          gdk_rgba_free (rgba);
-          g_variant_builder_add (builder, "{ss}", "fg-color", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-
-      g_object_get (tag, "background-set", &val_set, NULL);
-      if (val_set)
-        {
-          GdkRGBA *rgba;
-          char *value;
-
-          g_object_get (tag, "background-rgba", &rgba, NULL);
-          value = g_strdup_printf ("%u,%u,%u",
-                                   (guint) rgba->red * 65535,
-                                   (guint) rgba->green * 65535,
-                                   (guint) rgba->blue * 65535);
-          gdk_rgba_free (rgba);
-          g_variant_builder_add (builder, "{ss}", "bg-color", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-
-      g_object_get (tag, "family-set", &val_set, NULL);
-
-      if (val_set)
-        {
-          char *value;
-          g_object_get (tag, "family", &value, NULL);
-          g_variant_builder_add (builder, "{ss}", "family-name", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-
-      g_object_get (tag, "language-set", &val_set, NULL);
-
-      if (val_set)
-        {
-          char *value;
-          g_object_get (tag, "language", &value, NULL);
-          g_variant_builder_add (builder, "{ss}", "language", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int weight;
-
-      g_object_get (tag,
-                    "weight-set", &val_set,
-                    "weight", &weight,
-                    NULL);
-
-      if (val_set)
-        {
-          char *value;
-          value = g_strdup_printf ("%d", weight);
-          g_variant_builder_add (builder, "{ss}", "weight", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  /* scale is special as the effective value is the product
-   * of all specified values
-   */
-  temp_tags = tags;
-  while (temp_tags)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      gboolean scale_set;
-
-      g_object_get (tag, "scale-set", &scale_set, NULL);
-      if (scale_set)
-        {
-          double font_scale;
-          g_object_get (tag, "scale", &font_scale, NULL);
-          val_set = TRUE;
-          scale *= font_scale;
-        }
-      temp_tags = temp_tags->next;
-    }
-  if (val_set)
-    {
-      char *value = g_strdup_printf ("%g", scale);
-      g_variant_builder_add (builder, "{ss}", "scale", value);
-      g_free (value);
-    }
-  val_set = FALSE;
-
- temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int size;
-
-      g_object_get (tag,
-                    "size-set", &val_set,
-                    "size", &size,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", size);
-          g_variant_builder_add (builder, "{ss}", "size", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      gboolean strikethrough;
-
-      g_object_get (tag,
-                    "strikethrough-set", &val_set,
-                    "strikethrough", &strikethrough,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "strikethrough", strikethrough ? "true" : "false");
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      PangoUnderline underline;
-
-      g_object_get (tag,
-                    "underline-set", &val_set,
-                    "underline", &underline,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "underline",
-                               pango_underline_to_string (underline));
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int rise;
-
-      g_object_get (tag,
-                    "rise-set", &val_set,
-                    "rise", &rise,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", rise);
-          g_variant_builder_add (builder, "{ss}", "rise", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      gboolean bg_full_height;
-
-      g_object_get (tag,
-                    "background-full-height-set", &val_set,
-                    "background-full-height", &bg_full_height,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "bg-full-height", bg_full_height ? "true" : "false");
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int pixels;
-
-      g_object_get (tag,
-                    "pixels-inside-wrap-set", &val_set,
-                    "pixels-inside-wrap", &pixels,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", pixels);
-          g_variant_builder_add (builder, "{ss}", "pixels-inside-wrap", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int pixels;
-
-      g_object_get (tag,
-                    "pixels-below-lines-set", &val_set,
-                    "pixels-below-lines", &pixels,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", pixels);
-          g_variant_builder_add (builder, "{ss}", "pixels-below-lines", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int pixels;
-
-      g_object_get (tag,
-                    "pixels-above-lines-set", &val_set,
-                    "pixels-above-lines", &pixels,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", pixels);
-          g_variant_builder_add (builder, "{ss}", "pixels-above-lines", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      gboolean editable;
-
-      g_object_get (tag,
-                    "editable-set", &val_set,
-                    "editable", &editable,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "editable", editable ? "true" : "false");
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      gboolean invisible;
-
-      g_object_get (tag,
-                    "invisible-set", &val_set,
-                    "invisible", &invisible,
-                    NULL);
-      if (val_set)
-        g_variant_builder_add (builder, "{ss}", "invisible", invisible ? "true" : "false");
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
- temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int indent;
-
-      g_object_get (tag,
-                    "indent-set", &val_set,
-                    "indent", &indent,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", indent);
-          g_variant_builder_add (builder, "{ss}", "indent", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int margin;
-
-      g_object_get (tag,
-                    "right-margin-set", &val_set,
-                    "right-margin", &margin,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", margin);
-          g_variant_builder_add (builder, "{ss}", "right-margin", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  temp_tags = tags;
-  while (temp_tags && !val_set)
-    {
-      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
-      int margin;
-
-      g_object_get (tag,
-                    "left-margin-set", &val_set,
-                    "left-margin", &margin,
-                    NULL);
-      if (val_set)
-        {
-          char *value = g_strdup_printf ("%i", margin);
-          g_variant_builder_add (builder, "{ss}", "left-margin", value);
-          g_free (value);
-        }
-      temp_tags = temp_tags->next;
-    }
-  val_set = FALSE;
-
-  g_slist_free (tags);
-}
-
 char *
 gtk_text_view_get_text_before (GtkTextView           *view,
                                int                    offset,
diff --git a/gtk/a11y/gtkatspitextbufferprivate.h b/gtk/a11y/gtkatspitextbufferprivate.h
index fb97a94641..2b0017a112 100644
--- a/gtk/a11y/gtkatspitextbufferprivate.h
+++ b/gtk/a11y/gtkatspitextbufferprivate.h
@@ -25,11 +25,6 @@ G_BEGIN_DECLS
 
 void gtk_text_view_add_default_attributes (GtkTextView     *view,
                                            GVariantBuilder *builder);
-void gtk_text_buffer_get_run_attributes   (GtkTextBuffer   *buffer,
-                                           GVariantBuilder *builder,
-                                           int              offset,
-                                           int             *start_offset,
-                                           int             *end_offset);
 
 char *gtk_text_view_get_text_before (GtkTextView           *view,
                                      int                    offset,
diff --git a/gtk/gtkpango.c b/gtk/gtkpango.c
index 58ee7a3bf2..2ef8897c98 100644
--- a/gtk/gtkpango.c
+++ b/gtk/gtkpango.c
@@ -381,3 +381,127 @@ gtk_pango_attribute_start_element (GtkBuildableParseContext  *context,
                                         error);
     }
 }
+
+const char *
+pango_style_to_string (PangoStyle style)
+{
+  switch (style)
+    {
+    case PANGO_STYLE_NORMAL:
+      return "normal";
+    case PANGO_STYLE_OBLIQUE:
+      return "oblique";
+    case PANGO_STYLE_ITALIC:
+      return "italic";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+pango_variant_to_string (PangoVariant variant)
+{
+  switch (variant)
+    {
+    case PANGO_VARIANT_NORMAL:
+      return "normal";
+    case PANGO_VARIANT_SMALL_CAPS:
+      return "small_caps";
+    case PANGO_VARIANT_ALL_SMALL_CAPS:
+      return "all_small_caps";
+    case PANGO_VARIANT_PETITE_CAPS:
+      return "petite_caps";
+    case PANGO_VARIANT_ALL_PETITE_CAPS:
+      return "all_petite_caps";
+    case PANGO_VARIANT_UNICASE:
+      return "unicase";
+    case PANGO_VARIANT_TITLE_CAPS:
+      return "title_caps";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+pango_stretch_to_string (PangoStretch stretch)
+{
+  switch (stretch)
+    {
+    case PANGO_STRETCH_ULTRA_CONDENSED:
+      return "ultra_condensed";
+    case PANGO_STRETCH_EXTRA_CONDENSED:
+      return "extra_condensed";
+    case PANGO_STRETCH_CONDENSED:
+      return "condensed";
+    case PANGO_STRETCH_SEMI_CONDENSED:
+      return "semi_condensed";
+    case PANGO_STRETCH_NORMAL:
+      return "normal";
+    case PANGO_STRETCH_SEMI_EXPANDED:
+      return "semi_expanded";
+    case PANGO_STRETCH_EXPANDED:
+      return "expanded";
+    case PANGO_STRETCH_EXTRA_EXPANDED:
+      return "extra_expanded";
+    case PANGO_STRETCH_ULTRA_EXPANDED:
+      return "ultra_expanded";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+pango_underline_to_string (PangoUnderline value)
+{
+  switch (value)
+    {
+    case PANGO_UNDERLINE_NONE:
+      return "none";
+    case PANGO_UNDERLINE_SINGLE:
+    case PANGO_UNDERLINE_SINGLE_LINE:
+      return "single";
+    case PANGO_UNDERLINE_DOUBLE:
+    case PANGO_UNDERLINE_DOUBLE_LINE:
+      return "double";
+    case PANGO_UNDERLINE_LOW:
+      return "low";
+    case PANGO_UNDERLINE_ERROR:
+    case PANGO_UNDERLINE_ERROR_LINE:
+      return "error";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+pango_wrap_mode_to_string (PangoWrapMode mode)
+{
+  /* Keep these in sync with gtk_wrap_mode_to_string() */
+  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 ();
+    }
+}
+
+const char *
+pango_align_to_string (PangoAlignment align)
+{
+  switch (align)
+    {
+    case PANGO_ALIGN_LEFT:
+      return "left";
+    case PANGO_ALIGN_CENTER:
+      return "center";
+    case PANGO_ALIGN_RIGHT:
+      return "right";
+    default:
+      g_assert_not_reached ();
+    }
+}
diff --git a/gtk/gtkpango.h b/gtk/gtkpango.h
index 55cab30b3c..3d673d9b0a 100644
--- a/gtk/gtkpango.h
+++ b/gtk/gtkpango.h
@@ -54,6 +54,13 @@ gtk_pango_attribute_start_element (GtkBuildableParseContext  *context,
                                    gpointer                   user_data,
                                    GError                   **error);
 
+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);
+const char *pango_align_to_string (PangoAlignment align);
+
 G_END_DECLS
 
 #endif /* __GTK_PANGO_H__ */
diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c
index b3fa50ab5c..f4b728df11 100644
--- a/gtk/gtktextbuffer.c
+++ b/gtk/gtktextbuffer.c
@@ -35,6 +35,7 @@
 #include "gtktextiterprivate.h"
 #include "gtktexttagprivate.h"
 #include "gtktexttagtableprivate.h"
+#include "gtkpango.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -5125,3 +5126,572 @@ gtk_text_buffer_set_max_undo_levels (GtkTextBuffer *buffer,
 
   gtk_text_history_set_max_undo_levels (buffer->priv->history, max_undo_levels);
 }
+
+const char *
+gtk_justification_to_string (GtkJustification just)
+{
+  switch (just)
+    {
+    case GTK_JUSTIFY_LEFT:
+      return "left";
+    case GTK_JUSTIFY_RIGHT:
+      return "right";
+    case GTK_JUSTIFY_CENTER:
+      return "center";
+    case GTK_JUSTIFY_FILL:
+      return "fill";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+gtk_text_direction_to_string (GtkTextDirection direction)
+{
+  switch (direction)
+    {
+    case GTK_TEXT_DIR_NONE:
+      return "none";
+    case GTK_TEXT_DIR_LTR:
+      return "ltr";
+    case GTK_TEXT_DIR_RTL:
+      return "rtl";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+const char *
+gtk_wrap_mode_to_string (GtkWrapMode wrap_mode)
+{
+  /* Keep these in sync with pango_wrap_mode_to_string(); note that
+   * here we have an extra case for NONE.
+   */
+  switch (wrap_mode)
+    {
+    case GTK_WRAP_NONE:
+      return "none";
+    case GTK_WRAP_CHAR:
+      return "char";
+    case GTK_WRAP_WORD:
+      return "word";
+    case GTK_WRAP_WORD_CHAR:
+      return "word-char";
+    default:
+      g_assert_not_reached ();
+    }
+}
+
+/*< private >
+ * gtk_text_buffer_get_run_attributes:
+ * @buffer: the buffer to serialize
+ * @builder: the target `GVariant` builder
+ * @offset: the offset into the text buffer
+ * @start_offset: (out): the start offset for the attributes run
+ * @end_offset: (out): the end offset for the attributes run
+ *
+ * Serializes the attributes inside a text buffer at the given offset.
+ *
+ * All attributes are serializes as a dictionary of string keys
+ * and string values, `a{ss}`.
+ *
+ * The serialization format is private to GTK and should not be
+ * considered stable.
+ */
+void
+gtk_text_buffer_get_run_attributes (GtkTextBuffer   *buffer,
+                                    GVariantBuilder *builder,
+                                    int              offset,
+                                    int             *start_offset,
+                                    int             *end_offset)
+{
+  GtkTextIter iter;
+  GSList *tags, *temp_tags;
+  double scale = 1;
+  gboolean val_set = FALSE;
+
+  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
+
+  gtk_text_iter_forward_to_tag_toggle (&iter, NULL);
+  *end_offset = gtk_text_iter_get_offset (&iter);
+
+  gtk_text_iter_backward_to_tag_toggle (&iter, NULL);
+  *start_offset = gtk_text_iter_get_offset (&iter);
+
+  gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
+
+  tags = gtk_text_iter_get_tags (&iter);
+  tags = g_slist_reverse (tags);
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      PangoStyle style;
+
+      g_object_get (tag,
+                    "style-set", &val_set,
+                    "style", &style,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "style", pango_style_to_string (style));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      PangoVariant variant;
+
+      g_object_get (tag,
+                    "variant-set", &val_set,
+                    "variant", &variant,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "variant", pango_variant_to_string (variant));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      PangoStretch stretch;
+
+      g_object_get (tag,
+                    "stretch-set", &val_set,
+                    "stretch", &stretch,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "stretch", pango_stretch_to_string (stretch));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      GtkJustification justification;
+
+      g_object_get (tag,
+                    "justification-set", &val_set,
+                    "justification", &justification,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "justification", gtk_justification_to_string 
(justification));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      GtkTextDirection direction;
+
+      g_object_get (tag, "direction", &direction, NULL);
+      if (direction != GTK_TEXT_DIR_NONE)
+        {
+          val_set = TRUE;
+          g_variant_builder_add (builder, "{ss}", "direction", gtk_text_direction_to_string (direction));
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      GtkWrapMode wrap_mode;
+
+      g_object_get (tag,
+                    "wrap-mode-set", &val_set,
+                    "wrap-mode", &wrap_mode,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "wrap-mode", gtk_wrap_mode_to_string (wrap_mode));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+
+      g_object_get (tag, "foreground-set", &val_set, NULL);
+      if (val_set)
+        {
+          GdkRGBA *rgba;
+          char *value;
+
+          g_object_get (tag, "foreground", &rgba, NULL);
+          value = g_strdup_printf ("%u,%u,%u",
+                                   (guint) rgba->red * 65535,
+                                   (guint) rgba->green * 65535,
+                                   (guint) rgba->blue * 65535);
+          gdk_rgba_free (rgba);
+          g_variant_builder_add (builder, "{ss}", "fg-color", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+
+      g_object_get (tag, "background-set", &val_set, NULL);
+      if (val_set)
+        {
+          GdkRGBA *rgba;
+          char *value;
+
+          g_object_get (tag, "background-rgba", &rgba, NULL);
+          value = g_strdup_printf ("%u,%u,%u",
+                                   (guint) rgba->red * 65535,
+                                   (guint) rgba->green * 65535,
+                                   (guint) rgba->blue * 65535);
+          gdk_rgba_free (rgba);
+          g_variant_builder_add (builder, "{ss}", "bg-color", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+
+      g_object_get (tag, "family-set", &val_set, NULL);
+
+      if (val_set)
+        {
+          char *value;
+          g_object_get (tag, "family", &value, NULL);
+          g_variant_builder_add (builder, "{ss}", "family-name", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+
+      g_object_get (tag, "language-set", &val_set, NULL);
+
+      if (val_set)
+        {
+          char *value;
+          g_object_get (tag, "language", &value, NULL);
+          g_variant_builder_add (builder, "{ss}", "language", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int weight;
+
+      g_object_get (tag,
+                    "weight-set", &val_set,
+                    "weight", &weight,
+                    NULL);
+
+      if (val_set)
+        {
+          char *value;
+          value = g_strdup_printf ("%d", weight);
+          g_variant_builder_add (builder, "{ss}", "weight", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  /* scale is special as the effective value is the product
+   * of all specified values
+   */
+  temp_tags = tags;
+  while (temp_tags)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      gboolean scale_set;
+
+      g_object_get (tag, "scale-set", &scale_set, NULL);
+      if (scale_set)
+        {
+          double font_scale;
+          g_object_get (tag, "scale", &font_scale, NULL);
+          val_set = TRUE;
+          scale *= font_scale;
+        }
+      temp_tags = temp_tags->next;
+    }
+  if (val_set)
+    {
+      char *value = g_strdup_printf ("%g", scale);
+      g_variant_builder_add (builder, "{ss}", "scale", value);
+      g_free (value);
+    }
+  val_set = FALSE;
+
+ temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int size;
+
+      g_object_get (tag,
+                    "size-set", &val_set,
+                    "size", &size,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", size);
+          g_variant_builder_add (builder, "{ss}", "size", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      gboolean strikethrough;
+
+      g_object_get (tag,
+                    "strikethrough-set", &val_set,
+                    "strikethrough", &strikethrough,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "strikethrough", strikethrough ? "true" : "false");
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      PangoUnderline underline;
+
+      g_object_get (tag,
+                    "underline-set", &val_set,
+                    "underline", &underline,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "underline",
+                               pango_underline_to_string (underline));
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int rise;
+
+      g_object_get (tag,
+                    "rise-set", &val_set,
+                    "rise", &rise,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", rise);
+          g_variant_builder_add (builder, "{ss}", "rise", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      gboolean bg_full_height;
+
+      g_object_get (tag,
+                    "background-full-height-set", &val_set,
+                    "background-full-height", &bg_full_height,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "bg-full-height", bg_full_height ? "true" : "false");
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int pixels;
+
+      g_object_get (tag,
+                    "pixels-inside-wrap-set", &val_set,
+                    "pixels-inside-wrap", &pixels,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", pixels);
+          g_variant_builder_add (builder, "{ss}", "pixels-inside-wrap", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int pixels;
+
+      g_object_get (tag,
+                    "pixels-below-lines-set", &val_set,
+                    "pixels-below-lines", &pixels,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", pixels);
+          g_variant_builder_add (builder, "{ss}", "pixels-below-lines", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int pixels;
+
+      g_object_get (tag,
+                    "pixels-above-lines-set", &val_set,
+                    "pixels-above-lines", &pixels,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", pixels);
+          g_variant_builder_add (builder, "{ss}", "pixels-above-lines", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      gboolean editable;
+
+      g_object_get (tag,
+                    "editable-set", &val_set,
+                    "editable", &editable,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "editable", editable ? "true" : "false");
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      gboolean invisible;
+
+      g_object_get (tag,
+                    "invisible-set", &val_set,
+                    "invisible", &invisible,
+                    NULL);
+      if (val_set)
+        g_variant_builder_add (builder, "{ss}", "invisible", invisible ? "true" : "false");
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+ temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int indent;
+
+      g_object_get (tag,
+                    "indent-set", &val_set,
+                    "indent", &indent,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", indent);
+          g_variant_builder_add (builder, "{ss}", "indent", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int margin;
+
+      g_object_get (tag,
+                    "right-margin-set", &val_set,
+                    "right-margin", &margin,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", margin);
+          g_variant_builder_add (builder, "{ss}", "right-margin", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  temp_tags = tags;
+  while (temp_tags && !val_set)
+    {
+      GtkTextTag *tag = GTK_TEXT_TAG (temp_tags->data);
+      int margin;
+
+      g_object_get (tag,
+                    "left-margin-set", &val_set,
+                    "left-margin", &margin,
+                    NULL);
+      if (val_set)
+        {
+          char *value = g_strdup_printf ("%i", margin);
+          g_variant_builder_add (builder, "{ss}", "left-margin", value);
+          g_free (value);
+        }
+      temp_tags = temp_tags->next;
+    }
+  val_set = FALSE;
+
+  g_slist_free (tags);
+}
diff --git a/gtk/gtktextbufferprivate.h b/gtk/gtktextbufferprivate.h
index b67e22a38e..ef22648ac5 100644
--- a/gtk/gtktextbufferprivate.h
+++ b/gtk/gtktextbufferprivate.h
@@ -34,6 +34,17 @@ const PangoLogAttr* _gtk_text_buffer_get_line_log_attrs (GtkTextBuffer     *buff
 void _gtk_text_buffer_notify_will_remove_tag (GtkTextBuffer *buffer,
                                               GtkTextTag    *tag);
 
+
+const char *gtk_justification_to_string (GtkJustification just);
+const char *gtk_text_direction_to_string (GtkTextDirection direction);
+const char *gtk_wrap_mode_to_string (GtkWrapMode wrap_mode);
+
+void gtk_text_buffer_get_run_attributes (GtkTextBuffer   *buffer,
+                                         GVariantBuilder *builder,
+                                         int              offset,
+                                         int             *start_offset,
+                                         int             *end_offset);
+
 G_END_DECLS
 
 #endif
diff --git a/testsuite/gtk/textbuffer.c b/testsuite/gtk/textbuffer.c
index d1c2997c4f..13e7ee1893 100644
--- a/testsuite/gtk/textbuffer.c
+++ b/testsuite/gtk/textbuffer.c
@@ -22,7 +22,7 @@
 
 #include <gtk/gtk.h>
 #include "gtk/gtktexttypes.h" /* Private header, for UNKNOWN_CHAR */
-#include "gtk/a11y/gtkatspitextbufferprivate.h" /* Private header */
+#include "gtk/gtktextbufferprivate.h" /* Private header */
 
 static void
 gtk_text_iter_spew (const GtkTextIter *iter, const char *desc)
@@ -42,7 +42,7 @@ check_get_set_text (GtkTextBuffer *buffer,
   GtkTextIter start, end, iter;
   char *text;
   int n;
-  
+
   gtk_text_buffer_set_text (buffer, str, -1);
   if (gtk_text_buffer_get_char_count (buffer) != g_utf8_strlen (str, -1))
     g_error ("Wrong number of chars (%d not %d)",
@@ -79,7 +79,7 @@ check_get_set_text (GtkTextBuffer *buffer,
   if (n != strlen (str))
     g_error ("Sum of chars in lines is %d but buffer byte count is %d",
              n, (int) strlen (str));
-  
+
   gtk_text_buffer_set_text (buffer, "", -1);
 
   n = gtk_text_buffer_get_line_count (buffer);
@@ -98,12 +98,12 @@ count_toggles_at_iter (GtkTextIter *iter,
   GSList *tags;
   GSList *tmp;
   int count = 0;
-  
+
   /* get toggle-ons and toggle-offs */
   tags = gtk_text_iter_get_toggled_tags (iter, TRUE);
   tags = g_slist_concat (tags,
                          gtk_text_iter_get_toggled_tags (iter, FALSE));
-  
+
   tmp = tags;
   while (tmp != NULL)
     {
@@ -111,10 +111,10 @@ count_toggles_at_iter (GtkTextIter *iter,
         ++count;
       else if (of_tag == tmp->data)
         ++count;
-      
+
       tmp = tmp->next;
     }
-  
+
   g_slist_free (tags);
 
   return count;
@@ -128,7 +128,7 @@ count_toggles_in_range_by_char (GtkTextBuffer     *buffer,
 {
   GtkTextIter iter;
   int count = 0;
-  
+
   iter = *start;
   do
     {
@@ -141,7 +141,7 @@ count_toggles_in_range_by_char (GtkTextBuffer     *buffer,
         }
     }
   while (gtk_text_iter_compare (&iter, end) <= 0);
-  
+
   return count;
 }
 
@@ -174,12 +174,12 @@ check_specific_tag_in_range (GtkTextBuffer     *buffer,
       g_print ("  (inverted range for checking tags, skipping)\n");
       return;
     }
-  
+
   tag = gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table (buffer),
                                    tag_name);
 
   buffer_count = count_toggles_in_range_by_char (buffer, tag, start, end);
-  
+
   state = FALSE;
   count = 0;
 
@@ -191,7 +191,7 @@ check_specific_tag_in_range (GtkTextBuffer     *buffer,
       do
         {
           int this_offset;
-          
+
           ++count;
 
           this_offset = gtk_text_iter_get_offset (&iter);
@@ -200,13 +200,13 @@ check_specific_tag_in_range (GtkTextBuffer     *buffer,
             g_error ("forward_to_tag_toggle moved in wrong direction");
 
           last_offset = this_offset;
-          
+
           if (gtk_text_iter_starts_tag (&iter, tag))
             {
               if (state)
                 g_error ("Tag %p is already on, and was toggled on?", tag);
               state = TRUE;
-            }          
+            }
           else if (gtk_text_iter_ends_tag (&iter, tag))
             {
               if (!state)
@@ -223,10 +223,10 @@ check_specific_tag_in_range (GtkTextBuffer     *buffer,
   if (count != buffer_count)
     g_error ("Counted %d tags iterating by char, %d iterating forward by tag toggle",
              buffer_count, count);
-  
+
   state = FALSE;
   count = 0;
-  
+
   iter = *end;
   last_offset = gtk_text_iter_get_offset (&iter);
   if (gtk_text_iter_toggles_tag (&iter, tag) ||
@@ -235,14 +235,14 @@ check_specific_tag_in_range (GtkTextBuffer     *buffer,
       do
         {
           int this_offset;
-          
+
           ++count;
 
           this_offset = gtk_text_iter_get_offset (&iter);
-          
+
           if (this_offset >= last_offset)
             g_error ("backward_to_tag_toggle moved in wrong direction");
-          
+
           last_offset = this_offset;
 
           if (gtk_text_iter_starts_tag (&iter, tag))
@@ -297,7 +297,7 @@ run_tests (GtkTextBuffer *buffer)
   GHashTable *tag_states;
   int count;
   int buffer_count;
-  
+
   gtk_text_buffer_get_bounds (buffer, &start, &end);
 
   /* Check that walking the tree via chars and via iterators produces
@@ -449,10 +449,10 @@ run_tests (GtkTextBuffer *buffer)
    */
 
   buffer_count = count_toggles_in_buffer (buffer, NULL);
-  
+
   tag_states = g_hash_table_new (NULL, NULL);
   count = 0;
-  
+
   gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
   if (gtk_text_iter_toggles_tag (&iter, NULL) ||
       gtk_text_iter_forward_to_tag_toggle (&iter, NULL))
@@ -462,48 +462,48 @@ run_tests (GtkTextBuffer *buffer)
           GSList *tags;
           GSList *tmp;
           gboolean found_some = FALSE;
-          
+
           /* get toggled-on tags */
           tags = gtk_text_iter_get_toggled_tags (&iter, TRUE);
 
           if (tags)
             found_some = TRUE;
-          
+
           tmp = tags;
           while (tmp != NULL)
             {
               ++count;
-              
+
               tag = tmp->data;
-              
+
               if (g_hash_table_lookup (tag_states, tag))
                 g_error ("Tag %p is already on, and was toggled on?", tag);
 
               g_hash_table_insert (tag_states, tag, GINT_TO_POINTER (TRUE));
-          
+
               tmp = tmp->next;
             }
 
           g_slist_free (tags);
-      
+
           /* get toggled-off tags */
           tags = gtk_text_iter_get_toggled_tags (&iter, FALSE);
 
           if (tags)
             found_some = TRUE;
-          
+
           tmp = tags;
           while (tmp != NULL)
             {
               ++count;
-              
+
               tag = tmp->data;
 
               if (!g_hash_table_lookup (tag_states, tag))
                 g_error ("Tag %p is already off, and was toggled off?", tag);
 
               g_hash_table_remove (tag_states, tag);
-          
+
               tmp = tmp->next;
             }
 
@@ -515,20 +515,20 @@ run_tests (GtkTextBuffer *buffer)
         }
       while (gtk_text_iter_forward_to_tag_toggle (&iter, NULL));
     }
-  
+
   g_hash_table_destroy (tag_states);
 
   if (count != buffer_count)
     g_error ("Counted %d tags iterating by char, %d iterating by tag toggle\n",
              buffer_count, count);
-  
+
   /* Go backward; here TRUE in the hash means we saw
    * an off toggle last.
    */
-  
+
   tag_states = g_hash_table_new (NULL, NULL);
   count = 0;
-  
+
   gtk_text_buffer_get_end_iter (buffer, &iter);
   if (gtk_text_iter_toggles_tag (&iter, NULL) ||
       gtk_text_iter_backward_to_tag_toggle (&iter, NULL))
@@ -538,48 +538,48 @@ run_tests (GtkTextBuffer *buffer)
           GSList *tags;
           GSList *tmp;
           gboolean found_some = FALSE;
-          
+
           /* get toggled-off tags */
           tags = gtk_text_iter_get_toggled_tags (&iter, FALSE);
 
           if (tags)
             found_some = TRUE;
-          
+
           tmp = tags;
           while (tmp != NULL)
             {
               ++count;
-              
+
               tag = tmp->data;
 
               if (g_hash_table_lookup (tag_states, tag))
                 g_error ("Tag %p has two off-toggles in a row?", tag);
-          
+
               g_hash_table_insert (tag_states, tag, GINT_TO_POINTER (TRUE));
-          
+
               tmp = tmp->next;
             }
 
           g_slist_free (tags);
-      
+
           /* get toggled-on tags */
           tags = gtk_text_iter_get_toggled_tags (&iter, TRUE);
 
           if (tags)
             found_some = TRUE;
-          
+
           tmp = tags;
           while (tmp != NULL)
             {
               ++count;
-              
+
               tag = tmp->data;
 
               if (!g_hash_table_lookup (tag_states, tag))
                 g_error ("Tag %p was toggled on, but saw no off-toggle?", tag);
 
               g_hash_table_remove (tag_states, tag);
-          
+
               tmp = tmp->next;
             }
 
@@ -590,7 +590,7 @@ run_tests (GtkTextBuffer *buffer)
         }
       while (gtk_text_iter_backward_to_tag_toggle (&iter, NULL));
     }
-  
+
   g_hash_table_destroy (tag_states);
 
   if (count != buffer_count)
@@ -770,8 +770,8 @@ fill_buffer (GtkTextBuffer *buffer)
   gtk_text_buffer_get_iter_at_offset (buffer, &iter, 3);
   gtk_text_buffer_get_iter_at_offset (buffer, &iter2, 300);
 
-  gtk_text_buffer_apply_tag (buffer, tag, &iter, &iter2);  
-  
+  gtk_text_buffer_apply_tag (buffer, tag, &iter, &iter2);
+
   tag = gtk_text_buffer_create_tag (buffer, "end_tag", NULL);
   gtk_text_buffer_get_end_iter (buffer, &iter2);
   gtk_text_iter_backward_chars (&iter2, 12);
@@ -779,7 +779,7 @@ fill_buffer (GtkTextBuffer *buffer)
   gtk_text_iter_backward_chars (&iter, 157);
 
   gtk_text_buffer_apply_tag (buffer, tag, &iter, &iter2);
-  
+
   tag = gtk_text_buffer_create_tag (buffer, "center_tag", NULL);
   gtk_text_buffer_get_iter_at_offset (buffer, &iter,
                                       gtk_text_buffer_get_char_count (buffer)/2);
@@ -787,7 +787,7 @@ fill_buffer (GtkTextBuffer *buffer)
   iter2 = iter;
   gtk_text_iter_forward_chars (&iter2, 57);
 
-  gtk_text_buffer_apply_tag (buffer, tag, &iter, &iter2);  
+  gtk_text_buffer_apply_tag (buffer, tag, &iter, &iter2);
 
   g_object_unref (pixbuf);
   g_object_unref (texture);
@@ -820,7 +820,7 @@ test_line_separation (const char* str,
   g_assert_true (gtk_text_iter_ends_line (&iter) || gtk_text_iter_is_end (&iter));
 
   g_assert_cmpint (gtk_text_buffer_get_line_count (buffer), ==, expected_line_count);
-  
+
   on_next_line = gtk_text_iter_forward_line (&iter);
 
   g_assert_cmpint (expect_next_line, ==, on_next_line);
@@ -828,9 +828,9 @@ test_line_separation (const char* str,
   on_end_iter = gtk_text_iter_is_end (&iter);
 
   g_assert_true (on_end_iter == expect_end_iter);
-  
+
   new_pos = gtk_text_iter_get_offset (&iter);
-    
+
   if (on_next_line)
     g_assert_cmpint (expected_next_line_start, ==, new_pos);
 
@@ -842,19 +842,19 @@ test_line_separation (const char* str,
       g_assert_false (gtk_text_iter_ends_line (&iter));
 
       on_next_line = gtk_text_iter_forward_line (&iter);
-        
+
       g_assert_cmpint (expect_next_line, ==, on_next_line);
-        
+
       new_pos = gtk_text_iter_get_offset (&iter);
-        
+
       if (on_next_line)
         g_assert_cmpint (expected_next_line_start, ==, new_pos);
-        
+
       ++expected_line_break;
     }
 
   /* FIXME tests for backward line */
-  
+
   g_object_unref (buffer);
 }
 
@@ -899,7 +899,7 @@ test_line_separator (void)
    * Unicode 3.0; update this if that changes.
    */
 #define PARAGRAPH_SEPARATOR 0x2029
-  
+
   test_line_separation ("line", FALSE, TRUE, 1, 4, 4);
   test_line_separation ("line\r\n", FALSE, TRUE, 2, 4, 6);
   test_line_separation ("line\r", FALSE, TRUE, 2, 4, 5);
@@ -907,9 +907,9 @@ test_line_separator (void)
   test_line_separation ("line\rqw", TRUE, FALSE, 2, 4, 5);
   test_line_separation ("line\nqw", TRUE, FALSE, 2, 4, 5);
   test_line_separation ("line\r\nqw", TRUE, FALSE, 2, 4, 6);
-  
+
   g_unichar_to_utf8 (PARAGRAPH_SEPARATOR, buf);
-  
+
   str = g_strdup_printf ("line%s", buf);
   test_line_separation (str, FALSE, TRUE, 2, 4, 5);
   g_free (str);
@@ -988,13 +988,13 @@ test_logical_motion (void)
   int i;
   GtkTextBuffer *buffer;
   GtkTextIter iter;
-  
+
   buffer = gtk_text_buffer_new (NULL);
-  
+
 #define LEADING_JAMO 0x1111
 #define VOWEL_JAMO 0x1167
 #define TRAILING_JAMO 0x11B9
-  
+
   g_unichar_to_utf8 (LEADING_JAMO, buf1);
   g_unichar_to_utf8 (VOWEL_JAMO, buf2);
   g_unichar_to_utf8 (TRAILING_JAMO, buf3);
@@ -1003,7 +1003,7 @@ test_logical_motion (void)
   str = g_strconcat ("abc", buf1, buf2, buf3, "def\r\nxyz", NULL);
   gtk_text_buffer_set_text (buffer, str, -1);
   g_free (str);
-  
+
   /* Check cursor positions */
   memset (expected, 0, sizeof (expected));
   expected[0] = 0;    /* before 'a' */
@@ -1019,7 +1019,7 @@ test_logical_motion (void)
   expected[10] = 13;  /* before 'z' */
   expected[11] = 14;  /* after 'z' (only matters going backward) */
   expected_steps = 11;
-  
+
   gtk_text_buffer_get_start_iter (buffer, &iter);
   i = 0;
   do
@@ -1027,14 +1027,14 @@ test_logical_motion (void)
       int pos;
 
       pos = gtk_text_iter_get_offset (&iter);
-      
+
       if (pos != expected[i])
         {
           g_error ("Cursor position %d, expected %d",
                    pos, expected[i]);
         }
 
-      ++i;      
+      ++i;
     }
   while (gtk_text_iter_forward_cursor_position (&iter));
 
@@ -1043,7 +1043,7 @@ test_logical_motion (void)
 
   if (!gtk_text_iter_is_cursor_position (&iter))
     g_error ("Should be a cursor position before the end iterator");
-  
+
   if (i != expected_steps)
     g_error ("Expected %d steps, there were actually %d\n", expected_steps, i);
 
@@ -1053,7 +1053,7 @@ test_logical_motion (void)
       int pos;
 
       pos = gtk_text_iter_get_offset (&iter);
-      
+
       if (pos != expected[i])
         {
           g_error ("Moving backward, cursor position %d, expected %d",
@@ -1061,7 +1061,7 @@ test_logical_motion (void)
         }
 
       /* g_print ("%d = %d\n", pos, expected[i]); */
-      
+
       --i;
     }
   while (gtk_text_iter_backward_cursor_position (&iter));
@@ -1074,7 +1074,7 @@ test_logical_motion (void)
 
 
   /* Check sentence boundaries */
-  
+
   gtk_text_buffer_set_text (buffer, "Hi.\nHi. \nHi! Hi. Hi? Hi.", -1);
 
   memset (expected, 0, sizeof (expected));
@@ -1085,9 +1085,9 @@ test_logical_motion (void)
   expected[3] = 12;   /* After ! */
   expected[4] = 16;   /* After third . */
   expected[5] = 20;   /* After ? */
-  
+
   expected_steps = 6;
-  
+
   gtk_text_buffer_get_start_iter (buffer, &iter);
   i = 0;
   do
@@ -1106,7 +1106,7 @@ test_logical_motion (void)
           !gtk_text_iter_is_end (&iter) &&
           !gtk_text_iter_ends_sentence (&iter))
         g_error ("Iterator at %d should end a sentence", pos);
-      
+
       ++i;
     }
   while (gtk_text_iter_forward_sentence_end (&iter));
@@ -1116,7 +1116,7 @@ test_logical_motion (void)
 
   if (!gtk_text_iter_is_end (&iter))
     g_error ("Expected to stop at the end iterator");
-  
+
   gtk_text_buffer_set_text (buffer, "Hi.\nHi. \nHi! Hi. Hi? Hi.", -1);
 
   memset (expected, 0, sizeof (expected));
@@ -1128,9 +1128,9 @@ test_logical_motion (void)
   expected[4] = 9;
   expected[5] = 4;
   expected[6] = 0;
-  
+
   expected_steps = 7;
-  
+
   gtk_text_buffer_get_end_iter (buffer, &iter);
   i = 0;
   do
@@ -1149,7 +1149,7 @@ test_logical_motion (void)
           !gtk_text_iter_is_end (&iter) &&
           !gtk_text_iter_starts_sentence (&iter))
         g_error ("Iterator at %d should start a sentence", pos);
-      
+
       ++i;
     }
   while (gtk_text_iter_backward_sentence_start (&iter));
@@ -1159,7 +1159,7 @@ test_logical_motion (void)
 
   if (gtk_text_iter_get_offset (&iter) != 0)
     g_error ("Expected to stop at the start iterator");
-  
+
   g_object_unref (buffer);
 }
 
@@ -1271,7 +1271,7 @@ test_empty_buffer (void)
   n = gtk_text_iter_get_bytes_in_line (&start);
   if (n != 0)
     g_error ("%d bytes in first line, expected 0", n);
-  
+
   /* Run gruesome alien test suite on buffer */
   run_tests (buffer);
 
@@ -1301,7 +1301,7 @@ test_fill_empty (void)
   GtkTextBuffer *buffer;
   int n;
   GtkTextIter start, end;
-  
+
   buffer = gtk_text_buffer_new (NULL);
 
   /* Put stuff in the buffer */
@@ -1334,7 +1334,7 @@ test_tag (void)
 {
   GtkTextBuffer *buffer;
   GtkTextIter start, end;
-  
+
   buffer = gtk_text_buffer_new (NULL);
 
   fill_buffer (buffer);
@@ -1343,9 +1343,9 @@ test_tag (void)
   gtk_text_buffer_get_iter_at_offset (buffer, &start, 1);
   gtk_text_buffer_get_iter_at_offset (buffer, &end, 3);
   gtk_text_buffer_apply_tag_by_name (buffer, "fg_blue", &start, &end);
-  
+
   run_tests (buffer);
-  
+
   g_object_unref (buffer);
 }
 


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