blob: b33b7aadc77fca3398b56bb32015afe9788f30d1 [file] [edit]
/*
* Copyright © 2025 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Garret Rieger
*/
#ifndef GRAPH_LIGATURE_GRAPH_HH
#define GRAPH_LIGATURE_GRAPH_HH
#include "graph.hh"
#include "../OT/Layout/GSUB/LigatureSubst.hh"
#include "../OT/Layout/GSUB/LigatureSubstFormat1.hh"
#include "../OT/Layout/GSUB/LigatureSet.hh"
#include "../hb-ot-dual.hh"
#include <algorithm>
#include <utility>
namespace graph {
struct LigatureSet : public OT::Layout::GSUB_impl::LigatureSet<SmallTypes>
{
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
{
size_t vertex_len = vertex.table_size ();
if (unlikely (vertex_len < OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size)) return Err(SANITIZE_FAILURE);
hb_barrier ();
size_t total_len = ligature.get_size() + OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size - ligature.len.get_size();
if (unlikely (vertex_len < total_len)) {
return Err(SANITIZE_FAILURE);
}
return Ok();
}
};
struct LigatureSubstFormat1 : public OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>
{
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
{
size_t vertex_len = vertex.table_size ();
unsigned min_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
if (unlikely (vertex_len < min_size)) return Err(SANITIZE_FAILURE);
hb_barrier ();
if (unlikely (vertex_len < min_size + ligatureSet.get_size() - ligatureSet.len.get_size()))
return Err(SANITIZE_FAILURE);
return Ok();
}
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
unsigned this_index)
{
// Finding the object id for a ligatureSet array index with index_for_offset() is O(n), so
// precompute the whole index -> object id map once (a single scan of this_index's links) to
// keep the analysis passes below O(n) overall instead of O(n^2).
TRY_ASSIGN (auto liga_set_ids, liga_set_index_to_object_id (c, this_index));
TRY_ASSIGN (auto split_points, compute_split_points(c, liga_set_ids));
if (!split_points)
return Ok(hb_vector_t<unsigned> ());
TRY_ASSIGN (unsigned total_ligas, total_number_ligas(c, liga_set_ids));
TRY_ASSIGN (hb_vector_t<unsigned> counts, liga_counts(c, liga_set_ids));
// The split edits LigatureSet vertices in place (move_children, compact_liga_set, shrink),
// which assumes one vertex per coverage entry. The subset serializer's pop_pack() dedup can
// link one LigatureSet from several entries of this subtable, so give each sharing entry its
// own copy before splitting, otherwise their ligatures are silently dropped. This runs after
// the analysis passes above: the deep copies share the same Ligatures and keep the same
// ligature.len, so the counts and split points are unchanged (and the map is now stale).
TRY (duplicate_shared_liga_sets(c, this_index));
TRY_ASSIGN (liga_set_ids, liga_set_index_to_object_id (c, this_index));
split_context_t split_context {
c,
this,
this_index,
total_ligas,
std::move (counts),
std::move (liga_set_ids),
0,
0,
};
// TODO: move_children () and coverage filtering still scan the source
// for each range; many short ranges can take quadratic time.
return actuate_subtable_split<split_context_t> (split_context, split_points);
}
private:
// Separate duplicate LigatureSet references within this subtable. The ligatureSet offsets
// start at min_size (coverage sits at position 2).
graph_result_t<void> duplicate_shared_liga_sets(gsubgpos_graph_context_t& c, unsigned this_index) const {
const unsigned base_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
return c.graph.unshare_duplicate_children (this_index, base_size);
}
// Maps each ligatureSet array index to its object id in one scan of this_index's links, so the
// analysis passes below don't each pay an O(n) index_for_offset() per entry (which is O(n^2)).
graph_result_t<hb_vector_t<unsigned>> liga_set_index_to_object_id(gsubgpos_graph_context_t& c, unsigned this_index) const {
hb_vector_t<unsigned> map;
if (!map.resize_exact(ligatureSet.len)) return Err(ALLOCATION_FAILURE);
for (unsigned i = 0; i < map.length; i++)
map[i] = HB_GRAPH_INVALID;
const unsigned base_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
for (const auto& l : c.graph.vertices_[this_index].obj ().real_links) {
if (l.position < base_size) continue;
unsigned array_index = (l.position - base_size) / SmallTypes::size;
if (unlikely (l.width != SmallTypes::size ||
(l.position - base_size) % SmallTypes::size ||
array_index >= map.length))
return Err(INVALID_ARGUMENT);
map[array_index] = l.objidx;
}
return map;
}
graph_result_t<unsigned> total_number_ligas(gsubgpos_graph_context_t& c, const hb_vector_t<unsigned>& liga_set_ids) const {
unsigned total = 0;
for (unsigned i = 0; i < ligatureSet.len; i++)
{
TRY_ASSIGN (auto liga_set, c.graph.as_table_from_index<LigatureSet, graph_t::Immutable>(liga_set_ids[i]));
total += liga_set.table->ligature.len;
}
return Ok(total);
}
graph_result_t<hb_vector_t<unsigned>> liga_counts(gsubgpos_graph_context_t& c, const hb_vector_t<unsigned>& liga_set_ids) const {
hb_vector_t<unsigned> result;
for (unsigned i = 0; i < ligatureSet.len; i++)
{
TRY_ASSIGN (auto liga_set, c.graph.as_table_from_index<LigatureSet, graph_t::Immutable>(liga_set_ids[i]));
result.push(!liga_set.table ? 0 : liga_set.table->ligature.len);
}
return graph_result_t<hb_vector_t<unsigned>>::from(std::move(result), ALLOCATION_FAILURE);
}
template <graph_t::vertex_mutability_t mutability>
graph_result_t<hb_vector_t<unsigned>> ligature_index_to_object_id(const graph_t::vertex_and_table_t<LigatureSet, mutability>& liga_set) const {
hb_vector_t<unsigned> map;
if (!map.resize_exact(liga_set.table->ligature.len)) return Err(ALLOCATION_FAILURE);
for (unsigned i = 0; i < map.length; i++) {
map[i] = HB_GRAPH_INVALID;
}
for (const auto& l : liga_set.vertex->obj ().real_links) {
if (l.position < 2) continue;
unsigned array_index = (l.position - 2) / SmallTypes::size;
if (unlikely (l.width != SmallTypes::size ||
(l.position - 2) % SmallTypes::size ||
array_index >= map.length))
return Err(INVALID_ARGUMENT);
map[array_index] = l.objidx;
}
return map;
}
graph_result_t<hb_vector_t<unsigned>> compute_split_points(gsubgpos_graph_context_t& c,
const hb_vector_t<unsigned>& liga_set_ids) const
{
// For ligature subst coverage is always packed last, and as a result is where an overflow
// will happen if there is one, so we can check the estimate length of the
// LigatureSubstFormat1 -> Coverage offset length which is the sum of all data in the
// retained sub graph except for the coverage table itself.
const unsigned base_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
unsigned accumulated = base_size;
unsigned ligature_index = 0;
hb_vector_t<unsigned> split_points;
for (unsigned i = 0; i < ligatureSet.len; i++)
{
accumulated += OT::HBUINT16::static_size; // for ligature set offset
accumulated += OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size; // for ligature set table
TRY_ASSIGN (auto liga_set, c.graph.as_table_from_index<LigatureSet, graph_t::Immutable>(liga_set_ids[i]));
// Finding the object id associated with an array index is O(n)
// so to avoid O(n^2), precompute the mapping by scanning through
// all links
TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set));
// Split points and liga_counts () must count the same offset slots,
// including null offsets.
for (unsigned j = 0; j < liga_set.table->ligature.len; j++, ligature_index++)
{
const unsigned liga_id = index_to_id[j];
if (liga_id == HB_GRAPH_INVALID) continue; // no outgoing link, ignore
const unsigned liga_size = c.graph.vertices_[liga_id].table_size ();
accumulated += OT::HBUINT16::static_size; // for ligature offset
accumulated += liga_size; // for the ligature table
if (accumulated >= (1 << 16))
{
split_points.push(ligature_index);
// We're going to split such that the current ligature will be in the new sub table.
// That means we'll have one ligature subst (base_base), one ligature set, and one liga table
accumulated = base_size + // for liga subst subtable
(OT::HBUINT16::static_size * 2) + // for liga set and liga offset
OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size + // for liga set subtable
liga_size; // for liga sub table
}
}
}
return split_points;
}
struct split_context_t
{
gsubgpos_graph_context_t& c;
LigatureSubstFormat1* thiz;
unsigned this_index;
unsigned original_count_;
hb_vector_t<unsigned> liga_counts;
hb_vector_t<unsigned> liga_set_ids;
unsigned first_set;
unsigned first_liga;
unsigned original_count ()
{
return original_count_;
}
graph_result_t<unsigned> clone_range (unsigned start, unsigned end)
{
// Ranges arrive in order. Advance past earlier sets once across all
// ranges, rather than scanning the complete counts array for each one.
while (first_set < liga_counts.length &&
first_liga + liga_counts[first_set] <= start)
first_liga += liga_counts[first_set++];
return thiz->clone_range (c, this_index, liga_counts, liga_set_ids,
first_set, first_liga, start, end);
}
graph_result_t<void> shrink (unsigned count)
{
return thiz->shrink (c, this_index, original_count(), liga_counts, liga_set_ids, count);
}
};
graph_result_t<hb_pair_t<unsigned, LigatureSet*>> new_liga_set(gsubgpos_graph_context_t& c, unsigned count) const {
unsigned prime_size = OT::Layout::GSUB_impl::LigatureSet<SmallTypes>::min_size
+ count * SmallTypes::size;
TRY_ASSIGN (unsigned prime_id, c.create_node (prime_size));
LigatureSet* prime = (LigatureSet*) c.graph.object (prime_id).head;
prime->ligature.len = count;
return Ok(hb_pair(prime_id, prime));
}
void clear_virtual_links (gsubgpos_graph_context_t& c, unsigned node_index) const
{
auto& v = c.graph.vertices_[node_index];
for (const auto& l : v.obj ().virtual_links)
{
auto& child = c.graph.vertices_[l.objidx];
child.remove_parent(node_index);
}
v.clear_virtual_links ();
}
graph_result_t<void> add_virtual_link(gsubgpos_graph_context_t& c, unsigned from, unsigned to) const {
if (unlikely (from >= c.graph.vertices_.length || to >= c.graph.vertices_.length)) return Err(OUT_OF_BOUNDS);
TRY(c.graph.vertices_[to].add_parent (from, true));
TRY(c.graph.vertices_[from].add_virtual_link (to));
return Ok();
}
hb_pair_t<unsigned, unsigned> current_liga_set_bounds (gsubgpos_graph_context_t& c,
unsigned liga_set_index,
const hb_serialize_context_t::object_t& liga_set) const
{
// Finds the actual liga indices present in the liga set currently. Takes
// into account those that have been removed by processing.
unsigned min_index = HB_GRAPH_INVALID;
unsigned max_index = 0;
for (const auto& l : liga_set.real_links) {
if (l.position < 2) continue;
unsigned liga_index = (l.position - 2) / 2;
min_index = hb_min(min_index, liga_index);
max_index = hb_max(max_index, liga_index);
}
return hb_pair(min_index, max_index + 1);
}
void compact_liga_set (gsubgpos_graph_context_t& c, LigatureSet* table, graph_t::vertex_t* v) const
{
const auto& obj = v->obj ();
if (table->ligature.len <= obj.real_links.length) return;
// compact the remaining linked liga offsets into a continous array and shrink the node as needed.
unsigned to_remove = table->ligature.len - obj.real_links.length;
unsigned new_position = SmallTypes::size;
v->sort_real_links (); // for this to work we need to process links in order of position.
for (auto& l : v->real_links_writer ())
{
l.position = new_position;
new_position += SmallTypes::size;
}
table->ligature.len = obj.real_links.length;
v->shrink_buffer (to_remove * SmallTypes::size);
}
graph_result_t<unsigned> clone_range (gsubgpos_graph_context_t& c,
unsigned this_index,
const hb_vector_t<unsigned>& liga_counts,
hb_vector_t<unsigned>& liga_set_ids,
unsigned first_set, unsigned first_liga,
unsigned start, unsigned end) const
{
DEBUG_MSG (SUBSET_REPACK, nullptr,
" Cloning LigatureSubstFormat1 (%u) range [%u, %u).", this_index, start, end);
// Each emitted set contains at least one offset slot in [start, end).
// Bound the capacity by this range, so many short ranges do not each
// allocate the original subtable's entire offset array.
unsigned capacity = hb_min ((unsigned) ligatureSet.len, end - start);
unsigned prime_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size
+ capacity * SmallTypes::size;
TRY_ASSIGN (unsigned liga_subst_prime_id, c.create_node (prime_size));
LigatureSubstFormat1* liga_subst_prime = (LigatureSubstFormat1*) c.graph.object (liga_subst_prime_id).head;
liga_subst_prime->format = this->format;
liga_subst_prime->ligatureSet.len = capacity;
// Create a place holder coverage prime id since we need to add virtual links to it while
// generating liga and liga sets. Afterwards it will be updated to have the correct coverage.
TRY_ASSIGN (unsigned coverage_id, c.graph.index_for_offset (this_index, &coverage));
TRY_ASSIGN (unsigned coverage_prime_id, c.graph.duplicate(coverage_id));
auto& coverage_prime_vertex = c.graph.vertices_[coverage_prime_id];
TRY(c.graph.vertices_[liga_subst_prime_id].add_real_link (SmallTypes::size, coverage_prime_id, 2));
TRY(coverage_prime_vertex.add_parent (liga_subst_prime_id, false));
// Locate all liga sets with ligas between start and end.
// Clone or move them as needed.
unsigned count = first_liga;
unsigned liga_set_count = 0;
unsigned liga_set_start = HB_GRAPH_INVALID;
unsigned liga_set_end = 0; // inclusive
unsigned moved_end = 0; // liga sets before this one have already been moved to the new liga subst.
for (unsigned i = first_set; i < liga_counts.length && count < end; i++)
{
unsigned num_ligas = liga_counts[i];
unsigned current_start = count;
unsigned current_end = count + num_ligas;
if (current_start >= end || start >= current_end) {
// No intersection, so just skip
count += num_ligas;
continue;
}
if (i >= moved_end && current_start >= start && current_end <= end) {
// Move the whole run of liga sets fully contained within [start, end) at once.
// Moving (and looking them up) one at a time is O(n) each because move_child and
// as_mutable_table scan this_index's links, so per-offset handling is O(n^2); one
// move_children() over the run keeps the whole clone_range linear.
unsigned run_end = current_end;
moved_end = i + 1;
while (moved_end < liga_counts.length &&
run_end < end && run_end + liga_counts[moved_end] <= end)
run_end += liga_counts[moved_end++];
const unsigned base_size = OT::Layout::GSUB_impl::LigatureSubstFormat1_2<SmallTypes>::min_size;
TRY (c.graph.move_children<OT::Offset16>(
this_index,
base_size + i * SmallTypes::size,
base_size + moved_end * SmallTypes::size,
liga_subst_prime_id,
base_size + liga_set_count * SmallTypes::size));
}
// Moving a run does not change its object ids. Avoid rescanning either parent's
// links for each set, while still copying sets shared with other parents before mutation.
bool moved = i < moved_end;
TRY_ASSIGN (unsigned mutable_id, c.graph.mutable_index_for_child (
moved ? liga_subst_prime_id : this_index, liga_set_ids[i]));
if (!moved) liga_set_ids[i] = mutable_id;
TRY_ASSIGN (auto liga_set, c.graph.as_table_from_index<LigatureSet> (mutable_id));
unsigned liga_set_index = liga_set.index;
// Bounds may need to be adjusted if some ligas have been previously removed.
hb_pair_t<unsigned, unsigned> liga_bounds = current_liga_set_bounds(c, liga_set_index, liga_set.vertex->obj ());
current_start = hb_max(count + liga_bounds.first, current_start);
current_end = hb_min(count + liga_bounds.second, current_end);
unsigned liga_set_prime_id;
if (moved || (current_start >= start && current_end <= end)) {
// This liga set is fully contined within [start, end)
// We can move the entire ligaset to the new liga subset object (if not done already).
liga_set_end = i;
if (i < liga_set_start) liga_set_start = i;
liga_set_prime_id = liga_set_index;
if (!moved)
TRY (c.graph.move_child<> (this_index,
&ligatureSet[i],
liga_subst_prime_id,
&liga_subst_prime->ligatureSet[liga_set_count]));
liga_set_count++;
compact_liga_set (c, liga_set.table, liga_set.vertex);
}
else
{
// This liga set partially overlaps [start, end). We'll need to create
// a new liga set sub table and move the intersecting ligas to it.
unsigned start_index = hb_max(start, current_start) - count;
unsigned end_index = hb_min(end, current_end) - count;
// Narrowing to the remaining links may leave an inverted range.
if (unlikely (end_index < start_index))
return Err(INVALID_ARGUMENT);
unsigned liga_count = end_index - start_index;
TRY_ASSIGN (auto result, new_liga_set(c, liga_count));
liga_set_prime_id = result.first;
TRY (c.graph.move_children<OT::Offset16>(
liga_set_index,
2 + start_index * 2,
2 + end_index * 2,
liga_set_prime_id,
2));
liga_set_end = i;
if (i < liga_set_start) liga_set_start = i;
TRY (c.graph.add_link(&liga_subst_prime->ligatureSet[liga_set_count++], liga_subst_prime_id, liga_set_prime_id));
}
// The new liga and all children set needs to have a virtual link to the new coverage table:
const auto& liga_set_prime = c.graph.vertices_[liga_set_prime_id].obj ();
clear_virtual_links(c, liga_set_prime_id);
TRY(add_virtual_link(c, liga_set_prime_id, coverage_prime_id));
for (const auto& l : liga_set_prime.real_links) {
clear_virtual_links(c, l.objidx);
TRY(add_virtual_link(c, l.objidx, coverage_prime_id));
}
count += num_ligas;
}
// move_child () removes links unordered, so a later moved run can arrive
// out of position order. Keep shortest-distance tie breaking deterministic.
c.graph.vertices_[liga_subst_prime_id].sort_real_links ();
c.graph.vertices_[liga_subst_prime_id].shrink_buffer ((liga_subst_prime->ligatureSet.len - liga_set_count) * SmallTypes::size);
liga_subst_prime->ligatureSet.len = liga_set_count;
TRY (Coverage::filter_coverage (c,
coverage_prime_id,
liga_set_start, liga_set_end + 1));
return Ok(liga_subst_prime_id);
}
graph_result_t<void> shrink (gsubgpos_graph_context_t& c,
unsigned this_index,
unsigned old_count,
const hb_vector_t<unsigned>& liga_counts,
const hb_vector_t<unsigned>& liga_set_ids,
unsigned count)
{
DEBUG_MSG (SUBSET_REPACK, nullptr,
" Shrinking LigatureSubstFormat1 (%u) to [0, %u).",
this_index,
count);
if (count >= old_count)
return Ok();
hb_set_t retained_indices;
unsigned new_liga_set_count = 0;
for (unsigned i = 0; i < liga_counts.length; i++)
{
TRY_ASSIGN (unsigned mutable_id, c.graph.mutable_index_for_child (this_index, liga_set_ids[i]));
TRY_ASSIGN (auto liga_set, c.graph.as_table_from_index<LigatureSet> (mutable_id));
// We need the virtual links to coverage removed from all descendants on this liga subst.
// If any are left when we try to mutate the coverage table later it will be unnessecarily
// duplicated. Code later on will re-add the virtual links as needed (via retained_indices).
clear_virtual_links(c, liga_set.index);
retained_indices.add(liga_set.index);
TRY_ASSIGN (auto index_to_id, ligature_index_to_object_id (liga_set));
for (unsigned i = 0; i < liga_set.table->ligature.len; i++) {
unsigned liga_index = index_to_id[i];
if (liga_index != HB_GRAPH_INVALID) {
clear_virtual_links(c, liga_index);
retained_indices.add(liga_index);
}
}
unsigned num_ligas = liga_counts[i];
if (num_ligas >= count) {
// drop the trailing liga's from this set and all subsequent liga sets
unsigned num_ligas_to_remove = num_ligas - count;
new_liga_set_count = i + 1;
c.graph.vertices_[liga_set.index].shrink_buffer (num_ligas_to_remove * SmallTypes::size);
liga_set.table->ligature.len = count;
break;
} else {
count -= num_ligas;
}
}
// Adjust liga set array
auto& this_vertex = c.graph.vertices_[this_index];
this_vertex.shrink_buffer ((ligatureSet.len - new_liga_set_count) * SmallTypes::size);
ligatureSet.len = new_liga_set_count;
// Coverage matches the number of liga sets so rebuild as needed
TRY_ASSIGN (unsigned coverage_idx, c.graph.index_for_offset (this_index, &this->coverage));
auto& coverage_v = c.graph.vertices_[coverage_idx];
unsigned coverage_size = coverage_v.table_size ();
const Coverage* coverage_table = (const Coverage*) coverage_v.obj ().head;
if (coverage_v.is_shared ())
{
TRY_ASSIGN (coverage_idx, c.graph.remap_child (this_index, coverage_idx));
}
for (unsigned i : retained_indices.iter())
TRY(add_virtual_link(c, i, coverage_idx));
auto new_coverage =
+ hb_zip (coverage_table->iter (), hb_range ())
| hb_filter ([&] (hb_pair_t<unsigned, unsigned> p) {
return p.second < new_liga_set_count;
})
| hb_map_retains_sorting (hb_first)
;
return Coverage::make_coverage (c, new_coverage, coverage_idx, coverage_size);
}
};
struct LigatureSubst : public OT::Layout::GSUB_impl::LigatureSubst
{
graph_result_t<hb_vector_t<unsigned>> split_subtables (gsubgpos_graph_context_t& c,
unsigned this_index)
{
switch (u.format.v) {
case 1:
hb_barrier ();
return ((LigatureSubstFormat1*)(&u.format1))->split_subtables (c, this_index);
#ifndef HB_NO_BEYOND_64K
case 2: HB_FALLTHROUGH;
// 24-bit LigatureSubst already has widened offsets; leave it unsplit.
#endif
default:
return Ok(hb_vector_t<unsigned> ());
}
}
graph_result_t<void> sanitize (const graph_t::vertex_t& vertex) const
{
size_t vertex_len = vertex.table_size ();
if (unlikely (vertex_len < u.format.v.get_size ())) return Err(SANITIZE_FAILURE);
hb_barrier ();
switch (u.format.v) {
case 1:
hb_barrier ();
return ((LigatureSubstFormat1*)(&u.format1))->sanitize (vertex);
#ifndef HB_NO_BEYOND_64K
case 2: HB_FALLTHROUGH;
#endif
default:
// We don't handle format 2 here.
return Err(SANITIZE_FAILURE);
}
}
};
}
#endif // GRAPH_LIGATURE_GRAPH_HH