Merge branch 'gtk-compose-test-case-single-char' into 'main'

composetable: Accept short compose sequences

See merge request GNOME/gtk!6358
This commit is contained in:
Matthias Clasen 2023-08-29 19:46:00 +00:00
commit 1186eff1b7
4 changed files with 46 additions and 11 deletions

View File

@ -231,7 +231,7 @@ parse_compose_sequence (const char *seq,
char *start = words[i];
char *end = strchr (words[i], '>');
char *match;
gunichar codepoint;
guint keyval;
if (words[i][0] == '\0')
continue;
@ -248,18 +248,24 @@ parse_compose_sequence (const char *seq,
if (is_codepoint (match))
{
codepoint = (gunichar) g_ascii_strtoll (match + 1, NULL, 16);
sequence[n] = codepoint;
keyval = gdk_unicode_to_keyval ((gunichar) g_ascii_strtoll (match + 1, NULL, 16));
if (keyval > 0xffff)
g_warning ("Can't handle >16bit keyvals");
sequence[n] = (guint16) keyval;
sequence[n + 1] = 0;
}
else
{
codepoint = (gunichar) gdk_keyval_from_name (match);
sequence[n] = codepoint;
keyval = gdk_keyval_from_name (match);
if (keyval > 0xffff)
g_warning ("Can't handle >16bit keyvals");
sequence[n] = (guint16) keyval;
sequence[n + 1] = 0;
}
if (codepoint == GDK_KEY_VoidSymbol)
if (keyval == GDK_KEY_VoidSymbol)
g_warning ("Could not get code point of keysym %s", match);
g_free (match);
n++;
@ -1331,11 +1337,28 @@ gtk_compose_table_check (const GtkComposeTable *table,
if (!seq_index)
return FALSE;
if (n_compose == 1)
return TRUE;
match = FALSE;
if (n_compose == 1)
{
if (seq_index[2] - seq_index[1] > 0)
{
seq = table->data + seq_index[1];
value = seq[0];
if ((value & (1 << 15)) != 0)
g_string_append (output, &table->char_data[value & ~(1 << 15)]);
else
g_string_append_unichar (output, value);
if (compose_match)
*compose_match = TRUE;
}
return TRUE;
}
for (i = n_compose - 1; i < table->max_seq_len; i++)
{
len = i + 1;

View File

@ -30,12 +30,13 @@ typedef struct _GtkComposeTableCompact GtkComposeTableCompact;
* The first part of the data contains rows of length max_seq_len + 1,
* where the first element is the item of the sequence, and the
* following elements are offsets to the data for sequences that
* start with the first item of length 2, ..., max_seq_len.
* start with the first item of length 1, ..., max_seq_len.
*
* The second part of the data contains the rest of the sequence
* data. It does not have a fixed stride. For each sequence, we
* put seq[2], ..., seq[len - 1], followed by the encoded value
* for this sequence.
* for this sequence. In particular for a sequence of length 1,
* the offset points directly to the value.
*
* The values are encoded as follows:
*

View File

@ -2,3 +2,4 @@
<Multi_key> <s> <e> <q> <u> : "?"
<Multi_key> <z> <w> <i> <n> <e> <s> : "🥂"
<Multi_key> <l> <o> <n> <g> : "this is a long replacement string"
<q> : "qq"

View File

@ -242,6 +242,16 @@ compose_table_match (void)
g_assert_true (match);
g_assert_cmpstr (output->str, ==, "this is a long replacement string");
g_string_set_size (output, 0);
buffer[0] = GDK_KEY_q;
buffer[1] = 0;
ret = gtk_compose_table_check (table, buffer, 1, &finish, &match, output);
g_assert_true (ret);
g_assert_false (finish);
g_assert_true (match);
g_assert_cmpstr (output->str, ==, "qq");
g_string_free (output, TRUE);
g_free (file);
}