From bff78e651555e6376d2a4b49c323cf5e9fe3a25c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 10 May 2022 16:33:37 -0600 Subject: [PATCH] [cff] Convert interpretation environment to use constructor --- src/hb-cff-interp-common.hh | 29 ++++++++--------------------- src/hb-cff-interp-cs-common.hh | 13 +++++-------- src/hb-cff-interp-dict-common.hh | 2 ++ src/hb-cff1-interp-cs.hh | 8 +++----- src/hb-cff2-interp-cs.hh | 9 ++++----- src/hb-ot-cff1-table.cc | 16 ++++++++-------- src/hb-ot-cff1-table.hh | 19 ++++++++++--------- src/hb-ot-cff2-table.cc | 8 ++++---- src/hb-ot-cff2-table.hh | 24 ++++++++++-------------- src/hb-subset-cff-common.hh | 8 ++++---- 10 files changed, 58 insertions(+), 78 deletions(-) diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 1f924d8b8..058dc0cdd 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -351,13 +351,6 @@ using byte_str_array_t = hb_vector_t; template struct cff_stack_t { - void init () - { - error = false; - count = 0; - } - void fini () {} - ELEM& operator [] (unsigned int i) { if (unlikely (i >= count)) @@ -434,8 +427,8 @@ struct cff_stack_t { return hb_array_t (elements).sub_array (start, length); } private: - bool error; - unsigned int count; + bool error = false; + unsigned int count = 0; ELEM elements[LIMIT]; }; @@ -561,14 +554,11 @@ struct parsed_values_t template struct interp_env_t { - void init (const hb_ubytes_t &str_) + interp_env_t () {} + interp_env_t (const hb_ubytes_t &str_) { str_ref.reset (str_); - argStack.init (); - error = false; } - void fini () { argStack.fini (); } - bool in_error () const { return error || str_ref.in_error () || argStack.in_error (); } @@ -602,10 +592,10 @@ struct interp_env_t arg_stack_t argStack; protected: - bool error; + bool error = false; }; -typedef interp_env_t<> num_interp_env_t; +using num_interp_env_t = interp_env_t<>; template struct opset_t @@ -648,11 +638,8 @@ struct opset_t template struct interpreter_t { - ~interpreter_t() { fini (); } - - void fini () { env.fini (); } - - ENV env; + interpreter_t (ENV& env_) : env (env_) {} + ENV& env; }; } /* namespace CFF */ diff --git a/src/hb-cff-interp-cs-common.hh b/src/hb-cff-interp-cs-common.hh index a06490b65..2983ae54a 100644 --- a/src/hb-cff-interp-cs-common.hh +++ b/src/hb-cff-interp-cs-common.hh @@ -112,10 +112,9 @@ struct point_t template struct cs_interp_env_t : interp_env_t { - void init (const hb_ubytes_t &str, const SUBRS *globalSubrs_, const SUBRS *localSubrs_) + cs_interp_env_t (const hb_ubytes_t &str, const SUBRS *globalSubrs_, const SUBRS *localSubrs_) : + interp_env_t (str) { - interp_env_t::init (str); - context.init (str, CSType_CharString); seen_moveto = true; seen_hintmask = false; @@ -123,15 +122,11 @@ struct cs_interp_env_t : interp_env_t vstem_count = 0; hintmask_size = 0; pt.set_int (0, 0); - callStack.init (); globalSubrs.init (globalSubrs_); localSubrs.init (localSubrs_); } - void fini () + ~cs_interp_env_t () { - interp_env_t::fini (); - - callStack.fini (); globalSubrs.fini (); localSubrs.fini (); } @@ -880,6 +875,8 @@ struct path_procs_t template struct cs_interpreter_t : interpreter_t { + cs_interpreter_t (ENV& env_) : interpreter_t (env_) {} + bool interpret (PARAM& param) { SUPER::env.set_endchar (false); diff --git a/src/hb-cff-interp-dict-common.hh b/src/hb-cff-interp-dict-common.hh index a520ca3bc..79fe9b42c 100644 --- a/src/hb-cff-interp-dict-common.hh +++ b/src/hb-cff-interp-dict-common.hh @@ -179,6 +179,8 @@ struct top_dict_opset_t : dict_opset_t template struct dict_interpreter_t : interpreter_t { + dict_interpreter_t (ENV& env_) : interpreter_t (env_) {} + bool interpret (PARAM& param) { param.init (); diff --git a/src/hb-cff1-interp-cs.hh b/src/hb-cff1-interp-cs.hh index 5494a3de3..b306c2ecc 100644 --- a/src/hb-cff1-interp-cs.hh +++ b/src/hb-cff1-interp-cs.hh @@ -38,17 +38,15 @@ typedef biased_subrs_t cff1_biased_subrs_t; struct cff1_cs_interp_env_t : cs_interp_env_t { template - void init (const hb_ubytes_t &str, ACC &acc, unsigned int fd) + cff1_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd) + : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs) { - SUPER::init (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs); processed_width = false; has_width = false; arg_start = 0; in_seac = false; } - void fini () { SUPER::fini (); } - void set_width (bool has_width_) { if (likely (!processed_width && (SUPER::argStack.get_count () > 0))) @@ -154,7 +152,7 @@ struct cff1_cs_opset_t : cs_opset_t -struct cff1_cs_interpreter_t : cs_interpreter_t {}; +using cff1_cs_interpreter_t = cs_interpreter_t; } /* namespace CFF */ diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 6a0b6de61..d0b9e7b08 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -68,11 +68,10 @@ template struct cff2_cs_interp_env_t : cs_interp_env_t { template - void init (const hb_ubytes_t &str, ACC &acc, unsigned int fd, - const int *coords_=nullptr, unsigned int num_coords_=0) + cff2_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd, + const int *coords_=nullptr, unsigned int num_coords_=0) + : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs) { - SUPER::init (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs); - coords = coords_; num_coords = num_coords_; varStore = acc.varStore; @@ -269,7 +268,7 @@ struct cff2_cs_opset_t : cs_opset_t, PAR }; template -struct cff2_cs_interpreter_t : cs_interpreter_t, OPSET, PARAM> {}; +using cff2_cs_interpreter_t = cs_interpreter_t, OPSET, PARAM>; } /* namespace CFF */ diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index d02c7122c..bd9fe5d6d 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -393,10 +393,10 @@ bool _get_bounds (const OT::cff1::accelerator_t *cff, hb_codepoint_t glyph, boun if (unlikely (!cff->is_valid () || (glyph >= cff->num_glyphs))) return false; unsigned int fd = cff->fdSelect->get_fd (glyph); - cff1_cs_interpreter_t interp; const hb_ubytes_t str = (*cff->charStrings)[glyph]; - interp.env.init (str, *cff, fd); - interp.env.set_in_seac (in_seac); + cff1_cs_interp_env_t env (str, *cff, fd); + env.set_in_seac (in_seac); + cff1_cs_interpreter_t interp (env); cff1_extents_param_t param (cff); if (unlikely (!interp.interpret (param))) return false; bounds = param.bounds; @@ -538,10 +538,10 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin if (unlikely (!cff->is_valid () || (glyph >= cff->num_glyphs))) return false; unsigned int fd = cff->fdSelect->get_fd (glyph); - cff1_cs_interpreter_t interp; const hb_ubytes_t str = (*cff->charStrings)[glyph]; - interp.env.init (str, *cff, fd); - interp.env.set_in_seac (in_seac); + cff1_cs_interp_env_t env (str, *cff, fd); + env.set_in_seac (in_seac); + cff1_cs_interpreter_t interp (env); cff1_path_param_t param (cff, font, draw_session, delta); if (unlikely (!interp.interpret (param))) return false; @@ -590,9 +590,9 @@ bool OT::cff1::accelerator_t::get_seac_components (hb_codepoint_t glyph, hb_code if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; unsigned int fd = fdSelect->get_fd (glyph); - cff1_cs_interpreter_t interp; const hb_ubytes_t str = (*charStrings)[glyph]; - interp.env.init (str, *this, fd); + cff1_cs_interp_env_t env (str, *this, fd); + cff1_cs_interpreter_t interp (env); get_seac_param_t param (this); if (unlikely (!interp.interpret (param))) return false; diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index e527b5fd5..db614fe7e 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -602,6 +602,8 @@ struct cff1_top_dict_interp_env_t : num_interp_env_t { cff1_top_dict_interp_env_t () : num_interp_env_t(), prev_offset(0), last_offset(0) {} + cff1_top_dict_interp_env_t (const hb_ubytes_t &bytes) + : num_interp_env_t(bytes), prev_offset(0), last_offset(0) {} unsigned int prev_offset; unsigned int last_offset; @@ -1026,9 +1028,8 @@ struct cff1 { /* parse top dict */ 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); - topDict.init (); + cff1_top_dict_interp_env_t env (topDictStr); + cff1_top_dict_interpreter_t top_interp (env); if (unlikely (!top_interp.interpret (topDict))) { fini (); return; } } @@ -1101,8 +1102,8 @@ struct cff1 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; - font_interp.env.init (fontDictStr); + cff1_top_dict_interp_env_t env (fontDictStr); + cff1_font_dict_interpreter_t font_interp (env); font = fontDicts.push (); if (unlikely (font == &Crap (cff1_font_dict_values_t))) { fini (); return; } font->init (); @@ -1110,8 +1111,8 @@ struct cff1 PRIVDICTVAL *priv = &privateDicts[i]; 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); + num_interp_env_t env2 (privDictStr); + dict_interpreter_t priv_interp (env2); priv->init (); if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; } @@ -1128,8 +1129,8 @@ struct cff1 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); + num_interp_env_t env (privDictStr); + dict_interpreter_t priv_interp (env); priv->init (); if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; } diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc index e41ae2836..50c76daf9 100644 --- a/src/hb-ot-cff2-table.cc +++ b/src/hb-ot-cff2-table.cc @@ -111,9 +111,9 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; unsigned int fd = fdSelect->get_fd (glyph); - cff2_cs_interpreter_t interp; const hb_ubytes_t str = (*charStrings)[glyph]; - interp.env.init (str, *this, fd, font->coords, font->num_coords); + cff2_cs_interp_env_t env (str, *this, fd, font->coords, font->num_coords); + cff2_cs_interpreter_t interp (env); cff2_extents_param_t param; if (unlikely (!interp.interpret (param))) return false; @@ -200,9 +200,9 @@ bool OT::cff2::accelerator_t::get_path (hb_font_t *font, hb_codepoint_t glyph, h if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; unsigned int fd = fdSelect->get_fd (glyph); - cff2_cs_interpreter_t interp; const hb_ubytes_t str = (*charStrings)[glyph]; - interp.env.init (str, *this, fd, font->coords, font->num_coords); + cff2_cs_interp_env_t env (str, *this, fd, font->coords, font->num_coords); + cff2_cs_interpreter_t interp (env); cff2_path_param_t param (font, draw_session); if (unlikely (!interp.interpret (param))) return false; return true; diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 843a0c3c6..746160dc8 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -247,12 +247,8 @@ 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 hb_ubytes_t &str) - { - num_interp_env_t::init (str); - ivs = 0; - seen_vsindex = false; - } + cff2_priv_dict_interp_env_t (const hb_ubytes_t &str) : + num_interp_env_t (str) {} void process_vsindex () { @@ -267,8 +263,8 @@ struct cff2_priv_dict_interp_env_t : num_interp_env_t void set_ivs (unsigned int ivs_) { ivs = ivs_; } protected: - unsigned int ivs; - bool seen_vsindex; + unsigned int ivs = 0; + bool seen_vsindex = false; }; struct cff2_private_dict_opset_t : dict_opset_t @@ -417,8 +413,8 @@ struct cff2 { /* parse top dict */ 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); + num_interp_env_t env (topDictStr); + cff2_top_dict_interpreter_t top_interp (env); topDict.init (); if (unlikely (!top_interp.interpret (topDict))) goto fail; } @@ -450,8 +446,8 @@ struct cff2 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; - font_interp.env.init (fontDictStr); + num_interp_env_t env (fontDictStr); + cff2_font_dict_interpreter_t font_interp (env); font = fontDicts.push (); if (unlikely (font == &Crap (cff2_font_dict_values_t))) goto fail; font->init (); @@ -459,8 +455,8 @@ struct cff2 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); + cff2_priv_dict_interp_env_t env2 (privDictStr); + dict_interpreter_t priv_interp (env2); privateDicts[i].init (); if (unlikely (!priv_interp.interpret (privateDicts[i]))) goto fail; diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index e7d83c3ef..e3fae0850 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -257,8 +257,8 @@ struct subr_flattener_t unsigned int fd = acc.fdSelect->get_fd (glyph); if (unlikely (fd >= acc.fdCount)) return false; - cs_interpreter_t interp; - interp.env.init (str, acc, fd); + ENV env (str, acc, fd); + cs_interpreter_t interp (env); flatten_param_t param = { flat_charstrings[i], (bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING) @@ -566,8 +566,8 @@ struct subr_subsetter_t if (unlikely (fd >= acc.fdCount)) return false; - cs_interpreter_t interp; - interp.env.init (str, acc, fd); + ENV env (str, acc, fd); + cs_interpreter_t interp (env); subr_subset_param_t param (&parsed_charstrings[i], &parsed_global_subrs,