From 8aa54aaca250e2934bd2c97047db8b40bf027908 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 9 May 2022 16:09:56 -0600 Subject: [PATCH] [cff] Replace byte_str_t with hb_bytes_t use --- src/hb-cff-interp-common.hh | 25 ++++++++++--------------- src/hb-cff-interp-cs-common.hh | 6 +++--- src/hb-cff1-interp-cs.hh | 2 +- src/hb-cff2-interp-cs.hh | 2 +- src/hb-ot-cff-common.hh | 14 +++++++------- src/hb-ot-cff1-table.cc | 6 +++--- src/hb-ot-cff1-table.hh | 12 ++++++------ src/hb-ot-cff2-table.cc | 4 ++-- src/hb-ot-cff2-table.hh | 8 ++++---- src/hb-subset-cff-common.hh | 6 +++--- src/hb-subset-cff1.cc | 2 +- 11 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index f88e0cce8..c9426e72c 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -277,15 +277,10 @@ struct UnsizedByteStr : UnsizedArrayOf /* Defining null_size allows a Null object may be created. Should be safe because: * A descendent struct Dict uses a Null pointer to indicate a missing table, * checked before access. - * byte_str_t, a wrapper struct pairing a byte pointer along with its length, always - * checks the length before access. A Null pointer is used as the initial pointer - * along with zero length by the default ctor. */ DEFINE_SIZE_MIN(0); }; -using byte_str_t = hb_ubytes_t; - /* A byte string associated with the current offset and an error condition */ struct byte_str_ref_t { @@ -293,17 +288,17 @@ struct byte_str_ref_t void init () { - str = byte_str_t (); + str = hb_ubytes_t (); offset = 0; error = false; } void fini () {} - byte_str_ref_t (const byte_str_t &str_, unsigned int offset_ = 0) + byte_str_ref_t (const hb_ubytes_t &str_, unsigned int offset_ = 0) : str (str_), offset (offset_), error (false) {} - void reset (const byte_str_t &str_, unsigned int offset_ = 0) + void reset (const hb_ubytes_t &str_, unsigned int offset_ = 0) { str = str_; offset = offset_; @@ -319,10 +314,10 @@ struct byte_str_ref_t return str[offset + i]; } - /* Conversion to byte_str_t */ - operator byte_str_t () const { return str.sub_array (offset, str.length - offset); } + /* Conversion to hb_ubytes_t */ + operator hb_ubytes_t () const { return str.sub_array (offset, str.length - offset); } - byte_str_t sub_array (unsigned int offset_, unsigned int len_) const + hb_ubytes_t sub_array (unsigned int offset_, unsigned int len_) const { return str.sub_array (offset_, len_); } bool avail (unsigned int count=1) const @@ -343,14 +338,14 @@ struct byte_str_ref_t void set_error () { error = true; } bool in_error () const { return error; } - byte_str_t str; + hb_ubytes_t str; unsigned int offset; /* beginning of the sub-string within str */ protected: bool error; }; -typedef hb_vector_t byte_str_array_t; +typedef hb_vector_t byte_str_array_t; /* stack */ template @@ -504,7 +499,7 @@ struct arg_stack_t : cff_stack_t struct op_str_t { op_code_t op; - byte_str_t str; + hb_ubytes_t str; }; /* base of OP_SERIALIZER */ @@ -566,7 +561,7 @@ struct parsed_values_t template struct interp_env_t { - void init (const byte_str_t &str_) + void init (const hb_ubytes_t &str_) { str_ref.reset (str_); argStack.init (); diff --git a/src/hb-cff-interp-cs-common.hh b/src/hb-cff-interp-cs-common.hh index ef299369b..26232f4e7 100644 --- a/src/hb-cff-interp-cs-common.hh +++ b/src/hb-cff-interp-cs-common.hh @@ -79,10 +79,10 @@ struct biased_subrs_t unsigned int get_count () const { return subrs ? subrs->count : 0; } unsigned int get_bias () const { return bias; } - byte_str_t operator [] (unsigned int index) const + hb_ubytes_t operator [] (unsigned int index) const { if (unlikely (!subrs || index >= subrs->count)) - return Null (byte_str_t); + return Null (hb_ubytes_t); else return (*subrs)[index]; } @@ -112,7 +112,7 @@ struct point_t template struct cs_interp_env_t : interp_env_t { - void init (const byte_str_t &str, const SUBRS *globalSubrs_, const SUBRS *localSubrs_) + void init (const hb_ubytes_t &str, const SUBRS *globalSubrs_, const SUBRS *localSubrs_) { interp_env_t::init (str); diff --git a/src/hb-cff1-interp-cs.hh b/src/hb-cff1-interp-cs.hh index 1c8762c17..5494a3de3 100644 --- a/src/hb-cff1-interp-cs.hh +++ b/src/hb-cff1-interp-cs.hh @@ -38,7 +38,7 @@ typedef biased_subrs_t cff1_biased_subrs_t; struct cff1_cs_interp_env_t : cs_interp_env_t { template - void init (const byte_str_t &str, ACC &acc, unsigned int fd) + void init (const hb_ubytes_t &str, ACC &acc, unsigned int fd) { SUPER::init (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs); processed_width = false; diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 766183760..60a29e1ca 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -67,7 +67,7 @@ typedef biased_subrs_t cff2_biased_subrs_t; struct cff2_cs_interp_env_t : cs_interp_env_t { template - void init (const byte_str_t &str, ACC &acc, unsigned int fd, + void init (const hb_ubytes_t &str, ACC &acc, unsigned int fd, const int *coords_=nullptr, unsigned int num_coords_=0) { SUPER::init (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs); diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 53fe8bc23..7500615bb 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -115,7 +115,7 @@ struct CFFIndex /* serialize data */ for (unsigned int i = 0; i < byteArray.length; i++) { - const byte_str_t &bs = byteArray[i]; + const hb_ubytes_t &bs = byteArray[i]; unsigned char *dest = c->allocate_size (bs.length); if (unlikely (!dest)) return_trace (false); memcpy (dest, &bs[0], bs.length); @@ -132,7 +132,7 @@ struct CFFIndex byteArray.init (); byteArray.resize (buffArray.length); for (unsigned int i = 0; i < byteArray.length; i++) - byteArray[i] = byte_str_t (buffArray[i].arrayZ, buffArray[i].length); + byteArray[i] = hb_ubytes_t (buffArray[i].arrayZ, buffArray[i].length); bool result = this->serialize (c, offSize_, byteArray); byteArray.fini (); return result; @@ -144,7 +144,7 @@ struct CFFIndex Iterator it) { TRACE_SERIALIZE (this); - serialize_header(c, + it | hb_map ([] (const byte_str_t &_) { return _.length; })); + serialize_header(c, + it | hb_map ([] (const hb_ubytes_t &_) { return _.length; })); for (const auto &_ : +it) _.copy (c); return_trace (true); @@ -159,7 +159,7 @@ struct CFFIndex { auto it = + hb_iter (buffArray) - | hb_map ([] (const str_buff_t &_) { return byte_str_t (_.arrayZ, _.length); }) + | hb_map ([] (const str_buff_t &_) { return hb_ubytes_t (_.arrayZ, _.length); }) ; return serialize (c, it); } @@ -233,10 +233,10 @@ struct CFFIndex { return (const unsigned char *) this + min_size + offSize.static_size + offset_array_size (); } public: - byte_str_t operator [] (unsigned int index) const + hb_ubytes_t operator [] (unsigned int index) const { - if (unlikely (index >= count)) return byte_str_t (); - return byte_str_t (data_base () + offset_at (index) - 1, length_at (index)); + if (unlikely (index >= count)) return hb_ubytes_t (); + return hb_ubytes_t (data_base () + offset_at (index) - 1, length_at (index)); } unsigned int get_size () const diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index df4554ac0..8bec26f27 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -396,7 +396,7 @@ bool _get_bounds (const OT::cff1::accelerator_t *cff, hb_codepoint_t glyph, boun unsigned int fd = cff->fdSelect->get_fd (glyph); cff1_cs_interpreter_t interp; - const byte_str_t str = (*cff->charStrings)[glyph]; + const hb_ubytes_t str = (*cff->charStrings)[glyph]; interp.env.init (str, *cff, fd); interp.env.set_in_seac (in_seac); cff1_extents_param_t param; @@ -542,7 +542,7 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin unsigned int fd = cff->fdSelect->get_fd (glyph); cff1_cs_interpreter_t interp; - const byte_str_t str = (*cff->charStrings)[glyph]; + const hb_ubytes_t str = (*cff->charStrings)[glyph]; interp.env.init (str, *cff, fd); interp.env.set_in_seac (in_seac); cff1_path_param_t param (cff, font, draw_session, delta); @@ -599,7 +599,7 @@ bool OT::cff1::accelerator_t::get_seac_components (hb_codepoint_t glyph, hb_code unsigned int fd = fdSelect->get_fd (glyph); cff1_cs_interpreter_t interp; - const byte_str_t str = (*charStrings)[glyph]; + const hb_ubytes_t str = (*charStrings)[glyph]; interp.env.init (str, *this, fd); get_seac_param_t param; param.init (this); diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index dd3c3fa73..e527b5fd5 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1024,7 +1024,7 @@ struct cff1 { fini (); return; } { /* parse top dict */ - const byte_str_t topDictStr = (*topDictIndex)[0]; + const hb_ubytes_t topDictStr = (*topDictIndex)[0]; if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; } cff1_top_dict_interpreter_t top_interp; top_interp.env.init (topDictStr); @@ -1098,7 +1098,7 @@ struct cff1 { for (unsigned int i = 0; i < fdCount; i++) { - byte_str_t fontDictStr = (*fdArray)[i]; + hb_ubytes_t fontDictStr = (*fdArray)[i]; if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; } cff1_font_dict_values_t *font; cff1_font_dict_interpreter_t font_interp; @@ -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).as_ubytes (font->privateDictInfo.size); + const hb_ubytes_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).as_ubytes (font->privateDictInfo.size); + const hb_ubytes_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); @@ -1287,7 +1287,7 @@ struct cff1 gname.name = cff1_std_strings (sid); else { - byte_str_t ustr = (*stringIndex)[sid - cff1_std_strings_length]; + hb_ubytes_t ustr = (*stringIndex)[sid - cff1_std_strings_length]; gname.name = hb_bytes_t ((const char*)ustr.arrayZ, ustr.length); } if (unlikely (!gname.name.arrayZ)) { fini (); return; } @@ -1319,7 +1319,7 @@ struct cff1 } else { - byte_str_t ubyte_str = (*stringIndex)[sid - cff1_std_strings_length]; + hb_ubytes_t ubyte_str = (*stringIndex)[sid - cff1_std_strings_length]; str = (const char *)ubyte_str.arrayZ; str_len = ubyte_str.length; } diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index 817fe064c..7849c5a88 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -113,7 +113,7 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, unsigned int fd = fdSelect->get_fd (glyph); cff2_cs_interpreter_t interp; - const byte_str_t str = (*charStrings)[glyph]; + const hb_ubytes_t str = (*charStrings)[glyph]; interp.env.init (str, *this, fd, font->coords, font->num_coords); cff2_extents_param_t param; param.init (); @@ -203,7 +203,7 @@ bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, h unsigned int fd = fdSelect->get_fd (glyph); cff2_cs_interpreter_t interp; - const byte_str_t str = (*charStrings)[glyph]; + const hb_ubytes_t str = (*charStrings)[glyph]; interp.env.init (str, *this, fd, font->coords, font->num_coords); cff2_path_param_t param (font, draw_session); if (unlikely (!interp.interpret (param))) return false; diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 415525580..843a0c3c6 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -247,7 +247,7 @@ typedef cff2_private_dict_values_base_t cff2_private_dict_values struct cff2_priv_dict_interp_env_t : num_interp_env_t { - void init (const byte_str_t &str) + void init (const hb_ubytes_t &str) { num_interp_env_t::init (str); ivs = 0; @@ -415,7 +415,7 @@ struct cff2 goto fail; { /* parse top dict */ - byte_str_t topDictStr = (cff2 + cff2->topDict).as_ubytes (cff2->topDictSize); + hb_ubytes_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); @@ -447,7 +447,7 @@ struct cff2 /* parse font dicts and gather private dicts */ for (unsigned int i = 0; i < fdCount; i++) { - const byte_str_t fontDictStr = (*fdArray)[i]; + const hb_ubytes_t fontDictStr = (*fdArray)[i]; if (unlikely (!fontDictStr.sanitize (&sc))) goto fail; cff2_font_dict_values_t *font; cff2_font_dict_interpreter_t font_interp; @@ -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).as_ubytes (font->privateDictInfo.size); + const hb_ubytes_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); diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 18657705f..ebc4f59ab 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -107,7 +107,7 @@ struct str_encoder_t encode_byte (op); } - void copy_str (const byte_str_t &str) + void copy_str (const hb_ubytes_t &str) { unsigned int offset = buff.length; if (unlikely (!buff.resize (offset + str.length))) @@ -253,7 +253,7 @@ struct subr_flattener_t if (endchar_op != OpCode_Invalid) flat_charstrings[i].push (endchar_op); continue; } - const byte_str_t str = (*acc.charStrings)[glyph]; + const hb_ubytes_t str = (*acc.charStrings)[glyph]; unsigned int fd = acc.fdSelect->get_fd (glyph); if (unlikely (fd >= acc.fdCount)) return false; @@ -561,7 +561,7 @@ struct subr_subsetter_t hb_codepoint_t glyph; if (!plan->old_gid_for_new_gid (i, &glyph)) continue; - const byte_str_t str = (*acc.charStrings)[glyph]; + const hb_ubytes_t str = (*acc.charStrings)[glyph]; unsigned int fd = acc.fdSelect->get_fd (glyph); if (unlikely (fd >= acc.fdCount)) return false; diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 35fecd67b..6b187335a 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -169,7 +169,7 @@ struct cff1_top_dict_op_serializer_t : cff_top_dict_op_serializer_t= opstr.last_arg_offset + 3))) return_trace (false); - supp_op.str = byte_str_t (&opstr.str + opstr.last_arg_offset, opstr.str.length - opstr.last_arg_offset); + supp_op.str = hb_ubytes_t (&opstr.str + opstr.last_arg_offset, opstr.str.length - opstr.last_arg_offset); return_trace (UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[name_dict_values_t::registry]) && UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[name_dict_values_t::ordering]) && copy_opstr (c, supp_op));