src/hb-aat-layout-common-private.hh | 4 - src/hb-face.cc | 7 +- src/hb-open-type-private.hh | 97 +++++++++++++++++++----------------- src/hb-ot-color-sbix-table.hh | 12 +--- src/hb-ot-layout-common-private.hh | 3 - 5 files changed, 63 insertions(+), 60 deletions(-)
New commits: commit 1e9e344b2ba076a5fd6d57d1705e17a59c3875ce Author: Behdad Esfahbod <[email protected]> Date: Tue Jul 17 19:17:59 2018 +0200 Fix hb_face_count() sanitize referencing diff --git a/src/hb-face.cc b/src/hb-face.cc index 2fef09d0..3c22f654 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -52,10 +52,13 @@ hb_face_count (hb_blob_t *blob) if (unlikely (!blob)) return 0; - hb_blob_t *sanitized = OT::Sanitizer<OT::OpenTypeFontFile> ().sanitize (blob); + /* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */ + hb_blob_t *sanitized = OT::Sanitizer<OT::OpenTypeFontFile> ().sanitize (hb_blob_reference (blob)); const OT::OpenTypeFontFile& ot = *sanitized->as<OT::OpenTypeFontFile> (); + unsigned int ret = ot.get_face_count (); + hb_blob_destroy (sanitized); - return ot.get_face_count (); + return ret; } /* commit a8cc0b5907e61199334a3a886fe22efe9cc17149 Author: Behdad Esfahbod <[email protected]> Date: Tue Jul 17 19:09:03 2018 +0200 Remove TODO that is not gonna be done Previously the idea was to cache sanitize results externally (think, in Fontconfig) and avoid resanitizing every time. That's, not a good idea. diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index 26afb909..457e58c4 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -283,8 +283,6 @@ struct hb_sanitize_context_t : { bool sane; - /* TODO is_sane() stuff */ - init (blob); retry: commit be7073840097c873ce4954c6cffadab175a007d3 Author: Behdad Esfahbod <[email protected]> Date: Tue Jul 17 18:45:25 2018 +0200 Move sanitizer code around a bit diff --git a/src/hb-aat-layout-common-private.hh b/src/hb-aat-layout-common-private.hh index 2825b181..d7f35052 100644 --- a/src/hb-aat-layout-common-private.hh +++ b/src/hb-aat-layout-common-private.hh @@ -161,7 +161,7 @@ struct LookupFormat0 inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (arrayZ.sanitize (c, c->num_glyphs)); + return_trace (arrayZ.sanitize (c, c->get_num_glyphs ())); } protected: @@ -625,7 +625,7 @@ struct hb_aat_apply_context_t : sanitizer (), lookup_index (0), debug_depth (0) { sanitizer.init (table); - sanitizer.num_glyphs = face->get_num_glyphs (); + sanitizer.set_num_glyphs (face->get_num_glyphs ()); sanitizer.start_processing (); } diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index f681c573..26afb909 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -182,6 +182,9 @@ struct hb_sanitize_context_t : this->writable = false; } + inline void set_num_glyphs (unsigned int num_glyphs_) { num_glyphs = num_glyphs_; } + inline unsigned int get_num_glyphs (void) { return num_glyphs; } + inline void start_processing (void) { this->start = hb_blob_get_data (this->blob, nullptr); @@ -275,74 +278,63 @@ struct hb_sanitize_context_t : return false; } - mutable unsigned int debug_depth; - const char *start, *end; - bool writable; - unsigned int edit_count; - mutable int max_ops; - hb_blob_t *blob; - unsigned int num_glyphs; -}; - - - -/* Template to sanitize an object. */ -template <typename Type> -struct Sanitizer -{ - inline Sanitizer (unsigned int num_glyphs = 0) { c->num_glyphs = num_glyphs; } - + template <typename Type> inline hb_blob_t *sanitize (hb_blob_t *blob) { bool sane; /* TODO is_sane() stuff */ - c->init (blob); + init (blob); retry: - DEBUG_MSG_FUNC (SANITIZE, c->start, "start"); + DEBUG_MSG_FUNC (SANITIZE, start, "start"); - c->start_processing (); + start_processing (); - if (unlikely (!c->start)) { - c->end_processing (); + if (unlikely (!start)) + { + end_processing (); return blob; } - Type *t = CastP<Type> (const_cast<char *> (c->start)); + Type *t = CastP<Type> (const_cast<char *> (start)); - sane = t->sanitize (c); - if (sane) { - if (c->edit_count) { - DEBUG_MSG_FUNC (SANITIZE, c->start, "passed first round with %d edits; going for second round", c->edit_count); + sane = t->sanitize (this); + if (sane) + { + if (edit_count) + { + DEBUG_MSG_FUNC (SANITIZE, start, "passed first round with %d edits; going for second round", edit_count); /* sanitize again to ensure no toe-stepping */ - c->edit_count = 0; - sane = t->sanitize (c); - if (c->edit_count) { - DEBUG_MSG_FUNC (SANITIZE, c->start, "requested %d edits in second round; FAILLING", c->edit_count); + edit_count = 0; + sane = t->sanitize (this); + if (edit_count) { + DEBUG_MSG_FUNC (SANITIZE, start, "requested %d edits in second round; FAILLING", edit_count); sane = false; } } - } else { - unsigned int edit_count = c->edit_count; - if (edit_count && !c->writable) { - c->start = hb_blob_get_data_writable (blob, nullptr); - c->end = c->start + blob->length; - - if (c->start) { - c->writable = true; + } + else + { + if (edit_count && !writable) { + start = hb_blob_get_data_writable (blob, nullptr); + end = start + blob->length; + + if (start) + { + writable = true; /* ok, we made it writable by relocating. try again */ - DEBUG_MSG_FUNC (SANITIZE, c->start, "retry"); + DEBUG_MSG_FUNC (SANITIZE, start, "retry"); goto retry; } } } - c->end_processing (); + end_processing (); - DEBUG_MSG_FUNC (SANITIZE, c->start, sane ? "PASSED" : "FAILED"); + DEBUG_MSG_FUNC (SANITIZE, start, sane ? "PASSED" : "FAILED"); if (sane) { blob->lock (); @@ -355,7 +347,24 @@ struct Sanitizer } } - inline void set_num_glyphs (unsigned int num_glyphs) { c->num_glyphs = num_glyphs; } + mutable unsigned int debug_depth; + const char *start, *end; + private: + bool writable; + unsigned int edit_count; + mutable int max_ops; + hb_blob_t *blob; + unsigned int num_glyphs; +}; + + + +/* Template to sanitize an object. */ +template <typename Type> +struct Sanitizer +{ + inline Sanitizer (unsigned int num_glyphs = 0) { c->set_num_glyphs (num_glyphs); } + inline hb_blob_t *sanitize (hb_blob_t *blob) { return c->sanitize<Type> (blob); } private: hb_sanitize_context_t c[1]; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 09a9517c..bf644a67 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -68,7 +68,7 @@ struct SBIXStrike { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - imageOffsetsZ.sanitize_shallow (c, c->num_glyphs + 1)); + imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1)); } protected: @@ -96,14 +96,11 @@ struct sbix { inline void init (hb_face_t *face) { - num_glyphs = hb_face_get_glyph_count (face); - - OT::Sanitizer<OT::sbix> sanitizer; - sanitizer.set_num_glyphs (num_glyphs); - sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix)); + /* XXX Using public API instead of private method to avoid link problem in dump_emoji. + * Kill that! */ + sbix_blob = OT::Sanitizer<OT::sbix>(hb_face_get_glyph_count (face)/*face->get_num_glyphs ()*/).sanitize (face->reference_table (HB_OT_TAG_sbix)); sbix_len = hb_blob_get_length (sbix_blob); sbix_table = sbix_blob->as<OT::sbix> (); - } inline void fini (void) @@ -134,7 +131,6 @@ struct sbix unsigned int sbix_len; unsigned int num_glyphs; - }; protected: diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh index 21a8382c..2ae1157d 100644 --- a/src/hb-ot-layout-common-private.hh +++ b/src/hb-ot-layout-common-private.hh @@ -540,9 +540,6 @@ struct Feature c->try_set (&featureParams, new_offset) && !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE)) return_trace (false); - - if (c->edit_count > 1) - c->edit_count--; /* This was a "legitimate" edit; don't contribute to error count. */ } return_trace (true); _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
