Add hb-limits.hh

This commit is contained in:
Behdad Esfahbod 2022-12-26 12:30:39 -07:00
parent 5f5fa4b219
commit ae208963df
10 changed files with 113 additions and 82 deletions

View File

@ -47,6 +47,7 @@ HB_BASE_sources = \
hb-font.hh \ hb-font.hh \
hb-iter.hh \ hb-iter.hh \
hb-kern.hh \ hb-kern.hh \
hb-limits.hh \
hb-machinery.hh \ hb-machinery.hh \
hb-map.cc \ hb-map.cc \
hb-map.hh \ hb-map.hh \

View File

@ -18,11 +18,6 @@ struct glyf_accelerator_t;
namespace glyf_impl { namespace glyf_impl {
#ifndef HB_GLYF_MAX_POINTS
#define HB_GLYF_MAX_POINTS 10000
#endif
enum phantom_point_index_t enum phantom_point_index_t
{ {
PHANTOM_LEFT = 0, PHANTOM_LEFT = 0,

View File

@ -35,26 +35,6 @@
#include "hb-set-digest.hh" #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) == 20), "");
static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), ""); static_assert ((sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)), "");

View File

@ -57,7 +57,6 @@ struct call_context_t
/* call stack */ /* call stack */
const unsigned int kMaxCallLimit = 10; const unsigned int kMaxCallLimit = 10;
const unsigned int kMaxOps = 10000;
struct call_stack_t : cff_stack_t<call_context_t, kMaxCallLimit> {}; struct call_stack_t : cff_stack_t<call_context_t, kMaxCallLimit> {};
template <typename SUBRS> template <typename SUBRS>
@ -882,7 +881,7 @@ struct cs_interpreter_t : interpreter_t<ENV>
{ {
SUPER::env.set_endchar (false); SUPER::env.set_endchar (false);
unsigned max_ops = kMaxOps; unsigned max_ops = HB_CFF_MAX_OPS;
for (;;) { for (;;) {
if (unlikely (!--max_ops)) if (unlikely (!--max_ops))
{ {

View File

@ -35,13 +35,6 @@
#ifdef TT_SUPPORT_COLRV1 #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 static hb_paint_composite_mode_t
_hb_ft_paint_composite_mode (FT_Composite_Mode mode) _hb_ft_paint_composite_mode (FT_Composite_Mode mode)
@ -115,7 +108,7 @@ struct hb_ft_paint_context_t
void *data; void *data;
FT_Color *palette; FT_Color *palette;
hb_color_t foreground; 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; int edge_count = HB_COLRV1_MAX_EDGE_COUNT;
}; };

105
src/hb-limits.hh Normal file
View File

@ -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 */

View File

@ -41,14 +41,6 @@
*/ */
#define HB_OT_TAG_COLR HB_TAG('C','O','L','R') #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 { namespace OT {
struct hb_paint_context_t; struct hb_paint_context_t;
@ -78,7 +70,7 @@ public:
unsigned int palette; unsigned int palette;
hb_color_t foreground; hb_color_t foreground;
VarStoreInstancer &instancer; 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; int edge_count = HB_COLRV1_MAX_EDGE_COUNT;
hb_paint_context_t (const void *base_, hb_paint_context_t (const void *base_,
@ -174,7 +166,7 @@ struct hb_colrv1_closure_context_t :
hb_set_t *glyphs_, hb_set_t *glyphs_,
hb_set_t *layer_indices_, hb_set_t *layer_indices_,
hb_set_t *palette_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_), base (base_),
glyphs (glyphs_), glyphs (glyphs_),
layer_indices (layer_indices_), layer_indices (layer_indices_),
@ -1524,7 +1516,7 @@ struct Paint
{ {
TRACE_SANITIZE (this); 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->no_dispatch_return_value ());
return_trace (c->end_recursion (this->dispatch (c, std::forward<Ts> (ds)...))); return_trace (c->end_recursion (this->dispatch (c, std::forward<Ts> (ds)...)));

View File

@ -44,42 +44,6 @@ using OT::Layout::Common::RangeRecord;
using OT::Layout::SmallTypes; using OT::Layout::SmallTypes;
using OT::Layout::MediumTypes; 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 { namespace OT {

View File

@ -142,6 +142,7 @@
#include "hb-config.hh" #include "hb-config.hh"
#include "hb-limits.hh"
/* /*

View File

@ -55,6 +55,7 @@ hb_base_sources = files(
'hb-font.hh', 'hb-font.hh',
'hb-iter.hh', 'hb-iter.hh',
'hb-kern.hh', 'hb-kern.hh',
'hb-limits.hh',
'hb-machinery.hh', 'hb-machinery.hh',
'hb-map.cc', 'hb-map.cc',
'hb-map.hh', 'hb-map.hh',