Don't cast GtkWrapMode to the incompatible enum PangoWrapMode
authorFederico Mena Quintero <federico@gnome.org>
Tue, 26 Apr 2022 18:43:19 +0000 (13:43 -0500)
committerFederico Mena Quintero <federico@gnome.org>
Tue, 26 Apr 2022 18:43:19 +0000 (13:43 -0500)
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
gtk/a11y/gtkatspitextbuffer.c

index 4db6a1a64bd776c9f5aa1bf7c32a3310487d129f..b353027cc422e2070b50b73856984df5f0b09a88 100644 (file)
@@ -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:
index 61e240fb0db4cd1009ebc75030e11ed9a54c98bf..40fd05fa1f74652257781b29ddf34814d31ff834 100644 (file)
@@ -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;