diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 946731017..2d3d9d851 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -4057,7 +4057,7 @@ struct ContextFormat3_6 nullptr /* intersected_glyphs_cache */ }; context_depend_lookup (c, - glyphCount, (const HBUINT16 *) (coverageZ.arrayZ + 1), + glyphCount, coverageZ.arrayZ + 1, lookupCount, lookupRecord, this, coverageZ[0], lookup_context); diff --git a/test/api/fonts/context-format6.ttf b/test/api/fonts/context-format6.ttf new file mode 100644 index 000000000..e2b741b81 Binary files /dev/null and b/test/api/fonts/context-format6.ttf differ diff --git a/test/api/generate-context-format6-font.py b/test/api/generate-context-format6-font.py new file mode 100644 index 000000000..b2e039e6b --- /dev/null +++ b/test/api/generate-context-format6-font.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +"""Generate a minimal font with a GSUB ContextSubst format 6 lookup. + +Format 6 is the beyond-64k coverage-based context format; its Coverage +offsets are 24-bit. Lookup 0 (feature 'liga') matches glyphs 1 2 and +calls lookup 1 at sequence index 1. Lookup 1 is a SingleSubst that +maps glyph 2 to glyph 3 and is not referenced by any feature, so the +2 -> 3 dependency is only found by recursing through the format 6 rule. +""" +from pathlib import Path +import struct + +OUT = Path(__file__).parent / "fonts" / "context-format6.ttf" + + +def u16(v): + return struct.pack(">H", v) + + +def u24(v): + return struct.pack(">I", v)[1:] + + +def u32(v): + return struct.pack(">I", v) + + +def coverage(*glyphs): + return u16(1) + u16(len(glyphs)) + b"".join(u16(g) for g in glyphs) + + +# ContextFormat6: format, glyphCount, lookupCount, Offset24 coverages, +# then LookupRecords. +context_header_len = 6 + 2 * 3 + 4 +cov0 = coverage(1) +cov1 = coverage(2) +context = (u16(6) + u16(2) + u16(1) + + u24(context_header_len) + + u24(context_header_len + len(cov0)) + + u16(1) + u16(1) # sequenceIndex 1 -> lookup 1 + + cov0 + cov1) + +# SingleSubstFormat1: 2 -> 3. +single = u16(1) + u16(6) + u16(1) + coverage(2) + + +def lookup(lookup_type, subtable): + return u16(lookup_type) + u16(0) + u16(1) + u16(8) + subtable + + +lookups = [lookup(5, context), lookup(1, single)] +lookup_list = u16(len(lookups)) +offset = 2 + 2 * len(lookups) +for l in lookups: + lookup_list += u16(offset) + offset += len(l) +lookup_list += b"".join(lookups) + +feature_list = u16(1) + b"liga" + u16(8) + u16(0) + u16(1) + u16(0) +lang_sys = u16(0) + u16(0xFFFF) + u16(1) + u16(0) +script_list = u16(1) + b"DFLT" + u16(8) + u16(4) + u16(0) + lang_sys + +script_list_offset = 10 +feature_list_offset = script_list_offset + len(script_list) +lookup_list_offset = feature_list_offset + len(feature_list) +gsub = (u16(1) + u16(0) + + u16(script_list_offset) + + u16(feature_list_offset) + + u16(lookup_list_offset) + + script_list + feature_list + lookup_list) + +maxp = u32(0x00005000) + u16(4) + +tables = sorted([(b"GSUB", gsub), (b"maxp", maxp)]) +font = u32(0x00010000) + u16(len(tables)) + u16(32) + u16(1) + u16(0) +data = b"" +offset = 12 + 16 * len(tables) +for tag, table in tables: + font += tag + u32(0) + u32(offset + len(data)) + u32(len(table)) + data += table + b"\0" * (-len(table) % 4) +OUT.write_bytes(font + data) diff --git a/test/api/test-ot-depend.c b/test/api/test-ot-depend.c index 7944402f8..a442c20fe 100644 --- a/test/api/test-ot-depend.c +++ b/test/api/test-ot-depend.c @@ -604,6 +604,23 @@ test_depend_varc (void) hb_face_destroy (face); } +/* ContextSubst format 6 (beyond-64k) uses 24-bit Coverage offsets. + * Lookup 0 matches glyphs 1 2 and calls lookup 1 (SingleSubst 2 -> 3) + * at sequence index 1. */ +static void +test_depend_context_format6 (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/context-format6.ttf"); + hb_subset_depend_t *depend = hb_subset_depend_from_face_or_fail (face); + g_assert_nonnull (depend); + + g_assert_true (find_dependency (depend, 2, 3, HB_OT_TAG_GSUB, + NULL, NULL)); + + hb_subset_depend_destroy (depend); + hb_face_destroy (face); +} + int main (int argc, char **argv) { @@ -615,6 +632,7 @@ main (int argc, char **argv) hb_test_add (test_depend_math); hb_test_add (test_depend_varc); hb_test_add (test_depend_gsub_formats); + hb_test_add (test_depend_context_format6); return hb_test_run (); }