From fe1d85a55a53797f0808d1f473475b7ce15eeb92 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 16:04:52 -0600 Subject: [PATCH] [cff] Remove custom byte_str_t impl --- src/hb-cff-interp-common.hh | 35 ++++++++++------------------------- src/hb-ot-cff1-table.hh | 4 ++-- src/hb-ot-cff2-table.hh | 4 ++-- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 641de0eff..f88e0cce8 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -248,6 +248,9 @@ struct number_t /* byte string */ struct UnsizedByteStr : UnsizedArrayOf { + hb_ubytes_t as_ubytes (unsigned l) const + { return hb_ubytes_t ((const unsigned char *) this, l); } + // encode 2-byte int (Dict/CharString) or 4-byte int (Dict) template static bool serialize_int (hb_serialize_context_t *c, op_code_t intOp, V value) @@ -281,25 +284,7 @@ struct UnsizedByteStr : UnsizedArrayOf DEFINE_SIZE_MIN(0); }; -/* Holder of a section of byte string within a CFFIndex entry */ -struct byte_str_t : hb_ubytes_t -{ - byte_str_t () - : hb_ubytes_t () {} - byte_str_t (const UnsizedByteStr& s, unsigned int l) - : hb_ubytes_t ((const unsigned char*)&s, l) {} - byte_str_t (const unsigned char *s, unsigned int l) - : hb_ubytes_t (s, l) {} - byte_str_t (const hb_ubytes_t &ub) /* conversion from hb_ubytes_t */ - : hb_ubytes_t (ub) {} - - /* sub-string */ - byte_str_t sub_str (unsigned int offset, unsigned int len_) const - { return byte_str_t (hb_ubytes_t::sub_array (offset, len_)); } - - bool check_limit (unsigned int offset, unsigned int count) const - { return (offset + count <= length); } -}; +using byte_str_t = hb_ubytes_t; /* A byte string associated with the current offset and an error condition */ struct byte_str_ref_t @@ -335,13 +320,13 @@ struct byte_str_ref_t } /* Conversion to byte_str_t */ - operator byte_str_t () const { return str.sub_str (offset, str.length - offset); } + operator byte_str_t () const { return str.sub_array (offset, str.length - offset); } - byte_str_t sub_str (unsigned int offset_, unsigned int len_) const - { return str.sub_str (offset_, len_); } + byte_str_t sub_array (unsigned int offset_, unsigned int len_) const + { return str.sub_array (offset_, len_); } bool avail (unsigned int count=1) const - { return (!in_error () && str.check_limit (offset, count)); } + { return (!in_error () && offset + count <= str.length); } void inc (unsigned int count=1) { if (likely (!in_error () && (offset <= str.length) && (offset + count <= str.length))) @@ -551,7 +536,7 @@ struct parsed_values_t { VAL *val = values.push (); val->op = op; - val->str = str_ref.str.sub_str (opStart, str_ref.offset - opStart); + val->str = str_ref.str.sub_array (opStart, str_ref.offset - opStart); opStart = str_ref.offset; } @@ -559,7 +544,7 @@ struct parsed_values_t { VAL *val = values.push (v); val->op = op; - val->str = str_ref.sub_str ( opStart, str_ref.offset - opStart); + val->str = str_ref.sub_array ( opStart, str_ref.offset - opStart); opStart = str_ref.offset; } diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 542e3f4de..dd3c3fa73 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1108,7 +1108,7 @@ struct cff1 font->init (); if (unlikely (!font_interp.interpret (*font))) { fini (); return; } PRIVDICTVAL *priv = &privateDicts[i]; - const byte_str_t privDictStr (StructAtOffset (cff, font->privateDictInfo.offset), font->privateDictInfo.size); + const byte_str_t privDictStr = StructAtOffset (cff, font->privateDictInfo.offset).as_ubytes (font->privateDictInfo.size); if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } dict_interpreter_t priv_interp; priv_interp.env.init (privDictStr); @@ -1126,7 +1126,7 @@ struct cff1 cff1_top_dict_values_t *font = &topDict; PRIVDICTVAL *priv = &privateDicts[0]; - const byte_str_t privDictStr (StructAtOffset (cff, font->privateDictInfo.offset), font->privateDictInfo.size); + const byte_str_t privDictStr = StructAtOffset (cff, font->privateDictInfo.offset).as_ubytes (font->privateDictInfo.size); if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } dict_interpreter_t priv_interp; priv_interp.env.init (privDictStr); diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index b77e7f53f..415525580 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -415,7 +415,7 @@ struct cff2 goto fail; { /* parse top dict */ - byte_str_t topDictStr (cff2 + cff2->topDict, cff2->topDictSize); + byte_str_t topDictStr = (cff2 + cff2->topDict).as_ubytes (cff2->topDictSize); if (unlikely (!topDictStr.sanitize (&sc))) goto fail; cff2_top_dict_interpreter_t top_interp; top_interp.env.init (topDictStr); @@ -457,7 +457,7 @@ struct cff2 font->init (); if (unlikely (!font_interp.interpret (*font))) goto fail; - const byte_str_t privDictStr (StructAtOffsetOrNull (cff2, font->privateDictInfo.offset), font->privateDictInfo.size); + const byte_str_t privDictStr = StructAtOffsetOrNull (cff2, font->privateDictInfo.offset).as_ubytes (font->privateDictInfo.size); if (unlikely (!privDictStr.sanitize (&sc))) goto fail; dict_interpreter_t priv_interp; priv_interp.env.init(privDictStr);