diff --git a/src/hb-ot-shaper-hangul.cc b/src/hb-ot-shaper-hangul.cc index ce87a9156..514b078bf 100644 --- a/src/hb-ot-shaper-hangul.cc +++ b/src/hb-ot-shaper-hangul.cc @@ -67,14 +67,23 @@ static void override_features_hangul (hb_ot_shape_planner_t *plan) { /* Uniscribe does not apply 'calt' for Hangul, and certain fonts - * (Noto Sans CJK, Source Sans Han, etc) apply all of jamo lookups - * in calt, which is not desirable. */ - plan->map.disable_feature (HB_TAG('c','a','l','t')); + * (Noto Sans CJK, Source Han Sans, etc) apply all of jamo lookups + * in calt, which is not desirable. + * + * Rather than disabling 'calt' for the entire run, which also turns + * it off for any other characters in the run, allocate a mask for it + * and clear that mask on jamo only (in setup_masks_hangul). That + * keeps jamo out of reach of such lookups while letting the rest of + * the run shape with 'calt' as usual. + * + * https://github.com/harfbuzz/harfbuzz/discussions/4853 */ + plan->map.add_feature (HB_TAG('c','a','l','t')); } struct hangul_shape_plan_t { hb_mask_t mask_array[HANGUL_FEATURE_COUNT]; + hb_mask_t calt_mask; }; static void * @@ -87,6 +96,8 @@ data_create_hangul (const hb_ot_shape_plan_t *plan) for (unsigned int i = 0; i < HANGUL_FEATURE_COUNT; i++) hangul_plan->mask_array[i] = plan->map.get_1_mask (hangul_features[i]); + hangul_plan->calt_mask = plan->map.get_1_mask (HB_TAG('c','a','l','t')); + return hangul_plan; } @@ -405,7 +416,14 @@ setup_masks_hangul (const hb_ot_shape_plan_t *plan, unsigned int count = buffer->len; hb_glyph_info_t *info = buffer->info; for (unsigned int i = 0; i < count; i++, info++) + { info->mask |= hangul_plan->mask_array[info->hangul_shaping_feature()]; + + /* Keep 'calt' away from jamo; see override_features_hangul(). */ + hb_codepoint_t u = info->codepoint; + if (isL (u) || isV (u) || isT (u)) + info->mask &= ~hangul_plan->calt_mask; + } } HB_BUFFER_DEALLOCATE_VAR (buffer, hangul_shaping_feature); diff --git a/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf b/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf new file mode 100644 index 000000000..41825c743 Binary files /dev/null and b/test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf differ diff --git a/test/shape/data/in-house/meson.build b/test/shape/data/in-house/meson.build index 12a313a83..1253b08e5 100644 --- a/test/shape/data/in-house/meson.build +++ b/test/shape/data/in-house/meson.build @@ -22,6 +22,7 @@ in_house_tests = [ 'emoji-clusters.tests', 'fallback-positioning.tests', 'glyph-props-no-gdef.tests', + 'hangul-calt.tests', 'hangul-jamo.tests', 'harfbust.tests', 'hebrew-diacritics.tests', diff --git a/test/shape/data/in-house/tests/hangul-calt.tests b/test/shape/data/in-house/tests/hangul-calt.tests new file mode 100644 index 000000000..0c1eba6c4 --- /dev/null +++ b/test/shape/data/in-house/tests/hangul-calt.tests @@ -0,0 +1,5 @@ +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+AC00,U+003D,U+003E;[ga=0+600|eq_gt.calt=1+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+AC00,U+B098;[ga_na.calt=0+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+1100,U+1100;[jamoL=0+600|jamoL=1+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;;U+B098,U+B098;[na_na.liga=0+600] +../fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf;--features=calt=0;U+AC00,U+003D,U+003E;[ga=0+600|equal=1+600|greater=2+600]