From 7aad53657eb23264f658711a71da3e50f2264455 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 26 Jun 2019 13:21:03 -0700 Subject: [PATCH] [config] Add HB_NO_OT_SHAPE / HB_NO_OT Part of https://github.com/harfbuzz/harfbuzz/issues/1652 --- CONFIG.md | 14 ++++++++++++++ src/gen-indic-table.py | 6 ++++++ src/gen-use-table.py | 6 ++++++ src/gen-vowel-constraints.py | 7 +++++++ src/hb-config.hh | 4 ++++ src/hb-ot-shape-complex-arabic.cc | 6 ++++++ src/hb-ot-shape-complex-default.cc | 7 +++++++ src/hb-ot-shape-complex-hangul.cc | 7 +++++++ src/hb-ot-shape-complex-hebrew.cc | 7 +++++++ src/hb-ot-shape-complex-indic-table.cc | 6 ++++++ src/hb-ot-shape-complex-indic.cc | 7 +++++++ src/hb-ot-shape-complex-khmer.cc | 7 +++++++ src/hb-ot-shape-complex-myanmar.cc | 7 +++++++ src/hb-ot-shape-complex-thai.cc | 7 +++++++ src/hb-ot-shape-complex-use-table.cc | 6 ++++++ src/hb-ot-shape-complex-use.cc | 7 +++++++ src/hb-ot-shape-complex-vowel-constraints.cc | 6 ++++++ src/hb-ot-shape-fallback.cc | 7 +++++++ src/hb-ot-shape-normalize.cc | 7 +++++++ src/hb-ot-shape.cc | 7 +++++++ src/hb-shape-plan.cc | 10 ++++++++++ src/hb-shape-plan.hh | 4 ++++ src/hb-shaper-list.hh | 2 ++ 23 files changed, 154 insertions(+) diff --git a/CONFIG.md b/CONFIG.md index 5fb3e7cb4..ff55154ad 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -86,6 +86,20 @@ In that case, or if you otherwise provide those functions by calling without loss of functionality by defining `HB_NO_OT_FONT`. +## Shapers + +Most HarfBuzz clients use it for the main shaper, called "ot". However, it +is legitimate to want to compile HarfBuzz with only another backend, eg. +CoreText, for example for an iOS app. For that, you want `HB_NO_OT_SHAPE`, +or more generally `HB_NO_OT`. + +This is very rarely what you need. Make sure you understand exactly what you +are doing. + +Defining `HB_NO_FALLBACK_SHAPE` however is pretty harmless. That removes the +(unused) "fallback" shaper. + + ## Thread-safety By default HarfBuzz builds as a thread-safe library. The exception is that diff --git a/src/gen-indic-table.py b/src/gen-indic-table.py index eedf420b7..cdf81fe75 100755 --- a/src/gen-indic-table.py +++ b/src/gen-indic-table.py @@ -98,6 +98,10 @@ for h in headers: print (" * %s" % (l.strip())) print (" */") print () +print ('#include "hb.hh"') +print () +print ('#ifndef HB_NO_OT_SHAPE') +print () print ('#include "hb-ot-shape-complex-indic.hh"') print () @@ -251,6 +255,8 @@ for i in range (2): print ("#undef %s_%s" % (what_short[i], short[i][v])) print () +print () +print ('#endif') print ("/* == End of generated table == */") # Maintain at least 30% occupancy in the table */ diff --git a/src/gen-use-table.py b/src/gen-use-table.py index 820838cf8..a8a03a77b 100755 --- a/src/gen-use-table.py +++ b/src/gen-use-table.py @@ -419,6 +419,10 @@ for h in headers: print (" * %s" % (l.strip())) print (" */") print () +print ('#include "hb.hh"') +print () +print ('#ifndef HB_NO_OT_SHAPE') +print () print ('#include "hb-ot-shape-complex-use.hh"') print () @@ -533,6 +537,8 @@ for k,v in sorted(use_positions.items()): tag = k + suf print ("#undef %s" % tag) print () +print () +print ('#endif') print ("/* == End of generated table == */") # Maintain at least 50% occupancy in the table */ diff --git a/src/gen-vowel-constraints.py b/src/gen-vowel-constraints.py index 1340d97dc..8ca90c819 100755 --- a/src/gen-vowel-constraints.py +++ b/src/gen-vowel-constraints.py @@ -157,6 +157,11 @@ print (' *') for line in scripts_header: print (' * %s' % line.strip ()) print (' */') + +print () +print ('#include "hb.hh"') +print () +print ('#ifndef HB_NO_OT_SHAPE') print () print ('#include "hb-ot-shape-complex-vowel-constraints.hh"') print () @@ -223,4 +228,6 @@ print (' }') print ('}') print () +print () +print ('#endif') print ('/* == End of generated functions == */') diff --git a/src/hb-config.hh b/src/hb-config.hh index f9e4699fc..c6a408053 100644 --- a/src/hb-config.hh +++ b/src/hb-config.hh @@ -121,6 +121,10 @@ #define HB_NO_OT_NAME_LANGUAGE #endif +#ifdef HB_NO_OT +#define HB_NO_OT_SHAPE +#endif + #ifdef HB_NO_OT_SHAPE_FALLBACK #define HB_NO_OT_SHAPE_COMPLEX_ARABIC_FALLBACK #define HB_NO_OT_SHAPE_COMPLEX_HEBREW_FALLBACK diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc index 3212e0c96..b24833b71 100644 --- a/src/hb-ot-shape-complex-arabic.cc +++ b/src/hb-ot-shape-complex-arabic.cc @@ -25,6 +25,9 @@ */ #include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-arabic.hh" #include "hb-ot-shape.hh" @@ -710,3 +713,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_arabic = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, true, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-default.cc b/src/hb-ot-shape-complex-default.cc index 97923ecf6..a921f16fa 100644 --- a/src/hb-ot-shape-complex-default.cc +++ b/src/hb-ot-shape-complex-default.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex.hh" @@ -44,3 +48,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_default = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, true, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-hangul.cc b/src/hb-ot-shape-complex-hangul.cc index f084f6ad6..32e0e6612 100644 --- a/src/hb-ot-shape-complex-hangul.cc +++ b/src/hb-ot-shape-complex-hangul.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex.hh" @@ -430,3 +434,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hangul = HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, false, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-hebrew.cc b/src/hb-ot-shape-complex-hebrew.cc index 14989730f..334d3ded8 100644 --- a/src/hb-ot-shape-complex-hebrew.cc +++ b/src/hb-ot-shape-complex-hebrew.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex.hh" @@ -176,3 +180,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_hebrew = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, true, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-indic-table.cc b/src/hb-ot-shape-complex-indic-table.cc index d26bbb8f3..419aae11e 100644 --- a/src/hb-ot-shape-complex-indic-table.cc +++ b/src/hb-ot-shape-complex-indic-table.cc @@ -14,6 +14,10 @@ * # Date: 2018-07-30, 19:40:00 GMT [KW] */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-indic.hh" #pragma GCC diagnostic push @@ -487,4 +491,6 @@ hb_indic_get_categories (hb_codepoint_t u) #undef IMC_TR #undef IMC_VOL + +#endif /* == End of generated table == */ diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index f8cb5741b..6405d9c2d 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-indic.hh" #include "hb-ot-shape-complex-vowel-constraints.hh" #include "hb-ot-layout.hh" @@ -1648,3 +1652,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic = HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, false, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-khmer.cc b/src/hb-ot-shape-complex-khmer.cc index 4c8847762..eba7d86ea 100644 --- a/src/hb-ot-shape-complex-khmer.cc +++ b/src/hb-ot-shape-complex-khmer.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-khmer.hh" #include "hb-ot-layout.hh" @@ -502,3 +506,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_khmer = HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, false, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-myanmar.cc b/src/hb-ot-shape-complex-myanmar.cc index b1f6b65ef..5b819cf47 100644 --- a/src/hb-ot-shape-complex-myanmar.cc +++ b/src/hb-ot-shape-complex-myanmar.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-myanmar.hh" @@ -415,3 +419,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_myanmar_zawgyi = HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE, false, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-thai.cc b/src/hb-ot-shape-complex-thai.cc index 22d4aa3ab..347ea2e7a 100644 --- a/src/hb-ot-shape-complex-thai.cc +++ b/src/hb-ot-shape-complex-thai.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex.hh" @@ -385,3 +389,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_thai = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, false,/* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-use-table.cc b/src/hb-ot-shape-complex-use-table.cc index 024746989..4c5d687c7 100644 --- a/src/hb-ot-shape-complex-use-table.cc +++ b/src/hb-ot-shape-complex-use-table.cc @@ -15,6 +15,10 @@ * UnicodeData.txt does not have a header. */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-use.hh" #pragma GCC diagnostic push @@ -851,4 +855,6 @@ hb_use_get_category (hb_codepoint_t u) #undef VMPst #undef VMAbv + +#endif /* == End of generated table == */ diff --git a/src/hb-ot-shape-complex-use.cc b/src/hb-ot-shape-complex-use.cc index 2cc5ea278..91c0b8c04 100644 --- a/src/hb-ot-shape-complex-use.cc +++ b/src/hb-ot-shape-complex-use.cc @@ -26,6 +26,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-use.hh" #include "hb-ot-shape-complex-arabic.hh" #include "hb-ot-shape-complex-vowel-constraints.hh" @@ -643,3 +647,6 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use = HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY, false, /* fallback_position */ }; + + +#endif diff --git a/src/hb-ot-shape-complex-vowel-constraints.cc b/src/hb-ot-shape-complex-vowel-constraints.cc index 912ee35b4..2f8041323 100644 --- a/src/hb-ot-shape-complex-vowel-constraints.cc +++ b/src/hb-ot-shape-complex-vowel-constraints.cc @@ -13,6 +13,10 @@ * # Date: 2019-01-28, 22:16:47 GMT */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-complex-vowel-constraints.hh" static void @@ -440,4 +444,6 @@ _hb_preprocess_text_vowel_constraints (const hb_ot_shape_plan_t *plan HB_UNUSED, } } + +#endif /* == End of generated functions == */ diff --git a/src/hb-ot-shape-fallback.cc b/src/hb-ot-shape-fallback.cc index 573af8ec6..03a42df6f 100644 --- a/src/hb-ot-shape-fallback.cc +++ b/src/hb-ot-shape-fallback.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-fallback.hh" #include "hb-kern.hh" @@ -587,3 +591,6 @@ _hb_ot_shape_fallback_spaces (const hb_ot_shape_plan_t *plan HB_UNUSED, } } } + + +#endif diff --git a/src/hb-ot-shape-normalize.cc b/src/hb-ot-shape-normalize.cc index 82bb24b7d..14c5bd4ac 100644 --- a/src/hb-ot-shape-normalize.cc +++ b/src/hb-ot-shape-normalize.cc @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-ot-shape-normalize.hh" #include "hb-ot-shape-complex.hh" #include "hb-ot-shape.hh" @@ -469,3 +473,6 @@ _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan, buffer->swap_buffers (); } } + + +#endif diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 7690c2229..499b1be4b 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -26,6 +26,10 @@ * Google Author(s): Behdad Esfahbod */ +#include "hb.hh" + +#ifndef HB_NO_OT_SHAPE + #include "hb-shaper-impl.hh" #include "hb-ot-shape.hh" @@ -1146,3 +1150,6 @@ hb_ot_shape_glyphs_closure (hb_font_t *font, hb_shape_plan_destroy (shape_plan); } + + +#endif diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 61ea8d0e5..2b23dee62 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -79,7 +79,9 @@ hb_shape_plan_key_t::init (bool copy, } this->shaper_func = nullptr; this->shaper_name = nullptr; +#ifndef HB_NO_OT_SHAPE this->ot.init (face, coords, num_coords); +#endif /* * Choose shaper. @@ -148,7 +150,9 @@ hb_shape_plan_key_t::equal (const hb_shape_plan_key_t *other) { return hb_segment_properties_equal (&this->props, &other->props) && this->user_features_match (other) && +#ifndef HB_NO_OT_SHAPE this->ot.equal (&other->ot) && +#endif this->shaper_func == other->shaper_func; } @@ -224,12 +228,16 @@ hb_shape_plan_create2 (hb_face_t *face, num_coords, shaper_list))) goto bail2; +#ifndef HB_NO_OT_SHAPE if (unlikely (!shape_plan->ot.init0 (face, &shape_plan->key))) goto bail3; +#endif return shape_plan; +#ifndef HB_NO_OT_SHAPE bail3: +#endif shape_plan->key.free (); bail2: free (shape_plan); @@ -281,7 +289,9 @@ hb_shape_plan_destroy (hb_shape_plan_t *shape_plan) { if (!hb_object_destroy (shape_plan)) return; +#ifndef HB_NO_OT_SHAPE shape_plan->ot.fini (); +#endif shape_plan->key.free (); free (shape_plan); } diff --git a/src/hb-shape-plan.hh b/src/hb-shape-plan.hh index 3a057fd22..8e8d7632b 100644 --- a/src/hb-shape-plan.hh +++ b/src/hb-shape-plan.hh @@ -39,7 +39,9 @@ struct hb_shape_plan_key_t const hb_feature_t *user_features; unsigned int num_user_features; +#ifndef HB_NO_OT_SHAPE hb_ot_shape_plan_key_t ot; +#endif hb_shape_func_t *shaper_func; const char *shaper_name; @@ -65,7 +67,9 @@ struct hb_shape_plan_t hb_object_header_t header; hb_face_t *face_unsafe; /* We don't carry a reference to face. */ hb_shape_plan_key_t key; +#ifndef HB_NO_OT_SHAPE hb_ot_shape_plan_t ot; +#endif }; diff --git a/src/hb-shaper-list.hh b/src/hb-shaper-list.hh index 4108e7aab..c864af6ec 100644 --- a/src/hb-shaper-list.hh +++ b/src/hb-shaper-list.hh @@ -35,7 +35,9 @@ HB_SHAPER_IMPLEMENT (graphite2) #endif +#ifndef HB_NO_OT_SHAPE HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */ +#endif #ifdef HAVE_UNISCRIBE HB_SHAPER_IMPLEMENT (uniscribe)