mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-28 17:19:17 +01:00
Math, COLR, and glyf dependencies
This commit is contained in:
1 parent
65447f9cbb
commit
fe59e7c5cd
7 files changed
+225
-1
No files matched your search
@@ -205,6 +205,7 @@ set (subset_project_sources
|
||||
${PROJECT_SOURCE_DIR}/src/graph/split-helpers.hh
|
||||
${PROJECT_SOURCE_DIR}/src/graph/serialize.hh
|
||||
${PROJECT_SOURCE_DIR}/src/OT/Color/COLR/colrv1-closure.hh
|
||||
${PROJECT_SOURCE_DIR}/src/OT/Color/COLR/colrv1-depend.hh
|
||||
)
|
||||
set (project_extra_sources)
|
||||
set (project_headers
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "../../../hb-paint.hh"
|
||||
#include "../../../hb-paint-bounded.hh"
|
||||
#include "../../../hb-paint-extents.hh"
|
||||
#include "../../../hb-depend-data.hh"
|
||||
|
||||
#include "../CPAL/CPAL.hh"
|
||||
|
||||
@@ -225,6 +226,41 @@ struct hb_colrv1_closure_context_t :
|
||||
{}
|
||||
};
|
||||
|
||||
struct hb_colrv1_depend_context_t :
|
||||
hb_dispatch_context_t<hb_colrv1_depend_context_t, bool>
|
||||
{
|
||||
template <typename T>
|
||||
return_t dispatch (const T &obj)
|
||||
{
|
||||
if (unlikely (nesting_level_left == 0))
|
||||
return false;
|
||||
|
||||
nesting_level_left--;
|
||||
obj.dependv1 (this);
|
||||
nesting_level_left++;
|
||||
return true;
|
||||
}
|
||||
static return_t default_return_value () { return false; }
|
||||
|
||||
const COLR* get_colr_table () const
|
||||
{ return reinterpret_cast<const COLR *> (base); }
|
||||
|
||||
public:
|
||||
const void *base;
|
||||
hb_depend_data_t *depend_data;
|
||||
unsigned nesting_level_left;
|
||||
hb_codepoint_t source_gid;
|
||||
|
||||
hb_colrv1_depend_context_t (const void *base_,
|
||||
hb_depend_data_t *depend_data_,
|
||||
unsigned nesting_level_left_ = HB_MAX_NESTING_LEVEL) :
|
||||
base (base_),
|
||||
depend_data (depend_data_),
|
||||
nesting_level_left (nesting_level_left_),
|
||||
source_gid (0)
|
||||
{}
|
||||
};
|
||||
|
||||
struct LayerRecord
|
||||
{
|
||||
operator hb_ot_color_layer_t () const { return {glyphId, colorIdx}; }
|
||||
@@ -286,6 +322,9 @@ struct Variable
|
||||
return_trace (c->embed (this));
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{ value.dependv1 (c); }
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
c->num_var_idxes = 0;
|
||||
@@ -361,6 +400,9 @@ struct NoVariable
|
||||
return_trace (c->embed (this));
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{ value.dependv1 (c); }
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{ value.closurev1 (c); }
|
||||
|
||||
@@ -404,6 +446,8 @@ struct NoVariable
|
||||
|
||||
struct ColorStop
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t * c) const {}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
c->add_palette_index (paletteIndex);
|
||||
@@ -466,6 +510,12 @@ struct Extend : HBUINT8
|
||||
template <template<typename> class Var>
|
||||
struct ColorLine
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t * c) const
|
||||
{
|
||||
for (const auto &stop : stops.iter ())
|
||||
stop.dependv1 (c);
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
for (const auto &stop : stops.iter ())
|
||||
@@ -611,6 +661,8 @@ struct Affine2x3
|
||||
return_trace (c->check_struct (this));
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const {}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{ c->num_var_idxes = 6; }
|
||||
|
||||
@@ -657,6 +709,7 @@ struct Affine2x3
|
||||
|
||||
struct PaintColrLayers
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -688,6 +741,7 @@ struct PaintColrLayers
|
||||
|
||||
struct PaintSolid
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const {}
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
c->add_palette_index (paletteIndex);
|
||||
@@ -740,6 +794,11 @@ struct PaintSolid
|
||||
template <template<typename> class Var>
|
||||
struct PaintLinearGradient
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{
|
||||
(this+colorLine).dependv1 (c);
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
(this+colorLine).closurev1 (c);
|
||||
@@ -810,6 +869,11 @@ struct PaintLinearGradient
|
||||
template <template<typename> class Var>
|
||||
struct PaintRadialGradient
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{
|
||||
(this+colorLine).dependv1 (c);
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
(this+colorLine).closurev1 (c);
|
||||
@@ -880,6 +944,11 @@ struct PaintRadialGradient
|
||||
template <template<typename> class Var>
|
||||
struct PaintSweepGradient
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{
|
||||
(this+colorLine).dependv1 (c);
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
(this+colorLine).closurev1 (c);
|
||||
@@ -944,6 +1013,7 @@ struct PaintSweepGradient
|
||||
// Paint a non-COLR glyph, filled as indicated by paint.
|
||||
struct PaintGlyph
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -987,6 +1057,7 @@ struct PaintGlyph
|
||||
|
||||
struct PaintColrGlyph
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1017,6 +1088,7 @@ struct PaintColrGlyph
|
||||
template <template<typename> class Var>
|
||||
struct PaintTransform
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1056,6 +1128,7 @@ struct PaintTransform
|
||||
|
||||
struct PaintTranslate
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1105,6 +1178,7 @@ struct PaintTranslate
|
||||
|
||||
struct PaintScale
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1154,6 +1228,7 @@ struct PaintScale
|
||||
|
||||
struct PaintScaleAroundCenter
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1209,6 +1284,7 @@ struct PaintScaleAroundCenter
|
||||
|
||||
struct PaintScaleUniform
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1253,6 +1329,7 @@ struct PaintScaleUniform
|
||||
|
||||
struct PaintScaleUniformAroundCenter
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1305,6 +1382,7 @@ struct PaintScaleUniformAroundCenter
|
||||
|
||||
struct PaintRotate
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1349,6 +1427,7 @@ struct PaintRotate
|
||||
|
||||
struct PaintRotateAroundCenter
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1401,6 +1480,7 @@ struct PaintRotateAroundCenter
|
||||
|
||||
struct PaintSkew
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1450,6 +1530,7 @@ struct PaintSkew
|
||||
|
||||
struct PaintSkewAroundCenter
|
||||
{
|
||||
HB_INTERNAL void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
HB_INTERNAL void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1505,6 +1586,7 @@ struct PaintSkewAroundCenter
|
||||
|
||||
struct PaintComposite
|
||||
{
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const;
|
||||
|
||||
bool subset (hb_subset_context_t *c,
|
||||
@@ -1615,6 +1697,7 @@ struct ClipBoxFormat2 : Variable<ClipBoxFormat1>
|
||||
}
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const;
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{ c->variation_indices->add_range (varIdxBase, varIdxBase + 3); }
|
||||
};
|
||||
@@ -1632,6 +1715,14 @@ struct ClipBox
|
||||
}
|
||||
}
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c) const
|
||||
{
|
||||
switch (u.format) {
|
||||
case 2: u.format2.dependv1 (c);
|
||||
default:return;
|
||||
}
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c) const
|
||||
{
|
||||
switch (u.format.v) {
|
||||
@@ -1687,6 +1778,11 @@ struct ClipRecord
|
||||
int cmp (hb_codepoint_t g) const
|
||||
{ return g < startGlyphID ? -1 : g <= endGlyphID ? 0 : +1; }
|
||||
|
||||
void dependv1 (hb_colrv1_depend_context_t* c, const void *base) const
|
||||
{
|
||||
(base+clipBox).dependv1 (c);
|
||||
}
|
||||
|
||||
void closurev1 (hb_colrv1_closure_context_t* c, const void *base) const
|
||||
{
|
||||
if (!c->glyphs->intersects (startGlyphID, endGlyphID)) return;
|
||||
@@ -2184,6 +2280,9 @@ struct COLR
|
||||
|
||||
bool is_valid () { return colr.get_blob ()->length; }
|
||||
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{ colr->depend (depend_data); }
|
||||
|
||||
void closure_glyphs (hb_codepoint_t glyph,
|
||||
hb_set_t *related_ids /* OUT */) const
|
||||
{ colr->closure_glyphs (glyph, related_ids); }
|
||||
@@ -2245,6 +2344,31 @@ struct COLR
|
||||
mutable hb_atomic_t<hb_colr_scratch_t *> cached_scratch;
|
||||
};
|
||||
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{
|
||||
// v0
|
||||
hb_array_t<const BaseGlyphRecord> baseGlyphs = (this+baseGlyphsZ).as_array (numBaseGlyphs);
|
||||
for (const BaseGlyphRecord &record : baseGlyphs)
|
||||
{
|
||||
auto glyph_layers = (this+layersZ).as_array (numLayers).sub_array (record.firstLayerIdx,
|
||||
record.numLayers);
|
||||
for (const LayerRecord layer : glyph_layers)
|
||||
depend_data->add_depend(record.glyphId, HB_OT_TAG_COLR, layer.glyphId);
|
||||
}
|
||||
|
||||
// v1
|
||||
hb_colrv1_depend_context_t c (this, depend_data);
|
||||
const BaseGlyphList &baseglyph_paintrecords = this+baseGlyphList;
|
||||
|
||||
for (const BaseGlyphPaintRecord &baseglyph_paintrecord: baseglyph_paintrecords.iter ())
|
||||
{
|
||||
c.source_gid = baseglyph_paintrecord.glyphId;
|
||||
|
||||
const Paint &paint = &baseglyph_paintrecords+baseglyph_paintrecord.paint;
|
||||
paint.dispatch (&c);
|
||||
}
|
||||
}
|
||||
|
||||
void closure_glyphs (hb_codepoint_t glyph,
|
||||
hb_set_t *related_ids /* OUT */) const
|
||||
{
|
||||
|
||||
@@ -542,6 +542,8 @@ struct glyf_accelerator_t
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int get_num_glyphs () const { return num_glyphs; }
|
||||
|
||||
#ifndef HB_NO_VAR
|
||||
const gvar_accelerator_t *gvar;
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
|
||||
+10
-1
@@ -143,7 +143,16 @@ struct hb_depend_data_t
|
||||
return;
|
||||
}
|
||||
auto &gdr = glyph_dependencies[target];
|
||||
// XXX Check for dups here
|
||||
for (auto &dep : gdr.dependencies) {
|
||||
if (dep.table_tag == table_tag && dep.layout_tag == layout_tag &&
|
||||
dep.dependent == dependent) {
|
||||
if (dep.ligature_set == HB_CODEPOINT_INVALID && lig_set == HB_CODEPOINT_INVALID)
|
||||
return; // dup
|
||||
if (dep.ligature_set != HB_CODEPOINT_INVALID && lig_set != HB_CODEPOINT_INVALID &&
|
||||
sets[dep.ligature_set] == sets[lig_set])
|
||||
return; // dup
|
||||
}
|
||||
}
|
||||
gdr.dependencies.push(table_tag, dependent, layout_tag, lig_set,
|
||||
context_set); // , fv_context_set, fv_only);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,11 @@
|
||||
|
||||
#include "hb-face.hh"
|
||||
#include "hb-ot-cmap-table.hh"
|
||||
#include "hb-ot-glyf-table.hh"
|
||||
#include "hb-ot-layout-gsub-table.hh"
|
||||
#include "hb-ot-math-table.hh"
|
||||
#include "OT/Color/COLR/COLR.hh"
|
||||
#include "OT/Color/COLR/colrv1-depend.hh"
|
||||
|
||||
/**
|
||||
* SECTION:hb-depend
|
||||
@@ -130,6 +134,32 @@ void hb_depend_t::get_gsub_dependencies() {
|
||||
}
|
||||
}
|
||||
|
||||
void hb_depend_t::get_math_dependencies()
|
||||
{
|
||||
hb_blob_t *math_blob = hb_sanitize_context_t ().reference_table<OT::MATH> (face);
|
||||
auto math = math_blob->as<OT::MATH> ();
|
||||
math->depend (&data);
|
||||
}
|
||||
|
||||
void hb_depend_t::get_colr_dependencies()
|
||||
{
|
||||
OT::COLR::accelerator_t colr (face);
|
||||
if (!colr.is_valid ()) return;
|
||||
colr.depend (&data);
|
||||
}
|
||||
|
||||
void hb_depend_t::get_glyf_dependencies()
|
||||
{
|
||||
OT::glyf_accelerator_t glyf (face);
|
||||
if (!glyf.has_data())
|
||||
return;
|
||||
for (hb_codepoint_t gid = 0; gid < glyf.get_num_glyphs (); gid++) {
|
||||
auto glyph = glyf.glyph_for_gid(gid);
|
||||
for (auto &item : glyph.get_composite_iterator ())
|
||||
data.add_depend (gid, HB_OT_TAG_glyf, item.get_gid ());
|
||||
}
|
||||
}
|
||||
|
||||
hb_depend_t::~hb_depend_t ()
|
||||
{
|
||||
hb_face_destroy(face);
|
||||
|
||||
@@ -54,6 +54,9 @@ struct hb_depend_t
|
||||
|
||||
void get_cmap_dependencies ();
|
||||
void get_gsub_dependencies ();
|
||||
void get_math_dependencies ();
|
||||
void get_colr_dependencies ();
|
||||
void get_glyf_dependencies ();
|
||||
|
||||
hb_face_t *face;
|
||||
hb_set_t features;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "hb-open-type.hh"
|
||||
#include "hb-ot-layout-common.hh"
|
||||
#include "hb-ot-math.h"
|
||||
#include "hb-depend-data.hh"
|
||||
|
||||
namespace OT {
|
||||
|
||||
@@ -662,6 +663,9 @@ struct MathGlyphVariantRecord
|
||||
return_trace (c->check_struct (this));
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, unsigned source) const
|
||||
{ depend_data->add_depend(source, HB_OT_TAG_MATH, variantGlyph); }
|
||||
|
||||
void closure_glyphs (hb_set_t *variant_glyphs) const
|
||||
{ variant_glyphs->add (variantGlyph); }
|
||||
|
||||
@@ -723,6 +727,9 @@ struct MathGlyphPartRecord
|
||||
(partFlags & PartFlags::Defined);
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, unsigned source) const
|
||||
{ depend_data->add_depend(source, HB_OT_TAG_MATH, glyph); }
|
||||
|
||||
void closure_glyphs (hb_set_t *variant_glyphs) const
|
||||
{ variant_glyphs->add (glyph); }
|
||||
|
||||
@@ -790,6 +797,12 @@ struct MathGlyphAssembly
|
||||
return partRecords.len;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, unsigned source) const
|
||||
{
|
||||
for (const auto& _ : partRecords.iter ())
|
||||
_.depend (depend_data, source);
|
||||
}
|
||||
|
||||
void closure_glyphs (hb_set_t *variant_glyphs) const
|
||||
{
|
||||
for (const auto& _ : partRecords.iter ())
|
||||
@@ -855,6 +868,14 @@ struct MathGlyphConstruction
|
||||
return mathGlyphVariantRecord.len;
|
||||
}
|
||||
|
||||
void depend (hb_depend_data_t *depend_data, unsigned source) const
|
||||
{
|
||||
(this+glyphAssembly).depend (depend_data, source);
|
||||
|
||||
for (const auto& _ : mathGlyphVariantRecord.iter ())
|
||||
_.depend (depend_data, source);
|
||||
}
|
||||
|
||||
void closure_glyphs (hb_set_t *variant_glyphs) const
|
||||
{
|
||||
(this+glyphAssembly).closure_glyphs (variant_glyphs);
|
||||
@@ -877,6 +898,34 @@ struct MathGlyphConstruction
|
||||
|
||||
struct MathVariants
|
||||
{
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{
|
||||
const hb_array_t<const Offset16To<MathGlyphConstruction>> glyph_construction_offsets = glyphConstruction.as_array (vertGlyphCount + horizGlyphCount);
|
||||
|
||||
if (vertGlyphCoverage)
|
||||
{
|
||||
const auto vert_offsets = glyph_construction_offsets.sub_array (0, vertGlyphCount);
|
||||
+ hb_zip (this+vertGlyphCoverage, vert_offsets)
|
||||
| hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const Offset16To<MathGlyphConstruction>&> &_)
|
||||
{
|
||||
const MathGlyphConstruction &mgc = this+_.second;
|
||||
mgc.depend (depend_data, _.first);
|
||||
})
|
||||
;
|
||||
}
|
||||
if (horizGlyphCoverage)
|
||||
{
|
||||
const auto hori_offsets = glyph_construction_offsets.sub_array (vertGlyphCount, horizGlyphCount);
|
||||
+ hb_zip (this+horizGlyphCoverage, hori_offsets)
|
||||
| hb_apply ([&] (const hb_pair_t<hb_codepoint_t, const Offset16To<MathGlyphConstruction>&> &_)
|
||||
{
|
||||
const MathGlyphConstruction &mgc = this+_.second;
|
||||
mgc.depend (depend_data, _.first);
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void closure_glyphs (const hb_set_t *glyph_set,
|
||||
hb_set_t *variant_glyphs) const
|
||||
{
|
||||
@@ -1073,6 +1122,12 @@ struct MATH
|
||||
|
||||
bool has_data () const { return version.to_int (); }
|
||||
|
||||
void depend (hb_depend_data_t *depend_data) const
|
||||
{
|
||||
if (mathVariants)
|
||||
(this+mathVariants).depend (depend_data);
|
||||
}
|
||||
|
||||
void closure_glyphs (hb_set_t *glyph_set) const
|
||||
{
|
||||
if (mathVariants)
|
||||
|
||||
Reference in new issue
Block a user