[layout] Align extended offsets with spec

Coverage format 3 and 4 widen their array counts, and coverage
range records also widen the coverage index value.  Account for the
larger records in the graph size estimator.

Use 32-bit top-level offsets where the extended GSUB/GPOS/context
formats specify long offsets, while leaving nested offset arrays as
24-bit offsets.  SequenceRuleSet2 is the exception where the rule-set
array offsets stay 16-bit and only the rule contents use extended
widths.

Tested with:
- meson compile -C build util/hb-shape
- git diff --check

Existing fontTools-generated Sinhala upper-case test fonts still lose
GSUB/GPOS script data and need follow-up debugging.

Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Behdad Esfahbod committed 2026-06-06 13:19:16 +02:00
1 parent 41decf1b0f
commit 2a543ecdd4
14 files changed
+57 -57

No files matched your search

+2 -2
View File
@@ -43,10 +43,10 @@ struct CoverageFormat1_3
public:
HBUINT16 coverageFormat; /* Format identifier--format = 1 */
SortedArray16Of<typename Types::HBGlyphID>
typename Types::template SortedArrayOf<typename Types::HBGlyphID>
glyphArray; /* Array of GlyphIDs--in numerical order */
DEFINE_SIZE_ARRAY (4, glyphArray);
DEFINE_SIZE_ARRAY (2 + Types::HBUINT::static_size, glyphArray);
private:
bool sanitize (hb_sanitize_context_t *c) const
+6 -5
View File
@@ -39,15 +39,16 @@ template <typename Types>
struct CoverageFormat2_4
{
friend struct Coverage;
using CoverageRangeRecord = RangeRecord<Types, typename Types::HBUINT>;
public:
HBUINT16 coverageFormat; /* Format identifier--format = 2 */
SortedArray16Of<RangeRecord<Types>>
typename Types::template SortedArrayOf<CoverageRangeRecord>
rangeRecord; /* Array of glyph ranges--ordered by
* Start GlyphID. rangeCount entries
* long */
public:
DEFINE_SIZE_ARRAY (4, rangeRecord);
DEFINE_SIZE_ARRAY (2 + Types::HBUINT::static_size, rangeRecord);
private:
@@ -59,7 +60,7 @@ struct CoverageFormat2_4
unsigned int get_coverage (hb_codepoint_t glyph_id) const
{
const RangeRecord<Types> &range = rangeRecord.bsearch (glyph_id);
const CoverageRangeRecord &range = rangeRecord.bsearch (glyph_id);
return likely (range.first <= range.last)
? (unsigned int) range.value + (glyph_id - range.first)
: NOT_COVERED;
@@ -113,7 +114,7 @@ struct CoverageFormat2_4
}
if (unlikely (unsorted))
rangeRecord.as_array ().qsort (RangeRecord<Types>::cmp_range);
rangeRecord.as_array ().qsort (CoverageRangeRecord::cmp_range);
return_trace (true);
}
@@ -129,7 +130,7 @@ struct CoverageFormat2_4
}
return hb_any (+ hb_iter (rangeRecord)
| hb_map ([glyphs] (const RangeRecord<Types> &range) { return range.intersects (*glyphs); }));
| hb_map ([glyphs] (const CoverageRangeRecord &range) { return range.intersects (*glyphs); }));
}
bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const
{
+7 -7
View File
@@ -33,14 +33,14 @@ namespace OT {
namespace Layout {
namespace Common {
template <typename Types>
template <typename Types, typename Value = HBUINT16>
struct RangeRecord
{
typename Types::HBGlyphID first; /* First GlyphID in the range */
typename Types::HBGlyphID last; /* Last GlyphID in the range */
HBUINT16 value; /* Value */
Value value; /* Value */
DEFINE_SIZE_STATIC (2 + 2 * Types::size);
DEFINE_SIZE_STATIC (2 * Types::size + Value::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
@@ -86,10 +86,10 @@ struct RangeRecord
// but that only works when there is only a single namespace level.
// The macro should probably be fixed so it can work in this situation.
extern HB_INTERNAL const unsigned char _hb_Null_OT_RangeRecord[9];
template <typename Spec>
struct Null<OT::Layout::Common::RangeRecord<Spec>> {
static OT::Layout::Common::RangeRecord<Spec> const & get_null () {
return *reinterpret_cast<const OT::Layout::Common::RangeRecord<Spec> *> (_hb_Null_OT_RangeRecord);
template <typename Spec, typename Value>
struct Null<OT::Layout::Common::RangeRecord<Spec, Value>> {
static OT::Layout::Common::RangeRecord<Spec, Value> const & get_null () {
return *reinterpret_cast<const OT::Layout::Common::RangeRecord<Spec, Value> *> (_hb_Null_OT_RangeRecord);
}
};
+5 -5
View File
@@ -12,22 +12,22 @@ struct MarkBasePosFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
markCoverage; /* Offset to MarkCoverage table--from
* beginning of MarkBasePos subtable */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
baseCoverage; /* Offset to BaseCoverage table--from
* beginning of MarkBasePos subtable */
HBUINT16 classCount; /* Number of classes defined for marks */
typename Types::template OffsetTo<MarkArray<Types>>
typename Types::template LOffsetTo<MarkArray<Types>>
markArray; /* Offset to MarkArray table--from
* beginning of MarkBasePos subtable */
typename Types::template OffsetTo<AnchorMatrix<Types>>
typename Types::template LOffsetTo<AnchorMatrix<Types>>
baseArray; /* Offset to BaseArray table--from
* beginning of MarkBasePos subtable */
public:
DEFINE_SIZE_STATIC (4 + 4 * Types::size);
DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
+5 -5
View File
@@ -13,22 +13,22 @@ struct MarkLigPosFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
markCoverage; /* Offset to Mark Coverage table--from
* beginning of MarkLigPos subtable */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
ligatureCoverage; /* Offset to Ligature Coverage
* table--from beginning of MarkLigPos
* subtable */
HBUINT16 classCount; /* Number of defined mark classes */
typename Types::template OffsetTo<MarkArray<Types>>
typename Types::template LOffsetTo<MarkArray<Types>>
markArray; /* Offset to MarkArray table--from
* beginning of MarkLigPos subtable */
typename Types::template OffsetTo<LigatureArray<Types>>
typename Types::template LOffsetTo<LigatureArray<Types>>
ligatureArray; /* Offset to LigatureArray table--from
* beginning of MarkLigPos subtable */
public:
DEFINE_SIZE_STATIC (4 + 4 * Types::size);
DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
+5 -5
View File
@@ -12,23 +12,23 @@ struct MarkMarkPosFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
mark1Coverage; /* Offset to Combining Mark1 Coverage
* table--from beginning of MarkMarkPos
* subtable */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
mark2Coverage; /* Offset to Combining Mark2 Coverage
* table--from beginning of MarkMarkPos
* subtable */
HBUINT16 classCount; /* Number of defined mark classes */
typename Types::template OffsetTo<MarkArray<Types>>
typename Types::template LOffsetTo<MarkArray<Types>>
mark1Array; /* Offset to Mark1Array table--from
* beginning of MarkMarkPos subtable */
typename Types::template OffsetTo<AnchorMatrix<Types, HBUINT16>>
typename Types::template LOffsetTo<AnchorMatrix<Types, HBUINT16>>
mark2Array; /* Offset to Mark2Array table--from
* beginning of MarkMarkPos subtable */
public:
DEFINE_SIZE_STATIC (4 + 4 * Types::size);
DEFINE_SIZE_STATIC (4 + 4 * Types::LOffset::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -2
View File
@@ -13,14 +13,14 @@ struct AlternateSubstFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
typename Types::template ArrayOf<typename Types::template OffsetTo<AlternateSet<Types>>>
alternateSet; /* Array of AlternateSet tables
* ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, alternateSet);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, alternateSet);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -2
View File
@@ -13,14 +13,14 @@ struct LigatureSubstFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
typename Types::template ArrayOf<typename Types::template OffsetTo<LigatureSet<Types>>>
ligatureSet; /* Array LigatureSet tables
* ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, ligatureSet);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, ligatureSet);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -2
View File
@@ -13,14 +13,14 @@ struct MultipleSubstFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
typename Types::template ArrayOf<typename Types::template OffsetTo<Sequence<Types>>>
sequence; /* Array of Sequence tables
* ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, sequence);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, sequence);
bool sanitize (hb_sanitize_context_t *c) const
{
@@ -12,7 +12,7 @@ struct ReverseChainSingleSubstFormat1_2
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */
Array16Of<typename Types::template OffsetTo<Coverage>>
@@ -29,7 +29,7 @@ struct ReverseChainSingleSubstFormat1_2
substituteX; /* Array of substitute
* GlyphIDs--ordered by Coverage Index */
public:
DEFINE_SIZE_MIN (6 + 2 * Types::size);
DEFINE_SIZE_MIN (6 + Types::LOffset::static_size + Types::HBUINT::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -2
View File
@@ -12,7 +12,7 @@ struct SingleSubstFormat1_3
{
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
typename Types::HBUINT
@@ -20,7 +20,7 @@ struct SingleSubstFormat1_3
* substitute GlyphID, modulo 0x10000 */
public:
DEFINE_SIZE_STATIC (2 + 2 * Types::size);
DEFINE_SIZE_STATIC (2 + Types::LOffset::static_size + Types::HBUINT::static_size);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -2
View File
@@ -12,7 +12,7 @@ struct SingleSubstFormat2_4
{
protected:
HBUINT16 format; /* Format identifier--format = 2 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of Substitution table */
typename Types::template ArrayOf<typename Types::HBGlyphID>
@@ -20,7 +20,7 @@ struct SingleSubstFormat2_4
* GlyphIDs--ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, substitute);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, substitute);
bool sanitize (hb_sanitize_context_t *c) const
{
+2 -3
View File
@@ -135,8 +135,6 @@ struct ClassDef : public OT::ClassDef
struct class_def_size_estimator_t
{
constexpr static unsigned coverage_base_size = 4;
template<typename It>
class_def_size_estimator_t (It glyph_and_class)
: num_ranges_per_class (), glyphs_per_class ()
@@ -187,7 +185,8 @@ struct class_def_size_estimator_t
unsigned coverage_size () const
{
unsigned glyph_size = glyph_id_size (included_glyphs);
unsigned range_size = 2 * glyph_size + OT::HBUINT16::static_size;
unsigned coverage_base_size = OT::HBUINT16::static_size + glyph_size;
unsigned range_size = 3 * glyph_size;
unsigned format1_size = coverage_base_size + glyph_size * included_glyphs.get_population();
unsigned format2_size = coverage_base_size + range_size * num_glyph_ranges (included_glyphs);
return hb_min(format1_size, format2_size);
+13 -13
View File
@@ -2472,7 +2472,7 @@ struct RuleSetOf
};
template <typename Types>
struct RuleSet : RuleSetOf<Types, Rule<Types>> {};
struct RuleSet : RuleSetOf<SmallTypes, Rule<Types>> {};
template <typename Types>
struct ClassRuleSet : RuleSetOf<Types, Rule<SmallTypes>> {};
@@ -2619,14 +2619,14 @@ struct ContextFormat1_4
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */
typename Types::template ArrayOf<typename Types::template OffsetTo<RuleSet>>
ruleSet; /* Array of RuleSet tables
* ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, ruleSet);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, ruleSet);
};
@@ -2876,17 +2876,17 @@ struct ContextFormat2_5
protected:
HBUINT16 format; /* Format identifier--format = 2 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */
typename Types::template OffsetTo<ClassDef>
typename Types::template LOffsetTo<ClassDef>
classDef; /* Offset to glyph ClassDef table--from
* beginning of table */
typename Types::template ArrayOf<typename Types::template OffsetTo<RuleSet>>
ruleSet; /* Array of RuleSet tables
* ordered by class */
public:
DEFINE_SIZE_ARRAY (2 + 3 * Types::size, ruleSet);
DEFINE_SIZE_ARRAY (2 + 2 * Types::LOffset::static_size + Types::HBUINT::static_size, ruleSet);
};
@@ -3849,14 +3849,14 @@ struct ChainContextFormat1_4
protected:
HBUINT16 format; /* Format identifier--format = 1 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */
typename Types::template ArrayOf<typename Types::template OffsetTo<ChainRuleSet>>
ruleSet; /* Array of ChainRuleSet tables
* ordered by Coverage Index */
public:
DEFINE_SIZE_ARRAY (2 + 2 * Types::size, ruleSet);
DEFINE_SIZE_ARRAY (2 + Types::LOffset::static_size + Types::HBUINT::static_size, ruleSet);
};
template <typename Types>
@@ -4152,18 +4152,18 @@ struct ChainContextFormat2_5
protected:
HBUINT16 format; /* Format identifier--format = 2 */
typename Types::template OffsetTo<Coverage>
typename Types::template LOffsetTo<Coverage>
coverage; /* Offset to Coverage table--from
* beginning of table */
typename Types::template OffsetTo<ClassDef>
typename Types::template LOffsetTo<ClassDef>
backtrackClassDef; /* Offset to glyph ClassDef table
* containing backtrack sequence
* data--from beginning of table */
typename Types::template OffsetTo<ClassDef>
typename Types::template LOffsetTo<ClassDef>
inputClassDef; /* Offset to glyph ClassDef
* table containing input sequence
* data--from beginning of table */
typename Types::template OffsetTo<ClassDef>
typename Types::template LOffsetTo<ClassDef>
lookaheadClassDef; /* Offset to glyph ClassDef table
* containing lookahead sequence
* data--from beginning of table */
@@ -4171,7 +4171,7 @@ struct ChainContextFormat2_5
ruleSet; /* Array of ChainRuleSet tables
* ordered by class */
public:
DEFINE_SIZE_ARRAY (4 + 4 * Types::size, ruleSet);
DEFINE_SIZE_ARRAY (4 + 4 * Types::LOffset::static_size, ruleSet);
};
template <typename Types>