diff options
author | Eli Zaretskii <eliz@gnu.org> | 2018-12-29 16:35:09 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2018-12-29 16:35:09 +0200 |
commit | 48776b70115edf3775df19d80f734048dadff198 (patch) | |
tree | 10a7e72a45bbbdf8dbfed4afce59fc9a5b975110 /src/ftfont.c | |
parent | 1a80b5d9b8cfa0e523b596db5d1e7e6074dbee46 (diff) | |
download | emacs-48776b70115edf3775df19d80f734048dadff198.tar.gz emacs-48776b70115edf3775df19d80f734048dadff198.tar.bz2 emacs-48776b70115edf3775df19d80f734048dadff198.zip |
Provide text directionality and language to HarfBuzz shaper
* lisp/language/tv-util.el (tai-viet-composition-function):
* lisp/language/ethio-util.el (ethio-composition-function):
* lisp/language/japanese.el (compose-gstring-for-variation-glyph):
* lisp/language/thai-util.el (thai-composition-function):
* lisp/language/misc-lang.el (arabic-shape-gstring):
* lisp/language/lao-util.el (lao-composition-function):
* lisp/language/hebrew.el (hebrew-shape-gstring):
* lisp/composite.el (compose-gstring-for-graphic)
(compose-gstring-for-dotted-circle, auto-compose-chars)
(compose-gstring-for-terminal): Accept 2nd argument DIRECTION; all
callers changed.
* src/composite.c (composition_reseat_it): Call
auto-composition-function with one more argument DIRECTION.
(syms_of_composite) <auto-composition-function>: Update the doc
string.
* src/ftfont.c (ftfont_shape_by_hb): Compute language and
direction, and set buffer properties accordingly.
* src/composite.c (autocmp_chars):
* src/w32uniscribe.c (uniscribe_shape):
* src/xftfont.c (xftfont_shape):
* src/ftfont.c (ftfont_shape, ftfont_shape_by_hb):
* src/font.c (Ffont_shape_gstring): Accept an additional argument
DIRECTION.
* src/macfont.m (lgstring_direction): New enum.
(mac_font_shape_1, mac_screen_font_shape, mac_font_shape):
Accept an additional argument specifying text direction. All
callers changed.
* src/font.c (syms_of_font): New symbols QL2R and QR2L.
* src/font.h (shape): Accept new argument DIRECTION. All
implementations changed. (Bug#33729)
(ftfont_shape): Update prototype.
Diffstat (limited to 'src/ftfont.c')
-rw-r--r-- | src/ftfont.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 74d72f94abd..5a8adfdb24c 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -2797,7 +2797,7 @@ get_hb_unicode_funcs (void) static Lisp_Object ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face ft_face, hb_font_t *hb_font, - FT_Matrix *matrix) + FT_Matrix *matrix, Lisp_Object direction) { ptrdiff_t glyph_len = 0, text_len = LGSTRING_GLYPH_LEN (lgstring); ptrdiff_t i; @@ -2836,15 +2836,38 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face ft_face, hb_font_t *hb_font, hb_buffer_set_content_type (hb_buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); hb_buffer_set_cluster_level (hb_buffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); - /* FIXME: guess_segment_properties is BAD BAD BAD. - * we need to get these properties with the LGSTRING. */ -#if 1 + /* Set the default properties for when they cannot be determined + below. */ hb_buffer_guess_segment_properties (hb_buffer); -#else - hb_buffer_set_direction (hb_buffer, XXX); + hb_direction_t dir = HB_DIRECTION_INVALID; + if (EQ (direction, QL2R)) + dir = HB_DIRECTION_LTR; + else if (EQ (direction, QR2L)) + dir = HB_DIRECTION_RTL; + /* If the caller didn't provide a meaningful DIRECTION, let HarfBuzz + guess it. */ + if (dir != HB_DIRECTION_INVALID) + hb_buffer_set_direction (hb_buffer, dir); + /* Leave the script determination to HarfBuzz, until Emacs has a + better idea of the script of LGSTRING. FIXME. */ +#if 0 hb_buffer_set_script (hb_buffer, XXX); - hb_buffer_set_language (hb_buffer, XXX); #endif + /* FIXME: This can only handle the single global language, which + normally comes from the locale. In addition, if + current-iso639-language is a list, we arbitrarily use the first + one. We should instead have a notion of the language of the text + being shaped. */ + Lisp_Object lang = Vcurrent_iso639_language; + if (CONSP (Vcurrent_iso639_language)) + lang = XCAR (Vcurrent_iso639_language); + if (SYMBOLP (lang)) + { + Lisp_Object lang_str = SYMBOL_NAME (lang); + hb_buffer_set_language (hb_buffer, + hb_language_from_string (SSDATA (lang_str), + SBYTES (lang_str))); + } if (!hb_shape_full (hb_font, hb_buffer, NULL, 0, NULL)) return Qnil; @@ -2919,7 +2942,7 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face ft_face, hb_font_t *hb_font, #if (defined HAVE_M17N_FLT && defined HAVE_LIBOTF) || defined HAVE_HARFBUZZ Lisp_Object -ftfont_shape (Lisp_Object lgstring) +ftfont_shape (Lisp_Object lgstring, Lisp_Object direction) { struct font *font = CHECK_FONT_GET_OBJECT (LGSTRING_FONT (lgstring)); struct ftfont_info *ftfont_info = (struct ftfont_info *) font; @@ -2929,7 +2952,7 @@ ftfont_shape (Lisp_Object lgstring) hb_font_t *hb_font = ftfont_get_hb_font (ftfont_info); return ftfont_shape_by_hb (lgstring, ftfont_info->ft_size->face, - hb_font, &ftfont_info->matrix); + hb_font, &ftfont_info->matrix, direction); } else #endif /* HAVE_HARFBUZZ */ |