From ec4d4b01e803955a2814c7e4c1d417c2ee1f1bbe Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 7 Mar 2025 15:40:50 -0700 Subject: [PATCH 1/5] [morx] Update buffer on changes, in one more place Was missed out before I believe. --- src/hb-aat-layout-morx-table.hh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 617a239fe..9bc05a0eb 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -882,6 +882,9 @@ struct InsertionSubtable if (unlikely (!buffer->copy_glyph ())) return; /* TODO We ignore KashidaLike setting. */ if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return; + for (unsigned int i = 0; i < count; i++) + c->buffer_glyph_set.add (glyphs[i]); + ret = true; if (buffer->idx < buffer->len && !before) buffer->skip_glyph (); From c6972ac6dda207714c6b835e5b9abb351d46384c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 7 Mar 2025 15:29:48 -0700 Subject: [PATCH 2/5] [aat] Towards removing special deleting of 0xFFFF See https://github.com/harfbuzz/harfbuzz/discussions/5118 Remove the removal. Depend on the default_ignorable flag to hide them later. Test output adjusted. --- src/hb-aat-layout-morx-table.hh | 1 + src/hb-aat-layout.cc | 23 ------------------- src/hb-ot-shape.cc | 14 ----------- test/shape/data/in-house/tests/aat-morx.tests | 2 +- 4 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 9bc05a0eb..39895703a 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -589,6 +589,7 @@ struct LigatureSubtable { DEBUG_MSG (APPLY, nullptr, "Skipping ligature component"); if (unlikely (!buffer->move_to (match_positions[--match_length % ARRAY_LENGTH (match_positions)]))) return; + buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; _hb_glyph_info_set_default_ignorable (&buffer->cur()); if (unlikely (!buffer->replace_glyph (DELETED_GLYPH))) return; } diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 9fe77a575..44a1f3c82 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -320,29 +320,6 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, } } -void -hb_aat_layout_zero_width_deleted_glyphs (hb_buffer_t *buffer) -{ - unsigned int count = buffer->len; - hb_glyph_info_t *info = buffer->info; - hb_glyph_position_t *pos = buffer->pos; - for (unsigned int i = 0; i < count; i++) - if (unlikely (info[i].codepoint == AAT::DELETED_GLYPH)) - pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0; -} - -static bool -is_deleted_glyph (const hb_glyph_info_t *info) -{ - return info->codepoint == AAT::DELETED_GLYPH; -} - -void -hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer) -{ - buffer->delete_glyphs_inplace (is_deleted_glyph); -} - /** * hb_aat_layout_has_positioning: * @face: #hb_face_t to work upon diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index c9defc49a..e55221f69 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -956,21 +956,11 @@ hb_ot_substitute_pre (const hb_ot_shape_context_t *c) _hb_buffer_allocate_gsubgpos_vars (c->buffer); hb_ot_substitute_plan (c); - -#ifndef HB_NO_AAT_SHAPE - if (c->plan->apply_morx && c->plan->apply_gpos) - hb_aat_layout_remove_deleted_glyphs (c->buffer); -#endif } static inline void hb_ot_substitute_post (const hb_ot_shape_context_t *c) { -#ifndef HB_NO_AAT_SHAPE - if (c->plan->apply_morx && !c->plan->apply_gpos) - hb_aat_layout_remove_deleted_glyphs (c->buffer); -#endif - hb_ot_deal_with_variation_selectors (c->buffer); hb_ot_hide_default_ignorables (c->buffer, c->font); @@ -1109,10 +1099,6 @@ hb_ot_position_plan (const hb_ot_shape_context_t *c) /* Finish off. Has to follow a certain order. */ hb_ot_layout_position_finish_advances (c->font, c->buffer); hb_ot_zero_width_default_ignorables (c->buffer); -#ifndef HB_NO_AAT_SHAPE - if (c->plan->apply_morx) - hb_aat_layout_zero_width_deleted_glyphs (c->buffer); -#endif hb_ot_layout_position_finish_offsets (c->font, c->buffer); /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ diff --git a/test/shape/data/in-house/tests/aat-morx.tests b/test/shape/data/in-house/tests/aat-morx.tests index b1b5079e0..b9ecd0d58 100644 --- a/test/shape/data/in-house/tests/aat-morx.tests +++ b/test/shape/data/in-house/tests/aat-morx.tests @@ -1,2 +1,2 @@ -../fonts/MORXTwentyeight.ttf;;U+0041,U+0078,U+0045,U+0079,U+0044,U+0079,U+0079;[A_E_D=0+1394|x=0+529|y=0+510|y=5+510|y=6+510] +../fonts/MORXTwentyeight.ttf;;U+0041,U+0078,U+0045,U+0079,U+0044,U+0079,U+0079;[A_E_D=0+1394|x=0+529|space=0+0|y=0+510|space=0+0|y=5+510|y=6+510] ../fonts/e6185e88b04432fbf373594d5971686bb7dd698d.ttf;;U+0B95,U+0BCD,U+0020,U+0B9A,U+0BCD;[ka-tamil=0+825|pulli-tamil=0@-392,0+0|space=2+260|ca-tamil=3+723|pulli-tamil=3@-320,0+0] From 4ec560dd02d277ad3b2cacf39debeb147bedff1c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 7 Mar 2025 16:14:24 -0700 Subject: [PATCH 3/5] [aat/morx] Refactor all glyph replacements into the context --- src/hb-aat-layout-common.hh | 54 +++++++++++++++++++++++++++++++-- src/hb-aat-layout-morx-table.hh | 44 +++++---------------------- src/hb-aat-layout.cc | 7 +++-- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index d2626b45f..f8e829834 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -29,6 +29,8 @@ #include "hb-aat-layout.hh" #include "hb-aat-map.hh" +#include "hb-ot-layout-common.hh" +#include "hb-ot-layout-gdef-table.hh" #include "hb-open-type.hh" #include "hb-cache.hh" #include "hb-bit-set.hh" @@ -48,6 +50,8 @@ struct ankr; using hb_aat_class_cache_t = hb_cache_t<15, 8, 7>; static_assert (sizeof (hb_aat_class_cache_t) == 256, ""); +enum { DELETED_GLYPH = 0xFFFF }; + struct hb_aat_apply_context_t : hb_dispatch_context_t { @@ -64,7 +68,8 @@ struct hb_aat_apply_context_t : hb_buffer_t *buffer; hb_sanitize_context_t sanitizer; const ankr *ankr_table; - const OT::GDEF *gdef_table; + const OT::GDEF &gdef; + bool has_glyph_classes; const hb_sorted_vector_t *range_flags = nullptr; bool using_buffer_glyph_set = false; hb_bit_set_t buffer_glyph_set; @@ -106,6 +111,51 @@ struct hb_aat_apply_context_t : return true; return false; } + + template + HB_NODISCARD bool output_glyphs (unsigned int count, + const T *glyphs) + { + for (unsigned int i = 0; i < count; i++) + { + if (unlikely (!buffer->output_glyph (glyphs[i]))) return false; + if (glyphs[i] == DELETED_GLYPH) + { + buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; + _hb_glyph_info_set_default_ignorable (&buffer->prev()); + } + else + buffer_glyph_set.add (glyphs[i]); + } + return true; + } + + HB_NODISCARD bool replace_glyph (hb_codepoint_t glyph) + { + if (glyph == DELETED_GLYPH) + return delete_glyph (); + + buffer_glyph_set.add (glyph); + return buffer->replace_glyph (glyph); + } + + HB_NODISCARD bool delete_glyph () + { + buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; + _hb_glyph_info_set_default_ignorable (&buffer->cur()); + return buffer->replace_glyph (DELETED_GLYPH); + } + + void replace_glyph_inplace (unsigned i, hb_codepoint_t glyph) + { + buffer->info[i].codepoint = glyph; + buffer_glyph_set.add (glyph); +#ifndef HB_NO_OT_LAYOUT + if (has_glyph_classes) + _hb_glyph_info_set_glyph_props (&buffer->info[i], + gdef.get_glyph_props (glyph)); +#endif + } }; @@ -113,8 +163,6 @@ struct hb_aat_apply_context_t : * Lookup Table */ -enum { DELETED_GLYPH = 0xFFFF }; - template struct Lookup; template diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 39895703a..ecde9e6e5 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -30,8 +30,6 @@ #include "hb-open-type.hh" #include "hb-aat-layout-common.hh" #include "hb-ot-layout.hh" -#include "hb-ot-layout-common.hh" -#include "hb-ot-layout-gdef-table.hh" #include "hb-aat-map.hh" /* @@ -242,9 +240,7 @@ struct ContextualSubtable ret (false), c (c_), table (table_), - gdef (*c->gdef_table), mark_set (false), - has_glyph_classes (gdef.has_glyph_classes ()), mark (0), subs (table+table->substitutionTables) {} @@ -281,12 +277,7 @@ struct ContextualSubtable if (replacement) { buffer->unsafe_to_break (mark, hb_min (buffer->idx + 1, buffer->len)); - hb_codepoint_t glyph = *replacement; - buffer->info[mark].codepoint = glyph; - c->buffer_glyph_set.add (glyph); - if (has_glyph_classes) - _hb_glyph_info_set_glyph_props (&buffer->info[mark], - gdef.get_glyph_props (*replacement)); + c->replace_glyph_inplace (mark, *replacement); ret = true; } @@ -312,12 +303,7 @@ struct ContextualSubtable } if (replacement) { - hb_codepoint_t glyph = *replacement; - buffer->info[idx].codepoint = glyph; - c->buffer_glyph_set.add (glyph); - if (has_glyph_classes) - _hb_glyph_info_set_glyph_props (&buffer->info[idx], - gdef.get_glyph_props (*replacement)); + c->replace_glyph_inplace (idx, *replacement); ret = true; } @@ -333,9 +319,7 @@ struct ContextualSubtable hb_aat_apply_context_t *c; const ContextualSubtable *table; private: - const OT::GDEF &gdef; bool mark_set; - bool has_glyph_classes; unsigned int mark; const UnsizedListOfOffset16To, HBUINT, void, false> &subs; }; @@ -581,7 +565,7 @@ struct LigatureSubtable hb_codepoint_t lig = ligatureData; DEBUG_MSG (APPLY, nullptr, "Produced ligature %u", lig); - if (unlikely (!buffer->replace_glyph (lig))) return; + if (unlikely (!c->replace_glyph (lig))) return; unsigned int lig_end = match_positions[(match_length - 1u) % ARRAY_LENGTH (match_positions)] + 1u; /* Now go and delete all subsequent components. */ @@ -589,9 +573,7 @@ struct LigatureSubtable { DEBUG_MSG (APPLY, nullptr, "Skipping ligature component"); if (unlikely (!buffer->move_to (match_positions[--match_length % ARRAY_LENGTH (match_positions)]))) return; - buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; - _hb_glyph_info_set_default_ignorable (&buffer->cur()); - if (unlikely (!buffer->replace_glyph (DELETED_GLYPH))) return; + if (!c->delete_glyph ()) return; } if (unlikely (!buffer->move_to (lig_end))) return; @@ -672,9 +654,6 @@ struct NoncontextualSubtable return_trace (false); } - const OT::GDEF &gdef (*c->gdef_table); - bool has_glyph_classes = gdef.has_glyph_classes (); - bool ret = false; unsigned int num_glyphs = c->face->get_num_glyphs (); @@ -704,12 +683,7 @@ struct NoncontextualSubtable const HBGlyphID16 *replacement = substitute.get_value (info[i].codepoint, num_glyphs); if (replacement) { - hb_codepoint_t glyph = *replacement; - info[i].codepoint = glyph; - c->buffer_glyph_set.add (glyph); - if (has_glyph_classes) - _hb_glyph_info_set_glyph_props (&info[i], - gdef.get_glyph_props (*replacement)); + c->replace_glyph_inplace (i, *replacement); ret = true; } } @@ -851,9 +825,7 @@ struct InsertionSubtable if (buffer->idx < buffer->len && !before) if (unlikely (!buffer->copy_glyph ())) return; /* TODO We ignore KashidaLike setting. */ - if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return; - for (unsigned int i = 0; i < count; i++) - c->buffer_glyph_set.add (glyphs[i]); + if (unlikely (!c->output_glyphs (count, glyphs))) return; ret = true; if (buffer->idx < buffer->len && !before) buffer->skip_glyph (); @@ -882,9 +854,7 @@ struct InsertionSubtable if (buffer->idx < buffer->len && !before) if (unlikely (!buffer->copy_glyph ())) return; /* TODO We ignore KashidaLike setting. */ - if (unlikely (!buffer->replace_glyphs (0, count, glyphs))) return; - for (unsigned int i = 0; i < count; i++) - c->buffer_glyph_set.add (glyphs[i]); + if (unlikely (!c->output_glyphs (count, glyphs))) return; ret = true; if (buffer->idx < buffer->len && !before) buffer->skip_glyph (); diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 44a1f3c82..d1a7de1d1 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -58,13 +58,14 @@ AAT::hb_aat_apply_context_t::hb_aat_apply_context_t (const hb_ot_shape_plan_t *p buffer (buffer_), sanitizer (), ankr_table (&Null (AAT::ankr)), - gdef_table ( + gdef ( #ifndef HB_NO_OT_LAYOUT - face->table.GDEF->table + *face->table.GDEF->table #else - &Null (GDEF) + Null (GDEF) #endif ), + has_glyph_classes (gdef.has_glyph_classes ()), lookup_index (0) { sanitizer.init (blob); From dc048b7c8818cbbea02fdb49fb08ffea6a5cb471 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 7 Mar 2025 16:16:51 -0700 Subject: [PATCH 4/5] [aat/morx] Set glyph props consistently --- src/hb-aat-layout-common.hh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index f8e829834..e2ac53f6f 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -118,14 +118,21 @@ struct hb_aat_apply_context_t : { for (unsigned int i = 0; i < count; i++) { - if (unlikely (!buffer->output_glyph (glyphs[i]))) return false; if (glyphs[i] == DELETED_GLYPH) { buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; - _hb_glyph_info_set_default_ignorable (&buffer->prev()); + _hb_glyph_info_set_default_ignorable (&buffer->cur()); } else + { buffer_glyph_set.add (glyphs[i]); +#ifndef HB_NO_OT_LAYOUT + if (has_glyph_classes) + _hb_glyph_info_set_glyph_props (&buffer->cur(), + gdef.get_glyph_props (glyphs[i])); +#endif + } + if (unlikely (!buffer->output_glyph (glyphs[i]))) return false; } return true; } @@ -136,6 +143,11 @@ struct hb_aat_apply_context_t : return delete_glyph (); buffer_glyph_set.add (glyph); +#ifndef HB_NO_OT_LAYOUT + if (has_glyph_classes) + _hb_glyph_info_set_glyph_props (&buffer->cur(), + gdef.get_glyph_props (glyph)); +#endif return buffer->replace_glyph (glyph); } From ff76244ea66fc20e767903a0c8cbd65d1dc3e4ba Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 9 Mar 2025 17:23:18 -0600 Subject: [PATCH 5/5] [aat/morx] Delete deleted glyphs again But also check for default-ignorable bit this time. --- src/hb-aat-layout.cc | 13 +++++++++++++ src/hb-aat-layout.hh | 3 --- src/hb-ot-shape.cc | 10 ++++++++++ test/shape/data/in-house/tests/aat-morx.tests | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index d1a7de1d1..c984da447 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -321,6 +321,19 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, } } +static bool +is_deleted_glyph (const hb_glyph_info_t *info) +{ + return info->codepoint == AAT::DELETED_GLYPH && + _hb_glyph_info_is_default_ignorable (info); +} + +void +hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer) +{ + buffer->delete_glyphs_inplace (is_deleted_glyph); +} + /** * hb_aat_layout_has_positioning: * @face: #hb_face_t to work upon diff --git a/src/hb-aat-layout.hh b/src/hb-aat-layout.hh index c5d6ecb10..0e4ae6e7b 100644 --- a/src/hb-aat-layout.hh +++ b/src/hb-aat-layout.hh @@ -60,9 +60,6 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan, const hb_feature_t *features, unsigned num_features); -HB_INTERNAL void -hb_aat_layout_zero_width_deleted_glyphs (hb_buffer_t *buffer); - HB_INTERNAL void hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer); diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index e55221f69..6eecc1a10 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -956,11 +956,21 @@ hb_ot_substitute_pre (const hb_ot_shape_context_t *c) _hb_buffer_allocate_gsubgpos_vars (c->buffer); hb_ot_substitute_plan (c); + +#ifndef HB_NO_AAT_SHAPE + if (c->plan->apply_morx && c->plan->apply_gpos) + hb_aat_layout_remove_deleted_glyphs (c->buffer); +#endif } static inline void hb_ot_substitute_post (const hb_ot_shape_context_t *c) { +#ifndef HB_NO_AAT_SHAPE + if (c->plan->apply_morx && !c->plan->apply_gpos) + hb_aat_layout_remove_deleted_glyphs (c->buffer); +#endif + hb_ot_deal_with_variation_selectors (c->buffer); hb_ot_hide_default_ignorables (c->buffer, c->font); diff --git a/test/shape/data/in-house/tests/aat-morx.tests b/test/shape/data/in-house/tests/aat-morx.tests index b9ecd0d58..b1b5079e0 100644 --- a/test/shape/data/in-house/tests/aat-morx.tests +++ b/test/shape/data/in-house/tests/aat-morx.tests @@ -1,2 +1,2 @@ -../fonts/MORXTwentyeight.ttf;;U+0041,U+0078,U+0045,U+0079,U+0044,U+0079,U+0079;[A_E_D=0+1394|x=0+529|space=0+0|y=0+510|space=0+0|y=5+510|y=6+510] +../fonts/MORXTwentyeight.ttf;;U+0041,U+0078,U+0045,U+0079,U+0044,U+0079,U+0079;[A_E_D=0+1394|x=0+529|y=0+510|y=5+510|y=6+510] ../fonts/e6185e88b04432fbf373594d5971686bb7dd698d.ttf;;U+0B95,U+0BCD,U+0020,U+0B9A,U+0BCD;[ka-tamil=0+825|pulli-tamil=0@-392,0+0|space=2+260|ca-tamil=3+723|pulli-tamil=3@-320,0+0]