mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 17:01:17 +01:00
Merge branch 'master' into cff-subset
This commit is contained in:
commit
161b642ec5
93 files changed
+2587
-2532
No files matched your search
@@ -40,14 +40,14 @@ jobs:
|
||||
- run: rm -rf harfbuzz-*
|
||||
- run: make distdir && cd harfbuzz-* && cmake -DHB_CHECK=ON -Bbuild -H. -GNinja && ninja -Cbuild && CTEST_OUTPUT_ON_FAILURE=1 ninja -Cbuild test && ninja -Cbuild install
|
||||
|
||||
alpine-O3:
|
||||
alpine-O3-NOMMAP:
|
||||
docker:
|
||||
- image: alpine
|
||||
steps:
|
||||
- checkout
|
||||
- run: apk update && apk add ragel make pkgconfig libtool autoconf automake gettext gcc g++ glib-dev freetype-dev cairo-dev
|
||||
# C??FLAGS are not needed for a regular build
|
||||
- run: CFLAGS="-O3" CXXFLAGS="-O3" ./autogen.sh
|
||||
- run: CFLAGS="-O3" CXXFLAGS="-O3 -DHB_NO_MMAP" ./autogen.sh
|
||||
- run: make
|
||||
- run: make check || .ci/fail.sh
|
||||
|
||||
@@ -68,7 +68,8 @@ jobs:
|
||||
- image: multiarch/crossbuild
|
||||
steps:
|
||||
- checkout
|
||||
- run: apt update && apt install -y ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev python python-pip
|
||||
- run: apt update || true
|
||||
- run: apt install -y ragel libfreetype6-dev libglib2.0-dev libcairo2-dev libicu-dev libgraphite2-dev python python-pip
|
||||
- run: pip install fonttools
|
||||
- run: wget http://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.bz2 && tar xf freetype-2.9.tar.bz2 && cd freetype-2.9 && ./autogen.sh && ./configure && make -j4 && cd ..
|
||||
- run: CFLAGS="-O3" CXXFLAGS="-O3" CC=clang CXX=clang++ ./autogen.sh --with-freetype --with-glib --with-cairo --with-icu --with-graphite2
|
||||
@@ -196,7 +197,7 @@ workflows:
|
||||
- distcheck
|
||||
|
||||
# autotools based builds
|
||||
- alpine-O3
|
||||
- alpine-O3-NOMMAP
|
||||
- archlinux-debug-O0-py3
|
||||
- clang-O3-O0
|
||||
- fedora-outoftreebuild
|
||||
|
||||
+1
-2
@@ -834,9 +834,8 @@ set_target_properties(hb-ot-tag PROPERTIES COMPILE_FLAGS "-DMAIN")
|
||||
if (UNIX OR MINGW)
|
||||
if (BUILD_SHARED_LIBS)
|
||||
# generate harfbuzz.def after build completion
|
||||
string(REPLACE ";" " " space_separated_headers "${project_headers}")
|
||||
add_custom_command(TARGET harfbuzz POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env "headers=${space_separated_headers}" python ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def
|
||||
COMMAND "${PYTHON_EXECUTABLE}" ${PROJECT_SOURCE_DIR}/src/gen-def.py ${PROJECT_BINARY_DIR}/harfbuzz.def ${project_headers}
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src)
|
||||
|
||||
add_test(NAME check-static-inits.sh
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
Overview of changes leading to 1.8.4
|
||||
Tuesday, July 17, 2018
|
||||
====================================
|
||||
- Fix build on non-C++11.
|
||||
- Use C++-style GCC atomics and C++11 atomics.
|
||||
|
||||
|
||||
Overview of changes leading to 1.8.3
|
||||
Wednesday, July 11, 2018
|
||||
====================================
|
||||
- A couple of Indic / USE bug fixes.
|
||||
- Disable vectorization, as it was causing unaligned access bus error on
|
||||
certain 32bit architectures.
|
||||
|
||||
|
||||
Overview of changes leading to 1.8.2
|
||||
Tuesday, July 3, 2018
|
||||
====================================
|
||||
- Fix infinite loop in Khmer shaper.
|
||||
- Improve hb_blob_create_from_file() for streams.
|
||||
|
||||
|
||||
Overview of changes leading to 1.8.1
|
||||
Tuesday, June 12, 2018
|
||||
====================================
|
||||
@@ -5,6 +27,7 @@ Tuesday, June 12, 2018
|
||||
- Add correctness bug in hb_set_t operations, introduced in 1.7.7.
|
||||
- Remove HB_SUBSET_BUILTIN build option. Not necessary.
|
||||
|
||||
|
||||
Overview of changes leading to 1.8.0
|
||||
Tuesday, June 5, 2018
|
||||
====================================
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ HarfBuzz release walk-through checklist:
|
||||
7. "make release-files". Enter your GPG password. This creates a sha256 hash
|
||||
and signs it.
|
||||
|
||||
8. Now that you have release files built, commit NEWS and configure.ac changes,
|
||||
8. Now that you have release files, commit NEWS, configure.ac, and src/hb-version.h,
|
||||
as well as any REPLACEME changes you made. The commit message is simply the
|
||||
release number. Eg. "1.4.7"
|
||||
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ environment:
|
||||
MSYS2_ARCH: i686
|
||||
|
||||
install:
|
||||
- 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman -Syu --noconfirm"'
|
||||
- C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-ragel"
|
||||
|
||||
build_script:
|
||||
@@ -43,7 +44,7 @@ build_script:
|
||||
- 'if "%compiler%"=="msvc" msbuild harfbuzz.sln /p:Configuration=%configuration% /p:Platform=%platform%'
|
||||
- 'if "%compiler%"=="msvc" if not "%platform%"=="ARM" ctest --output-on-failure -C %configuration%'
|
||||
|
||||
- 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-$MSYS2_ARCH-{freetype,cairo,icu,gettext,gobject-introspection,gcc,gcc-libs,glib2,graphite2,pkg-config,python2}"'
|
||||
- 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-{freetype,cairo,icu,gettext,gobject-introspection,gcc,gcc-libs,glib2,graphite2,pkg-config,python2}"'
|
||||
- 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "curl https://raw.githubusercontent.com/mirror/mingw-w64/023eb04c396d4e8d8fcf604cfababc53dae13398/mingw-w64-headers/include/dwrite_1.h > %MINGW_PREFIX%/%MINGW_CHOST%/include/dwrite_1.h"'
|
||||
- 'if "%compiler%"=="msys2" C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER; PATH=$PATH:/mingw64/bin:/mingw32/bin; ./autogen.sh --with-uniscribe --with-freetype --with-glib --with-gobject --with-cairo --with-icu --with-graphite2 --with-directwrite --build=%MINGW_CHOST% --host=%MINGW_CHOST% --prefix=%MINGW_PREFIX%; make; make check || .ci/fail.sh"'
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
AC_PREREQ([2.64])
|
||||
AC_INIT([HarfBuzz],
|
||||
[1.8.1],
|
||||
[1.8.4],
|
||||
[https://github.com/harfbuzz/harfbuzz/issues/new],
|
||||
[harfbuzz],
|
||||
[http://harfbuzz.org/])
|
||||
@@ -78,7 +78,7 @@ GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
|
||||
])
|
||||
|
||||
# Functions and headers
|
||||
AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l)
|
||||
AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty newlocale strtod_l posix_memalign)
|
||||
|
||||
save_libs="$LIBS"
|
||||
LIBS="$LIBS -lm"
|
||||
|
||||
@@ -450,6 +450,7 @@ hb_ot_layout_collect_lookups
|
||||
hb_ot_layout_feature_get_lookups
|
||||
hb_ot_layout_feature_with_variations_get_lookups
|
||||
hb_ot_layout_get_attach_points
|
||||
hb_ot_layout_get_feature_name_ids
|
||||
hb_ot_layout_get_glyph_class
|
||||
hb_ot_layout_get_glyphs_in_class
|
||||
hb_ot_layout_get_ligature_carets
|
||||
|
||||
+5
-8
@@ -14,6 +14,7 @@ check_PROGRAMS =
|
||||
|
||||
# Convenience targets:
|
||||
lib: $(BUILT_SOURCES) libharfbuzz.la libharfbuzz-subset.la
|
||||
libs: $(BUILT_SOURCES) $(lib_LTLIBRARIES)
|
||||
fuzzing: $(BUILT_SOURCES) libharfbuzz-fuzzing.la libharfbuzz-subset-fuzzing.la
|
||||
|
||||
lib_LTLIBRARIES = libharfbuzz.la
|
||||
@@ -277,13 +278,13 @@ endif
|
||||
check: $(DEF_FILES) # For check-symbols.sh
|
||||
CLEANFILES += $(DEF_FILES)
|
||||
harfbuzz.def: $(HBHEADERS) $(HBNODISTHEADERS)
|
||||
$(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@"
|
||||
$(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^
|
||||
harfbuzz-subset.def: $(HB_SUBSET_headers)
|
||||
$(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@"
|
||||
$(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^
|
||||
harfbuzz-icu.def: $(HB_ICU_headers)
|
||||
$(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@"
|
||||
$(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^
|
||||
harfbuzz-gobject.def: $(HB_GOBJECT_headers)
|
||||
$(AM_V_GEN) headers="$^" $(srcdir)/gen-def.py "$@"
|
||||
$(AM_V_GEN) $(srcdir)/gen-def.py "$@" $^
|
||||
|
||||
|
||||
GENERATORS = \
|
||||
@@ -373,15 +374,11 @@ dist_check_SCRIPTS += \
|
||||
endif
|
||||
|
||||
check_PROGRAMS += \
|
||||
dump-fon \
|
||||
dump-indic-data \
|
||||
dump-khmer-data \
|
||||
dump-myanmar-data \
|
||||
dump-use-data \
|
||||
$(NULL)
|
||||
dump_fon_SOURCES = dump-fon.cc
|
||||
dump_fon_CPPFLAGS = $(HBCFLAGS)
|
||||
dump_fon_LDADD = libharfbuzz.la $(HBLIBS)
|
||||
dump_indic_data_SOURCES = dump-indic-data.cc hb-ot-shape-complex-indic-table.cc
|
||||
dump_indic_data_CPPFLAGS = $(HBCFLAGS)
|
||||
dump_indic_data_LDADD = libharfbuzz.la $(HBLIBS)
|
||||
|
||||
@@ -14,8 +14,10 @@ HB_BASE_sources = \
|
||||
hb-face.cc \
|
||||
hb-font-private.hh \
|
||||
hb-font.cc \
|
||||
hb-iter-private.hh \
|
||||
hb-map-private.hh \
|
||||
hb-map.cc \
|
||||
hb-machinery-private.hh \
|
||||
hb-mutex-private.hh \
|
||||
hb-object-private.hh \
|
||||
hb-open-file-private.hh \
|
||||
@@ -94,8 +96,6 @@ HB_OT_sources = \
|
||||
hb-aat-layout-morx-table.hh \
|
||||
hb-aat-layout-trak-table.hh \
|
||||
hb-aat-layout-private.hh \
|
||||
hb-aat-fmtx-table.hh \
|
||||
hb-aat-gcid-table.hh \
|
||||
hb-aat-ltag-table.hh \
|
||||
hb-ot-font.cc \
|
||||
hb-ot-layout.cc \
|
||||
|
||||
+2
-4
@@ -233,12 +233,10 @@ int main (int argc, char **argv)
|
||||
svg.dump (svg_callback);
|
||||
svg.fini ();
|
||||
|
||||
OT::Sanitizer<OT::COLR> sanitizerCOLR;
|
||||
hb_blob_t* colr_blob = sanitizerCOLR.sanitize (face->reference_table (HB_OT_TAG_COLR));
|
||||
hb_blob_t* colr_blob = OT::hb_sanitize_context_t().reference_table<OT::COLR> (face);
|
||||
const OT::COLR *colr = colr_blob->as<OT::COLR> ();
|
||||
|
||||
OT::Sanitizer<OT::CPAL> sanitizerCPAL;
|
||||
hb_blob_t* cpal_blob = sanitizerCPAL.sanitize (face->reference_table (HB_OT_TAG_CPAL));
|
||||
hb_blob_t* cpal_blob = OT::hb_sanitize_context_t().reference_table<OT::CPAL> (face);
|
||||
const OT::CPAL *cpal = cpal_blob->as<OT::CPAL> ();
|
||||
|
||||
cairo_font_face_t *cairo_face;
|
||||
|
||||
-555
@@ -1,555 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2018 Ebrahim Byagowi
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "hb-static.cc"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hb-open-type-private.hh"
|
||||
|
||||
template <typename Type, int Bytes> struct LEInt;
|
||||
|
||||
template <typename Type>
|
||||
struct LEInt<Type, 1>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v = V;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
private: uint8_t v;
|
||||
};
|
||||
template <typename Type>
|
||||
struct LEInt<Type, 2>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[1] = (V >> 8) & 0xFF;
|
||||
v[0] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[1] << 8)
|
||||
+ (v[0] );
|
||||
}
|
||||
private: uint8_t v[2];
|
||||
};
|
||||
template <typename Type>
|
||||
struct LEInt<Type, 3>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[2] = (V >> 16) & 0xFF;
|
||||
v[1] = (V >> 8) & 0xFF;
|
||||
v[0] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[2] << 16)
|
||||
+ (v[1] << 8)
|
||||
+ (v[0] );
|
||||
}
|
||||
private: uint8_t v[3];
|
||||
};
|
||||
template <typename Type>
|
||||
struct LEInt<Type, 4>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[3] = (V >> 24) & 0xFF;
|
||||
v[2] = (V >> 16) & 0xFF;
|
||||
v[1] = (V >> 8) & 0xFF;
|
||||
v[0] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[3] << 24)
|
||||
+ (v[2] << 16)
|
||||
+ (v[1] << 8)
|
||||
+ (v[0] );
|
||||
}
|
||||
private: uint8_t v[4];
|
||||
};
|
||||
|
||||
template <typename Type, unsigned int Size>
|
||||
struct LEIntType
|
||||
{
|
||||
inline void set (Type i) { v.set (i); }
|
||||
inline operator Type(void) const { return v; }
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this)));
|
||||
}
|
||||
protected:
|
||||
LEInt<Type, Size> v;
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (Size);
|
||||
};
|
||||
|
||||
typedef LEIntType<uint8_t, 1> LEUINT8; /* 8-bit unsigned integer. */
|
||||
typedef LEIntType<int8_t, 1> LEINT8; /* 8-bit signed integer. */
|
||||
typedef LEIntType<uint16_t, 2> LEUINT16; /* 16-bit unsigned integer. */
|
||||
typedef LEIntType<int16_t, 2> LEINT16; /* 16-bit signed integer. */
|
||||
typedef LEIntType<uint32_t, 4> LEUINT32; /* 32-bit unsigned integer. */
|
||||
typedef LEIntType<int32_t, 4> LEINT32; /* 32-bit signed integer. */
|
||||
typedef LEIntType<uint32_t, 3> LEUINT24; /* 24-bit unsigned integer. */
|
||||
|
||||
|
||||
struct LE_FONTINFO16
|
||||
{
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c, unsigned int length) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this) && c->check_range (this, length)));
|
||||
}
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/cc194829.aspx
|
||||
enum charset_t
|
||||
{
|
||||
// dfCharSet possible values and the codepage they are indicating to
|
||||
ANSI = 0x00, // 1252
|
||||
DEFAULT = 0x01, //
|
||||
SYMBOL = 0x02, //
|
||||
SHIFTJIS = 0x80, // 932
|
||||
HANGUL = 0x81, // 949
|
||||
GB2312 = 0x86, // 936
|
||||
CHINESEBIG5 = 0x88, // 950
|
||||
GREEK = 0xA1, // 1253
|
||||
TURKISH = 0xA2, // 1254
|
||||
HEBREW = 0xB1, // 1255
|
||||
ARABIC = 0xB2, // 1256
|
||||
BALTIC = 0xBA, // 1257
|
||||
RUSSIAN = 0xCC, // 1251
|
||||
THAI = 0xDE, // 874
|
||||
EE = 0xEE, // 1250
|
||||
OEM = 0xFF //
|
||||
};
|
||||
|
||||
inline const char* get_charset() const
|
||||
{
|
||||
switch (dfCharSet) {
|
||||
case ANSI: return "ISO8859";
|
||||
case DEFAULT: return "WinDefault";
|
||||
case SYMBOL: return "Symbol";
|
||||
case SHIFTJIS: return "JISX0208.1983";
|
||||
case HANGUL: return "MSHangul";
|
||||
case GB2312: return "GB2312.1980";
|
||||
case CHINESEBIG5: return "Big5";
|
||||
case GREEK: return "CP1253";
|
||||
case TURKISH: return "CP1254";
|
||||
case HEBREW: return "CP1255";
|
||||
case ARABIC: return "CP1256";
|
||||
case BALTIC: return "CP1257";
|
||||
case RUSSIAN: return "CP1251";
|
||||
case THAI: return "CP874";
|
||||
case EE: return "CP1250";
|
||||
case OEM: return "OEM";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int get_version () const
|
||||
{
|
||||
return dfVersion;
|
||||
}
|
||||
|
||||
inline unsigned int get_weight () const
|
||||
{
|
||||
return dfWeight;
|
||||
}
|
||||
|
||||
enum weight_t {
|
||||
DONTCARE = 0,
|
||||
THIN = 100,
|
||||
EXTRALIGHT = 200,
|
||||
ULTRALIGHT = 200,
|
||||
LIGHT = 300,
|
||||
NORMAL = 400,
|
||||
REGULAR = 400,
|
||||
MEDIUM = 500,
|
||||
SEMIBOLD = 600,
|
||||
DEMIBOLD = 600,
|
||||
BOLD = 700,
|
||||
EXTRABOLD = 800,
|
||||
ULTRABOLD = 800,
|
||||
HEAVY = 900,
|
||||
BLACK = 900
|
||||
};
|
||||
|
||||
inline void dump () const
|
||||
{
|
||||
// With https://github.com/juanitogan/mkwinfont/blob/master/python/dewinfont.py help
|
||||
// Should be implemented differently eventually, but for now
|
||||
unsigned int ctstart;
|
||||
unsigned int ctsize;
|
||||
if (dfVersion == 0x200)
|
||||
{
|
||||
ctstart = 0x76;
|
||||
ctsize = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
return; // must of ".fon"s are version 2 and even dewinfont V1 implmentation doesn't seem correct
|
||||
ctstart = 0x94;
|
||||
ctsize = 6;
|
||||
}
|
||||
// unsigned int maxwidth = 0;
|
||||
for (unsigned int i = dfFirstChar; i < dfLastChar; ++i)
|
||||
{
|
||||
unsigned int entry = ctstart + ctsize * (i-dfFirstChar);
|
||||
unsigned int w = (uint16_t) OT::StructAtOffset<LEUINT16> (this, entry);
|
||||
|
||||
unsigned int off;
|
||||
if (ctsize == 4)
|
||||
off = (uint16_t) OT::StructAtOffset<LEUINT16> (this, entry+2);
|
||||
else
|
||||
off = (uint32_t) OT::StructAtOffset<LEUINT32> (this, entry+2);
|
||||
|
||||
unsigned int widthbytes = (w + 7) / 8;
|
||||
for (unsigned int j = 0; j < dfPixHeight; ++j)
|
||||
{
|
||||
for (unsigned int k = 0; k < widthbytes; ++k)
|
||||
{
|
||||
unsigned int bytepos = off + k * dfPixHeight + j;
|
||||
const uint8_t b = (uint8_t) OT::StructAtOffset<LEINT8> (this, bytepos);
|
||||
for (unsigned int a = 128; a > 0; a >>= 1)
|
||||
printf (b & a ? "x" : ".");
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
printf ("\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
LEUINT16 dfVersion;
|
||||
LEUINT32 dfSize;
|
||||
LEUINT8 dfCopyright[60];
|
||||
LEUINT16 dfType;
|
||||
LEUINT16 dfPoints;
|
||||
LEUINT16 dfVertRes;
|
||||
LEUINT16 dfHorizRes;
|
||||
LEUINT16 dfAscent;
|
||||
LEUINT16 dfInternalLeading;
|
||||
LEUINT16 dfExternalLeading;
|
||||
LEUINT8 dfItalic;
|
||||
LEUINT8 dfUnderline;
|
||||
LEUINT8 dfStrikeOut;
|
||||
LEUINT16 dfWeight; // see weight_t
|
||||
LEUINT8 dfCharSet; // see charset_t
|
||||
LEUINT16 dfPixWidth;
|
||||
LEUINT16 dfPixHeight;
|
||||
LEUINT8 dfPitchAndFamily;
|
||||
LEUINT16 dfAvgWidth;
|
||||
LEUINT16 dfMaxWidth;
|
||||
LEUINT8 dfFirstChar;
|
||||
LEUINT8 dfLastChar;
|
||||
LEUINT8 dfDefaultChar;
|
||||
LEUINT8 dfBreakChar;
|
||||
LEUINT16 dfWidthBytes;
|
||||
LEUINT32 dfDevice;
|
||||
LEUINT32 dfFace;
|
||||
LEUINT32 dfBitsPointer;
|
||||
LEUINT32 dfBitsOffset;
|
||||
LEUINT8 dfReserved;
|
||||
// LEUINT32 dfFlags;
|
||||
// LEUINT16 dfAspace;
|
||||
// LEUINT16 dfBspace;
|
||||
// LEUINT16 dfCspace;
|
||||
// LEUINT32 dfColorPointer;
|
||||
// LEUINT32 dfReserved1[4];
|
||||
OT::UnsizedArrayOf<LEUINT8>
|
||||
dataZ;
|
||||
public:
|
||||
DEFINE_SIZE_ARRAY (118, dataZ);
|
||||
};
|
||||
|
||||
struct NE_NAMEINFO
|
||||
{
|
||||
friend struct NE_TYPEINFO;
|
||||
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base, unsigned int shift) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this) &&
|
||||
get_font (base, shift).sanitize (c, length << shift)));
|
||||
}
|
||||
|
||||
inline const LE_FONTINFO16& get_font (const void *base, int shift) const
|
||||
{
|
||||
return OT::StructAtOffset<LE_FONTINFO16> (base, offset << shift);
|
||||
}
|
||||
|
||||
enum resource_type_flag_t {
|
||||
NONE = 0x0000,
|
||||
MOVEABLE = 0x0010,
|
||||
PURE = 0x0020,
|
||||
PRELOAD = 0x0040
|
||||
};
|
||||
|
||||
protected:
|
||||
LEUINT16 offset; // Should be shifted with alignmentShiftCount before use
|
||||
LEUINT16 length; // Should be shifted with alignmentShiftCount before use
|
||||
LEUINT16 flags; // resource_type_flag_t
|
||||
LEUINT16 id;
|
||||
LEUINT16 handle;
|
||||
LEUINT16 usage;
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (12);
|
||||
};
|
||||
|
||||
struct NE_TYPEINFO
|
||||
{
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base, unsigned int shift) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (c->check_struct (this) && resources.sanitize (c, count, base, shift));
|
||||
}
|
||||
|
||||
inline unsigned int get_size (void) const
|
||||
{ return 8 + count * NE_NAMEINFO::static_size; }
|
||||
|
||||
inline const NE_TYPEINFO& next () const
|
||||
{
|
||||
const NE_TYPEINFO& next = OT::StructAfter<NE_TYPEINFO> (*this);
|
||||
if (type_id == 0)
|
||||
return Null(NE_TYPEINFO);
|
||||
return next;
|
||||
}
|
||||
|
||||
inline const LE_FONTINFO16& get_font (unsigned int idx, const void *base, int shift) const
|
||||
{
|
||||
if (idx < count)
|
||||
return resources[idx].get_font (base, shift);
|
||||
return Null(LE_FONTINFO16);
|
||||
}
|
||||
|
||||
inline unsigned int get_count () const
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
inline unsigned int get_type_id () const
|
||||
{
|
||||
return type_id;
|
||||
}
|
||||
|
||||
enum type_id_t {
|
||||
CURSOR = 0x8001,
|
||||
BITMAP = 0x8002,
|
||||
ICON = 0x8003,
|
||||
MENU = 0x8004,
|
||||
DIALOG = 0x8005,
|
||||
STRING = 0x8006,
|
||||
FONT_DIRECTORY = 0x8007,
|
||||
FONT = 0x8008,
|
||||
ACCELERATOR_TABLE = 0x8009,
|
||||
RESOURCE_DATA = 0x800a,
|
||||
GROUP_CURSOR = 0x800c,
|
||||
GROUP_ICON = 0x800e,
|
||||
VERSION = 0x8010
|
||||
};
|
||||
|
||||
protected:
|
||||
LEUINT16 type_id; // see type_id_t
|
||||
LEUINT16 count;
|
||||
LEUINT32 resloader;
|
||||
OT::UnsizedArrayOf<NE_NAMEINFO>
|
||||
resources;
|
||||
public:
|
||||
DEFINE_SIZE_ARRAY (8, resources);
|
||||
};
|
||||
|
||||
struct NE_RESOURCE_TABLE
|
||||
{
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
|
||||
if (!c->check_struct (this))
|
||||
return_trace (false);
|
||||
|
||||
const NE_TYPEINFO* n = &chain;
|
||||
while (n != &Null(NE_TYPEINFO) && c->check_struct (n) && n->get_type_id () != 0)
|
||||
{
|
||||
if (n->get_type_id () == NE_TYPEINFO::FONT)
|
||||
return_trace (n->sanitize (c, base, alignmentShiftCount));
|
||||
n = &n->next();
|
||||
}
|
||||
return_trace (false);
|
||||
}
|
||||
|
||||
inline unsigned int get_shift_value () const
|
||||
{
|
||||
return alignmentShiftCount;
|
||||
}
|
||||
|
||||
inline const NE_TYPEINFO& get_fonts_entry () const
|
||||
{
|
||||
const NE_TYPEINFO* n = &chain;
|
||||
while (n != &Null(NE_TYPEINFO) && n->get_type_id () != 0)
|
||||
{
|
||||
if (n->get_type_id () == NE_TYPEINFO::FONT)
|
||||
return *n;
|
||||
n = &n->next();
|
||||
}
|
||||
return Null(NE_TYPEINFO);
|
||||
}
|
||||
|
||||
protected:
|
||||
LEUINT16 alignmentShiftCount;
|
||||
NE_TYPEINFO chain;
|
||||
// It is followed by an array of OT::ArrayOf<LEUINT8, LEUINT8> chars;
|
||||
public:
|
||||
DEFINE_SIZE_MIN (2);
|
||||
};
|
||||
|
||||
// https://github.com/wine-mirror/wine/blob/master/include/winnt.h#L2467
|
||||
struct LE_IMAGE_OS2_HEADER
|
||||
{
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c, const void *base) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this) && (this+rsrctab).sanitize (c, base)));
|
||||
}
|
||||
|
||||
inline const NE_RESOURCE_TABLE& get_resource_table () const
|
||||
{
|
||||
if (magic != 0x454E) // Only NE containers are support for now, NE == 0x454E
|
||||
return Null(NE_RESOURCE_TABLE);
|
||||
return this+rsrctab;
|
||||
}
|
||||
|
||||
protected:
|
||||
LEUINT16 magic; /* 00 NE signature 'NE' */
|
||||
LEUINT8 ver; /* 02 Linker version number */
|
||||
LEUINT8 rev; /* 03 Linker revision number */
|
||||
LEUINT16 enttab; /* 04 Offset to entry table relative to NE */
|
||||
LEUINT16 cbenttab; /* 06 Length of entry table in bytes */
|
||||
LEUINT32 crc; /* 08 Checksum */
|
||||
LEUINT16 flags; /* 0c Flags about segments in this file */
|
||||
LEUINT16 autodata; /* 0e Automatic data segment number */
|
||||
LEUINT16 heap; /* 10 Initial size of local heap */
|
||||
LEUINT16 stack; /* 12 Initial size of stack */
|
||||
LEUINT32 csip; /* 14 Initial CS:IP */
|
||||
LEUINT32 sssp; /* 18 Initial SS:SP */
|
||||
LEUINT16 cseg; /* 1c # of entries in segment table */
|
||||
LEUINT16 cmod; /* 1e # of entries in module reference tab. */
|
||||
LEUINT16 cbnrestab; /* 20 Length of nonresident-name table */
|
||||
LEUINT16 segtab; /* 22 Offset to segment table */
|
||||
OT::OffsetTo<NE_RESOURCE_TABLE, LEUINT16>
|
||||
rsrctab; /* 24 Offset to resource table */
|
||||
LEUINT16 restab; /* 26 Offset to resident-name table */
|
||||
LEUINT16 modtab; /* 28 Offset to module reference table */
|
||||
LEUINT16 imptab; /* 2a Offset to imported name table */
|
||||
LEUINT32 nrestab; /* 2c Offset to nonresident-name table */
|
||||
LEUINT16 cmovent; /* 30 # of movable entry points */
|
||||
LEUINT16 align; /* 32 Logical sector alignment shift count */
|
||||
LEUINT16 cres; /* 34 # of resource segments */
|
||||
LEUINT8 exetyp; /* 36 Flags indicating target OS */
|
||||
LEUINT8 flagsothers; /* 37 Additional information flags */
|
||||
LEUINT16 pretthunks; /* 38 Offset to return thunks */
|
||||
LEUINT16 psegrefbytes; /* 3a Offset to segment ref. bytes */
|
||||
LEUINT16 swaparea; /* 3c Reserved by Microsoft */
|
||||
LEUINT16 expver; /* 3e Expected Windows version number */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (64);
|
||||
};
|
||||
|
||||
struct LE_IMAGE_DOS_HEADER {
|
||||
inline bool sanitize (OT::hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this) &&
|
||||
get_os2_header ().sanitize (c, this)));
|
||||
}
|
||||
|
||||
inline const LE_IMAGE_OS2_HEADER& get_os2_header () const
|
||||
{
|
||||
return this+e_lfanew;
|
||||
}
|
||||
|
||||
protected:
|
||||
LEUINT16 e_magic; // Magic number
|
||||
LEUINT16 e_cblp; // Bytes on last page of file
|
||||
LEUINT16 e_cp; // Pages in file
|
||||
LEUINT16 e_crlc; // Relocations
|
||||
LEUINT16 e_cparhdr; // Size of header in paragraphs
|
||||
LEUINT16 e_minalloc; // Minimum extra paragraphs needed
|
||||
LEUINT16 e_maxalloc; // Maximum extra paragraphs needed
|
||||
LEUINT16 e_ss; // Initial (relative) SS value
|
||||
LEUINT16 e_sp; // Initial SP value
|
||||
LEUINT16 e_csum; // Checksum
|
||||
LEUINT16 e_ip; // Initial IP value
|
||||
LEUINT16 e_cs; // Initial (relative) CS value
|
||||
LEUINT16 e_lfarlc; // File address of relocation table
|
||||
LEUINT16 e_ovno; // Overlay number
|
||||
LEUINT16 e_res_0; // Reserved words
|
||||
LEUINT16 e_res_1; // Reserved words
|
||||
LEUINT16 e_res_2; // Reserved words
|
||||
LEUINT16 e_res_3; // Reserved words
|
||||
LEUINT16 e_oemid; // OEM identifier (for e_oeminfo)
|
||||
LEUINT16 e_oeminfo; // OEM information; e_oemid specific
|
||||
LEUINT16 e_res2_0; // Reserved words
|
||||
LEUINT16 e_res2_1; // Reserved words
|
||||
LEUINT16 e_res2_2; // Reserved words
|
||||
LEUINT16 e_res2_3; // Reserved words
|
||||
LEUINT16 e_res2_4; // Reserved words
|
||||
LEUINT16 e_res2_5; // Reserved words
|
||||
LEUINT16 e_res2_6; // Reserved words
|
||||
LEUINT16 e_res2_7; // Reserved words
|
||||
LEUINT16 e_res2_8; // Reserved words
|
||||
LEUINT16 e_res2_9; // Reserved words
|
||||
OT::OffsetTo<LE_IMAGE_OS2_HEADER, LEUINT32>
|
||||
e_lfanew; // File address of new exe header
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (64);
|
||||
};
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
|
||||
|
||||
OT::Sanitizer<LE_IMAGE_DOS_HEADER> sanitizer;
|
||||
hb_blob_t *font_blob = sanitizer.sanitize (blob);
|
||||
const LE_IMAGE_DOS_HEADER* dos_header = font_blob->as<LE_IMAGE_DOS_HEADER> ();
|
||||
|
||||
const NE_RESOURCE_TABLE &rtable = dos_header->get_os2_header ().get_resource_table ();
|
||||
int shift = rtable.get_shift_value ();
|
||||
const NE_TYPEINFO& entry = rtable.get_fonts_entry ();
|
||||
for (unsigned int i = 0; i < entry.get_count (); ++i)
|
||||
{
|
||||
const LE_FONTINFO16& font = entry.get_font (i, dos_header, shift);
|
||||
printf ("version: %x, weight: %d, charset: %s\n", font.get_version (),
|
||||
font.get_weight (), font.get_charset ());
|
||||
// font.dump ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+9
-3
@@ -4,8 +4,14 @@ from __future__ import print_function, division, absolute_import
|
||||
|
||||
import io, os, re, sys
|
||||
|
||||
if len (sys.argv) < 3:
|
||||
sys.exit("usage: gen-def.py harfbuzz.def hb.h [hb-blob.h hb-buffer.h ...]")
|
||||
|
||||
output_file = sys.argv[1]
|
||||
header_paths = sys.argv[2:]
|
||||
|
||||
headers_content = []
|
||||
for h in os.environ["headers"].split (' '):
|
||||
for h in header_paths:
|
||||
if h.endswith (".h"):
|
||||
with io.open (h, encoding='utf-8') as f: headers_content.append (f.read ())
|
||||
|
||||
@@ -13,7 +19,7 @@ result = """EXPORTS
|
||||
%s
|
||||
LIBRARY lib%s-0.dll""" % (
|
||||
"\n".join (sorted (re.findall (r"^hb_\w+(?= \()", "\n".join (headers_content), re.M))),
|
||||
sys.argv[1].replace ('.def', '')
|
||||
output_file.replace ('.def', '')
|
||||
)
|
||||
|
||||
with open (sys.argv[1], "w") as f: f.write (result)
|
||||
with open (output_file, "w") as f: f.write (result)
|
||||
+17
-1
@@ -47,6 +47,9 @@ defaults = ('Other', 'Not_Applicable', 'Cn', 'No_Block')
|
||||
data[0][0x034F] = defaults[0]
|
||||
data[0][0x2060] = defaults[0]
|
||||
data[0][0x20F0] = defaults[0]
|
||||
# TODO https://github.com/roozbehp/unicode-data/issues/9
|
||||
data[0][0x11C44] = 'Consonant_Placeholder'
|
||||
data[0][0x11C45] = 'Consonant_Placeholder'
|
||||
for u in range (0xFE00, 0xFE0F + 1):
|
||||
data[0][u] = defaults[0]
|
||||
|
||||
@@ -165,7 +168,7 @@ def is_BASE(U, UISC, UGC):
|
||||
def is_BASE_IND(U, UISC, UGC):
|
||||
#SPEC-DRAFT return (UISC in [Consonant_Dead, Modifying_Letter] or UGC == Po)
|
||||
return (UISC in [Consonant_Dead, Modifying_Letter] or
|
||||
(UGC == Po and not U in [0x104B, 0x104E, 0x2022, 0x11A3F, 0x11A45]) or
|
||||
(UGC == Po and not U in [0x104B, 0x104E, 0x2022, 0x11A3F, 0x11A45, 0x11C44, 0x11C45]) or
|
||||
False # SPEC-DRAFT-OUTDATED! U == 0x002D
|
||||
)
|
||||
def is_BASE_NUM(U, UISC, UGC):
|
||||
@@ -325,6 +328,9 @@ def map_to_use(data):
|
||||
# TODO: https://github.com/harfbuzz/harfbuzz/pull/626
|
||||
if U == 0xA8B4: UISC = Consonant_Medial
|
||||
|
||||
# TODO: https://github.com/harfbuzz/harfbuzz/issues/1105
|
||||
if U == 0x11134: UISC = Gemination_Mark
|
||||
|
||||
values = [k for k,v in items if v(U,UISC,UGC)]
|
||||
assert len(values) == 1, "%s %s %s %s" % (hex(U), UISC, UGC, values)
|
||||
USE = values[0]
|
||||
@@ -344,12 +350,22 @@ def map_to_use(data):
|
||||
if 0xA926 <= U <= 0xA92A: UIPC = Top
|
||||
if U == 0x111CA: UIPC = Bottom
|
||||
if U == 0x11300: UIPC = Top
|
||||
# TODO: https://github.com/harfbuzz/harfbuzz/pull/1037
|
||||
if U == 0x11302: UIPC = Top
|
||||
if U == 0x1133C: UIPC = Bottom
|
||||
if U == 0x1171E: UIPC = Left # Correct?!
|
||||
if 0x1CF2 <= U <= 0x1CF3: UIPC = Right
|
||||
if 0x1CF8 <= U <= 0x1CF9: UIPC = Top
|
||||
# https://github.com/roozbehp/unicode-data/issues/8
|
||||
if U == 0x0A51: UIPC = Bottom
|
||||
|
||||
# TODO: https://github.com/harfbuzz/harfbuzz/pull/982
|
||||
if UBlock == 'Chakma' and is_VOWEL (U, UISC, UGC):
|
||||
if UIPC == Top:
|
||||
UIPC = Bottom
|
||||
elif UIPC == Bottom:
|
||||
UIPC = Top
|
||||
|
||||
assert (UIPC in [Not_Applicable, Visual_Order_Left] or
|
||||
USE in use_positions), "%s %s %s %s %s" % (hex(U), UIPC, USE, UISC, UGC)
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2018 Ebrahim Byagowi
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#ifndef HB_AAT_FMTX_TABLE_HH
|
||||
#define HB_AAT_FMTX_TABLE_HH
|
||||
|
||||
#include "hb-aat-layout-common-private.hh"
|
||||
|
||||
/*
|
||||
* fmtx -- Font Metrics
|
||||
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6fmtx.html
|
||||
*/
|
||||
#define HB_AAT_TAG_fmtx HB_TAG('f','m','t','x')
|
||||
|
||||
|
||||
namespace AAT {
|
||||
|
||||
|
||||
struct fmtx
|
||||
{
|
||||
static const hb_tag_t tableTag = HB_AAT_TAG_fmtx;
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this)));
|
||||
}
|
||||
|
||||
FixedVersion<>version; /* Version (set to 0x00020000). */
|
||||
HBUINT32 glyphIndex; /* The glyph whose points represent the metrics. */
|
||||
HBUINT8 horizontalBefore; /* Point number for the horizontal ascent. */
|
||||
HBUINT8 horizontalAfter; /* Point number for the horizontal descent. */
|
||||
HBUINT8 horizontalCaretHead; /* Point number for the horizontal caret head. */
|
||||
HBUINT8 horizontalCaretBase; /* Point number for the horizontal caret base. */
|
||||
HBUINT8 verticalBefore; /* Point number for the vertical ascent. */
|
||||
HBUINT8 verticalAfter; /* Point number for the vertical descent. */
|
||||
HBUINT8 verticalCaretHead; /* Point number for the vertical caret head. */
|
||||
HBUINT8 verticalCaretBase; /* Point number for the vertical caret base. */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (16);
|
||||
};
|
||||
|
||||
} /* namespace AAT */
|
||||
|
||||
|
||||
#endif /* HB_AAT_FMTX_TABLE_HH */
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2018 Ebrahim Byagowi
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*/
|
||||
|
||||
#ifndef HB_AAT_GCID_TABLE_HH
|
||||
#define HB_AAT_GCID_TABLE_HH
|
||||
|
||||
#include "hb-aat-layout-common-private.hh"
|
||||
|
||||
/*
|
||||
* gcid -- Glyphs CIDs
|
||||
* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gcid.html
|
||||
*/
|
||||
#define HB_AAT_TAG_gcid HB_TAG('g','c','i','d')
|
||||
|
||||
|
||||
namespace AAT {
|
||||
|
||||
|
||||
struct gcid
|
||||
{
|
||||
static const hb_tag_t tableTag = HB_AAT_TAG_gcid;
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (likely (c->check_struct (this) && CIDs.sanitize (c)));
|
||||
}
|
||||
|
||||
protected:
|
||||
HBUINT16 version; /* Version number (set to 0) */
|
||||
HBUINT16 format; /* Data format (set to 0) */
|
||||
HBUINT32 size; /* Size of the table, including header */
|
||||
HBUINT16 registry; /* The registry ID */
|
||||
HBUINT8 registryName[64];
|
||||
/* The registry name in ASCII */
|
||||
HBUINT16 order; /* The order ID */
|
||||
HBUINT8 orderName[64]; /* The order name in ASCII */
|
||||
HBUINT16 supplementVersion;
|
||||
/* The supplement version */
|
||||
ArrayOf<HBUINT16>
|
||||
CIDs; /* The CIDs for the glyphs in the font,
|
||||
* starting with glyph 0. If a glyph does not correspond
|
||||
* to a CID in the identified collection, 0xFFFF is used.
|
||||
* This should not exceed the number of glyphs in the font. */
|
||||
public:
|
||||
DEFINE_SIZE_ARRAY (144, CIDs);
|
||||
};
|
||||
|
||||
} /* namespace AAT */
|
||||
|
||||
|
||||
#endif /* HB_AAT_GCID_TABLE_HH */
|
||||
@@ -161,7 +161,7 @@ struct LookupFormat0
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (arrayZ.sanitize (c, c->num_glyphs));
|
||||
return_trace (arrayZ.sanitize (c, c->get_num_glyphs ()));
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -625,7 +625,7 @@ struct hb_aat_apply_context_t :
|
||||
sanitizer (), lookup_index (0), debug_depth (0)
|
||||
{
|
||||
sanitizer.init (table);
|
||||
sanitizer.num_glyphs = face->get_num_glyphs ();
|
||||
sanitizer.set_num_glyphs (face->get_num_glyphs ());
|
||||
sanitizer.start_processing ();
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ struct trak
|
||||
hb_position_t advance_to_add = c->font->em_scalef_x (tracking / 2);
|
||||
foreach_grapheme (buffer, start, end)
|
||||
{
|
||||
/* TODO This is wrong. */
|
||||
buffer->pos[start].x_offset += advance_to_add;
|
||||
buffer->pos[start].x_advance += advance_to_add;
|
||||
buffer->pos[end].x_advance += advance_to_add;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ struct trak
|
||||
hb_position_t advance_to_add = c->font->em_scalef_y (tracking / 2);
|
||||
foreach_grapheme (buffer, start, end)
|
||||
{
|
||||
/* TODO This is wrong. */
|
||||
buffer->pos[start].y_offset += advance_to_add;
|
||||
buffer->pos[start].y_advance += advance_to_add;
|
||||
buffer->pos[end].y_advance += advance_to_add;
|
||||
}
|
||||
|
||||
+3
-61
@@ -36,48 +36,12 @@
|
||||
#include "hb-aat-layout-kerx-table.hh"
|
||||
#include "hb-aat-layout-morx-table.hh"
|
||||
#include "hb-aat-layout-trak-table.hh"
|
||||
#include "hb-aat-fmtx-table.hh" // Just so we compile it; unused otherwise.
|
||||
#include "hb-aat-gcid-table.hh" // Just so we compile it; unused otherwise.
|
||||
#include "hb-aat-ltag-table.hh" // Just so we compile it; unused otherwise.
|
||||
|
||||
/*
|
||||
* morx/kerx/trak
|
||||
* morx/kerx/trak/ankr
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static inline const AAT::ankr&
|
||||
_get_ankr (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
{
|
||||
if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
|
||||
{
|
||||
if (blob)
|
||||
*blob = hb_blob_get_empty ();
|
||||
return Null(AAT::ankr);
|
||||
}
|
||||
hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
|
||||
const AAT::ankr& ankr = *(layout->ankr.get ());
|
||||
if (blob)
|
||||
*blob = layout->ankr.blob;
|
||||
return ankr;
|
||||
}
|
||||
|
||||
static inline const AAT::kerx&
|
||||
_get_kerx (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
{
|
||||
if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
|
||||
{
|
||||
if (blob)
|
||||
*blob = hb_blob_get_empty ();
|
||||
return Null(AAT::kerx);
|
||||
}
|
||||
hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
|
||||
/* XXX this doesn't call set_num_glyphs on sanitizer. */
|
||||
const AAT::kerx& kerx = *(layout->kerx.get ());
|
||||
if (blob)
|
||||
*blob = layout->kerx.blob;
|
||||
return kerx;
|
||||
}
|
||||
|
||||
static inline const AAT::morx&
|
||||
_get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
{
|
||||
@@ -88,36 +52,16 @@ _get_morx (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
return Null(AAT::morx);
|
||||
}
|
||||
hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
|
||||
/* XXX this doesn't call set_num_glyphs on sanitizer. */
|
||||
const AAT::morx& morx = *(layout->morx.get ());
|
||||
if (blob)
|
||||
*blob = layout->morx.blob;
|
||||
*blob = layout->morx.get_blob ();
|
||||
return morx;
|
||||
}
|
||||
|
||||
static inline const AAT::trak&
|
||||
_get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
{
|
||||
if (unlikely (!hb_ot_shaper_face_data_ensure (face)))
|
||||
{
|
||||
if (blob)
|
||||
*blob = hb_blob_get_empty ();
|
||||
return Null(AAT::trak);
|
||||
}
|
||||
hb_ot_layout_t * layout = hb_ot_layout_from_face (face);
|
||||
const AAT::trak& trak = *(layout->trak.get ());
|
||||
if (blob)
|
||||
*blob = layout->trak.blob;
|
||||
return trak;
|
||||
}
|
||||
#endif
|
||||
|
||||
// static inline void
|
||||
// _hb_aat_layout_create (hb_face_t *face)
|
||||
// {
|
||||
// OT::Sanitizer<AAT::morx> sanitizer;
|
||||
// sanitizer.set_num_glyphs (face->get_num_glyphs ());
|
||||
// hb_blob_t *morx_blob = sanitizer.sanitize (face->reference_table (HB_AAT_TAG_morx));
|
||||
// hb_blob_t *morx_blob = OT::hb_sanitize_context_t().reference_table<AAT::morx> (face);
|
||||
// morx_blob->as<AAT::morx> ();
|
||||
|
||||
// if (0)
|
||||
@@ -129,13 +73,11 @@ _get_trak (hb_face_t *face, hb_blob_t **blob = nullptr)
|
||||
void
|
||||
hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer)
|
||||
{
|
||||
#if 0
|
||||
hb_blob_t *blob;
|
||||
const AAT::morx& morx = _get_morx (font->face, &blob);
|
||||
|
||||
AAT::hb_aat_apply_context_t c (font, buffer, blob);
|
||||
morx.apply (&c);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -46,6 +46,41 @@
|
||||
/* Defined externally, i.e. in config.h; must have typedef'ed hb_atomic_int_impl_t as well. */
|
||||
|
||||
|
||||
#elif !defined(HB_NO_MT) && defined(__ATOMIC_ACQUIRE)
|
||||
|
||||
/* C++11-style GCC primitives. */
|
||||
|
||||
typedef int hb_atomic_int_impl_t;
|
||||
#define hb_atomic_int_impl_add(AI, V) __atomic_fetch_add (&(AI), (V), __ATOMIC_ACQ_REL)
|
||||
|
||||
#define hb_atomic_ptr_impl_get(P) __atomic_load_n ((P), __ATOMIC_ACQUIRE)
|
||||
static inline bool
|
||||
_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N)
|
||||
{
|
||||
const void *O = O_; // Need lvalue
|
||||
return __atomic_compare_exchange_n ((void **) P, (void **) &O, (void *) N, true, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
|
||||
}
|
||||
#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N)))
|
||||
|
||||
#elif !defined(HB_NO_MT) && __cplusplus >= 201103L
|
||||
|
||||
/* C++11 atomics. */
|
||||
|
||||
#include <atomic>
|
||||
|
||||
typedef int hb_atomic_int_impl_t;
|
||||
#define hb_atomic_int_impl_add(AI, V) (reinterpret_cast<std::atomic<int> *> (&AI)->fetch_add ((V), std::memory_order_acq_rel))
|
||||
|
||||
#define hb_atomic_ptr_impl_get(P) (reinterpret_cast<std::atomic<void*> *> (P)->load (std::memory_order_acquire))
|
||||
static inline bool
|
||||
_hb_atomic_ptr_impl_cmplexch (const void **P, const void *O_, const void *N)
|
||||
{
|
||||
const void *O = O_; // Need lvalue
|
||||
return reinterpret_cast<std::atomic<const void*> *> (P)->compare_exchange_weak (O, N, std::memory_order_acq_rel, std::memory_order_relaxed);
|
||||
}
|
||||
#define hb_atomic_ptr_impl_cmpexch(P,O,N) (_hb_atomic_ptr_impl_cmplexch ((const void **) (P), (O), (N)))
|
||||
|
||||
|
||||
#elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__))
|
||||
|
||||
#include <windows.h>
|
||||
@@ -162,16 +197,18 @@ typedef int hb_atomic_int_impl_t;
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef HB_ATOMIC_INT_INIT
|
||||
#define HB_ATOMIC_INT_INIT(V) {V}
|
||||
#endif
|
||||
|
||||
struct hb_atomic_int_t
|
||||
{
|
||||
hb_atomic_int_impl_t v;
|
||||
mutable 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<hb_atomic_int_impl_t &> (v), 1); }
|
||||
inline int dec (void) { return hb_atomic_int_impl_add (const_cast<hb_atomic_int_impl_t &> (v), -1); }
|
||||
inline int inc (void) { return hb_atomic_int_impl_add (v, 1); }
|
||||
inline int dec (void) { return hb_atomic_int_impl_add (v, -1); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
|
||||
/*
|
||||
* hb_blob_t
|
||||
|
||||
+85
-52
@@ -31,7 +31,6 @@
|
||||
#endif
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-blob-private.hh"
|
||||
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
@@ -489,10 +488,10 @@ hb_blob_t::try_make_writable (void)
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef _O_BINARY
|
||||
# define _O_BINARY 0
|
||||
#else
|
||||
# ifndef _O_BINARY
|
||||
# define _O_BINARY 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef MAP_NORESERVE
|
||||
@@ -508,6 +507,7 @@ struct hb_mapped_file_t
|
||||
#endif
|
||||
};
|
||||
|
||||
#if (defined(HAVE_MMAP) || defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_MMAP)
|
||||
static void
|
||||
_hb_mapped_file_destroy (hb_mapped_file_t *file)
|
||||
{
|
||||
@@ -517,11 +517,12 @@ _hb_mapped_file_destroy (hb_mapped_file_t *file)
|
||||
UnmapViewOfFile (file->contents);
|
||||
CloseHandle (file->mapping);
|
||||
#else
|
||||
free (file->contents);
|
||||
assert (0); // If we don't have mmap we shouldn't reach here
|
||||
#endif
|
||||
|
||||
free (file);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* hb_blob_create_from_file:
|
||||
@@ -534,77 +535,109 @@ _hb_mapped_file_destroy (hb_mapped_file_t *file)
|
||||
hb_blob_t *
|
||||
hb_blob_create_from_file (const char *file_name)
|
||||
{
|
||||
// Adopted from glib's gmappedfile.c with Matthias Clasen and
|
||||
// Allison Lortie permission but changed a lot to suit our need.
|
||||
bool writable = false;
|
||||
hb_memory_mode_t mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE;
|
||||
/* Adopted from glib's gmappedfile.c with Matthias Clasen and
|
||||
Allison Lortie permission but changed a lot to suit our need. */
|
||||
#if defined(HAVE_MMAP) && !defined(HB_NO_MMAP)
|
||||
hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t));
|
||||
if (unlikely (!file)) return hb_blob_get_empty ();
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
int fd = open (file_name, (writable ? O_RDWR : O_RDONLY) | _O_BINARY, 0);
|
||||
# define CLOSE close
|
||||
int fd = open (file_name, O_RDONLY | _O_BINARY, 0);
|
||||
if (unlikely (fd == -1)) goto fail_without_close;
|
||||
|
||||
struct stat st;
|
||||
if (unlikely (fstat (fd, &st) == -1)) goto fail;
|
||||
|
||||
// See https://github.com/GNOME/glib/blob/f9faac7/glib/gmappedfile.c#L139-L142
|
||||
if (unlikely (st.st_size == 0 && S_ISREG (st.st_mode))) goto fail;
|
||||
|
||||
file->length = (unsigned long) st.st_size;
|
||||
file->contents = (char *) mmap (nullptr, file->length,
|
||||
writable ? PROT_READ|PROT_WRITE : PROT_READ,
|
||||
file->contents = (char *) mmap (nullptr, file->length, PROT_READ,
|
||||
MAP_PRIVATE | MAP_NORESERVE, fd, 0);
|
||||
|
||||
if (unlikely (file->contents == MAP_FAILED)) goto fail;
|
||||
|
||||
#elif defined(_WIN32) || defined(__CYGWIN__)
|
||||
HANDLE fd = CreateFile (file_name,
|
||||
writable ? GENERIC_READ|GENERIC_WRITE : GENERIC_READ,
|
||||
FILE_SHARE_READ, nullptr, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, nullptr);
|
||||
# define CLOSE CloseHandle
|
||||
close (fd);
|
||||
|
||||
return hb_blob_create (file->contents, file->length,
|
||||
HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file,
|
||||
(hb_destroy_func_t) _hb_mapped_file_destroy);
|
||||
|
||||
fail:
|
||||
close (fd);
|
||||
fail_without_close:
|
||||
free (file);
|
||||
|
||||
#elif (defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_MMAP)
|
||||
hb_mapped_file_t *file = (hb_mapped_file_t *) calloc (1, sizeof (hb_mapped_file_t));
|
||||
if (unlikely (!file)) return hb_blob_get_empty ();
|
||||
|
||||
HANDLE fd;
|
||||
unsigned int size = strlen (file_name) + 1;
|
||||
wchar_t * wchar_file_name = (wchar_t *) malloc (sizeof (wchar_t) * size);
|
||||
if (unlikely (wchar_file_name == nullptr)) goto fail_without_close;
|
||||
mbstowcs (wchar_file_name, file_name, size);
|
||||
fd = CreateFileW (wchar_file_name, GENERIC_READ, FILE_SHARE_READ, nullptr,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
|
||||
nullptr);
|
||||
free (wchar_file_name);
|
||||
|
||||
if (unlikely (fd == INVALID_HANDLE_VALUE)) goto fail_without_close;
|
||||
|
||||
file->length = (unsigned long) GetFileSize (fd, nullptr);
|
||||
file->mapping = CreateFileMapping (fd, nullptr,
|
||||
writable ? PAGE_WRITECOPY : PAGE_READONLY,
|
||||
0, 0, nullptr);
|
||||
file->mapping = CreateFileMapping (fd, nullptr, PAGE_READONLY, 0, 0, nullptr);
|
||||
if (unlikely (file->mapping == nullptr)) goto fail;
|
||||
|
||||
file->contents = (char *) MapViewOfFile (file->mapping,
|
||||
writable ? FILE_MAP_COPY : FILE_MAP_READ,
|
||||
0, 0, 0);
|
||||
file->contents = (char *) MapViewOfFile (file->mapping, FILE_MAP_READ, 0, 0, 0);
|
||||
if (unlikely (file->contents == nullptr)) goto fail;
|
||||
|
||||
#else
|
||||
mm = HB_MEMORY_MODE_WRITABLE;
|
||||
|
||||
FILE *fd = fopen (file_name, "rb");
|
||||
# define CLOSE fclose
|
||||
if (unlikely (!fd)) goto fail_without_close;
|
||||
|
||||
fseek (fd, 0, SEEK_END);
|
||||
file->length = ftell (fd);
|
||||
rewind (fd);
|
||||
file->contents = (char *) malloc (file->length);
|
||||
if (unlikely (!file->contents)) goto fail;
|
||||
|
||||
if (unlikely (fread (file->contents, 1, file->length, fd) != file->length))
|
||||
goto fail;
|
||||
|
||||
#endif
|
||||
|
||||
CLOSE (fd);
|
||||
return hb_blob_create (file->contents, file->length, mm, (void *) file,
|
||||
CloseHandle (fd);
|
||||
return hb_blob_create (file->contents, file->length,
|
||||
HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, (void *) file,
|
||||
(hb_destroy_func_t) _hb_mapped_file_destroy);
|
||||
|
||||
fail:
|
||||
CLOSE (fd);
|
||||
#undef CLOSE
|
||||
CloseHandle (fd);
|
||||
fail_without_close:
|
||||
free (file);
|
||||
|
||||
#endif
|
||||
|
||||
/* The following tries to read a file without knowing its size beforehand
|
||||
It's used as a fallback for systems without mmap or to read from pipes */
|
||||
unsigned long len = 0, allocated = BUFSIZ * 16;
|
||||
char *data = (char *) malloc (allocated);
|
||||
if (unlikely (data == nullptr)) return hb_blob_get_empty ();
|
||||
|
||||
FILE *fp = fopen (file_name, "rb");
|
||||
if (unlikely (fp == nullptr)) goto fread_fail_without_close;
|
||||
|
||||
while (!feof (fp))
|
||||
{
|
||||
if (allocated - len < BUFSIZ)
|
||||
{
|
||||
allocated *= 2;
|
||||
/* Don't allocate and go more than ~536MB, our mmap reader still
|
||||
can cover files like that but lets limit our fallback reader */
|
||||
if (unlikely (allocated > (2 << 28))) goto fread_fail;
|
||||
char *new_data = (char *) realloc (data, allocated);
|
||||
if (unlikely (new_data == nullptr)) goto fread_fail;
|
||||
data = new_data;
|
||||
}
|
||||
|
||||
unsigned long addition = fread (data + len, 1, allocated - len, fp);
|
||||
|
||||
int err = ferror (fp);
|
||||
#ifdef EINTR // armcc doesn't have it
|
||||
if (unlikely (err == EINTR)) continue;
|
||||
#endif
|
||||
if (unlikely (err)) goto fread_fail;
|
||||
|
||||
len += addition;
|
||||
}
|
||||
|
||||
return hb_blob_create (data, len, HB_MEMORY_MODE_WRITABLE, data,
|
||||
(hb_destroy_func_t) free);
|
||||
|
||||
fread_fail:
|
||||
fclose (fp);
|
||||
fread_fail_without_close:
|
||||
free (data);
|
||||
return hb_blob_get_empty ();
|
||||
}
|
||||
@@ -31,7 +31,6 @@
|
||||
#define HB_BUFFER_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-unicode-private.hh"
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -124,14 +124,14 @@ hb_buffer_t::enlarge (unsigned int size)
|
||||
hb_glyph_info_t *new_info = nullptr;
|
||||
bool separate_out = out_info != info;
|
||||
|
||||
if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0]))))
|
||||
if (unlikely (hb_unsigned_mul_overflows (size, sizeof (info[0]))))
|
||||
goto done;
|
||||
|
||||
while (size >= new_allocated)
|
||||
new_allocated += (new_allocated >> 1) + 32;
|
||||
|
||||
static_assert ((sizeof (info[0]) == sizeof (pos[0])), "");
|
||||
if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0]))))
|
||||
if (unlikely (hb_unsigned_mul_overflows (new_allocated, sizeof (info[0]))))
|
||||
goto done;
|
||||
|
||||
new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0]));
|
||||
|
||||
+10
-2
@@ -28,8 +28,6 @@
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
#include "hb-mutex-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
#include <locale.h>
|
||||
#ifdef HAVE_XLOCALE_H
|
||||
@@ -545,6 +543,7 @@ hb_script_get_horizontal_direction (hb_script_t script)
|
||||
|
||||
/* https://github.com/harfbuzz/harfbuzz/issues/1000 */
|
||||
case HB_SCRIPT_OLD_ITALIC:
|
||||
case HB_SCRIPT_RUNIC:
|
||||
|
||||
return HB_DIRECTION_INVALID;
|
||||
}
|
||||
@@ -1070,3 +1069,12 @@ hb_variation_to_string (hb_variation_t *variation,
|
||||
memcpy (buf, s, len);
|
||||
buf[len] = '\0';
|
||||
}
|
||||
|
||||
/* If there is no visibility control, then hb-static.cc will NOT
|
||||
* define anything. Instead, we get it to define one set in here
|
||||
* only, so only libharfbuzz.so defines them, not other libs. */
|
||||
#ifdef HB_NO_VISIBILITY
|
||||
#undef HB_NO_VISIBILITY
|
||||
#include "hb-static.cc"
|
||||
#define HB_NO_VISIBILITY 1
|
||||
#endif
|
||||
@@ -29,7 +29,6 @@
|
||||
#define HB_SHAPER coretext
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-shaper-impl-private.hh"
|
||||
|
||||
#include "hb-coretext.h"
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#define HB_DEBUG_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-dsalgs.hh"
|
||||
|
||||
|
||||
#ifndef HB_DEBUG
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#define HB_SHAPER directwrite
|
||||
#include "hb-shaper-impl-private.hh"
|
||||
|
||||
|
||||
+701
-1
@@ -30,6 +30,243 @@
|
||||
#include "hb-private.hh"
|
||||
|
||||
|
||||
/* Void! For when we need a expression-type of void. */
|
||||
typedef const struct _hb_void_t *hb_void_t;
|
||||
#define HB_VOID ((const _hb_void_t *) nullptr)
|
||||
|
||||
|
||||
/*
|
||||
* Bithacks.
|
||||
*/
|
||||
|
||||
/* Return the number of 1 bits in v. */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
hb_popcount (T v)
|
||||
{
|
||||
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return __builtin_popcount (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return __builtin_popcountl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return __builtin_popcountll (v);
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "HACKMEM 169" */
|
||||
uint32_t y;
|
||||
y = (v >> 1) &033333333333;
|
||||
y = v - y - ((y >>1) & 033333333333);
|
||||
return (((y + (y >> 3)) & 030707070707) % 077);
|
||||
}
|
||||
|
||||
if (sizeof (T) == 8)
|
||||
{
|
||||
unsigned int shift = 32;
|
||||
return hb_popcount<uint32_t> ((uint32_t) v) + hb_popcount ((uint32_t) (v >> shift));
|
||||
}
|
||||
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return hb_popcount<uint64_t> ((uint64_t) v) + hb_popcount ((uint64_t) (v >> shift));
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
/* Returns the number of bits needed to store number */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
hb_bit_storage (T v)
|
||||
{
|
||||
if (unlikely (!v)) return 0;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return sizeof (unsigned int) * 8 - __builtin_clz (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return sizeof (unsigned long) * 8 - __builtin_clzl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return sizeof (unsigned long long) * 8 - __builtin_clzll (v);
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanReverse (&where, v);
|
||||
return 1 + where;
|
||||
}
|
||||
# if _WIN64
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanReverse64 (&where, v);
|
||||
return 1 + where;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "bithacks" */
|
||||
const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
|
||||
const unsigned int S[] = {1, 2, 4, 8, 16};
|
||||
unsigned int r = 0;
|
||||
for (int i = 4; i >= 0; i--)
|
||||
if (v & b[i])
|
||||
{
|
||||
v >>= S[i];
|
||||
r |= S[i];
|
||||
}
|
||||
return r + 1;
|
||||
}
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
/* "bithacks" */
|
||||
const uint64_t b[] = {0x2ULL, 0xCULL, 0xF0ULL, 0xFF00ULL, 0xFFFF0000ULL, 0xFFFFFFFF00000000ULL};
|
||||
const unsigned int S[] = {1, 2, 4, 8, 16, 32};
|
||||
unsigned int r = 0;
|
||||
for (int i = 5; i >= 0; i--)
|
||||
if (v & b[i])
|
||||
{
|
||||
v >>= S[i];
|
||||
r |= S[i];
|
||||
}
|
||||
return r + 1;
|
||||
}
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return (v >> shift) ? hb_bit_storage<uint64_t> ((uint64_t) (v >> shift)) + shift :
|
||||
hb_bit_storage<uint64_t> ((uint64_t) v);
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
/* Returns the number of zero bits in the least significant side of v */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
hb_ctz (T v)
|
||||
{
|
||||
if (unlikely (!v)) return 0;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return __builtin_ctz (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return __builtin_ctzl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return __builtin_ctzll (v);
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanForward (&where, v);
|
||||
return where;
|
||||
}
|
||||
# if _WIN64
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanForward64 (&where, v);
|
||||
return where;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "bithacks" */
|
||||
unsigned int c = 32;
|
||||
v &= - (int32_t) v;
|
||||
if (v) c--;
|
||||
if (v & 0x0000FFFF) c -= 16;
|
||||
if (v & 0x00FF00FF) c -= 8;
|
||||
if (v & 0x0F0F0F0F) c -= 4;
|
||||
if (v & 0x33333333) c -= 2;
|
||||
if (v & 0x55555555) c -= 1;
|
||||
return c;
|
||||
}
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
/* "bithacks" */
|
||||
unsigned int c = 64;
|
||||
v &= - (int64_t) (v);
|
||||
if (v) c--;
|
||||
if (v & 0x00000000FFFFFFFFULL) c -= 32;
|
||||
if (v & 0x0000FFFF0000FFFFULL) c -= 16;
|
||||
if (v & 0x00FF00FF00FF00FFULL) c -= 8;
|
||||
if (v & 0x0F0F0F0F0F0F0F0FULL) c -= 4;
|
||||
if (v & 0x3333333333333333ULL) c -= 2;
|
||||
if (v & 0x5555555555555555ULL) c -= 1;
|
||||
return c;
|
||||
}
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return (uint64_t) v ? hb_bit_storage<uint64_t> ((uint64_t) v) :
|
||||
hb_bit_storage<uint64_t> ((uint64_t) (v >> shift)) + shift;
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tiny stuff.
|
||||
*/
|
||||
|
||||
#undef MIN
|
||||
template <typename Type>
|
||||
static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
|
||||
|
||||
#undef MAX
|
||||
template <typename Type>
|
||||
static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
|
||||
|
||||
static inline unsigned int DIV_CEIL (const unsigned int a, unsigned int b)
|
||||
{ return (a + (b - 1)) / b; }
|
||||
|
||||
|
||||
#undef ARRAY_LENGTH
|
||||
template <typename Type, unsigned int n>
|
||||
static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; }
|
||||
/* A const version, but does not detect erratically being called on pointers. */
|
||||
#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
|
||||
|
||||
static inline bool
|
||||
hb_unsigned_mul_overflows (unsigned int count, unsigned int size)
|
||||
{
|
||||
return (size > 0) && (count >= ((unsigned int) -1) / size);
|
||||
}
|
||||
|
||||
static inline unsigned int
|
||||
hb_ceil_to_4 (unsigned int v)
|
||||
{
|
||||
return ((v - 1) | 3) + 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Sort and search.
|
||||
*/
|
||||
|
||||
static inline void *
|
||||
hb_bsearch_r (const void *key, const void *base,
|
||||
size_t nmemb, size_t size,
|
||||
@@ -53,7 +290,6 @@ hb_bsearch_r (const void *key, const void *base,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* From https://github.com/noporpoise/sort_r */
|
||||
|
||||
/* Isaac Turner 29 April 2014 Public Domain */
|
||||
@@ -158,4 +394,468 @@ static inline void hb_sort_r(void *base, size_t nel, size_t width,
|
||||
sort_r_simple(base, nel, width, compar, arg);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, typename T2> static inline void
|
||||
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2)
|
||||
{
|
||||
for (unsigned int i = 1; i < len; i++)
|
||||
{
|
||||
unsigned int j = i;
|
||||
while (j && compar (&array[j - 1], &array[i]) > 0)
|
||||
j--;
|
||||
if (i == j)
|
||||
continue;
|
||||
/* Move item i to occupy place for item j, shift what's in between. */
|
||||
{
|
||||
T t = array[i];
|
||||
memmove (&array[j + 1], &array[j], (i - j) * sizeof (T));
|
||||
array[j] = t;
|
||||
}
|
||||
if (array2)
|
||||
{
|
||||
T2 t = array2[i];
|
||||
memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2));
|
||||
array2[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> static inline void
|
||||
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *))
|
||||
{
|
||||
hb_stable_sort (array, len, compar, (int *) nullptr);
|
||||
}
|
||||
|
||||
static inline hb_bool_t
|
||||
hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out)
|
||||
{
|
||||
/* Pain because we don't know whether s is nul-terminated. */
|
||||
char buf[64];
|
||||
len = MIN (ARRAY_LENGTH (buf) - 1, len);
|
||||
strncpy (buf, s, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
char *end;
|
||||
errno = 0;
|
||||
unsigned long v = strtoul (buf, &end, base);
|
||||
if (errno) return false;
|
||||
if (*end) return false;
|
||||
*out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define HB_VECTOR_INIT {0, 0, false, nullptr}
|
||||
template <typename Type, unsigned int StaticSize=8>
|
||||
struct hb_vector_t
|
||||
{
|
||||
unsigned int len;
|
||||
unsigned int allocated; /* == 0 means allocation failed. */
|
||||
Type *arrayZ;
|
||||
Type static_array[StaticSize];
|
||||
|
||||
void init (void)
|
||||
{
|
||||
len = 0;
|
||||
allocated = ARRAY_LENGTH (static_array);
|
||||
arrayZ = static_array;
|
||||
}
|
||||
|
||||
inline Type& operator [] (unsigned int i)
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return Crap (Type);
|
||||
return arrayZ[i];
|
||||
}
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return Null(Type);
|
||||
return arrayZ[i];
|
||||
}
|
||||
|
||||
inline Type *push (void)
|
||||
{
|
||||
if (unlikely (!resize (len + 1)))
|
||||
return &Crap(Type);
|
||||
return &arrayZ[len - 1];
|
||||
}
|
||||
inline Type *push (const Type& v)
|
||||
{
|
||||
Type *p = push ();
|
||||
*p = v;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Allocate for size but don't adjust len. */
|
||||
inline bool alloc (unsigned int size)
|
||||
{
|
||||
if (unlikely (!allocated))
|
||||
return false;
|
||||
|
||||
if (likely (size <= allocated))
|
||||
return true;
|
||||
|
||||
/* Reallocate */
|
||||
|
||||
unsigned int new_allocated = allocated;
|
||||
while (size >= new_allocated)
|
||||
new_allocated += (new_allocated >> 1) + 8;
|
||||
|
||||
Type *new_array = nullptr;
|
||||
|
||||
if (arrayZ == static_array)
|
||||
{
|
||||
new_array = (Type *) calloc (new_allocated, sizeof (Type));
|
||||
if (new_array)
|
||||
memcpy (new_array, arrayZ, len * sizeof (Type));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool overflows = (new_allocated < allocated) || hb_unsigned_mul_overflows (new_allocated, sizeof (Type));
|
||||
if (likely (!overflows))
|
||||
new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type));
|
||||
}
|
||||
|
||||
if (unlikely (!new_array))
|
||||
{
|
||||
allocated = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
arrayZ = new_array;
|
||||
allocated = new_allocated;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool resize (int size_)
|
||||
{
|
||||
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;
|
||||
if (!alloc (size))
|
||||
return false;
|
||||
|
||||
if (size > len)
|
||||
memset (arrayZ + len, 0, (size - len) * sizeof (*arrayZ));
|
||||
|
||||
len = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pop (void)
|
||||
{
|
||||
if (!len) return;
|
||||
len--;
|
||||
}
|
||||
|
||||
inline void remove (unsigned int i)
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return;
|
||||
memmove (static_cast<void *> (&arrayZ[i]),
|
||||
static_cast<void *> (&arrayZ[i + 1]),
|
||||
(len - i - 1) * sizeof (Type));
|
||||
len--;
|
||||
}
|
||||
|
||||
inline void shrink (int size_)
|
||||
{
|
||||
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;
|
||||
if (size < len)
|
||||
len = size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *find (T v) {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *find (T v) const {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline void qsort (int (*cmp)(const void*, const void*))
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), cmp);
|
||||
}
|
||||
|
||||
inline void qsort (void)
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), Type::cmp);
|
||||
}
|
||||
|
||||
inline void qsort (unsigned int start, unsigned int end)
|
||||
{
|
||||
::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *lsearch (const T &x)
|
||||
{
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (0 == this->arrayZ[i].cmp (&x))
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *bsearch (const T &x)
|
||||
{
|
||||
unsigned int i;
|
||||
return bfind (x, &i) ? &arrayZ[i] : nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *bsearch (const T &x) const
|
||||
{
|
||||
unsigned int i;
|
||||
return bfind (x, &i) ? &arrayZ[i] : nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline bool bfind (const T &x, unsigned int *i) const
|
||||
{
|
||||
int min = 0, max = (int) this->len - 1;
|
||||
while (min <= max)
|
||||
{
|
||||
int mid = (min + max) / 2;
|
||||
int c = this->arrayZ[mid].cmp (&x);
|
||||
if (c < 0)
|
||||
max = mid - 1;
|
||||
else if (c > 0)
|
||||
min = mid + 1;
|
||||
else
|
||||
{
|
||||
*i = mid;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (max < 0 || (max < (int) this->len && this->arrayZ[max].cmp (&x) > 0))
|
||||
max++;
|
||||
*i = max;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
if (arrayZ != static_array)
|
||||
free (arrayZ);
|
||||
arrayZ = nullptr;
|
||||
allocated = len = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define HB_LOCKABLE_SET_INIT {HB_VECTOR_INIT}
|
||||
template <typename item_t, typename lock_t>
|
||||
struct hb_lockable_set_t
|
||||
{
|
||||
hb_vector_t <item_t, 1> items;
|
||||
|
||||
inline void init (void) { items.init (); }
|
||||
|
||||
template <typename T>
|
||||
inline item_t *replace_or_insert (T v, lock_t &l, bool replace)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item) {
|
||||
if (replace) {
|
||||
item_t old = *item;
|
||||
*item = v;
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
}
|
||||
else {
|
||||
item = nullptr;
|
||||
l.unlock ();
|
||||
}
|
||||
} else {
|
||||
item = items.push (v);
|
||||
l.unlock ();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void remove (T v, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item) {
|
||||
item_t old = *item;
|
||||
*item = items[items.len - 1];
|
||||
items.pop ();
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
} else {
|
||||
l.unlock ();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool find (T v, item_t *i, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item)
|
||||
*i = *item;
|
||||
l.unlock ();
|
||||
return !!item;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline item_t *find_or_insert (T v, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (!item) {
|
||||
item = items.push (v);
|
||||
}
|
||||
l.unlock ();
|
||||
return item;
|
||||
}
|
||||
|
||||
inline void fini (lock_t &l)
|
||||
{
|
||||
if (!items.len) {
|
||||
/* No need for locking. */
|
||||
items.fini ();
|
||||
return;
|
||||
}
|
||||
l.lock ();
|
||||
while (items.len) {
|
||||
item_t old = items[items.len - 1];
|
||||
items.pop ();
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
l.lock ();
|
||||
}
|
||||
items.fini ();
|
||||
l.unlock ();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <typename Type>
|
||||
struct hb_auto_t : Type
|
||||
{
|
||||
hb_auto_t (void) { Type::init (); }
|
||||
~hb_auto_t (void) { Type::fini (); }
|
||||
private: /* Hide */
|
||||
void init (void) {}
|
||||
void fini (void) {}
|
||||
};
|
||||
|
||||
struct hb_bytes_t
|
||||
{
|
||||
inline hb_bytes_t (void) : bytes (nullptr), len (0) {}
|
||||
inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
|
||||
|
||||
inline int cmp (const hb_bytes_t &a) const
|
||||
{
|
||||
if (len != a.len)
|
||||
return (int) a.len - (int) len;
|
||||
|
||||
return memcmp (a.bytes, bytes, len);
|
||||
}
|
||||
static inline int cmp (const void *pa, const void *pb)
|
||||
{
|
||||
hb_bytes_t *a = (hb_bytes_t *) pa;
|
||||
hb_bytes_t *b = (hb_bytes_t *) pb;
|
||||
return b->cmp (*a);
|
||||
}
|
||||
|
||||
const char *bytes;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
|
||||
struct HbOpOr
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = true;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a | b; }
|
||||
};
|
||||
struct HbOpAnd
|
||||
{
|
||||
static const bool passthru_left = false;
|
||||
static const bool passthru_right = false;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a & b; }
|
||||
};
|
||||
struct HbOpMinus
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = false;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a & ~b; }
|
||||
};
|
||||
struct HbOpXor
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = true;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a ^ b; }
|
||||
};
|
||||
|
||||
|
||||
/* Compiler-assisted vectorization. */
|
||||
|
||||
/* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))),
|
||||
* using vectorized operations if HB_VECTOR_SIZE is set to **bit** numbers (eg 128).
|
||||
* Define that to 0 to disable. */
|
||||
template <typename elt_t, unsigned int byte_size>
|
||||
struct hb_vector_size_t
|
||||
{
|
||||
elt_t& operator [] (unsigned int i) { return u.v[i]; }
|
||||
const elt_t& operator [] (unsigned int i) const { return u.v[i]; }
|
||||
|
||||
template <class Op>
|
||||
inline hb_vector_size_t process (const hb_vector_size_t &o) const
|
||||
{
|
||||
hb_vector_size_t r;
|
||||
#if HB_VECTOR_SIZE
|
||||
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
|
||||
Op::process (r.u.vec[i], u.vec[i], o.u.vec[i]);
|
||||
else
|
||||
#endif
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
|
||||
Op::process (r.u.v[i], u.v[i], o.u.v[i]);
|
||||
return r;
|
||||
}
|
||||
inline hb_vector_size_t operator | (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpOr> (o); }
|
||||
inline hb_vector_size_t operator & (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpAnd> (o); }
|
||||
inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpXor> (o); }
|
||||
inline hb_vector_size_t operator ~ () const
|
||||
{
|
||||
hb_vector_size_t r;
|
||||
#if HB_VECTOR_SIZE && 0
|
||||
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
|
||||
r.u.vec[i] = ~u.vec[i];
|
||||
else
|
||||
#endif
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
|
||||
r.u.v[i] = ~u.v[i];
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, "");
|
||||
union {
|
||||
elt_t v[byte_size / sizeof (elt_t)];
|
||||
#if HB_VECTOR_SIZE
|
||||
hb_vector_size_impl_t vec[byte_size / sizeof (hb_vector_size_impl_t)];
|
||||
#endif
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
#endif /* HB_DSALGS_HH */
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-shaper-private.hh"
|
||||
#include "hb-shape-plan-private.hh"
|
||||
|
||||
|
||||
+6
-23
@@ -31,8 +31,6 @@
|
||||
#include "hb-face-private.hh"
|
||||
#include "hb-blob-private.hh"
|
||||
#include "hb-open-file-private.hh"
|
||||
#include "hb-ot-head-table.hh"
|
||||
#include "hb-ot-maxp-table.hh"
|
||||
|
||||
|
||||
|
||||
@@ -52,10 +50,13 @@ hb_face_count (hb_blob_t *blob)
|
||||
if (unlikely (!blob))
|
||||
return 0;
|
||||
|
||||
hb_blob_t *sanitized = OT::Sanitizer<OT::OpenTypeFontFile> ().sanitize (blob);
|
||||
/* TODO We shouldn't be sanitizing blob. Port to run sanitizer and return if not sane. */
|
||||
hb_blob_t *sanitized = OT::hb_sanitize_context_t().sanitize_blob<OT::OpenTypeFontFile> (hb_blob_reference (blob));
|
||||
const OT::OpenTypeFontFile& ot = *sanitized->as<OT::OpenTypeFontFile> ();
|
||||
unsigned int ret = ot.get_face_count ();
|
||||
hb_blob_destroy (sanitized);
|
||||
|
||||
return ot.get_face_count ();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -188,7 +189,7 @@ hb_face_create (hb_blob_t *blob,
|
||||
if (unlikely (!blob))
|
||||
blob = hb_blob_get_empty ();
|
||||
|
||||
hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::Sanitizer<OT::OpenTypeFontFile>().sanitize (hb_blob_reference (blob)), index);
|
||||
hb_face_for_data_closure_t *closure = _hb_face_for_data_closure_create (OT::hb_sanitize_context_t().sanitize_blob<OT::OpenTypeFontFile> (hb_blob_reference (blob)), index);
|
||||
|
||||
if (unlikely (!closure))
|
||||
return hb_face_get_empty ();
|
||||
@@ -445,15 +446,6 @@ hb_face_get_upem (hb_face_t *face)
|
||||
return face->get_upem ();
|
||||
}
|
||||
|
||||
void
|
||||
hb_face_t::load_upem (void) const
|
||||
{
|
||||
hb_blob_t *head_blob = OT::Sanitizer<OT::head>().sanitize (reference_table (HB_OT_TAG_head));
|
||||
const OT::head *head_table = head_blob->as<OT::head> ();
|
||||
upem = head_table->get_upem ();
|
||||
hb_blob_destroy (head_blob);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_face_set_glyph_count:
|
||||
* @face: a face.
|
||||
@@ -489,15 +481,6 @@ hb_face_get_glyph_count (hb_face_t *face)
|
||||
return face->get_num_glyphs ();
|
||||
}
|
||||
|
||||
void
|
||||
hb_face_t::load_num_glyphs (void) const
|
||||
{
|
||||
hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (reference_table (HB_OT_TAG_maxp));
|
||||
const OT::maxp *maxp_table = maxp_blob->as<OT::maxp> ();
|
||||
num_glyphs = maxp_table->get_num_glyphs ();
|
||||
hb_blob_destroy (maxp_blob);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_face_get_table_tags:
|
||||
* @face: a face.
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-face-private.hh"
|
||||
#include "hb-shaper-private.hh"
|
||||
|
||||
|
||||
+3
-1
@@ -28,7 +28,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
|
||||
#include "hb-ft.h"
|
||||
|
||||
@@ -498,7 +497,10 @@ reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
|
||||
|
||||
error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length);
|
||||
if (error)
|
||||
{
|
||||
free (buffer);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return hb_blob_create ((const char *) buffer, length,
|
||||
HB_MEMORY_MODE_WRITABLE,
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright © 2018 Google, Inc.
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*
|
||||
* Google Author(s): Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#ifndef HB_ITER_PRIVATE_HH
|
||||
#define HB_ITER_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
|
||||
/* Unified iterator object.
|
||||
*
|
||||
* The goal of this template is to make the same iterator interface
|
||||
* available to all types, and make it very easy and compact to use.
|
||||
* Iterator objects are small, light-weight, objects that can be
|
||||
* copied by value. If the collection / object being iterated on
|
||||
* is writable, then the iterator points to lvalues, otherwise it
|
||||
* returns rvalues.
|
||||
*
|
||||
* The way to declare, initialize, and use iterators, eg.:
|
||||
*
|
||||
* Iter<const int *> s (src);
|
||||
* Iter<int *> t (dst);
|
||||
* for (; s && t; s++, t++)
|
||||
* *s = *t;
|
||||
*/
|
||||
|
||||
template <typename T>
|
||||
struct Iter;
|
||||
|
||||
#if 0
|
||||
template <typename T>
|
||||
struct Iter
|
||||
{
|
||||
explicit inline Iter (const T &c);
|
||||
};
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
struct Iter<T *>
|
||||
{
|
||||
/* Type of items. */
|
||||
typedef T Value;
|
||||
|
||||
/* Constructors. */
|
||||
inline Iter (T *array_, int length_) :
|
||||
array (array_), length (MAX (length_, 0)) {}
|
||||
template <unsigned int length_>
|
||||
explicit inline Iter (T (&array_)[length_]) :
|
||||
array (array_), length (length_) {}
|
||||
|
||||
/* Emptiness. */
|
||||
inline operator bool (void) const { return bool (length); }
|
||||
|
||||
/* Current item. */
|
||||
inline T &operator * (void)
|
||||
{
|
||||
if (unlikely (!length)) return CrapOrNull(T);
|
||||
return *array;
|
||||
}
|
||||
inline T &operator -> (void)
|
||||
{
|
||||
return (operator *);
|
||||
}
|
||||
|
||||
/* Next. */
|
||||
inline Iter<T *> & operator ++ (void)
|
||||
{
|
||||
if (unlikely (!length)) return *this;
|
||||
array++;
|
||||
length--;
|
||||
return *this;
|
||||
}
|
||||
/* Might return void, or a copy of pre-increment iterator. */
|
||||
inline void operator ++ (int)
|
||||
{
|
||||
if (unlikely (!length)) return;
|
||||
array++;
|
||||
length--;
|
||||
}
|
||||
|
||||
/* Some iterators might implement len(). */
|
||||
inline unsigned int len (void) const { return length; }
|
||||
|
||||
/* Some iterators might implement fast-forward.
|
||||
* Only implement it if it's constant-time. */
|
||||
inline void operator += (unsigned int n)
|
||||
{
|
||||
n = MIN (n, length);
|
||||
array += n;
|
||||
length -= n;
|
||||
}
|
||||
|
||||
/* Some iterators might implement random-access.
|
||||
* Only implement it if it's constant-time. */
|
||||
inline Iter<T *> & operator [] (unsigned int i)
|
||||
{
|
||||
if (unlikely (i >= length)) return CrapOrNull(T);
|
||||
return array[i];
|
||||
}
|
||||
|
||||
private:
|
||||
T *array;
|
||||
unsigned int length;
|
||||
};
|
||||
|
||||
/* XXX Remove
|
||||
* Just to test these compile. */
|
||||
static inline void
|
||||
m (void)
|
||||
{
|
||||
const int src[10] = {};
|
||||
int dst[20];
|
||||
|
||||
Iter<const int *> s (src);
|
||||
Iter<const int *> s2 (src, 5);
|
||||
Iter<int *> t (dst);
|
||||
|
||||
s2 = s;
|
||||
|
||||
for (; s && t; ++s, ++t)
|
||||
{
|
||||
*t = *s;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HB_ITER_PRIVATE_HH */
|
||||
@@ -0,0 +1,702 @@
|
||||
/*
|
||||
* Copyright © 2007,2008,2009,2010 Red Hat, Inc.
|
||||
* Copyright © 2012,2018 Google, Inc.
|
||||
*
|
||||
* This is part of HarfBuzz, a text shaping library.
|
||||
*
|
||||
* Permission is hereby granted, without written agreement and without
|
||||
* license or royalty fees, to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose, provided that the
|
||||
* above copyright notice and the following two paragraphs appear in
|
||||
* all copies of this software.
|
||||
*
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
||||
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
||||
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
*
|
||||
* Red Hat Author(s): Behdad Esfahbod
|
||||
* Google Author(s): Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#ifndef HB_MACHINERY_PRIVATE_HH
|
||||
#define HB_MACHINERY_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-iter-private.hh"
|
||||
|
||||
|
||||
namespace OT {
|
||||
|
||||
|
||||
/*
|
||||
* Casts
|
||||
*/
|
||||
|
||||
/* Cast to struct T, reference to reference */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type& CastR(const TObject &X)
|
||||
{ return reinterpret_cast<const Type&> (X); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type& CastR(TObject &X)
|
||||
{ return reinterpret_cast<Type&> (X); }
|
||||
|
||||
/* Cast to struct T, pointer to pointer */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type* CastP(const TObject *X)
|
||||
{ return reinterpret_cast<const Type*> (X); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type* CastP(TObject *X)
|
||||
{ return reinterpret_cast<Type*> (X); }
|
||||
|
||||
/* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory
|
||||
* location pointed to by P plus Ofs bytes. */
|
||||
template<typename Type>
|
||||
static inline const Type& StructAtOffset(const void *P, unsigned int offset)
|
||||
{ return * reinterpret_cast<const Type*> ((const char *) P + offset); }
|
||||
template<typename Type>
|
||||
static inline Type& StructAtOffset(void *P, unsigned int offset)
|
||||
{ return * reinterpret_cast<Type*> ((char *) P + offset); }
|
||||
|
||||
/* StructAfter<T>(X) returns the struct T& that is placed after X.
|
||||
* Works with X of variable size also. X must implement get_size() */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type& StructAfter(const TObject &X)
|
||||
{ return StructAtOffset<Type>(&X, X.get_size()); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type& StructAfter(TObject &X)
|
||||
{ return StructAtOffset<Type>(&X, X.get_size()); }
|
||||
|
||||
|
||||
/*
|
||||
* Size checking
|
||||
*/
|
||||
|
||||
/* Check _assertion in a method environment */
|
||||
#define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \
|
||||
inline void _instance_assertion_on_line_##_line (void) const \
|
||||
{ \
|
||||
static_assert ((_assertion), ""); \
|
||||
ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \
|
||||
}
|
||||
# define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion)
|
||||
# define DEFINE_INSTANCE_ASSERTION(_assertion) _DEFINE_INSTANCE_ASSERTION0 (__LINE__, _assertion)
|
||||
|
||||
/* Check that _code compiles in a method environment */
|
||||
#define _DEFINE_COMPILES_ASSERTION1(_line, _code) \
|
||||
inline void _compiles_assertion_on_line_##_line (void) const \
|
||||
{ _code; }
|
||||
# define _DEFINE_COMPILES_ASSERTION0(_line, _code) _DEFINE_COMPILES_ASSERTION1 (_line, _code)
|
||||
# define DEFINE_COMPILES_ASSERTION(_code) _DEFINE_COMPILES_ASSERTION0 (__LINE__, _code)
|
||||
|
||||
|
||||
#define DEFINE_SIZE_STATIC(size) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \
|
||||
static const unsigned int static_size = (size); \
|
||||
static const unsigned int min_size = (size); \
|
||||
inline unsigned int get_size (void) const { return (size); }
|
||||
|
||||
#define DEFINE_SIZE_UNION(size, _member) \
|
||||
DEFINE_INSTANCE_ASSERTION (0*sizeof(this->u._member.static_size) + sizeof(this->u._member) == (size)); \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_MIN(size) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)); \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_ARRAY(size, array) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \
|
||||
DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_ARRAY2(size, array1, array2) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \
|
||||
DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
|
||||
/*
|
||||
* Dispatch
|
||||
*/
|
||||
|
||||
template <typename Context, typename Return, unsigned int MaxDebugDepth>
|
||||
struct hb_dispatch_context_t
|
||||
{
|
||||
static const unsigned int max_debug_depth = MaxDebugDepth;
|
||||
typedef Return return_t;
|
||||
template <typename T, typename F>
|
||||
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
|
||||
*/
|
||||
|
||||
/* This limits sanitizing time on really broken fonts. */
|
||||
#ifndef HB_SANITIZE_MAX_EDITS
|
||||
#define HB_SANITIZE_MAX_EDITS 32
|
||||
#endif
|
||||
#ifndef HB_SANITIZE_MAX_OPS_FACTOR
|
||||
#define HB_SANITIZE_MAX_OPS_FACTOR 8
|
||||
#endif
|
||||
#ifndef HB_SANITIZE_MAX_OPS_MIN
|
||||
#define HB_SANITIZE_MAX_OPS_MIN 16384
|
||||
#endif
|
||||
|
||||
struct hb_sanitize_context_t :
|
||||
hb_dispatch_context_t<hb_sanitize_context_t, bool, HB_DEBUG_SANITIZE>
|
||||
{
|
||||
inline hb_sanitize_context_t (void) :
|
||||
debug_depth (0),
|
||||
start (nullptr), end (nullptr),
|
||||
writable (false), edit_count (0), max_ops (0),
|
||||
blob (nullptr),
|
||||
num_glyphs (65536),
|
||||
num_glyphs_set (false) {}
|
||||
|
||||
inline const char *get_name (void) { return "SANITIZE"; }
|
||||
template <typename T, typename F>
|
||||
inline bool may_dispatch (const T *obj, const F *format)
|
||||
{ return format->sanitize (this); }
|
||||
template <typename T>
|
||||
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)
|
||||
{
|
||||
this->blob = hb_blob_reference (b);
|
||||
this->writable = false;
|
||||
}
|
||||
|
||||
inline void set_num_glyphs (unsigned int num_glyphs_)
|
||||
{
|
||||
num_glyphs = num_glyphs_;
|
||||
num_glyphs_set = true;
|
||||
}
|
||||
inline unsigned int get_num_glyphs (void) { return num_glyphs; }
|
||||
|
||||
inline void start_processing (void)
|
||||
{
|
||||
this->start = hb_blob_get_data (this->blob, nullptr);
|
||||
this->end = this->start + this->blob->length;
|
||||
assert (this->start <= this->end); /* Must not overflow. */
|
||||
this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
|
||||
(unsigned) HB_SANITIZE_MAX_OPS_MIN);
|
||||
this->edit_count = 0;
|
||||
this->debug_depth = 0;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1,
|
||||
"start [%p..%p] (%lu bytes)",
|
||||
this->start, this->end,
|
||||
(unsigned long) (this->end - this->start));
|
||||
}
|
||||
|
||||
inline void end_processing (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->start, 0, -1,
|
||||
"end [%p..%p] %u edit requests",
|
||||
this->start, this->end, this->edit_count);
|
||||
|
||||
hb_blob_destroy (this->blob);
|
||||
this->blob = nullptr;
|
||||
this->start = this->end = nullptr;
|
||||
}
|
||||
|
||||
inline bool check_range (const void *base, unsigned int len) const
|
||||
{
|
||||
const char *p = (const char *) base;
|
||||
bool ok = this->max_ops-- > 0 &&
|
||||
this->start <= p &&
|
||||
p <= this->end &&
|
||||
(unsigned int) (this->end - p) >= len;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"check_range [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
ok ? "OK" : "OUT-OF-RANGE");
|
||||
|
||||
return likely (ok);
|
||||
}
|
||||
|
||||
inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
|
||||
{
|
||||
const char *p = (const char *) base;
|
||||
bool overflows = hb_unsigned_mul_overflows (len, record_size);
|
||||
unsigned int array_size = record_size * len;
|
||||
bool ok = !overflows && this->check_range (base, array_size);
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"check_array [%p..%p] (%d*%d=%d bytes) in [%p..%p] -> %s",
|
||||
p, p + (record_size * len), record_size, len, (unsigned int) array_size,
|
||||
this->start, this->end,
|
||||
overflows ? "OVERFLOWS" : ok ? "OK" : "OUT-OF-RANGE");
|
||||
|
||||
return likely (ok);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline bool check_struct (const Type *obj) const
|
||||
{
|
||||
return likely (this->check_range (obj, obj->min_size));
|
||||
}
|
||||
|
||||
inline bool may_edit (const void *base, unsigned int len)
|
||||
{
|
||||
if (this->edit_count >= HB_SANITIZE_MAX_EDITS)
|
||||
return false;
|
||||
|
||||
const char *p = (const char *) base;
|
||||
this->edit_count++;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
this->edit_count,
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
this->writable ? "GRANTED" : "DENIED");
|
||||
|
||||
return this->writable;
|
||||
}
|
||||
|
||||
template <typename Type, typename ValueType>
|
||||
inline bool try_set (const Type *obj, const ValueType &v) {
|
||||
if (this->may_edit (obj, obj->static_size)) {
|
||||
const_cast<Type *> (obj)->set (v);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline hb_blob_t *sanitize_blob (hb_blob_t *blob)
|
||||
{
|
||||
bool sane;
|
||||
|
||||
init (blob);
|
||||
|
||||
retry:
|
||||
DEBUG_MSG_FUNC (SANITIZE, start, "start");
|
||||
|
||||
start_processing ();
|
||||
|
||||
if (unlikely (!start))
|
||||
{
|
||||
end_processing ();
|
||||
return blob;
|
||||
}
|
||||
|
||||
Type *t = CastP<Type> (const_cast<char *> (start));
|
||||
|
||||
sane = t->sanitize (this);
|
||||
if (sane)
|
||||
{
|
||||
if (edit_count)
|
||||
{
|
||||
DEBUG_MSG_FUNC (SANITIZE, start, "passed first round with %d edits; going for second round", edit_count);
|
||||
|
||||
/* sanitize again to ensure no toe-stepping */
|
||||
edit_count = 0;
|
||||
sane = t->sanitize (this);
|
||||
if (edit_count) {
|
||||
DEBUG_MSG_FUNC (SANITIZE, start, "requested %d edits in second round; FAILLING", edit_count);
|
||||
sane = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (edit_count && !writable) {
|
||||
start = hb_blob_get_data_writable (blob, nullptr);
|
||||
end = start + blob->length;
|
||||
|
||||
if (start)
|
||||
{
|
||||
writable = true;
|
||||
/* ok, we made it writable by relocating. try again */
|
||||
DEBUG_MSG_FUNC (SANITIZE, start, "retry");
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_processing ();
|
||||
|
||||
DEBUG_MSG_FUNC (SANITIZE, start, sane ? "PASSED" : "FAILED");
|
||||
if (sane)
|
||||
{
|
||||
blob->lock ();
|
||||
return blob;
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_blob_destroy (blob);
|
||||
return hb_blob_get_empty ();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline hb_blob_t *reference_table (const hb_face_t *face, hb_tag_t tableTag = Type::tableTag)
|
||||
{
|
||||
if (!num_glyphs_set)
|
||||
set_num_glyphs (face->get_num_glyphs ());
|
||||
return sanitize_blob<Type> (face->reference_table (tableTag));
|
||||
}
|
||||
|
||||
mutable unsigned int debug_depth;
|
||||
const char *start, *end;
|
||||
private:
|
||||
bool writable;
|
||||
unsigned int edit_count;
|
||||
mutable int max_ops;
|
||||
hb_blob_t *blob;
|
||||
unsigned int num_glyphs;
|
||||
bool num_glyphs_set;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Serialize
|
||||
*/
|
||||
|
||||
struct hb_serialize_context_t
|
||||
{
|
||||
inline hb_serialize_context_t (void *start_, unsigned int size)
|
||||
{
|
||||
this->start = (char *) start_;
|
||||
this->end = this->start + size;
|
||||
|
||||
this->ran_out_of_room = false;
|
||||
this->head = this->start;
|
||||
this->debug_depth = 0;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *start_serialize (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, +1,
|
||||
"start [%p..%p] (%lu bytes)",
|
||||
this->start, this->end,
|
||||
(unsigned long) (this->end - this->start));
|
||||
|
||||
return start_embed<Type> ();
|
||||
}
|
||||
|
||||
inline void end_serialize (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1,
|
||||
"end [%p..%p] serialized %d bytes; %s",
|
||||
this->start, this->end,
|
||||
(int) (this->head - this->start),
|
||||
this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room");
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *copy (void)
|
||||
{
|
||||
assert (!this->ran_out_of_room);
|
||||
unsigned int len = this->head - this->start;
|
||||
void *p = malloc (len);
|
||||
if (p)
|
||||
memcpy (p, this->start, len);
|
||||
return reinterpret_cast<Type *> (p);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *allocate_size (unsigned int size)
|
||||
{
|
||||
if (unlikely (this->ran_out_of_room || this->end - this->head < ptrdiff_t (size))) {
|
||||
this->ran_out_of_room = true;
|
||||
return nullptr;
|
||||
}
|
||||
memset (this->head, 0, size);
|
||||
char *ret = this->head;
|
||||
this->head += size;
|
||||
return reinterpret_cast<Type *> (ret);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *allocate_min (void)
|
||||
{
|
||||
return this->allocate_size<Type> (Type::min_size);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *start_embed (void)
|
||||
{
|
||||
Type *ret = reinterpret_cast<Type *> (this->head);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *embed (const Type &obj)
|
||||
{
|
||||
unsigned int size = obj.get_size ();
|
||||
Type *ret = this->allocate_size<Type> (size);
|
||||
if (unlikely (!ret)) return nullptr;
|
||||
memcpy (ret, obj, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *extend_min (Type &obj)
|
||||
{
|
||||
unsigned int size = obj.min_size;
|
||||
assert (this->start <= (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head);
|
||||
if (unlikely (!this->allocate_size<Type> (((char *) &obj) + size - this->head))) return nullptr;
|
||||
return reinterpret_cast<Type *> (&obj);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *extend (Type &obj)
|
||||
{
|
||||
unsigned int size = obj.get_size ();
|
||||
assert (this->start < (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head);
|
||||
if (unlikely (!this->allocate_size<Type> (((char *) &obj) + size - this->head))) return nullptr;
|
||||
return reinterpret_cast<Type *> (&obj);
|
||||
}
|
||||
|
||||
inline void truncate (void *new_head)
|
||||
{
|
||||
assert (this->start < new_head && new_head <= this->head);
|
||||
this->head = (char *) new_head;
|
||||
}
|
||||
|
||||
unsigned int debug_depth;
|
||||
char *start, *end, *head;
|
||||
bool ran_out_of_room;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Supplier
|
||||
*/
|
||||
|
||||
template <typename Type>
|
||||
struct Supplier
|
||||
{
|
||||
inline Supplier (const Type *array, unsigned int len_, unsigned int stride_=sizeof(Type))
|
||||
{
|
||||
head = array;
|
||||
len = len_;
|
||||
stride = stride_;
|
||||
}
|
||||
inline const Type operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len)) return Type ();
|
||||
return * (const Type *) (const void *) ((const char *) head + stride * i);
|
||||
}
|
||||
|
||||
inline Supplier<Type> & operator += (unsigned int count)
|
||||
{
|
||||
if (unlikely (count > len))
|
||||
count = len;
|
||||
len -= count;
|
||||
head = (const Type *) (const void *) ((const char *) head + stride * count);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
inline Supplier (const Supplier<Type> &); /* Disallow copy */
|
||||
inline Supplier<Type>& operator= (const Supplier<Type> &); /* Disallow copy */
|
||||
|
||||
unsigned int len;
|
||||
unsigned int stride;
|
||||
const Type *head;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Big-endian integers.
|
||||
*/
|
||||
|
||||
template <typename Type, int Bytes> struct BEInt;
|
||||
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 1>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v = V;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
private: uint8_t v;
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 2>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 8) & 0xFF;
|
||||
v[1] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 8)
|
||||
+ (v[1] );
|
||||
}
|
||||
private: uint8_t v[2];
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 3>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 16) & 0xFF;
|
||||
v[1] = (V >> 8) & 0xFF;
|
||||
v[2] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 16)
|
||||
+ (v[1] << 8)
|
||||
+ (v[2] );
|
||||
}
|
||||
private: uint8_t v[3];
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 4>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 24) & 0xFF;
|
||||
v[1] = (V >> 16) & 0xFF;
|
||||
v[2] = (V >> 8) & 0xFF;
|
||||
v[3] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 24)
|
||||
+ (v[1] << 16)
|
||||
+ (v[2] << 8)
|
||||
+ (v[3] );
|
||||
}
|
||||
private: uint8_t v[4];
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Lazy struct and blob loaders.
|
||||
*/
|
||||
|
||||
/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */
|
||||
template <typename T>
|
||||
struct hb_lazy_loader_t
|
||||
{
|
||||
inline void init (hb_face_t *face_)
|
||||
{
|
||||
face = face_;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
if (instance && instance != &Null(T))
|
||||
{
|
||||
instance->fini();
|
||||
free (instance);
|
||||
}
|
||||
}
|
||||
|
||||
inline const T* get (void) const
|
||||
{
|
||||
retry:
|
||||
T *p = (T *) hb_atomic_ptr_get (&instance);
|
||||
if (unlikely (!p))
|
||||
{
|
||||
p = (T *) calloc (1, sizeof (T));
|
||||
if (unlikely (!p))
|
||||
p = const_cast<T *> (&Null(T));
|
||||
else
|
||||
p->init (face);
|
||||
if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p)))
|
||||
{
|
||||
if (p != &Null(T))
|
||||
p->fini ();
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline const T* operator-> (void) const
|
||||
{
|
||||
return get ();
|
||||
}
|
||||
|
||||
private:
|
||||
hb_face_t *face;
|
||||
mutable T *instance;
|
||||
};
|
||||
|
||||
/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */
|
||||
template <typename T>
|
||||
struct hb_table_lazy_loader_t
|
||||
{
|
||||
inline void init (hb_face_t *face_)
|
||||
{
|
||||
face = face_;
|
||||
blob = nullptr;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
|
||||
inline hb_blob_t* get_blob (void) const
|
||||
{
|
||||
retry:
|
||||
hb_blob_t *b = (hb_blob_t *) hb_atomic_ptr_get (&blob);
|
||||
if (unlikely (!b))
|
||||
{
|
||||
b = OT::hb_sanitize_context_t().reference_table<T> (face);
|
||||
if (!hb_atomic_ptr_cmpexch (&blob, nullptr, b))
|
||||
{
|
||||
hb_blob_destroy (b);
|
||||
goto retry;
|
||||
}
|
||||
blob = b;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
inline const T* get (void) const
|
||||
{
|
||||
hb_blob_t *b = get_blob ();
|
||||
return b->as<T> ();
|
||||
}
|
||||
|
||||
inline const T* operator-> (void) const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
private:
|
||||
hb_face_t *face;
|
||||
mutable hb_blob_t *blob;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace OT */
|
||||
|
||||
|
||||
#endif /* HB_MACHINERY_PRIVATE_HH */
|
||||
@@ -28,7 +28,6 @@
|
||||
#define HB_MAP_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
|
||||
template <typename T>
|
||||
@@ -89,7 +88,7 @@ struct hb_map_t
|
||||
{
|
||||
if (unlikely (!successful)) return false;
|
||||
|
||||
unsigned int power = _hb_bit_storage (population * 2 + 8);
|
||||
unsigned int power = hb_bit_storage (population * 2 + 8);
|
||||
unsigned int new_size = 1u << power;
|
||||
item_t *new_items = (item_t *) malloc ((size_t) new_size * sizeof (item_t));
|
||||
if (unlikely (!new_items))
|
||||
|
||||
@@ -33,8 +33,6 @@
|
||||
#define HB_OBJECT_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
|
||||
#include "hb-atomic-private.hh"
|
||||
#include "hb-mutex-private.hh"
|
||||
|
||||
@@ -96,7 +94,7 @@ struct hb_user_data_array_t
|
||||
struct hb_object_header_t
|
||||
{
|
||||
hb_reference_count_t ref_count;
|
||||
hb_user_data_array_t *user_data;
|
||||
mutable hb_user_data_array_t *user_data;
|
||||
|
||||
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INIT, nullptr}
|
||||
|
||||
|
||||
+196
-2
@@ -286,6 +286,197 @@ struct TTCHeader
|
||||
} u;
|
||||
};
|
||||
|
||||
/*
|
||||
* Mac Resource Fork
|
||||
*/
|
||||
|
||||
struct ResourceRefItem
|
||||
{
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
// actual data sanitization is done on ResourceForkHeader sanitizer
|
||||
return_trace (likely (c->check_struct (this)));
|
||||
}
|
||||
|
||||
HBINT16 id; /* Resource ID, is really should be signed? */
|
||||
HBINT16 nameOffset; /* Offset from beginning of resource name list
|
||||
* to resource name, minus means there is no */
|
||||
HBUINT8 attr; /* Resource attributes */
|
||||
HBUINT24 dataOffset; /* Offset from beginning of resource data to
|
||||
* data for this resource */
|
||||
HBUINT32 reserved; /* Reserved for handle to resource */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (12);
|
||||
};
|
||||
|
||||
struct ResourceTypeItem
|
||||
{
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
// RefList sanitization is done on ResourceMap sanitizer
|
||||
return_trace (likely (c->check_struct (this)));
|
||||
}
|
||||
|
||||
inline unsigned int get_resource_count () const
|
||||
{
|
||||
return numRes + 1;
|
||||
}
|
||||
|
||||
inline bool is_sfnt () const
|
||||
{
|
||||
return type == HB_TAG ('s','f','n','t');
|
||||
}
|
||||
|
||||
inline const ResourceRefItem& get_ref_item (const void *base,
|
||||
unsigned int i) const
|
||||
{
|
||||
return (base+refList)[i];
|
||||
}
|
||||
|
||||
protected:
|
||||
Tag type; /* Resource type */
|
||||
HBUINT16 numRes; /* Number of resource this type in map minus 1 */
|
||||
OffsetTo<UnsizedArrayOf<ResourceRefItem> >
|
||||
refList; /* Offset from beginning of resource type list
|
||||
* to reference list for this type */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (8);
|
||||
};
|
||||
|
||||
struct ResourceMap
|
||||
{
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!c->check_struct (this)))
|
||||
return_trace (false);
|
||||
for (unsigned int i = 0; i < get_types_count (); ++i)
|
||||
{
|
||||
const ResourceTypeItem& type = get_type (i);
|
||||
if (unlikely (!type.sanitize (c)))
|
||||
return_trace (false);
|
||||
for (unsigned int j = 0; j < type.get_resource_count (); ++j)
|
||||
if (unlikely (!get_ref_item (type, j).sanitize (c)))
|
||||
return_trace (false);
|
||||
}
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
inline const ResourceTypeItem& get_type (unsigned int i) const
|
||||
{
|
||||
// Why offset from the second byte of the object? I'm not sure
|
||||
return ((&reserved[2])+typeList)[i];
|
||||
}
|
||||
|
||||
inline unsigned int get_types_count () const
|
||||
{
|
||||
return nTypes + 1;
|
||||
}
|
||||
|
||||
inline const ResourceRefItem &get_ref_item (const ResourceTypeItem &type,
|
||||
unsigned int i) const
|
||||
{
|
||||
return type.get_ref_item (&(this+typeList), i);
|
||||
}
|
||||
|
||||
inline const PString& get_name (const ResourceRefItem &item,
|
||||
unsigned int i) const
|
||||
{
|
||||
if (item.nameOffset == -1)
|
||||
return Null (PString);
|
||||
|
||||
return StructAtOffset<PString> (this, nameList + item.nameOffset);
|
||||
}
|
||||
|
||||
protected:
|
||||
HBUINT8 reserved[16]; /* Reserved for copy of resource header */
|
||||
LOffsetTo<ResourceMap>
|
||||
reserved1; /* Reserved for handle to next resource map */
|
||||
HBUINT16 reserved2; /* Reserved for file reference number */
|
||||
HBUINT16 attr; /* Resource fork attribute */
|
||||
OffsetTo<UnsizedArrayOf<ResourceTypeItem> >
|
||||
typeList; /* Offset from beginning of map to
|
||||
* resource type list */
|
||||
HBUINT16 nameList; /* Offset from beginning of map to
|
||||
* resource name list */
|
||||
HBUINT16 nTypes; /* Number of types in the map minus 1 */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (30);
|
||||
};
|
||||
|
||||
struct ResourceForkHeader
|
||||
{
|
||||
inline unsigned int get_face_count () const
|
||||
{
|
||||
const ResourceMap &resource_map = this+map;
|
||||
for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
|
||||
{
|
||||
const ResourceTypeItem& type = resource_map.get_type (i);
|
||||
if (type.is_sfnt ())
|
||||
return type.get_resource_count ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const LArrayOf<HBUINT8>& get_data (const ResourceTypeItem& type,
|
||||
unsigned int idx) const
|
||||
{
|
||||
const ResourceMap &resource_map = this+map;
|
||||
unsigned int offset = dataOffset;
|
||||
offset += resource_map.get_ref_item (type, idx).dataOffset;
|
||||
return StructAtOffset<LArrayOf<HBUINT8> > (this, offset);
|
||||
}
|
||||
|
||||
inline const OpenTypeFontFace& get_face (unsigned int idx) const
|
||||
{
|
||||
const ResourceMap &resource_map = this+map;
|
||||
for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
|
||||
{
|
||||
const ResourceTypeItem& type = resource_map.get_type (i);
|
||||
if (type.is_sfnt () && idx < type.get_resource_count ())
|
||||
return (OpenTypeFontFace&) get_data (type, idx).arrayZ;
|
||||
}
|
||||
return Null (OpenTypeFontFace);
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!c->check_struct (this)))
|
||||
return_trace (false);
|
||||
|
||||
const ResourceMap &resource_map = this+map;
|
||||
if (unlikely (!resource_map.sanitize (c)))
|
||||
return_trace (false);
|
||||
|
||||
for (unsigned int i = 0; i < resource_map.get_types_count (); ++i)
|
||||
{
|
||||
const ResourceTypeItem& type = resource_map.get_type (i);
|
||||
for (unsigned int j = 0; j < type.get_resource_count (); ++j)
|
||||
{
|
||||
const LArrayOf<HBUINT8>& data = get_data (type, j);
|
||||
if (unlikely (!(data.sanitize (c) &&
|
||||
((OpenTypeFontFace&) data.arrayZ).sanitize (c))))
|
||||
return_trace (false);
|
||||
}
|
||||
}
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
protected:
|
||||
HBUINT32 dataOffset; /* Offset from beginning of resource fork
|
||||
* to resource data */
|
||||
LOffsetTo<ResourceMap>
|
||||
map; /* Offset from beginning of resource fork
|
||||
* to resource map */
|
||||
HBUINT32 dataLen; /* Length of resource data */
|
||||
HBUINT32 mapLen; /* Length of resource map */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (16);
|
||||
};
|
||||
|
||||
/*
|
||||
* OpenType Font File
|
||||
@@ -293,12 +484,11 @@ struct TTCHeader
|
||||
|
||||
struct OpenTypeFontFile
|
||||
{
|
||||
static const hb_tag_t tableTag = HB_TAG ('_','_','_','_'); /* Sanitizer needs this. */
|
||||
|
||||
enum {
|
||||
CFFTag = HB_TAG ('O','T','T','O'), /* OpenType with Postscript outlines */
|
||||
TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ), /* OpenType with TrueType outlines */
|
||||
TTCTag = HB_TAG ('t','t','c','f'), /* TrueType Collection */
|
||||
DFontTag = HB_TAG ( 0 , 0 , 1 , 0 ), /* DFont Mac Resource Fork */
|
||||
TrueTag = HB_TAG ('t','r','u','e'), /* Obsolete Apple TrueType */
|
||||
Typ1Tag = HB_TAG ('t','y','p','1') /* Obsolete Apple Type1 font in SFNT container */
|
||||
};
|
||||
@@ -313,6 +503,7 @@ struct OpenTypeFontFile
|
||||
case Typ1Tag:
|
||||
case TrueTypeTag: return 1;
|
||||
case TTCTag: return u.ttcHeader.get_face_count ();
|
||||
// case DFontTag: return u.rfHeader.get_face_count ();
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -327,6 +518,7 @@ struct OpenTypeFontFile
|
||||
case Typ1Tag:
|
||||
case TrueTypeTag: return u.fontFace;
|
||||
case TTCTag: return u.ttcHeader.get_face (i);
|
||||
// case DFontTag: return u.rfHeader.get_face (i);
|
||||
default: return Null(OpenTypeFontFace);
|
||||
}
|
||||
}
|
||||
@@ -353,6 +545,7 @@ struct OpenTypeFontFile
|
||||
case Typ1Tag:
|
||||
case TrueTypeTag: return_trace (u.fontFace.sanitize (c));
|
||||
case TTCTag: return_trace (u.ttcHeader.sanitize (c));
|
||||
// case DFontTag: return_trace (u.rfHeader.sanitize (c));
|
||||
default: return_trace (true);
|
||||
}
|
||||
}
|
||||
@@ -362,6 +555,7 @@ struct OpenTypeFontFile
|
||||
Tag tag; /* 4-byte identifier. */
|
||||
OpenTypeFontFace fontFace;
|
||||
TTCHeader ttcHeader;
|
||||
ResourceForkHeader rfHeader;
|
||||
} u;
|
||||
public:
|
||||
DEFINE_SIZE_UNION (4, tag);
|
||||
|
||||
+5
-654
@@ -30,487 +30,14 @@
|
||||
#define HB_OPEN_TYPE_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-blob-private.hh"
|
||||
#include "hb-face-private.hh"
|
||||
#include "hb-machinery-private.hh"
|
||||
|
||||
|
||||
namespace OT {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Casts
|
||||
*/
|
||||
|
||||
/* Cast to struct T, reference to reference */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type& CastR(const TObject &X)
|
||||
{ return reinterpret_cast<const Type&> (X); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type& CastR(TObject &X)
|
||||
{ return reinterpret_cast<Type&> (X); }
|
||||
|
||||
/* Cast to struct T, pointer to pointer */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type* CastP(const TObject *X)
|
||||
{ return reinterpret_cast<const Type*> (X); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type* CastP(TObject *X)
|
||||
{ return reinterpret_cast<Type*> (X); }
|
||||
|
||||
/* StructAtOffset<T>(P,Ofs) returns the struct T& that is placed at memory
|
||||
* location pointed to by P plus Ofs bytes. */
|
||||
template<typename Type>
|
||||
static inline const Type& StructAtOffset(const void *P, unsigned int offset)
|
||||
{ return * reinterpret_cast<const Type*> ((const char *) P + offset); }
|
||||
template<typename Type>
|
||||
static inline Type& StructAtOffset(void *P, unsigned int offset)
|
||||
{ return * reinterpret_cast<Type*> ((char *) P + offset); }
|
||||
|
||||
/* StructAfter<T>(X) returns the struct T& that is placed after X.
|
||||
* Works with X of variable size also. X must implement get_size() */
|
||||
template<typename Type, typename TObject>
|
||||
static inline const Type& StructAfter(const TObject &X)
|
||||
{ return StructAtOffset<Type>(&X, X.get_size()); }
|
||||
template<typename Type, typename TObject>
|
||||
static inline Type& StructAfter(TObject &X)
|
||||
{ return StructAtOffset<Type>(&X, X.get_size()); }
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Size checking
|
||||
*/
|
||||
|
||||
/* Check _assertion in a method environment */
|
||||
#define _DEFINE_INSTANCE_ASSERTION1(_line, _assertion) \
|
||||
inline void _instance_assertion_on_line_##_line (void) const \
|
||||
{ \
|
||||
static_assert ((_assertion), ""); \
|
||||
ASSERT_INSTANCE_POD (*this); /* Make sure it's POD. */ \
|
||||
}
|
||||
# define _DEFINE_INSTANCE_ASSERTION0(_line, _assertion) _DEFINE_INSTANCE_ASSERTION1 (_line, _assertion)
|
||||
# define DEFINE_INSTANCE_ASSERTION(_assertion) _DEFINE_INSTANCE_ASSERTION0 (__LINE__, _assertion)
|
||||
|
||||
/* Check that _code compiles in a method environment */
|
||||
#define _DEFINE_COMPILES_ASSERTION1(_line, _code) \
|
||||
inline void _compiles_assertion_on_line_##_line (void) const \
|
||||
{ _code; }
|
||||
# define _DEFINE_COMPILES_ASSERTION0(_line, _code) _DEFINE_COMPILES_ASSERTION1 (_line, _code)
|
||||
# define DEFINE_COMPILES_ASSERTION(_code) _DEFINE_COMPILES_ASSERTION0 (__LINE__, _code)
|
||||
|
||||
|
||||
#define DEFINE_SIZE_STATIC(size) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size)); \
|
||||
static const unsigned int static_size = (size); \
|
||||
static const unsigned int min_size = (size); \
|
||||
inline unsigned int get_size (void) const { return (size); }
|
||||
|
||||
#define DEFINE_SIZE_UNION(size, _member) \
|
||||
DEFINE_INSTANCE_ASSERTION (0*sizeof(this->u._member.static_size) + sizeof(this->u._member) == (size)); \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_MIN(size) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) >= (size)); \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_ARRAY(size, array) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (array[0])); \
|
||||
DEFINE_COMPILES_ASSERTION ((void) array[0].static_size) \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
#define DEFINE_SIZE_ARRAY2(size, array1, array2) \
|
||||
DEFINE_INSTANCE_ASSERTION (sizeof (*this) == (size) + sizeof (this->array1[0]) + sizeof (this->array2[0])); \
|
||||
DEFINE_COMPILES_ASSERTION ((void) array1[0].static_size; (void) array2[0].static_size) \
|
||||
static const unsigned int min_size = (size)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Dispatch
|
||||
*/
|
||||
|
||||
template <typename Context, typename Return, unsigned int MaxDebugDepth>
|
||||
struct hb_dispatch_context_t
|
||||
{
|
||||
static const unsigned int max_debug_depth = MaxDebugDepth;
|
||||
typedef Return return_t;
|
||||
template <typename T, typename F>
|
||||
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
|
||||
*/
|
||||
|
||||
/* This limits sanitizing time on really broken fonts. */
|
||||
#ifndef HB_SANITIZE_MAX_EDITS
|
||||
#define HB_SANITIZE_MAX_EDITS 32
|
||||
#endif
|
||||
#ifndef HB_SANITIZE_MAX_OPS_FACTOR
|
||||
#define HB_SANITIZE_MAX_OPS_FACTOR 8
|
||||
#endif
|
||||
#ifndef HB_SANITIZE_MAX_OPS_MIN
|
||||
#define HB_SANITIZE_MAX_OPS_MIN 16384
|
||||
#endif
|
||||
|
||||
struct hb_sanitize_context_t :
|
||||
hb_dispatch_context_t<hb_sanitize_context_t, bool, HB_DEBUG_SANITIZE>
|
||||
{
|
||||
inline hb_sanitize_context_t (void) :
|
||||
debug_depth (0),
|
||||
start (nullptr), end (nullptr),
|
||||
writable (false), edit_count (0), max_ops (0),
|
||||
blob (nullptr),
|
||||
num_glyphs (0) {}
|
||||
|
||||
inline const char *get_name (void) { return "SANITIZE"; }
|
||||
template <typename T, typename F>
|
||||
inline bool may_dispatch (const T *obj, const F *format)
|
||||
{ return format->sanitize (this); }
|
||||
template <typename T>
|
||||
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)
|
||||
{
|
||||
this->blob = hb_blob_reference (b);
|
||||
this->writable = false;
|
||||
}
|
||||
|
||||
inline void start_processing (void)
|
||||
{
|
||||
this->start = hb_blob_get_data (this->blob, nullptr);
|
||||
this->end = this->start + this->blob->length;
|
||||
assert (this->start <= this->end); /* Must not overflow. */
|
||||
this->max_ops = MAX ((unsigned int) (this->end - this->start) * HB_SANITIZE_MAX_OPS_FACTOR,
|
||||
(unsigned) HB_SANITIZE_MAX_OPS_MIN);
|
||||
this->edit_count = 0;
|
||||
this->debug_depth = 0;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, start, 0, +1,
|
||||
"start [%p..%p] (%lu bytes)",
|
||||
this->start, this->end,
|
||||
(unsigned long) (this->end - this->start));
|
||||
}
|
||||
|
||||
inline void end_processing (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->start, 0, -1,
|
||||
"end [%p..%p] %u edit requests",
|
||||
this->start, this->end, this->edit_count);
|
||||
|
||||
hb_blob_destroy (this->blob);
|
||||
this->blob = nullptr;
|
||||
this->start = this->end = nullptr;
|
||||
}
|
||||
|
||||
inline bool check_range (const void *base, unsigned int len) const
|
||||
{
|
||||
const char *p = (const char *) base;
|
||||
bool ok = this->max_ops-- > 0 &&
|
||||
this->start <= p &&
|
||||
p <= this->end &&
|
||||
(unsigned int) (this->end - p) >= len;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"check_range [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
ok ? "OK" : "OUT-OF-RANGE");
|
||||
|
||||
return likely (ok);
|
||||
}
|
||||
|
||||
inline bool check_array (const void *base, unsigned int record_size, unsigned int len) const
|
||||
{
|
||||
const char *p = (const char *) base;
|
||||
bool overflows = _hb_unsigned_int_mul_overflows (len, record_size);
|
||||
unsigned int array_size = record_size * len;
|
||||
bool ok = !overflows && this->check_range (base, array_size);
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"check_array [%p..%p] (%d*%d=%d bytes) in [%p..%p] -> %s",
|
||||
p, p + (record_size * len), record_size, len, (unsigned int) array_size,
|
||||
this->start, this->end,
|
||||
overflows ? "OVERFLOWS" : ok ? "OK" : "OUT-OF-RANGE");
|
||||
|
||||
return likely (ok);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline bool check_struct (const Type *obj) const
|
||||
{
|
||||
return likely (this->check_range (obj, obj->min_size));
|
||||
}
|
||||
|
||||
inline bool may_edit (const void *base, unsigned int len)
|
||||
{
|
||||
if (this->edit_count >= HB_SANITIZE_MAX_EDITS)
|
||||
return false;
|
||||
|
||||
const char *p = (const char *) base;
|
||||
this->edit_count++;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
|
||||
"may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
this->edit_count,
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
this->writable ? "GRANTED" : "DENIED");
|
||||
|
||||
return this->writable;
|
||||
}
|
||||
|
||||
template <typename Type, typename ValueType>
|
||||
inline bool try_set (const Type *obj, const ValueType &v) {
|
||||
if (this->may_edit (obj, obj->static_size)) {
|
||||
const_cast<Type *> (obj)->set (v);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mutable unsigned int debug_depth;
|
||||
const char *start, *end;
|
||||
bool writable;
|
||||
unsigned int edit_count;
|
||||
mutable int max_ops;
|
||||
hb_blob_t *blob;
|
||||
unsigned int num_glyphs;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Template to sanitize an object. */
|
||||
template <typename Type>
|
||||
struct Sanitizer
|
||||
{
|
||||
inline Sanitizer (void) {}
|
||||
|
||||
inline hb_blob_t *sanitize (hb_blob_t *blob) {
|
||||
bool sane;
|
||||
|
||||
/* TODO is_sane() stuff */
|
||||
|
||||
c->init (blob);
|
||||
|
||||
retry:
|
||||
DEBUG_MSG_FUNC (SANITIZE, c->start, "start");
|
||||
|
||||
c->start_processing ();
|
||||
|
||||
if (unlikely (!c->start)) {
|
||||
c->end_processing ();
|
||||
return blob;
|
||||
}
|
||||
|
||||
Type *t = CastP<Type> (const_cast<char *> (c->start));
|
||||
|
||||
sane = t->sanitize (c);
|
||||
if (sane) {
|
||||
if (c->edit_count) {
|
||||
DEBUG_MSG_FUNC (SANITIZE, c->start, "passed first round with %d edits; going for second round", c->edit_count);
|
||||
|
||||
/* sanitize again to ensure no toe-stepping */
|
||||
c->edit_count = 0;
|
||||
sane = t->sanitize (c);
|
||||
if (c->edit_count) {
|
||||
DEBUG_MSG_FUNC (SANITIZE, c->start, "requested %d edits in second round; FAILLING", c->edit_count);
|
||||
sane = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsigned int edit_count = c->edit_count;
|
||||
if (edit_count && !c->writable) {
|
||||
c->start = hb_blob_get_data_writable (blob, nullptr);
|
||||
c->end = c->start + blob->length;
|
||||
|
||||
if (c->start) {
|
||||
c->writable = true;
|
||||
/* ok, we made it writable by relocating. try again */
|
||||
DEBUG_MSG_FUNC (SANITIZE, c->start, "retry");
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c->end_processing ();
|
||||
|
||||
DEBUG_MSG_FUNC (SANITIZE, c->start, sane ? "PASSED" : "FAILED");
|
||||
if (sane)
|
||||
{
|
||||
blob->lock ();
|
||||
return blob;
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_blob_destroy (blob);
|
||||
return hb_blob_get_empty ();
|
||||
}
|
||||
}
|
||||
|
||||
inline void set_num_glyphs (unsigned int num_glyphs) { c->num_glyphs = num_glyphs; }
|
||||
|
||||
private:
|
||||
hb_sanitize_context_t c[1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Serialize
|
||||
*/
|
||||
|
||||
|
||||
struct hb_serialize_context_t
|
||||
{
|
||||
inline hb_serialize_context_t (void *start_, unsigned int size)
|
||||
{
|
||||
this->start = (char *) start_;
|
||||
this->end = this->start + size;
|
||||
|
||||
this->ran_out_of_room = false;
|
||||
this->head = this->start;
|
||||
this->debug_depth = 0;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *start_serialize (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, +1,
|
||||
"start [%p..%p] (%lu bytes)",
|
||||
this->start, this->end,
|
||||
(unsigned long) (this->end - this->start));
|
||||
|
||||
return start_embed<Type> ();
|
||||
}
|
||||
|
||||
inline void end_serialize (void)
|
||||
{
|
||||
DEBUG_MSG_LEVEL (SERIALIZE, this->start, 0, -1,
|
||||
"end [%p..%p] serialized %d bytes; %s",
|
||||
this->start, this->end,
|
||||
(int) (this->head - this->start),
|
||||
this->ran_out_of_room ? "RAN OUT OF ROOM" : "did not ran out of room");
|
||||
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *copy (void)
|
||||
{
|
||||
assert (!this->ran_out_of_room);
|
||||
unsigned int len = this->head - this->start;
|
||||
void *p = malloc (len);
|
||||
if (p)
|
||||
memcpy (p, this->start, len);
|
||||
return reinterpret_cast<Type *> (p);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *allocate_size (unsigned int size)
|
||||
{
|
||||
if (unlikely (this->ran_out_of_room || this->end - this->head < ptrdiff_t (size))) {
|
||||
this->ran_out_of_room = true;
|
||||
return nullptr;
|
||||
}
|
||||
memset (this->head, 0, size);
|
||||
char *ret = this->head;
|
||||
this->head += size;
|
||||
return reinterpret_cast<Type *> (ret);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *allocate_min (void)
|
||||
{
|
||||
return this->allocate_size<Type> (Type::min_size);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *start_embed (void)
|
||||
{
|
||||
Type *ret = reinterpret_cast<Type *> (this->head);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *embed (const Type &obj)
|
||||
{
|
||||
unsigned int size = obj.get_size ();
|
||||
Type *ret = this->allocate_size<Type> (size);
|
||||
if (unlikely (!ret)) return nullptr;
|
||||
memcpy (ret, obj, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *extend_min (Type &obj)
|
||||
{
|
||||
unsigned int size = obj.min_size;
|
||||
assert (this->start <= (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head);
|
||||
if (unlikely (!this->allocate_size<Type> (((char *) &obj) + size - this->head))) return nullptr;
|
||||
return reinterpret_cast<Type *> (&obj);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
inline Type *extend (Type &obj)
|
||||
{
|
||||
unsigned int size = obj.get_size ();
|
||||
assert (this->start < (char *) &obj && (char *) &obj <= this->head && (char *) &obj + size >= this->head);
|
||||
if (unlikely (!this->allocate_size<Type> (((char *) &obj) + size - this->head))) return nullptr;
|
||||
return reinterpret_cast<Type *> (&obj);
|
||||
}
|
||||
|
||||
inline void truncate (void *new_head)
|
||||
{
|
||||
assert (this->start < new_head && new_head <= this->head);
|
||||
this->head = (char *) new_head;
|
||||
}
|
||||
|
||||
unsigned int debug_depth;
|
||||
char *start, *end, *head;
|
||||
bool ran_out_of_room;
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct Supplier
|
||||
{
|
||||
inline Supplier (const Type *array, unsigned int len_, unsigned int stride_=sizeof(Type))
|
||||
{
|
||||
head = array;
|
||||
len = len_;
|
||||
stride = stride_;
|
||||
}
|
||||
inline const Type operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len)) return Type ();
|
||||
return * (const Type *) (const void *) ((const char *) head + stride * i);
|
||||
}
|
||||
|
||||
inline Supplier<Type> & operator += (unsigned int count)
|
||||
{
|
||||
if (unlikely (count > len))
|
||||
count = len;
|
||||
len -= count;
|
||||
head = (const Type *) (const void *) ((const char *) head + stride * count);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
inline Supplier (const Supplier<Type> &); /* Disallow copy */
|
||||
inline Supplier<Type>& operator= (const Supplier<Type> &); /* Disallow copy */
|
||||
|
||||
unsigned int len;
|
||||
unsigned int stride;
|
||||
const Type *head;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* The OpenType Font File: Data Types
|
||||
@@ -524,78 +51,6 @@ struct Supplier
|
||||
* Int types
|
||||
*/
|
||||
|
||||
|
||||
template <typename Type, int Bytes> struct BEInt;
|
||||
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 1>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v = V;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return v;
|
||||
}
|
||||
private: uint8_t v;
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 2>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 8) & 0xFF;
|
||||
v[1] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 8)
|
||||
+ (v[1] );
|
||||
}
|
||||
private: uint8_t v[2];
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 3>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 16) & 0xFF;
|
||||
v[1] = (V >> 8) & 0xFF;
|
||||
v[2] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 16)
|
||||
+ (v[1] << 8)
|
||||
+ (v[2] );
|
||||
}
|
||||
private: uint8_t v[3];
|
||||
};
|
||||
template <typename Type>
|
||||
struct BEInt<Type, 4>
|
||||
{
|
||||
public:
|
||||
inline void set (Type V)
|
||||
{
|
||||
v[0] = (V >> 24) & 0xFF;
|
||||
v[1] = (V >> 16) & 0xFF;
|
||||
v[2] = (V >> 8) & 0xFF;
|
||||
v[3] = (V ) & 0xFF;
|
||||
}
|
||||
inline operator Type (void) const
|
||||
{
|
||||
return (v[0] << 24)
|
||||
+ (v[1] << 16)
|
||||
+ (v[2] << 8)
|
||||
+ (v[3] );
|
||||
}
|
||||
private: uint8_t v[4];
|
||||
};
|
||||
|
||||
/* Integer types in big-endian order and no alignment requirement */
|
||||
template <typename Type, unsigned int Size>
|
||||
struct IntType
|
||||
@@ -766,7 +221,6 @@ struct FixedVersion
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Template subclasses of Offset that do the dereferencing.
|
||||
* Use: (base+offset)
|
||||
@@ -832,7 +286,6 @@ static inline Type& operator + (Base &base, OffsetTo<Type, OffsetType> &offset)
|
||||
* Array Types
|
||||
*/
|
||||
|
||||
|
||||
/* TODO Use it in ArrayOf, HeadlessArrayOf, and other places around the code base?? */
|
||||
template <typename Type>
|
||||
struct UnsizedArrayOf
|
||||
@@ -914,7 +367,6 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType>
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* An array with a number of elements. */
|
||||
template <typename Type, typename LenType=HBUINT16>
|
||||
struct ArrayOf
|
||||
@@ -1033,6 +485,7 @@ struct ArrayOf
|
||||
DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ);
|
||||
};
|
||||
template <typename Type> struct LArrayOf : ArrayOf<Type, HBUINT32> {};
|
||||
typedef ArrayOf<HBUINT8, HBUINT8> PString;
|
||||
|
||||
/* Array of Offset's */
|
||||
template <typename Type, typename OffsetType=HBUINT16>
|
||||
@@ -1066,7 +519,6 @@ struct OffsetListOf : OffsetArrayOf<Type>
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* An array starting at second element. */
|
||||
template <typename Type, typename LenType=HBUINT16>
|
||||
struct HeadlessArrayOf
|
||||
@@ -1131,10 +583,7 @@ struct HeadlessArrayOf
|
||||
DEFINE_SIZE_ARRAY (sizeof (LenType), arrayZ);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* An array with sorted elements. Supports binary searching.
|
||||
*/
|
||||
/* An array with sorted elements. Supports binary searching. */
|
||||
template <typename Type, typename LenType=HBUINT16>
|
||||
struct SortedArrayOf : ArrayOf<Type, LenType>
|
||||
{
|
||||
@@ -1159,10 +608,7 @@ struct SortedArrayOf : ArrayOf<Type, LenType>
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Binary-search arrays
|
||||
*/
|
||||
|
||||
/* Binary-search arrays */
|
||||
struct BinSearchHeader
|
||||
{
|
||||
inline operator uint32_t (void) const { return len; }
|
||||
@@ -1177,7 +623,7 @@ struct BinSearchHeader
|
||||
{
|
||||
len.set (v);
|
||||
assert (len == v);
|
||||
entrySelector.set (MAX (1u, _hb_bit_storage (v)) - 1);
|
||||
entrySelector.set (MAX (1u, hb_bit_storage (v)) - 1);
|
||||
searchRange.set (16 * (1u << entrySelector));
|
||||
rangeShift.set (v * 16 > searchRange
|
||||
? 16 * v - searchRange
|
||||
@@ -1198,101 +644,6 @@ template <typename Type>
|
||||
struct BinSearchArrayOf : SortedArrayOf<Type, BinSearchHeader> {};
|
||||
|
||||
|
||||
/* Lazy struct and blob loaders. */
|
||||
|
||||
/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */
|
||||
template <typename T>
|
||||
struct hb_lazy_loader_t
|
||||
{
|
||||
inline void init (hb_face_t *face_)
|
||||
{
|
||||
face = face_;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
if (instance && instance != &Null(T))
|
||||
{
|
||||
instance->fini();
|
||||
free (instance);
|
||||
}
|
||||
}
|
||||
|
||||
inline const T* get (void) const
|
||||
{
|
||||
retry:
|
||||
T *p = (T *) hb_atomic_ptr_get (&instance);
|
||||
if (unlikely (!p))
|
||||
{
|
||||
p = (T *) calloc (1, sizeof (T));
|
||||
if (unlikely (!p))
|
||||
p = const_cast<T *> (&Null(T));
|
||||
else
|
||||
p->init (face);
|
||||
if (unlikely (!hb_atomic_ptr_cmpexch (const_cast<T **>(&instance), nullptr, p)))
|
||||
{
|
||||
if (p != &Null(T))
|
||||
p->fini ();
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline const T* operator-> (void) const
|
||||
{
|
||||
return get ();
|
||||
}
|
||||
|
||||
private:
|
||||
hb_face_t *face;
|
||||
T *instance;
|
||||
};
|
||||
|
||||
/* Logic is shared between hb_lazy_loader_t and hb_table_lazy_loader_t */
|
||||
template <typename T>
|
||||
struct hb_table_lazy_loader_t
|
||||
{
|
||||
inline void init (hb_face_t *face_)
|
||||
{
|
||||
face = face_;
|
||||
blob = nullptr;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
|
||||
inline const T* get (void) const
|
||||
{
|
||||
retry:
|
||||
hb_blob_t *blob_ = (hb_blob_t *) hb_atomic_ptr_get (&blob);
|
||||
if (unlikely (!blob_))
|
||||
{
|
||||
blob_ = OT::Sanitizer<T>().sanitize (face->reference_table (T::tableTag));
|
||||
if (!hb_atomic_ptr_cmpexch (&blob, nullptr, blob_))
|
||||
{
|
||||
hb_blob_destroy (blob_);
|
||||
goto retry;
|
||||
}
|
||||
blob = blob_;
|
||||
}
|
||||
return blob_->as<T> ();
|
||||
}
|
||||
|
||||
inline const T* operator-> (void) const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
private:
|
||||
hb_face_t *face;
|
||||
mutable hb_blob_t *blob;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace OT */
|
||||
|
||||
|
||||
|
||||
+35
-35
@@ -89,7 +89,7 @@ struct CmapSubtableFormat4
|
||||
this->length.set (get_sub_table_size (segments));
|
||||
|
||||
this->segCountX2.set (segments.len * 2);
|
||||
this->entrySelector.set (MAX (1u, _hb_bit_storage (segments.len)) - 1);
|
||||
this->entrySelector.set (MAX (1u, hb_bit_storage (segments.len)) - 1);
|
||||
this->searchRange.set (2 * (1u << this->entrySelector));
|
||||
this->rangeShift.set (segments.len * 2 > this->searchRange
|
||||
? 2 * segments.len - this->searchRange
|
||||
@@ -800,37 +800,37 @@ struct cmap
|
||||
{
|
||||
hb_serialize_context_t c (dest, dest_sz);
|
||||
|
||||
OT::cmap *cmap = c.start_serialize<OT::cmap> ();
|
||||
if (unlikely (!c.extend_min (*cmap)))
|
||||
cmap *table = c.start_serialize<cmap> ();
|
||||
if (unlikely (!c.extend_min (*table)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
cmap->version.set (0);
|
||||
table->version.set (0);
|
||||
|
||||
if (unlikely (!cmap->encodingRecord.serialize (&c, /* numTables */ 3)))
|
||||
if (unlikely (!table->encodingRecord.serialize (&c, /* numTables */ 3)))
|
||||
return false;
|
||||
|
||||
// TODO(grieger): Convert the below to a for loop
|
||||
|
||||
// Format 4, Plat 0 Encoding Record
|
||||
EncodingRecord &format4_plat0_rec = cmap->encodingRecord[0];
|
||||
EncodingRecord &format4_plat0_rec = table->encodingRecord[0];
|
||||
format4_plat0_rec.platformID.set (0); // Unicode
|
||||
format4_plat0_rec.encodingID.set (3);
|
||||
|
||||
// Format 4, Plat 3 Encoding Record
|
||||
EncodingRecord &format4_plat3_rec = cmap->encodingRecord[1];
|
||||
EncodingRecord &format4_plat3_rec = table->encodingRecord[1];
|
||||
format4_plat3_rec.platformID.set (3); // Windows
|
||||
format4_plat3_rec.encodingID.set (1); // Unicode BMP
|
||||
|
||||
// Format 12 Encoding Record
|
||||
EncodingRecord &format12_rec = cmap->encodingRecord[2];
|
||||
EncodingRecord &format12_rec = table->encodingRecord[2];
|
||||
format12_rec.platformID.set (3); // Windows
|
||||
format12_rec.encodingID.set (10); // Unicode UCS-4
|
||||
|
||||
// Write out format 4 sub table
|
||||
{
|
||||
CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, cmap);
|
||||
CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, table);
|
||||
format4_plat3_rec.subtable.set (format4_plat0_rec.subtable);
|
||||
subtable.u.format.set (4);
|
||||
|
||||
@@ -841,7 +841,7 @@ struct cmap
|
||||
|
||||
// Write out format 12 sub table.
|
||||
{
|
||||
CmapSubtable &subtable = format12_rec.subtable.serialize (&c, cmap);
|
||||
CmapSubtable &subtable = format12_rec.subtable.serialize (&c, table);
|
||||
subtable.u.format.set (12);
|
||||
|
||||
CmapSubtableFormat12 &format12 = subtable.u.format12;
|
||||
@@ -894,57 +894,57 @@ struct cmap
|
||||
{
|
||||
inline void init (hb_face_t *face)
|
||||
{
|
||||
this->blob = OT::Sanitizer<OT::cmap>().sanitize (face->reference_table (HB_OT_TAG_cmap));
|
||||
const OT::cmap *cmap = this->blob->as<OT::cmap> ();
|
||||
const OT::CmapSubtable *subtable = nullptr;
|
||||
const OT::CmapSubtableFormat14 *subtable_uvs = nullptr;
|
||||
this->blob = hb_sanitize_context_t().reference_table<cmap> (face);
|
||||
const cmap *table = this->blob->as<cmap> ();
|
||||
const CmapSubtable *subtable = nullptr;
|
||||
const CmapSubtableFormat14 *subtable_uvs = nullptr;
|
||||
|
||||
bool symbol = false;
|
||||
/* 32-bit subtables. */
|
||||
if (!subtable) subtable = cmap->find_subtable (3, 10);
|
||||
if (!subtable) subtable = cmap->find_subtable (0, 6);
|
||||
if (!subtable) subtable = cmap->find_subtable (0, 4);
|
||||
if (!subtable) subtable = table->find_subtable (3, 10);
|
||||
if (!subtable) subtable = table->find_subtable (0, 6);
|
||||
if (!subtable) subtable = table->find_subtable (0, 4);
|
||||
/* 16-bit subtables. */
|
||||
if (!subtable) subtable = cmap->find_subtable (3, 1);
|
||||
if (!subtable) subtable = cmap->find_subtable (0, 3);
|
||||
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 = table->find_subtable (3, 1);
|
||||
if (!subtable) subtable = table->find_subtable (0, 3);
|
||||
if (!subtable) subtable = table->find_subtable (0, 2);
|
||||
if (!subtable) subtable = table->find_subtable (0, 1);
|
||||
if (!subtable) subtable = table->find_subtable (0, 0);
|
||||
if (!subtable)
|
||||
{
|
||||
subtable = cmap->find_subtable (3, 0);
|
||||
subtable = table->find_subtable (3, 0);
|
||||
if (subtable) symbol = true;
|
||||
}
|
||||
/* Meh. */
|
||||
if (!subtable) subtable = &Null(OT::CmapSubtable);
|
||||
if (!subtable) subtable = &Null(CmapSubtable);
|
||||
|
||||
/* UVS subtable. */
|
||||
if (!subtable_uvs)
|
||||
{
|
||||
const OT::CmapSubtable *st = cmap->find_subtable (0, 5);
|
||||
const CmapSubtable *st = table->find_subtable (0, 5);
|
||||
if (st && st->u.format == 14)
|
||||
subtable_uvs = &st->u.format14;
|
||||
}
|
||||
/* Meh. */
|
||||
if (!subtable_uvs) subtable_uvs = &Null(OT::CmapSubtableFormat14);
|
||||
if (!subtable_uvs) subtable_uvs = &Null(CmapSubtableFormat14);
|
||||
|
||||
this->uvs_table = subtable_uvs;
|
||||
|
||||
this->get_glyph_data = subtable;
|
||||
if (unlikely (symbol))
|
||||
{
|
||||
this->get_glyph_func = get_glyph_from_symbol<OT::CmapSubtable>;
|
||||
this->get_glyph_func = get_glyph_from_symbol<CmapSubtable>;
|
||||
this->get_all_codepoints_func = null_get_all_codepoints_func;
|
||||
} else {
|
||||
switch (subtable->u.format) {
|
||||
/* Accelerate format 4 and format 12. */
|
||||
default:
|
||||
this->get_glyph_func = get_glyph_from<OT::CmapSubtable>;
|
||||
this->get_glyph_func = get_glyph_from<CmapSubtable>;
|
||||
this->get_all_codepoints_func = null_get_all_codepoints_func;
|
||||
break;
|
||||
case 12:
|
||||
this->get_glyph_func = get_glyph_from<OT::CmapSubtableFormat12>;
|
||||
this->get_all_codepoints_func = get_all_codepoints_from<OT::CmapSubtableFormat12>;
|
||||
this->get_glyph_func = get_glyph_from<CmapSubtableFormat12>;
|
||||
this->get_all_codepoints_func = get_all_codepoints_from<CmapSubtableFormat12>;
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
@@ -977,9 +977,9 @@ struct cmap
|
||||
variation_selector,
|
||||
glyph))
|
||||
{
|
||||
case OT::GLYPH_VARIANT_NOT_FOUND: return false;
|
||||
case OT::GLYPH_VARIANT_FOUND: return true;
|
||||
case OT::GLYPH_VARIANT_USE_DEFAULT: break;
|
||||
case GLYPH_VARIANT_NOT_FOUND: return false;
|
||||
case GLYPH_VARIANT_FOUND: return true;
|
||||
case GLYPH_VARIANT_USE_DEFAULT: break;
|
||||
}
|
||||
|
||||
return get_nominal_glyph (unicode, glyph);
|
||||
@@ -1046,9 +1046,9 @@ struct cmap
|
||||
const void *get_glyph_data;
|
||||
hb_cmap_get_all_codepoints_func_t get_all_codepoints_func;
|
||||
|
||||
OT::CmapSubtableFormat4::accelerator_t format4_accel;
|
||||
CmapSubtableFormat4::accelerator_t format4_accel;
|
||||
|
||||
const OT::CmapSubtableFormat14 *uvs_table;
|
||||
const CmapSubtableFormat14 *uvs_table;
|
||||
hb_blob_t *blob;
|
||||
};
|
||||
|
||||
|
||||
@@ -394,8 +394,8 @@ struct CBDT
|
||||
{
|
||||
upem = hb_face_get_upem (face);
|
||||
|
||||
cblc_blob = Sanitizer<CBLC>().sanitize (face->reference_table (HB_OT_TAG_CBLC));
|
||||
cbdt_blob = Sanitizer<CBDT>().sanitize (face->reference_table (HB_OT_TAG_CBDT));
|
||||
cblc_blob = hb_sanitize_context_t().reference_table<CBLC> (face);
|
||||
cbdt_blob = hb_sanitize_context_t().reference_table<CBDT> (face);
|
||||
cbdt_len = hb_blob_get_length (cbdt_blob);
|
||||
|
||||
if (hb_blob_get_length (cblc_blob) == 0) {
|
||||
|
||||
@@ -68,7 +68,7 @@ struct SBIXStrike
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (c->check_struct (this) &&
|
||||
imageOffsetsZ.sanitize_shallow (c, c->num_glyphs + 1));
|
||||
imageOffsetsZ.sanitize_shallow (c, c->get_num_glyphs () + 1));
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -96,14 +96,9 @@ struct sbix
|
||||
{
|
||||
inline void init (hb_face_t *face)
|
||||
{
|
||||
num_glyphs = hb_face_get_glyph_count (face);
|
||||
|
||||
OT::Sanitizer<OT::sbix> sanitizer;
|
||||
sanitizer.set_num_glyphs (num_glyphs);
|
||||
sbix_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_sbix));
|
||||
sbix_blob = hb_sanitize_context_t().reference_table<sbix> (face);
|
||||
sbix_len = hb_blob_get_length (sbix_blob);
|
||||
sbix_table = sbix_blob->as<OT::sbix> ();
|
||||
|
||||
sbix_table = sbix_blob->as<sbix> ();
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
@@ -134,7 +129,6 @@ struct sbix
|
||||
|
||||
unsigned int sbix_len;
|
||||
unsigned int num_glyphs;
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
@@ -96,11 +96,9 @@ struct SVG
|
||||
{
|
||||
inline void init (hb_face_t *face)
|
||||
{
|
||||
OT::Sanitizer<OT::SVG> sanitizer;
|
||||
svg_blob = sanitizer.sanitize (face->reference_table (HB_OT_TAG_SVG));
|
||||
svg_blob = hb_sanitize_context_t().reference_table<SVG> (face);
|
||||
svg_len = hb_blob_get_length (svg_blob);
|
||||
svg = svg_blob->as<OT::SVG> ();
|
||||
|
||||
svg = svg_blob->as<SVG> ();
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
|
||||
@@ -103,14 +103,14 @@ struct glyf
|
||||
static bool
|
||||
_add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca)
|
||||
{
|
||||
hb_blob_t *head_blob = OT::Sanitizer<OT::head>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_head));
|
||||
hb_blob_t *head_blob = hb_sanitize_context_t().reference_table<head> (plan->source);
|
||||
hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob);
|
||||
hb_blob_destroy (head_blob);
|
||||
|
||||
if (unlikely (!head_prime_blob))
|
||||
return false;
|
||||
|
||||
OT::head *head_prime = (OT::head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
|
||||
head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
|
||||
head_prime->indexToLocFormat.set (use_short_loca ? 0 : 1);
|
||||
bool success = plan->add_table (HB_OT_TAG_head, head_prime_blob);
|
||||
|
||||
@@ -236,7 +236,7 @@ struct glyf
|
||||
{
|
||||
memset (this, 0, sizeof (accelerator_t));
|
||||
|
||||
hb_blob_t *head_blob = Sanitizer<head>().sanitize (face->reference_table (HB_OT_TAG_head));
|
||||
hb_blob_t *head_blob = hb_sanitize_context_t().reference_table<head> (face);
|
||||
const head *head_table = head_blob->as<head> ();
|
||||
if (head_table == &Null(head) || (unsigned int) head_table->indexToLocFormat > 1 || head_table->glyphDataFormat != 0)
|
||||
{
|
||||
@@ -247,9 +247,9 @@ struct glyf
|
||||
short_offset = 0 == head_table->indexToLocFormat;
|
||||
hb_blob_destroy (head_blob);
|
||||
|
||||
loca_blob = Sanitizer<loca>().sanitize (face->reference_table (HB_OT_TAG_loca));
|
||||
loca_blob = hb_sanitize_context_t().reference_table<loca> (face);
|
||||
loca_table = loca_blob->as<loca> ();
|
||||
glyf_blob = Sanitizer<glyf>().sanitize (face->reference_table (HB_OT_TAG_glyf));
|
||||
glyf_blob = hb_sanitize_context_t().reference_table<glyf> (face);
|
||||
glyf_table = glyf_blob->as<glyf> ();
|
||||
|
||||
num_glyphs = MAX (1u, hb_blob_get_length (loca_blob) / (short_offset ? 2 : 4)) - 1;
|
||||
|
||||
@@ -199,7 +199,7 @@ struct hdmx
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (c->check_struct (this) && version == 0 &&
|
||||
!_hb_unsigned_int_mul_overflows (num_records, size_device_record) &&
|
||||
!hb_unsigned_mul_overflows (num_records, size_device_record) &&
|
||||
size_device_record >= DeviceRecord::min_size &&
|
||||
c->check_range (this, get_size()));
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ struct hmtxvmtx
|
||||
inline bool subset_update_header (hb_subset_plan_t *plan,
|
||||
unsigned int num_hmetrics) const
|
||||
{
|
||||
hb_blob_t *src_blob = OT::Sanitizer<H> ().sanitize (plan->source->reference_table (H::tableTag));
|
||||
hb_blob_t *src_blob = hb_sanitize_context_t().reference_table<H> (plan->source, H::tableTag);
|
||||
hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob);
|
||||
hb_blob_destroy (src_blob);
|
||||
|
||||
@@ -195,7 +195,7 @@ struct hmtxvmtx
|
||||
bool got_font_extents = false;
|
||||
if (T::os2Tag)
|
||||
{
|
||||
hb_blob_t *os2_blob = Sanitizer<os2> ().sanitize (face->reference_table (T::os2Tag));
|
||||
hb_blob_t *os2_blob = hb_sanitize_context_t().reference_table<os2> (face);
|
||||
const os2 *os2_table = os2_blob->as<os2> ();
|
||||
#define USE_TYPO_METRICS (1u<<7)
|
||||
if (0 != (os2_table->fsSelection & USE_TYPO_METRICS))
|
||||
@@ -208,7 +208,7 @@ struct hmtxvmtx
|
||||
hb_blob_destroy (os2_blob);
|
||||
}
|
||||
|
||||
hb_blob_t *_hea_blob = Sanitizer<H> ().sanitize (face->reference_table (H::tableTag));
|
||||
hb_blob_t *_hea_blob = hb_sanitize_context_t().reference_table<H> (face);
|
||||
const H *_hea_table = _hea_blob->as<H> ();
|
||||
num_advances = _hea_table->numberOfLongMetrics;
|
||||
if (!got_font_extents)
|
||||
@@ -222,7 +222,7 @@ struct hmtxvmtx
|
||||
|
||||
has_font_extents = got_font_extents;
|
||||
|
||||
blob = Sanitizer<hmtxvmtx> ().sanitize (face->reference_table (T::tableTag));
|
||||
blob = hb_sanitize_context_t().reference_table<hmtxvmtx> (face, T::tableTag);
|
||||
|
||||
/* Cap num_metrics() and num_advances() based on table length. */
|
||||
unsigned int len = hb_blob_get_length (blob);
|
||||
@@ -240,7 +240,7 @@ struct hmtxvmtx
|
||||
}
|
||||
table = blob->as<hmtxvmtx> ();
|
||||
|
||||
var_blob = Sanitizer<HVARVVAR> ().sanitize (face->reference_table (T::variationsTag));
|
||||
var_blob = hb_sanitize_context_t().reference_table<HVARVVAR> (face, T::variationsTag);
|
||||
var_table = var_blob->as<HVARVVAR> ();
|
||||
}
|
||||
|
||||
|
||||
@@ -362,7 +362,7 @@ struct kern
|
||||
{
|
||||
inline void init (hb_face_t *face)
|
||||
{
|
||||
blob = Sanitizer<kern>().sanitize (face->reference_table (HB_OT_TAG_kern));
|
||||
blob = hb_sanitize_context_t().reference_table<kern> (face);
|
||||
table = blob->as<kern> ();
|
||||
table_length = blob->length;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#define HB_OT_LAYOUT_COMMON_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-ot-layout-private.hh"
|
||||
#include "hb-open-type-private.hh"
|
||||
#include "hb-set-private.hh"
|
||||
@@ -42,6 +41,13 @@
|
||||
#ifndef HB_MAX_CONTEXT_LENGTH
|
||||
#define HB_MAX_CONTEXT_LENGTH 64
|
||||
#endif
|
||||
#ifndef HB_CLOSURE_MAX_STAGES
|
||||
/*
|
||||
* The maximum number of times a lookup can be applied during shaping.
|
||||
* Used to limit the number of iterations of the closure algorithm.
|
||||
*/
|
||||
#define HB_CLOSURE_MAX_STAGES 8
|
||||
#endif
|
||||
|
||||
|
||||
namespace OT {
|
||||
@@ -479,6 +485,20 @@ struct FeatureParams
|
||||
return Null(FeatureParamsSize);
|
||||
}
|
||||
|
||||
inline const FeatureParamsStylisticSet& get_stylistic_set_params (hb_tag_t tag) const
|
||||
{
|
||||
if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */
|
||||
return u.stylisticSet;
|
||||
return Null(FeatureParamsStylisticSet);
|
||||
}
|
||||
|
||||
inline const FeatureParamsCharacterVariants& get_character_variants_params (hb_tag_t tag) const
|
||||
{
|
||||
if ((tag & 0xFFFF0000u) == HB_TAG ('c','v','\0','\0')) /* cvXX */
|
||||
return u.characterVariants;
|
||||
return Null(FeatureParamsCharacterVariants);
|
||||
}
|
||||
|
||||
private:
|
||||
union {
|
||||
FeatureParamsSize size;
|
||||
@@ -541,9 +561,6 @@ struct Feature
|
||||
c->try_set (&featureParams, new_offset) &&
|
||||
!featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE))
|
||||
return_trace (false);
|
||||
|
||||
if (c->edit_count > 1)
|
||||
c->edit_count--; /* This was a "legitimate" edit; don't contribute to error count. */
|
||||
}
|
||||
|
||||
return_trace (true);
|
||||
@@ -598,6 +615,14 @@ struct Lookup
|
||||
inline OffsetArrayOf<SubTableType>& get_subtables (void)
|
||||
{ return CastR<OffsetArrayOf<SubTableType> > (subTable); }
|
||||
|
||||
inline unsigned int get_size (void) const
|
||||
{
|
||||
const HBUINT16 &markFilteringSet = StructAfter<const HBUINT16> (subTable);
|
||||
if (lookupFlag & LookupFlag::UseMarkFilteringSet)
|
||||
return (const char *) &StructAfter<const char> (markFilteringSet) - (const char *) this;
|
||||
return (const char *) &markFilteringSet - (const char *) this;
|
||||
}
|
||||
|
||||
inline unsigned int get_type (void) const { return lookupType; }
|
||||
|
||||
/* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and
|
||||
@@ -640,6 +665,7 @@ struct Lookup
|
||||
if (unlikely (!subTable.serialize (c, num_subtables))) return_trace (false);
|
||||
if (lookupFlag & LookupFlag::UseMarkFilteringSet)
|
||||
{
|
||||
if (unlikely (!c->extend (*this))) return_trace (false);
|
||||
HBUINT16 &markFilteringSet = StructAfter<HBUINT16> (subTable);
|
||||
markFilteringSet.set (lookup_props >> 16);
|
||||
}
|
||||
@@ -832,7 +858,12 @@ struct CoverageFormat2
|
||||
c = &c_;
|
||||
coverage = 0;
|
||||
i = 0;
|
||||
j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0;
|
||||
j = c->rangeRecord.len ? c->rangeRecord[0].start : 0;
|
||||
if (unlikely (c->rangeRecord[0].start > c->rangeRecord[0].end))
|
||||
{
|
||||
/* Broken table. Skip. */
|
||||
i = c->rangeRecord.len;
|
||||
}
|
||||
}
|
||||
inline bool more (void) { return i < c->rangeRecord.len; }
|
||||
inline void next (void)
|
||||
@@ -842,7 +873,14 @@ struct CoverageFormat2
|
||||
i++;
|
||||
if (more ())
|
||||
{
|
||||
hb_codepoint_t old = j;
|
||||
j = c->rangeRecord[i].start;
|
||||
if (unlikely (j <= old))
|
||||
{
|
||||
/* Broken table. Skip. Important to avoid DoS. */
|
||||
i = c->rangeRecord.len;
|
||||
return;
|
||||
}
|
||||
coverage = c->rangeRecord[i].value;
|
||||
}
|
||||
return;
|
||||
@@ -855,7 +893,8 @@ struct CoverageFormat2
|
||||
|
||||
private:
|
||||
const struct CoverageFormat2 *c;
|
||||
unsigned int i, j, coverage;
|
||||
unsigned int i, coverage;
|
||||
hb_codepoint_t j;
|
||||
};
|
||||
private:
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ struct ValueFormat : HBUINT16
|
||||
#endif
|
||||
|
||||
inline unsigned int get_len (void) const
|
||||
{ return _hb_popcount ((unsigned int) *this); }
|
||||
{ return hb_popcount ((unsigned int) *this); }
|
||||
inline unsigned int get_size (void) const
|
||||
{ return get_len () * Value::static_size; }
|
||||
|
||||
@@ -374,7 +374,7 @@ struct AnchorMatrix
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (!c->check_struct (this)) return_trace (false);
|
||||
if (unlikely (_hb_unsigned_int_mul_overflows (rows, cols))) return_trace (false);
|
||||
if (unlikely (hb_unsigned_mul_overflows (rows, cols))) return_trace (false);
|
||||
unsigned int count = rows * cols;
|
||||
if (!c->check_array (matrixZ, matrixZ[0].static_size, count)) return_trace (false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
@@ -1074,10 +1074,13 @@ struct MarkBasePosFormat1
|
||||
if (!skippy_iter.prev ()) return_trace (false);
|
||||
/* We only want to attach to the first of a MultipleSubst sequence.
|
||||
* https://github.com/harfbuzz/harfbuzz/issues/740
|
||||
* Reject others. */
|
||||
* Reject others...
|
||||
* ...but stop if we find a mark in the MultipleSubst sequence:
|
||||
* https://github.com/harfbuzz/harfbuzz/issues/1020 */
|
||||
if (!_hb_glyph_info_multiplied (&buffer->info[skippy_iter.idx]) ||
|
||||
0 == _hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) ||
|
||||
(skippy_iter.idx == 0 ||
|
||||
_hb_glyph_info_is_mark (&buffer->info[skippy_iter.idx - 1]) ||
|
||||
_hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx]) !=
|
||||
_hb_glyph_info_get_lig_id (&buffer->info[skippy_iter.idx - 1]) ||
|
||||
_hb_glyph_info_get_lig_comp (&buffer->info[skippy_iter.idx]) !=
|
||||
|
||||
@@ -47,7 +47,7 @@ struct SingleSubstFormat1
|
||||
* https://github.com/harfbuzz/harfbuzz/issues/363 */
|
||||
hb_codepoint_t glyph_id = iter.get_glyph ();
|
||||
if (c->glyphs->has (glyph_id))
|
||||
c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFFu);
|
||||
c->out->add ((glyph_id + deltaGlyphID) & 0xFFFFu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ struct SingleSubstFormat2
|
||||
if (unlikely (iter.get_coverage () >= count))
|
||||
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
|
||||
if (c->glyphs->has (iter.get_glyph ()))
|
||||
c->glyphs->add (substitute[iter.get_coverage ()]);
|
||||
c->out->add (substitute[iter.get_coverage ()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ struct Sequence
|
||||
TRACE_CLOSURE (this);
|
||||
unsigned int count = substitute.len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
c->glyphs->add (substitute[i]);
|
||||
c->out->add (substitute[i]);
|
||||
}
|
||||
|
||||
inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
@@ -464,7 +464,7 @@ struct AlternateSubstFormat1
|
||||
const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()];
|
||||
unsigned int count = alt_set.len;
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
c->glyphs->add (alt_set[i]);
|
||||
c->out->add (alt_set[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,7 +511,7 @@ struct AlternateSubstFormat1
|
||||
hb_mask_t lookup_mask = c->lookup_mask;
|
||||
|
||||
/* Note: This breaks badly if two features enabled this lookup together. */
|
||||
unsigned int shift = _hb_ctz (lookup_mask);
|
||||
unsigned int shift = hb_ctz (lookup_mask);
|
||||
unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift);
|
||||
|
||||
if (unlikely (alt_index > alt_set.len || alt_index == 0)) return_trace (false);
|
||||
@@ -605,7 +605,7 @@ struct Ligature
|
||||
for (unsigned int i = 1; i < count; i++)
|
||||
if (!c->glyphs->has (component[i]))
|
||||
return;
|
||||
c->glyphs->add (ligGlyph);
|
||||
c->out->add (ligGlyph);
|
||||
}
|
||||
|
||||
inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
@@ -957,7 +957,7 @@ struct ReverseChainSingleSubstFormat1
|
||||
if (unlikely (iter.get_coverage () >= count))
|
||||
break; /* Work around malicious fonts. https://github.com/harfbuzz/harfbuzz/issues/363 */
|
||||
if (c->glyphs->has (iter.get_glyph ()))
|
||||
c->glyphs->add (substitute[iter.get_coverage ()]);
|
||||
c->out->add (substitute[iter.get_coverage ()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,7 +1163,12 @@ struct SubstLookup : Lookup
|
||||
return_trace (HB_VOID);
|
||||
|
||||
c->set_recurse_func (dispatch_closure_recurse_func);
|
||||
return_trace (dispatch (c));
|
||||
|
||||
hb_closure_context_t::return_t ret = dispatch (c);
|
||||
|
||||
c->flush ();
|
||||
|
||||
return_trace (ret);
|
||||
}
|
||||
|
||||
inline hb_collect_glyphs_context_t::return_t collect_glyphs (hb_collect_glyphs_context_t *c) const
|
||||
@@ -1265,7 +1270,12 @@ struct SubstLookup : Lookup
|
||||
{
|
||||
if (!c->should_visit_lookup (lookup_index))
|
||||
return HB_VOID;
|
||||
return dispatch_recurse_func (c, lookup_index);
|
||||
|
||||
hb_closure_context_t::return_t ret = dispatch_recurse_func (c, lookup_index);
|
||||
|
||||
c->flush ();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename context_t>
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-buffer-private.hh"
|
||||
#include "hb-map-private.hh"
|
||||
#include "hb-ot-layout-gdef-table.hh"
|
||||
@@ -70,12 +69,13 @@ struct hb_closure_context_t :
|
||||
|
||||
bool is_lookup_done (unsigned int lookup_index)
|
||||
{
|
||||
// Have we visited this lookup with the current set of glyphs?
|
||||
/* Have we visited this lookup with the current set of glyphs? */
|
||||
return done_lookups->get (lookup_index) == glyphs->get_population ();
|
||||
}
|
||||
|
||||
hb_face_t *face;
|
||||
hb_set_t *glyphs;
|
||||
hb_auto_t<hb_set_t> out[1];
|
||||
recurse_func_t recurse_func;
|
||||
unsigned int nesting_level_left;
|
||||
unsigned int debug_depth;
|
||||
@@ -91,8 +91,19 @@ struct hb_closure_context_t :
|
||||
debug_depth (0),
|
||||
done_lookups (done_lookups_) {}
|
||||
|
||||
~hb_closure_context_t (void)
|
||||
{
|
||||
flush ();
|
||||
}
|
||||
|
||||
void set_recurse_func (recurse_func_t func) { recurse_func = func; }
|
||||
|
||||
void flush (void)
|
||||
{
|
||||
hb_set_union (glyphs, out);
|
||||
hb_set_clear (out);
|
||||
}
|
||||
|
||||
private:
|
||||
hb_map_t *done_lookups;
|
||||
};
|
||||
@@ -388,7 +399,7 @@ struct hb_ot_apply_context_t :
|
||||
inline bool prev (void)
|
||||
{
|
||||
assert (num_items > 0);
|
||||
while (idx >= num_items)
|
||||
while (idx > num_items - 1)
|
||||
{
|
||||
idx--;
|
||||
const hb_glyph_info_t &info = c->buffer->out_info[idx];
|
||||
|
||||
@@ -176,6 +176,7 @@ struct hb_ot_layout_t
|
||||
OT::hb_table_lazy_loader_t<struct OT::MATH> math;
|
||||
OT::hb_table_lazy_loader_t<struct OT::fvar> fvar;
|
||||
OT::hb_table_lazy_loader_t<struct OT::avar> avar;
|
||||
OT::hb_table_lazy_loader_t<struct AAT::morx> morx;
|
||||
|
||||
unsigned int gsub_lookup_count;
|
||||
unsigned int gpos_lookup_count;
|
||||
|
||||
+116
-9
@@ -54,18 +54,19 @@ _hb_ot_layout_create (hb_face_t *face)
|
||||
if (unlikely (!layout))
|
||||
return nullptr;
|
||||
|
||||
layout->gdef_blob = OT::Sanitizer<OT::GDEF>().sanitize (face->reference_table (HB_OT_TAG_GDEF));
|
||||
layout->gdef_blob = OT::hb_sanitize_context_t().reference_table<OT::GDEF> (face);
|
||||
layout->gdef = layout->gdef_blob->as<OT::GDEF> ();
|
||||
|
||||
layout->gsub_blob = OT::Sanitizer<OT::GSUB>().sanitize (face->reference_table (HB_OT_TAG_GSUB));
|
||||
layout->gsub_blob = OT::hb_sanitize_context_t().reference_table<OT::GSUB> (face);
|
||||
layout->gsub = layout->gsub_blob->as<OT::GSUB> ();
|
||||
|
||||
layout->gpos_blob = OT::Sanitizer<OT::GPOS>().sanitize (face->reference_table (HB_OT_TAG_GPOS));
|
||||
layout->gpos_blob = OT::hb_sanitize_context_t().reference_table<OT::GPOS> (face);
|
||||
layout->gpos = layout->gpos_blob->as<OT::GPOS> ();
|
||||
|
||||
layout->math.init (face);
|
||||
layout->fvar.init (face);
|
||||
layout->avar.init (face);
|
||||
layout->morx.init (face);
|
||||
|
||||
{
|
||||
/*
|
||||
@@ -215,6 +216,7 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout)
|
||||
layout->math.fini ();
|
||||
layout->fvar.fini ();
|
||||
layout->avar.fini ();
|
||||
layout->morx.fini ();
|
||||
|
||||
free (layout);
|
||||
}
|
||||
@@ -661,6 +663,7 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face,
|
||||
unsigned int script_index,
|
||||
unsigned int language_index,
|
||||
const hb_tag_t *features,
|
||||
hb_set_t *visited_features,
|
||||
hb_set_t *lookup_indexes /* OUT */)
|
||||
{
|
||||
if (!features)
|
||||
@@ -671,11 +674,15 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face,
|
||||
script_index,
|
||||
language_index,
|
||||
&required_feature_index,
|
||||
nullptr))
|
||||
_hb_ot_layout_collect_lookups_lookups (face,
|
||||
table_tag,
|
||||
required_feature_index,
|
||||
lookup_indexes);
|
||||
nullptr)
|
||||
&& !visited_features->has (required_feature_index))
|
||||
{
|
||||
_hb_ot_layout_collect_lookups_lookups (face,
|
||||
table_tag,
|
||||
required_feature_index,
|
||||
lookup_indexes);
|
||||
visited_features->add (required_feature_index);
|
||||
}
|
||||
|
||||
/* All features */
|
||||
unsigned int feature_indices[32];
|
||||
@@ -692,10 +699,14 @@ _hb_ot_layout_collect_lookups_features (hb_face_t *face,
|
||||
feature_indices);
|
||||
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
{
|
||||
if (visited_features->has (feature_indices[i])) continue;
|
||||
_hb_ot_layout_collect_lookups_lookups (face,
|
||||
table_tag,
|
||||
feature_indices[i],
|
||||
lookup_indexes);
|
||||
visited_features->add (feature_indices[i]);
|
||||
}
|
||||
|
||||
offset += len;
|
||||
} while (len == ARRAY_LENGTH (feature_indices));
|
||||
@@ -725,6 +736,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face,
|
||||
unsigned int script_index,
|
||||
const hb_tag_t *languages,
|
||||
const hb_tag_t *features,
|
||||
hb_set_t *visited_features,
|
||||
hb_set_t *lookup_indexes /* OUT */)
|
||||
{
|
||||
_hb_ot_layout_collect_lookups_features (face,
|
||||
@@ -732,6 +744,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face,
|
||||
script_index,
|
||||
HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,
|
||||
features,
|
||||
visited_features,
|
||||
lookup_indexes);
|
||||
|
||||
if (!languages)
|
||||
@@ -747,6 +760,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face,
|
||||
script_index,
|
||||
language_index,
|
||||
features,
|
||||
visited_features,
|
||||
lookup_indexes);
|
||||
}
|
||||
else
|
||||
@@ -764,6 +778,7 @@ _hb_ot_layout_collect_lookups_languages (hb_face_t *face,
|
||||
script_index,
|
||||
language_index,
|
||||
features,
|
||||
visited_features,
|
||||
lookup_indexes);
|
||||
}
|
||||
}
|
||||
@@ -782,6 +797,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face,
|
||||
const hb_tag_t *features,
|
||||
hb_set_t *lookup_indexes /* OUT */)
|
||||
{
|
||||
hb_auto_t<hb_set_t> visited_features;
|
||||
if (!scripts)
|
||||
{
|
||||
/* All scripts */
|
||||
@@ -794,6 +810,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face,
|
||||
script_index,
|
||||
languages,
|
||||
features,
|
||||
&visited_features,
|
||||
lookup_indexes);
|
||||
}
|
||||
else
|
||||
@@ -810,6 +827,7 @@ hb_ot_layout_collect_lookups (hb_face_t *face,
|
||||
script_index,
|
||||
languages,
|
||||
features,
|
||||
&visited_features,
|
||||
lookup_indexes);
|
||||
}
|
||||
}
|
||||
@@ -969,6 +987,7 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
|
||||
OT::hb_closure_context_t c (face, glyphs, &done_lookups);
|
||||
const OT::GSUB& gsub = _get_gsub (face);
|
||||
|
||||
unsigned int iteration_count = 0;
|
||||
unsigned int glyphs_length;
|
||||
do
|
||||
{
|
||||
@@ -983,7 +1002,9 @@ hb_ot_layout_lookups_substitute_closure (hb_face_t *face,
|
||||
for (unsigned int i = 0; i < gsub.get_lookup_count (); i++)
|
||||
gsub.get_lookup (i).closure (&c, i);
|
||||
}
|
||||
} while (glyphs_length != glyphs->get_population ());
|
||||
iteration_count++;
|
||||
} while (iteration_count <= HB_CLOSURE_MAX_STAGES
|
||||
&& glyphs_length != glyphs->get_population ());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1014,6 +1035,24 @@ hb_ot_layout_position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
|
||||
OT::GPOS::position_finish_offsets (font, buffer);
|
||||
}
|
||||
|
||||
static const OT::FeatureParams&
|
||||
_get_gsubgpos_matched_feature_params (hb_face_t *face, hb_tag_t feature)
|
||||
{
|
||||
const OT::GSUB &gsub = _get_gsub (face);
|
||||
unsigned int gsub_num_features = gsub.get_feature_count ();
|
||||
for (unsigned int i = 0; i < gsub_num_features; i++)
|
||||
if (feature == gsub.get_feature_tag (i))
|
||||
return gsub.get_feature (i).get_feature_params ();
|
||||
|
||||
const OT::GPOS &gpos = _get_gpos (face);
|
||||
unsigned int gpos_num_features = gpos.get_feature_count ();
|
||||
for (unsigned int i = 0; i < gpos_num_features; i++)
|
||||
if (feature == gpos.get_feature_tag (i))
|
||||
return gpos.get_feature (i).get_feature_params ();
|
||||
|
||||
return Null (OT::FeatureParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_ot_layout_get_size_params:
|
||||
*
|
||||
@@ -1064,6 +1103,74 @@ hb_ot_layout_get_size_params (hb_face_t *face,
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* hb_ot_layout_get_feature_name_ids:
|
||||
* @face: #hb_face_t to work upon
|
||||
* @feature: ssXX and cvXX tag
|
||||
* @label_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
|
||||
* for a user-interface label for this feature. (May be NULL.)
|
||||
* @tooltip_id: (out) (allow-none): The ‘name’ table name ID that specifies a string
|
||||
* that an application can use for tooltip text for this
|
||||
* feature. (May be NULL.)
|
||||
* @sample_id: (out) (allow-none): The ‘name’ table name ID that specifies sample text
|
||||
* that illustrates the effect of this feature. (May be NULL.)
|
||||
* @num_named_parameters: (out) (allow-none): Number of named parameters. (May be zero.)
|
||||
* @first_param_id: (out) (allow-none): The first ‘name’ table name ID used to specify
|
||||
* strings for user-interface labels for the feature
|
||||
* parameters. (Must be zero if numParameters is zero.)
|
||||
*
|
||||
* Return value: true if could find any feature with the tag, false otherwise
|
||||
*
|
||||
* Since: REPLACEME
|
||||
**/
|
||||
hb_bool_t
|
||||
hb_ot_layout_get_feature_name_ids (hb_face_t *face,
|
||||
hb_tag_t feature,
|
||||
unsigned int *label_id, /* OUT. May be nullptr */
|
||||
unsigned int *tooltip_id, /* OUT. May be nullptr */
|
||||
unsigned int *sample_id, /* OUT. May be nullptr */
|
||||
unsigned int *num_named_parameters, /* OUT. May be nullptr */
|
||||
unsigned int *first_param_id /* OUT. May be nullptr */)
|
||||
{
|
||||
const OT::FeatureParams &feature_params =
|
||||
_get_gsubgpos_matched_feature_params (face, feature);
|
||||
if (&feature_params != &Null (OT::FeatureParams))
|
||||
{
|
||||
const OT::FeatureParamsStylisticSet& ss_params =
|
||||
feature_params.get_stylistic_set_params (feature);
|
||||
if (&ss_params != &Null (OT::FeatureParamsStylisticSet)) /* ssXX */
|
||||
{
|
||||
#define PARAM(a, A) if (a) *a = A
|
||||
PARAM(label_id, ss_params.uiNameID);
|
||||
// ssXX features don't have the rest
|
||||
PARAM(tooltip_id, 0);
|
||||
PARAM(sample_id, 0);
|
||||
PARAM(num_named_parameters, 0);
|
||||
PARAM(first_param_id, 0);
|
||||
return true;
|
||||
}
|
||||
const OT::FeatureParamsCharacterVariants& cv_params =
|
||||
feature_params.get_character_variants_params (feature);
|
||||
if (&cv_params != &Null (OT::FeatureParamsCharacterVariants)) /* cvXX */
|
||||
{
|
||||
PARAM(label_id, cv_params.featUILableNameID);
|
||||
PARAM(tooltip_id, cv_params.featUITooltipTextNameID);
|
||||
PARAM(sample_id, cv_params.sampleTextNameID);
|
||||
PARAM(num_named_parameters, cv_params.numNamedParameters);
|
||||
PARAM(first_param_id, cv_params.firstParamUILabelNameID);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PARAM(label_id, 0);
|
||||
PARAM(tooltip_id, 0);
|
||||
PARAM(sample_id, 0);
|
||||
PARAM(num_named_parameters, 0);
|
||||
PARAM(first_param_id, 0);
|
||||
#undef PARAM
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parts of different types are implemented here such that they have direct
|
||||
|
||||
@@ -322,6 +322,14 @@ hb_ot_layout_get_size_params (hb_face_t *face,
|
||||
unsigned int *range_start, /* OUT. May be NULL */
|
||||
unsigned int *range_end /* OUT. May be NULL */);
|
||||
|
||||
HB_EXTERN hb_bool_t
|
||||
hb_ot_layout_get_feature_name_ids (hb_face_t *face,
|
||||
hb_tag_t feature,
|
||||
unsigned int *label_id /* OUT. May be NULL */,
|
||||
unsigned int *tooltip_id /* OUT. May be NULL */,
|
||||
unsigned int *sample_id /* OUT. May be NULL */,
|
||||
unsigned int *num_named_parameters /* OUT. May be NULL */,
|
||||
unsigned int *first_param_id /* OUT. May be NULL */);
|
||||
|
||||
/*
|
||||
* BASE
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m,
|
||||
{
|
||||
static_assert ((!(HB_GLYPH_FLAG_DEFINED & (HB_GLYPH_FLAG_DEFINED + 1))), "");
|
||||
unsigned int global_bit_mask = HB_GLYPH_FLAG_DEFINED + 1;
|
||||
unsigned int global_bit_shift = _hb_popcount (HB_GLYPH_FLAG_DEFINED);
|
||||
unsigned int global_bit_shift = hb_popcount (HB_GLYPH_FLAG_DEFINED);
|
||||
|
||||
m.global_mask = global_bit_mask;
|
||||
|
||||
@@ -209,7 +209,7 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m,
|
||||
bits_needed = 0;
|
||||
else
|
||||
/* Limit to 8 bits per feature. */
|
||||
bits_needed = MIN(8u, _hb_bit_storage (info->max_value));
|
||||
bits_needed = MIN(8u, hb_bit_storage (info->max_value));
|
||||
|
||||
if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t))
|
||||
continue; /* Feature disabled, or not enough bits. */
|
||||
|
||||
@@ -100,14 +100,14 @@ struct maxp
|
||||
|
||||
inline bool subset (hb_subset_plan_t *plan) const
|
||||
{
|
||||
hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp));
|
||||
hb_blob_t *maxp_blob = hb_sanitize_context_t().reference_table<maxp> (plan->source);
|
||||
hb_blob_t *maxp_prime_blob = hb_blob_copy_writable_or_fail (maxp_blob);
|
||||
hb_blob_destroy (maxp_blob);
|
||||
|
||||
if (unlikely (!maxp_prime_blob)) {
|
||||
return false;
|
||||
}
|
||||
OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, nullptr);
|
||||
maxp *maxp_prime = (maxp *) hb_blob_get_data (maxp_prime_blob, nullptr);
|
||||
|
||||
maxp_prime->set_num_glyphs (plan->glyphs.len);
|
||||
if (plan->drop_hints)
|
||||
@@ -118,7 +118,7 @@ struct maxp
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline void drop_hint_fields (hb_subset_plan_t *plan, OT::maxp *maxp_prime)
|
||||
static inline void drop_hint_fields (hb_subset_plan_t *plan, maxp *maxp_prime)
|
||||
{
|
||||
if (maxp_prime->version.major == 1)
|
||||
{
|
||||
|
||||
@@ -51,12 +51,12 @@ struct os2
|
||||
|
||||
inline bool subset (hb_subset_plan_t *plan) const
|
||||
{
|
||||
hb_blob_t *os2_blob = OT::Sanitizer<OT::os2>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2));
|
||||
hb_blob_t *os2_blob = hb_sanitize_context_t().reference_table<os2> (plan->source);
|
||||
hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1);
|
||||
// TODO(grieger): move to hb_blob_copy_writable_or_fail
|
||||
hb_blob_destroy (os2_blob);
|
||||
|
||||
OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr);
|
||||
os2 *os2_prime = (os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr);
|
||||
if (unlikely (!os2_prime)) {
|
||||
hb_blob_destroy (os2_prime_blob);
|
||||
return false;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#define HB_OT_OS2_UNICODE_RANGES_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-dsalgs.hh"
|
||||
|
||||
namespace OT {
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#define HB_OT_POST_TABLE_HH
|
||||
|
||||
#include "hb-open-type-private.hh"
|
||||
#include "hb-dsalgs.hh"
|
||||
#include "hb-subset-plan.hh"
|
||||
|
||||
#define HB_STRING_ARRAY_NAME format1_names
|
||||
@@ -86,7 +85,7 @@ struct post
|
||||
inline bool subset (hb_subset_plan_t *plan) const
|
||||
{
|
||||
unsigned int post_prime_length;
|
||||
hb_blob_t *post_blob = OT::Sanitizer<post>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_post));
|
||||
hb_blob_t *post_blob = hb_sanitize_context_t().reference_table<post>(plan->source);
|
||||
hb_blob_t *post_prime_blob = hb_blob_create_sub_blob (post_blob, 0, post::static_size);
|
||||
post *post_prime = (post *) hb_blob_get_data_writable (post_prime_blob, &post_prime_length);
|
||||
hb_blob_destroy (post_blob);
|
||||
@@ -111,7 +110,7 @@ struct post
|
||||
{
|
||||
index_to_offset.init ();
|
||||
|
||||
blob = Sanitizer<post>().sanitize (face->reference_table (HB_OT_TAG_post));
|
||||
blob = hb_sanitize_context_t().reference_table<post> (face);
|
||||
const post *table = blob->as<post> ();
|
||||
unsigned int table_length = blob->length;
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-ot-shape-complex-arabic-private.hh"
|
||||
#include "hb-ot-shape-private.hh"
|
||||
|
||||
@@ -251,7 +250,7 @@ struct arabic_shape_plan_t
|
||||
* mask_array[NONE] == 0. */
|
||||
hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1];
|
||||
|
||||
arabic_fallback_plan_t *fallback_plan;
|
||||
mutable arabic_fallback_plan_t *fallback_plan;
|
||||
|
||||
unsigned int do_fallback : 1;
|
||||
unsigned int has_stch : 1;
|
||||
|
||||
@@ -668,8 +668,9 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
|
||||
*
|
||||
* Reports suggest that in some scripts Uniscribe does this only if there
|
||||
* is *not* a Halant after last consonant already (eg. Kannada), while it
|
||||
* does it unconditionally in other scripts (eg. Malayalam). We don't
|
||||
* currently know about other scripts, so we single out Malayalam for now.
|
||||
* does it unconditionally in other scripts (eg. Malayalam, Bengali). We
|
||||
* don't currently know about other scripts, so we whitelist Malayalam and
|
||||
* Bengali for now.
|
||||
*
|
||||
* Kannada test case:
|
||||
* U+0C9A,U+0CCD,U+0C9A,U+0CCD
|
||||
@@ -679,10 +680,16 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
|
||||
* Malayalam test case:
|
||||
* U+0D38,U+0D4D,U+0D31,U+0D4D,U+0D31,U+0D4D
|
||||
* With lohit-ttf-20121122/Lohit-Malayalam.ttf
|
||||
*
|
||||
* Bengali test case
|
||||
* U+0998,U+09CD,U+09AF,U+09CD
|
||||
* With Windows XP vrinda.ttf
|
||||
* https://github.com/harfbuzz/harfbuzz/issues/1073
|
||||
*/
|
||||
if (indic_plan->is_old_spec)
|
||||
{
|
||||
bool disallow_double_halants = buffer->props.script != HB_SCRIPT_MALAYALAM;
|
||||
bool disallow_double_halants = buffer->props.script != HB_SCRIPT_MALAYALAM &&
|
||||
buffer->props.script != HB_SCRIPT_BENGALI;
|
||||
for (unsigned int i = base + 1; i < end; i++)
|
||||
if (info[i].indic_category() == OT_H)
|
||||
{
|
||||
@@ -1120,6 +1127,24 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan,
|
||||
* defined as “after last standalone halant glyph, after initial matra
|
||||
* position and before the main consonant”. If ZWJ or ZWNJ follow this
|
||||
* halant, position is moved after it.
|
||||
*
|
||||
* IMPLEMENTATION NOTES:
|
||||
*
|
||||
* It looks like the last sentence is wrong. Testing, with Windows 7 Uniscribe
|
||||
* and Devanagari shows that the behavior is best described as:
|
||||
*
|
||||
* "If ZWJ follows this halant, matra is NOT repositioned after this halant.
|
||||
* If ZWNJ follows this halant, position is moved after it."
|
||||
*
|
||||
* Test case, with Adobe Devanagari or Nirmala UI:
|
||||
*
|
||||
* U+091F,U+094D,U+200C,U+092F,U+093F
|
||||
* (Matra moves to the middle, after ZWNJ.)
|
||||
*
|
||||
* U+091F,U+094D,U+200D,U+092F,U+093F
|
||||
* (Matra does NOT move, stays to the left.)
|
||||
*
|
||||
* https://github.com/harfbuzz/harfbuzz/issues/1070
|
||||
*/
|
||||
|
||||
if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */
|
||||
@@ -1133,6 +1158,7 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan,
|
||||
*/
|
||||
if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL)
|
||||
{
|
||||
search:
|
||||
while (new_pos > start &&
|
||||
!(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H)))))
|
||||
new_pos--;
|
||||
@@ -1143,9 +1169,27 @@ final_reordering_syllable (const hb_ot_shape_plan_t *plan,
|
||||
if (is_halant (info[new_pos]) &&
|
||||
info[new_pos].indic_position() != POS_PRE_M)
|
||||
{
|
||||
#if 0 // See comment above
|
||||
/* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */
|
||||
if (new_pos + 1 < end && is_joiner (info[new_pos + 1]))
|
||||
new_pos++;
|
||||
#endif
|
||||
if (new_pos + 1 < end)
|
||||
{
|
||||
/* -> If ZWJ follows this halant, matra is NOT repositioned after this halant. */
|
||||
if (info[new_pos + 1].indic_category() == OT_ZWJ)
|
||||
{
|
||||
/* Keep searching. */
|
||||
if (new_pos > start)
|
||||
{
|
||||
new_pos--;
|
||||
goto search;
|
||||
}
|
||||
}
|
||||
/* -> If ZWNJ follows this halant, position is moved after it. */
|
||||
if (info[new_pos + 1].indic_category() == OT_ZWNJ)
|
||||
new_pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
new_pos = start; /* No move. */
|
||||
|
||||
@@ -372,22 +372,25 @@ initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Note! syllable() is a one-byte field. */
|
||||
for (unsigned int i = base; i < end; i++)
|
||||
if (info[i].syllable() != 255)
|
||||
{
|
||||
unsigned int max = i;
|
||||
unsigned int j = start + info[i].syllable();
|
||||
while (j != i)
|
||||
if (unlikely (end - start >= 127))
|
||||
buffer->merge_clusters (start, end);
|
||||
else
|
||||
/* Note! syllable() is a one-byte field. */
|
||||
for (unsigned int i = base; i < end; i++)
|
||||
if (info[i].syllable() != 255)
|
||||
{
|
||||
max = MAX (max, j);
|
||||
unsigned int next = start + info[j].syllable();
|
||||
info[j].syllable() = 255; /* So we don't process j later again. */
|
||||
j = next;
|
||||
unsigned int max = i;
|
||||
unsigned int j = start + info[i].syllable();
|
||||
while (j != i)
|
||||
{
|
||||
max = MAX (max, j);
|
||||
unsigned int next = start + info[j].syllable();
|
||||
info[j].syllable() = 255; /* So we don't process j later again. */
|
||||
j = next;
|
||||
}
|
||||
if (i != max)
|
||||
buffer->merge_clusters (i, max + 1);
|
||||
}
|
||||
if (i != max)
|
||||
buffer->merge_clusters (i, max + 1);
|
||||
}
|
||||
|
||||
/* Put syllable back in. */
|
||||
for (unsigned int i = start; i < end; i++)
|
||||
|
||||
@@ -510,8 +510,8 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = {
|
||||
|
||||
/* 11100 */ VMAbv, VMAbv, VMAbv, B, B, B, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11110 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11120 */ B, B, B, B, B, B, B, VAbv, VAbv, VAbv, VBlw, VBlw, VPre, VAbv, VAbv, VAbv,
|
||||
/* 11130 */ VAbv, VBlw, VBlw, H, VAbv, O, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11120 */ B, B, B, B, B, B, B, VBlw, VBlw, VBlw, VAbv, VAbv, VPre, VBlw, VAbv, VAbv,
|
||||
/* 11130 */ VBlw, VAbv, VAbv, H, CMAbv, O, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11140 */ O, O, O, O, B, VPst, VPst, O, O, O, O, O, O, O, O, O,
|
||||
|
||||
/* Mahajani */
|
||||
@@ -560,7 +560,7 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = {
|
||||
|
||||
/* Grantha */
|
||||
|
||||
/* 11300 */ VMAbv, VMAbv, VMPst, VMPst, O, B, B, B, B, B, B, B, B, O, O, B,
|
||||
/* 11300 */ VMAbv, VMAbv, VMAbv, VMPst, O, B, B, B, B, B, B, B, B, O, O, B,
|
||||
/* 11310 */ B, O, O, B, B, B, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11320 */ B, B, B, B, B, B, B, B, B, O, B, B, B, B, B, B,
|
||||
/* 11330 */ B, O, B, B, O, B, B, B, B, B, O, CMBlw, CMBlw, B, VPst, VPst,
|
||||
@@ -673,7 +673,7 @@ static const USE_TABLE_ELEMENT_TYPE use_table[] = {
|
||||
/* 11C10 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11C20 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, VPst,
|
||||
/* 11C30 */ VAbv, VAbv, VBlw, VBlw, VBlw, VBlw, VBlw, O, VAbv, VAbv, VAbv, VAbv, VMAbv, VMAbv, VMPst, H,
|
||||
/* 11C40 */ B, O, O, O, O, O, O, O, O, O, O, O, O, O, O, O,
|
||||
/* 11C40 */ B, O, O, O, GB, GB, O, O, O, O, O, O, O, O, O, O,
|
||||
/* 11C50 */ B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B,
|
||||
/* 11C60 */ B, B, B, B, B, B, B, B, B, B, B, B, B, O, O, O,
|
||||
|
||||
|
||||
@@ -560,25 +560,6 @@ reorder (const hb_ot_shape_plan_t *plan,
|
||||
HB_BUFFER_DEALLOCATE_VAR (buffer, use_category);
|
||||
}
|
||||
|
||||
static bool
|
||||
decompose_use (const hb_ot_shape_normalize_context_t *c,
|
||||
hb_codepoint_t ab,
|
||||
hb_codepoint_t *a,
|
||||
hb_codepoint_t *b)
|
||||
{
|
||||
switch (ab)
|
||||
{
|
||||
/* Chakma:
|
||||
* Special case where the Unicode decomp gives matras in the wrong order
|
||||
* for cluster validation.
|
||||
*/
|
||||
case 0x1112Eu : *a = 0x11127u; *b= 0x11131u; return true;
|
||||
case 0x1112Fu : *a = 0x11127u; *b= 0x11132u; return true;
|
||||
}
|
||||
|
||||
return (bool) c->unicode->decompose (ab, a, b);
|
||||
}
|
||||
|
||||
static bool
|
||||
compose_use (const hb_ot_shape_normalize_context_t *c,
|
||||
hb_codepoint_t a,
|
||||
@@ -602,7 +583,7 @@ const hb_ot_complex_shaper_t _hb_ot_complex_shaper_use =
|
||||
nullptr, /* preprocess_text */
|
||||
nullptr, /* postprocess_glyphs */
|
||||
HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT,
|
||||
decompose_use,
|
||||
nullptr, /* decompose */
|
||||
compose_use,
|
||||
setup_masks_use,
|
||||
nullptr, /* disable_otl */
|
||||
|
||||
+8
-5
@@ -41,7 +41,7 @@
|
||||
#include "hb-set-private.hh"
|
||||
|
||||
#include "hb-ot-layout-gsubgpos-private.hh"
|
||||
//#include "hb-aat-layout-private.hh"
|
||||
#include "hb-aat-layout-private.hh"
|
||||
|
||||
static hb_tag_t common_features[] = {
|
||||
HB_TAG('c','c','m','p'),
|
||||
@@ -194,7 +194,10 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan,
|
||||
if (plan->shaper->data_create) {
|
||||
plan->data = plan->shaper->data_create (plan);
|
||||
if (unlikely (!plan->data))
|
||||
{
|
||||
free (plan);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return plan;
|
||||
@@ -623,8 +626,8 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c)
|
||||
|
||||
c->plan->substitute (c->font, buffer);
|
||||
|
||||
/* XXX Call morx instead. */
|
||||
//hb_aat_layout_substitute (c->font, c->buffer);
|
||||
if (0) /* XXX Call morx instead. */
|
||||
hb_aat_layout_substitute (c->font, c->buffer);
|
||||
}
|
||||
|
||||
static inline void
|
||||
@@ -829,12 +832,12 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c)
|
||||
{
|
||||
c->buffer->deallocate_var_all ();
|
||||
c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
|
||||
if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR)))
|
||||
if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR)))
|
||||
{
|
||||
c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR,
|
||||
(unsigned) HB_BUFFER_MAX_LEN_MIN);
|
||||
}
|
||||
if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR)))
|
||||
if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR)))
|
||||
{
|
||||
c->buffer->max_ops = MAX (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR,
|
||||
(unsigned) HB_BUFFER_MAX_OPS_MIN);
|
||||
|
||||
+109
-742
@@ -58,6 +58,7 @@
|
||||
#define HB_PASTE1(a,b) a##b
|
||||
#define HB_PASTE(a,b) HB_PASTE1(a,b)
|
||||
|
||||
|
||||
/* Compile-time custom allocator support. */
|
||||
|
||||
#if defined(hb_malloc_impl) \
|
||||
@@ -72,11 +73,20 @@ extern "C" void hb_free_impl(void *ptr);
|
||||
#define calloc hb_calloc_impl
|
||||
#define realloc hb_realloc_impl
|
||||
#define free hb_free_impl
|
||||
|
||||
#if defined(hb_memalign_impl)
|
||||
extern "C" int hb_memalign_impl(void **memptr, size_t alignment, size_t size);
|
||||
#define posix_memalign hb_memalign_impl
|
||||
#else
|
||||
#undef HAVE_POSIX_MEMALIGN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Compiler attributes */
|
||||
|
||||
/*
|
||||
* Compiler attributes
|
||||
* */
|
||||
|
||||
#if __cplusplus < 201103L
|
||||
|
||||
@@ -84,6 +94,10 @@ extern "C" void hb_free_impl(void *ptr);
|
||||
#define nullptr NULL
|
||||
#endif
|
||||
|
||||
#ifndef constexpr
|
||||
#define constexpr const
|
||||
#endif
|
||||
|
||||
// Static assertions
|
||||
#ifndef static_assert
|
||||
#define static_assert(e, msg) \
|
||||
@@ -98,6 +112,20 @@ extern "C" void hb_free_impl(void *ptr);
|
||||
#define thread_local
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
struct _hb_alignof
|
||||
{
|
||||
struct s
|
||||
{
|
||||
char c;
|
||||
T t;
|
||||
};
|
||||
static constexpr size_t value = offsetof (s, t);
|
||||
};
|
||||
#ifndef alignof
|
||||
#define alignof(x) (_hb_alignof<x>::value)
|
||||
#endif // alignof
|
||||
|
||||
#endif // __cplusplus < 201103L
|
||||
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && defined(__OPTIMIZE__)
|
||||
@@ -133,7 +161,11 @@ extern "C" void hb_free_impl(void *ptr);
|
||||
#ifndef HB_INTERNAL
|
||||
# if !defined(HB_NO_VISIBILITY) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_MSC_VER) && !defined(__SUNPRO_CC)
|
||||
# define HB_INTERNAL __attribute__((__visibility__("hidden")))
|
||||
# else
|
||||
# elif defined(__MINGW32__)
|
||||
/* We use -export-symbols on mingw32, since it does not support visibility
|
||||
* attribute. */
|
||||
# define HB_INTERNAL
|
||||
#else
|
||||
# define HB_INTERNAL
|
||||
# define HB_NO_VISIBILITY 1
|
||||
# endif
|
||||
@@ -251,26 +283,6 @@ static int errno = 0; /* Use something better? */
|
||||
# undef HB_USE_ATEXIT
|
||||
#endif
|
||||
|
||||
/* Basics */
|
||||
|
||||
#undef MIN
|
||||
template <typename Type>
|
||||
static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
|
||||
|
||||
#undef MAX
|
||||
template <typename Type>
|
||||
static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
|
||||
|
||||
static inline unsigned int DIV_CEIL (const unsigned int a, unsigned int b)
|
||||
{ return (a + (b - 1)) / b; }
|
||||
|
||||
|
||||
#undef ARRAY_LENGTH
|
||||
template <typename Type, unsigned int n>
|
||||
static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; }
|
||||
/* A const version, but does not detect erratically being called on pointers. */
|
||||
#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
|
||||
|
||||
#define HB_STMT_START do
|
||||
#define HB_STMT_END while (0)
|
||||
|
||||
@@ -322,227 +334,43 @@ static_assert ((sizeof (hb_var_int_t) == 4), "");
|
||||
# define ASSERT_POD() _ASSERT_POD0 (__LINE__)
|
||||
|
||||
|
||||
|
||||
/* Tiny functions */
|
||||
|
||||
/*
|
||||
* Void!
|
||||
*/
|
||||
typedef const struct _hb_void_t *hb_void_t;
|
||||
#define HB_VOID ((const _hb_void_t *) nullptr)
|
||||
|
||||
/* Return the number of 1 bits in v. */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
_hb_popcount (T v)
|
||||
{
|
||||
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return __builtin_popcount (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return __builtin_popcountl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return __builtin_popcountll (v);
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "HACKMEM 169" */
|
||||
uint32_t y;
|
||||
y = (v >> 1) &033333333333;
|
||||
y = v - y - ((y >>1) & 033333333333);
|
||||
return (((y + (y >> 3)) & 030707070707) % 077);
|
||||
}
|
||||
|
||||
if (sizeof (T) == 8)
|
||||
{
|
||||
unsigned int shift = 32;
|
||||
return _hb_popcount<uint32_t> ((uint32_t) v) + _hb_popcount ((uint32_t) (v >> shift));
|
||||
}
|
||||
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return _hb_popcount<uint64_t> ((uint64_t) v) + _hb_popcount ((uint64_t) (v >> shift));
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
/* Returns the number of bits needed to store number */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
_hb_bit_storage (T v)
|
||||
{
|
||||
if (unlikely (!v)) return 0;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return sizeof (unsigned int) * 8 - __builtin_clz (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return sizeof (unsigned long) * 8 - __builtin_clzl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return sizeof (unsigned long long) * 8 - __builtin_clzll (v);
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanReverse (&where, v);
|
||||
return 1 + where;
|
||||
}
|
||||
# if _WIN64
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanReverse64 (&where, v);
|
||||
return 1 + where;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "bithacks" */
|
||||
const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
|
||||
const unsigned int S[] = {1, 2, 4, 8, 16};
|
||||
unsigned int r = 0;
|
||||
for (int i = 4; i >= 0; i--)
|
||||
if (v & b[i])
|
||||
{
|
||||
v >>= S[i];
|
||||
r |= S[i];
|
||||
}
|
||||
return r + 1;
|
||||
}
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
/* "bithacks" */
|
||||
const uint64_t b[] = {0x2ULL, 0xCULL, 0xF0ULL, 0xFF00ULL, 0xFFFF0000ULL, 0xFFFFFFFF00000000ULL};
|
||||
const unsigned int S[] = {1, 2, 4, 8, 16, 32};
|
||||
unsigned int r = 0;
|
||||
for (int i = 5; i >= 0; i--)
|
||||
if (v & b[i])
|
||||
{
|
||||
v >>= S[i];
|
||||
r |= S[i];
|
||||
}
|
||||
return r + 1;
|
||||
}
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return (v >> shift) ? _hb_bit_storage<uint64_t> ((uint64_t) (v >> shift)) + shift :
|
||||
_hb_bit_storage<uint64_t> ((uint64_t) v);
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
/* Returns the number of zero bits in the least significant side of v */
|
||||
template <typename T>
|
||||
static inline HB_CONST_FUNC unsigned int
|
||||
_hb_ctz (T v)
|
||||
{
|
||||
if (unlikely (!v)) return 0;
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
return __builtin_ctz (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long))
|
||||
return __builtin_ctzl (v);
|
||||
|
||||
if (sizeof (T) <= sizeof (unsigned long long))
|
||||
return __builtin_ctzll (v);
|
||||
#endif
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
|
||||
if (sizeof (T) <= sizeof (unsigned int))
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanForward (&where, v);
|
||||
return where;
|
||||
}
|
||||
# if _WIN64
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
unsigned long where;
|
||||
_BitScanForward64 (&where, v);
|
||||
return where;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (sizeof (T) <= 4)
|
||||
{
|
||||
/* "bithacks" */
|
||||
unsigned int c = 32;
|
||||
v &= - (int32_t) v;
|
||||
if (v) c--;
|
||||
if (v & 0x0000FFFF) c -= 16;
|
||||
if (v & 0x00FF00FF) c -= 8;
|
||||
if (v & 0x0F0F0F0F) c -= 4;
|
||||
if (v & 0x33333333) c -= 2;
|
||||
if (v & 0x55555555) c -= 1;
|
||||
return c;
|
||||
}
|
||||
if (sizeof (T) <= 8)
|
||||
{
|
||||
/* "bithacks" */
|
||||
unsigned int c = 64;
|
||||
v &= - (int64_t) (v);
|
||||
if (v) c--;
|
||||
if (v & 0x00000000FFFFFFFFULL) c -= 32;
|
||||
if (v & 0x0000FFFF0000FFFFULL) c -= 16;
|
||||
if (v & 0x00FF00FF00FF00FFULL) c -= 8;
|
||||
if (v & 0x0F0F0F0F0F0F0F0FULL) c -= 4;
|
||||
if (v & 0x3333333333333333ULL) c -= 2;
|
||||
if (v & 0x5555555555555555ULL) c -= 1;
|
||||
return c;
|
||||
}
|
||||
if (sizeof (T) == 16)
|
||||
{
|
||||
unsigned int shift = 64;
|
||||
return (uint64_t) v ? _hb_bit_storage<uint64_t> ((uint64_t) v) :
|
||||
_hb_bit_storage<uint64_t> ((uint64_t) v >> shift) + shift;
|
||||
}
|
||||
|
||||
assert (0);
|
||||
return 0; /* Shut up stupid compiler. */
|
||||
}
|
||||
|
||||
static inline bool
|
||||
_hb_unsigned_int_mul_overflows (unsigned int count, unsigned int size)
|
||||
{
|
||||
return (size > 0) && (count >= ((unsigned int) -1) / size);
|
||||
}
|
||||
|
||||
static inline unsigned int
|
||||
_hb_ceil_to_4 (unsigned int v)
|
||||
{
|
||||
return ((v - 1) | 3) + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Utility types
|
||||
*
|
||||
*/
|
||||
|
||||
#define HB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&); \
|
||||
void operator=(const TypeName&)
|
||||
|
||||
|
||||
/*
|
||||
* Compiler-assisted vectorization parameters.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Disable vectorization for now. To correctly use them, we should
|
||||
* use posix_memalign() to allocate in hb_vector_t. Otherwise, can
|
||||
* cause misaligned access.
|
||||
*
|
||||
* https://bugs.chromium.org/p/chromium/issues/detail?id=860184
|
||||
*/
|
||||
#if !defined(HB_VECTOR_SIZE)
|
||||
# define HB_VECTOR_SIZE 0
|
||||
#endif
|
||||
|
||||
/* The `vector_size' attribute was introduced in gcc 3.1. */
|
||||
#if !defined(HB_VECTOR_SIZE)
|
||||
# if defined( __GNUC__ ) && ( __GNUC__ >= 4 )
|
||||
# define HB_VECTOR_SIZE 128
|
||||
# else
|
||||
# define HB_VECTOR_SIZE 0
|
||||
# endif
|
||||
#endif
|
||||
static_assert (0 == (HB_VECTOR_SIZE & (HB_VECTOR_SIZE - 1)), "HB_VECTOR_SIZE is not power of 2.");
|
||||
static_assert (0 == (HB_VECTOR_SIZE % 64), "HB_VECTOR_SIZE is not multiple of 64.");
|
||||
#if HB_VECTOR_SIZE
|
||||
typedef uint64_t hb_vector_size_impl_t __attribute__((vector_size (HB_VECTOR_SIZE / 8)));
|
||||
#else
|
||||
typedef uint64_t hb_vector_size_impl_t;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Static pools
|
||||
*/
|
||||
@@ -550,18 +378,10 @@ _hb_ceil_to_4 (unsigned int v)
|
||||
/* Global nul-content Null pool. Enlarge as necessary. */
|
||||
|
||||
#define HB_NULL_POOL_SIZE 264
|
||||
static_assert (HB_NULL_POOL_SIZE % sizeof (void *) == 0, "Align HB_NULL_POOL_SIZE.");
|
||||
|
||||
#ifdef HB_NO_VISIBILITY
|
||||
static
|
||||
#else
|
||||
extern HB_INTERNAL
|
||||
#endif
|
||||
void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)]
|
||||
#ifdef HB_NO_VISIBILITY
|
||||
= {}
|
||||
#endif
|
||||
;
|
||||
hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)];
|
||||
|
||||
/* Generic nul-content Null objects. */
|
||||
template <typename Type>
|
||||
static inline Type const & Null (void) {
|
||||
@@ -589,16 +409,9 @@ static_assert (Namespace::Type::min_size + 1 <= sizeof (_Null##Type), "Null pool
|
||||
* for correct operation. It only exist to catch and divert program logic bugs instead of
|
||||
* causing bad memory access. So, races there are not actually introducing incorrectness
|
||||
* in the code. Has ~12kb binary size overhead to have it, also clang build fails with it. */
|
||||
#ifdef HB_NO_VISIBILITY
|
||||
static
|
||||
#else
|
||||
extern HB_INTERNAL
|
||||
#endif
|
||||
/*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)]
|
||||
#ifdef HB_NO_VISIBILITY
|
||||
= {}
|
||||
#endif
|
||||
;
|
||||
/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)];
|
||||
|
||||
/* CRAP pool: Common Region for Access Protection. */
|
||||
template <typename Type>
|
||||
static inline Type& Crap (void) {
|
||||
@@ -620,321 +433,6 @@ struct CrapOrNull<const Type> {
|
||||
#define CrapOrNull(Type) CrapOrNull<Type>::get ()
|
||||
|
||||
|
||||
|
||||
/* arrays and maps */
|
||||
|
||||
|
||||
#define HB_PREALLOCED_ARRAY_INIT {0, 0, nullptr}
|
||||
template <typename Type, unsigned int StaticSize=8>
|
||||
struct hb_vector_t
|
||||
{
|
||||
unsigned int len;
|
||||
unsigned int allocated;
|
||||
bool successful;
|
||||
Type *arrayZ;
|
||||
Type static_array[StaticSize];
|
||||
|
||||
void init (void)
|
||||
{
|
||||
len = 0;
|
||||
allocated = ARRAY_LENGTH (static_array);
|
||||
successful = true;
|
||||
arrayZ = static_array;
|
||||
}
|
||||
|
||||
inline Type& operator [] (unsigned int i)
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return Crap (Type);
|
||||
return arrayZ[i];
|
||||
}
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return Null(Type);
|
||||
return arrayZ[i];
|
||||
}
|
||||
|
||||
inline Type *push (void)
|
||||
{
|
||||
if (unlikely (!resize (len + 1)))
|
||||
return &Crap(Type);
|
||||
return &arrayZ[len - 1];
|
||||
}
|
||||
inline Type *push (const Type& v)
|
||||
{
|
||||
Type *p = push ();
|
||||
*p = v;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Allocate for size but don't adjust len. */
|
||||
inline bool alloc (unsigned int size)
|
||||
{
|
||||
if (unlikely (!successful))
|
||||
return false;
|
||||
|
||||
if (likely (size <= allocated))
|
||||
return true;
|
||||
|
||||
/* Reallocate */
|
||||
|
||||
unsigned int new_allocated = allocated;
|
||||
while (size >= new_allocated)
|
||||
new_allocated += (new_allocated >> 1) + 8;
|
||||
|
||||
Type *new_array = nullptr;
|
||||
|
||||
if (arrayZ == static_array)
|
||||
{
|
||||
new_array = (Type *) calloc (new_allocated, sizeof (Type));
|
||||
if (new_array)
|
||||
memcpy (new_array, arrayZ, len * sizeof (Type));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool overflows = (new_allocated < allocated) || _hb_unsigned_int_mul_overflows (new_allocated, sizeof (Type));
|
||||
if (likely (!overflows))
|
||||
new_array = (Type *) realloc (arrayZ, new_allocated * sizeof (Type));
|
||||
}
|
||||
|
||||
if (unlikely (!new_array))
|
||||
{
|
||||
successful = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
arrayZ = new_array;
|
||||
allocated = new_allocated;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool resize (int size_)
|
||||
{
|
||||
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;
|
||||
if (!alloc (size))
|
||||
return false;
|
||||
|
||||
if (size > len)
|
||||
memset (arrayZ + len, 0, (size - len) * sizeof (*arrayZ));
|
||||
|
||||
len = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void pop (void)
|
||||
{
|
||||
if (!len) return;
|
||||
len--;
|
||||
}
|
||||
|
||||
inline void remove (unsigned int i)
|
||||
{
|
||||
if (unlikely (i >= len))
|
||||
return;
|
||||
memmove (static_cast<void *> (&arrayZ[i]),
|
||||
static_cast<void *> (&arrayZ[i + 1]),
|
||||
(len - i - 1) * sizeof (Type));
|
||||
len--;
|
||||
}
|
||||
|
||||
inline void shrink (int size_)
|
||||
{
|
||||
unsigned int size = size_ < 0 ? 0u : (unsigned int) size_;
|
||||
if (size < len)
|
||||
len = size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *find (T v) {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *find (T v) const {
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (arrayZ[i] == v)
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline void qsort (int (*cmp)(const void*, const void*))
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), cmp);
|
||||
}
|
||||
|
||||
inline void qsort (void)
|
||||
{
|
||||
::qsort (arrayZ, len, sizeof (Type), Type::cmp);
|
||||
}
|
||||
|
||||
inline void qsort (unsigned int start, unsigned int end)
|
||||
{
|
||||
::qsort (arrayZ + start, end - start, sizeof (Type), Type::cmp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *lsearch (const T &x)
|
||||
{
|
||||
for (unsigned int i = 0; i < len; i++)
|
||||
if (0 == this->arrayZ[i].cmp (&x))
|
||||
return &arrayZ[i];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Type *bsearch (const T &x)
|
||||
{
|
||||
unsigned int i;
|
||||
return bfind (x, &i) ? &arrayZ[i] : nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline const Type *bsearch (const T &x) const
|
||||
{
|
||||
unsigned int i;
|
||||
return bfind (x, &i) ? &arrayZ[i] : nullptr;
|
||||
}
|
||||
template <typename T>
|
||||
inline bool bfind (const T &x, unsigned int *i) const
|
||||
{
|
||||
int min = 0, max = (int) this->len - 1;
|
||||
while (min <= max)
|
||||
{
|
||||
int mid = (min + max) / 2;
|
||||
int c = this->arrayZ[mid].cmp (&x);
|
||||
if (c < 0)
|
||||
max = mid - 1;
|
||||
else if (c > 0)
|
||||
min = mid + 1;
|
||||
else
|
||||
{
|
||||
*i = mid;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (max < 0 || (max < (int) this->len && this->arrayZ[max].cmp (&x) > 0))
|
||||
max++;
|
||||
*i = max;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void fini (void)
|
||||
{
|
||||
if (arrayZ != static_array)
|
||||
free (arrayZ);
|
||||
arrayZ = nullptr;
|
||||
allocated = len = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
struct hb_auto_t : Type
|
||||
{
|
||||
hb_auto_t (void) { Type::init (); }
|
||||
~hb_auto_t (void) { Type::fini (); }
|
||||
private: /* Hide */
|
||||
void init (void) {}
|
||||
void fini (void) {}
|
||||
};
|
||||
template <typename Type>
|
||||
struct hb_auto_array_t : hb_auto_t <hb_vector_t <Type> > {};
|
||||
|
||||
|
||||
#define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT}
|
||||
template <typename item_t, typename lock_t>
|
||||
struct hb_lockable_set_t
|
||||
{
|
||||
hb_vector_t <item_t, 1> items;
|
||||
|
||||
inline void init (void) { items.init (); }
|
||||
|
||||
template <typename T>
|
||||
inline item_t *replace_or_insert (T v, lock_t &l, bool replace)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item) {
|
||||
if (replace) {
|
||||
item_t old = *item;
|
||||
*item = v;
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
}
|
||||
else {
|
||||
item = nullptr;
|
||||
l.unlock ();
|
||||
}
|
||||
} else {
|
||||
item = items.push (v);
|
||||
l.unlock ();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void remove (T v, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item) {
|
||||
item_t old = *item;
|
||||
*item = items[items.len - 1];
|
||||
items.pop ();
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
} else {
|
||||
l.unlock ();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool find (T v, item_t *i, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (item)
|
||||
*i = *item;
|
||||
l.unlock ();
|
||||
return !!item;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline item_t *find_or_insert (T v, lock_t &l)
|
||||
{
|
||||
l.lock ();
|
||||
item_t *item = items.find (v);
|
||||
if (!item) {
|
||||
item = items.push (v);
|
||||
}
|
||||
l.unlock ();
|
||||
return item;
|
||||
}
|
||||
|
||||
inline void fini (lock_t &l)
|
||||
{
|
||||
if (!items.len) {
|
||||
/* No need for locking. */
|
||||
items.fini ();
|
||||
return;
|
||||
}
|
||||
l.lock ();
|
||||
while (items.len) {
|
||||
item_t old = items[items.len - 1];
|
||||
items.pop ();
|
||||
l.unlock ();
|
||||
old.fini ();
|
||||
l.lock ();
|
||||
}
|
||||
items.fini ();
|
||||
l.unlock ();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* ASCII tag/character handling */
|
||||
|
||||
static inline bool ISALPHA (unsigned char c)
|
||||
@@ -1027,146 +525,6 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
|
||||
#define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x))
|
||||
|
||||
|
||||
template <typename T, typename T2> static inline void
|
||||
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2)
|
||||
{
|
||||
for (unsigned int i = 1; i < len; i++)
|
||||
{
|
||||
unsigned int j = i;
|
||||
while (j && compar (&array[j - 1], &array[i]) > 0)
|
||||
j--;
|
||||
if (i == j)
|
||||
continue;
|
||||
/* Move item i to occupy place for item j, shift what's in between. */
|
||||
{
|
||||
T t = array[i];
|
||||
memmove (&array[j + 1], &array[j], (i - j) * sizeof (T));
|
||||
array[j] = t;
|
||||
}
|
||||
if (array2)
|
||||
{
|
||||
T2 t = array2[i];
|
||||
memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2));
|
||||
array2[j] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> static inline void
|
||||
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *))
|
||||
{
|
||||
hb_stable_sort (array, len, compar, (int *) nullptr);
|
||||
}
|
||||
|
||||
static inline hb_bool_t
|
||||
hb_codepoint_parse (const char *s, unsigned int len, int base, hb_codepoint_t *out)
|
||||
{
|
||||
/* Pain because we don't know whether s is nul-terminated. */
|
||||
char buf[64];
|
||||
len = MIN (ARRAY_LENGTH (buf) - 1, len);
|
||||
strncpy (buf, s, len);
|
||||
buf[len] = '\0';
|
||||
|
||||
char *end;
|
||||
errno = 0;
|
||||
unsigned long v = strtoul (buf, &end, base);
|
||||
if (errno) return false;
|
||||
if (*end) return false;
|
||||
*out = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Vectorization */
|
||||
|
||||
struct HbOpOr
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = true;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a | b; }
|
||||
};
|
||||
struct HbOpAnd
|
||||
{
|
||||
static const bool passthru_left = false;
|
||||
static const bool passthru_right = false;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a & b; }
|
||||
};
|
||||
struct HbOpMinus
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = false;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a & ~b; }
|
||||
};
|
||||
struct HbOpXor
|
||||
{
|
||||
static const bool passthru_left = true;
|
||||
static const bool passthru_right = true;
|
||||
template <typename T> static void process (T &o, const T &a, const T &b) { o = a ^ b; }
|
||||
};
|
||||
|
||||
|
||||
/* Compiler-assisted vectorization. */
|
||||
|
||||
/* The `vector_size' attribute was introduced in gcc 3.1. */
|
||||
#if defined( __GNUC__ ) && ( __GNUC__ >= 4 )
|
||||
#define HB_VECTOR_SIZE 128
|
||||
#elif !defined(HB_VECTOR_SIZE)
|
||||
#define HB_VECTOR_SIZE 0
|
||||
#endif
|
||||
|
||||
/* Type behaving similar to vectorized vars defined using __attribute__((vector_size(...))). */
|
||||
template <typename elt_t, unsigned int byte_size>
|
||||
struct hb_vector_size_t
|
||||
{
|
||||
elt_t& operator [] (unsigned int i) { return u.v[i]; }
|
||||
const elt_t& operator [] (unsigned int i) const { return u.v[i]; }
|
||||
|
||||
template <class Op>
|
||||
inline hb_vector_size_t process (const hb_vector_size_t &o) const
|
||||
{
|
||||
hb_vector_size_t r;
|
||||
#if HB_VECTOR_SIZE
|
||||
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
|
||||
Op::process (r.u.vec[i], u.vec[i], o.u.vec[i]);
|
||||
else
|
||||
#endif
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
|
||||
Op::process (r.u.v[i], u.v[i], o.u.v[i]);
|
||||
return r;
|
||||
}
|
||||
inline hb_vector_size_t operator | (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpOr> (o); }
|
||||
inline hb_vector_size_t operator & (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpAnd> (o); }
|
||||
inline hb_vector_size_t operator ^ (const hb_vector_size_t &o) const
|
||||
{ return process<HbOpXor> (o); }
|
||||
inline hb_vector_size_t operator ~ () const
|
||||
{
|
||||
hb_vector_size_t r;
|
||||
#if HB_VECTOR_SIZE && 0
|
||||
if (HB_VECTOR_SIZE && 0 == (byte_size * 8) % HB_VECTOR_SIZE)
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.vec); i++)
|
||||
r.u.vec[i] = ~u.vec[i];
|
||||
else
|
||||
#endif
|
||||
for (unsigned int i = 0; i < ARRAY_LENGTH (u.v); i++)
|
||||
r.u.v[i] = ~u.v[i];
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
static_assert (byte_size / sizeof (elt_t) * sizeof (elt_t) == byte_size, "");
|
||||
union {
|
||||
elt_t v[byte_size / sizeof (elt_t)];
|
||||
#if HB_VECTOR_SIZE
|
||||
typedef unsigned long vec_t __attribute__((vector_size (HB_VECTOR_SIZE / 8)));
|
||||
vec_t vec[byte_size / sizeof (vec_t)];
|
||||
#endif
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
/* Global runtime options. */
|
||||
|
||||
struct hb_options_t
|
||||
@@ -1199,43 +557,52 @@ hb_options (void)
|
||||
#define VAR 1
|
||||
|
||||
|
||||
/* String type. */
|
||||
|
||||
struct hb_bytes_t
|
||||
{
|
||||
inline hb_bytes_t (void) : bytes (nullptr), len (0) {}
|
||||
inline hb_bytes_t (const char *bytes_, unsigned int len_) : bytes (bytes_), len (len_) {}
|
||||
|
||||
inline int cmp (const hb_bytes_t &a) const
|
||||
{
|
||||
if (len != a.len)
|
||||
return (int) a.len - (int) len;
|
||||
|
||||
return memcmp (a.bytes, bytes, len);
|
||||
}
|
||||
static inline int cmp (const void *pa, const void *pb)
|
||||
{
|
||||
hb_bytes_t *a = (hb_bytes_t *) pa;
|
||||
hb_bytes_t *b = (hb_bytes_t *) pb;
|
||||
return b->cmp (*a);
|
||||
}
|
||||
|
||||
const char *bytes;
|
||||
unsigned int len;
|
||||
};
|
||||
|
||||
|
||||
/* fallback for round() */
|
||||
#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND)
|
||||
static inline double
|
||||
round (double x)
|
||||
_hb_round (double x)
|
||||
{
|
||||
if (x >= 0)
|
||||
return floor (x + 0.5);
|
||||
else
|
||||
return ceil (x - 0.5);
|
||||
}
|
||||
#if !defined (HAVE_ROUND) && !defined (HAVE_DECL_ROUND)
|
||||
#define round(x) _hb_round(x)
|
||||
#endif
|
||||
|
||||
|
||||
/* fallback for posix_memalign() */
|
||||
static inline int
|
||||
_hb_memalign(void **memptr, size_t alignment, size_t size)
|
||||
{
|
||||
if (unlikely (0 != (alignment & (alignment - 1)) ||
|
||||
!alignment ||
|
||||
0 != (alignment & (sizeof (void *) - 1))))
|
||||
return EINVAL;
|
||||
|
||||
char *p = (char *) malloc (size + alignment - 1);
|
||||
if (unlikely (!p))
|
||||
return ENOMEM;
|
||||
|
||||
size_t off = (size_t) p & (alignment - 1);
|
||||
if (off)
|
||||
p += alignment - off;
|
||||
|
||||
*memptr = (void *) p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#if !defined(posix_memalign) && !defined(HAVE_POSIX_MEMALIGN)
|
||||
#define posix_memalign _hb_memalign
|
||||
#endif
|
||||
|
||||
|
||||
/* Headers we include for everyone. Keep sorted. They express dependency amongst
|
||||
* themselves, but no other file should include them.*/
|
||||
#include "hb-atomic-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-dsalgs.hh"
|
||||
#include "hb-mutex-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
#endif /* HB_PRIVATE_HH */
|
||||
@@ -28,7 +28,6 @@
|
||||
#define HB_SET_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
|
||||
/*
|
||||
@@ -94,7 +93,7 @@ struct hb_set_t
|
||||
{
|
||||
unsigned int pop = 0;
|
||||
for (unsigned int i = 0; i < len (); i++)
|
||||
pop += _hb_popcount (v[i]);
|
||||
pop += hb_popcount (v[i]);
|
||||
return pop;
|
||||
}
|
||||
|
||||
@@ -161,8 +160,8 @@ struct hb_set_t
|
||||
static const unsigned int PAGE_BITS = 512;
|
||||
static_assert ((PAGE_BITS & ((PAGE_BITS) - 1)) == 0, "");
|
||||
|
||||
static inline unsigned int elt_get_min (const elt_t &elt) { return _hb_ctz (elt); }
|
||||
static inline unsigned int elt_get_max (const elt_t &elt) { return _hb_bit_storage (elt) - 1; }
|
||||
static inline unsigned int elt_get_min (const elt_t &elt) { return hb_ctz (elt); }
|
||||
static inline unsigned int elt_get_max (const elt_t &elt) { return hb_bit_storage (elt) - 1; }
|
||||
|
||||
typedef hb_vector_size_t<elt_t, PAGE_BITS / 8> vector_t;
|
||||
|
||||
@@ -405,6 +404,7 @@ struct hb_set_t
|
||||
if (get_population () > larger_set->get_population ())
|
||||
return false;
|
||||
|
||||
/* TODO Optimize to use pages. */
|
||||
hb_codepoint_t c = INVALID;
|
||||
while (next (&c))
|
||||
if (!larger_set->has (c))
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#define HB_SHAPE_PLAN_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-shaper-private.hh"
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#include "hb-shape-plan-private.hh"
|
||||
#include "hb-shaper-private.hh"
|
||||
#include "hb-font-private.hh"
|
||||
|
||||
@@ -97,6 +97,10 @@ HB_SHAPER_DATA_ENSURE_FUNC(shaper, object) (hb_##object##_t *object) \
|
||||
retry: \
|
||||
HB_SHAPER_DATA_TYPE (shaper, object) *data = (HB_SHAPER_DATA_TYPE (shaper, object) *) hb_atomic_ptr_get (&HB_SHAPER_DATA (shaper, object)); \
|
||||
if (likely (data) && !(condition)) { \
|
||||
/* Note that evaluating condition above can be dangerous if another thread \
|
||||
* got here first and destructed data. That's, as always, bad use pattern. \
|
||||
* If you modify the font (change font size), other threads must not be \
|
||||
* using it at the same time. */ \
|
||||
/* Drop and recreate. */ \
|
||||
/* If someone dropped it in the mean time, throw it away and don't touch it. \
|
||||
* Otherwise, destruct it. */ \
|
||||
|
||||
+28
-2
@@ -25,8 +25,34 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-face-private.hh"
|
||||
#include "hb-open-type-private.hh"
|
||||
#include "hb-ot-head-table.hh"
|
||||
#include "hb-ot-maxp-table.hh"
|
||||
|
||||
#ifndef HB_NO_VISIBILITY
|
||||
void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
|
||||
/*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
|
||||
|
||||
hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {};
|
||||
/*thread_local*/ hb_vector_size_impl_t _hb_CrapPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)] = {};
|
||||
|
||||
void
|
||||
hb_face_t::load_num_glyphs (void) const
|
||||
{
|
||||
OT::hb_sanitize_context_t c = OT::hb_sanitize_context_t();
|
||||
c.set_num_glyphs (0); /* So we don't recurse ad infinitum. */
|
||||
hb_blob_t *maxp_blob = c.reference_table<OT::maxp> (this);
|
||||
const OT::maxp *maxp_table = maxp_blob->as<OT::maxp> ();
|
||||
num_glyphs = maxp_table->get_num_glyphs ();
|
||||
hb_blob_destroy (maxp_blob);
|
||||
}
|
||||
|
||||
void
|
||||
hb_face_t::load_upem (void) const
|
||||
{
|
||||
hb_blob_t *head_blob = OT::hb_sanitize_context_t().reference_table<OT::head> (this);
|
||||
const OT::head *head_table = head_blob->as<OT::head> ();
|
||||
upem = head_table->get_upem ();
|
||||
hb_blob_destroy (head_blob);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -292,7 +292,7 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan,
|
||||
hb_blob_t **glyf_prime, /* OUT */
|
||||
hb_blob_t **loca_prime /* OUT */)
|
||||
{
|
||||
hb_blob_t *glyf_blob = OT::Sanitizer<OT::glyf>().sanitize (plan->source->reference_table (HB_OT_TAG_glyf));
|
||||
hb_blob_t *glyf_blob = OT::hb_sanitize_context_t().reference_table<OT::glyf> (plan->source);
|
||||
const char *glyf_data = hb_blob_get_data(glyf_blob, nullptr);
|
||||
|
||||
OT::glyf::accelerator_t glyf;
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
* Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-subset-private.hh"
|
||||
#include "hb-set-private.hh"
|
||||
|
||||
|
||||
@@ -56,11 +56,15 @@ _add_gid_and_children (const OT::glyf::accelerator_t &glyf,
|
||||
static void
|
||||
_gsub_closure (hb_face_t *face, hb_set_t *gids_to_retain)
|
||||
{
|
||||
// TODO(grieger): This uses all lookups, instead collect
|
||||
// the set of lookups that are relevant.
|
||||
// See fontTools implementation.
|
||||
hb_auto_t<hb_set_t> lookup_indices;
|
||||
hb_ot_layout_collect_lookups (face,
|
||||
HB_OT_TAG_GSUB,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&lookup_indices);
|
||||
hb_ot_layout_lookups_substitute_closure (face,
|
||||
nullptr,
|
||||
&lookup_indices,
|
||||
gids_to_retain);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "hb-subset.h"
|
||||
#include "hb-subset-private.hh"
|
||||
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-map-private.hh"
|
||||
|
||||
struct hb_subset_plan_t
|
||||
|
||||
+2
-5
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
#include "hb-open-type-private.hh"
|
||||
|
||||
#include "hb-subset-glyf.hh"
|
||||
@@ -80,9 +79,7 @@ template<typename TableType>
|
||||
static bool
|
||||
_subset (hb_subset_plan_t *plan)
|
||||
{
|
||||
OT::Sanitizer<TableType> sanitizer;
|
||||
|
||||
hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag));
|
||||
hb_blob_t *source_blob = OT::hb_sanitize_context_t().reference_table<TableType> (plan->source);
|
||||
const TableType *table = source_blob->as<TableType> ();
|
||||
|
||||
hb_tag_t tag = TableType::tableTag;
|
||||
@@ -155,7 +152,7 @@ _hb_subset_face_data_reference_blob (hb_subset_face_data_t *data)
|
||||
unsigned int face_length = table_count * 16 + 12;
|
||||
|
||||
for (unsigned int i = 0; i < table_count; i++)
|
||||
face_length += _hb_ceil_to_4 (hb_blob_get_length (data->tables.arrayZ[i].blob));
|
||||
face_length += hb_ceil_to_4 (hb_blob_get_length (data->tables.arrayZ[i].blob));
|
||||
|
||||
char *buf = (char *) malloc (face_length);
|
||||
if (unlikely (!buf))
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define HB_UNICODE_PRIVATE_HH
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-object-private.hh"
|
||||
|
||||
|
||||
extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256];
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "hb-private.hh"
|
||||
#include "hb-debug.hh"
|
||||
#define HB_SHAPER uniscribe
|
||||
#include "hb-shaper-impl-private.hh"
|
||||
|
||||
@@ -359,7 +358,7 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
|
||||
* full, PS. All of them point to the same name data with our unique name.
|
||||
*/
|
||||
|
||||
blob = OT::Sanitizer<OT::OpenTypeFontFile>().sanitize (blob);
|
||||
blob = OT::hb_sanitize_context_t().sanitize_blob<OT::OpenTypeFontFile> (blob);
|
||||
|
||||
unsigned int length, new_length, name_str_len;
|
||||
const char *orig_sfnt_data = hb_blob_get_data (blob, &length);
|
||||
|
||||
+2
-2
@@ -38,9 +38,9 @@ HB_BEGIN_DECLS
|
||||
|
||||
#define HB_VERSION_MAJOR 1
|
||||
#define HB_VERSION_MINOR 8
|
||||
#define HB_VERSION_MICRO 1
|
||||
#define HB_VERSION_MICRO 4
|
||||
|
||||
#define HB_VERSION_STRING "1.8.1"
|
||||
#define HB_VERSION_STRING "1.8.4"
|
||||
|
||||
#define HB_VERSION_ATLEAST(major,minor,micro) \
|
||||
((major)*10000+(minor)*100+(micro) <= \
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
* Google Author(s): Behdad Esfahbod
|
||||
*/
|
||||
|
||||
#include "hb-atomic-private.hh"
|
||||
#include "hb-mutex-private.hh"
|
||||
|
||||
#include "hb-private.hh"
|
||||
|
||||
#if defined(HB_ATOMIC_INT_NIL)
|
||||
#error "Could not find any system to define atomic_int macros, library WILL NOT be thread-safe"
|
||||
|
||||
+4
-2
@@ -51,8 +51,7 @@ main (int argc, char **argv)
|
||||
const char *font_data = hb_blob_get_data (blob, &len);
|
||||
printf ("Opened font file %s: %d bytes long\n", argv[1], len);
|
||||
|
||||
Sanitizer<OpenTypeFontFile> sanitizer;
|
||||
hb_blob_t *font_blob = sanitizer.sanitize (blob);
|
||||
hb_blob_t *font_blob = hb_sanitize_context_t().sanitize_blob<OpenTypeFontFile> (blob);
|
||||
const OpenTypeFontFile* sanitized = font_blob->as<OpenTypeFontFile> ();
|
||||
if (sanitized == &Null(OpenTypeFontFile))
|
||||
{
|
||||
@@ -78,6 +77,9 @@ main (int argc, char **argv)
|
||||
case OpenTypeFontFile::Typ1Tag:
|
||||
printf ("Obsolete Apple Type1 font in SFNT container\n");
|
||||
break;
|
||||
case OpenTypeFontFile::DFontTag:
|
||||
printf ("DFont Mac Resource Fork\n");
|
||||
break;
|
||||
default:
|
||||
printf ("Unknown font format\n");
|
||||
break;
|
||||
|
||||
@@ -9,6 +9,8 @@ MAINTAINERCLEANFILES =
|
||||
# Convenience targets:
|
||||
lib:
|
||||
@$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/src lib
|
||||
libs:
|
||||
@$(MAKE) $(AM_MAKEFLAGS) -C $(top_builddir)/src libs
|
||||
|
||||
EXTRA_DIST += CMakeLists.txt
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
@@ -396,8 +396,8 @@ test_get_min_connector_overlap (void)
|
||||
initFreeType();
|
||||
|
||||
openFont("fonts/MathTestFontEmpty.otf");
|
||||
g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, FALSE), ==, 0); // MathVariants not available
|
||||
g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, TRUE), ==, 0); // MathVariants not available
|
||||
g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_LTR), ==, 0); // MathVariants not available
|
||||
g_assert_cmpint(hb_ot_math_get_min_connector_overlap(hb_font, HB_DIRECTION_TTB), ==, 0); // MathVariants not available
|
||||
closeFont();
|
||||
|
||||
openFont("fonts/MathTestFontPartial1.otf");
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,6 @@
|
||||
../fonts/f443753e8ffe8e8aae606cfba158e00334b6efb1.ttf::U+179A,U+1784,U+17D2,U+179F,U+200C,U+17CA,U+17B8,U+0020:[uni179a=0+775|uni1784=1+1550|uni179f.sub=1+775|space=1+0|uni17ca=1+0|uni17b8=1@0,300+0|space=7+600]
|
||||
../fonts/f443753e8ffe8e8aae606cfba158e00334b6efb1.ttf::U+179A,U+1784,U+17D2,U+179F,U+17CA,U+17B8:[uni179a=0+775|uni1784=1+1550|uni179f.sub=1+775|uni17bb=1@-75,-700+0|uni17b8=1+0]
|
||||
../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200C,U+092F,U+093F:[uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni093F.750=3+397|uni092F=3+924]
|
||||
../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+092F,U+093F:[uni093F=0+398|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni092F=0+924]
|
||||
../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+091F,U+094D,U+200C,U+091F,U+094D,U+200D,U+092F,U+093F:[uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=3+876|uni094D=3@4,0+0|space=3+0|uni093F=6+398|uni091F=6+876|uni094D=6@4,0+0|space=6+0|uni092F=6+924]
|
||||
../fonts/8116e5d8fedfbec74e45dc350d2416d810bed8c4.ttf:--font-funcs=ft:U+091F,U+094D,U+200D,U+091F,U+094D,U+200D,U+091F,U+094D,U+200D,U+092F,U+093F:[uni093F=0+398|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni091F=0+876|uni094D=0@4,0+0|space=0+0|uni092F=0+924]
|
||||
@@ -2,4 +2,9 @@
|
||||
../fonts/4cce528e99f600ed9c25a2b69e32eb94a03b4ae8.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+0|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212]
|
||||
../fonts/f518eb6f6b5eec2946c9fbbbde44e45d46f5e2ac.ttf::U+1A48,U+1A58,U+1A25,U+1A48,U+1A58,U+1A25,U+1A6E,U+1A63:[uni1A48=0+1212|uni1A25=0+1912|uni1A58=0+0|uni1A48=3+1212|uni1A6E=3+1211|uni1A25=3+1912|uni1A58=3+0|uni1A63=3+1212]
|
||||
../fonts/6ff0fbead4462d9f229167b4e6839eceb8465058.ttf:--font-funcs=ot:U+11103,U+11128:[u11103=0+837|u11128=0+0]
|
||||
../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+1112E:[u11124=0+514|u11131=0+0|u11127=0+0]
|
||||
../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11131,U+11127:[u11124=0+514|u11131=0+0|u11127=0+0]
|
||||
../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11127,U+11131:[u11124=0+514|u11127=0+0|uni25CC=0+547|u11131=0+0]
|
||||
../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11134,U+11131:[u11124=0+514|u11134=0+0|u11131=0+0]
|
||||
../fonts/2a670df15b73a5dc75a5cc491bde5ac93c5077dc.ttf::U+11124,U+11131,U+11134:[u11124=0+514|u11131=0+0|uni25CC=0+547|u11134=0+0]
|
||||
../fonts/573d3a3177c9a8646e94c8a0d7b224334340946a.ttf:--font-funcs=ft:U+11410,U+11442,U+11411,U+11440,U+11443,U+11410,U+11442,U+11411,U+11441,U+11443:[E_dv.alt=0+275|Ga.icd=0+367|Gha.diag=0@100,0+386|AA_dv.alt=0+208|Candrabindu=0@17,-8+0|E_dv.alt=5+275|Ga.icd=5+367|Gha.diag=5@100,0+386|AU_dv_part.alt=5+213|Candrabindu.sm=5@-52,179+0]
|
||||
+57
-44
@@ -15,75 +15,94 @@ import tempfile
|
||||
|
||||
from subset_test_suite import SubsetTestSuite
|
||||
|
||||
# https://stackoverflow.com/a/377028
|
||||
def which(program):
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, _ = os.path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
exe_file = os.path.join(path, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
|
||||
ttx = which ("ttx")
|
||||
ots_sanitize = which ("ots-sanitize")
|
||||
|
||||
if not ttx:
|
||||
print("TTX is not present, skipping test.")
|
||||
sys.exit (77)
|
||||
|
||||
def cmd(command):
|
||||
p = subprocess.Popen (
|
||||
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdoutdata, stderrdata) = p.communicate()
|
||||
(stdoutdata, stderrdata) = p.communicate ()
|
||||
print (stderrdata, end="") # file=sys.stderr
|
||||
return stdoutdata, p.returncode
|
||||
|
||||
def read_binary(file_path):
|
||||
with open(file_path, 'rb') as f:
|
||||
return f.read()
|
||||
def read_binary (file_path):
|
||||
with open (file_path, 'rb') as f:
|
||||
return f.read ()
|
||||
|
||||
def fail_test(test, cli_args, message):
|
||||
print ('ERROR: %s' % message)
|
||||
print ('Test State:')
|
||||
print (' test.font_path %s' % os.path.abspath(test.font_path))
|
||||
print (' test.profile_path %s' % os.path.abspath(test.profile_path))
|
||||
print (' test.unicodes %s' % test.unicodes())
|
||||
expected_file = os.path.join(test_suite.get_output_directory(),
|
||||
test.get_font_name())
|
||||
print (' expected_file %s' % os.path.abspath(expected_file))
|
||||
print (' test.font_path %s' % os.path.abspath (test.font_path))
|
||||
print (' test.profile_path %s' % os.path.abspath (test.profile_path))
|
||||
print (' test.unicodes %s' % test.unicodes ())
|
||||
expected_file = os.path.join(test_suite.get_output_directory (),
|
||||
test.get_font_name ())
|
||||
print (' expected_file %s' % os.path.abspath (expected_file))
|
||||
return 1
|
||||
|
||||
def run_test(test, should_check_ots):
|
||||
out_file = os.path.join(tempfile.mkdtemp(), test.get_font_name() + '-subset.ttf')
|
||||
out_file = os.path.join(tempfile.mkdtemp (), test.get_font_name () + '-subset.ttf')
|
||||
cli_args = [hb_subset,
|
||||
"--font-file=" + test.font_path,
|
||||
"--output-file=" + out_file,
|
||||
"--unicodes=%s" % test.unicodes()]
|
||||
cli_args.extend (test.get_profile_flags())
|
||||
print (' '.join(cli_args))
|
||||
_, return_code = cmd(cli_args)
|
||||
"--unicodes=%s" % test.unicodes ()]
|
||||
cli_args.extend (test.get_profile_flags ())
|
||||
print (' '.join (cli_args))
|
||||
_, return_code = cmd (cli_args)
|
||||
|
||||
if return_code:
|
||||
return fail_test(test, cli_args, "%s returned %d" % (' '.join(cli_args), return_code))
|
||||
return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code))
|
||||
|
||||
expected_ttx, return_code = run_ttx(os.path.join(test_suite.get_output_directory(),
|
||||
test.get_font_name()))
|
||||
expected_ttx, return_code = run_ttx (os.path.join (test_suite.get_output_directory (),
|
||||
test.get_font_name ()))
|
||||
if return_code:
|
||||
return fail_test(test, cli_args, "ttx (expected) returned %d" % (return_code))
|
||||
return fail_test (test, cli_args, "ttx (expected) returned %d" % (return_code))
|
||||
|
||||
actual_ttx, return_code = run_ttx(out_file)
|
||||
if return_code:
|
||||
return fail_test(test, cli_args, "ttx (actual) returned %d" % (return_code))
|
||||
return fail_test (test, cli_args, "ttx (actual) returned %d" % (return_code))
|
||||
|
||||
print ("stripping checksums.")
|
||||
expected_ttx = strip_check_sum (expected_ttx)
|
||||
actual_ttx = strip_check_sum (actual_ttx)
|
||||
|
||||
if not actual_ttx == expected_ttx:
|
||||
for line in unified_diff(expected_ttx.splitlines(1), actual_ttx.splitlines(1)):
|
||||
sys.stdout.write(line)
|
||||
sys.stdout.flush()
|
||||
for line in unified_diff (expected_ttx.splitlines (1), actual_ttx.splitlines (1)):
|
||||
sys.stdout.write (line)
|
||||
sys.stdout.flush ()
|
||||
return fail_test(test, cli_args, 'ttx for expected and actual does not match.')
|
||||
|
||||
if should_check_ots:
|
||||
print ("Checking output with ots-sanitize.")
|
||||
if not check_ots(out_file):
|
||||
return fail_test(test, cli_args, 'ots for subsetted file fails.')
|
||||
if not check_ots (out_file):
|
||||
return fail_test (test, cli_args, 'ots for subsetted file fails.')
|
||||
|
||||
return 0
|
||||
|
||||
def run_ttx(file):
|
||||
def run_ttx (file):
|
||||
print ("ttx %s" % file)
|
||||
cli_args = ["ttx",
|
||||
"-q",
|
||||
"-o-",
|
||||
file]
|
||||
return cmd(cli_args)
|
||||
return cmd([ttx, "-q", "-o-", file])
|
||||
|
||||
def strip_check_sum (ttx_string):
|
||||
return re.sub ('checkSumAdjustment value=["]0x([0-9a-fA-F])+["]',
|
||||
@@ -91,14 +110,13 @@ def strip_check_sum (ttx_string):
|
||||
ttx_string.decode (), count=1)
|
||||
|
||||
def has_ots ():
|
||||
_, returncode = cmd(["which", "ots-sanitize"])
|
||||
if returncode:
|
||||
if not ots_sanitize:
|
||||
print("OTS is not present, skipping all ots checks.")
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_ots (path):
|
||||
ots_report, returncode = cmd(["ots-sanitize", path])
|
||||
ots_report, returncode = cmd ([ots_sanitize, path])
|
||||
if returncode:
|
||||
print("OTS Failure: %s" % ots_report);
|
||||
return False
|
||||
@@ -110,24 +128,19 @@ if not args or sys.argv[1].find('hb-subset') == -1 or not os.path.exists (sys.ar
|
||||
sys.exit (1)
|
||||
hb_subset, args = args[0], args[1:]
|
||||
|
||||
if not len(args):
|
||||
if not len (args):
|
||||
print ("No tests supplied.")
|
||||
sys.exit (1)
|
||||
|
||||
_, returncode = cmd(["which", "ttx"])
|
||||
if returncode:
|
||||
print("TTX is not present, skipping test.")
|
||||
sys.exit (77)
|
||||
|
||||
has_ots = has_ots()
|
||||
|
||||
fails = 0
|
||||
for path in args:
|
||||
with io.open(path, mode="r", encoding="utf-8") as f:
|
||||
with io.open (path, mode="r", encoding="utf-8") as f:
|
||||
print ("Running tests in " + path)
|
||||
test_suite = SubsetTestSuite(path, f.read())
|
||||
for test in test_suite.tests():
|
||||
fails += run_test(test, has_ots)
|
||||
test_suite = SubsetTestSuite (path, f.read())
|
||||
for test in test_suite.tests ():
|
||||
fails += run_test (test, has_ots)
|
||||
|
||||
if fails != 0:
|
||||
print (str (fails) + " test(s) failed.")
|
||||
|
||||
+10
-4
@@ -89,10 +89,16 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
|
||||
atexit (free_ft_library);
|
||||
#endif
|
||||
}
|
||||
FT_New_Face (ft_library,
|
||||
font_opts->font_file,
|
||||
font_opts->face_index,
|
||||
&ft_face);
|
||||
|
||||
unsigned int blob_length;
|
||||
const char *blob_data = hb_blob_get_data (font_opts->blob, &blob_length);
|
||||
|
||||
if (FT_New_Memory_Face (ft_library,
|
||||
(const FT_Byte *) blob_data,
|
||||
blob_length,
|
||||
font_opts->face_index,
|
||||
&ft_face))
|
||||
fail (false, "FT_New_Memory_Face fail");
|
||||
}
|
||||
if (!ft_face)
|
||||
{
|
||||
|
||||
+12
-19
@@ -643,34 +643,27 @@ font_options_t::get_font (void) const
|
||||
if (font)
|
||||
return font;
|
||||
|
||||
hb_blob_t *blob = nullptr;
|
||||
|
||||
/* Create the blob */
|
||||
if (!font_file)
|
||||
fail (true, "No font file set");
|
||||
|
||||
if (0 == strcmp (font_file, "-")) {
|
||||
/* read it */
|
||||
GString *gs = g_string_new (nullptr);
|
||||
char buf[BUFSIZ];
|
||||
const char *font_path = font_file;
|
||||
|
||||
if (0 == strcmp (font_path, "-"))
|
||||
{
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
setmode (fileno (stdin), O_BINARY);
|
||||
font_path = "STDIN";
|
||||
#else
|
||||
font_path = "/dev/stdin";
|
||||
#endif
|
||||
while (!feof (stdin)) {
|
||||
size_t ret = fread (buf, 1, sizeof (buf), stdin);
|
||||
if (ferror (stdin))
|
||||
fail (false, "Failed reading font from standard input: %s",
|
||||
strerror (errno));
|
||||
g_string_append_len (gs, buf, ret);
|
||||
}
|
||||
char *font_data = g_string_free (gs, false);
|
||||
blob = hb_blob_create (font_data, gs->len,
|
||||
HB_MEMORY_MODE_WRITABLE, font_data,
|
||||
(hb_destroy_func_t) g_free);
|
||||
} else {
|
||||
blob = hb_blob_create_from_file (font_file);
|
||||
}
|
||||
|
||||
blob = hb_blob_create_from_file (font_path);
|
||||
|
||||
if (blob == hb_blob_get_empty ())
|
||||
fail (false, "No such file or directory");
|
||||
|
||||
/* Create the face */
|
||||
hb_face_t *face = hb_face_create (blob, face_index);
|
||||
hb_blob_destroy (blob);
|
||||
|
||||
@@ -455,6 +455,7 @@ struct font_options_t : option_group_t
|
||||
font_size_x = font_size_y = default_font_size;
|
||||
font_funcs = nullptr;
|
||||
|
||||
blob = nullptr;
|
||||
font = nullptr;
|
||||
|
||||
add_options (parser);
|
||||
@@ -471,6 +472,7 @@ struct font_options_t : option_group_t
|
||||
hb_font_t *get_font (void) const;
|
||||
|
||||
char *font_file;
|
||||
mutable hb_blob_t *blob;
|
||||
int face_index;
|
||||
hb_variation_t *variations;
|
||||
unsigned int num_variations;
|
||||
|
||||
Reference in new issue
Block a user