diff --git a/src/OT/Layout/GPOS/AnchorMatrix.hh b/src/OT/Layout/GPOS/AnchorMatrix.hh index 7e676371f..939442046 100644 --- a/src/OT/Layout/GPOS/AnchorMatrix.hh +++ b/src/OT/Layout/GPOS/AnchorMatrix.hh @@ -5,14 +5,15 @@ namespace OT { namespace Layout { namespace GPOS_impl { +template struct AnchorMatrix { - HBUINT16 rows; /* Number of rows */ - UnsizedArrayOf> + RowCount rows; /* Number of rows */ + UnsizedArrayOf> matrixZ; /* Matrix of offsets to Anchor tables-- * from beginning of AnchorMatrix table */ public: - DEFINE_SIZE_ARRAY (2, matrixZ); + DEFINE_SIZE_ARRAY (sizeof (RowCount), matrixZ); bool sanitize (hb_sanitize_context_t *c, unsigned int cols) const { diff --git a/src/OT/Layout/GPOS/LigatureArray.hh b/src/OT/Layout/GPOS/LigatureArray.hh index fd1312246..0630b5b00 100644 --- a/src/OT/Layout/GPOS/LigatureArray.hh +++ b/src/OT/Layout/GPOS/LigatureArray.hh @@ -6,14 +6,30 @@ namespace Layout { namespace GPOS_impl { -typedef AnchorMatrix LigatureAttach; /* component-major-- - * in order of writing direction--, - * mark-minor-- - * ordered by class--zero-based. */ - /* Array of LigatureAttach tables ordered by LigatureCoverage Index */ -struct LigatureArray : List16OfOffset16To +template +struct LigatureArray : + Types::template ArrayOf>> { + typedef AnchorMatrix LigatureAttach; + typedef typename Types::template OffsetTo LigatureAttachOffset; + typedef typename Types::template ArrayOf Super; + + const LigatureAttach& operator [] (int i_) const + { + unsigned int i = (unsigned int) i_; + if (unlikely (i >= this->len)) return Null (LigatureAttach); + hb_barrier (); + return this+this->arrayZ[i]; + } + + template + bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const + { + TRACE_SANITIZE (this); + return_trace (Super::sanitize (c, this, std::forward (ds)...)); + } + template bool subset (hb_subset_context_t *c, diff --git a/src/OT/Layout/GPOS/MarkArray.hh b/src/OT/Layout/GPOS/MarkArray.hh index 403a6a2bd..a08e4c5a9 100644 --- a/src/OT/Layout/GPOS/MarkArray.hh +++ b/src/OT/Layout/GPOS/MarkArray.hh @@ -8,22 +8,27 @@ namespace OT { namespace Layout { namespace GPOS_impl { -struct MarkArray : Array16Of /* Array of MarkRecords--in Coverage order */ +template +struct MarkArray : Types::template ArrayOf> + /* Array of MarkRecords--in Coverage order */ { + typedef typename Types::template ArrayOf> Super; + bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (Array16Of::sanitize (c, this)); + return_trace (Super::sanitize (c, this)); } + template bool apply (hb_ot_apply_context_t *c, unsigned int mark_index, unsigned int glyph_index, - const AnchorMatrix &anchors, unsigned int class_count, + const AnchorMatrixType &anchors, unsigned int class_count, unsigned int glyph_pos) const { TRACE_APPLY (this); hb_buffer_t *buffer = c->buffer; - const MarkRecord &record = Array16Of::operator[](mark_index); + const MarkRecord &record = Super::operator[](mark_index); unsigned int mark_class = record.klass; const Anchor& mark_anchor = this + record.markAnchor; @@ -103,18 +108,19 @@ struct MarkArray : Array16Of /* Array of MarkRecords--in Cove } }; +template HB_INTERNAL inline -void Markclass_closure_and_remap_indexes (const Coverage &mark_coverage, - const MarkArray &mark_array, - const hb_set_t &glyphset, - hb_map_t* klass_mapping /* INOUT */) +void Markclass_closure_and_remap_indexes (const Coverage &mark_coverage, + const MarkArray &mark_array, + const hb_set_t &glyphset, + hb_map_t* klass_mapping /* INOUT */) { hb_set_t orig_classes; + hb_zip (mark_coverage, mark_array) | hb_filter (glyphset, hb_first) | hb_map (hb_second) - | hb_map (&MarkRecord::get_class) + | hb_map (&MarkRecord::get_class) | hb_sink (orig_classes) ; diff --git a/src/OT/Layout/GPOS/MarkBasePosFormat1.hh b/src/OT/Layout/GPOS/MarkBasePosFormat1.hh index c13dc65d4..550d29a6c 100644 --- a/src/OT/Layout/GPOS/MarkBasePosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkBasePosFormat1.hh @@ -7,11 +7,6 @@ namespace OT { namespace Layout { namespace GPOS_impl { -typedef AnchorMatrix BaseArray; /* base-major-- - * in order of BaseCoverage Index--, - * mark-minor-- - * ordered by class--zero-based. */ - template struct MarkBasePosFormat1_2 { @@ -24,10 +19,10 @@ struct MarkBasePosFormat1_2 baseCoverage; /* Offset to BaseCoverage table--from * beginning of MarkBasePos subtable */ HBUINT16 classCount; /* Number of classes defined for marks */ - typename Types::template OffsetTo + typename Types::template OffsetTo> markArray; /* Offset to MarkArray table--from * beginning of MarkBasePos subtable */ - typename Types::template OffsetTo + typename Types::template OffsetTo> baseArray; /* Offset to BaseArray table--from * beginning of MarkBasePos subtable */ @@ -57,7 +52,7 @@ struct MarkBasePosFormat1_2 + hb_zip (this+markCoverage, this+markArray) | hb_filter (c->glyph_set, hb_first) | hb_map (hb_second) - | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+markArray)); }) + | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+markArray)); }) ; hb_map_t klass_mapping; diff --git a/src/OT/Layout/GPOS/MarkLigPosFormat1.hh b/src/OT/Layout/GPOS/MarkLigPosFormat1.hh index 57dae77a9..518a4b0f0 100644 --- a/src/OT/Layout/GPOS/MarkLigPosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkLigPosFormat1.hh @@ -21,10 +21,10 @@ struct MarkLigPosFormat1_2 * table--from beginning of MarkLigPos * subtable */ HBUINT16 classCount; /* Number of defined mark classes */ - typename Types::template OffsetTo + typename Types::template OffsetTo> markArray; /* Offset to MarkArray table--from * beginning of MarkLigPos subtable */ - typename Types::template OffsetTo + typename Types::template OffsetTo> ligatureArray; /* Offset to LigatureArray table--from * beginning of MarkLigPos subtable */ public: @@ -53,7 +53,7 @@ struct MarkLigPosFormat1_2 + hb_zip (this+markCoverage, this+markArray) | hb_filter (c->glyph_set, hb_first) | hb_map (hb_second) - | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+markArray)); }) + | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+markArray)); }) ; hb_map_t klass_mapping; @@ -66,7 +66,7 @@ struct MarkLigPosFormat1_2 | hb_map (hb_second) ; - const LigatureArray& lig_array = this+ligatureArray; + const LigatureArray& lig_array = this+ligatureArray; for (const unsigned i : lig_iter) { hb_sorted_vector_t lig_indexes; @@ -138,8 +138,8 @@ struct MarkLigPosFormat1_2 return_trace (false); } - const LigatureArray& lig_array = this+ligatureArray; - const LigatureAttach& lig_attach = lig_array[lig_index]; + const LigatureArray& lig_array = this+ligatureArray; + const AnchorMatrix& lig_attach = lig_array[lig_index]; /* Find component to attach to */ unsigned int comp_count = lig_attach.rows; diff --git a/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh b/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh index 7cd3094ca..0672c9c1e 100644 --- a/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh +++ b/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh @@ -7,11 +7,6 @@ namespace OT { namespace Layout { namespace GPOS_impl { -typedef AnchorMatrix Mark2Array; /* mark2-major-- - * in order of Mark2Coverage Index--, - * mark1-minor-- - * ordered by class--zero-based. */ - template struct MarkMarkPosFormat1_2 { @@ -26,10 +21,10 @@ struct MarkMarkPosFormat1_2 * table--from beginning of MarkMarkPos * subtable */ HBUINT16 classCount; /* Number of defined mark classes */ - typename Types::template OffsetTo + typename Types::template OffsetTo> mark1Array; /* Offset to Mark1Array table--from * beginning of MarkMarkPos subtable */ - typename Types::template OffsetTo + typename Types::template OffsetTo> mark2Array; /* Offset to Mark2Array table--from * beginning of MarkMarkPos subtable */ public: @@ -59,7 +54,7 @@ struct MarkMarkPosFormat1_2 + hb_zip (this+mark1Coverage, this+mark1Array) | hb_filter (c->glyph_set, hb_first) | hb_map (hb_second) - | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+mark1Array)); }) + | hb_apply ([&] (const MarkRecord& record) { record.collect_variation_indices (c, &(this+mark1Array)); }) ; hb_map_t klass_mapping; diff --git a/src/OT/Layout/GPOS/MarkRecord.hh b/src/OT/Layout/GPOS/MarkRecord.hh index 3d11c7773..439cb77c1 100644 --- a/src/OT/Layout/GPOS/MarkRecord.hh +++ b/src/OT/Layout/GPOS/MarkRecord.hh @@ -5,27 +5,30 @@ namespace OT { namespace Layout { namespace GPOS_impl { +template struct MarkArray; + +template struct MarkRecord { - friend struct MarkArray; + friend struct MarkArray; public: HBUINT16 klass; /* Class defined for this mark */ - Offset16To + typename Types::template OffsetTo> markAnchor; /* Offset to Anchor table--from * beginning of MarkArray table */ public: - DEFINE_SIZE_STATIC (4); + DEFINE_SIZE_STATIC (2 + Types::size); unsigned get_class () const { return (unsigned) klass; } - bool sanitize (hb_sanitize_context_t *c, const void *base) const + bool sanitize (hb_sanitize_context_t *c, const MarkArray *base) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && markAnchor.sanitize (c, base)); } bool subset (hb_subset_context_t *c, - const void *src_base, + const MarkArray *src_base, const hb_map_t *klass_mapping) const { TRACE_SUBSET (this); @@ -37,7 +40,7 @@ struct MarkRecord } void collect_variation_indices (hb_collect_variation_indices_context_t *c, - const void *src_base) const + const MarkArray *src_base) const { (src_base+markAnchor).collect_variation_indices (c); } diff --git a/src/graph/markbasepos-graph.hh b/src/graph/markbasepos-graph.hh index a17269d37..8e735486d 100644 --- a/src/graph/markbasepos-graph.hh +++ b/src/graph/markbasepos-graph.hh @@ -34,7 +34,7 @@ namespace graph { -struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix +struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix { bool sanitize (graph_t::vertex_t& vertex, unsigned class_count) const { @@ -122,7 +122,7 @@ struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix } }; -struct MarkArray : public OT::Layout::GPOS_impl::MarkArray +struct MarkArray : public OT::Layout::GPOS_impl::MarkArray { bool sanitize (graph_t::vertex_t& vertex) const { @@ -165,7 +165,7 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray this->len = new_index; o.tail = o.head + MarkArray::min_size + - OT::Layout::GPOS_impl::MarkRecord::static_size * new_index; + OT::Layout::GPOS_impl::MarkRecord::static_size * new_index; return true; } @@ -176,7 +176,7 @@ struct MarkArray : public OT::Layout::GPOS_impl::MarkArray unsigned start_class) { unsigned size = MarkArray::min_size + - OT::Layout::GPOS_impl::MarkRecord::static_size * + OT::Layout::GPOS_impl::MarkRecord::static_size * marks.get_population (); unsigned prime_id = c.create_node (size); if (prime_id == (unsigned) -1) return -1; @@ -241,7 +241,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2::static_size * info.marks.get_population () + OT::Offset16::static_size * base_count; for (unsigned objidx : info.child_indices) @@ -338,7 +338,7 @@ struct MarkBasePosFormat1 : public OT::Layout::GPOS_impl::MarkBasePosFormat1_2obj.real_links) { unsigned mark = (link.position - 2) / - OT::Layout::GPOS_impl::MarkRecord::static_size; + OT::Layout::GPOS_impl::MarkRecord::static_size; unsigned klass = (*mark_array.table)[mark].get_class (); if (klass >= class_count) continue; class_to_info[klass].child_indices.push (link.objidx);