[aat] Embed a sanitizer context in hb_aat_apply_context_t

For run-time checking.
This commit is contained in:
Behdad Esfahbod 2018-01-19 16:52:01 -08:00
parent 046690a4df
commit f07ce661a2
2 changed files with 24 additions and 14 deletions

View File

@ -704,13 +704,23 @@ struct hb_aat_apply_context_t :
hb_font_t *font; hb_font_t *font;
hb_face_t *face; hb_face_t *face;
hb_buffer_t *buffer; hb_buffer_t *buffer;
const char *end; hb_sanitize_context_t sanitizer;
hb_aat_apply_context_t (hb_font_t *font_, inline hb_aat_apply_context_t (hb_font_t *font_,
hb_buffer_t *buffer_, hb_buffer_t *buffer_,
const char *end_) : hb_blob_t *table) :
font (font_), face (font->face), buffer (buffer_), font (font_), face (font->face), buffer (buffer_),
end (end_) {} sanitizer ()
{
sanitizer.init (table);
sanitizer.num_glyphs = face->get_num_glyphs ();
sanitizer.start_processing ();
}
inline ~hb_aat_apply_context_t (void)
{
sanitizer.end_processing ();
}
}; };

View File

@ -37,19 +37,19 @@
*/ */
static inline const AAT::morx& static inline const AAT::morx&
_get_morx (hb_face_t *face, unsigned int *length = nullptr) _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
{ {
if (unlikely (!hb_ot_shaper_face_data_ensure (face))) if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
{ {
if (length) if (blob)
*length = 0; *blob = hb_blob_get_empty ();
return OT::Null(AAT::morx); return OT::Null(AAT::morx);
} }
hb_ot_layout_t * layout = hb_ot_layout_from_face (face); hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
/* XXX this doesn't call set_num_glyphs on sanitizer. */ /* XXX this doesn't call set_num_glyphs on sanitizer. */
const AAT::morx& morx = *(layout->morx.get ()); const AAT::morx& morx = *(layout->morx.get ());
if (length) if (blob)
*length = hb_blob_get_length (layout->morx.blob); *blob = layout->morx.blob;
return morx; return morx;
} }
@ -70,9 +70,9 @@ _hb_aat_layout_create (hb_face_t *face)
void void
hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer) hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
{ {
unsigned int length; hb_blob_t *blob;
const AAT::morx& morx = _get_morx (font->face, &length); const AAT::morx& morx = _get_morx (font->face, &blob);
AAT::hb_aat_apply_context_t c (font, buffer, (const char *) &morx + length); AAT::hb_aat_apply_context_t c (font, buffer, blob);
morx.apply (&c); morx.apply (&c);
} }