[repacker] Hook up MarkBasePos splitting.

This commit is contained in:
Garret Rieger 2022-08-11 19:26:59 +00:00
parent 4418beac93
commit cf817f3d99
2 changed files with 39 additions and 25 deletions

View File

@ -29,6 +29,7 @@
#include "../OT/Layout/GSUB/ExtensionSubst.hh"
#include "gsubgpos-context.hh"
#include "pairpos-graph.hh"
#include "markbasepos-graph.hh"
#ifndef GRAPH_GSUBGPOS_GRAPH_HH
#define GRAPH_GSUBGPOS_GRAPH_HH
@ -142,11 +143,18 @@ struct Lookup : public OT::Lookup
continue;
}
PairPos* pairPos = (PairPos*) c.graph.object (subtable_index).head;
if (!pairPos || !pairPos->sanitize (c.graph.vertices_[subtable_index])) continue;
hb_vector_t<unsigned> new_sub_tables = pairPos->split_subtables (c, subtable_index);
hb_vector_t<unsigned> new_sub_tables;
switch (type)
{
case 2:
new_sub_tables = split_subtable<PairPos> (c, subtable_index); break;
case 4:
new_sub_tables = split_subtable<MarkBasePos> (c, subtable_index); break;
default:
break;
}
if (new_sub_tables.in_error ()) return false;
if (!new_sub_tables) continue;
hb_pair_t<unsigned, hb_vector_t<unsigned>>* entry = all_new_subtables.push ();
entry->first = i;
entry->second = std::move (new_sub_tables);
@ -159,6 +167,17 @@ struct Lookup : public OT::Lookup
return true;
}
template<typename T>
hb_vector_t<unsigned> split_subtable (gsubgpos_graph_context_t& c,
unsigned objidx)
{
T* sub_table = (T*) c.graph.object (objidx).head;
if (!sub_table || !sub_table->sanitize (c.graph.vertices_[objidx]))
return hb_vector_t<unsigned> ();
return sub_table->split_subtables (c, objidx);
}
void add_sub_tables (gsubgpos_graph_context_t& c,
unsigned this_index,
unsigned type,

View File

@ -68,9 +68,6 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
{
hb_set_t visited;
const unsigned coverage_id = c.graph.index_for_offset (this_index, &markCoverage);
const unsigned coverage_size = c.graph.vertices_[coverage_id].table_size ();
const unsigned base_coverage_id = c.graph.index_for_offset (this_index, &baseCoverage);
const unsigned base_size =
OT::Layout::GPOS_impl::PairPosFormat1_3<SmallTypes>::min_size +
@ -87,6 +84,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
class_info_t& info = class_to_info[klass];
partial_coverage_size += OT::HBUINT16::static_size * info.num_marks;
unsigned accumulated_delta = OT::Layout::GPOS_impl::MarkRecord::static_size * info.num_marks;
// TODO this doesn't count up null offsets.
accumulated_delta += OT::Offset16::static_size * info.child_indices.length;
for (unsigned objidx : info.child_indices)
accumulated_delta += c.graph.find_subgraph_size (objidx, visited);
@ -121,7 +119,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
unsigned original_count ()
{
return thiz->pairSet.len;
return thiz->classCount;
}
unsigned clone_range (unsigned start, unsigned end)
@ -146,41 +144,38 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2<S
hb_vector_t<class_info_t> class_to_info;
unsigned class_count= classCount;
class_to_size.resize (class_count);
class_to_info.resize (class_count);
unsigned mark_array_id =
c.graph.index_for_offset (this_index, &markArray);
auto& mark_array_v = graph.vertices_[coverage_id];
MarkArray* mark_array = (MarkArray*) mark_array_v.head;
auto& mark_array_v = c.graph.vertices_[mark_array_id];
MarkArray* mark_array = (MarkArray*) mark_array_v.obj.head;
// TODO sanitize
unsigned mark_count = mark_array->length;
unsigned mark_count = mark_array->len;
for (unsigned mark = 0; mark < mark_count; mark++)
{
unsigned klass = (*mark_array)[mark].klass;
class_to_size[klass].num_marks++;
unsigned klass = (*mark_array)[mark].get_class ();
class_to_info[klass].num_marks++;
}
for (const auto* link : mark_array_v.obj.real_links)
for (const auto& link : mark_array_v.obj.real_links)
{
unsiged mark = (link->position - 2) /
OT::Layout::GPOS_impl::MarkReecord::static_size;
unsigned klass = (*mark_array)[mark].klass;
unsigned mark = (link.position - 2) /
OT::Layout::GPOS_impl::MarkRecord::static_size;
unsigned klass = (*mark_array)[mark].get_class ();
class_to_info[klass].child_indices.push (link.objidx);
}
unsigned base_array_id =
c.graph.index_for_offset (this_index, &baseArray);
auto& base_array_v = graph.vertices_[coverage_id];
AnchorMatrix* base_array = (AnchorMatrix*) base_array_v.head;
// TODO sanitize
auto& base_array_v = c.graph.vertices_[base_array_id];
unsigned base_count = base_array->rows;
for (const auto* link : base_array_v.obj.real_links)
for (const auto& link : base_array_v.obj.real_links)
{
unsigned index = (link->position - 2) / OT::Offset16::static_size;
unsigned index = (link.position - 2) / OT::Offset16::static_size;
unsigned klass = index % class_count;
class_to_info[klass].child_indices.push (link->objidx);
class_to_info[klass].child_indices.push (link.objidx);
}
return class_to_info;