mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
[gpos] Template mark attachment arrays
MarkBasePos, MarkLigPos, and MarkMarkPos format 2 use nested MarkArray2, BaseArray2, LigatureArray2, and Mark2Array2 tables with 24-bit counts and offsets in different combinations. Template the shared mark records and anchor matrices so format 1 continues to use SmallTypes while format 2 uses the widths specified for the beyond-64k layout forms. Keep the subset graph wrappers bound to their existing 16-bit forms. Testing: meson test -C build Assisted-by: OpenAI Codex
This commit is contained in:
1 parent
cdc1ca9edf
commit
813558d2e9
8 files changed
+68
-52
No files matched your search
@@ -5,14 +5,15 @@ namespace OT {
|
||||
namespace Layout {
|
||||
namespace GPOS_impl {
|
||||
|
||||
template <typename Types, typename RowCount=typename Types::HBUINT>
|
||||
struct AnchorMatrix
|
||||
{
|
||||
HBUINT16 rows; /* Number of rows */
|
||||
UnsizedArrayOf<Offset16To<Anchor, AnchorMatrix>>
|
||||
RowCount rows; /* Number of rows */
|
||||
UnsizedArrayOf<typename Types::template OffsetTo<Anchor, AnchorMatrix>>
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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<LigatureAttach>
|
||||
template <typename Types>
|
||||
struct LigatureArray :
|
||||
Types::template ArrayOf<typename Types::template OffsetTo<AnchorMatrix<Types, HBUINT16>>>
|
||||
{
|
||||
typedef AnchorMatrix<Types, HBUINT16> LigatureAttach;
|
||||
typedef typename Types::template OffsetTo<LigatureAttach> LigatureAttachOffset;
|
||||
typedef typename Types::template ArrayOf<LigatureAttachOffset> 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 <typename ...Ts>
|
||||
bool sanitize (hb_sanitize_context_t *c, Ts&&... ds) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (Super::sanitize (c, this, std::forward<Ts> (ds)...));
|
||||
}
|
||||
|
||||
template <typename Iterator,
|
||||
hb_requires (hb_is_iterator (Iterator))>
|
||||
bool subset (hb_subset_context_t *c,
|
||||
|
||||
@@ -8,22 +8,27 @@ namespace OT {
|
||||
namespace Layout {
|
||||
namespace GPOS_impl {
|
||||
|
||||
struct MarkArray : Array16Of<MarkRecord> /* Array of MarkRecords--in Coverage order */
|
||||
template <typename Types>
|
||||
struct MarkArray : Types::template ArrayOf<MarkRecord<Types>>
|
||||
/* Array of MarkRecords--in Coverage order */
|
||||
{
|
||||
typedef typename Types::template ArrayOf<MarkRecord<Types>> Super;
|
||||
|
||||
bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (Array16Of<MarkRecord>::sanitize (c, this));
|
||||
return_trace (Super::sanitize (c, this));
|
||||
}
|
||||
|
||||
template <typename AnchorMatrixType>
|
||||
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<MarkRecord>::operator[](mark_index);
|
||||
const MarkRecord<Types> &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<MarkRecord> /* Array of MarkRecords--in Cove
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Types>
|
||||
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<Types> &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<Types>::get_class)
|
||||
| hb_sink (orig_classes)
|
||||
;
|
||||
|
||||
|
||||
@@ -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 <typename Types>
|
||||
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<MarkArray>
|
||||
typename Types::template OffsetTo<MarkArray<Types>>
|
||||
markArray; /* Offset to MarkArray table--from
|
||||
* beginning of MarkBasePos subtable */
|
||||
typename Types::template OffsetTo<BaseArray>
|
||||
typename Types::template OffsetTo<AnchorMatrix<Types>>
|
||||
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<Types>& record) { record.collect_variation_indices (c, &(this+markArray)); })
|
||||
;
|
||||
|
||||
hb_map_t klass_mapping;
|
||||
|
||||
@@ -21,10 +21,10 @@ struct MarkLigPosFormat1_2
|
||||
* table--from beginning of MarkLigPos
|
||||
* subtable */
|
||||
HBUINT16 classCount; /* Number of defined mark classes */
|
||||
typename Types::template OffsetTo<MarkArray>
|
||||
typename Types::template OffsetTo<MarkArray<Types>>
|
||||
markArray; /* Offset to MarkArray table--from
|
||||
* beginning of MarkLigPos subtable */
|
||||
typename Types::template OffsetTo<LigatureArray>
|
||||
typename Types::template OffsetTo<LigatureArray<Types>>
|
||||
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<Types>& 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<Types>& lig_array = this+ligatureArray;
|
||||
for (const unsigned i : lig_iter)
|
||||
{
|
||||
hb_sorted_vector_t<unsigned> 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<Types>& lig_array = this+ligatureArray;
|
||||
const AnchorMatrix<Types, HBUINT16>& lig_attach = lig_array[lig_index];
|
||||
|
||||
/* Find component to attach to */
|
||||
unsigned int comp_count = lig_attach.rows;
|
||||
|
||||
@@ -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 <typename Types>
|
||||
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<MarkArray>
|
||||
typename Types::template OffsetTo<MarkArray<Types>>
|
||||
mark1Array; /* Offset to Mark1Array table--from
|
||||
* beginning of MarkMarkPos subtable */
|
||||
typename Types::template OffsetTo<Mark2Array>
|
||||
typename Types::template OffsetTo<AnchorMatrix<Types, HBUINT16>>
|
||||
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<Types>& record) { record.collect_variation_indices (c, &(this+mark1Array)); })
|
||||
;
|
||||
|
||||
hb_map_t klass_mapping;
|
||||
|
||||
@@ -5,27 +5,30 @@ namespace OT {
|
||||
namespace Layout {
|
||||
namespace GPOS_impl {
|
||||
|
||||
template <typename Types> struct MarkArray;
|
||||
|
||||
template <typename Types>
|
||||
struct MarkRecord
|
||||
{
|
||||
friend struct MarkArray;
|
||||
friend struct MarkArray<Types>;
|
||||
|
||||
public:
|
||||
HBUINT16 klass; /* Class defined for this mark */
|
||||
Offset16To<Anchor>
|
||||
typename Types::template OffsetTo<Anchor, MarkArray<Types>>
|
||||
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<Types> *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<Types> *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<Types> *src_base) const
|
||||
{
|
||||
(src_base+markAnchor).collect_variation_indices (c);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
namespace graph {
|
||||
|
||||
struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix
|
||||
struct AnchorMatrix : public OT::Layout::GPOS_impl::AnchorMatrix<SmallTypes>
|
||||
{
|
||||
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<SmallTypes>
|
||||
{
|
||||
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<SmallTypes>::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<SmallTypes>::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<S
|
||||
class_info_t& info = class_to_info[klass];
|
||||
partial_coverage_size += OT::HBUINT16::static_size * info.marks.get_population ();
|
||||
unsigned accumulated_delta =
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size * info.marks.get_population () +
|
||||
OT::Layout::GPOS_impl::MarkRecord<SmallTypes>::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_2<S
|
||||
for (const auto& link : mark_array.vertex->obj.real_links)
|
||||
{
|
||||
unsigned mark = (link.position - 2) /
|
||||
OT::Layout::GPOS_impl::MarkRecord::static_size;
|
||||
OT::Layout::GPOS_impl::MarkRecord<SmallTypes>::static_size;
|
||||
unsigned klass = (*mark_array.table)[mark].get_class ();
|
||||
if (klass >= class_count) continue;
|
||||
class_to_info[klass].child_indices.push (link.objidx);
|
||||
|
||||
Reference in new issue
Block a user