aboutsummaryrefslogtreecommitdiff
path: root/freetype/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-06-26 09:53:21 +0200
committermarha <marha@users.sourceforge.net>2014-06-26 09:53:21 +0200
commit90137f4c5e30b1c6f9a262e8c853494540dad2d7 (patch)
tree7da9d06a291a853f0d17b2ee49a2d31d86a5d757 /freetype/src
parentd47db8d4713de42ccca071c9e8401fc7a213ed49 (diff)
parentfba3b6d1979c1d1ad0d56d46fc2d787f111c07fb (diff)
downloadvcxsrv-90137f4c5e30b1c6f9a262e8c853494540dad2d7.tar.gz
vcxsrv-90137f4c5e30b1c6f9a262e8c853494540dad2d7.tar.bz2
vcxsrv-90137f4c5e30b1c6f9a262e8c853494540dad2d7.zip
Merge remote-tracking branch 'origin/released'
* origin/released: Updated to freetype 2.5.3
Diffstat (limited to 'freetype/src')
-rw-r--r--freetype/src/Jamfile4
-rw-r--r--freetype/src/autofit/afblue.c166
-rw-r--r--freetype/src/autofit/afblue.cin39
-rw-r--r--freetype/src/autofit/afblue.dat218
-rw-r--r--freetype/src/autofit/afblue.h199
-rw-r--r--freetype/src/autofit/afblue.hin142
-rw-r--r--freetype/src/autofit/afcjk.c691
-rw-r--r--freetype/src/autofit/afcjk.h62
-rw-r--r--freetype/src/autofit/afcover.h105
-rw-r--r--freetype/src/autofit/afdummy.c43
-rw-r--r--freetype/src/autofit/afdummy.h8
-rw-r--r--freetype/src/autofit/afglobal.c355
-rw-r--r--freetype/src/autofit/afglobal.h77
-rw-r--r--freetype/src/autofit/afhints.c312
-rw-r--r--freetype/src/autofit/afhints.h87
-rw-r--r--freetype/src/autofit/afindic.c59
-rw-r--r--freetype/src/autofit/afindic.h9
-rw-r--r--freetype/src/autofit/aflatin.c523
-rw-r--r--freetype/src/autofit/aflatin.h49
-rw-r--r--freetype/src/autofit/aflatin2.c39
-rw-r--r--freetype/src/autofit/aflatin2.h10
-rw-r--r--freetype/src/autofit/afloader.c56
-rw-r--r--freetype/src/autofit/afloader.h4
-rw-r--r--freetype/src/autofit/afmodule.c71
-rw-r--r--freetype/src/autofit/afmodule.h5
-rw-r--r--freetype/src/autofit/afpic.c67
-rw-r--r--freetype/src/autofit/afpic.h45
-rw-r--r--freetype/src/autofit/afranges.c208
-rw-r--r--freetype/src/autofit/afranges.h41
-rw-r--r--freetype/src/autofit/afscript.h138
-rw-r--r--freetype/src/autofit/afstyles.h150
-rw-r--r--freetype/src/autofit/aftypes.h463
-rw-r--r--freetype/src/autofit/afwrtsys.h52
-rw-r--r--freetype/src/autofit/autofit.c7
-rw-r--r--freetype/src/autofit/hbshim.c531
-rw-r--r--freetype/src/autofit/hbshim.h56
-rw-r--r--freetype/src/autofit/rules.mk13
-rw-r--r--freetype/src/base/basepic.c13
-rw-r--r--freetype/src/base/ftbbox.c334
-rw-r--r--freetype/src/base/ftbitmap.c8
-rw-r--r--freetype/src/base/ftcalc.c34
-rw-r--r--freetype/src/base/ftdebug.c2
-rw-r--r--freetype/src/base/ftglyph.c62
-rw-r--r--freetype/src/base/ftinit.c4
-rw-r--r--freetype/src/base/ftmac.c1
-rw-r--r--freetype/src/base/ftobjs.c62
-rw-r--r--freetype/src/base/ftoutln.c11
-rw-r--r--freetype/src/base/ftpic.c5
-rw-r--r--freetype/src/base/ftrfork.c26
-rw-r--r--freetype/src/base/ftsynth.c11
-rw-r--r--freetype/src/base/md5.c51
-rw-r--r--freetype/src/base/md5.h2
-rw-r--r--freetype/src/base/rules.mk13
-rw-r--r--freetype/src/bdf/bdfdrivr.c27
-rw-r--r--freetype/src/bdf/bdflib.c58
-rw-r--r--freetype/src/cache/Jamfile4
-rw-r--r--freetype/src/cff/cf2blues.c13
-rw-r--r--freetype/src/cff/cf2font.c182
-rw-r--r--freetype/src/cff/cf2font.h2
-rw-r--r--freetype/src/cff/cf2ft.c48
-rw-r--r--freetype/src/cff/cf2hints.c200
-rw-r--r--freetype/src/cff/cf2hints.h4
-rw-r--r--freetype/src/cff/cffdrivr.c61
-rw-r--r--freetype/src/cff/cffgload.c6
-rw-r--r--freetype/src/cff/cffload.c25
-rw-r--r--freetype/src/cff/cffobjs.c13
-rw-r--r--freetype/src/cff/cffobjs.h2
-rw-r--r--freetype/src/cff/cffparse.c6
-rw-r--r--freetype/src/cid/cidgload.c2
-rw-r--r--freetype/src/cid/cidload.c25
-rw-r--r--freetype/src/cid/cidobjs.c7
-rw-r--r--freetype/src/cid/cidparse.c4
-rw-r--r--freetype/src/cid/cidparse.h22
-rw-r--r--freetype/src/gxvalid/gxvcommn.c8
-rw-r--r--freetype/src/gxvalid/gxvmort.c2
-rw-r--r--freetype/src/gxvalid/gxvmorx2.c4
-rw-r--r--freetype/src/gzip/ftgzip.c78
-rw-r--r--freetype/src/gzip/rules.mk57
-rw-r--r--freetype/src/pcf/pcfdrivr.c42
-rw-r--r--freetype/src/pcf/pcfread.c9
-rw-r--r--freetype/src/pcf/pcfutil.c12
-rw-r--r--freetype/src/pfr/pfrcmap.c10
-rw-r--r--freetype/src/pfr/pfrload.c3
-rw-r--r--freetype/src/pfr/pfrobjs.c5
-rw-r--r--freetype/src/psaux/psobjs.c8
-rw-r--r--freetype/src/pshinter/pshalgo.c5
-rw-r--r--freetype/src/pshinter/pshglob.c4
-rw-r--r--freetype/src/psnames/rules.mk4
-rw-r--r--freetype/src/raster/ftraster.c8
-rw-r--r--freetype/src/sfnt/pngshim.c57
-rw-r--r--freetype/src/sfnt/pngshim.h5
-rw-r--r--freetype/src/sfnt/sfdriver.c8
-rw-r--r--freetype/src/sfnt/sfobjs.c421
-rw-r--r--freetype/src/sfnt/ttcmap.c74
-rw-r--r--freetype/src/sfnt/ttkern.c6
-rw-r--r--freetype/src/sfnt/ttload.c52
-rw-r--r--freetype/src/sfnt/ttmtx.c19
-rw-r--r--freetype/src/sfnt/ttsbit.c607
-rw-r--r--freetype/src/sfnt/ttsbit.h4
-rw-r--r--freetype/src/smooth/ftgrays.c90
-rw-r--r--freetype/src/tools/afblue.pl545
-rw-r--r--freetype/src/tools/chktrcmp.py4
-rw-r--r--freetype/src/tools/docmaker/content.py19
-rw-r--r--freetype/src/tools/docmaker/docmaker.py4
-rw-r--r--freetype/src/tools/docmaker/sources.py40
-rw-r--r--freetype/src/tools/docmaker/tohtml.py35
-rw-r--r--freetype/src/truetype/ttdriver.c3
-rw-r--r--freetype/src/truetype/ttgload.c354
-rw-r--r--freetype/src/truetype/ttgload.h1
-rw-r--r--freetype/src/truetype/ttinterp.c287
-rw-r--r--freetype/src/truetype/ttinterp.h10
-rw-r--r--freetype/src/truetype/ttobjs.c23
-rw-r--r--freetype/src/type1/t1gload.c6
-rw-r--r--freetype/src/type1/t1load.c17
-rw-r--r--freetype/src/type1/t1objs.c8
-rw-r--r--freetype/src/type1/t1parse.c31
-rw-r--r--freetype/src/type42/t42objs.c11
-rw-r--r--freetype/src/type42/t42parse.c50
-rw-r--r--freetype/src/winfonts/winfnt.c28
119 files changed, 7198 insertions, 2334 deletions
diff --git a/freetype/src/Jamfile b/freetype/src/Jamfile
index 76ee0f46e..1cc06858c 100644
--- a/freetype/src/Jamfile
+++ b/freetype/src/Jamfile
@@ -1,6 +1,6 @@
# FreeType 2 src Jamfile
#
-# Copyright 2001, 2002 by
+# Copyright 2001, 2002, 2013 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
@@ -11,7 +11,7 @@
SubDir FT2_TOP $(FT2_SRC_DIR) ;
-# The file <freetype/internal/internal.h> is used to define macros that are
+# The file <internal/internal.h> is used to define macros that are
# later used in #include statements. It needs to be parsed in order to
# record these definitions.
#
diff --git a/freetype/src/autofit/afblue.c b/freetype/src/autofit/afblue.c
new file mode 100644
index 000000000..6e214c872
--- /dev/null
+++ b/freetype/src/autofit/afblue.c
@@ -0,0 +1,166 @@
+/* This file has been generated by the Perl script `afblue.pl', */
+/* using data from file `afblue.dat'. */
+
+/***************************************************************************/
+/* */
+/* afblue.c */
+/* */
+/* Auto-fitter data for blue strings (body). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#include "aftypes.h"
+
+
+ FT_LOCAL_ARRAY_DEF( char )
+ af_blue_strings[] =
+ {
+ /* */
+ 'T', 'H', 'E', 'Z', 'O', 'C', 'Q', 'S', /* THEZOCQS */
+ '\0',
+ 'H', 'E', 'Z', 'L', 'O', 'C', 'U', 'S', /* HEZLOCUS */
+ '\0',
+ 'f', 'i', 'j', 'k', 'd', 'b', 'h', /* fijkdbh */
+ '\0',
+ 'x', 'z', 'r', 'o', 'e', 's', 'c', /* xzroesc */
+ '\0',
+ 'p', 'q', 'g', 'j', 'y', /* pqgjy */
+ '\0',
+ '\xCE', '\x93', '\xCE', '\x92', '\xCE', '\x95', '\xCE', '\x96', '\xCE', '\x98', '\xCE', '\x9F', '\xCE', '\xA9', /* ΓΒΕΖΘΟΩ */
+ '\0',
+ '\xCE', '\x92', '\xCE', '\x94', '\xCE', '\x96', '\xCE', '\x9E', '\xCE', '\x98', '\xCE', '\x9F', /* ΒΔΖΞΘΟ */
+ '\0',
+ '\xCE', '\xB2', '\xCE', '\xB8', '\xCE', '\xB4', '\xCE', '\xB6', '\xCE', '\xBB', '\xCE', '\xBE', /* βθδζλξ */
+ '\0',
+ '\xCE', '\xB1', '\xCE', '\xB5', '\xCE', '\xB9', '\xCE', '\xBF', '\xCF', '\x80', '\xCF', '\x83', '\xCF', '\x84', '\xCF', '\x89', /* αειοπστω */
+ '\0',
+ '\xCE', '\xB2', '\xCE', '\xB3', '\xCE', '\xB7', '\xCE', '\xBC', '\xCF', '\x81', '\xCF', '\x86', '\xCF', '\x87', '\xCF', '\x88', /* βγημρφχψ */
+ '\0',
+ '\xD0', '\x91', '\xD0', '\x92', '\xD0', '\x95', '\xD0', '\x9F', '\xD0', '\x97', '\xD0', '\x9E', '\xD0', '\xA1', '\xD0', '\xAD', /* БВЕПЗОСЭ */
+ '\0',
+ '\xD0', '\x91', '\xD0', '\x92', '\xD0', '\x95', '\xD0', '\xA8', '\xD0', '\x97', '\xD0', '\x9E', '\xD0', '\xA1', '\xD0', '\xAD', /* БВЕШЗОСЭ */
+ '\0',
+ '\xD1', '\x85', '\xD0', '\xBF', '\xD0', '\xBD', '\xD1', '\x88', '\xD0', '\xB5', '\xD0', '\xB7', '\xD0', '\xBE', '\xD1', '\x81', /* хпншезос */
+ '\0',
+ '\xD1', '\x80', '\xD1', '\x83', '\xD1', '\x84', /* руф */
+ '\0',
+ '\xD7', '\x91', '\xD7', '\x93', '\xD7', '\x94', '\xD7', '\x97', '\xD7', '\x9A', '\xD7', '\x9B', '\xD7', '\x9D', '\xD7', '\xA1', /* בדהחךכםס */
+ '\0',
+ '\xD7', '\x91', '\xD7', '\x98', '\xD7', '\x9B', '\xD7', '\x9D', '\xD7', '\xA1', '\xD7', '\xA6', /* בטכםסצ */
+ '\0',
+ '\xD7', '\xA7', '\xD7', '\x9A', '\xD7', '\x9F', '\xD7', '\xA3', '\xD7', '\xA5', /* קךןףץ */
+#ifdef AF_CONFIG_OPTION_CJK
+ '\0',
+ '\xE4', '\xBB', '\x96', '\xE4', '\xBB', '\xAC', '\xE4', '\xBD', '\xA0', '\xE4', '\xBE', '\x86', '\xE5', '\x80', '\x91', '\xE5', '\x88', '\xB0', '\xE5', '\x92', '\x8C', '\xE5', '\x9C', '\xB0', /* 他们你來們到和地 */
+ '\xE5', '\xAF', '\xB9', '\xE5', '\xB0', '\x8D', '\xE5', '\xB0', '\xB1', '\xE5', '\xB8', '\xAD', '\xE6', '\x88', '\x91', '\xE6', '\x97', '\xB6', '\xE6', '\x99', '\x82', '\xE6', '\x9C', '\x83', /* 对對就席我时時會 */
+ '\xE6', '\x9D', '\xA5', '\xE7', '\x82', '\xBA', '\xE8', '\x83', '\xBD', '\xE8', '\x88', '\xB0', '\xE8', '\xAA', '\xAA', '\xE8', '\xAF', '\xB4', '\xE8', '\xBF', '\x99', '\xE9', '\x80', '\x99', /* 来為能舰說说这這 */
+ '\xE9', '\xBD', '\x8A', /* 齊 */
+ '\0',
+ '\xE5', '\x86', '\x9B', '\xE5', '\x90', '\x8C', '\xE5', '\xB7', '\xB2', '\xE6', '\x84', '\xBF', '\xE6', '\x97', '\xA2', '\xE6', '\x98', '\x9F', '\xE6', '\x98', '\xAF', '\xE6', '\x99', '\xAF', /* 军同已愿既星是景 */
+ '\xE6', '\xB0', '\x91', '\xE7', '\x85', '\xA7', '\xE7', '\x8E', '\xB0', '\xE7', '\x8F', '\xBE', '\xE7', '\x90', '\x86', '\xE7', '\x94', '\xA8', '\xE7', '\xBD', '\xAE', '\xE8', '\xA6', '\x81', /* 民照现現理用置要 */
+ '\xE8', '\xBB', '\x8D', '\xE9', '\x82', '\xA3', '\xE9', '\x85', '\x8D', '\xE9', '\x87', '\x8C', '\xE9', '\x96', '\x8B', '\xE9', '\x9B', '\xB7', '\xE9', '\x9C', '\xB2', '\xE9', '\x9D', '\xA2', /* 軍那配里開雷露面 */
+ '\xE9', '\xA1', '\xBE', /* 顾 */
+ '\0',
+ '\xE4', '\xB8', '\xAA', '\xE4', '\xB8', '\xBA', '\xE4', '\xBA', '\xBA', '\xE4', '\xBB', '\x96', '\xE4', '\xBB', '\xA5', '\xE4', '\xBB', '\xAC', '\xE4', '\xBD', '\xA0', '\xE4', '\xBE', '\x86', /* 个为人他以们你來 */
+ '\xE5', '\x80', '\x8B', '\xE5', '\x80', '\x91', '\xE5', '\x88', '\xB0', '\xE5', '\x92', '\x8C', '\xE5', '\xA4', '\xA7', '\xE5', '\xAF', '\xB9', '\xE5', '\xB0', '\x8D', '\xE5', '\xB0', '\xB1', /* 個們到和大对對就 */
+ '\xE6', '\x88', '\x91', '\xE6', '\x97', '\xB6', '\xE6', '\x99', '\x82', '\xE6', '\x9C', '\x89', '\xE6', '\x9D', '\xA5', '\xE7', '\x82', '\xBA', '\xE8', '\xA6', '\x81', '\xE8', '\xAA', '\xAA', /* 我时時有来為要說 */
+ '\xE8', '\xAF', '\xB4', /* 说 */
+ '\0',
+ '\xE4', '\xB8', '\xBB', '\xE4', '\xBA', '\x9B', '\xE5', '\x9B', '\xA0', '\xE5', '\xAE', '\x83', '\xE6', '\x83', '\xB3', '\xE6', '\x84', '\x8F', '\xE7', '\x90', '\x86', '\xE7', '\x94', '\x9F', /* 主些因它想意理生 */
+ '\xE7', '\x95', '\xB6', '\xE7', '\x9C', '\x8B', '\xE7', '\x9D', '\x80', '\xE7', '\xBD', '\xAE', '\xE8', '\x80', '\x85', '\xE8', '\x87', '\xAA', '\xE8', '\x91', '\x97', '\xE8', '\xA3', '\xA1', /* 當看着置者自著裡 */
+ '\xE8', '\xBF', '\x87', '\xE8', '\xBF', '\x98', '\xE8', '\xBF', '\x9B', '\xE9', '\x80', '\xB2', '\xE9', '\x81', '\x8E', '\xE9', '\x81', '\x93', '\xE9', '\x82', '\x84', '\xE9', '\x87', '\x8C', /* 过还进進過道還里 */
+ '\xE9', '\x9D', '\xA2', /* 面 */
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+ '\0',
+ '\xE4', '\xBA', '\x9B', '\xE4', '\xBB', '\xAC', '\xE4', '\xBD', '\xA0', '\xE4', '\xBE', '\x86', '\xE5', '\x80', '\x91', '\xE5', '\x88', '\xB0', '\xE5', '\x92', '\x8C', '\xE5', '\x9C', '\xB0', /* 些们你來們到和地 */
+ '\xE5', '\xA5', '\xB9', '\xE5', '\xB0', '\x86', '\xE5', '\xB0', '\x87', '\xE5', '\xB0', '\xB1', '\xE5', '\xB9', '\xB4', '\xE5', '\xBE', '\x97', '\xE6', '\x83', '\x85', '\xE6', '\x9C', '\x80', /* 她将將就年得情最 */
+ '\xE6', '\xA0', '\xB7', '\xE6', '\xA8', '\xA3', '\xE7', '\x90', '\x86', '\xE8', '\x83', '\xBD', '\xE8', '\xAA', '\xAA', '\xE8', '\xAF', '\xB4', '\xE8', '\xBF', '\x99', '\xE9', '\x80', '\x99', /* 样樣理能說说这這 */
+ '\xE9', '\x80', '\x9A', /* 通 */
+ '\0',
+ '\xE5', '\x8D', '\xB3', '\xE5', '\x90', '\x97', '\xE5', '\x90', '\xA7', '\xE5', '\x90', '\xAC', '\xE5', '\x91', '\xA2', '\xE5', '\x93', '\x81', '\xE5', '\x93', '\x8D', '\xE5', '\x97', '\x8E', /* 即吗吧听呢品响嗎 */
+ '\xE5', '\xB8', '\x88', '\xE5', '\xB8', '\xAB', '\xE6', '\x94', '\xB6', '\xE6', '\x96', '\xAD', '\xE6', '\x96', '\xB7', '\xE6', '\x98', '\x8E', '\xE7', '\x9C', '\xBC', '\xE9', '\x96', '\x93', /* 师師收断斷明眼間 */
+ '\xE9', '\x97', '\xB4', '\xE9', '\x99', '\x85', '\xE9', '\x99', '\x88', '\xE9', '\x99', '\x90', '\xE9', '\x99', '\xA4', '\xE9', '\x99', '\xB3', '\xE9', '\x9A', '\x8F', '\xE9', '\x9A', '\x9B', /* 间际陈限除陳随際 */
+ '\xE9', '\x9A', '\xA8', /* 隨 */
+ '\0',
+ '\xE4', '\xBA', '\x8B', '\xE5', '\x89', '\x8D', '\xE5', '\xAD', '\xB8', '\xE5', '\xB0', '\x86', '\xE5', '\xB0', '\x87', '\xE6', '\x83', '\x85', '\xE6', '\x83', '\xB3', '\xE6', '\x88', '\x96', /* 事前學将將情想或 */
+ '\xE6', '\x94', '\xBF', '\xE6', '\x96', '\xAF', '\xE6', '\x96', '\xB0', '\xE6', '\xA0', '\xB7', '\xE6', '\xA8', '\xA3', '\xE6', '\xB0', '\x91', '\xE6', '\xB2', '\x92', '\xE6', '\xB2', '\xA1', /* 政斯新样樣民沒没 */
+ '\xE7', '\x84', '\xB6', '\xE7', '\x89', '\xB9', '\xE7', '\x8E', '\xB0', '\xE7', '\x8F', '\xBE', '\xE7', '\x90', '\x83', '\xE7', '\xAC', '\xAC', '\xE7', '\xB6', '\x93', '\xE8', '\xB0', '\x81', /* 然特现現球第經谁 */
+ '\xE8', '\xB5', '\xB7', /* 起 */
+ '\0',
+ '\xE4', '\xBE', '\x8B', '\xE5', '\x88', '\xA5', '\xE5', '\x88', '\xAB', '\xE5', '\x88', '\xB6', '\xE5', '\x8A', '\xA8', '\xE5', '\x8B', '\x95', '\xE5', '\x90', '\x97', '\xE5', '\x97', '\x8E', /* 例別别制动動吗嗎 */
+ '\xE5', '\xA2', '\x9E', '\xE6', '\x8C', '\x87', '\xE6', '\x98', '\x8E', '\xE6', '\x9C', '\x9D', '\xE6', '\x9C', '\x9F', '\xE6', '\x9E', '\x84', '\xE7', '\x89', '\xA9', '\xE7', '\xA1', '\xAE', /* 增指明朝期构物确 */
+ '\xE7', '\xA7', '\x8D', '\xE8', '\xAA', '\xBF', '\xE8', '\xB0', '\x83', '\xE8', '\xB2', '\xBB', '\xE8', '\xB4', '\xB9', '\xE9', '\x82', '\xA3', '\xE9', '\x83', '\xBD', '\xE9', '\x96', '\x93', /* 种調调費费那都間 */
+ '\xE9', '\x97', '\xB4', /* 间 */
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+#endif /* AF_CONFIG_OPTION_CJK */
+ '\0',
+
+ };
+
+
+ /* stringsets are specific to styles */
+ FT_LOCAL_ARRAY_DEF( AF_Blue_StringRec )
+ af_blue_stringsets[] =
+ {
+ /* */
+ { AF_BLUE_STRING_LATIN_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_LATIN_CAPITAL_BOTTOM, 0 },
+ { AF_BLUE_STRING_LATIN_SMALL_F_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_LATIN_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT },
+ { AF_BLUE_STRING_LATIN_SMALL, 0 },
+ { AF_BLUE_STRING_LATIN_SMALL_DESCENDER, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
+ { AF_BLUE_STRING_GREEK_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_GREEK_CAPITAL_BOTTOM, 0 },
+ { AF_BLUE_STRING_GREEK_SMALL_BETA_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_GREEK_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT },
+ { AF_BLUE_STRING_GREEK_SMALL, 0 },
+ { AF_BLUE_STRING_GREEK_SMALL_DESCENDER, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
+ { AF_BLUE_STRING_CYRILLIC_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
+ { AF_BLUE_STRING_CYRILLIC_CAPITAL_BOTTOM, 0 },
+ { AF_BLUE_STRING_CYRILLIC_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT },
+ { AF_BLUE_STRING_CYRILLIC_SMALL, 0 },
+ { AF_BLUE_STRING_CYRILLIC_SMALL_DESCENDER, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
+ { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_LONG },
+ { AF_BLUE_STRING_HEBREW_BOTTOM, 0 },
+ { AF_BLUE_STRING_HEBREW_DESCENDER, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
+#ifdef AF_CONFIG_OPTION_CJK
+ { AF_BLUE_STRING_CJK_TOP_FILL, AF_BLUE_PROPERTY_CJK_TOP |
+ AF_BLUE_PROPERTY_CJK_FILL },
+ { AF_BLUE_STRING_CJK_TOP_UNFILL, AF_BLUE_PROPERTY_CJK_TOP },
+ { AF_BLUE_STRING_CJK_BOTTOM_FILL, AF_BLUE_PROPERTY_CJK_FILL },
+ { AF_BLUE_STRING_CJK_BOTTOM_UNFILL, 0 },
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+ { AF_BLUE_STRING_CJK_LEFT_FILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_FILL },
+ { AF_BLUE_STRING_CJK_LEFT_UNFILL, AF_BLUE_PROPERTY_CJK_HORIZ },
+ { AF_BLUE_STRING_CJK_RIGHT_FILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_RIGHT |
+ AF_BLUE_PROPERTY_CJK_FILL },
+ { AF_BLUE_STRING_CJK_RIGHT_UNFILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_RIGHT },
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+ { AF_BLUE_STRING_MAX, 0 },
+#endif /* AF_CONFIG_OPTION_CJK */
+
+ };
+
+
+/* END */
diff --git a/freetype/src/autofit/afblue.cin b/freetype/src/autofit/afblue.cin
new file mode 100644
index 000000000..c6762bec3
--- /dev/null
+++ b/freetype/src/autofit/afblue.cin
@@ -0,0 +1,39 @@
+/***************************************************************************/
+/* */
+/* afblue.c */
+/* */
+/* Auto-fitter data for blue strings (body). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#include "aftypes.h"
+
+
+ FT_LOCAL_ARRAY_DEF( char )
+ af_blue_strings[] =
+ {
+ /* */
+@AF_BLUE_STRINGS_ARRAY@
+ };
+
+
+ /* stringsets are specific to styles */
+ FT_LOCAL_ARRAY_DEF( AF_Blue_StringRec )
+ af_blue_stringsets[] =
+ {
+ /* */
+@AF_BLUE_STRINGSETS_ARRAY@
+ };
+
+
+/* END */
diff --git a/freetype/src/autofit/afblue.dat b/freetype/src/autofit/afblue.dat
new file mode 100644
index 000000000..d488f3fae
--- /dev/null
+++ b/freetype/src/autofit/afblue.dat
@@ -0,0 +1,218 @@
+// afblue.dat
+//
+// Auto-fitter data for blue strings.
+//
+// Copyright 2013 by
+// David Turner, Robert Wilhelm, and Werner Lemberg.
+//
+// This file is part of the FreeType project, and may only be used,
+// modified, and distributed under the terms of the FreeType project
+// license, LICENSE.TXT. By continuing to use, modify, or distribute
+// this file you indicate that you have read the license and
+// understand and accept it fully.
+
+
+// This file contains data specific to blue zones. It gets processed by
+// a script to simulate `jagged arrays', with enumeration values holding
+// offsets into the arrays.
+//
+// The format of the file is rather simple: A section starts with three
+// labels separated by whitespace and followed by a colon (everything in a
+// single line); the first label gives the name of the enumeration template,
+// the second the name of the array template, and the third the name of the
+// `maximum' template, holding the size of the largest array element. The
+// script then fills the corresponding templates (indicated by `@'
+// characters around the name).
+//
+// A section contains one or more data records. Each data record consists
+// of two or more lines. The first line holds the enumeration name, and the
+// remaining lines the corresponding array data.
+//
+// There are two possible representations for array data.
+//
+// - A string of characters in UTF-8 encoding enclosed in double quotes,
+// using C syntax. There can be only one string per line, thus the
+// starting and ending double quote must be the first and last character
+// in the line, respectively, ignoring whitespace before and after the
+// string. If there are multiple strings (in multiple lines), they are
+// concatenated to a single string. In the output, a string gets
+// represented as a series of singles bytes, followed by a zero byte. The
+// enumeration values simply hold byte offsets to the start of the
+// corresponding strings.
+//
+// - Data blocks enclosed in balanced braces, which get copied verbatim and
+// which can span multiple lines. The opening brace of a block must be
+// the first character of a line (ignoring whitespace), and the closing
+// brace the last (ignoring whitespace also). The script appends a comma
+// character after each block and counts the number of blocks to set the
+// enumeration values.
+//
+// A section can contain either strings only or data blocks only.
+//
+// A comment line starts with `//'; it gets removed. A preprocessor
+// directive line (using the standard syntax of `cpp') starts with `#' and
+// gets copied verbatim to both the enumeration and the array. Whitespace
+// outside of a string is insignificant.
+//
+// Preprocessor directives are ignored while the script computes maximum
+// values; this essentially means that the maximum values can easily be too
+// large. Given that the purpose of those values is to create local
+// fixed-size arrays at compile time for further processing of the blue zone
+// data, this isn't a problem. Note the the final zero byte of a string is
+// not counted. Note also that the count holds the number of UTF-8 encoded
+// characters, not bytes.
+
+
+AF_BLUE_STRING_ENUM AF_BLUE_STRINGS_ARRAY AF_BLUE_STRING_MAX_LEN:
+
+ AF_BLUE_STRING_LATIN_CAPITAL_TOP
+ "THEZOCQS"
+ AF_BLUE_STRING_LATIN_CAPITAL_BOTTOM
+ "HEZLOCUS"
+ AF_BLUE_STRING_LATIN_SMALL_F_TOP
+ "fijkdbh"
+ AF_BLUE_STRING_LATIN_SMALL
+ "xzroesc"
+ AF_BLUE_STRING_LATIN_SMALL_DESCENDER
+ "pqgjy"
+
+ AF_BLUE_STRING_GREEK_CAPITAL_TOP
+ "ΓΒΕΖΘΟΩ"
+ AF_BLUE_STRING_GREEK_CAPITAL_BOTTOM
+ "ΒΔΖΞΘΟ"
+ AF_BLUE_STRING_GREEK_SMALL_BETA_TOP
+ "βθδζλξ"
+ AF_BLUE_STRING_GREEK_SMALL
+ "αειοπστω"
+ AF_BLUE_STRING_GREEK_SMALL_DESCENDER
+ "βγημρφχψ"
+
+ AF_BLUE_STRING_CYRILLIC_CAPITAL_TOP
+ "БВЕПЗОСЭ"
+ AF_BLUE_STRING_CYRILLIC_CAPITAL_BOTTOM
+ "БВЕШЗОСЭ"
+ AF_BLUE_STRING_CYRILLIC_SMALL
+ "хпншезос"
+ AF_BLUE_STRING_CYRILLIC_SMALL_DESCENDER
+ "руф"
+
+ AF_BLUE_STRING_HEBREW_TOP
+ "בדהחךכםס"
+ AF_BLUE_STRING_HEBREW_BOTTOM
+ "בטכםסצ"
+ AF_BLUE_STRING_HEBREW_DESCENDER
+ "קךןףץ"
+
+#ifdef AF_CONFIG_OPTION_CJK
+
+ AF_BLUE_STRING_CJK_TOP_FILL
+ "他们你來們到和地"
+ "对對就席我时時會"
+ "来為能舰說说这這"
+ "齊"
+ AF_BLUE_STRING_CJK_TOP_UNFILL
+ "军同已愿既星是景"
+ "民照现現理用置要"
+ "軍那配里開雷露面"
+ "顾"
+ AF_BLUE_STRING_CJK_BOTTOM_FILL
+ "个为人他以们你來"
+ "個們到和大对對就"
+ "我时時有来為要說"
+ "说"
+ AF_BLUE_STRING_CJK_BOTTOM_UNFILL
+ "主些因它想意理生"
+ "當看着置者自著裡"
+ "过还进進過道還里"
+ "面"
+
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+
+ AF_BLUE_STRING_CJK_LEFT_FILL
+ "些们你來們到和地"
+ "她将將就年得情最"
+ "样樣理能說说这這"
+ "通"
+ AF_BLUE_STRING_CJK_LEFT_UNFILL
+ "即吗吧听呢品响嗎"
+ "师師收断斷明眼間"
+ "间际陈限除陳随際"
+ "隨"
+ AF_BLUE_STRING_CJK_RIGHT_FILL
+ "事前學将將情想或"
+ "政斯新样樣民沒没"
+ "然特现現球第經谁"
+ "起"
+ AF_BLUE_STRING_CJK_RIGHT_UNFILL
+ "例別别制动動吗嗎"
+ "增指明朝期构物确"
+ "种調调費费那都間"
+ "间"
+
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+AF_BLUE_STRINGSET_ENUM AF_BLUE_STRINGSETS_ARRAY AF_BLUE_STRINGSET_MAX_LEN:
+
+ AF_BLUE_STRINGSET_LATN
+ { AF_BLUE_STRING_LATIN_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_LATIN_CAPITAL_BOTTOM, 0 }
+ { AF_BLUE_STRING_LATIN_SMALL_F_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_LATIN_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT }
+ { AF_BLUE_STRING_LATIN_SMALL, 0 }
+ { AF_BLUE_STRING_LATIN_SMALL_DESCENDER, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
+
+ AF_BLUE_STRINGSET_GREK
+ { AF_BLUE_STRING_GREEK_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_GREEK_CAPITAL_BOTTOM, 0 }
+ { AF_BLUE_STRING_GREEK_SMALL_BETA_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_GREEK_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT }
+ { AF_BLUE_STRING_GREEK_SMALL, 0 }
+ { AF_BLUE_STRING_GREEK_SMALL_DESCENDER, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
+
+ AF_BLUE_STRINGSET_CYRL
+ { AF_BLUE_STRING_CYRILLIC_CAPITAL_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
+ { AF_BLUE_STRING_CYRILLIC_CAPITAL_BOTTOM, 0 }
+ { AF_BLUE_STRING_CYRILLIC_SMALL, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_X_HEIGHT }
+ { AF_BLUE_STRING_CYRILLIC_SMALL, 0 }
+ { AF_BLUE_STRING_CYRILLIC_SMALL_DESCENDER, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
+
+ AF_BLUE_STRINGSET_HEBR
+ { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_LONG }
+ { AF_BLUE_STRING_HEBREW_BOTTOM, 0 }
+ { AF_BLUE_STRING_HEBREW_DESCENDER, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
+
+#ifdef AF_CONFIG_OPTION_CJK
+
+ AF_BLUE_STRINGSET_HANI
+ { AF_BLUE_STRING_CJK_TOP_FILL, AF_BLUE_PROPERTY_CJK_TOP |
+ AF_BLUE_PROPERTY_CJK_FILL }
+ { AF_BLUE_STRING_CJK_TOP_UNFILL, AF_BLUE_PROPERTY_CJK_TOP }
+ { AF_BLUE_STRING_CJK_BOTTOM_FILL, AF_BLUE_PROPERTY_CJK_FILL }
+ { AF_BLUE_STRING_CJK_BOTTOM_UNFILL, 0 }
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+ { AF_BLUE_STRING_CJK_LEFT_FILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_FILL }
+ { AF_BLUE_STRING_CJK_LEFT_UNFILL, AF_BLUE_PROPERTY_CJK_HORIZ }
+ { AF_BLUE_STRING_CJK_RIGHT_FILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_RIGHT |
+ AF_BLUE_PROPERTY_CJK_FILL }
+ { AF_BLUE_STRING_CJK_RIGHT_UNFILL, AF_BLUE_PROPERTY_CJK_HORIZ |
+ AF_BLUE_PROPERTY_CJK_RIGHT }
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+ { AF_BLUE_STRING_MAX, 0 }
+
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+// END
diff --git a/freetype/src/autofit/afblue.h b/freetype/src/autofit/afblue.h
new file mode 100644
index 000000000..6f336abc0
--- /dev/null
+++ b/freetype/src/autofit/afblue.h
@@ -0,0 +1,199 @@
+/* This file has been generated by the Perl script `afblue.pl', */
+/* using data from file `afblue.dat'. */
+
+/***************************************************************************/
+/* */
+/* afblue.h */
+/* */
+/* Auto-fitter data for blue strings (specification). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __AFBLUE_H__
+#define __AFBLUE_H__
+
+
+FT_BEGIN_HEADER
+
+
+ /* an auxiliary macro to decode a UTF-8 character -- since we only use */
+ /* hard-coded, self-converted data, no error checking is performed */
+#define GET_UTF8_CHAR( ch, p ) \
+ ch = (unsigned char)*p++; \
+ if ( ch >= 0x80 ) \
+ { \
+ FT_UInt len; \
+ \
+ \
+ if ( ch < 0xE0 ) \
+ { \
+ len = 1; \
+ ch &= 0x1F; \
+ } \
+ else if ( ch < 0xF0 ) \
+ { \
+ len = 2; \
+ ch &= 0x0F; \
+ } \
+ else \
+ { \
+ len = 3; \
+ ch &= 0x07; \
+ } \
+ \
+ for ( ; len > 0; len-- ) \
+ ch = ( ch << 6 ) | ( *p++ & 0x3F ); \
+ }
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** B L U E S T R I N G S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /* At the bottommost level, we define strings for finding blue zones. */
+
+
+#define AF_BLUE_STRING_MAX_LEN 25
+
+ /* The AF_Blue_String enumeration values are offsets into the */
+ /* `af_blue_strings' array. */
+
+ typedef enum AF_Blue_String_
+ {
+ AF_BLUE_STRING_LATIN_CAPITAL_TOP = 0,
+ AF_BLUE_STRING_LATIN_CAPITAL_BOTTOM = 9,
+ AF_BLUE_STRING_LATIN_SMALL_F_TOP = 18,
+ AF_BLUE_STRING_LATIN_SMALL = 26,
+ AF_BLUE_STRING_LATIN_SMALL_DESCENDER = 34,
+ AF_BLUE_STRING_GREEK_CAPITAL_TOP = 40,
+ AF_BLUE_STRING_GREEK_CAPITAL_BOTTOM = 55,
+ AF_BLUE_STRING_GREEK_SMALL_BETA_TOP = 68,
+ AF_BLUE_STRING_GREEK_SMALL = 81,
+ AF_BLUE_STRING_GREEK_SMALL_DESCENDER = 98,
+ AF_BLUE_STRING_CYRILLIC_CAPITAL_TOP = 115,
+ AF_BLUE_STRING_CYRILLIC_CAPITAL_BOTTOM = 132,
+ AF_BLUE_STRING_CYRILLIC_SMALL = 149,
+ AF_BLUE_STRING_CYRILLIC_SMALL_DESCENDER = 166,
+ AF_BLUE_STRING_HEBREW_TOP = 173,
+ AF_BLUE_STRING_HEBREW_BOTTOM = 190,
+ AF_BLUE_STRING_HEBREW_DESCENDER = 203,
+ af_blue_1_1 = 213,
+#ifdef AF_CONFIG_OPTION_CJK
+ AF_BLUE_STRING_CJK_TOP_FILL = af_blue_1_1 + 1,
+ AF_BLUE_STRING_CJK_TOP_UNFILL = af_blue_1_1 + 77,
+ AF_BLUE_STRING_CJK_BOTTOM_FILL = af_blue_1_1 + 153,
+ AF_BLUE_STRING_CJK_BOTTOM_UNFILL = af_blue_1_1 + 229,
+ af_blue_1_1_1 = af_blue_1_1 + 304,
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+ AF_BLUE_STRING_CJK_LEFT_FILL = af_blue_1_1_1 + 1,
+ AF_BLUE_STRING_CJK_LEFT_UNFILL = af_blue_1_1_1 + 77,
+ AF_BLUE_STRING_CJK_RIGHT_FILL = af_blue_1_1_1 + 153,
+ AF_BLUE_STRING_CJK_RIGHT_UNFILL = af_blue_1_1_1 + 229,
+ af_blue_1_1_2 = af_blue_1_1_1 + 304,
+#else
+ af_blue_1_1_2 = af_blue_1_1_1 + 0,
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+ af_blue_1_2 = af_blue_1_1_2 + 0,
+#else
+ af_blue_1_2 = af_blue_1_1 + 0,
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+ AF_BLUE_STRING_MAX /* do not remove */
+
+ } AF_Blue_String;
+
+
+ FT_LOCAL_ARRAY( char )
+ af_blue_strings[];
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** B L U E S T R I N G S E T S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /* The next level is to group blue strings into style-specific sets. */
+
+
+ /* Properties are specific to a writing system. We assume that a given */
+ /* blue string can't be used in more than a single writing system, which */
+ /* is a safe bet. */
+#define AF_BLUE_PROPERTY_LATIN_TOP ( 1 << 0 )
+#define AF_BLUE_PROPERTY_LATIN_X_HEIGHT ( 1 << 1 )
+#define AF_BLUE_PROPERTY_LATIN_LONG ( 1 << 2 )
+
+#define AF_BLUE_PROPERTY_CJK_HORIZ ( 1 << 0 )
+#define AF_BLUE_PROPERTY_CJK_TOP ( 1 << 1 )
+#define AF_BLUE_PROPERTY_CJK_FILL ( 1 << 2 )
+#define AF_BLUE_PROPERTY_CJK_RIGHT AF_BLUE_PROPERTY_CJK_TOP
+
+
+#define AF_BLUE_STRINGSET_MAX_LEN 9
+
+ /* The AF_Blue_Stringset enumeration values are offsets into the */
+ /* `af_blue_stringsets' array. */
+
+ typedef enum AF_Blue_Stringset_
+ {
+ AF_BLUE_STRINGSET_LATN = 0,
+ AF_BLUE_STRINGSET_GREK = 7,
+ AF_BLUE_STRINGSET_CYRL = 14,
+ AF_BLUE_STRINGSET_HEBR = 20,
+ af_blue_2_1 = 24,
+#ifdef AF_CONFIG_OPTION_CJK
+ AF_BLUE_STRINGSET_HANI = af_blue_2_1 + 0,
+ af_blue_2_1_1 = af_blue_2_1 + 4,
+#ifdef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
+ af_blue_2_1_2 = af_blue_2_1_1 + 4,
+#else
+ af_blue_2_1_2 = af_blue_2_1_1 + 0,
+#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
+ af_blue_2_2 = af_blue_2_1_2 + 1,
+#else
+ af_blue_2_2 = af_blue_2_1 + 0,
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+ AF_BLUE_STRINGSET_MAX /* do not remove */
+
+ } AF_Blue_Stringset;
+
+
+ typedef struct AF_Blue_StringRec_
+ {
+ AF_Blue_String string;
+ FT_UShort properties;
+
+ } AF_Blue_StringRec;
+
+
+ FT_LOCAL_ARRAY( AF_Blue_StringRec )
+ af_blue_stringsets[];
+
+/* */
+
+FT_END_HEADER
+
+
+#endif /* __AFBLUE_H__ */
+
+
+/* END */
diff --git a/freetype/src/autofit/afblue.hin b/freetype/src/autofit/afblue.hin
new file mode 100644
index 000000000..4fc991755
--- /dev/null
+++ b/freetype/src/autofit/afblue.hin
@@ -0,0 +1,142 @@
+/***************************************************************************/
+/* */
+/* afblue.h */
+/* */
+/* Auto-fitter data for blue strings (specification). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __AFBLUE_H__
+#define __AFBLUE_H__
+
+
+FT_BEGIN_HEADER
+
+
+ /* an auxiliary macro to decode a UTF-8 character -- since we only use */
+ /* hard-coded, self-converted data, no error checking is performed */
+#define GET_UTF8_CHAR( ch, p ) \
+ ch = (unsigned char)*p++; \
+ if ( ch >= 0x80 ) \
+ { \
+ FT_UInt len; \
+ \
+ \
+ if ( ch < 0xE0 ) \
+ { \
+ len = 1; \
+ ch &= 0x1F; \
+ } \
+ else if ( ch < 0xF0 ) \
+ { \
+ len = 2; \
+ ch &= 0x0F; \
+ } \
+ else \
+ { \
+ len = 3; \
+ ch &= 0x07; \
+ } \
+ \
+ for ( ; len > 0; len-- ) \
+ ch = ( ch << 6 ) | ( *p++ & 0x3F ); \
+ }
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** B L U E S T R I N G S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /* At the bottommost level, we define strings for finding blue zones. */
+
+
+#define AF_BLUE_STRING_MAX_LEN @AF_BLUE_STRING_MAX_LEN@
+
+ /* The AF_Blue_String enumeration values are offsets into the */
+ /* `af_blue_strings' array. */
+
+ typedef enum AF_Blue_String_
+ {
+@AF_BLUE_STRING_ENUM@
+
+ AF_BLUE_STRING_MAX /* do not remove */
+
+ } AF_Blue_String;
+
+
+ FT_LOCAL_ARRAY( char )
+ af_blue_strings[];
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** B L U E S T R I N G S E T S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /* The next level is to group blue strings into style-specific sets. */
+
+
+ /* Properties are specific to a writing system. We assume that a given */
+ /* blue string can't be used in more than a single writing system, which */
+ /* is a safe bet. */
+#define AF_BLUE_PROPERTY_LATIN_TOP ( 1 << 0 )
+#define AF_BLUE_PROPERTY_LATIN_X_HEIGHT ( 1 << 1 )
+#define AF_BLUE_PROPERTY_LATIN_LONG ( 1 << 2 )
+
+#define AF_BLUE_PROPERTY_CJK_HORIZ ( 1 << 0 )
+#define AF_BLUE_PROPERTY_CJK_TOP ( 1 << 1 )
+#define AF_BLUE_PROPERTY_CJK_FILL ( 1 << 2 )
+#define AF_BLUE_PROPERTY_CJK_RIGHT AF_BLUE_PROPERTY_CJK_TOP
+
+
+#define AF_BLUE_STRINGSET_MAX_LEN @AF_BLUE_STRINGSET_MAX_LEN@
+
+ /* The AF_Blue_Stringset enumeration values are offsets into the */
+ /* `af_blue_stringsets' array. */
+
+ typedef enum AF_Blue_Stringset_
+ {
+@AF_BLUE_STRINGSET_ENUM@
+
+ AF_BLUE_STRINGSET_MAX /* do not remove */
+
+ } AF_Blue_Stringset;
+
+
+ typedef struct AF_Blue_StringRec_
+ {
+ AF_Blue_String string;
+ FT_UShort properties;
+
+ } AF_Blue_StringRec;
+
+
+ FT_LOCAL_ARRAY( AF_Blue_StringRec )
+ af_blue_stringsets[];
+
+/* */
+
+FT_END_HEADER
+
+
+#endif /* __AFBLUE_H__ */
+
+
+/* END */
diff --git a/freetype/src/autofit/afcjk.c b/freetype/src/autofit/afcjk.c
index c94727b1b..7402b9b08 100644
--- a/freetype/src/autofit/afcjk.c
+++ b/freetype/src/autofit/afcjk.c
@@ -2,7 +2,7 @@
/* */
/* afcjk.c */
/* */
-/* Auto-fitter hinting routines for CJK script (body). */
+/* Auto-fitter hinting routines for CJK writing system (body). */
/* */
/* Copyright 2006-2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
@@ -26,7 +26,8 @@
#include <freetype/ftadvanc.h>
#include <freetype/internal/ftdebug.h>
-#include "aftypes.h"
+#include "afglobal.h"
+#include "afpic.h"
#include "aflatin.h"
@@ -73,6 +74,12 @@
AF_GlyphHintsRec hints[1];
+ FT_TRACE5(( "\n"
+ "cjk standard widths computation (style `%s')\n"
+ "===================================================\n"
+ "\n",
+ af_style_names[metrics->root.style_class->style] ));
+
af_glyph_hints_init( hints, face->memory );
metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
@@ -80,16 +87,59 @@
{
FT_Error error;
- FT_UInt glyph_index;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
int dim;
AF_CJKMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
+#ifdef FT_CONFIG_OPTION_PIC
+ AF_FaceGlobals globals = metrics->root.globals;
+#endif
- glyph_index = FT_Get_Char_Index( face,
- metrics->root.clazz->standard_char );
- if ( glyph_index == 0 )
- goto Exit;
+ AF_StyleClass style_class = metrics->root.style_class;
+ AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
+ [style_class->script];
+
+ FT_UInt32 standard_char;
+
+
+ standard_char = script_class->standard_char1;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ {
+ if ( script_class->standard_char2 )
+ {
+ standard_char = script_class->standard_char2;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ {
+ if ( script_class->standard_char3 )
+ {
+ standard_char = script_class->standard_char3;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ goto Exit;
+ }
+ else
+ goto Exit;
+ }
+ }
+ else
+ goto Exit;
+ }
+
+ FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
+ standard_char, glyph_index ));
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || face->glyph->outline.n_points <= 0 )
@@ -108,7 +158,7 @@
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
@@ -122,11 +172,13 @@
FT_UInt num_widths = 0;
- error = af_latin_hints_compute_segments( hints, (AF_Dimension)dim );
+ error = af_latin_hints_compute_segments( hints,
+ (AF_Dimension)dim );
if ( error )
goto Exit;
- af_latin_hints_link_segments( hints, (AF_Dimension)dim );
+ af_latin_hints_link_segments( hints,
+ (AF_Dimension)dim );
seg = axhints->segments;
limit = seg + axhints->num_segments;
@@ -151,7 +203,7 @@
}
/* this also replaces multiple almost identical stem widths */
- /* with a single one (the value 100 is heuristic) */
+ /* with a single one (the value 100 is heuristic) */
af_sort_and_quantize_widths( &num_widths, axis->widths,
dummy->units_per_em / 100 );
axis->width_count = num_widths;
@@ -171,263 +223,204 @@
axis->edge_distance_threshold = stdw / 5;
axis->standard_width = stdw;
axis->extra_light = 0;
- }
- }
-
- af_glyph_hints_done( hints );
- }
-
-
-#define AF_CJK_MAX_TEST_CHARACTERS 32
+#ifdef FT_DEBUG_LEVEL_TRACE
+ {
+ FT_UInt i;
- /* Each blue zone has two types of fill and unfill, this is, */
- /* filling the entire glyph square or not. */
- enum
- {
- AF_CJK_BLUE_TYPE_FILL,
- AF_CJK_BLUE_TYPE_UNFILL,
- AF_CJK_BLUE_TYPE_MAX
- };
+ FT_TRACE5(( "%s widths:\n",
+ dim == AF_DIMENSION_VERT ? "horizontal"
+ : "vertical" ));
+ FT_TRACE5(( " %d (standard)", axis->standard_width ));
+ for ( i = 1; i < axis->width_count; i++ )
+ FT_TRACE5(( " %d", axis->widths[i].org ));
- /* Put some common and representative Han Ideographs characters here. */
- static const FT_ULong af_cjk_hani_blue_chars[AF_CJK_BLUE_MAX]
- [AF_CJK_BLUE_TYPE_MAX]
- [AF_CJK_MAX_TEST_CHARACTERS] =
- {
- {
- {
- 0x4ED6, 0x4EEC, 0x4F60, 0x4F86, 0x5011, 0x5230, 0x548C, 0x5730,
- 0x5BF9, 0x5C0D, 0x5C31, 0x5E2D, 0x6211, 0x65F6, 0x6642, 0x6703,
- 0x6765, 0x70BA, 0x80FD, 0x8230, 0x8AAA, 0x8BF4, 0x8FD9, 0x9019,
- 0x9F4A /* top fill */
- },
- {
- 0x519B, 0x540C, 0x5DF2, 0x613F, 0x65E2, 0x661F, 0x662F, 0x666F,
- 0x6C11, 0x7167, 0x73B0, 0x73FE, 0x7406, 0x7528, 0x7F6E, 0x8981,
- 0x8ECD, 0x90A3, 0x914D, 0x91CC, 0x958B, 0x96F7, 0x9732, 0x9762,
- 0x987E /* top unfill */
- }
- },
- {
- {
- 0x4E2A, 0x4E3A, 0x4EBA, 0x4ED6, 0x4EE5, 0x4EEC, 0x4F60, 0x4F86,
- 0x500B, 0x5011, 0x5230, 0x548C, 0x5927, 0x5BF9, 0x5C0D, 0x5C31,
- 0x6211, 0x65F6, 0x6642, 0x6709, 0x6765, 0x70BA, 0x8981, 0x8AAA,
- 0x8BF4 /* bottom fill */
- },
- {
- 0x4E3B, 0x4E9B, 0x56E0, 0x5B83, 0x60F3, 0x610F, 0x7406, 0x751F,
- 0x7576, 0x770B, 0x7740, 0x7F6E, 0x8005, 0x81EA, 0x8457, 0x88E1,
- 0x8FC7, 0x8FD8, 0x8FDB, 0x9032, 0x904E, 0x9053, 0x9084, 0x91CC,
- 0x9762 /* bottom unfill */
- }
- },
-#ifndef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
- { {0x0000}, {0x0000} },
- { {0x0000}, {0x0000} }
-#else
- {
- {
- 0x4E9B, 0x4EEC, 0x4F60, 0x4F86, 0x5011, 0x5230, 0x548C, 0x5730,
- 0x5979, 0x5C06, 0x5C07, 0x5C31, 0x5E74, 0x5F97, 0x60C5, 0x6700,
- 0x6837, 0x6A23, 0x7406, 0x80FD, 0x8AAA, 0x8BF4, 0x8FD9, 0x9019,
- 0x901A /* left fill */
- },
- {
- 0x5373, 0x5417, 0x5427, 0x542C, 0x5462, 0x54C1, 0x54CD, 0x55CE,
- 0x5E08, 0x5E2B, 0x6536, 0x65AD, 0x65B7, 0x660E, 0x773C, 0x9593,
- 0x95F4, 0x9645, 0x9648, 0x9650, 0x9664, 0x9673, 0x968F, 0x969B,
- 0x96A8 /* left unfill */
- }
- },
- {
- {
- 0x4E8B, 0x524D, 0x5B78, 0x5C06, 0x5C07, 0x60C5, 0x60F3, 0x6216,
- 0x653F, 0x65AF, 0x65B0, 0x6837, 0x6A23, 0x6C11, 0x6C92, 0x6CA1,
- 0x7136, 0x7279, 0x73B0, 0x73FE, 0x7403, 0x7B2C, 0x7D93, 0x8C01,
- 0x8D77 /* right fill */
- },
- {
- 0x4F8B, 0x5225, 0x522B, 0x5236, 0x52A8, 0x52D5, 0x5417, 0x55CE,
- 0x589E, 0x6307, 0x660E, 0x671D, 0x671F, 0x6784, 0x7269, 0x786E,
- 0x79CD, 0x8ABF, 0x8C03, 0x8CBB, 0x8D39, 0x90A3, 0x90FD, 0x9593,
- 0x95F4 /* right unfill */
+ FT_TRACE5(( "\n" ));
+ }
+#endif
}
}
-#endif /* AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT */
- };
+ FT_TRACE5(( "\n" ));
+
+ af_glyph_hints_done( hints );
+ }
- /* Calculate blue zones for all the CJK_BLUE_XXX's. */
+
+ /* Find all blue zones. */
static void
- af_cjk_metrics_init_blues( AF_CJKMetrics metrics,
- FT_Face face,
- const FT_ULong blue_chars
- [AF_CJK_BLUE_MAX]
- [AF_CJK_BLUE_TYPE_MAX]
- [AF_CJK_MAX_TEST_CHARACTERS] )
+ af_cjk_metrics_init_blues( AF_CJKMetrics metrics,
+ FT_Face face )
{
- FT_Pos fills[AF_CJK_MAX_TEST_CHARACTERS];
- FT_Pos flats[AF_CJK_MAX_TEST_CHARACTERS];
+ FT_Pos fills[AF_BLUE_STRING_MAX_LEN];
+ FT_Pos flats[AF_BLUE_STRING_MAX_LEN];
- FT_Int num_fills;
- FT_Int num_flats;
+ FT_Int num_fills;
+ FT_Int num_flats;
- FT_Int bb;
- AF_CJKBlue blue;
- FT_Error error;
- AF_CJKAxis axis;
- FT_GlyphSlot glyph = face->glyph;
+ AF_CJKBlue blue;
+ FT_Error error;
+ AF_CJKAxis axis;
+ FT_Outline outline;
+
+ AF_StyleClass sc = metrics->root.style_class;
+
+ AF_Blue_Stringset bss = sc->blue_stringset;
+ const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
#ifdef FT_DEBUG_LEVEL_TRACE
- FT_String* cjk_blue_name[AF_CJK_BLUE_MAX] = {
- (FT_String*)"top",
- (FT_String*)"bottom",
- (FT_String*)"left",
- (FT_String*)"right"
+ FT_String* cjk_blue_name[4] =
+ {
+ (FT_String*)"bottom", /* -- , -- */
+ (FT_String*)"top", /* -- , TOP */
+ (FT_String*)"left", /* HORIZ, -- */
+ (FT_String*)"right" /* HORIZ, TOP */
};
- FT_String* cjk_blue_type_name[AF_CJK_BLUE_TYPE_MAX] = {
- (FT_String*)"filled",
- (FT_String*)"unfilled"
+
+ FT_String* cjk_blue_type_name[2] =
+ {
+ (FT_String*)"unfilled", /* -- */
+ (FT_String*)"filled" /* FILL */
};
#endif
- /* We compute the blues simply by loading each character from the */
- /* `blue_chars[blues]' string, then computing its extreme points */
- /* (depending blue zone type etc.). */
+ /* we walk over the blue character strings as specified in the */
+ /* style's entry in the `af_blue_stringset' array, computing its */
+ /* extremum points (depending on the string properties) */
- FT_TRACE5(( "cjk blue zones computation\n" ));
- FT_TRACE5(( "------------------------------------------------\n" ));
+ FT_TRACE5(( "cjk blue zones computation\n"
+ "==========================\n"
+ "\n" ));
- for ( bb = 0; bb < AF_CJK_BLUE_MAX; bb++ )
+ for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
- FT_Int fill_type;
- FT_Pos* blue_ref;
- FT_Pos* blue_shoot;
+ const char* p = &af_blue_strings[bs->string];
+ FT_Pos* blue_ref;
+ FT_Pos* blue_shoot;
+ if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
+ axis = &metrics->axis[AF_DIMENSION_HORZ];
+ else
+ axis = &metrics->axis[AF_DIMENSION_VERT];
+
+ FT_TRACE5(( "blue zone %d:\n", axis->blue_count ));
+
num_fills = 0;
num_flats = 0;
- for ( fill_type = 0; fill_type < AF_CJK_BLUE_TYPE_MAX; fill_type++ )
+ FT_TRACE5(( " cjk blue %s/%s\n",
+ cjk_blue_name[AF_CJK_IS_HORIZ_BLUE( bs ) |
+ AF_CJK_IS_TOP_BLUE( bs ) ],
+ cjk_blue_type_name[!!AF_CJK_IS_FILLED_BLUE( bs )] ));
+
+ while ( *p )
{
- const FT_ULong* p = blue_chars[bb][fill_type];
- const FT_ULong* limit = p + AF_CJK_MAX_TEST_CHARACTERS;
- FT_Bool fill = FT_BOOL(
- fill_type == AF_CJK_BLUE_TYPE_FILL );
+ FT_ULong ch;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
+ FT_Pos best_pos; /* same as points.y or points.x, resp. */
+ FT_Int best_point;
+ FT_Vector* points;
- FT_TRACE5(( "cjk blue %s/%s\n", cjk_blue_name[bb],
- cjk_blue_type_name[fill_type] ));
+ GET_UTF8_CHAR( ch, p );
+ /* load the character in the face -- skip unknown or empty ones */
+ af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset );
+ if ( glyph_index == 0 )
+ {
+ FT_TRACE5(( " U+%04lX unavailable\n", ch ));
+ continue;
+ }
- for ( ; p < limit && *p; p++ )
+ error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
+ outline = face->glyph->outline;
+ if ( error || outline.n_points <= 0 )
{
- FT_UInt glyph_index;
- FT_Pos best_pos; /* same as points.y */
- FT_Int best_point;
- FT_Vector* points;
+ FT_TRACE5(( " U+%04lX contains no outlines\n", ch ));
+ continue;
+ }
+ /* now compute min or max point indices and coordinates */
+ points = outline.points;
+ best_point = -1;
+ best_pos = 0; /* make compiler happy */
- FT_TRACE5(( " U+%lX...", *p ));
+ {
+ FT_Int nn;
+ FT_Int first = 0;
+ FT_Int last = -1;
- /* load the character in the face -- skip unknown or empty ones */
- glyph_index = FT_Get_Char_Index( face, *p );
- if ( glyph_index == 0 )
- {
- FT_TRACE5(( "unavailable\n" ));
- continue;
- }
- error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
- if ( error || glyph->outline.n_points <= 0 )
+ for ( nn = 0; nn < outline.n_contours; first = last + 1, nn++ )
{
- FT_TRACE5(( "no outline\n" ));
- continue;
- }
+ FT_Int pp;
- /* now compute min or max point indices and coordinates */
- points = glyph->outline.points;
- best_point = -1;
- best_pos = 0; /* make compiler happy */
- {
- FT_Int nn;
- FT_Int first = 0;
- FT_Int last = -1;
+ last = outline.contours[nn];
+ /* Avoid single-point contours since they are never rasterized. */
+ /* In some fonts, they correspond to mark attachment points */
+ /* which are way outside of the glyph's real outline. */
+ if ( last <= first )
+ continue;
- for ( nn = 0;
- nn < glyph->outline.n_contours;
- first = last + 1, nn++ )
+ if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
{
- FT_Int pp;
-
-
- last = glyph->outline.contours[nn];
-
- /* Avoid single-point contours since they are never */
- /* rasterized. In some fonts, they correspond to mark */
- /* attachment points which are way outside of the glyph's */
- /* real outline. */
- if ( last <= first )
- continue;
-
- switch ( bb )
+ if ( AF_CJK_IS_RIGHT_BLUE( bs ) )
{
- case AF_CJK_BLUE_TOP:
for ( pp = first; pp <= last; pp++ )
- if ( best_point < 0 || points[pp].y > best_pos )
+ if ( best_point < 0 || points[pp].x > best_pos )
{
best_point = pp;
- best_pos = points[pp].y;
+ best_pos = points[pp].x;
}
- break;
-
- case AF_CJK_BLUE_BOTTOM:
+ }
+ else
+ {
for ( pp = first; pp <= last; pp++ )
- if ( best_point < 0 || points[pp].y < best_pos )
+ if ( best_point < 0 || points[pp].x < best_pos )
{
best_point = pp;
- best_pos = points[pp].y;
+ best_pos = points[pp].x;
}
- break;
-
- case AF_CJK_BLUE_LEFT:
+ }
+ }
+ else
+ {
+ if ( AF_CJK_IS_TOP_BLUE( bs ) )
+ {
for ( pp = first; pp <= last; pp++ )
- if ( best_point < 0 || points[pp].x < best_pos )
+ if ( best_point < 0 || points[pp].y > best_pos )
{
best_point = pp;
- best_pos = points[pp].x;
+ best_pos = points[pp].y;
}
- break;
-
- case AF_CJK_BLUE_RIGHT:
+ }
+ else
+ {
for ( pp = first; pp <= last; pp++ )
- if ( best_point < 0 || points[pp].x > best_pos )
+ if ( best_point < 0 || points[pp].y < best_pos )
{
best_point = pp;
- best_pos = points[pp].x;
+ best_pos = points[pp].y;
}
- break;
-
- default:
- ;
}
}
- FT_TRACE5(( "best_pos=%5ld\n", best_pos ));
}
- if ( fill )
- fills[num_fills++] = best_pos;
- else
- flats[num_flats++] = best_pos;
+ FT_TRACE5(( " U+%04lX: best_pos = %5ld\n", ch, best_pos ));
}
+
+ if ( AF_CJK_IS_FILLED_BLUE( bs ) )
+ fills[num_fills++] = best_pos;
+ else
+ flats[num_flats++] = best_pos;
}
if ( num_flats == 0 && num_fills == 0 )
@@ -436,34 +429,30 @@
* we couldn't find a single glyph to compute this blue zone,
* we will simply ignore it then
*/
- FT_TRACE5(( "empty\n" ));
+ FT_TRACE5(( " empty\n" ));
continue;
}
/* we have computed the contents of the `fill' and `flats' tables, */
- /* now determine the reference position of the blue -- */
+ /* now determine the reference position of the blue zone -- */
/* we simply take the median value after a simple sort */
af_sort_pos( num_flats, flats );
af_sort_pos( num_fills, fills );
- if ( AF_CJK_BLUE_TOP == bb || AF_CJK_BLUE_BOTTOM == bb )
- axis = &metrics->axis[AF_DIMENSION_VERT];
- else
- axis = &metrics->axis[AF_DIMENSION_HORZ];
-
- blue = & axis->blues[axis->blue_count];
- blue_ref = & blue->ref.org;
- blue_shoot = & blue->shoot.org;
+ blue = &axis->blues[axis->blue_count];
+ blue_ref = &blue->ref.org;
+ blue_shoot = &blue->shoot.org;
axis->blue_count++;
+
if ( num_flats == 0 )
{
- *blue_ref = fills[num_fills / 2];
+ *blue_ref =
*blue_shoot = fills[num_fills / 2];
}
else if ( num_fills == 0 )
{
- *blue_ref = flats[num_flats / 2];
+ *blue_ref =
*blue_shoot = flats[num_flats / 2];
}
else
@@ -481,26 +470,34 @@
FT_Bool under_ref = FT_BOOL( shoot < ref );
- if ( ( AF_CJK_BLUE_TOP == bb ||
- AF_CJK_BLUE_RIGHT == bb ) ^ under_ref )
- *blue_shoot = *blue_ref = ( shoot + ref ) / 2;
+ /* AF_CJK_IS_TOP_BLUE covers `right' and `top' */
+ if ( AF_CJK_IS_TOP_BLUE( bs ) ^ under_ref )
+ {
+ *blue_ref =
+ *blue_shoot = ( shoot + ref ) / 2;
+
+ FT_TRACE5(( " [overshoot smaller than reference,"
+ " taking mean value]\n" ));
+ }
}
blue->flags = 0;
- if ( AF_CJK_BLUE_TOP == bb )
- blue->flags |= AF_CJK_BLUE_IS_TOP;
- else if ( AF_CJK_BLUE_RIGHT == bb )
- blue->flags |= AF_CJK_BLUE_IS_RIGHT;
+ if ( AF_CJK_IS_TOP_BLUE( bs ) )
+ blue->flags |= AF_CJK_BLUE_TOP;
- FT_TRACE5(( "-- cjk %s bluezone ref = %ld shoot = %ld\n",
- cjk_blue_name[bb], *blue_ref, *blue_shoot ));
+ FT_TRACE5(( " -> reference = %ld\n"
+ " overshoot = %ld\n",
+ *blue_ref, *blue_shoot ));
}
+ FT_TRACE5(( "\n" ));
+
return;
}
/* Basically the Latin version with type AF_CJKMetrics for metrics. */
+
FT_LOCAL_DEF( void )
af_cjk_metrics_check_digits( AF_CJKMetrics metrics,
FT_Face face )
@@ -510,14 +507,14 @@
FT_Fixed advance, old_advance = 0;
- /* check whether all ASCII digits have the same advance width; */
- /* digit `0' is 0x30 in all supported charmaps */
+ /* digit `0' is 0x30 in all supported charmaps */
for ( i = 0x30; i <= 0x39; i++ )
{
- FT_UInt glyph_index;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
- glyph_index = FT_Get_Char_Index( face, i );
+ af_get_char_index( &metrics->root, i, &glyph_index, &y_offset );
if ( glyph_index == 0 )
continue;
@@ -547,6 +544,8 @@
}
+ /* Initialize global metrics. */
+
FT_LOCAL_DEF( FT_Error )
af_cjk_metrics_init( AF_CJKMetrics metrics,
FT_Face face )
@@ -556,21 +555,21 @@
metrics->units_per_em = face->units_per_EM;
- if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
- face->charmap = NULL;
- else
+ if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
{
af_cjk_metrics_init_widths( metrics, face );
- af_cjk_metrics_init_blues( metrics, face, af_cjk_hani_blue_chars );
+ af_cjk_metrics_init_blues( metrics, face );
af_cjk_metrics_check_digits( metrics, face );
}
FT_Set_Charmap( face, oldmap );
-
return FT_Err_Ok;
}
+ /* Adjust scaling value, then scale and shift widths */
+ /* and blue zones (if applicable) for given dimension. */
+
static void
af_cjk_metrics_scale_dim( AF_CJKMetrics metrics,
AF_Scaler scaler,
@@ -582,8 +581,6 @@
FT_UInt nn;
- axis = &metrics->axis[dim];
-
if ( dim == AF_DIMENSION_HORZ )
{
scale = scaler->x_scale;
@@ -595,6 +592,8 @@
delta = scaler->y_delta;
}
+ axis = &metrics->axis[dim];
+
if ( axis->org_scale == scale && axis->org_delta == delta )
return;
@@ -650,12 +649,13 @@
blue->shoot.fit = blue->ref.fit - delta2;
- FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]: "
- "ref: cur=%.2f fit=%.2f shoot: cur=%.2f fit=%.2f\n",
- ( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V',
- nn, blue->ref.org, blue->shoot.org,
- blue->ref.cur / 64.0, blue->ref.fit / 64.0,
- blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
+ FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]:\n"
+ " ref: cur=%.2f fit=%.2f\n"
+ " shoot: cur=%.2f fit=%.2f\n",
+ ( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V',
+ nn, blue->ref.org, blue->shoot.org,
+ blue->ref.cur / 64.0, blue->ref.fit / 64.0,
+ blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
blue->flags |= AF_CJK_BLUE_ACTIVE;
}
@@ -663,10 +663,14 @@
}
+ /* Scale global values in both directions. */
+
FT_LOCAL_DEF( void )
af_cjk_metrics_scale( AF_CJKMetrics metrics,
AF_Scaler scaler )
{
+ /* we copy the whole structure since the x and y scaling values */
+ /* are not modified, contrary to e.g. the `latin' auto-hinter */
metrics->root.scaler = *scaler;
af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
@@ -682,6 +686,9 @@
/*************************************************************************/
/*************************************************************************/
+
+ /* Walk over all contours and compute its segments. */
+
static FT_Error
af_cjk_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim )
@@ -938,7 +945,7 @@
for ( seg = segments; seg < segment_limit; seg++ )
{
- AF_Edge found = 0;
+ AF_Edge found = NULL;
FT_Pos best = 0xFFFFU;
FT_Int ee;
@@ -1026,25 +1033,26 @@
}
}
- /*********************************************************************/
- /* */
- /* Good, we now compute each edge's properties according to segments */
- /* found on its position. Basically, these are as follows. */
- /* */
- /* - edge's main direction */
- /* - stem edge, serif edge or both (which defaults to stem then) */
- /* - rounded edge, straight or both (which defaults to straight) */
- /* - link for edge */
- /* */
- /*********************************************************************/
-
- /* first of all, set the `edge' field in each segment -- this is */
- /* required in order to compute edge links */
- /* */
- /* Note that removing this loop and setting the `edge' field of each */
- /* segment directly in the code above slows down execution speed for */
- /* some reasons on platforms like the Sun. */
+ /******************************************************************/
+ /* */
+ /* Good, we now compute each edge's properties according to the */
+ /* segments found on its position. Basically, these are */
+ /* */
+ /* - the edge's main direction */
+ /* - stem edge, serif edge or both (which defaults to stem then) */
+ /* - rounded edge, straight or both (which defaults to straight) */
+ /* - link for edge */
+ /* */
+ /******************************************************************/
+
+ /* first of all, set the `edge' field in each segment -- this is */
+ /* required in order to compute edge links */
+ /*
+ * Note that removing this loop and setting the `edge' field of each
+ * segment directly in the code above slows down execution speed for
+ * some reasons on platforms like the Sun.
+ */
{
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
@@ -1153,6 +1161,8 @@
}
+ /* Detect segments and edges for given dimension. */
+
static FT_Error
af_cjk_hints_detect_features( AF_GlyphHints hints,
AF_Dimension dim )
@@ -1171,6 +1181,8 @@
}
+ /* Compute all edges which lie within blue zones. */
+
FT_LOCAL_DEF( void )
af_cjk_hints_compute_blue_edges( AF_GlyphHints hints,
AF_CJKMetrics metrics,
@@ -1218,10 +1230,8 @@
/* zone, check for left edges */
/* */
/* of course, that's for TrueType */
- is_top_right_blue =
- FT_BOOL( ( ( blue->flags & AF_CJK_BLUE_IS_TOP ) != 0 ) ||
- ( ( blue->flags & AF_CJK_BLUE_IS_RIGHT ) != 0 ) );
- is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
+ is_top_right_blue = FT_BOOL( blue->flags & AF_CJK_BLUE_TOP );
+ is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
/* if it is a top zone, the edge must be against the major */
/* direction; if it is a bottom zone, it must be in the major */
@@ -1258,6 +1268,8 @@
}
+ /* Initalize hinting engine. */
+
FT_LOCAL_DEF( FT_Error )
af_cjk_hints_init( AF_GlyphHints hints,
AF_CJKMetrics metrics )
@@ -1266,7 +1278,7 @@
FT_UInt32 scaler_flags, other_flags;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale when needed, since they may have
@@ -1316,7 +1328,7 @@
hints->scaler_flags = scaler_flags;
hints->other_flags = other_flags;
- return 0;
+ return FT_Err_Ok;
}
@@ -1328,8 +1340,8 @@
/*************************************************************************/
/*************************************************************************/
- /* snap a given width in scaled coordinates to one of the */
- /* current standard widths */
+ /* Snap a given width in scaled coordinates to one of the */
+ /* current standard widths. */
static FT_Pos
af_cjk_snap_width( AF_Width widths,
@@ -1376,7 +1388,9 @@
}
- /* compute the snapped width of a given stem */
+ /* Compute the snapped width of a given stem. */
+ /* There is a lot of voodoo in this function; changing the hard-coded */
+ /* parameters influence the whole hinting process. */
static FT_Pos
af_cjk_compute_stem_width( AF_GlyphHints hints,
@@ -1385,8 +1399,8 @@
AF_Edge_Flags base_flags,
AF_Edge_Flags stem_flags )
{
- AF_CJKMetrics metrics = (AF_CJKMetrics) hints->metrics;
- AF_CJKAxis axis = & metrics->axis[dim];
+ AF_CJKMetrics metrics = (AF_CJKMetrics)hints->metrics;
+ AF_CJKAxis axis = &metrics->axis[dim];
FT_Pos dist = width;
FT_Int sign = 0;
FT_Bool vertical = FT_BOOL( dim == AF_DIMENSION_VERT );
@@ -1497,7 +1511,7 @@
}
- /* align one stem edge relative to the previous stem edge */
+ /* Align one stem edge relative to the previous stem edge. */
static void
af_cjk_align_linked_edge( AF_GlyphHints hints,
@@ -1517,6 +1531,9 @@
}
+ /* Shift the coordinates of the `serif' edge by the same amount */
+ /* as the corresponding `base' edge has been moved already. */
+
static void
af_cjk_align_serif_edge( AF_GlyphHints hints,
AF_Edge base,
@@ -1670,6 +1687,8 @@
}
+ /* The main grid-fitting routine. */
+
static void
af_cjk_hint_edges( AF_GlyphHints hints,
AF_Dimension dim )
@@ -1685,10 +1704,16 @@
FT_Bool has_last_stem = FALSE;
FT_Pos last_stem_pos = 0;
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_UInt num_actions = 0;
+#endif
+
+
+ FT_TRACE5(( "cjk %s edge hinting (style `%s')\n",
+ dim == AF_DIMENSION_VERT ? "horizontal" : "vertical",
+ af_style_names[hints->metrics->style_class->style] ));
/* we begin by aligning all stems relative to the blue zone */
- FT_TRACE5(( "==== cjk hinting %s edges =====\n",
- dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ));
if ( AF_HINTS_DO_BLUES( hints ) )
{
@@ -1719,10 +1744,14 @@
if ( !edge1 )
continue;
- FT_TRACE5(( "CJKBLUE: edge %d @%d (opos=%.2f) snapped to (%.2f), "
- "was (%.2f)\n",
- edge1-edges, edge1->fpos, edge1->opos / 64.0, blue->fit / 64.0,
- edge1->pos / 64.0 ));
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_TRACE5(( " CJKBLUE: edge %d @%d (opos=%.2f) snapped to %.2f,"
+ " was %.2f\n",
+ edge1 - edges, edge1->fpos, edge1->opos / 64.0,
+ blue->fit / 64.0, edge1->pos / 64.0 ));
+
+ num_actions++;
+#endif
edge1->pos = blue->fit;
edge1->flags |= AF_EDGE_DONE;
@@ -1731,6 +1760,10 @@
{
af_cjk_align_linked_edge( hints, dim, edge1, edge2 );
edge2->flags |= AF_EDGE_DONE;
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ num_actions++;
+#endif
}
if ( !anchor )
@@ -1772,6 +1805,7 @@
}
/* now align the stem */
+
/* this should not happen, but it's better to be safe */
if ( edge2->blue_edge )
{
@@ -1779,6 +1813,11 @@
af_cjk_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ num_actions++;
+#endif
+
continue;
}
@@ -1786,6 +1825,11 @@
{
af_cjk_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ num_actions++;
+#endif
+
/* We rarely reaches here it seems;
* usually the two edges belonging
* to one stem are marked as DONE together
@@ -1953,7 +1997,7 @@
}
if ( !skipped )
- return;
+ goto Exit;
/*
* now hint the remaining edges (serifs and single) in order
@@ -1973,7 +2017,7 @@
}
if ( !skipped )
- return;
+ goto Exit;
for ( edge = edges; edge < edge_limit; edge++ )
{
@@ -2011,6 +2055,16 @@
}
}
}
+
+ Exit:
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( !num_actions )
+ FT_TRACE5(( " (none)\n" ));
+ FT_TRACE5(( "\n" ));
+#endif
+
+ return;
}
@@ -2104,6 +2158,8 @@
}
+ /* Apply the complete hinting algorithm to a CJK glyph. */
+
FT_LOCAL_DEF( FT_Error )
af_cjk_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
@@ -2191,84 +2247,41 @@
/*************************************************************************/
- /* this corresponds to Unicode 6.0 */
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_cjk_writing_system_class,
- static const AF_Script_UniRangeRec af_cjk_uniranges[] =
- {
- AF_UNIRANGE_REC( 0x1100UL, 0x11FFUL ), /* Hangul Jamo */
- AF_UNIRANGE_REC( 0x2E80UL, 0x2EFFUL ), /* CJK Radicals Supplement */
- AF_UNIRANGE_REC( 0x2F00UL, 0x2FDFUL ), /* Kangxi Radicals */
- AF_UNIRANGE_REC( 0x2FF0UL, 0x2FFFUL ), /* Ideographic Description Characters */
- AF_UNIRANGE_REC( 0x3000UL, 0x303FUL ), /* CJK Symbols and Punctuation */
- AF_UNIRANGE_REC( 0x3040UL, 0x309FUL ), /* Hiragana */
- AF_UNIRANGE_REC( 0x30A0UL, 0x30FFUL ), /* Katakana */
- AF_UNIRANGE_REC( 0x3100UL, 0x312FUL ), /* Bopomofo */
- AF_UNIRANGE_REC( 0x3130UL, 0x318FUL ), /* Hangul Compatibility Jamo */
- AF_UNIRANGE_REC( 0x3190UL, 0x319FUL ), /* Kanbun */
- AF_UNIRANGE_REC( 0x31A0UL, 0x31BFUL ), /* Bopomofo Extended */
- AF_UNIRANGE_REC( 0x31C0UL, 0x31EFUL ), /* CJK Strokes */
- AF_UNIRANGE_REC( 0x31F0UL, 0x31FFUL ), /* Katakana Phonetic Extensions */
- AF_UNIRANGE_REC( 0x3200UL, 0x32FFUL ), /* Enclosed CJK Letters and Months */
- AF_UNIRANGE_REC( 0x3300UL, 0x33FFUL ), /* CJK Compatibility */
- AF_UNIRANGE_REC( 0x3400UL, 0x4DBFUL ), /* CJK Unified Ideographs Extension A */
- AF_UNIRANGE_REC( 0x4DC0UL, 0x4DFFUL ), /* Yijing Hexagram Symbols */
- AF_UNIRANGE_REC( 0x4E00UL, 0x9FFFUL ), /* CJK Unified Ideographs */
- AF_UNIRANGE_REC( 0xA960UL, 0xA97FUL ), /* Hangul Jamo Extended-A */
- AF_UNIRANGE_REC( 0xAC00UL, 0xD7AFUL ), /* Hangul Syllables */
- AF_UNIRANGE_REC( 0xD7B0UL, 0xD7FFUL ), /* Hangul Jamo Extended-B */
- AF_UNIRANGE_REC( 0xF900UL, 0xFAFFUL ), /* CJK Compatibility Ideographs */
- AF_UNIRANGE_REC( 0xFE10UL, 0xFE1FUL ), /* Vertical forms */
- AF_UNIRANGE_REC( 0xFE30UL, 0xFE4FUL ), /* CJK Compatibility Forms */
- AF_UNIRANGE_REC( 0xFF00UL, 0xFFEFUL ), /* Halfwidth and Fullwidth Forms */
- AF_UNIRANGE_REC( 0x1B000UL, 0x1B0FFUL ), /* Kana Supplement */
- AF_UNIRANGE_REC( 0x1D300UL, 0x1D35FUL ), /* Tai Xuan Hing Symbols */
- AF_UNIRANGE_REC( 0x1F200UL, 0x1F2FFUL ), /* Enclosed Ideographic Supplement */
- AF_UNIRANGE_REC( 0x20000UL, 0x2A6DFUL ), /* CJK Unified Ideographs Extension B */
- AF_UNIRANGE_REC( 0x2A700UL, 0x2B73FUL ), /* CJK Unified Ideographs Extension C */
- AF_UNIRANGE_REC( 0x2B740UL, 0x2B81FUL ), /* CJK Unified Ideographs Extension D */
- AF_UNIRANGE_REC( 0x2F800UL, 0x2FA1FUL ), /* CJK Compatibility Ideographs Supplement */
- AF_UNIRANGE_REC( 0UL, 0UL )
- };
-
-
- AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
- AF_SCRIPT_CJK,
- af_cjk_uniranges,
- 0x7530, /* 田 */
+ AF_WRITING_SYSTEM_CJK,
sizeof ( AF_CJKMetricsRec ),
- (AF_Script_InitMetricsFunc) af_cjk_metrics_init,
- (AF_Script_ScaleMetricsFunc)af_cjk_metrics_scale,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) af_cjk_metrics_init,
+ (AF_WritingSystem_ScaleMetricsFunc)af_cjk_metrics_scale,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) af_cjk_hints_init,
- (AF_Script_ApplyHintsFunc) af_cjk_hints_apply
+ (AF_WritingSystem_InitHintsFunc) af_cjk_hints_init,
+ (AF_WritingSystem_ApplyHintsFunc) af_cjk_hints_apply
)
+
#else /* !AF_CONFIG_OPTION_CJK */
- static const AF_Script_UniRangeRec af_cjk_uniranges[] =
- {
- AF_UNIRANGE_REC( 0UL, 0UL )
- };
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_cjk_writing_system_class,
- AF_DEFINE_SCRIPT_CLASS( af_cjk_script_class,
- AF_SCRIPT_CJK,
- af_cjk_uniranges,
- 0,
+ AF_WRITING_SYSTEM_CJK,
sizeof ( AF_CJKMetricsRec ),
- (AF_Script_InitMetricsFunc) NULL,
- (AF_Script_ScaleMetricsFunc)NULL,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) NULL,
+ (AF_WritingSystem_ScaleMetricsFunc)NULL,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) NULL,
- (AF_Script_ApplyHintsFunc) NULL
+ (AF_WritingSystem_InitHintsFunc) NULL,
+ (AF_WritingSystem_ApplyHintsFunc) NULL
)
+
#endif /* !AF_CONFIG_OPTION_CJK */
diff --git a/freetype/src/autofit/afcjk.h b/freetype/src/autofit/afcjk.h
index ab816f20b..a260b0911 100644
--- a/freetype/src/autofit/afcjk.h
+++ b/freetype/src/autofit/afcjk.h
@@ -2,9 +2,9 @@
/* */
/* afcjk.h */
/* */
-/* Auto-fitter hinting routines for CJK script (specification). */
+/* Auto-fitter hinting routines for CJK writing system (specification). */
/* */
-/* Copyright 2006, 2007, 2011, 2012 by */
+/* Copyright 2006, 2007, 2011-2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -26,39 +26,43 @@
FT_BEGIN_HEADER
- /* the CJK-specific script class */
+ /* the CJK-specific writing system */
- AF_DECLARE_SCRIPT_CLASS( af_cjk_script_class )
+ AF_DECLARE_WRITING_SYSTEM_CLASS( af_cjk_writing_system_class )
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** C J K G L O B A L M E T R I C S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
- /* CJK (global) metrics management */
/*
* CJK glyphs tend to fill the square. So we have both vertical and
* horizontal blue zones. But some glyphs have flat bounding strokes that
* leave some space between neighbour glyphs.
*/
- enum
- {
- AF_CJK_BLUE_TOP,
- AF_CJK_BLUE_BOTTOM,
- AF_CJK_BLUE_LEFT,
- AF_CJK_BLUE_RIGHT,
-
- AF_CJK_BLUE_MAX
- };
+#define AF_CJK_IS_TOP_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_CJK_TOP )
+#define AF_CJK_IS_HORIZ_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_CJK_HORIZ )
+#define AF_CJK_IS_FILLED_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_CJK_FILL )
+#define AF_CJK_IS_RIGHT_BLUE AF_CJK_IS_TOP_BLUE
#define AF_CJK_MAX_WIDTHS 16
-#define AF_CJK_MAX_BLUES AF_CJK_BLUE_MAX
enum
{
- AF_CJK_BLUE_ACTIVE = 1 << 0,
- AF_CJK_BLUE_IS_TOP = 1 << 1,
- AF_CJK_BLUE_IS_RIGHT = 1 << 2,
- AF_CJK_BLUE_ADJUSTMENT = 1 << 3, /* used for scale adjustment */
- /* optimization */
+ AF_CJK_BLUE_ACTIVE = 1 << 0, /* set if zone height is <= 3/4px */
+ AF_CJK_BLUE_TOP = 1 << 1, /* result of AF_CJK_IS_TOP_BLUE */
+ AF_CJK_BLUE_ADJUSTMENT = 1 << 2, /* used for scale adjustment */
+ /* optimization */
AF_CJK_BLUE_FLAG_MAX
};
@@ -77,16 +81,16 @@ FT_BEGIN_HEADER
FT_Fixed scale;
FT_Pos delta;
- FT_UInt width_count;
- AF_WidthRec widths[AF_CJK_MAX_WIDTHS];
- FT_Pos edge_distance_threshold;
- FT_Pos standard_width;
- FT_Bool extra_light;
+ FT_UInt width_count; /* number of used widths */
+ AF_WidthRec widths[AF_CJK_MAX_WIDTHS]; /* widths array */
+ FT_Pos edge_distance_threshold; /* used for creating edges */
+ FT_Pos standard_width; /* the default stem thickness */
+ FT_Bool extra_light; /* is standard width very light? */
/* used for horizontal metrics too for CJK */
FT_Bool control_overshoot;
FT_UInt blue_count;
- AF_CJKBlueRec blues[AF_CJK_BLUE_MAX];
+ AF_CJKBlueRec blues[AF_BLUE_STRINGSET_MAX];
FT_Fixed org_scale;
FT_Pos org_delta;
@@ -96,9 +100,9 @@ FT_BEGIN_HEADER
typedef struct AF_CJKMetricsRec_
{
- AF_ScriptMetricsRec root;
- FT_UInt units_per_em;
- AF_CJKAxisRec axis[AF_DIMENSION_MAX];
+ AF_StyleMetricsRec root;
+ FT_UInt units_per_em;
+ AF_CJKAxisRec axis[AF_DIMENSION_MAX];
} AF_CJKMetricsRec, *AF_CJKMetrics;
diff --git a/freetype/src/autofit/afcover.h b/freetype/src/autofit/afcover.h
new file mode 100644
index 000000000..d5ac96944
--- /dev/null
+++ b/freetype/src/autofit/afcover.h
@@ -0,0 +1,105 @@
+/***************************************************************************/
+/* */
+/* afcover.h */
+/* */
+/* Auto-fitter coverages (specification only). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+ /* This header file can be included multiple times. */
+ /* Define `COVERAGE' as needed. */
+
+
+ /* Add new coverages here. The first and second arguments are the */
+ /* coverage name in lowercase and uppercase, respectively, followed */
+ /* by a description string. The last four arguments are the four */
+ /* characters defining the corresponding OpenType feature. */
+
+#if 0
+ /* XXX: It's not possible to define blue zone characters in advance. */
+ COVERAGE( alternative_fractions, ALTERNATIVE_FRACTIONS,
+ "alternative fractions",
+ 'a', 'f', 'r', 'c' )
+#endif
+
+ COVERAGE( petite_capitals_from_capitals, PETITE_CAPITALS_FROM_CAPITALS,
+ "petite capitals from capitals",
+ 'c', '2', 'c', 'p' )
+
+ COVERAGE( small_capitals_from_capitals, SMALL_CAPITALS_FROM_CAPITALS,
+ "small capitals from capitals",
+ 'c', '2', 's', 'c' )
+
+#if 0
+ /* XXX: Only digits are in this coverage, however, both normal style */
+ /* and oldstyle representation forms are possible. */
+ COVERAGE( denominators, DENOMINATORS,
+ "denominators",
+ 'd', 'n', 'o', 'm' )
+#endif
+
+#if 0
+ /* XXX: It's not possible to define blue zone characters in advance. */
+ COVERAGE( fractions, FRACTIONS,
+ "fractions",
+ 'f', 'r', 'a', 'c' )
+#endif
+
+#if 0
+ /* XXX: Only digits are in this coverage, however, both normal style */
+ /* and oldstyle representation forms are possible. */
+ COVERAGE( numerators, NUMERATORS,
+ "numerators",
+ 'n', 'u', 'm', 'r' )
+#endif
+
+ COVERAGE( ordinals, ORDINALS,
+ "ordinals",
+ 'o', 'r', 'd', 'n' )
+
+ COVERAGE( petite_capitals, PETITE_CAPITALS,
+ "petite capitals",
+ 'p', 'c', 'a', 'p' )
+
+ COVERAGE( ruby, RUBY,
+ "ruby",
+ 'r', 'u', 'b', 'y' )
+
+ COVERAGE( scientific_inferiors, SCIENTIFIC_INFERIORS,
+ "scientific inferiors",
+ 's', 'i', 'n', 'f' )
+
+ COVERAGE( small_capitals, SMALL_CAPITALS,
+ "small capitals",
+ 's', 'm', 'c', 'p' )
+
+ COVERAGE( subscript, SUBSCRIPT,
+ "subscript",
+ 's', 'u', 'b', 's' )
+
+ COVERAGE( superscript, SUPERSCRIPT,
+ "superscript",
+ 's', 'u', 'p', 's' )
+
+ COVERAGE( titling, TITLING,
+ "titling",
+ 't', 'i', 't', 'l' )
+
+#if 0
+ /* to be always excluded */
+ COVERAGE(nalt, 'n', 'a', 'l', 't'); /* Alternate Annotation Forms (?) */
+ COVERAGE(ornm, 'o', 'r', 'n', 'm'); /* Ornaments (?) */
+#endif
+
+
+/* END */
diff --git a/freetype/src/autofit/afdummy.c b/freetype/src/autofit/afdummy.c
index 22944559d..f8702a109 100644
--- a/freetype/src/autofit/afdummy.c
+++ b/freetype/src/autofit/afdummy.c
@@ -23,11 +23,16 @@
static FT_Error
- af_dummy_hints_init( AF_GlyphHints hints,
- AF_ScriptMetrics metrics )
+ af_dummy_hints_init( AF_GlyphHints hints,
+ AF_StyleMetrics metrics )
{
- af_glyph_hints_rescale( hints,
- metrics );
+ af_glyph_hints_rescale( hints, metrics );
+
+ hints->x_scale = metrics->scaler.x_scale;
+ hints->y_scale = metrics->scaler.y_scale;
+ hints->x_delta = metrics->scaler.x_delta;
+ hints->y_delta = metrics->scaler.y_delta;
+
return FT_Err_Ok;
}
@@ -36,26 +41,30 @@
af_dummy_hints_apply( AF_GlyphHints hints,
FT_Outline* outline )
{
- FT_UNUSED( hints );
- FT_UNUSED( outline );
+ FT_Error error;
- return FT_Err_Ok;
+
+ error = af_glyph_hints_reload( hints, outline );
+ if ( !error )
+ af_glyph_hints_save( hints, outline );
+
+ return error;
}
- AF_DEFINE_SCRIPT_CLASS( af_dummy_script_class,
- AF_SCRIPT_DUMMY,
- NULL,
- 0,
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_dummy_writing_system_class,
+
+ AF_WRITING_SYSTEM_DUMMY,
- sizeof ( AF_ScriptMetricsRec ),
+ sizeof ( AF_StyleMetricsRec ),
- (AF_Script_InitMetricsFunc) NULL,
- (AF_Script_ScaleMetricsFunc)NULL,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) NULL,
+ (AF_WritingSystem_ScaleMetricsFunc)NULL,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) af_dummy_hints_init,
- (AF_Script_ApplyHintsFunc) af_dummy_hints_apply
+ (AF_WritingSystem_InitHintsFunc) af_dummy_hints_init,
+ (AF_WritingSystem_ApplyHintsFunc) af_dummy_hints_apply
)
diff --git a/freetype/src/autofit/afdummy.h b/freetype/src/autofit/afdummy.h
index 95d8f8cf1..ad1b0d3ab 100644
--- a/freetype/src/autofit/afdummy.h
+++ b/freetype/src/autofit/afdummy.h
@@ -5,7 +5,7 @@
/* Auto-fitter dummy routines to be used if no hinting should be */
/* performed (specification). */
/* */
-/* Copyright 2003-2005, 2011 by */
+/* Copyright 2003-2005, 2011, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -25,11 +25,9 @@
FT_BEGIN_HEADER
- /* A dummy script metrics class used when no hinting should
- * be performed. This is the default for non-latin glyphs!
- */
+ /* A dummy writing system used when no hinting should be performed. */
- AF_DECLARE_SCRIPT_CLASS( af_dummy_script_class )
+ AF_DECLARE_WRITING_SYSTEM_CLASS( af_dummy_writing_system_class )
/* */
diff --git a/freetype/src/autofit/afglobal.c b/freetype/src/autofit/afglobal.c
index 3e4146575..7aa2e1102 100644
--- a/freetype/src/autofit/afglobal.c
+++ b/freetype/src/autofit/afglobal.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter routines to compute global hinting values (body). */
/* */
-/* Copyright 2003-2013 by */
+/* Copyright 2003-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -17,107 +17,214 @@
#include "afglobal.h"
-#include "afdummy.h"
-#include "aflatin.h"
-#include "afcjk.h"
-#include "afindic.h"
-#include "afpic.h"
+#include "afranges.h"
+#include "hbshim.h"
+#include FT_INTERNAL_DEBUG_H
+
+
+ /*************************************************************************/
+ /* */
+ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
+ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
+ /* messages during execution. */
+ /* */
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_afglobal
+
+
+ /* get writing system specific header files */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) /* empty */
+#include "afwrtsys.h"
#include "aferrors.h"
+#include "afpic.h"
+
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ AF_DEFINE_SCRIPT_CLASS( \
+ af_ ## s ## _script_class, \
+ AF_SCRIPT_ ## S, \
+ af_ ## s ## _uniranges, \
+ sc1, sc2, sc3 )
+
+#include "afscript.h"
+
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ AF_DEFINE_STYLE_CLASS( \
+ af_ ## s ## _style_class, \
+ AF_STYLE_ ## S, \
+ ws, \
+ sc, \
+ ss, \
+ c )
+
+#include "afstyles.h"
-#ifdef FT_OPTION_AUTOFIT2
-#include "aflatin2.h"
-#endif
#ifndef FT_CONFIG_OPTION_PIC
- /* when updating this table, don't forget to update */
- /* AF_SCRIPT_CLASSES_COUNT and autofit_module_class_pic_init */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) \
+ &af_ ## ws ## _writing_system_class,
- /* populate this list when you add new scripts */
- static AF_ScriptClass const af_script_classes[] =
+ FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass )
+ af_writing_system_classes[] =
{
- &af_dummy_script_class,
-#ifdef FT_OPTION_AUTOFIT2
- &af_latin2_script_class,
-#endif
- &af_latin_script_class,
- &af_cjk_script_class,
- &af_indic_script_class,
+
+#include "afwrtsys.h"
+
+ NULL /* do not remove */
+ };
+
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ &af_ ## s ## _script_class,
+
+ FT_LOCAL_ARRAY_DEF( AF_ScriptClass )
+ af_script_classes[] =
+ {
+
+#include "afscript.h"
+
+ NULL /* do not remove */
+ };
+
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ &af_ ## s ## _style_class,
+
+ FT_LOCAL_ARRAY_DEF( AF_StyleClass )
+ af_style_classes[] =
+ {
+
+#include "afstyles.h"
+
NULL /* do not remove */
};
#endif /* !FT_CONFIG_OPTION_PIC */
- /* Compute the script index of each glyph within a given face. */
+#ifdef FT_DEBUG_LEVEL_TRACE
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) #s,
+
+ FT_LOCAL_ARRAY_DEF( char* )
+ af_style_names[] =
+ {
+
+#include "afstyles.h"
+
+ };
+
+#endif /* FT_DEBUG_LEVEL_TRACE */
+
+
+ /* Compute the style index of each glyph within a given face. */
static FT_Error
- af_face_globals_compute_script_coverage( AF_FaceGlobals globals )
+ af_face_globals_compute_style_coverage( AF_FaceGlobals globals )
{
FT_Error error;
FT_Face face = globals->face;
FT_CharMap old_charmap = face->charmap;
- FT_Byte* gscripts = globals->glyph_scripts;
+ FT_Byte* gstyles = globals->glyph_styles;
FT_UInt ss;
FT_UInt i;
+ FT_UInt dflt = -1;
- /* the value AF_SCRIPT_NONE means `uncovered glyph' */
- FT_MEM_SET( globals->glyph_scripts,
- AF_SCRIPT_NONE,
+ /* the value AF_STYLE_UNASSIGNED means `uncovered glyph' */
+ FT_MEM_SET( globals->glyph_styles,
+ AF_STYLE_UNASSIGNED,
globals->glyph_count );
error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
if ( error )
{
- /*
- * Ignore this error; we simply use the fallback script.
- * XXX: Shouldn't we rather disable hinting?
- */
+ /*
+ * Ignore this error; we simply use the fallback style.
+ * XXX: Shouldn't we rather disable hinting?
+ */
error = FT_Err_Ok;
goto Exit;
}
- /* scan each script in a Unicode charmap */
- for ( ss = 0; AF_SCRIPT_CLASSES_GET[ss]; ss++ )
+ /* scan each style in a Unicode charmap */
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
- AF_ScriptClass clazz = AF_SCRIPT_CLASSES_GET[ss];
+ AF_StyleClass style_class =
+ AF_STYLE_CLASSES_GET[ss];
+ AF_ScriptClass script_class =
+ AF_SCRIPT_CLASSES_GET[style_class->script];
AF_Script_UniRange range;
- if ( clazz->script_uni_ranges == NULL )
+ if ( script_class->script_uni_ranges == NULL )
continue;
/*
* Scan all Unicode points in the range and set the corresponding
- * glyph script index.
+ * glyph style index.
*/
- for ( range = clazz->script_uni_ranges; range->first != 0; range++ )
+ if ( style_class->coverage == AF_COVERAGE_DEFAULT )
{
- FT_ULong charcode = range->first;
- FT_UInt gindex;
+ if ( style_class->script == globals->module->default_script )
+ dflt = ss;
+
+ for ( range = script_class->script_uni_ranges;
+ range->first != 0;
+ range++ )
+ {
+ FT_ULong charcode = range->first;
+ FT_UInt gindex;
- gindex = FT_Get_Char_Index( face, charcode );
+ gindex = FT_Get_Char_Index( face, charcode );
- if ( gindex != 0 &&
- gindex < (FT_ULong)globals->glyph_count &&
- gscripts[gindex] == AF_SCRIPT_NONE )
- gscripts[gindex] = (FT_Byte)ss;
+ if ( gindex != 0 &&
+ gindex < (FT_ULong)globals->glyph_count &&
+ gstyles[gindex] == AF_STYLE_UNASSIGNED )
+ gstyles[gindex] = (FT_Byte)ss;
- for (;;)
- {
- charcode = FT_Get_Next_Char( face, charcode, &gindex );
+ for (;;)
+ {
+ charcode = FT_Get_Next_Char( face, charcode, &gindex );
- if ( gindex == 0 || charcode > range->last )
- break;
+ if ( gindex == 0 || charcode > range->last )
+ break;
- if ( gindex < (FT_ULong)globals->glyph_count &&
- gscripts[gindex] == AF_SCRIPT_NONE )
- gscripts[gindex] = (FT_Byte)ss;
+ if ( gindex < (FT_ULong)globals->glyph_count &&
+ gstyles[gindex] == AF_STYLE_UNASSIGNED )
+ gstyles[gindex] = (FT_Byte)ss;
+ }
}
}
+ else
+ {
+ /* get glyphs not directly addressable by cmap */
+ af_get_coverage( globals, style_class, gstyles );
+ }
+ }
+
+ /* handle the default OpenType features of the default script ... */
+ af_get_coverage( globals, AF_STYLE_CLASSES_GET[dflt], gstyles );
+
+ /* ... and the remaining default OpenType features */
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
+ {
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
+
+
+ if ( ss != dflt && style_class->coverage == AF_COVERAGE_DEFAULT )
+ af_get_coverage( globals, style_class, gstyles );
}
/* mark ASCII digits */
@@ -127,29 +234,68 @@
if ( gindex != 0 && gindex < (FT_ULong)globals->glyph_count )
- gscripts[gindex] |= AF_DIGIT;
+ gstyles[gindex] |= AF_DIGIT;
}
Exit:
/*
- * By default, all uncovered glyphs are set to the fallback script.
+ * By default, all uncovered glyphs are set to the fallback style.
* XXX: Shouldn't we disable hinting or do something similar?
*/
- if ( globals->module->fallback_script != AF_SCRIPT_NONE )
+ if ( globals->module->fallback_style != AF_STYLE_UNASSIGNED )
{
FT_Long nn;
for ( nn = 0; nn < globals->glyph_count; nn++ )
{
- if ( ( gscripts[nn] & ~AF_DIGIT ) == AF_SCRIPT_NONE )
+ if ( ( gstyles[nn] & ~AF_DIGIT ) == AF_STYLE_UNASSIGNED )
+ {
+ gstyles[nn] &= ~AF_STYLE_UNASSIGNED;
+ gstyles[nn] |= globals->module->fallback_style;
+ }
+ }
+ }
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+
+ FT_TRACE4(( "\n"
+ "style coverage\n"
+ "==============\n"
+ "\n" ));
+
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
+ {
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
+ FT_UInt count = 0;
+ FT_Long idx;
+
+
+ FT_TRACE4(( "%s:\n", af_style_names[style_class->style] ));
+
+ for ( idx = 0; idx < globals->glyph_count; idx++ )
+ {
+ if ( ( gstyles[idx] & ~AF_DIGIT ) == style_class->style )
{
- gscripts[nn] &= ~AF_SCRIPT_NONE;
- gscripts[nn] |= globals->module->fallback_script;
+ if ( !( count % 10 ) )
+ FT_TRACE4(( " " ));
+
+ FT_TRACE4(( " %d", idx ));
+ count++;
+
+ if ( !( count % 10 ) )
+ FT_TRACE4(( "\n" ));
}
}
+
+ if ( !count )
+ FT_TRACE4(( " (none)\n" ));
+ if ( count % 10 )
+ FT_TRACE4(( "\n" ));
}
+#endif /* FT_DEBUG_LEVEL_TRACE */
+
FT_Set_Charmap( face, old_charmap );
return error;
}
@@ -171,12 +317,16 @@
face->num_glyphs * sizeof ( FT_Byte ) ) )
goto Exit;
- globals->face = face;
- globals->glyph_count = face->num_glyphs;
- globals->glyph_scripts = (FT_Byte*)( globals + 1 );
- globals->module = module;
+ globals->face = face;
+ globals->glyph_count = face->num_glyphs;
+ globals->glyph_styles = (FT_Byte*)( globals + 1 );
+ globals->module = module;
- error = af_face_globals_compute_script_coverage( globals );
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ globals->hb_font = hb_ft_font_create( face, NULL );
+#endif
+
+ error = af_face_globals_compute_style_coverage( globals );
if ( error )
{
af_face_globals_free( globals );
@@ -200,25 +350,31 @@
FT_UInt nn;
- for ( nn = 0; nn < AF_SCRIPT_MAX; nn++ )
+ for ( nn = 0; nn < AF_STYLE_MAX; nn++ )
{
if ( globals->metrics[nn] )
{
- AF_ScriptClass clazz = AF_SCRIPT_CLASSES_GET[nn];
-
+ AF_StyleClass style_class =
+ AF_STYLE_CLASSES_GET[nn];
+ AF_WritingSystemClass writing_system_class =
+ AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
- FT_ASSERT( globals->metrics[nn]->clazz == clazz );
- if ( clazz->script_metrics_done )
- clazz->script_metrics_done( globals->metrics[nn] );
+ if ( writing_system_class->style_metrics_done )
+ writing_system_class->style_metrics_done( globals->metrics[nn] );
FT_FREE( globals->metrics[nn] );
}
}
- globals->glyph_count = 0;
- globals->glyph_scripts = NULL; /* no need to free this one! */
- globals->face = NULL;
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ hb_font_destroy( globals->hb_font );
+ globals->hb_font = NULL;
+#endif
+
+ globals->glyph_count = 0;
+ globals->glyph_styles = NULL; /* no need to free this one! */
+ globals->face = NULL;
FT_FREE( globals );
}
@@ -226,18 +382,18 @@
FT_LOCAL_DEF( FT_Error )
- af_face_globals_get_metrics( AF_FaceGlobals globals,
- FT_UInt gindex,
- FT_UInt options,
- AF_ScriptMetrics *ametrics )
+ af_face_globals_get_metrics( AF_FaceGlobals globals,
+ FT_UInt gindex,
+ FT_UInt options,
+ AF_StyleMetrics *ametrics )
{
- AF_ScriptMetrics metrics = NULL;
- FT_UInt gidx;
- AF_ScriptClass clazz;
- FT_UInt script = options & 15;
- const FT_Offset script_max = sizeof ( AF_SCRIPT_CLASSES_GET ) /
- sizeof ( AF_SCRIPT_CLASSES_GET[0] );
- FT_Error error = FT_Err_Ok;
+ AF_StyleMetrics metrics = NULL;
+
+ AF_Style style = (AF_Style)options;
+ AF_WritingSystemClass writing_system_class;
+ AF_StyleClass style_class;
+
+ FT_Error error = FT_Err_Ok;
if ( gindex >= (FT_ULong)globals->glyph_count )
@@ -246,41 +402,44 @@
goto Exit;
}
- gidx = script;
- if ( gidx == 0 || gidx + 1 >= script_max )
- gidx = globals->glyph_scripts[gindex] & AF_SCRIPT_NONE;
+ /* if we have a forced style (via `options'), use it, */
+ /* otherwise look into `glyph_styles' array */
+ if ( style == AF_STYLE_NONE_DFLT || style + 1 >= AF_STYLE_MAX )
+ style = (AF_Style)( globals->glyph_styles[gindex] &
+ AF_STYLE_UNASSIGNED );
- clazz = AF_SCRIPT_CLASSES_GET[gidx];
- if ( script == 0 )
- script = clazz->script;
+ style_class = AF_STYLE_CLASSES_GET[style];
+ writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
+ [style_class->writing_system];
- metrics = globals->metrics[clazz->script];
+ metrics = globals->metrics[style];
if ( metrics == NULL )
{
/* create the global metrics object if necessary */
FT_Memory memory = globals->face->memory;
- if ( FT_ALLOC( metrics, clazz->script_metrics_size ) )
+ if ( FT_ALLOC( metrics, writing_system_class->style_metrics_size ) )
goto Exit;
- metrics->clazz = clazz;
- metrics->globals = globals;
+ metrics->style_class = style_class;
+ metrics->globals = globals;
- if ( clazz->script_metrics_init )
+ if ( writing_system_class->style_metrics_init )
{
- error = clazz->script_metrics_init( metrics, globals->face );
+ error = writing_system_class->style_metrics_init( metrics,
+ globals->face );
if ( error )
{
- if ( clazz->script_metrics_done )
- clazz->script_metrics_done( metrics );
+ if ( writing_system_class->style_metrics_done )
+ writing_system_class->style_metrics_done( metrics );
FT_FREE( metrics );
goto Exit;
}
}
- globals->metrics[clazz->script] = metrics;
+ globals->metrics[style] = metrics;
}
Exit:
@@ -295,7 +454,7 @@
FT_UInt gindex )
{
if ( gindex < (FT_ULong)globals->glyph_count )
- return (FT_Bool)( globals->glyph_scripts[gindex] & AF_DIGIT );
+ return (FT_Bool)( globals->glyph_styles[gindex] & AF_DIGIT );
return (FT_Bool)0;
}
diff --git a/freetype/src/autofit/afglobal.h b/freetype/src/autofit/afglobal.h
index 2e2490082..d2da40e3c 100644
--- a/freetype/src/autofit/afglobal.h
+++ b/freetype/src/autofit/afglobal.h
@@ -5,7 +5,7 @@
/* Auto-fitter routines to compute global hinting values */
/* (specification). */
/* */
-/* Copyright 2003-2005, 2007, 2009, 2011-2012 by */
+/* Copyright 2003-2005, 2007, 2009, 2011-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -23,22 +23,59 @@
#include "aftypes.h"
#include "afmodule.h"
+#include "hbshim.h"
FT_BEGIN_HEADER
+ FT_LOCAL_ARRAY( AF_WritingSystemClass )
+ af_writing_system_classes[];
+
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ AF_DECLARE_SCRIPT_CLASS( af_ ## s ## _script_class )
+
+#include "afscript.h"
+
+ FT_LOCAL_ARRAY( AF_ScriptClass )
+ af_script_classes[];
+
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ AF_DECLARE_STYLE_CLASS( af_ ## s ## _style_class )
+
+#include "afstyles.h"
+
+ FT_LOCAL_ARRAY( AF_StyleClass )
+ af_style_classes[];
+
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_LOCAL_ARRAY( char* )
+ af_style_names[];
+#endif
+
+
/*
* Default values and flags for both autofitter globals (found in
* AF_ModuleRec) and face globals (in AF_FaceGlobalsRec).
*/
- /* index of fallback script in `af_script_classes' */
-#define AF_SCRIPT_FALLBACK 2
+ /* index of fallback style in `af_style_classes' */
+#ifdef AF_CONFIG_OPTION_CJK
+#define AF_STYLE_FALLBACK AF_STYLE_HANI_DFLT
+#else
+#define AF_STYLE_FALLBACK AF_STYLE_NONE_DFLT
+#endif
+ /* default script for OpenType; ignored if HarfBuzz isn't used */
+#define AF_SCRIPT_DEFAULT AF_SCRIPT_LATN
/* a bit mask indicating an uncovered glyph */
-#define AF_SCRIPT_NONE 0x7F
+#define AF_STYLE_UNASSIGNED 0x7F
/* if this flag is set, we have an ASCII digit */
-#define AF_DIGIT 0x80
+#define AF_DIGIT 0x80
/* `increase-x-height' property */
#define AF_PROP_INCREASE_X_HEIGHT_MIN 6
@@ -55,29 +92,33 @@ FT_BEGIN_HEADER
/*
- * Note that glyph_scripts[] is used to map each glyph into
- * an index into the `af_script_classes' array.
+ * Note that glyph_styles[] maps each glyph to an index into the
+ * `af_style_classes' array.
*
*/
typedef struct AF_FaceGlobalsRec_
{
- FT_Face face;
- FT_Long glyph_count; /* same as face->num_glyphs */
- FT_Byte* glyph_scripts;
+ FT_Face face;
+ FT_Long glyph_count; /* same as face->num_glyphs */
+ FT_Byte* glyph_styles;
+
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ hb_font_t* hb_font;
+#endif
/* per-face auto-hinter properties */
- FT_UInt increase_x_height;
+ FT_UInt increase_x_height;
- AF_ScriptMetrics metrics[AF_SCRIPT_MAX];
+ AF_StyleMetrics metrics[AF_STYLE_MAX];
- AF_Module module; /* to access global properties */
+ AF_Module module; /* to access global properties */
} AF_FaceGlobalsRec;
/*
* model the global hints data for a given face, decomposed into
- * script-specific items
+ * style-specific items
*/
FT_LOCAL( FT_Error )
@@ -86,10 +127,10 @@ FT_BEGIN_HEADER
AF_Module module );
FT_LOCAL( FT_Error )
- af_face_globals_get_metrics( AF_FaceGlobals globals,
- FT_UInt gindex,
- FT_UInt options,
- AF_ScriptMetrics *ametrics );
+ af_face_globals_get_metrics( AF_FaceGlobals globals,
+ FT_UInt gindex,
+ FT_UInt options,
+ AF_StyleMetrics *ametrics );
FT_LOCAL( void )
af_face_globals_free( AF_FaceGlobals globals );
diff --git a/freetype/src/autofit/afhints.c b/freetype/src/autofit/afhints.c
index d0f05d6a4..c96c7ac3c 100644
--- a/freetype/src/autofit/afhints.c
+++ b/freetype/src/autofit/afhints.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter hinting routines (body). */
/* */
-/* Copyright 2003-2007, 2009-2013 by */
+/* Copyright 2003-2007, 2009-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -144,6 +144,17 @@
#include FT_CONFIG_STANDARD_LIBRARY_H
+ /* The dump functions are used in the `ftgrid' demo program, too. */
+#define AF_DUMP( varformat ) \
+ do \
+ { \
+ if ( to_stdout ) \
+ printf varformat; \
+ else \
+ FT_TRACE7( varformat ); \
+ } while ( 0 )
+
+
static const char*
af_dir_str( AF_Direction dir )
{
@@ -179,34 +190,35 @@
extern "C" {
#endif
void
- af_glyph_hints_dump_points( AF_GlyphHints hints )
+ af_glyph_hints_dump_points( AF_GlyphHints hints,
+ FT_Bool to_stdout )
{
AF_Point points = hints->points;
AF_Point limit = points + hints->num_points;
AF_Point point;
- FT_TRACE7(( "Table of points:\n"
- " [ index | xorg | yorg | xscale | yscale"
- " | xfit | yfit | flags ]\n" ));
+ AF_DUMP(( "Table of points:\n"
+ " [ index | xorg | yorg | xscale | yscale"
+ " | xfit | yfit | flags ]\n" ));
for ( point = points; point < limit; point++ )
- FT_TRACE7(( " [ %5d | %5d | %5d | %6.2f | %6.2f"
- " | %5.2f | %5.2f | %c%c%c%c%c%c ]\n",
- point - points,
- point->fx,
- point->fy,
- point->ox / 64.0,
- point->oy / 64.0,
- point->x / 64.0,
- point->y / 64.0,
- ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ',
- ( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ',
- ( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ',
- ( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ',
- ( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ',
- ( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' '));
- FT_TRACE7(( "\n" ));
+ AF_DUMP(( " [ %5d | %5d | %5d | %6.2f | %6.2f"
+ " | %5.2f | %5.2f | %c%c%c%c%c%c ]\n",
+ point - points,
+ point->fx,
+ point->fy,
+ point->ox / 64.0,
+ point->oy / 64.0,
+ point->x / 64.0,
+ point->y / 64.0,
+ ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ',
+ ( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ',
+ ( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ',
+ ( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ',
+ ( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ',
+ ( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' '));
+ AF_DUMP(( "\n" ));
}
#ifdef __cplusplus
}
@@ -247,7 +259,8 @@
extern "C" {
#endif
void
- af_glyph_hints_dump_segments( AF_GlyphHints hints )
+ af_glyph_hints_dump_segments( AF_GlyphHints hints,
+ FT_Bool to_stdout )
{
FT_Int dimension;
@@ -262,34 +275,34 @@
AF_Segment seg;
- FT_TRACE7(( "Table of %s segments:\n",
- dimension == AF_DIMENSION_HORZ ? "vertical"
- : "horizontal" ));
+ AF_DUMP(( "Table of %s segments:\n",
+ dimension == AF_DIMENSION_HORZ ? "vertical"
+ : "horizontal" ));
if ( axis->num_segments )
- FT_TRACE7(( " [ index | pos | dir | from"
- " | to | link | serif | edge"
- " | height | extra | flags ]\n" ));
+ AF_DUMP(( " [ index | pos | dir | from"
+ " | to | link | serif | edge"
+ " | height | extra | flags ]\n" ));
else
- FT_TRACE7(( " (none)\n" ));
+ AF_DUMP(( " (none)\n" ));
for ( seg = segments; seg < limit; seg++ )
- FT_TRACE7(( " [ %5d | %5.2g | %5s | %4d"
- " | %4d | %4d | %5d | %4d"
- " | %6d | %5d | %11s ]\n",
- seg - segments,
- dimension == AF_DIMENSION_HORZ
- ? (int)seg->first->ox / 64.0
- : (int)seg->first->oy / 64.0,
- af_dir_str( (AF_Direction)seg->dir ),
- AF_INDEX_NUM( seg->first, points ),
- AF_INDEX_NUM( seg->last, points ),
- AF_INDEX_NUM( seg->link, segments ),
- AF_INDEX_NUM( seg->serif, segments ),
- AF_INDEX_NUM( seg->edge, edges ),
- seg->height,
- seg->height - ( seg->max_coord - seg->min_coord ),
- af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) ));
- FT_TRACE7(( "\n" ));
+ AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
+ " | %4d | %4d | %5d | %4d"
+ " | %6d | %5d | %11s ]\n",
+ seg - segments,
+ dimension == AF_DIMENSION_HORZ
+ ? (int)seg->first->ox / 64.0
+ : (int)seg->first->oy / 64.0,
+ af_dir_str( (AF_Direction)seg->dir ),
+ AF_INDEX_NUM( seg->first, points ),
+ AF_INDEX_NUM( seg->last, points ),
+ AF_INDEX_NUM( seg->link, segments ),
+ AF_INDEX_NUM( seg->serif, segments ),
+ AF_INDEX_NUM( seg->edge, edges ),
+ seg->height,
+ seg->height - ( seg->max_coord - seg->min_coord ),
+ af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) ));
+ AF_DUMP(( "\n" ));
}
}
#ifdef __cplusplus
@@ -332,7 +345,9 @@
af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
FT_Int dimension,
FT_Int idx,
- FT_Pos* offset )
+ FT_Pos *offset,
+ FT_Bool *is_blue,
+ FT_Pos *blue_offset )
{
AF_Dimension dim;
AF_AxisHints axis;
@@ -349,9 +364,18 @@
if ( idx < 0 || idx >= axis->num_segments )
return FT_THROW( Invalid_Argument );
- seg = &axis->segments[idx];
- *offset = ( dim == AF_DIMENSION_HORZ ) ? seg->first->ox
- : seg->first->oy;
+ seg = &axis->segments[idx];
+ *offset = ( dim == AF_DIMENSION_HORZ ) ? seg->first->ox
+ : seg->first->oy;
+ if ( seg->edge )
+ *is_blue = (FT_Bool)( seg->edge->blue_edge != 0 );
+ else
+ *is_blue = FALSE;
+
+ if ( *is_blue )
+ *blue_offset = seg->edge->blue_edge->cur;
+ else
+ *blue_offset = 0;
return FT_Err_Ok;
}
@@ -366,7 +390,8 @@
extern "C" {
#endif
void
- af_glyph_hints_dump_edges( AF_GlyphHints hints )
+ af_glyph_hints_dump_edges( AF_GlyphHints hints,
+ FT_Bool to_stdout )
{
FT_Int dimension;
@@ -383,94 +408,35 @@
* note: AF_DIMENSION_HORZ corresponds to _vertical_ edges
* since they have a constant X coordinate.
*/
- FT_TRACE7(( "Table of %s edges:\n",
- dimension == AF_DIMENSION_HORZ ? "vertical"
- : "horizontal" ));
+ AF_DUMP(( "Table of %s edges:\n",
+ dimension == AF_DIMENSION_HORZ ? "vertical"
+ : "horizontal" ));
if ( axis->num_edges )
- FT_TRACE7(( " [ index | pos | dir | link"
- " | serif | blue | opos | pos | flags ]\n" ));
+ AF_DUMP(( " [ index | pos | dir | link"
+ " | serif | blue | opos | pos | flags ]\n" ));
else
- FT_TRACE7(( " (none)\n" ));
+ AF_DUMP(( " (none)\n" ));
for ( edge = edges; edge < limit; edge++ )
- FT_TRACE7(( " [ %5d | %5.2g | %5s | %4d"
- " | %5d | %c | %5.2f | %5.2f | %11s ]\n",
- edge - edges,
- (int)edge->opos / 64.0,
- af_dir_str( (AF_Direction)edge->dir ),
- AF_INDEX_NUM( edge->link, edges ),
- AF_INDEX_NUM( edge->serif, edges ),
- edge->blue_edge ? 'y' : 'n',
- edge->opos / 64.0,
- edge->pos / 64.0,
- af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) ));
- FT_TRACE7(( "\n" ));
+ AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
+ " | %5d | %c | %5.2f | %5.2f | %11s ]\n",
+ edge - edges,
+ (int)edge->opos / 64.0,
+ af_dir_str( (AF_Direction)edge->dir ),
+ AF_INDEX_NUM( edge->link, edges ),
+ AF_INDEX_NUM( edge->serif, edges ),
+ edge->blue_edge ? 'y' : 'n',
+ edge->opos / 64.0,
+ edge->pos / 64.0,
+ af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) ));
+ AF_DUMP(( "\n" ));
}
}
#ifdef __cplusplus
}
#endif
-#else /* !FT_DEBUG_AUTOFIT */
-
- /* these empty stubs are only used to link the `ftgrid' test program */
- /* if debugging is disabled */
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
- void
- af_glyph_hints_dump_points( AF_GlyphHints hints )
- {
- FT_UNUSED( hints );
- }
-
-
- void
- af_glyph_hints_dump_segments( AF_GlyphHints hints )
- {
- FT_UNUSED( hints );
- }
-
-
- FT_Error
- af_glyph_hints_get_num_segments( AF_GlyphHints hints,
- FT_Int dimension,
- FT_Int* num_segments )
- {
- FT_UNUSED( hints );
- FT_UNUSED( dimension );
- FT_UNUSED( num_segments );
-
- return 0;
- }
-
-
- FT_Error
- af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
- FT_Int dimension,
- FT_Int idx,
- FT_Pos* offset )
- {
- FT_UNUSED( hints );
- FT_UNUSED( dimension );
- FT_UNUSED( idx );
- FT_UNUSED( offset );
-
- return 0;
- }
-
-
- void
- af_glyph_hints_dump_edges( AF_GlyphHints hints )
- {
- FT_UNUSED( hints );
- }
-
-#ifdef __cplusplus
- }
-#endif
+#undef AF_DUMP
#endif /* !FT_DEBUG_AUTOFIT */
@@ -578,8 +544,8 @@
/* Reset metrics. */
FT_LOCAL_DEF( void )
- af_glyph_hints_rescale( AF_GlyphHints hints,
- AF_ScriptMetrics metrics )
+ af_glyph_hints_rescale( AF_GlyphHints hints,
+ AF_StyleMetrics metrics )
{
hints->metrics = metrics;
hints->scaler_flags = metrics->scaler.flags;
@@ -740,6 +706,12 @@
FT_Pos in_y = 0;
AF_Direction in_dir = AF_DIR_NONE;
+ FT_Pos last_good_in_x = 0;
+ FT_Pos last_good_in_y = 0;
+
+ FT_UInt units_per_em = hints->metrics->scaler.face->units_per_EM;
+ FT_Int near_limit = 20 * units_per_em / 2048;
+
for ( point = points; point < point_limit; point++ )
{
@@ -749,15 +721,59 @@
if ( point == first )
{
- prev = first->prev;
- in_x = first->fx - prev->fx;
- in_y = first->fy - prev->fy;
+ prev = first->prev;
+
+ in_x = first->fx - prev->fx;
+ in_y = first->fy - prev->fy;
+
+ last_good_in_x = in_x;
+ last_good_in_y = in_y;
+
+ if ( FT_ABS( in_x ) + FT_ABS( in_y ) < near_limit )
+ {
+ /* search first non-near point to get a good `in_dir' value */
+
+ AF_Point point_ = prev;
+
+
+ while ( point_ != first )
+ {
+ AF_Point prev_ = point_->prev;
+
+ FT_Pos in_x_ = point_->fx - prev_->fx;
+ FT_Pos in_y_ = point_->fy - prev_->fy;
+
+
+ if ( FT_ABS( in_x_ ) + FT_ABS( in_y_ ) >= near_limit )
+ {
+ last_good_in_x = in_x_;
+ last_good_in_y = in_y_;
+
+ break;
+ }
+
+ point_ = prev_;
+ }
+ }
+
in_dir = af_direction_compute( in_x, in_y );
first = prev + 1;
}
point->in_dir = (FT_Char)in_dir;
+ /* check whether the current point is near to the previous one */
+ /* (value 20 in `near_limit' is heuristic; we use Taxicab */
+ /* metrics for the test) */
+
+ if ( FT_ABS( in_x ) + FT_ABS( in_y ) < near_limit )
+ point->flags |= AF_FLAG_NEAR;
+ else
+ {
+ last_good_in_x = in_x;
+ last_good_in_y = in_y;
+ }
+
next = point->next;
out_x = next->fx - point->fx;
out_y = next->fy - point->fy;
@@ -765,27 +781,46 @@
in_dir = af_direction_compute( out_x, out_y );
point->out_dir = (FT_Char)in_dir;
- /* check for weak points */
+ /* Check for weak points. The remaining points not collected */
+ /* in edges are then implicitly classified as strong points. */
if ( point->flags & AF_FLAG_CONTROL )
{
+ /* control points are always weak */
Is_Weak_Point:
point->flags |= AF_FLAG_WEAK_INTERPOLATION;
}
else if ( point->out_dir == point->in_dir )
{
if ( point->out_dir != AF_DIR_NONE )
+ {
+ /* current point lies on a horizontal or */
+ /* vertical segment (but doesn't start or end it) */
goto Is_Weak_Point;
+ }
- if ( ft_corner_is_flat( in_x, in_y, out_x, out_y ) )
+ /* test whether `in' and `out' direction is approximately */
+ /* the same (and use the last good `in' vector in case */
+ /* the current point is near to the previous one) */
+ if ( ft_corner_is_flat(
+ point->flags & AF_FLAG_NEAR ? last_good_in_x : in_x,
+ point->flags & AF_FLAG_NEAR ? last_good_in_y : in_y,
+ out_x,
+ out_y ) )
+ {
+ /* current point lies on a straight, diagonal line */
+ /* (more or less) */
goto Is_Weak_Point;
+ }
}
else if ( point->in_dir == -point->out_dir )
+ {
+ /* current point forms a spike */
goto Is_Weak_Point;
+ }
in_x = out_x;
in_y = out_y;
- prev = point;
}
}
}
@@ -1199,8 +1234,6 @@
}
}
- point = points;
-
for ( ; contour < contour_limit; contour++ )
{
AF_Point first_touched, last_touched;
@@ -1223,7 +1256,6 @@
}
first_touched = point;
- last_touched = point;
for (;;)
{
diff --git a/freetype/src/autofit/afhints.h b/freetype/src/autofit/afhints.h
index 776b3c844..5f1507f80 100644
--- a/freetype/src/autofit/afhints.h
+++ b/freetype/src/autofit/afhints.h
@@ -27,7 +27,7 @@ FT_BEGIN_HEADER
/*
* The definition of outline glyph hints. These are shared by all
- * script analysis routines (until now).
+ * writing system analysis routines (until now).
*/
typedef enum AF_Dimension_
@@ -62,15 +62,19 @@ FT_BEGIN_HEADER
*
* by David Turner and Werner Lemberg
*
- * http://www.tug.org/TUGboat/Articles/tb24-3/lemberg.pdf
+ * http://www.tug.org/TUGboat/Articles/tb24-3/lemberg.pdf
+ *
+ * with appropriate updates.
*
*
* Segments
*
* `af_{cjk,latin,...}_hints_compute_segments' are the functions to
- * find segments in an outline. A segment is a series of consecutive
- * points that are approximately aligned along a coordinate axis. The
- * analysis to do so is specific to a script.
+ * find segments in an outline.
+ *
+ * A segment is a series of consecutive points that are approximately
+ * aligned along a coordinate axis. The analysis to do so is specific
+ * to a writing system.
*
* A segment must have at least two points, except in the case of
* `fake' segments that are generated to hint metrics appropriately,
@@ -79,16 +83,17 @@ FT_BEGIN_HEADER
*
* Edges
*
+ * `af_{cjk,latin,...}_hints_compute_edges' are the functions to find
+ * edges.
+ *
* As soon as segments are defined, the auto-hinter groups them into
* edges. An edge corresponds to a single position on the main
* dimension that collects one or more segments (allowing for a small
* threshold).
*
- * The auto-hinter first tries to grid fit edges, then to align
- * segments on the edges unless it detects that they form a serif.
- *
- * `af_{cjk,latin,...}_hints_compute_edges' are the functions to find
- * edges; they are specific to a script.
+ * As an example, the `latin' writing system first tries to grid-fit
+ * edges, then to align segments on the edges unless it detects that
+ * they form a serif.
*
*
* A H
@@ -107,6 +112,8 @@ FT_BEGIN_HEADER
*
* Stems
*
+ * Stems are detected by `af_{cjk,latin,...}_hint_edges'.
+ *
* Segments need to be `linked' to other ones in order to detect stems.
* A stem is made of two segments that face each other in opposite
* directions and that are sufficiently close to each other. Using
@@ -127,17 +134,21 @@ FT_BEGIN_HEADER
* The best candidate is stored in field `link' in structure
* `AF_Segment'.
*
- * Stems are detected by `af_{cjk,latin,...}_hint_edges'.
- *
* In the above ASCII drawing, the best candidate for both AB and CD is
* GH, while the best candidate for GH is AB. Similarly, the best
* candidate for EF and GH is AB, while the best candidate for AB is
* GH.
*
+ * The detection and handling of stems is dependent on the writing
+ * system.
+ *
*
* Serifs
*
- * On the opposite, a serif has
+ * Serifs are detected by `af_{cjk,latin,...}_hint_edges'.
+ *
+ * In comparison to a stem, a serif (as handled by the auto-hinter
+ * module which takes care of the `latin' writing system) has
*
* best segment_1 = segment_2 && best segment_2 != segment_1
*
@@ -147,8 +158,6 @@ FT_BEGIN_HEADER
* The best candidate is stored in field `serif' in structure
* `AF_Segment' (and `link' is set to NULL).
*
- * Serifs are detected by `af_{cjk,latin,...}_hint_edges'.
- *
*
* Touched points
*
@@ -178,7 +187,8 @@ FT_BEGIN_HEADER
* differ greatly)
*
* - inflection points (i.e., where the `in' and `out' angles are the
- * same, but the curvature changes sign)
+ * same, but the curvature changes sign) [currently, such points
+ * aren't handled in the auto-hinter]
*
* `af_glyph_hints_align_strong_points' is the function which takes
* care of such situations; it is equivalent to the TrueType `IP'
@@ -226,7 +236,10 @@ FT_BEGIN_HEADER
AF_FLAG_WEAK_INTERPOLATION = 1 << 8,
/* all inflection points in the outline have this flag set */
- AF_FLAG_INFLECTION = 1 << 9
+ AF_FLAG_INFLECTION = 1 << 9,
+
+ /* the current point is very near to another one */
+ AF_FLAG_NEAR = 1 << 10
} AF_Flags;
@@ -330,31 +343,31 @@ FT_BEGIN_HEADER
typedef struct AF_GlyphHintsRec_
{
- FT_Memory memory;
+ FT_Memory memory;
- FT_Fixed x_scale;
- FT_Pos x_delta;
+ FT_Fixed x_scale;
+ FT_Pos x_delta;
- FT_Fixed y_scale;
- FT_Pos y_delta;
+ FT_Fixed y_scale;
+ FT_Pos y_delta;
- FT_Int max_points; /* number of allocated points */
- FT_Int num_points; /* number of used points */
- AF_Point points; /* points array */
+ FT_Int max_points; /* number of allocated points */
+ FT_Int num_points; /* number of used points */
+ AF_Point points; /* points array */
- FT_Int max_contours; /* number of allocated contours */
- FT_Int num_contours; /* number of used contours */
- AF_Point* contours; /* contours array */
+ FT_Int max_contours; /* number of allocated contours */
+ FT_Int num_contours; /* number of used contours */
+ AF_Point* contours; /* contours array */
- AF_AxisHintsRec axis[AF_DIMENSION_MAX];
+ AF_AxisHintsRec axis[AF_DIMENSION_MAX];
- FT_UInt32 scaler_flags; /* copy of scaler flags */
- FT_UInt32 other_flags; /* free for script-specific */
- /* implementations */
- AF_ScriptMetrics metrics;
+ FT_UInt32 scaler_flags; /* copy of scaler flags */
+ FT_UInt32 other_flags; /* free for style-specific */
+ /* implementations */
+ AF_StyleMetrics metrics;
- FT_Pos xmin_delta; /* used for warping */
- FT_Pos xmax_delta;
+ FT_Pos xmin_delta; /* used for warping */
+ FT_Pos xmax_delta;
} AF_GlyphHintsRec;
@@ -416,8 +429,8 @@ FT_BEGIN_HEADER
FT_Memory memory );
FT_LOCAL( void )
- af_glyph_hints_rescale( AF_GlyphHints hints,
- AF_ScriptMetrics metrics );
+ af_glyph_hints_rescale( AF_GlyphHints hints,
+ AF_StyleMetrics metrics );
FT_LOCAL( FT_Error )
af_glyph_hints_reload( AF_GlyphHints hints,
diff --git a/freetype/src/autofit/afindic.c b/freetype/src/autofit/afindic.c
index 8c2497259..197881b61 100644
--- a/freetype/src/autofit/afindic.c
+++ b/freetype/src/autofit/afindic.c
@@ -2,7 +2,7 @@
/* */
/* afindic.c */
/* */
-/* Auto-fitter hinting routines for Indic scripts (body). */
+/* Auto-fitter hinting routines for Indic writing system (body). */
/* */
/* Copyright 2007, 2011-2013 by */
/* Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>. */
@@ -97,60 +97,41 @@
/*************************************************************************/
- static const AF_Script_UniRangeRec af_indic_uniranges[] =
- {
-#if 0
- AF_UNIRANGE_REC( 0x0100UL, 0xFFFFUL ), /* why this? */
-#endif
- AF_UNIRANGE_REC( 0x0900UL, 0x0DFFUL), /* Indic Range */
- AF_UNIRANGE_REC( 0x0F00UL, 0x0FFFUL), /* Tibetan */
- AF_UNIRANGE_REC( 0x1900UL, 0x194FUL), /* Limbu */
- AF_UNIRANGE_REC( 0x1B80UL, 0x1BBFUL), /* Sundanese */
- AF_UNIRANGE_REC( 0x1C80UL, 0x1CDFUL), /* Meetei Mayak */
- AF_UNIRANGE_REC( 0xA800UL, 0xA82FUL), /* Syloti Nagri */
- AF_UNIRANGE_REC( 0x11800UL, 0x118DFUL), /* Sharada */
- AF_UNIRANGE_REC( 0UL, 0UL)
- };
-
-
- AF_DEFINE_SCRIPT_CLASS( af_indic_script_class,
- AF_SCRIPT_INDIC,
- af_indic_uniranges,
- 'o', /* XXX */
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_indic_writing_system_class,
+
+ AF_WRITING_SYSTEM_INDIC,
sizeof ( AF_CJKMetricsRec ),
- (AF_Script_InitMetricsFunc) af_indic_metrics_init,
- (AF_Script_ScaleMetricsFunc)af_indic_metrics_scale,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) af_indic_metrics_init,
+ (AF_WritingSystem_ScaleMetricsFunc)af_indic_metrics_scale,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) af_indic_hints_init,
- (AF_Script_ApplyHintsFunc) af_indic_hints_apply
+ (AF_WritingSystem_InitHintsFunc) af_indic_hints_init,
+ (AF_WritingSystem_ApplyHintsFunc) af_indic_hints_apply
)
+
#else /* !AF_CONFIG_OPTION_INDIC */
- static const AF_Script_UniRangeRec af_indic_uniranges[] =
- {
- { 0, 0 }
- };
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_indic_writing_system_class,
- AF_DEFINE_SCRIPT_CLASS( af_indic_script_class,
- AF_SCRIPT_INDIC,
- af_indic_uniranges,
- 0,
+ AF_WRITING_SYSTEM_INDIC,
sizeof ( AF_CJKMetricsRec ),
- (AF_Script_InitMetricsFunc) NULL,
- (AF_Script_ScaleMetricsFunc)NULL,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) NULL,
+ (AF_WritingSystem_ScaleMetricsFunc)NULL,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) NULL,
- (AF_Script_ApplyHintsFunc) NULL
+ (AF_WritingSystem_InitHintsFunc) NULL,
+ (AF_WritingSystem_ApplyHintsFunc) NULL
)
+
#endif /* !AF_CONFIG_OPTION_INDIC */
diff --git a/freetype/src/autofit/afindic.h b/freetype/src/autofit/afindic.h
index c252cf20d..9e13cf7e3 100644
--- a/freetype/src/autofit/afindic.h
+++ b/freetype/src/autofit/afindic.h
@@ -2,9 +2,10 @@
/* */
/* afindic.h */
/* */
-/* Auto-fitter hinting routines for Indic scripts (specification). */
+/* Auto-fitter hinting routines for Indic writing system */
+/* (specification). */
/* */
-/* Copyright 2007, 2012 by */
+/* Copyright 2007, 2012, 2013 by */
/* Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -25,9 +26,9 @@
FT_BEGIN_HEADER
- /* the Indic-specific script class */
+ /* the `indic' writing system */
- AF_DECLARE_SCRIPT_CLASS( af_indic_script_class )
+ AF_DECLARE_WRITING_SYSTEM_CLASS( af_indic_writing_system_class )
/* */
diff --git a/freetype/src/autofit/aflatin.c b/freetype/src/autofit/aflatin.c
index ae4bbba35..2938f79c7 100644
--- a/freetype/src/autofit/aflatin.c
+++ b/freetype/src/autofit/aflatin.c
@@ -2,9 +2,9 @@
/* */
/* aflatin.c */
/* */
-/* Auto-fitter hinting routines for latin script (body). */
+/* Auto-fitter hinting routines for latin writing system (body). */
/* */
-/* Copyright 2003-2013 by */
+/* Copyright 2003-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -21,6 +21,7 @@
#include <freetype/internal/ftdebug.h>
#include "afglobal.h"
+#include "afpic.h"
#include "aflatin.h"
#include "aferrors.h"
@@ -60,8 +61,11 @@
AF_GlyphHintsRec hints[1];
- FT_TRACE5(( "standard widths computation\n"
- "===========================\n\n" ));
+ FT_TRACE5(( "\n"
+ "latin standard widths computation (style `%s')\n"
+ "=====================================================\n"
+ "\n",
+ af_style_names[metrics->root.style_class->style] ));
af_glyph_hints_init( hints, face->memory );
@@ -70,19 +74,66 @@
{
FT_Error error;
- FT_UInt glyph_index;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
int dim;
AF_LatinMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
+#ifdef FT_CONFIG_OPTION_PIC
+ AF_FaceGlobals globals = metrics->root.globals;
+#endif
- glyph_index = FT_Get_Char_Index( face,
- metrics->root.clazz->standard_char );
- if ( glyph_index == 0 )
- goto Exit;
+ AF_StyleClass style_class = metrics->root.style_class;
+ AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
+ [style_class->script];
+
+ FT_UInt32 standard_char;
- FT_TRACE5(( "standard character: 0x%X (glyph index %d)\n",
- metrics->root.clazz->standard_char, glyph_index ));
+
+ /*
+ * We check more than a single standard character to catch features
+ * like `c2sc' (small caps from caps) that don't contain lowercase
+ * letters by definition, or other features that mainly operate on
+ * numerals.
+ */
+
+ standard_char = script_class->standard_char1;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ {
+ if ( script_class->standard_char2 )
+ {
+ standard_char = script_class->standard_char2;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ {
+ if ( script_class->standard_char3 )
+ {
+ standard_char = script_class->standard_char3;
+ af_get_char_index( &metrics->root,
+ standard_char,
+ &glyph_index,
+ &y_offset );
+ if ( !glyph_index )
+ goto Exit;
+ }
+ else
+ goto Exit;
+ }
+ }
+ else
+ goto Exit;
+ }
+
+ FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
+ standard_char, glyph_index ));
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || face->glyph->outline.n_points <= 0 )
@@ -101,7 +152,7 @@
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
@@ -146,22 +197,21 @@
}
/* this also replaces multiple almost identical stem widths */
- /* with a single one (the value 100 is heuristic) */
+ /* with a single one (the value 100 is heuristic) */
af_sort_and_quantize_widths( &num_widths, axis->widths,
dummy->units_per_em / 100 );
axis->width_count = num_widths;
}
- Exit:
+ Exit:
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_LatinAxis axis = &metrics->axis[dim];
FT_Pos stdw;
- stdw = ( axis->width_count > 0 )
- ? axis->widths[0].org
- : AF_LATIN_CONSTANT( metrics, 50 );
+ stdw = ( axis->width_count > 0 ) ? axis->widths[0].org
+ : AF_LATIN_CONSTANT( metrics, 50 );
/* let's try 20% of the smallest width */
axis->edge_distance_threshold = stdw / 5;
@@ -193,22 +243,6 @@
}
-
-#define AF_LATIN_MAX_TEST_CHARACTERS 12
-
-
- static const char af_latin_blue_chars[AF_LATIN_MAX_BLUES]
- [AF_LATIN_MAX_TEST_CHARACTERS + 1] =
- {
- "THEZOCQS",
- "HEZLOCUS",
- "fijkdbh",
- "xzroesc",
- "xzroesc",
- "pqgjy"
- };
-
-
/* Find all blue zones. Flat segments give the reference points, */
/* round segments the overshoot positions. */
@@ -216,55 +250,107 @@
af_latin_metrics_init_blues( AF_LatinMetrics metrics,
FT_Face face )
{
- FT_Pos flats [AF_LATIN_MAX_TEST_CHARACTERS];
- FT_Pos rounds[AF_LATIN_MAX_TEST_CHARACTERS];
+ FT_Pos flats [AF_BLUE_STRING_MAX_LEN];
+ FT_Pos rounds[AF_BLUE_STRING_MAX_LEN];
+
FT_Int num_flats;
FT_Int num_rounds;
- FT_Int bb;
+
AF_LatinBlue blue;
FT_Error error;
- AF_LatinAxis axis = &metrics->axis[AF_DIMENSION_VERT];
+ AF_LatinAxis axis = &metrics->axis[AF_DIMENSION_VERT];
FT_Outline outline;
+ AF_StyleClass sc = metrics->root.style_class;
+
+ AF_Blue_Stringset bss = sc->blue_stringset;
+ const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
+
- /* we compute the blues simply by loading each character from the */
- /* `af_latin_blue_chars[blues]' string, then finding its top-most or */
- /* bottom-most points (depending on `AF_IS_TOP_BLUE') */
+ /* we walk over the blue character strings as specified in the */
+ /* style's entry in the `af_blue_stringset' array */
- FT_TRACE5(( "blue zones computation\n"
- "======================\n\n" ));
+ FT_TRACE5(( "latin blue zones computation\n"
+ "============================\n"
+ "\n" ));
- for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )
+ for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
- const char* p = af_latin_blue_chars[bb];
- const char* limit = p + AF_LATIN_MAX_TEST_CHARACTERS;
+ const char* p = &af_blue_strings[bs->string];
FT_Pos* blue_ref;
FT_Pos* blue_shoot;
- FT_TRACE5(( "blue zone %d:\n", bb ));
+#ifdef FT_DEBUG_LEVEL_TRACE
+ {
+ FT_Bool have_flag = 0;
+
+
+ FT_TRACE5(( "blue zone %d", axis->blue_count ));
+
+ if ( bs->properties )
+ {
+ FT_TRACE5(( " (" ));
+
+ if ( AF_LATIN_IS_TOP_BLUE( bs ) )
+ {
+ FT_TRACE5(( "top" ));
+ have_flag = 1;
+ }
+
+ if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs ) )
+ {
+ if ( have_flag )
+ FT_TRACE5(( ", " ));
+ FT_TRACE5(( "small top" ));
+ have_flag = 1;
+ }
+
+ if ( AF_LATIN_IS_LONG_BLUE( bs ) )
+ {
+ if ( have_flag )
+ FT_TRACE5(( ", " ));
+ FT_TRACE5(( "long" ));
+ }
+
+ FT_TRACE5(( ")" ));
+ }
+
+ FT_TRACE5(( ":\n" ));
+ }
+#endif /* FT_DEBUG_LEVEL_TRACE */
num_flats = 0;
num_rounds = 0;
- for ( ; p < limit && *p; p++ )
+ while ( *p )
{
- FT_UInt glyph_index;
+ FT_ULong ch;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
FT_Pos best_y; /* same as points.y */
FT_Int best_point, best_contour_first, best_contour_last;
FT_Vector* points;
FT_Bool round = 0;
+ GET_UTF8_CHAR( ch, p );
+
/* load the character in the face -- skip unknown or empty ones */
- glyph_index = FT_Get_Char_Index( face, (FT_UInt)*p );
+ af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset );
if ( glyph_index == 0 )
+ {
+ FT_TRACE5(( " U+%04lX unavailable\n", ch ));
continue;
+ }
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
outline = face->glyph->outline;
if ( error || outline.n_points <= 0 )
+ {
+ FT_TRACE5(( " U+%04lX contains no outlines\n", ch ));
continue;
+ }
/* now compute min or max point indices and coordinates */
points = outline.points;
@@ -289,11 +375,11 @@
/* Avoid single-point contours since they are never rasterized. */
/* In some fonts, they correspond to mark attachment points */
- /* which are way outside of the glyph's real outline. */
+ /* that are way outside of the glyph's real outline. */
if ( last <= first )
continue;
- if ( AF_LATIN_IS_TOP_BLUE( bb ) )
+ if ( AF_LATIN_IS_TOP_BLUE( bs ) )
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y > best_y )
@@ -318,7 +404,6 @@
best_contour_last = last;
}
}
- FT_TRACE5(( " %c %ld", *p, best_y ));
}
/* now check whether the point belongs to a straight or round */
@@ -328,10 +413,14 @@
{
FT_Pos best_x = points[best_point].x;
FT_Int prev, next;
+ FT_Int best_segment_first, best_segment_last;
FT_Int best_on_point_first, best_on_point_last;
FT_Pos dist;
+ best_segment_first = best_point;
+ best_segment_last = best_point;
+
if ( FT_CURVE_TAG( outline.tags[best_point] ) == FT_CURVE_TAG_ON )
{
best_on_point_first = best_point;
@@ -343,8 +432,9 @@
best_on_point_last = -1;
}
- /* look for the previous and next points that are not on the */
- /* same Y coordinate, then threshold the `closeness'... */
+ /* look for the previous and next points on the contour */
+ /* that are not on the same Y coordinate, then threshold */
+ /* the `closeness'... */
prev = best_point;
next = prev;
@@ -362,6 +452,8 @@
if ( FT_ABS( points[prev].x - best_x ) <= 20 * dist )
break;
+ best_segment_first = prev;
+
if ( FT_CURVE_TAG( outline.tags[prev] ) == FT_CURVE_TAG_ON )
{
best_on_point_first = prev;
@@ -383,6 +475,8 @@
if ( FT_ABS( points[next].x - best_x ) <= 20 * dist )
break;
+ best_segment_last = next;
+
if ( FT_CURVE_TAG( outline.tags[next] ) == FT_CURVE_TAG_ON )
{
best_on_point_last = next;
@@ -392,8 +486,195 @@
} while ( next != best_point );
- /* now set the `round' flag depending on the segment's kind */
- /* (value 8 is heuristic) */
+ if ( AF_LATIN_IS_LONG_BLUE( bs ) )
+ {
+ /* If this flag is set, we have an additional constraint to */
+ /* get the blue zone distance: Find a segment of the topmost */
+ /* (or bottommost) contour that is longer than a heuristic */
+ /* threshold. This ensures that small bumps in the outline */
+ /* are ignored (for example, the `vertical serifs' found in */
+ /* many Hebrew glyph designs). */
+
+ /* If this segment is long enough, we are done. Otherwise, */
+ /* search the segment next to the extremum that is long */
+ /* enough, has the same direction, and a not too large */
+ /* vertical distance from the extremum. Note that the */
+ /* algorithm doesn't check whether the found segment is */
+ /* actually the one (vertically) nearest to the extremum. */
+
+ /* heuristic threshold value */
+ FT_Pos length_threshold = metrics->units_per_em / 25;
+
+
+ dist = FT_ABS( points[best_segment_last].x -
+ points[best_segment_first].x );
+
+ if ( dist < length_threshold &&
+ best_segment_last - best_segment_first + 2 <=
+ best_contour_last - best_contour_first )
+ {
+ /* heuristic threshold value */
+ FT_Pos height_threshold = metrics->units_per_em / 4;
+
+ FT_Int first;
+ FT_Int last;
+ FT_Bool hit;
+
+ FT_Bool left2right;
+
+
+ /* compute direction */
+ prev = best_point;
+
+ do
+ {
+ if ( prev > best_contour_first )
+ prev--;
+ else
+ prev = best_contour_last;
+
+ if ( points[prev].x != best_x )
+ break;
+
+ } while ( prev != best_point );
+
+ /* skip glyph for the degenerate case */
+ if ( prev == best_point )
+ continue;
+
+ left2right = FT_BOOL( points[prev].x < points[best_point].x );
+
+ first = best_segment_last;
+ last = first;
+ hit = 0;
+
+ do
+ {
+ FT_Bool l2r;
+ FT_Pos d;
+ FT_Int p_first, p_last;
+
+
+ if ( !hit )
+ {
+ /* no hit; adjust first point */
+ first = last;
+
+ /* also adjust first and last on point */
+ if ( FT_CURVE_TAG( outline.tags[first] ) ==
+ FT_CURVE_TAG_ON )
+ {
+ p_first = first;
+ p_last = first;
+ }
+ else
+ {
+ p_first = -1;
+ p_last = -1;
+ }
+
+ hit = 1;
+ }
+
+ if ( last < best_contour_last )
+ last++;
+ else
+ last = best_contour_first;
+
+ if ( FT_ABS( best_y - points[first].y ) > height_threshold )
+ {
+ /* vertical distance too large */
+ hit = 0;
+ continue;
+ }
+
+ /* same test as above */
+ dist = FT_ABS( points[last].y - points[first].y );
+ if ( dist > 5 )
+ if ( FT_ABS( points[last].x - points[first].x ) <=
+ 20 * dist )
+ {
+ hit = 0;
+ continue;
+ }
+
+ if ( FT_CURVE_TAG( outline.tags[last] ) == FT_CURVE_TAG_ON )
+ {
+ p_last = last;
+ if ( p_first < 0 )
+ p_first = last;
+ }
+
+ l2r = FT_BOOL( points[first].x < points[last].x );
+ d = FT_ABS( points[last].x - points[first].x );
+
+ if ( l2r == left2right &&
+ d >= length_threshold )
+ {
+ /* all constraints are met; update segment after finding */
+ /* its end */
+ do
+ {
+ if ( last < best_contour_last )
+ last++;
+ else
+ last = best_contour_first;
+
+ d = FT_ABS( points[last].y - points[first].y );
+ if ( d > 5 )
+ if ( FT_ABS( points[next].x - points[first].x ) <=
+ 20 * dist )
+ {
+ if ( last > best_contour_first )
+ last--;
+ else
+ last = best_contour_last;
+ break;
+ }
+
+ p_last = last;
+
+ if ( FT_CURVE_TAG( outline.tags[last] ) ==
+ FT_CURVE_TAG_ON )
+ {
+ p_last = last;
+ if ( p_first < 0 )
+ p_first = last;
+ }
+
+ } while ( last != best_segment_first );
+
+ best_y = points[first].y;
+
+ best_segment_first = first;
+ best_segment_last = last;
+
+ best_on_point_first = p_first;
+ best_on_point_last = p_last;
+
+ break;
+ }
+
+ } while ( last != best_segment_first );
+ }
+ }
+
+ /* for computing blue zones, we add the y offset as returned */
+ /* by the currently used OpenType feature -- for example, */
+ /* superscript glyphs might be identical to subscript glyphs */
+ /* with a vertical shift */
+ best_y += y_offset;
+
+ FT_TRACE5(( " U+%04lX: best_y = %5ld", ch, best_y ));
+
+ /* now set the `round' flag depending on the segment's kind: */
+ /* */
+ /* - if the horizontal distance between the first and last */
+ /* `on' point is larger than upem/8 (value 8 is heuristic) */
+ /* we have a flat segment */
+ /* - if either the first or the last point of the segment is */
+ /* an `off' point, the segment is round, otherwise it is */
+ /* flat */
if ( best_on_point_first >= 0 &&
best_on_point_last >= 0 &&
(FT_UInt)( FT_ABS( points[best_on_point_last].x -
@@ -402,8 +683,10 @@
round = 0;
else
round = FT_BOOL(
- FT_CURVE_TAG( outline.tags[prev] ) != FT_CURVE_TAG_ON ||
- FT_CURVE_TAG( outline.tags[next] ) != FT_CURVE_TAG_ON );
+ FT_CURVE_TAG( outline.tags[best_segment_first] ) !=
+ FT_CURVE_TAG_ON ||
+ FT_CURVE_TAG( outline.tags[best_segment_last] ) !=
+ FT_CURVE_TAG_ON );
FT_TRACE5(( " (%s)\n", round ? "round" : "flat" ));
}
@@ -448,7 +731,7 @@
}
else
{
- *blue_ref = flats[num_flats / 2];
+ *blue_ref = flats [num_flats / 2];
*blue_shoot = rounds[num_rounds / 2];
}
@@ -462,7 +745,7 @@
FT_Bool over_ref = FT_BOOL( shoot > ref );
- if ( AF_LATIN_IS_TOP_BLUE( bb ) ^ over_ref )
+ if ( AF_LATIN_IS_TOP_BLUE( bs ) ^ over_ref )
{
*blue_ref =
*blue_shoot = ( shoot + ref ) / 2;
@@ -473,7 +756,7 @@
}
blue->flags = 0;
- if ( AF_LATIN_IS_TOP_BLUE( bb ) )
+ if ( AF_LATIN_IS_TOP_BLUE( bs ) )
blue->flags |= AF_LATIN_BLUE_TOP;
/*
@@ -481,7 +764,7 @@
* in order to optimize the pixel grid alignment of the top of small
* letters.
*/
- if ( bb == AF_LATIN_BLUE_SMALL_TOP )
+ if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs ) )
blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
FT_TRACE5(( " -> reference = %ld\n"
@@ -509,10 +792,11 @@
/* digit `0' is 0x30 in all supported charmaps */
for ( i = 0x30; i <= 0x39; i++ )
{
- FT_UInt glyph_index;
+ FT_ULong glyph_index;
+ FT_Long y_offset;
- glyph_index = FT_Get_Char_Index( face, i );
+ af_get_char_index( &metrics->root, i, &glyph_index, &y_offset );
if ( glyph_index == 0 )
continue;
@@ -650,7 +934,20 @@
else
#endif
if ( dim == AF_DIMENSION_VERT )
+ {
scale = FT_MulDiv( scale, fitted, scaled );
+
+ FT_TRACE5((
+ "af_latin_metrics_scale_dim:"
+ " x height alignment (style `%s'):\n"
+ " "
+ " vertical scaling changed from %.4f to %.4f (by %d%%)\n"
+ "\n",
+ af_style_names[metrics->root.style_class->style],
+ axis->org_scale / 65536.0,
+ scale / 65536.0,
+ ( fitted - scaled ) * 100 / scaled ));
+ }
}
}
}
@@ -669,6 +966,10 @@
metrics->root.scaler.y_delta = delta;
}
+ FT_TRACE5(( "%s widths (style `%s')\n",
+ dim == AF_DIMENSION_HORZ ? "horizontal" : "vertical",
+ af_style_names[metrics->root.style_class->style] ));
+
/* scale the widths */
for ( nn = 0; nn < axis->width_count; nn++ )
{
@@ -677,15 +978,31 @@
width->cur = FT_MulFix( width->org, scale );
width->fit = width->cur;
+
+ FT_TRACE5(( " %d scaled to %.2f\n",
+ width->org,
+ width->cur / 64.0 ));
}
+ FT_TRACE5(( "\n" ));
+
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
(FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( axis->extra_light )
+ FT_TRACE5(( "`%s' style is extra light (at current resolution)\n"
+ "\n",
+ af_style_names[metrics->root.style_class->style] ));
+#endif
+
if ( dim == AF_DIMENSION_VERT )
{
+ FT_TRACE5(( "blue zones (style `%s')\n",
+ af_style_names[metrics->root.style_class->style] ));
+
/* scale the blue zones */
for ( nn = 0; nn < axis->blue_count; nn++ )
{
@@ -757,6 +1074,19 @@
#endif
blue->flags |= AF_LATIN_BLUE_ACTIVE;
+
+ FT_TRACE5(( " reference %d: %d scaled to %.2f%s\n"
+ " overshoot %d: %d scaled to %.2f%s\n",
+ nn,
+ blue->ref.org,
+ blue->ref.fit / 64.0,
+ blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
+ : " (inactive)",
+ nn,
+ blue->shoot.org,
+ blue->shoot.fit / 64.0,
+ blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
+ : " (inactive)" ));
}
}
}
@@ -1527,7 +1857,7 @@
FT_Face face = metrics->root.scaler.face;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale if needed, since they may have
@@ -1654,8 +1984,8 @@
AF_Edge_Flags base_flags,
AF_Edge_Flags stem_flags )
{
- AF_LatinMetrics metrics = (AF_LatinMetrics) hints->metrics;
- AF_LatinAxis axis = & metrics->axis[dim];
+ AF_LatinMetrics metrics = (AF_LatinMetrics)hints->metrics;
+ AF_LatinAxis axis = &metrics->axis[dim];
FT_Pos dist = width;
FT_Int sign = 0;
FT_Int vertical = ( dim == AF_DIMENSION_VERT );
@@ -1878,8 +2208,9 @@
#endif
- FT_TRACE5(( "%s edge hinting\n",
- dim == AF_DIMENSION_VERT ? "horizontal" : "vertical" ));
+ FT_TRACE5(( "latin %s edge hinting (style `%s')\n",
+ dim == AF_DIMENSION_VERT ? "horizontal" : "vertical",
+ af_style_names[hints->metrics->style_class->style] ));
/* we begin by aligning all stems relative to the blue zone */
/* if needed -- that's only for horizontal edges */
@@ -2414,6 +2745,7 @@
af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
}
}
+
af_glyph_hints_save( hints, outline );
Exit:
@@ -2430,56 +2762,19 @@
/*************************************************************************/
- /* XXX: this should probably fine tuned to differentiate better between */
- /* scripts... */
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_latin_writing_system_class,
- static const AF_Script_UniRangeRec af_latin_uniranges[] =
- {
- AF_UNIRANGE_REC( 0x0020UL, 0x007FUL ), /* Basic Latin (no control chars) */
- AF_UNIRANGE_REC( 0x00A0UL, 0x00FFUL ), /* Latin-1 Supplement (no control chars) */
- AF_UNIRANGE_REC( 0x0100UL, 0x017FUL ), /* Latin Extended-A */
- AF_UNIRANGE_REC( 0x0180UL, 0x024FUL ), /* Latin Extended-B */
- AF_UNIRANGE_REC( 0x0250UL, 0x02AFUL ), /* IPA Extensions */
- AF_UNIRANGE_REC( 0x02B0UL, 0x02FFUL ), /* Spacing Modifier Letters */
- AF_UNIRANGE_REC( 0x0300UL, 0x036FUL ), /* Combining Diacritical Marks */
- AF_UNIRANGE_REC( 0x0370UL, 0x03FFUL ), /* Greek and Coptic */
- AF_UNIRANGE_REC( 0x0400UL, 0x04FFUL ), /* Cyrillic */
- AF_UNIRANGE_REC( 0x0500UL, 0x052FUL ), /* Cyrillic Supplement */
- AF_UNIRANGE_REC( 0x1D00UL, 0x1D7FUL ), /* Phonetic Extensions */
- AF_UNIRANGE_REC( 0x1D80UL, 0x1DBFUL ), /* Phonetic Extensions Supplement */
- AF_UNIRANGE_REC( 0x1DC0UL, 0x1DFFUL ), /* Combining Diacritical Marks Supplement */
- AF_UNIRANGE_REC( 0x1E00UL, 0x1EFFUL ), /* Latin Extended Additional */
- AF_UNIRANGE_REC( 0x1F00UL, 0x1FFFUL ), /* Greek Extended */
- AF_UNIRANGE_REC( 0x2000UL, 0x206FUL ), /* General Punctuation */
- AF_UNIRANGE_REC( 0x2070UL, 0x209FUL ), /* Superscripts and Subscripts */
- AF_UNIRANGE_REC( 0x20A0UL, 0x20CFUL ), /* Currency Symbols */
- AF_UNIRANGE_REC( 0x2150UL, 0x218FUL ), /* Number Forms */
- AF_UNIRANGE_REC( 0x2460UL, 0x24FFUL ), /* Enclosed Alphanumerics */
- AF_UNIRANGE_REC( 0x2C60UL, 0x2C7FUL ), /* Latin Extended-C */
- AF_UNIRANGE_REC( 0x2DE0UL, 0x2DFFUL ), /* Cyrillic Extended-A */
- AF_UNIRANGE_REC( 0x2E00UL, 0x2E7FUL ), /* Supplemental Punctuation */
- AF_UNIRANGE_REC( 0xA640UL, 0xA69FUL ), /* Cyrillic Extended-B */
- AF_UNIRANGE_REC( 0xA720UL, 0xA7FFUL ), /* Latin Extended-D */
- AF_UNIRANGE_REC( 0xFB00UL, 0xFB06UL ), /* Alphab. Present. Forms (Latin Ligs) */
- AF_UNIRANGE_REC( 0x1D400UL, 0x1D7FFUL ), /* Mathematical Alphanumeric Symbols */
- AF_UNIRANGE_REC( 0x1F100UL, 0x1F1FFUL ), /* Enclosed Alphanumeric Supplement */
- AF_UNIRANGE_REC( 0UL, 0UL )
- };
-
-
- AF_DEFINE_SCRIPT_CLASS( af_latin_script_class,
- AF_SCRIPT_LATIN,
- af_latin_uniranges,
- 'o',
+ AF_WRITING_SYSTEM_LATIN,
sizeof ( AF_LatinMetricsRec ),
- (AF_Script_InitMetricsFunc) af_latin_metrics_init,
- (AF_Script_ScaleMetricsFunc)af_latin_metrics_scale,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) af_latin_metrics_init,
+ (AF_WritingSystem_ScaleMetricsFunc)af_latin_metrics_scale,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) af_latin_hints_init,
- (AF_Script_ApplyHintsFunc) af_latin_hints_apply
+ (AF_WritingSystem_InitHintsFunc) af_latin_hints_init,
+ (AF_WritingSystem_ApplyHintsFunc) af_latin_hints_apply
)
diff --git a/freetype/src/autofit/aflatin.h b/freetype/src/autofit/aflatin.h
index d9170b3dc..a958af36a 100644
--- a/freetype/src/autofit/aflatin.h
+++ b/freetype/src/autofit/aflatin.h
@@ -2,9 +2,10 @@
/* */
/* aflatin.h */
/* */
-/* Auto-fitter hinting routines for latin script (specification). */
+/* Auto-fitter hinting routines for latin writing system */
+/* (specification). */
/* */
-/* Copyright 2003-2007, 2009, 2011-2012 by */
+/* Copyright 2003-2007, 2009, 2011-2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -24,10 +25,9 @@
FT_BEGIN_HEADER
+ /* the `latin' writing system */
- /* the latin-specific script class */
-
- AF_DECLARE_SCRIPT_CLASS( af_latin_script_class )
+ AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin_writing_system_class )
/* constants are given with units_per_em == 2048 in mind */
@@ -46,32 +46,19 @@ FT_BEGIN_HEADER
/*
* The following declarations could be embedded in the file `aflatin.c';
- * they have been made semi-public to allow alternate script hinters to
- * re-use some of them.
+ * they have been made semi-public to allow alternate writing system
+ * hinters to re-use some of them.
*/
- /* Latin (global) metrics management */
-
- enum
- {
- AF_LATIN_BLUE_CAPITAL_TOP,
- AF_LATIN_BLUE_CAPITAL_BOTTOM,
- AF_LATIN_BLUE_SMALL_F_TOP,
- AF_LATIN_BLUE_SMALL_TOP,
- AF_LATIN_BLUE_SMALL_BOTTOM,
- AF_LATIN_BLUE_SMALL_MINOR,
-
- AF_LATIN_BLUE_MAX
- };
-
-
-#define AF_LATIN_IS_TOP_BLUE( b ) ( (b) == AF_LATIN_BLUE_CAPITAL_TOP || \
- (b) == AF_LATIN_BLUE_SMALL_F_TOP || \
- (b) == AF_LATIN_BLUE_SMALL_TOP )
+#define AF_LATIN_IS_TOP_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_LATIN_TOP )
+#define AF_LATIN_IS_X_HEIGHT_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_LATIN_X_HEIGHT )
+#define AF_LATIN_IS_LONG_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_LATIN_LONG )
#define AF_LATIN_MAX_WIDTHS 16
-#define AF_LATIN_MAX_BLUES AF_LATIN_BLUE_MAX
enum
@@ -106,7 +93,7 @@ FT_BEGIN_HEADER
/* ignored for horizontal metrics */
FT_UInt blue_count;
- AF_LatinBlueRec blues[AF_LATIN_BLUE_MAX];
+ AF_LatinBlueRec blues[AF_BLUE_STRINGSET_MAX];
FT_Fixed org_scale;
FT_Pos org_delta;
@@ -116,9 +103,9 @@ FT_BEGIN_HEADER
typedef struct AF_LatinMetricsRec_
{
- AF_ScriptMetricsRec root;
- FT_UInt units_per_em;
- AF_LatinAxisRec axis[AF_DIMENSION_MAX];
+ AF_StyleMetricsRec root;
+ FT_UInt units_per_em;
+ AF_LatinAxisRec axis[AF_DIMENSION_MAX];
} AF_LatinMetricsRec, *AF_LatinMetrics;
@@ -174,7 +161,7 @@ FT_BEGIN_HEADER
/*
* The next functions shouldn't normally be exported. However, other
- * scripts might like to use these functions as-is.
+ * writing systems might like to use these functions as-is.
*/
FT_LOCAL( FT_Error )
af_latin_hints_compute_segments( AF_GlyphHints hints,
diff --git a/freetype/src/autofit/aflatin2.c b/freetype/src/autofit/aflatin2.c
index b1e9658d5..930fa9834 100644
--- a/freetype/src/autofit/aflatin2.c
+++ b/freetype/src/autofit/aflatin2.c
@@ -2,7 +2,7 @@
/* */
/* aflatin2.c */
/* */
-/* Auto-fitter hinting routines for latin script (body). */
+/* Auto-fitter hinting routines for latin writing system (body). */
/* */
/* Copyright 2003-2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
@@ -76,8 +76,9 @@
AF_Scaler scaler = &dummy->root.scaler;
- glyph_index = FT_Get_Char_Index( face,
- metrics->root.clazz->standard_char );
+ glyph_index = FT_Get_Char_Index(
+ face,
+ metrics->root.style_class->standard_char );
if ( glyph_index == 0 )
goto Exit;
@@ -94,7 +95,7 @@
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)dummy );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
@@ -409,11 +410,11 @@
blue->flags |= AF_LATIN_BLUE_TOP;
/*
- * The following flags is used later to adjust the y and x scales
+ * The following flag is used later to adjust the y and x scales
* in order to optimize the pixel grid alignment of the top of small
* letters.
*/
- if ( bb == AF_LATIN_BLUE_SMALL_TOP )
+ if ( AF_LATIN_IS_X_HEIGHT_BLUE( bb ) )
blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
FT_TRACE5(( " -> reference = %ld\n"
@@ -1500,7 +1501,7 @@
FT_Face face = metrics->root.scaler.face;
- af_glyph_hints_rescale( hints, (AF_ScriptMetrics)metrics );
+ af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale if needed, since they may have
@@ -2379,27 +2380,19 @@
/*************************************************************************/
- static const AF_Script_UniRangeRec af_latin2_uniranges[] =
- {
- AF_UNIRANGE_REC( 32UL, 127UL ), /* TODO: Add new Unicode ranges here! */
- AF_UNIRANGE_REC( 160UL, 255UL ),
- AF_UNIRANGE_REC( 0UL, 0UL )
- };
-
+ AF_DEFINE_WRITING_SYSTEM_CLASS(
+ af_latin2_writing_system_class,
- AF_DEFINE_SCRIPT_CLASS( af_latin2_script_class,
- AF_SCRIPT_LATIN2,
- af_latin2_uniranges,
- 'o',
+ AF_WRITING_SYSTEM_LATIN2,
sizeof ( AF_LatinMetricsRec ),
- (AF_Script_InitMetricsFunc) af_latin2_metrics_init,
- (AF_Script_ScaleMetricsFunc)af_latin2_metrics_scale,
- (AF_Script_DoneMetricsFunc) NULL,
+ (AF_WritingSystem_InitMetricsFunc) af_latin2_metrics_init,
+ (AF_WritingSystem_ScaleMetricsFunc)af_latin2_metrics_scale,
+ (AF_WritingSystem_DoneMetricsFunc) NULL,
- (AF_Script_InitHintsFunc) af_latin2_hints_init,
- (AF_Script_ApplyHintsFunc) af_latin2_hints_apply
+ (AF_WritingSystem_InitHintsFunc) af_latin2_hints_init,
+ (AF_WritingSystem_ApplyHintsFunc) af_latin2_hints_apply
)
diff --git a/freetype/src/autofit/aflatin2.h b/freetype/src/autofit/aflatin2.h
index cbfa39552..b5d252a91 100644
--- a/freetype/src/autofit/aflatin2.h
+++ b/freetype/src/autofit/aflatin2.h
@@ -2,9 +2,10 @@
/* */
/* aflatin2.h */
/* */
-/* Auto-fitter hinting routines for latin script (specification). */
+/* Auto-fitter hinting routines for latin writing system */
+/* (specification). */
/* */
-/* Copyright 2003-2007, 2012 by */
+/* Copyright 2003-2007, 2012, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -25,9 +26,10 @@
FT_BEGIN_HEADER
- /* the latin-specific script class */
+ /* the `latin' writing system */
+
+ AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin2_writing_system_class )
- AF_DECLARE_SCRIPT_CLASS( af_latin2_script_class )
/* */
diff --git a/freetype/src/autofit/afloader.c b/freetype/src/autofit/afloader.c
index 17a6fb7c3..0fa3c1278 100644
--- a/freetype/src/autofit/afloader.c
+++ b/freetype/src/autofit/afloader.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter glyph loading routines (body). */
/* */
-/* Copyright 2003-2009, 2011-2013 by */
+/* Copyright 2003-2009, 2011-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -21,6 +21,7 @@
#include "afhints.h"
#include "aferrors.h"
#include "afmodule.h"
+#include "afpic.h"
/* Initialize glyph loader. */
@@ -108,7 +109,7 @@
FT_Error error;
FT_Face face = loader->face;
FT_GlyphLoader gloader = loader->gloader;
- AF_ScriptMetrics metrics = loader->metrics;
+ AF_StyleMetrics metrics = loader->metrics;
AF_GlyphHints hints = &loader->hints;
FT_GlyphSlot slot = face->glyph;
FT_Slot_Internal internal = slot->internal;
@@ -180,10 +181,20 @@
/* now load the slot image into the auto-outline and run the */
/* automatic hinting process */
- if ( metrics->clazz->script_hints_apply )
- metrics->clazz->script_hints_apply( hints,
- &gloader->current.outline,
- metrics );
+ {
+#ifdef FT_CONFIG_OPTION_PIC
+ AF_FaceGlobals globals = loader->globals;
+#endif
+ AF_StyleClass style_class = metrics->style_class;
+ AF_WritingSystemClass writing_system_class =
+ AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
+
+
+ if ( writing_system_class->style_hints_apply )
+ writing_system_class->style_hints_apply( hints,
+ &gloader->current.outline,
+ metrics );
+ }
/* we now need to adjust the metrics according to the change in */
/* width/positioning that occurred during the hinting process */
@@ -307,12 +318,7 @@
/* recompute subglyph pointer */
subglyph = gloader->base.subglyphs + num_base_subgs + nn;
- if ( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS )
- {
- pp1 = loader->pp1;
- pp2 = loader->pp2;
- }
- else
+ if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS ) )
{
loader->pp1 = pp1;
loader->pp2 = pp2;
@@ -518,34 +524,42 @@
error = af_loader_reset( module, face );
if ( !error )
{
- AF_ScriptMetrics metrics;
- FT_UInt options = 0;
+ AF_StyleMetrics metrics;
+ FT_UInt options = AF_STYLE_NONE_DFLT;
#ifdef FT_OPTION_AUTOFIT2
- /* XXX: undocumented hook to activate the latin2 hinter */
+ /* XXX: undocumented hook to activate the latin2 writing system */
if ( load_flags & ( 1UL << 20 ) )
- options = 2;
+ options = AF_STYLE_LTN2_DFLT;
#endif
error = af_face_globals_get_metrics( loader->globals, gindex,
options, &metrics );
if ( !error )
{
+#ifdef FT_CONFIG_OPTION_PIC
+ AF_FaceGlobals globals = loader->globals;
+#endif
+ AF_StyleClass style_class = metrics->style_class;
+ AF_WritingSystemClass writing_system_class =
+ AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
+
+
loader->metrics = metrics;
- if ( metrics->clazz->script_metrics_scale )
- metrics->clazz->script_metrics_scale( metrics, &scaler );
+ if ( writing_system_class->style_metrics_scale )
+ writing_system_class->style_metrics_scale( metrics, &scaler );
else
metrics->scaler = scaler;
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
load_flags &= ~FT_LOAD_RENDER;
- if ( metrics->clazz->script_hints_init )
+ if ( writing_system_class->style_hints_init )
{
- error = metrics->clazz->script_hints_init( &loader->hints,
- metrics );
+ error = writing_system_class->style_hints_init( &loader->hints,
+ metrics );
if ( error )
goto Exit;
}
diff --git a/freetype/src/autofit/afloader.h b/freetype/src/autofit/afloader.h
index 1f34d17cc..9601e24fc 100644
--- a/freetype/src/autofit/afloader.h
+++ b/freetype/src/autofit/afloader.h
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter glyph loading routines (specification). */
/* */
-/* Copyright 2003-2005, 2011-2012 by */
+/* Copyright 2003-2005, 2011-2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -44,7 +44,7 @@ FT_BEGIN_HEADER
/* current glyph data */
FT_GlyphLoader gloader;
AF_GlyphHintsRec hints;
- AF_ScriptMetrics metrics;
+ AF_StyleMetrics metrics;
FT_Bool transformed;
FT_Matrix trans_matrix;
FT_Vector trans_delta;
diff --git a/freetype/src/autofit/afmodule.c b/freetype/src/autofit/afmodule.c
index 2081925f1..55c8d596f 100644
--- a/freetype/src/autofit/afmodule.c
+++ b/freetype/src/autofit/afmodule.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter module implementation (body). */
/* */
-/* Copyright 2003-2006, 2009, 2011-2013 by */
+/* Copyright 2003-2006, 2009, 2011-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -45,7 +45,7 @@
#define FT_COMPONENT trace_afmodule
- FT_Error
+ static FT_Error
af_property_get_face_globals( FT_Face face,
AF_FaceGlobals* aglobals,
AF_Module module )
@@ -60,8 +60,8 @@
globals = (AF_FaceGlobals)face->autohint.data;
if ( !globals )
{
- /* trigger computation of the global script data */
- /* in case it hasn't been done yet */
+ /* trigger computation of the global style data */
+ /* in case it hasn't been done yet */
error = af_face_globals_new( face, &globals, module );
if ( !error )
{
@@ -79,7 +79,7 @@
}
- FT_Error
+ static FT_Error
af_property_set( FT_Module ft_module,
const char* property_name,
const void* value )
@@ -92,8 +92,40 @@
{
FT_UInt* fallback_script = (FT_UInt*)value;
+ FT_UInt ss;
- module->fallback_script = *fallback_script;
+
+ /* We translate the fallback script to a fallback style that uses */
+ /* `fallback-script' as its script and `AF_COVERAGE_NONE' as its */
+ /* coverage value. */
+ for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
+ {
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
+
+
+ if ( style_class->script == *fallback_script &&
+ style_class->coverage == AF_COVERAGE_DEFAULT )
+ {
+ module->fallback_style = ss;
+ break;
+ }
+ }
+
+ if ( !AF_STYLE_CLASSES_GET[ss] )
+ {
+ FT_TRACE0(( "af_property_set: Invalid value %d for property `%s'\n",
+ fallback_script, property_name ));
+ return FT_THROW( Invalid_Argument );
+ }
+
+ return error;
+ }
+ else if ( !ft_strcmp( property_name, "default-script" ) )
+ {
+ FT_UInt* default_script = (FT_UInt*)value;
+
+
+ module->default_script = *default_script;
return error;
}
@@ -116,14 +148,15 @@
}
- FT_Error
+ static FT_Error
af_property_get( FT_Module ft_module,
const char* property_name,
void* value )
{
- FT_Error error = FT_Err_Ok;
- AF_Module module = (AF_Module)ft_module;
- FT_UInt fallback_script = module->fallback_script;
+ FT_Error error = FT_Err_Ok;
+ AF_Module module = (AF_Module)ft_module;
+ FT_UInt fallback_style = module->fallback_style;
+ FT_UInt default_script = module->default_script;
if ( !ft_strcmp( property_name, "glyph-to-script-map" ) )
@@ -134,7 +167,7 @@
error = af_property_get_face_globals( prop->face, &globals, module );
if ( !error )
- prop->map = globals->glyph_scripts;
+ prop->map = globals->glyph_styles;
return error;
}
@@ -142,8 +175,19 @@
{
FT_UInt* val = (FT_UInt*)value;
+ AF_StyleClass style_class = AF_STYLE_CLASSES_GET[fallback_style];
+
+
+ *val = style_class->script;
+
+ return error;
+ }
+ else if ( !ft_strcmp( property_name, "default-script" ) )
+ {
+ FT_UInt* val = (FT_UInt*)value;
+
- *val = fallback_script;
+ *val = default_script;
return error;
}
@@ -206,7 +250,8 @@
AF_Module module = (AF_Module)ft_module;
- module->fallback_script = AF_SCRIPT_FALLBACK;
+ module->fallback_style = AF_STYLE_FALLBACK;
+ module->default_script = AF_SCRIPT_DEFAULT;
return af_loader_init( module );
}
diff --git a/freetype/src/autofit/afmodule.h b/freetype/src/autofit/afmodule.h
index cae3054ab..b347decc9 100644
--- a/freetype/src/autofit/afmodule.h
+++ b/freetype/src/autofit/afmodule.h
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter module implementation (specification). */
/* */
-/* Copyright 2003, 2004, 2005 by */
+/* Copyright 2003-2005, 2009, 2012, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -40,7 +40,8 @@ FT_BEGIN_HEADER
{
FT_ModuleRec root;
- FT_UInt fallback_script;
+ FT_UInt fallback_style;
+ FT_UInt default_script;
AF_LoaderRec loader[1];
diff --git a/freetype/src/autofit/afpic.c b/freetype/src/autofit/afpic.c
index d142914c0..90f8beb52 100644
--- a/freetype/src/autofit/afpic.c
+++ b/freetype/src/autofit/afpic.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType position independent code services for autofit module. */
/* */
-/* Copyright 2009-2013 by */
+/* Copyright 2009-2014 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -20,6 +20,7 @@
#include FT_FREETYPE_H
#include <freetype/internal/ftobjs.h>
#include "afpic.h"
+#include "afglobal.h"
#include "aferrors.h"
@@ -42,14 +43,11 @@
FT_AutoHinter_InterfaceRec* clazz );
- /* forward declaration of PIC init functions from script classes */
-#include "aflatin.h"
-#ifdef FT_OPTION_AUTOFIT2
-#include "aflatin2.h"
-#endif
-#include "afcjk.h"
-#include "afdummy.h"
-#include "afindic.h"
+ /* forward declaration of PIC init functions from writing system classes */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) /* empty */
+
+#include "afwrtsys.h"
void
@@ -100,27 +98,44 @@
FT_Init_Class_af_service_properties( &container->af_service_properties );
- for ( ss = 0 ; ss < AF_SCRIPT_CLASSES_REC_COUNT ; ss++ )
- {
+ for ( ss = 0; ss < AF_WRITING_SYSTEM_MAX; ss++ )
+ container->af_writing_system_classes[ss] =
+ &container->af_writing_system_classes_rec[ss];
+ container->af_writing_system_classes[AF_WRITING_SYSTEM_MAX] = NULL;
+
+ for ( ss = 0; ss < AF_SCRIPT_MAX; ss++ )
container->af_script_classes[ss] =
&container->af_script_classes_rec[ss];
- }
- container->af_script_classes[AF_SCRIPT_CLASSES_COUNT - 1] = NULL;
+ container->af_script_classes[AF_SCRIPT_MAX] = NULL;
+
+ for ( ss = 0; ss < AF_STYLE_MAX; ss++ )
+ container->af_style_classes[ss] =
+ &container->af_style_classes_rec[ss];
+ container->af_style_classes[AF_STYLE_MAX] = NULL;
+
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) \
+ FT_Init_Class_af_ ## ws ## _writing_system_class( \
+ &container->af_writing_system_classes_rec[ss++] );
+
+ ss = 0;
+#include "afwrtsys.h"
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ FT_Init_Class_af_ ## s ## _script_class( \
+ &container->af_script_classes_rec[ss++] );
+
+ ss = 0;
+#include "afscript.h"
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, bss, c ) \
+ FT_Init_Class_af_ ## s ## _style_class( \
+ &container->af_style_classes_rec[ss++] );
- /* add call to initialization function when you add new scripts */
ss = 0;
- FT_Init_Class_af_dummy_script_class(
- &container->af_script_classes_rec[ss++] );
-#ifdef FT_OPTION_AUTOFIT2
- FT_Init_Class_af_latin2_script_class(
- &container->af_script_classes_rec[ss++] );
-#endif
- FT_Init_Class_af_latin_script_class(
- &container->af_script_classes_rec[ss++] );
- FT_Init_Class_af_cjk_script_class(
- &container->af_script_classes_rec[ss++] );
- FT_Init_Class_af_indic_script_class(
- &container->af_script_classes_rec[ss++] );
+#include "afstyles.h"
FT_Init_Class_af_autofitter_interface(
library, &container->af_autofitter_interface );
diff --git a/freetype/src/autofit/afpic.h b/freetype/src/autofit/afpic.h
index 4ce95e3a4..e2b026751 100644
--- a/freetype/src/autofit/afpic.h
+++ b/freetype/src/autofit/afpic.h
@@ -4,7 +4,7 @@
/* */
/* The FreeType position independent code services for autofit module. */
/* */
-/* Copyright 2009, 2011-2012 by */
+/* Copyright 2009, 2011-2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -27,11 +27,13 @@ FT_BEGIN_HEADER
#ifndef FT_CONFIG_OPTION_PIC
-#define AF_SERVICES_GET af_services
-#define AF_SERVICE_PROPERTIES_GET af_service_properties
+#define AF_SERVICES_GET af_services
+#define AF_SERVICE_PROPERTIES_GET af_service_properties
-#define AF_SCRIPT_CLASSES_GET af_script_classes
-#define AF_INTERFACE_GET af_autofitter_interface
+#define AF_WRITING_SYSTEM_CLASSES_GET af_writing_system_classes
+#define AF_SCRIPT_CLASSES_GET af_script_classes
+#define AF_STYLE_CLASSES_GET af_style_classes
+#define AF_INTERFACE_GET af_autofitter_interface
#else /* FT_CONFIG_OPTION_PIC */
@@ -40,24 +42,27 @@ FT_BEGIN_HEADER
#include "aftypes.h"
- /* increase these when you add new scripts, */
- /* and update autofit_module_class_pic_init */
-#ifdef FT_OPTION_AUTOFIT2
-#define AF_SCRIPT_CLASSES_COUNT 6
-#else
-#define AF_SCRIPT_CLASSES_COUNT 5
-#endif
-
-#define AF_SCRIPT_CLASSES_REC_COUNT ( AF_SCRIPT_CLASSES_COUNT - 1 )
-
typedef struct AFModulePIC_
{
FT_ServiceDescRec* af_services;
FT_Service_PropertiesRec af_service_properties;
- AF_ScriptClass af_script_classes[AF_SCRIPT_CLASSES_COUNT];
- AF_ScriptClassRec af_script_classes_rec[AF_SCRIPT_CLASSES_REC_COUNT];
+ AF_WritingSystemClass af_writing_system_classes
+ [AF_WRITING_SYSTEM_MAX + 1];
+ AF_WritingSystemClassRec af_writing_system_classes_rec
+ [AF_WRITING_SYSTEM_MAX];
+
+ AF_ScriptClass af_script_classes
+ [AF_SCRIPT_MAX + 1];
+ AF_ScriptClassRec af_script_classes_rec
+ [AF_SCRIPT_MAX];
+
+ AF_StyleClass af_style_classes
+ [AF_STYLE_MAX + 1];
+ AF_StyleClassRec af_style_classes_rec
+ [AF_STYLE_MAX];
+
FT_AutoHinter_InterfaceRec af_autofitter_interface;
} AFModulePIC;
@@ -69,10 +74,14 @@ FT_BEGIN_HEADER
#define AF_SERVICES_GET \
( GET_PIC( library )->af_services )
#define AF_SERVICE_PROPERTIES_GET \
- ( GET_PIC( library)->af_service_properties )
+ ( GET_PIC( library )->af_service_properties )
+#define AF_WRITING_SYSTEM_CLASSES_GET \
+ ( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_writing_system_classes )
#define AF_SCRIPT_CLASSES_GET \
( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_script_classes )
+#define AF_STYLE_CLASSES_GET \
+ ( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_style_classes )
#define AF_INTERFACE_GET \
( GET_PIC( library )->af_autofitter_interface )
diff --git a/freetype/src/autofit/afranges.c b/freetype/src/autofit/afranges.c
new file mode 100644
index 000000000..3d919b5a4
--- /dev/null
+++ b/freetype/src/autofit/afranges.c
@@ -0,0 +1,208 @@
+/***************************************************************************/
+/* */
+/* afranges.c */
+/* */
+/* Auto-fitter Unicode script ranges (body). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#include "afranges.h"
+
+
+ const AF_Script_UniRangeRec af_cyrl_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0400UL, 0x04FFUL ), /* Cyrillic */
+ AF_UNIRANGE_REC( 0x0500UL, 0x052FUL ), /* Cyrillic Supplement */
+ AF_UNIRANGE_REC( 0x2DE0UL, 0x2DFFUL ), /* Cyrillic Extended-A */
+ AF_UNIRANGE_REC( 0xA640UL, 0xA69FUL ), /* Cyrillic Extended-B */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_grek_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0370UL, 0x03FFUL ), /* Greek and Coptic */
+ AF_UNIRANGE_REC( 0x1F00UL, 0x1FFFUL ), /* Greek Extended */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_hebr_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0590UL, 0x05FFUL ), /* Hebrew */
+ AF_UNIRANGE_REC( 0xFB1DUL, 0xFB4FUL ), /* Alphab. Present. Forms (Hebrew) */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_latn_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0020UL, 0x007FUL ), /* Basic Latin (no control chars) */
+ AF_UNIRANGE_REC( 0x00A0UL, 0x00FFUL ), /* Latin-1 Supplement (no control chars) */
+ AF_UNIRANGE_REC( 0x0100UL, 0x017FUL ), /* Latin Extended-A */
+ AF_UNIRANGE_REC( 0x0180UL, 0x024FUL ), /* Latin Extended-B */
+ AF_UNIRANGE_REC( 0x0250UL, 0x02AFUL ), /* IPA Extensions */
+ AF_UNIRANGE_REC( 0x02B0UL, 0x02FFUL ), /* Spacing Modifier Letters */
+ AF_UNIRANGE_REC( 0x0300UL, 0x036FUL ), /* Combining Diacritical Marks */
+ AF_UNIRANGE_REC( 0x1D00UL, 0x1D7FUL ), /* Phonetic Extensions */
+ AF_UNIRANGE_REC( 0x1D80UL, 0x1DBFUL ), /* Phonetic Extensions Supplement */
+ AF_UNIRANGE_REC( 0x1DC0UL, 0x1DFFUL ), /* Combining Diacritical Marks Supplement */
+ AF_UNIRANGE_REC( 0x1E00UL, 0x1EFFUL ), /* Latin Extended Additional */
+ AF_UNIRANGE_REC( 0x2000UL, 0x206FUL ), /* General Punctuation */
+ AF_UNIRANGE_REC( 0x2070UL, 0x209FUL ), /* Superscripts and Subscripts */
+ AF_UNIRANGE_REC( 0x20A0UL, 0x20CFUL ), /* Currency Symbols */
+ AF_UNIRANGE_REC( 0x2150UL, 0x218FUL ), /* Number Forms */
+ AF_UNIRANGE_REC( 0x2460UL, 0x24FFUL ), /* Enclosed Alphanumerics */
+ AF_UNIRANGE_REC( 0x2C60UL, 0x2C7FUL ), /* Latin Extended-C */
+ AF_UNIRANGE_REC( 0x2E00UL, 0x2E7FUL ), /* Supplemental Punctuation */
+ AF_UNIRANGE_REC( 0xA720UL, 0xA7FFUL ), /* Latin Extended-D */
+ AF_UNIRANGE_REC( 0xFB00UL, 0xFB06UL ), /* Alphab. Present. Forms (Latin Ligs) */
+ AF_UNIRANGE_REC( 0x1D400UL, 0x1D7FFUL ), /* Mathematical Alphanumeric Symbols */
+ AF_UNIRANGE_REC( 0x1F100UL, 0x1F1FFUL ), /* Enclosed Alphanumeric Supplement */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_none_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+#ifdef AF_CONFIG_OPTION_INDIC
+
+ const AF_Script_UniRangeRec af_beng_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0980UL, 0x09FFUL ), /* Bengali */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_deva_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0900UL, 0x097FUL ), /* Devanagari */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_gujr_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0A80UL, 0x0AFFUL ), /* Gujarati */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_guru_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0A00UL, 0x0A7FUL ), /* Gurmukhi */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_knda_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0C80UL, 0x0CFFUL ), /* Kannada */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_limb_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x1900UL, 0x194FUL ), /* Limbu */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_mlym_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0D00UL, 0x0D7FUL ), /* Malayalam */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_orya_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0B00UL, 0x0B7FUL ), /* Oriya */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_sinh_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0D80UL, 0x0DFFUL ), /* Sinhala */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_sund_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x1B80UL, 0x1BBFUL ), /* Sundanese */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_sylo_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0xA800UL, 0xA82FUL ), /* Syloti Nagri */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_taml_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0B80UL, 0x0BFFUL ), /* Tamil */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_telu_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0C00UL, 0x0C7FUL ), /* Telugu */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+ const AF_Script_UniRangeRec af_tibt_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x0F00UL, 0x0FFFUL ), /* Tibetan */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+#endif /* !AF_CONFIG_OPTION_INDIC */
+
+#ifdef AF_CONFIG_OPTION_CJK
+
+ /* this corresponds to Unicode 6.0 */
+
+ const AF_Script_UniRangeRec af_hani_uniranges[] =
+ {
+ AF_UNIRANGE_REC( 0x1100UL, 0x11FFUL ), /* Hangul Jamo */
+ AF_UNIRANGE_REC( 0x2E80UL, 0x2EFFUL ), /* CJK Radicals Supplement */
+ AF_UNIRANGE_REC( 0x2F00UL, 0x2FDFUL ), /* Kangxi Radicals */
+ AF_UNIRANGE_REC( 0x2FF0UL, 0x2FFFUL ), /* Ideographic Description Characters */
+ AF_UNIRANGE_REC( 0x3000UL, 0x303FUL ), /* CJK Symbols and Punctuation */
+ AF_UNIRANGE_REC( 0x3040UL, 0x309FUL ), /* Hiragana */
+ AF_UNIRANGE_REC( 0x30A0UL, 0x30FFUL ), /* Katakana */
+ AF_UNIRANGE_REC( 0x3100UL, 0x312FUL ), /* Bopomofo */
+ AF_UNIRANGE_REC( 0x3130UL, 0x318FUL ), /* Hangul Compatibility Jamo */
+ AF_UNIRANGE_REC( 0x3190UL, 0x319FUL ), /* Kanbun */
+ AF_UNIRANGE_REC( 0x31A0UL, 0x31BFUL ), /* Bopomofo Extended */
+ AF_UNIRANGE_REC( 0x31C0UL, 0x31EFUL ), /* CJK Strokes */
+ AF_UNIRANGE_REC( 0x31F0UL, 0x31FFUL ), /* Katakana Phonetic Extensions */
+ AF_UNIRANGE_REC( 0x3200UL, 0x32FFUL ), /* Enclosed CJK Letters and Months */
+ AF_UNIRANGE_REC( 0x3300UL, 0x33FFUL ), /* CJK Compatibility */
+ AF_UNIRANGE_REC( 0x3400UL, 0x4DBFUL ), /* CJK Unified Ideographs Extension A */
+ AF_UNIRANGE_REC( 0x4DC0UL, 0x4DFFUL ), /* Yijing Hexagram Symbols */
+ AF_UNIRANGE_REC( 0x4E00UL, 0x9FFFUL ), /* CJK Unified Ideographs */
+ AF_UNIRANGE_REC( 0xA960UL, 0xA97FUL ), /* Hangul Jamo Extended-A */
+ AF_UNIRANGE_REC( 0xAC00UL, 0xD7AFUL ), /* Hangul Syllables */
+ AF_UNIRANGE_REC( 0xD7B0UL, 0xD7FFUL ), /* Hangul Jamo Extended-B */
+ AF_UNIRANGE_REC( 0xF900UL, 0xFAFFUL ), /* CJK Compatibility Ideographs */
+ AF_UNIRANGE_REC( 0xFE10UL, 0xFE1FUL ), /* Vertical forms */
+ AF_UNIRANGE_REC( 0xFE30UL, 0xFE4FUL ), /* CJK Compatibility Forms */
+ AF_UNIRANGE_REC( 0xFF00UL, 0xFFEFUL ), /* Halfwidth and Fullwidth Forms */
+ AF_UNIRANGE_REC( 0x1B000UL, 0x1B0FFUL ), /* Kana Supplement */
+ AF_UNIRANGE_REC( 0x1D300UL, 0x1D35FUL ), /* Tai Xuan Hing Symbols */
+ AF_UNIRANGE_REC( 0x1F200UL, 0x1F2FFUL ), /* Enclosed Ideographic Supplement */
+ AF_UNIRANGE_REC( 0x20000UL, 0x2A6DFUL ), /* CJK Unified Ideographs Extension B */
+ AF_UNIRANGE_REC( 0x2A700UL, 0x2B73FUL ), /* CJK Unified Ideographs Extension C */
+ AF_UNIRANGE_REC( 0x2B740UL, 0x2B81FUL ), /* CJK Unified Ideographs Extension D */
+ AF_UNIRANGE_REC( 0x2F800UL, 0x2FA1FUL ), /* CJK Compatibility Ideographs Supplement */
+ AF_UNIRANGE_REC( 0UL, 0UL )
+ };
+
+#endif /* !AF_CONFIG_OPTION_CJK */
+
+/* END */
diff --git a/freetype/src/autofit/afranges.h b/freetype/src/autofit/afranges.h
new file mode 100644
index 000000000..fe5b2aa7c
--- /dev/null
+++ b/freetype/src/autofit/afranges.h
@@ -0,0 +1,41 @@
+/***************************************************************************/
+/* */
+/* afranges.h */
+/* */
+/* Auto-fitter Unicode script ranges (specification). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __AFRANGES_H__
+#define __AFRANGES_H__
+
+
+#include "aftypes.h"
+
+
+FT_BEGIN_HEADER
+
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ extern const AF_Script_UniRangeRec af_ ## s ## _uniranges[];
+
+#include "afscript.h"
+
+ /* */
+
+FT_END_HEADER
+
+#endif /* __AFRANGES_H__ */
+
+
+/* END */
diff --git a/freetype/src/autofit/afscript.h b/freetype/src/autofit/afscript.h
new file mode 100644
index 000000000..ae209322e
--- /dev/null
+++ b/freetype/src/autofit/afscript.h
@@ -0,0 +1,138 @@
+/***************************************************************************/
+/* */
+/* afscript.h */
+/* */
+/* Auto-fitter scripts (specification only). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+ /* The following part can be included multiple times. */
+ /* Define `SCRIPT' as needed. */
+
+
+ /* Add new scripts here. The first and second arguments are the */
+ /* script name in lowercase and uppercase, respectively, followed */
+ /* by a description string. Then comes the corresponding HarfBuzz */
+ /* script name tag, followed by a string of standard characters (to */
+ /* derive the standard width and height of stems). */
+
+ SCRIPT( cyrl, CYRL,
+ "Cyrillic",
+ HB_SCRIPT_CYRILLIC,
+ 0x43E, 0x41E, 0x0 ) /* оО */
+
+ SCRIPT( grek, GREK,
+ "Greek",
+ HB_SCRIPT_GREEK,
+ 0x3BF, 0x39F, 0x0 ) /* οΟ */
+
+ SCRIPT( hebr, HEBR,
+ "Hebrew",
+ HB_SCRIPT_HEBREW,
+ 0x5DD, 0x0, 0x0 ) /* ם */
+
+ SCRIPT( latn, LATN,
+ "Latin",
+ HB_SCRIPT_LATIN,
+ 'o', 'O', '0' )
+
+ SCRIPT( none, NONE,
+ "no script",
+ HB_SCRIPT_INVALID,
+ 0x0, 0x0, 0x0 )
+
+#ifdef AF_CONFIG_OPTION_INDIC
+
+ SCRIPT( beng, BENG,
+ "Bengali",
+ HB_SCRIPT_BENGALI,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( deva, DEVA,
+ "Devanagari",
+ HB_SCRIPT_DEVANAGARI,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( gujr, GUJR,
+ "Gujarati",
+ HB_SCRIPT_GUJARATI,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( guru, GURU,
+ "Gurmukhi",
+ HB_SCRIPT_GURMUKHI,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( knda, KNDA,
+ "Kannada",
+ HB_SCRIPT_KANNADA,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( limb, LIMB,
+ "Limbu",
+ HB_SCRIPT_LIMBU,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( mlym, MLYM,
+ "Malayalam",
+ HB_SCRIPT_MALAYALAM,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( orya, ORYA,
+ "Oriya",
+ HB_SCRIPT_ORIYA,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( sinh, SINH,
+ "Sinhala",
+ HB_SCRIPT_SINHALA,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( sund, SUND,
+ "Sundanese",
+ HB_SCRIPT_SUNDANESE,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( sylo, SYLO,
+ "Syloti Nagri",
+ HB_SCRIPT_SYLOTI_NAGRI,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( taml, TAML,
+ "Tamil",
+ HB_SCRIPT_TAMIL,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( telu, TELU,
+ "Telugu",
+ HB_SCRIPT_TELUGU,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+ SCRIPT( tibt, TIBT,
+ "Tibetan",
+ HB_SCRIPT_TIBETAN,
+ 'o', 0x0, 0x0 ) /* XXX */
+
+#endif /* AF_CONFIG_OPTION_INDIC */
+
+#ifdef AF_CONFIG_OPTION_CJK
+
+ SCRIPT( hani, HANI,
+ "CJKV ideographs",
+ HB_SCRIPT_HAN,
+ 0x7530, 0x56D7, 0x0 ) /* 田囗 */
+
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+/* END */
diff --git a/freetype/src/autofit/afstyles.h b/freetype/src/autofit/afstyles.h
new file mode 100644
index 000000000..429da7664
--- /dev/null
+++ b/freetype/src/autofit/afstyles.h
@@ -0,0 +1,150 @@
+/***************************************************************************/
+/* */
+/* afstyles.h */
+/* */
+/* Auto-fitter styles (specification only). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+ /* The following part can be included multiple times. */
+ /* Define `STYLE' as needed. */
+
+
+ /* Add new styles here. The first and second arguments are the */
+ /* style name in lowercase and uppercase, respectively, followed */
+ /* by a description string. The next arguments are the */
+ /* corresponding writing system, script, blue stringset, and */
+ /* coverage. */
+ /* */
+ /* Note that styles using `AF_COVERAGE_DEFAULT' should always */
+ /* come after styles with other coverages. */
+ /* */
+ /* Example: */
+ /* */
+ /* STYLE( cyrl_dflt, CYRL_DFLT, */
+ /* "Cyrillic default style", */
+ /* AF_WRITING_SYSTEM_LATIN, */
+ /* AF_SCRIPT_CYRL, */
+ /* AF_BLUE_STRINGSET_CYRL, */
+ /* AF_COVERAGE_DEFAULT ) */
+
+#undef STYLE_LATIN
+#define STYLE_LATIN( s, S, f, F, ds, df, C ) \
+ STYLE( s ## _ ## f, S ## _ ## F, \
+ ds " " df " style", \
+ AF_WRITING_SYSTEM_LATIN, \
+ AF_SCRIPT_ ## S, \
+ AF_BLUE_STRINGSET_ ## S, \
+ AF_COVERAGE_ ## C )
+
+#undef META_STYLE_LATIN
+#define META_STYLE_LATIN( s, S, ds ) \
+ STYLE_LATIN( s, S, c2cp, C2CP, ds, \
+ "petite capticals from capitals", \
+ PETITE_CAPITALS_FROM_CAPITALS ) \
+ STYLE_LATIN( s, S, c2sc, C2SC, ds, \
+ "small capticals from capitals", \
+ SMALL_CAPITALS_FROM_CAPITALS ) \
+ STYLE_LATIN( s, S, ordn, ORDN, ds, \
+ "ordinals", \
+ ORDINALS ) \
+ STYLE_LATIN( s, S, pcap, PCAP, ds, \
+ "petite capitals", \
+ PETITE_CAPITALS ) \
+ STYLE_LATIN( s, S, sinf, SINF, ds, \
+ "scientific inferiors", \
+ SCIENTIFIC_INFERIORS ) \
+ STYLE_LATIN( s, S, smcp, SMCP, ds, \
+ "small capitals", \
+ SMALL_CAPITALS ) \
+ STYLE_LATIN( s, S, subs, SUBS, ds, \
+ "subscript", \
+ SUBSCRIPT ) \
+ STYLE_LATIN( s, S, sups, SUPS, ds, \
+ "superscript", \
+ SUPERSCRIPT ) \
+ STYLE_LATIN( s, S, titl, TITL, ds, \
+ "titling", \
+ TITLING ) \
+ STYLE_LATIN( s, S, dflt, DFLT, ds, \
+ "default", \
+ DEFAULT )
+
+ META_STYLE_LATIN( cyrl, CYRL, "Cyrillic" )
+ META_STYLE_LATIN( grek, GREK, "Greek" )
+ STYLE( hebr_dflt, HEBR_DFLT,
+ "Hebrew default style",
+ AF_WRITING_SYSTEM_LATIN,
+ AF_SCRIPT_HEBR,
+ AF_BLUE_STRINGSET_HEBR,
+ AF_COVERAGE_DEFAULT )
+ META_STYLE_LATIN( latn, LATN, "Latin" )
+
+#ifdef FT_OPTION_AUTOFIT2
+ STYLE( ltn2_dflt, LTN2_DFLT,
+ "Latin 2 default style",
+ AF_WRITING_SYSTEM_LATIN2,
+ AF_SCRIPT_LATN,
+ AF_BLUE_STRINGSET_LATN,
+ AF_COVERAGE_DEFAULT )
+#endif
+
+ STYLE( none_dflt, NONE_DFLT,
+ "no style",
+ AF_WRITING_SYSTEM_DUMMY,
+ AF_SCRIPT_NONE,
+ (AF_Blue_Stringset)0,
+ AF_COVERAGE_DEFAULT )
+
+#ifdef AF_CONFIG_OPTION_INDIC
+
+ /* no blue stringset support for the Indic writing system yet */
+#undef STYLE_DEFAULT_INDIC
+#define STYLE_DEFAULT_INDIC( s, S, d ) \
+ STYLE( s ## _dflt, S ## _DFLT, \
+ d " default style", \
+ AF_WRITING_SYSTEM_INDIC, \
+ AF_SCRIPT_ ## S, \
+ (AF_Blue_Stringset)0, \
+ AF_COVERAGE_DEFAULT )
+
+ STYLE_DEFAULT_INDIC( beng, BENG, "Bengali" )
+ STYLE_DEFAULT_INDIC( deva, DEVA, "Devanagari" )
+ STYLE_DEFAULT_INDIC( gujr, GUJR, "Gujarati" )
+ STYLE_DEFAULT_INDIC( guru, GURU, "Gurmukhi" )
+ STYLE_DEFAULT_INDIC( knda, KNDA, "Kannada" )
+ STYLE_DEFAULT_INDIC( limb, LIMB, "Limbu" )
+ STYLE_DEFAULT_INDIC( mlym, MLYM, "Malayalam" )
+ STYLE_DEFAULT_INDIC( orya, ORYA, "Oriya" )
+ STYLE_DEFAULT_INDIC( sinh, SINH, "Sinhala" )
+ STYLE_DEFAULT_INDIC( sund, SUND, "Sundanese" )
+ STYLE_DEFAULT_INDIC( sylo, SYLO, "Syloti Nagri" )
+ STYLE_DEFAULT_INDIC( taml, TAML, "Tamil" )
+ STYLE_DEFAULT_INDIC( telu, TELU, "Telugu" )
+ STYLE_DEFAULT_INDIC( tibt, TIBT, "Tibetan" )
+
+#endif /* AF_CONFIG_OPTION_INDIC */
+
+#ifdef AF_CONFIG_OPTION_CJK
+
+ STYLE( hani_dflt, HANI_DFLT,
+ "CJKV ideographs default style",
+ AF_WRITING_SYSTEM_CJK,
+ AF_SCRIPT_HANI,
+ AF_BLUE_STRINGSET_HANI,
+ AF_COVERAGE_DEFAULT )
+
+#endif /* AF_CONFIG_OPTION_CJK */
+
+
+/* END */
diff --git a/freetype/src/autofit/aftypes.h b/freetype/src/autofit/aftypes.h
index 191a76f39..9f2331eed 100644
--- a/freetype/src/autofit/aftypes.h
+++ b/freetype/src/autofit/aftypes.h
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter types (specification only). */
/* */
-/* Copyright 2003-2009, 2011-2012 by */
+/* Copyright 2003-2009, 2011-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -20,15 +20,12 @@
*
* The auto-fitter is a complete rewrite of the old auto-hinter.
* Its main feature is the ability to differentiate between different
- * scripts in order to apply language-specific rules.
+ * writing systems and scripts in order to apply specific rules.
*
* The code has also been compartmentized into several entities that
* should make algorithmic experimentation easier than with the old
* code.
*
- * Finally, we get rid of the Catharon license, since this code is
- * released under the FreeType one.
- *
*************************************************************************/
@@ -42,6 +39,8 @@
#include <freetype/internal/ftobjs.h>
#include <freetype/internal/ftdebug.h>
+#include "afblue.h"
+
FT_BEGIN_HEADER
@@ -198,90 +197,124 @@ extern void* _af_debug_hints;
(a)->y_delta == (b)->y_delta )
+ typedef struct AF_StyleMetricsRec_* AF_StyleMetrics;
+
+ /* This function parses an FT_Face to compute global metrics for
+ * a specific style.
+ */
+ typedef FT_Error
+ (*AF_WritingSystem_InitMetricsFunc)( AF_StyleMetrics metrics,
+ FT_Face face );
+
+ typedef void
+ (*AF_WritingSystem_ScaleMetricsFunc)( AF_StyleMetrics metrics,
+ AF_Scaler scaler );
+
+ typedef void
+ (*AF_WritingSystem_DoneMetricsFunc)( AF_StyleMetrics metrics );
+
+
+ typedef FT_Error
+ (*AF_WritingSystem_InitHintsFunc)( AF_GlyphHints hints,
+ AF_StyleMetrics metrics );
+
+ typedef void
+ (*AF_WritingSystem_ApplyHintsFunc)( AF_GlyphHints hints,
+ FT_Outline* outline,
+ AF_StyleMetrics metrics );
+
+
/*************************************************************************/
/*************************************************************************/
/***** *****/
- /***** S C R I P T S *****/
+ /***** W R I T I N G S Y S T E M S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
- * The list of known scripts. Each different script corresponds to the
- * following information:
- *
- * - A set of Unicode ranges to test whether the face supports the
- * script.
+ * For the auto-hinter, a writing system consists of multiple scripts that
+ * can be handled similarly *in a typographical way*; the relationship is
+ * not based on history. For example, both the Greek and the unrelated
+ * Armenian scripts share the same features like ascender, descender,
+ * x-height, etc. Essentially, a writing system is covered by a
+ * submodule of the auto-fitter; it contains
*
- * - A specific global analyzer that will compute global metrics
- * specific to the script.
+ * - a specific global analyzer that computes global metrics specific to
+ * the script (based on script-specific characters to identify ascender
+ * height, x-height, etc.),
*
- * - A specific glyph analyzer that will compute segments and
- * edges for each glyph covered by the script.
+ * - a specific glyph analyzer that computes segments and edges for each
+ * glyph covered by the script,
*
- * - A specific grid-fitting algorithm that will distort the
- * scaled glyph outline according to the results of the glyph
- * analyzer.
- *
- * Note that a given analyzer and/or grid-fitting algorithm can be
- * used by more than one script.
+ * - a specific grid-fitting algorithm that distorts the scaled glyph
+ * outline according to the results of the glyph analyzer.
*/
- typedef enum AF_Script_
+#define __AFWRTSYS_H__ /* don't load header files */
+#undef WRITING_SYSTEM
+#define WRITING_SYSTEM( ws, WS ) \
+ AF_WRITING_SYSTEM_ ## WS,
+
+ /* The list of known writing systems. */
+ typedef enum AF_WritingSystem_
{
- AF_SCRIPT_DUMMY = 0,
- AF_SCRIPT_LATIN = 1,
- AF_SCRIPT_CJK = 2,
- AF_SCRIPT_INDIC = 3,
-#ifdef FT_OPTION_AUTOFIT2
- AF_SCRIPT_LATIN2 = 4,
-#endif
- /* add new scripts here. Don't forget to update the list in */
- /* `afglobal.c'. */
+#include "afwrtsys.h"
- AF_SCRIPT_MAX /* do not remove */
+ AF_WRITING_SYSTEM_MAX /* do not remove */
- } AF_Script;
+ } AF_WritingSystem;
+#undef __AFWRTSYS_H__
- typedef struct AF_ScriptClassRec_ const* AF_ScriptClass;
- typedef struct AF_FaceGlobalsRec_* AF_FaceGlobals;
- typedef struct AF_ScriptMetricsRec_
+ typedef struct AF_WritingSystemClassRec_
{
- AF_ScriptClass clazz;
- AF_ScalerRec scaler;
- FT_Bool digits_have_same_width;
+ AF_WritingSystem writing_system;
- AF_FaceGlobals globals; /* to access properties */
+ FT_Offset style_metrics_size;
+ AF_WritingSystem_InitMetricsFunc style_metrics_init;
+ AF_WritingSystem_ScaleMetricsFunc style_metrics_scale;
+ AF_WritingSystem_DoneMetricsFunc style_metrics_done;
- } AF_ScriptMetricsRec, *AF_ScriptMetrics;
+ AF_WritingSystem_InitHintsFunc style_hints_init;
+ AF_WritingSystem_ApplyHintsFunc style_hints_apply;
+ } AF_WritingSystemClassRec;
- /* This function parses an FT_Face to compute global metrics for
- * a specific script.
+ typedef const AF_WritingSystemClassRec* AF_WritingSystemClass;
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** S C R I P T S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /*
+ * Each script is associated with a set of Unicode ranges that gets used
+ * to test whether the font face supports the script.
+ *
+ * We use four-letter script tags from the OpenType specification,
+ * extended by `NONE', which indicates `no script'.
*/
- typedef FT_Error
- (*AF_Script_InitMetricsFunc)( AF_ScriptMetrics metrics,
- FT_Face face );
- typedef void
- (*AF_Script_ScaleMetricsFunc)( AF_ScriptMetrics metrics,
- AF_Scaler scaler );
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
+ AF_SCRIPT_ ## S,
- typedef void
- (*AF_Script_DoneMetricsFunc)( AF_ScriptMetrics metrics );
+ /* The list of known scripts. */
+ typedef enum AF_Script_
+ {
+#include "afscript.h"
- typedef FT_Error
- (*AF_Script_InitHintsFunc)( AF_GlyphHints hints,
- AF_ScriptMetrics metrics );
+ AF_SCRIPT_MAX /* do not remove */
- typedef void
- (*AF_Script_ApplyHintsFunc)( AF_GlyphHints hints,
- FT_Outline* outline,
- AF_ScriptMetrics metrics );
+ } AF_Script;
typedef struct AF_Script_UniRangeRec_
@@ -293,76 +326,300 @@ extern void* _af_debug_hints;
#define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
- typedef const AF_Script_UniRangeRec *AF_Script_UniRange;
+ typedef const AF_Script_UniRangeRec* AF_Script_UniRange;
typedef struct AF_ScriptClassRec_
{
- AF_Script script;
- AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
- FT_UInt32 standard_char; /* for default width and height */
+ AF_Script script;
- FT_Offset script_metrics_size;
- AF_Script_InitMetricsFunc script_metrics_init;
- AF_Script_ScaleMetricsFunc script_metrics_scale;
- AF_Script_DoneMetricsFunc script_metrics_done;
+ AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
- AF_Script_InitHintsFunc script_hints_init;
- AF_Script_ApplyHintsFunc script_hints_apply;
+ FT_UInt32 standard_char1; /* for default width and height */
+ FT_UInt32 standard_char2; /* ditto */
+ FT_UInt32 standard_char3; /* ditto */
} AF_ScriptClassRec;
+ typedef const AF_ScriptClassRec* AF_ScriptClass;
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** C O V E R A G E S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /*
+ * Usually, a font contains more glyphs than can be addressed by its
+ * character map.
+ *
+ * In the PostScript font world, encoding vectors specific to a given
+ * task are used to select such glyphs, and these glyphs can be often
+ * recognized by having a suffix in its glyph names. For example, a
+ * superscript glyph `A' might be called `A.sup'. Unfortunately, this
+ * naming scheme is not standardized and thus unusable for us.
+ *
+ * In the OpenType world, a better solution was invented, namely
+ * `features', which cleanly separate a character's input encoding from
+ * the corresponding glyph's appearance, and which don't use glyph names
+ * at all. For our purposes, and slightly generalized, an OpenType
+ * feature is a name of a mapping that maps character codes to
+ * non-standard glyph indices (features get used for other things also).
+ * For example, the `sups' feature provides superscript glyphs, thus
+ * mapping character codes like `A' or `B' to superscript glyph
+ * representation forms. How this mapping happens is completely
+ * uninteresting to us.
+ *
+ * For the auto-hinter, a `coverage' represents all glyphs of an OpenType
+ * feature collected in a set (as listed below) that can be hinted
+ * together. To continue the above example, superscript glyphs must not
+ * be hinted together with normal glyphs because the blue zones
+ * completely differ.
+ *
+ * Note that FreeType itself doesn't compute coverages; it only provides
+ * the glyphs addressable by the default Unicode character map. Instead,
+ * we use the HarfBuzz library (if available), which has many functions
+ * exactly for this purpose.
+ *
+ * AF_COVERAGE_DEFAULT is special: It should cover everything that isn't
+ * listed separately (including the glyphs addressable by the character
+ * map). In case HarfBuzz isn't available, it exactly covers the glyphs
+ * addressable by the character map.
+ *
+ */
+
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ AF_COVERAGE_ ## NAME,
+
+
+ typedef enum AF_Coverage_
+ {
+#include "afcover.h"
+
+ AF_COVERAGE_DEFAULT
+
+ } AF_Coverage;
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** S T Y L E S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ /*
+ * The topmost structure for modelling the auto-hinter glyph input data
+ * is a `style class', grouping everything together.
+ */
+
+#undef STYLE
+#define STYLE( s, S, d, ws, sc, ss, c ) \
+ AF_STYLE_ ## S,
+
+ /* The list of known styles. */
+ typedef enum AF_Style_
+ {
+
+#include "afstyles.h"
+
+ AF_STYLE_MAX /* do not remove */
+
+ } AF_Style;
+
+
+ typedef struct AF_StyleClassRec_
+ {
+ AF_Style style;
+
+ AF_WritingSystem writing_system;
+ AF_Script script;
+ AF_Blue_Stringset blue_stringset;
+ AF_Coverage coverage;
+
+ } AF_StyleClassRec;
+
+ typedef const AF_StyleClassRec* AF_StyleClass;
+
+
+ /*************************************************************************/
+ /*************************************************************************/
+ /***** *****/
+ /***** S T Y L E M E T R I C S *****/
+ /***** *****/
+ /*************************************************************************/
+ /*************************************************************************/
+
+ typedef struct AF_FaceGlobalsRec_* AF_FaceGlobals;
+
+ /* This is the main structure that combines everything. Autofit modules */
+ /* specific to writing systems derive their structures from it, for */
+ /* example `AF_LatinMetrics'. */
+
+ typedef struct AF_StyleMetricsRec_
+ {
+ AF_StyleClass style_class;
+ AF_ScalerRec scaler;
+ FT_Bool digits_have_same_width;
+
+ AF_FaceGlobals globals; /* to access properties */
+
+ } AF_StyleMetricsRec;
+
/* Declare and define vtables for classes */
#ifndef FT_CONFIG_OPTION_PIC
+#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
+ FT_CALLBACK_TABLE const AF_WritingSystemClassRec \
+ writing_system_class;
+
+#define AF_DEFINE_WRITING_SYSTEM_CLASS( \
+ writing_system_class, \
+ system, \
+ m_size, \
+ m_init, \
+ m_scale, \
+ m_done, \
+ h_init, \
+ h_apply ) \
+ FT_CALLBACK_TABLE_DEF \
+ const AF_WritingSystemClassRec writing_system_class = \
+ { \
+ system, \
+ \
+ m_size, \
+ \
+ m_init, \
+ m_scale, \
+ m_done, \
+ \
+ h_init, \
+ h_apply \
+ };
+
+
#define AF_DECLARE_SCRIPT_CLASS( script_class ) \
FT_CALLBACK_TABLE const AF_ScriptClassRec \
script_class;
-#define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, def_char, \
- m_size, \
- m_init, m_scale, m_done, h_init, h_apply ) \
- FT_CALLBACK_TABLE_DEF const AF_ScriptClassRec script_class = \
- { \
- script_, \
- ranges, \
- def_char, \
- \
- m_size, \
- \
- m_init, \
- m_scale, \
- m_done, \
- \
- h_init, \
- h_apply \
+#define AF_DEFINE_SCRIPT_CLASS( \
+ script_class, \
+ script, \
+ ranges, \
+ std_char1, \
+ std_char2, \
+ std_char3 ) \
+ FT_CALLBACK_TABLE_DEF \
+ const AF_ScriptClassRec script_class = \
+ { \
+ script, \
+ ranges, \
+ std_char1, \
+ std_char2, \
+ std_char3 \
+ };
+
+
+#define AF_DECLARE_STYLE_CLASS( style_class ) \
+ FT_CALLBACK_TABLE const AF_StyleClassRec \
+ style_class;
+
+#define AF_DEFINE_STYLE_CLASS( \
+ style_class, \
+ style, \
+ writing_system, \
+ script, \
+ blue_stringset, \
+ coverage ) \
+ FT_CALLBACK_TABLE_DEF \
+ const AF_StyleClassRec style_class = \
+ { \
+ style, \
+ writing_system, \
+ script, \
+ blue_stringset, \
+ coverage \
};
#else /* FT_CONFIG_OPTION_PIC */
+#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
+ FT_LOCAL( void ) \
+ FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec* ac );
+
+#define AF_DEFINE_WRITING_SYSTEM_CLASS( \
+ writing_system_class, \
+ system, \
+ m_size, \
+ m_init, \
+ m_scale, \
+ m_done, \
+ h_init, \
+ h_apply ) \
+ FT_LOCAL_DEF( void ) \
+ FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec* ac ) \
+ { \
+ ac->writing_system = system; \
+ \
+ ac->style_metrics_size = m_size; \
+ \
+ ac->style_metrics_init = m_init; \
+ ac->style_metrics_scale = m_scale; \
+ ac->style_metrics_done = m_done; \
+ \
+ ac->style_hints_init = h_init; \
+ ac->style_hints_apply = h_apply; \
+ }
+
+
#define AF_DECLARE_SCRIPT_CLASS( script_class ) \
FT_LOCAL( void ) \
FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac );
-#define AF_DEFINE_SCRIPT_CLASS( script_class, script_, ranges, def_char, \
- m_size, \
- m_init, m_scale, m_done, h_init, h_apply ) \
- FT_LOCAL_DEF( void ) \
- FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac ) \
- { \
- ac->script = script_; \
- ac->script_uni_ranges = ranges; \
- ac->default_char = def_char; \
- \
- ac->script_metrics_size = m_size; \
- \
- ac->script_metrics_init = m_init; \
- ac->script_metrics_scale = m_scale; \
- ac->script_metrics_done = m_done; \
- \
- ac->script_hints_init = h_init; \
- ac->script_hints_apply = h_apply; \
+#define AF_DEFINE_SCRIPT_CLASS( \
+ script_class, \
+ script_, \
+ ranges, \
+ std_char1, \
+ std_char2, \
+ std_char3 ) \
+ FT_LOCAL_DEF( void ) \
+ FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac ) \
+ { \
+ ac->script = script_; \
+ ac->script_uni_ranges = ranges; \
+ ac->standard_char1 = std_char1; \
+ ac->standard_char2 = std_char2; \
+ ac->standard_char3 = std_char3; \
+ }
+
+
+#define AF_DECLARE_STYLE_CLASS( style_class ) \
+ FT_LOCAL( void ) \
+ FT_Init_Class_ ## style_class( AF_StyleClassRec* ac );
+
+#define AF_DEFINE_STYLE_CLASS( \
+ style_class, \
+ style_, \
+ writing_system_, \
+ script_, \
+ blue_stringset_, \
+ coverage_ ) \
+ FT_LOCAL_DEF( void ) \
+ FT_Init_Class_ ## style_class( AF_StyleClassRec* ac ) \
+ { \
+ ac->style = style_; \
+ ac->writing_system = writing_system_; \
+ ac->script = script_; \
+ ac->blue_stringset = blue_stringset_; \
+ ac->coverage = coverage_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
diff --git a/freetype/src/autofit/afwrtsys.h b/freetype/src/autofit/afwrtsys.h
new file mode 100644
index 000000000..8aa2ed9e6
--- /dev/null
+++ b/freetype/src/autofit/afwrtsys.h
@@ -0,0 +1,52 @@
+/***************************************************************************/
+/* */
+/* afwrtsys.h */
+/* */
+/* Auto-fitter writing systems (specification only). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __AFWRTSYS_H__
+#define __AFWRTSYS_H__
+
+ /* Since preprocessor directives can't create other preprocessor */
+ /* directives, we have to include the header files manually. */
+
+#include "afdummy.h"
+#include "aflatin.h"
+#include "afcjk.h"
+#include "afindic.h"
+#ifdef FT_OPTION_AUTOFIT2
+#include "aflatin2.h"
+#endif
+
+#endif /* __AFWRTSYS_H__ */
+
+
+ /* The following part can be included multiple times. */
+ /* Define `WRITING_SYSTEM' as needed. */
+
+
+ /* Add new writing systems here. The arguments are the writing system */
+ /* name in lowercase and uppercase, respectively. */
+
+ WRITING_SYSTEM( dummy, DUMMY )
+ WRITING_SYSTEM( latin, LATIN )
+ WRITING_SYSTEM( cjk, CJK )
+ WRITING_SYSTEM( indic, INDIC )
+#ifdef FT_OPTION_AUTOFIT2
+ WRITING_SYSTEM( latin2, LATIN2 )
+#endif
+
+
+/* END */
diff --git a/freetype/src/autofit/autofit.c b/freetype/src/autofit/autofit.c
index 3883a0a70..e2b9934e4 100644
--- a/freetype/src/autofit/autofit.c
+++ b/freetype/src/autofit/autofit.c
@@ -4,7 +4,7 @@
/* */
/* Auto-fitter module (body). */
/* */
-/* Copyright 2003-2007, 2011 by */
+/* Copyright 2003-2007, 2011, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -20,9 +20,12 @@
#include <ft2build.h>
#include "afpic.c"
#include "afangles.c"
+#include "afblue.c"
#include "afglobal.c"
#include "afhints.c"
+#include "afranges.c"
+
#include "afdummy.c"
#include "aflatin.c"
#ifdef FT_OPTION_AUTOFIT2
@@ -31,6 +34,8 @@
#include "afcjk.c"
#include "afindic.c"
+#include "hbshim.c"
+
#include "afloader.c"
#include "afmodule.c"
diff --git a/freetype/src/autofit/hbshim.c b/freetype/src/autofit/hbshim.c
new file mode 100644
index 000000000..11fb743e8
--- /dev/null
+++ b/freetype/src/autofit/hbshim.c
@@ -0,0 +1,531 @@
+/***************************************************************************/
+/* */
+/* hbshim.c */
+/* */
+/* HarfBuzz interface for accessing OpenType features (body). */
+/* */
+/* Copyright 2013, 2014 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include "afglobal.h"
+#include "aftypes.h"
+#include "hbshim.h"
+
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+
+
+ /*************************************************************************/
+ /* */
+ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
+ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
+ /* messages during execution. */
+ /* */
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_afharfbuzz
+
+
+ /*
+ * We use `sets' (in the HarfBuzz sense, which comes quite near to the
+ * usual mathematical meaning) to manage both lookups and glyph indices.
+ *
+ * 1. For each coverage, collect lookup IDs in a set. Note that an
+ * auto-hinter `coverage' is represented by one `feature', and a
+ * feature consists of an arbitrary number of (font specific) `lookup's
+ * that actually do the mapping job. Please check the OpenType
+ * specification for more details on features and lookups.
+ *
+ * 2. Create glyph ID sets from the corresponding lookup sets.
+ *
+ * 3. The glyph set corresponding to AF_COVERAGE_DEFAULT is computed
+ * with all lookups specific to the OpenType script activated. It
+ * relies on the order of AF_DEFINE_STYLE_CLASS entries so that
+ * special coverages (like `oldstyle figures') don't get overwritten.
+ *
+ */
+
+
+ /* load coverage tags */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ static const hb_tag_t name ## _coverage[] = \
+ { \
+ HB_TAG( tag1, tag2, tag3, tag4 ), \
+ HB_TAG_NONE \
+ };
+
+
+#include "afcover.h"
+
+
+ /* define mapping between coverage tags and AF_Coverage */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ name ## _coverage,
+
+
+ static const hb_tag_t* coverages[] =
+ {
+#include "afcover.h"
+
+ NULL /* AF_COVERAGE_DEFAULT */
+ };
+
+
+ /* load HarfBuzz script tags */
+#undef SCRIPT
+#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) h,
+
+
+ static const hb_script_t scripts[] =
+ {
+#include "afscript.h"
+ };
+
+
+ FT_Error
+ af_get_coverage( AF_FaceGlobals globals,
+ AF_StyleClass style_class,
+ FT_Byte* gstyles )
+ {
+ hb_face_t* face;
+
+ hb_set_t* gsub_lookups; /* GSUB lookups for a given script */
+ hb_set_t* gsub_glyphs; /* glyphs covered by GSUB lookups */
+ hb_set_t* gpos_lookups; /* GPOS lookups for a given script */
+ hb_set_t* gpos_glyphs; /* glyphs covered by GPOS lookups */
+
+ hb_script_t script;
+ const hb_tag_t* coverage_tags;
+ hb_tag_t script_tags[] = { HB_TAG_NONE,
+ HB_TAG_NONE,
+ HB_TAG_NONE,
+ HB_TAG_NONE };
+
+ hb_codepoint_t idx;
+#ifdef FT_DEBUG_LEVEL_TRACE
+ int count;
+#endif
+
+
+ if ( !globals || !style_class || !gstyles )
+ return FT_THROW( Invalid_Argument );
+
+ face = hb_font_get_face( globals->hb_font );
+
+ gsub_lookups = hb_set_create();
+ gsub_glyphs = hb_set_create();
+ gpos_lookups = hb_set_create();
+ gpos_glyphs = hb_set_create();
+
+ coverage_tags = coverages[style_class->coverage];
+ script = scripts[style_class->script];
+
+ /* Convert a HarfBuzz script tag into the corresponding OpenType */
+ /* tag or tags -- some Indic scripts like Devanagari have an old */
+ /* and a new set of features. */
+ hb_ot_tags_from_script( script,
+ &script_tags[0],
+ &script_tags[1] );
+
+ /* `hb_ot_tags_from_script' usually returns HB_OT_TAG_DEFAULT_SCRIPT */
+ /* as the second tag. We change that to HB_TAG_NONE except for the */
+ /* default script. */
+ if ( style_class->script == globals->module->default_script &&
+ style_class->coverage == AF_COVERAGE_DEFAULT )
+ {
+ if ( script_tags[0] == HB_TAG_NONE )
+ script_tags[0] = HB_OT_TAG_DEFAULT_SCRIPT;
+ else
+ {
+ if ( script_tags[1] == HB_TAG_NONE )
+ script_tags[1] = HB_OT_TAG_DEFAULT_SCRIPT;
+ else if ( script_tags[1] != HB_OT_TAG_DEFAULT_SCRIPT )
+ script_tags[2] = HB_OT_TAG_DEFAULT_SCRIPT;
+ }
+ }
+ else
+ {
+ if ( script_tags[1] == HB_OT_TAG_DEFAULT_SCRIPT )
+ script_tags[1] = HB_TAG_NONE;
+ }
+
+ hb_ot_layout_collect_lookups( face,
+ HB_OT_TAG_GSUB,
+ script_tags,
+ NULL,
+ coverage_tags,
+ gsub_lookups );
+
+ if ( hb_set_is_empty( gsub_lookups ) )
+ goto Exit; /* nothing to do */
+
+ hb_ot_layout_collect_lookups( face,
+ HB_OT_TAG_GPOS,
+ script_tags,
+ NULL,
+ coverage_tags,
+ gpos_lookups );
+
+ FT_TRACE4(( "GSUB lookups (style `%s'):\n"
+ " ",
+ af_style_names[style_class->style] ));
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ count = 0;
+#endif
+
+ for ( idx = -1; hb_set_next( gsub_lookups, &idx ); )
+ {
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_TRACE4(( " %d", idx ));
+ count++;
+#endif
+
+ /* get output coverage of GSUB feature */
+ hb_ot_layout_lookup_collect_glyphs( face,
+ HB_OT_TAG_GSUB,
+ idx,
+ NULL,
+ NULL,
+ NULL,
+ gsub_glyphs );
+ }
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( !count )
+ FT_TRACE4(( " (none)" ));
+ FT_TRACE4(( "\n\n" ));
+#endif
+
+ FT_TRACE4(( "GPOS lookups (style `%s'):\n"
+ " ",
+ af_style_names[style_class->style] ));
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ count = 0;
+#endif
+
+ for ( idx = -1; hb_set_next( gpos_lookups, &idx ); )
+ {
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_TRACE4(( " %d", idx ));
+ count++;
+#endif
+
+ /* get input coverage of GPOS feature */
+ hb_ot_layout_lookup_collect_glyphs( face,
+ HB_OT_TAG_GPOS,
+ idx,
+ NULL,
+ gpos_glyphs,
+ NULL,
+ NULL );
+ }
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( !count )
+ FT_TRACE4(( " (none)" ));
+ FT_TRACE4(( "\n\n" ));
+#endif
+
+ /*
+ * We now check whether we can construct blue zones, using glyphs
+ * covered by the feature only. In case there is not a single zone
+ * (this is, not a single character is covered), we skip this coverage.
+ *
+ */
+ {
+ AF_Blue_Stringset bss = style_class->blue_stringset;
+ const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
+
+ FT_Bool found = 0;
+
+
+ for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
+ {
+ const char* p = &af_blue_strings[bs->string];
+
+
+ while ( *p )
+ {
+ hb_codepoint_t ch;
+
+
+ GET_UTF8_CHAR( ch, p );
+
+ for ( idx = -1; hb_set_next( gsub_lookups, &idx ); )
+ {
+ hb_codepoint_t gidx = FT_Get_Char_Index( globals->face, ch );
+
+
+ if ( hb_ot_layout_lookup_would_substitute( face, idx,
+ &gidx, 1, 1 ) )
+ {
+ found = 1;
+ break;
+ }
+ }
+ }
+ }
+
+ if ( !found )
+ {
+ FT_TRACE4(( " no blue characters found; style skipped\n" ));
+ goto Exit;
+ }
+ }
+
+ /*
+ * Various OpenType features might use the same glyphs at different
+ * vertical positions; for example, superscript and subscript glyphs
+ * could be the same. However, the auto-hinter is completely
+ * agnostic of OpenType features after the feature analysis has been
+ * completed: The engine then simply receives a glyph index and returns a
+ * hinted and usually rendered glyph.
+ *
+ * Consider the superscript feature of font `pala.ttf': Some of the
+ * glyphs are `real', this is, they have a zero vertical offset, but
+ * most of them are small caps glyphs shifted up to the superscript
+ * position (this is, the `sups' feature is present in both the GSUB and
+ * GPOS tables). The code for blue zones computation actually uses a
+ * feature's y offset so that the `real' glyphs get correct hints. But
+ * later on it is impossible to decide whether a glyph index belongs to,
+ * say, the small caps or superscript feature.
+ *
+ * For this reason, we don't assign a style to a glyph if the current
+ * feature covers the glyph in both the GSUB and the GPOS tables. This
+ * is quite a broad condition, assuming that
+ *
+ * (a) glyphs that get used in multiple features are present in a
+ * feature without vertical shift,
+ *
+ * and
+ *
+ * (b) a feature's GPOS data really moves the glyph vertically.
+ *
+ * Not fulfilling condition (a) makes a font larger; it would also
+ * reduce the number of glyphs that could be addressed directly without
+ * using OpenType features, so this assumption is rather strong.
+ *
+ * Condition (b) is much weaker, and there might be glyphs which get
+ * missed. However, the OpenType features we are going to handle are
+ * primarily located in GSUB, and HarfBuzz doesn't provide an API to
+ * directly get the necessary information from the GPOS table. A
+ * possible solution might be to directly parse the GPOS table to find
+ * out whether a glyph gets shifted vertically, but this is something I
+ * would like to avoid if not really necessary.
+ *
+ */
+ hb_set_subtract( gsub_glyphs, gpos_glyphs );
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ FT_TRACE4(( " glyphs without GPOS data (`*' means already assigned)" ));
+ count = 0;
+#endif
+
+ for ( idx = -1; hb_set_next( gsub_glyphs, &idx ); )
+ {
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( !( count % 10 ) )
+ FT_TRACE4(( "\n"
+ " " ));
+
+ FT_TRACE4(( " %d", idx ));
+ count++;
+#endif
+
+ if ( gstyles[idx] == AF_STYLE_UNASSIGNED )
+ gstyles[idx] = (FT_Byte)style_class->style;
+#ifdef FT_DEBUG_LEVEL_TRACE
+ else
+ FT_TRACE4(( "*" ));
+#endif
+ }
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( !count )
+ FT_TRACE4(( "\n"
+ " (none)" ));
+ FT_TRACE4(( "\n\n" ));
+#endif
+
+ Exit:
+ hb_set_destroy( gsub_lookups );
+ hb_set_destroy( gsub_glyphs );
+ hb_set_destroy( gpos_lookups );
+ hb_set_destroy( gpos_glyphs );
+
+ return FT_Err_Ok;
+ }
+
+
+ /* construct HarfBuzz features */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ static const hb_feature_t name ## _feature[] = \
+ { \
+ { \
+ HB_TAG( tag1, tag2, tag3, tag4 ), \
+ 1, 0, (unsigned int)-1 \
+ } \
+ };
+
+
+#include "afcover.h"
+
+
+ /* define mapping between HarfBuzz features and AF_Coverage */
+#undef COVERAGE
+#define COVERAGE( name, NAME, description, \
+ tag1, tag2, tag3, tag4 ) \
+ name ## _feature,
+
+
+ static const hb_feature_t* features[] =
+ {
+#include "afcover.h"
+
+ NULL /* AF_COVERAGE_DEFAULT */
+ };
+
+
+ FT_Error
+ af_get_char_index( AF_StyleMetrics metrics,
+ FT_ULong charcode,
+ FT_ULong *codepoint,
+ FT_Long *y_offset )
+ {
+ AF_StyleClass style_class;
+
+ const hb_feature_t* feature;
+
+ FT_ULong in_idx, out_idx;
+
+
+ if ( !metrics )
+ return FT_THROW( Invalid_Argument );
+
+ in_idx = FT_Get_Char_Index( metrics->globals->face, charcode );
+
+ style_class = metrics->style_class;
+
+ feature = features[style_class->coverage];
+
+ if ( feature )
+ {
+ FT_UInt upem = metrics->globals->face->units_per_EM;
+
+ hb_font_t* font = metrics->globals->hb_font;
+ hb_buffer_t* buf = hb_buffer_create();
+
+ uint32_t c = (uint32_t)charcode;
+
+ hb_glyph_info_t* ginfo;
+ hb_glyph_position_t* gpos;
+ unsigned int gcount;
+
+
+ /* we shape at a size of units per EM; this means font units */
+ hb_font_set_scale( font, upem, upem );
+
+ /* XXX: is this sufficient for a single character of any script? */
+ hb_buffer_set_direction( buf, HB_DIRECTION_LTR );
+ hb_buffer_set_script( buf, scripts[style_class->script] );
+
+ /* we add one character to `buf' ... */
+ hb_buffer_add_utf32( buf, &c, 1, 0, 1 );
+
+ /* ... and apply one feature */
+ hb_shape( font, buf, feature, 1 );
+
+ ginfo = hb_buffer_get_glyph_infos( buf, &gcount );
+ gpos = hb_buffer_get_glyph_positions( buf, &gcount );
+
+ out_idx = ginfo[0].codepoint;
+
+ /* getting the same index indicates no substitution, */
+ /* which means that the glyph isn't available in the feature */
+ if ( in_idx == out_idx )
+ {
+ *codepoint = 0;
+ *y_offset = 0;
+ }
+ else
+ {
+ *codepoint = out_idx;
+ *y_offset = gpos[0].y_offset;
+ }
+
+ hb_buffer_destroy( buf );
+
+#ifdef FT_DEBUG_LEVEL_TRACE
+ if ( gcount > 1 )
+ FT_TRACE1(( "af_get_char_index:"
+ " input character mapped to multiple glyphs\n" ));
+#endif
+ }
+ else
+ {
+ *codepoint = in_idx;
+ *y_offset = 0;
+ }
+
+ return FT_Err_Ok;
+ }
+
+
+#else /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
+
+
+ FT_Error
+ af_get_coverage( AF_FaceGlobals globals,
+ AF_StyleClass style_class,
+ FT_Byte* gstyles )
+ {
+ FT_UNUSED( globals );
+ FT_UNUSED( style_class );
+ FT_UNUSED( gstyles );
+
+ return FT_Err_Ok;
+ }
+
+
+ FT_Error
+ af_get_char_index( AF_StyleMetrics metrics,
+ FT_ULong charcode,
+ FT_ULong *codepoint,
+ FT_Long *y_offset )
+ {
+ FT_Face face;
+
+
+ if ( !metrics )
+ return FT_THROW( Invalid_Argument );
+
+ face = metrics->globals->face;
+
+ *codepoint = FT_Get_Char_Index( face, charcode );
+ *y_offset = 0;
+
+ return FT_Err_Ok;
+ }
+
+
+#endif /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
+
+
+/* END */
diff --git a/freetype/src/autofit/hbshim.h b/freetype/src/autofit/hbshim.h
new file mode 100644
index 000000000..02f1513f6
--- /dev/null
+++ b/freetype/src/autofit/hbshim.h
@@ -0,0 +1,56 @@
+/***************************************************************************/
+/* */
+/* hbshim.h */
+/* */
+/* HarfBuzz interface for accessing OpenType features (specification). */
+/* */
+/* Copyright 2013 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __HBSHIM_H__
+#define __HBSHIM_H__
+
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+
+#include <hb.h>
+#include <hb-ot.h>
+#include <hb-ft.h>
+
+#endif
+
+
+FT_BEGIN_HEADER
+
+ FT_Error
+ af_get_coverage( AF_FaceGlobals globals,
+ AF_StyleClass style_class,
+ FT_Byte* gstyles );
+
+ FT_Error
+ af_get_char_index( AF_StyleMetrics metrics,
+ FT_ULong charcode,
+ FT_ULong *codepoint,
+ FT_Long *y_offset );
+
+ /* */
+
+FT_END_HEADER
+
+#endif /* __HBSHIM_H__ */
+
+
+/* END */
diff --git a/freetype/src/autofit/rules.mk b/freetype/src/autofit/rules.mk
index b76bb79ab..658f04ea5 100644
--- a/freetype/src/autofit/rules.mk
+++ b/freetype/src/autofit/rules.mk
@@ -3,7 +3,7 @@
#
-# Copyright 2003, 2004, 2005, 2006, 2007, 2011 by
+# Copyright 2003-2007, 2011, 2013 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
@@ -26,6 +26,7 @@ AUTOF_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(AUTOF_DIR))
# AUTOF driver sources (i.e., C files)
#
AUTOF_DRV_SRC := $(AUTOF_DIR)/afangles.c \
+ $(AUTOF_DIR)/afblue.c \
$(AUTOF_DIR)/afcjk.c \
$(AUTOF_DIR)/afdummy.c \
$(AUTOF_DIR)/afglobal.c \
@@ -35,13 +36,19 @@ AUTOF_DRV_SRC := $(AUTOF_DIR)/afangles.c \
$(AUTOF_DIR)/afloader.c \
$(AUTOF_DIR)/afmodule.c \
$(AUTOF_DIR)/afpic.c \
- $(AUTOF_DIR)/afwarp.c
+ $(AUTOF_DIR)/afranges.c \
+ $(AUTOF_DIR)/afwarp.c \
+ $(AUTOF_DIR)/hbshim.c
# AUTOF driver headers
#
AUTOF_DRV_H := $(AUTOF_DRV_SRC:%c=%h) \
+ $(AUTOF_DIR)/afcover.h \
$(AUTOF_DIR)/aferrors.h \
- $(AUTOF_DIR)/aftypes.h
+ $(AUTOF_DIR)/afscript.h \
+ $(AUTOF_DIR)/afstyles.h \
+ $(AUTOF_DIR)/aftypes.h \
+ $(AUTOF_DIR)/afwrtsys.h
# AUTOF driver object(s)
diff --git a/freetype/src/base/basepic.c b/freetype/src/base/basepic.c
index 222772b41..fa7bf5142 100644
--- a/freetype/src/base/basepic.c
+++ b/freetype/src/base/basepic.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType position independent code services for base. */
/* */
-/* Copyright 2009, 2012 by */
+/* Copyright 2009, 2012, 2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -35,7 +35,7 @@
/* forward declaration of PIC init function from ftrfork.c */
/* (not modularized) */
void
- FT_Init_Table_raccess_guess_table( ft_raccess_guess_rec* record );
+ FT_Init_Table_ft_raccess_guess_table( ft_raccess_guess_rec* record );
#endif
/* forward declaration of PIC init functions from ftinit.c */
@@ -75,7 +75,7 @@
/* allocate pointer, clear and set global container pointer */
- if ( FT_ALLOC ( container, sizeof ( *container ) ) )
+ if ( FT_ALLOC( container, sizeof ( *container ) ) )
return error;
FT_MEM_SET( container, 0, sizeof ( *container ) );
pic_container->base = container;
@@ -92,17 +92,16 @@
FT_Init_Class_ft_bitmap_glyph_class(
&container->ft_bitmap_glyph_class );
#ifdef FT_CONFIG_OPTION_MAC_FONTS
- FT_Init_Table_raccess_guess_table(
+ FT_Init_Table_ft_raccess_guess_table(
(ft_raccess_guess_rec*)&container->ft_raccess_guess_table );
#endif
-Exit:
- if( error )
+ Exit:
+ if ( error )
ft_base_pic_free( library );
return error;
}
-
#endif /* FT_CONFIG_OPTION_PIC */
diff --git a/freetype/src/base/ftbbox.c b/freetype/src/base/ftbbox.c
index a01b68161..e04cbdaaf 100644
--- a/freetype/src/base/ftbbox.c
+++ b/freetype/src/base/ftbbox.c
@@ -85,7 +85,7 @@
/* BBox_Conic_Check */
/* */
/* <Description> */
- /* Finds the extrema of a 1-dimensional conic Bezier curve and update */
+ /* Find the extrema of a 1-dimensional conic Bezier curve and update */
/* a bounding range. This version uses direct computation, as it */
/* doesn't need square roots. */
/* */
@@ -108,30 +108,19 @@
FT_Pos* min,
FT_Pos* max )
{
- if ( y1 <= y3 && y2 == y1 ) /* flat arc */
- goto Suite;
-
- if ( y1 < y3 )
- {
- if ( y2 >= y1 && y2 <= y3 ) /* ascending arc */
- goto Suite;
- }
- else
- {
- if ( y2 >= y3 && y2 <= y1 ) /* descending arc */
- {
- y2 = y1;
- y1 = y3;
- y3 = y2;
- goto Suite;
- }
- }
-
- y1 = y3 = y1 - FT_MulDiv( y2 - y1, y2 - y1, y1 - 2*y2 + y3 );
-
- Suite:
- if ( y1 < *min ) *min = y1;
- if ( y3 > *max ) *max = y3;
+ /* This function is only called when a control off-point is outside */
+ /* the bbox that contains all on-points. It finds a local extremum */
+ /* within the segment, equal to (y1*y3 - y2*y2)/(y1 - 2*y2 + y3). */
+ /* Or, offsetting from y2, we get */
+
+ y1 -= y2;
+ y3 -= y2;
+ y2 += FT_MulDiv( y1, y3, y1 + y3 );
+
+ if ( y2 < *min )
+ *min = y2;
+ if ( y2 > *max )
+ *max = y2;
}
@@ -195,9 +184,9 @@
/* BBox_Cubic_Check */
/* */
/* <Description> */
- /* Finds the extrema of a 1-dimensional cubic Bezier curve and */
- /* updates a bounding range. This version uses splitting because we */
- /* don't want to use square roots and extra accuracy. */
+ /* Find the extrema of a 1-dimensional cubic Bezier curve and */
+ /* update a bounding range. This version uses iterative splitting */
+ /* because it is faster than the exact solution with square roots. */
/* */
/* <Input> */
/* p1 :: The start coordinate. */
@@ -213,28 +202,16 @@
/* */
/* max :: The address of the current maximum. */
/* */
-
-#if 0
-
- static void
- BBox_Cubic_Check( FT_Pos p1,
- FT_Pos p2,
- FT_Pos p3,
- FT_Pos p4,
- FT_Pos* min,
- FT_Pos* max )
+ static FT_Pos
+ update_cubic_max( FT_Pos q1,
+ FT_Pos q2,
+ FT_Pos q3,
+ FT_Pos q4,
+ FT_Pos max )
{
- FT_Pos q1, q2, q3, q4;
-
-
- q1 = p1;
- q2 = p2;
- q3 = p3;
- q4 = p4;
-
- /* for a conic segment to possibly reach new maximum */
- /* one of its off-points must be above the current value */
- while ( q2 > *max || q3 > *max )
+ /* for a cubic segment to possibly reach new maximum, at least */
+ /* one of its off-points must stay above the current value */
+ while ( q2 > max || q3 > max )
{
/* determine which half contains the maximum and split */
if ( q1 + q2 > q3 + q4 ) /* first half */
@@ -260,231 +237,91 @@
q3 = q3 / 2;
}
- /* check if either end reached the maximum */
+ /* check whether either end reached the maximum */
if ( q1 == q2 && q1 >= q3 )
{
- *max = q1;
+ max = q1;
break;
}
if ( q3 == q4 && q2 <= q4 )
{
- *max = q4;
+ max = q4;
break;
}
}
- q1 = p1;
- q2 = p2;
- q3 = p3;
- q4 = p4;
-
- /* for a conic segment to possibly reach new minimum */
- /* one of its off-points must be below the current value */
- while ( q2 < *min || q3 < *min )
- {
- /* determine which half contains the minimum and split */
- if ( q1 + q2 < q3 + q4 ) /* first half */
- {
- q4 = q4 + q3;
- q3 = q3 + q2;
- q2 = q2 + q1;
- q4 = q4 + q3;
- q3 = q3 + q2;
- q4 = ( q4 + q3 ) / 8;
- q3 = q3 / 4;
- q2 = q2 / 2;
- }
- else /* second half */
- {
- q1 = q1 + q2;
- q2 = q2 + q3;
- q3 = q3 + q4;
- q1 = q1 + q2;
- q2 = q2 + q3;
- q1 = ( q1 + q2 ) / 8;
- q2 = q2 / 4;
- q3 = q3 / 2;
- }
-
- /* check if either end reached the minimum */
- if ( q1 == q2 && q1 <= q3 )
- {
- *min = q1;
- break;
- }
- if ( q3 == q4 && q2 >= q4 )
- {
- *min = q4;
- break;
- }
- }
- }
-
-#else
-
- static void
- test_cubic_extrema( FT_Pos y1,
- FT_Pos y2,
- FT_Pos y3,
- FT_Pos y4,
- FT_Fixed u,
- FT_Pos* min,
- FT_Pos* max )
- {
- /* FT_Pos a = y4 - 3*y3 + 3*y2 - y1; */
- FT_Pos b = y3 - 2*y2 + y1;
- FT_Pos c = y2 - y1;
- FT_Pos d = y1;
- FT_Pos y;
- FT_Fixed uu;
-
- FT_UNUSED ( y4 );
-
-
- /* The polynomial is */
- /* */
- /* P(x) = a*x^3 + 3b*x^2 + 3c*x + d , */
- /* */
- /* dP/dx = 3a*x^2 + 6b*x + 3c . */
- /* */
- /* However, we also have */
- /* */
- /* dP/dx(u) = 0 , */
- /* */
- /* which implies by subtraction that */
- /* */
- /* P(u) = b*u^2 + 2c*u + d . */
-
- if ( u > 0 && u < 0x10000L )
- {
- uu = FT_MulFix( u, u );
- y = d + FT_MulFix( c, 2*u ) + FT_MulFix( b, uu );
-
- if ( y < *min ) *min = y;
- if ( y > *max ) *max = y;
- }
+ return max;
}
static void
- BBox_Cubic_Check( FT_Pos y1,
- FT_Pos y2,
- FT_Pos y3,
- FT_Pos y4,
+ BBox_Cubic_Check( FT_Pos p1,
+ FT_Pos p2,
+ FT_Pos p3,
+ FT_Pos p4,
FT_Pos* min,
FT_Pos* max )
{
- /* always compare first and last points */
- if ( y1 < *min ) *min = y1;
- else if ( y1 > *max ) *max = y1;
+ FT_Pos nmin, nmax;
+ FT_Int shift;
- if ( y4 < *min ) *min = y4;
- else if ( y4 > *max ) *max = y4;
- /* now, try to see if there are split points here */
- if ( y1 <= y4 )
+ /* This function is only called when a control off-point is outside */
+ /* the bbox that contains all on-points. It finds a local extremum */
+ /* within the segment using iterative bisection of the segment. */
+ /* The fixed-point arithmetic of bisection is inherently stable */
+ /* but may loose accuracy in the two lowest bits. To compensate, */
+ /* we upscale the segment if there is room. Large values may need */
+ /* to be downscaled to avoid overflows during bisection. */
+ /* The control off-point outside the bbox is likely to have the top */
+ /* absolute value among arguments. */
+
+ shift = 27 - FT_MSB( FT_ABS( p2 ) | FT_ABS( p3 ) );
+
+ if ( shift > 0 )
{
- /* flat or ascending arc test */
- if ( y1 <= y2 && y2 <= y4 && y1 <= y3 && y3 <= y4 )
- return;
+ /* upscaling too much just wastes time */
+ if ( shift > 2 )
+ shift = 2;
+
+ p1 <<= shift;
+ p2 <<= shift;
+ p3 <<= shift;
+ p4 <<= shift;
+ nmin = *min << shift;
+ nmax = *max << shift;
}
- else /* y1 > y4 */
+ else
{
- /* descending arc test */
- if ( y1 >= y2 && y2 >= y4 && y1 >= y3 && y3 >= y4 )
- return;
+ p1 >>= -shift;
+ p2 >>= -shift;
+ p3 >>= -shift;
+ p4 >>= -shift;
+ nmin = *min >> -shift;
+ nmax = *max >> -shift;
}
- /* There are some split points. Find them. */
- /* We already made sure that a, b, and c below cannot be all zero. */
- {
- FT_Pos a = y4 - 3*y3 + 3*y2 - y1;
- FT_Pos b = y3 - 2*y2 + y1;
- FT_Pos c = y2 - y1;
- FT_Pos d;
- FT_Fixed t;
- FT_Int shift;
-
-
- /* We need to solve `ax^2+2bx+c' here, without floating points! */
- /* The trick is to normalize to a different representation in order */
- /* to use our 16.16 fixed-point routines. */
- /* */
- /* We compute FT_MulFix(b,b) and FT_MulFix(a,c) after normalization. */
- /* These values must fit into a single 16.16 value. */
- /* */
- /* We normalize a, b, and c to `8.16' fixed-point values to ensure */
- /* that their product is held in a `16.16' value including the sign. */
- /* Necessarily, we need to shift `a', `b', and `c' so that the most */
- /* significant bit of their absolute values is at position 22. */
- /* */
- /* This also means that we are using 23 bits of precision to compute */
- /* the zeros, independently of the range of the original polynomial */
- /* coefficients. */
- /* */
- /* This algorithm should ensure reasonably accurate values for the */
- /* zeros. Note that they are only expressed with 16 bits when */
- /* computing the extrema (the zeros need to be in 0..1 exclusive */
- /* to be considered part of the arc). */
-
- shift = FT_MSB( FT_ABS( a ) | FT_ABS( b ) | FT_ABS( c ) );
-
- if ( shift > 22 )
- {
- shift -= 22;
+ nmax = update_cubic_max( p1, p2, p3, p4, nmax );
- /* this loses some bits of precision, but we use 23 of them */
- /* for the computation anyway */
- a >>= shift;
- b >>= shift;
- c >>= shift;
- }
- else
- {
- shift = 22 - shift;
-
- a <<= shift;
- b <<= shift;
- c <<= shift;
- }
+ /* now flip the signs to update the minimum */
+ nmin = -update_cubic_max( -p1, -p2, -p3, -p4, -nmin );
- /* handle a == 0 */
- if ( a == 0 )
- {
- if ( b != 0 )
- {
- t = - FT_DivFix( c, b ) / 2;
- test_cubic_extrema( y1, y2, y3, y4, t, min, max );
- }
- }
- else
- {
- /* solve the equation now */
- d = FT_MulFix( b, b ) - FT_MulFix( a, c );
- if ( d < 0 )
- return;
-
- if ( d == 0 )
- {
- /* there is a single split point at -b/a */
- t = - FT_DivFix( b, a );
- test_cubic_extrema( y1, y2, y3, y4, t, min, max );
- }
- else
- {
- /* there are two solutions; we need to filter them */
- d = FT_SqrtFixed( (FT_Int32)d );
- t = - FT_DivFix( b - d, a );
- test_cubic_extrema( y1, y2, y3, y4, t, min, max );
-
- t = - FT_DivFix( b + d, a );
- test_cubic_extrema( y1, y2, y3, y4, t, min, max );
- }
- }
+ if ( shift > 0 )
+ {
+ nmin >>= shift;
+ nmax >>= shift;
+ }
+ else
+ {
+ nmin <<= -shift;
+ nmax <<= -shift;
}
- }
-#endif
+ if ( nmin < *min )
+ *min = nmin;
+ if ( nmax > *max )
+ *max = nmax;
+ }
/*************************************************************************/
@@ -521,8 +358,9 @@
FT_Vector* to,
TBBox_Rec* user )
{
- /* we don't need to check `to' since it is always an `on' point, thus */
- /* within the bbox */
+ /* We don't need to check `to' since it is always an on-point, */
+ /* thus within the bbox. Only segments with an off-point outside */
+ /* the bbox can possibly reach new extreme values. */
if ( CHECK_X( control1, user->bbox ) ||
CHECK_X( control2, user->bbox ) )
diff --git a/freetype/src/base/ftbitmap.c b/freetype/src/base/ftbitmap.c
index 50ef269bf..3425c368f 100644
--- a/freetype/src/base/ftbitmap.c
+++ b/freetype/src/base/ftbitmap.c
@@ -4,7 +4,7 @@
/* */
/* FreeType utility functions for bitmaps (body). */
/* */
-/* Copyright 2004-2009, 2011, 2013 by */
+/* Copyright 2004-2009, 2011, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -375,7 +375,7 @@
}
- FT_Byte
+ static FT_Byte
ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra )
{
FT_Long a = bgra[3];
@@ -385,6 +385,10 @@
FT_Long l;
+ /* Short-circuit transparent color to avoid div-by-zero. */
+ if ( !a )
+ return 0;
+
/*
* Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722
* coefficients for RGB channels *on the linear colors*.
diff --git a/freetype/src/base/ftcalc.c b/freetype/src/base/ftcalc.c
index 27448b30a..a1e76e192 100644
--- a/freetype/src/base/ftcalc.c
+++ b/freetype/src/base/ftcalc.c
@@ -4,7 +4,7 @@
/* */
/* Arithmetic computations (body). */
/* */
-/* Copyright 1996-2006, 2008, 2012-2013 by */
+/* Copyright 1996-2006, 2008, 2012-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -128,7 +128,7 @@
}
if ( z >= ( 1L << 1 ) )
{
- z >>= 1;
+ /* z >>= 1; */
shift += 1;
}
@@ -816,6 +816,8 @@
}
+#if 0
+
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Int32 )
@@ -850,6 +852,8 @@
return (FT_Int32)root;
}
+#endif /* 0 */
+
/* documentation is in ftcalc.h */
@@ -945,11 +949,27 @@
FT_Pos d_in, d_out, d_corner;
+ /* We approximate the Euclidean metric (sqrt(x^2 + y^2)) with */
+ /* the Taxicab metric (|x| + |y|), which can be computed much */
+ /* faster. If one of the two vectors is much longer than the */
+ /* other one, the direction of the shorter vector doesn't */
+ /* influence the result any more. */
+ /* */
+ /* corner */
+ /* x---------------------------x */
+ /* \ / */
+ /* \ / */
+ /* in \ / out */
+ /* \ / */
+ /* o */
+ /* Point */
+ /* */
+
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
- d_in = ax + ay;
+ d_in = ax + ay; /* d_in = || in || */
ax = out_x;
if ( ax < 0 )
@@ -957,7 +977,7 @@
ay = out_y;
if ( ay < 0 )
ay = -ay;
- d_out = ax + ay;
+ d_out = ax + ay; /* d_out = || out || */
ax = out_x + in_x;
if ( ax < 0 )
@@ -965,7 +985,11 @@
ay = out_y + in_y;
if ( ay < 0 )
ay = -ay;
- d_corner = ax + ay;
+ d_corner = ax + ay; /* d_corner = || in + out || */
+
+ /* now do a simple length comparison: */
+ /* */
+ /* d_in + d_out < 17/16 d_corner */
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
}
diff --git a/freetype/src/base/ftdebug.c b/freetype/src/base/ftdebug.c
index 876fe1df7..95bde59bb 100644
--- a/freetype/src/base/ftdebug.c
+++ b/freetype/src/base/ftdebug.c
@@ -152,7 +152,7 @@
/* the memory and stream components which are set to 7 and 5, */
/* respectively. */
/* */
- /* See the file <include/freetype/internal/fttrace.h> for details of the */
+ /* See the file <include/internal/fttrace.h> for details of the */
/* available toggle names. */
/* */
/* The level must be between 0 and 7; 0 means quiet (except for serious */
diff --git a/freetype/src/base/ftglyph.c b/freetype/src/base/ftglyph.c
index 4380aa2bf..66b01ef29 100644
--- a/freetype/src/base/ftglyph.c
+++ b/freetype/src/base/ftglyph.c
@@ -424,15 +424,16 @@
FT_Matrix* matrix,
FT_Vector* delta )
{
- const FT_Glyph_Class* clazz;
- FT_Error error = FT_Err_Ok;
+ FT_Error error = FT_Err_Ok;
if ( !glyph || !glyph->clazz )
error = FT_THROW( Invalid_Argument );
else
{
- clazz = glyph->clazz;
+ const FT_Glyph_Class* clazz = glyph->clazz;
+
+
if ( clazz->glyph_transform )
{
/* transform glyph image */
@@ -466,38 +467,33 @@
if ( !glyph || !glyph->clazz )
return;
- else
+
+ clazz = glyph->clazz;
+ if ( !clazz->glyph_bbox )
+ return;
+
+ /* retrieve bbox in 26.6 coordinates */
+ clazz->glyph_bbox( glyph, acbox );
+
+ /* perform grid fitting if needed */
+ if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT ||
+ bbox_mode == FT_GLYPH_BBOX_PIXELS )
{
- clazz = glyph->clazz;
- if ( !clazz->glyph_bbox )
- return;
- else
- {
- /* retrieve bbox in 26.6 coordinates */
- clazz->glyph_bbox( glyph, acbox );
-
- /* perform grid fitting if needed */
- if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT ||
- bbox_mode == FT_GLYPH_BBOX_PIXELS )
- {
- acbox->xMin = FT_PIX_FLOOR( acbox->xMin );
- acbox->yMin = FT_PIX_FLOOR( acbox->yMin );
- acbox->xMax = FT_PIX_CEIL( acbox->xMax );
- acbox->yMax = FT_PIX_CEIL( acbox->yMax );
- }
-
- /* convert to integer pixels if needed */
- if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE ||
- bbox_mode == FT_GLYPH_BBOX_PIXELS )
- {
- acbox->xMin >>= 6;
- acbox->yMin >>= 6;
- acbox->xMax >>= 6;
- acbox->yMax >>= 6;
- }
- }
+ acbox->xMin = FT_PIX_FLOOR( acbox->xMin );
+ acbox->yMin = FT_PIX_FLOOR( acbox->yMin );
+ acbox->xMax = FT_PIX_CEIL( acbox->xMax );
+ acbox->yMax = FT_PIX_CEIL( acbox->yMax );
+ }
+
+ /* convert to integer pixels if needed */
+ if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE ||
+ bbox_mode == FT_GLYPH_BBOX_PIXELS )
+ {
+ acbox->xMin >>= 6;
+ acbox->yMin >>= 6;
+ acbox->xMax >>= 6;
+ acbox->yMax >>= 6;
}
- return;
}
diff --git a/freetype/src/base/ftinit.c b/freetype/src/base/ftinit.c
index b9dd96881..c18877aed 100644
--- a/freetype/src/base/ftinit.c
+++ b/freetype/src/base/ftinit.c
@@ -23,8 +23,8 @@
/* FT_Add_Default_Modules(): */
/* This function is used to add the set of default modules to a */
/* fresh new library object. The set is taken from the header file */
- /* `freetype/config/ftmodule.h'. See the document `FreeType 2.0 */
- /* Build System' for more information. */
+ /* `config/ftmodule.h'. See the document `FreeType 2.0 Build */
+ /* System' for more information. */
/* */
/* FT_Init_FreeType(): */
/* This function creates a system object for the current platform, */
diff --git a/freetype/src/base/ftmac.c b/freetype/src/base/ftmac.c
index 9d193b4fa..6607b3d29 100644
--- a/freetype/src/base/ftmac.c
+++ b/freetype/src/base/ftmac.c
@@ -963,7 +963,6 @@
if ( !pathname )
return FT_THROW( Invalid_Argument );
- error = FT_Err_Ok;
*aface = NULL;
/* try resourcefork based font: LWFN, FFIL */
diff --git a/freetype/src/base/ftobjs.c b/freetype/src/base/ftobjs.c
index 07b3b2f58..f01451ed5 100644
--- a/freetype/src/base/ftobjs.c
+++ b/freetype/src/base/ftobjs.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType private base classes (body). */
/* */
-/* Copyright 1996-2013 by */
+/* Copyright 1996-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -56,9 +56,7 @@
#endif /* _MSC_VER */
/* it's easiest to include `md5.c' directly */
-#define free md5_free /* suppress a shadow warning */
#include "md5.c"
-#undef free
#if defined( _MSC_VER )
#pragma warning( pop )
@@ -667,11 +665,18 @@
/* the check for `num_locations' assures that we actually */
/* test for instructions in a TTF and not in a CFF-based OTF */
+ /* */
+ /* since `maxSizeOfInstructions' might be unreliable, we */
+ /* check the size of the `fpgm' and `prep' tables, too -- */
+ /* the assumption is that there don't exist real TTFs where */
+ /* both `fpgm' and `prep' tables are missing */
if ( mode == FT_RENDER_MODE_LIGHT ||
face->internal->ignore_unpatented_hinter ||
( FT_IS_SFNT( face ) &&
ttface->num_locations &&
- ttface->max_profile.maxSizeOfInstructions == 0 ) )
+ ttface->max_profile.maxSizeOfInstructions == 0 &&
+ ttface->font_program_size == 0 &&
+ ttface->cvt_program_size == 0 ) )
autohint = TRUE;
}
}
@@ -1133,7 +1138,8 @@
/* */
static FT_Error
open_face( FT_Driver driver,
- FT_Stream stream,
+ FT_Stream *astream,
+ FT_Bool external_stream,
FT_Long face_index,
FT_Int num_params,
FT_Parameter* params,
@@ -1141,10 +1147,11 @@
{
FT_Memory memory;
FT_Driver_Class clazz;
- FT_Face face = 0;
- FT_Error error, error2;
+ FT_Face face = NULL;
FT_Face_Internal internal = NULL;
+ FT_Error error, error2;
+
clazz = driver->clazz;
memory = driver->root.memory;
@@ -1155,7 +1162,11 @@
face->driver = driver;
face->memory = memory;
- face->stream = stream;
+ face->stream = *astream;
+
+ /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
+ if ( external_stream )
+ face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
if ( FT_NEW( internal ) )
goto Fail;
@@ -1177,11 +1188,12 @@
#endif
if ( clazz->init_face )
- error = clazz->init_face( stream,
+ error = clazz->init_face( *astream,
face,
(FT_Int)face_index,
num_params,
params );
+ *astream = face->stream; /* Stream may have been changed. */
if ( error )
goto Fail;
@@ -1789,9 +1801,10 @@
if ( error )
return error;
+ /* POST resources must be sorted to concatenate properly */
error = FT_Raccess_Get_DataOffsets( library, stream,
map_offset, rdara_pos,
- TTAG_POST,
+ TTAG_POST, TRUE,
&data_offsets, &count );
if ( !error )
{
@@ -1804,9 +1817,11 @@
return error;
}
+ /* sfnt resources should not be sorted to preserve the face order by
+ QuickDraw API */
error = FT_Raccess_Get_DataOffsets( library, stream,
map_offset, rdara_pos,
- TTAG_sfnt,
+ TTAG_sfnt, FALSE,
&data_offsets, &count );
if ( !error )
{
@@ -2069,7 +2084,7 @@
params = args->params;
}
- error = open_face( driver, stream, face_index,
+ error = open_face( driver, &stream, external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
@@ -2105,7 +2120,7 @@
params = args->params;
}
- error = open_face( driver, stream, face_index,
+ error = open_face( driver, &stream, external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
@@ -2174,10 +2189,6 @@
Success:
FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
- /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
- if ( external_stream )
- face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
-
/* add the face object to its driver's list */
if ( FT_NEW( node ) )
goto Fail;
@@ -3349,6 +3360,7 @@
FT_UInt gindex = 0;
+ /* only do something if we have a charmap, and we have glyphs at all */
if ( face && face->charmap && face->num_glyphs )
{
gindex = FT_Get_Char_Index( face, 0 );
@@ -3380,8 +3392,10 @@
FT_CMap cmap = FT_CMAP( face->charmap );
- do {
+ do
+ {
gindex = cmap->clazz->char_next( cmap, &code );
+
} while ( gindex >= (FT_UInt)face->num_glyphs );
result = ( gindex == 0 ) ? 0 : code;
@@ -3933,11 +3947,17 @@
static void
ft_remove_renderer( FT_Module module )
{
- FT_Library library = module->library;
- FT_Memory memory = library->memory;
+ FT_Library library;
+ FT_Memory memory;
FT_ListNode node;
+ library = module->library;
+ if ( !library )
+ return;
+
+ memory = library->memory;
+
node = FT_List_Find( &library->renderers, module );
if ( node )
{
@@ -4453,7 +4473,7 @@
}
- FT_Error
+ static FT_Error
ft_property_do( FT_Library library,
const FT_String* module_name,
const FT_String* property_name,
diff --git a/freetype/src/base/ftoutln.c b/freetype/src/base/ftoutln.c
index b8f709d6b..ead7139b0 100644
--- a/freetype/src/base/ftoutln.c
+++ b/freetype/src/base/ftoutln.c
@@ -4,7 +4,7 @@
/* */
/* FreeType outline management (body). */
/* */
-/* Copyright 1996-2008, 2010, 2012-2013 by */
+/* Copyright 1996-2008, 2010, 2012-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -128,7 +128,7 @@
v_start.x = ( v_start.x + v_last.x ) / 2;
v_start.y = ( v_start.y + v_last.y ) / 2;
- v_last = v_start;
+ /* v_last = v_start; */
}
point--;
tags--;
@@ -576,11 +576,13 @@
{
char* p = outline->tags + first;
char* q = outline->tags + last;
- char swap;
while ( p < q )
{
+ char swap;
+
+
swap = *p;
*p = *q;
*q = swap;
@@ -721,7 +723,8 @@
#if 0
#define FT_OUTLINE_GET_CONTOUR( outline, c, first, last ) \
- do { \
+ do \
+ { \
(first) = ( c > 0 ) ? (outline)->points + \
(outline)->contours[c - 1] + 1 \
: (outline)->points; \
diff --git a/freetype/src/base/ftpic.c b/freetype/src/base/ftpic.c
index 7780c8a92..ce93f02ff 100644
--- a/freetype/src/base/ftpic.c
+++ b/freetype/src/base/ftpic.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType position independent code services (body). */
/* */
-/* Copyright 2009 by */
+/* Copyright 2009, 2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -29,7 +29,8 @@
ft_pic_container_init( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
+
FT_MEM_SET( pic_container, 0, sizeof ( *pic_container ) );
diff --git a/freetype/src/base/ftrfork.c b/freetype/src/base/ftrfork.c
index 16f81e62a..84032d723 100644
--- a/freetype/src/base/ftrfork.c
+++ b/freetype/src/base/ftrfork.c
@@ -4,7 +4,7 @@
/* */
/* Embedded resource forks accessor (body). */
/* */
-/* Copyright 2004-2010, 2013 by */
+/* Copyright 2004-2010, 2013, 2014 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */
@@ -29,6 +29,7 @@
#include <freetype/internal/ftstream.h>
#include <freetype/internal/ftrfork.h>
#include "basepic.h"
+#include "ftbase.h"
#undef FT_COMPONENT
#define FT_COMPONENT trace_raccess
@@ -151,6 +152,7 @@
FT_Long map_offset,
FT_Long rdata_pos,
FT_Long tag,
+ FT_Bool sort_by_res_id,
FT_Long **offsets,
FT_Long *count )
{
@@ -163,6 +165,7 @@
FT_RFork_Ref *ref = NULL;
+ FT_TRACE3(( "\n" ));
error = FT_Stream_Seek( stream, map_offset );
if ( error )
return error;
@@ -183,6 +186,8 @@
(char)( 0xff & ( tag_internal >> 16 ) ),
(char)( 0xff & ( tag_internal >> 8 ) ),
(char)( 0xff & ( tag_internal >> 0 ) ) ));
+ FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n",
+ subcnt, rpos ));
if ( tag_internal == tag )
{
@@ -208,11 +213,24 @@
goto Exit;
ref[j].offset = temp & 0xFFFFFFL;
+ FT_TRACE3(( " [%d]:"
+ " resource_id=0x%04x, offset=0x%08x\n",
+ j, ref[j].res_id, ref[j].offset ));
}
- ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ),
- ( int(*)(const void*, const void*) )
- ft_raccess_sort_ref_by_id );
+ if (sort_by_res_id)
+ {
+ ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ),
+ ( int(*)(const void*, const void*) )
+ ft_raccess_sort_ref_by_id );
+
+ FT_TRACE3(( " -- sort resources by their ids --\n" ));
+ for ( j = 0; j < *count; ++ j ) {
+ FT_TRACE3(( " [%d]:"
+ " resource_id=0x%04x, offset=0x%08x\n",
+ j, ref[j].res_id, ref[j].offset ));
+ }
+ }
if ( FT_NEW_ARRAY( offsets_internal, *count ) )
goto Exit;
diff --git a/freetype/src/base/ftsynth.c b/freetype/src/base/ftsynth.c
index a25280d0c..fdb31982c 100644
--- a/freetype/src/base/ftsynth.c
+++ b/freetype/src/base/ftsynth.c
@@ -4,7 +4,7 @@
/* */
/* FreeType synthesizing code for emboldening and slanting (body). */
/* */
-/* Copyright 2000-2006, 2010, 2012 by */
+/* Copyright 2000-2006, 2010, 2012, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -139,10 +139,11 @@
if ( slot->advance.y )
slot->advance.y += ystr;
- slot->metrics.width += xstr;
- slot->metrics.height += ystr;
- slot->metrics.horiAdvance += xstr;
- slot->metrics.vertAdvance += ystr;
+ slot->metrics.width += xstr;
+ slot->metrics.height += ystr;
+ slot->metrics.horiAdvance += xstr;
+ slot->metrics.vertAdvance += ystr;
+ slot->metrics.horiBearingY += ystr;
/* XXX: 16-bit overflow case must be excluded before here */
if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
diff --git a/freetype/src/base/md5.c b/freetype/src/base/md5.c
index 2f01c9302..52d96accd 100644
--- a/freetype/src/base/md5.c
+++ b/freetype/src/base/md5.c
@@ -50,7 +50,8 @@
*/
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define H(x, y, z) (((x) ^ (y)) ^ (z))
+#define H2(x, y, z) ((x) ^ ((y) ^ (z)))
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
/*
@@ -89,13 +90,13 @@
* This processes one or more 64-byte data blocks, but does NOT update
* the bit counters. There are no alignment requirements.
*/
-static void *body(MD5_CTX *ctx, void *data, unsigned long size)
+static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
{
- unsigned char *ptr;
+ const unsigned char *ptr;
MD5_u32plus a, b, c, d;
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
- ptr = (unsigned char *)data;
+ ptr = (const unsigned char *)data;
a = ctx->a;
b = ctx->b;
@@ -146,21 +147,21 @@ static void *body(MD5_CTX *ctx, void *data, unsigned long size)
/* Round 3 */
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
- STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
+ STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
- STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
+ STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
- STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
+ STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
- STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
+ STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
- STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
+ STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
- STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
+ STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
- STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
+ STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
- STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
+ STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
/* Round 4 */
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
@@ -207,10 +208,10 @@ void MD5_Init(MD5_CTX *ctx)
ctx->hi = 0;
}
-void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
+void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{
MD5_u32plus saved_lo;
- unsigned long used, free;
+ unsigned long used, available;
saved_lo = ctx->lo;
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
@@ -220,16 +221,16 @@ void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
used = saved_lo & 0x3f;
if (used) {
- free = 64 - used;
+ available = 64 - used;
- if (size < free) {
+ if (size < available) {
memcpy(&ctx->buffer[used], data, size);
return;
}
- memcpy(&ctx->buffer[used], data, free);
- data = (unsigned char *)data + free;
- size -= free;
+ memcpy(&ctx->buffer[used], data, available);
+ data = (const unsigned char *)data + available;
+ size -= available;
body(ctx, ctx->buffer, 64);
}
@@ -243,22 +244,22 @@ void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
{
- unsigned long used, free;
+ unsigned long used, available;
used = ctx->lo & 0x3f;
ctx->buffer[used++] = 0x80;
- free = 64 - used;
+ available = 64 - used;
- if (free < 8) {
- memset(&ctx->buffer[used], 0, free);
+ if (available < 8) {
+ memset(&ctx->buffer[used], 0, available);
body(ctx, ctx->buffer, 64);
used = 0;
- free = 64;
+ available = 64;
}
- memset(&ctx->buffer[used], 0, free - 8);
+ memset(&ctx->buffer[used], 0, available - 8);
ctx->lo <<= 3;
ctx->buffer[56] = ctx->lo;
diff --git a/freetype/src/base/md5.h b/freetype/src/base/md5.h
index f1a685764..2da44bf35 100644
--- a/freetype/src/base/md5.h
+++ b/freetype/src/base/md5.h
@@ -39,7 +39,7 @@ typedef struct {
} MD5_CTX;
extern void MD5_Init(MD5_CTX *ctx);
-extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size);
+extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
extern void MD5_Final(unsigned char *result, MD5_CTX *ctx);
#endif
diff --git a/freetype/src/base/rules.mk b/freetype/src/base/rules.mk
index e93219115..cbd810732 100644
--- a/freetype/src/base/rules.mk
+++ b/freetype/src/base/rules.mk
@@ -19,8 +19,8 @@
# BASE_OBJ_S: The single-object base layer.
# BASE_OBJ_M: A list of all objects for a multiple-objects build.
# BASE_EXT_OBJ: A list of base layer extensions, i.e., components found
-# in `freetype/src/base' which are not compiled within the
-# base layer proper.
+# in `src/base' which are not compiled within the base
+# layer proper.
BASE_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(SRC_DIR)/base)
@@ -33,12 +33,14 @@ BASE_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(SRC_DIR)/base)
# All files listed here should be included in `ftbase.c' (for a `single'
# build).
#
-BASE_SRC := $(BASE_DIR)/ftadvanc.c \
+BASE_SRC := $(BASE_DIR)/basepic.c \
+ $(BASE_DIR)/ftadvanc.c \
$(BASE_DIR)/ftcalc.c \
$(BASE_DIR)/ftdbgmem.c \
$(BASE_DIR)/ftgloadr.c \
$(BASE_DIR)/ftobjs.c \
$(BASE_DIR)/ftoutln.c \
+ $(BASE_DIR)/ftpic.c \
$(BASE_DIR)/ftrfork.c \
$(BASE_DIR)/ftsnames.c \
$(BASE_DIR)/ftstream.c \
@@ -51,8 +53,9 @@ ifneq ($(ftmac_c),)
endif
# for simplicity, we also handle `md5.c' (which gets included by `ftobjs.h')
-BASE_H := $(BASE_DIR)/ftbase.h \
- $(BASE_DIR)/md5.c \
+BASE_H := $(BASE_DIR)/basepic.h \
+ $(BASE_DIR)/ftbase.h \
+ $(BASE_DIR)/md5.c \
$(BASE_DIR)/md5.h
# Base layer `extensions' sources
diff --git a/freetype/src/bdf/bdfdrivr.c b/freetype/src/bdf/bdfdrivr.c
index 8127168d7..46b545f98 100644
--- a/freetype/src/bdf/bdfdrivr.c
+++ b/freetype/src/bdf/bdfdrivr.c
@@ -2,7 +2,7 @@
FreeType font driver for bdf files
- Copyright (C) 2001-2008, 2011, 2013 by
+ Copyright (C) 2001-2008, 2011, 2013, 2014 by
Francesco Zappa Nardelli
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -243,8 +243,6 @@ THE SOFTWARE.
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
strings[0] = (char *)(prop->value.atom);
- len = 0;
-
for ( len = 0, nn = 0; nn < 4; nn++ )
{
lengths[nn] = 0;
@@ -351,7 +349,6 @@ THE SOFTWARE.
FT_UNUSED( num_params );
FT_UNUSED( params );
- FT_UNUSED( face_index );
FT_TRACE2(( "BDF driver\n" ));
@@ -375,6 +372,19 @@ THE SOFTWARE.
/* we have a bdf font: let's construct the face object */
face->bdffont = font;
+
+ /* BDF could not have multiple face in single font file.
+ * XXX: non-zero face_index is already invalid argument, but
+ * Type1, Type42 driver has a convention to return
+ * an invalid argument error when the font could be
+ * opened by the specified driver.
+ */
+ if ( face_index > 0 ) {
+ FT_ERROR(( "BDF_Face_Init: invalid face index\n" ));
+ BDF_Face_Done( bdfface );
+ return FT_THROW( Invalid_Argument );
+ }
+
{
bdf_property_t* prop = NULL;
@@ -388,9 +398,10 @@ THE SOFTWARE.
bdfface->num_faces = 1;
bdfface->face_index = 0;
- bdfface->face_flags = FT_FACE_FLAG_FIXED_SIZES |
- FT_FACE_FLAG_HORIZONTAL |
- FT_FACE_FLAG_FAST_GLYPHS;
+
+ bdfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+ FT_FACE_FLAG_HORIZONTAL |
+ FT_FACE_FLAG_FAST_GLYPHS;
prop = bdf_get_font_property( font, "SPACING" );
if ( prop && prop->format == BDF_ATOM &&
@@ -674,6 +685,8 @@ THE SOFTWARE.
goto Exit;
}
+ FT_TRACE1(( "BDF_Glyph_Load: glyph index %d\n", glyph_index ));
+
/* index 0 is the undefined glyph */
if ( glyph_index == 0 )
glyph_index = bdf->default_glyph;
diff --git a/freetype/src/bdf/bdflib.c b/freetype/src/bdf/bdflib.c
index 73e145461..2c0e17917 100644
--- a/freetype/src/bdf/bdflib.c
+++ b/freetype/src/bdf/bdflib.c
@@ -1,6 +1,6 @@
/*
* Copyright 2000 Computing Research Labs, New Mexico State University
- * Copyright 2001-2013
+ * Copyright 2001-2014
* Francesco Zappa Nardelli
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -691,7 +691,6 @@
lineno = 1;
buf[0] = 0;
start = 0;
- end = 0;
avail = 0;
cursor = 0;
refill = 1;
@@ -1409,7 +1408,7 @@
/* If the property happens to be a comment, then it doesn't need */
/* to be added to the internal hash table. */
- if ( ft_memcmp( name, "COMMENT", 7 ) != 0 )
+ if ( ft_strncmp( name, "COMMENT", 7 ) != 0 )
{
/* Add the property to the font property table. */
error = hash_insert( fp->name,
@@ -1427,13 +1426,13 @@
/* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */
/* present, and the SPACING property should override the default */
/* spacing. */
- if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 )
+ if ( ft_strncmp( name, "DEFAULT_CHAR", 12 ) == 0 )
font->default_char = fp->value.l;
- else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 )
+ else if ( ft_strncmp( name, "FONT_ASCENT", 11 ) == 0 )
font->font_ascent = fp->value.l;
- else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 )
+ else if ( ft_strncmp( name, "FONT_DESCENT", 12 ) == 0 )
font->font_descent = fp->value.l;
- else if ( ft_memcmp( name, "SPACING", 7 ) == 0 )
+ else if ( ft_strncmp( name, "SPACING", 7 ) == 0 )
{
if ( !fp->value.atom )
{
@@ -1491,7 +1490,7 @@
memory = font->memory;
/* Check for a comment. */
- if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
+ if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
{
linelen -= 7;
@@ -1508,7 +1507,7 @@
/* The very first thing expected is the number of glyphs. */
if ( !( p->flags & _BDF_GLYPHS ) )
{
- if ( ft_memcmp( line, "CHARS", 5 ) != 0 )
+ if ( ft_strncmp( line, "CHARS", 5 ) != 0 )
{
FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" ));
error = FT_THROW( Missing_Chars_Field );
@@ -1542,7 +1541,7 @@
}
/* Check for the ENDFONT field. */
- if ( ft_memcmp( line, "ENDFONT", 7 ) == 0 )
+ if ( ft_strncmp( line, "ENDFONT", 7 ) == 0 )
{
/* Sort the glyphs by encoding. */
ft_qsort( (char *)font->glyphs,
@@ -1556,7 +1555,7 @@
}
/* Check for the ENDCHAR field. */
- if ( ft_memcmp( line, "ENDCHAR", 7 ) == 0 )
+ if ( ft_strncmp( line, "ENDCHAR", 7 ) == 0 )
{
p->glyph_enc = 0;
p->flags &= ~_BDF_GLYPH_BITS;
@@ -1572,7 +1571,7 @@
goto Exit;
/* Check for the STARTCHAR field. */
- if ( ft_memcmp( line, "STARTCHAR", 9 ) == 0 )
+ if ( ft_strncmp( line, "STARTCHAR", 9 ) == 0 )
{
/* Set the character name in the parse info first until the */
/* encoding can be checked for an unencoded character. */
@@ -1606,7 +1605,7 @@
}
/* Check for the ENCODING field. */
- if ( ft_memcmp( line, "ENCODING", 8 ) == 0 )
+ if ( ft_strncmp( line, "ENCODING", 8 ) == 0 )
{
if ( !( p->flags & _BDF_GLYPH ) )
{
@@ -1792,7 +1791,7 @@
}
/* Expect the SWIDTH (scalable width) field next. */
- if ( ft_memcmp( line, "SWIDTH", 6 ) == 0 )
+ if ( ft_strncmp( line, "SWIDTH", 6 ) == 0 )
{
if ( !( p->flags & _BDF_ENCODING ) )
goto Missing_Encoding;
@@ -1808,7 +1807,7 @@
}
/* Expect the DWIDTH (scalable width) field next. */
- if ( ft_memcmp( line, "DWIDTH", 6 ) == 0 )
+ if ( ft_strncmp( line, "DWIDTH", 6 ) == 0 )
{
if ( !( p->flags & _BDF_ENCODING ) )
goto Missing_Encoding;
@@ -1836,7 +1835,7 @@
}
/* Expect the BBX field next. */
- if ( ft_memcmp( line, "BBX", 3 ) == 0 )
+ if ( ft_strncmp( line, "BBX", 3 ) == 0 )
{
if ( !( p->flags & _BDF_ENCODING ) )
goto Missing_Encoding;
@@ -1904,7 +1903,7 @@
}
/* And finally, gather up the bitmap. */
- if ( ft_memcmp( line, "BITMAP", 6 ) == 0 )
+ if ( ft_strncmp( line, "BITMAP", 6 ) == 0 )
{
unsigned long bitmap_size;
@@ -1979,7 +1978,7 @@
p = (_bdf_parse_t *) client_data;
/* Check for the end of the properties. */
- if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 )
+ if ( ft_strncmp( line, "ENDPROPERTIES", 13 ) == 0 )
{
/* If the FONT_ASCENT or FONT_DESCENT properties have not been */
/* encountered yet, then make sure they are added as properties and */
@@ -2020,12 +2019,12 @@
}
/* Ignore the _XFREE86_GLYPH_RANGES properties. */
- if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
+ if ( ft_strncmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
goto Exit;
/* Handle COMMENT fields and properties in a special way to preserve */
/* the spacing. */
- if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
+ if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
{
name = value = line;
value += 7;
@@ -2089,7 +2088,7 @@
/* Check for a comment. This is done to handle those fonts that have */
/* comments before the STARTFONT line for some reason. */
- if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
+ if ( ft_strncmp( line, "COMMENT", 7 ) == 0 )
{
if ( p->opts->keep_comments != 0 && p->font != 0 )
{
@@ -2115,7 +2114,7 @@
{
memory = p->memory;
- if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
+ if ( ft_strncmp( line, "STARTFONT", 9 ) != 0 )
{
/* we don't emit an error message since this code gets */
/* explicitly caught one level higher */
@@ -2163,7 +2162,7 @@
}
/* Check for the start of the properties. */
- if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 )
+ if ( ft_strncmp( line, "STARTPROPERTIES", 15 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_BBX ) )
{
@@ -2192,7 +2191,7 @@
}
/* Check for the FONTBOUNDINGBOX field. */
- if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
+ if ( ft_strncmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
{
if ( !( p->flags & _BDF_SIZE ) )
{
@@ -2223,7 +2222,7 @@
}
/* The next thing to check for is the FONT field. */
- if ( ft_memcmp( line, "FONT", 4 ) == 0 )
+ if ( ft_strncmp( line, "FONT", 4 ) == 0 )
{
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
@@ -2258,7 +2257,7 @@
}
/* Check for the SIZE field. */
- if ( ft_memcmp( line, "SIZE", 4 ) == 0 )
+ if ( ft_strncmp( line, "SIZE", 4 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_NAME ) )
{
@@ -2312,7 +2311,7 @@
}
/* Check for the CHARS field -- font properties are optional */
- if ( ft_memcmp( line, "CHARS", 5 ) == 0 )
+ if ( ft_strncmp( line, "CHARS", 5 ) == 0 )
{
char nbuf[128];
@@ -2376,8 +2375,8 @@
unsigned long lineno = 0; /* make compiler happy */
_bdf_parse_t *p = NULL;
- FT_Memory memory = extmemory;
- FT_Error error = FT_Err_Ok;
+ FT_Memory memory = extmemory; /* needed for FT_NEW */
+ FT_Error error = FT_Err_Ok;
if ( FT_NEW( p ) )
@@ -2399,7 +2398,6 @@
{
/* If the font is not proportional, set the font's monowidth */
/* field to the width of the font bounding box. */
- memory = p->font->memory;
if ( p->font->spacing != BDF_PROPORTIONAL )
p->font->monowidth = p->font->bbx.width;
diff --git a/freetype/src/cache/Jamfile b/freetype/src/cache/Jamfile
index 340cff774..656399137 100644
--- a/freetype/src/cache/Jamfile
+++ b/freetype/src/cache/Jamfile
@@ -1,6 +1,6 @@
# FreeType 2 src/cache Jamfile
#
-# Copyright 2001, 2003, 2004 by
+# Copyright 2001, 2003, 2004, 2013 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
@@ -11,7 +11,7 @@
SubDir FT2_TOP $(FT2_SRC_DIR) cache ;
-# The file <freetype/ftcache.h> contains some macro definitions that are
+# The file <ftcache.h> contains some macro definitions that are
# later used in #include statements related to the cache sub-system. It
# needs to be parsed through a HDRMACRO rule for macro definitions.
#
diff --git a/freetype/src/cff/cf2blues.c b/freetype/src/cff/cf2blues.c
index 5b348398a..250f89e0d 100644
--- a/freetype/src/cff/cf2blues.c
+++ b/freetype/src/cff/cf2blues.c
@@ -4,7 +4,7 @@
/* */
/* Adobe's code for handling Blue Zones (body). */
/* */
-/* Copyright 2009-2013 Adobe Systems Incorporated. */
+/* Copyright 2009-2014 Adobe Systems Incorporated. */
/* */
/* This software, and all works of authorship, whether in source or */
/* object code form as indicated by the copyright notice(s) included */
@@ -86,11 +86,13 @@
size_t i;
CF2_Fixed emBoxBottom, emBoxTop;
+#if 0
CF2_Int unitsPerEm = font->unitsPerEm;
if ( unitsPerEm == 0 )
unitsPerEm = 1000;
+#endif
FT_ZERO( blues );
blues->scale = font->innerTransform.d;
@@ -406,11 +408,10 @@
/* Note: constant changed from 0.5 to 0.6 to avoid a problem with */
/* 10ppem Arial */
- blues->boost = FT_MulFix(
- cf2_floatToFixed( .6 ),
- ( cf2_intToFixed( 1 ) -
- FT_DivFix( blues->scale,
- blues->blueScale ) ) );
+ blues->boost = cf2_floatToFixed( .6 ) -
+ FT_MulDiv( cf2_floatToFixed ( .6 ),
+ blues->scale,
+ blues->blueScale );
if ( blues->boost > 0x7FFF )
{
/* boost must remain less than 0.5, or baseline could go negative */
diff --git a/freetype/src/cff/cf2font.c b/freetype/src/cff/cf2font.c
index 479d9125d..6e99dc2f0 100644
--- a/freetype/src/cff/cf2font.c
+++ b/freetype/src/cff/cf2font.c
@@ -4,7 +4,7 @@
/* */
/* Adobe's code for font instances (body). */
/* */
-/* Copyright 2007-2013 Adobe Systems Incorporated. */
+/* Copyright 2007-2014 Adobe Systems Incorporated. */
/* */
/* This software, and all works of authorship, whether in source or */
/* object code form as indicated by the copyright notice(s) included */
@@ -51,10 +51,59 @@
CF2_Fixed stemWidth,
CF2_Fixed* darkenAmount,
CF2_Fixed boldenAmount,
- FT_Bool stemDarkened )
+ FT_Bool stemDarkened,
+ FT_Int* darkenParams )
{
+ /*
+ * Total darkening amount is computed in 1000 unit character space
+ * using the modified 5 part curve as Adobe's Avalon rasterizer.
+ * The darkening amount is smaller for thicker stems.
+ * It becomes zero when the stem is thicker than 2.333 pixels.
+ *
+ * By default, we use
+ *
+ * darkenAmount = 0.4 pixels if scaledStem <= 0.5 pixels,
+ * darkenAmount = 0.275 pixels if 1 <= scaledStem <= 1.667 pixels,
+ * darkenAmount = 0 pixel if scaledStem >= 2.333 pixels,
+ *
+ * and piecewise linear in-between:
+ *
+ *
+ * darkening
+ * ^
+ * |
+ * | (x1,y1)
+ * |--------+
+ * | \
+ * | \
+ * | \ (x3,y3)
+ * | +----------+
+ * | (x2,y2) \
+ * | \
+ * | \
+ * | +-----------------
+ * | (x4,y4)
+ * +---------------------------------------------> stem
+ * thickness
+ *
+ *
+ * This corresponds to the following values for the
+ * `darkening-parameters' property:
+ *
+ * (x1, y1) = (500, 400)
+ * (x2, y2) = (1000, 275)
+ * (x3, y3) = (1667, 275)
+ * (x4, y4) = (2333, 0)
+ *
+ */
+
/* Internal calculations are done in units per thousand for */
- /* convenience. */
+ /* convenience. The x axis is scaled stem width in */
+ /* thousandths of a pixel. That is, 1000 is 1 pixel. */
+ /* The y axis is darkening amount in thousandths of a pixel.*/
+ /* In the code, below, dividing by ppem and */
+ /* adjusting for emRatio converts darkenAmount to character */
+ /* space (font units). */
CF2_Fixed stemWidthPer1000, scaledStem;
@@ -69,6 +118,16 @@
if ( stemDarkened )
{
+ FT_Int x1 = darkenParams[0];
+ FT_Int y1 = darkenParams[1];
+ FT_Int x2 = darkenParams[2];
+ FT_Int y2 = darkenParams[3];
+ FT_Int x3 = darkenParams[4];
+ FT_Int y3 = darkenParams[5];
+ FT_Int x4 = darkenParams[6];
+ FT_Int y4 = darkenParams[7];
+
+
/* convert from true character space to 1000 unit character space; */
/* add synthetic emboldening effect */
@@ -81,7 +140,7 @@
stemWidthPer1000 <= ( stemWidth + boldenAmount ) )
{
stemWidthPer1000 = 0; /* to pacify compiler */
- scaledStem = cf2_intToFixed( 2333 );
+ scaledStem = cf2_intToFixed( x4 );
}
else
{
@@ -89,39 +148,70 @@
if ( ppem > CF2_FIXED_ONE &&
scaledStem <= stemWidthPer1000 )
- scaledStem = cf2_intToFixed( 2333 );
+ scaledStem = cf2_intToFixed( x4 );
+ }
+
+ /* now apply the darkening parameters */
+
+ if ( scaledStem < cf2_intToFixed( x1 ) )
+ *darkenAmount = FT_DivFix( cf2_intToFixed( y1 ), ppem );
+
+ else if ( scaledStem < cf2_intToFixed( x2 ) )
+ {
+ FT_Int xdelta = x2 - x1;
+ FT_Int ydelta = y2 - y1;
+ FT_Int x = stemWidthPer1000 -
+ FT_DivFix( cf2_intToFixed( x1 ), ppem );
+
+
+ if ( !xdelta )
+ goto Try_x3;
+
+ *darkenAmount = FT_MulDiv( x, ydelta, xdelta ) +
+ FT_DivFix( cf2_intToFixed( y1 ), ppem );
+ }
+
+ else if ( scaledStem < cf2_intToFixed( x3 ) )
+ {
+ Try_x3:
+ {
+ FT_Int xdelta = x3 - x2;
+ FT_Int ydelta = y3 - y2;
+ FT_Int x = stemWidthPer1000 -
+ FT_DivFix( cf2_intToFixed( x2 ), ppem );
+
+
+ if ( !xdelta )
+ goto Try_x4;
+
+ *darkenAmount = FT_MulDiv( x, ydelta, xdelta ) +
+ FT_DivFix( cf2_intToFixed( y2 ), ppem );
+ }
+ }
+
+ else if ( scaledStem < cf2_intToFixed( x4 ) )
+ {
+ Try_x4:
+ {
+ FT_Int xdelta = x4 - x3;
+ FT_Int ydelta = y4 - y3;
+ FT_Int x = stemWidthPer1000 -
+ FT_DivFix( cf2_intToFixed( x3 ), ppem );
+
+
+ if ( !xdelta )
+ goto Use_y4;
+
+ *darkenAmount = FT_MulDiv( x, ydelta, xdelta ) +
+ FT_DivFix( cf2_intToFixed( y3 ), ppem );
+ }
}
- /*
- * Total darkening amount is computed in 1000 unit character space
- * using the modified 5 part curve as Avalon rasterizer.
- * The darkening amount is smaller for thicker stems.
- * It becomes zero when the stem is thicker than 2.333 pixels.
- *
- * In Avalon rasterizer,
- *
- * darkenAmount = 0.5 pixels if scaledStem <= 0.5 pixels,
- * darkenAmount = 0.333 pixels if 1 <= scaledStem <= 1.667 pixels,
- * darkenAmount = 0 pixel if scaledStem >= 2.333 pixels,
- *
- * and piecewise linear in-between.
- *
- */
- if ( scaledStem < cf2_intToFixed( 500 ) )
- *darkenAmount = FT_DivFix( cf2_intToFixed( 400 ), ppem );
-
- else if ( scaledStem < cf2_intToFixed( 1000 ) )
- *darkenAmount = FT_DivFix( cf2_intToFixed( 525 ), ppem ) -
- FT_MulFix( stemWidthPer1000,
- cf2_floatToFixed( .25 ) );
-
- else if ( scaledStem < cf2_intToFixed( 1667 ) )
- *darkenAmount = FT_DivFix( cf2_intToFixed( 275 ), ppem );
-
- else if ( scaledStem < cf2_intToFixed( 2333 ) )
- *darkenAmount = FT_DivFix( cf2_intToFixed( 963 ), ppem ) -
- FT_MulFix( stemWidthPer1000,
- cf2_floatToFixed( .413 ) );
+ else
+ {
+ Use_y4:
+ *darkenAmount = FT_DivFix( cf2_intToFixed( y4 ), ppem );
+ }
/* use half the amount on each side and convert back to true */
/* character space */
@@ -143,13 +233,14 @@
/* pointer to parsed font object */
CFF_Decoder* decoder = font->decoder;
- FT_Bool needExtraSetup;
+ FT_Bool needExtraSetup = FALSE;
/* character space units */
CF2_Fixed boldenX = font->syntheticEmboldeningAmountX;
CF2_Fixed boldenY = font->syntheticEmboldeningAmountY;
- CF2_Fixed ppem;
+ CFF_SubFont subFont;
+ CF2_Fixed ppem;
/* clear previous error */
@@ -157,8 +248,12 @@
/* if a CID fontDict has changed, we need to recompute some cached */
/* data */
- needExtraSetup =
- (FT_Bool)( font->lastSubfont != cf2_getSubfont( decoder ) );
+ subFont = cf2_getSubfont( decoder );
+ if ( font->lastSubfont != subFont )
+ {
+ font->lastSubfont = subFont;
+ needExtraSetup = TRUE;
+ }
/* if ppem has changed, we need to recompute some cached data */
/* note: because of CID font matrix concatenation, ppem and transform */
@@ -268,7 +363,8 @@
font->stdVW,
&font->darkenX,
boldenX,
- FALSE );
+ FALSE,
+ font->darkenParams );
}
else
cf2_computeDarkening( emRatio,
@@ -276,7 +372,8 @@
font->stdVW,
&font->darkenX,
0,
- font->stemDarkened );
+ font->stemDarkened,
+ font->darkenParams );
#if 0
/* since hstem is measured in the y-direction, we use the `d' member */
@@ -303,7 +400,8 @@
font->stdHW,
&font->darkenY,
boldenY,
- font->stemDarkened );
+ font->stemDarkened,
+ font->darkenParams );
if ( font->darkenX != 0 || font->darkenY != 0 )
font->darkened = TRUE;
diff --git a/freetype/src/cff/cf2font.h b/freetype/src/cff/cf2font.h
index f9dd1bbd4..d8860ce8e 100644
--- a/freetype/src/cff/cf2font.h
+++ b/freetype/src/cff/cf2font.h
@@ -85,6 +85,8 @@ FT_BEGIN_HEADER
/* i.e. darkenX != 0 || darkenY != 0 */
FT_Bool stemDarkened;
+ FT_Int darkenParams[8]; /* 1000 unit character space */
+
/* variables that depend on both FontDict and Transform */
CF2_Fixed stdVW; /* in character space; depends on dict entry */
CF2_Fixed stdHW; /* in character space; depends on dict entry */
diff --git a/freetype/src/cff/cf2ft.c b/freetype/src/cff/cf2ft.c
index c09a0244a..cb8d31c53 100644
--- a/freetype/src/cff/cf2ft.c
+++ b/freetype/src/cff/cf2ft.c
@@ -4,7 +4,7 @@
/* */
/* FreeType Glue Component to Adobe's Interpreter (body). */
/* */
-/* Copyright 2013 Adobe Systems Incorporated. */
+/* Copyright 2013-2014 Adobe Systems Incorporated. */
/* */
/* This software, and all works of authorship, whether in source or */
/* object code form as indicated by the copyright notice(s) included */
@@ -61,7 +61,9 @@
FT_ASSERT( unitsPerEm > 0 );
- FT_ASSERT( transform->a > 0 && transform->d > 0 );
+ if ( transform->a <= 0 || transform->d <= 0 )
+ return FT_THROW( Invalid_Size_Handle );
+
FT_ASSERT( transform->b == 0 && transform->c == 0 );
FT_ASSERT( transform->tx == 0 && transform->ty == 0 );
@@ -236,10 +238,8 @@
if ( *hinted )
{
- *x_scale = FT_DivFix( decoder->builder.glyph->x_scale,
- cf2_intToFixed( 64 ) );
- *y_scale = FT_DivFix( decoder->builder.glyph->y_scale,
- cf2_intToFixed( 64 ) );
+ *x_scale = ( decoder->builder.glyph->x_scale + 32 ) / 64;
+ *y_scale = ( decoder->builder.glyph->y_scale + 32 ) / 64;
}
else
{
@@ -344,13 +344,25 @@
if ( scaled && !driver->no_stem_darkening )
font->renderingFlags |= CF2_FlagsDarkened;
+ font->darkenParams[0] = driver->darken_params[0];
+ font->darkenParams[1] = driver->darken_params[1];
+ font->darkenParams[2] = driver->darken_params[2];
+ font->darkenParams[3] = driver->darken_params[3];
+ font->darkenParams[4] = driver->darken_params[4];
+ font->darkenParams[5] = driver->darken_params[5];
+ font->darkenParams[6] = driver->darken_params[6];
+ font->darkenParams[7] = driver->darken_params[7];
+
/* now get an outline for this glyph; */
/* also get units per em to validate scale */
font->unitsPerEm = (CF2_Int)cf2_getUnitsPerEm( decoder );
- error2 = cf2_checkTransform( &transform, font->unitsPerEm );
- if ( error2 )
- return error2;
+ if ( scaled )
+ {
+ error2 = cf2_checkTransform( &transform, font->unitsPerEm );
+ if ( error2 )
+ return error2;
+ }
error2 = cf2_getGlyphOutline( font, &buf, &transform, &glyphWidth );
if ( error2 )
@@ -380,8 +392,16 @@
FT_ASSERT( decoder &&
decoder->builder.face &&
decoder->builder.face->root.size );
- FT_ASSERT( decoder->builder.face->root.size->metrics.y_ppem );
+ /*
+ * Note that `y_ppem' can be zero if there wasn't a call to
+ * `FT_Set_Char_Size' or something similar. However, this isn't a
+ * problem since we come to this place in the code only if
+ * FT_LOAD_NO_SCALE is set (the other case gets caught by
+ * `cf2_checkTransform'). The ppem value is needed to compute the stem
+ * darkening, which is disabled for getting the unscaled outline.
+ *
+ */
return cf2_intToFixed(
decoder->builder.face->root.size->metrics.y_ppem );
}
@@ -499,7 +519,7 @@
CF2_UInt idx,
CF2_Buffer buf )
{
- FT_ASSERT( decoder && decoder->globals );
+ FT_ASSERT( decoder );
FT_ZERO( buf );
@@ -507,6 +527,8 @@
if ( idx >= decoder->num_globals )
return TRUE; /* error */
+ FT_ASSERT( decoder->globals );
+
buf->start =
buf->ptr = decoder->globals[idx];
buf->end = decoder->globals[idx + 1];
@@ -572,7 +594,7 @@
CF2_UInt idx,
CF2_Buffer buf )
{
- FT_ASSERT( decoder && decoder->locals );
+ FT_ASSERT( decoder );
FT_ZERO( buf );
@@ -580,6 +602,8 @@
if ( idx >= decoder->num_locals )
return TRUE; /* error */
+ FT_ASSERT( decoder->locals );
+
buf->start =
buf->ptr = decoder->locals[idx];
buf->end = decoder->locals[idx + 1];
diff --git a/freetype/src/cff/cf2hints.c b/freetype/src/cff/cf2hints.c
index 96bd49f18..5853d7758 100644
--- a/freetype/src/cff/cf2hints.c
+++ b/freetype/src/cff/cf2hints.c
@@ -4,7 +4,7 @@
/* */
/* Adobe's code for handling CFF hints (body). */
/* */
-/* Copyright 2007-2013 Adobe Systems Incorporated. */
+/* Copyright 2007-2014 Adobe Systems Incorporated. */
/* */
/* This software, and all works of authorship, whether in source or */
/* object code form as indicated by the copyright notice(s) included */
@@ -596,22 +596,31 @@
indexInsert = 0;
for ( ; indexInsert < hintmap->count; indexInsert++ )
{
- if ( hintmap->edge[indexInsert].csCoord > firstHintEdge->csCoord )
+ if ( hintmap->edge[indexInsert].csCoord >= firstHintEdge->csCoord )
break;
}
/*
- * Discard any hints that overlap in character space. Most often,
- * this is while building the initial map, but in theory, it can also
- * occur because of darkening.
+ * Discard any hints that overlap in character space. Most often, this
+ * is while building the initial map, where captured hints from all
+ * zones are combined. Define overlap to include hints that `touch'
+ * (overlap zero). Hiragino Sans/Gothic fonts have numerous hints that
+ * touch. Some fonts have non-ideographic glyphs that overlap our
+ * synthetic hints.
+ *
+ * Overlap also occurs when darkening stem hints that are close.
*
*/
if ( indexInsert < hintmap->count )
{
- /* we are inserting before an existing edge: */
+ /* we are inserting before an existing edge: */
+ /* verify that an existing edge is not the same */
+ if ( hintmap->edge[indexInsert].csCoord == firstHintEdge->csCoord )
+ return; /* ignore overlapping stem hint */
+
/* verify that a new pair does not straddle the next edge */
- if ( isPair &&
- hintmap->edge[indexInsert].csCoord < secondHintEdge->csCoord )
+ if ( isPair &&
+ hintmap->edge[indexInsert].csCoord <= secondHintEdge->csCoord )
return; /* ignore overlapping stem hint */
/* verify that we are not inserting between paired edges */
@@ -645,8 +654,27 @@
firstHintEdge->csCoord );
}
- /* discard any hints that overlap in device space; this can occur */
- /* because locked hints have been moved to align with blue zones */
+ /*
+ * Discard any hints that overlap in device space; this can occur
+ * because locked hints have been moved to align with blue zones.
+ *
+ * TODO: Although we might correct this later during adjustment, we
+ * don't currently have a way to delete a conflicting hint once it has
+ * been inserted. See v2.030 MinionPro-Regular, 12 ppem darkened,
+ * initial hint map for second path, glyph 945 (the perispomeni (tilde)
+ * in U+1F6E, Greek omega with psili and perispomeni). Darkening is
+ * 25. Pair 667,747 initially conflicts in design space with top edge
+ * 660. This is because 667 maps to 7.87, and the top edge was
+ * captured by a zone at 8.0. The pair is later successfully inserted
+ * in a zone without the top edge. In this zone it is adjusted to 8.0,
+ * and no longer conflicts with the top edge in design space. This
+ * means it can be included in yet a later zone which does have the top
+ * edge hint. This produces a small mismatch between the first and
+ * last points of this path, even though the hint masks are the same.
+ * The density map difference is tiny (1/256).
+ *
+ */
+
if ( indexInsert > 0 )
{
/* we are inserting after an existing edge */
@@ -753,6 +781,8 @@
cf2_hintmask_setAll( hintMask,
cf2_arrstack_size( hStemHintArray ) +
cf2_arrstack_size( vStemHintArray ) );
+ if ( !cf2_hintmask_isValid( hintMask ) )
+ return; /* too many stem hints */
}
/* begin by clearing the map */
@@ -1035,6 +1065,7 @@
glyphpath->moveIsPending = TRUE;
glyphpath->pathIsOpen = FALSE;
+ glyphpath->pathIsClosing = FALSE;
glyphpath->elemIsQueued = FALSE;
}
@@ -1175,12 +1206,16 @@
/*
* Push the cached element (glyphpath->prevElem*) to the outline
* consumer. When a darkening offset is used, the end point of the
- * cached element may be adjusted to an intersection point or it may be
- * connected by a line to the current element. This calculation must
- * use a HintMap that was valid at the time the element was saved. For
- * the first point in a subpath, that is a saved HintMap. For most
- * elements, it just means the caller has delayed building a HintMap
- * from the current HintMask.
+ * cached element may be adjusted to an intersection point or we may
+ * synthesize a connecting line to the current element. If we are
+ * closing a subpath, we may also generate a connecting line to the start
+ * point.
+ *
+ * This is where Character Space (CS) is converted to Device Space (DS)
+ * using a hint map. This calculation must use a HintMap that was valid
+ * at the time the element was saved. For the first point in a subpath,
+ * that is a saved HintMap. For most elements, it just means the caller
+ * has delayed building a HintMap from the current HintMask.
*
* Transform each point with outerTransform and call the outline
* callbacks. This is a general 3x3 transform:
@@ -1250,16 +1285,32 @@
params.op = CF2_PathOpLineTo;
/* note: pt2 and pt3 are unused */
- cf2_glyphpath_hintPoint( glyphpath,
- hintmap,
- &params.pt1,
- glyphpath->prevElemP1.x,
- glyphpath->prevElemP1.y );
- glyphpath->callbacks->lineTo( glyphpath->callbacks, &params );
+ if ( close )
+ {
+ /* use first hint map if closing */
+ cf2_glyphpath_hintPoint( glyphpath,
+ &glyphpath->firstHintMap,
+ &params.pt1,
+ glyphpath->prevElemP1.x,
+ glyphpath->prevElemP1.y );
+ }
+ else
+ {
+ cf2_glyphpath_hintPoint( glyphpath,
+ hintmap,
+ &params.pt1,
+ glyphpath->prevElemP1.x,
+ glyphpath->prevElemP1.y );
+ }
- glyphpath->currentDS = params.pt1;
+ /* output only non-zero length lines */
+ if ( params.pt0.x != params.pt1.x || params.pt0.y != params.pt1.y )
+ {
+ glyphpath->callbacks->lineTo( glyphpath->callbacks, &params );
+ glyphpath->currentDS = params.pt1;
+ }
break;
case CF2_PathOpCubeTo:
@@ -1296,11 +1347,24 @@
/* note: at the end of a subpath, we might do both, so use `nextP0' */
/* before we change it, below */
- cf2_glyphpath_hintPoint( glyphpath,
- hintmap,
- &params.pt1,
- nextP0->x,
- nextP0->y );
+ if ( close )
+ {
+ /* if we are closing the subpath, then nextP0 is in the first */
+ /* hint zone */
+ cf2_glyphpath_hintPoint( glyphpath,
+ &glyphpath->firstHintMap,
+ &params.pt1,
+ nextP0->x,
+ nextP0->y );
+ }
+ else
+ {
+ cf2_glyphpath_hintPoint( glyphpath,
+ hintmap,
+ &params.pt1,
+ nextP0->x,
+ nextP0->y );
+ }
if ( params.pt1.x != glyphpath->currentDS.x ||
params.pt1.y != glyphpath->currentDS.y )
@@ -1511,6 +1575,16 @@
}
+ /*
+ * The functions cf2_glyphpath_{moveTo,lineTo,curveTo,closeOpenPath} are
+ * called by the interpreter with Character Space (CS) coordinates. Each
+ * path element is placed into a queue of length one to await the
+ * calculation of the following element. At that time, the darkening
+ * offset of the following element is known and joins can be computed,
+ * including possible modification of this element, before mapping to
+ * Device Space (DS) and passing it on to the outline consumer.
+ *
+ */
FT_LOCAL_DEF( void )
cf2_glyphpath_moveTo( CF2_GlyphPath glyphpath,
CF2_Fixed x,
@@ -1548,10 +1622,46 @@
{
CF2_Fixed xOffset, yOffset;
FT_Vector P0, P1;
+ FT_Bool newHintMap;
+
+ /*
+ * New hints will be applied after cf2_glyphpath_pushPrevElem has run.
+ * In case this is a synthesized closing line, any new hints should be
+ * delayed until this path is closed (`cf2_hintmask_isNew' will be
+ * called again before the next line or curve).
+ */
+
+ /* true if new hint map not on close */
+ newHintMap = cf2_hintmask_isNew( glyphpath->hintMask ) &&
+ !glyphpath->pathIsClosing;
+
+ /*
+ * Zero-length lines may occur in the charstring. Because we cannot
+ * compute darkening offsets or intersections from zero-length lines,
+ * it is best to remove them and avoid artifacts. However, zero-length
+ * lines in CS at the start of a new hint map can generate non-zero
+ * lines in DS due to hint substitution. We detect a change in hint
+ * map here and pass those zero-length lines along.
+ */
+ /*
+ * Note: Find explicitly closed paths here with a conditional
+ * breakpoint using
+ *
+ * !gp->pathIsClosing && gp->start.x == x && gp->start.y == y
+ *
+ */
- /* can't compute offset of zero length line, so ignore them */
- if ( glyphpath->currentCS.x == x && glyphpath->currentCS.y == y )
+ if ( glyphpath->currentCS.x == x &&
+ glyphpath->currentCS.y == y &&
+ !newHintMap )
+ /*
+ * Ignore zero-length lines in CS where the hint map is the same
+ * because the line in DS will also be zero length.
+ *
+ * Ignore zero-length lines when we synthesize a closing line because
+ * the close will be handled in cf2_glyphPath_pushPrevElem.
+ */
return;
cf2_glyphpath_computeOffset( glyphpath,
@@ -1597,7 +1707,7 @@
glyphpath->prevElemP1 = P1;
/* update current map */
- if ( cf2_hintmask_isNew( glyphpath->hintMask ) )
+ if ( newHintMap )
cf2_hintmap_build( &glyphpath->hintMap,
glyphpath->hStemHintArray,
glyphpath->vStemHintArray,
@@ -1703,29 +1813,29 @@
{
if ( glyphpath->pathIsOpen )
{
- FT_ASSERT( cf2_hintmap_isValid( &glyphpath->firstHintMap ) );
+ /*
+ * A closing line in Character Space line is always generated below
+ * with `cf2_glyphPath_lineTo'. It may be ignored later if it turns
+ * out to be zero length in Device Space.
+ */
+ glyphpath->pathIsClosing = TRUE;
- /* since we need to apply an offset to the implicit lineto, we make */
- /* it explicit here */
cf2_glyphpath_lineTo( glyphpath,
glyphpath->start.x,
glyphpath->start.y );
- /* Draw previous element (the explicit LineTo we just created, */
- /* above) and connect it to the start point, but with the offset we */
- /* saved from the first element. */
- /* Use the saved HintMap, too. */
- FT_ASSERT( glyphpath->elemIsQueued );
-
- cf2_glyphpath_pushPrevElem( glyphpath,
- &glyphpath->firstHintMap,
- &glyphpath->offsetStart0,
- glyphpath->offsetStart1,
- TRUE );
+ /* empty the final element from the queue and close the path */
+ if ( glyphpath->elemIsQueued )
+ cf2_glyphpath_pushPrevElem( glyphpath,
+ &glyphpath->hintMap,
+ &glyphpath->offsetStart0,
+ glyphpath->offsetStart1,
+ TRUE );
/* reset state machine */
glyphpath->moveIsPending = TRUE;
glyphpath->pathIsOpen = FALSE;
+ glyphpath->pathIsClosing = FALSE;
glyphpath->elemIsQueued = FALSE;
}
}
diff --git a/freetype/src/cff/cf2hints.h b/freetype/src/cff/cf2hints.h
index c4fa922a3..f25d91bf8 100644
--- a/freetype/src/cff/cf2hints.h
+++ b/freetype/src/cff/cf2hints.h
@@ -204,6 +204,7 @@ FT_BEGIN_HEADER
#endif
FT_Bool pathIsOpen; /* true after MoveTo */
+ FT_Bool pathIsClosing; /* true when synthesizing closepath line */
FT_Bool darken; /* true if stem darkening */
FT_Bool moveIsPending; /* true between MoveTo and offset MoveTo */
@@ -229,7 +230,8 @@ FT_BEGIN_HEADER
FT_Vector currentCS;
/* current point, device space */
FT_Vector currentDS;
- FT_Vector start; /* start point of subpath */
+ /* start point of subpath, character space */
+ FT_Vector start;
/* the following members constitute the `queue' of one element */
FT_Bool elemIsQueued;
diff --git a/freetype/src/cff/cffdrivr.c b/freetype/src/cff/cffdrivr.c
index fd9472947..39e3f7b2d 100644
--- a/freetype/src/cff/cffdrivr.c
+++ b/freetype/src/cff/cffdrivr.c
@@ -164,6 +164,8 @@
if ( !slot )
return FT_THROW( Invalid_Slot_Handle );
+ FT_TRACE1(( "cff_glyph_load: glyph index %d\n", glyph_index ));
+
/* check whether we want a scaled outline or bitmap */
if ( !size )
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
@@ -586,7 +588,38 @@
CFF_Driver driver = (CFF_Driver)module;
- if ( !ft_strcmp( property_name, "hinting-engine" ) )
+ if ( !ft_strcmp( property_name, "darkening-parameters" ) )
+ {
+ FT_Int* darken_params = (FT_Int*)value;
+
+ FT_Int x1 = darken_params[0];
+ FT_Int y1 = darken_params[1];
+ FT_Int x2 = darken_params[2];
+ FT_Int y2 = darken_params[3];
+ FT_Int x3 = darken_params[4];
+ FT_Int y3 = darken_params[5];
+ FT_Int x4 = darken_params[6];
+ FT_Int y4 = darken_params[7];
+
+
+ if ( x1 < 0 || x2 < 0 || x3 < 0 || x4 < 0 ||
+ y1 < 0 || y2 < 0 || y3 < 0 || y4 < 0 ||
+ x1 > x2 || x2 > x3 || x3 > x4 ||
+ y1 > 500 || y2 > 500 || y3 > 500 || y4 > 500 )
+ return FT_THROW( Invalid_Argument );
+
+ driver->darken_params[0] = x1;
+ driver->darken_params[1] = y1;
+ driver->darken_params[2] = x2;
+ driver->darken_params[3] = y2;
+ driver->darken_params[4] = x3;
+ driver->darken_params[5] = y3;
+ driver->darken_params[6] = x4;
+ driver->darken_params[7] = y4;
+
+ return error;
+ }
+ else if ( !ft_strcmp( property_name, "hinting-engine" ) )
{
FT_UInt* hinting_engine = (FT_UInt*)value;
@@ -624,13 +657,28 @@
FT_Error error = FT_Err_Ok;
CFF_Driver driver = (CFF_Driver)module;
- FT_UInt hinting_engine = driver->hinting_engine;
- FT_Bool no_stem_darkening = driver->no_stem_darkening;
+ if ( !ft_strcmp( property_name, "darkening-parameters" ) )
+ {
+ FT_Int* darken_params = driver->darken_params;
+ FT_Int* val = (FT_Int*)value;
+
+
+ val[0] = darken_params[0];
+ val[1] = darken_params[1];
+ val[2] = darken_params[2];
+ val[3] = darken_params[3];
+ val[4] = darken_params[4];
+ val[5] = darken_params[5];
+ val[6] = darken_params[6];
+ val[7] = darken_params[7];
- if ( !ft_strcmp( property_name, "hinting-engine" ) )
+ return error;
+ }
+ else if ( !ft_strcmp( property_name, "hinting-engine" ) )
{
- FT_UInt* val = (FT_UInt*)value;
+ FT_UInt hinting_engine = driver->hinting_engine;
+ FT_UInt* val = (FT_UInt*)value;
*val = hinting_engine;
@@ -639,7 +687,8 @@
}
else if ( !ft_strcmp( property_name, "no-stem-darkening" ) )
{
- FT_Bool* val = (FT_Bool*)value;
+ FT_Bool no_stem_darkening = driver->no_stem_darkening;
+ FT_Bool* val = (FT_Bool*)value;
*val = no_stem_darkening;
diff --git a/freetype/src/cff/cffgload.c b/freetype/src/cff/cffgload.c
index 23a6adf45..3cc7d8ff9 100644
--- a/freetype/src/cff/cffgload.c
+++ b/freetype/src/cff/cffgload.c
@@ -434,7 +434,7 @@
goto Exit;
}
- FT_TRACE3(( "glyph index %d (subfont %d):\n", glyph_index, fd_index ));
+ FT_TRACE3(( " in subfont %d:\n", fd_index ));
sub = cff->subfonts[fd_index];
@@ -447,10 +447,6 @@
builder->hints_globals = (void *)internal->subfonts[fd_index];
}
}
-#ifdef FT_DEBUG_LEVEL_TRACE
- else
- FT_TRACE3(( "glyph index %d:\n", glyph_index ));
-#endif
decoder->num_locals = sub->local_subrs_index.count;
decoder->locals = sub->local_subrs;
diff --git a/freetype/src/cff/cffload.c b/freetype/src/cff/cffload.c
index 78f0b44ff..2e4da25d8 100644
--- a/freetype/src/cff/cffload.c
+++ b/freetype/src/cff/cffload.c
@@ -4,7 +4,7 @@
/* */
/* OpenType and CFF data/program tables loader (body). */
/* */
-/* Copyright 1996-2013 by */
+/* Copyright 1996-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -414,7 +414,7 @@
cur_offset = idx->offsets[0] - 1;
/* sanity check */
- if ( cur_offset >= idx->data_size )
+ if ( cur_offset != 0 )
{
FT_TRACE0(( "cff_index_get_pointers:"
" invalid first offset value %d set to zero\n",
@@ -432,11 +432,11 @@
FT_ULong next_offset = idx->offsets[n] - 1;
- /* empty slot + two sanity checks for invalid offset tables */
- if ( next_offset == 0 ||
- next_offset < cur_offset ||
- ( next_offset >= idx->data_size && n < idx->count ) )
+ /* two sanity checks for invalid offset tables */
+ if ( next_offset < cur_offset )
next_offset = cur_offset;
+ else if ( next_offset > idx->data_size )
+ next_offset = idx->data_size;
if ( !pool )
t[n] = org_bytes + next_offset;
@@ -689,6 +689,13 @@
if ( FT_READ_USHORT( num_ranges ) )
goto Exit;
+ if ( !num_ranges )
+ {
+ FT_TRACE0(( "CFF_Load_FD_Select: empty FDSelect array\n" ));
+ error = FT_THROW( Invalid_File_Format );
+ goto Exit;
+ }
+
fdselect->data_size = num_ranges * 3 + 2;
Load_Data:
@@ -719,7 +726,7 @@
break;
case 3:
- /* first, compare to cache */
+ /* first, compare to the cache */
if ( (FT_UInt)( glyph_index - fdselect->cache_first ) <
fdselect->cache_count )
{
@@ -727,7 +734,7 @@
break;
}
- /* then, lookup the ranges array */
+ /* then, look up the ranges array */
{
FT_Byte* p = fdselect->data;
FT_Byte* p_limit = p + fdselect->data_size;
@@ -750,7 +757,7 @@
/* update cache */
fdselect->cache_first = first;
- fdselect->cache_count = limit-first;
+ fdselect->cache_count = limit - first;
fdselect->cache_fd = fd2;
break;
}
diff --git a/freetype/src/cff/cffobjs.c b/freetype/src/cff/cffobjs.c
index e7dad2bd7..96b4e4f06 100644
--- a/freetype/src/cff/cffobjs.c
+++ b/freetype/src/cff/cffobjs.c
@@ -865,7 +865,7 @@
flags |= FT_FACE_FLAG_KERNING;
#endif
- cffface->face_flags = flags;
+ cffface->face_flags |= flags;
/*******************************************************************/
/* */
@@ -1054,7 +1054,7 @@
CFF_Driver driver = (CFF_Driver)module;
- /* set default property values */
+ /* set default property values, cf `ftcffdrv.h' */
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
driver->hinting_engine = FT_CFF_HINTING_FREETYPE;
#else
@@ -1062,6 +1062,15 @@
#endif
driver->no_stem_darkening = FALSE;
+ driver->darken_params[0] = 500;
+ driver->darken_params[1] = 400;
+ driver->darken_params[2] = 1000;
+ driver->darken_params[3] = 275;
+ driver->darken_params[4] = 1667;
+ driver->darken_params[5] = 275;
+ driver->darken_params[6] = 2333;
+ driver->darken_params[7] = 0;
+
return FT_Err_Ok;
}
diff --git a/freetype/src/cff/cffobjs.h b/freetype/src/cff/cffobjs.h
index 0a2de733f..072c0d080 100644
--- a/freetype/src/cff/cffobjs.h
+++ b/freetype/src/cff/cffobjs.h
@@ -121,6 +121,8 @@ FT_BEGIN_HEADER
FT_UInt hinting_engine;
FT_Bool no_stem_darkening;
+ FT_Int darken_params[8];
+
} CFF_DriverRec;
diff --git a/freetype/src/cff/cffparse.c b/freetype/src/cff/cffparse.c
index fad920315..d922f584b 100644
--- a/freetype/src/cff/cffparse.c
+++ b/freetype/src/cff/cffparse.c
@@ -4,7 +4,7 @@
/* */
/* CFF token stream parser (body) */
/* */
-/* Copyright 1996-2004, 2007-2013 by */
+/* Copyright 1996-2004, 2007-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -66,7 +66,6 @@
goto Bad;
val = (FT_Short)( ( (FT_UShort)p[0] << 8 ) | p[1] );
- p += 2;
}
else if ( v == 29 )
{
@@ -77,7 +76,6 @@
( (FT_ULong)p[1] << 16 ) |
( (FT_ULong)p[2] << 8 ) |
(FT_ULong)p[3] );
- p += 4;
}
else if ( v < 247 )
{
@@ -89,7 +87,6 @@
goto Bad;
val = ( v - 247 ) * 256 + p[0] + 108;
- p++;
}
else
{
@@ -97,7 +94,6 @@
goto Bad;
val = -( v - 251 ) * 256 - p[0] - 108;
- p++;
}
Exit:
diff --git a/freetype/src/cid/cidgload.c b/freetype/src/cid/cidgload.c
index 559ec0bd3..07d8fa915 100644
--- a/freetype/src/cid/cidgload.c
+++ b/freetype/src/cid/cidgload.c
@@ -58,7 +58,7 @@
#endif
- FT_TRACE4(( "cid_load_glyph: glyph index %d\n", glyph_index ));
+ FT_TRACE1(( "cid_load_glyph: glyph index %d\n", glyph_index ));
#ifdef FT_CONFIG_OPTION_INCREMENTAL
diff --git a/freetype/src/cid/cidload.c b/freetype/src/cid/cidload.c
index 44646a764..b39d6c3a6 100644
--- a/freetype/src/cid/cidload.c
+++ b/freetype/src/cid/cidload.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 font loader (body). */
/* */
-/* Copyright 1996-2006, 2009, 2011-2013 by */
+/* Copyright 1996-2006, 2009, 2011-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -150,8 +150,6 @@
cid_parse_font_matrix( CID_Face face,
CID_Parser* parser )
{
- FT_Matrix* matrix;
- FT_Vector* offset;
CID_FaceDict dict;
FT_Face root = (FT_Face)&face->root;
FT_Fixed temp[6];
@@ -160,14 +158,28 @@
if ( parser->num_dict >= 0 && parser->num_dict < face->cid.num_dicts )
{
+ FT_Matrix* matrix;
+ FT_Vector* offset;
+ FT_Int result;
+
+
dict = face->cid.font_dicts + parser->num_dict;
matrix = &dict->font_matrix;
offset = &dict->font_offset;
- (void)cid_parser_to_fixed_array( parser, 6, temp, 3 );
+ result = cid_parser_to_fixed_array( parser, 6, temp, 3 );
+
+ if ( result < 6 )
+ return FT_THROW( Invalid_File_Format );
temp_scale = FT_ABS( temp[3] );
+ if ( temp_scale == 0 )
+ {
+ FT_ERROR(( "cid_parse_font_matrix: invalid font matrix\n" ));
+ return FT_THROW( Invalid_File_Format );
+ }
+
/* Set Units per EM based on FontMatrix values. We set the value to */
/* 1000 / temp_scale, because temp_scale was already multiplied by */
/* 1000 (in t1_tofixed, from psobjs.c). */
@@ -182,7 +194,7 @@
temp[2] = FT_DivFix( temp[2], temp_scale );
temp[4] = FT_DivFix( temp[4], temp_scale );
temp[5] = FT_DivFix( temp[5], temp_scale );
- temp[3] = 0x10000L;
+ temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
}
matrix->xx = temp[0];
@@ -195,8 +207,7 @@
offset->y = temp[5] >> 16;
}
- return FT_Err_Ok; /* this is a callback function; */
- /* we must return an error code */
+ return FT_Err_Ok;
}
diff --git a/freetype/src/cid/cidobjs.c b/freetype/src/cid/cidobjs.c
index 145d62998..41bd735f6 100644
--- a/freetype/src/cid/cidobjs.c
+++ b/freetype/src/cid/cidobjs.c
@@ -355,9 +355,10 @@
cidface->num_charmaps = 0;
cidface->face_index = face_index;
- cidface->face_flags = FT_FACE_FLAG_SCALABLE | /* scalable outlines */
- FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
- FT_FACE_FLAG_HINTER; /* has native hinter */
+
+ cidface->face_flags |= FT_FACE_FLAG_SCALABLE | /* scalable outlines */
+ FT_FACE_FLAG_HORIZONTAL | /* horizontal data */
+ FT_FACE_FLAG_HINTER; /* has native hinter */
if ( info->is_fixed_pitch )
cidface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
diff --git a/freetype/src/cid/cidparse.c b/freetype/src/cid/cidparse.c
index 4f595dd64..c56e18b2d 100644
--- a/freetype/src/cid/cidparse.c
+++ b/freetype/src/cid/cidparse.c
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 parser (body). */
/* */
-/* Copyright 1996-2007, 2009, 2013 by */
+/* Copyright 1996-2007, 2009, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -178,8 +178,6 @@
if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
parser->binary_length = ft_atol( (const char *)arg2 );
- limit = parser->root.limit;
- cur = parser->root.cursor;
goto Exit;
}
else if ( cur[1] == 's' && ft_strncmp( (char*)cur, "/sfnts", 6 ) == 0 )
diff --git a/freetype/src/cid/cidparse.h b/freetype/src/cid/cidparse.h
index f25e652bc..40b3991e9 100644
--- a/freetype/src/cid/cidparse.h
+++ b/freetype/src/cid/cidparse.h
@@ -4,7 +4,7 @@
/* */
/* CID-keyed Type1 parser (specification). */
/* */
-/* Copyright 1996-2001, 2002, 2003, 2004 by */
+/* Copyright 1996-2004, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -92,26 +92,26 @@ FT_BEGIN_HEADER
/* */
/*************************************************************************/
-#define cid_parser_skip_spaces( p ) \
+#define cid_parser_skip_spaces( p ) \
(p)->root.funcs.skip_spaces( &(p)->root )
-#define cid_parser_skip_PS_token( p ) \
+#define cid_parser_skip_PS_token( p ) \
(p)->root.funcs.skip_PS_token( &(p)->root )
-#define cid_parser_to_int( p ) (p)->root.funcs.to_int( &(p)->root )
-#define cid_parser_to_fixed( p, t ) (p)->root.funcs.to_fixed( &(p)->root, t )
+#define cid_parser_to_int( p ) (p)->root.funcs.to_int( &(p)->root )
+#define cid_parser_to_fixed( p, t ) (p)->root.funcs.to_fixed( &(p)->root, t )
-#define cid_parser_to_coord_array( p, m, c ) \
+#define cid_parser_to_coord_array( p, m, c ) \
(p)->root.funcs.to_coord_array( &(p)->root, m, c )
-#define cid_parser_to_fixed_array( p, m, f, t ) \
+#define cid_parser_to_fixed_array( p, m, f, t ) \
(p)->root.funcs.to_fixed_array( &(p)->root, m, f, t )
-#define cid_parser_to_token( p, t ) \
+#define cid_parser_to_token( p, t ) \
(p)->root.funcs.to_token( &(p)->root, t )
-#define cid_parser_to_token_array( p, t, m, c ) \
+#define cid_parser_to_token_array( p, t, m, c ) \
(p)->root.funcs.to_token_array( &(p)->root, t, m, c )
-#define cid_parser_load_field( p, f, o ) \
+#define cid_parser_load_field( p, f, o ) \
(p)->root.funcs.load_field( &(p)->root, f, o, 0, 0 )
-#define cid_parser_load_field_table( p, f, o ) \
+#define cid_parser_load_field_table( p, f, o ) \
(p)->root.funcs.load_field_table( &(p)->root, f, o, 0, 0 )
diff --git a/freetype/src/gxvalid/gxvcommn.c b/freetype/src/gxvalid/gxvcommn.c
index 2ac80be8c..7af52342b 100644
--- a/freetype/src/gxvalid/gxvcommn.c
+++ b/freetype/src/gxvalid/gxvcommn.c
@@ -1288,7 +1288,9 @@
valid );
else
{
+#if 0
maxState = 1; /* 0:start of text, 1:start of line are predefined */
+#endif
maxEntry = 0;
}
@@ -1621,8 +1623,10 @@
gxv_LookupTable_validate( table + classTable,
table + classTable + classTable_length,
valid );
+#if 0
if ( valid->subtable_length < classTable_length )
classTable_length = valid->subtable_length;
+#endif
}
else
{
@@ -1641,7 +1645,9 @@
valid );
else
{
+#if 0
maxState = 1; /* 0:start of text, 1:start of line are predefined */
+#endif
maxEntry = 0;
}
@@ -1727,6 +1733,7 @@
odtect->range[j].start,
odtect->range[j].length ) )
{
+#ifdef FT_DEBUG_LEVEL_TRACE
if ( odtect->range[i].name || odtect->range[j].name )
GXV_TRACE(( "found overlap between range %d and range %d\n",
i, j ));
@@ -1734,6 +1741,7 @@
GXV_TRACE(( "found overlap between `%s' and `%s\'\n",
odtect->range[i].name,
odtect->range[j].name ));
+#endif
FT_INVALID_OFFSET;
}
diff --git a/freetype/src/gxvalid/gxvmort.c b/freetype/src/gxvalid/gxvmort.c
index 5356e67ca..c4d49b32d 100644
--- a/freetype/src/gxvalid/gxvmort.c
+++ b/freetype/src/gxvalid/gxvmort.c
@@ -123,6 +123,7 @@
{
FT_UNUSED( valid );
+#ifdef FT_DEBUG_LEVEL_TRACE
if ( coverage & 0x8000U )
GXV_TRACE(( " this subtable is for vertical text only\n" ));
else
@@ -141,6 +142,7 @@
if ( coverage & 0x1FF8 )
GXV_TRACE(( " coverage has non-zero bits in reserved area\n" ));
+#endif
}
diff --git a/freetype/src/gxvalid/gxvmorx2.c b/freetype/src/gxvalid/gxvmorx2.c
index 9d2b0bc4a..95b8ea40b 100644
--- a/freetype/src/gxvalid/gxvmorx2.c
+++ b/freetype/src/gxvalid/gxvmorx2.c
@@ -5,7 +5,7 @@
/* TrueTypeGX/AAT morx table validation */
/* body for type2 (Ligature Substitution) subtable. */
/* */
-/* Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
+/* Copyright 2005, 2013 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -317,7 +317,9 @@
gxv_XStateTable_validate( p, limit, valid );
+#if 0
p += valid->subtable_length;
+#endif
gxv_morx_subtable_type2_ligatureTable_validate( table, valid );
GXV_EXIT;
diff --git a/freetype/src/gzip/ftgzip.c b/freetype/src/gzip/ftgzip.c
index 4ae3fa77f..88f9af2a8 100644
--- a/freetype/src/gzip/ftgzip.c
+++ b/freetype/src/gzip/ftgzip.c
@@ -596,6 +596,8 @@
}
+ /* documentation is in ftgzip.h */
+
FT_EXPORT_DEF( FT_Error )
FT_Stream_OpenGzip( FT_Stream stream,
FT_Stream source )
@@ -684,7 +686,64 @@
return error;
}
-#else /* !FT_CONFIG_OPTION_USE_ZLIB */
+
+ /* documentation is in ftgzip.h */
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Gzip_Uncompress( FT_Memory memory,
+ FT_Byte* output,
+ FT_ULong* output_len,
+ const FT_Byte* input,
+ FT_ULong input_len )
+ {
+ z_stream stream;
+ int err;
+
+
+ /* this function is modeled after zlib's `uncompress' function */
+
+ stream.next_in = (Bytef*)input;
+ stream.avail_in = (uInt)input_len;
+
+ stream.next_out = output;
+ stream.avail_out = (uInt)*output_len;
+
+ stream.zalloc = (alloc_func)ft_gzip_alloc;
+ stream.zfree = (free_func) ft_gzip_free;
+ stream.opaque = memory;
+
+ err = inflateInit2( &stream, MAX_WBITS );
+ if ( err != Z_OK )
+ return FT_THROW( Invalid_Argument );
+
+ err = inflate( &stream, Z_FINISH );
+ if ( err != Z_STREAM_END )
+ {
+ inflateEnd( &stream );
+ if ( err == Z_OK )
+ err = Z_BUF_ERROR;
+ }
+ else
+ {
+ *output_len = stream.total_out;
+
+ err = inflateEnd( &stream );
+ }
+
+ if ( err == Z_MEM_ERROR )
+ return FT_THROW( Out_Of_Memory );
+
+ if ( err == Z_BUF_ERROR )
+ return FT_THROW( Array_Too_Large );
+
+ if ( err == Z_DATA_ERROR )
+ return FT_THROW( Invalid_Table );
+
+ return FT_Err_Ok;
+ }
+
+
+#else /* !FT_CONFIG_OPTION_USE_ZLIB */
FT_EXPORT_DEF( FT_Error )
FT_Stream_OpenGzip( FT_Stream stream,
@@ -696,6 +755,23 @@
return FT_THROW( Unimplemented_Feature );
}
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Gzip_Uncompress( FT_Memory memory,
+ FT_Byte* output,
+ FT_ULong* output_len,
+ const FT_Byte* input,
+ FT_ULong input_len )
+ {
+ FT_UNUSED( memory );
+ FT_UNUSED( output );
+ FT_UNUSED( output_len );
+ FT_UNUSED( input );
+ FT_UNUSED( input_len );
+
+ return FT_THROW( Unimplemented_Feature );
+ }
+
#endif /* !FT_CONFIG_OPTION_USE_ZLIB */
diff --git a/freetype/src/gzip/rules.mk b/freetype/src/gzip/rules.mk
index d2a43a6a8..37cd99176 100644
--- a/freetype/src/gzip/rules.mk
+++ b/freetype/src/gzip/rules.mk
@@ -3,7 +3,7 @@
#
-# Copyright 2002, 2003 by
+# Copyright 2002, 2003, 2013 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
@@ -27,49 +27,52 @@ else
endif
-# gzip support sources (i.e., C files)
+# gzip support sources
#
-GZIP_DRV_SRC := $(GZIP_DIR)/ftgzip.c
-
-# gzip support headers
+# All source and header files get loaded by `ftgzip.c' only if SYTEM_ZLIB is
+# not defined (regardless whether we have a `single' or a `multi' build).
+# However, it doesn't harm if we add everything as a dependency
+# unconditionally.
#
-GZIP_DRV_H :=
+GZIP_DRV_SRCS := $(GZIP_DIR)/adler32.c \
+ $(GZIP_DIR)/infblock.c \
+ $(GZIP_DIR)/infblock.h \
+ $(GZIP_DIR)/infcodes.c \
+ $(GZIP_DIR)/infcodes.h \
+ $(GZIP_DIR)/inffixed.h \
+ $(GZIP_DIR)/inflate.c \
+ $(GZIP_DIR)/inftrees.c \
+ $(GZIP_DIR)/inftrees.h \
+ $(GZIP_DIR)/infutil.c \
+ $(GZIP_DIR)/infutil.h \
+ $(GZIP_DIR)/zconf.h \
+ $(GZIP_DIR)/zlib.h \
+ $(GZIP_DIR)/zutil.c \
+ $(GZIP_DIR)/zutil.h
# gzip driver object(s)
#
-# GZIP_DRV_OBJ_M is used during `multi' builds
-# GZIP_DRV_OBJ_S is used during `single' builds
-#
-ifeq ($(SYSTEM_ZLIB),)
- GZIP_DRV_OBJ_M := $(GZIP_DRV_SRC:$(GZIP_DIR)/%.c=$(OBJ_DIR)/%.$O)
-else
- GZIP_DRV_OBJ_M := $(OBJ_DIR)/ftgzip.$O
-endif
-GZIP_DRV_OBJ_S := $(OBJ_DIR)/ftgzip.$O
-
-# gzip support source file for single build
+# GZIP_DRV_OBJ is used during both `single' and `multi' builds
#
-GZIP_DRV_SRC_S := $(GZIP_DIR)/ftgzip.c
+GZIP_DRV_OBJ := $(OBJ_DIR)/ftgzip.$O
-# gzip support - single object
+# gzip main source file
#
-$(GZIP_DRV_OBJ_S): $(GZIP_DRV_SRC_S) $(GZIP_DRV_SRC) $(FREETYPE_H) \
- $(GZIP_DRV_H)
- $(GZIP_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(GZIP_DRV_SRC_S))
+GZIP_DRV_SRC := $(GZIP_DIR)/ftgzip.c
-# gzip support - multiple objects
+# gzip support - object
#
-$(OBJ_DIR)/%.$O: $(GZIP_DIR)/%.c $(FREETYPE_H) $(GZIP_DRV_H)
- $(GZIP_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
+$(GZIP_DRV_OBJ): $(GZIP_DRV_SRC) $(GZIP_DRV_SRCS) $(FREETYPE_H)
+ $(GZIP_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(GZIP_DRV_SRC))
# update main driver object lists
#
-DRV_OBJS_S += $(GZIP_DRV_OBJ_S)
-DRV_OBJS_M += $(GZIP_DRV_OBJ_M)
+DRV_OBJS_S += $(GZIP_DRV_OBJ)
+DRV_OBJS_M += $(GZIP_DRV_OBJ)
# EOF
diff --git a/freetype/src/pcf/pcfdrivr.c b/freetype/src/pcf/pcfdrivr.c
index 903d7ee5a..44fb3789c 100644
--- a/freetype/src/pcf/pcfdrivr.c
+++ b/freetype/src/pcf/pcfdrivr.c
@@ -218,25 +218,24 @@ THE SOFTWARE.
FT_FREE( face->metrics );
/* free properties */
+ if ( face->properties )
{
- PCF_Property prop;
- FT_Int i;
+ FT_Int i;
- if ( face->properties )
+ for ( i = 0; i < face->nprops; i++ )
{
- for ( i = 0; i < face->nprops; i++ )
+ PCF_Property prop = &face->properties[i];
+
+
+ if ( prop )
{
- prop = &face->properties[i];
-
- if ( prop )
- {
- FT_FREE( prop->name );
- if ( prop->isString )
- FT_FREE( prop->value.atom );
- }
+ FT_FREE( prop->name );
+ if ( prop->isString )
+ FT_FREE( prop->value.atom );
}
}
+
FT_FREE( face->properties );
}
@@ -264,11 +263,10 @@ THE SOFTWARE.
FT_Parameter* params )
{
PCF_Face face = (PCF_Face)pcfface;
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
FT_UNUSED( num_params );
FT_UNUSED( params );
- FT_UNUSED( face_index );
FT_TRACE2(( "PCF driver\n" ));
@@ -347,6 +345,18 @@ THE SOFTWARE.
#endif
}
+ /* PCF could not have multiple face in single font file.
+ * XXX: non-zero face_index is already invalid argument, but
+ * Type1, Type42 driver has a convention to return
+ * an invalid argument error when the font could be
+ * opened by the specified driver.
+ */
+ if ( face_index > 0 ) {
+ FT_ERROR(( "PCF_Face_Init: invalid face index\n" ));
+ PCF_Face_Done( pcfface );
+ return FT_THROW( Invalid_Argument );
+ }
+
/* set up charmap */
{
FT_String *charset_registry = face->charset_registry;
@@ -482,7 +492,7 @@ THE SOFTWARE.
FT_UNUSED( load_flags );
- FT_TRACE4(( "load_glyph %d ---", glyph_index ));
+ FT_TRACE1(( "PCF_Glyph_Load: glyph index %d\n", glyph_index ));
if ( !face || glyph_index >= (FT_UInt)face->root.num_glyphs )
{
@@ -576,8 +586,6 @@ THE SOFTWARE.
( face->accel.fontAscent +
face->accel.fontDescent ) << 6 );
- FT_TRACE4(( " --- ok\n" ));
-
Exit:
return error;
}
diff --git a/freetype/src/pcf/pcfread.c b/freetype/src/pcf/pcfread.c
index 74b6cc65f..e8ea4e4c5 100644
--- a/freetype/src/pcf/pcfread.c
+++ b/freetype/src/pcf/pcfread.c
@@ -1096,7 +1096,7 @@ THE SOFTWARE.
pcf_load_font( FT_Stream stream,
PCF_Face face )
{
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
FT_Memory memory = FT_FACE( face )->memory;
FT_Bool hasBDFAccelerators;
@@ -1153,9 +1153,10 @@ THE SOFTWARE.
root->num_faces = 1;
root->face_index = 0;
- root->face_flags = FT_FACE_FLAG_FIXED_SIZES |
- FT_FACE_FLAG_HORIZONTAL |
- FT_FACE_FLAG_FAST_GLYPHS;
+
+ root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+ FT_FACE_FLAG_HORIZONTAL |
+ FT_FACE_FLAG_FAST_GLYPHS;
if ( face->accel.constantWidth )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
diff --git a/freetype/src/pcf/pcfutil.c b/freetype/src/pcf/pcfutil.c
index b91274f93..0451ee8de 100644
--- a/freetype/src/pcf/pcfutil.c
+++ b/freetype/src/pcf/pcfutil.c
@@ -66,11 +66,11 @@ in this Software without prior written authorization from The Open Group.
TwoByteSwap( unsigned char* buf,
size_t nbytes )
{
- unsigned char c;
-
-
for ( ; nbytes >= 2; nbytes -= 2, buf += 2 )
{
+ unsigned char c;
+
+
c = buf[0];
buf[0] = buf[1];
buf[1] = c;
@@ -85,11 +85,11 @@ in this Software without prior written authorization from The Open Group.
FourByteSwap( unsigned char* buf,
size_t nbytes )
{
- unsigned char c;
-
-
for ( ; nbytes >= 4; nbytes -= 4, buf += 4 )
{
+ unsigned char c;
+
+
c = buf[0];
buf[0] = buf[3];
buf[3] = c;
diff --git a/freetype/src/pfr/pfrcmap.c b/freetype/src/pfr/pfrcmap.c
index 740c433d6..1f05640cc 100644
--- a/freetype/src/pfr/pfrcmap.c
+++ b/freetype/src/pfr/pfrcmap.c
@@ -67,14 +67,16 @@
pfr_cmap_char_index( PFR_CMap cmap,
FT_UInt32 char_code )
{
- FT_UInt min = 0;
- FT_UInt max = cmap->num_chars;
- FT_UInt mid;
- PFR_Char gchar;
+ FT_UInt min = 0;
+ FT_UInt max = cmap->num_chars;
while ( min < max )
{
+ PFR_Char gchar;
+ FT_UInt mid;
+
+
mid = min + ( max - min ) / 2;
gchar = cmap->chars + mid;
diff --git a/freetype/src/pfr/pfrload.c b/freetype/src/pfr/pfrload.c
index 58a1506fa..f91fb077b 100644
--- a/freetype/src/pfr/pfrload.c
+++ b/freetype/src/pfr/pfrload.c
@@ -4,7 +4,7 @@
/* */
/* FreeType PFR loader (body). */
/* */
-/* Copyright 2002-2005, 2007, 2009, 2010, 2013 by */
+/* Copyright 2002-2005, 2007, 2009, 2010, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -813,7 +813,6 @@
phy_font->ascent = PFR_NEXT_SHORT( q );
phy_font->descent = PFR_NEXT_SHORT( q );
phy_font->leading = PFR_NEXT_SHORT( q );
- q += 16;
break;
case 3:
diff --git a/freetype/src/pfr/pfrobjs.c b/freetype/src/pfr/pfrobjs.c
index bfa4a3af2..80e4b7e71 100644
--- a/freetype/src/pfr/pfrobjs.c
+++ b/freetype/src/pfr/pfrobjs.c
@@ -137,7 +137,8 @@
pfrface->face_index = face_index;
pfrface->num_glyphs = phy_font->num_chars + 1;
- pfrface->face_flags = FT_FACE_FLAG_SCALABLE;
+
+ pfrface->face_flags |= FT_FACE_FLAG_SCALABLE;
/* if all characters point to the same gps_offset 0, we */
/* assume that the font only contains bitmaps */
@@ -324,6 +325,8 @@
FT_ULong gps_offset;
+ FT_TRACE1(( "pfr_slot_load: glyph index %d\n", gindex ));
+
if ( gindex > 0 )
gindex--;
diff --git a/freetype/src/psaux/psobjs.c b/freetype/src/psaux/psobjs.c
index 5c292e1eb..5659220bb 100644
--- a/freetype/src/psaux/psobjs.c
+++ b/freetype/src/psaux/psobjs.c
@@ -4,7 +4,7 @@
/* */
/* Auxiliary functions for PostScript fonts (body). */
/* */
-/* Copyright 1996-2013 by */
+/* Copyright 1996-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -847,6 +847,8 @@
/* first character must be a delimiter or a part of a number */
/* NB: `values' can be NULL if we just want to skip the */
/* array; in this case we ignore `max_values' */
+ /* */
+ /* return number of successfully parsed values */
static FT_Int
ps_tofixedarray( FT_Byte* *acur,
@@ -1200,7 +1202,7 @@
result = ps_tofixedarray( &cur, limit, 4, temp, 0 );
- if ( result < 0 )
+ if ( result < 4 )
{
FT_ERROR(( "ps_parser_load_field:"
" expected four integers in bounding box\n" ));
@@ -1230,7 +1232,7 @@
{
result = ps_tofixedarray( &cur, limit, max_objects,
temp + i * max_objects, 0 );
- if ( result < 0 )
+ if ( result < 0 || (FT_UInt)result < max_objects )
{
FT_ERROR(( "ps_parser_load_field:"
" expected %d integers in the %s subarray\n"
diff --git a/freetype/src/pshinter/pshalgo.c b/freetype/src/pshinter/pshalgo.c
index 9a37ec351..2a7497825 100644
--- a/freetype/src/pshinter/pshalgo.c
+++ b/freetype/src/pshinter/pshalgo.c
@@ -4,7 +4,7 @@
/* */
/* PostScript hinting algorithm (body). */
/* */
-/* Copyright 2001-2010, 2012, 2013 by */
+/* Copyright 2001-2010, 2012-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used */
@@ -1406,7 +1406,6 @@
point = first;
before = point;
- after = point;
do
{
@@ -2079,8 +2078,6 @@
start = first;
do
{
- point = first;
-
/* skip consecutive fitted points */
for (;;)
{
diff --git a/freetype/src/pshinter/pshglob.c b/freetype/src/pshinter/pshglob.c
index b3e224203..ac1e37baf 100644
--- a/freetype/src/pshinter/pshglob.c
+++ b/freetype/src/pshinter/pshglob.c
@@ -5,7 +5,7 @@
/* PostScript hinter global hinting management (body). */
/* Inspired by the new auto-hinter module. */
/* */
-/* Copyright 2001-2004, 2006, 2010, 2012 by */
+/* Copyright 2001-2004, 2006, 2010, 2012, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used */
@@ -757,7 +757,7 @@
FT_Fixed x_delta,
FT_Fixed y_delta )
{
- PSH_Dimension dim = &globals->dimension[0];
+ PSH_Dimension dim;
dim = &globals->dimension[0];
diff --git a/freetype/src/psnames/rules.mk b/freetype/src/psnames/rules.mk
index 4cd39a8cc..f321de2d6 100644
--- a/freetype/src/psnames/rules.mk
+++ b/freetype/src/psnames/rules.mk
@@ -3,7 +3,7 @@
#
-# Copyright 1996-2000, 2001, 2003, 2011 by
+# Copyright 1996-2001, 2003, 2011, 2013 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
@@ -46,7 +46,7 @@ PSNAMES_DRV_OBJ_S := $(OBJ_DIR)/psnames.$O
# PSNames driver source file for single build
#
-PSNAMES_DRV_SRC_S := $(PSNAMES_DIR)/psmodule.c
+PSNAMES_DRV_SRC_S := $(PSNAMES_DIR)/psnames.c
# PSNames driver - single object
diff --git a/freetype/src/raster/ftraster.c b/freetype/src/raster/ftraster.c
index cd442d69c..908352a59 100644
--- a/freetype/src/raster/ftraster.c
+++ b/freetype/src/raster/ftraster.c
@@ -4,7 +4,7 @@
/* */
/* The FreeType glyph rasterizer (body). */
/* */
-/* Copyright 1996-2003, 2005, 2007-2013 by */
+/* Copyright 1996-2003, 2005, 2007-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -24,8 +24,8 @@
/* */
/* - copy `src/raster/ftraster.c' (this file) to your current directory */
/* */
- /* - copy `include/freetype/ftimage.h' and `src/raster/ftmisc.h' */
- /* to your current directory */
+ /* - copy `include/ftimage.h' and `src/raster/ftmisc.h' to your current */
+ /* directory */
/* */
/* - compile `ftraster' with the _STANDALONE_ macro defined, as in */
/* */
@@ -1874,7 +1874,7 @@
v_start.x = ( v_start.x + v_last.x ) / 2;
v_start.y = ( v_start.y + v_last.y ) / 2;
- v_last = v_start;
+ /* v_last = v_start; */
}
point--;
tags--;
diff --git a/freetype/src/sfnt/pngshim.c b/freetype/src/sfnt/pngshim.c
index 408f879c3..878de1fef 100644
--- a/freetype/src/sfnt/pngshim.c
+++ b/freetype/src/sfnt/pngshim.c
@@ -122,7 +122,7 @@
error_callback( png_structp png,
png_const_charp error_msg )
{
- FT_Error* error = png_get_error_ptr( png );
+ FT_Error* error = (FT_Error*)png_get_error_ptr( png );
FT_UNUSED( error_msg );
@@ -159,7 +159,7 @@
if ( FT_FRAME_ENTER( length ) )
{
- FT_Error* e = png_get_error_ptr( png );
+ FT_Error* e = (FT_Error*)png_get_error_ptr( png );
*e = FT_THROW( Invalid_Stream_Read );
@@ -174,16 +174,18 @@
}
- static FT_Error
- Load_SBit_Png( FT_Bitmap* map,
+ FT_LOCAL_DEF( FT_Error )
+ Load_SBit_Png( FT_GlyphSlot slot,
FT_Int x_offset,
FT_Int y_offset,
FT_Int pix_bits,
TT_SBit_Metrics metrics,
FT_Memory memory,
FT_Byte* data,
- FT_UInt png_len )
+ FT_UInt png_len,
+ FT_Bool populate_map_and_metrics )
{
+ FT_Bitmap *map = &slot->bitmap;
FT_Error error = FT_Err_Ok;
FT_StreamRec stream;
@@ -193,12 +195,21 @@
int bitdepth, color_type, interlace;
FT_Int i;
- png_byte* *rows;
+ png_byte* *rows = NULL; /* pacify compiler */
- if ( x_offset < 0 || x_offset + metrics->width > map->width ||
- y_offset < 0 || y_offset + metrics->height > map->rows ||
- pix_bits != 32 || map->pixel_mode != FT_PIXEL_MODE_BGRA )
+ if ( x_offset < 0 ||
+ y_offset < 0 )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Exit;
+ }
+
+ if ( !populate_map_and_metrics &&
+ ( x_offset + metrics->width > map->width ||
+ y_offset + metrics->height > map->rows ||
+ pix_bits != 32 ||
+ map->pixel_mode != FT_PIXEL_MODE_BGRA ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
@@ -238,11 +249,33 @@
&bitdepth, &color_type, &interlace,
NULL, NULL );
- if ( error != FT_Err_Ok ||
- (FT_Int)imgWidth != metrics->width ||
- (FT_Int)imgHeight != metrics->height )
+ if ( error ||
+ ( !populate_map_and_metrics &&
+ ( (FT_Int)imgWidth != metrics->width ||
+ (FT_Int)imgHeight != metrics->height ) ) )
goto DestroyExit;
+ if ( populate_map_and_metrics )
+ {
+ FT_Long size;
+
+
+ metrics->width = (FT_Int)imgWidth;
+ metrics->height = (FT_Int)imgHeight;
+
+ map->width = metrics->width;
+ map->rows = metrics->height;
+ map->pixel_mode = FT_PIXEL_MODE_BGRA;
+ map->pitch = map->width * 4;
+ map->num_grays = 256;
+
+ size = map->rows * map->pitch;
+
+ error = ft_glyphslot_alloc_bitmap( slot, size );
+ if ( error )
+ goto DestroyExit;
+ }
+
/* convert palette/gray image to rgb */
if ( color_type == PNG_COLOR_TYPE_PALETTE )
png_set_palette_to_rgb( png );
diff --git a/freetype/src/sfnt/pngshim.h b/freetype/src/sfnt/pngshim.h
index 8a2e69ccf..dc9ecaf91 100644
--- a/freetype/src/sfnt/pngshim.h
+++ b/freetype/src/sfnt/pngshim.h
@@ -29,14 +29,15 @@ FT_BEGIN_HEADER
#ifdef FT_CONFIG_OPTION_USE_PNG
FT_LOCAL( FT_Error )
- Load_SBit_Png( FT_Bitmap* map,
+ Load_SBit_Png( FT_GlyphSlot slot,
FT_Int x_offset,
FT_Int y_offset,
FT_Int pix_bits,
TT_SBit_Metrics metrics,
FT_Memory memory,
FT_Byte* data,
- FT_UInt png_len );
+ FT_UInt png_len,
+ FT_Bool populate_map_and_metrics );
#endif
diff --git a/freetype/src/sfnt/sfdriver.c b/freetype/src/sfnt/sfdriver.c
index 4ff80ca83..cea38be6b 100644
--- a/freetype/src/sfnt/sfdriver.c
+++ b/freetype/src/sfnt/sfdriver.c
@@ -4,7 +4,7 @@
/* */
/* High-level SFNT driver interface (body). */
/* */
-/* Copyright 1996-2007, 2009-2013 by */
+/* Copyright 1996-2007, 2009-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -266,7 +266,7 @@
{
FT_Stream stream = face->name_table.stream;
FT_String* r = (FT_String*)result;
- FT_Byte* p = (FT_Byte*)name->string;
+ FT_Byte* p;
if ( FT_STREAM_SEEK( name->stringOffset ) ||
@@ -499,8 +499,8 @@
tt_face_load_hmtx,
/* see `ttsbit.h' and `sfnt.h' */
- PUT_EMBEDDED_BITMAPS( tt_face_load_eblc ),
- PUT_EMBEDDED_BITMAPS( tt_face_free_eblc ),
+ PUT_EMBEDDED_BITMAPS( tt_face_load_sbit ),
+ PUT_EMBEDDED_BITMAPS( tt_face_free_sbit ),
PUT_EMBEDDED_BITMAPS( tt_face_set_sbit_strike ),
PUT_EMBEDDED_BITMAPS( tt_face_load_strike_metrics ),
diff --git a/freetype/src/sfnt/sfobjs.c b/freetype/src/sfnt/sfobjs.c
index 9280d39f1..93e4321b6 100644
--- a/freetype/src/sfnt/sfobjs.c
+++ b/freetype/src/sfnt/sfobjs.c
@@ -27,6 +27,7 @@
#include FT_TRUETYPE_TAGS_H
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
#include FT_SFNT_NAMES_H
+#include FT_GZIP_H
#include "sferrors.h"
#ifdef TT_CONFIG_OPTION_BDF
@@ -347,6 +348,380 @@
}
+#define WRITE_BYTE( p, v ) \
+ do \
+ { \
+ *(p)++ = (v) >> 0; \
+ \
+ } while ( 0 )
+
+#define WRITE_USHORT( p, v ) \
+ do \
+ { \
+ *(p)++ = (v) >> 8; \
+ *(p)++ = (v) >> 0; \
+ \
+ } while ( 0 )
+
+#define WRITE_ULONG( p, v ) \
+ do \
+ { \
+ *(p)++ = (v) >> 24; \
+ *(p)++ = (v) >> 16; \
+ *(p)++ = (v) >> 8; \
+ *(p)++ = (v) >> 0; \
+ \
+ } while ( 0 )
+
+
+ static void
+ sfnt_stream_close( FT_Stream stream )
+ {
+ FT_Memory memory = stream->memory;
+
+
+ FT_FREE( stream->base );
+
+ stream->size = 0;
+ stream->base = 0;
+ stream->close = 0;
+ }
+
+
+ FT_CALLBACK_DEF( int )
+ compare_offsets( const void* a,
+ const void* b )
+ {
+ WOFF_Table table1 = *(WOFF_Table*)a;
+ WOFF_Table table2 = *(WOFF_Table*)b;
+
+ FT_ULong offset1 = table1->Offset;
+ FT_ULong offset2 = table2->Offset;
+
+
+ if ( offset1 > offset2 )
+ return 1;
+ else if ( offset1 < offset2 )
+ return -1;
+ else
+ return 0;
+ }
+
+
+ /* Replace `face->root.stream' with a stream containing the extracted */
+ /* SFNT of a WOFF font. */
+
+ static FT_Error
+ woff_open_font( FT_Stream stream,
+ TT_Face face )
+ {
+ FT_Memory memory = stream->memory;
+ FT_Error error = FT_Err_Ok;
+
+ WOFF_HeaderRec woff;
+ WOFF_Table tables = NULL;
+ WOFF_Table* indices = NULL;
+
+ FT_ULong woff_offset;
+
+ FT_Byte* sfnt = NULL;
+ FT_Stream sfnt_stream = NULL;
+
+ FT_Byte* sfnt_header;
+ FT_ULong sfnt_offset;
+
+ FT_Int nn;
+ FT_ULong old_tag = 0;
+
+ static const FT_Frame_Field woff_header_fields[] =
+ {
+#undef FT_STRUCTURE
+#define FT_STRUCTURE WOFF_HeaderRec
+
+ FT_FRAME_START( 44 ),
+ FT_FRAME_ULONG ( signature ),
+ FT_FRAME_ULONG ( flavor ),
+ FT_FRAME_ULONG ( length ),
+ FT_FRAME_USHORT( num_tables ),
+ FT_FRAME_USHORT( reserved ),
+ FT_FRAME_ULONG ( totalSfntSize ),
+ FT_FRAME_USHORT( majorVersion ),
+ FT_FRAME_USHORT( minorVersion ),
+ FT_FRAME_ULONG ( metaOffset ),
+ FT_FRAME_ULONG ( metaLength ),
+ FT_FRAME_ULONG ( metaOrigLength ),
+ FT_FRAME_ULONG ( privOffset ),
+ FT_FRAME_ULONG ( privLength ),
+ FT_FRAME_END
+ };
+
+
+ FT_ASSERT( stream == face->root.stream );
+ FT_ASSERT( FT_STREAM_POS() == 0 );
+
+ if ( FT_STREAM_READ_FIELDS( woff_header_fields, &woff ) )
+ return error;
+
+ /* Make sure we don't recurse back here or hit TTC code. */
+ if ( woff.flavor == TTAG_wOFF || woff.flavor == TTAG_ttcf )
+ return FT_THROW( Invalid_Table );
+
+ /* Miscellaneous checks. */
+ if ( woff.length != stream->size ||
+ woff.num_tables == 0 ||
+ 44 + woff.num_tables * 20UL >= woff.length ||
+ 12 + woff.num_tables * 16UL >= woff.totalSfntSize ||
+ ( woff.totalSfntSize & 3 ) != 0 ||
+ ( woff.metaOffset == 0 && ( woff.metaLength != 0 ||
+ woff.metaOrigLength != 0 ) ) ||
+ ( woff.metaLength != 0 && woff.metaOrigLength == 0 ) ||
+ ( woff.privOffset == 0 && woff.privLength != 0 ) )
+ return FT_THROW( Invalid_Table );
+
+ if ( FT_ALLOC( sfnt, woff.totalSfntSize ) ||
+ FT_NEW( sfnt_stream ) )
+ goto Exit;
+
+ sfnt_header = sfnt;
+
+ /* Write sfnt header. */
+ {
+ FT_UInt searchRange, entrySelector, rangeShift, x;
+
+
+ x = woff.num_tables;
+ entrySelector = 0;
+ while ( x )
+ {
+ x >>= 1;
+ entrySelector += 1;
+ }
+ entrySelector--;
+
+ searchRange = ( 1 << entrySelector ) * 16;
+ rangeShift = woff.num_tables * 16 - searchRange;
+
+ WRITE_ULONG ( sfnt_header, woff.flavor );
+ WRITE_USHORT( sfnt_header, woff.num_tables );
+ WRITE_USHORT( sfnt_header, searchRange );
+ WRITE_USHORT( sfnt_header, entrySelector );
+ WRITE_USHORT( sfnt_header, rangeShift );
+ }
+
+ /* While the entries in the sfnt header must be sorted by the */
+ /* tag value, the tables themselves are not. We thus have to */
+ /* sort them by offset and check that they don't overlap. */
+
+ if ( FT_NEW_ARRAY( tables, woff.num_tables ) ||
+ FT_NEW_ARRAY( indices, woff.num_tables ) )
+ goto Exit;
+
+ FT_TRACE2(( "\n"
+ " tag offset compLen origLen checksum\n"
+ " -------------------------------------------\n" ));
+
+ if ( FT_FRAME_ENTER( 20L * woff.num_tables ) )
+ goto Exit;
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = tables + nn;
+
+ table->Tag = FT_GET_TAG4();
+ table->Offset = FT_GET_ULONG();
+ table->CompLength = FT_GET_ULONG();
+ table->OrigLength = FT_GET_ULONG();
+ table->CheckSum = FT_GET_ULONG();
+
+ FT_TRACE2(( " %c%c%c%c %08lx %08lx %08lx %08lx\n",
+ (FT_Char)( table->Tag >> 24 ),
+ (FT_Char)( table->Tag >> 16 ),
+ (FT_Char)( table->Tag >> 8 ),
+ (FT_Char)( table->Tag ),
+ table->Offset,
+ table->CompLength,
+ table->OrigLength,
+ table->CheckSum ));
+
+ if ( table->Tag <= old_tag )
+ {
+ FT_FRAME_EXIT();
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ old_tag = table->Tag;
+ indices[nn] = table;
+ }
+
+ FT_FRAME_EXIT();
+
+ /* Sort by offset. */
+
+ ft_qsort( indices,
+ woff.num_tables,
+ sizeof ( WOFF_Table ),
+ compare_offsets );
+
+ /* Check offsets and lengths. */
+
+ woff_offset = 44 + woff.num_tables * 20L;
+ sfnt_offset = 12 + woff.num_tables * 16L;
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = indices[nn];
+
+
+ if ( table->Offset != woff_offset ||
+ table->Offset + table->CompLength > woff.length ||
+ sfnt_offset + table->OrigLength > woff.totalSfntSize ||
+ table->CompLength > table->OrigLength )
+ {
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ table->OrigOffset = sfnt_offset;
+
+ /* The offsets must be multiples of 4. */
+ woff_offset += ( table->CompLength + 3 ) & ~3;
+ sfnt_offset += ( table->OrigLength + 3 ) & ~3;
+ }
+
+ /*
+ * Final checks!
+ *
+ * We don't decode and check the metadata block.
+ * We don't check table checksums either.
+ * But other than those, I think we implement all
+ * `MUST' checks from the spec.
+ */
+
+ if ( woff.metaOffset )
+ {
+ if ( woff.metaOffset != woff_offset ||
+ woff.metaOffset + woff.metaLength > woff.length )
+ {
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* We have padding only ... */
+ woff_offset += woff.metaLength;
+ }
+
+ if ( woff.privOffset )
+ {
+ /* ... if it isn't the last block. */
+ woff_offset = ( woff_offset + 3 ) & ~3;
+
+ if ( woff.privOffset != woff_offset ||
+ woff.privOffset + woff.privLength > woff.length )
+ {
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* No padding for the last block. */
+ woff_offset += woff.privLength;
+ }
+
+ if ( sfnt_offset != woff.totalSfntSize ||
+ woff_offset != woff.length )
+ {
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+
+ /* Write the tables. */
+
+ for ( nn = 0; nn < woff.num_tables; nn++ )
+ {
+ WOFF_Table table = tables + nn;
+
+
+ /* Write SFNT table entry. */
+ WRITE_ULONG( sfnt_header, table->Tag );
+ WRITE_ULONG( sfnt_header, table->CheckSum );
+ WRITE_ULONG( sfnt_header, table->OrigOffset );
+ WRITE_ULONG( sfnt_header, table->OrigLength );
+
+ /* Write table data. */
+ if ( FT_STREAM_SEEK( table->Offset ) ||
+ FT_FRAME_ENTER( table->CompLength ) )
+ goto Exit;
+
+ if ( table->CompLength == table->OrigLength )
+ {
+ /* Uncompressed data; just copy. */
+ ft_memcpy( sfnt + table->OrigOffset,
+ stream->cursor,
+ table->OrigLength );
+ }
+ else
+ {
+ /* Uncompress with zlib. */
+ FT_ULong output_len = table->OrigLength;
+
+
+ error = FT_Gzip_Uncompress( memory,
+ sfnt + table->OrigOffset, &output_len,
+ stream->cursor, table->CompLength );
+ if ( error )
+ goto Exit;
+ if ( output_len != table->OrigLength )
+ {
+ error = FT_THROW( Invalid_Table );
+ goto Exit;
+ }
+ }
+
+ FT_FRAME_EXIT();
+
+ /* We don't check whether the padding bytes in the WOFF file are */
+ /* actually '\0'. For the output, however, we do set them properly. */
+ sfnt_offset = table->OrigOffset + table->OrigLength;
+ while ( sfnt_offset & 3 )
+ {
+ sfnt[sfnt_offset] = '\0';
+ sfnt_offset++;
+ }
+ }
+
+ /* Ok! Finally ready. Swap out stream and return. */
+ FT_Stream_OpenMemory( sfnt_stream, sfnt, woff.totalSfntSize );
+ sfnt_stream->memory = stream->memory;
+ sfnt_stream->close = sfnt_stream_close;
+
+ FT_Stream_Free(
+ face->root.stream,
+ ( face->root.face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
+
+ face->root.stream = sfnt_stream;
+
+ face->root.face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
+
+ Exit:
+ FT_FREE( tables );
+ FT_FREE( indices );
+
+ if ( error )
+ {
+ FT_FREE( sfnt );
+ FT_Stream_Close( sfnt_stream );
+ FT_FREE( sfnt_stream );
+ }
+
+ return error;
+ }
+
+
+#undef WRITE_BYTE
+#undef WRITE_USHORT
+#undef WRITE_ULONG
+
+
/* Fill in face->ttc_header. If the font is not a TTC, it is */
/* synthesized into a TTC with one offset table. */
static FT_Error
@@ -373,11 +748,28 @@
face->ttc_header.version = 0;
face->ttc_header.count = 0;
+ retry:
offset = FT_STREAM_POS();
if ( FT_READ_ULONG( tag ) )
return error;
+ if ( tag == TTAG_wOFF )
+ {
+ FT_TRACE2(( "sfnt_open_font: file is a WOFF; synthesizing SFNT\n" ));
+
+ if ( FT_STREAM_SEEK( offset ) )
+ return error;
+
+ error = woff_open_font( stream, face );
+ if ( error )
+ return error;
+
+ /* Swap out stream and retry! */
+ stream = face->root.stream;
+ goto retry;
+ }
+
if ( tag != 0x00010000UL &&
tag != TTAG_ttcf &&
tag != TTAG_OTTO &&
@@ -480,6 +872,9 @@
if ( error )
return error;
+ /* Stream may have changed in sfnt_open_font. */
+ stream = face->root.stream;
+
FT_TRACE2(( "sfnt_init_face: %08p, %ld\n", face, face_index ));
if ( face_index < 0 )
@@ -504,7 +899,8 @@
#define LOAD_( x ) \
- do { \
+ do \
+ { \
FT_TRACE2(( "`" #x "' " )); \
FT_TRACE3(( "-->\n" )); \
\
@@ -519,7 +915,8 @@
} while ( 0 )
#define LOADM_( x, vertical ) \
- do { \
+ do \
+ { \
FT_TRACE2(( "`%s" #x "' ", \
vertical ? "vertical " : "" )); \
FT_TRACE3(( "-->\n" )); \
@@ -535,7 +932,8 @@
} while ( 0 )
#define GET_NAME( id, field ) \
- do { \
+ do \
+ { \
error = tt_face_get_name( face, TT_NAME_ID_ ## id, field ); \
if ( error ) \
goto Exit; \
@@ -555,6 +953,7 @@
#endif
FT_Bool has_outline;
FT_Bool is_apple_sbit;
+ FT_Bool is_apple_sbix;
FT_Bool ignore_preferred_family = FALSE;
FT_Bool ignore_preferred_subfamily = FALSE;
@@ -608,6 +1007,14 @@
#endif
is_apple_sbit = 0;
+ is_apple_sbix = !face->goto_table( face, TTAG_sbix, stream, 0 );
+
+ /* Apple 'sbix' color bitmaps are rendered scaled and then the 'glyf'
+ * outline rendered on top. We don't support that yet, so just ignore
+ * the 'glyf' outline and advertise it as a bitmap-only font. */
+ if ( is_apple_sbix )
+ has_outline = FALSE;
+
/* if this font doesn't contain outlines, we try to load */
/* a `bhed' table */
@@ -619,7 +1026,7 @@
/* load the font header (`head' table) if this isn't an Apple */
/* sbit font file */
- if ( !is_apple_sbit )
+ if ( !is_apple_sbit || is_apple_sbix )
{
LOAD_( head );
if ( error )
@@ -803,6 +1210,10 @@
/* */
/* Compute face flags. */
/* */
+ if ( face->sbit_table_type == TT_SBIT_TABLE_TYPE_CBLC ||
+ face->sbit_table_type == TT_SBIT_TABLE_TYPE_SBIX )
+ flags |= FT_FACE_FLAG_COLOR; /* color glyphs */
+
if ( has_outline == TRUE )
flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */
@@ -931,7 +1342,7 @@
if ( em_size == 0 || face->os2.version == 0xFFFFU )
{
- avgwidth = 0;
+ avgwidth = 1;
em_size = 1;
}
diff --git a/freetype/src/sfnt/ttcmap.c b/freetype/src/sfnt/ttcmap.c
index e5434d285..1ef6d3ceb 100644
--- a/freetype/src/sfnt/ttcmap.c
+++ b/freetype/src/sfnt/ttcmap.c
@@ -4,7 +4,7 @@
/* */
/* TrueType character mapping table (cmap) support (body). */
/* */
-/* Copyright 2002-2010, 2012, 2013 by */
+/* Copyright 2002-2010, 2012-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -88,9 +88,15 @@
tt_cmap0_validate( FT_Byte* table,
FT_Validator valid )
{
- FT_Byte* p = table + 2;
- FT_UInt length = TT_NEXT_USHORT( p );
+ FT_Byte* p;
+ FT_UInt length;
+
+ if ( table + 2 + 2 > valid->limit )
+ FT_INVALID_TOO_SHORT;
+
+ p = table + 2; /* skip format */
+ length = TT_NEXT_USHORT( p );
if ( table + length > valid->limit || length < 262 )
FT_INVALID_TOO_SHORT;
@@ -279,14 +285,21 @@
tt_cmap2_validate( FT_Byte* table,
FT_Validator valid )
{
- FT_Byte* p = table + 2; /* skip format */
- FT_UInt length = TT_PEEK_USHORT( p );
+ FT_Byte* p;
+ FT_UInt length;
+
FT_UInt n, max_subs;
- FT_Byte* keys; /* keys table */
- FT_Byte* subs; /* sub-headers */
- FT_Byte* glyph_ids; /* glyph ID array */
+ FT_Byte* keys; /* keys table */
+ FT_Byte* subs; /* sub-headers */
+ FT_Byte* glyph_ids; /* glyph ID array */
+ if ( table + 2 + 2 > valid->limit )
+ FT_INVALID_TOO_SHORT;
+
+ p = table + 2; /* skip format */
+ length = TT_NEXT_USHORT( p );
+
if ( table + length > valid->limit || length < 6 + 512 )
FT_INVALID_TOO_SHORT;
@@ -320,9 +333,8 @@
/* parse sub-headers */
for ( n = 0; n <= max_subs; n++ )
{
- FT_UInt first_code, code_count, offset;
- FT_Int delta;
- FT_Byte* ids;
+ FT_UInt first_code, code_count, offset;
+ FT_Int delta;
first_code = TT_NEXT_USHORT( p );
@@ -344,6 +356,9 @@
/* check offset */
if ( offset != 0 )
{
+ FT_Byte* ids;
+
+
ids = p - 2 + offset;
if ( ids < glyph_ids || ids + code_count*2 > table + length )
FT_INVALID_OFFSET;
@@ -816,13 +831,20 @@
tt_cmap4_validate( FT_Byte* table,
FT_Validator valid )
{
- FT_Byte* p = table + 2; /* skip format */
- FT_UInt length = TT_NEXT_USHORT( p );
+ FT_Byte* p;
+ FT_UInt length;
+
FT_Byte *ends, *starts, *offsets, *deltas, *glyph_ids;
FT_UInt num_segs;
FT_Error error = FT_Err_Ok;
+ if ( table + 2 + 2 > valid->limit )
+ FT_INVALID_TOO_SHORT;
+
+ p = table + 2; /* skip format */
+ length = TT_NEXT_USHORT( p );
+
if ( length < 16 )
FT_INVALID_TOO_SHORT;
@@ -2042,9 +2064,9 @@
tt_cmap12_validate( FT_Byte* table,
FT_Validator valid )
{
- FT_Byte* p;
- FT_ULong length;
- FT_ULong num_groups;
+ FT_Byte* p;
+ FT_ULong length;
+ FT_ULong num_groups;
if ( table + 16 > valid->limit )
@@ -2108,8 +2130,6 @@
char_code = cmap->cur_charcode + 1;
- n = cmap->cur_group;
-
for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
{
p = cmap->cmap.data + 16 + 12 * n;
@@ -2432,8 +2452,6 @@
char_code = cmap->cur_charcode + 1;
- n = cmap->cur_group;
-
for ( n = cmap->cur_group; n < cmap->num_groups; n++ )
{
p = cmap->cmap.data + 16 + 12 * n;
@@ -2756,10 +2774,17 @@
tt_cmap14_validate( FT_Byte* table,
FT_Validator valid )
{
- FT_Byte* p = table + 2;
- FT_ULong length = TT_NEXT_ULONG( p );
- FT_ULong num_selectors = TT_NEXT_ULONG( p );
+ FT_Byte* p;
+ FT_ULong length;
+ FT_ULong num_selectors;
+
+ if ( table + 2 + 4 + 4 > valid->limit )
+ FT_INVALID_TOO_SHORT;
+
+ p = table + 2;
+ length = TT_NEXT_ULONG( p );
+ num_selectors = TT_NEXT_ULONG( p );
if ( length > (FT_ULong)( valid->limit - table ) ||
length < 10 + 11 * num_selectors )
@@ -3208,7 +3233,6 @@
{
FT_Byte *p = tt_cmap14_find_variant( cmap->data + 6,
variantSelector );
- FT_UInt32 *ret;
FT_Int i;
FT_ULong defOff;
FT_ULong nondefOff;
@@ -3242,6 +3266,8 @@
FT_Byte* dp;
FT_UInt di, ni, k;
+ FT_UInt32 *ret;
+
p = cmap->data + nondefOff;
dp = cmap->data + defOff;
diff --git a/freetype/src/sfnt/ttkern.c b/freetype/src/sfnt/ttkern.c
index b90c28e6a..ac870b424 100644
--- a/freetype/src/sfnt/ttkern.c
+++ b/freetype/src/sfnt/ttkern.c
@@ -5,7 +5,7 @@
/* Load the basic TrueType kerning table. This doesn't handle */
/* kerning data within the GPOS table at the moment. */
/* */
-/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 by */
+/* Copyright 1996-2007, 2009, 2010, 2013 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -183,7 +183,7 @@
FT_UInt right_glyph )
{
FT_Int result = 0;
- FT_UInt count, mask = 1;
+ FT_UInt count, mask;
FT_Byte* p = face->kern_table;
FT_Byte* p_limit = p + face->kern_table_size;
@@ -196,7 +196,7 @@
count--, mask <<= 1 )
{
FT_Byte* base = p;
- FT_Byte* next = base;
+ FT_Byte* next;
FT_UInt version = FT_NEXT_USHORT( p );
FT_UInt length = FT_NEXT_USHORT( p );
FT_UInt coverage = FT_NEXT_USHORT( p );
diff --git a/freetype/src/sfnt/ttload.c b/freetype/src/sfnt/ttload.c
index 9c2a35d68..f6a11c12f 100644
--- a/freetype/src/sfnt/ttload.c
+++ b/freetype/src/sfnt/ttload.c
@@ -236,7 +236,8 @@
*/
if ( table.Length < 0x36 )
{
- FT_TRACE2(( "check_table_dir: `head' table too small\n" ));
+ FT_TRACE2(( "check_table_dir:"
+ " `head' or `bhed' table too small\n" ));
error = FT_THROW( Table_Missing );
goto Exit;
}
@@ -246,12 +247,8 @@
goto Exit;
if ( magic != 0x5F0F3CF5UL )
- {
FT_TRACE2(( "check_table_dir:"
- " no magic number found in `head' table\n"));
- error = FT_THROW( Table_Missing );
- goto Exit;
- }
+ " invalid magic number in `head' or `bhed' table\n"));
if ( FT_STREAM_SEEK( offset + ( nn + 1 ) * 16 ) )
goto Exit;
@@ -394,8 +391,8 @@
{
entry->Tag = FT_GET_TAG4();
entry->CheckSum = FT_GET_ULONG();
- entry->Offset = FT_GET_LONG();
- entry->Length = FT_GET_LONG();
+ entry->Offset = FT_GET_ULONG();
+ entry->Length = FT_GET_ULONG();
/* ignore invalid tables */
if ( entry->Offset + entry->Length > stream->size )
@@ -1006,7 +1003,8 @@
FT_FRAME_END
};
- static const FT_Frame_Field os2_fields_extra[] =
+ /* `OS/2' version 1 and newer */
+ static const FT_Frame_Field os2_fields_extra1[] =
{
FT_FRAME_START( 8 ),
FT_FRAME_ULONG( ulCodePageRange1 ),
@@ -1014,6 +1012,7 @@
FT_FRAME_END
};
+ /* `OS/2' version 2 and newer */
static const FT_Frame_Field os2_fields_extra2[] =
{
FT_FRAME_START( 10 ),
@@ -1025,6 +1024,15 @@
FT_FRAME_END
};
+ /* `OS/2' version 5 and newer */
+ static const FT_Frame_Field os2_fields_extra5[] =
+ {
+ FT_FRAME_START( 4 ),
+ FT_FRAME_USHORT( usLowerOpticalPointSize ),
+ FT_FRAME_USHORT( usUpperOpticalPointSize ),
+ FT_FRAME_END
+ };
+
/* We now support old Mac fonts where the OS/2 table doesn't */
/* exist. Simply put, we set the `version' field to 0xFFFF */
@@ -1038,18 +1046,20 @@
if ( FT_STREAM_READ_FIELDS( os2_fields, os2 ) )
goto Exit;
- os2->ulCodePageRange1 = 0;
- os2->ulCodePageRange2 = 0;
- os2->sxHeight = 0;
- os2->sCapHeight = 0;
- os2->usDefaultChar = 0;
- os2->usBreakChar = 0;
- os2->usMaxContext = 0;
+ os2->ulCodePageRange1 = 0;
+ os2->ulCodePageRange2 = 0;
+ os2->sxHeight = 0;
+ os2->sCapHeight = 0;
+ os2->usDefaultChar = 0;
+ os2->usBreakChar = 0;
+ os2->usMaxContext = 0;
+ os2->usLowerOpticalPointSize = 0;
+ os2->usUpperOpticalPointSize = 0xFFFF;
if ( os2->version >= 0x0001 )
{
/* only version 1 tables */
- if ( FT_STREAM_READ_FIELDS( os2_fields_extra, os2 ) )
+ if ( FT_STREAM_READ_FIELDS( os2_fields_extra1, os2 ) )
goto Exit;
if ( os2->version >= 0x0002 )
@@ -1057,6 +1067,13 @@
/* only version 2 tables */
if ( FT_STREAM_READ_FIELDS( os2_fields_extra2, os2 ) )
goto Exit;
+
+ if ( os2->version >= 0x0005 )
+ {
+ /* only version 5 tables */
+ if ( FT_STREAM_READ_FIELDS( os2_fields_extra5, os2 ) )
+ goto Exit;
+ }
}
}
@@ -1164,6 +1181,7 @@
FT_FRAME_USHORT( Style ),
FT_FRAME_USHORT( TypeFamily ),
FT_FRAME_USHORT( CapHeight ),
+ FT_FRAME_USHORT( SymbolSet ),
FT_FRAME_BYTES ( TypeFace, 16 ),
FT_FRAME_BYTES ( CharacterComplement, 8 ),
FT_FRAME_BYTES ( FileName, 6 ),
diff --git a/freetype/src/sfnt/ttmtx.c b/freetype/src/sfnt/ttmtx.c
index 2101fb7c6..bc95bf861 100644
--- a/freetype/src/sfnt/ttmtx.c
+++ b/freetype/src/sfnt/ttmtx.c
@@ -183,20 +183,23 @@
/* tt_face_get_metrics */
/* */
/* <Description> */
- /* Returns the horizontal or vertical metrics in font units for a */
- /* given glyph. The metrics are the left side bearing (resp. top */
- /* side bearing) and advance width (resp. advance height). */
+ /* Return the horizontal or vertical metrics in font units for a */
+ /* given glyph. The values are the left side bearing (top side */
+ /* bearing for vertical metrics) and advance width (advance height */
+ /* for vertical metrics). */
/* */
/* <Input> */
- /* header :: A pointer to either the horizontal or vertical metrics */
- /* structure. */
+ /* face :: A pointer to the TrueType face structure. */
/* */
- /* idx :: The glyph index. */
+ /* vertical :: If set to TRUE, get vertical metrics. */
+ /* */
+ /* gindex :: The glyph index. */
/* */
/* <Output> */
- /* bearing :: The bearing, either left side or top side. */
+ /* abearing :: The bearing, either left side or top side. */
/* */
- /* advance :: The advance width resp. advance height. */
+ /* aadvance :: The advance width or advance height, depending on */
+ /* the `vertical' flag. */
/* */
FT_LOCAL_DEF( FT_Error )
tt_face_get_metrics( TT_Face face,
diff --git a/freetype/src/sfnt/ttsbit.c b/freetype/src/sfnt/ttsbit.c
index a5e65e2ad..cd7592dff 100644
--- a/freetype/src/sfnt/ttsbit.c
+++ b/freetype/src/sfnt/ttsbit.c
@@ -4,7 +4,7 @@
/* */
/* TrueType and OpenType embedded bitmap support (body). */
/* */
-/* Copyright 2005-2009, 2013 by */
+/* Copyright 2005-2009, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* Copyright 2013 by Google, Inc. */
@@ -28,6 +28,7 @@
#include "sferrors.h"
+#include "ttmtx.h"
#include "pngshim.h"
@@ -42,25 +43,36 @@
FT_LOCAL_DEF( FT_Error )
- tt_face_load_eblc( TT_Face face,
+ tt_face_load_sbit( TT_Face face,
FT_Stream stream )
{
- FT_Error error = FT_Err_Ok;
- FT_Fixed version;
- FT_ULong num_strikes, table_size;
- FT_Byte* p;
- FT_Byte* p_limit;
- FT_UInt count;
+ FT_Error error;
+ FT_ULong table_size;
+ face->sbit_table = NULL;
+ face->sbit_table_size = 0;
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE;
face->sbit_num_strikes = 0;
- /* this table is optional */
error = face->goto_table( face, TTAG_CBLC, stream, &table_size );
- if ( error )
+ if ( !error )
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_CBLC;
+ else
+ {
error = face->goto_table( face, TTAG_EBLC, stream, &table_size );
+ if ( error )
+ error = face->goto_table( face, TTAG_bloc, stream, &table_size );
+ if ( !error )
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_EBLC;
+ }
+
if ( error )
- error = face->goto_table( face, TTAG_bloc, stream, &table_size );
+ {
+ error = face->goto_table( face, TTAG_sbix, stream, &table_size );
+ if ( !error )
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_SBIX;
+ }
if ( error )
goto Exit;
@@ -71,53 +83,130 @@
goto Exit;
}
- if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) )
- goto Exit;
+ switch ( (FT_UInt)face->sbit_table_type )
+ {
+ case TT_SBIT_TABLE_TYPE_EBLC:
+ case TT_SBIT_TABLE_TYPE_CBLC:
+ {
+ FT_Byte* p;
+ FT_Fixed version;
+ FT_ULong num_strikes;
+ FT_UInt count;
- face->sbit_table_size = table_size;
- p = face->sbit_table;
- p_limit = p + table_size;
+ if ( FT_FRAME_EXTRACT( table_size, face->sbit_table ) )
+ goto Exit;
- version = FT_NEXT_ULONG( p );
- num_strikes = FT_NEXT_ULONG( p );
+ face->sbit_table_size = table_size;
- if ( version != 0x00020000UL || num_strikes >= 0x10000UL )
- {
- FT_ERROR(( "tt_face_load_sbit_strikes: invalid table version\n" ));
- error = FT_THROW( Invalid_File_Format );
- goto Fail;
+ p = face->sbit_table;
+
+ version = FT_NEXT_ULONG( p );
+ num_strikes = FT_NEXT_ULONG( p );
+
+ if ( ( version & 0xFFFF0000UL ) != 0x00020000UL )
+ {
+ error = FT_THROW( Unknown_File_Format );
+ goto Exit;
+ }
+
+ if ( num_strikes >= 0x10000UL )
+ {
+ error = FT_THROW( Invalid_File_Format );
+ goto Exit;
+ }
+
+ /*
+ * Count the number of strikes available in the table. We are a bit
+ * paranoid there and don't trust the data.
+ */
+ count = (FT_UInt)num_strikes;
+ if ( 8 + 48UL * count > table_size )
+ count = (FT_UInt)( ( table_size - 8 ) / 48 );
+
+ face->sbit_num_strikes = count;
+ }
+ break;
+
+ case TT_SBIT_TABLE_TYPE_SBIX:
+ {
+ FT_UShort version;
+ FT_UShort flags;
+ FT_ULong num_strikes;
+ FT_UInt count;
+
+
+ if ( FT_FRAME_ENTER( 8 ) )
+ goto Exit;
+
+ version = FT_GET_USHORT();
+ flags = FT_GET_USHORT();
+ num_strikes = FT_GET_ULONG();
+
+ FT_FRAME_EXIT();
+
+ if ( version < 1 )
+ {
+ error = FT_THROW( Unknown_File_Format );
+ goto Exit;
+ }
+ if ( flags != 0x0001 || num_strikes >= 0x10000UL )
+ {
+ error = FT_THROW( Invalid_File_Format );
+ goto Exit;
+ }
+
+ /*
+ * Count the number of strikes available in the table. We are a bit
+ * paranoid there and don't trust the data.
+ */
+ count = (FT_UInt)num_strikes;
+ if ( 8 + 4UL * count > table_size )
+ count = (FT_UInt)( ( table_size - 8 ) / 4 );
+
+ if ( FT_STREAM_SEEK( FT_STREAM_POS() - 8 ) )
+ goto Exit;
+
+ face->sbit_table_size = 8 + count * 4;
+ if ( FT_FRAME_EXTRACT( face->sbit_table_size, face->sbit_table ) )
+ goto Exit;
+
+ face->sbit_num_strikes = count;
+ }
+ break;
+
+ default:
+ error = FT_THROW( Unknown_File_Format );
+ break;
}
- /*
- * Count the number of strikes available in the table. We are a bit
- * paranoid there and don't trust the data.
- */
- count = (FT_UInt)num_strikes;
- if ( 8 + 48UL * count > table_size )
- count = (FT_UInt)( ( p_limit - p ) / 48 );
+ if ( !error )
+ FT_TRACE3(( "sbit_num_strikes: %u\n", face->sbit_num_strikes ));
- face->sbit_num_strikes = count;
+ return FT_Err_Ok;
- FT_TRACE3(( "sbit_num_strikes: %u\n", count ));
Exit:
- return error;
+ if ( error )
+ {
+ if ( face->sbit_table )
+ FT_FRAME_RELEASE( face->sbit_table );
+ face->sbit_table_size = 0;
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE;
+ }
- Fail:
- FT_FRAME_RELEASE( face->sbit_table );
- face->sbit_table_size = 0;
- goto Exit;
+ return error;
}
FT_LOCAL_DEF( void )
- tt_face_free_eblc( TT_Face face )
+ tt_face_free_sbit( TT_Face face )
{
FT_Stream stream = face->root.stream;
FT_FRAME_RELEASE( face->sbit_table );
face->sbit_table_size = 0;
+ face->sbit_table_type = TT_SBIT_TABLE_TYPE_NONE;
face->sbit_num_strikes = 0;
}
@@ -136,28 +225,85 @@
FT_ULong strike_index,
FT_Size_Metrics* metrics )
{
- FT_Byte* strike;
-
-
if ( strike_index >= (FT_ULong)face->sbit_num_strikes )
return FT_THROW( Invalid_Argument );
- strike = face->sbit_table + 8 + strike_index * 48;
+ switch ( (FT_UInt)face->sbit_table_type )
+ {
+ case TT_SBIT_TABLE_TYPE_EBLC:
+ case TT_SBIT_TABLE_TYPE_CBLC:
+ {
+ FT_Byte* strike;
- metrics->x_ppem = (FT_UShort)strike[44];
- metrics->y_ppem = (FT_UShort)strike[45];
- metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */
- metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */
- metrics->height = metrics->ascender - metrics->descender;
+ strike = face->sbit_table + 8 + strike_index * 48;
- /* XXX: Is this correct? */
- metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */
- strike[18] + /* max_width */
- (FT_Char)strike[23] /* min_advance_SB */
- ) << 6;
+ metrics->x_ppem = (FT_UShort)strike[44];
+ metrics->y_ppem = (FT_UShort)strike[45];
- return FT_Err_Ok;
+ metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */
+ metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */
+ metrics->height = metrics->ascender - metrics->descender;
+
+ /* Is this correct? */
+ metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */
+ strike[18] + /* max_width */
+ (FT_Char)strike[23] /* min_advance_SB */
+ ) << 6;
+ return FT_Err_Ok;
+ }
+
+ case TT_SBIT_TABLE_TYPE_SBIX:
+ {
+ FT_Stream stream = face->root.stream;
+ FT_UInt offset, ppem, resolution, upem;
+ TT_HoriHeader *hori;
+ FT_ULong table_size;
+
+ FT_Error error;
+ FT_Byte* p;
+
+
+ p = face->sbit_table + 8 + 4 * strike_index;
+ offset = FT_NEXT_ULONG( p );
+
+ error = face->goto_table( face, TTAG_sbix, stream, &table_size );
+ if ( error )
+ return error;
+
+ if ( offset + 4 > table_size )
+ return FT_THROW( Invalid_File_Format );
+
+ if ( FT_STREAM_SEEK( FT_STREAM_POS() + offset ) ||
+ FT_FRAME_ENTER( 4 ) )
+ return error;
+
+ ppem = FT_GET_USHORT();
+ resolution = FT_GET_USHORT();
+
+ FT_UNUSED( resolution ); /* What to do with this? */
+
+ FT_FRAME_EXIT();
+
+ upem = face->header.Units_Per_EM;
+ hori = &face->horizontal;
+
+ metrics->x_ppem = ppem;
+ metrics->y_ppem = ppem;
+
+ metrics->ascender = ppem * hori->Ascender * 64 / upem;
+ metrics->descender = ppem * hori->Descender * 64 / upem;
+ metrics->height = ppem * ( hori->Ascender -
+ hori->Descender +
+ hori->Line_Gap ) * 64 / upem;
+ metrics->max_advance = ppem * hori->advance_Width_Max * 64 / upem;
+
+ return error;
+ }
+
+ default:
+ return FT_THROW( Unknown_File_Format );
+ }
}
@@ -253,8 +399,7 @@
static FT_Error
- tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder,
- FT_UInt load_flags )
+ tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder )
{
FT_Error error = FT_Err_Ok;
FT_UInt width, height;
@@ -301,18 +446,9 @@
break;
case 32:
- if ( load_flags & FT_LOAD_COLOR )
- {
- map->pixel_mode = FT_PIXEL_MODE_BGRA;
- map->pitch = map->width * 4;
- map->num_grays = 256;
- }
- else
- {
- map->pixel_mode = FT_PIXEL_MODE_GRAY;
- map->pitch = map->width;
- map->num_grays = 256;
- }
+ map->pixel_mode = FT_PIXEL_MODE_BGRA;
+ map->pitch = map->width * 4;
+ map->num_grays = 256;
break;
default:
@@ -382,13 +518,11 @@
/* forward declaration */
static FT_Error
tt_sbit_decoder_load_image( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_UInt glyph_index,
FT_Int x_pos,
FT_Int y_pos );
typedef FT_Error (*TT_SBitDecoder_LoadFunc)( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_Byte* p,
FT_Byte* plimit,
FT_Int x_pos,
@@ -397,7 +531,6 @@
static FT_Error
tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_Byte* p,
FT_Byte* limit,
FT_Int x_pos,
@@ -408,8 +541,6 @@
FT_Int bit_height, bit_width, pitch, width, height, line_bits, h;
FT_Bitmap* bitmap;
- FT_UNUSED( load_flags );
-
/* check that we can write the glyph into the bitmap */
bitmap = decoder->bitmap;
@@ -538,7 +669,6 @@
static FT_Error
tt_sbit_decoder_load_bit_aligned( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_Byte* p,
FT_Byte* limit,
FT_Int x_pos,
@@ -550,8 +680,6 @@
FT_Bitmap* bitmap;
FT_UShort rval;
- FT_UNUSED( load_flags );
-
/* check that we can write the glyph into the bitmap */
bitmap = decoder->bitmap;
@@ -664,7 +792,6 @@
static FT_Error
tt_sbit_decoder_load_compound( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_Byte* p,
FT_Byte* limit,
FT_Int x_pos,
@@ -702,7 +829,7 @@
/* NB: a recursive call */
- error = tt_sbit_decoder_load_image( decoder, load_flags, gindex,
+ error = tt_sbit_decoder_load_image( decoder, gindex,
x_pos + dx, y_pos + dy );
if ( error )
break;
@@ -732,7 +859,6 @@
static FT_Error
tt_sbit_decoder_load_png( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_Byte* p,
FT_Byte* limit,
FT_Int x_pos,
@@ -741,8 +867,6 @@
FT_Error error = FT_Err_Ok;
FT_ULong png_len;
- FT_UNUSED( load_flags );
-
if ( limit - p < 4 )
{
@@ -759,14 +883,15 @@
goto Exit;
}
- error = Load_SBit_Png( decoder->bitmap,
+ error = Load_SBit_Png( decoder->face->root.glyph,
x_pos,
y_pos,
decoder->bit_depth,
decoder->metrics,
decoder->stream->memory,
p,
- png_len );
+ png_len,
+ FALSE );
Exit:
if ( !error )
@@ -779,7 +904,6 @@
static FT_Error
tt_sbit_decoder_load_bitmap( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_UInt glyph_format,
FT_ULong glyph_start,
FT_ULong glyph_size,
@@ -843,8 +967,36 @@
break;
case 2:
- case 5:
case 7:
+ {
+ /* Don't trust `glyph_format'. For example, Apple's main Korean */
+ /* system font, `AppleMyungJo.ttf' (version 7.0d2e6), uses glyph */
+ /* format 7, but the data is format 6. We check whether we have */
+ /* an excessive number of bytes in the image: If it is equal to */
+ /* the value for a byte-aligned glyph, use the other loading */
+ /* routine. */
+ /* */
+ /* Note that for some (width,height) combinations, where the */
+ /* width is not a multiple of 8, the sizes for bit- and */
+ /* byte-aligned data are equal, for example (7,7) or (15,6). We */
+ /* then prefer what `glyph_format' specifies. */
+
+ FT_UInt width = decoder->metrics->width;
+ FT_UInt height = decoder->metrics->height;
+
+ FT_UInt bit_size = ( width * height + 7 ) >> 3;
+ FT_UInt byte_size = height * ( ( width + 7 ) >> 3 );
+
+
+ if ( bit_size < byte_size &&
+ byte_size == (FT_UInt)( p_limit - p ) )
+ loader = tt_sbit_decoder_load_byte_aligned;
+ else
+ loader = tt_sbit_decoder_load_bit_aligned;
+ }
+ break;
+
+ case 5:
loader = tt_sbit_decoder_load_bit_aligned;
break;
@@ -859,12 +1011,15 @@
loader = tt_sbit_decoder_load_compound;
break;
-#ifdef FT_CONFIG_OPTION_USE_PNG
case 17: /* small metrics, PNG image data */
case 18: /* big metrics, PNG image data */
case 19: /* metrics in EBLC, PNG image data */
+#ifdef FT_CONFIG_OPTION_USE_PNG
loader = tt_sbit_decoder_load_png;
break;
+#else
+ error = FT_THROW( Unimplemented_Feature );
+ goto Fail;
#endif /* FT_CONFIG_OPTION_USE_PNG */
default:
@@ -874,64 +1029,12 @@
if ( !decoder->bitmap_allocated )
{
- error = tt_sbit_decoder_alloc_bitmap( decoder, load_flags );
+ error = tt_sbit_decoder_alloc_bitmap( decoder );
if ( error )
goto Fail;
}
- if ( decoder->bit_depth == 32 &&
- decoder->bitmap->pixel_mode != FT_PIXEL_MODE_BGRA )
- {
- /* Flatten color bitmaps if color was not requested. */
-
- FT_Library library = decoder->face->root.glyph->library;
- FT_Memory memory = decoder->stream->memory;
-
- FT_Bitmap color, *orig;
-
-
- if ( decoder->bitmap->pixel_mode != FT_PIXEL_MODE_GRAY ||
- x_pos != 0 || y_pos != 0 )
- {
- /* Shouldn't happen. */
- error = FT_THROW( Invalid_Table );
- goto Fail;
- }
-
- FT_Bitmap_New( &color );
-
- color.rows = decoder->bitmap->rows;
- color.width = decoder->bitmap->width;
- color.pitch = color.width * 4;
- color.pixel_mode = FT_PIXEL_MODE_BGRA;
-
- if ( FT_ALLOC( color.buffer, color.rows * color.pitch ) )
- goto Fail;
-
- orig = decoder->bitmap;
- decoder->bitmap = &color;
-
- error = loader( decoder, load_flags, p, p_limit, x_pos, y_pos );
-
- decoder->bitmap = orig;
-
- /* explicitly test against FT_Err_Ok to avoid compiler warnings */
- /* (we do an assignment within a conditional) */
- if ( error ||
- ( error = FT_Bitmap_Convert( library,
- &color,
- decoder->bitmap,
- 1 ) ) != FT_Err_Ok )
- {
- FT_Bitmap_Done( library, &color );
- goto Fail;
- }
-
- FT_Bitmap_Done( library, &color );
- }
-
- else
- error = loader( decoder, load_flags, p, p_limit, x_pos, y_pos );
+ error = loader( decoder, p, p_limit, x_pos, y_pos );
}
Fail:
@@ -944,7 +1047,6 @@
static FT_Error
tt_sbit_decoder_load_image( TT_SBitDecoder decoder,
- FT_UInt load_flags,
FT_UInt glyph_index,
FT_Int x_pos,
FT_Int y_pos )
@@ -993,17 +1095,15 @@
switch ( index_format )
{
case 1: /* 4-byte offsets relative to `image_offset' */
- {
- p += 4 * ( glyph_index - start );
- if ( p + 8 > p_limit )
- goto NoBitmap;
+ p += 4 * ( glyph_index - start );
+ if ( p + 8 > p_limit )
+ goto NoBitmap;
- image_start = FT_NEXT_ULONG( p );
- image_end = FT_NEXT_ULONG( p );
+ image_start = FT_NEXT_ULONG( p );
+ image_end = FT_NEXT_ULONG( p );
- if ( image_start == image_end ) /* missing glyph */
- goto NoBitmap;
- }
+ if ( image_start == image_end ) /* missing glyph */
+ goto NoBitmap;
break;
case 2: /* big metrics, constant image size */
@@ -1025,17 +1125,15 @@
break;
case 3: /* 2-byte offsets relative to 'image_offset' */
- {
- p += 2 * ( glyph_index - start );
- if ( p + 4 > p_limit )
- goto NoBitmap;
+ p += 2 * ( glyph_index - start );
+ if ( p + 4 > p_limit )
+ goto NoBitmap;
- image_start = FT_NEXT_USHORT( p );
- image_end = FT_NEXT_USHORT( p );
+ image_start = FT_NEXT_USHORT( p );
+ image_end = FT_NEXT_USHORT( p );
- if ( image_start == image_end ) /* missing glyph */
- goto NoBitmap;
- }
+ if ( image_start == image_end ) /* missing glyph */
+ goto NoBitmap;
break;
case 4: /* sparse glyph array with (glyph,offset) pairs */
@@ -1124,7 +1222,6 @@
image_format, glyph_index ));
return tt_sbit_decoder_load_bitmap( decoder,
- load_flags,
image_format,
image_start,
image_end,
@@ -1142,6 +1239,128 @@
}
+ static FT_Error
+ tt_face_load_sbix_image( TT_Face face,
+ FT_ULong strike_index,
+ FT_UInt glyph_index,
+ FT_Stream stream,
+ FT_Bitmap *map,
+ TT_SBit_MetricsRec *metrics )
+ {
+ FT_UInt sbix_pos, strike_offset, glyph_start, glyph_end;
+ FT_ULong table_size;
+ FT_Int originOffsetX, originOffsetY;
+ FT_Tag graphicType;
+ FT_Int recurse_depth = 0;
+
+ FT_Error error;
+ FT_Byte* p;
+
+ FT_UNUSED( map );
+
+
+ metrics->width = 0;
+ metrics->height = 0;
+
+ p = face->sbit_table + 8 + 4 * strike_index;
+ strike_offset = FT_NEXT_ULONG( p );
+
+ error = face->goto_table( face, TTAG_sbix, stream, &table_size );
+ if ( error )
+ return error;
+ sbix_pos = FT_STREAM_POS();
+
+ retry:
+ if ( glyph_index > (FT_UInt)face->root.num_glyphs )
+ return FT_THROW( Invalid_Argument );
+
+ if ( strike_offset >= table_size ||
+ table_size - strike_offset < 4 + glyph_index * 4 + 8 )
+ return FT_THROW( Invalid_File_Format );
+
+ if ( FT_STREAM_SEEK( sbix_pos + strike_offset + 4 + glyph_index * 4 ) ||
+ FT_FRAME_ENTER( 8 ) )
+ return error;
+
+ glyph_start = FT_GET_ULONG();
+ glyph_end = FT_GET_ULONG();
+
+ FT_FRAME_EXIT();
+
+ if ( glyph_start == glyph_end )
+ return FT_THROW( Invalid_Argument );
+ if ( glyph_start > glyph_end ||
+ glyph_end - glyph_start < 8 ||
+ table_size - strike_offset < glyph_end )
+ return FT_THROW( Invalid_File_Format );
+
+ if ( FT_STREAM_SEEK( sbix_pos + strike_offset + glyph_start ) ||
+ FT_FRAME_ENTER( glyph_end - glyph_start ) )
+ return error;
+
+ originOffsetX = FT_GET_SHORT();
+ originOffsetY = FT_GET_SHORT();
+
+ graphicType = FT_GET_TAG4();
+
+ switch ( graphicType )
+ {
+ case FT_MAKE_TAG( 'd', 'u', 'p', 'e' ):
+ if ( recurse_depth < 4 )
+ {
+ glyph_index = FT_GET_USHORT();
+ FT_FRAME_EXIT();
+ recurse_depth++;
+ goto retry;
+ }
+ error = FT_THROW( Invalid_File_Format );
+ break;
+
+ case FT_MAKE_TAG( 'p', 'n', 'g', ' ' ):
+#ifdef FT_CONFIG_OPTION_USE_PNG
+ error = Load_SBit_Png( face->root.glyph,
+ 0,
+ 0,
+ 32,
+ metrics,
+ stream->memory,
+ stream->cursor,
+ glyph_end - glyph_start - 8,
+ TRUE );
+#else
+ error = FT_THROW( Unimplemented_Feature );
+#endif
+ break;
+
+ case FT_MAKE_TAG( 'j', 'p', 'g', ' ' ):
+ case FT_MAKE_TAG( 't', 'i', 'f', 'f' ):
+ error = FT_THROW( Unknown_File_Format );
+ break;
+
+ default:
+ error = FT_THROW( Unimplemented_Feature );
+ break;
+ }
+
+ FT_FRAME_EXIT();
+
+ if ( !error )
+ {
+ FT_Short abearing;
+ FT_UShort aadvance;
+
+
+ tt_face_get_metrics( face, FALSE, glyph_index, &abearing, &aadvance );
+
+ metrics->horiBearingX = originOffsetX;
+ metrics->horiBearingY = -originOffsetY + metrics->height;
+ metrics->horiAdvance = aadvance * face->root.size->metrics.x_ppem /
+ face->header.Units_Per_EM;
+ }
+
+ return error;
+ }
+
FT_LOCAL( FT_Error )
tt_face_load_sbit_image( TT_Face face,
FT_ULong strike_index,
@@ -1151,23 +1370,67 @@
FT_Bitmap *map,
TT_SBit_MetricsRec *metrics )
{
- TT_SBitDecoderRec decoder[1];
- FT_Error error;
+ FT_Error error = FT_Err_Ok;
- FT_UNUSED( load_flags );
- FT_UNUSED( stream );
- FT_UNUSED( map );
+ switch ( (FT_UInt)face->sbit_table_type )
+ {
+ case TT_SBIT_TABLE_TYPE_EBLC:
+ case TT_SBIT_TABLE_TYPE_CBLC:
+ {
+ TT_SBitDecoderRec decoder[1];
- error = tt_sbit_decoder_init( decoder, face, strike_index, metrics );
- if ( !error )
+
+ error = tt_sbit_decoder_init( decoder, face, strike_index, metrics );
+ if ( !error )
+ {
+ error = tt_sbit_decoder_load_image( decoder,
+ glyph_index,
+ 0,
+ 0 );
+ tt_sbit_decoder_done( decoder );
+ }
+ }
+ break;
+
+ case TT_SBIT_TABLE_TYPE_SBIX:
+ error = tt_face_load_sbix_image( face,
+ strike_index,
+ glyph_index,
+ stream,
+ map,
+ metrics );
+ break;
+
+ default:
+ error = FT_THROW( Unknown_File_Format );
+ break;
+ }
+
+ /* Flatten color bitmaps if color was not requested. */
+ if ( !error &&
+ !( load_flags & FT_LOAD_COLOR ) &&
+ map->pixel_mode == FT_PIXEL_MODE_BGRA )
{
- error = tt_sbit_decoder_load_image( decoder,
- load_flags,
- glyph_index,
- 0,
- 0 );
- tt_sbit_decoder_done( decoder );
+ FT_Bitmap new_map;
+ FT_Library library = face->root.glyph->library;
+
+
+ FT_Bitmap_New( &new_map );
+
+ /* Convert to 8bit grayscale. */
+ error = FT_Bitmap_Convert( library, map, &new_map, 1 );
+ if ( error )
+ FT_Bitmap_Done( library, &new_map );
+ else
+ {
+ map->pixel_mode = new_map.pixel_mode;
+ map->pitch = new_map.pitch;
+ map->num_grays = new_map.num_grays;
+
+ ft_glyphslot_set_bitmap( face->root.glyph, new_map.buffer );
+ face->root.glyph->internal->flags |= FT_GLYPH_OWN_BITMAP;
+ }
}
return error;
diff --git a/freetype/src/sfnt/ttsbit.h b/freetype/src/sfnt/ttsbit.h
index ea0b5f8ad..695d0d8d0 100644
--- a/freetype/src/sfnt/ttsbit.h
+++ b/freetype/src/sfnt/ttsbit.h
@@ -28,11 +28,11 @@ FT_BEGIN_HEADER
FT_LOCAL( FT_Error )
- tt_face_load_eblc( TT_Face face,
+ tt_face_load_sbit( TT_Face face,
FT_Stream stream );
FT_LOCAL( void )
- tt_face_free_eblc( TT_Face face );
+ tt_face_free_sbit( TT_Face face );
FT_LOCAL( FT_Error )
diff --git a/freetype/src/smooth/ftgrays.c b/freetype/src/smooth/ftgrays.c
index b0ede7630..1c4e06288 100644
--- a/freetype/src/smooth/ftgrays.c
+++ b/freetype/src/smooth/ftgrays.c
@@ -4,7 +4,7 @@
/* */
/* A new `perfect' anti-aliasing renderer (body). */
/* */
-/* Copyright 2000-2003, 2005-2013 by */
+/* Copyright 2000-2003, 2005-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -24,8 +24,8 @@
/* */
/* - copy `src/smooth/ftgrays.c' (this file) to your current directory */
/* */
- /* - copy `include/freetype/ftimage.h' and `src/smooth/ftgrays.h' to the */
- /* same directory */
+ /* - copy `include/ftimage.h' and `src/smooth/ftgrays.h' to the same */
+ /* directory */
/* */
/* - compile `ftgrays' with the _STANDALONE_ macro defined, as in */
/* */
@@ -310,6 +310,40 @@ typedef ptrdiff_t FT_PtrDist;
#endif
+ /* Compute `dividend / divisor' and return both its quotient and */
+ /* remainder, cast to a specific type. This macro also ensures that */
+ /* the remainder is always positive. */
+#define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \
+ FT_BEGIN_STMNT \
+ (quotient) = (type)( (dividend) / (divisor) ); \
+ (remainder) = (type)( (dividend) % (divisor) ); \
+ if ( (remainder) < 0 ) \
+ { \
+ (quotient)--; \
+ (remainder) += (type)(divisor); \
+ } \
+ FT_END_STMNT
+
+#ifdef __arm__
+ /* Work around a bug specific to GCC which make the compiler fail to */
+ /* optimize a division and modulo operation on the same parameters */
+ /* into a single call to `__aeabi_idivmod'. See */
+ /* */
+ /* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 */
+#undef FT_DIV_MOD
+#define FT_DIV_MOD( type, dividend, divisor, quotient, remainder ) \
+ FT_BEGIN_STMNT \
+ (quotient) = (type)( (dividend) / (divisor) ); \
+ (remainder) = (type)( (dividend) - (quotient) * (divisor) ); \
+ if ( (remainder) < 0 ) \
+ { \
+ (quotient)--; \
+ (remainder) += (type)(divisor); \
+ } \
+ FT_END_STMNT
+#endif /* __arm__ */
+
+
/*************************************************************************/
/* */
/* TYPE DEFINITIONS */
@@ -548,7 +582,7 @@ typedef ptrdiff_t FT_PtrDist;
static void
gray_record_cell( RAS_ARG )
{
- if ( !ras.invalid && ( ras.area | ras.cover ) )
+ if ( ras.area | ras.cover )
{
PCell cell = gray_find_cell( RAS_VAR );
@@ -597,10 +631,10 @@ typedef ptrdiff_t FT_PtrDist;
ras.area = 0;
ras.cover = 0;
+ ras.ex = ex;
+ ras.ey = ey;
}
- ras.ex = ex;
- ras.ey = ey;
ras.invalid = ( (unsigned)ey >= (unsigned)ras.count_ey ||
ex >= ras.count_ex );
}
@@ -686,13 +720,7 @@ typedef ptrdiff_t FT_PtrDist;
dx = -dx;
}
- delta = (TCoord)( p / dx );
- mod = (TCoord)( p % dx );
- if ( mod < 0 )
- {
- delta--;
- mod += (TCoord)dx;
- }
+ FT_DIV_MOD( TCoord, p, dx, delta, mod );
ras.area += (TArea)(( fx1 + first ) * delta);
ras.cover += delta;
@@ -706,14 +734,8 @@ typedef ptrdiff_t FT_PtrDist;
TCoord lift, rem;
- p = ONE_PIXEL * ( y2 - y1 + delta );
- lift = (TCoord)( p / dx );
- rem = (TCoord)( p % dx );
- if ( rem < 0 )
- {
- lift--;
- rem += (TCoord)dx;
- }
+ p = ONE_PIXEL * ( y2 - y1 + delta );
+ FT_DIV_MOD( TCoord, p, dx, lift, rem );
mod -= (int)dx;
@@ -763,9 +785,6 @@ typedef ptrdiff_t FT_PtrDist;
dx = to_x - ras.x;
dy = to_y - ras.y;
- /* XXX: we should do something about the trivial case where dx == 0, */
- /* as it happens very often! */
-
/* perform vertical clipping */
{
TCoord min, max;
@@ -844,13 +863,7 @@ typedef ptrdiff_t FT_PtrDist;
dy = -dy;
}
- delta = (int)( p / dy );
- mod = (int)( p % dy );
- if ( mod < 0 )
- {
- delta--;
- mod += (TCoord)dy;
- }
+ FT_DIV_MOD( int, p, dy, delta, mod );
x = ras.x + delta;
gray_render_scanline( RAS_VAR_ ey1, ras.x, fy1, x, (TCoord)first );
@@ -861,13 +874,7 @@ typedef ptrdiff_t FT_PtrDist;
if ( ey1 != ey2 )
{
p = ONE_PIXEL * dx;
- lift = (int)( p / dy );
- rem = (int)( p % dy );
- if ( rem < 0 )
- {
- lift--;
- rem += (int)dy;
- }
+ FT_DIV_MOD( int, p, dy, lift, rem );
mod -= (int)dy;
while ( ey1 != ey2 )
@@ -1171,7 +1178,8 @@ typedef ptrdiff_t FT_PtrDist;
/* record current cell, if any */
- gray_record_cell( RAS_VAR );
+ if ( !ras.invalid )
+ gray_record_cell( RAS_VAR );
/* start to a new position */
x = UPSCALE( to->x );
@@ -1356,7 +1364,6 @@ typedef ptrdiff_t FT_PtrDist;
ras.num_gray_spans = 0;
ras.span_y = (int)y;
- count = 0;
span = ras.gray_spans;
}
else
@@ -1781,7 +1788,8 @@ typedef ptrdiff_t FT_PtrDist;
if ( ft_setjmp( ras.jump_buffer ) == 0 )
{
error = FT_Outline_Decompose( &ras.outline, &func_interface, &ras );
- gray_record_cell( RAS_VAR );
+ if ( !ras.invalid )
+ gray_record_cell( RAS_VAR );
}
else
error = FT_THROW( Memory_Overflow );
diff --git a/freetype/src/tools/afblue.pl b/freetype/src/tools/afblue.pl
new file mode 100644
index 000000000..58aa2a055
--- /dev/null
+++ b/freetype/src/tools/afblue.pl
@@ -0,0 +1,545 @@
+#! /usr/bin/perl -w
+# -*- Perl -*-
+#
+# afblue.pl
+#
+# Process a blue zone character data file.
+#
+# Copyright 2013, 2014 by
+# David Turner, Robert Wilhelm, and Werner Lemberg.
+#
+# This file is part of the FreeType project, and may only be used,
+# modified, and distributed under the terms of the FreeType project
+# license, LICENSE.TXT. By continuing to use, modify, or distribute
+# this file you indicate that you have read the license and
+# understand and accept it fully.
+
+use strict;
+use warnings;
+use English '-no_match_vars';
+use open ':std', ':encoding(UTF-8)';
+
+
+my $prog = $PROGRAM_NAME;
+$prog =~ s| .* / ||x; # Remove path.
+
+die "usage: $prog datafile < infile > outfile\n" if $#ARGV != 0;
+
+
+my $datafile = $ARGV[0];
+
+my %diversions; # The extracted and massaged data from `datafile'.
+my @else_stack; # Booleans to track else-clauses.
+my @name_stack; # Stack of integers used for names of aux. variables.
+
+my $curr_enum; # Name of the current enumeration.
+my $curr_array; # Name of the current array.
+my $curr_max; # Name of the current maximum value.
+
+my $curr_enum_element; # Name of the current enumeration element.
+my $curr_offset; # The offset relative to current aux. variable.
+my $curr_elem_size; # The size of the current string or block.
+
+my $have_sections = 0; # Boolean; set if start of a section has been seen.
+my $have_strings; # Boolean; set if current section contains strings.
+my $have_blocks; # Boolean; set if current section contains blocks.
+
+my $have_enum_element; # Boolean; set if we have an enumeration element.
+my $in_string; # Boolean; set if a string has been parsed.
+
+my $num_sections = 0; # Number of sections seen so far.
+
+my $last_aux; # Name of last auxiliary variable.
+
+
+# Regular expressions.
+
+# [<ws>] <enum_name> <ws> <array_name> <ws> <max_name> [<ws>] ':' [<ws>] '\n'
+my $section_re = qr/ ^ \s* (\S+) \s+ (\S+) \s+ (\S+) \s* : \s* $ /x;
+
+# [<ws>] <enum_element_name> [<ws>] '\n'
+my $enum_element_re = qr/ ^ \s* ( [A-Za-z0-9_]+ ) \s* $ /x;
+
+# '#' <preprocessor directive> '\n'
+my $preprocessor_re = qr/ ^ \# /x;
+
+# '/' '/' <comment> '\n'
+my $comment_re = qr| ^ // |x;
+
+# empty line
+my $whitespace_only_re = qr/ ^ \s* $ /x;
+
+# [<ws>] '"' <string> '"' [<ws>] '\n' (<string> doesn't contain newlines)
+my $string_re = qr/ ^ \s*
+ " ( (?> (?: (?> [^"\\]+ ) | \\. )* ) ) "
+ \s* $ /x;
+
+# [<ws>] '{' <block> '}' [<ws>] '\n' (<block> can contain newlines)
+my $block_start_re = qr/ ^ \s* \{ /x;
+
+# We need the capturing group for `split' to make it return the separator
+# tokens (i.e., the opening and closing brace) also.
+my $brace_re = qr/ ( [{}] ) /x;
+
+
+sub Warn
+{
+ my $message = shift;
+ warn "$datafile:$INPUT_LINE_NUMBER: warning: $message\n";
+}
+
+
+sub Die
+{
+ my $message = shift;
+ die "$datafile:$INPUT_LINE_NUMBER: error: $message\n";
+}
+
+
+my $warned_before = 0;
+
+sub warn_before
+{
+ Warn("data before first section gets ignored") unless $warned_before;
+ $warned_before = 1;
+}
+
+
+sub strip_newline
+{
+ chomp;
+ s/ \x0D $ //x;
+}
+
+
+sub end_curr_string
+{
+ # Append final null byte to string.
+ if ($have_strings)
+ {
+ push @{$diversions{$curr_array}}, " '\\0',\n" if $in_string;
+
+ $curr_offset++;
+ $in_string = 0;
+ }
+}
+
+
+sub update_max_elem_size
+{
+ if ($curr_elem_size)
+ {
+ my $max = pop @{$diversions{$curr_max}};
+ $max = $curr_elem_size if $curr_elem_size > $max;
+ push @{$diversions{$curr_max}}, $max;
+ }
+}
+
+
+sub convert_non_ascii_char
+{
+ # A UTF-8 character outside of the printable ASCII range, with possibly a
+ # leading backslash character.
+ my $s = shift;
+
+ # Here we count characters, not bytes.
+ $curr_elem_size += length $s;
+
+ utf8::encode($s);
+ $s = uc unpack 'H*', $s;
+
+ $curr_offset += $s =~ s/\G(..)/'\\x$1', /sg;
+
+ return $s;
+}
+
+
+sub convert_ascii_chars
+{
+ # A series of ASCII characters in the printable range.
+ my $s = shift;
+
+ my $count = $s =~ s/\G(.)/'$1', /g;
+ $curr_offset += $count;
+ $curr_elem_size += $count;
+
+ return $s;
+}
+
+
+sub convert_literal
+{
+ my $s = shift;
+ my $orig = $s;
+
+ # ASCII printables and space
+ my $safe_re = '\x20-\x7E';
+ # ASCII printables and space, no backslash
+ my $safe_no_backslash_re = '\x20-\x5B\x5D-\x7E';
+
+ $s =~ s{
+ (?: \\? ( [^$safe_re] )
+ | ( (?: [$safe_no_backslash_re]
+ | \\ [$safe_re] )+ ) )
+ }
+ {
+ defined($1) ? convert_non_ascii_char($1)
+ : convert_ascii_chars($2)
+ }egx;
+
+ # We assume that `$orig' doesn't contain `*/'
+ return $s . " /* $orig */";
+}
+
+
+sub aux_name
+{
+ return "af_blue_" . $num_sections. "_" . join('_', @name_stack);
+}
+
+
+sub aux_name_next
+{
+ $name_stack[$#name_stack]++;
+ my $name = aux_name();
+ $name_stack[$#name_stack]--;
+
+ return $name;
+}
+
+
+sub enum_val_string
+{
+ # Build string that holds code to save the current offset in an
+ # enumeration element.
+ my $aux = shift;
+
+ my $add = ($last_aux eq "af_blue_" . $num_sections . "_0" )
+ ? ""
+ : "$last_aux + ";
+
+ return " $aux = $add$curr_offset,\n";
+}
+
+
+
+# Process data file.
+
+open(DATA, $datafile) || die "$prog: can't open \`$datafile': $OS_ERROR\n";
+
+while (<DATA>)
+{
+ strip_newline();
+
+ next if /$comment_re/;
+ next if /$whitespace_only_re/;
+
+ if (/$section_re/)
+ {
+ Warn("previous section is empty") if ($have_sections
+ && !$have_strings
+ && !$have_blocks);
+
+ end_curr_string();
+ update_max_elem_size();
+
+ # Save captured groups from `section_re'.
+ $curr_enum = $1;
+ $curr_array = $2;
+ $curr_max = $3;
+
+ $curr_enum_element = "";
+ $curr_offset = 0;
+
+ Warn("overwriting already defined enumeration \`$curr_enum'")
+ if exists($diversions{$curr_enum});
+ Warn("overwriting already defined array \`$curr_array'")
+ if exists($diversions{$curr_array});
+ Warn("overwriting already defined maximum value \`$curr_max'")
+ if exists($diversions{$curr_max});
+
+ $diversions{$curr_enum} = [];
+ $diversions{$curr_array} = [];
+ $diversions{$curr_max} = [];
+
+ push @{$diversions{$curr_max}}, 0;
+
+ @name_stack = ();
+ push @name_stack, 0;
+
+ $have_sections = 1;
+ $have_strings = 0;
+ $have_blocks = 0;
+
+ $have_enum_element = 0;
+ $in_string = 0;
+
+ $num_sections++;
+ $curr_elem_size = 0;
+
+ $last_aux = aux_name();
+
+ next;
+ }
+
+ if (/$preprocessor_re/)
+ {
+ if ($have_sections)
+ {
+ # Having preprocessor conditionals complicates the computation of
+ # correct offset values. We have to introduce auxiliary enumeration
+ # elements with the name `af_blue_<s>_<n1>_<n2>_...' that store
+ # offsets to be used in conditional clauses. `<s>' is the number of
+ # sections seen so far, `<n1>' is the number of `#if' and `#endif'
+ # conditionals seen so far in the topmost level, `<n2>' the number of
+ # `#if' and `#endif' conditionals seen so far one level deeper, etc.
+ # As a consequence, uneven values are used within a clause, and even
+ # values after a clause, since the C standard doesn't allow the
+ # redefinition of an enumeration value. For example, the name
+ # `af_blue_5_1_6' is used to construct enumeration values in the fifth
+ # section after the third (second-level) if-clause within the first
+ # (top-level) if-clause. After the first top-level clause has
+ # finished, `af_blue_5_2' is used. The current offset is then
+ # relative to the value stored in the current auxiliary element.
+
+ if (/ ^ \# \s* if /x)
+ {
+ push @else_stack, 0;
+
+ $name_stack[$#name_stack]++;
+
+ push @{$diversions{$curr_enum}}, enum_val_string(aux_name());
+ $last_aux = aux_name();
+
+ push @name_stack, 0;
+
+ $curr_offset = 0;
+ }
+ elsif (/ ^ \# \s* elif /x)
+ {
+ Die("unbalanced #elif") unless @else_stack;
+
+ pop @name_stack;
+
+ push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next());
+ $last_aux = aux_name();
+
+ push @name_stack, 0;
+
+ $curr_offset = 0;
+ }
+ elsif (/ ^ \# \s* else /x)
+ {
+ my $prev_else = pop @else_stack;
+ Die("unbalanced #else") unless defined($prev_else);
+ Die("#else already seen") if $prev_else;
+ push @else_stack, 1;
+
+ pop @name_stack;
+
+ push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next());
+ $last_aux = aux_name();
+
+ push @name_stack, 0;
+
+ $curr_offset = 0;
+ }
+ elsif (/ ^ (\# \s*) endif /x)
+ {
+ my $prev_else = pop @else_stack;
+ Die("unbalanced #endif") unless defined($prev_else);
+
+ pop @name_stack;
+
+ # If there is no else-clause for an if-clause, we add one. This is
+ # necessary to have correct offsets.
+ if (!$prev_else)
+ {
+ # Use amount of whitespace from `endif'.
+ push @{$diversions{$curr_enum}}, enum_val_string(aux_name_next())
+ . $1 . "else\n";
+ $last_aux = aux_name();
+
+ $curr_offset = 0;
+ }
+
+ $name_stack[$#name_stack]++;
+
+ push @{$diversions{$curr_enum}}, enum_val_string(aux_name());
+ $last_aux = aux_name();
+
+ $curr_offset = 0;
+ }
+
+ # Handle (probably continued) preprocessor lines.
+ CONTINUED_LOOP:
+ {
+ do
+ {
+ strip_newline();
+
+ push @{$diversions{$curr_enum}}, $ARG . "\n";
+ push @{$diversions{$curr_array}}, $ARG . "\n";
+
+ last CONTINUED_LOOP unless / \\ $ /x;
+
+ } while (<DATA>);
+ }
+ }
+ else
+ {
+ warn_before();
+ }
+
+ next;
+ }
+
+ if (/$enum_element_re/)
+ {
+ end_curr_string();
+ update_max_elem_size();
+
+ $curr_enum_element = $1;
+ $have_enum_element = 1;
+ $curr_elem_size = 0;
+
+ next;
+ }
+
+ if (/$string_re/)
+ {
+ if ($have_sections)
+ {
+ Die("strings and blocks can't be mixed in a section") if $have_blocks;
+
+ # Save captured group from `string_re'.
+ my $string = $1;
+
+ if ($have_enum_element)
+ {
+ push @{$diversions{$curr_enum}}, enum_val_string($curr_enum_element);
+ $have_enum_element = 0;
+ }
+
+ $string = convert_literal($string);
+
+ push @{$diversions{$curr_array}}, " $string\n";
+
+ $have_strings = 1;
+ $in_string = 1;
+ }
+ else
+ {
+ warn_before();
+ }
+
+ next;
+ }
+
+ if (/$block_start_re/)
+ {
+ if ($have_sections)
+ {
+ Die("strings and blocks can't be mixed in a section") if $have_strings;
+
+ my $depth = 0;
+ my $block = "";
+ my $block_end = 0;
+
+ # Count braces while getting the block.
+ BRACE_LOOP:
+ {
+ do
+ {
+ strip_newline();
+
+ foreach my $substring (split(/$brace_re/))
+ {
+ if ($block_end)
+ {
+ Die("invalid data after last matching closing brace")
+ if $substring !~ /$whitespace_only_re/;
+ }
+
+ $block .= $substring;
+
+ if ($substring eq '{')
+ {
+ $depth++;
+ }
+ elsif ($substring eq '}')
+ {
+ $depth--;
+
+ $block_end = 1 if $depth == 0;
+ }
+ }
+
+ # If we are here, we have run out of substrings, so get next line
+ # or exit.
+ last BRACE_LOOP if $block_end;
+
+ $block .= "\n";
+
+ } while (<DATA>);
+ }
+
+ if ($have_enum_element)
+ {
+ push @{$diversions{$curr_enum}}, enum_val_string($curr_enum_element);
+ $have_enum_element = 0;
+ }
+
+ push @{$diversions{$curr_array}}, $block . ",\n";
+
+ $curr_offset++;
+ $curr_elem_size++;
+
+ $have_blocks = 1;
+ }
+ else
+ {
+ warn_before();
+ }
+
+ next;
+ }
+
+ # Garbage. We weren't able to parse the data.
+ Die("syntax error");
+}
+
+# Finalize data.
+end_curr_string();
+update_max_elem_size();
+
+
+# Filter stdin to stdout, replacing `@...@' templates.
+
+sub emit_diversion
+{
+ my $diversion_name = shift;
+ return (exists($diversions{$1})) ? "@{$diversions{$1}}"
+ : "@" . $diversion_name . "@";
+}
+
+
+$LIST_SEPARATOR = '';
+
+my $s1 = "This file has been generated by the Perl script \`$prog',";
+my $s1len = length $s1;
+my $s2 = "using data from file \`$datafile'.";
+my $s2len = length $s2;
+my $slen = ($s1len > $s2len) ? $s1len : $s2len;
+
+print "/* " . $s1 . " " x ($slen - $s1len) . " */\n"
+ . "/* " . $s2 . " " x ($slen - $s2len) . " */\n"
+ . "\n";
+
+while (<STDIN>)
+{
+ s/ @ ( [A-Za-z0-9_]+? ) @ / emit_diversion($1) /egx;
+ print;
+}
+
+# EOF
diff --git a/freetype/src/tools/chktrcmp.py b/freetype/src/tools/chktrcmp.py
index d0f342e6b..ce6500c7e 100644
--- a/freetype/src/tools/chktrcmp.py
+++ b/freetype/src/tools/chktrcmp.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
# Check trace components in FreeType 2 source.
-# Author: suzuki toshiya, 2009
+# Author: suzuki toshiya, 2009, 2013
#
# This code is explicitly into the public domain.
@@ -15,7 +15,7 @@ USED_COMPONENT = {}
KNOWN_COMPONENT = {}
SRC_FILE_DIRS = [ "src" ]
-TRACE_DEF_FILES = [ "include/freetype/internal/fttrace.h" ]
+TRACE_DEF_FILES = [ "include/internal/fttrace.h" ]
# --------------------------------------------------------------
diff --git a/freetype/src/tools/docmaker/content.py b/freetype/src/tools/docmaker/content.py
index 26087f7b8..98025e67e 100644
--- a/freetype/src/tools/docmaker/content.py
+++ b/freetype/src/tools/docmaker/content.py
@@ -1,4 +1,4 @@
-# Content (c) 2002, 2004, 2006-2009, 2012
+# Content (c) 2002, 2004, 2006-2009, 2012, 2013
# David Turner <david@freetype.org>
#
# This file contains routines used to parse the content of documentation
@@ -268,15 +268,6 @@ class DocMarkup:
except:
return None
- def get_start( self ):
- try:
- result = ""
- for word in self.fields[0].items[0].words:
- result = result + " " + word
- return result[1:]
- except:
- return "ERROR"
-
def dump( self, margin ):
print " " * margin + "<" + self.tag + ">"
for f in self.fields:
@@ -555,14 +546,6 @@ class DocBlock:
return m
return None
- def get_markup_name( self, tag_name ):
- """return the name of a given primary markup in a block"""
- try:
- m = self.get_markup( tag_name )
- return m.get_name()
- except:
- return None
-
def get_markup_words( self, tag_name ):
try:
m = self.get_markup( tag_name )
diff --git a/freetype/src/tools/docmaker/docmaker.py b/freetype/src/tools/docmaker/docmaker.py
index 1d9de9fbf..bf75c5d5f 100644
--- a/freetype/src/tools/docmaker/docmaker.py
+++ b/freetype/src/tools/docmaker/docmaker.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
#
-# DocMaker (c) 2002, 2004, 2008 David Turner <david@freetype.org>
+# DocMaker (c) 2002, 2004, 2008, 2013 David Turner <david@freetype.org>
#
-# This program is a re-write of the original DocMaker took used
+# This program is a re-write of the original DocMaker tool used
# to generate the API Reference of the FreeType font engine
# by converting in-source comments into structured HTML.
#
diff --git a/freetype/src/tools/docmaker/sources.py b/freetype/src/tools/docmaker/sources.py
index 490ba2506..dab834978 100644
--- a/freetype/src/tools/docmaker/sources.py
+++ b/freetype/src/tools/docmaker/sources.py
@@ -1,4 +1,4 @@
-# Sources (c) 2002-2004, 2006-2009, 2012
+# Sources (c) 2002-2004, 2006-2009, 2012, 2013
# David Turner <david@freetype.org>
#
#
@@ -132,7 +132,7 @@ re_markup_tags = [re_markup_tag1, re_markup_tag2]
#
# used to detect a cross-reference, after markup tags have been stripped
#
-re_crossref = re.compile( r'@((?:\w|-)*)(.*)' )
+re_crossref = re.compile( r'@((?:\w|-)*)(.*)' ) # @foo
#
# used to detect italic and bold styles in paragraph text
@@ -141,6 +141,42 @@ re_italic = re.compile( r"_(\w(\w|')*)_(.*)" ) # _italic_
re_bold = re.compile( r"\*(\w(\w|')*)\*(.*)" ) # *bold*
#
+# this regular expression code to identify an URL has been taken from
+#
+# http://mail.python.org/pipermail/tutor/2002-September/017228.html
+#
+# (with slight modifications)
+#
+
+urls = r'(?:https?|telnet|gopher|file|wais|ftp)'
+ltrs = r'\w'
+gunk = r'/#~:.?+=&%@!\-'
+punc = r'.:?\-'
+any = "%(ltrs)s%(gunk)s%(punc)s" % { 'ltrs' : ltrs,
+ 'gunk' : gunk,
+ 'punc' : punc }
+url = r"""
+ (
+ \b # start at word boundary
+ %(urls)s : # need resource and a colon
+ [%(any)s] +? # followed by one or more of any valid
+ # character, but be conservative and
+ # take only what you need to...
+ (?= # [look-ahead non-consumptive assertion]
+ [%(punc)s]* # either 0 or more punctuation
+ (?: # [non-grouping parentheses]
+ [^%(any)s] | $ # followed by a non-url char
+ # or end of the string
+ )
+ )
+ )
+ """ % {'urls' : urls,
+ 'any' : any,
+ 'punc' : punc }
+
+re_url = re.compile( url, re.VERBOSE | re.MULTILINE )
+
+#
# used to detect the end of commented source lines
#
re_source_sep = re.compile( r'\s*/\*\s*\*/' )
diff --git a/freetype/src/tools/docmaker/tohtml.py b/freetype/src/tools/docmaker/tohtml.py
index fffa12097..7944f1c99 100644
--- a/freetype/src/tools/docmaker/tohtml.py
+++ b/freetype/src/tools/docmaker/tohtml.py
@@ -1,4 +1,4 @@
-# ToHTML (c) 2002, 2003, 2005, 2006, 2007, 2008
+# ToHTML (c) 2002, 2003, 2005-2008, 2013
# David Turner <david@freetype.org>
from sources import *
@@ -175,25 +175,6 @@ def html_quote( line ):
return result
-# same as 'html_quote', but ignores left and right brackets
-def html_quote0( line ):
- return string.replace( line, "&", "&amp;" )
-
-
-def dump_html_code( lines, prefix = "" ):
- # clean the last empty lines
- l = len( self.lines )
- while l > 0 and string.strip( self.lines[l - 1] ) == "":
- l = l - 1
-
- # The code footer should be directly appended to the last code
- # line to avoid an additional blank line.
- print prefix + code_header,
- for line in self.lines[0 : l + 1]:
- print '\n' + prefix + html_quote( line ),
- print prefix + code_footer,
-
-
class HtmlFormatter( Formatter ):
@@ -242,16 +223,6 @@ class HtmlFormatter( Formatter ):
def make_block_url( self, block ):
return self.make_section_url( block.section ) + "#" + block.name
- def make_html_words( self, words ):
- """ convert a series of simple words into some HTML text """
- line = ""
- if words:
- line = html_quote( words[0] )
- for w in words[1:]:
- line = line + " " + html_quote( w )
-
- return line
-
def make_html_word( self, word ):
"""analyze a simple word to detect cross-references and styling"""
# look for cross-references
@@ -291,6 +262,8 @@ class HtmlFormatter( Formatter ):
line = self.make_html_word( words[0] )
for word in words[1:]:
line = line + " " + self.make_html_word( word )
+ # handle hyperlinks
+ line = re_url.sub( r'<a href="\1">\1</a>', line )
# convert `...' quotations into real left and right single quotes
line = re.sub( r"(^|\W)`(.*?)'(\W|$)", \
r'\1&lsquo;\2&rsquo;\3', \
@@ -549,7 +522,7 @@ class HtmlFormatter( Formatter ):
if block.source.filename.find( f ) >= 0:
header = self.headers[f] + ' (' + f + ')'
break;
-
+
# if not header:
# sys.stderr.write( \
# 'WARNING: No header macro for ' + block.source.filename + '.\n' )
diff --git a/freetype/src/truetype/ttdriver.c b/freetype/src/truetype/ttdriver.c
index 9610baf1b..ff15ea070 100644
--- a/freetype/src/truetype/ttdriver.c
+++ b/freetype/src/truetype/ttdriver.c
@@ -215,7 +215,8 @@
FT_UShort ah;
- TT_Get_VMetrics( face, start + nn, &tsb, &ah );
+ /* since we don't need `tsb', we use zero for `yMax' parameter */
+ TT_Get_VMetrics( face, start + nn, 0, &tsb, &ah );
advances[nn] = ah;
}
}
diff --git a/freetype/src/truetype/ttgload.c b/freetype/src/truetype/ttgload.c
index dbb5abdc9..404ecf0df 100644
--- a/freetype/src/truetype/ttgload.c
+++ b/freetype/src/truetype/ttgload.c
@@ -85,51 +85,36 @@
/*************************************************************************/
/* */
/* Return the vertical metrics in font units for a given glyph. */
- /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */
- /* table, typoAscender/Descender from the `OS/2' table would be used */
- /* instead, and if there were no `OS/2' table, use ascender/descender */
- /* from the `hhea' table. But that is not what Microsoft's rasterizer */
- /* apparently does: It uses the ppem value as the advance height, and */
- /* sets the top side bearing to be zero. */
+ /* See macro `TT_LOADER_SET_PP' below for explanations. */
/* */
FT_LOCAL_DEF( void )
TT_Get_VMetrics( TT_Face face,
FT_UInt idx,
+ FT_Pos yMax,
FT_Short* tsb,
FT_UShort* ah )
{
if ( face->vertical_info )
( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah );
-#if 1 /* Empirically determined, at variance with what MS said */
-
- else
- {
- *tsb = 0;
- *ah = face->root.units_per_EM;
- }
-
-#else /* This is what MS said to do. It isn't what they do, however. */
-
else if ( face->os2.version != 0xFFFFU )
{
- *tsb = face->os2.sTypoAscender;
+ *tsb = face->os2.sTypoAscender - yMax;
*ah = face->os2.sTypoAscender - face->os2.sTypoDescender;
}
+
else
{
- *tsb = face->horizontal.Ascender;
+ *tsb = face->horizontal.Ascender - yMax;
*ah = face->horizontal.Ascender - face->horizontal.Descender;
}
-#endif
-
FT_TRACE5(( " advance height (font units): %d\n", *ah ));
FT_TRACE5(( " top side bearing (font units): %d\n", *tsb ));
}
- static void
+ static FT_Error
tt_get_metrics( TT_Loader loader,
FT_UInt glyph_index )
{
@@ -138,17 +123,28 @@
TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face );
#endif
+ FT_Error error;
+ FT_Stream stream = loader->stream;
+
FT_Short left_bearing = 0, top_bearing = 0;
FT_UShort advance_width = 0, advance_height = 0;
+ /* we must preserve the stream position */
+ /* (which gets altered by the metrics functions) */
+ FT_ULong pos = FT_STREAM_POS();
+
TT_Get_HMetrics( face, glyph_index,
&left_bearing,
&advance_width );
TT_Get_VMetrics( face, glyph_index,
+ loader->bbox.yMax,
&top_bearing,
&advance_height );
+ if ( FT_STREAM_SEEK( pos ) )
+ return error;
+
loader->left_bearing = left_bearing;
loader->advance = advance_width;
loader->top_bearing = top_bearing;
@@ -171,6 +167,8 @@
loader->linear_def = 1;
loader->linear = advance_width;
}
+
+ return FT_Err_Ok;
}
@@ -350,9 +348,9 @@
FT_GlyphLoader gloader = load->gloader;
FT_Int n_contours = load->n_contours;
FT_Outline* outline;
- TT_Face face = (TT_Face)load->face;
FT_UShort n_ins;
FT_Int n_points;
+ FT_ULong tmp;
FT_Byte *flag, *flag_limit;
FT_Byte c, count;
@@ -418,14 +416,7 @@
FT_TRACE5(( " Instructions size: %u\n", n_ins ));
- if ( n_ins > face->max_profile.maxSizeOfInstructions )
- {
- FT_TRACE0(( "TT_Load_Simple_Glyph: too many instructions (%d)\n",
- n_ins ));
- error = FT_THROW( Too_Many_Hints );
- goto Fail;
- }
-
+ /* check it */
if ( ( limit - p ) < n_ins )
{
FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" ));
@@ -437,6 +428,20 @@
if ( IS_HINTED( load->load_flags ) )
{
+ /* we don't trust `maxSizeOfInstructions' in the `maxp' table */
+ /* and thus update the bytecode array size by ourselves */
+
+ tmp = load->exec->glyphSize;
+ error = Update_Max( load->exec->memory,
+ &tmp,
+ sizeof ( FT_Byte ),
+ (void*)&load->exec->glyphIns,
+ n_ins );
+
+ load->exec->glyphSize = (FT_UShort)tmp;
+ if ( error )
+ return error;
+
load->glyph->control_len = n_ins;
load->glyph->control_data = load->exec->glyphIns;
@@ -733,7 +738,6 @@
#endif
TT_GlyphZone zone = &loader->zone;
- FT_Pos origin;
#ifdef TT_USE_BYTECODE_INTERPRETER
FT_UInt n_ins;
@@ -745,19 +749,12 @@
#ifdef TT_USE_BYTECODE_INTERPRETER
if ( loader->glyph->control_len > 0xFFFFL )
{
- FT_TRACE1(( "TT_Hint_Glyph: too long instructions " ));
- FT_TRACE1(( "(0x%lx byte) is truncated\n",
+ FT_TRACE1(( "TT_Hint_Glyph: too long instructions" ));
+ FT_TRACE1(( " (0x%lx byte) is truncated\n",
loader->glyph->control_len ));
}
n_ins = (FT_UInt)( loader->glyph->control_len );
-#endif
-
- origin = zone->cur[zone->n_points - 4].x;
- origin = FT_PIX_ROUND( origin ) - origin;
- if ( origin )
- translate_array( zone->n_points, zone->cur, origin, 0 );
-#ifdef TT_USE_BYTECODE_INTERPRETER
/* save original point position in org */
if ( n_ins > 0 )
FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points );
@@ -783,9 +780,13 @@
}
#endif
- /* round pp2 and pp4 */
+ /* round phantom points */
+ zone->cur[zone->n_points - 4].x =
+ FT_PIX_ROUND( zone->cur[zone->n_points - 4].x );
zone->cur[zone->n_points - 3].x =
FT_PIX_ROUND( zone->cur[zone->n_points - 3].x );
+ zone->cur[zone->n_points - 2].y =
+ FT_PIX_ROUND( zone->cur[zone->n_points - 2].y );
zone->cur[zone->n_points - 1].y =
FT_PIX_ROUND( zone->cur[zone->n_points - 1].y );
@@ -823,13 +824,10 @@
#endif
/* save glyph phantom points */
- if ( !loader->preserve_pps )
- {
- loader->pp1 = zone->cur[zone->n_points - 4];
- loader->pp2 = zone->cur[zone->n_points - 3];
- loader->pp3 = zone->cur[zone->n_points - 2];
- loader->pp4 = zone->cur[zone->n_points - 1];
- }
+ loader->pp1 = zone->cur[zone->n_points - 4];
+ loader->pp2 = zone->cur[zone->n_points - 3];
+ loader->pp3 = zone->cur[zone->n_points - 2];
+ loader->pp4 = zone->cur[zone->n_points - 1];
#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 )
@@ -1077,9 +1075,9 @@
if ( !x && !y )
return FT_Err_Ok;
- /* Use a default value dependent on */
- /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */
- /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */
+ /* Use a default value dependent on */
+ /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old */
+ /* TT fonts which don't set the xxx_COMPONENT_OFFSET bit. */
if ( have_scale &&
#ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED
@@ -1091,10 +1089,10 @@
#if 0
- /*************************************************************************/
- /* */
- /* This algorithm is what Apple documents. But it doesn't work. */
- /* */
+ /*******************************************************************/
+ /* */
+ /* This algorithm is what Apple documents. But it doesn't work. */
+ /* */
int a = subglyph->transform.xx > 0 ? subglyph->transform.xx
: -subglyph->transform.xx;
int b = subglyph->transform.yx > 0 ? subglyph->transform.yx
@@ -1114,12 +1112,12 @@
x = FT_MulFix( x, m );
y = FT_MulFix( y, n );
-#else /* 0 */
+#else /* 1 */
- /*************************************************************************/
- /* */
- /* This algorithm is a guess and works much better than the above. */
- /* */
+ /*******************************************************************/
+ /* */
+ /* This algorithm is a guess and works much better than the above. */
+ /* */
FT_Fixed mac_xscale = FT_Hypot( subglyph->transform.xx,
subglyph->transform.xy );
FT_Fixed mac_yscale = FT_Hypot( subglyph->transform.yy,
@@ -1129,7 +1127,7 @@
x = FT_MulFix( x, mac_xscale );
y = FT_MulFix( y, mac_yscale );
-#endif /* 0 */
+#endif /* 1 */
}
@@ -1218,21 +1216,23 @@
max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions;
if ( n_ins > max_ins )
{
- /* acroread ignores this field, so we only do a rough safety check */
+ /* don't trust `maxSizeOfInstructions'; */
+ /* only do a rough safety check */
if ( (FT_Int)n_ins > loader->byte_len )
{
- FT_TRACE1(( "TT_Process_Composite_Glyph: "
- "too many instructions (%d) for glyph with length %d\n",
+ FT_TRACE1(( "TT_Process_Composite_Glyph:"
+ " too many instructions (%d) for glyph with length %d\n",
n_ins, loader->byte_len ));
return FT_THROW( Too_Many_Hints );
}
- tmp = loader->exec->glyphSize;
+ tmp = loader->exec->glyphSize;
error = Update_Max( loader->exec->memory,
&tmp,
sizeof ( FT_Byte ),
(void*)&loader->exec->glyphIns,
n_ins );
+
loader->exec->glyphSize = (FT_UShort)tmp;
if ( error )
return error;
@@ -1254,7 +1254,7 @@
/* Some points are likely touched during execution of */
/* instructions on components. So let's untouch them. */
- for ( i = start_point; i < loader->zone.n_points; i++ )
+ for ( i = 0; i < loader->zone.n_points; i++ )
loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH;
loader->zone.n_points += 4;
@@ -1263,21 +1263,131 @@
}
- /* Calculate the four phantom points. */
- /* The first two stand for horizontal origin and advance. */
- /* The last two stand for vertical origin and advance. */
+ /*
+ * Calculate the phantom points
+ *
+ * Defining the right side bearing (rsb) as
+ *
+ * rsb = aw - (lsb + xmax - xmin)
+ *
+ * (with `aw' the advance width, `lsb' the left side bearing, and `xmin'
+ * and `xmax' the glyph's minimum and maximum x value), the OpenType
+ * specification defines the initial position of horizontal phantom points
+ * as
+ *
+ * pp1 = (round(xmin - lsb), 0) ,
+ * pp2 = (round(pp1 + aw), 0) .
+ *
+ * Note that the rounding to the grid (in the device space) is not
+ * documented currently in the specification.
+ *
+ * However, the specification lacks the precise definition of vertical
+ * phantom points. Greg Hitchcock provided the following explanation.
+ *
+ * - a `vmtx' table is present
+ *
+ * For any glyph, the minimum and maximum y values (`ymin' and `ymax')
+ * are given in the `glyf' table, the top side bearing (tsb) and advance
+ * height (ah) are given in the `vmtx' table. The bottom side bearing
+ * (bsb) is then calculated as
+ *
+ * bsb = ah - (tsb + ymax - ymin) ,
+ *
+ * and the initial position of vertical phantom points is
+ *
+ * pp3 = (x, round(ymax + tsb)) ,
+ * pp4 = (x, round(pp3 - ah)) .
+ *
+ * See below for value `x'.
+ *
+ * - no `vmtx' table in the font
+ *
+ * If there is an `OS/2' table, we set
+ *
+ * DefaultAscender = sTypoAscender ,
+ * DefaultDescender = sTypoDescender ,
+ *
+ * otherwise we use data from the `hhea' table:
+ *
+ * DefaultAscender = Ascender ,
+ * DefaultDescender = Descender .
+ *
+ * With these two variables we can now set
+ *
+ * ah = DefaultAscender - sDefaultDescender ,
+ * tsb = DefaultAscender - yMax ,
+ *
+ * and proceed as if a `vmtx' table was present.
+ *
+ * Usually we have
+ *
+ * x = aw / 2 , (1)
+ *
+ * but there is one compatibility case where it can be set to
+ *
+ * x = -DefaultDescender -
+ * ((DefaultAscender - DefaultDescender - aw) / 2) . (2)
+ *
+ * and another one with
+ *
+ * x = 0 . (3)
+ *
+ * In Windows, the history of those values is quite complicated,
+ * depending on the hinting engine (that is, the graphics framework).
+ *
+ * framework from to formula
+ * ----------------------------------------------------------
+ * GDI Windows 98 current (1)
+ * (Windows 2000 for NT)
+ * GDI+ Windows XP Windows 7 (2)
+ * GDI+ Windows 8 current (3)
+ * DWrite Windows 7 current (3)
+ *
+ * For simplicity, FreeType uses (1) for grayscale subpixel hinting and
+ * (3) for everything else.
+ *
+ */
+#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
+
#define TT_LOADER_SET_PP( loader ) \
- do { \
+ do \
+ { \
+ FT_Bool subpixel_ = loader->exec ? loader->exec->subpixel \
+ : 0; \
+ FT_Bool grayscale_ = loader->exec ? loader->exec->grayscale \
+ : 0; \
+ FT_Bool use_aw_2_ = (FT_Bool)( subpixel_ && grayscale_ ); \
+ \
+ \
(loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \
(loader)->pp1.y = 0; \
(loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \
(loader)->pp2.y = 0; \
+ \
+ (loader)->pp3.x = use_aw_2_ ? (loader)->advance / 2 : 0; \
+ (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \
+ (loader)->pp4.x = use_aw_2_ ? (loader)->advance / 2 : 0; \
+ (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \
+ } while ( 0 )
+
+#else /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
+#define TT_LOADER_SET_PP( loader ) \
+ do \
+ { \
+ (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \
+ (loader)->pp1.y = 0; \
+ (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \
+ (loader)->pp2.y = 0; \
+ \
(loader)->pp3.x = 0; \
- (loader)->pp3.y = (loader)->top_bearing + (loader)->bbox.yMax; \
+ (loader)->pp3.y = (loader)->bbox.yMax + (loader)->top_bearing; \
(loader)->pp4.x = 0; \
(loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \
} while ( 0 )
+#endif /* !TT_CONFIG_OPTION_SUBPIXEL_HINTING */
+
/*************************************************************************/
/* */
@@ -1341,8 +1451,6 @@
y_scale = 0x10000L;
}
- tt_get_metrics( loader, glyph_index );
-
/* Set `offset' to the start of the glyph relative to the start of */
/* the `glyf' table, and `byte_len' to the length of the glyph in */
/* bytes. */
@@ -1402,7 +1510,17 @@
/* read glyph header first */
error = face->read_glyph_header( loader );
- if ( error || header_only )
+ if ( error )
+ goto Exit;
+
+ /* the metrics must be computed after loading the glyph header */
+ /* since we need the glyph's `yMax' value in case the vertical */
+ /* metrics must be emulated */
+ error = tt_get_metrics( loader, glyph_index );
+ if ( error )
+ goto Exit;
+
+ if ( header_only )
goto Exit;
}
@@ -1413,6 +1531,10 @@
loader->bbox.yMin = 0;
loader->bbox.yMax = 0;
+ error = tt_get_metrics( loader, glyph_index );
+ if ( error )
+ goto Exit;
+
if ( header_only )
goto Exit;
@@ -1437,21 +1559,32 @@
if ( error )
goto Exit;
- loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y;
- loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y;
- loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y;
- loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y;
+ loader->pp1.x += deltas[0].x;
+ loader->pp1.y += deltas[0].y;
+ loader->pp2.x += deltas[1].x;
+ loader->pp2.y += deltas[1].y;
+
+ loader->pp3.x += deltas[2].x;
+ loader->pp3.y += deltas[2].y;
+ loader->pp4.x += deltas[3].x;
+ loader->pp4.y += deltas[3].y;
FT_FREE( deltas );
}
-#endif
+#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+ /* scale phantom points, if necessary; */
+ /* they get rounded in `TT_Hint_Glyph' */
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
{
loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
+ /* pp1.y and pp2.y are always zero */
+
+ loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale );
loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
+ loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale );
loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
}
@@ -1459,8 +1592,8 @@
goto Exit;
}
- /* must initialize points before (possibly) overriding */
- /* glyph metrics from the incremental interface */
+ /* must initialize phantom points before (possibly) overriding */
+ /* glyph metrics from the incremental interface */
TT_LOADER_SET_PP( loader );
#ifdef FT_CONFIG_OPTION_INCREMENTAL
@@ -1533,7 +1666,7 @@
face,
glyph_index,
&deltas,
- gloader->current.num_subglyphs + 4 )) != 0 )
+ gloader->current.num_subglyphs + 4 ) ) != 0 )
goto Exit;
subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs;
@@ -1551,21 +1684,32 @@
}
}
- loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y;
- loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y;
- loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y;
- loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y;
+ loader->pp1.x += deltas[i + 0].x;
+ loader->pp1.y += deltas[i + 0].y;
+ loader->pp2.x += deltas[i + 1].x;
+ loader->pp2.y += deltas[i + 1].y;
+
+ loader->pp3.x += deltas[i + 2].x;
+ loader->pp3.y += deltas[i + 2].y;
+ loader->pp4.x += deltas[i + 3].x;
+ loader->pp4.y += deltas[i + 3].y;
FT_FREE( deltas );
}
#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
+ /* scale phantom points, if necessary; */
+ /* they get rounded in `TT_Hint_Glyph' */
if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
{
loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
+ /* pp1.y and pp2.y are always zero */
+
+ loader->pp3.x = FT_MulFix( loader->pp3.x, x_scale );
loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
+ loader->pp4.x = FT_MulFix( loader->pp4.x, x_scale );
loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
}
@@ -1625,6 +1769,7 @@
/* restore subglyph pointer */
subglyph = gloader->base.subglyphs + num_base_subgs + n;
+ /* restore phantom points if necessary */
if ( !( subglyph->flags & USE_MY_METRICS ) )
{
loader->pp1 = pp[0];
@@ -1961,8 +2106,7 @@
#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( face );
- FT_Bool subpixel_hinting = FALSE;
- FT_Bool grayscale_hinting = TRUE;
+ FT_Bool subpixel = FALSE;
#if 0
/* not used yet */
@@ -1995,24 +2139,24 @@
if ( driver->interpreter_version == TT_INTERPRETER_VERSION_38 )
{
- subpixel_hinting = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags )
- != FT_RENDER_MODE_MONO ) &&
- SPH_OPTION_SET_SUBPIXEL );
+ subpixel = FT_BOOL( ( FT_LOAD_TARGET_MODE( load_flags ) !=
+ FT_RENDER_MODE_MONO ) &&
+ SPH_OPTION_SET_SUBPIXEL );
- if ( subpixel_hinting )
- grayscale = grayscale_hinting = FALSE;
+ if ( subpixel )
+ grayscale = FALSE;
else if ( SPH_OPTION_SET_GRAYSCALE )
{
- grayscale = grayscale_hinting = TRUE;
- subpixel_hinting = FALSE;
+ grayscale = TRUE;
+ subpixel = FALSE;
}
else
- grayscale = grayscale_hinting = FALSE;
+ grayscale = FALSE;
if ( FT_IS_TRICKY( glyph->face ) )
- subpixel_hinting = grayscale_hinting = FALSE;
+ subpixel = FALSE;
- exec->ignore_x_mode = subpixel_hinting || grayscale_hinting;
+ exec->ignore_x_mode = subpixel || grayscale;
exec->rasterizer_version = SPH_OPTION_SET_RASTERIZER_VERSION;
if ( exec->sph_tweak_flags & SPH_TWEAK_RASTERIZER_35 )
exec->rasterizer_version = TT_INTERPRETER_VERSION_35;
@@ -2055,24 +2199,24 @@
{
/* a change from mono to subpixel rendering (and vice versa) */
/* requires a re-execution of the CVT program */
- if ( subpixel_hinting != exec->subpixel_hinting )
+ if ( subpixel != exec->subpixel )
{
FT_TRACE4(( "tt_loader_init: subpixel hinting change,"
" re-executing `prep' table\n" ));
- exec->subpixel_hinting = subpixel_hinting;
- reexecute = TRUE;
+ exec->subpixel = subpixel;
+ reexecute = TRUE;
}
/* a change from mono to grayscale rendering (and vice versa) */
/* requires a re-execution of the CVT program */
- if ( grayscale != exec->grayscale_hinting )
+ if ( grayscale != exec->grayscale )
{
FT_TRACE4(( "tt_loader_init: grayscale hinting change,"
" re-executing `prep' table\n" ));
- exec->grayscale_hinting = grayscale_hinting;
- reexecute = TRUE;
+ exec->grayscale = grayscale;
+ reexecute = TRUE;
}
}
else
@@ -2202,7 +2346,7 @@
TT_LoaderRec loader;
- error = FT_Err_Ok;
+ FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index ));
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
diff --git a/freetype/src/truetype/ttgload.h b/freetype/src/truetype/ttgload.h
index 05f75882d..3f1699e68 100644
--- a/freetype/src/truetype/ttgload.h
+++ b/freetype/src/truetype/ttgload.h
@@ -43,6 +43,7 @@ FT_BEGIN_HEADER
FT_LOCAL( void )
TT_Get_VMetrics( TT_Face face,
FT_UInt idx,
+ FT_Pos yMax,
FT_Short* tsb,
FT_UShort* ah );
diff --git a/freetype/src/truetype/ttinterp.c b/freetype/src/truetype/ttinterp.c
index b97db8c57..9b7ca9df5 100644
--- a/freetype/src/truetype/ttinterp.c
+++ b/freetype/src/truetype/ttinterp.c
@@ -4,7 +4,7 @@
/* */
/* TrueType bytecode interpreter (body). */
/* */
-/* Copyright 1996-2013 */
+/* Copyright 1996-2014 */
/* by David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -796,16 +796,13 @@
FT_EXPORT_DEF( TT_ExecContext )
TT_New_Context( TT_Driver driver )
{
- TT_ExecContext exec;
- FT_Memory memory;
+ FT_Memory memory = driver->root.root.memory;
- memory = driver->root.root.memory;
- exec = driver->context;
-
if ( !driver->context )
{
- FT_Error error;
+ FT_Error error;
+ TT_ExecContext exec;
/* allocate object */
@@ -1437,9 +1434,108 @@
#undef PACK
-#if 1
+
+#ifndef FT_CONFIG_OPTION_NO_ASSEMBLER
+
+#if defined( __arm__ ) && \
+ ( defined( __thumb2__ ) || !defined( __thumb__ ) )
+
+#define TT_MulFix14 TT_MulFix14_arm
static FT_Int32
+ TT_MulFix14_arm( FT_Int32 a,
+ FT_Int b )
+ {
+ register FT_Int32 t, t2;
+
+
+#if defined( __CC_ARM ) || defined( __ARMCC__ )
+
+ __asm
+ {
+ smull t2, t, b, a /* (lo=t2,hi=t) = a*b */
+ mov a, t, asr #31 /* a = (hi >> 31) */
+ add a, a, #0x2000 /* a += 0x2000 */
+ adds t2, t2, a /* t2 += a */
+ adc t, t, #0 /* t += carry */
+ mov a, t2, lsr #14 /* a = t2 >> 14 */
+ orr a, a, t, lsl #18 /* a |= t << 18 */
+ }
+
+#elif defined( __GNUC__ )
+
+ __asm__ __volatile__ (
+ "smull %1, %2, %4, %3\n\t" /* (lo=%1,hi=%2) = a*b */
+ "mov %0, %2, asr #31\n\t" /* %0 = (hi >> 31) */
+#if defined( __clang__ ) && defined( __thumb2__ )
+ "add.w %0, %0, #0x2000\n\t" /* %0 += 0x2000 */
+#else
+ "add %0, %0, #0x2000\n\t" /* %0 += 0x2000 */
+#endif
+ "adds %1, %1, %0\n\t" /* %1 += %0 */
+ "adc %2, %2, #0\n\t" /* %2 += carry */
+ "mov %0, %1, lsr #14\n\t" /* %0 = %1 >> 16 */
+ "orr %0, %0, %2, lsl #18\n\t" /* %0 |= %2 << 16 */
+ : "=r"(a), "=&r"(t2), "=&r"(t)
+ : "r"(a), "r"(b)
+ : "cc" );
+
+#endif
+
+ return a;
+ }
+
+#endif /* __arm__ && ( __thumb2__ || !__thumb__ ) */
+
+#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
+
+
+#if defined( __GNUC__ ) && \
+ ( defined( __i386__ ) || defined( __x86_64__ ) )
+
+#define TT_MulFix14 TT_MulFix14_long_long
+
+ /* Temporarily disable the warning that C90 doesn't support `long long'. */
+#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406
+#pragma GCC diagnostic push
+#endif
+#pragma GCC diagnostic ignored "-Wlong-long"
+
+ /* This is declared `noinline' because inlining the function results */
+ /* in slower code. The `pure' attribute indicates that the result */
+ /* only depends on the parameters. */
+ static __attribute__(( noinline ))
+ __attribute__(( pure )) FT_Int32
+ TT_MulFix14_long_long( FT_Int32 a,
+ FT_Int b )
+ {
+
+ long long ret = (long long)a * b;
+
+ /* The following line assumes that right shifting of signed values */
+ /* will actually preserve the sign bit. The exact behaviour is */
+ /* undefined, but this is true on x86 and x86_64. */
+ long long tmp = ret >> 63;
+
+
+ ret += 0x2000 + tmp;
+
+ return (FT_Int32)( ret >> 14 );
+ }
+
+#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406
+#pragma GCC diagnostic pop
+#endif
+
+#endif /* __GNUC__ && ( __i386__ || __x86_64__ ) */
+
+
+#ifndef TT_MulFix14
+
+ /* Compute (a*b)/2^14 with maximum accuracy and rounding. */
+ /* This is optimized to be faster than calling FT_MulFix() */
+ /* for platforms where sizeof(int) == 2. */
+ static FT_Int32
TT_MulFix14( FT_Int32 a,
FT_Int b )
{
@@ -1470,37 +1566,50 @@
return sign >= 0 ? (FT_Int32)mid : -(FT_Int32)mid;
}
-#else
+#endif /* !TT_MulFix14 */
- /* compute (a*b)/2^14 with maximum accuracy and rounding */
- static FT_Int32
- TT_MulFix14( FT_Int32 a,
- FT_Int b )
- {
- FT_Int32 m, s, hi;
- FT_UInt32 l, lo;
+#if defined( __GNUC__ ) && \
+ ( defined( __i386__ ) || \
+ defined( __x86_64__ ) || \
+ defined( __arm__ ) )
- /* compute ax*bx as 64-bit value */
- l = (FT_UInt32)( ( a & 0xFFFFU ) * b );
- m = ( a >> 16 ) * b;
+#define TT_DotFix14 TT_DotFix14_long_long
- lo = l + ( (FT_UInt32)m << 16 );
- hi = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo < l );
+#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406
+#pragma GCC diagnostic push
+#endif
+#pragma GCC diagnostic ignored "-Wlong-long"
- /* divide the result by 2^14 with rounding */
- s = hi >> 31;
- l = lo + (FT_UInt32)s;
- hi += s + ( l < lo );
- lo = l;
+ static __attribute__(( pure )) FT_Int32
+ TT_DotFix14_long_long( FT_Int32 ax,
+ FT_Int32 ay,
+ FT_Int bx,
+ FT_Int by )
+ {
+ /* Temporarily disable the warning that C90 doesn't support */
+ /* `long long'. */
- l = lo + 0x2000U;
- hi += l < lo;
+ long long temp1 = (long long)ax * bx;
+ long long temp2 = (long long)ay * by;
+
+
+ temp1 += temp2;
+ temp2 = temp1 >> 63;
+ temp1 += 0x2000 + temp2;
+
+ return (FT_Int32)( temp1 >> 14 );
- return (FT_Int32)( ( (FT_UInt32)hi << 18 ) | ( l >> 14 ) );
}
+
+#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406
+#pragma GCC diagnostic pop
#endif
+#endif /* __GNUC__ && (__arm__ || __i386__ || __x86_64__) */
+
+
+#ifndef TT_DotFix14
/* compute (ax*bx+ay*by)/2^14 with maximum accuracy and rounding */
static FT_Int32
@@ -1543,6 +1652,8 @@
return (FT_Int32)( ( (FT_UInt32)hi << 18 ) | ( l >> 14 ) );
}
+#endif /* TT_DotFix14 */
+
/*************************************************************************/
/* */
@@ -3037,42 +3148,42 @@
}
-#define DO_JROT \
- if ( args[1] != 0 ) \
- { \
- if ( args[0] == 0 && CUR.args == 0 ) \
- CUR.error = FT_THROW( Bad_Argument ); \
- CUR.IP += args[0]; \
- if ( CUR.IP < 0 || \
- ( CUR.callTop > 0 && \
- CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \
- CUR.error = FT_THROW( Bad_Argument ); \
- CUR.step_ins = FALSE; \
+#define DO_JROT \
+ if ( args[1] != 0 ) \
+ { \
+ if ( args[0] == 0 && CUR.args == 0 ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
+ CUR.IP += args[0]; \
+ if ( CUR.IP < 0 || \
+ ( CUR.callTop > 0 && \
+ CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
+ CUR.step_ins = FALSE; \
}
-#define DO_JMPR \
- if ( args[0] == 0 && CUR.args == 0 ) \
- CUR.error = FT_THROW( Bad_Argument ); \
- CUR.IP += args[0]; \
- if ( CUR.IP < 0 || \
- ( CUR.callTop > 0 && \
- CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \
- CUR.error = FT_THROW( Bad_Argument ); \
+#define DO_JMPR \
+ if ( args[0] == 0 && CUR.args == 0 ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
+ CUR.IP += args[0]; \
+ if ( CUR.IP < 0 || \
+ ( CUR.callTop > 0 && \
+ CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
CUR.step_ins = FALSE;
-#define DO_JROF \
- if ( args[1] == 0 ) \
- { \
- if ( args[0] == 0 && CUR.args == 0 ) \
- CUR.error = FT_THROW( Bad_Argument ); \
- CUR.IP += args[0]; \
- if ( CUR.IP < 0 || \
- ( CUR.callTop > 0 && \
- CUR.IP > CUR.callStack[CUR.callTop - 1].Cur_End ) ) \
- CUR.error = FT_THROW( Bad_Argument ); \
- CUR.step_ins = FALSE; \
+#define DO_JROF \
+ if ( args[1] == 0 ) \
+ { \
+ if ( args[0] == 0 && CUR.args == 0 ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
+ CUR.IP += args[0]; \
+ if ( CUR.IP < 0 || \
+ ( CUR.callTop > 0 && \
+ CUR.IP > CUR.callStack[CUR.callTop - 1].Def->end ) ) \
+ CUR.error = FT_THROW( Bad_Argument ); \
+ CUR.step_ins = FALSE; \
}
@@ -4788,7 +4899,7 @@
if ( pRec->Cur_Count > 0 )
{
CUR.callTop++;
- CUR.IP = pRec->Cur_Restart;
+ CUR.IP = pRec->Def->start;
}
else
/* Loop through the current function */
@@ -4878,8 +4989,7 @@
pCrec->Caller_Range = CUR.curRange;
pCrec->Caller_IP = CUR.IP + 1;
pCrec->Cur_Count = 1;
- pCrec->Cur_Restart = def->start;
- pCrec->Cur_End = def->end;
+ pCrec->Def = def;
CUR.callTop++;
@@ -4967,8 +5077,7 @@
pCrec->Caller_Range = CUR.curRange;
pCrec->Caller_IP = CUR.IP + 1;
pCrec->Cur_Count = (FT_Int)args[0];
- pCrec->Cur_Restart = def->start;
- pCrec->Cur_End = def->end;
+ pCrec->Def = def;
CUR.callTop++;
@@ -7057,7 +7166,7 @@
org_dist = CUR_fast_dualproj( &vec );
}
- cur_dist = CUR_Func_project ( &CUR.zp2.cur[point], cur_base );
+ cur_dist = CUR_Func_project( &CUR.zp2.cur[point], cur_base );
if ( org_dist )
{
@@ -7068,14 +7177,20 @@
/* This is the same as what MS does for the invalid case: */
/* */
/* delta = (Original_Pt - Original_RP1) - */
- /* (Current_Pt - Current_RP1) */
+ /* (Current_Pt - Current_RP1) ; */
/* */
/* In FreeType speak: */
/* */
- /* new_dist = cur_dist - */
- /* org_dist - cur_dist; */
+ /* delta = org_dist - cur_dist . */
+ /* */
+ /* We move `point' by `new_dist - cur_dist' after leaving */
+ /* this block, thus we have */
+ /* */
+ /* new_dist - cur_dist = delta , */
+ /* new_dist - cur_dist = org_dist - cur_dist , */
+ /* new_dist = org_dist . */
- new_dist = -org_dist;
+ new_dist = org_dist;
}
}
else
@@ -7708,26 +7823,16 @@
CUR.ignore_x_mode &&
CUR.rasterizer_version >= TT_INTERPRETER_VERSION_35 )
{
- /********************************/
- /* HINTING FOR GRAYSCALE */
- /* Selector Bit: 5 */
- /* Return Bit(s): 12 */
- /* */
- if ( ( args[0] & 32 ) != 0 && CUR.grayscale_hinting )
- K |= 1 << 12;
-
- /********************************/
- /* HINTING FOR SUBPIXEL */
- /* Selector Bit: 6 */
- /* Return Bit(s): 13 */
- /* */
- if ( ( args[0] & 64 ) != 0 &&
- CUR.subpixel_hinting &&
- CUR.rasterizer_version >= 37 )
- {
- K |= 1 << 13;
- /* the stuff below is irrelevant if subpixel_hinting is not set */
+ if ( CUR.rasterizer_version >= 37 )
+ {
+ /********************************/
+ /* HINTING FOR SUBPIXEL */
+ /* Selector Bit: 6 */
+ /* Return Bit(s): 13 */
+ /* */
+ if ( ( args[0] & 64 ) != 0 && CUR.subpixel )
+ K |= 1 << 13;
/********************************/
/* COMPATIBLE WIDTHS ENABLED */
@@ -7803,8 +7908,7 @@
call->Caller_Range = CUR.curRange;
call->Caller_IP = CUR.IP + 1;
call->Cur_Count = 1;
- call->Cur_Restart = def->start;
- call->Cur_End = def->end;
+ call->Def = def;
INS_Goto_CodeRange( def->range, def->start );
@@ -8860,8 +8964,7 @@
callrec->Caller_Range = CUR.curRange;
callrec->Caller_IP = CUR.IP + 1;
callrec->Cur_Count = 1;
- callrec->Cur_Restart = def->start;
- callrec->Cur_End = def->end;
+ callrec->Def = def;
if ( INS_Goto_CodeRange( def->range, def->start ) == FAILURE )
goto LErrorLabel_;
diff --git a/freetype/src/truetype/ttinterp.h b/freetype/src/truetype/ttinterp.h
index 69f5011ed..1d8825d3b 100644
--- a/freetype/src/truetype/ttinterp.h
+++ b/freetype/src/truetype/ttinterp.h
@@ -101,8 +101,8 @@ FT_BEGIN_HEADER
FT_Int Caller_Range;
FT_Long Caller_IP;
FT_Long Cur_Count;
- FT_Long Cur_Restart;
- FT_Long Cur_End;
+
+ TT_DefRecord *Def; /* either FDEF or IDEF */
} TT_CallRec, *TT_CallStack;
@@ -263,12 +263,10 @@ FT_BEGIN_HEADER
#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
TT_Round_Func func_round_sphn; /* subpixel rounding function */
- FT_Bool grayscale_hinting; /* Using grayscale hinting? */
- FT_Bool subpixel_hinting; /* Using subpixel hinting? */
- FT_Bool native_hinting; /* Using native hinting? */
+ FT_Bool subpixel; /* Using subpixel hinting? */
FT_Bool ignore_x_mode; /* Standard rendering mode for */
/* subpixel hinting. On if gray */
- /* or subpixel hinting is on ) */
+ /* or subpixel hinting is on. */
/* The following 4 aren't fully implemented but here for MS rasterizer */
/* compatibility. */
diff --git a/freetype/src/truetype/ttobjs.c b/freetype/src/truetype/ttobjs.c
index a3d43bf7d..af04873fa 100644
--- a/freetype/src/truetype/ttobjs.c
+++ b/freetype/src/truetype/ttobjs.c
@@ -150,20 +150,21 @@
tt_check_trickyness_family( FT_String* name )
{
-#define TRICK_NAMES_MAX_CHARACTERS 16
-#define TRICK_NAMES_COUNT 8
+#define TRICK_NAMES_MAX_CHARACTERS 19
+#define TRICK_NAMES_COUNT 9
static const char trick_names[TRICK_NAMES_COUNT]
[TRICK_NAMES_MAX_CHARACTERS + 1] =
{
- "DFKaiSho-SB", /* dfkaisb.ttf */
+ "DFKaiSho-SB", /* dfkaisb.ttf */
"DFKaiShu",
- "DFKai-SB", /* kaiu.ttf */
- "HuaTianKaiTi?", /* htkt2.ttf */
- "HuaTianSongTi?", /* htst3.ttf */
- "MingLiU", /* mingliu.ttf & mingliu.ttc */
- "PMingLiU", /* mingliu.ttc */
- "MingLi43", /* mingli.ttf */
+ "DFKai-SB", /* kaiu.ttf */
+ "HuaTianKaiTi?", /* htkt2.ttf */
+ "HuaTianSongTi?", /* htst3.ttf */
+ "Ming(for ISO10646)", /* hkscsiic.ttf & iicore.ttf */
+ "MingLiU", /* mingliu.ttf & mingliu.ttc */
+ "PMingLiU", /* mingliu.ttc */
+ "MingLi43", /* mingli.ttf */
};
int nn;
@@ -532,6 +533,10 @@
/* check that we have a valid TrueType file */
error = sfnt->init_face( stream, face, face_index, num_params, params );
+
+ /* Stream may have changed. */
+ stream = face->root.stream;
+
if ( error )
goto Exit;
diff --git a/freetype/src/type1/t1gload.c b/freetype/src/type1/t1gload.c
index 1f3ae18c7..960a6d8cc 100644
--- a/freetype/src/type1/t1gload.c
+++ b/freetype/src/type1/t1gload.c
@@ -4,7 +4,7 @@
/* */
/* Type 1 Glyph Loader (body). */
/* */
-/* Copyright 1996-2006, 2008-2010, 2013 by */
+/* Copyright 1996-2006, 2008-2010, 2013, 2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -194,7 +194,7 @@
for ( glyph_index = 0; glyph_index < type1->num_glyphs; glyph_index++ )
{
/* now get load the unscaled outline */
- error = T1_Parse_Glyph( &decoder, glyph_index );
+ (void)T1_Parse_Glyph( &decoder, glyph_index );
if ( glyph_index == 0 || decoder.builder.advance.x > *max_advance )
*max_advance = decoder.builder.advance.x;
@@ -300,6 +300,8 @@
goto Exit;
}
+ FT_TRACE1(( "T1_Load_Glyph: glyph index %d\n", glyph_index ));
+
FT_ASSERT( ( face->len_buildchar == 0 ) == ( face->buildchar == NULL ) );
if ( load_flags & FT_LOAD_NO_RECURSE )
diff --git a/freetype/src/type1/t1load.c b/freetype/src/type1/t1load.c
index fff575a5c..e5b4b06fa 100644
--- a/freetype/src/type1/t1load.c
+++ b/freetype/src/type1/t1load.c
@@ -4,7 +4,7 @@
/* */
/* Type 1 font loader (body). */
/* */
-/* Copyright 1996-2013 by */
+/* Copyright 1996-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -377,8 +377,6 @@
if ( blend && blend->num_axis == num_coords )
{
/* recompute the weight vector from the blend coordinates */
- error = FT_Err_Ok;
-
for ( n = 0; n < blend->num_designs; n++ )
{
FT_Fixed result = 0x10000L; /* 1.0 fixed */
@@ -1107,7 +1105,7 @@
result = T1_ToFixedArray( parser, 6, temp, 3 );
- if ( result < 0 )
+ if ( result < 6 )
{
parser->root.error = FT_THROW( Invalid_File_Format );
return;
@@ -1274,6 +1272,13 @@
{
charcode = (FT_Int)T1_ToInt( parser );
T1_Skip_Spaces( parser );
+
+ /* protect against invalid charcode */
+ if ( cur == parser->root.cursor )
+ {
+ parser->root.error = FT_THROW( Unknown_File_Format );
+ return;
+ }
}
cur = parser->root.cursor;
@@ -2209,7 +2214,6 @@
if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY )
{
FT_Int charcode, idx, min_char, max_char;
- FT_Byte* char_name;
FT_Byte* glyph_name;
@@ -2224,6 +2228,9 @@
charcode = 0;
for ( ; charcode < loader.encoding_table.max_elems; charcode++ )
{
+ FT_Byte* char_name;
+
+
type1->encoding.char_index[charcode] = 0;
type1->encoding.char_name [charcode] = (char *)".notdef";
diff --git a/freetype/src/type1/t1objs.c b/freetype/src/type1/t1objs.c
index 8cb552e3a..8289f31b5 100644
--- a/freetype/src/type1/t1objs.c
+++ b/freetype/src/type1/t1objs.c
@@ -364,10 +364,10 @@
root->num_glyphs = type1->num_glyphs;
root->face_index = 0;
- root->face_flags = FT_FACE_FLAG_SCALABLE |
- FT_FACE_FLAG_HORIZONTAL |
- FT_FACE_FLAG_GLYPH_NAMES |
- FT_FACE_FLAG_HINTER;
+ root->face_flags |= FT_FACE_FLAG_SCALABLE |
+ FT_FACE_FLAG_HORIZONTAL |
+ FT_FACE_FLAG_GLYPH_NAMES |
+ FT_FACE_FLAG_HINTER;
if ( info->is_fixed_pitch )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
diff --git a/freetype/src/type1/t1parse.c b/freetype/src/type1/t1parse.c
index a53fb9089..9cb45eff8 100644
--- a/freetype/src/type1/t1parse.c
+++ b/freetype/src/type1/t1parse.c
@@ -4,7 +4,7 @@
/* */
/* Type 1 parser (body). */
/* */
-/* Copyright 1996-2005, 2008, 2009, 2012, 2013 by */
+/* Copyright 1996-2005, 2008, 2009, 2012-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -332,9 +332,11 @@
/* dictionary block in the heap. */
/* first of all, look at the `eexec' keyword */
- FT_Byte* cur = parser->base_dict;
- FT_Byte* limit = cur + parser->base_len;
- FT_Byte c;
+ FT_Byte* cur = parser->base_dict;
+ FT_Byte* limit = cur + parser->base_len;
+ FT_Byte c;
+ FT_Pointer pos_lf;
+ FT_Bool test_cr;
Again:
@@ -400,15 +402,24 @@
cur = parser->root.cursor;
limit = parser->root.limit;
- /* according to the Type1 spec, the first cipher byte must not be */
+ /* According to the Type 1 spec, the first cipher byte must not be */
/* an ASCII whitespace character code (blank, tab, carriage return */
/* or line feed). We have seen Type 1 fonts with two line feed */
/* characters... So skip now all whitespace character codes. */
- while ( cur < limit &&
- ( *cur == ' ' ||
- *cur == '\t' ||
- *cur == '\r' ||
- *cur == '\n' ) )
+ /* */
+ /* On the other hand, Adobe's Type 1 parser handles fonts just */
+ /* fine that are violating this limitation, so we add a heuristic */
+ /* test to stop at \r only if it is not used for EOL. */
+
+ pos_lf = ft_memchr( cur, '\n', limit - cur );
+ test_cr = FT_BOOL( !pos_lf ||
+ pos_lf > ft_memchr( cur, '\r', limit - cur ) );
+
+ while ( cur < limit &&
+ ( *cur == ' ' ||
+ *cur == '\t' ||
+ (test_cr && *cur == '\r' ) ||
+ *cur == '\n' ) )
++cur;
if ( cur >= limit )
{
diff --git a/freetype/src/type42/t42objs.c b/freetype/src/type42/t42objs.c
index 7f30f4d38..85d10a36f 100644
--- a/freetype/src/type42/t42objs.c
+++ b/freetype/src/type42/t42objs.c
@@ -171,7 +171,6 @@
FT_UNUSED( num_params );
FT_UNUSED( params );
- FT_UNUSED( face_index );
FT_UNUSED( stream );
@@ -219,9 +218,9 @@
root->num_charmaps = 0;
root->face_index = 0;
- root->face_flags = FT_FACE_FLAG_SCALABLE |
- FT_FACE_FLAG_HORIZONTAL |
- FT_FACE_FLAG_GLYPH_NAMES;
+ root->face_flags |= FT_FACE_FLAG_SCALABLE |
+ FT_FACE_FLAG_HORIZONTAL |
+ FT_FACE_FLAG_GLYPH_NAMES;
if ( info->is_fixed_pitch )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
@@ -507,7 +506,7 @@
FT_Face face = size->face;
T42_Face t42face = (T42_Face)face;
FT_Size ttsize;
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
error = FT_New_Size( t42face->ttf_face, &ttsize );
@@ -648,6 +647,8 @@
FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz;
+ FT_TRACE1(( "T42_GlyphSlot_Load: glyph index %d\n", glyph_index ));
+
t42_glyphslot_clear( t42slot->ttslot );
error = ttclazz->load_glyph( t42slot->ttslot,
t42size->ttsize,
diff --git a/freetype/src/type42/t42parse.c b/freetype/src/type42/t42parse.c
index 89564556e..5fdecb291 100644
--- a/freetype/src/type42/t42parse.c
+++ b/freetype/src/type42/t42parse.c
@@ -4,7 +4,7 @@
/* */
/* Type 42 font parser (body). */
/* */
-/* Copyright 2002-2013 by */
+/* Copyright 2002-2014 by */
/* Roberto Alameda. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -255,12 +255,26 @@
FT_Face root = (FT_Face)&face->root;
FT_Fixed temp[6];
FT_Fixed temp_scale;
+ FT_Int result;
- (void)T1_ToFixedArray( parser, 6, temp, 3 );
+ result = T1_ToFixedArray( parser, 6, temp, 3 );
+
+ if ( result < 6 )
+ {
+ parser->root.error = FT_THROW( Invalid_File_Format );
+ return;
+ }
temp_scale = FT_ABS( temp[3] );
+ if ( temp_scale == 0 )
+ {
+ FT_ERROR(( "t1_parse_font_matrix: invalid font matrix\n" ));
+ parser->root.error = FT_THROW( Invalid_File_Format );
+ return;
+ }
+
/* Set Units per EM based on FontMatrix values. We set the value to */
/* 1000 / temp_scale, because temp_scale was already multiplied by */
/* 1000 (in t1_tofixed, from psobjs.c). */
@@ -275,7 +289,7 @@
temp[2] = FT_DivFix( temp[2], temp_scale );
temp[4] = FT_DivFix( temp[4], temp_scale );
temp[5] = FT_DivFix( temp[5], temp_scale );
- temp[3] = 0x10000L;
+ temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
}
matrix->xx = temp[0];
@@ -314,7 +328,7 @@
if ( ft_isdigit( *cur ) || *cur == '[' )
{
T1_Encoding encode = &face->type1.encoding;
- FT_UInt count, n;
+ FT_Int count, n;
PS_Table char_table = &loader->encoding_table;
FT_Memory memory = parser->root.memory;
FT_Error error;
@@ -329,7 +343,7 @@
parser->root.cursor++;
}
else
- count = (FT_UInt)T1_ToInt( parser );
+ count = (FT_Int)T1_ToInt( parser );
T1_Skip_Spaces( parser );
if ( parser->root.cursor >= limit )
@@ -417,7 +431,7 @@
cur = parser->root.cursor;
- if ( *cur == '/' && cur + 2 < limit && n < count )
+ if ( cur + 2 < limit && *cur == '/' && n < count )
{
FT_PtrDist len;
@@ -426,6 +440,8 @@
parser->root.cursor = cur;
T1_Skip_PS_Token( parser );
+ if ( parser->root.cursor >= limit )
+ return;
if ( parser->root.error )
return;
@@ -439,6 +455,19 @@
n++;
}
+ else if ( only_immediates )
+ {
+ /* Since the current position is not updated for */
+ /* immediates-only mode we would get an infinite loop if */
+ /* we don't do anything here. */
+ /* */
+ /* This encoding array is not valid according to the type1 */
+ /* specification (it might be an encoding for a CID type1 */
+ /* font, however), so we conclude that this font is NOT a */
+ /* type1 font. */
+ parser->root.error = FT_THROW( Unknown_File_Format );
+ return;
+ }
}
else
{
@@ -450,8 +479,8 @@
T1_Skip_Spaces( parser );
}
- face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY;
- parser->root.cursor = cur;
+ face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY;
+ parser->root.cursor = cur;
}
/* Otherwise, we should have either `StandardEncoding', */
@@ -471,10 +500,7 @@
face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1;
else
- {
- FT_ERROR(( "t42_parse_encoding: invalid token\n" ));
- parser->root.error = FT_THROW( Invalid_File_Format );
- }
+ parser->root.error = FT_THROW( Ignore );
}
}
diff --git a/freetype/src/winfonts/winfnt.c b/freetype/src/winfonts/winfnt.c
index 36248913b..55ff04fba 100644
--- a/freetype/src/winfonts/winfnt.c
+++ b/freetype/src/winfonts/winfnt.c
@@ -4,7 +4,7 @@
/* */
/* FreeType font driver for Windows FNT/FON files */
/* */
-/* Copyright 1996-2004, 2006-2013 by */
+/* Copyright 1996-2004, 2006-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* Copyright 2003 Huw D M Davies for Codeweavers */
/* Copyright 2007 Dmitry Timoshkov for Codeweavers */
@@ -743,8 +743,8 @@
root->face_index = face_index;
- root->face_flags = FT_FACE_FLAG_FIXED_SIZES |
- FT_FACE_FLAG_HORIZONTAL;
+ root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+ FT_FACE_FLAG_HORIZONTAL;
if ( font->header.avg_width == font->header.max_width )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
@@ -977,26 +977,38 @@
font = face->font;
- if ( !font ||
+ if ( !font ||
glyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
+ FT_TRACE1(( "FNT_Load_Glyph: glyph index %d\n", glyph_index ));
+
if ( glyph_index > 0 )
glyph_index--; /* revert to real index */
else
- glyph_index = font->header.default_char; /* the .notdef glyph */
+ glyph_index = font->header.default_char; /* the `.notdef' glyph */
new_format = FT_BOOL( font->header.version == 0x300 );
len = new_format ? 6 : 4;
- /* jump to glyph entry */
- p = font->fnt_frame + ( new_format ? 148 : 118 ) + len * glyph_index;
+ /* get glyph width and offset */
+ offset = ( new_format ? 148 : 118 ) + len * glyph_index;
+
+ if ( offset >= font->header.file_size - 2 - ( new_format ? 4 : 2 ) )
+ {
+ FT_TRACE2(( "invalid FNT offset\n" ));
+ error = FT_THROW( Invalid_File_Format );
+ goto Exit;
+ }
+
+ p = font->fnt_frame + offset;
bitmap->width = FT_NEXT_SHORT_LE( p );
+ /* jump to glyph entry */
if ( new_format )
offset = FT_NEXT_ULONG_LE( p );
else
@@ -1024,7 +1036,7 @@
bitmap->rows = font->header.pixel_height;
bitmap->pixel_mode = FT_PIXEL_MODE_MONO;
- if ( offset + pitch * bitmap->rows >= font->header.file_size )
+ if ( offset + pitch * bitmap->rows > font->header.file_size )
{
FT_TRACE2(( "invalid bitmap width\n" ));
error = FT_THROW( Invalid_File_Format );