From 4f8c75acbd7598ee5664b558293fb542817e0091 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 2 Nov 2015 08:26:39 +0400 Subject: Update bundled HarfBuzz-NG to 1.0.6 - Unicode 8.0 support - Universal Shaping Engine - Various fixes, improvements, optimizations, etc. Change-Id: Ib6f8c92fa275c2a6575b9ae09068c92aecac7b4e Reviewed-by: Lars Knoll Reviewed-by: Eskil Abrahamsen Blomfeldt --- config.tests/unix/harfbuzz/harfbuzz.cpp | 2 +- src/3rdparty/harfbuzz-ng/NEWS | 115 ++++ src/3rdparty/harfbuzz-ng/README | 1 + src/3rdparty/harfbuzz-ng/config.h | 47 ++ src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro | 11 +- src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh | 102 +-- src/3rdparty/harfbuzz-ng/src/hb-blob.cc | 24 +- .../harfbuzz-ng/src/hb-buffer-deserialize-text.hh | 4 +- src/3rdparty/harfbuzz-ng/src/hb-buffer-private.hh | 14 +- .../harfbuzz-ng/src/hb-buffer-serialize.cc | 33 +- src/3rdparty/harfbuzz-ng/src/hb-buffer.cc | 219 +++++-- src/3rdparty/harfbuzz-ng/src/hb-buffer.h | 28 +- src/3rdparty/harfbuzz-ng/src/hb-common.cc | 47 +- src/3rdparty/harfbuzz-ng/src/hb-common.h | 10 + src/3rdparty/harfbuzz-ng/src/hb-coretext.cc | 106 ++-- src/3rdparty/harfbuzz-ng/src/hb-face.cc | 40 +- src/3rdparty/harfbuzz-ng/src/hb-font-private.hh | 2 +- src/3rdparty/harfbuzz-ng/src/hb-font.cc | 126 ++-- src/3rdparty/harfbuzz-ng/src/hb-font.h | 35 +- src/3rdparty/harfbuzz-ng/src/hb-mutex-private.hh | 10 +- src/3rdparty/harfbuzz-ng/src/hb-object-private.hh | 34 +- .../harfbuzz-ng/src/hb-open-file-private.hh | 20 +- .../harfbuzz-ng/src/hb-open-type-private.hh | 116 ++-- src/3rdparty/harfbuzz-ng/src/hb-ot-cmap-table.hh | 56 +- src/3rdparty/harfbuzz-ng/src/hb-ot-font.cc | 108 +++- src/3rdparty/harfbuzz-ng/src/hb-ot-font.h | 4 + src/3rdparty/harfbuzz-ng/src/hb-ot-glyf-table.hh | 104 +++ src/3rdparty/harfbuzz-ng/src/hb-ot-head-table.hh | 5 +- src/3rdparty/harfbuzz-ng/src/hb-ot-hhea-table.hh | 2 +- src/3rdparty/harfbuzz-ng/src/hb-ot-hmtx-table.hh | 2 +- .../harfbuzz-ng/src/hb-ot-layout-common-private.hh | 110 ++-- .../harfbuzz-ng/src/hb-ot-layout-gdef-table.hh | 44 +- .../harfbuzz-ng/src/hb-ot-layout-gpos-table.hh | 331 ++++++---- .../harfbuzz-ng/src/hb-ot-layout-gsub-table.hh | 311 ++++----- .../src/hb-ot-layout-gsubgpos-private.hh | 279 ++++----- .../harfbuzz-ng/src/hb-ot-layout-jstf-table.hh | 35 +- .../harfbuzz-ng/src/hb-ot-layout-private.hh | 45 +- src/3rdparty/harfbuzz-ng/src/hb-ot-layout.cc | 77 ++- src/3rdparty/harfbuzz-ng/src/hb-ot-map-private.hh | 7 +- src/3rdparty/harfbuzz-ng/src/hb-ot-map.cc | 10 + src/3rdparty/harfbuzz-ng/src/hb-ot-maxp-table.hh | 5 +- src/3rdparty/harfbuzz-ng/src/hb-ot-name-table.hh | 14 +- .../src/hb-ot-shape-complex-arabic-fallback.hh | 6 +- .../src/hb-ot-shape-complex-arabic-private.hh | 50 ++ .../src/hb-ot-shape-complex-arabic-table.hh | 26 +- .../harfbuzz-ng/src/hb-ot-shape-complex-arabic.cc | 39 +- .../harfbuzz-ng/src/hb-ot-shape-complex-hangul.cc | 13 +- .../src/hb-ot-shape-complex-indic-private.hh | 2 - .../harfbuzz-ng/src/hb-ot-shape-complex-indic.cc | 141 ++--- .../harfbuzz-ng/src/hb-ot-shape-complex-myanmar.cc | 77 +-- .../harfbuzz-ng/src/hb-ot-shape-complex-private.hh | 145 ++--- .../src/hb-ot-shape-complex-sea-machine.hh | 224 ------- .../harfbuzz-ng/src/hb-ot-shape-complex-sea.cc | 380 ----------- .../harfbuzz-ng/src/hb-ot-shape-complex-thai.cc | 4 +- .../src/hb-ot-shape-complex-use-machine.hh | 548 ++++++++++++++++ .../src/hb-ot-shape-complex-use-private.hh | 97 +++ .../src/hb-ot-shape-complex-use-table.cc | 696 +++++++++++++++++++++ .../harfbuzz-ng/src/hb-ot-shape-complex-use.cc | 585 +++++++++++++++++ .../harfbuzz-ng/src/hb-ot-shape-fallback.cc | 9 +- .../harfbuzz-ng/src/hb-ot-shape-normalize.cc | 50 +- src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc | 207 ++++-- src/3rdparty/harfbuzz-ng/src/hb-ot-tag.cc | 40 +- src/3rdparty/harfbuzz-ng/src/hb-private.hh | 122 ++-- src/3rdparty/harfbuzz-ng/src/hb-set-private.hh | 11 +- src/3rdparty/harfbuzz-ng/src/hb-set.cc | 52 +- src/3rdparty/harfbuzz-ng/src/hb-set.h | 3 + src/3rdparty/harfbuzz-ng/src/hb-shape-plan.cc | 36 +- src/3rdparty/harfbuzz-ng/src/hb-shape.cc | 85 ++- src/3rdparty/harfbuzz-ng/src/hb-shape.h | 3 - src/3rdparty/harfbuzz-ng/src/hb-shaper.cc | 2 +- src/3rdparty/harfbuzz-ng/src/hb-unicode-private.hh | 2 +- src/3rdparty/harfbuzz-ng/src/hb-unicode.cc | 33 +- src/3rdparty/harfbuzz-ng/src/hb-unicode.h | 41 +- src/3rdparty/harfbuzz-ng/src/hb-version.h | 8 +- src/3rdparty/harfbuzz-ng/src/hb-warning.cc | 24 +- 75 files changed, 4354 insertions(+), 2102 deletions(-) create mode 100644 src/3rdparty/harfbuzz-ng/config.h create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-glyf-table.hh create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-arabic-private.hh delete mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-sea-machine.hh delete mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-sea.cc create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-use-machine.hh create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-use-private.hh create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-use-table.cc create mode 100644 src/3rdparty/harfbuzz-ng/src/hb-ot-shape-complex-use.cc diff --git a/config.tests/unix/harfbuzz/harfbuzz.cpp b/config.tests/unix/harfbuzz/harfbuzz.cpp index bbaa9fc14d..1e6f7e70d6 100644 --- a/config.tests/unix/harfbuzz/harfbuzz.cpp +++ b/config.tests/unix/harfbuzz/harfbuzz.cpp @@ -33,7 +33,7 @@ #include -#if !HB_VERSION_ATLEAST(0, 9, 31) +#if !HB_VERSION_ATLEAST(0, 9, 42) # error "This version of harfbuzz is too old." #endif diff --git a/src/3rdparty/harfbuzz-ng/NEWS b/src/3rdparty/harfbuzz-ng/NEWS index c4950e2620..f2b0a32401 100644 --- a/src/3rdparty/harfbuzz-ng/NEWS +++ b/src/3rdparty/harfbuzz-ng/NEWS @@ -1,3 +1,118 @@ +Overview of changes leading to 1.0.6 +Thursday, October 15, 2015 +==================================== + +- Reduce max nesting level in OT lookups from 8 to 6. + Should not affect any real font as far as I know. +- Fix memory access issue in ot-font. +- Revert default load-flags of fonts created using hb_ft_font_create() + back to FT_LOAD_DEFAULT|FT_LOAD_NO_HINTING. This was changed in + last release (1.0.5), but caused major issues, so revert. + https://github.com/behdad/harfbuzz/issues/143 + + +Overview of changes leading to 1.0.5 +Tuesday, October 13, 2015 +==================================== + +- Fix multiple memory access bugs discovered using libFuzzer. + https://github.com/behdad/harfbuzz/issues/139 + Everyone should upgrade to this version as soon as possible. + We now have continuous fuzzing set up, to avoid issues like + these creeping in again. +- Misc fixes. + +- New API: + * hb_font_set_parent(). + * hb_ft_font_[sg]et_load_flags() + The default flags for fonts created using hb_ft_font_create() + has changed to default to FT_LOAD_DEFAULT now. Previously it + was defaulting to FT_LOAD_DFEAULT|FT_LOAD_NO_HINTING. + +- API changes: + * Fonts now default to units-per-EM as their scale, instead of 0. + * hb_font_create_sub_font() does NOT make parent font immutable + anymore. hb_font_make_immutable() does. + + +Overview of changes leading to 1.0.4 +Wednesday, September 30, 2015 +==================================== + +- Fix minor out-of-bounds read error. + + +Overview of changes leading to 1.0.3 +Tuesday, September 1, 2015 +==================================== + +- Start of user documentation, from Simon Cozens! +- Implement glyph_extents() for TrueType fonts in hb-ot-font. +- Improve GPOS cursive attachments with conflicting lookups. +- More fixes for cluster-level = 1. +- Uniscribe positioning fix. + + +Overview of changes leading to 1.0.2 +Wednesday, August 19, 2015 +==================================== + +- Fix shaping with cluster-level > 0. +- Fix Uniscribe backend font-size scaling. +- Declare dependencies in harfbuzz.pc. + FreeType is not declared though, to avoid bugs in pkg-config + 0.26 with recursive dependencies. +- Slightly improved debug infrastructure. More to come later. +- Misc build fixes. + + +Overview of changes leading to 1.0.1 +Monday, July 27, 2015 +==================================== + +- Fix out-of-bounds access in USE shaper. + + +Overview of changes leading to 1.0.0 +Sunday, July 26, 2015 +==================================== + +- Implement Universal Shaping Engine: + https://www.microsoft.com/typography/OpenTypeDev/USE/intro.htm + http://blogs.windows.com/bloggingwindows/2015/02/23/windows-shapes-the-worlds-languages/ +- Bump version to 1.0.0. The soname was NOT bumped. + + +Overview of changes leading to 0.9.42 +Thursday, July 26, 2015 +===================================== + +- New API to allow for retrieving finer-grained cluster + mappings if the client desires to handle them. Default + behavior is unchanged. +- Fix cluster merging when removing default-ignorables. +- Update to Unicode 8.0 +- hb-graphite2 fixes. +- Misc fixes. +- Removed HB_NO_MERGE_CLUSTERS hack. +- New API: + hb_buffer_cluster_level_t enum + hb_buffer_get_cluster_level() + hb_buffer_set_cluster_level() + hb-shape / hb-view --cluster-level + + +Overview of changes leading to 0.9.41 +Thursday, June 18, 2015 +===================================== + +- Fix hb-coretext with trailing whitespace in right-to-left. +- New API: hb_buffer_reverse_range(). +- Allow implementing atomic ops in config.h. +- Fix hb_language_t in language bindings. +- Misc fixes. + + Overview of changes leading to 0.9.40 Friday, March 20, 2015 ===================================== diff --git a/src/3rdparty/harfbuzz-ng/README b/src/3rdparty/harfbuzz-ng/README index d34bc74f99..dea10688f3 100644 --- a/src/3rdparty/harfbuzz-ng/README +++ b/src/3rdparty/harfbuzz-ng/README @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/behdad/harfbuzz.svg)](https://travis-ci.org/behdad/harfbuzz) [![Coverage Status](https://img.shields.io/coveralls/behdad/harfbuzz.svg)](https://coveralls.io/r/behdad/harfbuzz) +[![Coverity Scan](https://img.shields.io/coverity/scan/5450.svg)](https://scan.coverity.com/projects/5450) This is HarfBuzz, a text shaping library. diff --git a/src/3rdparty/harfbuzz-ng/config.h b/src/3rdparty/harfbuzz-ng/config.h new file mode 100644 index 0000000000..b8b6b3c0fe --- /dev/null +++ b/src/3rdparty/harfbuzz-ng/config.h @@ -0,0 +1,47 @@ +/* +* Copyright (C) 2015 The Qt Company Ltd. +* Copyright (C) 2015 Konstantin Ritt +* +* 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. +* +*/ + +#include + +QT_USE_NAMESPACE + +namespace { + +// We need to cast hb_atomic_int_t to QAtomicInt and pointers to +// QAtomicPointer instead of using QAtomicOps, otherwise we get a failed +// overload resolution of the template arguments for testAndSetOrdered. +template +inline QAtomicPointer *makeAtomicPointer(T * const &ptr) +{ + return reinterpret_cast *>(const_cast(&ptr)); +} + +} // namespace + +typedef int hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) reinterpret_cast(AI).fetchAndAddOrdered(V) + +#define hb_atomic_ptr_impl_get(P) makeAtomicPointer(*(P))->loadAcquire() +#define hb_atomic_ptr_impl_cmpexch(P,O,N) makeAtomicPointer(*(P))->testAndSetOrdered((O), (N)) diff --git a/src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro b/src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro index fb6771759b..031f7ecd58 100644 --- a/src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro +++ b/src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro @@ -7,7 +7,8 @@ CONFIG += \ load(qt_helper_lib) -DEFINES += HAVE_OT HAVE_QT5_ATOMICS HB_NO_UNICODE_FUNCS HB_DISABLE_DEPRECATED +DEFINES += HAVE_CONFIG_H +DEFINES += HAVE_OT HB_NO_UNICODE_FUNCS HB_DISABLE_DEPRECATED # platform/compiler specific definitions DEFINES += HAVE_ATEXIT @@ -45,6 +46,7 @@ HEADERS += \ $$PWD/src/hb-open-file-private.hh \ $$PWD/src/hb-open-type-private.hh \ $$PWD/src/hb-ot-cmap-table.hh \ + $$PWD/src/hb-ot-glyf-table.hh \ $$PWD/src/hb-ot-head-table.hh \ $$PWD/src/hb-ot-hhea-table.hh \ $$PWD/src/hb-ot-hmtx-table.hh \ @@ -86,9 +88,10 @@ SOURCES += \ $$PWD/src/hb-ot-shape-complex-indic.cc \ $$PWD/src/hb-ot-shape-complex-indic-table.cc \ $$PWD/src/hb-ot-shape-complex-myanmar.cc \ - $$PWD/src/hb-ot-shape-complex-sea.cc \ $$PWD/src/hb-ot-shape-complex-thai.cc \ $$PWD/src/hb-ot-shape-complex-tibetan.cc \ + $$PWD/src/hb-ot-shape-complex-use.cc \ + $$PWD/src/hb-ot-shape-complex-use-table.cc \ $$PWD/src/hb-ot-shape-fallback.cc \ $$PWD/src/hb-ot-shape-normalize.cc @@ -102,12 +105,14 @@ HEADERS += \ $$PWD/src/hb-ot-layout-private.hh \ $$PWD/src/hb-ot-map-private.hh \ $$PWD/src/hb-ot-shape-complex-arabic-fallback.hh \ + $$PWD/src/hb-ot-shape-complex-arabic-private.hh \ $$PWD/src/hb-ot-shape-complex-arabic-table.hh \ $$PWD/src/hb-ot-shape-complex-indic-machine.hh \ $$PWD/src/hb-ot-shape-complex-indic-private.hh \ $$PWD/src/hb-ot-shape-complex-myanmar-machine.hh \ $$PWD/src/hb-ot-shape-complex-private.hh \ - $$PWD/src/hb-ot-shape-complex-sea-machine.hh \ + $$PWD/src/hb-ot-shape-complex-use-machine.hh \ + $$PWD/src/hb-ot-shape-complex-use-private.hh \ $$PWD/src/hb-ot-shape-fallback-private.hh \ $$PWD/src/hb-ot-shape-normalize-private.hh \ $$PWD/src/hb-ot-shape-private.hh diff --git a/src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh index 48eb56141f..8179571ad2 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-atomic-private.hh @@ -39,27 +39,12 @@ /* We need external help for these */ -#if 0 +#if defined(hb_atomic_int_impl_add) \ + && defined(hb_atomic_ptr_impl_get) \ + && defined(hb_atomic_ptr_impl_cmpexch) -#elif !defined(HB_NO_MT) && defined(HAVE_QT5_ATOMICS) -#include +/* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */ -QT_USE_NAMESPACE - -namespace { -// We need to cast hb_atomic_int_t to QAtomicInt and pointers to -// QAtomicPointer instead of using QAtomicOps, otherwise we get a failed -// overload resolution of the template arguments for testAndSetOrdered. -template QAtomicPointer *makeAtomicPointer(T * const &ptr) -{ - return reinterpret_cast *>(const_cast(&ptr)); -} -} - -typedef int hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) reinterpret_cast(AI).fetchAndAddOrdered(V) -#define hb_atomic_ptr_get(P) makeAtomicPointer(*P)->loadAcquire() -#define hb_atomic_ptr_cmpexch(P,O,N) makeAtomicPointer(*P)->testAndSetOrdered((O), (N)) #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) @@ -77,11 +62,12 @@ static inline void _HBMemoryBarrier (void) { #endif } -typedef LONG hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) +typedef LONG hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) -#define hb_atomic_ptr_get(P) (_HBMemoryBarrier (), (void *) *(P)) -#define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) +#define hb_atomic_ptr_impl_get(P) (_HBMemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) #elif !defined(HB_NO_MT) && defined(__APPLE__) @@ -93,28 +79,31 @@ typedef LONG hb_atomic_int_t; #include #endif -typedef int32_t hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) -#define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +typedef int32_t hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) + +#define hb_atomic_ptr_impl_get(P) (OSMemoryBarrier (), (void *) *(P)) #if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) -#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) #else #if __ppc64__ || __x86_64__ || __aarch64__ -#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) #else -#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) #endif #endif #elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) -typedef int hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) +typedef int hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) __sync_fetch_and_add (&(AI), (V)) -#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) -#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) +#define hb_atomic_ptr_impl_get(P) (void *) (__sync_synchronize (), *(P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) #elif !defined(HB_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS) @@ -122,33 +111,54 @@ typedef int hb_atomic_int_t; #include #include -typedef unsigned int hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) ( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V)) +typedef unsigned int hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) ( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V)) -#define hb_atomic_ptr_get(P) ( ({__machine_rw_barrier ();}), (void *) *(P)) -#define hb_atomic_ptr_cmpexch(P,O,N) ( ({__machine_rw_barrier ();}), atomic_cas_ptr ((void **) (P), (void *) (O), (void *) (N)) == (void *) (O) ? true : false) +#define hb_atomic_ptr_impl_get(P) ( ({__machine_rw_barrier ();}), (void *) *(P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) ( ({__machine_rw_barrier ();}), atomic_cas_ptr ((void **) (P), (void *) (O), (void *) (N)) == (void *) (O) ? true : false) #elif !defined(HB_NO_MT) #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ -typedef volatile int hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) -#define hb_atomic_ptr_get(P) ((void *) *(P)) -#define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) +typedef volatile int hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) (((AI) += (V)) - (V)) + +#define hb_atomic_ptr_impl_get(P) ((void *) *(P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) #else /* HB_NO_MT */ -typedef int hb_atomic_int_t; -#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) +typedef int hb_atomic_int_impl_t; +#define HB_ATOMIC_INT_IMPL_INIT(V) (V) +#define hb_atomic_int_impl_add(AI, V) (((AI) += (V)) - (V)) + +#define hb_atomic_ptr_impl_get(P) ((void *) *(P)) +#define hb_atomic_ptr_impl_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false) -#define hb_atomic_ptr_get(P) ((void *) *(P)) -#define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false) #endif -/* TODO Add tracing. */ + +#define HB_ATOMIC_INT_INIT(V) {HB_ATOMIC_INT_IMPL_INIT(V)} + +struct hb_atomic_int_t +{ + hb_atomic_int_impl_t v; + + inline void set_unsafe (int v_) { v = v_; } + inline int get_unsafe (void) const { return v; } + inline int inc (void) { return hb_atomic_int_impl_add (const_cast (v), 1); } + inline int dec (void) { return hb_atomic_int_impl_add (const_cast (v), -1); } +}; + + +#define hb_atomic_ptr_get(P) hb_atomic_ptr_impl_get(P) +#define hb_atomic_ptr_cmpexch(P,O,N) hb_atomic_ptr_impl_cmpexch((P),(O),(N)) + #endif /* HB_ATOMIC_PRIVATE_HH */ diff --git a/src/3rdparty/harfbuzz-ng/src/hb-blob.cc b/src/3rdparty/harfbuzz-ng/src/hb-blob.cc index 8759a252a5..a6870dc06e 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-blob.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-blob.cc @@ -91,7 +91,7 @@ _hb_blob_destroy_user_data (hb_blob_t *blob) * Return value: New blob, or the empty blob if something failed or if @length is * zero. Destroy with hb_blob_destroy(). * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_blob_create (const char *data, @@ -147,7 +147,7 @@ hb_blob_create (const char *data, * @length is zero or @offset is beyond the end of @parent's data. Destroy * with hb_blob_destroy(). * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_blob_create_sub_blob (hb_blob_t *parent, @@ -179,7 +179,7 @@ hb_blob_create_sub_blob (hb_blob_t *parent, * * Return value: (transfer full): the empty blob. * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_blob_get_empty (void) @@ -210,7 +210,7 @@ hb_blob_get_empty (void) * * Return value: @blob. * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_blob_reference (hb_blob_t *blob) @@ -228,7 +228,7 @@ hb_blob_reference (hb_blob_t *blob) * * See TODO:link object types for more information. * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_blob_destroy (hb_blob_t *blob) @@ -250,7 +250,7 @@ hb_blob_destroy (hb_blob_t *blob) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_blob_set_user_data (hb_blob_t *blob, @@ -271,7 +271,7 @@ hb_blob_set_user_data (hb_blob_t *blob, * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ void * hb_blob_get_user_data (hb_blob_t *blob, @@ -287,7 +287,7 @@ hb_blob_get_user_data (hb_blob_t *blob, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_blob_make_immutable (hb_blob_t *blob) @@ -306,7 +306,7 @@ hb_blob_make_immutable (hb_blob_t *blob) * * Return value: TODO * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_blob_is_immutable (hb_blob_t *blob) @@ -323,7 +323,7 @@ hb_blob_is_immutable (hb_blob_t *blob) * * Return value: the length of blob data in bytes. * - * Since: 1.0 + * Since: 0.9.2 **/ unsigned int hb_blob_get_length (hb_blob_t *blob) @@ -340,7 +340,7 @@ hb_blob_get_length (hb_blob_t *blob) * * Returns: (transfer none) (array length=length): * - * Since: 1.0 + * Since: 0.9.2 **/ const char * hb_blob_get_data (hb_blob_t *blob, unsigned int *length) @@ -365,7 +365,7 @@ hb_blob_get_data (hb_blob_t *blob, unsigned int *length) * Returns: (transfer none) (array length=length): Writable blob data, * or %NULL if failed. * - * Since: 1.0 + * Since: 0.9.2 **/ char * hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length) diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer-deserialize-text.hh b/src/3rdparty/harfbuzz-ng/src/hb-buffer-deserialize-text.hh index 7a46ab278b..d2d8daae7e 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-buffer-deserialize-text.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer-deserialize-text.hh @@ -336,8 +336,8 @@ _hb_buffer_deserialize_glyphs_text (hb_buffer_t *buffer, const char *eof = pe, *tok = NULL; int cs; - hb_glyph_info_t info; - hb_glyph_position_t pos; + hb_glyph_info_t info = {0}; + hb_glyph_position_t pos = {0}; #line 343 "hb-buffer-deserialize-text.hh" { diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-buffer-private.hh index 069f925581..7fed7386b0 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-buffer-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer-private.hh @@ -50,6 +50,7 @@ struct hb_buffer_t { /* Information about how the text in the buffer should be treated */ hb_unicode_funcs_t *unicode; /* Unicode functions */ hb_buffer_flags_t flags; /* BOT / EOT / etc. */ + hb_buffer_cluster_level_t cluster_level; hb_codepoint_t replacement; /* U+FFFD or something else. */ /* Buffer contents */ @@ -171,9 +172,18 @@ struct hb_buffer_t { unsigned int cluster_end); HB_INTERNAL void merge_clusters (unsigned int start, - unsigned int end); + unsigned int end) + { + if (end - start < 2) + return; + merge_clusters_impl (start, end); + } + HB_INTERNAL void merge_clusters_impl (unsigned int start, + unsigned int end); HB_INTERNAL void merge_out_clusters (unsigned int start, unsigned int end); + /* Merge clusters for deleting current glyph, and skip it. */ + HB_INTERNAL void delete_glyph (void); /* Internal methods */ HB_INTERNAL bool enlarge (unsigned int size); @@ -191,6 +201,8 @@ struct hb_buffer_t { HB_INTERNAL scratch_buffer_t *get_scratch_buffer (unsigned int *size); inline void clear_context (unsigned int side) { context_len[side] = 0; } + + HB_INTERNAL void sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)); }; diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer-serialize.cc b/src/3rdparty/harfbuzz-ng/src/hb-buffer-serialize.cc index 406d69db75..7839cbc3f0 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-buffer-serialize.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer-serialize.cc @@ -40,7 +40,7 @@ static const char *serialize_formats[] = { * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ const char ** hb_buffer_serialize_list_formats (void) @@ -57,7 +57,7 @@ hb_buffer_serialize_list_formats (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_buffer_serialize_format_t hb_buffer_serialize_format_from_string (const char *str, int len) @@ -74,7 +74,7 @@ hb_buffer_serialize_format_from_string (const char *str, int len) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ const char * hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format) @@ -99,7 +99,8 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, hb_buffer_serialize_flags_t flags) { hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL); - hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, NULL); + hb_glyph_position_t *pos = (flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS) ? + NULL : hb_buffer_get_glyph_positions (buffer, NULL); *buf_consumed = 0; for (unsigned int i = start; i < end; i++) @@ -144,6 +145,16 @@ _hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, pos[i].x_advance, pos[i].y_advance); } + if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS) + { + hb_glyph_extents_t extents; + hb_font_get_glyph_extents(font, info[i].codepoint, &extents); + p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"xb\":%d,\"yb\":%d", + extents.x_bearing, extents.y_bearing)); + p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"w\":%d,\"h\":%d", + extents.width, extents.height)); + } + *p++ = '}'; unsigned int l = p - b; @@ -172,7 +183,8 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, hb_buffer_serialize_flags_t flags) { hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL); - hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, NULL); + hb_glyph_position_t *pos = (flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS) ? + NULL : hb_buffer_get_glyph_positions (buffer, NULL); *buf_consumed = 0; for (unsigned int i = start; i < end; i++) @@ -208,6 +220,13 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance)); } + if (flags & HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS) + { + hb_glyph_extents_t extents; + hb_font_get_glyph_extents(font, info[i].codepoint, &extents); + p += MAX (0, snprintf (p, ARRAY_LENGTH (b) - (p - b), "<%d,%d,%d,%d>", extents.x_bearing, extents.y_bearing, extents.width, extents.height)); + } + unsigned int l = p - b; if (buf_size > l) { @@ -240,7 +259,7 @@ _hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ unsigned int hb_buffer_serialize_glyphs (hb_buffer_t *buffer, @@ -347,7 +366,7 @@ parse_int (const char *pp, const char *end, int32_t *pv) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc b/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc index b9fe263ce5..50710dd23e 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer.cc @@ -36,6 +36,9 @@ #endif +/** + * Since: 0.9.7 + **/ hb_bool_t hb_segment_properties_equal (const hb_segment_properties_t *a, const hb_segment_properties_t *b) @@ -48,6 +51,9 @@ hb_segment_properties_equal (const hb_segment_properties_t *a, } +/** + * Since: 0.9.7 + **/ unsigned int hb_segment_properties_hash (const hb_segment_properties_t *p) { @@ -498,14 +504,10 @@ hb_buffer_t::reverse_clusters (void) } void -hb_buffer_t::merge_clusters (unsigned int start, - unsigned int end) +hb_buffer_t::merge_clusters_impl (unsigned int start, + unsigned int end) { -#ifdef HB_NO_MERGE_CLUSTERS - return; -#endif - - if (unlikely (end - start < 2)) + if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) return; unsigned int cluster = info[start].cluster; @@ -523,7 +525,7 @@ hb_buffer_t::merge_clusters (unsigned int start, /* If we hit the start of buffer, continue in out-buffer. */ if (idx == start) - for (unsigned i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--) + for (unsigned int i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--) out_info[i - 1].cluster = cluster; for (unsigned int i = start; i < end; i++) @@ -533,9 +535,8 @@ void hb_buffer_t::merge_out_clusters (unsigned int start, unsigned int end) { -#ifdef HB_NO_MERGE_CLUSTERS - return; -#endif + if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_CHARACTERS) + return; if (unlikely (end - start < 2)) return; @@ -555,12 +556,44 @@ hb_buffer_t::merge_out_clusters (unsigned int start, /* If we hit the end of out-buffer, continue in buffer. */ if (end == out_len) - for (unsigned i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++) + for (unsigned int i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++) info[i].cluster = cluster; for (unsigned int i = start; i < end; i++) out_info[i].cluster = cluster; } +void +hb_buffer_t::delete_glyph () +{ + unsigned int cluster = info[idx].cluster; + if (idx + 1 < len && cluster == info[idx + 1].cluster) + { + /* Cluster survives; do nothing. */ + goto done; + } + + if (out_len) + { + /* Merge cluster backward. */ + if (cluster < out_info[out_len - 1].cluster) + { + unsigned int old_cluster = out_info[out_len - 1].cluster; + for (unsigned i = out_len; i && out_info[i - 1].cluster == old_cluster; i--) + out_info[i - 1].cluster = cluster; + } + goto done; + } + + if (idx + 1 < len) + { + /* Merge cluster forward. */ + merge_clusters (idx, idx + 2); + goto done; + } + +done: + skip_glyph (); +} void hb_buffer_t::guess_segment_properties (void) @@ -671,7 +704,7 @@ void hb_buffer_t::deallocate_var_all (void) * * Return value: (transfer full) * - * Since: 1.0 + * Since: 0.9.2 **/ hb_buffer_t * hb_buffer_create (void) @@ -693,7 +726,7 @@ hb_buffer_create (void) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_buffer_t * hb_buffer_get_empty (void) @@ -703,6 +736,7 @@ hb_buffer_get_empty (void) const_cast (&_hb_unicode_funcs_nil), HB_BUFFER_FLAG_DEFAULT, + HB_BUFFER_CLUSTER_LEVEL_DEFAULT, HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT, HB_BUFFER_CONTENT_TYPE_INVALID, @@ -725,7 +759,7 @@ hb_buffer_get_empty (void) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_buffer_t * hb_buffer_reference (hb_buffer_t *buffer) @@ -739,7 +773,7 @@ hb_buffer_reference (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_destroy (hb_buffer_t *buffer) @@ -766,7 +800,7 @@ hb_buffer_destroy (hb_buffer_t *buffer) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_buffer_set_user_data (hb_buffer_t *buffer, @@ -787,7 +821,7 @@ hb_buffer_set_user_data (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ void * hb_buffer_get_user_data (hb_buffer_t *buffer, @@ -804,7 +838,7 @@ hb_buffer_get_user_data (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.5 **/ void hb_buffer_set_content_type (hb_buffer_t *buffer, @@ -821,7 +855,7 @@ hb_buffer_set_content_type (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.5 **/ hb_buffer_content_type_t hb_buffer_get_content_type (hb_buffer_t *buffer) @@ -837,7 +871,7 @@ hb_buffer_get_content_type (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, @@ -863,7 +897,7 @@ hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_unicode_funcs_t * hb_buffer_get_unicode_funcs (hb_buffer_t *buffer) @@ -878,7 +912,7 @@ hb_buffer_get_unicode_funcs (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_set_direction (hb_buffer_t *buffer, @@ -899,7 +933,7 @@ hb_buffer_set_direction (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_direction_t hb_buffer_get_direction (hb_buffer_t *buffer) @@ -914,7 +948,7 @@ hb_buffer_get_direction (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_set_script (hb_buffer_t *buffer, @@ -934,7 +968,7 @@ hb_buffer_set_script (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_script_t hb_buffer_get_script (hb_buffer_t *buffer) @@ -949,7 +983,7 @@ hb_buffer_get_script (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_set_language (hb_buffer_t *buffer, @@ -967,9 +1001,9 @@ hb_buffer_set_language (hb_buffer_t *buffer, * * * - * Return value: + * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_language_t hb_buffer_get_language (hb_buffer_t *buffer) @@ -984,7 +1018,7 @@ hb_buffer_get_language (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_buffer_set_segment_properties (hb_buffer_t *buffer, @@ -999,11 +1033,11 @@ hb_buffer_set_segment_properties (hb_buffer_t *buffer, /** * hb_buffer_get_segment_properties: * @buffer: a buffer. - * @props: + * @props: (out): * * * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_buffer_get_segment_properties (hb_buffer_t *buffer, @@ -1020,7 +1054,7 @@ hb_buffer_get_segment_properties (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_buffer_set_flags (hb_buffer_t *buffer, @@ -1040,7 +1074,7 @@ hb_buffer_set_flags (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.7 **/ hb_buffer_flags_t hb_buffer_get_flags (hb_buffer_t *buffer) @@ -1048,6 +1082,41 @@ hb_buffer_get_flags (hb_buffer_t *buffer) return buffer->flags; } +/** + * hb_buffer_set_cluster_level: + * @buffer: a buffer. + * @cluster_level: + * + * + * + * Since: 0.9.42 + **/ +void +hb_buffer_set_cluster_level (hb_buffer_t *buffer, + hb_buffer_cluster_level_t cluster_level) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->cluster_level = cluster_level; +} + +/** + * hb_buffer_get_cluster_level: + * @buffer: a buffer. + * + * + * + * Return value: + * + * Since: 0.9.42 + **/ +hb_buffer_cluster_level_t +hb_buffer_get_cluster_level (hb_buffer_t *buffer) +{ + return buffer->cluster_level; +} + /** * hb_buffer_set_replacement_codepoint: @@ -1056,7 +1125,7 @@ hb_buffer_get_flags (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.31 **/ void hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer, @@ -1076,7 +1145,7 @@ hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.31 **/ hb_codepoint_t hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer) @@ -1091,7 +1160,7 @@ hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_reset (hb_buffer_t *buffer) @@ -1105,7 +1174,7 @@ hb_buffer_reset (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.11 **/ void hb_buffer_clear_contents (hb_buffer_t *buffer) @@ -1122,7 +1191,7 @@ hb_buffer_clear_contents (hb_buffer_t *buffer) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size) @@ -1138,7 +1207,7 @@ hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_buffer_allocation_successful (hb_buffer_t *buffer) @@ -1154,7 +1223,7 @@ hb_buffer_allocation_successful (hb_buffer_t *buffer) * * * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_buffer_add (hb_buffer_t *buffer, @@ -1174,7 +1243,7 @@ hb_buffer_add (hb_buffer_t *buffer, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_buffer_set_length (hb_buffer_t *buffer, @@ -1213,7 +1282,7 @@ hb_buffer_set_length (hb_buffer_t *buffer, * * Return value: buffer length. * - * Since: 1.0 + * Since: 0.9.2 **/ unsigned int hb_buffer_get_length (hb_buffer_t *buffer) @@ -1231,7 +1300,7 @@ hb_buffer_get_length (hb_buffer_t *buffer) * * Return value: (transfer none) (array length=length): buffer glyph information array. * - * Since: 1.0 + * Since: 0.9.2 **/ hb_glyph_info_t * hb_buffer_get_glyph_infos (hb_buffer_t *buffer, @@ -1253,7 +1322,7 @@ hb_buffer_get_glyph_infos (hb_buffer_t *buffer, * * Return value: (transfer none) (array length=length): buffer glyph position array. * - * Since: 1.0 + * Since: 0.9.2 **/ hb_glyph_position_t * hb_buffer_get_glyph_positions (hb_buffer_t *buffer, @@ -1274,7 +1343,7 @@ hb_buffer_get_glyph_positions (hb_buffer_t *buffer, * * Reverses buffer contents. * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_reverse (hb_buffer_t *buffer) @@ -1282,6 +1351,23 @@ hb_buffer_reverse (hb_buffer_t *buffer) buffer->reverse (); } +/** + * hb_buffer_reverse_range: + * @buffer: a buffer. + * @start: start index. + * @end: end index. + * + * Reverses buffer contents between start to end. + * + * Since: 0.9.41 + **/ +void +hb_buffer_reverse_range (hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + buffer->reverse_range (start, end); +} + /** * hb_buffer_reverse_clusters: * @buffer: a buffer. @@ -1290,7 +1376,7 @@ hb_buffer_reverse (hb_buffer_t *buffer) * reversed, then each cluster (consecutive items having the * same cluster number) are reversed again. * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_reverse_clusters (hb_buffer_t *buffer) @@ -1320,7 +1406,7 @@ hb_buffer_reverse_clusters (hb_buffer_t *buffer) * hb_language_get_default(). This may change in the future by * taking buffer script into consideration when choosing a language. * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_buffer_guess_segment_properties (hb_buffer_t *buffer) @@ -1407,7 +1493,7 @@ hb_buffer_add_utf (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_add_utf8 (hb_buffer_t *buffer, @@ -1429,7 +1515,7 @@ hb_buffer_add_utf8 (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_add_utf16 (hb_buffer_t *buffer, @@ -1451,7 +1537,7 @@ hb_buffer_add_utf16 (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_add_utf32 (hb_buffer_t *buffer, @@ -1473,7 +1559,7 @@ hb_buffer_add_utf32 (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.39 **/ void hb_buffer_add_latin1 (hb_buffer_t *buffer, @@ -1495,7 +1581,7 @@ hb_buffer_add_latin1 (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.31 **/ void hb_buffer_add_codepoints (hb_buffer_t *buffer, @@ -1550,7 +1636,7 @@ normalize_glyphs_cluster (hb_buffer_t *buffer, pos[end - 1].x_advance = total_x_advance; pos[end - 1].y_advance = total_y_advance; - hb_bubble_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start); + hb_stable_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start); } else { /* Transfer all cluster advance to the first glyph. */ pos[start].x_advance += total_x_advance; @@ -1559,7 +1645,7 @@ normalize_glyphs_cluster (hb_buffer_t *buffer, pos[i].x_offset -= total_x_advance; pos[i].y_offset -= total_y_advance; } - hb_bubble_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1); + hb_stable_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1); } } @@ -1569,7 +1655,7 @@ normalize_glyphs_cluster (hb_buffer_t *buffer, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_buffer_normalize_glyphs (hb_buffer_t *buffer) @@ -1592,3 +1678,24 @@ hb_buffer_normalize_glyphs (hb_buffer_t *buffer) } normalize_glyphs_cluster (buffer, start, end, backward); } + +void +hb_buffer_t::sort (unsigned int start, unsigned int end, int(*compar)(const hb_glyph_info_t *, const hb_glyph_info_t *)) +{ + assert (!have_positions); + for (unsigned int i = start + 1; i < end; i++) + { + unsigned int j = i; + while (j > start && compar (&info[j - 1], &info[i]) > 0) + j--; + if (i == j) + continue; + /* Move item i to occupy place for item j, shift what's in between. */ + merge_clusters (j, i + 1); + { + hb_glyph_info_t t = info[i]; + memmove (&info[j + 1], &info[j], (i - j) * sizeof (hb_glyph_info_t)); + info[j] = t; + } + } +} diff --git a/src/3rdparty/harfbuzz-ng/src/hb-buffer.h b/src/3rdparty/harfbuzz-ng/src/hb-buffer.h index e5b46d867a..bb89dc3de7 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-buffer.h +++ b/src/3rdparty/harfbuzz-ng/src/hb-buffer.h @@ -171,6 +171,9 @@ void hb_buffer_guess_segment_properties (hb_buffer_t *buffer); +/* + * Since: 0.9.20 + */ typedef enum { /*< flags >*/ HB_BUFFER_FLAG_DEFAULT = 0x00000000u, HB_BUFFER_FLAG_BOT = 0x00000001u, /* Beginning-of-text */ @@ -185,7 +188,22 @@ hb_buffer_set_flags (hb_buffer_t *buffer, hb_buffer_flags_t hb_buffer_get_flags (hb_buffer_t *buffer); +/* + * Since: 0.9.42 + */ +typedef enum { + HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES = 0, + HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS = 1, + HB_BUFFER_CLUSTER_LEVEL_CHARACTERS = 2, + HB_BUFFER_CLUSTER_LEVEL_DEFAULT = HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES +} hb_buffer_cluster_level_t; +void +hb_buffer_set_cluster_level (hb_buffer_t *buffer, + hb_buffer_cluster_level_t cluster_level); + +hb_buffer_cluster_level_t +hb_buffer_get_cluster_level (hb_buffer_t *buffer); #define HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT 0xFFFDu @@ -221,6 +239,10 @@ hb_buffer_allocation_successful (hb_buffer_t *buffer); void hb_buffer_reverse (hb_buffer_t *buffer); +void +hb_buffer_reverse_range (hb_buffer_t *buffer, + unsigned int start, unsigned int end); + void hb_buffer_reverse_clusters (hb_buffer_t *buffer); @@ -303,11 +325,15 @@ hb_buffer_normalize_glyphs (hb_buffer_t *buffer); * Serialize */ +/* + * Since: 0.9.20 + */ typedef enum { /*< flags >*/ HB_BUFFER_SERIALIZE_FLAG_DEFAULT = 0x00000000u, HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001u, HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002u, - HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u + HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004u, + HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS = 0x00000008u } hb_buffer_serialize_flags_t; typedef enum { diff --git a/src/3rdparty/harfbuzz-ng/src/hb-common.cc b/src/3rdparty/harfbuzz-ng/src/hb-common.cc index 1516211e96..e67059d10b 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-common.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-common.cc @@ -64,7 +64,7 @@ _hb_options_init (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_tag_t hb_tag_from_string (const char *str, int len) @@ -92,7 +92,7 @@ hb_tag_from_string (const char *str, int len) * * * - * Since: 1.0 + * Since: 0.9.5 **/ void hb_tag_to_string (hb_tag_t tag, char *buf) @@ -122,7 +122,7 @@ const char direction_strings[][4] = { * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_direction_t hb_direction_from_string (const char *str, int len) @@ -149,7 +149,7 @@ hb_direction_from_string (const char *str, int len) * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ const char * hb_direction_to_string (hb_direction_t direction) @@ -179,7 +179,7 @@ static const char canon_map[256] = { 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0 }; -static hb_bool_t +static bool lang_equal (hb_language_t v1, const void *v2) { @@ -286,28 +286,28 @@ retry: * * * - * Return value: + * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_language_t hb_language_from_string (const char *str, int len) { - char strbuf[64]; - if (!str || !len || !*str) return HB_LANGUAGE_INVALID; + hb_language_item_t *item = NULL; if (len >= 0) { /* NUL-terminate it. */ + char strbuf[64]; len = MIN (len, (int) sizeof (strbuf) - 1); memcpy (strbuf, str, len); strbuf[len] = '\0'; - str = strbuf; + item = lang_find_or_insert (strbuf); } - - hb_language_item_t *item = lang_find_or_insert (str); + else + item = lang_find_or_insert (str); return likely (item) ? item->lang : HB_LANGUAGE_INVALID; } @@ -320,7 +320,7 @@ hb_language_from_string (const char *str, int len) * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ const char * hb_language_to_string (hb_language_t language) @@ -334,9 +334,9 @@ hb_language_to_string (hb_language_t language) * * * - * Return value: + * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_language_t hb_language_get_default (void) @@ -363,7 +363,7 @@ hb_language_get_default (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_script_t hb_script_from_iso15924_tag (hb_tag_t tag) @@ -408,7 +408,7 @@ hb_script_from_iso15924_tag (hb_tag_t tag) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_script_t hb_script_from_string (const char *s, int len) @@ -424,7 +424,7 @@ hb_script_from_string (const char *s, int len) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_tag_t hb_script_to_iso15924_tag (hb_script_t script) @@ -440,7 +440,7 @@ hb_script_to_iso15924_tag (hb_script_t script) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_direction_t hb_script_get_horizontal_direction (hb_script_t script) @@ -493,6 +493,9 @@ hb_script_get_horizontal_direction (hb_script_t script) case HB_SCRIPT_PALMYRENE: case HB_SCRIPT_PSALTER_PAHLAVI: + /* Unicode-8.0 additions */ + case HB_SCRIPT_OLD_HUNGARIAN: + return HB_DIRECTION_RTL; } @@ -542,7 +545,7 @@ hb_user_data_array_t::get (hb_user_data_key_t *key) * * Returns library version as three integer components. * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_version (unsigned int *major, @@ -561,7 +564,7 @@ hb_version (unsigned int *major, * * Return value: library version string. * - * Since: 1.0 + * Since: 0.9.2 **/ const char * hb_version_string (void) @@ -579,7 +582,7 @@ hb_version_string (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.30 **/ hb_bool_t hb_version_atleast (unsigned int major, diff --git a/src/3rdparty/harfbuzz-ng/src/hb-common.h b/src/3rdparty/harfbuzz-ng/src/hb-common.h index b6ce3f724d..c291dbbe94 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-common.h +++ b/src/3rdparty/harfbuzz-ng/src/hb-common.h @@ -272,6 +272,9 @@ typedef enum /*6.1*/ HB_SCRIPT_SORA_SOMPENG = HB_TAG ('S','o','r','a'), /*6.1*/ HB_SCRIPT_TAKRI = HB_TAG ('T','a','k','r'), + /* + * Since: 0.9.30 + */ /*7.0*/ HB_SCRIPT_BASSA_VAH = HB_TAG ('B','a','s','s'), /*7.0*/ HB_SCRIPT_CAUCASIAN_ALBANIAN = HB_TAG ('A','g','h','b'), /*7.0*/ HB_SCRIPT_DUPLOYAN = HB_TAG ('D','u','p','l'), @@ -296,6 +299,13 @@ typedef enum /*7.0*/ HB_SCRIPT_TIRHUTA = HB_TAG ('T','i','r','h'), /*7.0*/ HB_SCRIPT_WARANG_CITI = HB_TAG ('W','a','r','a'), + /*8.0*/ HB_SCRIPT_AHOM = HB_TAG ('A','h','o','m'), + /*8.0*/ HB_SCRIPT_ANATOLIAN_HIEROGLYPHS = HB_TAG ('H','l','u','w'), + /*8.0*/ HB_SCRIPT_HATRAN = HB_TAG ('H','a','t','r'), + /*8.0*/ HB_SCRIPT_MULTANI = HB_TAG ('M','u','l','t'), + /*8.0*/ HB_SCRIPT_OLD_HUNGARIAN = HB_TAG ('H','u','n','g'), + /*8.0*/ HB_SCRIPT_SIGNWRITING = HB_TAG ('S','g','n','w'), + /* No script set. */ HB_SCRIPT_INVALID = HB_TAG_NONE, diff --git a/src/3rdparty/harfbuzz-ng/src/hb-coretext.cc b/src/3rdparty/harfbuzz-ng/src/hb-coretext.cc index ab9e1d4a93..13ba5d94ef 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-coretext.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-coretext.cc @@ -38,19 +38,6 @@ #endif -typedef bool (*qt_get_font_table_func_t) (void *user_data, unsigned int tag, unsigned char *buffer, unsigned int *length); - -struct FontEngineFaceData { - void *user_data; - qt_get_font_table_func_t get_font_table; -}; - -struct CoreTextFontEngineData { - CTFontRef ctFont; - CGFontRef cgFont; -}; - - static void release_table_data (void *user_data) { @@ -104,7 +91,7 @@ hb_coretext_shaper_face_data_t * _hb_coretext_shaper_face_data_create (hb_face_t *face) { hb_coretext_shaper_face_data_t *data = NULL; -#if 0 + if (face->destroy == (hb_destroy_func_t) CGFontRelease) { data = CGFontRetain ((CGFontRef) face->user_data); @@ -124,11 +111,7 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face) CGDataProviderRelease (provider); } } -#else - FontEngineFaceData *fontEngineFaceData = (FontEngineFaceData *) face->user_data; - CoreTextFontEngineData *coreTextFontEngineData = (CoreTextFontEngineData *) fontEngineFaceData->user_data; - data = CGFontRetain (coreTextFontEngineData->cgFont); -#endif + if (unlikely (!data)) { DEBUG_MSG (CORETEXT, face, "Face CGFontCreateWithDataProvider() failed"); } @@ -142,6 +125,9 @@ _hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data) CFRelease (data); } +/* + * Since: 0.9.10 + */ CGFontRef hb_coretext_face_get_cg_font (hb_face_t *face) { @@ -170,10 +156,10 @@ _hb_coretext_shaper_font_data_create (hb_font_t *font) return NULL; hb_face_t *face = font->face; -#if 0 hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); /* Choose a CoreText font size and calculate multipliers to convert to HarfBuzz space. */ + /* TODO: use upem instead of 36? */ CGFloat font_size = 36.; /* Default... */ /* No idea if the following is even a good idea. */ if (font->y_ppem) @@ -184,12 +170,6 @@ _hb_coretext_shaper_font_data_create (hb_font_t *font) data->x_mult = (CGFloat) font->x_scale / font_size; data->y_mult = (CGFloat) font->y_scale / font_size; data->ct_font = CTFontCreateWithGraphicsFont (face_data, font_size, NULL, NULL); -#else - data->x_mult = data->y_mult = (CGFloat) 64.0f; - FontEngineFaceData *fontEngineFaceData = (FontEngineFaceData *) face->user_data; - CoreTextFontEngineData *coreTextFontEngineData = (CoreTextFontEngineData *) fontEngineFaceData->user_data; - data->ct_font = (CTFontRef) CFRetain (coreTextFontEngineData->ctFont); -#endif if (unlikely (!data->ct_font)) { DEBUG_MSG (CORETEXT, font, "Font CTFontCreateWithGraphicsFont() failed"); free (data); @@ -812,6 +792,17 @@ retry: buffer->len = 0; uint32_t status_and = ~0, status_or = 0; double advances_so_far = 0; + /* For right-to-left runs, CoreText returns the glyphs positioned such that + * any trailing whitespace is to the left of (0,0). Adjust coordinate system + * to fix for that. Test with any RTL string with trailing spaces. + * https://code.google.com/p/chromium/issues/detail?id=469028 + */ + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + { + advances_so_far -= CTLineGetTrailingWhitespaceWidth (line); + if (HB_DIRECTION_IS_VERTICAL (buffer->props.direction)) + advances_so_far = -advances_so_far; + } const CFRange range_all = CFRangeMake (0, 0); @@ -827,8 +818,6 @@ retry: run_advance = -run_advance; DEBUG_MSG (CORETEXT, run, "Run advance: %g", run_advance); - CFRange range = CTRunGetStringRange (run); - /* CoreText does automatic font fallback (AKA "cascading") for characters * not supported by the requested font, and provides no way to turn it off, * so we must detect if the returned run uses a font other than the requested @@ -895,6 +884,7 @@ retry: } if (!matched) { + CFRange range = CTRunGetStringRange (run); DEBUG_MSG (CORETEXT, run, "Run used fallback font: %ld..%ld", range.location, range.location + range.length); if (!buffer->ensure_inplace (buffer->len + range.length)) @@ -929,8 +919,8 @@ retry: info->cluster = log_clusters[j]; info->mask = advance; - info->var1.u32 = x_offset; - info->var2.u32 = y_offset; + info->var1.i32 = x_offset; + info->var2.i32 = y_offset; info++; buffer->len++; @@ -946,13 +936,7 @@ retry: if (num_glyphs == 0) continue; - /* ### temporary fix for QTBUG-38113 */ - /* CoreText throws away the PDF token, while the OpenType backend will add a zero-advance - * glyph for this. We need to make sure the two produce the same output. */ - UniChar endGlyph = CFStringGetCharacterAtIndex (string_ref, range.location + range.length - 1); - bool endsWithPDF = endGlyph == 0x202c; - - if (!buffer->ensure_inplace (buffer->len + num_glyphs + (endsWithPDF ? 1 : 0))) + if (!buffer->ensure_inplace (buffer->len + num_glyphs)) goto resize_and_retry; hb_glyph_info_t *run_info = buffer->info + buffer->len; @@ -1022,8 +1006,8 @@ retry: else /* last glyph */ advance = run_advance - (positions[j].x - positions[0].x); info->mask = advance * x_mult; - info->var1.u32 = x_offset; - info->var2.u32 = positions[j].y * y_mult; + info->var1.i32 = x_offset; + info->var2.i32 = positions[j].y * y_mult; info++; } } @@ -1038,25 +1022,11 @@ retry: else /* last glyph */ advance = run_advance - (positions[j].y - positions[0].y); info->mask = advance * y_mult; - info->var1.u32 = positions[j].x * x_mult; - info->var2.u32 = y_offset; + info->var1.i32 = positions[j].x * x_mult; + info->var2.i32 = y_offset; info++; } } - if (endsWithPDF) { - /* Ensure a zero-advance glyph the PDF token */ - if (unlikely (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))) { - memmove (run_info + 1, run_info, num_glyphs * sizeof (hb_glyph_info_t)); - info = run_info; - } - info->codepoint = 0xffff; - info->cluster = log_clusters[range.location + range.length - 1]; - info->mask = 0; - info->var1.u32 = 0; - info->var2.u32 = 0; - - buffer->len++; - } SCRATCH_RESTORE(); advances_so_far += run_advance; } @@ -1068,10 +1038,20 @@ retry: buffer->len += num_glyphs; } - /* Make sure all runs had the expected direction. */ - bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); - assert (bool (status_and & kCTRunStatusRightToLeft) == backward); - assert (bool (status_or & kCTRunStatusRightToLeft) == backward); + /* Mac OS 10.6 doesn't have kCTTypesetterOptionForcedEmbeddingLevel, + * or if it does, it doesn't resepct it. So we get runs with wrong + * directions. As such, disable the assert... It wouldn't crash, but + * cursoring will be off... + * + * http://crbug.com/419769 + */ + if (0) + { + /* Make sure all runs had the expected direction. */ + bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); + assert (bool (status_and & kCTRunStatusRightToLeft) == backward); + assert (bool (status_or & kCTRunStatusRightToLeft) == backward); + } buffer->clear_positions (); @@ -1082,16 +1062,16 @@ retry: for (unsigned int i = 0; i < count; i++) { pos->x_advance = info->mask; - pos->x_offset = info->var1.u32; - pos->y_offset = info->var2.u32; + pos->x_offset = info->var1.i32; + pos->y_offset = info->var2.i32; info++, pos++; } else for (unsigned int i = 0; i < count; i++) { pos->y_advance = info->mask; - pos->x_offset = info->var1.u32; - pos->y_offset = info->var2.u32; + pos->x_offset = info->var1.i32; + pos->y_offset = info->var2.i32; info++, pos++; } diff --git a/src/3rdparty/harfbuzz-ng/src/hb-face.cc b/src/3rdparty/harfbuzz-ng/src/hb-face.cc index 9348af7bf8..9effc41c88 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-face.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-face.cc @@ -77,7 +77,7 @@ const hb_face_t _hb_face_nil = { * * Return value: (transfer full) * - * Since: 1.0 + * Since: 0.9.2 **/ hb_face_t * hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, @@ -113,7 +113,7 @@ _hb_face_for_data_closure_create (hb_blob_t *blob, unsigned int index) { hb_face_for_data_closure_t *closure; - closure = (hb_face_for_data_closure_t *) malloc (sizeof (hb_face_for_data_closure_t)); + closure = (hb_face_for_data_closure_t *) calloc (1, sizeof (hb_face_for_data_closure_t)); if (unlikely (!closure)) return NULL; @@ -157,7 +157,7 @@ _hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_face_t * hb_face_create (hb_blob_t *blob, @@ -165,8 +165,8 @@ hb_face_create (hb_blob_t *blob, { hb_face_t *face; - if (unlikely (!blob || !hb_blob_get_length (blob))) - return hb_face_get_empty (); + if (unlikely (!blob)) + blob = hb_blob_get_empty (); hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer::sanitize (hb_blob_reference (blob)), index); @@ -189,7 +189,7 @@ hb_face_create (hb_blob_t *blob, * * Return value: (transfer full) * - * Since: 1.0 + * Since: 0.9.2 **/ hb_face_t * hb_face_get_empty (void) @@ -206,7 +206,7 @@ hb_face_get_empty (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_face_t * hb_face_reference (hb_face_t *face) @@ -220,7 +220,7 @@ hb_face_reference (hb_face_t *face) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_face_destroy (hb_face_t *face) @@ -257,7 +257,7 @@ hb_face_destroy (hb_face_t *face) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_face_set_user_data (hb_face_t *face, @@ -278,7 +278,7 @@ hb_face_set_user_data (hb_face_t *face, * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ void * hb_face_get_user_data (hb_face_t *face, @@ -293,7 +293,7 @@ hb_face_get_user_data (hb_face_t *face, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_face_make_immutable (hb_face_t *face) @@ -312,7 +312,7 @@ hb_face_make_immutable (hb_face_t *face) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_face_is_immutable (hb_face_t *face) @@ -330,7 +330,7 @@ hb_face_is_immutable (hb_face_t *face) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_face_reference_table (hb_face_t *face, @@ -347,7 +347,7 @@ hb_face_reference_table (hb_face_t *face, * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_blob_t * hb_face_reference_blob (hb_face_t *face) @@ -362,7 +362,7 @@ hb_face_reference_blob (hb_face_t *face) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_face_set_index (hb_face_t *face, @@ -382,7 +382,7 @@ hb_face_set_index (hb_face_t *face, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ unsigned int hb_face_get_index (hb_face_t *face) @@ -397,7 +397,7 @@ hb_face_get_index (hb_face_t *face) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_face_set_upem (hb_face_t *face, @@ -417,7 +417,7 @@ hb_face_set_upem (hb_face_t *face, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ unsigned int hb_face_get_upem (hb_face_t *face) @@ -441,7 +441,7 @@ hb_face_t::load_upem (void) const * * * - * Since: 1.0 + * Since: 0.9.7 **/ void hb_face_set_glyph_count (hb_face_t *face, @@ -461,7 +461,7 @@ hb_face_set_glyph_count (hb_face_t *face, * * Return value: * - * Since: 1.0 + * Since: 0.9.7 **/ unsigned int hb_face_get_glyph_count (hb_face_t *face) diff --git a/src/3rdparty/harfbuzz-ng/src/hb-font-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-font-private.hh index 33bbf7143a..c05499d4c2 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-font-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-font-private.hh @@ -268,7 +268,7 @@ struct hb_font_t { { *x = get_glyph_h_advance (glyph) / 2; - /* TODO use font_metics.ascent */ + /* TODO use font_metrics.ascent */ *y = y_scale; } diff --git a/src/3rdparty/harfbuzz-ng/src/hb-font.cc b/src/3rdparty/harfbuzz-ng/src/hb-font.cc index d42db59855..6a69cae313 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-font.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-font.cc @@ -236,7 +236,7 @@ static const hb_font_funcs_t _hb_font_funcs_nil = { * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_funcs_t * hb_font_funcs_create (void) @@ -258,7 +258,7 @@ hb_font_funcs_create (void) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_funcs_t * hb_font_funcs_get_empty (void) @@ -274,7 +274,7 @@ hb_font_funcs_get_empty (void) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_funcs_t * hb_font_funcs_reference (hb_font_funcs_t *ffuncs) @@ -288,7 +288,7 @@ hb_font_funcs_reference (hb_font_funcs_t *ffuncs) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_destroy (hb_font_funcs_t *ffuncs) @@ -315,7 +315,7 @@ hb_font_funcs_destroy (hb_font_funcs_t *ffuncs) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, @@ -336,7 +336,7 @@ hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ void * hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, @@ -352,7 +352,7 @@ hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) @@ -371,7 +371,7 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) @@ -425,7 +425,7 @@ HB_FONT_FUNCS_IMPLEMENT_CALLBACKS * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph (hb_font_t *font, @@ -444,7 +444,7 @@ hb_font_get_glyph (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_position_t hb_font_get_glyph_h_advance (hb_font_t *font, @@ -462,7 +462,7 @@ hb_font_get_glyph_h_advance (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_position_t hb_font_get_glyph_v_advance (hb_font_t *font, @@ -482,7 +482,7 @@ hb_font_get_glyph_v_advance (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_h_origin (hb_font_t *font, @@ -503,7 +503,7 @@ hb_font_get_glyph_h_origin (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_v_origin (hb_font_t *font, @@ -523,7 +523,7 @@ hb_font_get_glyph_v_origin (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_position_t hb_font_get_glyph_h_kerning (hb_font_t *font, @@ -542,7 +542,7 @@ hb_font_get_glyph_h_kerning (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_position_t hb_font_get_glyph_v_kerning (hb_font_t *font, @@ -561,7 +561,7 @@ hb_font_get_glyph_v_kerning (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_extents (hb_font_t *font, @@ -583,7 +583,7 @@ hb_font_get_glyph_extents (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_contour_point (hb_font_t *font, @@ -604,7 +604,7 @@ hb_font_get_glyph_contour_point (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_name (hb_font_t *font, @@ -625,7 +625,7 @@ hb_font_get_glyph_name (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_from_name (hb_font_t *font, @@ -648,7 +648,7 @@ hb_font_get_glyph_from_name (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_get_glyph_advance_for_direction (hb_font_t *font, @@ -669,7 +669,7 @@ hb_font_get_glyph_advance_for_direction (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_get_glyph_origin_for_direction (hb_font_t *font, @@ -690,7 +690,7 @@ hb_font_get_glyph_origin_for_direction (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_add_glyph_origin_for_direction (hb_font_t *font, @@ -711,7 +711,7 @@ hb_font_add_glyph_origin_for_direction (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, @@ -733,7 +733,7 @@ hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_get_glyph_kerning_for_direction (hb_font_t *font, @@ -755,7 +755,7 @@ hb_font_get_glyph_kerning_for_direction (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_extents_for_origin (hb_font_t *font, @@ -779,7 +779,7 @@ hb_font_get_glyph_extents_for_origin (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, @@ -800,7 +800,7 @@ hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_glyph_to_string (hb_font_t *font, @@ -822,7 +822,7 @@ hb_font_glyph_to_string (hb_font_t *font, * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_glyph_from_string (hb_font_t *font, @@ -845,7 +845,7 @@ hb_font_glyph_from_string (hb_font_t *font, * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_t * hb_font_create (hb_face_t *face) @@ -854,8 +854,6 @@ hb_font_create (hb_face_t *face) if (unlikely (!face)) face = hb_face_get_empty (); - if (unlikely (hb_object_is_inert (face))) - return hb_font_get_empty (); if (!(font = hb_object_create ())) return hb_font_get_empty (); @@ -863,6 +861,8 @@ hb_font_create (hb_face_t *face) font->face = hb_face_reference (face); font->klass = hb_font_funcs_get_empty (); + font->x_scale = font->y_scale = hb_face_get_upem (face); + return font; } @@ -874,20 +874,19 @@ hb_font_create (hb_face_t *face) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_t * hb_font_create_sub_font (hb_font_t *parent) { if (unlikely (!parent)) - return hb_font_get_empty (); + parent = hb_font_get_empty (); hb_font_t *font = hb_font_create (parent->face); if (unlikely (hb_object_is_inert (font))) return font; - hb_font_make_immutable (parent); font->parent = hb_font_reference (parent); font->x_scale = parent->x_scale; @@ -905,7 +904,7 @@ hb_font_create_sub_font (hb_font_t *parent) * * Return value: (transfer full) * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_t * hb_font_get_empty (void) @@ -946,7 +945,7 @@ hb_font_get_empty (void) * * Return value: (transfer full): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_t * hb_font_reference (hb_font_t *font) @@ -960,7 +959,7 @@ hb_font_reference (hb_font_t *font) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_destroy (hb_font_t *font) @@ -993,7 +992,7 @@ hb_font_destroy (hb_font_t *font) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_set_user_data (hb_font_t *font, @@ -1014,7 +1013,7 @@ hb_font_set_user_data (hb_font_t *font, * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ void * hb_font_get_user_data (hb_font_t *font, @@ -1029,7 +1028,7 @@ hb_font_get_user_data (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_make_immutable (hb_font_t *font) @@ -1037,6 +1036,9 @@ hb_font_make_immutable (hb_font_t *font) if (unlikely (hb_object_is_inert (font))) return; + if (font->parent) + hb_font_make_immutable (font->parent); + font->immutable = true; } @@ -1048,7 +1050,7 @@ hb_font_make_immutable (hb_font_t *font) * * Return value: * - * Since: 1.0 + * Since: 0.9.2 **/ hb_bool_t hb_font_is_immutable (hb_font_t *font) @@ -1056,6 +1058,32 @@ hb_font_is_immutable (hb_font_t *font) return font->immutable; } +/** + * hb_font_set_parent: + * @font: a font. + * @parent: new parent. + * + * Sets parent font of @font. + * + * Since: 1.0.5 + **/ +void +hb_font_set_parent (hb_font_t *font, + hb_font_t *parent) +{ + if (font->immutable) + return; + + if (!parent) + parent = hb_font_get_empty (); + + hb_font_t *old = font->parent; + + font->parent = hb_font_reference (parent); + + hb_font_destroy (old); +} + /** * hb_font_get_parent: * @font: a font. @@ -1064,7 +1092,7 @@ hb_font_is_immutable (hb_font_t *font) * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_font_t * hb_font_get_parent (hb_font_t *font) @@ -1080,7 +1108,7 @@ hb_font_get_parent (hb_font_t *font) * * Return value: (transfer none): * - * Since: 1.0 + * Since: 0.9.2 **/ hb_face_t * hb_font_get_face (hb_font_t *font) @@ -1098,7 +1126,7 @@ hb_font_get_face (hb_font_t *font) * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_set_funcs (hb_font_t *font, @@ -1133,7 +1161,7 @@ hb_font_set_funcs (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_set_funcs_data (hb_font_t *font, @@ -1163,7 +1191,7 @@ hb_font_set_funcs_data (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_set_scale (hb_font_t *font, @@ -1185,7 +1213,7 @@ hb_font_set_scale (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_get_scale (hb_font_t *font, @@ -1204,7 +1232,7 @@ hb_font_get_scale (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_set_ppem (hb_font_t *font, @@ -1226,7 +1254,7 @@ hb_font_set_ppem (hb_font_t *font, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_get_ppem (hb_font_t *font, diff --git a/src/3rdparty/harfbuzz-ng/src/hb-font.h b/src/3rdparty/harfbuzz-ng/src/hb-font.h index 7273db43ed..fb4a0eab5a 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-font.h +++ b/src/3rdparty/harfbuzz-ng/src/hb-font.h @@ -80,12 +80,13 @@ hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs); /* glyph extents */ +/* Note that height is negative in coordinate systems that grow up. */ typedef struct hb_glyph_extents_t { - hb_position_t x_bearing; - hb_position_t y_bearing; - hb_position_t width; - hb_position_t height; + hb_position_t x_bearing; /* left side of glyph from origin. */ + hb_position_t y_bearing; /* top side of glyph from origin. */ + hb_position_t width; /* distance from left to right side. */ + hb_position_t height; /* distance from top to bottom side. */ } hb_glyph_extents_t; @@ -148,7 +149,7 @@ typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void * * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs, @@ -164,7 +165,7 @@ hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, @@ -180,7 +181,7 @@ hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs, @@ -196,7 +197,7 @@ hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs, @@ -212,7 +213,7 @@ hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs, @@ -228,7 +229,7 @@ hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs, @@ -244,7 +245,7 @@ hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs, @@ -260,7 +261,7 @@ hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs, @@ -276,7 +277,7 @@ hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs, @@ -292,7 +293,7 @@ hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs, @@ -308,7 +309,7 @@ hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs, * * * - * Since: 1.0 + * Since: 0.9.2 **/ void hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs, @@ -458,6 +459,10 @@ hb_font_make_immutable (hb_font_t *font); hb_bool_t hb_font_is_immutable (hb_font_t *font); +void +hb_font_set_parent (hb_font_t *font, + hb_font_t *parent); + hb_font_t * hb_font_get_parent (hb_font_t *font); diff --git a/src/3rdparty/harfbuzz-ng/src/hb-mutex-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-mutex-private.hh index a8ea39ccfd..ed2703571c 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-mutex-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-mutex-private.hh @@ -39,7 +39,13 @@ /* We need external help for these */ -#if 0 +#if defined(HB_MUTEX_IMPL_INIT) \ + && defined(hb_mutex_impl_init) \ + && defined(hb_mutex_impl_lock) \ + && defined(hb_mutex_impl_unlock) \ + && defined(hb_mutex_impl_finish) + +/* Defined externally, i.e. in config.h; must have typedef'ed hb_mutex_impl_t as well. */ #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) @@ -113,10 +119,12 @@ typedef int hb_mutex_impl_t; #define hb_mutex_impl_unlock(M) HB_STMT_START {} HB_STMT_END #define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + #endif #define HB_MUTEX_INIT {HB_MUTEX_IMPL_INIT} + struct hb_mutex_t { /* TODO Add tracing. */ diff --git a/src/3rdparty/harfbuzz-ng/src/hb-object-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-object-private.hh index 7bd0f1624b..6b73ff92d0 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-object-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-object-private.hh @@ -47,19 +47,22 @@ /* reference_count */ -#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1) -#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE} +#define HB_REFERENCE_COUNT_INERT_VALUE -1 +#define HB_REFERENCE_COUNT_POISON_VALUE -0x0000DEAD +#define HB_REFERENCE_COUNT_INIT {HB_ATOMIC_INT_INIT(HB_REFERENCE_COUNT_INERT_VALUE)} + struct hb_reference_count_t { hb_atomic_int_t ref_count; - inline void init (int v) { ref_count = v; } - inline int inc (void) { return hb_atomic_int_add (const_cast (ref_count), 1); } - inline int dec (void) { return hb_atomic_int_add (const_cast (ref_count), -1); } - inline void finish (void) { ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; } - - inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; } + inline void init (int v) { ref_count.set_unsafe (v); } + inline int get_unsafe (void) const { return ref_count.get_unsafe (); } + inline int inc (void) { return ref_count.inc (); } + inline int dec (void) { return ref_count.dec (); } + inline void finish (void) { ref_count.set_unsafe (HB_REFERENCE_COUNT_POISON_VALUE); } + inline bool is_inert (void) const { return ref_count.get_unsafe () == HB_REFERENCE_COUNT_INERT_VALUE; } + inline bool is_valid (void) const { return ref_count.get_unsafe () > 0; } }; @@ -102,7 +105,7 @@ struct hb_object_header_t hb_reference_count_t ref_count; hb_user_data_array_t user_data; -#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT} +#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, HB_USER_DATA_ARRAY_INIT} private: ASSERT_POD (); @@ -117,7 +120,7 @@ static inline void hb_object_trace (const Type *obj, const char *function) DEBUG_MSG (OBJECT, (void *) obj, "%s refcount=%d", function, - obj ? obj->header.ref_count.ref_count : 0); + obj ? obj->header.ref_count.get_unsafe () : 0); } template @@ -141,7 +144,12 @@ static inline void hb_object_init (Type *obj) template static inline bool hb_object_is_inert (const Type *obj) { - return unlikely (obj->header.ref_count.is_invalid ()); + return unlikely (obj->header.ref_count.is_inert ()); +} +template +static inline bool hb_object_is_valid (const Type *obj) +{ + return likely (obj->header.ref_count.is_valid ()); } template static inline Type *hb_object_reference (Type *obj) @@ -149,6 +157,7 @@ static inline Type *hb_object_reference (Type *obj) hb_object_trace (obj, HB_FUNC); if (unlikely (!obj || hb_object_is_inert (obj))) return obj; + assert (hb_object_is_valid (obj)); obj->header.ref_count.inc (); return obj; } @@ -158,6 +167,7 @@ static inline bool hb_object_destroy (Type *obj) hb_object_trace (obj, HB_FUNC); if (unlikely (!obj || hb_object_is_inert (obj))) return false; + assert (hb_object_is_valid (obj)); if (obj->header.ref_count.dec () != 1) return false; @@ -174,6 +184,7 @@ static inline bool hb_object_set_user_data (Type *obj, { if (unlikely (!obj || hb_object_is_inert (obj))) return false; + assert (hb_object_is_valid (obj)); return obj->header.user_data.set (key, data, destroy, replace); } @@ -183,6 +194,7 @@ static inline void *hb_object_get_user_data (Type *obj, { if (unlikely (!obj || hb_object_is_inert (obj))) return NULL; + assert (hb_object_is_valid (obj)); return obj->header.user_data.get (key); } diff --git a/src/3rdparty/harfbuzz-ng/src/hb-open-file-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-open-file-private.hh index 178bc7ccb8..152230a0e5 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-open-file-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-open-file-private.hh @@ -56,7 +56,7 @@ typedef struct TableRecord inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } Tag tag; /* 4-byte identifier. */ @@ -106,7 +106,7 @@ typedef struct OffsetTable inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables)); + return_trace (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables)); } protected: @@ -135,7 +135,7 @@ struct TTCHeaderVersion1 inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (table.sanitize (c, this)); + return_trace (table.sanitize (c, this)); } protected: @@ -175,11 +175,11 @@ struct TTCHeader inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false); + if (unlikely (!u.header.version.sanitize (c))) return_trace (false); switch (u.header.version.major) { case 2: /* version 2 is compatible with version 1 */ - case 1: return TRACE_RETURN (u.version1.sanitize (c)); - default:return TRACE_RETURN (true); + case 1: return_trace (u.version1.sanitize (c)); + default:return_trace (true); } } @@ -240,14 +240,14 @@ struct OpenTypeFontFile inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false); + if (unlikely (!u.tag.sanitize (c))) return_trace (false); switch (u.tag) { case CFFTag: /* All the non-collection tags */ case TrueTag: case Typ1Tag: - case TrueTypeTag: return TRACE_RETURN (u.fontFace.sanitize (c)); - case TTCTag: return TRACE_RETURN (u.ttcHeader.sanitize (c)); - default: return TRACE_RETURN (true); + case TrueTypeTag: return_trace (u.fontFace.sanitize (c)); + case TTCTag: return_trace (u.ttcHeader.sanitize (c)); + default: return_trace (true); } } diff --git a/src/3rdparty/harfbuzz-ng/src/hb-open-type-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-open-type-private.hh index 75a0f568d1..f053502ded 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-open-type-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-open-type-private.hh @@ -154,6 +154,20 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) #define Null(Type) Null() +/* + * Dispatch + */ + +template +struct hb_dispatch_context_t +{ + static const unsigned int max_debug_depth = MaxDebugDepth; + typedef Return return_t; + template + inline bool may_dispatch (const T *obj, const F *format) { return true; } + static return_t no_dispatch_return_value (void) { return Context::default_return_value (); } +}; + /* * Sanitize @@ -174,17 +188,23 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) #define HB_SANITIZE_MAX_EDITS 100 #endif -struct hb_sanitize_context_t +struct hb_sanitize_context_t : + hb_dispatch_context_t { + inline hb_sanitize_context_t (void) : + debug_depth (0), + start (NULL), end (NULL), + writable (false), edit_count (0), + blob (NULL) {} + inline const char *get_name (void) { return "SANITIZE"; } - static const unsigned int max_debug_depth = HB_DEBUG_SANITIZE; - typedef bool return_t; template inline bool may_dispatch (const T *obj, const F *format) { return format->sanitize (this); } template inline return_t dispatch (const T &obj) { return obj.sanitize (this); } static return_t default_return_value (void) { return true; } + static return_t no_dispatch_return_value (void) { return false; } bool stop_sublookup_iteration (const return_t r) const { return !r; } inline void init (hb_blob_t *b) @@ -295,7 +315,7 @@ template struct Sanitizer { static hb_blob_t *sanitize (hb_blob_t *blob) { - hb_sanitize_context_t c[1] = {{0, NULL, NULL, false, 0, NULL}}; + hb_sanitize_context_t c[1]; bool sane; /* TODO is_sane() stuff */ @@ -379,9 +399,9 @@ struct Sanitizer struct hb_serialize_context_t { - inline hb_serialize_context_t (void *start, unsigned int size) + inline hb_serialize_context_t (void *start_, unsigned int size) { - this->start = (char *) start; + this->start = (char *) start_; this->end = this->start + size; this->ran_out_of_room = false; @@ -475,10 +495,10 @@ struct hb_serialize_context_t return reinterpret_cast (&obj); } - inline void truncate (void *head) + inline void truncate (void *new_head) { - assert (this->start < head && head <= this->head); - this->head = (char *) head; + assert (this->start < new_head && new_head <= this->head); + this->head = (char *) new_head; } unsigned int debug_depth; @@ -535,6 +555,20 @@ struct Supplier template struct BEInt; +template +struct BEInt +{ + public: + inline void set (Type V) + { + v = V; + } + inline operator Type (void) const + { + return v; + } + private: uint8_t v; +}; template struct BEInt { @@ -610,7 +644,7 @@ struct IntType inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (likely (c->check_struct (this))); + return_trace (likely (c->check_struct (this))); } protected: BEInt v; @@ -618,7 +652,7 @@ struct IntType DEFINE_SIZE_STATIC (Size); }; -typedef uint8_t BYTE; /* 8-bit unsigned integer. */ +typedef IntType BYTE; /* 8-bit unsigned integer. */ typedef IntType USHORT; /* 16-bit unsigned integer. */ typedef IntType SHORT; /* 16-bit signed integer. */ typedef IntType ULONG; /* 32-bit unsigned integer. */ @@ -638,7 +672,7 @@ struct LONGDATETIME inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (likely (c->check_struct (this))); + return_trace (likely (c->check_struct (this))); } protected: LONG major; @@ -715,7 +749,7 @@ struct FixedVersion inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } USHORT major; @@ -751,21 +785,21 @@ struct OffsetTo : Offset inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false); + if (unlikely (!c->check_struct (this))) return_trace (false); unsigned int offset = *this; - if (unlikely (!offset)) return TRACE_RETURN (true); + if (unlikely (!offset)) return_trace (true); const Type &obj = StructAtOffset (base, offset); - return TRACE_RETURN (likely (obj.sanitize (c)) || neuter (c)); + return_trace (likely (obj.sanitize (c)) || neuter (c)); } template inline bool sanitize (hb_sanitize_context_t *c, const void *base, T user_data) const { TRACE_SANITIZE (this); - if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false); + if (unlikely (!c->check_struct (this))) return_trace (false); unsigned int offset = *this; - if (unlikely (!offset)) return TRACE_RETURN (true); + if (unlikely (!offset)) return_trace (true); const Type &obj = StructAtOffset (base, offset); - return TRACE_RETURN (likely (obj.sanitize (c, user_data)) || neuter (c)); + return_trace (likely (obj.sanitize (c, user_data)) || neuter (c)); } /* Set the offset to Null */ @@ -816,10 +850,10 @@ struct ArrayOf unsigned int items_len) { TRACE_SERIALIZE (this); - if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!c->extend_min (*this))) return_trace (false); len.set (items_len); /* TODO(serialize) Overflow? */ - if (unlikely (!c->extend (*this))) return TRACE_RETURN (false); - return TRACE_RETURN (true); + if (unlikely (!c->extend (*this))) return_trace (false); + return_trace (true); } inline bool serialize (hb_serialize_context_t *c, @@ -827,17 +861,17 @@ struct ArrayOf unsigned int items_len) { TRACE_SERIALIZE (this); - if (unlikely (!serialize (c, items_len))) return TRACE_RETURN (false); + if (unlikely (!serialize (c, items_len))) return_trace (false); for (unsigned int i = 0; i < items_len; i++) array[i] = items[i]; items.advance (items_len); - return TRACE_RETURN (true); + return_trace (true); } inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + if (unlikely (!sanitize_shallow (c))) return_trace (false); /* Note: for structs that do not reference other structs, * we do not need to call their sanitize() as we already did @@ -848,28 +882,28 @@ struct ArrayOf */ (void) (false && array[0].sanitize (c)); - return TRACE_RETURN (true); + return_trace (true); } inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + if (unlikely (!sanitize_shallow (c))) return_trace (false); unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (unlikely (!array[i].sanitize (c, base))) - return TRACE_RETURN (false); - return TRACE_RETURN (true); + return_trace (false); + return_trace (true); } template inline bool sanitize (hb_sanitize_context_t *c, const void *base, T user_data) const { TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + if (unlikely (!sanitize_shallow (c))) return_trace (false); unsigned int count = len; for (unsigned int i = 0; i < count; i++) if (unlikely (!array[i].sanitize (c, base, user_data))) - return TRACE_RETURN (false); - return TRACE_RETURN (true); + return_trace (false); + return_trace (true); } template @@ -886,7 +920,7 @@ struct ArrayOf inline bool sanitize_shallow (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && c->check_array (this, Type::static_size, len)); + return_trace (c->check_struct (this) && c->check_array (array, Type::static_size, len)); } public: @@ -913,13 +947,13 @@ struct OffsetListOf : OffsetArrayOf inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (OffsetArrayOf::sanitize (c, this)); + return_trace (OffsetArrayOf::sanitize (c, this)); } template inline bool sanitize (hb_sanitize_context_t *c, T user_data) const { TRACE_SANITIZE (this); - return TRACE_RETURN (OffsetArrayOf::sanitize (c, this, user_data)); + return_trace (OffsetArrayOf::sanitize (c, this, user_data)); } }; @@ -941,14 +975,14 @@ struct HeadlessArrayOf unsigned int items_len) { TRACE_SERIALIZE (this); - if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!c->extend_min (*this))) return_trace (false); len.set (items_len); /* TODO(serialize) Overflow? */ - if (unlikely (!items_len)) return TRACE_RETURN (true); - if (unlikely (!c->extend (*this))) return TRACE_RETURN (false); + if (unlikely (!items_len)) return_trace (true); + if (unlikely (!c->extend (*this))) return_trace (false); for (unsigned int i = 0; i < items_len - 1; i++) array[i] = items[i]; items.advance (items_len - 1); - return TRACE_RETURN (true); + return_trace (true); } inline bool sanitize_shallow (hb_sanitize_context_t *c) const @@ -960,7 +994,7 @@ struct HeadlessArrayOf inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + if (unlikely (!sanitize_shallow (c))) return_trace (false); /* Note: for structs that do not reference other structs, * we do not need to call their sanitize() as we already did @@ -971,7 +1005,7 @@ struct HeadlessArrayOf */ (void) (false && array[0].sanitize (c)); - return TRACE_RETURN (true); + return_trace (true); } LenType len; diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-cmap-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-cmap-table.hh index 0482312553..c9161f0ef4 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-cmap-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-cmap-table.hh @@ -54,7 +54,7 @@ struct CmapSubtableFormat0 inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } protected: @@ -130,7 +130,7 @@ struct CmapSubtableFormat4 { TRACE_SANITIZE (this); if (unlikely (!c->check_struct (this))) - return TRACE_RETURN (false); + return_trace (false); if (unlikely (!c->check_range (this, length))) { @@ -141,10 +141,10 @@ struct CmapSubtableFormat4 (uintptr_t) (c->end - (char *) this)); if (!c->try_set (&length, new_length)) - return TRACE_RETURN (false); + return_trace (false); } - return TRACE_RETURN (16 + 4 * (unsigned int) segCountX2 <= length); + return_trace (16 + 4 * (unsigned int) segCountX2 <= length); } protected: @@ -187,7 +187,7 @@ struct CmapSubtableLongGroup inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } private: @@ -215,7 +215,7 @@ struct CmapSubtableTrimmed inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && glyphIdArray.sanitize (c)); + return_trace (c->check_struct (this) && glyphIdArray.sanitize (c)); } protected: @@ -248,7 +248,7 @@ struct CmapSubtableLongSegmented inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && groups.sanitize (c)); + return_trace (c->check_struct (this) && groups.sanitize (c)); } protected: @@ -295,7 +295,7 @@ struct UnicodeValueRange inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } UINT24 startUnicodeValue; /* First value in this range. */ @@ -317,7 +317,7 @@ struct UVSMapping inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } UINT24 unicodeValue; /* Base Unicode value of the UVS */ @@ -357,9 +357,9 @@ struct VariationSelectorRecord inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && - defaultUVS.sanitize (c, base) && - nonDefaultUVS.sanitize (c, base)); + return_trace (c->check_struct (this) && + defaultUVS.sanitize (c, base) && + nonDefaultUVS.sanitize (c, base)); } UINT24 varSelector; /* Variation selector. */ @@ -383,8 +383,8 @@ struct CmapSubtableFormat14 inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && - record.sanitize (c, this)); + return_trace (c->check_struct (this) && + record.sanitize (c, this)); } protected: @@ -429,16 +429,16 @@ struct CmapSubtable inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - if (!u.format.sanitize (c)) return TRACE_RETURN (false); + if (!u.format.sanitize (c)) return_trace (false); switch (u.format) { - case 0: return TRACE_RETURN (u.format0 .sanitize (c)); - case 4: return TRACE_RETURN (u.format4 .sanitize (c)); - case 6: return TRACE_RETURN (u.format6 .sanitize (c)); - case 10: return TRACE_RETURN (u.format10.sanitize (c)); - case 12: return TRACE_RETURN (u.format12.sanitize (c)); - case 13: return TRACE_RETURN (u.format13.sanitize (c)); - case 14: return TRACE_RETURN (u.format14.sanitize (c)); - default:return TRACE_RETURN (true); + case 0: return_trace (u.format0 .sanitize (c)); + case 4: return_trace (u.format4 .sanitize (c)); + case 6: return_trace (u.format6 .sanitize (c)); + case 10: return_trace (u.format10.sanitize (c)); + case 12: return_trace (u.format12.sanitize (c)); + case 13: return_trace (u.format13.sanitize (c)); + case 14: return_trace (u.format14.sanitize (c)); + default:return_trace (true); } } @@ -473,8 +473,8 @@ struct EncodingRecord inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && - subtable.sanitize (c, base)); + return_trace (c->check_struct (this) && + subtable.sanitize (c, base)); } USHORT platformID; /* Platform ID. */ @@ -509,9 +509,9 @@ struct cmap inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && - likely (version == 0) && - encodingRecord.sanitize (c, this)); + return_trace (c->check_struct (this) && + likely (version == 0) && + encodingRecord.sanitize (c, this)); } USHORT version; /* Table version number (0). */ diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-font.cc b/src/3rdparty/harfbuzz-ng/src/hb-ot-font.cc index 2af2f54a75..69d2503abb 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-font.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-font.cc @@ -31,6 +31,8 @@ #include "hb-font-private.hh" #include "hb-ot-cmap-table.hh" +#include "hb-ot-glyf-table.hh" +#include "hb-ot-head-table.hh" #include "hb-ot-hhea-table.hh" #include "hb-ot-hmtx-table.hh" @@ -45,9 +47,9 @@ struct hb_ot_face_metrics_accelerator_t inline void init (hb_face_t *face, hb_tag_t _hea_tag, hb_tag_t _mtx_tag, - unsigned int default_advance) + unsigned int default_advance_) { - this->default_advance = default_advance; + this->default_advance = default_advance_; this->num_metrics = face->get_num_glyphs (); hb_blob_t *_hea_blob = OT::Sanitizer::sanitize (face->reference_table (_hea_tag)); @@ -57,7 +59,7 @@ struct hb_ot_face_metrics_accelerator_t this->blob = OT::Sanitizer::sanitize (face->reference_table (_mtx_tag)); if (unlikely (!this->num_advances || - 2 * (this->num_advances + this->num_metrics) < hb_blob_get_length (this->blob))) + 2 * (this->num_advances + this->num_metrics) > hb_blob_get_length (this->blob))) { this->num_metrics = this->num_advances = 0; hb_blob_destroy (this->blob); @@ -76,8 +78,8 @@ struct hb_ot_face_metrics_accelerator_t if (unlikely (glyph >= this->num_metrics)) { /* If this->num_metrics is zero, it means we don't have the metrics table - * for this direction: return one EM. Otherwise, it means that the glyph - * index is out of bound: return zero. */ + * for this direction: return default advance. Otherwise, it means that the + * glyph index is out of bound: return zero. */ if (this->num_metrics) return 0; else @@ -91,6 +93,79 @@ struct hb_ot_face_metrics_accelerator_t } }; +struct hb_ot_face_glyf_accelerator_t +{ + bool short_offset; + unsigned int num_glyphs; + const OT::loca *loca; + const OT::glyf *glyf; + hb_blob_t *loca_blob; + hb_blob_t *glyf_blob; + unsigned int glyf_len; + + inline void init (hb_face_t *face) + { + hb_blob_t *head_blob = OT::Sanitizer::sanitize (face->reference_table (HB_OT_TAG_head)); + const OT::head *head = OT::Sanitizer::lock_instance (head_blob); + if ((unsigned int) head->indexToLocFormat > 1 || head->glyphDataFormat != 0) + { + /* Unknown format. Leave num_glyphs=0, that takes care of disabling us. */ + hb_blob_destroy (head_blob); + return; + } + this->short_offset = 0 == head->indexToLocFormat; + hb_blob_destroy (head_blob); + + this->loca_blob = OT::Sanitizer::sanitize (face->reference_table (HB_OT_TAG_loca)); + this->loca = OT::Sanitizer::lock_instance (this->loca_blob); + this->glyf_blob = OT::Sanitizer::sanitize (face->reference_table (HB_OT_TAG_glyf)); + this->glyf = OT::Sanitizer::lock_instance (this->glyf_blob); + + this->num_glyphs = MAX (1u, hb_blob_get_length (this->loca_blob) / (this->short_offset ? 2 : 4)) - 1; + this->glyf_len = hb_blob_get_length (this->glyf_blob); + } + + inline void fini (void) + { + hb_blob_destroy (this->loca_blob); + hb_blob_destroy (this->glyf_blob); + } + + inline bool get_extents (hb_codepoint_t glyph, + hb_glyph_extents_t *extents) const + { + if (unlikely (glyph >= this->num_glyphs)) + return false; + + unsigned int start_offset, end_offset; + if (this->short_offset) + { + start_offset = 2 * this->loca->u.shortsZ[glyph]; + end_offset = 2 * this->loca->u.shortsZ[glyph + 1]; + } + else + { + start_offset = this->loca->u.longsZ[glyph]; + end_offset = this->loca->u.longsZ[glyph + 1]; + } + + if (start_offset > end_offset || end_offset > this->glyf_len) + return false; + + if (end_offset - start_offset < OT::glyfGlyphHeader::static_size) + return true; /* Empty glyph; zero extents. */ + + const OT::glyfGlyphHeader &glyph_header = OT::StructAtOffset (this->glyf, start_offset); + + extents->x_bearing = MIN (glyph_header.xMin, glyph_header.xMax); + extents->y_bearing = MAX (glyph_header.yMin, glyph_header.yMax); + extents->width = MAX (glyph_header.xMin, glyph_header.xMax) - extents->x_bearing; + extents->height = MIN (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing; + + return true; + } +}; + struct hb_ot_face_cmap_accelerator_t { const OT::CmapSubtable *table; @@ -114,6 +189,7 @@ struct hb_ot_face_cmap_accelerator_t if (!subtable) subtable = cmap->find_subtable (0, 2); if (!subtable) subtable = cmap->find_subtable (0, 1); if (!subtable) subtable = cmap->find_subtable (0, 0); + if (!subtable) subtable = cmap->find_subtable (3, 0); /* Meh. */ if (!subtable) subtable = &OT::Null(OT::CmapSubtable); @@ -157,14 +233,14 @@ struct hb_ot_font_t hb_ot_face_cmap_accelerator_t cmap; hb_ot_face_metrics_accelerator_t h_metrics; hb_ot_face_metrics_accelerator_t v_metrics; + hb_ot_face_glyf_accelerator_t glyf; }; static hb_ot_font_t * -_hb_ot_font_create (hb_font_t *font) +_hb_ot_font_create (hb_face_t *face) { hb_ot_font_t *ot_font = (hb_ot_font_t *) calloc (1, sizeof (hb_ot_font_t)); - hb_face_t *face = font->face; if (unlikely (!ot_font)) return NULL; @@ -174,6 +250,7 @@ _hb_ot_font_create (hb_font_t *font) ot_font->cmap.init (face); ot_font->h_metrics.init (face, HB_OT_TAG_hhea, HB_OT_TAG_hmtx, upem>>1); ot_font->v_metrics.init (face, HB_OT_TAG_vhea, HB_OT_TAG_vmtx, upem); /* TODO Can we do this lazily? */ + ot_font->glyf.init (face); return ot_font; } @@ -184,6 +261,7 @@ _hb_ot_font_destroy (hb_ot_font_t *ot_font) ot_font->cmap.fini (); ot_font->h_metrics.fini (); ot_font->v_metrics.fini (); + ot_font->glyf.fini (); free (ot_font); } @@ -219,7 +297,7 @@ hb_ot_get_glyph_v_advance (hb_font_t *font HB_UNUSED, void *user_data HB_UNUSED) { const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; - return font->em_scale_y (-ot_font->v_metrics.get_advance (glyph)); + return font->em_scale_y (-(int) ot_font->v_metrics.get_advance (glyph)); } static hb_bool_t @@ -275,8 +353,13 @@ hb_ot_get_glyph_extents (hb_font_t *font HB_UNUSED, hb_glyph_extents_t *extents, void *user_data HB_UNUSED) { - /* TODO */ - return false; + const hb_ot_font_t *ot_font = (const hb_ot_font_t *) font_data; + bool ret = ot_font->glyf.get_extents (glyph, extents); + extents->x_bearing = font->em_scale_x (extents->x_bearing); + extents->y_bearing = font->em_scale_y (extents->y_bearing); + extents->width = font->em_scale_x (extents->width); + extents->height = font->em_scale_y (extents->height); + return ret; } static hb_bool_t @@ -334,10 +417,13 @@ _hb_ot_get_font_funcs (void) } +/** + * Since: 0.9.28 + **/ void hb_ot_font_set_funcs (hb_font_t *font) { - hb_ot_font_t *ot_font = _hb_ot_font_create (font); + hb_ot_font_t *ot_font = _hb_ot_font_create (font->face); if (unlikely (!ot_font)) return; diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-font.h b/src/3rdparty/harfbuzz-ng/src/hb-ot-font.h index 7a8c04ac33..b9947a16bc 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-font.h +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-font.h @@ -24,6 +24,10 @@ * Google Author(s): Behdad Esfahbod, Roozbeh Pournader */ +#ifndef HB_OT_H_IN +#error "Include instead." +#endif + #ifndef HB_OT_FONT_H #define HB_OT_FONT_H diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-glyf-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-glyf-table.hh new file mode 100644 index 0000000000..9e5af6d10d --- /dev/null +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-glyf-table.hh @@ -0,0 +1,104 @@ +/* + * Copyright © 2015 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_OT_GLYF_TABLE_HH +#define HB_OT_GLYF_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * loca -- Index to Location + */ + +#define HB_OT_TAG_loca HB_TAG('l','o','c','a') + + +struct loca +{ + static const hb_tag_t tableTag = HB_OT_TAG_loca; + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (true); + } + + public: + union { + USHORT shortsZ[VAR]; /* Location offset divided by 2. */ + ULONG longsZ[VAR]; /* Location offset. */ + } u; + DEFINE_SIZE_ARRAY (0, u.longsZ); +}; + + +/* + * glyf -- TrueType Glyph Data + */ + +#define HB_OT_TAG_glyf HB_TAG('g','l','y','f') + + +struct glyf +{ + static const hb_tag_t tableTag = HB_OT_TAG_glyf; + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + /* We don't check for anything specific here. The users of the + * struct do all the hard work... */ + return_trace (true); + } + + public: + BYTE dataX[VAR]; /* Glyphs data. */ + + DEFINE_SIZE_ARRAY (0, dataX); +}; + +struct glyfGlyphHeader +{ + SHORT numberOfContours; /* If the number of contours is + * greater than or equal to zero, + * this is a simple glyph; if negative, + * this is a composite glyph. */ + SHORT xMin; /* Minimum x for coordinate data. */ + SHORT yMin; /* Minimum y for coordinate data. */ + SHORT xMax; /* Maximum x for coordinate data. */ + SHORT yMax; /* Maximum y for coordinate data. */ + + DEFINE_SIZE_STATIC (10); +}; + +} /* namespace OT */ + + +#endif /* HB_OT_GLYF_TABLE_HH */ diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-head-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-head-table.hh index 268f133408..fc351cfb48 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-head-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-head-table.hh @@ -55,7 +55,7 @@ struct head inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1)); + return_trace (c->check_struct (this) && likely (version.major == 1)); } protected: @@ -138,9 +138,10 @@ struct head * 2: Like 1 but also contains neutrals; * -1: Only strongly right to left; * -2: Like -1 but also contains neutrals. */ + public: SHORT indexToLocFormat; /* 0 for short offsets, 1 for long. */ SHORT glyphDataFormat; /* 0 for current format. */ - public: + DEFINE_SIZE_STATIC (54); }; diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-hhea-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-hhea-table.hh index 992fe55202..24114534a7 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-hhea-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-hhea-table.hh @@ -52,7 +52,7 @@ struct _hea inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1)); + return_trace (c->check_struct (this) && likely (version.major == 1)); } public: diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-hmtx-table.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-hmtx-table.hh index a0e3855a84..49056e6769 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-hmtx-table.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-hmtx-table.hh @@ -62,7 +62,7 @@ struct _mtx TRACE_SANITIZE (this); /* We don't check for anything specific here. The users of the * struct do all the hard work... */ - return TRACE_RETURN (true); + return_trace (true); } public: diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-common-private.hh b/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-common-private.hh index 3db7f57ab4..ea61f5c1bd 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-common-private.hh +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-layout-common-private.hh @@ -44,7 +44,7 @@ namespace OT { #define NOT_COVERED ((unsigned int) -1) -#define MAX_NESTING_LEVEL 8 +#define MAX_NESTING_LEVEL 6 #define MAX_CONTEXT_LENGTH 64 @@ -75,7 +75,7 @@ struct Record { TRACE_SANITIZE (this); const sanitize_closure_t closure = {tag, base}; - return TRACE_RETURN (c->check_struct (this) && offset.sanitize (c, base, &closure)); + return_trace (c->check_struct (this) && offset.sanitize (c, base, &closure)); } Tag tag; /* 4-byte Tag identifier */ @@ -131,7 +131,7 @@ struct RecordListOf : RecordArrayOf inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (RecordArrayOf::sanitize (c, this)); + return_trace (RecordArrayOf::sanitize (c, this)); } }; @@ -145,7 +145,7 @@ struct RangeRecord inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this)); + return_trace (c->check_struct (this)); } inline bool intersects (const hb_set_t *glyphs) const { @@ -211,7 +211,7 @@ struct LangSys const Record::sanitize_closure_t * = NULL) const { TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c)); + return_trace (c->check_struct (this) && featureIndex.sanitize (c)); } Offset<> lookupOrderZ; /* = Null (reserved for an offset to a @@ -251,7 +251,7 @@ struct Script const Record