diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-01-03 09:48:38 +0000 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-01-03 09:48:38 +0000 |
commit | 56cfeda664bae608ccd21e46d36e867647ec770c (patch) | |
tree | 77a1fc0fd1cca97981b9d8c8bbbe836ba8775137 /Build/source/libs/harfbuzz/harfbuzz-0.9.10/src | |
parent | f1bd5839458f018b2c34831a49f52dd57dc00164 (diff) |
harfbuzz-0.9.10
git-svn-id: svn://tug.org/texlive/trunk@28708 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-0.9.10/src')
105 files changed, 34684 insertions, 0 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/Makefile.am b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/Makefile.am new file mode 100644 index 00000000000..558ce08ead9 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/Makefile.am @@ -0,0 +1,321 @@ +# Process this file with automake to produce Makefile.in + +NULL = +SUBDIRS = +DIST_SUBDIRS = +BUILT_SOURCES = +EXTRA_DIST = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = +DISTCHECK_CONFIGURE_FLAGS = --enable-introspection + +# The following warning options are useful for debugging: -Wpadded +#AM_CXXFLAGS = + +lib_LTLIBRARIES = libharfbuzz.la + +HBCFLAGS = +HBLIBS = +HBSOURCES = \ + hb-atomic-private.hh \ + hb-blob.cc \ + hb-buffer-private.hh \ + hb-buffer.cc \ + hb-cache-private.hh \ + hb-common.cc \ + hb-fallback-shape.cc \ + hb-font-private.hh \ + hb-font.cc \ + hb-mutex-private.hh \ + hb-object-private.hh \ + hb-open-file-private.hh \ + hb-open-type-private.hh \ + hb-ot-head-table.hh \ + hb-ot-hhea-table.hh \ + hb-ot-hmtx-table.hh \ + hb-ot-maxp-table.hh \ + hb-ot-name-table.hh \ + hb-ot-tag.cc \ + hb-private.hh \ + hb-set-private.hh \ + hb-set.cc \ + hb-shape.cc \ + hb-shape-plan-private.hh \ + hb-shape-plan.cc \ + hb-shaper-list.hh \ + hb-shaper-impl-private.hh \ + hb-shaper-private.hh \ + hb-shaper.cc \ + hb-tt-font.cc \ + hb-unicode-private.hh \ + hb-unicode.cc \ + hb-utf-private.hh \ + hb-warning.cc \ + $(NULL) +HBHEADERS = \ + hb.h \ + hb-blob.h \ + hb-buffer.h \ + hb-common.h \ + hb-font.h \ + hb-set.h \ + hb-shape.h \ + hb-shape-plan.h \ + hb-unicode.h \ + hb-version.h \ + $(NULL) + +if HAVE_OT +HBSOURCES += \ + hb-ot-layout.cc \ + hb-ot-layout-common-private.hh \ + hb-ot-layout-gdef-table.hh \ + hb-ot-layout-gpos-table.hh \ + hb-ot-layout-gsubgpos-private.hh \ + hb-ot-layout-gsub-table.hh \ + hb-ot-layout-private.hh \ + hb-ot-map.cc \ + hb-ot-map-private.hh \ + hb-ot-shape.cc \ + hb-ot-shape-complex-arabic.cc \ + hb-ot-shape-complex-arabic-fallback.hh \ + hb-ot-shape-complex-arabic-table.hh \ + hb-ot-shape-complex-default.cc \ + hb-ot-shape-complex-indic.cc \ + hb-ot-shape-complex-indic-machine.hh \ + hb-ot-shape-complex-indic-private.hh \ + hb-ot-shape-complex-indic-table.hh \ + hb-ot-shape-complex-thai.cc \ + hb-ot-shape-complex-private.hh \ + hb-ot-shape-normalize-private.hh \ + hb-ot-shape-normalize.cc \ + hb-ot-shape-fallback-private.hh \ + hb-ot-shape-fallback.cc \ + hb-ot-shape-private.hh \ + $(NULL) +HBHEADERS += \ + hb-ot.h \ + hb-ot-layout.h \ + hb-ot-tag.h \ + $(NULL) +endif + +if HAVE_PTHREAD +HBCFLAGS += $(PTHREAD_CFLAGS) +HBLIBS += $(PTHREAD_LIBS) +endif + +if HAVE_GLIB +HBCFLAGS += $(GLIB_CFLAGS) +HBLIBS += $(GLIB_LIBS) +HBSOURCES += hb-glib.cc +HBHEADERS += hb-glib.h +endif + +if HAVE_GOBJECT +HBCFLAGS += $(GOBJECT_CFLAGS) +HBLIBS += $(GOBJECT_LIBS) +HBSOURCES += hb-gobject-structs.cc +nodist_HBSOURCES = hb-gobject-enums.cc +HBHEADERS += hb-gobject.h +BUILT_SOURCES += hb-gobject-enums.cc +EXTRA_DIST += hb-gobject-enums.cc.tmpl +DISTCLEANFILES += hb-gobject-enums.cc + +hb-gobject-enums.cc: hb-gobject-enums.cc.tmpl $(HBHEADERS) + $(AM_V_GEN) $(GLIB_MKENUMS) --template $^ > "$@.tmp" && \ + mv "$@.tmp" "$@" || ( $(RM) "@.tmp" && false ) +endif + +if HAVE_ICU +HBCFLAGS += $(ICU_CFLAGS) +HBLIBS += $(ICU_LIBS) +HBSOURCES += hb-icu.cc +HBHEADERS += hb-icu.h +endif + +if HAVE_FREETYPE +HBCFLAGS += $(FREETYPE_CFLAGS) +HBLIBS += $(FREETYPE_LIBS) +HBSOURCES += hb-ft.cc +HBHEADERS += hb-ft.h +endif + +if HAVE_GRAPHITE2 +HBCFLAGS += $(GRAPHITE2_CFLAGS) +HBLIBS += $(GRAPHITE2_LIBS) +HBSOURCES += hb-graphite2.cc +HBHEADERS += hb-graphite2.h +endif + +if HAVE_UNISCRIBE +HBCFLAGS += $(UNISCRIBE_CFLAGS) +HBLIBS += $(UNISCRIBE_LIBS) +HBSOURCES += hb-uniscribe.cc +HBHEADERS += hb-uniscribe.h +endif + +if HAVE_CORETEXT +HBCFLAGS += $(CORETEXT_CFLAGS) +HBLIBS += $(CORETEXT_LIBS) +HBSOURCES += hb-coretext.cc +HBHEADERS += hb-coretext.h +endif + +if HAVE_HB_OLD +SUBDIRS += hb-old +HBCFLAGS += -I$(srcdir)/hb-old +HBLIBS += hb-old/libhb-old.la +HBSOURCES += hb-old.cc +endif +DIST_SUBDIRS += hb-old + +if HAVE_ICU_LE +SUBDIRS += hb-icu-le +HBCFLAGS += -I$(srcdir)/hb-icu-le +HBLIBS += hb-icu-le/libhb-icu-le.la +HBSOURCES += hb-icu-le.cc +endif +DIST_SUBDIRS += hb-icu-le + +if HAVE_UCDN +SUBDIRS += hb-ucdn +HBCFLAGS += -I$(srcdir)/hb-ucdn +HBLIBS += hb-ucdn/libhb-ucdn.la +HBSOURCES += hb-ucdn.cc +endif +DIST_SUBDIRS += hb-ucdn + + +# Put the library together + +if OS_WIN32 +export_symbols = -export-symbols harfbuzz.def +harfbuzz_def_dependency = harfbuzz.def +libharfbuzz_la_LINK = $(CXXLINK) $(libharfbuzz_la_LDFLAGS) +else +if HAVE_ICU +libharfbuzz_la_LINK = $(CXXLINK) $(libharfbuzz_la_LDFLAGS) +else +# Use a C linker, not C++; Don't link to libstdc++ +libharfbuzz_la_LINK = $(LINK) $(libharfbuzz_la_LDFLAGS) +endif +endif + +libharfbuzz_la_SOURCES = $(HBSOURCES) $(HBHEADERS) +nodist_libharfbuzz_la_SOURCES = $(nodist_HBSOURCES) +libharfbuzz_la_CPPFLAGS = $(HBCFLAGS) +libharfbuzz_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(HB_LIBTOOL_VERSION_INFO) $(export_symbols) -no-undefined +libharfbuzz_la_LIBADD = $(HBLIBS) +EXTRA_libharfbuzz_la_DEPENDENCIES = $(harfbuzz_def_dependency) +pkginclude_HEADERS = $(HBHEADERS) +nodist_pkginclude_HEADERS = hb-version.h + +CLEANFILES += harfbuzz.def +harfbuzz.def: $(HBHEADERS) + $(AM_V_GEN) (echo EXPORTS; \ + (cat $^ || echo 'hb_ERROR ()' ) | \ + $(EGREP) '^hb_.* \(' | \ + sed -e 's/ (.*//' | \ + LANG=C sort; \ + echo LIBRARY libharfbuzz-$(HB_VERSION_MAJOR).dll; \ + ) >"$@.tmp" + @ ! grep -q hb_ERROR "$@.tmp" && mv "$@.tmp" "$@" || ($(RM) "$@"; false) + + +GENERATORS = \ + gen-arabic-table.py \ + gen-indic-table.py \ + $(NULL) + +EXTRA_DIST += $(GENERATORS) + +unicode-tables: arabic-table indic-table + +indic-table: gen-indic-table.py IndicSyllabicCategory.txt IndicMatraCategory.txt Blocks.txt + $(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-indic-table.hh.tmp && \ + mv hb-ot-shape-complex-indic-table.hh.tmp $(srcdir)/hb-ot-shape-complex-indic-table.hh || \ + ($(RM) hb-ot-shape-complex-indic-table.hh.tmp; false) + +arabic-table: gen-arabic-table.py ArabicShaping.txt UnicodeData.txt + $(AM_V_GEN) $(builddir)/$^ > hb-ot-shape-complex-arabic-table.hh.tmp && \ + mv hb-ot-shape-complex-arabic-table.hh.tmp $(srcdir)/hb-ot-shape-complex-arabic-table.hh || \ + ($(RM) hb-ot-shape-complex-arabic-table.hh.tmp; false) + + +.PHONY: unicode-tables arabic-table indic-table + +EXTRA_DIST += hb-ot-shape-complex-indic-machine.rl +$(srcdir)/hb-ot-shape-complex-indic-machine.hh: hb-ot-shape-complex-indic-machine.rl + $(AM_V_GEN)$(top_srcdir)/missing --run ragel -e -F1 -o "$@.tmp" "$<" && \ + mv "$@.tmp" "$@" || ( $(RM) "$@.tmp" && false ) + +noinst_PROGRAMS = main test test-would-substitute test-size-params +bin_PROGRAMS = + +main_SOURCES = main.cc +main_CPPFLAGS = $(HBCFLAGS) +main_LDADD = libharfbuzz.la $(HBLIBS) + +test_SOURCES = test.cc +test_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) +test_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) + +test_would_substitute_SOURCES = test-would-substitute.cc +test_would_substitute_CPPFLAGS = $(HBCFLAGS) $(FREETYPE_CFLAGS) +test_would_substitute_LDADD = libharfbuzz.la $(HBLIBS) $(FREETYPE_LIBS) + +test_size_params_SOURCES = test-size-params.cc +test_size_params_CPPFLAGS = $(HBCFLAGS) +test_size_params_LDADD = libharfbuzz.la $(HBLIBS) + +dist_check_SCRIPTS = \ + check-c-linkage-decls.sh \ + check-header-guards.sh \ + check-exported-symbols.sh \ + check-includes.sh \ + check-internal-symbols.sh \ + $(NULL) + +if HAVE_ICU +else +dist_check_SCRIPTS += check-libstdc++.sh +endif + +if HAVE_ICU_LE +else +dist_check_SCRIPTS += check-static-inits.sh +endif + +TESTS = $(dist_check_SCRIPTS) +TESTS_ENVIRONMENT = \ + srcdir="$(srcdir)" \ + MAKE="$(MAKE) $(AM_MAKEFLAGS)" \ + HBSOURCES="$(HBSOURCES)" \ + HBHEADERS="$(HBHEADERS)" \ + $(NULL) + +#-include $(INTROSPECTION_MAKEFILE) +#INTROSPECTION_GIRS = hb-1.0.gir +#INTROSPECTION_SCANNER_ARGS = -I$(srcdir) -n hb --identifier-prefix=hb_ +#INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) +# +#if HAVE_INTROSPECTION +# +#hb-1.0.gir: libharfbuzz.la +#hb_1_0_gir_INCLUDES = GObject-2.0 +#hb_1_0_gir_CFLAGS = $(INCLUDES) $(HBCFLAGS) -DHB_H -DHB_H_IN -DHB_OT_H -DHB_OT_H_IN +#hb_1_0_gir_LIBS = libharfbuzz.la +#hb_1_0_gir_FILES = $(HBHEADERS) +# +#girdir = $(datadir)/gir-1.0 +#gir_DATA = $(INTROSPECTION_GIRS) +# +#typelibdir = $(libdir)/girepository-1.0 +#typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) +# +#CLEANFILES += $(gir_DATA) $(typelib_DATA) +#endif + +-include $(top_srcdir)/git.mk diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-c-linkage-decls.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-c-linkage-decls.sh new file mode 100755 index 00000000000..44cdfa0f23c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-c-linkage-decls.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + +test "x$HBHEADERS" = x && HBHEADERS=`find . -maxdepth 1 -name 'hb*.h'` +test "x$HBSOURCES" = x && HBSOURCES=`find . -maxdepth 1 -name 'hb*.h'` + + +for x in $HBHEADERS; do + test -f $srcdir/$x && x=$srcdir/$x + if ! grep -q HB_BEGIN_DECLS "$x" || ! grep -q HB_END_DECLS "$x"; then + echo "Ouch, file $x does not have HB_BEGIN_DECLS / HB_END_DECLS, but it should" + stat=1 + fi +done +for x in $HBSOURCES; do + test -f $srcdir/$x && x=$srcdir/$x + if grep -q HB_BEGIN_DECLS "$x" || grep -q HB_END_DECLS "$x"; then + echo "Ouch, file $x has HB_BEGIN_DECLS / HB_END_DECLS, but it shouldn't" + stat=1 + fi +done + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-exported-symbols.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-exported-symbols.sh new file mode 100755 index 00000000000..6f0bf7fd823 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-exported-symbols.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +test -z "$MAKE" && MAKE=make +stat=0 + +if which nm 2>/dev/null >/dev/null; then + : +else + echo "check-exported-symbols.sh: 'nm' not found; skipping test" + exit 77 +fi + +defs="harfbuzz.def" +$MAKE $defs > /dev/null +tested=false +for def in $defs; do + lib=`echo "$def" | sed 's/[.]def$//;s@.*/@@'` + so=.libs/lib${lib}.so + if test -f "$so"; then + echo "Checking that $so has the same symbol list as $def" + { + echo EXPORTS + nm "$so" | grep ' [BCDGINRSTVW] ' | grep -v ' T _fini\>\| T _init\>\| __bss_start\>\| __bss_start__\>\| __bss_end__\>\| _edata\>\| _end\>\| _bss_end__\>\| __end__\>' | cut -d' ' -f3 + stat=1 + # cheat: copy the last line from the def file! + tail -n1 "$def" + } | diff "$def" - >&2 || stat=1 + tested=true + fi +done +if ! $tested; then + echo "check-exported-symbols.sh: libharfbuzz shared library not found; skipping test" + exit 77 +fi + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-header-guards.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-header-guards.sh new file mode 100755 index 00000000000..af9fa7fc24e --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-header-guards.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + +test "x$HBHEADERS" = x && HBHEADERS=`find . -maxdepth 1 -name 'hb*.h'` +test "x$HBSOURCES" = x && HBSOURCES=`find . -maxdepth 1 -name 'hb-*.cc' -or -name 'hb-*.hh'` + + +for x in $HBHEADERS $HBSOURCES; do + test -f "$srcdir/$x" && x="$srcdir/$x" + echo "$x" | grep '[^h]$' -q && continue; + xx=`echo "$x" | sed 's@.*/@@'` + tag=`echo "$xx" | tr 'a-z.-' 'A-Z_'` + lines=`grep "\<$tag\>" "$x" | wc -l | sed 's/[ ]*//g'` + if test "x$lines" != x3; then + echo "Ouch, header file $x does not have correct preprocessor guards" + stat=1 + fi +done + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-includes.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-includes.sh new file mode 100755 index 00000000000..79323a74fb2 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-includes.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + +test "x$HBHEADERS" = x && HBHEADERS=`find . -maxdepth 1 -name 'hb*.h'` +test "x$HBSOURCES" = x && HBSOURCES=`find . -maxdepth 1 -name 'hb-*.cc' -or -name 'hb-*.hh'` + + +cd "$srcdir" + + +echo 'Checking that public header files #include "hb-common.h" or "hb.h" first (or none)' + +for x in $HBHEADERS; do + grep '#.*\<include\>' "$x" /dev/null | head -n 1 +done | +grep -v '"hb-common[.]h"' | +grep -v '"hb[.]h"' | +grep -v 'hb-common[.]h:' | +grep -v 'hb[.]h:' | +grep . >&2 && stat=1 + + +echo 'Checking that source files #include "hb-*private.hh" first (or none)' + +for x in $HBSOURCES; do + grep '#.*\<include\>' "$x" /dev/null | head -n 1 +done | +grep -v '"hb-.*private[.]hh"' | +grep -v 'hb-private[.]hh:' | +grep . >&2 && stat=1 + + +echo 'Checking that there is no #include <hb.*.h>' +grep '#.*\<include\>.*<.*hb' $HBHEADERS $HBSOURCES >&2 && stat=1 + + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-internal-symbols.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-internal-symbols.sh new file mode 100755 index 00000000000..a8fdc537dd7 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-internal-symbols.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + + +if which nm 2>/dev/null >/dev/null; then + : +else + echo "check-internal-symbols.sh: 'nm' not found; skipping test" + exit 77 +fi + +tested=false +for suffix in .so; do + so=`echo .libs/libharfbuzz$suffix` + if test -f "$so"; then + echo "Checking that we are not exposing internal symbols" + if nm "$so" | grep ' [BCDGINRSTVW] ' | grep -v ' T _fini\>\| T _init\>\| T hb_\| __bss_start\>\| __bss_start__\>\| __bss_end__\>\| _edata\>\| _end\>\| _bss_end__\>\| __end__\>'; then + echo "Ouch, internal symbols exposed" + stat=1 + fi + tested=true + fi +done +if ! $tested; then + echo "check-internal-symbols.sh: libharfbuzz shared library not found; skipping test" + exit 77 +fi + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-libstdc++.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-libstdc++.sh new file mode 100755 index 00000000000..e7e0e295e1a --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-libstdc++.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + + +if which ldd 2>/dev/null >/dev/null; then + : +else + echo "check-libstdc++.sh: 'ldd' not found; skipping test" + exit 77 +fi + +tested=false +for suffix in so dylib; do + so=.libs/libharfbuzz.$suffix + if test -f "$so"; then + echo "Checking that we are not linking to libstdc++" + if ldd $so | grep 'libstdc[+][+]'; then + echo "Ouch, linked to libstdc++" + stat=1 + fi + tested=true + fi +done +if ! $tested; then + echo "check-libstdc++.sh: libharfbuzz shared library not found; skipping test" + exit 77 +fi + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-static-inits.sh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-static-inits.sh new file mode 100755 index 00000000000..bb0a7ff630d --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/check-static-inits.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +LC_ALL=C +export LC_ALL + +test -z "$srcdir" && srcdir=. +stat=0 + + +if which objdump 2>/dev/null >/dev/null; then + : +else + echo "check-static-inits.sh: 'objdump' not found; skipping test" + exit 77 +fi + +OBJS=.libs/*.o +if test "x`echo $OBJS`" = "x$OBJS" 2>/dev/null >/dev/null; then + echo "check-static-inits.sh: object files not found; skipping test" + exit 77 +fi + +echo "Checking that no object file has static initializers" +for obj in $OBJS; do + if objdump -t "$obj" | grep '[.]ctors'; then + echo "Ouch, $obj has static initializers" + stat=1 + fi +done + +echo "Checking that no object file has lazy static C++ constructors/destructors or other such stuff" +for obj in $OBJS; do + if objdump -t "$obj" | grep '__c'; then + echo "Ouch, $obj has lazy static C++ constructors/destructors or other such stuff" + stat=1 + fi +done + +exit $stat diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-arabic-table.py b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-arabic-table.py new file mode 100755 index 00000000000..da5a4fcbf5c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-arabic-table.py @@ -0,0 +1,197 @@ +#!/usr/bin/python + +import sys +import os.path + +if len (sys.argv) != 3: + print >>sys.stderr, "usage: ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt" + sys.exit (1) + +files = [file (x) for x in sys.argv[1:]] + +headers = [[files[0].readline (), files[0].readline ()]] +headers.append (["UnicodeData.txt does not have a header."]) +while files[0].readline ().find ('##################') < 0: + pass + + +def print_joining_table(f): + + print + print "static const uint8_t joining_table[] =" + print "{" + + min_u = 0x110000 + max_u = 0 + num = 0 + last = -1 + block = '' + for line in f: + + if line[0] == '#': + if line.find (" characters"): + block = line[2:].strip () + continue + + fields = [x.strip () for x in line.split (';')] + if len (fields) == 1: + continue + + u = int (fields[0], 16) + if u == 0x200C or u == 0x200D: + continue + if u < last: + raise Exception ("Input data character not sorted", u) + min_u = min (min_u, u) + max_u = max (max_u, u) + num += 1 + + if block: + print "\n /* %s */\n" % block + block = '' + + if last != -1: + last += 1 + while last < u: + print " JOINING_TYPE_X, /* %04X */" % last + last += 1 + else: + last = u + + if fields[3] in ["ALAPH", "DALATH RISH"]: + value = "JOINING_GROUP_" + fields[3].replace(' ', '_') + else: + value = "JOINING_TYPE_" + fields[2] + print " %s, /* %s */" % (value, '; '.join(fields)) + + print + print "};" + print + print "#define JOINING_TABLE_FIRST 0x%04X" % min_u + print "#define JOINING_TABLE_LAST 0x%04X" % max_u + print + + occupancy = num * 100 / (max_u - min_u + 1) + # Maintain at least 40% occupancy in the table */ + if occupancy < 40: + raise Exception ("Table too sparse, please investigate: ", occupancy) + +def print_shaping_table(f): + + shapes = {} + ligatures = {} + names = {} + for line in f: + + fields = [x.strip () for x in line.split (';')] + if fields[5][0:1] != '<': + continue + + items = fields[5].split (' ') + shape, items = items[0][1:-1], tuple (int (x, 16) for x in items[1:]) + + if not shape in ['initial', 'medial', 'isolated', 'final']: + continue + + c = int (fields[0], 16) + if len (items) != 1: + # We only care about lam-alef ligatures + if len (items) != 2 or items[0] != 0x0644 or items[1] not in [0x0622, 0x0623, 0x0625, 0x0627]: + continue + + # Save ligature + names[c] = fields[1] + if items not in ligatures: + ligatures[items] = {} + ligatures[items][shape] = c + pass + else: + # Save shape + if items[0] not in names: + names[items[0]] = fields[1] + else: + names[items[0]] = os.path.commonprefix ([names[items[0]], fields[1]]).strip () + if items[0] not in shapes: + shapes[items[0]] = {} + shapes[items[0]][shape] = c + + print + print "static const uint16_t shaping_table[][4] =" + print "{" + + keys = shapes.keys () + min_u, max_u = min (keys), max (keys) + for u in range (min_u, max_u + 1): + s = [shapes[u][shape] if u in shapes and shape in shapes[u] else 0 + for shape in ['initial', 'medial', 'final', 'isolated']] + value = ', '.join ("0x%04X" % c for c in s) + print " {%s}, /* U+%04X %s */" % (value, u, names[u] if u in names else "") + + print "};" + print + print "#define SHAPING_TABLE_FIRST 0x%04X" % min_u + print "#define SHAPING_TABLE_LAST 0x%04X" % max_u + print + + ligas = {} + for pair in ligatures.keys (): + for shape in ligatures[pair]: + c = ligatures[pair][shape] + if shape == 'isolated': + liga = (shapes[pair[0]]['initial'], shapes[pair[1]]['final']) + elif shape == 'final': + liga = (shapes[pair[0]]['medial'], shapes[pair[1]]['final']) + else: + raise Exception ("Unexpected shape", shape) + if liga[0] not in ligas: + ligas[liga[0]] = [] + ligas[liga[0]].append ((liga[1], c)) + max_i = max (len (ligas[l]) for l in ligas) + print + print "static const struct ligature_set_t {" + print " uint16_t first;" + print " struct ligature_pairs_t {" + print " uint16_t second;" + print " uint16_t ligature;" + print " } ligatures[%d];" % max_i + print "} ligature_table[] =" + print "{" + keys = ligas.keys () + keys.sort () + for first in keys: + + print " { 0x%04X, {" % (first) + for liga in ligas[first]: + print " { 0x%04X, 0x%04X }, /* %s */" % (liga[0], liga[1], names[liga[1]]) + print " }}," + + print "};" + print + + + +print "/* == Start of generated table == */" +print "/*" +print " * The following table is generated by running:" +print " *" +print " * ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt" +print " *" +print " * on files with these headers:" +print " *" +for h in headers: + for l in h: + print " * %s" % (l.strip()) +print " */" +print +print "#ifndef HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH" +print "#define HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH" +print + +print_joining_table (files[0]) +print_shaping_table (files[1]) + +print +print "#endif /* HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH */" +print +print "/* == End of generated table == */" + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-indic-table.py b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-indic-table.py new file mode 100755 index 00000000000..94aa2ab0728 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/gen-indic-table.py @@ -0,0 +1,211 @@ +#!/usr/bin/python + +import sys + +if len (sys.argv) != 4: + print >>sys.stderr, "usage: ./gen-indic-table.py IndicSyllabicCategory.txt IndicMatraCategory.txt Blocks.txt" + sys.exit (1) + +files = [file (x) for x in sys.argv[1:]] + +headers = [[f.readline () for i in range (2)] for f in files] + +blocks = {} +data = [{} for f in files] +values = [{} for f in files] +for i, f in enumerate (files): + for line in f: + + j = line.find ('#') + if j >= 0: + line = line[:j] + + fields = [x.strip () for x in line.split (';')] + if len (fields) == 1: + continue + + uu = fields[0].split ('..') + start = int (uu[0], 16) + if len (uu) == 1: + end = start + else: + end = int (uu[1], 16) + + t = fields[1] + + for u in range (start, end + 1): + data[i][u] = t + values[i][t] = values[i].get (t, 0) + 1 + + if i == 2: + blocks[t] = (start, end) + +# Merge data into one dict: +defaults = ('Other', 'Not_Applicable', 'No_Block') +for i,v in enumerate (defaults): + values[i][v] = values[i].get (v, 0) + 1 +combined = {} +for i,d in enumerate (data): + for u,v in d.items (): + if i == 2 and not u in combined: + continue + if not u in combined: + combined[u] = list (defaults) + combined[u][i] = v +data = combined +del combined +num = len (data) + +# Move the outliers NO-BREAK SPACE and DOTTED CIRCLE out +singles = {} +for u in [0x00A0, 0x25CC]: + singles[u] = data[u] + del data[u] + +print "/* == Start of generated table == */" +print "/*" +print " * The following table is generated by running:" +print " *" +print " * ./gen-indic-table.py IndicSyllabicCategory.txt IndicMatraCategory.txt Blocks.txt" +print " *" +print " * on files with these headers:" +print " *" +for h in headers: + for l in h: + print " * %s" % (l.strip()) +print " */" +print +print "#ifndef HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH" +print "#define HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH" +print + +# Shorten values +short = [{ + "Bindu": 'Bi', + "Visarga": 'Vs', + "Vowel": 'Vo', + "Vowel_Dependent": 'M', + "Other": 'x', +},{ + "Not_Applicable": 'x', +}] +all_shorts = [[],[]] + +# Add some of the values, to make them more readable, and to avoid duplicates + + +for i in range (2): + for v,s in short[i].items (): + all_shorts[i].append (s) + +what = ["INDIC_SYLLABIC_CATEGORY", "INDIC_MATRA_CATEGORY"] +what_short = ["ISC", "IMC"] +for i in range (2): + print + vv = values[i].keys () + vv.sort () + for v in vv: + v_no_and = v.replace ('_And_', '_') + if v in short[i]: + s = short[i][v] + else: + s = ''.join ([c for c in v_no_and if ord ('A') <= ord (c) <= ord ('Z')]) + if s in all_shorts[i]: + raise Exception ("Duplicate short value alias", v, s) + all_shorts[i].append (s) + short[i][v] = s + print "#define %s_%s %s_%s %s/* %3d chars; %s */" % \ + (what_short[i], s, what[i], v.upper (), \ + ' '* ((48-1 - len (what[i]) - 1 - len (v)) / 8), \ + values[i][v], v) +print +print "#define _(S,M) INDIC_COMBINE_CATEGORIES (ISC_##S, IMC_##M)" +print +print + +total = 0 +used = 0 +def print_block (block, start, end, data): + print + print + print " /* %s (%04X..%04X) */" % (block, start, end) + num = 0 + for u in range (start, end+1): + if u % 8 == 0: + print + print " /* %04X */" % u, + if u in data: + num += 1 + d = data.get (u, defaults) + sys.stdout.write ("%9s" % ("_(%s,%s)," % (short[0][d[0]], short[1][d[1]]))) + + global total, used + total += end - start + 1 + used += num + +uu = data.keys () +uu.sort () + +last = -1 +num = 0 +offset = 0 +starts = [] +ends = [] +print "static const INDIC_TABLE_ELEMENT_TYPE indic_table[] = {" +for u in uu: + if u <= last: + continue + block = data[u][2] + (start, end) = blocks[block] + + if start != last + 1: + if start - last <= 33: + print_block ("FILLER", last+1, start-1, data) + last = start-1 + else: + if last >= 0: + ends.append (last + 1) + offset += ends[-1] - starts[-1] + print + print + print "#define indic_offset_0x%04x %d" % (start, offset) + starts.append (start) + + print_block (block, start, end, data) + last = end +ends.append (last + 1) +offset += ends[-1] - starts[-1] +print +print +print "#define indic_offset_total %d" % offset +print +occupancy = used * 100. / total +print "}; /* Table occupancy: %d%% */" % occupancy +print +print "static INDIC_TABLE_ELEMENT_TYPE" +print "get_indic_categories (hb_codepoint_t u)" +print "{" +for (start,end) in zip (starts, ends): + offset = "indic_offset_0x%04x" % start + print " if (0x%04X <= u && u <= 0x%04X) return indic_table[u - 0x%04X + %s];" % (start, end, start, offset) +for u,d in singles.items (): + print " if (unlikely (u == 0x%04X)) return _(%s,%s);" % (u, short[0][d[0]], short[1][d[1]]) +print " return _(x,x);" +print "}" +print +print "#undef _" +for i in range (2): + print + vv = values[i].keys () + vv.sort () + for v in vv: + print "#undef %s_%s" % \ + (what_short[i], short[i][v]) +print +print "#endif /* HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH */" +print +print "/* == End of generated table == */" + +# Maintain at least 30% occupancy in the table */ +if occupancy < 30: + raise Exception ("Table too sparse, please investigate: ", occupancy) diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-atomic-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-atomic-private.hh new file mode 100644 index 00000000000..67579cdd442 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-atomic-private.hh @@ -0,0 +1,124 @@ +/* + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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. + * + * Contributor(s): + * Chris Wilson <chris@chris-wilson.co.uk> + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_ATOMIC_PRIVATE_HH +#define HB_ATOMIC_PRIVATE_HH + +#include "hb-private.hh" + + +/* atomic_int */ + +/* We need external help for these */ + +#if 0 + + +#elif !defined(HB_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* mingw32 does not have MemoryBarrier. + * MemoryBarrier may be defined as a macro or a function. + * Just make a failsafe version for ourselves. */ +#ifdef MemoryBarrier +#define HBMemoryBarrier MemoryBarrier +#else +static inline void HBMemoryBarrier (void) { + long dummy = 0; + InterlockedExchange (&dummy, 1); +} +#endif + +typedef LONG hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) + +#define hb_atomic_ptr_get(P) (HBMemoryBarrier (), (void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) + + +#elif !defined(HB_NO_MT) && defined(__APPLE__) + +#include <libkern/OSAtomic.h> +#ifdef __MAC_OS_X_MIN_REQUIRED +#include <AvailabilityMacros.h> +#elif defined(__IPHONE_OS_MIN_REQUIRED) +#include <Availability.h> +#endif + +typedef int32_t hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) + +#define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) +#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) +#else +#if __ppc64__ || __x86_64__ +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) +#else +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) +#endif +#endif + + +#elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) + +typedef int hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) + +#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) + + +#elif !defined(HB_NO_MT) + +#define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ +typedef volatile int hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) + +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) + + +#else /* HB_NO_MT */ + +typedef int hb_atomic_int_t; +#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) + +#define hb_atomic_ptr_get(P) ((void *) *(P)) +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false) + +#endif + +/* TODO Add tracing. */ + +#endif /* HB_ATOMIC_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.cc new file mode 100644 index 00000000000..b6e696be322 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.cc @@ -0,0 +1,325 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#include "hb-private.hh" + +#include "hb-blob.h" +#include "hb-object-private.hh" + +#ifdef HAVE_SYS_MMAN_H +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#include <sys/mman.h> +#endif /* HAVE_SYS_MMAN_H */ + +#include <stdio.h> +#include <errno.h> + + + +#ifndef HB_DEBUG_BLOB +#define HB_DEBUG_BLOB (HB_DEBUG+0) +#endif + + +struct hb_blob_t { + hb_object_header_t header; + ASSERT_POD (); + + bool immutable; + + const char *data; + unsigned int length; + hb_memory_mode_t mode; + + void *user_data; + hb_destroy_func_t destroy; +}; + + +static bool _try_writable (hb_blob_t *blob); + +static void +_hb_blob_destroy_user_data (hb_blob_t *blob) +{ + if (blob->destroy) { + blob->destroy (blob->user_data); + blob->user_data = NULL; + blob->destroy = NULL; + } +} + +hb_blob_t * +hb_blob_create (const char *data, + unsigned int length, + hb_memory_mode_t mode, + void *user_data, + hb_destroy_func_t destroy) +{ + hb_blob_t *blob; + + if (!length || !(blob = hb_object_create<hb_blob_t> ())) { + if (destroy) + destroy (user_data); + return hb_blob_get_empty (); + } + + blob->data = data; + blob->length = length; + blob->mode = mode; + + blob->user_data = user_data; + blob->destroy = destroy; + + if (blob->mode == HB_MEMORY_MODE_DUPLICATE) { + blob->mode = HB_MEMORY_MODE_READONLY; + if (!_try_writable (blob)) { + hb_blob_destroy (blob); + return hb_blob_get_empty (); + } + } + + return blob; +} + +hb_blob_t * +hb_blob_create_sub_blob (hb_blob_t *parent, + unsigned int offset, + unsigned int length) +{ + hb_blob_t *blob; + + if (!length || offset >= parent->length) + return hb_blob_get_empty (); + + hb_blob_make_immutable (parent); + + blob = hb_blob_create (parent->data + offset, + MIN (length, parent->length - offset), + parent->mode, + hb_blob_reference (parent), + (hb_destroy_func_t) hb_blob_destroy); + + return blob; +} + +hb_blob_t * +hb_blob_get_empty (void) +{ + static const hb_blob_t _hb_blob_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + NULL, /* data */ + 0, /* length */ + HB_MEMORY_MODE_READONLY, /* mode */ + + NULL, /* user_data */ + NULL /* destroy */ + }; + + return const_cast<hb_blob_t *> (&_hb_blob_nil); +} + +hb_blob_t * +hb_blob_reference (hb_blob_t *blob) +{ + return hb_object_reference (blob); +} + +void +hb_blob_destroy (hb_blob_t *blob) +{ + if (!hb_object_destroy (blob)) return; + + _hb_blob_destroy_user_data (blob); + + free (blob); +} + +hb_bool_t +hb_blob_set_user_data (hb_blob_t *blob, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (blob, key, data, destroy, replace); +} + +void * +hb_blob_get_user_data (hb_blob_t *blob, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (blob, key); +} + + +void +hb_blob_make_immutable (hb_blob_t *blob) +{ + if (hb_object_is_inert (blob)) + return; + + blob->immutable = true; +} + +hb_bool_t +hb_blob_is_immutable (hb_blob_t *blob) +{ + return blob->immutable; +} + + +unsigned int +hb_blob_get_length (hb_blob_t *blob) +{ + return blob->length; +} + +const char * +hb_blob_get_data (hb_blob_t *blob, unsigned int *length) +{ + if (length) + *length = blob->length; + + return blob->data; +} + +char * +hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length) +{ + if (!_try_writable (blob)) { + if (length) + *length = 0; + + return NULL; + } + + if (length) + *length = blob->length; + + return const_cast<char *> (blob->data); +} + + +static hb_bool_t +_try_make_writable_inplace_unix (hb_blob_t *blob) +{ +#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_MPROTECT) + uintptr_t pagesize = -1, mask, length; + const char *addr; + +#if defined(HAVE_SYSCONF) && defined(_SC_PAGE_SIZE) + pagesize = (uintptr_t) sysconf (_SC_PAGE_SIZE); +#elif defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE) + pagesize = (uintptr_t) sysconf (_SC_PAGESIZE); +#elif defined(HAVE_GETPAGESIZE) + pagesize = (uintptr_t) getpagesize (); +#endif + + if ((uintptr_t) -1L == pagesize) { + DEBUG_MSG_FUNC (BLOB, blob, "failed to get pagesize: %s", strerror (errno)); + return false; + } + DEBUG_MSG_FUNC (BLOB, blob, "pagesize is %lu", (unsigned long) pagesize); + + mask = ~(pagesize-1); + addr = (const char *) (((uintptr_t) blob->data) & mask); + length = (const char *) (((uintptr_t) blob->data + blob->length + pagesize-1) & mask) - addr; + DEBUG_MSG_FUNC (BLOB, blob, + "calling mprotect on [%p..%p] (%lu bytes)", + addr, addr+length, (unsigned long) length); + if (-1 == mprotect ((void *) addr, length, PROT_READ | PROT_WRITE)) { + DEBUG_MSG_FUNC (BLOB, blob, "mprotect failed: %s", strerror (errno)); + return false; + } + + blob->mode = HB_MEMORY_MODE_WRITABLE; + + DEBUG_MSG_FUNC (BLOB, blob, + "successfully made [%p..%p] (%lu bytes) writable\n", + addr, addr+length, (unsigned long) length); + return true; +#else + return false; +#endif +} + +static bool +_try_writable_inplace (hb_blob_t *blob) +{ + DEBUG_MSG_FUNC (BLOB, blob, "making writable inplace\n"); + + if (_try_make_writable_inplace_unix (blob)) + return true; + + DEBUG_MSG_FUNC (BLOB, blob, "making writable -> FAILED\n"); + + /* Failed to make writable inplace, mark that */ + blob->mode = HB_MEMORY_MODE_READONLY; + return false; +} + +static bool +_try_writable (hb_blob_t *blob) +{ + if (blob->immutable) + return false; + + if (blob->mode == HB_MEMORY_MODE_WRITABLE) + return true; + + if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE && _try_writable_inplace (blob)) + return true; + + if (blob->mode == HB_MEMORY_MODE_WRITABLE) + return true; + + + DEBUG_MSG_FUNC (BLOB, blob, "current data is -> %p\n", blob->data); + + char *new_data; + + new_data = (char *) malloc (blob->length); + if (unlikely (!new_data)) + return false; + + DEBUG_MSG_FUNC (BLOB, blob, "dupped successfully -> %p\n", blob->data); + + memcpy (new_data, blob->data, blob->length); + _hb_blob_destroy_user_data (blob); + blob->mode = HB_MEMORY_MODE_WRITABLE; + blob->data = new_data; + blob->user_data = new_data; + blob->destroy = free; + + return true; +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.h new file mode 100644 index 00000000000..1a93baa46dc --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-blob.h @@ -0,0 +1,101 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_BLOB_H +#define HB_BLOB_H + +#include "hb-common.h" + +HB_BEGIN_DECLS + + +typedef enum { + HB_MEMORY_MODE_DUPLICATE, + HB_MEMORY_MODE_READONLY, + HB_MEMORY_MODE_WRITABLE, + HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE +} hb_memory_mode_t; + +typedef struct hb_blob_t hb_blob_t; + +hb_blob_t * +hb_blob_create (const char *data, + unsigned int length, + hb_memory_mode_t mode, + void *user_data, + hb_destroy_func_t destroy); + +hb_blob_t * +hb_blob_create_sub_blob (hb_blob_t *parent, + unsigned int offset, + unsigned int length); + +hb_blob_t * +hb_blob_get_empty (void); + +hb_blob_t * +hb_blob_reference (hb_blob_t *blob); + +void +hb_blob_destroy (hb_blob_t *blob); + +hb_bool_t +hb_blob_set_user_data (hb_blob_t *blob, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + +void * +hb_blob_get_user_data (hb_blob_t *blob, + hb_user_data_key_t *key); + + +void +hb_blob_make_immutable (hb_blob_t *blob); + +hb_bool_t +hb_blob_is_immutable (hb_blob_t *blob); + + +unsigned int +hb_blob_get_length (hb_blob_t *blob); + +const char * +hb_blob_get_data (hb_blob_t *blob, unsigned int *length); + +char * +hb_blob_get_data_writable (hb_blob_t *blob, unsigned int *length); + + +HB_END_DECLS + +#endif /* HB_BLOB_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer-private.hh new file mode 100644 index 00000000000..13cf4bb0e9b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer-private.hh @@ -0,0 +1,199 @@ +/* + * Copyright © 1998-2004 David Turner and Werner Lemberg + * Copyright © 2004,2007,2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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): Owen Taylor, Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_BUFFER_PRIVATE_HH +#define HB_BUFFER_PRIVATE_HH + +#include "hb-private.hh" +#include "hb-buffer.h" +#include "hb-object-private.hh" +#include "hb-unicode-private.hh" + + +ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); +ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); + + +/* + * hb_buffer_t + */ + +struct hb_buffer_t { + hb_object_header_t header; + ASSERT_POD (); + + /* Information about how the text in the buffer should be treated */ + + hb_unicode_funcs_t *unicode; /* Unicode functions */ + hb_segment_properties_t props; /* Script, language, direction */ + hb_buffer_flags_t flags; /* BOT / EOT / etc. */ + + /* Buffer contents */ + + hb_buffer_content_type_t content_type; + + bool in_error; /* Allocation failed */ + bool have_output; /* Whether we have an output buffer going on */ + bool have_positions; /* Whether we have positions */ + + unsigned int idx; /* Cursor into ->info and ->pos arrays */ + unsigned int len; /* Length of ->info and ->pos arrays */ + unsigned int out_len; /* Length of ->out array if have_output */ + + unsigned int allocated; /* Length of allocated arrays */ + hb_glyph_info_t *info; + hb_glyph_info_t *out_info; + hb_glyph_position_t *pos; + + inline hb_glyph_info_t &cur (unsigned int i = 0) { return info[idx + i]; } + inline hb_glyph_info_t cur (unsigned int i = 0) const { return info[idx + i]; } + + inline hb_glyph_position_t &cur_pos (unsigned int i = 0) { return pos[idx + i]; } + inline hb_glyph_position_t cur_pos (unsigned int i = 0) const { return pos[idx + i]; } + + inline hb_glyph_info_t &prev (void) { return out_info[out_len - 1]; } + inline hb_glyph_info_t prev (void) const { return info[out_len - 1]; } + + unsigned int serial; + + /* These reflect current allocations of the bytes in glyph_info_t's var1 and var2. */ + uint8_t allocated_var_bytes[8]; + const char *allocated_var_owner[8]; + + /* Text before / after the main buffer contents. + * Always in Unicode, and ordered outward. + * Index 0 is for "pre-context", 1 for "post-context". */ + static const unsigned int CONTEXT_LENGTH = 5; + hb_codepoint_t context[2][CONTEXT_LENGTH]; + unsigned int context_len[2]; + + + /* Methods */ + + HB_INTERNAL void reset (void); + HB_INTERNAL void clear (void); + + inline unsigned int backtrack_len (void) const + { return have_output? out_len : idx; } + inline unsigned int next_serial (void) { return serial++; } + + HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner); + HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner); + HB_INTERNAL void assert_var (unsigned int byte_i, unsigned int count, const char *owner); + HB_INTERNAL void deallocate_var_all (void); + + HB_INTERNAL void add (hb_codepoint_t codepoint, + unsigned int cluster); + + HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); + HB_INTERNAL void reverse (void); + HB_INTERNAL void reverse_clusters (void); + HB_INTERNAL void guess_segment_properties (void); + + HB_INTERNAL void swap_buffers (void); + HB_INTERNAL void remove_output (void); + HB_INTERNAL void clear_output (void); + HB_INTERNAL void clear_positions (void); + + HB_INTERNAL void replace_glyphs (unsigned int num_in, + unsigned int num_out, + const hb_codepoint_t *glyph_data); + + HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index); + /* Makes a copy of the glyph at idx to output and replace glyph_index */ + HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index); + HB_INTERNAL void output_info (hb_glyph_info_t &glyph_info); + /* Copies glyph at idx to output but doesn't advance idx */ + HB_INTERNAL void copy_glyph (void); + /* Copies glyph at idx to output and advance idx. + * If there's no output, just advance idx. */ + inline void + next_glyph (void) + { + if (have_output) + { + if (unlikely (out_info != info || out_len != idx)) { + if (unlikely (!make_room_for (1, 1))) return; + out_info[out_len] = info[idx]; + } + out_len++; + } + + idx++; + } + + /* Advance idx without copying to output. */ + inline void skip_glyph (void) { idx++; } + + inline void reset_masks (hb_mask_t mask) + { + for (unsigned int j = 0; j < len; j++) + info[j].mask = mask; + } + inline void add_masks (hb_mask_t mask) + { + for (unsigned int j = 0; j < len; j++) + info[j].mask |= mask; + } + HB_INTERNAL void set_masks (hb_mask_t value, + hb_mask_t mask, + unsigned int cluster_start, + unsigned int cluster_end); + + HB_INTERNAL void merge_clusters (unsigned int start, + unsigned int end); + HB_INTERNAL void merge_out_clusters (unsigned int start, + unsigned int end); + + /* Internal methods */ + HB_INTERNAL bool enlarge (unsigned int size); + + inline bool ensure (unsigned int size) + { return likely (size < allocated) ? true : enlarge (size); } + + HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); + + HB_INTERNAL void *get_scratch_buffer (unsigned int *size); + + inline void clear_context (unsigned int side) { context_len[side] = 0; } +}; + + +#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \ + b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \ + sizeof (b->info[0].var), owner) +#define HB_BUFFER_ALLOCATE_VAR(b, var) \ + HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var) +#define HB_BUFFER_DEALLOCATE_VAR(b, var) \ + HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var) +#define HB_BUFFER_ASSERT_VAR(b, var) \ + HB_BUFFER_XALLOCATE_VAR (b, assert_var, var (), #var) + + +#endif /* HB_BUFFER_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.cc new file mode 100644 index 00000000000..4b644e40217 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.cc @@ -0,0 +1,1294 @@ +/* + * Copyright © 1998-2004 David Turner and Werner Lemberg + * Copyright © 2004,2007,2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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): Owen Taylor, Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-buffer-private.hh" +#include "hb-utf-private.hh" + + +#ifndef HB_DEBUG_BUFFER +#define HB_DEBUG_BUFFER (HB_DEBUG+0) +#endif + + +hb_bool_t +hb_segment_properties_equal (const hb_segment_properties_t *a, + const hb_segment_properties_t *b) +{ + return a->direction == b->direction && + a->script == b->script && + a->language == b->language && + a->reserved1 == b->reserved1 && + a->reserved2 == b->reserved2; + +} + +unsigned int +hb_segment_properties_hash (const hb_segment_properties_t *p) +{ + return (unsigned int) p->direction ^ + (unsigned int) p->script ^ + (intptr_t) (p->language); +} + + + +/* Here is how the buffer works internally: + * + * There are two info pointers: info and out_info. They always have + * the same allocated size, but different lengths. + * + * As an optimization, both info and out_info may point to the + * same piece of memory, which is owned by info. This remains the + * case as long as out_len doesn't exceed i at any time. + * In that case, swap_buffers() is no-op and the glyph operations operate + * mostly in-place. + * + * As soon as out_info gets longer than info, out_info is moved over + * to an alternate buffer (which we reuse the pos buffer for!), and its + * current contents (out_len entries) are copied to the new place. + * This should all remain transparent to the user. swap_buffers() then + * switches info and out_info. + */ + + + +/* Internal API */ + +bool +hb_buffer_t::enlarge (unsigned int size) +{ + if (unlikely (in_error)) + return false; + + unsigned int new_allocated = allocated; + hb_glyph_position_t *new_pos = NULL; + hb_glyph_info_t *new_info = NULL; + bool separate_out = out_info != info; + + if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0])))) + goto done; + + while (size >= new_allocated) + new_allocated += (new_allocated >> 1) + 32; + + ASSERT_STATIC (sizeof (info[0]) == sizeof (pos[0])); + if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0])))) + goto done; + + new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0])); + new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0])); + +done: + if (unlikely (!new_pos || !new_info)) + in_error = true; + + if (likely (new_pos)) + pos = new_pos; + + if (likely (new_info)) + info = new_info; + + out_info = separate_out ? (hb_glyph_info_t *) pos : info; + if (likely (!in_error)) + allocated = new_allocated; + + return likely (!in_error); +} + +bool +hb_buffer_t::make_room_for (unsigned int num_in, + unsigned int num_out) +{ + if (unlikely (!ensure (out_len + num_out))) return false; + + if (out_info == info && + out_len + num_out > idx + num_in) + { + assert (have_output); + + out_info = (hb_glyph_info_t *) pos; + memcpy (out_info, info, out_len * sizeof (out_info[0])); + } + + return true; +} + +void * +hb_buffer_t::get_scratch_buffer (unsigned int *size) +{ + have_output = false; + have_positions = false; + + out_len = 0; + out_info = info; + + *size = allocated * sizeof (pos[0]); + return pos; +} + + + +/* HarfBuzz-Internal API */ + +void +hb_buffer_t::reset (void) +{ + if (unlikely (hb_object_is_inert (this))) + return; + + hb_unicode_funcs_destroy (unicode); + unicode = hb_unicode_funcs_get_default (); + + clear (); +} + +void +hb_buffer_t::clear (void) +{ + if (unlikely (hb_object_is_inert (this))) + return; + + hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT; + props = default_props; + flags = HB_BUFFER_FLAGS_DEFAULT; + + content_type = HB_BUFFER_CONTENT_TYPE_INVALID; + in_error = false; + have_output = false; + have_positions = false; + + idx = 0; + len = 0; + out_len = 0; + out_info = info; + + serial = 0; + memset (allocated_var_bytes, 0, sizeof allocated_var_bytes); + memset (allocated_var_owner, 0, sizeof allocated_var_owner); + + memset (context, 0, sizeof context); + memset (context_len, 0, sizeof context_len); +} + +void +hb_buffer_t::add (hb_codepoint_t codepoint, + unsigned int cluster) +{ + hb_glyph_info_t *glyph; + + if (unlikely (!ensure (len + 1))) return; + + glyph = &info[len]; + + memset (glyph, 0, sizeof (*glyph)); + glyph->codepoint = codepoint; + glyph->mask = 1; + glyph->cluster = cluster; + + len++; +} + +void +hb_buffer_t::remove_output (void) +{ + if (unlikely (hb_object_is_inert (this))) + return; + + have_output = false; + have_positions = false; + + out_len = 0; + out_info = info; +} + +void +hb_buffer_t::clear_output (void) +{ + if (unlikely (hb_object_is_inert (this))) + return; + + have_output = true; + have_positions = false; + + out_len = 0; + out_info = info; +} + +void +hb_buffer_t::clear_positions (void) +{ + if (unlikely (hb_object_is_inert (this))) + return; + + have_output = false; + have_positions = true; + + out_len = 0; + out_info = info; + + memset (pos, 0, sizeof (pos[0]) * len); +} + +void +hb_buffer_t::swap_buffers (void) +{ + if (unlikely (in_error)) return; + + assert (have_output); + have_output = false; + + if (out_info != info) + { + hb_glyph_info_t *tmp_string; + tmp_string = info; + info = out_info; + out_info = tmp_string; + pos = (hb_glyph_position_t *) out_info; + } + + unsigned int tmp; + tmp = len; + len = out_len; + out_len = tmp; + + idx = 0; +} + + +void +hb_buffer_t::replace_glyphs (unsigned int num_in, + unsigned int num_out, + const uint32_t *glyph_data) +{ + if (unlikely (!make_room_for (num_in, num_out))) return; + + merge_clusters (idx, idx + num_in); + + hb_glyph_info_t orig_info = info[idx]; + hb_glyph_info_t *pinfo = &out_info[out_len]; + for (unsigned int i = 0; i < num_out; i++) + { + *pinfo = orig_info; + pinfo->codepoint = glyph_data[i]; + pinfo++; + } + + idx += num_in; + out_len += num_out; +} + +void +hb_buffer_t::output_glyph (hb_codepoint_t glyph_index) +{ + if (unlikely (!make_room_for (0, 1))) return; + + out_info[out_len] = info[idx]; + out_info[out_len].codepoint = glyph_index; + + out_len++; +} + +void +hb_buffer_t::output_info (hb_glyph_info_t &glyph_info) +{ + if (unlikely (!make_room_for (0, 1))) return; + + out_info[out_len] = glyph_info; + + out_len++; +} + +void +hb_buffer_t::copy_glyph (void) +{ + if (unlikely (!make_room_for (0, 1))) return; + + out_info[out_len] = info[idx]; + + out_len++; +} + +void +hb_buffer_t::replace_glyph (hb_codepoint_t glyph_index) +{ + if (unlikely (out_info != info || out_len != idx)) { + if (unlikely (!make_room_for (1, 1))) return; + out_info[out_len] = info[idx]; + } + out_info[out_len].codepoint = glyph_index; + + idx++; + out_len++; +} + + +void +hb_buffer_t::set_masks (hb_mask_t value, + hb_mask_t mask, + unsigned int cluster_start, + unsigned int cluster_end) +{ + hb_mask_t not_mask = ~mask; + value &= mask; + + if (!mask) + return; + + if (cluster_start == 0 && cluster_end == (unsigned int)-1) { + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + info[i].mask = (info[i].mask & not_mask) | value; + return; + } + + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end) + info[i].mask = (info[i].mask & not_mask) | value; +} + +void +hb_buffer_t::reverse_range (unsigned int start, + unsigned int end) +{ + unsigned int i, j; + + if (start == end - 1) + return; + + for (i = start, j = end - 1; i < j; i++, j--) { + hb_glyph_info_t t; + + t = info[i]; + info[i] = info[j]; + info[j] = t; + } + + if (pos) { + for (i = start, j = end - 1; i < j; i++, j--) { + hb_glyph_position_t t; + + t = pos[i]; + pos[i] = pos[j]; + pos[j] = t; + } + } +} + +void +hb_buffer_t::reverse (void) +{ + if (unlikely (!len)) + return; + + reverse_range (0, len); +} + +void +hb_buffer_t::reverse_clusters (void) +{ + unsigned int i, start, count, last_cluster; + + if (unlikely (!len)) + return; + + reverse (); + + count = len; + start = 0; + last_cluster = info[0].cluster; + for (i = 1; i < count; i++) { + if (last_cluster != info[i].cluster) { + reverse_range (start, i); + start = i; + last_cluster = info[i].cluster; + } + } + reverse_range (start, i); +} + +void +hb_buffer_t::merge_clusters (unsigned int start, + unsigned int end) +{ + if (unlikely (end - start < 2)) + return; + + unsigned int cluster = info[start].cluster; + + for (unsigned int i = start + 1; i < end; i++) + cluster = MIN (cluster, info[i].cluster); + + /* Extend end */ + while (end < len && info[end - 1].cluster == info[end].cluster) + end++; + + /* Extend start */ + while (idx < start && info[start - 1].cluster == info[start].cluster) + start--; + + /* If we hit the start of buffer, continue in out-buffer. */ + if (idx == start) + for (unsigned i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--) + out_info[i - 1].cluster = cluster; + + for (unsigned int i = start; i < end; i++) + info[i].cluster = cluster; +} +void +hb_buffer_t::merge_out_clusters (unsigned int start, + unsigned int end) +{ + if (unlikely (end - start < 2)) + return; + + unsigned int cluster = out_info[start].cluster; + + for (unsigned int i = start + 1; i < end; i++) + cluster = MIN (cluster, out_info[i].cluster); + + /* Extend start */ + while (start && out_info[start - 1].cluster == out_info[start].cluster) + start--; + + /* Extend end */ + while (end < out_len && out_info[end - 1].cluster == out_info[end].cluster) + end++; + + /* If we hit the end of out-buffer, continue in buffer. */ + if (end == out_len) + for (unsigned i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++) + info[i].cluster = cluster; + + for (unsigned int i = start; i < end; i++) + out_info[i].cluster = cluster; +} + +void +hb_buffer_t::guess_segment_properties (void) +{ + assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || + (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); + + /* If script is set to INVALID, guess from buffer contents */ + if (props.script == HB_SCRIPT_INVALID) { + for (unsigned int i = 0; i < len; i++) { + hb_script_t script = unicode->script (info[i].codepoint); + if (likely (script != HB_SCRIPT_COMMON && + script != HB_SCRIPT_INHERITED && + script != HB_SCRIPT_UNKNOWN)) { + props.script = script; + break; + } + } + } + + /* If direction is set to INVALID, guess from script */ + if (props.direction == HB_DIRECTION_INVALID) { + props.direction = hb_script_get_horizontal_direction (props.script); + } + + /* If language is not set, use default language from locale */ + if (props.language == HB_LANGUAGE_INVALID) { + /* TODO get_default_for_script? using $LANGUAGE */ + props.language = hb_language_get_default (); + } +} + + +static inline void +dump_var_allocation (const hb_buffer_t *buffer) +{ + char buf[80]; + for (unsigned int i = 0; i < 8; i++) + buf[i] = '0' + buffer->allocated_var_bytes[7 - i]; + buf[8] = '\0'; + DEBUG_MSG (BUFFER, buffer, + "Current var allocation: %s", + buf); +} + +void hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner) +{ + assert (byte_i < 8 && byte_i + count <= 8); + + if (DEBUG (BUFFER)) + dump_var_allocation (this); + DEBUG_MSG (BUFFER, this, + "Allocating var bytes %d..%d for %s", + byte_i, byte_i + count - 1, owner); + + for (unsigned int i = byte_i; i < byte_i + count; i++) { + assert (!allocated_var_bytes[i]); + allocated_var_bytes[i]++; + allocated_var_owner[i] = owner; + } +} + +void hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner) +{ + if (DEBUG (BUFFER)) + dump_var_allocation (this); + + DEBUG_MSG (BUFFER, this, + "Deallocating var bytes %d..%d for %s", + byte_i, byte_i + count - 1, owner); + + assert (byte_i < 8 && byte_i + count <= 8); + for (unsigned int i = byte_i; i < byte_i + count; i++) { + assert (allocated_var_bytes[i]); + assert (0 == strcmp (allocated_var_owner[i], owner)); + allocated_var_bytes[i]--; + } +} + +void hb_buffer_t::assert_var (unsigned int byte_i, unsigned int count, const char *owner) +{ + if (DEBUG (BUFFER)) + dump_var_allocation (this); + + DEBUG_MSG (BUFFER, this, + "Asserting var bytes %d..%d for %s", + byte_i, byte_i + count - 1, owner); + + assert (byte_i < 8 && byte_i + count <= 8); + for (unsigned int i = byte_i; i < byte_i + count; i++) { + assert (allocated_var_bytes[i]); + assert (0 == strcmp (allocated_var_owner[i], owner)); + } +} + +void hb_buffer_t::deallocate_var_all (void) +{ + memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes)); + memset (allocated_var_owner, 0, sizeof (allocated_var_owner)); +} + +/* Public API */ + +hb_buffer_t * +hb_buffer_create (void) +{ + hb_buffer_t *buffer; + + if (!(buffer = hb_object_create<hb_buffer_t> ())) + return hb_buffer_get_empty (); + + buffer->reset (); + + return buffer; +} + +hb_buffer_t * +hb_buffer_get_empty (void) +{ + static const hb_buffer_t _hb_buffer_nil = { + HB_OBJECT_HEADER_STATIC, + + const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil), + HB_SEGMENT_PROPERTIES_DEFAULT, + HB_BUFFER_FLAGS_DEFAULT, + + HB_BUFFER_CONTENT_TYPE_INVALID, + true, /* in_error */ + true, /* have_output */ + true /* have_positions */ + + /* Zero is good enough for everything else. */ + }; + + return const_cast<hb_buffer_t *> (&_hb_buffer_nil); +} + +hb_buffer_t * +hb_buffer_reference (hb_buffer_t *buffer) +{ + return hb_object_reference (buffer); +} + +void +hb_buffer_destroy (hb_buffer_t *buffer) +{ + if (!hb_object_destroy (buffer)) return; + + hb_unicode_funcs_destroy (buffer->unicode); + + free (buffer->info); + free (buffer->pos); + + free (buffer); +} + +hb_bool_t +hb_buffer_set_user_data (hb_buffer_t *buffer, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (buffer, key, data, destroy, replace); +} + +void * +hb_buffer_get_user_data (hb_buffer_t *buffer, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (buffer, key); +} + + +void +hb_buffer_set_content_type (hb_buffer_t *buffer, + hb_buffer_content_type_t content_type) +{ + buffer->content_type = content_type; +} + +hb_buffer_content_type_t +hb_buffer_get_content_type (hb_buffer_t *buffer) +{ + return buffer->content_type; +} + + +void +hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, + hb_unicode_funcs_t *unicode) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + if (!unicode) + unicode = hb_unicode_funcs_get_default (); + + + hb_unicode_funcs_reference (unicode); + hb_unicode_funcs_destroy (buffer->unicode); + buffer->unicode = unicode; +} + +hb_unicode_funcs_t * +hb_buffer_get_unicode_funcs (hb_buffer_t *buffer) +{ + return buffer->unicode; +} + +void +hb_buffer_set_direction (hb_buffer_t *buffer, + hb_direction_t direction) + +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->props.direction = direction; +} + +hb_direction_t +hb_buffer_get_direction (hb_buffer_t *buffer) +{ + return buffer->props.direction; +} + +void +hb_buffer_set_script (hb_buffer_t *buffer, + hb_script_t script) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->props.script = script; +} + +hb_script_t +hb_buffer_get_script (hb_buffer_t *buffer) +{ + return buffer->props.script; +} + +void +hb_buffer_set_language (hb_buffer_t *buffer, + hb_language_t language) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->props.language = language; +} + +hb_language_t +hb_buffer_get_language (hb_buffer_t *buffer) +{ + return buffer->props.language; +} + +void +hb_buffer_set_segment_properties (hb_buffer_t *buffer, + const hb_segment_properties_t *props) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->props = *props; +} + +void +hb_buffer_get_segment_properties (hb_buffer_t *buffer, + hb_segment_properties_t *props) +{ + *props = buffer->props; +} + + +void +hb_buffer_set_flags (hb_buffer_t *buffer, + hb_buffer_flags_t flags) +{ + if (unlikely (hb_object_is_inert (buffer))) + return; + + buffer->flags = flags; +} + +hb_buffer_flags_t +hb_buffer_get_flags (hb_buffer_t *buffer) +{ + return buffer->flags; +} + + +void +hb_buffer_reset (hb_buffer_t *buffer) +{ + buffer->reset (); +} + +void +hb_buffer_clear (hb_buffer_t *buffer) +{ + buffer->clear (); +} + +hb_bool_t +hb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size) +{ + return buffer->ensure (size); +} + +hb_bool_t +hb_buffer_allocation_successful (hb_buffer_t *buffer) +{ + return !buffer->in_error; +} + +void +hb_buffer_add (hb_buffer_t *buffer, + hb_codepoint_t codepoint, + unsigned int cluster) +{ + buffer->add (codepoint, cluster); + buffer->clear_context (1); +} + +hb_bool_t +hb_buffer_set_length (hb_buffer_t *buffer, + unsigned int length) +{ + if (unlikely (hb_object_is_inert (buffer))) + return length == 0; + + if (!buffer->ensure (length)) + return false; + + /* Wipe the new space */ + if (length > buffer->len) { + memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len)); + if (buffer->have_positions) + memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len)); + } + + buffer->len = length; + + if (!length) + buffer->clear_context (0); + buffer->clear_context (1); + + return true; +} + +unsigned int +hb_buffer_get_length (hb_buffer_t *buffer) +{ + return buffer->len; +} + +/* Return value valid as long as buffer not modified */ +hb_glyph_info_t * +hb_buffer_get_glyph_infos (hb_buffer_t *buffer, + unsigned int *length) +{ + if (length) + *length = buffer->len; + + return (hb_glyph_info_t *) buffer->info; +} + +/* Return value valid as long as buffer not modified */ +hb_glyph_position_t * +hb_buffer_get_glyph_positions (hb_buffer_t *buffer, + unsigned int *length) +{ + if (!buffer->have_positions) + buffer->clear_positions (); + + if (length) + *length = buffer->len; + + return (hb_glyph_position_t *) buffer->pos; +} + +void +hb_buffer_reverse (hb_buffer_t *buffer) +{ + buffer->reverse (); +} + +void +hb_buffer_reverse_clusters (hb_buffer_t *buffer) +{ + buffer->reverse_clusters (); +} + +void +hb_buffer_guess_segment_properties (hb_buffer_t *buffer) +{ + buffer->guess_segment_properties (); +} + +template <typename T> +static inline void +hb_buffer_add_utf (hb_buffer_t *buffer, + const T *text, + int text_length, + unsigned int item_offset, + int item_length) +{ + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || + (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); + + if (unlikely (hb_object_is_inert (buffer))) + return; + + if (text_length == -1) + text_length = hb_utf_strlen (text); + + if (item_length == -1) + item_length = text_length - item_offset; + + buffer->ensure (buffer->len + item_length * sizeof (T) / 4); + + /* If buffer is empty and pre-context provided, install it. + * This check is written this way, to make sure people can + * provide pre-context in one add_utf() call, then provide + * text in a follow-up call. See: + * + * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13 + */ + if (!buffer->len && item_offset > 0) + { + /* Add pre-context */ + buffer->clear_context (0); + const T *prev = text + item_offset; + const T *start = text; + while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH) + { + hb_codepoint_t u; + prev = hb_utf_prev (prev, start, &u); + buffer->context[0][buffer->context_len[0]++] = u; + } + } + + const T *next = text + item_offset; + const T *end = next + item_length; + while (next < end) + { + hb_codepoint_t u; + const T *old_next = next; + next = hb_utf_next (next, end, &u); + buffer->add (u, old_next - (const T *) text); + } + + /* Add post-context */ + buffer->clear_context (1); + end = text + text_length; + while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH) + { + hb_codepoint_t u; + next = hb_utf_next (next, end, &u); + buffer->context[1][buffer->context_len[1]++] = u; + } + + buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; +} + +void +hb_buffer_add_utf8 (hb_buffer_t *buffer, + const char *text, + int text_length, + unsigned int item_offset, + int item_length) +{ + hb_buffer_add_utf (buffer, (const uint8_t *) text, text_length, item_offset, item_length); +} + +void +hb_buffer_add_utf16 (hb_buffer_t *buffer, + const uint16_t *text, + int text_length, + unsigned int item_offset, + int item_length) +{ + hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); +} + +void +hb_buffer_add_utf32 (hb_buffer_t *buffer, + const uint32_t *text, + int text_length, + unsigned int item_offset, + int item_length) +{ + hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); +} + + +static int +compare_info_codepoint (const hb_glyph_info_t *pa, + const hb_glyph_info_t *pb) +{ + return (int) pb->codepoint - (int) pa->codepoint; +} + +static inline void +normalize_glyphs_cluster (hb_buffer_t *buffer, + unsigned int start, + unsigned int end, + bool backward) +{ + hb_glyph_position_t *pos = buffer->pos; + + /* Total cluster advance */ + hb_position_t total_x_advance = 0, total_y_advance = 0; + for (unsigned int i = start; i < end; i++) + { + total_x_advance += pos[i].x_advance; + total_y_advance += pos[i].y_advance; + } + + hb_position_t x_advance = 0, y_advance = 0; + for (unsigned int i = start; i < end; i++) + { + pos[i].x_offset += x_advance; + pos[i].y_offset += y_advance; + + x_advance += pos[i].x_advance; + y_advance += pos[i].y_advance; + + pos[i].x_advance = 0; + pos[i].y_advance = 0; + } + + if (backward) + { + /* Transfer all cluster advance to the last glyph. */ + pos[end - 1].x_advance = total_x_advance; + pos[end - 1].y_advance = total_y_advance; + + hb_bubble_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start); + } else { + /* Transfer all cluster advance to the first glyph. */ + pos[start].x_advance += total_x_advance; + pos[start].y_advance += total_y_advance; + for (unsigned int i = start + 1; i < end; i++) { + pos[i].x_offset -= total_x_advance; + pos[i].y_offset -= total_y_advance; + } + hb_bubble_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1); + } +} + +void +hb_buffer_normalize_glyphs (hb_buffer_t *buffer) +{ + assert (buffer->have_positions); + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); + + bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); + + unsigned int count = buffer->len; + if (unlikely (!count)) return; + hb_glyph_info_t *info = buffer->info; + + unsigned int start = 0; + unsigned int end; + for (end = start + 1; end < count; end++) + if (info[start].cluster != info[end].cluster) { + normalize_glyphs_cluster (buffer, start, end, backward); + start = end; + } + normalize_glyphs_cluster (buffer, start, end, backward); +} + + +/* + * Serialize + */ + +static const char *serialize_formats[] = { + "text", + "json", + NULL +}; + +const char ** +hb_buffer_serialize_list_formats (void) +{ + return serialize_formats; +} + +hb_buffer_serialize_format_t +hb_buffer_serialize_format_from_string (const char *str, int len) +{ + /* Upper-case it. */ + return (hb_buffer_serialize_format_t) (hb_tag_from_string (str, len) & ~0x20202020); +} + +const char * +hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format) +{ + switch (format) + { + case HB_BUFFER_SERIALIZE_FORMAT_TEXT: return serialize_formats[0]; + case HB_BUFFER_SERIALIZE_FORMAT_JSON: return serialize_formats[1]; + default: + case HB_BUFFER_SERIALIZE_FORMAT_INVALID: return NULL; + } +} + +static unsigned int +_hb_buffer_serialize_glyphs_json (hb_buffer_t *buffer, + unsigned int start, + unsigned int end, + char *buf, + unsigned int buf_size, + unsigned int *buf_consumed, + hb_font_t *font, + hb_buffer_serialize_flags_t flags) +{ + hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL); + hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, NULL); + + *buf_consumed = 0; + for (unsigned int i = start; i < end; i++) + { + char b[1024]; + char *p = b; + + /* In the following code, we know b is large enough that no overflow can happen. */ + +#define APPEND(s) HB_STMT_START { strcpy (p, s); p += strlen (s); } HB_STMT_END + + if (i) + *p++ = ','; + + *p++ = '{'; + + APPEND ("\"g\":"); + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES)) + { + char g[128]; + hb_font_glyph_to_string (font, info[i].codepoint, g, sizeof (g)); + *p++ = '"'; + for (char *q = g; *q; q++) { + if (*q == '"') + *p++ = '\\'; + *p++ = *q; + } + *p++ = '"'; + } + else + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint); + + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"cl\":%u", info[i].cluster); + } + + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) + { + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"dx\":%d,\"dy\":%d", + pos[i].x_offset, pos[i].y_offset); + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",\"ax\":%d,\"ay\":%d", + pos[i].x_advance, pos[i].y_advance); + } + + *p++ = '}'; + + if (buf_size > (p - b)) + { + unsigned int l = p - b; + memcpy (buf, b, l); + buf += l; + buf_size -= l; + *buf_consumed += l; + *buf = '\0'; + } else + return i - start; + } + + return end - start; +} + +static unsigned int +_hb_buffer_serialize_glyphs_text (hb_buffer_t *buffer, + unsigned int start, + unsigned int end, + char *buf, + unsigned int buf_size, + unsigned int *buf_consumed, + hb_font_t *font, + hb_buffer_serialize_flags_t flags) +{ + hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL); + hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, NULL); + hb_direction_t direction = hb_buffer_get_direction (buffer); + + *buf_consumed = 0; + for (unsigned int i = start; i < end; i++) + { + char b[1024]; + char *p = b; + + /* In the following code, we know b is large enough that no overflow can happen. */ + + if (i) + *p++ = '|'; + + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES)) + { + hb_font_glyph_to_string (font, info[i].codepoint, p, 128); + p += strlen (p); + } + else + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%u", info[i].codepoint); + + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS)) { + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "=%u", info[i].cluster); + } + + if (!(flags & HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS)) + { + if (pos[i].x_offset || pos[i].y_offset) + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "@%d,%d", pos[i].x_offset, pos[i].y_offset); + + *p++ = '+'; + if (HB_DIRECTION_IS_HORIZONTAL (direction) || pos[i].x_advance) + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), "%d", pos[i].x_advance); + if (HB_DIRECTION_IS_VERTICAL (direction) || pos->y_advance) + p += snprintf (p, ARRAY_LENGTH (b) - (p - b), ",%d", pos[i].y_advance); + } + + if (buf_size > (p - b)) + { + unsigned int l = p - b; + memcpy (buf, b, l); + buf += l; + buf_size -= l; + *buf_consumed += l; + *buf = '\0'; + } else + return i - start; + } + + return end - start; +} + +/* Returns number of items, starting at start, that were serialized. */ +unsigned int +hb_buffer_serialize_glyphs (hb_buffer_t *buffer, + unsigned int start, + unsigned int end, + char *buf, + unsigned int buf_size, + unsigned int *buf_consumed, + hb_font_t *font, /* May be NULL */ + hb_buffer_serialize_format_t format, + hb_buffer_serialize_flags_t flags) +{ + assert (start <= end && end <= buffer->len); + + *buf_consumed = 0; + + assert ((!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID) || + buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); + + if (unlikely (start == end)) + return 0; + + if (!font) + font = hb_font_get_empty (); + + switch (format) + { + case HB_BUFFER_SERIALIZE_FORMAT_TEXT: + return _hb_buffer_serialize_glyphs_text (buffer, start, end, + buf, buf_size, buf_consumed, + font, flags); + + case HB_BUFFER_SERIALIZE_FORMAT_JSON: + return _hb_buffer_serialize_glyphs_json (buffer, start, end, + buf, buf_size, buf_consumed, + font, flags); + + default: + case HB_BUFFER_SERIALIZE_FORMAT_INVALID: + return 0; + + } +} + +hb_bool_t +hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, + const char *buf, + unsigned int buf_len, + unsigned int *buf_consumed, + hb_font_t *font, /* May be NULL */ + hb_buffer_serialize_format_t format) +{ + return false; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.h new file mode 100644 index 00000000000..48ec4a527ad --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-buffer.h @@ -0,0 +1,323 @@ +/* + * Copyright © 1998-2004 David Turner and Werner Lemberg + * Copyright © 2004,2007,2009 Red Hat, Inc. + * Copyright © 2011,2012 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): Owen Taylor, Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_BUFFER_H +#define HB_BUFFER_H + +#include "hb-common.h" +#include "hb-unicode.h" +#include "hb-font.h" + +HB_BEGIN_DECLS + + +typedef struct hb_glyph_info_t { + hb_codepoint_t codepoint; + hb_mask_t mask; + uint32_t cluster; + + /*< private >*/ + hb_var_int_t var1; + hb_var_int_t var2; +} hb_glyph_info_t; + +typedef struct hb_glyph_position_t { + hb_position_t x_advance; + hb_position_t y_advance; + hb_position_t x_offset; + hb_position_t y_offset; + + /*< private >*/ + hb_var_int_t var; +} hb_glyph_position_t; + + +typedef struct hb_segment_properties_t { + hb_direction_t direction; + hb_script_t script; + hb_language_t language; + /*< private >*/ + void *reserved1; + void *reserved2; +} hb_segment_properties_t; + +#define HB_SEGMENT_PROPERTIES_DEFAULT {HB_DIRECTION_INVALID, \ + HB_SCRIPT_INVALID, \ + HB_LANGUAGE_INVALID, \ + NULL, \ + NULL} + +hb_bool_t +hb_segment_properties_equal (const hb_segment_properties_t *a, + const hb_segment_properties_t *b); + +unsigned int +hb_segment_properties_hash (const hb_segment_properties_t *p); + + + +/* + * hb_buffer_t + */ + +typedef struct hb_buffer_t hb_buffer_t; + +hb_buffer_t * +hb_buffer_create (void); + +hb_buffer_t * +hb_buffer_get_empty (void); + +hb_buffer_t * +hb_buffer_reference (hb_buffer_t *buffer); + +void +hb_buffer_destroy (hb_buffer_t *buffer); + +hb_bool_t +hb_buffer_set_user_data (hb_buffer_t *buffer, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + +void * +hb_buffer_get_user_data (hb_buffer_t *buffer, + hb_user_data_key_t *key); + + +typedef enum { + HB_BUFFER_CONTENT_TYPE_INVALID = 0, + HB_BUFFER_CONTENT_TYPE_UNICODE, + HB_BUFFER_CONTENT_TYPE_GLYPHS +} hb_buffer_content_type_t; + +void +hb_buffer_set_content_type (hb_buffer_t *buffer, + hb_buffer_content_type_t content_type); + +hb_buffer_content_type_t +hb_buffer_get_content_type (hb_buffer_t *buffer); + + +void +hb_buffer_set_unicode_funcs (hb_buffer_t *buffer, + hb_unicode_funcs_t *unicode_funcs); + +hb_unicode_funcs_t * +hb_buffer_get_unicode_funcs (hb_buffer_t *buffer); + +void +hb_buffer_set_direction (hb_buffer_t *buffer, + hb_direction_t direction); + +hb_direction_t +hb_buffer_get_direction (hb_buffer_t *buffer); + +void +hb_buffer_set_script (hb_buffer_t *buffer, + hb_script_t script); + +hb_script_t +hb_buffer_get_script (hb_buffer_t *buffer); + +void +hb_buffer_set_language (hb_buffer_t *buffer, + hb_language_t language); + + +hb_language_t +hb_buffer_get_language (hb_buffer_t *buffer); + +void +hb_buffer_set_segment_properties (hb_buffer_t *buffer, + const hb_segment_properties_t *props); + +void +hb_buffer_get_segment_properties (hb_buffer_t *buffer, + hb_segment_properties_t *props); + +void +hb_buffer_guess_segment_properties (hb_buffer_t *buffer); + + +typedef enum { + HB_BUFFER_FLAGS_DEFAULT = 0x00000000, + HB_BUFFER_FLAG_BOT = 0x00000001, /* Beginning-of-text */ + HB_BUFFER_FLAG_EOT = 0x00000002, /* End-of-text */ + HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES = 0x00000004 +} hb_buffer_flags_t; + +void +hb_buffer_set_flags (hb_buffer_t *buffer, + hb_buffer_flags_t flags); + +hb_buffer_flags_t +hb_buffer_get_flags (hb_buffer_t *buffer); + + +/* Resets the buffer. Afterwards it's as if it was just created, + * except that it has a larger buffer allocated perhaps... */ +void +hb_buffer_reset (hb_buffer_t *buffer); + +/* Like reset, but does NOT clear unicode_funcs. */ +void +hb_buffer_clear (hb_buffer_t *buffer); + +/* Returns false if allocation failed */ +hb_bool_t +hb_buffer_pre_allocate (hb_buffer_t *buffer, + unsigned int size); + + +/* Returns false if allocation has failed before */ +hb_bool_t +hb_buffer_allocation_successful (hb_buffer_t *buffer); + +void +hb_buffer_reverse (hb_buffer_t *buffer); + +void +hb_buffer_reverse_clusters (hb_buffer_t *buffer); + + +/* Filling the buffer in */ + +void +hb_buffer_add (hb_buffer_t *buffer, + hb_codepoint_t codepoint, + unsigned int cluster); + +void +hb_buffer_add_utf8 (hb_buffer_t *buffer, + const char *text, + int text_length, + unsigned int item_offset, + int item_length); + +void +hb_buffer_add_utf16 (hb_buffer_t *buffer, + const uint16_t *text, + int text_length, + unsigned int item_offset, + int item_length); + +void +hb_buffer_add_utf32 (hb_buffer_t *buffer, + const uint32_t *text, + int text_length, + unsigned int item_offset, + int item_length); + + +/* Clears any new items added at the end */ +hb_bool_t +hb_buffer_set_length (hb_buffer_t *buffer, + unsigned int length); + +/* Return value valid as long as buffer not modified */ +unsigned int +hb_buffer_get_length (hb_buffer_t *buffer); + +/* Getting glyphs out of the buffer */ + +/* Return value valid as long as buffer not modified */ +hb_glyph_info_t * +hb_buffer_get_glyph_infos (hb_buffer_t *buffer, + unsigned int *length); + +/* Return value valid as long as buffer not modified */ +hb_glyph_position_t * +hb_buffer_get_glyph_positions (hb_buffer_t *buffer, + unsigned int *length); + + +/* Reorders a glyph buffer to have canonical in-cluster glyph order / position. + * The resulting clusters should behave identical to pre-reordering clusters. + * NOTE: This has nothing to do with Unicode normalization. */ +void +hb_buffer_normalize_glyphs (hb_buffer_t *buffer); + + +/* + * Serialize + */ + +typedef enum { + HB_BUFFER_SERIALIZE_FLAGS_DEFAULT = 0x00000000, + HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS = 0x00000001, + HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS = 0x00000002, + HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES = 0x00000004 +} hb_buffer_serialize_flags_t; + +typedef enum { + HB_BUFFER_SERIALIZE_FORMAT_TEXT = HB_TAG('T','E','X','T'), + HB_BUFFER_SERIALIZE_FORMAT_JSON = HB_TAG('J','S','O','N'), + HB_BUFFER_SERIALIZE_FORMAT_INVALID = HB_TAG_NONE +} hb_buffer_serialize_format_t; + +/* len=-1 means str is NUL-terminated. */ +hb_buffer_serialize_format_t +hb_buffer_serialize_format_from_string (const char *str, int len); + +const char * +hb_buffer_serialize_format_to_string (hb_buffer_serialize_format_t format); + +const char ** +hb_buffer_serialize_list_formats (void); + +/* Returns number of items, starting at start, that were serialized. */ +unsigned int +hb_buffer_serialize_glyphs (hb_buffer_t *buffer, + unsigned int start, + unsigned int end, + char *buf, + unsigned int buf_size, + unsigned int *buf_consumed, + hb_font_t *font, /* May be NULL */ + hb_buffer_serialize_format_t format, + hb_buffer_serialize_flags_t flags); + +hb_bool_t +hb_buffer_deserialize_glyphs (hb_buffer_t *buffer, + const char *buf, + unsigned int buf_len, + unsigned int *buf_consumed, + hb_font_t *font, /* May be NULL */ + hb_buffer_serialize_format_t format); + + +HB_END_DECLS + +#endif /* HB_BUFFER_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-cache-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-cache-private.hh new file mode 100644 index 00000000000..19b70b7e395 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-cache-private.hh @@ -0,0 +1,74 @@ +/* + * Copyright © 2012 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_CACHE_PRIVATE_HH +#define HB_CACHE_PRIVATE_HH + +#include "hb-private.hh" + + +/* Implements a lock-free cache for int->int functions. */ + +template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bits> +struct hb_cache_t +{ + ASSERT_STATIC (key_bits >= cache_bits); + ASSERT_STATIC (key_bits + value_bits - cache_bits < 8 * sizeof (unsigned int)); + + inline void clear (void) + { + memset (values, 255, sizeof (values)); + } + + inline bool get (unsigned int key, unsigned int *value) + { + unsigned int k = key & ((1<<cache_bits)-1); + unsigned int v = values[k]; + if ((v >> value_bits) != (key >> cache_bits)) + return false; + *value = v & ((1<<value_bits)-1); + return true; + } + + inline bool set (unsigned int key, unsigned int value) + { + if (unlikely ((key >> key_bits) || (value >> value_bits))) + return false; /* Overflows */ + unsigned int k = key & ((1<<cache_bits)-1); + unsigned int v = ((key>>cache_bits)<<value_bits) | value; + values[k] = v; + return true; + } + + private: + unsigned int values[1<<cache_bits]; +}; + +typedef hb_cache_t<21, 16, 8> hb_cmap_cache_t; +typedef hb_cache_t<16, 24, 8> hb_advance_cache_t; + + +#endif /* HB_CACHE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.cc new file mode 100644 index 00000000000..9422555cfbc --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.cc @@ -0,0 +1,418 @@ +/* + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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 + */ + +#include "hb-private.hh" + +#include "hb-version.h" + +#include "hb-mutex-private.hh" +#include "hb-object-private.hh" + +#include <locale.h> + + + +/* hb_tag_t */ + +hb_tag_t +hb_tag_from_string (const char *s, int len) +{ + char tag[4]; + unsigned int i; + + if (!s || !len || !*s) + return HB_TAG_NONE; + + if (len < 0 || len > 4) + len = 4; + for (i = 0; i < (unsigned) len && s[i]; i++) + tag[i] = s[i]; + for (; i < 4; i++) + tag[i] = ' '; + + return HB_TAG_CHAR4 (tag); +} + +void +hb_tag_to_string (hb_tag_t tag, char *buf) +{ + buf[0] = (char) (uint8_t) (tag >> 24); + buf[1] = (char) (uint8_t) (tag >> 16); + buf[2] = (char) (uint8_t) (tag >> 8); + buf[3] = (char) (uint8_t) (tag >> 0); +} + + +/* hb_direction_t */ + +const char direction_strings[][4] = { + "ltr", + "rtl", + "ttb", + "btt" +}; + +hb_direction_t +hb_direction_from_string (const char *str, int len) +{ + if (unlikely (!str || !len || !*str)) + return HB_DIRECTION_INVALID; + + /* Lets match loosely: just match the first letter, such that + * all of "ltr", "left-to-right", etc work! + */ + char c = TOLOWER (str[0]); + for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++) + if (c == direction_strings[i][0]) + return (hb_direction_t) (HB_DIRECTION_LTR + i); + + return HB_DIRECTION_INVALID; +} + +const char * +hb_direction_to_string (hb_direction_t direction) +{ + if (likely ((unsigned int) (direction - HB_DIRECTION_LTR) + < ARRAY_LENGTH (direction_strings))) + return direction_strings[direction - HB_DIRECTION_LTR]; + + return "invalid"; +} + + +/* hb_language_t */ + +struct hb_language_impl_t { + const char s[1]; +}; + +static const char canon_map[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-', 0, 0, + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0, + '-', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, '-', + 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0, 0, 0, 0, 0 +}; + +static hb_bool_t +lang_equal (hb_language_t v1, + const void *v2) +{ + const unsigned char *p1 = (const unsigned char *) v1; + const unsigned char *p2 = (const unsigned char *) v2; + + while (*p1 && *p1 == canon_map[*p2]) + p1++, p2++; + + return *p1 == canon_map[*p2]; +} + +#if 0 +static unsigned int +lang_hash (const void *key) +{ + const unsigned char *p = key; + unsigned int h = 0; + while (canon_map[*p]) + { + h = (h << 5) - h + canon_map[*p]; + p++; + } + + return h; +} +#endif + + +struct hb_language_item_t { + + struct hb_language_item_t *next; + hb_language_t lang; + + inline bool operator == (const char *s) const { + return lang_equal (lang, s); + } + + inline hb_language_item_t & operator = (const char *s) { + lang = (hb_language_t) strdup (s); + for (unsigned char *p = (unsigned char *) lang; *p; p++) + *p = canon_map[*p]; + + return *this; + } + + void finish (void) { free (lang); } +}; + + +/* Thread-safe lock-free language list */ + +static hb_language_item_t *langs; + +static +void free_langs (void) +{ + while (langs) { + hb_language_item_t *next = langs->next; + langs->finish (); + free (langs); + langs = next; + } +} + +static hb_language_item_t * +lang_find_or_insert (const char *key) +{ +retry: + hb_language_item_t *first_lang = (hb_language_item_t *) hb_atomic_ptr_get (&langs); + + for (hb_language_item_t *lang = first_lang; lang; lang = lang->next) + if (*lang == key) + return lang; + + /* Not found; allocate one. */ + hb_language_item_t *lang = (hb_language_item_t *) calloc (1, sizeof (hb_language_item_t)); + if (unlikely (!lang)) + return NULL; + lang->next = first_lang; + *lang = key; + + if (!hb_atomic_ptr_cmpexch (&langs, first_lang, lang)) { + free (lang); + goto retry; + } + +#ifdef HAVE_ATEXIT + if (!first_lang) + atexit (free_langs); /* First person registers atexit() callback. */ +#endif + + return lang; +} + + +hb_language_t +hb_language_from_string (const char *str, int len) +{ + if (!str || !len || !*str) + return HB_LANGUAGE_INVALID; + + char strbuf[32]; + if (len >= 0) { + len = MIN (len, (int) sizeof (strbuf) - 1); + str = (char *) memcpy (strbuf, str, len); + strbuf[len] = '\0'; + } + + hb_language_item_t *item = lang_find_or_insert (str); + + return likely (item) ? item->lang : HB_LANGUAGE_INVALID; +} + +const char * +hb_language_to_string (hb_language_t language) +{ + /* This is actually NULL-safe! */ + return language->s; +} + +hb_language_t +hb_language_get_default (void) +{ + static hb_language_t default_language = HB_LANGUAGE_INVALID; + + hb_language_t language = (hb_language_t) hb_atomic_ptr_get (&default_language); + if (unlikely (language == HB_LANGUAGE_INVALID)) { + language = hb_language_from_string (setlocale (LC_CTYPE, NULL), -1); + hb_atomic_ptr_cmpexch (&default_language, HB_LANGUAGE_INVALID, language); + } + + return default_language; +} + + +/* hb_script_t */ + +hb_script_t +hb_script_from_iso15924_tag (hb_tag_t tag) +{ + if (unlikely (tag == HB_TAG_NONE)) + return HB_SCRIPT_INVALID; + + /* Be lenient, adjust case (one capital letter followed by three small letters) */ + tag = (tag & 0xDFDFDFDF) | 0x00202020; + + switch (tag) { + + /* These graduated from the 'Q' private-area codes, but + * the old code is still aliased by Unicode, and the Qaai + * one in use by ICU. */ + case HB_TAG('Q','a','a','i'): return HB_SCRIPT_INHERITED; + case HB_TAG('Q','a','a','c'): return HB_SCRIPT_COPTIC; + + /* Script variants from http://unicode.org/iso15924/ */ + case HB_TAG('C','y','r','s'): return HB_SCRIPT_CYRILLIC; + case HB_TAG('L','a','t','f'): return HB_SCRIPT_LATIN; + case HB_TAG('L','a','t','g'): return HB_SCRIPT_LATIN; + case HB_TAG('S','y','r','e'): return HB_SCRIPT_SYRIAC; + case HB_TAG('S','y','r','j'): return HB_SCRIPT_SYRIAC; + case HB_TAG('S','y','r','n'): return HB_SCRIPT_SYRIAC; + } + + /* If it looks right, just use the tag as a script */ + if (((uint32_t) tag & 0xE0E0E0E0) == 0x40606060) + return (hb_script_t) tag; + + /* Otherwise, return unknown */ + return HB_SCRIPT_UNKNOWN; +} + +hb_script_t +hb_script_from_string (const char *s, int len) +{ + return hb_script_from_iso15924_tag (hb_tag_from_string (s, len)); +} + +hb_tag_t +hb_script_to_iso15924_tag (hb_script_t script) +{ + return (hb_tag_t) script; +} + +hb_direction_t +hb_script_get_horizontal_direction (hb_script_t script) +{ + /* http://goo.gl/x9ilM */ + switch ((hb_tag_t) script) + { + /* Unicode-1.1 additions */ + case HB_SCRIPT_ARABIC: + case HB_SCRIPT_HEBREW: + + /* Unicode-3.0 additions */ + case HB_SCRIPT_SYRIAC: + case HB_SCRIPT_THAANA: + + /* Unicode-4.0 additions */ + case HB_SCRIPT_CYPRIOT: + + /* Unicode-4.1 additions */ + case HB_SCRIPT_KHAROSHTHI: + + /* Unicode-5.0 additions */ + case HB_SCRIPT_PHOENICIAN: + case HB_SCRIPT_NKO: + + /* Unicode-5.1 additions */ + case HB_SCRIPT_LYDIAN: + + /* Unicode-5.2 additions */ + case HB_SCRIPT_AVESTAN: + case HB_SCRIPT_IMPERIAL_ARAMAIC: + case HB_SCRIPT_INSCRIPTIONAL_PAHLAVI: + case HB_SCRIPT_INSCRIPTIONAL_PARTHIAN: + case HB_SCRIPT_OLD_SOUTH_ARABIAN: + case HB_SCRIPT_OLD_TURKIC: + case HB_SCRIPT_SAMARITAN: + + /* Unicode-6.0 additions */ + case HB_SCRIPT_MANDAIC: + + /* Unicode-6.1 additions */ + case HB_SCRIPT_MEROITIC_CURSIVE: + case HB_SCRIPT_MEROITIC_HIEROGLYPHS: + + return HB_DIRECTION_RTL; + } + + return HB_DIRECTION_LTR; +} + + +/* hb_user_data_array_t */ + +bool +hb_user_data_array_t::set (hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + if (!key) + return false; + + if (replace) { + if (!data && !destroy) { + items.remove (key, lock); + return true; + } + } + hb_user_data_item_t item = {key, data, destroy}; + bool ret = !!items.replace_or_insert (item, lock, replace); + + return ret; +} + +void * +hb_user_data_array_t::get (hb_user_data_key_t *key) +{ + hb_user_data_item_t item = {NULL }; + + return items.find (key, &item, lock) ? item.data : NULL; +} + + +/* hb_version */ + +void +hb_version (unsigned int *major, + unsigned int *minor, + unsigned int *micro) +{ + *major = HB_VERSION_MAJOR; + *minor = HB_VERSION_MINOR; + *micro = HB_VERSION_MICRO; +} + +const char * +hb_version_string (void) +{ + return HB_VERSION_STRING; +} + +hb_bool_t +hb_version_check (unsigned int major, + unsigned int minor, + unsigned int micro) +{ + return HB_VERSION_CHECK (major, minor, micro); +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.h new file mode 100644 index 00000000000..cc221d33be9 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-common.h @@ -0,0 +1,317 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2011,2012 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_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_COMMON_H +#define HB_COMMON_H + +#ifndef HB_BEGIN_DECLS +# ifdef __cplusplus +# define HB_BEGIN_DECLS extern "C" { +# define HB_END_DECLS } +# else /* !__cplusplus */ +# define HB_BEGIN_DECLS +# define HB_END_DECLS +# endif /* !__cplusplus */ +#endif + +#if !defined (HB_DONT_DEFINE_STDINT) + +#if defined (_SVR4) || defined (SVR4) || defined (__OpenBSD__) || \ + defined (_sgi) || defined (__sun) || defined (sun) || \ + defined (__digital__) || defined (__HP_cc) +# include <inttypes.h> +#elif defined (_AIX) +# include <sys/inttypes.h> +/* VS 2010 (_MSC_VER 1600) has stdint.h */ +#elif defined (_MSC_VER) && _MSC_VER < 1600 +typedef __int8 int8_t; +typedef unsigned __int8 uint8_t; +typedef __int16 int16_t; +typedef unsigned __int16 uint16_t; +typedef __int32 int32_t; +typedef unsigned __int32 uint32_t; +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +#else +# include <stdint.h> +#endif + +#endif + +HB_BEGIN_DECLS + + +typedef int hb_bool_t; + +typedef uint32_t hb_codepoint_t; +typedef int32_t hb_position_t; +typedef uint32_t hb_mask_t; + +typedef union _hb_var_int_t { + uint32_t u32; + int32_t i32; + uint16_t u16[2]; + int16_t i16[2]; + uint8_t u8[4]; + int8_t i8[4]; +} hb_var_int_t; + + +/* hb_tag_t */ + +typedef uint32_t hb_tag_t; + +#define HB_TAG(a,b,c,d) ((hb_tag_t)((((uint8_t)(a))<<24)|(((uint8_t)(b))<<16)|(((uint8_t)(c))<<8)|((uint8_t)(d)))) +#define HB_UNTAG(tag) ((uint8_t)((tag)>>24)), ((uint8_t)((tag)>>16)), ((uint8_t)((tag)>>8)), ((uint8_t)(tag)) + +#define HB_TAG_NONE HB_TAG(0,0,0,0) + +/* len=-1 means str is NUL-terminated. */ +hb_tag_t +hb_tag_from_string (const char *str, int len); + +/* buf should have 4 bytes. */ +void +hb_tag_to_string (hb_tag_t tag, char *buf); + + +/* hb_direction_t */ + +typedef enum { + HB_DIRECTION_INVALID = 0, + HB_DIRECTION_LTR = 4, + HB_DIRECTION_RTL, + HB_DIRECTION_TTB, + HB_DIRECTION_BTT +} hb_direction_t; + +/* len=-1 means str is NUL-terminated */ +hb_direction_t +hb_direction_from_string (const char *str, int len); + +const char * +hb_direction_to_string (hb_direction_t direction); + +#define HB_DIRECTION_IS_HORIZONTAL(dir) ((((unsigned int) (dir)) & ~1U) == 4) +#define HB_DIRECTION_IS_VERTICAL(dir) ((((unsigned int) (dir)) & ~1U) == 6) +#define HB_DIRECTION_IS_FORWARD(dir) ((((unsigned int) (dir)) & ~2U) == 4) +#define HB_DIRECTION_IS_BACKWARD(dir) ((((unsigned int) (dir)) & ~2U) == 5) +#define HB_DIRECTION_IS_VALID(dir) ((((unsigned int) (dir)) & ~3U) == 4) +#define HB_DIRECTION_REVERSE(dir) ((hb_direction_t) (((unsigned int) (dir)) ^ 1)) /* Direction must be valid */ + + +/* hb_language_t */ + +typedef struct hb_language_impl_t *hb_language_t; + +/* len=-1 means str is NUL-terminated */ +hb_language_t +hb_language_from_string (const char *str, int len); + +const char * +hb_language_to_string (hb_language_t language); + +#define HB_LANGUAGE_INVALID ((hb_language_t) NULL) + +hb_language_t +hb_language_get_default (void); + + +/* hb_script_t */ + +/* http://unicode.org/iso15924/ */ +/* http://goo.gl/x9ilM */ +/* Unicode Character Database property: Script (sc) */ +typedef enum +{ + /* Unicode-1.1 additions */ + HB_SCRIPT_COMMON = HB_TAG ('Z','y','y','y'), + HB_SCRIPT_ARABIC = HB_TAG ('A','r','a','b'), + HB_SCRIPT_ARMENIAN = HB_TAG ('A','r','m','n'), + HB_SCRIPT_BENGALI = HB_TAG ('B','e','n','g'), + HB_SCRIPT_BOPOMOFO = HB_TAG ('B','o','p','o'), + HB_SCRIPT_CANADIAN_ABORIGINAL = HB_TAG ('C','a','n','s'), + HB_SCRIPT_CHEROKEE = HB_TAG ('C','h','e','r'), + HB_SCRIPT_COPTIC = HB_TAG ('C','o','p','t'), + HB_SCRIPT_CYRILLIC = HB_TAG ('C','y','r','l'), + HB_SCRIPT_DEVANAGARI = HB_TAG ('D','e','v','a'), + HB_SCRIPT_GEORGIAN = HB_TAG ('G','e','o','r'), + HB_SCRIPT_GREEK = HB_TAG ('G','r','e','k'), + HB_SCRIPT_GUJARATI = HB_TAG ('G','u','j','r'), + HB_SCRIPT_GURMUKHI = HB_TAG ('G','u','r','u'), + HB_SCRIPT_HANGUL = HB_TAG ('H','a','n','g'), + HB_SCRIPT_HAN = HB_TAG ('H','a','n','i'), + HB_SCRIPT_HEBREW = HB_TAG ('H','e','b','r'), + HB_SCRIPT_HIRAGANA = HB_TAG ('H','i','r','a'), + HB_SCRIPT_INHERITED = HB_TAG ('Z','i','n','h'), + HB_SCRIPT_KANNADA = HB_TAG ('K','n','d','a'), + HB_SCRIPT_KATAKANA = HB_TAG ('K','a','n','a'), + HB_SCRIPT_LAO = HB_TAG ('L','a','o','o'), + HB_SCRIPT_LATIN = HB_TAG ('L','a','t','n'), + HB_SCRIPT_MALAYALAM = HB_TAG ('M','l','y','m'), + HB_SCRIPT_MONGOLIAN = HB_TAG ('M','o','n','g'), + HB_SCRIPT_OGHAM = HB_TAG ('O','g','a','m'), + HB_SCRIPT_ORIYA = HB_TAG ('O','r','y','a'), + HB_SCRIPT_RUNIC = HB_TAG ('R','u','n','r'), + HB_SCRIPT_SYRIAC = HB_TAG ('S','y','r','c'), + HB_SCRIPT_TAMIL = HB_TAG ('T','a','m','l'), + HB_SCRIPT_TELUGU = HB_TAG ('T','e','l','u'), + HB_SCRIPT_THAI = HB_TAG ('T','h','a','i'), + HB_SCRIPT_YI = HB_TAG ('Y','i','i','i'), + + /* Unicode-2.0 additions */ + HB_SCRIPT_TIBETAN = HB_TAG ('T','i','b','t'), + + /* Unicode-3.0 additions */ + HB_SCRIPT_ETHIOPIC = HB_TAG ('E','t','h','i'), + HB_SCRIPT_KHMER = HB_TAG ('K','h','m','r'), + HB_SCRIPT_MYANMAR = HB_TAG ('M','y','m','r'), + HB_SCRIPT_SINHALA = HB_TAG ('S','i','n','h'), + HB_SCRIPT_THAANA = HB_TAG ('T','h','a','a'), + + /* Unicode-3.1 additions */ + HB_SCRIPT_DESERET = HB_TAG ('D','s','r','t'), + HB_SCRIPT_GOTHIC = HB_TAG ('G','o','t','h'), + HB_SCRIPT_OLD_ITALIC = HB_TAG ('I','t','a','l'), + + /* Unicode-3.2 additions */ + HB_SCRIPT_BUHID = HB_TAG ('B','u','h','d'), + HB_SCRIPT_HANUNOO = HB_TAG ('H','a','n','o'), + HB_SCRIPT_TAGALOG = HB_TAG ('T','g','l','g'), + HB_SCRIPT_TAGBANWA = HB_TAG ('T','a','g','b'), + + /* Unicode-4.0 additions */ + HB_SCRIPT_BRAILLE = HB_TAG ('B','r','a','i'), + HB_SCRIPT_CYPRIOT = HB_TAG ('C','p','r','t'), + HB_SCRIPT_LIMBU = HB_TAG ('L','i','m','b'), + HB_SCRIPT_LINEAR_B = HB_TAG ('L','i','n','b'), + HB_SCRIPT_OSMANYA = HB_TAG ('O','s','m','a'), + HB_SCRIPT_SHAVIAN = HB_TAG ('S','h','a','w'), + HB_SCRIPT_TAI_LE = HB_TAG ('T','a','l','e'), + HB_SCRIPT_UGARITIC = HB_TAG ('U','g','a','r'), + + /* Unicode-4.1 additions */ + HB_SCRIPT_BUGINESE = HB_TAG ('B','u','g','i'), + HB_SCRIPT_GLAGOLITIC = HB_TAG ('G','l','a','g'), + HB_SCRIPT_KHAROSHTHI = HB_TAG ('K','h','a','r'), + HB_SCRIPT_NEW_TAI_LUE = HB_TAG ('T','a','l','u'), + HB_SCRIPT_OLD_PERSIAN = HB_TAG ('X','p','e','o'), + HB_SCRIPT_SYLOTI_NAGRI = HB_TAG ('S','y','l','o'), + HB_SCRIPT_TIFINAGH = HB_TAG ('T','f','n','g'), + + /* Unicode-5.0 additions */ + HB_SCRIPT_BALINESE = HB_TAG ('B','a','l','i'), + HB_SCRIPT_CUNEIFORM = HB_TAG ('X','s','u','x'), + HB_SCRIPT_NKO = HB_TAG ('N','k','o','o'), + HB_SCRIPT_PHAGS_PA = HB_TAG ('P','h','a','g'), + HB_SCRIPT_PHOENICIAN = HB_TAG ('P','h','n','x'), + HB_SCRIPT_UNKNOWN = HB_TAG ('Z','z','z','z'), + + /* Unicode-5.1 additions */ + HB_SCRIPT_CARIAN = HB_TAG ('C','a','r','i'), + HB_SCRIPT_CHAM = HB_TAG ('C','h','a','m'), + HB_SCRIPT_KAYAH_LI = HB_TAG ('K','a','l','i'), + HB_SCRIPT_LEPCHA = HB_TAG ('L','e','p','c'), + HB_SCRIPT_LYCIAN = HB_TAG ('L','y','c','i'), + HB_SCRIPT_LYDIAN = HB_TAG ('L','y','d','i'), + HB_SCRIPT_OL_CHIKI = HB_TAG ('O','l','c','k'), + HB_SCRIPT_REJANG = HB_TAG ('R','j','n','g'), + HB_SCRIPT_SAURASHTRA = HB_TAG ('S','a','u','r'), + HB_SCRIPT_SUNDANESE = HB_TAG ('S','u','n','d'), + HB_SCRIPT_VAI = HB_TAG ('V','a','i','i'), + + /* Unicode-5.2 additions */ + HB_SCRIPT_AVESTAN = HB_TAG ('A','v','s','t'), + HB_SCRIPT_BAMUM = HB_TAG ('B','a','m','u'), + HB_SCRIPT_EGYPTIAN_HIEROGLYPHS = HB_TAG ('E','g','y','p'), + HB_SCRIPT_IMPERIAL_ARAMAIC = HB_TAG ('A','r','m','i'), + HB_SCRIPT_INSCRIPTIONAL_PAHLAVI = HB_TAG ('P','h','l','i'), + HB_SCRIPT_INSCRIPTIONAL_PARTHIAN = HB_TAG ('P','r','t','i'), + HB_SCRIPT_JAVANESE = HB_TAG ('J','a','v','a'), + HB_SCRIPT_KAITHI = HB_TAG ('K','t','h','i'), + HB_SCRIPT_LISU = HB_TAG ('L','i','s','u'), + HB_SCRIPT_MEETEI_MAYEK = HB_TAG ('M','t','e','i'), + HB_SCRIPT_OLD_SOUTH_ARABIAN = HB_TAG ('S','a','r','b'), + HB_SCRIPT_OLD_TURKIC = HB_TAG ('O','r','k','h'), + HB_SCRIPT_SAMARITAN = HB_TAG ('S','a','m','r'), + HB_SCRIPT_TAI_THAM = HB_TAG ('L','a','n','a'), + HB_SCRIPT_TAI_VIET = HB_TAG ('T','a','v','t'), + + /* Unicode-6.0 additions */ + HB_SCRIPT_BATAK = HB_TAG ('B','a','t','k'), + HB_SCRIPT_BRAHMI = HB_TAG ('B','r','a','h'), + HB_SCRIPT_MANDAIC = HB_TAG ('M','a','n','d'), + + /* Unicode-6.1 additions */ + HB_SCRIPT_CHAKMA = HB_TAG ('C','a','k','m'), + HB_SCRIPT_MEROITIC_CURSIVE = HB_TAG ('M','e','r','c'), + HB_SCRIPT_MEROITIC_HIEROGLYPHS = HB_TAG ('M','e','r','o'), + HB_SCRIPT_MIAO = HB_TAG ('P','l','r','d'), + HB_SCRIPT_SHARADA = HB_TAG ('S','h','r','d'), + HB_SCRIPT_SORA_SOMPENG = HB_TAG ('S','o','r','a'), + HB_SCRIPT_TAKRI = HB_TAG ('T','a','k','r'), + + /* No script set */ + HB_SCRIPT_INVALID = HB_TAG_NONE +} hb_script_t; + + +/* Script functions */ + +hb_script_t +hb_script_from_iso15924_tag (hb_tag_t tag); + +/* suger for tag_from_string() then script_from_iso15924_tag */ +/* len=-1 means s is NUL-terminated */ +hb_script_t +hb_script_from_string (const char *s, int len); + +hb_tag_t +hb_script_to_iso15924_tag (hb_script_t script); + +hb_direction_t +hb_script_get_horizontal_direction (hb_script_t script); + + +/* User data */ + +typedef struct hb_user_data_key_t { + /*< private >*/ + char unused; +} hb_user_data_key_t; + +typedef void (*hb_destroy_func_t) (void *user_data); + + +HB_END_DECLS + +#endif /* HB_COMMON_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.cc new file mode 100644 index 00000000000..8f94795928c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.cc @@ -0,0 +1,355 @@ +/* + * Copyright © 2012 Mozilla Foundation. + * Copyright © 2012 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. + * + * Mozilla Author(s): Jonathan Kew + * Google Author(s): Behdad Esfahbod + */ + +#define HB_SHAPER coretext +#include "hb-shaper-impl-private.hh" + +#include "hb-coretext.h" + + +#ifndef HB_DEBUG_CORETEXT +#define HB_DEBUG_CORETEXT (HB_DEBUG+0) +#endif + + +HB_SHAPER_DATA_ENSURE_DECLARE(coretext, face) +HB_SHAPER_DATA_ENSURE_DECLARE(coretext, font) + + +/* + * shaper face data + */ + +struct hb_coretext_shaper_face_data_t { + CGFontRef cg_font; +}; + +static void +release_data (void *info, const void *data, size_t size) +{ + assert (hb_blob_get_length ((hb_blob_t *) info) == size && + hb_blob_get_data ((hb_blob_t *) info, NULL) == data); + + hb_blob_destroy ((hb_blob_t *) info); +} + +hb_coretext_shaper_face_data_t * +_hb_coretext_shaper_face_data_create (hb_face_t *face) +{ + hb_coretext_shaper_face_data_t *data = (hb_coretext_shaper_face_data_t *) calloc (1, sizeof (hb_coretext_shaper_face_data_t)); + if (unlikely (!data)) + return NULL; + + hb_blob_t *blob = hb_face_reference_blob (face); + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (blob, &blob_length); + if (unlikely (!blob_length)) + DEBUG_MSG (CORETEXT, face, "Face has empty blob"); + + CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data); + data->cg_font = CGFontCreateWithDataProvider (provider); + CGDataProviderRelease (provider); + + if (unlikely (!data->cg_font)) { + DEBUG_MSG (CORETEXT, face, "Face CGFontCreateWithDataProvider() failed"); + free (data); + return NULL; + } + + return data; +} + +void +_hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data) +{ + CFRelease (data->cg_font); + free (data); +} + +CGFontRef +hb_coretext_face_get_cg_font (hb_face_t *face) +{ + if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL; + hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); + return face_data->cg_font; +} + + +/* + * shaper font data + */ + +struct hb_coretext_shaper_font_data_t { + CTFontRef ct_font; +}; + +hb_coretext_shaper_font_data_t * +_hb_coretext_shaper_font_data_create (hb_font_t *font) +{ + if (unlikely (!hb_coretext_shaper_face_data_ensure (font->face))) return NULL; + + hb_coretext_shaper_font_data_t *data = (hb_coretext_shaper_font_data_t *) calloc (1, sizeof (hb_coretext_shaper_font_data_t)); + if (unlikely (!data)) + return NULL; + + hb_face_t *face = font->face; + hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); + + data->ct_font = CTFontCreateWithGraphicsFont (face_data->cg_font, font->y_scale, NULL, NULL); + if (unlikely (!data->ct_font)) { + DEBUG_MSG (CORETEXT, font, "Font CTFontCreateWithGraphicsFont() failed"); + free (data); + return NULL; + } + + return data; +} + +void +_hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *data) +{ + CFRelease (data->ct_font); + free (data); +} + + +/* + * shaper shape_plan data + */ + +struct hb_coretext_shaper_shape_plan_data_t {}; + +hb_coretext_shaper_shape_plan_data_t * +_hb_coretext_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features HB_UNUSED, + unsigned int num_user_features HB_UNUSED) +{ + return (hb_coretext_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shaper_shape_plan_data_t *data HB_UNUSED) +{ +} + +CTFontRef +hb_coretext_font_get_ct_font (hb_font_t *font) +{ + if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return NULL; + hb_coretext_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); + return font_data->ct_font; +} + + +/* + * shaper + */ + +hb_bool_t +_hb_coretext_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_face_t *face = font->face; + hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); + hb_coretext_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); + +#define FAIL(...) \ + HB_STMT_START { \ + DEBUG_MSG (CORETEXT, NULL, __VA_ARGS__); \ + return false; \ + } HB_STMT_END; + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + +#define utf16_index() var1.u32 + + UniChar *pchars = (UniChar *) scratch; + unsigned int chars_len = 0; + for (unsigned int i = 0; i < buffer->len; i++) { + hb_codepoint_t c = buffer->info[i].codepoint; + buffer->info[i].utf16_index() = chars_len; + if (likely (c < 0x10000)) + pchars[chars_len++] = c; + else if (unlikely (c >= 0x110000)) + pchars[chars_len++] = 0xFFFD; + else { + pchars[chars_len++] = 0xD800 + ((c - 0x10000) >> 10); + pchars[chars_len++] = 0xDC00 + ((c - 0x10000) & ((1 << 10) - 1)); + } + } + +#undef utf16_index + + CFStringRef string_ref = CFStringCreateWithCharactersNoCopy (kCFAllocatorDefault, + pchars, chars_len, + kCFAllocatorNull); + + CFDictionaryRef attrs = CFDictionaryCreate (kCFAllocatorDefault, + (const void**) &kCTFontAttributeName, + (const void**) &font_data->ct_font, + 1, /* count of attributes */ + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + + /* TODO: support features */ + + CFAttributedStringRef attr_string = CFAttributedStringCreate (kCFAllocatorDefault, string_ref, attrs); + CFRelease (string_ref); + CFRelease (attrs); + + CTLineRef line = CTLineCreateWithAttributedString (attr_string); + CFRelease (attr_string); + + CFArrayRef glyph_runs = CTLineGetGlyphRuns (line); + unsigned int num_runs = CFArrayGetCount (glyph_runs); + + bool success = true; + buffer->len = 0; + + const CFRange range_all = CFRangeMake (0, 0); + + for (unsigned int i = 0; i < num_runs; i++) { + CTRunRef run = (CTRunRef) CFArrayGetValueAtIndex (glyph_runs, i); + + unsigned int num_glyphs = CTRunGetGlyphCount (run); + if (num_glyphs == 0) + continue; + + buffer->ensure (buffer->len + num_glyphs); + + /* Testing indicates that CTRunGetGlyphsPtr (almost?) always succeeds, + * and so copying data to our own buffer with CTRunGetGlyphs will be + * extremely rare. */ + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + +#define ALLOCATE_ARRAY(Type, name, len) \ + Type *name = (Type *) scratch; \ + scratch += (len) * sizeof ((name)[0]); \ + scratch_size -= (len) * sizeof ((name)[0]); + + const CGGlyph* glyphs = CTRunGetGlyphsPtr (run); + if (!glyphs) { + ALLOCATE_ARRAY (CGGlyph, glyph_buf, num_glyphs); + CTRunGetGlyphs (run, range_all, glyph_buf); + glyphs = glyph_buf; + } + + const CGPoint* positions = CTRunGetPositionsPtr (run); + if (!positions) { + ALLOCATE_ARRAY (CGPoint, position_buf, num_glyphs); + CTRunGetPositions (run, range_all, position_buf); + positions = position_buf; + } + + const CFIndex* string_indices = CTRunGetStringIndicesPtr (run); + if (!string_indices) { + ALLOCATE_ARRAY (CFIndex, index_buf, num_glyphs); + CTRunGetStringIndices (run, range_all, index_buf); + string_indices = index_buf; + } + +#undef ALLOCATE_ARRAY + + double run_width = CTRunGetTypographicBounds (run, range_all, NULL, NULL, NULL); + + for (unsigned int j = 0; j < num_glyphs; j++) { + double advance = (j + 1 < num_glyphs ? positions[j + 1].x : positions[0].x + run_width) - positions[j].x; + + hb_glyph_info_t *info = &buffer->info[buffer->len]; + hb_glyph_position_t *pos = &buffer->pos[buffer->len]; + + info->codepoint = glyphs[j]; + info->cluster = string_indices[j]; + + /* Currently, we do all x-positioning by setting the advance, we never use x-offset. */ + info->mask = advance; + info->var1.u32 = 0; + info->var2.u32 = positions[j].y; + + buffer->len++; + } + } + + buffer->clear_positions (); + + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; ++i) { + hb_glyph_info_t *info = &buffer->info[i]; + hb_glyph_position_t *pos = &buffer->pos[i]; + + /* TODO vertical */ + pos->x_advance = info->mask; + pos->x_offset = info->var1.u32; + pos->y_offset = info->var2.u32; + } + + /* Fix up clusters so that we never return out-of-order indices; + * if core text has reordered glyphs, we'll merge them to the + * beginning of the reordered cluster. + * + * This does *not* mean we'll form the same clusters as Uniscribe + * or the native OT backend, only that the cluster indices will be + * monotonic in the output buffer. */ + if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { + unsigned int prev_cluster = 0; + for (unsigned int i = 0; i < count; i++) { + unsigned int curr_cluster = buffer->info[i].cluster; + if (curr_cluster < prev_cluster) { + for (unsigned int j = i; j > 0; j--) { + if (buffer->info[j - 1].cluster > curr_cluster) + buffer->info[j - 1].cluster = curr_cluster; + else + break; + } + } + prev_cluster = curr_cluster; + } + } else { + unsigned int prev_cluster = (unsigned int)-1; + for (unsigned int i = 0; i < count; i++) { + unsigned int curr_cluster = buffer->info[i].cluster; + if (curr_cluster > prev_cluster) { + for (unsigned int j = i; j > 0; j--) { + if (buffer->info[j - 1].cluster < curr_cluster) + buffer->info[j - 1].cluster = curr_cluster; + else + break; + } + } + prev_cluster = curr_cluster; + } + } + + return true; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.h new file mode 100644 index 00000000000..c4954fa1b2c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-coretext.h @@ -0,0 +1,46 @@ +/* + * Copyright © 2012 Mozilla Foundation. + * + * 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. + * + * Mozilla Author(s): Jonathan Kew + */ + +#ifndef HB_CORETEXT_H +#define HB_CORETEXT_H + +#include "hb.h" + +#include <ApplicationServices/ApplicationServices.h> + +HB_BEGIN_DECLS + + +CGFontRef +hb_coretext_face_get_cg_font (hb_face_t *face); + +CTFontRef +hb_coretext_font_get_ct_font (hb_font_t *font); + + +HB_END_DECLS + +#endif /* HB_CORETEXT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-fallback-shape.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-fallback-shape.cc new file mode 100644 index 00000000000..bdc8a80c4bd --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-fallback-shape.cc @@ -0,0 +1,129 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#define HB_SHAPER fallback +#include "hb-shaper-impl-private.hh" + + +/* + * shaper face data + */ + +struct hb_fallback_shaper_face_data_t {}; + +hb_fallback_shaper_face_data_t * +_hb_fallback_shaper_face_data_create (hb_face_t *face HB_UNUSED) +{ + return (hb_fallback_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_fallback_shaper_face_data_destroy (hb_fallback_shaper_face_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper font data + */ + +struct hb_fallback_shaper_font_data_t {}; + +hb_fallback_shaper_font_data_t * +_hb_fallback_shaper_font_data_create (hb_font_t *font HB_UNUSED) +{ + return (hb_fallback_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_fallback_shaper_font_data_destroy (hb_fallback_shaper_font_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper shape_plan data + */ + +struct hb_fallback_shaper_shape_plan_data_t {}; + +hb_fallback_shaper_shape_plan_data_t * +_hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features HB_UNUSED, + unsigned int num_user_features HB_UNUSED) +{ + return (hb_fallback_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shaper_shape_plan_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper + */ + +hb_bool_t +_hb_fallback_shape (hb_shape_plan_t *shape_plan HB_UNUSED, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features HB_UNUSED, + unsigned int num_features HB_UNUSED) +{ + hb_codepoint_t space; + font->get_glyph (' ', 0, &space); + + buffer->guess_segment_properties (); + buffer->clear_positions (); + + unsigned int count = buffer->len; + + for (unsigned int i = 0; i < count; i++) + { + if (buffer->unicode->is_default_ignorable (buffer->info[i].codepoint)) { + buffer->info[i].codepoint = space; + buffer->pos[i].x_advance = 0; + buffer->pos[i].y_advance = 0; + continue; + } + font->get_glyph (buffer->info[i].codepoint, 0, &buffer->info[i].codepoint); + font->get_glyph_advance_for_direction (buffer->info[i].codepoint, + buffer->props.direction, + &buffer->pos[i].x_advance, + &buffer->pos[i].y_advance); + font->subtract_glyph_origin_for_direction (buffer->info[i].codepoint, + buffer->props.direction, + &buffer->pos[i].x_offset, + &buffer->pos[i].y_offset); + } + + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + hb_buffer_reverse (buffer); + + return true; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font-private.hh new file mode 100644 index 00000000000..48fbb0ee549 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font-private.hh @@ -0,0 +1,469 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_FONT_PRIVATE_HH +#define HB_FONT_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-font.h" +#include "hb-object-private.hh" +#include "hb-shaper-private.hh" +#include "hb-shape-plan-private.hh" + + + +/* + * hb_font_funcs_t + */ + +#define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \ + HB_FONT_FUNC_IMPLEMENT (glyph) \ + HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \ + HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \ + HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \ + HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \ + HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \ + HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \ + HB_FONT_FUNC_IMPLEMENT (glyph_extents) \ + HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \ + HB_FONT_FUNC_IMPLEMENT (glyph_name) \ + HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ + /* ^--- Add new callbacks here */ + +struct hb_font_funcs_t { + hb_object_header_t header; + ASSERT_POD (); + + hb_bool_t immutable; + + /* Don't access these directly. Call hb_font_get_*() instead. */ + + struct { +#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_func_t name; + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + } get; + + struct { +#define HB_FONT_FUNC_IMPLEMENT(name) void *name; + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + } user_data; + + struct { +#define HB_FONT_FUNC_IMPLEMENT(name) hb_destroy_func_t name; + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + } destroy; +}; + + +/* + * hb_face_t + */ + +struct hb_face_t { + hb_object_header_t header; + ASSERT_POD (); + + hb_bool_t immutable; + + hb_reference_table_func_t reference_table_func; + void *user_data; + hb_destroy_func_t destroy; + + unsigned int index; + mutable unsigned int upem; + mutable unsigned int num_glyphs; + + struct hb_shaper_data_t shaper_data; + + struct plan_node_t { + hb_shape_plan_t *shape_plan; + plan_node_t *next; + } *shape_plans; + + + inline hb_blob_t *reference_table (hb_tag_t tag) const + { + hb_blob_t *blob; + + if (unlikely (!this || !reference_table_func)) + return hb_blob_get_empty (); + + blob = reference_table_func (/*XXX*/const_cast<hb_face_t *> (this), tag, user_data); + if (unlikely (!blob)) + return hb_blob_get_empty (); + + return blob; + } + + inline unsigned int get_upem (void) const + { + if (unlikely (!upem)) + load_upem (); + return upem; + } + + inline unsigned int get_num_glyphs (void) const + { + if (unlikely (num_glyphs == (unsigned int) -1)) + load_num_glyphs (); + return num_glyphs; + } + + private: + HB_INTERNAL void load_upem (void) const; + HB_INTERNAL void load_num_glyphs (void) const; +}; + +#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT +#undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS + + +/* + * hb_font_t + */ + +struct hb_font_t { + hb_object_header_t header; + ASSERT_POD (); + + hb_bool_t immutable; + + hb_font_t *parent; + hb_face_t *face; + + int x_scale; + int y_scale; + + unsigned int x_ppem; + unsigned int y_ppem; + + hb_font_funcs_t *klass; + void *user_data; + hb_destroy_func_t destroy; + + struct hb_shaper_data_t shaper_data; + + + /* Convert from font-space to user-space */ + inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); } + inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); } + + /* Convert from parent-font user-space to our user-space */ + inline hb_position_t parent_scale_x_distance (hb_position_t v) { + if (unlikely (parent && parent->x_scale != x_scale)) + return v * (int64_t) this->x_scale / this->parent->x_scale; + return v; + } + inline hb_position_t parent_scale_y_distance (hb_position_t v) { + if (unlikely (parent && parent->y_scale != y_scale)) + return v * (int64_t) this->y_scale / this->parent->y_scale; + return v; + } + inline hb_position_t parent_scale_x_position (hb_position_t v) { + return parent_scale_x_distance (v); + } + inline hb_position_t parent_scale_y_position (hb_position_t v) { + return parent_scale_y_distance (v); + } + + inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) { + *x = parent_scale_x_distance (*x); + *y = parent_scale_y_distance (*y); + } + inline void parent_scale_position (hb_position_t *x, hb_position_t *y) { + *x = parent_scale_x_position (*x); + *y = parent_scale_y_position (*y); + } + + + /* Public getters */ + + inline hb_bool_t get_glyph (hb_codepoint_t unicode, hb_codepoint_t variation_selector, + hb_codepoint_t *glyph) + { + *glyph = 0; + return klass->get.glyph (this, user_data, + unicode, variation_selector, glyph, + klass->user_data.glyph); + } + + inline hb_position_t get_glyph_h_advance (hb_codepoint_t glyph) + { + return klass->get.glyph_h_advance (this, user_data, + glyph, + klass->user_data.glyph_h_advance); + } + + inline hb_position_t get_glyph_v_advance (hb_codepoint_t glyph) + { + return klass->get.glyph_v_advance (this, user_data, + glyph, + klass->user_data.glyph_v_advance); + } + + inline hb_bool_t get_glyph_h_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + *x = *y = 0; + return klass->get.glyph_h_origin (this, user_data, + glyph, x, y, + klass->user_data.glyph_h_origin); + } + + inline hb_bool_t get_glyph_v_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + *x = *y = 0; + return klass->get.glyph_v_origin (this, user_data, + glyph, x, y, + klass->user_data.glyph_v_origin); + } + + inline hb_position_t get_glyph_h_kerning (hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) + { + return klass->get.glyph_h_kerning (this, user_data, + left_glyph, right_glyph, + klass->user_data.glyph_h_kerning); + } + + inline hb_position_t get_glyph_v_kerning (hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) + { + return klass->get.glyph_v_kerning (this, user_data, + left_glyph, right_glyph, + klass->user_data.glyph_v_kerning); + } + + inline hb_bool_t get_glyph_extents (hb_codepoint_t glyph, + hb_glyph_extents_t *extents) + { + memset (extents, 0, sizeof (*extents)); + return klass->get.glyph_extents (this, user_data, + glyph, + extents, + klass->user_data.glyph_extents); + } + + inline hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int point_index, + hb_position_t *x, hb_position_t *y) + { + *x = *y = 0; + return klass->get.glyph_contour_point (this, user_data, + glyph, point_index, + x, y, + klass->user_data.glyph_contour_point); + } + + inline hb_bool_t get_glyph_name (hb_codepoint_t glyph, + char *name, unsigned int size) + { + if (size) *name = '\0'; + return klass->get.glyph_name (this, user_data, + glyph, + name, size, + klass->user_data.glyph_name); + } + + inline hb_bool_t get_glyph_from_name (const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph) + { + *glyph = 0; + if (len == -1) len = strlen (name); + return klass->get.glyph_from_name (this, user_data, + name, len, + glyph, + klass->user_data.glyph_from_name); + } + + + /* A bit higher-level, and with fallback */ + + inline void get_glyph_advance_for_direction (hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { + *x = get_glyph_h_advance (glyph); + *y = 0; + } else { + *x = 0; + *y = get_glyph_v_advance (glyph); + } + } + + /* Internal only */ + inline void guess_v_origin_minus_h_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + *x = get_glyph_h_advance (glyph) / 2; + + /* TODO use font_metics.ascent */ + *y = y_scale; + } + + inline void get_glyph_origin_for_direction (hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { + hb_bool_t ret = get_glyph_h_origin (glyph, x, y); + if (!ret && (ret = get_glyph_v_origin (glyph, x, y))) { + hb_position_t dx, dy; + guess_v_origin_minus_h_origin (glyph, &dx, &dy); + *x -= dx; *y -= dy; + } + } else { + hb_bool_t ret = get_glyph_v_origin (glyph, x, y); + if (!ret && (ret = get_glyph_h_origin (glyph, x, y))) { + hb_position_t dx, dy; + guess_v_origin_minus_h_origin (glyph, &dx, &dy); + *x += dx; *y += dy; + } + } + } + + inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); + + *x += origin_x; + *y += origin_y; + } + + inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_origin_for_direction (glyph, direction, &origin_x, &origin_y); + + *x -= origin_x; + *y -= origin_y; + } + + inline void get_glyph_kerning_for_direction (hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) { + *x = get_glyph_h_kerning (first_glyph, second_glyph); + *y = 0; + } else { + *x = 0; + *y = get_glyph_v_kerning (first_glyph, second_glyph); + } + } + + inline hb_bool_t get_glyph_extents_for_origin (hb_codepoint_t glyph, + hb_direction_t direction, + hb_glyph_extents_t *extents) + { + hb_bool_t ret = get_glyph_extents (glyph, extents); + + if (ret) + subtract_glyph_origin_for_direction (glyph, direction, &extents->x_bearing, &extents->y_bearing); + + return ret; + } + + inline hb_bool_t get_glyph_contour_point_for_origin (hb_codepoint_t glyph, unsigned int point_index, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) + { + hb_bool_t ret = get_glyph_contour_point (glyph, point_index, x, y); + + if (ret) + subtract_glyph_origin_for_direction (glyph, direction, x, y); + + return ret; + } + + /* Generates gidDDD if glyph has no name. */ + inline void + glyph_to_string (hb_codepoint_t glyph, + char *s, unsigned int size) + { + if (get_glyph_name (glyph, s, size)) return; + + snprintf (s, size, "gid%u", glyph); + } + + /* Parses gidDDD and uniUUUU strings automatically. */ + inline hb_bool_t + glyph_from_string (const char *s, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph) + { + if (get_glyph_from_name (s, len, glyph)) return true; + + if (len == -1) len = strlen (s); + + /* Straight glyph index. */ + if (hb_codepoint_parse (s, len, 10, glyph)) + return true; + + if (len > 3) + { + /* gidDDD syntax for glyph indices. */ + if (0 == strncmp (s, "gid", 3) && + hb_codepoint_parse (s + 3, len - 3, 10, glyph)) + return true; + + /* uniUUUU and other Unicode character indices. */ + hb_codepoint_t unichar; + if (0 == strncmp (s, "uni", 3) && + hb_codepoint_parse (s + 3, len - 3, 16, &unichar) && + get_glyph (unichar, 0, glyph)) + return true; + } + + return false; + } + + private: + inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / hb_face_get_upem (this->face); } +}; + +#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT +#undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS + + +#endif /* HB_FONT_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.cc new file mode 100644 index 00000000000..b59fdebaea7 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.cc @@ -0,0 +1,1008 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2012 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 + */ + +#include "hb-private.hh" + +#include "hb-ot-layout-private.hh" + +#include "hb-font-private.hh" +#include "hb-blob.h" +#include "hb-open-file-private.hh" +#include "hb-ot-head-table.hh" +#include "hb-ot-maxp-table.hh" + +#include "hb-cache-private.hh" + +#include <string.h> + + + +/* + * hb_font_funcs_t + */ + +static hb_bool_t +hb_font_get_glyph_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t unicode, + hb_codepoint_t variation_selector, + hb_codepoint_t *glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent->get_glyph (unicode, variation_selector, glyph); + + *glyph = 0; + return false; +} + +static hb_position_t +hb_font_get_glyph_h_advance_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent_scale_x_distance (font->parent->get_glyph_h_advance (glyph)); + + return font->x_scale; +} + +static hb_position_t +hb_font_get_glyph_v_advance_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent_scale_y_distance (font->parent->get_glyph_v_advance (glyph)); + + return font->y_scale; +} + +static hb_bool_t +hb_font_get_glyph_h_origin_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + hb_position_t *x, + hb_position_t *y, + void *user_data HB_UNUSED) +{ + if (font->parent) { + hb_bool_t ret = font->parent->get_glyph_h_origin (glyph, x, y); + if (ret) + font->parent_scale_position (x, y); + return ret; + } + + *x = *y = 0; + return false; +} + +static hb_bool_t +hb_font_get_glyph_v_origin_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + hb_position_t *x, + hb_position_t *y, + void *user_data HB_UNUSED) +{ + if (font->parent) { + hb_bool_t ret = font->parent->get_glyph_v_origin (glyph, x, y); + if (ret) + font->parent_scale_position (x, y); + return ret; + } + + *x = *y = 0; + return false; +} + +static hb_position_t +hb_font_get_glyph_h_kerning_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t left_glyph, + hb_codepoint_t right_glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent_scale_x_distance (font->parent->get_glyph_h_kerning (left_glyph, right_glyph)); + + return 0; +} + +static hb_position_t +hb_font_get_glyph_v_kerning_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t top_glyph, + hb_codepoint_t bottom_glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent_scale_y_distance (font->parent->get_glyph_v_kerning (top_glyph, bottom_glyph)); + + return 0; +} + +static hb_bool_t +hb_font_get_glyph_extents_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + hb_glyph_extents_t *extents, + void *user_data HB_UNUSED) +{ + if (font->parent) { + hb_bool_t ret = font->parent->get_glyph_extents (glyph, extents); + if (ret) { + font->parent_scale_position (&extents->x_bearing, &extents->y_bearing); + font->parent_scale_distance (&extents->width, &extents->height); + } + return ret; + } + + memset (extents, 0, sizeof (*extents)); + return false; +} + +static hb_bool_t +hb_font_get_glyph_contour_point_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + unsigned int point_index, + hb_position_t *x, + hb_position_t *y, + void *user_data HB_UNUSED) +{ + if (font->parent) { + hb_bool_t ret = font->parent->get_glyph_contour_point (glyph, point_index, x, y); + if (ret) + font->parent_scale_position (x, y); + return ret; + } + + *x = *y = 0; + return false; +} + +static hb_bool_t +hb_font_get_glyph_name_nil (hb_font_t *font, + void *font_data HB_UNUSED, + hb_codepoint_t glyph, + char *name, unsigned int size, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent->get_glyph_name (glyph, name, size); + + if (size) *name = '\0'; + return false; +} + +static hb_bool_t +hb_font_get_glyph_from_name_nil (hb_font_t *font, + void *font_data HB_UNUSED, + const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph, + void *user_data HB_UNUSED) +{ + if (font->parent) + return font->parent->get_glyph_from_name (name, len, glyph); + + *glyph = 0; + return false; +} + + +static const hb_font_funcs_t _hb_font_funcs_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + { +#define HB_FONT_FUNC_IMPLEMENT(name) hb_font_get_##name##_nil, + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + } +}; + + +hb_font_funcs_t * +hb_font_funcs_create (void) +{ + hb_font_funcs_t *ffuncs; + + if (!(ffuncs = hb_object_create<hb_font_funcs_t> ())) + return hb_font_funcs_get_empty (); + + ffuncs->get = _hb_font_funcs_nil.get; + + return ffuncs; +} + +hb_font_funcs_t * +hb_font_funcs_get_empty (void) +{ + return const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil); +} + +hb_font_funcs_t * +hb_font_funcs_reference (hb_font_funcs_t *ffuncs) +{ + return hb_object_reference (ffuncs); +} + +void +hb_font_funcs_destroy (hb_font_funcs_t *ffuncs) +{ + if (!hb_object_destroy (ffuncs)) return; + +#define HB_FONT_FUNC_IMPLEMENT(name) if (ffuncs->destroy.name) \ + ffuncs->destroy.name (ffuncs->user_data.name); + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + + free (ffuncs); +} + +hb_bool_t +hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (ffuncs, key, data, destroy, replace); +} + +void * +hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (ffuncs, key); +} + + +void +hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs) +{ + if (hb_object_is_inert (ffuncs)) + return; + + ffuncs->immutable = true; +} + +hb_bool_t +hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs) +{ + return ffuncs->immutable; +} + + +#define HB_FONT_FUNC_IMPLEMENT(name) \ + \ +void \ +hb_font_funcs_set_##name##_func (hb_font_funcs_t *ffuncs, \ + hb_font_get_##name##_func_t func, \ + void *user_data, \ + hb_destroy_func_t destroy) \ +{ \ + if (ffuncs->immutable) { \ + if (destroy) \ + destroy (user_data); \ + return; \ + } \ + \ + if (ffuncs->destroy.name) \ + ffuncs->destroy.name (ffuncs->user_data.name); \ + \ + if (func) { \ + ffuncs->get.name = func; \ + ffuncs->user_data.name = user_data; \ + ffuncs->destroy.name = destroy; \ + } else { \ + ffuncs->get.name = hb_font_get_##name##_nil; \ + ffuncs->user_data.name = NULL; \ + ffuncs->destroy.name = NULL; \ + } \ +} + +HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + + +/* Public getters */ + +hb_bool_t +hb_font_get_glyph (hb_font_t *font, + hb_codepoint_t unicode, hb_codepoint_t variation_selector, + hb_codepoint_t *glyph) +{ + return font->get_glyph (unicode, variation_selector, glyph); +} + +hb_position_t +hb_font_get_glyph_h_advance (hb_font_t *font, + hb_codepoint_t glyph) +{ + return font->get_glyph_h_advance (glyph); +} + +hb_position_t +hb_font_get_glyph_v_advance (hb_font_t *font, + hb_codepoint_t glyph) +{ + return font->get_glyph_v_advance (glyph); +} + +hb_bool_t +hb_font_get_glyph_h_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_h_origin (glyph, x, y); +} + +hb_bool_t +hb_font_get_glyph_v_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_v_origin (glyph, x, y); +} + +hb_position_t +hb_font_get_glyph_h_kerning (hb_font_t *font, + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) +{ + return font->get_glyph_h_kerning (left_glyph, right_glyph); +} + +hb_position_t +hb_font_get_glyph_v_kerning (hb_font_t *font, + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph) +{ + return font->get_glyph_v_kerning (left_glyph, right_glyph); +} + +hb_bool_t +hb_font_get_glyph_extents (hb_font_t *font, + hb_codepoint_t glyph, + hb_glyph_extents_t *extents) +{ + return font->get_glyph_extents (glyph, extents); +} + +hb_bool_t +hb_font_get_glyph_contour_point (hb_font_t *font, + hb_codepoint_t glyph, unsigned int point_index, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_contour_point (glyph, point_index, x, y); +} + +hb_bool_t +hb_font_get_glyph_name (hb_font_t *font, + hb_codepoint_t glyph, + char *name, unsigned int size) +{ + return font->get_glyph_name (glyph, name, size); +} + +hb_bool_t +hb_font_get_glyph_from_name (hb_font_t *font, + const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph) +{ + return font->get_glyph_from_name (name, len, glyph); +} + + +/* A bit higher-level, and with fallback */ + +void +hb_font_get_glyph_advance_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_advance_for_direction (glyph, direction, x, y); +} + +void +hb_font_get_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_origin_for_direction (glyph, direction, x, y); +} + +void +hb_font_add_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->add_glyph_origin_for_direction (glyph, direction, x, y); +} + +void +hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->subtract_glyph_origin_for_direction (glyph, direction, x, y); +} + +void +hb_font_get_glyph_kerning_for_direction (hb_font_t *font, + hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_kerning_for_direction (first_glyph, second_glyph, direction, x, y); +} + +hb_bool_t +hb_font_get_glyph_extents_for_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_glyph_extents_t *extents) +{ + return font->get_glyph_extents_for_origin (glyph, direction, extents); +} + +hb_bool_t +hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, + hb_codepoint_t glyph, unsigned int point_index, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y) +{ + return font->get_glyph_contour_point_for_origin (glyph, point_index, direction, x, y); +} + +/* Generates gidDDD if glyph has no name. */ +void +hb_font_glyph_to_string (hb_font_t *font, + hb_codepoint_t glyph, + char *s, unsigned int size) +{ + font->glyph_to_string (glyph, s, size); +} + +/* Parses gidDDD and uniUUUU strings automatically. */ +hb_bool_t +hb_font_glyph_from_string (hb_font_t *font, + const char *s, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph) +{ + return font->glyph_from_string (s, len, glyph); +} + + +/* + * hb_face_t + */ + +static const hb_face_t _hb_face_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + NULL, /* reference_table_func */ + NULL, /* user_data */ + NULL, /* destroy */ + + 0, /* index */ + 1000, /* upem */ + 0, /* num_glyphs */ + + { +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + }, + + NULL, /* shape_plans */ +}; + + +hb_face_t * +hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, + void *user_data, + hb_destroy_func_t destroy) +{ + hb_face_t *face; + + if (!reference_table_func || !(face = hb_object_create<hb_face_t> ())) { + if (destroy) + destroy (user_data); + return hb_face_get_empty (); + } + + face->reference_table_func = reference_table_func; + face->user_data = user_data; + face->destroy = destroy; + + face->upem = 0; + face->num_glyphs = (unsigned int) -1; + + return face; +} + + +typedef struct hb_face_for_data_closure_t { + hb_blob_t *blob; + unsigned int index; +} hb_face_for_data_closure_t; + +static hb_face_for_data_closure_t * +_hb_face_for_data_closure_create (hb_blob_t *blob, unsigned int index) +{ + hb_face_for_data_closure_t *closure; + + closure = (hb_face_for_data_closure_t *) malloc (sizeof (hb_face_for_data_closure_t)); + if (unlikely (!closure)) + return NULL; + + closure->blob = blob; + closure->index = index; + + return closure; +} + +static void +_hb_face_for_data_closure_destroy (hb_face_for_data_closure_t *closure) +{ + hb_blob_destroy (closure->blob); + free (closure); +} + +static hb_blob_t * +_hb_face_for_data_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) +{ + hb_face_for_data_closure_t *data = (hb_face_for_data_closure_t *) user_data; + + if (tag == HB_TAG_NONE) + return hb_blob_reference (data->blob); + + const OT::OpenTypeFontFile &ot_file = *OT::Sanitizer<OT::OpenTypeFontFile>::lock_instance (data->blob); + const OT::OpenTypeFontFace &ot_face = ot_file.get_face (data->index); + + const OT::OpenTypeTable &table = ot_face.get_table_by_tag (tag); + + hb_blob_t *blob = hb_blob_create_sub_blob (data->blob, table.offset, table.length); + + return blob; +} + +hb_face_t * +hb_face_create (hb_blob_t *blob, + unsigned int index) +{ + hb_face_t *face; + + if (unlikely (!blob || !hb_blob_get_length (blob))) + return hb_face_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); + + if (unlikely (!closure)) + return hb_face_get_empty (); + + face = hb_face_create_for_tables (_hb_face_for_data_reference_table, + closure, + (hb_destroy_func_t) _hb_face_for_data_closure_destroy); + + hb_face_set_index (face, index); + + return face; +} + +hb_face_t * +hb_face_get_empty (void) +{ + return const_cast<hb_face_t *> (&_hb_face_nil); +} + + +hb_face_t * +hb_face_reference (hb_face_t *face) +{ + return hb_object_reference (face); +} + +void +hb_face_destroy (hb_face_t *face) +{ + if (!hb_object_destroy (face)) return; + + for (hb_face_t::plan_node_t *node = face->shape_plans; node; ) + { + hb_face_t::plan_node_t *next = node->next; + hb_shape_plan_destroy (node->shape_plan); + free (node); + node = next; + } + +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, face); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + + if (face->destroy) + face->destroy (face->user_data); + + free (face); +} + +hb_bool_t +hb_face_set_user_data (hb_face_t *face, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (face, key, data, destroy, replace); +} + +void * +hb_face_get_user_data (hb_face_t *face, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (face, key); +} + +void +hb_face_make_immutable (hb_face_t *face) +{ + if (hb_object_is_inert (face)) + return; + + face->immutable = true; +} + +hb_bool_t +hb_face_is_immutable (hb_face_t *face) +{ + return face->immutable; +} + + +hb_blob_t * +hb_face_reference_table (hb_face_t *face, + hb_tag_t tag) +{ + return face->reference_table (tag); +} + +hb_blob_t * +hb_face_reference_blob (hb_face_t *face) +{ + return face->reference_table (HB_TAG_NONE); +} + +void +hb_face_set_index (hb_face_t *face, + unsigned int index) +{ + if (hb_object_is_inert (face)) + return; + + face->index = index; +} + +unsigned int +hb_face_get_index (hb_face_t *face) +{ + return face->index; +} + +void +hb_face_set_upem (hb_face_t *face, + unsigned int upem) +{ + if (hb_object_is_inert (face)) + return; + + face->upem = upem; +} + +unsigned int +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 = OT::Sanitizer<OT::head>::lock_instance (head_blob); + upem = head_table->get_upem (); + hb_blob_destroy (head_blob); +} + +void +hb_face_set_glyph_count (hb_face_t *face, + unsigned int glyph_count) +{ + if (hb_object_is_inert (face)) + return; + + face->num_glyphs = glyph_count; +} + +unsigned int +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 = OT::Sanitizer<OT::maxp>::lock_instance (maxp_blob); + num_glyphs = maxp_table->get_num_glyphs (); + hb_blob_destroy (maxp_blob); +} + + +/* + * hb_font_t + */ + +hb_font_t * +hb_font_create (hb_face_t *face) +{ + hb_font_t *font; + + if (unlikely (!face)) + face = hb_face_get_empty (); + if (unlikely (hb_object_is_inert (face))) + return hb_font_get_empty (); + if (!(font = hb_object_create<hb_font_t> ())) + return hb_font_get_empty (); + + hb_face_make_immutable (face); + font->face = hb_face_reference (face); + font->klass = hb_font_funcs_get_empty (); + + return font; +} + +hb_font_t * +hb_font_create_sub_font (hb_font_t *parent) +{ + if (unlikely (!parent)) + return hb_font_get_empty (); + + hb_font_t *font = hb_font_create (parent->face); + + if (unlikely (hb_object_is_inert (font))) + return font; + + hb_font_make_immutable (parent); + font->parent = hb_font_reference (parent); + + font->x_scale = parent->x_scale; + font->y_scale = parent->y_scale; + font->x_ppem = parent->x_ppem; + font->y_ppem = parent->y_ppem; + + return font; +} + +hb_font_t * +hb_font_get_empty (void) +{ + static const hb_font_t _hb_font_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + NULL, /* parent */ + const_cast<hb_face_t *> (&_hb_face_nil), + + 0, /* x_scale */ + 0, /* y_scale */ + + 0, /* x_ppem */ + 0, /* y_ppem */ + + const_cast<hb_font_funcs_t *> (&_hb_font_funcs_nil), /* klass */ + NULL, /* user_data */ + NULL, /* destroy */ + + { +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } + }; + + return const_cast<hb_font_t *> (&_hb_font_nil); +} + +hb_font_t * +hb_font_reference (hb_font_t *font) +{ + return hb_object_reference (font); +} + +void +hb_font_destroy (hb_font_t *font) +{ + if (!hb_object_destroy (font)) return; + +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, font); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + + if (font->destroy) + font->destroy (font->user_data); + + hb_font_destroy (font->parent); + hb_face_destroy (font->face); + hb_font_funcs_destroy (font->klass); + + free (font); +} + +hb_bool_t +hb_font_set_user_data (hb_font_t *font, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (font, key, data, destroy, replace); +} + +void * +hb_font_get_user_data (hb_font_t *font, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (font, key); +} + +void +hb_font_make_immutable (hb_font_t *font) +{ + if (hb_object_is_inert (font)) + return; + + font->immutable = true; +} + +hb_bool_t +hb_font_is_immutable (hb_font_t *font) +{ + return font->immutable; +} + +hb_font_t * +hb_font_get_parent (hb_font_t *font) +{ + return font->parent; +} + +hb_face_t * +hb_font_get_face (hb_font_t *font) +{ + return font->face; +} + + +void +hb_font_set_funcs (hb_font_t *font, + hb_font_funcs_t *klass, + void *user_data, + hb_destroy_func_t destroy) +{ + if (font->immutable) { + if (destroy) + destroy (user_data); + return; + } + + if (font->destroy) + font->destroy (font->user_data); + + if (!klass) + klass = hb_font_funcs_get_empty (); + + hb_font_funcs_reference (klass); + hb_font_funcs_destroy (font->klass); + font->klass = klass; + font->user_data = user_data; + font->destroy = destroy; +} + +void +hb_font_set_funcs_data (hb_font_t *font, + void *user_data, + hb_destroy_func_t destroy) +{ + /* Destroy user_data? */ + if (font->immutable) { + if (destroy) + destroy (user_data); + return; + } + + if (font->destroy) + font->destroy (font->user_data); + + font->user_data = user_data; + font->destroy = destroy; +} + + +void +hb_font_set_scale (hb_font_t *font, + int x_scale, + int y_scale) +{ + if (font->immutable) + return; + + font->x_scale = x_scale; + font->y_scale = y_scale; +} + +void +hb_font_get_scale (hb_font_t *font, + int *x_scale, + int *y_scale) +{ + if (x_scale) *x_scale = font->x_scale; + if (y_scale) *y_scale = font->y_scale; +} + +void +hb_font_set_ppem (hb_font_t *font, + unsigned int x_ppem, + unsigned int y_ppem) +{ + if (font->immutable) + return; + + font->x_ppem = x_ppem; + font->y_ppem = y_ppem; +} + +void +hb_font_get_ppem (hb_font_t *font, + unsigned int *x_ppem, + unsigned int *y_ppem) +{ + if (x_ppem) *x_ppem = font->x_ppem; + if (y_ppem) *y_ppem = font->y_ppem; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.h new file mode 100644 index 00000000000..88d489551e8 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-font.h @@ -0,0 +1,454 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_FONT_H +#define HB_FONT_H + +#include "hb-common.h" +#include "hb-blob.h" + +HB_BEGIN_DECLS + + +typedef struct hb_face_t hb_face_t; +typedef struct hb_font_t hb_font_t; + +/* + * hb_face_t + */ + +hb_face_t * +hb_face_create (hb_blob_t *blob, + unsigned int index); + +typedef hb_blob_t * (*hb_reference_table_func_t) (hb_face_t *face, hb_tag_t tag, void *user_data); + +/* calls destroy() when not needing user_data anymore */ +hb_face_t * +hb_face_create_for_tables (hb_reference_table_func_t reference_table_func, + void *user_data, + hb_destroy_func_t destroy); + +hb_face_t * +hb_face_get_empty (void); + +hb_face_t * +hb_face_reference (hb_face_t *face); + +void +hb_face_destroy (hb_face_t *face); + +hb_bool_t +hb_face_set_user_data (hb_face_t *face, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + +void * +hb_face_get_user_data (hb_face_t *face, + hb_user_data_key_t *key); + +void +hb_face_make_immutable (hb_face_t *face); + +hb_bool_t +hb_face_is_immutable (hb_face_t *face); + + +hb_blob_t * +hb_face_reference_table (hb_face_t *face, + hb_tag_t tag); + +hb_blob_t * +hb_face_reference_blob (hb_face_t *face); + +void +hb_face_set_index (hb_face_t *face, + unsigned int index); + +unsigned int +hb_face_get_index (hb_face_t *face); + +void +hb_face_set_upem (hb_face_t *face, + unsigned int upem); + +unsigned int +hb_face_get_upem (hb_face_t *face); + +void +hb_face_set_glyph_count (hb_face_t *face, + unsigned int glyph_count); + +unsigned int +hb_face_get_glyph_count (hb_face_t *face); + + +/* + * hb_font_funcs_t + */ + +typedef struct hb_font_funcs_t hb_font_funcs_t; + +hb_font_funcs_t * +hb_font_funcs_create (void); + +hb_font_funcs_t * +hb_font_funcs_get_empty (void); + +hb_font_funcs_t * +hb_font_funcs_reference (hb_font_funcs_t *ffuncs); + +void +hb_font_funcs_destroy (hb_font_funcs_t *ffuncs); + +hb_bool_t +hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + +void * +hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs, + hb_user_data_key_t *key); + + +void +hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs); + +hb_bool_t +hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs); + + +/* glyph extents */ + +typedef struct hb_glyph_extents_t +{ + hb_position_t x_bearing; + hb_position_t y_bearing; + hb_position_t width; + hb_position_t height; +} hb_glyph_extents_t; + + +/* func types */ + +typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t unicode, hb_codepoint_t variation_selector, + hb_codepoint_t *glyph, + void *user_data); + + +typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, + void *user_data); +typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t; +typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t; + +typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y, + void *user_data); +typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t; +typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t; + +typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, + void *user_data); +typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t; +typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t; + + +typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, + hb_glyph_extents_t *extents, + void *user_data); +typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, unsigned int point_index, + hb_position_t *x, hb_position_t *y, + void *user_data); + + +typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data, + hb_codepoint_t glyph, + char *name, unsigned int size, + void *user_data); +typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data, + const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph, + void *user_data); + + +/* func setters */ + +void +hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_func_t glyph_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_h_advance_func_t func, + void *user_data, hb_destroy_func_t destroy); +void +hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_v_advance_func_t func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_h_origin_func_t func, + void *user_data, hb_destroy_func_t destroy); +void +hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_v_origin_func_t func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_h_kerning_func_t func, + void *user_data, hb_destroy_func_t destroy); +void +hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_v_kerning_func_t func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_extents_func_t func, + void *user_data, hb_destroy_func_t destroy); +void +hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_contour_point_func_t func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_name_func_t glyph_func, + void *user_data, hb_destroy_func_t destroy); +void +hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs, + hb_font_get_glyph_from_name_func_t glyph_func, + void *user_data, hb_destroy_func_t destroy); + + +/* func dispatch */ + +hb_bool_t +hb_font_get_glyph (hb_font_t *font, + hb_codepoint_t unicode, hb_codepoint_t variation_selector, + hb_codepoint_t *glyph); + +hb_position_t +hb_font_get_glyph_h_advance (hb_font_t *font, + hb_codepoint_t glyph); +hb_position_t +hb_font_get_glyph_v_advance (hb_font_t *font, + hb_codepoint_t glyph); + +hb_bool_t +hb_font_get_glyph_h_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y); +hb_bool_t +hb_font_get_glyph_v_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y); + +hb_position_t +hb_font_get_glyph_h_kerning (hb_font_t *font, + hb_codepoint_t left_glyph, hb_codepoint_t right_glyph); +hb_position_t +hb_font_get_glyph_v_kerning (hb_font_t *font, + hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph); + +hb_bool_t +hb_font_get_glyph_extents (hb_font_t *font, + hb_codepoint_t glyph, + hb_glyph_extents_t *extents); + +hb_bool_t +hb_font_get_glyph_contour_point (hb_font_t *font, + hb_codepoint_t glyph, unsigned int point_index, + hb_position_t *x, hb_position_t *y); + +hb_bool_t +hb_font_get_glyph_name (hb_font_t *font, + hb_codepoint_t glyph, + char *name, unsigned int size); +hb_bool_t +hb_font_get_glyph_from_name (hb_font_t *font, + const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph); + + +/* high-level funcs, with fallback */ + +void +hb_font_get_glyph_advance_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); +void +hb_font_get_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); +void +hb_font_add_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); +void +hb_font_subtract_glyph_origin_for_direction (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); + +void +hb_font_get_glyph_kerning_for_direction (hb_font_t *font, + hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); + +hb_bool_t +hb_font_get_glyph_extents_for_origin (hb_font_t *font, + hb_codepoint_t glyph, + hb_direction_t direction, + hb_glyph_extents_t *extents); + +hb_bool_t +hb_font_get_glyph_contour_point_for_origin (hb_font_t *font, + hb_codepoint_t glyph, unsigned int point_index, + hb_direction_t direction, + hb_position_t *x, hb_position_t *y); + +/* Generates gidDDD if glyph has no name. */ +void +hb_font_glyph_to_string (hb_font_t *font, + hb_codepoint_t glyph, + char *s, unsigned int size); +/* Parses gidDDD and uniUUUU strings automatically. */ +hb_bool_t +hb_font_glyph_from_string (hb_font_t *font, + const char *s, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph); + + +/* + * hb_font_t + */ + +/* Fonts are very light-weight objects */ + +hb_font_t * +hb_font_create (hb_face_t *face); + +hb_font_t * +hb_font_create_sub_font (hb_font_t *parent); + +hb_font_t * +hb_font_get_empty (void); + +hb_font_t * +hb_font_reference (hb_font_t *font); + +void +hb_font_destroy (hb_font_t *font); + +hb_bool_t +hb_font_set_user_data (hb_font_t *font, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + +void * +hb_font_get_user_data (hb_font_t *font, + hb_user_data_key_t *key); + +void +hb_font_make_immutable (hb_font_t *font); + +hb_bool_t +hb_font_is_immutable (hb_font_t *font); + +hb_font_t * +hb_font_get_parent (hb_font_t *font); + +hb_face_t * +hb_font_get_face (hb_font_t *font); + + +void +hb_font_set_funcs (hb_font_t *font, + hb_font_funcs_t *klass, + void *font_data, + hb_destroy_func_t destroy); + +/* Be *very* careful with this function! */ +void +hb_font_set_funcs_data (hb_font_t *font, + void *font_data, + hb_destroy_func_t destroy); + + +void +hb_font_set_scale (hb_font_t *font, + int x_scale, + int y_scale); + +void +hb_font_get_scale (hb_font_t *font, + int *x_scale, + int *y_scale); + +/* + * A zero value means "no hinting in that direction" + */ +void +hb_font_set_ppem (hb_font_t *font, + unsigned int x_ppem, + unsigned int y_ppem); + +void +hb_font_get_ppem (hb_font_t *font, + unsigned int *x_ppem, + unsigned int *y_ppem); + + +HB_END_DECLS + +#endif /* HB_FONT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.cc new file mode 100644 index 00000000000..6198185e9e4 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.cc @@ -0,0 +1,493 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2009 Keith Stribley + * + * 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 + */ + +#include "hb-private.hh" + +#include "hb-ft.h" + +#include "hb-font-private.hh" + +#include FT_ADVANCES_H +#include FT_TRUETYPE_TABLES_H + + + +#ifndef HB_DEBUG_FT +#define HB_DEBUG_FT (HB_DEBUG+0) +#endif + + +/* TODO: + * + * In general, this file does a fine job of what it's supposed to do. + * There are, however, things that need more work: + * + * - We don't handle any load_flags. That definitely has API implications. :( + * I believe hb_ft_font_create() should take load_flags input. + * In particular, FT_Get_Advance() without the NO_HINTING flag seems to be + * buggy. + * + * - We don't handle / allow for emboldening / obliqueing. + * + * - Rounding, etc? + * + * - In the future, we should add constructors to create fonts in font space. + * + * - I believe transforms are not correctly implemented. FreeType does not + * provide any API to get to the transform/delta set on the face. :( + * + * - Always use FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH? + * + * - FT_Load_Glyph() is exteremely costly. Do something about it? + */ + + +static hb_bool_t +hb_ft_get_glyph (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t unicode, + hb_codepoint_t variation_selector, + hb_codepoint_t *glyph, + void *user_data HB_UNUSED) + +{ + FT_Face ft_face = (FT_Face) font_data; + +#ifdef HAVE_FT_FACE_GETCHARVARIANTINDEX + if (unlikely (variation_selector)) { + *glyph = FT_Face_GetCharVariantIndex (ft_face, unicode, variation_selector); + if (*glyph) + return true; + } +#endif + + *glyph = FT_Get_Char_Index (ft_face, unicode); + return *glyph != 0; +} + +static hb_position_t +hb_ft_get_glyph_h_advance (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + int load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING; + FT_Fixed v; + + if (unlikely (FT_Get_Advance (ft_face, glyph, load_flags, &v))) + return 0; + + return v >> 10; +} + +static hb_position_t +hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + int load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING | FT_LOAD_VERTICAL_LAYOUT; + FT_Fixed v; + + if (unlikely (FT_Get_Advance (ft_face, glyph, load_flags, &v))) + return 0; + + /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates + * have a Y growing upward. Hence the extra negation. */ + return -v >> 10; +} + +static hb_bool_t +hb_ft_get_glyph_h_origin (hb_font_t *font HB_UNUSED, + void *font_data HB_UNUSED, + hb_codepoint_t glyph HB_UNUSED, + hb_position_t *x HB_UNUSED, + hb_position_t *y HB_UNUSED, + void *user_data HB_UNUSED) +{ + /* We always work in the horizontal coordinates. */ + return true; +} + +static hb_bool_t +hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + hb_position_t *x, + hb_position_t *y, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + int load_flags = FT_LOAD_DEFAULT; + + if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) + return false; + + /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates + * have a Y growing upward. Hence the extra negation. */ + *x = ft_face->glyph->metrics.horiBearingX - ft_face->glyph->metrics.vertBearingX; + *y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY); + + return true; +} + +static hb_position_t +hb_ft_get_glyph_h_kerning (hb_font_t *font, + void *font_data, + hb_codepoint_t left_glyph, + hb_codepoint_t right_glyph, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + FT_Vector kerningv; + + FT_Kerning_Mode mode = font->x_ppem ? FT_KERNING_DEFAULT : FT_KERNING_UNFITTED; + if (FT_Get_Kerning (ft_face, left_glyph, right_glyph, mode, &kerningv)) + return 0; + + return kerningv.x; +} + +static hb_position_t +hb_ft_get_glyph_v_kerning (hb_font_t *font HB_UNUSED, + void *font_data HB_UNUSED, + hb_codepoint_t top_glyph HB_UNUSED, + hb_codepoint_t bottom_glyph HB_UNUSED, + void *user_data HB_UNUSED) +{ + /* FreeType API doesn't support vertical kerning */ + return 0; +} + +static hb_bool_t +hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + hb_glyph_extents_t *extents, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + int load_flags = FT_LOAD_DEFAULT; + + if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) + return false; + + extents->x_bearing = ft_face->glyph->metrics.horiBearingX; + extents->y_bearing = ft_face->glyph->metrics.horiBearingY; + extents->width = ft_face->glyph->metrics.width; + extents->height = -ft_face->glyph->metrics.height; + return true; +} + +static hb_bool_t +hb_ft_get_glyph_contour_point (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + unsigned int point_index, + hb_position_t *x, + hb_position_t *y, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + int load_flags = FT_LOAD_DEFAULT; + + if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags))) + return false; + + if (unlikely (ft_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)) + return false; + + if (unlikely (point_index >= (unsigned int) ft_face->glyph->outline.n_points)) + return false; + + *x = ft_face->glyph->outline.points[point_index].x; + *y = ft_face->glyph->outline.points[point_index].y; + + return true; +} + +static hb_bool_t +hb_ft_get_glyph_name (hb_font_t *font HB_UNUSED, + void *font_data, + hb_codepoint_t glyph, + char *name, unsigned int size, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + + hb_bool_t ret = !FT_Get_Glyph_Name (ft_face, glyph, name, size); + if (!ret || (size && !*name)) + snprintf (name, size, "gid%u", glyph); + + return ret; +} + +static hb_bool_t +hb_ft_get_glyph_from_name (hb_font_t *font HB_UNUSED, + void *font_data, + const char *name, int len, /* -1 means nul-terminated */ + hb_codepoint_t *glyph, + void *user_data HB_UNUSED) +{ + FT_Face ft_face = (FT_Face) font_data; + + if (len < 0) + *glyph = FT_Get_Name_Index (ft_face, (FT_String *) name); + else { + /* Make a nul-terminated version. */ + char buf[128]; + len = MIN (len, (int) sizeof (buf) - 1); + strncpy (buf, name, len); + buf[len] = '\0'; + *glyph = FT_Get_Name_Index (ft_face, buf); + } + + return *glyph != 0; +} + + +static hb_font_funcs_t * +_hb_ft_get_font_funcs (void) +{ + static const hb_font_funcs_t ft_ffuncs = { + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + { +#define HB_FONT_FUNC_IMPLEMENT(name) hb_ft_get_##name, + HB_FONT_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_FONT_FUNC_IMPLEMENT + } + }; + + return const_cast<hb_font_funcs_t *> (&ft_ffuncs); +} + + +static hb_blob_t * +reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) +{ + FT_Face ft_face = (FT_Face) user_data; + FT_Byte *buffer; + FT_ULong length = 0; + FT_Error error; + + /* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */ + + error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length); + if (error) + return NULL; + + buffer = (FT_Byte *) malloc (length); + if (buffer == NULL) + return NULL; + + error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length); + if (error) + return NULL; + + return hb_blob_create ((const char *) buffer, length, + HB_MEMORY_MODE_WRITABLE, + buffer, free); +} + + +hb_face_t * +hb_ft_face_create (FT_Face ft_face, + hb_destroy_func_t destroy) +{ + hb_face_t *face; + + if (ft_face->stream->read == NULL) { + hb_blob_t *blob; + + blob = hb_blob_create ((const char *) ft_face->stream->base, + (unsigned int) ft_face->stream->size, + /* TODO: We assume that it's mmap()'ed, but FreeType code + * suggests that there are cases we reach here but font is + * not mmapped. For example, when mmap() fails. No idea + * how to deal with it better here. */ + HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE, + ft_face, destroy); + face = hb_face_create (blob, ft_face->face_index); + hb_blob_destroy (blob); + } else { + face = hb_face_create_for_tables (reference_table, ft_face, destroy); + } + + hb_face_set_index (face, ft_face->face_index); + hb_face_set_upem (face, ft_face->units_per_EM); + + return face; +} + +static void +hb_ft_face_finalize (FT_Face ft_face) +{ + hb_face_destroy ((hb_face_t *) ft_face->generic.data); +} + +hb_face_t * +hb_ft_face_create_cached (FT_Face ft_face) +{ + if (unlikely (!ft_face->generic.data || ft_face->generic.finalizer != (FT_Generic_Finalizer) hb_ft_face_finalize)) + { + if (ft_face->generic.finalizer) + ft_face->generic.finalizer (ft_face); + + ft_face->generic.data = hb_ft_face_create (ft_face, NULL); + ft_face->generic.finalizer = (FT_Generic_Finalizer) hb_ft_face_finalize; + } + + return hb_face_reference ((hb_face_t *) ft_face->generic.data); +} + +static void +_do_nothing (void) +{ +} + + +hb_font_t * +hb_ft_font_create (FT_Face ft_face, + hb_destroy_func_t destroy) +{ + hb_font_t *font; + hb_face_t *face; + + face = hb_ft_face_create (ft_face, destroy); + font = hb_font_create (face); + hb_face_destroy (face); + hb_font_set_funcs (font, + _hb_ft_get_font_funcs (), + ft_face, (hb_destroy_func_t) _do_nothing); + hb_font_set_scale (font, + ((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM) >> 16, + ((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM) >> 16); + hb_font_set_ppem (font, + ft_face->size->metrics.x_ppem, + ft_face->size->metrics.y_ppem); + + return font; +} + + +/* Thread-safe, lock-free, FT_Library */ + +static FT_Library ft_library; + +static +void free_ft_library (void) +{ + FT_Done_FreeType (ft_library); +} + +static FT_Library +get_ft_library (void) +{ +retry: + FT_Library library = (FT_Library) hb_atomic_ptr_get (&ft_library); + + if (unlikely (!library)) + { + /* Not found; allocate one. */ + if (FT_Init_FreeType (&library)) + return NULL; + + if (!hb_atomic_ptr_cmpexch (&ft_library, NULL, library)) { + FT_Done_FreeType (library); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_ft_library); /* First person registers atexit() callback. */ +#endif + } + + return library; +} + +static void +_release_blob (FT_Face ft_face) +{ + hb_blob_destroy ((hb_blob_t *) ft_face->generic.data); +} + +void +hb_ft_font_set_funcs (hb_font_t *font) +{ + hb_blob_t *blob = hb_face_reference_blob (font->face); + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (blob, &blob_length); + if (unlikely (!blob_length)) + DEBUG_MSG (FT, font, "Font face has empty blob"); + + FT_Face ft_face = NULL; + FT_Error err = FT_New_Memory_Face (get_ft_library (), + (const FT_Byte *) blob_data, + blob_length, + hb_face_get_index (font->face), + &ft_face); + + if (unlikely (err)) { + hb_blob_destroy (blob); + DEBUG_MSG (FT, font, "Font face FT_New_Memory_Face() failed"); + return; + } + + FT_Select_Charmap (ft_face, FT_ENCODING_UNICODE); + + assert (font->y_scale >= 0); + FT_Set_Char_Size (ft_face, + font->x_scale, font->y_scale, + 0, 0); +#if 0 + font->x_ppem * 72 * 64 / font->x_scale, + font->y_ppem * 72 * 64 / font->y_scale); +#endif + + ft_face->generic.data = blob; + ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob; + + hb_font_set_funcs (font, + _hb_ft_get_font_funcs (), + ft_face, + (hb_destroy_func_t) FT_Done_Face); +} + +FT_Face +hb_ft_font_get_face (hb_font_t *font) +{ + if (font->destroy == (hb_destroy_func_t) FT_Done_Face || + font->destroy == (hb_destroy_func_t) _do_nothing) + return (FT_Face) font->user_data; + + return NULL; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.h new file mode 100644 index 00000000000..696251e143f --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ft.h @@ -0,0 +1,62 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_FT_H +#define HB_FT_H + +#include "hb.h" + +#include <ft2build.h> +#include FT_FREETYPE_H + +HB_BEGIN_DECLS + +/* Note: FreeType is not thread-safe. Hence, these functions are not either. */ + +hb_face_t * +hb_ft_face_create (FT_Face ft_face, + hb_destroy_func_t destroy); + +hb_face_t * +hb_ft_face_create_cached (FT_Face ft_face); + +hb_font_t * +hb_ft_font_create (FT_Face ft_face, + hb_destroy_func_t destroy); + + + +/* Makes an hb_font_t use FreeType internally to implement font functions. */ +void +hb_ft_font_set_funcs (hb_font_t *font); + +FT_Face +hb_ft_font_get_face (hb_font_t *font); + + +HB_END_DECLS + +#endif /* HB_FT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.cc new file mode 100644 index 00000000000..676e6601628 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.cc @@ -0,0 +1,384 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" + +#include "hb-glib.h" + +#include "hb-unicode-private.hh" + + +#if !GLIB_CHECK_VERSION(2,29,14) +static const hb_script_t +glib_script_to_script[] = +{ + HB_SCRIPT_COMMON, + HB_SCRIPT_INHERITED, + HB_SCRIPT_ARABIC, + HB_SCRIPT_ARMENIAN, + HB_SCRIPT_BENGALI, + HB_SCRIPT_BOPOMOFO, + HB_SCRIPT_CHEROKEE, + HB_SCRIPT_COPTIC, + HB_SCRIPT_CYRILLIC, + HB_SCRIPT_DESERET, + HB_SCRIPT_DEVANAGARI, + HB_SCRIPT_ETHIOPIC, + HB_SCRIPT_GEORGIAN, + HB_SCRIPT_GOTHIC, + HB_SCRIPT_GREEK, + HB_SCRIPT_GUJARATI, + HB_SCRIPT_GURMUKHI, + HB_SCRIPT_HAN, + HB_SCRIPT_HANGUL, + HB_SCRIPT_HEBREW, + HB_SCRIPT_HIRAGANA, + HB_SCRIPT_KANNADA, + HB_SCRIPT_KATAKANA, + HB_SCRIPT_KHMER, + HB_SCRIPT_LAO, + HB_SCRIPT_LATIN, + HB_SCRIPT_MALAYALAM, + HB_SCRIPT_MONGOLIAN, + HB_SCRIPT_MYANMAR, + HB_SCRIPT_OGHAM, + HB_SCRIPT_OLD_ITALIC, + HB_SCRIPT_ORIYA, + HB_SCRIPT_RUNIC, + HB_SCRIPT_SINHALA, + HB_SCRIPT_SYRIAC, + HB_SCRIPT_TAMIL, + HB_SCRIPT_TELUGU, + HB_SCRIPT_THAANA, + HB_SCRIPT_THAI, + HB_SCRIPT_TIBETAN, + HB_SCRIPT_CANADIAN_ABORIGINAL, + HB_SCRIPT_YI, + HB_SCRIPT_TAGALOG, + HB_SCRIPT_HANUNOO, + HB_SCRIPT_BUHID, + HB_SCRIPT_TAGBANWA, + + /* Unicode-4.0 additions */ + HB_SCRIPT_BRAILLE, + HB_SCRIPT_CYPRIOT, + HB_SCRIPT_LIMBU, + HB_SCRIPT_OSMANYA, + HB_SCRIPT_SHAVIAN, + HB_SCRIPT_LINEAR_B, + HB_SCRIPT_TAI_LE, + HB_SCRIPT_UGARITIC, + + /* Unicode-4.1 additions */ + HB_SCRIPT_NEW_TAI_LUE, + HB_SCRIPT_BUGINESE, + HB_SCRIPT_GLAGOLITIC, + HB_SCRIPT_TIFINAGH, + HB_SCRIPT_SYLOTI_NAGRI, + HB_SCRIPT_OLD_PERSIAN, + HB_SCRIPT_KHAROSHTHI, + + /* Unicode-5.0 additions */ + HB_SCRIPT_UNKNOWN, + HB_SCRIPT_BALINESE, + HB_SCRIPT_CUNEIFORM, + HB_SCRIPT_PHOENICIAN, + HB_SCRIPT_PHAGS_PA, + HB_SCRIPT_NKO, + + /* Unicode-5.1 additions */ + HB_SCRIPT_KAYAH_LI, + HB_SCRIPT_LEPCHA, + HB_SCRIPT_REJANG, + HB_SCRIPT_SUNDANESE, + HB_SCRIPT_SAURASHTRA, + HB_SCRIPT_CHAM, + HB_SCRIPT_OL_CHIKI, + HB_SCRIPT_VAI, + HB_SCRIPT_CARIAN, + HB_SCRIPT_LYCIAN, + HB_SCRIPT_LYDIAN, + + /* Unicode-5.2 additions */ + HB_SCRIPT_AVESTAN, + HB_SCRIPT_BAMUM, + HB_SCRIPT_EGYPTIAN_HIEROGLYPHS, + HB_SCRIPT_IMPERIAL_ARAMAIC, + HB_SCRIPT_INSCRIPTIONAL_PAHLAVI, + HB_SCRIPT_INSCRIPTIONAL_PARTHIAN, + HB_SCRIPT_JAVANESE, + HB_SCRIPT_KAITHI, + HB_SCRIPT_TAI_THAM, + HB_SCRIPT_LISU, + HB_SCRIPT_MEETEI_MAYEK, + HB_SCRIPT_OLD_SOUTH_ARABIAN, + HB_SCRIPT_OLD_TURKIC, + HB_SCRIPT_SAMARITAN, + HB_SCRIPT_TAI_VIET, + + /* Unicode-6.0 additions */ + HB_SCRIPT_BATAK, + HB_SCRIPT_BRAHMI, + HB_SCRIPT_MANDAIC, + + /* Unicode-6.1 additions */ + HB_SCRIPT_CHAKMA, + HB_SCRIPT_MEROITIC_CURSIVE, + HB_SCRIPT_MEROITIC_HIEROGLYPHS, + HB_SCRIPT_MIAO, + HB_SCRIPT_SHARADA, + HB_SCRIPT_SORA_SOMPENG, + HB_SCRIPT_TAKRI +}; +#endif + +hb_script_t +hb_glib_script_to_script (GUnicodeScript script) +{ +#if GLIB_CHECK_VERSION(2,29,14) + return (hb_script_t) g_unicode_script_to_iso15924 (script); +#else + if (likely ((unsigned int) script < ARRAY_LENGTH (glib_script_to_script))) + return glib_script_to_script[script]; + + if (unlikely (script == G_UNICODE_SCRIPT_INVALID_CODE)) + return HB_SCRIPT_INVALID; + + return HB_SCRIPT_UNKNOWN; +#endif +} + +GUnicodeScript +hb_glib_script_from_script (hb_script_t script) +{ +#if GLIB_CHECK_VERSION(2,29,14) + return g_unicode_script_from_iso15924 (script); +#else + unsigned int count = ARRAY_LENGTH (glib_script_to_script); + for (unsigned int i = 0; i < count; i++) + if (glib_script_to_script[i] == script) + return (GUnicodeScript) i; + + if (unlikely (script == HB_SCRIPT_INVALID)) + return G_UNICODE_SCRIPT_INVALID_CODE; + + return G_UNICODE_SCRIPT_UNKNOWN; +#endif +} + + +static hb_unicode_combining_class_t +hb_glib_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) + +{ + return (hb_unicode_combining_class_t) g_unichar_combining_class (unicode); +} + +static unsigned int +hb_glib_unicode_eastasian_width (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return g_unichar_iswide (unicode) ? 2 : 1; +} + +static hb_unicode_general_category_t +hb_glib_unicode_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) + +{ + /* hb_unicode_general_category_t and GUnicodeType are identical */ + return (hb_unicode_general_category_t) g_unichar_type (unicode); +} + +static hb_codepoint_t +hb_glib_unicode_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + g_unichar_get_mirror_char (unicode, &unicode); + return unicode; +} + +static hb_script_t +hb_glib_unicode_script (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return hb_glib_script_to_script (g_unichar_get_script (unicode)); +} + +static hb_bool_t +hb_glib_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab, + void *user_data HB_UNUSED) +{ +#if GLIB_CHECK_VERSION(2,29,12) + return g_unichar_compose (a, b, ab); +#endif + + /* We don't ifdef-out the fallback code such that compiler always + * sees it and makes sure it's compilable. */ + + gchar utf8[12]; + gchar *normalized; + int len; + hb_bool_t ret; + + len = g_unichar_to_utf8 (a, utf8); + len += g_unichar_to_utf8 (b, utf8 + len); + normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFC); + len = g_utf8_strlen (normalized, -1); + if (unlikely (!len)) + return false; + + if (len == 1) { + *ab = g_utf8_get_char (normalized); + ret = true; + } else { + ret = false; + } + + g_free (normalized); + return ret; +} + +static hb_bool_t +hb_glib_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b, + void *user_data HB_UNUSED) +{ +#if GLIB_CHECK_VERSION(2,29,12) + return g_unichar_decompose (ab, a, b); +#endif + + /* We don't ifdef-out the fallback code such that compiler always + * sees it and makes sure it's compilable. */ + + gchar utf8[6]; + gchar *normalized; + int len; + hb_bool_t ret; + + len = g_unichar_to_utf8 (ab, utf8); + normalized = g_utf8_normalize (utf8, len, G_NORMALIZE_NFD); + len = g_utf8_strlen (normalized, -1); + if (unlikely (!len)) + return false; + + if (len == 1) { + *a = g_utf8_get_char (normalized); + *b = 0; + ret = *a != ab; + } else if (len == 2) { + *a = g_utf8_get_char (normalized); + *b = g_utf8_get_char (g_utf8_next_char (normalized)); + /* Here's the ugly part: if ab decomposes to a single character and + * that character decomposes again, we have to detect that and undo + * the second part :-(. */ + gchar *recomposed = g_utf8_normalize (normalized, -1, G_NORMALIZE_NFC); + hb_codepoint_t c = g_utf8_get_char (recomposed); + if (c != ab && c != *a) { + *a = c; + *b = 0; + } + g_free (recomposed); + ret = true; + } else { + /* If decomposed to more than two characters, take the last one, + * and recompose the rest to get the first component. */ + gchar *end = g_utf8_offset_to_pointer (normalized, len - 1); + gchar *recomposed; + *b = g_utf8_get_char (end); + recomposed = g_utf8_normalize (normalized, end - normalized, G_NORMALIZE_NFC); + /* We expect that recomposed has exactly one character now. */ + *a = g_utf8_get_char (recomposed); + g_free (recomposed); + ret = true; + } + + g_free (normalized); + return ret; +} + +static unsigned int +hb_glib_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t u, + hb_codepoint_t *decomposed, + void *user_data HB_UNUSED) +{ +#if GLIB_CHECK_VERSION(2,29,12) + return g_unichar_fully_decompose (u, TRUE, decomposed, HB_UNICODE_MAX_DECOMPOSITION_LEN); +#endif + + /* If the user doesn't have GLib >= 2.29.12 we have to perform + * a round trip to UTF-8 and the associated memory management dance. */ + gchar utf8[6]; + gchar *utf8_decomposed, *c; + gsize utf8_len, utf8_decomposed_len, i; + + /* Convert @u to UTF-8 and normalise it in NFKD mode. This performs the compatibility decomposition. */ + utf8_len = g_unichar_to_utf8 (u, utf8); + utf8_decomposed = g_utf8_normalize (utf8, utf8_len, G_NORMALIZE_NFKD); + utf8_decomposed_len = g_utf8_strlen (utf8_decomposed, -1); + + assert (utf8_decomposed_len <= HB_UNICODE_MAX_DECOMPOSITION_LEN); + + for (i = 0, c = utf8_decomposed; i < utf8_decomposed_len; i++, c = g_utf8_next_char (c)) + *decomposed++ = g_utf8_get_char (c); + + g_free (utf8_decomposed); + + return utf8_decomposed_len; +} + +hb_unicode_funcs_t * +hb_glib_get_unicode_funcs (void) +{ + static const hb_unicode_funcs_t _hb_glib_unicode_funcs = { + HB_OBJECT_HEADER_STATIC, + + NULL, /* parent */ + true, /* immutable */ + { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_glib_unicode_##name, + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } + }; + + return const_cast<hb_unicode_funcs_t *> (&_hb_glib_unicode_funcs); +} + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.h new file mode 100644 index 00000000000..63a9d3366c5 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-glib.h @@ -0,0 +1,52 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_GLIB_H +#define HB_GLIB_H + +#include "hb.h" + +#include <glib.h> + +HB_BEGIN_DECLS + + +hb_script_t +hb_glib_script_to_script (GUnicodeScript script); + +GUnicodeScript +hb_glib_script_from_script (hb_script_t script); + + +hb_unicode_funcs_t * +hb_glib_get_unicode_funcs (void); + + +HB_END_DECLS + +#endif /* HB_GLIB_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-enums.cc.tmpl b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-enums.cc.tmpl new file mode 100644 index 00000000000..05abd898d4f --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-enums.cc.tmpl @@ -0,0 +1,74 @@ +/*** BEGIN file-header ***/ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" + +/* g++ didn't like older gtype.h gcc-only code path. */ +#include <glib.h> +#if !GLIB_CHECK_VERSION(2,29,16) +#undef __GNUC__ +#undef __GNUC_MINOR__ +#define __GNUC__ 2 +#define __GNUC_MINOR__ 6 +#endif + +#include "hb-gobject.h" + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +inline static /* TODO(behdad) disable these for now until we fix them... */ +GType +@enum_name@_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter (&g_define_type_id__volatile)) + { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + GType g_define_type_id = + g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + +/*** END value-tail ***/ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-structs.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-structs.cc new file mode 100644 index 00000000000..cec48542275 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject-structs.cc @@ -0,0 +1,63 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" + +/* g++ didn't like older gtype.h gcc-only code path. */ +#include <glib.h> +#if !GLIB_CHECK_VERSION(2,29,16) +#undef __GNUC__ +#undef __GNUC_MINOR__ +#define __GNUC__ 2 +#define __GNUC_MINOR__ 6 +#endif + +#include "hb-gobject.h" + +#define _HB_DEFINE_BOXED_TYPE(Name,underscore_name,copy_func,free_func) \ +GType \ +underscore_name##_get_type (void) \ +{ \ + static volatile gsize type = 0; \ + if (g_once_init_enter (&type)) { \ + GType t = g_boxed_type_register_static (g_intern_static_string (#Name), \ + (GBoxedCopyFunc) copy_func, \ + (GBoxedFreeFunc) free_func); \ + g_once_init_leave (&type, t); \ + } \ + return type; \ +} + +#define HB_DEFINE_BOXED_TYPE(name) \ + _HB_DEFINE_BOXED_TYPE (hb_##name, hb_gobject_##name, hb_##name##_reference, hb_##name##_destroy); + +HB_DEFINE_BOXED_TYPE (buffer) +HB_DEFINE_BOXED_TYPE (blob) +HB_DEFINE_BOXED_TYPE (face) +HB_DEFINE_BOXED_TYPE (font) +HB_DEFINE_BOXED_TYPE (font_funcs) +HB_DEFINE_BOXED_TYPE (unicode_funcs) + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject.h new file mode 100644 index 00000000000..4f23fdd385d --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-gobject.h @@ -0,0 +1,69 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_GOBJECT_H +#define HB_GOBJECT_H + +#include "hb.h" + +#include <glib-object.h> + +HB_BEGIN_DECLS + + +/* Objects */ + +#define HB_GOBJECT_TYPE_BLOB hb_gobject_blob_get_type () +GType +hb_gobject_blob_get_type (void); + +#define HB_GOBJECT_TYPE_BUFFER hb_gobject_buffer_get_type () +GType +hb_gobject_buffer_get_type (void); + +#define HB_GOBJECT_TYPE_FACE hb_gobject_face_get_type () +GType +hb_gobject_face_get_type (void); + +#define HB_GOBJECT_TYPE_FONT hb_gobject_font_get_type () +GType +hb_gobject_font_get_type (void); + +#define HB_GOBJECT_TYPE_FONT_FUNCS hb_gobject_font_funcs_get_type () +GType +hb_gobject_font_funcs_get_type (void); + +#define HB_GOBJECT_TYPE_UNICODE_FUNCS hb_gobject_unicode_funcs_get_type () +GType +hb_gobject_unicode_funcs_get_type (void); + + +/* Enums */ + + +HB_END_DECLS + +#endif /* HB_GOBJECT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.cc new file mode 100644 index 00000000000..16ef9a4dabe --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.cc @@ -0,0 +1,370 @@ +/* + * Copyright © 2011 Martin Hosken + * Copyright © 2011 SIL International + * Copyright © 2011,2012 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 + */ + +#define HB_SHAPER graphite2 +#define hb_graphite2_shaper_font_data_t gr_font +#include "hb-shaper-impl-private.hh" + +#include <graphite2/Font.h> +#include <graphite2/Segment.h> + +#include "hb-graphite2.h" + +#include "hb-ot-tag.h" + + +HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, face) +HB_SHAPER_DATA_ENSURE_DECLARE(graphite2, font) + + +/* + * shaper face data + */ + +typedef struct hb_graphite2_tablelist_t { + struct hb_graphite2_tablelist_t *next; + hb_blob_t *blob; + unsigned int tag; +} hb_graphite2_tablelist_t; + +struct hb_graphite2_shaper_face_data_t { + hb_face_t *face; + gr_face *grface; + hb_graphite2_tablelist_t *tlist; +}; + +static const void *hb_graphite2_get_table (const void *data, unsigned int tag, size_t *len) +{ + hb_graphite2_shaper_face_data_t *face_data = (hb_graphite2_shaper_face_data_t *) data; + hb_graphite2_tablelist_t *tlist = face_data->tlist; + + hb_blob_t *blob = NULL; + + for (hb_graphite2_tablelist_t *p = tlist; p; p = p->next) + if (p->tag == tag) { + blob = p->blob; + break; + } + + if (unlikely (!blob)) + { + blob = face_data->face->reference_table (tag); + + hb_graphite2_tablelist_t *p = (hb_graphite2_tablelist_t *) calloc (1, sizeof (hb_graphite2_tablelist_t)); + if (unlikely (!p)) { + hb_blob_destroy (blob); + return NULL; + } + p->blob = blob; + p->tag = tag; + + /* TODO Not thread-safe, but fairly harmless. + * We can do the double-chcked pointer cmpexch thing here. */ + p->next = face_data->tlist; + face_data->tlist = p; + } + + unsigned int tlen; + const char *d = hb_blob_get_data (blob, &tlen); + *len = tlen; + return d; +} + +hb_graphite2_shaper_face_data_t * +_hb_graphite2_shaper_face_data_create (hb_face_t *face) +{ + hb_blob_t *silf_blob = face->reference_table (HB_GRAPHITE2_TAG_SILF); + /* Umm, we just reference the table to check whether it exists. + * Maybe add better API for this? */ + if (!hb_blob_get_length (silf_blob)) + { + hb_blob_destroy (silf_blob); + return NULL; + } + hb_blob_destroy (silf_blob); + + hb_graphite2_shaper_face_data_t *data = (hb_graphite2_shaper_face_data_t *) calloc (1, sizeof (hb_graphite2_shaper_face_data_t)); + if (unlikely (!data)) + hb_blob_destroy (silf_blob); + + data->face = face; + data->grface = gr_make_face (data, &hb_graphite2_get_table, gr_face_preloadAll); + + if (unlikely (!data->grface)) { + free (data); + return NULL; + } + + return data; +} + +void +_hb_graphite2_shaper_face_data_destroy (hb_graphite2_shaper_face_data_t *data) +{ + hb_graphite2_tablelist_t *tlist = data->tlist; + + while (tlist) + { + hb_graphite2_tablelist_t *old = tlist; + hb_blob_destroy (tlist->blob); + tlist = tlist->next; + free (old); + } + + gr_face_destroy (data->grface); + + free (data); +} + +gr_face * +hb_graphite2_face_get_gr_face (hb_face_t *face) +{ + if (unlikely (!hb_graphite2_shaper_face_data_ensure (face))) return NULL; + return HB_SHAPER_DATA_GET (face)->grface; +} + + +/* + * shaper font data + */ + +static float hb_graphite2_get_advance (const void *hb_font, unsigned short gid) +{ + return ((hb_font_t *) hb_font)->get_glyph_h_advance (gid); +} + +hb_graphite2_shaper_font_data_t * +_hb_graphite2_shaper_font_data_create (hb_font_t *font) +{ + if (unlikely (!hb_graphite2_shaper_face_data_ensure (font->face))) return NULL; + + hb_face_t *face = font->face; + hb_graphite2_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); + + return gr_make_font_with_advance_fn (font->x_scale, font, &hb_graphite2_get_advance, face_data->grface); +} + +void +_hb_graphite2_shaper_font_data_destroy (hb_graphite2_shaper_font_data_t *data) +{ + gr_font_destroy (data); +} + +gr_font * +hb_graphite2_font_get_gr_font (hb_font_t *font) +{ + if (unlikely (!hb_graphite2_shaper_font_data_ensure (font))) return NULL; + return HB_SHAPER_DATA_GET (font); +} + + +/* + * shaper shape_plan data + */ + +struct hb_graphite2_shaper_shape_plan_data_t {}; + +hb_graphite2_shaper_shape_plan_data_t * +_hb_graphite2_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features HB_UNUSED, + unsigned int num_user_features HB_UNUSED) +{ + return (hb_graphite2_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_graphite2_shaper_shape_plan_data_destroy (hb_graphite2_shaper_shape_plan_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper + */ + +struct hb_graphite2_cluster_t { + unsigned int base_char; + unsigned int num_chars; + unsigned int base_glyph; + unsigned int num_glyphs; +}; + +hb_bool_t +_hb_graphite2_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_face_t *face = font->face; + gr_face *grface = HB_SHAPER_DATA_GET (face)->grface; + gr_font *grfont = HB_SHAPER_DATA_GET (font); + + const char *lang = hb_language_to_string (hb_buffer_get_language (buffer)); + const char *lang_end = strchr (lang, '-'); + int lang_len = lang_end ? lang_end - lang : -1; + gr_feature_val *feats = gr_face_featureval_for_lang (grface, lang ? hb_tag_from_string (lang, lang_len) : 0); + + while (num_features--) + { + const gr_feature_ref *fref = gr_face_find_fref (grface, features->tag); + if (fref) + gr_fref_set_feature_value (fref, features->value, feats); + features++; + } + + gr_segment *seg = NULL; + const gr_slot *is; + unsigned int ci = 0, ic = 0; + float curradvx = 0., curradvy = 0.; + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + +#define ALLOCATE_ARRAY(Type, name, len) \ + Type *name = (Type *) scratch; \ + scratch += (len) * sizeof ((name)[0]); \ + scratch_size -= (len) * sizeof ((name)[0]); + + ALLOCATE_ARRAY (uint32_t, chars, buffer->len); + + for (unsigned int i = 0; i < buffer->len; ++i) + chars[i] = buffer->info[i].codepoint; + + hb_tag_t script_tag[2]; + hb_ot_tags_from_script (hb_buffer_get_script (buffer), &script_tag[0], &script_tag[1]); + + seg = gr_make_seg (grfont, grface, + script_tag[1] == HB_TAG_NONE ? script_tag[0] : script_tag[1], + feats, + gr_utf32, chars, buffer->len, + 2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ? 1 : 0)); + + if (unlikely (!seg)) { + if (feats) gr_featureval_destroy (feats); + return false; + } + + unsigned int glyph_count = gr_seg_n_slots (seg); + if (unlikely (!glyph_count)) { + if (feats) gr_featureval_destroy (feats); + gr_seg_destroy (seg); + return false; + } + + scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + while ((sizeof (hb_graphite2_cluster_t) * buffer->len + + sizeof (hb_codepoint_t) * glyph_count) > scratch_size) + { + buffer->ensure (buffer->allocated * 2); + if (unlikely (buffer->in_error)) { + if (feats) gr_featureval_destroy (feats); + gr_seg_destroy (seg); + return false; + } + scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + } + + ALLOCATE_ARRAY (hb_graphite2_cluster_t, clusters, buffer->len); + ALLOCATE_ARRAY (hb_codepoint_t, gids, glyph_count); + + memset (clusters, 0, sizeof (clusters[0]) * buffer->len); + + hb_codepoint_t *pg = gids; + for (is = gr_seg_first_slot (seg), ic = 0; is; is = gr_slot_next_in_segment (is), ic++) + { + unsigned int before = gr_slot_before (is); + unsigned int after = gr_slot_after (is); + *pg = gr_slot_gid (is); + pg++; + while (clusters[ci].base_char > before && ci) + { + clusters[ci-1].num_chars += clusters[ci].num_chars; + clusters[ci-1].num_glyphs += clusters[ci].num_glyphs; + ci--; + } + + if (gr_slot_can_insert_before (is) && clusters[ci].num_chars && before >= clusters[ci].base_char + clusters[ci].num_chars) + { + hb_graphite2_cluster_t *c = clusters + ci + 1; + c->base_char = clusters[ci].base_char + clusters[ci].num_chars; + c->num_chars = before - c->base_char; + c->base_glyph = ic; + c->num_glyphs = 0; + ci++; + } + clusters[ci].num_glyphs++; + + if (clusters[ci].base_char + clusters[ci].num_chars < after + 1) + clusters[ci].num_chars = after + 1 - clusters[ci].base_char; + } + ci++; + + //buffer->clear_output (); + for (unsigned int i = 0; i < ci; ++i) + { + for (unsigned int j = 0; j < clusters[i].num_glyphs; ++j) + { + hb_glyph_info_t *info = &buffer->info[clusters[i].base_glyph + j]; + info->codepoint = gids[clusters[i].base_glyph + j]; + info->cluster = gr_cinfo_base(gr_seg_cinfo(seg, clusters[i].base_char)); + } + } + buffer->len = glyph_count; + //buffer->swap_buffers (); + + if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction)) + curradvx = gr_seg_advance_X(seg); + + hb_glyph_position_t *pPos; + for (pPos = hb_buffer_get_glyph_positions (buffer, NULL), is = gr_seg_first_slot (seg); + is; pPos++, is = gr_slot_next_in_segment (is)) + { + pPos->x_offset = gr_slot_origin_X (is) - curradvx; + pPos->y_offset = gr_slot_origin_Y (is) - curradvy; + pPos->x_advance = gr_slot_advance_X (is, grface, grfont); + pPos->y_advance = gr_slot_advance_Y (is, grface, grfont); + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + curradvx -= pPos->x_advance; + pPos->x_offset = gr_slot_origin_X (is) - curradvx; + if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + curradvx += pPos->x_advance; + pPos->y_offset = gr_slot_origin_Y (is) - curradvy; + curradvy += pPos->y_advance; + } + if (!HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + pPos[-1].x_advance += gr_seg_advance_X(seg) - curradvx; + + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + hb_buffer_reverse_clusters (buffer); + + if (feats) gr_featureval_destroy (feats); + gr_seg_destroy (seg); + + return true; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.h new file mode 100644 index 00000000000..bea68f939b4 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-graphite2.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 Martin Hosken + * Copyright (C) 2011 SIL International + * + * 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_GRAPHITE2_H +#define HB_GRAPHITE2_H + +#include "hb.h" + +HB_BEGIN_DECLS + + +#define HB_GRAPHITE2_TAG_SILF HB_TAG('S','i','l','f') + + +gr_face * +hb_graphite2_face_get_gr_face (hb_face_t *face); + +gr_font * +hb_graphite2_font_get_gr_font (hb_font_t *font); + + +HB_END_DECLS + +#endif /* HB_GRAPHITE2_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu-le.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu-le.cc new file mode 100644 index 00000000000..c05d330b957 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu-le.cc @@ -0,0 +1,215 @@ +/* + * Copyright © 2012 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 + */ + +#define HB_SHAPER icu_le +#define hb_icu_le_shaper_font_data_t PortableFontInstance +#include "hb-shaper-impl-private.hh" + +#include "hb-icu-le/PortableFontInstance.h" + +#include "layout/loengine.h" +#include "unicode/unistr.h" + +#include "hb-icu.h" + + +/* + * shaper face data + */ + +struct hb_icu_le_shaper_face_data_t {}; + +hb_icu_le_shaper_face_data_t * +_hb_icu_le_shaper_face_data_create (hb_face_t *face HB_UNUSED) +{ + return (hb_icu_le_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_icu_le_shaper_face_data_destroy (hb_icu_le_shaper_face_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper font data + */ + +hb_icu_le_shaper_font_data_t * +_hb_icu_le_shaper_font_data_create (hb_font_t *font) +{ + LEErrorCode status = LE_NO_ERROR; + hb_icu_le_shaper_font_data_t *data = new PortableFontInstance (font->face, + font->x_scale, + font->y_scale, + status); + if (status != LE_NO_ERROR) { + delete (data); + return NULL; + } + + return data; +} + +void +_hb_icu_le_shaper_font_data_destroy (hb_icu_le_shaper_font_data_t *data) +{ + delete (data); +} + + +/* + * shaper shape_plan data + */ + +struct hb_icu_le_shaper_shape_plan_data_t {}; + +hb_icu_le_shaper_shape_plan_data_t * +_hb_icu_le_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features, + unsigned int num_user_features) +{ + return (hb_icu_le_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_icu_le_shaper_shape_plan_data_destroy (hb_icu_le_shaper_shape_plan_data_t *data) +{ +} + + +/* + * shaper + */ + +hb_bool_t +_hb_icu_le_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + LEFontInstance *font_instance = HB_SHAPER_DATA_GET (font); + le_int32 script_code = hb_icu_script_from_script (shape_plan->props.script); + le_int32 language_code = -1 /* TODO */; + le_int32 typography_flags = 3; /* Needed for ligatures and kerning */ + LEErrorCode status = LE_NO_ERROR; + le_engine *le = le_create ((const le_font *) font_instance, + script_code, + language_code, + typography_flags, + &status); + if (status != LE_NO_ERROR) + { le_close (le); return false; } + +retry: + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + +#define ALLOCATE_ARRAY(Type, name, len) \ + Type *name = (Type *) scratch; \ + scratch += (len) * sizeof ((name)[0]); \ + scratch_size -= (len) * sizeof ((name)[0]); + + ALLOCATE_ARRAY (LEUnicode, chars, buffer->len); + ALLOCATE_ARRAY (unsigned int, clusters, buffer->len); + + /* XXX Use UTF-16 decoder! */ + for (unsigned int i = 0; i < buffer->len; i++) { + chars[i] = buffer->info[i].codepoint; + clusters[i] = buffer->info[i].cluster; + } + + unsigned int glyph_count = le_layoutChars (le, + chars, + 0, + buffer->len, + buffer->len, + HB_DIRECTION_IS_BACKWARD (buffer->props.direction), + 0., 0., + &status); + if (status != LE_NO_ERROR) + { le_close (le); return false; } + + unsigned int num_glyphs = scratch_size / (sizeof (LEGlyphID) + + sizeof (le_int32) + + sizeof (float) * 2); + + if (unlikely (glyph_count >= num_glyphs || glyph_count > buffer->allocated)) { + buffer->ensure (buffer->allocated * 2); + if (buffer->in_error) + { le_close (le); return false; } + goto retry; + } + + ALLOCATE_ARRAY (LEGlyphID, glyphs, glyph_count); + ALLOCATE_ARRAY (le_int32, indices, glyph_count); + ALLOCATE_ARRAY (float, positions, glyph_count * 2 + 2); + + le_getGlyphs (le, glyphs, &status); + le_getCharIndices (le, indices, &status); + le_getGlyphPositions (le, positions, &status); + +#undef ALLOCATE_ARRAY + + /* Ok, we've got everything we need, now compose output buffer, + * very, *very*, carefully! */ + + unsigned int j = 0; + hb_glyph_info_t *info = buffer->info; + for (unsigned int i = 0; i < glyph_count; i++) + { + if (glyphs[i] >= 0xFFFE) + continue; + + info[j].codepoint = glyphs[i]; + info[j].cluster = clusters[indices[i]]; + + /* icu-le doesn't seem to have separate advance values. */ + info[j].mask = positions[2 * i + 2] - positions[2 * i]; + info[j].var1.u32 = 0; + info[j].var2.u32 = -positions[2 * i + 1]; + + j++; + } + buffer->len = j; + + buffer->clear_positions (); + + for (unsigned int i = 0; i < buffer->len; i++) { + hb_glyph_info_t *info = &buffer->info[i]; + hb_glyph_position_t *pos = &buffer->pos[i]; + + /* TODO vertical */ + pos->x_advance = info->mask; + pos->x_offset = info->var1.u32; + pos->y_offset = info->var2.u32; + } + + le_close (le); + return true; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.cc new file mode 100644 index 00000000000..c177be2c4b2 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.cc @@ -0,0 +1,372 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2009 Keith Stribley + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" + +#include "hb-icu.h" + +#include "hb-unicode-private.hh" + +#include <unicode/uchar.h> +#include <unicode/unorm.h> +#include <unicode/ustring.h> +#include <unicode/uversion.h> + + +hb_script_t +hb_icu_script_to_script (UScriptCode script) +{ + if (unlikely (script == USCRIPT_INVALID_CODE)) + return HB_SCRIPT_INVALID; + + return hb_script_from_string (uscript_getShortName (script), -1); +} + +UScriptCode +hb_icu_script_from_script (hb_script_t script) +{ + if (unlikely (script == HB_SCRIPT_INVALID)) + return USCRIPT_INVALID_CODE; + + for (unsigned int i = 0; i < USCRIPT_CODE_LIMIT; i++) + if (unlikely (hb_icu_script_to_script ((UScriptCode) i) == script)) + return (UScriptCode) i; + + return USCRIPT_UNKNOWN; +} + + +static hb_unicode_combining_class_t +hb_icu_unicode_combining_class (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) + +{ + return (hb_unicode_combining_class_t) u_getCombiningClass (unicode); +} + +static unsigned int +hb_icu_unicode_eastasian_width (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + switch (u_getIntPropertyValue(unicode, UCHAR_EAST_ASIAN_WIDTH)) + { + case U_EA_WIDE: + case U_EA_FULLWIDTH: + return 2; + case U_EA_NEUTRAL: + case U_EA_AMBIGUOUS: + case U_EA_HALFWIDTH: + case U_EA_NARROW: + return 1; + } + return 1; +} + +static hb_unicode_general_category_t +hb_icu_unicode_general_category (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + switch (u_getIntPropertyValue(unicode, UCHAR_GENERAL_CATEGORY)) + { + case U_UNASSIGNED: return HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; + + case U_UPPERCASE_LETTER: return HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER; + case U_LOWERCASE_LETTER: return HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER; + case U_TITLECASE_LETTER: return HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER; + case U_MODIFIER_LETTER: return HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER; + case U_OTHER_LETTER: return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER; + + case U_NON_SPACING_MARK: return HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK; + case U_ENCLOSING_MARK: return HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK; + case U_COMBINING_SPACING_MARK: return HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK; + + case U_DECIMAL_DIGIT_NUMBER: return HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER; + case U_LETTER_NUMBER: return HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER; + case U_OTHER_NUMBER: return HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER; + + case U_SPACE_SEPARATOR: return HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR; + case U_LINE_SEPARATOR: return HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR; + case U_PARAGRAPH_SEPARATOR: return HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR; + + case U_CONTROL_CHAR: return HB_UNICODE_GENERAL_CATEGORY_CONTROL; + case U_FORMAT_CHAR: return HB_UNICODE_GENERAL_CATEGORY_FORMAT; + case U_PRIVATE_USE_CHAR: return HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE; + case U_SURROGATE: return HB_UNICODE_GENERAL_CATEGORY_SURROGATE; + + + case U_DASH_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION; + case U_START_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION; + case U_END_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION; + case U_CONNECTOR_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION; + case U_OTHER_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION; + + case U_MATH_SYMBOL: return HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL; + case U_CURRENCY_SYMBOL: return HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL; + case U_MODIFIER_SYMBOL: return HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL; + case U_OTHER_SYMBOL: return HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL; + + case U_INITIAL_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION; + case U_FINAL_PUNCTUATION: return HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION; + } + + return HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; +} + +static hb_codepoint_t +hb_icu_unicode_mirroring (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return u_charMirror(unicode); +} + +static hb_script_t +hb_icu_unicode_script (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + UErrorCode status = U_ZERO_ERROR; + UScriptCode scriptCode = uscript_getScript(unicode, &status); + + if (unlikely (U_FAILURE (status))) + return HB_SCRIPT_UNKNOWN; + + return hb_icu_script_to_script (scriptCode); +} + +#if U_ICU_VERSION_MAJOR_NUM >= 49 +static const UNormalizer2 *normalizer; +#endif + +static hb_bool_t +hb_icu_unicode_compose (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab, + void *user_data HB_UNUSED) +{ +#if U_ICU_VERSION_MAJOR_NUM >= 49 + { + UChar32 ret = unorm2_composePair (normalizer, a, b); + if (ret < 0) return false; + *ab = ret; + return true; + } +#endif + + /* We don't ifdef-out the fallback code such that compiler always + * sees it and makes sure it's compilable. */ + + UChar utf16[4], normalized[5]; + unsigned int len; + hb_bool_t ret, err; + UErrorCode icu_err; + + len = 0; + err = false; + U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), a, err); + if (err) return false; + U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), b, err); + if (err) return false; + + icu_err = U_ZERO_ERROR; + len = unorm_normalize (utf16, len, UNORM_NFC, 0, normalized, ARRAY_LENGTH (normalized), &icu_err); + if (U_FAILURE (icu_err)) + return false; + if (u_countChar32 (normalized, len) == 1) { + U16_GET_UNSAFE (normalized, 0, *ab); + ret = true; + } else { + ret = false; + } + + return ret; +} + +static hb_bool_t +hb_icu_unicode_decompose (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b, + void *user_data HB_UNUSED) +{ +#if U_ICU_VERSION_MAJOR_NUM >= 49 + { + UChar decomposed[4]; + int len; + UErrorCode icu_err = U_ZERO_ERROR; + len = unorm2_getRawDecomposition (normalizer, ab, decomposed, + ARRAY_LENGTH (decomposed), &icu_err); + if (U_FAILURE (icu_err) || len < 0) return false; + + len = u_countChar32 (decomposed, len); + if (len == 1) { + U16_GET_UNSAFE (decomposed, 0, *a); + *b = 0; + return *a != ab; + } else if (len == 2) { + len =0; + U16_NEXT_UNSAFE (decomposed, len, *a); + U16_NEXT_UNSAFE (decomposed, len, *b); + } + return true; + } +#endif + + /* We don't ifdef-out the fallback code such that compiler always + * sees it and makes sure it's compilable. */ + + UChar utf16[2], normalized[2 * HB_UNICODE_MAX_DECOMPOSITION_LEN + 1]; + unsigned int len; + hb_bool_t ret, err; + UErrorCode icu_err; + + /* This function is a monster! Maybe it wasn't a good idea adding a + * pairwise decompose API... */ + /* Watchout for the dragons. Err, watchout for macros changing len. */ + + len = 0; + err = false; + U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), ab, err); + if (err) return false; + + icu_err = U_ZERO_ERROR; + len = unorm_normalize (utf16, len, UNORM_NFD, 0, normalized, ARRAY_LENGTH (normalized), &icu_err); + if (U_FAILURE (icu_err)) + return false; + + len = u_countChar32 (normalized, len); + + if (len == 1) { + U16_GET_UNSAFE (normalized, 0, *a); + *b = 0; + ret = *a != ab; + } else if (len == 2) { + len =0; + U16_NEXT_UNSAFE (normalized, len, *a); + U16_NEXT_UNSAFE (normalized, len, *b); + + /* Here's the ugly part: if ab decomposes to a single character and + * that character decomposes again, we have to detect that and undo + * the second part :-(. */ + UChar recomposed[20]; + icu_err = U_ZERO_ERROR; + unorm_normalize (normalized, len, UNORM_NFC, 0, recomposed, ARRAY_LENGTH (recomposed), &icu_err); + if (U_FAILURE (icu_err)) + return false; + hb_codepoint_t c; + U16_GET_UNSAFE (recomposed, 0, c); + if (c != *a && c != ab) { + *a = c; + *b = 0; + } + ret = true; + } else { + /* If decomposed to more than two characters, take the last one, + * and recompose the rest to get the first component. */ + U16_PREV_UNSAFE (normalized, len, *b); /* Changes len in-place. */ + UChar recomposed[18 * 2]; + icu_err = U_ZERO_ERROR; + len = unorm_normalize (normalized, len, UNORM_NFC, 0, recomposed, ARRAY_LENGTH (recomposed), &icu_err); + if (U_FAILURE (icu_err)) + return false; + /* We expect that recomposed has exactly one character now. */ + if (unlikely (u_countChar32 (recomposed, len) != 1)) + return false; + U16_GET_UNSAFE (recomposed, 0, *a); + ret = true; + } + + return ret; +} + +static unsigned int +hb_icu_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t u, + hb_codepoint_t *decomposed, + void *user_data HB_UNUSED) +{ + UChar utf16[2], normalized[2 * HB_UNICODE_MAX_DECOMPOSITION_LEN + 1]; + unsigned int len; + int32_t utf32_len; + hb_bool_t err; + UErrorCode icu_err; + + /* Copy @u into a UTF-16 array to be passed to ICU. */ + len = 0; + err = FALSE; + U16_APPEND (utf16, len, ARRAY_LENGTH (utf16), u, err); + if (err) + return 0; + + /* Normalise the codepoint using NFKD mode. */ + icu_err = U_ZERO_ERROR; + len = unorm_normalize (utf16, len, UNORM_NFKD, 0, normalized, ARRAY_LENGTH (normalized), &icu_err); + if (icu_err) + return 0; + + /* Convert the decomposed form from UTF-16 to UTF-32. */ + icu_err = U_ZERO_ERROR; + u_strToUTF32 ((UChar32*) decomposed, HB_UNICODE_MAX_DECOMPOSITION_LEN, &utf32_len, normalized, len, &icu_err); + if (icu_err) + return 0; + + return utf32_len; +} + + +hb_unicode_funcs_t * +hb_icu_get_unicode_funcs (void) +{ + static const hb_unicode_funcs_t _hb_icu_unicode_funcs = { + HB_OBJECT_HEADER_STATIC, + + NULL, /* parent */ + true, /* immutable */ + { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_icu_unicode_##name, + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } + }; + +#if U_ICU_VERSION_MAJOR_NUM >= 49 + if (!hb_atomic_ptr_get (&normalizer)) { + UErrorCode icu_err = U_ZERO_ERROR; + /* We ignore failure in getNFCInstace(). */ + hb_atomic_ptr_cmpexch (&normalizer, NULL, unorm2_getNFCInstance (&icu_err)); + } +#endif + return const_cast<hb_unicode_funcs_t *> (&_hb_icu_unicode_funcs); +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.h new file mode 100644 index 00000000000..f2f35f0f2ce --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-icu.h @@ -0,0 +1,52 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_ICU_H +#define HB_ICU_H + +#include "hb.h" + +#include <unicode/uscript.h> + +HB_BEGIN_DECLS + + +hb_script_t +hb_icu_script_to_script (UScriptCode script); + +UScriptCode +hb_icu_script_from_script (hb_script_t script); + + +hb_unicode_funcs_t * +hb_icu_get_unicode_funcs (void); + + +HB_END_DECLS + +#endif /* HB_ICU_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-mutex-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-mutex-private.hh new file mode 100644 index 00000000000..5b3a17e9174 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-mutex-private.hh @@ -0,0 +1,130 @@ +/* + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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. + * + * Contributor(s): + * Chris Wilson <chris@chris-wilson.co.uk> + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_MUTEX_PRIVATE_HH +#define HB_MUTEX_PRIVATE_HH + +#include "hb-private.hh" + + +/* mutex */ + +/* We need external help for these */ + +#if 0 + + +#elif !defined(HB_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +typedef CRITICAL_SECTION hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT { NULL, 0, 0, NULL, NULL, 0 } +#define hb_mutex_impl_init(M) InitializeCriticalSection (M) +#define hb_mutex_impl_lock(M) EnterCriticalSection (M) +#define hb_mutex_impl_unlock(M) LeaveCriticalSection (M) +#define hb_mutex_impl_finish(M) DeleteCriticalSection (M) + + +#elif !defined(HB_NO_MT) && (defined(HAVE_PTHREAD) || defined(__APPLE__)) + +#include <pthread.h> +typedef pthread_mutex_t hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT PTHREAD_MUTEX_INITIALIZER +#define hb_mutex_impl_init(M) pthread_mutex_init (M, NULL) +#define hb_mutex_impl_lock(M) pthread_mutex_lock (M) +#define hb_mutex_impl_unlock(M) pthread_mutex_unlock (M) +#define hb_mutex_impl_finish(M) pthread_mutex_destroy (M) + + +#elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include <sched.h> +# define HB_SCHED_YIELD() sched_yield () +#else +# define HB_SCHED_YIELD() HB_STMT_START {} HB_STMT_END +#endif + +/* This actually is not a totally awful implementation. */ +typedef volatile int hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT 0 +#define hb_mutex_impl_init(M) *(M) = 0 +#define hb_mutex_impl_lock(M) HB_STMT_START { while (__sync_lock_test_and_set((M), 1)) HB_SCHED_YIELD (); } HB_STMT_END +#define hb_mutex_impl_unlock(M) __sync_lock_release (M) +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + + +#elif !defined(HB_NO_MT) + +#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD) +# include <sched.h> +# define HB_SCHED_YIELD() sched_yield () +#else +# define HB_SCHED_YIELD() HB_STMT_START {} HB_STMT_END +#endif + +#define HB_MUTEX_INT_NIL 1 /* Warn that fallback implementation is in use. */ +typedef volatile int hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT 0 +#define hb_mutex_impl_init(M) *(M) = 0 +#define hb_mutex_impl_lock(M) HB_STMT_START { while (*(M)) HB_SCHED_YIELD (); (*(M))++; } HB_STMT_END +#define hb_mutex_impl_unlock(M) (*(M))--; +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + + +#else /* HB_NO_MT */ + +typedef int hb_mutex_impl_t; +#define HB_MUTEX_IMPL_INIT 0 +#define hb_mutex_impl_init(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_lock(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_unlock(M) HB_STMT_START {} HB_STMT_END +#define hb_mutex_impl_finish(M) HB_STMT_START {} HB_STMT_END + +#endif + + +#define HB_MUTEX_INIT {HB_MUTEX_IMPL_INIT} +struct hb_mutex_t +{ + /* TODO Add tracing. */ + + hb_mutex_impl_t m; + + inline void init (void) { hb_mutex_impl_init (&m); } + inline void lock (void) { hb_mutex_impl_lock (&m); } + inline void unlock (void) { hb_mutex_impl_unlock (&m); } + inline void finish (void) { hb_mutex_impl_finish (&m); } +}; + + +#endif /* HB_MUTEX_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-object-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-object-private.hh new file mode 100644 index 00000000000..8a9ae34dbee --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-object-private.hh @@ -0,0 +1,227 @@ +/* + * Copyright © 2007 Chris Wilson + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2011,2012 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. + * + * Contributor(s): + * Chris Wilson <chris@chris-wilson.co.uk> + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OBJECT_PRIVATE_HH +#define HB_OBJECT_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-atomic-private.hh" +#include "hb-mutex-private.hh" + + +/* Debug */ + +#ifndef HB_DEBUG_OBJECT +#define HB_DEBUG_OBJECT (HB_DEBUG+0) +#endif + + +/* reference_count */ + +#define HB_REFERENCE_COUNT_INVALID_VALUE ((hb_atomic_int_t) -1) +#define HB_REFERENCE_COUNT_INVALID {HB_REFERENCE_COUNT_INVALID_VALUE} +struct hb_reference_count_t +{ + hb_atomic_int_t ref_count; + + inline void init (int v) { ref_count = v; } + inline int inc (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), 1); } + inline int dec (void) { return hb_atomic_int_add (const_cast<hb_atomic_int_t &> (ref_count), -1); } + inline void finish (void) { ref_count = HB_REFERENCE_COUNT_INVALID_VALUE; } + + inline bool is_invalid (void) const { return ref_count == HB_REFERENCE_COUNT_INVALID_VALUE; } + +}; + + +/* user_data */ + +#define HB_USER_DATA_ARRAY_INIT {HB_MUTEX_INIT, HB_LOCKABLE_SET_INIT} +struct hb_user_data_array_t +{ + /* TODO Add tracing. */ + + struct hb_user_data_item_t { + hb_user_data_key_t *key; + void *data; + hb_destroy_func_t destroy; + + inline bool operator == (hb_user_data_key_t *other_key) const { return key == other_key; } + inline bool operator == (hb_user_data_item_t &other) const { return key == other.key; } + + void finish (void) { if (destroy) destroy (data); } + }; + + hb_mutex_t lock; + hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items; + + inline void init (void) { lock.init (); items.init (); } + + HB_INTERNAL bool set (hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + HB_INTERNAL void *get (hb_user_data_key_t *key); + + inline void finish (void) { items.finish (lock); lock.finish (); } +}; + + +/* object_header */ + +struct hb_object_header_t +{ + hb_reference_count_t ref_count; + hb_user_data_array_t user_data; + +#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT} + + static inline void *create (unsigned int size) { + hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size); + + if (likely (obj)) + obj->init (); + + return obj; + } + + inline void init (void) { + ref_count.init (1); + user_data.init (); + } + + inline bool is_inert (void) const { + return unlikely (ref_count.is_invalid ()); + } + + inline void reference (void) { + if (unlikely (!this || this->is_inert ())) + return; + ref_count.inc (); + } + + inline bool destroy (void) { + if (unlikely (!this || this->is_inert ())) + return false; + if (ref_count.dec () != 1) + return false; + + ref_count.finish (); /* Do this before user_data */ + user_data.finish (); + + return true; + } + + inline bool set_user_data (hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy_func, + hb_bool_t replace) { + if (unlikely (!this || this->is_inert ())) + return false; + + return user_data.set (key, data, destroy_func, replace); + } + + inline void *get_user_data (hb_user_data_key_t *key) { + if (unlikely (!this || this->is_inert ())) + return NULL; + + return user_data.get (key); + } + + inline void trace (const char *function) const { + if (unlikely (!this)) return; + /* TODO We cannot use DEBUG_MSG_FUNC here since that one currently only + * prints the class name and throws away the template info. */ + DEBUG_MSG (OBJECT, (void *) this, + "%s refcount=%d", + function, + this ? ref_count.ref_count : 0); + } + + private: + ASSERT_POD (); +}; + + +/* object */ + +template <typename Type> +static inline void hb_object_trace (const Type *obj, const char *function) +{ + obj->header.trace (function); +} +template <typename Type> +static inline Type *hb_object_create (void) +{ + Type *obj = (Type *) hb_object_header_t::create (sizeof (Type)); + hb_object_trace (obj, HB_FUNC); + return obj; +} +template <typename Type> +static inline bool hb_object_is_inert (const Type *obj) +{ + return unlikely (obj->header.is_inert ()); +} +template <typename Type> +static inline Type *hb_object_reference (Type *obj) +{ + hb_object_trace (obj, HB_FUNC); + obj->header.reference (); + return obj; +} +template <typename Type> +static inline bool hb_object_destroy (Type *obj) +{ + hb_object_trace (obj, HB_FUNC); + return obj->header.destroy (); +} +template <typename Type> +static inline bool hb_object_set_user_data (Type *obj, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return obj->header.set_user_data (key, data, destroy, replace); +} + +template <typename Type> +static inline void *hb_object_get_user_data (Type *obj, + hb_user_data_key_t *key) +{ + return obj->header.get_user_data (key); +} + + +#endif /* HB_OBJECT_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-old.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-old.cc new file mode 100644 index 00000000000..a7ea8ed9bbe --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-old.cc @@ -0,0 +1,410 @@ +/* + * Copyright © 2012 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 + */ + +#define HB_SHAPER old +#define hb_old_shaper_face_data_t HB_FaceRec_ +#define hb_old_shaper_font_data_t HB_Font_ +#include "hb-shaper-impl-private.hh" + +#include <harfbuzz.h> + + +#ifndef HB_DEBUG_OLD +#define HB_DEBUG_OLD (HB_DEBUG+0) +#endif + + +static HB_Script +hb_old_script_from_script (hb_script_t script) +{ + switch ((hb_tag_t) script) + { + default: + case HB_SCRIPT_COMMON: return HB_Script_Common; + case HB_SCRIPT_GREEK: return HB_Script_Greek; + case HB_SCRIPT_CYRILLIC: return HB_Script_Cyrillic; + case HB_SCRIPT_ARMENIAN: return HB_Script_Armenian; + case HB_SCRIPT_HEBREW: return HB_Script_Hebrew; + case HB_SCRIPT_ARABIC: return HB_Script_Arabic; + case HB_SCRIPT_SYRIAC: return HB_Script_Syriac; + case HB_SCRIPT_THAANA: return HB_Script_Thaana; + case HB_SCRIPT_DEVANAGARI: return HB_Script_Devanagari; + case HB_SCRIPT_BENGALI: return HB_Script_Bengali; + case HB_SCRIPT_GURMUKHI: return HB_Script_Gurmukhi; + case HB_SCRIPT_GUJARATI: return HB_Script_Gujarati; + case HB_SCRIPT_ORIYA: return HB_Script_Oriya; + case HB_SCRIPT_TAMIL: return HB_Script_Tamil; + case HB_SCRIPT_TELUGU: return HB_Script_Telugu; + case HB_SCRIPT_KANNADA: return HB_Script_Kannada; + case HB_SCRIPT_MALAYALAM: return HB_Script_Malayalam; + case HB_SCRIPT_SINHALA: return HB_Script_Sinhala; + case HB_SCRIPT_THAI: return HB_Script_Thai; + case HB_SCRIPT_LAO: return HB_Script_Lao; + case HB_SCRIPT_TIBETAN: return HB_Script_Tibetan; + case HB_SCRIPT_MYANMAR: return HB_Script_Myanmar; + case HB_SCRIPT_GEORGIAN: return HB_Script_Georgian; + case HB_SCRIPT_HANGUL: return HB_Script_Hangul; + case HB_SCRIPT_OGHAM: return HB_Script_Ogham; + case HB_SCRIPT_RUNIC: return HB_Script_Runic; + case HB_SCRIPT_KHMER: return HB_Script_Khmer; + case HB_SCRIPT_NKO: return HB_Script_Nko; + case HB_SCRIPT_INHERITED: return HB_Script_Inherited; + } +} + + +static HB_Bool +hb_old_convertStringToGlyphIndices (HB_Font old_font, + const HB_UChar16 *string, + hb_uint32 length, + HB_Glyph *glyphs, + hb_uint32 *numGlyphs, + HB_Bool rightToLeft) +{ + hb_font_t *font = (hb_font_t *) old_font->userData; + + for (unsigned int i = 0; i < length; i++) + { + hb_codepoint_t u; + + /* XXX Handle UTF-16. Ugh */ + u = string[i]; + + if (rightToLeft) + u = hb_unicode_funcs_get_default ()->mirroring (u); + + font->get_glyph (u, 0, &u); /* TODO Variation selectors */ + + glyphs[i] = u; + } + *numGlyphs = length; /* XXX */ + + return true; +} + +static void +hb_old_getGlyphAdvances (HB_Font old_font, + const HB_Glyph *glyphs, + hb_uint32 numGlyphs, + HB_Fixed *advances, + int flags /*HB_ShaperFlag*/ HB_UNUSED) +{ + hb_font_t *font = (hb_font_t *) old_font->userData; + + for (unsigned int i = 0; i < numGlyphs; i++) + advances[i] = font->get_glyph_h_advance (glyphs[i]); +} + +static HB_Bool +hb_old_canRender (HB_Font old_font, + const HB_UChar16 *string, + hb_uint32 length) +{ + return true; /* TODO */ +} + +static HB_Error +hb_old_getPointInOutline (HB_Font old_font, + HB_Glyph glyph, + int flags /*HB_ShaperFlag*/, + hb_uint32 point, + HB_Fixed *xpos, + HB_Fixed *ypos, + hb_uint32 *nPoints) +{ + return HB_Err_Ok; /* TODO */ +} + +static void +hb_old_getGlyphMetrics (HB_Font old_font, + HB_Glyph glyph, + HB_GlyphMetrics *metrics) +{ + hb_font_t *font = (hb_font_t *) old_font->userData; + + hb_glyph_extents_t extents; + + font->get_glyph_extents (glyph, &extents); + + metrics->x = extents.x_bearing; + metrics->y = extents.y_bearing; + metrics->width = extents.width; + metrics->height = extents.height; + metrics->xOffset = font->get_glyph_h_advance (glyph); + metrics->yOffset = 0; +} + +static HB_Fixed +hb_old_getFontMetric (HB_Font old_font, + HB_FontMetric metric) +{ + hb_font_t *font = (hb_font_t *) old_font->userData; + + switch (metric) + { + case HB_FontAscent: + return font->y_scale; /* XXX We don't have ascent data yet. */ + + default: + return 0; + } +} + +static const HB_FontClass hb_old_font_class = { + hb_old_convertStringToGlyphIndices, + hb_old_getGlyphAdvances, + hb_old_canRender, + hb_old_getPointInOutline, + hb_old_getGlyphMetrics, + hb_old_getFontMetric +}; + + + +static HB_Error +table_func (void *font, HB_Tag tag, HB_Byte *buffer, HB_UInt *length) +{ + hb_face_t *face = (hb_face_t *) font; + hb_blob_t *blob = face->reference_table ((hb_tag_t) tag); + unsigned int capacity = *length; + *length = hb_blob_get_length (blob); + memcpy (buffer, hb_blob_get_data (blob, NULL), MIN (capacity, *length)); + hb_blob_destroy (blob); + return HB_Err_Ok; +} + + +/* + * shaper face data + */ + +hb_old_shaper_face_data_t * +_hb_old_shaper_face_data_create (hb_face_t *face) +{ + return HB_NewFace (face, table_func); +} + +void +_hb_old_shaper_face_data_destroy (hb_old_shaper_face_data_t *data) +{ + HB_FreeFace (data); +} + + +/* + * shaper font data + */ + +hb_old_shaper_font_data_t * +_hb_old_shaper_font_data_create (hb_font_t *font) +{ + HB_FontRec *data = (HB_FontRec *) calloc (1, sizeof (HB_FontRec)); + if (unlikely (!data)) { + DEBUG_MSG (OLD, font, "malloc()ing HB_Font failed"); + return NULL; + } + + data->klass = &hb_old_font_class; + data->x_ppem = font->x_ppem; + data->y_ppem = font->y_ppem; + data->x_scale = font->x_scale; /* XXX */ + data->y_scale = font->y_scale; /* XXX */ + data->userData = font; + + return data; +} + +void +_hb_old_shaper_font_data_destroy (hb_old_shaper_font_data_t *data) +{ + free (data); +} + + +/* + * shaper shape_plan data + */ + +struct hb_old_shaper_shape_plan_data_t {}; + +hb_old_shaper_shape_plan_data_t * +_hb_old_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features HB_UNUSED, + unsigned int num_user_features HB_UNUSED) +{ + return (hb_old_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_old_shaper_shape_plan_data_destroy (hb_old_shaper_shape_plan_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper + */ + +hb_bool_t +_hb_old_shape (hb_shape_plan_t *shape_plan HB_UNUSED, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_face_t *face = font->face; + HB_Face old_face = HB_SHAPER_DATA_GET (face); + HB_Font old_font = HB_SHAPER_DATA_GET (font); + + bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); + +retry: + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + +#define utf16_index() var1.u32 + HB_UChar16 *pchars = (HB_UChar16 *) scratch; + unsigned int chars_len = 0; + for (unsigned int i = 0; i < buffer->len; i++) { + hb_codepoint_t c = buffer->info[i].codepoint; + buffer->info[i].utf16_index() = chars_len; + if (likely (c < 0x10000)) + pchars[chars_len++] = c; + else if (unlikely (c >= 0x110000)) + pchars[chars_len++] = 0xFFFD; + else { + pchars[chars_len++] = 0xD800 + ((c - 0x10000) >> 10); + pchars[chars_len++] = 0xDC00 + ((c - 0x10000) & ((1 << 10) - 1)); + } + } + + +#define ALLOCATE_ARRAY(Type, name, len) \ + name = (Type *) scratch; \ + scratch += (len) * sizeof ((name)[0]); \ + scratch_size -= (len) * sizeof ((name)[0]); + + + HB_ShaperItem item = {0}; + + ALLOCATE_ARRAY (const HB_UChar16, item.string, chars_len); + ALLOCATE_ARRAY (unsigned short, item.log_clusters, chars_len + 2); + item.stringLength = chars_len; + item.item.pos = 0; + item.item.length = item.stringLength; + item.item.script = hb_old_script_from_script (buffer->props.script); + item.item.bidiLevel = backward ? 1 : 0; + + item.font = old_font; + item.face = old_face; + item.shaperFlags = 0; + + item.glyphIndicesPresent = false; + + /* TODO Alignment. */ + unsigned int num_glyphs = scratch_size / (sizeof (HB_Glyph) + + sizeof (HB_GlyphAttributes) + + sizeof (HB_Fixed) + + sizeof (HB_FixedPoint) + + sizeof (uint32_t)); + + item.num_glyphs = num_glyphs; + ALLOCATE_ARRAY (HB_Glyph, item.glyphs, num_glyphs); + ALLOCATE_ARRAY (HB_GlyphAttributes, item.attributes, num_glyphs); + ALLOCATE_ARRAY (HB_Fixed, item.advances, num_glyphs); + ALLOCATE_ARRAY (HB_FixedPoint, item.offsets, num_glyphs); + /* Apparently in some cases the offsets array will not be fully assigned to. + * Clear it. */ + memset (item.offsets, 0, num_glyphs * sizeof (item.offsets[0])); + uint32_t *vis_clusters; + ALLOCATE_ARRAY (uint32_t, vis_clusters, num_glyphs); + +#undef ALLOCATE_ARRAY + + if (!HB_ShapeItem (&item)) + { + if (unlikely (item.num_glyphs > num_glyphs)) + { + buffer->ensure (buffer->allocated * 2); + if (buffer->in_error) + return false; + goto retry; + } + return false; + } + num_glyphs = item.num_glyphs; + + /* Ok, we've got everything we need, now compose output buffer, + * very, *very*, carefully! */ + + /* Calculate visual-clusters. That's what we ship. */ + for (unsigned int i = 0; i < num_glyphs; i++) + vis_clusters[i] = -1; + for (unsigned int i = 0; i < buffer->len; i++) { + uint32_t *p = &vis_clusters[item.log_clusters[buffer->info[i].utf16_index()]]; + *p = MIN (*p, buffer->info[i].cluster); + } + for (unsigned int i = 1; i < num_glyphs; i++) + if (vis_clusters[i] == (uint32_t) -1) + vis_clusters[i] = vis_clusters[i - 1]; + +#undef utf16_index + + buffer->ensure (num_glyphs); + if (buffer->in_error) + return false; + + + buffer->len = num_glyphs; + hb_glyph_info_t *info = buffer->info; + for (unsigned int i = 0; i < num_glyphs; i++) + { + info[i].codepoint = item.glyphs[i]; + info[i].cluster = vis_clusters[i]; + + info[i].mask = item.advances[i]; + info[i].var1.u32 = item.offsets[i].x; + info[i].var2.u32 = item.offsets[i].y; + } + + buffer->clear_positions (); + + for (unsigned int i = 0; i < num_glyphs; ++i) { + hb_glyph_info_t *info = &buffer->info[i]; + hb_glyph_position_t *pos = &buffer->pos[i]; + + /* TODO vertical */ + pos->x_advance = info->mask; + pos->x_offset = info->var1.u32; + pos->y_offset = info->var2.u32; + } + + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) + buffer->reverse (); + + return true; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-file-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-file-private.hh new file mode 100644 index 00000000000..250504ae20b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-file-private.hh @@ -0,0 +1,261 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2012 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_OPEN_FILE_PRIVATE_HH +#define HB_OPEN_FILE_PRIVATE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * + * The OpenType Font File + * + */ + + +/* + * Organization of an OpenType Font + */ + +struct OpenTypeFontFile; +struct OffsetTable; +struct TTCHeader; + + +typedef struct TableRecord +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + Tag tag; /* 4-byte identifier. */ + CheckSum checkSum; /* CheckSum for this table. */ + ULONG offset; /* Offset from beginning of TrueType font + * file. */ + ULONG length; /* Length of this table. */ + public: + DEFINE_SIZE_STATIC (16); +} OpenTypeTable; + +typedef struct OffsetTable +{ + friend struct OpenTypeFontFile; + + inline unsigned int get_table_count (void) const + { return numTables; } + inline const TableRecord& get_table (unsigned int i) const + { + if (unlikely (i >= numTables)) return Null(TableRecord); + return tables[i]; + } + inline bool find_table_index (hb_tag_t tag, unsigned int *table_index) const + { + Tag t; + t.set (tag); + unsigned int count = numTables; + for (unsigned int i = 0; i < count; i++) + { + if (t == tables[i].tag) + { + if (table_index) *table_index = i; + return true; + } + } + if (table_index) *table_index = Index::NOT_FOUND_INDEX; + return false; + } + inline const TableRecord& get_table_by_tag (hb_tag_t tag) const + { + unsigned int table_index; + find_table_index (tag, &table_index); + return get_table (table_index); + } + + public: + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && c->check_array (tables, TableRecord::static_size, numTables)); + } + + protected: + Tag sfnt_version; /* '\0\001\0\00' if TrueType / 'OTTO' if CFF */ + USHORT numTables; /* Number of tables. */ + USHORT searchRange; /* (Maximum power of 2 <= numTables) x 16 */ + USHORT entrySelector; /* Log2(maximum power of 2 <= numTables). */ + USHORT rangeShift; /* NumTables x 16-searchRange. */ + TableRecord tables[VAR]; /* TableRecord entries. numTables items */ + public: + DEFINE_SIZE_ARRAY (12, tables); +} OpenTypeFontFace; + + +/* + * TrueType Collections + */ + +struct TTCHeaderVersion1 +{ + friend struct TTCHeader; + + inline unsigned int get_face_count (void) const { return table.len; } + inline const OpenTypeFontFace& get_face (unsigned int i) const { return this+table[i]; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (table.sanitize (c, this)); + } + + protected: + Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ + FixedVersion version; /* Version of the TTC Header (1.0), + * 0x00010000 */ + LongOffsetLongArrayOf<OffsetTable> + table; /* Array of offsets to the OffsetTable for each font + * from the beginning of the file */ + public: + DEFINE_SIZE_ARRAY (12, table); +}; + +struct TTCHeader +{ + friend struct OpenTypeFontFile; + + private: + + inline unsigned int get_face_count (void) const + { + switch (u.header.version.major) { + case 2: /* version 2 is compatible with version 1 */ + case 1: return u.version1.get_face_count (); + default:return 0; + } + } + inline const OpenTypeFontFace& get_face (unsigned int i) const + { + switch (u.header.version.major) { + case 2: /* version 2 is compatible with version 1 */ + case 1: return u.version1.get_face (i); + default:return Null(OpenTypeFontFace); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!u.header.version.sanitize (c))) return TRACE_RETURN (false); + switch (u.header.version.major) { + case 2: /* version 2 is compatible with version 1 */ + case 1: return TRACE_RETURN (u.version1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + struct { + Tag ttcTag; /* TrueType Collection ID string: 'ttcf' */ + FixedVersion version; /* Version of the TTC Header (1.0 or 2.0), + * 0x00010000 or 0x00020000 */ + } header; + TTCHeaderVersion1 version1; + } u; +}; + + +/* + * OpenType Font File + */ + +struct OpenTypeFontFile +{ + static const hb_tag_t CFFTag = HB_TAG ('O','T','T','O'); /* OpenType with Postscript outlines */ + static const hb_tag_t TrueTypeTag = HB_TAG ( 0 , 1 , 0 , 0 ); /* OpenType with TrueType outlines */ + static const hb_tag_t TTCTag = HB_TAG ('t','t','c','f'); /* TrueType Collection */ + static const hb_tag_t TrueTag = HB_TAG ('t','r','u','e'); /* Obsolete Apple TrueType */ + static const hb_tag_t Typ1Tag = HB_TAG ('t','y','p','1'); /* Obsolete Apple Type1 font in SFNT container */ + + inline hb_tag_t get_tag (void) const { return u.tag; } + + inline unsigned int get_face_count (void) const + { + switch (u.tag) { + case CFFTag: /* All the non-collection tags */ + case TrueTag: + case Typ1Tag: + case TrueTypeTag: return 1; + case TTCTag: return u.ttcHeader.get_face_count (); + default: return 0; + } + } + inline const OpenTypeFontFace& get_face (unsigned int i) const + { + switch (u.tag) { + /* Note: for non-collection SFNT data we ignore index. This is because + * Apple dfont container is a container of SFNT's. So each SFNT is a + * non-TTC, but the index is more than zero. */ + case CFFTag: /* All the non-collection tags */ + case TrueTag: + case Typ1Tag: + case TrueTypeTag: return u.fontFace; + case TTCTag: return u.ttcHeader.get_face (i); + default: return Null(OpenTypeFontFace); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!u.tag.sanitize (c))) return TRACE_RETURN (false); + switch (u.tag) { + case CFFTag: /* All the non-collection tags */ + case TrueTag: + case Typ1Tag: + case TrueTypeTag: return TRACE_RETURN (u.fontFace.sanitize (c)); + case TTCTag: return TRACE_RETURN (u.ttcHeader.sanitize (c)); + default: return TRACE_RETURN (true); + } + } + + protected: + union { + Tag tag; /* 4-byte identifier. */ + OpenTypeFontFace fontFace; + TTCHeader ttcHeader; + } u; + public: + DEFINE_SIZE_UNION (4, tag); +}; + + +} /* namespace OT */ + + +#endif /* HB_OPEN_FILE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-type-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-type-private.hh new file mode 100644 index 00000000000..5bfeb165470 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-open-type-private.hh @@ -0,0 +1,962 @@ +/* + * Copyright © 2007,2008,2009,2010 Red Hat, Inc. + * Copyright © 2012 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_OPEN_TYPE_PRIVATE_HH +#define HB_OPEN_TYPE_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-blob.h" + + +namespace OT { + + + +/* + * Casts + */ + +/* Cast to struct T, reference to reference */ +template<typename Type, typename TObject> +inline const Type& CastR(const TObject &X) +{ return reinterpret_cast<const Type&> (X); } +template<typename Type, typename TObject> +inline Type& CastR(TObject &X) +{ return reinterpret_cast<Type&> (X); } + +/* Cast to struct T, pointer to pointer */ +template<typename Type, typename TObject> +inline const Type* CastP(const TObject *X) +{ return reinterpret_cast<const Type*> (X); } +template<typename Type, typename TObject> +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> +inline const Type& StructAtOffset(const void *P, unsigned int offset) +{ return * reinterpret_cast<const Type*> ((const char *) P + offset); } +template<typename Type> +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> +inline const Type& StructAfter(const TObject &X) +{ return StructAtOffset<Type>(&X, X.get_size()); } +template<typename Type, typename TObject> +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 \ + { \ + ASSERT_STATIC (_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) + +/* Size signifying variable-sized array */ +#define VAR 1 + +#define DEFINE_SIZE_UNION(size, _member) \ + DEFINE_INSTANCE_ASSERTION (this->u._member.static_size == (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) + + + +/* + * Null objects + */ + +/* Global nul-content Null pool. Enlarge as necessary. */ +/* TODO This really should be a extern HB_INTERNAL and defined somewhere... */ +static const void *_NullPool[64 / sizeof (void *)]; + +/* Generic nul-content Null objects. */ +template <typename Type> +static inline const Type& Null (void) { + ASSERT_STATIC (sizeof (Type) <= sizeof (_NullPool)); + return *CastP<Type> (_NullPool); +} + +/* Specializaiton for arbitrary-content arbitrary-sized Null objects. */ +#define DEFINE_NULL_DATA(Type, data) \ +static const char _Null##Type[sizeof (Type) + 1] = data; /* +1 is for nul-termination in data */ \ +template <> \ +inline const Type& Null<Type> (void) { \ + return *CastP<Type> (_Null##Type); \ +} /* The following line really exists such that we end in a place needing semicolon */ \ +ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type)) + +/* Accessor macro. */ +#define Null(Type) Null<Type>() + + + +/* + * Sanitize + */ + +#ifndef HB_DEBUG_SANITIZE +#define HB_DEBUG_SANITIZE (HB_DEBUG+0) +#endif + + +#define TRACE_SANITIZE(this) \ + hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + ""); + + +struct hb_sanitize_context_t +{ + inline const char *get_name (void) { return "SANITIZE"; } + static const unsigned int max_debug_depth = HB_DEBUG_SANITIZE; + typedef bool return_t; + template <typename T> + inline return_t process (const T &obj) { return obj.sanitize (this); } + static return_t default_return_value (void) { return true; } + bool stop_sublookup_iteration (const return_t r HB_UNUSED) const { return false; } + + 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, NULL); + this->end = this->start + hb_blob_get_length (this->blob); + this->edit_count = 0; + this->debug_depth = 0; + + DEBUG_MSG_LEVEL (SANITIZE, this->blob, 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->blob, 0, -1, + "end [%p..%p] %u edit requests", + this->start, this->end, this->edit_count); + + hb_blob_destroy (this->blob); + this->blob = NULL; + this->start = this->end = NULL; + } + + inline bool check_range (const void *base, unsigned int len) const + { + const char *p = (const char *) base; + + hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace + (&this->debug_depth, "SANITIZE", this->blob, NULL, + "check_range [%p..%p] (%d bytes) in [%p..%p]", + p, p + len, len, + this->start, this->end); + + return TRACE_RETURN (likely (this->start <= p && p <= this->end && (unsigned int) (this->end - p) >= len)); + } + + 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); + + hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace + (&this->debug_depth, "SANITIZE", this->blob, NULL, + "check_array [%p..%p] (%d*%d=%ld bytes) in [%p..%p]", + p, p + (record_size * len), record_size, len, (unsigned long) record_size * len, + this->start, this->end); + + return TRACE_RETURN (likely (!overflows && this->check_range (base, record_size * len))); + } + + 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 HB_UNUSED, unsigned int len HB_UNUSED) + { + const char *p = (const char *) base; + this->edit_count++; + + hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace + (&this->debug_depth, "SANITIZE", this->blob, NULL, + "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 TRACE_RETURN (this->writable); + } + + mutable unsigned int debug_depth; + const char *start, *end; + bool writable; + unsigned int edit_count; + hb_blob_t *blob; +}; + + + +/* Template to sanitize an object. */ +template <typename Type> +struct Sanitizer +{ + static hb_blob_t *sanitize (hb_blob_t *blob) { + hb_sanitize_context_t c[1] = {{0}}; + bool sane; + + /* TODO is_sane() stuff */ + + c->init (blob); + + retry: + DEBUG_MSG_FUNC (SANITIZE, blob, "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, blob, "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, blob, "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, NULL); + c->end = c->start + hb_blob_get_length (blob); + + if (c->start) { + c->writable = true; + /* ok, we made it writable by relocating. try again */ + DEBUG_MSG_FUNC (SANITIZE, blob, "retry"); + goto retry; + } + } + } + + c->end_processing (); + + DEBUG_MSG_FUNC (SANITIZE, blob, sane ? "PASSED" : "FAILED"); + if (sane) + return blob; + else { + hb_blob_destroy (blob); + return hb_blob_get_empty (); + } + } + + static const Type* lock_instance (hb_blob_t *blob) { + hb_blob_make_immutable (blob); + const char *base = hb_blob_get_data (blob, NULL); + return unlikely (!base) ? &Null(Type) : CastP<Type> (base); + } +}; + + + +/* + * Serialize + */ + +#ifndef HB_DEBUG_SERIALIZE +#define HB_DEBUG_SERIALIZE (HB_DEBUG+0) +#endif + + +#define TRACE_SERIALIZE(this) \ + hb_auto_trace_t<HB_DEBUG_SERIALIZE, bool> trace \ + (&c->debug_depth, "SERIALIZE", c, HB_FUNC, \ + ""); + + +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 < size)) { + this->ran_out_of_room = true; + return NULL; + } + 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 NULL; + 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 NULL; + 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 NULL; + return reinterpret_cast<Type *> (&obj); + } + + inline void truncate (void *head) + { + assert (this->start < head && head <= this->head); + this->head = (char *) 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_) + { + head = array; + len = len_; + } + inline const Type operator [] (unsigned int i) const + { + if (unlikely (i >= len)) return Type (); + return head[i]; + } + + inline void advance (unsigned int count) + { + if (unlikely (count > len)) + count = len; + len -= count; + head += count; + } + + private: + inline Supplier (const Supplier<Type> &); /* Disallow copy */ + inline Supplier<Type>& operator= (const Supplier<Type> &); /* Disallow copy */ + + unsigned int len; + const Type *head; +}; + + + + +/* + * + * The OpenType Font File: Data Types + */ + + +/* "The following data types are used in the OpenType font file. + * All OpenType fonts use Motorola-style byte ordering (Big Endian):" */ + +/* + * Int types + */ + + +template <typename Type, int Bytes> struct BEInt; + +template <typename Type> +struct BEInt<Type, 2> +{ + public: + inline void set (Type i) { hb_be_uint16_put (v,i); } + inline operator Type (void) const { return hb_be_uint16_get (v); } + inline bool operator == (const BEInt<Type, 2>& o) const { return hb_be_uint16_eq (v, o.v); } + inline bool operator != (const BEInt<Type, 2>& o) const { return !(*this == o); } + private: uint8_t v[2]; +}; +template <typename Type> +struct BEInt<Type, 4> +{ + public: + inline void set (Type i) { hb_be_uint32_put (v,i); } + inline operator Type (void) const { return hb_be_uint32_get (v); } + inline bool operator == (const BEInt<Type, 4>& o) const { return hb_be_uint32_eq (v, o.v); } + inline bool operator != (const BEInt<Type, 4>& o) const { return !(*this == o); } + private: uint8_t v[4]; +}; +template <typename Type> +struct BEInt<Type, 3> +{ + public: + inline void set (Type i) { hb_be_uint24_put (v,i); } + inline operator Type (void) const { return hb_be_uint24_get (v); } + inline bool operator == (const BEInt<Type, 3>& o) const { return hb_be_uint24_eq (v, o.v); } + inline bool operator != (const BEInt<Type, 3>& o) const { return !(*this == o); } + private: uint8_t v[3]; +}; + +/* Integer types in big-endian order and no alignment requirement */ +template <typename Type, unsigned int Size> +struct IntType +{ + inline void set (Type i) { v.set (i); } + inline operator Type(void) const { return v; } + inline bool operator == (const IntType<Type,Size> &o) const { return v == o.v; } + inline bool operator != (const IntType<Type,Size> &o) const { return v != o.v; } + static inline int cmp (const IntType<Type,Size> *a, const IntType<Type,Size> *b) { return b->cmp (*a); } + inline int cmp (IntType<Type,Size> va) const { Type a = va; Type b = v; return a < b ? -1 : a == b ? 0 : +1; } + inline int cmp (Type a) const { Type b = v; return a < b ? -1 : a == b ? 0 : +1; } + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (likely (c->check_struct (this))); + } + protected: + BEInt<Type, Size> v; + public: + DEFINE_SIZE_STATIC (Size); +}; + +typedef IntType<uint16_t, 2> USHORT; /* 16-bit unsigned integer. */ +typedef IntType<int16_t, 2> SHORT; /* 16-bit signed integer. */ +typedef IntType<uint32_t, 4> ULONG; /* 32-bit unsigned integer. */ +typedef IntType<int32_t, 4> LONG; /* 32-bit signed integer. */ +typedef IntType<uint32_t, 3> UINT24; /* 24-bit unsigned integer. */ + +/* 16-bit signed integer (SHORT) that describes a quantity in FUnits. */ +typedef SHORT FWORD; + +/* 16-bit unsigned integer (USHORT) that describes a quantity in FUnits. */ +typedef USHORT UFWORD; + +/* Date represented in number of seconds since 12:00 midnight, January 1, + * 1904. The value is represented as a signed 64-bit integer. */ +struct LONGDATETIME +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (likely (c->check_struct (this))); + } + private: + LONG major; + ULONG minor; + public: + DEFINE_SIZE_STATIC (8); +}; + +/* Array of four uint8s (length = 32 bits) used to identify a script, language + * system, feature, or baseline */ +struct Tag : ULONG +{ + /* What the char* converters return is NOT nul-terminated. Print using "%.4s" */ + inline operator const char* (void) const { return reinterpret_cast<const char *> (&this->v); } + inline operator char* (void) { return reinterpret_cast<char *> (&this->v); } + public: + DEFINE_SIZE_STATIC (4); +}; +DEFINE_NULL_DATA (Tag, " "); + +/* Glyph index number, same as uint16 (length = 16 bits) */ +typedef USHORT GlyphID; + +/* Script/language-system/feature index */ +struct Index : USHORT { + static const unsigned int NOT_FOUND_INDEX = 0xFFFF; +}; +DEFINE_NULL_DATA (Index, "\xff\xff"); + +/* Offset to a table, same as uint16 (length = 16 bits), Null offset = 0x0000 */ +typedef USHORT Offset; + +/* LongOffset to a table, same as uint32 (length = 32 bits), Null offset = 0x00000000 */ +typedef ULONG LongOffset; + + +/* CheckSum */ +struct CheckSum : ULONG +{ + static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length) + { + uint32_t Sum = 0L; + ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size; + + while (Table < EndPtr) + Sum += *Table++; + return Sum; + } + public: + DEFINE_SIZE_STATIC (4); +}; + + +/* + * Version Numbers + */ + +struct FixedVersion +{ + inline uint32_t to_int (void) const { return (major << 16) + minor; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + USHORT major; + USHORT minor; + public: + DEFINE_SIZE_STATIC (4); +}; + + + +/* + * Template subclasses of Offset and LongOffset that do the dereferencing. + * Use: (base+offset) + */ + +template <typename OffsetType, typename Type> +struct GenericOffsetTo : OffsetType +{ + inline const Type& operator () (const void *base) const + { + unsigned int offset = *this; + if (unlikely (!offset)) return Null(Type); + return StructAtOffset<Type> (base, offset); + } + inline Type& operator () (void *base) + { + unsigned int offset = *this; + return StructAtOffset<Type> (base, offset); + } + + inline Type& serialize (hb_serialize_context_t *c, void *base) + { + Type *t = c->start_embed<Type> (); + this->set ((char *) t - (char *) base); /* TODO(serialize) Overflow? */ + return *t; + } + + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false); + unsigned int offset = *this; + if (unlikely (!offset)) return TRACE_RETURN (true); + Type &obj = StructAtOffset<Type> (base, offset); + return TRACE_RETURN (likely (obj.sanitize (c)) || neuter (c)); + } + template <typename T> + inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false); + unsigned int offset = *this; + if (unlikely (!offset)) return TRACE_RETURN (true); + Type &obj = StructAtOffset<Type> (base, offset); + return TRACE_RETURN (likely (obj.sanitize (c, user_data)) || neuter (c)); + } + + inline bool try_set (hb_sanitize_context_t *c, const OffsetType &v) { + if (c->may_edit (this, this->static_size)) { + this->set (v); + return true; + } + return false; + } + /* Set the offset to Null */ + inline bool neuter (hb_sanitize_context_t *c) { + if (c->may_edit (this, this->static_size)) { + this->set (0); /* 0 is Null offset */ + return true; + } + return false; + } +}; +template <typename Base, typename OffsetType, typename Type> +inline const Type& operator + (const Base &base, const GenericOffsetTo<OffsetType, Type> &offset) { return offset (base); } +template <typename Base, typename OffsetType, typename Type> +inline Type& operator + (Base &base, GenericOffsetTo<OffsetType, Type> &offset) { return offset (base); } + +template <typename Type> +struct OffsetTo : GenericOffsetTo<Offset, Type> {}; + +template <typename Type> +struct LongOffsetTo : GenericOffsetTo<LongOffset, Type> {}; + + +/* + * Array Types + */ + +template <typename LenType, typename Type> +struct GenericArrayOf +{ + const Type *sub_array (unsigned int start_offset, unsigned int *pcount /* IN/OUT */) const + { + unsigned int count = len; + if (unlikely (start_offset > count)) + count = 0; + else + count -= start_offset; + count = MIN (count, *pcount); + *pcount = count; + return array + start_offset; + } + + inline const Type& operator [] (unsigned int i) const + { + if (unlikely (i >= len)) return Null(Type); + return array[i]; + } + inline Type& operator [] (unsigned int i) + { + return array[i]; + } + inline unsigned int get_size (void) const + { return len.static_size + len * Type::static_size; } + + inline bool serialize (hb_serialize_context_t *c, + unsigned int items_len) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + len.set (items_len); /* TODO(serialize) Overflow? */ + if (unlikely (!c->extend (*this))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<Type> &items, + unsigned int items_len) + { + TRACE_SERIALIZE (this); + if (unlikely (!serialize (c, items_len))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < items_len; i++) + array[i] = items[i]; + items.advance (items_len); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size. We just include + * a small unreachable expression to make sure the structs + * pointed to do have a simple sanitize(), ie. they do not + * reference other structs via offsets. + */ + (void) (false && array[0].sanitize (c)); + + return TRACE_RETURN (true); + } + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + if (unlikely (!array[i].sanitize (c, base))) + return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + template <typename T> + inline bool sanitize (hb_sanitize_context_t *c, void *base, T user_data) { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + if (unlikely (!array[i].sanitize (c, base, user_data))) + return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + private: + inline bool sanitize_shallow (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && c->check_array (this, Type::static_size, len)); + } + + public: + LenType len; + Type array[VAR]; + public: + DEFINE_SIZE_ARRAY (sizeof (LenType), array); +}; + +/* An array with a USHORT number of elements. */ +template <typename Type> +struct ArrayOf : GenericArrayOf<USHORT, Type> {}; + +/* An array with a ULONG number of elements. */ +template <typename Type> +struct LongArrayOf : GenericArrayOf<ULONG, Type> {}; + +/* Array of Offset's */ +template <typename Type> +struct OffsetArrayOf : ArrayOf<OffsetTo<Type> > {}; + +/* Array of LongOffset's */ +template <typename Type> +struct LongOffsetArrayOf : ArrayOf<LongOffsetTo<Type> > {}; + +/* LongArray of LongOffset's */ +template <typename Type> +struct LongOffsetLongArrayOf : LongArrayOf<LongOffsetTo<Type> > {}; + +/* Array of offsets relative to the beginning of the array itself. */ +template <typename Type> +struct OffsetListOf : OffsetArrayOf<Type> +{ + inline const Type& operator [] (unsigned int i) const + { + if (unlikely (i >= this->len)) return Null(Type); + return this+this->array[i]; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (OffsetArrayOf<Type>::sanitize (c, this)); + } + template <typename T> + inline bool sanitize (hb_sanitize_context_t *c, T user_data) { + TRACE_SANITIZE (this); + return TRACE_RETURN (OffsetArrayOf<Type>::sanitize (c, this, user_data)); + } +}; + + +/* An array with a USHORT number of elements, + * starting at second element. */ +template <typename Type> +struct HeadlessArrayOf +{ + inline const Type& operator [] (unsigned int i) const + { + if (unlikely (i >= len || !i)) return Null(Type); + return array[i-1]; + } + inline unsigned int get_size (void) const + { return len.static_size + (len ? len - 1 : 0) * Type::static_size; } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<Type> &items, + unsigned int items_len) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + len.set (items_len); /* TODO(serialize) Overflow? */ + if (unlikely (!items_len)) return TRACE_RETURN (true); + if (unlikely (!c->extend (*this))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < items_len - 1; i++) + array[i] = items[i]; + items.advance (items_len - 1); + return TRACE_RETURN (true); + } + + inline bool sanitize_shallow (hb_sanitize_context_t *c) { + return c->check_struct (this) + && c->check_array (this, Type::static_size, len); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!sanitize_shallow (c))) return TRACE_RETURN (false); + + /* Note: for structs that do not reference other structs, + * we do not need to call their sanitize() as we already did + * a bound check on the aggregate array size. We just include + * a small unreachable expression to make sure the structs + * pointed to do have a simple sanitize(), ie. they do not + * reference other structs via offsets. + */ + (void) (false && array[0].sanitize (c)); + + return TRACE_RETURN (true); + } + + USHORT len; + Type array[VAR]; + public: + DEFINE_SIZE_ARRAY (sizeof (USHORT), array); +}; + + +/* An array with sorted elements. Supports binary searching. */ +template <typename Type> +struct SortedArrayOf : ArrayOf<Type> { + + template <typename SearchType> + inline int search (const SearchType &x) const { + unsigned int count = this->len; + /* Linear search is *much* faster for small counts. */ + if (likely (count < 32)) { + for (unsigned int i = 0; i < count; i++) + if (this->array[i].cmp (x) == 0) + return i; + return -1; + } else { + struct Cmp { + static int cmp (const SearchType *a, const Type *b) { return b->cmp (*a); } + }; + const Type *p = (const Type *) bsearch (&x, this->array, this->len, sizeof (this->array[0]), (hb_compare_func_t) Cmp::cmp); + return p ? p - this->array : -1; + } + } +}; + + +} /* namespace OT */ + + +#endif /* HB_OPEN_TYPE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-head-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-head-table.hh new file mode 100644 index 00000000000..3a9451295de --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-head-table.hh @@ -0,0 +1,149 @@ +/* + * Copyright © 2010 Red Hat, Inc. + * Copyright © 2012 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_OT_HEAD_TABLE_HH +#define HB_OT_HEAD_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * head -- Font Header + */ + +#define HB_OT_TAG_head HB_TAG('h','e','a','d') + +struct head +{ + static const hb_tag_t Tag = HB_OT_TAG_head; + + inline unsigned int get_upem (void) const { + unsigned int upem = unitsPerEm; + /* If no valid head table found, assume 1000, which matches typical Type1 usage. */ + return 16 <= upem && upem <= 16384 ? upem : 1000; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1)); + } + + protected: + FixedVersion version; /* Version of the head table--currently + * 0x00010000 for version 1.0. */ + FixedVersion fontRevision; /* Set by font manufacturer. */ + ULONG checkSumAdjustment; /* To compute: set it to 0, sum the + * entire font as ULONG, then store + * 0xB1B0AFBA - sum. */ + ULONG magicNumber; /* Set to 0x5F0F3CF5. */ + USHORT flags; /* Bit 0: Baseline for font at y=0; + * Bit 1: Left sidebearing point at x=0; + * Bit 2: Instructions may depend on point size; + * Bit 3: Force ppem to integer values for all + * internal scaler math; may use fractional + * ppem sizes if this bit is clear; + * Bit 4: Instructions may alter advance width + * (the advance widths might not scale linearly); + + * Bits 5-10: These should be set according to + * Apple's specification. However, they are not + * implemented in OpenType. + * Bit 5: This bit should be set in fonts that are + * intended to e laid out vertically, and in + * which the glyphs have been drawn such that an + * x-coordinate of 0 corresponds to the desired + * vertical baseline. + * Bit 6: This bit must be set to zero. + * Bit 7: This bit should be set if the font + * requires layout for correct linguistic + * rendering (e.g. Arabic fonts). + * Bit 8: This bit should be set for a GX font + * which has one or more metamorphosis effects + * designated as happening by default. + * Bit 9: This bit should be set if the font + * contains any strong right-to-left glyphs. + * Bit 10: This bit should be set if the font + * contains Indic-style rearrangement effects. + + * Bit 11: Font data is 'lossless,' as a result + * of having been compressed and decompressed + * with the Agfa MicroType Express engine. + * Bit 12: Font converted (produce compatible metrics) + * Bit 13: Font optimized for ClearType™. + * Note, fonts that rely on embedded bitmaps (EBDT) + * for rendering should not be considered optimized + * for ClearType, and therefore should keep this bit + * cleared. + * Bit 14: Last Resort font. If set, indicates that + * the glyphs encoded in the cmap subtables are simply + * generic symbolic representations of code point + * ranges and don’t truly represent support for those + * code points. If unset, indicates that the glyphs + * encoded in the cmap subtables represent proper + * support for those code points. + * Bit 15: Reserved, set to 0. */ + USHORT unitsPerEm; /* Valid range is from 16 to 16384. This value + * should be a power of 2 for fonts that have + * TrueType outlines. */ + LONGDATETIME created; /* Number of seconds since 12:00 midnight, + January 1, 1904. 64-bit integer */ + LONGDATETIME modified; /* Number of seconds since 12:00 midnight, + January 1, 1904. 64-bit integer */ + SHORT xMin; /* For all glyph bounding boxes. */ + SHORT yMin; /* For all glyph bounding boxes. */ + SHORT xMax; /* For all glyph bounding boxes. */ + SHORT yMax; /* For all glyph bounding boxes. */ + USHORT macStyle; /* Bit 0: Bold (if set to 1); + * Bit 1: Italic (if set to 1) + * Bit 2: Underline (if set to 1) + * Bit 3: Outline (if set to 1) + * Bit 4: Shadow (if set to 1) + * Bit 5: Condensed (if set to 1) + * Bit 6: Extended (if set to 1) + * Bits 7-15: Reserved (set to 0). */ + USHORT lowestRecPPEM; /* Smallest readable size in pixels. */ + SHORT fontDirectionHint; /* Deprecated (Set to 2). + * 0: Fully mixed directional glyphs; + * 1: Only strongly left to right; + * 2: Like 1 but also contains neutrals; + * -1: Only strongly right to left; + * -2: Like -1 but also contains neutrals. */ + SHORT indexToLocFormat; /* 0 for short offsets, 1 for long. */ + SHORT glyphDataFormat; /* 0 for current format. */ + public: + DEFINE_SIZE_STATIC (54); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_HEAD_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hhea-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hhea-table.hh new file mode 100644 index 00000000000..2b89c4e0208 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hhea-table.hh @@ -0,0 +1,97 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_HHEA_TABLE_HH +#define HB_OT_HHEA_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * hhea -- The Horizontal Header Table + */ + +#define HB_OT_TAG_hhea HB_TAG('h','h','e','a') + + +struct hhea +{ + static const hb_tag_t Tag = HB_OT_TAG_hhea; + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && likely (version.major == 1)); + } + + protected: + FixedVersion version; /* 0x00010000 for version 1.0. */ + FWORD ascender; /* Typographic ascent. <a + * href="http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html"> + * (Distance from baseline of highest + * ascender)</a> */ + FWORD descender; /* Typographic descent. <a + * href="http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html"> + * (Distance from baseline of lowest + * descender)</a> */ + FWORD lineGap; /* Typographic line gap. Negative + * LineGap values are treated as zero + * in Windows 3.1, System 6, and + * System 7. */ + UFWORD advanceWidthMax; /* Maximum advance width value in + * 'hmtx' table. */ + FWORD minLeftSideBearing; /* Minimum left sidebearing value in + * 'hmtx' table. */ + FWORD minRightSideBearing; /* Minimum right sidebearing value; + * calculated as Min(aw - lsb - + * (xMax - xMin)). */ + FWORD xMaxExtent; /* Max(lsb + (xMax - xMin)). */ + SHORT caretSlopeRise; /* Used to calculate the slope of the + * cursor (rise/run); 1 for vertical. */ + SHORT caretSlopeRun; /* 0 for vertical. */ + SHORT caretOffset; /* The amount by which a slanted + * highlight on a glyph needs + * to be shifted to produce the + * best appearance. Set to 0 for + * non--slanted fonts */ + SHORT reserved1; /* set to 0 */ + SHORT reserved2; /* set to 0 */ + SHORT reserved3; /* set to 0 */ + SHORT reserved4; /* set to 0 */ + SHORT metricDataFormat; /* 0 for current format. */ + USHORT numberOfHMetrics; /* Number of hMetric entries in 'hmtx' + * table */ + public: + DEFINE_SIZE_STATIC (36); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_HHEA_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hmtx-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hmtx-table.hh new file mode 100644 index 00000000000..b94337d0be7 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-hmtx-table.hh @@ -0,0 +1,92 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_HMTX_TABLE_HH +#define HB_OT_HMTX_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * hmtx -- The Horizontal Metrics Table + */ + +#define HB_OT_TAG_hmtx HB_TAG('h','m','t','x') + + +struct LongHorMetric +{ + USHORT advanceWidth; + SHORT lsb; + public: + DEFINE_SIZE_STATIC (4); +}; + +struct hmtx +{ + static const hb_tag_t Tag = HB_OT_TAG_hmtx; + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + /* We don't check for anything specific here. The users of the + * struct do all the hard work... */ + return TRACE_RETURN (true); + } + + protected: + LongHorMetric longHorMetric[VAR]; /* Paired advance width and left side + * bearing values for each glyph. The + * value numOfHMetrics comes from + * the 'hhea' table. If the font is + * monospaced, only one entry need + * be in the array, but that entry is + * required. The last entry applies to + * all subsequent glyphs. */ + SHORT leftSideBearingX[VAR]; /* Here the advanceWidth is assumed + * to be the same as the advanceWidth + * for the last entry above. The + * number of entries in this array is + * derived from numGlyphs (from 'maxp' + * table) minus numberOfHMetrics. This + * generally is used with a run of + * monospaced glyphs (e.g., Kanji + * fonts or Courier fonts). Only one + * run is allowed and it must be at + * the end. This allows a monospaced + * font to vary the left side bearing + * values for each glyph. */ + public: + DEFINE_SIZE_ARRAY2 (0, longHorMetric, leftSideBearingX); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_HMTX_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-common-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-common-private.hh new file mode 100644 index 00000000000..e6018db1243 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-common-private.hh @@ -0,0 +1,1142 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2010,2012 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_OT_LAYOUT_COMMON_PRIVATE_HH +#define HB_OT_LAYOUT_COMMON_PRIVATE_HH + +#include "hb-ot-layout-private.hh" +#include "hb-open-type-private.hh" +#include "hb-set-private.hh" + + +namespace OT { + + +#define NOT_COVERED ((unsigned int) -1) +#define MAX_NESTING_LEVEL 8 + + + +/* + * + * OpenType Layout Common Table Formats + * + */ + + +/* + * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList + */ + +template <typename Type> +struct Record +{ + inline int cmp (hb_tag_t a) const { + return tag.cmp (a); + } + + struct sanitize_closure_t { + hb_tag_t tag; + void *list_base; + }; + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + const sanitize_closure_t closure = {tag, base}; + return TRACE_RETURN (c->check_struct (this) && offset.sanitize (c, base, &closure)); + } + + Tag tag; /* 4-byte Tag identifier */ + OffsetTo<Type> + offset; /* Offset from beginning of object holding + * the Record */ + public: + DEFINE_SIZE_STATIC (6); +}; + +template <typename Type> +struct RecordArrayOf : SortedArrayOf<Record<Type> > { + inline const Tag& get_tag (unsigned int i) const + { + /* We cheat slightly and don't define separate Null objects + * for Record types. Instead, we return the correct Null(Tag) + * here. */ + if (unlikely (i >= this->len)) return Null(Tag); + return (*this)[i].tag; + } + inline unsigned int get_tags (unsigned int start_offset, + unsigned int *record_count /* IN/OUT */, + hb_tag_t *record_tags /* OUT */) const + { + if (record_count) { + const Record<Type> *arr = this->sub_array (start_offset, record_count); + unsigned int count = *record_count; + for (unsigned int i = 0; i < count; i++) + record_tags[i] = arr[i].tag; + } + return this->len; + } + inline bool find_index (hb_tag_t tag, unsigned int *index) const + { + int i = this->search (tag); + if (i != -1) { + if (index) *index = i; + return true; + } else { + if (index) *index = Index::NOT_FOUND_INDEX; + return false; + } + } +}; + +template <typename Type> +struct RecordListOf : RecordArrayOf<Type> +{ + inline const Type& operator [] (unsigned int i) const + { return this+RecordArrayOf<Type>::operator [](i).offset; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (RecordArrayOf<Type>::sanitize (c, this)); + } +}; + + +struct RangeRecord +{ + inline int cmp (hb_codepoint_t g) const { + hb_codepoint_t a = start, b = end; + return g < a ? -1 : g <= b ? 0 : +1 ; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + inline bool intersects (const hb_set_t *glyphs) const { + return glyphs->intersects (start, end); + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const { + glyphs->add_range (start, end); + } + + GlyphID start; /* First GlyphID in the range */ + GlyphID end; /* Last GlyphID in the range */ + USHORT value; /* Value */ + public: + DEFINE_SIZE_STATIC (6); +}; +DEFINE_NULL_DATA (RangeRecord, "\000\001"); + + +struct IndexArray : ArrayOf<Index> +{ + inline unsigned int get_indexes (unsigned int start_offset, + unsigned int *_count /* IN/OUT */, + unsigned int *_indexes /* OUT */) const + { + if (_count) { + const USHORT *arr = this->sub_array (start_offset, _count); + unsigned int count = *_count; + for (unsigned int i = 0; i < count; i++) + _indexes[i] = arr[i]; + } + return this->len; + } +}; + + +struct Script; +struct LangSys; +struct Feature; + + +struct LangSys +{ + inline unsigned int get_feature_count (void) const + { return featureIndex.len; } + inline hb_tag_t get_feature_index (unsigned int i) const + { return featureIndex[i]; } + inline unsigned int get_feature_indexes (unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + unsigned int *feature_indexes /* OUT */) const + { return featureIndex.get_indexes (start_offset, feature_count, feature_indexes); } + + inline bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; } + inline unsigned int get_required_feature_index (void) const + { + if (reqFeatureIndex == 0xffff) + return Index::NOT_FOUND_INDEX; + return reqFeatureIndex;; + } + + inline bool sanitize (hb_sanitize_context_t *c, + const Record<LangSys>::sanitize_closure_t * = NULL) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c)); + } + + Offset lookupOrder; /* = Null (reserved for an offset to a + * reordering table) */ + USHORT reqFeatureIndex;/* Index of a feature required for this + * language system--if no required features + * = 0xFFFF */ + IndexArray featureIndex; /* Array of indices into the FeatureList */ + public: + DEFINE_SIZE_ARRAY (6, featureIndex); +}; +DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); + + +struct Script +{ + inline unsigned int get_lang_sys_count (void) const + { return langSys.len; } + inline const Tag& get_lang_sys_tag (unsigned int i) const + { return langSys.get_tag (i); } + inline unsigned int get_lang_sys_tags (unsigned int start_offset, + unsigned int *lang_sys_count /* IN/OUT */, + hb_tag_t *lang_sys_tags /* OUT */) const + { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); } + inline const LangSys& get_lang_sys (unsigned int i) const + { + if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys (); + return this+langSys[i].offset; + } + inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const + { return langSys.find_index (tag, index); } + + inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } + inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } + + inline bool sanitize (hb_sanitize_context_t *c, + const Record<Script>::sanitize_closure_t * = NULL) { + TRACE_SANITIZE (this); + return TRACE_RETURN (defaultLangSys.sanitize (c, this) && langSys.sanitize (c, this)); + } + + protected: + OffsetTo<LangSys> + defaultLangSys; /* Offset to DefaultLangSys table--from + * beginning of Script table--may be Null */ + RecordArrayOf<LangSys> + langSys; /* Array of LangSysRecords--listed + * alphabetically by LangSysTag */ + public: + DEFINE_SIZE_ARRAY (4, langSys); +}; + +typedef RecordListOf<Script> ScriptList; + + +/* http://www.microsoft.com/typography/otspec/features_pt.htm#size */ +struct FeatureParamsSize +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!c->check_struct (this))) return TRACE_RETURN (false); + + /* This subtable has some "history", if you will. Some earlier versions of + * Adobe tools calculated the offset of the FeatureParams sutable from the + * beginning of the FeatureList table! Now, that is dealt with in the + * Feature implementation. But we still need to be able to tell junk from + * real data. Note: We don't check that the nameID actually exists. + * + * Read Roberts wrote on 9/15/06 on opentype-list@indx.co.uk : + * + * Yes, it is correct that a new version of the AFDKO (version 2.0) will be + * coming out soon, and that the makeotf program will build a font with a + * 'size' feature that is correct by the specification. + * + * The specification for this feature tag is in the "OpenType Layout Tag + * Registry". You can see a copy of this at: + * http://partners.adobe.com/public/developer/opentype/index_tag8.html#size + * + * Here is one set of rules to determine if the 'size' feature is built + * correctly, or as by the older versions of MakeOTF. You may be able to do + * better. + * + * Assume that the offset to the size feature is according to specification, + * and make the following value checks. If it fails, assume the the size + * feature is calculated as versions of MakeOTF before the AFDKO 2.0 built it. + * If this fails, reject the 'size' feature. The older makeOTF's calculated the + * offset from the beginning of the FeatureList table, rather than from the + * beginning of the 'size' Feature table. + * + * If "design size" == 0: + * fails check + * + * Else if ("subfamily identifier" == 0 and + * "range start" == 0 and + * "range end" == 0 and + * "range start" == 0 and + * "menu name ID" == 0) + * passes check: this is the format used when there is a design size + * specified, but there is no recommended size range. + * + * Else if ("design size" < "range start" or + * "design size" > "range end" or + * "range end" <= "range start" or + * "menu name ID" < 256 or + * "menu name ID" > 32767 or + * menu name ID is not a name ID which is actually in the name table) + * fails test + * Else + * passes test. + */ + + if (!designSize) + return TRACE_RETURN (false); + else if (subfamilyID == 0 && + subfamilyNameID == 0 && + rangeStart == 0 && + rangeEnd == 0) + return TRACE_RETURN (true); + else if (designSize < rangeStart || + designSize > rangeEnd || + subfamilyNameID < 256 || + subfamilyNameID > 32767) + return TRACE_RETURN (false); + else + return TRACE_RETURN (true); + } + + USHORT designSize; /* Represents the design size in 720/inch + * units (decipoints). The design size entry + * must be non-zero. When there is a design + * size but no recommended size range, the + * rest of the array will consist of zeros. */ + USHORT subfamilyID; /* Has no independent meaning, but serves + * as an identifier that associates fonts + * in a subfamily. All fonts which share a + * Preferred or Font Family name and which + * differ only by size range shall have the + * same subfamily value, and no fonts which + * differ in weight or style shall have the + * same subfamily value. If this value is + * zero, the remaining fields in the array + * will be ignored. */ + USHORT subfamilyNameID;/* If the preceding value is non-zero, this + * value must be set in the range 256 - 32767 + * (inclusive). It records the value of a + * field in the name table, which must + * contain English-language strings encoded + * in Windows Unicode and Macintosh Roman, + * and may contain additional strings + * localized to other scripts and languages. + * Each of these strings is the name an + * application should use, in combination + * with the family name, to represent the + * subfamily in a menu. Applications will + * choose the appropriate version based on + * their selection criteria. */ + USHORT rangeStart; /* Large end of the recommended usage range + * (inclusive), stored in 720/inch units + * (decipoints). */ + USHORT rangeEnd; /* Small end of the recommended usage range + (exclusive), stored in 720/inch units + * (decipoints). */ + public: + DEFINE_SIZE_STATIC (10); +}; + +/* http://www.microsoft.com/typography/otspec/features_pt.htm#ssxx */ +struct FeatureParamsStylisticSet +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + /* Right now minorVersion is at zero. Which means, any table supports + * the uiNameID field. */ + return TRACE_RETURN (c->check_struct (this)); + } + + USHORT minorVersion; /* (set to 0): This corresponds to a “minor” + * version number. Additional data may be + * added to the end of this Feature Parameters + * table in the future. */ + + USHORT uiNameID; /* The 'name' table name ID that specifies a + * string (or strings, for multiple languages) + * for a user-interface label for this + * feature. The values of uiLabelNameId and + * sampleTextNameId are expected to be in the + * font-specific name ID range (256-32767), + * though that is not a requirement in this + * Feature Parameters specification. The + * user-interface label for the feature can + * be provided in multiple languages. An + * English string should be included as a + * fallback. The string should be kept to a + * minimal length to fit comfortably with + * different application interfaces. */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct FeatureParamsCharacterVariants +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && + characters.sanitize (c)); + } + + USHORT format; /* Format number is set to 0. */ + USHORT featUILableNameID; /* The ‘name’ table name ID that + * specifies a string (or strings, + * for multiple languages) for a + * user-interface label for this + * feature. (May be NULL.) */ + USHORT featUITooltipTextNameID;/* The ‘name’ table name ID that + * specifies a string (or strings, + * for multiple languages) that an + * application can use for tooltip + * text for this feature. (May be + * NULL.) */ + USHORT sampleTextNameID; /* The ‘name’ table name ID that + * specifies sample text that + * illustrates the effect of this + * feature. (May be NULL.) */ + USHORT numNamedParameters; /* Number of named parameters. (May + * be zero.) */ + USHORT firstParamUILabelNameID;/* 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.) */ + ArrayOf<UINT24> + characters; /* Array of the Unicode Scalar Value + * of the characters for which this + * feature provides glyph variants. + * (May be zero.) */ + public: + DEFINE_SIZE_ARRAY (14, characters); +}; + +struct FeatureParams +{ + inline bool sanitize (hb_sanitize_context_t *c, hb_tag_t tag) { + TRACE_SANITIZE (this); + if (tag == HB_TAG ('s','i','z','e')) + return TRACE_RETURN (u.size.sanitize (c)); + if ((tag & 0xFFFF0000) == HB_TAG ('s','s','\0','\0')) /* ssXX */ + return TRACE_RETURN (u.stylisticSet.sanitize (c)); + if ((tag & 0xFFFF0000) == HB_TAG ('c','v','\0','\0')) /* cvXX */ + return TRACE_RETURN (u.characterVariants.sanitize (c)); + return TRACE_RETURN (true); + } + + inline const FeatureParamsSize& get_size_params (hb_tag_t tag) const + { + if (tag == HB_TAG ('s','i','z','e')) + return u.size; + return Null(FeatureParamsSize); + } + + private: + union { + FeatureParamsSize size; + FeatureParamsStylisticSet stylisticSet; + FeatureParamsCharacterVariants characterVariants; + } u; + DEFINE_SIZE_STATIC (17); +}; + +struct Feature +{ + inline unsigned int get_lookup_count (void) const + { return lookupIndex.len; } + inline hb_tag_t get_lookup_index (unsigned int i) const + { return lookupIndex[i]; } + inline unsigned int get_lookup_indexes (unsigned int start_index, + unsigned int *lookup_count /* IN/OUT */, + unsigned int *lookup_tags /* OUT */) const + { return lookupIndex.get_indexes (start_index, lookup_count, lookup_tags); } + + inline const FeatureParams &get_feature_params (void) const + { return this+featureParams; } + + inline bool sanitize (hb_sanitize_context_t *c, + const Record<Feature>::sanitize_closure_t *closure) { + TRACE_SANITIZE (this); + if (unlikely (!(c->check_struct (this) && lookupIndex.sanitize (c)))) + return TRACE_RETURN (false); + + /* Some earlier versions of Adobe tools calculated the offset of the + * FeatureParams subtable from the beginning of the FeatureList table! + * + * If sanitizing "failed" for the FeatureParams subtable, try it with the + * alternative location. We would know sanitize "failed" if old value + * of the offset was non-zero, but it's zeroed now. + * + * Only do this for the 'size' feature, since at the time of the faulty + * Adobe tools, only the 'size' feature had FeatureParams defined. + */ + + Offset orig_offset = featureParams; + if (unlikely (!featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE))) + return TRACE_RETURN (false); + + if (likely (!orig_offset)) + return TRACE_RETURN (true); + + if (featureParams == 0 && closure && + closure->tag == HB_TAG ('s','i','z','e') && + closure->list_base && closure->list_base < this) + { + unsigned int new_offset_int = (unsigned int) orig_offset - + ((char *) this - (char *) closure->list_base); + + Offset new_offset; + /* Check that it did not overflow. */ + new_offset.set (new_offset_int); + if (new_offset == new_offset_int && + featureParams.try_set (c, new_offset) && + !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE)) + return TRACE_RETURN (false); + } + + return TRACE_RETURN (true); + } + + OffsetTo<FeatureParams> + featureParams; /* Offset to Feature Parameters table (if one + * has been defined for the feature), relative + * to the beginning of the Feature Table; = Null + * if not required */ + IndexArray lookupIndex; /* Array of LookupList indices */ + public: + DEFINE_SIZE_ARRAY (4, lookupIndex); +}; + +typedef RecordListOf<Feature> FeatureList; + + +struct LookupFlag : USHORT +{ + enum Flags { + RightToLeft = 0x0001u, + IgnoreBaseGlyphs = 0x0002u, + IgnoreLigatures = 0x0004u, + IgnoreMarks = 0x0008u, + IgnoreFlags = 0x000Eu, + UseMarkFilteringSet = 0x0010u, + Reserved = 0x00E0u, + MarkAttachmentType = 0xFF00u + }; + public: + DEFINE_SIZE_STATIC (2); +}; + +struct Lookup +{ + inline unsigned int get_subtable_count (void) const { return subTable.len; } + + inline unsigned int get_type (void) const { return lookupType; } + + /* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and + * higher 16-bit is mark-filtering-set if the lookup uses one. + * Not to be confused with glyph_props which is very similar. */ + inline uint32_t get_props (void) const + { + unsigned int flag = lookupFlag; + if (unlikely (flag & LookupFlag::UseMarkFilteringSet)) + { + const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); + flag += (markFilteringSet << 16); + } + return flag; + } + + inline bool serialize (hb_serialize_context_t *c, + unsigned int lookup_type, + uint32_t lookup_props, + unsigned int num_subtables) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + lookupType.set (lookup_type); + lookupFlag.set (lookup_props & 0xFFFF); + if (unlikely (!subTable.serialize (c, num_subtables))) return TRACE_RETURN (false); + if (lookupFlag & LookupFlag::UseMarkFilteringSet) + { + USHORT &markFilteringSet = StructAfter<USHORT> (subTable); + markFilteringSet.set (lookup_props >> 16); + } + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + /* Real sanitize of the subtables is done by GSUB/GPOS/... */ + if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN (false); + if (lookupFlag & LookupFlag::UseMarkFilteringSet) + { + USHORT &markFilteringSet = StructAfter<USHORT> (subTable); + if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); + } + return TRACE_RETURN (true); + } + + USHORT lookupType; /* Different enumerations for GSUB and GPOS */ + USHORT lookupFlag; /* Lookup qualifiers */ + ArrayOf<Offset> + subTable; /* Array of SubTables */ + USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets + * structure. This field is only present if bit + * UseMarkFilteringSet of lookup flags is set. */ + public: + DEFINE_SIZE_ARRAY2 (6, subTable, markFilteringSetX); +}; + +typedef OffsetListOf<Lookup> LookupList; + + +/* + * Coverage Table + */ + +struct CoverageFormat1 +{ + friend struct Coverage; + + private: + inline unsigned int get_coverage (hb_codepoint_t glyph_id) const + { + int i = glyphArray.search (glyph_id); + ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); + return i; + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + glyphArray.len.set (num_glyphs); + if (unlikely (!c->extend (glyphArray))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < num_glyphs; i++) + glyphArray[i] = glyphs[i]; + glyphs.advance (num_glyphs); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (glyphArray.sanitize (c)); + } + + inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { + return glyphs->has (glyphArray[index]); + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const { + unsigned int count = glyphArray.len; + for (unsigned int i = 0; i < count; i++) + glyphs->add (glyphArray[i]); + } + + public: + /* Older compilers need this to be public. */ + struct Iter { + inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; }; + inline bool more (void) { return i < c->glyphArray.len; } + inline void next (void) { i++; } + inline uint16_t get_glyph (void) { return c->glyphArray[i]; } + inline uint16_t get_coverage (void) { return i; } + + private: + const struct CoverageFormat1 *c; + unsigned int i; + }; + private: + + protected: + USHORT coverageFormat; /* Format identifier--format = 1 */ + SortedArrayOf<GlyphID> + glyphArray; /* Array of GlyphIDs--in numerical order */ + public: + DEFINE_SIZE_ARRAY (4, glyphArray); +}; + +struct CoverageFormat2 +{ + friend struct Coverage; + + private: + inline unsigned int get_coverage (hb_codepoint_t glyph_id) const + { + int i = rangeRecord.search (glyph_id); + if (i != -1) { + const RangeRecord &range = rangeRecord[i]; + return (unsigned int) range.value + (glyph_id - range.start); + } + return NOT_COVERED; + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + + if (unlikely (!num_glyphs)) return TRACE_RETURN (true); + + unsigned int num_ranges = 1; + for (unsigned int i = 1; i < num_glyphs; i++) + if (glyphs[i - 1] + 1 != glyphs[i]) + num_ranges++; + rangeRecord.len.set (num_ranges); + if (unlikely (!c->extend (rangeRecord))) return TRACE_RETURN (false); + + unsigned int range = 0; + rangeRecord[range].start = glyphs[0]; + rangeRecord[range].value.set (0); + for (unsigned int i = 1; i < num_glyphs; i++) + if (glyphs[i - 1] + 1 != glyphs[i]) { + range++; + rangeRecord[range].start = glyphs[i]; + rangeRecord[range].value.set (i); + rangeRecord[range].end = glyphs[i]; + } else { + rangeRecord[range].end = glyphs[i]; + } + glyphs.advance (num_glyphs); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (rangeRecord.sanitize (c)); + } + + inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { + unsigned int i; + unsigned int count = rangeRecord.len; + for (i = 0; i < count; i++) { + const RangeRecord &range = rangeRecord[i]; + if (range.value <= index && + index < (unsigned int) range.value + (range.end - range.start) && + range.intersects (glyphs)) + return true; + else if (index < range.value) + return false; + } + return false; + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const { + unsigned int count = rangeRecord.len; + for (unsigned int i = 0; i < count; i++) + rangeRecord[i].add_coverage (glyphs); + } + + public: + /* Older compilers need this to be public. */ + struct Iter { + inline void init (const CoverageFormat2 &c_) { + c = &c_; + coverage = 0; + i = 0; + j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; + } + inline bool more (void) { return i < c->rangeRecord.len; } + inline void next (void) { + coverage++; + if (j == c->rangeRecord[i].end) { + i++; + if (more ()) + j = c->rangeRecord[i].start; + return; + } + j++; + } + inline uint16_t get_glyph (void) { return j; } + inline uint16_t get_coverage (void) { return coverage; } + + private: + const struct CoverageFormat2 *c; + unsigned int i, j, coverage; + }; + private: + + protected: + USHORT coverageFormat; /* Format identifier--format = 2 */ + SortedArrayOf<RangeRecord> + rangeRecord; /* Array of glyph ranges--ordered by + * Start GlyphID. rangeCount entries + * long */ + public: + DEFINE_SIZE_ARRAY (4, rangeRecord); +}; + +struct Coverage +{ + inline unsigned int get_coverage (hb_codepoint_t glyph_id) const + { + switch (u.format) { + case 1: return u.format1.get_coverage(glyph_id); + case 2: return u.format2.get_coverage(glyph_id); + default:return NOT_COVERED; + } + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + unsigned int num_ranges = 1; + for (unsigned int i = 1; i < num_glyphs; i++) + if (glyphs[i - 1] + 1 != glyphs[i]) + num_ranges++; + u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs)); + case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, num_glyphs)); + default:return TRACE_RETURN (false); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + inline bool intersects (const hb_set_t *glyphs) const { + /* TODO speed this up */ + Coverage::Iter iter; + for (iter.init (*this); iter.more (); iter.next ()) { + if (glyphs->has (iter.get_glyph ())) + return true; + } + return false; + } + + inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { + switch (u.format) { + case 1: return u.format1.intersects_coverage (glyphs, index); + case 2: return u.format2.intersects_coverage (glyphs, index); + default:return false; + } + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const { + switch (u.format) { + case 1: u.format1.add_coverage (glyphs); break; + case 2: u.format2.add_coverage (glyphs); break; + default: break; + } + } + + struct Iter { + Iter (void) : format (0) {}; + inline void init (const Coverage &c_) { + format = c_.u.format; + switch (format) { + case 1: return u.format1.init (c_.u.format1); + case 2: return u.format2.init (c_.u.format2); + default:return; + } + } + inline bool more (void) { + switch (format) { + case 1: return u.format1.more (); + case 2: return u.format2.more (); + default:return true; + } + } + inline void next (void) { + switch (format) { + case 1: u.format1.next (); break; + case 2: u.format2.next (); break; + default: break; + } + } + inline uint16_t get_glyph (void) { + switch (format) { + case 1: return u.format1.get_glyph (); + case 2: return u.format2.get_glyph (); + default:return true; + } + } + inline uint16_t get_coverage (void) { + switch (format) { + case 1: return u.format1.get_coverage (); + case 2: return u.format2.get_coverage (); + default:return true; + } + } + + private: + unsigned int format; + union { + CoverageFormat1::Iter format1; + CoverageFormat2::Iter format2; + } u; + }; + + protected: + union { + USHORT format; /* Format identifier */ + CoverageFormat1 format1; + CoverageFormat2 format2; + } u; + public: + DEFINE_SIZE_UNION (2, format); +}; + + +/* + * Class Definition Table + */ + +struct ClassDefFormat1 +{ + friend struct ClassDef; + + private: + inline unsigned int get_class (hb_codepoint_t glyph_id) const + { + if (unlikely ((unsigned int) (glyph_id - startGlyph) < classValue.len)) + return classValue[glyph_id - startGlyph]; + return 0; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && classValue.sanitize (c)); + } + + template <typename set_t> + inline void add_class (set_t *glyphs, unsigned int klass) const { + unsigned int count = classValue.len; + for (unsigned int i = 0; i < count; i++) + if (classValue[i] == klass) + glyphs->add (startGlyph + i); + } + + inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { + unsigned int count = classValue.len; + for (unsigned int i = 0; i < count; i++) + if (classValue[i] == klass && glyphs->has (startGlyph + i)) + return true; + return false; + } + + protected: + USHORT classFormat; /* Format identifier--format = 1 */ + GlyphID startGlyph; /* First GlyphID of the classValueArray */ + ArrayOf<USHORT> + classValue; /* Array of Class Values--one per GlyphID */ + public: + DEFINE_SIZE_ARRAY (6, classValue); +}; + +struct ClassDefFormat2 +{ + friend struct ClassDef; + + private: + inline unsigned int get_class (hb_codepoint_t glyph_id) const + { + int i = rangeRecord.search (glyph_id); + if (i != -1) + return rangeRecord[i].value; + return 0; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (rangeRecord.sanitize (c)); + } + + template <typename set_t> + inline void add_class (set_t *glyphs, unsigned int klass) const { + unsigned int count = rangeRecord.len; + for (unsigned int i = 0; i < count; i++) + if (rangeRecord[i].value == klass) + rangeRecord[i].add_coverage (glyphs); + } + + inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { + unsigned int count = rangeRecord.len; + for (unsigned int i = 0; i < count; i++) + if (rangeRecord[i].value == klass && rangeRecord[i].intersects (glyphs)) + return true; + return false; + } + + protected: + USHORT classFormat; /* Format identifier--format = 2 */ + SortedArrayOf<RangeRecord> + rangeRecord; /* Array of glyph ranges--ordered by + * Start GlyphID */ + public: + DEFINE_SIZE_ARRAY (4, rangeRecord); +}; + +struct ClassDef +{ + inline unsigned int get_class (hb_codepoint_t glyph_id) const + { + switch (u.format) { + case 1: return u.format1.get_class(glyph_id); + case 2: return u.format2.get_class(glyph_id); + default:return 0; + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + inline void add_class (hb_set_t *glyphs, unsigned int klass) const { + switch (u.format) { + case 1: u.format1.add_class (glyphs, klass); return; + case 2: u.format2.add_class (glyphs, klass); return; + default:return; + } + } + + inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { + switch (u.format) { + case 1: return u.format1.intersects_class (glyphs, klass); + case 2: return u.format2.intersects_class (glyphs, klass); + default:return false; + } + } + + protected: + union { + USHORT format; /* Format identifier */ + ClassDefFormat1 format1; + ClassDefFormat2 format2; + } u; + public: + DEFINE_SIZE_UNION (2, format); +}; + + +/* + * Device Tables + */ + +struct Device +{ + + inline hb_position_t get_x_delta (hb_font_t *font) const + { return get_delta (font->x_ppem, font->x_scale); } + + inline hb_position_t get_y_delta (hb_font_t *font) const + { return get_delta (font->y_ppem, font->y_scale); } + + inline int get_delta (unsigned int ppem, int scale) const + { + if (!ppem) return 0; + + int pixels = get_delta_pixels (ppem); + + if (!pixels) return 0; + + return pixels * (int64_t) scale / ppem; + } + + + inline int get_delta_pixels (unsigned int ppem_size) const + { + unsigned int f = deltaFormat; + if (unlikely (f < 1 || f > 3)) + return 0; + + if (ppem_size < startSize || ppem_size > endSize) + return 0; + + unsigned int s = ppem_size - startSize; + + unsigned int byte = deltaValue[s >> (4 - f)]; + unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f))); + unsigned int mask = (0xFFFF >> (16 - (1 << f))); + + int delta = bits & mask; + + if ((unsigned int) delta >= ((mask + 1) >> 1)) + delta -= mask + 1; + + return delta; + } + + inline unsigned int get_size (void) const + { + unsigned int f = deltaFormat; + if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::static_size; + return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && c->check_range (this, this->get_size ())); + } + + protected: + USHORT startSize; /* Smallest size to correct--in ppem */ + USHORT endSize; /* Largest size to correct--in ppem */ + USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 + * 1 Signed 2-bit value, 8 values per uint16 + * 2 Signed 4-bit value, 4 values per uint16 + * 3 Signed 8-bit value, 2 values per uint16 + */ + USHORT deltaValue[VAR]; /* Array of compressed data */ + public: + DEFINE_SIZE_ARRAY (6, deltaValue); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gdef-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gdef-table.hh new file mode 100644 index 00000000000..ff2d09c51f0 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gdef-table.hh @@ -0,0 +1,431 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2010,2011,2012 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_OT_LAYOUT_GDEF_TABLE_HH +#define HB_OT_LAYOUT_GDEF_TABLE_HH + +#include "hb-ot-layout-common-private.hh" + +#include "hb-font-private.hh" + + +namespace OT { + + +/* + * Attachment List Table + */ + +typedef ArrayOf<USHORT> AttachPoint; /* Array of contour point indices--in + * increasing numerical order */ + +struct AttachList +{ + inline unsigned int get_attach_points (hb_codepoint_t glyph_id, + unsigned int start_offset, + unsigned int *point_count /* IN/OUT */, + unsigned int *point_array /* OUT */) const + { + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (index == NOT_COVERED) + { + if (point_count) + *point_count = 0; + return 0; + } + + const AttachPoint &points = this+attachPoint[index]; + + if (point_count) { + const USHORT *array = points.sub_array (start_offset, point_count); + unsigned int count = *point_count; + for (unsigned int i = 0; i < count; i++) + point_array[i] = array[i]; + } + + return points.len; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && attachPoint.sanitize (c, this)); + } + + protected: + OffsetTo<Coverage> + coverage; /* Offset to Coverage table -- from + * beginning of AttachList table */ + OffsetArrayOf<AttachPoint> + attachPoint; /* Array of AttachPoint tables + * in Coverage Index order */ + public: + DEFINE_SIZE_ARRAY (4, attachPoint); +}; + +/* + * Ligature Caret Table + */ + +struct CaretValueFormat1 +{ + friend struct CaretValue; + + private: + inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const + { + return HB_DIRECTION_IS_HORIZONTAL (direction) ? font->em_scale_x (coordinate) : font->em_scale_y (coordinate); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + protected: + USHORT caretValueFormat; /* Format identifier--format = 1 */ + SHORT coordinate; /* X or Y value, in design units */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct CaretValueFormat2 +{ + friend struct CaretValue; + + private: + inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const + { + hb_position_t x, y; + if (font->get_glyph_contour_point_for_origin (glyph_id, caretValuePoint, direction, &x, &y)) + return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y; + else + return 0; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + protected: + USHORT caretValueFormat; /* Format identifier--format = 2 */ + USHORT caretValuePoint; /* Contour point index on glyph */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct CaretValueFormat3 +{ + friend struct CaretValue; + + inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id HB_UNUSED) const + { + return HB_DIRECTION_IS_HORIZONTAL (direction) ? + font->em_scale_x (coordinate) + (this+deviceTable).get_x_delta (font) : + font->em_scale_y (coordinate) + (this+deviceTable).get_y_delta (font); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && deviceTable.sanitize (c, this)); + } + + protected: + USHORT caretValueFormat; /* Format identifier--format = 3 */ + SHORT coordinate; /* X or Y value, in design units */ + OffsetTo<Device> + deviceTable; /* Offset to Device table for X or Y + * value--from beginning of CaretValue + * table */ + public: + DEFINE_SIZE_STATIC (6); +}; + +struct CaretValue +{ + inline hb_position_t get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const + { + switch (u.format) { + case 1: return u.format1.get_caret_value (font, direction, glyph_id); + case 2: return u.format2.get_caret_value (font, direction, glyph_id); + case 3: return u.format3.get_caret_value (font, direction, glyph_id); + default:return 0; + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + case 3: return TRACE_RETURN (u.format3.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + CaretValueFormat1 format1; + CaretValueFormat2 format2; + CaretValueFormat3 format3; + } u; + public: + DEFINE_SIZE_UNION (2, format); +}; + +struct LigGlyph +{ + inline unsigned int get_lig_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph_id, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + hb_position_t *caret_array /* OUT */) const + { + if (caret_count) { + const OffsetTo<CaretValue> *array = carets.sub_array (start_offset, caret_count); + unsigned int count = *caret_count; + for (unsigned int i = 0; i < count; i++) + caret_array[i] = (this+array[i]).get_caret_value (font, direction, glyph_id); + } + + return carets.len; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (carets.sanitize (c, this)); + } + + protected: + OffsetArrayOf<CaretValue> + carets; /* Offset array of CaretValue tables + * --from beginning of LigGlyph table + * --in increasing coordinate order */ + public: + DEFINE_SIZE_ARRAY (2, carets); +}; + +struct LigCaretList +{ + inline unsigned int get_lig_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph_id, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + hb_position_t *caret_array /* OUT */) const + { + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (index == NOT_COVERED) + { + if (caret_count) + *caret_count = 0; + return 0; + } + const LigGlyph &lig_glyph = this+ligGlyph[index]; + return lig_glyph.get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && ligGlyph.sanitize (c, this)); + } + + protected: + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of LigCaretList table */ + OffsetArrayOf<LigGlyph> + ligGlyph; /* Array of LigGlyph tables + * in Coverage Index order */ + public: + DEFINE_SIZE_ARRAY (4, ligGlyph); +}; + + +struct MarkGlyphSetsFormat1 +{ + inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const + { return (this+coverage[set_index]).get_coverage (glyph_id) != NOT_COVERED; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + LongOffsetArrayOf<Coverage> + coverage; /* Array of long offsets to mark set + * coverage tables */ + public: + DEFINE_SIZE_ARRAY (4, coverage); +}; + +struct MarkGlyphSets +{ + inline bool covers (unsigned int set_index, hb_codepoint_t glyph_id) const + { + switch (u.format) { + case 1: return u.format1.covers (set_index, glyph_id); + default:return false; + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + MarkGlyphSetsFormat1 format1; + } u; + public: + DEFINE_SIZE_UNION (2, format); +}; + + +/* + * GDEF -- The Glyph Definition Table + */ + +struct GDEF +{ + static const hb_tag_t Tag = HB_OT_TAG_GDEF; + + enum GlyphClasses { + UnclassifiedGlyph = 0, + BaseGlyph = 1, + LigatureGlyph = 2, + MarkGlyph = 3, + ComponentGlyph = 4 + }; + + inline bool has_glyph_classes (void) const { return glyphClassDef != 0; } + inline unsigned int get_glyph_class (hb_codepoint_t glyph) const + { return (this+glyphClassDef).get_class (glyph); } + inline void get_glyphs_in_class (unsigned int klass, hb_set_t *glyphs) const + { (this+glyphClassDef).add_class (glyphs, klass); } + + inline bool has_mark_attachment_types (void) const { return markAttachClassDef != 0; } + inline unsigned int get_mark_attachment_type (hb_codepoint_t glyph) const + { return (this+markAttachClassDef).get_class (glyph); } + + inline bool has_attach_points (void) const { return attachList != 0; } + inline unsigned int get_attach_points (hb_codepoint_t glyph_id, + unsigned int start_offset, + unsigned int *point_count /* IN/OUT */, + unsigned int *point_array /* OUT */) const + { return (this+attachList).get_attach_points (glyph_id, start_offset, point_count, point_array); } + + inline bool has_lig_carets (void) const { return ligCaretList != 0; } + inline unsigned int get_lig_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph_id, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + hb_position_t *caret_array /* OUT */) const + { return (this+ligCaretList).get_lig_carets (font, direction, glyph_id, start_offset, caret_count, caret_array); } + + inline bool has_mark_sets (void) const { return version.to_int () >= 0x00010002 && markGlyphSetsDef[0] != 0; } + inline bool mark_set_covers (unsigned int set_index, hb_codepoint_t glyph_id) const + { return version.to_int () >= 0x00010002 && (this+markGlyphSetsDef[0]).covers (set_index, glyph_id); } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (version.sanitize (c) && + likely (version.major == 1) && + glyphClassDef.sanitize (c, this) && + attachList.sanitize (c, this) && + ligCaretList.sanitize (c, this) && + markAttachClassDef.sanitize (c, this) && + (version.to_int () < 0x00010002 || markGlyphSetsDef[0].sanitize (c, this))); + } + + + /* glyph_props is a 16-bit integer where the lower 8-bit have bits representing + * glyph class and other bits, and high 8-bit gthe mark attachment type (if any). + * Not to be confused with lookup_props which is very similar. */ + inline unsigned int get_glyph_props (hb_codepoint_t glyph) const + { + unsigned int klass = get_glyph_class (glyph); + + switch (klass) { + default: + case UnclassifiedGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_UNCLASSIFIED; + case BaseGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH; + case LigatureGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; + case ComponentGlyph: return HB_OT_LAYOUT_GLYPH_PROPS_COMPONENT; + case MarkGlyph: + klass = get_mark_attachment_type (glyph); + return HB_OT_LAYOUT_GLYPH_PROPS_MARK | (klass << 8); + } + } + + + protected: + FixedVersion version; /* Version of the GDEF table--currently + * 0x00010002 */ + OffsetTo<ClassDef> + glyphClassDef; /* Offset to class definition table + * for glyph type--from beginning of + * GDEF header (may be Null) */ + OffsetTo<AttachList> + attachList; /* Offset to list of glyphs with + * attachment points--from beginning + * of GDEF header (may be Null) */ + OffsetTo<LigCaretList> + ligCaretList; /* Offset to list of positioning points + * for ligature carets--from beginning + * of GDEF header (may be Null) */ + OffsetTo<ClassDef> + markAttachClassDef; /* Offset to class definition table for + * mark attachment type--from beginning + * of GDEF header (may be Null) */ + OffsetTo<MarkGlyphSets> + markGlyphSetsDef[VAR]; /* Offset to the table of mark set + * definitions--from beginning of GDEF + * header (may be NULL). Introduced + * in version 00010002. */ + public: + DEFINE_SIZE_ARRAY (12, markGlyphSetsDef); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_LAYOUT_GDEF_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gpos-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gpos-table.hh new file mode 100644 index 00000000000..d27ce4f71ee --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gpos-table.hh @@ -0,0 +1,1646 @@ +/* + * Copyright © 2007,2008,2009,2010 Red Hat, Inc. + * Copyright © 2010,2012 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_OT_LAYOUT_GPOS_TABLE_HH +#define HB_OT_LAYOUT_GPOS_TABLE_HH + +#include "hb-ot-layout-gsubgpos-private.hh" + + +namespace OT { + + +/* buffer **position** var allocations */ +#define attach_lookback() var.u16[0] /* number of glyphs to go back to attach this glyph to its base */ +#define cursive_chain() var.i16[1] /* character to which this connects, may be positive or negative */ + + +/* Shared Tables: ValueRecord, Anchor Table, and MarkArray */ + +typedef USHORT Value; + +typedef Value ValueRecord[VAR]; + +struct ValueFormat : USHORT +{ + enum Flags { + xPlacement = 0x0001, /* Includes horizontal adjustment for placement */ + yPlacement = 0x0002, /* Includes vertical adjustment for placement */ + xAdvance = 0x0004, /* Includes horizontal adjustment for advance */ + yAdvance = 0x0008, /* Includes vertical adjustment for advance */ + xPlaDevice = 0x0010, /* Includes horizontal Device table for placement */ + yPlaDevice = 0x0020, /* Includes vertical Device table for placement */ + xAdvDevice = 0x0040, /* Includes horizontal Device table for advance */ + yAdvDevice = 0x0080, /* Includes vertical Device table for advance */ + ignored = 0x0F00, /* Was used in TrueType Open for MM fonts */ + reserved = 0xF000, /* For future use */ + + devices = 0x00F0 /* Mask for having any Device table */ + }; + +/* All fields are options. Only those available advance the value pointer. */ +#if 0 + SHORT xPlacement; /* Horizontal adjustment for + * placement--in design units */ + SHORT yPlacement; /* Vertical adjustment for + * placement--in design units */ + SHORT xAdvance; /* Horizontal adjustment for + * advance--in design units (only used + * for horizontal writing) */ + SHORT yAdvance; /* Vertical adjustment for advance--in + * design units (only used for vertical + * writing) */ + Offset xPlaDevice; /* Offset to Device table for + * horizontal placement--measured from + * beginning of PosTable (may be NULL) */ + Offset yPlaDevice; /* Offset to Device table for vertical + * placement--measured from beginning + * of PosTable (may be NULL) */ + Offset xAdvDevice; /* Offset to Device table for + * horizontal advance--measured from + * beginning of PosTable (may be NULL) */ + Offset yAdvDevice; /* Offset to Device table for vertical + * advance--measured from beginning of + * PosTable (may be NULL) */ +#endif + + inline unsigned int get_len (void) const + { return _hb_popcount32 ((unsigned int) *this); } + inline unsigned int get_size (void) const + { return get_len () * Value::static_size; } + + void apply_value (hb_font_t *font, + hb_direction_t direction, + const void *base, + const Value *values, + hb_glyph_position_t &glyph_pos) const + { + unsigned int x_ppem, y_ppem; + unsigned int format = *this; + hb_bool_t horizontal = HB_DIRECTION_IS_HORIZONTAL (direction); + + if (!format) return; + + if (format & xPlacement) glyph_pos.x_offset += font->em_scale_x (get_short (values++)); + if (format & yPlacement) glyph_pos.y_offset += font->em_scale_y (get_short (values++)); + if (format & xAdvance) { + if (likely (horizontal)) glyph_pos.x_advance += font->em_scale_x (get_short (values++)); else values++; + } + /* y_advance values grow downward but font-space grows upward, hence negation */ + if (format & yAdvance) { + if (unlikely (!horizontal)) glyph_pos.y_advance -= font->em_scale_y (get_short (values++)); else values++; + } + + if (!has_device ()) return; + + x_ppem = font->x_ppem; + y_ppem = font->y_ppem; + + if (!x_ppem && !y_ppem) return; + + /* pixel -> fractional pixel */ + if (format & xPlaDevice) { + if (x_ppem) glyph_pos.x_offset += (base + get_device (values++)).get_x_delta (font); else values++; + } + if (format & yPlaDevice) { + if (y_ppem) glyph_pos.y_offset += (base + get_device (values++)).get_y_delta (font); else values++; + } + if (format & xAdvDevice) { + if (horizontal && x_ppem) glyph_pos.x_advance += (base + get_device (values++)).get_x_delta (font); else values++; + } + if (format & yAdvDevice) { + /* y_advance values grow downward but font-space grows upward, hence negation */ + if (!horizontal && y_ppem) glyph_pos.y_advance -= (base + get_device (values++)).get_y_delta (font); else values++; + } + } + + private: + inline bool sanitize_value_devices (hb_sanitize_context_t *c, void *base, Value *values) { + unsigned int format = *this; + + if (format & xPlacement) values++; + if (format & yPlacement) values++; + if (format & xAdvance) values++; + if (format & yAdvance) values++; + + if ((format & xPlaDevice) && !get_device (values++).sanitize (c, base)) return false; + if ((format & yPlaDevice) && !get_device (values++).sanitize (c, base)) return false; + if ((format & xAdvDevice) && !get_device (values++).sanitize (c, base)) return false; + if ((format & yAdvDevice) && !get_device (values++).sanitize (c, base)) return false; + + return true; + } + + static inline OffsetTo<Device>& get_device (Value* value) + { return *CastP<OffsetTo<Device> > (value); } + static inline const OffsetTo<Device>& get_device (const Value* value) + { return *CastP<OffsetTo<Device> > (value); } + + static inline const SHORT& get_short (const Value* value) + { return *CastP<SHORT> (value); } + + public: + + inline bool has_device (void) const { + unsigned int format = *this; + return (format & devices) != 0; + } + + inline bool sanitize_value (hb_sanitize_context_t *c, void *base, Value *values) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_range (values, get_size ()) && (!has_device () || sanitize_value_devices (c, base, values))); + } + + inline bool sanitize_values (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count) { + TRACE_SANITIZE (this); + unsigned int len = get_len (); + + if (!c->check_array (values, get_size (), count)) return TRACE_RETURN (false); + + if (!has_device ()) return TRACE_RETURN (true); + + for (unsigned int i = 0; i < count; i++) { + if (!sanitize_value_devices (c, base, values)) + return TRACE_RETURN (false); + values += len; + } + + return TRACE_RETURN (true); + } + + /* Just sanitize referenced Device tables. Doesn't check the values themselves. */ + inline bool sanitize_values_stride_unsafe (hb_sanitize_context_t *c, void *base, Value *values, unsigned int count, unsigned int stride) { + TRACE_SANITIZE (this); + + if (!has_device ()) return TRACE_RETURN (true); + + for (unsigned int i = 0; i < count; i++) { + if (!sanitize_value_devices (c, base, values)) + return TRACE_RETURN (false); + values += stride; + } + + return TRACE_RETURN (true); + } +}; + + +struct AnchorFormat1 +{ + inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED, + hb_position_t *x, hb_position_t *y) const + { + *x = font->em_scale_x (xCoordinate); + *y = font->em_scale_y (yCoordinate); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + SHORT xCoordinate; /* Horizontal value--in design units */ + SHORT yCoordinate; /* Vertical value--in design units */ + public: + DEFINE_SIZE_STATIC (6); +}; + +struct AnchorFormat2 +{ + inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id, + hb_position_t *x, hb_position_t *y) const + { + unsigned int x_ppem = font->x_ppem; + unsigned int y_ppem = font->y_ppem; + hb_position_t cx, cy; + hb_bool_t ret = false; + + if (x_ppem || y_ppem) + ret = font->get_glyph_contour_point_for_origin (glyph_id, anchorPoint, HB_DIRECTION_LTR, &cx, &cy); + *x = x_ppem && ret ? cx : font->em_scale_x (xCoordinate); + *y = y_ppem && ret ? cy : font->em_scale_y (yCoordinate); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + SHORT xCoordinate; /* Horizontal value--in design units */ + SHORT yCoordinate; /* Vertical value--in design units */ + USHORT anchorPoint; /* Index to glyph contour point */ + public: + DEFINE_SIZE_STATIC (8); +}; + +struct AnchorFormat3 +{ + inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id HB_UNUSED, + hb_position_t *x, hb_position_t *y) const + { + *x = font->em_scale_x (xCoordinate); + *y = font->em_scale_y (yCoordinate); + + if (font->x_ppem) + *x += (this+xDeviceTable).get_x_delta (font); + if (font->y_ppem) + *y += (this+yDeviceTable).get_x_delta (font); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && xDeviceTable.sanitize (c, this) && yDeviceTable.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 3 */ + SHORT xCoordinate; /* Horizontal value--in design units */ + SHORT yCoordinate; /* Vertical value--in design units */ + OffsetTo<Device> + xDeviceTable; /* Offset to Device table for X + * coordinate-- from beginning of + * Anchor table (may be NULL) */ + OffsetTo<Device> + yDeviceTable; /* Offset to Device table for Y + * coordinate-- from beginning of + * Anchor table (may be NULL) */ + public: + DEFINE_SIZE_STATIC (10); +}; + +struct Anchor +{ + inline void get_anchor (hb_font_t *font, hb_codepoint_t glyph_id, + hb_position_t *x, hb_position_t *y) const + { + *x = *y = 0; + switch (u.format) { + case 1: u.format1.get_anchor (font, glyph_id, x, y); return; + case 2: u.format2.get_anchor (font, glyph_id, x, y); return; + case 3: u.format3.get_anchor (font, glyph_id, x, y); return; + default: return; + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + case 3: return TRACE_RETURN (u.format3.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + AnchorFormat1 format1; + AnchorFormat2 format2; + AnchorFormat3 format3; + } u; + public: + DEFINE_SIZE_UNION (2, format); +}; + + +struct AnchorMatrix +{ + inline const Anchor& get_anchor (unsigned int row, unsigned int col, unsigned int cols) const { + if (unlikely (row >= rows || col >= cols)) return Null(Anchor); + return this+matrix[row * cols + col]; + } + + inline bool sanitize (hb_sanitize_context_t *c, unsigned int cols) { + TRACE_SANITIZE (this); + if (!c->check_struct (this)) return TRACE_RETURN (false); + if (unlikely (rows > 0 && cols >= ((unsigned int) -1) / rows)) return TRACE_RETURN (false); + unsigned int count = rows * cols; + if (!c->check_array (matrix, matrix[0].static_size, count)) return TRACE_RETURN (false); + for (unsigned int i = 0; i < count; i++) + if (!matrix[i].sanitize (c, this)) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + USHORT rows; /* Number of rows */ + protected: + OffsetTo<Anchor> + matrix[VAR]; /* Matrix of offsets to Anchor tables-- + * from beginning of AnchorMatrix table */ + public: + DEFINE_SIZE_ARRAY (2, matrix); +}; + + +struct MarkRecord +{ + friend struct MarkArray; + + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && markAnchor.sanitize (c, base)); + } + + protected: + USHORT klass; /* Class defined for this mark */ + OffsetTo<Anchor> + markAnchor; /* Offset to Anchor table--from + * beginning of MarkArray table */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct MarkArray : ArrayOf<MarkRecord> /* Array of MarkRecords--in Coverage order */ +{ + inline bool apply (hb_apply_context_t *c, + unsigned int mark_index, unsigned int glyph_index, + const AnchorMatrix &anchors, unsigned int class_count, + unsigned int glyph_pos) const + { + TRACE_APPLY (this); + const MarkRecord &record = ArrayOf<MarkRecord>::operator[](mark_index); + unsigned int mark_class = record.klass; + + const Anchor& mark_anchor = this + record.markAnchor; + const Anchor& glyph_anchor = anchors.get_anchor (glyph_index, mark_class, class_count); + + hb_position_t mark_x, mark_y, base_x, base_y; + + mark_anchor.get_anchor (c->font, c->buffer->cur().codepoint, &mark_x, &mark_y); + glyph_anchor.get_anchor (c->font, c->buffer->info[glyph_pos].codepoint, &base_x, &base_y); + + hb_glyph_position_t &o = c->buffer->cur_pos(); + o.x_offset = base_x - mark_x; + o.y_offset = base_y - mark_y; + o.attach_lookback() = c->buffer->idx - glyph_pos; + + c->buffer->idx++; + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (ArrayOf<MarkRecord>::sanitize (c, this)); + } +}; + + +/* Lookups */ + +struct SinglePosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + valueFormat.apply_value (c->font, c->direction, this, + values, c->buffer->cur_pos()); + + c->buffer->idx++; + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_value (c, this, values)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of subtable */ + ValueFormat valueFormat; /* Defines the types of data in the + * ValueRecord */ + ValueRecord values; /* Defines positioning + * value(s)--applied to all glyphs in + * the Coverage table */ + public: + DEFINE_SIZE_ARRAY (6, values); +}; + +struct SinglePosFormat2 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + if (likely (index >= valueCount)) return TRACE_RETURN (false); + + valueFormat.apply_value (c->font, c->direction, this, + &values[index * valueFormat.get_len ()], + c->buffer->cur_pos()); + + c->buffer->idx++; + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && valueFormat.sanitize_values (c, this, values, valueCount)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of subtable */ + ValueFormat valueFormat; /* Defines the types of data in the + * ValueRecord */ + USHORT valueCount; /* Number of ValueRecords */ + ValueRecord values; /* Array of ValueRecords--positioning + * values applied to glyphs */ + public: + DEFINE_SIZE_ARRAY (8, values); +}; + +struct SinglePos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + case 2: return TRACE_RETURN (c->process (u.format2)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + SinglePosFormat1 format1; + SinglePosFormat2 format2; + } u; +}; + + +struct PairValueRecord +{ + friend struct PairSet; + + protected: + GlyphID secondGlyph; /* GlyphID of second glyph in the + * pair--first glyph is listed in the + * Coverage table */ + ValueRecord values; /* Positioning data for the first glyph + * followed by for second glyph */ + public: + DEFINE_SIZE_ARRAY (2, values); +}; + +struct PairSet +{ + friend struct PairPosFormat1; + + inline void collect_glyphs (hb_collect_glyphs_context_t *c, + const ValueFormat *valueFormats) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int len1 = valueFormats[0].get_len (); + unsigned int len2 = valueFormats[1].get_len (); + unsigned int record_size = USHORT::static_size * (1 + len1 + len2); + + const PairValueRecord *record = CastP<PairValueRecord> (array); + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + { + c->input->add (record->secondGlyph); + record = &StructAtOffset<PairValueRecord> (record, record_size); + } + } + + inline bool apply (hb_apply_context_t *c, + const ValueFormat *valueFormats, + unsigned int pos) const + { + TRACE_APPLY (this); + unsigned int len1 = valueFormats[0].get_len (); + unsigned int len2 = valueFormats[1].get_len (); + unsigned int record_size = USHORT::static_size * (1 + len1 + len2); + + const PairValueRecord *record = CastP<PairValueRecord> (array); + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + { + if (c->buffer->info[pos].codepoint == record->secondGlyph) + { + valueFormats[0].apply_value (c->font, c->direction, this, + &record->values[0], c->buffer->cur_pos()); + valueFormats[1].apply_value (c->font, c->direction, this, + &record->values[len1], c->buffer->pos[pos]); + if (len2) + pos++; + c->buffer->idx = pos; + return TRACE_RETURN (true); + } + record = &StructAtOffset<PairValueRecord> (record, record_size); + } + + return TRACE_RETURN (false); + } + + struct sanitize_closure_t { + void *base; + ValueFormat *valueFormats; + unsigned int len1; /* valueFormats[0].get_len() */ + unsigned int stride; /* 1 + len1 + len2 */ + }; + + inline bool sanitize (hb_sanitize_context_t *c, const sanitize_closure_t *closure) { + TRACE_SANITIZE (this); + if (!(c->check_struct (this) + && c->check_array (array, USHORT::static_size * closure->stride, len))) return TRACE_RETURN (false); + + unsigned int count = len; + PairValueRecord *record = CastP<PairValueRecord> (array); + return TRACE_RETURN (closure->valueFormats[0].sanitize_values_stride_unsafe (c, closure->base, &record->values[0], count, closure->stride) + && closure->valueFormats[1].sanitize_values_stride_unsafe (c, closure->base, &record->values[closure->len1], count, closure->stride)); + } + + protected: + USHORT len; /* Number of PairValueRecords */ + USHORT array[VAR]; /* Array of PairValueRecords--ordered + * by GlyphID of the second glyph */ + public: + DEFINE_SIZE_ARRAY (2, array); +}; + +struct PairPosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + unsigned int count = pairSet.len; + for (unsigned int i = 0; i < count; i++) + (this+pairSet[i]).collect_glyphs (c, &valueFormat1); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, 1); + if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); + + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + if (!skippy_iter.next ()) return TRACE_RETURN (false); + + return TRACE_RETURN ((this+pairSet[index]).apply (c, &valueFormat1, skippy_iter.idx)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + + unsigned int len1 = valueFormat1.get_len (); + unsigned int len2 = valueFormat2.get_len (); + PairSet::sanitize_closure_t closure = { + this, + &valueFormat1, + len1, + 1 + len1 + len2 + }; + + return TRACE_RETURN (c->check_struct (this) && coverage.sanitize (c, this) && pairSet.sanitize (c, this, &closure)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of subtable */ + ValueFormat valueFormat1; /* Defines the types of data in + * ValueRecord1--for the first glyph + * in the pair--may be zero (0) */ + ValueFormat valueFormat2; /* Defines the types of data in + * ValueRecord2--for the second glyph + * in the pair--may be zero (0) */ + OffsetArrayOf<PairSet> + pairSet; /* Array of PairSet tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (10, pairSet); +}; + +struct PairPosFormat2 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + /* (this+coverage).add_coverage (c->input); // Don't need this. */ + + /* TODO only add values for pairs that have nonzero adjustments. */ + + unsigned int count1 = class1Count; + const ClassDef &klass1 = this+classDef1; + for (unsigned int i = 0; i < count1; i++) + klass1.add_class (c->input, i); + + unsigned int count2 = class2Count; + const ClassDef &klass2 = this+classDef2; + for (unsigned int i = 0; i < count2; i++) + klass2.add_class (c->input, i); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, 1); + if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); + + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + if (!skippy_iter.next ()) return TRACE_RETURN (false); + + unsigned int len1 = valueFormat1.get_len (); + unsigned int len2 = valueFormat2.get_len (); + unsigned int record_len = len1 + len2; + + unsigned int klass1 = (this+classDef1).get_class (c->buffer->cur().codepoint); + unsigned int klass2 = (this+classDef2).get_class (c->buffer->info[skippy_iter.idx].codepoint); + if (unlikely (klass1 >= class1Count || klass2 >= class2Count)) return TRACE_RETURN (false); + + const Value *v = &values[record_len * (klass1 * class2Count + klass2)]; + valueFormat1.apply_value (c->font, c->direction, this, + v, c->buffer->cur_pos()); + valueFormat2.apply_value (c->font, c->direction, this, + v + len1, c->buffer->pos[skippy_iter.idx]); + + c->buffer->idx = skippy_iter.idx; + if (len2) + c->buffer->idx++; + + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!(c->check_struct (this) + && coverage.sanitize (c, this) + && classDef1.sanitize (c, this) + && classDef2.sanitize (c, this))) return TRACE_RETURN (false); + + unsigned int len1 = valueFormat1.get_len (); + unsigned int len2 = valueFormat2.get_len (); + unsigned int stride = len1 + len2; + unsigned int record_size = valueFormat1.get_size () + valueFormat2.get_size (); + unsigned int count = (unsigned int) class1Count * (unsigned int) class2Count; + return TRACE_RETURN (c->check_array (values, record_size, count) && + valueFormat1.sanitize_values_stride_unsafe (c, this, &values[0], count, stride) && + valueFormat2.sanitize_values_stride_unsafe (c, this, &values[len1], count, stride)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of subtable */ + ValueFormat valueFormat1; /* ValueRecord definition--for the + * first glyph of the pair--may be zero + * (0) */ + ValueFormat valueFormat2; /* ValueRecord definition--for the + * second glyph of the pair--may be + * zero (0) */ + OffsetTo<ClassDef> + classDef1; /* Offset to ClassDef table--from + * beginning of PairPos subtable--for + * the first glyph of the pair */ + OffsetTo<ClassDef> + classDef2; /* Offset to ClassDef table--from + * beginning of PairPos subtable--for + * the second glyph of the pair */ + USHORT class1Count; /* Number of classes in ClassDef1 + * table--includes Class0 */ + USHORT class2Count; /* Number of classes in ClassDef2 + * table--includes Class0 */ + ValueRecord values; /* Matrix of value pairs: + * class1-major, class2-minor, + * Each entry has value1 and value2 */ + public: + DEFINE_SIZE_ARRAY (16, values); +}; + +struct PairPos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + case 2: return TRACE_RETURN (c->process (u.format2)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + PairPosFormat1 format1; + PairPosFormat2 format2; + } u; +}; + + +struct EntryExitRecord +{ + friend struct CursivePosFormat1; + + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + return TRACE_RETURN (entryAnchor.sanitize (c, base) && exitAnchor.sanitize (c, base)); + } + + protected: + OffsetTo<Anchor> + entryAnchor; /* Offset to EntryAnchor table--from + * beginning of CursivePos + * subtable--may be NULL */ + OffsetTo<Anchor> + exitAnchor; /* Offset to ExitAnchor table--from + * beginning of CursivePos + * subtable--may be NULL */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct CursivePosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + + /* We don't handle mark glyphs here. */ + if (c->property & HB_OT_LAYOUT_GLYPH_PROPS_MARK) return TRACE_RETURN (false); + + hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, 1); + if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); + + const EntryExitRecord &this_record = entryExitRecord[(this+coverage).get_coverage (c->buffer->cur().codepoint)]; + if (!this_record.exitAnchor) return TRACE_RETURN (false); + + if (!skippy_iter.next ()) return TRACE_RETURN (false); + + const EntryExitRecord &next_record = entryExitRecord[(this+coverage).get_coverage (c->buffer->info[skippy_iter.idx].codepoint)]; + if (!next_record.entryAnchor) return TRACE_RETURN (false); + + unsigned int i = c->buffer->idx; + unsigned int j = skippy_iter.idx; + + hb_position_t entry_x, entry_y, exit_x, exit_y; + (this+this_record.exitAnchor).get_anchor (c->font, c->buffer->info[i].codepoint, &exit_x, &exit_y); + (this+next_record.entryAnchor).get_anchor (c->font, c->buffer->info[j].codepoint, &entry_x, &entry_y); + + hb_glyph_position_t *pos = c->buffer->pos; + + hb_position_t d; + /* Main-direction adjustment */ + switch (c->direction) { + case HB_DIRECTION_LTR: + pos[i].x_advance = exit_x + pos[i].x_offset; + + d = entry_x + pos[j].x_offset; + pos[j].x_advance -= d; + pos[j].x_offset -= d; + break; + case HB_DIRECTION_RTL: + d = exit_x + pos[i].x_offset; + pos[i].x_advance -= d; + pos[i].x_offset -= d; + + pos[j].x_advance = entry_x + pos[j].x_offset; + break; + case HB_DIRECTION_TTB: + pos[i].y_advance = exit_y + pos[i].y_offset; + + d = entry_y + pos[j].y_offset; + pos[j].y_advance -= d; + pos[j].y_offset -= d; + break; + case HB_DIRECTION_BTT: + d = exit_y + pos[i].y_offset; + pos[i].y_advance -= d; + pos[i].y_offset -= d; + + pos[j].y_advance = entry_y; + break; + case HB_DIRECTION_INVALID: + default: + break; + } + + /* Cross-direction adjustment */ + if (c->lookup_props & LookupFlag::RightToLeft) { + pos[i].cursive_chain() = j - i; + if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction))) + pos[i].y_offset = entry_y - exit_y; + else + pos[i].x_offset = entry_x - exit_x; + } else { + pos[j].cursive_chain() = i - j; + if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction))) + pos[j].y_offset = exit_y - entry_y; + else + pos[j].x_offset = exit_x - entry_x; + } + + c->buffer->idx = j; + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && entryExitRecord.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of subtable */ + ArrayOf<EntryExitRecord> + entryExitRecord; /* Array of EntryExit records--in + * Coverage Index order */ + public: + DEFINE_SIZE_ARRAY (6, entryExitRecord); +}; + +struct CursivePos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + CursivePosFormat1 format1; + } u; +}; + + +typedef AnchorMatrix BaseArray; /* base-major-- + * in order of BaseCoverage Index--, + * mark-minor-- + * ordered by class--zero-based. */ + +struct MarkBasePosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+markCoverage).add_coverage (c->input); + (this+baseCoverage).add_coverage (c->input); + /* TODO only add combinations that have nonzero adjustment. */ + } + + inline const Coverage &get_coverage (void) const + { + return this+markCoverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int mark_index = (this+markCoverage).get_coverage (c->buffer->cur().codepoint); + if (likely (mark_index == NOT_COVERED)) return TRACE_RETURN (false); + + /* now we search backwards for a non-mark glyph */ + unsigned int property; + hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->idx, 1); + do { + if (!skippy_iter.prev (&property, LookupFlag::IgnoreMarks)) return TRACE_RETURN (false); + /* We only want to attach to the first of a MultipleSubst sequence. Reject others. */ + if (0 == get_lig_comp (c->buffer->info[skippy_iter.idx])) break; + skippy_iter.reject (); + } while (1); + + /* The following assertion is too strong, so we've disabled it. */ + if (!(property & HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH)) {/*return TRACE_RETURN (false);*/} + + unsigned int base_index = (this+baseCoverage).get_coverage (c->buffer->info[skippy_iter.idx].codepoint); + if (base_index == NOT_COVERED) return TRACE_RETURN (false); + + return TRACE_RETURN ((this+markArray).apply (c, mark_index, base_index, this+baseArray, classCount, skippy_iter.idx)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && baseCoverage.sanitize (c, this) && + markArray.sanitize (c, this) && baseArray.sanitize (c, this, (unsigned int) classCount)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + markCoverage; /* Offset to MarkCoverage table--from + * beginning of MarkBasePos subtable */ + OffsetTo<Coverage> + baseCoverage; /* Offset to BaseCoverage table--from + * beginning of MarkBasePos subtable */ + USHORT classCount; /* Number of classes defined for marks */ + OffsetTo<MarkArray> + markArray; /* Offset to MarkArray table--from + * beginning of MarkBasePos subtable */ + OffsetTo<BaseArray> + baseArray; /* Offset to BaseArray table--from + * beginning of MarkBasePos subtable */ + public: + DEFINE_SIZE_STATIC (12); +}; + +struct MarkBasePos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + MarkBasePosFormat1 format1; + } u; +}; + + +typedef AnchorMatrix LigatureAttach; /* component-major-- + * in order of writing direction--, + * mark-minor-- + * ordered by class--zero-based. */ + +typedef OffsetListOf<LigatureAttach> LigatureArray; + /* Array of LigatureAttach + * tables ordered by + * LigatureCoverage Index */ + +struct MarkLigPosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+markCoverage).add_coverage (c->input); + (this+ligatureCoverage).add_coverage (c->input); + /* TODO only add combinations that have nonzero adjustment. */ + } + + inline const Coverage &get_coverage (void) const + { + return this+markCoverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int mark_index = (this+markCoverage).get_coverage (c->buffer->cur().codepoint); + if (likely (mark_index == NOT_COVERED)) return TRACE_RETURN (false); + + /* now we search backwards for a non-mark glyph */ + unsigned int property; + hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->idx, 1); + if (!skippy_iter.prev (&property, LookupFlag::IgnoreMarks)) return TRACE_RETURN (false); + + /* The following assertion is too strong, so we've disabled it. */ + if (!(property & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE)) {/*return TRACE_RETURN (false);*/} + + unsigned int j = skippy_iter.idx; + unsigned int lig_index = (this+ligatureCoverage).get_coverage (c->buffer->info[j].codepoint); + if (lig_index == NOT_COVERED) return TRACE_RETURN (false); + + const LigatureArray& lig_array = this+ligatureArray; + const LigatureAttach& lig_attach = lig_array[lig_index]; + + /* Find component to attach to */ + unsigned int comp_count = lig_attach.rows; + if (unlikely (!comp_count)) return TRACE_RETURN (false); + + /* We must now check whether the ligature ID of the current mark glyph + * is identical to the ligature ID of the found ligature. If yes, we + * can directly use the component index. If not, we attach the mark + * glyph to the last component of the ligature. */ + unsigned int comp_index; + unsigned int lig_id = get_lig_id (c->buffer->info[j]); + unsigned int mark_id = get_lig_id (c->buffer->cur()); + unsigned int mark_comp = get_lig_comp (c->buffer->cur()); + if (lig_id && lig_id == mark_id && mark_comp > 0) + comp_index = MIN (comp_count, get_lig_comp (c->buffer->cur())) - 1; + else + comp_index = comp_count - 1; + + return TRACE_RETURN ((this+markArray).apply (c, mark_index, comp_index, lig_attach, classCount, j)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && markCoverage.sanitize (c, this) && ligatureCoverage.sanitize (c, this) && + markArray.sanitize (c, this) && ligatureArray.sanitize (c, this, (unsigned int) classCount)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + markCoverage; /* Offset to Mark Coverage table--from + * beginning of MarkLigPos subtable */ + OffsetTo<Coverage> + ligatureCoverage; /* Offset to Ligature Coverage + * table--from beginning of MarkLigPos + * subtable */ + USHORT classCount; /* Number of defined mark classes */ + OffsetTo<MarkArray> + markArray; /* Offset to MarkArray table--from + * beginning of MarkLigPos subtable */ + OffsetTo<LigatureArray> + ligatureArray; /* Offset to LigatureArray table--from + * beginning of MarkLigPos subtable */ + public: + DEFINE_SIZE_STATIC (12); +}; + +struct MarkLigPos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + MarkLigPosFormat1 format1; + } u; +}; + + +typedef AnchorMatrix Mark2Array; /* mark2-major-- + * in order of Mark2Coverage Index--, + * mark1-minor-- + * ordered by class--zero-based. */ + +struct MarkMarkPosFormat1 +{ + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+mark1Coverage).add_coverage (c->input); + (this+mark2Coverage).add_coverage (c->input); + /* TODO only add combinations that have nonzero adjustment. */ + } + + inline const Coverage &get_coverage (void) const + { + return this+mark1Coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int mark1_index = (this+mark1Coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (mark1_index == NOT_COVERED)) return TRACE_RETURN (false); + + /* now we search backwards for a suitable mark glyph until a non-mark glyph */ + unsigned int property; + hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->idx, 1); + if (!skippy_iter.prev (&property)) return TRACE_RETURN (false); + + if (!(property & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) return TRACE_RETURN (false); + + unsigned int j = skippy_iter.idx; + + unsigned int id1 = get_lig_id (c->buffer->cur()); + unsigned int id2 = get_lig_id (c->buffer->info[j]); + unsigned int comp1 = get_lig_comp (c->buffer->cur()); + unsigned int comp2 = get_lig_comp (c->buffer->info[j]); + + if (likely (id1 == id2)) { + if (id1 == 0) /* Marks belonging to the same base. */ + goto good; + else if (comp1 == comp2) /* Marks belonging to the same ligature component. */ + goto good; + } else { + /* If ligature ids don't match, it may be the case that one of the marks + * itself is a ligature. In which case match. */ + if ((id1 > 0 && !comp1) || (id2 > 0 && !comp2)) + goto good; + } + + /* Didn't match. */ + return TRACE_RETURN (false); + + good: + unsigned int mark2_index = (this+mark2Coverage).get_coverage (c->buffer->info[j].codepoint); + if (mark2_index == NOT_COVERED) return TRACE_RETURN (false); + + return TRACE_RETURN ((this+mark1Array).apply (c, mark1_index, mark2_index, this+mark2Array, classCount, j)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && mark1Coverage.sanitize (c, this) && + mark2Coverage.sanitize (c, this) && mark1Array.sanitize (c, this) + && mark2Array.sanitize (c, this, (unsigned int) classCount)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + mark1Coverage; /* Offset to Combining Mark1 Coverage + * table--from beginning of MarkMarkPos + * subtable */ + OffsetTo<Coverage> + mark2Coverage; /* Offset to Combining Mark2 Coverage + * table--from beginning of MarkMarkPos + * subtable */ + USHORT classCount; /* Number of defined mark classes */ + OffsetTo<MarkArray> + mark1Array; /* Offset to Mark1Array table--from + * beginning of MarkMarkPos subtable */ + OffsetTo<Mark2Array> + mark2Array; /* Offset to Mark2Array table--from + * beginning of MarkMarkPos subtable */ + public: + DEFINE_SIZE_STATIC (12); +}; + +struct MarkMarkPos +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + MarkMarkPosFormat1 format1; + } u; +}; + + +struct ContextPos : Context {}; + +struct ChainContextPos : ChainContext {}; + +struct ExtensionPos : Extension<ExtensionPos> +{ + typedef struct PosLookupSubTable LookupSubTable; +}; + + + +/* + * PosLookup + */ + + +struct PosLookupSubTable +{ + friend struct PosLookup; + + enum Type { + Single = 1, + Pair = 2, + Cursive = 3, + MarkBase = 4, + MarkLig = 5, + MarkMark = 6, + Context = 7, + ChainContext = 8, + Extension = 9 + }; + + template <typename context_t> + inline typename context_t::return_t process (context_t *c, unsigned int lookup_type) const + { + TRACE_PROCESS (this); + switch (lookup_type) { + case Single: return TRACE_RETURN (u.single.process (c)); + case Pair: return TRACE_RETURN (u.pair.process (c)); + case Cursive: return TRACE_RETURN (u.cursive.process (c)); + case MarkBase: return TRACE_RETURN (u.markBase.process (c)); + case MarkLig: return TRACE_RETURN (u.markLig.process (c)); + case MarkMark: return TRACE_RETURN (u.markMark.process (c)); + case Context: return TRACE_RETURN (u.context.process (c)); + case ChainContext: return TRACE_RETURN (u.chainContext.process (c)); + case Extension: return TRACE_RETURN (u.extension.process (c)); + default: return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) { + TRACE_SANITIZE (this); + if (!u.header.sub_format.sanitize (c)) + return TRACE_RETURN (false); + switch (lookup_type) { + case Single: return TRACE_RETURN (u.single.sanitize (c)); + case Pair: return TRACE_RETURN (u.pair.sanitize (c)); + case Cursive: return TRACE_RETURN (u.cursive.sanitize (c)); + case MarkBase: return TRACE_RETURN (u.markBase.sanitize (c)); + case MarkLig: return TRACE_RETURN (u.markLig.sanitize (c)); + case MarkMark: return TRACE_RETURN (u.markMark.sanitize (c)); + case Context: return TRACE_RETURN (u.context.sanitize (c)); + case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c)); + case Extension: return TRACE_RETURN (u.extension.sanitize (c)); + default: return TRACE_RETURN (true); + } + } + + protected: + union { + struct { + USHORT sub_format; + } header; + SinglePos single; + PairPos pair; + CursivePos cursive; + MarkBasePos markBase; + MarkLigPos markLig; + MarkMarkPos markMark; + ContextPos context; + ChainContextPos chainContext; + ExtensionPos extension; + } u; + public: + DEFINE_SIZE_UNION (2, header.sub_format); +}; + + +struct PosLookup : Lookup +{ + inline const PosLookupSubTable& get_subtable (unsigned int i) const + { return this+CastR<OffsetArrayOf<PosLookupSubTable> > (subTable)[i]; } + + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + unsigned int lookup_type = get_type (); + unsigned int count = get_subtable_count (); + for (unsigned int i = 0; i < count; i++) { + typename context_t::return_t r = get_subtable (i).process (c, lookup_type); + if (c->stop_sublookup_iteration (r)) + return TRACE_RETURN (r); + } + return TRACE_RETURN (c->default_return_value ()); + } + template <typename context_t> + static inline typename context_t::return_t process_recurse_func (context_t *c, unsigned int lookup_index); + + inline hb_collect_glyphs_context_t::return_t collect_glyphs_lookup (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + c->set_recurse_func (NULL); + return TRACE_RETURN (process (c)); + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const + { + hb_get_coverage_context_t c; + const Coverage *last = NULL; + unsigned int count = get_subtable_count (); + for (unsigned int i = 0; i < count; i++) { + const Coverage *coverage = &get_subtable (i).process (&c, get_type ()); + if (coverage != last) { + coverage->add_coverage (glyphs); + last = coverage; + } + } + } + + inline bool apply_once (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + if (!c->check_glyph_property (&c->buffer->cur(), c->lookup_props, &c->property)) + return TRACE_RETURN (false); + return TRACE_RETURN (process (c)); + } + + static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index); + + inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const + { + bool ret = false; + + if (unlikely (!c->buffer->len || !c->lookup_mask)) + return false; + + c->set_recurse_func (apply_recurse_func); + c->set_lookup (*this); + + c->buffer->idx = 0; + + while (c->buffer->idx < c->buffer->len) + { + if ((c->buffer->cur().mask & c->lookup_mask) && + digest->may_have (c->buffer->cur().codepoint) && + apply_once (c)) + ret = true; + else + c->buffer->idx++; + } + + return ret; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false); + OffsetArrayOf<PosLookupSubTable> &list = CastR<OffsetArrayOf<PosLookupSubTable> > (subTable); + return TRACE_RETURN (list.sanitize (c, this, get_type ())); + } +}; + +typedef OffsetListOf<PosLookup> PosLookupList; + +/* + * GPOS -- The Glyph Positioning Table + */ + +struct GPOS : GSUBGPOS +{ + static const hb_tag_t Tag = HB_OT_TAG_GPOS; + + inline const PosLookup& get_lookup (unsigned int i) const + { return CastR<PosLookup> (GSUBGPOS::get_lookup (i)); } + + static inline void position_start (hb_font_t *font, hb_buffer_t *buffer); + static inline void position_finish (hb_font_t *font, hb_buffer_t *buffer, hb_bool_t zero_width_attahced_marks); + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false); + OffsetTo<PosLookupList> &list = CastR<OffsetTo<PosLookupList> > (lookupList); + return TRACE_RETURN (list.sanitize (c, this)); + } + public: + DEFINE_SIZE_STATIC (10); +}; + + +static void +fix_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction) +{ + unsigned int j = pos[i].cursive_chain(); + if (likely (!j)) + return; + + j += i; + + pos[i].cursive_chain() = 0; + + fix_cursive_minor_offset (pos, j, direction); + + if (HB_DIRECTION_IS_HORIZONTAL (direction)) + pos[i].y_offset += pos[j].y_offset; + else + pos[i].x_offset += pos[j].x_offset; +} + +static void +fix_mark_attachment (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction, hb_bool_t zero_width_attached_marks) +{ + if (likely (!(pos[i].attach_lookback()))) + return; + + unsigned int j = i - pos[i].attach_lookback(); + + if (zero_width_attached_marks) { + pos[i].x_advance = 0; + pos[i].y_advance = 0; + } + pos[i].x_offset += pos[j].x_offset; + pos[i].y_offset += pos[j].y_offset; + + if (HB_DIRECTION_IS_FORWARD (direction)) + for (unsigned int k = j; k < i; k++) { + pos[i].x_offset -= pos[k].x_advance; + pos[i].y_offset -= pos[k].y_advance; + } + else + for (unsigned int k = j + 1; k < i + 1; k++) { + pos[i].x_offset += pos[k].x_advance; + pos[i].y_offset += pos[k].y_advance; + } +} + +void +GPOS::position_start (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) +{ + buffer->clear_positions (); + + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + buffer->pos[i].attach_lookback() = buffer->pos[i].cursive_chain() = 0; +} + +void +GPOS::position_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer, hb_bool_t zero_width_attached_marks) +{ + unsigned int len; + hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len); + hb_direction_t direction = buffer->props.direction; + + /* Handle cursive connections */ + for (unsigned int i = 0; i < len; i++) + fix_cursive_minor_offset (pos, i, direction); + + /* Handle attachments */ + for (unsigned int i = 0; i < len; i++) + fix_mark_attachment (pos, i, direction, zero_width_attached_marks); + + HB_BUFFER_DEALLOCATE_VAR (buffer, syllable); + HB_BUFFER_DEALLOCATE_VAR (buffer, lig_props); + HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_props); +} + + +/* Out-of-class implementation for methods recursing */ + +template <typename context_t> +inline typename context_t::return_t PosLookup::process_recurse_func (context_t *c, unsigned int lookup_index) +{ + const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos); + const PosLookup &l = gpos.get_lookup (lookup_index); + return l.process (c); +} + +inline bool PosLookup::apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index) +{ + const GPOS &gpos = *(hb_ot_layout_from_face (c->face)->gpos); + const PosLookup &l = gpos.get_lookup (lookup_index); + unsigned int saved_lookup_props = c->lookup_props; + unsigned int saved_property = c->property; + c->set_lookup (l); + bool ret = l.apply_once (c); + c->lookup_props = saved_lookup_props; + c->property = saved_property; + return ret; +} + + +#undef attach_lookback +#undef cursive_chain + + +} /* namespace OT */ + + +#endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsub-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsub-table.hh new file mode 100644 index 00000000000..2642acbbb5c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsub-table.hh @@ -0,0 +1,1414 @@ +/* + * Copyright © 2007,2008,2009,2010 Red Hat, Inc. + * Copyright © 2010,2012 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_OT_LAYOUT_GSUB_TABLE_HH +#define HB_OT_LAYOUT_GSUB_TABLE_HH + +#include "hb-ot-layout-gsubgpos-private.hh" + + +namespace OT { + + +struct SingleSubstFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + hb_codepoint_t glyph_id = iter.get_glyph (); + if (c->glyphs->has (glyph_id)) + c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFF); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + hb_codepoint_t glyph_id = iter.get_glyph (); + c->input->add (glyph_id); + c->output->add ((glyph_id + deltaGlyphID) & 0xFFFF); + } + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_codepoint_t glyph_id = c->buffer->cur().codepoint; + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + /* According to the Adobe Annotated OpenType Suite, result is always + * limited to 16bit. */ + glyph_id = (glyph_id + deltaGlyphID) & 0xFFFF; + c->replace_glyph (glyph_id); + + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + unsigned int num_glyphs, + int delta) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); + deltaGlyphID.set (delta); /* TODO(serilaize) overflow? */ + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of Substitution table */ + SHORT deltaGlyphID; /* Add to original GlyphID to get + * substitute GlyphID */ + public: + DEFINE_SIZE_STATIC (6); +}; + +struct SingleSubstFormat2 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + if (c->glyphs->has (iter.get_glyph ())) + c->glyphs->add (substitute[iter.get_coverage ()]); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + c->input->add (iter.get_glyph ()); + c->output->add (substitute[iter.get_coverage ()]); + } + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_codepoint_t glyph_id = c->buffer->cur().codepoint; + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + if (unlikely (index >= substitute.len)) return TRACE_RETURN (false); + + glyph_id = substitute[index]; + c->replace_glyph (glyph_id); + + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<GlyphID> &substitutes, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!substitute.serialize (c, substitutes, num_glyphs))) return TRACE_RETURN (false); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of Substitution table */ + ArrayOf<GlyphID> + substitute; /* Array of substitute + * GlyphIDs--ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, substitute); +}; + +struct SingleSubst +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + case 2: return TRACE_RETURN (c->process (u.format2)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<GlyphID> &substitutes, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); + unsigned int format = 2; + int delta; + if (num_glyphs) { + format = 1; + /* TODO(serialize) check for wrap-around */ + delta = substitutes[0] - glyphs[0]; + for (unsigned int i = 1; i < num_glyphs; i++) + if (delta != substitutes[i] - glyphs[i]) { + format = 2; + break; + } + } + u.format.set (format); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs, delta)); + case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, substitutes, num_glyphs)); + default:return TRACE_RETURN (false); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + SingleSubstFormat1 format1; + SingleSubstFormat2 format2; + } u; +}; + + +struct Sequence +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + unsigned int count = substitute.len; + for (unsigned int i = 0; i < count; i++) + c->glyphs->add (substitute[i]); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int count = substitute.len; + for (unsigned int i = 0; i < count; i++) + c->output->add (substitute[i]); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + if (unlikely (!substitute.len)) return TRACE_RETURN (false); + + unsigned int klass = c->property & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE ? HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH : 0; + unsigned int count = substitute.len; + for (unsigned int i = 0; i < count; i++) { + set_lig_props_for_component (c->buffer->cur(), i); + c->output_glyph (substitute.array[i], klass); + } + c->buffer->skip_glyph (); + + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!substitute.serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (substitute.sanitize (c)); + } + + protected: + ArrayOf<GlyphID> + substitute; /* String of GlyphIDs to substitute */ + public: + DEFINE_SIZE_ARRAY (2, substitute); +}; + +struct MultipleSubstFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + if (c->glyphs->has (iter.get_glyph ())) + (this+sequence[iter.get_coverage ()]).closure (c); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + unsigned int count = sequence.len; + for (unsigned int i = 0; i < count; i++) + (this+sequence[i]).collect_glyphs (c); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + return TRACE_RETURN ((this+sequence[index]).apply (c)); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &substitute_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &substitute_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!sequence.serialize (c, num_glyphs))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < num_glyphs; i++) + if (unlikely (!sequence[i].serialize (c, this).serialize (c, + substitute_glyphs_list, + substitute_len_list[i]))) return TRACE_RETURN (false); + substitute_len_list.advance (num_glyphs); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && sequence.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of Substitution table */ + OffsetArrayOf<Sequence> + sequence; /* Array of Sequence tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, sequence); +}; + +struct MultipleSubst +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &substitute_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &substitute_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); + unsigned int format = 1; + u.format.set (format); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, substitute_len_list, num_glyphs, substitute_glyphs_list)); + default:return TRACE_RETURN (false); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + MultipleSubstFormat1 format1; + } u; +}; + + +typedef ArrayOf<GlyphID> AlternateSet; /* Array of alternate GlyphIDs--in + * arbitrary order */ + +struct AlternateSubstFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + if (c->glyphs->has (iter.get_glyph ())) { + 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]); + } + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + c->input->add (iter.get_glyph ()); + const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()]; + unsigned int count = alt_set.len; + for (unsigned int i = 0; i < count; i++) + c->output->add (alt_set[i]); + } + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_codepoint_t glyph_id = c->buffer->cur().codepoint; + + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const AlternateSet &alt_set = this+alternateSet[index]; + + if (unlikely (!alt_set.len)) return TRACE_RETURN (false); + + hb_mask_t glyph_mask = c->buffer->cur().mask; + 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 alt_index = ((lookup_mask & glyph_mask) >> shift); + + if (unlikely (alt_index > alt_set.len || alt_index == 0)) return TRACE_RETURN (false); + + glyph_id = alt_set[alt_index - 1]; + + c->replace_glyph (glyph_id); + + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &alternate_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &alternate_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!alternateSet.serialize (c, num_glyphs))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < num_glyphs; i++) + if (unlikely (!alternateSet[i].serialize (c, this).serialize (c, + alternate_glyphs_list, + alternate_len_list[i]))) return TRACE_RETURN (false); + alternate_len_list.advance (num_glyphs); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && alternateSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of Substitution table */ + OffsetArrayOf<AlternateSet> + alternateSet; /* Array of AlternateSet tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, alternateSet); +}; + +struct AlternateSubst +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &alternate_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &alternate_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); + unsigned int format = 1; + u.format.set (format); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, alternate_len_list, num_glyphs, alternate_glyphs_list)); + default:return TRACE_RETURN (false); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + AlternateSubstFormat1 format1; + } u; +}; + + +struct Ligature +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + unsigned int count = component.len; + for (unsigned int i = 1; i < count; i++) + if (!c->glyphs->has (component[i])) + return; + c->glyphs->add (ligGlyph); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int count = component.len; + for (unsigned int i = 1; i < count; i++) + c->input->add (component[i]); + c->output->add (ligGlyph); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + if (c->len != component.len) + return TRACE_RETURN (false); + + for (unsigned int i = 1; i < c->len; i++) + if (likely (c->glyphs[i] != component[i])) + return TRACE_RETURN (false); + + return TRACE_RETURN (true); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int count = component.len; + if (unlikely (count < 1)) return TRACE_RETURN (false); + + unsigned int end_offset = 0; + bool is_mark_ligature = false; + unsigned int total_component_count = 0; + + if (likely (!match_input (c, count, + &component[1], + match_glyph, + NULL, + &end_offset, + &is_mark_ligature, + &total_component_count))) + return TRACE_RETURN (false); + + /* Deal, we are forming the ligature. */ + c->buffer->merge_clusters (c->buffer->idx, c->buffer->idx + end_offset); + + ligate_input (c, + count, + &component[1], + ligGlyph, + match_glyph, + NULL, + is_mark_ligature, + total_component_count); + + return TRACE_RETURN (true); + } + + inline bool serialize (hb_serialize_context_t *c, + GlyphID ligature, + Supplier<GlyphID> &components, /* Starting from second */ + unsigned int num_components /* Including first component */) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + ligGlyph = ligature; + if (unlikely (!component.serialize (c, components, num_components))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + public: + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (ligGlyph.sanitize (c) && component.sanitize (c)); + } + + protected: + GlyphID ligGlyph; /* GlyphID of ligature to substitute */ + HeadlessArrayOf<GlyphID> + component; /* Array of component GlyphIDs--start + * with the second component--ordered + * in writing direction */ + public: + DEFINE_SIZE_ARRAY (4, component); +}; + +struct LigatureSet +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + unsigned int num_ligs = ligature.len; + for (unsigned int i = 0; i < num_ligs; i++) + (this+ligature[i]).closure (c); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int num_ligs = ligature.len; + for (unsigned int i = 0; i < num_ligs; i++) + (this+ligature[i]).collect_glyphs (c); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + unsigned int num_ligs = ligature.len; + for (unsigned int i = 0; i < num_ligs; i++) + { + const Ligature &lig = this+ligature[i]; + if (lig.would_apply (c)) + return TRACE_RETURN (true); + } + return TRACE_RETURN (false); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int num_ligs = ligature.len; + for (unsigned int i = 0; i < num_ligs; i++) + { + const Ligature &lig = this+ligature[i]; + if (lig.apply (c)) return TRACE_RETURN (true); + } + + return TRACE_RETURN (false); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &ligatures, + Supplier<unsigned int> &component_count_list, + unsigned int num_ligatures, + Supplier<GlyphID> &component_list /* Starting from second for each ligature */) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!ligature.serialize (c, num_ligatures))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < num_ligatures; i++) + if (unlikely (!ligature[i].serialize (c, this).serialize (c, + ligatures[i], + component_list, + component_count_list[i]))) return TRACE_RETURN (false); + ligatures.advance (num_ligatures); + component_count_list.advance (num_ligatures); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (ligature.sanitize (c, this)); + } + + protected: + OffsetArrayOf<Ligature> + ligature; /* Array LigatureSet tables + * ordered by preference */ + public: + DEFINE_SIZE_ARRAY (2, ligature); +}; + +struct LigatureSubstFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + if (c->glyphs->has (iter.get_glyph ())) + (this+ligatureSet[iter.get_coverage ()]).closure (c); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + c->input->add (iter.get_glyph ()); + (this+ligatureSet[iter.get_coverage ()]).collect_glyphs (c); + } + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->glyphs[0]); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const LigatureSet &lig_set = this+ligatureSet[index]; + return TRACE_RETURN (lig_set.would_apply (c)); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_codepoint_t glyph_id = c->buffer->cur().codepoint; + + unsigned int index = (this+coverage).get_coverage (glyph_id); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const LigatureSet &lig_set = this+ligatureSet[index]; + return TRACE_RETURN (lig_set.apply (c)); + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &first_glyphs, + Supplier<unsigned int> &ligature_per_first_glyph_count_list, + unsigned int num_first_glyphs, + Supplier<GlyphID> &ligatures_list, + Supplier<unsigned int> &component_count_list, + Supplier<GlyphID> &component_list /* Starting from second for each ligature */) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); + if (unlikely (!ligatureSet.serialize (c, num_first_glyphs))) return TRACE_RETURN (false); + for (unsigned int i = 0; i < num_first_glyphs; i++) + if (unlikely (!ligatureSet[i].serialize (c, this).serialize (c, + ligatures_list, + component_count_list, + ligature_per_first_glyph_count_list[i], + component_list))) return TRACE_RETURN (false); + ligature_per_first_glyph_count_list.advance (num_first_glyphs); + if (unlikely (!coverage.serialize (c, this).serialize (c, first_glyphs, num_first_glyphs))) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of Substitution table */ + OffsetArrayOf<LigatureSet> + ligatureSet; /* Array LigatureSet tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, ligatureSet); +}; + +struct LigatureSubst +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool serialize (hb_serialize_context_t *c, + Supplier<GlyphID> &first_glyphs, + Supplier<unsigned int> &ligature_per_first_glyph_count_list, + unsigned int num_first_glyphs, + Supplier<GlyphID> &ligatures_list, + Supplier<unsigned int> &component_count_list, + Supplier<GlyphID> &component_list /* Starting from second for each ligature */) + { + TRACE_SERIALIZE (this); + if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); + unsigned int format = 1; + u.format.set (format); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs, + ligatures_list, component_count_list, component_list)); + default:return TRACE_RETURN (false); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + LigatureSubstFormat1 format1; + } u; +}; + + +struct ContextSubst : Context {}; + +struct ChainContextSubst : ChainContext {}; + +struct ExtensionSubst : Extension<ExtensionSubst> +{ + typedef struct SubstLookupSubTable LookupSubTable; + + inline bool is_reverse (void) const; +}; + + +struct ReverseChainSingleSubstFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + + unsigned int count; + + count = backtrack.len; + for (unsigned int i = 0; i < count; i++) + if (!(this+backtrack[i]).intersects (c->glyphs)) + return; + + count = lookahead.len; + for (unsigned int i = 0; i < count; i++) + if (!(this+lookahead[i]).intersects (c->glyphs)) + return; + + const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); + Coverage::Iter iter; + for (iter.init (this+coverage); iter.more (); iter.next ()) { + if (c->glyphs->has (iter.get_glyph ())) + c->glyphs->add (substitute[iter.get_coverage ()]); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + + unsigned int count; + + (this+coverage).add_coverage (c->input); + + count = backtrack.len; + for (unsigned int i = 0; i < count; i++) + (this+backtrack[i]).add_coverage (c->before); + + count = lookahead.len; + for (unsigned int i = 0; i < count; i++) + (this+lookahead[i]).add_coverage (c->after); + + const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); + count = substitute.len; + for (unsigned int i = 0; i < count; i++) + c->output->add (substitute[i]); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED); + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + if (unlikely (c->nesting_level_left != MAX_NESTING_LEVEL)) + return TRACE_RETURN (false); /* No chaining to this type */ + + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); + + if (match_backtrack (c, + backtrack.len, (USHORT *) backtrack.array, + match_coverage, this) && + match_lookahead (c, + lookahead.len, (USHORT *) lookahead.array, + match_coverage, this, + 1)) + { + c->replace_glyph_inplace (substitute[index]); + c->buffer->idx--; /* Reverse! */ + return TRACE_RETURN (true); + } + + return TRACE_RETURN (false); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!(coverage.sanitize (c, this) && backtrack.sanitize (c, this))) + return TRACE_RETURN (false); + OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + if (!lookahead.sanitize (c, this)) + return TRACE_RETURN (false); + ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); + return TRACE_RETURN (substitute.sanitize (c)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of table */ + OffsetArrayOf<Coverage> + backtrack; /* Array of coverage tables + * in backtracking sequence, in glyph + * sequence order */ + OffsetArrayOf<Coverage> + lookaheadX; /* Array of coverage tables + * in lookahead sequence, in glyph + * sequence order */ + ArrayOf<GlyphID> + substituteX; /* Array of substitute + * GlyphIDs--ordered by Coverage Index */ + public: + DEFINE_SIZE_MIN (10); +}; + +struct ReverseChainSingleSubst +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + ReverseChainSingleSubstFormat1 format1; + } u; +}; + + + +/* + * SubstLookup + */ + +struct SubstLookupSubTable +{ + friend struct SubstLookup; + + enum Type { + Single = 1, + Multiple = 2, + Alternate = 3, + Ligature = 4, + Context = 5, + ChainContext = 6, + Extension = 7, + ReverseChainSingle = 8 + }; + + template <typename context_t> + inline typename context_t::return_t process (context_t *c, unsigned int lookup_type) const + { + TRACE_PROCESS (this); + switch (lookup_type) { + case Single: return TRACE_RETURN (u.single.process (c)); + case Multiple: return TRACE_RETURN (u.multiple.process (c)); + case Alternate: return TRACE_RETURN (u.alternate.process (c)); + case Ligature: return TRACE_RETURN (u.ligature.process (c)); + case Context: return TRACE_RETURN (u.context.process (c)); + case ChainContext: return TRACE_RETURN (u.chainContext.process (c)); + case Extension: return TRACE_RETURN (u.extension.process (c)); + case ReverseChainSingle: return TRACE_RETURN (u.reverseChainContextSingle.process (c)); + default: return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) { + TRACE_SANITIZE (this); + if (!u.header.sub_format.sanitize (c)) + return TRACE_RETURN (false); + switch (lookup_type) { + case Single: return TRACE_RETURN (u.single.sanitize (c)); + case Multiple: return TRACE_RETURN (u.multiple.sanitize (c)); + case Alternate: return TRACE_RETURN (u.alternate.sanitize (c)); + case Ligature: return TRACE_RETURN (u.ligature.sanitize (c)); + case Context: return TRACE_RETURN (u.context.sanitize (c)); + case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c)); + case Extension: return TRACE_RETURN (u.extension.sanitize (c)); + case ReverseChainSingle: return TRACE_RETURN (u.reverseChainContextSingle.sanitize (c)); + default: return TRACE_RETURN (true); + } + } + + protected: + union { + struct { + USHORT sub_format; + } header; + SingleSubst single; + MultipleSubst multiple; + AlternateSubst alternate; + LigatureSubst ligature; + ContextSubst context; + ChainContextSubst chainContext; + ExtensionSubst extension; + ReverseChainSingleSubst reverseChainContextSingle; + } u; + public: + DEFINE_SIZE_UNION (2, header.sub_format); +}; + + +struct SubstLookup : Lookup +{ + inline const SubstLookupSubTable& get_subtable (unsigned int i) const + { return this+CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i]; } + + inline static bool lookup_type_is_reverse (unsigned int lookup_type) + { return lookup_type == SubstLookupSubTable::ReverseChainSingle; } + + inline bool is_reverse (void) const + { + unsigned int type = get_type (); + if (unlikely (type == SubstLookupSubTable::Extension)) + return CastR<ExtensionSubst> (get_subtable(0)).is_reverse (); + return lookup_type_is_reverse (type); + } + + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + unsigned int lookup_type = get_type (); + unsigned int count = get_subtable_count (); + for (unsigned int i = 0; i < count; i++) { + typename context_t::return_t r = get_subtable (i).process (c, lookup_type); + if (c->stop_sublookup_iteration (r)) + return TRACE_RETURN (r); + } + return TRACE_RETURN (c->default_return_value ()); + } + template <typename context_t> + static inline typename context_t::return_t process_recurse_func (context_t *c, unsigned int lookup_index); + + inline hb_closure_context_t::return_t closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + c->set_recurse_func (process_recurse_func<hb_closure_context_t>); + return TRACE_RETURN (process (c)); + } + + inline hb_collect_glyphs_context_t::return_t collect_glyphs_lookup (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + c->set_recurse_func (process_recurse_func<hb_collect_glyphs_context_t>); + return TRACE_RETURN (process (c)); + } + + template <typename set_t> + inline void add_coverage (set_t *glyphs) const + { + hb_get_coverage_context_t c; + const Coverage *last = NULL; + unsigned int count = get_subtable_count (); + for (unsigned int i = 0; i < count; i++) { + const Coverage *coverage = &get_subtable (i).process (&c, get_type ()); + if (coverage != last) { + coverage->add_coverage (glyphs); + last = coverage; + } + } + } + + inline bool would_apply (hb_would_apply_context_t *c, const hb_set_digest_t *digest) const + { + TRACE_WOULD_APPLY (this); + if (unlikely (!c->len)) return TRACE_RETURN (false); + if (!digest->may_have (c->glyphs[0])) return TRACE_RETURN (false); + return TRACE_RETURN (process (c)); + } + + inline bool apply_once (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + if (!c->check_glyph_property (&c->buffer->cur(), c->lookup_props, &c->property)) + return TRACE_RETURN (false); + return TRACE_RETURN (process (c)); + } + + static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index); + inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const + { + bool ret = false; + + if (unlikely (!c->buffer->len || !c->lookup_mask)) + return false; + + c->set_recurse_func (apply_recurse_func); + c->set_lookup (*this); + + if (likely (!is_reverse ())) + { + /* in/out forward substitution */ + c->buffer->clear_output (); + c->buffer->idx = 0; + + while (c->buffer->idx < c->buffer->len) + { + if ((c->buffer->cur().mask & c->lookup_mask) && + digest->may_have (c->buffer->cur().codepoint) && + apply_once (c)) + ret = true; + else + c->buffer->next_glyph (); + } + if (ret) + c->buffer->swap_buffers (); + } + else + { + /* in-place backward substitution */ + c->buffer->remove_output (); + c->buffer->idx = c->buffer->len - 1; + do + { + if ((c->buffer->cur().mask & c->lookup_mask) && + digest->may_have (c->buffer->cur().codepoint) && + apply_once (c)) + ret = true; + else + c->buffer->idx--; + + } + while ((int) c->buffer->idx >= 0); + } + + return ret; + } + + inline SubstLookupSubTable& serialize_subtable (hb_serialize_context_t *c, + unsigned int i) + { return CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i].serialize (c, this); } + + inline bool serialize_single (hb_serialize_context_t *c, + uint32_t lookup_props, + Supplier<GlyphID> &glyphs, + Supplier<GlyphID> &substitutes, + unsigned int num_glyphs) + { + TRACE_SERIALIZE (this); + if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Single, lookup_props, 1))) return TRACE_RETURN (false); + return TRACE_RETURN (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes, num_glyphs)); + } + + inline bool serialize_multiple (hb_serialize_context_t *c, + uint32_t lookup_props, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &substitute_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &substitute_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Multiple, lookup_props, 1))) return TRACE_RETURN (false); + return TRACE_RETURN (serialize_subtable (c, 0).u.multiple.serialize (c, glyphs, substitute_len_list, num_glyphs, + substitute_glyphs_list)); + } + + inline bool serialize_alternate (hb_serialize_context_t *c, + uint32_t lookup_props, + Supplier<GlyphID> &glyphs, + Supplier<unsigned int> &alternate_len_list, + unsigned int num_glyphs, + Supplier<GlyphID> &alternate_glyphs_list) + { + TRACE_SERIALIZE (this); + if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Alternate, lookup_props, 1))) return TRACE_RETURN (false); + return TRACE_RETURN (serialize_subtable (c, 0).u.alternate.serialize (c, glyphs, alternate_len_list, num_glyphs, + alternate_glyphs_list)); + } + + inline bool serialize_ligature (hb_serialize_context_t *c, + uint32_t lookup_props, + Supplier<GlyphID> &first_glyphs, + Supplier<unsigned int> &ligature_per_first_glyph_count_list, + unsigned int num_first_glyphs, + Supplier<GlyphID> &ligatures_list, + Supplier<unsigned int> &component_count_list, + Supplier<GlyphID> &component_list /* Starting from second for each ligature */) + { + TRACE_SERIALIZE (this); + if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Ligature, lookup_props, 1))) return TRACE_RETURN (false); + return TRACE_RETURN (serialize_subtable (c, 0).u.ligature.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs, + ligatures_list, component_count_list, component_list)); + } + + inline bool sanitize (hb_sanitize_context_t *c) + { + TRACE_SANITIZE (this); + if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false); + OffsetArrayOf<SubstLookupSubTable> &list = CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable); + if (unlikely (!list.sanitize (c, this, get_type ()))) return TRACE_RETURN (false); + + if (unlikely (get_type () == SubstLookupSubTable::Extension)) + { + /* The spec says all subtables of an Extension lookup should + * have the same type. This is specially important if one has + * a reverse type! + * + * We just check that they are all either forward, or reverse. */ + unsigned int type = get_subtable (0).u.extension.get_type (); + unsigned int count = get_subtable_count (); + for (unsigned int i = 1; i < count; i++) + if (get_subtable (i).u.extension.get_type () != type) + return TRACE_RETURN (false); + } + return TRACE_RETURN (true); + } +}; + +typedef OffsetListOf<SubstLookup> SubstLookupList; + +/* + * GSUB -- The Glyph Substitution Table + */ + +struct GSUB : GSUBGPOS +{ + static const hb_tag_t Tag = HB_OT_TAG_GSUB; + + inline const SubstLookup& get_lookup (unsigned int i) const + { return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); } + + static inline void substitute_start (hb_font_t *font, hb_buffer_t *buffer); + static inline void substitute_finish (hb_font_t *font, hb_buffer_t *buffer); + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false); + OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList); + return TRACE_RETURN (list.sanitize (c, this)); + } + public: + DEFINE_SIZE_STATIC (10); +}; + + +void +GSUB::substitute_start (hb_font_t *font, hb_buffer_t *buffer) +{ + HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props); + HB_BUFFER_ALLOCATE_VAR (buffer, lig_props); + HB_BUFFER_ALLOCATE_VAR (buffer, syllable); + + const GDEF &gdef = *hb_ot_layout_from_face (font->face)->gdef; + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) { + buffer->info[i].lig_props() = buffer->info[i].syllable() = 0; + buffer->info[i].glyph_props() = gdef.get_glyph_props (buffer->info[i].codepoint); + } +} + +void +GSUB::substitute_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer HB_UNUSED) +{ +} + + +/* Out-of-class implementation for methods recursing */ + +inline bool ExtensionSubst::is_reverse (void) const +{ + unsigned int type = get_type (); + if (unlikely (type == SubstLookupSubTable::Extension)) + return CastR<ExtensionSubst> (get_subtable<SubstLookupSubTable>()).is_reverse (); + return SubstLookup::lookup_type_is_reverse (type); +} + +template <typename context_t> +inline typename context_t::return_t SubstLookup::process_recurse_func (context_t *c, unsigned int lookup_index) +{ + const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub); + const SubstLookup &l = gsub.get_lookup (lookup_index); + return l.process (c); +} + +inline bool SubstLookup::apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index) +{ + const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub); + const SubstLookup &l = gsub.get_lookup (lookup_index); + unsigned int saved_lookup_props = c->lookup_props; + unsigned int saved_property = c->property; + c->set_lookup (l); + bool ret = l.apply_once (c); + c->lookup_props = saved_lookup_props; + c->property = saved_property; + return ret; +} + + +} /* namespace OT */ + + +#endif /* HB_OT_LAYOUT_GSUB_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsubgpos-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsubgpos-private.hh new file mode 100644 index 00000000000..40be861f39c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-gsubgpos-private.hh @@ -0,0 +1,2146 @@ +/* + * Copyright © 2007,2008,2009,2010 Red Hat, Inc. + * Copyright © 2010,2012 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_OT_LAYOUT_GSUBGPOS_PRIVATE_HH +#define HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH + +#include "hb-buffer-private.hh" +#include "hb-ot-layout-gdef-table.hh" +#include "hb-set-private.hh" + + +namespace OT { + + + +#define TRACE_PROCESS(this) \ + hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + ""); + + +#ifndef HB_DEBUG_CLOSURE +#define HB_DEBUG_CLOSURE (HB_DEBUG+0) +#endif + +#define TRACE_CLOSURE(this) \ + hb_auto_trace_t<HB_DEBUG_CLOSURE, hb_void_t> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + ""); + +struct hb_closure_context_t +{ + inline const char *get_name (void) { return "CLOSURE"; } + static const unsigned int max_debug_depth = HB_DEBUG_CLOSURE; + typedef hb_void_t return_t; + typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); + template <typename T> + inline return_t process (const T &obj) { obj.closure (this); return HB_VOID; } + static return_t default_return_value (void) { return HB_VOID; } + bool stop_sublookup_iteration (const return_t r HB_UNUSED) const { return false; } + return_t recurse (unsigned int lookup_index) + { + if (unlikely (nesting_level_left == 0 || !recurse_func)) + return default_return_value (); + + nesting_level_left--; + recurse_func (this, lookup_index); + nesting_level_left++; + return HB_VOID; + } + + hb_face_t *face; + hb_set_t *glyphs; + recurse_func_t recurse_func; + unsigned int nesting_level_left; + unsigned int debug_depth; + + hb_closure_context_t (hb_face_t *face_, + hb_set_t *glyphs_, + unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : + face (face_), + glyphs (glyphs_), + recurse_func (NULL), + nesting_level_left (nesting_level_left_), + debug_depth (0) {} + + void set_recurse_func (recurse_func_t func) { recurse_func = func; } +}; + + + +#ifndef HB_DEBUG_WOULD_APPLY +#define HB_DEBUG_WOULD_APPLY (HB_DEBUG+0) +#endif + +#define TRACE_WOULD_APPLY(this) \ + hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + "%d glyphs", c->len); + +struct hb_would_apply_context_t +{ + inline const char *get_name (void) { return "WOULD_APPLY"; } + static const unsigned int max_debug_depth = HB_DEBUG_WOULD_APPLY; + typedef bool return_t; + template <typename T> + inline return_t process (const T &obj) { return obj.would_apply (this); } + static return_t default_return_value (void) { return false; } + bool stop_sublookup_iteration (const return_t r) const { return r; } + + hb_face_t *face; + const hb_codepoint_t *glyphs; + unsigned int len; + bool zero_context; + unsigned int debug_depth; + + hb_would_apply_context_t (hb_face_t *face_, + const hb_codepoint_t *glyphs_, + unsigned int len_, + bool zero_context_) : + face (face_), + glyphs (glyphs_), + len (len_), + zero_context (zero_context_), + debug_depth (0) {} +}; + + + +#ifndef HB_DEBUG_COLLECT_GLYPHS +#define HB_DEBUG_COLLECT_GLYPHS (HB_DEBUG+0) +#endif + +#define TRACE_COLLECT_GLYPHS(this) \ + hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, hb_void_t> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + ""); + +struct hb_collect_glyphs_context_t +{ + inline const char *get_name (void) { return "COLLECT_GLYPHS"; } + static const unsigned int max_debug_depth = HB_DEBUG_COLLECT_GLYPHS; + typedef hb_void_t return_t; + typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); + template <typename T> + inline return_t process (const T &obj) { obj.collect_glyphs (this); return HB_VOID; } + static return_t default_return_value (void) { return HB_VOID; } + bool stop_sublookup_iteration (const return_t r HB_UNUSED) const { return false; } + return_t recurse (unsigned int lookup_index) + { + if (unlikely (nesting_level_left == 0 || !recurse_func)) + return default_return_value (); + + /* Note that GPOS sets recurse_func to NULL already, so it doesn't get + * past the previous check. For GSUB, we only want to collect the output + * glyphs in the recursion. If output is not requested, we can go home now. */ + + if (output == hb_set_get_empty ()) + return HB_VOID; + + hb_set_t *old_before = before; + hb_set_t *old_input = input; + hb_set_t *old_after = after; + before = input = after = hb_set_get_empty (); + + nesting_level_left--; + recurse_func (this, lookup_index); + nesting_level_left++; + + before = old_before; + input = old_input; + after = old_after; + + return HB_VOID; + } + + hb_face_t *face; + hb_set_t *before; + hb_set_t *input; + hb_set_t *after; + hb_set_t *output; + recurse_func_t recurse_func; + unsigned int nesting_level_left; + unsigned int debug_depth; + + hb_collect_glyphs_context_t (hb_face_t *face_, + hb_set_t *glyphs_before, /* OUT. May be NULL */ + hb_set_t *glyphs_input, /* OUT. May be NULL */ + hb_set_t *glyphs_after, /* OUT. May be NULL */ + hb_set_t *glyphs_output, /* OUT. May be NULL */ + unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : + face (face_), + before (glyphs_before ? glyphs_before : hb_set_get_empty ()), + input (glyphs_input ? glyphs_input : hb_set_get_empty ()), + after (glyphs_after ? glyphs_after : hb_set_get_empty ()), + output (glyphs_output ? glyphs_output : hb_set_get_empty ()), + recurse_func (NULL), + nesting_level_left (nesting_level_left_), + debug_depth (0) {} + + void set_recurse_func (recurse_func_t func) { recurse_func = func; } +}; + + + +struct hb_get_coverage_context_t +{ + inline const char *get_name (void) { return "GET_COVERAGE"; } + static const unsigned int max_debug_depth = 0; + typedef const Coverage &return_t; + template <typename T> + inline return_t process (const T &obj) { return obj.get_coverage (); } + static return_t default_return_value (void) { return Null(Coverage); } + + hb_get_coverage_context_t (void) : + debug_depth (0) {} + + unsigned int debug_depth; +}; + + + +#ifndef HB_DEBUG_APPLY +#define HB_DEBUG_APPLY (HB_DEBUG+0) +#endif + +#define TRACE_APPLY(this) \ + hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \ + (&c->debug_depth, c->get_name (), this, HB_FUNC, \ + "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); + +struct hb_apply_context_t +{ + inline const char *get_name (void) { return "APPLY"; } + static const unsigned int max_debug_depth = HB_DEBUG_APPLY; + typedef bool return_t; + typedef return_t (*recurse_func_t) (hb_apply_context_t *c, unsigned int lookup_index); + template <typename T> + inline return_t process (const T &obj) { return obj.apply (this); } + static return_t default_return_value (void) { return false; } + bool stop_sublookup_iteration (const return_t r) const { return r; } + return_t recurse (unsigned int lookup_index) + { + if (unlikely (nesting_level_left == 0 || !recurse_func)) + return default_return_value (); + + nesting_level_left--; + bool ret = recurse_func (this, lookup_index); + nesting_level_left++; + return ret; + } + + hb_font_t *font; + hb_face_t *face; + hb_buffer_t *buffer; + hb_direction_t direction; + hb_mask_t lookup_mask; + recurse_func_t recurse_func; + unsigned int nesting_level_left; + unsigned int lookup_props; + unsigned int property; /* propety of first glyph */ + const GDEF &gdef; + bool has_glyph_classes; + unsigned int debug_depth; + + + hb_apply_context_t (hb_font_t *font_, + hb_buffer_t *buffer_, + hb_mask_t lookup_mask_) : + font (font_), face (font->face), buffer (buffer_), + direction (buffer_->props.direction), + lookup_mask (lookup_mask_), + recurse_func (NULL), + nesting_level_left (MAX_NESTING_LEVEL), + lookup_props (0), property (0), + gdef (*hb_ot_layout_from_face (face)->gdef), + has_glyph_classes (gdef.has_glyph_classes ()), + debug_depth (0) {} + + void set_recurse_func (recurse_func_t func) { recurse_func = func; } + void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; } + void set_lookup (const Lookup &l) { lookup_props = l.get_props (); } + + struct mark_skipping_forward_iterator_t + { + inline mark_skipping_forward_iterator_t (hb_apply_context_t *c_, + unsigned int start_index_, + unsigned int num_items_, + bool context_match = false) + { + c = c_; + idx = start_index_; + num_items = num_items_; + mask = context_match ? -1 : c->lookup_mask; + syllable = context_match ? 0 : c->buffer->cur().syllable (); + end = c->buffer->len; + } + inline bool has_no_chance (void) const + { + return unlikely (num_items && idx + num_items >= end); + } + inline void reject (void) + { + num_items++; + } + inline bool next (unsigned int *property_out, + unsigned int lookup_props) + { + assert (num_items > 0); + do + { + if (has_no_chance ()) + return false; + idx++; + } while (c->should_skip_mark (&c->buffer->info[idx], lookup_props, property_out)); + num_items--; + return (c->buffer->info[idx].mask & mask) && (!syllable || syllable == c->buffer->info[idx].syllable ()); + } + inline bool next (unsigned int *property_out = NULL) + { + return next (property_out, c->lookup_props); + } + + unsigned int idx; + protected: + hb_apply_context_t *c; + unsigned int num_items; + hb_mask_t mask; + uint8_t syllable; + unsigned int end; + }; + + struct mark_skipping_backward_iterator_t + { + inline mark_skipping_backward_iterator_t (hb_apply_context_t *c_, + unsigned int start_index_, + unsigned int num_items_, + hb_mask_t mask_ = 0, + bool match_syllable_ = true) + { + c = c_; + idx = start_index_; + num_items = num_items_; + mask = mask_ ? mask_ : c->lookup_mask; + syllable = match_syllable_ ? c->buffer->cur().syllable () : 0; + } + inline bool has_no_chance (void) const + { + return unlikely (idx < num_items); + } + inline void reject (void) + { + num_items++; + } + inline bool prev (unsigned int *property_out, + unsigned int lookup_props) + { + assert (num_items > 0); + do + { + if (has_no_chance ()) + return false; + idx--; + } while (c->should_skip_mark (&c->buffer->out_info[idx], lookup_props, property_out)); + num_items--; + return (c->buffer->out_info[idx].mask & mask) && (!syllable || syllable == c->buffer->out_info[idx].syllable ()); + } + inline bool prev (unsigned int *property_out = NULL) + { + return prev (property_out, c->lookup_props); + } + + unsigned int idx; + protected: + hb_apply_context_t *c; + unsigned int num_items; + hb_mask_t mask; + uint8_t syllable; + }; + + inline bool + match_properties_mark (hb_codepoint_t glyph, + unsigned int glyph_props, + unsigned int lookup_props) const + { + /* If using mark filtering sets, the high short of + * lookup_props has the set index. + */ + if (lookup_props & LookupFlag::UseMarkFilteringSet) + return gdef.mark_set_covers (lookup_props >> 16, glyph); + + /* The second byte of lookup_props has the meaning + * "ignore marks of attachment type different than + * the attachment type specified." + */ + if (lookup_props & LookupFlag::MarkAttachmentType) + return (lookup_props & LookupFlag::MarkAttachmentType) == (glyph_props & LookupFlag::MarkAttachmentType); + + return true; + } + + inline bool + match_properties (hb_codepoint_t glyph, + unsigned int glyph_props, + unsigned int lookup_props) const + { + /* Not covered, if, for example, glyph class is ligature and + * lookup_props includes LookupFlags::IgnoreLigatures + */ + if (glyph_props & lookup_props & LookupFlag::IgnoreFlags) + return false; + + if (unlikely (glyph_props & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) + return match_properties_mark (glyph, glyph_props, lookup_props); + + return true; + } + + inline bool + check_glyph_property (hb_glyph_info_t *info, + unsigned int lookup_props, + unsigned int *property_out) const + { + unsigned int property; + + property = info->glyph_props(); + *property_out = property; + + return match_properties (info->codepoint, property, lookup_props); + } + + inline bool + should_skip_mark (hb_glyph_info_t *info, + unsigned int lookup_props, + unsigned int *property_out) const + { + unsigned int property; + + property = info->glyph_props(); + if (property_out) + *property_out = property; + + /* If it's a mark, skip it if we don't accept it. */ + if (unlikely (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) + return !match_properties (info->codepoint, property, lookup_props); + + /* If not a mark, don't skip. */ + return false; + } + + + inline bool should_mark_skip_current_glyph (void) const + { + return should_skip_mark (&buffer->cur(), lookup_props, NULL); + } + + inline void set_class (hb_codepoint_t glyph_index, unsigned int class_guess) const + { + if (likely (has_glyph_classes)) + buffer->cur().glyph_props() = gdef.get_glyph_props (glyph_index); + else if (class_guess) + buffer->cur().glyph_props() = class_guess; + } + + inline void output_glyph (hb_codepoint_t glyph_index, + unsigned int class_guess = 0) const + { + set_class (glyph_index, class_guess); + buffer->output_glyph (glyph_index); + } + inline void replace_glyph (hb_codepoint_t glyph_index, + unsigned int class_guess = 0) const + { + set_class (glyph_index, class_guess); + buffer->replace_glyph (glyph_index); + } + inline void replace_glyph_inplace (hb_codepoint_t glyph_index, + unsigned int class_guess = 0) const + { + set_class (glyph_index, class_guess); + buffer->cur().codepoint = glyph_index; + } +}; + + + +typedef bool (*intersects_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data); +typedef void (*collect_glyphs_func_t) (hb_set_t *glyphs, const USHORT &value, const void *data); +typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, const void *data); + +struct ContextClosureFuncs +{ + intersects_func_t intersects; +}; +struct ContextCollectGlyphsFuncs +{ + collect_glyphs_func_t collect; +}; +struct ContextApplyFuncs +{ + match_func_t match; +}; + + +static inline bool intersects_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED) +{ + return glyphs->has (value); +} +static inline bool intersects_class (hb_set_t *glyphs, const USHORT &value, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); + return class_def.intersects_class (glyphs, value); +} +static inline bool intersects_coverage (hb_set_t *glyphs, const USHORT &value, const void *data) +{ + const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; + return (data+coverage).intersects (glyphs); +} + +static inline bool intersects_array (hb_closure_context_t *c, + unsigned int count, + const USHORT values[], + intersects_func_t intersects_func, + const void *intersects_data) +{ + for (unsigned int i = 0; i < count; i++) + if (likely (!intersects_func (c->glyphs, values[i], intersects_data))) + return false; + return true; +} + + +static inline void collect_glyph (hb_set_t *glyphs, const USHORT &value, const void *data HB_UNUSED) +{ + glyphs->add (value); +} +static inline void collect_class (hb_set_t *glyphs, const USHORT &value, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); + class_def.add_class (glyphs, value); +} +static inline void collect_coverage (hb_set_t *glyphs, const USHORT &value, const void *data) +{ + const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; + (data+coverage).add_coverage (glyphs); +} +static inline void collect_array (hb_collect_glyphs_context_t *c HB_UNUSED, + hb_set_t *glyphs, + unsigned int count, + const USHORT values[], + collect_glyphs_func_t collect_func, + const void *collect_data) +{ + for (unsigned int i = 0; i < count; i++) + collect_func (glyphs, values[i], collect_data); +} + + +static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, const void *data HB_UNUSED) +{ + return glyph_id == value; +} +static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, const void *data) +{ + const ClassDef &class_def = *reinterpret_cast<const ClassDef *>(data); + return class_def.get_class (glyph_id) == value; +} +static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, const void *data) +{ + const OffsetTo<Coverage> &coverage = (const OffsetTo<Coverage>&)value; + return (data+coverage).get_coverage (glyph_id) != NOT_COVERED; +} + +static inline bool would_match_input (hb_would_apply_context_t *c, + unsigned int count, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + match_func_t match_func, + const void *match_data) +{ + if (count != c->len) + return false; + + for (unsigned int i = 1; i < count; i++) + if (likely (!match_func (c->glyphs[i], input[i - 1], match_data))) + return false; + + return true; +} +static inline bool match_input (hb_apply_context_t *c, + unsigned int count, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + match_func_t match_func, + const void *match_data, + unsigned int *end_offset = NULL, + bool *p_is_mark_ligature = NULL, + unsigned int *p_total_component_count = NULL) +{ + TRACE_APPLY (NULL); + + hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1); + if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); + + /* + * This is perhaps the trickiest part of OpenType... Remarks: + * + * - If all components of the ligature were marks, we call this a mark ligature. + * + * - If there is no GDEF, and the ligature is NOT a mark ligature, we categorize + * it as a ligature glyph. + * + * - Ligatures cannot be formed across glyphs attached to different components + * of previous ligatures. Eg. the sequence is LAM,SHADDA,LAM,FATHA,HEH, and + * LAM,LAM,HEH form a ligature, leaving SHADDA,FATHA next to eachother. + * However, it would be wrong to ligate that SHADDA,FATHA sequence.o + * There is an exception to this: If a ligature tries ligating with marks that + * belong to it itself, go ahead, assuming that the font designer knows what + * they are doing (otherwise it can break Indic stuff when a matra wants to + * ligate with a conjunct...) + */ + + bool is_mark_ligature = !!(c->property & HB_OT_LAYOUT_GLYPH_PROPS_MARK); + + unsigned int total_component_count = 0; + total_component_count += get_lig_num_comps (c->buffer->cur()); + + unsigned int first_lig_id = get_lig_id (c->buffer->cur()); + unsigned int first_lig_comp = get_lig_comp (c->buffer->cur()); + + for (unsigned int i = 1; i < count; i++) + { + unsigned int property; + + if (!skippy_iter.next (&property)) return TRACE_RETURN (false); + + if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, input[i - 1], match_data))) return TRACE_RETURN (false); + + unsigned int this_lig_id = get_lig_id (c->buffer->info[skippy_iter.idx]); + unsigned int this_lig_comp = get_lig_comp (c->buffer->info[skippy_iter.idx]); + + if (first_lig_id && first_lig_comp) { + /* If first component was attached to a previous ligature component, + * all subsequent components should be attached to the same ligature + * component, otherwise we shouldn't ligate them. */ + if (first_lig_id != this_lig_id || first_lig_comp != this_lig_comp) + return TRACE_RETURN (false); + } else { + /* If first component was NOT attached to a previous ligature component, + * all subsequent components should also NOT be attached to any ligature + * component, unless they are attached to the first component itself! */ + if (this_lig_id && this_lig_comp && (this_lig_id != first_lig_id)) + return TRACE_RETURN (false); + } + + is_mark_ligature = is_mark_ligature && (property & HB_OT_LAYOUT_GLYPH_PROPS_MARK); + total_component_count += get_lig_num_comps (c->buffer->info[skippy_iter.idx]); + } + + if (end_offset) + *end_offset = skippy_iter.idx - c->buffer->idx + 1; + + if (p_is_mark_ligature) + *p_is_mark_ligature = is_mark_ligature; + + if (p_total_component_count) + *p_total_component_count = total_component_count; + + return TRACE_RETURN (true); +} +static inline void ligate_input (hb_apply_context_t *c, + unsigned int count, /* Including the first glyph (not matched) */ + const USHORT input[] HB_UNUSED, /* Array of input values--start with second glyph */ + hb_codepoint_t lig_glyph, + match_func_t match_func HB_UNUSED, + const void *match_data HB_UNUSED, + bool is_mark_ligature, + unsigned int total_component_count) +{ + /* + * - If it *is* a mark ligature, we don't allocate a new ligature id, and leave + * the ligature to keep its old ligature id. This will allow it to attach to + * a base ligature in GPOS. Eg. if the sequence is: LAM,LAM,SHADDA,FATHA,HEH, + * and LAM,LAM,HEH for a ligature, they will leave SHADDA and FATHA wit a + * ligature id and component value of 2. Then if SHADDA,FATHA form a ligature + * later, we don't want them to lose their ligature id/component, otherwise + * GPOS will fail to correctly position the mark ligature on top of the + * LAM,LAM,HEH ligature. See: + * https://bugzilla.gnome.org/show_bug.cgi?id=676343 + * + * - If a ligature is formed of components that some of which are also ligatures + * themselves, and those ligature components had marks attached to *their* + * components, we have to attach the marks to the new ligature component + * positions! Now *that*'s tricky! And these marks may be following the + * last component of the whole sequence, so we should loop forward looking + * for them and update them. + * + * Eg. the sequence is LAM,LAM,SHADDA,FATHA,HEH, and the font first forms a + * 'calt' ligature of LAM,HEH, leaving the SHADDA and FATHA with a ligature + * id and component == 1. Now, during 'liga', the LAM and the LAM-HEH ligature + * form a LAM-LAM-HEH ligature. We need to reassign the SHADDA and FATHA to + * the new ligature with a component value of 2. + * + * This in fact happened to a font... See: + * https://bugzilla.gnome.org/show_bug.cgi?id=437633 + */ + + unsigned int klass = is_mark_ligature ? 0 : HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE; + unsigned int lig_id = is_mark_ligature ? 0 : allocate_lig_id (c->buffer); + unsigned int last_lig_id = get_lig_id (c->buffer->cur()); + unsigned int last_num_components = get_lig_num_comps (c->buffer->cur()); + unsigned int components_so_far = last_num_components; + + if (!is_mark_ligature) + set_lig_props_for_ligature (c->buffer->cur(), lig_id, total_component_count); + c->replace_glyph (lig_glyph, klass); + + for (unsigned int i = 1; i < count; i++) + { + while (c->should_mark_skip_current_glyph ()) + { + if (!is_mark_ligature) { + unsigned int new_lig_comp = components_so_far - last_num_components + + MIN (MAX (get_lig_comp (c->buffer->cur()), 1u), last_num_components); + set_lig_props_for_mark (c->buffer->cur(), lig_id, new_lig_comp); + } + c->buffer->next_glyph (); + } + + last_lig_id = get_lig_id (c->buffer->cur()); + last_num_components = get_lig_num_comps (c->buffer->cur()); + components_so_far += last_num_components; + + /* Skip the base glyph */ + c->buffer->idx++; + } + + if (!is_mark_ligature && last_lig_id) { + /* Re-adjust components for any marks following. */ + for (unsigned int i = c->buffer->idx; i < c->buffer->len; i++) { + if (last_lig_id == get_lig_id (c->buffer->info[i])) { + unsigned int new_lig_comp = components_so_far - last_num_components + + MIN (MAX (get_lig_comp (c->buffer->info[i]), 1u), last_num_components); + set_lig_props_for_mark (c->buffer->info[i], lig_id, new_lig_comp); + } else + break; + } + } +} + +static inline bool match_backtrack (hb_apply_context_t *c, + unsigned int count, + const USHORT backtrack[], + match_func_t match_func, + const void *match_data) +{ + TRACE_APPLY (NULL); + + hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true); + if (skippy_iter.has_no_chance ()) + return TRACE_RETURN (false); + + for (unsigned int i = 0; i < count; i++) + { + if (!skippy_iter.prev ()) + return TRACE_RETURN (false); + + if (likely (!match_func (c->buffer->out_info[skippy_iter.idx].codepoint, backtrack[i], match_data))) + return TRACE_RETURN (false); + } + + return TRACE_RETURN (true); +} + +static inline bool match_lookahead (hb_apply_context_t *c, + unsigned int count, + const USHORT lookahead[], + match_func_t match_func, + const void *match_data, + unsigned int offset) +{ + TRACE_APPLY (NULL); + + hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true); + if (skippy_iter.has_no_chance ()) + return TRACE_RETURN (false); + + for (unsigned int i = 0; i < count; i++) + { + if (!skippy_iter.next ()) + return TRACE_RETURN (false); + + if (likely (!match_func (c->buffer->info[skippy_iter.idx].codepoint, lookahead[i], match_data))) + return TRACE_RETURN (false); + } + + return TRACE_RETURN (true); +} + + + +struct LookupRecord +{ + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + USHORT sequenceIndex; /* Index into current glyph + * sequence--first glyph = 0 */ + USHORT lookupListIndex; /* Lookup to apply to that + * position--zero--based */ + public: + DEFINE_SIZE_STATIC (4); +}; + + +template <typename context_t> +static inline void recurse_lookups (context_t *c, + unsigned int lookupCount, + const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) +{ + for (unsigned int i = 0; i < lookupCount; i++) + c->recurse (lookupRecord->lookupListIndex); +} + +static inline bool apply_lookup (hb_apply_context_t *c, + unsigned int count, /* Including the first glyph */ + unsigned int lookupCount, + const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) +{ + TRACE_APPLY (NULL); + + unsigned int end = c->buffer->len; + if (unlikely (count == 0 || c->buffer->idx + count > end)) + return TRACE_RETURN (false); + + /* TODO We don't support lookupRecord arrays that are not increasing: + * Should be easy for in_place ones at least. */ + + /* Note: If sublookup is reverse, it will underflow after the first loop + * and we jump out of it. Not entirely disastrous. So we don't check + * for reverse lookup here. + */ + for (unsigned int i = 0; i < count; /* NOP */) + { + if (unlikely (c->buffer->idx == end)) + return TRACE_RETURN (true); + while (c->should_mark_skip_current_glyph ()) + { + /* No lookup applied for this index */ + c->buffer->next_glyph (); + if (unlikely (c->buffer->idx == end)) + return TRACE_RETURN (true); + } + + if (lookupCount && i == lookupRecord->sequenceIndex) + { + unsigned int old_pos = c->buffer->idx; + + /* Apply a lookup */ + bool done = c->recurse (lookupRecord->lookupListIndex); + + lookupRecord++; + lookupCount--; + /* Err, this is wrong if the lookup jumped over some glyphs */ + i += c->buffer->idx - old_pos; + if (unlikely (c->buffer->idx == end)) + return TRACE_RETURN (true); + + if (!done) + goto not_applied; + } + else + { + not_applied: + /* No lookup applied for this index */ + c->buffer->next_glyph (); + i++; + } + } + + return TRACE_RETURN (true); +} + + + +/* Contextual lookups */ + +struct ContextClosureLookupContext +{ + ContextClosureFuncs funcs; + const void *intersects_data; +}; + +struct ContextCollectGlyphsLookupContext +{ + ContextCollectGlyphsFuncs funcs; + const void *collect_data; +}; + +struct ContextApplyLookupContext +{ + ContextApplyFuncs funcs; + const void *match_data; +}; + +static inline void context_closure_lookup (hb_closure_context_t *c, + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ContextClosureLookupContext &lookup_context) +{ + if (intersects_array (c, + inputCount ? inputCount - 1 : 0, input, + lookup_context.funcs.intersects, lookup_context.intersects_data)) + recurse_lookups (c, + lookupCount, lookupRecord); +} + +static inline void context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ContextCollectGlyphsLookupContext &lookup_context) +{ + collect_array (c, c->input, + inputCount ? inputCount - 1 : 0, input, + lookup_context.funcs.collect, lookup_context.collect_data); + recurse_lookups (c, + lookupCount, lookupRecord); +} + +static inline bool context_would_apply_lookup (hb_would_apply_context_t *c, + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookupCount HB_UNUSED, + const LookupRecord lookupRecord[] HB_UNUSED, + ContextApplyLookupContext &lookup_context) +{ + return would_match_input (c, + inputCount, input, + lookup_context.funcs.match, lookup_context.match_data); +} +static inline bool context_apply_lookup (hb_apply_context_t *c, + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ContextApplyLookupContext &lookup_context) +{ + return match_input (c, + inputCount, input, + lookup_context.funcs.match, lookup_context.match_data) + && apply_lookup (c, + inputCount, + lookupCount, lookupRecord); +} + +struct Rule +{ + inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const + { + TRACE_CLOSURE (this); + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); + context_closure_lookup (c, + inputCount, input, + lookupCount, lookupRecord, + lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const + { + TRACE_COLLECT_GLYPHS (this); + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); + context_collect_glyphs_lookup (c, + inputCount, input, + lookupCount, lookupRecord, + lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const + { + TRACE_WOULD_APPLY (this); + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); + return TRACE_RETURN (context_would_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context)); + } + + inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const + { + TRACE_APPLY (this); + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (input, input[0].static_size * (inputCount ? inputCount - 1 : 0)); + return TRACE_RETURN (context_apply_lookup (c, inputCount, input, lookupCount, lookupRecord, lookup_context)); + } + + public: + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return inputCount.sanitize (c) + && lookupCount.sanitize (c) + && c->check_range (input, + input[0].static_size * inputCount + + lookupRecordX[0].static_size * lookupCount); + } + + protected: + USHORT inputCount; /* Total number of glyphs in input + * glyph sequence--includes the first + * glyph */ + USHORT lookupCount; /* Number of LookupRecords */ + USHORT input[VAR]; /* Array of match inputs--start with + * second glyph */ + LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in + * design order */ + public: + DEFINE_SIZE_ARRAY2 (4, input, lookupRecordX); +}; + +struct RuleSet +{ + inline void closure (hb_closure_context_t *c, ContextClosureLookupContext &lookup_context) const + { + TRACE_CLOSURE (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + (this+rule[i]).closure (c, lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c, ContextCollectGlyphsLookupContext &lookup_context) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + (this+rule[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c, ContextApplyLookupContext &lookup_context) const + { + TRACE_WOULD_APPLY (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + { + if ((this+rule[i]).would_apply (c, lookup_context)) + return TRACE_RETURN (true); + } + return TRACE_RETURN (false); + } + + inline bool apply (hb_apply_context_t *c, ContextApplyLookupContext &lookup_context) const + { + TRACE_APPLY (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + { + if ((this+rule[i]).apply (c, lookup_context)) + return TRACE_RETURN (true); + } + return TRACE_RETURN (false); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (rule.sanitize (c, this)); + } + + protected: + OffsetArrayOf<Rule> + rule; /* Array of Rule tables + * ordered by preference */ + public: + DEFINE_SIZE_ARRAY (2, rule); +}; + + +struct ContextFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + + const Coverage &cov = (this+coverage); + + struct ContextClosureLookupContext lookup_context = { + {intersects_glyph}, + NULL + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + if (cov.intersects_coverage (c->glyphs, i)) { + const RuleSet &rule_set = this+ruleSet[i]; + rule_set.closure (c, lookup_context); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + + struct ContextCollectGlyphsLookupContext lookup_context = { + {collect_glyph}, + NULL + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + (this+ruleSet[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const RuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; + struct ContextApplyLookupContext lookup_context = { + {match_glyph}, + NULL + }; + return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) + return TRACE_RETURN (false); + + const RuleSet &rule_set = this+ruleSet[index]; + struct ContextApplyLookupContext lookup_context = { + {match_glyph}, + NULL + }; + return TRACE_RETURN (rule_set.apply (c, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of table */ + OffsetArrayOf<RuleSet> + ruleSet; /* Array of RuleSet tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, ruleSet); +}; + + +struct ContextFormat2 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + if (!(this+coverage).intersects (c->glyphs)) + return; + + const ClassDef &class_def = this+classDef; + + struct ContextClosureLookupContext lookup_context = { + {intersects_class}, + &class_def + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + if (class_def.intersects_class (c->glyphs, i)) { + const RuleSet &rule_set = this+ruleSet[i]; + rule_set.closure (c, lookup_context); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + + const ClassDef &class_def = this+classDef; + struct ContextCollectGlyphsLookupContext lookup_context = { + {collect_class}, + &class_def + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + (this+ruleSet[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const ClassDef &class_def = this+classDef; + unsigned int index = class_def.get_class (c->glyphs[0]); + const RuleSet &rule_set = this+ruleSet[index]; + struct ContextApplyLookupContext lookup_context = { + {match_class}, + &class_def + }; + return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const ClassDef &class_def = this+classDef; + index = class_def.get_class (c->buffer->cur().codepoint); + const RuleSet &rule_set = this+ruleSet[index]; + struct ContextApplyLookupContext lookup_context = { + {match_class}, + &class_def + }; + return TRACE_RETURN (rule_set.apply (c, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && classDef.sanitize (c, this) && ruleSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of table */ + OffsetTo<ClassDef> + classDef; /* Offset to glyph ClassDef table--from + * beginning of table */ + OffsetArrayOf<RuleSet> + ruleSet; /* Array of RuleSet tables + * ordered by class */ + public: + DEFINE_SIZE_ARRAY (8, ruleSet); +}; + + +struct ContextFormat3 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + if (!(this+coverage[0]).intersects (c->glyphs)) + return; + + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); + struct ContextClosureLookupContext lookup_context = { + {intersects_coverage}, + this + }; + context_closure_lookup (c, + glyphCount, (const USHORT *) (coverage + 1), + lookupCount, lookupRecord, + lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage[0]).add_coverage (c->input); + + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); + struct ContextCollectGlyphsLookupContext lookup_context = { + {collect_coverage}, + this + }; + + context_collect_glyphs_lookup (c, + glyphCount, (const USHORT *) (coverage + 1), + lookupCount, lookupRecord, + lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); + struct ContextApplyLookupContext lookup_context = { + {match_coverage}, + this + }; + return TRACE_RETURN (context_would_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage[0]; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage[0]).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * glyphCount); + struct ContextApplyLookupContext lookup_context = { + {match_coverage}, + this + }; + return TRACE_RETURN (context_apply_lookup (c, glyphCount, (const USHORT *) (coverage + 1), lookupCount, lookupRecord, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!c->check_struct (this)) return TRACE_RETURN (false); + unsigned int count = glyphCount; + if (!c->check_array (coverage, coverage[0].static_size, count)) return TRACE_RETURN (false); + for (unsigned int i = 0; i < count; i++) + if (!coverage[i].sanitize (c, this)) return TRACE_RETURN (false); + LookupRecord *lookupRecord = &StructAtOffset<LookupRecord> (coverage, coverage[0].static_size * count); + return TRACE_RETURN (c->check_array (lookupRecord, lookupRecord[0].static_size, lookupCount)); + } + + protected: + USHORT format; /* Format identifier--format = 3 */ + USHORT glyphCount; /* Number of glyphs in the input glyph + * sequence */ + USHORT lookupCount; /* Number of LookupRecords */ + OffsetTo<Coverage> + coverage[VAR]; /* Array of offsets to Coverage + * table in glyph sequence order */ + LookupRecord lookupRecordX[VAR]; /* Array of LookupRecords--in + * design order */ + public: + DEFINE_SIZE_ARRAY2 (6, coverage, lookupRecordX); +}; + +struct Context +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + case 2: return TRACE_RETURN (c->process (u.format2)); + case 3: return TRACE_RETURN (c->process (u.format3)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + case 3: return TRACE_RETURN (u.format3.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + ContextFormat1 format1; + ContextFormat2 format2; + ContextFormat3 format3; + } u; +}; + + +/* Chaining Contextual lookups */ + +struct ChainContextClosureLookupContext +{ + ContextClosureFuncs funcs; + const void *intersects_data[3]; +}; + +struct ChainContextCollectGlyphsLookupContext +{ + ContextCollectGlyphsFuncs funcs; + const void *collect_data[3]; +}; + +struct ChainContextApplyLookupContext +{ + ContextApplyFuncs funcs; + const void *match_data[3]; +}; + +static inline void chain_context_closure_lookup (hb_closure_context_t *c, + unsigned int backtrackCount, + const USHORT backtrack[], + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookaheadCount, + const USHORT lookahead[], + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ChainContextClosureLookupContext &lookup_context) +{ + if (intersects_array (c, + backtrackCount, backtrack, + lookup_context.funcs.intersects, lookup_context.intersects_data[0]) + && intersects_array (c, + inputCount ? inputCount - 1 : 0, input, + lookup_context.funcs.intersects, lookup_context.intersects_data[1]) + && intersects_array (c, + lookaheadCount, lookahead, + lookup_context.funcs.intersects, lookup_context.intersects_data[2])) + recurse_lookups (c, + lookupCount, lookupRecord); +} + +static inline void chain_context_collect_glyphs_lookup (hb_collect_glyphs_context_t *c, + unsigned int backtrackCount, + const USHORT backtrack[], + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookaheadCount, + const USHORT lookahead[], + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ChainContextCollectGlyphsLookupContext &lookup_context) +{ + collect_array (c, c->before, + backtrackCount, backtrack, + lookup_context.funcs.collect, lookup_context.collect_data[0]); + collect_array (c, c->input, + inputCount ? inputCount - 1 : 0, input, + lookup_context.funcs.collect, lookup_context.collect_data[1]); + collect_array (c, c->after, + lookaheadCount, lookahead, + lookup_context.funcs.collect, lookup_context.collect_data[2]); + recurse_lookups (c, + lookupCount, lookupRecord); +} + +static inline bool chain_context_would_apply_lookup (hb_would_apply_context_t *c, + unsigned int backtrackCount, + const USHORT backtrack[] HB_UNUSED, + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookaheadCount, + const USHORT lookahead[] HB_UNUSED, + unsigned int lookupCount HB_UNUSED, + const LookupRecord lookupRecord[] HB_UNUSED, + ChainContextApplyLookupContext &lookup_context) +{ + return (c->zero_context ? !backtrackCount && !lookaheadCount : true) + && would_match_input (c, + inputCount, input, + lookup_context.funcs.match, lookup_context.match_data[1]); +} + +static inline bool chain_context_apply_lookup (hb_apply_context_t *c, + unsigned int backtrackCount, + const USHORT backtrack[], + unsigned int inputCount, /* Including the first glyph (not matched) */ + const USHORT input[], /* Array of input values--start with second glyph */ + unsigned int lookaheadCount, + const USHORT lookahead[], + unsigned int lookupCount, + const LookupRecord lookupRecord[], + ChainContextApplyLookupContext &lookup_context) +{ + unsigned int lookahead_offset = 0; + return match_input (c, + inputCount, input, + lookup_context.funcs.match, lookup_context.match_data[1], + &lookahead_offset) + && match_backtrack (c, + backtrackCount, backtrack, + lookup_context.funcs.match, lookup_context.match_data[0]) + && match_lookahead (c, + lookaheadCount, lookahead, + lookup_context.funcs.match, lookup_context.match_data[2], + lookahead_offset) + && apply_lookup (c, + inputCount, + lookupCount, lookupRecord); +} + +struct ChainRule +{ + inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const + { + TRACE_CLOSURE (this); + const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); + const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + chain_context_closure_lookup (c, + backtrack.len, backtrack.array, + input.len, input.array, + lookahead.len, lookahead.array, + lookup.len, lookup.array, + lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const + { + TRACE_COLLECT_GLYPHS (this); + const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); + const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + chain_context_collect_glyphs_lookup (c, + backtrack.len, backtrack.array, + input.len, input.array, + lookahead.len, lookahead.array, + lookup.len, lookup.array, + lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const + { + TRACE_WOULD_APPLY (this); + const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); + const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + return TRACE_RETURN (chain_context_would_apply_lookup (c, + backtrack.len, backtrack.array, + input.len, input.array, + lookahead.len, lookahead.array, lookup.len, + lookup.array, lookup_context)); + } + + inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const + { + TRACE_APPLY (this); + const HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); + const ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + return TRACE_RETURN (chain_context_apply_lookup (c, + backtrack.len, backtrack.array, + input.len, input.array, + lookahead.len, lookahead.array, lookup.len, + lookup.array, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!backtrack.sanitize (c)) return TRACE_RETURN (false); + HeadlessArrayOf<USHORT> &input = StructAfter<HeadlessArrayOf<USHORT> > (backtrack); + if (!input.sanitize (c)) return TRACE_RETURN (false); + ArrayOf<USHORT> &lookahead = StructAfter<ArrayOf<USHORT> > (input); + if (!lookahead.sanitize (c)) return TRACE_RETURN (false); + ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + return TRACE_RETURN (lookup.sanitize (c)); + } + + protected: + ArrayOf<USHORT> + backtrack; /* Array of backtracking values + * (to be matched before the input + * sequence) */ + HeadlessArrayOf<USHORT> + inputX; /* Array of input values (start with + * second glyph) */ + ArrayOf<USHORT> + lookaheadX; /* Array of lookahead values's (to be + * matched after the input sequence) */ + ArrayOf<LookupRecord> + lookupX; /* Array of LookupRecords--in + * design order) */ + public: + DEFINE_SIZE_MIN (8); +}; + +struct ChainRuleSet +{ + inline void closure (hb_closure_context_t *c, ChainContextClosureLookupContext &lookup_context) const + { + TRACE_CLOSURE (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + (this+rule[i]).closure (c, lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c, ChainContextCollectGlyphsLookupContext &lookup_context) const + { + TRACE_COLLECT_GLYPHS (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + (this+rule[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const + { + TRACE_WOULD_APPLY (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + if ((this+rule[i]).would_apply (c, lookup_context)) + return TRACE_RETURN (true); + + return TRACE_RETURN (false); + } + + inline bool apply (hb_apply_context_t *c, ChainContextApplyLookupContext &lookup_context) const + { + TRACE_APPLY (this); + unsigned int num_rules = rule.len; + for (unsigned int i = 0; i < num_rules; i++) + if ((this+rule[i]).apply (c, lookup_context)) + return TRACE_RETURN (true); + + return TRACE_RETURN (false); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (rule.sanitize (c, this)); + } + + protected: + OffsetArrayOf<ChainRule> + rule; /* Array of ChainRule tables + * ordered by preference */ + public: + DEFINE_SIZE_ARRAY (2, rule); +}; + +struct ChainContextFormat1 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + const Coverage &cov = (this+coverage); + + struct ChainContextClosureLookupContext lookup_context = { + {intersects_glyph}, + {NULL, NULL, NULL} + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + if (cov.intersects_coverage (c->glyphs, i)) { + const ChainRuleSet &rule_set = this+ruleSet[i]; + rule_set.closure (c, lookup_context); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + + struct ChainContextCollectGlyphsLookupContext lookup_context = { + {collect_glyph}, + {NULL, NULL, NULL} + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + (this+ruleSet[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const ChainRuleSet &rule_set = this+ruleSet[(this+coverage).get_coverage (c->glyphs[0])]; + struct ChainContextApplyLookupContext lookup_context = { + {match_glyph}, + {NULL, NULL, NULL} + }; + return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const ChainRuleSet &rule_set = this+ruleSet[index]; + struct ChainContextApplyLookupContext lookup_context = { + {match_glyph}, + {NULL, NULL, NULL} + }; + return TRACE_RETURN (rule_set.apply (c, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && ruleSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 1 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of table */ + OffsetArrayOf<ChainRuleSet> + ruleSet; /* Array of ChainRuleSet tables + * ordered by Coverage Index */ + public: + DEFINE_SIZE_ARRAY (6, ruleSet); +}; + +struct ChainContextFormat2 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + if (!(this+coverage).intersects (c->glyphs)) + return; + + const ClassDef &backtrack_class_def = this+backtrackClassDef; + const ClassDef &input_class_def = this+inputClassDef; + const ClassDef &lookahead_class_def = this+lookaheadClassDef; + + struct ChainContextClosureLookupContext lookup_context = { + {intersects_class}, + {&backtrack_class_def, + &input_class_def, + &lookahead_class_def} + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + if (input_class_def.intersects_class (c->glyphs, i)) { + const ChainRuleSet &rule_set = this+ruleSet[i]; + rule_set.closure (c, lookup_context); + } + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + (this+coverage).add_coverage (c->input); + + const ClassDef &backtrack_class_def = this+backtrackClassDef; + const ClassDef &input_class_def = this+inputClassDef; + const ClassDef &lookahead_class_def = this+lookaheadClassDef; + + struct ChainContextCollectGlyphsLookupContext lookup_context = { + {collect_class}, + {&backtrack_class_def, + &input_class_def, + &lookahead_class_def} + }; + + unsigned int count = ruleSet.len; + for (unsigned int i = 0; i < count; i++) + (this+ruleSet[i]).collect_glyphs (c, lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const ClassDef &backtrack_class_def = this+backtrackClassDef; + const ClassDef &input_class_def = this+inputClassDef; + const ClassDef &lookahead_class_def = this+lookaheadClassDef; + + unsigned int index = input_class_def.get_class (c->glyphs[0]); + const ChainRuleSet &rule_set = this+ruleSet[index]; + struct ChainContextApplyLookupContext lookup_context = { + {match_class}, + {&backtrack_class_def, + &input_class_def, + &lookahead_class_def} + }; + return TRACE_RETURN (rule_set.would_apply (c, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + return this+coverage; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const ClassDef &backtrack_class_def = this+backtrackClassDef; + const ClassDef &input_class_def = this+inputClassDef; + const ClassDef &lookahead_class_def = this+lookaheadClassDef; + + index = input_class_def.get_class (c->buffer->cur().codepoint); + const ChainRuleSet &rule_set = this+ruleSet[index]; + struct ChainContextApplyLookupContext lookup_context = { + {match_class}, + {&backtrack_class_def, + &input_class_def, + &lookahead_class_def} + }; + return TRACE_RETURN (rule_set.apply (c, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (coverage.sanitize (c, this) && backtrackClassDef.sanitize (c, this) && + inputClassDef.sanitize (c, this) && lookaheadClassDef.sanitize (c, this) && + ruleSet.sanitize (c, this)); + } + + protected: + USHORT format; /* Format identifier--format = 2 */ + OffsetTo<Coverage> + coverage; /* Offset to Coverage table--from + * beginning of table */ + OffsetTo<ClassDef> + backtrackClassDef; /* Offset to glyph ClassDef table + * containing backtrack sequence + * data--from beginning of table */ + OffsetTo<ClassDef> + inputClassDef; /* Offset to glyph ClassDef + * table containing input sequence + * data--from beginning of table */ + OffsetTo<ClassDef> + lookaheadClassDef; /* Offset to glyph ClassDef table + * containing lookahead sequence + * data--from beginning of table */ + OffsetArrayOf<ChainRuleSet> + ruleSet; /* Array of ChainRuleSet tables + * ordered by class */ + public: + DEFINE_SIZE_ARRAY (12, ruleSet); +}; + +struct ChainContextFormat3 +{ + inline void closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (this); + const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + + if (!(this+input[0]).intersects (c->glyphs)) + return; + + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + struct ChainContextClosureLookupContext lookup_context = { + {intersects_coverage}, + {this, this, this} + }; + chain_context_closure_lookup (c, + backtrack.len, (const USHORT *) backtrack.array, + input.len, (const USHORT *) input.array + 1, + lookahead.len, (const USHORT *) lookahead.array, + lookup.len, lookup.array, + lookup_context); + } + + inline void collect_glyphs (hb_collect_glyphs_context_t *c) const + { + TRACE_COLLECT_GLYPHS (this); + const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + + (this+input[0]).add_coverage (c->input); + + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + struct ChainContextCollectGlyphsLookupContext lookup_context = { + {collect_coverage}, + {this, this, this} + }; + chain_context_collect_glyphs_lookup (c, + backtrack.len, (const USHORT *) backtrack.array, + input.len, (const USHORT *) input.array + 1, + lookahead.len, (const USHORT *) lookahead.array, + lookup.len, lookup.array, + lookup_context); + } + + inline bool would_apply (hb_would_apply_context_t *c) const + { + TRACE_WOULD_APPLY (this); + + const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + struct ChainContextApplyLookupContext lookup_context = { + {match_coverage}, + {this, this, this} + }; + return TRACE_RETURN (chain_context_would_apply_lookup (c, + backtrack.len, (const USHORT *) backtrack.array, + input.len, (const USHORT *) input.array + 1, + lookahead.len, (const USHORT *) lookahead.array, + lookup.len, lookup.array, lookup_context)); + } + + inline const Coverage &get_coverage (void) const + { + const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + return this+input[0]; + } + + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + const OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + + unsigned int index = (this+input[0]).get_coverage (c->buffer->cur().codepoint); + if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); + + const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); + const ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + struct ChainContextApplyLookupContext lookup_context = { + {match_coverage}, + {this, this, this} + }; + return TRACE_RETURN (chain_context_apply_lookup (c, + backtrack.len, (const USHORT *) backtrack.array, + input.len, (const USHORT *) input.array + 1, + lookahead.len, (const USHORT *) lookahead.array, + lookup.len, lookup.array, lookup_context)); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!backtrack.sanitize (c, this)) return TRACE_RETURN (false); + OffsetArrayOf<Coverage> &input = StructAfter<OffsetArrayOf<Coverage> > (backtrack); + if (!input.sanitize (c, this)) return TRACE_RETURN (false); + OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (input); + if (!lookahead.sanitize (c, this)) return TRACE_RETURN (false); + ArrayOf<LookupRecord> &lookup = StructAfter<ArrayOf<LookupRecord> > (lookahead); + return TRACE_RETURN (lookup.sanitize (c)); + } + + protected: + USHORT format; /* Format identifier--format = 3 */ + OffsetArrayOf<Coverage> + backtrack; /* Array of coverage tables + * in backtracking sequence, in glyph + * sequence order */ + OffsetArrayOf<Coverage> + inputX ; /* Array of coverage + * tables in input sequence, in glyph + * sequence order */ + OffsetArrayOf<Coverage> + lookaheadX; /* Array of coverage tables + * in lookahead sequence, in glyph + * sequence order */ + ArrayOf<LookupRecord> + lookupX; /* Array of LookupRecords--in + * design order) */ + public: + DEFINE_SIZE_MIN (10); +}; + +struct ChainContext +{ + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + TRACE_PROCESS (this); + switch (u.format) { + case 1: return TRACE_RETURN (c->process (u.format1)); + case 2: return TRACE_RETURN (c->process (u.format2)); + case 3: return TRACE_RETURN (c->process (u.format3)); + default:return TRACE_RETURN (c->default_return_value ()); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + case 2: return TRACE_RETURN (u.format2.sanitize (c)); + case 3: return TRACE_RETURN (u.format3.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + protected: + union { + USHORT format; /* Format identifier */ + ChainContextFormat1 format1; + ChainContextFormat2 format2; + ChainContextFormat3 format3; + } u; +}; + + +struct ExtensionFormat1 +{ + inline unsigned int get_type (void) const { return extensionLookupType; } + inline unsigned int get_offset (void) const { return extensionOffset; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this)); + } + + protected: + USHORT format; /* Format identifier. Set to 1. */ + USHORT extensionLookupType; /* Lookup type of subtable referenced + * by ExtensionOffset (i.e. the + * extension subtable). */ + ULONG extensionOffset; /* Offset to the extension subtable, + * of lookup type subtable. */ + public: + DEFINE_SIZE_STATIC (8); +}; + +template <typename T> +struct Extension +{ + inline unsigned int get_type (void) const + { + switch (u.format) { + case 1: return u.format1.get_type (); + default:return 0; + } + } + inline unsigned int get_offset (void) const + { + switch (u.format) { + case 1: return u.format1.get_offset (); + default:return 0; + } + } + + template <typename X> + inline const X& get_subtable (void) const + { + unsigned int offset = get_offset (); + if (unlikely (!offset)) return Null(typename T::LookupSubTable); + return StructAtOffset<typename T::LookupSubTable> (this, offset); + } + + template <typename context_t> + inline typename context_t::return_t process (context_t *c) const + { + return get_subtable<typename T::LookupSubTable> ().process (c, get_type ()); + } + + inline bool sanitize_self (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!u.format.sanitize (c)) return TRACE_RETURN (false); + switch (u.format) { + case 1: return TRACE_RETURN (u.format1.sanitize (c)); + default:return TRACE_RETURN (true); + } + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + if (!sanitize_self (c)) return TRACE_RETURN (false); + unsigned int offset = get_offset (); + if (unlikely (!offset)) return TRACE_RETURN (true); + return TRACE_RETURN (StructAtOffset<typename T::LookupSubTable> (this, offset).sanitize (c, get_type ())); + } + + protected: + union { + USHORT format; /* Format identifier */ + ExtensionFormat1 format1; + } u; +}; + + +/* + * GSUB/GPOS Common + */ + +struct GSUBGPOS +{ + static const hb_tag_t GSUBTag = HB_OT_TAG_GSUB; + static const hb_tag_t GPOSTag = HB_OT_TAG_GPOS; + + inline unsigned int get_script_count (void) const + { return (this+scriptList).len; } + inline const Tag& get_script_tag (unsigned int i) const + { return (this+scriptList).get_tag (i); } + inline unsigned int get_script_tags (unsigned int start_offset, + unsigned int *script_count /* IN/OUT */, + hb_tag_t *script_tags /* OUT */) const + { return (this+scriptList).get_tags (start_offset, script_count, script_tags); } + inline const Script& get_script (unsigned int i) const + { return (this+scriptList)[i]; } + inline bool find_script_index (hb_tag_t tag, unsigned int *index) const + { return (this+scriptList).find_index (tag, index); } + + inline unsigned int get_feature_count (void) const + { return (this+featureList).len; } + inline const Tag& get_feature_tag (unsigned int i) const + { return (this+featureList).get_tag (i); } + inline unsigned int get_feature_tags (unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + hb_tag_t *feature_tags /* OUT */) const + { return (this+featureList).get_tags (start_offset, feature_count, feature_tags); } + inline const Feature& get_feature (unsigned int i) const + { return (this+featureList)[i]; } + inline bool find_feature_index (hb_tag_t tag, unsigned int *index) const + { return (this+featureList).find_index (tag, index); } + + inline unsigned int get_lookup_count (void) const + { return (this+lookupList).len; } + inline const Lookup& get_lookup (unsigned int i) const + { return (this+lookupList)[i]; } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) && + scriptList.sanitize (c, this) && + featureList.sanitize (c, this) && + lookupList.sanitize (c, this)); + } + + protected: + FixedVersion version; /* Version of the GSUB/GPOS table--initially set + * to 0x00010000 */ + OffsetTo<ScriptList> + scriptList; /* ScriptList table */ + OffsetTo<FeatureList> + featureList; /* FeatureList table */ + OffsetTo<LookupList> + lookupList; /* LookupList table */ + public: + DEFINE_SIZE_STATIC (10); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_LAYOUT_GSUBGPOS_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-private.hh new file mode 100644 index 00000000000..49093de8a1e --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout-private.hh @@ -0,0 +1,220 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2012 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_OT_LAYOUT_PRIVATE_HH +#define HB_OT_LAYOUT_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-ot-layout.h" + +#include "hb-font-private.hh" +#include "hb-buffer-private.hh" +#include "hb-set-private.hh" + + +/* buffer var allocations, used during the GSUB/GPOS processing */ +#define glyph_props() var1.u16[0] /* GDEF glyph properties */ +#define syllable() var1.u8[2] /* GSUB/GPOS shaping boundaries */ +#define lig_props() var1.u8[3] /* GSUB/GPOS ligature tracking */ + +#define hb_ot_layout_from_face(face) ((hb_ot_layout_t *) face->shaper_data.ot) + +/* + * GDEF + */ + +typedef enum { + HB_OT_LAYOUT_GLYPH_PROPS_UNCLASSIFIED = 0x0001, + HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH = 0x0002, + HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE = 0x0004, + HB_OT_LAYOUT_GLYPH_PROPS_MARK = 0x0008, + HB_OT_LAYOUT_GLYPH_PROPS_COMPONENT = 0x0010 +} hb_ot_layout_glyph_class_mask_t; + + + +/* + * GSUB/GPOS + */ + +/* lig_id / lig_comp + * + * When a ligature is formed: + * + * - The ligature glyph and any marks in between all the same newly allocated + * lig_id, + * - The ligature glyph will get lig_num_comps set to the number of components + * - The marks get lig_comp > 0, reflecting which component of the ligature + * they were applied to. + * - This is used in GPOS to attach marks to the right component of a ligature + * in MarkLigPos. + * + * When a multiple-substitution is done: + * + * - All resulting glyphs will have lig_id = 0, + * - The resulting glyphs will have lig_comp = 0, 1, 2, ... respectively. + * - This is used in GPOS to attach marks to the first component of a + * multiple substitution in MarkBasePos. + * + * The numbers are also used in GPOS to do mark-to-mark positioning only + * to marks that belong to the same component of a ligature in MarkMarPos. + */ +#define IS_LIG_BASE 0x10 +static inline void +set_lig_props_for_ligature (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_num_comps) +{ + info.lig_props() = (lig_id << 5) | IS_LIG_BASE | (lig_num_comps & 0x0F); +} +static inline void +set_lig_props_for_mark (hb_glyph_info_t &info, unsigned int lig_id, unsigned int lig_comp) +{ + info.lig_props() = (lig_id << 5) | (lig_comp & 0x0F); +} +static inline void +set_lig_props_for_component (hb_glyph_info_t &info, unsigned int comp) +{ + set_lig_props_for_mark (info, 0, comp); +} + +static inline unsigned int +get_lig_id (const hb_glyph_info_t &info) +{ + return info.lig_props() >> 5; +} +static inline bool +is_a_ligature (const hb_glyph_info_t &info) +{ + return !!(info.lig_props() & IS_LIG_BASE); +} +static inline unsigned int +get_lig_comp (const hb_glyph_info_t &info) +{ + if (is_a_ligature (info)) + return 0; + else + return info.lig_props() & 0x0F; +} +static inline unsigned int +get_lig_num_comps (const hb_glyph_info_t &info) +{ + if ((info.glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE) && is_a_ligature (info)) + return info.lig_props() & 0x0F; + else + return 1; +} + +static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) { + uint8_t lig_id = buffer->next_serial () & 0x07; + if (unlikely (!lig_id)) + lig_id = allocate_lig_id (buffer); /* in case of overflow */ + return lig_id; +} + + +HB_INTERNAL hb_bool_t +hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, + unsigned int lookup_index, + const hb_codepoint_t *glyphs, + unsigned int glyphs_length, + hb_bool_t zero_context); + + +/* Should be called before all the substitute_lookup's are done. */ +HB_INTERNAL void +hb_ot_layout_substitute_start (hb_font_t *font, + hb_buffer_t *buffer); + +HB_INTERNAL hb_bool_t +hb_ot_layout_substitute_lookup (hb_font_t *font, + hb_buffer_t *buffer, + unsigned int lookup_index, + hb_mask_t mask); + +/* Should be called after all the substitute_lookup's are done */ +HB_INTERNAL void +hb_ot_layout_substitute_finish (hb_font_t *font, + hb_buffer_t *buffer); + + +/* Should be called before all the position_lookup's are done. Resets positions to zero. */ +HB_INTERNAL void +hb_ot_layout_position_start (hb_font_t *font, + hb_buffer_t *buffer); + +HB_INTERNAL hb_bool_t +hb_ot_layout_position_lookup (hb_font_t *font, + hb_buffer_t *buffer, + unsigned int lookup_index, + hb_mask_t mask); + +/* Should be called after all the position_lookup's are done */ +HB_INTERNAL void +hb_ot_layout_position_finish (hb_font_t *font, + hb_buffer_t *buffer, + hb_bool_t zero_width_attached_marks); + + + +/* + * hb_ot_layout_t + */ + +namespace OT { + struct GDEF; + struct GSUB; + struct GPOS; +} + +struct hb_ot_layout_t +{ + hb_blob_t *gdef_blob; + hb_blob_t *gsub_blob; + hb_blob_t *gpos_blob; + + const struct OT::GDEF *gdef; + const struct OT::GSUB *gsub; + const struct OT::GPOS *gpos; + + unsigned int gsub_lookup_count; + unsigned int gpos_lookup_count; + + hb_set_digest_t *gsub_digests; + hb_set_digest_t *gpos_digests; +}; + + +HB_INTERNAL hb_ot_layout_t * +_hb_ot_layout_create (hb_face_t *face); + +HB_INTERNAL void +_hb_ot_layout_destroy (hb_ot_layout_t *layout); + + + +#endif /* HB_OT_LAYOUT_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.cc new file mode 100644 index 00000000000..5c266e61942 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.cc @@ -0,0 +1,772 @@ +/* + * Copyright © 1998-2004 David Turner and Werner Lemberg + * Copyright © 2006 Behdad Esfahbod + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2012 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 + */ + +#include "hb-ot-layout-private.hh" + +#include "hb-ot-layout-gdef-table.hh" +#include "hb-ot-layout-gsub-table.hh" +#include "hb-ot-layout-gpos-table.hh" + +#include <stdlib.h> +#include <string.h> + + +HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) + +hb_ot_layout_t * +_hb_ot_layout_create (hb_face_t *face) +{ + hb_ot_layout_t *layout = (hb_ot_layout_t *) calloc (1, sizeof (hb_ot_layout_t)); + if (unlikely (!layout)) + return NULL; + + layout->gdef_blob = OT::Sanitizer<OT::GDEF>::sanitize (face->reference_table (HB_OT_TAG_GDEF)); + layout->gdef = OT::Sanitizer<OT::GDEF>::lock_instance (layout->gdef_blob); + + layout->gsub_blob = OT::Sanitizer<OT::GSUB>::sanitize (face->reference_table (HB_OT_TAG_GSUB)); + layout->gsub = OT::Sanitizer<OT::GSUB>::lock_instance (layout->gsub_blob); + + layout->gpos_blob = OT::Sanitizer<OT::GPOS>::sanitize (face->reference_table (HB_OT_TAG_GPOS)); + layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); + + layout->gsub_lookup_count = layout->gsub->get_lookup_count (); + layout->gpos_lookup_count = layout->gpos->get_lookup_count (); + + layout->gsub_digests = (hb_set_digest_t *) calloc (layout->gsub->get_lookup_count (), sizeof (hb_set_digest_t)); + layout->gpos_digests = (hb_set_digest_t *) calloc (layout->gpos->get_lookup_count (), sizeof (hb_set_digest_t)); + + if (unlikely ((layout->gsub_lookup_count && !layout->gsub_digests) || + (layout->gpos_lookup_count && !layout->gpos_digests))) + { + _hb_ot_layout_destroy (layout); + return NULL; + } + + for (unsigned int i = 0; i < layout->gsub_lookup_count; i++) + layout->gsub->get_lookup (i).add_coverage (&layout->gsub_digests[i]); + for (unsigned int i = 0; i < layout->gpos_lookup_count; i++) + layout->gpos->get_lookup (i).add_coverage (&layout->gpos_digests[i]); + + return layout; +} + +void +_hb_ot_layout_destroy (hb_ot_layout_t *layout) +{ + hb_blob_destroy (layout->gdef_blob); + hb_blob_destroy (layout->gsub_blob); + hb_blob_destroy (layout->gpos_blob); + + free (layout->gsub_digests); + free (layout->gpos_digests); + + free (layout); +} + +static inline const OT::GDEF& +_get_gdef (hb_face_t *face) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GDEF); + return *hb_ot_layout_from_face (face)->gdef; +} +static inline const OT::GSUB& +_get_gsub (hb_face_t *face) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GSUB); + return *hb_ot_layout_from_face (face)->gsub; +} +static inline const OT::GPOS& +_get_gpos (hb_face_t *face) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::GPOS); + return *hb_ot_layout_from_face (face)->gpos; +} + + +/* + * GDEF + */ + +hb_bool_t +hb_ot_layout_has_glyph_classes (hb_face_t *face) +{ + return _get_gdef (face).has_glyph_classes (); +} + +hb_ot_layout_glyph_class_t +hb_ot_layout_get_glyph_class (hb_face_t *face, + hb_codepoint_t glyph) +{ + return (hb_ot_layout_glyph_class_t) _get_gdef (face).get_glyph_class (glyph); +} + +void +hb_ot_layout_get_glyphs_in_class (hb_face_t *face, + hb_ot_layout_glyph_class_t klass, + hb_set_t *glyphs /* OUT */) +{ + return _get_gdef (face).get_glyphs_in_class (klass, glyphs); +} + +unsigned int +hb_ot_layout_get_attach_points (hb_face_t *face, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *point_count /* IN/OUT */, + unsigned int *point_array /* OUT */) +{ + return _get_gdef (face).get_attach_points (glyph, start_offset, point_count, point_array); +} + +unsigned int +hb_ot_layout_get_ligature_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + int *caret_array /* OUT */) +{ + return _get_gdef (font->face).get_lig_carets (font, direction, glyph, start_offset, caret_count, caret_array); +} + + +/* + * GSUB/GPOS + */ + +static const OT::GSUBGPOS& +get_gsubgpos_table (hb_face_t *face, + hb_tag_t table_tag) +{ + switch (table_tag) { + case HB_OT_TAG_GSUB: return _get_gsub (face); + case HB_OT_TAG_GPOS: return _get_gpos (face); + default: return OT::Null(OT::GSUBGPOS); + } +} + + +unsigned int +hb_ot_layout_table_get_script_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int start_offset, + unsigned int *script_count /* IN/OUT */, + hb_tag_t *script_tags /* OUT */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + + return g.get_script_tags (start_offset, script_count, script_tags); +} + +hb_bool_t +hb_ot_layout_table_find_script (hb_face_t *face, + hb_tag_t table_tag, + hb_tag_t script_tag, + unsigned int *script_index) +{ + ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + + if (g.find_script_index (script_tag, script_index)) + return true; + + /* try finding 'DFLT' */ + if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) + return false; + + /* try with 'dflt'; MS site has had typos and many fonts use it now :(. + * including many versions of DejaVu Sans Mono! */ + if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) + return false; + + if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; + return false; +} + +hb_bool_t +hb_ot_layout_table_choose_script (hb_face_t *face, + hb_tag_t table_tag, + const hb_tag_t *script_tags, + unsigned int *script_index, + hb_tag_t *chosen_script) +{ + ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_SCRIPT_INDEX); + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + + while (*script_tags) + { + if (g.find_script_index (*script_tags, script_index)) { + if (chosen_script) + *chosen_script = *script_tags; + return true; + } + script_tags++; + } + + /* try finding 'DFLT' */ + if (g.find_script_index (HB_OT_TAG_DEFAULT_SCRIPT, script_index)) { + if (chosen_script) + *chosen_script = HB_OT_TAG_DEFAULT_SCRIPT; + return false; + } + + /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ + if (g.find_script_index (HB_OT_TAG_DEFAULT_LANGUAGE, script_index)) { + if (chosen_script) + *chosen_script = HB_OT_TAG_DEFAULT_LANGUAGE; + return false; + } + + /* try with 'latn'; some old fonts put their features there even though + they're really trying to support Thai, for example :( */ +#define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') + if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { + if (chosen_script) + *chosen_script = HB_OT_TAG_LATIN_SCRIPT; + return false; + } + + if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; + if (chosen_script) + *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX; + return false; +} + +unsigned int +hb_ot_layout_table_get_feature_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + hb_tag_t *feature_tags /* OUT */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + + return g.get_feature_tags (start_offset, feature_count, feature_tags); +} + + +unsigned int +hb_ot_layout_script_get_language_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int start_offset, + unsigned int *language_count /* IN/OUT */, + hb_tag_t *language_tags /* OUT */) +{ + const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); + + return s.get_lang_sys_tags (start_offset, language_count, language_tags); +} + +hb_bool_t +hb_ot_layout_script_find_language (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + hb_tag_t language_tag, + unsigned int *language_index) +{ + ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX); + const OT::Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index); + + if (s.find_lang_sys_index (language_tag, language_index)) + return true; + + /* try with 'dflt'; MS site has had typos and many fonts use it now :( */ + if (s.find_lang_sys_index (HB_OT_TAG_DEFAULT_LANGUAGE, language_index)) + return false; + + if (language_index) *language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX; + return false; +} + +hb_bool_t +hb_ot_layout_language_get_required_feature_index (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int *feature_index) +{ + const OT::LangSys &l = get_gsubgpos_table (face, table_tag).get_script (script_index).get_lang_sys (language_index); + + if (feature_index) *feature_index = l.get_required_feature_index (); + + return l.has_required_feature (); +} + +unsigned int +hb_ot_layout_language_get_feature_indexes (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + unsigned int *feature_indexes /* OUT */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); + + return l.get_feature_indexes (start_offset, feature_count, feature_indexes); +} + +unsigned int +hb_ot_layout_language_get_feature_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + hb_tag_t *feature_tags /* OUT */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); + + ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t)); + unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags); + + if (feature_tags) { + unsigned int count = *feature_count; + for (unsigned int i = 0; i < count; i++) + feature_tags[i] = g.get_feature_tag ((unsigned int) feature_tags[i]); + } + + return ret; +} + + +hb_bool_t +hb_ot_layout_language_find_feature (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + hb_tag_t feature_tag, + unsigned int *feature_index) +{ + ASSERT_STATIC (OT::Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX); + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + const OT::LangSys &l = g.get_script (script_index).get_lang_sys (language_index); + + unsigned int num_features = l.get_feature_count (); + for (unsigned int i = 0; i < num_features; i++) { + unsigned int f_index = l.get_feature_index (i); + + if (feature_tag == g.get_feature_tag (f_index)) { + if (feature_index) *feature_index = f_index; + return true; + } + } + + if (feature_index) *feature_index = HB_OT_LAYOUT_NO_FEATURE_INDEX; + return false; +} + +unsigned int +hb_ot_layout_feature_get_lookups (hb_face_t *face, + hb_tag_t table_tag, + unsigned int feature_index, + unsigned int start_offset, + unsigned int *lookup_count /* IN/OUT */, + unsigned int *lookup_indexes /* OUT */) +{ + const OT::GSUBGPOS &g = get_gsubgpos_table (face, table_tag); + const OT::Feature &f = g.get_feature (feature_index); + + return f.get_lookup_indexes (start_offset, lookup_count, lookup_indexes); +} + +static void +_hb_ot_layout_collect_lookups_lookups (hb_face_t *face, + hb_tag_t table_tag, + unsigned int feature_index, + hb_set_t *lookup_indexes /* OUT */) +{ + unsigned int lookup_indices[32]; + unsigned int offset, len; + + offset = 0; + do { + len = ARRAY_LENGTH (lookup_indices); + hb_ot_layout_feature_get_lookups (face, + table_tag, + feature_index, + offset, &len, + lookup_indices); + + for (unsigned int i = 0; i < len; i++) + lookup_indexes->add (lookup_indices[i]); + + offset += len; + } while (len == ARRAY_LENGTH (lookup_indices)); +} + +static void +_hb_ot_layout_collect_lookups_features (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + const hb_tag_t *features, + hb_set_t *lookup_indexes /* OUT */) +{ + unsigned int required_feature_index; + if (hb_ot_layout_language_get_required_feature_index (face, + table_tag, + script_index, + language_index, + &required_feature_index)) + _hb_ot_layout_collect_lookups_lookups (face, + table_tag, + required_feature_index, + lookup_indexes); + + if (!features) + { + /* All features */ + unsigned int feature_indices[32]; + unsigned int offset, len; + + offset = 0; + do { + len = ARRAY_LENGTH (feature_indices); + hb_ot_layout_language_get_feature_indexes (face, + table_tag, + script_index, + language_index, + offset, &len, + feature_indices); + + for (unsigned int i = 0; i < len; i++) + _hb_ot_layout_collect_lookups_lookups (face, + table_tag, + feature_indices[i], + lookup_indexes); + + offset += len; + } while (len == ARRAY_LENGTH (feature_indices)); + } + else + { + for (; *features; features++) + { + unsigned int feature_index; + if (hb_ot_layout_language_find_feature (face, + table_tag, + script_index, + language_index, + *features, + &feature_index)) + _hb_ot_layout_collect_lookups_lookups (face, + table_tag, + feature_index, + lookup_indexes); + } + } +} + +static void +_hb_ot_layout_collect_lookups_languages (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + const hb_tag_t *languages, + const hb_tag_t *features, + hb_set_t *lookup_indexes /* OUT */) +{ + _hb_ot_layout_collect_lookups_features (face, + table_tag, + script_index, + HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX, + features, + lookup_indexes); + + if (!languages) + { + /* All languages */ + unsigned int count = hb_ot_layout_script_get_language_tags (face, + table_tag, + script_index, + 0, NULL, NULL); + for (unsigned int language_index = 0; language_index < count; language_index++) + _hb_ot_layout_collect_lookups_features (face, + table_tag, + script_index, + language_index, + features, + lookup_indexes); + } + else + { + for (; *languages; languages++) + { + unsigned int language_index; + if (hb_ot_layout_script_find_language (face, + table_tag, + script_index, + *languages, + &language_index)) + _hb_ot_layout_collect_lookups_features (face, + table_tag, + script_index, + language_index, + features, + lookup_indexes); + } + } +} + +void +hb_ot_layout_collect_lookups (hb_face_t *face, + hb_tag_t table_tag, + const hb_tag_t *scripts, + const hb_tag_t *languages, + const hb_tag_t *features, + hb_set_t *lookup_indexes /* OUT */) +{ + if (!scripts) + { + /* All scripts */ + unsigned int count = hb_ot_layout_table_get_script_tags (face, + table_tag, + 0, NULL, NULL); + for (unsigned int script_index = 0; script_index < count; script_index++) + _hb_ot_layout_collect_lookups_languages (face, + table_tag, + script_index, + languages, + features, + lookup_indexes); + } + else + { + for (; *scripts; scripts++) + { + unsigned int script_index; + if (hb_ot_layout_table_find_script (face, + table_tag, + *scripts, + &script_index)) + _hb_ot_layout_collect_lookups_languages (face, + table_tag, + script_index, + languages, + features, + lookup_indexes); + } + } +} + +void +hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, + hb_tag_t table_tag, + unsigned int lookup_index, + hb_set_t *glyphs_before, /* OUT. May be NULL */ + hb_set_t *glyphs_input, /* OUT. May be NULL */ + hb_set_t *glyphs_after, /* OUT. May be NULL */ + hb_set_t *glyphs_output /* OUT. May be NULL */) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return; + + OT::hb_collect_glyphs_context_t c (face, + glyphs_before, + glyphs_input, + glyphs_after, + glyphs_output); + + switch (table_tag) + { + case HB_OT_TAG_GSUB: + { + const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); + l.collect_glyphs_lookup (&c); + return; + } + case HB_OT_TAG_GPOS: + { + const OT::PosLookup& l = hb_ot_layout_from_face (face)->gpos->get_lookup (lookup_index); + l.collect_glyphs_lookup (&c); + return; + } + } +} + + +/* + * OT::GSUB + */ + +hb_bool_t +hb_ot_layout_has_substitution (hb_face_t *face) +{ + return &_get_gsub (face) != &OT::Null(OT::GSUB); +} + +hb_bool_t +hb_ot_layout_lookup_would_substitute (hb_face_t *face, + unsigned int lookup_index, + const hb_codepoint_t *glyphs, + unsigned int glyphs_length, + hb_bool_t zero_context) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return false; + return hb_ot_layout_lookup_would_substitute_fast (face, lookup_index, glyphs, glyphs_length, zero_context); +} + +hb_bool_t +hb_ot_layout_lookup_would_substitute_fast (hb_face_t *face, + unsigned int lookup_index, + const hb_codepoint_t *glyphs, + unsigned int glyphs_length, + hb_bool_t zero_context) +{ + if (unlikely (lookup_index >= hb_ot_layout_from_face (face)->gsub_lookup_count)) return false; + OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, zero_context); + + const OT::SubstLookup& l = hb_ot_layout_from_face (face)->gsub->get_lookup (lookup_index); + + return l.would_apply (&c, &hb_ot_layout_from_face (face)->gsub_digests[lookup_index]); +} + +void +hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer) +{ + OT::GSUB::substitute_start (font, buffer); +} + +hb_bool_t +hb_ot_layout_substitute_lookup (hb_font_t *font, + hb_buffer_t *buffer, + unsigned int lookup_index, + hb_mask_t mask) +{ + if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gsub_lookup_count)) return false; + + OT::hb_apply_context_t c (font, buffer, mask); + + const OT::SubstLookup& l = hb_ot_layout_from_face (font->face)->gsub->get_lookup (lookup_index); + + return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gsub_digests[lookup_index]); +} + +void +hb_ot_layout_substitute_finish (hb_font_t *font, hb_buffer_t *buffer) +{ + OT::GSUB::substitute_finish (font, buffer); +} + +void +hb_ot_layout_lookup_substitute_closure (hb_face_t *face, + unsigned int lookup_index, + hb_set_t *glyphs) +{ + OT::hb_closure_context_t c (face, glyphs); + + const OT::SubstLookup& l = _get_gsub (face).get_lookup (lookup_index); + + l.closure (&c); +} + +/* + * OT::GPOS + */ + +hb_bool_t +hb_ot_layout_has_positioning (hb_face_t *face) +{ + return &_get_gpos (face) != &OT::Null(OT::GPOS); +} + +void +hb_ot_layout_position_start (hb_font_t *font, hb_buffer_t *buffer) +{ + OT::GPOS::position_start (font, buffer); +} + +hb_bool_t +hb_ot_layout_position_lookup (hb_font_t *font, + hb_buffer_t *buffer, + unsigned int lookup_index, + hb_mask_t mask) +{ + if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gpos_lookup_count)) return false; + + OT::hb_apply_context_t c (font, buffer, mask); + + const OT::PosLookup& l = hb_ot_layout_from_face (font->face)->gpos->get_lookup (lookup_index); + + return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gpos_digests[lookup_index]); +} + +void +hb_ot_layout_position_finish (hb_font_t *font, hb_buffer_t *buffer, hb_bool_t zero_width_attached_marks) +{ + OT::GPOS::position_finish (font, buffer, zero_width_attached_marks); +} + +hb_bool_t +hb_ot_layout_get_size_params (hb_face_t *face, + unsigned int *design_size, /* OUT. May be NULL */ + unsigned int *subfamily_id, /* OUT. May be NULL */ + unsigned int *subfamily_name_id, /* OUT. May be NULL */ + unsigned int *range_start, /* OUT. May be NULL */ + unsigned int *range_end /* OUT. May be NULL */) +{ + const OT::GPOS &gpos = _get_gpos (face); + const hb_tag_t tag = HB_TAG ('s','i','z','e'); + + unsigned int num_features = gpos.get_feature_count (); + for (unsigned int i = 0; i < num_features; i++) + { + if (tag == gpos.get_feature_tag (i)) + { + const OT::Feature &f = gpos.get_feature (i); + const OT::FeatureParamsSize ¶ms = f.get_feature_params ().get_size_params (tag); + + if (params.designSize) + { +#define PARAM(a, A) if (a) *a = params.A + PARAM (design_size, designSize); + PARAM (subfamily_id, subfamilyID); + PARAM (subfamily_name_id, subfamilyNameID); + PARAM (range_start, rangeStart); + PARAM (range_end, rangeEnd); +#undef PARAM + + return true; + } + } + } + +#define PARAM(a, A) if (a) *a = 0 + PARAM (design_size, designSize); + PARAM (subfamily_id, subfamilyID); + PARAM (subfamily_name_id, subfamilyNameID); + PARAM (range_start, rangeStart); + PARAM (range_end, rangeEnd); +#undef PARAM + + return false; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.h new file mode 100644 index 00000000000..134f1a6c164 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-layout.h @@ -0,0 +1,293 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, 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 + */ + +#ifndef HB_OT_H_IN +#error "Include <hb-ot.h> instead." +#endif + +#ifndef HB_OT_LAYOUT_H +#define HB_OT_LAYOUT_H + +#include "hb.h" + +#include "hb-ot-tag.h" + +HB_BEGIN_DECLS + + +#define HB_OT_TAG_GDEF HB_TAG('G','D','E','F') +#define HB_OT_TAG_GSUB HB_TAG('G','S','U','B') +#define HB_OT_TAG_GPOS HB_TAG('G','P','O','S') + + +/* + * GDEF + */ + +hb_bool_t +hb_ot_layout_has_glyph_classes (hb_face_t *face); + +typedef enum { + HB_OT_LAYOUT_GLYPH_CLASS_UNCLASSIFIED = 0, + HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH = 1, + HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE = 2, + HB_OT_LAYOUT_GLYPH_CLASS_MARK = 3, + HB_OT_LAYOUT_GLYPH_CLASS_COMPONENT = 4 +} hb_ot_layout_glyph_class_t; + +hb_ot_layout_glyph_class_t +hb_ot_layout_get_glyph_class (hb_face_t *face, + hb_codepoint_t glyph); + +void +hb_ot_layout_get_glyphs_in_class (hb_face_t *face, + hb_ot_layout_glyph_class_t klass, + hb_set_t *glyphs /* OUT */); + + +/* Not that useful. Provides list of attach points for a glyph that a + * client may want to cache */ +unsigned int +hb_ot_layout_get_attach_points (hb_face_t *face, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *point_count /* IN/OUT */, + unsigned int *point_array /* OUT */); + +/* Ligature caret positions */ +unsigned int +hb_ot_layout_get_ligature_carets (hb_font_t *font, + hb_direction_t direction, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *caret_count /* IN/OUT */, + hb_position_t *caret_array /* OUT */); + + +/* + * GSUB/GPOS feature query and enumeration interface + */ + +#define HB_OT_LAYOUT_NO_SCRIPT_INDEX ((unsigned int) 0xFFFF) +#define HB_OT_LAYOUT_NO_FEATURE_INDEX ((unsigned int) 0xFFFF) +#define HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX ((unsigned int) 0xFFFF) + +unsigned int +hb_ot_layout_table_get_script_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int start_offset, + unsigned int *script_count /* IN/OUT */, + hb_tag_t *script_tags /* OUT */); + +hb_bool_t +hb_ot_layout_table_find_script (hb_face_t *face, + hb_tag_t table_tag, + hb_tag_t script_tag, + unsigned int *script_index); + +/* Like find_script, but takes zero-terminated array of scripts to test */ +hb_bool_t +hb_ot_layout_table_choose_script (hb_face_t *face, + hb_tag_t table_tag, + const hb_tag_t *script_tags, + unsigned int *script_index, + hb_tag_t *chosen_script); + +unsigned int +hb_ot_layout_table_get_feature_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + hb_tag_t *feature_tags /* OUT */); + +unsigned int +hb_ot_layout_script_get_language_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int start_offset, + unsigned int *language_count /* IN/OUT */, + hb_tag_t *language_tags /* OUT */); + +hb_bool_t +hb_ot_layout_script_find_language (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + hb_tag_t language_tag, + unsigned int *language_index); + +hb_bool_t +hb_ot_layout_language_get_required_feature_index (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int *feature_index); + +unsigned int +hb_ot_layout_language_get_feature_indexes (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + unsigned int *feature_indexes /* OUT */); + +unsigned int +hb_ot_layout_language_get_feature_tags (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + unsigned int start_offset, + unsigned int *feature_count /* IN/OUT */, + hb_tag_t *feature_tags /* OUT */); + +hb_bool_t +hb_ot_layout_language_find_feature (hb_face_t *face, + hb_tag_t table_tag, + unsigned int script_index, + unsigned int language_index, + hb_tag_t feature_tag, + unsigned int *feature_index); + +unsigned int +hb_ot_layout_feature_get_lookups (hb_face_t *face, + hb_tag_t table_tag, + unsigned int feature_index, + unsigned int start_offset, + unsigned int *lookup_count /* IN/OUT */, + unsigned int *lookup_indexes /* OUT */); + +void +hb_ot_layout_collect_lookups (hb_face_t *face, + hb_tag_t table_tag, + const hb_tag_t *scripts, + const hb_tag_t *languages, + const hb_tag_t *features, + hb_set_t *lookup_indexes /* OUT */); + +void +hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, + hb_tag_t table_tag, + hb_set_t *lookup_indexes /* OUT */); + +void +hb_ot_layout_lookup_collect_glyphs (hb_face_t *face, + hb_tag_t table_tag, + unsigned int lookup_index, + hb_set_t *glyphs_before, /* OUT. May be NULL */ + hb_set_t *glyphs_input, /* OUT. May be NULL */ + hb_set_t *glyphs_after, /* OUT. May be NULL */ + hb_set_t *glyphs_output /* OUT. May be NULL */); + +#ifdef HB_NOT_IMPLEMENTED +typedef struct +{ + const hb_codepoint_t *before, + unsigned int before_length, + const hb_codepoint_t *input, + unsigned int input_length, + const hb_codepoint_t *after, + unsigned int after_length, +} hb_ot_layout_glyph_sequence_t; + +typedef hb_bool_t +(*hb_ot_layout_glyph_sequence_func_t) (hb_font_t *font, + hb_tag_t table_tag, + unsigned int lookup_index, + const hb_ot_layout_glyph_sequence_t *sequence, + void *user_data); + +void +Xhb_ot_layout_lookup_enumerate_sequences (hb_face_t *face, + hb_tag_t table_tag, + unsigned int lookup_index, + hb_ot_layout_glyph_sequence_func_t callback, + void *user_data); +#endif + + +/* + * GSUB + */ + +hb_bool_t +hb_ot_layout_has_substitution (hb_face_t *face); + +hb_bool_t +hb_ot_layout_lookup_would_substitute (hb_face_t *face, + unsigned int lookup_index, + const hb_codepoint_t *glyphs, + unsigned int glyphs_length, + hb_bool_t zero_context); + +void +hb_ot_layout_lookup_substitute_closure (hb_face_t *face, + unsigned int lookup_index, + hb_set_t *glyphs + /*TODO , hb_bool_t inclusive */); + +#ifdef HB_NOT_IMPLEMENTED +/* Note: You better have GDEF when using this API, or marks won't do much. */ +hb_bool_t +Xhb_ot_layout_lookup_substitute (hb_font_t *font, + unsigned int lookup_index, + const hb_ot_layout_glyph_sequence_t *sequence, + unsigned int out_size, + hb_codepoint_t *glyphs_out, /* OUT */ + unsigned int *clusters_out, /* OUT */ + unsigned int *out_length /* OUT */); +#endif + + +/* + * GPOS + */ + +hb_bool_t +hb_ot_layout_has_positioning (hb_face_t *face); + +#ifdef HB_NOT_IMPLEMENTED +/* Note: You better have GDEF when using this API, or marks won't do much. */ +hb_bool_t +Xhb_ot_layout_lookup_position (hb_font_t *font, + unsigned int lookup_index, + const hb_ot_layout_glyph_sequence_t *sequence, + hb_glyph_position_t *positions /* IN / OUT */); +#endif + +/* Optical 'size' feature info. Returns true if found. + * http://www.microsoft.com/typography/otspec/features_pt.htm#size */ +hb_bool_t +hb_ot_layout_get_size_params (hb_face_t *face, + unsigned int *design_size, /* OUT. May be NULL */ + unsigned int *subfamily_id, /* OUT. May be NULL */ + unsigned int *subfamily_name_id, /* OUT. May be NULL */ + unsigned int *range_start, /* OUT. May be NULL */ + unsigned int *range_end /* OUT. May be NULL */); + + +HB_END_DECLS + +#endif /* HB_OT_LAYOUT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map-private.hh new file mode 100644 index 00000000000..b140207aa97 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map-private.hh @@ -0,0 +1,214 @@ +/* + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2010,2011,2012 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_OT_MAP_PRIVATE_HH +#define HB_OT_MAP_PRIVATE_HH + +#include "hb-buffer-private.hh" + +#include "hb-ot-layout-private.hh" + + +static const hb_tag_t table_tags[2] = {HB_OT_TAG_GSUB, HB_OT_TAG_GPOS}; + +struct hb_ot_map_t +{ + friend struct hb_ot_map_builder_t; + + public: + + struct feature_map_t { + hb_tag_t tag; /* should be first for our bsearch to work */ + unsigned int index[2]; /* GSUB/GPOS */ + unsigned int stage[2]; /* GSUB/GPOS */ + unsigned int shift; + hb_mask_t mask; + hb_mask_t _1_mask; /* mask for value=1, for quick access */ + hb_bool_t needs_fallback; + + static int cmp (const feature_map_t *a, const feature_map_t *b) + { return a->tag < b->tag ? -1 : a->tag > b->tag ? 1 : 0; } + }; + + struct lookup_map_t { + unsigned int index; + hb_mask_t mask; + + static int cmp (const lookup_map_t *a, const lookup_map_t *b) + { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; } + }; + + typedef void (*pause_func_t) (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer); + + struct pause_map_t { + unsigned int num_lookups; /* Cumulative */ + pause_func_t callback; + }; + + + hb_ot_map_t (void) { memset (this, 0, sizeof (*this)); } + + inline hb_mask_t get_global_mask (void) const { return global_mask; } + + inline hb_mask_t get_mask (hb_tag_t feature_tag, unsigned int *shift = NULL) const { + const feature_map_t *map = features.bsearch (&feature_tag); + if (shift) *shift = map ? map->shift : 0; + return map ? map->mask : 0; + } + + inline bool needs_fallback (hb_tag_t feature_tag) const { + const feature_map_t *map = features.bsearch (&feature_tag); + return map ? map->needs_fallback : false; + } + + inline hb_mask_t get_1_mask (hb_tag_t feature_tag) const { + const feature_map_t *map = features.bsearch (&feature_tag); + return map ? map->_1_mask : 0; + } + + inline unsigned int get_feature_index (unsigned int table_index, hb_tag_t feature_tag) const { + const feature_map_t *map = features.bsearch (&feature_tag); + return map ? map->index[table_index] : HB_OT_LAYOUT_NO_FEATURE_INDEX; + } + + inline unsigned int get_feature_stage (unsigned int table_index, hb_tag_t feature_tag) const { + const feature_map_t *map = features.bsearch (&feature_tag); + return map ? map->stage[table_index] : (unsigned int) -1; + } + + inline void get_stage_lookups (unsigned int table_index, unsigned int stage, + const struct lookup_map_t **plookups, unsigned int *lookup_count) const { + if (unlikely (stage == (unsigned int) -1)) { + *plookups = NULL; + *lookup_count = 0; + return; + } + assert (stage <= pauses[table_index].len); + unsigned int start = stage ? pauses[table_index][stage - 1].num_lookups : 0; + unsigned int end = stage < pauses[table_index].len ? pauses[table_index][stage].num_lookups : lookups[table_index].len; + *plookups = &lookups[table_index][start]; + *lookup_count = end - start; + } + + HB_INTERNAL void collect_lookups (unsigned int table_index, hb_set_t *lookups) const; + HB_INTERNAL void substitute (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; + HB_INTERNAL void position (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; + + inline void finish (void) { + features.finish (); + lookups[0].finish (); + lookups[1].finish (); + pauses[0].finish (); + pauses[1].finish (); + } + + public: + hb_tag_t chosen_script[2]; + bool found_script[2]; + + private: + + HB_INTERNAL void add_lookups (hb_face_t *face, + unsigned int table_index, + unsigned int feature_index, + hb_mask_t mask); + + hb_mask_t global_mask; + + hb_prealloced_array_t<feature_map_t, 8> features; + hb_prealloced_array_t<lookup_map_t, 32> lookups[2]; /* GSUB/GPOS */ + hb_prealloced_array_t<pause_map_t, 1> pauses[2]; /* GSUB/GPOS */ +}; + + +struct hb_ot_map_builder_t +{ + public: + + HB_INTERNAL hb_ot_map_builder_t (hb_face_t *face_, + const hb_segment_properties_t *props_); + + HB_INTERNAL void add_feature (hb_tag_t tag, unsigned int value, bool global, bool has_fallback = false); + + inline void add_bool_feature (hb_tag_t tag, bool global = true, bool has_fallback = false) + { add_feature (tag, 1, global, has_fallback); } + + inline void add_gsub_pause (hb_ot_map_t::pause_func_t pause_func) + { add_pause (0, pause_func); } + inline void add_gpos_pause (hb_ot_map_t::pause_func_t pause_func) + { add_pause (1, pause_func); } + + HB_INTERNAL void compile (struct hb_ot_map_t &m); + + inline void finish (void) { + feature_infos.finish (); + pauses[0].finish (); + pauses[1].finish (); + } + + private: + + struct feature_info_t { + hb_tag_t tag; + unsigned int seq; /* sequence#, used for stable sorting only */ + unsigned int max_value; + bool global; /* whether the feature applies value to every glyph in the buffer */ + bool has_fallback; /* whether to allocate bits even if feature not found */ + unsigned int default_value; /* for non-global features, what should the unset glyphs take */ + unsigned int stage[2]; /* GSUB/GPOS */ + + static int cmp (const feature_info_t *a, const feature_info_t *b) + { return (a->tag != b->tag) ? (a->tag < b->tag ? -1 : 1) : (a->seq < b->seq ? -1 : 1); } + }; + + struct pause_info_t { + unsigned int stage; + hb_ot_map_t::pause_func_t callback; + }; + + HB_INTERNAL void add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func); + + public: + + hb_face_t *face; + hb_segment_properties_t props; + + hb_tag_t chosen_script[2]; + bool found_script[2]; + unsigned int script_index[2], language_index[2]; + + private: + + unsigned int current_stage[2]; /* GSUB/GPOS */ + hb_prealloced_array_t<feature_info_t,16> feature_infos; + hb_prealloced_array_t<pause_info_t, 1> pauses[2]; /* GSUB/GPOS */ +}; + + + +#endif /* HB_OT_MAP_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map.cc new file mode 100644 index 00000000000..62f7904b2f9 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-map.cc @@ -0,0 +1,304 @@ +/* + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2010,2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-map-private.hh" + + +void +hb_ot_map_t::add_lookups (hb_face_t *face, + unsigned int table_index, + unsigned int feature_index, + hb_mask_t mask) +{ + unsigned int lookup_indices[32]; + unsigned int offset, len; + + offset = 0; + do { + len = ARRAY_LENGTH (lookup_indices); + hb_ot_layout_feature_get_lookups (face, + table_tags[table_index], + feature_index, + offset, &len, + lookup_indices); + + for (unsigned int i = 0; i < len; i++) { + hb_ot_map_t::lookup_map_t *lookup = lookups[table_index].push (); + if (unlikely (!lookup)) + return; + lookup->mask = mask; + lookup->index = lookup_indices[i]; + } + + offset += len; + } while (len == ARRAY_LENGTH (lookup_indices)); +} + +hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_, + const hb_segment_properties_t *props_) +{ + memset (this, 0, sizeof (*this)); + + face = face_; + props = *props_; + + + /* Fetch script/language indices for GSUB/GPOS. We need these later to skip + * features not available in either table and not waste precious bits for them. */ + + hb_tag_t script_tags[3] = {HB_TAG_NONE, HB_TAG_NONE, HB_TAG_NONE}; + hb_tag_t language_tag; + + hb_ot_tags_from_script (props.script, &script_tags[0], &script_tags[1]); + language_tag = hb_ot_tag_from_language (props.language); + + for (unsigned int table_index = 0; table_index < 2; table_index++) { + hb_tag_t table_tag = table_tags[table_index]; + found_script[table_index] = hb_ot_layout_table_choose_script (face, table_tag, script_tags, &script_index[table_index], &chosen_script[table_index]); + hb_ot_layout_script_find_language (face, table_tag, script_index[table_index], language_tag, &language_index[table_index]); + } +} + +void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, bool global, bool has_fallback) +{ + feature_info_t *info = feature_infos.push(); + if (unlikely (!info)) return; + info->tag = tag; + info->seq = feature_infos.len; + info->max_value = value; + info->global = global; + info->has_fallback = has_fallback; + info->default_value = global ? value : 0; + info->stage[0] = current_stage[0]; + info->stage[1] = current_stage[1]; +} + +/* Keep the next two functions in sync. */ + +void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const +{ + const unsigned int table_index = 0; + unsigned int i = 0; + + for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) { + const pause_map_t *pause = &pauses[table_index][pause_index]; + for (; i < pause->num_lookups; i++) + hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); + + buffer->clear_output (); + + if (pause->callback) + pause->callback (plan, font, buffer); + } + + for (; i < lookups[table_index].len; i++) + hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); +} + +void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const +{ + const unsigned int table_index = 1; + unsigned int i = 0; + + for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; pause_index++) { + const pause_map_t *pause = &pauses[table_index][pause_index]; + for (; i < pause->num_lookups; i++) + hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); + + if (pause->callback) + pause->callback (plan, font, buffer); + } + + for (; i < lookups[table_index].len; i++) + hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); +} + +void hb_ot_map_t::collect_lookups (unsigned int table_index, hb_set_t *lookups_out) const +{ + for (unsigned int i = 0; i < lookups[table_index].len; i++) + hb_set_add (lookups_out, lookups[table_index][i].index); +} + +void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func) +{ + pause_info_t *p = pauses[table_index].push (); + if (likely (p)) { + p->stage = current_stage[table_index]; + p->callback = pause_func; + } + + current_stage[table_index]++; +} + +void +hb_ot_map_builder_t::compile (hb_ot_map_t &m) +{ + m.global_mask = 1; + + for (unsigned int table_index = 0; table_index < 2; table_index++) { + m.chosen_script[table_index] = chosen_script[table_index]; + m.found_script[table_index] = found_script[table_index]; + } + + if (!feature_infos.len) + return; + + /* Sort features and merge duplicates */ + { + feature_infos.sort (); + unsigned int j = 0; + for (unsigned int i = 1; i < feature_infos.len; i++) + if (feature_infos[i].tag != feature_infos[j].tag) + feature_infos[++j] = feature_infos[i]; + else { + if (feature_infos[i].global) { + feature_infos[j].global = true; + feature_infos[j].max_value = feature_infos[i].max_value; + feature_infos[j].default_value = feature_infos[i].default_value; + } else { + feature_infos[j].global = false; + feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_infos[i].max_value); + } + feature_infos[j].has_fallback = feature_infos[j].has_fallback || feature_infos[i].has_fallback; + feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_infos[i].stage[0]); + feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_infos[i].stage[1]); + /* Inherit default_value from j */ + } + feature_infos.shrink (j + 1); + } + + + /* Allocate bits now */ + unsigned int next_bit = 1; + for (unsigned int i = 0; i < feature_infos.len; i++) { + const feature_info_t *info = &feature_infos[i]; + + unsigned int bits_needed; + + if (info->global && info->max_value == 1) + /* Uses the global bit */ + bits_needed = 0; + else + bits_needed = _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. */ + + + bool found = false; + unsigned int feature_index[2]; + for (unsigned int table_index = 0; table_index < 2; table_index++) + found |= hb_ot_layout_language_find_feature (face, + table_tags[table_index], + script_index[table_index], + language_index[table_index], + info->tag, + &feature_index[table_index]); + if (!found && !info->has_fallback) + continue; + + + hb_ot_map_t::feature_map_t *map = m.features.push (); + if (unlikely (!map)) + break; + + map->tag = info->tag; + map->index[0] = feature_index[0]; + map->index[1] = feature_index[1]; + map->stage[0] = info->stage[0]; + map->stage[1] = info->stage[1]; + if (info->global && info->max_value == 1) { + /* Uses the global bit */ + map->shift = 0; + map->mask = 1; + } else { + map->shift = next_bit; + map->mask = (1 << (next_bit + bits_needed)) - (1 << next_bit); + next_bit += bits_needed; + if (info->global) + m.global_mask |= (info->default_value << map->shift) & map->mask; + } + map->_1_mask = (1 << map->shift) & map->mask; + map->needs_fallback = !found; + + } + feature_infos.shrink (0); /* Done with these */ + + + add_gsub_pause (NULL); + add_gpos_pause (NULL); + + for (unsigned int table_index = 0; table_index < 2; table_index++) { + hb_tag_t table_tag = table_tags[table_index]; + + /* Collect lookup indices for features */ + + unsigned int required_feature_index; + if (hb_ot_layout_language_get_required_feature_index (face, + table_tag, + script_index[table_index], + language_index[table_index], + &required_feature_index)) + m.add_lookups (face, table_index, required_feature_index, 1); + + unsigned int pause_index = 0; + unsigned int last_num_lookups = 0; + for (unsigned stage = 0; stage < current_stage[table_index]; stage++) + { + for (unsigned i = 0; i < m.features.len; i++) + if (m.features[i].stage[table_index] == stage) + m.add_lookups (face, table_index, m.features[i].index[table_index], m.features[i].mask); + + /* Sort lookups and merge duplicates */ + if (last_num_lookups < m.lookups[table_index].len) + { + m.lookups[table_index].sort (last_num_lookups, m.lookups[table_index].len); + + unsigned int j = last_num_lookups; + for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++) + if (m.lookups[table_index][i].index != m.lookups[table_index][j].index) + m.lookups[table_index][++j] = m.lookups[table_index][i]; + else + m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask; + m.lookups[table_index].shrink (j + 1); + } + + last_num_lookups = m.lookups[table_index].len; + + if (pause_index < pauses[table_index].len && pauses[table_index][pause_index].stage == stage) { + hb_ot_map_t::pause_map_t *pause_map = m.pauses[table_index].push (); + if (likely (pause_map)) { + pause_map->num_lookups = last_num_lookups; + pause_map->callback = pauses[table_index][pause_index].callback; + } + + pause_index++; + } + } + } +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-maxp-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-maxp-table.hh new file mode 100644 index 00000000000..0ce3ebcc2a6 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-maxp-table.hh @@ -0,0 +1,69 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_MAXP_TABLE_HH +#define HB_OT_MAXP_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * maxp -- The Maximum Profile Table + */ + +#define HB_OT_TAG_maxp HB_TAG('m','a','x','p') + +struct maxp +{ + static const hb_tag_t Tag = HB_OT_TAG_maxp; + + inline unsigned int get_num_glyphs (void) const { + return numGlyphs; + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && + likely (version.major == 1 || (version.major == 0 && version.minor == 0x5000))); + } + + /* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */ + protected: + FixedVersion version; /* Version of the maxp table (0.5 or 1.0), + * 0x00005000 or 0x00010000. */ + USHORT numGlyphs; /* The number of glyphs in the font. */ + public: + DEFINE_SIZE_STATIC (6); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_MAXP_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-name-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-name-table.hh new file mode 100644 index 00000000000..75a1b94ea31 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-name-table.hh @@ -0,0 +1,132 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_NAME_TABLE_HH +#define HB_OT_NAME_TABLE_HH + +#include "hb-open-type-private.hh" + + +namespace OT { + + +/* + * name -- The Naming Table + */ + +#define HB_OT_TAG_name HB_TAG('n','a','m','e') + + +struct NameRecord +{ + static int cmp (const NameRecord *a, const NameRecord *b) + { + int ret; + ret = b->platformID.cmp (a->platformID); + if (ret) return ret; + ret = b->encodingID.cmp (a->encodingID); + if (ret) return ret; + ret = b->languageID.cmp (a->languageID); + if (ret) return ret; + ret = b->nameID.cmp (a->nameID); + if (ret) return ret; + return 0; + } + + inline bool sanitize (hb_sanitize_context_t *c, void *base) { + TRACE_SANITIZE (this); + /* We can check from base all the way up to the end of string... */ + return TRACE_RETURN (c->check_struct (this) && c->check_range ((char *) base, (unsigned int) length + offset)); + } + + USHORT platformID; /* Platform ID. */ + USHORT encodingID; /* Platform-specific encoding ID. */ + USHORT languageID; /* Language ID. */ + USHORT nameID; /* Name ID. */ + USHORT length; /* String length (in bytes). */ + USHORT offset; /* String offset from start of storage area (in bytes). */ + public: + DEFINE_SIZE_STATIC (12); +}; + +struct name +{ + static const hb_tag_t Tag = HB_OT_TAG_name; + + inline unsigned int get_name (unsigned int platform_id, + unsigned int encoding_id, + unsigned int language_id, + unsigned int name_id, + void *buffer, + unsigned int buffer_length) const + { + NameRecord key; + key.platformID.set (platform_id); + key.encodingID.set (encoding_id); + key.languageID.set (language_id); + key.nameID.set (name_id); + NameRecord *match = (NameRecord *) bsearch (&key, nameRecord, count, sizeof (nameRecord[0]), (hb_compare_func_t) NameRecord::cmp); + + if (!match) + return 0; + + unsigned int length = MIN (buffer_length, (unsigned int) match->length); + memcpy (buffer, (char *) this + stringOffset + match->offset, length); + return length; + } + + inline bool sanitize_records (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + char *string_pool = (char *) this + stringOffset; + unsigned int _count = count; + for (unsigned int i = 0; i < _count; i++) + if (!nameRecord[i].sanitize (c, string_pool)) return TRACE_RETURN (false); + return TRACE_RETURN (true); + } + + inline bool sanitize (hb_sanitize_context_t *c) { + TRACE_SANITIZE (this); + return TRACE_RETURN (c->check_struct (this) && + likely (format == 0 || format == 1) && + c->check_array (nameRecord, nameRecord[0].static_size, count) && + sanitize_records (c)); + } + + /* We only implement format 0 for now. */ + protected: + USHORT format; /* Format selector (=0/1). */ + USHORT count; /* Number of name records. */ + Offset stringOffset; /* Offset to start of string storage (from start of table). */ + NameRecord nameRecord[VAR]; /* The name records where count is the number of records. */ + public: + DEFINE_SIZE_ARRAY (6, nameRecord); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_NAME_TABLE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-fallback.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-fallback.hh new file mode 100644 index 00000000000..4fcd0a2fd94 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-fallback.hh @@ -0,0 +1,253 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_COMPLEX_ARABIC_FALLBACK_HH +#define HB_OT_SHAPE_COMPLEX_ARABIC_FALLBACK_HH + +#include "hb-private.hh" + +#include "hb-ot-shape-private.hh" +#include "hb-ot-layout-gsub-table.hh" + + +static const hb_tag_t arabic_fallback_features[] = +{ + HB_TAG('i','n','i','t'), + HB_TAG('m','e','d','i'), + HB_TAG('f','i','n','a'), + HB_TAG('i','s','o','l'), + HB_TAG('r','l','i','g'), +}; + +/* Same order as the fallback feature array */ +enum { + FALLBACK_INIT, + FALLBACK_MEDI, + FALLBACK_FINA, + FALLBACK_ISOL, + FALLBACK_RLIG, + ARABIC_NUM_FALLBACK_FEATURES +}; + +static OT::SubstLookup * +arabic_fallback_synthesize_lookup_single (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_font_t *font, + unsigned int feature_index) +{ + OT::GlyphID glyphs[SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1]; + OT::GlyphID substitutes[SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1]; + unsigned int num_glyphs = 0; + + /* Populate arrays */ + for (hb_codepoint_t u = SHAPING_TABLE_FIRST; u < SHAPING_TABLE_LAST + 1; u++) + { + hb_codepoint_t s = shaping_table[u - SHAPING_TABLE_FIRST][feature_index]; + hb_codepoint_t u_glyph, s_glyph; + + if (!s || + !hb_font_get_glyph (font, u, 0, &u_glyph) || + !hb_font_get_glyph (font, s, 0, &s_glyph) || + u_glyph == s_glyph || + u_glyph > 0xFFFF || s_glyph > 0xFFFF) + continue; + + glyphs[num_glyphs].set (u_glyph); + substitutes[num_glyphs].set (s_glyph); + + num_glyphs++; + } + + /* Bubble-sort! + * May not be good-enough for presidential candidate interviews, but good-enough for us... */ + hb_bubble_sort (&glyphs[0], num_glyphs, OT::GlyphID::cmp, &substitutes[0]); + + OT::Supplier<OT::GlyphID> glyphs_supplier (glyphs, num_glyphs); + OT::Supplier<OT::GlyphID> substitutes_supplier (substitutes, num_glyphs); + + /* Each glyph takes four bytes max, and there's some overhead. */ + char buf[(SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1) * 4 + 128]; + OT::hb_serialize_context_t c (buf, sizeof (buf)); + OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> (); + bool ret = lookup->serialize_single (&c, + OT::LookupFlag::IgnoreMarks, + glyphs_supplier, + substitutes_supplier, + num_glyphs); + c.end_serialize (); + /* TODO sanitize the results? */ + + return ret ? c.copy<OT::SubstLookup> () : NULL; +} + +static OT::SubstLookup * +arabic_fallback_synthesize_lookup_ligature (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_font_t *font) +{ + OT::GlyphID first_glyphs[ARRAY_LENGTH_CONST (ligature_table)]; + unsigned int first_glyphs_indirection[ARRAY_LENGTH_CONST (ligature_table)]; + unsigned int ligature_per_first_glyph_count_list[ARRAY_LENGTH_CONST (first_glyphs)]; + unsigned int num_first_glyphs = 0; + + /* We know that all our ligatures are 2-component */ + OT::GlyphID ligature_list[ARRAY_LENGTH_CONST (first_glyphs) * ARRAY_LENGTH_CONST(ligature_table[0].ligatures)]; + unsigned int component_count_list[ARRAY_LENGTH_CONST (ligature_list)]; + OT::GlyphID component_list[ARRAY_LENGTH_CONST (ligature_list) * 1/* One extra component per ligature */]; + unsigned int num_ligatures = 0; + + /* Populate arrays */ + + /* Sort out the first-glyphs */ + for (unsigned int first_glyph_idx = 0; first_glyph_idx < ARRAY_LENGTH (first_glyphs); first_glyph_idx++) + { + hb_codepoint_t first_u = ligature_table[first_glyph_idx].first; + hb_codepoint_t first_glyph; + if (!hb_font_get_glyph (font, first_u, 0, &first_glyph)) + continue; + first_glyphs[num_first_glyphs].set (first_glyph); + ligature_per_first_glyph_count_list[num_first_glyphs] = 0; + first_glyphs_indirection[num_first_glyphs] = first_glyph_idx; + num_first_glyphs++; + } + hb_bubble_sort (&first_glyphs[0], num_first_glyphs, OT::GlyphID::cmp, &first_glyphs_indirection[0]); + + /* Now that the first-glyphs are sorted, walk again, populate ligatures. */ + for (unsigned int i = 0; i < num_first_glyphs; i++) + { + unsigned int first_glyph_idx = first_glyphs_indirection[i]; + + for (unsigned int second_glyph_idx = 0; second_glyph_idx < ARRAY_LENGTH (ligature_table[0].ligatures); second_glyph_idx++) + { + hb_codepoint_t second_u = ligature_table[first_glyph_idx].ligatures[second_glyph_idx].second; + hb_codepoint_t ligature_u = ligature_table[first_glyph_idx].ligatures[second_glyph_idx].ligature; + hb_codepoint_t second_glyph, ligature_glyph; + if (!second_u || + !hb_font_get_glyph (font, second_u, 0, &second_glyph) || + !hb_font_get_glyph (font, ligature_u, 0, &ligature_glyph)) + continue; + + ligature_per_first_glyph_count_list[i]++; + + ligature_list[num_ligatures].set (ligature_glyph); + component_count_list[num_ligatures] = 2; + component_list[num_ligatures].set (second_glyph); + num_ligatures++; + } + } + + OT::Supplier<OT::GlyphID> first_glyphs_supplier (first_glyphs, num_first_glyphs); + OT::Supplier<unsigned int > ligature_per_first_glyph_count_supplier (ligature_per_first_glyph_count_list, num_first_glyphs); + OT::Supplier<OT::GlyphID> ligatures_supplier (ligature_list, num_ligatures); + OT::Supplier<unsigned int > component_count_supplier (component_count_list, num_ligatures); + OT::Supplier<OT::GlyphID> component_supplier (component_list, num_ligatures); + + /* 16 bytes per ligature ought to be enough... */ + char buf[ARRAY_LENGTH_CONST (ligature_list) * 16 + 128]; + OT::hb_serialize_context_t c (buf, sizeof (buf)); + OT::SubstLookup *lookup = c.start_serialize<OT::SubstLookup> (); + bool ret = lookup->serialize_ligature (&c, + OT::LookupFlag::IgnoreMarks, + first_glyphs_supplier, + ligature_per_first_glyph_count_supplier, + num_first_glyphs, + ligatures_supplier, + component_count_supplier, + component_supplier); + + c.end_serialize (); + /* TODO sanitize the results? */ + + return ret ? c.copy<OT::SubstLookup> () : NULL; +} + +static OT::SubstLookup * +arabic_fallback_synthesize_lookup (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + unsigned int feature_index) +{ + if (feature_index < 4) + return arabic_fallback_synthesize_lookup_single (plan, font, feature_index); + else + return arabic_fallback_synthesize_lookup_ligature (plan, font); +} + +struct arabic_fallback_plan_t +{ + ASSERT_POD (); + + hb_mask_t mask_array[ARABIC_NUM_FALLBACK_FEATURES]; + OT::SubstLookup *lookup_array[ARABIC_NUM_FALLBACK_FEATURES]; + hb_set_digest_t digest_array[ARABIC_NUM_FALLBACK_FEATURES]; +}; + +static const arabic_fallback_plan_t arabic_fallback_plan_nil = {}; + +static arabic_fallback_plan_t * +arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan, + hb_font_t *font) +{ + arabic_fallback_plan_t *fallback_plan = (arabic_fallback_plan_t *) calloc (1, sizeof (arabic_fallback_plan_t)); + if (unlikely (!fallback_plan)) + return const_cast<arabic_fallback_plan_t *> (&arabic_fallback_plan_nil); + + for (unsigned int i = 0; i < ARABIC_NUM_FALLBACK_FEATURES; i++) { + fallback_plan->mask_array[i] = plan->map.get_1_mask (arabic_fallback_features[i]); + if (fallback_plan->mask_array[i]) { + fallback_plan->lookup_array[i] = arabic_fallback_synthesize_lookup (plan, font, i); + if (fallback_plan->lookup_array[i]) + fallback_plan->lookup_array[i]->add_coverage (&fallback_plan->digest_array[i]); + } + } + + return fallback_plan; +} + +static void +arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan) +{ + if (!fallback_plan || fallback_plan == &arabic_fallback_plan_nil) + return; + + for (unsigned int i = 0; i < ARABIC_NUM_FALLBACK_FEATURES; i++) + if (fallback_plan->lookup_array[i]) + free (fallback_plan->lookup_array[i]); + + free (fallback_plan); +} + +static void +arabic_fallback_plan_shape (arabic_fallback_plan_t *fallback_plan, + hb_font_t *font, + hb_buffer_t *buffer) +{ + for (unsigned int i = 0; i < ARABIC_NUM_FALLBACK_FEATURES; i++) + if (fallback_plan->lookup_array[i]) { + OT::hb_apply_context_t c (font, buffer, fallback_plan->mask_array[i]); + fallback_plan->lookup_array[i]->apply_string (&c, &fallback_plan->digest_array[i]); + } +} + + +#endif /* HB_OT_SHAPE_COMPLEX_ARABIC_FALLBACK_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-table.hh new file mode 100644 index 00000000000..730a275bf0a --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic-table.hh @@ -0,0 +1,942 @@ +/* == Start of generated table == */ +/* + * The following table is generated by running: + * + * ./gen-arabic-table.py ArabicShaping.txt UnicodeData.txt + * + * on files with these headers: + * + * # ArabicShaping-6.2.0.txt + * # Date: 2012-05-15, 21:05:00 GMT [KW] + * UnicodeData.txt does not have a header. + */ + +#ifndef HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH +#define HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH + + +static const uint8_t joining_table[] = +{ + + /* Arabic Characters */ + + JOINING_TYPE_U, /* 0600; ARABIC NUMBER SIGN; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0601; ARABIC SIGN SANAH; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0602; ARABIC FOOTNOTE MARKER; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0603; ARABIC SIGN SAFHA; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0604; ARABIC SIGN SAMVAT; U; No_Joining_Group */ + JOINING_TYPE_X, /* 0605 */ + JOINING_TYPE_X, /* 0606 */ + JOINING_TYPE_X, /* 0607 */ + JOINING_TYPE_U, /* 0608; ARABIC RAY; U; No_Joining_Group */ + JOINING_TYPE_X, /* 0609 */ + JOINING_TYPE_X, /* 060A */ + JOINING_TYPE_U, /* 060B; AFGHANI SIGN; U; No_Joining_Group */ + JOINING_TYPE_X, /* 060C */ + JOINING_TYPE_X, /* 060D */ + JOINING_TYPE_X, /* 060E */ + JOINING_TYPE_X, /* 060F */ + JOINING_TYPE_X, /* 0610 */ + JOINING_TYPE_X, /* 0611 */ + JOINING_TYPE_X, /* 0612 */ + JOINING_TYPE_X, /* 0613 */ + JOINING_TYPE_X, /* 0614 */ + JOINING_TYPE_X, /* 0615 */ + JOINING_TYPE_X, /* 0616 */ + JOINING_TYPE_X, /* 0617 */ + JOINING_TYPE_X, /* 0618 */ + JOINING_TYPE_X, /* 0619 */ + JOINING_TYPE_X, /* 061A */ + JOINING_TYPE_X, /* 061B */ + JOINING_TYPE_X, /* 061C */ + JOINING_TYPE_X, /* 061D */ + JOINING_TYPE_X, /* 061E */ + JOINING_TYPE_X, /* 061F */ + JOINING_TYPE_D, /* 0620; DOTLESS YEH WITH SEPARATE RING BELOW; D; YEH */ + JOINING_TYPE_U, /* 0621; HAMZA; U; No_Joining_Group */ + JOINING_TYPE_R, /* 0622; ALEF WITH MADDA ABOVE; R; ALEF */ + JOINING_TYPE_R, /* 0623; ALEF WITH HAMZA ABOVE; R; ALEF */ + JOINING_TYPE_R, /* 0624; WAW WITH HAMZA ABOVE; R; WAW */ + JOINING_TYPE_R, /* 0625; ALEF WITH HAMZA BELOW; R; ALEF */ + JOINING_TYPE_D, /* 0626; DOTLESS YEH WITH HAMZA ABOVE; D; YEH */ + JOINING_TYPE_R, /* 0627; ALEF; R; ALEF */ + JOINING_TYPE_D, /* 0628; BEH; D; BEH */ + JOINING_TYPE_R, /* 0629; TEH MARBUTA; R; TEH MARBUTA */ + JOINING_TYPE_D, /* 062A; DOTLESS BEH WITH 2 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 062B; DOTLESS BEH WITH 3 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 062C; HAH WITH DOT BELOW; D; HAH */ + JOINING_TYPE_D, /* 062D; HAH; D; HAH */ + JOINING_TYPE_D, /* 062E; HAH WITH DOT ABOVE; D; HAH */ + JOINING_TYPE_R, /* 062F; DAL; R; DAL */ + JOINING_TYPE_R, /* 0630; DAL WITH DOT ABOVE; R; DAL */ + JOINING_TYPE_R, /* 0631; REH; R; REH */ + JOINING_TYPE_R, /* 0632; REH WITH DOT ABOVE; R; REH */ + JOINING_TYPE_D, /* 0633; SEEN; D; SEEN */ + JOINING_TYPE_D, /* 0634; SEEN WITH 3 DOTS ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 0635; SAD; D; SAD */ + JOINING_TYPE_D, /* 0636; SAD WITH DOT ABOVE; D; SAD */ + JOINING_TYPE_D, /* 0637; TAH; D; TAH */ + JOINING_TYPE_D, /* 0638; TAH WITH DOT ABOVE; D; TAH */ + JOINING_TYPE_D, /* 0639; AIN; D; AIN */ + JOINING_TYPE_D, /* 063A; AIN WITH DOT ABOVE; D; AIN */ + JOINING_TYPE_D, /* 063B; KEHEH WITH 2 DOTS ABOVE; D; GAF */ + JOINING_TYPE_D, /* 063C; KEHEH WITH 3 DOTS BELOW; D; GAF */ + JOINING_TYPE_D, /* 063D; FARSI YEH WITH INVERTED V ABOVE; D; FARSI YEH */ + JOINING_TYPE_D, /* 063E; FARSI YEH WITH 2 DOTS ABOVE; D; FARSI YEH */ + JOINING_TYPE_D, /* 063F; FARSI YEH WITH 3 DOTS ABOVE; D; FARSI YEH */ + JOINING_TYPE_C, /* 0640; TATWEEL; C; No_Joining_Group */ + JOINING_TYPE_D, /* 0641; FEH; D; FEH */ + JOINING_TYPE_D, /* 0642; QAF; D; QAF */ + JOINING_TYPE_D, /* 0643; KAF; D; KAF */ + JOINING_TYPE_D, /* 0644; LAM; D; LAM */ + JOINING_TYPE_D, /* 0645; MEEM; D; MEEM */ + JOINING_TYPE_D, /* 0646; NOON; D; NOON */ + JOINING_TYPE_D, /* 0647; HEH; D; HEH */ + JOINING_TYPE_R, /* 0648; WAW; R; WAW */ + JOINING_TYPE_D, /* 0649; DOTLESS YEH; D; YEH */ + JOINING_TYPE_D, /* 064A; YEH; D; YEH */ + JOINING_TYPE_X, /* 064B */ + JOINING_TYPE_X, /* 064C */ + JOINING_TYPE_X, /* 064D */ + JOINING_TYPE_X, /* 064E */ + JOINING_TYPE_X, /* 064F */ + JOINING_TYPE_X, /* 0650 */ + JOINING_TYPE_X, /* 0651 */ + JOINING_TYPE_X, /* 0652 */ + JOINING_TYPE_X, /* 0653 */ + JOINING_TYPE_X, /* 0654 */ + JOINING_TYPE_X, /* 0655 */ + JOINING_TYPE_X, /* 0656 */ + JOINING_TYPE_X, /* 0657 */ + JOINING_TYPE_X, /* 0658 */ + JOINING_TYPE_X, /* 0659 */ + JOINING_TYPE_X, /* 065A */ + JOINING_TYPE_X, /* 065B */ + JOINING_TYPE_X, /* 065C */ + JOINING_TYPE_X, /* 065D */ + JOINING_TYPE_X, /* 065E */ + JOINING_TYPE_X, /* 065F */ + JOINING_TYPE_X, /* 0660 */ + JOINING_TYPE_X, /* 0661 */ + JOINING_TYPE_X, /* 0662 */ + JOINING_TYPE_X, /* 0663 */ + JOINING_TYPE_X, /* 0664 */ + JOINING_TYPE_X, /* 0665 */ + JOINING_TYPE_X, /* 0666 */ + JOINING_TYPE_X, /* 0667 */ + JOINING_TYPE_X, /* 0668 */ + JOINING_TYPE_X, /* 0669 */ + JOINING_TYPE_X, /* 066A */ + JOINING_TYPE_X, /* 066B */ + JOINING_TYPE_X, /* 066C */ + JOINING_TYPE_X, /* 066D */ + JOINING_TYPE_D, /* 066E; DOTLESS BEH; D; BEH */ + JOINING_TYPE_D, /* 066F; DOTLESS QAF; D; QAF */ + JOINING_TYPE_X, /* 0670 */ + JOINING_TYPE_R, /* 0671; ALEF WITH WASLA ABOVE; R; ALEF */ + JOINING_TYPE_R, /* 0672; ALEF WITH WAVY HAMZA ABOVE; R; ALEF */ + JOINING_TYPE_R, /* 0673; ALEF WITH WAVY HAMZA BELOW; R; ALEF */ + JOINING_TYPE_U, /* 0674; HIGH HAMZA; U; No_Joining_Group */ + JOINING_TYPE_R, /* 0675; HIGH HAMZA ALEF; R; ALEF */ + JOINING_TYPE_R, /* 0676; HIGH HAMZA WAW; R; WAW */ + JOINING_TYPE_R, /* 0677; HIGH HAMZA WAW WITH DAMMA ABOVE; R; WAW */ + JOINING_TYPE_D, /* 0678; HIGH HAMZA DOTLESS YEH; D; YEH */ + JOINING_TYPE_D, /* 0679; DOTLESS BEH WITH TAH ABOVE; D; BEH */ + JOINING_TYPE_D, /* 067A; DOTLESS BEH WITH VERTICAL 2 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 067B; DOTLESS BEH WITH VERTICAL 2 DOTS BELOW; D; BEH */ + JOINING_TYPE_D, /* 067C; DOTLESS BEH WITH ATTACHED RING BELOW AND 2 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 067D; DOTLESS BEH WITH INVERTED 3 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 067E; DOTLESS BEH WITH 3 DOTS BELOW; D; BEH */ + JOINING_TYPE_D, /* 067F; DOTLESS BEH WITH 4 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 0680; DOTLESS BEH WITH 4 DOTS BELOW; D; BEH */ + JOINING_TYPE_D, /* 0681; HAH WITH HAMZA ABOVE; D; HAH */ + JOINING_TYPE_D, /* 0682; HAH WITH VERTICAL 2 DOTS ABOVE; D; HAH */ + JOINING_TYPE_D, /* 0683; HAH WITH 2 DOTS BELOW; D; HAH */ + JOINING_TYPE_D, /* 0684; HAH WITH VERTICAL 2 DOTS BELOW; D; HAH */ + JOINING_TYPE_D, /* 0685; HAH WITH 3 DOTS ABOVE; D; HAH */ + JOINING_TYPE_D, /* 0686; HAH WITH 3 DOTS BELOW; D; HAH */ + JOINING_TYPE_D, /* 0687; HAH WITH 4 DOTS BELOW; D; HAH */ + JOINING_TYPE_R, /* 0688; DAL WITH TAH ABOVE; R; DAL */ + JOINING_TYPE_R, /* 0689; DAL WITH ATTACHED RING BELOW; R; DAL */ + JOINING_TYPE_R, /* 068A; DAL WITH DOT BELOW; R; DAL */ + JOINING_TYPE_R, /* 068B; DAL WITH DOT BELOW AND TAH ABOVE; R; DAL */ + JOINING_TYPE_R, /* 068C; DAL WITH 2 DOTS ABOVE; R; DAL */ + JOINING_TYPE_R, /* 068D; DAL WITH 2 DOTS BELOW; R; DAL */ + JOINING_TYPE_R, /* 068E; DAL WITH 3 DOTS ABOVE; R; DAL */ + JOINING_TYPE_R, /* 068F; DAL WITH INVERTED 3 DOTS ABOVE; R; DAL */ + JOINING_TYPE_R, /* 0690; DAL WITH 4 DOTS ABOVE; R; DAL */ + JOINING_TYPE_R, /* 0691; REH WITH TAH ABOVE; R; REH */ + JOINING_TYPE_R, /* 0692; REH WITH V ABOVE; R; REH */ + JOINING_TYPE_R, /* 0693; REH WITH ATTACHED RING BELOW; R; REH */ + JOINING_TYPE_R, /* 0694; REH WITH DOT BELOW; R; REH */ + JOINING_TYPE_R, /* 0695; REH WITH V BELOW; R; REH */ + JOINING_TYPE_R, /* 0696; REH WITH DOT BELOW AND DOT WITHIN; R; REH */ + JOINING_TYPE_R, /* 0697; REH WITH 2 DOTS ABOVE; R; REH */ + JOINING_TYPE_R, /* 0698; REH WITH 3 DOTS ABOVE; R; REH */ + JOINING_TYPE_R, /* 0699; REH WITH 4 DOTS ABOVE; R; REH */ + JOINING_TYPE_D, /* 069A; SEEN WITH DOT BELOW AND DOT ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 069B; SEEN WITH 3 DOTS BELOW; D; SEEN */ + JOINING_TYPE_D, /* 069C; SEEN WITH 3 DOTS BELOW AND 3 DOTS ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 069D; SAD WITH 2 DOTS BELOW; D; SAD */ + JOINING_TYPE_D, /* 069E; SAD WITH 3 DOTS ABOVE; D; SAD */ + JOINING_TYPE_D, /* 069F; TAH WITH 3 DOTS ABOVE; D; TAH */ + JOINING_TYPE_D, /* 06A0; AIN WITH 3 DOTS ABOVE; D; AIN */ + JOINING_TYPE_D, /* 06A1; DOTLESS FEH; D; FEH */ + JOINING_TYPE_D, /* 06A2; DOTLESS FEH WITH DOT BELOW; D; FEH */ + JOINING_TYPE_D, /* 06A3; FEH WITH DOT BELOW; D; FEH */ + JOINING_TYPE_D, /* 06A4; DOTLESS FEH WITH 3 DOTS ABOVE; D; FEH */ + JOINING_TYPE_D, /* 06A5; DOTLESS FEH WITH 3 DOTS BELOW; D; FEH */ + JOINING_TYPE_D, /* 06A6; DOTLESS FEH WITH 4 DOTS ABOVE; D; FEH */ + JOINING_TYPE_D, /* 06A7; DOTLESS QAF WITH DOT ABOVE; D; QAF */ + JOINING_TYPE_D, /* 06A8; DOTLESS QAF WITH 3 DOTS ABOVE; D; QAF */ + JOINING_TYPE_D, /* 06A9; KEHEH; D; GAF */ + JOINING_TYPE_D, /* 06AA; SWASH KAF; D; SWASH KAF */ + JOINING_TYPE_D, /* 06AB; KEHEH WITH ATTACHED RING BELOW; D; GAF */ + JOINING_TYPE_D, /* 06AC; KAF WITH DOT ABOVE; D; KAF */ + JOINING_TYPE_D, /* 06AD; KAF WITH 3 DOTS ABOVE; D; KAF */ + JOINING_TYPE_D, /* 06AE; KAF WITH 3 DOTS BELOW; D; KAF */ + JOINING_TYPE_D, /* 06AF; GAF; D; GAF */ + JOINING_TYPE_D, /* 06B0; GAF WITH ATTACHED RING BELOW; D; GAF */ + JOINING_TYPE_D, /* 06B1; GAF WITH 2 DOTS ABOVE; D; GAF */ + JOINING_TYPE_D, /* 06B2; GAF WITH 2 DOTS BELOW; D; GAF */ + JOINING_TYPE_D, /* 06B3; GAF WITH VERTICAL 2 DOTS BELOW; D; GAF */ + JOINING_TYPE_D, /* 06B4; GAF WITH 3 DOTS ABOVE; D; GAF */ + JOINING_TYPE_D, /* 06B5; LAM WITH V ABOVE; D; LAM */ + JOINING_TYPE_D, /* 06B6; LAM WITH DOT ABOVE; D; LAM */ + JOINING_TYPE_D, /* 06B7; LAM WITH 3 DOTS ABOVE; D; LAM */ + JOINING_TYPE_D, /* 06B8; LAM WITH 3 DOTS BELOW; D; LAM */ + JOINING_TYPE_D, /* 06B9; NOON WITH DOT BELOW; D; NOON */ + JOINING_TYPE_D, /* 06BA; DOTLESS NOON; D; NOON */ + JOINING_TYPE_D, /* 06BB; DOTLESS NOON WITH TAH ABOVE; D; NOON */ + JOINING_TYPE_D, /* 06BC; NOON WITH ATTACHED RING BELOW; D; NOON */ + JOINING_TYPE_D, /* 06BD; NYA; D; NYA */ + JOINING_TYPE_D, /* 06BE; KNOTTED HEH; D; KNOTTED HEH */ + JOINING_TYPE_D, /* 06BF; HAH WITH 3 DOTS BELOW AND DOT ABOVE; D; HAH */ + JOINING_TYPE_R, /* 06C0; DOTLESS TEH MARBUTA WITH HAMZA ABOVE; R; TEH MARBUTA */ + JOINING_TYPE_D, /* 06C1; HEH GOAL; D; HEH GOAL */ + JOINING_TYPE_D, /* 06C2; HEH GOAL WITH HAMZA ABOVE; D; HEH GOAL */ + JOINING_TYPE_R, /* 06C3; TEH MARBUTA GOAL; R; TEH MARBUTA GOAL */ + JOINING_TYPE_R, /* 06C4; WAW WITH ATTACHED RING WITHIN; R; WAW */ + JOINING_TYPE_R, /* 06C5; WAW WITH BAR; R; WAW */ + JOINING_TYPE_R, /* 06C6; WAW WITH V ABOVE; R; WAW */ + JOINING_TYPE_R, /* 06C7; WAW WITH DAMMA ABOVE; R; WAW */ + JOINING_TYPE_R, /* 06C8; WAW WITH ALEF ABOVE; R; WAW */ + JOINING_TYPE_R, /* 06C9; WAW WITH INVERTED V ABOVE; R; WAW */ + JOINING_TYPE_R, /* 06CA; WAW WITH 2 DOTS ABOVE; R; WAW */ + JOINING_TYPE_R, /* 06CB; WAW WITH 3 DOTS ABOVE; R; WAW */ + JOINING_TYPE_D, /* 06CC; FARSI YEH; D; FARSI YEH */ + JOINING_TYPE_R, /* 06CD; YEH WITH TAIL; R; YEH WITH TAIL */ + JOINING_TYPE_D, /* 06CE; FARSI YEH WITH V ABOVE; D; FARSI YEH */ + JOINING_TYPE_R, /* 06CF; WAW WITH DOT ABOVE; R; WAW */ + JOINING_TYPE_D, /* 06D0; DOTLESS YEH WITH VERTICAL 2 DOTS BELOW; D; YEH */ + JOINING_TYPE_D, /* 06D1; DOTLESS YEH WITH 3 DOTS BELOW; D; YEH */ + JOINING_TYPE_R, /* 06D2; YEH BARREE; R; YEH BARREE */ + JOINING_TYPE_R, /* 06D3; YEH BARREE WITH HAMZA ABOVE; R; YEH BARREE */ + JOINING_TYPE_X, /* 06D4 */ + JOINING_TYPE_R, /* 06D5; DOTLESS TEH MARBUTA; R; TEH MARBUTA */ + JOINING_TYPE_X, /* 06D6 */ + JOINING_TYPE_X, /* 06D7 */ + JOINING_TYPE_X, /* 06D8 */ + JOINING_TYPE_X, /* 06D9 */ + JOINING_TYPE_X, /* 06DA */ + JOINING_TYPE_X, /* 06DB */ + JOINING_TYPE_X, /* 06DC */ + JOINING_TYPE_U, /* 06DD; ARABIC END OF AYAH; U; No_Joining_Group */ + JOINING_TYPE_X, /* 06DE */ + JOINING_TYPE_X, /* 06DF */ + JOINING_TYPE_X, /* 06E0 */ + JOINING_TYPE_X, /* 06E1 */ + JOINING_TYPE_X, /* 06E2 */ + JOINING_TYPE_X, /* 06E3 */ + JOINING_TYPE_X, /* 06E4 */ + JOINING_TYPE_X, /* 06E5 */ + JOINING_TYPE_X, /* 06E6 */ + JOINING_TYPE_X, /* 06E7 */ + JOINING_TYPE_X, /* 06E8 */ + JOINING_TYPE_X, /* 06E9 */ + JOINING_TYPE_X, /* 06EA */ + JOINING_TYPE_X, /* 06EB */ + JOINING_TYPE_X, /* 06EC */ + JOINING_TYPE_X, /* 06ED */ + JOINING_TYPE_R, /* 06EE; DAL WITH INVERTED V ABOVE; R; DAL */ + JOINING_TYPE_R, /* 06EF; REH WITH INVERTED V ABOVE; R; REH */ + JOINING_TYPE_X, /* 06F0 */ + JOINING_TYPE_X, /* 06F1 */ + JOINING_TYPE_X, /* 06F2 */ + JOINING_TYPE_X, /* 06F3 */ + JOINING_TYPE_X, /* 06F4 */ + JOINING_TYPE_X, /* 06F5 */ + JOINING_TYPE_X, /* 06F6 */ + JOINING_TYPE_X, /* 06F7 */ + JOINING_TYPE_X, /* 06F8 */ + JOINING_TYPE_X, /* 06F9 */ + JOINING_TYPE_D, /* 06FA; SEEN WITH DOT BELOW AND 3 DOTS ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 06FB; SAD WITH DOT BELOW AND DOT ABOVE; D; SAD */ + JOINING_TYPE_D, /* 06FC; AIN WITH DOT BELOW AND DOT ABOVE; D; AIN */ + JOINING_TYPE_X, /* 06FD */ + JOINING_TYPE_X, /* 06FE */ + JOINING_TYPE_D, /* 06FF; KNOTTED HEH WITH INVERTED V ABOVE; D; KNOTTED HEH */ + + /* Syriac Characters */ + + JOINING_TYPE_X, /* 0700 */ + JOINING_TYPE_X, /* 0701 */ + JOINING_TYPE_X, /* 0702 */ + JOINING_TYPE_X, /* 0703 */ + JOINING_TYPE_X, /* 0704 */ + JOINING_TYPE_X, /* 0705 */ + JOINING_TYPE_X, /* 0706 */ + JOINING_TYPE_X, /* 0707 */ + JOINING_TYPE_X, /* 0708 */ + JOINING_TYPE_X, /* 0709 */ + JOINING_TYPE_X, /* 070A */ + JOINING_TYPE_X, /* 070B */ + JOINING_TYPE_X, /* 070C */ + JOINING_TYPE_X, /* 070D */ + JOINING_TYPE_X, /* 070E */ + JOINING_TYPE_X, /* 070F */ + JOINING_GROUP_ALAPH, /* 0710; ALAPH; R; ALAPH */ + JOINING_TYPE_X, /* 0711 */ + JOINING_TYPE_D, /* 0712; BETH; D; BETH */ + JOINING_TYPE_D, /* 0713; GAMAL; D; GAMAL */ + JOINING_TYPE_D, /* 0714; GAMAL GARSHUNI; D; GAMAL */ + JOINING_GROUP_DALATH_RISH, /* 0715; DALATH; R; DALATH RISH */ + JOINING_GROUP_DALATH_RISH, /* 0716; DOTLESS DALATH RISH; R; DALATH RISH */ + JOINING_TYPE_R, /* 0717; HE; R; HE */ + JOINING_TYPE_R, /* 0718; WAW; R; SYRIAC WAW */ + JOINING_TYPE_R, /* 0719; ZAIN; R; ZAIN */ + JOINING_TYPE_D, /* 071A; HETH; D; HETH */ + JOINING_TYPE_D, /* 071B; TETH; D; TETH */ + JOINING_TYPE_D, /* 071C; TETH GARSHUNI; D; TETH */ + JOINING_TYPE_D, /* 071D; YUDH; D; YUDH */ + JOINING_TYPE_R, /* 071E; YUDH HE; R; YUDH HE */ + JOINING_TYPE_D, /* 071F; KAPH; D; KAPH */ + JOINING_TYPE_D, /* 0720; LAMADH; D; LAMADH */ + JOINING_TYPE_D, /* 0721; MIM; D; MIM */ + JOINING_TYPE_D, /* 0722; NUN; D; NUN */ + JOINING_TYPE_D, /* 0723; SEMKATH; D; SEMKATH */ + JOINING_TYPE_D, /* 0724; FINAL SEMKATH; D; FINAL SEMKATH */ + JOINING_TYPE_D, /* 0725; E; D; E */ + JOINING_TYPE_D, /* 0726; PE; D; PE */ + JOINING_TYPE_D, /* 0727; REVERSED PE; D; REVERSED PE */ + JOINING_TYPE_R, /* 0728; SADHE; R; SADHE */ + JOINING_TYPE_D, /* 0729; QAPH; D; QAPH */ + JOINING_GROUP_DALATH_RISH, /* 072A; RISH; R; DALATH RISH */ + JOINING_TYPE_D, /* 072B; SHIN; D; SHIN */ + JOINING_TYPE_R, /* 072C; TAW; R; TAW */ + JOINING_TYPE_D, /* 072D; PERSIAN BHETH; D; BETH */ + JOINING_TYPE_D, /* 072E; PERSIAN GHAMAL; D; GAMAL */ + JOINING_GROUP_DALATH_RISH, /* 072F; PERSIAN DHALATH; R; DALATH RISH */ + JOINING_TYPE_X, /* 0730 */ + JOINING_TYPE_X, /* 0731 */ + JOINING_TYPE_X, /* 0732 */ + JOINING_TYPE_X, /* 0733 */ + JOINING_TYPE_X, /* 0734 */ + JOINING_TYPE_X, /* 0735 */ + JOINING_TYPE_X, /* 0736 */ + JOINING_TYPE_X, /* 0737 */ + JOINING_TYPE_X, /* 0738 */ + JOINING_TYPE_X, /* 0739 */ + JOINING_TYPE_X, /* 073A */ + JOINING_TYPE_X, /* 073B */ + JOINING_TYPE_X, /* 073C */ + JOINING_TYPE_X, /* 073D */ + JOINING_TYPE_X, /* 073E */ + JOINING_TYPE_X, /* 073F */ + JOINING_TYPE_X, /* 0740 */ + JOINING_TYPE_X, /* 0741 */ + JOINING_TYPE_X, /* 0742 */ + JOINING_TYPE_X, /* 0743 */ + JOINING_TYPE_X, /* 0744 */ + JOINING_TYPE_X, /* 0745 */ + JOINING_TYPE_X, /* 0746 */ + JOINING_TYPE_X, /* 0747 */ + JOINING_TYPE_X, /* 0748 */ + JOINING_TYPE_X, /* 0749 */ + JOINING_TYPE_X, /* 074A */ + JOINING_TYPE_X, /* 074B */ + JOINING_TYPE_X, /* 074C */ + JOINING_TYPE_R, /* 074D; SOGDIAN ZHAIN; R; ZHAIN */ + JOINING_TYPE_D, /* 074E; SOGDIAN KHAPH; D; KHAPH */ + JOINING_TYPE_D, /* 074F; SOGDIAN FE; D; FE */ + + /* Arabic Supplement Characters */ + + JOINING_TYPE_D, /* 0750; DOTLESS BEH WITH HORIZONTAL 3 DOTS BELOW; D; BEH */ + JOINING_TYPE_D, /* 0751; BEH WITH 3 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 0752; DOTLESS BEH WITH INVERTED 3 DOTS BELOW; D; BEH */ + JOINING_TYPE_D, /* 0753; DOTLESS BEH WITH INVERTED 3 DOTS BELOW AND 2 DOTS ABOVE; D; BEH */ + JOINING_TYPE_D, /* 0754; DOTLESS BEH WITH 2 DOTS BELOW AND DOT ABOVE; D; BEH */ + JOINING_TYPE_D, /* 0755; DOTLESS BEH WITH INVERTED V BELOW; D; BEH */ + JOINING_TYPE_D, /* 0756; DOTLESS BEH WITH V ABOVE; D; BEH */ + JOINING_TYPE_D, /* 0757; HAH WITH 2 DOTS ABOVE; D; HAH */ + JOINING_TYPE_D, /* 0758; HAH WITH INVERTED 3 DOTS BELOW; D; HAH */ + JOINING_TYPE_R, /* 0759; DAL WITH VERTICAL 2 DOTS BELOW AND TAH ABOVE; R; DAL */ + JOINING_TYPE_R, /* 075A; DAL WITH INVERTED V BELOW; R; DAL */ + JOINING_TYPE_R, /* 075B; REH WITH BAR; R; REH */ + JOINING_TYPE_D, /* 075C; SEEN WITH 4 DOTS ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 075D; AIN WITH 2 DOTS ABOVE; D; AIN */ + JOINING_TYPE_D, /* 075E; AIN WITH INVERTED 3 DOTS ABOVE; D; AIN */ + JOINING_TYPE_D, /* 075F; AIN WITH VERTICAL 2 DOTS ABOVE; D; AIN */ + JOINING_TYPE_D, /* 0760; DOTLESS FEH WITH 2 DOTS BELOW; D; FEH */ + JOINING_TYPE_D, /* 0761; DOTLESS FEH WITH INVERTED 3 DOTS BELOW; D; FEH */ + JOINING_TYPE_D, /* 0762; KEHEH WITH DOT ABOVE; D; GAF */ + JOINING_TYPE_D, /* 0763; KEHEH WITH 3 DOTS ABOVE; D; GAF */ + JOINING_TYPE_D, /* 0764; KEHEH WITH INVERTED 3 DOTS BELOW; D; GAF */ + JOINING_TYPE_D, /* 0765; MEEM WITH DOT ABOVE; D; MEEM */ + JOINING_TYPE_D, /* 0766; MEEM WITH DOT BELOW; D; MEEM */ + JOINING_TYPE_D, /* 0767; NOON WITH 2 DOTS BELOW; D; NOON */ + JOINING_TYPE_D, /* 0768; NOON WITH TAH ABOVE; D; NOON */ + JOINING_TYPE_D, /* 0769; NOON WITH V ABOVE; D; NOON */ + JOINING_TYPE_D, /* 076A; LAM WITH BAR; D; LAM */ + JOINING_TYPE_R, /* 076B; REH WITH VERTICAL 2 DOTS ABOVE; R; REH */ + JOINING_TYPE_R, /* 076C; REH WITH HAMZA ABOVE; R; REH */ + JOINING_TYPE_D, /* 076D; SEEN WITH VERTICAL 2 DOTS ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 076E; HAH WITH TAH BELOW; D; HAH */ + JOINING_TYPE_D, /* 076F; HAH WITH TAH AND 2 DOTS BELOW; D; HAH */ + JOINING_TYPE_D, /* 0770; SEEN WITH 2 DOTS AND TAH ABOVE; D; SEEN */ + JOINING_TYPE_R, /* 0771; REH WITH 2 DOTS AND TAH ABOVE; R; REH */ + JOINING_TYPE_D, /* 0772; HAH WITH TAH ABOVE; D; HAH */ + JOINING_TYPE_R, /* 0773; ALEF WITH DIGIT TWO ABOVE; R; ALEF */ + JOINING_TYPE_R, /* 0774; ALEF WITH DIGIT THREE ABOVE; R; ALEF */ + JOINING_TYPE_D, /* 0775; FARSI YEH WITH DIGIT TWO ABOVE; D; FARSI YEH */ + JOINING_TYPE_D, /* 0776; FARSI YEH WITH DIGIT THREE ABOVE; D; FARSI YEH */ + JOINING_TYPE_D, /* 0777; DOTLESS YEH WITH DIGIT FOUR BELOW; D; YEH */ + JOINING_TYPE_R, /* 0778; WAW WITH DIGIT TWO ABOVE; R; WAW */ + JOINING_TYPE_R, /* 0779; WAW WITH DIGIT THREE ABOVE; R; WAW */ + JOINING_TYPE_D, /* 077A; BURUSHASKI YEH BARREE WITH DIGIT TWO ABOVE; D; BURUSHASKI YEH BARREE */ + JOINING_TYPE_D, /* 077B; BURUSHASKI YEH BARREE WITH DIGIT THREE ABOVE; D; BURUSHASKI YEH BARREE */ + JOINING_TYPE_D, /* 077C; HAH WITH DIGIT FOUR BELOW; D; HAH */ + JOINING_TYPE_D, /* 077D; SEEN WITH DIGIT FOUR ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 077E; SEEN WITH INVERTED V ABOVE; D; SEEN */ + JOINING_TYPE_D, /* 077F; KAF WITH 2 DOTS ABOVE; D; KAF */ + + /* N'Ko Characters */ + + JOINING_TYPE_X, /* 0780 */ + JOINING_TYPE_X, /* 0781 */ + JOINING_TYPE_X, /* 0782 */ + JOINING_TYPE_X, /* 0783 */ + JOINING_TYPE_X, /* 0784 */ + JOINING_TYPE_X, /* 0785 */ + JOINING_TYPE_X, /* 0786 */ + JOINING_TYPE_X, /* 0787 */ + JOINING_TYPE_X, /* 0788 */ + JOINING_TYPE_X, /* 0789 */ + JOINING_TYPE_X, /* 078A */ + JOINING_TYPE_X, /* 078B */ + JOINING_TYPE_X, /* 078C */ + JOINING_TYPE_X, /* 078D */ + JOINING_TYPE_X, /* 078E */ + JOINING_TYPE_X, /* 078F */ + JOINING_TYPE_X, /* 0790 */ + JOINING_TYPE_X, /* 0791 */ + JOINING_TYPE_X, /* 0792 */ + JOINING_TYPE_X, /* 0793 */ + JOINING_TYPE_X, /* 0794 */ + JOINING_TYPE_X, /* 0795 */ + JOINING_TYPE_X, /* 0796 */ + JOINING_TYPE_X, /* 0797 */ + JOINING_TYPE_X, /* 0798 */ + JOINING_TYPE_X, /* 0799 */ + JOINING_TYPE_X, /* 079A */ + JOINING_TYPE_X, /* 079B */ + JOINING_TYPE_X, /* 079C */ + JOINING_TYPE_X, /* 079D */ + JOINING_TYPE_X, /* 079E */ + JOINING_TYPE_X, /* 079F */ + JOINING_TYPE_X, /* 07A0 */ + JOINING_TYPE_X, /* 07A1 */ + JOINING_TYPE_X, /* 07A2 */ + JOINING_TYPE_X, /* 07A3 */ + JOINING_TYPE_X, /* 07A4 */ + JOINING_TYPE_X, /* 07A5 */ + JOINING_TYPE_X, /* 07A6 */ + JOINING_TYPE_X, /* 07A7 */ + JOINING_TYPE_X, /* 07A8 */ + JOINING_TYPE_X, /* 07A9 */ + JOINING_TYPE_X, /* 07AA */ + JOINING_TYPE_X, /* 07AB */ + JOINING_TYPE_X, /* 07AC */ + JOINING_TYPE_X, /* 07AD */ + JOINING_TYPE_X, /* 07AE */ + JOINING_TYPE_X, /* 07AF */ + JOINING_TYPE_X, /* 07B0 */ + JOINING_TYPE_X, /* 07B1 */ + JOINING_TYPE_X, /* 07B2 */ + JOINING_TYPE_X, /* 07B3 */ + JOINING_TYPE_X, /* 07B4 */ + JOINING_TYPE_X, /* 07B5 */ + JOINING_TYPE_X, /* 07B6 */ + JOINING_TYPE_X, /* 07B7 */ + JOINING_TYPE_X, /* 07B8 */ + JOINING_TYPE_X, /* 07B9 */ + JOINING_TYPE_X, /* 07BA */ + JOINING_TYPE_X, /* 07BB */ + JOINING_TYPE_X, /* 07BC */ + JOINING_TYPE_X, /* 07BD */ + JOINING_TYPE_X, /* 07BE */ + JOINING_TYPE_X, /* 07BF */ + JOINING_TYPE_X, /* 07C0 */ + JOINING_TYPE_X, /* 07C1 */ + JOINING_TYPE_X, /* 07C2 */ + JOINING_TYPE_X, /* 07C3 */ + JOINING_TYPE_X, /* 07C4 */ + JOINING_TYPE_X, /* 07C5 */ + JOINING_TYPE_X, /* 07C6 */ + JOINING_TYPE_X, /* 07C7 */ + JOINING_TYPE_X, /* 07C8 */ + JOINING_TYPE_X, /* 07C9 */ + JOINING_TYPE_D, /* 07CA; NKO A; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07CB; NKO EE; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07CC; NKO I; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07CD; NKO E; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07CE; NKO U; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07CF; NKO OO; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D0; NKO O; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D1; NKO DAGBASINNA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D2; NKO N; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D3; NKO BA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D4; NKO PA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D5; NKO TA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D6; NKO JA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D7; NKO CHA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D8; NKO DA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07D9; NKO RA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DA; NKO RRA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DB; NKO SA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DC; NKO GBA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DD; NKO FA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DE; NKO KA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07DF; NKO LA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E0; NKO NA WOLOSO; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E1; NKO MA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E2; NKO NYA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E3; NKO NA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E4; NKO HA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E5; NKO WA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E6; NKO YA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E7; NKO NYA WOLOSO; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E8; NKO JONA JA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07E9; NKO JONA CHA; D; No_Joining_Group */ + JOINING_TYPE_D, /* 07EA; NKO JONA RA; D; No_Joining_Group */ + JOINING_TYPE_X, /* 07EB */ + JOINING_TYPE_X, /* 07EC */ + JOINING_TYPE_X, /* 07ED */ + JOINING_TYPE_X, /* 07EE */ + JOINING_TYPE_X, /* 07EF */ + JOINING_TYPE_X, /* 07F0 */ + JOINING_TYPE_X, /* 07F1 */ + JOINING_TYPE_X, /* 07F2 */ + JOINING_TYPE_X, /* 07F3 */ + JOINING_TYPE_X, /* 07F4 */ + JOINING_TYPE_X, /* 07F5 */ + JOINING_TYPE_X, /* 07F6 */ + JOINING_TYPE_X, /* 07F7 */ + JOINING_TYPE_X, /* 07F8 */ + JOINING_TYPE_X, /* 07F9 */ + JOINING_TYPE_C, /* 07FA; NKO LAJANYALAN; C; No_Joining_Group */ + + /* Mandaic Characters */ + + JOINING_TYPE_X, /* 07FB */ + JOINING_TYPE_X, /* 07FC */ + JOINING_TYPE_X, /* 07FD */ + JOINING_TYPE_X, /* 07FE */ + JOINING_TYPE_X, /* 07FF */ + JOINING_TYPE_X, /* 0800 */ + JOINING_TYPE_X, /* 0801 */ + JOINING_TYPE_X, /* 0802 */ + JOINING_TYPE_X, /* 0803 */ + JOINING_TYPE_X, /* 0804 */ + JOINING_TYPE_X, /* 0805 */ + JOINING_TYPE_X, /* 0806 */ + JOINING_TYPE_X, /* 0807 */ + JOINING_TYPE_X, /* 0808 */ + JOINING_TYPE_X, /* 0809 */ + JOINING_TYPE_X, /* 080A */ + JOINING_TYPE_X, /* 080B */ + JOINING_TYPE_X, /* 080C */ + JOINING_TYPE_X, /* 080D */ + JOINING_TYPE_X, /* 080E */ + JOINING_TYPE_X, /* 080F */ + JOINING_TYPE_X, /* 0810 */ + JOINING_TYPE_X, /* 0811 */ + JOINING_TYPE_X, /* 0812 */ + JOINING_TYPE_X, /* 0813 */ + JOINING_TYPE_X, /* 0814 */ + JOINING_TYPE_X, /* 0815 */ + JOINING_TYPE_X, /* 0816 */ + JOINING_TYPE_X, /* 0817 */ + JOINING_TYPE_X, /* 0818 */ + JOINING_TYPE_X, /* 0819 */ + JOINING_TYPE_X, /* 081A */ + JOINING_TYPE_X, /* 081B */ + JOINING_TYPE_X, /* 081C */ + JOINING_TYPE_X, /* 081D */ + JOINING_TYPE_X, /* 081E */ + JOINING_TYPE_X, /* 081F */ + JOINING_TYPE_X, /* 0820 */ + JOINING_TYPE_X, /* 0821 */ + JOINING_TYPE_X, /* 0822 */ + JOINING_TYPE_X, /* 0823 */ + JOINING_TYPE_X, /* 0824 */ + JOINING_TYPE_X, /* 0825 */ + JOINING_TYPE_X, /* 0826 */ + JOINING_TYPE_X, /* 0827 */ + JOINING_TYPE_X, /* 0828 */ + JOINING_TYPE_X, /* 0829 */ + JOINING_TYPE_X, /* 082A */ + JOINING_TYPE_X, /* 082B */ + JOINING_TYPE_X, /* 082C */ + JOINING_TYPE_X, /* 082D */ + JOINING_TYPE_X, /* 082E */ + JOINING_TYPE_X, /* 082F */ + JOINING_TYPE_X, /* 0830 */ + JOINING_TYPE_X, /* 0831 */ + JOINING_TYPE_X, /* 0832 */ + JOINING_TYPE_X, /* 0833 */ + JOINING_TYPE_X, /* 0834 */ + JOINING_TYPE_X, /* 0835 */ + JOINING_TYPE_X, /* 0836 */ + JOINING_TYPE_X, /* 0837 */ + JOINING_TYPE_X, /* 0838 */ + JOINING_TYPE_X, /* 0839 */ + JOINING_TYPE_X, /* 083A */ + JOINING_TYPE_X, /* 083B */ + JOINING_TYPE_X, /* 083C */ + JOINING_TYPE_X, /* 083D */ + JOINING_TYPE_X, /* 083E */ + JOINING_TYPE_X, /* 083F */ + JOINING_TYPE_R, /* 0840; MANDAIC HALQA; R; No_Joining_Group */ + JOINING_TYPE_D, /* 0841; MANDAIC AB; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0842; MANDAIC AG; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0843; MANDAIC AD; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0844; MANDAIC AH; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0845; MANDAIC USHENNA; D; No_Joining_Group */ + JOINING_TYPE_R, /* 0846; MANDAIC AZ; R; No_Joining_Group */ + JOINING_TYPE_D, /* 0847; MANDAIC IT; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0848; MANDAIC ATT; D; No_Joining_Group */ + JOINING_TYPE_R, /* 0849; MANDAIC AKSA; R; No_Joining_Group */ + JOINING_TYPE_D, /* 084A; MANDAIC AK; D; No_Joining_Group */ + JOINING_TYPE_D, /* 084B; MANDAIC AL; D; No_Joining_Group */ + JOINING_TYPE_D, /* 084C; MANDAIC AM; D; No_Joining_Group */ + JOINING_TYPE_D, /* 084D; MANDAIC AN; D; No_Joining_Group */ + JOINING_TYPE_D, /* 084E; MANDAIC AS; D; No_Joining_Group */ + JOINING_TYPE_R, /* 084F; MANDAIC IN; R; No_Joining_Group */ + JOINING_TYPE_D, /* 0850; MANDAIC AP; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0851; MANDAIC ASZ; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0852; MANDAIC AQ; D; No_Joining_Group */ + JOINING_TYPE_D, /* 0853; MANDAIC AR; D; No_Joining_Group */ + JOINING_TYPE_R, /* 0854; MANDAIC ASH; R; No_Joining_Group */ + JOINING_TYPE_D, /* 0855; MANDAIC AT; D; No_Joining_Group */ + JOINING_TYPE_U, /* 0856; MANDAIC DUSHENNA; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0857; MANDAIC KAD; U; No_Joining_Group */ + JOINING_TYPE_U, /* 0858; MANDAIC AIN; U; No_Joining_Group */ + + /* Arabic Extended-A Characters */ + + JOINING_TYPE_X, /* 0859 */ + JOINING_TYPE_X, /* 085A */ + JOINING_TYPE_X, /* 085B */ + JOINING_TYPE_X, /* 085C */ + JOINING_TYPE_X, /* 085D */ + JOINING_TYPE_X, /* 085E */ + JOINING_TYPE_X, /* 085F */ + JOINING_TYPE_X, /* 0860 */ + JOINING_TYPE_X, /* 0861 */ + JOINING_TYPE_X, /* 0862 */ + JOINING_TYPE_X, /* 0863 */ + JOINING_TYPE_X, /* 0864 */ + JOINING_TYPE_X, /* 0865 */ + JOINING_TYPE_X, /* 0866 */ + JOINING_TYPE_X, /* 0867 */ + JOINING_TYPE_X, /* 0868 */ + JOINING_TYPE_X, /* 0869 */ + JOINING_TYPE_X, /* 086A */ + JOINING_TYPE_X, /* 086B */ + JOINING_TYPE_X, /* 086C */ + JOINING_TYPE_X, /* 086D */ + JOINING_TYPE_X, /* 086E */ + JOINING_TYPE_X, /* 086F */ + JOINING_TYPE_X, /* 0870 */ + JOINING_TYPE_X, /* 0871 */ + JOINING_TYPE_X, /* 0872 */ + JOINING_TYPE_X, /* 0873 */ + JOINING_TYPE_X, /* 0874 */ + JOINING_TYPE_X, /* 0875 */ + JOINING_TYPE_X, /* 0876 */ + JOINING_TYPE_X, /* 0877 */ + JOINING_TYPE_X, /* 0878 */ + JOINING_TYPE_X, /* 0879 */ + JOINING_TYPE_X, /* 087A */ + JOINING_TYPE_X, /* 087B */ + JOINING_TYPE_X, /* 087C */ + JOINING_TYPE_X, /* 087D */ + JOINING_TYPE_X, /* 087E */ + JOINING_TYPE_X, /* 087F */ + JOINING_TYPE_X, /* 0880 */ + JOINING_TYPE_X, /* 0881 */ + JOINING_TYPE_X, /* 0882 */ + JOINING_TYPE_X, /* 0883 */ + JOINING_TYPE_X, /* 0884 */ + JOINING_TYPE_X, /* 0885 */ + JOINING_TYPE_X, /* 0886 */ + JOINING_TYPE_X, /* 0887 */ + JOINING_TYPE_X, /* 0888 */ + JOINING_TYPE_X, /* 0889 */ + JOINING_TYPE_X, /* 088A */ + JOINING_TYPE_X, /* 088B */ + JOINING_TYPE_X, /* 088C */ + JOINING_TYPE_X, /* 088D */ + JOINING_TYPE_X, /* 088E */ + JOINING_TYPE_X, /* 088F */ + JOINING_TYPE_X, /* 0890 */ + JOINING_TYPE_X, /* 0891 */ + JOINING_TYPE_X, /* 0892 */ + JOINING_TYPE_X, /* 0893 */ + JOINING_TYPE_X, /* 0894 */ + JOINING_TYPE_X, /* 0895 */ + JOINING_TYPE_X, /* 0896 */ + JOINING_TYPE_X, /* 0897 */ + JOINING_TYPE_X, /* 0898 */ + JOINING_TYPE_X, /* 0899 */ + JOINING_TYPE_X, /* 089A */ + JOINING_TYPE_X, /* 089B */ + JOINING_TYPE_X, /* 089C */ + JOINING_TYPE_X, /* 089D */ + JOINING_TYPE_X, /* 089E */ + JOINING_TYPE_X, /* 089F */ + JOINING_TYPE_D, /* 08A0; DOTLESS BEH WITH V BELOW; D; BEH */ + JOINING_TYPE_X, /* 08A1 */ + JOINING_TYPE_D, /* 08A2; HAH WITH DOT BELOW AND 2 DOTS ABOVE; D; HAH */ + JOINING_TYPE_D, /* 08A3; TAH WITH 2 DOTS ABOVE; D; TAH */ + JOINING_TYPE_D, /* 08A4; DOTLESS FEH WITH DOT BELOW AND 3 DOTS ABOVE; D; FEH */ + JOINING_TYPE_D, /* 08A5; QAF WITH DOT BELOW; D; QAF */ + JOINING_TYPE_D, /* 08A6; LAM WITH DOUBLE BAR; D; LAM */ + JOINING_TYPE_D, /* 08A7; MEEM WITH 3 DOTS ABOVE; D; MEEM */ + JOINING_TYPE_D, /* 08A8; YEH WITH HAMZA ABOVE; D; YEH */ + JOINING_TYPE_D, /* 08A9; YEH WITH DOT ABOVE; D; YEH */ + JOINING_TYPE_R, /* 08AA; REH WITH LOOP; R; REH */ + JOINING_TYPE_R, /* 08AB; WAW WITH DOT WITHIN; R; WAW */ + JOINING_TYPE_R, /* 08AC; ROHINGYA YEH; R; ROHINGYA YEH */ + +}; + +#define JOINING_TABLE_FIRST 0x0600 +#define JOINING_TABLE_LAST 0x08AC + + +static const uint16_t shaping_table[][4] = +{ + {0x0000, 0x0000, 0x0000, 0xFE80}, /* U+0621 ARABIC LETTER HAMZA ISOLATED FORM */ + {0x0000, 0x0000, 0xFE82, 0xFE81}, /* U+0622 ARABIC LETTER ALEF WITH MADDA ABOVE */ + {0x0000, 0x0000, 0xFE84, 0xFE83}, /* U+0623 ARABIC LETTER ALEF WITH HAMZA ABOVE */ + {0x0000, 0x0000, 0xFE86, 0xFE85}, /* U+0624 ARABIC LETTER WAW WITH HAMZA ABOVE */ + {0x0000, 0x0000, 0xFE88, 0xFE87}, /* U+0625 ARABIC LETTER ALEF WITH HAMZA BELOW */ + {0xFE8B, 0xFE8C, 0xFE8A, 0xFE89}, /* U+0626 ARABIC LETTER YEH WITH HAMZA ABOVE */ + {0x0000, 0x0000, 0xFE8E, 0xFE8D}, /* U+0627 ARABIC LETTER ALEF */ + {0xFE91, 0xFE92, 0xFE90, 0xFE8F}, /* U+0628 ARABIC LETTER BEH */ + {0x0000, 0x0000, 0xFE94, 0xFE93}, /* U+0629 ARABIC LETTER TEH MARBUTA */ + {0xFE97, 0xFE98, 0xFE96, 0xFE95}, /* U+062A ARABIC LETTER TEH */ + {0xFE9B, 0xFE9C, 0xFE9A, 0xFE99}, /* U+062B ARABIC LETTER THEH */ + {0xFE9F, 0xFEA0, 0xFE9E, 0xFE9D}, /* U+062C ARABIC LETTER JEEM */ + {0xFEA3, 0xFEA4, 0xFEA2, 0xFEA1}, /* U+062D ARABIC LETTER HAH */ + {0xFEA7, 0xFEA8, 0xFEA6, 0xFEA5}, /* U+062E ARABIC LETTER KHAH */ + {0x0000, 0x0000, 0xFEAA, 0xFEA9}, /* U+062F ARABIC LETTER DAL */ + {0x0000, 0x0000, 0xFEAC, 0xFEAB}, /* U+0630 ARABIC LETTER THAL */ + {0x0000, 0x0000, 0xFEAE, 0xFEAD}, /* U+0631 ARABIC LETTER REH */ + {0x0000, 0x0000, 0xFEB0, 0xFEAF}, /* U+0632 ARABIC LETTER ZAIN */ + {0xFEB3, 0xFEB4, 0xFEB2, 0xFEB1}, /* U+0633 ARABIC LETTER SEEN */ + {0xFEB7, 0xFEB8, 0xFEB6, 0xFEB5}, /* U+0634 ARABIC LETTER SHEEN */ + {0xFEBB, 0xFEBC, 0xFEBA, 0xFEB9}, /* U+0635 ARABIC LETTER SAD */ + {0xFEBF, 0xFEC0, 0xFEBE, 0xFEBD}, /* U+0636 ARABIC LETTER DAD */ + {0xFEC3, 0xFEC4, 0xFEC2, 0xFEC1}, /* U+0637 ARABIC LETTER TAH */ + {0xFEC7, 0xFEC8, 0xFEC6, 0xFEC5}, /* U+0638 ARABIC LETTER ZAH */ + {0xFECB, 0xFECC, 0xFECA, 0xFEC9}, /* U+0639 ARABIC LETTER AIN */ + {0xFECF, 0xFED0, 0xFECE, 0xFECD}, /* U+063A ARABIC LETTER GHAIN */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+063B */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+063C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+063D */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+063E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+063F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0640 */ + {0xFED3, 0xFED4, 0xFED2, 0xFED1}, /* U+0641 ARABIC LETTER FEH */ + {0xFED7, 0xFED8, 0xFED6, 0xFED5}, /* U+0642 ARABIC LETTER QAF */ + {0xFEDB, 0xFEDC, 0xFEDA, 0xFED9}, /* U+0643 ARABIC LETTER KAF */ + {0xFEDF, 0xFEE0, 0xFEDE, 0xFEDD}, /* U+0644 ARABIC LETTER LAM */ + {0xFEE3, 0xFEE4, 0xFEE2, 0xFEE1}, /* U+0645 ARABIC LETTER MEEM */ + {0xFEE7, 0xFEE8, 0xFEE6, 0xFEE5}, /* U+0646 ARABIC LETTER NOON */ + {0xFEEB, 0xFEEC, 0xFEEA, 0xFEE9}, /* U+0647 ARABIC LETTER HEH */ + {0x0000, 0x0000, 0xFEEE, 0xFEED}, /* U+0648 ARABIC LETTER WAW */ + {0xFBE8, 0xFBE9, 0xFEF0, 0xFEEF}, /* U+0649 ARABIC LETTER */ + {0xFEF3, 0xFEF4, 0xFEF2, 0xFEF1}, /* U+064A ARABIC LETTER YEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+064B */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+064C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+064D */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+064E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+064F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0650 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0651 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0652 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0653 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0654 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0655 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0656 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0657 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0658 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0659 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065A */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065B */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065D */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+065F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0660 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0661 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0662 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0663 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0664 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0665 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0666 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0667 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0668 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0669 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066A */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066B */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066D */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+066F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0670 */ + {0x0000, 0x0000, 0xFB51, 0xFB50}, /* U+0671 ARABIC LETTER ALEF WASLA */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0672 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0673 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0674 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0675 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0676 */ + {0x0000, 0x0000, 0x0000, 0xFBDD}, /* U+0677 ARABIC LETTER U WITH HAMZA ABOVE ISOLATED FORM */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0678 */ + {0xFB68, 0xFB69, 0xFB67, 0xFB66}, /* U+0679 ARABIC LETTER TTEH */ + {0xFB60, 0xFB61, 0xFB5F, 0xFB5E}, /* U+067A ARABIC LETTER TTEHEH */ + {0xFB54, 0xFB55, 0xFB53, 0xFB52}, /* U+067B ARABIC LETTER BEEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+067C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+067D */ + {0xFB58, 0xFB59, 0xFB57, 0xFB56}, /* U+067E ARABIC LETTER PEH */ + {0xFB64, 0xFB65, 0xFB63, 0xFB62}, /* U+067F ARABIC LETTER TEHEH */ + {0xFB5C, 0xFB5D, 0xFB5B, 0xFB5A}, /* U+0680 ARABIC LETTER BEHEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0681 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0682 */ + {0xFB78, 0xFB79, 0xFB77, 0xFB76}, /* U+0683 ARABIC LETTER NYEH */ + {0xFB74, 0xFB75, 0xFB73, 0xFB72}, /* U+0684 ARABIC LETTER DYEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0685 */ + {0xFB7C, 0xFB7D, 0xFB7B, 0xFB7A}, /* U+0686 ARABIC LETTER TCHEH */ + {0xFB80, 0xFB81, 0xFB7F, 0xFB7E}, /* U+0687 ARABIC LETTER TCHEHEH */ + {0x0000, 0x0000, 0xFB89, 0xFB88}, /* U+0688 ARABIC LETTER DDAL */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0689 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+068A */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+068B */ + {0x0000, 0x0000, 0xFB85, 0xFB84}, /* U+068C ARABIC LETTER DAHAL */ + {0x0000, 0x0000, 0xFB83, 0xFB82}, /* U+068D ARABIC LETTER DDAHAL */ + {0x0000, 0x0000, 0xFB87, 0xFB86}, /* U+068E ARABIC LETTER DUL */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+068F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0690 */ + {0x0000, 0x0000, 0xFB8D, 0xFB8C}, /* U+0691 ARABIC LETTER RREH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0692 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0693 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0694 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0695 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0696 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0697 */ + {0x0000, 0x0000, 0xFB8B, 0xFB8A}, /* U+0698 ARABIC LETTER JEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+0699 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069A */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069B */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069C */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069D */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+069F */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A0 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A1 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A2 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A3 */ + {0xFB6C, 0xFB6D, 0xFB6B, 0xFB6A}, /* U+06A4 ARABIC LETTER VEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A5 */ + {0xFB70, 0xFB71, 0xFB6F, 0xFB6E}, /* U+06A6 ARABIC LETTER PEHEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A7 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06A8 */ + {0xFB90, 0xFB91, 0xFB8F, 0xFB8E}, /* U+06A9 ARABIC LETTER KEHEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06AA */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06AB */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06AC */ + {0xFBD5, 0xFBD6, 0xFBD4, 0xFBD3}, /* U+06AD ARABIC LETTER NG */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06AE */ + {0xFB94, 0xFB95, 0xFB93, 0xFB92}, /* U+06AF ARABIC LETTER GAF */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B0 */ + {0xFB9C, 0xFB9D, 0xFB9B, 0xFB9A}, /* U+06B1 ARABIC LETTER NGOEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B2 */ + {0xFB98, 0xFB99, 0xFB97, 0xFB96}, /* U+06B3 ARABIC LETTER GUEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B4 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B5 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B6 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B7 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B8 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06B9 */ + {0x0000, 0x0000, 0xFB9F, 0xFB9E}, /* U+06BA ARABIC LETTER NOON GHUNNA */ + {0xFBA2, 0xFBA3, 0xFBA1, 0xFBA0}, /* U+06BB ARABIC LETTER RNOON */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06BC */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06BD */ + {0xFBAC, 0xFBAD, 0xFBAB, 0xFBAA}, /* U+06BE ARABIC LETTER HEH DOACHASHMEE */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06BF */ + {0x0000, 0x0000, 0xFBA5, 0xFBA4}, /* U+06C0 ARABIC LETTER HEH WITH YEH ABOVE */ + {0xFBA8, 0xFBA9, 0xFBA7, 0xFBA6}, /* U+06C1 ARABIC LETTER HEH GOAL */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06C2 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06C3 */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06C4 */ + {0x0000, 0x0000, 0xFBE1, 0xFBE0}, /* U+06C5 ARABIC LETTER KIRGHIZ OE */ + {0x0000, 0x0000, 0xFBDA, 0xFBD9}, /* U+06C6 ARABIC LETTER OE */ + {0x0000, 0x0000, 0xFBD8, 0xFBD7}, /* U+06C7 ARABIC LETTER U */ + {0x0000, 0x0000, 0xFBDC, 0xFBDB}, /* U+06C8 ARABIC LETTER YU */ + {0x0000, 0x0000, 0xFBE3, 0xFBE2}, /* U+06C9 ARABIC LETTER KIRGHIZ YU */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06CA */ + {0x0000, 0x0000, 0xFBDF, 0xFBDE}, /* U+06CB ARABIC LETTER VE */ + {0xFBFE, 0xFBFF, 0xFBFD, 0xFBFC}, /* U+06CC ARABIC LETTER FARSI YEH */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06CD */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06CE */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06CF */ + {0xFBE6, 0xFBE7, 0xFBE5, 0xFBE4}, /* U+06D0 ARABIC LETTER E */ + {0x0000, 0x0000, 0x0000, 0x0000}, /* U+06D1 */ + {0x0000, 0x0000, 0xFBAF, 0xFBAE}, /* U+06D2 ARABIC LETTER YEH BARREE */ + {0x0000, 0x0000, 0xFBB1, 0xFBB0}, /* U+06D3 ARABIC LETTER YEH BARREE WITH HAMZA ABOVE */ +}; + +#define SHAPING_TABLE_FIRST 0x0621 +#define SHAPING_TABLE_LAST 0x06D3 + + +static const struct ligature_set_t { + uint16_t first; + struct ligature_pairs_t { + uint16_t second; + uint16_t ligature; + } ligatures[4]; +} ligature_table[] = +{ + { 0xFEDF, { + { 0xFE88, 0xFEF9 }, /* ARABIC LIGATURE LAM WITH ALEF WITH HAMZA BELOW ISOLATED FORM */ + { 0xFE82, 0xFEF5 }, /* ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE ISOLATED FORM */ + { 0xFE8E, 0xFEFB }, /* ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM */ + { 0xFE84, 0xFEF7 }, /* ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE ISOLATED FORM */ + }}, + { 0xFEE0, { + { 0xFE88, 0xFEFA }, /* ARABIC LIGATURE LAM WITH ALEF WITH HAMZA BELOW FINAL FORM */ + { 0xFE82, 0xFEF6 }, /* ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM */ + { 0xFE8E, 0xFEFC }, /* ARABIC LIGATURE LAM WITH ALEF FINAL FORM */ + { 0xFE84, 0xFEF8 }, /* ARABIC LIGATURE LAM WITH ALEF WITH HAMZA ABOVE FINAL FORM */ + }}, +}; + + +#endif /* HB_OT_SHAPE_COMPLEX_ARABIC_TABLE_HH */ + +/* == End of generated table == */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic.cc new file mode 100644 index 00000000000..35356fe97d3 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-arabic.cc @@ -0,0 +1,359 @@ +/* + * Copyright © 2010,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-complex-private.hh" +#include "hb-ot-shape-private.hh" + + +/* buffer var allocations */ +#define arabic_shaping_action() complex_var_u8_0() /* arabic shaping action */ + + +/* + * Bits used in the joining tables + */ +enum { + JOINING_TYPE_U = 0, + JOINING_TYPE_R = 1, + JOINING_TYPE_D = 2, + JOINING_TYPE_C = JOINING_TYPE_D, + JOINING_GROUP_ALAPH = 3, + JOINING_GROUP_DALATH_RISH = 4, + NUM_STATE_MACHINE_COLS = 5, + + /* We deliberately don't have a JOINING_TYPE_L since that's unused in Unicode. */ + + JOINING_TYPE_T = 6, + JOINING_TYPE_X = 7 /* means: use general-category to choose between U or T. */ +}; + +/* + * Joining types: + */ + +#include "hb-ot-shape-complex-arabic-table.hh" + +static unsigned int get_joining_type (hb_codepoint_t u, hb_unicode_general_category_t gen_cat) +{ + if (likely (hb_in_range<hb_codepoint_t> (u, JOINING_TABLE_FIRST, JOINING_TABLE_LAST))) { + unsigned int j_type = joining_table[u - JOINING_TABLE_FIRST]; + if (likely (j_type != JOINING_TYPE_X)) + return j_type; + } + + /* Mongolian joining data is not in ArabicJoining.txt yet. */ + if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x1800, 0x18AF))) + { + if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x1880, 0x1886))) + return JOINING_TYPE_U; + + /* All letters, SIBE SYLLABLE BOUNDARY MARKER, and NIRUGU are D */ + if ((FLAG(gen_cat) & (FLAG (HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER) | + FLAG (HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER))) + || u == 0x1807 || u == 0x180A) + return JOINING_TYPE_D; + } + + /* 'Phags-pa joining data is not in ArabicJoining.txt yet. */ + if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xA840, 0xA872))) + { + if (unlikely (u == 0xA872)) + /* XXX Looks like this should be TYPE_L, but we don't support that yet! */ + return JOINING_TYPE_R; + + return JOINING_TYPE_D; + } + + if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x200C, 0x200D))) + { + return u == 0x200C ? JOINING_TYPE_U : JOINING_TYPE_C; + } + + return (FLAG(gen_cat) & (FLAG(HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) | FLAG(HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | FLAG(HB_UNICODE_GENERAL_CATEGORY_FORMAT))) ? + JOINING_TYPE_T : JOINING_TYPE_U; +} + +static const hb_tag_t arabic_features[] = +{ + HB_TAG('i','n','i','t'), + HB_TAG('m','e','d','i'), + HB_TAG('f','i','n','a'), + HB_TAG('i','s','o','l'), + /* Syriac */ + HB_TAG('m','e','d','2'), + HB_TAG('f','i','n','2'), + HB_TAG('f','i','n','3'), + HB_TAG_NONE +}; + + +/* Same order as the feature array */ +enum { + INIT, + MEDI, + FINA, + ISOL, + + /* Syriac */ + MED2, + FIN2, + FIN3, + + NONE, + + ARABIC_NUM_FEATURES = NONE +}; + +static const struct arabic_state_table_entry { + uint8_t prev_action; + uint8_t curr_action; + uint16_t next_state; +} arabic_state_table[][NUM_STATE_MACHINE_COLS] = +{ + /* jt_U, jt_R, jt_D, jg_ALAPH, jg_DALATH_RISH */ + + /* State 0: prev was U, not willing to join. */ + { {NONE,NONE,0}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,ISOL,1}, {NONE,ISOL,6}, }, + + /* State 1: prev was R or ISOL/ALAPH, not willing to join. */ + { {NONE,NONE,0}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,FIN2,5}, {NONE,ISOL,6}, }, + + /* State 2: prev was D/ISOL, willing to join. */ + { {NONE,NONE,0}, {INIT,FINA,1}, {INIT,FINA,3}, {INIT,FINA,4}, {INIT,FINA,6}, }, + + /* State 3: prev was D/FINA, willing to join. */ + { {NONE,NONE,0}, {MEDI,FINA,1}, {MEDI,FINA,3}, {MEDI,FINA,4}, {MEDI,FINA,6}, }, + + /* State 4: prev was FINA ALAPH, not willing to join. */ + { {NONE,NONE,0}, {MED2,ISOL,1}, {MED2,ISOL,2}, {MED2,FIN2,5}, {MED2,ISOL,6}, }, + + /* State 5: prev was FIN2/FIN3 ALAPH, not willing to join. */ + { {NONE,NONE,0}, {ISOL,ISOL,1}, {ISOL,ISOL,2}, {ISOL,FIN2,5}, {ISOL,ISOL,6}, }, + + /* State 6: prev was DALATH/RISH, not willing to join. */ + { {NONE,NONE,0}, {NONE,ISOL,1}, {NONE,ISOL,2}, {NONE,FIN3,5}, {NONE,ISOL,6}, } +}; + + +static void +arabic_fallback_shape (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); + +static void +collect_features_arabic (hb_ot_shape_planner_t *plan) +{ + hb_ot_map_builder_t *map = &plan->map; + + /* For Language forms (in ArabicOT speak), we do the iso/fina/medi/init together, + * then rlig and calt each in their own stage. This makes IranNastaliq's ALLAH + * ligature work correctly. It's unfortunate though... + * + * This also makes Arial Bold in Windows7 work. See: + * https://bugzilla.mozilla.org/show_bug.cgi?id=644184 + * + * TODO: Add test cases for these two. + */ + + map->add_bool_feature (HB_TAG('c','c','m','p')); + map->add_bool_feature (HB_TAG('l','o','c','l')); + + map->add_gsub_pause (NULL); + + for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++) + map->add_bool_feature (arabic_features[i], false, i < 4); /* The first four features have fallback. */ + + map->add_gsub_pause (NULL); + + map->add_bool_feature (HB_TAG('r','l','i','g'), true, true); + map->add_gsub_pause (arabic_fallback_shape); + + map->add_bool_feature (HB_TAG('c','a','l','t')); + map->add_gsub_pause (NULL); + + map->add_bool_feature (HB_TAG('c','s','w','h')); + map->add_bool_feature (HB_TAG('d','l','i','g')); + map->add_bool_feature (HB_TAG('m','s','e','t')); +} + +#include "hb-ot-shape-complex-arabic-fallback.hh" + +struct arabic_shape_plan_t +{ + ASSERT_POD (); + + /* The "+ 1" in the next array is to accommodate for the "NONE" command, + * which is not an OpenType feature, but this simplifies the code by not + * having to do a "if (... < NONE) ..." and just rely on the fact that + * mask_array[NONE] == 0. */ + hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1]; + + bool do_fallback; + arabic_fallback_plan_t *fallback_plan; +}; + +static void * +data_create_arabic (const hb_ot_shape_plan_t *plan) +{ + arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) calloc (1, sizeof (arabic_shape_plan_t)); + if (unlikely (!arabic_plan)) + return NULL; + + arabic_plan->do_fallback = plan->props.script == HB_SCRIPT_ARABIC; + for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++) { + arabic_plan->mask_array[i] = plan->map.get_1_mask (arabic_features[i]); + if (i < 4) + arabic_plan->do_fallback = arabic_plan->do_fallback && plan->map.needs_fallback (arabic_features[i]); + } + + return arabic_plan; +} + +static void +data_destroy_arabic (void *data) +{ + arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) data; + + arabic_fallback_plan_destroy (arabic_plan->fallback_plan); + + free (data); +} + +static void +arabic_joining (hb_buffer_t *buffer) +{ + unsigned int count = buffer->len; + unsigned int prev = (unsigned int) -1, state = 0; + + HB_BUFFER_ALLOCATE_VAR (buffer, arabic_shaping_action); + + /* Check pre-context */ + if (!(buffer->flags & HB_BUFFER_FLAG_BOT)) + for (unsigned int i = 0; i < buffer->context_len[0]; i++) + { + unsigned int this_type = get_joining_type (buffer->context[0][i], buffer->unicode->general_category (buffer->context[0][i])); + + if (unlikely (this_type == JOINING_TYPE_T)) + continue; + + const arabic_state_table_entry *entry = &arabic_state_table[state][this_type]; + state = entry->next_state; + break; + } + + for (unsigned int i = 0; i < count; i++) + { + unsigned int this_type = get_joining_type (buffer->info[i].codepoint, _hb_glyph_info_get_general_category (&buffer->info[i])); + + if (unlikely (this_type == JOINING_TYPE_T)) { + buffer->info[i].arabic_shaping_action() = NONE; + continue; + } + + const arabic_state_table_entry *entry = &arabic_state_table[state][this_type]; + + if (entry->prev_action != NONE && prev != (unsigned int) -1) + buffer->info[prev].arabic_shaping_action() = entry->prev_action; + + buffer->info[i].arabic_shaping_action() = entry->curr_action; + + prev = i; + state = entry->next_state; + } + + if (!(buffer->flags & HB_BUFFER_FLAG_EOT)) + for (unsigned int i = 0; i < buffer->context_len[1]; i++) + { + unsigned int this_type = get_joining_type (buffer->context[1][i], buffer->unicode->general_category (buffer->context[1][i])); + + if (unlikely (this_type == JOINING_TYPE_T)) + continue; + + const arabic_state_table_entry *entry = &arabic_state_table[state][this_type]; + if (entry->prev_action != NONE && prev != (unsigned int) -1) + buffer->info[prev].arabic_shaping_action() = entry->prev_action; + break; + } + + + HB_BUFFER_DEALLOCATE_VAR (buffer, arabic_shaping_action); +} + +static void +setup_masks_arabic (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + hb_font_t *font HB_UNUSED) +{ + const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->data; + + arabic_joining (buffer); + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + buffer->info[i].mask |= arabic_plan->mask_array[buffer->info[i].arabic_shaping_action()]; +} + + +static void +arabic_fallback_shape (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer) +{ + const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->data; + + if (!arabic_plan->do_fallback) + return; + +retry: + arabic_fallback_plan_t *fallback_plan = (arabic_fallback_plan_t *) hb_atomic_ptr_get (&arabic_plan->fallback_plan); + if (unlikely (!fallback_plan)) + { + /* This sucks. We need a font to build the fallback plan... */ + fallback_plan = arabic_fallback_plan_create (plan, font); + if (unlikely (!hb_atomic_ptr_cmpexch (&(const_cast<arabic_shape_plan_t *> (arabic_plan))->fallback_plan, NULL, fallback_plan))) { + arabic_fallback_plan_destroy (fallback_plan); + goto retry; + } + } + + arabic_fallback_plan_shape (fallback_plan, font, buffer); +} + + +const hb_ot_complex_shaper_t _hb_ot_complex_shaper_arabic = +{ + "arabic", + collect_features_arabic, + NULL, /* override_features */ + data_create_arabic, + data_destroy_arabic, + NULL, /* preprocess_text_arabic */ + NULL, /* normalization_preference */ + NULL, /* decompose */ + NULL, /* compose */ + setup_masks_arabic, + true, /* zero_width_attached_marks */ + true, /* fallback_position */ +}; diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-default.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-default.cc new file mode 100644 index 00000000000..5340293db50 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-default.cc @@ -0,0 +1,226 @@ +/* + * Copyright © 2010,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-complex-private.hh" + + +/* TODO Add kana, and other small shapers here */ + + +/* The default shaper *only* adds additional per-script features.*/ + +static const hb_tag_t hangul_features[] = +{ + HB_TAG('l','j','m','o'), + HB_TAG('v','j','m','o'), + HB_TAG('t','j','m','o'), + HB_TAG_NONE +}; + +static const hb_tag_t tibetan_features[] = +{ + HB_TAG('a','b','v','s'), + HB_TAG('b','l','w','s'), + HB_TAG('a','b','v','m'), + HB_TAG('b','l','w','m'), + HB_TAG_NONE +}; + +static void +collect_features_default (hb_ot_shape_planner_t *plan) +{ + const hb_tag_t *script_features = NULL; + + switch ((hb_tag_t) plan->props.script) + { + /* Unicode-1.1 additions */ + case HB_SCRIPT_HANGUL: + script_features = hangul_features; + break; + + /* Unicode-2.0 additions */ + case HB_SCRIPT_TIBETAN: + script_features = tibetan_features; + break; + } + + for (; script_features && *script_features; script_features++) + plan->map.add_bool_feature (*script_features); +} + +static hb_ot_shape_normalization_mode_t +normalization_preference_default (const hb_segment_properties_t *props) +{ + switch ((hb_tag_t) props->script) + { + /* Unicode-1.1 additions */ + case HB_SCRIPT_HANGUL: + return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL; + } + return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS; +} + +static bool +compose_default (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab) +{ + /* Hebrew presentation-form shaping. + * https://bugzilla.mozilla.org/show_bug.cgi?id=728866 + * Hebrew presentation forms with dagesh, for characters 0x05D0..0x05EA; + * Note that some letters do not have a dagesh presForm encoded. + */ + static const hb_codepoint_t sDageshForms[0x05EA - 0x05D0 + 1] = { + 0xFB30, /* ALEF */ + 0xFB31, /* BET */ + 0xFB32, /* GIMEL */ + 0xFB33, /* DALET */ + 0xFB34, /* HE */ + 0xFB35, /* VAV */ + 0xFB36, /* ZAYIN */ + 0x0000, /* HET */ + 0xFB38, /* TET */ + 0xFB39, /* YOD */ + 0xFB3A, /* FINAL KAF */ + 0xFB3B, /* KAF */ + 0xFB3C, /* LAMED */ + 0x0000, /* FINAL MEM */ + 0xFB3E, /* MEM */ + 0x0000, /* FINAL NUN */ + 0xFB40, /* NUN */ + 0xFB41, /* SAMEKH */ + 0x0000, /* AYIN */ + 0xFB43, /* FINAL PE */ + 0xFB44, /* PE */ + 0x0000, /* FINAL TSADI */ + 0xFB46, /* TSADI */ + 0xFB47, /* QOF */ + 0xFB48, /* RESH */ + 0xFB49, /* SHIN */ + 0xFB4A /* TAV */ + }; + + bool found = c->unicode->compose (a, b, ab); + + if (!found && (b & ~0x7F) == 0x0580) { + /* Special-case Hebrew presentation forms that are excluded from + * standard normalization, but wanted for old fonts. */ + switch (b) { + case 0x05B4: /* HIRIQ */ + if (a == 0x05D9) { /* YOD */ + *ab = 0xFB1D; + found = true; + } + break; + case 0x05B7: /* patah */ + if (a == 0x05F2) { /* YIDDISH YOD YOD */ + *ab = 0xFB1F; + found = true; + } else if (a == 0x05D0) { /* ALEF */ + *ab = 0xFB2E; + found = true; + } + break; + case 0x05B8: /* QAMATS */ + if (a == 0x05D0) { /* ALEF */ + *ab = 0xFB2F; + found = true; + } + break; + case 0x05B9: /* HOLAM */ + if (a == 0x05D5) { /* VAV */ + *ab = 0xFB4B; + found = true; + } + break; + case 0x05BC: /* DAGESH */ + if (a >= 0x05D0 && a <= 0x05EA) { + *ab = sDageshForms[a - 0x05D0]; + found = (*ab != 0); + } else if (a == 0xFB2A) { /* SHIN WITH SHIN DOT */ + *ab = 0xFB2C; + found = true; + } else if (a == 0xFB2B) { /* SHIN WITH SIN DOT */ + *ab = 0xFB2D; + found = true; + } + break; + case 0x05BF: /* RAFE */ + switch (a) { + case 0x05D1: /* BET */ + *ab = 0xFB4C; + found = true; + break; + case 0x05DB: /* KAF */ + *ab = 0xFB4D; + found = true; + break; + case 0x05E4: /* PE */ + *ab = 0xFB4E; + found = true; + break; + } + break; + case 0x05C1: /* SHIN DOT */ + if (a == 0x05E9) { /* SHIN */ + *ab = 0xFB2A; + found = true; + } else if (a == 0xFB49) { /* SHIN WITH DAGESH */ + *ab = 0xFB2C; + found = true; + } + break; + case 0x05C2: /* SIN DOT */ + if (a == 0x05E9) { /* SHIN */ + *ab = 0xFB2B; + found = true; + } else if (a == 0xFB49) { /* SHIN WITH DAGESH */ + *ab = 0xFB2D; + found = true; + } + break; + } + } + + return found; +} + +const hb_ot_complex_shaper_t _hb_ot_complex_shaper_default = +{ + "default", + collect_features_default, + NULL, /* override_features */ + NULL, /* data_create */ + NULL, /* data_destroy */ + NULL, /* preprocess_text */ + normalization_preference_default, + NULL, /* decompose */ + compose_default, + NULL, /* setup_masks */ + true, /* zero_width_attached_marks */ + true, /* fallback_position */ +}; diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.hh new file mode 100644 index 00000000000..ed40b968bcb --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.hh @@ -0,0 +1,1443 @@ + +#line 1 "../../src/hb-ot-shape-complex-indic-machine.rl" +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH +#define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH + +#include "hb-private.hh" + + +#line 36 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" +static const unsigned char _indic_syllable_machine_trans_keys[] = { + 1u, 16u, 13u, 13u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, + 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 4u, 4u, 6u, 6u, + 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, + 6u, 6u, 16u, 16u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, + 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 1u, 16u, 13u, 13u, 5u, 7u, 5u, 7u, + 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, + 5u, 7u, 7u, 7u, 4u, 4u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, + 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 14u, 4u, 14u, + 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, + 1u, 16u, 13u, 13u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, + 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 4u, 4u, 6u, 6u, + 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, + 6u, 6u, 16u, 16u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, + 4u, 14u, 4u, 14u, 4u, 14u, 1u, 16u, 13u, 13u, 5u, 7u, 5u, 7u, 7u, 7u, + 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, + 7u, 7u, 4u, 4u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, + 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 14u, 4u, 14u, 4u, 14u, + 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, 4u, 14u, + 4u, 14u, 5u, 7u, 5u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 5u, 7u, 5u, 7u, + 7u, 7u, 5u, 7u, 5u, 7u, 7u, 7u, 1u, 16u, 13u, 13u, 4u, 4u, 6u, 6u, + 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, 6u, 6u, 16u, 16u, 4u, 7u, + 6u, 6u, 16u, 16u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, + 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, + 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 5u, 14u, 8u, 14u, + 5u, 9u, 9u, 9u, 9u, 9u, 3u, 17u, 3u, 9u, 8u, 9u, 3u, 9u, 3u, 13u, + 3u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, + 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 6u, 14u, 3u, 14u, 4u, 14u, 1u, 16u, + 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, + 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, + 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, + 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 3u, 14u, 3u, 14u, + 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, + 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, + 4u, 14u, 5u, 14u, 8u, 14u, 5u, 9u, 9u, 9u, 9u, 9u, 3u, 17u, 3u, 9u, + 8u, 9u, 3u, 9u, 3u, 13u, 3u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, + 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 6u, 14u, + 3u, 14u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, + 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, + 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, + 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 4u, 14u, 1u, 16u, 3u, 14u, + 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, + 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, + 3u, 14u, 4u, 14u, 5u, 14u, 8u, 14u, 5u, 9u, 9u, 9u, 9u, 9u, 3u, 17u, + 3u, 9u, 8u, 9u, 3u, 9u, 3u, 13u, 3u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, + 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, + 6u, 14u, 3u, 14u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, + 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, + 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, + 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 4u, 14u, + 3u, 14u, 4u, 14u, 3u, 14u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, + 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, + 4u, 14u, 1u, 16u, 3u, 17u, 3u, 14u, 4u, 14u, 5u, 14u, 8u, 14u, 5u, 9u, + 9u, 9u, 9u, 9u, 3u, 17u, 3u, 9u, 8u, 9u, 3u, 9u, 3u, 13u, 3u, 14u, + 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, + 5u, 14u, 3u, 14u, 4u, 14u, 6u, 14u, 3u, 14u, 1u, 16u, 3u, 14u, 3u, 14u, + 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, + 1u, 16u, 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, + 1u, 16u, 1u, 16u, 1u, 16u, 3u, 14u, 3u, 14u, 1u, 16u, 1u, 16u, 1u, 16u, + 1u, 16u, 1u, 16u, 3u, 14u, 1u, 16u, 3u, 17u, 1u, 16u, 4u, 14u, 1u, 16u, + 3u, 17u, 3u, 14u, 4u, 14u, 5u, 9u, 9u, 9u, 9u, 9u, 3u, 14u, 3u, 14u, + 1u, 16u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 5u, 14u, 3u, 14u, + 4u, 14u, 5u, 14u, 3u, 14u, 4u, 14u, 8u, 14u, 3u, 17u, 3u, 9u, 8u, 9u, + 3u, 9u, 3u, 13u, 1u, 16u, 0 +}; + +static const char _indic_syllable_machine_key_spans[] = { + 16, 1, 3, 3, 1, 3, 3, 1, + 3, 3, 1, 3, 3, 1, 1, 1, + 1, 4, 1, 1, 4, 1, 1, 4, + 1, 1, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 16, 1, 3, 3, + 1, 3, 3, 1, 3, 3, 1, 3, + 3, 1, 1, 1, 1, 4, 1, 1, + 4, 1, 1, 4, 1, 1, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 16, 1, 3, 3, 1, 3, 3, 1, + 3, 3, 1, 3, 3, 1, 1, 1, + 1, 4, 1, 1, 4, 1, 1, 4, + 1, 1, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 16, 1, 3, 3, 1, + 3, 3, 1, 3, 3, 1, 3, 3, + 1, 1, 1, 1, 4, 1, 1, 4, + 1, 1, 4, 1, 1, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 3, 3, 3, 3, 1, 3, 3, + 1, 3, 3, 1, 16, 1, 1, 1, + 1, 4, 1, 1, 4, 1, 1, 4, + 1, 1, 16, 15, 12, 11, 16, 15, + 12, 11, 16, 15, 12, 11, 16, 15, + 12, 11, 16, 15, 12, 11, 10, 7, + 5, 1, 1, 15, 7, 2, 7, 11, + 12, 12, 11, 10, 12, 11, 10, 12, + 11, 10, 12, 11, 9, 12, 11, 16, + 12, 12, 16, 16, 16, 16, 16, 12, + 12, 16, 16, 16, 16, 16, 12, 12, + 16, 16, 16, 16, 16, 12, 12, 16, + 16, 16, 16, 16, 12, 12, 12, 12, + 11, 16, 15, 12, 11, 16, 15, 12, + 11, 16, 15, 12, 11, 16, 15, 12, + 11, 10, 7, 5, 1, 1, 15, 7, + 2, 7, 11, 12, 12, 11, 10, 12, + 11, 10, 12, 11, 10, 12, 11, 9, + 12, 16, 12, 12, 16, 16, 16, 16, + 16, 12, 12, 16, 16, 16, 16, 16, + 12, 12, 16, 16, 16, 16, 16, 12, + 12, 16, 16, 16, 16, 11, 16, 12, + 12, 11, 16, 15, 12, 11, 16, 15, + 12, 11, 16, 15, 12, 11, 16, 15, + 12, 11, 10, 7, 5, 1, 1, 15, + 7, 2, 7, 11, 12, 12, 11, 10, + 12, 11, 10, 12, 11, 10, 12, 11, + 9, 12, 16, 12, 12, 16, 16, 16, + 16, 16, 12, 12, 16, 16, 16, 16, + 16, 12, 12, 16, 16, 16, 16, 16, + 12, 12, 16, 16, 16, 16, 16, 11, + 12, 11, 12, 12, 11, 16, 15, 12, + 11, 16, 15, 12, 11, 16, 15, 12, + 11, 16, 15, 12, 11, 10, 7, 5, + 1, 1, 15, 7, 2, 7, 11, 12, + 12, 11, 10, 12, 11, 10, 12, 11, + 10, 12, 11, 9, 12, 16, 12, 12, + 16, 16, 16, 16, 16, 12, 12, 16, + 16, 16, 16, 16, 12, 12, 16, 16, + 16, 16, 16, 12, 12, 16, 16, 16, + 16, 16, 12, 16, 15, 16, 11, 16, + 15, 12, 11, 5, 1, 1, 12, 12, + 16, 12, 11, 10, 12, 11, 10, 12, + 11, 10, 12, 11, 7, 15, 7, 2, + 7, 11, 16 +}; + +static const short _indic_syllable_machine_index_offsets[] = { + 0, 17, 19, 23, 27, 29, 33, 37, + 39, 43, 47, 49, 53, 57, 59, 61, + 63, 65, 70, 72, 74, 79, 81, 83, + 88, 90, 92, 104, 116, 128, 140, 152, + 164, 176, 188, 200, 212, 229, 231, 235, + 239, 241, 245, 249, 251, 255, 259, 261, + 265, 269, 271, 273, 275, 277, 282, 284, + 286, 291, 293, 295, 300, 302, 304, 316, + 328, 340, 352, 364, 376, 388, 400, 412, + 424, 441, 443, 447, 451, 453, 457, 461, + 463, 467, 471, 473, 477, 481, 483, 485, + 487, 489, 494, 496, 498, 503, 505, 507, + 512, 514, 516, 528, 540, 552, 564, 576, + 588, 600, 612, 624, 641, 643, 647, 651, + 653, 657, 661, 663, 667, 671, 673, 677, + 681, 683, 685, 687, 689, 694, 696, 698, + 703, 705, 707, 712, 714, 716, 728, 740, + 752, 764, 776, 788, 800, 812, 824, 836, + 848, 860, 864, 868, 872, 876, 878, 882, + 886, 888, 892, 896, 898, 915, 917, 919, + 921, 923, 928, 930, 932, 937, 939, 941, + 946, 948, 950, 967, 983, 996, 1008, 1025, + 1041, 1054, 1066, 1083, 1099, 1112, 1124, 1141, + 1157, 1170, 1182, 1199, 1215, 1228, 1240, 1251, + 1259, 1265, 1267, 1269, 1285, 1293, 1296, 1304, + 1316, 1329, 1342, 1354, 1365, 1378, 1390, 1401, + 1414, 1426, 1437, 1450, 1462, 1472, 1485, 1497, + 1514, 1527, 1540, 1557, 1574, 1591, 1608, 1625, + 1638, 1651, 1668, 1685, 1702, 1719, 1736, 1749, + 1762, 1779, 1796, 1813, 1830, 1847, 1860, 1873, + 1890, 1907, 1924, 1941, 1958, 1971, 1984, 1997, + 2010, 2022, 2039, 2055, 2068, 2080, 2097, 2113, + 2126, 2138, 2155, 2171, 2184, 2196, 2213, 2229, + 2242, 2254, 2265, 2273, 2279, 2281, 2283, 2299, + 2307, 2310, 2318, 2330, 2343, 2356, 2368, 2379, + 2392, 2404, 2415, 2428, 2440, 2451, 2464, 2476, + 2486, 2499, 2516, 2529, 2542, 2559, 2576, 2593, + 2610, 2627, 2640, 2653, 2670, 2687, 2704, 2721, + 2738, 2751, 2764, 2781, 2798, 2815, 2832, 2849, + 2862, 2875, 2892, 2909, 2926, 2943, 2955, 2972, + 2985, 2998, 3010, 3027, 3043, 3056, 3068, 3085, + 3101, 3114, 3126, 3143, 3159, 3172, 3184, 3201, + 3217, 3230, 3242, 3253, 3261, 3267, 3269, 3271, + 3287, 3295, 3298, 3306, 3318, 3331, 3344, 3356, + 3367, 3380, 3392, 3403, 3416, 3428, 3439, 3452, + 3464, 3474, 3487, 3504, 3517, 3530, 3547, 3564, + 3581, 3598, 3615, 3628, 3641, 3658, 3675, 3692, + 3709, 3726, 3739, 3752, 3769, 3786, 3803, 3820, + 3837, 3850, 3863, 3880, 3897, 3914, 3931, 3948, + 3960, 3973, 3985, 3998, 4011, 4023, 4040, 4056, + 4069, 4081, 4098, 4114, 4127, 4139, 4156, 4172, + 4185, 4197, 4214, 4230, 4243, 4255, 4266, 4274, + 4280, 4282, 4284, 4300, 4308, 4311, 4319, 4331, + 4344, 4357, 4369, 4380, 4393, 4405, 4416, 4429, + 4441, 4452, 4465, 4477, 4487, 4500, 4517, 4530, + 4543, 4560, 4577, 4594, 4611, 4628, 4641, 4654, + 4671, 4688, 4705, 4722, 4739, 4752, 4765, 4782, + 4799, 4816, 4833, 4850, 4863, 4876, 4893, 4910, + 4927, 4944, 4961, 4974, 4991, 5007, 5024, 5036, + 5053, 5069, 5082, 5094, 5100, 5102, 5104, 5117, + 5130, 5147, 5160, 5172, 5183, 5196, 5208, 5219, + 5232, 5244, 5255, 5268, 5280, 5288, 5304, 5312, + 5315, 5323, 5335 +}; + +static const short _indic_syllable_machine_indicies[] = { + 1, 2, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 0, 3, 0, 4, 4, 5, 0, 6, + 6, 5, 0, 5, 0, 7, 7, 8, + 0, 9, 9, 8, 0, 8, 0, 10, + 10, 11, 0, 12, 12, 11, 0, 11, + 0, 13, 13, 14, 0, 15, 15, 14, + 0, 14, 0, 16, 0, 17, 0, 18, + 0, 19, 13, 13, 14, 0, 20, 0, + 21, 0, 22, 10, 10, 11, 0, 23, + 0, 24, 0, 25, 7, 7, 8, 0, + 26, 0, 27, 0, 28, 4, 4, 5, + 0, 0, 0, 0, 0, 0, 28, 0, + 28, 4, 4, 5, 0, 0, 0, 0, + 0, 29, 28, 0, 30, 4, 4, 5, + 0, 0, 0, 0, 0, 0, 30, 0, + 30, 4, 4, 5, 0, 0, 0, 0, + 0, 31, 30, 0, 32, 4, 4, 5, + 0, 0, 0, 0, 0, 0, 32, 0, + 32, 4, 4, 5, 0, 0, 0, 0, + 0, 33, 32, 0, 34, 4, 4, 5, + 0, 0, 0, 0, 0, 0, 34, 0, + 34, 4, 4, 5, 0, 0, 0, 0, + 0, 35, 34, 0, 36, 4, 4, 5, + 0, 0, 0, 0, 0, 0, 36, 0, + 36, 4, 4, 5, 0, 0, 0, 0, + 0, 37, 36, 0, 39, 40, 38, 38, + 38, 38, 38, 38, 38, 38, 38, 38, + 38, 38, 38, 39, 38, 41, 38, 42, + 42, 43, 38, 44, 44, 43, 38, 43, + 38, 45, 45, 46, 38, 47, 47, 46, + 38, 46, 38, 48, 48, 49, 38, 50, + 50, 49, 38, 49, 38, 51, 51, 52, + 38, 53, 53, 52, 38, 52, 38, 54, + 38, 55, 38, 56, 38, 57, 51, 51, + 52, 38, 58, 38, 59, 38, 60, 48, + 48, 49, 38, 61, 38, 62, 38, 63, + 45, 45, 46, 38, 64, 38, 65, 38, + 66, 42, 42, 43, 38, 38, 38, 38, + 38, 38, 66, 38, 66, 42, 42, 43, + 38, 38, 38, 38, 38, 67, 66, 38, + 68, 42, 42, 43, 38, 38, 38, 38, + 38, 38, 68, 38, 68, 42, 42, 43, + 38, 38, 38, 38, 38, 69, 68, 38, + 70, 42, 42, 43, 38, 38, 38, 38, + 38, 38, 70, 38, 70, 42, 42, 43, + 38, 38, 38, 38, 38, 71, 70, 38, + 72, 42, 42, 43, 38, 38, 38, 38, + 38, 38, 72, 38, 72, 42, 42, 43, + 38, 38, 38, 38, 38, 73, 72, 38, + 74, 42, 42, 43, 38, 38, 38, 38, + 38, 38, 74, 38, 74, 42, 42, 43, + 38, 38, 38, 38, 38, 75, 74, 38, + 77, 78, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 77, + 76, 79, 76, 80, 80, 81, 76, 83, + 83, 81, 82, 81, 82, 84, 84, 85, + 76, 86, 86, 85, 76, 85, 76, 87, + 87, 88, 76, 89, 89, 88, 76, 88, + 76, 90, 90, 91, 76, 92, 92, 91, + 76, 91, 76, 93, 76, 94, 76, 95, + 76, 96, 90, 90, 91, 76, 97, 76, + 98, 76, 99, 87, 87, 88, 76, 100, + 76, 101, 76, 102, 84, 84, 85, 76, + 103, 76, 104, 76, 105, 80, 80, 81, + 76, 76, 76, 76, 76, 76, 105, 76, + 105, 80, 80, 81, 76, 76, 76, 76, + 76, 106, 105, 76, 107, 80, 80, 81, + 76, 76, 76, 76, 76, 76, 107, 76, + 107, 80, 80, 81, 76, 76, 76, 76, + 76, 108, 107, 76, 109, 80, 80, 81, + 76, 76, 76, 76, 76, 76, 109, 76, + 109, 80, 80, 81, 76, 76, 76, 76, + 76, 110, 109, 76, 111, 80, 80, 81, + 82, 82, 82, 82, 82, 82, 111, 82, + 111, 80, 80, 81, 76, 76, 76, 76, + 76, 112, 111, 76, 113, 80, 80, 81, + 76, 76, 76, 76, 76, 76, 113, 76, + 115, 116, 114, 114, 114, 114, 114, 114, + 114, 114, 114, 114, 114, 114, 114, 115, + 114, 117, 114, 118, 118, 119, 114, 120, + 120, 119, 114, 119, 114, 121, 121, 122, + 114, 123, 123, 122, 114, 122, 114, 124, + 124, 125, 114, 126, 126, 125, 114, 125, + 114, 127, 127, 128, 114, 129, 129, 128, + 114, 128, 114, 130, 114, 131, 114, 132, + 114, 133, 127, 127, 128, 114, 134, 114, + 135, 114, 136, 124, 124, 125, 114, 137, + 114, 138, 114, 139, 121, 121, 122, 114, + 140, 114, 141, 114, 142, 118, 118, 119, + 114, 114, 114, 114, 114, 114, 142, 114, + 142, 118, 118, 119, 114, 114, 114, 114, + 114, 143, 142, 114, 144, 118, 118, 119, + 114, 114, 114, 114, 114, 114, 144, 114, + 144, 118, 118, 119, 114, 114, 114, 114, + 114, 145, 144, 114, 146, 118, 118, 119, + 114, 114, 114, 114, 114, 114, 146, 114, + 146, 118, 118, 119, 114, 114, 114, 114, + 114, 147, 146, 114, 148, 118, 118, 119, + 114, 114, 114, 114, 114, 114, 148, 114, + 148, 118, 118, 119, 114, 114, 114, 114, + 114, 149, 148, 114, 150, 118, 118, 119, + 114, 114, 114, 114, 114, 114, 150, 114, + 150, 118, 118, 119, 114, 114, 114, 114, + 114, 151, 150, 114, 113, 80, 80, 81, + 76, 76, 76, 76, 76, 152, 113, 76, + 111, 80, 80, 81, 0, 0, 0, 0, + 0, 153, 111, 0, 154, 154, 155, 0, + 6, 6, 155, 0, 156, 156, 157, 0, + 158, 158, 157, 0, 157, 0, 159, 159, + 160, 0, 161, 161, 160, 0, 160, 0, + 162, 162, 163, 0, 164, 164, 163, 0, + 163, 0, 165, 166, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 165, 0, 167, 0, 168, 0, 169, + 0, 170, 0, 171, 162, 162, 163, 0, + 172, 0, 173, 0, 174, 159, 159, 160, + 0, 175, 0, 176, 0, 177, 156, 156, + 157, 0, 178, 0, 179, 0, 181, 182, + 183, 184, 185, 186, 81, 187, 188, 180, + 189, 189, 152, 190, 191, 192, 180, 194, + 195, 196, 197, 5, 198, 199, 200, 193, + 193, 37, 201, 193, 193, 181, 193, 202, + 195, 203, 203, 5, 198, 199, 200, 193, + 193, 193, 201, 193, 195, 203, 203, 5, + 198, 199, 200, 193, 193, 193, 201, 193, + 204, 193, 193, 193, 18, 205, 193, 198, + 199, 193, 193, 193, 193, 206, 193, 204, + 193, 207, 208, 209, 210, 5, 198, 199, + 200, 193, 193, 35, 211, 193, 193, 204, + 193, 212, 208, 213, 213, 5, 198, 199, + 200, 193, 193, 193, 211, 193, 208, 213, + 213, 5, 198, 199, 200, 193, 193, 193, + 211, 193, 214, 193, 193, 193, 18, 215, + 193, 198, 199, 193, 193, 193, 193, 206, + 193, 214, 193, 216, 217, 218, 219, 5, + 198, 199, 200, 193, 193, 33, 220, 193, + 193, 214, 193, 221, 217, 222, 222, 5, + 198, 199, 200, 193, 193, 193, 220, 193, + 217, 222, 222, 5, 198, 199, 200, 193, + 193, 193, 220, 193, 223, 193, 193, 193, + 18, 224, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 223, 193, 225, 226, 227, + 228, 5, 198, 199, 200, 193, 193, 31, + 229, 193, 193, 223, 193, 230, 226, 231, + 231, 5, 198, 199, 200, 193, 193, 193, + 229, 193, 226, 231, 231, 5, 198, 199, + 200, 193, 193, 193, 229, 193, 232, 193, + 193, 193, 18, 233, 193, 198, 199, 193, + 193, 193, 193, 206, 193, 232, 193, 234, + 235, 236, 237, 5, 198, 199, 200, 193, + 193, 29, 238, 193, 193, 232, 193, 239, + 235, 240, 240, 5, 198, 199, 200, 193, + 193, 193, 238, 193, 235, 240, 240, 5, + 198, 199, 200, 193, 193, 193, 238, 193, + 18, 241, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 242, 193, 193, 193, 199, + 193, 199, 193, 243, 193, 244, 193, 245, + 246, 193, 198, 199, 193, 193, 193, 3, + 193, 193, 193, 1, 193, 2, 193, 193, + 193, 193, 198, 199, 193, 198, 199, 193, + 244, 193, 193, 193, 193, 198, 199, 193, + 244, 193, 245, 193, 193, 198, 199, 193, + 193, 193, 3, 193, 18, 193, 247, 247, + 5, 198, 199, 193, 193, 193, 193, 206, + 193, 248, 27, 249, 250, 8, 198, 199, + 193, 193, 193, 193, 206, 193, 27, 249, + 250, 8, 198, 199, 193, 193, 193, 193, + 206, 193, 249, 249, 8, 198, 199, 193, + 193, 193, 193, 206, 193, 251, 24, 252, + 253, 11, 198, 199, 193, 193, 193, 193, + 206, 193, 24, 252, 253, 11, 198, 199, + 193, 193, 193, 193, 206, 193, 252, 252, + 11, 198, 199, 193, 193, 193, 193, 206, + 193, 254, 21, 255, 256, 14, 198, 199, + 193, 193, 193, 193, 206, 193, 21, 255, + 256, 14, 198, 199, 193, 193, 193, 193, + 206, 193, 255, 255, 14, 198, 199, 193, + 193, 193, 193, 206, 193, 257, 18, 193, + 258, 193, 198, 199, 193, 193, 193, 193, + 206, 193, 18, 193, 258, 193, 198, 199, + 193, 193, 193, 193, 206, 193, 259, 193, + 198, 199, 193, 193, 193, 193, 206, 193, + 18, 193, 193, 193, 193, 198, 199, 193, + 193, 193, 193, 206, 193, 235, 240, 240, + 5, 198, 199, 193, 193, 193, 193, 238, + 193, 1, 2, 193, 193, 18, 241, 193, + 198, 199, 193, 193, 193, 193, 206, 193, + 1, 193, 234, 235, 240, 240, 5, 198, + 199, 200, 193, 193, 193, 238, 193, 234, + 235, 236, 240, 5, 198, 199, 200, 193, + 193, 29, 238, 193, 232, 193, 260, 193, + 247, 247, 5, 198, 199, 193, 193, 193, + 193, 206, 193, 232, 193, 232, 193, 193, + 193, 193, 193, 193, 198, 199, 193, 193, + 193, 193, 206, 193, 232, 193, 232, 193, + 193, 193, 193, 261, 193, 198, 199, 193, + 193, 193, 193, 206, 193, 232, 193, 232, + 193, 260, 193, 193, 193, 193, 198, 199, + 193, 193, 193, 193, 206, 193, 232, 193, + 232, 2, 193, 193, 18, 233, 193, 198, + 199, 193, 193, 193, 193, 206, 193, 232, + 193, 225, 226, 231, 231, 5, 198, 199, + 200, 193, 193, 193, 229, 193, 225, 226, + 227, 231, 5, 198, 199, 200, 193, 193, + 31, 229, 193, 223, 193, 262, 193, 247, + 247, 5, 198, 199, 193, 193, 193, 193, + 206, 193, 223, 193, 223, 193, 193, 193, + 193, 193, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 223, 193, 223, 193, 193, + 193, 193, 263, 193, 198, 199, 193, 193, + 193, 193, 206, 193, 223, 193, 223, 193, + 262, 193, 193, 193, 193, 198, 199, 193, + 193, 193, 193, 206, 193, 223, 193, 223, + 2, 193, 193, 18, 224, 193, 198, 199, + 193, 193, 193, 193, 206, 193, 223, 193, + 216, 217, 222, 222, 5, 198, 199, 200, + 193, 193, 193, 220, 193, 216, 217, 218, + 222, 5, 198, 199, 200, 193, 193, 33, + 220, 193, 214, 193, 264, 193, 247, 247, + 5, 198, 199, 193, 193, 193, 193, 206, + 193, 214, 193, 214, 193, 193, 193, 193, + 193, 193, 198, 199, 193, 193, 193, 193, + 206, 193, 214, 193, 214, 193, 193, 193, + 193, 265, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 214, 193, 214, 193, 264, + 193, 193, 193, 193, 198, 199, 193, 193, + 193, 193, 206, 193, 214, 193, 214, 2, + 193, 193, 18, 215, 193, 198, 199, 193, + 193, 193, 193, 206, 193, 214, 193, 207, + 208, 213, 213, 5, 198, 199, 200, 193, + 193, 193, 211, 193, 207, 208, 209, 213, + 5, 198, 199, 200, 193, 193, 35, 211, + 193, 204, 193, 266, 193, 247, 247, 5, + 198, 199, 193, 193, 193, 193, 206, 193, + 204, 193, 204, 193, 193, 193, 193, 193, + 193, 198, 199, 193, 193, 193, 193, 206, + 193, 204, 193, 204, 193, 193, 193, 193, + 267, 193, 198, 199, 193, 193, 193, 193, + 206, 193, 204, 193, 204, 193, 266, 193, + 193, 193, 193, 198, 199, 193, 193, 193, + 193, 206, 193, 204, 193, 204, 2, 193, + 193, 18, 205, 193, 198, 199, 193, 193, + 193, 193, 206, 193, 204, 193, 194, 195, + 203, 203, 5, 198, 199, 200, 193, 193, + 193, 201, 193, 194, 195, 196, 203, 5, + 198, 199, 200, 193, 193, 37, 201, 193, + 269, 270, 271, 272, 43, 273, 274, 268, + 268, 268, 75, 275, 268, 276, 270, 277, + 272, 43, 273, 274, 268, 268, 268, 268, + 275, 268, 270, 277, 272, 43, 273, 274, + 268, 268, 268, 268, 275, 268, 278, 268, + 268, 268, 56, 279, 268, 273, 274, 268, + 268, 268, 268, 280, 268, 278, 268, 281, + 282, 283, 284, 43, 273, 274, 268, 268, + 268, 73, 285, 268, 268, 278, 268, 286, + 282, 287, 287, 43, 273, 274, 268, 268, + 268, 268, 285, 268, 282, 287, 287, 43, + 273, 274, 268, 268, 268, 268, 285, 268, + 288, 268, 268, 268, 56, 289, 268, 273, + 274, 268, 268, 268, 268, 280, 268, 288, + 268, 290, 291, 292, 293, 43, 273, 274, + 268, 268, 268, 71, 294, 268, 268, 288, + 268, 295, 291, 296, 296, 43, 273, 274, + 268, 268, 268, 268, 294, 268, 291, 296, + 296, 43, 273, 274, 268, 268, 268, 268, + 294, 268, 297, 268, 268, 268, 56, 298, + 268, 273, 274, 268, 268, 268, 268, 280, + 268, 297, 268, 299, 300, 301, 302, 43, + 273, 274, 268, 268, 268, 69, 303, 268, + 268, 297, 268, 304, 300, 305, 305, 43, + 273, 274, 268, 268, 268, 268, 303, 268, + 300, 305, 305, 43, 273, 274, 268, 268, + 268, 268, 303, 268, 306, 268, 268, 268, + 56, 307, 268, 273, 274, 268, 268, 268, + 268, 280, 268, 306, 268, 308, 309, 310, + 311, 43, 273, 274, 268, 268, 268, 67, + 312, 268, 268, 306, 268, 313, 309, 314, + 314, 43, 273, 274, 268, 268, 268, 268, + 312, 268, 309, 314, 314, 43, 273, 274, + 268, 268, 268, 268, 312, 268, 56, 315, + 268, 273, 274, 268, 268, 268, 268, 280, + 268, 273, 274, 268, 268, 268, 268, 280, + 268, 316, 268, 268, 268, 274, 268, 274, + 268, 317, 268, 318, 268, 319, 320, 268, + 273, 274, 268, 268, 268, 41, 268, 268, + 268, 39, 268, 40, 268, 268, 268, 268, + 273, 274, 268, 273, 274, 268, 318, 268, + 268, 268, 268, 273, 274, 268, 318, 268, + 319, 268, 268, 273, 274, 268, 268, 268, + 41, 268, 56, 268, 321, 321, 43, 273, + 274, 268, 268, 268, 268, 280, 268, 322, + 65, 323, 324, 46, 273, 274, 268, 268, + 268, 268, 280, 268, 65, 323, 324, 46, + 273, 274, 268, 268, 268, 268, 280, 268, + 323, 323, 46, 273, 274, 268, 268, 268, + 268, 280, 268, 325, 62, 326, 327, 49, + 273, 274, 268, 268, 268, 268, 280, 268, + 62, 326, 327, 49, 273, 274, 268, 268, + 268, 268, 280, 268, 326, 326, 49, 273, + 274, 268, 268, 268, 268, 280, 268, 328, + 59, 329, 330, 52, 273, 274, 268, 268, + 268, 268, 280, 268, 59, 329, 330, 52, + 273, 274, 268, 268, 268, 268, 280, 268, + 329, 329, 52, 273, 274, 268, 268, 268, + 268, 280, 268, 331, 56, 268, 332, 268, + 273, 274, 268, 268, 268, 268, 280, 268, + 56, 268, 332, 268, 273, 274, 268, 268, + 268, 268, 280, 268, 333, 268, 273, 274, + 268, 268, 268, 268, 280, 268, 56, 268, + 268, 268, 268, 273, 274, 268, 268, 268, + 268, 280, 268, 39, 40, 268, 268, 56, + 315, 268, 273, 274, 268, 268, 268, 268, + 280, 268, 39, 268, 308, 309, 314, 314, + 43, 273, 274, 268, 268, 268, 268, 312, + 268, 308, 309, 310, 314, 43, 273, 274, + 268, 268, 268, 67, 312, 268, 306, 268, + 334, 268, 321, 321, 43, 273, 274, 268, + 268, 268, 268, 280, 268, 306, 268, 306, + 268, 268, 268, 268, 268, 268, 273, 274, + 268, 268, 268, 268, 280, 268, 306, 268, + 306, 268, 268, 268, 268, 335, 268, 273, + 274, 268, 268, 268, 268, 280, 268, 306, + 268, 306, 268, 334, 268, 268, 268, 268, + 273, 274, 268, 268, 268, 268, 280, 268, + 306, 268, 306, 40, 268, 268, 56, 307, + 268, 273, 274, 268, 268, 268, 268, 280, + 268, 306, 268, 299, 300, 305, 305, 43, + 273, 274, 268, 268, 268, 268, 303, 268, + 299, 300, 301, 305, 43, 273, 274, 268, + 268, 268, 69, 303, 268, 297, 268, 336, + 268, 321, 321, 43, 273, 274, 268, 268, + 268, 268, 280, 268, 297, 268, 297, 268, + 268, 268, 268, 268, 268, 273, 274, 268, + 268, 268, 268, 280, 268, 297, 268, 297, + 268, 268, 268, 268, 337, 268, 273, 274, + 268, 268, 268, 268, 280, 268, 297, 268, + 297, 268, 336, 268, 268, 268, 268, 273, + 274, 268, 268, 268, 268, 280, 268, 297, + 268, 297, 40, 268, 268, 56, 298, 268, + 273, 274, 268, 268, 268, 268, 280, 268, + 297, 268, 290, 291, 296, 296, 43, 273, + 274, 268, 268, 268, 268, 294, 268, 290, + 291, 292, 296, 43, 273, 274, 268, 268, + 268, 71, 294, 268, 288, 268, 338, 268, + 321, 321, 43, 273, 274, 268, 268, 268, + 268, 280, 268, 288, 268, 288, 268, 268, + 268, 268, 268, 268, 273, 274, 268, 268, + 268, 268, 280, 268, 288, 268, 288, 268, + 268, 268, 268, 339, 268, 273, 274, 268, + 268, 268, 268, 280, 268, 288, 268, 288, + 268, 338, 268, 268, 268, 268, 273, 274, + 268, 268, 268, 268, 280, 268, 288, 268, + 288, 40, 268, 268, 56, 289, 268, 273, + 274, 268, 268, 268, 268, 280, 268, 288, + 268, 281, 282, 287, 287, 43, 273, 274, + 268, 268, 268, 268, 285, 268, 281, 282, + 283, 287, 43, 273, 274, 268, 268, 268, + 73, 285, 268, 278, 268, 340, 268, 321, + 321, 43, 273, 274, 268, 268, 268, 268, + 280, 268, 278, 268, 278, 268, 268, 268, + 268, 268, 268, 273, 274, 268, 268, 268, + 268, 280, 268, 278, 268, 278, 268, 268, + 268, 268, 341, 268, 273, 274, 268, 268, + 268, 268, 280, 268, 278, 268, 278, 268, + 340, 268, 268, 268, 268, 273, 274, 268, + 268, 268, 268, 280, 268, 278, 268, 74, + 42, 42, 43, 268, 268, 268, 268, 268, + 268, 74, 268, 278, 40, 268, 268, 56, + 279, 268, 273, 274, 268, 268, 268, 268, + 280, 268, 278, 268, 269, 270, 277, 272, + 43, 273, 274, 268, 268, 268, 268, 275, + 268, 343, 184, 344, 344, 81, 187, 188, + 342, 342, 342, 342, 190, 342, 184, 344, + 344, 81, 187, 188, 342, 342, 342, 342, + 190, 342, 345, 342, 342, 342, 95, 346, + 342, 187, 188, 342, 342, 342, 342, 347, + 342, 345, 342, 348, 349, 350, 351, 81, + 187, 188, 342, 342, 342, 112, 352, 342, + 342, 345, 342, 353, 349, 354, 354, 81, + 187, 188, 342, 342, 342, 342, 352, 342, + 349, 354, 354, 81, 187, 188, 342, 342, + 342, 342, 352, 342, 355, 342, 342, 342, + 95, 356, 342, 187, 188, 342, 342, 342, + 342, 347, 342, 355, 342, 357, 358, 359, + 360, 81, 187, 188, 342, 342, 342, 110, + 361, 342, 342, 355, 342, 362, 358, 363, + 363, 81, 187, 188, 342, 342, 342, 342, + 361, 342, 358, 363, 363, 81, 187, 188, + 342, 342, 342, 342, 361, 342, 364, 342, + 342, 342, 95, 365, 342, 187, 188, 342, + 342, 342, 342, 347, 342, 364, 342, 366, + 367, 368, 369, 81, 187, 188, 342, 342, + 342, 108, 370, 342, 342, 364, 342, 371, + 367, 372, 372, 81, 187, 188, 342, 342, + 342, 342, 370, 342, 367, 372, 372, 81, + 187, 188, 342, 342, 342, 342, 370, 342, + 373, 342, 342, 342, 95, 374, 342, 187, + 188, 342, 342, 342, 342, 347, 342, 373, + 342, 375, 376, 377, 378, 81, 187, 188, + 342, 342, 342, 106, 379, 342, 342, 373, + 342, 380, 376, 381, 381, 81, 187, 188, + 342, 342, 342, 342, 379, 342, 376, 381, + 381, 81, 187, 188, 342, 342, 342, 342, + 379, 342, 95, 382, 342, 187, 188, 342, + 342, 342, 342, 347, 342, 187, 188, 342, + 342, 342, 342, 347, 342, 383, 342, 342, + 342, 188, 342, 188, 342, 384, 342, 385, + 342, 386, 387, 342, 187, 188, 342, 342, + 342, 79, 342, 342, 342, 77, 342, 78, + 342, 342, 342, 342, 187, 188, 342, 187, + 188, 342, 385, 342, 342, 342, 342, 187, + 188, 342, 385, 342, 386, 342, 342, 187, + 188, 342, 342, 342, 79, 342, 95, 342, + 388, 388, 81, 187, 188, 342, 342, 342, + 342, 347, 342, 389, 104, 390, 391, 85, + 187, 188, 342, 342, 342, 342, 347, 342, + 104, 390, 391, 85, 187, 188, 342, 342, + 342, 342, 347, 342, 390, 390, 85, 187, + 188, 342, 342, 342, 342, 347, 342, 392, + 101, 393, 394, 88, 187, 188, 342, 342, + 342, 342, 347, 342, 101, 393, 394, 88, + 187, 188, 342, 342, 342, 342, 347, 342, + 393, 393, 88, 187, 188, 342, 342, 342, + 342, 347, 342, 395, 98, 396, 397, 91, + 187, 188, 342, 342, 342, 342, 347, 342, + 98, 396, 397, 91, 187, 188, 342, 342, + 342, 342, 347, 342, 396, 396, 91, 187, + 188, 342, 342, 342, 342, 347, 342, 398, + 95, 342, 399, 342, 187, 188, 342, 342, + 342, 342, 347, 342, 95, 342, 399, 342, + 187, 188, 342, 342, 342, 342, 347, 342, + 400, 342, 187, 188, 342, 342, 342, 342, + 347, 342, 95, 342, 342, 342, 342, 187, + 188, 342, 342, 342, 342, 347, 342, 77, + 78, 342, 342, 95, 382, 342, 187, 188, + 342, 342, 342, 342, 347, 342, 77, 342, + 375, 376, 381, 381, 81, 187, 188, 342, + 342, 342, 342, 379, 342, 375, 376, 377, + 381, 81, 187, 188, 342, 342, 342, 106, + 379, 342, 373, 342, 401, 342, 388, 388, + 81, 187, 188, 342, 342, 342, 342, 347, + 342, 373, 342, 373, 342, 342, 342, 342, + 342, 342, 187, 188, 342, 342, 342, 342, + 347, 342, 373, 342, 373, 342, 342, 342, + 342, 402, 342, 187, 188, 342, 342, 342, + 342, 347, 342, 373, 342, 373, 342, 401, + 342, 342, 342, 342, 187, 188, 342, 342, + 342, 342, 347, 342, 373, 342, 373, 78, + 342, 342, 95, 374, 342, 187, 188, 342, + 342, 342, 342, 347, 342, 373, 342, 366, + 367, 372, 372, 81, 187, 188, 342, 342, + 342, 342, 370, 342, 366, 367, 368, 372, + 81, 187, 188, 342, 342, 342, 108, 370, + 342, 364, 342, 403, 342, 388, 388, 81, + 187, 188, 342, 342, 342, 342, 347, 342, + 364, 342, 364, 342, 342, 342, 342, 342, + 342, 187, 188, 342, 342, 342, 342, 347, + 342, 364, 342, 364, 342, 342, 342, 342, + 404, 342, 187, 188, 342, 342, 342, 342, + 347, 342, 364, 342, 364, 342, 403, 342, + 342, 342, 342, 187, 188, 342, 342, 342, + 342, 347, 342, 364, 342, 364, 78, 342, + 342, 95, 365, 342, 187, 188, 342, 342, + 342, 342, 347, 342, 364, 342, 357, 358, + 363, 363, 81, 187, 188, 342, 342, 342, + 342, 361, 342, 357, 358, 359, 363, 81, + 187, 188, 342, 342, 342, 110, 361, 342, + 355, 342, 405, 342, 388, 388, 81, 187, + 188, 342, 342, 342, 342, 347, 342, 355, + 342, 355, 342, 342, 342, 342, 342, 342, + 187, 188, 342, 342, 342, 342, 347, 342, + 355, 342, 355, 342, 342, 342, 342, 406, + 342, 187, 188, 342, 342, 342, 342, 347, + 342, 355, 342, 355, 342, 405, 342, 342, + 342, 342, 187, 188, 342, 342, 342, 342, + 347, 342, 355, 342, 355, 78, 342, 342, + 95, 356, 342, 187, 188, 342, 342, 342, + 342, 347, 342, 355, 342, 348, 349, 354, + 354, 81, 187, 188, 342, 342, 342, 342, + 352, 342, 348, 349, 350, 354, 81, 187, + 188, 342, 342, 342, 112, 352, 342, 345, + 342, 407, 342, 388, 388, 81, 187, 188, + 342, 342, 342, 342, 347, 342, 345, 342, + 345, 342, 342, 342, 342, 342, 342, 187, + 188, 342, 342, 342, 342, 347, 342, 345, + 342, 345, 342, 342, 342, 342, 408, 342, + 187, 188, 342, 342, 342, 342, 347, 342, + 345, 342, 345, 342, 407, 342, 342, 342, + 342, 187, 188, 342, 342, 342, 342, 347, + 342, 345, 342, 345, 78, 342, 342, 95, + 346, 342, 187, 188, 342, 342, 342, 342, + 347, 342, 345, 342, 113, 80, 80, 81, + 409, 409, 409, 409, 409, 152, 113, 409, + 183, 184, 344, 344, 81, 187, 188, 342, + 342, 342, 342, 190, 342, 113, 80, 80, + 81, 409, 409, 409, 409, 409, 409, 113, + 409, 411, 412, 413, 414, 119, 415, 416, + 410, 410, 410, 151, 417, 410, 418, 412, + 414, 414, 119, 415, 416, 410, 410, 410, + 410, 417, 410, 412, 414, 414, 119, 415, + 416, 410, 410, 410, 410, 417, 410, 419, + 410, 410, 410, 132, 420, 410, 415, 416, + 410, 410, 410, 410, 421, 410, 419, 410, + 422, 423, 424, 425, 119, 415, 416, 410, + 410, 410, 149, 426, 410, 410, 419, 410, + 427, 423, 428, 428, 119, 415, 416, 410, + 410, 410, 410, 426, 410, 423, 428, 428, + 119, 415, 416, 410, 410, 410, 410, 426, + 410, 429, 410, 410, 410, 132, 430, 410, + 415, 416, 410, 410, 410, 410, 421, 410, + 429, 410, 431, 432, 433, 434, 119, 415, + 416, 410, 410, 410, 147, 435, 410, 410, + 429, 410, 436, 432, 437, 437, 119, 415, + 416, 410, 410, 410, 410, 435, 410, 432, + 437, 437, 119, 415, 416, 410, 410, 410, + 410, 435, 410, 438, 410, 410, 410, 132, + 439, 410, 415, 416, 410, 410, 410, 410, + 421, 410, 438, 410, 440, 441, 442, 443, + 119, 415, 416, 410, 410, 410, 145, 444, + 410, 410, 438, 410, 445, 441, 446, 446, + 119, 415, 416, 410, 410, 410, 410, 444, + 410, 441, 446, 446, 119, 415, 416, 410, + 410, 410, 410, 444, 410, 447, 410, 410, + 410, 132, 448, 410, 415, 416, 410, 410, + 410, 410, 421, 410, 447, 410, 449, 450, + 451, 452, 119, 415, 416, 410, 410, 410, + 143, 453, 410, 410, 447, 410, 454, 450, + 455, 455, 119, 415, 416, 410, 410, 410, + 410, 453, 410, 450, 455, 455, 119, 415, + 416, 410, 410, 410, 410, 453, 410, 132, + 456, 410, 415, 416, 410, 410, 410, 410, + 421, 410, 415, 416, 410, 410, 410, 410, + 421, 410, 457, 410, 410, 410, 416, 410, + 416, 410, 458, 410, 459, 410, 460, 461, + 410, 415, 416, 410, 410, 410, 117, 410, + 410, 410, 115, 410, 116, 410, 410, 410, + 410, 415, 416, 410, 415, 416, 410, 459, + 410, 410, 410, 410, 415, 416, 410, 459, + 410, 460, 410, 410, 415, 416, 410, 410, + 410, 117, 410, 132, 410, 462, 462, 119, + 415, 416, 410, 410, 410, 410, 421, 410, + 463, 141, 464, 465, 122, 415, 416, 410, + 410, 410, 410, 421, 410, 141, 464, 465, + 122, 415, 416, 410, 410, 410, 410, 421, + 410, 464, 464, 122, 415, 416, 410, 410, + 410, 410, 421, 410, 466, 138, 467, 468, + 125, 415, 416, 410, 410, 410, 410, 421, + 410, 138, 467, 468, 125, 415, 416, 410, + 410, 410, 410, 421, 410, 467, 467, 125, + 415, 416, 410, 410, 410, 410, 421, 410, + 469, 135, 470, 471, 128, 415, 416, 410, + 410, 410, 410, 421, 410, 135, 470, 471, + 128, 415, 416, 410, 410, 410, 410, 421, + 410, 470, 470, 128, 415, 416, 410, 410, + 410, 410, 421, 410, 472, 132, 410, 473, + 410, 415, 416, 410, 410, 410, 410, 421, + 410, 132, 410, 473, 410, 415, 416, 410, + 410, 410, 410, 421, 410, 474, 410, 415, + 416, 410, 410, 410, 410, 421, 410, 132, + 410, 410, 410, 410, 415, 416, 410, 410, + 410, 410, 421, 410, 115, 116, 410, 410, + 132, 456, 410, 415, 416, 410, 410, 410, + 410, 421, 410, 115, 410, 449, 450, 455, + 455, 119, 415, 416, 410, 410, 410, 410, + 453, 410, 449, 450, 451, 455, 119, 415, + 416, 410, 410, 410, 143, 453, 410, 447, + 410, 475, 410, 462, 462, 119, 415, 416, + 410, 410, 410, 410, 421, 410, 447, 410, + 447, 410, 410, 410, 410, 410, 410, 415, + 416, 410, 410, 410, 410, 421, 410, 447, + 410, 447, 410, 410, 410, 410, 476, 410, + 415, 416, 410, 410, 410, 410, 421, 410, + 447, 410, 447, 410, 475, 410, 410, 410, + 410, 415, 416, 410, 410, 410, 410, 421, + 410, 447, 410, 447, 116, 410, 410, 132, + 448, 410, 415, 416, 410, 410, 410, 410, + 421, 410, 447, 410, 440, 441, 446, 446, + 119, 415, 416, 410, 410, 410, 410, 444, + 410, 440, 441, 442, 446, 119, 415, 416, + 410, 410, 410, 145, 444, 410, 438, 410, + 477, 410, 462, 462, 119, 415, 416, 410, + 410, 410, 410, 421, 410, 438, 410, 438, + 410, 410, 410, 410, 410, 410, 415, 416, + 410, 410, 410, 410, 421, 410, 438, 410, + 438, 410, 410, 410, 410, 478, 410, 415, + 416, 410, 410, 410, 410, 421, 410, 438, + 410, 438, 410, 477, 410, 410, 410, 410, + 415, 416, 410, 410, 410, 410, 421, 410, + 438, 410, 438, 116, 410, 410, 132, 439, + 410, 415, 416, 410, 410, 410, 410, 421, + 410, 438, 410, 431, 432, 437, 437, 119, + 415, 416, 410, 410, 410, 410, 435, 410, + 431, 432, 433, 437, 119, 415, 416, 410, + 410, 410, 147, 435, 410, 429, 410, 479, + 410, 462, 462, 119, 415, 416, 410, 410, + 410, 410, 421, 410, 429, 410, 429, 410, + 410, 410, 410, 410, 410, 415, 416, 410, + 410, 410, 410, 421, 410, 429, 410, 429, + 410, 410, 410, 410, 480, 410, 415, 416, + 410, 410, 410, 410, 421, 410, 429, 410, + 429, 410, 479, 410, 410, 410, 410, 415, + 416, 410, 410, 410, 410, 421, 410, 429, + 410, 429, 116, 410, 410, 132, 430, 410, + 415, 416, 410, 410, 410, 410, 421, 410, + 429, 410, 422, 423, 428, 428, 119, 415, + 416, 410, 410, 410, 410, 426, 410, 422, + 423, 424, 428, 119, 415, 416, 410, 410, + 410, 149, 426, 410, 419, 410, 481, 410, + 462, 462, 119, 415, 416, 410, 410, 410, + 410, 421, 410, 419, 410, 419, 410, 410, + 410, 410, 410, 410, 415, 416, 410, 410, + 410, 410, 421, 410, 419, 410, 419, 410, + 410, 410, 410, 482, 410, 415, 416, 410, + 410, 410, 410, 421, 410, 419, 410, 419, + 410, 481, 410, 410, 410, 410, 415, 416, + 410, 410, 410, 410, 421, 410, 419, 410, + 419, 116, 410, 410, 132, 420, 410, 415, + 416, 410, 410, 410, 410, 421, 410, 419, + 410, 411, 412, 414, 414, 119, 415, 416, + 410, 410, 410, 410, 417, 410, 181, 182, + 183, 184, 483, 344, 81, 187, 188, 342, + 189, 189, 152, 190, 342, 181, 342, 194, + 484, 196, 197, 5, 198, 199, 200, 193, + 193, 37, 201, 193, 193, 181, 193, 204, + 182, 183, 184, 485, 486, 81, 487, 488, + 193, 189, 189, 152, 489, 193, 204, 193, + 113, 80, 80, 81, 198, 199, 193, 193, + 193, 152, 490, 193, 491, 2, 342, 342, + 342, 408, 342, 187, 188, 342, 342, 342, + 342, 347, 342, 491, 342, 492, 349, 493, + 494, 81, 487, 488, 193, 193, 193, 153, + 352, 193, 193, 491, 193, 495, 349, 354, + 354, 81, 487, 488, 193, 193, 193, 193, + 352, 193, 349, 354, 354, 81, 487, 488, + 193, 193, 193, 193, 352, 193, 496, 193, + 193, 193, 488, 193, 488, 193, 243, 193, + 492, 349, 354, 354, 81, 487, 488, 193, + 193, 193, 193, 352, 193, 492, 349, 493, + 354, 81, 487, 488, 193, 193, 193, 153, + 352, 193, 204, 193, 266, 113, 497, 497, + 155, 198, 199, 193, 193, 193, 193, 490, + 193, 204, 193, 498, 179, 499, 500, 157, + 487, 488, 193, 193, 193, 193, 501, 193, + 179, 499, 500, 157, 487, 488, 193, 193, + 193, 193, 501, 193, 499, 499, 157, 487, + 488, 193, 193, 193, 193, 501, 193, 502, + 176, 503, 504, 160, 487, 488, 193, 193, + 193, 193, 501, 193, 176, 503, 504, 160, + 487, 488, 193, 193, 193, 193, 501, 193, + 503, 503, 160, 487, 488, 193, 193, 193, + 193, 501, 193, 505, 173, 506, 507, 163, + 487, 488, 193, 193, 193, 193, 501, 193, + 173, 506, 507, 163, 487, 488, 193, 193, + 193, 193, 501, 193, 506, 506, 163, 487, + 488, 193, 193, 193, 193, 501, 193, 508, + 170, 193, 509, 193, 487, 488, 193, 193, + 193, 193, 501, 193, 170, 193, 509, 193, + 487, 488, 193, 193, 193, 193, 501, 193, + 487, 488, 193, 193, 193, 193, 501, 193, + 510, 193, 511, 512, 193, 487, 488, 193, + 193, 193, 167, 193, 193, 193, 165, 193, + 166, 193, 193, 193, 193, 487, 488, 193, + 487, 488, 193, 510, 193, 193, 193, 193, + 487, 488, 193, 510, 193, 511, 193, 193, + 487, 488, 193, 193, 193, 167, 193, 491, + 166, 342, 342, 95, 346, 342, 187, 188, + 342, 342, 342, 342, 347, 342, 491, 342, + 0 +}; + +static const short _indic_syllable_machine_trans_targs[] = { + 170, 195, 197, 198, 3, 201, 4, 6, + 204, 7, 9, 207, 10, 12, 210, 13, + 15, 16, 191, 18, 19, 209, 21, 22, + 206, 24, 25, 203, 212, 216, 220, 223, + 227, 230, 234, 237, 241, 244, 170, 270, + 272, 273, 39, 276, 40, 42, 279, 43, + 45, 282, 46, 48, 285, 49, 51, 52, + 266, 54, 55, 284, 57, 58, 281, 60, + 61, 278, 287, 290, 294, 297, 301, 304, + 308, 311, 315, 319, 170, 343, 345, 346, + 75, 349, 170, 76, 78, 352, 79, 81, + 355, 82, 84, 358, 85, 87, 88, 339, + 90, 91, 357, 93, 94, 354, 96, 97, + 351, 360, 363, 367, 370, 374, 377, 381, + 384, 388, 170, 418, 420, 421, 110, 424, + 111, 113, 427, 114, 116, 430, 117, 119, + 433, 120, 122, 123, 414, 125, 126, 432, + 128, 129, 429, 131, 132, 426, 435, 438, + 442, 445, 449, 452, 456, 459, 463, 466, + 392, 478, 146, 481, 148, 484, 149, 151, + 487, 152, 154, 490, 155, 493, 495, 496, + 159, 160, 492, 162, 163, 489, 165, 166, + 486, 168, 169, 483, 170, 171, 246, 320, + 322, 391, 393, 340, 342, 394, 390, 467, + 468, 170, 172, 174, 35, 245, 192, 194, + 214, 243, 173, 34, 175, 239, 0, 176, + 178, 33, 238, 236, 177, 32, 179, 232, + 180, 182, 31, 231, 229, 181, 30, 183, + 225, 184, 186, 29, 224, 222, 185, 28, + 187, 218, 188, 190, 27, 217, 215, 189, + 26, 200, 193, 170, 196, 1, 199, 2, + 202, 5, 23, 205, 8, 20, 208, 11, + 17, 211, 14, 213, 219, 221, 226, 228, + 233, 235, 240, 242, 170, 247, 249, 71, + 317, 267, 269, 318, 248, 70, 250, 313, + 36, 251, 253, 69, 312, 310, 252, 68, + 254, 306, 255, 257, 67, 305, 303, 256, + 66, 258, 299, 259, 261, 65, 298, 296, + 260, 64, 262, 292, 263, 265, 63, 291, + 289, 264, 62, 275, 268, 170, 271, 37, + 274, 38, 277, 41, 59, 280, 44, 56, + 283, 47, 53, 286, 50, 288, 293, 295, + 300, 302, 307, 309, 314, 316, 170, 321, + 106, 323, 386, 72, 324, 326, 105, 385, + 383, 325, 104, 327, 379, 328, 330, 103, + 378, 376, 329, 102, 331, 372, 332, 334, + 101, 371, 369, 333, 100, 335, 365, 336, + 338, 99, 364, 362, 337, 98, 348, 341, + 170, 344, 73, 347, 74, 350, 77, 95, + 353, 80, 92, 356, 83, 89, 359, 86, + 361, 366, 368, 373, 375, 380, 382, 387, + 389, 170, 170, 395, 397, 142, 141, 415, + 417, 465, 396, 398, 461, 107, 399, 401, + 140, 460, 458, 400, 139, 402, 454, 403, + 405, 138, 453, 451, 404, 137, 406, 447, + 407, 409, 136, 446, 444, 408, 135, 410, + 440, 411, 413, 134, 439, 437, 412, 133, + 423, 416, 170, 419, 108, 422, 109, 425, + 112, 130, 428, 115, 127, 431, 118, 124, + 434, 121, 436, 441, 443, 448, 450, 455, + 457, 462, 464, 143, 469, 470, 480, 475, + 477, 498, 471, 472, 473, 144, 479, 474, + 476, 145, 482, 147, 167, 156, 485, 150, + 164, 488, 153, 161, 491, 158, 494, 157, + 497 +}; + +static const char _indic_syllable_machine_trans_actions[] = { + 1, 2, 0, 0, 0, 2, 0, 0, + 2, 0, 0, 2, 0, 0, 2, 0, + 0, 0, 2, 0, 0, 2, 0, 0, + 2, 0, 0, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 2, + 0, 0, 0, 2, 0, 0, 2, 0, + 0, 2, 0, 0, 2, 0, 0, 0, + 2, 0, 0, 2, 0, 0, 2, 0, + 0, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 4, 2, 0, 0, + 0, 2, 5, 0, 0, 2, 0, 0, + 2, 0, 0, 2, 0, 0, 0, 2, + 0, 0, 2, 0, 0, 2, 0, 0, + 2, 2, 6, 2, 6, 2, 6, 2, + 6, 2, 7, 2, 0, 0, 0, 2, + 0, 0, 2, 0, 0, 2, 0, 0, + 2, 0, 0, 0, 2, 0, 0, 2, + 0, 0, 2, 0, 0, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, + 6, 8, 0, 2, 0, 2, 0, 0, + 2, 0, 0, 2, 0, 2, 0, 0, + 0, 0, 2, 0, 0, 2, 0, 0, + 2, 0, 0, 2, 11, 2, 2, 6, + 2, 12, 12, 0, 0, 2, 2, 6, + 2, 13, 2, 2, 0, 2, 0, 0, + 2, 2, 2, 0, 2, 2, 0, 2, + 2, 0, 2, 2, 2, 0, 2, 2, + 2, 2, 0, 2, 2, 2, 0, 2, + 2, 2, 2, 0, 2, 2, 2, 0, + 2, 2, 2, 2, 0, 2, 2, 2, + 0, 2, 0, 14, 0, 0, 2, 0, + 2, 0, 0, 2, 0, 0, 2, 0, + 0, 2, 0, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 15, 2, 2, 0, + 2, 0, 0, 2, 2, 0, 2, 2, + 0, 2, 2, 0, 2, 2, 2, 0, + 2, 2, 2, 2, 0, 2, 2, 2, + 0, 2, 2, 2, 2, 0, 2, 2, + 2, 0, 2, 2, 2, 2, 0, 2, + 2, 2, 0, 2, 0, 16, 0, 0, + 2, 0, 2, 0, 0, 2, 0, 0, + 2, 0, 0, 2, 0, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 17, 6, + 0, 6, 6, 0, 6, 2, 0, 6, + 2, 6, 0, 6, 6, 6, 2, 0, + 6, 2, 6, 0, 6, 6, 6, 2, + 0, 6, 2, 6, 0, 6, 6, 6, + 2, 0, 6, 2, 6, 0, 6, 0, + 18, 0, 0, 2, 0, 2, 0, 0, + 2, 0, 0, 2, 0, 0, 2, 0, + 2, 2, 2, 2, 2, 2, 2, 2, + 2, 19, 20, 2, 2, 0, 0, 0, + 0, 2, 2, 2, 2, 0, 2, 2, + 0, 2, 2, 2, 0, 2, 2, 2, + 2, 0, 2, 2, 2, 0, 2, 2, + 2, 2, 0, 2, 2, 2, 0, 2, + 2, 2, 2, 0, 2, 2, 2, 0, + 2, 0, 21, 0, 0, 2, 0, 2, + 0, 0, 2, 0, 0, 2, 0, 0, + 2, 0, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 0, 0, 8, 2, 0, + 0, 2, 2, 8, 8, 0, 8, 8, + 0, 0, 2, 0, 0, 0, 2, 0, + 0, 2, 0, 0, 2, 0, 0, 0, + 2 +}; + +static const char _indic_syllable_machine_to_state_actions[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 9, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 +}; + +static const char _indic_syllable_machine_from_state_actions[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 10, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0 +}; + +static const short _indic_syllable_machine_eof_trans[] = { + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, + 77, 77, 77, 83, 83, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, + 77, 77, 77, 77, 77, 77, 77, 77, + 83, 77, 77, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 115, + 115, 115, 115, 115, 115, 115, 115, 77, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 269, 269, 269, 269, 269, 269, 269, 269, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 343, + 343, 343, 343, 343, 343, 343, 343, 410, + 343, 410, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 411, 411, 411, 411, 411, + 411, 411, 411, 343, 194, 194, 194, 343, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 194, 194, 194, 194, 194, 194, + 194, 194, 343 +}; + +static const int indic_syllable_machine_start = 170; +static const int indic_syllable_machine_first_final = 170; +static const int indic_syllable_machine_error = -1; + +static const int indic_syllable_machine_en_main = 170; + + +#line 36 "../../src/hb-ot-shape-complex-indic-machine.rl" + + + +#line 91 "../../src/hb-ot-shape-complex-indic-machine.rl" + + +#define found_syllable(syllable_type) \ + HB_STMT_START { \ + if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \ + for (unsigned int i = last; i < p+1; i++) \ + info[i].syllable() = (syllable_serial << 4) | syllable_type; \ + last = p+1; \ + syllable_serial++; \ + if (unlikely (syllable_serial == 16)) syllable_serial = 1; \ + } HB_STMT_END + +static void +find_syllables (hb_buffer_t *buffer) +{ + unsigned int p, pe, eof, ts HB_UNUSED, te, act; + int cs; + hb_glyph_info_t *info = buffer->info; + +#line 1273 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" + { + cs = indic_syllable_machine_start; + ts = 0; + te = 0; + act = 0; + } + +#line 112 "../../src/hb-ot-shape-complex-indic-machine.rl" + + + p = 0; + pe = eof = buffer->len; + + unsigned int last = 0; + unsigned int syllable_serial = 1; + +#line 1290 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" + { + int _slen; + int _trans; + const unsigned char *_keys; + const short *_inds; + if ( p == pe ) + goto _test_eof; +_resume: + switch ( _indic_syllable_machine_from_state_actions[cs] ) { + case 10: +#line 1 "NONE" + {ts = p;} + break; +#line 1304 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" + } + + _keys = _indic_syllable_machine_trans_keys + (cs<<1); + _inds = _indic_syllable_machine_indicies + _indic_syllable_machine_index_offsets[cs]; + + _slen = _indic_syllable_machine_key_spans[cs]; + _trans = _inds[ _slen > 0 && _keys[0] <=( info[p].indic_category()) && + ( info[p].indic_category()) <= _keys[1] ? + ( info[p].indic_category()) - _keys[0] : _slen ]; + +_eof_trans: + cs = _indic_syllable_machine_trans_targs[_trans]; + + if ( _indic_syllable_machine_trans_actions[_trans] == 0 ) + goto _again; + + switch ( _indic_syllable_machine_trans_actions[_trans] ) { + case 2: +#line 1 "NONE" + {te = p+1;} + break; + case 14: +#line 83 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p+1;{ found_syllable (consonant_syllable); }} + break; + case 16: +#line 84 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p+1;{ found_syllable (vowel_syllable); }} + break; + case 21: +#line 85 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p+1;{ found_syllable (standalone_cluster); }} + break; + case 18: +#line 86 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p+1;{ found_syllable (broken_cluster); }} + break; + case 11: +#line 87 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p+1;{ found_syllable (non_indic_cluster); }} + break; + case 13: +#line 83 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p;p--;{ found_syllable (consonant_syllable); }} + break; + case 15: +#line 84 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p;p--;{ found_syllable (vowel_syllable); }} + break; + case 20: +#line 85 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p;p--;{ found_syllable (standalone_cluster); }} + break; + case 17: +#line 86 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p;p--;{ found_syllable (broken_cluster); }} + break; + case 19: +#line 87 "../../src/hb-ot-shape-complex-indic-machine.rl" + {te = p;p--;{ found_syllable (non_indic_cluster); }} + break; + case 1: +#line 83 "../../src/hb-ot-shape-complex-indic-machine.rl" + {{p = ((te))-1;}{ found_syllable (consonant_syllable); }} + break; + case 3: +#line 84 "../../src/hb-ot-shape-complex-indic-machine.rl" + {{p = ((te))-1;}{ found_syllable (vowel_syllable); }} + break; + case 7: +#line 85 "../../src/hb-ot-shape-complex-indic-machine.rl" + {{p = ((te))-1;}{ found_syllable (standalone_cluster); }} + break; + case 4: +#line 86 "../../src/hb-ot-shape-complex-indic-machine.rl" + {{p = ((te))-1;}{ found_syllable (broken_cluster); }} + break; + case 5: +#line 1 "NONE" + { switch( act ) { + case 1: + {{p = ((te))-1;} found_syllable (consonant_syllable); } + break; + case 4: + {{p = ((te))-1;} found_syllable (broken_cluster); } + break; + case 5: + {{p = ((te))-1;} found_syllable (non_indic_cluster); } + break; + } + } + break; + case 8: +#line 1 "NONE" + {te = p+1;} +#line 83 "../../src/hb-ot-shape-complex-indic-machine.rl" + {act = 1;} + break; + case 6: +#line 1 "NONE" + {te = p+1;} +#line 86 "../../src/hb-ot-shape-complex-indic-machine.rl" + {act = 4;} + break; + case 12: +#line 1 "NONE" + {te = p+1;} +#line 87 "../../src/hb-ot-shape-complex-indic-machine.rl" + {act = 5;} + break; +#line 1415 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" + } + +_again: + switch ( _indic_syllable_machine_to_state_actions[cs] ) { + case 9: +#line 1 "NONE" + {ts = 0;} + break; +#line 1424 "../../src/hb-ot-shape-complex-indic-machine.hh.tmp" + } + + if ( ++p != pe ) + goto _resume; + _test_eof: {} + if ( p == eof ) + { + if ( _indic_syllable_machine_eof_trans[cs] > 0 ) { + _trans = _indic_syllable_machine_eof_trans[cs] - 1; + goto _eof_trans; + } + } + + } + +#line 121 "../../src/hb-ot-shape-complex-indic-machine.rl" + +} + +#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.rl b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.rl new file mode 100644 index 00000000000..11115c9cda4 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-machine.rl @@ -0,0 +1,124 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH +#define HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH + +#include "hb-private.hh" + +%%{ + machine indic_syllable_machine; + alphtype unsigned char; + write data; +}%% + +%%{ + +# Same order as enum indic_category_t. Not sure how to avoid duplication. +X = 0; +C = 1; +V = 2; +N = 3; +H = 4; +ZWNJ = 5; +ZWJ = 6; +M = 7; +SM = 8; +VD = 9; +A = 10; +NBSP = 11; +DOTTEDCIRCLE = 12; +RS = 13; +Coeng = 14; +Repha = 15; +Ra = 16; +CM = 17; + +c = (C | Ra)CM*; # is_consonant +n = ((ZWNJ?.RS)? (N.N?)?); # is_consonant_modifier +z = ZWJ|ZWNJ; # is_joiner +h = H | Coeng; # is_halant_or_coeng +reph = (Ra H | Repha); # possible reph + +cn = c.ZWJ?.n?; +forced_rakar = ZWJ H ZWJ Ra; +matra_group = z{0,3}.M.N?.(H | forced_rakar)?; +syllable_tail = (Coeng (cn|V))? (SM.ZWNJ?)? (VD VD?)?; +place_holder = NBSP | DOTTEDCIRCLE; +halant_group = (z?.h.(ZWJ.N?)?); +final_halant_group = halant_group | h.ZWNJ; +halant_or_matra_group = (final_halant_group | (h.ZWJ)? matra_group{0,4}); + + +consonant_syllable = Repha? (cn.halant_group){0,4} cn A? halant_or_matra_group? syllable_tail; +vowel_syllable = reph? V.n? (ZWJ | (halant_group.cn){0,4} halant_or_matra_group? syllable_tail); +standalone_cluster = reph? place_holder.n? (halant_group.cn){0,4} halant_or_matra_group? syllable_tail; +broken_cluster = reph? n? (halant_group.cn){0,4} halant_or_matra_group syllable_tail; +other = any; + +main := |* + consonant_syllable => { found_syllable (consonant_syllable); }; + vowel_syllable => { found_syllable (vowel_syllable); }; + standalone_cluster => { found_syllable (standalone_cluster); }; + broken_cluster => { found_syllable (broken_cluster); }; + other => { found_syllable (non_indic_cluster); }; +*|; + + +}%% + +#define found_syllable(syllable_type) \ + HB_STMT_START { \ + if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #syllable_type); \ + for (unsigned int i = last; i < p+1; i++) \ + info[i].syllable() = (syllable_serial << 4) | syllable_type; \ + last = p+1; \ + syllable_serial++; \ + if (unlikely (syllable_serial == 16)) syllable_serial = 1; \ + } HB_STMT_END + +static void +find_syllables (hb_buffer_t *buffer) +{ + unsigned int p, pe, eof, ts HB_UNUSED, te, act; + int cs; + hb_glyph_info_t *info = buffer->info; + %%{ + write init; + getkey info[p].indic_category(); + }%% + + p = 0; + pe = eof = buffer->len; + + unsigned int last = 0; + unsigned int syllable_serial = 1; + %%{ + write exec; + }%% +} + +#endif /* HB_OT_SHAPE_COMPLEX_INDIC_MACHINE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-private.hh new file mode 100644 index 00000000000..e36090e4837 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-private.hh @@ -0,0 +1,388 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH +#define HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH + +#include "hb-private.hh" + + +#include "hb-ot-shape-complex-private.hh" +#include "hb-ot-shape-private.hh" /* XXX Remove */ + + +/* buffer var allocations */ +#define indic_category() complex_var_u8_0() /* indic_category_t */ +#define indic_position() complex_var_u8_1() /* indic_matra_category_t */ + + +#define INDIC_TABLE_ELEMENT_TYPE uint16_t + +/* Cateories used in the OpenType spec: + * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx + */ +/* Note: This enum is duplicated in the -machine.rl source file. + * Not sure how to avoid duplication. */ +enum indic_category_t { + OT_X = 0, + OT_C, + OT_V, + OT_N, + OT_H, + OT_ZWNJ, + OT_ZWJ, + OT_M, + OT_SM, + OT_VD, + OT_A, + OT_NBSP, + OT_DOTTEDCIRCLE, /* Not in the spec, but special in Uniscribe. /Very very/ special! */ + OT_RS, /* Register Shifter, used in Khmer OT spec */ + OT_Coeng, + OT_Repha, + OT_Ra, /* Not explicitly listed in the OT spec, but used in the grammar. */ + OT_CM +}; + +/* Visual positions in a syllable from left to right. */ +enum indic_position_t { + POS_START, + + POS_RA_TO_BECOME_REPH, + POS_PRE_M, + POS_PRE_C, + + POS_BASE_C, + POS_AFTER_MAIN, + + POS_ABOVE_C, + + POS_BEFORE_SUB, + POS_BELOW_C, + POS_AFTER_SUB, + + POS_BEFORE_POST, + POS_POST_C, + POS_AFTER_POST, + + POS_FINAL_C, + POS_SMVD, + + POS_END +}; + +/* Categories used in IndicSyllabicCategory.txt from UCD. */ +enum indic_syllabic_category_t { + INDIC_SYLLABIC_CATEGORY_OTHER = OT_X, + + INDIC_SYLLABIC_CATEGORY_AVAGRAHA = OT_X, + INDIC_SYLLABIC_CATEGORY_BINDU = OT_SM, + INDIC_SYLLABIC_CATEGORY_CONSONANT = OT_C, + INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD = OT_C, + INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL = OT_C, + INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER = OT_C, + INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL = OT_CM, + INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER = OT_NBSP, + INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED = OT_C, + INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA = OT_Repha, + INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER = OT_X, + INDIC_SYLLABIC_CATEGORY_NUKTA = OT_N, + INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER = OT_RS, + INDIC_SYLLABIC_CATEGORY_TONE_LETTER = OT_X, + INDIC_SYLLABIC_CATEGORY_TONE_MARK = OT_N, + INDIC_SYLLABIC_CATEGORY_VIRAMA = OT_H, + INDIC_SYLLABIC_CATEGORY_VISARGA = OT_SM, + INDIC_SYLLABIC_CATEGORY_VOWEL = OT_V, + INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT = OT_M, + INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT = OT_V +}; + +/* Categories used in IndicSMatraCategory.txt from UCD */ +enum indic_matra_category_t { + INDIC_MATRA_CATEGORY_NOT_APPLICABLE = POS_END, + + INDIC_MATRA_CATEGORY_LEFT = POS_PRE_C, + INDIC_MATRA_CATEGORY_TOP = POS_ABOVE_C, + INDIC_MATRA_CATEGORY_BOTTOM = POS_BELOW_C, + INDIC_MATRA_CATEGORY_RIGHT = POS_POST_C, + + /* These should resolve to the position of the last part of the split sequence. */ + INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, + INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, + INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM = INDIC_MATRA_CATEGORY_BOTTOM, + INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, + INDIC_MATRA_CATEGORY_TOP_AND_LEFT = INDIC_MATRA_CATEGORY_TOP, + INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, + INDIC_MATRA_CATEGORY_TOP_AND_RIGHT = INDIC_MATRA_CATEGORY_RIGHT, + + INDIC_MATRA_CATEGORY_INVISIBLE = INDIC_MATRA_CATEGORY_NOT_APPLICABLE, + INDIC_MATRA_CATEGORY_OVERSTRUCK = POS_AFTER_MAIN, + INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT = POS_PRE_M +}; + +/* Note: We use ASSERT_STATIC_EXPR_ZERO() instead of ASSERT_STATIC_EXPR() and the comma operation + * because gcc fails to optimize the latter and fills the table in at runtime. */ +#define INDIC_COMBINE_CATEGORIES(S,M) \ + (ASSERT_STATIC_EXPR_ZERO (M == INDIC_MATRA_CATEGORY_NOT_APPLICABLE || (S == INDIC_SYLLABIC_CATEGORY_VIRAMA || S == INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT)) + \ + ASSERT_STATIC_EXPR_ZERO (S < 255 && M < 255) + \ + ((M << 8) | S)) + + +#include "hb-ot-shape-complex-indic-table.hh" + + +#define IN_HALF_BLOCK(u, Base) (((u) & ~0x7F) == (Base)) + +#define IS_DEVA(u) (IN_HALF_BLOCK (u, 0x0900)) +#define IS_BENG(u) (IN_HALF_BLOCK (u, 0x0980)) +#define IS_GURU(u) (IN_HALF_BLOCK (u, 0x0A00)) +#define IS_GUJR(u) (IN_HALF_BLOCK (u, 0x0A80)) +#define IS_ORYA(u) (IN_HALF_BLOCK (u, 0x0B00)) +#define IS_TAML(u) (IN_HALF_BLOCK (u, 0x0B80)) +#define IS_TELU(u) (IN_HALF_BLOCK (u, 0x0C00)) +#define IS_KNDA(u) (IN_HALF_BLOCK (u, 0x0C80)) +#define IS_MLYM(u) (IN_HALF_BLOCK (u, 0x0D00)) +#define IS_SINH(u) (IN_HALF_BLOCK (u, 0x0D80)) +#define IS_KHMR(u) (IN_HALF_BLOCK (u, 0x1780)) + + +#define MATRA_POS_LEFT(u) POS_PRE_M +#define MATRA_POS_RIGHT(u) ( \ + IS_DEVA(u) ? POS_AFTER_SUB : \ + IS_BENG(u) ? POS_AFTER_POST : \ + IS_GURU(u) ? POS_AFTER_POST : \ + IS_GUJR(u) ? POS_AFTER_POST : \ + IS_ORYA(u) ? POS_AFTER_POST : \ + IS_TAML(u) ? POS_AFTER_POST : \ + IS_TELU(u) ? (u <= 0x0C42 ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ + IS_KNDA(u) ? (u < 0x0CC3 || u > 0xCD6 ? POS_BEFORE_SUB : POS_AFTER_SUB) : \ + IS_MLYM(u) ? POS_AFTER_POST : \ + IS_SINH(u) ? POS_AFTER_SUB : \ + IS_KHMR(u) ? POS_AFTER_POST : \ + /*default*/ POS_AFTER_SUB \ + ) +#define MATRA_POS_TOP(u) ( /* BENG and MLYM don't have top matras. */ \ + IS_DEVA(u) ? POS_AFTER_SUB : \ + IS_GURU(u) ? POS_AFTER_POST : /* Deviate from spec */ \ + IS_GUJR(u) ? POS_AFTER_SUB : \ + IS_ORYA(u) ? POS_AFTER_MAIN : \ + IS_TAML(u) ? POS_AFTER_SUB : \ + IS_TELU(u) ? POS_BEFORE_SUB : \ + IS_KNDA(u) ? POS_BEFORE_SUB : \ + IS_SINH(u) ? POS_AFTER_SUB : \ + IS_KHMR(u) ? POS_AFTER_POST : \ + /*default*/ POS_AFTER_SUB \ + ) +#define MATRA_POS_BOTTOM(u) ( \ + IS_DEVA(u) ? POS_AFTER_SUB : \ + IS_BENG(u) ? POS_AFTER_SUB : \ + IS_GURU(u) ? POS_AFTER_POST : \ + IS_GUJR(u) ? POS_AFTER_POST : \ + IS_ORYA(u) ? POS_AFTER_SUB : \ + IS_TAML(u) ? POS_AFTER_POST : \ + IS_TELU(u) ? POS_BEFORE_SUB : \ + IS_KNDA(u) ? POS_BEFORE_SUB : \ + IS_MLYM(u) ? POS_AFTER_POST : \ + IS_SINH(u) ? POS_AFTER_SUB : \ + IS_KHMR(u) ? POS_AFTER_POST : \ + /*default*/ POS_AFTER_SUB \ + ) + + +static inline indic_position_t +matra_position (hb_codepoint_t u, indic_position_t side) +{ + switch ((int) side) + { + case POS_PRE_C: return MATRA_POS_LEFT (u); + case POS_POST_C: return MATRA_POS_RIGHT (u); + case POS_ABOVE_C: return MATRA_POS_TOP (u); + case POS_BELOW_C: return MATRA_POS_BOTTOM (u); + }; + return side; +} + + + +/* XXX + * This is a hack for now. We should move this data into the main Indic table. + * Or completely remove it and just check in the tables. + */ +static const hb_codepoint_t ra_chars[] = { + 0x0930, /* Devanagari */ + 0x09B0, /* Bengali */ + 0x09F0, /* Bengali */ + 0x0A30, /* Gurmukhi */ /* No Reph */ + 0x0AB0, /* Gujarati */ + 0x0B30, /* Oriya */ + 0x0BB0, /* Tamil */ /* No Reph */ + 0x0C30, /* Telugu */ /* Reph formed only with ZWJ */ + 0x0CB0, /* Kannada */ + 0x0D30, /* Malayalam */ /* No Reph, Logical Repha */ + + 0x0DBB, /* Sinhala */ /* Reph formed only with ZWJ */ + + 0x179A, /* Khmer */ /* No Reph, Visual Repha */ +}; + +static inline indic_position_t +consonant_position (hb_codepoint_t u) +{ + if ((u & ~0x007F) == 0x1780) + return POS_BELOW_C; /* In Khmer coeng model, post and below forms should not be reordered. */ + return POS_BASE_C; /* Will recategorize later based on font lookups. */ +} + +static inline bool +is_ra (hb_codepoint_t u) +{ + for (unsigned int i = 0; i < ARRAY_LENGTH (ra_chars); i++) + if (u == ra_chars[i]) + return true; + return false; +} + + +static inline bool +is_one_of (const hb_glyph_info_t &info, unsigned int flags) +{ + /* If it ligated, all bets are off. */ + if (is_a_ligature (info)) return false; + return !!(FLAG (info.indic_category()) & flags); +} + +#define JOINER_FLAGS (FLAG (OT_ZWJ) | FLAG (OT_ZWNJ)) +static inline bool +is_joiner (const hb_glyph_info_t &info) +{ + return is_one_of (info, JOINER_FLAGS); +} + +/* Note: + * + * We treat Vowels and placeholders as if they were consonants. This is safe because Vowels + * cannot happen in a consonant syllable. The plus side however is, we can call the + * consonant syllable logic from the vowel syllable function and get it all right! */ +#define CONSONANT_FLAGS (FLAG (OT_C) | FLAG (OT_CM) | FLAG (OT_Ra) | FLAG (OT_V) | FLAG (OT_NBSP) | FLAG (OT_DOTTEDCIRCLE)) +static inline bool +is_consonant (const hb_glyph_info_t &info) +{ + return is_one_of (info, CONSONANT_FLAGS); +} + +#define HALANT_OR_COENG_FLAGS (FLAG (OT_H) | FLAG (OT_Coeng)) +static inline bool +is_halant_or_coeng (const hb_glyph_info_t &info) +{ + return is_one_of (info, HALANT_OR_COENG_FLAGS); +} + +static inline void +set_indic_properties (hb_glyph_info_t &info) +{ + hb_codepoint_t u = info.codepoint; + unsigned int type = get_indic_categories (u); + indic_category_t cat = (indic_category_t) (type & 0x7F); + indic_position_t pos = (indic_position_t) (type >> 8); + + + /* + * Re-assign category + */ + + + /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe + * treats U+0951..U+0952 all as OT_VD. + * TESTS: + * U+092E,U+0947,U+0952 + * U+092E,U+0952,U+0947 + * U+092E,U+0947,U+0951 + * U+092E,U+0951,U+0947 + * */ + if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x0951, 0x0954))) + cat = OT_VD; + + if (unlikely (u == 0x17D1)) + cat = OT_X; + if (cat == OT_X && + unlikely (hb_in_range<hb_codepoint_t> (u, 0x17CB, 0x17D3))) /* Khmer Various signs */ + { + /* These are like Top Matras. */ + cat = OT_M; + pos = POS_ABOVE_C; + } + if (u == 0x17C6) /* Khmer Bindu doesn't like to be repositioned. */ + cat = OT_N; + + if (unlikely (u == 0x17D2)) cat = OT_Coeng; /* Khmer coeng */ + else if (unlikely (u == 0x200C)) cat = OT_ZWNJ; + else if (unlikely (u == 0x200D)) cat = OT_ZWJ; + else if (unlikely (u == 0x25CC)) cat = OT_DOTTEDCIRCLE; + else if (unlikely (u == 0x0A71)) cat = OT_SM; /* GURMUKHI ADDAK. More like consonant medial. like 0A75. */ + + if (cat == OT_Repha) { + /* There are two kinds of characters marked as Repha: + * - The ones that are GenCat=Mn are already positioned visually, ie. after base. (eg. Khmer) + * - The ones that are GenCat=Lo is encoded logically, ie. beginning of syllable. (eg. Malayalam) + * + * We recategorize the first kind to look like a Nukta and attached to the base directly. + */ + if (_hb_glyph_info_get_general_category (&info) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) + cat = OT_N; + } + + + + /* + * Re-assign position. + */ + + if ((FLAG (cat) & CONSONANT_FLAGS)) + { + pos = consonant_position (u); + if (is_ra (u)) + cat = OT_Ra; + } + else if (cat == OT_M) + { + pos = matra_position (u, pos); + } + else if (cat == OT_SM || cat == OT_VD) + { + pos = POS_SMVD; + } + + if (unlikely (u == 0x0B01)) pos = POS_BEFORE_SUB; /* Oriya Bindu is BeforeSub in the spec. */ + + + + info.indic_category() = cat; + info.indic_position() = pos; +} + + + +#endif /* HB_OT_SHAPE_COMPLEX_INDIC_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-table.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-table.hh new file mode 100644 index 00000000000..70765b6d6f4 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic-table.hh @@ -0,0 +1,872 @@ +/* == Start of generated table == */ +/* + * The following table is generated by running: + * + * ./gen-indic-table.py IndicSyllabicCategory.txt IndicMatraCategory.txt Blocks.txt + * + * on files with these headers: + * + * # IndicSyllabicCategory-6.2.0.txt + * # Date: 2012-05-15, 21:12:00 GMT [KW] + * # IndicMatraCategory-6.2.0.txt + * # Date: 2012-05-15, 21:10:00 GMT [KW] + * # Blocks-6.2.0.txt + * # Date: 2012-05-14, 22:42:00 GMT [KW, LI] + */ + +#ifndef HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH +#define HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH + + +#define ISC_A INDIC_SYLLABIC_CATEGORY_AVAGRAHA /* 11 chars; Avagraha */ +#define ISC_Bi INDIC_SYLLABIC_CATEGORY_BINDU /* 34 chars; Bindu */ +#define ISC_C INDIC_SYLLABIC_CATEGORY_CONSONANT /* 123 chars; Consonant */ +#define ISC_CD INDIC_SYLLABIC_CATEGORY_CONSONANT_DEAD /* 2 chars; Consonant_Dead */ +#define ISC_CF INDIC_SYLLABIC_CATEGORY_CONSONANT_FINAL /* 17 chars; Consonant_Final */ +#define ISC_CHL INDIC_SYLLABIC_CATEGORY_CONSONANT_HEAD_LETTER /* 1 chars; Consonant_Head_Letter */ +#define ISC_CM INDIC_SYLLABIC_CATEGORY_CONSONANT_MEDIAL /* 12 chars; Consonant_Medial */ +#define ISC_CP INDIC_SYLLABIC_CATEGORY_CONSONANT_PLACEHOLDER /* 4 chars; Consonant_Placeholder */ +#define ISC_CR INDIC_SYLLABIC_CATEGORY_CONSONANT_REPHA /* 5 chars; Consonant_Repha */ +#define ISC_CS INDIC_SYLLABIC_CATEGORY_CONSONANT_SUBJOINED /* 10 chars; Consonant_Subjoined */ +#define ISC_ML INDIC_SYLLABIC_CATEGORY_MODIFYING_LETTER /* 1 chars; Modifying_Letter */ +#define ISC_N INDIC_SYLLABIC_CATEGORY_NUKTA /* 12 chars; Nukta */ +#define ISC_x INDIC_SYLLABIC_CATEGORY_OTHER /* 1 chars; Other */ +#define ISC_RS INDIC_SYLLABIC_CATEGORY_REGISTER_SHIFTER /* 1 chars; Register_Shifter */ +#define ISC_TL INDIC_SYLLABIC_CATEGORY_TONE_LETTER /* 3 chars; Tone_Letter */ +#define ISC_TM INDIC_SYLLABIC_CATEGORY_TONE_MARK /* 16 chars; Tone_Mark */ +#define ISC_V INDIC_SYLLABIC_CATEGORY_VIRAMA /* 34 chars; Virama */ +#define ISC_Vs INDIC_SYLLABIC_CATEGORY_VISARGA /* 25 chars; Visarga */ +#define ISC_Vo INDIC_SYLLABIC_CATEGORY_VOWEL /* 5 chars; Vowel */ +#define ISC_M INDIC_SYLLABIC_CATEGORY_VOWEL_DEPENDENT /* 165 chars; Vowel_Dependent */ +#define ISC_VI INDIC_SYLLABIC_CATEGORY_VOWEL_INDEPENDENT /* 59 chars; Vowel_Independent */ + +#define IMC_B INDIC_MATRA_CATEGORY_BOTTOM /* 65 chars; Bottom */ +#define IMC_BR INDIC_MATRA_CATEGORY_BOTTOM_AND_RIGHT /* 2 chars; Bottom_And_Right */ +#define IMC_I INDIC_MATRA_CATEGORY_INVISIBLE /* 6 chars; Invisible */ +#define IMC_L INDIC_MATRA_CATEGORY_LEFT /* 30 chars; Left */ +#define IMC_LR INDIC_MATRA_CATEGORY_LEFT_AND_RIGHT /* 8 chars; Left_And_Right */ +#define IMC_x INDIC_MATRA_CATEGORY_NOT_APPLICABLE /* 1 chars; Not_Applicable */ +#define IMC_O INDIC_MATRA_CATEGORY_OVERSTRUCK /* 2 chars; Overstruck */ +#define IMC_R INDIC_MATRA_CATEGORY_RIGHT /* 75 chars; Right */ +#define IMC_T INDIC_MATRA_CATEGORY_TOP /* 83 chars; Top */ +#define IMC_TB INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM /* 6 chars; Top_And_Bottom */ +#define IMC_TBR INDIC_MATRA_CATEGORY_TOP_AND_BOTTOM_AND_RIGHT /* 1 chars; Top_And_Bottom_And_Right */ +#define IMC_TL INDIC_MATRA_CATEGORY_TOP_AND_LEFT /* 4 chars; Top_And_Left */ +#define IMC_TLR INDIC_MATRA_CATEGORY_TOP_AND_LEFT_AND_RIGHT /* 2 chars; Top_And_Left_And_Right */ +#define IMC_TR INDIC_MATRA_CATEGORY_TOP_AND_RIGHT /* 8 chars; Top_And_Right */ +#define IMC_VOL INDIC_MATRA_CATEGORY_VISUAL_ORDER_LEFT /* 5 chars; Visual_Order_Left */ + +#define _(S,M) INDIC_COMBINE_CATEGORIES (ISC_##S, IMC_##M) + + +static const INDIC_TABLE_ELEMENT_TYPE indic_table[] = { + + +#define indic_offset_0x0900 0 + + + /* Devanagari (0900..097F) */ + + /* 0900 */ _(Bi,x), _(Bi,x), _(Bi,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 0908 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 0910 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0918 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0920 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0928 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0930 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0938 */ _(C,x), _(C,x), _(M,T), _(M,R), _(N,x), _(A,x), _(M,R), _(M,L), + /* 0940 */ _(M,R), _(M,B), _(M,B), _(M,B), _(M,B), _(M,T), _(M,T), _(M,T), + /* 0948 */ _(M,T), _(M,R), _(M,R), _(M,R), _(M,R), _(V,B), _(M,L), _(M,R), + /* 0950 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,T), _(M,B), _(M,B), + /* 0958 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0960 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0968 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0970 */ _(x,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 0978 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + + /* Bengali (0980..09FF) */ + + /* 0980 */ _(x,x), _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0988 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(x,x), _(VI,x), + /* 0990 */ _(VI,x), _(x,x), _(x,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0998 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 09A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 09A8 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 09B0 */ _(C,x), _(x,x), _(C,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), + /* 09B8 */ _(C,x), _(C,x), _(x,x), _(x,x), _(N,x), _(A,x), _(M,R), _(M,L), + /* 09C0 */ _(M,R), _(M,B), _(M,B), _(M,B), _(M,B), _(x,x), _(x,x), _(M,L), + /* 09C8 */ _(M,L), _(x,x), _(x,x), _(M,LR), _(M,LR), _(V,B), _(CD,x), _(x,x), + /* 09D0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), + /* 09D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), + /* 09E0 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 09E8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 09F0 */ _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 09F8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Gurmukhi (0A00..0A7F) */ + + /* 0A00 */ _(x,x), _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0A08 */ _(VI,x), _(VI,x), _(VI,x), _(x,x), _(x,x), _(x,x), _(x,x), _(VI,x), + /* 0A10 */ _(VI,x), _(x,x), _(x,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0A18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0A20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0A28 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0A30 */ _(C,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(x,x), + /* 0A38 */ _(C,x), _(C,x), _(x,x), _(x,x), _(N,x), _(x,x), _(M,R), _(M,L), + /* 0A40 */ _(M,R), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), _(M,T), + /* 0A48 */ _(M,T), _(x,x), _(x,x), _(M,T), _(M,T), _(V,B), _(x,x), _(x,x), + /* 0A50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0A58 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(x,x), + /* 0A60 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0A68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0A70 */ _(Bi,x), _(x,x), _(CP,x), _(CP,x), _(x,x), _(CM,x), _(x,x), _(x,x), + /* 0A78 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Gujarati (0A80..0AFF) */ + + /* 0A80 */ _(x,x), _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0A88 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(VI,x), + /* 0A90 */ _(VI,x), _(VI,x), _(x,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0A98 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0AA0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0AA8 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0AB0 */ _(C,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), + /* 0AB8 */ _(C,x), _(C,x), _(x,x), _(x,x), _(N,x), _(A,x), _(M,R), _(M,L), + /* 0AC0 */ _(M,R), _(M,B), _(M,B), _(M,B), _(M,B), _(M,T), _(x,x), _(M,T), + /* 0AC8 */ _(M,T), _(M,TR), _(x,x), _(M,R), _(M,R), _(V,B), _(x,x), _(x,x), + /* 0AD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0AD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0AE0 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0AE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0AF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0AF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Oriya (0B00..0B7F) */ + + /* 0B00 */ _(x,x), _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0B08 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(x,x), _(VI,x), + /* 0B10 */ _(VI,x), _(x,x), _(x,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0B18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0B20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0B28 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0B30 */ _(C,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), + /* 0B38 */ _(C,x), _(C,x), _(x,x), _(x,x), _(N,x), _(A,x), _(M,R), _(M,T), + /* 0B40 */ _(M,R), _(M,B), _(M,B), _(M,B), _(M,B), _(x,x), _(x,x), _(M,L), + /* 0B48 */ _(M,TL), _(x,x), _(x,x), _(M,LR),_(M,TLR), _(V,B), _(x,x), _(x,x), + /* 0B50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,T), _(M,TR), + /* 0B58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), + /* 0B60 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0B68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0B70 */ _(x,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0B78 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tamil (0B80..0BFF) */ + + /* 0B80 */ _(x,x), _(x,x), _(Bi,x), _(ML,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0B88 */ _(VI,x), _(VI,x), _(VI,x), _(x,x), _(x,x), _(x,x), _(VI,x), _(VI,x), + /* 0B90 */ _(VI,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(x,x), _(x,x), + /* 0B98 */ _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(x,x), _(C,x), _(C,x), + /* 0BA0 */ _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), + /* 0BA8 */ _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), + /* 0BB0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0BB8 */ _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), _(M,R), + /* 0BC0 */ _(M,T), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(M,L), _(M,L), + /* 0BC8 */ _(M,L), _(x,x), _(M,LR), _(M,LR), _(M,LR), _(V,T), _(x,x), _(x,x), + /* 0BD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), + /* 0BD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0BE0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0BE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0BF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0BF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Telugu (0C00..0C7F) */ + + /* 0C00 */ _(x,x), _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0C08 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(VI,x), _(VI,x), + /* 0C10 */ _(VI,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0C18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0C20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0C28 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0C30 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), + /* 0C38 */ _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(A,x), _(M,T), _(M,T), + /* 0C40 */ _(M,T), _(M,R), _(M,R), _(M,R), _(M,R), _(x,x), _(M,T), _(M,T), + /* 0C48 */ _(M,TB), _(x,x), _(M,T), _(M,T), _(M,T), _(V,T), _(x,x), _(x,x), + /* 0C50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,T), _(M,B), _(x,x), + /* 0C58 */ _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0C60 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0C68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0C70 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0C78 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Kannada (0C80..0CFF) */ + + /* 0C80 */ _(x,x), _(x,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0C88 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(VI,x), _(VI,x), + /* 0C90 */ _(VI,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0C98 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0CA0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0CA8 */ _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0CB0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), + /* 0CB8 */ _(C,x), _(C,x), _(x,x), _(x,x), _(N,x), _(A,x), _(M,R), _(M,T), + /* 0CC0 */ _(M,TR), _(M,R), _(M,R), _(M,R), _(M,R), _(x,x), _(M,T), _(M,TR), + /* 0CC8 */ _(M,TR), _(x,x), _(M,TR), _(M,TR), _(M,T), _(V,T), _(x,x), _(x,x), + /* 0CD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), _(M,R), _(x,x), + /* 0CD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(x,x), + /* 0CE0 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0CE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0CF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0CF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Malayalam (0D00..0D7F) */ + + /* 0D00 */ _(x,x), _(x,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0D08 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(VI,x), _(VI,x), + /* 0D10 */ _(VI,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 0D18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0D20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0D28 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0D30 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0D38 */ _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(A,x), _(M,R), _(M,R), + /* 0D40 */ _(M,R), _(M,R), _(M,R), _(M,B), _(M,B), _(x,x), _(M,L), _(M,L), + /* 0D48 */ _(M,L), _(x,x), _(M,LR), _(M,LR), _(M,LR), _(V,T), _(CR,x), _(x,x), + /* 0D50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), + /* 0D58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0D60 */ _(VI,x), _(VI,x), _(M,B), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0D68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0D70 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0D78 */ _(x,x), _(x,x), _(CD,x), _(CD,x), _(CD,x), _(CD,x), _(CD,x), _(CD,x), + + /* Sinhala (0D80..0DFF) */ + + /* 0D80 */ _(x,x), _(x,x), _(Bi,x), _(Vs,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 0D88 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 0D90 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), + /* 0D98 */ _(x,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0DA0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0DA8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0DB0 */ _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0DB8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(x,x), _(x,x), + /* 0DC0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), + /* 0DC8 */ _(x,x), _(x,x), _(V,T), _(x,x), _(x,x), _(x,x), _(x,x), _(M,R), + /* 0DD0 */ _(M,R), _(M,R), _(M,T), _(M,T), _(M,B), _(x,x), _(M,B), _(x,x), + /* 0DD8 */ _(M,R), _(M,L), _(M,TL), _(M,L), _(M,LR), _(M,LR), _(M,LR), _(M,R), + /* 0DE0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0DE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0DF0 */ _(x,x), _(x,x), _(M,R), _(M,R), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0DF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Thai (0E00..0E7F) */ + + /* 0E00 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E08 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E10 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E28 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), + /* 0E30 */ _(M,R), _(M,T), _(M,R), _(M,R), _(M,T), _(M,T), _(M,T), _(M,T), + /* 0E38 */ _(M,B), _(M,B), _(V,B), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E40 */_(M,VOL),_(M,VOL),_(M,VOL),_(M,VOL),_(M,VOL), _(M,R), _(x,x), _(M,T), + /* 0E48 */ _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(x,x), _(Bi,x), _(V,T), _(x,x), + /* 0E50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E60 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E70 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0E78 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Lao (0E80..0EFF) */ + + /* 0E80 */ _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(x,x), _(x,x), _(C,x), + /* 0E88 */ _(C,x), _(x,x), _(C,x), _(x,x), _(x,x), _(C,x), _(x,x), _(x,x), + /* 0E90 */ _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0E98 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0EA0 */ _(x,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(x,x), _(C,x), + /* 0EA8 */ _(x,x), _(x,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(x,x), + /* 0EB0 */ _(M,R), _(M,T), _(M,R), _(M,R), _(M,T), _(M,T), _(M,T), _(M,T), + /* 0EB8 */ _(M,B), _(M,B), _(x,x), _(M,T), _(CM,x), _(CM,x), _(x,x), _(x,x), + /* 0EC0 */_(M,VOL),_(M,VOL),_(M,VOL),_(M,VOL),_(M,VOL), _(x,x), _(x,x), _(x,x), + /* 0EC8 */ _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(x,x), _(Bi,x), _(x,x), _(x,x), + /* 0ED0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0ED8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(x,x), _(x,x), + /* 0EE0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0EE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0EF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0EF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tibetan (0F00..0FFF) */ + + /* 0F00 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F08 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F10 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F18 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F20 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F28 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F30 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F38 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0F40 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0F48 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0F50 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0F58 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0F60 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 0F68 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), + /* 0F70 */ _(x,x), _(M,B), _(M,T), _(M,TB), _(M,B), _(M,B), _(M,TB), _(M,TB), + /* 0F78 */ _(M,TB), _(M,TB), _(M,T), _(M,T), _(M,T), _(M,T), _(Bi,x), _(Vs,x), + /* 0F80 */ _(M,T), _(M,TB), _(Bi,x), _(Bi,x), _(V,B), _(A,x), _(x,x), _(x,x), + /* 0F88 */_(CHL,x),_(CHL,x),_(CHL,x),_(CHL,x),_(CHL,x), _(CS,x), _(CS,x), _(CS,x), + /* 0F90 */ _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), + /* 0F98 */ _(x,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), + /* 0FA0 */ _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), + /* 0FA8 */ _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), + /* 0FB0 */ _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), + /* 0FB8 */ _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(CS,x), _(x,x), _(x,x), _(x,x), + /* 0FC0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FC8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FE0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 0FF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Myanmar (1000..109F) */ + + /* 1000 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1008 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1010 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1018 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1020 */ _(C,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 1028 */ _(VI,x), _(VI,x), _(VI,x), _(M,R), _(M,R), _(M,T), _(M,T), _(M,B), + /* 1030 */ _(M,B), _(M,L), _(M,T), _(M,T), _(M,T), _(M,T), _(Bi,x), _(TM,x), + /* 1038 */ _(Vs,x), _(V,I), _(V,T), _(CM,x), _(CM,x), _(CM,x), _(CM,x), _(C,x), + /* 1040 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1048 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1050 */ _(C,x), _(C,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(M,R), _(M,R), + /* 1058 */ _(M,B), _(M,B), _(C,x), _(C,x), _(C,x), _(C,x), _(CM,x), _(CM,x), + /* 1060 */ _(CM,x), _(C,x), _(M,R), _(TM,x), _(TM,x), _(C,x), _(C,x), _(M,R), + /* 1068 */ _(M,R), _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(C,x), _(C,x), + /* 1070 */ _(C,x), _(M,T), _(M,T), _(M,T), _(M,T), _(C,x), _(C,x), _(C,x), + /* 1078 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1080 */ _(C,x), _(C,x), _(CM,x), _(M,R), _(M,L), _(M,T), _(M,T), _(TM,x), + /* 1088 */ _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(TM,x), _(C,x), _(TM,x), + /* 1090 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1098 */ _(x,x), _(x,x), _(TM,x), _(TM,x), _(M,R), _(M,T), _(x,x), _(x,x), + +#define indic_offset_0x1700 1952 + + + /* Tagalog (1700..171F) */ + + /* 1700 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1708 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), + /* 1710 */ _(C,x), _(C,x), _(M,T), _(M,B), _(V,B), _(x,x), _(x,x), _(x,x), + /* 1718 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Hanunoo (1720..173F) */ + + /* 1720 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1728 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1730 */ _(C,x), _(C,x), _(M,T), _(M,B), _(V,B), _(x,x), _(x,x), _(x,x), + /* 1738 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Buhid (1740..175F) */ + + /* 1740 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1748 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1750 */ _(C,x), _(C,x), _(M,T), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1758 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tagbanwa (1760..177F) */ + + /* 1760 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1768 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), + /* 1770 */ _(C,x), _(x,x), _(M,T), _(M,B), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1778 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Khmer (1780..17FF) */ + + /* 1780 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1788 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1790 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1798 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 17A0 */ _(C,x), _(C,x), _(C,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 17A8 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 17B0 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(x,x), _(x,x), _(M,R), _(M,T), + /* 17B8 */ _(M,T), _(M,T), _(M,T), _(M,B), _(M,B), _(M,B), _(M,TL),_(M,TLR), + /* 17C0 */ _(M,LR), _(M,L), _(M,L), _(M,L), _(M,LR), _(M,LR), _(Bi,x), _(Vs,x), + /* 17C8 */ _(M,R), _(RS,x), _(RS,x), _(x,x), _(CR,x), _(x,x), _(x,x), _(x,x), + /* 17D0 */ _(x,x), _(V,T), _(V,I), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 17D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(A,x), _(x,x), _(x,x), _(x,x), + /* 17E0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 17E8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 17F0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 17F8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x1900 2208 + + + /* Limbu (1900..194F) */ + + /* 1900 */ _(CP,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1908 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1910 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1918 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), + /* 1920 */ _(M,T), _(M,T), _(M,B), _(M,R), _(M,R), _(M,TR), _(M,TR), _(M,T), + /* 1928 */ _(M,T), _(CS,x), _(CS,x), _(CS,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1930 */ _(CF,x), _(CF,x), _(Bi,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), + /* 1938 */ _(CF,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1940 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1948 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tai Le (1950..197F) */ + + /* 1950 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1958 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1960 */ _(C,x), _(C,x), _(C,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), + /* 1968 */ _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(x,x), _(x,x), + /* 1970 */ _(TL,x), _(TL,x), _(TL,x), _(TL,x), _(TL,x), _(x,x), _(x,x), _(x,x), + /* 1978 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* New Tai Lue (1980..19DF) */ + + /* 1980 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1988 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1990 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1998 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 19A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 19A8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19B0 */ _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), _(M,L), _(M,L), _(M,L), + /* 19B8 */ _(M,R), _(M,R), _(M,L), _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), + /* 19C0 */ _(M,R), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), + /* 19C8 */ _(TM,x), _(TM,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19D0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* FILLER (19E0..19FF) */ + + /* 19E0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19E8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19F0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 19F8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Buginese (1A00..1A1F) */ + + /* 1A00 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A08 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A10 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(M,T), + /* 1A18 */ _(M,B), _(M,L), _(M,R), _(M,L), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tai Tham (1A20..1AAF) */ + + /* 1A20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A28 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A30 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A38 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A40 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1A48 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(VI,x), _(VI,x), _(VI,x), + /* 1A50 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(CM,x), _(CM,x), _(CF,x), + /* 1A58 */ _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(x,x), + /* 1A60 */ _(V,I), _(M,R), _(M,T), _(M,R), _(M,R), _(M,T), _(M,T), _(M,T), + /* 1A68 */ _(M,T), _(M,B), _(M,B), _(M,T), _(M,B), _(M,R), _(M,L), _(M,L), + /* 1A70 */ _(M,L), _(M,L), _(M,L), _(M,T), _(M,T), _(TM,x), _(TM,x), _(TM,x), + /* 1A78 */ _(TM,x), _(TM,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1A80 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1A88 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1A90 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1A98 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1AA0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1AA8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x1b00 2640 + + + /* Balinese (1B00..1B7F) */ + + /* 1B00 */ _(Bi,x), _(Bi,x), _(Bi,x), _(CR,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), + /* 1B08 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 1B10 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B28 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B30 */ _(C,x), _(C,x), _(C,x), _(C,x), _(N,x), _(M,R), _(M,T), _(M,T), + /* 1B38 */ _(M,B), _(M,B), _(M,B), _(M,BR), _(M,TB),_(M,TBR), _(M,L), _(M,L), + /* 1B40 */ _(M,LR), _(M,LR), _(M,T), _(M,TR), _(V,R), _(C,x), _(C,x), _(C,x), + /* 1B48 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B60 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B68 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B70 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1B78 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Sundanese (1B80..1BBF) */ + + /* 1B80 */ _(Bi,x), _(CR,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 1B88 */ _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B90 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1B98 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1BA0 */ _(C,x), _(CS,x), _(CS,x), _(CS,x), _(M,T), _(M,B), _(M,L), _(M,R), + /* 1BA8 */ _(M,T), _(M,T), _(V,R), _(V,x), _(CS,x), _(CS,x), _(C,x), _(C,x), + /* 1BB0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1BB8 */ _(x,x), _(x,x), _(A,x), _(C,x), _(C,x), _(C,x), _(CF,x), _(CF,x), + + /* Batak (1BC0..1BFF) */ + + /* 1BC0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1BC8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1BD0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1BD8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1BE0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(VI,x), _(VI,x), _(N,x), _(M,x), + /* 1BE8 */ _(M,x), _(M,x), _(M,x), _(M,x), _(M,x), _(M,x), _(M,x), _(M,x), + /* 1BF0 */ _(CF,x), _(CF,x), _(V,R), _(V,R), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1BF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Lepcha (1C00..1C4F) */ + + /* 1C00 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1C08 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1C10 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1C18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 1C20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(CS,x), _(CS,x), _(M,R), _(M,L), + /* 1C28 */ _(M,L), _(M,TL), _(M,R), _(M,R), _(M,B), _(CF,x), _(CF,x), _(CF,x), + /* 1C30 */ _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(Bi,x), _(Bi,x), _(x,x), _(N,x), + /* 1C38 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1C40 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1C48 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(C,x), _(C,x), _(C,x), + +#define indic_offset_0x1cd0 2976 + + + /* Vedic Extensions (1CD0..1CFF) */ + + /* 1CD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1CD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1CE0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1CE8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1CF0 */ _(x,x), _(x,x), _(Vs,x), _(Vs,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 1CF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0xa800 3024 + + + /* Syloti Nagri (A800..A82F) */ + + /* A800 */ _(VI,x), _(VI,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), _(V,T), _(C,x), + /* A808 */ _(C,x), _(C,x), _(C,x), _(Bi,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A810 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A818 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A820 */ _(C,x), _(C,x), _(C,x), _(M,R), _(M,R), _(M,B), _(M,T), _(M,R), + /* A828 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* FILLER (A830..A83F) */ + + /* A830 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A838 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Phags-pa (A840..A87F) */ + + /* A840 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A848 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A850 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A858 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(Vo,x), _(Vo,x), + /* A860 */ _(Vo,x), _(Vo,x), _(C,x), _(C,x), _(C,x), _(C,x), _(Vo,x), _(CS,x), + /* A868 */ _(CS,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A870 */ _(C,x), _(CS,x), _(C,x), _(Bi,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A878 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Saurashtra (A880..A8DF) */ + + /* A880 */ _(Bi,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* A888 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* A890 */ _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A898 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A8A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A8A8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A8B0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(CF,x), _(M,R), _(M,R), _(M,R), + /* A8B8 */ _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), _(M,R), + /* A8C0 */ _(M,R), _(M,R), _(M,R), _(M,R), _(V,B), _(x,x), _(x,x), _(x,x), + /* A8C8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A8D0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A8D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* FILLER (A8E0..A8FF) */ + + /* A8E0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A8E8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A8F0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A8F8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Kayah Li (A900..A92F) */ + + /* A900 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A908 */ _(x,x), _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A910 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A918 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A920 */ _(C,x), _(C,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), _(Vo,x), + /* A928 */ _(Vo,x), _(Vo,x), _(Vo,x), _(TM,x), _(TM,x), _(TM,x), _(x,x), _(x,x), + + /* Rejang (A930..A95F) */ + + /* A930 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A938 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A940 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(M,B), + /* A948 */ _(M,B), _(M,B), _(M,T), _(M,B), _(M,B), _(M,B), _(M,B), _(CF,x), + /* A950 */ _(CF,x), _(CF,x), _(CF,x), _(V,R), _(x,x), _(x,x), _(x,x), _(x,x), + /* A958 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* FILLER (A960..A97F) */ + + /* A960 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A968 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A970 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A978 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Javanese (A980..A9DF) */ + + /* A980 */ _(Bi,x), _(Bi,x), _(CR,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* A988 */ _(VI,x), _(C,x), _(C,x), _(C,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), + /* A990 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A998 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A9A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A9A8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* A9B0 */ _(C,x), _(C,x), _(C,x), _(N,x), _(M,R), _(M,R), _(M,T), _(M,T), + /* A9B8 */ _(M,B), _(M,B), _(M,L), _(M,L), _(M,T), _(CS,x), _(CM,x), _(CM,x), + /* A9C0 */ _(V,BR), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9C8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9D0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* FILLER (A9E0..A9FF) */ + + /* A9E0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9E8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9F0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* A9F8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Cham (AA00..AA5F) */ + + /* AA00 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), + /* AA08 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA10 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA18 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA28 */ _(C,x), _(M,T), _(M,T), _(M,T), _(M,T), _(M,B), _(M,T), _(M,L), + /* AA30 */ _(M,L), _(M,T), _(M,B), _(CM,x), _(CM,x), _(CM,x), _(CM,x), _(x,x), + /* AA38 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AA40 */ _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), + /* AA48 */ _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(x,x), _(x,x), + /* AA50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AA58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Myanmar Extended-A (AA60..AA7F) */ + + /* AA60 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA68 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA70 */ _(x,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AA78 */ _(x,x), _(x,x), _(C,x), _(TM,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Tai Viet (AA80..AADF) */ + + /* AA80 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA88 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA90 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AA98 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AAA0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AAA8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AAB0 */ _(M,T), _(M,R), _(M,T), _(M,T), _(M,B),_(M,VOL),_(M,VOL), _(M,T), + /* AAB8 */ _(M,T),_(M,VOL), _(M,R),_(M,VOL),_(M,VOL), _(M,R), _(M,T), _(TM,x), + /* AAC0 */ _(TL,x), _(TM,x), _(TL,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AAC8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AAD0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* AAD8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Meetei Mayek Extensions (AAE0..AAFF) */ + + /* AAE0 */ _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* AAE8 */ _(C,x), _(C,x), _(C,x), _(M,L), _(M,B), _(M,T), _(M,L), _(M,R), + /* AAF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(Vs,x), _(V,I), _(x,x), + /* AAF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0xabc0 3792 + + + /* Meetei Mayek (ABC0..ABFF) */ + + /* ABC0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* ABC8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(VI,x), _(VI,x), + /* ABD0 */ _(C,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* ABD8 */ _(C,x), _(C,x), _(C,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), _(CF,x), + /* ABE0 */ _(CF,x), _(CF,x), _(CF,x), _(M,R), _(M,R), _(M,T), _(M,R), _(M,R), + /* ABE8 */ _(M,B), _(M,R), _(M,R), _(x,x), _(TM,x), _(V,B), _(x,x), _(x,x), + /* ABF0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* ABF8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x10a00 3856 + + + /* Kharoshthi (10A00..10A5F) */ + + /* 10A00 */ _(C,x), _(M,O), _(M,B), _(M,B), _(x,x), _(M,T), _(M,O), _(x,x), + /* 10A08 */ _(x,x), _(x,x), _(x,x), _(x,x), _(M,B), _(x,x), _(Bi,x), _(Vs,x), + /* 10A10 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(C,x), _(C,x), _(C,x), + /* 10A18 */ _(x,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 10A20 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 10A28 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 10A30 */ _(C,x), _(C,x), _(C,x), _(C,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 10A38 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(V,I), + /* 10A40 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 10A48 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 10A50 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 10A58 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x11000 3952 + + + /* Brahmi (11000..1107F) */ + + /* 11000 */ _(Bi,x), _(Bi,x), _(Vs,x), _(x,x), _(x,x), _(VI,x), _(VI,x), _(VI,x), + /* 11008 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 11010 */ _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11018 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11020 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11028 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11030 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11038 */ _(M,T), _(M,T), _(M,T), _(M,T), _(M,B), _(M,B), _(M,B), _(M,B), + /* 11040 */ _(M,B), _(M,B), _(M,T), _(M,T), _(M,T), _(M,T), _(V,T), _(x,x), + /* 11048 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11050 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11058 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11060 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11068 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11070 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11078 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + + /* Kaithi (11080..110CF) */ + + /* 11080 */ _(Bi,x), _(Bi,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 11088 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), + /* 11090 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11098 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 110A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 110A8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 110B0 */ _(M,R), _(M,L), _(M,R), _(M,B), _(M,B), _(M,T), _(M,T), _(M,R), + /* 110B8 */ _(M,R), _(V,B), _(N,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 110C0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 110C8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x11100 4160 + + + /* Chakma (11100..1114F) */ + + /* 11100 */ _(Bi,x), _(Bi,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(C,x), + /* 11108 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11110 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11118 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11120 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(M,T), + /* 11128 */ _(M,T), _(M,T), _(M,B), _(M,B), _(M,L), _(M,T), _(M,TB), _(M,TB), + /* 11130 */ _(M,T), _(M,B), _(M,B), _(V,I), _(V,T), _(x,x), _(x,x), _(x,x), + /* 11138 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11140 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 11148 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x11180 4240 + + + /* Sharada (11180..111DF) */ + + /* 11180 */ _(Bi,x), _(Bi,x), _(Vs,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 11188 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 11190 */ _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11198 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 111A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 111A8 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 111B0 */ _(C,x), _(C,x), _(C,x), _(M,R), _(M,L), _(M,R), _(M,B), _(M,B), + /* 111B8 */ _(M,B), _(M,B), _(M,B), _(M,B), _(M,T), _(M,T), _(M,T), _(M,TR), + /* 111C0 */ _(V,R), _(A,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 111C8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 111D0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 111D8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_0x11680 4336 + + + /* Takri (11680..116CF) */ + + /* 11680 */ _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), _(VI,x), + /* 11688 */ _(VI,x), _(VI,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11690 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 11698 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 116A0 */ _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), _(C,x), + /* 116A8 */ _(C,x), _(C,x), _(C,x), _(Bi,x), _(Vs,x), _(M,T), _(M,L), _(M,R), + /* 116B0 */ _(M,B), _(M,B), _(M,T), _(M,T), _(M,T), _(M,T), _(V,T), _(N,x), + /* 116B8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 116C0 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + /* 116C8 */ _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), _(x,x), + +#define indic_offset_total 4416 + +}; /* Table occupancy: 60% */ + +static INDIC_TABLE_ELEMENT_TYPE +get_indic_categories (hb_codepoint_t u) +{ + if (0x0900 <= u && u <= 0x10A0) return indic_table[u - 0x0900 + indic_offset_0x0900]; + if (0x1700 <= u && u <= 0x1800) return indic_table[u - 0x1700 + indic_offset_0x1700]; + if (0x1900 <= u && u <= 0x1AB0) return indic_table[u - 0x1900 + indic_offset_0x1900]; + if (0x1B00 <= u && u <= 0x1C50) return indic_table[u - 0x1B00 + indic_offset_0x1b00]; + if (0x1CD0 <= u && u <= 0x1D00) return indic_table[u - 0x1CD0 + indic_offset_0x1cd0]; + if (0xA800 <= u && u <= 0xAB00) return indic_table[u - 0xA800 + indic_offset_0xa800]; + if (0xABC0 <= u && u <= 0xAC00) return indic_table[u - 0xABC0 + indic_offset_0xabc0]; + if (0x10A00 <= u && u <= 0x10A60) return indic_table[u - 0x10A00 + indic_offset_0x10a00]; + if (0x11000 <= u && u <= 0x110D0) return indic_table[u - 0x11000 + indic_offset_0x11000]; + if (0x11100 <= u && u <= 0x11150) return indic_table[u - 0x11100 + indic_offset_0x11100]; + if (0x11180 <= u && u <= 0x111E0) return indic_table[u - 0x11180 + indic_offset_0x11180]; + if (0x11680 <= u && u <= 0x116D0) return indic_table[u - 0x11680 + indic_offset_0x11680]; + if (unlikely (u == 0x00A0)) return _(CP,x); + if (unlikely (u == 0x25CC)) return _(CP,x); + return _(x,x); +} + +#undef _ + +#undef ISC_A +#undef ISC_Bi +#undef ISC_C +#undef ISC_CD +#undef ISC_CF +#undef ISC_CHL +#undef ISC_CM +#undef ISC_CP +#undef ISC_CR +#undef ISC_CS +#undef ISC_ML +#undef ISC_N +#undef ISC_x +#undef ISC_RS +#undef ISC_TL +#undef ISC_TM +#undef ISC_V +#undef ISC_Vs +#undef ISC_Vo +#undef ISC_M +#undef ISC_VI + +#undef IMC_B +#undef IMC_BR +#undef IMC_I +#undef IMC_L +#undef IMC_LR +#undef IMC_x +#undef IMC_O +#undef IMC_R +#undef IMC_T +#undef IMC_TB +#undef IMC_TBR +#undef IMC_TL +#undef IMC_TLR +#undef IMC_TR +#undef IMC_VOL + +#endif /* HB_OT_SHAPE_COMPLEX_INDIC_TABLE_HH */ + +/* == End of generated table == */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic.cc new file mode 100644 index 00000000000..1bc8a773e31 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-indic.cc @@ -0,0 +1,1413 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-complex-indic-private.hh" +#include "hb-ot-layout-private.hh" + + +/* + * Global Indic shaper options. + */ + +struct indic_options_t +{ + int initialized : 1; + int uniscribe_bug_compatible : 1; +}; + +union indic_options_union_t { + int i; + indic_options_t opts; +}; +ASSERT_STATIC (sizeof (int) == sizeof (indic_options_union_t)); + +static indic_options_union_t +indic_options_init (void) +{ + indic_options_union_t u; + u.i = 0; + u.opts.initialized = 1; + + char *c = getenv ("HB_OT_INDIC_OPTIONS"); + u.opts.uniscribe_bug_compatible = c && strstr (c, "uniscribe-bug-compatible"); + + return u; +} + +static inline indic_options_t +indic_options (void) +{ + static indic_options_union_t options; + + if (unlikely (!options.i)) { + /* This is idempotent and threadsafe. */ + options = indic_options_init (); + } + + return options.opts; +} + + +/* + * Indic configurations. Note that we do not want to keep every single script-specific + * behavior in these tables necessarily. This should mainly be used for per-script + * properties that are cheaper keeping here, than in the code. Ie. if, say, one and + * only one script has an exception, that one script can be if'ed directly in the code, + * instead of adding a new flag in these structs. + */ + +enum base_position_t { + BASE_POS_FIRST, + BASE_POS_LAST +}; +enum reph_position_t { + REPH_POS_DEFAULT = POS_BEFORE_POST, + + REPH_POS_AFTER_MAIN = POS_AFTER_MAIN, + REPH_POS_BEFORE_SUB = POS_BEFORE_SUB, + REPH_POS_AFTER_SUB = POS_AFTER_SUB, + REPH_POS_BEFORE_POST = POS_BEFORE_POST, + REPH_POS_AFTER_POST = POS_AFTER_POST +}; +enum reph_mode_t { + REPH_MODE_IMPLICIT, /* Reph formed out of initial Ra,H sequence. */ + REPH_MODE_EXPLICIT, /* Reph formed out of initial Ra,H,ZWJ sequence. */ + REPH_MODE_VIS_REPHA, /* Encoded Repha character, no reordering needed. */ + REPH_MODE_LOG_REPHA /* Encoded Repha character, needs reordering. */ +}; +struct indic_config_t +{ + hb_script_t script; + bool has_old_spec; + hb_codepoint_t virama; + base_position_t base_pos; + reph_position_t reph_pos; + reph_mode_t reph_mode; +}; + +static const indic_config_t indic_configs[] = +{ + /* Default. Should be first. */ + {HB_SCRIPT_INVALID, false, 0,BASE_POS_LAST, REPH_POS_DEFAULT, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_DEVANAGARI,true, 0x094D,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT}, + {HB_SCRIPT_BENGALI, true, 0x09CD,BASE_POS_LAST, REPH_POS_AFTER_SUB, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_GURMUKHI, true, 0x0A4D,BASE_POS_LAST, REPH_POS_BEFORE_SUB, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_GUJARATI, true, 0x0ACD,BASE_POS_LAST, REPH_POS_BEFORE_POST,REPH_MODE_IMPLICIT}, + {HB_SCRIPT_ORIYA, true, 0x0B4D,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_TAMIL, true, 0x0BCD,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_TELUGU, true, 0x0C4D,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_EXPLICIT}, + {HB_SCRIPT_KANNADA, true, 0x0CCD,BASE_POS_LAST, REPH_POS_AFTER_POST, REPH_MODE_IMPLICIT}, + {HB_SCRIPT_MALAYALAM, true, 0x0D4D,BASE_POS_LAST, REPH_POS_AFTER_MAIN, REPH_MODE_LOG_REPHA}, + {HB_SCRIPT_SINHALA, false,0x0DCA,BASE_POS_FIRST,REPH_POS_AFTER_MAIN, REPH_MODE_EXPLICIT}, + {HB_SCRIPT_KHMER, false,0x17D2,BASE_POS_FIRST,REPH_POS_DEFAULT, REPH_MODE_VIS_REPHA}, + /* Myanmar does not have the "old_indic" behavior, even though it has a "new" tag. */ + {HB_SCRIPT_MYANMAR, false,0x1039,BASE_POS_LAST, REPH_POS_DEFAULT, REPH_MODE_EXPLICIT}, +}; + + + +/* + * Indic shaper. + */ + +struct feature_list_t { + hb_tag_t tag; + hb_bool_t is_global; +}; + +static const feature_list_t +indic_features[] = +{ + /* + * Basic features. + * These features are applied in order, one at a time, after initial_reordering. + */ + {HB_TAG('n','u','k','t'), true}, + {HB_TAG('a','k','h','n'), true}, + {HB_TAG('r','p','h','f'), false}, + {HB_TAG('r','k','r','f'), true}, + {HB_TAG('p','r','e','f'), false}, + {HB_TAG('h','a','l','f'), false}, + {HB_TAG('b','l','w','f'), false}, + {HB_TAG('a','b','v','f'), false}, + {HB_TAG('p','s','t','f'), false}, + {HB_TAG('c','f','a','r'), false}, + {HB_TAG('c','j','c','t'), true}, + {HB_TAG('v','a','t','u'), true}, + /* + * Other features. + * These features are applied all at once, after final_reordering. + */ + {HB_TAG('i','n','i','t'), false}, + {HB_TAG('p','r','e','s'), true}, + {HB_TAG('a','b','v','s'), true}, + {HB_TAG('b','l','w','s'), true}, + {HB_TAG('p','s','t','s'), true}, + {HB_TAG('h','a','l','n'), true}, + /* Positioning features, though we don't care about the types. */ + {HB_TAG('d','i','s','t'), true}, + {HB_TAG('a','b','v','m'), true}, + {HB_TAG('b','l','w','m'), true}, +}; + +/* + * Must be in the same order as the indic_features array. + */ +enum { + _NUKT, + _AKHN, + RPHF, + _RKRF, + PREF, + HALF, + BLWF, + ABVF, + PSTF, + CFAR, + _CJCT, + _VATU, + + INIT, + _PRES, + _ABVS, + _BLWS, + _PSTS, + _HALN, + _DIST, + _ABVM, + _BLWM, + + INDIC_NUM_FEATURES, + INDIC_BASIC_FEATURES = INIT /* Don't forget to update this! */ +}; + +static void +setup_syllables (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); +static void +initial_reordering (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); +static void +final_reordering (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); + +static void +collect_features_indic (hb_ot_shape_planner_t *plan) +{ + hb_ot_map_builder_t *map = &plan->map; + + /* Do this before any lookups have been applied. */ + map->add_gsub_pause (setup_syllables); + + map->add_bool_feature (HB_TAG('l','o','c','l')); + /* The Indic specs do not require ccmp, but we apply it here since if + * there is a use of it, it's typically at the beginning. */ + map->add_bool_feature (HB_TAG('c','c','m','p')); + + + unsigned int i = 0; + map->add_gsub_pause (initial_reordering); + for (; i < INDIC_BASIC_FEATURES; i++) { + map->add_bool_feature (indic_features[i].tag, indic_features[i].is_global); + map->add_gsub_pause (NULL); + } + map->add_gsub_pause (final_reordering); + for (; i < INDIC_NUM_FEATURES; i++) { + map->add_bool_feature (indic_features[i].tag, indic_features[i].is_global); + } +} + +static void +override_features_indic (hb_ot_shape_planner_t *plan) +{ + /* Uniscribe does not apply 'kern'. */ + if (indic_options ().uniscribe_bug_compatible) + plan->map.add_feature (HB_TAG('k','e','r','n'), 0, true); + + plan->map.add_feature (HB_TAG('l','i','g','a'), 0, true); +} + + +struct would_substitute_feature_t +{ + inline void init (const hb_ot_map_t *map, hb_tag_t feature_tag) + { + map->get_stage_lookups (0/*GSUB*/, + map->get_feature_stage (0/*GSUB*/, feature_tag), + &lookups, &count); + } + + inline bool would_substitute (hb_codepoint_t *glyphs, + unsigned int glyphs_count, + bool zero_context, + hb_face_t *face) const + { + for (unsigned int i = 0; i < count; i++) + if (hb_ot_layout_lookup_would_substitute_fast (face, lookups[i].index, glyphs, glyphs_count, zero_context)) + return true; + return false; + } + + private: + const hb_ot_map_t::lookup_map_t *lookups; + unsigned int count; +}; + +struct indic_shape_plan_t +{ + ASSERT_POD (); + + inline bool get_virama_glyph (hb_font_t *font, hb_codepoint_t *pglyph) const + { + hb_codepoint_t glyph = virama_glyph; + if (unlikely (virama_glyph == (hb_codepoint_t) -1)) + { + if (!config->virama || !font->get_glyph (config->virama, 0, &glyph)) + glyph = 0; + /* Technically speaking, the spec says we should apply 'locl' to virama too. + * Maybe one day... */ + + /* Our get_glyph() function needs a font, so we can't get the virama glyph + * during shape planning... Instead, overwrite it here. It's safe. Don't worry! */ + (const_cast<indic_shape_plan_t *> (this))->virama_glyph = glyph; + } + + *pglyph = glyph; + return glyph != 0; + } + + const indic_config_t *config; + + bool is_old_spec; + hb_codepoint_t virama_glyph; + + would_substitute_feature_t rphf; + would_substitute_feature_t pref; + would_substitute_feature_t blwf; + would_substitute_feature_t pstf; + + hb_mask_t mask_array[INDIC_NUM_FEATURES]; +}; + +static void * +data_create_indic (const hb_ot_shape_plan_t *plan) +{ + indic_shape_plan_t *indic_plan = (indic_shape_plan_t *) calloc (1, sizeof (indic_shape_plan_t)); + if (unlikely (!indic_plan)) + return NULL; + + indic_plan->config = &indic_configs[0]; + for (unsigned int i = 1; i < ARRAY_LENGTH (indic_configs); i++) + if (plan->props.script == indic_configs[i].script) { + indic_plan->config = &indic_configs[i]; + break; + } + + indic_plan->is_old_spec = indic_plan->config->has_old_spec && ((plan->map.chosen_script[0] & 0x000000FF) != '2'); + indic_plan->virama_glyph = (hb_codepoint_t) -1; + + indic_plan->rphf.init (&plan->map, HB_TAG('r','p','h','f')); + indic_plan->pref.init (&plan->map, HB_TAG('p','r','e','f')); + indic_plan->blwf.init (&plan->map, HB_TAG('b','l','w','f')); + indic_plan->pstf.init (&plan->map, HB_TAG('p','s','t','f')); + + for (unsigned int i = 0; i < ARRAY_LENGTH (indic_plan->mask_array); i++) + indic_plan->mask_array[i] = indic_features[i].is_global ? 0 : plan->map.get_1_mask (indic_features[i].tag); + + return indic_plan; +} + +static void +data_destroy_indic (void *data) +{ + free (data); +} + +static indic_position_t +consonant_position_from_face (const indic_shape_plan_t *indic_plan, + hb_codepoint_t *glyphs, unsigned int glyphs_len, + hb_face_t *face) +{ + bool zero_context = indic_plan->is_old_spec ? false : true; + if (indic_plan->pref.would_substitute (glyphs, glyphs_len, zero_context, face)) return POS_BELOW_C; + if (indic_plan->blwf.would_substitute (glyphs, glyphs_len, zero_context, face)) return POS_BELOW_C; + if (indic_plan->pstf.would_substitute (glyphs, glyphs_len, zero_context, face)) return POS_POST_C; + return POS_BASE_C; +} + + +enum syllable_type_t { + consonant_syllable, + vowel_syllable, + standalone_cluster, + broken_cluster, + non_indic_cluster, +}; + +#include "hb-ot-shape-complex-indic-machine.hh" + + +static void +setup_masks_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_buffer_t *buffer, + hb_font_t *font HB_UNUSED) +{ + HB_BUFFER_ALLOCATE_VAR (buffer, indic_category); + HB_BUFFER_ALLOCATE_VAR (buffer, indic_position); + + /* We cannot setup masks here. We save information about characters + * and setup masks later on in a pause-callback. */ + + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + set_indic_properties (buffer->info[i]); +} + +static void +setup_syllables (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_font_t *font HB_UNUSED, + hb_buffer_t *buffer) +{ + find_syllables (buffer); +} + +static int +compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) +{ + int a = pa->indic_position(); + int b = pb->indic_position(); + + return a < b ? -1 : a == b ? 0 : +1; +} + + + +static void +update_consonant_positions (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer) +{ + const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; + + unsigned int consonant_pos = indic_plan->is_old_spec ? 0 : 1; + hb_codepoint_t glyphs[2]; + if (indic_plan->get_virama_glyph (font, &glyphs[1 - consonant_pos])) + { + hb_face_t *face = font->face; + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + if (buffer->info[i].indic_position() == POS_BASE_C) { + glyphs[consonant_pos] = buffer->info[i].codepoint; + buffer->info[i].indic_position() = consonant_position_from_face (indic_plan, glyphs, 2, face); + } + } +} + + +/* Rules from: + * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ + +static void +initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, + hb_face_t *face, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; + hb_glyph_info_t *info = buffer->info; + + + /* 1. Find base consonant: + * + * The shaping engine finds the base consonant of the syllable, using the + * following algorithm: starting from the end of the syllable, move backwards + * until a consonant is found that does not have a below-base or post-base + * form (post-base forms have to follow below-base forms), or that is not a + * pre-base reordering Ra, or arrive at the first consonant. The consonant + * stopped at will be the base. + * + * o If the syllable starts with Ra + Halant (in a script that has Reph) + * and has more than one consonant, Ra is excluded from candidates for + * base consonants. + */ + + unsigned int base = end; + bool has_reph = false; + + { + /* -> If the syllable starts with Ra + Halant (in a script that has Reph) + * and has more than one consonant, Ra is excluded from candidates for + * base consonants. */ + unsigned int limit = start; + if (indic_plan->mask_array[RPHF] && + start + 3 <= end && + ( + (indic_plan->config->reph_mode == REPH_MODE_IMPLICIT && !is_joiner (info[start + 2])) || + (indic_plan->config->reph_mode == REPH_MODE_EXPLICIT && info[start + 2].indic_category() == OT_ZWJ) + )) + { + /* See if it matches the 'rphf' feature. */ + hb_codepoint_t glyphs[2] = {info[start].codepoint, info[start + 1].codepoint}; + if (indic_plan->rphf.would_substitute (glyphs, ARRAY_LENGTH (glyphs), true, face)) + { + limit += 2; + while (limit < end && is_joiner (info[limit])) + limit++; + base = start; + has_reph = true; + } + } else if (indic_plan->config->reph_mode == REPH_MODE_LOG_REPHA && info[start].indic_category() == OT_Repha) + { + limit += 1; + while (limit < end && is_joiner (info[limit])) + limit++; + base = start; + has_reph = true; + } + + switch (indic_plan->config->base_pos) + { + default: + assert (false); + /* fallthrough */ + + case BASE_POS_LAST: + { + /* -> starting from the end of the syllable, move backwards */ + unsigned int i = end; + bool seen_below = false; + do { + i--; + /* -> until a consonant is found */ + if (is_consonant (info[i])) + { + /* -> that does not have a below-base or post-base form + * (post-base forms have to follow below-base forms), */ + if (info[i].indic_position() != POS_BELOW_C && + (info[i].indic_position() != POS_POST_C || seen_below)) + { + base = i; + break; + } + if (info[i].indic_position() == POS_BELOW_C) + seen_below = true; + + /* -> or that is not a pre-base reordering Ra, + * + * IMPLEMENTATION NOTES: + * + * Our pre-base reordering Ra's are marked POS_BELOW, so will be skipped + * by the logic above already. + */ + + /* -> or arrive at the first consonant. The consonant stopped at will + * be the base. */ + base = i; + } + else + { + /* A ZWJ after a Halant stops the base search, and requests an explicit + * half form. + * A ZWJ before a Halant, requests a subjoined form instead, and hence + * search continues. This is particularly important for Bengali + * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya. */ + if (start < i && + info[i].indic_category() == OT_ZWJ && + info[i - 1].indic_category() == OT_H) + break; + } + } while (i > limit); + } + break; + + case BASE_POS_FIRST: + { + /* In scripts without half forms (eg. Khmer), the first consonant is always the base. */ + + if (!has_reph) + base = limit; + + /* Find the last base consonant that is not blocked by ZWJ. If there is + * a ZWJ right before a base consonant, that would request a subjoined form. */ + for (unsigned int i = limit; i < end; i++) + if (is_consonant (info[i]) && info[i].indic_position() == POS_BASE_C) + { + if (limit < i && info[i - 1].indic_category() == OT_ZWJ) + break; + else + base = i; + } + + /* Mark all subsequent consonants as below. */ + for (unsigned int i = base + 1; i < end; i++) + if (is_consonant (info[i]) && info[i].indic_position() == POS_BASE_C) + info[i].indic_position() = POS_BELOW_C; + } + break; + } + + /* -> If the syllable starts with Ra + Halant (in a script that has Reph) + * and has more than one consonant, Ra is excluded from candidates for + * base consonants. + * + * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */ + if (has_reph && base == start && start - limit <= 2) { + /* Have no other consonant, so Reph is not formed and Ra becomes base. */ + has_reph = false; + } + } + + if (base < end) + info[base].indic_position() = POS_BASE_C; + + + /* 2. Decompose and reorder Matras: + * + * Each matra and any syllable modifier sign in the cluster are moved to the + * appropriate position relative to the consonant(s) in the cluster. The + * shaping engine decomposes two- or three-part matras into their constituent + * parts before any repositioning. Matra characters are classified by which + * consonant in a conjunct they have affinity for and are reordered to the + * following positions: + * + * o Before first half form in the syllable + * o After subjoined consonants + * o After post-form consonant + * o After main consonant (for above marks) + * + * IMPLEMENTATION NOTES: + * + * The normalize() routine has already decomposed matras for us, so we don't + * need to worry about that. + */ + + + /* 3. Reorder marks to canonical order: + * + * Adjacent nukta and halant or nukta and vedic sign are always repositioned + * if necessary, so that the nukta is first. + * + * IMPLEMENTATION NOTES: + * + * We don't need to do this: the normalize() routine already did this for us. + */ + + + /* Reorder characters */ + + for (unsigned int i = start; i < base; i++) + info[i].indic_position() = MIN (POS_PRE_C, (indic_position_t) info[i].indic_position()); + + if (base < end) + info[base].indic_position() = POS_BASE_C; + + /* Mark final consonants. A final consonant is one appearing after a matra, + * like in Khmer. */ + for (unsigned int i = base + 1; i < end; i++) + if (info[i].indic_category() == OT_M) { + for (unsigned int j = i + 1; j < end; j++) + if (is_consonant (info[j])) { + info[j].indic_position() = POS_FINAL_C; + break; + } + break; + } + + /* Handle beginning Ra */ + if (has_reph) + info[start].indic_position() = POS_RA_TO_BECOME_REPH; + + /* For old-style Indic script tags, move the first post-base Halant after + * last consonant. */ + if (indic_plan->is_old_spec) { + for (unsigned int i = base + 1; i < end; i++) + if (info[i].indic_category() == OT_H) { + unsigned int j; + for (j = end - 1; j > i; j--) + if (is_consonant (info[j])) + break; + if (j > i) { + /* Move Halant to after last consonant. */ + hb_glyph_info_t t = info[i]; + memmove (&info[i], &info[i + 1], (j - i) * sizeof (info[0])); + info[j] = t; + } + break; + } + } + + /* Attach misc marks to previous char to move with them. */ + { + indic_position_t last_pos = POS_START; + for (unsigned int i = start; i < end; i++) + { + if ((FLAG (info[i].indic_category()) & (JOINER_FLAGS | FLAG (OT_N) | FLAG (OT_RS) | HALANT_OR_COENG_FLAGS))) + { + info[i].indic_position() = last_pos; + if (unlikely (info[i].indic_category() == OT_H && + info[i].indic_position() == POS_PRE_M)) + { + /* + * Uniscribe doesn't move the Halant with Left Matra. + * TEST: U+092B,U+093F,U+094DE + * We follow. This is important for the Sinhala + * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA + * where U+0DD9 is a left matra and U+0DCA is the virama. + * We don't want to move the virama with the left matra. + * TEST: U+0D9A,U+0DDA + */ + for (unsigned int j = i; j > start; j--) + if (info[j - 1].indic_position() != POS_PRE_M) { + info[i].indic_position() = info[j - 1].indic_position(); + break; + } + } + } else if (info[i].indic_position() != POS_SMVD) { + last_pos = (indic_position_t) info[i].indic_position(); + } + } + } + /* Re-attach ZWJ, ZWNJ, and halant to next char, for after-base consonants. */ + { + unsigned int last_halant = end; + for (unsigned int i = base + 1; i < end; i++) + if (is_halant_or_coeng (info[i])) + last_halant = i; + else if (is_consonant (info[i])) { + for (unsigned int j = last_halant; j < i; j++) + if (info[j].indic_position() != POS_SMVD) + info[j].indic_position() = info[i].indic_position(); + } + } + + { + /* Things are out-of-control for post base positions, they may shuffle + * around like crazy, so merge clusters. For pre-base stuff, we handle + * cluster issues in final reordering. */ + buffer->merge_clusters (base, end); + /* Sit tight, rock 'n roll! */ + hb_bubble_sort (info + start, end - start, compare_indic_order); + /* Find base again */ + base = end; + for (unsigned int i = start; i < end; i++) + if (info[i].indic_position() == POS_BASE_C) { + base = i; + break; + } + } + + /* Setup masks now */ + + { + hb_mask_t mask; + + /* Reph */ + for (unsigned int i = start; i < end && info[i].indic_position() == POS_RA_TO_BECOME_REPH; i++) + info[i].mask |= indic_plan->mask_array[RPHF]; + + /* Pre-base */ + mask = indic_plan->mask_array[HALF]; + for (unsigned int i = start; i < base; i++) + info[i].mask |= mask; + /* Base */ + mask = 0; + if (base < end) + info[base].mask |= mask; + /* Post-base */ + mask = indic_plan->mask_array[BLWF] | indic_plan->mask_array[ABVF] | indic_plan->mask_array[PSTF]; + for (unsigned int i = base + 1; i < end; i++) + info[i].mask |= mask; + } + + if (indic_plan->mask_array[PREF] && base + 2 < end) + { + /* Find a Halant,Ra sequence and mark it for pre-base reordering processing. */ + for (unsigned int i = base + 1; i + 1 < end; i++) { + hb_codepoint_t glyphs[2] = {info[i].codepoint, info[i + 1].codepoint}; + if (indic_plan->pref.would_substitute (glyphs, ARRAY_LENGTH (glyphs), true, face)) + { + info[i++].mask |= indic_plan->mask_array[PREF]; + info[i++].mask |= indic_plan->mask_array[PREF]; + + /* Mark the subsequent stuff with 'cfar'. Used in Khmer. + * Read the feature spec. + * This allows distinguishing the following cases with MS Khmer fonts: + * U+1784,U+17D2,U+179A,U+17D2,U+1782 + * U+1784,U+17D2,U+1782,U+17D2,U+179A + */ + for (; i < end; i++) + info[i].mask |= indic_plan->mask_array[CFAR]; + + break; + } + } + } + + /* Apply ZWJ/ZWNJ effects */ + for (unsigned int i = start + 1; i < end; i++) + if (is_joiner (info[i])) { + bool non_joiner = info[i].indic_category() == OT_ZWNJ; + unsigned int j = i; + + do { + j--; + + /* A ZWJ disables CJCT, however, it's mere presence is enough + * to disable ligation. No explicit action needed. */ + + /* A ZWNJ disables HALF. */ + if (non_joiner) + info[j].mask &= ~indic_plan->mask_array[HALF]; + + } while (j > start && !is_consonant (info[j])); + } +} + + +static void +initial_reordering_vowel_syllable (const hb_ot_shape_plan_t *plan, + hb_face_t *face, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + /* We made the vowels look like consonants. So let's call the consonant logic! */ + initial_reordering_consonant_syllable (plan, face, buffer, start, end); +} + +static void +initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan, + hb_face_t *face, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + /* We treat NBSP/dotted-circle as if they are consonants, so we should just chain. + * Only if not in compatibility mode that is... */ + + if (indic_options ().uniscribe_bug_compatible) + { + /* For dotted-circle, this is what Uniscribe does: + * If dotted-circle is the last glyph, it just does nothing. + * Ie. It doesn't form Reph. */ + if (buffer->info[end - 1].indic_category() == OT_DOTTEDCIRCLE) + return; + } + + initial_reordering_consonant_syllable (plan, face, buffer, start, end); +} + +static void +initial_reordering_broken_cluster (const hb_ot_shape_plan_t *plan, + hb_face_t *face, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + /* We already inserted dotted-circles, so just call the standalone_cluster. */ + initial_reordering_standalone_cluster (plan, face, buffer, start, end); +} + +static void +initial_reordering_non_indic_cluster (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_face_t *face HB_UNUSED, + hb_buffer_t *buffer HB_UNUSED, + unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) +{ + /* Nothing to do right now. If we ever switch to using the output + * buffer in the reordering process, we'd need to next_glyph() here. */ +} + + +static void +initial_reordering_syllable (const hb_ot_shape_plan_t *plan, + hb_face_t *face, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + syllable_type_t syllable_type = (syllable_type_t) (buffer->info[start].syllable() & 0x0F); + switch (syllable_type) { + case consonant_syllable: initial_reordering_consonant_syllable (plan, face, buffer, start, end); return; + case vowel_syllable: initial_reordering_vowel_syllable (plan, face, buffer, start, end); return; + case standalone_cluster: initial_reordering_standalone_cluster (plan, face, buffer, start, end); return; + case broken_cluster: initial_reordering_broken_cluster (plan, face, buffer, start, end); return; + case non_indic_cluster: initial_reordering_non_indic_cluster (plan, face, buffer, start, end); return; + } +} + +static inline void +insert_dotted_circles (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_font_t *font, + hb_buffer_t *buffer) +{ + /* Note: This loop is extra overhead, but should not be measurable. */ + bool has_broken_syllables = false; + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + if ((buffer->info[i].syllable() & 0x0F) == broken_cluster) { + has_broken_syllables = true; + break; + } + if (likely (!has_broken_syllables)) + return; + + + hb_codepoint_t dottedcircle_glyph; + if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph)) + return; + + hb_glyph_info_t dottedcircle = {0}; + dottedcircle.codepoint = 0x25CC; + set_indic_properties (dottedcircle); + dottedcircle.codepoint = dottedcircle_glyph; + + buffer->clear_output (); + + buffer->idx = 0; + unsigned int last_syllable = 0; + while (buffer->idx < buffer->len) + { + unsigned int syllable = buffer->cur().syllable(); + syllable_type_t syllable_type = (syllable_type_t) (syllable & 0x0F); + if (unlikely (last_syllable != syllable && syllable_type == broken_cluster)) + { + last_syllable = syllable; + + hb_glyph_info_t info = dottedcircle; + info.cluster = buffer->cur().cluster; + info.mask = buffer->cur().mask; + info.syllable() = buffer->cur().syllable(); + + /* Insert dottedcircle after possible Repha. */ + while (buffer->idx < buffer->len && + last_syllable == buffer->cur().syllable() && + buffer->cur().indic_category() == OT_Repha) + buffer->next_glyph (); + + buffer->output_info (info); + } + else + buffer->next_glyph (); + } + + buffer->swap_buffers (); +} + +static void +initial_reordering (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer) +{ + update_consonant_positions (plan, font, buffer); + insert_dotted_circles (plan, font, buffer); + + hb_glyph_info_t *info = buffer->info; + unsigned int count = buffer->len; + if (unlikely (!count)) return; + unsigned int last = 0; + unsigned int last_syllable = info[0].syllable(); + for (unsigned int i = 1; i < count; i++) + if (last_syllable != info[i].syllable()) { + initial_reordering_syllable (plan, font->face, buffer, last, i); + last = i; + last_syllable = info[last].syllable(); + } + initial_reordering_syllable (plan, font->face, buffer, last, count); +} + +static void +final_reordering_syllable (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + unsigned int start, unsigned int end) +{ + const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) plan->data; + hb_glyph_info_t *info = buffer->info; + + /* 4. Final reordering: + * + * After the localized forms and basic shaping forms GSUB features have been + * applied (see below), the shaping engine performs some final glyph + * reordering before applying all the remaining font features to the entire + * cluster. + */ + + /* Find base again */ + unsigned int base; + for (base = start; base < end; base++) + if (info[base].indic_position() >= POS_BASE_C) { + if (start < base && info[base].indic_position() > POS_BASE_C) + base--; + break; + } + + + /* o Reorder matras: + * + * If a pre-base matra character had been reordered before applying basic + * features, the glyph can be moved closer to the main consonant based on + * whether half-forms had been formed. Actual position for the matra is + * 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. + */ + + if (start + 1 < end && start < base) /* Otherwise there can't be any pre-base matra characters. */ + { + /* If we lost track of base, alas, position before last thingy. */ + unsigned int new_pos = base == end ? base - 2 : base - 1; + + /* Malayalam / Tamil do not have "half" forms or explicit virama forms. + * The glyphs formed by 'half' are Chillus or ligated explicit viramas. + * We want to position matra after them. + */ + if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) + { + while (new_pos > start && + !(is_one_of (info[new_pos], (FLAG (OT_M) | FLAG (OT_H) | FLAG (OT_Coeng))))) + new_pos--; + + /* If we found no Halant we are done. + * Otherwise only proceed if the Halant does + * not belong to the Matra itself! */ + if (is_halant_or_coeng (info[new_pos]) && + info[new_pos].indic_position() != POS_PRE_M) + { + /* -> 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++; + } + else + new_pos = start; /* No move. */ + } + + if (start < new_pos && info[new_pos].indic_position () != POS_PRE_M) + { + /* Now go see if there's actually any matras... */ + for (unsigned int i = new_pos; i > start; i--) + if (info[i - 1].indic_position () == POS_PRE_M) + { + unsigned int old_pos = i - 1; + hb_glyph_info_t tmp = info[old_pos]; + memmove (&info[old_pos], &info[old_pos + 1], (new_pos - old_pos) * sizeof (info[0])); + info[new_pos] = tmp; + new_pos--; + } + buffer->merge_clusters (new_pos, MIN (end, base + 1)); + } else { + for (unsigned int i = start; i < base; i++) + if (info[i].indic_position () == POS_PRE_M) { + buffer->merge_clusters (i, MIN (end, base + 1)); + break; + } + } + } + + + /* o Reorder reph: + * + * Reph’s original position is always at the beginning of the syllable, + * (i.e. it is not reordered at the character reordering stage). However, + * it will be reordered according to the basic-forms shaping results. + * Possible positions for reph, depending on the script, are; after main, + * before post-base consonant forms, and after post-base consonant forms. + */ + + /* If there's anything after the Ra that has the REPH pos, it ought to be halant. + * Which means that the font has failed to ligate the Reph. In which case, we + * shouldn't move. */ + if (start + 1 < end && + info[start].indic_position() == POS_RA_TO_BECOME_REPH && + info[start + 1].indic_position() != POS_RA_TO_BECOME_REPH) + { + unsigned int new_reph_pos; + reph_position_t reph_pos = indic_plan->config->reph_pos; + + /* XXX Figure out old behavior too */ + + /* 1. If reph should be positioned after post-base consonant forms, + * proceed to step 5. + */ + if (reph_pos == REPH_POS_AFTER_POST) + { + goto reph_step_5; + } + + /* 2. If the reph repositioning class is not after post-base: target + * position is after the first explicit halant glyph between the + * first post-reph consonant and last main consonant. If ZWJ or ZWNJ + * are following this halant, position is moved after it. If such + * position is found, this is the target position. Otherwise, + * proceed to the next step. + * + * Note: in old-implementation fonts, where classifications were + * fixed in shaping engine, there was no case where reph position + * will be found on this step. + */ + { + new_reph_pos = start + 1; + while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) + new_reph_pos++; + + if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) { + /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ + if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) + new_reph_pos++; + goto reph_move; + } + } + + /* 3. If reph should be repositioned after the main consonant: find the + * first consonant not ligated with main, or find the first + * consonant that is not a potential pre-base reordering Ra. + */ + if (reph_pos == REPH_POS_AFTER_MAIN) + { + new_reph_pos = base; + /* XXX Skip potential pre-base reordering Ra. */ + while (new_reph_pos + 1 < end && info[new_reph_pos + 1].indic_position() <= POS_AFTER_MAIN) + new_reph_pos++; + if (new_reph_pos < end) + goto reph_move; + } + + /* 4. If reph should be positioned before post-base consonant, find + * first post-base classified consonant not ligated with main. If no + * consonant is found, the target position should be before the + * first matra, syllable modifier sign or vedic sign. + */ + /* This is our take on what step 4 is trying to say (and failing, BADLY). */ + if (reph_pos == REPH_POS_AFTER_SUB) + { + new_reph_pos = base; + while (new_reph_pos < end && + !( FLAG (info[new_reph_pos + 1].indic_position()) & (FLAG (POS_POST_C) | FLAG (POS_AFTER_POST) | FLAG (POS_SMVD)))) + new_reph_pos++; + if (new_reph_pos < end) + goto reph_move; + } + + /* 5. If no consonant is found in steps 3 or 4, move reph to a position + * immediately before the first post-base matra, syllable modifier + * sign or vedic sign that has a reordering class after the intended + * reph position. For example, if the reordering position for reph + * is post-main, it will skip above-base matras that also have a + * post-main position. + */ + reph_step_5: + { + /* Copied from step 2. */ + new_reph_pos = start + 1; + while (new_reph_pos < base && !is_halant_or_coeng (info[new_reph_pos])) + new_reph_pos++; + + if (new_reph_pos < base && is_halant_or_coeng (info[new_reph_pos])) { + /* ->If ZWJ or ZWNJ are following this halant, position is moved after it. */ + if (new_reph_pos + 1 < base && is_joiner (info[new_reph_pos + 1])) + new_reph_pos++; + goto reph_move; + } + } + + /* 6. Otherwise, reorder reph to the end of the syllable. + */ + { + new_reph_pos = end - 1; + while (new_reph_pos > start && info[new_reph_pos].indic_position() == POS_SMVD) + new_reph_pos--; + + /* + * If the Reph is to be ending up after a Matra,Halant sequence, + * position it before that Halant so it can interact with the Matra. + * However, if it's a plain Consonant,Halant we shouldn't do that. + * Uniscribe doesn't do this. + * TEST: U+0930,U+094D,U+0915,U+094B,U+094D + */ + if (!indic_options ().uniscribe_bug_compatible && + unlikely (is_halant_or_coeng (info[new_reph_pos]))) { + for (unsigned int i = base + 1; i < new_reph_pos; i++) + if (info[i].indic_category() == OT_M) { + /* Ok, got it. */ + new_reph_pos--; + } + } + goto reph_move; + } + + reph_move: + { + /* Yay, one big cluster! Merge before moving. */ + buffer->merge_clusters (start, end); + + /* Move */ + hb_glyph_info_t reph = info[start]; + memmove (&info[start], &info[start + 1], (new_reph_pos - start) * sizeof (info[0])); + info[new_reph_pos] = reph; + } + } + + + /* o Reorder pre-base reordering consonants: + * + * If a pre-base reordering consonant is found, reorder it according to + * the following rules: + */ + + if (indic_plan->mask_array[PREF] && base + 1 < end) /* Otherwise there can't be any pre-base reordering Ra. */ + { + for (unsigned int i = base + 1; i < end; i++) + if ((info[i].mask & indic_plan->mask_array[PREF]) != 0) + { + /* 1. Only reorder a glyph produced by substitution during application + * of the <pref> feature. (Note that a font may shape a Ra consonant with + * the feature generally but block it in certain contexts.) + */ + if (i + 1 == end || (info[i + 1].mask & indic_plan->mask_array[PREF]) == 0) + { + /* + * 2. Try to find a target position the same way as for pre-base matra. + * If it is found, reorder pre-base consonant glyph. + * + * 3. If position is not found, reorder immediately before main + * consonant. + */ + + unsigned int new_pos = base; + /* Malayalam / Tamil do not have "half" forms or explicit virama forms. + * The glyphs formed by 'half' are Chillus or ligated explicit viramas. + * We want to position matra after them. + */ + if (buffer->props.script != HB_SCRIPT_MALAYALAM && buffer->props.script != HB_SCRIPT_TAMIL) + { + while (new_pos > start && + !(is_one_of (info[new_pos - 1], FLAG(OT_M) | HALANT_OR_COENG_FLAGS))) + new_pos--; + + /* In Khmer coeng model, a V,Ra can go *after* matras. If it goes after a + * split matra, it should be reordered to *before* the left part of such matra. */ + if (new_pos > start && info[new_pos - 1].indic_category() == OT_M) + { + unsigned int old_pos = i; + for (unsigned int i = base + 1; i < old_pos; i++) + if (info[i].indic_category() == OT_M) + { + new_pos--; + break; + } + } + } + + if (new_pos > start && is_halant_or_coeng (info[new_pos - 1])) + /* -> If ZWJ or ZWNJ follow this halant, position is moved after it. */ + if (new_pos < end && is_joiner (info[new_pos])) + new_pos++; + + { + unsigned int old_pos = i; + buffer->merge_clusters (new_pos, old_pos + 1); + hb_glyph_info_t tmp = info[old_pos]; + memmove (&info[new_pos + 1], &info[new_pos], (old_pos - new_pos) * sizeof (info[0])); + info[new_pos] = tmp; + } + } + + break; + } + } + + + /* Apply 'init' to the Left Matra if it's a word start. */ + if (info[start].indic_position () == POS_PRE_M && + (!start || + !(FLAG (_hb_glyph_info_get_general_category (&info[start - 1])) & + FLAG_RANGE (HB_UNICODE_GENERAL_CATEGORY_FORMAT, HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))) + info[start].mask |= indic_plan->mask_array[INIT]; + + + /* + * Finish off the clusters and go home! + */ + if (indic_options ().uniscribe_bug_compatible) + { + /* Uniscribe merges the entire cluster. + * This means, half forms are submerged into the main consonants cluster. + * This is unnecessary, and makes cursor positioning harder, but that's what + * Uniscribe does. */ + buffer->merge_clusters (start, end); + } +} + + +static void +final_reordering (const hb_ot_shape_plan_t *plan, + hb_font_t *font HB_UNUSED, + hb_buffer_t *buffer) +{ + unsigned int count = buffer->len; + if (unlikely (!count)) return; + + hb_glyph_info_t *info = buffer->info; + unsigned int last = 0; + unsigned int last_syllable = info[0].syllable(); + for (unsigned int i = 1; i < count; i++) + if (last_syllable != info[i].syllable()) { + final_reordering_syllable (plan, buffer, last, i); + last = i; + last_syllable = info[last].syllable(); + } + final_reordering_syllable (plan, buffer, last, count); + + /* Zero syllables now... */ + for (unsigned int i = 0; i < count; i++) + info[i].syllable() = 0; + + HB_BUFFER_DEALLOCATE_VAR (buffer, indic_category); + HB_BUFFER_DEALLOCATE_VAR (buffer, indic_position); +} + + +static hb_ot_shape_normalization_mode_t +normalization_preference_indic (const hb_segment_properties_t *props HB_UNUSED) +{ + return HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT; +} + +static bool +decompose_indic (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b) +{ + switch (ab) + { + /* Don't decompose these. */ + case 0x0931 : return false; + case 0x0B94 : return false; + + + /* + * Decompose split matras that don't have Unicode decompositions. + */ + + case 0x0F77 : *a = 0x0FB2; *b= 0x0F81; return true; + case 0x0F79 : *a = 0x0FB3; *b= 0x0F81; return true; + case 0x17BE : *a = 0x17C1; *b= 0x17BE; return true; + case 0x17BF : *a = 0x17C1; *b= 0x17BF; return true; + case 0x17C0 : *a = 0x17C1; *b= 0x17C0; return true; + case 0x17C4 : *a = 0x17C1; *b= 0x17C4; return true; + case 0x17C5 : *a = 0x17C1; *b= 0x17C5; return true; + case 0x1925 : *a = 0x1920; *b= 0x1923; return true; + case 0x1926 : *a = 0x1920; *b= 0x1924; return true; + case 0x1B3C : *a = 0x1B42; *b= 0x1B3C; return true; + case 0x1112E : *a = 0x11127; *b= 0x11131; return true; + case 0x1112F : *a = 0x11127; *b= 0x11132; return true; +#if 0 + /* This one has no decomposition in Unicode, but needs no decomposition either. */ + /* case 0x0AC9 : return false; */ + case 0x0B57 : *a = no decomp, -> RIGHT; return true; + case 0x1C29 : *a = no decomp, -> LEFT; return true; + case 0xA9C0 : *a = no decomp, -> RIGHT; return true; + case 0x111BF : *a = no decomp, -> ABOVE; return true; +#endif + } + + if ((ab == 0x0DDA || hb_in_range<hb_codepoint_t> (ab, 0x0DDC, 0x0DDE))) + { + /* + * Sinhala split matras... Let the fun begin. + * + * These four characters have Unicode decompositions. However, Uniscribe + * decomposes them "Khmer-style", that is, it uses the character itself to + * get the second half. The first half of all four decompositions is always + * U+0DD9. + * + * Now, there are buggy fonts, namely, the widely used lklug.ttf, that are + * broken with Uniscribe. But we need to support them. As such, we only + * do the Uniscribe-style decomposition if the character is transformed into + * its "sec.half" form by the 'pstf' feature. Otherwise, we fall back to + * Unicode decomposition. + * + * Note that we can't unconditionally use Unicode decomposition. That would + * break some other fonts, that are designed to work with Uniscribe, and + * don't have positioning features for the Unicode-style decomposition. + * + * Argh... + * + * The Uniscribe behavior is now documented in the newly published Sinhala + * spec in 2012: + * + * http://www.microsoft.com/typography/OpenTypeDev/sinhala/intro.htm#shaping + */ + + const indic_shape_plan_t *indic_plan = (const indic_shape_plan_t *) c->plan->data; + + hb_codepoint_t glyph; + + if (indic_options ().uniscribe_bug_compatible || + (c->font->get_glyph (ab, 0, &glyph) && + indic_plan->pstf.would_substitute (&glyph, 1, true, c->font->face))) + { + /* Ok, safe to use Uniscribe-style decomposition. */ + *a = 0x0DD9; + *b = ab; + return true; + } + } + + return c->unicode->decompose (ab, a, b); +} + +static bool +compose_indic (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab) +{ + /* Avoid recomposing split matras. */ + if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (c->unicode->general_category (a))) + return false; + + /* Composition-exclusion exceptions that we want to recompose. */ + if (a == 0x09AF && b == 0x09BC) { *ab = 0x09DF; return true; } + + return c->unicode->compose (a, b, ab); +} + + +const hb_ot_complex_shaper_t _hb_ot_complex_shaper_indic = +{ + "indic", + collect_features_indic, + override_features_indic, + data_create_indic, + data_destroy_indic, + NULL, /* preprocess_text */ + normalization_preference_indic, + decompose_indic, + compose_indic, + setup_masks_indic, + false, /* zero_width_attached_marks */ + false, /* fallback_position */ +}; diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-private.hh new file mode 100644 index 00000000000..26871c2fc09 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-private.hh @@ -0,0 +1,313 @@ +/* + * Copyright © 2010,2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_COMPLEX_PRIVATE_HH +#define HB_OT_SHAPE_COMPLEX_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-ot-shape-private.hh" +#include "hb-ot-shape-normalize-private.hh" + + + +/* buffer var allocations, used by complex shapers */ +#define complex_var_u8_0() var2.u8[2] +#define complex_var_u8_1() var2.u8[3] + + + +/* Master OT shaper list */ +#define HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS \ + HB_COMPLEX_SHAPER_IMPLEMENT (default) /* should be first */ \ + HB_COMPLEX_SHAPER_IMPLEMENT (arabic) \ + HB_COMPLEX_SHAPER_IMPLEMENT (indic) \ + HB_COMPLEX_SHAPER_IMPLEMENT (thai) \ + /* ^--- Add new shapers here */ + + +struct hb_ot_complex_shaper_t +{ + char name[8]; + + /* collect_features() + * Called during shape_plan(). + * Shapers should use plan->map to add their features and callbacks. + * May be NULL. + */ + void (*collect_features) (hb_ot_shape_planner_t *plan); + + /* override_features() + * Called during shape_plan(). + * Shapers should use plan->map to override features and add callbacks after + * common features are added. + * May be NULL. + */ + void (*override_features) (hb_ot_shape_planner_t *plan); + + + /* data_create() + * Called at the end of shape_plan(). + * Whatever shapers return will be accessible through plan->data later. + * If NULL is returned, means a plan failure. + */ + void *(*data_create) (const hb_ot_shape_plan_t *plan); + + /* data_destroy() + * Called when the shape_plan is being destroyed. + * plan->data is passed here for destruction. + * If NULL is returned, means a plan failure. + * May be NULL. + */ + void (*data_destroy) (void *data); + + + /* preprocess_text() + * Called during shape(). + * Shapers can use to modify text before shaping starts. + * May be NULL. + */ + void (*preprocess_text) (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + hb_font_t *font); + + + /* normalization_preference() + * Called during shape(). + * May be NULL. + */ + hb_ot_shape_normalization_mode_t + (*normalization_preference) (const hb_segment_properties_t *props); + + /* decompose() + * Called during shape()'s normalization. + * May be NULL. + */ + bool (*decompose) (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b); + + /* compose() + * Called during shape()'s normalization. + * May be NULL. + */ + bool (*compose) (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab); + + /* setup_masks() + * Called during shape(). + * Shapers should use map to get feature masks and set on buffer. + * Shapers may NOT modify characters. + * May be NULL. + */ + void (*setup_masks) (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + hb_font_t *font); + + bool zero_width_attached_marks; + bool fallback_position; +}; + +#define HB_COMPLEX_SHAPER_IMPLEMENT(name) extern HB_INTERNAL const hb_ot_complex_shaper_t _hb_ot_complex_shaper_##name; +HB_COMPLEX_SHAPERS_IMPLEMENT_SHAPERS +#undef HB_COMPLEX_SHAPER_IMPLEMENT + + +static inline const hb_ot_complex_shaper_t * +hb_ot_shape_complex_categorize (const hb_ot_shape_planner_t *planner) +{ + switch ((hb_tag_t) planner->props.script) + { + default: + return &_hb_ot_complex_shaper_default; + + + /* Unicode-1.1 additions */ + case HB_SCRIPT_ARABIC: + case HB_SCRIPT_MONGOLIAN: + case HB_SCRIPT_SYRIAC: + + /* Unicode-5.0 additions */ + case HB_SCRIPT_NKO: + case HB_SCRIPT_PHAGS_PA: + + /* Unicode-6.0 additions */ + case HB_SCRIPT_MANDAIC: + + /* For Arabic script, use the Arabic shaper even if no OT script tag was found. + * This is because we do fallback shaping for Arabic script (and not others). */ + if (planner->map.chosen_script[0] != HB_OT_TAG_DEFAULT_SCRIPT || + planner->props.script == HB_SCRIPT_ARABIC) + return &_hb_ot_complex_shaper_arabic; + else + return &_hb_ot_complex_shaper_default; + + + /* Unicode-1.1 additions */ + case HB_SCRIPT_THAI: + case HB_SCRIPT_LAO: + + return &_hb_ot_complex_shaper_thai; + + + + /* ^--- Add new shapers here */ + + +#if 0 + /* Note: + * + * These disabled scripts are listed in ucd/IndicSyllabicCategory.txt, but according + * to Martin Hosken and Jonathan Kew do not require complex shaping. + * + * TODO We should automate figuring out which scripts do not need complex shaping + * + * TODO We currently keep data for these scripts in our indic table. Need to fix the + * generator to not do that. + */ + + + /* Simple? */ + + /* Unicode-3.2 additions */ + case HB_SCRIPT_BUHID: + case HB_SCRIPT_HANUNOO: + + /* Unicode-5.1 additions */ + case HB_SCRIPT_SAURASHTRA: + + /* Unicode-6.0 additions */ + case HB_SCRIPT_BATAK: + case HB_SCRIPT_BRAHMI: + + + /* Simple */ + + /* Unicode-1.1 additions */ + /* These have their own shaper now. */ + case HB_SCRIPT_LAO: + case HB_SCRIPT_THAI: + + /* Unicode-2.0 additions */ + case HB_SCRIPT_TIBETAN: + + /* Unicode-3.2 additions */ + case HB_SCRIPT_TAGALOG: + case HB_SCRIPT_TAGBANWA: + + /* Unicode-4.0 additions */ + case HB_SCRIPT_LIMBU: + case HB_SCRIPT_TAI_LE: + + /* Unicode-4.1 additions */ + case HB_SCRIPT_KHAROSHTHI: + case HB_SCRIPT_SYLOTI_NAGRI: + + /* Unicode-5.1 additions */ + case HB_SCRIPT_KAYAH_LI: + + /* Unicode-5.2 additions */ + case HB_SCRIPT_TAI_VIET: + + +#endif + + /* Unicode-1.1 additions */ + case HB_SCRIPT_BENGALI: + case HB_SCRIPT_DEVANAGARI: + case HB_SCRIPT_GUJARATI: + case HB_SCRIPT_GURMUKHI: + case HB_SCRIPT_KANNADA: + case HB_SCRIPT_MALAYALAM: + case HB_SCRIPT_ORIYA: + case HB_SCRIPT_TAMIL: + case HB_SCRIPT_TELUGU: + + /* Unicode-3.0 additions */ + case HB_SCRIPT_SINHALA: + + /* Unicode-4.1 additions */ + case HB_SCRIPT_BUGINESE: + case HB_SCRIPT_NEW_TAI_LUE: + + /* Unicode-5.0 additions */ + case HB_SCRIPT_BALINESE: + + /* Unicode-5.1 additions */ + case HB_SCRIPT_CHAM: + case HB_SCRIPT_LEPCHA: + case HB_SCRIPT_REJANG: + case HB_SCRIPT_SUNDANESE: + + /* Unicode-5.2 additions */ + case HB_SCRIPT_JAVANESE: + case HB_SCRIPT_KAITHI: + case HB_SCRIPT_MEETEI_MAYEK: + case HB_SCRIPT_TAI_THAM: + + + /* Unicode-6.1 additions */ + case HB_SCRIPT_CHAKMA: + case HB_SCRIPT_SHARADA: + case HB_SCRIPT_TAKRI: + + /* Only use Indic shaper if the font has Indic tables. */ + if (planner->map.found_script[0]) + return &_hb_ot_complex_shaper_indic; + else + return &_hb_ot_complex_shaper_default; + + case HB_SCRIPT_KHMER: + /* A number of Khmer fonts in the wild don't have a 'pref' feature, + * and as such won't shape properly via the Indic shaper; + * however, they typically have 'liga' / 'clig' features that implement + * the necessary "reordering" by means of ligature substitutions. + * So we send such pref-less fonts through the generic shaper instead. */ + if (planner->map.found_script[0] && + hb_ot_layout_language_find_feature (planner->face, HB_OT_TAG_GSUB, + planner->map.script_index[0], + planner->map.language_index[0], + HB_TAG ('p','r','e','f'), + NULL)) + return &_hb_ot_complex_shaper_indic; + else + return &_hb_ot_complex_shaper_default; + + case HB_SCRIPT_MYANMAR: + /* For Myanmar, we only want to use the Indic shaper if the "new" script + * tag is found. For "old" script tag we want to use the default shaper. */ + if (planner->map.chosen_script[0] == HB_TAG ('m','y','m','2')) + return &_hb_ot_complex_shaper_indic; + else + return &_hb_ot_complex_shaper_default; + } +} + + +#endif /* HB_OT_SHAPE_COMPLEX_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-thai.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-thai.cc new file mode 100644 index 00000000000..24d476a0ba3 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-complex-thai.cc @@ -0,0 +1,378 @@ +/* + * Copyright © 2010,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-complex-private.hh" + + +/* Thai / Lao shaper */ + + +/* PUA shaping */ + + +enum thai_consonant_type_t +{ + NC, + AC, + RC, + DC, + NOT_CONSONANT, + NUM_CONSONANT_TYPES = NOT_CONSONANT +}; + +static thai_consonant_type_t +get_consonant_type (hb_codepoint_t u) +{ + if (u == 0x0E1B || u == 0x0E1D || u == 0x0E1F/* || u == 0x0E2C*/) + return AC; + if (u == 0x0E0D || u == 0x0E10) + return RC; + if (u == 0x0E0E || u == 0x0E0F) + return DC; + if (hb_in_range<hb_codepoint_t> (u, 0x0E01, 0x0E2E)) + return NC; + return NOT_CONSONANT; +} + + +enum thai_mark_type_t +{ + AV, + BV, + T, + NOT_MARK, + NUM_MARK_TYPES = NOT_MARK +}; + +static thai_mark_type_t +get_mark_type (hb_codepoint_t u) +{ + if (u == 0x0E31 || hb_in_range<hb_codepoint_t> (u, 0x0E34, 0x0E37) || + u == 0x0E47 || hb_in_range<hb_codepoint_t> (u, 0x0E4D, 0x0E4E)) + return AV; + if (hb_in_range<hb_codepoint_t> (u, 0x0E38, 0x0E3A)) + return BV; + if (hb_in_range<hb_codepoint_t> (u, 0x0E48, 0x0E4C)) + return T; + return NOT_MARK; +} + + +enum thai_action_t +{ + NOP, + SD, /* Shift combining-mark down */ + SL, /* Shift combining-mark left */ + SDL, /* Shift combining-mark down-left */ + RD /* Remove descender from base */ +}; + +static hb_codepoint_t +thai_pua_shape (hb_codepoint_t u, thai_action_t action, hb_font_t *font) +{ + struct thai_pua_mapping_t { + hb_codepoint_t u; + hb_codepoint_t win_pua; + hb_codepoint_t mac_pua; + } const *pua_mappings = NULL; + static const thai_pua_mapping_t SD_mappings[] = { + {0x0E48, 0xF70A, 0xF88B}, /* MAI EK */ + {0x0E49, 0xF70B, 0xF88E}, /* MAI THO */ + {0x0E4A, 0xF70C, 0xF891}, /* MAI TRI */ + {0x0E4B, 0xF70D, 0xF894}, /* MAI CHATTAWA */ + {0x0E4C, 0xF70E, 0xF897}, /* THANTHAKHAT */ + {0x0E38, 0xF718, 0xF89B}, /* SARA U */ + {0x0E39, 0xF719, 0xF89C}, /* SARA UU */ + {0x0E3A, 0xF71A, 0xF89D}, /* PHINTHU */ + {0x0000, 0x0000, 0x0000} + }; + static const thai_pua_mapping_t SDL_mappings[] = { + {0x0E48, 0xF705, 0xF88C}, /* MAI EK */ + {0x0E49, 0xF706, 0xF88F}, /* MAI THO */ + {0x0E4A, 0xF707, 0xF892}, /* MAI TRI */ + {0x0E4B, 0xF708, 0xF895}, /* MAI CHATTAWA */ + {0x0E4C, 0xF709, 0xF898}, /* THANTHAKHAT */ + {0x0000, 0x0000, 0x0000} + }; + static const thai_pua_mapping_t SL_mappings[] = { + {0x0E48, 0xF713, 0xF88A}, /* MAI EK */ + {0x0E49, 0xF714, 0xF88D}, /* MAI THO */ + {0x0E4A, 0xF715, 0xF890}, /* MAI TRI */ + {0x0E4B, 0xF716, 0xF893}, /* MAI CHATTAWA */ + {0x0E4C, 0xF717, 0xF896}, /* THANTHAKHAT */ + {0x0E31, 0xF710, 0xF884}, /* MAI HAN-AKAT */ + {0x0E34, 0xF701, 0xF885}, /* SARA I */ + {0x0E35, 0xF702, 0xF886}, /* SARA II */ + {0x0E36, 0xF703, 0xF887}, /* SARA UE */ + {0x0E37, 0xF704, 0xF888}, /* SARA UEE */ + {0x0E47, 0xF712, 0xF889}, /* MAITAIKHU */ + {0x0E4D, 0xF711, 0xF899}, /* NIKHAHIT */ + {0x0000, 0x0000, 0x0000} + }; + static const thai_pua_mapping_t RD_mappings[] = { + {0x0E0D, 0xF70F, 0xF89A}, /* YO YING */ + {0x0E10, 0xF700, 0xF89E}, /* THO THAN */ + {0x0000, 0x0000, 0x0000} + }; + + switch (action) { + default: assert (false); /* Fallthrough */ + case NOP: return u; + case SD: pua_mappings = SD_mappings; break; + case SDL: pua_mappings = SDL_mappings; break; + case SL: pua_mappings = SL_mappings; break; + case RD: pua_mappings = RD_mappings; break; + } + for (; pua_mappings->u; pua_mappings++) + if (pua_mappings->u == u) + { + hb_codepoint_t glyph; + if (hb_font_get_glyph (font, pua_mappings->win_pua, 0, &glyph)) + return pua_mappings->win_pua; + if (hb_font_get_glyph (font, pua_mappings->mac_pua, 0, &glyph)) + return pua_mappings->mac_pua; + break; + } + return u; +} + + +static enum thai_above_state_t +{ /* Cluster above looks like: */ + T0, /* ⣤ */ + T1, /* ⣼ */ + T2, /* ⣾ */ + T3, /* ⣿ */ + NUM_ABOVE_STATES +} thai_above_start_state[NUM_CONSONANT_TYPES + 1/* For NOT_CONSONANT */] = +{ + T0, /* NC */ + T1, /* AC */ + T0, /* RC */ + T0, /* DC */ + T3, /* NOT_CONSONANT */ +}; + +static const struct thai_above_state_machine_edge_t { + thai_action_t action; + thai_above_state_t next_state; +} thai_above_state_machine[NUM_ABOVE_STATES][NUM_MARK_TYPES] = +{ /*AV*/ /*BV*/ /*T*/ +/*T0*/ {{NOP,T3}, {NOP,T0}, {SD, T3}}, +/*T1*/ {{SL, T2}, {NOP,T1}, {SDL,T2}}, +/*T2*/ {{NOP,T3}, {NOP,T2}, {SL, T3}}, +/*T3*/ {{NOP,T3}, {NOP,T3}, {NOP,T3}}, +}; + + +static enum thai_below_state_t +{ + B0, /* No descender */ + B1, /* Removable descender */ + B2, /* Strict descender */ + NUM_BELOW_STATES +} thai_below_start_state[NUM_CONSONANT_TYPES + 1/* For NOT_CONSONANT */] = +{ + B0, /* NC */ + B0, /* AC */ + B1, /* RC */ + B2, /* DC */ + B2, /* NOT_CONSONANT */ +}; + +static const struct thai_below_state_machine_edge_t { + thai_action_t action; + thai_below_state_t next_state; +} thai_below_state_machine[NUM_BELOW_STATES][NUM_MARK_TYPES] = +{ /*AV*/ /*BV*/ /*T*/ +/*B0*/ {{NOP,B0}, {NOP,B2}, {NOP, B0}}, +/*B1*/ {{NOP,B1}, {RD, B2}, {NOP, B1}}, +/*B2*/ {{NOP,B2}, {SD, B2}, {NOP, B2}}, +}; + + +static void +do_thai_pua_shaping (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_buffer_t *buffer, + hb_font_t *font) +{ + thai_above_state_t above_state = thai_above_start_state[NOT_CONSONANT]; + thai_below_state_t below_state = thai_below_start_state[NOT_CONSONANT]; + unsigned int base = 0; + + hb_glyph_info_t *info = buffer->info; + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + { + thai_mark_type_t mt = get_mark_type (info[i].codepoint); + + if (mt == NOT_MARK) { + thai_consonant_type_t ct = get_consonant_type (info[i].codepoint); + above_state = thai_above_start_state[ct]; + below_state = thai_below_start_state[ct]; + base = i; + continue; + } + + const thai_above_state_machine_edge_t &above_edge = thai_above_state_machine[above_state][mt]; + const thai_below_state_machine_edge_t &below_edge = thai_below_state_machine[below_state][mt]; + above_state = above_edge.next_state; + below_state = below_edge.next_state; + + /* At least one of the above/below actions is NOP. */ + thai_action_t action = above_edge.action != NOP ? above_edge.action : below_edge.action; + + if (action == RD) + info[base].codepoint = thai_pua_shape (info[base].codepoint, action, font); + else + info[i].codepoint = thai_pua_shape (info[i].codepoint, action, font); + } +} + + +static void +preprocess_text_thai (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + hb_font_t *font) +{ + /* This function implements the shaping logic documented here: + * + * http://linux.thai.net/~thep/th-otf/shaping.html + * + * The first shaping rule listed there is needed even if the font has Thai + * OpenType tables. The rest do fallback positioning based on PUA codepoints. + * We implement that only if there exist no Thai GSUB in the font. + */ + + /* The following is NOT specified in the MS OT Thai spec, however, it seems + * to be what Uniscribe and other engines implement. According to Eric Muller: + * + * When you have a SARA AM, decompose it in NIKHAHIT + SARA AA, *and* move the + * NIKHAHIT backwards over any tone mark (0E48-0E4B). + * + * <0E14, 0E4B, 0E33> -> <0E14, 0E4D, 0E4B, 0E32> + * + * This reordering is legit only when the NIKHAHIT comes from a SARA AM, not + * when it's there to start with. The string <0E14, 0E4B, 0E4D> is probably + * not what a user wanted, but the rendering is nevertheless nikhahit above + * chattawa. + * + * Same for Lao. + * + * Note: + * + * Uniscribe also does some below-marks reordering. Namely, it positions U+0E3A + * after U+0E38 and U+0E39. We do that by modifying the ccc for U+0E3A. + * See unicode->modified_combining_class (). Lao does NOT have a U+0E3A + * equivalent. + */ + + + /* + * Here are the characters of significance: + * + * Thai Lao + * SARA AM: U+0E33 U+0EB3 + * SARA AA: U+0E32 U+0EB2 + * Nikhahit: U+0E4D U+0ECD + * + * Testing shows that Uniscribe reorder the following marks: + * Thai: <0E31,0E34..0E37,0E47..0E4E> + * Lao: <0EB1,0EB4..0EB7,0EC7..0ECE> + * + * Note how the Lao versions are the same as Thai + 0x80. + */ + + /* We only get one script at a time, so a script-agnostic implementation + * is adequate here. */ +#define IS_SARA_AM(x) (((x) & ~0x0080) == 0x0E33) +#define NIKHAHIT_FROM_SARA_AM(x) ((x) - 0xE33 + 0xE4D) +#define SARA_AA_FROM_SARA_AM(x) ((x) - 1) +#define IS_TONE_MARK(x) (hb_in_ranges<hb_codepoint_t> ((x) & ~0x0080, 0x0E34, 0x0E37, 0x0E47, 0x0E4E, 0x0E31, 0x0E31)) + + buffer->clear_output (); + unsigned int count = buffer->len; + for (buffer->idx = 0; buffer->idx < count;) + { + hb_codepoint_t u = buffer->cur().codepoint; + if (likely (!IS_SARA_AM (u))) { + buffer->next_glyph (); + continue; + } + + /* Is SARA AM. Decompose and reorder. */ + hb_codepoint_t decomposed[2] = {hb_codepoint_t (NIKHAHIT_FROM_SARA_AM (u)), + hb_codepoint_t (SARA_AA_FROM_SARA_AM (u))}; + buffer->replace_glyphs (1, 2, decomposed); + if (unlikely (buffer->in_error)) + return; + + /* Ok, let's see... */ + unsigned int end = buffer->out_len; + unsigned int start = end - 2; + while (start > 0 && IS_TONE_MARK (buffer->out_info[start - 1].codepoint)) + start--; + + if (start + 2 < end) + { + /* Move Nikhahit (end-2) to the beginning */ + buffer->merge_out_clusters (start, end); + hb_glyph_info_t t = buffer->out_info[end - 2]; + memmove (buffer->out_info + start + 1, + buffer->out_info + start, + sizeof (buffer->out_info[0]) * (end - start - 2)); + buffer->out_info[start] = t; + } + else + { + /* Since we decomposed, and NIKHAHIT is combining, merge clusters with the + * previous cluster. */ + if (start) + buffer->merge_out_clusters (start - 1, end); + } + } + buffer->swap_buffers (); + + /* If font has Thai GSUB, we are done. */ + if (plan->props.script == HB_SCRIPT_THAI && !plan->map.found_script[0]) + do_thai_pua_shaping (plan, buffer, font); +} + +const hb_ot_complex_shaper_t _hb_ot_complex_shaper_thai = +{ + "thai", + NULL, /* collect_features */ + NULL, /* override_features */ + NULL, /* data_create */ + NULL, /* data_destroy */ + preprocess_text_thai, + NULL, /* normalization_preference */ + NULL, /* decompose */ + NULL, /* compose */ + NULL, /* setup_masks */ + true, /* zero_width_attached_marks */ + false,/* fallback_position */ +}; diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback-private.hh new file mode 100644 index 00000000000..5e9cb061780 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback-private.hh @@ -0,0 +1,44 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_FALLBACK_PRIVATE_HH +#define HB_OT_SHAPE_FALLBACK_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-ot-shape-private.hh" + + +HB_INTERNAL void _hb_ot_shape_fallback_position (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); + +HB_INTERNAL void _hb_ot_shape_fallback_position_recategorize_marks (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); + + +#endif /* HB_OT_SHAPE_FALLBACK_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback.cc new file mode 100644 index 00000000000..6f3426e6b49 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-fallback.cc @@ -0,0 +1,409 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-fallback-private.hh" + +static unsigned int +recategorize_combining_class (hb_codepoint_t u, + unsigned int klass) +{ + if (klass >= 200) + return klass; + + /* Thai / Lao need some per-character work. */ + if ((u & ~0xFF) == 0x0E00) + { + if (unlikely (klass == 0)) + { + switch (u) + { + case 0x0E31: + case 0x0E34: + case 0x0E35: + case 0x0E36: + case 0x0E37: + case 0x0E47: + case 0x0E4C: + case 0x0E4D: + case 0x0E4E: + klass = HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; + break; + + case 0x0EB1: + case 0x0EB4: + case 0x0EB5: + case 0x0EB6: + case 0x0EB7: + case 0x0EBB: + case 0x0ECC: + case 0x0ECD: + klass = HB_UNICODE_COMBINING_CLASS_ABOVE; + break; + + case 0x0EBC: + klass = HB_UNICODE_COMBINING_CLASS_BELOW; + break; + } + } else { + /* Thai virama is below-right */ + if (u == 0x0E3A) + klass = HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; + } + } + + switch (klass) + { + + /* Hebrew */ + + case HB_MODIFIED_COMBINING_CLASS_CCC10: /* sheva */ + case HB_MODIFIED_COMBINING_CLASS_CCC11: /* hataf segol */ + case HB_MODIFIED_COMBINING_CLASS_CCC12: /* hataf patah */ + case HB_MODIFIED_COMBINING_CLASS_CCC13: /* hataf qamats */ + case HB_MODIFIED_COMBINING_CLASS_CCC14: /* hiriq */ + case HB_MODIFIED_COMBINING_CLASS_CCC15: /* tsere */ + case HB_MODIFIED_COMBINING_CLASS_CCC16: /* segol */ + case HB_MODIFIED_COMBINING_CLASS_CCC17: /* patah */ + case HB_MODIFIED_COMBINING_CLASS_CCC18: /* qamats */ + case HB_MODIFIED_COMBINING_CLASS_CCC20: /* qubuts */ + case HB_MODIFIED_COMBINING_CLASS_CCC22: /* meteg */ + return HB_UNICODE_COMBINING_CLASS_BELOW; + + case HB_MODIFIED_COMBINING_CLASS_CCC23: /* rafe */ + return HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE; + + case HB_MODIFIED_COMBINING_CLASS_CCC24: /* shin dot */ + return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; + + case HB_MODIFIED_COMBINING_CLASS_CCC25: /* sin dot */ + case HB_MODIFIED_COMBINING_CLASS_CCC19: /* holam */ + return HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT; + + case HB_MODIFIED_COMBINING_CLASS_CCC26: /* point varika */ + return HB_UNICODE_COMBINING_CLASS_ABOVE; + + case HB_MODIFIED_COMBINING_CLASS_CCC21: /* dagesh */ + break; + + + /* Arabic and Syriac */ + + case HB_MODIFIED_COMBINING_CLASS_CCC27: /* fathatan */ + case HB_MODIFIED_COMBINING_CLASS_CCC28: /* dammatan */ + case HB_MODIFIED_COMBINING_CLASS_CCC30: /* fatha */ + case HB_MODIFIED_COMBINING_CLASS_CCC31: /* damma */ + case HB_MODIFIED_COMBINING_CLASS_CCC33: /* shadda */ + case HB_MODIFIED_COMBINING_CLASS_CCC34: /* sukun */ + case HB_MODIFIED_COMBINING_CLASS_CCC35: /* superscript alef */ + case HB_MODIFIED_COMBINING_CLASS_CCC36: /* superscript alaph */ + return HB_UNICODE_COMBINING_CLASS_ABOVE; + + case HB_MODIFIED_COMBINING_CLASS_CCC29: /* kasratan */ + case HB_MODIFIED_COMBINING_CLASS_CCC32: /* kasra */ + return HB_UNICODE_COMBINING_CLASS_BELOW; + + + /* Thai */ + + case HB_MODIFIED_COMBINING_CLASS_CCC103: /* sara u / sara uu */ + return HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT; + + case HB_MODIFIED_COMBINING_CLASS_CCC107: /* mai */ + return HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT; + + + /* Lao */ + + case HB_MODIFIED_COMBINING_CLASS_CCC118: /* sign u / sign uu */ + return HB_UNICODE_COMBINING_CLASS_BELOW; + + case HB_MODIFIED_COMBINING_CLASS_CCC122: /* mai */ + return HB_UNICODE_COMBINING_CLASS_ABOVE; + + + /* Tibetan */ + + case HB_MODIFIED_COMBINING_CLASS_CCC129: /* sign aa */ + return HB_UNICODE_COMBINING_CLASS_BELOW; + + case HB_MODIFIED_COMBINING_CLASS_CCC130: /* sign i*/ + return HB_UNICODE_COMBINING_CLASS_ABOVE; + + case HB_MODIFIED_COMBINING_CLASS_CCC132: /* sign u */ + return HB_UNICODE_COMBINING_CLASS_BELOW; + + } + + return klass; +} + +void +_hb_ot_shape_fallback_position_recategorize_marks (const hb_ot_shape_plan_t *plan HB_UNUSED, + hb_font_t *font HB_UNUSED, + hb_buffer_t *buffer) +{ + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) { + unsigned int combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]); + combining_class = recategorize_combining_class (buffer->info[i].codepoint, combining_class); + _hb_glyph_info_set_modified_combining_class (&buffer->info[i], combining_class); + } +} + + +static void +zero_mark_advances (hb_buffer_t *buffer, + unsigned int start, + unsigned int end) +{ + for (unsigned int i = start; i < end; i++) + if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) + { + buffer->pos[i].x_advance = 0; + buffer->pos[i].y_advance = 0; + } +} + +static inline void +position_mark (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer, + hb_glyph_extents_t &base_extents, + unsigned int i, + unsigned int combining_class) +{ + hb_glyph_extents_t mark_extents; + if (!font->get_glyph_extents (buffer->info[i].codepoint, + &mark_extents)) + return; + + hb_position_t y_gap = font->y_scale / 16; + + hb_glyph_position_t &pos = buffer->pos[i]; + pos.x_offset = pos.y_offset = 0; + + + /* We dont position LEFT and RIGHT marks. */ + + /* X positioning */ + switch (combining_class) + { + case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: + case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: + if (buffer->props.direction == HB_DIRECTION_LTR) { + pos.x_offset += base_extents.x_bearing - mark_extents.width / 2 - mark_extents.x_bearing; + break; + } else if (buffer->props.direction == HB_DIRECTION_RTL) { + pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width / 2 - mark_extents.x_bearing; + break; + } + /* Fall through */ + + default: + case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: + case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: + case HB_UNICODE_COMBINING_CLASS_BELOW: + case HB_UNICODE_COMBINING_CLASS_ABOVE: + /* Center align. */ + pos.x_offset += base_extents.x_bearing + (base_extents.width - mark_extents.width) / 2 - mark_extents.x_bearing; + break; + + case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: + case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: + case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: + /* Left align. */ + pos.x_offset += base_extents.x_bearing - mark_extents.x_bearing; + break; + + case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: + case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: + case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: + /* Right align. */ + pos.x_offset += base_extents.x_bearing + base_extents.width - mark_extents.width - mark_extents.x_bearing; + break; + } + + /* Y positioning */ + switch (combining_class) + { + case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: + case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: + case HB_UNICODE_COMBINING_CLASS_BELOW: + case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: + /* Add gap, fall-through. */ + base_extents.height -= y_gap; + + case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: + case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: + pos.y_offset += base_extents.y_bearing + base_extents.height - mark_extents.y_bearing; + base_extents.height += mark_extents.height; + break; + + case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: + case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: + case HB_UNICODE_COMBINING_CLASS_ABOVE: + case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: + /* Add gap, fall-through. */ + base_extents.y_bearing += y_gap; + base_extents.height -= y_gap; + + case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: + case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: + pos.y_offset += base_extents.y_bearing - (mark_extents.y_bearing + mark_extents.height); + base_extents.y_bearing -= mark_extents.height; + base_extents.height += mark_extents.height; + break; + } +} + +static inline void +position_around_base (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer, + unsigned int base, + unsigned int end) +{ + hb_direction_t horiz_dir = HB_DIRECTION_INVALID; + hb_glyph_extents_t base_extents; + if (!font->get_glyph_extents (buffer->info[base].codepoint, + &base_extents)) + { + /* If extents don't work, zero marks and go home. */ + zero_mark_advances (buffer, base + 1, end); + return; + } + base_extents.x_bearing += buffer->pos[base].x_offset; + base_extents.y_bearing += buffer->pos[base].y_offset; + + unsigned int lig_id = get_lig_id (buffer->info[base]); + unsigned int num_lig_components = get_lig_num_comps (buffer->info[base]); + + hb_position_t x_offset = 0, y_offset = 0; + if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { + x_offset -= buffer->pos[base].x_advance; + y_offset -= buffer->pos[base].y_advance; + } + + hb_glyph_extents_t component_extents = base_extents; + unsigned int last_lig_component = (unsigned int) -1; + unsigned int last_combining_class = 255; + hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just to shut gcc up. */ + for (unsigned int i = base + 1; i < end; i++) + if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i])) + { + if (num_lig_components > 1) { + unsigned int this_lig_id = get_lig_id (buffer->info[i]); + unsigned int this_lig_component = get_lig_comp (buffer->info[i]) - 1; + /* Conditions for attaching to the last component. */ + if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_components) + this_lig_component = num_lig_components - 1; + if (last_lig_component != this_lig_component) + { + last_lig_component = this_lig_component; + last_combining_class = 255; + component_extents = base_extents; + if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) { + if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction)) + horiz_dir = plan->props.direction; + else + horiz_dir = hb_script_get_horizontal_direction (plan->props.script); + } + if (horiz_dir == HB_DIRECTION_LTR) + component_extents.x_bearing += (this_lig_component * component_extents.width) / num_lig_components; + else + component_extents.x_bearing += ((num_lig_components - 1 - this_lig_component) * component_extents.width) / num_lig_components; + component_extents.width /= num_lig_components; + } + } + + unsigned int this_combining_class = _hb_glyph_info_get_modified_combining_class (&buffer->info[i]); + if (last_combining_class != this_combining_class) + { + last_combining_class = this_combining_class; + cluster_extents = component_extents; + } + + position_mark (plan, font, buffer, cluster_extents, i, this_combining_class); + + buffer->pos[i].x_advance = 0; + buffer->pos[i].y_advance = 0; + buffer->pos[i].x_offset += x_offset; + buffer->pos[i].y_offset += y_offset; + + } else { + if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { + x_offset -= buffer->pos[i].x_advance; + y_offset -= buffer->pos[i].y_advance; + } else { + x_offset += buffer->pos[i].x_advance; + y_offset += buffer->pos[i].y_advance; + } + } +} + +static inline void +position_cluster (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer, + unsigned int start, + unsigned int end) +{ + if (end - start < 2) + return; + + /* Find the base glyph */ + for (unsigned int i = start; i < end; i++) + if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i]))) + { + /* Find mark glyphs */ + unsigned int j; + for (j = i + 1; j < end; j++) + if (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[j]))) + break; + + position_around_base (plan, font, buffer, i, j); + + i = j - 1; + } +} + +void +_hb_ot_shape_fallback_position (const hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer) +{ + unsigned int start = 0; + unsigned int last_cluster = buffer->info[0].cluster; + unsigned int count = buffer->len; + for (unsigned int i = 1; i < count; i++) + if (buffer->info[i].cluster != last_cluster) { + position_cluster (plan, font, buffer, start, i); + start = i; + last_cluster = buffer->info[i].cluster; + } + position_cluster (plan, font, buffer, start, count); +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize-private.hh new file mode 100644 index 00000000000..8112f03aee9 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize-private.hh @@ -0,0 +1,71 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_NORMALIZE_PRIVATE_HH +#define HB_OT_SHAPE_NORMALIZE_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-font.h" +#include "hb-buffer.h" + +/* buffer var allocations, used during the normalization process */ +#define glyph_index() var1.u32 + +struct hb_ot_shape_plan_t; + +enum hb_ot_shape_normalization_mode_t { + HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED, + HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS, /* never composes base-to-base */ + HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT, /* always fully decomposes and then recompose back */ + HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL, /* including base-to-base composition */ + + HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT = HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS +}; + +HB_INTERNAL void _hb_ot_shape_normalize (const hb_ot_shape_plan_t *shaper, + hb_buffer_t *buffer, + hb_font_t *font); + + +struct hb_ot_shape_normalize_context_t +{ + const hb_ot_shape_plan_t *plan; + hb_buffer_t *buffer; + hb_font_t *font; + hb_unicode_funcs_t *unicode; + bool (*decompose) (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b); + bool (*compose) (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab); +}; + + +#endif /* HB_OT_SHAPE_NORMALIZE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize.cc new file mode 100644 index 00000000000..c5325e42b53 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-normalize.cc @@ -0,0 +1,408 @@ +/* + * Copyright © 2011,2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-ot-shape-normalize-private.hh" +#include "hb-ot-shape-complex-private.hh" +#include "hb-ot-shape-private.hh" + + +/* + * HIGHLEVEL DESIGN: + * + * This file exports one main function: _hb_ot_shape_normalize(). + * + * This function closely reflects the Unicode Normalization Algorithm, + * yet it's different. + * + * Each shaper specifies whether it prefers decomposed (NFD) or composed (NFC). + * The logic however tries to use whatever the font can support. + * + * In general what happens is that: each grapheme is decomposed in a chain + * of 1:2 decompositions, marks reordered, and then recomposed if desired, + * so far it's like Unicode Normalization. However, the decomposition and + * recomposition only happens if the font supports the resulting characters. + * + * The goals are: + * + * - Try to render all canonically equivalent strings similarly. To really + * achieve this we have to always do the full decomposition and then + * selectively recompose from there. It's kinda too expensive though, so + * we skip some cases. For example, if composed is desired, we simply + * don't touch 1-character clusters that are supported by the font, even + * though their NFC may be different. + * + * - When a font has a precomposed character for a sequence but the 'ccmp' + * feature in the font is not adequate, use the precomposed character + * which typically has better mark positioning. + * + * - When a font does not support a combining mark, but supports it precomposed + * with previous base, use that. This needs the itemizer to have this + * knowledge too. We need to provide assistance to the itemizer. + * + * - When a font does not support a character but supports its decomposition, + * well, use the decomposition (preferring the canonical decomposition, but + * falling back to the compatibility decomposition if necessary). The + * compatibility decomposition is really nice to have, for characters like + * ellipsis, or various-sized space characters. + * + * - The complex shapers can customize the compose and decompose functions to + * offload some of their requirements to the normalizer. For example, the + * Indic shaper may want to disallow recomposing of two matras. + * + * - We try compatibility decomposition if decomposing through canonical + * decomposition alone failed to find a sequence that the font supports. + * We don't try compatibility decomposition recursively during the canonical + * decomposition phase. This has minimal impact. There are only a handful + * of Greek letter that have canonical decompositions that include characters + * with compatibility decomposition. Those can be found using this command: + * + * egrep "`echo -n ';('; grep ';<' UnicodeData.txt | cut -d';' -f1 | tr '\n' '|'; echo ') '`" UnicodeData.txt + */ + +static bool +decompose_unicode (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b) +{ + return c->unicode->decompose (ab, a, b); +} + +static bool +compose_unicode (const hb_ot_shape_normalize_context_t *c, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab) +{ + return c->unicode->compose (a, b, ab); +} + +static inline void +set_glyph (hb_glyph_info_t &info, hb_font_t *font) +{ + font->get_glyph (info.codepoint, 0, &info.glyph_index()); +} + +static inline void +output_char (hb_buffer_t *buffer, hb_codepoint_t unichar, hb_codepoint_t glyph) +{ + buffer->cur().glyph_index() = glyph; + buffer->output_glyph (unichar); + _hb_glyph_info_set_unicode_props (&buffer->prev(), buffer->unicode); +} + +static inline void +next_char (hb_buffer_t *buffer, hb_codepoint_t glyph) +{ + buffer->cur().glyph_index() = glyph; + buffer->next_glyph (); +} + +static inline void +skip_char (hb_buffer_t *buffer) +{ + buffer->skip_glyph (); +} + +/* Returns 0 if didn't decompose, number of resulting characters otherwise. */ +static inline unsigned int +decompose (const hb_ot_shape_normalize_context_t *c, bool shortest, hb_codepoint_t ab) +{ + hb_codepoint_t a, b, a_glyph, b_glyph; + + if (!c->decompose (c, ab, &a, &b) || + (b && !c->font->get_glyph (b, 0, &b_glyph))) + return 0; + + bool has_a = c->font->get_glyph (a, 0, &a_glyph); + if (shortest && has_a) { + /* Output a and b */ + output_char (c->buffer, a, a_glyph); + if (likely (b)) { + output_char (c->buffer, b, b_glyph); + return 2; + } + return 1; + } + + unsigned int ret; + if ((ret = decompose (c, shortest, a))) { + if (b) { + output_char (c->buffer, b, b_glyph); + return ret + 1; + } + return ret; + } + + if (has_a) { + output_char (c->buffer, a, a_glyph); + if (likely (b)) { + output_char (c->buffer, b, b_glyph); + return 2; + } + return 1; + } + + return 0; +} + +/* Returns 0 if didn't decompose, number of resulting characters otherwise. */ +static inline bool +decompose_compatibility (const hb_ot_shape_normalize_context_t *c, hb_codepoint_t u) +{ + unsigned int len, i; + hb_codepoint_t decomposed[HB_UNICODE_MAX_DECOMPOSITION_LEN]; + hb_codepoint_t glyphs[HB_UNICODE_MAX_DECOMPOSITION_LEN]; + + len = c->buffer->unicode->decompose_compatibility (u, decomposed); + if (!len) + return 0; + + for (i = 0; i < len; i++) + if (!c->font->get_glyph (decomposed[i], 0, &glyphs[i])) + return 0; + + for (i = 0; i < len; i++) + output_char (c->buffer, decomposed[i], glyphs[i]); + + return len; +} + +/* Returns true if recomposition may be benefitial. */ +static inline bool +decompose_current_character (const hb_ot_shape_normalize_context_t *c, bool shortest) +{ + hb_buffer_t * const buffer = c->buffer; + hb_codepoint_t glyph; + unsigned int len = 1; + + /* Kind of a cute waterfall here... */ + if (shortest && c->font->get_glyph (buffer->cur().codepoint, 0, &glyph)) + next_char (buffer, glyph); + else if ((len = decompose (c, shortest, buffer->cur().codepoint))) + skip_char (buffer); + else if (!shortest && c->font->get_glyph (buffer->cur().codepoint, 0, &glyph)) + next_char (buffer, glyph); + else if ((len = decompose_compatibility (c, buffer->cur().codepoint))) + skip_char (buffer); + else + next_char (buffer, glyph); /* glyph is initialized in earlier branches. */ + + /* + * A recomposition would only be useful if we decomposed into at least three + * characters... + */ + return len > 2; +} + +static inline void +handle_variation_selector_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end) +{ + hb_buffer_t * const buffer = c->buffer; + for (; buffer->idx < end - 1;) { + if (unlikely (buffer->unicode->is_variation_selector (buffer->cur(+1).codepoint))) { + /* The next two lines are some ugly lines... But work. */ + c->font->get_glyph (buffer->cur().codepoint, buffer->cur(+1).codepoint, &buffer->cur().glyph_index()); + buffer->replace_glyphs (2, 1, &buffer->cur().codepoint); + } else { + set_glyph (buffer->cur(), c->font); + buffer->next_glyph (); + } + } + if (likely (buffer->idx < end)) { + set_glyph (buffer->cur(), c->font); + buffer->next_glyph (); + } +} + +/* Returns true if recomposition may be benefitial. */ +static inline bool +decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end) +{ + hb_buffer_t * const buffer = c->buffer; + /* TODO Currently if there's a variation-selector we give-up, it's just too hard. */ + for (unsigned int i = buffer->idx; i < end; i++) + if (unlikely (buffer->unicode->is_variation_selector (buffer->info[i].codepoint))) { + handle_variation_selector_cluster (c, end); + return false; + } + + while (buffer->idx < end) + decompose_current_character (c, false); + /* We can be smarter here and only return true if there are at least two ccc!=0 marks. + * But does not matter. */ + return true; +} + +static inline bool +decompose_cluster (const hb_ot_shape_normalize_context_t *c, bool short_circuit, unsigned int end) +{ + if (likely (c->buffer->idx + 1 == end)) + return decompose_current_character (c, short_circuit); + else + return decompose_multi_char_cluster (c, end); +} + + +static int +compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) +{ + unsigned int a = _hb_glyph_info_get_modified_combining_class (pa); + unsigned int b = _hb_glyph_info_get_modified_combining_class (pb); + + return a < b ? -1 : a == b ? 0 : +1; +} + + +void +_hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan, + hb_buffer_t *buffer, + hb_font_t *font) +{ + hb_ot_shape_normalization_mode_t mode = plan->shaper->normalization_preference ? + plan->shaper->normalization_preference (&buffer->props) : + HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT; + const hb_ot_shape_normalize_context_t c = { + plan, + buffer, + font, + buffer->unicode, + plan->shaper->decompose ? plan->shaper->decompose : decompose_unicode, + plan->shaper->compose ? plan->shaper->compose : compose_unicode + }; + + bool short_circuit = mode != HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED && + mode != HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_DIACRITICS_NO_SHORT_CIRCUIT; + bool can_use_recompose = false; + unsigned int count; + + /* We do a fairly straightforward yet custom normalization process in three + * separate rounds: decompose, reorder, recompose (if desired). Currently + * this makes two buffer swaps. We can make it faster by moving the last + * two rounds into the inner loop for the first round, but it's more readable + * this way. */ + + + /* First round, decompose */ + + buffer->clear_output (); + count = buffer->len; + for (buffer->idx = 0; buffer->idx < count;) + { + unsigned int end; + for (end = buffer->idx + 1; end < count; end++) + if (buffer->cur().cluster != buffer->info[end].cluster) + break; + + can_use_recompose = decompose_cluster (&c, short_circuit, end) || can_use_recompose; + } + buffer->swap_buffers (); + + + if (mode != HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL && !can_use_recompose) + return; /* Done! */ + + + /* Second round, reorder (inplace) */ + + count = buffer->len; + for (unsigned int i = 0; i < count; i++) + { + if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]) == 0) + continue; + + unsigned int end; + for (end = i + 1; end < count; end++) + if (_hb_glyph_info_get_modified_combining_class (&buffer->info[end]) == 0) + break; + + /* We are going to do a bubble-sort. Only do this if the + * sequence is short. Doing it on long sequences can result + * in an O(n^2) DoS. */ + if (end - i > 10) { + i = end; + continue; + } + + hb_bubble_sort (buffer->info + i, end - i, compare_combining_class); + + i = end; + } + + + if (mode == HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED) + return; + + /* Third round, recompose */ + + /* As noted in the comment earlier, we don't try to combine + * ccc=0 chars with their previous Starter. */ + + buffer->clear_output (); + count = buffer->len; + unsigned int starter = 0; + buffer->next_glyph (); + while (buffer->idx < count) + { + hb_codepoint_t composed, glyph; + if (/* If mode is NOT COMPOSED_FULL (ie. it's COMPOSED_DIACRITICS), we don't try to + * compose a CCC=0 character with it's preceding starter. */ + (mode == HB_OT_SHAPE_NORMALIZATION_MODE_COMPOSED_FULL || + _hb_glyph_info_get_modified_combining_class (&buffer->cur()) != 0) && + /* If there's anything between the starter and this char, they should have CCC + * smaller than this character's. */ + (starter == buffer->out_len - 1 || + _hb_glyph_info_get_modified_combining_class (&buffer->prev()) < _hb_glyph_info_get_modified_combining_class (&buffer->cur())) && + /* And compose. */ + c.compose (&c, + buffer->out_info[starter].codepoint, + buffer->cur().codepoint, + &composed) && + /* And the font has glyph for the composite. */ + font->get_glyph (composed, 0, &glyph)) + { + /* Composes. */ + buffer->next_glyph (); /* Copy to out-buffer. */ + if (unlikely (buffer->in_error)) + return; + buffer->merge_out_clusters (starter, buffer->out_len); + buffer->out_len--; /* Remove the second composable. */ + buffer->out_info[starter].codepoint = composed; /* Modify starter and carry on. */ + set_glyph (buffer->out_info[starter], font); + _hb_glyph_info_set_unicode_props (&buffer->out_info[starter], buffer->unicode); + + continue; + } + + /* Blocked, or doesn't compose. */ + buffer->next_glyph (); + + if (_hb_glyph_info_get_modified_combining_class (&buffer->prev()) == 0) + starter = buffer->out_len - 1; + } + buffer->swap_buffers (); + +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-private.hh new file mode 100644 index 00000000000..23e80b7bdfa --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape-private.hh @@ -0,0 +1,125 @@ +/* + * Copyright © 2010 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_OT_SHAPE_PRIVATE_HH +#define HB_OT_SHAPE_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-ot-map-private.hh" + + + +/* buffer var allocations, used during the entire shaping process */ +#define unicode_props0() var2.u8[0] +#define unicode_props1() var2.u8[1] + + + +struct hb_ot_shape_plan_t +{ + hb_segment_properties_t props; + const struct hb_ot_complex_shaper_t *shaper; + hb_ot_map_t map; + const void *data; + + inline void collect_lookups (hb_tag_t table_tag, hb_set_t *lookups) const + { + unsigned int table_index; + switch (table_tag) { + case HB_OT_TAG_GSUB: table_index = 0; break; + case HB_OT_TAG_GPOS: table_index = 1; break; + default: return; + } + map.collect_lookups (table_index, lookups); + } + inline void substitute (hb_font_t *font, hb_buffer_t *buffer) const { map.substitute (this, font, buffer); } + inline void position (hb_font_t *font, hb_buffer_t *buffer) const { map.position (this, font, buffer); } + + void finish (void) { map.finish (); } +}; + +struct hb_ot_shape_planner_t +{ + /* In the order that they are filled in. */ + hb_face_t *face; + hb_segment_properties_t props; + const struct hb_ot_complex_shaper_t *shaper; + hb_ot_map_builder_t map; + + hb_ot_shape_planner_t (const hb_shape_plan_t *master_plan) : + face (master_plan->face), + props (master_plan->props), + shaper (NULL), + map (face, &props) {} + ~hb_ot_shape_planner_t (void) { map.finish (); } + + inline void compile (hb_ot_shape_plan_t &plan) + { + plan.props = props; + plan.shaper = shaper; + map.compile (plan.map); + } + + private: + NO_COPY (hb_ot_shape_planner_t); +}; + + + +inline void +_hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_unicode_funcs_t *unicode) +{ + info->unicode_props0() = ((unsigned int) unicode->general_category (info->codepoint)) | + (unicode->is_default_ignorable (info->codepoint) ? 0x80 : 0); + info->unicode_props1() = unicode->modified_combining_class (info->codepoint); +} + +inline hb_unicode_general_category_t +_hb_glyph_info_get_general_category (const hb_glyph_info_t *info) +{ + return (hb_unicode_general_category_t) (info->unicode_props0() & 0x7F); +} + +inline void +_hb_glyph_info_set_modified_combining_class (hb_glyph_info_t *info, unsigned int modified_class) +{ + info->unicode_props1() = modified_class; +} + +inline unsigned int +_hb_glyph_info_get_modified_combining_class (const hb_glyph_info_t *info) +{ + return info->unicode_props1(); +} + +inline hb_bool_t +_hb_glyph_info_is_default_ignorable (const hb_glyph_info_t *info) +{ + return !!(info->unicode_props0() & 0x80); +} + +#endif /* HB_OT_SHAPE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape.cc new file mode 100644 index 00000000000..96461d7079e --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-shape.cc @@ -0,0 +1,640 @@ +/* + * Copyright © 2009,2010 Red Hat, Inc. + * Copyright © 2010,2011,2012 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 + */ + +#define HB_SHAPER ot +#define hb_ot_shaper_face_data_t hb_ot_layout_t +#define hb_ot_shaper_shape_plan_data_t hb_ot_shape_plan_t +#include "hb-shaper-impl-private.hh" + +#include "hb-ot-shape-private.hh" +#include "hb-ot-shape-complex-private.hh" +#include "hb-ot-shape-fallback-private.hh" +#include "hb-ot-shape-normalize-private.hh" + +#include "hb-ot-layout-private.hh" +#include "hb-set-private.hh" + + +static hb_tag_t common_features[] = { + HB_TAG('c','c','m','p'), + HB_TAG('l','i','g','a'), + HB_TAG('l','o','c','l'), + HB_TAG('m','a','r','k'), + HB_TAG('m','k','m','k'), + HB_TAG('r','l','i','g'), +}; + + +static hb_tag_t horizontal_features[] = { + HB_TAG('c','a','l','t'), + HB_TAG('c','l','i','g'), + HB_TAG('c','u','r','s'), + HB_TAG('k','e','r','n'), + HB_TAG('r','c','l','t'), +}; + +/* Note: + * Technically speaking, vrt2 and vert are mutually exclusive. + * According to the spec, valt and vpal are also mutually exclusive. + * But we apply them all for now. + */ +static hb_tag_t vertical_features[] = { + HB_TAG('v','a','l','t'), + HB_TAG('v','e','r','t'), + HB_TAG('v','k','r','n'), + HB_TAG('v','p','a','l'), + HB_TAG('v','r','t','2'), +}; + + + +static void +hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features) +{ + hb_ot_map_builder_t *map = &planner->map; + + switch (props->direction) { + case HB_DIRECTION_LTR: + map->add_bool_feature (HB_TAG ('l','t','r','a')); + map->add_bool_feature (HB_TAG ('l','t','r','m')); + break; + case HB_DIRECTION_RTL: + map->add_bool_feature (HB_TAG ('r','t','l','a')); + map->add_bool_feature (HB_TAG ('r','t','l','m'), false); + break; + case HB_DIRECTION_TTB: + case HB_DIRECTION_BTT: + case HB_DIRECTION_INVALID: + default: + break; + } + +#define ADD_FEATURES(array) \ + HB_STMT_START { \ + for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \ + map->add_bool_feature (array[i]); \ + } HB_STMT_END + + if (planner->shaper->collect_features) + planner->shaper->collect_features (planner); + + ADD_FEATURES (common_features); + + if (HB_DIRECTION_IS_HORIZONTAL (props->direction)) + ADD_FEATURES (horizontal_features); + else + ADD_FEATURES (vertical_features); + + if (planner->shaper->override_features) + planner->shaper->override_features (planner); + +#undef ADD_FEATURES + + for (unsigned int i = 0; i < num_user_features; i++) { + const hb_feature_t *feature = &user_features[i]; + map->add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); + } +} + + +/* + * shaper face data + */ + +hb_ot_shaper_face_data_t * +_hb_ot_shaper_face_data_create (hb_face_t *face) +{ + return _hb_ot_layout_create (face); +} + +void +_hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data) +{ + _hb_ot_layout_destroy (data); +} + + +/* + * shaper font data + */ + +struct hb_ot_shaper_font_data_t {}; + +hb_ot_shaper_font_data_t * +_hb_ot_shaper_font_data_create (hb_font_t *font) +{ + return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data) +{ +} + + +/* + * shaper shape_plan data + */ + +hb_ot_shaper_shape_plan_data_t * +_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, + const hb_feature_t *user_features, + unsigned int num_user_features) +{ + hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); + if (unlikely (!plan)) + return NULL; + + hb_ot_shape_planner_t planner (shape_plan); + + planner.shaper = hb_ot_shape_complex_categorize (&planner); + + hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features); + + planner.compile (*plan); + + if (plan->shaper->data_create) { + plan->data = plan->shaper->data_create (plan); + if (unlikely (!plan->data)) + return NULL; + } + + return plan; +} + +void +_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan) +{ + if (plan->shaper->data_destroy) + plan->shaper->data_destroy (const_cast<void *> (plan->data)); + + plan->finish (); + + free (plan); +} + + +/* + * shaper + */ + +struct hb_ot_shape_context_t +{ + hb_ot_shape_plan_t *plan; + hb_font_t *font; + hb_face_t *face; + hb_buffer_t *buffer; + const hb_feature_t *user_features; + unsigned int num_user_features; + + /* Transient stuff */ + hb_direction_t target_direction; +}; + + + +/* Main shaper */ + + +/* Prepare */ + +static void +hb_set_unicode_props (hb_buffer_t *buffer) +{ + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + _hb_glyph_info_set_unicode_props (&buffer->info[i], buffer->unicode); +} + +static void +hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) +{ + if (!(buffer->flags & HB_BUFFER_FLAG_BOT) || + _hb_glyph_info_get_general_category (&buffer->info[0]) != + HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) + return; + + hb_codepoint_t dottedcircle_glyph; + if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph)) + return; + + hb_glyph_info_t dottedcircle; + dottedcircle.codepoint = 0x25CC; + _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode); + + buffer->clear_output (); + + buffer->idx = 0; + hb_glyph_info_t info = dottedcircle; + info.cluster = buffer->cur().cluster; + info.mask = buffer->cur().mask; + buffer->output_info (info); + while (buffer->idx < buffer->len) + buffer->next_glyph (); + + buffer->swap_buffers (); +} + +static void +hb_form_clusters (hb_buffer_t *buffer) +{ + unsigned int count = buffer->len; + for (unsigned int i = 1; i < count; i++) + if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i]))) + buffer->merge_clusters (i - 1, i + 1); +} + +static void +hb_ensure_native_direction (hb_buffer_t *buffer) +{ + hb_direction_t direction = buffer->props.direction; + + /* TODO vertical: + * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType + * Ogham fonts are supposed to be implemented BTT or not. Need to research that + * first. */ + if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) || + (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) + { + hb_buffer_reverse_clusters (buffer); + buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction); + } +} + + +/* Substitute */ + +static inline void +hb_ot_mirror_chars (hb_ot_shape_context_t *c) +{ + if (HB_DIRECTION_IS_FORWARD (c->target_direction)) + return; + + hb_unicode_funcs_t *unicode = c->buffer->unicode; + hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m')); + + unsigned int count = c->buffer->len; + for (unsigned int i = 0; i < count; i++) { + hb_codepoint_t codepoint = unicode->mirroring (c->buffer->info[i].codepoint); + if (likely (codepoint == c->buffer->info[i].codepoint)) + c->buffer->info[i].mask |= rtlm_mask; + else + c->buffer->info[i].codepoint = codepoint; + } +} + +static inline void +hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) +{ + hb_ot_map_t *map = &c->plan->map; + + hb_mask_t global_mask = map->get_global_mask (); + c->buffer->reset_masks (global_mask); + + if (c->plan->shaper->setup_masks) + c->plan->shaper->setup_masks (c->plan, c->buffer, c->font); + + for (unsigned int i = 0; i < c->num_user_features; i++) + { + const hb_feature_t *feature = &c->user_features[i]; + if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { + unsigned int shift; + hb_mask_t mask = map->get_mask (feature->tag, &shift); + c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); + } + } +} + +static inline void +hb_ot_map_glyphs_fast (hb_buffer_t *buffer) +{ + /* Normalization process sets up glyph_index(), we just copy it. */ + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + buffer->info[i].codepoint = buffer->info[i].glyph_index(); +} + +static inline void +hb_synthesize_glyph_classes (hb_ot_shape_context_t *c) +{ + unsigned int count = c->buffer->len; + for (unsigned int i = 0; i < count; i++) + c->buffer->info[i].glyph_props() = _hb_glyph_info_get_general_category (&c->buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK ? + HB_OT_LAYOUT_GLYPH_PROPS_MARK : + HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH; +} + +static inline void +hb_ot_substitute_default (hb_ot_shape_context_t *c) +{ + if (c->plan->shaper->preprocess_text) + c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font); + + hb_ot_mirror_chars (c); + + HB_BUFFER_ALLOCATE_VAR (c->buffer, glyph_index); + + _hb_ot_shape_normalize (c->plan, c->buffer, c->font); + + hb_ot_shape_setup_masks (c); + + /* This is unfortunate to go here, but necessary... */ + if (!hb_ot_layout_has_positioning (c->face)) + _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, c->buffer); + + hb_ot_map_glyphs_fast (c->buffer); + + HB_BUFFER_DEALLOCATE_VAR (c->buffer, glyph_index); +} + +static inline void +hb_ot_substitute_complex (hb_ot_shape_context_t *c) +{ + hb_ot_layout_substitute_start (c->font, c->buffer); + + if (!hb_ot_layout_has_glyph_classes (c->face)) + hb_synthesize_glyph_classes (c); + + c->plan->substitute (c->font, c->buffer); + + hb_ot_layout_substitute_finish (c->font, c->buffer); + + return; +} + +static inline void +hb_ot_substitute (hb_ot_shape_context_t *c) +{ + hb_ot_substitute_default (c); + hb_ot_substitute_complex (c); +} + +/* Position */ + +static inline void +hb_ot_position_default (hb_ot_shape_context_t *c) +{ + hb_ot_layout_position_start (c->font, c->buffer); + + unsigned int count = c->buffer->len; + for (unsigned int i = 0; i < count; i++) { + c->font->get_glyph_advance_for_direction (c->buffer->info[i].codepoint, + c->buffer->props.direction, + &c->buffer->pos[i].x_advance, + &c->buffer->pos[i].y_advance); + c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint, + c->buffer->props.direction, + &c->buffer->pos[i].x_offset, + &c->buffer->pos[i].y_offset); + } +} + +static inline bool +hb_ot_position_complex (hb_ot_shape_context_t *c) +{ + bool ret = false; + + if (hb_ot_layout_has_positioning (c->face)) + { + /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */ + + unsigned int count = c->buffer->len; + for (unsigned int i = 0; i < count; i++) { + c->font->add_glyph_origin_for_direction (c->buffer->info[i].codepoint, + HB_DIRECTION_LTR, + &c->buffer->pos[i].x_offset, + &c->buffer->pos[i].y_offset); + } + + c->plan->position (c->font, c->buffer); + + for (unsigned int i = 0; i < count; i++) { + c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint, + HB_DIRECTION_LTR, + &c->buffer->pos[i].x_offset, + &c->buffer->pos[i].y_offset); + } + + ret = true; + } + + hb_ot_layout_position_finish (c->font, c->buffer, c->plan->shaper->zero_width_attached_marks); + + return ret; +} + +static inline void +hb_ot_truetype_kern (hb_ot_shape_context_t *c) +{ + /* TODO Check for kern=0 */ + unsigned int count = c->buffer->len; + for (unsigned int i = 1; i < count; i++) { + hb_position_t x_kern, y_kern, kern1, kern2; + c->font->get_glyph_kerning_for_direction (c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint, + c->buffer->props.direction, + &x_kern, &y_kern); + + kern1 = x_kern >> 1; + kern2 = x_kern - kern1; + c->buffer->pos[i - 1].x_advance += kern1; + c->buffer->pos[i].x_advance += kern2; + c->buffer->pos[i].x_offset += kern2; + + kern1 = y_kern >> 1; + kern2 = y_kern - kern1; + c->buffer->pos[i - 1].y_advance += kern1; + c->buffer->pos[i].y_advance += kern2; + c->buffer->pos[i].y_offset += kern2; + } +} + +static inline void +hb_ot_position (hb_ot_shape_context_t *c) +{ + hb_ot_position_default (c); + + hb_bool_t fallback = !hb_ot_position_complex (c); + + if (fallback && c->plan->shaper->fallback_position) + _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer); + + if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) + hb_buffer_reverse (c->buffer); + + /* Visual fallback goes here. */ + + if (fallback) + hb_ot_truetype_kern (c); +} + + +/* Post-process */ + +static void +hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) +{ + if (c->buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) + return; + + hb_codepoint_t space = 0; + + unsigned int count = c->buffer->len; + for (unsigned int i = 0; i < count; i++) + if (unlikely (!is_a_ligature (c->buffer->info[i]) && + _hb_glyph_info_is_default_ignorable (&c->buffer->info[i]))) + { + if (!space) { + /* We assume that the space glyph is not gid0. */ + if (unlikely (!c->font->get_glyph (' ', 0, &space)) || !space) + return; /* No point! */ + } + c->buffer->info[i].codepoint = space; + c->buffer->pos[i].x_advance = 0; + c->buffer->pos[i].y_advance = 0; + } +} + + +/* Pull it all together! */ + +static void +hb_ot_shape_internal (hb_ot_shape_context_t *c) +{ + c->buffer->deallocate_var_all (); + + /* Save the original direction, we use it later. */ + c->target_direction = c->buffer->props.direction; + + HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props0); + HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props1); + + c->buffer->clear_output (); + + hb_set_unicode_props (c->buffer); + hb_insert_dotted_circle (c->buffer, c->font); + hb_form_clusters (c->buffer); + + hb_ensure_native_direction (c->buffer); + + hb_ot_substitute (c); + hb_ot_position (c); + + hb_ot_hide_default_ignorables (c); + + HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props1); + HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props0); + + c->buffer->props.direction = c->target_direction; + + c->buffer->deallocate_var_all (); +} + + +hb_bool_t +_hb_ot_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features}; + hb_ot_shape_internal (&c); + + return true; +} + + +void +hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, + hb_tag_t table_tag, + hb_set_t *lookup_indexes /* OUT */) +{ + /* XXX Does the first part always succeed? */ + HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes); +} + + +/* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */ +static void +add_char (hb_font_t *font, + hb_unicode_funcs_t *unicode, + hb_bool_t mirror, + hb_codepoint_t u, + hb_set_t *glyphs) +{ + hb_codepoint_t glyph; + if (font->get_glyph (u, 0, &glyph)) + glyphs->add (glyph); + if (mirror) + { + hb_codepoint_t m = unicode->mirroring (u); + if (m != u && font->get_glyph (m, 0, &glyph)) + glyphs->add (glyph); + } +} + + +void +hb_ot_shape_glyphs_closure (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features, + hb_set_t *glyphs) +{ + hb_ot_shape_plan_t plan; + + buffer->guess_segment_properties (); + + const char *shapers[] = {"ot", NULL}; + hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, + features, num_features, shapers); + + bool mirror = hb_script_get_horizontal_direction (buffer->props.script) == HB_DIRECTION_RTL; + + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + add_char (font, buffer->unicode, mirror, buffer->info[i].codepoint, glyphs); + + hb_set_t lookups; + lookups.init (); + hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, &lookups); + + /* And find transitive closure. */ + hb_set_t copy; + copy.init (); + do { + copy.set (glyphs); + for (hb_codepoint_t lookup_index = -1; hb_set_next (&lookups, &lookup_index);) + hb_ot_layout_lookup_substitute_closure (font->face, lookup_index, glyphs); + } while (!copy.is_equal (glyphs)); + + hb_shape_plan_destroy (shape_plan); +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.cc new file mode 100644 index 00000000000..91ebec76ee3 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.cc @@ -0,0 +1,722 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Red Hat Author(s): Behdad Esfahbod + * Google Author(s): Behdad Esfahbod, Roozbeh Pournader + */ + +#include "hb-private.hh" +#include "hb-ot.h" + +#include <string.h> + + + +/* hb_script_t */ + +static hb_tag_t +hb_ot_old_tag_from_script (hb_script_t script) +{ + /* This seems to be accurate as of end of 2012. */ + + switch ((hb_tag_t) script) { + case HB_SCRIPT_INVALID: return HB_OT_TAG_DEFAULT_SCRIPT; + + /* KATAKANA and HIRAGANA both map to 'kana' */ + case HB_SCRIPT_HIRAGANA: return HB_TAG('k','a','n','a'); + + /* Spaces at the end are preserved, unlike ISO 15924 */ + case HB_SCRIPT_LAO: return HB_TAG('l','a','o',' '); + case HB_SCRIPT_YI: return HB_TAG('y','i',' ',' '); + /* Unicode-5.0 additions */ + case HB_SCRIPT_NKO: return HB_TAG('n','k','o',' '); + /* Unicode-5.1 additions */ + case HB_SCRIPT_VAI: return HB_TAG('v','a','i',' '); + /* Unicode-5.2 additions */ + /* Unicode-6.0 additions */ + } + + /* Else, just change first char to lowercase and return */ + return ((hb_tag_t) script) | 0x20000000; +} + +static hb_script_t +hb_ot_old_tag_to_script (hb_tag_t tag) +{ + if (unlikely (tag == HB_OT_TAG_DEFAULT_SCRIPT)) + return HB_SCRIPT_INVALID; + + /* This side of the conversion is fully algorithmic. */ + + /* Any spaces at the end of the tag are replaced by repeating the last + * letter. Eg 'nko ' -> 'Nkoo' */ + if (unlikely ((tag & 0x0000FF00) == 0x00002000)) + tag |= (tag >> 8) & 0x0000FF00; /* Copy second letter to third */ + if (unlikely ((tag & 0x000000FF) == 0x00000020)) + tag |= (tag >> 8) & 0x000000FF; /* Copy third letter to fourth */ + + /* Change first char to uppercase and return */ + return (hb_script_t) (tag & ~0x20000000); +} + +static hb_tag_t +hb_ot_new_tag_from_script (hb_script_t script) +{ + switch ((hb_tag_t) script) { + case HB_SCRIPT_BENGALI: return HB_TAG('b','n','g','2'); + case HB_SCRIPT_DEVANAGARI: return HB_TAG('d','e','v','2'); + case HB_SCRIPT_GUJARATI: return HB_TAG('g','j','r','2'); + case HB_SCRIPT_GURMUKHI: return HB_TAG('g','u','r','2'); + case HB_SCRIPT_KANNADA: return HB_TAG('k','n','d','2'); + case HB_SCRIPT_MALAYALAM: return HB_TAG('m','l','m','2'); + case HB_SCRIPT_ORIYA: return HB_TAG('o','r','y','2'); + case HB_SCRIPT_TAMIL: return HB_TAG('t','m','l','2'); + case HB_SCRIPT_TELUGU: return HB_TAG('t','e','l','2'); + case HB_SCRIPT_MYANMAR: return HB_TAG('m','y','m','2'); + } + + return HB_OT_TAG_DEFAULT_SCRIPT; +} + +static hb_script_t +hb_ot_new_tag_to_script (hb_tag_t tag) +{ + switch (tag) { + case HB_TAG('b','n','g','2'): return HB_SCRIPT_BENGALI; + case HB_TAG('d','e','v','2'): return HB_SCRIPT_DEVANAGARI; + case HB_TAG('g','j','r','2'): return HB_SCRIPT_GUJARATI; + case HB_TAG('g','u','r','2'): return HB_SCRIPT_GURMUKHI; + case HB_TAG('k','n','d','2'): return HB_SCRIPT_KANNADA; + case HB_TAG('m','l','m','2'): return HB_SCRIPT_MALAYALAM; + case HB_TAG('o','r','y','2'): return HB_SCRIPT_ORIYA; + case HB_TAG('t','m','l','2'): return HB_SCRIPT_TAMIL; + case HB_TAG('t','e','l','2'): return HB_SCRIPT_TELUGU; + case HB_TAG('m','y','m','2'): return HB_SCRIPT_MYANMAR; + } + + return HB_SCRIPT_UNKNOWN; +} + +/* + * Complete list at: + * https://www.microsoft.com/typography/otspec/scripttags.htm + * https://www.microsoft.com/typography/otspec160/scripttagsProposed.htm + * + * Most of the script tags are the same as the ISO 15924 tag but lowercased. + * So we just do that, and handle the exceptional cases in a switch. + */ + +void +hb_ot_tags_from_script (hb_script_t script, + hb_tag_t *script_tag_1, + hb_tag_t *script_tag_2) +{ + hb_tag_t new_tag; + + *script_tag_2 = HB_OT_TAG_DEFAULT_SCRIPT; + *script_tag_1 = hb_ot_old_tag_from_script (script); + + new_tag = hb_ot_new_tag_from_script (script); + if (unlikely (new_tag != HB_OT_TAG_DEFAULT_SCRIPT)) { + *script_tag_2 = *script_tag_1; + *script_tag_1 = new_tag; + } +} + +hb_script_t +hb_ot_tag_to_script (hb_tag_t tag) +{ + if (unlikely ((tag & 0x000000FF) == '2')) + return hb_ot_new_tag_to_script (tag); + + return hb_ot_old_tag_to_script (tag); +} + + +/* hb_language_t */ + +typedef struct { + char language[6]; + hb_tag_t tag; +} LangTag; + +/* + * Complete list at: + * http://www.microsoft.com/typography/otspec/languagetags.htm + * + * Generated by intersecting the OpenType language tag list from + * Draft OpenType 1.5 spec, with with the ISO 639-3 codes from + * 2008/08/04, matching on name, and finally adjusted manually. + * + * Updated on 2012/12/07 with more research into remaining codes. + * + * Some items still missing. Those are commented out at the end. + * Keep sorted for bsearch. + */ + +static const LangTag ot_languages[] = { + {"aa", HB_TAG('A','F','R',' ')}, /* Afar */ + {"ab", HB_TAG('A','B','K',' ')}, /* Abkhazian */ + {"abq", HB_TAG('A','B','A',' ')}, /* Abaza */ + {"ada", HB_TAG('D','N','G',' ')}, /* Dangme */ + {"ady", HB_TAG('A','D','Y',' ')}, /* Adyghe */ + {"af", HB_TAG('A','F','K',' ')}, /* Afrikaans */ + {"aii", HB_TAG('S','W','A',' ')}, /* Swadaya Aramaic */ + {"aiw", HB_TAG('A','R','I',' ')}, /* Aari */ + {"alt", HB_TAG('A','L','T',' ')}, /* [Southern] Altai */ + {"am", HB_TAG('A','M','H',' ')}, /* Amharic */ + {"amf", HB_TAG('H','B','N',' ')}, /* Hammer-Banna */ + {"ar", HB_TAG('A','R','A',' ')}, /* Arabic */ + {"arn", HB_TAG('M','A','P',' ')}, /* Mapudungun */ + {"as", HB_TAG('A','S','M',' ')}, /* Assamese */ + {"ath", HB_TAG('A','T','H',' ')}, /* Athapaskan [family] */ + {"atv", HB_TAG('A','L','T',' ')}, /* [Northern] Altai */ + {"av", HB_TAG('A','V','R',' ')}, /* Avaric */ + {"awa", HB_TAG('A','W','A',' ')}, /* Awadhi */ + {"ay", HB_TAG('A','Y','M',' ')}, /* Aymara */ + {"az", HB_TAG('A','Z','E',' ')}, /* Azerbaijani */ + {"ba", HB_TAG('B','S','H',' ')}, /* Bashkir */ + {"bai", HB_TAG('B','M','L',' ')}, /* Bamileke [family] */ + {"bal", HB_TAG('B','L','I',' ')}, /* Baluchi */ + {"bci", HB_TAG('B','A','U',' ')}, /* Baule */ + {"bcq", HB_TAG('B','C','H',' ')}, /* Bench */ + {"be", HB_TAG('B','E','L',' ')}, /* Belarussian */ + {"bem", HB_TAG('B','E','M',' ')}, /* Bemba (Zambia) */ + {"ber", HB_TAG('B','E','R',' ')}, /* Berber [family] */ + {"bfq", HB_TAG('B','A','D',' ')}, /* Badaga */ + {"bft", HB_TAG('B','L','T',' ')}, /* Balti */ + {"bfy", HB_TAG('B','A','G',' ')}, /* Baghelkhandi */ + {"bg", HB_TAG('B','G','R',' ')}, /* Bulgarian */ + {"bhb", HB_TAG('B','H','I',' ')}, /* Bhili */ + {"bho", HB_TAG('B','H','O',' ')}, /* Bhojpuri */ + {"bik", HB_TAG('B','I','K',' ')}, /* Bikol */ + {"bin", HB_TAG('E','D','O',' ')}, /* Bini */ + {"bjt", HB_TAG('B','L','N',' ')}, /* Balanta-Ganja */ + {"bla", HB_TAG('B','K','F',' ')}, /* Blackfoot */ + {"ble", HB_TAG('B','L','N',' ')}, /* Balanta-Kentohe */ + {"bm", HB_TAG('B','M','B',' ')}, /* Bambara */ + {"bn", HB_TAG('B','E','N',' ')}, /* Bengali */ + {"bo", HB_TAG('T','I','B',' ')}, /* Tibetan */ + {"br", HB_TAG('B','R','E',' ')}, /* Breton */ + {"bra", HB_TAG('B','R','I',' ')}, /* Braj Bhasha */ + {"brh", HB_TAG('B','R','H',' ')}, /* Brahui */ + {"bs", HB_TAG('B','O','S',' ')}, /* Bosnian */ + {"btb", HB_TAG('B','T','I',' ')}, /* Beti (Cameroon) */ + {"bxr", HB_TAG('R','B','U',' ')}, /* Russian Buriat */ + {"byn", HB_TAG('B','I','L',' ')}, /* Bilen */ + {"ca", HB_TAG('C','A','T',' ')}, /* Catalan */ + {"ce", HB_TAG('C','H','E',' ')}, /* Chechen */ + {"ceb", HB_TAG('C','E','B',' ')}, /* Cebuano */ + {"chp", HB_TAG('C','H','P',' ')}, /* Chipewyan */ + {"chr", HB_TAG('C','H','R',' ')}, /* Cherokee */ + {"ckt", HB_TAG('C','H','K',' ')}, /* Chukchi */ + {"cop", HB_TAG('C','O','P',' ')}, /* Coptic */ + {"cr", HB_TAG('C','R','E',' ')}, /* Cree */ + {"crh", HB_TAG('C','R','T',' ')}, /* Crimean Tatar */ + {"crj", HB_TAG('E','C','R',' ')}, /* [Southern] East Cree */ + {"crl", HB_TAG('E','C','R',' ')}, /* [Northern] East Cree */ + {"crm", HB_TAG('M','C','R',' ')}, /* Moose Cree */ + {"crx", HB_TAG('C','R','R',' ')}, /* Carrier */ + {"cs", HB_TAG('C','S','Y',' ')}, /* Czech */ + {"cu", HB_TAG('C','S','L',' ')}, /* Church Slavic */ + {"cv", HB_TAG('C','H','U',' ')}, /* Chuvash */ + {"cwd", HB_TAG('D','C','R',' ')}, /* Woods Cree */ + {"cy", HB_TAG('W','E','L',' ')}, /* Welsh */ + {"da", HB_TAG('D','A','N',' ')}, /* Danish */ + {"dap", HB_TAG('N','I','S',' ')}, /* Nisi (India) */ + {"dar", HB_TAG('D','A','R',' ')}, /* Dargwa */ + {"de", HB_TAG('D','E','U',' ')}, /* German */ + {"din", HB_TAG('D','N','K',' ')}, /* Dinka */ + {"dje", HB_TAG('D','J','R',' ')}, /* Djerma */ + {"dng", HB_TAG('D','U','N',' ')}, /* Dungan */ + {"doi", HB_TAG('D','G','R',' ')}, /* Dogri */ + {"dsb", HB_TAG('L','S','B',' ')}, /* Lower Sorbian */ + {"dv", HB_TAG('D','I','V',' ')}, /* Dhivehi */ + {"dyu", HB_TAG('J','U','L',' ')}, /* Jula */ + {"dz", HB_TAG('D','Z','N',' ')}, /* Dzongkha */ + {"ee", HB_TAG('E','W','E',' ')}, /* Ewe */ + {"efi", HB_TAG('E','F','I',' ')}, /* Efik */ + {"el", HB_TAG('E','L','L',' ')}, /* Modern Greek (1453-) */ + {"en", HB_TAG('E','N','G',' ')}, /* English */ + {"eo", HB_TAG('N','T','O',' ')}, /* Esperanto */ + {"eot", HB_TAG('B','T','I',' ')}, /* Beti (Côte d'Ivoire) */ + {"es", HB_TAG('E','S','P',' ')}, /* Spanish */ + {"et", HB_TAG('E','T','I',' ')}, /* Estonian */ + {"eu", HB_TAG('E','U','Q',' ')}, /* Basque */ + {"eve", HB_TAG('E','V','N',' ')}, /* Even */ + {"evn", HB_TAG('E','V','K',' ')}, /* Evenki */ + {"fa", HB_TAG('F','A','R',' ')}, /* Persian */ + {"ff", HB_TAG('F','U','L',' ')}, /* Fulah */ + {"fi", HB_TAG('F','I','N',' ')}, /* Finnish */ + {"fil", HB_TAG('P','I','L',' ')}, /* Filipino */ + {"fj", HB_TAG('F','J','I',' ')}, /* Fijian */ + {"fo", HB_TAG('F','O','S',' ')}, /* Faroese */ + {"fon", HB_TAG('F','O','N',' ')}, /* Fon */ + {"fr", HB_TAG('F','R','A',' ')}, /* French */ + {"fur", HB_TAG('F','R','L',' ')}, /* Friulian */ + {"fy", HB_TAG('F','R','I',' ')}, /* Western Frisian */ + {"ga", HB_TAG('I','R','I',' ')}, /* Irish */ + {"gaa", HB_TAG('G','A','D',' ')}, /* Ga */ + {"gag", HB_TAG('G','A','G',' ')}, /* Gagauz */ + {"gbm", HB_TAG('G','A','W',' ')}, /* Garhwali */ + {"gd", HB_TAG('G','A','E',' ')}, /* Scottish Gaelic */ + {"gez", HB_TAG('G','E','Z',' ')}, /* Ge'ez */ + {"gl", HB_TAG('G','A','L',' ')}, /* Galician */ + {"gld", HB_TAG('N','A','N',' ')}, /* Nanai */ + {"gn", HB_TAG('G','U','A',' ')}, /* Guarani */ + {"gon", HB_TAG('G','O','N',' ')}, /* Gondi */ + {"grt", HB_TAG('G','R','O',' ')}, /* Garo */ + {"gru", HB_TAG('S','O','G',' ')}, /* Sodo Gurage */ + {"gu", HB_TAG('G','U','J',' ')}, /* Gujarati */ + {"guk", HB_TAG('G','M','Z',' ')}, /* Gumuz */ + {"gv", HB_TAG('M','N','X',' ')}, /* Manx Gaelic */ + {"ha", HB_TAG('H','A','U',' ')}, /* Hausa */ + {"har", HB_TAG('H','R','I',' ')}, /* Harari */ + {"haw", HB_TAG('H','A','W',' ')}, /* Hawaiin */ + {"he", HB_TAG('I','W','R',' ')}, /* Hebrew */ + {"hi", HB_TAG('H','I','N',' ')}, /* Hindi */ + {"hil", HB_TAG('H','I','L',' ')}, /* Hiligaynon */ + {"hnd", HB_TAG('H','N','D',' ')}, /* [Southern] Hindko */ + {"hne", HB_TAG('C','H','H',' ')}, /* Chattisgarhi */ + {"hno", HB_TAG('H','N','D',' ')}, /* [Northern] Hindko */ + {"hoc", HB_TAG('H','O',' ',' ')}, /* Ho */ + {"hoj", HB_TAG('H','A','R',' ')}, /* Harauti */ + {"hr", HB_TAG('H','R','V',' ')}, /* Croatian */ + {"hsb", HB_TAG('U','S','B',' ')}, /* Upper Sorbian */ + {"ht", HB_TAG('H','A','I',' ')}, /* Haitian */ + {"hu", HB_TAG('H','U','N',' ')}, /* Hungarian */ + {"hy", HB_TAG('H','Y','E',' ')}, /* Armenian */ + {"id", HB_TAG('I','N','D',' ')}, /* Indonesian */ + {"ig", HB_TAG('I','B','O',' ')}, /* Igbo */ + {"igb", HB_TAG('E','B','I',' ')}, /* Ebira */ + {"ijo", HB_TAG('I','J','O',' ')}, /* Ijo [family] */ + {"ilo", HB_TAG('I','L','O',' ')}, /* Ilokano */ + {"inh", HB_TAG('I','N','G',' ')}, /* Ingush */ + {"is", HB_TAG('I','S','L',' ')}, /* Icelandic */ + {"it", HB_TAG('I','T','A',' ')}, /* Italian */ + {"iu", HB_TAG('I','N','U',' ')}, /* Inuktitut */ + {"ja", HB_TAG('J','A','N',' ')}, /* Japanese */ + {"jv", HB_TAG('J','A','V',' ')}, /* Javanese */ + {"ka", HB_TAG('K','A','T',' ')}, /* Georgian */ + {"kaa", HB_TAG('K','R','K',' ')}, /* Karakalpak */ + {"kam", HB_TAG('K','M','B',' ')}, /* Kamba (Kenya) */ + {"kar", HB_TAG('K','R','N',' ')}, /* Karen [family] */ + {"kbd", HB_TAG('K','A','B',' ')}, /* Kabardian */ + {"kdr", HB_TAG('K','R','M',' ')}, /* Karaim */ + {"kdt", HB_TAG('K','U','Y',' ')}, /* Kuy */ + {"kex", HB_TAG('K','K','N',' ')}, /* Kokni */ + {"kfr", HB_TAG('K','A','C',' ')}, /* Kachchi */ + {"kfy", HB_TAG('K','M','N',' ')}, /* Kumaoni */ + {"kha", HB_TAG('K','S','I',' ')}, /* Khasi */ + {"khb", HB_TAG('X','B','D',' ')}, /* Tai Lue */ + {"khw", HB_TAG('K','H','W',' ')}, /* Khowar */ + {"ki", HB_TAG('K','I','K',' ')}, /* Kikuyu */ + {"kjh", HB_TAG('K','H','A',' ')}, /* Khakass */ + {"kk", HB_TAG('K','A','Z',' ')}, /* Kazakh */ + {"kl", HB_TAG('G','R','N',' ')}, /* Kalaallisut */ + {"kln", HB_TAG('K','A','L',' ')}, /* Kalenjin */ + {"km", HB_TAG('K','H','M',' ')}, /* Central Khmer */ + {"kmb", HB_TAG('M','B','N',' ')}, /* [North] Mbundu */ + {"kmw", HB_TAG('K','M','O',' ')}, /* Komo (Democratic Republic of Congo) */ + {"kn", HB_TAG('K','A','N',' ')}, /* Kannada */ + {"ko", HB_TAG('K','O','R',' ')}, /* Korean */ + {"koi", HB_TAG('K','O','P',' ')}, /* Komi-Permyak */ + {"kok", HB_TAG('K','O','K',' ')}, /* Konkani */ + {"kpe", HB_TAG('K','P','L',' ')}, /* Kpelle */ + {"kpv", HB_TAG('K','O','Z',' ')}, /* Komi-Zyrian */ + {"kpy", HB_TAG('K','Y','K',' ')}, /* Koryak */ + {"kqy", HB_TAG('K','R','T',' ')}, /* Koorete */ + {"kr", HB_TAG('K','N','R',' ')}, /* Kanuri */ + {"kri", HB_TAG('K','R','I',' ')}, /* Krio */ + {"krl", HB_TAG('K','R','L',' ')}, /* Karelian */ + {"kru", HB_TAG('K','U','U',' ')}, /* Kurukh */ + {"ks", HB_TAG('K','S','H',' ')}, /* Kashmiri */ + {"ku", HB_TAG('K','U','R',' ')}, /* Kurdish */ + {"kum", HB_TAG('K','U','M',' ')}, /* Kumyk */ + {"kvd", HB_TAG('K','U','I',' ')}, /* Kui (Indonesia) */ + {"kxc", HB_TAG('K','M','S',' ')}, /* Komso */ + {"kxu", HB_TAG('K','U','I',' ')}, /* Kui (India) */ + {"ky", HB_TAG('K','I','R',' ')}, /* Kirghiz */ + {"la", HB_TAG('L','A','T',' ')}, /* Latin */ + {"lad", HB_TAG('J','U','D',' ')}, /* Ladino */ + {"lb", HB_TAG('L','T','Z',' ')}, /* Luxembourgish */ + {"lbe", HB_TAG('L','A','K',' ')}, /* Lak */ + {"lbj", HB_TAG('L','D','K',' ')}, /* Ladakhi */ + {"lez", HB_TAG('L','E','Z',' ')}, /* Lezgi */ + {"lg", HB_TAG('L','U','G',' ')}, /* Luganda */ + {"lif", HB_TAG('L','M','B',' ')}, /* Limbu */ + {"lld", HB_TAG('L','A','D',' ')}, /* Ladin */ + {"lmn", HB_TAG('L','A','M',' ')}, /* Lambani */ + {"ln", HB_TAG('L','I','N',' ')}, /* Lingala */ + {"lo", HB_TAG('L','A','O',' ')}, /* Lao */ + {"lt", HB_TAG('L','T','H',' ')}, /* Lithuanian */ + {"lu", HB_TAG('L','U','B',' ')}, /* Luba-Katanga */ + {"lua", HB_TAG('L','U','B',' ')}, /* Luba-Kasai */ + {"luo", HB_TAG('L','U','O',' ')}, /* Luo (Kenya and Tanzania) */ + {"lus", HB_TAG('M','I','Z',' ')}, /* Mizo */ + {"luy", HB_TAG('L','U','H',' ')}, /* Luhya [macrolanguage] */ + {"lv", HB_TAG('L','V','I',' ')}, /* Latvian */ + {"lzz", HB_TAG('L','A','Z',' ')}, /* Laz */ + {"mai", HB_TAG('M','T','H',' ')}, /* Maithili */ + {"mdc", HB_TAG('M','L','E',' ')}, /* Male (Papua New Guinea) */ + {"mdf", HB_TAG('M','O','K',' ')}, /* Moksha */ + {"mdy", HB_TAG('M','L','E',' ')}, /* Male (Ethiopia) */ + {"men", HB_TAG('M','D','E',' ')}, /* Mende (Sierra Leone) */ + {"mg", HB_TAG('M','L','G',' ')}, /* Malagasy */ + {"mhr", HB_TAG('L','M','A',' ')}, /* Low Mari */ + {"mi", HB_TAG('M','R','I',' ')}, /* Maori */ + {"mk", HB_TAG('M','K','D',' ')}, /* Macedonian */ + {"ml", HB_TAG('M','L','R',' ')}, /* Malayalam */ + {"mn", HB_TAG('M','N','G',' ')}, /* Mongolian */ + {"mnc", HB_TAG('M','C','H',' ')}, /* Manchu */ + {"mni", HB_TAG('M','N','I',' ')}, /* Manipuri */ + {"mnk", HB_TAG('M','N','D',' ')}, /* Mandinka */ + {"mns", HB_TAG('M','A','N',' ')}, /* Mansi */ + {"mnw", HB_TAG('M','O','N',' ')}, /* Mon */ + {"mo", HB_TAG('M','O','L',' ')}, /* Moldavian */ + {"moh", HB_TAG('M','O','H',' ')}, /* Mohawk */ + {"mpe", HB_TAG('M','A','J',' ')}, /* Majang */ + {"mr", HB_TAG('M','A','R',' ')}, /* Marathi */ + {"mrj", HB_TAG('H','M','A',' ')}, /* High Mari */ + {"ms", HB_TAG('M','L','Y',' ')}, /* Malay */ + {"mt", HB_TAG('M','T','S',' ')}, /* Maltese */ + {"mwr", HB_TAG('M','A','W',' ')}, /* Marwari */ + {"my", HB_TAG('B','R','M',' ')}, /* Burmese */ + {"mym", HB_TAG('M','E','N',' ')}, /* Me'en */ + {"myv", HB_TAG('E','R','Z',' ')}, /* Erzya */ + {"nag", HB_TAG('N','A','G',' ')}, /* Naga-Assamese */ + {"nb", HB_TAG('N','O','R',' ')}, /* Norwegian Bokmål */ + {"nco", HB_TAG('S','I','B',' ')}, /* Sibe */ + {"nd", HB_TAG('N','D','B',' ')}, /* [North] Ndebele */ + {"ne", HB_TAG('N','E','P',' ')}, /* Nepali */ + {"new", HB_TAG('N','E','W',' ')}, /* Newari */ + {"ng", HB_TAG('N','D','G',' ')}, /* Ndonga */ + {"ngl", HB_TAG('L','M','W',' ')}, /* Lomwe */ + {"niu", HB_TAG('N','I','U',' ')}, /* Niuean */ + {"niv", HB_TAG('G','I','L',' ')}, /* Gilyak */ + {"nl", HB_TAG('N','L','D',' ')}, /* Dutch */ + {"nn", HB_TAG('N','Y','N',' ')}, /* Norwegian Nynorsk */ + {"no", HB_TAG('N','O','R',' ')}, /* Norwegian (deprecated) */ + {"nod", HB_TAG('N','T','A',' ')}, /* Northern Tai */ + {"nog", HB_TAG('N','O','G',' ')}, /* Nogai */ + {"nqo", HB_TAG('N','K','O',' ')}, /* N'Ko */ + {"nr", HB_TAG('N','D','B',' ')}, /* [South] Ndebele */ + {"nsk", HB_TAG('N','A','S',' ')}, /* Naskapi */ + {"nso", HB_TAG('S','O','T',' ')}, /* [Northern] Sotho */ + {"ny", HB_TAG('C','H','I',' ')}, /* Nyanja */ + {"nyn", HB_TAG('N','K','L',' ')}, /* Nkole */ + {"oc", HB_TAG('O','C','I',' ')}, /* Occitan (post 1500) */ + {"oj", HB_TAG('O','J','B',' ')}, /* Ojibwa */ + {"ojs", HB_TAG('O','C','R',' ')}, /* Oji-Cree */ + {"om", HB_TAG('O','R','O',' ')}, /* Oromo */ + {"or", HB_TAG('O','R','I',' ')}, /* Oriya */ + {"os", HB_TAG('O','S','S',' ')}, /* Ossetian */ + {"pa", HB_TAG('P','A','N',' ')}, /* Panjabi */ + {"pce", HB_TAG('P','L','G',' ')}, /* [Ruching] Palaung */ + {"pi", HB_TAG('P','A','L',' ')}, /* Pali */ + {"pl", HB_TAG('P','L','K',' ')}, /* Polish */ + {"pll", HB_TAG('P','L','G',' ')}, /* [Shwe] Palaung */ + {"plp", HB_TAG('P','A','P',' ')}, /* Palpa */ + {"prs", HB_TAG('D','R','I',' ')}, /* Dari */ + {"ps", HB_TAG('P','A','S',' ')}, /* Pushto */ + {"pt", HB_TAG('P','T','G',' ')}, /* Portuguese */ + {"raj", HB_TAG('R','A','J',' ')}, /* Rajasthani */ + {"rbb", HB_TAG('P','L','G',' ')}, /* [Rumai] Palaung */ + {"ria", HB_TAG('R','I','A',' ')}, /* Riang (India) */ + {"ril", HB_TAG('R','I','A',' ')}, /* Riang (Myanmar) */ + {"rki", HB_TAG('A','R','K',' ')}, /* Arakanese */ + {"rm", HB_TAG('R','M','S',' ')}, /* Rhaeto-Romanic */ + {"ro", HB_TAG('R','O','M',' ')}, /* Romanian */ + {"rom", HB_TAG('R','O','Y',' ')}, /* Romany */ + {"ru", HB_TAG('R','U','S',' ')}, /* Russian */ + {"rue", HB_TAG('R','S','Y',' ')}, /* Rusyn */ + {"rw", HB_TAG('R','U','A',' ')}, /* Ruanda */ + {"sa", HB_TAG('S','A','N',' ')}, /* Sanskrit */ + {"sah", HB_TAG('Y','A','K',' ')}, /* Yakut */ + {"sat", HB_TAG('S','A','T',' ')}, /* Santali */ + {"sck", HB_TAG('S','A','D',' ')}, /* Sadri */ + {"scs", HB_TAG('S','L','A',' ')}, /* [North] Slavey */ + {"sd", HB_TAG('S','N','D',' ')}, /* Sindhi */ + {"se", HB_TAG('N','S','M',' ')}, /* Northern Sami */ + {"seh", HB_TAG('S','N','A',' ')}, /* Sena */ + {"sel", HB_TAG('S','E','L',' ')}, /* Selkup */ + {"sg", HB_TAG('S','G','O',' ')}, /* Sango */ + {"shn", HB_TAG('S','H','N',' ')}, /* Shan */ + {"si", HB_TAG('S','N','H',' ')}, /* Sinhala */ + {"sid", HB_TAG('S','I','D',' ')}, /* Sidamo */ + {"sjd", HB_TAG('K','S','M',' ')}, /* Kildin Sami */ + {"sk", HB_TAG('S','K','Y',' ')}, /* Slovak */ + {"skr", HB_TAG('S','R','K',' ')}, /* Seraiki */ + {"sl", HB_TAG('S','L','V',' ')}, /* Slovenian */ + {"sm", HB_TAG('S','M','O',' ')}, /* Samoan */ + {"sma", HB_TAG('S','S','M',' ')}, /* Southern Sami */ + {"smj", HB_TAG('L','S','M',' ')}, /* Lule Sami */ + {"smn", HB_TAG('I','S','M',' ')}, /* Inari Sami */ + {"sms", HB_TAG('S','K','S',' ')}, /* Skolt Sami */ + {"snk", HB_TAG('S','N','K',' ')}, /* Soninke */ + {"so", HB_TAG('S','M','L',' ')}, /* Somali */ + {"sq", HB_TAG('S','Q','I',' ')}, /* Albanian */ + {"sr", HB_TAG('S','R','B',' ')}, /* Serbian */ + {"srr", HB_TAG('S','R','R',' ')}, /* Serer */ + {"ss", HB_TAG('S','W','Z',' ')}, /* Swazi */ + {"st", HB_TAG('S','O','T',' ')}, /* [Southern] Sotho */ + {"suq", HB_TAG('S','U','R',' ')}, /* Suri */ + {"sv", HB_TAG('S','V','E',' ')}, /* Swedish */ + {"sva", HB_TAG('S','V','A',' ')}, /* Svan */ + {"sw", HB_TAG('S','W','K',' ')}, /* Swahili */ + {"swb", HB_TAG('C','M','R',' ')}, /* Comorian */ + {"syr", HB_TAG('S','Y','R',' ')}, /* Syriac */ + {"ta", HB_TAG('T','A','M',' ')}, /* Tamil */ + {"tab", HB_TAG('T','A','B',' ')}, /* Tabasaran */ + {"tcy", HB_TAG('T','U','L',' ')}, /* Tulu */ + {"te", HB_TAG('T','E','L',' ')}, /* Telugu */ + {"tem", HB_TAG('T','M','N',' ')}, /* Temne */ + {"tg", HB_TAG('T','A','J',' ')}, /* Tajik */ + {"th", HB_TAG('T','H','A',' ')}, /* Thai */ + {"ti", HB_TAG('T','G','Y',' ')}, /* Tigrinya */ + {"tig", HB_TAG('T','G','R',' ')}, /* Tigre */ + {"tk", HB_TAG('T','K','M',' ')}, /* Turkmen */ + {"tn", HB_TAG('T','N','A',' ')}, /* Tswana */ + {"to", HB_TAG('T','G','N',' ')}, /* Tonga (Tonga Islands) */ + {"tr", HB_TAG('T','R','K',' ')}, /* Turkish */ + {"tru", HB_TAG('T','U','A',' ')}, /* Turoyo Aramaic */ + {"ts", HB_TAG('T','S','G',' ')}, /* Tsonga */ + {"tt", HB_TAG('T','A','T',' ')}, /* Tatar */ + {"tw", HB_TAG('T','W','I',' ')}, /* Twi */ + {"ty", HB_TAG('T','H','T',' ')}, /* Tahitian */ + {"tyv", HB_TAG('T','U','V',' ')}, /* Tuvin */ + {"udm", HB_TAG('U','D','M',' ')}, /* Udmurt */ + {"ug", HB_TAG('U','Y','G',' ')}, /* Uighur */ + {"uk", HB_TAG('U','K','R',' ')}, /* Ukrainian */ + {"umb", HB_TAG('M','B','N',' ')}, /* [South] Mbundu */ + {"unr", HB_TAG('M','U','N',' ')}, /* Mundari */ + {"ur", HB_TAG('U','R','D',' ')}, /* Urdu */ + {"uz", HB_TAG('U','Z','B',' ')}, /* Uzbek */ + {"ve", HB_TAG('V','E','N',' ')}, /* Venda */ + {"vi", HB_TAG('V','I','T',' ')}, /* Vietnamese */ + {"vmw", HB_TAG('M','A','K',' ')}, /* Makua */ + {"wbm", HB_TAG('W','A',' ',' ')}, /* Wa */ + {"wbr", HB_TAG('W','A','G',' ')}, /* Wagdi */ + {"wo", HB_TAG('W','L','F',' ')}, /* Wolof */ + {"xal", HB_TAG('K','L','M',' ')}, /* Kalmyk */ + {"xh", HB_TAG('X','H','S',' ')}, /* Xhosa */ + {"xom", HB_TAG('K','M','O',' ')}, /* Komo (Sudan) */ + {"xsl", HB_TAG('S','S','L',' ')}, /* South Slavey */ + {"yi", HB_TAG('J','I','I',' ')}, /* Yiddish */ + {"yo", HB_TAG('Y','B','A',' ')}, /* Yoruba */ + {"yso", HB_TAG('N','I','S',' ')}, /* Nisi (China) */ + {"zne", HB_TAG('Z','N','D',' ')}, /* Zande */ + {"zu", HB_TAG('Z','U','L',' ')} /* Zulu */ + + /* The corresponding languages IDs for the following IDs are unclear, + * overlap, or are architecturally weird. Needs more research. */ + +/*{"ahg/awn/xan?", HB_TAG('A','G','W',' ')},*/ /* Agaw */ +/*{"gsw?/gsw-FR?", HB_TAG('A','L','S',' ')},*/ /* Alsatian */ +/*{"krc", HB_TAG('B','A','L',' ')},*/ /* Balkar */ +/*{"??", HB_TAG('B','C','R',' ')},*/ /* Bible Cree */ +/*{"sgw?", HB_TAG('C','H','G',' ')},*/ /* Chaha Gurage */ +/*{"acf/gcf?", HB_TAG('F','A','N',' ')},*/ /* French Antillean */ +/*{"vls/nl-be", HB_TAG('F','L','E',' ')},*/ /* Flemish */ +/*{"enf?/yrk?", HB_TAG('F','N','E',' ')},*/ /* Forest Nenets */ +/*{"fuf?", HB_TAG('F','T','A',' ')},*/ /* Futa */ +/*{"ar-Syrc?", HB_TAG('G','A','R',' ')},*/ /* Garshuni */ +/*{"cfm/rnl?", HB_TAG('H','A','L',' ')},*/ /* Halam */ +/*{"ga-Latg?/Latg?", HB_TAG('I','R','T',' ')},*/ /* Irish Traditional */ +/*{"krc", HB_TAG('K','A','R',' ')},*/ /* Karachay */ +/*{"alw?/ktb?", HB_TAG('K','E','B',' ')},*/ /* Kebena */ +/*{"Geok", HB_TAG('K','G','E',' ')},*/ /* Khutsuri Georgian */ +/*{"kca", HB_TAG('K','H','K',' ')},*/ /* Khanty-Kazim */ +/*{"kca", HB_TAG('K','H','S',' ')},*/ /* Khanty-Shurishkar */ +/*{"kca", HB_TAG('K','H','V',' ')},*/ /* Khanty-Vakhi */ +/*{"guz?/kqs?/kss?", HB_TAG('K','I','S',' ')},*/ /* Kisii */ +/*{"kfa/kfi?/kpb?/xua?/xuj?", HB_TAG('K','O','D',' ')},*/ /* Kodagu */ +/*{"okm?/oko?", HB_TAG('K','O','H',' ')},*/ /* Korean Old Hangul */ +/*{"kon?/ktu?/...", HB_TAG('K','O','N',' ')},*/ /* Kikongo */ +/*{"kfx?", HB_TAG('K','U','L',' ')},*/ /* Kulvi */ +/*{"??", HB_TAG('L','A','H',' ')},*/ /* Lahuli */ +/*{"??", HB_TAG('L','C','R',' ')},*/ /* L-Cree */ +/*{"??", HB_TAG('M','A','L',' ')},*/ /* Malayalam Traditional */ +/*{"mnk?/mlq?/...", HB_TAG('M','L','N',' ')},*/ /* Malinke */ +/*{"man?/myq?/mku?/msc?/...", HB_TAG('M','N','K',' ')},*/ /* Maninka */ +/*{"??", HB_TAG('M','O','R',' ')},*/ /* Moroccan */ +/*{"??", HB_TAG('N','C','R',' ')},*/ /* N-Cree */ +/*{"??", HB_TAG('N','H','C',' ')},*/ /* Norway House Cree */ +/*{"jpa?/sam?", HB_TAG('P','A','A',' ')},*/ /* Palestinian Aramaic */ +/*{"polyton", HB_TAG('P','G','R',' ')},*/ /* Polytonic Greek */ +/*{"??", HB_TAG('Q','I','N',' ')},*/ /* Asho Chin */ +/*{"??", HB_TAG('R','C','R',' ')},*/ /* R-Cree */ +/*{"chp?", HB_TAG('S','A','Y',' ')},*/ /* Sayisi */ +/*{"xan?", HB_TAG('S','E','K',' ')},*/ /* Sekota */ +/*{"stv/wle?/xst?", HB_TAG('S','I','G',' ')},*/ /* Silte Gurage */ +/*{"ngo?", HB_TAG('S','X','T',' ')},*/ /* Sutu */ +/*{"??", HB_TAG('T','C','R',' ')},*/ /* TH-Cree */ +/*{"tnz?/tog?/toi?", HB_TAG('T','N','G',' ')},*/ /* Tonga */ +/*{"enh?/yrk?", HB_TAG('T','N','E',' ')},*/ /* Tundra Nenets */ +/*{"??", HB_TAG('T','O','D',' ')},*/ /* Todo */ +/*{"??", HB_TAG('W','C','R',' ')},*/ /* West-Cree */ +/*{"??", HB_TAG('Y','C','R',' ')},*/ /* Y-Cree */ +/*{"??", HB_TAG('Y','I','C',' ')},*/ /* Yi Classic */ +/*{"ii?/Yiii?", HB_TAG('Y','I','M',' ')},*/ /* Yi Modern */ +/*{"??", HB_TAG('Z','H','P',' ')},*/ /* Chinese Phonetic */ +}; + +static const LangTag ot_languages_zh[] = { + {"zh-cn", HB_TAG('Z','H','S',' ')}, /* Chinese (China) */ + {"zh-hk", HB_TAG('Z','H','H',' ')}, /* Chinese (Hong Kong) */ + {"zh-mo", HB_TAG('Z','H','T',' ')}, /* Chinese (Macao) */ + {"zh-sg", HB_TAG('Z','H','S',' ')}, /* Chinese (Singapore) */ + {"zh-tw", HB_TAG('Z','H','T',' ')} /* Chinese (Taiwan) */ +}; + +static int +lang_compare_first_component (const char *a, + const char *b) +{ + unsigned int da, db; + const char *p; + + p = strchr (a, '-'); + da = p ? (unsigned int) (p - a) : strlen (a); + + p = strchr (b, '-'); + db = p ? (unsigned int) (p - b) : strlen (b); + + return strncmp (a, b, MAX (da, db)); +} + +static hb_bool_t +lang_matches (const char *lang_str, const char *spec) +{ + unsigned int len = strlen (spec); + + return strncmp (lang_str, spec, len) == 0 && + (lang_str[len] == '\0' || lang_str[len] == '-'); +} + +hb_tag_t +hb_ot_tag_from_language (hb_language_t language) +{ + const char *lang_str, *s; + const LangTag *lang_tag; + + if (language == HB_LANGUAGE_INVALID) + return HB_OT_TAG_DEFAULT_LANGUAGE; + + lang_str = hb_language_to_string (language); + + s = strstr (lang_str, "x-hbot"); + if (s) { + char tag[4]; + int i; + s += 6; + for (i = 0; i < 4 && ISALPHA (s[i]); i++) + tag[i] = TOUPPER (s[i]); + if (i) { + for (; i < 4; i++) + tag[i] = ' '; + return HB_TAG_CHAR4 (tag); + } + } + + /* Find a language matching in the first component */ + lang_tag = (LangTag *) bsearch (lang_str, ot_languages, + ARRAY_LENGTH (ot_languages), sizeof (LangTag), + (hb_compare_func_t) lang_compare_first_component); + if (lang_tag) + return lang_tag->tag; + + /* Otherwise, check the Chinese ones */ + if (0 == lang_compare_first_component (lang_str, "zh")) + { + unsigned int i; + + for (i = 0; i < ARRAY_LENGTH (ot_languages_zh); i++) + { + lang_tag = &ot_languages_zh[i]; + if (lang_matches (lang_tag->language, lang_str)) + return lang_tag->tag; + } + + /* Otherwise just return 'ZHS ' */ + return HB_TAG('Z','H','S',' '); + } + + s = strchr (lang_str, '-'); + if (!s) + s = lang_str + strlen (lang_str); + if (s - lang_str == 3) { + /* Assume it's ISO-639-3 and upper-case and use it. */ + return hb_tag_from_string (lang_str, s - lang_str) & ~0x20202000; + } + + return HB_OT_TAG_DEFAULT_LANGUAGE; +} + +hb_language_t +hb_ot_tag_to_language (hb_tag_t tag) +{ + unsigned int i; + + if (tag == HB_OT_TAG_DEFAULT_LANGUAGE) + return NULL; + + for (i = 0; i < ARRAY_LENGTH (ot_languages); i++) + if (ot_languages[i].tag == tag) + return hb_language_from_string (ot_languages[i].language, -1); + + /* If tag starts with ZH, it's Chinese */ + if ((tag & 0xFFFF0000) == 0x5A480000) { + switch (tag) { + case HB_TAG('Z','H','H',' '): return hb_language_from_string ("zh-hk", -1); /* Hong Kong */ + default: { + /* Encode the tag... */ + unsigned char buf[14] = "zh-x-hbot"; + buf[9] = tag >> 24; + buf[10] = (tag >> 16) & 0xFF; + buf[11] = (tag >> 8) & 0xFF; + buf[12] = tag & 0xFF; + if (buf[12] == 0x20) + buf[12] = '\0'; + buf[13] = '\0'; + return hb_language_from_string ((char *) buf, -1); + } + } + } + + /* Else return a custom language in the form of "x-hbotABCD" */ + { + unsigned char buf[11] = "x-hbot"; + buf[6] = tag >> 24; + buf[7] = (tag >> 16) & 0xFF; + buf[8] = (tag >> 8) & 0xFF; + buf[9] = tag & 0xFF; + if (buf[9] == 0x20) + buf[9] = '\0'; + buf[10] = '\0'; + return hb_language_from_string ((char *) buf, -1); + } +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.h new file mode 100644 index 00000000000..1bf12ab3c09 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot-tag.h @@ -0,0 +1,59 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_OT_H_IN +#error "Include <hb-ot.h> instead." +#endif + +#ifndef HB_OT_TAG_H +#define HB_OT_TAG_H + +#include "hb.h" + +HB_BEGIN_DECLS + + +#define HB_OT_TAG_DEFAULT_SCRIPT HB_TAG ('D', 'F', 'L', 'T') +#define HB_OT_TAG_DEFAULT_LANGUAGE HB_TAG ('d', 'f', 'l', 't') + +void +hb_ot_tags_from_script (hb_script_t script, + hb_tag_t *script_tag_1, + hb_tag_t *script_tag_2); + +hb_script_t +hb_ot_tag_to_script (hb_tag_t tag); + +hb_tag_t +hb_ot_tag_from_language (hb_language_t language); + +hb_language_t +hb_ot_tag_to_language (hb_tag_t tag); + + +HB_END_DECLS + +#endif /* HB_OT_TAG_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot.h new file mode 100644 index 00000000000..80739063991 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ot.h @@ -0,0 +1,49 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_OT_H +#define HB_OT_H +#define HB_OT_H_IN + +#include "hb.h" + +#include "hb-ot-layout.h" +#include "hb-ot-tag.h" + +HB_BEGIN_DECLS + +/* TODO remove */ +void +hb_ot_shape_glyphs_closure (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features, + hb_set_t *glyphs); + +HB_END_DECLS + +#undef HB_OT_H_IN +#endif /* HB_OT_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-private.hh new file mode 100644 index 00000000000..be0d505f7b5 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-private.hh @@ -0,0 +1,857 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, Inc. + * Copyright © 2011,2012 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_PRIVATE_HH +#define HB_PRIVATE_HH + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "hb.h" +#define HB_H_IN +#ifdef HAVE_OT +#include "hb-ot.h" +#define HB_OT_H_IN +#endif + +#include <stdlib.h> +#include <stddef.h> +#include <string.h> +#include <assert.h> + +/* We only use these two for debug output. However, the debug code is + * always seen by the compiler (and optimized out in non-debug builds. + * If including these becomes a problem, we can start thinking about + * someway around that. */ +#include <stdio.h> +#include <errno.h> +#include <stdarg.h> + + + +/* Essentials */ + +#ifndef NULL +# define NULL ((void *) 0) +#endif + + +/* Void! */ +struct _hb_void_t {}; +typedef const _hb_void_t &hb_void_t; +#define HB_VOID (* (const _hb_void_t *) NULL) + + +/* 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; } + + +#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) + +#define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1] +#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond)) +#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond)) + +#define ASSERT_STATIC_EXPR(_cond)((void) sizeof (char[(_cond) ? 1 : -1])) +#define ASSERT_STATIC_EXPR_ZERO(_cond) (0 * sizeof (char[(_cond) ? 1 : -1])) + +#define _PASTE1(a,b) a##b +#define PASTE(a,b) _PASTE1(a,b) + +/* Lets assert int types. Saves trouble down the road. */ + +ASSERT_STATIC (sizeof (int8_t) == 1); +ASSERT_STATIC (sizeof (uint8_t) == 1); +ASSERT_STATIC (sizeof (int16_t) == 2); +ASSERT_STATIC (sizeof (uint16_t) == 2); +ASSERT_STATIC (sizeof (int32_t) == 4); +ASSERT_STATIC (sizeof (uint32_t) == 4); +ASSERT_STATIC (sizeof (int64_t) == 8); +ASSERT_STATIC (sizeof (uint64_t) == 8); + +ASSERT_STATIC (sizeof (hb_codepoint_t) == 4); +ASSERT_STATIC (sizeof (hb_position_t) == 4); +ASSERT_STATIC (sizeof (hb_mask_t) == 4); +ASSERT_STATIC (sizeof (hb_var_int_t) == 4); + + +/* We like our types POD */ + +#define _ASSERT_TYPE_POD1(_line, _type) union _type_##_type##_on_line_##_line##_is_not_POD { _type instance; } +#define _ASSERT_TYPE_POD0(_line, _type) _ASSERT_TYPE_POD1 (_line, _type) +#define ASSERT_TYPE_POD(_type) _ASSERT_TYPE_POD0 (__LINE__, _type) + +#ifdef __GNUC__ +# define _ASSERT_INSTANCE_POD1(_line, _instance) \ + HB_STMT_START { \ + typedef __typeof__(_instance) _type_##_line; \ + _ASSERT_TYPE_POD1 (_line, _type_##_line); \ + } HB_STMT_END +#else +# define _ASSERT_INSTANCE_POD1(_line, _instance) typedef int _assertion_on_line_##_line##_not_tested +#endif +# define _ASSERT_INSTANCE_POD0(_line, _instance) _ASSERT_INSTANCE_POD1 (_line, _instance) +# define ASSERT_INSTANCE_POD(_instance) _ASSERT_INSTANCE_POD0 (__LINE__, _instance) + +/* Check _assertion in a method environment */ +#define _ASSERT_POD1(_line) \ + inline void _static_assertion_on_line_##_line (void) const \ + { _ASSERT_INSTANCE_POD1 (_line, *this); /* Make sure it's POD. */ } +# define _ASSERT_POD0(_line) _ASSERT_POD1 (_line) +# define ASSERT_POD() _ASSERT_POD0 (__LINE__) + + + +/* Misc */ + + +#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) +#define _HB_BOOLEAN_EXPR(expr) ((expr) ? 1 : 0) +#define likely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1)) +#define unlikely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0)) +#else +#define likely(expr) (expr) +#define unlikely(expr) (expr) +#endif + +#ifndef __GNUC__ +#undef __attribute__ +#define __attribute__(x) +#endif + +#if __GNUC__ >= 3 +#define HB_PURE_FUNC __attribute__((pure)) +#define HB_CONST_FUNC __attribute__((const)) +#define HB_PRINTF_FUNC(format_idx, arg_idx) __attribute__((__format__ (__printf__, format_idx, arg_idx))) +#else +#define HB_PURE_FUNC +#define HB_CONST_FUNC +#define HB_PRINTF_FUNC(format_idx, arg_idx) +#endif +#if __GNUC__ >= 4 +#define HB_UNUSED __attribute__((unused)) +#else +#define HB_UNUSED +#endif + +#ifndef HB_INTERNAL +# ifndef __MINGW32__ +# define HB_INTERNAL __attribute__((__visibility__("hidden"))) +# else +# define HB_INTERNAL +# endif +#endif + + +#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER) +#define snprintf _snprintf +#endif + +#ifdef _MSC_VER +#undef inline +#define inline __inline +#endif + +#ifdef __STRICT_ANSI__ +#undef inline +#define inline __inline__ +#endif + + +#if __GNUC__ >= 3 +#define HB_FUNC __PRETTY_FUNCTION__ +#elif defined(_MSC_VER) +#define HB_FUNC __FUNCSIG__ +#else +#define HB_FUNC __func__ +#endif + + +/* Return the number of 1 bits in mask. */ +static inline HB_CONST_FUNC unsigned int +_hb_popcount32 (uint32_t mask) +{ +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + return __builtin_popcount (mask); +#else + /* "HACKMEM 169" */ + register uint32_t y; + y = (mask >> 1) &033333333333; + y = mask - y - ((y >>1) & 033333333333); + return (((y + (y >> 3)) & 030707070707) % 077); +#endif +} + +/* Returns the number of bits needed to store number */ +static inline HB_CONST_FUNC unsigned int +_hb_bit_storage (unsigned int number) +{ +#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) + return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clz (number)) : 0; +#else + register unsigned int n_bits = 0; + while (number) { + n_bits++; + number >>= 1; + } + return n_bits; +#endif +} + +/* Returns the number of zero bits in the least significant side of number */ +static inline HB_CONST_FUNC unsigned int +_hb_ctz (unsigned int number) +{ +#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) + return likely (number) ? __builtin_ctz (number) : 0; +#else + register unsigned int n_bits = 0; + if (unlikely (!number)) return 0; + while (!(number & 1)) { + n_bits++; + number >>= 1; + } + return n_bits; +#endif +} + +static inline bool +_hb_unsigned_int_mul_overflows (unsigned int count, unsigned int size) +{ + return (size > 0) && (count >= ((unsigned int) -1) / size); +} + + +/* Type of bsearch() / qsort() compare function */ +typedef int (*hb_compare_func_t) (const void *, const void *); + + + + +/* arrays and maps */ + + +#define HB_PREALLOCED_ARRAY_INIT {0} +template <typename Type, unsigned int StaticSize> +struct hb_prealloced_array_t +{ + unsigned int len; + unsigned int allocated; + Type *array; + Type static_array[StaticSize]; + + void init (void) { memset (this, 0, sizeof (*this)); } + + inline Type& operator [] (unsigned int i) { return array[i]; } + inline const Type& operator [] (unsigned int i) const { return array[i]; } + + inline Type *push (void) + { + if (!array) { + array = static_array; + allocated = ARRAY_LENGTH (static_array); + } + if (likely (len < allocated)) + return &array[len++]; + + /* Need to reallocate */ + unsigned int new_allocated = allocated + (allocated >> 1) + 8; + Type *new_array = NULL; + + if (array == static_array) { + new_array = (Type *) calloc (new_allocated, sizeof (Type)); + if (new_array) + memcpy (new_array, array, 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 (array, new_allocated * sizeof (Type)); + } + } + + if (unlikely (!new_array)) + return NULL; + + array = new_array; + allocated = new_allocated; + return &array[len++]; + } + + inline void pop (void) + { + len--; + /* TODO: shrink array if needed */ + } + + inline void shrink (unsigned int l) + { + if (l < len) + len = l; + /* TODO: shrink array if needed */ + } + + template <typename T> + inline Type *find (T v) { + for (unsigned int i = 0; i < len; i++) + if (array[i] == v) + return &array[i]; + return NULL; + } + template <typename T> + inline const Type *find (T v) const { + for (unsigned int i = 0; i < len; i++) + if (array[i] == v) + return &array[i]; + return NULL; + } + + inline void sort (void) + { + qsort (array, len, sizeof (Type), (hb_compare_func_t) Type::cmp); + } + + inline void sort (unsigned int start, unsigned int end) + { + qsort (array + start, end - start, sizeof (Type), (hb_compare_func_t) Type::cmp); + } + + template <typename T> + inline Type *bsearch (T *key) + { + return (Type *) ::bsearch (key, array, len, sizeof (Type), (hb_compare_func_t) Type::cmp); + } + template <typename T> + inline const Type *bsearch (T *key) const + { + return (const Type *) ::bsearch (key, array, len, sizeof (Type), (hb_compare_func_t) Type::cmp); + } + + inline void finish (void) + { + if (array != static_array) + free (array); + array = NULL; + allocated = len = 0; + } +}; + + +#define HB_LOCKABLE_SET_INIT {HB_PREALLOCED_ARRAY_INIT} +template <typename item_t, typename lock_t> +struct hb_lockable_set_t +{ + hb_prealloced_array_t <item_t, 2> 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.finish (); + } + else { + item = NULL; + l.unlock (); + } + } else { + item = items.push (); + if (likely (item)) + *item = 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.finish (); + } 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 (); + if (likely (item)) + *item = v; + } + l.unlock (); + return item; + } + + inline void finish (lock_t &l) + { + if (!items.len) { + /* No need for locking. */ + items.finish (); + return; + } + l.lock (); + while (items.len) { + item_t old = items[items.len - 1]; + items.pop (); + l.unlock (); + old.finish (); + l.lock (); + } + items.finish (); + l.unlock (); + } + +}; + + + + +/* Big-endian handling */ + +static inline uint16_t hb_be_uint16 (const uint16_t v) +{ + const uint8_t *V = (const uint8_t *) &v; + return (V[0] << 8) | V[1]; +} + +static inline uint16_t hb_uint16_swap (const uint16_t v) +{ + return (v >> 8) | (v << 8); +} + +static inline uint32_t hb_uint32_swap (const uint32_t v) +{ + return (hb_uint16_swap (v) << 16) | hb_uint16_swap (v >> 16); +} + +/* Note, of the following macros, uint16_get is the one called many many times. + * If there is any optimizations to be done, it's in that macro. However, I + * already confirmed that on my T400 ThinkPad at least, using bswap_16(), which + * results in a single ror instruction, does NOT speed this up. In fact, it + * resulted in a minor slowdown. At any rate, note that v may not be correctly + * aligned, so I think the current implementation is optimal. + */ + +#define hb_be_uint16_put(v,V) HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END +#define hb_be_uint16_get(v) (uint16_t) ((v[0] << 8) + v[1]) +#define hb_be_uint16_eq(a,b) (a[0] == b[0] && a[1] == b[1]) + +#define hb_be_uint32_put(v,V) HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16); v[2] = (V>>8); v[3] = (V); } HB_STMT_END +#define hb_be_uint32_get(v) (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3]) +#define hb_be_uint32_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]) + +#define hb_be_uint24_put(v,V) HB_STMT_START { v[0] = (V>>16); v[1] = (V>>8); v[2] (V); } HB_STMT_END +#define hb_be_uint24_get(v) (uint32_t) ((v[0] << 16) + (v[1] << 8) + v[2]) +#define hb_be_uint24_eq(a,b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) + + +/* ASCII tag/character handling */ + +static inline unsigned char ISALPHA (unsigned char c) +{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } +static inline unsigned char ISALNUM (unsigned char c) +{ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } +static inline unsigned char TOUPPER (unsigned char c) +{ return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; } +static inline unsigned char TOLOWER (unsigned char c) +{ return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; } + +#define HB_TAG_CHAR4(s) (HB_TAG(((const char *) s)[0], \ + ((const char *) s)[1], \ + ((const char *) s)[2], \ + ((const char *) s)[3])) + + +/* C++ helpers */ + +/* Makes class uncopyable. Use in private: section. */ +#define NO_COPY(T) \ + T (const T &o); \ + T &operator = (const T &o) + + +/* Debug */ + + +#ifndef HB_DEBUG +#define HB_DEBUG 0 +#endif + +static inline bool +_hb_debug (unsigned int level, + unsigned int max_level) +{ + return level < max_level; +} + +#define DEBUG_LEVEL(WHAT, LEVEL) (_hb_debug ((LEVEL), HB_DEBUG_##WHAT)) +#define DEBUG(WHAT) (DEBUG_LEVEL (WHAT, 0)) + +template <int max_level> static inline void +_hb_debug_msg_va (const char *what, + const void *obj, + const char *func, + bool indented, + unsigned int level, + int level_dir, + const char *message, + va_list ap) +{ + if (!_hb_debug (level, max_level)) + return; + + fprintf (stderr, "%-10s", what ? what : ""); + + if (obj) + fprintf (stderr, "(%0*lx) ", (unsigned int) (2 * sizeof (void *)), (unsigned long) obj); + else + fprintf (stderr, " %*s ", (unsigned int) (2 * sizeof (void *)), ""); + + if (indented) { +/* One may want to add ASCII version of these. See: + * https://bugs.freedesktop.org/show_bug.cgi?id=50970 */ +#define VBAR "\342\224\202" /* U+2502 BOX DRAWINGS LIGHT VERTICAL */ +#define VRBAR "\342\224\234" /* U+251C BOX DRAWINGS LIGHT VERTICAL AND RIGHT */ +#define DLBAR "\342\225\256" /* U+256E BOX DRAWINGS LIGHT ARC DOWN AND LEFT */ +#define ULBAR "\342\225\257" /* U+256F BOX DRAWINGS LIGHT ARC UP AND LEFT */ +#define LBAR "\342\225\264" /* U+2574 BOX DRAWINGS LIGHT LEFT */ + static const char bars[] = VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR VBAR; + fprintf (stderr, "%2d %s" VRBAR "%s", + level, + bars + sizeof (bars) - 1 - MIN ((unsigned int) sizeof (bars), (unsigned int) (sizeof (VBAR) - 1) * level), + level_dir ? (level_dir > 0 ? DLBAR : ULBAR) : LBAR); + } else + fprintf (stderr, " " VRBAR LBAR); + + if (func) + { + /* Skip "typename" */ + if (0 == strncmp (func, "typename ", 9)) + func += 9; + /* Skip return type */ + const char *space = strchr (func, ' '); + if (space) + func = space + 1; + /* Skip parameter list */ + const char *paren = strchr (func, '('); + unsigned int func_len = paren ? paren - func : strlen (func); + fprintf (stderr, "%.*s: ", func_len, func); + } + + if (message) + vfprintf (stderr, message, ap); + + fprintf (stderr, "\n"); +} +template <> inline void +_hb_debug_msg_va<0> (const char *what HB_UNUSED, + const void *obj HB_UNUSED, + const char *func HB_UNUSED, + bool indented HB_UNUSED, + unsigned int level HB_UNUSED, + int level_dir HB_UNUSED, + const char *message HB_UNUSED, + va_list ap HB_UNUSED) {} + +template <int max_level> static inline void +_hb_debug_msg (const char *what, + const void *obj, + const char *func, + bool indented, + unsigned int level, + int level_dir, + const char *message, + ...) HB_PRINTF_FUNC(7, 8); +template <int max_level> static inline void +_hb_debug_msg (const char *what, + const void *obj, + const char *func, + bool indented, + unsigned int level, + int level_dir, + const char *message, + ...) +{ + va_list ap; + va_start (ap, message); + _hb_debug_msg_va<max_level> (what, obj, func, indented, level, level_dir, message, ap); + va_end (ap); +} +template <> inline void +_hb_debug_msg<0> (const char *what HB_UNUSED, + const void *obj HB_UNUSED, + const char *func HB_UNUSED, + bool indented HB_UNUSED, + unsigned int level HB_UNUSED, + int level_dir HB_UNUSED, + const char *message HB_UNUSED, + ...) HB_PRINTF_FUNC(7, 8); +template <> inline void +_hb_debug_msg<0> (const char *what HB_UNUSED, + const void *obj HB_UNUSED, + const char *func HB_UNUSED, + bool indented HB_UNUSED, + unsigned int level HB_UNUSED, + int level_dir HB_UNUSED, + const char *message HB_UNUSED, + ...) {} + +#define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, LEVEL_DIR, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, true, (LEVEL), (LEVEL_DIR), __VA_ARGS__) +#define DEBUG_MSG(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, false, 0, 0, __VA_ARGS__) +#define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, false, 0, 0, __VA_ARGS__) + + +/* + * Printer + */ + +template <typename T> +struct hb_printer_t {}; + +template <> +struct hb_printer_t<bool> { + const char *print (bool v) { return v ? "true" : "false"; } +}; + +template <> +struct hb_printer_t<hb_void_t> { + const char *print (hb_void_t) { return ""; } +}; + + +/* + * Trace + */ + +template <typename T> +static inline void _hb_warn_no_return (bool returned) +{ + if (unlikely (!returned)) { + fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report.\n"); + } +} +template <> +inline void _hb_warn_no_return<hb_void_t> (bool returned HB_UNUSED) +{} + +template <int max_level, typename ret_t> +struct hb_auto_trace_t { + explicit inline hb_auto_trace_t (unsigned int *plevel_, + const char *what_, + const void *obj_, + const char *func, + const char *message, + ...) : plevel (plevel_), what (what_), obj (obj_), returned (false) + { + if (plevel) ++*plevel; + + va_list ap; + va_start (ap, message); + _hb_debug_msg_va<max_level> (what, obj, func, true, plevel ? *plevel : 0, +1, message, ap); + va_end (ap); + } + inline ~hb_auto_trace_t (void) + { + _hb_warn_no_return<ret_t> (returned); + if (!returned) { + _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, " "); + } + if (plevel) --*plevel; + } + + inline ret_t ret (ret_t v, unsigned int line = 0) + { + if (unlikely (returned)) { + fprintf (stderr, "OUCH, double calls to TRACE_RETURN. This is a bug, please report.\n"); + return v; + } + + _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, + "return %s (line %d)", + hb_printer_t<ret_t>().print (v), line); + if (plevel) --*plevel; + plevel = NULL; + returned = true; + return v; + } + + private: + unsigned int *plevel; + const char *what; + const void *obj; + bool returned; +}; +template <typename ret_t> /* Optimize when tracing is disabled */ +struct hb_auto_trace_t<0, ret_t> { + explicit inline hb_auto_trace_t (unsigned int *plevel_ HB_UNUSED, + const char *what HB_UNUSED, + const void *obj HB_UNUSED, + const char *func HB_UNUSED, + const char *message HB_UNUSED, + ...) {} + + inline ret_t ret (ret_t v, unsigned int line HB_UNUSED = 0) { return v; } +}; + +#define TRACE_RETURN(RET) trace.ret (RET, __LINE__) + +/* Misc */ + + +/* Pre-mature optimization: + * Checks for lo <= u <= hi but with an optimization if lo and hi + * are only different in a contiguous set of lower-most bits. + */ +template <typename T> static inline bool +hb_in_range (T u, T lo, T hi) +{ + if ( ((lo^hi) & lo) == 0 && + ((lo^hi) & hi) == (lo^hi) && + ((lo^hi) & ((lo^hi) + 1)) == 0 ) + return (u & ~(lo^hi)) == lo; + else + return lo <= u && u <= hi; +} + +template <typename T> static inline bool +hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) +{ + return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (u, lo3, hi3); +} + + +/* Useful for set-operations on small enums. + * For example, for testing "x ∈ {x1, x2, x3}" use: + * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) + */ +#define FLAG(x) (1<<(x)) +#define FLAG_RANGE(x,y) (ASSERT_STATIC_EXPR_ZERO ((x) < (y)) + FLAG(y+1) - FLAG(x)) + + +template <typename T, typename T2> inline void +hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) +{ + if (unlikely (!len)) + return; + + unsigned int k = len - 1; + do { + unsigned int new_k = 0; + + for (unsigned int j = 0; j < k; j++) + if (compar (&array[j], &array[j+1]) > 0) + { + { + T t; + t = array[j]; + array[j] = array[j + 1]; + array[j + 1] = t; + } + if (array2) + { + T2 t; + t = array2[j]; + array2[j] = array2[j + 1]; + array2[j + 1] = t; + } + + new_k = j; + } + k = new_k; + } while (k); +} + +template <typename T> inline void +hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) +{ + hb_bubble_sort (array, len, compar, (int *) NULL); +} + +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]; + strncpy (buf, s, MIN (ARRAY_LENGTH (buf) - 1, len)); + buf[MIN (ARRAY_LENGTH (buf) - 1, 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; +} + + +#endif /* HB_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set-private.hh new file mode 100644 index 00000000000..5e30a7e3616 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set-private.hh @@ -0,0 +1,324 @@ +/* + * Copyright © 2012 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_SET_PRIVATE_HH +#define HB_SET_PRIVATE_HH + +#include "hb-private.hh" +#include "hb-set.h" +#include "hb-object-private.hh" + + +struct hb_set_digest_common_bits_t +{ + ASSERT_POD (); + + typedef unsigned int mask_t; + + inline void init (void) { + mask = ~0; + value = (mask_t) -1; + } + + inline void add (hb_codepoint_t g) { + if (unlikely (value == (mask_t) -1)) { + value = g; + return; + } + + mask ^= (g & mask) ^ value; + value &= mask; + } + + inline void add_range (hb_codepoint_t a, hb_codepoint_t b) { + /* The negation here stands for ~(x-1). */ + mask &= -(1 << _hb_bit_storage (a ^ b)); + value &= mask; + } + + inline bool may_have (hb_codepoint_t g) const { + return (g & mask) == value; + } + + private: + mask_t mask; + mask_t value; +}; + +struct hb_set_digest_lowest_bits_t +{ + ASSERT_POD (); + + typedef unsigned long mask_t; + + inline void init (void) { + mask = 0; + } + + inline void add (hb_codepoint_t g) { + mask |= mask_for (g); + } + + inline void add_range (hb_codepoint_t a, hb_codepoint_t b) { + if (b - a >= sizeof (mask_t) * 8 - 1) + mask = (mask_t) -1; + else { + mask_t ma = mask_for (a); + mask_t mb = mask_for (b); + mask |= mb + (mb - ma) - (mb < ma); + } + } + + inline bool may_have (hb_codepoint_t g) const { + return !!(mask & mask_for (g)); + } + + private: + + static inline mask_t mask_for (hb_codepoint_t g) { return ((mask_t) 1) << (g & (sizeof (mask_t) * 8 - 1)); } + mask_t mask; +}; + +struct hb_set_digest_t +{ + ASSERT_POD (); + + inline void init (void) { + digest1.init (); + digest2.init (); + } + + inline void add (hb_codepoint_t g) { + digest1.add (g); + digest2.add (g); + } + + inline void add_range (hb_codepoint_t a, hb_codepoint_t b) { + digest1.add_range (a, b); + digest2.add_range (a, b); + } + + inline bool may_have (hb_codepoint_t g) const { + return digest1.may_have (g) && digest2.may_have (g); + } + + private: + hb_set_digest_common_bits_t digest1; + hb_set_digest_lowest_bits_t digest2; +}; + + +/* TODO Make this faster and memmory efficient. */ + +struct hb_set_t +{ + hb_object_header_t header; + ASSERT_POD (); + bool in_error; + + inline void init (void) { + header.init (); + clear (); + } + inline void fini (void) { + } + inline void clear (void) { + if (unlikely (hb_object_is_inert (this))) + return; + in_error = false; + memset (elts, 0, sizeof elts); + } + inline bool is_empty (void) const { + for (unsigned int i = 0; i < ARRAY_LENGTH (elts); i++) + if (elts[i]) + return false; + return true; + } + inline void add (hb_codepoint_t g) + { + if (unlikely (in_error)) return; + if (unlikely (g == SENTINEL)) return; + if (unlikely (g > MAX_G)) return; + elt (g) |= mask (g); + } + inline void add_range (hb_codepoint_t a, hb_codepoint_t b) + { + if (unlikely (in_error)) return; + /* TODO Speedup */ + for (unsigned int i = a; i < b + 1; i++) + add (i); + } + inline void del (hb_codepoint_t g) + { + if (unlikely (in_error)) return; + if (unlikely (g > MAX_G)) return; + elt (g) &= ~mask (g); + } + inline void del_range (hb_codepoint_t a, hb_codepoint_t b) + { + if (unlikely (in_error)) return; + /* TODO Speedup */ + for (unsigned int i = a; i < b + 1; i++) + del (i); + } + inline bool has (hb_codepoint_t g) const + { + if (unlikely (g > MAX_G)) return false; + return !!(elt (g) & mask (g)); + } + inline bool intersects (hb_codepoint_t first, + hb_codepoint_t last) const + { + if (unlikely (first > MAX_G)) return false; + if (unlikely (last > MAX_G)) last = MAX_G; + unsigned int end = last + 1; + for (hb_codepoint_t i = first; i < end; i++) + if (has (i)) + return true; + return false; + } + inline bool is_equal (const hb_set_t *other) const + { + for (unsigned int i = 0; i < ELTS; i++) + if (elts[i] != other->elts[i]) + return false; + return true; + } + inline void set (const hb_set_t *other) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] = other->elts[i]; + } + inline void union_ (const hb_set_t *other) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] |= other->elts[i]; + } + inline void intersect (const hb_set_t *other) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] &= other->elts[i]; + } + inline void subtract (const hb_set_t *other) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] &= ~other->elts[i]; + } + inline void symmetric_difference (const hb_set_t *other) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] ^= other->elts[i]; + } + inline void invert (void) + { + if (unlikely (in_error)) return; + for (unsigned int i = 0; i < ELTS; i++) + elts[i] = ~elts[i]; + } + inline bool next (hb_codepoint_t *codepoint) const + { + if (unlikely (*codepoint == SENTINEL)) { + hb_codepoint_t i = get_min (); + if (i != SENTINEL) { + *codepoint = i; + return true; + } else + return false; + } + for (hb_codepoint_t i = *codepoint + 1; i < MAX_G + 1; i++) + if (has (i)) { + *codepoint = i; + return true; + } + return false; + } + inline bool next_range (hb_codepoint_t *first, hb_codepoint_t *last) const + { + hb_codepoint_t i; + + i = *last; + if (!next (&i)) + return false; + + *last = *first = i; + while (next (&i) && i == *last + 1) + (*last)++; + + return true; + } + + inline unsigned int get_population (void) const + { + unsigned int count = 0; + for (unsigned int i = 0; i < ELTS; i++) + count += _hb_popcount32 (elts[i]); + return count; + } + inline hb_codepoint_t get_min (void) const + { + for (unsigned int i = 0; i < ELTS; i++) + if (elts[i]) + for (unsigned int j = 0; i < BITS; j++) + if (elts[i] & (1 << j)) + return i * BITS + j; + return SENTINEL; + } + inline hb_codepoint_t get_max (void) const + { + for (unsigned int i = ELTS; i; i--) + if (elts[i - 1]) + for (unsigned int j = BITS; j; j--) + if (elts[i - 1] & (1 << (j - 1))) + return (i - 1) * BITS + (j - 1); + return SENTINEL; + } + + typedef uint32_t elt_t; + static const unsigned int MAX_G = 65536 - 1; /* XXX Fix this... */ + static const unsigned int SHIFT = 5; + static const unsigned int BITS = (1 << SHIFT); + static const unsigned int MASK = BITS - 1; + static const unsigned int ELTS = (MAX_G + 1 + (BITS - 1)) / BITS; + static const hb_codepoint_t SENTINEL = (hb_codepoint_t) -1; + + elt_t &elt (hb_codepoint_t g) { return elts[g >> SHIFT]; } + elt_t elt (hb_codepoint_t g) const { return elts[g >> SHIFT]; } + elt_t mask (hb_codepoint_t g) const { return elt_t (1) << (g & MASK); } + + elt_t elts[ELTS]; /* XXX 8kb */ + + ASSERT_STATIC (sizeof (elt_t) * 8 == BITS); + ASSERT_STATIC (sizeof (elt_t) * 8 * ELTS > MAX_G); +}; + + + +#endif /* HB_SET_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.cc new file mode 100644 index 00000000000..5f427a5d8e0 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.cc @@ -0,0 +1,228 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-set-private.hh" + + + +/* Public API */ + + +hb_set_t * +hb_set_create (void) +{ + hb_set_t *set; + + if (!(set = hb_object_create<hb_set_t> ())) + return hb_set_get_empty (); + + set->clear (); + + return set; +} + +hb_set_t * +hb_set_get_empty (void) +{ + static const hb_set_t _hb_set_nil = { + HB_OBJECT_HEADER_STATIC, + true, /* in_error */ + + {0} /* elts */ + }; + + return const_cast<hb_set_t *> (&_hb_set_nil); +} + +hb_set_t * +hb_set_reference (hb_set_t *set) +{ + return hb_object_reference (set); +} + +void +hb_set_destroy (hb_set_t *set) +{ + if (!hb_object_destroy (set)) return; + + set->fini (); + + free (set); +} + +hb_bool_t +hb_set_set_user_data (hb_set_t *set, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (set, key, data, destroy, replace); +} + +void * +hb_set_get_user_data (hb_set_t *set, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (set, key); +} + + +hb_bool_t +hb_set_allocation_successful (const hb_set_t *set HB_UNUSED) +{ + return !set->in_error; +} + +void +hb_set_clear (hb_set_t *set) +{ + set->clear (); +} + +hb_bool_t +hb_set_is_empty (const hb_set_t *set) +{ + return set->is_empty (); +} + +hb_bool_t +hb_set_has (const hb_set_t *set, + hb_codepoint_t codepoint) +{ + return set->has (codepoint); +} + +void +hb_set_add (hb_set_t *set, + hb_codepoint_t codepoint) +{ + set->add (codepoint); +} + +void +hb_set_add_range (hb_set_t *set, + hb_codepoint_t first, + hb_codepoint_t last) +{ + set->add_range (first, last); +} + +void +hb_set_del (hb_set_t *set, + hb_codepoint_t codepoint) +{ + set->del (codepoint); +} + +void +hb_set_del_range (hb_set_t *set, + hb_codepoint_t first, + hb_codepoint_t last) +{ + set->del_range (first, last); +} + +hb_bool_t +hb_set_is_equal (const hb_set_t *set, + const hb_set_t *other) +{ + return set->is_equal (other); +} + +void +hb_set_set (hb_set_t *set, + const hb_set_t *other) +{ + set->set (other); +} + +void +hb_set_union (hb_set_t *set, + const hb_set_t *other) +{ + set->union_ (other); +} + +void +hb_set_intersect (hb_set_t *set, + const hb_set_t *other) +{ + set->intersect (other); +} + +void +hb_set_subtract (hb_set_t *set, + const hb_set_t *other) +{ + set->subtract (other); +} + +void +hb_set_symmetric_difference (hb_set_t *set, + const hb_set_t *other) +{ + set->symmetric_difference (other); +} + +void +hb_set_invert (hb_set_t *set) +{ + set->invert (); +} + +unsigned int +hb_set_get_population (const hb_set_t *set) +{ + return set->get_population (); +} + +hb_codepoint_t +hb_set_get_min (const hb_set_t *set) +{ + return set->get_min (); +} + +hb_codepoint_t +hb_set_get_max (const hb_set_t *set) +{ + return set->get_max (); +} + +hb_bool_t +hb_set_next (const hb_set_t *set, + hb_codepoint_t *codepoint) +{ + return set->next (codepoint); +} + +hb_bool_t +hb_set_next_range (const hb_set_t *set, + hb_codepoint_t *first, + hb_codepoint_t *last) +{ + return set->next_range (first, last); +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.h new file mode 100644 index 00000000000..291e24974e6 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-set.h @@ -0,0 +1,152 @@ +/* + * Copyright © 2012 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_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_SET_H +#define HB_SET_H + +#include "hb-common.h" + +HB_BEGIN_DECLS + + +typedef struct hb_set_t hb_set_t; + + +hb_set_t * +hb_set_create (void); + +hb_set_t * +hb_set_get_empty (void); + +hb_set_t * +hb_set_reference (hb_set_t *set); + +void +hb_set_destroy (hb_set_t *set); + +hb_bool_t +hb_set_set_user_data (hb_set_t *set, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + +void * +hb_set_get_user_data (hb_set_t *set, + hb_user_data_key_t *key); + + +/* Returns false if allocation has failed before */ +hb_bool_t +hb_set_allocation_successful (const hb_set_t *set); + +void +hb_set_clear (hb_set_t *set); + +hb_bool_t +hb_set_is_empty (const hb_set_t *set); + +hb_bool_t +hb_set_has (const hb_set_t *set, + hb_codepoint_t codepoint); + +/* Right now limited to 16-bit integers. Eventually will do full codepoint range, sans -1 + * which we will use as a sentinel. */ +void +hb_set_add (hb_set_t *set, + hb_codepoint_t codepoint); + +void +hb_set_add_range (hb_set_t *set, + hb_codepoint_t first, + hb_codepoint_t last); + +void +hb_set_del (hb_set_t *set, + hb_codepoint_t codepoint); + +void +hb_set_del_range (hb_set_t *set, + hb_codepoint_t first, + hb_codepoint_t last); + +hb_bool_t +hb_set_is_equal (const hb_set_t *set, + const hb_set_t *other); + +void +hb_set_set (hb_set_t *set, + const hb_set_t *other); + +void +hb_set_union (hb_set_t *set, + const hb_set_t *other); + +void +hb_set_intersect (hb_set_t *set, + const hb_set_t *other); + +void +hb_set_subtract (hb_set_t *set, + const hb_set_t *other); + +void +hb_set_symmetric_difference (hb_set_t *set, + const hb_set_t *other); + +void +hb_set_invert (hb_set_t *set); + +unsigned int +hb_set_get_population (const hb_set_t *set); + +/* Returns -1 if set empty. */ +hb_codepoint_t +hb_set_get_min (const hb_set_t *set); + +/* Returns -1 if set empty. */ +hb_codepoint_t +hb_set_get_max (const hb_set_t *set); + +/* Pass -1 in to get started. */ +hb_bool_t +hb_set_next (const hb_set_t *set, + hb_codepoint_t *codepoint); + +/* Pass -1 for first and last to get started. */ +hb_bool_t +hb_set_next_range (const hb_set_t *set, + hb_codepoint_t *first, + hb_codepoint_t *last); + + +HB_END_DECLS + +#endif /* HB_SET_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan-private.hh new file mode 100644 index 00000000000..dd014e38d01 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan-private.hh @@ -0,0 +1,60 @@ +/* + * Copyright © 2012 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_SHAPE_PLAN_PRIVATE_HH +#define HB_SHAPE_PLAN_PRIVATE_HH + +#include "hb-private.hh" +#include "hb-shape-plan.h" +#include "hb-object-private.hh" +#include "hb-shaper-private.hh" + + +struct hb_shape_plan_t +{ + hb_object_header_t header; + ASSERT_POD (); + + hb_bool_t default_shaper_list; + hb_face_t *face; + hb_segment_properties_t props; + + hb_shape_func_t *shaper_func; + const char *shaper_name; + + struct hb_shaper_data_t shaper_data; +}; + +#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \ + , const hb_feature_t *user_features \ + , unsigned int num_user_features +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, shape_plan); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT +#undef HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS + + +#endif /* HB_SHAPE_PLAN_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.cc new file mode 100644 index 00000000000..22a226f3a6c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.cc @@ -0,0 +1,308 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-shape-plan-private.hh" +#include "hb-shaper-private.hh" +#include "hb-font-private.hh" + +#define HB_SHAPER_IMPLEMENT(shaper) \ + HB_SHAPER_DATA_ENSURE_DECLARE(shaper, face) \ + HB_SHAPER_DATA_ENSURE_DECLARE(shaper, font) +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + + +static void +hb_shape_plan_plan (hb_shape_plan_t *shape_plan, + const hb_feature_t *user_features, + unsigned int num_user_features, + const char * const *shaper_list) +{ + const hb_shaper_pair_t *shapers = _hb_shapers_get (); + +#define HB_SHAPER_PLAN(shaper) \ + HB_STMT_START { \ + if (hb_##shaper##_shaper_face_data_ensure (shape_plan->face)) { \ + HB_SHAPER_DATA (shaper, shape_plan) = \ + HB_SHAPER_DATA_CREATE_FUNC (shaper, shape_plan) (shape_plan, user_features, num_user_features); \ + shape_plan->shaper_func = _hb_##shaper##_shape; \ + shape_plan->shaper_name = #shaper; \ + return; \ + } \ + } HB_STMT_END + + if (likely (!shaper_list)) { + for (unsigned int i = 0; i < HB_SHAPERS_COUNT; i++) + if (0) + ; +#define HB_SHAPER_IMPLEMENT(shaper) \ + else if (shapers[i].func == _hb_##shaper##_shape) \ + HB_SHAPER_PLAN (shaper); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } else { + for (; *shaper_list; shaper_list++) + if (0) + ; +#define HB_SHAPER_IMPLEMENT(shaper) \ + else if (0 == strcmp (*shaper_list, #shaper)) \ + HB_SHAPER_PLAN (shaper); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } + +#undef HB_SHAPER_PLAN +} + + +/* + * hb_shape_plan_t + */ + +hb_shape_plan_t * +hb_shape_plan_create (hb_face_t *face, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features, + const char * const *shaper_list) +{ + assert (props->direction != HB_DIRECTION_INVALID); + + hb_shape_plan_t *shape_plan; + + if (unlikely (!face)) + face = hb_face_get_empty (); + if (unlikely (!props || hb_object_is_inert (face))) + return hb_shape_plan_get_empty (); + if (!(shape_plan = hb_object_create<hb_shape_plan_t> ())) + return hb_shape_plan_get_empty (); + + hb_face_make_immutable (face); + shape_plan->default_shaper_list = shaper_list == NULL; + shape_plan->face = hb_face_reference (face); + shape_plan->props = *props; + + hb_shape_plan_plan (shape_plan, user_features, num_user_features, shaper_list); + + return shape_plan; +} + +hb_shape_plan_t * +hb_shape_plan_get_empty (void) +{ + static const hb_shape_plan_t _hb_shape_plan_nil = { + HB_OBJECT_HEADER_STATIC, + + true, /* default_shaper_list */ + NULL, /* face */ + HB_SEGMENT_PROPERTIES_DEFAULT, /* props */ + + NULL, /* shaper_func */ + NULL, /* shaper_name */ + + { +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } + }; + + return const_cast<hb_shape_plan_t *> (&_hb_shape_plan_nil); +} + +hb_shape_plan_t * +hb_shape_plan_reference (hb_shape_plan_t *shape_plan) +{ + return hb_object_reference (shape_plan); +} + +void +hb_shape_plan_destroy (hb_shape_plan_t *shape_plan) +{ + if (!hb_object_destroy (shape_plan)) return; + +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_DESTROY(shaper, shape_plan); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + + hb_face_destroy (shape_plan->face); + + free (shape_plan); +} + +hb_bool_t +hb_shape_plan_set_user_data (hb_shape_plan_t *shape_plan, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (shape_plan, key, data, destroy, replace); +} + +void * +hb_shape_plan_get_user_data (hb_shape_plan_t *shape_plan, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (shape_plan, key); +} + + +hb_bool_t +hb_shape_plan_execute (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + if (unlikely (shape_plan->face != font->face)) + return false; + +#define HB_SHAPER_EXECUTE(shaper) \ + HB_STMT_START { \ + return HB_SHAPER_DATA (shaper, shape_plan) && \ + hb_##shaper##_shaper_font_data_ensure (font) && \ + _hb_##shaper##_shape (shape_plan, font, buffer, features, num_features); \ + } HB_STMT_END + + if (0) + ; +#define HB_SHAPER_IMPLEMENT(shaper) \ + else if (shape_plan->shaper_func == _hb_##shaper##_shape) \ + HB_SHAPER_EXECUTE (shaper); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + +#undef HB_SHAPER_EXECUTE + + return false; +} + + +/* + * caching + */ + +#if 0 +static unsigned int +hb_shape_plan_hash (const hb_shape_plan_t *shape_plan) +{ + return hb_segment_properties_hash (&shape_plan->props) + + shape_plan->default_shaper_list ? 0 : (intptr_t) shape_plan->shaper_func; +} +#endif + +/* TODO no user-feature caching for now. */ +struct hb_shape_plan_proposal_t +{ + const hb_segment_properties_t props; + const char * const *shaper_list; + hb_shape_func_t *shaper_func; +}; + +static hb_bool_t +hb_shape_plan_matches (const hb_shape_plan_t *shape_plan, + const hb_shape_plan_proposal_t *proposal) +{ + return hb_segment_properties_equal (&shape_plan->props, &proposal->props) && + ((shape_plan->default_shaper_list && proposal->shaper_list == NULL) || + (shape_plan->shaper_func == proposal->shaper_func)); +} + +hb_shape_plan_t * +hb_shape_plan_create_cached (hb_face_t *face, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features, + const char * const *shaper_list) +{ + if (num_user_features) + return hb_shape_plan_create (face, props, user_features, num_user_features, shaper_list); + + hb_shape_plan_proposal_t proposal = { + *props, + shaper_list, + NULL + }; + + if (shaper_list) { + /* Choose shaper. Adapted from hb_shape_plan_plan(). */ +#define HB_SHAPER_PLAN(shaper) \ + HB_STMT_START { \ + if (hb_##shaper##_shaper_face_data_ensure (face)) \ + proposal.shaper_func = _hb_##shaper##_shape; \ + } HB_STMT_END + + for (const char * const *shaper_item = shaper_list; *shaper_item; shaper_item++) + if (0) + ; +#define HB_SHAPER_IMPLEMENT(shaper) \ + else if (0 == strcmp (*shaper_item, #shaper)) \ + HB_SHAPER_PLAN (shaper); +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + +#undef HB_SHAPER_PLAN + + if (unlikely (!proposal.shaper_list)) + return hb_shape_plan_get_empty (); + } + + +retry: + hb_face_t::plan_node_t *cached_plan_nodes = (hb_face_t::plan_node_t *) hb_atomic_ptr_get (&face->shape_plans); + for (hb_face_t::plan_node_t *node = cached_plan_nodes; node; node = node->next) + if (hb_shape_plan_matches (node->shape_plan, &proposal)) + return hb_shape_plan_reference (node->shape_plan); + + /* Not found. */ + + hb_shape_plan_t *shape_plan = hb_shape_plan_create (face, props, user_features, num_user_features, shaper_list); + + hb_face_t::plan_node_t *node = (hb_face_t::plan_node_t *) calloc (1, sizeof (hb_face_t::plan_node_t)); + if (unlikely (!node)) + return shape_plan; + + node->shape_plan = shape_plan; + node->next = cached_plan_nodes; + + if (!hb_atomic_ptr_cmpexch (&face->shape_plans, cached_plan_nodes, node)) { + hb_shape_plan_destroy (shape_plan); + free (node); + goto retry; + } + + /* Release our reference on face. */ + hb_face_destroy (face); + + return hb_shape_plan_reference (shape_plan); +} + +const char * +hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan) +{ + return shape_plan->shaper_name; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.h new file mode 100644 index 00000000000..8f54552f90b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape-plan.h @@ -0,0 +1,89 @@ +/* + * Copyright © 2012 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_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_SHAPE_PLAN_H +#define HB_SHAPE_PLAN_H + +#include "hb-common.h" +#include "hb-font.h" + +HB_BEGIN_DECLS + +typedef struct hb_shape_plan_t hb_shape_plan_t; + +hb_shape_plan_t * +hb_shape_plan_create (hb_face_t *face, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features, + const char * const *shaper_list); + +hb_shape_plan_t * +hb_shape_plan_create_cached (hb_face_t *face, + const hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features, + const char * const *shaper_list); + +hb_shape_plan_t * +hb_shape_plan_get_empty (void); + +hb_shape_plan_t * +hb_shape_plan_reference (hb_shape_plan_t *shape_plan); + +void +hb_shape_plan_destroy (hb_shape_plan_t *shape_plan); + +hb_bool_t +hb_shape_plan_set_user_data (hb_shape_plan_t *shape_plan, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + +void * +hb_shape_plan_get_user_data (hb_shape_plan_t *shape_plan, + hb_user_data_key_t *key); + + +hb_bool_t +hb_shape_plan_execute (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features); + +const char * +hb_shape_plan_get_shaper (hb_shape_plan_t *shape_plan); + + +HB_END_DECLS + +#endif /* HB_SHAPE_PLAN_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.cc new file mode 100644 index 00000000000..389ce3e34b1 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.cc @@ -0,0 +1,276 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2012 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 + */ + +#include "hb-private.hh" + +#include "hb-shaper-private.hh" +#include "hb-shape-plan-private.hh" +#include "hb-buffer-private.hh" +#include "hb-font-private.hh" + + +static void +parse_space (const char **pp, const char *end) +{ + char c; +#define ISSPACE(c) ((c)==' '||(c)=='\f'||(c)=='\n'||(c)=='\r'||(c)=='\t'||(c)=='\v') + while (*pp < end && (c = **pp, ISSPACE (c))) + (*pp)++; +#undef ISSPACE +} + +static hb_bool_t +parse_char (const char **pp, const char *end, char c) +{ + parse_space (pp, end); + + if (*pp == end || **pp != c) + return false; + + (*pp)++; + return true; +} + +static hb_bool_t +parse_uint (const char **pp, const char *end, unsigned int *pv) +{ + char buf[32]; + strncpy (buf, *pp, end - *pp); + buf[ARRAY_LENGTH (buf) - 1] = '\0'; + + char *p = buf; + char *pend = p; + unsigned int v; + + v = strtol (p, &pend, 0); + + if (p == pend) + return false; + + *pv = v; + *pp += pend - p; + return true; +} + +static hb_bool_t +parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feature) +{ + if (parse_char (pp, end, '-')) + feature->value = 0; + else { + parse_char (pp, end, '+'); + feature->value = 1; + } + + return true; +} + +static hb_bool_t +parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature) +{ + const char *p = *pp; + char c; + + parse_space (pp, end); + +#define ISALNUM(c) (('a' <= (c) && (c) <= 'z') || ('A' <= (c) && (c) <= 'Z') || ('0' <= (c) && (c) <= '9')) + while (*pp < end && (c = **pp, ISALNUM(c))) + (*pp)++; +#undef ISALNUM + + if (p == *pp) + return false; + + feature->tag = hb_tag_from_string (p, *pp - p); + return true; +} + +static hb_bool_t +parse_feature_indices (const char **pp, const char *end, hb_feature_t *feature) +{ + parse_space (pp, end); + + hb_bool_t has_start; + + feature->start = 0; + feature->end = (unsigned int) -1; + + if (!parse_char (pp, end, '[')) + return true; + + has_start = parse_uint (pp, end, &feature->start); + + if (parse_char (pp, end, ':')) { + parse_uint (pp, end, &feature->end); + } else { + if (has_start) + feature->end = feature->start + 1; + } + + return parse_char (pp, end, ']'); +} + +static hb_bool_t +parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *feature) +{ + return !parse_char (pp, end, '=') || parse_uint (pp, end, &feature->value); +} + + +static hb_bool_t +parse_one_feature (const char **pp, const char *end, hb_feature_t *feature) +{ + return parse_feature_value_prefix (pp, end, feature) && + parse_feature_tag (pp, end, feature) && + parse_feature_indices (pp, end, feature) && + parse_feature_value_postfix (pp, end, feature) && + *pp == end; +} + +hb_bool_t +hb_feature_from_string (const char *str, int len, + hb_feature_t *feature) +{ + if (len < 0) + len = strlen (str); + + return parse_one_feature (&str, str + len, feature); +} + +void +hb_feature_to_string (hb_feature_t *feature, + char *buf, unsigned int size) +{ + if (unlikely (!size)) return; + + char s[128]; + unsigned int len = 0; + if (feature->value == 0) + s[len++] = '-'; + hb_tag_to_string (feature->tag, s + len); + len += 4; + while (len && s[len - 1] == ' ') + len--; + if (feature->start != 0 || feature->end != (unsigned int) -1) + { + s[len++] = '['; + if (feature->start) + len += snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->start); + if (feature->end != feature->start + 1) { + s[len++] = ':'; + if (feature->end != (unsigned int) -1) + len += snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->end); + } + s[len++] = ']'; + } + if (feature->value > 1) + { + s[len++] = '='; + len += snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->value); + } + assert (len < ARRAY_LENGTH (s)); + len = MIN (len, size - 1); + memcpy (buf, s, len); + s[len] = '\0'; +} + + +static const char **static_shaper_list; + +static +void free_static_shaper_list (void) +{ + free (static_shaper_list); +} + +const char ** +hb_shape_list_shapers (void) +{ +retry: + const char **shaper_list = (const char **) hb_atomic_ptr_get (&static_shaper_list); + + if (unlikely (!shaper_list)) + { + /* Not found; allocate one. */ + shaper_list = (const char **) calloc (1 + HB_SHAPERS_COUNT, sizeof (const char *)); + if (unlikely (!shaper_list)) { + static const char *nil_shaper_list[] = {NULL}; + return nil_shaper_list; + } + + const hb_shaper_pair_t *shapers = _hb_shapers_get (); + unsigned int i; + for (i = 0; i < HB_SHAPERS_COUNT; i++) + shaper_list[i] = shapers[i].name; + shaper_list[i] = NULL; + + if (!hb_atomic_ptr_cmpexch (&static_shaper_list, NULL, shaper_list)) { + free (shaper_list); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_static_shaper_list); /* First person registers atexit() callback. */ +#endif + } + + return shaper_list; +} + + +hb_bool_t +hb_shape_full (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features, + const char * const *shaper_list) +{ + if (unlikely (!buffer->len)) + return true; + + assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE); + + buffer->guess_segment_properties (); + + hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, features, num_features, shaper_list); + hb_bool_t res = hb_shape_plan_execute (shape_plan, font, buffer, features, num_features); + hb_shape_plan_destroy (shape_plan); + + if (res) + buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; + return res; +} + +void +hb_shape (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_shape_full (font, buffer, features, num_features, NULL); +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.h new file mode 100644 index 00000000000..10a35cb517e --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shape.h @@ -0,0 +1,81 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2012 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_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_SHAPE_H +#define HB_SHAPE_H + +#include "hb-common.h" +#include "hb-buffer.h" +#include "hb-font.h" + +HB_BEGIN_DECLS + + +typedef struct hb_feature_t { + hb_tag_t tag; + uint32_t value; + unsigned int start; + unsigned int end; +} hb_feature_t; + +/* len=-1 means str is NUL-terminated */ +hb_bool_t +hb_feature_from_string (const char *str, int len, + hb_feature_t *feature); + +/* Something like 128 bytes is more than enough. + * nul-terminates. */ +void +hb_feature_to_string (hb_feature_t *feature, + char *buf, unsigned int size); + + +void +hb_shape (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features); + +hb_bool_t +hb_shape_full (hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features, + const char * const *shaper_list); + +const char ** +hb_shape_list_shapers (void); + + +HB_END_DECLS + +#endif /* HB_SHAPE_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-impl-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-impl-private.hh new file mode 100644 index 00000000000..7844081e95b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-impl-private.hh @@ -0,0 +1,43 @@ +/* + * Copyright © 2012 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_SHAPER_IMPL_PRIVATE_HH +#define HB_SHAPER_IMPL_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-shaper-private.hh" +#include "hb-shape-plan-private.hh" +#include "hb-font-private.hh" +#include "hb-buffer-private.hh" + + +#ifdef HB_SHAPER +#define HB_SHAPER_DATA_GET(object) HB_SHAPER_DATA (HB_SHAPER, object) +#endif + + +#endif /* HB_SHAPER_IMPL_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-list.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-list.hh new file mode 100644 index 00000000000..b9c029e58f1 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-list.hh @@ -0,0 +1,55 @@ +/* + * Copyright © 2012 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_SHAPER_LIST_HH +#define HB_SHAPER_LIST_HH +#endif /* HB_SHAPER_LIST_HH */ /* Dummy header guards */ + +/* v--- Add new shapers in the right place here. */ + +#ifdef HAVE_GRAPHITE2 +/* Only picks up fonts that have a "Silf" table. */ +HB_SHAPER_IMPLEMENT (graphite2) +#endif + +#ifdef HAVE_OT +HB_SHAPER_IMPLEMENT (ot) /* <--- This is our main OpenType shaper. */ +#endif + +#ifdef HAVE_HB_OLD +HB_SHAPER_IMPLEMENT (old) +#endif +#ifdef HAVE_ICU_LE +HB_SHAPER_IMPLEMENT (icu_le) +#endif +#ifdef HAVE_UNISCRIBE +HB_SHAPER_IMPLEMENT (uniscribe) +#endif +#ifdef HAVE_CORETEXT +HB_SHAPER_IMPLEMENT (coretext) +#endif + +HB_SHAPER_IMPLEMENT (fallback) /* <--- This should be last. */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-private.hh new file mode 100644 index 00000000000..9d30c1ea0c2 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper-private.hh @@ -0,0 +1,106 @@ +/* + * Copyright © 2012 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_SHAPER_PRIVATE_HH +#define HB_SHAPER_PRIVATE_HH + +#include "hb-private.hh" + +typedef hb_bool_t hb_shape_func_t (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features); + +#define HB_SHAPER_IMPLEMENT(name) \ + extern "C" HB_INTERNAL hb_shape_func_t _hb_##name##_shape; +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + +struct hb_shaper_pair_t { + char name[16]; + hb_shape_func_t *func; +}; + +HB_INTERNAL const hb_shaper_pair_t * +_hb_shapers_get (void); + + +/* For embedding in face / font / ... */ +struct hb_shaper_data_t { +#define HB_SHAPER_IMPLEMENT(shaper) void *shaper; +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT +}; + +#define HB_SHAPERS_COUNT (sizeof (hb_shaper_data_t) / sizeof (void *)) + +/* Means: succeeded, but don't need to keep any data. */ +#define HB_SHAPER_DATA_SUCCEEDED ((void *) +1) + +/* Means: tried but failed to create. */ +#define HB_SHAPER_DATA_INVALID ((void *) -1) +#define HB_SHAPER_DATA_IS_INVALID(data) ((void *) (data) == HB_SHAPER_DATA_INVALID) + +#define HB_SHAPER_DATA_TYPE(shaper, object) struct hb_##shaper##_shaper_##object##_data_t +#define HB_SHAPER_DATA_INSTANCE(shaper, object, instance) (* (HB_SHAPER_DATA_TYPE(shaper, object) **) &(instance)->shaper_data.shaper) +#define HB_SHAPER_DATA(shaper, object) HB_SHAPER_DATA_INSTANCE (shaper, object, object) +#define HB_SHAPER_DATA_CREATE_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_create +#define HB_SHAPER_DATA_DESTROY_FUNC(shaper, object) _hb_##shaper##_shaper_##object##_data_destroy + +#define HB_SHAPER_DATA_PROTOTYPE(shaper, object) \ + HB_SHAPER_DATA_TYPE (shaper, object); /* Type forward declaration. */ \ + extern "C" HB_INTERNAL HB_SHAPER_DATA_TYPE (shaper, object) * \ + HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (hb_##object##_t *object HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS); \ + extern "C" HB_INTERNAL void \ + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA_TYPE (shaper, object) *data) + +#define HB_SHAPER_DATA_DESTROY(shaper, object) \ + if (object->shaper_data.shaper && \ + object->shaper_data.shaper != HB_SHAPER_DATA_INVALID && \ + object->shaper_data.shaper != HB_SHAPER_DATA_SUCCEEDED) \ + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (HB_SHAPER_DATA (shaper, object)); + +#define HB_SHAPER_DATA_ENSURE_DECLARE(shaper, object) \ +static inline bool \ +hb_##shaper##_shaper_##object##_data_ensure (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 (unlikely (!data)) { \ + data = HB_SHAPER_DATA_CREATE_FUNC (shaper, object) (object); \ + if (unlikely (!data)) \ + data = (HB_SHAPER_DATA_TYPE (shaper, object) *) HB_SHAPER_DATA_INVALID; \ + if (!hb_atomic_ptr_cmpexch (&HB_SHAPER_DATA (shaper, object), NULL, data)) { \ + HB_SHAPER_DATA_DESTROY_FUNC (shaper, object) (data); \ + goto retry; \ + } \ + } \ + return data != NULL && !HB_SHAPER_DATA_IS_INVALID (data); \ +} + + +#endif /* HB_SHAPER_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper.cc new file mode 100644 index 00000000000..1c1aed9034a --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-shaper.cc @@ -0,0 +1,109 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" +#include "hb-shaper-private.hh" +#include "hb-atomic-private.hh" + + +static const hb_shaper_pair_t all_shapers[] = { +#define HB_SHAPER_IMPLEMENT(name) {#name, _hb_##name##_shape}, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT +}; + + +/* Thread-safe, lock-free, shapers */ + +static const hb_shaper_pair_t *static_shapers; + +static +void free_static_shapers (void) +{ + if (unlikely (static_shapers != all_shapers)) + free ((void *) static_shapers); +} + +const hb_shaper_pair_t * +_hb_shapers_get (void) +{ +retry: + hb_shaper_pair_t *shapers = (hb_shaper_pair_t *) hb_atomic_ptr_get (&static_shapers); + + if (unlikely (!shapers)) + { + char *env = getenv ("HB_SHAPER_LIST"); + if (!env || !*env) { + (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]); + return (const hb_shaper_pair_t *) all_shapers; + } + + /* Not found; allocate one. */ + shapers = (hb_shaper_pair_t *) malloc (sizeof (all_shapers)); + if (unlikely (!shapers)) { + (void) hb_atomic_ptr_cmpexch (&static_shapers, NULL, &all_shapers[0]); + return (const hb_shaper_pair_t *) all_shapers; + } + + memcpy (shapers, all_shapers, sizeof (all_shapers)); + + /* Reorder shaper list to prefer requested shapers. */ + unsigned int i = 0; + char *end, *p = env; + for (;;) { + end = strchr (p, ','); + if (!end) + end = p + strlen (p); + + for (unsigned int j = i; j < ARRAY_LENGTH (all_shapers); j++) + if (end - p == (int) strlen (shapers[j].name) && + 0 == strncmp (shapers[j].name, p, end - p)) + { + /* Reorder this shaper to position i */ + struct hb_shaper_pair_t t = shapers[j]; + memmove (&shapers[i + 1], &shapers[i], sizeof (shapers[i]) * (j - i)); + shapers[i] = t; + i++; + } + + if (!*end) + break; + else + p = end + 1; + } + + if (!hb_atomic_ptr_cmpexch (&static_shapers, NULL, shapers)) { + free (shapers); + goto retry; + } + +#ifdef HAVE_ATEXIT + atexit (free_static_shapers); /* First person registers atexit() callback. */ +#endif + } + + return shapers; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-tt-font.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-tt-font.cc new file mode 100644 index 00000000000..c503a404380 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-tt-font.cc @@ -0,0 +1,79 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-font-private.hh" /* Shall be first since may include windows.h */ + +#include "hb-open-type-private.hh" + +#include "hb-ot-hhea-table.hh" +#include "hb-ot-hmtx-table.hh" + +#include "hb-blob.h" + +#include <string.h> + + + +#if 0 +struct hb_tt_font_t +{ + const struct hhea *hhea; + hb_blob_t *hhea_blob; +}; + + +static hb_tt_font_t * +_hb_tt_font_create (hb_font_t *font) +{ + /* TODO Remove this object altogether */ + hb_tt_font_t *tt = (hb_tt_font_t *) calloc (1, sizeof (hb_tt_font_t)); + + tt->hhea_blob = Sanitizer<hhea>::sanitize (font->face->reference_table (HB_OT_TAG_hhea)); + tt->hhea = Sanitizer<hhea>::lock_instance (tt->hhea_blob); + + return tt; +} + +static void +_hb_tt_font_destroy (hb_tt_font_t *tt) +{ + hb_blob_destroy (tt->hhea_blob); + + free (tt); +} + +static inline const hhea& +_get_hhea (hb_face_t *face) +{ + return likely (face->tt && face->tt->hhea) ? *face->tt->hhea : Null(hhea); +} + + +/* + * hb_tt_font_funcs_t + */ + +#endif diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ucdn.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ucdn.cc new file mode 100644 index 00000000000..61e6ad36229 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-ucdn.cc @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2012 Grigori Goronzy <greg@kinoho.net> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "hb-private.hh" + +#include "hb-unicode-private.hh" + +#include "ucdn.h" + +static const hb_script_t ucdn_script_translate[] = +{ + HB_SCRIPT_COMMON, + HB_SCRIPT_LATIN, + HB_SCRIPT_GREEK, + HB_SCRIPT_CYRILLIC, + HB_SCRIPT_ARMENIAN, + HB_SCRIPT_HEBREW, + HB_SCRIPT_ARABIC, + HB_SCRIPT_SYRIAC, + HB_SCRIPT_THAANA, + HB_SCRIPT_DEVANAGARI, + HB_SCRIPT_BENGALI, + HB_SCRIPT_GURMUKHI, + HB_SCRIPT_GUJARATI, + HB_SCRIPT_ORIYA, + HB_SCRIPT_TAMIL, + HB_SCRIPT_TELUGU, + HB_SCRIPT_KANNADA, + HB_SCRIPT_MALAYALAM, + HB_SCRIPT_SINHALA, + HB_SCRIPT_THAI, + HB_SCRIPT_LAO, + HB_SCRIPT_TIBETAN, + HB_SCRIPT_MYANMAR, + HB_SCRIPT_GEORGIAN, + HB_SCRIPT_HANGUL, + HB_SCRIPT_ETHIOPIC, + HB_SCRIPT_CHEROKEE, + HB_SCRIPT_CANADIAN_ABORIGINAL, + HB_SCRIPT_OGHAM, + HB_SCRIPT_RUNIC, + HB_SCRIPT_KHMER, + HB_SCRIPT_MONGOLIAN, + HB_SCRIPT_HIRAGANA, + HB_SCRIPT_KATAKANA, + HB_SCRIPT_BOPOMOFO, + HB_SCRIPT_HAN, + HB_SCRIPT_YI, + HB_SCRIPT_OLD_ITALIC, + HB_SCRIPT_GOTHIC, + HB_SCRIPT_DESERET, + HB_SCRIPT_INHERITED, + HB_SCRIPT_TAGALOG, + HB_SCRIPT_HANUNOO, + HB_SCRIPT_BUHID, + HB_SCRIPT_TAGBANWA, + HB_SCRIPT_LIMBU, + HB_SCRIPT_TAI_LE, + HB_SCRIPT_LINEAR_B, + HB_SCRIPT_UGARITIC, + HB_SCRIPT_SHAVIAN, + HB_SCRIPT_OSMANYA, + HB_SCRIPT_CYPRIOT, + HB_SCRIPT_BRAILLE, + HB_SCRIPT_BUGINESE, + HB_SCRIPT_COPTIC, + HB_SCRIPT_NEW_TAI_LUE, + HB_SCRIPT_GLAGOLITIC, + HB_SCRIPT_TIFINAGH, + HB_SCRIPT_SYLOTI_NAGRI, + HB_SCRIPT_OLD_PERSIAN, + HB_SCRIPT_KHAROSHTHI, + HB_SCRIPT_BALINESE, + HB_SCRIPT_CUNEIFORM, + HB_SCRIPT_PHOENICIAN, + HB_SCRIPT_PHAGS_PA, + HB_SCRIPT_NKO, + HB_SCRIPT_SUNDANESE, + HB_SCRIPT_LEPCHA, + HB_SCRIPT_OL_CHIKI, + HB_SCRIPT_VAI, + HB_SCRIPT_SAURASHTRA, + HB_SCRIPT_KAYAH_LI, + HB_SCRIPT_REJANG, + HB_SCRIPT_LYCIAN, + HB_SCRIPT_CARIAN, + HB_SCRIPT_LYDIAN, + HB_SCRIPT_CHAM, + HB_SCRIPT_TAI_THAM, + HB_SCRIPT_TAI_VIET, + HB_SCRIPT_AVESTAN, + HB_SCRIPT_EGYPTIAN_HIEROGLYPHS, + HB_SCRIPT_SAMARITAN, + HB_SCRIPT_LISU, + HB_SCRIPT_BAMUM, + HB_SCRIPT_JAVANESE, + HB_SCRIPT_MEETEI_MAYEK, + HB_SCRIPT_IMPERIAL_ARAMAIC, + HB_SCRIPT_OLD_SOUTH_ARABIAN, + HB_SCRIPT_INSCRIPTIONAL_PARTHIAN, + HB_SCRIPT_INSCRIPTIONAL_PAHLAVI, + HB_SCRIPT_OLD_TURKIC, + HB_SCRIPT_KAITHI, + HB_SCRIPT_BATAK, + HB_SCRIPT_BRAHMI, + HB_SCRIPT_MANDAIC, + HB_SCRIPT_CHAKMA, + HB_SCRIPT_MEROITIC_CURSIVE, + HB_SCRIPT_MEROITIC_HIEROGLYPHS, + HB_SCRIPT_MIAO, + HB_SCRIPT_SHARADA, + HB_SCRIPT_SORA_SOMPENG, + HB_SCRIPT_TAKRI, + HB_SCRIPT_UNKNOWN, +}; + +static hb_unicode_combining_class_t +hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return (hb_unicode_combining_class_t) ucdn_get_combining_class(unicode); +} + +static unsigned int +hb_ucdn_eastasian_width(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + int w = ucdn_get_east_asian_width(unicode); + return (w == UCDN_EAST_ASIAN_F || w == UCDN_EAST_ASIAN_W) ? 2 : 1; +} + +static hb_unicode_general_category_t +hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return (hb_unicode_general_category_t)ucdn_get_general_category(unicode); +} + +static hb_codepoint_t +hb_ucdn_mirroring(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return ucdn_mirror(unicode); +} + +static hb_script_t +hb_ucdn_script(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode, + void *user_data HB_UNUSED) +{ + return ucdn_script_translate[ucdn_get_script(unicode)]; +} + +static hb_bool_t +hb_ucdn_compose(hb_unicode_funcs_t *ufuncs, + hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab, + void *user_data HB_UNUSED) +{ + return ucdn_compose(ab, a, b); +} + +static hb_bool_t +hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs, + hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b, + void *user_data HB_UNUSED) +{ + return ucdn_decompose(ab, a, b); +} + +static unsigned int +hb_ucdn_decompose_compatibility(hb_unicode_funcs_t *ufuncs, + hb_codepoint_t u, hb_codepoint_t *decomposed, + void *user_data HB_UNUSED) +{ + return ucdn_compat_decompose(u, decomposed); +} + +extern "C" HB_INTERNAL +hb_unicode_funcs_t * +hb_ucdn_get_unicode_funcs (void) +{ + static const hb_unicode_funcs_t _hb_ucdn_unicode_funcs = { + HB_OBJECT_HEADER_STATIC, + + NULL, /* parent */ + true, /* immutable */ + { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_ucdn_##name, + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } + }; + + return const_cast<hb_unicode_funcs_t *> (&_hb_ucdn_unicode_funcs); +} + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode-private.hh new file mode 100644 index 00000000000..7be4b04da6b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode-private.hh @@ -0,0 +1,306 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Codethink Limited + * Copyright © 2010,2011,2012 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 + * Codethink Author(s): Ryan Lortie + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_UNICODE_PRIVATE_HH +#define HB_UNICODE_PRIVATE_HH + +#include "hb-private.hh" + +#include "hb-unicode.h" +#include "hb-object-private.hh" + + +extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; + +/* + * hb_unicode_funcs_t + */ + +#define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \ + HB_UNICODE_FUNC_IMPLEMENT (combining_class) \ + HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \ + HB_UNICODE_FUNC_IMPLEMENT (general_category) \ + HB_UNICODE_FUNC_IMPLEMENT (mirroring) \ + HB_UNICODE_FUNC_IMPLEMENT (script) \ + HB_UNICODE_FUNC_IMPLEMENT (compose) \ + HB_UNICODE_FUNC_IMPLEMENT (decompose) \ + HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \ + /* ^--- Add new callbacks here */ + +/* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */ +#define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \ + HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \ + HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \ + HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \ + HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \ + HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ + /* ^--- Add new simple callbacks here */ + +struct hb_unicode_funcs_t { + hb_object_header_t header; + ASSERT_POD (); + + hb_unicode_funcs_t *parent; + + bool immutable; + +#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ + inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); } +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE +#undef HB_UNICODE_FUNC_IMPLEMENT + + inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b, + hb_codepoint_t *ab) + { + *ab = 0; + if (unlikely (!a || !b)) return false; + return func.compose (this, a, b, ab, user_data.compose); + } + + inline hb_bool_t decompose (hb_codepoint_t ab, + hb_codepoint_t *a, hb_codepoint_t *b) + { + *a = ab; *b = 0; + return func.decompose (this, ab, a, b, user_data.decompose); + } + + inline unsigned int decompose_compatibility (hb_codepoint_t u, + hb_codepoint_t *decomposed) + { + unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility); + if (ret == 1 && u == decomposed[0]) { + decomposed[0] = 0; + return 0; + } + decomposed[ret] = 0; + return ret; + } + + + unsigned int + modified_combining_class (hb_codepoint_t unicode) + { + return _hb_modified_combining_class[combining_class (unicode)]; + } + + inline hb_bool_t + is_variation_selector (hb_codepoint_t unicode) + { + return unlikely (hb_in_ranges<hb_codepoint_t> (unicode, + 0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */ + 0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */ + 0xE0100, 0xE01EF)); /* VARIATION SELECTOR-17..256 */ + } + + /* Default_Ignorable codepoints: + * + * Note that as of Oct 2012 (Unicode 6.2), U+180E MONGOLIAN VOWEL SEPARATOR + * is NOT Default_Ignorable, but it really behaves in a way that it should + * be. That has been reported to the Unicode Technical Committee for + * consideration. As such, we include it here, since Uniscribe removes it. + * + * Gathered from: + * http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:DI:]&abb=on&ucd=on&esc=on + * + * Last updated to the page with the following versions: + * Version 3.6; ICU version: 50.0.1.0; Unicode version: 6.1.0.0 + * + * 4,167 Code Points + * + * [\u00AD\u034F\u115F\u1160\u17B4\u17B5\u180B-\u180D\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\U0001D173-\U0001D17A\U000E0000-\U000E0FFF] + * + * 00AD ;SOFT HYPHEN + * 034F ;COMBINING GRAPHEME JOINER + * 115F ;HANGUL CHOSEONG FILLER + * 1160 ;HANGUL JUNGSEONG FILLER + * 17B4 ;KHMER VOWEL INHERENT AQ + * 17B5 ;KHMER VOWEL INHERENT AA + * 180B..180D ;MONGOLIAN FREE VARIATION SELECTOR THREE + * 200B..200F ;RIGHT-TO-LEFT MARK + * 202A..202E ;RIGHT-TO-LEFT OVERRIDE + * 2060..206F ;NOMINAL DIGIT SHAPES + * 3164 ;HANGUL FILLER + * FE00..FE0F ;VARIATION SELECTOR-16 + * FEFF ;ZERO WIDTH NO-BREAK SPACE + * FFA0 ;HALFWIDTH HANGUL FILLER + * FFF0..FFF8 ;<unassigned-FFF8> + * 1D173..1D17A ;MUSICAL SYMBOL END PHRASE + * E0000..E0FFF ;<unassigned-E0FFF> + */ + inline hb_bool_t + is_default_ignorable (hb_codepoint_t ch) + { + hb_codepoint_t plane = ch >> 16; + if (likely (plane == 0)) + { + /* BMP */ + hb_codepoint_t page = ch >> 8; + switch (page) { + case 0x00: return unlikely (ch == 0x00AD); + case 0x03: return unlikely (ch == 0x034F); + case 0x11: return hb_in_range<hb_codepoint_t> (ch, 0x115F, 0x1160); + case 0x17: return hb_in_range<hb_codepoint_t> (ch, 0x17B4, 0x17B5); + case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180B, 0x180E); + case 0x20: return hb_in_ranges<hb_codepoint_t> (ch, 0x200B, 0x200F, + 0x202A, 0x202E, + 0x2060, 0x206F); + case 0x31: return unlikely (ch == 0x3164); + case 0xFE: return hb_in_range<hb_codepoint_t> (ch, 0xFE00, 0xFE0F) || ch == 0xFEFF; + case 0xFF: return hb_in_range<hb_codepoint_t> (ch, 0xFFF0, 0xFFF8) || ch == 0xFFA0; + default: return false; + } + } + else + { + /* Other planes */ + switch (plane) { + case 0x01: return hb_in_range<hb_codepoint_t> (ch, 0x0001D173, 0x0001D17A); + case 0x0E: return hb_in_range<hb_codepoint_t> (ch, 0x000E0000, 0x000E0FFF); + default: return false; + } + } + } + + + struct { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name; + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } func; + + struct { +#define HB_UNICODE_FUNC_IMPLEMENT(name) void *name; + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } user_data; + + struct { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name; + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } destroy; +}; + + +extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; + + +/* Modified combining marks */ + +/* Hebrew + * + * We permute the "fixed-position" classes 10-26 into the order + * described in the SBL Hebrew manual: + * + * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf + * + * (as recommended by: + * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html) + * + * More details here: + * https://bugzilla.mozilla.org/show_bug.cgi?id=662055 + */ +#define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */ +#define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */ +#define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */ +#define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */ +#define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */ +#define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */ +#define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */ +#define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */ +#define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */ +#define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */ +#define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */ +#define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */ +#define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */ +#define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */ +#define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */ +#define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */ +#define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */ + +/* + * Arabic + * + * Modify to move Shadda (ccc=33) before other marks. See: + * http://unicode.org/faq/normalization.html#8 + * http://unicode.org/faq/normalization.html#9 + */ +#define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */ +#define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */ +#define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */ +#define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */ +#define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */ +#define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */ +#define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */ +#define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */ +#define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */ + +/* Syriac */ +#define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */ + +/* Telugu + * + * Modify Telugu length marks (ccc=84, ccc=91). + * These are the only matras in the main Indic scripts range that have + * a non-zero ccc. That makes them reorder with the Halant that is + * ccc=9. Just zero them, we don't need them in our Indic shaper. + */ +#define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */ +#define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */ + +/* Thai + * + * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9). + * Assign 3, which is unassigned otherwise. + * Uniscribe does this reordering too. + */ +#define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */ +#define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */ + +/* Lao */ +#define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */ +#define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */ + +/* Tibetan */ +#define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */ +#define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */ +#define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */ + + +/* Misc */ + +#define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \ + (FLAG (gen_cat) & \ + (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \ + FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \ + FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK))) + + +#endif /* HB_UNICODE_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.cc new file mode 100644 index 00000000000..0a3907eec8c --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.cc @@ -0,0 +1,435 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Codethink Limited + * Copyright © 2010,2011,2012 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 + * Codethink Author(s): Ryan Lortie + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-private.hh" + +#include "hb-unicode-private.hh" + + + +/* + * hb_unicode_funcs_t + */ + +static hb_unicode_combining_class_t +hb_unicode_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return HB_UNICODE_COMBINING_CLASS_NOT_REORDERED; +} + +static unsigned int +hb_unicode_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return 1; +} + +static hb_unicode_general_category_t +hb_unicode_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER; +} + +static hb_codepoint_t +hb_unicode_mirroring_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return unicode; +} + +static hb_script_t +hb_unicode_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t unicode HB_UNUSED, + void *user_data HB_UNUSED) +{ + return HB_SCRIPT_UNKNOWN; +} + +static hb_bool_t +hb_unicode_compose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t a HB_UNUSED, + hb_codepoint_t b HB_UNUSED, + hb_codepoint_t *ab HB_UNUSED, + void *user_data HB_UNUSED) +{ + return false; +} + +static hb_bool_t +hb_unicode_decompose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t ab HB_UNUSED, + hb_codepoint_t *a HB_UNUSED, + hb_codepoint_t *b HB_UNUSED, + void *user_data HB_UNUSED) +{ + return false; +} + + +static unsigned int +hb_unicode_decompose_compatibility_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, + hb_codepoint_t u HB_UNUSED, + hb_codepoint_t *decomposed HB_UNUSED, + void *user_data HB_UNUSED) +{ + return 0; +} + + +#define HB_UNICODE_FUNCS_IMPLEMENT_SET \ + HB_UNICODE_FUNCS_IMPLEMENT (glib) \ + HB_UNICODE_FUNCS_IMPLEMENT (icu) \ + HB_UNICODE_FUNCS_IMPLEMENT (ucdn) \ + HB_UNICODE_FUNCS_IMPLEMENT (nil) \ + /* ^--- Add new callbacks before nil */ + +#define hb_nil_get_unicode_funcs hb_unicode_funcs_get_empty + +/* Prototype them all */ +#define HB_UNICODE_FUNCS_IMPLEMENT(set) \ +extern "C" hb_unicode_funcs_t *hb_##set##_get_unicode_funcs (void); +HB_UNICODE_FUNCS_IMPLEMENT_SET +#undef HB_UNICODE_FUNCS_IMPLEMENT + + +hb_unicode_funcs_t * +hb_unicode_funcs_get_default (void) +{ +#define HB_UNICODE_FUNCS_IMPLEMENT(set) \ + return hb_##set##_get_unicode_funcs (); + +#ifdef HAVE_GLIB + HB_UNICODE_FUNCS_IMPLEMENT(glib) +#elif defined(HAVE_ICU) + HB_UNICODE_FUNCS_IMPLEMENT(icu) +#elif defined(HAVE_UCDN) + HB_UNICODE_FUNCS_IMPLEMENT(ucdn) +#else +#define HB_UNICODE_FUNCS_NIL 1 + HB_UNICODE_FUNCS_IMPLEMENT(nil) +#endif + +#undef HB_UNICODE_FUNCS_IMPLEMENT +} + +#if !defined(HB_NO_UNICODE_FUNCS) && defined(HB_UNICODE_FUNCS_NIL) +#pragma message("Could not find any Unicode functions implementation, you have to provide your own.") +#pragma message("To suppress this warnings, define HB_NO_UNICODE_FUNCS.") +#endif + +hb_unicode_funcs_t * +hb_unicode_funcs_create (hb_unicode_funcs_t *parent) +{ + hb_unicode_funcs_t *ufuncs; + + if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ())) + return hb_unicode_funcs_get_empty (); + + if (!parent) + parent = hb_unicode_funcs_get_empty (); + + hb_unicode_funcs_make_immutable (parent); + ufuncs->parent = hb_unicode_funcs_reference (parent); + + ufuncs->func = parent->func; + + /* We can safely copy user_data from parent since we hold a reference + * onto it and it's immutable. We should not copy the destroy notifiers + * though. */ + ufuncs->user_data = parent->user_data; + + return ufuncs; +} + + +const hb_unicode_funcs_t _hb_unicode_funcs_nil = { + HB_OBJECT_HEADER_STATIC, + + NULL, /* parent */ + true, /* immutable */ + { +#define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil, + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + } +}; + +hb_unicode_funcs_t * +hb_unicode_funcs_get_empty (void) +{ + return const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil); +} + +hb_unicode_funcs_t * +hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs) +{ + return hb_object_reference (ufuncs); +} + +void +hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs) +{ + if (!hb_object_destroy (ufuncs)) return; + +#define HB_UNICODE_FUNC_IMPLEMENT(name) \ + if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name); + HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + + hb_unicode_funcs_destroy (ufuncs->parent); + + free (ufuncs); +} + +hb_bool_t +hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace) +{ + return hb_object_set_user_data (ufuncs, key, data, destroy, replace); +} + +void * +hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs, + hb_user_data_key_t *key) +{ + return hb_object_get_user_data (ufuncs, key); +} + + +void +hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs) +{ + if (hb_object_is_inert (ufuncs)) + return; + + ufuncs->immutable = true; +} + +hb_bool_t +hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs) +{ + return ufuncs->immutable; +} + +hb_unicode_funcs_t * +hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs) +{ + return ufuncs->parent ? ufuncs->parent : hb_unicode_funcs_get_empty (); +} + + +#define HB_UNICODE_FUNC_IMPLEMENT(name) \ + \ +void \ +hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \ + hb_unicode_##name##_func_t func, \ + void *user_data, \ + hb_destroy_func_t destroy) \ +{ \ + if (ufuncs->immutable) \ + return; \ + \ + if (ufuncs->destroy.name) \ + ufuncs->destroy.name (ufuncs->user_data.name); \ + \ + if (func) { \ + ufuncs->func.name = func; \ + ufuncs->user_data.name = user_data; \ + ufuncs->destroy.name = destroy; \ + } else { \ + ufuncs->func.name = ufuncs->parent->func.name; \ + ufuncs->user_data.name = ufuncs->parent->user_data.name; \ + ufuncs->destroy.name = NULL; \ + } \ +} + +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS +#undef HB_UNICODE_FUNC_IMPLEMENT + + +#define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ + \ +return_type \ +hb_unicode_##name (hb_unicode_funcs_t *ufuncs, \ + hb_codepoint_t unicode) \ +{ \ + return ufuncs->name (unicode); \ +} +HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE +#undef HB_UNICODE_FUNC_IMPLEMENT + +hb_bool_t +hb_unicode_compose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab) +{ + return ufuncs->compose (a, b, ab); +} + +hb_bool_t +hb_unicode_decompose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b) +{ + return ufuncs->decompose (ab, a, b); +} + +unsigned int +hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t u, + hb_codepoint_t *decomposed) +{ + return ufuncs->decompose_compatibility (u, decomposed); +} + + +/* See hb-unicode-private.hh for details. */ +const uint8_t +_hb_modified_combining_class[256] = +{ + 0, /* HB_UNICODE_COMBINING_CLASS_NOT_REORDERED */ + 1, /* HB_UNICODE_COMBINING_CLASS_OVERLAY */ + 2, 3, 4, 5, 6, + 7, /* HB_UNICODE_COMBINING_CLASS_NUKTA */ + 8, /* HB_UNICODE_COMBINING_CLASS_KANA_VOICING */ + 9, /* HB_UNICODE_COMBINING_CLASS_VIRAMA */ + + /* Hebrew */ + HB_MODIFIED_COMBINING_CLASS_CCC10, + HB_MODIFIED_COMBINING_CLASS_CCC11, + HB_MODIFIED_COMBINING_CLASS_CCC12, + HB_MODIFIED_COMBINING_CLASS_CCC13, + HB_MODIFIED_COMBINING_CLASS_CCC14, + HB_MODIFIED_COMBINING_CLASS_CCC15, + HB_MODIFIED_COMBINING_CLASS_CCC16, + HB_MODIFIED_COMBINING_CLASS_CCC17, + HB_MODIFIED_COMBINING_CLASS_CCC18, + HB_MODIFIED_COMBINING_CLASS_CCC19, + HB_MODIFIED_COMBINING_CLASS_CCC20, + HB_MODIFIED_COMBINING_CLASS_CCC21, + HB_MODIFIED_COMBINING_CLASS_CCC22, + HB_MODIFIED_COMBINING_CLASS_CCC23, + HB_MODIFIED_COMBINING_CLASS_CCC24, + HB_MODIFIED_COMBINING_CLASS_CCC25, + HB_MODIFIED_COMBINING_CLASS_CCC26, + + /* Arabic */ + HB_MODIFIED_COMBINING_CLASS_CCC27, + HB_MODIFIED_COMBINING_CLASS_CCC28, + HB_MODIFIED_COMBINING_CLASS_CCC29, + HB_MODIFIED_COMBINING_CLASS_CCC30, + HB_MODIFIED_COMBINING_CLASS_CCC31, + HB_MODIFIED_COMBINING_CLASS_CCC32, + HB_MODIFIED_COMBINING_CLASS_CCC33, + HB_MODIFIED_COMBINING_CLASS_CCC34, + HB_MODIFIED_COMBINING_CLASS_CCC35, + + /* Syriac */ + HB_MODIFIED_COMBINING_CLASS_CCC36, + + 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, + + /* Telugu */ + HB_MODIFIED_COMBINING_CLASS_CCC84, + 85, 86, 87, 88, 89, 90, + HB_MODIFIED_COMBINING_CLASS_CCC91, + 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + + /* Thai */ + HB_MODIFIED_COMBINING_CLASS_CCC103, + 104, 105, 106, + HB_MODIFIED_COMBINING_CLASS_CCC107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, + + /* Lao */ + HB_MODIFIED_COMBINING_CLASS_CCC118, + 119, 120, 121, + HB_MODIFIED_COMBINING_CLASS_CCC122, + 123, 124, 125, 126, 127, 128, + + /* Tibetan */ + HB_MODIFIED_COMBINING_CLASS_CCC129, + HB_MODIFIED_COMBINING_CLASS_CCC130, + 131, + HB_MODIFIED_COMBINING_CLASS_CCC132, + 133, 134, 135, 136, 137, 138, 139, + + + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + + 200, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT */ + 201, + 202, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW */ + 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, + 214, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE */ + 215, + 216, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT */ + 217, + 218, /* HB_UNICODE_COMBINING_CLASS_BELOW_LEFT */ + 219, + 220, /* HB_UNICODE_COMBINING_CLASS_BELOW */ + 221, + 222, /* HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT */ + 223, + 224, /* HB_UNICODE_COMBINING_CLASS_LEFT */ + 225, + 226, /* HB_UNICODE_COMBINING_CLASS_RIGHT */ + 227, + 228, /* HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT */ + 229, + 230, /* HB_UNICODE_COMBINING_CLASS_ABOVE */ + 231, + 232, /* HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT */ + 233, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW */ + 234, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE */ + 235, 236, 237, 238, 239, + 240, /* HB_UNICODE_COMBINING_CLASS_IOTA_SUBSCRIPT */ + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, /* HB_UNICODE_COMBINING_CLASS_INVALID */ +}; diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.h new file mode 100644 index 00000000000..2e10d98a3b3 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-unicode.h @@ -0,0 +1,357 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * Copyright © 2011 Codethink Limited + * Copyright © 2011,2012 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 + * Codethink Author(s): Ryan Lortie + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_UNICODE_H +#define HB_UNICODE_H + +#include "hb-common.h" + +HB_BEGIN_DECLS + + +/* hb_unicode_general_category_t */ + +/* Unicode Character Database property: General_Category (gc) */ +typedef enum +{ + HB_UNICODE_GENERAL_CATEGORY_CONTROL, /* Cc */ + HB_UNICODE_GENERAL_CATEGORY_FORMAT, /* Cf */ + HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED, /* Cn */ + HB_UNICODE_GENERAL_CATEGORY_PRIVATE_USE, /* Co */ + HB_UNICODE_GENERAL_CATEGORY_SURROGATE, /* Cs */ + HB_UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER, /* Ll */ + HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER, /* Lm */ + HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER, /* Lo */ + HB_UNICODE_GENERAL_CATEGORY_TITLECASE_LETTER, /* Lt */ + HB_UNICODE_GENERAL_CATEGORY_UPPERCASE_LETTER, /* Lu */ + HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK, /* Mc */ + HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK, /* Me */ + HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK, /* Mn */ + HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER, /* Nd */ + HB_UNICODE_GENERAL_CATEGORY_LETTER_NUMBER, /* Nl */ + HB_UNICODE_GENERAL_CATEGORY_OTHER_NUMBER, /* No */ + HB_UNICODE_GENERAL_CATEGORY_CONNECT_PUNCTUATION, /* Pc */ + HB_UNICODE_GENERAL_CATEGORY_DASH_PUNCTUATION, /* Pd */ + HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION, /* Pe */ + HB_UNICODE_GENERAL_CATEGORY_FINAL_PUNCTUATION, /* Pf */ + HB_UNICODE_GENERAL_CATEGORY_INITIAL_PUNCTUATION, /* Pi */ + HB_UNICODE_GENERAL_CATEGORY_OTHER_PUNCTUATION, /* Po */ + HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION, /* Ps */ + HB_UNICODE_GENERAL_CATEGORY_CURRENCY_SYMBOL, /* Sc */ + HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL, /* Sk */ + HB_UNICODE_GENERAL_CATEGORY_MATH_SYMBOL, /* Sm */ + HB_UNICODE_GENERAL_CATEGORY_OTHER_SYMBOL, /* So */ + HB_UNICODE_GENERAL_CATEGORY_LINE_SEPARATOR, /* Zl */ + HB_UNICODE_GENERAL_CATEGORY_PARAGRAPH_SEPARATOR, /* Zp */ + HB_UNICODE_GENERAL_CATEGORY_SPACE_SEPARATOR /* Zs */ +} hb_unicode_general_category_t; + +/* hb_unicode_combining_class_t */ + +/* Note: newer versions of Unicode may add new values. Clients should be ready to handle + * any value in the 0..254 range being returned from hb_unicode_combining_class(). + */ + +/* Unicode Character Database property: Canonical_Combining_Class (ccc) */ +typedef enum +{ + HB_UNICODE_COMBINING_CLASS_NOT_REORDERED = 0, + HB_UNICODE_COMBINING_CLASS_OVERLAY = 1, + HB_UNICODE_COMBINING_CLASS_NUKTA = 7, + HB_UNICODE_COMBINING_CLASS_KANA_VOICING = 8, + HB_UNICODE_COMBINING_CLASS_VIRAMA = 9, + + /* Hebrew */ + HB_UNICODE_COMBINING_CLASS_CCC10 = 10, + HB_UNICODE_COMBINING_CLASS_CCC11 = 11, + HB_UNICODE_COMBINING_CLASS_CCC12 = 12, + HB_UNICODE_COMBINING_CLASS_CCC13 = 13, + HB_UNICODE_COMBINING_CLASS_CCC14 = 14, + HB_UNICODE_COMBINING_CLASS_CCC15 = 15, + HB_UNICODE_COMBINING_CLASS_CCC16 = 16, + HB_UNICODE_COMBINING_CLASS_CCC17 = 17, + HB_UNICODE_COMBINING_CLASS_CCC18 = 18, + HB_UNICODE_COMBINING_CLASS_CCC19 = 19, + HB_UNICODE_COMBINING_CLASS_CCC20 = 20, + HB_UNICODE_COMBINING_CLASS_CCC21 = 21, + HB_UNICODE_COMBINING_CLASS_CCC22 = 22, + HB_UNICODE_COMBINING_CLASS_CCC23 = 23, + HB_UNICODE_COMBINING_CLASS_CCC24 = 24, + HB_UNICODE_COMBINING_CLASS_CCC25 = 25, + HB_UNICODE_COMBINING_CLASS_CCC26 = 26, + + /* Arabic */ + HB_UNICODE_COMBINING_CLASS_CCC27 = 27, + HB_UNICODE_COMBINING_CLASS_CCC28 = 28, + HB_UNICODE_COMBINING_CLASS_CCC29 = 29, + HB_UNICODE_COMBINING_CLASS_CCC30 = 30, + HB_UNICODE_COMBINING_CLASS_CCC31 = 31, + HB_UNICODE_COMBINING_CLASS_CCC32 = 32, + HB_UNICODE_COMBINING_CLASS_CCC33 = 33, + HB_UNICODE_COMBINING_CLASS_CCC34 = 34, + HB_UNICODE_COMBINING_CLASS_CCC35 = 35, + + /* Syriac */ + HB_UNICODE_COMBINING_CLASS_CCC36 = 36, + + /* Telugu */ + HB_UNICODE_COMBINING_CLASS_CCC84 = 84, + HB_UNICODE_COMBINING_CLASS_CCC91 = 91, + + /* Thai */ + HB_UNICODE_COMBINING_CLASS_CCC103 = 103, + HB_UNICODE_COMBINING_CLASS_CCC107 = 107, + + /* Lao */ + HB_UNICODE_COMBINING_CLASS_CCC118 = 118, + HB_UNICODE_COMBINING_CLASS_CCC122 = 122, + + /* Tibetan */ + HB_UNICODE_COMBINING_CLASS_CCC129 = 129, + HB_UNICODE_COMBINING_CLASS_CCC130 = 130, + HB_UNICODE_COMBINING_CLASS_CCC133 = 132, + + + HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT = 200, + HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW = 202, + HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE = 214, + HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT = 216, + HB_UNICODE_COMBINING_CLASS_BELOW_LEFT = 218, + HB_UNICODE_COMBINING_CLASS_BELOW = 220, + HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT = 222, + HB_UNICODE_COMBINING_CLASS_LEFT = 224, + HB_UNICODE_COMBINING_CLASS_RIGHT = 226, + HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT = 228, + HB_UNICODE_COMBINING_CLASS_ABOVE = 230, + HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT = 232, + HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW = 233, + HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE = 234, + + HB_UNICODE_COMBINING_CLASS_IOTA_SUBSCRIPT = 240, + + HB_UNICODE_COMBINING_CLASS_INVALID = 255 +} hb_unicode_combining_class_t; + + +/* + * hb_unicode_funcs_t + */ + +typedef struct hb_unicode_funcs_t hb_unicode_funcs_t; + + +/* + * just give me the best implementation you've got there. + */ +hb_unicode_funcs_t * +hb_unicode_funcs_get_default (void); + + +hb_unicode_funcs_t * +hb_unicode_funcs_create (hb_unicode_funcs_t *parent); + +hb_unicode_funcs_t * +hb_unicode_funcs_get_empty (void); + +hb_unicode_funcs_t * +hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs); + +void +hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs); + +hb_bool_t +hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs, + hb_user_data_key_t *key, + void * data, + hb_destroy_func_t destroy, + hb_bool_t replace); + + +void * +hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs, + hb_user_data_key_t *key); + + +void +hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs); + +hb_bool_t +hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs); + +hb_unicode_funcs_t * +hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs); + + +/* + * funcs + */ + +/* typedefs */ + +typedef hb_unicode_combining_class_t (*hb_unicode_combining_class_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef unsigned int (*hb_unicode_eastasian_width_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef hb_unicode_general_category_t (*hb_unicode_general_category_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef hb_codepoint_t (*hb_unicode_mirroring_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); +typedef hb_script_t (*hb_unicode_script_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data); + +typedef hb_bool_t (*hb_unicode_compose_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab, + void *user_data); +typedef hb_bool_t (*hb_unicode_decompose_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b, + void *user_data); + +/** + * hb_unicode_decompose_compatibility_func_t: + * @ufuncs: Unicode function structure + * @u: codepoint to decompose + * @decomposed: address of codepoint array (of length %HB_UNICODE_MAX_DECOMPOSITION_LEN) to write decomposition into + * @user_data: user data pointer as passed to hb_unicode_funcs_set_decompose_compatibility_func() + * + * Fully decompose @u to its Unicode compatibility decomposition. The codepoints of the decomposition will be written to @decomposed. + * The complete length of the decomposition will be returned. + * + * If @u has no compatibility decomposition, zero should be returned. + * + * The Unicode standard guarantees that a buffer of length %HB_UNICODE_MAX_DECOMPOSITION_LEN codepoints will always be sufficient for any + * compatibility decomposition plus an terminating value of 0. Consequently, @decompose must be allocated by the caller to be at least this length. Implementations + * of this function type must ensure that they do not write past the provided array. + * + * Return value: number of codepoints in the full compatibility decomposition of @u, or 0 if no decomposition available. + */ +typedef unsigned int (*hb_unicode_decompose_compatibility_func_t) (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t u, + hb_codepoint_t *decomposed, + void *user_data); + +/* See Unicode 6.1 for details on the maximum decomposition length. */ +#define HB_UNICODE_MAX_DECOMPOSITION_LEN (18+1) /* codepoints */ + +/* setters */ + +void +hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_combining_class_func_t combining_class_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_eastasian_width_func_t eastasian_width_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_general_category_func_t general_category_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_mirroring_func_t mirroring_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_script_func_t script_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_compose_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_compose_func_t compose_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_decompose_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_decompose_func_t decompose_func, + void *user_data, hb_destroy_func_t destroy); + +void +hb_unicode_funcs_set_decompose_compatibility_func (hb_unicode_funcs_t *ufuncs, + hb_unicode_decompose_compatibility_func_t decompose_compatibility_func, + void *user_data, hb_destroy_func_t destroy); + +/* accessors */ + +hb_unicode_combining_class_t +hb_unicode_combining_class (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +unsigned int +hb_unicode_eastasian_width (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_unicode_general_category_t +hb_unicode_general_category (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_codepoint_t +hb_unicode_mirroring (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_script_t +hb_unicode_script (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode); + +hb_bool_t +hb_unicode_compose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab); +hb_bool_t +hb_unicode_decompose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b); + +unsigned int +hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t u, + hb_codepoint_t *decomposed); + +HB_END_DECLS + +#endif /* HB_UNICODE_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.cc new file mode 100644 index 00000000000..2f01c28778f --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.cc @@ -0,0 +1,475 @@ +/* + * Copyright © 2011,2012 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 + */ + +#define _WIN32_WINNT 0x0600 +#define WIN32_LEAN_AND_MEAN + +#define HB_SHAPER uniscribe +#include "hb-shaper-impl-private.hh" + +#include <windows.h> +#include <usp10.h> + +#include "hb-uniscribe.h" + +#include "hb-ot-name-table.hh" +#include "hb-ot-tag.h" + + +#ifndef HB_DEBUG_UNISCRIBE +#define HB_DEBUG_UNISCRIBE (HB_DEBUG+0) +#endif + + +/* +DWORD GetFontData( + __in HDC hdc, + __in DWORD dwTable, + __in DWORD dwOffset, + __out LPVOID lpvBuffer, + __in DWORD cbData +); +*/ + + +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, face) +HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, font) + + +/* + * shaper face data + */ + +struct hb_uniscribe_shaper_face_data_t { + HANDLE fh; +}; + +hb_uniscribe_shaper_face_data_t * +_hb_uniscribe_shaper_face_data_create (hb_face_t *face) +{ + hb_uniscribe_shaper_face_data_t *data = (hb_uniscribe_shaper_face_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_face_data_t)); + if (unlikely (!data)) + return NULL; + + hb_blob_t *blob = hb_face_reference_blob (face); + unsigned int blob_length; + const char *blob_data = hb_blob_get_data (blob, &blob_length); + if (unlikely (!blob_length)) + DEBUG_MSG (UNISCRIBE, face, "Face has empty blob"); + + DWORD num_fonts_installed; + data->fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed); + hb_blob_destroy (blob); + if (unlikely (!data->fh)) { + DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed"); + free (data); + return NULL; + } + + return data; +} + +void +_hb_uniscribe_shaper_face_data_destroy (hb_uniscribe_shaper_face_data_t *data) +{ + RemoveFontMemResourceEx (data->fh); + free (data); +} + + +/* + * shaper font data + */ + +struct hb_uniscribe_shaper_font_data_t { + HDC hdc; + LOGFONTW log_font; + HFONT hfont; + SCRIPT_CACHE script_cache; +}; + +static bool +populate_log_font (LOGFONTW *lf, + hb_font_t *font) +{ + memset (lf, 0, sizeof (*lf)); + lf->lfHeight = -font->y_scale; + lf->lfCharSet = DEFAULT_CHARSET; + + hb_blob_t *blob = OT::Sanitizer<OT::name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e'))); + const OT::name *name_table = OT::Sanitizer<OT::name>::lock_instance (blob); + unsigned int len = name_table->get_name (3, 1, 0x409, 4, + lf->lfFaceName, + sizeof (lf->lfFaceName[0]) * LF_FACESIZE) + / sizeof (lf->lfFaceName[0]); + hb_blob_destroy (blob); + + if (unlikely (!len)) { + DEBUG_MSG (UNISCRIBE, NULL, "Didn't find English name table entry"); + return false; + } + if (unlikely (len >= LF_FACESIZE)) { + DEBUG_MSG (UNISCRIBE, NULL, "Font name too long"); + return false; + } + + for (unsigned int i = 0; i < len; i++) + lf->lfFaceName[i] = hb_be_uint16 (lf->lfFaceName[i]); + lf->lfFaceName[len] = 0; + + return true; +} + +hb_uniscribe_shaper_font_data_t * +_hb_uniscribe_shaper_font_data_create (hb_font_t *font) +{ + if (unlikely (!hb_uniscribe_shaper_face_data_ensure (font->face))) return NULL; + + hb_uniscribe_shaper_font_data_t *data = (hb_uniscribe_shaper_font_data_t *) calloc (1, sizeof (hb_uniscribe_shaper_font_data_t)); + if (unlikely (!data)) + return NULL; + + data->hdc = GetDC (NULL); + + if (unlikely (!populate_log_font (&data->log_font, font))) { + DEBUG_MSG (UNISCRIBE, font, "Font populate_log_font() failed"); + _hb_uniscribe_shaper_font_data_destroy (data); + return NULL; + } + + data->hfont = CreateFontIndirectW (&data->log_font); + if (unlikely (!data->hfont)) { + DEBUG_MSG (UNISCRIBE, font, "Font CreateFontIndirectW() failed"); + _hb_uniscribe_shaper_font_data_destroy (data); + return NULL; + } + + if (!SelectObject (data->hdc, data->hfont)) { + DEBUG_MSG (UNISCRIBE, font, "Font SelectObject() failed"); + _hb_uniscribe_shaper_font_data_destroy (data); + return NULL; + } + + return data; +} + +void +_hb_uniscribe_shaper_font_data_destroy (hb_uniscribe_shaper_font_data_t *data) +{ + if (data->hdc) + ReleaseDC (NULL, data->hdc); + if (data->hfont) + DeleteObject (data->hfont); + if (data->script_cache) + ScriptFreeCache (&data->script_cache); + free (data); +} + +LOGFONTW * +hb_uniscribe_font_get_logfontw (hb_font_t *font) +{ + if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL; + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); + return &font_data->log_font; +} + +HFONT +hb_uniscribe_font_get_hfont (hb_font_t *font) +{ + if (unlikely (!hb_uniscribe_shaper_font_data_ensure (font))) return NULL; + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); + return font_data->hfont; +} + + +/* + * shaper shape_plan data + */ + +struct hb_uniscribe_shaper_shape_plan_data_t {}; + +hb_uniscribe_shaper_shape_plan_data_t * +_hb_uniscribe_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, + const hb_feature_t *user_features HB_UNUSED, + unsigned int num_user_features HB_UNUSED) +{ + return (hb_uniscribe_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; +} + +void +_hb_uniscribe_shaper_shape_plan_data_destroy (hb_uniscribe_shaper_shape_plan_data_t *data HB_UNUSED) +{ +} + + +/* + * shaper + */ + + +hb_bool_t +_hb_uniscribe_shape (hb_shape_plan_t *shape_plan, + hb_font_t *font, + hb_buffer_t *buffer, + const hb_feature_t *features, + unsigned int num_features) +{ + hb_face_t *face = font->face; + hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face); + hb_uniscribe_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font); + +#define FAIL(...) \ + HB_STMT_START { \ + DEBUG_MSG (UNISCRIBE, NULL, __VA_ARGS__); \ + return false; \ + } HB_STMT_END; + + HRESULT hr; + +retry: + + unsigned int scratch_size; + char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size); + + /* Allocate char buffers; they all fit */ + +#define ALLOCATE_ARRAY(Type, name, len) \ + Type *name = (Type *) scratch; \ + scratch += (len) * sizeof ((name)[0]); \ + scratch_size -= (len) * sizeof ((name)[0]); + +#define utf16_index() var1.u32 + + WCHAR *pchars = (WCHAR *) scratch; + unsigned int chars_len = 0; + for (unsigned int i = 0; i < buffer->len; i++) { + hb_codepoint_t c = buffer->info[i].codepoint; + buffer->info[i].utf16_index() = chars_len; + if (likely (c < 0x10000)) + pchars[chars_len++] = c; + else if (unlikely (c >= 0x110000)) + pchars[chars_len++] = 0xFFFD; + else { + pchars[chars_len++] = 0xD800 + ((c - 0x10000) >> 10); + pchars[chars_len++] = 0xDC00 + ((c - 0x10000) & ((1 << 10) - 1)); + } + } + + ALLOCATE_ARRAY (WCHAR, wchars, chars_len); + ALLOCATE_ARRAY (WORD, log_clusters, chars_len); + ALLOCATE_ARRAY (SCRIPT_CHARPROP, char_props, chars_len); + + /* On Windows, we don't care about alignment...*/ + unsigned int glyphs_size = scratch_size / (sizeof (WORD) + + sizeof (SCRIPT_GLYPHPROP) + + sizeof (int) + + sizeof (GOFFSET) + + sizeof (uint32_t)); + + ALLOCATE_ARRAY (WORD, glyphs, glyphs_size); + ALLOCATE_ARRAY (SCRIPT_GLYPHPROP, glyph_props, glyphs_size); + ALLOCATE_ARRAY (int, advances, glyphs_size); + ALLOCATE_ARRAY (GOFFSET, offsets, glyphs_size); + ALLOCATE_ARRAY (uint32_t, vis_clusters, glyphs_size); + +#undef ALLOCATE_ARRAY + +#define MAX_ITEMS 256 + + SCRIPT_ITEM items[MAX_ITEMS + 1]; + SCRIPT_CONTROL bidi_control = {0}; + SCRIPT_STATE bidi_state = {0}; + ULONG script_tags[MAX_ITEMS]; + int item_count; + + /* MinGW32 doesn't define fMergeNeutralItems, so we bruteforce */ + //bidi_control.fMergeNeutralItems = true; + *(uint32_t*)&bidi_control |= 1<<24; + + bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1; + bidi_state.fOverrideDirection = 1; + + hr = ScriptItemizeOpenType (wchars, + chars_len, + MAX_ITEMS, + &bidi_control, + &bidi_state, + items, + script_tags, + &item_count); + if (unlikely (FAILED (hr))) + FAIL ("ScriptItemizeOpenType() failed: 0x%08xL", hr); + +#undef MAX_ITEMS + + int *range_char_counts = NULL; + TEXTRANGE_PROPERTIES **range_properties = NULL; + int range_count = 0; + if (num_features) { + /* TODO setup ranges */ + } + + OPENTYPE_TAG language_tag = hb_uint32_swap (hb_ot_tag_from_language (buffer->props.language)); + + unsigned int glyphs_offset = 0; + unsigned int glyphs_len; + bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); + for (unsigned int j = 0; j < item_count; j++) + { + unsigned int i = backward ? item_count - 1 - j : j; + unsigned int chars_offset = items[i].iCharPos; + unsigned int item_chars_len = items[i + 1].iCharPos - chars_offset; + + retry_shape: + hr = ScriptShapeOpenType (font_data->hdc, + &font_data->script_cache, + &items[i].a, + script_tags[i], + language_tag, + range_char_counts, + range_properties, + range_count, + wchars + chars_offset, + item_chars_len, + glyphs_size - glyphs_offset, + /* out */ + log_clusters + chars_offset, + char_props + chars_offset, + glyphs + glyphs_offset, + glyph_props + glyphs_offset, + (int *) &glyphs_len); + + if (unlikely (items[i].a.fNoGlyphIndex)) + FAIL ("ScriptShapeOpenType() set fNoGlyphIndex"); + if (unlikely (hr == E_OUTOFMEMORY)) + { + buffer->ensure (buffer->allocated * 2); + if (buffer->in_error) + FAIL ("Buffer resize failed"); + goto retry; + } + if (unlikely (hr == USP_E_SCRIPT_NOT_IN_FONT)) + { + if (items[i].a.eScript == SCRIPT_UNDEFINED) + FAIL ("ScriptShapeOpenType() failed: Font doesn't support script"); + items[i].a.eScript = SCRIPT_UNDEFINED; + goto retry_shape; + } + if (unlikely (FAILED (hr))) + { + FAIL ("ScriptShapeOpenType() failed: 0x%08xL", hr); + } + + for (unsigned int j = chars_offset; j < chars_offset + item_chars_len; j++) + log_clusters[j] += glyphs_offset; + + hr = ScriptPlaceOpenType (font_data->hdc, + &font_data->script_cache, + &items[i].a, + script_tags[i], + language_tag, + range_char_counts, + range_properties, + range_count, + wchars + chars_offset, + log_clusters + chars_offset, + char_props + chars_offset, + item_chars_len, + glyphs + glyphs_offset, + glyph_props + glyphs_offset, + glyphs_len, + /* out */ + advances + glyphs_offset, + offsets + glyphs_offset, + NULL); + if (unlikely (FAILED (hr))) + FAIL ("ScriptPlaceOpenType() failed: 0x%08xL", hr); + + glyphs_offset += glyphs_len; + } + glyphs_len = glyphs_offset; + + /* Ok, we've got everything we need, now compose output buffer, + * very, *very*, carefully! */ + + /* Calculate visual-clusters. That's what we ship. */ + for (unsigned int i = 0; i < glyphs_len; i++) + vis_clusters[i] = -1; + for (unsigned int i = 0; i < buffer->len; i++) { + uint32_t *p = &vis_clusters[log_clusters[buffer->info[i].utf16_index()]]; + *p = MIN (*p, buffer->info[i].cluster); + } + if (!backward) { + for (unsigned int i = 1; i < glyphs_len; i++) + if (vis_clusters[i] == -1) + vis_clusters[i] = vis_clusters[i - 1]; + } else { + for (int i = glyphs_len - 2; i >= 0; i--) + if (vis_clusters[i] == -1) + vis_clusters[i] = vis_clusters[i + 1]; + } + +#undef utf16_index + + buffer->ensure (glyphs_len); + if (buffer->in_error) + FAIL ("Buffer in error"); + +#undef FAIL + + /* Set glyph infos */ + buffer->len = 0; + for (unsigned int i = 0; i < glyphs_len; i++) + { + hb_glyph_info_t *info = &buffer->info[buffer->len++]; + + info->codepoint = glyphs[i]; + info->cluster = vis_clusters[i]; + + /* The rest is crap. Let's store position info there for now. */ + info->mask = advances[i]; + info->var1.u32 = offsets[i].du; + info->var2.u32 = offsets[i].dv; + } + + /* Set glyph positions */ + buffer->clear_positions (); + for (unsigned int i = 0; i < glyphs_len; i++) + { + hb_glyph_info_t *info = &buffer->info[i]; + hb_glyph_position_t *pos = &buffer->pos[i]; + + /* TODO vertical */ + pos->x_advance = info->mask; + pos->x_offset = info->var1.u32; + pos->y_offset = info->var2.u32; + } + + /* Wow, done! */ + return true; +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.h new file mode 100644 index 00000000000..51887c8794b --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-uniscribe.h @@ -0,0 +1,49 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_UNISCRIBE_H +#define HB_UNISCRIBE_H + +#include "hb.h" + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif +#include <windows.h> + +HB_BEGIN_DECLS + + +LOGFONTW * +hb_uniscribe_font_get_logfontw (hb_font_t *font); + +HFONT +hb_uniscribe_font_get_hfont (hb_font_t *font); + + +HB_END_DECLS + +#endif /* HB_UNISCRIBE_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-utf-private.hh b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-utf-private.hh new file mode 100644 index 00000000000..b9a6519d28e --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-utf-private.hh @@ -0,0 +1,204 @@ +/* + * Copyright © 2011,2012 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_UTF_PRIVATE_HH +#define HB_UTF_PRIVATE_HH + +#include "hb-private.hh" + + +/* UTF-8 */ + +#define HB_UTF8_COMPUTE(Char, Mask, Len) \ + if (Char < 128) { Len = 1; Mask = 0x7f; } \ + else if ((Char & 0xe0) == 0xc0) { Len = 2; Mask = 0x1f; } \ + else if ((Char & 0xf0) == 0xe0) { Len = 3; Mask = 0x0f; } \ + else if ((Char & 0xf8) == 0xf0) { Len = 4; Mask = 0x07; } \ + else Len = 0; + +static inline const uint8_t * +hb_utf_next (const uint8_t *text, + const uint8_t *end, + hb_codepoint_t *unicode) +{ + hb_codepoint_t c = *text, mask; + unsigned int len; + + /* TODO check for overlong sequences? */ + + HB_UTF8_COMPUTE (c, mask, len); + if (unlikely (!len || (unsigned int) (end - text) < len)) { + *unicode = -1; + return text + 1; + } else { + hb_codepoint_t result; + unsigned int i; + result = c & mask; + for (i = 1; i < len; i++) + { + if (unlikely ((text[i] & 0xc0) != 0x80)) + { + *unicode = -1; + return text + 1; + } + result <<= 6; + result |= (text[i] & 0x3f); + } + *unicode = result; + return text + len; + } +} + +static inline const uint8_t * +hb_utf_prev (const uint8_t *text, + const uint8_t *start, + hb_codepoint_t *unicode) +{ + const uint8_t *end = text--; + while (start < text && (*text & 0xc0) == 0x80 && end - text < 4) + text--; + + hb_codepoint_t c = *text, mask; + unsigned int len; + + /* TODO check for overlong sequences? */ + + HB_UTF8_COMPUTE (c, mask, len); + if (unlikely (!len || (unsigned int) (end - text) != len)) { + *unicode = -1; + return end - 1; + } else { + hb_codepoint_t result; + unsigned int i; + result = c & mask; + for (i = 1; i < len; i++) + { + result <<= 6; + result |= (text[i] & 0x3f); + } + *unicode = result; + return text; + } +} + + +static inline unsigned int +hb_utf_strlen (const uint8_t *text) +{ + return strlen ((const char *) text); +} + + +/* UTF-16 */ + +static inline const uint16_t * +hb_utf_next (const uint16_t *text, + const uint16_t *end, + hb_codepoint_t *unicode) +{ + hb_codepoint_t c = *text++; + + if (unlikely (hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdbff))) + { + /* high surrogate */ + hb_codepoint_t l; + if (text < end && ((l = *text), likely (hb_in_range<hb_codepoint_t> (l, 0xdc00, 0xdfff)))) + { + /* low surrogate */ + *unicode = (c << 10) + l - ((0xd800 << 10) - 0x10000 + 0xdc00); + text++; + } else + *unicode = -1; + } else + *unicode = c; + + return text; +} + +static inline const uint16_t * +hb_utf_prev (const uint16_t *text, + const uint16_t *start, + hb_codepoint_t *unicode) +{ + hb_codepoint_t c = *--text; + + if (unlikely (hb_in_range<hb_codepoint_t> (c, 0xdc00, 0xdfff))) + { + /* low surrogate */ + hb_codepoint_t h; + if (start < text && ((h = *(text - 1)), likely (hb_in_range<hb_codepoint_t> (h, 0xd800, 0xdbff)))) + { + /* high surrogate */ + *unicode = (h << 10) + c - ((0xd800 << 10) - 0x10000 + 0xdc00); + text--; + } else + *unicode = -1; + } else + *unicode = c; + + return text; +} + + +static inline unsigned int +hb_utf_strlen (const uint16_t *text) +{ + unsigned int l = 0; + while (*text++) l++; + return l; +} + + +/* UTF-32 */ + +static inline const uint32_t * +hb_utf_next (const uint32_t *text, + const uint32_t *end HB_UNUSED, + hb_codepoint_t *unicode) +{ + *unicode = *text++; + return text; +} + +static inline const uint32_t * +hb_utf_prev (const uint32_t *text, + const uint32_t *start HB_UNUSED, + hb_codepoint_t *unicode) +{ + *unicode = *--text; + return text; +} + +static inline unsigned int +hb_utf_strlen (const uint32_t *text) +{ + unsigned int l = 0; + while (*text++) l++; + return l; +} + + +#endif /* HB_UTF_PRIVATE_HH */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-version.h.in b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-version.h.in new file mode 100644 index 00000000000..43634f91ce8 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-version.h.in @@ -0,0 +1,66 @@ +/* + * Copyright © 2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifndef HB_H_IN +#error "Include <hb.h> instead." +#endif + +#ifndef HB_VERSION_H +#define HB_VERSION_H + +#include "hb-common.h" + +HB_BEGIN_DECLS + + +#define HB_VERSION_MAJOR @HB_VERSION_MAJOR@ +#define HB_VERSION_MINOR @HB_VERSION_MINOR@ +#define HB_VERSION_MICRO @HB_VERSION_MICRO@ + +#define HB_VERSION_STRING "@HB_VERSION@" + +#define HB_VERSION_CHECK(major,minor,micro) \ + ((major)*10000+(minor)*100+(micro) >= \ + HB_VERSION_MAJOR*10000+HB_VERSION_MINOR*100+HB_VERSION_MICRO) + + +void +hb_version (unsigned int *major, + unsigned int *minor, + unsigned int *micro); + +const char * +hb_version_string (void); + +hb_bool_t +hb_version_check (unsigned int major, + unsigned int minor, + unsigned int micro); + + +HB_END_DECLS + +#endif /* HB_VERSION_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-warning.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-warning.cc new file mode 100644 index 00000000000..01adceac325 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb-warning.cc @@ -0,0 +1,39 @@ +/* + * Copyright © 2012 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#include "hb-atomic-private.hh" +#include "hb-mutex-private.hh" + + +#if defined(HB_ATOMIC_INT_NIL) +#pragma message("Could not find any system to define atomic_int macros, library may NOT be thread-safe.") +#endif +#if defined(HB_MUTEX_IMPL_NIL) +#pragma message("Could not find any system to define mutex macros, library may NOT be thread-safe.") +#endif +#if defined(HB_ATOMIC_INT_NIL) || defined(HB_MUTEX_IMPL_NIL) +#pragma message("To suppress these warnings, define HB_NO_MT.") +#endif diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb.h b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb.h new file mode 100644 index 00000000000..52c479cc2e5 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/hb.h @@ -0,0 +1,45 @@ +/* + * Copyright © 2009 Red Hat, 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 + */ + +#ifndef HB_H +#define HB_H +#define HB_H_IN + +#include "hb-blob.h" +#include "hb-buffer.h" +#include "hb-common.h" +#include "hb-font.h" +#include "hb-set.h" +#include "hb-shape.h" +#include "hb-shape-plan.h" +#include "hb-unicode.h" +#include "hb-version.h" + +HB_BEGIN_DECLS +HB_END_DECLS + +#undef HB_H_IN +#endif /* HB_H */ diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/main.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/main.cc new file mode 100644 index 00000000000..b362744e213 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/main.cc @@ -0,0 +1,197 @@ +/* + * Copyright © 2007,2008,2009 Red Hat, 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 + */ + +#include "hb-mutex-private.hh" +#include "hb-open-file-private.hh" +#include "hb-ot-layout-gdef-table.hh" +#include "hb-ot-layout-gsubgpos-private.hh" + +#ifdef HAVE_GLIB +#include <glib.h> +#endif +#include <stdlib.h> +#include <stdio.h> + + +using namespace OT; + + +int +main (int argc, char **argv) +{ + if (argc != 2) { + fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]); + exit (1); + } + + const char *font_data = NULL; + int len = 0; + +#ifdef HAVE_GLIB + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); + font_data = g_mapped_file_get_contents (mf); + len = g_mapped_file_get_length (mf); +#else + FILE *f = fopen (argv[1], "rb"); + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + font_data = (const char *) malloc (len); + len = fread ((char *) font_data, 1, len, f); +#endif + + printf ("Opened font file %s: %d bytes long\n", argv[1], len); + + const OpenTypeFontFile &ot = *CastP<OpenTypeFontFile> (font_data); + + switch (ot.get_tag ()) { + case OpenTypeFontFile::TrueTypeTag: + printf ("OpenType font with TrueType outlines\n"); + break; + case OpenTypeFontFile::CFFTag: + printf ("OpenType font with CFF (Type1) outlines\n"); + break; + case OpenTypeFontFile::TTCTag: + printf ("TrueType Collection of OpenType fonts\n"); + break; + case OpenTypeFontFile::TrueTag: + printf ("Obsolete Apple TrueType font\n"); + break; + case OpenTypeFontFile::Typ1Tag: + printf ("Obsolete Apple Type1 font in SFNT container\n"); + break; + default: + printf ("Unknown font format\n"); + break; + } + + int num_fonts = ot.get_face_count (); + printf ("%d font(s) found in file\n", num_fonts); + for (int n_font = 0; n_font < num_fonts; n_font++) { + const OpenTypeFontFace &font = ot.get_face (n_font); + printf ("Font %d of %d:\n", n_font, num_fonts); + + int num_tables = font.get_table_count (); + printf (" %d table(s) found in font\n", num_tables); + for (int n_table = 0; n_table < num_tables; n_table++) { + const OpenTypeTable &table = font.get_table (n_table); + printf (" Table %2d of %2d: %.4s (0x%08x+0x%08x)\n", n_table, num_tables, + (const char *)table.tag, + (unsigned int) table.offset, + (unsigned int) table.length); + + switch (table.tag) { + + case GSUBGPOS::GSUBTag: + case GSUBGPOS::GPOSTag: + { + + const GSUBGPOS &g = *CastP<GSUBGPOS> (font_data + table.offset); + + int num_scripts = g.get_script_count (); + printf (" %d script(s) found in table\n", num_scripts); + for (int n_script = 0; n_script < num_scripts; n_script++) { + const Script &script = g.get_script (n_script); + printf (" Script %2d of %2d: %.4s\n", n_script, num_scripts, + (const char *)g.get_script_tag(n_script)); + + if (!script.has_default_lang_sys()) + printf (" No default language system\n"); + int num_langsys = script.get_lang_sys_count (); + printf (" %d language system(s) found in script\n", num_langsys); + for (int n_langsys = script.has_default_lang_sys() ? -1 : 0; n_langsys < num_langsys; n_langsys++) { + const LangSys &langsys = n_langsys == -1 + ? script.get_default_lang_sys () + : script.get_lang_sys (n_langsys); + if (n_langsys == -1) + printf (" Default Language System\n"); + else + printf (" Language System %2d of %2d: %.4s\n", n_langsys, num_langsys, + (const char *)script.get_lang_sys_tag (n_langsys)); + if (langsys.get_required_feature_index () == Index::NOT_FOUND_INDEX) + printf (" No required feature\n"); + + int num_features = langsys.get_feature_count (); + printf (" %d feature(s) found in language system\n", num_features); + for (int n_feature = 0; n_feature < num_features; n_feature++) { + printf (" Feature index %2d of %2d: %d\n", n_feature, num_features, + langsys.get_feature_index (n_feature)); + } + } + } + + int num_features = g.get_feature_count (); + printf (" %d feature(s) found in table\n", num_features); + for (int n_feature = 0; n_feature < num_features; n_feature++) { + const Feature &feature = g.get_feature (n_feature); + printf (" Feature %2d of %2d: %.4s; %d lookup(s)\n", n_feature, num_features, + (const char *)g.get_feature_tag(n_feature), + feature.get_lookup_count()); + + int num_lookups = feature.get_lookup_count (); + printf (" %d lookup(s) found in feature\n", num_lookups); + for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { + printf (" Lookup index %2d of %2d: %d\n", n_lookup, num_lookups, + feature.get_lookup_index (n_lookup)); + } + } + + int num_lookups = g.get_lookup_count (); + printf (" %d lookup(s) found in table\n", num_lookups); + for (int n_lookup = 0; n_lookup < num_lookups; n_lookup++) { + const Lookup &lookup = g.get_lookup (n_lookup); + printf (" Lookup %2d of %2d: type %d, props 0x%04X\n", n_lookup, num_lookups, + lookup.get_type(), lookup.get_props()); + } + + } + break; + + case GDEF::Tag: + { + + const GDEF &gdef = *CastP<GDEF> (font_data + table.offset); + + printf (" Has %sglyph classes\n", + gdef.has_glyph_classes () ? "" : "no "); + printf (" Has %smark attachment types\n", + gdef.has_mark_attachment_types () ? "" : "no "); + printf (" Has %sattach points\n", + gdef.has_attach_points () ? "" : "no "); + printf (" Has %slig carets\n", + gdef.has_lig_carets () ? "" : "no "); + printf (" Has %smark sets\n", + gdef.has_mark_sets () ? "" : "no "); + break; + } + } + } + } + + return 0; +} + + diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-size-params.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-size-params.cc new file mode 100644 index 00000000000..947b5669a14 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-size-params.cc @@ -0,0 +1,93 @@ +/* + * Copyright © 2010,2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "hb.h" +#include "hb-ot.h" + +#ifdef HAVE_GLIB +#include <glib.h> +#endif +#include <stdlib.h> +#include <stdio.h> + +int +main (int argc, char **argv) +{ + hb_blob_t *blob = NULL; + + if (argc != 2) { + fprintf (stderr, "usage: %s font-file\n", argv[0]); + exit (1); + } + + /* Create the blob */ + { + const char *font_data; + unsigned int len; + hb_destroy_func_t destroy; + void *user_data; + hb_memory_mode_t mm; + +#ifdef HAVE_GLIB + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); + font_data = g_mapped_file_get_contents (mf); + len = g_mapped_file_get_length (mf); + destroy = (hb_destroy_func_t) g_mapped_file_unref; + user_data = (void *) mf; + mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; +#else + FILE *f = fopen (argv[1], "rb"); + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + font_data = (const char *) malloc (len); + if (!font_data) len = 0; + len = fread ((char *) font_data, 1, len, f); + destroy = free; + user_data = (void *) font_data; + fclose (f); + mm = HB_MEMORY_MODE_WRITABLE; +#endif + + blob = hb_blob_create (font_data, len, mm, user_data, destroy); + } + + /* Create the face */ + hb_face_t *face = hb_face_create (blob, 0 /* first face */); + hb_blob_destroy (blob); + blob = NULL; + + unsigned int p[5]; + bool ret = hb_ot_layout_get_size_params (face, p, p+1, p+2, p+3, p+4); + + printf ("%g %u %u %g %g\n", p[0]/10., p[1], p[2], p[3]/10., p[4]/10.); + + return !ret; +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-would-substitute.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-would-substitute.cc new file mode 100644 index 00000000000..4731e265607 --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test-would-substitute.cc @@ -0,0 +1,103 @@ +/* + * Copyright © 2010,2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "hb.h" +#include "hb-ot.h" + +#ifdef HAVE_GLIB +#include <glib.h> +#endif +#include <stdlib.h> +#include <stdio.h> + +#ifdef HAVE_FREETYPE +#include "hb-ft.h" +#endif + +int +main (int argc, char **argv) +{ + hb_blob_t *blob = NULL; + + if (argc != 4 && argc != 5) { + fprintf (stderr, "usage: %s font-file lookup-index first-glyph [second-glyph]\n", argv[0]); + exit (1); + } + + /* Create the blob */ + { + const char *font_data; + unsigned int len; + hb_destroy_func_t destroy; + void *user_data; + hb_memory_mode_t mm; + +#ifdef HAVE_GLIB + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); + font_data = g_mapped_file_get_contents (mf); + len = g_mapped_file_get_length (mf); + destroy = (hb_destroy_func_t) g_mapped_file_unref; + user_data = (void *) mf; + mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; +#else + FILE *f = fopen (argv[1], "rb"); + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + font_data = (const char *) malloc (len); + if (!font_data) len = 0; + len = fread ((char *) font_data, 1, len, f); + destroy = free; + user_data = (void *) font_data; + fclose (f); + mm = HB_MEMORY_MODE_WRITABLE; +#endif + + blob = hb_blob_create (font_data, len, mm, user_data, destroy); + } + + /* Create the face */ + hb_face_t *face = hb_face_create (blob, 0 /* first face */); + hb_blob_destroy (blob); + blob = NULL; + + hb_font_t *font = hb_font_create (face); +#ifdef HAVE_FREETYPE + hb_ft_font_set_funcs (font); +#endif + + unsigned int len = argc - 3; + hb_codepoint_t glyphs[2]; + if (!hb_font_glyph_from_string (font, argv[3], -1, &glyphs[0]) || + (argc > 4 && + !hb_font_glyph_from_string (font, argv[4], -1, &glyphs[1]))) + return 2; + return !hb_ot_layout_lookup_would_substitute (face, strtol (argv[2], NULL, 0), glyphs, len, false); +} diff --git a/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test.cc b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test.cc new file mode 100644 index 00000000000..22108b86b7a --- /dev/null +++ b/Build/source/libs/harfbuzz/harfbuzz-0.9.10/src/test.cc @@ -0,0 +1,132 @@ +/* + * Copyright © 2010,2011 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Behdad Esfahbod + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "hb.h" + +#ifdef HAVE_GLIB +#include <glib.h> +#endif +#include <stdlib.h> +#include <stdio.h> + +#ifdef HAVE_FREETYPE +#include "hb-ft.h" +#endif + +int +main (int argc, char **argv) +{ + hb_blob_t *blob = NULL; + + if (argc != 2) { + fprintf (stderr, "usage: %s font-file.ttf\n", argv[0]); + exit (1); + } + + /* Create the blob */ + { + const char *font_data; + unsigned int len; + hb_destroy_func_t destroy; + void *user_data; + hb_memory_mode_t mm; + +#ifdef HAVE_GLIB + GMappedFile *mf = g_mapped_file_new (argv[1], false, NULL); + font_data = g_mapped_file_get_contents (mf); + len = g_mapped_file_get_length (mf); + destroy = (hb_destroy_func_t) g_mapped_file_unref; + user_data = (void *) mf; + mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; +#else + FILE *f = fopen (argv[1], "rb"); + fseek (f, 0, SEEK_END); + len = ftell (f); + fseek (f, 0, SEEK_SET); + font_data = (const char *) malloc (len); + if (!font_data) len = 0; + len = fread ((char *) font_data, 1, len, f); + destroy = free; + user_data = (void *) font_data; + fclose (f); + mm = HB_MEMORY_MODE_WRITABLE; +#endif + + blob = hb_blob_create (font_data, len, mm, user_data, destroy); + } + + printf ("Opened font file %s: %u bytes long\n", argv[1], hb_blob_get_length (blob)); + + /* Create the face */ + hb_face_t *face = hb_face_create (blob, 0 /* first face */); + hb_blob_destroy (blob); + blob = NULL; + unsigned int upem = hb_face_get_upem (face); + + hb_font_t *font = hb_font_create (face); + hb_font_set_scale (font, upem, upem); + +#ifdef HAVE_FREETYPE + hb_ft_font_set_funcs (font); +#endif + + hb_buffer_t *buffer = hb_buffer_create (); + + hb_buffer_add_utf8 (buffer, "\xe0\xa4\x95\xe0\xa5\x8d\xe0\xa4\xb0\xe0\xa5\x8d\xe0\xa4\x95", -1, 0, -1); + + hb_shape (font, buffer, NULL, 0); + + unsigned int count = hb_buffer_get_length (buffer); + hb_glyph_info_t *infos = hb_buffer_get_glyph_infos (buffer, NULL); + hb_glyph_position_t *positions = hb_buffer_get_glyph_positions (buffer, NULL); + + for (unsigned int i = 0; i < count; i++) + { + hb_glyph_info_t *info = &infos[i]; + hb_glyph_position_t *pos = &positions[i]; + + printf ("cluster %d glyph 0x%x at (%d,%d)+(%d,%d)\n", + info->cluster, + info->codepoint, + pos->x_offset, + pos->x_offset, + pos->x_advance, + pos->y_advance); + + } + + hb_buffer_destroy (buffer); + hb_font_destroy (font); + hb_face_destroy (face); + + return 0; +} + + |