diff --git a/NEWS b/NEWS index ff4f6e29d..890c258d8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,18 @@ +Overview of changes leading to 2.3.0 +Thursday, December 20, 2018 +==================================== +- Fix regression on big-endian architectures. Ouch! +- Misc bug and build fixes. +- Fix subsetting of simple GSUB/GDEF. +- Merge CFF / CFF2 support contributed by Adobe. This mostly involves + the subsetter, but also get_glyph_extents on CFF fonts. + +New API in hb-aat.h: ++hb_aat_layout_has_substitution() ++hb_aat_layout_has_positioning() ++hb_aat_layout_has_tracking() + + Overview of changes leading to 2.2.0 Thursday, November 29, 2018 ==================================== diff --git a/configure.ac b/configure.ac index 4d7348eff..03155372b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ([2.64]) AC_INIT([HarfBuzz], - [2.2.0], + [2.3.0], [https://github.com/harfbuzz/harfbuzz/issues/new], [harfbuzz], [http://harfbuzz.org/]) diff --git a/src/Makefile.am b/src/Makefile.am index 3618d03a2..5ed629217 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -384,14 +384,20 @@ dump_use_data_SOURCES = dump-use-data.cc hb-ot-shape-complex-use-table.cc dump_use_data_CPPFLAGS = $(HBCFLAGS) dump_use_data_LDADD = libharfbuzz.la $(HBLIBS) -check_PROGRAMS += test-ot-tag test-unicode-ranges -TESTS += test-ot-tag test-unicode-ranges +COMPILED_TESTS = test-iter test-ot-tag test-unicode-ranges +check_PROGRAMS += $(COMPILED_TESTS) +TESTS += $(COMPILED_TESTS) + +test_iter_SOURCES = test-iter.cc hb-static.cc +test_iter_CPPFLAGS = $(HBCFLAGS) -DMAIN +test_iter_LDADD = libharfbuzz.la $(HBLIBS) test_ot_tag_SOURCES = hb-ot-tag.cc test_ot_tag_CPPFLAGS = $(HBCFLAGS) -DMAIN test_ot_tag_LDADD = libharfbuzz.la $(HBLIBS) test_unicode_ranges_SOURCES = test-unicode-ranges.cc +test_unicode_ranges_CPPFLAGS = $(HBCFLAGS) -DMAIN test_unicode_ranges_LDADD = libharfbuzz.la $(HBLIBS) TESTS_ENVIRONMENT = \ diff --git a/src/Makefile.sources b/src/Makefile.sources index 98b622889..0da4abe05 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -36,6 +36,7 @@ HB_BASE_sources = \ hb-face.hh \ hb-font.cc \ hb-font.hh \ + hb-iter.hh \ hb-kern.hh \ hb-machinery.hh \ hb-map.cc \ diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index 8a868a054..8de8205f5 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -209,7 +209,7 @@ hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, * @face: * * Returns: - * Since: REPLACEME + * Since: 2.3.0 */ hb_bool_t hb_aat_layout_has_substitution (hb_face_t *face) @@ -270,7 +270,7 @@ hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer) * @face: * * Returns: - * Since: REPLACEME + * Since: 2.3.0 */ hb_bool_t hb_aat_layout_has_positioning (hb_face_t *face) @@ -300,7 +300,7 @@ hb_aat_layout_position (const hb_ot_shape_plan_t *plan, * @face: * * Returns: - * Since: REPLACEME + * Since: 2.3.0 */ hb_bool_t hb_aat_layout_has_tracking (hb_face_t *face) diff --git a/src/hb-array.hh b/src/hb-array.hh index d4df16546..af4233bfa 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -36,7 +36,7 @@ struct hb_sorted_array_t; template struct hb_array_t { - typedef Type ItemType; + typedef Type item_t; enum { item_size = hb_static_size (Type) }; /* diff --git a/src/hb-iter.hh b/src/hb-iter.hh new file mode 100644 index 000000000..a919d4e32 --- /dev/null +++ b/src/hb-iter.hh @@ -0,0 +1,105 @@ +/* + * Copyright © 2018 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 + */ + +#ifndef HB_ITER_HH +#define HB_ITER_HH + +#include "hb.hh" + + +/* Unified iterator object. + * + * The goal of this template is to make the same iterator interface + * available to all types, and make it very easy and compact to use. + * hb_iter_tator objects are small, light-weight, objects that can be + * copied by value. If the collection / object being iterated on + * is writable, then the iterator returns lvalues, otherwise it + * returns rvalues. + */ + +/* Base class for all iterators. */ +template +struct hb_iter_t +{ + typedef Iter iter_t; + typedef Item item_t; + + /* https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ + const iter_t* thiz () const { return static_cast (this); } + iter_t* thiz () { return static_cast< iter_t *> (this); } + + /* Operators. */ + operator iter_t () { return iter(); } + explicit_operator bool () const { return more (); } + item_t& operator * () { return item (); } + item_t& operator [] (unsigned i) { return item (i); } + iter_t& operator += (unsigned count) { forward (count); return *thiz(); } + iter_t& operator ++ () { next (); return *thiz(); } + iter_t& operator -= (unsigned count) { rewind (count); return *thiz(); } + iter_t& operator -- () { prev (); return *thiz(); } + iter_t operator + (unsigned count) { iter_t c (*thiz()); c += count; return c; } + iter_t operator ++ (int) { iter_t c (*thiz()); ++*thiz(); return c; } + iter_t operator - (unsigned count) { iter_t c (*thiz()); c -= count; return c; } + iter_t operator -- (int) { iter_t c (*thiz()); --*thiz(); return c; } + + /* Methods. */ + iter_t iter () const { return *thiz(); } + item_t& item () const { return thiz()->__item__ (); } + item_t& item_at (unsigned i) const { return thiz()->__item_at__ (i); } + bool more () const { return thiz()->__more__ (); } + void next () { thiz()->__next__ (); } + void forward (unsigned n) { thiz()->__forward__ (n); } + void prev () { thiz()->__prev__ (); } + void rewind (unsigned n) { thiz()->__rewind__ (n); } + unsigned len () const { return thiz()->__len__ (); } + + /* + * Subclasses overrides: + */ + + /* Access: Implement __item__(), or __item_at__() if random-access. */ + item_t& __item__ () const { return thiz()->item_at (0); } + item_t& __item_at__ (unsigned i) const { return *(thiz() + i); } + + /* Termination: Implement __more__() or __end__(). */ + bool __more__ () const { return item () != thiz()->__end__ (); } + const item_t& __end__ () const { return iter_t::__sentinel__; } + + /* Advancing: Implement __next__(), or __forward__() if random-access. */ + void __next__ () { thiz()->forward (1); } + void __forward__ (unsigned n) { while (n--) next (); } + + /* Rewinding: Implement __prev__() or __rewind__() if bidirectional. */ + void __prev__ () { thiz()->rewind (1); } + void __rewind__ (unsigned n) { while (n--) prev (); } + + /* Population: Implement __len__() if known. */ + unsigned __len__ () const + { iter_t c (*thiz()); unsigned l = 0; while (c) { c++; l++; }; return l; } +}; + + +#endif /* HB_ITER_HH */ diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index 1205b1fea..fdb7b0a0d 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -390,7 +390,7 @@ struct hb_sanitize_context_t : { if (this->may_edit (obj, hb_static_size (Type))) { - const_cast (obj)->set (v); + hb_assign (* const_cast (obj), v); return true; } return false; @@ -599,6 +599,8 @@ struct hb_serialize_context_t memcpy (ret, &obj, size); return ret; } + template + hb_serialize_context_t &operator << (const Type &obj) { embed (obj); return *this; } template Type *extend_size (Type &obj, unsigned int size) @@ -665,7 +667,6 @@ template struct BEInt { public: - typedef Type type; void set (Type V) { v = V; } operator Type () const { return v; } private: uint8_t v; @@ -674,7 +675,6 @@ template struct BEInt { public: - typedef Type type; void set (Type V) { v[0] = (V >> 8) & 0xFF; @@ -703,7 +703,6 @@ template struct BEInt { public: - typedef Type type; void set (Type V) { v[0] = (V >> 16) & 0xFF; diff --git a/src/hb-null.hh b/src/hb-null.hh index 7ea2bab16..8a3e0d405 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -59,7 +59,10 @@ struct hb_null_size { enum { value = _hb_null_size >::value }; }; #define hb_null_size(T) hb_null_size::value -/* This doesn't belong here, but since is copy/paste from above, put it here. */ +/* These doesn't belong here, but since is copy/paste from above, put it here. */ + +/* hb_static_size (T) + * Returns T::static_size if T::min_size is defined, or sizeof (T) otherwise. */ template struct _hb_static_size @@ -74,6 +77,25 @@ struct hb_static_size #define hb_static_size(T) hb_static_size::value +/* hb_assign (obj, value) + * Calls obj.set (value) if obj.min_size is defined and value has different type + * from obj, or obj = v otherwise. */ + +template +struct _hb_assign +{ static inline void value (T &o, const V v) { o = v; } }; +template +struct _hb_assign > +{ static inline void value (T &o, const V v) { o.set (v); } }; +template +struct _hb_assign > +{ static inline void value (T &o, const T v) { o = v; } }; + +template +static inline void hb_assign (T &o, const V v) +{ _hb_assign >::value (o, v); }; + + /* * Null() */ diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 6517c6bfe..4c6d5e38b 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -352,7 +352,7 @@ static inline Type& operator + (Base &base, OffsetTo template struct UnsizedArrayOf { - typedef Type ItemType; + typedef Type item_t; enum { item_size = hb_static_size (Type) }; HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type); @@ -508,7 +508,7 @@ struct SortedUnsizedArrayOf : UnsizedArrayOf template struct ArrayOf { - typedef Type ItemType; + typedef Type item_t; enum { item_size = hb_static_size (Type) }; HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType); @@ -553,12 +553,13 @@ struct ArrayOf if (unlikely (!c->extend (*this))) return_trace (false); return_trace (true); } - bool serialize (hb_serialize_context_t *c, hb_array_t items) + template + bool serialize (hb_serialize_context_t *c, hb_array_t items) { TRACE_SERIALIZE (this); if (unlikely (!serialize (c, items.len))) return_trace (false); for (unsigned int i = 0; i < items.len; i++) - arrayZ[i] = items[i]; + hb_assign (arrayZ[i], items[i]); return_trace (true); } diff --git a/src/hb-vector.hh b/src/hb-vector.hh index d8e3f4ef1..4e962d2ef 100644 --- a/src/hb-vector.hh +++ b/src/hb-vector.hh @@ -34,7 +34,7 @@ template struct hb_vector_t { - typedef Type ItemType; + typedef Type item_t; enum { item_size = hb_static_size (Type) }; HB_NO_COPY_ASSIGN_TEMPLATE2 (hb_vector_t, Type, PreallocedCount); @@ -89,6 +89,8 @@ struct hb_vector_t return arrayZ()[i]; } + explicit_operator bool () const { return len; } + hb_array_t as_array () { return hb_array (arrayZ(), len); } hb_array_t as_array () const diff --git a/src/hb-version.h b/src/hb-version.h index 7c4a8ad4a..0c82d5bbb 100644 --- a/src/hb-version.h +++ b/src/hb-version.h @@ -37,10 +37,10 @@ HB_BEGIN_DECLS #define HB_VERSION_MAJOR 2 -#define HB_VERSION_MINOR 2 +#define HB_VERSION_MINOR 3 #define HB_VERSION_MICRO 0 -#define HB_VERSION_STRING "2.2.0" +#define HB_VERSION_STRING "2.3.0" #define HB_VERSION_ATLEAST(major,minor,micro) \ ((major)*10000+(minor)*100+(micro) <= \ diff --git a/src/test-iter.cc b/src/test-iter.cc new file mode 100644 index 000000000..32fb9f831 --- /dev/null +++ b/src/test-iter.cc @@ -0,0 +1,97 @@ +/* + * Copyright © 2018 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-iter.hh" + +#include "hb-array.hh" + +template +struct array_iter_t : hb_iter_t, T> +{ + array_iter_t (hb_array_t arr_) : arr (arr_) {} + + typedef T __item_type__; + T& __item_at__ (unsigned i) const { return arr[i]; } + bool __more__ () const { return arr.len; } + void __forward__ (unsigned n) { arr += n; } + void __rewind__ (unsigned n) { arr -= n; } + unsigned __len__ () const { return arr.len; } + + private: + hb_array_t arr; +}; + +template +struct some_array_t +{ + some_array_t (hb_array_t arr_) : arr (arr_) {} + + typedef array_iter_t iter_t; + array_iter_t iter () { return array_iter_t (arr); } + operator array_iter_t () { return iter (); } + operator hb_iter_t > () { return iter (); } + + private: + hb_array_t arr; +}; + + +template inline void +hb_fill (hb_iter_t &i, const V &v) +{ + for (; i; i++) + hb_assign (*i, v); +} + +template inline bool +hb_copy (hb_iter_t &id, hb_iter_t &is) +{ + for (; id && is; ++id, ++is) + *id = *is; + return !id; +} + +int +main (int argc, char **argv) +{ + const int src[10] = {}; + int dst[20]; + hb_vector_t v; + + array_iter_t s (src); /* Implicit conversion from static array. */ + array_iter_t s2 (v); /* Implicit conversion from vector. */ + array_iter_t t (dst); + + some_array_t a (src); + + s2 = s; + + hb_fill (t, 42); + hb_copy (t, s); + // hb_copy (t, a.iter ()); + + return 0; +} diff --git a/src/test-unicode-ranges.cc b/src/test-unicode-ranges.cc index ec9d17acd..d5d39b957 100644 --- a/src/test-unicode-ranges.cc +++ b/src/test-unicode-ranges.cc @@ -24,8 +24,6 @@ * Google Author(s): Garret Rieger */ -#include "hb.hh" - #include "hb-ot-os2-unicode-ranges.hh" static void