[repack] Add add_link helper to graph.

This commit is contained in:
Garret Rieger 2022-08-11 20:33:21 +00:00
parent 1acd2a8bf9
commit b00eb77682
2 changed files with 19 additions and 16 deletions

View File

@ -240,6 +240,22 @@ struct graph_t
return vertices_[i].obj;
}
/*
* Adds a 16 bit link from parent_id to child_id
*/
template<typename T>
void add_link (T* offset,
unsigned parent_id,
unsigned child_id)
{
auto& v = vertices_[parent_id];
auto* link = v.obj.real_links.push ();
link->width = 2;
link->objidx = child_id;
link->position = (char*) offset - (char*) v.obj.head;
vertices_[child_id].parents.push (parent_id);
}
/*
* Generates a new topological sorting of graph ordered by the shortest
* distance to each node if positions are marked as invalid.

View File

@ -271,11 +271,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
unsigned base_coverage_id =
graph.index_for_offset (sc.this_index, &baseCoverage);
auto* base_coverage_link = graph.vertices_[prime_id].obj.real_links.push ();
base_coverage_link->width = SmallTypes::size;
base_coverage_link->objidx = base_coverage_id;
base_coverage_link->position = 4;
graph.vertices_[base_coverage_id].parents.push (prime_id);
graph.add_link (&(prime->baseCoverage), prime_id, base_coverage_id);
graph.duplicate (prime_id, base_coverage_id);
hb_set_t marks;
@ -302,12 +298,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
mark_array_id,
sc.mark_array_links,
marks);
auto* mark_array_link = graph.vertices_[prime_id].obj.real_links.push ();
mark_array_link->width = SmallTypes::size;
mark_array_link->objidx = new_mark_array;
mark_array_link->position = 8;
graph.vertices_[new_mark_array].parents.push (prime_id);
graph.add_link (&(prime->markArray), prime_id, new_mark_array);
unsigned base_array_id =
graph.index_for_offset (sc.this_index, &baseArray);
@ -318,11 +309,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
mark_array_id,
sc.base_array_links,
start, end);
auto* base_array_link = graph.vertices_[prime_id].obj.real_links.push ();
base_array_link->width = SmallTypes::size;
base_array_link->objidx = new_base_array;
base_array_link->position = 10;
graph.vertices_[new_base_array].parents.push (prime_id);
graph.add_link (&(prime->baseArray), prime_id, new_base_array);
return prime_id;
}