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
This commit is contained in:
Behdad Esfahbod 2018-05-07 13:58:32 -07:00
parent 90869e6962
commit f673cfbd64
7 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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. */

View File

@ -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);
}

View File

@ -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 \

View File

@ -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]