Merge branch 'matthiasc/for-master' into 'master'

Revert "imwayland: Tweak preedit text"

Closes #4123

See merge request GNOME/gtk!3877
This commit is contained in:
Matthias Clasen 2021-08-24 17:19:42 +00:00
commit da5eb92f47
2 changed files with 34 additions and 99 deletions

View File

@ -571,38 +571,6 @@ gtk_im_context_wayland_set_client_widget (GtkIMContext *context,
}
}
/* We want a unified experience between GtkIMContextSimple and IBus / Wayland
* when it comes to Compose sequences. IBus initial implementation of preedit
* for Compose sequences shows U+2384, which has been described as 'distracting'.
* This function tries to detect this case, and tweaks the text to match what
* GtkIMContextSimple produces.
*/
static char *
tweak_preedit (const char *text)
{
GString *s;
guint len;
s = g_string_new ("");
len = g_utf8_strlen (text, -1);
for (const char *p = text; *p; p = g_utf8_next_char (p))
{
gunichar ch = g_utf8_get_char (p);
if (ch == 0x2384)
{
if (len == 1 || p > text)
g_string_append (s, "·");
}
else
g_string_append_unichar (s, ch);
}
return g_string_free (s, FALSE);
}
static void
gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
char **str,
@ -610,7 +578,7 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
int *cursor_pos)
{
GtkIMContextWayland *context_wayland = GTK_IM_CONTEXT_WAYLAND (context);
char *preedit_str;
const char *preedit_str;
if (attrs)
*attrs = NULL;
@ -629,12 +597,14 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
}
preedit_str =
tweak_preedit (context_wayland->current_preedit.text ? context_wayland->current_preedit.text : "");
context_wayland->current_preedit.text ? context_wayland->current_preedit.text : "";
if (cursor_pos)
*cursor_pos = g_utf8_strlen (preedit_str,
context_wayland->current_preedit.cursor_begin);
if (str)
*str = g_strdup (preedit_str);
if (attrs)
{
PangoAttribute *attr;
@ -664,10 +634,6 @@ gtk_im_context_wayland_get_preedit_string (GtkIMContext *context,
pango_attr_list_insert (*attrs, cursor);
}
}
if (str)
*str = preedit_str;
else
g_free (preedit_str);
}
static gboolean

View File

@ -5,6 +5,13 @@ print_attribute (PangoAttribute *attr, GString *string)
{
GEnumClass *class;
GEnumValue *value;
PangoAttrString *str;
PangoAttrLanguage *lang;
PangoAttrInt *integer;
PangoAttrFloat *flt;
PangoAttrFontDesc *font;
PangoAttrColor *color;
PangoAttrShape *shape;
g_string_append_printf (string, "[%d,%d]", attr->start_index, attr->end_index);
@ -13,73 +20,35 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append_printf (string, "%s=", value->value_nick);
g_type_class_unref (class);
switch (attr->klass->type)
if ((str = pango_attribute_as_string (attr)) != NULL)
g_string_append (string, str->value);
else if ((lang = pango_attribute_as_language (attr)) != NULL)
g_string_append (string, pango_language_to_string (lang->value));
else if ((integer = pango_attribute_as_int (attr)) != NULL)
g_string_append_printf (string, "%d", integer->value);
else if ((flt = pango_attribute_as_float (attr)) != NULL)
{
case PANGO_ATTR_LANGUAGE:
g_string_append (string, pango_language_to_string (((PangoAttrLanguage *)attr)->value));
break;
case PANGO_ATTR_FAMILY:
case PANGO_ATTR_FONT_FEATURES:
g_string_append (string, ((PangoAttrString *)attr)->value);
break;
case PANGO_ATTR_STYLE:
case PANGO_ATTR_WEIGHT:
case PANGO_ATTR_VARIANT:
case PANGO_ATTR_STRETCH:
case PANGO_ATTR_SIZE:
case PANGO_ATTR_ABSOLUTE_SIZE:
case PANGO_ATTR_UNDERLINE:
case PANGO_ATTR_OVERLINE:
case PANGO_ATTR_STRIKETHROUGH:
case PANGO_ATTR_RISE:
case PANGO_ATTR_FALLBACK:
case PANGO_ATTR_LETTER_SPACING:
case PANGO_ATTR_GRAVITY:
case PANGO_ATTR_GRAVITY_HINT:
case PANGO_ATTR_FOREGROUND_ALPHA:
case PANGO_ATTR_BACKGROUND_ALPHA:
case PANGO_ATTR_ALLOW_BREAKS:
case PANGO_ATTR_INSERT_HYPHENS:
case PANGO_ATTR_SHOW:
case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
case PANGO_ATTR_TEXT_TRANSFORM:
g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value);
break;
case PANGO_ATTR_FONT_DESC:
{
char *text = pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc);
g_string_append (string, text);
g_free (text);
}
break;
case PANGO_ATTR_FOREGROUND:
case PANGO_ATTR_BACKGROUND:
case PANGO_ATTR_UNDERLINE_COLOR:
case PANGO_ATTR_OVERLINE_COLOR:
case PANGO_ATTR_STRIKETHROUGH_COLOR:
{
char *text = pango_color_to_string (&((PangoAttrColor *)attr)->color);
g_string_append (string, text);
g_free (text);
}
break;
case PANGO_ATTR_SHAPE:
g_string_append_printf (string, "shape");
break;
case PANGO_ATTR_SCALE:
case PANGO_ATTR_LINE_HEIGHT:
{
char val[20];
g_ascii_formatd (val, 20, "%f", ((PangoAttrFloat *)attr)->value);
g_ascii_formatd (val, 20, "%f", flt->value);
g_string_append (string, val);
}
break;
case PANGO_ATTR_INVALID:
default:
g_assert_not_reached ();
break;
else if ((font = pango_attribute_as_font_desc (attr)) != NULL)
{
char *text = pango_font_description_to_string (font->desc);
g_string_append (string, text);
g_free (text);
}
else if ((color = pango_attribute_as_color (attr)) != NULL)
{
char *text = pango_color_to_string (&color->color);
g_string_append (string, text);
g_free (text);
}
else if ((shape = pango_attribute_as_shape (attr)) != NULL)
g_string_append_printf (string, "shape");
else
g_assert_not_reached ();
}
void