From 72dfc30899653306a1100752a786f3d42bfd2a9f Mon Sep 17 00:00:00 2001 From: j0j1j2 <000111000e@gmail.com> Date: Tue, 16 Jun 2026 20:55:17 +0900 Subject: [PATCH] [hangul] Apply 'calt' feature to non-Hangul characters in Hangul runs (#6030) --- src/hb-ot-shaper-hangul.cc | 24 +++++++++++++++--- ...0387433d01cd5799e421dad6510a54c862f56b.ttf | Bin 0 -> 956 bytes test/shape/data/in-house/meson.build | 1 + .../data/in-house/tests/hangul-calt.tests | 5 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/shape/data/in-house/fonts/600387433d01cd5799e421dad6510a54c862f56b.ttf create mode 100644 test/shape/data/in-house/tests/hangul-calt.tests 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 0000000000000000000000000000000000000000..41825c74395738740e05a8dd41b16588c42f3c71 GIT binary patch literal 956 zcmah|ziU%b6#mY=FG&+?wGyRNg(!7V(JB~38l|n;4uwJ*rGpwT@%hs5@)Da@sGFOE zi#T=YEDjD8916PV(%FAP97Go#C4ToNO(P9>;NEk-@BDb@p2LFxIDlu+n4DX>GjsC$ zSOL&EvYU%b7cWm=(Ro0w5^h|_7~#!#P@>m>0@e&I?qe0zIk-+!@C;ok39J* z34K~#(f-9VQLV@8YMB;fgV%W2s2Gcwf0);J-K;lp5Q_dW;#_3v{+}0{&*`5eUTZd5 z@tL^?pNQXB4BI=;%JHdE`OwsFX#I^0z81G{^=oTWw5{xfIXc(on>yW)vz7Wq95dXb zb~Aefv|5&zNWj~p23vfZ^q0RuVPs*;&S0?Qpn9DRj}x*68I z2Dy2Ap~U&RjdQBDBZ0DIFyg|q-FVB>!#&KnXknJ%EGIIIW2_})?Vgmg($ooOWn7N9 VoqEi+U+Ux@>1vPvYA28N{{lh6b94Xz literal 0 HcmV?d00001 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]