From ae208963dfd9bf3354b2eaa194bf2f4b5ec60c99 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 26 Dec 2022 12:30:39 -0700 Subject: [PATCH] Add hb-limits.hh --- src/Makefile.sources | 1 + src/OT/glyf/Glyph.hh | 5 -- src/hb-buffer.hh | 20 ------- src/hb-cff-interp-cs-common.hh | 3 +- src/hb-ft-colr.hh | 9 +-- src/hb-limits.hh | 105 +++++++++++++++++++++++++++++++++ src/hb-ot-color-colr-table.hh | 14 +---- src/hb-ot-layout-common.hh | 36 ----------- src/hb.hh | 1 + src/meson.build | 1 + 10 files changed, 113 insertions(+), 82 deletions(-) create mode 100644 src/hb-limits.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index e009dce80..df4e4ea20 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -47,6 +47,7 @@ HB_BASE_sources = \ hb-font.hh \ hb-iter.hh \ hb-kern.hh \ + hb-limits.hh \ hb-machinery.hh \ hb-map.cc \ hb-map.hh \ diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 5ece5b400..e1b8087f3 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -18,11 +18,6 @@ struct glyf_accelerator_t; namespace glyf_impl { -#ifndef HB_GLYF_MAX_POINTS -#define HB_GLYF_MAX_POINTS 10000 -#endif - - enum phantom_point_index_t { PHANTOM_LEFT = 0, diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh index bb1efe9dd..6f45900e8 100644 --- a/src/hb-buffer.hh +++ b/src/hb-buffer.hh @@ -35,26 +35,6 @@ #include "hb-set-digest.hh" -#ifndef HB_BUFFER_MAX_LEN_FACTOR -#define HB_BUFFER_MAX_LEN_FACTOR 64 -#endif -#ifndef HB_BUFFER_MAX_LEN_MIN -#define HB_BUFFER_MAX_LEN_MIN 16384 -#endif -#ifndef HB_BUFFER_MAX_LEN_DEFAULT -#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */ -#endif - -#ifndef HB_BUFFER_MAX_OPS_FACTOR -#define HB_BUFFER_MAX_OPS_FACTOR 1024 -#endif -#ifndef HB_BUFFER_MAX_OPS_MIN -#define HB_BUFFER_MAX_OPS_MIN 16384 -#endif -#ifndef HB_BUFFER_MAX_OPS_DEFAULT -#define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */ -#endif - static_assert ((sizeof (hb_glyph_info_t) == 20), ""); static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); diff --git a/src/hb-cff-interp-cs-common.hh b/src/hb-cff-interp-cs-common.hh index f93c83ab4..f40be51f0 100644 --- a/src/hb-cff-interp-cs-common.hh +++ b/src/hb-cff-interp-cs-common.hh @@ -57,7 +57,6 @@ struct call_context_t /* call stack */ const unsigned int kMaxCallLimit = 10; -const unsigned int kMaxOps = 10000; struct call_stack_t : cff_stack_t {}; template @@ -882,7 +881,7 @@ struct cs_interpreter_t : interpreter_t { SUPER::env.set_endchar (false); - unsigned max_ops = kMaxOps; + unsigned max_ops = HB_CFF_MAX_OPS; for (;;) { if (unlikely (!--max_ops)) { diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 7b74c3d1c..e3abeac85 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -35,13 +35,6 @@ #ifdef TT_SUPPORT_COLRV1 -#ifndef HB_COLRV1_MAX_NESTING_LEVEL -#define HB_COLRV1_MAX_NESTING_LEVEL 128 -#endif - -#ifndef HB_COLRV1_MAX_EDGE_COUNT -#define HB_COLRV1_MAX_EDGE_COUNT 1024 -#endif static hb_paint_composite_mode_t _hb_ft_paint_composite_mode (FT_Composite_Mode mode) @@ -115,7 +108,7 @@ struct hb_ft_paint_context_t void *data; FT_Color *palette; hb_color_t foreground; - int depth_left = HB_COLRV1_MAX_NESTING_LEVEL; + int depth_left = HB_MAX_NESTING_LEVEL; int edge_count = HB_COLRV1_MAX_EDGE_COUNT; }; diff --git a/src/hb-limits.hh b/src/hb-limits.hh new file mode 100644 index 000000000..7481a5235 --- /dev/null +++ b/src/hb-limits.hh @@ -0,0 +1,105 @@ +/* + * Copyright © 2022 Behdad Esfahbod + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#ifndef HB_LIMITS_HH +#define HB_LIMITS_HH + +#include "hb.hh" + + +#ifndef HB_BUFFER_MAX_LEN_FACTOR +#define HB_BUFFER_MAX_LEN_FACTOR 64 +#endif +#ifndef HB_BUFFER_MAX_LEN_MIN +#define HB_BUFFER_MAX_LEN_MIN 16384 +#endif +#ifndef HB_BUFFER_MAX_LEN_DEFAULT +#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */ +#endif + +#ifndef HB_BUFFER_MAX_OPS_FACTOR +#define HB_BUFFER_MAX_OPS_FACTOR 1024 +#endif +#ifndef HB_BUFFER_MAX_OPS_MIN +#define HB_BUFFER_MAX_OPS_MIN 16384 +#endif +#ifndef HB_BUFFER_MAX_OPS_DEFAULT +#define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */ +#endif + + +#ifndef HB_MAX_NESTING_LEVEL +#define HB_MAX_NESTING_LEVEL 64 +#endif + + +#ifndef HB_MAX_CONTEXT_LENGTH +#define HB_MAX_CONTEXT_LENGTH 64 +#endif + +#ifndef HB_CLOSURE_MAX_STAGES +/* + * The maximum number of times a lookup can be applied during shaping. + * Used to limit the number of iterations of the closure algorithm. + * This must be larger than the number of times add_gsub_pause() is + * called in a collect_features call of any shaper. + */ +#define HB_CLOSURE_MAX_STAGES 12 +#endif + +#ifndef HB_MAX_SCRIPTS +#define HB_MAX_SCRIPTS 500 +#endif + +#ifndef HB_MAX_LANGSYS +#define HB_MAX_LANGSYS 2000 +#endif + +#ifndef HB_MAX_LANGSYS_FEATURE_COUNT +#define HB_MAX_LANGSYS_FEATURE_COUNT 50000 +#endif + +#ifndef HB_MAX_FEATURE_INDICES +#define HB_MAX_FEATURE_INDICES 1500 +#endif + +#ifndef HB_MAX_LOOKUP_VISIT_COUNT +#define HB_MAX_LOOKUP_VISIT_COUNT 35000 +#endif + + +#ifndef HB_GLYF_MAX_POINTS +#define HB_GLYF_MAX_POINTS 10000 +#endif + +#ifndef HB_CFF_MAX_OPS +#define HB_CFF_MAX_OPS 10000 +#endif + +#ifndef HB_COLRV1_MAX_EDGE_COUNT +#define HB_COLRV1_MAX_EDGE_COUNT 1024 +#endif + + +#endif /* HB_LIMITS_HH */ diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index b132da0e1..dc590e3da 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -41,14 +41,6 @@ */ #define HB_OT_TAG_COLR HB_TAG('C','O','L','R') -#ifndef HB_COLRV1_MAX_NESTING_LEVEL -#define HB_COLRV1_MAX_NESTING_LEVEL 128 -#endif - -#ifndef HB_COLRV1_MAX_EDGE_COUNT -#define HB_COLRV1_MAX_EDGE_COUNT 1024 -#endif - namespace OT { struct hb_paint_context_t; @@ -78,7 +70,7 @@ public: unsigned int palette; hb_color_t foreground; VarStoreInstancer &instancer; - int depth_left = HB_COLRV1_MAX_NESTING_LEVEL; + int depth_left = HB_MAX_NESTING_LEVEL; int edge_count = HB_COLRV1_MAX_EDGE_COUNT; hb_paint_context_t (const void *base_, @@ -174,7 +166,7 @@ struct hb_colrv1_closure_context_t : hb_set_t *glyphs_, hb_set_t *layer_indices_, hb_set_t *palette_indices_, - unsigned nesting_level_left_ = HB_COLRV1_MAX_NESTING_LEVEL) : + unsigned nesting_level_left_ = HB_MAX_NESTING_LEVEL) : base (base_), glyphs (glyphs_), layer_indices (layer_indices_), @@ -1524,7 +1516,7 @@ struct Paint { TRACE_SANITIZE (this); - if (unlikely (!c->check_start_recursion (HB_COLRV1_MAX_NESTING_LEVEL))) + if (unlikely (!c->check_start_recursion (HB_MAX_NESTING_LEVEL))) return_trace (c->no_dispatch_return_value ()); return_trace (c->end_recursion (this->dispatch (c, std::forward (ds)...))); diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 0f424f5aa..e651db678 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -44,42 +44,6 @@ using OT::Layout::Common::RangeRecord; using OT::Layout::SmallTypes; using OT::Layout::MediumTypes; -#ifndef HB_MAX_NESTING_LEVEL -#define HB_MAX_NESTING_LEVEL 64 -#endif -#ifndef HB_MAX_CONTEXT_LENGTH -#define HB_MAX_CONTEXT_LENGTH 64 -#endif -#ifndef HB_CLOSURE_MAX_STAGES -/* - * The maximum number of times a lookup can be applied during shaping. - * Used to limit the number of iterations of the closure algorithm. - * This must be larger than the number of times add_gsub_pause() is - * called in a collect_features call of any shaper. - */ -#define HB_CLOSURE_MAX_STAGES 12 -#endif - -#ifndef HB_MAX_SCRIPTS -#define HB_MAX_SCRIPTS 500 -#endif - -#ifndef HB_MAX_LANGSYS -#define HB_MAX_LANGSYS 2000 -#endif - -#ifndef HB_MAX_LANGSYS_FEATURE_COUNT -#define HB_MAX_LANGSYS_FEATURE_COUNT 50000 -#endif - -#ifndef HB_MAX_FEATURE_INDICES -#define HB_MAX_FEATURE_INDICES 1500 -#endif - -#ifndef HB_MAX_LOOKUP_VISIT_COUNT -#define HB_MAX_LOOKUP_VISIT_COUNT 35000 -#endif - namespace OT { diff --git a/src/hb.hh b/src/hb.hh index 410d090d3..1715bd492 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -142,6 +142,7 @@ #include "hb-config.hh" +#include "hb-limits.hh" /* diff --git a/src/meson.build b/src/meson.build index e015e0525..c25a3c633 100644 --- a/src/meson.build +++ b/src/meson.build @@ -55,6 +55,7 @@ hb_base_sources = files( 'hb-font.hh', 'hb-iter.hh', 'hb-kern.hh', + 'hb-limits.hh', 'hb-machinery.hh', 'hb-map.cc', 'hb-map.hh',