mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 01:11:25 +01:00
[repacker] Handle extended layout graphs
Discover GSUB/GPOS 1.2 lookups through LookupList2 and treat the 32-bit lookup-list link like other wide graph roots. Also preserve parent multiplicity when identical lookup subtables are promoted to a shared extension wrapper. Add coverage for 1.2 extension promotion and repeated subtable links. Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
1 parent
6b231378b0
commit
5b104f8afe
3 files changed
+139
-21
No files matched your search
+5
-5
@@ -828,12 +828,12 @@ public:
|
||||
// pointer to the lookup list.
|
||||
continue;
|
||||
|
||||
if (l.width == 3)
|
||||
if (l.width >= 3)
|
||||
{
|
||||
// A 24bit offset forms a root, unless there is 32bit offsets somewhere
|
||||
// in it's subgraph, then those become the roots instead. This is to make sure
|
||||
// that extension subtables beneath a 24bit lookup become the spaces instead
|
||||
// of the offset to the lookup.
|
||||
// A wide offset forms a root, unless there are 32-bit offsets somewhere
|
||||
// in its subgraph, then those become the roots instead. This is to make sure
|
||||
// that extension subtables beneath a 24-bit lookup and lookups beneath a
|
||||
// 32-bit lookup list become the spaces instead of their enclosing lists.
|
||||
hb_set_t sub_roots;
|
||||
TRY (find_32bit_roots (l.objidx, sub_roots));
|
||||
if (sub_roots) {
|
||||
|
||||
+23
-13
@@ -112,13 +112,21 @@ struct Lookup : public OT::Lookup
|
||||
type,
|
||||
this_index);
|
||||
|
||||
hb_set_t seen;
|
||||
hb_vector_t<unsigned> subtables;
|
||||
for (unsigned i = 0; i < subTable.len; i++)
|
||||
{
|
||||
TRY_ASSIGN (unsigned subtable_index, c.graph.index_for_offset (this_index, &subTable[i]));
|
||||
TRY (make_subtable_extension (c,
|
||||
this_index,
|
||||
subtable_index));
|
||||
if (seen.has (subtable_index))
|
||||
continue;
|
||||
seen.add (subtable_index);
|
||||
subtables.push (subtable_index);
|
||||
}
|
||||
TRY (graph_result_t<void>::from (seen, ALLOCATION_FAILURE));
|
||||
TRY (graph_result_t<void>::from (subtables, ALLOCATION_FAILURE));
|
||||
|
||||
for (unsigned subtable_index : subtables)
|
||||
TRY (make_subtable_extension (c, this_index, subtable_index));
|
||||
|
||||
lookupType = ext_type;
|
||||
return Ok();
|
||||
@@ -348,21 +356,25 @@ struct Lookup : public OT::Lookup
|
||||
|
||||
auto& subtable_vertex = c.graph.vertices_[subtable_index];
|
||||
auto& lookup_vertex = c.graph.vertices_[lookup_index];
|
||||
unsigned replaced = 0;
|
||||
for (auto& l : lookup_vertex.real_links_writer ())
|
||||
{
|
||||
if (l.objidx == subtable_index) {
|
||||
// Change lookup to point at the extension.
|
||||
l.objidx = ext_index;
|
||||
if (existing_ext_index)
|
||||
subtable_vertex.remove_parent(lookup_index);
|
||||
replaced++;
|
||||
}
|
||||
}
|
||||
|
||||
// Make extension point at the subtable.
|
||||
auto& ext_vertex = c.graph.vertices_[ext_index];
|
||||
TRY(ext_vertex.add_parent (lookup_index, false));
|
||||
for (unsigned i = 0; i < replaced; i++)
|
||||
{
|
||||
subtable_vertex.remove_parent (lookup_index);
|
||||
TRY(ext_vertex.add_parent (lookup_index, false));
|
||||
}
|
||||
if (!existing_ext_index)
|
||||
TRY(subtable_vertex.remap_parent (lookup_index, ext_index));
|
||||
TRY(subtable_vertex.add_parent (ext_index, false));
|
||||
|
||||
return Ok();
|
||||
}
|
||||
@@ -437,15 +449,16 @@ struct GSTAR : public OT::GSUBGPOS
|
||||
graph_result_t<void> find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */) const
|
||||
{
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
if (version.to_int () >= 0x00010002u && lookupList2)
|
||||
return find_lookups<MediumTypes> (graph, lookups);
|
||||
#endif
|
||||
TRY(find_lookups<SmallTypes> (graph, lookups));
|
||||
return Ok();
|
||||
}
|
||||
|
||||
graph_result_t<unsigned> get_lookup_list_index (graph_t& graph) const
|
||||
{
|
||||
if (version.to_int () >= 0x00010002u)
|
||||
return Err(INVALID_ARGUMENT);
|
||||
|
||||
const void* offset = get_lookup_list_field_offset ();
|
||||
if (unlikely (!offset)) return Err(INVALID_ARGUMENT);
|
||||
return graph.index_for_offset (graph.root_idx (), offset);
|
||||
@@ -455,9 +468,6 @@ struct GSTAR : public OT::GSUBGPOS
|
||||
graph_result_t<void> find_lookups (graph_t& graph,
|
||||
hb_hashmap_t<unsigned, Lookup*>& lookups /* OUT */) const
|
||||
{
|
||||
if (version.to_int () >= 0x00010002u)
|
||||
return Ok();
|
||||
|
||||
TRY_ASSIGN (unsigned lookup_list_idx, get_lookup_list_index (graph));
|
||||
const LookupList<Types>* lookupList =
|
||||
(const LookupList<Types>*) graph.object (lookup_list_idx).head;
|
||||
|
||||
+111
-3
@@ -96,6 +96,24 @@ static void add_gsubgpos_header (unsigned lookup_list,
|
||||
c->pop_pack (false);
|
||||
}
|
||||
|
||||
static void add_gsubgpos_header_1_2 (unsigned lookup_list,
|
||||
hb_serialize_context_t* c)
|
||||
{
|
||||
char header[] = {
|
||||
0, 1, 0, 2, // version
|
||||
0, 0, // script list
|
||||
0, 0, // feature list
|
||||
0, 0, // lookup list
|
||||
0, 0, 0, 0, // feature variations
|
||||
0, 0, 0, 0, // script list 2
|
||||
0, 0, 0, 0, // feature list 2
|
||||
};
|
||||
|
||||
start_object (header, sizeof (header), c);
|
||||
add_wide_offset (lookup_list, c);
|
||||
c->pop_pack (false);
|
||||
}
|
||||
|
||||
static unsigned add_lookup_list (const unsigned* lookups,
|
||||
char count,
|
||||
hb_serialize_context_t* c)
|
||||
@@ -109,6 +127,19 @@ static unsigned add_lookup_list (const unsigned* lookups,
|
||||
return c->pop_pack (false);
|
||||
}
|
||||
|
||||
static unsigned add_lookup_list_1_2 (const unsigned* lookups,
|
||||
char count,
|
||||
hb_serialize_context_t* c)
|
||||
{
|
||||
char lookup_count[] = {0, count};
|
||||
start_object ((char *) &lookup_count, 2, c);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
add_wide_offset (lookups[i], c);
|
||||
|
||||
return c->pop_pack (false);
|
||||
}
|
||||
|
||||
static void start_lookup (int8_t type,
|
||||
int8_t num_subtables,
|
||||
hb_serialize_context_t* c)
|
||||
@@ -1411,7 +1442,8 @@ populate_serializer_with_24_and_32_bit_offsets (hb_serialize_context_t* c)
|
||||
static void
|
||||
populate_serializer_with_extension_promotion (hb_serialize_context_t* c,
|
||||
int num_extensions = 0,
|
||||
bool shared_subtables = false)
|
||||
bool shared_subtables = false,
|
||||
bool version_1_2 = false)
|
||||
{
|
||||
constexpr int num_lookups = 5;
|
||||
constexpr int num_subtables = num_lookups * 2;
|
||||
@@ -1458,9 +1490,14 @@ populate_serializer_with_extension_promotion (hb_serialize_context_t* c,
|
||||
lookups[i] = finish_lookup (c);
|
||||
}
|
||||
|
||||
unsigned lookup_list = add_lookup_list (lookups, num_lookups, c);
|
||||
unsigned lookup_list = version_1_2
|
||||
? add_lookup_list_1_2 (lookups, num_lookups, c)
|
||||
: add_lookup_list (lookups, num_lookups, c);
|
||||
|
||||
add_gsubgpos_header (lookup_list, c);
|
||||
if (version_1_2)
|
||||
add_gsubgpos_header_1_2 (lookup_list, c);
|
||||
else
|
||||
add_gsubgpos_header (lookup_list, c);
|
||||
|
||||
c->end_serialize();
|
||||
}
|
||||
@@ -2311,6 +2348,73 @@ static void test_resolve_with_shared_extension_promotion ()
|
||||
free (expected_buffer);
|
||||
}
|
||||
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
static void test_resolve_with_extension_promotion_1_2 ()
|
||||
{
|
||||
size_t buffer_size = 200000;
|
||||
void* buffer = malloc (buffer_size);
|
||||
hb_always_assert (buffer);
|
||||
hb_serialize_context_t c (buffer, buffer_size);
|
||||
populate_serializer_with_extension_promotion (&c, 0, false, true);
|
||||
|
||||
void* expected_buffer = malloc (buffer_size);
|
||||
hb_always_assert (expected_buffer);
|
||||
hb_serialize_context_t e (expected_buffer, buffer_size);
|
||||
populate_serializer_with_extension_promotion (&e, 3, false, true);
|
||||
|
||||
run_resolve_overflow_test ("test_resolve_with_extension_promotion_1_2",
|
||||
c,
|
||||
e,
|
||||
20,
|
||||
true);
|
||||
free (buffer);
|
||||
free (expected_buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_resolve_with_repeated_extension_promotion ()
|
||||
{
|
||||
size_t buffer_size = 1000;
|
||||
void* buffer = malloc (buffer_size);
|
||||
hb_always_assert (buffer);
|
||||
hb_serialize_context_t c (buffer, buffer_size);
|
||||
|
||||
c.start_serialize<char> ();
|
||||
unsigned subtable = add_object ("subt", 4, &c);
|
||||
start_lookup (5, 2, &c);
|
||||
add_offset (subtable, &c);
|
||||
add_offset (subtable, &c);
|
||||
unsigned lookup = finish_lookup (&c);
|
||||
unsigned lookup_list = add_lookup_list (&lookup, 1, &c);
|
||||
add_gsubgpos_header (lookup_list, &c);
|
||||
c.end_serialize ();
|
||||
|
||||
graph_t graph = graph_t::create (c.object_graph ()).value ();
|
||||
auto context = graph::gsubgpos_graph_context_t::create (HB_TAG ('G', 'S', 'U', 'B'),
|
||||
graph).value ();
|
||||
hb_always_assert (context.lookups.get_population () == 1);
|
||||
unsigned lookup_index = *context.lookups.keys ();
|
||||
graph::Lookup* lookup_table = context.lookups.get (lookup_index);
|
||||
hb_always_assert (lookup_table->make_extension (context, lookup_index).is_ok ());
|
||||
|
||||
const auto& lookup_vertex = graph.vertices_[lookup_index];
|
||||
hb_always_assert (lookup_vertex.obj ().real_links.length == 2);
|
||||
unsigned extension_index = lookup_vertex.obj ().real_links[0].objidx;
|
||||
hb_always_assert (lookup_vertex.obj ().real_links[1].objidx == extension_index);
|
||||
|
||||
auto* extension = graph.vertices_[extension_index].as<
|
||||
graph::ExtensionFormat1<OT::Layout::GSUB_impl::ExtensionSubst>*> ();
|
||||
unsigned promoted_subtable = extension->get_subtable_index (graph, extension_index).value ();
|
||||
hb_always_assert (graph.vertices_[promoted_subtable].table_size () == 4);
|
||||
hb_always_assert (graph.update_parents ().is_ok ());
|
||||
hb_always_assert (graph.vertices_[extension_index].incoming_edges () == 2);
|
||||
hb_always_assert (graph.vertices_[promoted_subtable].incoming_edges () == 1);
|
||||
|
||||
hb_blob_t* out = graph::serialize (graph).value ();
|
||||
hb_blob_destroy (out);
|
||||
free (buffer);
|
||||
}
|
||||
|
||||
static void test_resolve_with_basic_pair_pos_1_split ()
|
||||
{
|
||||
size_t buffer_size = 200000;
|
||||
@@ -2923,6 +3027,10 @@ main (int argc, char **argv)
|
||||
test_shared_node_with_virtual_links ();
|
||||
test_resolve_with_extension_promotion ();
|
||||
test_resolve_with_shared_extension_promotion ();
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
test_resolve_with_extension_promotion_1_2 ();
|
||||
#endif
|
||||
test_resolve_with_repeated_extension_promotion ();
|
||||
test_resolve_with_basic_pair_pos_1_split ();
|
||||
test_resolve_with_extension_pair_pos_1_split ();
|
||||
test_resolve_with_basic_pair_pos_2_split ();
|
||||
|
||||
Reference in new issue
Block a user