summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-12-02 09:17:29 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-12-02 09:17:29 +0000
commitc213aa5e07da96e6e628f68e6ebc1aeaca213ea9 (patch)
tree3f8a0a47fec4e76f1371b33012602f739fb47dad
parent9ac026df0b860968a28af4b64d75c2246924ff40 (diff)
graphite2 1.2.4
git-svn-id: svn://tug.org/texlive/trunk@32299 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Build/source/libs/README2
-rw-r--r--Build/source/libs/graphite2/ChangeLog5
-rwxr-xr-xBuild/source/libs/graphite2/configure24
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/.hg_archival.txt5
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/Todo.txt6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/Bidi.cpp578
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/Silf.cpp387
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/TtfUtil.cpp1980
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/gr_logging.cpp225
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Endian.h107
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Sparse.h157
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfTypes.h419
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfUtil.h206
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/UtfCodec.h207
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/inc/json.h165
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.3/src/json.cpp126
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/ChangeLog (renamed from Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/ChangeLog)7
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/TL-Changes (renamed from Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/TL-Changes)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/.hg_archival.txt5
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/.hgeol (renamed from Build/source/libs/graphite2/graphite2-1.2.3/.hgeol)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/.hgignore (renamed from Build/source/libs/graphite2/graphite2-1.2.3/.hgignore)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/.hgtags (renamed from Build/source/libs/graphite2/graphite2-1.2.3/.hgtags)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/CMakeLists.txt (renamed from Build/source/libs/graphite2/graphite2-1.2.3/CMakeLists.txt)17
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/COPYING (renamed from Build/source/libs/graphite2/graphite2-1.2.3/COPYING)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/ChangeLog (renamed from Build/source/libs/graphite2/graphite2-1.2.3/ChangeLog)19
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/Graphite.cmake (renamed from Build/source/libs/graphite2/graphite2-1.2.3/Graphite.cmake)3
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/LICENSE (renamed from Build/source/libs/graphite2/graphite2-1.2.3/LICENSE)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/Todo.txt3
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/graphite2.pc.in (renamed from Build/source/libs/graphite2/graphite2-1.2.3/graphite2.pc.in)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Font.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Font.h)5
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Log.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Log.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Segment.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Segment.h)14
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Types.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Types.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Bidi.cpp823
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/CMakeLists.txt (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/CMakeLists.txt)14
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/CachedFace.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/CachedFace.cpp)26
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/CmapCache.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/CmapCache.cpp)8
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Code.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Code.cpp)47
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Face.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Face.cpp)78
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/FeatureMap.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/FeatureMap.cpp)120
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/FileFace.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/FileFace.cpp)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Font.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Font.cpp)6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphCache.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphCache.cpp)82
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphFace.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphFace.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Justifier.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Justifier.cpp)11
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/NameTable.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/NameTable.cpp)46
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Pass.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Pass.cpp)284
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Rule.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Rule.cpp)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/SegCache.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/SegCache.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheEntry.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheEntry.cpp)18
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheStore.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheStore.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Segment.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Segment.cpp)214
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Silf.cpp415
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Slot.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Slot.cpp)96
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/Sparse.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/Sparse.cpp)24
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/TtfUtil.cpp1979
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/UtfCodec.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/UtfCodec.cpp)10
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/call_machine.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/call_machine.cpp)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/direct_machine.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/direct_machine.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/files.mk (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/files.mk)5
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_char_info.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_char_info.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_face.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_face.cpp)46
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_features.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_features.cpp)6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_font.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_font.cpp)4
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_logging.cpp242
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_segment.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_segment.cpp)62
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/gr_slot.cpp (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/gr_slot.cpp)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Bidi.h126
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CachedFace.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CachedFace.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CharInfo.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CharInfo.h)6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CmapCache.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CmapCache.h)22
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Code.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Code.h)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Endian.h112
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Error.h127
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Face.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Face.h)25
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureMap.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureMap.h)28
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureVal.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureVal.h)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FileFace.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FileFace.h)2
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Font.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Font.h)6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphCache.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphCache.h)14
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphFace.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphFace.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/List.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/List.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Machine.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Machine.h)16
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Main.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Main.h)6
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/NameTable.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/NameTable.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Pass.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Pass.h)31
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Position.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Position.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Rule.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Rule.h)10
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCache.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCache.h)4
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheEntry.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheEntry.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheStore.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheStore.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Segment.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Segment.h)10
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Silf.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Silf.h)10
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Slot.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Slot.h)30
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Sparse.h170
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfTypes.h419
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfUtil.h206
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/UtfCodec.h207
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/bits.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/bits.h)34
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/debug.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/debug.h)16
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/json.h165
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/locale2lcid.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/locale2lcid.h)12
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcode_table.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcode_table.h)0
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcodes.h (renamed from Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcodes.h)36
-rw-r--r--Build/source/libs/graphite2/graphite2-1.2.4/src/json.cpp126
-rw-r--r--Build/source/libs/graphite2/version.ac2
106 files changed, 6052 insertions, 5278 deletions
diff --git a/Build/source/libs/README b/Build/source/libs/README
index 83b41845544..cd633a56946 100644
--- a/Build/source/libs/README
+++ b/Build/source/libs/README
@@ -18,7 +18,7 @@ freetype2 2.5.1 - checked 25nov13
gd 2.1.0 - checked 26jun13
https://bitbucket.org/libgd/gd-libgd/downloads/
-graphite2 1.2.3 - checked 12jun13
+graphite2 1.2.4 - checked 2dec13
http://sourceforge.net/projects/silgraphite/files/graphite2/
harfbuzz 0.9.24 - checked 14nov13
diff --git a/Build/source/libs/graphite2/ChangeLog b/Build/source/libs/graphite2/ChangeLog
index 0274842f59e..18870d12e4c 100644
--- a/Build/source/libs/graphite2/ChangeLog
+++ b/Build/source/libs/graphite2/ChangeLog
@@ -1,3 +1,8 @@
+2013-12-02 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Import graphite2-1.2.4.
+ * version.ac: Adjust.
+
2013-10-29 Peter Breitenlohner <peb@mppmu.mpg.de>
* gr2test.c: Print more info.
diff --git a/Build/source/libs/graphite2/configure b/Build/source/libs/graphite2/configure
index 5783e746892..8d52fb159a1 100755
--- a/Build/source/libs/graphite2/configure
+++ b/Build/source/libs/graphite2/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for graphite2 (TeX Live) 1.2.3.
+# Generated by GNU Autoconf 2.69 for graphite2 (TeX Live) 1.2.4.
#
# Report bugs to <tex-k@tug.org>.
#
@@ -579,12 +579,12 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='graphite2 (TeX Live)'
PACKAGE_TARNAME='graphite2--tex-live-'
-PACKAGE_VERSION='1.2.3'
-PACKAGE_STRING='graphite2 (TeX Live) 1.2.3'
+PACKAGE_VERSION='1.2.4'
+PACKAGE_STRING='graphite2 (TeX Live) 1.2.4'
PACKAGE_BUGREPORT='tex-k@tug.org'
PACKAGE_URL=''
-ac_unique_file="graphite2-1.2.3/graphite2.pc.in"
+ac_unique_file="graphite2-1.2.4/graphite2.pc.in"
ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
@@ -1254,7 +1254,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures graphite2 (TeX Live) 1.2.3 to adapt to many kinds of systems.
+\`configure' configures graphite2 (TeX Live) 1.2.4 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1321,7 +1321,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of graphite2 (TeX Live) 1.2.3:";;
+ short | recursive ) echo "Configuration of graphite2 (TeX Live) 1.2.4:";;
esac
cat <<\_ACEOF
@@ -1419,7 +1419,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-graphite2 (TeX Live) configure 1.2.3
+graphite2 (TeX Live) configure 1.2.4
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1558,7 +1558,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by graphite2 (TeX Live) $as_me 1.2.3, which was
+It was created by graphite2 (TeX Live) $as_me 1.2.4, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -3481,7 +3481,7 @@ fi
# Define the identity of the package.
PACKAGE='graphite2--tex-live-'
- VERSION='1.2.3'
+ VERSION='1.2.4'
cat >>confdefs.h <<_ACEOF
@@ -5008,7 +5008,7 @@ $as_echo "#define GRAPHITE2_NTRACING 1" >>confdefs.h
fi
-GRAPHITE2_TREE=graphite2-1.2.3
+GRAPHITE2_TREE=graphite2-1.2.4
ac_config_files="$ac_config_files Makefile include/graphite2/Makefile"
@@ -5576,7 +5576,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by graphite2 (TeX Live) $as_me 1.2.3, which was
+This file was extended by graphite2 (TeX Live) $as_me 1.2.4, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -5642,7 +5642,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-graphite2 (TeX Live) config.status 1.2.3
+graphite2 (TeX Live) config.status 1.2.4
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/.hg_archival.txt b/Build/source/libs/graphite2/graphite2-1.2.3/.hg_archival.txt
deleted file mode 100644
index 6420ed884d4..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/.hg_archival.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-repo: 999e2033695c3bcf2f65d611737ac9008805bd58
-node: 4605b74e26f3a119753b700524c49b98e7e45639
-branch: default
-latesttag: 1.2.2
-latesttagdistance: 8
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/Todo.txt b/Build/source/libs/graphite2/graphite2-1.2.3/Todo.txt
deleted file mode 100644
index 93569ddb8a1..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/Todo.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Expected changes to come:
-
-* Handle new isolated direction overrides in bidi.
-* Handle type 14 tables for variation selectors, not that anyone is using them yet.
-* Handle fonts with not glyf/loca table (e.g. cff & svg-ttf). bbox is 0,0,0,0
-
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Bidi.cpp b/Build/source/libs/graphite2/graphite2-1.2.3/src/Bidi.cpp
deleted file mode 100644
index c97eeb1738d..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Bidi.cpp
+++ /dev/null
@@ -1,578 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#include "inc/Main.h"
-#include "inc/Slot.h"
-#include "inc/Segment.h"
-
-using namespace graphite2;
-
-enum DirCode { // Hungarian: dirc
- Unk = -1,
- N = 0, // other neutrals (default) - ON
- L = 1, // left-to-right, strong - L
- R = 2, // right-to-left, strong - R
- AL = 3, // Arabic letter, right-to-left, strong, AR
- EN = 4, // European number, left-to-right, weak - EN
- EUS = 5, // European separator, left-to-right, weak - ES
- ET = 6, // European number terminator, left-to-right, weak - ET
- AN = 7, // Arabic number, left-to-right, weak - AN
- CUS = 8, // Common number separator, left-to-right, weak - CS
- WS = 9, // white space, neutral - WS
- BN = 10, // boundary neutral - BN
-
- LRO = 11, // LTR override
- RLO = 12, // RTL override
- LRE = 13, // LTR embedding
- RLE = 14, // RTL embedding
- PDF = 15, // pop directional format
- NSM = 16, // non-space mark
-
- ON = N
-};
-
-enum DirMask {
- Nmask = 1,
- Lmask = 2,
- Rmask = 4,
- ALmask = 8,
- ENmask = 0x10,
- ESmask = 0x20,
- ETmask = 0x40,
- ANmask = 0x80,
- CSmask = 0x100,
- WSmask = 0x200,
- BNmask = 0x400,
- LROmask = 0x800,
- RLOmask = 0x1000,
- LREmask = 0x2000,
- RLEmask = 0x4000,
- PDFmask = 0x8000,
- NSMmask = 0x10000
-};
-
-unsigned int bidi_class_map[] = { 0, 1, 2, 5, 4, 8, 9, 3, 7, 0, 0, 0, 0, 0, 0, 0, 6 };
-// Algorithms based on Unicode reference standard code. Thanks Asmus Freitag.
-#define MAX_LEVEL 61
-
-Slot *resolveExplicit(int level, int dir, Slot *s, int nNest = 0)
-{
- int nLastValid = nNest;
- Slot *res = NULL;
- for ( ; s && !res; s = s->next())
- {
- int cls = s->getBidiClass();
- switch(cls)
- {
- case LRO:
- case LRE:
- nNest++;
- if (level & 1)
- s->setBidiLevel(level + 1);
- else
- s->setBidiLevel(level + 2);
- if (s->getBidiLevel() > MAX_LEVEL)
- s->setBidiLevel(level);
- else
- {
- s = resolveExplicit(s->getBidiLevel(), (cls == LRE ? N : L), s->next(), nNest);
- nNest--;
- if (s) continue; else break;
- }
- cls = BN;
- s->setBidiClass(cls);
- break;
-
- case RLO:
- case RLE:
- nNest++;
- if (level & 1)
- s->setBidiLevel(level + 2);
- else
- s->setBidiLevel(level + 1);
- if (s->getBidiLevel() > MAX_LEVEL)
- s->setBidiLevel(level);
- else
- {
- s = resolveExplicit(s->getBidiLevel(), (cls == RLE ? N : R), s->next(), nNest);
- nNest--;
- if (s) continue; else break;
- }
- cls = BN;
- s->setBidiClass(cls);
- break;
-
- case PDF:
- cls = BN;
- s->setBidiClass(cls);
- if (nNest)
- {
- if (nLastValid < nNest)
- --nNest;
- else
- res = s;
- }
- break;
- }
-
- if (dir != N)
- cls = dir;
- if (s)
- {
- s->setBidiLevel(level);
- if (s->getBidiClass() != BN)
- s->setBidiClass(cls);
- }
- else
- break;
- }
- return res;
-}
-
-// === RESOLVE WEAK TYPES ================================================
-
-enum bidi_state // possible states
-{
- xa, // arabic letter
- xr, // right leter
- xl, // left letter
-
- ao, // arabic lett. foll by ON
- ro, // right lett. foll by ON
- lo, // left lett. foll by ON
-
- rt, // ET following R
- lt, // ET following L
-
- cn, // EN, AN following AL
- ra, // arabic number foll R
- re, // european number foll R
- la, // arabic number foll L
- le, // european number foll L
-
- ac, // CS following cn
- rc, // CS following ra
- rs, // CS,ES following re
- lc, // CS following la
- ls, // CS,ES following le
-
- ret, // ET following re
- let, // ET following le
-} ;
-
-enum bidi_state_mask
-{
- xamask = 1,
- xrmask = 2,
- xlmask = 4,
- aomask = 8,
- romask = 0x10,
- lomask = 0x20,
- rtmask = 0x40,
- ltmask = 0x80,
- cnmask = 0x100,
- ramask = 0x200,
- remask = 0x400,
- lamask = 0x800,
- lemask = 0x1000,
- acmask = 0x2000,
- rcmask = 0x4000,
- rsmask = 0x8000,
- lcmask = 0x10000,
- lsmask = 0x20000,
- retmask = 0x40000,
- letmask = 0x80000
-};
-
-const bidi_state stateWeak[][10] =
-{
- // N, L, R, AN, EN, AL,NSM, CS, ES, ET,
-{ /*xa*/ ao, xl, xr, cn, cn, xa, xa, ao, ao, ao, /* arabic letter */ },
-{ /*xr*/ ro, xl, xr, ra, re, xa, xr, ro, ro, rt, /* right letter */ },
-{ /*xl*/ lo, xl, xr, la, le, xa, xl, lo, lo, lt, /* left letter */ },
-
-{ /*ao*/ ao, xl, xr, cn, cn, xa, ao, ao, ao, ao, /* arabic lett. foll by ON*/ },
-{ /*ro*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* right lett. foll by ON */ },
-{ /*lo*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* left lett. foll by ON */ },
-
-{ /*rt*/ ro, xl, xr, ra, re, xa, rt, ro, ro, rt, /* ET following R */ },
-{ /*lt*/ lo, xl, xr, la, le, xa, lt, lo, lo, lt, /* ET following L */ },
-
-{ /*cn*/ ao, xl, xr, cn, cn, xa, cn, ac, ao, ao, /* EN, AN following AL */ },
-{ /*ra*/ ro, xl, xr, ra, re, xa, ra, rc, ro, rt, /* arabic number foll R */ },
-{ /*re*/ ro, xl, xr, ra, re, xa, re, rs, rs,ret, /* european number foll R */ },
-{ /*la*/ lo, xl, xr, la, le, xa, la, lc, lo, lt, /* arabic number foll L */ },
-{ /*le*/ lo, xl, xr, la, le, xa, le, ls, ls,let, /* european number foll L */ },
-
-{ /*ac*/ ao, xl, xr, cn, cn, xa, ao, ao, ao, ao, /* CS following cn */ },
-{ /*rc*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* CS following ra */ },
-{ /*rs*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* CS,ES following re */ },
-{ /*lc*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* CS following la */ },
-{ /*ls*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* CS,ES following le */ },
-
-{ /*ret*/ ro, xl, xr, ra, re, xa,ret, ro, ro,ret, /* ET following re */ },
-{ /*let*/ lo, xl, xr, la, le, xa,let, lo, lo,let, /* ET following le */ },
-
-
-};
-
-enum bidi_action // possible actions
-{
- // primitives
- IX = 0x100, // increment
- XX = 0xF, // no-op
-
- // actions
- xxx = (XX << 4) + XX, // no-op
- xIx = IX + xxx, // increment run
- xxN = (XX << 4) + ON, // set current to N
- xxE = (XX << 4) + EN, // set current to EN
- xxA = (XX << 4) + AN, // set current to AN
- xxR = (XX << 4) + R, // set current to R
- xxL = (XX << 4) + L, // set current to L
- Nxx = (ON << 4) + 0xF, // set run to neutral
- Axx = (AN << 4) + 0xF, // set run to AN
- ExE = (EN << 4) + EN, // set run to EN, set current to EN
- NIx = (ON << 4) + 0xF + IX, // set run to N, increment
- NxN = (ON << 4) + ON, // set run to N, set current to N
- NxR = (ON << 4) + R, // set run to N, set current to R
- NxE = (ON << 4) + EN, // set run to N, set current to EN
-
- AxA = (AN << 4) + AN, // set run to AN, set current to AN
- NxL = (ON << 4) + L, // set run to N, set current to L
- LxL = (L << 4) + L, // set run to L, set current to L
-};
-
-
-const bidi_action actionWeak[][10] =
-{
- // N,.. L, R, AN, EN, AL, NSM, CS,..ES, ET,
-{ /*xa*/ xxx, xxx, xxx, xxx, xxA, xxR, xxR, xxN, xxN, xxN, /* arabic letter */ },
-{ /*xr*/ xxx, xxx, xxx, xxx, xxE, xxR, xxR, xxN, xxN, xIx, /* right leter */ },
-{ /*xl*/ xxx, xxx, xxx, xxx, xxL, xxR, xxL, xxN, xxN, xIx, /* left letter */ },
-
-{ /*ao*/ xxx, xxx, xxx, xxx, xxA, xxR, xxN, xxN, xxN, xxN, /* arabic lett. foll by ON */ },
-{ /*ro*/ xxx, xxx, xxx, xxx, xxE, xxR, xxN, xxN, xxN, xIx, /* right lett. foll by ON */ },
-{ /*lo*/ xxx, xxx, xxx, xxx, xxL, xxR, xxN, xxN, xxN, xIx, /* left lett. foll by ON */ },
-
-{ /*rt*/ Nxx, Nxx, Nxx, Nxx, ExE, NxR, xIx, NxN, NxN, xIx, /* ET following R */ },
-{ /*lt*/ Nxx, Nxx, Nxx, Nxx, LxL, NxR, xIx, NxN, NxN, xIx, /* ET following L */ },
-
-{ /*cn*/ xxx, xxx, xxx, xxx, xxA, xxR, xxA, xIx, xxN, xxN, /* EN, AN following AL */ },
-{ /*ra*/ xxx, xxx, xxx, xxx, xxE, xxR, xxA, xIx, xxN, xIx, /* arabic number foll R */ },
-{ /*re*/ xxx, xxx, xxx, xxx, xxE, xxR, xxE, xIx, xIx, xxE, /* european number foll R */ },
-{ /*la*/ xxx, xxx, xxx, xxx, xxL, xxR, xxA, xIx, xxN, xIx, /* arabic number foll L */ },
-{ /*le*/ xxx, xxx, xxx, xxx, xxL, xxR, xxL, xIx, xIx, xxL, /* european number foll L */ },
-
-{ /*ac*/ Nxx, Nxx, Nxx, Axx, AxA, NxR, NxN, NxN, NxN, NxN, /* CS following cn */ },
-{ /*rc*/ Nxx, Nxx, Nxx, Axx, NxE, NxR, NxN, NxN, NxN, NIx, /* CS following ra */ },
-{ /*rs*/ Nxx, Nxx, Nxx, Nxx, ExE, NxR, NxN, NxN, NxN, NIx, /* CS,ES following re */ },
-{ /*lc*/ Nxx, Nxx, Nxx, Axx, NxL, NxR, NxN, NxN, NxN, NIx, /* CS following la */ },
-{ /*ls*/ Nxx, Nxx, Nxx, Nxx, LxL, NxR, NxN, NxN, NxN, NIx, /* CS,ES following le */ },
-
-{ /*ret*/xxx, xxx, xxx, xxx, xxE, xxR, xxE, xxN, xxN, xxE, /* ET following re */ },
-{ /*let*/xxx, xxx, xxx, xxx, xxL, xxR, xxL, xxN, xxN, xxL, /* ET following le */ },
-};
-
-inline uint8 GetDeferredType(bidi_action a) { return (a >> 4) & 0xF; }
-inline uint8 GetResolvedType(bidi_action a) { return a & 0xF; }
-inline DirCode EmbeddingDirection(int l) { return l & 1 ? R : L; }
-inline bool IsDeferredState(bidi_state a) { return 0 != ((1 << a) & (rtmask | ltmask | acmask | rcmask | rsmask | lcmask | lsmask)); }
-inline bool IsModifiedClass(DirCode a) { return 0 != ((1 << a) & (ALmask | NSMmask | ESmask | CSmask | ETmask | ENmask)); }
-
-void SetDeferredRunClass(Slot *s, Slot *sRun, int nval)
-{
- if (!sRun || s == sRun) return;
- for (Slot *p = s->prev(); p != sRun; p = p->prev())
- p->setBidiClass(nval);
-}
-
-void resolveWeak(int baseLevel, Slot *s)
-{
- int state = (baseLevel & 1) ? xr : xl;
- int cls;
- int level = baseLevel;
- Slot *sRun = NULL;
- Slot *sLast = s;
-
- for ( ; s; s = s->next())
- {
- sLast = s;
- cls = s->getBidiClass();
- if (cls == BN)
- {
- s->setBidiLevel(level);
- if (!s->next() && level != baseLevel)
- s->setBidiClass(EmbeddingDirection(level));
- else if (s->next() && level != s->next()->getBidiLevel() && s->next()->getBidiClass() != BN)
- {
- int newLevel = s->next()->getBidiLevel();
- if (level > newLevel)
- newLevel = level;
- s->setBidiLevel(newLevel);
- s->setBidiClass(EmbeddingDirection(newLevel));
- level = s->next()->getBidiLevel();
- }
- else
- continue;
- }
-
- bidi_action action = actionWeak[state][bidi_class_map[cls]];
- int clsRun = GetDeferredType(action);
- if (clsRun != XX)
- {
- SetDeferredRunClass(s, sRun, clsRun);
- sRun = NULL;
- }
- int clsNew = GetResolvedType(action);
- if (clsNew != XX)
- s->setBidiClass(clsNew);
- if (!sRun && (IX & action))
- sRun = s->prev();
- state = stateWeak[state][bidi_class_map[cls]];
- }
-
- cls = EmbeddingDirection(level);
- int clsRun = GetDeferredType(actionWeak[state][bidi_class_map[cls]]);
- if (clsRun != XX)
- SetDeferredRunClass(sLast, sRun, clsRun);
-}
-
-// Neutrals
-enum neutral_action
-{
- // action to resolve previous input
- nL = L, // resolve EN to L
- En = 3 << 4, // resolve neutrals run to embedding level direction
- Rn = R << 4, // resolve neutrals run to strong right
- Ln = L << 4, // resolved neutrals run to strong left
- In = (1<<8), // increment count of deferred neutrals
- LnL = (1<<4)+L, // set run and EN to L
-};
-
-int GetDeferredNeutrals(int action, int level)
-{
- action = (action >> 4) & 0xF;
- if (action == (En >> 4))
- return EmbeddingDirection(level);
- else
- return action;
-}
-
-int GetResolvedNeutrals(int action)
-{
- action = action & 0xF;
- if (action == In)
- return 0;
- else
- return action;
-}
-
-// state values
-enum neutral_state
-{
- // new temporary class
- r, // R and characters resolved to R
- l, // L and characters resolved to L
- rn, // N preceded by right
- ln, // N preceded by left
- a, // AN preceded by left (the abbrev 'la' is used up above)
- na, // N preceeded by a
-} ;
-
-const uint8 neutral_class_map[] = { 0, 1, 2, 0, 4, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-const int actionNeutrals[][5] =
-{
-// N, L, R, AN, EN, = cls
- // state =
-{ In, 0, 0, 0, 0, }, // r right
-{ In, 0, 0, 0, L, }, // l left
-
-{ In, En, Rn, Rn, Rn, }, // rn N preceded by right
-{ In, Ln, En, En, LnL, }, // ln N preceded by left
-
-{ In, 0, 0, 0, L, }, // a AN preceded by left
-{ In, En, Rn, Rn, En, }, // na N preceded by a
-} ;
-
-const int stateNeutrals[][5] =
-{
-// N, L, R, AN, EN = cls
- // state =
-{ rn, l, r, r, r, }, // r right
-{ ln, l, r, a, l, }, // l left
-
-{ rn, l, r, r, r, }, // rn N preceded by right
-{ ln, l, r, a, l, }, // ln N preceded by left
-
-{ na, l, r, a, l, }, // a AN preceded by left
-{ na, l, r, a, l, }, // na N preceded by la
-} ;
-
-void resolveNeutrals(int baseLevel, Slot *s)
-{
- int state = baseLevel ? r : l;
- int cls;
- Slot *sRun = NULL;
- Slot *sLast = s;
- int level = baseLevel;
-
- for ( ; s; s = s->next())
- {
- sLast = s;
- cls = s->getBidiClass();
- if (cls == BN)
- {
- if (sRun)
- sRun = sRun->prev();
- continue;
- }
-
- int action = actionNeutrals[state][neutral_class_map[cls]];
- int clsRun = GetDeferredNeutrals(action, level);
- if (clsRun != N)
- {
- SetDeferredRunClass(s, sRun, clsRun);
- sRun = NULL;
- }
- int clsNew = GetResolvedNeutrals(action);
- if (clsNew != N)
- s->setBidiClass(clsNew);
- if (!sRun && (action & In))
- sRun = s->prev();
- state = stateNeutrals[state][neutral_class_map[cls]];
- level = s->getBidiLevel();
- }
- cls = EmbeddingDirection(level);
- int clsRun = GetDeferredNeutrals(actionNeutrals[state][neutral_class_map[cls]], level);
- if (clsRun != N)
- SetDeferredRunClass(sLast, sRun, clsRun);
-}
-
-const int addLevel[][4] =
-{
- // L, R, AN, EN = cls
- // level =
-/* even */ { 0, 1, 2, 2, }, // EVEN
-/* odd */ { 1, 0, 1, 1, }, // ODD
-
-};
-
-void resolveImplicit(Slot *s, Segment *seg, uint8 aMirror)
-{
- bool rtl = seg->dir() & 1;
- for ( ; s; s = s->next())
- {
- int cls = s->getBidiClass();
- if (cls == BN)
- continue;
- else if (cls == AN)
- cls = AL;
- if (cls < 5 && cls > 0)
- {
- int level = s->getBidiLevel();
- level += addLevel[level & 1][cls - 1];
- s->setBidiLevel(level);
- if (aMirror)
- {
- int hasChar = seg->glyphAttr(s->gid(), aMirror + 1);
- if ( ((level & 1) && (!(seg->dir() & 4) || !hasChar))
- || ((rtl ^ (level & 1)) && (seg->dir() & 4) && hasChar) )
- {
- unsigned short g = seg->glyphAttr(s->gid(), aMirror);
- if (g) s->setGlyph(seg, g);
- }
- }
- }
- }
-}
-
-void resolveWhitespace(int baseLevel, Segment *seg, uint8 aBidi, Slot *s)
-{
- for ( ; s; s = s->prev())
- {
- int cls = seg->glyphAttr(s->gid(), aBidi);
- if (cls == WS)
- s->setBidiLevel(baseLevel);
- else
- break;
- }
-}
-
-
-inline
-Slot * join(int level, Slot * a, Slot * b)
-{
- if (!a) return b;
- if (level & 1) { Slot * const t = a; a = b; b = t; }
- Slot * const t = b->prev();
- a->prev()->next(b); b->prev(a->prev()); // splice middle
- t->next(a); a->prev(t); // splice ends
- return a;
-}
-
-
-Slot * span(Slot * & cs, const bool rtl)
-{
- Slot * r = cs, * re = cs; cs = cs->next();
- if (rtl)
- {
- Slot * t = r->next(); r->next(r->prev()); r->prev(t);
- for (int l = r->getBidiLevel(); cs && l == cs->getBidiLevel(); cs = cs->prev())
- {
- re = cs;
- t = cs->next(); cs->next(cs->prev()); cs->prev(t);
- }
- r->next(re);
- re->prev(r);
- r = re;
- }
- else
- {
- for (int l = r->getBidiLevel(); cs && l == cs->getBidiLevel(); cs = cs->next())
- re = cs;
- r->prev(re);
- re->next(r);
- }
- if (cs) cs->prev(0);
- return r;
-}
-
-
-Slot *resolveOrder(Slot * & cs, const bool reordered, const int level)
-{
- Slot * r = 0;
- int ls;
- while (cs && level <= (ls = cs->getBidiLevel() - reordered))
- {
- r = join(level, r, level >= ls
- ? span(cs, level & 1)
- : resolveOrder(cs, reordered, level+1));
- }
- return r;
-}
-
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Silf.cpp b/Build/source/libs/graphite2/graphite2-1.2.3/src/Silf.cpp
deleted file mode 100644
index 74b8003611c..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Silf.cpp
+++ /dev/null
@@ -1,387 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#include <cstdlib>
-#include "graphite2/Segment.h"
-#include "inc/debug.h"
-#include "inc/Endian.h"
-#include "inc/Silf.h"
-#include "inc/Segment.h"
-#include "inc/Rule.h"
-
-
-using namespace graphite2;
-
-namespace { static const uint32 ERROROFFSET = 0xFFFFFFFF; }
-
-Silf::Silf() throw()
-: m_passes(0),
- m_pseudos(0),
- m_classOffsets(0),
- m_classData(0),
- m_justs(0),
- m_numPasses(0),
- m_numJusts(0),
- m_sPass(0),
- m_pPass(0),
- m_jPass(0),
- m_bPass(0),
- m_flags(0),
- m_aPseudo(0),
- m_aBreak(0),
- m_aUser(0),
- m_aBidi(0),
- m_aMirror(0),
- m_aPassBits(0),
- m_iMaxComp(0),
- m_aLig(0),
- m_numPseudo(0),
- m_nClass(0),
- m_nLinear(0),
- m_gEndLine(0)
-{
- memset(&m_silfinfo, 0, sizeof m_silfinfo);
-}
-
-Silf::~Silf() throw()
-{
- releaseBuffers();
-}
-
-void Silf::releaseBuffers() throw()
-{
- delete [] m_passes;
- delete [] m_pseudos;
- free(m_classOffsets);
- free(m_classData);
- free(m_justs);
- m_passes= 0;
- m_pseudos = 0;
- m_classOffsets = 0;
- m_classData = 0;
- m_justs = 0;
-}
-
-
-bool Silf::readGraphite(const byte * const silf_start, size_t lSilf, const Face& face, uint32 version)
-{
- const byte * p = silf_start,
- * const silf_end = p + lSilf;
-
- if (version >= 0x00030000)
- {
- if (lSilf < 28) { releaseBuffers(); return false; }
- be::skip<int32>(p); // ruleVersion
- be::skip<uint16>(p,2); // passOffset & pseudosOffset
- }
- else if (lSilf < 20) { releaseBuffers(); return false; }
- const uint16 maxGlyph = be::read<uint16>(p);
- m_silfinfo.extra_ascent = be::read<uint16>(p);
- m_silfinfo.extra_descent = be::read<uint16>(p);
- m_numPasses = be::read<uint8>(p);
- m_sPass = be::read<uint8>(p);
- m_pPass = be::read<uint8>(p);
- m_jPass = be::read<uint8>(p);
- m_bPass = be::read<uint8>(p);
- m_flags = be::read<uint8>(p);
- be::skip<uint8>(p,2); // max{Pre,Post}Context.
- m_aPseudo = be::read<uint8>(p);
- m_aBreak = be::read<uint8>(p);
- m_aBidi = be::read<uint8>(p);
- m_aMirror = be::read<uint8>(p);
- m_aPassBits = be::read<uint8>(p);
-
- // Read Justification levels.
- m_numJusts = be::read<uint8>(p);
- if (maxGlyph >= face.glyphs().numGlyphs()
- || p + m_numJusts * 8 >= silf_end) { releaseBuffers(); return false; }
- m_justs = gralloc<Justinfo>(m_numJusts);
- for (uint8 i = 0; i < m_numJusts; i++)
- {
- ::new(m_justs + i) Justinfo(p[0], p[1], p[2], p[3]);
- be::skip<byte>(p,8);
- }
-
- if (p + sizeof(uint16) + sizeof(uint8)*8 >= silf_end) { releaseBuffers(); return false; }
- m_aLig = be::read<uint16>(p);
- m_aUser = be::read<uint8>(p);
- m_iMaxComp = be::read<uint8>(p);
- be::skip<byte>(p,5); // direction and 4 reserved bytes
- be::skip<uint16>(p, be::read<uint8>(p)); // don't need critical features yet
- be::skip<byte>(p); // reserved
- if (p >= silf_end) { releaseBuffers(); return false; }
- be::skip<uint32>(p, be::read<uint8>(p)); // don't use scriptTag array.
- if (p + sizeof(uint16) + sizeof(uint32) >= silf_end) { releaseBuffers(); return false; }
- m_gEndLine = be::read<uint16>(p); // lbGID
- const byte * o_passes = p,
- * const passes_start = silf_start + be::read<uint32>(p);
-
- const size_t num_attrs = face.glyphs().numAttrs();
- if (m_aPseudo >= num_attrs
- || m_aBreak >= num_attrs
- || m_aBidi >= num_attrs
- || m_aMirror>= num_attrs
- || m_numPasses > 128 || passes_start >= silf_end
- || m_pPass < m_sPass || m_pPass > m_numPasses || m_sPass > m_numPasses
- || m_jPass < m_pPass || m_jPass > m_numPasses
- || (m_bPass != 0xFF && (m_bPass < m_jPass || m_bPass > m_numPasses))
- || m_aLig > 127) { releaseBuffers(); return false; }
- be::skip<uint32>(p, m_numPasses);
- if (p + sizeof(uint16) >= passes_start) { releaseBuffers(); return false; }
- m_numPseudo = be::read<uint16>(p);
- be::skip<uint16>(p, 3); // searchPseudo, pseudoSelector, pseudoShift
- if (p + m_numPseudo*(sizeof(uint32) + sizeof(uint16)) >= passes_start) {
- releaseBuffers(); return false;
- }
- m_pseudos = new Pseudo[m_numPseudo];
- for (int i = 0; i < m_numPseudo; i++)
- {
- m_pseudos[i].uid = be::read<uint32>(p);
- m_pseudos[i].gid = be::read<uint16>(p);
- }
-
- const size_t clen = readClassMap(p, passes_start - p, version);
- if (clen == ERROROFFSET || p + clen > passes_start) { releaseBuffers(); return false; }
-
- m_passes = new Pass[m_numPasses];
- for (size_t i = 0; i < m_numPasses; ++i)
- {
- const byte * const pass_start = silf_start + be::read<uint32>(o_passes),
- * const pass_end = silf_start + be::peek<uint32>(o_passes);
- if (pass_start > pass_end || pass_end > silf_end) {
- releaseBuffers(); return false;
- }
-
- m_passes[i].init(this);
- if (!m_passes[i].readPass(pass_start, pass_end - pass_start, pass_start - silf_start, face))
- {
- releaseBuffers();
- return false;
- }
- }
-
- // fill in gr_faceinfo
- m_silfinfo.upem = face.glyphs().unitsPerEm();
- m_silfinfo.has_bidi_pass = (m_bPass != 0xFF);
- m_silfinfo.justifies = (m_numJusts != 0) || (m_jPass < m_pPass);
- m_silfinfo.line_ends = (m_flags & 1);
- m_silfinfo.space_contextuals = gr_faceinfo::gr_space_contextuals((m_flags >> 2) & 0x7);
- return true;
-}
-
-template<typename T> inline uint32 Silf::readClassOffsets(const byte *&p, size_t data_len)
-{
- const T cls_off = 2*sizeof(uint16) + sizeof(T)*(m_nClass+1);
- const size_t max_off = (be::peek<T>(p + sizeof(T)*m_nClass) - cls_off)/sizeof(uint16);
- // Check that the last+1 offset is less than or equal to the class map length.
- if (be::peek<T>(p) != cls_off || max_off > (data_len - cls_off)/sizeof(uint16))
- return ERROROFFSET;
-
- // Read in all the offsets.
- m_classOffsets = gralloc<uint32>(m_nClass+1);
- for (uint32 * o = m_classOffsets, * const o_end = o + m_nClass + 1; o != o_end; ++o)
- {
- *o = (be::read<T>(p) - cls_off)/sizeof(uint16);
- if (*o > max_off)
- return ERROROFFSET;
- }
- return max_off;
-}
-
-size_t Silf::readClassMap(const byte *p, size_t data_len, uint32 version)
-{
- if (data_len < sizeof(uint16)*2) return ERROROFFSET;
-
- m_nClass = be::read<uint16>(p);
- m_nLinear = be::read<uint16>(p);
-
- // Check that numLinear < numClass,
- // that there is at least enough data for numClasses offsets.
- if (m_nLinear > m_nClass
- || (m_nClass + 1) * (version >= 0x00040000 ? sizeof(uint32) : sizeof(uint16))> (data_len - 4))
- return ERROROFFSET;
-
-
- uint32 max_off;
- if (version >= 0x00040000)
- max_off = readClassOffsets<uint32>(p, data_len);
- else
- max_off = readClassOffsets<uint16>(p, data_len);
-
- if (max_off == ERROROFFSET) return ERROROFFSET;
-
- // Check the linear offsets are sane, these must be monotonically increasing.
- for (const uint32 *o = m_classOffsets, * const o_end = o + m_nLinear; o != o_end; ++o)
- if (o[0] > o[1])
- return ERROROFFSET;
-
- // Fortunately the class data is all uint16s so we can decode these now
- m_classData = gralloc<uint16>(max_off);
- for (uint16 *d = m_classData, * const d_end = d + max_off; d != d_end; ++d)
- *d = be::read<uint16>(p);
-
- // Check the lookup class invariants for each non-linear class
- for (const uint32 *o = m_classOffsets + m_nLinear, * const o_end = m_classOffsets + m_nClass; o != o_end; ++o)
- {
- const uint16 * lookup = m_classData + *o;
- if (*o > max_off - 4 // LookupClass doesn't stretch over max_off
- || lookup[0] == 0 // A LookupClass with no looks is a suspicious thing ...
- || lookup[0] > (max_off - *o - 4)/2 // numIDs lookup pairs fits within (start of LookupClass' lookups array, max_off]
- || lookup[3] != lookup[0] - lookup[1]) // rangeShift: numIDs - searchRange
- return ERROROFFSET;
- }
-
- return max_off;
-}
-
-uint16 Silf::findPseudo(uint32 uid) const
-{
- for (int i = 0; i < m_numPseudo; i++)
- if (m_pseudos[i].uid == uid) return m_pseudos[i].gid;
- return 0;
-}
-
-uint16 Silf::findClassIndex(uint16 cid, uint16 gid) const
-{
- if (cid > m_nClass) return -1;
-
- const uint16 * cls = m_classData + m_classOffsets[cid];
- if (cid < m_nLinear) // output class being used for input, shouldn't happen
- {
- for (unsigned int i = 0, n = m_classOffsets[cid + 1]; i < n; ++i, ++cls)
- if (*cls == gid) return i;
- return -1;
- }
- else
- {
- const uint16 * min = cls + 4, // lookups array
- * max = min + cls[0]*2; // lookups aray is numIDs (cls[0]) uint16 pairs long
- do
- {
- const uint16 * p = min + (-2 & ((max-min)/2));
- if (p[0] > gid) max = p;
- else min = p;
- }
- while (max - min > 2);
- return min[0] == gid ? min[1] : -1;
- }
-}
-
-uint16 Silf::getClassGlyph(uint16 cid, unsigned int index) const
-{
- if (cid > m_nClass) return 0;
-
- uint32 loc = m_classOffsets[cid];
- if (cid < m_nLinear)
- {
- if (index < m_classOffsets[cid + 1] - loc)
- return m_classData[index + loc];
- }
- else // input class being used for output. Shouldn't happen
- {
- for (unsigned int i = loc + 4; i < m_classOffsets[cid + 1]; i += 2)
- if (m_classData[i + 1] == index) return m_classData[i];
- }
- return 0;
-}
-
-
-bool Silf::runGraphite(Segment *seg, uint8 firstPass, uint8 lastPass) const
-{
- assert(seg != 0);
- SlotMap map(*seg);
- FiniteStateMachine fsm(map, seg->getFace()->logger());
- vm::Machine m(map);
- unsigned int initSize = seg->slotCount();
-#if !defined GRAPHITE2_NTRACING
- json * const dbgout = seg->getFace()->logger();
-#endif
-
- if (lastPass == 0)
- {
- if (firstPass == lastPass)
- return true;
- lastPass = m_numPasses;
- }
-
- for (size_t i = firstPass; i < lastPass; ++i)
- {
- // bidi and mirroring
- if (i == m_bPass)
- {
-#if !defined GRAPHITE2_NTRACING
- if (dbgout)
- {
- *dbgout << json::item << json::object
- << "id" << -1
- << "slots" << json::array;
- seg->positionSlots(0);
- for(Slot * s = seg->first(); s; s = s->next())
- *dbgout << dslot(seg, s);
- *dbgout << json::close
- << "rules" << json::array << json::close
- << json::close;
- }
-#endif
-
- if (!(seg->dir() & 2))
- seg->bidiPass(m_aBidi, seg->dir() & 1, m_aMirror);
- else if (m_aMirror)
- {
- Slot * s;
- for (s = seg->first(); s; s = s->next())
- {
- unsigned short g = seg->glyphAttr(s->gid(), m_aMirror);
- if (g && (!(seg->dir() & 4) || !seg->glyphAttr(s->gid(), m_aMirror + 1)))
- s->setGlyph(seg, g);
- }
- }
- }
-
-#if !defined GRAPHITE2_NTRACING
- if (dbgout)
- {
- *dbgout << json::item << json::object
- << "id" << i+1
- << "slots" << json::array;
- seg->positionSlots(0);
- for(Slot * s = seg->first(); s; s = s->next())
- *dbgout << dslot(seg, s);
- *dbgout << json::close;
- }
-#endif
-
- // test whether to reorder, prepare for positioning
- if (i >= 32 || (seg->passBits() & (1 << i)) == 0)
- m_passes[i].runGraphite(m, fsm);
- // only subsitution passes can change segment length, cached subsegments are short for their text
- if (m.status() != vm::Machine::finished
- || (i < m_pPass && (seg->slotCount() > initSize * MAX_SEG_GROWTH_FACTOR
- || (seg->slotCount() && seg->slotCount() * MAX_SEG_GROWTH_FACTOR < initSize))))
- return false;
- }
- return true;
-}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/TtfUtil.cpp b/Build/source/libs/graphite2/graphite2-1.2.3/src/TtfUtil.cpp
deleted file mode 100644
index ba26946dcc1..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/TtfUtil.cpp
+++ /dev/null
@@ -1,1980 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-/*--------------------------------------------------------------------*//*:Ignore this sentence.
-
-File: TtfUtil.cpp
-Responsibility: Alan Ward
-Last reviewed: Not yet.
-
-Description
- Implements the methods for TtfUtil class. This file should remain portable to any C++
- environment by only using standard C++ and the TTF structurs defined in Tt.h.
--------------------------------------------------------------------------------*//*:End Ignore*/
-
-
-/***********************************************************************************************
- Include files
-***********************************************************************************************/
-// Language headers
-//#include <algorithm>
-#include <cassert>
-#include <cstddef>
-#include <cstring>
-#include <climits>
-#include <cwchar>
-//#include <stdexcept>
-// Platform headers
-// Module headers
-#include "inc/TtfUtil.h"
-#include "inc/TtfTypes.h"
-#include "inc/Endian.h"
-
-/***********************************************************************************************
- Forward declarations
-***********************************************************************************************/
-
-/***********************************************************************************************
- Local Constants and static variables
-***********************************************************************************************/
-namespace
-{
- // max number of components allowed in composite glyphs
- const int kMaxGlyphComponents = 8;
-
- template <int R, typename T>
- inline float fixed_to_float(const T f) {
- return float(f)/float(2^R);
- }
-
-/*----------------------------------------------------------------------------------------------
- Table of standard Postscript glyph names. From Martin Hosken. Disagress with ttfdump.exe
----------------------------------------------------------------------------------------------*/
-#ifdef ALL_TTFUTILS
- const int kcPostNames = 258;
-
- const char * rgPostName[kcPostNames] = {
- ".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign",
- "dollar", "percent", "ampersand", "quotesingle", "parenleft",
- "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
- "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
- "nine", "colon", "semicolon", "less", "equal", "greater", "question",
- "at", "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",
- "bracketleft", "backslash", "bracketright", "asciicircum",
- "underscore", "grave", "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", "braceleft", "bar", "braceright", "asciitilde",
- "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis",
- "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde",
- "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis",
- "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute",
- "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave",
- "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling",
- "section", "bullet", "paragraph", "germandbls", "registered",
- "copyright", "trademark", "acute", "dieresis", "notequal", "AE",
- "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen",
- "mu", "partialdiff", "summation", "product", "pi", "integral",
- "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown",
- "exclamdown", "logicalnot", "radical", "florin", "approxequal",
- "Delta", "guillemotleft", "guillemotright", "ellipsis", "nonbreakingspace",
- "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash",
- "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide",
- "lozenge", "ydieresis", "Ydieresis", "fraction", "currency",
- "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered",
- "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
- "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute",
- "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
- "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi",
- "circumflex", "tilde", "macron", "breve", "dotaccent", "ring",
- "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash",
- "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth",
- "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply",
- "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter",
- "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla",
- "scedilla", "Cacute", "cacute", "Ccaron", "ccaron",
- "dcroat" };
-#endif
-
-} // end of namespace
-
-/***********************************************************************************************
- Methods
-***********************************************************************************************/
-
-/* Note on error processing: The code guards against bad glyph ids being used to look up data
-in open ended tables (loca, hmtx). If the glyph id comes from a cmap this shouldn't happen
-but it seems prudent to check for user errors here. The code does assume that data obtained
-from the TTF file is valid otherwise (though the CheckTable method seeks to check for
-obvious problems that might accompany a change in table versions). For example an invalid
-offset in the loca table which could exceed the size of the glyf table is NOT trapped.
-Likewise if numberOf_LongHorMetrics in the hhea table is wrong, this will NOT be trapped,
-which could cause a lookup in the hmtx table to exceed the table length. Of course, TTF tables
-that are completely corrupt will cause unpredictable results. */
-
-/* Note on composite glyphs: Glyphs that have components that are themselves composites
-are not supported. IsDeepComposite can be used to test for this. False is returned from many
-of the methods in this cases. It is unclear how to build composite glyphs in some cases,
-so this code represents my best guess until test cases can be found. See notes on the high-
-level GlyfPoints method. */
-namespace graphite2
-{
-namespace TtfUtil
-{
-
-
-/*----------------------------------------------------------------------------------------------
- Get offset and size of the offset table needed to find table directory.
- Return true if success, false otherwise.
- lSize excludes any table directory entries.
-----------------------------------------------------------------------------------------------*/
-bool GetHeaderInfo(size_t & lOffset, size_t & lSize)
-{
- lOffset = 0;
- lSize = offsetof(Sfnt::OffsetSubTable, table_directory);
- assert(sizeof(uint32) + 4*sizeof (uint16) == lSize);
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Check the offset table for expected data.
- Return true if success, false otherwise.
-----------------------------------------------------------------------------------------------*/
-bool CheckHeader(const void * pHdr)
-{
- const Sfnt::OffsetSubTable * pOffsetTable
- = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
-
- return pHdr && be::swap(pOffsetTable->scaler_type) == Sfnt::OffsetSubTable::TrueTypeWin;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get offset and size of the table directory.
- Return true if successful, false otherwise.
-----------------------------------------------------------------------------------------------*/
-bool GetTableDirInfo(const void * pHdr, size_t & lOffset, size_t & lSize)
-{
- const Sfnt::OffsetSubTable * pOffsetTable
- = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
-
- lOffset = offsetof(Sfnt::OffsetSubTable, table_directory);
- lSize = be::swap(pOffsetTable->num_tables)
- * sizeof(Sfnt::OffsetSubTable::Entry);
-
- return true;
-}
-
-
-/*----------------------------------------------------------------------------------------------
- Get offset and size of the specified table.
- Return true if successful, false otherwise. On false, offset and size will be 0.
-----------------------------------------------------------------------------------------------*/
-bool GetTableInfo(const Tag TableTag, const void * pHdr, const void * pTableDir,
- size_t & lOffset, size_t & lSize)
-{
- const Sfnt::OffsetSubTable * pOffsetTable
- = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
- const size_t num_tables = be::swap(pOffsetTable->num_tables);
- const Sfnt::OffsetSubTable::Entry
- * entry_itr = reinterpret_cast<const Sfnt::OffsetSubTable::Entry *>(
- pTableDir),
- * const dir_end = entry_itr + num_tables;
-
- if (num_tables > 40)
- return false;
-
- for (;entry_itr != dir_end; ++entry_itr) // 40 - safe guard
- {
- if (be::swap(entry_itr->tag) == TableTag)
- {
- lOffset = be::swap(entry_itr->offset);
- lSize = be::swap(entry_itr->length);
- return true;
- }
- }
-
- return false;
-}
-
-/*----------------------------------------------------------------------------------------------
- Check the specified table. Tests depend on the table type.
- Return true if successful, false otherwise.
-----------------------------------------------------------------------------------------------*/
-bool CheckTable(const Tag TableId, const void * pTable, size_t lTableSize)
-{
- using namespace Sfnt;
-
- if (pTable == 0) return false;
-
- switch(TableId)
- {
- case Tag::cmap: // cmap
- {
- const Sfnt::CharacterCodeMap * const pCmap
- = reinterpret_cast<const Sfnt::CharacterCodeMap *>(pTable);
- return be::swap(pCmap->version) == 0;
- }
-
- case Tag::head: // head
- {
- const Sfnt::FontHeader * const pHead
- = reinterpret_cast<const Sfnt::FontHeader *>(pTable);
- bool r = be::swap(pHead->version) == OneFix
- && be::swap(pHead->magic_number) == FontHeader::MagicNumber
- && be::swap(pHead->glyph_data_format)
- == FontHeader::GlypDataFormat
- && (be::swap(pHead->index_to_loc_format)
- == FontHeader::ShortIndexLocFormat
- || be::swap(pHead->index_to_loc_format)
- == FontHeader::LongIndexLocFormat)
- && sizeof(FontHeader) <= lTableSize;
- return r;
- }
-
- case Tag::post: // post
- {
- const Sfnt::PostScriptGlyphName * const pPost
- = reinterpret_cast<const Sfnt::PostScriptGlyphName *>(pTable);
- const fixed format = be::swap(pPost->format);
- bool r = format == PostScriptGlyphName::Format1
- || format == PostScriptGlyphName::Format2
- || format == PostScriptGlyphName::Format3
- || format == PostScriptGlyphName::Format25;
- return r;
- }
-
- case Tag::hhea: // hhea
- {
- const Sfnt::HorizontalHeader * pHhea =
- reinterpret_cast<const Sfnt::HorizontalHeader *>(pTable);
- bool r = be::swap(pHhea->version) == OneFix
- && be::swap(pHhea->metric_data_format) == 0
- && sizeof (Sfnt::HorizontalHeader) <= lTableSize;
- return r;
- }
-
- case Tag::maxp: // maxp
- {
- const Sfnt::MaximumProfile * pMaxp =
- reinterpret_cast<const Sfnt::MaximumProfile *>(pTable);
- bool r = be::swap(pMaxp->version) == OneFix
- && sizeof(Sfnt::MaximumProfile) <= lTableSize;
- return r;
- }
-
- case Tag::OS_2: // OS/2
- {
- const Sfnt::Compatibility * pOs2
- = reinterpret_cast<const Sfnt::Compatibility *>(pTable);
- if (be::swap(pOs2->version) == 0)
- { // OS/2 table version 1 size
-// if (sizeof(Sfnt::Compatibility)
-// - sizeof(uint32)*2 - sizeof(int16)*2
-// - sizeof(uint16)*3 <= lTableSize)
- if (sizeof(Sfnt::Compatibility0) <= lTableSize)
- return true;
- }
- else if (be::swap(pOs2->version) == 1)
- { // OS/2 table version 2 size
-// if (sizeof(Sfnt::Compatibility)
-// - sizeof(int16) *2
-// - sizeof(uint16)*3 <= lTableSize)
- if (sizeof(Sfnt::Compatibility1) <= lTableSize)
- return true;
- }
- else if (be::swap(pOs2->version) == 2)
- { // OS/2 table version 3 size
- if (sizeof(Sfnt::Compatibility2) <= lTableSize)
- return true;
- }
- else if (be::swap(pOs2->version) == 3 || be::swap(pOs2->version) == 4)
- { // OS/2 table version 4 size - version 4 changed the meaning of some fields which we don't use
- if (sizeof(Sfnt::Compatibility3) <= lTableSize)
- return true;
- }
- else
- return false;
- break;
- }
-
- case Tag::name:
- {
- const Sfnt::FontNames * pName
- = reinterpret_cast<const Sfnt::FontNames *>(pTable);
- return be::swap(pName->format) == 0;
- }
-
- default:
- break;
- }
-
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the number of glyphs in the font. Should never be less than zero.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-size_t GlyphCount(const void * pMaxp)
-{
- const Sfnt::MaximumProfile * pTable =
- reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
- return be::swap(pTable->num_glyphs);
-}
-
-#ifdef ALL_TTFUTILS
-/*----------------------------------------------------------------------------------------------
- Return the maximum number of components for any composite glyph in the font.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-size_t MaxCompositeComponentCount(const void * pMaxp)
-{
- const Sfnt::MaximumProfile * pTable =
- reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
- return be::swap(pTable->max_component_elements);
-}
-
-/*----------------------------------------------------------------------------------------------
- Composite glyphs can be composed of glyphs that are themselves composites.
- This method returns the maximum number of levels like this for any glyph in the font.
- A non-composite glyph has a level of 1.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-size_t MaxCompositeLevelCount(const void * pMaxp)
-{
- const Sfnt::MaximumProfile * pTable =
- reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
- return be::swap(pTable->max_component_depth);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the number of glyphs in the font according to a differt source.
- Should never be less than zero. Return -1 on failure.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-size_t LocaGlyphCount(size_t lLocaSize, const void * pHead) //throw(std::domain_error)
-{
-
- const Sfnt::FontHeader * pTable
- = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- if (be::swap(pTable->index_to_loc_format)
- == Sfnt::FontHeader::ShortIndexLocFormat)
- // loca entries are two bytes and have been divided by two
- return (lLocaSize >> 1) - 1;
-
- if (be::swap(pTable->index_to_loc_format)
- == Sfnt::FontHeader::LongIndexLocFormat)
- // loca entries are four bytes
- return (lLocaSize >> 2) - 1;
-
- return -1;
- //throw std::domain_error("head table in inconsistent state. The font may be corrupted");
-}
-#endif
-
-/*----------------------------------------------------------------------------------------------
- Return the design units the font is designed with
-----------------------------------------------------------------------------------------------*/
-int DesignUnits(const void * pHead)
-{
- const Sfnt::FontHeader * pTable =
- reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- return be::swap(pTable->units_per_em);
-}
-
-#ifdef ALL_TTFUTILS
-/*----------------------------------------------------------------------------------------------
- Return the checksum from the head table, which serves as a unique identifer for the font.
-----------------------------------------------------------------------------------------------*/
-int HeadTableCheckSum(const void * pHead)
-{
- const Sfnt::FontHeader * pTable =
- reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- return be::swap(pTable->check_sum_adjustment);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the create time from the head table. This consists of a 64-bit integer, which
- we return here as two 32-bit integers.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-void HeadTableCreateTime(const void * pHead,
- unsigned int * pnDateBC, unsigned int * pnDateAD)
-{
- const Sfnt::FontHeader * pTable =
- reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- *pnDateBC = be::swap(pTable->created[0]);
- *pnDateAD = be::swap(pTable->created[1]);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the modify time from the head table.This consists of a 64-bit integer, which
- we return here as two 32-bit integers.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-void HeadTableModifyTime(const void * pHead,
- unsigned int * pnDateBC, unsigned int *pnDateAD)
-{
- const Sfnt::FontHeader * pTable =
- reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- *pnDateBC = be::swap(pTable->modified[0]);
- *pnDateAD = be::swap(pTable->modified[1]);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return true if the font is italic.
-----------------------------------------------------------------------------------------------*/
-bool IsItalic(const void * pHead)
-{
- const Sfnt::FontHeader * pTable =
- reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- return ((be::swap(pTable->mac_style) & 0x00000002) != 0);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the ascent for the font
-----------------------------------------------------------------------------------------------*/
-int FontAscent(const void * pOs2)
-{
- const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
-
- return be::swap(pTable->win_ascent);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the descent for the font
-----------------------------------------------------------------------------------------------*/
-int FontDescent(const void * pOs2)
-{
- const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
-
- return be::swap(pTable->win_descent);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the bold and italic style bits.
- Return true if successful. false otherwise.
- In addition to checking the OS/2 table, one could also check
- the head table's macStyle field (overridden by the OS/2 table on Win)
- the sub-family name in the name table (though this can contain oblique, dark, etc too)
-----------------------------------------------------------------------------------------------*/
-bool FontOs2Style(const void *pOs2, bool & fBold, bool & fItalic)
-{
- const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
-
- fBold = (be::swap(pTable->fs_selection) & Sfnt::Compatibility::Bold) != 0;
- fItalic = (be::swap(pTable->fs_selection) & Sfnt::Compatibility::Italic) != 0;
-
- return true;
-}
-#endif
-
-/*----------------------------------------------------------------------------------------------
- Method for searching name table.
-----------------------------------------------------------------------------------------------*/
-bool GetNameInfo(const void * pName, int nPlatformId, int nEncodingId,
- int nLangId, int nNameId, size_t & lOffset, size_t & lSize)
-{
- lOffset = 0;
- lSize = 0;
-
- const Sfnt::FontNames * pTable = reinterpret_cast<const Sfnt::FontNames *>(pName);
- uint16 cRecord = be::swap(pTable->count);
- uint16 nRecordOffset = be::swap(pTable->string_offset);
- const Sfnt::NameRecord * pRecord = reinterpret_cast<const Sfnt::NameRecord *>(pTable + 1);
-
- for (int i = 0; i < cRecord; ++i)
- {
- if (be::swap(pRecord->platform_id) == nPlatformId &&
- be::swap(pRecord->platform_specific_id) == nEncodingId &&
- be::swap(pRecord->language_id) == nLangId &&
- be::swap(pRecord->name_id) == nNameId)
- {
- lOffset = be::swap(pRecord->offset) + nRecordOffset;
- lSize = be::swap(pRecord->length);
- return true;
- }
- pRecord++;
- }
-
- return false;
-}
-
-#ifdef ALL_TTFUTILS
-/*----------------------------------------------------------------------------------------------
- Return all the lang-IDs that have data for the given name-IDs. Assume that there is room
- in the return array (langIdList) for 128 items. The purpose of this method is to return
- a list of all possible lang-IDs.
-----------------------------------------------------------------------------------------------*/
-int GetLangsForNames(const void * pName, int nPlatformId, int nEncodingId,
- int * nameIdList, int cNameIds, short * langIdList)
-{
- const Sfnt::FontNames * pTable = reinterpret_cast<const Sfnt::FontNames *>(pName);
- int cLangIds = 0;
- uint16 cRecord = be::swap(pTable->count);
- if (cRecord > 127) return cLangIds;
- //uint16 nRecordOffset = swapw(pTable->stringOffset);
- const Sfnt::NameRecord * pRecord = reinterpret_cast<const Sfnt::NameRecord *>(pTable + 1);
-
- for (int i = 0; i < cRecord; ++i)
- {
- if (be::swap(pRecord->platform_id) == nPlatformId &&
- be::swap(pRecord->platform_specific_id) == nEncodingId)
- {
- bool fNameFound = false;
- int nLangId = be::swap(pRecord->language_id);
- int nNameId = be::swap(pRecord->name_id);
- for (int j = 0; j < cNameIds; j++)
- {
- if (nNameId == nameIdList[j])
- {
- fNameFound = true;
- break;
- }
- }
- if (fNameFound)
- {
- // Add it if it's not there.
- int ilang;
- for (ilang = 0; ilang < cLangIds; ilang++)
- if (langIdList[ilang] == nLangId)
- break;
- if (ilang >= cLangIds)
- {
- langIdList[cLangIds] = short(nLangId);
- cLangIds++;
- }
- if (cLangIds == 128)
- return cLangIds;
- }
- }
- pRecord++;
- }
-
- return cLangIds;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the offset and size of the font family name in English for the MS Platform with Unicode
- writing system. The offset is within the pName data. The string is double byte with MSB
- first.
-----------------------------------------------------------------------------------------------*/
-bool Get31EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize)
-{
- return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 1, 1033,
- Sfnt::NameRecord::Family, lOffset, lSize);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the offset and size of the full font name in English for the MS Platform with Unicode
- writing system. The offset is within the pName data. The string is double byte with MSB
- first.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-bool Get31EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize)
-{
- return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 1, 1033,
- Sfnt::NameRecord::Fullname, lOffset, lSize);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the offset and size of the font family name in English for the MS Platform with Symbol
- writing system. The offset is within the pName data. The string is double byte with MSB
- first.
-----------------------------------------------------------------------------------------------*/
-bool Get30EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize)
-{
- return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 0, 1033,
- Sfnt::NameRecord::Family, lOffset, lSize);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the offset and size of the full font name in English for the MS Platform with Symbol
- writing system. The offset is within the pName data. The string is double byte with MSB
- first.
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-bool Get30EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize)
-{
- return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 0, 1033,
- Sfnt::NameRecord::Fullname, lOffset, lSize);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the Glyph ID for a given Postscript name. This method finds the first glyph which
- matches the requested Postscript name. Ideally every glyph should have a unique Postscript
- name (except for special names such as .notdef), but this is not always true.
- On failure return value less than zero.
- -1 - table search failed
- -2 - format 3 table (no Postscript glyph info)
- -3 - other failures
-
- Note: this method is not currently used by the Graphite engine.
-----------------------------------------------------------------------------------------------*/
-int PostLookup(const void * pPost, size_t lPostSize, const void * pMaxp,
- const char * pPostName)
-{
- using namespace Sfnt;
-
- const Sfnt::PostScriptGlyphName * pTable
- = reinterpret_cast<const Sfnt::PostScriptGlyphName *>(pPost);
- fixed format = be::swap(pTable->format);
-
- if (format == PostScriptGlyphName::Format3)
- { // format 3 - no Postscript glyph info in font
- return -2;
- }
-
- // search for given Postscript name among the standard names
- int iPostName = -1; // index in standard names
- for (int i = 0; i < kcPostNames; i++)
- {
- if (!strcmp(pPostName, rgPostName[i]))
- {
- iPostName = i;
- break;
- }
- }
-
- if (format == PostScriptGlyphName::Format1)
- { // format 1 - use standard Postscript names
- return iPostName;
- }
-
- if (format == PostScriptGlyphName::Format25)
- {
- if (iPostName == -1)
- return -1;
-
- const PostScriptGlyphName25 * pTable25
- = static_cast<const PostScriptGlyphName25 *>(pTable);
- int cnGlyphs = GlyphCount(pMaxp);
- for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs && nGlyphId < kcPostNames;
- nGlyphId++)
- { // glyph_name_index25 contains bytes so no byte swapping needed
- // search for first glyph id that uses the standard name
- if (nGlyphId + pTable25->offset[nGlyphId] == iPostName)
- return nGlyphId;
- }
- }
-
- if (format == PostScriptGlyphName::Format2)
- { // format 2
- const PostScriptGlyphName2 * pTable2
- = static_cast<const PostScriptGlyphName2 *>(pTable);
-
- int cnGlyphs = be::swap(pTable2->number_of_glyphs);
-
- if (iPostName != -1)
- { // did match a standard name, look for first glyph id mapped to that name
- for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs; nGlyphId++)
- {
- if (be::swap(pTable2->glyph_name_index[nGlyphId]) == iPostName)
- return nGlyphId;
- }
- }
-
- { // did not match a standard name, search font specific names
- size_t nStrSizeGoal = strlen(pPostName);
- const char * pFirstGlyphName = reinterpret_cast<const char *>(
- &pTable2->glyph_name_index[0] + cnGlyphs);
- const char * pGlyphName = pFirstGlyphName;
- int iInNames = 0; // index in font specific names
- bool fFound = false;
- const char * const endOfTable
- = reinterpret_cast<const char *>(pTable2) + lPostSize;
- while (pGlyphName < endOfTable && !fFound)
- { // search Pascal strings for first matching name
- size_t nStringSize = size_t(*pGlyphName);
- if (nStrSizeGoal != nStringSize ||
- strncmp(pGlyphName + 1, pPostName, nStringSize))
- { // did not match
- ++iInNames;
- pGlyphName += nStringSize + 1;
- }
- else
- { // did match
- fFound = true;
- }
- }
- if (!fFound)
- return -1; // no font specific name matches request
-
- iInNames += kcPostNames;
- for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs; nGlyphId++)
- { // search for first glyph id that maps to the found string index
- if (be::swap(pTable2->glyph_name_index[nGlyphId]) == iInNames)
- return nGlyphId;
- }
- return -1; // no glyph mapped to this index (very strange)
- }
- }
-
- return -3;
-}
-
-/*----------------------------------------------------------------------------------------------
- Convert a Unicode character string from big endian (MSB first, Motorola) format to little
- endian (LSB first, Intel) format.
- nSize is the number of Unicode characters in the string. It should not include any
- terminating null. If nSize is 0, it is assumed the string is null terminated. nSize
- defaults to 0.
- Return true if successful, false otherwise.
-----------------------------------------------------------------------------------------------*/
-void SwapWString(void * pWStr, size_t nSize /* = 0 */) //throw (std::invalid_argument)
-{
- if (pWStr == 0)
- {
-// throw std::invalid_argument("null pointer given");
- return;
- }
-
- uint16 * pStr = reinterpret_cast<uint16 *>(pWStr);
- uint16 * const pStrEnd = pStr + (nSize == 0 ? wcslen((const wchar_t*)pStr) : nSize);
-
- for (; pStr != pStrEnd; ++pStr)
- *pStr = be::swap(*pStr);
-// std::transform(pStr, pStrEnd, pStr, read<uint16>);
-
-// for (int i = 0; i < nSize; i++)
-// { // swap the wide characters in the string
-// pStr[i] = utf16(be::swap(uint16(pStr[i])));
-// }
-}
-#endif
-
-/*----------------------------------------------------------------------------------------------
- Get the left-side bearing and and advance width based on the given tables and Glyph ID
- Return true if successful, false otherwise. On false, one or both value could be INT_MIN
-----------------------------------------------------------------------------------------------*/
-bool HorMetrics(gid16 nGlyphId, const void * pHmtx, size_t lHmtxSize, const void * pHhea,
- int & nLsb, unsigned int & nAdvWid)
-{
- const Sfnt::HorizontalMetric * phmtx =
- reinterpret_cast<const Sfnt::HorizontalMetric *>(pHmtx);
-
- const Sfnt::HorizontalHeader * phhea =
- reinterpret_cast<const Sfnt::HorizontalHeader *>(pHhea);
-
- size_t cLongHorMetrics = be::swap(phhea->num_long_hor_metrics);
- if (nGlyphId < cLongHorMetrics)
- { // glyph id is acceptable
- if (nGlyphId * sizeof(Sfnt::HorizontalMetric) >= lHmtxSize) return false;
- nAdvWid = be::swap(phmtx[nGlyphId].advance_width);
- nLsb = be::swap(phmtx[nGlyphId].left_side_bearing);
- }
- else
- {
- // guard against bad glyph id
- size_t lLsbOffset = sizeof(Sfnt::HorizontalMetric) * cLongHorMetrics +
- sizeof(int16) * (nGlyphId - cLongHorMetrics); // offset in bytes
- // We test like this as LsbOffset is an offset not a length.
- if (lLsbOffset > lHmtxSize - sizeof(int16))
- {
- nLsb = 0;
- return false;
- }
- nAdvWid = be::swap(phmtx[cLongHorMetrics - 1].advance_width);
- nLsb = be::peek<int16>(reinterpret_cast<const byte *>(phmtx) + lLsbOffset);
- }
-
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return a pointer to the requested cmap subtable. By default find the Microsoft Unicode
- subtable. Pass nEncoding as -1 to find first table that matches only nPlatformId.
- Return NULL if the subtable cannot be found.
-----------------------------------------------------------------------------------------------*/
-const void * FindCmapSubtable(const void * pCmap, int nPlatformId, /* =3 */ int nEncodingId, /* = 1 */ size_t length)
-{
- const Sfnt::CharacterCodeMap * pTable = reinterpret_cast<const Sfnt::CharacterCodeMap *>(pCmap);
- uint16 csuPlatforms = be::swap(pTable->num_subtables);
- if (length && (sizeof(Sfnt::CharacterCodeMap) + 8 * (csuPlatforms - 1) > length))
- return NULL;
- for (int i = 0; i < csuPlatforms; i++)
- {
- if (be::swap(pTable->encoding[i].platform_id) == nPlatformId &&
- (nEncodingId == -1 || be::swap(pTable->encoding[i].platform_specific_id) == nEncodingId))
- {
- uint32 offset = be::swap(pTable->encoding[i].offset);
- const uint8 * pRtn = reinterpret_cast<const uint8 *>(pCmap) + offset;
- if (length)
- {
- if (offset > length) return NULL;
- uint16 format = be::read<uint16>(pRtn);
- if (format == 4)
- {
- uint16 subTableLength = be::peek<uint16>(pRtn);
- if (i + 1 == csuPlatforms)
- {
- if (subTableLength > length - offset)
- return NULL;
- }
- else if (subTableLength > be::swap(pTable->encoding[i+1].offset))
- return NULL;
- }
- if (format == 12)
- {
- uint32 subTableLength = be::peek<uint32>(pRtn);
- if (i + 1 == csuPlatforms)
- {
- if (subTableLength > length - offset)
- return NULL;
- }
- else if (subTableLength > be::swap(pTable->encoding[i+1].offset))
- return NULL;
- }
- }
- return reinterpret_cast<const uint8 *>(pCmap) + offset;
- }
- }
-
- return 0;
-}
-
-/*----------------------------------------------------------------------------------------------
- Check the Microsoft Unicode subtable for expected values
-----------------------------------------------------------------------------------------------*/
-bool CheckCmapSubtable4(const void * pCmapSubtable4)
-{
- if (!pCmapSubtable4) return false;
- const Sfnt::CmapSubTable * pTable = reinterpret_cast<const Sfnt::CmapSubTable *>(pCmapSubtable4);
- // Bob H says ome freeware TT fonts have version 1 (eg, CALIGULA.TTF)
- // so don't check subtable version. 21 Mar 2002 spec changes version to language.
- if (be::swap(pTable->format) != 4) return false;
- const Sfnt::CmapSubTableFormat4 * pTable4 = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmapSubtable4);
- uint16 length = be::swap(pTable4->length);
- if (length < sizeof(Sfnt::CmapSubTableFormat4))
- return false;
- uint16 nRanges = be::swap(pTable4->seg_count_x2) >> 1;
- if (length < sizeof(Sfnt::CmapSubTableFormat4) + 4 * nRanges * sizeof(uint16))
- return false;
- // check last range is properly terminated
- uint16 chEnd = be::peek<uint16>(pTable4->end_code + nRanges - 1);
- return (chEnd == 0xFFFF);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the Glyph ID for the given Unicode ID in the Microsoft Unicode subtable.
- (Actually this code only depends on subtable being format 4.)
- Return 0 if the Unicode ID is not in the subtable.
-----------------------------------------------------------------------------------------------*/
-gid16 CmapSubtable4Lookup(const void * pCmapSubtabel4, unsigned int nUnicodeId, int rangeKey)
-{
- const Sfnt::CmapSubTableFormat4 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmapSubtabel4);
-
- uint16 nSeg = be::swap(pTable->seg_count_x2) >> 1;
-
- uint16 n;
- const uint16 * pLeft, * pMid;
- uint16 cMid, chStart, chEnd;
-
- if (rangeKey)
- {
- pMid = &(pTable->end_code[rangeKey]);
- chEnd = be::peek<uint16>(pMid);
- n = rangeKey;
- }
- else
- {
- // Binary search of the endCode[] array
- pLeft = &(pTable->end_code[0]);
- n = nSeg;
- while (n > 0)
- {
- cMid = n >> 1; // Pick an element in the middle
- pMid = pLeft + cMid;
- chEnd = be::peek<uint16>(pMid);
- if (nUnicodeId <= chEnd)
- {
- if (cMid == 0 || nUnicodeId > be::peek<uint16>(pMid -1))
- break; // Must be this seg or none!
- n = cMid; // Continue on left side, omitting mid point
- }
- else
- {
- pLeft = pMid + 1; // Continue on right side, omitting mid point
- n -= (cMid + 1);
- }
- }
-
- if (!n)
- return 0;
- }
-
- // Ok, we're down to one segment and pMid points to the endCode element
- // Either this is it or none is.
-
- chStart = be::peek<uint16>(pMid += nSeg + 1);
- if (chEnd >= nUnicodeId && nUnicodeId >= chStart)
- {
- // Found correct segment. Find Glyph Id
- int16 idDelta = be::peek<uint16>(pMid += nSeg);
- uint16 idRangeOffset = be::peek<uint16>(pMid += nSeg);
-
- if (idRangeOffset == 0)
- return (uint16)(idDelta + nUnicodeId); // must use modulus 2^16
-
- // Look up value in glyphIdArray
- const ptrdiff_t offset = (nUnicodeId - chStart) + (idRangeOffset >> 1) +
- (pMid - reinterpret_cast<const uint16 *>(pTable));
- if (offset * 2 >= be::swap<uint16>(pTable->length))
- return 0;
- gid16 nGlyphId = be::peek<uint16>(reinterpret_cast<const uint16 *>(pTable)+offset);
- // If this value is 0, return 0. Else add the idDelta
- return nGlyphId ? nGlyphId + idDelta : 0;
- }
-
- return 0;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the next Unicode value in the cmap. Pass 0 to obtain the first item.
- Returns 0xFFFF as the last item.
- pRangeKey is an optional key that is used to optimize the search; its value is the range
- in which the character is found.
-----------------------------------------------------------------------------------------------*/
-unsigned int CmapSubtable4NextCodepoint(const void *pCmap31, unsigned int nUnicodeId, int * pRangeKey)
-{
- const Sfnt::CmapSubTableFormat4 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmap31);
-
- uint16 nRange = be::swap(pTable->seg_count_x2) >> 1;
-
- uint32 nUnicodePrev = (uint32)nUnicodeId;
-
- const uint16 * pStartCode = &(pTable->end_code[0])
- + nRange // length of end code array
- + 1; // reserved word
-
- if (nUnicodePrev == 0)
- {
- // return the first codepoint.
- if (pRangeKey)
- *pRangeKey = 0;
- return be::peek<uint16>(pStartCode);
- }
- else if (nUnicodePrev >= 0xFFFF)
- {
- if (pRangeKey)
- *pRangeKey = nRange - 1;
- return 0xFFFF;
- }
-
- int iRange = (pRangeKey) ? *pRangeKey : 0;
- // Just in case we have a bad key:
- while (iRange > 0 && be::peek<uint16>(pStartCode + iRange) > nUnicodePrev)
- iRange--;
- while (be::peek<uint16>(pTable->end_code + iRange) < nUnicodePrev)
- iRange++;
-
- // Now iRange is the range containing nUnicodePrev.
- unsigned int nStartCode = be::peek<uint16>(pStartCode + iRange);
- unsigned int nEndCode = be::peek<uint16>(pTable->end_code + iRange);
-
- if (nStartCode > nUnicodePrev)
- // Oops, nUnicodePrev is not in the cmap! Adjust so we get a reasonable
- // answer this time around.
- nUnicodePrev = nStartCode - 1;
-
- if (nEndCode > nUnicodePrev)
- {
- // Next is in the same range; it is the next successive codepoint.
- if (pRangeKey)
- *pRangeKey = iRange;
- return nUnicodePrev + 1;
- }
-
- // Otherwise the next codepoint is the first one in the next range.
- // There is guaranteed to be a next range because there must be one that
- // ends with 0xFFFF.
- if (pRangeKey)
- *pRangeKey = iRange + 1;
- return be::peek<uint16>(pStartCode + iRange + 1);
-}
-
-/*----------------------------------------------------------------------------------------------
- Check the Microsoft UCS-4 subtable for expected values.
-----------------------------------------------------------------------------------------------*/
-bool CheckCmapSubtable12(const void *pCmapSubtable12)
-{
- if (!pCmapSubtable12) return false;
- const Sfnt::CmapSubTable * pTable = reinterpret_cast<const Sfnt::CmapSubTable *>(pCmapSubtable12);
- if (be::swap(pTable->format) != 12)
- return false;
- const Sfnt::CmapSubTableFormat12 * pTable12 = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmapSubtable12);
- uint32 length = be::swap(pTable12->length);
- if (length < sizeof(Sfnt::CmapSubTableFormat12))
- return false;
-
- return (length == (sizeof(Sfnt::CmapSubTableFormat12) + (be::swap(pTable12->num_groups) - 1)
- * sizeof(uint32) * 3));
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the Glyph ID for the given Unicode ID in the Microsoft UCS-4 subtable.
- (Actually this code only depends on subtable being format 12.)
- Return 0 if the Unicode ID is not in the subtable.
-----------------------------------------------------------------------------------------------*/
-gid16 CmapSubtable12Lookup(const void * pCmap310, unsigned int uUnicodeId, int rangeKey)
-{
- const Sfnt::CmapSubTableFormat12 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmap310);
-
- //uint32 uLength = be::swap(pTable->length); //could use to test for premature end of table
- uint32 ucGroups = be::swap(pTable->num_groups);
-
- for (unsigned int i = rangeKey; i < ucGroups; i++)
- {
- uint32 uStartCode = be::swap(pTable->group[i].start_char_code);
- uint32 uEndCode = be::swap(pTable->group[i].end_char_code);
- if (uUnicodeId >= uStartCode && uUnicodeId <= uEndCode)
- {
- uint32 uDiff = uUnicodeId - uStartCode;
- uint32 uStartGid = be::swap(pTable->group[i].start_glyph_id);
- return static_cast<gid16>(uStartGid + uDiff);
- }
- }
-
- return 0;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the next Unicode value in the cmap. Pass 0 to obtain the first item.
- Returns 0x10FFFF as the last item.
- pRangeKey is an optional key that is used to optimize the search; its value is the range
- in which the character is found.
-----------------------------------------------------------------------------------------------*/
-unsigned int CmapSubtable12NextCodepoint(const void *pCmap310, unsigned int nUnicodeId, int * pRangeKey)
-{
- const Sfnt::CmapSubTableFormat12 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmap310);
-
- int nRange = be::swap(pTable->num_groups);
-
- uint32 nUnicodePrev = (uint32)nUnicodeId;
-
- if (nUnicodePrev == 0)
- {
- // return the first codepoint.
- if (pRangeKey)
- *pRangeKey = 0;
- return be::swap(pTable->group[0].start_char_code);
- }
- else if (nUnicodePrev >= 0x10FFFF)
- {
- if (pRangeKey)
- *pRangeKey = nRange;
- return 0x10FFFF;
- }
-
- int iRange = (pRangeKey) ? *pRangeKey : 0;
- // Just in case we have a bad key:
- while (iRange > 0 && be::swap(pTable->group[iRange].start_char_code) > nUnicodePrev)
- iRange--;
- while (be::swap(pTable->group[iRange].end_char_code) < nUnicodePrev)
- iRange++;
-
- // Now iRange is the range containing nUnicodePrev.
-
- unsigned int nStartCode = be::swap(pTable->group[iRange].start_char_code);
- unsigned int nEndCode = be::swap(pTable->group[iRange].end_char_code);
-
- if (nStartCode > nUnicodePrev)
- // Oops, nUnicodePrev is not in the cmap! Adjust so we get a reasonable
- // answer this time around.
- nUnicodePrev = nStartCode - 1;
-
- if (nEndCode > nUnicodePrev)
- {
- // Next is in the same range; it is the next successive codepoint.
- if (pRangeKey)
- *pRangeKey = iRange;
- return nUnicodePrev + 1;
- }
-
- // Otherwise the next codepoint is the first one in the next range, or 10FFFF if we're done.
- if (pRangeKey)
- *pRangeKey = iRange + 1;
- return (iRange + 1 >= nRange) ? 0x10FFFF : be::swap(pTable->group[iRange + 1].start_char_code);
-}
-
-/*----------------------------------------------------------------------------------------------
- Return the offset stored in the loca table for the given Glyph ID.
- (This offset is into the glyf table.)
- Return -1 if the lookup failed.
- Technically this method should return an unsigned long but it is unlikely the offset will
- exceed 2^31.
-----------------------------------------------------------------------------------------------*/
-size_t LocaLookup(gid16 nGlyphId,
- const void * pLoca, size_t lLocaSize,
- const void * pHead) // throw (std::out_of_range)
-{
- const Sfnt::FontHeader * pTable = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- // CheckTable verifies the index_to_loc_format is valid
- if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::ShortIndexLocFormat)
- { // loca entries are two bytes and have been divided by two
- if (nGlyphId < (lLocaSize >> 1) - 1) // allow sentinel value to be accessed
- {
- const uint16 * pShortTable = reinterpret_cast<const uint16 *>(pLoca);
- return (be::peek<uint16>(pShortTable + nGlyphId) << 1);
- }
- }
-
- if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::LongIndexLocFormat)
- { // loca entries are four bytes
- if (nGlyphId < (lLocaSize >> 2) - 1)
- {
- const uint32 * pLongTable = reinterpret_cast<const uint32 *>(pLoca);
- return be::peek<uint32>(pLongTable + nGlyphId);
- }
- }
-
- // only get here if glyph id was bad
- return -1;
- //throw std::out_of_range("glyph id out of range for font");
-}
-
-/*----------------------------------------------------------------------------------------------
- Return a pointer into the glyf table based on the given offset (from LocaLookup).
- Return NULL on error.
-----------------------------------------------------------------------------------------------*/
-void * GlyfLookup(const void * pGlyf, size_t nGlyfOffset, size_t nTableLen)
-{
- const uint8 * pByte = reinterpret_cast<const uint8 *>(pGlyf);
- if (nGlyfOffset == size_t(-1) || nGlyfOffset >= nTableLen)
- return NULL;
- return const_cast<uint8 *>(pByte + nGlyfOffset);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the bounding box coordinates for a simple glyf entry (non-composite).
- Return true if successful, false otherwise.
-----------------------------------------------------------------------------------------------*/
-bool GlyfBox(const void * pSimpleGlyf, int & xMin, int & yMin,
- int & xMax, int & yMax)
-{
- const Sfnt::Glyph * pGlyph = reinterpret_cast<const Sfnt::Glyph *>(pSimpleGlyf);
-
- xMin = be::swap(pGlyph->x_min);
- yMin = be::swap(pGlyph->y_min);
- xMax = be::swap(pGlyph->x_max);
- yMax = be::swap(pGlyph->y_max);
-
- return true;
-}
-
-#ifdef ALL_TTFUTILS
-/*----------------------------------------------------------------------------------------------
- Return the number of contours for a simple glyf entry (non-composite)
- Returning -1 means this is a composite glyph
-----------------------------------------------------------------------------------------------*/
-int GlyfContourCount(const void * pSimpleGlyf)
-{
- const Sfnt::Glyph * pGlyph = reinterpret_cast<const Sfnt::Glyph *>(pSimpleGlyf);
- return be::swap(pGlyph->number_of_contours); // -1 means composite glyph
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the point numbers for the end points of the glyph contours for a simple
- glyf entry (non-composite).
- cnPointsTotal - count of contours from GlyfContourCount(); (same as number of end points)
- prgnContourEndPoints - should point to a buffer large enough to hold cnPoints integers
- cnPoints - count of points placed in above range
- Return true if successful, false otherwise.
- False could indicate a multi-level composite glyphs.
-----------------------------------------------------------------------------------------------*/
-bool GlyfContourEndPoints(const void * pSimpleGlyf, int * prgnContourEndPoint,
- int cnPointsTotal, int & cnPoints)
-{
- const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
-
- int cContours = be::swap(pGlyph->number_of_contours);
- if (cContours < 0)
- return false; // this method isn't supposed handle composite glyphs
-
- for (int i = 0; i < cContours && i < cnPointsTotal; i++)
- {
- prgnContourEndPoint[i] = be::swap(pGlyph->end_pts_of_contours[i]);
- }
-
- cnPoints = cContours;
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the points for a simple glyf entry (non-composite)
- cnPointsTotal - count of points from largest end point obtained from GlyfContourEndPoints
- prgnX & prgnY - should point to buffers large enough to hold cnPointsTotal integers
- The ranges are parallel so that coordinates for point(n) are found at offset n in both
- ranges. This is raw point data with relative coordinates.
- prgbFlag - should point to a buffer a large enough to hold cnPointsTotal bytes
- This range is parallel to the prgnX & prgnY
- cnPoints - count of points placed in above ranges
- Return true if successful, false otherwise.
- False could indicate a composite glyph
-----------------------------------------------------------------------------------------------*/
-bool GlyfPoints(const void * pSimpleGlyf, int * prgnX, int * prgnY,
- char * prgbFlag, int cnPointsTotal, int & cnPoints)
-{
- using namespace Sfnt;
-
- const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
- int cContours = be::swap(pGlyph->number_of_contours);
- // return false for composite glyph
- if (cContours <= 0)
- return false;
- int cPts = be::swap(pGlyph->end_pts_of_contours[cContours - 1]) + 1;
- if (cPts > cnPointsTotal)
- return false;
-
- // skip over bounding box data & point to byte count of instructions (hints)
- const uint8 * pbGlyph = reinterpret_cast<const uint8 *>
- (&pGlyph->end_pts_of_contours[cContours]);
-
- // skip over hints & point to first flag
- int cbHints = be::swap(*(uint16 *)pbGlyph);
- pbGlyph += sizeof(uint16);
- pbGlyph += cbHints;
-
- // load flags & point to first x coordinate
- int iFlag = 0;
- while (iFlag < cPts)
- {
- if (!(*pbGlyph & SimpleGlyph::Repeat))
- { // flag isn't repeated
- prgbFlag[iFlag] = (char)*pbGlyph;
- pbGlyph++;
- iFlag++;
- }
- else
- { // flag is repeated; count specified by next byte
- char chFlag = (char)*pbGlyph;
- pbGlyph++;
- int cFlags = (int)*pbGlyph;
- pbGlyph++;
- prgbFlag[iFlag] = chFlag;
- iFlag++;
- for (int i = 0; i < cFlags; i++)
- {
- prgbFlag[iFlag + i] = chFlag;
- }
- iFlag += cFlags;
- }
- }
- if (iFlag != cPts)
- return false;
-
- // load x coordinates
- iFlag = 0;
- while (iFlag < cPts)
- {
- if (prgbFlag[iFlag] & SimpleGlyph::XShort)
- {
- prgnX[iFlag] = *pbGlyph;
- if (!(prgbFlag[iFlag] & SimpleGlyph::XIsPos))
- {
- prgnX[iFlag] = -prgnX[iFlag];
- }
- pbGlyph++;
- }
- else
- {
- if (prgbFlag[iFlag] & SimpleGlyph::XIsSame)
- {
- prgnX[iFlag] = 0;
- // do NOT increment pbGlyph
- }
- else
- {
- prgnX[iFlag] = be::swap(*(int16 *)pbGlyph);
- pbGlyph += sizeof(int16);
- }
- }
- iFlag++;
- }
-
- // load y coordinates
- iFlag = 0;
- while (iFlag < cPts)
- {
- if (prgbFlag[iFlag] & SimpleGlyph::YShort)
- {
- prgnY[iFlag] = *pbGlyph;
- if (!(prgbFlag[iFlag] & SimpleGlyph::YIsPos))
- {
- prgnY[iFlag] = -prgnY[iFlag];
- }
- pbGlyph++;
- }
- else
- {
- if (prgbFlag[iFlag] & SimpleGlyph::YIsSame)
- {
- prgnY[iFlag] = 0;
- // do NOT increment pbGlyph
- }
- else
- {
- prgnY[iFlag] = be::swap(*(int16 *)pbGlyph);
- pbGlyph += sizeof(int16);
- }
- }
- iFlag++;
- }
-
- cnPoints = cPts;
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Fill prgnCompId with the component Glyph IDs from pSimpleGlyf.
- Client must allocate space before calling.
- pSimpleGlyf - assumed to point to a composite glyph
- cCompIdTotal - the number of elements in prgnCompId
- cCompId - the total number of Glyph IDs stored in prgnCompId
- Return true if successful, false otherwise
- False could indicate a non-composite glyph or the input array was not big enough
-----------------------------------------------------------------------------------------------*/
-bool GetComponentGlyphIds(const void * pSimpleGlyf, int * prgnCompId,
- size_t cnCompIdTotal, size_t & cnCompId)
-{
- using namespace Sfnt;
-
- if (GlyfContourCount(pSimpleGlyf) >= 0)
- return false;
-
- const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
- // for a composite glyph, the special data begins here
- const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
-
- uint16 GlyphFlags;
- size_t iCurrentComp = 0;
- do
- {
- GlyphFlags = be::swap(*((uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- prgnCompId[iCurrentComp++] = be::swap(*((uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- if (iCurrentComp >= cnCompIdTotal)
- return false;
- int nOffset = 0;
- nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
- nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
- pbGlyph += nOffset;
- } while (GlyphFlags & CompoundGlyph::MoreComponents);
-
- cnCompId = iCurrentComp;
-
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return info on how a component glyph is to be placed
- pSimpleGlyph - assumed to point to a composite glyph
- nCompId - glyph id for component of interest
- bOffset - if true, a & b are the x & y offsets for this component
- if false, b is the point on this component that is attaching to point a on the
- preceding glyph
- Return true if successful, false otherwise
- False could indicate a non-composite glyph or that component wasn't found
-----------------------------------------------------------------------------------------------*/
-bool GetComponentPlacement(const void * pSimpleGlyf, int nCompId,
- bool fOffset, int & a, int & b)
-{
- using namespace Sfnt;
-
- if (GlyfContourCount(pSimpleGlyf) >= 0)
- return false;
-
- const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
- // for a composite glyph, the special data begins here
- const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
-
- uint16 GlyphFlags;
- do
- {
- GlyphFlags = be::swap(*((uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- if (be::swap(*((uint16 *)pbGlyph)) == nCompId)
- {
- pbGlyph += sizeof(uint16); // skip over glyph id of component
- fOffset = (GlyphFlags & CompoundGlyph::ArgsAreXYValues) == CompoundGlyph::ArgsAreXYValues;
-
- if (GlyphFlags & CompoundGlyph::Arg1Arg2Words )
- {
- a = be::swap(*(int16 *)pbGlyph);
- pbGlyph += sizeof(int16);
- b = be::swap(*(int16 *)pbGlyph);
- pbGlyph += sizeof(int16);
- }
- else
- { // args are signed bytes
- a = *pbGlyph++;
- b = *pbGlyph++;
- }
- return true;
- }
- pbGlyph += sizeof(uint16); // skip over glyph id of component
- int nOffset = 0;
- nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
- nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
- pbGlyph += nOffset;
- } while (GlyphFlags & CompoundGlyph::MoreComponents);
-
- // didn't find requested component
- fOffset = true;
- a = 0;
- b = 0;
- return false;
-}
-
-/*----------------------------------------------------------------------------------------------
- Return info on how a component glyph is to be transformed
- pSimpleGlyph - assumed to point to a composite glyph
- nCompId - glyph id for component of interest
- flt11, flt11, flt11, flt11 - a 2x2 matrix giving the transform
- bTransOffset - whether to transform the offset from above method
- The spec is unclear about the meaning of this flag
- Currently - initialize to true for MS rasterizer and false for Mac rasterizer, then
- on return it will indicate whether transform should apply to offset (MSDN CD 10/99)
- Return true if successful, false otherwise
- False could indicate a non-composite glyph or that component wasn't found
-----------------------------------------------------------------------------------------------*/
-bool GetComponentTransform(const void * pSimpleGlyf, int nCompId,
- float & flt11, float & flt12, float & flt21, float & flt22,
- bool & fTransOffset)
-{
- using namespace Sfnt;
-
- if (GlyfContourCount(pSimpleGlyf) >= 0)
- return false;
-
- const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
- // for a composite glyph, the special data begins here
- const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
-
- uint16 GlyphFlags;
- do
- {
- GlyphFlags = be::swap(*((uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- if (be::swap(*((uint16 *)pbGlyph)) == nCompId)
- {
- pbGlyph += sizeof(uint16); // skip over glyph id of component
- pbGlyph += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2; // skip over placement data
-
- if (fTransOffset) // MS rasterizer
- fTransOffset = !(GlyphFlags & CompoundGlyph::UnscaledOffset);
- else // Apple rasterizer
- fTransOffset = (GlyphFlags & CompoundGlyph::ScaledOffset) != 0;
-
- if (GlyphFlags & CompoundGlyph::HaveScale)
- {
- flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- flt12 = 0;
- flt21 = 0;
- flt22 = flt11;
- }
- else if (GlyphFlags & CompoundGlyph::HaveXAndYScale)
- {
- flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- flt12 = 0;
- flt21 = 0;
- flt22 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- }
- else if (GlyphFlags & CompoundGlyph::HaveTwoByTwo)
- {
- flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- flt12 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- flt21 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- flt22 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
- pbGlyph += sizeof(uint16);
- }
- else
- { // identity transform
- flt11 = 1.0;
- flt12 = 0.0;
- flt21 = 0.0;
- flt22 = 1.0;
- }
- return true;
- }
- pbGlyph += sizeof(uint16); // skip over glyph id of component
- int nOffset = 0;
- nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
- nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
- nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
- pbGlyph += nOffset;
- } while (GlyphFlags & CompoundGlyph::MoreComponents);
-
- // didn't find requested component
- fTransOffset = false;
- flt11 = 1;
- flt12 = 0;
- flt21 = 0;
- flt22 = 1;
- return false;
-}
-#endif
-
-/*----------------------------------------------------------------------------------------------
- Return a pointer into the glyf table based on the given tables and Glyph ID
- Since this method doesn't check for spaces, it is good to call IsSpace before using it.
- Return NULL on error.
-----------------------------------------------------------------------------------------------*/
-void * GlyfLookup(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead)
-{
- // test for valid glyph id
- // CheckTable verifies the index_to_loc_format is valid
-
- const Sfnt::FontHeader * pTable
- = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
-
- if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::ShortIndexLocFormat)
- { // loca entries are two bytes (and have been divided by two)
- if (nGlyphId >= (lLocaSize >> 1) - 1) // don't allow nGlyphId to access sentinel
- {
-// throw std::out_of_range("glyph id out of range for font");
- return NULL;
- }
- }
- if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::LongIndexLocFormat)
- { // loca entries are four bytes
- if (nGlyphId >= (lLocaSize >> 2) - 1)
- {
-// throw std::out_of_range("glyph id out of range for font");
- return NULL;
- }
- }
-
- long lGlyfOffset = LocaLookup(nGlyphId, pLoca, lLocaSize, pHead);
- void * pSimpleGlyf = GlyfLookup(pGlyf, lGlyfOffset, lGlyfSize); // invalid loca offset returns null
- return pSimpleGlyf;
-}
-
-#ifdef ALL_TTFUTILS
-/*----------------------------------------------------------------------------------------------
- Determine if a particular Glyph ID has any data in the glyf table. If it is white space,
- there will be no glyf data, though there will be metric data in hmtx, etc.
-----------------------------------------------------------------------------------------------*/
-bool IsSpace(gid16 nGlyphId, const void * pLoca, size_t lLocaSize, const void * pHead)
-{
- size_t lGlyfOffset = LocaLookup(nGlyphId, pLoca, lLocaSize, pHead);
-
- // the +1 should always work because there is a sentinel value at the end of the loca table
- size_t lNextGlyfOffset = LocaLookup(nGlyphId + 1, pLoca, lLocaSize, pHead);
-
- return (lNextGlyfOffset - lGlyfOffset) == 0;
-}
-
-/*----------------------------------------------------------------------------------------------
- Determine if a particular Glyph ID is a multi-level composite.
-----------------------------------------------------------------------------------------------*/
-bool IsDeepComposite(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, long lLocaSize, const void * pHead)
-{
- if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
-
- void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL)
- return false; // no way to really indicate an error occured here
-
- if (GlyfContourCount(pSimpleGlyf) >= 0)
- return false;
-
- int rgnCompId[kMaxGlyphComponents]; // assumes only a limited number of glyph components
- size_t cCompIdTotal = kMaxGlyphComponents;
- size_t cCompId = 0;
-
- if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
- return false;
-
- for (size_t i = 0; i < cCompId; i++)
- {
- pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]),
- pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL) {return false;}
-
- if (GlyfContourCount(pSimpleGlyf) < 0)
- return true;
- }
-
- return false;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the bounding box coordinates based on the given tables and Glyph ID
- Handles both simple and composite glyphs.
- Return true if successful, false otherwise. On false, all point values will be INT_MIN
- False may indicate a white space glyph
-----------------------------------------------------------------------------------------------*/
-bool GlyfBox(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead, int & xMin, int & yMin, int & xMax, int & yMax)
-{
- xMin = yMin = xMax = yMax = INT_MIN;
-
- if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
-
- void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL) {return false;}
-
- return GlyfBox(pSimpleGlyf, xMin, yMin, xMax, yMax);
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the number of contours based on the given tables and Glyph ID
- Handles both simple and composite glyphs.
- Return true if successful, false otherwise. On false, cnContours will be INT_MIN
- False may indicate a white space glyph or a multi-level composite glyph.
-----------------------------------------------------------------------------------------------*/
-bool GlyfContourCount(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead, size_t & cnContours)
-{
- cnContours = static_cast<size_t>(INT_MIN);
-
- if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
-
- void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL) {return false;}
-
- int cRtnContours = GlyfContourCount(pSimpleGlyf);
- if (cRtnContours >= 0)
- {
- cnContours = size_t(cRtnContours);
- return true;
- }
-
- //handle composite glyphs
-
- int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
- size_t cCompIdTotal = kMaxGlyphComponents;
- size_t cCompId = 0;
-
- if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
- return false;
-
- cRtnContours = 0;
- int cTmp = 0;
- for (size_t i = 0; i < cCompId; i++)
- {
- if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
- pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]),
- pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == 0) {return false;}
- // return false on multi-level composite
- if ((cTmp = GlyfContourCount(pSimpleGlyf)) < 0)
- return false;
- cRtnContours += cTmp;
- }
-
- cnContours = size_t(cRtnContours);
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the point numbers for the end points of the glyph contours based on the given tables
- and Glyph ID
- Handles both simple and composite glyphs.
- cnPoints - count of contours from GlyfContourCount (same as number of end points)
- prgnContourEndPoints - should point to a buffer large enough to hold cnPoints integers
- Return true if successful, false otherwise. On false, all end points are INT_MIN
- False may indicate a white space glyph or a multi-level composite glyph.
-----------------------------------------------------------------------------------------------*/
-bool GlyfContourEndPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead,
- int * prgnContourEndPoint, size_t cnPoints)
-{
- memset(prgnContourEndPoint, 0xFF, cnPoints * sizeof(int));
- // std::fill_n(prgnContourEndPoint, cnPoints, INT_MIN);
-
- if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
-
- void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL) {return false;}
-
- int cContours = GlyfContourCount(pSimpleGlyf);
- int cActualPts = 0;
- if (cContours > 0)
- return GlyfContourEndPoints(pSimpleGlyf, prgnContourEndPoint, cnPoints, cActualPts);
-
- // handle composite glyphs
-
- int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
- size_t cCompIdTotal = kMaxGlyphComponents;
- size_t cCompId = 0;
-
- if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
- return false;
-
- int * prgnCurrentEndPoint = prgnContourEndPoint;
- int cCurrentPoints = cnPoints;
- int nPrevPt = 0;
- for (size_t i = 0; i < cCompId; i++)
- {
- if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
- pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]), pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL) {return false;}
- // returns false on multi-level composite
- if (!GlyfContourEndPoints(pSimpleGlyf, prgnCurrentEndPoint, cCurrentPoints, cActualPts))
- return false;
- // points in composite are numbered sequentially as components are added
- // must adjust end point numbers for new point numbers
- for (int j = 0; j < cActualPts; j++)
- prgnCurrentEndPoint[j] += nPrevPt;
- nPrevPt = prgnCurrentEndPoint[cActualPts - 1] + 1;
-
- prgnCurrentEndPoint += cActualPts;
- cCurrentPoints -= cActualPts;
- }
-
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Get the points for a glyph based on the given tables and Glyph ID
- Handles both simple and composite glyphs.
- cnPoints - count of points from largest end point obtained from GlyfContourEndPoints
- prgnX & prgnY - should point to buffers large enough to hold cnPoints integers
- The ranges are parallel so that coordinates for point(n) are found at offset n in
- both ranges. These points are in absolute coordinates.
- prgfOnCurve - should point to a buffer a large enough to hold cnPoints bytes (bool)
- This range is parallel to the prgnX & prgnY
- Return true if successful, false otherwise. On false, all points may be INT_MIN
- False may indicate a white space glyph, a multi-level composite, or a corrupt font
- // TODO: doesn't support composite glyphs whose components are themselves components
- It's not clear from the TTF spec when the transforms should be applied. Should the
- transform be done before or after attachment point calcs? (current code - before)
- Should the transform be applied to other offsets? (currently - no; however commented
- out code is in place so that if CompoundGlyph::UnscaledOffset on the MS rasterizer is
- clear (typical) then yes, and if CompoundGlyph::ScaledOffset on the Apple rasterizer is
- clear (typical?) then no). See GetComponentTransform.
- It's also unclear where point numbering with attachment poinst starts
- (currently - first point number is relative to whole glyph, second point number is
- relative to current glyph).
-----------------------------------------------------------------------------------------------*/
-bool GlyfPoints(gid16 nGlyphId, const void * pGlyf,
- const void * pLoca, size_t lGlyfSize, size_t lLocaSize, const void * pHead,
- const int * /*prgnContourEndPoint*/, size_t /*cnEndPoints*/,
- int * prgnX, int * prgnY, bool * prgfOnCurve, size_t cnPoints)
-{
- memset(prgnX, 0x7F, cnPoints * sizeof(int));
- memset(prgnY, 0x7F, cnPoints * sizeof(int));
-
- if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead))
- return false;
-
- void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pSimpleGlyf == NULL)
- return false;
-
- int cContours = GlyfContourCount(pSimpleGlyf);
- int cActualPts;
- if (cContours > 0)
- {
- if (!GlyfPoints(pSimpleGlyf, prgnX, prgnY, (char *)prgfOnCurve, cnPoints, cActualPts))
- return false;
- CalcAbsolutePoints(prgnX, prgnY, cnPoints);
- SimplifyFlags((char *)prgfOnCurve, cnPoints);
- return true;
- }
-
- // handle composite glyphs
- int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
- size_t cCompIdTotal = kMaxGlyphComponents;
- size_t cCompId = 0;
-
- // this will fail if there are more components than there is room for
- if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
- return false;
-
- int * prgnCurrentX = prgnX;
- int * prgnCurrentY = prgnY;
- char * prgbCurrentFlag = (char *)prgfOnCurve; // converting bool to char should be safe
- int cCurrentPoints = cnPoints;
- bool fOffset = true, fTransOff = true;
- int a, b;
- float flt11, flt12, flt21, flt22;
- // int * prgnPrevX = prgnX; // in case first att pt number relative to preceding glyph
- // int * prgnPrevY = prgnY;
- for (size_t i = 0; i < cCompId; i++)
- {
- if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
- void * pCompGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]), pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
- if (pCompGlyf == NULL) {return false;}
- // returns false on multi-level composite
- if (!GlyfPoints(pCompGlyf, prgnCurrentX, prgnCurrentY, prgbCurrentFlag,
- cCurrentPoints, cActualPts))
- return false;
- if (!GetComponentPlacement(pSimpleGlyf, rgnCompId[i], fOffset, a, b))
- return false;
- if (!GetComponentTransform(pSimpleGlyf, rgnCompId[i],
- flt11, flt12, flt21, flt22, fTransOff))
- return false;
- bool fIdTrans = flt11 == 1.0 && flt12 == 0.0 && flt21 == 0.0 && flt22 == 1.0;
-
- // convert points to absolute coordinates
- // do before transform and attachment point placement are applied
- CalcAbsolutePoints(prgnCurrentX, prgnCurrentY, cActualPts);
-
- // apply transform - see main method note above
- // do before attachment point calcs
- if (!fIdTrans)
- for (int j = 0; j < cActualPts; j++)
- {
- int x = prgnCurrentX[j]; // store before transform applied
- int y = prgnCurrentY[j];
- prgnCurrentX[j] = (int)(x * flt11 + y * flt12);
- prgnCurrentY[j] = (int)(x * flt21 + y * flt22);
- }
-
- // apply placement - see main method note above
- int nXOff, nYOff;
- if (fOffset) // explicit x & y offsets
- {
- /* ignore fTransOff for now
- if (fTransOff && !fIdTrans)
- { // transform x & y offsets
- nXOff = (int)(a * flt11 + b * flt12);
- nYOff = (int)(a * flt21 + b * flt22);
- }
- else */
- { // don't transform offset
- nXOff = a;
- nYOff = b;
- }
- }
- else // attachment points
- { // in case first point is relative to preceding glyph and second relative to current
- // nXOff = prgnPrevX[a] - prgnCurrentX[b];
- // nYOff = prgnPrevY[a] - prgnCurrentY[b];
- // first point number relative to whole composite, second relative to current glyph
- nXOff = prgnX[a] - prgnCurrentX[b];
- nYOff = prgnY[a] - prgnCurrentY[b];
- }
- for (int j = 0; j < cActualPts; j++)
- {
- prgnCurrentX[j] += nXOff;
- prgnCurrentY[j] += nYOff;
- }
-
- // prgnPrevX = prgnCurrentX;
- // prgnPrevY = prgnCurrentY;
- prgnCurrentX += cActualPts;
- prgnCurrentY += cActualPts;
- prgbCurrentFlag += cActualPts;
- cCurrentPoints -= cActualPts;
- }
-
- SimplifyFlags((char *)prgfOnCurve, cnPoints);
-
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Simplify the meaning of flags to just indicate whether point is on-curve or off-curve.
----------------------------------------------------------------------------------------------*/
-bool SimplifyFlags(char * prgbFlags, int cnPoints)
-{
- for (int i = 0; i < cnPoints; i++)
- prgbFlags[i] = static_cast<char>(prgbFlags[i] & Sfnt::SimpleGlyph::OnCurve);
- return true;
-}
-
-/*----------------------------------------------------------------------------------------------
- Convert relative point coordinates to absolute coordinates
- Points are stored in the font such that they are offsets from one another except for the
- first point of a glyph.
----------------------------------------------------------------------------------------------*/
-bool CalcAbsolutePoints(int * prgnX, int * prgnY, int cnPoints)
-{
- int nX = prgnX[0];
- int nY = prgnY[0];
- for (int i = 1; i < cnPoints; i++)
- {
- prgnX[i] += nX;
- nX = prgnX[i];
- prgnY[i] += nY;
- nY = prgnY[i];
- }
-
- return true;
-}
-#endif
-
-/*----------------------------------------------------------------------------------------------
- Return the length of the 'name' table in bytes.
- Currently used.
----------------------------------------------------------------------------------------------*/
-#if 0
-size_t NameTableLength(const byte * pTable)
-{
- byte * pb = (const_cast<byte *>(pTable)) + 2; // skip format
- size_t cRecords = *pb++ << 8; cRecords += *pb++;
- int dbStringOffset0 = (*pb++) << 8; dbStringOffset0 += *pb++;
- int dbMaxStringOffset = 0;
- for (size_t irec = 0; irec < cRecords; irec++)
- {
- int nPlatform = (*pb++) << 8; nPlatform += *pb++;
- int nEncoding = (*pb++) << 8; nEncoding += *pb++;
- int nLanguage = (*pb++) << 8; nLanguage += *pb++;
- int nName = (*pb++) << 8; nName += *pb++;
- int cbStringLen = (*pb++) << 8; cbStringLen += *pb++;
- int dbStringOffset = (*pb++) << 8; dbStringOffset += *pb++;
- if (dbMaxStringOffset < dbStringOffset + cbStringLen)
- dbMaxStringOffset = dbStringOffset + cbStringLen;
- }
- return dbStringOffset0 + dbMaxStringOffset;
-}
-#endif
-
-} // end of namespace TtfUtil
-} // end of namespace graphite
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_logging.cpp b/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_logging.cpp
deleted file mode 100644
index a010e97d764..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_logging.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#include <cstdio>
-
-#include "graphite2/Log.h"
-#include "inc/debug.h"
-#include "inc/CharInfo.h"
-#include "inc/Slot.h"
-#include "inc/Segment.h"
-
-#if defined _WIN32
-#include "windows.h"
-#endif
-
-using namespace graphite2;
-
-extern "C" {
-
-
-bool gr_start_logging(gr_face * face, const char *log_path)
-{
- if (!face || !log_path) return false;
-
-#if !defined GRAPHITE2_NTRACING
- gr_stop_logging(face);
-#if defined _WIN32
- int n = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, log_path, -1, 0, 0);
- if (n == 0 || n > MAX_PATH - 12) return false;
-
- LPWSTR wlog_path = gralloc<WCHAR>(n);
- FILE *log = 0;
- if (wlog_path && MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, log_path, -1, wlog_path, n))
- log = _wfopen(wlog_path, L"wt");
-
- free(wlog_path);
-#else // _WIN32
- FILE *log = fopen(log_path, "wt");
-#endif // _WIN32
- if (!log) return false;
-
- face->setLogger(log);
- if (!face->logger()) return false;
-
- *face->logger() << json::array;
-#ifdef GRAPHITE2_TELEMETRY
- *face->logger() << face->tele;
-#endif
-
- return true;
-#else // GRAPHITE2_NTRACING
- return false;
-#endif // GRAPHITE2_NTRACING
-}
-
-bool graphite_start_logging(FILE * /* log */, GrLogMask /* mask */)
-{
-//#if !defined GRAPHITE2_NTRACING
-// graphite_stop_logging();
-//
-// if (!log) return false;
-//
-// dbgout = new json(log);
-// if (!dbgout) return false;
-//
-// *dbgout << json::array;
-// return true;
-//#else
- return false;
-//#endif
-}
-
-void gr_stop_logging(gr_face * face)
-{
- if (!face) return;
-
-#if !defined GRAPHITE2_NTRACING
- if (face->logger())
- {
- FILE * log = face->logger()->stream();
- face->setLogger(0);
- fclose(log);
- }
-#endif
-}
-
-void graphite_stop_logging()
-{
-// if (dbgout) delete dbgout;
-// dbgout = 0;
-}
-
-} // extern "C"
-
-#ifdef GRAPHITE2_TELEMETRY
-size_t * graphite2::telemetry::_category = 0UL;
-#endif
-
-#if !defined GRAPHITE2_NTRACING
-
-#ifdef GRAPHITE2_TELEMETRY
-
-json & graphite2::operator << (json & j, const telemetry & t) throw()
-{
- j << json::object
- << "type" << "telemetry"
- << "silf" << t.silf
- << "states" << t.states
- << "starts" << t.starts
- << "transitions" << t.transitions
- << "glyphs" << t.glyph
- << "code" << t.code
- << "misc" << t.misc
- << "total" << (t.silf + t.states + t.starts + t.transitions + t.glyph + t.code + t.misc)
- << json::close;
- return j;
-}
-#else
-json & graphite2::operator << (json & j, const telemetry &) throw()
-{
- return j;
-}
-#endif
-
-
-json & graphite2::operator << (json & j, const CharInfo & ci) throw()
-{
- return j << json::object
- << "offset" << ci.base()
- << "unicode" << ci.unicodeChar()
- << "break" << ci.breakWeight()
- << "flags" << ci.flags()
- << "slot" << json::flat << json::object
- << "before" << ci.before()
- << "after" << ci.after()
- << json::close
- << json::close;
-}
-
-
-json & graphite2::operator << (json & j, const dslot & ds) throw()
-{
- assert(ds.first);
- assert(ds.second);
- const Segment & seg = *ds.first;
- const Slot & s = *ds.second;
-
- j << json::object
- << "id" << objectid(ds)
- << "gid" << s.gid()
- << "charinfo" << json::flat << json::object
- << "original" << s.original()
- << "before" << s.before()
- << "after" << s.after()
- << json::close
- << "origin" << s.origin()
- << "shift" << Position(float(s.getAttr(0, gr_slatShiftX, 0)),
- float(s.getAttr(0, gr_slatShiftY, 0)))
- << "advance" << s.advancePos()
- << "insert" << s.isInsertBefore()
- << "break" << s.getAttr(&seg, gr_slatBreak, 0);
- if (s.just() > 0)
- j << "justification" << s.just();
- if (s.getBidiLevel() > 0)
- j << "bidi" << s.getBidiLevel();
- if (!s.isBase())
- j << "parent" << json::flat << json::object
- << "id" << objectid(dslot(&seg, s.attachedTo()))
- << "level" << s.getAttr(0, gr_slatAttLevel, 0)
- << "offset" << s.attachOffset()
- << json::close;
- j << "user" << json::flat << json::array;
- for (int n = 0; n!= seg.numAttrs(); ++n)
- j << s.userAttrs()[n];
- j << json::close;
- if (s.firstChild())
- {
- j << "children" << json::flat << json::array;
- for (const Slot *c = s.firstChild(); c; c = c->nextSibling())
- j << objectid(dslot(&seg, c));
- j << json::close;
- }
- return j << json::close;
-}
-
-
-graphite2::objectid::objectid(const dslot & ds) throw()
-{
- const Slot * const p = ds.second;
- uint32 s = reinterpret_cast<size_t>(p);
- sprintf(name, "%.4x-%.2x-%.4hx", uint16(s >> 16), uint16(p ? p->userAttrs()[ds.first->silf()->numUser()] : 0), uint16(s));
- name[sizeof name-1] = 0;
-}
-
-graphite2::objectid::objectid(const Segment * const p) throw()
-{
- uint32 s = reinterpret_cast<size_t>(p);
- sprintf(name, "%.4x-%.2x-%.4hx", uint16(s >> 16), 0, uint16(s));
- name[sizeof name-1] = 0;
-}
-
-#endif
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Endian.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Endian.h
deleted file mode 100644
index 16ff79f5519..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Endian.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-----------------------------------------------------------------------------
-Copyright (C) 2011 SIL International
-Responsibility: Tim Eves
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-
-Description:
-A set of fast template based decoders for decoding values of any C integer
-type up to long int size laid out with most significant byte first or least
-significant byte first (aka big endian or little endian). These are CPU
-byte order agnostic and will function the same regardless of the CPUs native
-byte order.
-Being template based means if the either le or be class is not used then
-template code of unused functions will not be instantiated by the compiler
-and thus shouldn't cause any overhead.
------------------------------------------------------------------------------*/
-#include <cstddef>
-
-#pragma once
-
-
-class be
-{
- template<int S>
- inline static unsigned long int _peek(const unsigned char * p) {
- return _peek<S/2>(p) << (S/2)*8 | _peek<S/2>(p+S/2);
- }
-public:
- template<typename T>
- inline static T peek(const void * p) {
- return T(_peek<sizeof(T)>(static_cast<const unsigned char *>(p)));
- }
-
- template<typename T>
- inline static T read(const unsigned char * &p) {
- const T r = T(_peek<sizeof(T)>(p));
- p += sizeof r;
- return r;
- }
-
- template<typename T>
- inline static T swap(const T x) {
- return T(_peek<sizeof(T)>(reinterpret_cast<const unsigned char *>(&x)));
- }
-
- template<typename T>
- inline static void skip(const unsigned char * &p, size_t n=1) {
- p += sizeof(T)*n;
- }
-};
-
-template<>
-inline unsigned long int be::_peek<1>(const unsigned char * p) { return *p; }
-
-
-class le
-{
- template<int S>
- inline static unsigned long int _peek(const unsigned char * p) {
- return _peek<S/2>(p) | _peek<S/2>(p+S/2) << (S/2)*8;
- }
-public:
- template<typename T>
- inline static T peek(const void * p) {
- return T(_peek<sizeof(T)>(static_cast<const unsigned char *>(p)));
- }
-
- template<typename T>
- inline static T read(const unsigned char * &p) {
- const T r = T(_peek<sizeof(T)>(p));
- p += sizeof r;
- return r;
- }
-
- template<typename T>
- inline static T swap(const T x) {
- return T(_peek<sizeof(T)>(reinterpret_cast<const unsigned char *>(&x)));
- }
-
- template<typename T>
- inline static void skip(const unsigned char * &p, size_t n=1) {
- p += sizeof(T)*n;
- }
-};
-
-template<>
-inline unsigned long int le::_peek<1>(const unsigned char * p) { return *p; }
-
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Sparse.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Sparse.h
deleted file mode 100644
index 0159a9d6705..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Sparse.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#pragma once
-#include <iterator>
-#include <utility>
-
-#include "inc/Main.h"
-
-namespace graphite2 {
-
-
-// A read-only packed fast sparse array of uint16 with uint16 keys.
-// Like most container classes this has capacity and size properties and these
-// refer to the number of stored entries and the number of addressable entries
-// as normal. However due the sparse nature the capacity is always <= than the
-// size.
-class sparse
-{
-public:
- typedef uint16 key_type;
- typedef uint16 mapped_type;
- typedef std::pair<const key_type, mapped_type> value_type;
-
-private:
- typedef unsigned long mask_t;
-
- static const unsigned char SIZEOF_CHUNK = (sizeof(mask_t) - sizeof(key_type))*8;
-
- struct chunk
- {
- mask_t mask:SIZEOF_CHUNK;
- key_type offset;
- };
-
- sparse(const sparse &);
- sparse & operator = (const sparse &);
-
-public:
- template<typename I>
- sparse(I first, const I last);
- sparse() throw();
- ~sparse() throw();
-
- operator bool () const throw();
- mapped_type operator [] (const key_type k) const throw();
-
- size_t capacity() const throw();
- size_t size() const throw();
-
- size_t _sizeof() const throw();
-
- CLASS_NEW_DELETE;
-
-private:
- union {
- chunk * map;
- mapped_type * values;
- } m_array;
- key_type m_nchunks;
-};
-
-
-inline
-sparse::sparse() throw() : m_nchunks(0)
-{
- m_array.map = 0;
-}
-
-
-template <typename I>
-sparse::sparse(I attr, const I last)
-: m_nchunks(0)
-{
- m_array.map = 0;
-
- // Find the maximum extent of the key space.
- size_t n_values=0;
- for (I i = attr; i != last; ++i, ++n_values)
- {
- const key_type k = (*i).first / SIZEOF_CHUNK;
- if (k >= m_nchunks) m_nchunks = k+1;
- }
- if (m_nchunks == 0) return;
-
- m_array.values = grzeroalloc<mapped_type>((m_nchunks*sizeof(chunk) + sizeof(mapped_type)/2)
- / sizeof(mapped_type)
- + n_values); // *sizeof(mapped_type));
-
- if (m_array.values == 0)
- {
- free(m_array.values); m_array.map=0;
- return;
- }
-
- chunk * ci = m_array.map;
- ci->offset = (m_nchunks*sizeof(chunk) + sizeof(mapped_type)-1)/sizeof(mapped_type);
- mapped_type * vi = m_array.values + ci->offset;
- for (; attr != last; ++attr, ++vi)
- {
- const typename std::iterator_traits<I>::value_type v = *attr;
- chunk * const ci_ = m_array.map + v.first/SIZEOF_CHUNK;
-
- if (ci != ci_)
- {
- ci = ci_;
- ci->offset = vi - m_array.values;
- }
-
- ci->mask |= 1UL << (SIZEOF_CHUNK - 1 - (v.first % SIZEOF_CHUNK));
- *vi = v.second;
- }
-}
-
-
-inline
-sparse::operator bool () const throw()
-{
- return m_array.map != 0;
-}
-
-inline
-size_t sparse::size() const throw()
-{
- return m_nchunks*SIZEOF_CHUNK;
-}
-
-inline
-size_t sparse::_sizeof() const throw()
-{
- return sizeof(sparse) + capacity()*sizeof(mapped_type) + m_nchunks*sizeof(chunk);
-}
-
-} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfTypes.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfTypes.h
deleted file mode 100644
index 49ffa39229e..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfTypes.h
+++ /dev/null
@@ -1,419 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#pragma once
-/*--------------------------------------------------------------------*//*:Ignore this sentence.
-
-File: TtfTypes.h
-Responsibility: Tim Eves
-Last reviewed: Not yet.
-
-Description:
-Provides types required to represent the TTF basic types.
--------------------------------------------------------------------------------*//*:End Ignore*/
-
-
-//**********************************************************************************************
-// Include files
-//**********************************************************************************************
-namespace graphite2
-{
-namespace TtfUtil
-{
-//**********************************************************************************************
-// Forward declarations
-//**********************************************************************************************
-
-
-//**********************************************************************************************
-// Type declarations
-//**********************************************************************************************
-typedef unsigned char uint8;
-typedef uint8 byte;
-typedef signed char int8;
-typedef unsigned short uint16;
-typedef short int16;
-typedef unsigned int uint32;
-typedef int int32;
-
-typedef int16 short_frac;
-typedef int32 fixed;
-typedef int16 fword;
-typedef uint16 ufword;
-typedef int16 f2dot14;
-typedef uint32 long_date_time[2];
-
-//**********************************************************************************************
-// Constants and enum types
-//**********************************************************************************************/
-enum
-{
- OneFix = 1<<16
-};
-
-//**********************************************************************************************
-// Table declarations
-//**********************************************************************************************
-namespace Sfnt
-{
-#pragma pack(1) // We need this or the structure members aren't alligned
- // correctly. Fortunately this form of pragma is supposed
- // to be recongnised by VS C++ too (at least according to
- // MSDN).
-
- struct OffsetSubTable
- {
- uint32 scaler_type;
- uint16 num_tables,
- search_range,
- entry_selector,
- range_shift;
- struct Entry
- {
- uint32 tag,
- checksum,
- offset,
- length;
- } table_directory[1];
-
- enum ScalerType
- {
- TrueTypeMac = 0x74727565U,
- TrueTypeWin = 0x00010000U,
- Type1 = 0x74797031U
- };
- };
-
-
-
-
- struct CharacterCodeMap
- {
- uint16 version,
- num_subtables;
- struct
- {
- uint16 platform_id,
- platform_specific_id;
- uint32 offset;
- } encoding[1];
- };
-
- struct CmapSubTable
- {
- uint16 format,
- length,
- language;
- };
-
- struct CmapSubTableFormat4 : CmapSubTable
- {
- uint16 seg_count_x2,
- search_range,
- entry_selector,
- range_shift,
- end_code[1];
- // There are arrarys after this which need their
- // start positions calculated since end_code is
- // seg_count uint16s long.
- };
-
- struct CmapSubTableFormat12
- {
- fixed format;
- uint32 length,
- language,
- num_groups;
- struct
- {
- uint32 start_char_code,
- end_char_code,
- start_glyph_id;
- } group[1];
- };
-
-
-
- struct FontHeader
- {
- fixed version,
- font_revision;
- uint32 check_sum_adjustment,
- magic_number;
- uint16 flags,
- units_per_em;
- long_date_time created,
- modified;
- fword x_min,
- y_min,
- x_max,
- y_max;
- uint16 mac_style,
- lowest_rec_ppem;
- int16 font_direction_hint,
- index_to_loc_format,
- glyph_data_format;
- enum
- {
- MagicNumber = 0x5F0F3CF5,
- GlypDataFormat = 0
- };
- enum {ShortIndexLocFormat, LongIndexLocFormat};
- };
-
-
-
-
- struct PostScriptGlyphName
- {
- fixed format,
- italic_angle;
- fword underline_position,
- underline_thickness;
- uint32 is_fixed_pitch,
- min_mem_type42,
- max_mem_type42,
- min_mem_type1,
- max_mem_type1;
- enum
- {
- Format1 = 0x10000,
- Format2 = 0x20000,
- Format25 = 0x28000,
- Format3 = 0x30000,
- Format4 = 0x40000
- };
- };
-
- struct PostScriptGlyphName2 : PostScriptGlyphName
- {
- uint16 number_of_glyphs,
- glyph_name_index[1];
- };
-
- struct PostScriptGlyphName25 : PostScriptGlyphName
- {
- uint16 number_of_glyphs;
- int8 offset[1];
- };
-
- struct PostScriptGlyphName3 : PostScriptGlyphName {};
-
- struct PostScriptGlyphName4 : PostScriptGlyphName
- {
- uint16 glyph_to_char_map[1];
- };
-
-
- struct HorizontalHeader
- {
- fixed version;
- fword ascent,
- descent,
- line_gap;
- ufword advance_width_max;
- fword min_left_side_bearing,
- max_left_side_bearing,
- x_max_element;
- int16 caret_slope_rise,
- caret_slope_run;
- fword caret_offset;
- int16 reserved[4],
- metric_data_format;
- uint16 num_long_hor_metrics;
- };
-
- struct MaximumProfile
- {
- fixed version;
- uint16 num_glyphs,
- max_points,
- max_contours,
- max_component_points,
- max_component_contours,
- max_zones,
- max_twilight_points,
- max_storage,
- max_function_defs,
- max_instruction_defs,
- max_stack_elements,
- max_size_of_instructions,
- max_component_elements,
- max_component_depth;
- };
-
-
- typedef byte Panose[10];
-
- struct Compatibility0
- {
- uint16 version;
- int16 x_avg_char_width;
- uint16 weight_class,
- width_class;
- int16 fs_type,
- y_subscript_x_size,
- y_subscript_y_size,
- y_subscript_x_offset,
- y_subscript_y_offset,
- y_superscript_x_size,
- y_superscript_y_size,
- y_superscript_x_offset,
- y_superscript_y_offset,
- y_strikeout_size,
- y_strikeout_position,
- family_class;
- Panose panose;
- uint32 unicode_range[4];
- int8 ach_vend_id[4];
- uint16 fs_selection,
- fs_first_char_index,
- fs_last_char_index, // Acording to Apple's spec this is where v0 should end
- typo_ascender,
- typo_descender,
- type_linegap,
- win_ascent,
- win_descent;
-
- enum
- {
- Italic =0x01,
- Underscore=0x02,
- Negative =0x04,
- Outlined =0x08,
- StrikeOut =0x10,
- Bold =0x20
- };
- };
-
- struct Compatibility1 : Compatibility0
- {
- uint32 codepage_range[2];
- };
-
- struct Compatibility2 : Compatibility1
- {
- int16 x_height,
- cap_height;
- uint16 default_char,
- break_char,
- max_context;
- };
-
- struct Compatibility3 : Compatibility2 {};
-
- typedef Compatibility3 Compatibility;
-
-
- struct NameRecord
- {
- uint16 platform_id,
- platform_specific_id,
- language_id,
- name_id,
- length,
- offset;
- enum {Unicode, Mactintosh, Reserved, Microsoft};
- enum
- {
- Copyright, Family, Subfamily, UniqueSubfamily,
- Fullname, Version, PostScript
- };
- };
-
- struct LangTagRecord
- {
- uint16 length,
- offset;
- };
-
- struct FontNames
- {
- uint16 format,
- count,
- string_offset;
- NameRecord name_record[1];
- };
-
-
- struct HorizontalMetric
- {
- uint16 advance_width;
- int16 left_side_bearing;
- };
-
-
- struct Glyph
- {
- int16 number_of_contours;
- fword x_min,
- y_min,
- x_max,
- y_max;
- };
-
- struct SimpleGlyph : Glyph
- {
- uint16 end_pts_of_contours[1];
- enum
- {
- OnCurve = 0x01,
- XShort = 0x02,
- YShort = 0x04,
- Repeat = 0x08,
- XIsSame = 0x10,
- XIsPos = 0x10,
- YIsSame = 0x20,
- YIsPos = 0x20
- };
- };
-
- struct CompoundGlyph : Glyph
- {
- uint16 flags,
- glyph_index;
- enum
- {
- Arg1Arg2Words = 0x01,
- ArgsAreXYValues = 0x02,
- RoundXYToGrid = 0x04,
- HaveScale = 0x08,
- MoreComponents = 0x20,
- HaveXAndYScale = 0x40,
- HaveTwoByTwo = 0x80,
- HaveInstructions = 0x100,
- UseMyMetrics = 0x200,
- OverlapCompund = 0x400,
- ScaledOffset = 0x800,
- UnscaledOffset = 0x1000
- };
- };
-
-#pragma pack()
-} // end of namespace Sfnt
-
-} // end of namespace TtfUtil
-} // end of namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfUtil.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfUtil.h
deleted file mode 100644
index 7fafb69cf29..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/TtfUtil.h
+++ /dev/null
@@ -1,206 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#pragma once
-/*--------------------------------------------------------------------*//*:Ignore this sentence.
-
-File: TtfUtil.h
-Responsibility: Alan Ward
-Last reviewed: Not yet.
-
-Description:
- Utility class for handling TrueType font files.
-----------------------------------------------------------------------------------------------*/
-
-
-#include <cstddef>
-
-namespace graphite2
-{
-namespace TtfUtil
-{
-
-typedef long fontTableId32;
-typedef unsigned short gid16;
-
-#define TTF_TAG(a,b,c,d) ((a << 24UL) + (b << 16UL) + (c << 8UL) + (d))
-
-// Enumeration used to specify a table in a TTF file
-class Tag
-{
- unsigned long _v;
-public:
- Tag(const char n[5]) throw() : _v(TTF_TAG(n[0],n[1],n[2],n[3])) {}
- Tag(const unsigned long tag) throw() : _v(tag) {}
-
- operator unsigned long () const throw () { return _v; }
-
- enum
- {
- Feat = TTF_TAG('F','e','a','t'),
- Glat = TTF_TAG('G','l','a','t'),
- Gloc = TTF_TAG('G','l','o','c'),
- Sile = TTF_TAG('S','i','l','e'),
- Silf = TTF_TAG('S','i','l','f'),
- Sill = TTF_TAG('S','i','l','l'),
- cmap = TTF_TAG('c','m','a','p'),
- cvt = TTF_TAG('c','v','t',' '),
- cryp = TTF_TAG('c','r','y','p'),
- head = TTF_TAG('h','e','a','d'),
- fpgm = TTF_TAG('f','p','g','m'),
- gdir = TTF_TAG('g','d','i','r'),
- glyf = TTF_TAG('g','l','y','f'),
- hdmx = TTF_TAG('h','d','m','x'),
- hhea = TTF_TAG('h','h','e','a'),
- hmtx = TTF_TAG('h','m','t','x'),
- loca = TTF_TAG('l','o','c','a'),
- kern = TTF_TAG('k','e','r','n'),
- LTSH = TTF_TAG('L','T','S','H'),
- maxp = TTF_TAG('m','a','x','p'),
- name = TTF_TAG('n','a','m','e'),
- OS_2 = TTF_TAG('O','S','/','2'),
- post = TTF_TAG('p','o','s','t'),
- prep = TTF_TAG('p','r','e','p')
- };
-};
-
-/*----------------------------------------------------------------------------------------------
- Class providing utility methods to parse a TrueType font file (TTF).
- Callling application handles all file input and memory allocation.
- Assumes minimal knowledge of TTF file format.
-----------------------------------------------------------------------------------------------*/
- ////////////////////////////////// tools to find & check TTF tables
- bool GetHeaderInfo(size_t & lOffset, size_t & lSize);
- bool CheckHeader(const void * pHdr);
- bool GetTableDirInfo(const void * pHdr, size_t & lOffset, size_t & lSize);
- bool GetTableInfo(const Tag TableTag, const void * pHdr, const void * pTableDir,
- size_t & lOffset, size_t & lSize);
- bool CheckTable(const Tag TableId, const void * pTable, size_t lTableSize);
-
- ////////////////////////////////// simple font wide info
- size_t GlyphCount(const void * pMaxp);
-#ifdef ALL_TTFUTILS
- size_t MaxCompositeComponentCount(const void * pMaxp);
- size_t MaxCompositeLevelCount(const void * pMaxp);
- size_t LocaGlyphCount(size_t lLocaSize, const void * pHead); // throw (std::domain_error);
-#endif
- int DesignUnits(const void * pHead);
-#ifdef ALL_TTFUTILS
- int HeadTableCheckSum(const void * pHead);
- void HeadTableCreateTime(const void * pHead, unsigned int * pnDateBC, unsigned int * pnDateAD);
- void HeadTableModifyTime(const void * pHead, unsigned int * pnDateBC, unsigned int * pnDateAD);
- bool IsItalic(const void * pHead);
- int FontAscent(const void * pOs2);
- int FontDescent(const void * pOs2);
- bool FontOs2Style(const void *pOs2, bool & fBold, bool & fItalic);
- bool Get31EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize);
- bool Get31EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize);
- bool Get30EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize);
- bool Get30EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize);
- int PostLookup(const void * pPost, size_t lPostSize, const void * pMaxp,
- const char * pPostName);
-#endif
-
- ////////////////////////////////// utility methods helpful for name table
- bool GetNameInfo(const void * pName, int nPlatformId, int nEncodingId,
- int nLangId, int nNameId, size_t & lOffset, size_t & lSize);
- //size_t NameTableLength(const byte * pTable);
-#ifdef ALL_TTFUTILS
- int GetLangsForNames(const void * pName, int nPlatformId, int nEncodingId,
- int *nameIdList, int cNameIds, short *langIdList);
- void SwapWString(void * pWStr, size_t nSize = 0); // throw (std::invalid_argument);
-#endif
-
- ////////////////////////////////// cmap lookup tools
- const void * FindCmapSubtable(const void * pCmap, int nPlatformId = 3,
- int nEncodingId = 1, size_t length = 0);
- bool CheckCmapSubtable4(const void * pCmap31);
- gid16 CmapSubtable4Lookup(const void * pCmapSubtabel4, unsigned int nUnicodeId, int rangeKey = 0);
- unsigned int CmapSubtable4NextCodepoint(const void *pCmap31, unsigned int nUnicodeId,
- int * pRangeKey = 0);
- bool CheckCmapSubtable12(const void *pCmap310);
- gid16 CmapSubtable12Lookup(const void * pCmap310, unsigned int uUnicodeId, int rangeKey = 0);
- unsigned int CmapSubtable12NextCodepoint(const void *pCmap310, unsigned int nUnicodeId,
- int * pRangeKey = 0);
-
- ///////////////////////////////// horizontal metric data for a glyph
- bool HorMetrics(gid16 nGlyphId, const void * pHmtx, size_t lHmtxSize,
- const void * pHhea, int & nLsb, unsigned int & nAdvWid);
-
- ////////////////////////////////// primitives for loca and glyf lookup
- size_t LocaLookup(gid16 nGlyphId, const void * pLoca, size_t lLocaSize,
- const void * pHead); // throw (std::out_of_range);
- void * GlyfLookup(const void * pGlyf, size_t lGlyfOffset, size_t lTableLen);
-
- ////////////////////////////////// primitves for simple glyph data
- bool GlyfBox(const void * pSimpleGlyf, int & xMin, int & yMin,
- int & xMax, int & yMax);
-
-#ifdef ALL_TTFUTILS
- int GlyfContourCount(const void * pSimpleGlyf);
- bool GlyfContourEndPoints(const void * pSimpleGlyf, int * prgnContourEndPoint,
- int cnPointsTotal, size_t & cnPoints);
- bool GlyfPoints(const void * pSimpleGlyf, int * prgnX, int * prgnY,
- char * prgbFlag, int cnPointsTotal, int & cnPoints);
-
- // primitive to find the glyph ids in a composite glyph
- bool GetComponentGlyphIds(const void * pSimpleGlyf, int * prgnCompId,
- size_t cnCompIdTotal, size_t & cnCompId);
- // primitive to find the placement data for a component in a composite glyph
- bool GetComponentPlacement(const void * pSimpleGlyf, int nCompId,
- bool fOffset, int & a, int & b);
- // primitive to find the transform data for a component in a composite glyph
- bool GetComponentTransform(const void * pSimpleGlyf, int nCompId,
- float & flt11, float & flt12, float & flt21, float & flt22, bool & fTransOffset);
-#endif
-
- ////////////////////////////////// operate on composite or simple glyph (auto glyf lookup)
- void * GlyfLookup(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead); // primitive used by below methods
-
-#ifdef ALL_TTFUTILS
- // below are primary user methods for handling glyf data
- bool IsSpace(gid16 nGlyphId, const void * pLoca, size_t lLocaSize, const void * pHead);
- bool IsDeepComposite(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead);
-
- bool GlyfBox(gid16 nGlyphId, const void * pGlyf, const void * pLoca, size_t lGlyfSize, size_t lLocaSize,
- const void * pHead, int & xMin, int & yMin, int & xMax, int & yMax);
- bool GlyfContourCount(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void *pHead, size_t & cnContours);
- bool GlyfContourEndPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead, int * prgnContourEndPoint, size_t cnPoints);
- bool GlyfPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
- size_t lGlyfSize, size_t lLocaSize, const void * pHead, const int * prgnContourEndPoint, size_t cnEndPoints,
- int * prgnX, int * prgnY, bool * prgfOnCurve, size_t cnPoints);
-
- // utitily method used by high-level GlyfPoints
- bool SimplifyFlags(char * prgbFlags, int cnPoints);
- bool CalcAbsolutePoints(int * prgnX, int * prgnY, int cnPoints);
-#endif
-
-} // end of namespace TtfUtil
-} // end of namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/UtfCodec.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/UtfCodec.h
deleted file mode 100644
index 1a49179aafa..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/UtfCodec.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-#pragma once
-
-#include <cstdlib>
-#include "inc/Main.h"
-
-namespace graphite2 {
-
-typedef uint32 uchar_t;
-
-template <int N>
-struct _utf_codec
-{
- typedef uchar_t codeunit_t;
-
- static void put(codeunit_t * cp, const uchar_t , int8 & len) throw();
- static uchar_t get(const codeunit_t * cp, int8 & len) throw();
-};
-
-
-template <>
-struct _utf_codec<32>
-{
-private:
- static const uchar_t limit = 0x110000;
-public:
- typedef uint32 codeunit_t;
-
- inline
- static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
- {
- *cp = usv; l = 1;
- }
-
- inline
- static uchar_t get(const codeunit_t * cp, int8 & l) throw()
- {
- if (cp[0] < limit) { l = 1; return cp[0]; }
- else { l = -1; return 0xFFFD; }
- }
-};
-
-
-template <>
-struct _utf_codec<16>
-{
-private:
- static const int32 lead_offset = 0xD800 - (0x10000 >> 10);
- static const int32 surrogate_offset = 0x10000 - (0xD800 << 10) - 0xDC00;
-public:
- typedef uint16 codeunit_t;
-
- inline
- static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
- {
- if (usv < 0x10000) { l = 1; cp[0] = codeunit_t(usv); }
- else
- {
- cp[0] = codeunit_t(lead_offset + (usv >> 10));
- cp[1] = codeunit_t(0xDC00 + (usv & 0x3FF));
- l = 2;
- }
- }
-
- inline
- static uchar_t get(const codeunit_t * cp, int8 & l) throw()
- {
- const uint32 uh = cp[0];
- l = 1;
-
- if (0xD800 > uh || uh > 0xDFFF) { return uh; }
- const uint32 ul = cp[1];
- if (uh > 0xDBFF || 0xDC00 > ul || ul > 0xDFFF) { l = -1; return 0xFFFD; }
- ++l;
- return (uh<<10) + ul + surrogate_offset;
- }
-};
-
-
-template <>
-struct _utf_codec<8>
-{
-private:
- static const int8 sz_lut[16];
- static const byte mask_lut[5];
-
-
-public:
- typedef uint8 codeunit_t;
-
- inline
- static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
- {
- if (usv < 0x80) {l = 1; cp[0] = usv; return; }
- if (usv < 0x0800) {l = 2; cp[0] = 0xC0 + (usv >> 6); cp[1] = 0x80 + (usv & 0x3F); return; }
- if (usv < 0x10000) {l = 3; cp[0] = 0xE0 + (usv >> 12); cp[1] = 0x80 + ((usv >> 6) & 0x3F); cp[2] = 0x80 + (usv & 0x3F); return; }
- else {l = 4; cp[0] = 0xF0 + (usv >> 18); cp[1] = 0x80 + ((usv >> 12) & 0x3F); cp[2] = 0x80 + ((usv >> 6) & 0x3F); cp[3] = 0x80 + (usv & 0x3F); return; }
- }
-
- inline
- static uchar_t get(const codeunit_t * cp, int8 & l) throw()
- {
- const int8 seq_sz = sz_lut[*cp >> 4];
- uchar_t u = *cp & mask_lut[seq_sz];
- l = 1;
- bool toolong = false;
-
- switch(seq_sz) {
- case 4: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong = (u < 0x10); // no break
- case 3: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong |= (u < 0x20); // no break
- case 2: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong |= (u < 0x80); // no break
- case 1: break;
- case 0: l = -1; return 0xFFFD;
- }
-
- if (l != seq_sz || toolong)
- {
- l = -l;
- return 0xFFFD;
- }
- return u;
- }
-};
-
-
-template <typename C>
-class _utf_iterator
-{
- typedef _utf_codec<sizeof(C)*8> codec;
-
- C * cp;
- mutable int8 sl;
-
-public:
- typedef C codeunit_type;
- typedef uchar_t value_type;
- typedef uchar_t * pointer;
-
- class reference
- {
- const _utf_iterator & _i;
-
- reference(const _utf_iterator & i): _i(i) {}
- public:
- operator value_type () const throw () { return codec::get(_i.cp, _i.sl); }
- reference & operator = (const value_type usv) throw() { codec::put(_i.cp, usv, _i.sl); return *this; }
-
- friend class _utf_iterator;
- };
-
-
- _utf_iterator(const void * us=0) : cp(reinterpret_cast<C *>(const_cast<void *>(us))), sl(1) { }
-
- _utf_iterator & operator ++ () { cp += abs(sl); return *this; }
- _utf_iterator operator ++ (int) { _utf_iterator tmp(*this); operator++(); return tmp; }
-
- bool operator == (const _utf_iterator & rhs) const throw() { return cp >= rhs.cp; }
- bool operator != (const _utf_iterator & rhs) const throw() { return !operator==(rhs); }
-
- reference operator * () const throw() { return *this; }
- pointer operator ->() const throw() { return &operator *(); }
-
- operator codeunit_type * () const throw() { return cp; }
-
- bool error() const throw() { return sl < 1; }
-};
-
-template <typename C>
-struct utf
-{
- typedef typename _utf_codec<sizeof(C)*8>::codeunit_t codeunit_t;
-
- typedef _utf_iterator<C> iterator;
- typedef _utf_iterator<const C> const_iterator;
-};
-
-
-typedef utf<uint32> utf32;
-typedef utf<uint16> utf16;
-typedef utf<uint8> utf8;
-
-} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/json.h b/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/json.h
deleted file mode 100644
index 80ff5b5cbf8..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/json.h
+++ /dev/null
@@ -1,165 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-// JSON pretty printer for graphite font debug output logging.
-// Created on: 15 Dec 2011
-// Author: Tim Eves
-
-#pragma once
-#include "inc/Main.h"
-#include <cassert>
-#include <cstdio>
-
-namespace graphite2 {
-
-class json
-{
- // Prevent copying
- json(const json &);
- json & operator = (const json &);
-
- typedef void (*_context_t)(json &);
- class _null_t {};
-
- FILE * const _stream;
- char _contexts[128], // context stack
- * _context, // current context (top of stack)
- * _flatten; // if !0 points to context above which
- // pretty printed output should occur.
-
- void context(const char current) throw();
- void indent(const int d=0) throw();
- void push_context(const char, const char) throw();
- void pop_context() throw();
-
-public:
- class closer;
-
- typedef const char * string;
- typedef double number;
- typedef long signed int integer;
- typedef bool boolean;
- static const _null_t null;
-
- static void flat(json &) throw();
- static void close(json &) throw();
- static void object(json &) throw();
- static void array(json &) throw();
- static void item(json &) throw();
-
- json(FILE * stream) throw();
- ~json() throw ();
-
- FILE * stream() const throw();
-
- json & operator << (string) throw();
- json & operator << (number) throw();
- json & operator << (integer) throw();
- json & operator << (long unsigned int d) throw();
- json & operator << (boolean) throw();
- json & operator << (_null_t) throw();
- json & operator << (_context_t) throw();
-
- operator bool() const throw();
- bool good() const throw();
- bool eof() const throw();
-
- CLASS_NEW_DELETE;
-};
-
-class json::closer
-{
- // Prevent copying.
- closer(const closer &);
- closer & operator = (const closer &);
-
- json * const _j;
-public:
- closer(json * const j) : _j(j) {}
- ~closer() throw() { if (_j) *_j << close; }
-};
-
-inline
-json::json(FILE * s) throw()
-: _stream(s), _context(_contexts), _flatten(0)
-{
- if (good())
- fflush(s);
-}
-
-
-inline
-json::~json() throw ()
-{
- while (_context > _contexts) pop_context();
-}
-
-inline
-FILE * json::stream() const throw() { return _stream; }
-
-
-inline
-json & json::operator << (json::_context_t ctxt) throw()
-{
- ctxt(*this);
- return *this;
-}
-
-inline
-json & operator << (json & j, signed char d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, short signed int d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, signed int d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, unsigned char d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, short unsigned int d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, unsigned int d) throw() { return j << json::integer(d); }
-
-inline
-json & operator << (json & j, char c) throw ()
-{
- const char str[2] = {c,0};
- return j << str;
-}
-
-inline
-json::operator bool() const throw() { return good(); }
-
-inline
-bool json::good() const throw() { return _stream && ferror(_stream) == 0; }
-
-inline
-bool json::eof() const throw() { return feof(_stream) != 0; }
-
-} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/json.cpp b/Build/source/libs/graphite2/graphite2-1.2.3/src/json.cpp
deleted file mode 100644
index c10037f3afe..00000000000
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/json.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/* GRAPHITE2 LICENSING
-
- Copyright 2010, SIL International
- All rights reserved.
-
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should also have received a copy of the GNU Lesser General Public
- License along with this library in the file named "LICENSE".
- If not, write to the Free Software Foundation, 51 Franklin Street,
- Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
- internet at http://www.fsf.org/licenses/lgpl.html.
-
-Alternatively, the contents of this file may be used under the terms of the
-Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
-License, as published by the Free Software Foundation, either version 2
-of the License or (at your option) any later version.
-*/
-// JSON debug logging
-// Author: Tim Eves
-
-#if !defined GRAPHITE2_NTRACING
-
-#include <cstdio>
-#include "inc/json.h"
-
-using namespace graphite2;
-
-namespace
-{
- enum
- {
- seq = ',',
- obj='}', member=':', empty_obj='{',
- arr=']', empty_arr='['
- };
-}
-
-const json::_null_t json::null = {};
-
-inline
-void json::context(const char current) throw()
-{
- fprintf(_stream, "%c", *_context);
- indent();
- *_context = current;
-}
-
-
-void json::indent(const int d) throw()
-{
- if (*_context == member || (_flatten && _flatten < _context))
- fputc(' ', _stream);
- else
- fprintf(_stream, "\n%*s", 4*int(_context - _contexts + d), "");
-}
-
-
-inline
-void json::push_context(const char prefix, const char suffix) throw()
-{
- assert(_context - _contexts < ptrdiff_t(sizeof _contexts));
-
- if (_context == _contexts)
- *_context = suffix;
- else
- context(suffix);
- *++_context = prefix;
-}
-
-
-void json::pop_context() throw()
-{
- assert(_context > _contexts);
-
- if (*_context == seq) indent(-1);
- else fputc(*_context, _stream);
-
- fputc(*--_context, _stream);
- if (_context == _contexts) fputc('\n', _stream);
- fflush(_stream);
-
- if (_flatten >= _context) _flatten = 0;
- *_context = seq;
-}
-
-
-// These four functions cannot be inlined as pointers to these
-// functions are needed for operator << (_context_t) to work.
-void json::flat(json & j) throw() { if (!j._flatten) j._flatten = j._context; }
-void json::close(json & j) throw() { j.pop_context(); }
-void json::object(json & j) throw() { j.push_context('{', '}'); }
-void json::array(json & j) throw() { j.push_context('[', ']'); }
-void json::item(json & j) throw()
-{
- while (j._context > j._contexts+1 && j._context[-1] != arr)
- j.pop_context();
-}
-
-
-json & json::operator << (json::string s) throw()
-{
- const char ctxt = _context[-1] == obj ? *_context == member ? seq : member : seq;
- context(ctxt);
- fprintf(_stream, "\"%s\"", s);
- if (ctxt == member) fputc(' ', _stream);
-
- return *this;
-}
-
-json & json::operator << (json::number f) throw() { context(seq); fprintf(_stream, "%g", f); return *this; }
-json & json::operator << (json::integer d) throw() { context(seq); fprintf(_stream, "%ld", d); return *this; }
-json & json::operator << (long unsigned d) throw() { context(seq); fprintf(_stream, "%ld", d); return *this; }
-json & json::operator << (json::boolean b) throw() { context(seq); fputs(b ? "true" : "false", _stream); return *this; }
-json & json::operator << (json::_null_t) throw() { context(seq); fputs("null",_stream); return *this; }
-
-#endif
-
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/ChangeLog b/Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/ChangeLog
index e1374b4e172..8d3061edbaf 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/ChangeLog
+++ b/Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/ChangeLog
@@ -1,6 +1,11 @@
+2013-12-02 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Imported graphite2-1.2.4 source tree from:
+ http://sourceforge.net/projects/silgraphite/files/graphite2/
+
2013-06-12 Peter Breitenlohner <peb@mppmu.mpg.de>
- Imported graphite2-1.2.2 source tree from:
+ Imported graphite2-1.2.3 source tree from:
http://sourceforge.net/projects/silgraphite/files/graphite2/
2013-06-02 Peter Breitenlohner <peb@mppmu.mpg.de>
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/TL-Changes b/Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/TL-Changes
index a8f992013b8..1bc60f09413 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3-PATCHES/TL-Changes
+++ b/Build/source/libs/graphite2/graphite2-1.2.4-PATCHES/TL-Changes
@@ -1,4 +1,4 @@
-Changes applied to the graphite2-1.2.3/ tree as obtained from:
+Changes applied to the graphite2-1.2.4/ tree as obtained from:
http://sourceforge.net/projects/silgraphite/files/graphite2/
Removed unused dirs:
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/.hg_archival.txt b/Build/source/libs/graphite2/graphite2-1.2.4/.hg_archival.txt
new file mode 100644
index 00000000000..dc9ddb46d6c
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/.hg_archival.txt
@@ -0,0 +1,5 @@
+repo: 999e2033695c3bcf2f65d611737ac9008805bd58
+node: 1efd96aeade964b4d00b7b14e6158a74f0f6593e
+branch: default
+latesttag: 1.2.4
+latesttagdistance: 1
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/.hgeol b/Build/source/libs/graphite2/graphite2-1.2.4/.hgeol
index 5eb1fc19d0f..5eb1fc19d0f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/.hgeol
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/.hgeol
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/.hgignore b/Build/source/libs/graphite2/graphite2-1.2.4/.hgignore
index 5934da4b3c8..5934da4b3c8 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/.hgignore
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/.hgignore
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/.hgtags b/Build/source/libs/graphite2/graphite2-1.2.4/.hgtags
index 97a863999a4..5a66aa21918 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/.hgtags
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/.hgtags
@@ -27,3 +27,5 @@ d8c8ce7898a9e73a9cb11c25b9ff6a198fdf8d80 1.1.3
fb4b0c347a953f6aa656a4e414f8e42e91c00c2b 1.2.0
9ca2c8c1469f6107cd366e4be2035ce0dfa09b65 1.2.1
7b0a153b4873117ff726ac8c780f7bd994845285 1.2.2
+4605b74e26f3a119753b700524c49b98e7e45639 1.2.3
+89895200933d3b0ce799b2d230dd6840106750b1 1.2.4
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/CMakeLists.txt b/Build/source/libs/graphite2/graphite2-1.2.4/CMakeLists.txt
index 2bc3e0d55fe..b09e95f4456 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/CMakeLists.txt
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/CMakeLists.txt
@@ -8,7 +8,7 @@ if (NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release)
endif (NOT CMAKE_BUILD_TYPE)
#if (CMAKE_BUILD_TYPE STREQUAL ClangASN)
-# add_definitions(-faddress-sanitizer -fno-omit-frame-pointer)
+# add_definitions(-fsanitize=address -fno-omit-frame-pointer)
# set_property(CACHE CMAKE_C_COMPILER PROPERTY VALUE clang)
# set_property(CACHE CMAKE_CXX_COMPILER PROPERTY VALUE clang)
#endif (CMAKE_BUILD_TYPE STREQUAL ClangASN)
@@ -16,9 +16,6 @@ endif (NOT CMAKE_BUILD_TYPE)
enable_language(CXX C)
include_directories(${PROJECT_SOURCE_DIR}/include)
-if (CMAKE_BUILD_TYPE STREQUAL ClangASN)
- add_definitions(-faddress-sanitizer -fno-omit-frame-pointer)
-endif (CMAKE_BUILD_TYPE STREQUAL ClangASN)
enable_testing()
@@ -27,6 +24,7 @@ option(GRAPHITE2_NSEGCACHE "Compile out the gr_*_with_seg_cache APIs")
option(GRAPHITE2_NFILEFACE "Compile out the gr_make_file_face* APIs")
option(GRAPHITE2_NTRACING "Compile out log segment tracing capability")
option(GRAPHITE2_TELEMETRY "Add memory usage telemetry")
+option(GRAPHITE2_ASAN "Enable Address Sanitizing")
message(STATUS "Build: " ${CMAKE_BUILD_TYPE})
@@ -40,6 +38,13 @@ message(STATUS "Segment Cache support: " ${_SEGCACHE_SUPPORT})
message(STATUS "File Face support: " ${_FILEFACE_SUPPORT})
message(STATUS "Tracing support: " ${_TRACING_SUPPORT})
+if (GRAPHITE2_ASAN)
+ add_definitions(-fsanitize=address -fno-omit-frame-pointer -g)
+ find_program(ASAN_SYMBOLIZER llvm-symbolizer
+ PATHS "/usr/lib" "/usr/local/lib"
+ PATH_SUFFIXES "llvm-3.3/bin" "llvm-3.4/bin" "llvm-3.5/bin")
+endif (GRAPHITE2_ASAN)
+
string(TOLOWER ${GRAPHITE2_VM_TYPE} GRAPHITE2_VM_TYPE)
if (NOT GRAPHITE2_VM_TYPE MATCHES "auto|direct|call")
message(SEND_ERROR "unrecognised vm machine type: ${GRAPHITE2_VM_TYPE}. Only Auto, Direct or Call are available")
@@ -51,10 +56,10 @@ if (GRAPHITE2_VM_TYPE STREQUAL "auto")
set(GRAPHITE2_VM_TYPE "call")
endif(CMAKE_BUILD_TYPE MATCHES "[Rr]el(ease|[Ww]ith[Dd]eb[Ii]nfo)")
endif (GRAPHITE2_VM_TYPE STREQUAL "auto")
-if (GRAPHITE2_VM_TYPE STREQUAL "direct" AND NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_BASE_NAME STREQUAL "clang++"))
+if (GRAPHITE2_VM_TYPE STREQUAL "direct" AND NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
message(WARNING "vm machine type direct can only be built using GCC")
set(GRAPHITE2_VM_TYPE "call")
-endif (GRAPHITE2_VM_TYPE STREQUAL "direct" AND NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_BASE_NAME STREQUAL "clang++"))
+endif (GRAPHITE2_VM_TYPE STREQUAL "direct" AND NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
message(STATUS "Using vm machine type: ${GRAPHITE2_VM_TYPE}")
add_subdirectory(src)
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/COPYING b/Build/source/libs/graphite2/graphite2-1.2.4/COPYING
index d40f2d84587..d40f2d84587 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/COPYING
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/COPYING
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/ChangeLog b/Build/source/libs/graphite2/graphite2-1.2.4/ChangeLog
index 1ba1b18ce4c..f0e88d60a23 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/ChangeLog
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/ChangeLog
@@ -1,3 +1,22 @@
+1.2.4
+ . Face failure now has error code reporting via debug logging
+ . can now call gr_start_logging(NULL, fname)
+ . gr2fonttest --alltrace added
+ . Format 14 table support
+ . Not done. To be handled entirely in the compiler
+ . Bidi support for Unicode 6.3 Isolating direction controls
+ . Fonts no longer require a glyf/loca table. In such cases the bounding box is always 0.
+ . Clang ASAN build support added for testing.
+ . Handle out of memory sanely.
+ . Dcoumentation improvements
+ . Bug fixes:
+ . Enforce fonts having to store glyph attributes by monotonically increasing attribute number
+ . zeropadding was not getting called on feature tags
+ . automatic associations for unassociated characters
+ . use direct engine on Mac
+ . various extreme case reading 1 past the end errors fixed
+ . remove tabs from sources so that it becomes readable again
+
1.2.3
. Bug fixes only:
. fix byte swapping when testing cmap subtable lengths
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/Graphite.cmake b/Build/source/libs/graphite2/graphite2-1.2.4/Graphite.cmake
index 54f765aded7..1fd3a4e6888 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/Graphite.cmake
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/Graphite.cmake
@@ -80,6 +80,9 @@ function(fonttest TESTNAME FONTFILE)
if (NOT (GRAPHITE2_NSEGCACHE OR GRAPHITE2_NFILEFACE))
add_test(NAME ${TESTNAME} COMMAND $<TARGET_FILE:gr2fonttest> -trace ${PROJECT_BINARY_DIR}/${TESTNAME}.json -log ${PROJECT_BINARY_DIR}/${TESTNAME}.log ${PROJECT_SOURCE_DIR}/fonts/${FONTFILE} -codes ${ARGN})
set_tests_properties(${TESTNAME} PROPERTIES TIMEOUT 3)
+ if (GRAPHITE2_ASAN)
+ set_property(TEST ${TESTNAME} APPEND PROPERTY ENVIRONMENT "ASAN_SYMBOLIZER_PATH=${ASAN_SYMBOLIZER}")
+ endif (GRAPHITE2_ASAN)
add_test(NAME ${TESTNAME}Output COMMAND ${CMAKE_COMMAND} -E compare_files ${PROJECT_BINARY_DIR}/${TESTNAME}.log ${PROJECT_SOURCE_DIR}/standards/${TESTNAME}${PLATFORM_TEST_SUFFIX}.log)
if (NOT GRAPHITE2_NTRACING)
add_test(NAME ${TESTNAME}Debug COMMAND python ${PROJECT_SOURCE_DIR}/jsoncmp ${PROJECT_BINARY_DIR}/${TESTNAME}.json ${PROJECT_SOURCE_DIR}/standards/${TESTNAME}.json)
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/LICENSE b/Build/source/libs/graphite2/graphite2-1.2.4/LICENSE
index 2d2d780e601..2d2d780e601 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/LICENSE
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/LICENSE
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/Todo.txt b/Build/source/libs/graphite2/graphite2-1.2.4/Todo.txt
new file mode 100644
index 00000000000..de9d36157e8
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/Todo.txt
@@ -0,0 +1,3 @@
+Expected changes to come:
+
+* None
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/graphite2.pc.in b/Build/source/libs/graphite2/graphite2-1.2.4/graphite2.pc.in
index a4f19b39ce4..a4f19b39ce4 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/graphite2.pc.in
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/graphite2.pc.in
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Font.h b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Font.h
index 85ee73d9126..72e8461eafb 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Font.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Font.h
@@ -30,7 +30,7 @@
#define GR2_VERSION_MAJOR 1
#define GR2_VERSION_MINOR 2
-#define GR2_VERSION_BUGFIX 3
+#define GR2_VERSION_BUGFIX 4
#ifdef __cplusplus
extern "C"
@@ -296,7 +296,7 @@ typedef struct gr_font_ops gr_font_ops;
* @param appFontHandle font specific information that must stay alive as long
* as the font does
* @param font_ops pointer font specific callback structure for hinted metrics.
- * Must stay alive for the duration of the call.
+ * Need only stay alive for the duration of the call.
* @param face the face this font corresponds to. Must stay alive as long as
* the font does.
*/
@@ -310,7 +310,6 @@ GR2_API gr_font* gr_make_font_with_ops(float ppm, const void* appFontHandle, con
* @param appFontHandle font specific information that must stay alive as long
* as the font does
* @param getAdvance callback function reference that returns horizontal advance in pixels for a glyph.
- * Must stay alive for the duration of the call.
* @param face the face this font corresponds to. Must stay alive as long as
* the font does.
*/
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Log.h b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Log.h
index d1c6f0fe36f..d1c6f0fe36f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Log.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Log.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Segment.h b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Segment.h
index 580f83763f9..c89df5e8811 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Segment.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Segment.h
@@ -125,6 +125,8 @@ enum gr_attrCode {
gr_slatSegSplit = gr_slatJStretch + 29,
/// User defined attribute, see subattr for user attr number
gr_slatUserDefn,
+ /// Bidi level
+ gr_slatBidiLevel,
/// not implemented
gr_slatMax,
@@ -327,8 +329,8 @@ GR2_API const gr_slot* gr_slot_first_attachment(const gr_slot* p);
*
* This returns the next slot in the singly linked list of slots attached to this
* slot's parent. If there are no more such slots, NULL is returned. If there is
- * no parent, i.e. the passed slot is a base, then the next base in graphical order
- * (ltr even for rtl text) is returned.
+ * no parent, i.e. the passed slot is a cluster base, then the next cluster base
+ * in graphical order (ltr, even for rtl text) is returned.
*
* if gr_slot_next_sibling_attachment(p) != NULL then gr_slot_attached_to(gr_slot_next_sibling_attachment(p)) == gr_slot_attached_to(p).
*/
@@ -398,7 +400,13 @@ GR2_API unsigned int gr_slot_index(const gr_slot* p/*not NULL*/);
*/
GR2_API int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, enum gr_attrCode index, gr_uint8 subindex); //tbd - do we need to expose this?
-/** Returns whether text may be inserted before this glyph [check this isn't inverted] **/
+/** Returns whether text may be inserted before this glyph.
+ *
+ * This indicates whether a cursor can be put before this slot. It applies to
+ * base glyphs that have no parent as well as attached glyphs that have the
+ * .insert attribute explicitly set to true. This is the primary mechanism
+ * for identifying contiguous sequences of base plus diacritics.
+ */
GR2_API int gr_slot_can_insert_before(const gr_slot* p);
/** Returns the original gr_char_info index this slot refers to.
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Types.h b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Types.h
index 268bee7a975..268bee7a975 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/include/graphite2/Types.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/include/graphite2/Types.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/Bidi.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Bidi.cpp
new file mode 100644
index 00000000000..530f51abc1d
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Bidi.cpp
@@ -0,0 +1,823 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#include "inc/Main.h"
+#include "inc/Slot.h"
+#include "inc/Segment.h"
+#include "inc/Bidi.h"
+
+using namespace graphite2;
+
+enum DirCode { // Hungarian: dirc
+ Unk = -1,
+ N = 0, // other neutrals (default) - ON
+ L = 1, // left-to-right, strong - L
+ R = 2, // right-to-left, strong - R
+ AL = 3, // Arabic letter, right-to-left, strong, AR
+ EN = 4, // European number, left-to-right, weak - EN
+ EUS = 5, // European separator, left-to-right, weak - ES
+ ET = 6, // European number terminator, left-to-right, weak - ET
+ AN = 7, // Arabic number, left-to-right, weak - AN
+ CUS = 8, // Common number separator, left-to-right, weak - CS
+ WS = 9, // white space, neutral - WS
+ BN = 10, // boundary neutral - BN
+
+ LRO = 11, // LTR override
+ RLO = 12, // RTL override
+ LRE = 13, // LTR embedding
+ RLE = 14, // RTL embedding
+ PDF = 15, // pop directional format
+ NSM = 16, // non-space mark
+ LRI = 17, // LRI isolate
+ RLI = 18, // RLI isolate
+ FSI = 19, // FSI isolate
+ PDI = 20, // pop isolate
+ OPP = 21, // opening paired parenthesis
+ CPP = 22, // closing paired parenthesis
+
+ ON = N
+};
+
+enum DirMask {
+ WSflag = (1 << 7), // keep track of WS for eos handling
+ WSMask = ~(1 << 7)
+};
+
+inline uint8 BaseClass(Slot *s) { return s->getBidiClass() & WSMask; }
+
+unsigned int bidi_class_map[] = { 0, 1, 2, 5, 4, 8, 9, 3, 7, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0 };
+// Algorithms based on Unicode reference standard code. Thanks Asmus Freitag.
+
+void resolveWeak(Slot *start, int sos, int eos);
+void resolveNeutrals(Slot *s, int baseLevel, int sos, int eos);
+void processParens(Slot *s, Segment *seg, uint8 aMirror, int level, BracketPairStack &stack);
+
+inline int calc_base_level(Slot *s)
+{
+ int count = 0;
+ for ( ; s; s = s->next())
+ {
+ int cls = s->getBidiClass();
+ if (count)
+ {
+ switch(cls)
+ {
+ case LRI :
+ case RLI :
+ case FSI :
+ ++count;
+ break;
+ case PDI :
+ --count;
+ }
+ }
+ else
+ {
+ switch(cls)
+ {
+ case L :
+ return 0;
+ case R :
+ case AL :
+ return 1;
+ case LRI :
+ case RLI :
+ case FSI :
+ ++count;
+ }
+ }
+ }
+ return 0;
+}
+
+// inline or not?
+void do_resolves(Slot *start, int level, int sos, int eos, int &bmask, Segment *seg, uint8 aMirror, BracketPairStack &stack)
+{
+ if (bmask & 0x1F1178)
+ resolveWeak(start, sos, eos);
+ if (bmask & 0x200000)
+ processParens(start, seg, aMirror, level, stack);
+ if (bmask & 0x7E0361)
+ resolveNeutrals(start, level, sos, eos);
+ bmask = 0;
+}
+
+enum maxs
+{
+ MAX_LEVEL = 125,
+};
+
+// returns where we are up to in processing
+Slot *process_bidi(Slot *start, int level, int prelevel, int &nextLevel, int dirover, int isol, int &cisol, int &isolerr, int &embederr, int init, Segment *seg, uint8 aMirror, BracketPairStack &bstack)
+{
+ int bmask = 0;
+ Slot *s = start;
+ Slot *slast = start;
+ Slot *scurr = 0;
+ Slot *stemp;
+ int lnextLevel = nextLevel;
+ int newLevel;
+ int empty = 1;
+ for ( ; s; s = s ? s->next() : s)
+ {
+ int cls = s->getBidiClass();
+ bmask |= (1 << cls);
+ s->setBidiLevel(level);
+ // we keep s->prev() pointing backwards for PDI repeating
+
+ switch (cls)
+ {
+ case BN :
+ if (slast == s) slast = s->next(); // ignore if at front of text
+ continue;
+ case LRE :
+ case LRO :
+ case RLE :
+ case RLO :
+ switch (cls)
+ {
+ case LRE :
+ case LRO :
+ newLevel = level + (level & 1 ? 1 : 2);
+ break;
+ case RLE :
+ case RLO :
+ newLevel = level + (level & 1 ? 2 : 1);
+ break;
+ }
+ s->setBidiClass(BN);
+ if (isolerr || newLevel > MAX_LEVEL || embederr)
+ {
+ if (!isolerr) ++embederr;
+ break;
+ }
+ stemp = scurr;
+ if (scurr)
+ scurr->prev(0); // don't include control in string
+ lnextLevel = newLevel;
+ scurr = s;
+ s->setBidiLevel(newLevel); // to make it vanish
+ // recurse for the new subsequence. A sequence only contains text at the same level
+ s = process_bidi(s->next(), newLevel, level, lnextLevel, cls < LRE, 0, cisol, isolerr, embederr, 0, seg, aMirror, bstack);
+ // s points at PDF or end of sequence
+ // try to keep extending the run and not process it until we have to
+ if (lnextLevel != level || !s) // if the subsequence really had something in it, or we are at the end of the run
+ {
+ if (slast != scurr) // process the run now, don't try to extend it
+ {
+ // process text preceeding embedding
+ do_resolves(slast, level, (prelevel > level ? prelevel : level) & 1, lnextLevel & 1, bmask, seg, aMirror, bstack);
+ empty = 0;
+ nextLevel = level;
+ }
+ else if (lnextLevel != level) // the subsequence had something
+ {
+ empty = 0; // so we aren't empty either
+ nextLevel = lnextLevel; // but since we really are empty, pass back our level from the subsequence
+ }
+ if (s) // if still more to process
+ {
+ prelevel = lnextLevel; // future text starts out with sos of the higher subsequence
+ lnextLevel = level; // and eos is our level
+ }
+ slast = s ? s->next() : s;
+ }
+ else if (stemp)
+ stemp->prev(s);
+ break;
+
+ case PDF :
+ s->setBidiClass(BN);
+ s->prev(0); // unstitch us since we skip final stitching code when we return
+ if (isol || isolerr || init) // boundary error conditions
+ break;
+ if (embederr)
+ {
+ --embederr;
+ break;
+ }
+ if (slast != s)
+ {
+ scurr->prev(0); // if slast, then scurr. Terminate before here
+ do_resolves(slast, level, level & 1, level & 1, bmask, seg, aMirror, bstack);
+ empty = 0;
+ }
+ if (empty)
+ {
+ nextLevel = prelevel; // no contents? set our level to that of parent
+ s->setBidiLevel(prelevel);
+ }
+ return s;
+
+ case FSI :
+ case LRI :
+ case RLI :
+ switch (cls)
+ {
+ case FSI :
+ if (calc_base_level(s->next()))
+ newLevel = level + (level & 1 ? 2 : 1);
+ else
+ newLevel = level + (level & 1 ? 1 : 2);
+ break;
+ case LRI :
+ newLevel = level + (level & 1 ? 1 : 2);
+ break;
+ case RLI :
+ newLevel = level + (level & 1 ? 2 : 1);
+ break;
+ }
+ if (newLevel > MAX_LEVEL || isolerr)
+ {
+ ++isolerr;
+ s->setBidiClass(ON | WSflag);
+ break;
+ }
+ ++cisol;
+ if (scurr) scurr->prev(s);
+ scurr = s; // include FSI
+ lnextLevel = newLevel;
+ // recurse for the new sub sequence
+ s = process_bidi(s->next(), newLevel, newLevel, lnextLevel, 0, 1, cisol, isolerr, embederr, 0, seg, aMirror, bstack);
+ // s points at PDI
+ if (s)
+ {
+ bmask |= 1 << BaseClass(s); // include the PDI in the mask
+ s->setBidiLevel(level); // reset its level to our level
+ }
+ lnextLevel = level;
+ break;
+
+ case PDI :
+ if (isolerr)
+ {
+ --isolerr;
+ s->setBidiClass(ON | WSflag);
+ break;
+ }
+ if (init || !cisol)
+ {
+ s->setBidiClass(ON | WSflag);
+ break;
+ }
+ embederr = 0;
+ if (!isol) // we are in an embedded subsequence, we have to return through all those
+ {
+ if (empty) // if empty, reset the level to tell embedded parent
+ nextLevel = prelevel;
+ return s->prev(); // keep working up the stack pointing at this PDI until we get to an isolate entry
+ }
+ else // we are terminating an isolate sequence
+ {
+ if (slast != s) // process any remaining content in this subseqence
+ {
+ scurr->prev(0);
+ do_resolves(slast, level, prelevel & 1, level & 1, bmask, seg, aMirror, bstack);
+ }
+ --cisol; // pop the isol sequence from the stack
+ return s;
+ }
+
+ default :
+ if (dirover)
+ s->setBidiClass((level & 1 ? R : L) | (WSflag * (cls == WS)));
+ }
+ if (s) s->prev(0); // unstitch us
+ if (scurr) // stitch in text for processing
+ scurr->prev(s);
+ scurr = s; // add us to text to process
+ }
+ if (slast != s)
+ {
+ do_resolves(slast, level, (level > prelevel ? level : prelevel) & 1, lnextLevel & 1, bmask, seg, aMirror, bstack);
+ empty = 0;
+ }
+ if (empty || isol)
+ nextLevel = prelevel;
+ return s;
+}
+
+// === RESOLVE WEAK TYPES ================================================
+
+enum bidi_state // possible states
+{
+ xa, // arabic letter
+ xr, // right leter
+ xl, // left letter
+
+ ao, // arabic lett. foll by ON
+ ro, // right lett. foll by ON
+ lo, // left lett. foll by ON
+
+ rt, // ET following R
+ lt, // ET following L
+
+ cn, // EN, AN following AL
+ ra, // arabic number foll R
+ re, // european number foll R
+ la, // arabic number foll L
+ le, // european number foll L
+
+ ac, // CS following cn
+ rc, // CS following ra
+ rs, // CS,ES following re
+ lc, // CS following la
+ ls, // CS,ES following le
+
+ ret, // ET following re
+ let, // ET following le
+} ;
+
+const bidi_state stateWeak[][10] =
+{
+ // N, L, R, AN, EN, AL,NSM, CS, ES, ET,
+{ /*xa*/ ao, xl, xr, cn, cn, xa, xa, ao, ao, ao, /* arabic letter */ },
+{ /*xr*/ ro, xl, xr, ra, re, xa, xr, ro, ro, rt, /* right letter */ },
+{ /*xl*/ lo, xl, xr, la, le, xa, xl, lo, lo, lt, /* left letter */ },
+
+{ /*ao*/ ao, xl, xr, cn, cn, xa, ao, ao, ao, ao, /* arabic lett. foll by ON*/ },
+{ /*ro*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* right lett. foll by ON */ },
+{ /*lo*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* left lett. foll by ON */ },
+
+{ /*rt*/ ro, xl, xr, ra, re, xa, rt, ro, ro, rt, /* ET following R */ },
+{ /*lt*/ lo, xl, xr, la, le, xa, lt, lo, lo, lt, /* ET following L */ },
+
+{ /*cn*/ ao, xl, xr, cn, cn, xa, cn, ac, ao, ao, /* EN, AN following AL */ },
+{ /*ra*/ ro, xl, xr, ra, re, xa, ra, rc, ro, rt, /* arabic number foll R */ },
+{ /*re*/ ro, xl, xr, ra, re, xa, re, rs, rs,ret, /* european number foll R */ },
+{ /*la*/ lo, xl, xr, la, le, xa, la, lc, lo, lt, /* arabic number foll L */ },
+{ /*le*/ lo, xl, xr, la, le, xa, le, ls, ls,let, /* european number foll L */ },
+
+{ /*ac*/ ao, xl, xr, cn, cn, xa, ao, ao, ao, ao, /* CS following cn */ },
+{ /*rc*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* CS following ra */ },
+{ /*rs*/ ro, xl, xr, ra, re, xa, ro, ro, ro, rt, /* CS,ES following re */ },
+{ /*lc*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* CS following la */ },
+{ /*ls*/ lo, xl, xr, la, le, xa, lo, lo, lo, lt, /* CS,ES following le */ },
+
+{ /*ret*/ ro, xl, xr, ra, re, xa,ret, ro, ro,ret, /* ET following re */ },
+{ /*let*/ lo, xl, xr, la, le, xa,let, lo, lo,let, /* ET following le */ },
+
+
+};
+
+enum bidi_action // possible actions
+{
+ // primitives
+ IX = 0x100, // increment
+ XX = 0xF, // no-op
+
+ // actions
+ xxx = (XX << 4) + XX, // no-op
+ xIx = IX + xxx, // increment run
+ xxN = (XX << 4) + ON, // set current to N
+ xxE = (XX << 4) + EN, // set current to EN
+ xxA = (XX << 4) + AN, // set current to AN
+ xxR = (XX << 4) + R, // set current to R
+ xxL = (XX << 4) + L, // set current to L
+ Nxx = (ON << 4) + 0xF, // set run to neutral
+ Axx = (AN << 4) + 0xF, // set run to AN
+ ExE = (EN << 4) + EN, // set run to EN, set current to EN
+ NIx = (ON << 4) + 0xF + IX, // set run to N, increment
+ NxN = (ON << 4) + ON, // set run to N, set current to N
+ NxR = (ON << 4) + R, // set run to N, set current to R
+ NxE = (ON << 4) + EN, // set run to N, set current to EN
+
+ AxA = (AN << 4) + AN, // set run to AN, set current to AN
+ NxL = (ON << 4) + L, // set run to N, set current to L
+ LxL = (L << 4) + L, // set run to L, set current to L
+};
+
+
+const bidi_action actionWeak[][10] =
+{
+ // N,.. L, R, AN, EN, AL, NSM, CS,..ES, ET,
+{ /*xa*/ xxx, xxx, xxx, xxx, xxA, xxR, xxR, xxN, xxN, xxN, /* arabic letter */ },
+{ /*xr*/ xxx, xxx, xxx, xxx, xxE, xxR, xxR, xxN, xxN, xIx, /* right leter */ },
+{ /*xl*/ xxx, xxx, xxx, xxx, xxL, xxR, xxL, xxN, xxN, xIx, /* left letter */ },
+
+{ /*ao*/ xxx, xxx, xxx, xxx, xxA, xxR, xxN, xxN, xxN, xxN, /* arabic lett. foll by ON */ },
+{ /*ro*/ xxx, xxx, xxx, xxx, xxE, xxR, xxN, xxN, xxN, xIx, /* right lett. foll by ON */ },
+{ /*lo*/ xxx, xxx, xxx, xxx, xxL, xxR, xxN, xxN, xxN, xIx, /* left lett. foll by ON */ },
+
+{ /*rt*/ Nxx, Nxx, Nxx, Nxx, ExE, NxR, xIx, NxN, NxN, xIx, /* ET following R */ },
+{ /*lt*/ Nxx, Nxx, Nxx, Nxx, LxL, NxR, xIx, NxN, NxN, xIx, /* ET following L */ },
+
+{ /*cn*/ xxx, xxx, xxx, xxx, xxA, xxR, xxA, xIx, xxN, xxN, /* EN, AN following AL */ },
+{ /*ra*/ xxx, xxx, xxx, xxx, xxE, xxR, xxA, xIx, xxN, xIx, /* arabic number foll R */ },
+{ /*re*/ xxx, xxx, xxx, xxx, xxE, xxR, xxE, xIx, xIx, xxE, /* european number foll R */ },
+{ /*la*/ xxx, xxx, xxx, xxx, xxL, xxR, xxA, xIx, xxN, xIx, /* arabic number foll L */ },
+{ /*le*/ xxx, xxx, xxx, xxx, xxL, xxR, xxL, xIx, xIx, xxL, /* european number foll L */ },
+
+{ /*ac*/ Nxx, Nxx, Nxx, Axx, AxA, NxR, NxN, NxN, NxN, NxN, /* CS following cn */ },
+{ /*rc*/ Nxx, Nxx, Nxx, Axx, NxE, NxR, NxN, NxN, NxN, NIx, /* CS following ra */ },
+{ /*rs*/ Nxx, Nxx, Nxx, Nxx, ExE, NxR, NxN, NxN, NxN, NIx, /* CS,ES following re */ },
+{ /*lc*/ Nxx, Nxx, Nxx, Axx, NxL, NxR, NxN, NxN, NxN, NIx, /* CS following la */ },
+{ /*ls*/ Nxx, Nxx, Nxx, Nxx, LxL, NxR, NxN, NxN, NxN, NIx, /* CS,ES following le */ },
+
+{ /*ret*/xxx, xxx, xxx, xxx, xxE, xxR, xxE, xxN, xxN, xxE, /* ET following re */ },
+{ /*let*/xxx, xxx, xxx, xxx, xxL, xxR, xxL, xxN, xxN, xxL, /* ET following le */ },
+};
+
+inline uint8 GetDeferredType(bidi_action a) { return (a >> 4) & 0xF; }
+inline uint8 GetResolvedType(bidi_action a) { return a & 0xF; }
+inline DirCode EmbeddingDirection(int l) { return l & 1 ? R : L; }
+
+// Neutrals
+enum neutral_action
+{
+ // action to resolve previous input
+ nL = L, // resolve EN to L
+ En = 3 << 4, // resolve neutrals run to embedding level direction
+ Rn = R << 4, // resolve neutrals run to strong right
+ Ln = L << 4, // resolved neutrals run to strong left
+ In = (1<<8), // increment count of deferred neutrals
+ LnL = (1<<4)+L, // set run and EN to L
+};
+
+// ->prev() here means ->next()
+void SetDeferredRunClass(Slot *s, Slot *sRun, int nval)
+{
+ if (!sRun || s == sRun) return;
+ for (Slot *p = sRun; p != s; p = p->prev())
+ if (p->getBidiClass() == WS) p->setBidiClass(nval | WSflag);
+ else if (BaseClass(p) != BN) p->setBidiClass(nval | (p->getBidiClass() & WSflag));
+}
+
+void SetThisDeferredRunClass(Slot *s, Slot *sRun, int nval)
+{
+ if (!sRun) return;
+ for (Slot *p = sRun, *e = s->prev(); p != e; p = p->prev())
+ if (p->getBidiClass() == WS) p->setBidiClass(nval | WSflag);
+ else if (BaseClass(p) != BN) p->setBidiClass(nval | (p->getBidiClass() & WSflag));
+}
+
+void resolveWeak(Slot *start, int sos, int eos)
+{
+ int state = (sos & 1) ? xr : xl;
+ int cls;
+ Slot *s = start;
+ Slot *sRun = NULL;
+ Slot *sLast = s;
+
+ for ( ; s; s = s->prev())
+ {
+ sLast = s;
+ cls = BaseClass(s);
+ switch (cls)
+ {
+ case BN :
+ if (s == start) start = s->prev(); // skip initial BNs for NSM resolving
+ continue;
+ case LRI :
+ case RLI :
+ case FSI :
+ case PDI :
+ {
+ Slot *snext = s->prev();
+ if (snext && snext->getBidiClass() == NSM)
+ snext->setBidiClass(ON);
+ s->setBidiClass(ON | WSflag);
+ }
+ break;
+
+ case NSM :
+ if (s == start)
+ {
+ cls = EmbeddingDirection(sos);
+ s->setBidiClass(cls);
+ }
+ break;
+ }
+
+ bidi_action action = actionWeak[state][bidi_class_map[cls]];
+ int clsRun = GetDeferredType(action);
+ if (clsRun != XX)
+ {
+ SetDeferredRunClass(s, sRun, clsRun);
+ sRun = NULL;
+ }
+ int clsNew = GetResolvedType(action);
+ if (clsNew != XX)
+ s->setBidiClass(clsNew);
+ if (!sRun && (IX & action))
+ sRun = s;
+ state = stateWeak[state][bidi_class_map[cls]];
+ }
+
+ cls = EmbeddingDirection(eos);
+ int clsRun = GetDeferredType(actionWeak[state][bidi_class_map[cls]]);
+ if (clsRun != XX)
+ SetThisDeferredRunClass(sLast, sRun, clsRun);
+}
+
+void processParens(Slot *s, Segment *seg, uint8 aMirror, int level, BracketPairStack &stack)
+{
+ uint8 mask = 0;
+ int8 lastDir = -1;
+ BracketPair *p;
+ for ( ; s; s = s->prev()) // walk the sequence
+ {
+ uint16 ogid = seg->glyphAttr(s->gid(), aMirror);
+ int cls = BaseClass(s);
+
+ switch(cls)
+ {
+ case OPP :
+ stack.orin(mask);
+ stack.push(ogid, s, lastDir, lastDir != CPP);
+ mask = 0;
+ lastDir = OPP;
+ break;
+ case CPP :
+ stack.orin(mask);
+ p = stack.scan(s->gid());
+ if (!p) break;
+ mask = 0;
+ stack.close(p, s);
+ lastDir = CPP;
+ break;
+ case L :
+ lastDir = L;
+ mask |= 1;
+ break;
+ case R :
+ case AL :
+ case AN :
+ case EN :
+ lastDir = R;
+ mask |= 2;
+ }
+ }
+ for (p = stack.start(); p; p =p->next()) // walk the stack
+ {
+ if (p->close() && p->mask())
+ {
+ int dir = (level & 1) + 1;
+ if (p->mask() & dir)
+ { }
+ else if (p->mask() & (1 << (~level & 1))) // if inside has strong other embedding
+ {
+ int ldir = p->before();
+ if ((p->before() == OPP || p->before() == CPP) && p->prev())
+ {
+ for (BracketPair *q = p->prev(); q; q = q->prev())
+ {
+ ldir = q->open()->getBidiClass();
+ if (ldir < 3) break;
+ ldir = q->before();
+ if (ldir < 3) break;
+ }
+ if (ldir > 2) ldir = 0;
+ }
+ if (ldir > 0 && (ldir - 1) != (level & 1)) // is dir given opp. to level dir (ldir == R or L)
+ dir = (~level & 1) + 1;
+ }
+ p->open()->setBidiClass(dir);
+ p->close()->setBidiClass(dir);
+ }
+ }
+ stack.clear();
+}
+
+int GetDeferredNeutrals(int action, int level)
+{
+ action = (action >> 4) & 0xF;
+ if (action == (En >> 4))
+ return EmbeddingDirection(level);
+ else
+ return action;
+}
+
+int GetResolvedNeutrals(int action)
+{
+ return action & 0xF;
+}
+
+// state values
+enum neutral_state
+{
+ // new temporary class
+ r, // R and characters resolved to R
+ l, // L and characters resolved to L
+ rn, // N preceded by right
+ ln, // N preceded by left
+ a, // AN preceded by left (the abbrev 'la' is used up above)
+ na, // N preceeded by a
+} ;
+
+const uint8 neutral_class_map[] = { 0, 1, 2, 0, 4, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+const int actionNeutrals[][5] =
+{
+// cls= N, L, R, AN, EN, state =
+{ In, 0, 0, 0, 0, }, // r right
+{ In, 0, 0, 0, L, }, // l left
+
+{ In, En, Rn, Rn, Rn, }, // rn N preceded by right
+{ In, Ln, En, En, LnL, }, // ln N preceded by left
+
+{ In, 0, 0, 0, L, }, // a AN preceded by left
+{ In, En, Rn, Rn, En, }, // na N preceded by a
+} ;
+
+const int stateNeutrals[][5] =
+{
+// cls= N, L, R, AN, EN state =
+{ rn, l, r, r, r, }, // r right
+{ ln, l, r, a, l, }, // l left
+
+{ rn, l, r, r, r, }, // rn N preceded by right
+{ ln, l, r, a, l, }, // ln N preceded by left
+
+{ na, l, r, a, l, }, // a AN preceded by left
+{ na, l, r, a, l, }, // na N preceded by la
+} ;
+
+void resolveNeutrals(Slot *s, int baseLevel, int sos, int eos)
+{
+ int state = (sos & 1) ? r : l;
+ int cls;
+ Slot *sRun = NULL;
+ Slot *sLast = s;
+ int level = baseLevel;
+
+ for ( ; s; s = s->prev())
+ {
+ sLast = s;
+ cls = BaseClass(s);
+ switch (cls)
+ {
+ case BN :
+ continue;
+ case LRI :
+ case RLI :
+ case FSI :
+ s->setBidiClass(BN | WSflag);
+ continue;
+
+ default :
+ int action = actionNeutrals[state][neutral_class_map[cls]];
+ int clsRun = GetDeferredNeutrals(action, level);
+ if (clsRun != N)
+ {
+ SetDeferredRunClass(s, sRun, clsRun);
+ sRun = NULL;
+ }
+ int clsNew = GetResolvedNeutrals(action);
+ if (clsNew != N)
+ s->setBidiClass(clsNew);
+ if (!sRun && (action & In))
+ sRun = s;
+ state = stateNeutrals[state][neutral_class_map[cls]];
+ }
+ }
+ cls = EmbeddingDirection(eos);
+ int clsRun = GetDeferredNeutrals(actionNeutrals[state][neutral_class_map[cls]], level);
+ if (clsRun != N)
+ SetThisDeferredRunClass(sLast, sRun, clsRun);
+}
+
+const int addLevel[][4] =
+{
+ // cls = L, R, AN, EN level =
+/* even */ { 0, 1, 2, 2, }, // EVEN
+/* odd */ { 1, 0, 1, 1, }, // ODD
+
+};
+
+void resolveImplicit(Slot *s, Segment *seg, uint8 aMirror)
+{
+ bool rtl = seg->dir() & 1;
+ int level = rtl;
+ Slot *slast = 0;
+ for ( ; s; s = s->next())
+ {
+ int cls = BaseClass(s);
+ s->prev(slast); // restitch the prev() side of the doubly linked list
+ slast = s;
+ if (cls == AN)
+ cls = AL; // use AL value as the index for AN, no property change
+ if (cls < 5 && cls > 0)
+ {
+ level = s->getBidiLevel();
+ level += addLevel[level & 1][cls - 1];
+ s->setBidiLevel(level);
+ }
+ if (aMirror)
+ {
+ int hasChar = seg->glyphAttr(s->gid(), aMirror + 1);
+ if ( ((level & 1) && (!(seg->dir() & 4) || !hasChar))
+ || ((rtl ^ (level & 1)) && (seg->dir() & 4) && hasChar) )
+ {
+ unsigned short g = seg->glyphAttr(s->gid(), aMirror);
+ if (g) s->setGlyph(seg, g);
+ }
+ }
+ }
+}
+
+void resolveWhitespace(int baseLevel, Slot *s)
+{
+ for ( ; s; s = s->prev())
+ {
+ int8 cls = s->getBidiClass();
+ if (cls == WS || cls & WSflag)
+ s->setBidiLevel(baseLevel);
+ else if (cls != BN)
+ break;
+ }
+}
+
+
+/*
+Stitch two spans together to make another span (with ends tied together).
+If the level is odd then swap the order of the two spans
+*/
+inline
+Slot * join(int level, Slot * a, Slot * b)
+{
+ if (!a) return b;
+ if (level & 1) { Slot * const t = a; a = b; b = t; }
+ Slot * const t = b->prev();
+ a->prev()->next(b); b->prev(a->prev()); // splice middle
+ t->next(a); a->prev(t); // splice ends
+ return a;
+}
+
+/*
+Given the first slot in a run of slots with the same bidi level, turn the run
+into it's own little doubly linked list ring (a span) with the two ends joined together.
+If the run is rtl then reverse its direction.
+Returns the first slot after the span
+*/
+Slot * span(Slot * & cs, const bool rtl)
+{
+ Slot * r = cs, * re = cs; cs = cs->next();
+ if (rtl)
+ {
+ Slot * t = r->next(); r->next(r->prev()); r->prev(t);
+ for (int l = r->getBidiLevel(); cs && (l == cs->getBidiLevel() || cs->getBidiClass() == BN); cs = cs->prev())
+ {
+ re = cs;
+ t = cs->next(); cs->next(cs->prev()); cs->prev(t);
+ }
+ r->next(re);
+ re->prev(r);
+ r = re;
+ }
+ else
+ {
+ for (int l = r->getBidiLevel(); cs && (l == cs->getBidiLevel() || cs->getBidiClass() == BN); cs = cs->next())
+ re = cs;
+ r->prev(re);
+ re->next(r);
+ }
+ if (cs) cs->prev(0);
+ return r;
+}
+
+inline int getlevel(const Slot *cs, const int level)
+{
+ while (cs && cs->getBidiClass() == BN)
+ { cs = cs->next(); }
+ if (cs)
+ return cs->getBidiLevel();
+ else
+ return level;
+}
+
+Slot *resolveOrder(Slot * & cs, const bool reordered, const int level)
+{
+ Slot * r = 0;
+ int ls;
+ while (cs && level <= (ls = getlevel(cs, level) - reordered))
+ {
+ r = join(level, r, level < ls
+ ? resolveOrder(/* updates */cs, reordered, level+1) // find span of heighest level
+ : span(/* updates */cs, level & 1));
+ }
+ return r;
+}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/CMakeLists.txt b/Build/source/libs/graphite2/graphite2-1.2.4/src/CMakeLists.txt
index f76cbed114c..f785070830a 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/CMakeLists.txt
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/CMakeLists.txt
@@ -104,15 +104,25 @@ set_target_properties(graphite2 PROPERTIES PUBLIC_HEADER "${GRAPHITE_HEADERS}"
LT_VERSION_REVISION ${GRAPHITE_API_REVISION}
LT_VERSION_AGE ${GRAPHITE_API_AGE})
+if (${CMAKE_BUILD_TYPE} STREQUAL "ClangASN")
+ set(GRAPHITE_LINK_FLAGS "-fsanitize=address")
+else (${CMAKE_BUILD_TYPE} STREQUAL "ClangASN")
+ set(GRAPHITE_LINK_FLAGS "")
+endif (${CMAKE_BUILD_TYPE} STREQUAL "ClangASN")
+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set_target_properties(graphite2 PROPERTIES
COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wendif-labels -Wshadow -Wctor-dtor-privacy -Wnon-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -fno-stack-protector"
- LINK_FLAGS "-nodefaultlibs"
+ LINK_FLAGS "-nodefaultlibs ${GRAPHITE_LINK_FLAGS}"
LINKER_LANGUAGE C)
if (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*")
target_link_libraries(graphite2 kernel32 msvcr90 mingw32 gcc user32)
else (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*")
- target_link_libraries(graphite2 c gcc)
+ if (GRAPHITE2_ASAN)
+ target_link_libraries(graphite2 c gcc_s)
+ else (GRAPHITE2_ASAN)
+ target_link_libraries(graphite2 c gcc)
+ endif (GRAPHITE2_ASAN)
include(Graphite)
nolib_test(stdc++ $<TARGET_SONAME_FILE:graphite2>)
endif (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*")
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/CachedFace.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/CachedFace.cpp
index 3642768854b..fd599bde8aa 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/CachedFace.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/CachedFace.cpp
@@ -61,7 +61,7 @@ bool CachedFace::runGraphite(Segment *seg, const Silf *pSilf) const
if (silfIndex == m_numSilf) return false;
SegCache * const segCache = m_cacheStore->getOrCreate(silfIndex, seg->getFeatures(0));
if (!segCache)
- return false;
+ return false;
assert(m_cacheStore);
// find where the segment can be broken
@@ -71,23 +71,23 @@ bool CachedFace::runGraphite(Segment *seg, const Silf *pSilf) const
int subSegStart = 0;
for (unsigned int i = 0; i < seg->charInfoCount(); ++i)
{
- const unsigned int length = i - subSegStart + 1;
+ const unsigned int length = i - subSegStart + 1;
if (length < eMaxSpliceSize)
cmapGlyphs[length-1] = subSegEndSlot->gid();
else return false;
const bool spaceOnly = m_cacheStore->isSpaceGlyph(subSegEndSlot->gid());
// at this stage the character to slot mapping is still 1 to 1
- const int breakWeight = seg->charinfo(i)->breakWeight(),
- nextBreakWeight = (i + 1 < seg->charInfoCount())?
- seg->charinfo(i+1)->breakWeight() : 0;
+ const int breakWeight = seg->charinfo(i)->breakWeight(),
+ nextBreakWeight = (i + 1 < seg->charInfoCount())?
+ seg->charinfo(i+1)->breakWeight() : 0;
const uint8 f = seg->charinfo(i)->flags();
if (((spaceOnly
- || (breakWeight > 0 && breakWeight <= gr_breakWord)
- || i + 1 == seg->charInfoCount()
- || ((nextBreakWeight < 0 && nextBreakWeight >= gr_breakBeforeWord)
- || (subSegEndSlot->next() && m_cacheStore->isSpaceGlyph(subSegEndSlot->next()->gid()))))
- && f != 1)
- || f == 2)
+ || (breakWeight > 0 && breakWeight <= gr_breakWord)
+ || i + 1 == seg->charInfoCount()
+ || ((nextBreakWeight < 0 && nextBreakWeight >= gr_breakBeforeWord)
+ || (subSegEndSlot->next() && m_cacheStore->isSpaceGlyph(subSegEndSlot->next()->gid()))))
+ && f != 1)
+ || f == 2)
{
// record the next slot before any splicing
Slot * nextSlot = subSegEndSlot->next();
@@ -103,8 +103,8 @@ bool CachedFace::runGraphite(Segment *seg, const Silf *pSilf) const
pSilf->runGraphite(seg, pSilf->substitutionPass(), pSilf->numPasses());
if (length < eMaxSpliceSize)
{
- seg->associateChars();
- entry = segCache->cache(m_cacheStore, cmapGlyphs, length, seg, subSegStart);
+ seg->associateChars(subSegStart, length);
+ segCache->cache(m_cacheStore, cmapGlyphs, length, seg, subSegStart);
}
seg->removeScope(scopeState);
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/CmapCache.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/CmapCache.cpp
index f388df9d289..a184e97095c 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/CmapCache.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/CmapCache.cpp
@@ -89,7 +89,7 @@ CachedCmap::CachedCmap(const Face & face)
m_blocks(0)
{
const Face::Table cmap(face, Tag::cmap);
- if (!cmap) return;
+ if (!cmap) return;
const void * bmp_cmap = bmp_subtable(cmap);
const void * smp_cmap = smp_subtable(cmap);
@@ -114,7 +114,7 @@ CachedCmap::~CachedCmap() throw()
if (!m_blocks) return;
unsigned int numBlocks = (m_isBmpOnly)? 0x100 : 0x1100;
for (unsigned int i = 0; i < numBlocks; i++)
- free(m_blocks[i]);
+ free(m_blocks[i]);
free(m_blocks);
}
@@ -130,7 +130,7 @@ uint16 CachedCmap::operator [] (const uint32 usv) const throw()
CachedCmap::operator bool() const throw()
{
- return m_blocks != 0;
+ return m_blocks != 0;
}
@@ -150,6 +150,6 @@ uint16 DirectCmap::operator [] (const uint32 usv) const throw()
DirectCmap::operator bool () const throw()
{
- return _cmap && _bmp;
+ return _cmap && _bmp;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Code.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Code.cpp
index 3c6be746f91..85769867dfd 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Code.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Code.cpp
@@ -105,7 +105,7 @@ private:
opcode fetch_opcode(const byte * bc);
void analyse_opcode(const opcode, const int8 * const dp) throw();
bool emit_opcode(opcode opc, const byte * & bc);
- bool validate_opcode(const opcode opc, const byte * const bc);
+ bool validate_opcode(const opcode opc, const byte * const bc);
bool valid_upto(const uint16 limit, const uint16 x) const throw();
void failure(const status_t s) const throw() { _code.failure(s); }
@@ -215,7 +215,10 @@ Machine::Code::Code(bool is_constraint, const byte * bytecode_begin, const byte
_data = static_cast<byte *>(realloc(_data, _data_size*sizeof(byte)));
if (!_code)
+ {
failure(alloc_failed);
+ return;
+ }
// Make this RET_ZERO, we should never reach this but just in case ...
_code[_instr_count] = op_to_fn[RET_ZERO].impl[_constraint];
@@ -257,7 +260,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc)
const opcode opc = opcode(*bc++);
// Do some basic sanity checks based on what we know about the opcode
- if (!validate_opcode(opc, bc)) return MAX_OPCODE;
+ if (!validate_opcode(opc, bc)) return MAX_OPCODE;
// And check it's arguments as far as possible
switch (opc)
@@ -322,11 +325,11 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc)
case ATTR_ADD :
case ATTR_SUB :
case ATTR_SET_SLOT :
- valid_upto(gr_slatMax, bc[0]);
+ valid_upto(gr_slatMax, bc[0]);
break;
case IATTR_SET_SLOT :
if (valid_upto(gr_slatMax, bc[0]))
- valid_upto(_max.attrid[bc[0]], bc[1]);
+ valid_upto(_max.attrid[bc[0]], bc[1]);
break;
case PUSH_SLOT_ATTR :
valid_upto(gr_slatMax, bc[0]);
@@ -357,8 +360,8 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc)
case PUSH_ISLOT_ATTR :
if (valid_upto(gr_slatMax, bc[0]))
{
- valid_upto(_rule_length, _pre_context + int8(bc[1]));
- valid_upto(_max.attrid[bc[0]], bc[2]);
+ valid_upto(_rule_length, _pre_context + int8(bc[1]));
+ valid_upto(_max.attrid[bc[0]], bc[2]);
}
break;
case PUSH_IGLYPH_ATTR :// not implemented
@@ -370,7 +373,7 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc)
case IATTR_ADD :
case IATTR_SUB :
if (valid_upto(gr_slatMax, bc[0]))
- valid_upto(_max.attrid[bc[0]], bc[1]);
+ valid_upto(_max.attrid[bc[0]], bc[1]);
break;
case PUSH_PROC_STATE : // dummy: dp[0] no check necessary
case PUSH_VERSION :
@@ -544,26 +547,26 @@ void Machine::Code::decoder::apply_analysis(instr * const code, instr * code_end
inline
bool Machine::Code::decoder::validate_opcode(const opcode opc, const byte * const bc)
{
- if (opc >= MAX_OPCODE)
- {
- failure(invalid_opcode);
- return false;
- }
- const opcode_t & op = Machine::getOpcodeTable()[opc];
- const size_t param_sz = op.param_sz == VARARGS ? bc[0] + 1 : op.param_sz;
- if (bc + param_sz > _max.bytecode)
- {
- failure(arguments_exhausted);
- return false;
- }
- return true;
+ if (opc >= MAX_OPCODE)
+ {
+ failure(invalid_opcode);
+ return false;
+ }
+ const opcode_t & op = Machine::getOpcodeTable()[opc];
+ const size_t param_sz = op.param_sz == VARARGS ? bc[0] + 1 : op.param_sz;
+ if (bc + param_sz > _max.bytecode)
+ {
+ failure(arguments_exhausted);
+ return false;
+ }
+ return true;
}
bool Machine::Code::decoder::valid_upto(const uint16 limit, const uint16 x) const throw()
{
- const bool t = x < limit;
- if (!t) failure(out_of_range_data);
+ const bool t = x < limit;
+ if (!t) failure(out_of_range_data);
return t;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Face.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Face.cpp
index a8b8f0ce21a..e25f7260ac6 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Face.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Face.cpp
@@ -36,7 +36,7 @@ of the License or (at your option) any later version.
#include "inc/SegCacheStore.h"
#include "inc/Segment.h"
#include "inc/NameTable.h"
-
+#include "inc/Error.h"
using namespace graphite2;
@@ -47,6 +47,7 @@ Face::Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops)
m_cmap(NULL),
m_pNames(NULL),
m_logger(NULL),
+ m_error(0), m_errcntxt(0),
m_silfs(NULL),
m_numSilf(0),
m_ascent(0),
@@ -78,20 +79,24 @@ float Face::default_glyph_advance(const void* font_ptr, gr_uint16 glyphid)
bool Face::readGlyphs(uint32 faceOptions)
{
+ Error e;
#ifdef GRAPHITE2_TELEMETRY
telemetry::category _glyph_cat(tele.glyph);
#endif
+ error_context(EC_READGLYPHS);
if (faceOptions & gr_face_cacheCmap)
- m_cmap = new CachedCmap(*this);
+ m_cmap = new CachedCmap(*this);
else
- m_cmap = new DirectCmap(*this);
+ m_cmap = new DirectCmap(*this);
m_pGlyphFaceCache = new GlyphCache(*this, faceOptions);
- if (!m_pGlyphFaceCache
- || m_pGlyphFaceCache->numGlyphs() == 0
- || m_pGlyphFaceCache->unitsPerEm() == 0
- || !m_cmap || !*m_cmap)
- return false;
+ if (e.test(!m_pGlyphFaceCache, E_OUTOFMEM)
+ || e.test(m_pGlyphFaceCache->numGlyphs() == 0, E_NOGLYPHS)
+ || e.test(m_pGlyphFaceCache->unitsPerEm() == 0, E_BADUPEM)
+ || e.test(!m_cmap, E_OUTOFMEM) || e.test(!*m_cmap, E_BADCMAP))
+ {
+ return error(e);
+ }
if (faceOptions & gr_face_preloadGlyphs)
nameTable(); // preload the name table along with the glyphs.
@@ -104,24 +109,27 @@ bool Face::readGraphite(const Table & silf)
#ifdef GRAPHITE2_TELEMETRY
telemetry::category _silf_cat(tele.silf);
#endif
+ Error e;
+ error_context(EC_READSILF);
const byte * p = silf;
- if (!p) return false;
+ if (e.test(!p, E_NOSILF)) return error(e);
const uint32 version = be::read<uint32>(p);
- if (version < 0x00020000) return false;
+ if (e.test(version < 0x00020000, E_TOOOLD)) return error(e);
if (version >= 0x00030000)
- be::skip<uint32>(p); // compilerVersion
+ be::skip<uint32>(p); // compilerVersion
m_numSilf = be::read<uint16>(p);
- be::skip<uint16>(p); // reserved
+ be::skip<uint16>(p); // reserved
bool havePasses = false;
m_silfs = new Silf[m_numSilf];
for (int i = 0; i < m_numSilf; i++)
{
+ error_context(EC_ASILF + (i << 8));
const uint32 offset = be::read<uint32>(p),
- next = i == m_numSilf - 1 ? silf.size() : be::peek<uint32>(p);
- if (next > silf.size() || offset >= next)
- return false;
+ next = i == m_numSilf - 1 ? silf.size() : be::peek<uint32>(p);
+ if (e.test(next > silf.size() || offset >= next, E_BADSIZE))
+ return error(e);
if (!m_silfs[i].readGraphite(silf + offset, next - offset, *this, version))
return false;
@@ -144,33 +152,33 @@ bool Face::runGraphite(Segment *seg, const Silf *aSilf) const
json * dbgout = logger();
if (dbgout)
{
- *dbgout << json::object
- << "id" << objectid(seg)
- << "passes" << json::array;
+ *dbgout << json::object
+ << "id" << objectid(seg)
+ << "passes" << json::array;
}
#endif
- bool res = aSilf->runGraphite(seg, 0, aSilf->justificationPass());
+ bool res = aSilf->runGraphite(seg, 0, aSilf->justificationPass(), true);
if (res)
- res = aSilf->runGraphite(seg, aSilf->positionPass(), aSilf->numPasses());
+ res = aSilf->runGraphite(seg, aSilf->positionPass(), aSilf->numPasses(), false);
#if !defined GRAPHITE2_NTRACING
- if (dbgout)
+ if (dbgout)
{
- *dbgout << json::item
- << json::close // Close up the passes array
- << "output" << json::array;
- for(Slot * s = seg->first(); s; s = s->next())
- *dbgout << dslot(seg, s);
- seg->finalise(0); // Call this here to fix up charinfo back indexes.
- *dbgout << json::close
- << "advance" << seg->advance()
- << "chars" << json::array;
- for(size_t i = 0, n = seg->charInfoCount(); i != n; ++i)
- *dbgout << json::flat << *seg->charinfo(i);
- *dbgout << json::close // Close up the chars array
- << json::close; // Close up the segment object
- }
+ *dbgout << json::item
+ << json::close // Close up the passes array
+ << "output" << json::array;
+ for(Slot * s = seg->first(); s; s = s->next())
+ *dbgout << dslot(seg, s);
+ seg->finalise(0); // Call this here to fix up charinfo back indexes.
+ *dbgout << json::close
+ << "advance" << seg->advance()
+ << "chars" << json::array;
+ for(size_t i = 0, n = seg->charInfoCount(); i != n; ++i)
+ *dbgout << json::flat << *seg->charinfo(i);
+ *dbgout << json::close // Close up the chars array
+ << json::close; // Close up the segment object
+ }
#endif
return res;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/FeatureMap.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/FeatureMap.cpp
index aa638d5cb4c..7cc3c7299bd 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/FeatureMap.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/FeatureMap.cpp
@@ -41,38 +41,38 @@ using namespace graphite2;
namespace
{
- static int cmpNameAndFeatures(const void *ap, const void *bp)
- {
- const NameAndFeatureRef & a = *static_cast<const NameAndFeatureRef *>(ap),
- & b = *static_cast<const NameAndFeatureRef *>(bp);
- return (a < b ? -1 : (b < a ? 1 : 0));
- }
-
- const size_t FEAT_HEADER = sizeof(uint32) + 2*sizeof(uint16) + sizeof(uint32),
- FEATURE_SIZE = sizeof(uint32)
- + 2*sizeof(uint16)
- + sizeof(uint32)
- + 2*sizeof(uint16),
- FEATURE_SETTING_SIZE = sizeof(int16) + sizeof(uint16);
-
- uint16 readFeatureSettings(const byte * p, FeatureSetting * s, size_t num_settings)
- {
- uint16 max_val = 0;
+ static int cmpNameAndFeatures(const void *ap, const void *bp)
+ {
+ const NameAndFeatureRef & a = *static_cast<const NameAndFeatureRef *>(ap),
+ & b = *static_cast<const NameAndFeatureRef *>(bp);
+ return (a < b ? -1 : (b < a ? 1 : 0));
+ }
+
+ const size_t FEAT_HEADER = sizeof(uint32) + 2*sizeof(uint16) + sizeof(uint32),
+ FEATURE_SIZE = sizeof(uint32)
+ + 2*sizeof(uint16)
+ + sizeof(uint32)
+ + 2*sizeof(uint16),
+ FEATURE_SETTING_SIZE = sizeof(int16) + sizeof(uint16);
+
+ uint16 readFeatureSettings(const byte * p, FeatureSetting * s, size_t num_settings)
+ {
+ uint16 max_val = 0;
for (FeatureSetting * const end = s + num_settings; s != end; ++s)
{
- const int16 value = be::read<int16>(p);
+ const int16 value = be::read<int16>(p);
::new (s) FeatureSetting(value, be::read<uint16>(p));
- if (uint16(value) > max_val) max_val = value;
+ if (uint16(value) > max_val) max_val = value;
}
return max_val;
- }
+ }
}
FeatureRef::FeatureRef(const Face & face,
- unsigned short & bits_offset, uint32 max_val,
- uint32 name, uint16 uiName, uint16 flags,
- FeatureSetting *settings, uint16 num_set) throw()
+ unsigned short & bits_offset, uint32 max_val,
+ uint32 name, uint16 uiName, uint16 flags,
+ FeatureSetting *settings, uint16 num_set) throw()
: m_pFace(&face),
m_nameValues(settings),
m_mask(mask_over_val(max_val)),
@@ -82,13 +82,13 @@ FeatureRef::FeatureRef(const Face & face,
m_flags(flags),
m_numSet(num_set)
{
- const uint8 need_bits = bit_set_count(m_mask);
- m_index = (bits_offset + need_bits) / SIZEOF_CHUNK;
- if (m_index > bits_offset / SIZEOF_CHUNK)
- bits_offset = m_index*SIZEOF_CHUNK;
- m_bits = bits_offset % SIZEOF_CHUNK;
- bits_offset += need_bits;
- m_mask <<= m_bits;
+ const uint8 need_bits = bit_set_count(m_mask);
+ m_index = (bits_offset + need_bits) / SIZEOF_CHUNK;
+ if (m_index > bits_offset / SIZEOF_CHUNK)
+ bits_offset = m_index*SIZEOF_CHUNK;
+ m_bits = bits_offset % SIZEOF_CHUNK;
+ bits_offset += need_bits;
+ m_mask <<= m_bits;
}
FeatureRef::~FeatureRef() throw()
@@ -104,7 +104,7 @@ bool FeatureMap::readFeats(const Face & face)
if (feat.size() < FEAT_HEADER) return false;
const byte *const feat_start = p,
- *const feat_end = p + feat.size();
+ *const feat_end = p + feat.size();
const uint32 version = be::read<uint32>(p);
m_numFeats = be::read<uint16>(p);
@@ -112,27 +112,28 @@ bool FeatureMap::readFeats(const Face & face)
be::skip<uint32>(p);
// Sanity checks
- if (m_numFeats == 0) return true;
+ if (m_numFeats == 0) return true;
if (version < 0x00010000 ||
- p + m_numFeats*FEATURE_SIZE > feat_end)
+ p + m_numFeats*FEATURE_SIZE > feat_end)
{ //defensive
- m_numFeats = 0;
- return false;
+ m_numFeats = 0;
+ return false;
}
m_feats = new FeatureRef [m_numFeats];
- uint16 * const defVals = gralloc<uint16>(m_numFeats);
+ uint16 * const defVals = gralloc<uint16>(m_numFeats);
+ if (!defVals || !m_feats) return false;
unsigned short bits = 0; //to cause overflow on first Feature
for (int i = 0, ie = m_numFeats; i != ie; i++)
{
- const uint32 label = version < 0x00020000 ? be::read<uint16>(p) : be::read<uint32>(p);
- const uint16 num_settings = be::read<uint16>(p);
+ const uint32 label = version < 0x00020000 ? be::read<uint16>(p) : be::read<uint32>(p);
+ const uint16 num_settings = be::read<uint16>(p);
if (version >= 0x00020000)
- be::skip<uint16>(p);
+ be::skip<uint16>(p);
const byte * const feat_setts = feat_start + be::read<uint32>(p);
- const uint16 flags = be::read<uint16>(p),
- uiName = be::read<uint16>(p);
+ const uint16 flags = be::read<uint16>(p),
+ uiName = be::read<uint16>(p);
if (feat_setts + num_settings * FEATURE_SETTING_SIZE > feat_end)
{
@@ -144,26 +145,36 @@ bool FeatureMap::readFeats(const Face & face)
uint32 maxVal;
if (num_settings != 0)
{
- uiSet = gralloc<FeatureSetting>(num_settings);
- maxVal = readFeatureSettings(feat_setts, uiSet, num_settings);
- defVals[i] = uiSet[0].value();
+ uiSet = gralloc<FeatureSetting>(num_settings);
+ if (!uiSet)
+ {
+ free(defVals);
+ return false;
+ }
+ maxVal = readFeatureSettings(feat_setts, uiSet, num_settings);
+ defVals[i] = uiSet[0].value();
}
else
{
- uiSet = 0;
- maxVal = 0xffffffff;
- defVals[i] = 0;
+ uiSet = 0;
+ maxVal = 0xffffffff;
+ defVals[i] = 0;
}
- ::new (m_feats + i) FeatureRef (face, bits, maxVal,
- label, uiName, flags,
- uiSet, num_settings);
+ ::new (m_feats + i) FeatureRef (face, bits, maxVal,
+ label, uiName, flags,
+ uiSet, num_settings);
}
m_defaultFeatures = new Features(bits/(sizeof(uint32)*8) + 1, *this);
m_pNamedFeats = new NameAndFeatureRef[m_numFeats];
+ if (!m_defaultFeatures || !m_pNamedFeats)
+ {
+ free(defVals);
+ return false;
+ }
for (int i = 0; i < m_numFeats; ++i)
{
- m_feats[i].applyValToFeature(defVals[i], *m_defaultFeatures);
+ m_feats[i].applyValToFeature(defVals[i], *m_defaultFeatures);
m_pNamedFeats[i] = m_feats+i;
}
@@ -184,7 +195,7 @@ bool SillMap::readFace(const Face & face)
bool SillMap::readSill(const Face & face)
{
- const Face::Table sill(face, TtfUtil::Tag::Sill);
+ const Face::Table sill(face, TtfUtil::Tag::Sill);
const byte *p = sill;
if (!p) return true;
@@ -204,6 +215,7 @@ bool SillMap::readSill(const Face & face)
uint16 offset = be::read<uint16>(p);
if (offset + 8U * numSettings > sill.size() && numSettings > 0) return false;
Features* feats = new Features(*m_FeatureMap.m_defaultFeatures);
+ if (!feats) return false;
const byte *pLSet = sill + offset;
// Apply langauge specific settings
@@ -213,11 +225,11 @@ bool SillMap::readSill(const Face & face)
uint16 val = be::read<uint16>(pLSet);
pLSet += 2;
const FeatureRef* pRef = m_FeatureMap.findFeatureRef(name);
- if (pRef) pRef->applyValToFeature(val, *feats);
+ if (pRef) pRef->applyValToFeature(val, *feats);
}
// Add the language id feature which is always feature id 1
const FeatureRef* pRef = m_FeatureMap.findFeatureRef(1);
- if (pRef) pRef->applyValToFeature(langid, *feats);
+ if (pRef) pRef->applyValToFeature(langid, *feats);
m_langFeats[i].m_lang = langid;
m_langFeats[i].m_pFeatures = feats;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/FileFace.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/FileFace.cpp
index 79a3213530e..3df67354b1b 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/FileFace.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/FileFace.cpp
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Font.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Font.cpp
index 8860d3b58be..5cec362bfc6 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Font.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Font.cpp
@@ -37,7 +37,7 @@ Font::Font(float ppm, const Face & f, const void * appFontHandle, const gr_font_
m_hinted(appFontHandle && ops && (ops->glyph_advance_x || ops->glyph_advance_y))
{
memset(&m_ops, 0, sizeof m_ops);
- if (m_hinted)
+ if (m_hinted && ops)
memcpy(&m_ops, ops, min(sizeof m_ops, ops->size));
else
m_ops.glyph_advance_x = &Face::default_glyph_advance;
@@ -47,14 +47,14 @@ Font::Font(float ppm, const Face & f, const void * appFontHandle, const gr_font_
if (m_advances)
{
for (float *advp = m_advances; nGlyphs; --nGlyphs, ++advp)
- *advp = INVALID_ADVANCE;
+ *advp = INVALID_ADVANCE;
}
}
/*virtual*/ Font::~Font()
{
- free(m_advances);
+ free(m_advances);
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphCache.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphCache.cpp
index 457397b7505..aee03055e17 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphCache.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphCache.cpp
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -36,45 +36,45 @@ using namespace graphite2;
namespace
{
- class glat_iterator : public std::iterator<std::input_iterator_tag, std::pair<sparse::key_type, sparse::mapped_type> >
+ // Iterator over version 1 or 2 glat entries which consist of a series of
+ // +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+
+ // v1 |k|n|v1 |v2 |...|vN | or v2 | k | n |v1 |v2 |...|vN |
+ // +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+
+ // variable length structures.
+
+ template<typename W>
+ class _glat_iterator : public std::iterator<std::input_iterator_tag, std::pair<sparse::key_type, sparse::mapped_type> >
{
+ unsigned short key() const { return be::peek<W>(_e) + _n; }
+ unsigned int run() const { return be::peek<W>(_e+sizeof(W)); }
+ void advance_entry() { _n = 0; _e = _v; be::skip<W>(_v,2); }
public:
- glat_iterator(const void * glat=0) : _p(reinterpret_cast<const byte *>(glat)), _n(0) {}
+ _glat_iterator(const void * glat=0) : _e(reinterpret_cast<const byte *>(glat)), _v(_e+2*sizeof(W)), _n(0) {}
- glat_iterator & operator ++ () { ++_v.first; --_n; _p += sizeof(uint16); if (_n == -1) { _p -= 2; _v.first = *_p++; _n = *_p++; } return *this; }
- glat_iterator operator ++ (int) { glat_iterator tmp(*this); operator++(); return tmp; }
+ _glat_iterator<W> & operator ++ () {
+ ++_n; be::skip<uint16>(_v);
+ if (_n == run()) advance_entry();
+ return *this;
+ }
+ _glat_iterator<W> operator ++ (int) { _glat_iterator<W> tmp(*this); operator++(); return tmp; }
- bool operator == (const glat_iterator & rhs) { return _p >= rhs._p || _p + _n*sizeof(uint16) > rhs._p; }
- bool operator != (const glat_iterator & rhs) { return !operator==(rhs); }
+ // This is strictly a >= operator. A true == operator could be
+ // implemented that test for overlap but it would be more expensive a
+ // test.
+ bool operator == (const _glat_iterator<W> & rhs) { return _v >= rhs._e; }
+ bool operator != (const _glat_iterator<W> & rhs) { return !operator==(rhs); }
value_type operator * () const {
- if (_n==0) { _v.first = *_p++; _n = *_p++; }
- _v.second = be::peek<uint16>(_p);
- return _v;
+ return value_type(key(), be::peek<uint16>(_v));
}
- const value_type * operator ->() const { operator * (); return &_v; }
protected:
- mutable const byte * _p;
- mutable value_type _v;
- mutable int _n;
+ const byte * _e, * _v;
+ ptrdiff_t _n;
};
- class glat2_iterator : public glat_iterator
- {
- public:
- glat2_iterator(const void * glat) : glat_iterator(glat) {}
-
- glat2_iterator & operator ++ () { ++_v.first; --_n; _p += sizeof(uint16); if (_n == -1) { _p -= sizeof(uint16)*2; _v.first = be::read<uint16>(_p); _n = be::read<uint16>(_p); } return *this; }
- glat2_iterator operator ++ (int) { glat2_iterator tmp(*this); operator++(); return tmp; }
-
- value_type operator * () const {
- if (_n==0) { _v.first = be::read<uint16>(_p); _n = be::read<uint16>(_p); }
- _v.second = be::peek<uint16>(_p);
- return _v;
- }
- const value_type * operator ->() const { operator * (); return &_v; }
- };
+ typedef _glat_iterator<uint8> glat_iterator;
+ typedef _glat_iterator<uint16> glat2_iterator;
}
@@ -203,7 +203,7 @@ GlyphCache::Loader::Loader(const Face & face, const bool dumb_font)
_num_glyphs_graphics = TtfUtil::GlyphCount(maxp);
// This will fail if the number of glyphs is wildly out of range.
- if (TtfUtil::LocaLookup(_num_glyphs_graphics-1, _loca, _loca.size(), _head) == size_t(-1))
+ if (_glyf && TtfUtil::LocaLookup(_num_glyphs_graphics-1, _loca, _loca.size(), _head) == size_t(-1))
{
_head = Face::Table();
return;
@@ -244,7 +244,7 @@ GlyphCache::Loader::Loader(const Face & face, const bool dumb_font)
inline
GlyphCache::Loader::operator bool () const throw()
{
- return _head && _hhea && _hmtx && _glyf && _loca;
+ return _head && _hhea && _hmtx && !(bool(_glyf) != bool(_loca));
}
inline
@@ -272,16 +272,20 @@ const GlyphFace * GlyphCache::Loader::read_glyph(unsigned short glyphid, GlyphFa
if (glyphid < _num_glyphs_graphics)
{
- int nLsb, xMin, yMin, xMax, yMax;
+ int nLsb;
unsigned int nAdvWid;
- size_t locidx = TtfUtil::LocaLookup(glyphid, _loca, _loca.size(), _head);
- void *pGlyph = TtfUtil::GlyfLookup(_glyf, locidx, _glyf.size());
+ if (_glyf)
+ {
+ int xMin, yMin, xMax, yMax;
+ size_t locidx = TtfUtil::LocaLookup(glyphid, _loca, _loca.size(), _head);
+ void *pGlyph = TtfUtil::GlyfLookup(_glyf, locidx, _glyf.size());
+
+ if (pGlyph && TtfUtil::GlyfBox(pGlyph, xMin, yMin, xMax, yMax))
+ bbox = Rect(Position(static_cast<float>(xMin), static_cast<float>(yMin)),
+ Position(static_cast<float>(xMax), static_cast<float>(yMax)));
+ }
if (TtfUtil::HorMetrics(glyphid, _hmtx, _hmtx.size(), _hhea, nLsb, nAdvWid))
advance = Position(static_cast<float>(nAdvWid), 0);
-
- if (pGlyph && TtfUtil::GlyfBox(pGlyph, xMin, yMin, xMax, yMax))
- bbox = Rect(Position(static_cast<float>(xMin), static_cast<float>(yMin)),
- Position(static_cast<float>(xMax), static_cast<float>(yMax)));
}
if (glyphid < _num_glyphs_attributes)
@@ -329,7 +333,7 @@ const GlyphFace * GlyphCache::Loader::read_glyph(unsigned short glyphid, GlyphFa
new (&glyph) GlyphFace(bbox, advance, glat2_iterator(m_pGlat + glocs), glat2_iterator(m_pGlat + gloce));
}
- if (glyph.attrs().capacity() > _num_attrs)
+ if (!glyph.attrs() || glyph.attrs().capacity() > _num_attrs)
return 0;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphFace.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphFace.cpp
index 9fc11b2157e..9fc11b2157e 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/GlyphFace.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/GlyphFace.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Justifier.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Justifier.cpp
index fc667dca1ab..5816ee0890f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Justifier.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Justifier.cpp
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -117,6 +117,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS
}
JustifyTotal *stats = new JustifyTotal[numLevels];
+ if (!stats) return -1.0;
for (s = pFirst; s != end; s = s->nextSibling())
{
float w = s->origin().x / scale + s->advance() - base;
@@ -179,6 +180,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS
{
m_first = pSlot = addLineEnd(pSlot);
m_last = pLast = addLineEnd(end);
+ if (!m_first || !m_last) return -1.0;
}
else
{
@@ -191,7 +193,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS
json * const dbgout = m_face->logger();
if (dbgout)
*dbgout << json::object
- << "justifies" << objectid(this)
+ << "justifies" << objectid(this)
<< "passes" << json::array;
#endif
@@ -206,8 +208,8 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS
Slot *lEnd = pLast->nextSibling();
*dbgout << "output" << json::array;
for(Slot * t = pSlot; t != lEnd; t = t->next())
- *dbgout << dslot(this, t);
- *dbgout << json::close << json::close;
+ *dbgout << dslot(this, t);
+ *dbgout << json::close << json::close;
}
#endif
@@ -226,6 +228,7 @@ float Segment::justify(Slot *pSlot, const Font *font, float width, GR_MAYBE_UNUS
Slot *Segment::addLineEnd(Slot *nSlot)
{
Slot *eSlot = newSlot();
+ if (!eSlot) return NULL;
const uint16 gid = silf()->endLineGlyphid();
const GlyphFace * theGlyph = m_face->glyphs().glyphSafe(gid);
eSlot->setGlyph(this, gid, theGlyph);
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/NameTable.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/NameTable.cpp
index c9eb7651fe5..f83adb09cd8 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/NameTable.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/NameTable.cpp
@@ -145,6 +145,12 @@ void* NameTable::getName(uint16& languageId, uint16 nameId, gr_encform enc, uint
}
utf16Length >>= 1; // in utf16 units
utf16::codeunit_t * utf16Name = gralloc<utf16::codeunit_t>(utf16Length);
+ if (!utf16Name)
+ {
+ languageId = 0;
+ length = 0;
+ return NULL;
+ }
const uint8* pName = m_nameData + offset;
for (size_t i = 0; i < utf16Length; i++)
{
@@ -154,28 +160,46 @@ void* NameTable::getName(uint16& languageId, uint16 nameId, gr_encform enc, uint
{
case gr_utf8:
{
- utf8::codeunit_t* uniBuffer = gralloc<utf8::codeunit_t>(3 * utf16Length + 1);
+ utf8::codeunit_t* uniBuffer = gralloc<utf8::codeunit_t>(3 * utf16Length + 1);
+ if (!uniBuffer)
+ {
+ free(utf16Name);
+ languageId = 0;
+ length = 0;
+ return NULL;
+ }
utf8::iterator d = uniBuffer;
for (utf16::const_iterator s = utf16Name, e = utf16Name + utf16Length; s != e; ++s, ++d)
- *d = *s;
+ *d = *s;
length = d - uniBuffer;
uniBuffer[length] = 0;
+ free(utf16Name);
return uniBuffer;
}
case gr_utf16:
- length = utf16Length;
- return utf16Name;
+ length = utf16Length;
+ return utf16Name;
case gr_utf32:
{
- utf32::codeunit_t * uniBuffer = gralloc<utf32::codeunit_t>(utf16Length + 1);
- utf32::iterator d = uniBuffer;
- for (utf16::const_iterator s = utf16Name, e = utf16Name + utf16Length; s != e; ++s, ++d)
- *d = *s;
- length = d - uniBuffer;
- uniBuffer[length] = 0;
- return uniBuffer;
+ utf32::codeunit_t * uniBuffer = gralloc<utf32::codeunit_t>(utf16Length + 1);
+ if (!uniBuffer)
+ {
+ free(utf16Name);
+ languageId = 0;
+ length = 0;
+ return NULL;
+ }
+ utf32::iterator d = uniBuffer;
+ for (utf16::const_iterator s = utf16Name, e = utf16Name + utf16Length; s != e; ++s, ++d)
+ *d = *s;
+ length = d - uniBuffer;
+ uniBuffer[length] = 0;
+ free(utf16Name);
+ return uniBuffer;
}
}
+ free(utf16Name);
+ languageId = 0;
length = 0;
return NULL;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Pass.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Pass.cpp
index 4c139e64f6a..140b45bcca0 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Pass.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Pass.cpp
@@ -34,6 +34,7 @@ of the License or (at your option) any later version.
#include "inc/Segment.h"
#include "inc/Code.h"
#include "inc/Rule.h"
+#include "inc/Error.h"
using namespace graphite2;
using vm::Machine;
@@ -72,13 +73,13 @@ Pass::~Pass()
delete [] m_rules;
}
-bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t subtable_base, GR_MAYBE_UNUSED const Face & face)
+bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t subtable_base, GR_MAYBE_UNUSED Face & face, Error &e)
{
const byte * p = pass_start,
* const pass_end = p + pass_length;
size_t numRanges;
- if (pass_length < 40) return false;
+ if (e.test(pass_length < 40, E_BADPASSLENGTH)) return face.error(e);
// Read in basic values
m_flags = be::read<byte>(p);
m_iMaxLoop = be::read<byte>(p);
@@ -97,14 +98,14 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
be::skip<uint16>(p, 3); // skip searchRange, entrySelector & rangeShift.
assert(p - pass_start == 40);
// Perform some sanity checks.
- if ( m_numTransition > m_numStates
- || m_numSuccess > m_numStates
- || m_numSuccess + m_numTransition < m_numStates
- || numRanges == 0)
- return false;
+ if ( e.test(m_numTransition > m_numStates, E_BADNUMTRANS)
+ || e.test(m_numSuccess > m_numStates, E_BADNUMSUCCESS)
+ || e.test(m_numSuccess + m_numTransition < m_numStates, E_BADNUMSTATES)
+ || e.test(numRanges == 0, E_NORANGES))
+ return face.error(e);
m_successStart = m_numStates - m_numSuccess;
- if (p + numRanges * 6 - 4 > pass_end) return false;
+ if (e.test(p + numRanges * 6 - 4 > pass_end, E_BADPASSLENGTH)) return face.error(e);
m_numGlyphs = be::peek<uint16>(p + numRanges * 6 - 4) + 1;
// Calculate the start of various arrays.
const byte * const ranges = p;
@@ -113,17 +114,17 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
be::skip<uint16>(p, m_numSuccess + 1);
// More sanity checks
- if (reinterpret_cast<const byte *>(o_rule_map + m_numSuccess*sizeof(uint16)) > pass_end
- || p > pass_end)
- return false;
+ if (e.test(reinterpret_cast<const byte *>(o_rule_map + m_numSuccess*sizeof(uint16)) > pass_end
+ || p > pass_end, E_BADRULEMAPLEN))
+ return face.error(e);
const size_t numEntries = be::peek<uint16>(o_rule_map + m_numSuccess*sizeof(uint16));
const byte * const rule_map = p;
be::skip<uint16>(p, numEntries);
- if (p + 2*sizeof(uint8) > pass_end) return false;
+ if (e.test(p + 2*sizeof(uint8) > pass_end, E_BADPASSLENGTH)) return face.error(e);
m_minPreCtxt = be::read<uint8>(p);
m_maxPreCtxt = be::read<uint8>(p);
- if (m_minPreCtxt > m_maxPreCtxt) return false;
+ if (e.test(m_minPreCtxt > m_maxPreCtxt, E_BADCTXTLENBOUNDS)) return face.error(e);
const byte * const start_states = p;
be::skip<int16>(p, m_maxPreCtxt - m_minPreCtxt + 1);
const uint16 * const sort_keys = reinterpret_cast<const uint16 *>(p);
@@ -132,7 +133,7 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
be::skip<byte>(p, m_numRules);
be::skip<byte>(p); // skip reserved byte
- if (p + sizeof(uint16) > pass_end) return false;
+ if (e.test(p + sizeof(uint16) > pass_end, E_BADCTXTLENS)) return face.error(e);
const size_t pass_constraint_len = be::read<uint16>(p);
const uint16 * const o_constraint = reinterpret_cast<const uint16 *>(p);
be::skip<uint16>(p, m_numRules + 1);
@@ -141,31 +142,35 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su
const byte * const states = p;
be::skip<int16>(p, m_numTransition*m_numColumns);
be::skip<byte>(p); // skip reserved byte
- if (p != pcCode || p >= pass_end) return false;
+ if (e.test(p != pcCode, E_BADPASSCCODEPTR) || e.test(p >= pass_end, E_BADPASSLENGTH)) return face.error(e);
be::skip<byte>(p, pass_constraint_len);
- if (p != rcCode || p >= pass_end
- || size_t(rcCode - pcCode) != pass_constraint_len) return false;
+ if (e.test(p != rcCode, E_BADRULECCODEPTR) || e.test(p >= pass_end, E_BADPASSLENGTH)
+ || e.test(size_t(rcCode - pcCode) != pass_constraint_len, E_BADCCODELEN)) return face.error(e);
be::skip<byte>(p, be::peek<uint16>(o_constraint + m_numRules));
- if (p != aCode || p >= pass_end) return false;
+ if (e.test(p != aCode, E_BADACTIONCODEPTR) || e.test(p >= pass_end, E_BADPASSLENGTH)) return face.error(e);
be::skip<byte>(p, be::peek<uint16>(o_actions + m_numRules));
// We should be at the end or within the pass
- if (p > pass_end) return false;
+ if (e.test(p > pass_end, E_BADPASSLENGTH)) return face.error(e);
// Load the pass constraint if there is one.
if (pass_constraint_len)
{
+ face.error_context(face.error_context() + 1);
m_cPConstraint = vm::Machine::Code(true, pcCode, pcCode + pass_constraint_len,
precontext[0], be::peek<uint16>(sort_keys), *m_silf, face);
- if (!m_cPConstraint) return false;
+ if (e.test(!m_cPConstraint, E_OUTOFMEM)
+ || e.test(m_cPConstraint.status(), m_cPConstraint.status() + E_CODEFAILURE))
+ return face.error(e);
+ face.error_context(face.error_context() - 1);
}
- if (!readRanges(ranges, numRanges)) return false;
+ if (!readRanges(ranges, numRanges, e)) return face.error(e);
if (!readRules(rule_map, numEntries, precontext, sort_keys,
- o_constraint, rcCode, o_actions, aCode, face)) return false;
+ o_constraint, rcCode, o_actions, aCode, face, e)) return false;
#ifdef GRAPHITE2_TELEMETRY
telemetry::category _states_cat(face.tele.states);
#endif
- return readStates(start_states, states, o_rule_map, face);
+ return readStates(start_states, states, o_rule_map, face, e);
}
@@ -173,12 +178,12 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
const byte *precontext, const uint16 * sort_key,
const uint16 * o_constraint, const byte *rc_data,
const uint16 * o_action, const byte * ac_data,
- const Face & face)
+ Face & face, Error &e)
{
const byte * const ac_data_end = ac_data + be::peek<uint16>(o_action + m_numRules);
const byte * const rc_data_end = rc_data + be::peek<uint16>(o_constraint + m_numRules);
- if (!(m_rules = new Rule [m_numRules])) return false;
+ if (e.test(!(m_rules = new Rule [m_numRules]), E_OUTOFMEM)) return face.error(e);
precontext += m_numRules;
sort_key += m_numRules;
o_constraint += m_numRules;
@@ -191,6 +196,7 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
Rule * r = m_rules + m_numRules - 1;
for (size_t n = m_numRules; n; --n, --r, ac_end = ac_begin, rc_end = rc_begin)
{
+ face.error_context((face.error_context() & 0xFFFF00) + EC_ARULE + ((n - 1) << 24));
r->preContext = *--precontext;
r->sort = be::peek<uint16>(--sort_key);
#ifndef NDEBUG
@@ -208,19 +214,21 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
r->action = new vm::Machine::Code(false, ac_begin, ac_end, r->preContext, r->sort, *m_silf, face);
r->constraint = new vm::Machine::Code(true, rc_begin, rc_end, r->preContext, r->sort, *m_silf, face);
- if (!r->action || !r->constraint
- || r->action->status() != Code::loaded
- || r->constraint->status() != Code::loaded
- || !r->constraint->immutable())
- return false;
+ if (e.test(!r->action || !r->constraint, E_OUTOFMEM)
+ || e.test(r->action->status() != Code::loaded, r->action->status() + E_CODEFAILURE)
+ || e.test(r->constraint->status() != Code::loaded, r->constraint->status() + E_CODEFAILURE)
+ || e.test(!r->constraint->immutable(), E_MUTABLECCODE))
+ return face.error(e);
}
// Load the rule entries map
+ face.error_context((face.error_context() & 0xFFFF00) + EC_APASS);
RuleEntry * re = m_ruleMap = gralloc<RuleEntry>(num_entries);
+ if (e.test(!re, E_OUTOFMEM)) return face.error(e);
for (size_t n = num_entries; n; --n, ++re)
{
const ptrdiff_t rn = be::read<uint16>(rule_map);
- if (rn >= m_numRules) return false;
+ if (e.test(rn >= m_numRules, E_BADRULENUM)) return face.error(e);
re->rule = m_rules + rn;
}
@@ -230,7 +238,7 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries,
static int cmpRuleEntry(const void *a, const void *b) { return (*(RuleEntry *)a < *(RuleEntry *)b ? -1 :
(*(RuleEntry *)b < *(RuleEntry *)a ? 1 : 0)); }
-bool Pass::readStates(const byte * starts, const byte *states, const byte * o_rule_map, GR_MAYBE_UNUSED const Face & face)
+bool Pass::readStates(const byte * starts, const byte *states, const byte * o_rule_map, GR_MAYBE_UNUSED Face & face, Error &e)
{
#ifdef GRAPHITE2_TELEMETRY
telemetry::category _states_cat(face.tele.starts);
@@ -245,13 +253,17 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru
#endif
m_transitions = gralloc<uint16>(m_numTransition * m_numColumns);
- if (!m_startStates || !m_states || !m_transitions) return false;
+ if (e.test(!m_startStates || !m_states || !m_transitions, E_OUTOFMEM)) return face.error(e);
// load start states
for (uint16 * s = m_startStates,
* const s_end = s + m_maxPreCtxt - m_minPreCtxt + 1; s != s_end; ++s)
{
*s = be::read<uint16>(starts);
- if (*s >= m_numStates) return false; // true;
+ if (e.test(*s >= m_numStates, E_BADSTATE))
+ {
+ face.error_context((face.error_context() & 0xFFFF00) + EC_ASTARTS + ((s - m_startStates) << 24));
+ return face.error(e); // true;
+ }
}
// load state transition table.
@@ -259,7 +271,11 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru
* const t_end = t + m_numTransition*m_numColumns; t != t_end; ++t)
{
*t = be::read<uint16>(states);
- if (*t >= m_numStates) return false;
+ if (e.test(*t >= m_numStates, E_BADSTATE))
+ {
+ face.error_context((face.error_context() & 0xFFFF00) + EC_ATRANS + (((t - m_transitions) / m_numColumns) << 24));
+ return face.error(e);
+ }
}
State * s = m_states,
@@ -270,8 +286,11 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru
RuleEntry * const begin = s < success_begin ? 0 : m_ruleMap + be::read<uint16>(o_rule_map),
* const end = s < success_begin ? 0 : m_ruleMap + be::peek<uint16>(o_rule_map);
- if (begin >= rule_map_end || end > rule_map_end || begin > end)
- return false;
+ if (e.test(begin >= rule_map_end || end > rule_map_end || begin > end, E_BADRULEMAPPING))
+ {
+ face.error_context((face.error_context() & 0xFFFF00) + EC_ARULEMAP + (n << 24));
+ return face.error(e);
+ }
s->rules = begin;
s->rules_end = (end - begin <= FiniteStateMachine::MAX_RULES)? end :
begin + FiniteStateMachine::MAX_RULES;
@@ -281,9 +300,10 @@ bool Pass::readStates(const byte * starts, const byte *states, const byte * o_ru
return true;
}
-bool Pass::readRanges(const byte * ranges, size_t num_ranges)
+bool Pass::readRanges(const byte * ranges, size_t num_ranges, Error &e)
{
m_cols = gralloc<uint16>(m_numGlyphs);
+ if (e.test(!m_cols, E_OUTOFMEM)) return false;
memset(m_cols, 0xFF, m_numGlyphs * sizeof(uint16));
for (size_t n = num_ranges; n; --n)
{
@@ -291,14 +311,14 @@ bool Pass::readRanges(const byte * ranges, size_t num_ranges)
* ci_end = m_cols + be::read<uint16>(ranges) + 1,
col = be::read<uint16>(ranges);
- if (ci >= ci_end || ci_end > m_cols+m_numGlyphs || col >= m_numColumns)
+ if (e.test(ci >= ci_end || ci_end > m_cols+m_numGlyphs || col >= m_numColumns, E_BADRANGE))
return false;
// A glyph must only belong to one column at a time
while (ci != ci_end && *ci == 0xffff)
*ci++ = col;
- if (ci != ci_end)
+ if (e.test(ci != ci_end, E_BADRANGE))
return false;
}
return true;
@@ -307,13 +327,13 @@ bool Pass::readRanges(const byte * ranges, size_t num_ranges)
void Pass::runGraphite(Machine & m, FiniteStateMachine & fsm) const
{
- Slot *s = m.slotMap().segment.first();
- if (!s || !testPassConstraint(m)) return;
+ Slot *s = m.slotMap().segment.first();
+ if (!s || !testPassConstraint(m)) return;
Slot *currHigh = s->next();
#if !defined GRAPHITE2_NTRACING
- if (fsm.dbgout) *fsm.dbgout << "rules" << json::array;
- json::closer rules_array_closer(fsm.dbgout);
+ if (fsm.dbgout) *fsm.dbgout << "rules" << json::array;
+ json::closer rules_array_closer(fsm.dbgout);
#endif
m.slotMap().highwater(currHigh);
@@ -322,21 +342,21 @@ void Pass::runGraphite(Machine & m, FiniteStateMachine & fsm) const
{
findNDoRule(s, m, fsm);
if (s && (m.slotMap().highpassed() || s == m.slotMap().highwater() || --lc == 0)) {
- if (!lc)
- {
-// if (dbgout) *dbgout << json::item << json::flat << rule_event(-1, s, 1);
- s = m.slotMap().highwater();
- }
- lc = m_iMaxLoop;
+ if (!lc)
+ {
+// if (dbgout) *dbgout << json::item << json::flat << rule_event(-1, s, 1);
+ s = m.slotMap().highwater();
+ }
+ lc = m_iMaxLoop;
if (s)
- m.slotMap().highwater(s->next());
+ m.slotMap().highwater(s->next());
}
} while (s);
}
bool Pass::runFSM(FiniteStateMachine& fsm, Slot * slot) const
{
- fsm.reset(slot, m_maxPreCtxt);
+ fsm.reset(slot, m_maxPreCtxt);
if (fsm.slots.context() < m_minPreCtxt)
return false;
@@ -368,17 +388,17 @@ bool Pass::runFSM(FiniteStateMachine& fsm, Slot * slot) const
inline
Slot * input_slot(const SlotMap & slots, const int n)
{
- Slot * s = slots[slots.context() + n];
- if (!s->isCopied()) return s;
+ Slot * s = slots[slots.context() + n];
+ if (!s->isCopied()) return s;
- return s->prev() ? s->prev()->next() : (s->next() ? s->next()->prev() : slots.segment.last());
+ return s->prev() ? s->prev()->next() : (s->next() ? s->next()->prev() : slots.segment.last());
}
inline
Slot * output_slot(const SlotMap & slots, const int n)
{
- Slot * s = slots[slots.context() + n - 1];
- return s ? s->next() : slots.segment.first();
+ Slot * s = slots[slots.context() + n - 1];
+ return s ? s->next() : slots.segment.first();
}
#endif //!defined GRAPHITE2_NTRACING
@@ -397,40 +417,40 @@ void Pass::findNDoRule(Slot * & slot, Machine &m, FiniteStateMachine & fsm) cons
#if !defined GRAPHITE2_NTRACING
if (fsm.dbgout)
{
- if (fsm.rules.size() != 0)
- {
- *fsm.dbgout << json::item << json::object;
- dumpRuleEventConsidered(fsm, *r);
- if (r != re)
- {
- const int adv = doAction(r->rule->action, slot, m);
- dumpRuleEventOutput(fsm, *r->rule, slot);
- if (r->rule->action->deletes()) fsm.slots.collectGarbage();
- adjustSlot(adv, slot, fsm.slots);
- *fsm.dbgout << "cursor" << objectid(dslot(&fsm.slots.segment, slot))
- << json::close; // Close RuelEvent object
-
- return;
- }
- else
- {
- *fsm.dbgout << json::close // close "considered" array
- << "output" << json::null
- << "cursor" << objectid(dslot(&fsm.slots.segment, slot->next()))
- << json::close;
- }
- }
+ if (fsm.rules.size() != 0)
+ {
+ *fsm.dbgout << json::item << json::object;
+ dumpRuleEventConsidered(fsm, *r);
+ if (r != re)
+ {
+ const int adv = doAction(r->rule->action, slot, m);
+ dumpRuleEventOutput(fsm, *r->rule, slot);
+ if (r->rule->action->deletes()) fsm.slots.collectGarbage();
+ adjustSlot(adv, slot, fsm.slots);
+ *fsm.dbgout << "cursor" << objectid(dslot(&fsm.slots.segment, slot))
+ << json::close; // Close RuelEvent object
+
+ return;
+ }
+ else
+ {
+ *fsm.dbgout << json::close // close "considered" array
+ << "output" << json::null
+ << "cursor" << objectid(dslot(&fsm.slots.segment, slot->next()))
+ << json::close;
+ }
+ }
}
else
#endif
{
- if (r != re)
- {
- const int adv = doAction(r->rule->action, slot, m);
- if (r->rule->action->deletes()) fsm.slots.collectGarbage();
- adjustSlot(adv, slot, fsm.slots);
- return;
- }
+ if (r != re)
+ {
+ const int adv = doAction(r->rule->action, slot, m);
+ if (r->rule->action->deletes()) fsm.slots.collectGarbage();
+ adjustSlot(adv, slot, fsm.slots);
+ return;
+ }
}
}
@@ -441,47 +461,47 @@ void Pass::findNDoRule(Slot * & slot, Machine &m, FiniteStateMachine & fsm) cons
void Pass::dumpRuleEventConsidered(const FiniteStateMachine & fsm, const RuleEntry & re) const
{
- *fsm.dbgout << "considered" << json::array;
- for (const RuleEntry *r = fsm.rules.begin(); r != &re; ++r)
- {
- if (r->rule->preContext > fsm.slots.context()) continue;
- *fsm.dbgout << json::flat << json::object
- << "id" << r->rule - m_rules
- << "failed" << true
- << "input" << json::flat << json::object
- << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, -r->rule->preContext)))
- << "length" << r->rule->sort
- << json::close // close "input"
- << json::close; // close Rule object
- }
+ *fsm.dbgout << "considered" << json::array;
+ for (const RuleEntry *r = fsm.rules.begin(); r != &re; ++r)
+ {
+ if (r->rule->preContext > fsm.slots.context()) continue;
+ *fsm.dbgout << json::flat << json::object
+ << "id" << r->rule - m_rules
+ << "failed" << true
+ << "input" << json::flat << json::object
+ << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, -r->rule->preContext)))
+ << "length" << r->rule->sort
+ << json::close // close "input"
+ << json::close; // close Rule object
+ }
}
void Pass::dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & r, Slot * const last_slot) const
{
- *fsm.dbgout << json::item << json::flat << json::object
- << "id" << &r - m_rules
- << "failed" << false
- << "input" << json::flat << json::object
- << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, 0)))
- << "length" << r.sort - r.preContext
- << json::close // close "input"
- << json::close // close Rule object
- << json::close // close considered array
- << "output" << json::object
- << "range" << json::flat << json::object
- << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, 0)))
- << "end" << objectid(dslot(&fsm.slots.segment, last_slot))
- << json::close // close "input"
- << "slots" << json::array;
- const Position rsb_prepos = last_slot ? last_slot->origin() : fsm.slots.segment.advance();
- fsm.slots.segment.positionSlots(0);
-
- for(Slot * slot = output_slot(fsm.slots, 0); slot != last_slot; slot = slot->next())
- *fsm.dbgout << dslot(&fsm.slots.segment, slot);
- *fsm.dbgout << json::close // close "slots"
- << "postshift" << (last_slot ? last_slot->origin() : fsm.slots.segment.advance()) - rsb_prepos
- << json::close; // close "output" object
+ *fsm.dbgout << json::item << json::flat << json::object
+ << "id" << &r - m_rules
+ << "failed" << false
+ << "input" << json::flat << json::object
+ << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, 0)))
+ << "length" << r.sort - r.preContext
+ << json::close // close "input"
+ << json::close // close Rule object
+ << json::close // close considered array
+ << "output" << json::object
+ << "range" << json::flat << json::object
+ << "start" << objectid(dslot(&fsm.slots.segment, input_slot(fsm.slots, 0)))
+ << "end" << objectid(dslot(&fsm.slots.segment, last_slot))
+ << json::close // close "input"
+ << "slots" << json::array;
+ const Position rsb_prepos = last_slot ? last_slot->origin() : fsm.slots.segment.advance();
+ fsm.slots.segment.positionSlots(0);
+
+ for(Slot * slot = output_slot(fsm.slots, 0); slot != last_slot; slot = slot->next())
+ *fsm.dbgout << dslot(&fsm.slots.segment, slot);
+ *fsm.dbgout << json::close // close "slots"
+ << "postshift" << (last_slot ? last_slot->origin() : fsm.slots.segment.advance()) - rsb_prepos
+ << json::close; // close "output" object
}
@@ -503,7 +523,7 @@ bool Pass::testPassConstraint(Machine & m) const
#if !defined GRAPHITE2_NTRACING
json * const dbgout = m.slotMap().segment.getFace()->logger();
if (dbgout)
- *dbgout << "constraint" << (ret && m.status() == Machine::finished);
+ *dbgout << "constraint" << (ret && m.status() == Machine::finished);
#endif
return ret && m.status() == Machine::finished;
@@ -512,16 +532,16 @@ bool Pass::testPassConstraint(Machine & m) const
bool Pass::testConstraint(const Rule & r, Machine & m) const
{
- const uint16 curr_context = m.slotMap().context();
+ const uint16 curr_context = m.slotMap().context();
if (unsigned(r.sort - r.preContext) > m.slotMap().size() - curr_context
- || curr_context - r.preContext < 0) return false;
+ || curr_context - r.preContext < 0) return false;
if (!*r.constraint) return true;
assert(r.constraint->constraint());
vm::slotref * map = m.slotMap().begin() + curr_context - r.preContext;
for (int n = r.sort; n && map; --n, ++map)
{
- if (!*map) continue;
+ if (!*map) continue;
const int32 ret = r.constraint->run(m, map);
if (!ret || m.status() != Machine::finished)
return false;
@@ -554,9 +574,9 @@ int Pass::doAction(const Code *codeptr, Slot * & slot_out, vm::Machine & m) cons
if (m.status() != Machine::finished)
{
- slot_out = NULL;
- smap.highwater(0);
- return 0;
+ slot_out = NULL;
+ smap.highwater(0);
+ return 0;
}
slot_out = *map;
@@ -573,12 +593,12 @@ void Pass::adjustSlot(int delta, Slot * & slot_out, SlotMap & smap) const
slot_out = smap.segment.last();
++delta;
if (smap.highpassed() && !smap.highwater())
- smap.highpassed(false);
+ smap.highpassed(false);
}
while (++delta <= 0 && slot_out)
{
if (smap.highpassed() && smap.highwater() == slot_out)
- smap.highpassed(false);
+ smap.highpassed(false);
slot_out = slot_out->prev();
}
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Rule.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Rule.cpp
index afdab495f53..34c8ae1691f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Rule.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Rule.cpp
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2011, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCache.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCache.cpp
index 446dfbec43f..446dfbec43f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCache.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCache.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheEntry.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheEntry.cpp
index 5e87646185a..d35912d5aed 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheEntry.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheEntry.cpp
@@ -41,12 +41,13 @@ SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment *
m_attr(NULL), m_justs(NULL),
m_accessCount(0), m_lastAccess(cacheTime)
{
- for (uint16 i = 0; i < length; i++)
- {
- m_unicode[i] = cmapGlyphs[i];
- }
+ if (m_unicode)
+ for (uint16 i = 0; i < length; i++)
+ m_unicode[i] = cmapGlyphs[i];
+
const size_t glyphCount = seg->slotCount(),
sizeof_sjust = SlotJustify::size_of(seg->silf()->numJustLevels());
+ if (!glyphCount) return;
size_t num_justs = 0,
justs_pos = 0;
if (seg->hasJustification())
@@ -61,6 +62,7 @@ SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment *
const Slot * slot = seg->first();
m_glyph = new Slot[glyphCount];
m_attr = gralloc<int16>(glyphCount * seg->numAttrs());
+ if (!m_glyph || (!m_attr && seg->numAttrs())) return;
m_glyphLength = glyphCount;
Slot * slotCopy = m_glyph;
m_glyph->prev(NULL);
@@ -70,14 +72,14 @@ SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment *
{
slotCopy->userAttrs(m_attr + pos * seg->numAttrs());
slotCopy->m_justs = m_justs ? reinterpret_cast<SlotJustify *>(m_justs + justs_pos++ * sizeof_sjust) : 0;
- slotCopy->set(*slot, -static_cast<int32>(charOffset), seg->numAttrs(), seg->silf()->numJustLevels());
+ slotCopy->set(*slot, -static_cast<int32>(charOffset), seg->numAttrs(), seg->silf()->numJustLevels(), length);
slotCopy->index(pos);
if (slot->firstChild())
- slotCopy->m_child = m_glyph + slot->firstChild()->index();
+ slotCopy->m_child = m_glyph + slot->firstChild()->index();
if (slot->attachedTo())
- slotCopy->attachTo(m_glyph + slot->attachedTo()->index());
+ slotCopy->attachTo(m_glyph + slot->attachedTo()->index());
if (slot->nextSibling())
- slotCopy->m_sibling = m_glyph + slot->nextSibling()->index();
+ slotCopy->m_sibling = m_glyph + slot->nextSibling()->index();
slot = slot->next();
++slotCopy;
++pos;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheStore.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheStore.cpp
index 236fb707ffa..236fb707ffa 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/SegCacheStore.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/SegCacheStore.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Segment.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Segment.cpp
index ccce282bf3f..42d7be57c26 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Segment.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Segment.cpp
@@ -36,6 +36,7 @@ of the License or (at your option) any later version.
#include "inc/Slot.h"
#include "inc/Main.h"
#include "inc/CmapCache.h"
+#include "inc/Bidi.h"
#include "graphite2/Segment.h"
@@ -106,15 +107,15 @@ void Segment::removeScope(SegmentScopeState & state)
m_defaultOriginal = 0;
}
-
+#if 0
void Segment::append(const Segment &other)
{
Rect bbox = other.m_bbox + m_advance;
m_slots.insert(m_slots.end(), other.m_slots.begin(), other.m_slots.end());
- CharInfo* pNewCharInfo = new CharInfo[m_numCharinfo+other.m_numCharinfo]; //since CharInfo has no constructor, this doesn't do much
+ CharInfo* pNewCharInfo = new CharInfo[m_numCharinfo+other.m_numCharinfo]; //since CharInfo has no constructor, this doesn't do much
for (unsigned int i=0 ; i<m_numCharinfo ; ++i)
- pNewCharInfo[i] = m_charinfo[i];
+ pNewCharInfo[i] = m_charinfo[i];
m_last->next(other.m_first);
other.m_last->prev(m_last);
m_userAttrs.insert(m_userAttrs.end(), other.m_userAttrs.begin(), other.m_userAttrs.end());
@@ -131,12 +132,14 @@ void Segment::append(const Segment &other)
m_bbox = m_bbox.widen(bbox);
m_passBits &= other.passBits();
}
+#endif
#endif // GRAPHITE2_NSEGCACHE
void Segment::appendSlot(int id, int cid, int gid, int iFeats, size_t coffset)
{
Slot *aSlot = newSlot();
+ if (!aSlot) return;
m_charinfo[id].init(cid);
m_charinfo[id].feats(iFeats);
m_charinfo[id].base(coffset);
@@ -167,14 +170,15 @@ Slot *Segment::newSlot()
#endif
Slot *newSlots = grzeroalloc<Slot>(m_bufSize);
int16 *newAttrs = grzeroalloc<int16>(numUser * m_bufSize);
- newSlots[0].userAttrs(newAttrs);
- for (size_t i = 1; i < m_bufSize - 1; i++)
+ if (!newSlots || !newAttrs) return NULL;
+ for (size_t i = 0; i < m_bufSize; i++)
{
newSlots[i].next(newSlots + i + 1);
newSlots[i].userAttrs(newAttrs + i * numUser);
+ newSlots[i].setBidiClass(-1);
}
- newSlots[m_bufSize - 1].userAttrs(newAttrs + (m_bufSize - 1) * numUser);
newSlots[m_bufSize - 1].next(NULL);
+ newSlots[0].next(NULL);
m_slots.push_back(newSlots);
m_userAttrs.push_back(newAttrs);
m_freeSlots = (m_bufSize > 1)? newSlots + 1 : NULL;
@@ -219,6 +223,7 @@ SlotJustify *Segment::newJustify()
{
const size_t justSize = SlotJustify::size_of(m_silf->numJustLevels());
byte *justs = grzeroalloc<byte>(justSize * m_bufSize);
+ if (!justs) return NULL;
for (int i = m_bufSize - 2; i >= 0; --i)
{
SlotJustify *p = reinterpret_cast<SlotJustify *>(justs + justSize * i);
@@ -248,6 +253,7 @@ void Segment::splice(size_t offset, size_t length, Slot * const startSlot,
Slot * endSlot, const Slot * srcSlot,
const size_t numGlyphs)
{
+ size_t numChars = length;
extendLength(numGlyphs - length);
// remove any extra
if (numGlyphs < length)
@@ -268,6 +274,7 @@ void Segment::splice(size_t offset, size_t length, Slot * const startSlot,
while (numGlyphs > length)
{
Slot * extra = newSlot();
+ if (!extra) return;
extra->prev(endSlot);
extra->next(endSlot->next());
endSlot->next(extra);
@@ -282,60 +289,60 @@ void Segment::splice(size_t offset, size_t length, Slot * const startSlot,
endSlot = endSlot->next();
assert(numGlyphs == length);
+ assert(offset + numChars <= m_numCharinfo);
Slot * indexmap[eMaxSpliceSize*3];
assert(numGlyphs < sizeof indexmap/sizeof *indexmap);
Slot * slot = startSlot;
for (uint16 i=0; i < numGlyphs; slot = slot->next(), ++i)
- indexmap[i] = slot;
+ indexmap[i] = slot;
- slot = startSlot;
- for (slot=startSlot; slot != endSlot; slot = slot->next(), srcSlot = srcSlot->next())
+ for (slot = startSlot; slot != endSlot; slot = slot->next(), srcSlot = srcSlot->next())
{
- slot->set(*srcSlot, offset, m_silf->numUser(), m_silf->numJustLevels());
- if (srcSlot->attachedTo()) slot->attachTo(indexmap[srcSlot->attachedTo()->index()]);
- if (srcSlot->nextSibling()) slot->m_sibling = indexmap[srcSlot->nextSibling()->index()];
- if (srcSlot->firstChild()) slot->m_child = indexmap[srcSlot->firstChild()->index()];
+ slot->set(*srcSlot, offset, m_silf->numUser(), m_silf->numJustLevels(), numChars);
+ if (srcSlot->attachedTo()) slot->attachTo(indexmap[srcSlot->attachedTo()->index()]);
+ if (srcSlot->nextSibling()) slot->m_sibling = indexmap[srcSlot->nextSibling()->index()];
+ if (srcSlot->firstChild()) slot->m_child = indexmap[srcSlot->firstChild()->index()];
}
}
#endif // GRAPHITE2_NSEGCACHE
void Segment::linkClusters(Slot *s, Slot * end)
{
- end = end->next();
-
- for (; s != end && !s->isBase(); s = s->next());
- Slot * ls = s;
-
- if (m_dir & 1)
- {
- for (; s != end; s = s->next())
- {
- if (!s->isBase()) continue;
-
- s->sibling(ls);
- ls = s;
- }
- }
- else
- {
- for (; s != end; s = s->next())
- {
- if (!s->isBase()) continue;
-
- ls->sibling(s);
- ls = s;
- }
- }
+ end = end->next();
+
+ for (; s != end && !s->isBase(); s = s->next());
+ Slot * ls = s;
+
+ if (m_dir & 1)
+ {
+ for (; s != end; s = s->next())
+ {
+ if (!s->isBase()) continue;
+
+ s->sibling(ls);
+ ls = s;
+ }
+ }
+ else
+ {
+ for (; s != end; s = s->next())
+ {
+ if (!s->isBase()) continue;
+
+ ls->sibling(s);
+ ls = s;
+ }
+ }
}
Position Segment::positionSlots(const Font *font, Slot * iStart, Slot * iEnd)
{
Position currpos(0., 0.);
- Rect bbox;
float clusterMin = 0.;
+ Rect bbox;
- if (!iStart) iStart = m_first;
- if (!iEnd) iEnd = m_last;
+ if (!iStart) iStart = m_first;
+ if (!iEnd) iEnd = m_last;
if (m_dir & 1)
{
@@ -357,20 +364,39 @@ Position Segment::positionSlots(const Font *font, Slot * iStart, Slot * iEnd)
}
-void Segment::associateChars()
+void Segment::associateChars(int offset, int numChars)
{
- int i = 0;
+ int i = 0, j = 0;
+ CharInfo *c, *cend;
+ for (c = m_charinfo + offset, cend = m_charinfo + offset + numChars; c != cend; ++c)
+ {
+ c->before(-1);
+ c->after(-1);
+ }
for (Slot * s = m_first; s; s->index(i++), s = s->next())
{
- int j = s->before();
- if (j < 0) continue;
+ j = s->before();
+ if (j < 0) continue;
for (const int after = s->after(); j <= after; ++j)
- {
- CharInfo & c = *charinfo(j);
- if (c.before() == -1 || i < c.before()) c.before(i);
- if (c.after() < i) c.after(i);
- }
+ {
+ c = charinfo(j);
+ if (c->before() == -1 || i < c->before()) c->before(i);
+ if (c->after() < i) c->after(i);
+ }
+ }
+ for (Slot *s = m_first; s; s = s->next())
+ {
+ int a;
+ for (a = s->after() + 1; a < offset + numChars && charinfo(a)->after() < 0; ++a)
+ { charinfo(a)->after(s->index()); }
+ --a;
+ s->after(a);
+
+ for (a = s->before() - 1; a >= offset && charinfo(a)->before() < 0; --a)
+ { charinfo(a)->before(s->index()); }
+ ++a;
+ s->before(a);
}
}
@@ -378,31 +404,34 @@ void Segment::associateChars()
template <typename utf_iter>
inline void process_utf_data(Segment & seg, const Face & face, const int fid, utf_iter c, size_t n_chars)
{
- const Cmap & cmap = face.cmap();
- int slotid = 0;
-
- const typename utf_iter::codeunit_type * const base = c;
- for (; n_chars; --n_chars, ++c, ++slotid)
- {
- const uint32 usv = *c;
- uint16 gid = cmap[usv];
- if (!gid) gid = face.findPseudo(usv);
- seg.appendSlot(slotid, usv, gid, fid, c - base);
- }
+ const Cmap & cmap = face.cmap();
+ int slotid = 0;
+
+ const typename utf_iter::codeunit_type * const base = c;
+ for (; n_chars; --n_chars, ++c, ++slotid)
+ {
+ const uint32 usv = *c;
+ uint16 gid = cmap[usv];
+ if (!gid) gid = face.findPseudo(usv);
+ seg.appendSlot(slotid, usv, gid, fid, c - base);
+ }
}
-void Segment::read_text(const Face *face, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void* pStart, size_t nChars)
+bool Segment::read_text(const Face *face, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void* pStart, size_t nChars)
{
- assert(face);
- assert(pFeats);
-
- switch (enc)
- {
- case gr_utf8: process_utf_data(*this, *face, addFeatures(*pFeats), utf8::const_iterator(pStart), nChars); break;
- case gr_utf16: process_utf_data(*this, *face, addFeatures(*pFeats), utf16::const_iterator(pStart), nChars); break;
- case gr_utf32: process_utf_data(*this, *face, addFeatures(*pFeats), utf32::const_iterator(pStart), nChars); break;
- }
+ assert(face);
+ assert(pFeats);
+ if (!m_charinfo) return false;
+
+ // utf iterator is self recovering so we don't care about the error state of the iterator.
+ switch (enc)
+ {
+ case gr_utf8: process_utf_data(*this, *face, addFeatures(*pFeats), utf8::const_iterator(pStart), nChars); break;
+ case gr_utf16: process_utf_data(*this, *face, addFeatures(*pFeats), utf16::const_iterator(pStart), nChars); break;
+ case gr_utf32: process_utf_data(*this, *face, addFeatures(*pFeats), utf32::const_iterator(pStart), nChars); break;
+ }
+ return true;
}
void Segment::prepare_pos(const Font * /*font*/)
@@ -410,41 +439,48 @@ void Segment::prepare_pos(const Font * /*font*/)
// copy key changeable metrics into slot (if any);
}
-Slot *resolveExplicit(int level, int dir, Slot *s, int nNest = 0);
-void resolveWeak(int baseLevel, Slot *s);
-void resolveNeutrals(int baseLevel, Slot *s);
+Slot *process_bidi(Slot *start, int level, int prelevel, int &nextLevel, int dirover, int isol, int &cisol, int &isolerr, int &embederr, int init, Segment *seg, uint8 aMirror, BracketPairStack &stack);
void resolveImplicit(Slot *s, Segment *seg, uint8 aMirror);
-void resolveWhitespace(int baseLevel, Segment *seg, uint8 aBidi, Slot *s);
+void resolveWhitespace(int baseLevel, Slot *s);
Slot *resolveOrder(Slot * & s, const bool reordered, const int level = 0);
void Segment::bidiPass(uint8 aBidi, int paradir, uint8 aMirror)
{
- if (slotCount() == 0)
- return;
+ if (slotCount() == 0)
+ return;
Slot *s;
int baseLevel = paradir ? 1 : 0;
unsigned int bmask = 0;
+ unsigned int ssize = 0;
for (s = first(); s; s = s->next())
{
- unsigned int bAttr = glyphAttr(s->gid(), aBidi);
- s->setBidiClass((bAttr <= 16) * bAttr);
+ if (s->getBidiClass() == -1)
+ {
+ unsigned int bAttr = glyphAttr(s->gid(), aBidi);
+ s->setBidiClass((bAttr <= 22) * bAttr);
+ }
bmask |= (1 << s->getBidiClass());
s->setBidiLevel(baseLevel);
+ if (glyphAttr(s->gid(), aMirror) && s->getBidiClass() == 21)
+ ++ssize;
}
- if (bmask & (paradir ? 0x92 : 0x9C))
+
+ BracketPairStack bstack(ssize);
+ if (bmask & (paradir ? 0x2E7892 : 0x2E789C))
{
- if (bmask & 0xF800)
- resolveExplicit(baseLevel, 0, first(), 0);
- if (bmask & 0x10178)
- resolveWeak(baseLevel, first());
- if (bmask & 0x361)
- resolveNeutrals(baseLevel, first());
+ // O(8N) algorithm, with no working data beyond what is needed for processParens
+ int nextLevel = paradir;
+ int e, i, c;
+ process_bidi(first(), baseLevel, paradir, nextLevel, 0, 0, c = 0, i = 0, e = 0, 1, this, aMirror, bstack);
resolveImplicit(first(), this, aMirror);
- resolveWhitespace(baseLevel, this, aBidi, last());
+ resolveWhitespace(baseLevel, last());
s = resolveOrder(s = first(), baseLevel != 0);
- first(s); last(s->prev());
- s->prev()->next(0); s->prev(0);
+ if (s)
+ {
+ first(s); last(s->prev());
+ s->prev()->next(0); s->prev(0);
+ }
}
else if (!(dir() & 4) && baseLevel && aMirror)
{
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/Silf.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Silf.cpp
new file mode 100644
index 00000000000..8b77271d2b4
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Silf.cpp
@@ -0,0 +1,415 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2010, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#include <cstdlib>
+#include "graphite2/Segment.h"
+#include "inc/debug.h"
+#include "inc/Endian.h"
+#include "inc/Silf.h"
+#include "inc/Segment.h"
+#include "inc/Rule.h"
+#include "inc/Error.h"
+
+
+using namespace graphite2;
+
+namespace { static const uint32 ERROROFFSET = 0xFFFFFFFF; }
+
+Silf::Silf() throw()
+: m_passes(0),
+ m_pseudos(0),
+ m_classOffsets(0),
+ m_classData(0),
+ m_justs(0),
+ m_numPasses(0),
+ m_numJusts(0),
+ m_sPass(0),
+ m_pPass(0),
+ m_jPass(0),
+ m_bPass(0),
+ m_flags(0),
+ m_aPseudo(0),
+ m_aBreak(0),
+ m_aUser(0),
+ m_aBidi(0),
+ m_aMirror(0),
+ m_aPassBits(0),
+ m_iMaxComp(0),
+ m_aLig(0),
+ m_numPseudo(0),
+ m_nClass(0),
+ m_nLinear(0),
+ m_gEndLine(0)
+{
+ memset(&m_silfinfo, 0, sizeof m_silfinfo);
+}
+
+Silf::~Silf() throw()
+{
+ releaseBuffers();
+}
+
+void Silf::releaseBuffers() throw()
+{
+ delete [] m_passes;
+ delete [] m_pseudos;
+ free(m_classOffsets);
+ free(m_classData);
+ free(m_justs);
+ m_passes= 0;
+ m_pseudos = 0;
+ m_classOffsets = 0;
+ m_classData = 0;
+ m_justs = 0;
+}
+
+
+bool Silf::readGraphite(const byte * const silf_start, size_t lSilf, Face& face, uint32 version)
+{
+ const byte * p = silf_start,
+ * const silf_end = p + lSilf;
+ Error e;
+
+ if (version >= 0x00030000)
+ {
+ if (e.test(lSilf < 28, E_BADSIZE)) { releaseBuffers(); return face.error(e); }
+ be::skip<int32>(p); // ruleVersion
+ be::skip<uint16>(p,2); // passOffset & pseudosOffset
+ }
+ else if (e.test(lSilf < 20, E_BADSIZE)) { releaseBuffers(); return face.error(e); }
+ const uint16 maxGlyph = be::read<uint16>(p);
+ m_silfinfo.extra_ascent = be::read<uint16>(p);
+ m_silfinfo.extra_descent = be::read<uint16>(p);
+ m_numPasses = be::read<uint8>(p);
+ m_sPass = be::read<uint8>(p);
+ m_pPass = be::read<uint8>(p);
+ m_jPass = be::read<uint8>(p);
+ m_bPass = be::read<uint8>(p);
+ m_flags = be::read<uint8>(p);
+ be::skip<uint8>(p,2); // max{Pre,Post}Context.
+ m_aPseudo = be::read<uint8>(p);
+ m_aBreak = be::read<uint8>(p);
+ m_aBidi = be::read<uint8>(p);
+ m_aMirror = be::read<uint8>(p);
+ m_aPassBits = be::read<uint8>(p);
+
+ // Read Justification levels.
+ m_numJusts = be::read<uint8>(p);
+ if (e.test(maxGlyph >= face.glyphs().numGlyphs(), E_BADMAXGLYPH)
+ || e.test(p + m_numJusts * 8 >= silf_end, E_BADNUMJUSTS))
+ {
+ releaseBuffers(); return face.error(e);
+ }
+
+ if (m_numJusts)
+ {
+ m_justs = gralloc<Justinfo>(m_numJusts);
+ if (e.test(!m_justs, E_OUTOFMEM)) return face.error(e);
+
+ for (uint8 i = 0; i < m_numJusts; i++)
+ {
+ ::new(m_justs + i) Justinfo(p[0], p[1], p[2], p[3]);
+ be::skip<byte>(p,8);
+ }
+ }
+
+ if (e.test(p + sizeof(uint16) + sizeof(uint8)*8 >= silf_end, E_BADENDJUSTS)) { releaseBuffers(); return face.error(e); }
+ m_aLig = be::read<uint16>(p);
+ m_aUser = be::read<uint8>(p);
+ m_iMaxComp = be::read<uint8>(p);
+ be::skip<byte>(p,5); // direction and 4 reserved bytes
+ be::skip<uint16>(p, be::read<uint8>(p)); // don't need critical features yet
+ be::skip<byte>(p); // reserved
+ if (e.test(p >= silf_end, E_BADCRITFEATURES)) { releaseBuffers(); return face.error(e); }
+ be::skip<uint32>(p, be::read<uint8>(p)); // don't use scriptTag array.
+ if (e.test(p + sizeof(uint16) + sizeof(uint32) >= silf_end, E_BADSCRIPTTAGS)) { releaseBuffers(); return face.error(e); }
+ m_gEndLine = be::read<uint16>(p); // lbGID
+ const byte * o_passes = p,
+ * const passes_start = silf_start + be::read<uint32>(p);
+
+ const size_t num_attrs = face.glyphs().numAttrs();
+ if (e.test(m_aPseudo >= num_attrs, E_BADAPSEUDO)
+ || e.test(m_aBreak >= num_attrs, E_BADABREAK)
+ || e.test(m_aBidi >= num_attrs, E_BADABIDI)
+ || e.test(m_aMirror>= num_attrs, E_BADAMIRROR)
+ || e.test(m_numPasses > 128, E_BADNUMPASSES) || e.test(passes_start >= silf_end, E_BADPASSESSTART)
+ || e.test(m_pPass < m_sPass, E_BADPASSBOUND) || e.test(m_pPass > m_numPasses, E_BADPPASS) || e.test(m_sPass > m_numPasses, E_BADSPASS)
+ || e.test(m_jPass < m_pPass, E_BADJPASSBOUND) || e.test(m_jPass > m_numPasses, E_BADJPASS)
+ || e.test((m_bPass != 0xFF && (m_bPass < m_jPass || m_bPass > m_numPasses)), E_BADBPASS)
+ || e.test(m_aLig > 127, E_BADALIG))
+ {
+ releaseBuffers();
+ return face.error(e);
+ }
+ be::skip<uint32>(p, m_numPasses);
+ if (e.test(p + sizeof(uint16) >= passes_start, E_BADPASSESSTART)) { releaseBuffers(); return face.error(e); }
+ m_numPseudo = be::read<uint16>(p);
+ be::skip<uint16>(p, 3); // searchPseudo, pseudoSelector, pseudoShift
+ if (e.test(p + m_numPseudo*(sizeof(uint32) + sizeof(uint16)) >= passes_start, E_BADNUMPSEUDO))
+ {
+ releaseBuffers(); return face.error(e);
+ }
+ m_pseudos = new Pseudo[m_numPseudo];
+ for (int i = 0; i < m_numPseudo; i++)
+ {
+ m_pseudos[i].uid = be::read<uint32>(p);
+ m_pseudos[i].gid = be::read<uint16>(p);
+ }
+
+ const size_t clen = readClassMap(p, passes_start - p, version, e);
+ if (e || e.test(p + clen > passes_start, E_BADPASSESSTART)) { releaseBuffers(); return face.error(e); }
+
+ m_passes = new Pass[m_numPasses];
+ for (size_t i = 0; i < m_numPasses; ++i)
+ {
+ const byte * const pass_start = silf_start + be::read<uint32>(o_passes),
+ * const pass_end = silf_start + be::peek<uint32>(o_passes);
+ face.error_context((face.error_context() & 0xFF00) + EC_ASILF + (i << 16));
+ if (e.test(pass_start > pass_end, E_BADPASSSTART) || e.test(pass_end > silf_end, E_BADPASSEND)) {
+ releaseBuffers(); return face.error(e);
+ }
+
+ m_passes[i].init(this);
+ if (!m_passes[i].readPass(pass_start, pass_end - pass_start, pass_start - silf_start, face, e))
+ {
+ releaseBuffers();
+ return false;
+ }
+ }
+
+ // fill in gr_faceinfo
+ m_silfinfo.upem = face.glyphs().unitsPerEm();
+ m_silfinfo.has_bidi_pass = (m_bPass != 0xFF);
+ m_silfinfo.justifies = (m_numJusts != 0) || (m_jPass < m_pPass);
+ m_silfinfo.line_ends = (m_flags & 1);
+ m_silfinfo.space_contextuals = gr_faceinfo::gr_space_contextuals((m_flags >> 2) & 0x7);
+ return true;
+}
+
+template<typename T> inline uint32 Silf::readClassOffsets(const byte *&p, size_t data_len, Error &e)
+{
+ const T cls_off = 2*sizeof(uint16) + sizeof(T)*(m_nClass+1);
+ const size_t max_off = (be::peek<T>(p + sizeof(T)*m_nClass) - cls_off)/sizeof(uint16);
+ // Check that the last+1 offset is less than or equal to the class map length.
+ if (e.test(be::peek<T>(p) != cls_off, E_MISALIGNEDCLASSES)
+ || e.test(max_off > (data_len - cls_off)/sizeof(uint16), E_HIGHCLASSOFFSET))
+ return ERROROFFSET;
+
+ // Read in all the offsets.
+ m_classOffsets = gralloc<uint32>(m_nClass+1);
+ if (e.test(!m_classOffsets, E_OUTOFMEM)) return ERROROFFSET;
+ for (uint32 * o = m_classOffsets, * const o_end = o + m_nClass + 1; o != o_end; ++o)
+ {
+ *o = (be::read<T>(p) - cls_off)/sizeof(uint16);
+ if (e.test(*o > max_off, E_HIGHCLASSOFFSET))
+ return ERROROFFSET;
+ }
+ return max_off;
+}
+
+size_t Silf::readClassMap(const byte *p, size_t data_len, uint32 version, Error &e)
+{
+ if (e.test(data_len < sizeof(uint16)*2, E_BADCLASSSIZE)) return ERROROFFSET;
+
+ m_nClass = be::read<uint16>(p);
+ m_nLinear = be::read<uint16>(p);
+
+ // Check that numLinear < numClass,
+ // that there is at least enough data for numClasses offsets.
+ if (e.test(m_nLinear > m_nClass, E_TOOMANYLINEAR)
+ || e.test((m_nClass + 1) * (version >= 0x00040000 ? sizeof(uint32) : sizeof(uint16)) > (data_len - 4), E_CLASSESTOOBIG))
+ return ERROROFFSET;
+
+ uint32 max_off;
+ if (version >= 0x00040000)
+ max_off = readClassOffsets<uint32>(p, data_len, e);
+ else
+ max_off = readClassOffsets<uint16>(p, data_len, e);
+
+ if (max_off == ERROROFFSET) return ERROROFFSET;
+
+ // Check the linear offsets are sane, these must be monotonically increasing.
+ for (const uint32 *o = m_classOffsets, * const o_end = o + m_nLinear; o != o_end; ++o)
+ if (e.test(o[0] > o[1], E_BADCLASSOFFSET))
+ return ERROROFFSET;
+
+ // Fortunately the class data is all uint16s so we can decode these now
+ m_classData = gralloc<uint16>(max_off);
+ if (e.test(!m_classData, E_OUTOFMEM)) return ERROROFFSET;
+ for (uint16 *d = m_classData, * const d_end = d + max_off; d != d_end; ++d)
+ *d = be::read<uint16>(p);
+
+ // Check the lookup class invariants for each non-linear class
+ for (const uint32 *o = m_classOffsets + m_nLinear, * const o_end = m_classOffsets + m_nClass; o != o_end; ++o)
+ {
+ const uint16 * lookup = m_classData + *o;
+ if (e.test(*o > max_off - 4, E_HIGHCLASSOFFSET) // LookupClass doesn't stretch over max_off
+ || e.test(lookup[0] == 0 // A LookupClass with no looks is a suspicious thing ...
+ || lookup[0] > (max_off - *o - 4)/2 // numIDs lookup pairs fits within (start of LookupClass' lookups array, max_off]
+ || lookup[3] != lookup[0] - lookup[1], E_BADCLASSLOOKUPINFO)) // rangeShift: numIDs - searchRange
+ return ERROROFFSET;
+ }
+
+ return max_off;
+}
+
+uint16 Silf::findPseudo(uint32 uid) const
+{
+ for (int i = 0; i < m_numPseudo; i++)
+ if (m_pseudos[i].uid == uid) return m_pseudos[i].gid;
+ return 0;
+}
+
+uint16 Silf::findClassIndex(uint16 cid, uint16 gid) const
+{
+ if (cid > m_nClass) return -1;
+
+ const uint16 * cls = m_classData + m_classOffsets[cid];
+ if (cid < m_nLinear) // output class being used for input, shouldn't happen
+ {
+ for (unsigned int i = 0, n = m_classOffsets[cid + 1]; i < n; ++i, ++cls)
+ if (*cls == gid) return i;
+ return -1;
+ }
+ else
+ {
+ const uint16 * min = cls + 4, // lookups array
+ * max = min + cls[0]*2; // lookups aray is numIDs (cls[0]) uint16 pairs long
+ do
+ {
+ const uint16 * p = min + (-2 & ((max-min)/2));
+ if (p[0] > gid) max = p;
+ else min = p;
+ }
+ while (max - min > 2);
+ return min[0] == gid ? min[1] : -1;
+ }
+}
+
+uint16 Silf::getClassGlyph(uint16 cid, unsigned int index) const
+{
+ if (cid > m_nClass) return 0;
+
+ uint32 loc = m_classOffsets[cid];
+ if (cid < m_nLinear)
+ {
+ if (index < m_classOffsets[cid + 1] - loc)
+ return m_classData[index + loc];
+ }
+ else // input class being used for output. Shouldn't happen
+ {
+ for (unsigned int i = loc + 4; i < m_classOffsets[cid + 1]; i += 2)
+ if (m_classData[i + 1] == index) return m_classData[i];
+ }
+ return 0;
+}
+
+
+bool Silf::runGraphite(Segment *seg, uint8 firstPass, uint8 lastPass, int dobidi) const
+{
+ assert(seg != 0);
+ SlotMap map(*seg);
+ FiniteStateMachine fsm(map, seg->getFace()->logger());
+ vm::Machine m(map);
+ unsigned int initSize = seg->slotCount();
+ uint8 lbidi = m_bPass;
+#if !defined GRAPHITE2_NTRACING
+ json * const dbgout = seg->getFace()->logger();
+#endif
+
+ if (lastPass == 0)
+ {
+ if (firstPass == lastPass && lbidi == 0xFF)
+ return true;
+ lastPass = m_numPasses;
+ }
+ if (firstPass <= lbidi && lastPass >= lbidi && dobidi)
+ lastPass++;
+ else
+ lbidi = 0xFF;
+
+ for (size_t i = firstPass; i < lastPass; ++i)
+ {
+ // bidi and mirroring
+ if (i == lbidi)
+ {
+#if !defined GRAPHITE2_NTRACING
+ if (dbgout)
+ {
+ *dbgout << json::item << json::object
+ << "id" << -1
+ << "slots" << json::array;
+ seg->positionSlots(0);
+ for(Slot * s = seg->first(); s; s = s->next())
+ *dbgout << dslot(seg, s);
+ *dbgout << json::close
+ << "rules" << json::array << json::close
+ << json::close;
+ }
+#endif
+
+ if (!(seg->dir() & 2))
+ seg->bidiPass(m_aBidi, seg->dir() & 1, m_aMirror);
+ else if (m_aMirror)
+ {
+ Slot * s;
+ for (s = seg->first(); s; s = s->next())
+ {
+ unsigned short g = seg->glyphAttr(s->gid(), m_aMirror);
+ if (g && (!(seg->dir() & 4) || !seg->glyphAttr(s->gid(), m_aMirror + 1)))
+ s->setGlyph(seg, g);
+ }
+ }
+ --i;
+ --lastPass;
+ lbidi = 0xFF;
+ continue;
+ }
+
+#if !defined GRAPHITE2_NTRACING
+ if (dbgout)
+ {
+ *dbgout << json::item << json::object
+ << "id" << i+1
+ << "slots" << json::array;
+ seg->positionSlots(0);
+ for(Slot * s = seg->first(); s; s = s->next())
+ *dbgout << dslot(seg, s);
+ *dbgout << json::close;
+ }
+#endif
+
+ // test whether to reorder, prepare for positioning
+ if (i >= 32 || (seg->passBits() & (1 << i)) == 0)
+ m_passes[i].runGraphite(m, fsm);
+ // only subsitution passes can change segment length, cached subsegments are short for their text
+ if (m.status() != vm::Machine::finished
+ || (i < m_pPass && (seg->slotCount() > initSize * MAX_SEG_GROWTH_FACTOR
+ || (seg->slotCount() && seg->slotCount() * MAX_SEG_GROWTH_FACTOR < initSize))))
+ return false;
+ }
+ return true;
+}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Slot.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Slot.cpp
index c6fc2b5679a..d802cd98d24 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Slot.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Slot.cpp
@@ -37,23 +37,29 @@ Slot::Slot() :
m_next(NULL), m_prev(NULL),
m_glyphid(0), m_realglyphid(0), m_original(0), m_before(0), m_after(0),
m_index(0), m_parent(NULL), m_child(NULL), m_sibling(NULL),
- m_position(0, 0), m_shift(0, 0), m_advance(-1, -1),
+ m_position(0, 0), m_shift(0, 0), m_advance(0, 0),
m_attach(0, 0), m_with(0, 0), m_just(0.),
- m_flags(0), m_attLevel(0), m_bidiCls(0), m_bidiLevel(0), m_justs(NULL)
+ m_flags(0), m_attLevel(0), m_bidiCls(-1), m_bidiLevel(0), m_justs(NULL)
// Do not set m_userAttr since it is set *before* new is called since this
// is used as a positional new to reset the GrSlot
{
}
// take care, this does not copy any of the GrSlot pointer fields
-void Slot::set(const Slot & orig, int charOffset, size_t numUserAttr, size_t justLevels)
+void Slot::set(const Slot & orig, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars)
{
// leave m_next and m_prev unchanged
m_glyphid = orig.m_glyphid;
m_realglyphid = orig.m_realglyphid;
m_original = orig.m_original + charOffset;
- m_before = orig.m_before + charOffset;
- m_after = orig.m_after + charOffset;
+ if (charOffset + int(orig.m_before) < 0)
+ m_before = 0;
+ else
+ m_before = orig.m_before + charOffset;
+ if (charOffset <= 0 && orig.m_after + charOffset >= numChars)
+ m_after = numChars - 1;
+ else
+ m_after = orig.m_after + charOffset;
m_parent = NULL;
m_child = NULL;
m_sibling = NULL;
@@ -67,13 +73,9 @@ void Slot::set(const Slot & orig, int charOffset, size_t numUserAttr, size_t jus
m_bidiCls = orig.m_bidiCls;
m_bidiLevel = orig.m_bidiLevel;
if (m_userAttr && orig.m_userAttr)
- {
memcpy(m_userAttr, orig.m_userAttr, numUserAttr * sizeof(*m_userAttr));
- }
if (m_justs && orig.m_justs)
- {
memcpy(m_justs, orig.m_justs, SlotJustify::size_of(justLevels));
- }
}
void Slot::update(int /*numGrSlots*/, int numCharInfo, Position &relpos)
@@ -194,32 +196,35 @@ int Slot::getAttr(const Segment *seg, attrCode ind, uint8 subindex) const
switch (ind)
{
- case gr_slatAdvX : return int(m_advance.x);
- case gr_slatAdvY : return int(m_advance.y);
- case gr_slatAttTo : return m_parent ? 1 : 0;
- case gr_slatAttX : return int(m_attach.x);
- case gr_slatAttY : return int(m_attach.y);
+ case gr_slatAdvX : return int(m_advance.x);
+ case gr_slatAdvY : return int(m_advance.y);
+ case gr_slatAttTo : return m_parent ? 1 : 0;
+ case gr_slatAttX : return int(m_attach.x);
+ case gr_slatAttY : return int(m_attach.y);
case gr_slatAttXOff :
- case gr_slatAttYOff : return 0;
+ case gr_slatAttYOff : return 0;
case gr_slatAttWithX : return int(m_with.x);
case gr_slatAttWithY : return int(m_with.y);
case gr_slatAttWithXOff:
case gr_slatAttWithYOff:return 0;
- case gr_slatAttLevel : return m_attLevel;
- case gr_slatBreak : return seg->charinfo(m_original)->breakWeight();
- case gr_slatCompRef : return 0;
- case gr_slatDir : return seg->dir();
- case gr_slatInsert : return isInsertBefore();
- case gr_slatPosX : return int(m_position.x); // but need to calculate it
- case gr_slatPosY : return int(m_position.y);
- case gr_slatShiftX : return int(m_shift.x);
- case gr_slatShiftY : return int(m_shift.y);
- case gr_slatMeasureSol: return -1; // err what's this?
+ case gr_slatAttLevel : return m_attLevel;
+ case gr_slatBreak : return seg->charinfo(m_original)->breakWeight();
+ case gr_slatCompRef : return 0;
+ case gr_slatDir : if (m_bidiCls == -1)
+ const_cast<Slot *>(this)->setBidiClass(seg->glyphAttr(gid(), seg->silf()->aBidi()));
+ return m_bidiCls;
+ case gr_slatInsert : return isInsertBefore();
+ case gr_slatPosX : return int(m_position.x); // but need to calculate it
+ case gr_slatPosY : return int(m_position.y);
+ case gr_slatShiftX : return int(m_shift.x);
+ case gr_slatShiftY : return int(m_shift.y);
+ case gr_slatMeasureSol: return -1; // err what's this?
case gr_slatMeasureEol: return -1;
- case gr_slatJWidth: return m_just;
- case gr_slatUserDefn : return m_userAttr[subindex];
+ case gr_slatJWidth: return int(m_just);
+ case gr_slatUserDefn : return m_userAttr[subindex];
case gr_slatSegSplit : return seg->charinfo(m_original)->flags() & 3;
- default : return 0;
+ case gr_slatBidiLevel: return m_bidiLevel;
+ default : return 0;
}
}
@@ -239,8 +244,8 @@ void Slot::setAttr(Segment *seg, attrCode ind, uint8 subindex, int16 value, cons
switch (ind)
{
- case gr_slatAdvX : m_advance.x = value; break;
- case gr_slatAdvY : m_advance.y = value; break;
+ case gr_slatAdvX : m_advance.x = value; break;
+ case gr_slatAdvY : m_advance.y = value; break;
case gr_slatAttTo :
{
const uint16 idx = uint16(value);
@@ -260,36 +265,36 @@ void Slot::setAttr(Segment *seg, attrCode ind, uint8 subindex, int16 value, cons
}
break;
}
- case gr_slatAttX : m_attach.x = value; break;
- case gr_slatAttY : m_attach.y = value; break;
+ case gr_slatAttX : m_attach.x = value; break;
+ case gr_slatAttY : m_attach.y = value; break;
case gr_slatAttXOff :
- case gr_slatAttYOff : break;
- case gr_slatAttWithX : m_with.x = value; break;
- case gr_slatAttWithY : m_with.y = value; break;
+ case gr_slatAttYOff : break;
+ case gr_slatAttWithX : m_with.x = value; break;
+ case gr_slatAttWithY : m_with.y = value; break;
case gr_slatAttWithXOff :
- case gr_slatAttWithYOff : break;
+ case gr_slatAttWithYOff : break;
case gr_slatAttLevel :
m_attLevel = byte(value);
break;
case gr_slatBreak :
seg->charinfo(m_original)->breakWeight(value);
break;
- case gr_slatCompRef : break; // not sure what to do here
- case gr_slatDir : break; // read only
+ case gr_slatCompRef : break; // not sure what to do here
+ case gr_slatDir : m_bidiCls = value; break;
case gr_slatInsert :
markInsertBefore(value? true : false);
break;
- case gr_slatPosX : break; // can't set these here
- case gr_slatPosY : break;
- case gr_slatShiftX : m_shift.x = value; break;
+ case gr_slatPosX : break; // can't set these here
+ case gr_slatPosY : break;
+ case gr_slatShiftX : m_shift.x = value; break;
case gr_slatShiftY : m_shift.y = value; break;
- case gr_slatMeasureSol : break;
- case gr_slatMeasureEol : break;
- case gr_slatJWidth : just(value); break;
+ case gr_slatMeasureSol : break;
+ case gr_slatMeasureEol : break;
+ case gr_slatJWidth : just(value); break;
case gr_slatSegSplit : seg->charinfo(m_original)->addflags(value & 3); break;
case gr_slatUserDefn : m_userAttr[subindex] = value; break;
default :
- break;
+ break;
}
}
@@ -319,6 +324,7 @@ void Slot::setJustify(Segment *seg, uint8 level, uint8 subindex, int16 value)
if (!m_justs)
{
SlotJustify *j = seg->newJustify();
+ if (!j) return;
j->LoadSlot(this, seg);
m_justs = j;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/Sparse.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/Sparse.cpp
index a3eb52a1942..8730f78644d 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/Sparse.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/Sparse.cpp
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2011, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -30,31 +30,33 @@ of the License or (at your option) any later version.
using namespace graphite2;
+sparse::chunk sparse::empty_chunk = {0,0};
sparse::~sparse() throw()
{
- free(m_array.values);
+ if (m_array.map == &empty_chunk) return;
+ free(m_array.values);
}
sparse::mapped_type sparse::operator [] (const key_type k) const throw()
{
mapped_type g = key_type(k/SIZEOF_CHUNK - m_nchunks) >> (sizeof k*8 - 1);
- const chunk & c = m_array.map[g*k/SIZEOF_CHUNK];
- const mask_t m = c.mask >> (SIZEOF_CHUNK - 1 - (k%SIZEOF_CHUNK));
- g *= m & 1;
+ const chunk & c = m_array.map[g*k/SIZEOF_CHUNK];
+ const mask_t m = c.mask >> (SIZEOF_CHUNK - 1 - (k%SIZEOF_CHUNK));
+ g *= m & 1;
- return g*m_array.values[g*(c.offset + bit_set_count(m >> 1))];
+ return g*m_array.values[g*(c.offset + bit_set_count(m >> 1))];
}
size_t sparse::capacity() const throw()
{
- size_t n = m_nchunks,
- s = 0;
+ size_t n = m_nchunks,
+ s = 0;
- for (const chunk *ci=m_array.map; n; --n, ++ci)
- s += bit_set_count(ci->mask);
+ for (const chunk *ci=m_array.map; n; --n, ++ci)
+ s += bit_set_count(ci->mask);
- return s;
+ return s;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/TtfUtil.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/TtfUtil.cpp
new file mode 100644
index 00000000000..fcd2478a266
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/TtfUtil.cpp
@@ -0,0 +1,1979 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2010, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+/*--------------------------------------------------------------------*//*:Ignore this sentence.
+
+File: TtfUtil.cpp
+Responsibility: Alan Ward
+Last reviewed: Not yet.
+
+Description
+ Implements the methods for TtfUtil class. This file should remain portable to any C++
+ environment by only using standard C++ and the TTF structurs defined in Tt.h.
+-------------------------------------------------------------------------------*//*:End Ignore*/
+
+
+/***********************************************************************************************
+ Include files
+***********************************************************************************************/
+// Language headers
+//#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstring>
+#include <climits>
+#include <cwchar>
+//#include <stdexcept>
+// Platform headers
+// Module headers
+#include "inc/TtfUtil.h"
+#include "inc/TtfTypes.h"
+#include "inc/Endian.h"
+
+/***********************************************************************************************
+ Forward declarations
+***********************************************************************************************/
+
+/***********************************************************************************************
+ Local Constants and static variables
+***********************************************************************************************/
+namespace
+{
+ // max number of components allowed in composite glyphs
+ const int kMaxGlyphComponents = 8;
+
+ template <int R, typename T>
+ inline float fixed_to_float(const T f) {
+ return float(f)/float(2^R);
+ }
+
+/*----------------------------------------------------------------------------------------------
+ Table of standard Postscript glyph names. From Martin Hosken. Disagress with ttfdump.exe
+---------------------------------------------------------------------------------------------*/
+#ifdef ALL_TTFUTILS
+ const int kcPostNames = 258;
+
+ const char * rgPostName[kcPostNames] = {
+ ".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign",
+ "dollar", "percent", "ampersand", "quotesingle", "parenleft",
+ "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash",
+ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
+ "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "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",
+ "bracketleft", "backslash", "bracketright", "asciicircum",
+ "underscore", "grave", "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", "braceleft", "bar", "braceright", "asciitilde",
+ "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis",
+ "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde",
+ "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis",
+ "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute",
+ "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave",
+ "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling",
+ "section", "bullet", "paragraph", "germandbls", "registered",
+ "copyright", "trademark", "acute", "dieresis", "notequal", "AE",
+ "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen",
+ "mu", "partialdiff", "summation", "product", "pi", "integral",
+ "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown",
+ "exclamdown", "logicalnot", "radical", "florin", "approxequal",
+ "Delta", "guillemotleft", "guillemotright", "ellipsis", "nonbreakingspace",
+ "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash",
+ "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide",
+ "lozenge", "ydieresis", "Ydieresis", "fraction", "currency",
+ "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered",
+ "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
+ "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute",
+ "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
+ "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi",
+ "circumflex", "tilde", "macron", "breve", "dotaccent", "ring",
+ "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash",
+ "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth",
+ "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply",
+ "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter",
+ "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla",
+ "scedilla", "Cacute", "cacute", "Ccaron", "ccaron",
+ "dcroat" };
+#endif
+
+} // end of namespace
+
+/***********************************************************************************************
+ Methods
+***********************************************************************************************/
+
+/* Note on error processing: The code guards against bad glyph ids being used to look up data
+in open ended tables (loca, hmtx). If the glyph id comes from a cmap this shouldn't happen
+but it seems prudent to check for user errors here. The code does assume that data obtained
+from the TTF file is valid otherwise (though the CheckTable method seeks to check for
+obvious problems that might accompany a change in table versions). For example an invalid
+offset in the loca table which could exceed the size of the glyf table is NOT trapped.
+Likewise if numberOf_LongHorMetrics in the hhea table is wrong, this will NOT be trapped,
+which could cause a lookup in the hmtx table to exceed the table length. Of course, TTF tables
+that are completely corrupt will cause unpredictable results. */
+
+/* Note on composite glyphs: Glyphs that have components that are themselves composites
+are not supported. IsDeepComposite can be used to test for this. False is returned from many
+of the methods in this cases. It is unclear how to build composite glyphs in some cases,
+so this code represents my best guess until test cases can be found. See notes on the high-
+level GlyfPoints method. */
+namespace graphite2
+{
+namespace TtfUtil
+{
+
+
+/*----------------------------------------------------------------------------------------------
+ Get offset and size of the offset table needed to find table directory.
+ Return true if success, false otherwise.
+ lSize excludes any table directory entries.
+----------------------------------------------------------------------------------------------*/
+bool GetHeaderInfo(size_t & lOffset, size_t & lSize)
+{
+ lOffset = 0;
+ lSize = offsetof(Sfnt::OffsetSubTable, table_directory);
+ assert(sizeof(uint32) + 4*sizeof (uint16) == lSize);
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Check the offset table for expected data.
+ Return true if success, false otherwise.
+----------------------------------------------------------------------------------------------*/
+bool CheckHeader(const void * pHdr)
+{
+ const Sfnt::OffsetSubTable * pOffsetTable
+ = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
+
+ return pHdr && be::swap(pOffsetTable->scaler_type) == Sfnt::OffsetSubTable::TrueTypeWin;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get offset and size of the table directory.
+ Return true if successful, false otherwise.
+----------------------------------------------------------------------------------------------*/
+bool GetTableDirInfo(const void * pHdr, size_t & lOffset, size_t & lSize)
+{
+ const Sfnt::OffsetSubTable * pOffsetTable
+ = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
+
+ lOffset = offsetof(Sfnt::OffsetSubTable, table_directory);
+ lSize = be::swap(pOffsetTable->num_tables)
+ * sizeof(Sfnt::OffsetSubTable::Entry);
+
+ return true;
+}
+
+
+/*----------------------------------------------------------------------------------------------
+ Get offset and size of the specified table.
+ Return true if successful, false otherwise. On false, offset and size will be 0.
+----------------------------------------------------------------------------------------------*/
+bool GetTableInfo(const Tag TableTag, const void * pHdr, const void * pTableDir,
+ size_t & lOffset, size_t & lSize)
+{
+ const Sfnt::OffsetSubTable * pOffsetTable
+ = reinterpret_cast<const Sfnt::OffsetSubTable *>(pHdr);
+ const size_t num_tables = be::swap(pOffsetTable->num_tables);
+ const Sfnt::OffsetSubTable::Entry
+ * entry_itr = reinterpret_cast<const Sfnt::OffsetSubTable::Entry *>(
+ pTableDir),
+ * const dir_end = entry_itr + num_tables;
+
+ if (num_tables > 40)
+ return false;
+
+ for (;entry_itr != dir_end; ++entry_itr) // 40 - safe guard
+ {
+ if (be::swap(entry_itr->tag) == TableTag)
+ {
+ lOffset = be::swap(entry_itr->offset);
+ lSize = be::swap(entry_itr->length);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Check the specified table. Tests depend on the table type.
+ Return true if successful, false otherwise.
+----------------------------------------------------------------------------------------------*/
+bool CheckTable(const Tag TableId, const void * pTable, size_t lTableSize)
+{
+ using namespace Sfnt;
+
+ if (pTable == 0) return false;
+
+ switch(TableId)
+ {
+ case Tag::cmap: // cmap
+ {
+ const Sfnt::CharacterCodeMap * const pCmap
+ = reinterpret_cast<const Sfnt::CharacterCodeMap *>(pTable);
+ return be::swap(pCmap->version) == 0;
+ }
+
+ case Tag::head: // head
+ {
+ const Sfnt::FontHeader * const pHead
+ = reinterpret_cast<const Sfnt::FontHeader *>(pTable);
+ bool r = be::swap(pHead->version) == OneFix
+ && be::swap(pHead->magic_number) == FontHeader::MagicNumber
+ && be::swap(pHead->glyph_data_format)
+ == FontHeader::GlypDataFormat
+ && (be::swap(pHead->index_to_loc_format)
+ == FontHeader::ShortIndexLocFormat
+ || be::swap(pHead->index_to_loc_format)
+ == FontHeader::LongIndexLocFormat)
+ && sizeof(FontHeader) <= lTableSize;
+ return r;
+ }
+
+ case Tag::post: // post
+ {
+ const Sfnt::PostScriptGlyphName * const pPost
+ = reinterpret_cast<const Sfnt::PostScriptGlyphName *>(pTable);
+ const fixed format = be::swap(pPost->format);
+ bool r = format == PostScriptGlyphName::Format1
+ || format == PostScriptGlyphName::Format2
+ || format == PostScriptGlyphName::Format3
+ || format == PostScriptGlyphName::Format25;
+ return r;
+ }
+
+ case Tag::hhea: // hhea
+ {
+ const Sfnt::HorizontalHeader * pHhea =
+ reinterpret_cast<const Sfnt::HorizontalHeader *>(pTable);
+ bool r = be::swap(pHhea->version) == OneFix
+ && be::swap(pHhea->metric_data_format) == 0
+ && sizeof (Sfnt::HorizontalHeader) <= lTableSize;
+ return r;
+ }
+
+ case Tag::maxp: // maxp
+ {
+ const Sfnt::MaximumProfile * pMaxp =
+ reinterpret_cast<const Sfnt::MaximumProfile *>(pTable);
+ bool r = be::swap(pMaxp->version) == OneFix
+ && sizeof(Sfnt::MaximumProfile) <= lTableSize;
+ return r;
+ }
+
+ case Tag::OS_2: // OS/2
+ {
+ const Sfnt::Compatibility * pOs2
+ = reinterpret_cast<const Sfnt::Compatibility *>(pTable);
+ if (be::swap(pOs2->version) == 0)
+ { // OS/2 table version 1 size
+// if (sizeof(Sfnt::Compatibility)
+// - sizeof(uint32)*2 - sizeof(int16)*2
+// - sizeof(uint16)*3 <= lTableSize)
+ if (sizeof(Sfnt::Compatibility0) <= lTableSize)
+ return true;
+ }
+ else if (be::swap(pOs2->version) == 1)
+ { // OS/2 table version 2 size
+// if (sizeof(Sfnt::Compatibility)
+// - sizeof(int16) *2
+// - sizeof(uint16)*3 <= lTableSize)
+ if (sizeof(Sfnt::Compatibility1) <= lTableSize)
+ return true;
+ }
+ else if (be::swap(pOs2->version) == 2)
+ { // OS/2 table version 3 size
+ if (sizeof(Sfnt::Compatibility2) <= lTableSize)
+ return true;
+ }
+ else if (be::swap(pOs2->version) == 3 || be::swap(pOs2->version) == 4)
+ { // OS/2 table version 4 size - version 4 changed the meaning of some fields which we don't use
+ if (sizeof(Sfnt::Compatibility3) <= lTableSize)
+ return true;
+ }
+ else
+ return false;
+ break;
+ }
+
+ case Tag::name:
+ {
+ const Sfnt::FontNames * pName
+ = reinterpret_cast<const Sfnt::FontNames *>(pTable);
+ return be::swap(pName->format) == 0;
+ }
+
+ default:
+ break;
+ }
+
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the number of glyphs in the font. Should never be less than zero.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+size_t GlyphCount(const void * pMaxp)
+{
+ const Sfnt::MaximumProfile * pTable =
+ reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
+ return be::swap(pTable->num_glyphs);
+}
+
+#ifdef ALL_TTFUTILS
+/*----------------------------------------------------------------------------------------------
+ Return the maximum number of components for any composite glyph in the font.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+size_t MaxCompositeComponentCount(const void * pMaxp)
+{
+ const Sfnt::MaximumProfile * pTable =
+ reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
+ return be::swap(pTable->max_component_elements);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Composite glyphs can be composed of glyphs that are themselves composites.
+ This method returns the maximum number of levels like this for any glyph in the font.
+ A non-composite glyph has a level of 1.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+size_t MaxCompositeLevelCount(const void * pMaxp)
+{
+ const Sfnt::MaximumProfile * pTable =
+ reinterpret_cast<const Sfnt::MaximumProfile *>(pMaxp);
+ return be::swap(pTable->max_component_depth);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the number of glyphs in the font according to a differt source.
+ Should never be less than zero. Return -1 on failure.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+size_t LocaGlyphCount(size_t lLocaSize, const void * pHead) //throw(std::domain_error)
+{
+
+ const Sfnt::FontHeader * pTable
+ = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ if (be::swap(pTable->index_to_loc_format)
+ == Sfnt::FontHeader::ShortIndexLocFormat)
+ // loca entries are two bytes and have been divided by two
+ return (lLocaSize >> 1) - 1;
+
+ if (be::swap(pTable->index_to_loc_format)
+ == Sfnt::FontHeader::LongIndexLocFormat)
+ // loca entries are four bytes
+ return (lLocaSize >> 2) - 1;
+
+ return -1;
+ //throw std::domain_error("head table in inconsistent state. The font may be corrupted");
+}
+#endif
+
+/*----------------------------------------------------------------------------------------------
+ Return the design units the font is designed with
+----------------------------------------------------------------------------------------------*/
+int DesignUnits(const void * pHead)
+{
+ const Sfnt::FontHeader * pTable =
+ reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ return be::swap(pTable->units_per_em);
+}
+
+#ifdef ALL_TTFUTILS
+/*----------------------------------------------------------------------------------------------
+ Return the checksum from the head table, which serves as a unique identifer for the font.
+----------------------------------------------------------------------------------------------*/
+int HeadTableCheckSum(const void * pHead)
+{
+ const Sfnt::FontHeader * pTable =
+ reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ return be::swap(pTable->check_sum_adjustment);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the create time from the head table. This consists of a 64-bit integer, which
+ we return here as two 32-bit integers.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+void HeadTableCreateTime(const void * pHead,
+ unsigned int * pnDateBC, unsigned int * pnDateAD)
+{
+ const Sfnt::FontHeader * pTable =
+ reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ *pnDateBC = be::swap(pTable->created[0]);
+ *pnDateAD = be::swap(pTable->created[1]);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the modify time from the head table.This consists of a 64-bit integer, which
+ we return here as two 32-bit integers.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+void HeadTableModifyTime(const void * pHead,
+ unsigned int * pnDateBC, unsigned int *pnDateAD)
+{
+ const Sfnt::FontHeader * pTable =
+ reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ *pnDateBC = be::swap(pTable->modified[0]);
+ *pnDateAD = be::swap(pTable->modified[1]);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return true if the font is italic.
+----------------------------------------------------------------------------------------------*/
+bool IsItalic(const void * pHead)
+{
+ const Sfnt::FontHeader * pTable =
+ reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ return ((be::swap(pTable->mac_style) & 0x00000002) != 0);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the ascent for the font
+----------------------------------------------------------------------------------------------*/
+int FontAscent(const void * pOs2)
+{
+ const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
+
+ return be::swap(pTable->win_ascent);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the descent for the font
+----------------------------------------------------------------------------------------------*/
+int FontDescent(const void * pOs2)
+{
+ const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
+
+ return be::swap(pTable->win_descent);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the bold and italic style bits.
+ Return true if successful. false otherwise.
+ In addition to checking the OS/2 table, one could also check
+ the head table's macStyle field (overridden by the OS/2 table on Win)
+ the sub-family name in the name table (though this can contain oblique, dark, etc too)
+----------------------------------------------------------------------------------------------*/
+bool FontOs2Style(const void *pOs2, bool & fBold, bool & fItalic)
+{
+ const Sfnt::Compatibility * pTable = reinterpret_cast<const Sfnt::Compatibility *>(pOs2);
+
+ fBold = (be::swap(pTable->fs_selection) & Sfnt::Compatibility::Bold) != 0;
+ fItalic = (be::swap(pTable->fs_selection) & Sfnt::Compatibility::Italic) != 0;
+
+ return true;
+}
+#endif
+
+/*----------------------------------------------------------------------------------------------
+ Method for searching name table.
+----------------------------------------------------------------------------------------------*/
+bool GetNameInfo(const void * pName, int nPlatformId, int nEncodingId,
+ int nLangId, int nNameId, size_t & lOffset, size_t & lSize)
+{
+ lOffset = 0;
+ lSize = 0;
+
+ const Sfnt::FontNames * pTable = reinterpret_cast<const Sfnt::FontNames *>(pName);
+ uint16 cRecord = be::swap(pTable->count);
+ uint16 nRecordOffset = be::swap(pTable->string_offset);
+ const Sfnt::NameRecord * pRecord = reinterpret_cast<const Sfnt::NameRecord *>(pTable + 1);
+
+ for (int i = 0; i < cRecord; ++i)
+ {
+ if (be::swap(pRecord->platform_id) == nPlatformId &&
+ be::swap(pRecord->platform_specific_id) == nEncodingId &&
+ be::swap(pRecord->language_id) == nLangId &&
+ be::swap(pRecord->name_id) == nNameId)
+ {
+ lOffset = be::swap(pRecord->offset) + nRecordOffset;
+ lSize = be::swap(pRecord->length);
+ return true;
+ }
+ pRecord++;
+ }
+
+ return false;
+}
+
+#ifdef ALL_TTFUTILS
+/*----------------------------------------------------------------------------------------------
+ Return all the lang-IDs that have data for the given name-IDs. Assume that there is room
+ in the return array (langIdList) for 128 items. The purpose of this method is to return
+ a list of all possible lang-IDs.
+----------------------------------------------------------------------------------------------*/
+int GetLangsForNames(const void * pName, int nPlatformId, int nEncodingId,
+ int * nameIdList, int cNameIds, short * langIdList)
+{
+ const Sfnt::FontNames * pTable = reinterpret_cast<const Sfnt::FontNames *>(pName);
+ int cLangIds = 0;
+ uint16 cRecord = be::swap(pTable->count);
+ if (cRecord > 127) return cLangIds;
+ //uint16 nRecordOffset = swapw(pTable->stringOffset);
+ const Sfnt::NameRecord * pRecord = reinterpret_cast<const Sfnt::NameRecord *>(pTable + 1);
+
+ for (int i = 0; i < cRecord; ++i)
+ {
+ if (be::swap(pRecord->platform_id) == nPlatformId &&
+ be::swap(pRecord->platform_specific_id) == nEncodingId)
+ {
+ bool fNameFound = false;
+ int nLangId = be::swap(pRecord->language_id);
+ int nNameId = be::swap(pRecord->name_id);
+ for (int j = 0; j < cNameIds; j++)
+ {
+ if (nNameId == nameIdList[j])
+ {
+ fNameFound = true;
+ break;
+ }
+ }
+ if (fNameFound)
+ {
+ // Add it if it's not there.
+ int ilang;
+ for (ilang = 0; ilang < cLangIds; ilang++)
+ if (langIdList[ilang] == nLangId)
+ break;
+ if (ilang >= cLangIds)
+ {
+ langIdList[cLangIds] = short(nLangId);
+ cLangIds++;
+ }
+ if (cLangIds == 128)
+ return cLangIds;
+ }
+ }
+ pRecord++;
+ }
+
+ return cLangIds;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the offset and size of the font family name in English for the MS Platform with Unicode
+ writing system. The offset is within the pName data. The string is double byte with MSB
+ first.
+----------------------------------------------------------------------------------------------*/
+bool Get31EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize)
+{
+ return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 1, 1033,
+ Sfnt::NameRecord::Family, lOffset, lSize);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the offset and size of the full font name in English for the MS Platform with Unicode
+ writing system. The offset is within the pName data. The string is double byte with MSB
+ first.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+bool Get31EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize)
+{
+ return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 1, 1033,
+ Sfnt::NameRecord::Fullname, lOffset, lSize);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the offset and size of the font family name in English for the MS Platform with Symbol
+ writing system. The offset is within the pName data. The string is double byte with MSB
+ first.
+----------------------------------------------------------------------------------------------*/
+bool Get30EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize)
+{
+ return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 0, 1033,
+ Sfnt::NameRecord::Family, lOffset, lSize);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the offset and size of the full font name in English for the MS Platform with Symbol
+ writing system. The offset is within the pName data. The string is double byte with MSB
+ first.
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+bool Get30EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize)
+{
+ return GetNameInfo(pName, Sfnt::NameRecord::Microsoft, 0, 1033,
+ Sfnt::NameRecord::Fullname, lOffset, lSize);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the Glyph ID for a given Postscript name. This method finds the first glyph which
+ matches the requested Postscript name. Ideally every glyph should have a unique Postscript
+ name (except for special names such as .notdef), but this is not always true.
+ On failure return value less than zero.
+ -1 - table search failed
+ -2 - format 3 table (no Postscript glyph info)
+ -3 - other failures
+
+ Note: this method is not currently used by the Graphite engine.
+----------------------------------------------------------------------------------------------*/
+int PostLookup(const void * pPost, size_t lPostSize, const void * pMaxp,
+ const char * pPostName)
+{
+ using namespace Sfnt;
+
+ const Sfnt::PostScriptGlyphName * pTable
+ = reinterpret_cast<const Sfnt::PostScriptGlyphName *>(pPost);
+ fixed format = be::swap(pTable->format);
+
+ if (format == PostScriptGlyphName::Format3)
+ { // format 3 - no Postscript glyph info in font
+ return -2;
+ }
+
+ // search for given Postscript name among the standard names
+ int iPostName = -1; // index in standard names
+ for (int i = 0; i < kcPostNames; i++)
+ {
+ if (!strcmp(pPostName, rgPostName[i]))
+ {
+ iPostName = i;
+ break;
+ }
+ }
+
+ if (format == PostScriptGlyphName::Format1)
+ { // format 1 - use standard Postscript names
+ return iPostName;
+ }
+
+ if (format == PostScriptGlyphName::Format25)
+ {
+ if (iPostName == -1)
+ return -1;
+
+ const PostScriptGlyphName25 * pTable25
+ = static_cast<const PostScriptGlyphName25 *>(pTable);
+ int cnGlyphs = GlyphCount(pMaxp);
+ for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs && nGlyphId < kcPostNames;
+ nGlyphId++)
+ { // glyph_name_index25 contains bytes so no byte swapping needed
+ // search for first glyph id that uses the standard name
+ if (nGlyphId + pTable25->offset[nGlyphId] == iPostName)
+ return nGlyphId;
+ }
+ }
+
+ if (format == PostScriptGlyphName::Format2)
+ { // format 2
+ const PostScriptGlyphName2 * pTable2
+ = static_cast<const PostScriptGlyphName2 *>(pTable);
+
+ int cnGlyphs = be::swap(pTable2->number_of_glyphs);
+
+ if (iPostName != -1)
+ { // did match a standard name, look for first glyph id mapped to that name
+ for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs; nGlyphId++)
+ {
+ if (be::swap(pTable2->glyph_name_index[nGlyphId]) == iPostName)
+ return nGlyphId;
+ }
+ }
+
+ { // did not match a standard name, search font specific names
+ size_t nStrSizeGoal = strlen(pPostName);
+ const char * pFirstGlyphName = reinterpret_cast<const char *>(
+ &pTable2->glyph_name_index[0] + cnGlyphs);
+ const char * pGlyphName = pFirstGlyphName;
+ int iInNames = 0; // index in font specific names
+ bool fFound = false;
+ const char * const endOfTable
+ = reinterpret_cast<const char *>(pTable2) + lPostSize;
+ while (pGlyphName < endOfTable && !fFound)
+ { // search Pascal strings for first matching name
+ size_t nStringSize = size_t(*pGlyphName);
+ if (nStrSizeGoal != nStringSize ||
+ strncmp(pGlyphName + 1, pPostName, nStringSize))
+ { // did not match
+ ++iInNames;
+ pGlyphName += nStringSize + 1;
+ }
+ else
+ { // did match
+ fFound = true;
+ }
+ }
+ if (!fFound)
+ return -1; // no font specific name matches request
+
+ iInNames += kcPostNames;
+ for (gid16 nGlyphId = 0; nGlyphId < cnGlyphs; nGlyphId++)
+ { // search for first glyph id that maps to the found string index
+ if (be::swap(pTable2->glyph_name_index[nGlyphId]) == iInNames)
+ return nGlyphId;
+ }
+ return -1; // no glyph mapped to this index (very strange)
+ }
+ }
+
+ return -3;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Convert a Unicode character string from big endian (MSB first, Motorola) format to little
+ endian (LSB first, Intel) format.
+ nSize is the number of Unicode characters in the string. It should not include any
+ terminating null. If nSize is 0, it is assumed the string is null terminated. nSize
+ defaults to 0.
+ Return true if successful, false otherwise.
+----------------------------------------------------------------------------------------------*/
+void SwapWString(void * pWStr, size_t nSize /* = 0 */) //throw (std::invalid_argument)
+{
+ if (pWStr == 0)
+ {
+// throw std::invalid_argument("null pointer given");
+ return;
+ }
+
+ uint16 * pStr = reinterpret_cast<uint16 *>(pWStr);
+ uint16 * const pStrEnd = pStr + (nSize == 0 ? wcslen((const wchar_t*)pStr) : nSize);
+
+ for (; pStr != pStrEnd; ++pStr)
+ *pStr = be::swap(*pStr);
+// std::transform(pStr, pStrEnd, pStr, read<uint16>);
+
+// for (int i = 0; i < nSize; i++)
+// { // swap the wide characters in the string
+// pStr[i] = utf16(be::swap(uint16(pStr[i])));
+// }
+}
+#endif
+
+/*----------------------------------------------------------------------------------------------
+ Get the left-side bearing and and advance width based on the given tables and Glyph ID
+ Return true if successful, false otherwise. On false, one or both value could be INT_MIN
+----------------------------------------------------------------------------------------------*/
+bool HorMetrics(gid16 nGlyphId, const void * pHmtx, size_t lHmtxSize, const void * pHhea,
+ int & nLsb, unsigned int & nAdvWid)
+{
+ const Sfnt::HorizontalMetric * phmtx =
+ reinterpret_cast<const Sfnt::HorizontalMetric *>(pHmtx);
+
+ const Sfnt::HorizontalHeader * phhea =
+ reinterpret_cast<const Sfnt::HorizontalHeader *>(pHhea);
+
+ size_t cLongHorMetrics = be::swap(phhea->num_long_hor_metrics);
+ if (nGlyphId < cLongHorMetrics)
+ { // glyph id is acceptable
+ if (nGlyphId * sizeof(Sfnt::HorizontalMetric) >= lHmtxSize) return false;
+ nAdvWid = be::swap(phmtx[nGlyphId].advance_width);
+ nLsb = be::swap(phmtx[nGlyphId].left_side_bearing);
+ }
+ else
+ {
+ // guard against bad glyph id
+ size_t lLsbOffset = sizeof(Sfnt::HorizontalMetric) * cLongHorMetrics +
+ sizeof(int16) * (nGlyphId - cLongHorMetrics); // offset in bytes
+ // We test like this as LsbOffset is an offset not a length.
+ if (lLsbOffset > lHmtxSize - sizeof(int16))
+ {
+ nLsb = 0;
+ return false;
+ }
+ nAdvWid = be::swap(phmtx[cLongHorMetrics - 1].advance_width);
+ nLsb = be::peek<int16>(reinterpret_cast<const byte *>(phmtx) + lLsbOffset);
+ }
+
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return a pointer to the requested cmap subtable. By default find the Microsoft Unicode
+ subtable. Pass nEncoding as -1 to find first table that matches only nPlatformId.
+ Return NULL if the subtable cannot be found.
+----------------------------------------------------------------------------------------------*/
+const void * FindCmapSubtable(const void * pCmap, int nPlatformId, /* =3 */ int nEncodingId, /* = 1 */ size_t length)
+{
+ const Sfnt::CharacterCodeMap * pTable = reinterpret_cast<const Sfnt::CharacterCodeMap *>(pCmap);
+ uint16 csuPlatforms = be::swap(pTable->num_subtables);
+ if (length && (sizeof(Sfnt::CharacterCodeMap) + 8 * (csuPlatforms - 1) > length))
+ return NULL;
+ for (int i = 0; i < csuPlatforms; i++)
+ {
+ if (be::swap(pTable->encoding[i].platform_id) == nPlatformId &&
+ (nEncodingId == -1 || be::swap(pTable->encoding[i].platform_specific_id) == nEncodingId))
+ {
+ uint32 offset = be::swap(pTable->encoding[i].offset);
+ const uint8 * pRtn = reinterpret_cast<const uint8 *>(pCmap) + offset;
+ if (length)
+ {
+ if (offset > length) return NULL;
+ uint16 format = be::read<uint16>(pRtn);
+ if (format == 4)
+ {
+ uint16 subTableLength = be::peek<uint16>(pRtn);
+ if (i + 1 == csuPlatforms)
+ {
+ if (subTableLength > length - offset)
+ return NULL;
+ }
+ else if (subTableLength > be::swap(pTable->encoding[i+1].offset))
+ return NULL;
+ }
+ if (format == 12)
+ {
+ uint32 subTableLength = be::peek<uint32>(pRtn);
+ if (i + 1 == csuPlatforms)
+ {
+ if (subTableLength > length - offset)
+ return NULL;
+ }
+ else if (subTableLength > be::swap(pTable->encoding[i+1].offset))
+ return NULL;
+ }
+ }
+ return reinterpret_cast<const uint8 *>(pCmap) + offset;
+ }
+ }
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Check the Microsoft Unicode subtable for expected values
+----------------------------------------------------------------------------------------------*/
+bool CheckCmapSubtable4(const void * pCmapSubtable4)
+{
+ if (!pCmapSubtable4) return false;
+ const Sfnt::CmapSubTable * pTable = reinterpret_cast<const Sfnt::CmapSubTable *>(pCmapSubtable4);
+ // Bob H says ome freeware TT fonts have version 1 (eg, CALIGULA.TTF)
+ // so don't check subtable version. 21 Mar 2002 spec changes version to language.
+ if (be::swap(pTable->format) != 4) return false;
+ const Sfnt::CmapSubTableFormat4 * pTable4 = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmapSubtable4);
+ uint16 length = be::swap(pTable4->length);
+ if (length < sizeof(Sfnt::CmapSubTableFormat4))
+ return false;
+ uint16 nRanges = be::swap(pTable4->seg_count_x2) >> 1;
+ if (length < sizeof(Sfnt::CmapSubTableFormat4) + 4 * nRanges * sizeof(uint16))
+ return false;
+ // check last range is properly terminated
+ uint16 chEnd = be::peek<uint16>(pTable4->end_code + nRanges - 1);
+ return (chEnd == 0xFFFF);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the Glyph ID for the given Unicode ID in the Microsoft Unicode subtable.
+ (Actually this code only depends on subtable being format 4.)
+ Return 0 if the Unicode ID is not in the subtable.
+----------------------------------------------------------------------------------------------*/
+gid16 CmapSubtable4Lookup(const void * pCmapSubtabel4, unsigned int nUnicodeId, int rangeKey)
+{
+ const Sfnt::CmapSubTableFormat4 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmapSubtabel4);
+
+ uint16 nSeg = be::swap(pTable->seg_count_x2) >> 1;
+
+ uint16 n;
+ const uint16 * pLeft, * pMid;
+ uint16 cMid, chStart, chEnd;
+
+ if (rangeKey)
+ {
+ pMid = &(pTable->end_code[rangeKey]);
+ chEnd = be::peek<uint16>(pMid);
+ }
+ else
+ {
+ // Binary search of the endCode[] array
+ pLeft = &(pTable->end_code[0]);
+ n = nSeg;
+ while (n > 0)
+ {
+ cMid = n >> 1; // Pick an element in the middle
+ pMid = pLeft + cMid;
+ chEnd = be::peek<uint16>(pMid);
+ if (nUnicodeId <= chEnd)
+ {
+ if (cMid == 0 || nUnicodeId > be::peek<uint16>(pMid -1))
+ break; // Must be this seg or none!
+ n = cMid; // Continue on left side, omitting mid point
+ }
+ else
+ {
+ pLeft = pMid + 1; // Continue on right side, omitting mid point
+ n -= (cMid + 1);
+ }
+ }
+
+ if (!n)
+ return 0;
+ }
+
+ // Ok, we're down to one segment and pMid points to the endCode element
+ // Either this is it or none is.
+
+ chStart = be::peek<uint16>(pMid += nSeg + 1);
+ if (chEnd >= nUnicodeId && nUnicodeId >= chStart)
+ {
+ // Found correct segment. Find Glyph Id
+ int16 idDelta = be::peek<uint16>(pMid += nSeg);
+ uint16 idRangeOffset = be::peek<uint16>(pMid += nSeg);
+
+ if (idRangeOffset == 0)
+ return (uint16)(idDelta + nUnicodeId); // must use modulus 2^16
+
+ // Look up value in glyphIdArray
+ const ptrdiff_t offset = (nUnicodeId - chStart) + (idRangeOffset >> 1) +
+ (pMid - reinterpret_cast<const uint16 *>(pTable));
+ if (offset * 2 >= be::swap<uint16>(pTable->length))
+ return 0;
+ gid16 nGlyphId = be::peek<uint16>(reinterpret_cast<const uint16 *>(pTable)+offset);
+ // If this value is 0, return 0. Else add the idDelta
+ return nGlyphId ? nGlyphId + idDelta : 0;
+ }
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the next Unicode value in the cmap. Pass 0 to obtain the first item.
+ Returns 0xFFFF as the last item.
+ pRangeKey is an optional key that is used to optimize the search; its value is the range
+ in which the character is found.
+----------------------------------------------------------------------------------------------*/
+unsigned int CmapSubtable4NextCodepoint(const void *pCmap31, unsigned int nUnicodeId, int * pRangeKey)
+{
+ const Sfnt::CmapSubTableFormat4 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat4 *>(pCmap31);
+
+ uint16 nRange = be::swap(pTable->seg_count_x2) >> 1;
+
+ uint32 nUnicodePrev = (uint32)nUnicodeId;
+
+ const uint16 * pStartCode = &(pTable->end_code[0])
+ + nRange // length of end code array
+ + 1; // reserved word
+
+ if (nUnicodePrev == 0)
+ {
+ // return the first codepoint.
+ if (pRangeKey)
+ *pRangeKey = 0;
+ return be::peek<uint16>(pStartCode);
+ }
+ else if (nUnicodePrev >= 0xFFFF)
+ {
+ if (pRangeKey)
+ *pRangeKey = nRange - 1;
+ return 0xFFFF;
+ }
+
+ int iRange = (pRangeKey) ? *pRangeKey : 0;
+ // Just in case we have a bad key:
+ while (iRange > 0 && be::peek<uint16>(pStartCode + iRange) > nUnicodePrev)
+ iRange--;
+ while (be::peek<uint16>(pTable->end_code + iRange) < nUnicodePrev)
+ iRange++;
+
+ // Now iRange is the range containing nUnicodePrev.
+ unsigned int nStartCode = be::peek<uint16>(pStartCode + iRange);
+ unsigned int nEndCode = be::peek<uint16>(pTable->end_code + iRange);
+
+ if (nStartCode > nUnicodePrev)
+ // Oops, nUnicodePrev is not in the cmap! Adjust so we get a reasonable
+ // answer this time around.
+ nUnicodePrev = nStartCode - 1;
+
+ if (nEndCode > nUnicodePrev)
+ {
+ // Next is in the same range; it is the next successive codepoint.
+ if (pRangeKey)
+ *pRangeKey = iRange;
+ return nUnicodePrev + 1;
+ }
+
+ // Otherwise the next codepoint is the first one in the next range.
+ // There is guaranteed to be a next range because there must be one that
+ // ends with 0xFFFF.
+ if (pRangeKey)
+ *pRangeKey = iRange + 1;
+ return be::peek<uint16>(pStartCode + iRange + 1);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Check the Microsoft UCS-4 subtable for expected values.
+----------------------------------------------------------------------------------------------*/
+bool CheckCmapSubtable12(const void *pCmapSubtable12)
+{
+ if (!pCmapSubtable12) return false;
+ const Sfnt::CmapSubTable * pTable = reinterpret_cast<const Sfnt::CmapSubTable *>(pCmapSubtable12);
+ if (be::swap(pTable->format) != 12)
+ return false;
+ const Sfnt::CmapSubTableFormat12 * pTable12 = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmapSubtable12);
+ uint32 length = be::swap(pTable12->length);
+ if (length < sizeof(Sfnt::CmapSubTableFormat12))
+ return false;
+
+ return (length == (sizeof(Sfnt::CmapSubTableFormat12) + (be::swap(pTable12->num_groups) - 1)
+ * sizeof(uint32) * 3));
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the Glyph ID for the given Unicode ID in the Microsoft UCS-4 subtable.
+ (Actually this code only depends on subtable being format 12.)
+ Return 0 if the Unicode ID is not in the subtable.
+----------------------------------------------------------------------------------------------*/
+gid16 CmapSubtable12Lookup(const void * pCmap310, unsigned int uUnicodeId, int rangeKey)
+{
+ const Sfnt::CmapSubTableFormat12 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmap310);
+
+ //uint32 uLength = be::swap(pTable->length); //could use to test for premature end of table
+ uint32 ucGroups = be::swap(pTable->num_groups);
+
+ for (unsigned int i = rangeKey; i < ucGroups; i++)
+ {
+ uint32 uStartCode = be::swap(pTable->group[i].start_char_code);
+ uint32 uEndCode = be::swap(pTable->group[i].end_char_code);
+ if (uUnicodeId >= uStartCode && uUnicodeId <= uEndCode)
+ {
+ uint32 uDiff = uUnicodeId - uStartCode;
+ uint32 uStartGid = be::swap(pTable->group[i].start_glyph_id);
+ return static_cast<gid16>(uStartGid + uDiff);
+ }
+ }
+
+ return 0;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the next Unicode value in the cmap. Pass 0 to obtain the first item.
+ Returns 0x10FFFF as the last item.
+ pRangeKey is an optional key that is used to optimize the search; its value is the range
+ in which the character is found.
+----------------------------------------------------------------------------------------------*/
+unsigned int CmapSubtable12NextCodepoint(const void *pCmap310, unsigned int nUnicodeId, int * pRangeKey)
+{
+ const Sfnt::CmapSubTableFormat12 * pTable = reinterpret_cast<const Sfnt::CmapSubTableFormat12 *>(pCmap310);
+
+ int nRange = be::swap(pTable->num_groups);
+
+ uint32 nUnicodePrev = (uint32)nUnicodeId;
+
+ if (nUnicodePrev == 0)
+ {
+ // return the first codepoint.
+ if (pRangeKey)
+ *pRangeKey = 0;
+ return be::swap(pTable->group[0].start_char_code);
+ }
+ else if (nUnicodePrev >= 0x10FFFF)
+ {
+ if (pRangeKey)
+ *pRangeKey = nRange;
+ return 0x10FFFF;
+ }
+
+ int iRange = (pRangeKey) ? *pRangeKey : 0;
+ // Just in case we have a bad key:
+ while (iRange > 0 && be::swap(pTable->group[iRange].start_char_code) > nUnicodePrev)
+ iRange--;
+ while (be::swap(pTable->group[iRange].end_char_code) < nUnicodePrev)
+ iRange++;
+
+ // Now iRange is the range containing nUnicodePrev.
+
+ unsigned int nStartCode = be::swap(pTable->group[iRange].start_char_code);
+ unsigned int nEndCode = be::swap(pTable->group[iRange].end_char_code);
+
+ if (nStartCode > nUnicodePrev)
+ // Oops, nUnicodePrev is not in the cmap! Adjust so we get a reasonable
+ // answer this time around.
+ nUnicodePrev = nStartCode - 1;
+
+ if (nEndCode > nUnicodePrev)
+ {
+ // Next is in the same range; it is the next successive codepoint.
+ if (pRangeKey)
+ *pRangeKey = iRange;
+ return nUnicodePrev + 1;
+ }
+
+ // Otherwise the next codepoint is the first one in the next range, or 10FFFF if we're done.
+ if (pRangeKey)
+ *pRangeKey = iRange + 1;
+ return (iRange + 1 >= nRange) ? 0x10FFFF : be::swap(pTable->group[iRange + 1].start_char_code);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return the offset stored in the loca table for the given Glyph ID.
+ (This offset is into the glyf table.)
+ Return -1 if the lookup failed.
+ Technically this method should return an unsigned long but it is unlikely the offset will
+ exceed 2^31.
+----------------------------------------------------------------------------------------------*/
+size_t LocaLookup(gid16 nGlyphId,
+ const void * pLoca, size_t lLocaSize,
+ const void * pHead) // throw (std::out_of_range)
+{
+ const Sfnt::FontHeader * pTable = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ // CheckTable verifies the index_to_loc_format is valid
+ if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::ShortIndexLocFormat)
+ { // loca entries are two bytes and have been divided by two
+ if (nGlyphId < (lLocaSize >> 1) - 1) // allow sentinel value to be accessed
+ {
+ const uint16 * pShortTable = reinterpret_cast<const uint16 *>(pLoca);
+ return (be::peek<uint16>(pShortTable + nGlyphId) << 1);
+ }
+ }
+
+ if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::LongIndexLocFormat)
+ { // loca entries are four bytes
+ if (nGlyphId < (lLocaSize >> 2) - 1)
+ {
+ const uint32 * pLongTable = reinterpret_cast<const uint32 *>(pLoca);
+ return be::peek<uint32>(pLongTable + nGlyphId);
+ }
+ }
+
+ // only get here if glyph id was bad
+ return -1;
+ //throw std::out_of_range("glyph id out of range for font");
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return a pointer into the glyf table based on the given offset (from LocaLookup).
+ Return NULL on error.
+----------------------------------------------------------------------------------------------*/
+void * GlyfLookup(const void * pGlyf, size_t nGlyfOffset, size_t nTableLen)
+{
+ const uint8 * pByte = reinterpret_cast<const uint8 *>(pGlyf);
+ if (nGlyfOffset == size_t(-1) || nGlyfOffset >= nTableLen)
+ return NULL;
+ return const_cast<uint8 *>(pByte + nGlyfOffset);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the bounding box coordinates for a simple glyf entry (non-composite).
+ Return true if successful, false otherwise.
+----------------------------------------------------------------------------------------------*/
+bool GlyfBox(const void * pSimpleGlyf, int & xMin, int & yMin,
+ int & xMax, int & yMax)
+{
+ const Sfnt::Glyph * pGlyph = reinterpret_cast<const Sfnt::Glyph *>(pSimpleGlyf);
+
+ xMin = be::swap(pGlyph->x_min);
+ yMin = be::swap(pGlyph->y_min);
+ xMax = be::swap(pGlyph->x_max);
+ yMax = be::swap(pGlyph->y_max);
+
+ return true;
+}
+
+#ifdef ALL_TTFUTILS
+/*----------------------------------------------------------------------------------------------
+ Return the number of contours for a simple glyf entry (non-composite)
+ Returning -1 means this is a composite glyph
+----------------------------------------------------------------------------------------------*/
+int GlyfContourCount(const void * pSimpleGlyf)
+{
+ const Sfnt::Glyph * pGlyph = reinterpret_cast<const Sfnt::Glyph *>(pSimpleGlyf);
+ return be::swap(pGlyph->number_of_contours); // -1 means composite glyph
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the point numbers for the end points of the glyph contours for a simple
+ glyf entry (non-composite).
+ cnPointsTotal - count of contours from GlyfContourCount(); (same as number of end points)
+ prgnContourEndPoints - should point to a buffer large enough to hold cnPoints integers
+ cnPoints - count of points placed in above range
+ Return true if successful, false otherwise.
+ False could indicate a multi-level composite glyphs.
+----------------------------------------------------------------------------------------------*/
+bool GlyfContourEndPoints(const void * pSimpleGlyf, int * prgnContourEndPoint,
+ int cnPointsTotal, int & cnPoints)
+{
+ const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
+
+ int cContours = be::swap(pGlyph->number_of_contours);
+ if (cContours < 0)
+ return false; // this method isn't supposed handle composite glyphs
+
+ for (int i = 0; i < cContours && i < cnPointsTotal; i++)
+ {
+ prgnContourEndPoint[i] = be::swap(pGlyph->end_pts_of_contours[i]);
+ }
+
+ cnPoints = cContours;
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the points for a simple glyf entry (non-composite)
+ cnPointsTotal - count of points from largest end point obtained from GlyfContourEndPoints
+ prgnX & prgnY - should point to buffers large enough to hold cnPointsTotal integers
+ The ranges are parallel so that coordinates for point(n) are found at offset n in both
+ ranges. This is raw point data with relative coordinates.
+ prgbFlag - should point to a buffer a large enough to hold cnPointsTotal bytes
+ This range is parallel to the prgnX & prgnY
+ cnPoints - count of points placed in above ranges
+ Return true if successful, false otherwise.
+ False could indicate a composite glyph
+----------------------------------------------------------------------------------------------*/
+bool GlyfPoints(const void * pSimpleGlyf, int * prgnX, int * prgnY,
+ char * prgbFlag, int cnPointsTotal, int & cnPoints)
+{
+ using namespace Sfnt;
+
+ const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
+ int cContours = be::swap(pGlyph->number_of_contours);
+ // return false for composite glyph
+ if (cContours <= 0)
+ return false;
+ int cPts = be::swap(pGlyph->end_pts_of_contours[cContours - 1]) + 1;
+ if (cPts > cnPointsTotal)
+ return false;
+
+ // skip over bounding box data & point to byte count of instructions (hints)
+ const uint8 * pbGlyph = reinterpret_cast<const uint8 *>
+ (&pGlyph->end_pts_of_contours[cContours]);
+
+ // skip over hints & point to first flag
+ int cbHints = be::swap(*(uint16 *)pbGlyph);
+ pbGlyph += sizeof(uint16);
+ pbGlyph += cbHints;
+
+ // load flags & point to first x coordinate
+ int iFlag = 0;
+ while (iFlag < cPts)
+ {
+ if (!(*pbGlyph & SimpleGlyph::Repeat))
+ { // flag isn't repeated
+ prgbFlag[iFlag] = (char)*pbGlyph;
+ pbGlyph++;
+ iFlag++;
+ }
+ else
+ { // flag is repeated; count specified by next byte
+ char chFlag = (char)*pbGlyph;
+ pbGlyph++;
+ int cFlags = (int)*pbGlyph;
+ pbGlyph++;
+ prgbFlag[iFlag] = chFlag;
+ iFlag++;
+ for (int i = 0; i < cFlags; i++)
+ {
+ prgbFlag[iFlag + i] = chFlag;
+ }
+ iFlag += cFlags;
+ }
+ }
+ if (iFlag != cPts)
+ return false;
+
+ // load x coordinates
+ iFlag = 0;
+ while (iFlag < cPts)
+ {
+ if (prgbFlag[iFlag] & SimpleGlyph::XShort)
+ {
+ prgnX[iFlag] = *pbGlyph;
+ if (!(prgbFlag[iFlag] & SimpleGlyph::XIsPos))
+ {
+ prgnX[iFlag] = -prgnX[iFlag];
+ }
+ pbGlyph++;
+ }
+ else
+ {
+ if (prgbFlag[iFlag] & SimpleGlyph::XIsSame)
+ {
+ prgnX[iFlag] = 0;
+ // do NOT increment pbGlyph
+ }
+ else
+ {
+ prgnX[iFlag] = be::swap(*(int16 *)pbGlyph);
+ pbGlyph += sizeof(int16);
+ }
+ }
+ iFlag++;
+ }
+
+ // load y coordinates
+ iFlag = 0;
+ while (iFlag < cPts)
+ {
+ if (prgbFlag[iFlag] & SimpleGlyph::YShort)
+ {
+ prgnY[iFlag] = *pbGlyph;
+ if (!(prgbFlag[iFlag] & SimpleGlyph::YIsPos))
+ {
+ prgnY[iFlag] = -prgnY[iFlag];
+ }
+ pbGlyph++;
+ }
+ else
+ {
+ if (prgbFlag[iFlag] & SimpleGlyph::YIsSame)
+ {
+ prgnY[iFlag] = 0;
+ // do NOT increment pbGlyph
+ }
+ else
+ {
+ prgnY[iFlag] = be::swap(*(int16 *)pbGlyph);
+ pbGlyph += sizeof(int16);
+ }
+ }
+ iFlag++;
+ }
+
+ cnPoints = cPts;
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Fill prgnCompId with the component Glyph IDs from pSimpleGlyf.
+ Client must allocate space before calling.
+ pSimpleGlyf - assumed to point to a composite glyph
+ cCompIdTotal - the number of elements in prgnCompId
+ cCompId - the total number of Glyph IDs stored in prgnCompId
+ Return true if successful, false otherwise
+ False could indicate a non-composite glyph or the input array was not big enough
+----------------------------------------------------------------------------------------------*/
+bool GetComponentGlyphIds(const void * pSimpleGlyf, int * prgnCompId,
+ size_t cnCompIdTotal, size_t & cnCompId)
+{
+ using namespace Sfnt;
+
+ if (GlyfContourCount(pSimpleGlyf) >= 0)
+ return false;
+
+ const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
+ // for a composite glyph, the special data begins here
+ const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
+
+ uint16 GlyphFlags;
+ size_t iCurrentComp = 0;
+ do
+ {
+ GlyphFlags = be::swap(*((uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ prgnCompId[iCurrentComp++] = be::swap(*((uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ if (iCurrentComp >= cnCompIdTotal)
+ return false;
+ int nOffset = 0;
+ nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
+ nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
+ pbGlyph += nOffset;
+ } while (GlyphFlags & CompoundGlyph::MoreComponents);
+
+ cnCompId = iCurrentComp;
+
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return info on how a component glyph is to be placed
+ pSimpleGlyph - assumed to point to a composite glyph
+ nCompId - glyph id for component of interest
+ bOffset - if true, a & b are the x & y offsets for this component
+ if false, b is the point on this component that is attaching to point a on the
+ preceding glyph
+ Return true if successful, false otherwise
+ False could indicate a non-composite glyph or that component wasn't found
+----------------------------------------------------------------------------------------------*/
+bool GetComponentPlacement(const void * pSimpleGlyf, int nCompId,
+ bool fOffset, int & a, int & b)
+{
+ using namespace Sfnt;
+
+ if (GlyfContourCount(pSimpleGlyf) >= 0)
+ return false;
+
+ const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
+ // for a composite glyph, the special data begins here
+ const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
+
+ uint16 GlyphFlags;
+ do
+ {
+ GlyphFlags = be::swap(*((uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ if (be::swap(*((uint16 *)pbGlyph)) == nCompId)
+ {
+ pbGlyph += sizeof(uint16); // skip over glyph id of component
+ fOffset = (GlyphFlags & CompoundGlyph::ArgsAreXYValues) == CompoundGlyph::ArgsAreXYValues;
+
+ if (GlyphFlags & CompoundGlyph::Arg1Arg2Words )
+ {
+ a = be::swap(*(int16 *)pbGlyph);
+ pbGlyph += sizeof(int16);
+ b = be::swap(*(int16 *)pbGlyph);
+ pbGlyph += sizeof(int16);
+ }
+ else
+ { // args are signed bytes
+ a = *pbGlyph++;
+ b = *pbGlyph++;
+ }
+ return true;
+ }
+ pbGlyph += sizeof(uint16); // skip over glyph id of component
+ int nOffset = 0;
+ nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
+ nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
+ pbGlyph += nOffset;
+ } while (GlyphFlags & CompoundGlyph::MoreComponents);
+
+ // didn't find requested component
+ fOffset = true;
+ a = 0;
+ b = 0;
+ return false;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Return info on how a component glyph is to be transformed
+ pSimpleGlyph - assumed to point to a composite glyph
+ nCompId - glyph id for component of interest
+ flt11, flt11, flt11, flt11 - a 2x2 matrix giving the transform
+ bTransOffset - whether to transform the offset from above method
+ The spec is unclear about the meaning of this flag
+ Currently - initialize to true for MS rasterizer and false for Mac rasterizer, then
+ on return it will indicate whether transform should apply to offset (MSDN CD 10/99)
+ Return true if successful, false otherwise
+ False could indicate a non-composite glyph or that component wasn't found
+----------------------------------------------------------------------------------------------*/
+bool GetComponentTransform(const void * pSimpleGlyf, int nCompId,
+ float & flt11, float & flt12, float & flt21, float & flt22,
+ bool & fTransOffset)
+{
+ using namespace Sfnt;
+
+ if (GlyfContourCount(pSimpleGlyf) >= 0)
+ return false;
+
+ const Sfnt::SimpleGlyph * pGlyph = reinterpret_cast<const Sfnt::SimpleGlyph *>(pSimpleGlyf);
+ // for a composite glyph, the special data begins here
+ const uint8 * pbGlyph = reinterpret_cast<const uint8 *>(&pGlyph->end_pts_of_contours[0]);
+
+ uint16 GlyphFlags;
+ do
+ {
+ GlyphFlags = be::swap(*((uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ if (be::swap(*((uint16 *)pbGlyph)) == nCompId)
+ {
+ pbGlyph += sizeof(uint16); // skip over glyph id of component
+ pbGlyph += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2; // skip over placement data
+
+ if (fTransOffset) // MS rasterizer
+ fTransOffset = !(GlyphFlags & CompoundGlyph::UnscaledOffset);
+ else // Apple rasterizer
+ fTransOffset = (GlyphFlags & CompoundGlyph::ScaledOffset) != 0;
+
+ if (GlyphFlags & CompoundGlyph::HaveScale)
+ {
+ flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ flt12 = 0;
+ flt21 = 0;
+ flt22 = flt11;
+ }
+ else if (GlyphFlags & CompoundGlyph::HaveXAndYScale)
+ {
+ flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ flt12 = 0;
+ flt21 = 0;
+ flt22 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ }
+ else if (GlyphFlags & CompoundGlyph::HaveTwoByTwo)
+ {
+ flt11 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ flt12 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ flt21 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ flt22 = fixed_to_float<14>(be::swap(*(uint16 *)pbGlyph));
+ pbGlyph += sizeof(uint16);
+ }
+ else
+ { // identity transform
+ flt11 = 1.0;
+ flt12 = 0.0;
+ flt21 = 0.0;
+ flt22 = 1.0;
+ }
+ return true;
+ }
+ pbGlyph += sizeof(uint16); // skip over glyph id of component
+ int nOffset = 0;
+ nOffset += GlyphFlags & CompoundGlyph::Arg1Arg2Words ? 4 : 2;
+ nOffset += GlyphFlags & CompoundGlyph::HaveScale ? 2 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveXAndYScale ? 4 : 0;
+ nOffset += GlyphFlags & CompoundGlyph::HaveTwoByTwo ? 8 : 0;
+ pbGlyph += nOffset;
+ } while (GlyphFlags & CompoundGlyph::MoreComponents);
+
+ // didn't find requested component
+ fTransOffset = false;
+ flt11 = 1;
+ flt12 = 0;
+ flt21 = 0;
+ flt22 = 1;
+ return false;
+}
+#endif
+
+/*----------------------------------------------------------------------------------------------
+ Return a pointer into the glyf table based on the given tables and Glyph ID
+ Since this method doesn't check for spaces, it is good to call IsSpace before using it.
+ Return NULL on error.
+----------------------------------------------------------------------------------------------*/
+void * GlyfLookup(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead)
+{
+ // test for valid glyph id
+ // CheckTable verifies the index_to_loc_format is valid
+
+ const Sfnt::FontHeader * pTable
+ = reinterpret_cast<const Sfnt::FontHeader *>(pHead);
+
+ if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::ShortIndexLocFormat)
+ { // loca entries are two bytes (and have been divided by two)
+ if (nGlyphId >= (lLocaSize >> 1) - 1) // don't allow nGlyphId to access sentinel
+ {
+// throw std::out_of_range("glyph id out of range for font");
+ return NULL;
+ }
+ }
+ if (be::swap(pTable->index_to_loc_format) == Sfnt::FontHeader::LongIndexLocFormat)
+ { // loca entries are four bytes
+ if (nGlyphId >= (lLocaSize >> 2) - 1)
+ {
+// throw std::out_of_range("glyph id out of range for font");
+ return NULL;
+ }
+ }
+
+ long lGlyfOffset = LocaLookup(nGlyphId, pLoca, lLocaSize, pHead);
+ void * pSimpleGlyf = GlyfLookup(pGlyf, lGlyfOffset, lGlyfSize); // invalid loca offset returns null
+ return pSimpleGlyf;
+}
+
+#ifdef ALL_TTFUTILS
+/*----------------------------------------------------------------------------------------------
+ Determine if a particular Glyph ID has any data in the glyf table. If it is white space,
+ there will be no glyf data, though there will be metric data in hmtx, etc.
+----------------------------------------------------------------------------------------------*/
+bool IsSpace(gid16 nGlyphId, const void * pLoca, size_t lLocaSize, const void * pHead)
+{
+ size_t lGlyfOffset = LocaLookup(nGlyphId, pLoca, lLocaSize, pHead);
+
+ // the +1 should always work because there is a sentinel value at the end of the loca table
+ size_t lNextGlyfOffset = LocaLookup(nGlyphId + 1, pLoca, lLocaSize, pHead);
+
+ return (lNextGlyfOffset - lGlyfOffset) == 0;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Determine if a particular Glyph ID is a multi-level composite.
+----------------------------------------------------------------------------------------------*/
+bool IsDeepComposite(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, long lLocaSize, const void * pHead)
+{
+ if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
+
+ void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL)
+ return false; // no way to really indicate an error occured here
+
+ if (GlyfContourCount(pSimpleGlyf) >= 0)
+ return false;
+
+ int rgnCompId[kMaxGlyphComponents]; // assumes only a limited number of glyph components
+ size_t cCompIdTotal = kMaxGlyphComponents;
+ size_t cCompId = 0;
+
+ if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
+ return false;
+
+ for (size_t i = 0; i < cCompId; i++)
+ {
+ pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]),
+ pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL) {return false;}
+
+ if (GlyfContourCount(pSimpleGlyf) < 0)
+ return true;
+ }
+
+ return false;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the bounding box coordinates based on the given tables and Glyph ID
+ Handles both simple and composite glyphs.
+ Return true if successful, false otherwise. On false, all point values will be INT_MIN
+ False may indicate a white space glyph
+----------------------------------------------------------------------------------------------*/
+bool GlyfBox(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead, int & xMin, int & yMin, int & xMax, int & yMax)
+{
+ xMin = yMin = xMax = yMax = INT_MIN;
+
+ if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
+
+ void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL) {return false;}
+
+ return GlyfBox(pSimpleGlyf, xMin, yMin, xMax, yMax);
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the number of contours based on the given tables and Glyph ID
+ Handles both simple and composite glyphs.
+ Return true if successful, false otherwise. On false, cnContours will be INT_MIN
+ False may indicate a white space glyph or a multi-level composite glyph.
+----------------------------------------------------------------------------------------------*/
+bool GlyfContourCount(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead, size_t & cnContours)
+{
+ cnContours = static_cast<size_t>(INT_MIN);
+
+ if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
+
+ void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL) {return false;}
+
+ int cRtnContours = GlyfContourCount(pSimpleGlyf);
+ if (cRtnContours >= 0)
+ {
+ cnContours = size_t(cRtnContours);
+ return true;
+ }
+
+ //handle composite glyphs
+
+ int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
+ size_t cCompIdTotal = kMaxGlyphComponents;
+ size_t cCompId = 0;
+
+ if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
+ return false;
+
+ cRtnContours = 0;
+ int cTmp = 0;
+ for (size_t i = 0; i < cCompId; i++)
+ {
+ if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
+ pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]),
+ pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == 0) {return false;}
+ // return false on multi-level composite
+ if ((cTmp = GlyfContourCount(pSimpleGlyf)) < 0)
+ return false;
+ cRtnContours += cTmp;
+ }
+
+ cnContours = size_t(cRtnContours);
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the point numbers for the end points of the glyph contours based on the given tables
+ and Glyph ID
+ Handles both simple and composite glyphs.
+ cnPoints - count of contours from GlyfContourCount (same as number of end points)
+ prgnContourEndPoints - should point to a buffer large enough to hold cnPoints integers
+ Return true if successful, false otherwise. On false, all end points are INT_MIN
+ False may indicate a white space glyph or a multi-level composite glyph.
+----------------------------------------------------------------------------------------------*/
+bool GlyfContourEndPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead,
+ int * prgnContourEndPoint, size_t cnPoints)
+{
+ memset(prgnContourEndPoint, 0xFF, cnPoints * sizeof(int));
+ // std::fill_n(prgnContourEndPoint, cnPoints, INT_MIN);
+
+ if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead)) {return false;}
+
+ void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL) {return false;}
+
+ int cContours = GlyfContourCount(pSimpleGlyf);
+ int cActualPts = 0;
+ if (cContours > 0)
+ return GlyfContourEndPoints(pSimpleGlyf, prgnContourEndPoint, cnPoints, cActualPts);
+
+ // handle composite glyphs
+
+ int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
+ size_t cCompIdTotal = kMaxGlyphComponents;
+ size_t cCompId = 0;
+
+ if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
+ return false;
+
+ int * prgnCurrentEndPoint = prgnContourEndPoint;
+ int cCurrentPoints = cnPoints;
+ int nPrevPt = 0;
+ for (size_t i = 0; i < cCompId; i++)
+ {
+ if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
+ pSimpleGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]), pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL) {return false;}
+ // returns false on multi-level composite
+ if (!GlyfContourEndPoints(pSimpleGlyf, prgnCurrentEndPoint, cCurrentPoints, cActualPts))
+ return false;
+ // points in composite are numbered sequentially as components are added
+ // must adjust end point numbers for new point numbers
+ for (int j = 0; j < cActualPts; j++)
+ prgnCurrentEndPoint[j] += nPrevPt;
+ nPrevPt = prgnCurrentEndPoint[cActualPts - 1] + 1;
+
+ prgnCurrentEndPoint += cActualPts;
+ cCurrentPoints -= cActualPts;
+ }
+
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Get the points for a glyph based on the given tables and Glyph ID
+ Handles both simple and composite glyphs.
+ cnPoints - count of points from largest end point obtained from GlyfContourEndPoints
+ prgnX & prgnY - should point to buffers large enough to hold cnPoints integers
+ The ranges are parallel so that coordinates for point(n) are found at offset n in
+ both ranges. These points are in absolute coordinates.
+ prgfOnCurve - should point to a buffer a large enough to hold cnPoints bytes (bool)
+ This range is parallel to the prgnX & prgnY
+ Return true if successful, false otherwise. On false, all points may be INT_MIN
+ False may indicate a white space glyph, a multi-level composite, or a corrupt font
+ // TODO: doesn't support composite glyphs whose components are themselves components
+ It's not clear from the TTF spec when the transforms should be applied. Should the
+ transform be done before or after attachment point calcs? (current code - before)
+ Should the transform be applied to other offsets? (currently - no; however commented
+ out code is in place so that if CompoundGlyph::UnscaledOffset on the MS rasterizer is
+ clear (typical) then yes, and if CompoundGlyph::ScaledOffset on the Apple rasterizer is
+ clear (typical?) then no). See GetComponentTransform.
+ It's also unclear where point numbering with attachment poinst starts
+ (currently - first point number is relative to whole glyph, second point number is
+ relative to current glyph).
+----------------------------------------------------------------------------------------------*/
+bool GlyfPoints(gid16 nGlyphId, const void * pGlyf,
+ const void * pLoca, size_t lGlyfSize, size_t lLocaSize, const void * pHead,
+ const int * /*prgnContourEndPoint*/, size_t /*cnEndPoints*/,
+ int * prgnX, int * prgnY, bool * prgfOnCurve, size_t cnPoints)
+{
+ memset(prgnX, 0x7F, cnPoints * sizeof(int));
+ memset(prgnY, 0x7F, cnPoints * sizeof(int));
+
+ if (IsSpace(nGlyphId, pLoca, lLocaSize, pHead))
+ return false;
+
+ void * pSimpleGlyf = GlyfLookup(nGlyphId, pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pSimpleGlyf == NULL)
+ return false;
+
+ int cContours = GlyfContourCount(pSimpleGlyf);
+ int cActualPts;
+ if (cContours > 0)
+ {
+ if (!GlyfPoints(pSimpleGlyf, prgnX, prgnY, (char *)prgfOnCurve, cnPoints, cActualPts))
+ return false;
+ CalcAbsolutePoints(prgnX, prgnY, cnPoints);
+ SimplifyFlags((char *)prgfOnCurve, cnPoints);
+ return true;
+ }
+
+ // handle composite glyphs
+ int rgnCompId[kMaxGlyphComponents]; // assumes no glyph will be made of more than 8 components
+ size_t cCompIdTotal = kMaxGlyphComponents;
+ size_t cCompId = 0;
+
+ // this will fail if there are more components than there is room for
+ if (!GetComponentGlyphIds(pSimpleGlyf, rgnCompId, cCompIdTotal, cCompId))
+ return false;
+
+ int * prgnCurrentX = prgnX;
+ int * prgnCurrentY = prgnY;
+ char * prgbCurrentFlag = (char *)prgfOnCurve; // converting bool to char should be safe
+ int cCurrentPoints = cnPoints;
+ bool fOffset = true, fTransOff = true;
+ int a, b;
+ float flt11, flt12, flt21, flt22;
+ // int * prgnPrevX = prgnX; // in case first att pt number relative to preceding glyph
+ // int * prgnPrevY = prgnY;
+ for (size_t i = 0; i < cCompId; i++)
+ {
+ if (IsSpace(static_cast<gid16>(rgnCompId[i]), pLoca, lLocaSize, pHead)) {return false;}
+ void * pCompGlyf = GlyfLookup(static_cast<gid16>(rgnCompId[i]), pGlyf, pLoca, lGlyfSize, lLocaSize, pHead);
+ if (pCompGlyf == NULL) {return false;}
+ // returns false on multi-level composite
+ if (!GlyfPoints(pCompGlyf, prgnCurrentX, prgnCurrentY, prgbCurrentFlag,
+ cCurrentPoints, cActualPts))
+ return false;
+ if (!GetComponentPlacement(pSimpleGlyf, rgnCompId[i], fOffset, a, b))
+ return false;
+ if (!GetComponentTransform(pSimpleGlyf, rgnCompId[i],
+ flt11, flt12, flt21, flt22, fTransOff))
+ return false;
+ bool fIdTrans = flt11 == 1.0 && flt12 == 0.0 && flt21 == 0.0 && flt22 == 1.0;
+
+ // convert points to absolute coordinates
+ // do before transform and attachment point placement are applied
+ CalcAbsolutePoints(prgnCurrentX, prgnCurrentY, cActualPts);
+
+ // apply transform - see main method note above
+ // do before attachment point calcs
+ if (!fIdTrans)
+ for (int j = 0; j < cActualPts; j++)
+ {
+ int x = prgnCurrentX[j]; // store before transform applied
+ int y = prgnCurrentY[j];
+ prgnCurrentX[j] = (int)(x * flt11 + y * flt12);
+ prgnCurrentY[j] = (int)(x * flt21 + y * flt22);
+ }
+
+ // apply placement - see main method note above
+ int nXOff, nYOff;
+ if (fOffset) // explicit x & y offsets
+ {
+ /* ignore fTransOff for now
+ if (fTransOff && !fIdTrans)
+ { // transform x & y offsets
+ nXOff = (int)(a * flt11 + b * flt12);
+ nYOff = (int)(a * flt21 + b * flt22);
+ }
+ else */
+ { // don't transform offset
+ nXOff = a;
+ nYOff = b;
+ }
+ }
+ else // attachment points
+ { // in case first point is relative to preceding glyph and second relative to current
+ // nXOff = prgnPrevX[a] - prgnCurrentX[b];
+ // nYOff = prgnPrevY[a] - prgnCurrentY[b];
+ // first point number relative to whole composite, second relative to current glyph
+ nXOff = prgnX[a] - prgnCurrentX[b];
+ nYOff = prgnY[a] - prgnCurrentY[b];
+ }
+ for (int j = 0; j < cActualPts; j++)
+ {
+ prgnCurrentX[j] += nXOff;
+ prgnCurrentY[j] += nYOff;
+ }
+
+ // prgnPrevX = prgnCurrentX;
+ // prgnPrevY = prgnCurrentY;
+ prgnCurrentX += cActualPts;
+ prgnCurrentY += cActualPts;
+ prgbCurrentFlag += cActualPts;
+ cCurrentPoints -= cActualPts;
+ }
+
+ SimplifyFlags((char *)prgfOnCurve, cnPoints);
+
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Simplify the meaning of flags to just indicate whether point is on-curve or off-curve.
+---------------------------------------------------------------------------------------------*/
+bool SimplifyFlags(char * prgbFlags, int cnPoints)
+{
+ for (int i = 0; i < cnPoints; i++)
+ prgbFlags[i] = static_cast<char>(prgbFlags[i] & Sfnt::SimpleGlyph::OnCurve);
+ return true;
+}
+
+/*----------------------------------------------------------------------------------------------
+ Convert relative point coordinates to absolute coordinates
+ Points are stored in the font such that they are offsets from one another except for the
+ first point of a glyph.
+---------------------------------------------------------------------------------------------*/
+bool CalcAbsolutePoints(int * prgnX, int * prgnY, int cnPoints)
+{
+ int nX = prgnX[0];
+ int nY = prgnY[0];
+ for (int i = 1; i < cnPoints; i++)
+ {
+ prgnX[i] += nX;
+ nX = prgnX[i];
+ prgnY[i] += nY;
+ nY = prgnY[i];
+ }
+
+ return true;
+}
+#endif
+
+/*----------------------------------------------------------------------------------------------
+ Return the length of the 'name' table in bytes.
+ Currently used.
+---------------------------------------------------------------------------------------------*/
+#if 0
+size_t NameTableLength(const byte * pTable)
+{
+ byte * pb = (const_cast<byte *>(pTable)) + 2; // skip format
+ size_t cRecords = *pb++ << 8; cRecords += *pb++;
+ int dbStringOffset0 = (*pb++) << 8; dbStringOffset0 += *pb++;
+ int dbMaxStringOffset = 0;
+ for (size_t irec = 0; irec < cRecords; irec++)
+ {
+ int nPlatform = (*pb++) << 8; nPlatform += *pb++;
+ int nEncoding = (*pb++) << 8; nEncoding += *pb++;
+ int nLanguage = (*pb++) << 8; nLanguage += *pb++;
+ int nName = (*pb++) << 8; nName += *pb++;
+ int cbStringLen = (*pb++) << 8; cbStringLen += *pb++;
+ int dbStringOffset = (*pb++) << 8; dbStringOffset += *pb++;
+ if (dbMaxStringOffset < dbStringOffset + cbStringLen)
+ dbMaxStringOffset = dbStringOffset + cbStringLen;
+ }
+ return dbStringOffset0 + dbMaxStringOffset;
+}
+#endif
+
+} // end of namespace TtfUtil
+} // end of namespace graphite
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/UtfCodec.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/UtfCodec.cpp
index ca3c0c0a700..d1db5fa11f1 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/UtfCodec.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/UtfCodec.cpp
@@ -35,11 +35,11 @@ using namespace graphite2;
const int8 _utf_codec<8>::sz_lut[16] =
{
- 1,1,1,1,1,1,1,1, // 1 byte
- 0,0,0,0, // trailing byte
- 2,2, // 2 bytes
- 3, // 3 bytes
- 4 // 4 bytes
+ 1,1,1,1,1,1,1,1, // 1 byte
+ 0,0,0,0, // trailing byte
+ 2,2, // 2 bytes
+ 3, // 3 bytes
+ 4 // 4 bytes
};
const byte _utf_codec<8>::mask_lut[5] = {0x7f, 0xff, 0x3f, 0x1f, 0x0f};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/call_machine.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/call_machine.cpp
index f06f43cbda3..cfe57076fab 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/call_machine.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/call_machine.cpp
@@ -50,7 +50,7 @@ of the License or (at your option) any later version.
vm::Machine::stack_t * const sb, regbank & reg
// These are required by opcodes.h and should not be changed
-#define STARTOP(name) bool name(registers) REGPARM(4);\
+#define STARTOP(name) bool name(registers) REGPARM(4);\
bool name(registers) {
#define ENDOP return (sp - sb)/Machine::STACK_MAX==0; \
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/direct_machine.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/direct_machine.cpp
index 09709c30336..09709c30336 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/direct_machine.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/direct_machine.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/files.mk b/Build/source/libs/graphite2/graphite2-1.2.4/src/files.mk
index 358acef62df..a9950a58d70 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/files.mk
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/files.mk
@@ -1,6 +1,6 @@
# GRAPHITE2 LICENSING
#
-# Copyright 2010, SIL International
+# Copyright 2011, SIL International
# All rights reserved.
#
# This library is free software; you can redistribute it and/or modify
@@ -43,7 +43,7 @@ $(_NS)_SOURCES = \
$($(_NS)_BASE)/src/gr_face.cpp \
$($(_NS)_BASE)/src/gr_features.cpp \
$($(_NS)_BASE)/src/gr_font.cpp \
- $($(_NS)_BASE)/src/gr_logging.cpp \
+ $($(_NS)_BASE)/src/gr_logging.cpp \
$($(_NS)_BASE)/src/gr_segment.cpp \
$($(_NS)_BASE)/src/gr_slot.cpp \
$($(_NS)_BASE)/src/json.cpp \
@@ -79,6 +79,7 @@ $(_NS)_PRIVATE_HEADERS = \
$($(_NS)_BASE)/src/inc/CmapCache.h \
$($(_NS)_BASE)/src/inc/Code.h \
$($(_NS)_BASE)/src/inc/Endian.h \
+ $($(_NS)_BASE)/src/inc/Error.h \
$($(_NS)_BASE)/src/inc/Face.h \
$($(_NS)_BASE)/src/inc/FeatureMap.h \
$($(_NS)_BASE)/src/inc/FeatureVal.h \
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_char_info.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_char_info.cpp
index ebcb68e593f..ebcb68e593f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_char_info.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_char_info.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_face.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_face.cpp
index caf16b33a35..a245da4da47 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_face.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_face.cpp
@@ -31,9 +31,14 @@ of the License or (at your option) any later version.
#include "inc/CachedFace.h"
#include "inc/CmapCache.h"
#include "inc/Silf.h"
+#include "inc/json.h"
using namespace graphite2;
+#if !defined GRAPHITE2_NTRACING
+extern json *global_log;
+#endif
+
namespace
{
bool load_face(Face & face, unsigned int options)
@@ -49,8 +54,27 @@ namespace
if (!face.readGlyphs(options))
return false;
- return silf ? face.readFeatures() && face.readGraphite(silf)
- : options & gr_face_dumbRendering;
+ if (silf)
+ {
+ if (!face.readFeatures() || !face.readGraphite(silf))
+ {
+#if !defined GRAPHITE2_NTRACING
+ if (global_log)
+ {
+ *global_log << json::object
+ << "type" << "fontload"
+ << "failure" << face.error()
+ << "context" << face.error_context()
+ << json::close;
+ }
+#endif
+ return false;
+ }
+ else
+ return true;
+ }
+ else
+ return options & gr_face_dumbRendering;
}
}
@@ -59,7 +83,7 @@ extern "C" {
gr_face* gr_make_face_with_ops(const void* appFaceHandle/*non-NULL*/, const gr_face_ops *ops, unsigned int faceOptions)
//the appFaceHandle must stay alive all the time when the gr_face is alive. When finished with the gr_face, call destroy_face
{
- if (ops == 0) return 0;
+ if (ops == 0) return 0;
Face *res = new Face(appFaceHandle, *ops);
if (res && load_face(*res, faceOptions))
@@ -79,7 +103,7 @@ gr_face* gr_make_face(const void* appFaceHandle/*non-NULL*/, gr_get_table_fn tab
gr_face* gr_make_face_with_seg_cache_and_ops(const void* appFaceHandle/*non-NULL*/, const gr_face_ops *ops, unsigned int cacheSize, unsigned int faceOptions)
//the appFaceHandle must stay alive all the time when the GrFace is alive. When finished with the GrFace, call destroy_face
{
- if (ops == 0) return 0;
+ if (ops == 0) return 0;
CachedFace *res = new CachedFace(appFaceHandle, *ops);
if (res && load_face(*res, faceOptions)
@@ -120,17 +144,17 @@ void gr_tag_to_str(gr_uint32 tag, char *str)
inline
uint32 zeropad(const uint32 x)
{
- if (x == 0x20202020) return 0;
- if ((x & 0x00FFFFFF) == 0x00202020) return x & 0xFF000000;
- if ((x & 0x0000FFFF) == 0x00002020) return x & 0xFFFF0000;
- if ((x & 0x000000FF) == 0x00000020) return x & 0xFFFFFF00;
- return x;
+ if (x == 0x20202020) return 0;
+ if ((x & 0x00FFFFFF) == 0x00202020) return x & 0xFF000000;
+ if ((x & 0x0000FFFF) == 0x00002020) return x & 0xFFFF0000;
+ if ((x & 0x000000FF) == 0x00000020) return x & 0xFFFFFF00;
+ return x;
}
gr_feature_val* gr_face_featureval_for_lang(const gr_face* pFace, gr_uint32 langname/*0 means clone default*/) //clones the features. if none for language, clones the default
{
assert(pFace);
- zeropad(langname);
+ langname = zeropad(langname);
return static_cast<gr_feature_val *>(pFace->theSill().cloneFeatures(langname));
}
@@ -138,7 +162,7 @@ gr_feature_val* gr_face_featureval_for_lang(const gr_face* pFace, gr_uint32 lang
const gr_feature_ref* gr_face_find_fref(const gr_face* pFace, gr_uint32 featId) //When finished with the FeatureRef, call destroy_FeatureRef
{
assert(pFace);
- zeropad(featId);
+ featId = zeropad(featId);
const FeatureRef* pRef = pFace->featureById(featId);
return static_cast<const gr_feature_ref*>(pRef);
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_features.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_features.cpp
index 63c5564ffdd..38cebb7b5db 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_features.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_features.cpp
@@ -37,7 +37,7 @@ extern "C" {
gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feature_val* feats) //returns 0 if either pointer is NULL
{
- if (!pfeatureref || !feats) return 0;
+ if (!pfeatureref || !feats) return 0;
return pfeatureref->getFeatureVal(*feats);
}
@@ -45,7 +45,7 @@ gr_uint16 gr_fref_feature_value(const gr_feature_ref* pfeatureref, const gr_feat
int gr_fref_set_feature_value(const gr_feature_ref* pfeatureref, gr_uint16 val, gr_feature_val* pDest)
{
- if (!pfeatureref || !pDest) return 0;
+ if (!pfeatureref || !pDest) return 0;
return pfeatureref->applyValToFeature(val, *pDest);
}
@@ -121,7 +121,7 @@ void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting,
void gr_label_destroy(void * label)
{
- free(label);
+ free(label);
}
gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL*/)
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_font.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_font.cpp
index 22e4ec9c157..ed70ab7381e 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_font.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_font.cpp
@@ -47,9 +47,9 @@ gr_font* gr_make_font(float ppm/*pixels per em*/, const gr_face *face)
gr_font* gr_make_font_with_ops(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, const gr_font_ops * font_ops, const gr_face * face/*needed for scaling*/)
{ //the appFontHandle must stay alive all the time when the gr_font is alive. When finished with the gr_font, call destroy_gr_font
- if (face == 0) return 0;
+ if (face == 0) return 0;
- Font * const res = new Font(ppm, *face, appFontHandle, font_ops);
+ Font * const res = new Font(ppm, *face, appFontHandle, font_ops);
return static_cast<gr_font*>(res);
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_logging.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_logging.cpp
new file mode 100644
index 00000000000..7cfe5360886
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_logging.cpp
@@ -0,0 +1,242 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2010, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#include <cstdio>
+
+#include "graphite2/Log.h"
+#include "inc/debug.h"
+#include "inc/CharInfo.h"
+#include "inc/Slot.h"
+#include "inc/Segment.h"
+#include "inc/json.h"
+
+#if defined _WIN32
+#include "windows.h"
+#endif
+
+using namespace graphite2;
+
+#if !defined GRAPHITE2_NTRACING
+json *global_log = NULL;
+#endif
+
+extern "C" {
+
+bool gr_start_logging(GR_MAYBE_UNUSED gr_face * face, const char *log_path)
+{
+ if (!log_path) return false;
+
+#if !defined GRAPHITE2_NTRACING
+ gr_stop_logging(face);
+#if defined _WIN32
+ int n = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, log_path, -1, 0, 0);
+ if (n == 0 || n > MAX_PATH - 12) return false;
+
+ LPWSTR wlog_path = gralloc<WCHAR>(n);
+ if (!wlog_path) return false;
+ FILE *log = 0;
+ if (wlog_path && MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, log_path, -1, wlog_path, n))
+ log = _wfopen(wlog_path, L"wt");
+
+ free(wlog_path);
+#else // _WIN32
+ FILE *log = fopen(log_path, "wt");
+#endif // _WIN32
+ if (!log) return false;
+
+ if (face)
+ {
+ face->setLogger(log);
+ if (!face->logger()) return false;
+
+ *face->logger() << json::array;
+#ifdef GRAPHITE2_TELEMETRY
+ *face->logger() << face->tele;
+#endif
+ }
+ else
+ {
+ global_log = new json(log);
+ *global_log << json::array;
+ }
+
+ return true;
+#else // GRAPHITE2_NTRACING
+ return false;
+#endif // GRAPHITE2_NTRACING
+}
+
+bool graphite_start_logging(FILE * /* log */, GrLogMask /* mask */)
+{
+//#if !defined GRAPHITE2_NTRACING
+// graphite_stop_logging();
+//
+// if (!log) return false;
+//
+// dbgout = new json(log);
+// if (!dbgout) return false;
+//
+// *dbgout << json::array;
+// return true;
+//#else
+ return false;
+//#endif
+}
+
+void gr_stop_logging(GR_MAYBE_UNUSED gr_face * face)
+{
+#if !defined GRAPHITE2_NTRACING
+ if (face && face->logger())
+ {
+ FILE * log = face->logger()->stream();
+ face->setLogger(0);
+ fclose(log);
+ }
+ else if (!face && global_log)
+ {
+ FILE * log = global_log->stream();
+ delete global_log;
+ fclose(log);
+ }
+#endif
+}
+
+void graphite_stop_logging()
+{
+// if (dbgout) delete dbgout;
+// dbgout = 0;
+}
+
+} // extern "C"
+
+#ifdef GRAPHITE2_TELEMETRY
+size_t * graphite2::telemetry::_category = 0UL;
+#endif
+
+#if !defined GRAPHITE2_NTRACING
+
+#ifdef GRAPHITE2_TELEMETRY
+
+json & graphite2::operator << (json & j, const telemetry & t) throw()
+{
+ j << json::object
+ << "type" << "telemetry"
+ << "silf" << t.silf
+ << "states" << t.states
+ << "starts" << t.starts
+ << "transitions" << t.transitions
+ << "glyphs" << t.glyph
+ << "code" << t.code
+ << "misc" << t.misc
+ << "total" << (t.silf + t.states + t.starts + t.transitions + t.glyph + t.code + t.misc)
+ << json::close;
+ return j;
+}
+#else
+json & graphite2::operator << (json & j, const telemetry &) throw()
+{
+ return j;
+}
+#endif
+
+
+json & graphite2::operator << (json & j, const CharInfo & ci) throw()
+{
+ return j << json::object
+ << "offset" << ci.base()
+ << "unicode" << ci.unicodeChar()
+ << "break" << ci.breakWeight()
+ << "flags" << ci.flags()
+ << "slot" << json::flat << json::object
+ << "before" << ci.before()
+ << "after" << ci.after()
+ << json::close
+ << json::close;
+}
+
+
+json & graphite2::operator << (json & j, const dslot & ds) throw()
+{
+ assert(ds.first);
+ assert(ds.second);
+ const Segment & seg = *ds.first;
+ const Slot & s = *ds.second;
+
+ j << json::object
+ << "id" << objectid(ds)
+ << "gid" << s.gid()
+ << "charinfo" << json::flat << json::object
+ << "original" << s.original()
+ << "before" << s.before()
+ << "after" << s.after()
+ << json::close
+ << "origin" << s.origin()
+ << "shift" << Position(float(s.getAttr(0, gr_slatShiftX, 0)),
+ float(s.getAttr(0, gr_slatShiftY, 0)))
+ << "advance" << s.advancePos()
+ << "insert" << s.isInsertBefore()
+ << "break" << s.getAttr(&seg, gr_slatBreak, 0);
+ if (s.just() > 0)
+ j << "justification" << s.just();
+ if (s.getBidiLevel() > 0)
+ j << "bidi" << s.getBidiLevel();
+ if (!s.isBase())
+ j << "parent" << json::flat << json::object
+ << "id" << objectid(dslot(&seg, s.attachedTo()))
+ << "level" << s.getAttr(0, gr_slatAttLevel, 0)
+ << "offset" << s.attachOffset()
+ << json::close;
+ j << "user" << json::flat << json::array;
+ for (int n = 0; n!= seg.numAttrs(); ++n)
+ j << s.userAttrs()[n];
+ j << json::close;
+ if (s.firstChild())
+ {
+ j << "children" << json::flat << json::array;
+ for (const Slot *c = s.firstChild(); c; c = c->nextSibling())
+ j << objectid(dslot(&seg, c));
+ j << json::close;
+ }
+ return j << json::close;
+}
+
+
+graphite2::objectid::objectid(const dslot & ds) throw()
+{
+ const Slot * const p = ds.second;
+ uint32 s = reinterpret_cast<size_t>(p);
+ sprintf(name, "%.4x-%.2x-%.4hx", uint16(s >> 16), uint16(p ? p->userAttrs()[ds.first->silf()->numUser()] : 0), uint16(s));
+ name[sizeof name-1] = 0;
+}
+
+graphite2::objectid::objectid(const Segment * const p) throw()
+{
+ uint32 s = reinterpret_cast<size_t>(p);
+ sprintf(name, "%.4x-%.2x-%.4hx", uint16(s >> 16), 0, uint16(s));
+ name[sizeof name-1] = 0;
+}
+
+#endif
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_segment.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_segment.cpp
index 6eca66b4a0b..71e40bcdddf 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_segment.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_segment.cpp
@@ -42,8 +42,8 @@ namespace
// if (!font) return NULL;
Segment* pRes=new Segment(nChars, face, script, dir);
- pRes->read_text(face, pFeats, enc, pStart, nChars);
- if (!pRes->runGraphite())
+
+ if (!pRes->read_text(face, pFeats, enc, pStart, nChars) || !pRes->runGraphite())
{
delete pRes;
return NULL;
@@ -64,46 +64,46 @@ namespace
template <typename utf_iter>
inline size_t count_unicode_chars(utf_iter first, const utf_iter last, const void **error)
{
- size_t n_chars = 0;
- uint32 usv = 0;
-
- if (last)
- {
- for (;first != last; ++first, ++n_chars)
- if ((usv = *first) == 0 || first.error()) break;
- }
- else
- {
- while ((usv = *first) != 0 && !first.error())
- {
- ++first;
- ++n_chars;
- }
- }
-
- if (error) *error = first.error() ? first : 0;
- return n_chars;
+ size_t n_chars = 0;
+ uint32 usv = 0;
+
+ if (last)
+ {
+ for (;first != last; ++first, ++n_chars)
+ if ((usv = *first) == 0 || first.error()) break;
+ }
+ else
+ {
+ while ((usv = *first) != 0 && !first.error())
+ {
+ ++first;
+ ++n_chars;
+ }
+ }
+
+ if (error) *error = first.error() ? first : 0;
+ return n_chars;
}
extern "C" {
size_t gr_count_unicode_characters(gr_encform enc, const void* buffer_begin, const void* buffer_end/*don't go on or past end, If NULL then ignored*/, const void** pError) //Also stops on nul. Any nul is not in the count
{
- assert(buffer_begin);
-
- switch (enc)
- {
- case gr_utf8: return count_unicode_chars<utf8::const_iterator>(buffer_begin, buffer_end, pError); break;
- case gr_utf16: return count_unicode_chars<utf16::const_iterator>(buffer_begin, buffer_end, pError); break;
- case gr_utf32: return count_unicode_chars<utf32::const_iterator>(buffer_begin, buffer_end, pError); break;
- default: return 0;
- }
+ assert(buffer_begin);
+
+ switch (enc)
+ {
+ case gr_utf8: return count_unicode_chars<utf8::const_iterator>(buffer_begin, buffer_end, pError); break;
+ case gr_utf16: return count_unicode_chars<utf16::const_iterator>(buffer_begin, buffer_end, pError); break;
+ case gr_utf32: return count_unicode_chars<utf32::const_iterator>(buffer_begin, buffer_end, pError); break;
+ default: return 0;
+ }
}
gr_segment* gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 script, const gr_feature_val* pFeats, gr_encform enc, const void* pStart, size_t nChars, int dir)
{
- const gr_feature_val * tmp_feats = 0;
+ const gr_feature_val * tmp_feats = 0;
if (pFeats == 0)
pFeats = tmp_feats = static_cast<const gr_feature_val*>(face->theSill().cloneFeatures(0));
gr_segment * seg = makeAndInitialize(font, face, script, pFeats, enc, pStart, nChars, dir);
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_slot.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_slot.cpp
index c615e40ffe5..c615e40ffe5 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/gr_slot.cpp
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/gr_slot.cpp
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Bidi.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Bidi.h
new file mode 100644
index 00000000000..9593c7e149a
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Bidi.h
@@ -0,0 +1,126 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2013, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+
+namespace graphite2
+{
+
+class BracketPair
+{
+public:
+ BracketPair(uint16 g, Slot *s, uint8 b, BracketPair *p, BracketPair *l) : _open(s), _close(0), _parent(p), _next(0), _prev(l), _gid(g), _mask(0), _before(b) {};
+ uint16 gid() const { return _gid; }
+ Slot *open() const { return _open; }
+ Slot *close() const { return _close; }
+ uint8 mask() const { return _mask; }
+ int8 before() const { return _before; }
+ BracketPair *parent() const { return _parent; }
+ void close(Slot *s) { _close = s; }
+ BracketPair *next() const { return _next; }
+ BracketPair *prev() const { return _prev; }
+ void next(BracketPair *n) { _next = n; }
+ void orin(uint8 m) { _mask |= m; }
+private:
+ Slot * _open; // Slot of opening paren
+ Slot * _close; // Slot of closing paren
+ BracketPair * _parent; // pair this pair is in or NULL
+ BracketPair * _next; // next pair along the string
+ BracketPair * _prev; // pair that closed last before we opened
+ uint16 _gid; // gid of closing paren
+ uint8 _mask; // bitmap (2 bits) of directions within the pair
+ int8 _before; // most recent strong type (L, R, OPP, CPP)
+};
+
+class BracketPairStack
+{
+public:
+ BracketPairStack(int s) : _stack(grzeroalloc<BracketPair>(s)), _ip(_stack - 1), _top(0), _last(0), _lastclose(0), _size(s) {}
+ ~BracketPairStack() { free(_stack); }
+
+public:
+ BracketPair *scan(uint16 gid);
+ void close(BracketPair *tos, Slot *s);
+ BracketPair *push(uint16 gid, Slot *pos, uint8 before, int prevopen);
+ void orin(uint8 mask);
+ void clear() { _ip = _stack - 1; _top = 0; _last = 0; _lastclose = 0; }
+ int size() const { return _size; }
+ BracketPair *start() const { return _stack; }
+
+ CLASS_NEW_DELETE
+
+private:
+
+ BracketPair *_stack; // start of storage
+ BracketPair *_ip; // where to add the next pair
+ BracketPair *_top; // current parent
+ BracketPair *_last; // end of next() chain
+ BracketPair *_lastclose; // last pair to close
+ int _size; // capacity
+};
+
+inline BracketPair *BracketPairStack::scan(uint16 gid)
+{
+ BracketPair *res = _top;
+ while (res >= _stack)
+ {
+ if (res->gid() == gid)
+ return res;
+ res = res->parent();
+ }
+ return 0;
+}
+
+inline void BracketPairStack::close(BracketPair *tos, Slot *s)
+{
+ for ( ; _last && _last != tos && !_last->close(); _last = _last->parent())
+ { }
+ tos->close(s);
+ _last->next(NULL);
+ _lastclose = tos;
+ _top = tos->parent();
+}
+
+inline BracketPair *BracketPairStack::push(uint16 gid, Slot *pos, uint8 before, int prevopen)
+{
+ if (++_ip - _stack < _size && _stack)
+ {
+ ::new (_ip) BracketPair(gid, pos, before, _top, prevopen ? _last : _lastclose);
+ if (_last) _last->next(_ip);
+ _last = _ip;
+ }
+ _top = _ip;
+ return _ip;
+}
+
+inline void BracketPairStack::orin(uint8 mask)
+{
+ BracketPair *t = _top;
+ for ( ; t; t = t->parent())
+ t->orin(mask);
+}
+
+}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CachedFace.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CachedFace.h
index 53674754ee2..53674754ee2 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CachedFace.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CachedFace.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CharInfo.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CharInfo.h
index 2debaf73477..d9e56eeed64 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CharInfo.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CharInfo.h
@@ -34,7 +34,7 @@ class CharInfo
{
public:
- CharInfo() : m_char(0), m_before(-1), m_after(0), m_base(0), m_featureid(0), m_break(0), m_flags(0) {}
+ CharInfo() : m_char(0), m_before(-1), m_after(-1), m_base(0), m_featureid(0), m_break(0), m_flags(0) {}
void init(int cid) { m_char = cid; }
unsigned int unicodeChar() const { return m_char; }
void feats(int offset) { m_featureid = offset; }
@@ -56,8 +56,8 @@ private:
int m_before; // slot index before us, comes before
int m_after; // slot index after us, comes after
size_t m_base; // offset into input string corresponding to this charinfo
- uint8 m_featureid; // index into features list in the segment
- int8 m_break; // breakweight coming from lb table
+ uint8 m_featureid; // index into features list in the segment
+ int8 m_break; // breakweight coming from lb table
uint8 m_flags; // 0,1 segment split.
};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CmapCache.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CmapCache.h
index a7df78ea568..7820c958b0e 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/CmapCache.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/CmapCache.h
@@ -37,13 +37,13 @@ class Cmap
{
public:
- virtual ~Cmap() throw() {}
+ virtual ~Cmap() throw() {}
- virtual uint16 operator [] (const uint32) const throw() { return 0; }
+ virtual uint16 operator [] (const uint32) const throw() { return 0; }
- virtual operator bool () const throw() { return false; }
+ virtual operator bool () const throw() { return false; }
- CLASS_NEW_DELETE;
+ CLASS_NEW_DELETE;
};
class DirectCmap : public Cmap
@@ -52,9 +52,9 @@ class DirectCmap : public Cmap
DirectCmap & operator = (const DirectCmap &);
public:
- DirectCmap(const Face &);
- virtual uint16 operator [] (const uint32 usv) const throw();
- virtual operator bool () const throw();
+ DirectCmap(const Face &);
+ virtual uint16 operator [] (const uint32 usv) const throw();
+ virtual operator bool () const throw();
CLASS_NEW_DELETE;
private:
@@ -69,10 +69,10 @@ class CachedCmap : public Cmap
CachedCmap & operator = (const CachedCmap &);
public:
- CachedCmap(const Face &);
- virtual ~CachedCmap() throw();
- virtual uint16 operator [] (const uint32 usv) const throw();
- virtual operator bool () const throw();
+ CachedCmap(const Face &);
+ virtual ~CachedCmap() throw();
+ virtual uint16 operator [] (const uint32 usv) const throw();
+ virtual operator bool () const throw();
CLASS_NEW_DELETE;
private:
bool m_isBmpOnly;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Code.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Code.h
index d9539b0da24..1ce148ab430 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Code.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Code.h
@@ -168,7 +168,7 @@ inline bool Machine::Code::deletes() const throw()
inline size_t Machine::Code::maxRef() const throw()
{
- return _max_ref;
+ return _max_ref;
}
} // namespace vm
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Endian.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Endian.h
new file mode 100644
index 00000000000..fc84ec27898
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Endian.h
@@ -0,0 +1,112 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+
+/*
+Description:
+ A set of fast template based decoders for decoding values of any C integer
+ type up to long int size laid out with most significant byte first or least
+ significant byte first (aka big endian or little endian). These are CPU
+ byte order agnostic and will function the same regardless of the CPUs native
+ byte order.
+
+ Being template based means if the either le or be class is not used then
+ template code of unused functions will not be instantiated by the compiler
+ and thus shouldn't cause any overhead.
+*/
+
+#include <cstddef>
+
+#pragma once
+
+
+class be
+{
+ template<int S>
+ inline static unsigned long int _peek(const unsigned char * p) {
+ return _peek<S/2>(p) << (S/2)*8 | _peek<S/2>(p+S/2);
+ }
+public:
+ template<typename T>
+ inline static T peek(const void * p) {
+ return T(_peek<sizeof(T)>(static_cast<const unsigned char *>(p)));
+ }
+
+ template<typename T>
+ inline static T read(const unsigned char * &p) {
+ const T r = T(_peek<sizeof(T)>(p));
+ p += sizeof r;
+ return r;
+ }
+
+ template<typename T>
+ inline static T swap(const T x) {
+ return T(_peek<sizeof(T)>(reinterpret_cast<const unsigned char *>(&x)));
+ }
+
+ template<typename T>
+ inline static void skip(const unsigned char * &p, size_t n=1) {
+ p += sizeof(T)*n;
+ }
+};
+
+template<>
+inline unsigned long int be::_peek<1>(const unsigned char * p) { return *p; }
+
+
+class le
+{
+ template<int S>
+ inline static unsigned long int _peek(const unsigned char * p) {
+ return _peek<S/2>(p) | _peek<S/2>(p+S/2) << (S/2)*8;
+ }
+public:
+ template<typename T>
+ inline static T peek(const void * p) {
+ return T(_peek<sizeof(T)>(static_cast<const unsigned char *>(p)));
+ }
+
+ template<typename T>
+ inline static T read(const unsigned char * &p) {
+ const T r = T(_peek<sizeof(T)>(p));
+ p += sizeof r;
+ return r;
+ }
+
+ template<typename T>
+ inline static T swap(const T x) {
+ return T(_peek<sizeof(T)>(reinterpret_cast<const unsigned char *>(&x)));
+ }
+
+ template<typename T>
+ inline static void skip(const unsigned char * &p, size_t n=1) {
+ p += sizeof(T)*n;
+ }
+};
+
+template<>
+inline unsigned long int le::_peek<1>(const unsigned char * p) { return *p; }
+
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Error.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Error.h
new file mode 100644
index 00000000000..dd958de6fcd
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Error.h
@@ -0,0 +1,127 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2013, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+
+// numbers are explicitly assigned for future proofing
+
+namespace graphite2
+{
+
+class Error
+{
+public:
+ Error() : _e(0) {};
+ operator bool() { return (_e != 0); }
+ int error() { return _e; }
+ void error(int e) { _e = e; }
+ bool test(bool pr, int err) { return (_e = int(pr) * err); }
+
+private:
+ int _e;
+};
+
+enum errcontext {
+ EC_READGLYPHS = 1, // while reading glyphs
+ EC_READSILF = 2, // in Silf table
+ EC_ASILF = 3, // in Silf %d
+ EC_APASS = 4, // in Silf %d, pass %d
+ EC_PASSCCODE = 5, // in pass constraint code for Silf %d, pass %d
+ EC_ARULE = 6, // in Silf %d, pass %d, rule %d
+ EC_ASTARTS = 7, // in Silf %d, pass %d, start state %d
+ EC_ATRANS = 8, // in Silf %d, pass %d, fsm state %d
+ EC_ARULEMAP = 9 // in Silf %d, pass %d, state %d
+};
+
+enum errors {
+ E_OUTOFMEM = 1, // Out of memory
+ E_NOGLYPHS = 2, // There are no glyphs in the font
+ E_BADUPEM = 3, // The units per em for the font is bad (0)
+ E_BADCMAP = 4, // The font does not contain any useful cmaps
+ E_NOSILF = 5, // Missing Silf table
+ E_TOOOLD = 6, // Silf table version is too old
+ E_BADSIZE = 7, // context object has the wrong structural size
+// Silf Subtable Errors take a Silf subtable number * 256 in the context
+ E_BADMAXGLYPH = 8, // Silf max glyph id is too high
+ E_BADNUMJUSTS = 9, // Number of Silf justification blocks is too high
+ E_BADENDJUSTS = 10, // Silf justification blocks take too much of the Silf table space
+ E_BADCRITFEATURES = 11, // Critical features section in a Silf table is too big
+ E_BADSCRIPTTAGS = 12, // Silf script tags area is too big
+ E_BADAPSEUDO = 13, // The pseudo glyph attribute number is too high
+ E_BADABREAK = 14, // The linebreak glyph attribute number is too high
+ E_BADABIDI = 15, // The bidi glyph attribute number is too high
+ E_BADAMIRROR = 16, // The mirrored glyph attribute number is too high
+ E_BADNUMPASSES = 17, // The number of passes is > 128
+ E_BADPASSESSTART = 18, // The Silf table is too small to hold any passes
+ E_BADPASSBOUND = 19, // The positioning pass number is too low or the substitution pass number is too high
+ E_BADPPASS = 20, // The positioning pass number is too high
+ E_BADSPASS = 21, // the substitution pass number is too high
+ E_BADJPASSBOUND = 22, // the justification pass must be higher than the positioning pass
+ E_BADJPASS = 23, // the justification pass is too high
+ E_BADALIG = 24, // the number of initial ligature component glyph attributes is too high
+ E_BADBPASS = 25, // the bidi pass number is specified and is either too high or too low
+ E_BADNUMPSEUDO = 26, // The number of pseudo glyphs is too high
+ E_BADCLASSSIZE = 27, // The size of the classes block is bad
+ E_TOOMANYLINEAR = 28, // The number of linear classes in the silf table is too high
+ E_CLASSESTOOBIG = 29, // There are too many classes for the space allocated in the Silf subtable
+ E_MISALIGNEDCLASSES = 30, // The class offsets in the class table don't line up with the number of classes
+ E_HIGHCLASSOFFSET = 31, // The class offsets point out of the class table
+ E_BADCLASSOFFSET = 32, // A class offset is less than one following it
+ E_BADCLASSLOOKUPINFO = 33, // The search header info for a non-linear class has wrong values in it
+// Pass subtable errors. Context has pass number * 65536
+ E_BADPASSSTART = 34, // The start offset for a particular pass is bad
+ E_BADPASSEND = 35, // The end offset for a particular pass is bad
+ E_BADPASSLENGTH = 36, // The length of the pass is too small
+ E_BADNUMTRANS = 37, // The number of transition states in the fsm is bad
+ E_BADNUMSUCCESS = 38, // The number of success states in the fsm is bad
+ E_BADNUMSTATES = 39, // The number of states in the fsm is bad
+ E_NORANGES = 40, // There are no columns in the fsm
+ E_BADRULEMAPLEN = 41, // The size of the success state to rule mapping is bad
+ E_BADCTXTLENBOUNDS = 42, // The precontext maximum is greater than its minimum
+ E_BADCTXTLENS = 43, // The lists of rule lengths or pre context lengths is bad
+ E_BADPASSCCODEPTR = 44, // The pass constraint code position does not align with where the forward reference says it should be
+ E_BADRULECCODEPTR = 45, // The rule constraint code position does not align with where the forward reference says it should be
+ E_BADCCODELEN = 46, // Bad rule/pass constraint code length
+ E_BADACTIONCODEPTR = 47, // The action code position does not align with where the forward reference says it should be
+ E_MUTABLECCODE = 48, // Constraint code edits slots. It shouldn't.
+ E_BADSTATE = 49, // Bad state transition referencing an illegal state
+ E_BADRULEMAPPING = 50, // The structure of the rule mapping is bad
+ E_BADRANGE = 51, // Bad column range structure including a glyph in more than one column
+ E_BADRULENUM = 52, // A reference to a rule is out of range (too high)
+// Code errors
+ E_CODEFAILURE = 60, // Base code error. The following subcodes must align with Machine::Code::status_t in Code.h
+ E_CODEALLOC = 61, // Out of memory
+ E_INVALIDOPCODE = 62, // Invalid op code
+ E_UNIMPOPCODE = 63, // Unimplemented op code encountered
+ E_OUTOFRANGECODE = 64, // Code argument out of range
+ E_BADJUMPCODE = 65, // Code jumps past end of op codes
+ E_CODEBADARGS = 66, // Code arguments exhausted
+ E_CODENORETURN = 67, // Missing return type op code at end of code
+ E_CODENESTEDCTXT = 68 // Nested context encountered in code
+};
+
+}
+
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Face.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Face.h
index 5730e579c4f..e2574492583 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Face.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Face.h
@@ -34,6 +34,7 @@ of the License or (at your option) any later version.
#include "inc/FeatureMap.h"
#include "inc/TtfUtil.h"
#include "inc/Silf.h"
+#include "inc/Error.h"
namespace graphite2 {
@@ -55,7 +56,7 @@ class Face
Face& operator=(const Face&);
public:
- class Table;
+ class Table;
static float default_glyph_advance(const void* face_ptr, gr_uint16 glyphid);
Face(const void* appFaceHandle/*non-NULL*/, const gr_face_ops & ops);
@@ -88,6 +89,12 @@ public:
uint16 getGlyphMetric(uint16 gid, uint8 metric) const;
uint16 findPseudo(uint32 uid) const;
+ // Errors
+ unsigned int error() const { return m_error; }
+ bool error(Error e) { m_error = e.error(); return false; }
+ unsigned int error_context() const { return m_error; }
+ void error_context(unsigned int errcntxt) { m_errcntxt = errcntxt; }
+
CLASS_NEW_DELETE;
private:
SillMap m_Sill;
@@ -98,6 +105,8 @@ private:
mutable Cmap * m_cmap; // cmap cache if available
mutable NameTable * m_pNames;
mutable json * m_logger;
+ unsigned int m_error;
+ unsigned int m_errcntxt;
protected:
Silf * m_silfs; // silf subtables.
uint16 m_numSilf; // num silf subtables in the silf table
@@ -139,7 +148,7 @@ const FeatureRef *Face::feature(uint16 index) const
inline
const GlyphCache & Face::glyphs() const
{
- return *m_pGlyphFaceCache;
+ return *m_pGlyphFaceCache;
}
inline
@@ -184,26 +193,26 @@ inline
Face::Table::Table(const Table & rhs) throw()
: _f(rhs._f), _p(rhs._p), _sz(rhs._sz)
{
- rhs._p = 0;
+ rhs._p = 0;
}
inline
Face::Table::~Table() throw()
{
- if (_p && _f->m_ops.release_table)
- (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p);
+ if (_p && _f->m_ops.release_table)
+ (*_f->m_ops.release_table)(_f->m_appFaceHandle, _p);
}
inline
Face::Table::operator const byte * () const throw()
{
- return _p;
+ return _p;
}
inline
-size_t Face::Table::size() const throw()
+size_t Face::Table::size() const throw()
{
- return _sz;
+ return _sz;
}
} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureMap.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureMap.h
index dc5175c3054..bc8a5db170d 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureMap.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureMap.h
@@ -52,11 +52,11 @@ private:
class FeatureRef
{
- typedef uint32 chunk_t;
- static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8;
+ typedef uint32 chunk_t;
+ static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8;
public:
- FeatureRef() : m_nameValues(0) {}
+ FeatureRef() : m_nameValues(0) {}
FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val,
uint32 name, uint16 uiName, uint16 flags,
FeatureSetting *settings, uint16 num_set) throw();
@@ -64,8 +64,8 @@ public:
bool applyValToFeature(uint32 val, Features& pDest) const; //defined in GrFaceImp.h
void maskFeature(Features & pDest) const {
- if (m_index < pDest.size()) //defensive
- pDest[m_index] |= m_mask;
+ if (m_index < pDest.size()) //defensive
+ pDest[m_index] |= m_mask;
}
uint32 getFeatureVal(const Features& feats) const; //defined in GrFaceImp.h
@@ -83,16 +83,16 @@ public:
private:
FeatureRef(const FeatureRef & rhs);
- const Face * m_pFace; //not NULL
+ const Face * m_pFace; //not NULL
FeatureSetting * m_nameValues; // array of name table ids for feature values
chunk_t m_mask, // bit mask to get the value from the vector
- m_max; // max value the value can take
- uint32 m_id; // feature identifier/name
- uint16 m_nameid, // Name table id for feature name
- m_flags, // feature flags (unused at the moment but read from the font)
- m_numSet; // number of values (number of entries in m_nameValues)
- byte m_bits, // how many bits to shift the value into place
- m_index; // index into the array to find the ulong to mask
+ m_max; // max value the value can take
+ uint32 m_id; // feature identifier/name
+ uint16 m_nameid, // Name table id for feature name
+ m_flags, // feature flags (unused at the moment but read from the font)
+ m_numSet; // number of values (number of entries in m_nameValues)
+ byte m_bits, // how many bits to shift the value into place
+ m_index; // index into the array to find the ulong to mask
private: //unimplemented
FeatureRef& operator=(const FeatureRef&);
@@ -137,7 +137,7 @@ friend class SillMap;
NameAndFeatureRef* m_pNamedFeats; //owned
FeatureVal* m_defaultFeatures; //owned
-private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures
+private: //defensive on m_feats, m_pNamedFeats, and m_defaultFeatures
FeatureMap(const FeatureMap&);
FeatureMap& operator=(const FeatureMap&);
};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureVal.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureVal.h
index 8c9298c76cf..5fbcf082063 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FeatureVal.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FeatureVal.h
@@ -56,7 +56,7 @@ public:
CLASS_NEW_DELETE
private:
- friend class FeatureRef; //so that FeatureRefs can manipulate m_vec directly
+ friend class FeatureRef; //so that FeatureRefs can manipulate m_vec directly
const FeatureMap* m_pMap;
};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FileFace.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FileFace.h
index 05e56d64543..81e501bab25 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/FileFace.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/FileFace.h
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Font.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Font.h
index 650bc7cd8c4..bc7084050e5 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Font.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Font.h
@@ -32,7 +32,7 @@ of the License or (at your option) any later version.
namespace graphite2 {
-#define INVALID_ADVANCE -1e38f // can't be a static const because non-integral
+#define INVALID_ADVANCE -1e38f // can't be a static const because non-integral
class Font
{
@@ -69,13 +69,13 @@ float Font::advance(unsigned short glyphid) const
inline
float Font::scale() const
{
- return m_scale;
+ return m_scale;
}
inline
bool Font::isHinted() const
{
- return m_hinted;
+ return m_hinted;
}
inline
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphCache.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphCache.h
index 74457152916..ab5b0b7c5fe 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphCache.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphCache.h
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -41,7 +41,7 @@ class GlyphCache
{
class Loader;
- GlyphCache(const GlyphCache&);
+ GlyphCache(const GlyphCache&);
GlyphCache& operator=(const GlyphCache&);
public:
@@ -58,11 +58,11 @@ public:
CLASS_NEW_DELETE;
private:
- const Loader * _glyph_loader;
- const GlyphFace * * _glyphs;
- unsigned short _num_glyphs,
- _num_attrs,
- _upem;
+ const Loader * _glyph_loader;
+ const GlyphFace * * _glyphs;
+ unsigned short _num_glyphs,
+ _num_attrs,
+ _upem;
};
inline
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphFace.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphFace.h
index 89ed5aea91a..89ed5aea91a 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/GlyphFace.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/GlyphFace.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/List.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/List.h
index f99036912d8..f99036912d8 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/List.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/List.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Machine.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Machine.h
index f6af44329fa..21f8addbb44 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Machine.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Machine.h
@@ -147,7 +147,7 @@ public:
CLASS_NEW_DELETE;
SlotMap & slotMap() const throw();
- status_t status() const throw();
+ status_t status() const throw();
operator bool () const throw();
private:
@@ -157,18 +157,18 @@ private:
SlotMap & _map;
stack_t _stack[STACK_MAX + 2*STACK_GUARD];
- status_t _status;
+ status_t _status;
};
inline Machine::Machine(SlotMap & map) throw()
: _map(map), _status(finished)
{
- // Initialise stack guard +1 entries as the stack pointer points to the
- // current top of stack, hence the first push will never write entry 0.
- // Initialising the guard space like this is unnecessary and is only
- // done to keep valgrind happy during fuzz testing. Hopefully loop
- // unrolling will flatten this.
- for (size_t n = STACK_GUARD + 1; n; --n) _stack[n-1] = 0;
+ // Initialise stack guard +1 entries as the stack pointer points to the
+ // current top of stack, hence the first push will never write entry 0.
+ // Initialising the guard space like this is unnecessary and is only
+ // done to keep valgrind happy during fuzz testing. Hopefully loop
+ // unrolling will flatten this.
+ for (size_t n = STACK_GUARD + 1; n; --n) _stack[n-1] = 0;
}
inline SlotMap& Machine::slotMap() const throw()
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Main.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Main.h
index 0717693d689..8f7c201b96b 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Main.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Main.h
@@ -44,7 +44,7 @@ typedef gr_int16 int16;
typedef gr_int32 int32;
typedef size_t uintptr;
-#if GRAPHITE2_TELEMETRY
+#ifdef GRAPHITE2_TELEMETRY
struct telemetry
{
class category;
@@ -82,7 +82,7 @@ struct telemetry {};
template <typename T> T * gralloc(size_t n)
{
-#if GRAPHITE2_TELEMETRY
+#ifdef GRAPHITE2_TELEMETRY
telemetry::count_bytes(sizeof(T) * n);
#endif
return reinterpret_cast<T*>(malloc(sizeof(T) * n));
@@ -90,7 +90,7 @@ template <typename T> T * gralloc(size_t n)
template <typename T> T * grzeroalloc(size_t n)
{
-#if GRAPHITE2_TELEMETRY
+#ifdef GRAPHITE2_TELEMETRY
telemetry::count_bytes(sizeof(T) * n);
#endif
return reinterpret_cast<T*>(calloc(n, sizeof(T)));
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/NameTable.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/NameTable.h
index 0fdbeb4d85f..0fdbeb4d85f 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/NameTable.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/NameTable.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Pass.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Pass.h
index 5fea65a289b..33abbdce503 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Pass.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Pass.h
@@ -38,6 +38,7 @@ struct Rule;
struct RuleEntry;
struct State;
class FiniteStateMachine;
+class Error;
class Pass
{
@@ -45,29 +46,29 @@ public:
Pass();
~Pass();
- bool readPass(const byte * pPass, size_t pass_length, size_t subtable_base, const Face & face);
+ bool readPass(const byte * pPass, size_t pass_length, size_t subtable_base, Face & face, Error &e);
void runGraphite(vm::Machine & m, FiniteStateMachine & fsm) const;
void init(Silf *silf) { m_silf = silf; }
byte spaceContextuals() const { return (m_flags & 0x0E) >> 1; }
CLASS_NEW_DELETE
private:
- void findNDoRule(Slot* & iSlot, vm::Machine &, FiniteStateMachine& fsm) const;
- int doAction(const vm::Machine::Code* codeptr, Slot * & slot_out, vm::Machine &) const;
- bool testPassConstraint(vm::Machine & m) const;
- bool testConstraint(const Rule & r, vm::Machine &) const;
- bool readRules(const byte * rule_map, const size_t num_entries,
+ void findNDoRule(Slot* & iSlot, vm::Machine &, FiniteStateMachine& fsm) const;
+ int doAction(const vm::Machine::Code* codeptr, Slot * & slot_out, vm::Machine &) const;
+ bool testPassConstraint(vm::Machine & m) const;
+ bool testConstraint(const Rule & r, vm::Machine &) const;
+ bool readRules(const byte * rule_map, const size_t num_entries,
const byte *precontext, const uint16 * sort_key,
const uint16 * o_constraint, const byte *constraint_data,
const uint16 * o_action, const byte * action_data,
- const Face &);
- bool readStates(const byte * starts, const byte * states, const byte * o_rule_map, const Face &);
- bool readRanges(const byte * ranges, size_t num_ranges);
- uint16 glyphToCol(const uint16 gid) const;
- bool runFSM(FiniteStateMachine & fsm, Slot * slot) const;
- void dumpRuleEventConsidered(const FiniteStateMachine & fsm, const RuleEntry & re) const;
- void dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & r, Slot * os) const;
- void adjustSlot(int delta, Slot * & slot_out, SlotMap &) const;
+ Face &, Error &e);
+ bool readStates(const byte * starts, const byte * states, const byte * o_rule_map, Face &, Error &e);
+ bool readRanges(const byte * ranges, size_t num_ranges, Error &e);
+ uint16 glyphToCol(const uint16 gid) const;
+ bool runFSM(FiniteStateMachine & fsm, Slot * slot) const;
+ void dumpRuleEventConsidered(const FiniteStateMachine & fsm, const RuleEntry & re) const;
+ void dumpRuleEventOutput(const FiniteStateMachine & fsm, const Rule & r, Slot * os) const;
+ void adjustSlot(int delta, Slot * & slot_out, SlotMap &) const;
const Silf* m_silf;
uint16 * m_cols;
Rule * m_rules; // rules
@@ -89,7 +90,7 @@ private:
byte m_maxPreCtxt;
vm::Machine::Code m_cPConstraint;
-private: //defensive
+private: //defensive
Pass(const Pass&);
Pass& operator=(const Pass&);
};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Position.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Position.h
index c6f1b755644..c6f1b755644 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Position.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Position.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Rule.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Rule.h
index 491d985e3a7..8891ac86334 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Rule.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Rule.h
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2011, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -107,12 +107,12 @@ public:
Slot * const & operator[](int n) const;
Slot * & operator [] (int);
void pushSlot(Slot * const slot);
- void collectGarbage();
+ void collectGarbage();
Slot * highwater() { return m_highwater; }
void highwater(Slot *s) { m_highwater = s; m_highpassed = false; }
- bool highpassed() const { return m_highpassed; }
- void highpassed(bool v) { m_highpassed = v; }
+ bool highpassed() const { return m_highpassed; }
+ void highpassed(bool v) { m_highpassed = v; }
Segment & segment;
private:
@@ -120,7 +120,7 @@ private:
unsigned short m_size;
unsigned short m_precontext;
Slot * m_highwater;
- bool m_highpassed;
+ bool m_highpassed;
};
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCache.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCache.h
index ac09966589c..ad48258d053 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCache.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCache.h
@@ -93,9 +93,7 @@ public:
if (m_entryCounts[length-1] + 1u > listSize)
{
if (m_entryCounts[length-1] == 0)
- {
listSize = 1;
- }
else
{
// the problem comes when you get incremental numeric ids in a large doc
@@ -105,9 +103,7 @@ public:
}
newEntries = gralloc<SegCacheEntry>(listSize);
if (!newEntries)
- {
return NULL;
- }
}
uint16 insertPos = 0;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheEntry.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheEntry.h
index 9a7d930677c..9a7d930677c 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheEntry.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheEntry.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheStore.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheStore.h
index 1e6a6e216e7..1e6a6e216e7 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/SegCacheStore.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/SegCacheStore.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Segment.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Segment.h
index 8ddeeb8106b..ef15e125ef2 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Segment.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Segment.h
@@ -39,6 +39,7 @@ of the License or (at your option) any later version.
#include "inc/Slot.h"
#include "inc/Position.h"
#include "inc/List.h"
+#include "inc/Bidi.h"
#define MAX_SEG_GROWTH_FACTOR 256
@@ -116,7 +117,7 @@ public:
SlotJustify *newJustify();
void freeJustify(SlotJustify *aJustify);
Position positionSlots(const Font *font, Slot *first=0, Slot *last=0);
- void associateChars();
+ void associateChars(int offset, int num);
void linkClusters(Slot *first, Slot *last);
uint16 getClassGlyph(uint16 cid, uint16 offset) const { return m_silf->getClassGlyph(cid, offset); }
uint16 findClassIndex(uint16 cid, uint16 gid) const { return m_silf->findClassIndex(cid, gid); }
@@ -144,13 +145,12 @@ public:
CLASS_NEW_DELETE
public: //only used by: GrSegment* makeAndInitialize(const GrFont *font, const GrFace *face, uint32 script, const FeaturesHandle& pFeats/*must not be IsNull*/, encform enc, const void* pStart, size_t nChars, int dir);
- void read_text(const Face *face, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void*pStart, size_t nChars);
+ bool read_text(const Face *face, const Features* pFeats/*must not be NULL*/, gr_encform enc, const void*pStart, size_t nChars);
void prepare_pos(const Font *font);
void finalise(const Font *font);
float justify(Slot *pSlot, const Font *font, float width, enum justFlags flags, Slot *pFirst, Slot *pLast);
private:
- Rect m_bbox; // ink box of the segment
Position m_advance; // whole segment advance
SlotRope m_slots; // Vector of slot buffers
AttributeRope m_userAttrs; // Vector of userAttrs buffers
@@ -176,10 +176,10 @@ private:
inline
void Segment::finalise(const Font *font)
{
- if (!m_first) return;
+ if (!m_first) return;
m_advance = positionSlots(font);
- associateChars();
+ associateChars(0, m_numCharinfo);
linkClusters(m_first, m_last);
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Silf.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Silf.h
index 526d9ba30bd..c7e9b5d6b6a 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Silf.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Silf.h
@@ -36,6 +36,7 @@ class Face;
class Segment;
class FeatureVal;
class VMScratch;
+class Error;
class Pseudo
{
@@ -73,8 +74,8 @@ public:
Silf() throw();
~Silf() throw();
- bool readGraphite(const byte * const pSilf, size_t lSilf, const Face &face, uint32 version);
- bool runGraphite(Segment *seg, uint8 firstPass=0, uint8 lastPass=0) const;
+ bool readGraphite(const byte * const pSilf, size_t lSilf, Face &face, uint32 version);
+ bool runGraphite(Segment *seg, uint8 firstPass=0, uint8 lastPass=0, int dobidi = 0) const;
uint16 findClassIndex(uint16 cid, uint16 gid) const;
uint16 getClassGlyph(uint16 cid, unsigned int index) const;
uint16 findPseudo(uint32 uid) const;
@@ -83,6 +84,7 @@ public:
uint8 aBreak() const { return m_aBreak; }
uint8 aMirror() const {return m_aMirror; }
uint8 aPassBits() const { return m_aPassBits; }
+ uint8 aBidi() const { return m_aBidi; }
uint8 substitutionPass() const { return m_sPass; }
uint8 positionPass() const { return m_pPass; }
uint8 justificationPass() const { return m_jPass; }
@@ -99,8 +101,8 @@ public:
CLASS_NEW_DELETE;
private:
- size_t readClassMap(const byte *p, size_t data_len, uint32 version);
- template<typename T> inline uint32 readClassOffsets(const byte *&p, size_t data_len);
+ size_t readClassMap(const byte *p, size_t data_len, uint32 version, Error &e);
+ template<typename T> inline uint32 readClassOffsets(const byte *&p, size_t data_len, Error &e);
Pass * m_passes;
Pseudo * m_pseudos;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Slot.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Slot.h
index 3f0c473889a..1847269d733 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/Slot.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Slot.h
@@ -60,17 +60,17 @@ public:
class Slot
{
- enum Flag
- {
- DELETED = 1,
- INSERTED = 2,
- COPIED = 4,
- POSITIONED = 8,
- ATTACHED = 16
- };
+ enum Flag
+ {
+ DELETED = 1,
+ INSERTED = 2,
+ COPIED = 4,
+ POSITIONED = 8,
+ ATTACHED = 16
+ };
public:
- struct iterator;
+ struct iterator;
unsigned short gid() const { return m_glyphid; }
Position origin() const { return m_position; }
@@ -82,7 +82,7 @@ public:
void index(uint32 val) { m_index = val; }
Slot();
- void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels);
+ void set(const Slot & slot, int charOffset, size_t numUserAttr, size_t justLevels, size_t numChars);
Slot *next() const { return m_next; }
void next(Slot *s) { m_next = s; }
Slot *prev() const { return m_prev; }
@@ -108,8 +108,8 @@ public:
bool isInsertBefore() const { return !(m_flags & INSERTED); }
uint8 getBidiLevel() const { return m_bidiLevel; }
void setBidiLevel(uint8 level) { m_bidiLevel = level; }
- uint8 getBidiClass() const { return m_bidiCls; }
- void setBidiClass(uint8 cls) { m_bidiCls = cls; }
+ int8 getBidiClass() const { return m_bidiCls; }
+ void setBidiClass(int8 cls) { m_bidiCls = cls; }
int16 *userAttrs() const { return m_userAttr; }
void userAttrs(int16 *p) { m_userAttr = p; }
void markInsertBefore(bool state) { if (!state) m_flags |= INSERTED; else m_flags &= ~INSERTED; }
@@ -140,7 +140,7 @@ private:
Slot *m_prev;
unsigned short m_glyphid; // glyph id
uint16 m_realglyphid;
- uint32 m_original; // charinfo that originated this slot (e.g. for feature values)
+ uint32 m_original; // charinfo that originated this slot (e.g. for feature values)
uint32 m_before; // charinfo index of before association
uint32 m_after; // charinfo index of after association
uint32 m_index; // slot index given to this slot during finalising
@@ -151,11 +151,11 @@ private:
Position m_shift; // .shift slot attribute
Position m_advance; // .advance slot attribute
Position m_attach; // attachment point on us
- Position m_with; // attachment point position on parent
+ Position m_with; // attachment point position on parent
float m_just; // Justification inserted space
uint8 m_flags; // holds bit flags
byte m_attLevel; // attachment level
- byte m_bidiCls; // bidirectional class
+ int8 m_bidiCls; // bidirectional class
byte m_bidiLevel; // bidirectional level
int16 *m_userAttr; // pointer to user attributes
SlotJustify *m_justs; // pointer to justification parameters
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Sparse.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Sparse.h
new file mode 100644
index 00000000000..b87ab88f3c8
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/Sparse.h
@@ -0,0 +1,170 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+#include <iterator>
+#include <utility>
+
+#include "inc/Main.h"
+
+namespace graphite2 {
+
+
+// A read-only packed fast sparse array of uint16 with uint16 keys.
+// Like most container classes this has capacity and size properties and these
+// refer to the number of stored entries and the number of addressable entries
+// as normal. However due the sparse nature the capacity is always <= than the
+// size.
+class sparse
+{
+public:
+ typedef uint16 key_type;
+ typedef uint16 mapped_type;
+ typedef std::pair<const key_type, mapped_type> value_type;
+
+private:
+ typedef unsigned long mask_t;
+
+ static const unsigned char SIZEOF_CHUNK = (sizeof(mask_t) - sizeof(key_type))*8;
+
+ struct chunk
+ {
+ mask_t mask:SIZEOF_CHUNK;
+ key_type offset;
+ };
+
+ static chunk empty_chunk;
+ sparse(const sparse &);
+ sparse & operator = (const sparse &);
+
+public:
+ template<typename I>
+ sparse(I first, const I last);
+ sparse() throw();
+ ~sparse() throw();
+
+ operator bool () const throw();
+ mapped_type operator [] (const key_type k) const throw();
+
+ size_t capacity() const throw();
+ size_t size() const throw();
+
+ size_t _sizeof() const throw();
+
+ CLASS_NEW_DELETE;
+
+private:
+ union {
+ chunk * map;
+ mapped_type * values;
+ } m_array;
+ key_type m_nchunks;
+};
+
+
+inline
+sparse::sparse() throw() : m_nchunks(0)
+{
+ m_array.map = &empty_chunk;
+}
+
+
+template <typename I>
+sparse::sparse(I attr, const I last)
+: m_nchunks(0)
+{
+ m_array.map = 0;
+
+ // Find the maximum extent of the key space.
+ size_t n_values=0;
+ long lastkey = -1;
+ for (I i = attr; i != last; ++i, ++n_values)
+ {
+ const typename std::iterator_traits<I>::value_type v = *i;
+ if (v.second == 0) { --n_values; continue; }
+ if (v.first <= lastkey) { m_nchunks = 0; return; }
+
+ lastkey = v.first;
+ const key_type k = v.first / SIZEOF_CHUNK;
+ if (k >= m_nchunks) m_nchunks = k+1;
+ }
+ if (m_nchunks == 0)
+ {
+ m_array.map=&empty_chunk;
+ return;
+ }
+
+ m_array.values = grzeroalloc<mapped_type>((m_nchunks*sizeof(chunk) + sizeof(mapped_type)-1)
+ / sizeof(mapped_type)
+ + n_values);
+
+ if (m_array.values == 0)
+ {
+ free(m_array.values); m_array.map=0;
+ return;
+ }
+
+ chunk * ci = m_array.map;
+ ci->offset = (m_nchunks*sizeof(chunk) + sizeof(mapped_type)-1)/sizeof(mapped_type);
+ mapped_type * vi = m_array.values + ci->offset;
+ for (; attr != last; ++attr, ++vi)
+ {
+ const typename std::iterator_traits<I>::value_type v = *attr;
+ if (v.second == 0) { --vi; continue; }
+
+ chunk * const ci_ = m_array.map + v.first/SIZEOF_CHUNK;
+
+ if (ci != ci_)
+ {
+ ci = ci_;
+ ci->offset = vi - m_array.values;
+ }
+
+ ci->mask |= 1UL << (SIZEOF_CHUNK - 1 - (v.first % SIZEOF_CHUNK));
+ *vi = v.second;
+ }
+}
+
+
+inline
+sparse::operator bool () const throw()
+{
+ return m_array.map != 0;
+}
+
+inline
+size_t sparse::size() const throw()
+{
+ return m_nchunks*SIZEOF_CHUNK;
+}
+
+inline
+size_t sparse::_sizeof() const throw()
+{
+ return sizeof(sparse) + capacity()*sizeof(mapped_type) + m_nchunks*sizeof(chunk);
+}
+
+} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfTypes.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfTypes.h
new file mode 100644
index 00000000000..ea20e5775fc
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfTypes.h
@@ -0,0 +1,419 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2010, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+/*--------------------------------------------------------------------*//*:Ignore this sentence.
+
+File: TtfTypes.h
+Responsibility: Tim Eves
+Last reviewed: Not yet.
+
+Description:
+Provides types required to represent the TTF basic types.
+-------------------------------------------------------------------------------*//*:End Ignore*/
+
+
+//**********************************************************************************************
+// Include files
+//**********************************************************************************************
+namespace graphite2
+{
+namespace TtfUtil
+{
+//**********************************************************************************************
+// Forward declarations
+//**********************************************************************************************
+
+
+//**********************************************************************************************
+// Type declarations
+//**********************************************************************************************
+typedef unsigned char uint8;
+typedef uint8 byte;
+typedef signed char int8;
+typedef unsigned short uint16;
+typedef short int16;
+typedef unsigned int uint32;
+typedef int int32;
+
+typedef int16 short_frac;
+typedef int32 fixed;
+typedef int16 fword;
+typedef uint16 ufword;
+typedef int16 f2dot14;
+typedef uint32 long_date_time[2];
+
+//**********************************************************************************************
+// Constants and enum types
+//**********************************************************************************************/
+enum
+{
+ OneFix = 1<<16
+};
+
+//**********************************************************************************************
+// Table declarations
+//**********************************************************************************************
+namespace Sfnt
+{
+#pragma pack(1) // We need this or the structure members aren't alligned
+ // correctly. Fortunately this form of pragma is supposed
+ // to be recongnised by VS C++ too (at least according to
+ // MSDN).
+
+ struct OffsetSubTable
+ {
+ uint32 scaler_type;
+ uint16 num_tables,
+ search_range,
+ entry_selector,
+ range_shift;
+ struct Entry
+ {
+ uint32 tag,
+ checksum,
+ offset,
+ length;
+ } table_directory[1];
+
+ enum ScalerType
+ {
+ TrueTypeMac = 0x74727565U,
+ TrueTypeWin = 0x00010000U,
+ Type1 = 0x74797031U
+ };
+ };
+
+
+
+
+ struct CharacterCodeMap
+ {
+ uint16 version,
+ num_subtables;
+ struct
+ {
+ uint16 platform_id,
+ platform_specific_id;
+ uint32 offset;
+ } encoding[1];
+ };
+
+ struct CmapSubTable
+ {
+ uint16 format,
+ length,
+ language;
+ };
+
+ struct CmapSubTableFormat4 : CmapSubTable
+ {
+ uint16 seg_count_x2,
+ search_range,
+ entry_selector,
+ range_shift,
+ end_code[1];
+ // There are arrarys after this which need their
+ // start positions calculated since end_code is
+ // seg_count uint16s long.
+ };
+
+ struct CmapSubTableFormat12
+ {
+ fixed format;
+ uint32 length,
+ language,
+ num_groups;
+ struct
+ {
+ uint32 start_char_code,
+ end_char_code,
+ start_glyph_id;
+ } group[1];
+ };
+
+
+
+ struct FontHeader
+ {
+ fixed version,
+ font_revision;
+ uint32 check_sum_adjustment,
+ magic_number;
+ uint16 flags,
+ units_per_em;
+ long_date_time created,
+ modified;
+ fword x_min,
+ y_min,
+ x_max,
+ y_max;
+ uint16 mac_style,
+ lowest_rec_ppem;
+ int16 font_direction_hint,
+ index_to_loc_format,
+ glyph_data_format;
+ enum
+ {
+ MagicNumber = 0x5F0F3CF5,
+ GlypDataFormat = 0
+ };
+ enum {ShortIndexLocFormat, LongIndexLocFormat};
+ };
+
+
+
+
+ struct PostScriptGlyphName
+ {
+ fixed format,
+ italic_angle;
+ fword underline_position,
+ underline_thickness;
+ uint32 is_fixed_pitch,
+ min_mem_type42,
+ max_mem_type42,
+ min_mem_type1,
+ max_mem_type1;
+ enum
+ {
+ Format1 = 0x10000,
+ Format2 = 0x20000,
+ Format25 = 0x28000,
+ Format3 = 0x30000,
+ Format4 = 0x40000
+ };
+ };
+
+ struct PostScriptGlyphName2 : PostScriptGlyphName
+ {
+ uint16 number_of_glyphs,
+ glyph_name_index[1];
+ };
+
+ struct PostScriptGlyphName25 : PostScriptGlyphName
+ {
+ uint16 number_of_glyphs;
+ int8 offset[1];
+ };
+
+ struct PostScriptGlyphName3 : PostScriptGlyphName {};
+
+ struct PostScriptGlyphName4 : PostScriptGlyphName
+ {
+ uint16 glyph_to_char_map[1];
+ };
+
+
+ struct HorizontalHeader
+ {
+ fixed version;
+ fword ascent,
+ descent,
+ line_gap;
+ ufword advance_width_max;
+ fword min_left_side_bearing,
+ max_left_side_bearing,
+ x_max_element;
+ int16 caret_slope_rise,
+ caret_slope_run;
+ fword caret_offset;
+ int16 reserved[4],
+ metric_data_format;
+ uint16 num_long_hor_metrics;
+ };
+
+ struct MaximumProfile
+ {
+ fixed version;
+ uint16 num_glyphs,
+ max_points,
+ max_contours,
+ max_component_points,
+ max_component_contours,
+ max_zones,
+ max_twilight_points,
+ max_storage,
+ max_function_defs,
+ max_instruction_defs,
+ max_stack_elements,
+ max_size_of_instructions,
+ max_component_elements,
+ max_component_depth;
+ };
+
+
+ typedef byte Panose[10];
+
+ struct Compatibility0
+ {
+ uint16 version;
+ int16 x_avg_char_width;
+ uint16 weight_class,
+ width_class;
+ int16 fs_type,
+ y_subscript_x_size,
+ y_subscript_y_size,
+ y_subscript_x_offset,
+ y_subscript_y_offset,
+ y_superscript_x_size,
+ y_superscript_y_size,
+ y_superscript_x_offset,
+ y_superscript_y_offset,
+ y_strikeout_size,
+ y_strikeout_position,
+ family_class;
+ Panose panose;
+ uint32 unicode_range[4];
+ int8 ach_vend_id[4];
+ uint16 fs_selection,
+ fs_first_char_index,
+ fs_last_char_index, // Acording to Apple's spec this is where v0 should end
+ typo_ascender,
+ typo_descender,
+ type_linegap,
+ win_ascent,
+ win_descent;
+
+ enum
+ {
+ Italic =0x01,
+ Underscore=0x02,
+ Negative =0x04,
+ Outlined =0x08,
+ StrikeOut =0x10,
+ Bold =0x20
+ };
+ };
+
+ struct Compatibility1 : Compatibility0
+ {
+ uint32 codepage_range[2];
+ };
+
+ struct Compatibility2 : Compatibility1
+ {
+ int16 x_height,
+ cap_height;
+ uint16 default_char,
+ break_char,
+ max_context;
+ };
+
+ struct Compatibility3 : Compatibility2 {};
+
+ typedef Compatibility3 Compatibility;
+
+
+ struct NameRecord
+ {
+ uint16 platform_id,
+ platform_specific_id,
+ language_id,
+ name_id,
+ length,
+ offset;
+ enum {Unicode, Mactintosh, Reserved, Microsoft};
+ enum
+ {
+ Copyright, Family, Subfamily, UniqueSubfamily,
+ Fullname, Version, PostScript
+ };
+ };
+
+ struct LangTagRecord
+ {
+ uint16 length,
+ offset;
+ };
+
+ struct FontNames
+ {
+ uint16 format,
+ count,
+ string_offset;
+ NameRecord name_record[1];
+ };
+
+
+ struct HorizontalMetric
+ {
+ uint16 advance_width;
+ int16 left_side_bearing;
+ };
+
+
+ struct Glyph
+ {
+ int16 number_of_contours;
+ fword x_min,
+ y_min,
+ x_max,
+ y_max;
+ };
+
+ struct SimpleGlyph : Glyph
+ {
+ uint16 end_pts_of_contours[1];
+ enum
+ {
+ OnCurve = 0x01,
+ XShort = 0x02,
+ YShort = 0x04,
+ Repeat = 0x08,
+ XIsSame = 0x10,
+ XIsPos = 0x10,
+ YIsSame = 0x20,
+ YIsPos = 0x20
+ };
+ };
+
+ struct CompoundGlyph : Glyph
+ {
+ uint16 flags,
+ glyph_index;
+ enum
+ {
+ Arg1Arg2Words = 0x01,
+ ArgsAreXYValues = 0x02,
+ RoundXYToGrid = 0x04,
+ HaveScale = 0x08,
+ MoreComponents = 0x20,
+ HaveXAndYScale = 0x40,
+ HaveTwoByTwo = 0x80,
+ HaveInstructions = 0x100,
+ UseMyMetrics = 0x200,
+ OverlapCompund = 0x400,
+ ScaledOffset = 0x800,
+ UnscaledOffset = 0x1000
+ };
+ };
+
+#pragma pack()
+} // end of namespace Sfnt
+
+} // end of namespace TtfUtil
+} // end of namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfUtil.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfUtil.h
new file mode 100644
index 00000000000..b7b7ffee6c8
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/TtfUtil.h
@@ -0,0 +1,206 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2010, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+/*--------------------------------------------------------------------*//*:Ignore this sentence.
+
+File: TtfUtil.h
+Responsibility: Alan Ward
+Last reviewed: Not yet.
+
+Description:
+ Utility class for handling TrueType font files.
+----------------------------------------------------------------------------------------------*/
+
+
+#include <cstddef>
+
+namespace graphite2
+{
+namespace TtfUtil
+{
+
+typedef long fontTableId32;
+typedef unsigned short gid16;
+
+#define TTF_TAG(a,b,c,d) ((a << 24UL) + (b << 16UL) + (c << 8UL) + (d))
+
+// Enumeration used to specify a table in a TTF file
+class Tag
+{
+ unsigned long _v;
+public:
+ Tag(const char n[5]) throw() : _v(TTF_TAG(n[0],n[1],n[2],n[3])) {}
+ Tag(const unsigned long tag) throw() : _v(tag) {}
+
+ operator unsigned long () const throw () { return _v; }
+
+ enum
+ {
+ Feat = TTF_TAG('F','e','a','t'),
+ Glat = TTF_TAG('G','l','a','t'),
+ Gloc = TTF_TAG('G','l','o','c'),
+ Sile = TTF_TAG('S','i','l','e'),
+ Silf = TTF_TAG('S','i','l','f'),
+ Sill = TTF_TAG('S','i','l','l'),
+ cmap = TTF_TAG('c','m','a','p'),
+ cvt = TTF_TAG('c','v','t',' '),
+ cryp = TTF_TAG('c','r','y','p'),
+ head = TTF_TAG('h','e','a','d'),
+ fpgm = TTF_TAG('f','p','g','m'),
+ gdir = TTF_TAG('g','d','i','r'),
+ glyf = TTF_TAG('g','l','y','f'),
+ hdmx = TTF_TAG('h','d','m','x'),
+ hhea = TTF_TAG('h','h','e','a'),
+ hmtx = TTF_TAG('h','m','t','x'),
+ loca = TTF_TAG('l','o','c','a'),
+ kern = TTF_TAG('k','e','r','n'),
+ LTSH = TTF_TAG('L','T','S','H'),
+ maxp = TTF_TAG('m','a','x','p'),
+ name = TTF_TAG('n','a','m','e'),
+ OS_2 = TTF_TAG('O','S','/','2'),
+ post = TTF_TAG('p','o','s','t'),
+ prep = TTF_TAG('p','r','e','p')
+ };
+};
+
+/*----------------------------------------------------------------------------------------------
+ Class providing utility methods to parse a TrueType font file (TTF).
+ Callling application handles all file input and memory allocation.
+ Assumes minimal knowledge of TTF file format.
+----------------------------------------------------------------------------------------------*/
+ ////////////////////////////////// tools to find & check TTF tables
+ bool GetHeaderInfo(size_t & lOffset, size_t & lSize);
+ bool CheckHeader(const void * pHdr);
+ bool GetTableDirInfo(const void * pHdr, size_t & lOffset, size_t & lSize);
+ bool GetTableInfo(const Tag TableTag, const void * pHdr, const void * pTableDir,
+ size_t & lOffset, size_t & lSize);
+ bool CheckTable(const Tag TableId, const void * pTable, size_t lTableSize);
+
+ ////////////////////////////////// simple font wide info
+ size_t GlyphCount(const void * pMaxp);
+#ifdef ALL_TTFUTILS
+ size_t MaxCompositeComponentCount(const void * pMaxp);
+ size_t MaxCompositeLevelCount(const void * pMaxp);
+ size_t LocaGlyphCount(size_t lLocaSize, const void * pHead); // throw (std::domain_error);
+#endif
+ int DesignUnits(const void * pHead);
+#ifdef ALL_TTFUTILS
+ int HeadTableCheckSum(const void * pHead);
+ void HeadTableCreateTime(const void * pHead, unsigned int * pnDateBC, unsigned int * pnDateAD);
+ void HeadTableModifyTime(const void * pHead, unsigned int * pnDateBC, unsigned int * pnDateAD);
+ bool IsItalic(const void * pHead);
+ int FontAscent(const void * pOs2);
+ int FontDescent(const void * pOs2);
+ bool FontOs2Style(const void *pOs2, bool & fBold, bool & fItalic);
+ bool Get31EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize);
+ bool Get31EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize);
+ bool Get30EngFamilyInfo(const void * pName, size_t & lOffset, size_t & lSize);
+ bool Get30EngFullFontInfo(const void * pName, size_t & lOffset, size_t & lSize);
+ int PostLookup(const void * pPost, size_t lPostSize, const void * pMaxp,
+ const char * pPostName);
+#endif
+
+ ////////////////////////////////// utility methods helpful for name table
+ bool GetNameInfo(const void * pName, int nPlatformId, int nEncodingId,
+ int nLangId, int nNameId, size_t & lOffset, size_t & lSize);
+ //size_t NameTableLength(const byte * pTable);
+#ifdef ALL_TTFUTILS
+ int GetLangsForNames(const void * pName, int nPlatformId, int nEncodingId,
+ int *nameIdList, int cNameIds, short *langIdList);
+ void SwapWString(void * pWStr, size_t nSize = 0); // throw (std::invalid_argument);
+#endif
+
+ ////////////////////////////////// cmap lookup tools
+ const void * FindCmapSubtable(const void * pCmap, int nPlatformId = 3,
+ int nEncodingId = 1, size_t length = 0);
+ bool CheckCmapSubtable4(const void * pCmap31);
+ gid16 CmapSubtable4Lookup(const void * pCmapSubtabel4, unsigned int nUnicodeId, int rangeKey = 0);
+ unsigned int CmapSubtable4NextCodepoint(const void *pCmap31, unsigned int nUnicodeId,
+ int * pRangeKey = 0);
+ bool CheckCmapSubtable12(const void *pCmap310);
+ gid16 CmapSubtable12Lookup(const void * pCmap310, unsigned int uUnicodeId, int rangeKey = 0);
+ unsigned int CmapSubtable12NextCodepoint(const void *pCmap310, unsigned int nUnicodeId,
+ int * pRangeKey = 0);
+
+ ///////////////////////////////// horizontal metric data for a glyph
+ bool HorMetrics(gid16 nGlyphId, const void * pHmtx, size_t lHmtxSize,
+ const void * pHhea, int & nLsb, unsigned int & nAdvWid);
+
+ ////////////////////////////////// primitives for loca and glyf lookup
+ size_t LocaLookup(gid16 nGlyphId, const void * pLoca, size_t lLocaSize,
+ const void * pHead); // throw (std::out_of_range);
+ void * GlyfLookup(const void * pGlyf, size_t lGlyfOffset, size_t lTableLen);
+
+ ////////////////////////////////// primitves for simple glyph data
+ bool GlyfBox(const void * pSimpleGlyf, int & xMin, int & yMin,
+ int & xMax, int & yMax);
+
+#ifdef ALL_TTFUTILS
+ int GlyfContourCount(const void * pSimpleGlyf);
+ bool GlyfContourEndPoints(const void * pSimpleGlyf, int * prgnContourEndPoint,
+ int cnPointsTotal, size_t & cnPoints);
+ bool GlyfPoints(const void * pSimpleGlyf, int * prgnX, int * prgnY,
+ char * prgbFlag, int cnPointsTotal, int & cnPoints);
+
+ // primitive to find the glyph ids in a composite glyph
+ bool GetComponentGlyphIds(const void * pSimpleGlyf, int * prgnCompId,
+ size_t cnCompIdTotal, size_t & cnCompId);
+ // primitive to find the placement data for a component in a composite glyph
+ bool GetComponentPlacement(const void * pSimpleGlyf, int nCompId,
+ bool fOffset, int & a, int & b);
+ // primitive to find the transform data for a component in a composite glyph
+ bool GetComponentTransform(const void * pSimpleGlyf, int nCompId,
+ float & flt11, float & flt12, float & flt21, float & flt22, bool & fTransOffset);
+#endif
+
+ ////////////////////////////////// operate on composite or simple glyph (auto glyf lookup)
+ void * GlyfLookup(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead); // primitive used by below methods
+
+#ifdef ALL_TTFUTILS
+ // below are primary user methods for handling glyf data
+ bool IsSpace(gid16 nGlyphId, const void * pLoca, size_t lLocaSize, const void * pHead);
+ bool IsDeepComposite(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead);
+
+ bool GlyfBox(gid16 nGlyphId, const void * pGlyf, const void * pLoca, size_t lGlyfSize, size_t lLocaSize,
+ const void * pHead, int & xMin, int & yMin, int & xMax, int & yMax);
+ bool GlyfContourCount(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void *pHead, size_t & cnContours);
+ bool GlyfContourEndPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead, int * prgnContourEndPoint, size_t cnPoints);
+ bool GlyfPoints(gid16 nGlyphId, const void * pGlyf, const void * pLoca,
+ size_t lGlyfSize, size_t lLocaSize, const void * pHead, const int * prgnContourEndPoint, size_t cnEndPoints,
+ int * prgnX, int * prgnY, bool * prgfOnCurve, size_t cnPoints);
+
+ // utitily method used by high-level GlyfPoints
+ bool SimplifyFlags(char * prgbFlags, int cnPoints);
+ bool CalcAbsolutePoints(int * prgnX, int * prgnY, int cnPoints);
+#endif
+
+} // end of namespace TtfUtil
+} // end of namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/UtfCodec.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/UtfCodec.h
new file mode 100644
index 00000000000..c60ba41e72e
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/UtfCodec.h
@@ -0,0 +1,207 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+#pragma once
+
+#include <cstdlib>
+#include "inc/Main.h"
+
+namespace graphite2 {
+
+typedef uint32 uchar_t;
+
+template <int N>
+struct _utf_codec
+{
+ typedef uchar_t codeunit_t;
+
+ static void put(codeunit_t * cp, const uchar_t , int8 & len) throw();
+ static uchar_t get(const codeunit_t * cp, int8 & len) throw();
+};
+
+
+template <>
+struct _utf_codec<32>
+{
+private:
+ static const uchar_t limit = 0x110000;
+public:
+ typedef uint32 codeunit_t;
+
+ inline
+ static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
+ {
+ *cp = usv; l = 1;
+ }
+
+ inline
+ static uchar_t get(const codeunit_t * cp, int8 & l) throw()
+ {
+ if (cp[0] < limit) { l = 1; return cp[0]; }
+ else { l = -1; return 0xFFFD; }
+ }
+};
+
+
+template <>
+struct _utf_codec<16>
+{
+private:
+ static const int32 lead_offset = 0xD800 - (0x10000 >> 10);
+ static const int32 surrogate_offset = 0x10000 - (0xD800 << 10) - 0xDC00;
+public:
+ typedef uint16 codeunit_t;
+
+ inline
+ static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
+ {
+ if (usv < 0x10000) { l = 1; cp[0] = codeunit_t(usv); }
+ else
+ {
+ cp[0] = codeunit_t(lead_offset + (usv >> 10));
+ cp[1] = codeunit_t(0xDC00 + (usv & 0x3FF));
+ l = 2;
+ }
+ }
+
+ inline
+ static uchar_t get(const codeunit_t * cp, int8 & l) throw()
+ {
+ const uint32 uh = cp[0];
+ l = 1;
+
+ if (0xD800 > uh || uh > 0xDFFF) { return uh; }
+ const uint32 ul = cp[1];
+ if (uh > 0xDBFF || 0xDC00 > ul || ul > 0xDFFF) { l = -1; return 0xFFFD; }
+ ++l;
+ return (uh<<10) + ul + surrogate_offset;
+ }
+};
+
+
+template <>
+struct _utf_codec<8>
+{
+private:
+ static const int8 sz_lut[16];
+ static const byte mask_lut[5];
+
+
+public:
+ typedef uint8 codeunit_t;
+
+ inline
+ static void put(codeunit_t * cp, const uchar_t usv, int8 & l) throw()
+ {
+ if (usv < 0x80) {l = 1; cp[0] = usv; return; }
+ if (usv < 0x0800) {l = 2; cp[0] = 0xC0 + (usv >> 6); cp[1] = 0x80 + (usv & 0x3F); return; }
+ if (usv < 0x10000) {l = 3; cp[0] = 0xE0 + (usv >> 12); cp[1] = 0x80 + ((usv >> 6) & 0x3F); cp[2] = 0x80 + (usv & 0x3F); return; }
+ else {l = 4; cp[0] = 0xF0 + (usv >> 18); cp[1] = 0x80 + ((usv >> 12) & 0x3F); cp[2] = 0x80 + ((usv >> 6) & 0x3F); cp[3] = 0x80 + (usv & 0x3F); return; }
+ }
+
+ inline
+ static uchar_t get(const codeunit_t * cp, int8 & l) throw()
+ {
+ const int8 seq_sz = sz_lut[*cp >> 4];
+ uchar_t u = *cp & mask_lut[seq_sz];
+ l = 1;
+ bool toolong = false;
+
+ switch(seq_sz) {
+ case 4: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong = (u < 0x10); // no break
+ case 3: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong |= (u < 0x20); // no break
+ case 2: u <<= 6; u |= *++cp & 0x3F; if (*cp >> 6 != 2) break; ++l; toolong |= (u < 0x80); // no break
+ case 1: break;
+ case 0: l = -1; return 0xFFFD;
+ }
+
+ if (l != seq_sz || toolong)
+ {
+ l = -l;
+ return 0xFFFD;
+ }
+ return u;
+ }
+};
+
+
+template <typename C>
+class _utf_iterator
+{
+ typedef _utf_codec<sizeof(C)*8> codec;
+
+ C * cp;
+ mutable int8 sl;
+
+public:
+ typedef C codeunit_type;
+ typedef uchar_t value_type;
+ typedef uchar_t * pointer;
+
+ class reference
+ {
+ const _utf_iterator & _i;
+
+ reference(const _utf_iterator & i): _i(i) {}
+ public:
+ operator value_type () const throw () { return codec::get(_i.cp, _i.sl); }
+ reference & operator = (const value_type usv) throw() { codec::put(_i.cp, usv, _i.sl); return *this; }
+
+ friend class _utf_iterator;
+ };
+
+
+ _utf_iterator(const void * us=0) : cp(reinterpret_cast<C *>(const_cast<void *>(us))), sl(1) { }
+
+ _utf_iterator & operator ++ () { cp += abs(sl); return *this; }
+ _utf_iterator operator ++ (int) { _utf_iterator tmp(*this); operator++(); return tmp; }
+
+ bool operator == (const _utf_iterator & rhs) const throw() { return cp >= rhs.cp; }
+ bool operator != (const _utf_iterator & rhs) const throw() { return !operator==(rhs); }
+
+ reference operator * () const throw() { return *this; }
+ pointer operator ->() const throw() { return &operator *(); }
+
+ operator codeunit_type * () const throw() { return cp; }
+
+ bool error() const throw() { return sl < 1; }
+};
+
+template <typename C>
+struct utf
+{
+ typedef typename _utf_codec<sizeof(C)*8>::codeunit_t codeunit_t;
+
+ typedef _utf_iterator<C> iterator;
+ typedef _utf_iterator<const C> const_iterator;
+};
+
+
+typedef utf<uint32> utf32;
+typedef utf<uint16> utf16;
+typedef utf<uint8> utf8;
+
+} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/bits.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/bits.h
index 56b2d10224e..908049f7285 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/bits.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/bits.h
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2012, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -32,40 +32,40 @@ namespace graphite2
template<typename T>
inline unsigned int bit_set_count(T v)
{
- v = v - ((v >> 1) & T(~T(0)/3)); // temp
- v = (v & T(~T(0)/15*3)) + ((v >> 2) & T(~T(0)/15*3)); // temp
- v = (v + (v >> 4)) & T(~T(0)/255*15); // temp
- return (T)(v * T(~T(0)/255)) >> (sizeof(T)-1)*8; // count
+ v = v - ((v >> 1) & T(~T(0)/3)); // temp
+ v = (v & T(~T(0)/15*3)) + ((v >> 2) & T(~T(0)/15*3)); // temp
+ v = (v + (v >> 4)) & T(~T(0)/255*15); // temp
+ return (T)(v * T(~T(0)/255)) >> (sizeof(T)-1)*8; // count
}
template<int S>
inline unsigned long _mask_over_val(unsigned long v)
{
- v = _mask_over_val<S/2>(v);
- v |= v >> S*4;
- return v;
+ v = _mask_over_val<S/2>(v);
+ v |= v >> S*4;
+ return v;
}
template<>
inline unsigned long _mask_over_val<1>(unsigned long v)
{
- v |= v >> 1;
- v |= v >> 2;
- v |= v >> 4;
- return v;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ return v;
}
template<typename T>
inline T mask_over_val(T v)
{
- return _mask_over_val<sizeof(T)>(v);
+ return _mask_over_val<sizeof(T)>(v);
}
template<typename T>
inline unsigned long next_highest_power2(T v)
{
- return _mask_over_val<sizeof(T)>(v-1)+1;
+ return _mask_over_val<sizeof(T)>(v-1)+1;
}
template<typename T>
@@ -77,14 +77,14 @@ inline unsigned int log_binary(T v)
template<typename T>
inline T has_zero(const T x)
{
- return (x - T(~T(0)/255)) & ~x & T(~T(0)/255*128);
+ return (x - T(~T(0)/255)) & ~x & T(~T(0)/255*128);
}
template<typename T>
inline T zero_bytes(const T x, unsigned char n)
{
- const T t = T(~T(0)/255*n);
- return T((has_zero(x^t) >> 7)*n);
+ const T t = T(~T(0)/255*n);
+ return T((has_zero(x^t) >> 7)*n);
}
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/debug.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/debug.h
index ba77cb19151..a4438c9269d 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/debug.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/debug.h
@@ -1,6 +1,6 @@
/* GRAPHITE2 LICENSING
- Copyright 2010, SIL International
+ Copyright 2011, SIL International
All rights reserved.
This library is free software; you can redistribute it and/or modify
@@ -24,7 +24,7 @@ Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
License, as published by the Free Software Foundation, either version 2
of the License or (at your option) any later version.
*/
-// debug.h
+// debug.h
//
// Created on: 22 Dec 2011
// Author: tim
@@ -44,12 +44,12 @@ class CharInfo;
class Segment;
class Slot;
-typedef std::pair<const Segment * const, const Slot * const> dslot;
+typedef std::pair<const Segment * const, const Slot * const> dslot;
struct objectid
{
- char name[16];
- objectid(const dslot &) throw();
- objectid(const Segment * const p) throw();
+ char name[16];
+ objectid(const dslot &) throw();
+ objectid(const Segment * const p) throw();
};
@@ -64,14 +64,14 @@ json & operator << (json & j, const telemetry &) throw();
inline
json & operator << (json & j, const Position & p) throw()
{
- return j << json::flat << json::array << p.x << p.y << json::close;
+ return j << json::flat << json::array << p.x << p.y << json::close;
}
inline
json & operator << (json & j, const objectid & sid) throw()
{
- return j << sid.name;
+ return j << sid.name;
}
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/json.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/json.h
new file mode 100644
index 00000000000..1310411270d
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/json.h
@@ -0,0 +1,165 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+// JSON pretty printer for graphite font debug output logging.
+// Created on: 15 Dec 2011
+// Author: Tim Eves
+
+#pragma once
+#include "inc/Main.h"
+#include <cassert>
+#include <cstdio>
+
+namespace graphite2 {
+
+class json
+{
+ // Prevent copying
+ json(const json &);
+ json & operator = (const json &);
+
+ typedef void (*_context_t)(json &);
+ class _null_t {};
+
+ FILE * const _stream;
+ char _contexts[128], // context stack
+ * _context, // current context (top of stack)
+ * _flatten; // if !0 points to context above which
+ // pretty printed output should occur.
+
+ void context(const char current) throw();
+ void indent(const int d=0) throw();
+ void push_context(const char, const char) throw();
+ void pop_context() throw();
+
+public:
+ class closer;
+
+ typedef const char * string;
+ typedef double number;
+ typedef long signed int integer;
+ typedef bool boolean;
+ static const _null_t null;
+
+ static void flat(json &) throw();
+ static void close(json &) throw();
+ static void object(json &) throw();
+ static void array(json &) throw();
+ static void item(json &) throw();
+
+ json(FILE * stream) throw();
+ ~json() throw ();
+
+ FILE * stream() const throw();
+
+ json & operator << (string) throw();
+ json & operator << (number) throw();
+ json & operator << (integer) throw();
+ json & operator << (long unsigned int d) throw();
+ json & operator << (boolean) throw();
+ json & operator << (_null_t) throw();
+ json & operator << (_context_t) throw();
+
+ operator bool() const throw();
+ bool good() const throw();
+ bool eof() const throw();
+
+ CLASS_NEW_DELETE;
+};
+
+class json::closer
+{
+ // Prevent copying.
+ closer(const closer &);
+ closer & operator = (const closer &);
+
+ json * const _j;
+public:
+ closer(json * const j) : _j(j) {}
+ ~closer() throw() { if (_j) *_j << close; }
+};
+
+inline
+json::json(FILE * s) throw()
+: _stream(s), _context(_contexts), _flatten(0)
+{
+ if (good())
+ fflush(s);
+}
+
+
+inline
+json::~json() throw ()
+{
+ while (_context > _contexts) pop_context();
+}
+
+inline
+FILE * json::stream() const throw() { return _stream; }
+
+
+inline
+json & json::operator << (json::_context_t ctxt) throw()
+{
+ ctxt(*this);
+ return *this;
+}
+
+inline
+json & operator << (json & j, signed char d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, short signed int d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, signed int d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, unsigned char d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, short unsigned int d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, unsigned int d) throw() { return j << json::integer(d); }
+
+inline
+json & operator << (json & j, char c) throw ()
+{
+ const char str[2] = {c,0};
+ return j << str;
+}
+
+inline
+json::operator bool() const throw() { return good(); }
+
+inline
+bool json::good() const throw() { return _stream && ferror(_stream) == 0; }
+
+inline
+bool json::eof() const throw() { return feof(_stream) != 0; }
+
+} // namespace graphite2
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/locale2lcid.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/locale2lcid.h
index fc2d384b444..bc3e3d83047 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/locale2lcid.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/locale2lcid.h
@@ -273,6 +273,11 @@ public:
while (old[len]) len++;
len += 2;
mLangLookup[a][b] = gralloc<const IsoLangEntry *>(len);
+ if (!mLangLookup[a][b])
+ {
+ mLangLookup[a][b] = old;
+ continue;
+ }
mLangLookup[a][b][--len] = NULL;
mLangLookup[a][b][--len] = &LANG_ENTRIES[i];
while (--len >= 0)
@@ -285,6 +290,7 @@ public:
else
{
mLangLookup[a][b] = gralloc<const IsoLangEntry *>(2);
+ if (!mLangLookup[a][b]) continue;
mLangLookup[a][b][1] = NULL;
mLangLookup[a][b][0] = &LANG_ENTRIES[i];
}
@@ -295,8 +301,8 @@ public:
~Locale2Lang()
{
for (int i = 0; i != 26; ++i)
- for (int j = 0; j != 26; ++j)
- free(mLangLookup[i][j]);
+ for (int j = 0; j != 26; ++j)
+ free(mLangLookup[i][j]);
}
unsigned short getMsId(const char * locale) const
{
@@ -393,7 +399,7 @@ public:
++i;
continue;
}
- if (strcmp(mLangLookup[a][b][i]->maCountry, region) == 0)
+ if (region && (strncmp(mLangLookup[a][b][i]->maCountry, region, regionLength) == 0))
{
langId = mLangLookup[a][b][i]->mnLang;
break;
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcode_table.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcode_table.h
index 06916f6c875..06916f6c875 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcode_table.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcode_table.h
diff --git a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcodes.h b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcodes.h
index 835e89351ff..9ad35bfd373 100644
--- a/Build/source/libs/graphite2/graphite2-1.2.3/src/inc/opcodes.h
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/inc/opcodes.h
@@ -199,9 +199,9 @@ STARTOP(next)
if (map - &smap[0] >= int(smap.size())) DIE
if (is)
{
- if (is == smap.highwater())
- smap.highpassed(true);
- is = is->next();
+ if (is == smap.highwater())
+ smap.highpassed(true);
+ is = is->next();
}
++map;
ENDOP
@@ -263,6 +263,7 @@ ENDOP
STARTOP(insert)
Slot *newSlot = seg.newSlot();
+ if (!newSlot) DIE;
Slot *iss = is;
while (iss && iss->isDeleted()) iss = iss->next();
if (!iss)
@@ -284,7 +285,7 @@ STARTOP(insert)
{
iss->prev()->next(newSlot);
newSlot->prev(iss->prev());
- newSlot->before(iss->prev()->after());
+ newSlot->before(iss->prev()->after());
}
else
{
@@ -297,12 +298,12 @@ STARTOP(insert)
{
iss->prev(newSlot);
newSlot->originate(iss->original());
- newSlot->after(iss->before());
+ newSlot->after(iss->before());
}
else if (newSlot->prev())
{
newSlot->originate(newSlot->prev()->original());
- newSlot->after(newSlot->prev()->after());
+ newSlot->after(newSlot->prev()->after());
}
else
{
@@ -328,7 +329,7 @@ STARTOP(delete_)
seg.last(is->prev());
if (is == smap.highwater())
- smap.highwater(is->next());
+ smap.highwater(is->next());
if (is->prev())
is = is->prev();
seg.extendLength(-1);
@@ -373,14 +374,14 @@ ENDOP
STARTOP(attr_set)
declare_params(1);
- const attrCode slat = attrCode(uint8(*param));
+ const attrCode slat = attrCode(uint8(*param));
const int val = int(pop());
is->setAttr(&seg, slat, 0, val, smap);
ENDOP
STARTOP(attr_add)
declare_params(1);
- const attrCode slat = attrCode(uint8(*param));
+ const attrCode slat = attrCode(uint8(*param));
const int val = int(pop());
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
{
@@ -393,7 +394,7 @@ ENDOP
STARTOP(attr_sub)
declare_params(1);
- const attrCode slat = attrCode(uint8(*param));
+ const attrCode slat = attrCode(uint8(*param));
const int val = int(pop());
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
{
@@ -406,7 +407,7 @@ ENDOP
STARTOP(attr_set_slot)
declare_params(1);
- const attrCode slat = attrCode(uint8(*param));
+ const attrCode slat = attrCode(uint8(*param));
const int offset = (map - smap.begin())*int(slat == gr_slatAttTo);
const int val = int(pop()) + offset;
is->setAttr(&seg, slat, offset, val, smap);
@@ -414,7 +415,7 @@ ENDOP
STARTOP(iattr_set_slot)
declare_params(2);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const size_t idx = uint8(param[1]);
const int val = int(pop()) + (map - smap.begin())*int(slat == gr_slatAttTo);
is->setAttr(&seg, slat, idx, val, smap);
@@ -422,7 +423,7 @@ ENDOP
STARTOP(push_slot_attr)
declare_params(2);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const int slot_ref = int8(param[1]);
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
{
@@ -497,7 +498,7 @@ ENDOP
STARTOP(push_islot_attr)
declare_params(3);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const int slot_ref = int8(param[1]),
idx = uint8(param[2]);
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
@@ -534,7 +535,7 @@ ENDOP
STARTOP(iattr_set)
declare_params(2);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const size_t idx = uint8(param[1]);
const int val = int(pop());
is->setAttr(&seg, slat, idx, val, smap);
@@ -542,7 +543,7 @@ ENDOP
STARTOP(iattr_add)
declare_params(2);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const size_t idx = uint8(param[1]);
const int val = int(pop());
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
@@ -556,7 +557,7 @@ ENDOP
STARTOP(iattr_sub)
declare_params(2);
- const attrCode slat = attrCode(uint8(param[0]));
+ const attrCode slat = attrCode(uint8(param[0]));
const size_t idx = uint8(param[1]);
const int val = int(pop());
if ((slat == gr_slatPosX || slat == gr_slatPosY) && (flags & POSITIONED) == 0)
@@ -635,6 +636,7 @@ ENDOP
STARTOP(temp_copy)
slotref newSlot = seg.newSlot();
+ if (!newSlot) DIE;
int16 *tempUserAttrs = newSlot->userAttrs();
memcpy(newSlot, is, sizeof(Slot));
memcpy(tempUserAttrs, is->userAttrs(), seg.numAttrs() * sizeof(uint16));
diff --git a/Build/source/libs/graphite2/graphite2-1.2.4/src/json.cpp b/Build/source/libs/graphite2/graphite2-1.2.4/src/json.cpp
new file mode 100644
index 00000000000..2f45cc005a0
--- /dev/null
+++ b/Build/source/libs/graphite2/graphite2-1.2.4/src/json.cpp
@@ -0,0 +1,126 @@
+/* GRAPHITE2 LICENSING
+
+ Copyright 2011, SIL International
+ All rights reserved.
+
+ This library is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should also have received a copy of the GNU Lesser General Public
+ License along with this library in the file named "LICENSE".
+ If not, write to the Free Software Foundation, 51 Franklin Street,
+ Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
+ internet at http://www.fsf.org/licenses/lgpl.html.
+
+Alternatively, the contents of this file may be used under the terms of the
+Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
+License, as published by the Free Software Foundation, either version 2
+of the License or (at your option) any later version.
+*/
+// JSON debug logging
+// Author: Tim Eves
+
+#if !defined GRAPHITE2_NTRACING
+
+#include <cstdio>
+#include "inc/json.h"
+
+using namespace graphite2;
+
+namespace
+{
+ enum
+ {
+ seq = ',',
+ obj='}', member=':', empty_obj='{',
+ arr=']', empty_arr='['
+ };
+}
+
+const json::_null_t json::null = {};
+
+inline
+void json::context(const char current) throw()
+{
+ fprintf(_stream, "%c", *_context);
+ indent();
+ *_context = current;
+}
+
+
+void json::indent(const int d) throw()
+{
+ if (*_context == member || (_flatten && _flatten < _context))
+ fputc(' ', _stream);
+ else
+ fprintf(_stream, "\n%*s", 4*int(_context - _contexts + d), "");
+}
+
+
+inline
+void json::push_context(const char prefix, const char suffix) throw()
+{
+ assert(_context - _contexts < ptrdiff_t(sizeof _contexts));
+
+ if (_context == _contexts)
+ *_context = suffix;
+ else
+ context(suffix);
+ *++_context = prefix;
+}
+
+
+void json::pop_context() throw()
+{
+ assert(_context > _contexts);
+
+ if (*_context == seq) indent(-1);
+ else fputc(*_context, _stream);
+
+ fputc(*--_context, _stream);
+ if (_context == _contexts) fputc('\n', _stream);
+ fflush(_stream);
+
+ if (_flatten >= _context) _flatten = 0;
+ *_context = seq;
+}
+
+
+// These four functions cannot be inlined as pointers to these
+// functions are needed for operator << (_context_t) to work.
+void json::flat(json & j) throw() { if (!j._flatten) j._flatten = j._context; }
+void json::close(json & j) throw() { j.pop_context(); }
+void json::object(json & j) throw() { j.push_context('{', '}'); }
+void json::array(json & j) throw() { j.push_context('[', ']'); }
+void json::item(json & j) throw()
+{
+ while (j._context > j._contexts+1 && j._context[-1] != arr)
+ j.pop_context();
+}
+
+
+json & json::operator << (json::string s) throw()
+{
+ const char ctxt = _context[-1] == obj ? *_context == member ? seq : member : seq;
+ context(ctxt);
+ fprintf(_stream, "\"%s\"", s);
+ if (ctxt == member) fputc(' ', _stream);
+
+ return *this;
+}
+
+json & json::operator << (json::number f) throw() { context(seq); fprintf(_stream, "%g", f); return *this; }
+json & json::operator << (json::integer d) throw() { context(seq); fprintf(_stream, "%ld", d); return *this; }
+json & json::operator << (long unsigned d) throw() { context(seq); fprintf(_stream, "%ld", d); return *this; }
+json & json::operator << (json::boolean b) throw() { context(seq); fputs(b ? "true" : "false", _stream); return *this; }
+json & json::operator << (json::_null_t) throw() { context(seq); fputs("null",_stream); return *this; }
+
+#endif
+
diff --git a/Build/source/libs/graphite2/version.ac b/Build/source/libs/graphite2/version.ac
index 7b82c6e2011..5962e99fc3f 100644
--- a/Build/source/libs/graphite2/version.ac
+++ b/Build/source/libs/graphite2/version.ac
@@ -8,4 +8,4 @@ dnl
dnl --------------------------------------------------------
dnl
dnl m4-include this file to define the current graphite2 version
-m4_define([graphite2_version], [1.2.3])
+m4_define([graphite2_version], [1.2.4])