Avoid div-by-zero, validate upem
This commit is contained in:
parent
7f97d2cd90
commit
ac0c1663fa
|
@ -42,12 +42,19 @@ struct head
|
||||||
{
|
{
|
||||||
static const hb_tag_t Tag = HB_OT_TAG_head;
|
static const hb_tag_t Tag = HB_OT_TAG_head;
|
||||||
|
|
||||||
|
inline unsigned int get_upem (void) const {
|
||||||
|
unsigned int upem = unitsPerEm;
|
||||||
|
/* If no valid head table found, assume 1000, which matches typicaly Type1 usage. */
|
||||||
|
return 16 <= upem && upem <= 16384 ? upem : 1000;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool sanitize (hb_sanitize_context_t *c) {
|
inline bool sanitize (hb_sanitize_context_t *c) {
|
||||||
TRACE_SANITIZE ();
|
TRACE_SANITIZE ();
|
||||||
/* Shall we check for magicNumber here? Who cares? */
|
/* Shall we check for magicNumber here? Who cares? */
|
||||||
return c->check_struct (this) && likely (version.major == 1);
|
return c->check_struct (this) && likely (version.major == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
FixedVersion version; /* Version of the head table--currently
|
FixedVersion version; /* Version of the head table--currently
|
||||||
* 0x00010000 for version 1.0. */
|
* 0x00010000 for version 1.0. */
|
||||||
FixedVersion fontRevision; /* Set by font manufacturer. */
|
FixedVersion fontRevision; /* Set by font manufacturer. */
|
||||||
|
|
|
@ -77,9 +77,9 @@ struct hb_ot_layout_context_t
|
||||||
} info;
|
} info;
|
||||||
|
|
||||||
/* Convert from font-space to user-space */
|
/* Convert from font-space to user-space */
|
||||||
/* XXX div-by-zero / speed up */
|
/* XXX speed up */
|
||||||
inline hb_position_t scale_x (int16_t v) { return (int64_t) this->font->x_scale * v / this->face->head_table->unitsPerEm; }
|
inline hb_position_t scale_x (int16_t v) { return (int64_t) this->font->x_scale * v / this->face->head_table->get_upem (); }
|
||||||
inline hb_position_t scale_y (int16_t v) { return (int64_t) this->font->y_scale * v / this->face->head_table->unitsPerEm; }
|
inline hb_position_t scale_y (int16_t v) { return (int64_t) this->font->y_scale * v / this->face->head_table->get_upem (); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue