diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2022-08-04 23:34:41 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2022-08-04 23:34:41 +0100 |
commit | d030c92d6347444b1cb0bfb59ad950436d79dd66 (patch) | |
tree | c291ae1a418ba340ebff68ccc39565ddea6269db /gtk | |
parent | a07ee709d257ba793d827eaa30302dd8cb847955 (diff) | |
download | gtk+-d030c92d6347444b1cb0bfb59ad950436d79dd66.tar.gz |
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.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/a11y/gtkatspipango.c | 125 | ||||
-rw-r--r-- | gtk/a11y/gtkatspipangoprivate.h | 6 | ||||
-rw-r--r-- | gtk/a11y/gtkatspitext.c | 8 | ||||
-rw-r--r-- | gtk/a11y/gtkatspitextbuffer.c | 555 | ||||
-rw-r--r-- | gtk/a11y/gtkatspitextbufferprivate.h | 5 | ||||
-rw-r--r-- | gtk/gtkpango.c | 124 | ||||
-rw-r--r-- | gtk/gtkpango.h | 7 | ||||
-rw-r--r-- | gtk/gtktextbuffer.c | 570 | ||||
-rw-r--r-- | gtk/gtktextbufferprivate.h | 11 |
9 files changed, 720 insertions, 691 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 |