diff --git a/src/Makefile.sources b/src/Makefile.sources index 16473634e..a3fb92bac 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -352,6 +352,8 @@ HB_SUBSET_sources = \ graph/gsubgpos-context.hh \ graph/gsubgpos-context.cc \ graph/pairpos-graph.hh \ + graph/coverage-graph.hh \ + graph/pairpos-graph.hh \ graph/serialize.hh \ $(NULL) diff --git a/src/graph/coverage-graph.hh b/src/graph/coverage-graph.hh new file mode 100644 index 000000000..1d9fd0eb5 --- /dev/null +++ b/src/graph/coverage-graph.hh @@ -0,0 +1,80 @@ +/* + * Copyright © 2022 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 + */ + +#include "graph.hh" +#include "../OT/Layout/Common/Coverage.hh" + +#ifndef GRAPH_COVERAGE_GRAPH_HH +#define GRAPH_COVERAGE_GRAPH_HH + +namespace graph { + +struct CoverageFormat1 : public OT::Layout::Common::CoverageFormat1_3 +{ + bool sanitize (graph_t::vertex_t& vertex) const + { + int64_t vertex_len = vertex.obj.tail - vertex.obj.head; + constexpr unsigned min_size = OT::Layout::Common::CoverageFormat1_3::min_size; + if (vertex_len < min_size) return false; + return vertex_len >= min_size + glyphArray.get_size () - glyphArray.len.get_size (); + } +}; + +struct CoverageFormat2 : public OT::Layout::Common::CoverageFormat2_4 +{ + bool sanitize (graph_t::vertex_t& vertex) const + { + int64_t vertex_len = vertex.obj.tail - vertex.obj.head; + constexpr unsigned min_size = OT::Layout::Common::CoverageFormat2_4::min_size; + if (vertex_len < min_size) return false; + return vertex_len >= min_size + rangeRecord.get_size () - rangeRecord.len.get_size (); + } +}; + +struct Coverage : public OT::Layout::Common::Coverage +{ + bool sanitize (graph_t::vertex_t& vertex) const + { + int64_t vertex_len = vertex.obj.tail - vertex.obj.head; + if (vertex_len < OT::Layout::Common::Coverage::min_size) return false; + switch (u.format) + { + case 1: return ((CoverageFormat1*)this)->sanitize (vertex); + case 2: return ((CoverageFormat2*)this)->sanitize (vertex); +#ifndef HB_NO_BORING_EXPANSION + // Not currently supported + case 3: + case 4: +#endif + default: return false; + } + } +}; + + +} + +#endif // GRAPH_COVERAGE_GRAPH_HH diff --git a/src/graph/pairpos-graph.hh b/src/graph/pairpos-graph.hh index 7c905899f..429d84323 100644 --- a/src/graph/pairpos-graph.hh +++ b/src/graph/pairpos-graph.hh @@ -27,6 +27,7 @@ #ifndef GRAPH_PAIRPOS_GRAPH_HH #define GRAPH_PAIRPOS_GRAPH_HH +#include "coverage-graph.hh" #include "../OT/Layout/GPOS/PairPos.hh" #include "../OT/Layout/GPOS/PosLookupSubTable.hh" @@ -47,9 +48,13 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3 split_subtables (gsubgpos_graph_context_t& c, unsigned this_index) { hb_set_t visited; - const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat1_3::min_size; + + const unsigned coverage_id = c.graph.index_for_offset (this_index, &coverage); + const unsigned coverage_size = c.graph.vertices_[coverage_id].table_size (); + const unsigned base_size = OT::Layout::GPOS_impl::PairPosFormat1_3::min_size + + coverage_size; + unsigned accumulated = base_size; - // TODO: include coverage size hb_vector_t split_points; for (unsigned i = 0; i < pairSet.len; i++) { @@ -121,8 +126,10 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3sanitize (coverage_v)) + return false; auto new_coverage = + hb_zip (coverage_table->iter (), hb_range ()) @@ -167,8 +174,10 @@ struct PairPosFormat1 : public OT::Layout::GPOS_impl::PairPosFormat1_3sanitize (coverage_v)) + return false; auto new_coverage = + hb_zip (coverage_table->iter (), hb_range ()) diff --git a/src/harfbuzz-subset.cc b/src/harfbuzz-subset.cc index b6d722515..ae4907eb4 100644 --- a/src/harfbuzz-subset.cc +++ b/src/harfbuzz-subset.cc @@ -1,10 +1,10 @@ -#include "gsubgpos-context.cc" +#include "graph/gsubgpos-context.cc" #include "hb-aat-layout.cc" #include "hb-aat-map.cc" #include "hb-blob.cc" +#include "hb-buffer.cc" #include "hb-buffer-serialize.cc" #include "hb-buffer-verify.cc" -#include "hb-buffer.cc" #include "hb-common.cc" #include "hb-draw.cc" #include "hb-face.cc" @@ -23,15 +23,15 @@ #include "hb-ot-meta.cc" #include "hb-ot-metrics.cc" #include "hb-ot-name.cc" +#include "hb-ot-shape.cc" #include "hb-ot-shape-fallback.cc" #include "hb-ot-shape-normalize.cc" -#include "hb-ot-shape.cc" #include "hb-ot-shaper-arabic.cc" #include "hb-ot-shaper-default.cc" #include "hb-ot-shaper-hangul.cc" #include "hb-ot-shaper-hebrew.cc" -#include "hb-ot-shaper-indic-table.cc" #include "hb-ot-shaper-indic.cc" +#include "hb-ot-shaper-indic-table.cc" #include "hb-ot-shaper-khmer.cc" #include "hb-ot-shaper-myanmar.cc" #include "hb-ot-shaper-syllabic.cc" @@ -41,17 +41,17 @@ #include "hb-ot-tag.cc" #include "hb-ot-var.cc" #include "hb-set.cc" -#include "hb-shape-plan.cc" #include "hb-shape.cc" +#include "hb-shape-plan.cc" #include "hb-shaper.cc" #include "hb-static.cc" #include "hb-style.cc" -#include "hb-subset-cff-common.cc" +#include "hb-subset.cc" #include "hb-subset-cff1.cc" #include "hb-subset-cff2.cc" +#include "hb-subset-cff-common.cc" #include "hb-subset-input.cc" #include "hb-subset-plan.cc" #include "hb-subset-repacker.cc" -#include "hb-subset.cc" #include "hb-ucd.cc" #include "hb-unicode.cc" diff --git a/src/meson.build b/src/meson.build index 631b124b4..1f1105cae 100644 --- a/src/meson.build +++ b/src/meson.build @@ -346,6 +346,10 @@ hb_subset_sources = files( 'hb-subset-plan.hh', 'hb-subset-repacker.cc', 'graph/gsubgpos-context.cc', + 'graph/gsubgpos-context.hh', + 'graph/gsubgpos-graph.hh', + 'graph/pairpos-graph.hh', + 'graph/coverage-graph.hh', 'hb-subset.cc', 'hb-subset.hh', )