src/hb-blob.cc | 2 src/hb-dsalgs.hh | 4 + src/hb-null.hh | 30 +++++++++++++ src/hb-open-type.hh | 2 src/hb-ot-color-cbdt-table.hh | 10 ---- src/hb-ot-color-sbix-table.hh | 11 +--- src/hb-ot-color-svg-table.hh | 11 +--- src/hb-ot-glyf-table.hh | 6 +- src/hb-ot-layout-gdef-table.hh | 2 src/hb-ot-layout-gsubgpos.hh | 2 src/hb-ot-name-table.hh | 2 src/hb-ot-name.cc | 4 - src/hb-ot-post-table.hh | 2 test/api/Makefile.am | 1 test/api/test-ot-face.c | 94 +++++++++++++++++++++++++++++++++++++++++ 15 files changed, 150 insertions(+), 33 deletions(-)
New commits: commit c8f94a1ca6928f07749285da910b63087d485537 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 21:07:39 2018 -0400 Minor diff --git a/src/hb-ot-name.cc b/src/hb-ot-name.cc index e0c97108..f5ac18d7 100644 --- a/src/hb-ot-name.cc +++ b/src/hb-ot-name.cc @@ -52,7 +52,7 @@ _get_name (hb_face_t *face) /** * hb_ot_name_list_names: * @face: font face. - * @num_entries: (out): number of returned entries. + * @num_entries: (out) (allow-none): number of returned entries. * * Enumerates all available name IDs and language combinations. Returned * array is owned by the @face and should not be modified. It can be @@ -66,7 +66,7 @@ hb_ot_name_list_names (hb_face_t *face, unsigned int *num_entries /* OUT */) { const OT::name_accelerator_t &name = _get_name (face); - *num_entries = name.names.len; + if (num_entries) *num_entries = name.names.len; return name.names.arrayZ(); } commit 9779e602ed7ac214c0da2c90e104b38460422476 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 20:50:56 2018 -0400 [test] Add test for empty face diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 3b985703..b307cd12 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -36,6 +36,7 @@ TEST_PROGS = \ test-font \ test-map \ test-object \ + test-ot-face \ test-set \ test-shape \ test-subset \ diff --git a/test/api/test-ot-face.c b/test/api/test-ot-face.c new file mode 100644 index 00000000..0af584e0 --- /dev/null +++ b/test/api/test-ot-face.c @@ -0,0 +1,94 @@ +/* + * Copyright © 2011 Google, Inc. + * + * 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. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-test.h" +#include <hb-ot.h> + +/* Unit tests for hb-ot-*.h */ + + +static void +test_ot_face_empty (void) +{ + hb_face_t *face = hb_face_get_empty (); + hb_font_t *font = hb_font_create (face); + hb_set_t *set = hb_set_create (); + + hb_face_collect_unicodes (face, set); + hb_face_collect_variation_selectors (face, set); + hb_face_collect_variation_unicodes (face, 0, set); + + hb_ot_color_has_palettes (face); + hb_ot_color_palette_get_count (face); + hb_ot_color_palette_get_name_id (face, 0); + hb_ot_color_palette_color_get_name_id (face, 0); + hb_ot_color_palette_get_flags (face, 0); + hb_ot_color_palette_get_colors (face, 0, 0, NULL, NULL); + hb_ot_color_has_layers (face); + hb_ot_color_glyph_get_layers (face, 0, 0, NULL, NULL); + hb_ot_color_has_svg (face); + hb_ot_color_glyph_reference_svg (face, 0); + hb_ot_color_has_png (face); + hb_ot_color_glyph_reference_png (font, 0); + + hb_ot_layout_has_glyph_classes (face); + hb_ot_layout_has_substitution (face); + hb_ot_layout_has_positioning (face); + + hb_ot_math_has_data (face); + hb_ot_math_get_constant (font, 0); + hb_ot_math_get_glyph_italics_correction (font, 0); + hb_ot_math_get_glyph_top_accent_attachment (font, 0); + hb_ot_math_is_glyph_extended_shape (face, 0); + hb_ot_math_get_glyph_kerning (font, 0, 0, 0); + hb_ot_math_get_glyph_variants (font, 0, 0, 0, NULL, NULL); + hb_ot_math_get_min_connector_overlap (font, 0); + hb_ot_math_get_glyph_assembly (font, 0, 0, 0, NULL, NULL, NULL); + + hb_ot_name_list_names (face, NULL); + hb_ot_name_get_utf8 (face, 0, NULL, NULL, NULL); + hb_ot_name_get_utf16 (face, 0, NULL, NULL, NULL); + hb_ot_name_get_utf32 (face, 0, NULL, NULL, NULL); + + hb_ot_var_get_axis_count (face); + hb_ot_var_get_axes (face, 0, NULL, NULL); + hb_ot_var_normalize_variations (face, NULL, 0, NULL, 0); + hb_ot_var_normalize_coords (face, 0, NULL, NULL); + + hb_set_destroy (set); + hb_font_destroy (font); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_ot_face_empty); + + return hb_test_run(); +} commit 0b0b38ec1e6a815a30bef98193043d255b52c4a1 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 16:15:30 2018 -0400 Fix null accelerator's Fixes all except for cmap. To be done separately. Part of https://github.com/harfbuzz/harfbuzz/issues/1146 diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index 614cc80c..580dc376 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -409,9 +409,6 @@ struct CBDT inline bool get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const { - if (!cblc) - return false; - const void *base; const BitmapSizeTable &strike = this->cblc->choose_strike (font); const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base); @@ -467,9 +464,6 @@ struct CBDT inline hb_blob_t* reference_png (hb_font_t *font, hb_codepoint_t glyph) const { - if (!cblc) - return hb_blob_get_empty (); - const void *base; const BitmapSizeTable &strike = this->cblc->choose_strike (font); const IndexSubtableRecord *subtable_record = strike.find_table (glyph, cblc, &base); @@ -525,8 +519,8 @@ struct CBDT private: hb_blob_t *cblc_blob; hb_blob_t *cbdt_blob; - const CBLC *cblc; - const CBDT *cbdt; + hb_nonnull_ptr_t<const CBLC> cblc; + hb_nonnull_ptr_t<const CBDT> cbdt; unsigned int cbdt_len; unsigned int upem; diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index 065c0dd1..7a01d14a 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -152,9 +152,6 @@ struct sbix inline bool has_data () const { - /* XXX Fix somehow and remove next line. - * https://github.com/harfbuzz/harfbuzz/issues/1146 */ - if (!num_glyphs) return false; return table->has_data (); } @@ -234,8 +231,8 @@ struct sbix hb_codepoint_t glyph, hb_glyph_extents_t *extents) const { - /* Following code is safe to call even without data (XXX currently - * isn't. See has_data()), but faster to short-circuit. */ + /* Following code is safe to call even without data. + * But faster to short-circuit. */ if (!has_data ()) return false; @@ -262,12 +259,12 @@ struct sbix hb_blob_destroy (blob); - return true; + return strike_ppem; } private: hb_blob_t *sbix_blob; - const sbix *table; + hb_nonnull_ptr_t<const sbix> table; unsigned int num_glyphs; }; diff --git a/src/hb-ot-color-svg-table.hh b/src/hb-ot-color-svg-table.hh index bb4c4f75..069c5478 100644 --- a/src/hb-ot-color-svg-table.hh +++ b/src/hb-ot-color-svg-table.hh @@ -75,12 +75,13 @@ struct SVG { static const hb_tag_t tableTag = HB_OT_TAG_SVG; + inline bool has_data (void) const { return svgDocEntries; } + struct accelerator_t { inline void init (hb_face_t *face) { svg_blob = hb_sanitize_context_t().reference_table<SVG> (face); - svg_len = hb_blob_get_length (svg_blob); table = svg_blob->as<SVG> (); } @@ -91,18 +92,14 @@ struct SVG inline hb_blob_t *reference_blob_for_glyph (hb_codepoint_t glyph_id) const { - if (unlikely (!svg_len)) - return hb_blob_get_empty (); return table->get_glyph_entry (glyph_id).reference_blob (svg_blob, table->svgDocEntries); } - inline bool has_data () const { return svg_len; } + inline bool has_data () const { return table->has_data (); } private: hb_blob_t *svg_blob; - const SVG *table; - - unsigned int svg_len; + hb_nonnull_ptr_t<const SVG> table; }; inline const SVGDocumentIndexEntry &get_glyph_entry (hb_codepoint_t glyph_id) const diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 7bd175e3..d2a39f23 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -276,7 +276,7 @@ struct glyf if (!get_offsets (glyph, &start_offset, &end_offset)) return false; /* glyph not found */ - return CompositeGlyphHeader::get_iterator ((const char*) this->glyf_table + start_offset, + return CompositeGlyphHeader::get_iterator ((const char *) this->glyf_table + start_offset, end_offset - start_offset, composite); } @@ -476,8 +476,8 @@ struct glyf private: bool short_offset; unsigned int num_glyphs; - const loca *loca_table; - const glyf *glyf_table; + hb_nonnull_ptr_t<const loca> loca_table; + hb_nonnull_ptr_t<const glyf> glyf_table; hb_blob_t *loca_blob; hb_blob_t *glyf_blob; unsigned int glyf_len; diff --git a/src/hb-ot-layout-gdef-table.hh b/src/hb-ot-layout-gdef-table.hh index 75709086..5847953d 100644 --- a/src/hb-ot-layout-gdef-table.hh +++ b/src/hb-ot-layout-gdef-table.hh @@ -418,7 +418,7 @@ struct GDEF } hb_blob_t *blob; - const GDEF *table; + hb_nonnull_ptr_t<const GDEF> table; }; inline unsigned int get_size (void) const diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 54ae429b..0d9eeae5 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -2774,7 +2774,7 @@ struct GSUBGPOS } hb_blob_t *blob; - const T *table; + hb_nonnull_ptr_t<const T> table; unsigned int lookup_count; hb_ot_layout_lookup_accelerator_t *accels; }; diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh index 9f67b574..f1e785f1 100644 --- a/src/hb-ot-name-table.hh +++ b/src/hb-ot-name-table.hh @@ -257,7 +257,7 @@ struct name const void *pool; unsigned int pool_len; public: - const name *table; + hb_nonnull_ptr_t<const name> table; hb_vector_t<hb_ot_name_entry_t> names; }; diff --git a/src/hb-ot-post-table.hh b/src/hb-ot-post-table.hh index bd049f9a..6432f3f1 100644 --- a/src/hb-ot-post-table.hh +++ b/src/hb-ot-post-table.hh @@ -254,7 +254,7 @@ struct post private: hb_blob_t *blob; uint32_t version; - const ArrayOf<HBUINT16> *glyphNameIndex; + hb_nonnull_ptr_t<const ArrayOf<HBUINT16>> glyphNameIndex; hb_vector_t<uint32_t, 1> index_to_offset; const uint8_t *pool; hb_atomic_ptr_t<uint16_t *> gids_sorted_by_name; commit db889c182ee5f54127285bfaab5bc94dafe46bda Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 16:04:19 2018 -0400 Add operator char * to the naked array types as well diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index f2bff063..fafac1f7 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -553,8 +553,10 @@ struct hb_array_t inline unsigned int get_size (void) const { return len * sizeof (Type); } - template <typename T> inline operator T * (void) { return arrayZ; } + template <typename T> inline operator T * (void) { return arrayZ; } template <typename T> inline operator const T * (void) const { return arrayZ; } + inline operator char * (void) { return (char *) arrayZ; } + inline operator const char * (void) const { return (const char *) arrayZ; } inline Type * operator & (void) { return arrayZ; } inline const Type * operator & (void) const { return arrayZ; } diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 0f6efdc6..e1dc8aab 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -342,6 +342,8 @@ struct UnsizedArrayOf template <typename T> inline operator T * (void) { return arrayZ; } template <typename T> inline operator const T * (void) const { return arrayZ; } + inline operator char * (void) { return (char *) arrayZ; } + inline operator const char * (void) const { return (const char *) arrayZ; } inline unsigned int get_size (unsigned int len) const { return len * Type::static_size; } commit d6fdae310f2a98ca624c3a77c3aa03b8b3bd393a Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 16:02:03 2018 -0400 Add operator char * to hb_nonnull_ptr_t diff --git a/src/hb-null.hh b/src/hb-null.hh index a3f0ea07..c91af163 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -120,10 +120,10 @@ struct hb_nonnull_ptr_t inline const T & operator * (void) const { return *get (); } inline T ** operator & (void) { return &v; } inline const T ** operator & (void) const { return &v; } - template <typename C> - inline operator C * (void) { return get (); } - template <typename C> - inline operator const C * (void) const { return get (); } + template <typename C> inline operator C * (void) { return get (); } + template <typename C> inline operator const C * (void) const { return get (); } + inline operator char * (void) { return (char *) get (); } + inline operator const char * (void) const { return (const char *) get (); } inline T * get (void) { return v ? v : const_cast<T *> (&Null(T)); } inline const T * get (void) const { return v ? v : const_cast<T *> (&Null(T)); } inline T * get_raw (void) { return v; } commit 7430ff604aa54bedcb07cc1c2962eae85fcade76 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 15:59:13 2018 -0400 Template casts in hb_nonnull_ptr_t diff --git a/src/hb-null.hh b/src/hb-null.hh index 151277ca..a3f0ea07 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -120,8 +120,10 @@ struct hb_nonnull_ptr_t inline const T & operator * (void) const { return *get (); } inline T ** operator & (void) { return &v; } inline const T ** operator & (void) const { return &v; } - inline operator T * (void) { return get (); } - inline operator const T * (void) const { return get (); } + template <typename C> + inline operator C * (void) { return get (); } + template <typename C> + inline operator const C * (void) const { return get (); } inline T * get (void) { return v ? v : const_cast<T *> (&Null(T)); } inline const T * get (void) const { return v ? v : const_cast<T *> (&Null(T)); } inline T * get_raw (void) { return v; } commit da408fce98153e0fab3d82fe28813085feed0974 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 15:49:37 2018 -0400 [blob] Allow null parent in create_sub_blob() Like font and unicode. diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 4b036e80..9271200b 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -149,7 +149,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent, { hb_blob_t *blob; - if (!length || offset >= parent->length) + if (!length || !parent || offset >= parent->length) return hb_blob_get_empty (); hb_blob_make_immutable (parent); commit fb0f30f55a5d654b2f1f9b99efa9b8abc51dbf34 Author: Behdad Esfahbod <[email protected]> Date: Sat Nov 3 15:24:14 2018 -0400 Add hb_nonnull_ptr_t Towards fixing https://github.com/harfbuzz/harfbuzz/issues/1146 diff --git a/src/hb-null.hh b/src/hb-null.hh index d5b74bf5..151277ca 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -103,4 +103,32 @@ struct CrapOrNull<const Type> { #define CrapOrNull(Type) CrapOrNull<Type>::get () +/* + * hb_nonnull_ptr_t + */ + +template <typename P> +struct hb_nonnull_ptr_t +{ + typedef typename hb_remove_pointer<P>::value T; + + inline hb_nonnull_ptr_t (T *v_ = nullptr) : v (v_) {} + inline T * operator = (T *v_) { return v = v_; } + inline T * operator -> (void) { return get (); } + inline const T * operator -> (void) const { return get (); } + inline T & operator * (void) { return *get (); } + inline const T & operator * (void) const { return *get (); } + inline T ** operator & (void) { return &v; } + inline const T ** operator & (void) const { return &v; } + inline operator T * (void) { return get (); } + inline operator const T * (void) const { return get (); } + inline T * get (void) { return v ? v : const_cast<T *> (&Null(T)); } + inline const T * get (void) const { return v ? v : const_cast<T *> (&Null(T)); } + inline T * get_raw (void) { return v; } + inline const T * get_raw (void) const { return v; } + + T *v; +}; + + #endif /* HB_NULL_HH */ _______________________________________________ HarfBuzz mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/harfbuzz
