[var] Prepare for hooking up advance variations to hb-ot-font

This commit is contained in:
Behdad Esfahbod 2017-01-23 17:34:44 -08:00
parent a4fca9f005
commit bd3b11d926
2 changed files with 21 additions and 15 deletions

View File

@ -54,9 +54,13 @@ struct hb_ot_face_metrics_accelerator_t
const OT::hmtxvmtx *table; const OT::hmtxvmtx *table;
hb_blob_t *blob; hb_blob_t *blob;
const OT::HVARVVAR *var;
hb_blob_t *var_blob;
inline void init (hb_face_t *face, inline void init (hb_face_t *face,
hb_tag_t _hea_tag, hb_tag_t _hea_tag,
hb_tag_t _mtx_tag, hb_tag_t _mtx_tag,
hb_tag_t _var_tag,
hb_tag_t os2_tag, hb_tag_t os2_tag,
unsigned int default_advance = 0) unsigned int default_advance = 0)
{ {
@ -109,14 +113,19 @@ struct hb_ot_face_metrics_accelerator_t
this->blob = hb_blob_get_empty (); this->blob = hb_blob_get_empty ();
} }
this->table = OT::Sanitizer<OT::hmtxvmtx>::lock_instance (this->blob); this->table = OT::Sanitizer<OT::hmtxvmtx>::lock_instance (this->blob);
this->var_blob = OT::Sanitizer<OT::HVARVVAR>::sanitize (face->reference_table (_var_tag));
this->var = OT::Sanitizer<OT::HVARVVAR>::lock_instance (this->var_blob);
} }
inline void fini (void) inline void fini (void)
{ {
hb_blob_destroy (this->blob); hb_blob_destroy (this->blob);
hb_blob_destroy (this->var_blob);
} }
inline unsigned int get_advance (hb_codepoint_t glyph) const inline unsigned int get_advance (hb_codepoint_t glyph,
hb_font_t *font) const
{ {
if (unlikely (glyph >= this->num_metrics)) if (unlikely (glyph >= this->num_metrics))
{ {
@ -129,10 +138,7 @@ struct hb_ot_face_metrics_accelerator_t
return this->default_advance; return this->default_advance;
} }
if (glyph >= this->num_advances) return this->table->longMetric[MIN (glyph, this->num_advances - 1)].advance;
glyph = this->num_advances - 1;
return this->table->longMetric[glyph].advance;
} }
}; };
@ -441,8 +447,8 @@ _hb_ot_font_create (hb_face_t *face)
return NULL; return NULL;
ot_font->cmap.init (face); ot_font->cmap.init (face);
ot_font->h_metrics.init (face, HB_OT_TAG_hhea, HB_OT_TAG_hmtx, HB_OT_TAG_os2); ot_font->h_metrics.init (face, HB_OT_TAG_hhea, HB_OT_TAG_hmtx, HB_OT_TAG_HVAR, HB_OT_TAG_os2);
ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, HB_TAG_NONE, ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, HB_OT_TAG_VVAR, HB_TAG_NONE,
ot_font->h_metrics.ascender - ot_font->h_metrics.descender); /* TODO Can we do this lazily? */ ot_font->h_metrics.ascender - ot_font->h_metrics.descender); /* TODO Can we do this lazily? */
ot_font->glyf.init (face); ot_font->glyf.init (face);
ot_font->cbdt.init (face); ot_font->cbdt.init (face);
@ -488,23 +494,23 @@ hb_ot_get_variation_glyph (hb_font_t *font HB_UNUSED,
} }
static hb_position_t static hb_position_t
hb_ot_get_glyph_h_advance (hb_font_t *font HB_UNUSED, hb_ot_get_glyph_h_advance (hb_font_t *font,
void *font_data, void *font_data,
hb_codepoint_t glyph, hb_codepoint_t glyph,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return font->em_scale_x (ot_font->h_metrics.get_advance (glyph)); return font->em_scale_x (ot_font->h_metrics.get_advance (glyph, font));
} }
static hb_position_t static hb_position_t
hb_ot_get_glyph_v_advance (hb_font_t *font HB_UNUSED, hb_ot_get_glyph_v_advance (hb_font_t *font,
void *font_data, void *font_data,
hb_codepoint_t glyph, hb_codepoint_t glyph,
void *user_data HB_UNUSED) void *user_data HB_UNUSED)
{ {
const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data;
return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph)); return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph, font));
} }
static hb_bool_t static hb_bool_t

View File

@ -98,8 +98,8 @@ struct DeltaSetIndexMap
struct HVARVVAR struct HVARVVAR
{ {
static const hb_tag_t HVARTag = HB_OT_TAG_hmtx; static const hb_tag_t HVARTag = HB_OT_TAG_HVAR;
static const hb_tag_t VVARTag = HB_OT_TAG_vmtx; static const hb_tag_t VVARTag = HB_OT_TAG_VVAR;
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
@ -112,8 +112,8 @@ struct HVARVVAR
rsbMap.sanitize (c, this)); rsbMap.sanitize (c, this));
} }
inline float get_advance_delta (hb_codepoint_t glyph, inline float get_advance_var (hb_codepoint_t glyph,
int *coords, unsigned int coord_count) const int *coords, unsigned int coord_count) const
{ {
unsigned int varidx = (this+advMap).map (glyph); unsigned int varidx = (this+advMap).map (glyph);
return (this+varStore).get_delta (varidx, coords, coord_count); return (this+varStore).get_delta (varidx, coords, coord_count);