From 882ce8e6f381c45c9bf129aad37b284d5abcff73 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 7 Jun 2026 20:59:44 +0200 Subject: [PATCH] [layout] Use 32-bit lookup offsets in LookupList2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make the GSUB/GPOS v1.2 LookupList2 path use LookupList, so the lookup count remains 16-bit while per-lookup offsets are widened to 32 bits. Runtime lookup access now branches between the lower and upper lookup-list layouts. As of June 2026, the proposed GSUB/GPOS v1.2 spec points LookupList2 at LookupList, which would leave per-lookup offsets at 16 bits. Note that HarfBuzz intentionally widens those offsets because the proposed shape is not suitable for beyond-64k fonts. Keep the graph repacker on lower GSUB/GPOS tables for now, since it walks the raw lookup-list object layout. Testing: meson compile -C build util/hb-subset test-repacker Testing: meson test -C build --suite shape --suite subset Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'test' Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'කොහොමද' Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'क्षि' Assisted-by: OpenAI Codex --- src/graph/gsubgpos-graph.hh | 6 +++++ src/hb-ot-layout-common.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 49 +++++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/graph/gsubgpos-graph.hh b/src/graph/gsubgpos-graph.hh index 7f21ca2ed..25105c7cf 100644 --- a/src/graph/gsubgpos-graph.hh +++ b/src/graph/gsubgpos-graph.hh @@ -433,6 +433,9 @@ struct GSTAR : public OT::GSUBGPOS unsigned get_lookup_list_index (graph_t& graph) { + if (version.to_int () >= 0x00010002u) + return (unsigned) -1; + return graph.index_for_offset (graph.root_idx (), get_lookup_list_field_offset()); } @@ -441,6 +444,9 @@ struct GSTAR : public OT::GSUBGPOS void find_lookups (graph_t& graph, hb_hashmap_t& lookups /* OUT */) { + if (version.to_int () >= 0x00010002u) + return; + unsigned lookup_list_idx = get_lookup_list_index (graph); const LookupList* lookupList = (const LookupList*) graph.object (lookup_list_idx).head; diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 8899b68a1..953cb1187 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1432,7 +1432,7 @@ struct Lookup }; template -using LookupList = List16OfOffsetTo; +using LookupList = List16OfOffsetTo; template struct LookupOffsetList : List16OfOffsetTo diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index dee7d04c1..a3611d804 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -4644,10 +4644,15 @@ struct hb_ot_layout_lookup_accelerator_t struct GSUBGPOS { using LookupListT = LookupList; + using LookupList2T = LookupList; template - using TLookupList = List16OfOffset16To; + using TLookupList = List16OfOffsetTo; template - using TLookupOffsetList = LookupOffsetList; + using TLookupList2 = List16OfOffsetTo; + template + using TLookupOffsetList = LookupOffsetList; + template + using TLookupOffsetList2 = LookupOffsetList; size_t get_size () const { @@ -4677,14 +4682,6 @@ struct GSUBGPOS #endif return this + featureList; } - const LookupListT &get_lookup_list () const - { -#ifndef HB_NO_BEYOND_64K - if (version.to_int () >= 0x00010002u && lookupList2) return this + lookupList2; -#endif - return this + lookupList; - } - template bool sanitize (hb_sanitize_context_t *c) const { @@ -4812,9 +4809,21 @@ struct GSUBGPOS } unsigned int get_lookup_count () const - { return get_lookup_list ().len; } + { +#ifndef HB_NO_BEYOND_64K + if (version.to_int () >= 0x00010002u && lookupList2) + return (this + lookupList2).len; +#endif + return (this + lookupList).len; + } const Lookup& get_lookup (unsigned int i) const - { return get_lookup_list ()[i]; } + { +#ifndef HB_NO_BEYOND_64K + if (version.to_int () >= 0x00010002u && lookupList2) + return (this + lookupList2)[i]; +#endif + return (this + lookupList)[i]; + } const FeatureVariations &get_feature_variations () const { return (version.to_int () >= 0x00010001u && hb_barrier ()) ? this+featureVars : Null (FeatureVariations); @@ -5055,8 +5064,8 @@ struct GSUBGPOS #ifndef HB_NO_BEYOND_64K template - const Offset32To>& typed_lookup_list2_offset () const - { return reinterpret_cast>&> (lookupList2); } + const Offset32To>& typed_lookup_list2_offset () const + { return reinterpret_cast>&> (lookupList2); } #endif template @@ -5068,8 +5077,8 @@ struct GSUBGPOS #ifndef HB_NO_BEYOND_64K template - const Offset32To>& subset_lookup_list2_offset () const - { return reinterpret_cast>&> (lookupList2); } + const Offset32To>& subset_lookup_list2_offset () const + { return reinterpret_cast>&> (lookupList2); } #endif const Offset16To& subset_feature_list_offset () const @@ -5127,8 +5136,12 @@ struct GSUBGPOS Offset32To featureList2; /* 32-bit offset to FeatureList table. * Introduced in version 0x00010002. */ - Offset32To - lookupList2; /* 32-bit offset to LookupList table. + Offset32To + lookupList2; /* 32-bit offset to LookupList table with + * 32-bit lookup offsets. + * The June 2026 proposed spec points this to + * a LookupList instead; that was not suitable + * for beyond-64k fonts. * Introduced in version 0x00010002. */ #endif public: