From f673cfbd64d0c9d97123500a7b851b9cfc09deb3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 7 May 2018 13:58:32 -0700 Subject: [PATCH] Support scripts that are written both LTR and RTL Right now only Old Italic is marked as such. Fixes https://github.com/harfbuzz/harfbuzz/issues/1000 --- src/hb-buffer.cc | 4 ++++ src/hb-common.cc | 6 ++++++ src/hb-ot-shape.cc | 7 +++++-- test/api/test-common.c | 1 + test/shaping/data/in-house/Makefile.sources | 1 + .../73e84dac2fc6a2d1bc9250d1414353661088937d.ttf | Bin 0 -> 1136 bytes .../data/in-house/tests/none-directional.tests | 3 +++ 7 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/shaping/data/in-house/fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf create mode 100644 test/shaping/data/in-house/tests/none-directional.tests diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index dc0639f4f..f7a0495b3 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -687,6 +687,8 @@ hb_buffer_t::guess_segment_properties (void) /* If direction is set to INVALID, guess from script */ if (props.direction == HB_DIRECTION_INVALID) { props.direction = hb_script_get_horizontal_direction (props.script); + if (props.direction == HB_DIRECTION_INVALID) + props.direction = HB_DIRECTION_LTR; } /* If language is not set, use default language from locale */ @@ -1489,6 +1491,8 @@ hb_buffer_reverse_clusters (hb_buffer_t *buffer) * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID), * it will be set to the natural horizontal direction of the * buffer script as returned by hb_script_get_horizontal_direction(). + * If hb_script_get_horizontal_direction() returns %HB_DIRECTION_INVALID, + * then %HB_DIRECTION_LTR is used. * * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID), * it will be set to the process's default language as returned by diff --git a/src/hb-common.cc b/src/hb-common.cc index f38ebb043..956855c4d 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -536,6 +536,12 @@ hb_script_get_horizontal_direction (hb_script_t script) case HB_SCRIPT_ADLAM: return HB_DIRECTION_RTL; + + + /* https://github.com/harfbuzz/harfbuzz/issues/1000 */ + case HB_SCRIPT_OLD_ITALIC: + + return HB_DIRECTION_INVALID; } return HB_DIRECTION_LTR; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index dd10e346e..5dc578421 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -306,13 +306,16 @@ static void hb_ensure_native_direction (hb_buffer_t *buffer) { hb_direction_t direction = buffer->props.direction; + hb_direction_t horiz_dir = hb_script_get_horizontal_direction (buffer->props.script); /* TODO vertical: * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType * Ogham fonts are supposed to be implemented BTT or not. Need to research that * first. */ - if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) || - (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) + if ((HB_DIRECTION_IS_HORIZONTAL (direction) && + direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) || + (HB_DIRECTION_IS_VERTICAL (direction) && + direction != HB_DIRECTION_TTB)) { /* Same loop as hb_form_clusters(). * Since form_clusters() merged clusters already, we don't merge. */ diff --git a/test/api/test-common.c b/test/api/test-common.c index 74b50be96..f6f0d4851 100644 --- a/test/api/test-common.c +++ b/test/api/test-common.c @@ -173,6 +173,7 @@ test_types_script (void) g_assert_cmpint (hb_script_get_horizontal_direction (HB_SCRIPT_LATIN), ==, HB_DIRECTION_LTR); g_assert_cmpint (hb_script_get_horizontal_direction (HB_SCRIPT_ARABIC), ==, HB_DIRECTION_RTL); + g_assert_cmpint (hb_script_get_horizontal_direction (HB_SCRIPT_OLD_ITALIC), ==, HB_DIRECTION_INVALID); g_assert_cmpint (hb_script_get_horizontal_direction (hb_script_from_iso15924_tag (wWyZ)), ==, HB_DIRECTION_LTR); } diff --git a/test/shaping/data/in-house/Makefile.sources b/test/shaping/data/in-house/Makefile.sources index 9a1434ec6..bf4df2018 100644 --- a/test/shaping/data/in-house/Makefile.sources +++ b/test/shaping/data/in-house/Makefile.sources @@ -31,6 +31,7 @@ TESTS = \ tests/mark-filtering-sets.tests \ tests/mongolian-variation-selector.tests \ tests/myanmar-syllable.tests \ + tests/none-directional.tests \ tests/spaces.tests \ tests/simple.tests \ tests/tibetan-contractions-1.tests \ diff --git a/test/shaping/data/in-house/fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf b/test/shaping/data/in-house/fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf new file mode 100644 index 0000000000000000000000000000000000000000..46e7c1dacd522eeddf7d84dab4555104e1c87939 GIT binary patch literal 1136 zcma)6T}V_x6#i!J+`FrZyVj;*KW?>I(%;&TOHd^CAeldu{XL}@bG6#lWp|4biXMVq z5{)7#f`STyo`NXpA<^)Wih4-0D1soUz}>#NS1IbHfivg(&YUx6=A5|~0ze)P z!a!wpS8i$;kQ>RHTjF*C1y%+574ms)b}E5F%%;De+}{@4 z7yYs7{&(U*%BS{LdwWiI?R7xBBd=(u!8cu9W_*}D)E-aoEnY9{$fuD9Vx28Ej^i2q zUy$d;?Y#;3u!X#jJlJ8!Tm3TBMgLdiBZ#mdQM$dC&^km?##Ve$Jd882UKU zHz1l`#`^ANMuhLlaOR81AMuwjIMBOhTYqxr@#>m0M;6XMyyS2sd}j0N=(QDP`yj ziC$`$r_817UWu!Xr-qMFo zL?di;AVt)G7`9Wd<%&(b11;EqR$0Y#3(A|4tdjvRYnu-bU!KpY tVj)>BQ2-*Dj>RzrVn^DJ@!R(>nZQJ6*4@xdaOVGj(HaR@?3fr6`~uF+(H;N* literal 0 HcmV?d00001 diff --git a/test/shaping/data/in-house/tests/none-directional.tests b/test/shaping/data/in-house/tests/none-directional.tests new file mode 100644 index 000000000..e59946d1a --- /dev/null +++ b/test/shaping/data/in-house/tests/none-directional.tests @@ -0,0 +1,3 @@ +../fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf::U+10300,U+10301:[u10300=0+1470|u10301=1+1284] +../fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf:--direction=ltr:U+10300,U+10301:[u10300=0+1470|u10301=1+1284] +../fonts/73e84dac2fc6a2d1bc9250d1414353661088937d.ttf:--direction=rtl:U+10300,U+10301:[u10301_r=1+1284|u10300_r=0+1470]