diff options
author | Robert Pluim <rpluim@gmail.com> | 2021-09-26 17:26:22 +0200 |
---|---|---|
committer | Robert Pluim <rpluim@gmail.com> | 2021-09-27 10:31:32 +0200 |
commit | a2a62f71051f1295492780f320e9b7bc02b6e6f4 (patch) | |
tree | 79212dd1c9b038c7779dc7edbd2760fb8ad2514c /src/font.c | |
parent | da4e58458f6659d075143083a9f04be3a42853da (diff) | |
download | emacs-a2a62f71051f1295492780f320e9b7bc02b6e6f4.tar.gz |
Enhance font_range to check for emoji composition triggers
If the codepoint that triggered composition is from the emoji script,
use the emoji font to check the string being composed, rather than the
font of the first character of the string. This makes e.g.
"emoji codepoint with Emoji_Presentation = No followed by VS-16 (FE0F)"
display the emoji version of the glyph for that codepoint.
* admin/unidata/blocks.awk: Add VS-1 through VS-16 to the emoji
script.
* src/composite.c (autocmp_chars): Accept additional argument CH for
the codepoint that triggered composition, pass it to font_range.
(composition_reseat_it, find_automatic_composition): Pass codepoint
that triggered composition to autocmp_chars.
* src/font.c (font_range): Accept additional argument CH for the
triggering codepoint. If the codepoint is from the 'emoji' script,
use Vscript_representative_chars to find the font to use for the
composition attempt.
(syms_of_font): Add Qemoji symbol.
* src/font.h: Update font_range prototype for argument CH.
* etc/NEWS: Announce change.
Diffstat (limited to 'src/font.c')
-rw-r--r-- | src/font.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/font.c b/src/font.c index e043ef8d01b..82a1dffc011 100644 --- a/src/font.c +++ b/src/font.c @@ -3866,6 +3866,9 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, If STRING is not nil, it is the string to check instead of the current buffer. In that case, FACE must be not NULL. + CH is the character that actually caused the composition + process to start, it may be different from the character at POS. + The return value is the font-object for the character at POS. *LIMIT is set to the position where that font can't be used. @@ -3873,15 +3876,16 @@ font_at (int c, ptrdiff_t pos, struct face *face, struct window *w, Lisp_Object font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit, - struct window *w, struct face *face, Lisp_Object string) + struct window *w, struct face *face, Lisp_Object string, + int ch) { ptrdiff_t ignore; int c; Lisp_Object font_object = Qnil; + struct frame *f = XFRAME (w->frame); if (!face) { - struct frame *f = XFRAME (w->frame); int face_id; if (NILP (string)) @@ -3900,6 +3904,24 @@ font_range (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t *limit, face = FACE_FROM_ID (f, face_id); } + /* If the composition was triggered by an emoji, use a character + from 'script-representative-chars', rather than the first + character in the string, to determine the font to use. */ + if (EQ (CHAR_TABLE_REF (Vchar_script_table, ch), + Qemoji)) + { + Lisp_Object val = assq_no_quit (Qemoji, Vscript_representative_chars); + if (CONSP (val)) + { + val = XCDR (val); + if (CONSP (val)) + val = XCAR (val); + else if (VECTORP (val)) + val = AREF (val, 0); + font_object = font_for_char (face, XFIXNAT (val), pos - 1, string); + } + } + while (pos < *limit) { c = (NILP (string) @@ -5423,6 +5445,7 @@ syms_of_font (void) DEFSYM (Qiso8859_1, "iso8859-1"); DEFSYM (Qiso10646_1, "iso10646-1"); DEFSYM (Qunicode_bmp, "unicode-bmp"); + DEFSYM (Qemoji, "emoji"); /* Symbols representing keys of font extra info. */ DEFSYM (QCotf, ":otf"); |