From 737854aa0d203de7bdab2b282a51691c9056dadc Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Tue, 26 Apr 2022 13:43:19 -0500 Subject: Don't cast GtkWrapMode to the incompatible enum PangoWrapMode The enum values are not compatible, and moreover, there is an extra GTK_WRAP_NONE that PangoWrapMode doesn't have - thus, pango_wrap_mode_to_string() will assert. As far as I can tell, Orca does not read the wrap-mode key in the dictionary for text attributes, anyway. Fixes: #4869 --- gtk/a11y/gtkatspipango.c | 1 + gtk/a11y/gtkatspitextbuffer.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'gtk/a11y') diff --git a/gtk/a11y/gtkatspipango.c b/gtk/a11y/gtkatspipango.c index 4db6a1a64b..b353027cc4 100644 --- a/gtk/a11y/gtkatspipango.c +++ b/gtk/a11y/gtkatspipango.c @@ -113,6 +113,7 @@ pango_underline_to_string (PangoUnderline value) 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: diff --git a/gtk/a11y/gtkatspitextbuffer.c b/gtk/a11y/gtkatspitextbuffer.c index 61e240fb0d..40fd05fa1f 100644 --- a/gtk/a11y/gtkatspitextbuffer.c +++ b/gtk/a11y/gtkatspitextbuffer.c @@ -55,6 +55,27 @@ gtk_text_direction_to_string (GtkTextDirection direction) } } +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 (); + } +} + void gtk_text_view_add_default_attributes (GtkTextView *view, GVariantBuilder *builder) @@ -75,7 +96,7 @@ gtk_text_view_add_default_attributes (GtkTextView *view, g_variant_builder_add (builder, "{ss}", "direction", gtk_text_direction_to_string (text_attrs->direction)); g_variant_builder_add (builder, "{ss}", "wrap-mode", - pango_wrap_mode_to_string ((PangoWrapMode)text_attrs->wrap_mode)); + gtk_wrap_mode_to_string (text_attrs->wrap_mode)); g_variant_builder_add (builder, "{ss}", "editable", text_attrs->editable ? "true" : "false"); g_variant_builder_add (builder, "{ss}", "invisible", @@ -256,7 +277,7 @@ gtk_text_buffer_get_run_attributes (GtkTextBuffer *buffer, "wrap-mode", &wrap_mode, NULL); if (val_set) - g_variant_builder_add (builder, "{ss}", "wrap-mode", pango_wrap_mode_to_string ((PangoWrapMode)wrap_mode)); + g_variant_builder_add (builder, "{ss}", "wrap-mode", gtk_wrap_mode_to_string (wrap_mode)); temp_tags = temp_tags->next; } val_set = FALSE; -- cgit v1.2.1