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
This commit is contained in:
Federico Mena Quintero 2022-04-26 13:43:19 -05:00
parent 3af4d53945
commit 737854aa0d
2 changed files with 24 additions and 2 deletions

View 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:

View 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;