From 4d48fae4f247c789612f6a888aba6abf7906f012 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 20 Apr 2022 11:35:19 -0600 Subject: [PATCH] Enforce Regional_Indicators native direction to LTR And undo the morx direction reversal change introduced in https://github.com/harfbuzz/harfbuzz/pull/3315 23159084b43c1ce429d9e98035bf845919fd8a89 This fixes original bug https://github.com/harfbuzz/harfbuzz/issues/3314 And the reversion in morx code fixes regressions: https://github.com/harfbuzz/harfbuzz/issues/3528 https://github.com/harfbuzz/harfbuzz/issues/3535 Supersedes: https://github.com/harfbuzz/harfbuzz/pull/3529 --- src/hb-aat-layout-morx-table.hh | 4 ++-- src/hb-ot-shape.cc | 19 ++++++++++++++----- test/shape/data/in-house/tests/macos.tests | 8 +++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 2f9951092..b77c1f4d4 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -1038,12 +1038,12 @@ struct Chain goto skip; if (reverse) - _hb_ot_layout_reverse_graphemes (c->buffer); + c->buffer->reverse (); subtable->apply (c); if (reverse) - _hb_ot_layout_reverse_graphemes (c->buffer); + c->buffer->reverse (); (void) c->buffer->message (c->font, "end chainsubtable %d", c->lookup_index); diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 298cf4778..405cd5aab 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -598,24 +598,33 @@ hb_ensure_native_direction (hb_buffer_t *buffer) * direction, so that features like ligatures will work as intended. * * https://github.com/harfbuzz/harfbuzz/issues/501 + * + * Similar thing about Regional_Indicators; They are bidi=L, but Script=Common. + * If they are presentin a run of natively-RTL text, they get assigned a script + * with natively RTL direction, which would result in wrong shaping if we + * assign such native RTL direction to them then. Detect that as well. + * + * https://github.com/harfbuzz/harfbuzz/issues/3314 */ if (unlikely (horiz_dir == HB_DIRECTION_RTL && direction == HB_DIRECTION_LTR)) { - bool found_number = false, found_letter = false; + bool found_number = false, found_letter = false, found_ri = false; const auto* info = buffer->info; const auto count = buffer->len; for (unsigned i = 0; i < count; i++) { auto gc = _hb_glyph_info_get_general_category (&info[i]); if (gc == HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) - found_number = true; + found_number = true; else if (HB_UNICODE_GENERAL_CATEGORY_IS_LETTER (gc)) { - found_letter = true; - break; + found_letter = true; + break; } + else if (hb_in_range (info[i].codepoint, 0x1F1E6u, 0x1F1FFu)) + found_ri = true; } - if (found_number && !found_letter) + if ((found_number || found_ri) && !found_letter) horiz_dir = HB_DIRECTION_LTR; } diff --git a/test/shape/data/in-house/tests/macos.tests b/test/shape/data/in-house/tests/macos.tests index cbec63435..14c317ccf 100644 --- a/test/shape/data/in-house/tests/macos.tests +++ b/test/shape/data/in-house/tests/macos.tests @@ -1,5 +1,11 @@ # https://github.com/harfbuzz/harfbuzz/issues/3314 -/System/Library/Fonts/Apple\ Color\ Emoji.ttc;;U+05D0,U+1F1FA,U+1F1F8,U+1F1EE,U+1F1F1;[u1F1EE_u1F1F1=3+800|u1F1FA_u1F1F8=1+800|.notdef=0+800] +/System/Library/Fonts/Apple\ Color\ Emoji.ttc;--script=hebrew --direction ltr;U+1F1FA,U+1F1F8,U+1F1EE,U+1F1F1;[u1F1FA_u1F1F8=0+800|u1F1EE_u1F1F1=2+800] + +# https://github.com/harfbuzz/harfbuzz/issues/3528 +/System/Library/Fonts/Supplemental/Bangla MN.ttc;;U+09AC,U+09BF;[bn_ikaar=0+474|bn_ba=0+998] + +# https://github.com/harfbuzz/harfbuzz/issues/3535 +/System/Library/Fonts/LucidaGrande.ttc;;U+20DD,U+1F174,U+1F175;[circlecmb=0+0|.notdef=1+1536|.notdef=2+1536] # https;//github.com/harfbuzz/harfbuzz/issues/3008 /System/Library/Fonts/ヒラギノ丸ゴ\ ProN\ W4.ttc;--features=palt;U+FF11;[gid781=0@-78,0+842]