From e192439547bf637ef3d0e5ed730064a2c89247f9 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 22:14:22 +0000 Subject: Prepare for a new update Reverting patches so we can apply the latest update and changes can be seen in the spec file and sources. --- diff --git a/builds/unix/freetype-config.in b/builds/unix/freetype-config.in index 29541e9..97de134 100644 --- a/builds/unix/freetype-config.in +++ b/builds/unix/freetype-config.in @@ -13,24 +13,44 @@ LC_ALL=C export LC_ALL -# note that option `--variable' is not affected by the -# PKG_CONFIG_SYSROOT_DIR environment variable -if test "x$SYSROOT" != "x" ; then - PKG_CONFIG_SYSROOT_DIR="$SYSROOT" - export PKG_CONFIG_SYSROOT_DIR -fi +# if `pkg-config' is available, use values from `freetype2.pc' +pkg-config --version >/dev/null 2>&1 +if test $? -eq 0 ; then + # note that option `--variable' is not affected by the + # PKG_CONFIG_SYSROOT_DIR environment variable + if test "x$SYSROOT" != "x" ; then + PKG_CONFIG_SYSROOT_DIR="$SYSROOT" + export PKG_CONFIG_SYSROOT_DIR + fi + + prefix=`pkg-config --variable prefix freetype2` + exec_prefix=`pkg-config --variable exec_prefix freetype2` + + includedir=`pkg-config --variable includedir freetype2` + libdir=`pkg-config --variable libdir freetype2` -prefix=`pkg-config --variable prefix freetype2` -exec_prefix=`pkg-config --variable exec_prefix freetype2` + version=`pkg-config --modversion freetype2` -includedir=`pkg-config --variable includedir freetype2` -libdir=`pkg-config --variable libdir freetype2` + cflags=`pkg-config --cflags freetype2` + dynamic_libs=`pkg-config --libs freetype2` + static_libs=`pkg-config --static --libs freetype2` +else + prefix="%prefix%" + exec_prefix="%exec_prefix%" -version=`pkg-config --modversion freetype2` + includedir="%includedir%" + libdir="%libdir%" -cflags=`pkg-config --cflags freetype2` -dynamic_libs=`pkg-config --libs freetype2` -static_libs=`pkg-config --static --libs freetype2` + version=%ft_version% + + cflags="-I${SYSROOT}$includedir/freetype2" + dynamic_libs="-lfreetype" + static_libs="%LIBSSTATIC_CONFIG%" + if test "${SYSROOT}$libdir" != "/usr/lib" && + test "${SYSROOT}$libdir" != "/usr/lib64" ; then + libs_L="-L${SYSROOT}$libdir" + fi +fi orig_prefix=$prefix orig_exec_prefix=$exec_prefix @@ -185,7 +205,7 @@ if test "$echo_libs" = "yes" ; then fi if test "$echo_libtool" = "yes" ; then - echo "" + echo ${SYSROOT}$libdir/libfreetype.la fi # EOF diff --git a/builds/unix/freetype-config.in.libtool b/builds/unix/freetype-config.in.libtool deleted file mode 100644 index 97de134..0000000 --- a/builds/unix/freetype-config.in.libtool +++ /dev/null @@ -1,211 +0,0 @@ -#! /bin/sh -# -# Copyright 2000-2017 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. - -LC_ALL=C -export LC_ALL - - -# if `pkg-config' is available, use values from `freetype2.pc' -pkg-config --version >/dev/null 2>&1 -if test $? -eq 0 ; then - # note that option `--variable' is not affected by the - # PKG_CONFIG_SYSROOT_DIR environment variable - if test "x$SYSROOT" != "x" ; then - PKG_CONFIG_SYSROOT_DIR="$SYSROOT" - export PKG_CONFIG_SYSROOT_DIR - fi - - prefix=`pkg-config --variable prefix freetype2` - exec_prefix=`pkg-config --variable exec_prefix freetype2` - - includedir=`pkg-config --variable includedir freetype2` - libdir=`pkg-config --variable libdir freetype2` - - version=`pkg-config --modversion freetype2` - - cflags=`pkg-config --cflags freetype2` - dynamic_libs=`pkg-config --libs freetype2` - static_libs=`pkg-config --static --libs freetype2` -else - prefix="%prefix%" - exec_prefix="%exec_prefix%" - - includedir="%includedir%" - libdir="%libdir%" - - version=%ft_version% - - cflags="-I${SYSROOT}$includedir/freetype2" - dynamic_libs="-lfreetype" - static_libs="%LIBSSTATIC_CONFIG%" - if test "${SYSROOT}$libdir" != "/usr/lib" && - test "${SYSROOT}$libdir" != "/usr/lib64" ; then - libs_L="-L${SYSROOT}$libdir" - fi -fi - -orig_prefix=$prefix -orig_exec_prefix=$exec_prefix - -orig_includedir=$includedir -orig_libdir=$libdir - -include_suffix=`echo $includedir | sed "s|$prefix||"` -lib_suffix=`echo $libdir | sed "s|$exec_prefix||"` - - -usage() -{ - cat <&2 -fi - - -while test $# -gt 0 ; do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - ;; - *) - optarg= - ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - local_prefix=yes - ;; - --prefix) - echo_prefix=yes - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - local_prefix=yes - ;; - --exec-prefix) - echo_exec_prefix=yes - ;; - --version) - echo_version=yes - break - ;; - --ftversion) - echo_ft_version=yes - ;; - --cflags) - echo_cflags=yes - ;; - --libs) - echo_libs=yes - ;; - --libtool) - echo_libtool=yes - ;; - --static) - show_static=yes - ;; - --help) - usage 0 - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - - -if test "$local_prefix" = "yes" ; then - if test "$exec_prefix_set" != "yes" ; then - exec_prefix=$prefix - fi -fi - -if test "$local_prefix" = "yes" ; then - includedir=${prefix}${include_suffix} - if test "$exec_prefix_set" = "yes" ; then - libdir=${exec_prefix}${lib_suffix} - else - libdir=${prefix}${lib_suffix} - fi -fi - - -if test "$echo_version" = "yes" ; then - echo $version -fi - -if test "$echo_prefix" = "yes" ; then - echo ${SYSROOT}$prefix -fi - -if test "$echo_exec_prefix" = "yes" ; then - echo ${SYSROOT}$exec_prefix -fi - -if test "$echo_ft_version" = "yes" ; then - major=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MAJOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - minor=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MINOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - patch=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_PATCH \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - echo $major.$minor.$patch -fi - -if test "$echo_cflags" = "yes" ; then - echo $cflags | sed "s|$orig_includedir/freetype2|$includedir/freetype2|" -fi - -if test "$echo_libs" = "yes" ; then - if test "$show_static" = "yes" ; then - libs="$libs_L $static_libs" - else - libs="$libs_L $dynamic_libs" - fi - echo $libs | sed "s|$orig_libdir|$libdir|" -fi - -if test "$echo_libtool" = "yes" ; then - echo ${SYSROOT}$libdir/libfreetype.la -fi - -# EOF diff --git a/builds/unix/freetype-config.in.multilib b/builds/unix/freetype-config.in.multilib deleted file mode 100644 index 4d4d8d6..0000000 --- a/builds/unix/freetype-config.in.multilib +++ /dev/null @@ -1,211 +0,0 @@ -#! /bin/sh -# -# Copyright 2000-2017 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. - -LC_ALL=C -export LC_ALL - - -# if `pkg-config' is available, use values from `freetype2.pc' -pkg-config --version >/dev/null 2>&1 -if test $? -eq 0 ; then - # note that option `--variable' is not affected by the - # PKG_CONFIG_SYSROOT_DIR environment variable - if test "x$SYSROOT" != "x" ; then - PKG_CONFIG_SYSROOT_DIR="$SYSROOT" - export PKG_CONFIG_SYSROOT_DIR - fi - - prefix=`pkg-config --variable prefix freetype2` - exec_prefix=`pkg-config --variable exec_prefix freetype2` - - includedir=`pkg-config --variable includedir freetype2` - libdir=`pkg-config --variable libdir freetype2` - - version=`pkg-config --modversion freetype2` - - cflags=`pkg-config --cflags freetype2` - dynamic_libs=`pkg-config --libs freetype2` - static_libs=`pkg-config --static --libs freetype2` -else - prefix="%prefix%" - exec_prefix="%exec_prefix%" - - includedir="%includedir%" - libdir="%libdir%" - - version=%ft_version% - - cflags="-I${SYSROOT}$includedir/freetype2" - dynamic_libs="-lfreetype" - static_libs="%LIBSSTATIC_CONFIG%" - if test "${SYSROOT}$libdir" != "/usr/lib" && - test "${SYSROOT}$libdir" != "/usr/lib64" ; then - libs_L="-L${SYSROOT}$libdir" - fi -fi - -orig_prefix=$prefix -orig_exec_prefix=$exec_prefix - -orig_includedir=$includedir -orig_libdir=$libdir - -include_suffix=`echo $includedir | sed "s|$prefix||"` -lib_suffix=`echo $libdir | sed "s|$exec_prefix||"` - - -usage() -{ - cat <&2 -fi - - -while test $# -gt 0 ; do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - ;; - *) - optarg= - ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - local_prefix=yes - ;; - --prefix) - echo_prefix=yes - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - local_prefix=yes - ;; - --exec-prefix) - echo_exec_prefix=yes - ;; - --version) - echo_version=yes - break - ;; - --ftversion) - echo_ft_version=yes - ;; - --cflags) - echo_cflags=yes - ;; - --libs) - echo_libs=yes - ;; - --libtool) - echo_libtool=yes - ;; - --static) - show_static=yes - ;; - --help) - usage 0 - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - - -if test "$local_prefix" = "yes" ; then - if test "$exec_prefix_set" != "yes" ; then - exec_prefix=$prefix - fi -fi - -if test "$local_prefix" = "yes" ; then - includedir=${prefix}${include_suffix} - if test "$exec_prefix_set" = "yes" ; then - libdir=${exec_prefix}${lib_suffix} - else - libdir=${prefix}${lib_suffix} - fi -fi - - -if test "$echo_version" = "yes" ; then - echo $version -fi - -if test "$echo_prefix" = "yes" ; then - echo ${SYSROOT}$prefix -fi - -if test "$echo_exec_prefix" = "yes" ; then - echo ${SYSROOT}$exec_prefix -fi - -if test "$echo_ft_version" = "yes" ; then - major=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MAJOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - minor=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_MINOR \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - patch=`grep define ${SYSROOT}$includedir/freetype2/freetype/freetype.h \ - | grep FREETYPE_PATCH \ - | sed 's/.*[ ]\([0-9][0-9]*\).*/\1/'` - echo $major.$minor.$patch -fi - -if test "$echo_cflags" = "yes" ; then - echo $cflags | sed "s|$orig_includedir/freetype2|$includedir/freetype2|" -fi - -if test "$echo_libs" = "yes" ; then - if test "$show_static" = "yes" ; then - libs="$libs_L $static_libs" - else - libs="$libs_L $dynamic_libs" - fi - echo $libs | sed "s|$orig_libdir|$libdir|" -fi - -if test "$echo_libtool" = "yes" ; then - echo "" -fi - -# EOF diff --git a/include/freetype/ftmm.h b/include/freetype/ftmm.h index b1bc1ed..c41b80e 100644 --- a/include/freetype/ftmm.h +++ b/include/freetype/ftmm.h @@ -178,8 +178,7 @@ FT_BEGIN_HEADER /* strid :: The entry in `name' table identifying this instance. */ /* */ /* psid :: The entry in `name' table identifying a PostScript name */ - /* for this instance. Value 0xFFFF indicates a missing */ - /* entry. */ + /* for this instance. */ /* */ typedef struct FT_Var_Named_Style_ { diff --git a/include/freetype/ftmm.h.named-instances b/include/freetype/ftmm.h.named-instances deleted file mode 100644 index c41b80e..0000000 --- a/include/freetype/ftmm.h.named-instances +++ /dev/null @@ -1,490 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftmm.h */ -/* */ -/* FreeType Multiple Master font interface (specification). */ -/* */ -/* Copyright 1996-2017 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 FTMM_H_ -#define FTMM_H_ - - -#include -#include FT_TYPE1_TABLES_H - - -FT_BEGIN_HEADER - - - /*************************************************************************/ - /* */ - /*
*/ - /* multiple_masters */ - /* */ - /* */ - /* Multiple Masters */ - /* */ - /* <Abstract> */ - /* How to manage Multiple Masters fonts. */ - /* */ - /* <Description> */ - /* The following types and functions are used to manage Multiple */ - /* Master fonts, i.e., the selection of specific design instances by */ - /* setting design axis coordinates. */ - /* */ - /* Besides Adobe MM fonts, the interface supports Apple's TrueType GX */ - /* and OpenType variation fonts. Some of the routines only work with */ - /* Adobe MM fonts, others will work with all three types. They are */ - /* similar enough that a consistent interface makes sense. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_MM_Axis */ - /* */ - /* <Description> */ - /* A structure to model a given axis in design space for Multiple */ - /* Masters fonts. */ - /* */ - /* This structure can't be used for TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Fields> */ - /* name :: The axis's name. */ - /* */ - /* minimum :: The axis's minimum design coordinate. */ - /* */ - /* maximum :: The axis's maximum design coordinate. */ - /* */ - typedef struct FT_MM_Axis_ - { - FT_String* name; - FT_Long minimum; - FT_Long maximum; - - } FT_MM_Axis; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Multi_Master */ - /* */ - /* <Description> */ - /* A structure to model the axes and space of a Multiple Masters */ - /* font. */ - /* */ - /* This structure can't be used for TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Fields> */ - /* num_axis :: Number of axes. Cannot exceed~4. */ - /* */ - /* num_designs :: Number of designs; should be normally 2^num_axis */ - /* even though the Type~1 specification strangely */ - /* allows for intermediate designs to be present. */ - /* This number cannot exceed~16. */ - /* */ - /* axis :: A table of axis descriptors. */ - /* */ - typedef struct FT_Multi_Master_ - { - FT_UInt num_axis; - FT_UInt num_designs; - FT_MM_Axis axis[T1_MAX_MM_AXIS]; - - } FT_Multi_Master; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Var_Axis */ - /* */ - /* <Description> */ - /* A structure to model a given axis in design space for Multiple */ - /* Masters, TrueType GX, and OpenType variation fonts. */ - /* */ - /* <Fields> */ - /* name :: The axis's name. */ - /* Not always meaningful for TrueType GX or OpenType */ - /* variation fonts. */ - /* */ - /* minimum :: The axis's minimum design coordinate. */ - /* */ - /* def :: The axis's default design coordinate. */ - /* FreeType computes meaningful default values for Adobe */ - /* MM fonts. */ - /* */ - /* maximum :: The axis's maximum design coordinate. */ - /* */ - /* tag :: The axis's tag (the equivalent to `name' for TrueType */ - /* GX and OpenType variation fonts). FreeType provides */ - /* default values for Adobe MM fonts if possible. */ - /* */ - /* strid :: The axis name entry in the font's `name' table. This */ - /* is another (and often better) version of the `name' */ - /* field for TrueType GX or OpenType variation fonts. Not */ - /* meaningful for Adobe MM fonts. */ - /* */ - /* <Note> */ - /* The fields `minimum', `def', and `maximum' are 16.16 fractional */ - /* values for TrueType GX and OpenType variation fonts. For Adobe MM */ - /* fonts, the values are integers. */ - /* */ - typedef struct FT_Var_Axis_ - { - FT_String* name; - - FT_Fixed minimum; - FT_Fixed def; - FT_Fixed maximum; - - FT_ULong tag; - FT_UInt strid; - - } FT_Var_Axis; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Var_Named_Style */ - /* */ - /* <Description> */ - /* A structure to model a named instance in a TrueType GX or OpenType */ - /* variation font. */ - /* */ - /* This structure can't be used for Adobe MM fonts. */ - /* */ - /* <Fields> */ - /* coords :: The design coordinates for this instance. */ - /* This is an array with one entry for each axis. */ - /* */ - /* strid :: The entry in `name' table identifying this instance. */ - /* */ - /* psid :: The entry in `name' table identifying a PostScript name */ - /* for this instance. */ - /* */ - typedef struct FT_Var_Named_Style_ - { - FT_Fixed* coords; - FT_UInt strid; - FT_UInt psid; /* since 2.7.1 */ - - } FT_Var_Named_Style; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_MM_Var */ - /* */ - /* <Description> */ - /* A structure to model the axes and space of a Adobe MM, TrueType */ - /* GX, or OpenType variation font. */ - /* */ - /* Some fields are specific to one format and not to the others. */ - /* */ - /* <Fields> */ - /* num_axis :: The number of axes. The maximum value is~4 for */ - /* Adobe MM fonts; no limit in TrueType GX or */ - /* OpenType variation fonts. */ - /* */ - /* num_designs :: The number of designs; should be normally */ - /* 2^num_axis for Adobe MM fonts. Not meaningful */ - /* for TrueType GX or OpenType variation fonts */ - /* (where every glyph could have a different */ - /* number of designs). */ - /* */ - /* num_namedstyles :: The number of named styles; a `named style' is */ - /* a tuple of design coordinates that has a string */ - /* ID (in the `name' table) associated with it. */ - /* The font can tell the user that, for example, */ - /* [Weight=1.5,Width=1.1] is `Bold'. Another name */ - /* for `named style' is `named instance'. */ - /* */ - /* For Adobe Multiple Masters fonts, this value is */ - /* always zero because the format does not support */ - /* named styles. */ - /* */ - /* axis :: An axis descriptor table. */ - /* TrueType GX and OpenType variation fonts */ - /* contain slightly more data than Adobe MM fonts. */ - /* Memory management of this pointer is done */ - /* internally by FreeType. */ - /* */ - /* namedstyle :: A named style (instance) table. */ - /* Only meaningful for TrueType GX and OpenType */ - /* variation fonts. Memory management of this */ - /* pointer is done internally by FreeType. */ - /* */ - typedef struct FT_MM_Var_ - { - FT_UInt num_axis; - FT_UInt num_designs; - FT_UInt num_namedstyles; - FT_Var_Axis* axis; - FT_Var_Named_Style* namedstyle; - - } FT_MM_Var; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Multi_Master */ - /* */ - /* <Description> */ - /* Retrieve a variation descriptor of a given Adobe MM font. */ - /* */ - /* This function can't be used with TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* <Output> */ - /* amaster :: The Multiple Masters descriptor. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Multi_Master( FT_Face face, - FT_Multi_Master *amaster ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_MM_Var */ - /* */ - /* <Description> */ - /* Retrieve a variation descriptor for a given font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* <Output> */ - /* amaster :: The variation descriptor. */ - /* Allocates a data structure, which the user must */ - /* deallocate with `free' after use. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_MM_Var( FT_Face face, - FT_MM_Var* *amaster ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_MM_Design_Coordinates */ - /* */ - /* <Description> */ - /* For Adobe MM fonts, choose an interpolated font design through */ - /* design coordinates. */ - /* */ - /* This function can't be used with TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: An array of design coordinates. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_MM_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Long* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_Var_Design_Coordinates */ - /* */ - /* <Description> */ - /* Choose an interpolated font design through design coordinates. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: An array of design coordinates. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Var_Design_Coordinates */ - /* */ - /* <Description> */ - /* Get the design coordinates of the currently selected interpolated */ - /* font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of design coordinates to retrieve. If it */ - /* is larger than the number of axes, set the excess */ - /* values to~0. */ - /* */ - /* <Output> */ - /* coords :: The design coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_MM_Blend_Coordinates */ - /* */ - /* <Description> */ - /* Choose an interpolated font design through normalized blend */ - /* coordinates. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: The design coordinates array (each element must be */ - /* between 0 and 1.0 for Adobe MM fonts, and between */ - /* -1.0 and 1.0 for TrueType GX and OpenType variation */ - /* fonts). */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_MM_Blend_Coordinates */ - /* */ - /* <Description> */ - /* Get the normalized blend coordinates of the currently selected */ - /* interpolated font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of normalized blend coordinates to */ - /* retrieve. If it is larger than the number of axes, */ - /* set the excess values to~0.5 for Adobe MM fonts, and */ - /* to~0 for TrueType GX and OpenType variation fonts. */ - /* */ - /* <Output> */ - /* coords :: The normalized blend coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_Var_Blend_Coordinates */ - /* */ - /* <Description> */ - /* This is another name of @FT_Set_MM_Blend_Coordinates. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Var_Blend_Coordinates */ - /* */ - /* <Description> */ - /* This is another name of @FT_Get_MM_Blend_Coordinates. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - /* */ - - -FT_END_HEADER - -#endif /* FTMM_H_ */ - - -/* END */ diff --git a/include/freetype/ftmm.h.named-instances2 b/include/freetype/ftmm.h.named-instances2 deleted file mode 100644 index 1f48a49..0000000 --- a/include/freetype/ftmm.h.named-instances2 +++ /dev/null @@ -1,490 +0,0 @@ -/***************************************************************************/ -/* */ -/* ftmm.h */ -/* */ -/* FreeType Multiple Master font interface (specification). */ -/* */ -/* Copyright 1996-2017 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 FTMM_H_ -#define FTMM_H_ - - -#include <ft2build.h> -#include FT_TYPE1_TABLES_H - - -FT_BEGIN_HEADER - - - /*************************************************************************/ - /* */ - /* <Section> */ - /* multiple_masters */ - /* */ - /* <Title> */ - /* Multiple Masters */ - /* */ - /* <Abstract> */ - /* How to manage Multiple Masters fonts. */ - /* */ - /* <Description> */ - /* The following types and functions are used to manage Multiple */ - /* Master fonts, i.e., the selection of specific design instances by */ - /* setting design axis coordinates. */ - /* */ - /* Besides Adobe MM fonts, the interface supports Apple's TrueType GX */ - /* and OpenType variation fonts. Some of the routines only work with */ - /* Adobe MM fonts, others will work with all three types. They are */ - /* similar enough that a consistent interface makes sense. */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_MM_Axis */ - /* */ - /* <Description> */ - /* A structure to model a given axis in design space for Multiple */ - /* Masters fonts. */ - /* */ - /* This structure can't be used for TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Fields> */ - /* name :: The axis's name. */ - /* */ - /* minimum :: The axis's minimum design coordinate. */ - /* */ - /* maximum :: The axis's maximum design coordinate. */ - /* */ - typedef struct FT_MM_Axis_ - { - FT_String* name; - FT_Long minimum; - FT_Long maximum; - - } FT_MM_Axis; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Multi_Master */ - /* */ - /* <Description> */ - /* A structure to model the axes and space of a Multiple Masters */ - /* font. */ - /* */ - /* This structure can't be used for TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Fields> */ - /* num_axis :: Number of axes. Cannot exceed~4. */ - /* */ - /* num_designs :: Number of designs; should be normally 2^num_axis */ - /* even though the Type~1 specification strangely */ - /* allows for intermediate designs to be present. */ - /* This number cannot exceed~16. */ - /* */ - /* axis :: A table of axis descriptors. */ - /* */ - typedef struct FT_Multi_Master_ - { - FT_UInt num_axis; - FT_UInt num_designs; - FT_MM_Axis axis[T1_MAX_MM_AXIS]; - - } FT_Multi_Master; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Var_Axis */ - /* */ - /* <Description> */ - /* A structure to model a given axis in design space for Multiple */ - /* Masters, TrueType GX, and OpenType variation fonts. */ - /* */ - /* <Fields> */ - /* name :: The axis's name. */ - /* Not always meaningful for TrueType GX or OpenType */ - /* variation fonts. */ - /* */ - /* minimum :: The axis's minimum design coordinate. */ - /* */ - /* def :: The axis's default design coordinate. */ - /* FreeType computes meaningful default values for Adobe */ - /* MM fonts. */ - /* */ - /* maximum :: The axis's maximum design coordinate. */ - /* */ - /* tag :: The axis's tag (the equivalent to `name' for TrueType */ - /* GX and OpenType variation fonts). FreeType provides */ - /* default values for Adobe MM fonts if possible. */ - /* */ - /* strid :: The axis name entry in the font's `name' table. This */ - /* is another (and often better) version of the `name' */ - /* field for TrueType GX or OpenType variation fonts. Not */ - /* meaningful for Adobe MM fonts. */ - /* */ - /* <Note> */ - /* The fields `minimum', `def', and `maximum' are 16.16 fractional */ - /* values for TrueType GX and OpenType variation fonts. For Adobe MM */ - /* fonts, the values are integers. */ - /* */ - typedef struct FT_Var_Axis_ - { - FT_String* name; - - FT_Fixed minimum; - FT_Fixed def; - FT_Fixed maximum; - - FT_ULong tag; - FT_UInt strid; - - } FT_Var_Axis; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_Var_Named_Style */ - /* */ - /* <Description> */ - /* A structure to model a named instance in a TrueType GX or OpenType */ - /* variation font. */ - /* */ - /* This structure can't be used for Adobe MM fonts. */ - /* */ - /* <Fields> */ - /* coords :: The design coordinates for this instance. */ - /* This is an array with one entry for each axis. */ - /* */ - /* strid :: The entry in `name' table identifying this instance. */ - /* */ - /* psid :: The entry in `name' table identifying a PostScript name */ - /* for this instance. Value 0 indicates a missing entry. */ - /* */ - typedef struct FT_Var_Named_Style_ - { - FT_Fixed* coords; - FT_UInt strid; - FT_UInt psid; /* since 2.7.1 */ - - } FT_Var_Named_Style; - - - /*************************************************************************/ - /* */ - /* <Struct> */ - /* FT_MM_Var */ - /* */ - /* <Description> */ - /* A structure to model the axes and space of a Adobe MM, TrueType */ - /* GX, or OpenType variation font. */ - /* */ - /* Some fields are specific to one format and not to the others. */ - /* */ - /* <Fields> */ - /* num_axis :: The number of axes. The maximum value is~4 for */ - /* Adobe MM fonts; no limit in TrueType GX or */ - /* OpenType variation fonts. */ - /* */ - /* num_designs :: The number of designs; should be normally */ - /* 2^num_axis for Adobe MM fonts. Not meaningful */ - /* for TrueType GX or OpenType variation fonts */ - /* (where every glyph could have a different */ - /* number of designs). */ - /* */ - /* num_namedstyles :: The number of named styles; a `named style' is */ - /* a tuple of design coordinates that has a string */ - /* ID (in the `name' table) associated with it. */ - /* The font can tell the user that, for example, */ - /* [Weight=1.5,Width=1.1] is `Bold'. Another name */ - /* for `named style' is `named instance'. */ - /* */ - /* For Adobe Multiple Masters fonts, this value is */ - /* always zero because the format does not support */ - /* named styles. */ - /* */ - /* axis :: An axis descriptor table. */ - /* TrueType GX and OpenType variation fonts */ - /* contain slightly more data than Adobe MM fonts. */ - /* Memory management of this pointer is done */ - /* internally by FreeType. */ - /* */ - /* namedstyle :: A named style (instance) table. */ - /* Only meaningful for TrueType GX and OpenType */ - /* variation fonts. Memory management of this */ - /* pointer is done internally by FreeType. */ - /* */ - typedef struct FT_MM_Var_ - { - FT_UInt num_axis; - FT_UInt num_designs; - FT_UInt num_namedstyles; - FT_Var_Axis* axis; - FT_Var_Named_Style* namedstyle; - - } FT_MM_Var; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Multi_Master */ - /* */ - /* <Description> */ - /* Retrieve a variation descriptor of a given Adobe MM font. */ - /* */ - /* This function can't be used with TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* <Output> */ - /* amaster :: The Multiple Masters descriptor. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Multi_Master( FT_Face face, - FT_Multi_Master *amaster ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_MM_Var */ - /* */ - /* <Description> */ - /* Retrieve a variation descriptor for a given font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* <Output> */ - /* amaster :: The variation descriptor. */ - /* Allocates a data structure, which the user must */ - /* deallocate with `free' after use. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_MM_Var( FT_Face face, - FT_MM_Var* *amaster ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_MM_Design_Coordinates */ - /* */ - /* <Description> */ - /* For Adobe MM fonts, choose an interpolated font design through */ - /* design coordinates. */ - /* */ - /* This function can't be used with TrueType GX or OpenType variation */ - /* fonts. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: An array of design coordinates. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_MM_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Long* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_Var_Design_Coordinates */ - /* */ - /* <Description> */ - /* Choose an interpolated font design through design coordinates. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: An array of design coordinates. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Var_Design_Coordinates */ - /* */ - /* <Description> */ - /* Get the design coordinates of the currently selected interpolated */ - /* font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of design coordinates to retrieve. If it */ - /* is larger than the number of axes, set the excess */ - /* values to~0. */ - /* */ - /* <Output> */ - /* coords :: The design coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Var_Design_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_MM_Blend_Coordinates */ - /* */ - /* <Description> */ - /* Choose an interpolated font design through normalized blend */ - /* coordinates. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <InOut> */ - /* face :: A handle to the source face. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available design coordinates. If it */ - /* is larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use default values for the remaining axes. */ - /* */ - /* coords :: The design coordinates array (each element must be */ - /* between 0 and 1.0 for Adobe MM fonts, and between */ - /* -1.0 and 1.0 for TrueType GX and OpenType variation */ - /* fonts). */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_MM_Blend_Coordinates */ - /* */ - /* <Description> */ - /* Get the normalized blend coordinates of the currently selected */ - /* interpolated font. */ - /* */ - /* This function works with all supported variation formats. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of normalized blend coordinates to */ - /* retrieve. If it is larger than the number of axes, */ - /* set the excess values to~0.5 for Adobe MM fonts, and */ - /* to~0 for TrueType GX and OpenType variation fonts. */ - /* */ - /* <Output> */ - /* coords :: The normalized blend coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_MM_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Set_Var_Blend_Coordinates */ - /* */ - /* <Description> */ - /* This is another name of @FT_Set_MM_Blend_Coordinates. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Set_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* FT_Get_Var_Blend_Coordinates */ - /* */ - /* <Description> */ - /* This is another name of @FT_Get_MM_Blend_Coordinates. */ - /* */ - FT_EXPORT( FT_Error ) - FT_Get_Var_Blend_Coordinates( FT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ); - - /* */ - - -FT_END_HEADER - -#endif /* FTMM_H_ */ - - -/* END */ diff --git a/modules.cfg b/modules.cfg index 64b2a34..517111e 100644 --- a/modules.cfg +++ b/modules.cfg @@ -120,7 +120,7 @@ AUX_MODULES += cache # TrueType GX/AAT table validation. Needs ftgxval.c below. # # No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += gxvalid +# AUX_MODULES += gxvalid # Support for streams compressed with gzip (files with suffix .gz). # @@ -143,7 +143,7 @@ AUX_MODULES += bzip2 # OpenType table validation. Needs ftotval.c below. # # No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += otvalid +# AUX_MODULES += otvalid # Auxiliary PostScript driver component to share common code. # diff --git a/modules.cfg.enable-valid b/modules.cfg.enable-valid deleted file mode 100644 index 517111e..0000000 --- a/modules.cfg.enable-valid +++ /dev/null @@ -1,270 +0,0 @@ -# modules.cfg -# -# Copyright 2005-2017 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. -# -# -# In case you compile the FreeType library with GNU make or makepp, this -# file controls which components are built into the library. Otherwise, -# please read this file for information on the various modules and its -# dependencies, then follow the instructions in the file `docs/INSTALL.ANY'. -# -# To deactivate a module, simply comment out the corresponding line. To -# activate a module, remove the comment character. -# -# Note that many modules and components are further controlled with macros -# in the file `include/freetype/config/ftoption.h'. - - -#### -#### font modules -- at least one is required -#### -#### The order given here (from top to down) is the order used for testing -#### font formats in the compiled library. -#### - -# TrueType font driver. -# -# This driver needs the `sfnt' module. -FONT_MODULES += truetype - -# PostScript Type 1 font driver. -# -# This driver needs the `psaux', `pshinter', and `psnames' modules. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += type1 - -# CFF/OpenType font driver. -# -# This driver needs the `sfnt', `pshinter', and `psnames' modules. -FONT_MODULES += cff - -# Type 1 CID-keyed font driver. -# -# This driver needs the `psaux', `pshinter', and `psnames' modules. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += cid - -# PFR/TrueDoc font driver. See optional extension ftpfr.c below also. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += pfr - -# PostScript Type 42 font driver. -# -# This driver needs the `truetype' and `psaux' modules. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += type42 - -# Windows FONT/FNT font driver. See optional extension ftwinfnt.c below -# also. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += winfonts - -# PCF font driver. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += pcf - -# BDF font driver. See optional extension ftbdf.c below also. -# No FT_CONFIG_OPTION_PIC support. -FONT_MODULES += bdf - -# SFNT files support. If used without `truetype' or `cff', it supports -# bitmap-only fonts within an SFNT wrapper. -# -# This driver needs the `psnames' module. -FONT_MODULES += sfnt - - -#### -#### hinting modules -#### - -# FreeType's auto hinter. -HINTING_MODULES += autofit - -# PostScript hinter. -HINTING_MODULES += pshinter - -# The TrueType hinting engine doesn't have a module of its own but is -# controlled in file include/freetype/config/ftoption.h -# (TT_CONFIG_OPTION_BYTECODE_INTERPRETER and friends). - - -#### -#### raster modules -- at least one is required for vector font formats -#### - -# Monochrome rasterizer. -RASTER_MODULES += raster - -# Anti-aliasing rasterizer. -RASTER_MODULES += smooth - - -#### -#### auxiliary modules -#### - -# FreeType's cache sub-system (quite stable but still in beta -- this means -# that its public API is subject to change if necessary). See -# include/freetype/ftcache.h. Needs ftglyph.c. -# No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += cache - -# TrueType GX/AAT table validation. Needs ftgxval.c below. -# -# No FT_CONFIG_OPTION_PIC support. -# AUX_MODULES += gxvalid - -# Support for streams compressed with gzip (files with suffix .gz). -# -# See include/freetype/ftgzip.h for the API. -# No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += gzip - -# Support for streams compressed with LZW (files with suffix .Z). -# -# See include/freetype/ftlzw.h for the API. -# No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += lzw - -# Support for streams compressed with bzip2 (files with suffix .bz2). -# -# See include/freetype/ftbzip2.h for the API. -# No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += bzip2 - -# OpenType table validation. Needs ftotval.c below. -# -# No FT_CONFIG_OPTION_PIC support. -# AUX_MODULES += otvalid - -# Auxiliary PostScript driver component to share common code. -# -# This module depends on `psnames'. -# No FT_CONFIG_OPTION_PIC support. -AUX_MODULES += psaux - -# Support for PostScript glyph names. -# -# This module can be controlled in ftconfig.h -# (FT_CONFIG_OPTION_POSTSCRIPT_NAMES). -AUX_MODULES += psnames - - -#### -#### base module extensions -#### - -# Exact bounding box calculation. -# -# See include/freetype/ftbbox.h for the API. -BASE_EXTENSIONS += ftbbox.c - -# Access BDF-specific strings. Needs BDF font driver. -# -# See include/freetype/ftbdf.h for the API. -BASE_EXTENSIONS += ftbdf.c - -# Utility functions for converting 1bpp, 2bpp, 4bpp, and 8bpp bitmaps into -# 8bpp format, and for emboldening of bitmap glyphs. -# -# See include/freetype/ftbitmap.h for the API. -BASE_EXTENSIONS += ftbitmap.c - -# Access CID font information. -# -# See include/freetype/ftcid.h for the API. -BASE_EXTENSIONS += ftcid.c - -# Support functions for font formats. -# -# See include/freetype/ftfntfmt.h for the API. -BASE_EXTENSIONS += ftfntfmt.c - -# Access FSType information. Needs fttype1.c. -# -# See include/freetype/freetype.h for the API. -BASE_EXTENSIONS += ftfstype.c - -# Support for GASP table queries. -# -# See include/freetype/ftgasp.h for the API. -BASE_EXTENSIONS += ftgasp.c - -# Convenience functions to handle glyphs. Needs ftbitmap.c. -# -# See include/freetype/ftglyph.h for the API. -BASE_EXTENSIONS += ftglyph.c - -# Interface for gxvalid module. -# -# See include/freetype/ftgxval.h for the API. -BASE_EXTENSIONS += ftgxval.c - -# Support for LCD color filtering of subpixel bitmaps. -# -# See include/freetype/ftlcdfil.h for the API. -BASE_EXTENSIONS += ftlcdfil.c - -# Multiple Master font interface. -# -# See include/freetype/ftmm.h for the API. -BASE_EXTENSIONS += ftmm.c - -# Interface for otvalid module. -# -# See include/freetype/ftotval.h for the API. -BASE_EXTENSIONS += ftotval.c - -# Support for FT_Face_CheckTrueTypePatents. -# -# See include/freetype/freetype.h for the API. -BASE_EXTENSIONS += ftpatent.c - -# Interface for accessing PFR-specific data. Needs PFR font driver. -# -# See include/freetype/ftpfr.h for the API. -BASE_EXTENSIONS += ftpfr.c - -# Path stroker. Needs ftglyph.c. -# -# See include/freetype/ftstroke.h for the API. -BASE_EXTENSIONS += ftstroke.c - -# Support for synthetic emboldening and slanting of fonts. Needs ftbitmap.c. -# -# See include/freetype/ftsynth.h for the API. -BASE_EXTENSIONS += ftsynth.c - -# Interface to access data specific to PostScript Type 1 and Type 2 (CFF) -# fonts. -# -# See include/freetype/t1tables.h for the API. -BASE_EXTENSIONS += fttype1.c - -# Interface for accessing data specific to Windows FNT files. Needs winfnt -# driver. -# -# See include/freetype/ftwinfnt.h for the API. -BASE_EXTENSIONS += ftwinfnt.c - -#### -#### The components `ftsystem.c' (for memory allocation and stream I/O -#### management) and `ftdebug.c' (for emitting debug messages to the user) -#### are controlled with the following variables. -#### -#### ftsystem.c: $(FTSYS_SRC) -#### ftdebug.c: $(FTDEBUG_SRC) -#### -#### Please refer to docs/CUSTOMIZE for details. -#### - - -# EOF diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c index c0a5a5c..a2242be 100644 --- a/src/bdf/bdfdrivr.c +++ b/src/bdf/bdfdrivr.c @@ -545,11 +545,7 @@ THE SOFTWARE. if ( !ft_strcmp( s, "10646" ) || ( !ft_strcmp( s, "8859" ) && !ft_strcmp( face->charset_encoding, "1" ) ) ) - unicode_charmap = 1; - /* another name for ASCII */ - else if ( !ft_strcmp( s, "646.1991" ) && - !ft_strcmp( face->charset_encoding, "IRV" ) ) - unicode_charmap = 1; + unicode_charmap = 1; } { diff --git a/src/bdf/bdfdrivr.c.pcf-encoding b/src/bdf/bdfdrivr.c.pcf-encoding deleted file mode 100644 index a2242be..0000000 --- a/src/bdf/bdfdrivr.c.pcf-encoding +++ /dev/null @@ -1,898 +0,0 @@ -/* bdfdrivr.c - - FreeType font driver for bdf files - - Copyright (C) 2001-2008, 2011, 2013, 2014 by - Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#include <ft2build.h> - -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_OBJECTS_H -#include FT_BDF_H -#include FT_TRUETYPE_IDS_H - -#include FT_SERVICE_BDF_H -#include FT_SERVICE_FONT_FORMAT_H - -#include "bdf.h" -#include "bdfdrivr.h" - -#include "bdferror.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_bdfdriver - - - typedef struct BDF_CMapRec_ - { - FT_CMapRec cmap; - FT_ULong num_encodings; /* ftobjs.h: FT_CMap->clazz->size */ - BDF_encoding_el* encodings; - - } BDF_CMapRec, *BDF_CMap; - - - FT_CALLBACK_DEF( FT_Error ) - bdf_cmap_init( FT_CMap bdfcmap, - FT_Pointer init_data ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - BDF_Face face = (BDF_Face)FT_CMAP_FACE( cmap ); - FT_UNUSED( init_data ); - - - cmap->num_encodings = face->bdffont->glyphs_used; - cmap->encodings = face->en_table; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( void ) - bdf_cmap_done( FT_CMap bdfcmap ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - - - cmap->encodings = NULL; - cmap->num_encodings = 0; - } - - - FT_CALLBACK_DEF( FT_UInt ) - bdf_cmap_char_index( FT_CMap bdfcmap, - FT_UInt32 charcode ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - BDF_encoding_el* encodings = cmap->encodings; - FT_ULong min, max, mid; /* num_encodings */ - FT_UShort result = 0; /* encodings->glyph */ - - - min = 0; - max = cmap->num_encodings; - - while ( min < max ) - { - FT_ULong code; - - - mid = ( min + max ) >> 1; - code = (FT_ULong)encodings[mid].enc; - - if ( charcode == code ) - { - /* increase glyph index by 1 -- */ - /* we reserve slot 0 for the undefined glyph */ - result = encodings[mid].glyph + 1; - break; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - } - - return result; - } - - - FT_CALLBACK_DEF( FT_UInt ) - bdf_cmap_char_next( FT_CMap bdfcmap, - FT_UInt32 *acharcode ) - { - BDF_CMap cmap = (BDF_CMap)bdfcmap; - BDF_encoding_el* encodings = cmap->encodings; - FT_ULong min, max, mid; /* num_encodings */ - FT_UShort result = 0; /* encodings->glyph */ - FT_ULong charcode = *acharcode + 1; - - - min = 0; - max = cmap->num_encodings; - - while ( min < max ) - { - FT_ULong code; /* same as BDF_encoding_el.enc */ - - - mid = ( min + max ) >> 1; - code = (FT_ULong)encodings[mid].enc; - - if ( charcode == code ) - { - /* increase glyph index by 1 -- */ - /* we reserve slot 0 for the undefined glyph */ - result = encodings[mid].glyph + 1; - goto Exit; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - } - - charcode = 0; - if ( min < cmap->num_encodings ) - { - charcode = (FT_ULong)encodings[min].enc; - result = encodings[min].glyph + 1; - } - - Exit: - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "bdf_cmap_char_next: charcode 0x%x > 32bit API" )); - *acharcode = 0; - /* XXX: result should be changed to indicate an overflow error */ - } - else - *acharcode = (FT_UInt32)charcode; - return result; - } - - - static - const FT_CMap_ClassRec bdf_cmap_class = - { - sizeof ( BDF_CMapRec ), - bdf_cmap_init, - bdf_cmap_done, - bdf_cmap_char_index, - bdf_cmap_char_next, - - NULL, NULL, NULL, NULL, NULL - }; - - - static FT_Error - bdf_interpret_style( BDF_Face bdf ) - { - FT_Error error = FT_Err_Ok; - FT_Face face = FT_FACE( bdf ); - FT_Memory memory = face->memory; - bdf_font_t* font = bdf->bdffont; - bdf_property_t* prop; - - char* strings[4] = { NULL, NULL, NULL, NULL }; - size_t nn, len, lengths[4]; - - - face->style_flags = 0; - - prop = bdf_get_font_property( font, (char *)"SLANT" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && - ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' || - *(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) ) - { - face->style_flags |= FT_STYLE_FLAG_ITALIC; - strings[2] = ( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ) - ? (char *)"Oblique" - : (char *)"Italic"; - } - - prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && - ( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) ) - { - face->style_flags |= FT_STYLE_FLAG_BOLD; - strings[1] = (char *)"Bold"; - } - - prop = bdf_get_font_property( font, (char *)"SETWIDTH_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && *(prop->value.atom) && - !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - strings[3] = (char *)(prop->value.atom); - - prop = bdf_get_font_property( font, (char *)"ADD_STYLE_NAME" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && *(prop->value.atom) && - !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) - strings[0] = (char *)(prop->value.atom); - - for ( len = 0, nn = 0; nn < 4; nn++ ) - { - lengths[nn] = 0; - if ( strings[nn] ) - { - lengths[nn] = ft_strlen( strings[nn] ); - len += lengths[nn] + 1; - } - } - - if ( len == 0 ) - { - strings[0] = (char *)"Regular"; - lengths[0] = ft_strlen( strings[0] ); - len = lengths[0] + 1; - } - - { - char* s; - - - if ( FT_ALLOC( face->style_name, len ) ) - return error; - - s = face->style_name; - - for ( nn = 0; nn < 4; nn++ ) - { - char* src = strings[nn]; - - - len = lengths[nn]; - - if ( !src ) - continue; - - /* separate elements with a space */ - if ( s != face->style_name ) - *s++ = ' '; - - ft_memcpy( s, src, len ); - - /* need to convert spaces to dashes for */ - /* add_style_name and setwidth_name */ - if ( nn == 0 || nn == 3 ) - { - size_t mm; - - - for ( mm = 0; mm < len; mm++ ) - if ( s[mm] == ' ' ) - s[mm] = '-'; - } - - s += len; - } - *s = 0; - } - - return error; - } - - - FT_CALLBACK_DEF( void ) - BDF_Face_Done( FT_Face bdfface ) /* BDF_Face */ - { - BDF_Face face = (BDF_Face)bdfface; - FT_Memory memory; - - - if ( !face ) - return; - - memory = FT_FACE_MEMORY( face ); - - bdf_free_font( face->bdffont ); - - FT_FREE( face->en_table ); - - FT_FREE( face->charset_encoding ); - FT_FREE( face->charset_registry ); - FT_FREE( bdfface->family_name ); - FT_FREE( bdfface->style_name ); - - FT_FREE( bdfface->available_sizes ); - - FT_FREE( face->bdffont ); - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Face_Init( FT_Stream stream, - FT_Face bdfface, /* BDF_Face */ - FT_Int face_index, - FT_Int num_params, - FT_Parameter* params ) - { - FT_Error error = FT_Err_Ok; - BDF_Face face = (BDF_Face)bdfface; - FT_Memory memory = FT_FACE_MEMORY( face ); - - bdf_font_t* font = NULL; - bdf_options_t options; - - FT_UNUSED( num_params ); - FT_UNUSED( params ); - - - FT_TRACE2(( "BDF driver\n" )); - - if ( FT_STREAM_SEEK( 0 ) ) - goto Exit; - - options.correct_metrics = 1; /* FZ XXX: options semantics */ - options.keep_unencoded = 1; - options.keep_comments = 0; - options.font_spacing = BDF_PROPORTIONAL; - - error = bdf_load_font( stream, memory, &options, &font ); - if ( FT_ERR_EQ( error, Missing_Startfont_Field ) ) - { - FT_TRACE2(( " not a BDF file\n" )); - goto Fail; - } - else if ( error ) - goto Exit; - - /* 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 && ( face_index & 0xFFFF ) > 0 ) - { - FT_ERROR(( "BDF_Face_Init: invalid face index\n" )); - BDF_Face_Done( bdfface ); - return FT_THROW( Invalid_Argument ); - } - - { - bdf_property_t* prop = NULL; - - - FT_TRACE4(( " number of glyphs: allocated %d (used %d)\n", - font->glyphs_size, - font->glyphs_used )); - FT_TRACE4(( " number of unencoded glyphs: allocated %d (used %d)\n", - font->unencoded_size, - font->unencoded_used )); - - 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; - - prop = bdf_get_font_property( font, "SPACING" ); - if ( prop && prop->format == BDF_ATOM && - prop->value.atom && - ( *(prop->value.atom) == 'M' || *(prop->value.atom) == 'm' || - *(prop->value.atom) == 'C' || *(prop->value.atom) == 'c' ) ) - bdfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; - - /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL */ - /* FZ XXX: I need a font to implement this */ - - prop = bdf_get_font_property( font, "FAMILY_NAME" ); - if ( prop && prop->value.atom ) - { - if ( FT_STRDUP( bdfface->family_name, prop->value.atom ) ) - goto Exit; - } - else - bdfface->family_name = NULL; - - if ( FT_SET_ERROR( bdf_interpret_style( face ) ) ) - goto Exit; - - /* the number of glyphs (with one slot for the undefined glyph */ - /* at position 0 and all unencoded glyphs) */ - bdfface->num_glyphs = (FT_Long)( font->glyphs_size + 1 ); - - bdfface->num_fixed_sizes = 1; - if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) ) - goto Exit; - - { - FT_Bitmap_Size* bsize = bdfface->available_sizes; - FT_Short resolution_x = 0, resolution_y = 0; - - - FT_ZERO( bsize ); - - bsize->height = (FT_Short)( font->font_ascent + font->font_descent ); - - prop = bdf_get_font_property( font, "AVERAGE_WIDTH" ); - if ( prop ) - bsize->width = (FT_Short)( ( prop->value.l + 5 ) / 10 ); - else - bsize->width = (FT_Short)( bsize->height * 2/3 ); - - prop = bdf_get_font_property( font, "POINT_SIZE" ); - if ( prop ) - /* convert from 722.7 decipoints to 72 points per inch */ - bsize->size = - (FT_Pos)( ( prop->value.l * 64 * 7200 + 36135L ) / 72270L ); - else - bsize->size = bsize->width << 6; - - prop = bdf_get_font_property( font, "PIXEL_SIZE" ); - if ( prop ) - bsize->y_ppem = (FT_Short)prop->value.l << 6; - - prop = bdf_get_font_property( font, "RESOLUTION_X" ); - if ( prop ) - resolution_x = (FT_Short)prop->value.l; - - prop = bdf_get_font_property( font, "RESOLUTION_Y" ); - if ( prop ) - resolution_y = (FT_Short)prop->value.l; - - if ( bsize->y_ppem == 0 ) - { - bsize->y_ppem = bsize->size; - if ( resolution_y ) - bsize->y_ppem = bsize->y_ppem * resolution_y / 72; - } - if ( resolution_x && resolution_y ) - bsize->x_ppem = bsize->y_ppem * resolution_x / resolution_y; - else - bsize->x_ppem = bsize->y_ppem; - } - - /* encoding table */ - { - bdf_glyph_t* cur = font->glyphs; - unsigned long n; - - - if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) ) - goto Exit; - - face->default_glyph = 0; - for ( n = 0; n < font->glyphs_size; n++ ) - { - (face->en_table[n]).enc = cur[n].encoding; - FT_TRACE4(( " idx %d, val 0x%lX\n", n, cur[n].encoding )); - (face->en_table[n]).glyph = (FT_UShort)n; - - if ( cur[n].encoding == font->default_char ) - { - if ( n < FT_UINT_MAX ) - face->default_glyph = (FT_UInt)n; - else - FT_TRACE1(( "BDF_Face_Init:" - " idx %d is too large for this system\n", n )); - } - } - } - - /* charmaps */ - { - bdf_property_t *charset_registry, *charset_encoding; - FT_Bool unicode_charmap = 0; - - - charset_registry = - bdf_get_font_property( font, "CHARSET_REGISTRY" ); - charset_encoding = - bdf_get_font_property( font, "CHARSET_ENCODING" ); - if ( charset_registry && charset_encoding ) - { - if ( charset_registry->format == BDF_ATOM && - charset_encoding->format == BDF_ATOM && - charset_registry->value.atom && - charset_encoding->value.atom ) - { - const char* s; - - - if ( FT_STRDUP( face->charset_encoding, - charset_encoding->value.atom ) || - FT_STRDUP( face->charset_registry, - charset_registry->value.atom ) ) - goto Exit; - - /* Uh, oh, compare first letters manually to avoid dependency */ - /* on locales. */ - s = face->charset_registry; - if ( ( s[0] == 'i' || s[0] == 'I' ) && - ( s[1] == 's' || s[1] == 'S' ) && - ( s[2] == 'o' || s[2] == 'O' ) ) - { - s += 3; - if ( !ft_strcmp( s, "10646" ) || - ( !ft_strcmp( s, "8859" ) && - !ft_strcmp( face->charset_encoding, "1" ) ) ) - unicode_charmap = 1; - } - - { - FT_CharMapRec charmap; - - - charmap.face = FT_FACE( face ); - charmap.encoding = FT_ENCODING_NONE; - /* initial platform/encoding should indicate unset status? */ - charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; - charmap.encoding_id = TT_APPLE_ID_DEFAULT; - - if ( unicode_charmap ) - { - charmap.encoding = FT_ENCODING_UNICODE; - charmap.platform_id = TT_PLATFORM_MICROSOFT; - charmap.encoding_id = TT_MS_ID_UNICODE_CS; - } - - error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); - -#if 0 - /* Select default charmap */ - if ( bdfface->num_charmaps ) - bdfface->charmap = bdfface->charmaps[0]; -#endif - } - - goto Exit; - } - } - - /* otherwise assume Adobe standard encoding */ - - { - FT_CharMapRec charmap; - - - charmap.face = FT_FACE( face ); - charmap.encoding = FT_ENCODING_ADOBE_STANDARD; - charmap.platform_id = TT_PLATFORM_ADOBE; - charmap.encoding_id = TT_ADOBE_ID_STANDARD; - - error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); - - /* Select default charmap */ - if ( bdfface->num_charmaps ) - bdfface->charmap = bdfface->charmaps[0]; - } - } - } - - Exit: - return error; - - Fail: - BDF_Face_Done( bdfface ); - return FT_THROW( Unknown_File_Format ); - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Size_Select( FT_Size size, - FT_ULong strike_index ) - { - bdf_font_t* bdffont = ( (BDF_Face)size->face )->bdffont; - - - FT_Select_Metrics( size->face, strike_index ); - - size->metrics.ascender = bdffont->font_ascent * 64; - size->metrics.descender = -bdffont->font_descent * 64; - size->metrics.max_advance = bdffont->bbx.width * 64; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Size_Request( FT_Size size, - FT_Size_Request req ) - { - FT_Face face = size->face; - FT_Bitmap_Size* bsize = face->available_sizes; - bdf_font_t* bdffont = ( (BDF_Face)face )->bdffont; - FT_Error error = FT_ERR( Invalid_Pixel_Size ); - FT_Long height; - - - height = FT_REQUEST_HEIGHT( req ); - height = ( height + 32 ) >> 6; - - switch ( req->type ) - { - case FT_SIZE_REQUEST_TYPE_NOMINAL: - if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) - error = FT_Err_Ok; - break; - - case FT_SIZE_REQUEST_TYPE_REAL_DIM: - if ( height == ( bdffont->font_ascent + - bdffont->font_descent ) ) - error = FT_Err_Ok; - break; - - default: - error = FT_THROW( Unimplemented_Feature ); - break; - } - - if ( error ) - return error; - else - return BDF_Size_Select( size, 0 ); - } - - - - FT_CALLBACK_DEF( FT_Error ) - BDF_Glyph_Load( FT_GlyphSlot slot, - FT_Size size, - FT_UInt glyph_index, - FT_Int32 load_flags ) - { - BDF_Face bdf = (BDF_Face)FT_SIZE_FACE( size ); - FT_Face face = FT_FACE( bdf ); - FT_Error error = FT_Err_Ok; - FT_Bitmap* bitmap = &slot->bitmap; - bdf_glyph_t glyph; - int bpp = bdf->bdffont->bpp; - - FT_UNUSED( load_flags ); - - - if ( !face ) - { - error = FT_THROW( Invalid_Face_Handle ); - goto Exit; - } - - if ( glyph_index >= (FT_UInt)face->num_glyphs ) - { - error = FT_THROW( Invalid_Argument ); - 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; - else - glyph_index--; - - /* slot, bitmap => freetype, glyph => bdflib */ - glyph = bdf->bdffont->glyphs[glyph_index]; - - bitmap->rows = glyph.bbx.height; - bitmap->width = glyph.bbx.width; - if ( glyph.bpr > INT_MAX ) - FT_TRACE1(( "BDF_Glyph_Load: too large pitch %d is truncated\n", - glyph.bpr )); - bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */ - - /* note: we don't allocate a new array to hold the bitmap; */ - /* we can simply point to it */ - ft_glyphslot_set_bitmap( slot, glyph.bitmap ); - - switch ( bpp ) - { - case 1: - bitmap->pixel_mode = FT_PIXEL_MODE_MONO; - break; - case 2: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY2; - break; - case 4: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY4; - break; - case 8: - bitmap->pixel_mode = FT_PIXEL_MODE_GRAY; - bitmap->num_grays = 256; - break; - } - - slot->format = FT_GLYPH_FORMAT_BITMAP; - slot->bitmap_left = glyph.bbx.x_offset; - slot->bitmap_top = glyph.bbx.ascent; - - slot->metrics.horiAdvance = (FT_Pos)( glyph.dwidth * 64 ); - slot->metrics.horiBearingX = (FT_Pos)( glyph.bbx.x_offset * 64 ); - slot->metrics.horiBearingY = (FT_Pos)( glyph.bbx.ascent * 64 ); - slot->metrics.width = (FT_Pos)( bitmap->width * 64 ); - slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); - - /* - * XXX DWIDTH1 and VVECTOR should be parsed and - * used here, provided such fonts do exist. - */ - ft_synthesize_vertical_metrics( &slot->metrics, - bdf->bdffont->bbx.height * 64 ); - - Exit: - return error; - } - - - /* - * - * BDF SERVICE - * - */ - - static FT_Error - bdf_get_bdf_property( BDF_Face face, - const char* prop_name, - BDF_PropertyRec *aproperty ) - { - bdf_property_t* prop; - - - FT_ASSERT( face && face->bdffont ); - - prop = bdf_get_font_property( face->bdffont, prop_name ); - if ( prop ) - { - switch ( prop->format ) - { - case BDF_ATOM: - aproperty->type = BDF_PROPERTY_TYPE_ATOM; - aproperty->u.atom = prop->value.atom; - break; - - case BDF_INTEGER: - if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) ) - { - FT_TRACE1(( "bdf_get_bdf_property:" - " too large integer 0x%x is truncated\n" )); - } - aproperty->type = BDF_PROPERTY_TYPE_INTEGER; - aproperty->u.integer = (FT_Int32)prop->value.l; - break; - - case BDF_CARDINAL: - if ( prop->value.ul > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "bdf_get_bdf_property:" - " too large cardinal 0x%x is truncated\n" )); - } - aproperty->type = BDF_PROPERTY_TYPE_CARDINAL; - aproperty->u.cardinal = (FT_UInt32)prop->value.ul; - break; - - default: - goto Fail; - } - return 0; - } - - Fail: - return FT_THROW( Invalid_Argument ); - } - - - static FT_Error - bdf_get_charset_id( BDF_Face face, - const char* *acharset_encoding, - const char* *acharset_registry ) - { - *acharset_encoding = face->charset_encoding; - *acharset_registry = face->charset_registry; - - return 0; - } - - - static const FT_Service_BDFRec bdf_service_bdf = - { - (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id, /* get_charset_id */ - (FT_BDF_GetPropertyFunc) bdf_get_bdf_property /* get_property */ - }; - - - /* - * - * SERVICES LIST - * - */ - - static const FT_ServiceDescRec bdf_services[] = - { - { FT_SERVICE_ID_BDF, &bdf_service_bdf }, - { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_BDF }, - { NULL, NULL } - }; - - - FT_CALLBACK_DEF( FT_Module_Interface ) - bdf_driver_requester( FT_Module module, - const char* name ) - { - FT_UNUSED( module ); - - return ft_service_list_lookup( bdf_services, name ); - } - - - - FT_CALLBACK_TABLE_DEF - const FT_Driver_ClassRec bdf_driver_class = - { - { - FT_MODULE_FONT_DRIVER | - FT_MODULE_DRIVER_NO_OUTLINES, - sizeof ( FT_DriverRec ), - - "bdf", - 0x10000L, - 0x20000L, - - NULL, /* module-specific interface */ - - NULL, /* FT_Module_Constructor module_init */ - NULL, /* FT_Module_Destructor module_done */ - bdf_driver_requester /* FT_Module_Requester get_interface */ - }, - - sizeof ( BDF_FaceRec ), - sizeof ( FT_SizeRec ), - sizeof ( FT_GlyphSlotRec ), - - BDF_Face_Init, /* FT_Face_InitFunc init_face */ - BDF_Face_Done, /* FT_Face_DoneFunc done_face */ - NULL, /* FT_Size_InitFunc init_size */ - NULL, /* FT_Size_DoneFunc done_size */ - NULL, /* FT_Slot_InitFunc init_slot */ - NULL, /* FT_Slot_DoneFunc done_slot */ - - BDF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ - - NULL, /* FT_Face_GetKerningFunc get_kerning */ - NULL, /* FT_Face_AttachFunc attach_file */ - NULL, /* FT_Face_GetAdvancesFunc get_advances */ - - BDF_Size_Request, /* FT_Size_RequestFunc request_size */ - BDF_Size_Select /* FT_Size_SelectFunc select_size */ - }; - - -/* END */ diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c index 5053094..9f4d36d 100644 --- a/src/pcf/pcfdrivr.c +++ b/src/pcf/pcfdrivr.c @@ -387,11 +387,7 @@ THE SOFTWARE. if ( !ft_strcmp( s, "10646" ) || ( !ft_strcmp( s, "8859" ) && !ft_strcmp( face->charset_encoding, "1" ) ) ) - unicode_charmap = 1; - /* another name for ASCII */ - else if ( !ft_strcmp( s, "646.1991" ) && - !ft_strcmp( face->charset_encoding, "IRV" ) ) - unicode_charmap = 1; + unicode_charmap = 1; } } diff --git a/src/pcf/pcfdrivr.c.pcf-encoding b/src/pcf/pcfdrivr.c.pcf-encoding deleted file mode 100644 index 9f4d36d..0000000 --- a/src/pcf/pcfdrivr.c.pcf-encoding +++ /dev/null @@ -1,871 +0,0 @@ -/* pcfdrivr.c - - FreeType font driver for pcf files - - Copyright (C) 2000-2004, 2006-2011, 2013, 2014 by - Francesco Zappa Nardelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - - -#include <ft2build.h> - -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_OBJECTS_H -#include FT_GZIP_H -#include FT_LZW_H -#include FT_BZIP2_H -#include FT_ERRORS_H -#include FT_BDF_H -#include FT_TRUETYPE_IDS_H - -#include "pcf.h" -#include "pcfdrivr.h" -#include "pcfread.h" - -#include "pcferror.h" -#include "pcfutil.h" - -#undef FT_COMPONENT -#define FT_COMPONENT trace_pcfread - -#include FT_SERVICE_BDF_H -#include FT_SERVICE_FONT_FORMAT_H -#include FT_SERVICE_PROPERTIES_H -#include FT_PCF_DRIVER_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_pcfdriver - - - typedef struct PCF_CMapRec_ - { - FT_CMapRec root; - FT_ULong num_encodings; - PCF_Encoding encodings; - - } PCF_CMapRec, *PCF_CMap; - - - FT_CALLBACK_DEF( FT_Error ) - pcf_cmap_init( FT_CMap pcfcmap, /* PCF_CMap */ - FT_Pointer init_data ) - { - PCF_CMap cmap = (PCF_CMap)pcfcmap; - PCF_Face face = (PCF_Face)FT_CMAP_FACE( pcfcmap ); - - FT_UNUSED( init_data ); - - - cmap->num_encodings = face->nencodings; - cmap->encodings = face->encodings; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( void ) - pcf_cmap_done( FT_CMap pcfcmap ) /* PCF_CMap */ - { - PCF_CMap cmap = (PCF_CMap)pcfcmap; - - - cmap->encodings = NULL; - cmap->num_encodings = 0; - } - - - FT_CALLBACK_DEF( FT_UInt ) - pcf_cmap_char_index( FT_CMap pcfcmap, /* PCF_CMap */ - FT_UInt32 charcode ) - { - PCF_CMap cmap = (PCF_CMap)pcfcmap; - PCF_Encoding encodings = cmap->encodings; - FT_ULong min, max, mid; - FT_UInt result = 0; - - - min = 0; - max = cmap->num_encodings; - - while ( min < max ) - { - FT_ULong code; - - - mid = ( min + max ) >> 1; - code = (FT_ULong)encodings[mid].enc; - - if ( charcode == code ) - { - result = encodings[mid].glyph + 1; - break; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - } - - return result; - } - - - FT_CALLBACK_DEF( FT_UInt ) - pcf_cmap_char_next( FT_CMap pcfcmap, /* PCF_CMap */ - FT_UInt32 *acharcode ) - { - PCF_CMap cmap = (PCF_CMap)pcfcmap; - PCF_Encoding encodings = cmap->encodings; - FT_ULong min, max, mid; - FT_ULong charcode = *acharcode + 1; - FT_UInt result = 0; - - - min = 0; - max = cmap->num_encodings; - - while ( min < max ) - { - FT_ULong code; - - - mid = ( min + max ) >> 1; - code = (FT_ULong)encodings[mid].enc; - - if ( charcode == code ) - { - result = encodings[mid].glyph + 1; - goto Exit; - } - - if ( charcode < code ) - max = mid; - else - min = mid + 1; - } - - charcode = 0; - if ( min < cmap->num_encodings ) - { - charcode = (FT_ULong)encodings[min].enc; - result = encodings[min].glyph + 1; - } - - Exit: - if ( charcode > 0xFFFFFFFFUL ) - { - FT_TRACE1(( "pcf_cmap_char_next: charcode 0x%x > 32bit API" )); - *acharcode = 0; - /* XXX: result should be changed to indicate an overflow error */ - } - else - *acharcode = (FT_UInt32)charcode; - return result; - } - - - static - const FT_CMap_ClassRec pcf_cmap_class = - { - sizeof ( PCF_CMapRec ), - pcf_cmap_init, - pcf_cmap_done, - pcf_cmap_char_index, - pcf_cmap_char_next, - - NULL, NULL, NULL, NULL, NULL - }; - - - FT_CALLBACK_DEF( void ) - PCF_Face_Done( FT_Face pcfface ) /* PCF_Face */ - { - PCF_Face face = (PCF_Face)pcfface; - FT_Memory memory; - - - if ( !face ) - return; - - memory = FT_FACE_MEMORY( face ); - - FT_FREE( face->encodings ); - FT_FREE( face->metrics ); - - /* free properties */ - if ( face->properties ) - { - FT_Int i; - - - for ( i = 0; i < face->nprops; i++ ) - { - PCF_Property prop = &face->properties[i]; - - - if ( prop ) - { - FT_FREE( prop->name ); - if ( prop->isString ) - FT_FREE( prop->value.atom ); - } - } - - FT_FREE( face->properties ); - } - - FT_FREE( face->toc.tables ); - FT_FREE( pcfface->family_name ); - FT_FREE( pcfface->style_name ); - FT_FREE( pcfface->available_sizes ); - FT_FREE( face->charset_encoding ); - FT_FREE( face->charset_registry ); - - /* close compressed stream if any */ - if ( pcfface->stream == &face->comp_stream ) - { - FT_Stream_Close( &face->comp_stream ); - pcfface->stream = face->comp_source; - } - } - - - FT_CALLBACK_DEF( FT_Error ) - PCF_Face_Init( FT_Stream stream, - FT_Face pcfface, /* PCF_Face */ - FT_Int face_index, - FT_Int num_params, - FT_Parameter* params ) - { - PCF_Face face = (PCF_Face)pcfface; - FT_Error error; - - FT_UNUSED( num_params ); - FT_UNUSED( params ); - - - FT_TRACE2(( "PCF driver\n" )); - - error = pcf_load_font( stream, face, face_index ); - if ( error ) - { - PCF_Face_Done( pcfface ); - -#if defined( FT_CONFIG_OPTION_USE_ZLIB ) || \ - defined( FT_CONFIG_OPTION_USE_LZW ) || \ - defined( FT_CONFIG_OPTION_USE_BZIP2 ) - -#ifdef FT_CONFIG_OPTION_USE_ZLIB - { - FT_Error error2; - - - /* this didn't work, try gzip support! */ - FT_TRACE2(( " ... try gzip stream\n" )); - error2 = FT_Stream_OpenGzip( &face->comp_stream, stream ); - if ( FT_ERR_EQ( error2, Unimplemented_Feature ) ) - goto Fail; - - error = error2; - } -#endif /* FT_CONFIG_OPTION_USE_ZLIB */ - -#ifdef FT_CONFIG_OPTION_USE_LZW - if ( error ) - { - FT_Error error3; - - - /* this didn't work, try LZW support! */ - FT_TRACE2(( " ... try LZW stream\n" )); - error3 = FT_Stream_OpenLZW( &face->comp_stream, stream ); - if ( FT_ERR_EQ( error3, Unimplemented_Feature ) ) - goto Fail; - - error = error3; - } -#endif /* FT_CONFIG_OPTION_USE_LZW */ - -#ifdef FT_CONFIG_OPTION_USE_BZIP2 - if ( error ) - { - FT_Error error4; - - - /* this didn't work, try Bzip2 support! */ - FT_TRACE2(( " ... try Bzip2 stream\n" )); - error4 = FT_Stream_OpenBzip2( &face->comp_stream, stream ); - if ( FT_ERR_EQ( error4, Unimplemented_Feature ) ) - goto Fail; - - error = error4; - } -#endif /* FT_CONFIG_OPTION_USE_BZIP2 */ - - if ( error ) - goto Fail; - - face->comp_source = stream; - pcfface->stream = &face->comp_stream; - - stream = pcfface->stream; - - error = pcf_load_font( stream, face, face_index ); - if ( error ) - goto Fail; - -#else /* !(FT_CONFIG_OPTION_USE_ZLIB || - FT_CONFIG_OPTION_USE_LZW || - FT_CONFIG_OPTION_USE_BZIP2) */ - - goto Fail; - -#endif - } - - /* PCF cannot have multiple faces in a single font file. - * XXX: A non-zero face_index is already an invalid argument, but - * Type1, Type42 drivers have a convention to return - * an invalid argument error when the font could be - * opened by the specified driver. - */ - if ( face_index < 0 ) - goto Exit; - else if ( face_index > 0 && ( face_index & 0xFFFF ) > 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; - FT_String *charset_encoding = face->charset_encoding; - FT_Bool unicode_charmap = 0; - - - if ( charset_registry && charset_encoding ) - { - char* s = charset_registry; - - - /* Uh, oh, compare first letters manually to avoid dependency - on locales. */ - if ( ( s[0] == 'i' || s[0] == 'I' ) && - ( s[1] == 's' || s[1] == 'S' ) && - ( s[2] == 'o' || s[2] == 'O' ) ) - { - s += 3; - if ( !ft_strcmp( s, "10646" ) || - ( !ft_strcmp( s, "8859" ) && - !ft_strcmp( face->charset_encoding, "1" ) ) ) - unicode_charmap = 1; - } - } - - { - FT_CharMapRec charmap; - - - charmap.face = FT_FACE( face ); - charmap.encoding = FT_ENCODING_NONE; - /* initial platform/encoding should indicate unset status? */ - charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; - charmap.encoding_id = TT_APPLE_ID_DEFAULT; - - if ( unicode_charmap ) - { - charmap.encoding = FT_ENCODING_UNICODE; - charmap.platform_id = TT_PLATFORM_MICROSOFT; - charmap.encoding_id = TT_MS_ID_UNICODE_CS; - } - - error = FT_CMap_New( &pcf_cmap_class, NULL, &charmap, NULL ); - -#if 0 - /* Select default charmap */ - if ( pcfface->num_charmaps ) - pcfface->charmap = pcfface->charmaps[0]; -#endif - } - } - - Exit: - return error; - - Fail: - FT_TRACE2(( " not a PCF file\n" )); - PCF_Face_Done( pcfface ); - error = FT_THROW( Unknown_File_Format ); /* error */ - goto Exit; - } - - - FT_CALLBACK_DEF( FT_Error ) - PCF_Size_Select( FT_Size size, - FT_ULong strike_index ) - { - PCF_Accel accel = &( (PCF_Face)size->face )->accel; - - - FT_Select_Metrics( size->face, strike_index ); - - size->metrics.ascender = accel->fontAscent * 64; - size->metrics.descender = -accel->fontDescent * 64; - size->metrics.max_advance = accel->maxbounds.characterWidth * 64; - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( FT_Error ) - PCF_Size_Request( FT_Size size, - FT_Size_Request req ) - { - PCF_Face face = (PCF_Face)size->face; - FT_Bitmap_Size* bsize = size->face->available_sizes; - FT_Error error = FT_ERR( Invalid_Pixel_Size ); - FT_Long height; - - - height = FT_REQUEST_HEIGHT( req ); - height = ( height + 32 ) >> 6; - - switch ( req->type ) - { - case FT_SIZE_REQUEST_TYPE_NOMINAL: - if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) - error = FT_Err_Ok; - break; - - case FT_SIZE_REQUEST_TYPE_REAL_DIM: - if ( height == ( face->accel.fontAscent + - face->accel.fontDescent ) ) - error = FT_Err_Ok; - break; - - default: - error = FT_THROW( Unimplemented_Feature ); - break; - } - - if ( error ) - return error; - else - return PCF_Size_Select( size, 0 ); - } - - - FT_CALLBACK_DEF( FT_Error ) - PCF_Glyph_Load( FT_GlyphSlot slot, - FT_Size size, - FT_UInt glyph_index, - FT_Int32 load_flags ) - { - PCF_Face face = (PCF_Face)FT_SIZE_FACE( size ); - FT_Stream stream; - FT_Error error = FT_Err_Ok; - FT_Bitmap* bitmap = &slot->bitmap; - PCF_Metric metric; - FT_ULong bytes; - - - FT_TRACE1(( "PCF_Glyph_Load: glyph index %d\n", glyph_index )); - - if ( !face ) - { - error = FT_THROW( Invalid_Face_Handle ); - goto Exit; - } - - if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) - { - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - stream = face->root.stream; - - if ( glyph_index > 0 ) - glyph_index--; - - metric = face->metrics + glyph_index; - - bitmap->rows = (unsigned int)( metric->ascent + - metric->descent ); - bitmap->width = (unsigned int)( metric->rightSideBearing - - metric->leftSideBearing ); - bitmap->num_grays = 1; - bitmap->pixel_mode = FT_PIXEL_MODE_MONO; - - switch ( PCF_GLYPH_PAD( face->bitmapsFormat ) ) - { - case 1: - bitmap->pitch = (int)( ( bitmap->width + 7 ) >> 3 ); - break; - - case 2: - bitmap->pitch = (int)( ( ( bitmap->width + 15 ) >> 4 ) << 1 ); - break; - - case 4: - bitmap->pitch = (int)( ( ( bitmap->width + 31 ) >> 5 ) << 2 ); - break; - - case 8: - bitmap->pitch = (int)( ( ( bitmap->width + 63 ) >> 6 ) << 3 ); - break; - - default: - return FT_THROW( Invalid_File_Format ); - } - - slot->format = FT_GLYPH_FORMAT_BITMAP; - slot->bitmap_left = metric->leftSideBearing; - slot->bitmap_top = metric->ascent; - - slot->metrics.horiAdvance = (FT_Pos)( metric->characterWidth * 64 ); - slot->metrics.horiBearingX = (FT_Pos)( metric->leftSideBearing * 64 ); - slot->metrics.horiBearingY = (FT_Pos)( metric->ascent * 64 ); - slot->metrics.width = (FT_Pos)( ( metric->rightSideBearing - - metric->leftSideBearing ) * 64 ); - slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); - - ft_synthesize_vertical_metrics( &slot->metrics, - ( face->accel.fontAscent + - face->accel.fontDescent ) * 64 ); - - if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) - goto Exit; - - /* XXX: to do: are there cases that need repadding the bitmap? */ - bytes = (FT_ULong)bitmap->pitch * bitmap->rows; - - error = ft_glyphslot_alloc_bitmap( slot, (FT_ULong)bytes ); - if ( error ) - goto Exit; - - if ( FT_STREAM_SEEK( metric->bits ) || - FT_STREAM_READ( bitmap->buffer, bytes ) ) - goto Exit; - - if ( PCF_BIT_ORDER( face->bitmapsFormat ) != MSBFirst ) - BitOrderInvert( bitmap->buffer, bytes ); - - if ( ( PCF_BYTE_ORDER( face->bitmapsFormat ) != - PCF_BIT_ORDER( face->bitmapsFormat ) ) ) - { - switch ( PCF_SCAN_UNIT( face->bitmapsFormat ) ) - { - case 1: - break; - - case 2: - TwoByteSwap( bitmap->buffer, bytes ); - break; - - case 4: - FourByteSwap( bitmap->buffer, bytes ); - break; - } - } - - Exit: - return error; - } - - - /* - * - * BDF SERVICE - * - */ - - static FT_Error - pcf_get_bdf_property( PCF_Face face, - const char* prop_name, - BDF_PropertyRec *aproperty ) - { - PCF_Property prop; - - - prop = pcf_find_property( face, prop_name ); - if ( prop ) - { - if ( prop->isString ) - { - aproperty->type = BDF_PROPERTY_TYPE_ATOM; - aproperty->u.atom = prop->value.atom; - } - else - { - if ( prop->value.l > 0x7FFFFFFFL || - prop->value.l < ( -1 - 0x7FFFFFFFL ) ) - { - FT_TRACE1(( "pcf_get_bdf_property:" )); - FT_TRACE1(( " too large integer 0x%x is truncated\n" )); - } - - /* - * The PCF driver loads all properties as signed integers. - * This really doesn't seem to be a problem, because this is - * sufficient for any meaningful values. - */ - aproperty->type = BDF_PROPERTY_TYPE_INTEGER; - aproperty->u.integer = (FT_Int32)prop->value.l; - } - - return FT_Err_Ok; - } - - return FT_THROW( Invalid_Argument ); - } - - - static FT_Error - pcf_get_charset_id( PCF_Face face, - const char* *acharset_encoding, - const char* *acharset_registry ) - { - *acharset_encoding = face->charset_encoding; - *acharset_registry = face->charset_registry; - - return FT_Err_Ok; - } - - - static const FT_Service_BDFRec pcf_service_bdf = - { - (FT_BDF_GetCharsetIdFunc)pcf_get_charset_id, /* get_charset_id */ - (FT_BDF_GetPropertyFunc) pcf_get_bdf_property /* get_property */ - }; - - - /* - * PROPERTY SERVICE - * - */ - static FT_Error - pcf_property_set( FT_Module module, /* PCF_Driver */ - const char* property_name, - const void* value, - FT_Bool value_is_string ) - { -#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES - - FT_Error error = FT_Err_Ok; - PCF_Driver driver = (PCF_Driver)module; - -#ifndef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES - FT_UNUSED( value_is_string ); -#endif - - - if ( !ft_strcmp( property_name, "no-long-family-names" ) ) - { -#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES - if ( value_is_string ) - { - const char* s = (const char*)value; - long lfn = ft_strtol( s, NULL, 10 ); - - - if ( lfn == 0 ) - driver->no_long_family_names = 0; - else if ( lfn == 1 ) - driver->no_long_family_names = 1; - else - return FT_THROW( Invalid_Argument ); - } - else -#endif - { - FT_Bool* no_long_family_names = (FT_Bool*)value; - - - driver->no_long_family_names = *no_long_family_names; - } - - return error; - } - -#else /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ - - FT_UNUSED( module ); - FT_UNUSED( value ); - FT_UNUSED( value_is_string ); -#ifndef FT_DEBUG_LEVEL_TRACE - FT_UNUSED( property_name ); -#endif - -#endif /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ - - FT_TRACE0(( "pcf_property_set: missing property `%s'\n", - property_name )); - return FT_THROW( Missing_Property ); - } - - - static FT_Error - pcf_property_get( FT_Module module, /* PCF_Driver */ - const char* property_name, - const void* value ) - { -#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES - - FT_Error error = FT_Err_Ok; - PCF_Driver driver = (PCF_Driver)module; - - - if ( !ft_strcmp( property_name, "no-long-family-names" ) ) - { - FT_Bool no_long_family_names = driver->no_long_family_names; - FT_Bool* val = (FT_Bool*)value; - - - *val = no_long_family_names; - - return error; - } - -#else /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ - - FT_UNUSED( module ); - FT_UNUSED( value ); -#ifndef FT_DEBUG_LEVEL_TRACE - FT_UNUSED( property_name ); -#endif - -#endif /* !PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */ - - FT_TRACE0(( "pcf_property_get: missing property `%s'\n", - property_name )); - return FT_THROW( Missing_Property ); - } - - - FT_DEFINE_SERVICE_PROPERTIESREC( - pcf_service_properties, - - (FT_Properties_SetFunc)pcf_property_set, /* set_property */ - (FT_Properties_GetFunc)pcf_property_get ) /* get_property */ - - - /* - * - * SERVICE LIST - * - */ - - static const FT_ServiceDescRec pcf_services[] = - { - { FT_SERVICE_ID_BDF, &pcf_service_bdf }, - { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_PCF }, - { FT_SERVICE_ID_PROPERTIES, &pcf_service_properties }, - { NULL, NULL } - }; - - - FT_CALLBACK_DEF( FT_Module_Interface ) - pcf_driver_requester( FT_Module module, - const char* name ) - { - FT_UNUSED( module ); - - return ft_service_list_lookup( pcf_services, name ); - } - - - FT_CALLBACK_DEF( FT_Error ) - pcf_driver_init( FT_Module module ) /* PCF_Driver */ - { -#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES - PCF_Driver driver = (PCF_Driver)module; - - - driver->no_long_family_names = 0; -#else - FT_UNUSED( module ); -#endif - - return FT_Err_Ok; - } - - - FT_CALLBACK_DEF( void ) - pcf_driver_done( FT_Module module ) /* PCF_Driver */ - { - FT_UNUSED( module ); - } - - - FT_CALLBACK_TABLE_DEF - const FT_Driver_ClassRec pcf_driver_class = - { - { - FT_MODULE_FONT_DRIVER | - FT_MODULE_DRIVER_NO_OUTLINES, - - sizeof ( PCF_DriverRec ), - "pcf", - 0x10000L, - 0x20000L, - - NULL, /* module-specific interface */ - - pcf_driver_init, /* FT_Module_Constructor module_init */ - pcf_driver_done, /* FT_Module_Destructor module_done */ - pcf_driver_requester /* FT_Module_Requester get_interface */ - }, - - sizeof ( PCF_FaceRec ), - sizeof ( FT_SizeRec ), - sizeof ( FT_GlyphSlotRec ), - - PCF_Face_Init, /* FT_Face_InitFunc init_face */ - PCF_Face_Done, /* FT_Face_DoneFunc done_face */ - NULL, /* FT_Size_InitFunc init_size */ - NULL, /* FT_Size_DoneFunc done_size */ - NULL, /* FT_Slot_InitFunc init_slot */ - NULL, /* FT_Slot_DoneFunc done_slot */ - - PCF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ - - NULL, /* FT_Face_GetKerningFunc get_kerning */ - NULL, /* FT_Face_AttachFunc attach_file */ - NULL, /* FT_Face_GetAdvancesFunc get_advances */ - - PCF_Size_Request, /* FT_Size_RequestFunc request_size */ - PCF_Size_Select /* FT_Size_SelectFunc select_size */ - }; - - -/* END */ diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c index 997ad2e..0cedb6b 100644 --- a/src/truetype/ttgxvar.c +++ b/src/truetype/ttgxvar.c @@ -2136,16 +2136,8 @@ goto Exit; if ( fvar_head.instanceCount && !face->blend->avar_loaded ) - { - FT_ULong offset = FT_STREAM_POS(); - - ft_var_load_avar( face ); - if ( FT_STREAM_SEEK( offset ) ) - goto Exit; - } - ns = mmvar->namedstyle; nsc = face->blend->normalized_stylecoords; for ( i = 0; i < fvar_head.instanceCount; i++, ns++ ) @@ -2162,11 +2154,8 @@ for ( j = 0; j < fvar_head.axisCount; j++, c++ ) *c = FT_GET_LONG(); - /* valid psid values are 6, [256;32767], and 0xFFFF */ if ( usePsName ) ns->psid = FT_GET_USHORT(); - else - ns->psid = 0xFFFF; ft_var_to_normalized( face, fvar_head.axisCount, @@ -2182,7 +2171,7 @@ SFNT_Service sfnt = (SFNT_Service)face->sfnt; FT_Int found, dummy1, dummy2; - FT_UInt strid = ~0U; + FT_UInt strid = 0xFFFFFFFFUL; /* the default instance is missing in array the */ diff --git a/src/truetype/ttgxvar.c.named-instances b/src/truetype/ttgxvar.c.named-instances deleted file mode 100644 index 0cedb6b..0000000 --- a/src/truetype/ttgxvar.c.named-instances +++ /dev/null @@ -1,3719 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttgxvar.c */ -/* */ -/* TrueType GX Font Variation loader */ -/* */ -/* Copyright 2004-2017 by */ -/* David Turner, Robert Wilhelm, Werner Lemberg, and George Williams. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Apple documents the `fvar', `gvar', `cvar', and `avar' tables at */ - /* */ - /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6[fgca]var.html */ - /* */ - /* The documentation for `gvar' is not intelligible; `cvar' refers you */ - /* to `gvar' and is thus also incomprehensible. */ - /* */ - /* The documentation for `avar' appears correct, but Apple has no fonts */ - /* with an `avar' table, so it is hard to test. */ - /* */ - /* Many thanks to John Jenkins (at Apple) in figuring this out. */ - /* */ - /* */ - /* Apple's `kern' table has some references to tuple indices, but as */ - /* there is no indication where these indices are defined, nor how to */ - /* interpolate the kerning values (different tuples have different */ - /* classes) this issue is ignored. */ - /* */ - /*************************************************************************/ - - -#include <ft2build.h> -#include FT_INTERNAL_DEBUG_H -#include FT_CONFIG_CONFIG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_SFNT_H -#include FT_TRUETYPE_TAGS_H -#include FT_TRUETYPE_IDS_H -#include FT_MULTIPLE_MASTERS_H -#include FT_LIST_H - -#include "ttpload.h" -#include "ttgxvar.h" - -#include "tterrors.h" - - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - - -#define FT_Stream_FTell( stream ) \ - (FT_ULong)( (stream)->cursor - (stream)->base ) -#define FT_Stream_SeekSet( stream, off ) \ - ( (stream)->cursor = (stream)->base + (off) ) - - - /*************************************************************************/ - /* */ - /* 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_ttgxvar - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** Internal Routines *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* The macro ALL_POINTS is used in `ft_var_readpackedpoints'. It */ - /* indicates that there is a delta for every point without needing to */ - /* enumerate all of them. */ - /* */ - - /* ensure that value `0' has the same width as a pointer */ -#define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0 - - -#define GX_PT_POINTS_ARE_WORDS 0x80U -#define GX_PT_POINT_RUN_COUNT_MASK 0x7FU - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_readpackedpoints */ - /* */ - /* <Description> */ - /* Read a set of points to which the following deltas will apply. */ - /* Points are packed with a run length encoding. */ - /* */ - /* <Input> */ - /* stream :: The data stream. */ - /* */ - /* size :: The size of the table holding the data. */ - /* */ - /* <Output> */ - /* point_cnt :: The number of points read. A zero value means that */ - /* all points in the glyph will be affected, without */ - /* enumerating them individually. */ - /* */ - /* <Return> */ - /* An array of FT_UShort containing the affected points or the */ - /* special value ALL_POINTS. */ - /* */ - static FT_UShort* - ft_var_readpackedpoints( FT_Stream stream, - FT_ULong size, - FT_UInt *point_cnt ) - { - FT_UShort *points = NULL; - FT_UInt n; - FT_UInt runcnt; - FT_UInt i, j; - FT_UShort first; - FT_Memory memory = stream->memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( error ); - - - *point_cnt = 0; - - n = FT_GET_BYTE(); - if ( n == 0 ) - return ALL_POINTS; - - if ( n & GX_PT_POINTS_ARE_WORDS ) - { - n &= GX_PT_POINT_RUN_COUNT_MASK; - n <<= 8; - n |= FT_GET_BYTE(); - } - - if ( n > size ) - { - FT_TRACE1(( "ft_var_readpackedpoints: number of points too large\n" )); - return NULL; - } - - /* in the nested loops below we increase `i' twice; */ - /* it is faster to simply allocate one more slot */ - /* than to add another test within the loop */ - if ( FT_NEW_ARRAY( points, n + 1 ) ) - return NULL; - - *point_cnt = n; - - first = 0; - i = 0; - while ( i < n ) - { - runcnt = FT_GET_BYTE(); - if ( runcnt & GX_PT_POINTS_ARE_WORDS ) - { - runcnt &= GX_PT_POINT_RUN_COUNT_MASK; - first += FT_GET_USHORT(); - points[i++] = first; - - /* first point not included in run count */ - for ( j = 0; j < runcnt; j++ ) - { - first += FT_GET_USHORT(); - points[i++] = first; - if ( i >= n ) - break; - } - } - else - { - first += FT_GET_BYTE(); - points[i++] = first; - - for ( j = 0; j < runcnt; j++ ) - { - first += FT_GET_BYTE(); - points[i++] = first; - if ( i >= n ) - break; - } - } - } - - return points; - } - - -#define GX_DT_DELTAS_ARE_ZERO 0x80U -#define GX_DT_DELTAS_ARE_WORDS 0x40U -#define GX_DT_DELTA_RUN_COUNT_MASK 0x3FU - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_readpackeddeltas */ - /* */ - /* <Description> */ - /* Read a set of deltas. These are packed slightly differently than */ - /* points. In particular there is no overall count. */ - /* */ - /* <Input> */ - /* stream :: The data stream. */ - /* */ - /* size :: The size of the table holding the data. */ - /* */ - /* delta_cnt :: The number of deltas to be read. */ - /* */ - /* <Return> */ - /* An array of FT_Short containing the deltas for the affected */ - /* points. (This only gets the deltas for one dimension. It will */ - /* generally be called twice, once for x, once for y. When used in */ - /* cvt table, it will only be called once.) */ - /* */ - static FT_Short* - ft_var_readpackeddeltas( FT_Stream stream, - FT_ULong size, - FT_UInt delta_cnt ) - { - FT_Short *deltas = NULL; - FT_UInt runcnt, cnt; - FT_UInt i, j; - FT_Memory memory = stream->memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( error ); - - - if ( delta_cnt > size ) - { - FT_TRACE1(( "ft_var_readpackeddeltas: number of points too large\n" )); - return NULL; - } - - if ( FT_NEW_ARRAY( deltas, delta_cnt ) ) - return NULL; - - i = 0; - while ( i < delta_cnt ) - { - runcnt = FT_GET_BYTE(); - cnt = runcnt & GX_DT_DELTA_RUN_COUNT_MASK; - - if ( runcnt & GX_DT_DELTAS_ARE_ZERO ) - { - /* `runcnt' zeroes get added */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = 0; - } - else if ( runcnt & GX_DT_DELTAS_ARE_WORDS ) - { - /* `runcnt' shorts from the stack */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = FT_GET_SHORT(); - } - else - { - /* `runcnt' signed bytes from the stack */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = FT_GET_CHAR(); - } - - if ( j <= cnt ) - { - /* bad format */ - FT_FREE( deltas ); - return NULL; - } - } - - return deltas; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_avar */ - /* */ - /* <Description> */ - /* Parse the `avar' table if present. It need not be, so we return */ - /* nothing. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - static void - ft_var_load_avar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - GX_AVarSegment segment; - FT_Error error = FT_Err_Ok; - FT_Long version; - FT_Long axisCount; - FT_Int i, j; - FT_ULong table_len; - - FT_UNUSED( error ); - - - FT_TRACE2(( "AVAR " )); - - blend->avar_loaded = TRUE; - error = face->goto_table( face, TTAG_avar, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - return; - } - - if ( FT_FRAME_ENTER( table_len ) ) - return; - - version = FT_GET_LONG(); - axisCount = FT_GET_LONG(); - - if ( version != 0x00010000L ) - { - FT_TRACE2(( "bad table version\n" )); - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - - if ( axisCount != (FT_Long)blend->mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_load_avar: number of axes in `avar' and `fvar'\n" - " table are different\n" )); - goto Exit; - } - - if ( FT_NEW_ARRAY( blend->avar_segment, axisCount ) ) - goto Exit; - - segment = &blend->avar_segment[0]; - for ( i = 0; i < axisCount; i++, segment++ ) - { - FT_TRACE5(( " axis %d:\n", i )); - - segment->pairCount = FT_GET_USHORT(); - if ( (FT_ULong)segment->pairCount * 4 > table_len || - FT_NEW_ARRAY( segment->correspondence, segment->pairCount ) ) - { - /* Failure. Free everything we have done so far. We must do */ - /* it right now since loading the `avar' table is optional. */ - - for ( j = i - 1; j >= 0; j-- ) - FT_FREE( blend->avar_segment[j].correspondence ); - - FT_FREE( blend->avar_segment ); - blend->avar_segment = NULL; - goto Exit; - } - - for ( j = 0; j < segment->pairCount; j++ ) - { - /* convert to Fixed */ - segment->correspondence[j].fromCoord = FT_GET_SHORT() * 4; - segment->correspondence[j].toCoord = FT_GET_SHORT() * 4; - - FT_TRACE5(( " mapping %.5f to %.5f\n", - segment->correspondence[j].fromCoord / 65536.0, - segment->correspondence[j].toCoord / 65536.0 )); - } - - FT_TRACE5(( "\n" )); - } - - Exit: - FT_FRAME_EXIT(); - } - - - /* some macros we need */ - #define FT_FIXED_ONE ( (FT_Fixed)0x10000 ) - - #define FT_fdot14ToFixed( x ) \ - ( (FT_Fixed)( (FT_ULong)(x) << 2 ) ) - #define FT_intToFixed( i ) \ - ( (FT_Fixed)( (FT_ULong)(i) << 16 ) ) - #define FT_fixedToInt( x ) \ - ( (FT_Short)( ( (FT_UInt32)(x) + 0x8000U ) >> 16 ) ) - - - static FT_Error - ft_var_load_item_variation_store( TT_Face face, - FT_ULong offset, - GX_ItemVarStore itemStore ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - FT_Error error; - FT_UShort format; - FT_ULong region_offset; - FT_UInt i, j, k; - FT_UInt shortDeltaCount; - - GX_Blend blend = face->blend; - GX_ItemVarData varData; - - FT_ULong* dataOffsetArray = NULL; - - - if ( FT_STREAM_SEEK( offset ) || - FT_READ_USHORT( format ) ) - goto Exit; - - if ( format != 1 ) - { - FT_TRACE2(( "ft_var_load_item_variation_store: bad store format %d\n", - format )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* read top level fields */ - if ( FT_READ_ULONG( region_offset ) || - FT_READ_USHORT( itemStore->dataCount ) ) - goto Exit; - - /* we need at least one entry in `itemStore->varData' */ - if ( !itemStore->dataCount ) - { - FT_TRACE2(( "ft_var_load_item_variation_store: missing varData\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* make temporary copy of item variation data offsets; */ - /* we will parse region list first, then come back */ - if ( FT_NEW_ARRAY( dataOffsetArray, itemStore->dataCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->dataCount; i++ ) - { - if ( FT_READ_ULONG( dataOffsetArray[i] ) ) - goto Exit; - } - - /* parse array of region records (region list) */ - if ( FT_STREAM_SEEK( offset + region_offset ) ) - goto Exit; - - if ( FT_READ_USHORT( itemStore->axisCount ) || - FT_READ_USHORT( itemStore->regionCount ) ) - goto Exit; - - if ( itemStore->axisCount != (FT_Long)blend->mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_load_item_variation_store:" - " number of axes in item variation store\n" - " " - " and `fvar' table are different\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( FT_NEW_ARRAY( itemStore->varRegionList, itemStore->regionCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->regionCount; i++ ) - { - GX_AxisCoords axisCoords; - - - if ( FT_NEW_ARRAY( itemStore->varRegionList[i].axisList, - itemStore->axisCount ) ) - goto Exit; - - axisCoords = itemStore->varRegionList[i].axisList; - - for ( j = 0; j < itemStore->axisCount; j++ ) - { - FT_Short start, peak, end; - - - if ( FT_READ_SHORT( start ) || - FT_READ_SHORT( peak ) || - FT_READ_SHORT( end ) ) - goto Exit; - - axisCoords[j].startCoord = FT_fdot14ToFixed( start ); - axisCoords[j].peakCoord = FT_fdot14ToFixed( peak ); - axisCoords[j].endCoord = FT_fdot14ToFixed( end ); - } - } - - /* end of region list parse */ - - /* use dataOffsetArray now to parse varData items */ - if ( FT_NEW_ARRAY( itemStore->varData, itemStore->dataCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->dataCount; i++ ) - { - varData = &itemStore->varData[i]; - - if ( FT_STREAM_SEEK( offset + dataOffsetArray[i] ) ) - goto Exit; - - if ( FT_READ_USHORT( varData->itemCount ) || - FT_READ_USHORT( shortDeltaCount ) || - FT_READ_USHORT( varData->regionIdxCount ) ) - goto Exit; - - /* check some data consistency */ - if ( shortDeltaCount > varData->regionIdxCount ) - { - FT_TRACE2(( "bad short count %d or region count %d\n", - shortDeltaCount, - varData->regionIdxCount )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( varData->regionIdxCount > itemStore->regionCount ) - { - FT_TRACE2(( "inconsistent regionCount %d in varData[%d]\n", - varData->regionIdxCount, - i )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* parse region indices */ - if ( FT_NEW_ARRAY( varData->regionIndices, - varData->regionIdxCount ) ) - goto Exit; - - for ( j = 0; j < varData->regionIdxCount; j++ ) - { - if ( FT_READ_USHORT( varData->regionIndices[j] ) ) - goto Exit; - - if ( varData->regionIndices[j] >= itemStore->regionCount ) - { - FT_TRACE2(( "bad region index %d\n", - varData->regionIndices[j] )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - } - - /* Parse delta set. */ - /* */ - /* On input, deltas are (shortDeltaCount + regionIdxCount) bytes */ - /* each; on output, deltas are expanded to `regionIdxCount' shorts */ - /* each. */ - if ( FT_NEW_ARRAY( varData->deltaSet, - varData->regionIdxCount * varData->itemCount ) ) - goto Exit; - - /* the delta set is stored as a 2-dimensional array of shorts; */ - /* sign-extend signed bytes to signed shorts */ - for ( j = 0; j < varData->itemCount * varData->regionIdxCount; ) - { - for ( k = 0; k < shortDeltaCount; k++, j++ ) - { - /* read the short deltas */ - FT_Short delta; - - - if ( FT_READ_SHORT( delta ) ) - goto Exit; - - varData->deltaSet[j] = delta; - } - - for ( ; k < varData->regionIdxCount; k++, j++ ) - { - /* read the (signed) byte deltas */ - FT_Char delta; - - - if ( FT_READ_CHAR( delta ) ) - goto Exit; - - varData->deltaSet[j] = delta; - } - } - } - - Exit: - FT_FREE( dataOffsetArray ); - - return error; - } - - - static FT_Error - ft_var_load_delta_set_index_mapping( TT_Face face, - FT_ULong offset, - GX_DeltaSetIdxMap map, - GX_ItemVarStore itemStore ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - FT_Error error; - - FT_UShort format; - FT_UInt entrySize; - FT_UInt innerBitCount; - FT_UInt innerIndexMask; - FT_UInt i, j; - - - if ( FT_STREAM_SEEK( offset ) || - FT_READ_USHORT( format ) || - FT_READ_USHORT( map->mapCount ) ) - goto Exit; - - if ( format & 0xFFC0 ) - { - FT_TRACE2(( "bad map format %d\n", format )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* bytes per entry: 1, 2, 3, or 4 */ - entrySize = ( ( format & 0x0030 ) >> 4 ) + 1; - innerBitCount = ( format & 0x000F ) + 1; - innerIndexMask = ( 1 << innerBitCount ) - 1; - - if ( FT_NEW_ARRAY( map->innerIndex, map->mapCount ) ) - goto Exit; - - if ( FT_NEW_ARRAY( map->outerIndex, map->mapCount ) ) - goto Exit; - - for ( i = 0; i < map->mapCount; i++ ) - { - FT_UInt mapData = 0; - FT_UInt outerIndex, innerIndex; - - - /* read map data one unsigned byte at a time, big endian */ - for ( j = 0; j < entrySize; j++ ) - { - FT_Byte data; - - - if ( FT_READ_BYTE( data ) ) - goto Exit; - - mapData = ( mapData << 8 ) | data; - } - - outerIndex = mapData >> innerBitCount; - - if ( outerIndex >= itemStore->dataCount ) - { - FT_TRACE2(( "outerIndex[%d] == %d out of range\n", - i, - outerIndex )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - map->outerIndex[i] = outerIndex; - - innerIndex = mapData & innerIndexMask; - - if ( innerIndex >= itemStore->varData[outerIndex].itemCount ) - { - FT_TRACE2(( "innerIndex[%d] == %d out of range\n", - i, - innerIndex )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - map->innerIndex[i] = innerIndex; - } - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_hvvar */ - /* */ - /* <Description> */ - /* If `vertical' is zero, parse the `HVAR' table and set */ - /* `blend->hvar_loaded' to TRUE. On success, `blend->hvar_checked' */ - /* is set to TRUE. */ - /* */ - /* If `vertical' is not zero, parse the `VVAR' table and set */ - /* `blend->vvar_loaded' to TRUE. On success, `blend->vvar_checked' */ - /* is set to TRUE. */ - /* */ - /* Some memory may remain allocated on error; it is always freed in */ - /* `tt_done_blend', however. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - static FT_Error - ft_var_load_hvvar( TT_Face face, - FT_Bool vertical ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - GX_Blend blend = face->blend; - - GX_HVVarTable table; - - FT_Error error; - FT_UShort majorVersion; - FT_ULong table_len; - FT_ULong table_offset; - FT_ULong store_offset; - FT_ULong widthMap_offset; - - - if ( vertical ) - { - blend->vvar_loaded = TRUE; - - FT_TRACE2(( "VVAR " )); - - error = face->goto_table( face, TTAG_VVAR, stream, &table_len ); - } - else - { - blend->hvar_loaded = TRUE; - - FT_TRACE2(( "HVAR " )); - - error = face->goto_table( face, TTAG_HVAR, stream, &table_len ); - } - - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - goto Exit; - } - - table_offset = FT_STREAM_POS(); - - /* skip minor version */ - if ( FT_READ_USHORT( majorVersion ) || - FT_STREAM_SKIP( 2 ) ) - goto Exit; - - if ( majorVersion != 1 ) - { - FT_TRACE2(( "bad table version %d\n", majorVersion )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( FT_READ_ULONG( store_offset ) || - FT_READ_ULONG( widthMap_offset ) ) - goto Exit; - - if ( vertical ) - { - if ( FT_NEW( blend->vvar_table ) ) - goto Exit; - table = blend->vvar_table; - } - else - { - if ( FT_NEW( blend->hvar_table ) ) - goto Exit; - table = blend->hvar_table; - } - - error = ft_var_load_item_variation_store( - face, - table_offset + store_offset, - &table->itemStore ); - if ( error ) - goto Exit; - - if ( widthMap_offset ) - { - error = ft_var_load_delta_set_index_mapping( - face, - table_offset + widthMap_offset, - &table->widthMap, - &table->itemStore ); - if ( error ) - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - error = FT_Err_Ok; - - Exit: - if ( !error ) - { - if ( vertical ) - { - blend->vvar_checked = TRUE; - - /* FreeType doesn't provide functions to quickly retrieve */ - /* TSB, BSB, or VORG values; we thus don't have to implement */ - /* support for those three item variation stores. */ - - face->variation_support |= TT_FACE_FLAG_VAR_VADVANCE; - } - else - { - blend->hvar_checked = TRUE; - - /* FreeType doesn't provide functions to quickly retrieve */ - /* LSB or RSB values; we thus don't have to implement */ - /* support for those two item variation stores. */ - - face->variation_support |= TT_FACE_FLAG_VAR_HADVANCE; - } - } - - return error; - } - - - static FT_Int - ft_var_get_item_delta( TT_Face face, - GX_ItemVarStore itemStore, - FT_UInt outerIndex, - FT_UInt innerIndex ) - { - GX_ItemVarData varData; - FT_Short* deltaSet; - - FT_UInt master, j; - FT_Fixed netAdjustment = 0; /* accumulated adjustment */ - FT_Fixed scaledDelta; - FT_Fixed delta; - - - /* See pseudo code from `Font Variations Overview' */ - /* in the OpenType specification. */ - - varData = &itemStore->varData[outerIndex]; - deltaSet = &varData->deltaSet[varData->regionIdxCount * innerIndex]; - - /* outer loop steps through master designs to be blended */ - for ( master = 0; master < varData->regionIdxCount; master++ ) - { - FT_Fixed scalar = FT_FIXED_ONE; - FT_UInt regionIndex = varData->regionIndices[master]; - - GX_AxisCoords axis = itemStore->varRegionList[regionIndex].axisList; - - - /* inner loop steps through axes in this region */ - for ( j = 0; j < itemStore->axisCount; j++, axis++ ) - { - FT_Fixed axisScalar; - - - /* compute the scalar contribution of this axis; */ - /* ignore invalid ranges */ - if ( axis->startCoord > axis->peakCoord || - axis->peakCoord > axis->endCoord ) - axisScalar = FT_FIXED_ONE; - - else if ( axis->startCoord < 0 && - axis->endCoord > 0 && - axis->peakCoord != 0 ) - axisScalar = FT_FIXED_ONE; - - /* peak of 0 means ignore this axis */ - else if ( axis->peakCoord == 0 ) - axisScalar = FT_FIXED_ONE; - - /* ignore this region if coords are out of range */ - else if ( face->blend->normalizedcoords[j] < axis->startCoord || - face->blend->normalizedcoords[j] > axis->endCoord ) - axisScalar = 0; - - /* calculate a proportional factor */ - else - { - if ( face->blend->normalizedcoords[j] == axis->peakCoord ) - axisScalar = FT_FIXED_ONE; - else if ( face->blend->normalizedcoords[j] < axis->peakCoord ) - axisScalar = - FT_DivFix( face->blend->normalizedcoords[j] - axis->startCoord, - axis->peakCoord - axis->startCoord ); - else - axisScalar = - FT_DivFix( axis->endCoord - face->blend->normalizedcoords[j], - axis->endCoord - axis->peakCoord ); - } - - /* take product of all the axis scalars */ - scalar = FT_MulFix( scalar, axisScalar ); - - } /* per-axis loop */ - - /* get the scaled delta for this region */ - delta = FT_intToFixed( deltaSet[master] ); - scaledDelta = FT_MulFix( scalar, delta ); - - /* accumulate the adjustments from each region */ - netAdjustment = netAdjustment + scaledDelta; - - } /* per-region loop */ - - return FT_fixedToInt( netAdjustment ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_hvadvance_adjust */ - /* */ - /* <Description> */ - /* Apply `HVAR' advance width or `VVAR' advance height adjustment of */ - /* a given glyph. */ - /* */ - /* <Input> */ - /* gindex :: The glyph index. */ - /* */ - /* vertical :: If set, handle `VVAR' table. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* adelta :: Points to width or height value that gets modified. */ - /* */ - static FT_Error - tt_hvadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue, - FT_Bool vertical ) - { - FT_Error error = FT_Err_Ok; - FT_UInt innerIndex, outerIndex; - FT_Int delta; - - GX_HVVarTable table; - - - if ( !face->doblend || !face->blend ) - goto Exit; - - if ( vertical ) - { - if ( !face->blend->vvar_loaded ) - { - /* initialize vvar table */ - face->blend->vvar_error = ft_var_load_hvvar( face, 1 ); - } - - if ( !face->blend->vvar_checked ) - { - error = face->blend->vvar_error; - goto Exit; - } - - table = face->blend->vvar_table; - } - else - { - if ( !face->blend->hvar_loaded ) - { - /* initialize hvar table */ - face->blend->hvar_error = ft_var_load_hvvar( face, 0 ); - } - - if ( !face->blend->hvar_checked ) - { - error = face->blend->hvar_error; - goto Exit; - } - - table = face->blend->hvar_table; - } - - /* advance width or height adjustments are always present in an */ - /* `HVAR' or `VVAR' table; no need to test for this capability */ - - if ( table->widthMap.innerIndex ) - { - FT_UInt idx = gindex; - - - if ( idx >= table->widthMap.mapCount ) - idx = table->widthMap.mapCount - 1; - - /* trust that HVAR parser has checked indices */ - outerIndex = table->widthMap.outerIndex[idx]; - innerIndex = table->widthMap.innerIndex[idx]; - } - else - { - GX_ItemVarData varData; - - - /* no widthMap data */ - outerIndex = 0; - innerIndex = gindex; - - varData = &table->itemStore.varData[outerIndex]; - if ( gindex >= varData->itemCount ) - { - FT_TRACE2(( "gindex %d out of range\n", gindex )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - } - - delta = ft_var_get_item_delta( face, - &table->itemStore, - outerIndex, - innerIndex ); - - FT_TRACE5(( "%s value %d adjusted by %d units (%s)\n", - vertical ? "vertical height" : "horizontal width", - *avalue, - delta, - vertical ? "VVAR" : "HVAR" )); - - *avalue += delta; - - Exit: - return error; - } - - - FT_LOCAL_DEF( FT_Error ) - tt_hadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue ) - { - return tt_hvadvance_adjust( face, gindex, avalue, 0 ); - } - - - FT_LOCAL_DEF( FT_Error ) - tt_vadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue ) - { - return tt_hvadvance_adjust( face, gindex, avalue, 1 ); - } - - -#define GX_VALUE_SIZE 8 - - /* all values are FT_Short or FT_UShort entities; */ - /* we treat them consistently as FT_Short */ -#define GX_VALUE_CASE( tag, dflt ) \ - case MVAR_TAG_ ## tag : \ - p = (FT_Short*)&face->dflt; \ - break - -#define GX_GASP_CASE( idx ) \ - case MVAR_TAG_GASP_ ## idx : \ - if ( idx < face->gasp.numRanges - 1 ) \ - p = (FT_Short*)&face->gasp.gaspRanges[idx].maxPPEM; \ - else \ - p = NULL; \ - break - - - static FT_Short* - ft_var_get_value_pointer( TT_Face face, - FT_ULong mvar_tag ) - { - FT_Short* p; - - - switch ( mvar_tag ) - { - GX_GASP_CASE( 0 ); - GX_GASP_CASE( 1 ); - GX_GASP_CASE( 2 ); - GX_GASP_CASE( 3 ); - GX_GASP_CASE( 4 ); - GX_GASP_CASE( 5 ); - GX_GASP_CASE( 6 ); - GX_GASP_CASE( 7 ); - GX_GASP_CASE( 8 ); - GX_GASP_CASE( 9 ); - - GX_VALUE_CASE( CPHT, os2.sCapHeight ); - GX_VALUE_CASE( HASC, os2.sTypoAscender ); - GX_VALUE_CASE( HCLA, os2.usWinAscent ); - GX_VALUE_CASE( HCLD, os2.usWinDescent ); - GX_VALUE_CASE( HCOF, horizontal.caret_Offset ); - GX_VALUE_CASE( HCRN, horizontal.caret_Slope_Run ); - GX_VALUE_CASE( HCRS, horizontal.caret_Slope_Rise ); - GX_VALUE_CASE( HDSC, os2.sTypoDescender ); - GX_VALUE_CASE( HLGP, os2.sTypoLineGap ); - GX_VALUE_CASE( SBXO, os2.ySubscriptXOffset); - GX_VALUE_CASE( SBXS, os2.ySubscriptXSize ); - GX_VALUE_CASE( SBYO, os2.ySubscriptYOffset ); - GX_VALUE_CASE( SBYS, os2.ySubscriptYSize ); - GX_VALUE_CASE( SPXO, os2.ySuperscriptXOffset ); - GX_VALUE_CASE( SPXS, os2.ySuperscriptXSize ); - GX_VALUE_CASE( SPYO, os2.ySuperscriptYOffset ); - GX_VALUE_CASE( SPYS, os2.ySuperscriptYSize ); - GX_VALUE_CASE( STRO, os2.yStrikeoutPosition ); - GX_VALUE_CASE( STRS, os2.yStrikeoutSize ); - GX_VALUE_CASE( UNDO, postscript.underlinePosition ); - GX_VALUE_CASE( UNDS, postscript.underlineThickness ); - GX_VALUE_CASE( VASC, vertical.Ascender ); - GX_VALUE_CASE( VCOF, vertical.caret_Offset ); - GX_VALUE_CASE( VCRN, vertical.caret_Slope_Run ); - GX_VALUE_CASE( VCRS, vertical.caret_Slope_Rise ); - GX_VALUE_CASE( VDSC, vertical.Descender ); - GX_VALUE_CASE( VLGP, vertical.Line_Gap ); - GX_VALUE_CASE( XHGT, os2.sxHeight ); - - default: - /* ignore unknown tag */ - p = NULL; - } - - return p; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_mvar */ - /* */ - /* <Description> */ - /* Parse the `MVAR' table. */ - /* */ - /* Some memory may remain allocated on error; it is always freed in */ - /* `tt_done_blend', however. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - static void - ft_var_load_mvar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - GX_Blend blend = face->blend; - GX_ItemVarStore itemStore; - GX_Value value, limit; - - FT_Error error; - FT_UShort majorVersion; - FT_ULong table_len; - FT_ULong table_offset; - FT_UShort store_offset; - FT_ULong records_offset; - - - FT_TRACE2(( "MVAR " )); - - error = face->goto_table( face, TTAG_MVAR, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - return; - } - - table_offset = FT_STREAM_POS(); - - /* skip minor version */ - if ( FT_READ_USHORT( majorVersion ) || - FT_STREAM_SKIP( 2 ) ) - return; - - if ( majorVersion != 1 ) - { - FT_TRACE2(( "bad table version %d\n", majorVersion )); - return; - } - - if ( FT_NEW( blend->mvar_table ) ) - return; - - /* skip reserved entry and value record size */ - if ( FT_STREAM_SKIP( 4 ) || - FT_READ_USHORT( blend->mvar_table->valueCount ) || - FT_READ_USHORT( store_offset ) ) - return; - - records_offset = FT_STREAM_POS(); - - error = ft_var_load_item_variation_store( - face, - table_offset + store_offset, - &blend->mvar_table->itemStore ); - if ( error ) - return; - - if ( FT_NEW_ARRAY( blend->mvar_table->values, - blend->mvar_table->valueCount ) ) - return; - - if ( FT_STREAM_SEEK( records_offset ) || - FT_FRAME_ENTER( blend->mvar_table->valueCount * GX_VALUE_SIZE ) ) - return; - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - itemStore = &blend->mvar_table->itemStore; - - for ( ; value < limit; value++ ) - { - value->tag = FT_GET_ULONG(); - value->outerIndex = FT_GET_USHORT(); - value->innerIndex = FT_GET_USHORT(); - - if ( value->outerIndex >= itemStore->dataCount || - value->innerIndex >= itemStore->varData[value->outerIndex] - .itemCount ) - { - error = FT_THROW( Invalid_Table ); - break; - } - } - - FT_FRAME_EXIT(); - - if ( error ) - return; - - FT_TRACE2(( "loaded\n" )); - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - - /* save original values of the data MVAR is going to modify */ - for ( ; value < limit; value++ ) - { - FT_Short* p = ft_var_get_value_pointer( face, value->tag ); - - - if ( p ) - value->unmodified = *p; -#ifdef FT_DEBUG_LEVEL_TRACE - else - FT_TRACE1(( "ft_var_load_mvar: Ignoring unknown tag `%c%c%c%c'\n", - (FT_Char)( value->tag >> 24 ), - (FT_Char)( value->tag >> 16 ), - (FT_Char)( value->tag >> 8 ), - (FT_Char)( value->tag ) )); -#endif - } - - face->variation_support |= TT_FACE_FLAG_VAR_MVAR; - } - - - static FT_Error - tt_size_reset_iterator( FT_ListNode node, - void* user ) - { - TT_Size size = (TT_Size)node->data; - - FT_UNUSED( user ); - - - tt_size_reset( size, 1 ); - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_apply_mvar */ - /* */ - /* <Description> */ - /* Apply `MVAR' table adjustments. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - FT_LOCAL_DEF( void ) - tt_apply_mvar( TT_Face face ) - { - GX_Blend blend = face->blend; - GX_Value value, limit; - - - if ( !( face->variation_support & TT_FACE_FLAG_VAR_MVAR ) ) - return; - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - - for ( ; value < limit; value++ ) - { - FT_Short* p = ft_var_get_value_pointer( face, value->tag ); - FT_Int delta; - - - delta = ft_var_get_item_delta( face, - &blend->mvar_table->itemStore, - value->outerIndex, - value->innerIndex ); - - if ( p ) - { - FT_TRACE5(( "value %c%c%c%c (%d units) adjusted by %d units (MVAR)\n", - (FT_Char)( value->tag >> 24 ), - (FT_Char)( value->tag >> 16 ), - (FT_Char)( value->tag >> 8 ), - (FT_Char)( value->tag ), - value->unmodified, - delta )); - - /* since we handle both signed and unsigned values as FT_Short, */ - /* ensure proper overflow arithmetic */ - *p = (FT_Short)( value->unmodified + (FT_Short)delta ); - } - } - - /* adjust all derived values */ - { - FT_Face root = &face->root; - - - if ( face->os2.version != 0xFFFFU ) - { - if ( face->os2.sTypoAscender || face->os2.sTypoDescender ) - { - root->ascender = face->os2.sTypoAscender; - root->descender = face->os2.sTypoDescender; - - root->height = root->ascender - root->descender + - face->os2.sTypoLineGap; - } - else - { - root->ascender = (FT_Short)face->os2.usWinAscent; - root->descender = -(FT_Short)face->os2.usWinDescent; - - root->height = root->ascender - root->descender; - } - } - - root->underline_position = face->postscript.underlinePosition - - face->postscript.underlineThickness / 2; - root->underline_thickness = face->postscript.underlineThickness; - - /* iterate over all FT_Size objects and call `tt_size_reset' */ - /* to propagate the metrics changes */ - FT_List_Iterate( &root->sizes_list, - tt_size_reset_iterator, - NULL ); - } - } - - - typedef struct GX_GVar_Head_ - { - FT_Long version; - FT_UShort axisCount; - FT_UShort globalCoordCount; - FT_ULong offsetToCoord; - FT_UShort glyphCount; - FT_UShort flags; - FT_ULong offsetToData; - - } GX_GVar_Head; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_gvar */ - /* */ - /* <Description> */ - /* Parse the `gvar' table if present. If `fvar' is there, `gvar' had */ - /* better be there too. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - static FT_Error - ft_var_load_gvar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - FT_Error error; - FT_UInt i, j; - FT_ULong table_len; - FT_ULong gvar_start; - FT_ULong offsetToData; - GX_GVar_Head gvar_head; - - static const FT_Frame_Field gvar_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_GVar_Head - - FT_FRAME_START( 20 ), - FT_FRAME_LONG ( version ), - FT_FRAME_USHORT( axisCount ), - FT_FRAME_USHORT( globalCoordCount ), - FT_FRAME_ULONG ( offsetToCoord ), - FT_FRAME_USHORT( glyphCount ), - FT_FRAME_USHORT( flags ), - FT_FRAME_ULONG ( offsetToData ), - FT_FRAME_END - }; - - - FT_TRACE2(( "GVAR " )); - - if ( FT_SET_ERROR( face->goto_table( face, - TTAG_gvar, - stream, - &table_len ) ) ) - { - FT_TRACE2(( "is missing\n" )); - goto Exit; - } - - gvar_start = FT_STREAM_POS( ); - if ( FT_STREAM_READ_FIELDS( gvar_fields, &gvar_head ) ) - goto Exit; - - if ( gvar_head.version != 0x00010000L ) - { - FT_TRACE1(( "bad table version\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis ) - { - FT_TRACE1(( "ft_var_load_gvar: number of axes in `gvar' and `cvar'\n" - " table are different\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* rough sanity check, ignoring offsets */ - if ( (FT_ULong)gvar_head.globalCoordCount * gvar_head.axisCount > - table_len / 2 ) - { - FT_TRACE1(( "ft_var_load_gvar:" - " invalid number of global coordinates\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* rough sanity check: offsets can be either 2 or 4 bytes */ - if ( (FT_ULong)gvar_head.glyphCount * - ( ( gvar_head.flags & 1 ) ? 4 : 2 ) > table_len ) - { - FT_TRACE1(( "ft_var_load_gvar: invalid number of glyphs\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - - blend->gvar_size = table_len; - blend->tuplecount = gvar_head.globalCoordCount; - blend->gv_glyphcnt = gvar_head.glyphCount; - offsetToData = gvar_start + gvar_head.offsetToData; - - FT_TRACE5(( "gvar: there are %d shared coordinates:\n", - blend->tuplecount )); - - if ( FT_NEW_ARRAY( blend->glyphoffsets, blend->gv_glyphcnt + 1 ) ) - goto Exit; - - if ( gvar_head.flags & 1 ) - { - /* long offsets (one more offset than glyphs, to mark size of last) */ - if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 4L ) ) - goto Exit; - - for ( i = 0; i <= blend->gv_glyphcnt; i++ ) - blend->glyphoffsets[i] = offsetToData + FT_GET_ULONG(); - - FT_FRAME_EXIT(); - } - else - { - /* short offsets (one more offset than glyphs, to mark size of last) */ - if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 2L ) ) - goto Exit; - - for ( i = 0; i <= blend->gv_glyphcnt; i++ ) - blend->glyphoffsets[i] = offsetToData + FT_GET_USHORT() * 2; - /* XXX: Undocumented: `*2'! */ - - FT_FRAME_EXIT(); - } - - if ( blend->tuplecount != 0 ) - { - if ( FT_NEW_ARRAY( blend->tuplecoords, - gvar_head.axisCount * blend->tuplecount ) ) - goto Exit; - - if ( FT_STREAM_SEEK( gvar_start + gvar_head.offsetToCoord ) || - FT_FRAME_ENTER( blend->tuplecount * gvar_head.axisCount * 2L ) ) - goto Exit; - - for ( i = 0; i < blend->tuplecount; i++ ) - { - FT_TRACE5(( " [ " )); - for ( j = 0; j < (FT_UInt)gvar_head.axisCount; j++ ) - { - blend->tuplecoords[i * gvar_head.axisCount + j] = - FT_GET_SHORT() * 4; /* convert to FT_Fixed */ - FT_TRACE5(( "%.5f ", - blend->tuplecoords[i * gvar_head.axisCount + j] / 65536.0 )); - } - FT_TRACE5(( "]\n" )); - } - - FT_TRACE5(( "\n" )); - - FT_FRAME_EXIT(); - } - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_apply_tuple */ - /* */ - /* <Description> */ - /* Figure out whether a given tuple (design) applies to the current */ - /* blend, and if so, what is the scaling factor. */ - /* */ - /* <Input> */ - /* blend :: The current blend of the font. */ - /* */ - /* tupleIndex :: A flag saying whether this is an intermediate */ - /* tuple or not. */ - /* */ - /* tuple_coords :: The coordinates of the tuple in normalized axis */ - /* units. */ - /* */ - /* im_start_coords :: The initial coordinates where this tuple starts */ - /* to apply (for intermediate coordinates). */ - /* */ - /* im_end_coords :: The final coordinates after which this tuple no */ - /* longer applies (for intermediate coordinates). */ - /* */ - /* <Return> */ - /* An FT_Fixed value containing the scaling factor. */ - /* */ - static FT_Fixed - ft_var_apply_tuple( GX_Blend blend, - FT_UShort tupleIndex, - FT_Fixed* tuple_coords, - FT_Fixed* im_start_coords, - FT_Fixed* im_end_coords ) - { - FT_UInt i; - FT_Fixed apply = 0x10000L; - - - for ( i = 0; i < blend->num_axis; i++ ) - { - FT_TRACE6(( " axis coordinate %d (%.5f):\n", - i, blend->normalizedcoords[i] / 65536.0 )); - if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) - FT_TRACE6(( " intermediate coordinates %d (%.5f, %.5f):\n", - i, - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - - /* It's not clear why (for intermediate tuples) we don't need */ - /* to check against start/end -- the documentation says we don't. */ - /* Similarly, it's unclear why we don't need to scale along the */ - /* axis. */ - - if ( tuple_coords[i] == 0 ) - { - FT_TRACE6(( " tuple coordinate is zero, ignored\n", i )); - continue; - } - - if ( blend->normalizedcoords[i] == 0 ) - { - FT_TRACE6(( " axis coordinate is zero, stop\n" )); - apply = 0; - break; - } - - if ( blend->normalizedcoords[i] == tuple_coords[i] ) - { - FT_TRACE6(( " tuple coordinate value %.5f fits perfectly\n", - tuple_coords[i] / 65536.0 )); - /* `apply' does not change */ - continue; - } - - if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) - { - /* not an intermediate tuple */ - - if ( blend->normalizedcoords[i] < FT_MIN( 0, tuple_coords[i] ) || - blend->normalizedcoords[i] > FT_MAX( 0, tuple_coords[i] ) ) - { - FT_TRACE6(( " tuple coordinate value %.5f is exceeded, stop\n", - tuple_coords[i] / 65536.0 )); - apply = 0; - break; - } - - FT_TRACE6(( " tuple coordinate value %.5f fits\n", - tuple_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - blend->normalizedcoords[i], - tuple_coords[i] ); - } - else - { - /* intermediate tuple */ - - if ( blend->normalizedcoords[i] < im_start_coords[i] || - blend->normalizedcoords[i] > im_end_coords[i] ) - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] is exceeded," - " stop\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = 0; - break; - } - - else if ( blend->normalizedcoords[i] < tuple_coords[i] ) - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] fits\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - blend->normalizedcoords[i] - im_start_coords[i], - tuple_coords[i] - im_start_coords[i] ); - } - - else - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] fits\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - im_end_coords[i] - blend->normalizedcoords[i], - im_end_coords[i] - tuple_coords[i] ); - } - } - } - - FT_TRACE6(( " apply factor is %.5f\n", apply / 65536.0 )); - - return apply; - } - - - /* convert from design coordinates to normalized coordinates */ - - static void - ft_var_to_normalized( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Fixed* normalized ) - { - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i, j; - FT_Var_Axis* a; - GX_AVarSegment av; - - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_to_normalized:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - /* Axis normalization is a two-stage process. First we normalize */ - /* based on the [min,def,max] values for the axis to be [-1,0,1]. */ - /* Then, if there's an `avar' table, we renormalize this range. */ - - FT_TRACE5(( "design coordinates:\n" )); - - a = mmvar->axis; - for ( i = 0; i < num_coords; i++, a++ ) - { - FT_Fixed coord = coords[i]; - - - FT_TRACE5(( " %.5f\n", coord / 65536.0 )); - if ( coord > a->maximum || coord < a->minimum ) - { - FT_TRACE1(( - "ft_var_to_normalized: design coordinate %.5f\n" - " is out of range [%.5f;%.5f]; clamping\n", - coord / 65536.0, - a->minimum / 65536.0, - a->maximum / 65536.0 )); - - if ( coord > a->maximum) - coord = a->maximum; - else - coord = a->minimum; - } - - if ( coord < a->def ) - normalized[i] = -FT_DivFix( coords[i] - a->def, - a->minimum - a->def ); - else if ( coord > a->def ) - normalized[i] = FT_DivFix( coords[i] - a->def, - a->maximum - a->def ); - else - normalized[i] = 0; - } - - FT_TRACE5(( "\n" )); - - for ( ; i < mmvar->num_axis; i++ ) - normalized[i] = 0; - - if ( blend->avar_segment ) - { - FT_TRACE5(( "normalized design coordinates" - " before applying `avar' data:\n" )); - - av = blend->avar_segment; - for ( i = 0; i < mmvar->num_axis; i++, av++ ) - { - for ( j = 1; j < (FT_UInt)av->pairCount; j++ ) - { - if ( normalized[i] < av->correspondence[j].fromCoord ) - { - FT_TRACE5(( " %.5f\n", normalized[i] / 65536.0 )); - - normalized[i] = - FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord, - av->correspondence[j].toCoord - - av->correspondence[j - 1].toCoord, - av->correspondence[j].fromCoord - - av->correspondence[j - 1].fromCoord ) + - av->correspondence[j - 1].toCoord; - break; - } - } - } - } - } - - - /* convert from normalized coordinates to design coordinates */ - - static void - ft_var_to_design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Fixed* design ) - { - GX_Blend blend; - FT_MM_Var* mmvar; - FT_Var_Axis* a; - - FT_UInt i, j, nc; - - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "ft_var_to_design:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - design[i] = coords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - design[i] = 0; - } - - for ( ; i < num_coords; i++ ) - design[i] = 0; - - if ( blend->avar_segment ) - { - GX_AVarSegment av = blend->avar_segment; - - - FT_TRACE5(( "design coordinates" - " after removing `avar' distortion:\n" )); - - for ( i = 0; i < nc; i++, av++ ) - { - for ( j = 1; j < (FT_UInt)av->pairCount; j++ ) - { - if ( design[i] < av->correspondence[j].toCoord ) - { - design[i] = - FT_MulDiv( design[i] - av->correspondence[j - 1].toCoord, - av->correspondence[j].fromCoord - - av->correspondence[j - 1].fromCoord, - av->correspondence[j].toCoord - - av->correspondence[j - 1].toCoord ) + - av->correspondence[j - 1].fromCoord; - - FT_TRACE5(( " %.5f\n", design[i] / 65536.0 )); - break; - } - } - } - } - - mmvar = blend->mmvar; - a = mmvar->axis; - - for ( i = 0; i < nc; i++, a++ ) - { - if ( design[i] < 0 ) - design[i] = a->def + FT_MulFix( design[i], - a->def - a->minimum ); - else if ( design[i] > 0 ) - design[i] = a->def + FT_MulFix( design[i], - a->maximum - a->def ); - else - design[i] = a->def; - } - } - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** MULTIPLE MASTERS SERVICE FUNCTIONS *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - typedef struct GX_FVar_Head_ - { - FT_Long version; - FT_UShort offsetToData; - FT_UShort axisCount; - FT_UShort axisSize; - FT_UShort instanceCount; - FT_UShort instanceSize; - - } GX_FVar_Head; - - - typedef struct fvar_axis_ - { - FT_ULong axisTag; - FT_Fixed minValue; - FT_Fixed defaultValue; - FT_Fixed maxValue; - FT_UShort flags; - FT_UShort nameID; - - } GX_FVar_Axis; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_MM_Var */ - /* */ - /* <Description> */ - /* Check that the font's `fvar' table is valid, parse it, and return */ - /* those data. It also loads (and parses) the `MVAR' table, if */ - /* possible. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* TT_Get_MM_Var initializes the blend structure. */ - /* */ - /* <Output> */ - /* master :: The `fvar' data (must be freed by caller). Can be NULL, */ - /* which makes this function simply load MM support. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_MM_Var( TT_Face face, - FT_MM_Var* *master ) - { - FT_Stream stream = face->root.stream; - FT_Memory memory = face->root.memory; - FT_ULong table_len; - FT_Error error = FT_Err_Ok; - FT_ULong fvar_start; - FT_UInt i, j; - FT_MM_Var* mmvar = NULL; - FT_Fixed* next_coords; - FT_Fixed* nsc; - FT_String* next_name; - FT_Var_Axis* a; - FT_Fixed* c; - FT_Var_Named_Style* ns; - GX_FVar_Head fvar_head; - FT_Bool usePsName; - FT_UInt num_instances; - - static const FT_Frame_Field fvar_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_FVar_Head - - FT_FRAME_START( 16 ), - FT_FRAME_LONG ( version ), - FT_FRAME_USHORT ( offsetToData ), - FT_FRAME_SKIP_SHORT, - FT_FRAME_USHORT ( axisCount ), - FT_FRAME_USHORT ( axisSize ), - FT_FRAME_USHORT ( instanceCount ), - FT_FRAME_USHORT ( instanceSize ), - FT_FRAME_END - }; - - static const FT_Frame_Field fvaraxis_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_FVar_Axis - - FT_FRAME_START( 20 ), - FT_FRAME_ULONG ( axisTag ), - FT_FRAME_LONG ( minValue ), - FT_FRAME_LONG ( defaultValue ), - FT_FRAME_LONG ( maxValue ), - FT_FRAME_USHORT( flags ), - FT_FRAME_USHORT( nameID ), - FT_FRAME_END - }; - - - /* read the font data and set up the internal representation */ - /* if not already done */ - - if ( !face->blend ) - { - FT_TRACE2(( "FVAR " )); - - /* both `fvar' and `gvar' must be present */ - if ( FT_SET_ERROR( face->goto_table( face, TTAG_gvar, - stream, &table_len ) ) ) - { - /* CFF2 is an alternate to gvar here */ - if ( FT_SET_ERROR( face->goto_table( face, TTAG_CFF2, - stream, &table_len ) ) ) - { - FT_TRACE1(( "\n" - "TT_Get_MM_Var: `gvar' or `CFF2' table is missing\n" )); - goto Exit; - } - } - - if ( FT_SET_ERROR( face->goto_table( face, TTAG_fvar, - stream, &table_len ) ) ) - { - FT_TRACE1(( "is missing\n" )); - goto Exit; - } - - fvar_start = FT_STREAM_POS( ); - - /* the validity of the `fvar' header data was already checked */ - /* in function `sfnt_init_face' */ - if ( FT_STREAM_READ_FIELDS( fvar_fields, &fvar_head ) ) - goto Exit; - - usePsName = FT_BOOL( fvar_head.instanceSize == - 6 + 4 * fvar_head.axisCount ); - - FT_TRACE2(( "loaded\n" )); - - FT_TRACE5(( "number of GX style axes: %d\n", fvar_head.axisCount )); - - if ( FT_NEW( face->blend ) ) - goto Exit; - - /* `num_instances' holds the number of all named instances, */ - /* including the default instance which might be missing */ - /* in fvar's table of named instances */ - num_instances = face->root.style_flags >> 16; - - /* cannot overflow 32-bit arithmetic because of the size limits */ - /* used in the `fvar' table validity check in `sfnt_init_face' */ - face->blend->mmvar_len = - sizeof ( FT_MM_Var ) + - fvar_head.axisCount * sizeof ( FT_Var_Axis ) + - num_instances * sizeof ( FT_Var_Named_Style ) + - num_instances * fvar_head.axisCount * sizeof ( FT_Fixed ) + - 5 * fvar_head.axisCount; - - if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) - goto Exit; - face->blend->mmvar = mmvar; - - /* set up pointers and offsets into the `mmvar' array; */ - /* the data gets filled in later on */ - - mmvar->num_axis = - fvar_head.axisCount; - mmvar->num_designs = - ~0U; /* meaningless in this context; each glyph */ - /* may have a different number of designs */ - /* (or tuples, as called by Apple) */ - mmvar->num_namedstyles = - num_instances; - mmvar->axis = - (FT_Var_Axis*)&( mmvar[1] ); - mmvar->namedstyle = - (FT_Var_Named_Style*)&( mmvar->axis[fvar_head.axisCount] ); - - next_coords = - (FT_Fixed*)&( mmvar->namedstyle[num_instances] ); - for ( i = 0; i < num_instances; i++ ) - { - mmvar->namedstyle[i].coords = next_coords; - next_coords += fvar_head.axisCount; - } - - next_name = (FT_String*)next_coords; - for ( i = 0; i < fvar_head.axisCount; i++ ) - { - mmvar->axis[i].name = next_name; - next_name += 5; - } - - /* now fill in the data */ - - if ( FT_STREAM_SEEK( fvar_start + fvar_head.offsetToData ) ) - goto Exit; - - a = mmvar->axis; - for ( i = 0; i < fvar_head.axisCount; i++ ) - { - GX_FVar_Axis axis_rec; - - - if ( FT_STREAM_READ_FIELDS( fvaraxis_fields, &axis_rec ) ) - goto Exit; - a->tag = axis_rec.axisTag; - a->minimum = axis_rec.minValue; - a->def = axis_rec.defaultValue; - a->maximum = axis_rec.maxValue; - a->strid = axis_rec.nameID; - - a->name[0] = (FT_String)( a->tag >> 24 ); - a->name[1] = (FT_String)( ( a->tag >> 16 ) & 0xFF ); - a->name[2] = (FT_String)( ( a->tag >> 8 ) & 0xFF ); - a->name[3] = (FT_String)( ( a->tag ) & 0xFF ); - a->name[4] = '\0'; - - if ( a->minimum > a->def || - a->def > a->maximum ) - { - FT_TRACE2(( "TT_Get_MM_Var:" - " invalid \"%s\" axis record; disabling\n", - a->name )); - - a->minimum = a->def; - a->maximum = a->def; - } - - FT_TRACE5(( " \"%s\": minimum=%.5f, default=%.5f, maximum=%.5f\n", - a->name, - a->minimum / 65536.0, - a->def / 65536.0, - a->maximum / 65536.0 )); - - a++; - } - - FT_TRACE5(( "\n" )); - - /* named instance coordinates are stored as design coordinates; */ - /* we have to convert them to normalized coordinates also */ - if ( FT_NEW_ARRAY( face->blend->normalized_stylecoords, - fvar_head.axisCount * num_instances ) ) - goto Exit; - - if ( fvar_head.instanceCount && !face->blend->avar_loaded ) - ft_var_load_avar( face ); - - ns = mmvar->namedstyle; - nsc = face->blend->normalized_stylecoords; - for ( i = 0; i < fvar_head.instanceCount; i++, ns++ ) - { - /* PostScript names add 2 bytes to the instance record size */ - if ( FT_FRAME_ENTER( ( usePsName ? 6L : 4L ) + - 4L * fvar_head.axisCount ) ) - goto Exit; - - ns->strid = FT_GET_USHORT(); - (void) /* flags = */ FT_GET_USHORT(); - - c = ns->coords; - for ( j = 0; j < fvar_head.axisCount; j++, c++ ) - *c = FT_GET_LONG(); - - if ( usePsName ) - ns->psid = FT_GET_USHORT(); - - ft_var_to_normalized( face, - fvar_head.axisCount, - ns->coords, - nsc ); - nsc += fvar_head.axisCount; - - FT_FRAME_EXIT(); - } - - if ( num_instances != fvar_head.instanceCount ) - { - SFNT_Service sfnt = (SFNT_Service)face->sfnt; - - FT_Int found, dummy1, dummy2; - FT_UInt strid = 0xFFFFFFFFUL; - - - /* the default instance is missing in array the */ - /* of named instances; try to synthesize an entry */ - found = sfnt->get_name_id( face, - TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY, - &dummy1, - &dummy2 ); - if ( found ) - strid = TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY; - else - { - found = sfnt->get_name_id( face, - TT_NAME_ID_FONT_SUBFAMILY, - &dummy1, - &dummy2 ); - if ( found ) - strid = TT_NAME_ID_FONT_SUBFAMILY; - } - - if ( found ) - { - found = sfnt->get_name_id( face, - TT_NAME_ID_PS_NAME, - &dummy1, - &dummy2 ); - if ( found ) - { - FT_TRACE5(( "TT_Get_MM_Var:" - " Adding default instance to named instances\n" )); - - ns = &mmvar->namedstyle[fvar_head.instanceCount]; - - ns->strid = strid; - ns->psid = TT_NAME_ID_PS_NAME; - - a = mmvar->axis; - c = ns->coords; - for ( j = 0; j < fvar_head.axisCount; j++, a++, c++ ) - *c = a->def; - } - } - } - - ft_var_load_mvar( face ); - } - - /* fill the output array if requested */ - - if ( master ) - { - FT_UInt n; - - - if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) - goto Exit; - FT_MEM_COPY( mmvar, face->blend->mmvar, face->blend->mmvar_len ); - - mmvar->axis = - (FT_Var_Axis*)&( mmvar[1] ); - mmvar->namedstyle = - (FT_Var_Named_Style*)&( mmvar->axis[mmvar->num_axis] ); - next_coords = - (FT_Fixed*)&( mmvar->namedstyle[mmvar->num_namedstyles] ); - - for ( n = 0; n < mmvar->num_namedstyles; n++ ) - { - mmvar->namedstyle[n].coords = next_coords; - next_coords += mmvar->num_axis; - } - - a = mmvar->axis; - next_name = (FT_String*)next_coords; - for ( n = 0; n < mmvar->num_axis; n++ ) - { - a->name = next_name; - - /* standard PostScript names for some standard apple tags */ - if ( a->tag == TTAG_wght ) - a->name = (char*)"Weight"; - else if ( a->tag == TTAG_wdth ) - a->name = (char*)"Width"; - else if ( a->tag == TTAG_opsz ) - a->name = (char*)"OpticalSize"; - else if ( a->tag == TTAG_slnt ) - a->name = (char*)"Slant"; - - next_name += 5; - a++; - } - - *master = mmvar; - } - - Exit: - return error; - } - - - static FT_Error - tt_set_mm_blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Bool set_design_coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i, j; - FT_Bool is_default_instance = 1; - FT_Memory memory = face->root.memory; - - enum - { - mcvt_retain, - mcvt_modify, - mcvt_load - - } manageCvt; - - - face->doblend = FALSE; - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - goto Exit; - } - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "TT_Set_MM_Blend:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - FT_TRACE5(( "normalized design coordinates:\n" )); - - for ( i = 0; i < num_coords; i++ ) - { - FT_TRACE5(( " %.5f\n", coords[i] / 65536.0 )); - if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L ) - { - FT_TRACE1(( "TT_Set_MM_Blend: normalized design coordinate %.5f\n" - " is out of range [-1;1]\n", - coords[i] / 65536.0 )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( coords[i] != 0 ) - is_default_instance = 0; - } - - FT_TRACE5(( "\n" )); - - if ( !face->is_cff2 && !blend->glyphoffsets ) - if ( FT_SET_ERROR( ft_var_load_gvar( face ) ) ) - goto Exit; - - if ( !blend->coords ) - { - if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) ) - goto Exit; - } - - if ( !blend->normalizedcoords ) - { - if ( FT_NEW_ARRAY( blend->normalizedcoords, mmvar->num_axis ) ) - goto Exit; - - manageCvt = mcvt_modify; - - /* If we have not set the blend coordinates before this, then the */ - /* cvt table will still be what we read from the `cvt ' table and */ - /* we don't need to reload it. We may need to change it though... */ - } - else - { - manageCvt = mcvt_retain; - - for ( i = 0; i < num_coords; i++ ) - { - if ( blend->normalizedcoords[i] != coords[i] ) - { - manageCvt = mcvt_load; - break; - } - } - - for ( ; i < mmvar->num_axis; i++ ) - { - if ( blend->normalizedcoords[i] != 0 ) - { - manageCvt = mcvt_load; - break; - } - } - - /* If we don't change the blend coords then we don't need to do */ - /* anything to the cvt table. It will be correct. Otherwise we */ - /* no longer have the original cvt (it was modified when we set */ - /* the blend last time), so we must reload and then modify it. */ - } - - blend->num_axis = mmvar->num_axis; - FT_MEM_COPY( blend->normalizedcoords, - coords, - num_coords * sizeof ( FT_Fixed ) ); - - if ( set_design_coords ) - ft_var_to_design( face, - num_coords, - blend->normalizedcoords, - blend->coords ); - - face->doblend = TRUE; - - if ( face->cvt ) - { - switch ( manageCvt ) - { - case mcvt_load: - /* The cvt table has been loaded already; every time we change the */ - /* blend we may need to reload and remodify the cvt table. */ - FT_FREE( face->cvt ); - face->cvt = NULL; - - error = tt_face_load_cvt( face, face->root.stream ); - break; - - case mcvt_modify: - /* The original cvt table is in memory. All we need to do is */ - /* apply the `cvar' table (if any). */ - error = tt_face_vary_cvt( face, face->root.stream ); - break; - - case mcvt_retain: - /* The cvt table is correct for this set of coordinates. */ - break; - } - } - - /* check whether the current variation tuple coincides */ - /* with a named instance */ - - for ( i = 0; i < blend->mmvar->num_namedstyles; i++ ) - { - FT_Fixed* nsc = blend->normalized_stylecoords + i * blend->num_axis; - FT_Fixed* ns = blend->normalizedcoords; - - - for ( j = 0; j < blend->num_axis; j++, nsc++, ns++ ) - { - if ( *nsc != *ns ) - break; - } - - if ( j == blend->num_axis ) - break; - } - - /* adjust named instance index */ - face->root.face_index &= 0xFFFF; - if ( i < blend->mmvar->num_namedstyles ) - face->root.face_index |= ( i + 1 ) << 16; - - face->is_default_instance = is_default_instance; - - /* enforce recomputation of the PostScript name; */ - FT_FREE( face->postscript_name ); - face->postscript_name = NULL; - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Set_MM_Blend */ - /* */ - /* <Description> */ - /* Set the blend (normalized) coordinates for this instance of the */ - /* font. Check that the `gvar' table is reasonable and does some */ - /* initial preparation. */ - /* */ - /* <InOut> */ - /* face :: The font. */ - /* Initialize the blend structure with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use the default value (0) for the remaining axes. */ - /* */ - /* coords :: An array of `num_coords', each between [-1,1]. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Set_MM_Blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - return tt_set_mm_blend( face, num_coords, coords, 1 ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_MM_Blend */ - /* */ - /* <Description> */ - /* Get the blend (normalized) coordinates for this instance of the */ - /* font. */ - /* */ - /* <InOut> */ - /* face :: The font. */ - /* Initialize the blend structure with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, set the excess */ - /* values to 0. */ - /* */ - /* coords :: An array of `num_coords', each between [-1,1]. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_MM_Blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_UInt i, nc; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - return error; - } - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "TT_Get_MM_Blend:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - coords[i] = blend->normalizedcoords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - coords[i] = 0; - } - - for ( ; i < num_coords; i++ ) - coords[i] = 0; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Set_Var_Design */ - /* */ - /* <Description> */ - /* Set the coordinates for the instance, measured in the user */ - /* coordinate system. Parse the `avar' table (if present) to convert */ - /* from user to normalized coordinates. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* Initialize the blend struct with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use the default values for the remaining axes. */ - /* */ - /* coords :: A coordinate array with `num_coords' elements. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Set_Var_Design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i; - FT_Memory memory = face->root.memory; - - FT_Var_Axis* a; - FT_Fixed* c; - - FT_Fixed* normalized = NULL; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - goto Exit; - } - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "TT_Set_Var_Design:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - if ( !blend->coords ) - { - if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) ) - goto Exit; - } - - FT_MEM_COPY( blend->coords, - coords, - num_coords * sizeof ( FT_Fixed ) ); - - a = mmvar->axis + num_coords; - c = coords + num_coords; - for ( i = num_coords; i < mmvar->num_axis; i++, a++, c++ ) - *c = a->def; - - if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) ) - goto Exit; - - if ( !face->blend->avar_loaded ) - ft_var_load_avar( face ); - - ft_var_to_normalized( face, num_coords, coords, normalized ); - - error = tt_set_mm_blend( face, mmvar->num_axis, normalized, 0 ); - - Exit: - FT_FREE( normalized ); - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_Var_Design */ - /* */ - /* <Description> */ - /* Get the design coordinates of the currently selected interpolated */ - /* font. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of design coordinates to retrieve. If it */ - /* is larger than the number of axes, set the excess */ - /* values to~0. */ - /* */ - /* <Output> */ - /* coords :: The design coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_Var_Design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_UInt i, nc; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - return error; - } - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "TT_Get_Var_Design:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - coords[i] = blend->coords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - coords[i] = 0; - } - - for ( ; i < num_coords; i++ ) - coords[i] = 0; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GX VAR PARSING ROUTINES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_face_vary_cvt */ - /* */ - /* <Description> */ - /* Modify the loaded cvt table according to the `cvar' table and the */ - /* font's blend. */ - /* */ - /* <InOut> */ - /* face :: A handle to the target face object. */ - /* */ - /* <Input> */ - /* stream :: A handle to the input stream. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - /* Most errors are ignored. It is perfectly valid not to have a */ - /* `cvar' table even if there is a `gvar' and `fvar' table. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - tt_face_vary_cvt( TT_Face face, - FT_Stream stream ) - { - FT_Error error; - FT_Memory memory = stream->memory; - FT_ULong table_start; - FT_ULong table_len; - FT_UInt tupleCount; - FT_ULong offsetToData; - FT_ULong here; - FT_UInt i, j; - FT_Fixed* tuple_coords = NULL; - FT_Fixed* im_start_coords = NULL; - FT_Fixed* im_end_coords = NULL; - GX_Blend blend = face->blend; - FT_UInt point_count; - FT_UShort* localpoints; - FT_Short* deltas; - - - FT_TRACE2(( "CVAR " )); - - if ( !blend ) - { - FT_TRACE2(( "\n" - "tt_face_vary_cvt: no blend specified\n" )); - error = FT_Err_Ok; - goto Exit; - } - - if ( !face->cvt ) - { - FT_TRACE2(( "\n" - "tt_face_vary_cvt: no `cvt ' table\n" )); - error = FT_Err_Ok; - goto Exit; - } - - error = face->goto_table( face, TTAG_cvar, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - - error = FT_Err_Ok; - goto Exit; - } - - if ( FT_FRAME_ENTER( table_len ) ) - { - error = FT_Err_Ok; - goto Exit; - } - - table_start = FT_Stream_FTell( stream ); - if ( FT_GET_LONG() != 0x00010000L ) - { - FT_TRACE2(( "bad table version\n" )); - - error = FT_Err_Ok; - goto FExit; - } - - FT_TRACE2(( "loaded\n" )); - - if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) - goto FExit; - - tupleCount = FT_GET_USHORT(); - offsetToData = FT_GET_USHORT(); - - /* rough sanity test */ - if ( offsetToData + ( tupleCount & GX_TC_TUPLE_COUNT_MASK ) * 4 > - table_len ) - { - FT_TRACE2(( "tt_face_vary_cvt:" - " invalid CVT variation array header\n" )); - - error = FT_THROW( Invalid_Table ); - goto FExit; - } - - offsetToData += table_start; - - /* The documentation implies there are flags packed into */ - /* `tupleCount', but John Jenkins says that shared points don't apply */ - /* to `cvar', and no other flags are defined. */ - - FT_TRACE5(( "cvar: there are %d tuples:\n", tupleCount & 0xFFF )); - - for ( i = 0; i < ( tupleCount & 0xFFF ); i++ ) - { - FT_UInt tupleDataSize; - FT_UInt tupleIndex; - FT_Fixed apply; - - - FT_TRACE6(( " tuple %d:\n", i )); - - tupleDataSize = FT_GET_USHORT(); - tupleIndex = FT_GET_USHORT(); - - /* There is no provision here for a global tuple coordinate section, */ - /* so John says. There are no tuple indices, just embedded tuples. */ - - if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) - { - for ( j = 0; j < blend->num_axis; j++ ) - tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */ - /* short frac to fixed */ - } - else - { - /* skip this tuple; it makes no sense */ - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - for ( j = 0; j < 2 * blend->num_axis; j++ ) - (void)FT_GET_SHORT(); - - offsetToData += tupleDataSize; - continue; - } - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - { - for ( j = 0; j < blend->num_axis; j++ ) - im_start_coords[j] = FT_GET_SHORT() * 4; - for ( j = 0; j < blend->num_axis; j++ ) - im_end_coords[j] = FT_GET_SHORT() * 4; - } - - apply = ft_var_apply_tuple( blend, - (FT_UShort)tupleIndex, - tuple_coords, - im_start_coords, - im_end_coords ); - if ( /* tuple isn't active for our blend */ - apply == 0 || - /* global points not allowed, */ - /* if they aren't local, makes no sense */ - !( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) ) - { - offsetToData += tupleDataSize; - continue; - } - - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - localpoints = ft_var_readpackedpoints( stream, - table_len, - &point_count ); - deltas = ft_var_readpackeddeltas( stream, - table_len, - point_count == 0 ? face->cvt_size - : point_count ); - if ( !localpoints || !deltas ) - ; /* failure, ignore it */ - - else if ( localpoints == ALL_POINTS ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " CVT deltas:\n" )); - - /* this means that there are deltas for every entry in cvt */ - for ( j = 0; j < face->cvt_size; j++ ) - { - FT_Long orig_cvt = face->cvt[j]; - - - face->cvt[j] = (FT_Short)( orig_cvt + - FT_MulFix( deltas[j], apply ) ); - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( orig_cvt != face->cvt[j] ) - { - FT_TRACE7(( " %d: %d -> %d\n", - j, orig_cvt, face->cvt[j] )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - else - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " CVT deltas:\n" )); - - for ( j = 0; j < point_count; j++ ) - { - int pindex; - FT_Long orig_cvt; - - - pindex = localpoints[j]; - if ( (FT_ULong)pindex >= face->cvt_size ) - continue; - - orig_cvt = face->cvt[pindex]; - face->cvt[pindex] = (FT_Short)( orig_cvt + - FT_MulFix( deltas[j], apply ) ); - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( orig_cvt != face->cvt[pindex] ) - { - FT_TRACE7(( " %d: %d -> %d\n", - pindex, orig_cvt, face->cvt[pindex] )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - if ( localpoints != ALL_POINTS ) - FT_FREE( localpoints ); - FT_FREE( deltas ); - - offsetToData += tupleDataSize; - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "\n" )); - - FExit: - FT_FRAME_EXIT(); - - Exit: - FT_FREE( tuple_coords ); - FT_FREE( im_start_coords ); - FT_FREE( im_end_coords ); - - return error; - } - - - /* Shift the original coordinates of all points between indices `p1' */ - /* and `p2', using the same difference as given by index `ref'. */ - - /* modeled after `af_iup_shift' */ - - static void - tt_delta_shift( int p1, - int p2, - int ref, - FT_Vector* in_points, - FT_Vector* out_points ) - { - int p; - FT_Vector delta; - - - delta.x = out_points[ref].x - in_points[ref].x; - delta.y = out_points[ref].y - in_points[ref].y; - - if ( delta.x == 0 && delta.y == 0 ) - return; - - for ( p = p1; p < ref; p++ ) - { - out_points[p].x += delta.x; - out_points[p].y += delta.y; - } - - for ( p = ref + 1; p <= p2; p++ ) - { - out_points[p].x += delta.x; - out_points[p].y += delta.y; - } - } - - - /* Interpolate the original coordinates of all points with indices */ - /* between `p1' and `p2', using `ref1' and `ref2' as the reference */ - /* point indices. */ - - /* modeled after `af_iup_interp', `_iup_worker_interpolate', and */ - /* `Ins_IUP' */ - - static void - tt_delta_interpolate( int p1, - int p2, - int ref1, - int ref2, - FT_Vector* in_points, - FT_Vector* out_points ) - { - int p, i; - - FT_Pos out, in1, in2, out1, out2, d1, d2; - - - if ( p1 > p2 ) - return; - - /* handle both horizontal and vertical coordinates */ - for ( i = 0; i <= 1; i++ ) - { - /* shift array pointers so that we can access `foo.y' as `foo.x' */ - in_points = (FT_Vector*)( (FT_Pos*)in_points + i ); - out_points = (FT_Vector*)( (FT_Pos*)out_points + i ); - - if ( in_points[ref1].x > in_points[ref2].x ) - { - p = ref1; - ref1 = ref2; - ref2 = p; - } - - in1 = in_points[ref1].x; - in2 = in_points[ref2].x; - out1 = out_points[ref1].x; - out2 = out_points[ref2].x; - d1 = out1 - in1; - d2 = out2 - in2; - - /* If the reference points have the same coordinate but different */ - /* delta, inferred delta is zero. Otherwise interpolate. */ - if ( in1 != in2 || out1 == out2 ) - { - FT_Fixed scale = in1 != in2 ? FT_DivFix( out2 - out1, in2 - in1 ) - : 0; - - - for ( p = p1; p <= p2; p++ ) - { - out = in_points[p].x; - - if ( out <= in1 ) - out += d1; - else if ( out >= in2 ) - out += d2; - else - out = out1 + FT_MulFix( out - in1, scale ); - - out_points[p].x = out; - } - } - } - } - - - /* Interpolate points without delta values, similar to */ - /* the `IUP' hinting instruction. */ - - /* modeled after `Ins_IUP */ - - static void - tt_interpolate_deltas( FT_Outline* outline, - FT_Vector* out_points, - FT_Vector* in_points, - FT_Bool* has_delta ) - { - FT_Int first_point; - FT_Int end_point; - - FT_Int first_delta; - FT_Int cur_delta; - - FT_Int point; - FT_Short contour; - - - /* ignore empty outlines */ - if ( !outline->n_contours ) - return; - - contour = 0; - point = 0; - - do - { - end_point = outline->contours[contour]; - first_point = point; - - /* search first point that has a delta */ - while ( point <= end_point && !has_delta[point] ) - point++; - - if ( point <= end_point ) - { - first_delta = point; - cur_delta = point; - - point++; - - while ( point <= end_point ) - { - /* search next point that has a delta */ - /* and interpolate intermediate points */ - if ( has_delta[point] ) - { - tt_delta_interpolate( cur_delta + 1, - point - 1, - cur_delta, - point, - in_points, - out_points ); - cur_delta = point; - } - - point++; - } - - /* shift contour if we only have a single delta */ - if ( cur_delta == first_delta ) - tt_delta_shift( first_point, - end_point, - cur_delta, - in_points, - out_points ); - else - { - /* otherwise handle remaining points */ - /* at the end and beginning of the contour */ - tt_delta_interpolate( cur_delta + 1, - end_point, - cur_delta, - first_delta, - in_points, - out_points ); - - if ( first_delta > 0 ) - tt_delta_interpolate( first_point, - first_delta - 1, - cur_delta, - first_delta, - in_points, - out_points ); - } - } - contour++; - - } while ( contour < outline->n_contours ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Vary_Apply_Glyph_Deltas */ - /* */ - /* <Description> */ - /* Apply the appropriate deltas to the current glyph. */ - /* */ - /* <Input> */ - /* face :: A handle to the target face object. */ - /* */ - /* glyph_index :: The index of the glyph being modified. */ - /* */ - /* n_points :: The number of the points in the glyph, including */ - /* phantom points. */ - /* */ - /* <InOut> */ - /* outline :: The outline to change. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Vary_Apply_Glyph_Deltas( TT_Face face, - FT_UInt glyph_index, - FT_Outline* outline, - FT_UInt n_points ) - { - FT_Stream stream = face->root.stream; - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - - FT_Vector* points_org = NULL; - FT_Vector* points_out = NULL; - FT_Bool* has_delta = NULL; - - FT_Error error; - FT_ULong glyph_start; - FT_UInt tupleCount; - FT_ULong offsetToData; - FT_ULong here; - FT_UInt i, j; - FT_Fixed* tuple_coords = NULL; - FT_Fixed* im_start_coords = NULL; - FT_Fixed* im_end_coords = NULL; - FT_UInt point_count, spoint_count = 0; - FT_UShort* sharedpoints = NULL; - FT_UShort* localpoints = NULL; - FT_UShort* points; - FT_Short *deltas_x, *deltas_y; - - - if ( !face->doblend || !blend ) - return FT_THROW( Invalid_Argument ); - - if ( glyph_index >= blend->gv_glyphcnt || - blend->glyphoffsets[glyph_index] == - blend->glyphoffsets[glyph_index + 1] ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " no variation data for this glyph\n" )); - return FT_Err_Ok; - } - - if ( FT_NEW_ARRAY( points_org, n_points ) || - FT_NEW_ARRAY( points_out, n_points ) || - FT_NEW_ARRAY( has_delta, n_points ) ) - goto Fail1; - - if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) || - FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] - - blend->glyphoffsets[glyph_index] ) ) - goto Fail1; - - glyph_start = FT_Stream_FTell( stream ); - - /* each set of glyph variation data is formatted similarly to `cvar' */ - /* (except we get shared points and global tuples) */ - - if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) - goto Fail2; - - tupleCount = FT_GET_USHORT(); - offsetToData = FT_GET_USHORT(); - - /* rough sanity test */ - if ( offsetToData + ( tupleCount & GX_TC_TUPLE_COUNT_MASK ) * 4 > - blend->gvar_size ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " invalid glyph variation array header\n" )); - - error = FT_THROW( Invalid_Table ); - goto Fail2; - } - - offsetToData += glyph_start; - - if ( tupleCount & GX_TC_TUPLES_SHARE_POINT_NUMBERS ) - { - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - sharedpoints = ft_var_readpackedpoints( stream, - blend->gvar_size, - &spoint_count ); - offsetToData = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "gvar: there are %d tuples:\n", - tupleCount & GX_TC_TUPLE_COUNT_MASK )); - - for ( j = 0; j < n_points; j++ ) - points_org[j] = outline->points[j]; - - for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); i++ ) - { - FT_UInt tupleDataSize; - FT_UInt tupleIndex; - FT_Fixed apply; - - - FT_TRACE6(( " tuple %d:\n", i )); - - tupleDataSize = FT_GET_USHORT(); - tupleIndex = FT_GET_USHORT(); - - if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) - { - for ( j = 0; j < blend->num_axis; j++ ) - tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */ - /* short frac to fixed */ - } - else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " invalid tuple index\n" )); - - error = FT_THROW( Invalid_Table ); - goto Fail2; - } - else - FT_MEM_COPY( - tuple_coords, - &blend->tuplecoords[( tupleIndex & 0xFFF ) * blend->num_axis], - blend->num_axis * sizeof ( FT_Fixed ) ); - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - { - for ( j = 0; j < blend->num_axis; j++ ) - im_start_coords[j] = FT_GET_SHORT() * 4; - for ( j = 0; j < blend->num_axis; j++ ) - im_end_coords[j] = FT_GET_SHORT() * 4; - } - - apply = ft_var_apply_tuple( blend, - (FT_UShort)tupleIndex, - tuple_coords, - im_start_coords, - im_end_coords ); - - if ( apply == 0 ) /* tuple isn't active for our blend */ - { - offsetToData += tupleDataSize; - continue; - } - - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - if ( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) - { - localpoints = ft_var_readpackedpoints( stream, - blend->gvar_size, - &point_count ); - points = localpoints; - } - else - { - points = sharedpoints; - point_count = spoint_count; - } - - deltas_x = ft_var_readpackeddeltas( stream, - blend->gvar_size, - point_count == 0 ? n_points - : point_count ); - deltas_y = ft_var_readpackeddeltas( stream, - blend->gvar_size, - point_count == 0 ? n_points - : point_count ); - - if ( !points || !deltas_y || !deltas_x ) - ; /* failure, ignore it */ - - else if ( points == ALL_POINTS ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " point deltas:\n" )); - - /* this means that there are deltas for every point in the glyph */ - for ( j = 0; j < n_points; j++ ) - { - FT_Pos delta_x = FT_MulFix( deltas_x[j], apply ); - FT_Pos delta_y = FT_MulFix( deltas_y[j], apply ); - - - if ( j < n_points - 3 ) - { - outline->points[j].x += delta_x; - outline->points[j].y += delta_y; - } - else - { - /* To avoid double adjustment of advance width or height, */ - /* adjust phantom points only if there is no HVAR or VVAR */ - /* support, respectively. */ - if ( j == ( n_points - 3 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_HADVANCE ) ) - outline->points[j].x += delta_x; - - else if ( j == ( n_points - 2 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_LSB ) ) - outline->points[j].x += delta_x; - - else if ( j == ( n_points - 1 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_VADVANCE ) ) - outline->points[j].y += delta_y; - - else if ( j == ( n_points - 0 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_TSB ) ) - outline->points[j].y += delta_y; - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( delta_x || delta_y ) - { - FT_TRACE7(( " %d: (%d, %d) -> (%d, %d)\n", - j, - outline->points[j].x - delta_x, - outline->points[j].y - delta_y, - outline->points[j].x, - outline->points[j].y )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - else - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - /* we have to interpolate the missing deltas similar to the */ - /* IUP bytecode instruction */ - for ( j = 0; j < n_points; j++ ) - { - has_delta[j] = FALSE; - points_out[j] = points_org[j]; - } - - for ( j = 0; j < point_count; j++ ) - { - FT_UShort idx = points[j]; - - - if ( idx >= n_points ) - continue; - - has_delta[idx] = TRUE; - - points_out[idx].x += FT_MulFix( deltas_x[j], apply ); - points_out[idx].y += FT_MulFix( deltas_y[j], apply ); - } - - /* no need to handle phantom points here, */ - /* since solitary points can't be interpolated */ - tt_interpolate_deltas( outline, - points_out, - points_org, - has_delta ); - - FT_TRACE7(( " point deltas:\n" )); - - for ( j = 0; j < n_points; j++ ) - { - FT_Pos delta_x = points_out[j].x - points_org[j].x; - FT_Pos delta_y = points_out[j].y - points_org[j].y; - - - outline->points[j].x += delta_x; - outline->points[j].y += delta_y; - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( delta_x || delta_y ) - { - FT_TRACE7(( " %d: (%d, %d) -> (%d, %d)\n", - j, - outline->points[j].x - delta_x, - outline->points[j].y - delta_y, - outline->points[j].x, - outline->points[j].y )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - if ( localpoints != ALL_POINTS ) - FT_FREE( localpoints ); - FT_FREE( deltas_x ); - FT_FREE( deltas_y ); - - offsetToData += tupleDataSize; - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "\n" )); - - Fail2: - if ( sharedpoints != ALL_POINTS ) - FT_FREE( sharedpoints ); - FT_FREE( tuple_coords ); - FT_FREE( im_start_coords ); - FT_FREE( im_end_coords ); - - FT_FRAME_EXIT(); - - Fail1: - FT_FREE( points_org ); - FT_FREE( points_out ); - FT_FREE( has_delta ); - - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_get_var_blend */ - /* */ - /* <Description> */ - /* An extended internal version of `TT_Get_MM_Blend' that returns */ - /* pointers instead of copying data, without any initialization of */ - /* the MM machinery in case it isn't loaded yet. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - tt_get_var_blend( TT_Face face, - FT_UInt *num_coords, - FT_Fixed* *coords, - FT_Fixed* *normalizedcoords, - FT_MM_Var* *mm_var ) - { - if ( face->blend ) - { - if ( num_coords ) - *num_coords = face->blend->num_axis; - if ( coords ) - *coords = face->blend->coords; - if ( normalizedcoords ) - *normalizedcoords = face->blend->normalizedcoords; - if ( mm_var ) - *mm_var = face->blend->mmvar; - } - else - { - if ( num_coords ) - *num_coords = 0; - if ( coords ) - *coords = NULL; - if ( mm_var ) - *mm_var = NULL; - } - - return FT_Err_Ok; - } - - - static void - ft_var_done_item_variation_store( TT_Face face, - GX_ItemVarStore itemStore ) - { - FT_Memory memory = FT_FACE_MEMORY( face ); - FT_UInt i; - - - if ( itemStore->varData ) - { - for ( i = 0; i < itemStore->dataCount; i++ ) - { - FT_FREE( itemStore->varData[i].regionIndices ); - FT_FREE( itemStore->varData[i].deltaSet ); - } - - FT_FREE( itemStore->varData ); - } - - if ( itemStore->varRegionList ) - { - for ( i = 0; i < itemStore->regionCount; i++ ) - FT_FREE( itemStore->varRegionList[i].axisList ); - - FT_FREE( itemStore->varRegionList ); - } - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_done_blend */ - /* */ - /* <Description> */ - /* Free the blend internal data structure. */ - /* */ - FT_LOCAL_DEF( void ) - tt_done_blend( TT_Face face ) - { - FT_Memory memory = FT_FACE_MEMORY( face ); - GX_Blend blend = face->blend; - - - if ( blend ) - { - FT_UInt i, num_axes; - - - /* blend->num_axis might not be set up yet */ - num_axes = blend->mmvar->num_axis; - - FT_FREE( blend->coords ); - FT_FREE( blend->normalizedcoords ); - FT_FREE( blend->normalized_stylecoords ); - FT_FREE( blend->mmvar ); - - if ( blend->avar_segment ) - { - for ( i = 0; i < num_axes; i++ ) - FT_FREE( blend->avar_segment[i].correspondence ); - FT_FREE( blend->avar_segment ); - } - - if ( blend->hvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->hvar_table->itemStore ); - - FT_FREE( blend->hvar_table->widthMap.innerIndex ); - FT_FREE( blend->hvar_table->widthMap.outerIndex ); - FT_FREE( blend->hvar_table ); - } - - if ( blend->vvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->vvar_table->itemStore ); - - FT_FREE( blend->vvar_table->widthMap.innerIndex ); - FT_FREE( blend->vvar_table->widthMap.outerIndex ); - FT_FREE( blend->vvar_table ); - } - - if ( blend->mvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->mvar_table->itemStore ); - - FT_FREE( blend->mvar_table->values ); - FT_FREE( blend->mvar_table ); - } - - FT_FREE( blend->tuplecoords ); - FT_FREE( blend->glyphoffsets ); - FT_FREE( blend ); - } - } - -#else /* !TT_CONFIG_OPTION_GX_VAR_SUPPORT */ - - /* ANSI C doesn't like empty source files */ - typedef int _tt_gxvar_dummy; - -#endif /* !TT_CONFIG_OPTION_GX_VAR_SUPPORT */ - - -/* END */ diff --git a/src/truetype/ttgxvar.c.named-instances2 b/src/truetype/ttgxvar.c.named-instances2 deleted file mode 100644 index cfb0ed0..0000000 --- a/src/truetype/ttgxvar.c.named-instances2 +++ /dev/null @@ -1,3728 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttgxvar.c */ -/* */ -/* TrueType GX Font Variation loader */ -/* */ -/* Copyright 2004-2017 by */ -/* David Turner, Robert Wilhelm, Werner Lemberg, and George Williams. */ -/* */ -/* 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. */ -/* */ -/***************************************************************************/ - - - /*************************************************************************/ - /* */ - /* Apple documents the `fvar', `gvar', `cvar', and `avar' tables at */ - /* */ - /* https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6[fgca]var.html */ - /* */ - /* The documentation for `gvar' is not intelligible; `cvar' refers you */ - /* to `gvar' and is thus also incomprehensible. */ - /* */ - /* The documentation for `avar' appears correct, but Apple has no fonts */ - /* with an `avar' table, so it is hard to test. */ - /* */ - /* Many thanks to John Jenkins (at Apple) in figuring this out. */ - /* */ - /* */ - /* Apple's `kern' table has some references to tuple indices, but as */ - /* there is no indication where these indices are defined, nor how to */ - /* interpolate the kerning values (different tuples have different */ - /* classes) this issue is ignored. */ - /* */ - /*************************************************************************/ - - -#include <ft2build.h> -#include FT_INTERNAL_DEBUG_H -#include FT_CONFIG_CONFIG_H -#include FT_INTERNAL_STREAM_H -#include FT_INTERNAL_SFNT_H -#include FT_TRUETYPE_TAGS_H -#include FT_TRUETYPE_IDS_H -#include FT_MULTIPLE_MASTERS_H -#include FT_LIST_H - -#include "ttpload.h" -#include "ttgxvar.h" - -#include "tterrors.h" - - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - - -#define FT_Stream_FTell( stream ) \ - (FT_ULong)( (stream)->cursor - (stream)->base ) -#define FT_Stream_SeekSet( stream, off ) \ - ( (stream)->cursor = (stream)->base + (off) ) - - - /*************************************************************************/ - /* */ - /* 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_ttgxvar - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** Internal Routines *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* The macro ALL_POINTS is used in `ft_var_readpackedpoints'. It */ - /* indicates that there is a delta for every point without needing to */ - /* enumerate all of them. */ - /* */ - - /* ensure that value `0' has the same width as a pointer */ -#define ALL_POINTS (FT_UShort*)~(FT_PtrDist)0 - - -#define GX_PT_POINTS_ARE_WORDS 0x80U -#define GX_PT_POINT_RUN_COUNT_MASK 0x7FU - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_readpackedpoints */ - /* */ - /* <Description> */ - /* Read a set of points to which the following deltas will apply. */ - /* Points are packed with a run length encoding. */ - /* */ - /* <Input> */ - /* stream :: The data stream. */ - /* */ - /* size :: The size of the table holding the data. */ - /* */ - /* <Output> */ - /* point_cnt :: The number of points read. A zero value means that */ - /* all points in the glyph will be affected, without */ - /* enumerating them individually. */ - /* */ - /* <Return> */ - /* An array of FT_UShort containing the affected points or the */ - /* special value ALL_POINTS. */ - /* */ - static FT_UShort* - ft_var_readpackedpoints( FT_Stream stream, - FT_ULong size, - FT_UInt *point_cnt ) - { - FT_UShort *points = NULL; - FT_UInt n; - FT_UInt runcnt; - FT_UInt i, j; - FT_UShort first; - FT_Memory memory = stream->memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( error ); - - - *point_cnt = 0; - - n = FT_GET_BYTE(); - if ( n == 0 ) - return ALL_POINTS; - - if ( n & GX_PT_POINTS_ARE_WORDS ) - { - n &= GX_PT_POINT_RUN_COUNT_MASK; - n <<= 8; - n |= FT_GET_BYTE(); - } - - if ( n > size ) - { - FT_TRACE1(( "ft_var_readpackedpoints: number of points too large\n" )); - return NULL; - } - - /* in the nested loops below we increase `i' twice; */ - /* it is faster to simply allocate one more slot */ - /* than to add another test within the loop */ - if ( FT_NEW_ARRAY( points, n + 1 ) ) - return NULL; - - *point_cnt = n; - - first = 0; - i = 0; - while ( i < n ) - { - runcnt = FT_GET_BYTE(); - if ( runcnt & GX_PT_POINTS_ARE_WORDS ) - { - runcnt &= GX_PT_POINT_RUN_COUNT_MASK; - first += FT_GET_USHORT(); - points[i++] = first; - - /* first point not included in run count */ - for ( j = 0; j < runcnt; j++ ) - { - first += FT_GET_USHORT(); - points[i++] = first; - if ( i >= n ) - break; - } - } - else - { - first += FT_GET_BYTE(); - points[i++] = first; - - for ( j = 0; j < runcnt; j++ ) - { - first += FT_GET_BYTE(); - points[i++] = first; - if ( i >= n ) - break; - } - } - } - - return points; - } - - -#define GX_DT_DELTAS_ARE_ZERO 0x80U -#define GX_DT_DELTAS_ARE_WORDS 0x40U -#define GX_DT_DELTA_RUN_COUNT_MASK 0x3FU - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_readpackeddeltas */ - /* */ - /* <Description> */ - /* Read a set of deltas. These are packed slightly differently than */ - /* points. In particular there is no overall count. */ - /* */ - /* <Input> */ - /* stream :: The data stream. */ - /* */ - /* size :: The size of the table holding the data. */ - /* */ - /* delta_cnt :: The number of deltas to be read. */ - /* */ - /* <Return> */ - /* An array of FT_Short containing the deltas for the affected */ - /* points. (This only gets the deltas for one dimension. It will */ - /* generally be called twice, once for x, once for y. When used in */ - /* cvt table, it will only be called once.) */ - /* */ - static FT_Short* - ft_var_readpackeddeltas( FT_Stream stream, - FT_ULong size, - FT_UInt delta_cnt ) - { - FT_Short *deltas = NULL; - FT_UInt runcnt, cnt; - FT_UInt i, j; - FT_Memory memory = stream->memory; - FT_Error error = FT_Err_Ok; - - FT_UNUSED( error ); - - - if ( delta_cnt > size ) - { - FT_TRACE1(( "ft_var_readpackeddeltas: number of points too large\n" )); - return NULL; - } - - if ( FT_NEW_ARRAY( deltas, delta_cnt ) ) - return NULL; - - i = 0; - while ( i < delta_cnt ) - { - runcnt = FT_GET_BYTE(); - cnt = runcnt & GX_DT_DELTA_RUN_COUNT_MASK; - - if ( runcnt & GX_DT_DELTAS_ARE_ZERO ) - { - /* `runcnt' zeroes get added */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = 0; - } - else if ( runcnt & GX_DT_DELTAS_ARE_WORDS ) - { - /* `runcnt' shorts from the stack */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = FT_GET_SHORT(); - } - else - { - /* `runcnt' signed bytes from the stack */ - for ( j = 0; j <= cnt && i < delta_cnt; j++ ) - deltas[i++] = FT_GET_CHAR(); - } - - if ( j <= cnt ) - { - /* bad format */ - FT_FREE( deltas ); - return NULL; - } - } - - return deltas; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_avar */ - /* */ - /* <Description> */ - /* Parse the `avar' table if present. It need not be, so we return */ - /* nothing. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - static void - ft_var_load_avar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - GX_AVarSegment segment; - FT_Error error = FT_Err_Ok; - FT_Long version; - FT_Long axisCount; - FT_Int i, j; - FT_ULong table_len; - - FT_UNUSED( error ); - - - FT_TRACE2(( "AVAR " )); - - blend->avar_loaded = TRUE; - error = face->goto_table( face, TTAG_avar, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - return; - } - - if ( FT_FRAME_ENTER( table_len ) ) - return; - - version = FT_GET_LONG(); - axisCount = FT_GET_LONG(); - - if ( version != 0x00010000L ) - { - FT_TRACE2(( "bad table version\n" )); - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - - if ( axisCount != (FT_Long)blend->mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_load_avar: number of axes in `avar' and `fvar'\n" - " table are different\n" )); - goto Exit; - } - - if ( FT_NEW_ARRAY( blend->avar_segment, axisCount ) ) - goto Exit; - - segment = &blend->avar_segment[0]; - for ( i = 0; i < axisCount; i++, segment++ ) - { - FT_TRACE5(( " axis %d:\n", i )); - - segment->pairCount = FT_GET_USHORT(); - if ( (FT_ULong)segment->pairCount * 4 > table_len || - FT_NEW_ARRAY( segment->correspondence, segment->pairCount ) ) - { - /* Failure. Free everything we have done so far. We must do */ - /* it right now since loading the `avar' table is optional. */ - - for ( j = i - 1; j >= 0; j-- ) - FT_FREE( blend->avar_segment[j].correspondence ); - - FT_FREE( blend->avar_segment ); - blend->avar_segment = NULL; - goto Exit; - } - - for ( j = 0; j < segment->pairCount; j++ ) - { - /* convert to Fixed */ - segment->correspondence[j].fromCoord = FT_GET_SHORT() * 4; - segment->correspondence[j].toCoord = FT_GET_SHORT() * 4; - - FT_TRACE5(( " mapping %.5f to %.5f\n", - segment->correspondence[j].fromCoord / 65536.0, - segment->correspondence[j].toCoord / 65536.0 )); - } - - FT_TRACE5(( "\n" )); - } - - Exit: - FT_FRAME_EXIT(); - } - - - /* some macros we need */ - #define FT_FIXED_ONE ( (FT_Fixed)0x10000 ) - - #define FT_fdot14ToFixed( x ) \ - ( (FT_Fixed)( (FT_ULong)(x) << 2 ) ) - #define FT_intToFixed( i ) \ - ( (FT_Fixed)( (FT_ULong)(i) << 16 ) ) - #define FT_fixedToInt( x ) \ - ( (FT_Short)( ( (FT_UInt32)(x) + 0x8000U ) >> 16 ) ) - - - static FT_Error - ft_var_load_item_variation_store( TT_Face face, - FT_ULong offset, - GX_ItemVarStore itemStore ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - FT_Error error; - FT_UShort format; - FT_ULong region_offset; - FT_UInt i, j, k; - FT_UInt shortDeltaCount; - - GX_Blend blend = face->blend; - GX_ItemVarData varData; - - FT_ULong* dataOffsetArray = NULL; - - - if ( FT_STREAM_SEEK( offset ) || - FT_READ_USHORT( format ) ) - goto Exit; - - if ( format != 1 ) - { - FT_TRACE2(( "ft_var_load_item_variation_store: bad store format %d\n", - format )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* read top level fields */ - if ( FT_READ_ULONG( region_offset ) || - FT_READ_USHORT( itemStore->dataCount ) ) - goto Exit; - - /* we need at least one entry in `itemStore->varData' */ - if ( !itemStore->dataCount ) - { - FT_TRACE2(( "ft_var_load_item_variation_store: missing varData\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* make temporary copy of item variation data offsets; */ - /* we will parse region list first, then come back */ - if ( FT_NEW_ARRAY( dataOffsetArray, itemStore->dataCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->dataCount; i++ ) - { - if ( FT_READ_ULONG( dataOffsetArray[i] ) ) - goto Exit; - } - - /* parse array of region records (region list) */ - if ( FT_STREAM_SEEK( offset + region_offset ) ) - goto Exit; - - if ( FT_READ_USHORT( itemStore->axisCount ) || - FT_READ_USHORT( itemStore->regionCount ) ) - goto Exit; - - if ( itemStore->axisCount != (FT_Long)blend->mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_load_item_variation_store:" - " number of axes in item variation store\n" - " " - " and `fvar' table are different\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( FT_NEW_ARRAY( itemStore->varRegionList, itemStore->regionCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->regionCount; i++ ) - { - GX_AxisCoords axisCoords; - - - if ( FT_NEW_ARRAY( itemStore->varRegionList[i].axisList, - itemStore->axisCount ) ) - goto Exit; - - axisCoords = itemStore->varRegionList[i].axisList; - - for ( j = 0; j < itemStore->axisCount; j++ ) - { - FT_Short start, peak, end; - - - if ( FT_READ_SHORT( start ) || - FT_READ_SHORT( peak ) || - FT_READ_SHORT( end ) ) - goto Exit; - - axisCoords[j].startCoord = FT_fdot14ToFixed( start ); - axisCoords[j].peakCoord = FT_fdot14ToFixed( peak ); - axisCoords[j].endCoord = FT_fdot14ToFixed( end ); - } - } - - /* end of region list parse */ - - /* use dataOffsetArray now to parse varData items */ - if ( FT_NEW_ARRAY( itemStore->varData, itemStore->dataCount ) ) - goto Exit; - - for ( i = 0; i < itemStore->dataCount; i++ ) - { - varData = &itemStore->varData[i]; - - if ( FT_STREAM_SEEK( offset + dataOffsetArray[i] ) ) - goto Exit; - - if ( FT_READ_USHORT( varData->itemCount ) || - FT_READ_USHORT( shortDeltaCount ) || - FT_READ_USHORT( varData->regionIdxCount ) ) - goto Exit; - - /* check some data consistency */ - if ( shortDeltaCount > varData->regionIdxCount ) - { - FT_TRACE2(( "bad short count %d or region count %d\n", - shortDeltaCount, - varData->regionIdxCount )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( varData->regionIdxCount > itemStore->regionCount ) - { - FT_TRACE2(( "inconsistent regionCount %d in varData[%d]\n", - varData->regionIdxCount, - i )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* parse region indices */ - if ( FT_NEW_ARRAY( varData->regionIndices, - varData->regionIdxCount ) ) - goto Exit; - - for ( j = 0; j < varData->regionIdxCount; j++ ) - { - if ( FT_READ_USHORT( varData->regionIndices[j] ) ) - goto Exit; - - if ( varData->regionIndices[j] >= itemStore->regionCount ) - { - FT_TRACE2(( "bad region index %d\n", - varData->regionIndices[j] )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - } - - /* Parse delta set. */ - /* */ - /* On input, deltas are (shortDeltaCount + regionIdxCount) bytes */ - /* each; on output, deltas are expanded to `regionIdxCount' shorts */ - /* each. */ - if ( FT_NEW_ARRAY( varData->deltaSet, - varData->regionIdxCount * varData->itemCount ) ) - goto Exit; - - /* the delta set is stored as a 2-dimensional array of shorts; */ - /* sign-extend signed bytes to signed shorts */ - for ( j = 0; j < varData->itemCount * varData->regionIdxCount; ) - { - for ( k = 0; k < shortDeltaCount; k++, j++ ) - { - /* read the short deltas */ - FT_Short delta; - - - if ( FT_READ_SHORT( delta ) ) - goto Exit; - - varData->deltaSet[j] = delta; - } - - for ( ; k < varData->regionIdxCount; k++, j++ ) - { - /* read the (signed) byte deltas */ - FT_Char delta; - - - if ( FT_READ_CHAR( delta ) ) - goto Exit; - - varData->deltaSet[j] = delta; - } - } - } - - Exit: - FT_FREE( dataOffsetArray ); - - return error; - } - - - static FT_Error - ft_var_load_delta_set_index_mapping( TT_Face face, - FT_ULong offset, - GX_DeltaSetIdxMap map, - GX_ItemVarStore itemStore ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - FT_Error error; - - FT_UShort format; - FT_UInt entrySize; - FT_UInt innerBitCount; - FT_UInt innerIndexMask; - FT_UInt i, j; - - - if ( FT_STREAM_SEEK( offset ) || - FT_READ_USHORT( format ) || - FT_READ_USHORT( map->mapCount ) ) - goto Exit; - - if ( format & 0xFFC0 ) - { - FT_TRACE2(( "bad map format %d\n", format )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* bytes per entry: 1, 2, 3, or 4 */ - entrySize = ( ( format & 0x0030 ) >> 4 ) + 1; - innerBitCount = ( format & 0x000F ) + 1; - innerIndexMask = ( 1 << innerBitCount ) - 1; - - if ( FT_NEW_ARRAY( map->innerIndex, map->mapCount ) ) - goto Exit; - - if ( FT_NEW_ARRAY( map->outerIndex, map->mapCount ) ) - goto Exit; - - for ( i = 0; i < map->mapCount; i++ ) - { - FT_UInt mapData = 0; - FT_UInt outerIndex, innerIndex; - - - /* read map data one unsigned byte at a time, big endian */ - for ( j = 0; j < entrySize; j++ ) - { - FT_Byte data; - - - if ( FT_READ_BYTE( data ) ) - goto Exit; - - mapData = ( mapData << 8 ) | data; - } - - outerIndex = mapData >> innerBitCount; - - if ( outerIndex >= itemStore->dataCount ) - { - FT_TRACE2(( "outerIndex[%d] == %d out of range\n", - i, - outerIndex )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - map->outerIndex[i] = outerIndex; - - innerIndex = mapData & innerIndexMask; - - if ( innerIndex >= itemStore->varData[outerIndex].itemCount ) - { - FT_TRACE2(( "innerIndex[%d] == %d out of range\n", - i, - innerIndex )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - map->innerIndex[i] = innerIndex; - } - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_hvvar */ - /* */ - /* <Description> */ - /* If `vertical' is zero, parse the `HVAR' table and set */ - /* `blend->hvar_loaded' to TRUE. On success, `blend->hvar_checked' */ - /* is set to TRUE. */ - /* */ - /* If `vertical' is not zero, parse the `VVAR' table and set */ - /* `blend->vvar_loaded' to TRUE. On success, `blend->vvar_checked' */ - /* is set to TRUE. */ - /* */ - /* Some memory may remain allocated on error; it is always freed in */ - /* `tt_done_blend', however. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - static FT_Error - ft_var_load_hvvar( TT_Face face, - FT_Bool vertical ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - GX_Blend blend = face->blend; - - GX_HVVarTable table; - - FT_Error error; - FT_UShort majorVersion; - FT_ULong table_len; - FT_ULong table_offset; - FT_ULong store_offset; - FT_ULong widthMap_offset; - - - if ( vertical ) - { - blend->vvar_loaded = TRUE; - - FT_TRACE2(( "VVAR " )); - - error = face->goto_table( face, TTAG_VVAR, stream, &table_len ); - } - else - { - blend->hvar_loaded = TRUE; - - FT_TRACE2(( "HVAR " )); - - error = face->goto_table( face, TTAG_HVAR, stream, &table_len ); - } - - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - goto Exit; - } - - table_offset = FT_STREAM_POS(); - - /* skip minor version */ - if ( FT_READ_USHORT( majorVersion ) || - FT_STREAM_SKIP( 2 ) ) - goto Exit; - - if ( majorVersion != 1 ) - { - FT_TRACE2(( "bad table version %d\n", majorVersion )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( FT_READ_ULONG( store_offset ) || - FT_READ_ULONG( widthMap_offset ) ) - goto Exit; - - if ( vertical ) - { - if ( FT_NEW( blend->vvar_table ) ) - goto Exit; - table = blend->vvar_table; - } - else - { - if ( FT_NEW( blend->hvar_table ) ) - goto Exit; - table = blend->hvar_table; - } - - error = ft_var_load_item_variation_store( - face, - table_offset + store_offset, - &table->itemStore ); - if ( error ) - goto Exit; - - if ( widthMap_offset ) - { - error = ft_var_load_delta_set_index_mapping( - face, - table_offset + widthMap_offset, - &table->widthMap, - &table->itemStore ); - if ( error ) - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - error = FT_Err_Ok; - - Exit: - if ( !error ) - { - if ( vertical ) - { - blend->vvar_checked = TRUE; - - /* FreeType doesn't provide functions to quickly retrieve */ - /* TSB, BSB, or VORG values; we thus don't have to implement */ - /* support for those three item variation stores. */ - - face->variation_support |= TT_FACE_FLAG_VAR_VADVANCE; - } - else - { - blend->hvar_checked = TRUE; - - /* FreeType doesn't provide functions to quickly retrieve */ - /* LSB or RSB values; we thus don't have to implement */ - /* support for those two item variation stores. */ - - face->variation_support |= TT_FACE_FLAG_VAR_HADVANCE; - } - } - - return error; - } - - - static FT_Int - ft_var_get_item_delta( TT_Face face, - GX_ItemVarStore itemStore, - FT_UInt outerIndex, - FT_UInt innerIndex ) - { - GX_ItemVarData varData; - FT_Short* deltaSet; - - FT_UInt master, j; - FT_Fixed netAdjustment = 0; /* accumulated adjustment */ - FT_Fixed scaledDelta; - FT_Fixed delta; - - - /* See pseudo code from `Font Variations Overview' */ - /* in the OpenType specification. */ - - varData = &itemStore->varData[outerIndex]; - deltaSet = &varData->deltaSet[varData->regionIdxCount * innerIndex]; - - /* outer loop steps through master designs to be blended */ - for ( master = 0; master < varData->regionIdxCount; master++ ) - { - FT_Fixed scalar = FT_FIXED_ONE; - FT_UInt regionIndex = varData->regionIndices[master]; - - GX_AxisCoords axis = itemStore->varRegionList[regionIndex].axisList; - - - /* inner loop steps through axes in this region */ - for ( j = 0; j < itemStore->axisCount; j++, axis++ ) - { - FT_Fixed axisScalar; - - - /* compute the scalar contribution of this axis; */ - /* ignore invalid ranges */ - if ( axis->startCoord > axis->peakCoord || - axis->peakCoord > axis->endCoord ) - axisScalar = FT_FIXED_ONE; - - else if ( axis->startCoord < 0 && - axis->endCoord > 0 && - axis->peakCoord != 0 ) - axisScalar = FT_FIXED_ONE; - - /* peak of 0 means ignore this axis */ - else if ( axis->peakCoord == 0 ) - axisScalar = FT_FIXED_ONE; - - /* ignore this region if coords are out of range */ - else if ( face->blend->normalizedcoords[j] < axis->startCoord || - face->blend->normalizedcoords[j] > axis->endCoord ) - axisScalar = 0; - - /* calculate a proportional factor */ - else - { - if ( face->blend->normalizedcoords[j] == axis->peakCoord ) - axisScalar = FT_FIXED_ONE; - else if ( face->blend->normalizedcoords[j] < axis->peakCoord ) - axisScalar = - FT_DivFix( face->blend->normalizedcoords[j] - axis->startCoord, - axis->peakCoord - axis->startCoord ); - else - axisScalar = - FT_DivFix( axis->endCoord - face->blend->normalizedcoords[j], - axis->endCoord - axis->peakCoord ); - } - - /* take product of all the axis scalars */ - scalar = FT_MulFix( scalar, axisScalar ); - - } /* per-axis loop */ - - /* get the scaled delta for this region */ - delta = FT_intToFixed( deltaSet[master] ); - scaledDelta = FT_MulFix( scalar, delta ); - - /* accumulate the adjustments from each region */ - netAdjustment = netAdjustment + scaledDelta; - - } /* per-region loop */ - - return FT_fixedToInt( netAdjustment ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_hvadvance_adjust */ - /* */ - /* <Description> */ - /* Apply `HVAR' advance width or `VVAR' advance height adjustment of */ - /* a given glyph. */ - /* */ - /* <Input> */ - /* gindex :: The glyph index. */ - /* */ - /* vertical :: If set, handle `VVAR' table. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* adelta :: Points to width or height value that gets modified. */ - /* */ - static FT_Error - tt_hvadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue, - FT_Bool vertical ) - { - FT_Error error = FT_Err_Ok; - FT_UInt innerIndex, outerIndex; - FT_Int delta; - - GX_HVVarTable table; - - - if ( !face->doblend || !face->blend ) - goto Exit; - - if ( vertical ) - { - if ( !face->blend->vvar_loaded ) - { - /* initialize vvar table */ - face->blend->vvar_error = ft_var_load_hvvar( face, 1 ); - } - - if ( !face->blend->vvar_checked ) - { - error = face->blend->vvar_error; - goto Exit; - } - - table = face->blend->vvar_table; - } - else - { - if ( !face->blend->hvar_loaded ) - { - /* initialize hvar table */ - face->blend->hvar_error = ft_var_load_hvvar( face, 0 ); - } - - if ( !face->blend->hvar_checked ) - { - error = face->blend->hvar_error; - goto Exit; - } - - table = face->blend->hvar_table; - } - - /* advance width or height adjustments are always present in an */ - /* `HVAR' or `VVAR' table; no need to test for this capability */ - - if ( table->widthMap.innerIndex ) - { - FT_UInt idx = gindex; - - - if ( idx >= table->widthMap.mapCount ) - idx = table->widthMap.mapCount - 1; - - /* trust that HVAR parser has checked indices */ - outerIndex = table->widthMap.outerIndex[idx]; - innerIndex = table->widthMap.innerIndex[idx]; - } - else - { - GX_ItemVarData varData; - - - /* no widthMap data */ - outerIndex = 0; - innerIndex = gindex; - - varData = &table->itemStore.varData[outerIndex]; - if ( gindex >= varData->itemCount ) - { - FT_TRACE2(( "gindex %d out of range\n", gindex )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - } - - delta = ft_var_get_item_delta( face, - &table->itemStore, - outerIndex, - innerIndex ); - - FT_TRACE5(( "%s value %d adjusted by %d units (%s)\n", - vertical ? "vertical height" : "horizontal width", - *avalue, - delta, - vertical ? "VVAR" : "HVAR" )); - - *avalue += delta; - - Exit: - return error; - } - - - FT_LOCAL_DEF( FT_Error ) - tt_hadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue ) - { - return tt_hvadvance_adjust( face, gindex, avalue, 0 ); - } - - - FT_LOCAL_DEF( FT_Error ) - tt_vadvance_adjust( TT_Face face, - FT_UInt gindex, - FT_Int *avalue ) - { - return tt_hvadvance_adjust( face, gindex, avalue, 1 ); - } - - -#define GX_VALUE_SIZE 8 - - /* all values are FT_Short or FT_UShort entities; */ - /* we treat them consistently as FT_Short */ -#define GX_VALUE_CASE( tag, dflt ) \ - case MVAR_TAG_ ## tag : \ - p = (FT_Short*)&face->dflt; \ - break - -#define GX_GASP_CASE( idx ) \ - case MVAR_TAG_GASP_ ## idx : \ - if ( idx < face->gasp.numRanges - 1 ) \ - p = (FT_Short*)&face->gasp.gaspRanges[idx].maxPPEM; \ - else \ - p = NULL; \ - break - - - static FT_Short* - ft_var_get_value_pointer( TT_Face face, - FT_ULong mvar_tag ) - { - FT_Short* p; - - - switch ( mvar_tag ) - { - GX_GASP_CASE( 0 ); - GX_GASP_CASE( 1 ); - GX_GASP_CASE( 2 ); - GX_GASP_CASE( 3 ); - GX_GASP_CASE( 4 ); - GX_GASP_CASE( 5 ); - GX_GASP_CASE( 6 ); - GX_GASP_CASE( 7 ); - GX_GASP_CASE( 8 ); - GX_GASP_CASE( 9 ); - - GX_VALUE_CASE( CPHT, os2.sCapHeight ); - GX_VALUE_CASE( HASC, os2.sTypoAscender ); - GX_VALUE_CASE( HCLA, os2.usWinAscent ); - GX_VALUE_CASE( HCLD, os2.usWinDescent ); - GX_VALUE_CASE( HCOF, horizontal.caret_Offset ); - GX_VALUE_CASE( HCRN, horizontal.caret_Slope_Run ); - GX_VALUE_CASE( HCRS, horizontal.caret_Slope_Rise ); - GX_VALUE_CASE( HDSC, os2.sTypoDescender ); - GX_VALUE_CASE( HLGP, os2.sTypoLineGap ); - GX_VALUE_CASE( SBXO, os2.ySubscriptXOffset); - GX_VALUE_CASE( SBXS, os2.ySubscriptXSize ); - GX_VALUE_CASE( SBYO, os2.ySubscriptYOffset ); - GX_VALUE_CASE( SBYS, os2.ySubscriptYSize ); - GX_VALUE_CASE( SPXO, os2.ySuperscriptXOffset ); - GX_VALUE_CASE( SPXS, os2.ySuperscriptXSize ); - GX_VALUE_CASE( SPYO, os2.ySuperscriptYOffset ); - GX_VALUE_CASE( SPYS, os2.ySuperscriptYSize ); - GX_VALUE_CASE( STRO, os2.yStrikeoutPosition ); - GX_VALUE_CASE( STRS, os2.yStrikeoutSize ); - GX_VALUE_CASE( UNDO, postscript.underlinePosition ); - GX_VALUE_CASE( UNDS, postscript.underlineThickness ); - GX_VALUE_CASE( VASC, vertical.Ascender ); - GX_VALUE_CASE( VCOF, vertical.caret_Offset ); - GX_VALUE_CASE( VCRN, vertical.caret_Slope_Run ); - GX_VALUE_CASE( VCRS, vertical.caret_Slope_Rise ); - GX_VALUE_CASE( VDSC, vertical.Descender ); - GX_VALUE_CASE( VLGP, vertical.Line_Gap ); - GX_VALUE_CASE( XHGT, os2.sxHeight ); - - default: - /* ignore unknown tag */ - p = NULL; - } - - return p; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_mvar */ - /* */ - /* <Description> */ - /* Parse the `MVAR' table. */ - /* */ - /* Some memory may remain allocated on error; it is always freed in */ - /* `tt_done_blend', however. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - static void - ft_var_load_mvar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - - GX_Blend blend = face->blend; - GX_ItemVarStore itemStore; - GX_Value value, limit; - - FT_Error error; - FT_UShort majorVersion; - FT_ULong table_len; - FT_ULong table_offset; - FT_UShort store_offset; - FT_ULong records_offset; - - - FT_TRACE2(( "MVAR " )); - - error = face->goto_table( face, TTAG_MVAR, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - return; - } - - table_offset = FT_STREAM_POS(); - - /* skip minor version */ - if ( FT_READ_USHORT( majorVersion ) || - FT_STREAM_SKIP( 2 ) ) - return; - - if ( majorVersion != 1 ) - { - FT_TRACE2(( "bad table version %d\n", majorVersion )); - return; - } - - if ( FT_NEW( blend->mvar_table ) ) - return; - - /* skip reserved entry and value record size */ - if ( FT_STREAM_SKIP( 4 ) || - FT_READ_USHORT( blend->mvar_table->valueCount ) || - FT_READ_USHORT( store_offset ) ) - return; - - records_offset = FT_STREAM_POS(); - - error = ft_var_load_item_variation_store( - face, - table_offset + store_offset, - &blend->mvar_table->itemStore ); - if ( error ) - return; - - if ( FT_NEW_ARRAY( blend->mvar_table->values, - blend->mvar_table->valueCount ) ) - return; - - if ( FT_STREAM_SEEK( records_offset ) || - FT_FRAME_ENTER( blend->mvar_table->valueCount * GX_VALUE_SIZE ) ) - return; - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - itemStore = &blend->mvar_table->itemStore; - - for ( ; value < limit; value++ ) - { - value->tag = FT_GET_ULONG(); - value->outerIndex = FT_GET_USHORT(); - value->innerIndex = FT_GET_USHORT(); - - if ( value->outerIndex >= itemStore->dataCount || - value->innerIndex >= itemStore->varData[value->outerIndex] - .itemCount ) - { - error = FT_THROW( Invalid_Table ); - break; - } - } - - FT_FRAME_EXIT(); - - if ( error ) - return; - - FT_TRACE2(( "loaded\n" )); - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - - /* save original values of the data MVAR is going to modify */ - for ( ; value < limit; value++ ) - { - FT_Short* p = ft_var_get_value_pointer( face, value->tag ); - - - if ( p ) - value->unmodified = *p; -#ifdef FT_DEBUG_LEVEL_TRACE - else - FT_TRACE1(( "ft_var_load_mvar: Ignoring unknown tag `%c%c%c%c'\n", - (FT_Char)( value->tag >> 24 ), - (FT_Char)( value->tag >> 16 ), - (FT_Char)( value->tag >> 8 ), - (FT_Char)( value->tag ) )); -#endif - } - - face->variation_support |= TT_FACE_FLAG_VAR_MVAR; - } - - - static FT_Error - tt_size_reset_iterator( FT_ListNode node, - void* user ) - { - TT_Size size = (TT_Size)node->data; - - FT_UNUSED( user ); - - - tt_size_reset( size, 1 ); - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_apply_mvar */ - /* */ - /* <Description> */ - /* Apply `MVAR' table adjustments. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - FT_LOCAL_DEF( void ) - tt_apply_mvar( TT_Face face ) - { - GX_Blend blend = face->blend; - GX_Value value, limit; - - - if ( !( face->variation_support & TT_FACE_FLAG_VAR_MVAR ) ) - return; - - value = blend->mvar_table->values; - limit = value + blend->mvar_table->valueCount; - - for ( ; value < limit; value++ ) - { - FT_Short* p = ft_var_get_value_pointer( face, value->tag ); - FT_Int delta; - - - delta = ft_var_get_item_delta( face, - &blend->mvar_table->itemStore, - value->outerIndex, - value->innerIndex ); - - if ( p ) - { - FT_TRACE5(( "value %c%c%c%c (%d units) adjusted by %d units (MVAR)\n", - (FT_Char)( value->tag >> 24 ), - (FT_Char)( value->tag >> 16 ), - (FT_Char)( value->tag >> 8 ), - (FT_Char)( value->tag ), - value->unmodified, - delta )); - - /* since we handle both signed and unsigned values as FT_Short, */ - /* ensure proper overflow arithmetic */ - *p = (FT_Short)( value->unmodified + (FT_Short)delta ); - } - } - - /* adjust all derived values */ - { - FT_Face root = &face->root; - - - if ( face->os2.version != 0xFFFFU ) - { - if ( face->os2.sTypoAscender || face->os2.sTypoDescender ) - { - root->ascender = face->os2.sTypoAscender; - root->descender = face->os2.sTypoDescender; - - root->height = root->ascender - root->descender + - face->os2.sTypoLineGap; - } - else - { - root->ascender = (FT_Short)face->os2.usWinAscent; - root->descender = -(FT_Short)face->os2.usWinDescent; - - root->height = root->ascender - root->descender; - } - } - - root->underline_position = face->postscript.underlinePosition - - face->postscript.underlineThickness / 2; - root->underline_thickness = face->postscript.underlineThickness; - - /* iterate over all FT_Size objects and call `tt_size_reset' */ - /* to propagate the metrics changes */ - FT_List_Iterate( &root->sizes_list, - tt_size_reset_iterator, - NULL ); - } - } - - - typedef struct GX_GVar_Head_ - { - FT_Long version; - FT_UShort axisCount; - FT_UShort globalCoordCount; - FT_ULong offsetToCoord; - FT_UShort glyphCount; - FT_UShort flags; - FT_ULong offsetToData; - - } GX_GVar_Head; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_load_gvar */ - /* */ - /* <Description> */ - /* Parse the `gvar' table if present. If `fvar' is there, `gvar' had */ - /* better be there too. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - static FT_Error - ft_var_load_gvar( TT_Face face ) - { - FT_Stream stream = FT_FACE_STREAM( face ); - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - FT_Error error; - FT_UInt i, j; - FT_ULong table_len; - FT_ULong gvar_start; - FT_ULong offsetToData; - GX_GVar_Head gvar_head; - - static const FT_Frame_Field gvar_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_GVar_Head - - FT_FRAME_START( 20 ), - FT_FRAME_LONG ( version ), - FT_FRAME_USHORT( axisCount ), - FT_FRAME_USHORT( globalCoordCount ), - FT_FRAME_ULONG ( offsetToCoord ), - FT_FRAME_USHORT( glyphCount ), - FT_FRAME_USHORT( flags ), - FT_FRAME_ULONG ( offsetToData ), - FT_FRAME_END - }; - - - FT_TRACE2(( "GVAR " )); - - if ( FT_SET_ERROR( face->goto_table( face, - TTAG_gvar, - stream, - &table_len ) ) ) - { - FT_TRACE2(( "is missing\n" )); - goto Exit; - } - - gvar_start = FT_STREAM_POS( ); - if ( FT_STREAM_READ_FIELDS( gvar_fields, &gvar_head ) ) - goto Exit; - - if ( gvar_head.version != 0x00010000L ) - { - FT_TRACE1(( "bad table version\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - if ( gvar_head.axisCount != (FT_UShort)blend->mmvar->num_axis ) - { - FT_TRACE1(( "ft_var_load_gvar: number of axes in `gvar' and `cvar'\n" - " table are different\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* rough sanity check, ignoring offsets */ - if ( (FT_ULong)gvar_head.globalCoordCount * gvar_head.axisCount > - table_len / 2 ) - { - FT_TRACE1(( "ft_var_load_gvar:" - " invalid number of global coordinates\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - /* rough sanity check: offsets can be either 2 or 4 bytes */ - if ( (FT_ULong)gvar_head.glyphCount * - ( ( gvar_head.flags & 1 ) ? 4 : 2 ) > table_len ) - { - FT_TRACE1(( "ft_var_load_gvar: invalid number of glyphs\n" )); - error = FT_THROW( Invalid_Table ); - goto Exit; - } - - FT_TRACE2(( "loaded\n" )); - - blend->gvar_size = table_len; - blend->tuplecount = gvar_head.globalCoordCount; - blend->gv_glyphcnt = gvar_head.glyphCount; - offsetToData = gvar_start + gvar_head.offsetToData; - - FT_TRACE5(( "gvar: there are %d shared coordinates:\n", - blend->tuplecount )); - - if ( FT_NEW_ARRAY( blend->glyphoffsets, blend->gv_glyphcnt + 1 ) ) - goto Exit; - - if ( gvar_head.flags & 1 ) - { - /* long offsets (one more offset than glyphs, to mark size of last) */ - if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 4L ) ) - goto Exit; - - for ( i = 0; i <= blend->gv_glyphcnt; i++ ) - blend->glyphoffsets[i] = offsetToData + FT_GET_ULONG(); - - FT_FRAME_EXIT(); - } - else - { - /* short offsets (one more offset than glyphs, to mark size of last) */ - if ( FT_FRAME_ENTER( ( blend->gv_glyphcnt + 1 ) * 2L ) ) - goto Exit; - - for ( i = 0; i <= blend->gv_glyphcnt; i++ ) - blend->glyphoffsets[i] = offsetToData + FT_GET_USHORT() * 2; - /* XXX: Undocumented: `*2'! */ - - FT_FRAME_EXIT(); - } - - if ( blend->tuplecount != 0 ) - { - if ( FT_NEW_ARRAY( blend->tuplecoords, - gvar_head.axisCount * blend->tuplecount ) ) - goto Exit; - - if ( FT_STREAM_SEEK( gvar_start + gvar_head.offsetToCoord ) || - FT_FRAME_ENTER( blend->tuplecount * gvar_head.axisCount * 2L ) ) - goto Exit; - - for ( i = 0; i < blend->tuplecount; i++ ) - { - FT_TRACE5(( " [ " )); - for ( j = 0; j < (FT_UInt)gvar_head.axisCount; j++ ) - { - blend->tuplecoords[i * gvar_head.axisCount + j] = - FT_GET_SHORT() * 4; /* convert to FT_Fixed */ - FT_TRACE5(( "%.5f ", - blend->tuplecoords[i * gvar_head.axisCount + j] / 65536.0 )); - } - FT_TRACE5(( "]\n" )); - } - - FT_TRACE5(( "\n" )); - - FT_FRAME_EXIT(); - } - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* ft_var_apply_tuple */ - /* */ - /* <Description> */ - /* Figure out whether a given tuple (design) applies to the current */ - /* blend, and if so, what is the scaling factor. */ - /* */ - /* <Input> */ - /* blend :: The current blend of the font. */ - /* */ - /* tupleIndex :: A flag saying whether this is an intermediate */ - /* tuple or not. */ - /* */ - /* tuple_coords :: The coordinates of the tuple in normalized axis */ - /* units. */ - /* */ - /* im_start_coords :: The initial coordinates where this tuple starts */ - /* to apply (for intermediate coordinates). */ - /* */ - /* im_end_coords :: The final coordinates after which this tuple no */ - /* longer applies (for intermediate coordinates). */ - /* */ - /* <Return> */ - /* An FT_Fixed value containing the scaling factor. */ - /* */ - static FT_Fixed - ft_var_apply_tuple( GX_Blend blend, - FT_UShort tupleIndex, - FT_Fixed* tuple_coords, - FT_Fixed* im_start_coords, - FT_Fixed* im_end_coords ) - { - FT_UInt i; - FT_Fixed apply = 0x10000L; - - - for ( i = 0; i < blend->num_axis; i++ ) - { - FT_TRACE6(( " axis coordinate %d (%.5f):\n", - i, blend->normalizedcoords[i] / 65536.0 )); - if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) - FT_TRACE6(( " intermediate coordinates %d (%.5f, %.5f):\n", - i, - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - - /* It's not clear why (for intermediate tuples) we don't need */ - /* to check against start/end -- the documentation says we don't. */ - /* Similarly, it's unclear why we don't need to scale along the */ - /* axis. */ - - if ( tuple_coords[i] == 0 ) - { - FT_TRACE6(( " tuple coordinate is zero, ignored\n", i )); - continue; - } - - if ( blend->normalizedcoords[i] == 0 ) - { - FT_TRACE6(( " axis coordinate is zero, stop\n" )); - apply = 0; - break; - } - - if ( blend->normalizedcoords[i] == tuple_coords[i] ) - { - FT_TRACE6(( " tuple coordinate value %.5f fits perfectly\n", - tuple_coords[i] / 65536.0 )); - /* `apply' does not change */ - continue; - } - - if ( !( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) ) - { - /* not an intermediate tuple */ - - if ( blend->normalizedcoords[i] < FT_MIN( 0, tuple_coords[i] ) || - blend->normalizedcoords[i] > FT_MAX( 0, tuple_coords[i] ) ) - { - FT_TRACE6(( " tuple coordinate value %.5f is exceeded, stop\n", - tuple_coords[i] / 65536.0 )); - apply = 0; - break; - } - - FT_TRACE6(( " tuple coordinate value %.5f fits\n", - tuple_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - blend->normalizedcoords[i], - tuple_coords[i] ); - } - else - { - /* intermediate tuple */ - - if ( blend->normalizedcoords[i] < im_start_coords[i] || - blend->normalizedcoords[i] > im_end_coords[i] ) - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] is exceeded," - " stop\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = 0; - break; - } - - else if ( blend->normalizedcoords[i] < tuple_coords[i] ) - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] fits\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - blend->normalizedcoords[i] - im_start_coords[i], - tuple_coords[i] - im_start_coords[i] ); - } - - else - { - FT_TRACE6(( " intermediate tuple range [%.5f;%.5f] fits\n", - im_start_coords[i] / 65536.0, - im_end_coords[i] / 65536.0 )); - apply = FT_MulDiv( apply, - im_end_coords[i] - blend->normalizedcoords[i], - im_end_coords[i] - tuple_coords[i] ); - } - } - } - - FT_TRACE6(( " apply factor is %.5f\n", apply / 65536.0 )); - - return apply; - } - - - /* convert from design coordinates to normalized coordinates */ - - static void - ft_var_to_normalized( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Fixed* normalized ) - { - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i, j; - FT_Var_Axis* a; - GX_AVarSegment av; - - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "ft_var_to_normalized:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - /* Axis normalization is a two-stage process. First we normalize */ - /* based on the [min,def,max] values for the axis to be [-1,0,1]. */ - /* Then, if there's an `avar' table, we renormalize this range. */ - - FT_TRACE5(( "design coordinates:\n" )); - - a = mmvar->axis; - for ( i = 0; i < num_coords; i++, a++ ) - { - FT_Fixed coord = coords[i]; - - - FT_TRACE5(( " %.5f\n", coord / 65536.0 )); - if ( coord > a->maximum || coord < a->minimum ) - { - FT_TRACE1(( - "ft_var_to_normalized: design coordinate %.5f\n" - " is out of range [%.5f;%.5f]; clamping\n", - coord / 65536.0, - a->minimum / 65536.0, - a->maximum / 65536.0 )); - - if ( coord > a->maximum) - coord = a->maximum; - else - coord = a->minimum; - } - - if ( coord < a->def ) - normalized[i] = -FT_DivFix( coords[i] - a->def, - a->minimum - a->def ); - else if ( coord > a->def ) - normalized[i] = FT_DivFix( coords[i] - a->def, - a->maximum - a->def ); - else - normalized[i] = 0; - } - - FT_TRACE5(( "\n" )); - - for ( ; i < mmvar->num_axis; i++ ) - normalized[i] = 0; - - if ( blend->avar_segment ) - { - FT_TRACE5(( "normalized design coordinates" - " before applying `avar' data:\n" )); - - av = blend->avar_segment; - for ( i = 0; i < mmvar->num_axis; i++, av++ ) - { - for ( j = 1; j < (FT_UInt)av->pairCount; j++ ) - { - if ( normalized[i] < av->correspondence[j].fromCoord ) - { - FT_TRACE5(( " %.5f\n", normalized[i] / 65536.0 )); - - normalized[i] = - FT_MulDiv( normalized[i] - av->correspondence[j - 1].fromCoord, - av->correspondence[j].toCoord - - av->correspondence[j - 1].toCoord, - av->correspondence[j].fromCoord - - av->correspondence[j - 1].fromCoord ) + - av->correspondence[j - 1].toCoord; - break; - } - } - } - } - } - - - /* convert from normalized coordinates to design coordinates */ - - static void - ft_var_to_design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Fixed* design ) - { - GX_Blend blend; - FT_MM_Var* mmvar; - FT_Var_Axis* a; - - FT_UInt i, j, nc; - - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "ft_var_to_design:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - design[i] = coords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - design[i] = 0; - } - - for ( ; i < num_coords; i++ ) - design[i] = 0; - - if ( blend->avar_segment ) - { - GX_AVarSegment av = blend->avar_segment; - - - FT_TRACE5(( "design coordinates" - " after removing `avar' distortion:\n" )); - - for ( i = 0; i < nc; i++, av++ ) - { - for ( j = 1; j < (FT_UInt)av->pairCount; j++ ) - { - if ( design[i] < av->correspondence[j].toCoord ) - { - design[i] = - FT_MulDiv( design[i] - av->correspondence[j - 1].toCoord, - av->correspondence[j].fromCoord - - av->correspondence[j - 1].fromCoord, - av->correspondence[j].toCoord - - av->correspondence[j - 1].toCoord ) + - av->correspondence[j - 1].fromCoord; - - FT_TRACE5(( " %.5f\n", design[i] / 65536.0 )); - break; - } - } - } - } - - mmvar = blend->mmvar; - a = mmvar->axis; - - for ( i = 0; i < nc; i++, a++ ) - { - if ( design[i] < 0 ) - design[i] = a->def + FT_MulFix( design[i], - a->def - a->minimum ); - else if ( design[i] > 0 ) - design[i] = a->def + FT_MulFix( design[i], - a->maximum - a->def ); - else - design[i] = a->def; - } - } - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** MULTIPLE MASTERS SERVICE FUNCTIONS *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - typedef struct GX_FVar_Head_ - { - FT_Long version; - FT_UShort offsetToData; - FT_UShort axisCount; - FT_UShort axisSize; - FT_UShort instanceCount; - FT_UShort instanceSize; - - } GX_FVar_Head; - - - typedef struct fvar_axis_ - { - FT_ULong axisTag; - FT_Fixed minValue; - FT_Fixed defaultValue; - FT_Fixed maxValue; - FT_UShort flags; - FT_UShort nameID; - - } GX_FVar_Axis; - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_MM_Var */ - /* */ - /* <Description> */ - /* Check that the font's `fvar' table is valid, parse it, and return */ - /* those data. It also loads (and parses) the `MVAR' table, if */ - /* possible. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* TT_Get_MM_Var initializes the blend structure. */ - /* */ - /* <Output> */ - /* master :: The `fvar' data (must be freed by caller). Can be NULL, */ - /* which makes this function simply load MM support. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_MM_Var( TT_Face face, - FT_MM_Var* *master ) - { - FT_Stream stream = face->root.stream; - FT_Memory memory = face->root.memory; - FT_ULong table_len; - FT_Error error = FT_Err_Ok; - FT_ULong fvar_start; - FT_UInt i, j; - FT_MM_Var* mmvar = NULL; - FT_Fixed* next_coords; - FT_Fixed* nsc; - FT_String* next_name; - FT_Var_Axis* a; - FT_Fixed* c; - FT_Var_Named_Style* ns; - GX_FVar_Head fvar_head; - FT_Bool usePsName; - FT_UInt num_instances; - - static const FT_Frame_Field fvar_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_FVar_Head - - FT_FRAME_START( 16 ), - FT_FRAME_LONG ( version ), - FT_FRAME_USHORT ( offsetToData ), - FT_FRAME_SKIP_SHORT, - FT_FRAME_USHORT ( axisCount ), - FT_FRAME_USHORT ( axisSize ), - FT_FRAME_USHORT ( instanceCount ), - FT_FRAME_USHORT ( instanceSize ), - FT_FRAME_END - }; - - static const FT_Frame_Field fvaraxis_fields[] = - { - -#undef FT_STRUCTURE -#define FT_STRUCTURE GX_FVar_Axis - - FT_FRAME_START( 20 ), - FT_FRAME_ULONG ( axisTag ), - FT_FRAME_LONG ( minValue ), - FT_FRAME_LONG ( defaultValue ), - FT_FRAME_LONG ( maxValue ), - FT_FRAME_USHORT( flags ), - FT_FRAME_USHORT( nameID ), - FT_FRAME_END - }; - - - /* read the font data and set up the internal representation */ - /* if not already done */ - - if ( !face->blend ) - { - FT_TRACE2(( "FVAR " )); - - /* both `fvar' and `gvar' must be present */ - if ( FT_SET_ERROR( face->goto_table( face, TTAG_gvar, - stream, &table_len ) ) ) - { - /* CFF2 is an alternate to gvar here */ - if ( FT_SET_ERROR( face->goto_table( face, TTAG_CFF2, - stream, &table_len ) ) ) - { - FT_TRACE1(( "\n" - "TT_Get_MM_Var: `gvar' or `CFF2' table is missing\n" )); - goto Exit; - } - } - - if ( FT_SET_ERROR( face->goto_table( face, TTAG_fvar, - stream, &table_len ) ) ) - { - FT_TRACE1(( "is missing\n" )); - goto Exit; - } - - fvar_start = FT_STREAM_POS( ); - - /* the validity of the `fvar' header data was already checked */ - /* in function `sfnt_init_face' */ - if ( FT_STREAM_READ_FIELDS( fvar_fields, &fvar_head ) ) - goto Exit; - - usePsName = FT_BOOL( fvar_head.instanceSize == - 6 + 4 * fvar_head.axisCount ); - - FT_TRACE2(( "loaded\n" )); - - FT_TRACE5(( "number of GX style axes: %d\n", fvar_head.axisCount )); - - if ( FT_NEW( face->blend ) ) - goto Exit; - - /* `num_instances' holds the number of all named instances, */ - /* including the default instance which might be missing */ - /* in fvar's table of named instances */ - num_instances = face->root.style_flags >> 16; - - /* cannot overflow 32-bit arithmetic because of the size limits */ - /* used in the `fvar' table validity check in `sfnt_init_face' */ - face->blend->mmvar_len = - sizeof ( FT_MM_Var ) + - fvar_head.axisCount * sizeof ( FT_Var_Axis ) + - num_instances * sizeof ( FT_Var_Named_Style ) + - num_instances * fvar_head.axisCount * sizeof ( FT_Fixed ) + - 5 * fvar_head.axisCount; - - if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) - goto Exit; - face->blend->mmvar = mmvar; - - /* set up pointers and offsets into the `mmvar' array; */ - /* the data gets filled in later on */ - - mmvar->num_axis = - fvar_head.axisCount; - mmvar->num_designs = - ~0U; /* meaningless in this context; each glyph */ - /* may have a different number of designs */ - /* (or tuples, as called by Apple) */ - mmvar->num_namedstyles = - num_instances; - mmvar->axis = - (FT_Var_Axis*)&( mmvar[1] ); - mmvar->namedstyle = - (FT_Var_Named_Style*)&( mmvar->axis[fvar_head.axisCount] ); - - next_coords = - (FT_Fixed*)&( mmvar->namedstyle[num_instances] ); - for ( i = 0; i < num_instances; i++ ) - { - mmvar->namedstyle[i].coords = next_coords; - next_coords += fvar_head.axisCount; - } - - next_name = (FT_String*)next_coords; - for ( i = 0; i < fvar_head.axisCount; i++ ) - { - mmvar->axis[i].name = next_name; - next_name += 5; - } - - /* now fill in the data */ - - if ( FT_STREAM_SEEK( fvar_start + fvar_head.offsetToData ) ) - goto Exit; - - a = mmvar->axis; - for ( i = 0; i < fvar_head.axisCount; i++ ) - { - GX_FVar_Axis axis_rec; - - - if ( FT_STREAM_READ_FIELDS( fvaraxis_fields, &axis_rec ) ) - goto Exit; - a->tag = axis_rec.axisTag; - a->minimum = axis_rec.minValue; - a->def = axis_rec.defaultValue; - a->maximum = axis_rec.maxValue; - a->strid = axis_rec.nameID; - - a->name[0] = (FT_String)( a->tag >> 24 ); - a->name[1] = (FT_String)( ( a->tag >> 16 ) & 0xFF ); - a->name[2] = (FT_String)( ( a->tag >> 8 ) & 0xFF ); - a->name[3] = (FT_String)( ( a->tag ) & 0xFF ); - a->name[4] = '\0'; - - if ( a->minimum > a->def || - a->def > a->maximum ) - { - FT_TRACE2(( "TT_Get_MM_Var:" - " invalid \"%s\" axis record; disabling\n", - a->name )); - - a->minimum = a->def; - a->maximum = a->def; - } - - FT_TRACE5(( " \"%s\": minimum=%.5f, default=%.5f, maximum=%.5f\n", - a->name, - a->minimum / 65536.0, - a->def / 65536.0, - a->maximum / 65536.0 )); - - a++; - } - - FT_TRACE5(( "\n" )); - - /* named instance coordinates are stored as design coordinates; */ - /* we have to convert them to normalized coordinates also */ - if ( FT_NEW_ARRAY( face->blend->normalized_stylecoords, - fvar_head.axisCount * num_instances ) ) - goto Exit; - - if ( fvar_head.instanceCount && !face->blend->avar_loaded ) - { - FT_ULong offset = FT_STREAM_POS(); - - - ft_var_load_avar( face ); - - if ( FT_STREAM_SEEK( offset ) ) - goto Exit; - } - - ns = mmvar->namedstyle; - nsc = face->blend->normalized_stylecoords; - for ( i = 0; i < fvar_head.instanceCount; i++, ns++ ) - { - /* PostScript names add 2 bytes to the instance record size */ - if ( FT_FRAME_ENTER( ( usePsName ? 6L : 4L ) + - 4L * fvar_head.axisCount ) ) - goto Exit; - - ns->strid = FT_GET_USHORT(); - (void) /* flags = */ FT_GET_USHORT(); - - c = ns->coords; - for ( j = 0; j < fvar_head.axisCount; j++, c++ ) - *c = FT_GET_LONG(); - - /* valid psid values are 6 and [256;32767] */ - if ( usePsName ) - ns->psid = FT_GET_USHORT(); - - ft_var_to_normalized( face, - fvar_head.axisCount, - ns->coords, - nsc ); - nsc += fvar_head.axisCount; - - FT_FRAME_EXIT(); - } - - if ( num_instances != fvar_head.instanceCount ) - { - SFNT_Service sfnt = (SFNT_Service)face->sfnt; - - FT_Int found, dummy1, dummy2; - FT_UInt strid = ~0U; - - - /* the default instance is missing in array the */ - /* of named instances; try to synthesize an entry */ - found = sfnt->get_name_id( face, - TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY, - &dummy1, - &dummy2 ); - if ( found ) - strid = TT_NAME_ID_TYPOGRAPHIC_SUBFAMILY; - else - { - found = sfnt->get_name_id( face, - TT_NAME_ID_FONT_SUBFAMILY, - &dummy1, - &dummy2 ); - if ( found ) - strid = TT_NAME_ID_FONT_SUBFAMILY; - } - - if ( found ) - { - found = sfnt->get_name_id( face, - TT_NAME_ID_PS_NAME, - &dummy1, - &dummy2 ); - if ( found ) - { - FT_TRACE5(( "TT_Get_MM_Var:" - " Adding default instance to named instances\n" )); - - ns = &mmvar->namedstyle[fvar_head.instanceCount]; - - ns->strid = strid; - ns->psid = TT_NAME_ID_PS_NAME; - - a = mmvar->axis; - c = ns->coords; - for ( j = 0; j < fvar_head.axisCount; j++, a++, c++ ) - *c = a->def; - } - } - } - - ft_var_load_mvar( face ); - } - - /* fill the output array if requested */ - - if ( master ) - { - FT_UInt n; - - - if ( FT_ALLOC( mmvar, face->blend->mmvar_len ) ) - goto Exit; - FT_MEM_COPY( mmvar, face->blend->mmvar, face->blend->mmvar_len ); - - mmvar->axis = - (FT_Var_Axis*)&( mmvar[1] ); - mmvar->namedstyle = - (FT_Var_Named_Style*)&( mmvar->axis[mmvar->num_axis] ); - next_coords = - (FT_Fixed*)&( mmvar->namedstyle[mmvar->num_namedstyles] ); - - for ( n = 0; n < mmvar->num_namedstyles; n++ ) - { - mmvar->namedstyle[n].coords = next_coords; - next_coords += mmvar->num_axis; - } - - a = mmvar->axis; - next_name = (FT_String*)next_coords; - for ( n = 0; n < mmvar->num_axis; n++ ) - { - a->name = next_name; - - /* standard PostScript names for some standard apple tags */ - if ( a->tag == TTAG_wght ) - a->name = (char*)"Weight"; - else if ( a->tag == TTAG_wdth ) - a->name = (char*)"Width"; - else if ( a->tag == TTAG_opsz ) - a->name = (char*)"OpticalSize"; - else if ( a->tag == TTAG_slnt ) - a->name = (char*)"Slant"; - - next_name += 5; - a++; - } - - *master = mmvar; - } - - Exit: - return error; - } - - - static FT_Error - tt_set_mm_blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords, - FT_Bool set_design_coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i, j; - FT_Bool is_default_instance = 1; - FT_Memory memory = face->root.memory; - - enum - { - mcvt_retain, - mcvt_modify, - mcvt_load - - } manageCvt; - - - face->doblend = FALSE; - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - goto Exit; - } - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "TT_Set_MM_Blend:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - FT_TRACE5(( "normalized design coordinates:\n" )); - - for ( i = 0; i < num_coords; i++ ) - { - FT_TRACE5(( " %.5f\n", coords[i] / 65536.0 )); - if ( coords[i] < -0x00010000L || coords[i] > 0x00010000L ) - { - FT_TRACE1(( "TT_Set_MM_Blend: normalized design coordinate %.5f\n" - " is out of range [-1;1]\n", - coords[i] / 65536.0 )); - error = FT_THROW( Invalid_Argument ); - goto Exit; - } - - if ( coords[i] != 0 ) - is_default_instance = 0; - } - - FT_TRACE5(( "\n" )); - - if ( !face->is_cff2 && !blend->glyphoffsets ) - if ( FT_SET_ERROR( ft_var_load_gvar( face ) ) ) - goto Exit; - - if ( !blend->coords ) - { - if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) ) - goto Exit; - } - - if ( !blend->normalizedcoords ) - { - if ( FT_NEW_ARRAY( blend->normalizedcoords, mmvar->num_axis ) ) - goto Exit; - - manageCvt = mcvt_modify; - - /* If we have not set the blend coordinates before this, then the */ - /* cvt table will still be what we read from the `cvt ' table and */ - /* we don't need to reload it. We may need to change it though... */ - } - else - { - manageCvt = mcvt_retain; - - for ( i = 0; i < num_coords; i++ ) - { - if ( blend->normalizedcoords[i] != coords[i] ) - { - manageCvt = mcvt_load; - break; - } - } - - for ( ; i < mmvar->num_axis; i++ ) - { - if ( blend->normalizedcoords[i] != 0 ) - { - manageCvt = mcvt_load; - break; - } - } - - /* If we don't change the blend coords then we don't need to do */ - /* anything to the cvt table. It will be correct. Otherwise we */ - /* no longer have the original cvt (it was modified when we set */ - /* the blend last time), so we must reload and then modify it. */ - } - - blend->num_axis = mmvar->num_axis; - FT_MEM_COPY( blend->normalizedcoords, - coords, - num_coords * sizeof ( FT_Fixed ) ); - - if ( set_design_coords ) - ft_var_to_design( face, - num_coords, - blend->normalizedcoords, - blend->coords ); - - face->doblend = TRUE; - - if ( face->cvt ) - { - switch ( manageCvt ) - { - case mcvt_load: - /* The cvt table has been loaded already; every time we change the */ - /* blend we may need to reload and remodify the cvt table. */ - FT_FREE( face->cvt ); - face->cvt = NULL; - - error = tt_face_load_cvt( face, face->root.stream ); - break; - - case mcvt_modify: - /* The original cvt table is in memory. All we need to do is */ - /* apply the `cvar' table (if any). */ - error = tt_face_vary_cvt( face, face->root.stream ); - break; - - case mcvt_retain: - /* The cvt table is correct for this set of coordinates. */ - break; - } - } - - /* check whether the current variation tuple coincides */ - /* with a named instance */ - - for ( i = 0; i < blend->mmvar->num_namedstyles; i++ ) - { - FT_Fixed* nsc = blend->normalized_stylecoords + i * blend->num_axis; - FT_Fixed* ns = blend->normalizedcoords; - - - for ( j = 0; j < blend->num_axis; j++, nsc++, ns++ ) - { - if ( *nsc != *ns ) - break; - } - - if ( j == blend->num_axis ) - break; - } - - /* adjust named instance index */ - face->root.face_index &= 0xFFFF; - if ( i < blend->mmvar->num_namedstyles ) - face->root.face_index |= ( i + 1 ) << 16; - - face->is_default_instance = is_default_instance; - - /* enforce recomputation of the PostScript name; */ - FT_FREE( face->postscript_name ); - face->postscript_name = NULL; - - Exit: - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Set_MM_Blend */ - /* */ - /* <Description> */ - /* Set the blend (normalized) coordinates for this instance of the */ - /* font. Check that the `gvar' table is reasonable and does some */ - /* initial preparation. */ - /* */ - /* <InOut> */ - /* face :: The font. */ - /* Initialize the blend structure with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use the default value (0) for the remaining axes. */ - /* */ - /* coords :: An array of `num_coords', each between [-1,1]. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Set_MM_Blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - return tt_set_mm_blend( face, num_coords, coords, 1 ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_MM_Blend */ - /* */ - /* <Description> */ - /* Get the blend (normalized) coordinates for this instance of the */ - /* font. */ - /* */ - /* <InOut> */ - /* face :: The font. */ - /* Initialize the blend structure with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, set the excess */ - /* values to 0. */ - /* */ - /* coords :: An array of `num_coords', each between [-1,1]. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_MM_Blend( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_UInt i, nc; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - return error; - } - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "TT_Get_MM_Blend:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - coords[i] = blend->normalizedcoords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - coords[i] = 0; - } - - for ( ; i < num_coords; i++ ) - coords[i] = 0; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Set_Var_Design */ - /* */ - /* <Description> */ - /* Set the coordinates for the instance, measured in the user */ - /* coordinate system. Parse the `avar' table (if present) to convert */ - /* from user to normalized coordinates. */ - /* */ - /* <InOut> */ - /* face :: The font face. */ - /* Initialize the blend struct with `gvar' data. */ - /* */ - /* <Input> */ - /* num_coords :: The number of available coordinates. If it is */ - /* larger than the number of axes, ignore the excess */ - /* values. If it is smaller than the number of axes, */ - /* use the default values for the remaining axes. */ - /* */ - /* coords :: A coordinate array with `num_coords' elements. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Set_Var_Design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_MM_Var* mmvar; - FT_UInt i; - FT_Memory memory = face->root.memory; - - FT_Var_Axis* a; - FT_Fixed* c; - - FT_Fixed* normalized = NULL; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - goto Exit; - } - - blend = face->blend; - mmvar = blend->mmvar; - - if ( num_coords > mmvar->num_axis ) - { - FT_TRACE2(( "TT_Set_Var_Design:" - " only using first %d of %d coordinates\n", - mmvar->num_axis, num_coords )); - num_coords = mmvar->num_axis; - } - - if ( !blend->coords ) - { - if ( FT_NEW_ARRAY( blend->coords, mmvar->num_axis ) ) - goto Exit; - } - - FT_MEM_COPY( blend->coords, - coords, - num_coords * sizeof ( FT_Fixed ) ); - - a = mmvar->axis + num_coords; - c = coords + num_coords; - for ( i = num_coords; i < mmvar->num_axis; i++, a++, c++ ) - *c = a->def; - - if ( FT_NEW_ARRAY( normalized, mmvar->num_axis ) ) - goto Exit; - - if ( !face->blend->avar_loaded ) - ft_var_load_avar( face ); - - ft_var_to_normalized( face, num_coords, coords, normalized ); - - error = tt_set_mm_blend( face, mmvar->num_axis, normalized, 0 ); - - Exit: - FT_FREE( normalized ); - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Get_Var_Design */ - /* */ - /* <Description> */ - /* Get the design coordinates of the currently selected interpolated */ - /* font. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face. */ - /* */ - /* num_coords :: The number of design coordinates to retrieve. If it */ - /* is larger than the number of axes, set the excess */ - /* values to~0. */ - /* */ - /* <Output> */ - /* coords :: The design coordinates array. */ - /* */ - /* <Return> */ - /* FreeType error code. 0~means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Get_Var_Design( TT_Face face, - FT_UInt num_coords, - FT_Fixed* coords ) - { - FT_Error error = FT_Err_Ok; - GX_Blend blend; - FT_UInt i, nc; - - - if ( !face->blend ) - { - if ( FT_SET_ERROR( TT_Get_MM_Var( face, NULL ) ) ) - return error; - } - - blend = face->blend; - - nc = num_coords; - if ( num_coords > blend->num_axis ) - { - FT_TRACE2(( "TT_Get_Var_Design:" - " only using first %d of %d coordinates\n", - blend->num_axis, num_coords )); - nc = blend->num_axis; - } - - if ( face->doblend ) - { - for ( i = 0; i < nc; i++ ) - coords[i] = blend->coords[i]; - } - else - { - for ( i = 0; i < nc; i++ ) - coords[i] = 0; - } - - for ( ; i < num_coords; i++ ) - coords[i] = 0; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GX VAR PARSING ROUTINES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_face_vary_cvt */ - /* */ - /* <Description> */ - /* Modify the loaded cvt table according to the `cvar' table and the */ - /* font's blend. */ - /* */ - /* <InOut> */ - /* face :: A handle to the target face object. */ - /* */ - /* <Input> */ - /* stream :: A handle to the input stream. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - /* Most errors are ignored. It is perfectly valid not to have a */ - /* `cvar' table even if there is a `gvar' and `fvar' table. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - tt_face_vary_cvt( TT_Face face, - FT_Stream stream ) - { - FT_Error error; - FT_Memory memory = stream->memory; - FT_ULong table_start; - FT_ULong table_len; - FT_UInt tupleCount; - FT_ULong offsetToData; - FT_ULong here; - FT_UInt i, j; - FT_Fixed* tuple_coords = NULL; - FT_Fixed* im_start_coords = NULL; - FT_Fixed* im_end_coords = NULL; - GX_Blend blend = face->blend; - FT_UInt point_count; - FT_UShort* localpoints; - FT_Short* deltas; - - - FT_TRACE2(( "CVAR " )); - - if ( !blend ) - { - FT_TRACE2(( "\n" - "tt_face_vary_cvt: no blend specified\n" )); - error = FT_Err_Ok; - goto Exit; - } - - if ( !face->cvt ) - { - FT_TRACE2(( "\n" - "tt_face_vary_cvt: no `cvt ' table\n" )); - error = FT_Err_Ok; - goto Exit; - } - - error = face->goto_table( face, TTAG_cvar, stream, &table_len ); - if ( error ) - { - FT_TRACE2(( "is missing\n" )); - - error = FT_Err_Ok; - goto Exit; - } - - if ( FT_FRAME_ENTER( table_len ) ) - { - error = FT_Err_Ok; - goto Exit; - } - - table_start = FT_Stream_FTell( stream ); - if ( FT_GET_LONG() != 0x00010000L ) - { - FT_TRACE2(( "bad table version\n" )); - - error = FT_Err_Ok; - goto FExit; - } - - FT_TRACE2(( "loaded\n" )); - - if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) - goto FExit; - - tupleCount = FT_GET_USHORT(); - offsetToData = FT_GET_USHORT(); - - /* rough sanity test */ - if ( offsetToData + ( tupleCount & GX_TC_TUPLE_COUNT_MASK ) * 4 > - table_len ) - { - FT_TRACE2(( "tt_face_vary_cvt:" - " invalid CVT variation array header\n" )); - - error = FT_THROW( Invalid_Table ); - goto FExit; - } - - offsetToData += table_start; - - /* The documentation implies there are flags packed into */ - /* `tupleCount', but John Jenkins says that shared points don't apply */ - /* to `cvar', and no other flags are defined. */ - - FT_TRACE5(( "cvar: there are %d tuples:\n", tupleCount & 0xFFF )); - - for ( i = 0; i < ( tupleCount & 0xFFF ); i++ ) - { - FT_UInt tupleDataSize; - FT_UInt tupleIndex; - FT_Fixed apply; - - - FT_TRACE6(( " tuple %d:\n", i )); - - tupleDataSize = FT_GET_USHORT(); - tupleIndex = FT_GET_USHORT(); - - /* There is no provision here for a global tuple coordinate section, */ - /* so John says. There are no tuple indices, just embedded tuples. */ - - if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) - { - for ( j = 0; j < blend->num_axis; j++ ) - tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */ - /* short frac to fixed */ - } - else - { - /* skip this tuple; it makes no sense */ - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - for ( j = 0; j < 2 * blend->num_axis; j++ ) - (void)FT_GET_SHORT(); - - offsetToData += tupleDataSize; - continue; - } - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - { - for ( j = 0; j < blend->num_axis; j++ ) - im_start_coords[j] = FT_GET_SHORT() * 4; - for ( j = 0; j < blend->num_axis; j++ ) - im_end_coords[j] = FT_GET_SHORT() * 4; - } - - apply = ft_var_apply_tuple( blend, - (FT_UShort)tupleIndex, - tuple_coords, - im_start_coords, - im_end_coords ); - if ( /* tuple isn't active for our blend */ - apply == 0 || - /* global points not allowed, */ - /* if they aren't local, makes no sense */ - !( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) ) - { - offsetToData += tupleDataSize; - continue; - } - - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - localpoints = ft_var_readpackedpoints( stream, - table_len, - &point_count ); - deltas = ft_var_readpackeddeltas( stream, - table_len, - point_count == 0 ? face->cvt_size - : point_count ); - if ( !localpoints || !deltas ) - ; /* failure, ignore it */ - - else if ( localpoints == ALL_POINTS ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " CVT deltas:\n" )); - - /* this means that there are deltas for every entry in cvt */ - for ( j = 0; j < face->cvt_size; j++ ) - { - FT_Long orig_cvt = face->cvt[j]; - - - face->cvt[j] = (FT_Short)( orig_cvt + - FT_MulFix( deltas[j], apply ) ); - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( orig_cvt != face->cvt[j] ) - { - FT_TRACE7(( " %d: %d -> %d\n", - j, orig_cvt, face->cvt[j] )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - else - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " CVT deltas:\n" )); - - for ( j = 0; j < point_count; j++ ) - { - int pindex; - FT_Long orig_cvt; - - - pindex = localpoints[j]; - if ( (FT_ULong)pindex >= face->cvt_size ) - continue; - - orig_cvt = face->cvt[pindex]; - face->cvt[pindex] = (FT_Short)( orig_cvt + - FT_MulFix( deltas[j], apply ) ); - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( orig_cvt != face->cvt[pindex] ) - { - FT_TRACE7(( " %d: %d -> %d\n", - pindex, orig_cvt, face->cvt[pindex] )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - if ( localpoints != ALL_POINTS ) - FT_FREE( localpoints ); - FT_FREE( deltas ); - - offsetToData += tupleDataSize; - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "\n" )); - - FExit: - FT_FRAME_EXIT(); - - Exit: - FT_FREE( tuple_coords ); - FT_FREE( im_start_coords ); - FT_FREE( im_end_coords ); - - return error; - } - - - /* Shift the original coordinates of all points between indices `p1' */ - /* and `p2', using the same difference as given by index `ref'. */ - - /* modeled after `af_iup_shift' */ - - static void - tt_delta_shift( int p1, - int p2, - int ref, - FT_Vector* in_points, - FT_Vector* out_points ) - { - int p; - FT_Vector delta; - - - delta.x = out_points[ref].x - in_points[ref].x; - delta.y = out_points[ref].y - in_points[ref].y; - - if ( delta.x == 0 && delta.y == 0 ) - return; - - for ( p = p1; p < ref; p++ ) - { - out_points[p].x += delta.x; - out_points[p].y += delta.y; - } - - for ( p = ref + 1; p <= p2; p++ ) - { - out_points[p].x += delta.x; - out_points[p].y += delta.y; - } - } - - - /* Interpolate the original coordinates of all points with indices */ - /* between `p1' and `p2', using `ref1' and `ref2' as the reference */ - /* point indices. */ - - /* modeled after `af_iup_interp', `_iup_worker_interpolate', and */ - /* `Ins_IUP' */ - - static void - tt_delta_interpolate( int p1, - int p2, - int ref1, - int ref2, - FT_Vector* in_points, - FT_Vector* out_points ) - { - int p, i; - - FT_Pos out, in1, in2, out1, out2, d1, d2; - - - if ( p1 > p2 ) - return; - - /* handle both horizontal and vertical coordinates */ - for ( i = 0; i <= 1; i++ ) - { - /* shift array pointers so that we can access `foo.y' as `foo.x' */ - in_points = (FT_Vector*)( (FT_Pos*)in_points + i ); - out_points = (FT_Vector*)( (FT_Pos*)out_points + i ); - - if ( in_points[ref1].x > in_points[ref2].x ) - { - p = ref1; - ref1 = ref2; - ref2 = p; - } - - in1 = in_points[ref1].x; - in2 = in_points[ref2].x; - out1 = out_points[ref1].x; - out2 = out_points[ref2].x; - d1 = out1 - in1; - d2 = out2 - in2; - - /* If the reference points have the same coordinate but different */ - /* delta, inferred delta is zero. Otherwise interpolate. */ - if ( in1 != in2 || out1 == out2 ) - { - FT_Fixed scale = in1 != in2 ? FT_DivFix( out2 - out1, in2 - in1 ) - : 0; - - - for ( p = p1; p <= p2; p++ ) - { - out = in_points[p].x; - - if ( out <= in1 ) - out += d1; - else if ( out >= in2 ) - out += d2; - else - out = out1 + FT_MulFix( out - in1, scale ); - - out_points[p].x = out; - } - } - } - } - - - /* Interpolate points without delta values, similar to */ - /* the `IUP' hinting instruction. */ - - /* modeled after `Ins_IUP */ - - static void - tt_interpolate_deltas( FT_Outline* outline, - FT_Vector* out_points, - FT_Vector* in_points, - FT_Bool* has_delta ) - { - FT_Int first_point; - FT_Int end_point; - - FT_Int first_delta; - FT_Int cur_delta; - - FT_Int point; - FT_Short contour; - - - /* ignore empty outlines */ - if ( !outline->n_contours ) - return; - - contour = 0; - point = 0; - - do - { - end_point = outline->contours[contour]; - first_point = point; - - /* search first point that has a delta */ - while ( point <= end_point && !has_delta[point] ) - point++; - - if ( point <= end_point ) - { - first_delta = point; - cur_delta = point; - - point++; - - while ( point <= end_point ) - { - /* search next point that has a delta */ - /* and interpolate intermediate points */ - if ( has_delta[point] ) - { - tt_delta_interpolate( cur_delta + 1, - point - 1, - cur_delta, - point, - in_points, - out_points ); - cur_delta = point; - } - - point++; - } - - /* shift contour if we only have a single delta */ - if ( cur_delta == first_delta ) - tt_delta_shift( first_point, - end_point, - cur_delta, - in_points, - out_points ); - else - { - /* otherwise handle remaining points */ - /* at the end and beginning of the contour */ - tt_delta_interpolate( cur_delta + 1, - end_point, - cur_delta, - first_delta, - in_points, - out_points ); - - if ( first_delta > 0 ) - tt_delta_interpolate( first_point, - first_delta - 1, - cur_delta, - first_delta, - in_points, - out_points ); - } - } - contour++; - - } while ( contour < outline->n_contours ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Vary_Apply_Glyph_Deltas */ - /* */ - /* <Description> */ - /* Apply the appropriate deltas to the current glyph. */ - /* */ - /* <Input> */ - /* face :: A handle to the target face object. */ - /* */ - /* glyph_index :: The index of the glyph being modified. */ - /* */ - /* n_points :: The number of the points in the glyph, including */ - /* phantom points. */ - /* */ - /* <InOut> */ - /* outline :: The outline to change. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Vary_Apply_Glyph_Deltas( TT_Face face, - FT_UInt glyph_index, - FT_Outline* outline, - FT_UInt n_points ) - { - FT_Stream stream = face->root.stream; - FT_Memory memory = stream->memory; - GX_Blend blend = face->blend; - - FT_Vector* points_org = NULL; - FT_Vector* points_out = NULL; - FT_Bool* has_delta = NULL; - - FT_Error error; - FT_ULong glyph_start; - FT_UInt tupleCount; - FT_ULong offsetToData; - FT_ULong here; - FT_UInt i, j; - FT_Fixed* tuple_coords = NULL; - FT_Fixed* im_start_coords = NULL; - FT_Fixed* im_end_coords = NULL; - FT_UInt point_count, spoint_count = 0; - FT_UShort* sharedpoints = NULL; - FT_UShort* localpoints = NULL; - FT_UShort* points; - FT_Short *deltas_x, *deltas_y; - - - if ( !face->doblend || !blend ) - return FT_THROW( Invalid_Argument ); - - if ( glyph_index >= blend->gv_glyphcnt || - blend->glyphoffsets[glyph_index] == - blend->glyphoffsets[glyph_index + 1] ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " no variation data for this glyph\n" )); - return FT_Err_Ok; - } - - if ( FT_NEW_ARRAY( points_org, n_points ) || - FT_NEW_ARRAY( points_out, n_points ) || - FT_NEW_ARRAY( has_delta, n_points ) ) - goto Fail1; - - if ( FT_STREAM_SEEK( blend->glyphoffsets[glyph_index] ) || - FT_FRAME_ENTER( blend->glyphoffsets[glyph_index + 1] - - blend->glyphoffsets[glyph_index] ) ) - goto Fail1; - - glyph_start = FT_Stream_FTell( stream ); - - /* each set of glyph variation data is formatted similarly to `cvar' */ - /* (except we get shared points and global tuples) */ - - if ( FT_NEW_ARRAY( tuple_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_start_coords, blend->num_axis ) || - FT_NEW_ARRAY( im_end_coords, blend->num_axis ) ) - goto Fail2; - - tupleCount = FT_GET_USHORT(); - offsetToData = FT_GET_USHORT(); - - /* rough sanity test */ - if ( offsetToData + ( tupleCount & GX_TC_TUPLE_COUNT_MASK ) * 4 > - blend->gvar_size ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " invalid glyph variation array header\n" )); - - error = FT_THROW( Invalid_Table ); - goto Fail2; - } - - offsetToData += glyph_start; - - if ( tupleCount & GX_TC_TUPLES_SHARE_POINT_NUMBERS ) - { - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - sharedpoints = ft_var_readpackedpoints( stream, - blend->gvar_size, - &spoint_count ); - offsetToData = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "gvar: there are %d tuples:\n", - tupleCount & GX_TC_TUPLE_COUNT_MASK )); - - for ( j = 0; j < n_points; j++ ) - points_org[j] = outline->points[j]; - - for ( i = 0; i < ( tupleCount & GX_TC_TUPLE_COUNT_MASK ); i++ ) - { - FT_UInt tupleDataSize; - FT_UInt tupleIndex; - FT_Fixed apply; - - - FT_TRACE6(( " tuple %d:\n", i )); - - tupleDataSize = FT_GET_USHORT(); - tupleIndex = FT_GET_USHORT(); - - if ( tupleIndex & GX_TI_EMBEDDED_TUPLE_COORD ) - { - for ( j = 0; j < blend->num_axis; j++ ) - tuple_coords[j] = FT_GET_SHORT() * 4; /* convert from */ - /* short frac to fixed */ - } - else if ( ( tupleIndex & GX_TI_TUPLE_INDEX_MASK ) >= blend->tuplecount ) - { - FT_TRACE2(( "TT_Vary_Apply_Glyph_Deltas:" - " invalid tuple index\n" )); - - error = FT_THROW( Invalid_Table ); - goto Fail2; - } - else - FT_MEM_COPY( - tuple_coords, - &blend->tuplecoords[( tupleIndex & 0xFFF ) * blend->num_axis], - blend->num_axis * sizeof ( FT_Fixed ) ); - - if ( tupleIndex & GX_TI_INTERMEDIATE_TUPLE ) - { - for ( j = 0; j < blend->num_axis; j++ ) - im_start_coords[j] = FT_GET_SHORT() * 4; - for ( j = 0; j < blend->num_axis; j++ ) - im_end_coords[j] = FT_GET_SHORT() * 4; - } - - apply = ft_var_apply_tuple( blend, - (FT_UShort)tupleIndex, - tuple_coords, - im_start_coords, - im_end_coords ); - - if ( apply == 0 ) /* tuple isn't active for our blend */ - { - offsetToData += tupleDataSize; - continue; - } - - here = FT_Stream_FTell( stream ); - - FT_Stream_SeekSet( stream, offsetToData ); - - if ( tupleIndex & GX_TI_PRIVATE_POINT_NUMBERS ) - { - localpoints = ft_var_readpackedpoints( stream, - blend->gvar_size, - &point_count ); - points = localpoints; - } - else - { - points = sharedpoints; - point_count = spoint_count; - } - - deltas_x = ft_var_readpackeddeltas( stream, - blend->gvar_size, - point_count == 0 ? n_points - : point_count ); - deltas_y = ft_var_readpackeddeltas( stream, - blend->gvar_size, - point_count == 0 ? n_points - : point_count ); - - if ( !points || !deltas_y || !deltas_x ) - ; /* failure, ignore it */ - - else if ( points == ALL_POINTS ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - FT_TRACE7(( " point deltas:\n" )); - - /* this means that there are deltas for every point in the glyph */ - for ( j = 0; j < n_points; j++ ) - { - FT_Pos delta_x = FT_MulFix( deltas_x[j], apply ); - FT_Pos delta_y = FT_MulFix( deltas_y[j], apply ); - - - if ( j < n_points - 3 ) - { - outline->points[j].x += delta_x; - outline->points[j].y += delta_y; - } - else - { - /* To avoid double adjustment of advance width or height, */ - /* adjust phantom points only if there is no HVAR or VVAR */ - /* support, respectively. */ - if ( j == ( n_points - 3 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_HADVANCE ) ) - outline->points[j].x += delta_x; - - else if ( j == ( n_points - 2 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_LSB ) ) - outline->points[j].x += delta_x; - - else if ( j == ( n_points - 1 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_VADVANCE ) ) - outline->points[j].y += delta_y; - - else if ( j == ( n_points - 0 ) && - !( face->variation_support & - TT_FACE_FLAG_VAR_TSB ) ) - outline->points[j].y += delta_y; - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( delta_x || delta_y ) - { - FT_TRACE7(( " %d: (%d, %d) -> (%d, %d)\n", - j, - outline->points[j].x - delta_x, - outline->points[j].y - delta_y, - outline->points[j].x, - outline->points[j].y )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - else - { -#ifdef FT_DEBUG_LEVEL_TRACE - int count = 0; -#endif - - - /* we have to interpolate the missing deltas similar to the */ - /* IUP bytecode instruction */ - for ( j = 0; j < n_points; j++ ) - { - has_delta[j] = FALSE; - points_out[j] = points_org[j]; - } - - for ( j = 0; j < point_count; j++ ) - { - FT_UShort idx = points[j]; - - - if ( idx >= n_points ) - continue; - - has_delta[idx] = TRUE; - - points_out[idx].x += FT_MulFix( deltas_x[j], apply ); - points_out[idx].y += FT_MulFix( deltas_y[j], apply ); - } - - /* no need to handle phantom points here, */ - /* since solitary points can't be interpolated */ - tt_interpolate_deltas( outline, - points_out, - points_org, - has_delta ); - - FT_TRACE7(( " point deltas:\n" )); - - for ( j = 0; j < n_points; j++ ) - { - FT_Pos delta_x = points_out[j].x - points_org[j].x; - FT_Pos delta_y = points_out[j].y - points_org[j].y; - - - outline->points[j].x += delta_x; - outline->points[j].y += delta_y; - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( delta_x || delta_y ) - { - FT_TRACE7(( " %d: (%d, %d) -> (%d, %d)\n", - j, - outline->points[j].x - delta_x, - outline->points[j].y - delta_y, - outline->points[j].x, - outline->points[j].y )); - count++; - } -#endif - } - -#ifdef FT_DEBUG_LEVEL_TRACE - if ( !count ) - FT_TRACE7(( " none\n" )); -#endif - } - - if ( localpoints != ALL_POINTS ) - FT_FREE( localpoints ); - FT_FREE( deltas_x ); - FT_FREE( deltas_y ); - - offsetToData += tupleDataSize; - - FT_Stream_SeekSet( stream, here ); - } - - FT_TRACE5(( "\n" )); - - Fail2: - if ( sharedpoints != ALL_POINTS ) - FT_FREE( sharedpoints ); - FT_FREE( tuple_coords ); - FT_FREE( im_start_coords ); - FT_FREE( im_end_coords ); - - FT_FRAME_EXIT(); - - Fail1: - FT_FREE( points_org ); - FT_FREE( points_out ); - FT_FREE( has_delta ); - - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_get_var_blend */ - /* */ - /* <Description> */ - /* An extended internal version of `TT_Get_MM_Blend' that returns */ - /* pointers instead of copying data, without any initialization of */ - /* the MM machinery in case it isn't loaded yet. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - tt_get_var_blend( TT_Face face, - FT_UInt *num_coords, - FT_Fixed* *coords, - FT_Fixed* *normalizedcoords, - FT_MM_Var* *mm_var ) - { - if ( face->blend ) - { - if ( num_coords ) - *num_coords = face->blend->num_axis; - if ( coords ) - *coords = face->blend->coords; - if ( normalizedcoords ) - *normalizedcoords = face->blend->normalizedcoords; - if ( mm_var ) - *mm_var = face->blend->mmvar; - } - else - { - if ( num_coords ) - *num_coords = 0; - if ( coords ) - *coords = NULL; - if ( mm_var ) - *mm_var = NULL; - } - - return FT_Err_Ok; - } - - - static void - ft_var_done_item_variation_store( TT_Face face, - GX_ItemVarStore itemStore ) - { - FT_Memory memory = FT_FACE_MEMORY( face ); - FT_UInt i; - - - if ( itemStore->varData ) - { - for ( i = 0; i < itemStore->dataCount; i++ ) - { - FT_FREE( itemStore->varData[i].regionIndices ); - FT_FREE( itemStore->varData[i].deltaSet ); - } - - FT_FREE( itemStore->varData ); - } - - if ( itemStore->varRegionList ) - { - for ( i = 0; i < itemStore->regionCount; i++ ) - FT_FREE( itemStore->varRegionList[i].axisList ); - - FT_FREE( itemStore->varRegionList ); - } - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* tt_done_blend */ - /* */ - /* <Description> */ - /* Free the blend internal data structure. */ - /* */ - FT_LOCAL_DEF( void ) - tt_done_blend( TT_Face face ) - { - FT_Memory memory = FT_FACE_MEMORY( face ); - GX_Blend blend = face->blend; - - - if ( blend ) - { - FT_UInt i, num_axes; - - - /* blend->num_axis might not be set up yet */ - num_axes = blend->mmvar->num_axis; - - FT_FREE( blend->coords ); - FT_FREE( blend->normalizedcoords ); - FT_FREE( blend->normalized_stylecoords ); - FT_FREE( blend->mmvar ); - - if ( blend->avar_segment ) - { - for ( i = 0; i < num_axes; i++ ) - FT_FREE( blend->avar_segment[i].correspondence ); - FT_FREE( blend->avar_segment ); - } - - if ( blend->hvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->hvar_table->itemStore ); - - FT_FREE( blend->hvar_table->widthMap.innerIndex ); - FT_FREE( blend->hvar_table->widthMap.outerIndex ); - FT_FREE( blend->hvar_table ); - } - - if ( blend->vvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->vvar_table->itemStore ); - - FT_FREE( blend->vvar_table->widthMap.innerIndex ); - FT_FREE( blend->vvar_table->widthMap.outerIndex ); - FT_FREE( blend->vvar_table ); - } - - if ( blend->mvar_table ) - { - ft_var_done_item_variation_store( face, - &blend->mvar_table->itemStore ); - - FT_FREE( blend->mvar_table->values ); - FT_FREE( blend->mvar_table ); - } - - FT_FREE( blend->tuplecoords ); - FT_FREE( blend->glyphoffsets ); - FT_FREE( blend ); - } - } - -#else /* !TT_CONFIG_OPTION_GX_VAR_SUPPORT */ - - /* ANSI C doesn't like empty source files */ - typedef int _tt_gxvar_dummy; - -#endif /* !TT_CONFIG_OPTION_GX_VAR_SUPPORT */ - - -/* END */ diff --git a/src/truetype/ttinterp.c b/src/truetype/ttinterp.c index 8a24831..af31408 100644 --- a/src/truetype/ttinterp.c +++ b/src/truetype/ttinterp.c @@ -7639,7 +7639,8 @@ FT_MAX( 50, exc->cvtSize / 10 ); else - exc->loopcall_counter_max = 300 + 8 * exc->cvtSize; + exc->loopcall_counter_max = FT_MAX( 100, + 10 * exc->cvtSize ); /* as a protection against an unreasonable number of CVT entries */ /* we assume at most 100 control values per glyph for the counter */ diff --git a/src/truetype/ttinterp.c.loop-counter b/src/truetype/ttinterp.c.loop-counter deleted file mode 100644 index af31408..0000000 --- a/src/truetype/ttinterp.c.loop-counter +++ /dev/null @@ -1,8439 +0,0 @@ -/***************************************************************************/ -/* */ -/* ttinterp.c */ -/* */ -/* TrueType bytecode interpreter (body). */ -/* */ -/* Copyright 1996-2017 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. */ -/* */ -/***************************************************************************/ - - -/* Greg Hitchcock from Microsoft has helped a lot in resolving unclear */ -/* issues; many thanks! */ - - -#include <ft2build.h> -#include FT_INTERNAL_DEBUG_H -#include FT_INTERNAL_CALC_H -#include FT_TRIGONOMETRY_H -#include FT_SYSTEM_H -#include FT_TRUETYPE_DRIVER_H -#include FT_MULTIPLE_MASTERS_H - -#include "ttinterp.h" -#include "tterrors.h" -#include "ttsubpix.h" -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT -#include "ttgxvar.h" -#endif - - -#ifdef TT_USE_BYTECODE_INTERPRETER - - - /*************************************************************************/ - /* */ - /* 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_ttinterp - - -#define NO_SUBPIXEL_HINTING \ - ( ((TT_Driver)FT_FACE_DRIVER( exc->face ))->interpreter_version == \ - TT_INTERPRETER_VERSION_35 ) - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY -#define SUBPIXEL_HINTING_INFINALITY \ - ( ((TT_Driver)FT_FACE_DRIVER( exc->face ))->interpreter_version == \ - TT_INTERPRETER_VERSION_38 ) -#endif - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL -#define SUBPIXEL_HINTING_MINIMAL \ - ( ((TT_Driver)FT_FACE_DRIVER( exc->face ))->interpreter_version == \ - TT_INTERPRETER_VERSION_40 ) -#endif - -#define PROJECT( v1, v2 ) \ - exc->func_project( exc, (v1)->x - (v2)->x, (v1)->y - (v2)->y ) - -#define DUALPROJ( v1, v2 ) \ - exc->func_dualproj( exc, (v1)->x - (v2)->x, (v1)->y - (v2)->y ) - -#define FAST_PROJECT( v ) \ - exc->func_project( exc, (v)->x, (v)->y ) - -#define FAST_DUALPROJ( v ) \ - exc->func_dualproj( exc, (v)->x, (v)->y ) - - - /*************************************************************************/ - /* */ - /* Two simple bounds-checking macros. */ - /* */ -#define BOUNDS( x, n ) ( (FT_UInt)(x) >= (FT_UInt)(n) ) -#define BOUNDSL( x, n ) ( (FT_ULong)(x) >= (FT_ULong)(n) ) - - -#undef SUCCESS -#define SUCCESS 0 - -#undef FAILURE -#define FAILURE 1 - - - /*************************************************************************/ - /* */ - /* CODERANGE FUNCTIONS */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Goto_CodeRange */ - /* */ - /* <Description> */ - /* Switches to a new code range (updates the code related elements in */ - /* `exec', and `IP'). */ - /* */ - /* <Input> */ - /* range :: The new execution code range. */ - /* */ - /* IP :: The new IP in the new code range. */ - /* */ - /* <InOut> */ - /* exec :: The target execution context. */ - /* */ - FT_LOCAL_DEF( void ) - TT_Goto_CodeRange( TT_ExecContext exec, - FT_Int range, - FT_Long IP ) - { - TT_CodeRange* coderange; - - - FT_ASSERT( range >= 1 && range <= 3 ); - - coderange = &exec->codeRangeTable[range - 1]; - - FT_ASSERT( coderange->base ); - - /* NOTE: Because the last instruction of a program may be a CALL */ - /* which will return to the first byte *after* the code */ - /* range, we test for IP <= Size instead of IP < Size. */ - /* */ - FT_ASSERT( IP <= coderange->size ); - - exec->code = coderange->base; - exec->codeSize = coderange->size; - exec->IP = IP; - exec->curRange = range; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Set_CodeRange */ - /* */ - /* <Description> */ - /* Sets a code range. */ - /* */ - /* <Input> */ - /* range :: The code range index. */ - /* */ - /* base :: The new code base. */ - /* */ - /* length :: The range size in bytes. */ - /* */ - /* <InOut> */ - /* exec :: The target execution context. */ - /* */ - FT_LOCAL_DEF( void ) - TT_Set_CodeRange( TT_ExecContext exec, - FT_Int range, - void* base, - FT_Long length ) - { - FT_ASSERT( range >= 1 && range <= 3 ); - - exec->codeRangeTable[range - 1].base = (FT_Byte*)base; - exec->codeRangeTable[range - 1].size = length; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Clear_CodeRange */ - /* */ - /* <Description> */ - /* Clears a code range. */ - /* */ - /* <Input> */ - /* range :: The code range index. */ - /* */ - /* <InOut> */ - /* exec :: The target execution context. */ - /* */ - FT_LOCAL_DEF( void ) - TT_Clear_CodeRange( TT_ExecContext exec, - FT_Int range ) - { - FT_ASSERT( range >= 1 && range <= 3 ); - - exec->codeRangeTable[range - 1].base = NULL; - exec->codeRangeTable[range - 1].size = 0; - } - - - /*************************************************************************/ - /* */ - /* EXECUTION CONTEXT ROUTINES */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Done_Context */ - /* */ - /* <Description> */ - /* Destroys a given context. */ - /* */ - /* <Input> */ - /* exec :: A handle to the target execution context. */ - /* */ - /* memory :: A handle to the parent memory object. */ - /* */ - /* <Note> */ - /* Only the glyph loader and debugger should call this function. */ - /* */ - FT_LOCAL_DEF( void ) - TT_Done_Context( TT_ExecContext exec ) - { - FT_Memory memory = exec->memory; - - - /* points zone */ - exec->maxPoints = 0; - exec->maxContours = 0; - - /* free stack */ - FT_FREE( exec->stack ); - exec->stackSize = 0; - - /* free call stack */ - FT_FREE( exec->callStack ); - exec->callSize = 0; - exec->callTop = 0; - - /* free glyph code range */ - FT_FREE( exec->glyphIns ); - exec->glyphSize = 0; - - exec->size = NULL; - exec->face = NULL; - - FT_FREE( exec ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Init_Context */ - /* */ - /* <Description> */ - /* Initializes a context object. */ - /* */ - /* <Input> */ - /* memory :: A handle to the parent memory object. */ - /* */ - /* <InOut> */ - /* exec :: A handle to the target execution context. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - static FT_Error - Init_Context( TT_ExecContext exec, - FT_Memory memory ) - { - FT_Error error; - - - FT_TRACE1(( "Init_Context: new object at 0x%08p\n", exec )); - - exec->memory = memory; - exec->callSize = 32; - - if ( FT_NEW_ARRAY( exec->callStack, exec->callSize ) ) - goto Fail_Memory; - - /* all values in the context are set to 0 already, but this is */ - /* here as a remainder */ - exec->maxPoints = 0; - exec->maxContours = 0; - - exec->stackSize = 0; - exec->glyphSize = 0; - - exec->stack = NULL; - exec->glyphIns = NULL; - - exec->face = NULL; - exec->size = NULL; - - return FT_Err_Ok; - - Fail_Memory: - FT_ERROR(( "Init_Context: not enough memory for %p\n", exec )); - TT_Done_Context( exec ); - - return error; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Update_Max */ - /* */ - /* <Description> */ - /* Checks the size of a buffer and reallocates it if necessary. */ - /* */ - /* <Input> */ - /* memory :: A handle to the parent memory object. */ - /* */ - /* multiplier :: The size in bytes of each element in the buffer. */ - /* */ - /* new_max :: The new capacity (size) of the buffer. */ - /* */ - /* <InOut> */ - /* size :: The address of the buffer's current size expressed */ - /* in elements. */ - /* */ - /* buff :: The address of the buffer base pointer. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - Update_Max( FT_Memory memory, - FT_ULong* size, - FT_ULong multiplier, - void* _pbuff, - FT_ULong new_max ) - { - FT_Error error; - void** pbuff = (void**)_pbuff; - - - if ( *size < new_max ) - { - if ( FT_REALLOC( *pbuff, *size * multiplier, new_max * multiplier ) ) - return error; - *size = new_max; - } - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Load_Context */ - /* */ - /* <Description> */ - /* Prepare an execution context for glyph hinting. */ - /* */ - /* <Input> */ - /* face :: A handle to the source face object. */ - /* */ - /* size :: A handle to the source size object. */ - /* */ - /* <InOut> */ - /* exec :: A handle to the target execution context. */ - /* */ - /* <Return> */ - /* FreeType error code. 0 means success. */ - /* */ - /* <Note> */ - /* Only the glyph loader and debugger should call this function. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Load_Context( TT_ExecContext exec, - TT_Face face, - TT_Size size ) - { - FT_Int i; - FT_ULong tmp; - TT_MaxProfile* maxp; - FT_Error error; - - - exec->face = face; - maxp = &face->max_profile; - exec->size = size; - - if ( size ) - { - exec->numFDefs = size->num_function_defs; - exec->maxFDefs = size->max_function_defs; - exec->numIDefs = size->num_instruction_defs; - exec->maxIDefs = size->max_instruction_defs; - exec->FDefs = size->function_defs; - exec->IDefs = size->instruction_defs; - exec->pointSize = size->point_size; - exec->tt_metrics = size->ttmetrics; - exec->metrics = *size->metrics; - - exec->maxFunc = size->max_func; - exec->maxIns = size->max_ins; - - for ( i = 0; i < TT_MAX_CODE_RANGES; i++ ) - exec->codeRangeTable[i] = size->codeRangeTable[i]; - - /* set graphics state */ - exec->GS = size->GS; - - exec->cvtSize = size->cvt_size; - exec->cvt = size->cvt; - - exec->storeSize = size->storage_size; - exec->storage = size->storage; - - exec->twilight = size->twilight; - - /* In case of multi-threading it can happen that the old size object */ - /* no longer exists, thus we must clear all glyph zone references. */ - FT_ZERO( &exec->zp0 ); - exec->zp1 = exec->zp0; - exec->zp2 = exec->zp0; - } - - /* XXX: We reserve a little more elements on the stack to deal safely */ - /* with broken fonts like arialbs, courbs, timesbs, etc. */ - tmp = (FT_ULong)exec->stackSize; - error = Update_Max( exec->memory, - &tmp, - sizeof ( FT_F26Dot6 ), - (void*)&exec->stack, - maxp->maxStackElements + 32 ); - exec->stackSize = (FT_Long)tmp; - if ( error ) - return error; - - tmp = exec->glyphSize; - error = Update_Max( exec->memory, - &tmp, - sizeof ( FT_Byte ), - (void*)&exec->glyphIns, - maxp->maxSizeOfInstructions ); - exec->glyphSize = (FT_UShort)tmp; - if ( error ) - return error; - - exec->pts.n_points = 0; - exec->pts.n_contours = 0; - - exec->zp1 = exec->pts; - exec->zp2 = exec->pts; - exec->zp0 = exec->pts; - - exec->instruction_trap = FALSE; - - return FT_Err_Ok; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Save_Context */ - /* */ - /* <Description> */ - /* Saves the code ranges in a `size' object. */ - /* */ - /* <Input> */ - /* exec :: A handle to the source execution context. */ - /* */ - /* <InOut> */ - /* size :: A handle to the target size object. */ - /* */ - /* <Note> */ - /* Only the glyph loader and debugger should call this function. */ - /* */ - FT_LOCAL_DEF( void ) - TT_Save_Context( TT_ExecContext exec, - TT_Size size ) - { - FT_Int i; - - - /* XXX: Will probably disappear soon with all the code range */ - /* management, which is now rather obsolete. */ - /* */ - size->num_function_defs = exec->numFDefs; - size->num_instruction_defs = exec->numIDefs; - - size->max_func = exec->maxFunc; - size->max_ins = exec->maxIns; - - for ( i = 0; i < TT_MAX_CODE_RANGES; i++ ) - size->codeRangeTable[i] = exec->codeRangeTable[i]; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* TT_Run_Context */ - /* */ - /* <Description> */ - /* Executes one or more instructions in the execution context. */ - /* */ - /* <Input> */ - /* debug :: A Boolean flag. If set, the function sets some internal */ - /* variables and returns immediately, otherwise TT_RunIns() */ - /* is called. */ - /* */ - /* This is commented out currently. */ - /* */ - /* <Input> */ - /* exec :: A handle to the target execution context. */ - /* */ - /* <Return> */ - /* TrueType error code. 0 means success. */ - /* */ - FT_LOCAL_DEF( FT_Error ) - TT_Run_Context( TT_ExecContext exec ) - { - TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ); - - exec->zp0 = exec->pts; - exec->zp1 = exec->pts; - exec->zp2 = exec->pts; - - exec->GS.gep0 = 1; - exec->GS.gep1 = 1; - exec->GS.gep2 = 1; - - exec->GS.projVector.x = 0x4000; - exec->GS.projVector.y = 0x0000; - - exec->GS.freeVector = exec->GS.projVector; - exec->GS.dualVector = exec->GS.projVector; - - exec->GS.round_state = 1; - exec->GS.loop = 1; - - /* some glyphs leave something on the stack. so we clean it */ - /* before a new execution. */ - exec->top = 0; - exec->callTop = 0; - - return exec->face->interpreter( exec ); - } - - - /* The default value for `scan_control' is documented as FALSE in the */ - /* TrueType specification. This is confusing since it implies a */ - /* Boolean value. However, this is not the case, thus both the */ - /* default values of our `scan_type' and `scan_control' fields (which */ - /* the documentation's `scan_control' variable is split into) are */ - /* zero. */ - - const TT_GraphicsState tt_default_graphics_state = - { - 0, 0, 0, - { 0x4000, 0 }, - { 0x4000, 0 }, - { 0x4000, 0 }, - - 1, 64, 1, - TRUE, 68, 0, 0, 9, 3, - 0, FALSE, 0, 1, 1, 1 - }; - - - /* documentation is in ttinterp.h */ - - FT_EXPORT_DEF( TT_ExecContext ) - TT_New_Context( TT_Driver driver ) - { - FT_Memory memory; - FT_Error error; - - TT_ExecContext exec = NULL; - - - if ( !driver ) - goto Fail; - - memory = driver->root.root.memory; - - /* allocate object */ - if ( FT_NEW( exec ) ) - goto Fail; - - /* initialize it; in case of error this deallocates `exec' too */ - error = Init_Context( exec, memory ); - if ( error ) - goto Fail; - - return exec; - - Fail: - return NULL; - } - - - /*************************************************************************/ - /* */ - /* Before an opcode is executed, the interpreter verifies that there are */ - /* enough arguments on the stack, with the help of the `Pop_Push_Count' */ - /* table. */ - /* */ - /* For each opcode, the first column gives the number of arguments that */ - /* are popped from the stack; the second one gives the number of those */ - /* that are pushed in result. */ - /* */ - /* Opcodes which have a varying number of parameters in the data stream */ - /* (NPUSHB, NPUSHW) are handled specially; they have a negative value in */ - /* the `opcode_length' table, and the value in `Pop_Push_Count' is set */ - /* to zero. */ - /* */ - /*************************************************************************/ - - -#undef PACK -#define PACK( x, y ) ( ( x << 4 ) | y ) - - - static - const FT_Byte Pop_Push_Count[256] = - { - /* opcodes are gathered in groups of 16 */ - /* please keep the spaces as they are */ - - /* SVTCA y */ PACK( 0, 0 ), - /* SVTCA x */ PACK( 0, 0 ), - /* SPvTCA y */ PACK( 0, 0 ), - /* SPvTCA x */ PACK( 0, 0 ), - /* SFvTCA y */ PACK( 0, 0 ), - /* SFvTCA x */ PACK( 0, 0 ), - /* SPvTL // */ PACK( 2, 0 ), - /* SPvTL + */ PACK( 2, 0 ), - /* SFvTL // */ PACK( 2, 0 ), - /* SFvTL + */ PACK( 2, 0 ), - /* SPvFS */ PACK( 2, 0 ), - /* SFvFS */ PACK( 2, 0 ), - /* GPv */ PACK( 0, 2 ), - /* GFv */ PACK( 0, 2 ), - /* SFvTPv */ PACK( 0, 0 ), - /* ISECT */ PACK( 5, 0 ), - - /* SRP0 */ PACK( 1, 0 ), - /* SRP1 */ PACK( 1, 0 ), - /* SRP2 */ PACK( 1, 0 ), - /* SZP0 */ PACK( 1, 0 ), - /* SZP1 */ PACK( 1, 0 ), - /* SZP2 */ PACK( 1, 0 ), - /* SZPS */ PACK( 1, 0 ), - /* SLOOP */ PACK( 1, 0 ), - /* RTG */ PACK( 0, 0 ), - /* RTHG */ PACK( 0, 0 ), - /* SMD */ PACK( 1, 0 ), - /* ELSE */ PACK( 0, 0 ), - /* JMPR */ PACK( 1, 0 ), - /* SCvTCi */ PACK( 1, 0 ), - /* SSwCi */ PACK( 1, 0 ), - /* SSW */ PACK( 1, 0 ), - - /* DUP */ PACK( 1, 2 ), - /* POP */ PACK( 1, 0 ), - /* CLEAR */ PACK( 0, 0 ), - /* SWAP */ PACK( 2, 2 ), - /* DEPTH */ PACK( 0, 1 ), - /* CINDEX */ PACK( 1, 1 ), - /* MINDEX */ PACK( 1, 0 ), - /* AlignPTS */ PACK( 2, 0 ), - /* INS_$28 */ PACK( 0, 0 ), - /* UTP */ PACK( 1, 0 ), - /* LOOPCALL */ PACK( 2, 0 ), - /* CALL */ PACK( 1, 0 ), - /* FDEF */ PACK( 1, 0 ), - /* ENDF */ PACK( 0, 0 ), - /* MDAP[0] */ PACK( 1, 0 ), - /* MDAP[1] */ PACK( 1, 0 ), - - /* IUP[0] */ PACK( 0, 0 ), - /* IUP[1] */ PACK( 0, 0 ), - /* SHP[0] */ PACK( 0, 0 ), /* loops */ - /* SHP[1] */ PACK( 0, 0 ), /* loops */ - /* SHC[0] */ PACK( 1, 0 ), - /* SHC[1] */ PACK( 1, 0 ), - /* SHZ[0] */ PACK( 1, 0 ), - /* SHZ[1] */ PACK( 1, 0 ), - /* SHPIX */ PACK( 1, 0 ), /* loops */ - /* IP */ PACK( 0, 0 ), /* loops */ - /* MSIRP[0] */ PACK( 2, 0 ), - /* MSIRP[1] */ PACK( 2, 0 ), - /* AlignRP */ PACK( 0, 0 ), /* loops */ - /* RTDG */ PACK( 0, 0 ), - /* MIAP[0] */ PACK( 2, 0 ), - /* MIAP[1] */ PACK( 2, 0 ), - - /* NPushB */ PACK( 0, 0 ), - /* NPushW */ PACK( 0, 0 ), - /* WS */ PACK( 2, 0 ), - /* RS */ PACK( 1, 1 ), - /* WCvtP */ PACK( 2, 0 ), - /* RCvt */ PACK( 1, 1 ), - /* GC[0] */ PACK( 1, 1 ), - /* GC[1] */ PACK( 1, 1 ), - /* SCFS */ PACK( 2, 0 ), - /* MD[0] */ PACK( 2, 1 ), - /* MD[1] */ PACK( 2, 1 ), - /* MPPEM */ PACK( 0, 1 ), - /* MPS */ PACK( 0, 1 ), - /* FlipON */ PACK( 0, 0 ), - /* FlipOFF */ PACK( 0, 0 ), - /* DEBUG */ PACK( 1, 0 ), - - /* LT */ PACK( 2, 1 ), - /* LTEQ */ PACK( 2, 1 ), - /* GT */ PACK( 2, 1 ), - /* GTEQ */ PACK( 2, 1 ), - /* EQ */ PACK( 2, 1 ), - /* NEQ */ PACK( 2, 1 ), - /* ODD */ PACK( 1, 1 ), - /* EVEN */ PACK( 1, 1 ), - /* IF */ PACK( 1, 0 ), - /* EIF */ PACK( 0, 0 ), - /* AND */ PACK( 2, 1 ), - /* OR */ PACK( 2, 1 ), - /* NOT */ PACK( 1, 1 ), - /* DeltaP1 */ PACK( 1, 0 ), - /* SDB */ PACK( 1, 0 ), - /* SDS */ PACK( 1, 0 ), - - /* ADD */ PACK( 2, 1 ), - /* SUB */ PACK( 2, 1 ), - /* DIV */ PACK( 2, 1 ), - /* MUL */ PACK( 2, 1 ), - /* ABS */ PACK( 1, 1 ), - /* NEG */ PACK( 1, 1 ), - /* FLOOR */ PACK( 1, 1 ), - /* CEILING */ PACK( 1, 1 ), - /* ROUND[0] */ PACK( 1, 1 ), - /* ROUND[1] */ PACK( 1, 1 ), - /* ROUND[2] */ PACK( 1, 1 ), - /* ROUND[3] */ PACK( 1, 1 ), - /* NROUND[0] */ PACK( 1, 1 ), - /* NROUND[1] */ PACK( 1, 1 ), - /* NROUND[2] */ PACK( 1, 1 ), - /* NROUND[3] */ PACK( 1, 1 ), - - /* WCvtF */ PACK( 2, 0 ), - /* DeltaP2 */ PACK( 1, 0 ), - /* DeltaP3 */ PACK( 1, 0 ), - /* DeltaCn[0] */ PACK( 1, 0 ), - /* DeltaCn[1] */ PACK( 1, 0 ), - /* DeltaCn[2] */ PACK( 1, 0 ), - /* SROUND */ PACK( 1, 0 ), - /* S45Round */ PACK( 1, 0 ), - /* JROT */ PACK( 2, 0 ), - /* JROF */ PACK( 2, 0 ), - /* ROFF */ PACK( 0, 0 ), - /* INS_$7B */ PACK( 0, 0 ), - /* RUTG */ PACK( 0, 0 ), - /* RDTG */ PACK( 0, 0 ), - /* SANGW */ PACK( 1, 0 ), - /* AA */ PACK( 1, 0 ), - - /* FlipPT */ PACK( 0, 0 ), /* loops */ - /* FlipRgON */ PACK( 2, 0 ), - /* FlipRgOFF */ PACK( 2, 0 ), - /* INS_$83 */ PACK( 0, 0 ), - /* INS_$84 */ PACK( 0, 0 ), - /* ScanCTRL */ PACK( 1, 0 ), - /* SDPvTL[0] */ PACK( 2, 0 ), - /* SDPvTL[1] */ PACK( 2, 0 ), - /* GetINFO */ PACK( 1, 1 ), - /* IDEF */ PACK( 1, 0 ), - /* ROLL */ PACK( 3, 3 ), - /* MAX */ PACK( 2, 1 ), - /* MIN */ PACK( 2, 1 ), - /* ScanTYPE */ PACK( 1, 0 ), - /* InstCTRL */ PACK( 2, 0 ), - /* INS_$8F */ PACK( 0, 0 ), - - /* INS_$90 */ PACK( 0, 0 ), - /* GETVAR */ PACK( 0, 0 ), /* will be handled specially */ - /* GETDATA */ PACK( 0, 1 ), - /* INS_$93 */ PACK( 0, 0 ), - /* INS_$94 */ PACK( 0, 0 ), - /* INS_$95 */ PACK( 0, 0 ), - /* INS_$96 */ PACK( 0, 0 ), - /* INS_$97 */ PACK( 0, 0 ), - /* INS_$98 */ PACK( 0, 0 ), - /* INS_$99 */ PACK( 0, 0 ), - /* INS_$9A */ PACK( 0, 0 ), - /* INS_$9B */ PACK( 0, 0 ), - /* INS_$9C */ PACK( 0, 0 ), - /* INS_$9D */ PACK( 0, 0 ), - /* INS_$9E */ PACK( 0, 0 ), - /* INS_$9F */ PACK( 0, 0 ), - - /* INS_$A0 */ PACK( 0, 0 ), - /* INS_$A1 */ PACK( 0, 0 ), - /* INS_$A2 */ PACK( 0, 0 ), - /* INS_$A3 */ PACK( 0, 0 ), - /* INS_$A4 */ PACK( 0, 0 ), - /* INS_$A5 */ PACK( 0, 0 ), - /* INS_$A6 */ PACK( 0, 0 ), - /* INS_$A7 */ PACK( 0, 0 ), - /* INS_$A8 */ PACK( 0, 0 ), - /* INS_$A9 */ PACK( 0, 0 ), - /* INS_$AA */ PACK( 0, 0 ), - /* INS_$AB */ PACK( 0, 0 ), - /* INS_$AC */ PACK( 0, 0 ), - /* INS_$AD */ PACK( 0, 0 ), - /* INS_$AE */ PACK( 0, 0 ), - /* INS_$AF */ PACK( 0, 0 ), - - /* PushB[0] */ PACK( 0, 1 ), - /* PushB[1] */ PACK( 0, 2 ), - /* PushB[2] */ PACK( 0, 3 ), - /* PushB[3] */ PACK( 0, 4 ), - /* PushB[4] */ PACK( 0, 5 ), - /* PushB[5] */ PACK( 0, 6 ), - /* PushB[6] */ PACK( 0, 7 ), - /* PushB[7] */ PACK( 0, 8 ), - /* PushW[0] */ PACK( 0, 1 ), - /* PushW[1] */ PACK( 0, 2 ), - /* PushW[2] */ PACK( 0, 3 ), - /* PushW[3] */ PACK( 0, 4 ), - /* PushW[4] */ PACK( 0, 5 ), - /* PushW[5] */ PACK( 0, 6 ), - /* PushW[6] */ PACK( 0, 7 ), - /* PushW[7] */ PACK( 0, 8 ), - - /* MDRP[00] */ PACK( 1, 0 ), - /* MDRP[01] */ PACK( 1, 0 ), - /* MDRP[02] */ PACK( 1, 0 ), - /* MDRP[03] */ PACK( 1, 0 ), - /* MDRP[04] */ PACK( 1, 0 ), - /* MDRP[05] */ PACK( 1, 0 ), - /* MDRP[06] */ PACK( 1, 0 ), - /* MDRP[07] */ PACK( 1, 0 ), - /* MDRP[08] */ PACK( 1, 0 ), - /* MDRP[09] */ PACK( 1, 0 ), - /* MDRP[10] */ PACK( 1, 0 ), - /* MDRP[11] */ PACK( 1, 0 ), - /* MDRP[12] */ PACK( 1, 0 ), - /* MDRP[13] */ PACK( 1, 0 ), - /* MDRP[14] */ PACK( 1, 0 ), - /* MDRP[15] */ PACK( 1, 0 ), - - /* MDRP[16] */ PACK( 1, 0 ), - /* MDRP[17] */ PACK( 1, 0 ), - /* MDRP[18] */ PACK( 1, 0 ), - /* MDRP[19] */ PACK( 1, 0 ), - /* MDRP[20] */ PACK( 1, 0 ), - /* MDRP[21] */ PACK( 1, 0 ), - /* MDRP[22] */ PACK( 1, 0 ), - /* MDRP[23] */ PACK( 1, 0 ), - /* MDRP[24] */ PACK( 1, 0 ), - /* MDRP[25] */ PACK( 1, 0 ), - /* MDRP[26] */ PACK( 1, 0 ), - /* MDRP[27] */ PACK( 1, 0 ), - /* MDRP[28] */ PACK( 1, 0 ), - /* MDRP[29] */ PACK( 1, 0 ), - /* MDRP[30] */ PACK( 1, 0 ), - /* MDRP[31] */ PACK( 1, 0 ), - - /* MIRP[00] */ PACK( 2, 0 ), - /* MIRP[01] */ PACK( 2, 0 ), - /* MIRP[02] */ PACK( 2, 0 ), - /* MIRP[03] */ PACK( 2, 0 ), - /* MIRP[04] */ PACK( 2, 0 ), - /* MIRP[05] */ PACK( 2, 0 ), - /* MIRP[06] */ PACK( 2, 0 ), - /* MIRP[07] */ PACK( 2, 0 ), - /* MIRP[08] */ PACK( 2, 0 ), - /* MIRP[09] */ PACK( 2, 0 ), - /* MIRP[10] */ PACK( 2, 0 ), - /* MIRP[11] */ PACK( 2, 0 ), - /* MIRP[12] */ PACK( 2, 0 ), - /* MIRP[13] */ PACK( 2, 0 ), - /* MIRP[14] */ PACK( 2, 0 ), - /* MIRP[15] */ PACK( 2, 0 ), - - /* MIRP[16] */ PACK( 2, 0 ), - /* MIRP[17] */ PACK( 2, 0 ), - /* MIRP[18] */ PACK( 2, 0 ), - /* MIRP[19] */ PACK( 2, 0 ), - /* MIRP[20] */ PACK( 2, 0 ), - /* MIRP[21] */ PACK( 2, 0 ), - /* MIRP[22] */ PACK( 2, 0 ), - /* MIRP[23] */ PACK( 2, 0 ), - /* MIRP[24] */ PACK( 2, 0 ), - /* MIRP[25] */ PACK( 2, 0 ), - /* MIRP[26] */ PACK( 2, 0 ), - /* MIRP[27] */ PACK( 2, 0 ), - /* MIRP[28] */ PACK( 2, 0 ), - /* MIRP[29] */ PACK( 2, 0 ), - /* MIRP[30] */ PACK( 2, 0 ), - /* MIRP[31] */ PACK( 2, 0 ) - }; - - -#ifdef FT_DEBUG_LEVEL_TRACE - - /* the first hex digit gives the length of the opcode name; the space */ - /* after the digit is here just to increase readability of the source */ - /* code */ - - static - const char* const opcode_name[256] = - { - "7 SVTCA y", - "7 SVTCA x", - "8 SPvTCA y", - "8 SPvTCA x", - "8 SFvTCA y", - "8 SFvTCA x", - "8 SPvTL ||", - "7 SPvTL +", - "8 SFvTL ||", - "7 SFvTL +", - "5 SPvFS", - "5 SFvFS", - "3 GPv", - "3 GFv", - "6 SFvTPv", - "5 ISECT", - - "4 SRP0", - "4 SRP1", - "4 SRP2", - "4 SZP0", - "4 SZP1", - "4 SZP2", - "4 SZPS", - "5 SLOOP", - "3 RTG", - "4 RTHG", - "3 SMD", - "4 ELSE", - "4 JMPR", - "6 SCvTCi", - "5 SSwCi", - "3 SSW", - - "3 DUP", - "3 POP", - "5 CLEAR", - "4 SWAP", - "5 DEPTH", - "6 CINDEX", - "6 MINDEX", - "8 AlignPTS", - "7 INS_$28", - "3 UTP", - "8 LOOPCALL", - "4 CALL", - "4 FDEF", - "4 ENDF", - "7 MDAP[0]", - "7 MDAP[1]", - - "6 IUP[0]", - "6 IUP[1]", - "6 SHP[0]", - "6 SHP[1]", - "6 SHC[0]", - "6 SHC[1]", - "6 SHZ[0]", - "6 SHZ[1]", - "5 SHPIX", - "2 IP", - "8 MSIRP[0]", - "8 MSIRP[1]", - "7 AlignRP", - "4 RTDG", - "7 MIAP[0]", - "7 MIAP[1]", - - "6 NPushB", - "6 NPushW", - "2 WS", - "2 RS", - "5 WCvtP", - "4 RCvt", - "5 GC[0]", - "5 GC[1]", - "4 SCFS", - "5 MD[0]", - "5 MD[1]", - "5 MPPEM", - "3 MPS", - "6 FlipON", - "7 FlipOFF", - "5 DEBUG", - - "2 LT", - "4 LTEQ", - "2 GT", - "4 GTEQ", - "2 EQ", - "3 NEQ", - "3 ODD", - "4 EVEN", - "2 IF", - "3 EIF", - "3 AND", - "2 OR", - "3 NOT", - "7 DeltaP1", - "3 SDB", - "3 SDS", - - "3 ADD", - "3 SUB", - "3 DIV", - "3 MUL", - "3 ABS", - "3 NEG", - "5 FLOOR", - "7 CEILING", - "8 ROUND[0]", - "8 ROUND[1]", - "8 ROUND[2]", - "8 ROUND[3]", - "9 NROUND[0]", - "9 NROUND[1]", - "9 NROUND[2]", - "9 NROUND[3]", - - "5 WCvtF", - "7 DeltaP2", - "7 DeltaP3", - "A DeltaCn[0]", - "A DeltaCn[1]", - "A DeltaCn[2]", - "6 SROUND", - "8 S45Round", - "4 JROT", - "4 JROF", - "4 ROFF", - "7 INS_$7B", - "4 RUTG", - "4 RDTG", - "5 SANGW", - "2 AA", - - "6 FlipPT", - "8 FlipRgON", - "9 FlipRgOFF", - "7 INS_$83", - "7 INS_$84", - "8 ScanCTRL", - "9 SDPvTL[0]", - "9 SDPvTL[1]", - "7 GetINFO", - "4 IDEF", - "4 ROLL", - "3 MAX", - "3 MIN", - "8 ScanTYPE", - "8 InstCTRL", - "7 INS_$8F", - - "7 INS_$90", -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - "6 GETVAR", - "7 GETDATA", -#else - "7 INS_$91", - "7 INS_$92", -#endif - "7 INS_$93", - "7 INS_$94", - "7 INS_$95", - "7 INS_$96", - "7 INS_$97", - "7 INS_$98", - "7 INS_$99", - "7 INS_$9A", - "7 INS_$9B", - "7 INS_$9C", - "7 INS_$9D", - "7 INS_$9E", - "7 INS_$9F", - - "7 INS_$A0", - "7 INS_$A1", - "7 INS_$A2", - "7 INS_$A3", - "7 INS_$A4", - "7 INS_$A5", - "7 INS_$A6", - "7 INS_$A7", - "7 INS_$A8", - "7 INS_$A9", - "7 INS_$AA", - "7 INS_$AB", - "7 INS_$AC", - "7 INS_$AD", - "7 INS_$AE", - "7 INS_$AF", - - "8 PushB[0]", - "8 PushB[1]", - "8 PushB[2]", - "8 PushB[3]", - "8 PushB[4]", - "8 PushB[5]", - "8 PushB[6]", - "8 PushB[7]", - "8 PushW[0]", - "8 PushW[1]", - "8 PushW[2]", - "8 PushW[3]", - "8 PushW[4]", - "8 PushW[5]", - "8 PushW[6]", - "8 PushW[7]", - - "8 MDRP[00]", - "8 MDRP[01]", - "8 MDRP[02]", - "8 MDRP[03]", - "8 MDRP[04]", - "8 MDRP[05]", - "8 MDRP[06]", - "8 MDRP[07]", - "8 MDRP[08]", - "8 MDRP[09]", - "8 MDRP[10]", - "8 MDRP[11]", - "8 MDRP[12]", - "8 MDRP[13]", - "8 MDRP[14]", - "8 MDRP[15]", - - "8 MDRP[16]", - "8 MDRP[17]", - "8 MDRP[18]", - "8 MDRP[19]", - "8 MDRP[20]", - "8 MDRP[21]", - "8 MDRP[22]", - "8 MDRP[23]", - "8 MDRP[24]", - "8 MDRP[25]", - "8 MDRP[26]", - "8 MDRP[27]", - "8 MDRP[28]", - "8 MDRP[29]", - "8 MDRP[30]", - "8 MDRP[31]", - - "8 MIRP[00]", - "8 MIRP[01]", - "8 MIRP[02]", - "8 MIRP[03]", - "8 MIRP[04]", - "8 MIRP[05]", - "8 MIRP[06]", - "8 MIRP[07]", - "8 MIRP[08]", - "8 MIRP[09]", - "8 MIRP[10]", - "8 MIRP[11]", - "8 MIRP[12]", - "8 MIRP[13]", - "8 MIRP[14]", - "8 MIRP[15]", - - "8 MIRP[16]", - "8 MIRP[17]", - "8 MIRP[18]", - "8 MIRP[19]", - "8 MIRP[20]", - "8 MIRP[21]", - "8 MIRP[22]", - "8 MIRP[23]", - "8 MIRP[24]", - "8 MIRP[25]", - "8 MIRP[26]", - "8 MIRP[27]", - "8 MIRP[28]", - "8 MIRP[29]", - "8 MIRP[30]", - "8 MIRP[31]" - }; - -#endif /* FT_DEBUG_LEVEL_TRACE */ - - - static - const FT_Char opcode_length[256] = - { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - -1,-2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7, 9, 11,13,15,17, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - -#undef PACK - - -#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 ) - { - 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 ) - { - FT_Int32 sign; - FT_UInt32 ah, al, mid, lo, hi; - - - sign = a ^ b; - - if ( a < 0 ) - a = -a; - if ( b < 0 ) - b = -b; - - ah = (FT_UInt32)( ( a >> 16 ) & 0xFFFFU ); - al = (FT_UInt32)( a & 0xFFFFU ); - - lo = al * b; - mid = ah * b; - hi = mid >> 16; - mid = ( mid << 16 ) + ( 1 << 13 ); /* rounding */ - lo += mid; - if ( lo < mid ) - hi += 1; - - mid = ( lo >> 14 ) | ( hi << 18 ); - - return sign >= 0 ? (FT_Int32)mid : -(FT_Int32)mid; - } - -#endif /* !TT_MulFix14 */ - - -#if defined( __GNUC__ ) && \ - ( defined( __i386__ ) || \ - defined( __x86_64__ ) || \ - defined( __arm__ ) ) - -#define TT_DotFix14 TT_DotFix14_long_long - -#if ( __GNUC__ * 100 + __GNUC_MINOR__ ) >= 406 -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wlong-long" - - 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'. */ - - 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 ); - - } - -#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 - TT_DotFix14( FT_Int32 ax, - FT_Int32 ay, - FT_Int bx, - FT_Int by ) - { - FT_Int32 m, s, hi1, hi2, hi; - FT_UInt32 l, lo1, lo2, lo; - - - /* compute ax*bx as 64-bit value */ - l = (FT_UInt32)( ( ax & 0xFFFFU ) * bx ); - m = ( ax >> 16 ) * bx; - - lo1 = l + ( (FT_UInt32)m << 16 ); - hi1 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo1 < l ); - - /* compute ay*by as 64-bit value */ - l = (FT_UInt32)( ( ay & 0xFFFFU ) * by ); - m = ( ay >> 16 ) * by; - - lo2 = l + ( (FT_UInt32)m << 16 ); - hi2 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo2 < l ); - - /* add them */ - lo = lo1 + lo2; - hi = hi1 + hi2 + ( lo < lo1 ); - - /* divide the result by 2^14 with rounding */ - s = hi >> 31; - l = lo + (FT_UInt32)s; - hi += s + ( l < lo ); - lo = l; - - l = lo + 0x2000U; - hi += ( l < lo ); - - return (FT_Int32)( ( (FT_UInt32)hi << 18 ) | ( l >> 14 ) ); - } - -#endif /* TT_DotFix14 */ - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Current_Ratio */ - /* */ - /* <Description> */ - /* Returns the current aspect ratio scaling factor depending on the */ - /* projection vector's state and device resolutions. */ - /* */ - /* <Return> */ - /* The aspect ratio in 16.16 format, always <= 1.0 . */ - /* */ - static FT_Long - Current_Ratio( TT_ExecContext exc ) - { - if ( !exc->tt_metrics.ratio ) - { - if ( exc->GS.projVector.y == 0 ) - exc->tt_metrics.ratio = exc->tt_metrics.x_ratio; - - else if ( exc->GS.projVector.x == 0 ) - exc->tt_metrics.ratio = exc->tt_metrics.y_ratio; - - else - { - FT_F26Dot6 x, y; - - - x = TT_MulFix14( exc->tt_metrics.x_ratio, - exc->GS.projVector.x ); - y = TT_MulFix14( exc->tt_metrics.y_ratio, - exc->GS.projVector.y ); - exc->tt_metrics.ratio = FT_Hypot( x, y ); - } - } - return exc->tt_metrics.ratio; - } - - - FT_CALLBACK_DEF( FT_Long ) - Current_Ppem( TT_ExecContext exc ) - { - return exc->tt_metrics.ppem; - } - - - FT_CALLBACK_DEF( FT_Long ) - Current_Ppem_Stretched( TT_ExecContext exc ) - { - return FT_MulFix( exc->tt_metrics.ppem, Current_Ratio( exc ) ); - } - - - /*************************************************************************/ - /* */ - /* Functions related to the control value table (CVT). */ - /* */ - /*************************************************************************/ - - - FT_CALLBACK_DEF( FT_F26Dot6 ) - Read_CVT( TT_ExecContext exc, - FT_ULong idx ) - { - return exc->cvt[idx]; - } - - - FT_CALLBACK_DEF( FT_F26Dot6 ) - Read_CVT_Stretched( TT_ExecContext exc, - FT_ULong idx ) - { - return FT_MulFix( exc->cvt[idx], Current_Ratio( exc ) ); - } - - - FT_CALLBACK_DEF( void ) - Write_CVT( TT_ExecContext exc, - FT_ULong idx, - FT_F26Dot6 value ) - { - exc->cvt[idx] = value; - } - - - FT_CALLBACK_DEF( void ) - Write_CVT_Stretched( TT_ExecContext exc, - FT_ULong idx, - FT_F26Dot6 value ) - { - exc->cvt[idx] = FT_DivFix( value, Current_Ratio( exc ) ); - } - - - FT_CALLBACK_DEF( void ) - Move_CVT( TT_ExecContext exc, - FT_ULong idx, - FT_F26Dot6 value ) - { - exc->cvt[idx] += value; - } - - - FT_CALLBACK_DEF( void ) - Move_CVT_Stretched( TT_ExecContext exc, - FT_ULong idx, - FT_F26Dot6 value ) - { - exc->cvt[idx] += FT_DivFix( value, Current_Ratio( exc ) ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* GetShortIns */ - /* */ - /* <Description> */ - /* Returns a short integer taken from the instruction stream at */ - /* address IP. */ - /* */ - /* <Return> */ - /* Short read at code[IP]. */ - /* */ - /* <Note> */ - /* This one could become a macro. */ - /* */ - static FT_Short - GetShortIns( TT_ExecContext exc ) - { - /* Reading a byte stream so there is no endianness (DaveP) */ - exc->IP += 2; - return (FT_Short)( ( exc->code[exc->IP - 2] << 8 ) + - exc->code[exc->IP - 1] ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Ins_Goto_CodeRange */ - /* */ - /* <Description> */ - /* Goes to a certain code range in the instruction stream. */ - /* */ - /* <Input> */ - /* aRange :: The index of the code range. */ - /* */ - /* aIP :: The new IP address in the code range. */ - /* */ - /* <Return> */ - /* SUCCESS or FAILURE. */ - /* */ - static FT_Bool - Ins_Goto_CodeRange( TT_ExecContext exc, - FT_Int aRange, - FT_Long aIP ) - { - TT_CodeRange* range; - - - if ( aRange < 1 || aRange > 3 ) - { - exc->error = FT_THROW( Bad_Argument ); - return FAILURE; - } - - range = &exc->codeRangeTable[aRange - 1]; - - if ( !range->base ) /* invalid coderange */ - { - exc->error = FT_THROW( Invalid_CodeRange ); - return FAILURE; - } - - /* NOTE: Because the last instruction of a program may be a CALL */ - /* which will return to the first byte *after* the code */ - /* range, we test for aIP <= Size, instead of aIP < Size. */ - - if ( aIP > range->size ) - { - exc->error = FT_THROW( Code_Overflow ); - return FAILURE; - } - - exc->code = range->base; - exc->codeSize = range->size; - exc->IP = aIP; - exc->curRange = aRange; - - return SUCCESS; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Direct_Move */ - /* */ - /* <Description> */ - /* Moves a point by a given distance along the freedom vector. The */ - /* point will be `touched'. */ - /* */ - /* <Input> */ - /* point :: The index of the point to move. */ - /* */ - /* distance :: The distance to apply. */ - /* */ - /* <InOut> */ - /* zone :: The affected glyph zone. */ - /* */ - /* <Note> */ - /* See `ttinterp.h' for details on backward compatibility mode. */ - /* `Touches' the point. */ - /* */ - static void - Direct_Move( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { - FT_F26Dot6 v; - - - v = exc->GS.freeVector.x; - - if ( v != 0 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - ( !exc->ignore_x_mode || - ( exc->sph_tweak_flags & SPH_TWEAK_ALLOW_X_DMOVE ) ) ) - zone->cur[point].x += FT_MulDiv( distance, v, exc->F_dot_P ); - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* Exception to the post-IUP curfew: Allow the x component of */ - /* diagonal moves, but only post-IUP. DejaVu tries to adjust */ - /* diagonal stems like on `Z' and `z' post-IUP. */ - if ( SUBPIXEL_HINTING_MINIMAL && !exc->backward_compatibility ) - zone->cur[point].x += FT_MulDiv( distance, v, exc->F_dot_P ); - else -#endif - - if ( NO_SUBPIXEL_HINTING ) - zone->cur[point].x += FT_MulDiv( distance, v, exc->F_dot_P ); - - zone->tags[point] |= FT_CURVE_TAG_TOUCH_X; - } - - v = exc->GS.freeVector.y; - - if ( v != 0 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( !( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && - exc->iupy_called ) ) -#endif - zone->cur[point].y += FT_MulDiv( distance, v, exc->F_dot_P ); - - zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y; - } - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Direct_Move_Orig */ - /* */ - /* <Description> */ - /* Moves the *original* position of a point by a given distance along */ - /* the freedom vector. Obviously, the point will not be `touched'. */ - /* */ - /* <Input> */ - /* point :: The index of the point to move. */ - /* */ - /* distance :: The distance to apply. */ - /* */ - /* <InOut> */ - /* zone :: The affected glyph zone. */ - /* */ - static void - Direct_Move_Orig( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { - FT_F26Dot6 v; - - - v = exc->GS.freeVector.x; - - if ( v != 0 ) - zone->org[point].x += FT_MulDiv( distance, v, exc->F_dot_P ); - - v = exc->GS.freeVector.y; - - if ( v != 0 ) - zone->org[point].y += FT_MulDiv( distance, v, exc->F_dot_P ); - } - - - /*************************************************************************/ - /* */ - /* Special versions of Direct_Move() */ - /* */ - /* The following versions are used whenever both vectors are both */ - /* along one of the coordinate unit vectors, i.e. in 90% of the cases. */ - /* See `ttinterp.h' for details on backward compatibility mode. */ - /* */ - /*************************************************************************/ - - - static void - Direct_Move_X( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && !exc->ignore_x_mode ) - zone->cur[point].x += distance; - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( SUBPIXEL_HINTING_MINIMAL && !exc->backward_compatibility ) - zone->cur[point].x += distance; - else -#endif - - if ( NO_SUBPIXEL_HINTING ) - zone->cur[point].x += distance; - - zone->tags[point] |= FT_CURVE_TAG_TOUCH_X; - } - - - static void - Direct_Move_Y( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { - FT_UNUSED( exc ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( !( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && exc->iupy_called ) ) -#endif - zone->cur[point].y += distance; - - zone->tags[point] |= FT_CURVE_TAG_TOUCH_Y; - } - - - /*************************************************************************/ - /* */ - /* Special versions of Direct_Move_Orig() */ - /* */ - /* The following versions are used whenever both vectors are both */ - /* along one of the coordinate unit vectors, i.e. in 90% of the cases. */ - /* */ - /*************************************************************************/ - - - static void - Direct_Move_Orig_X( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { - FT_UNUSED( exc ); - - zone->org[point].x += distance; - } - - - static void - Direct_Move_Orig_Y( TT_ExecContext exc, - TT_GlyphZone zone, - FT_UShort point, - FT_F26Dot6 distance ) - { - FT_UNUSED( exc ); - - zone->org[point].y += distance; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_None */ - /* */ - /* <Description> */ - /* Does not round, but adds engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance (not) to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* The compensated distance. */ - /* */ - /* <Note> */ - /* The TrueType specification says very few about the relationship */ - /* between rounding and engine compensation. However, it seems from */ - /* the description of super round that we should add the compensation */ - /* before rounding. */ - /* */ - static FT_F26Dot6 - Round_None( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = distance + compensation; - if ( val < 0 ) - val = 0; - } - else - { - val = distance - compensation; - if ( val > 0 ) - val = 0; - } - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_To_Grid */ - /* */ - /* <Description> */ - /* Rounds value to grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - static FT_F26Dot6 - Round_To_Grid( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = FT_PIX_ROUND( distance + compensation ); - if ( val < 0 ) - val = 0; - } - else - { - val = -FT_PIX_ROUND( compensation - distance ); - if ( val > 0 ) - val = 0; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_To_Half_Grid */ - /* */ - /* <Description> */ - /* Rounds value to half grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - static FT_F26Dot6 - Round_To_Half_Grid( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = FT_PIX_FLOOR( distance + compensation ) + 32; - if ( val < 0 ) - val = 32; - } - else - { - val = -( FT_PIX_FLOOR( compensation - distance ) + 32 ); - if ( val > 0 ) - val = -32; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_Down_To_Grid */ - /* */ - /* <Description> */ - /* Rounds value down to grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - static FT_F26Dot6 - Round_Down_To_Grid( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = FT_PIX_FLOOR( distance + compensation ); - if ( val < 0 ) - val = 0; - } - else - { - val = -FT_PIX_FLOOR( compensation - distance ); - if ( val > 0 ) - val = 0; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_Up_To_Grid */ - /* */ - /* <Description> */ - /* Rounds value up to grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - static FT_F26Dot6 - Round_Up_To_Grid( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = FT_PIX_CEIL( distance + compensation ); - if ( val < 0 ) - val = 0; - } - else - { - val = -FT_PIX_CEIL( compensation - distance ); - if ( val > 0 ) - val = 0; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_To_Double_Grid */ - /* */ - /* <Description> */ - /* Rounds value to double grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - static FT_F26Dot6 - Round_To_Double_Grid( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - FT_UNUSED( exc ); - - - if ( distance >= 0 ) - { - val = FT_PAD_ROUND( distance + compensation, 32 ); - if ( val < 0 ) - val = 0; - } - else - { - val = -FT_PAD_ROUND( compensation - distance, 32 ); - if ( val > 0 ) - val = 0; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_Super */ - /* */ - /* <Description> */ - /* Super-rounds value to grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - /* <Note> */ - /* The TrueType specification says very little about the relationship */ - /* between rounding and engine compensation. However, it seems from */ - /* the description of super round that we should add the compensation */ - /* before rounding. */ - /* */ - static FT_F26Dot6 - Round_Super( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - - if ( distance >= 0 ) - { - val = ( distance - exc->phase + exc->threshold + compensation ) & - -exc->period; - val += exc->phase; - if ( val < 0 ) - val = exc->phase; - } - else - { - val = -( ( exc->threshold - exc->phase - distance + compensation ) & - -exc->period ); - val -= exc->phase; - if ( val > 0 ) - val = -exc->phase; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Round_Super_45 */ - /* */ - /* <Description> */ - /* Super-rounds value to grid after adding engine compensation. */ - /* */ - /* <Input> */ - /* distance :: The distance to round. */ - /* */ - /* compensation :: The engine compensation. */ - /* */ - /* <Return> */ - /* Rounded distance. */ - /* */ - /* <Note> */ - /* There is a separate function for Round_Super_45() as we may need */ - /* greater precision. */ - /* */ - static FT_F26Dot6 - Round_Super_45( TT_ExecContext exc, - FT_F26Dot6 distance, - FT_F26Dot6 compensation ) - { - FT_F26Dot6 val; - - - if ( distance >= 0 ) - { - val = ( ( distance - exc->phase + exc->threshold + compensation ) / - exc->period ) * exc->period; - val += exc->phase; - if ( val < 0 ) - val = exc->phase; - } - else - { - val = -( ( ( exc->threshold - exc->phase - distance + compensation ) / - exc->period ) * exc->period ); - val -= exc->phase; - if ( val > 0 ) - val = -exc->phase; - } - - return val; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Compute_Round */ - /* */ - /* <Description> */ - /* Sets the rounding mode. */ - /* */ - /* <Input> */ - /* round_mode :: The rounding mode to be used. */ - /* */ - static void - Compute_Round( TT_ExecContext exc, - FT_Byte round_mode ) - { - switch ( round_mode ) - { - case TT_Round_Off: - exc->func_round = (TT_Round_Func)Round_None; - break; - - case TT_Round_To_Grid: - exc->func_round = (TT_Round_Func)Round_To_Grid; - break; - - case TT_Round_Up_To_Grid: - exc->func_round = (TT_Round_Func)Round_Up_To_Grid; - break; - - case TT_Round_Down_To_Grid: - exc->func_round = (TT_Round_Func)Round_Down_To_Grid; - break; - - case TT_Round_To_Half_Grid: - exc->func_round = (TT_Round_Func)Round_To_Half_Grid; - break; - - case TT_Round_To_Double_Grid: - exc->func_round = (TT_Round_Func)Round_To_Double_Grid; - break; - - case TT_Round_Super: - exc->func_round = (TT_Round_Func)Round_Super; - break; - - case TT_Round_Super_45: - exc->func_round = (TT_Round_Func)Round_Super_45; - break; - } - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* SetSuperRound */ - /* */ - /* <Description> */ - /* Sets Super Round parameters. */ - /* */ - /* <Input> */ - /* GridPeriod :: The grid period. */ - /* */ - /* selector :: The SROUND opcode. */ - /* */ - static void - SetSuperRound( TT_ExecContext exc, - FT_F2Dot14 GridPeriod, - FT_Long selector ) - { - switch ( (FT_Int)( selector & 0xC0 ) ) - { - case 0: - exc->period = GridPeriod / 2; - break; - - case 0x40: - exc->period = GridPeriod; - break; - - case 0x80: - exc->period = GridPeriod * 2; - break; - - /* This opcode is reserved, but... */ - case 0xC0: - exc->period = GridPeriod; - break; - } - - switch ( (FT_Int)( selector & 0x30 ) ) - { - case 0: - exc->phase = 0; - break; - - case 0x10: - exc->phase = exc->period / 4; - break; - - case 0x20: - exc->phase = exc->period / 2; - break; - - case 0x30: - exc->phase = exc->period * 3 / 4; - break; - } - - if ( ( selector & 0x0F ) == 0 ) - exc->threshold = exc->period - 1; - else - exc->threshold = ( (FT_Int)( selector & 0x0F ) - 4 ) * exc->period / 8; - - /* convert to F26Dot6 format */ - exc->period >>= 8; - exc->phase >>= 8; - exc->threshold >>= 8; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Project */ - /* */ - /* <Description> */ - /* Computes the projection of vector given by (v2-v1) along the */ - /* current projection vector. */ - /* */ - /* <Input> */ - /* v1 :: First input vector. */ - /* v2 :: Second input vector. */ - /* */ - /* <Return> */ - /* The distance in F26dot6 format. */ - /* */ - static FT_F26Dot6 - Project( TT_ExecContext exc, - FT_Pos dx, - FT_Pos dy ) - { - return TT_DotFix14( dx, dy, - exc->GS.projVector.x, - exc->GS.projVector.y ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Dual_Project */ - /* */ - /* <Description> */ - /* Computes the projection of the vector given by (v2-v1) along the */ - /* current dual vector. */ - /* */ - /* <Input> */ - /* v1 :: First input vector. */ - /* v2 :: Second input vector. */ - /* */ - /* <Return> */ - /* The distance in F26dot6 format. */ - /* */ - static FT_F26Dot6 - Dual_Project( TT_ExecContext exc, - FT_Pos dx, - FT_Pos dy ) - { - return TT_DotFix14( dx, dy, - exc->GS.dualVector.x, - exc->GS.dualVector.y ); - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Project_x */ - /* */ - /* <Description> */ - /* Computes the projection of the vector given by (v2-v1) along the */ - /* horizontal axis. */ - /* */ - /* <Input> */ - /* v1 :: First input vector. */ - /* v2 :: Second input vector. */ - /* */ - /* <Return> */ - /* The distance in F26dot6 format. */ - /* */ - static FT_F26Dot6 - Project_x( TT_ExecContext exc, - FT_Pos dx, - FT_Pos dy ) - { - FT_UNUSED( exc ); - FT_UNUSED( dy ); - - return dx; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Project_y */ - /* */ - /* <Description> */ - /* Computes the projection of the vector given by (v2-v1) along the */ - /* vertical axis. */ - /* */ - /* <Input> */ - /* v1 :: First input vector. */ - /* v2 :: Second input vector. */ - /* */ - /* <Return> */ - /* The distance in F26dot6 format. */ - /* */ - static FT_F26Dot6 - Project_y( TT_ExecContext exc, - FT_Pos dx, - FT_Pos dy ) - { - FT_UNUSED( exc ); - FT_UNUSED( dx ); - - return dy; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Compute_Funcs */ - /* */ - /* <Description> */ - /* Computes the projection and movement function pointers according */ - /* to the current graphics state. */ - /* */ - static void - Compute_Funcs( TT_ExecContext exc ) - { - if ( exc->GS.freeVector.x == 0x4000 ) - exc->F_dot_P = exc->GS.projVector.x; - else if ( exc->GS.freeVector.y == 0x4000 ) - exc->F_dot_P = exc->GS.projVector.y; - else - exc->F_dot_P = - ( (FT_Long)exc->GS.projVector.x * exc->GS.freeVector.x + - (FT_Long)exc->GS.projVector.y * exc->GS.freeVector.y ) >> 14; - - if ( exc->GS.projVector.x == 0x4000 ) - exc->func_project = (TT_Project_Func)Project_x; - else if ( exc->GS.projVector.y == 0x4000 ) - exc->func_project = (TT_Project_Func)Project_y; - else - exc->func_project = (TT_Project_Func)Project; - - if ( exc->GS.dualVector.x == 0x4000 ) - exc->func_dualproj = (TT_Project_Func)Project_x; - else if ( exc->GS.dualVector.y == 0x4000 ) - exc->func_dualproj = (TT_Project_Func)Project_y; - else - exc->func_dualproj = (TT_Project_Func)Dual_Project; - - exc->func_move = (TT_Move_Func)Direct_Move; - exc->func_move_orig = (TT_Move_Func)Direct_Move_Orig; - - if ( exc->F_dot_P == 0x4000L ) - { - if ( exc->GS.freeVector.x == 0x4000 ) - { - exc->func_move = (TT_Move_Func)Direct_Move_X; - exc->func_move_orig = (TT_Move_Func)Direct_Move_Orig_X; - } - else if ( exc->GS.freeVector.y == 0x4000 ) - { - exc->func_move = (TT_Move_Func)Direct_Move_Y; - exc->func_move_orig = (TT_Move_Func)Direct_Move_Orig_Y; - } - } - - /* at small sizes, F_dot_P can become too small, resulting */ - /* in overflows and `spikes' in a number of glyphs like `w'. */ - - if ( FT_ABS( exc->F_dot_P ) < 0x400L ) - exc->F_dot_P = 0x4000L; - - /* Disable cached aspect ratio */ - exc->tt_metrics.ratio = 0; - } - - - /*************************************************************************/ - /* */ - /* <Function> */ - /* Normalize */ - /* */ - /* <Description> */ - /* Norms a vector. */ - /* */ - /* <Input> */ - /* Vx :: The horizontal input vector coordinate. */ - /* Vy :: The vertical input vector coordinate. */ - /* */ - /* <Output> */ - /* R :: The normed unit vector. */ - /* */ - /* <Return> */ - /* Returns FAILURE if a vector parameter is zero. */ - /* */ - /* <Note> */ - /* In case Vx and Vy are both zero, `Normalize' returns SUCCESS, and */ - /* R is undefined. */ - /* */ - static FT_Bool - Normalize( FT_F26Dot6 Vx, - FT_F26Dot6 Vy, - FT_UnitVector* R ) - { - FT_Vector V; - - - if ( Vx == 0 && Vy == 0 ) - { - /* XXX: UNDOCUMENTED! It seems that it is possible to try */ - /* to normalize the vector (0,0). Return immediately. */ - return SUCCESS; - } - - V.x = Vx; - V.y = Vy; - - FT_Vector_NormLen( &V ); - - R->x = (FT_F2Dot14)( V.x / 4 ); - R->y = (FT_F2Dot14)( V.y / 4 ); - - return SUCCESS; - } - - - /*************************************************************************/ - /* */ - /* Here we start with the implementation of the various opcodes. */ - /* */ - /*************************************************************************/ - - -#define ARRAY_BOUND_ERROR \ - do \ - { \ - exc->error = FT_THROW( Invalid_Reference ); \ - return; \ - } while (0) - - - /*************************************************************************/ - /* */ - /* MPPEM[]: Measure Pixel Per EM */ - /* Opcode range: 0x4B */ - /* Stack: --> Euint16 */ - /* */ - static void - Ins_MPPEM( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = exc->func_cur_ppem( exc ); - } - - - /*************************************************************************/ - /* */ - /* MPS[]: Measure Point Size */ - /* Opcode range: 0x4C */ - /* Stack: --> Euint16 */ - /* */ - static void - Ins_MPS( TT_ExecContext exc, - FT_Long* args ) - { - if ( NO_SUBPIXEL_HINTING ) - { - /* Microsoft's GDI bytecode interpreter always returns value 12; */ - /* we return the current PPEM value instead. */ - args[0] = exc->func_cur_ppem( exc ); - } - else - { - /* A possible practical application of the MPS instruction is to */ - /* implement optical scaling and similar features, which should be */ - /* based on perceptual attributes, thus independent of the */ - /* resolution. */ - args[0] = exc->pointSize; - } - } - - - /*************************************************************************/ - /* */ - /* DUP[]: DUPlicate the stack's top element */ - /* Opcode range: 0x20 */ - /* Stack: StkElt --> StkElt StkElt */ - /* */ - static void - Ins_DUP( FT_Long* args ) - { - args[1] = args[0]; - } - - - /*************************************************************************/ - /* */ - /* POP[]: POP the stack's top element */ - /* Opcode range: 0x21 */ - /* Stack: StkElt --> */ - /* */ - static void - Ins_POP( void ) - { - /* nothing to do */ - } - - - /*************************************************************************/ - /* */ - /* CLEAR[]: CLEAR the entire stack */ - /* Opcode range: 0x22 */ - /* Stack: StkElt... --> */ - /* */ - static void - Ins_CLEAR( TT_ExecContext exc ) - { - exc->new_top = 0; - } - - - /*************************************************************************/ - /* */ - /* SWAP[]: SWAP the stack's top two elements */ - /* Opcode range: 0x23 */ - /* Stack: 2 * StkElt --> 2 * StkElt */ - /* */ - static void - Ins_SWAP( FT_Long* args ) - { - FT_Long L; - - - L = args[0]; - args[0] = args[1]; - args[1] = L; - } - - - /*************************************************************************/ - /* */ - /* DEPTH[]: return the stack DEPTH */ - /* Opcode range: 0x24 */ - /* Stack: --> uint32 */ - /* */ - static void - Ins_DEPTH( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = exc->top; - } - - - /*************************************************************************/ - /* */ - /* LT[]: Less Than */ - /* Opcode range: 0x50 */ - /* Stack: int32? int32? --> bool */ - /* */ - static void - Ins_LT( FT_Long* args ) - { - args[0] = ( args[0] < args[1] ); - } - - - /*************************************************************************/ - /* */ - /* LTEQ[]: Less Than or EQual */ - /* Opcode range: 0x51 */ - /* Stack: int32? int32? --> bool */ - /* */ - static void - Ins_LTEQ( FT_Long* args ) - { - args[0] = ( args[0] <= args[1] ); - } - - - /*************************************************************************/ - /* */ - /* GT[]: Greater Than */ - /* Opcode range: 0x52 */ - /* Stack: int32? int32? --> bool */ - /* */ - static void - Ins_GT( FT_Long* args ) - { - args[0] = ( args[0] > args[1] ); - } - - - /*************************************************************************/ - /* */ - /* GTEQ[]: Greater Than or EQual */ - /* Opcode range: 0x53 */ - /* Stack: int32? int32? --> bool */ - /* */ - static void - Ins_GTEQ( FT_Long* args ) - { - args[0] = ( args[0] >= args[1] ); - } - - - /*************************************************************************/ - /* */ - /* EQ[]: EQual */ - /* Opcode range: 0x54 */ - /* Stack: StkElt StkElt --> bool */ - /* */ - static void - Ins_EQ( FT_Long* args ) - { - args[0] = ( args[0] == args[1] ); - } - - - /*************************************************************************/ - /* */ - /* NEQ[]: Not EQual */ - /* Opcode range: 0x55 */ - /* Stack: StkElt StkElt --> bool */ - /* */ - static void - Ins_NEQ( FT_Long* args ) - { - args[0] = ( args[0] != args[1] ); - } - - - /*************************************************************************/ - /* */ - /* ODD[]: Is ODD */ - /* Opcode range: 0x56 */ - /* Stack: f26.6 --> bool */ - /* */ - static void - Ins_ODD( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = ( ( exc->func_round( exc, args[0], 0 ) & 127 ) == 64 ); - } - - - /*************************************************************************/ - /* */ - /* EVEN[]: Is EVEN */ - /* Opcode range: 0x57 */ - /* Stack: f26.6 --> bool */ - /* */ - static void - Ins_EVEN( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = ( ( exc->func_round( exc, args[0], 0 ) & 127 ) == 0 ); - } - - - /*************************************************************************/ - /* */ - /* AND[]: logical AND */ - /* Opcode range: 0x5A */ - /* Stack: uint32 uint32 --> uint32 */ - /* */ - static void - Ins_AND( FT_Long* args ) - { - args[0] = ( args[0] && args[1] ); - } - - - /*************************************************************************/ - /* */ - /* OR[]: logical OR */ - /* Opcode range: 0x5B */ - /* Stack: uint32 uint32 --> uint32 */ - /* */ - static void - Ins_OR( FT_Long* args ) - { - args[0] = ( args[0] || args[1] ); - } - - - /*************************************************************************/ - /* */ - /* NOT[]: logical NOT */ - /* Opcode range: 0x5C */ - /* Stack: StkElt --> uint32 */ - /* */ - static void - Ins_NOT( FT_Long* args ) - { - args[0] = !args[0]; - } - - - /*************************************************************************/ - /* */ - /* ADD[]: ADD */ - /* Opcode range: 0x60 */ - /* Stack: f26.6 f26.6 --> f26.6 */ - /* */ - static void - Ins_ADD( FT_Long* args ) - { - args[0] += args[1]; - } - - - /*************************************************************************/ - /* */ - /* SUB[]: SUBtract */ - /* Opcode range: 0x61 */ - /* Stack: f26.6 f26.6 --> f26.6 */ - /* */ - static void - Ins_SUB( FT_Long* args ) - { - args[0] -= args[1]; - } - - - /*************************************************************************/ - /* */ - /* DIV[]: DIVide */ - /* Opcode range: 0x62 */ - /* Stack: f26.6 f26.6 --> f26.6 */ - /* */ - static void - Ins_DIV( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[1] == 0 ) - exc->error = FT_THROW( Divide_By_Zero ); - else - args[0] = FT_MulDiv_No_Round( args[0], 64L, args[1] ); - } - - - /*************************************************************************/ - /* */ - /* MUL[]: MULtiply */ - /* Opcode range: 0x63 */ - /* Stack: f26.6 f26.6 --> f26.6 */ - /* */ - static void - Ins_MUL( FT_Long* args ) - { - args[0] = FT_MulDiv( args[0], args[1], 64L ); - } - - - /*************************************************************************/ - /* */ - /* ABS[]: ABSolute value */ - /* Opcode range: 0x64 */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_ABS( FT_Long* args ) - { - args[0] = FT_ABS( args[0] ); - } - - - /*************************************************************************/ - /* */ - /* NEG[]: NEGate */ - /* Opcode range: 0x65 */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_NEG( FT_Long* args ) - { - args[0] = -args[0]; - } - - - /*************************************************************************/ - /* */ - /* FLOOR[]: FLOOR */ - /* Opcode range: 0x66 */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_FLOOR( FT_Long* args ) - { - args[0] = FT_PIX_FLOOR( args[0] ); - } - - - /*************************************************************************/ - /* */ - /* CEILING[]: CEILING */ - /* Opcode range: 0x67 */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_CEILING( FT_Long* args ) - { - args[0] = FT_PIX_CEIL( args[0] ); - } - - - /*************************************************************************/ - /* */ - /* RS[]: Read Store */ - /* Opcode range: 0x43 */ - /* Stack: uint32 --> uint32 */ - /* */ - static void - Ins_RS( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong I = (FT_ULong)args[0]; - - - if ( BOUNDSL( I, exc->storeSize ) ) - { - if ( exc->pedantic_hinting ) - ARRAY_BOUND_ERROR; - else - args[0] = 0; - } - else - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* subpixel hinting - avoid Typeman Dstroke and */ - /* IStroke and Vacuform rounds */ - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - ( ( I == 24 && - ( exc->face->sph_found_func_flags & - ( SPH_FDEF_SPACING_1 | - SPH_FDEF_SPACING_2 ) ) ) || - ( I == 22 && - ( exc->sph_in_func_flags & - SPH_FDEF_TYPEMAN_STROKES ) ) || - ( I == 8 && - ( exc->face->sph_found_func_flags & - SPH_FDEF_VACUFORM_ROUND_1 ) && - exc->iup_called ) ) ) - args[0] = 0; - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - args[0] = exc->storage[I]; - } - } - - - /*************************************************************************/ - /* */ - /* WS[]: Write Store */ - /* Opcode range: 0x42 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_WS( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong I = (FT_ULong)args[0]; - - - if ( BOUNDSL( I, exc->storeSize ) ) - { - if ( exc->pedantic_hinting ) - ARRAY_BOUND_ERROR; - } - else - exc->storage[I] = args[1]; - } - - - /*************************************************************************/ - /* */ - /* WCVTP[]: Write CVT in Pixel units */ - /* Opcode range: 0x44 */ - /* Stack: f26.6 uint32 --> */ - /* */ - static void - Ins_WCVTP( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong I = (FT_ULong)args[0]; - - - if ( BOUNDSL( I, exc->cvtSize ) ) - { - if ( exc->pedantic_hinting ) - ARRAY_BOUND_ERROR; - } - else - exc->func_write_cvt( exc, I, args[1] ); - } - - - /*************************************************************************/ - /* */ - /* WCVTF[]: Write CVT in Funits */ - /* Opcode range: 0x70 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_WCVTF( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong I = (FT_ULong)args[0]; - - - if ( BOUNDSL( I, exc->cvtSize ) ) - { - if ( exc->pedantic_hinting ) - ARRAY_BOUND_ERROR; - } - else - exc->cvt[I] = FT_MulFix( args[1], exc->tt_metrics.scale ); - } - - - /*************************************************************************/ - /* */ - /* RCVT[]: Read CVT */ - /* Opcode range: 0x45 */ - /* Stack: uint32 --> f26.6 */ - /* */ - static void - Ins_RCVT( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong I = (FT_ULong)args[0]; - - - if ( BOUNDSL( I, exc->cvtSize ) ) - { - if ( exc->pedantic_hinting ) - ARRAY_BOUND_ERROR; - else - args[0] = 0; - } - else - args[0] = exc->func_read_cvt( exc, I ); - } - - - /*************************************************************************/ - /* */ - /* AA[]: Adjust Angle */ - /* Opcode range: 0x7F */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_AA( void ) - { - /* intentionally no longer supported */ - } - - - /*************************************************************************/ - /* */ - /* DEBUG[]: DEBUG. Unsupported. */ - /* Opcode range: 0x4F */ - /* Stack: uint32 --> */ - /* */ - /* Note: The original instruction pops a value from the stack. */ - /* */ - static void - Ins_DEBUG( TT_ExecContext exc ) - { - exc->error = FT_THROW( Debug_OpCode ); - } - - - /*************************************************************************/ - /* */ - /* ROUND[ab]: ROUND value */ - /* Opcode range: 0x68-0x6B */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_ROUND( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = exc->func_round( - exc, - args[0], - exc->tt_metrics.compensations[exc->opcode - 0x68] ); - } - - - /*************************************************************************/ - /* */ - /* NROUND[ab]: No ROUNDing of value */ - /* Opcode range: 0x6C-0x6F */ - /* Stack: f26.6 --> f26.6 */ - /* */ - static void - Ins_NROUND( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = Round_None( - exc, - args[0], - exc->tt_metrics.compensations[exc->opcode - 0x6C] ); - } - - - /*************************************************************************/ - /* */ - /* MAX[]: MAXimum */ - /* Opcode range: 0x8B */ - /* Stack: int32? int32? --> int32 */ - /* */ - static void - Ins_MAX( FT_Long* args ) - { - if ( args[1] > args[0] ) - args[0] = args[1]; - } - - - /*************************************************************************/ - /* */ - /* MIN[]: MINimum */ - /* Opcode range: 0x8C */ - /* Stack: int32? int32? --> int32 */ - /* */ - static void - Ins_MIN( FT_Long* args ) - { - if ( args[1] < args[0] ) - args[0] = args[1]; - } - - - /*************************************************************************/ - /* */ - /* MINDEX[]: Move INDEXed element */ - /* Opcode range: 0x26 */ - /* Stack: int32? --> StkElt */ - /* */ - static void - Ins_MINDEX( TT_ExecContext exc, - FT_Long* args ) - { - FT_Long L, K; - - - L = args[0]; - - if ( L <= 0 || L > exc->args ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - } - else - { - K = exc->stack[exc->args - L]; - - FT_ARRAY_MOVE( &exc->stack[exc->args - L ], - &exc->stack[exc->args - L + 1], - ( L - 1 ) ); - - exc->stack[exc->args - 1] = K; - } - } - - - /*************************************************************************/ - /* */ - /* CINDEX[]: Copy INDEXed element */ - /* Opcode range: 0x25 */ - /* Stack: int32 --> StkElt */ - /* */ - static void - Ins_CINDEX( TT_ExecContext exc, - FT_Long* args ) - { - FT_Long L; - - - L = args[0]; - - if ( L <= 0 || L > exc->args ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - args[0] = 0; - } - else - args[0] = exc->stack[exc->args - L]; - } - - - /*************************************************************************/ - /* */ - /* ROLL[]: ROLL top three elements */ - /* Opcode range: 0x8A */ - /* Stack: 3 * StkElt --> 3 * StkElt */ - /* */ - static void - Ins_ROLL( FT_Long* args ) - { - FT_Long A, B, C; - - - A = args[2]; - B = args[1]; - C = args[0]; - - args[2] = C; - args[1] = A; - args[0] = B; - } - - - /*************************************************************************/ - /* */ - /* MANAGING THE FLOW OF CONTROL */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* SLOOP[]: Set LOOP variable */ - /* Opcode range: 0x17 */ - /* Stack: int32? --> */ - /* */ - static void - Ins_SLOOP( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[0] < 0 ) - exc->error = FT_THROW( Bad_Argument ); - else - exc->GS.loop = args[0]; - } - - - static FT_Bool - SkipCode( TT_ExecContext exc ) - { - exc->IP += exc->length; - - if ( exc->IP < exc->codeSize ) - { - exc->opcode = exc->code[exc->IP]; - - exc->length = opcode_length[exc->opcode]; - if ( exc->length < 0 ) - { - if ( exc->IP + 1 >= exc->codeSize ) - goto Fail_Overflow; - exc->length = 2 - exc->length * exc->code[exc->IP + 1]; - } - - if ( exc->IP + exc->length <= exc->codeSize ) - return SUCCESS; - } - - Fail_Overflow: - exc->error = FT_THROW( Code_Overflow ); - return FAILURE; - } - - - /*************************************************************************/ - /* */ - /* IF[]: IF test */ - /* Opcode range: 0x58 */ - /* Stack: StkElt --> */ - /* */ - static void - Ins_IF( TT_ExecContext exc, - FT_Long* args ) - { - FT_Int nIfs; - FT_Bool Out; - - - if ( args[0] != 0 ) - return; - - nIfs = 1; - Out = 0; - - do - { - if ( SkipCode( exc ) == FAILURE ) - return; - - switch ( exc->opcode ) - { - case 0x58: /* IF */ - nIfs++; - break; - - case 0x1B: /* ELSE */ - Out = FT_BOOL( nIfs == 1 ); - break; - - case 0x59: /* EIF */ - nIfs--; - Out = FT_BOOL( nIfs == 0 ); - break; - } - } while ( Out == 0 ); - } - - - /*************************************************************************/ - /* */ - /* ELSE[]: ELSE */ - /* Opcode range: 0x1B */ - /* Stack: --> */ - /* */ - static void - Ins_ELSE( TT_ExecContext exc ) - { - FT_Int nIfs; - - - nIfs = 1; - - do - { - if ( SkipCode( exc ) == FAILURE ) - return; - - switch ( exc->opcode ) - { - case 0x58: /* IF */ - nIfs++; - break; - - case 0x59: /* EIF */ - nIfs--; - break; - } - } while ( nIfs != 0 ); - } - - - /*************************************************************************/ - /* */ - /* EIF[]: End IF */ - /* Opcode range: 0x59 */ - /* Stack: --> */ - /* */ - static void - Ins_EIF( void ) - { - /* nothing to do */ - } - - - /*************************************************************************/ - /* */ - /* JMPR[]: JuMP Relative */ - /* Opcode range: 0x1C */ - /* Stack: int32 --> */ - /* */ - static void - Ins_JMPR( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[0] == 0 && exc->args == 0 ) - { - exc->error = FT_THROW( Bad_Argument ); - return; - } - - exc->IP += args[0]; - if ( exc->IP < 0 || - ( exc->callTop > 0 && - exc->IP > exc->callStack[exc->callTop - 1].Def->end ) ) - { - exc->error = FT_THROW( Bad_Argument ); - return; - } - - exc->step_ins = FALSE; - - if ( args[0] < 0 ) - { - if ( ++exc->neg_jump_counter > exc->neg_jump_counter_max ) - exc->error = FT_THROW( Execution_Too_Long ); - } - } - - - /*************************************************************************/ - /* */ - /* JROT[]: Jump Relative On True */ - /* Opcode range: 0x78 */ - /* Stack: StkElt int32 --> */ - /* */ - static void - Ins_JROT( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[1] != 0 ) - Ins_JMPR( exc, args ); - } - - - /*************************************************************************/ - /* */ - /* JROF[]: Jump Relative On False */ - /* Opcode range: 0x79 */ - /* Stack: StkElt int32 --> */ - /* */ - static void - Ins_JROF( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[1] == 0 ) - Ins_JMPR( exc, args ); - } - - - /*************************************************************************/ - /* */ - /* DEFINING AND USING FUNCTIONS AND INSTRUCTIONS */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* FDEF[]: Function DEFinition */ - /* Opcode range: 0x2C */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_FDEF( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong n; - TT_DefRecord* rec; - TT_DefRecord* limit; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* arguments to opcodes are skipped by `SKIP_Code' */ - FT_Byte opcode_pattern[9][12] = { - /* #0 inline delta function 1 */ - { - 0x4B, /* PPEM */ - 0x53, /* GTEQ */ - 0x23, /* SWAP */ - 0x4B, /* PPEM */ - 0x51, /* LTEQ */ - 0x5A, /* AND */ - 0x58, /* IF */ - 0x38, /* SHPIX */ - 0x1B, /* ELSE */ - 0x21, /* POP */ - 0x21, /* POP */ - 0x59 /* EIF */ - }, - /* #1 inline delta function 2 */ - { - 0x4B, /* PPEM */ - 0x54, /* EQ */ - 0x58, /* IF */ - 0x38, /* SHPIX */ - 0x1B, /* ELSE */ - 0x21, /* POP */ - 0x21, /* POP */ - 0x59 /* EIF */ - }, - /* #2 diagonal stroke function */ - { - 0x20, /* DUP */ - 0x20, /* DUP */ - 0xB0, /* PUSHB_1 */ - /* 1 */ - 0x60, /* ADD */ - 0x46, /* GC_cur */ - 0xB0, /* PUSHB_1 */ - /* 64 */ - 0x23, /* SWAP */ - 0x42 /* WS */ - }, - /* #3 VacuFormRound function */ - { - 0x45, /* RCVT */ - 0x23, /* SWAP */ - 0x46, /* GC_cur */ - 0x60, /* ADD */ - 0x20, /* DUP */ - 0xB0 /* PUSHB_1 */ - /* 38 */ - }, - /* #4 TTFautohint bytecode (old) */ - { - 0x20, /* DUP */ - 0x64, /* ABS */ - 0xB0, /* PUSHB_1 */ - /* 32 */ - 0x60, /* ADD */ - 0x66, /* FLOOR */ - 0x23, /* SWAP */ - 0xB0 /* PUSHB_1 */ - }, - /* #5 spacing function 1 */ - { - 0x01, /* SVTCA_x */ - 0xB0, /* PUSHB_1 */ - /* 24 */ - 0x43, /* RS */ - 0x58 /* IF */ - }, - /* #6 spacing function 2 */ - { - 0x01, /* SVTCA_x */ - 0x18, /* RTG */ - 0xB0, /* PUSHB_1 */ - /* 24 */ - 0x43, /* RS */ - 0x58 /* IF */ - }, - /* #7 TypeMan Talk DiagEndCtrl function */ - { - 0x01, /* SVTCA_x */ - 0x20, /* DUP */ - 0xB0, /* PUSHB_1 */ - /* 3 */ - 0x25, /* CINDEX */ - }, - /* #8 TypeMan Talk Align */ - { - 0x06, /* SPVTL */ - 0x7D, /* RDTG */ - }, - }; - FT_UShort opcode_patterns = 9; - FT_UShort opcode_pointer[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - FT_UShort opcode_size[9] = { 12, 8, 8, 6, 7, 4, 5, 4, 2 }; - FT_UShort i; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - - /* FDEF is only allowed in `prep' or `fpgm' */ - if ( exc->curRange == tt_coderange_glyph ) - { - exc->error = FT_THROW( DEF_In_Glyf_Bytecode ); - return; - } - - /* some font programs are broken enough to redefine functions! */ - /* We will then parse the current table. */ - - rec = exc->FDefs; - limit = rec + exc->numFDefs; - n = (FT_ULong)args[0]; - - for ( ; rec < limit; rec++ ) - { - if ( rec->opc == n ) - break; - } - - if ( rec == limit ) - { - /* check that there is enough room for new functions */ - if ( exc->numFDefs >= exc->maxFDefs ) - { - exc->error = FT_THROW( Too_Many_Function_Defs ); - return; - } - exc->numFDefs++; - } - - /* Although FDEF takes unsigned 32-bit integer, */ - /* func # must be within unsigned 16-bit integer */ - if ( n > 0xFFFFU ) - { - exc->error = FT_THROW( Too_Many_Function_Defs ); - return; - } - - rec->range = exc->curRange; - rec->opc = (FT_UInt16)n; - rec->start = exc->IP + 1; - rec->active = TRUE; - rec->inline_delta = FALSE; - rec->sph_fdef_flags = 0x0000; - - if ( n > exc->maxFunc ) - exc->maxFunc = (FT_UInt16)n; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* We don't know for sure these are typeman functions, */ - /* however they are only active when RS 22 is called */ - if ( n >= 64 && n <= 66 ) - rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_STROKES; -#endif - - /* Now skip the whole function definition. */ - /* We don't allow nested IDEFS & FDEFs. */ - - while ( SkipCode( exc ) == SUCCESS ) - { - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - - if ( SUBPIXEL_HINTING_INFINALITY ) - { - for ( i = 0; i < opcode_patterns; i++ ) - { - if ( opcode_pointer[i] < opcode_size[i] && - exc->opcode == opcode_pattern[i][opcode_pointer[i]] ) - { - opcode_pointer[i] += 1; - - if ( opcode_pointer[i] == opcode_size[i] ) - { - FT_TRACE6(( "sph: Function %d, opcode ptrn: %d, %s %s\n", - i, n, - exc->face->root.family_name, - exc->face->root.style_name )); - - switch ( i ) - { - case 0: - rec->sph_fdef_flags |= SPH_FDEF_INLINE_DELTA_1; - exc->face->sph_found_func_flags |= SPH_FDEF_INLINE_DELTA_1; - break; - - case 1: - rec->sph_fdef_flags |= SPH_FDEF_INLINE_DELTA_2; - exc->face->sph_found_func_flags |= SPH_FDEF_INLINE_DELTA_2; - break; - - case 2: - switch ( n ) - { - /* needs to be implemented still */ - case 58: - rec->sph_fdef_flags |= SPH_FDEF_DIAGONAL_STROKE; - exc->face->sph_found_func_flags |= SPH_FDEF_DIAGONAL_STROKE; - } - break; - - case 3: - switch ( n ) - { - case 0: - rec->sph_fdef_flags |= SPH_FDEF_VACUFORM_ROUND_1; - exc->face->sph_found_func_flags |= SPH_FDEF_VACUFORM_ROUND_1; - } - break; - - case 4: - /* probably not necessary to detect anymore */ - rec->sph_fdef_flags |= SPH_FDEF_TTFAUTOHINT_1; - exc->face->sph_found_func_flags |= SPH_FDEF_TTFAUTOHINT_1; - break; - - case 5: - switch ( n ) - { - case 0: - case 1: - case 2: - case 4: - case 7: - case 8: - rec->sph_fdef_flags |= SPH_FDEF_SPACING_1; - exc->face->sph_found_func_flags |= SPH_FDEF_SPACING_1; - } - break; - - case 6: - switch ( n ) - { - case 0: - case 1: - case 2: - case 4: - case 7: - case 8: - rec->sph_fdef_flags |= SPH_FDEF_SPACING_2; - exc->face->sph_found_func_flags |= SPH_FDEF_SPACING_2; - } - break; - - case 7: - rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; - exc->face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; - break; - - case 8: -#if 0 - rec->sph_fdef_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; - exc->face->sph_found_func_flags |= SPH_FDEF_TYPEMAN_DIAGENDCTRL; -#endif - break; - } - opcode_pointer[i] = 0; - } - } - - else - opcode_pointer[i] = 0; - } - - /* Set sph_compatibility_mode only when deltas are detected */ - exc->face->sph_compatibility_mode = - ( ( exc->face->sph_found_func_flags & SPH_FDEF_INLINE_DELTA_1 ) | - ( exc->face->sph_found_func_flags & SPH_FDEF_INLINE_DELTA_2 ) ); - } - -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - switch ( exc->opcode ) - { - case 0x89: /* IDEF */ - case 0x2C: /* FDEF */ - exc->error = FT_THROW( Nested_DEFS ); - return; - - case 0x2D: /* ENDF */ - rec->end = exc->IP; - return; - } - } - } - - - /*************************************************************************/ - /* */ - /* ENDF[]: END Function definition */ - /* Opcode range: 0x2D */ - /* Stack: --> */ - /* */ - static void - Ins_ENDF( TT_ExecContext exc ) - { - TT_CallRec* pRec; - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - exc->sph_in_func_flags = 0x0000; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - if ( exc->callTop <= 0 ) /* We encountered an ENDF without a call */ - { - exc->error = FT_THROW( ENDF_In_Exec_Stream ); - return; - } - - exc->callTop--; - - pRec = &exc->callStack[exc->callTop]; - - pRec->Cur_Count--; - - exc->step_ins = FALSE; - - if ( pRec->Cur_Count > 0 ) - { - exc->callTop++; - exc->IP = pRec->Def->start; - } - else - /* Loop through the current function */ - Ins_Goto_CodeRange( exc, pRec->Caller_Range, pRec->Caller_IP ); - - /* Exit the current call frame. */ - - /* NOTE: If the last instruction of a program is a */ - /* CALL or LOOPCALL, the return address is */ - /* always out of the code range. This is a */ - /* valid address, and it is why we do not test */ - /* the result of Ins_Goto_CodeRange() here! */ - } - - - /*************************************************************************/ - /* */ - /* CALL[]: CALL function */ - /* Opcode range: 0x2B */ - /* Stack: uint32? --> */ - /* */ - static void - Ins_CALL( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong F; - TT_CallRec* pCrec; - TT_DefRecord* def; - - - /* first of all, check the index */ - - F = (FT_ULong)args[0]; - if ( BOUNDSL( F, exc->maxFunc + 1 ) ) - goto Fail; - - /* Except for some old Apple fonts, all functions in a TrueType */ - /* font are defined in increasing order, starting from 0. This */ - /* means that we normally have */ - /* */ - /* exc->maxFunc+1 == exc->numFDefs */ - /* exc->FDefs[n].opc == n for n in 0..exc->maxFunc */ - /* */ - /* If this isn't true, we need to look up the function table. */ - - def = exc->FDefs + F; - if ( exc->maxFunc + 1 != exc->numFDefs || def->opc != F ) - { - /* look up the FDefs table */ - TT_DefRecord* limit; - - - def = exc->FDefs; - limit = def + exc->numFDefs; - - while ( def < limit && def->opc != F ) - def++; - - if ( def == limit ) - goto Fail; - } - - /* check that the function is active */ - if ( !def->active ) - goto Fail; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - ( ( exc->iup_called && - ( exc->sph_tweak_flags & SPH_TWEAK_NO_CALL_AFTER_IUP ) ) || - ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 ) ) ) - goto Fail; - else - exc->sph_in_func_flags = def->sph_fdef_flags; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - /* check the call stack */ - if ( exc->callTop >= exc->callSize ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - pCrec = exc->callStack + exc->callTop; - - pCrec->Caller_Range = exc->curRange; - pCrec->Caller_IP = exc->IP + 1; - pCrec->Cur_Count = 1; - pCrec->Def = def; - - exc->callTop++; - - Ins_Goto_CodeRange( exc, def->range, def->start ); - - exc->step_ins = FALSE; - - return; - - Fail: - exc->error = FT_THROW( Invalid_Reference ); - } - - - /*************************************************************************/ - /* */ - /* LOOPCALL[]: LOOP and CALL function */ - /* Opcode range: 0x2A */ - /* Stack: uint32? Eint16? --> */ - /* */ - static void - Ins_LOOPCALL( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong F; - TT_CallRec* pCrec; - TT_DefRecord* def; - - - /* first of all, check the index */ - F = (FT_ULong)args[1]; - if ( BOUNDSL( F, exc->maxFunc + 1 ) ) - goto Fail; - - /* Except for some old Apple fonts, all functions in a TrueType */ - /* font are defined in increasing order, starting from 0. This */ - /* means that we normally have */ - /* */ - /* exc->maxFunc+1 == exc->numFDefs */ - /* exc->FDefs[n].opc == n for n in 0..exc->maxFunc */ - /* */ - /* If this isn't true, we need to look up the function table. */ - - def = exc->FDefs + F; - if ( exc->maxFunc + 1 != exc->numFDefs || def->opc != F ) - { - /* look up the FDefs table */ - TT_DefRecord* limit; - - - def = exc->FDefs; - limit = def + exc->numFDefs; - - while ( def < limit && def->opc != F ) - def++; - - if ( def == limit ) - goto Fail; - } - - /* check that the function is active */ - if ( !def->active ) - goto Fail; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - ( def->sph_fdef_flags & SPH_FDEF_VACUFORM_ROUND_1 ) ) - goto Fail; - else - exc->sph_in_func_flags = def->sph_fdef_flags; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - /* check stack */ - if ( exc->callTop >= exc->callSize ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - if ( args[0] > 0 ) - { - pCrec = exc->callStack + exc->callTop; - - pCrec->Caller_Range = exc->curRange; - pCrec->Caller_IP = exc->IP + 1; - pCrec->Cur_Count = (FT_Int)args[0]; - pCrec->Def = def; - - exc->callTop++; - - Ins_Goto_CodeRange( exc, def->range, def->start ); - - exc->step_ins = FALSE; - - exc->loopcall_counter += (FT_ULong)args[0]; - if ( exc->loopcall_counter > exc->loopcall_counter_max ) - exc->error = FT_THROW( Execution_Too_Long ); - } - - return; - - Fail: - exc->error = FT_THROW( Invalid_Reference ); - } - - - /*************************************************************************/ - /* */ - /* IDEF[]: Instruction DEFinition */ - /* Opcode range: 0x89 */ - /* Stack: Eint8 --> */ - /* */ - static void - Ins_IDEF( TT_ExecContext exc, - FT_Long* args ) - { - TT_DefRecord* def; - TT_DefRecord* limit; - - - /* we enable IDEF only in `prep' or `fpgm' */ - if ( exc->curRange == tt_coderange_glyph ) - { - exc->error = FT_THROW( DEF_In_Glyf_Bytecode ); - return; - } - - /* First of all, look for the same function in our table */ - - def = exc->IDefs; - limit = def + exc->numIDefs; - - for ( ; def < limit; def++ ) - if ( def->opc == (FT_ULong)args[0] ) - break; - - if ( def == limit ) - { - /* check that there is enough room for a new instruction */ - if ( exc->numIDefs >= exc->maxIDefs ) - { - exc->error = FT_THROW( Too_Many_Instruction_Defs ); - return; - } - exc->numIDefs++; - } - - /* opcode must be unsigned 8-bit integer */ - if ( 0 > args[0] || args[0] > 0x00FF ) - { - exc->error = FT_THROW( Too_Many_Instruction_Defs ); - return; - } - - def->opc = (FT_Byte)args[0]; - def->start = exc->IP + 1; - def->range = exc->curRange; - def->active = TRUE; - - if ( (FT_ULong)args[0] > exc->maxIns ) - exc->maxIns = (FT_Byte)args[0]; - - /* Now skip the whole function definition. */ - /* We don't allow nested IDEFs & FDEFs. */ - - while ( SkipCode( exc ) == SUCCESS ) - { - switch ( exc->opcode ) - { - case 0x89: /* IDEF */ - case 0x2C: /* FDEF */ - exc->error = FT_THROW( Nested_DEFS ); - return; - case 0x2D: /* ENDF */ - def->end = exc->IP; - return; - } - } - } - - - /*************************************************************************/ - /* */ - /* PUSHING DATA ONTO THE INTERPRETER STACK */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* NPUSHB[]: PUSH N Bytes */ - /* Opcode range: 0x40 */ - /* Stack: --> uint32... */ - /* */ - static void - Ins_NPUSHB( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort L, K; - - - L = (FT_UShort)exc->code[exc->IP + 1]; - - if ( BOUNDS( L, exc->stackSize + 1 - exc->top ) ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - for ( K = 1; K <= L; K++ ) - args[K - 1] = exc->code[exc->IP + K + 1]; - - exc->new_top += L; - } - - - /*************************************************************************/ - /* */ - /* NPUSHW[]: PUSH N Words */ - /* Opcode range: 0x41 */ - /* Stack: --> int32... */ - /* */ - static void - Ins_NPUSHW( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort L, K; - - - L = (FT_UShort)exc->code[exc->IP + 1]; - - if ( BOUNDS( L, exc->stackSize + 1 - exc->top ) ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - exc->IP += 2; - - for ( K = 0; K < L; K++ ) - args[K] = GetShortIns( exc ); - - exc->step_ins = FALSE; - exc->new_top += L; - } - - - /*************************************************************************/ - /* */ - /* PUSHB[abc]: PUSH Bytes */ - /* Opcode range: 0xB0-0xB7 */ - /* Stack: --> uint32... */ - /* */ - static void - Ins_PUSHB( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort L, K; - - - L = (FT_UShort)( exc->opcode - 0xB0 + 1 ); - - if ( BOUNDS( L, exc->stackSize + 1 - exc->top ) ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - for ( K = 1; K <= L; K++ ) - args[K - 1] = exc->code[exc->IP + K]; - } - - - /*************************************************************************/ - /* */ - /* PUSHW[abc]: PUSH Words */ - /* Opcode range: 0xB8-0xBF */ - /* Stack: --> int32... */ - /* */ - static void - Ins_PUSHW( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort L, K; - - - L = (FT_UShort)( exc->opcode - 0xB8 + 1 ); - - if ( BOUNDS( L, exc->stackSize + 1 - exc->top ) ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - exc->IP++; - - for ( K = 0; K < L; K++ ) - args[K] = GetShortIns( exc ); - - exc->step_ins = FALSE; - } - - - /*************************************************************************/ - /* */ - /* MANAGING THE GRAPHICS STATE */ - /* */ - /*************************************************************************/ - - - static FT_Bool - Ins_SxVTL( TT_ExecContext exc, - FT_UShort aIdx1, - FT_UShort aIdx2, - FT_UnitVector* Vec ) - { - FT_Long A, B, C; - FT_Vector* p1; - FT_Vector* p2; - - FT_Byte opcode = exc->opcode; - - - if ( BOUNDS( aIdx1, exc->zp2.n_points ) || - BOUNDS( aIdx2, exc->zp1.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return FAILURE; - } - - p1 = exc->zp1.cur + aIdx2; - p2 = exc->zp2.cur + aIdx1; - - A = p1->x - p2->x; - B = p1->y - p2->y; - - /* If p1 == p2, SPvTL and SFvTL behave the same as */ - /* SPvTCA[X] and SFvTCA[X], respectively. */ - /* */ - /* Confirmed by Greg Hitchcock. */ - - if ( A == 0 && B == 0 ) - { - A = 0x4000; - opcode = 0; - } - - if ( ( opcode & 1 ) != 0 ) - { - C = B; /* counter clockwise rotation */ - B = A; - A = -C; - } - - Normalize( A, B, Vec ); - - return SUCCESS; - } - - - /*************************************************************************/ - /* */ - /* SVTCA[a]: Set (F and P) Vectors to Coordinate Axis */ - /* Opcode range: 0x00-0x01 */ - /* Stack: --> */ - /* */ - /* SPvTCA[a]: Set PVector to Coordinate Axis */ - /* Opcode range: 0x02-0x03 */ - /* Stack: --> */ - /* */ - /* SFvTCA[a]: Set FVector to Coordinate Axis */ - /* Opcode range: 0x04-0x05 */ - /* Stack: --> */ - /* */ - static void - Ins_SxyTCA( TT_ExecContext exc ) - { - FT_Short AA, BB; - - FT_Byte opcode = exc->opcode; - - - AA = (FT_Short)( ( opcode & 1 ) << 14 ); - BB = (FT_Short)( AA ^ 0x4000 ); - - if ( opcode < 4 ) - { - exc->GS.projVector.x = AA; - exc->GS.projVector.y = BB; - - exc->GS.dualVector.x = AA; - exc->GS.dualVector.y = BB; - } - - if ( ( opcode & 2 ) == 0 ) - { - exc->GS.freeVector.x = AA; - exc->GS.freeVector.y = BB; - } - - Compute_Funcs( exc ); - } - - - /*************************************************************************/ - /* */ - /* SPvTL[a]: Set PVector To Line */ - /* Opcode range: 0x06-0x07 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_SPVTL( TT_ExecContext exc, - FT_Long* args ) - { - if ( Ins_SxVTL( exc, - (FT_UShort)args[1], - (FT_UShort)args[0], - &exc->GS.projVector ) == SUCCESS ) - { - exc->GS.dualVector = exc->GS.projVector; - Compute_Funcs( exc ); - } - } - - - /*************************************************************************/ - /* */ - /* SFvTL[a]: Set FVector To Line */ - /* Opcode range: 0x08-0x09 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_SFVTL( TT_ExecContext exc, - FT_Long* args ) - { - if ( Ins_SxVTL( exc, - (FT_UShort)args[1], - (FT_UShort)args[0], - &exc->GS.freeVector ) == SUCCESS ) - { - Compute_Funcs( exc ); - } - } - - - /*************************************************************************/ - /* */ - /* SFvTPv[]: Set FVector To PVector */ - /* Opcode range: 0x0E */ - /* Stack: --> */ - /* */ - static void - Ins_SFVTPV( TT_ExecContext exc ) - { - exc->GS.freeVector = exc->GS.projVector; - Compute_Funcs( exc ); - } - - - /*************************************************************************/ - /* */ - /* SPvFS[]: Set PVector From Stack */ - /* Opcode range: 0x0A */ - /* Stack: f2.14 f2.14 --> */ - /* */ - static void - Ins_SPVFS( TT_ExecContext exc, - FT_Long* args ) - { - FT_Short S; - FT_Long X, Y; - - - /* Only use low 16bits, then sign extend */ - S = (FT_Short)args[1]; - Y = (FT_Long)S; - S = (FT_Short)args[0]; - X = (FT_Long)S; - - Normalize( X, Y, &exc->GS.projVector ); - - exc->GS.dualVector = exc->GS.projVector; - Compute_Funcs( exc ); - } - - - /*************************************************************************/ - /* */ - /* SFvFS[]: Set FVector From Stack */ - /* Opcode range: 0x0B */ - /* Stack: f2.14 f2.14 --> */ - /* */ - static void - Ins_SFVFS( TT_ExecContext exc, - FT_Long* args ) - { - FT_Short S; - FT_Long X, Y; - - - /* Only use low 16bits, then sign extend */ - S = (FT_Short)args[1]; - Y = (FT_Long)S; - S = (FT_Short)args[0]; - X = S; - - Normalize( X, Y, &exc->GS.freeVector ); - Compute_Funcs( exc ); - } - - - /*************************************************************************/ - /* */ - /* GPv[]: Get Projection Vector */ - /* Opcode range: 0x0C */ - /* Stack: ef2.14 --> ef2.14 */ - /* */ - static void - Ins_GPV( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = exc->GS.projVector.x; - args[1] = exc->GS.projVector.y; - } - - - /*************************************************************************/ - /* */ - /* GFv[]: Get Freedom Vector */ - /* Opcode range: 0x0D */ - /* Stack: ef2.14 --> ef2.14 */ - /* */ - static void - Ins_GFV( TT_ExecContext exc, - FT_Long* args ) - { - args[0] = exc->GS.freeVector.x; - args[1] = exc->GS.freeVector.y; - } - - - /*************************************************************************/ - /* */ - /* SRP0[]: Set Reference Point 0 */ - /* Opcode range: 0x10 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SRP0( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.rp0 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SRP1[]: Set Reference Point 1 */ - /* Opcode range: 0x11 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SRP1( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.rp1 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SRP2[]: Set Reference Point 2 */ - /* Opcode range: 0x12 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SRP2( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.rp2 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SMD[]: Set Minimum Distance */ - /* Opcode range: 0x1A */ - /* Stack: f26.6 --> */ - /* */ - static void - Ins_SMD( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.minimum_distance = args[0]; - } - - - /*************************************************************************/ - /* */ - /* SCVTCI[]: Set Control Value Table Cut In */ - /* Opcode range: 0x1D */ - /* Stack: f26.6 --> */ - /* */ - static void - Ins_SCVTCI( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.control_value_cutin = (FT_F26Dot6)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SSWCI[]: Set Single Width Cut In */ - /* Opcode range: 0x1E */ - /* Stack: f26.6 --> */ - /* */ - static void - Ins_SSWCI( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.single_width_cutin = (FT_F26Dot6)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SSW[]: Set Single Width */ - /* Opcode range: 0x1F */ - /* Stack: int32? --> */ - /* */ - static void - Ins_SSW( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.single_width_value = FT_MulFix( args[0], - exc->tt_metrics.scale ); - } - - - /*************************************************************************/ - /* */ - /* FLIPON[]: Set auto-FLIP to ON */ - /* Opcode range: 0x4D */ - /* Stack: --> */ - /* */ - static void - Ins_FLIPON( TT_ExecContext exc ) - { - exc->GS.auto_flip = TRUE; - } - - - /*************************************************************************/ - /* */ - /* FLIPOFF[]: Set auto-FLIP to OFF */ - /* Opcode range: 0x4E */ - /* Stack: --> */ - /* */ - static void - Ins_FLIPOFF( TT_ExecContext exc ) - { - exc->GS.auto_flip = FALSE; - } - - - /*************************************************************************/ - /* */ - /* SANGW[]: Set ANGle Weight */ - /* Opcode range: 0x7E */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SANGW( void ) - { - /* instruction not supported anymore */ - } - - - /*************************************************************************/ - /* */ - /* SDB[]: Set Delta Base */ - /* Opcode range: 0x5E */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SDB( TT_ExecContext exc, - FT_Long* args ) - { - exc->GS.delta_base = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SDS[]: Set Delta Shift */ - /* Opcode range: 0x5F */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SDS( TT_ExecContext exc, - FT_Long* args ) - { - if ( (FT_ULong)args[0] > 6UL ) - exc->error = FT_THROW( Bad_Argument ); - else - exc->GS.delta_shift = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* RTHG[]: Round To Half Grid */ - /* Opcode range: 0x19 */ - /* Stack: --> */ - /* */ - static void - Ins_RTHG( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_To_Half_Grid; - exc->func_round = (TT_Round_Func)Round_To_Half_Grid; - } - - - /*************************************************************************/ - /* */ - /* RTG[]: Round To Grid */ - /* Opcode range: 0x18 */ - /* Stack: --> */ - /* */ - static void - Ins_RTG( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_To_Grid; - exc->func_round = (TT_Round_Func)Round_To_Grid; - } - - - /*************************************************************************/ - /* RTDG[]: Round To Double Grid */ - /* Opcode range: 0x3D */ - /* Stack: --> */ - /* */ - static void - Ins_RTDG( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_To_Double_Grid; - exc->func_round = (TT_Round_Func)Round_To_Double_Grid; - } - - - /*************************************************************************/ - /* RUTG[]: Round Up To Grid */ - /* Opcode range: 0x7C */ - /* Stack: --> */ - /* */ - static void - Ins_RUTG( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_Up_To_Grid; - exc->func_round = (TT_Round_Func)Round_Up_To_Grid; - } - - - /*************************************************************************/ - /* */ - /* RDTG[]: Round Down To Grid */ - /* Opcode range: 0x7D */ - /* Stack: --> */ - /* */ - static void - Ins_RDTG( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_Down_To_Grid; - exc->func_round = (TT_Round_Func)Round_Down_To_Grid; - } - - - /*************************************************************************/ - /* */ - /* ROFF[]: Round OFF */ - /* Opcode range: 0x7A */ - /* Stack: --> */ - /* */ - static void - Ins_ROFF( TT_ExecContext exc ) - { - exc->GS.round_state = TT_Round_Off; - exc->func_round = (TT_Round_Func)Round_None; - } - - - /*************************************************************************/ - /* */ - /* SROUND[]: Super ROUND */ - /* Opcode range: 0x76 */ - /* Stack: Eint8 --> */ - /* */ - static void - Ins_SROUND( TT_ExecContext exc, - FT_Long* args ) - { - SetSuperRound( exc, 0x4000, args[0] ); - - exc->GS.round_state = TT_Round_Super; - exc->func_round = (TT_Round_Func)Round_Super; - } - - - /*************************************************************************/ - /* */ - /* S45ROUND[]: Super ROUND 45 degrees */ - /* Opcode range: 0x77 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_S45ROUND( TT_ExecContext exc, - FT_Long* args ) - { - SetSuperRound( exc, 0x2D41, args[0] ); - - exc->GS.round_state = TT_Round_Super_45; - exc->func_round = (TT_Round_Func)Round_Super_45; - } - - - /*************************************************************************/ - /* */ - /* GC[a]: Get Coordinate projected onto */ - /* Opcode range: 0x46-0x47 */ - /* Stack: uint32 --> f26.6 */ - /* */ - /* XXX: UNDOCUMENTED: Measures from the original glyph must be taken */ - /* along the dual projection vector! */ - /* */ - static void - Ins_GC( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong L; - FT_F26Dot6 R; - - - L = (FT_ULong)args[0]; - - if ( BOUNDSL( L, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - R = 0; - } - else - { - if ( exc->opcode & 1 ) - R = FAST_DUALPROJ( &exc->zp2.org[L] ); - else - R = FAST_PROJECT( &exc->zp2.cur[L] ); - } - - args[0] = R; - } - - - /*************************************************************************/ - /* */ - /* SCFS[]: Set Coordinate From Stack */ - /* Opcode range: 0x48 */ - /* Stack: f26.6 uint32 --> */ - /* */ - /* Formula: */ - /* */ - /* OA := OA + ( value - OA.p )/( f.p ) * f */ - /* */ - static void - Ins_SCFS( TT_ExecContext exc, - FT_Long* args ) - { - FT_Long K; - FT_UShort L; - - - L = (FT_UShort)args[0]; - - if ( BOUNDS( L, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - K = FAST_PROJECT( &exc->zp2.cur[L] ); - - exc->func_move( exc, &exc->zp2, L, args[1] - K ); - - /* UNDOCUMENTED! The MS rasterizer does that with */ - /* twilight points (confirmed by Greg Hitchcock) */ - if ( exc->GS.gep2 == 0 ) - exc->zp2.org[L] = exc->zp2.cur[L]; - } - - - /*************************************************************************/ - /* */ - /* MD[a]: Measure Distance */ - /* Opcode range: 0x49-0x4A */ - /* Stack: uint32 uint32 --> f26.6 */ - /* */ - /* XXX: UNDOCUMENTED: Measure taken in the original glyph must be along */ - /* the dual projection vector. */ - /* */ - /* XXX: UNDOCUMENTED: Flag attributes are inverted! */ - /* 0 => measure distance in original outline */ - /* 1 => measure distance in grid-fitted outline */ - /* */ - /* XXX: UNDOCUMENTED: `zp0 - zp1', and not `zp2 - zp1! */ - /* */ - static void - Ins_MD( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort K, L; - FT_F26Dot6 D; - - - K = (FT_UShort)args[1]; - L = (FT_UShort)args[0]; - - if ( BOUNDS( L, exc->zp0.n_points ) || - BOUNDS( K, exc->zp1.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - D = 0; - } - else - { - if ( exc->opcode & 1 ) - D = PROJECT( exc->zp0.cur + L, exc->zp1.cur + K ); - else - { - /* XXX: UNDOCUMENTED: twilight zone special case */ - - if ( exc->GS.gep0 == 0 || exc->GS.gep1 == 0 ) - { - FT_Vector* vec1 = exc->zp0.org + L; - FT_Vector* vec2 = exc->zp1.org + K; - - - D = DUALPROJ( vec1, vec2 ); - } - else - { - FT_Vector* vec1 = exc->zp0.orus + L; - FT_Vector* vec2 = exc->zp1.orus + K; - - - if ( exc->metrics.x_scale == exc->metrics.y_scale ) - { - /* this should be faster */ - D = DUALPROJ( vec1, vec2 ); - D = FT_MulFix( D, exc->metrics.x_scale ); - } - else - { - FT_Vector vec; - - - vec.x = FT_MulFix( vec1->x - vec2->x, exc->metrics.x_scale ); - vec.y = FT_MulFix( vec1->y - vec2->y, exc->metrics.y_scale ); - - D = FAST_DUALPROJ( &vec ); - } - } - } - } - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* Disable Type 2 Vacuform Rounds - e.g. Arial Narrow */ - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - FT_ABS( D ) == 64 ) - D += 1; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - args[0] = D; - } - - - /*************************************************************************/ - /* */ - /* SDPvTL[a]: Set Dual PVector to Line */ - /* Opcode range: 0x86-0x87 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_SDPVTL( TT_ExecContext exc, - FT_Long* args ) - { - FT_Long A, B, C; - FT_UShort p1, p2; /* was FT_Int in pas type ERROR */ - - FT_Byte opcode = exc->opcode; - - - p1 = (FT_UShort)args[1]; - p2 = (FT_UShort)args[0]; - - if ( BOUNDS( p2, exc->zp1.n_points ) || - BOUNDS( p1, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - { - FT_Vector* v1 = exc->zp1.org + p2; - FT_Vector* v2 = exc->zp2.org + p1; - - - A = v1->x - v2->x; - B = v1->y - v2->y; - - /* If v1 == v2, SDPvTL behaves the same as */ - /* SVTCA[X], respectively. */ - /* */ - /* Confirmed by Greg Hitchcock. */ - - if ( A == 0 && B == 0 ) - { - A = 0x4000; - opcode = 0; - } - } - - if ( ( opcode & 1 ) != 0 ) - { - C = B; /* counter clockwise rotation */ - B = A; - A = -C; - } - - Normalize( A, B, &exc->GS.dualVector ); - - { - FT_Vector* v1 = exc->zp1.cur + p2; - FT_Vector* v2 = exc->zp2.cur + p1; - - - A = v1->x - v2->x; - B = v1->y - v2->y; - - if ( A == 0 && B == 0 ) - { - A = 0x4000; - opcode = 0; - } - } - - if ( ( opcode & 1 ) != 0 ) - { - C = B; /* counter clockwise rotation */ - B = A; - A = -C; - } - - Normalize( A, B, &exc->GS.projVector ); - Compute_Funcs( exc ); - } - - - /*************************************************************************/ - /* */ - /* SZP0[]: Set Zone Pointer 0 */ - /* Opcode range: 0x13 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SZP0( TT_ExecContext exc, - FT_Long* args ) - { - switch ( (FT_Int)args[0] ) - { - case 0: - exc->zp0 = exc->twilight; - break; - - case 1: - exc->zp0 = exc->pts; - break; - - default: - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - exc->GS.gep0 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SZP1[]: Set Zone Pointer 1 */ - /* Opcode range: 0x14 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SZP1( TT_ExecContext exc, - FT_Long* args ) - { - switch ( (FT_Int)args[0] ) - { - case 0: - exc->zp1 = exc->twilight; - break; - - case 1: - exc->zp1 = exc->pts; - break; - - default: - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - exc->GS.gep1 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SZP2[]: Set Zone Pointer 2 */ - /* Opcode range: 0x15 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SZP2( TT_ExecContext exc, - FT_Long* args ) - { - switch ( (FT_Int)args[0] ) - { - case 0: - exc->zp2 = exc->twilight; - break; - - case 1: - exc->zp2 = exc->pts; - break; - - default: - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - exc->GS.gep2 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* SZPS[]: Set Zone PointerS */ - /* Opcode range: 0x16 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SZPS( TT_ExecContext exc, - FT_Long* args ) - { - switch ( (FT_Int)args[0] ) - { - case 0: - exc->zp0 = exc->twilight; - break; - - case 1: - exc->zp0 = exc->pts; - break; - - default: - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - exc->zp1 = exc->zp0; - exc->zp2 = exc->zp0; - - exc->GS.gep0 = (FT_UShort)args[0]; - exc->GS.gep1 = (FT_UShort)args[0]; - exc->GS.gep2 = (FT_UShort)args[0]; - } - - - /*************************************************************************/ - /* */ - /* INSTCTRL[]: INSTruction ConTRoL */ - /* Opcode range: 0x8E */ - /* Stack: int32 int32 --> */ - /* */ - static void - Ins_INSTCTRL( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong K, L, Kf; - - - K = (FT_ULong)args[1]; - L = (FT_ULong)args[0]; - - /* selector values cannot be `OR'ed; */ - /* they are indices starting with index 1, not flags */ - if ( K < 1 || K > 3 ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - /* convert index to flag value */ - Kf = 1 << ( K - 1 ); - - if ( L != 0 ) - { - /* arguments to selectors look like flag values */ - if ( L != Kf ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - - exc->GS.instruct_control &= ~(FT_Byte)Kf; - exc->GS.instruct_control |= (FT_Byte)L; - - if ( K == 3 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* INSTCTRL modifying flag 3 also has an effect */ - /* outside of the CVT program */ - if ( SUBPIXEL_HINTING_INFINALITY ) - exc->ignore_x_mode = FT_BOOL( L == 4 ); -#endif - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* Native ClearType fonts sign a waiver that turns off all backward */ - /* compatibility hacks and lets them program points to the grid like */ - /* it's 1996. They might sign a waiver for just one glyph, though. */ - if ( SUBPIXEL_HINTING_MINIMAL ) - exc->backward_compatibility = !FT_BOOL( L == 4 ); -#endif - } - } - - - /*************************************************************************/ - /* */ - /* SCANCTRL[]: SCAN ConTRoL */ - /* Opcode range: 0x85 */ - /* Stack: uint32? --> */ - /* */ - static void - Ins_SCANCTRL( TT_ExecContext exc, - FT_Long* args ) - { - FT_Int A; - - - /* Get Threshold */ - A = (FT_Int)( args[0] & 0xFF ); - - if ( A == 0xFF ) - { - exc->GS.scan_control = TRUE; - return; - } - else if ( A == 0 ) - { - exc->GS.scan_control = FALSE; - return; - } - - if ( ( args[0] & 0x100 ) != 0 && exc->tt_metrics.ppem <= A ) - exc->GS.scan_control = TRUE; - - if ( ( args[0] & 0x200 ) != 0 && exc->tt_metrics.rotated ) - exc->GS.scan_control = TRUE; - - if ( ( args[0] & 0x400 ) != 0 && exc->tt_metrics.stretched ) - exc->GS.scan_control = TRUE; - - if ( ( args[0] & 0x800 ) != 0 && exc->tt_metrics.ppem > A ) - exc->GS.scan_control = FALSE; - - if ( ( args[0] & 0x1000 ) != 0 && exc->tt_metrics.rotated ) - exc->GS.scan_control = FALSE; - - if ( ( args[0] & 0x2000 ) != 0 && exc->tt_metrics.stretched ) - exc->GS.scan_control = FALSE; - } - - - /*************************************************************************/ - /* */ - /* SCANTYPE[]: SCAN TYPE */ - /* Opcode range: 0x8D */ - /* Stack: uint16 --> */ - /* */ - static void - Ins_SCANTYPE( TT_ExecContext exc, - FT_Long* args ) - { - if ( args[0] >= 0 ) - exc->GS.scan_type = (FT_Int)args[0] & 0xFFFF; - } - - - /*************************************************************************/ - /* */ - /* MANAGING OUTLINES */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* FLIPPT[]: FLIP PoinT */ - /* Opcode range: 0x80 */ - /* Stack: uint32... --> */ - /* */ - static void - Ins_FLIPPT( TT_ExecContext exc ) - { - FT_UShort point; - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* See `ttinterp.h' for details on backward compatibility mode. */ - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && - exc->iupy_called ) - goto Fail; -#endif - - if ( exc->top < exc->GS.loop ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Too_Few_Arguments ); - goto Fail; - } - - while ( exc->GS.loop > 0 ) - { - exc->args--; - - point = (FT_UShort)exc->stack[exc->args]; - - if ( BOUNDS( point, exc->pts.n_points ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - else - exc->pts.tags[point] ^= FT_CURVE_TAG_ON; - - exc->GS.loop--; - } - - Fail: - exc->GS.loop = 1; - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* FLIPRGON[]: FLIP RanGe ON */ - /* Opcode range: 0x81 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_FLIPRGON( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort I, K, L; - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* See `ttinterp.h' for details on backward compatibility mode. */ - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && - exc->iupy_called ) - return; -#endif - - K = (FT_UShort)args[1]; - L = (FT_UShort)args[0]; - - if ( BOUNDS( K, exc->pts.n_points ) || - BOUNDS( L, exc->pts.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - for ( I = L; I <= K; I++ ) - exc->pts.tags[I] |= FT_CURVE_TAG_ON; - } - - - /*************************************************************************/ - /* */ - /* FLIPRGOFF: FLIP RanGe OFF */ - /* Opcode range: 0x82 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_FLIPRGOFF( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort I, K, L; - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* See `ttinterp.h' for details on backward compatibility mode. */ - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && - exc->iupy_called ) - return; -#endif - - K = (FT_UShort)args[1]; - L = (FT_UShort)args[0]; - - if ( BOUNDS( K, exc->pts.n_points ) || - BOUNDS( L, exc->pts.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - for ( I = L; I <= K; I++ ) - exc->pts.tags[I] &= ~FT_CURVE_TAG_ON; - } - - - static FT_Bool - Compute_Point_Displacement( TT_ExecContext exc, - FT_F26Dot6* x, - FT_F26Dot6* y, - TT_GlyphZone zone, - FT_UShort* refp ) - { - TT_GlyphZoneRec zp; - FT_UShort p; - FT_F26Dot6 d; - - - if ( exc->opcode & 1 ) - { - zp = exc->zp0; - p = exc->GS.rp1; - } - else - { - zp = exc->zp1; - p = exc->GS.rp2; - } - - if ( BOUNDS( p, zp.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - *refp = 0; - return FAILURE; - } - - *zone = zp; - *refp = p; - - d = PROJECT( zp.cur + p, zp.org + p ); - - *x = FT_MulDiv( d, (FT_Long)exc->GS.freeVector.x, exc->F_dot_P ); - *y = FT_MulDiv( d, (FT_Long)exc->GS.freeVector.y, exc->F_dot_P ); - - return SUCCESS; - } - - - /* See `ttinterp.h' for details on backward compatibility mode. */ - static void - Move_Zp2_Point( TT_ExecContext exc, - FT_UShort point, - FT_F26Dot6 dx, - FT_F26Dot6 dy, - FT_Bool touch ) - { - if ( exc->GS.freeVector.x != 0 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( !( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility ) ) -#endif - exc->zp2.cur[point].x += dx; - - if ( touch ) - exc->zp2.tags[point] |= FT_CURVE_TAG_TOUCH_X; - } - - if ( exc->GS.freeVector.y != 0 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( !( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility && - exc->iupx_called && - exc->iupy_called ) ) -#endif - exc->zp2.cur[point].y += dy; - - if ( touch ) - exc->zp2.tags[point] |= FT_CURVE_TAG_TOUCH_Y; - } - } - - - /*************************************************************************/ - /* */ - /* SHP[a]: SHift Point by the last point */ - /* Opcode range: 0x32-0x33 */ - /* Stack: uint32... --> */ - /* */ - static void - Ins_SHP( TT_ExecContext exc ) - { - TT_GlyphZoneRec zp; - FT_UShort refp; - - FT_F26Dot6 dx, dy; - FT_UShort point; - - - if ( exc->top < exc->GS.loop ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - if ( Compute_Point_Displacement( exc, &dx, &dy, &zp, &refp ) ) - return; - - while ( exc->GS.loop > 0 ) - { - exc->args--; - point = (FT_UShort)exc->stack[exc->args]; - - if ( BOUNDS( point, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - else -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* doesn't follow Cleartype spec but produces better result */ - if ( SUBPIXEL_HINTING_INFINALITY && exc->ignore_x_mode ) - Move_Zp2_Point( exc, point, 0, dy, TRUE ); - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - Move_Zp2_Point( exc, point, dx, dy, TRUE ); - - exc->GS.loop--; - } - - Fail: - exc->GS.loop = 1; - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* SHC[a]: SHift Contour */ - /* Opcode range: 0x34-35 */ - /* Stack: uint32 --> */ - /* */ - /* UNDOCUMENTED: According to Greg Hitchcock, there is one (virtual) */ - /* contour in the twilight zone, namely contour number */ - /* zero which includes all points of it. */ - /* */ - static void - Ins_SHC( TT_ExecContext exc, - FT_Long* args ) - { - TT_GlyphZoneRec zp; - FT_UShort refp; - FT_F26Dot6 dx, dy; - - FT_Short contour, bounds; - FT_UShort start, limit, i; - - - contour = (FT_Short)args[0]; - bounds = ( exc->GS.gep2 == 0 ) ? 1 : exc->zp2.n_contours; - - if ( BOUNDS( contour, bounds ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - if ( Compute_Point_Displacement( exc, &dx, &dy, &zp, &refp ) ) - return; - - if ( contour == 0 ) - start = 0; - else - start = (FT_UShort)( exc->zp2.contours[contour - 1] + 1 - - exc->zp2.first_point ); - - /* we use the number of points if in the twilight zone */ - if ( exc->GS.gep2 == 0 ) - limit = exc->zp2.n_points; - else - limit = (FT_UShort)( exc->zp2.contours[contour] - - exc->zp2.first_point + 1 ); - - for ( i = start; i < limit; i++ ) - { - if ( zp.cur != exc->zp2.cur || refp != i ) - Move_Zp2_Point( exc, i, dx, dy, TRUE ); - } - } - - - /*************************************************************************/ - /* */ - /* SHZ[a]: SHift Zone */ - /* Opcode range: 0x36-37 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_SHZ( TT_ExecContext exc, - FT_Long* args ) - { - TT_GlyphZoneRec zp; - FT_UShort refp; - FT_F26Dot6 dx, - dy; - - FT_UShort limit, i; - - - if ( BOUNDS( args[0], 2 ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - if ( Compute_Point_Displacement( exc, &dx, &dy, &zp, &refp ) ) - return; - - /* XXX: UNDOCUMENTED! SHZ doesn't move the phantom points. */ - /* Twilight zone has no real contours, so use `n_points'. */ - /* Normal zone's `n_points' includes phantoms, so must */ - /* use end of last contour. */ - if ( exc->GS.gep2 == 0 ) - limit = (FT_UShort)exc->zp2.n_points; - else if ( exc->GS.gep2 == 1 && exc->zp2.n_contours > 0 ) - limit = (FT_UShort)( exc->zp2.contours[exc->zp2.n_contours - 1] + 1 ); - else - limit = 0; - - /* XXX: UNDOCUMENTED! SHZ doesn't touch the points */ - for ( i = 0; i < limit; i++ ) - { - if ( zp.cur != exc->zp2.cur || refp != i ) - Move_Zp2_Point( exc, i, dx, dy, FALSE ); - } - } - - - /*************************************************************************/ - /* */ - /* SHPIX[]: SHift points by a PIXel amount */ - /* Opcode range: 0x38 */ - /* Stack: f26.6 uint32... --> */ - /* */ - static void - Ins_SHPIX( TT_ExecContext exc, - FT_Long* args ) - { - FT_F26Dot6 dx, dy; - FT_UShort point; -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - FT_Int B1, B2; -#endif -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - FT_Bool in_twilight = FT_BOOL( exc->GS.gep0 == 0 || - exc->GS.gep1 == 0 || - exc->GS.gep2 == 0 ); -#endif - - - - if ( exc->top < exc->GS.loop + 1 ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - dx = TT_MulFix14( args[0], exc->GS.freeVector.x ); - dy = TT_MulFix14( args[0], exc->GS.freeVector.y ); - - while ( exc->GS.loop > 0 ) - { - exc->args--; - - point = (FT_UShort)exc->stack[exc->args]; - - if ( BOUNDS( point, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - else -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY ) - { - /* If not using ignore_x_mode rendering, allow ZP2 move. */ - /* If inline deltas aren't allowed, skip ZP2 move. */ - /* If using ignore_x_mode rendering, allow ZP2 point move if: */ - /* - freedom vector is y and sph_compatibility_mode is off */ - /* - the glyph is composite and the move is in the Y direction */ - /* - the glyph is specifically set to allow SHPIX moves */ - /* - the move is on a previously Y-touched point */ - - if ( exc->ignore_x_mode ) - { - /* save point for later comparison */ - if ( exc->GS.freeVector.y != 0 ) - B1 = exc->zp2.cur[point].y; - else - B1 = exc->zp2.cur[point].x; - - if ( !exc->face->sph_compatibility_mode && - exc->GS.freeVector.y != 0 ) - { - Move_Zp2_Point( exc, point, dx, dy, TRUE ); - - /* save new point */ - if ( exc->GS.freeVector.y != 0 ) - { - B2 = exc->zp2.cur[point].y; - - /* reverse any disallowed moves */ - if ( ( exc->sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) && - ( B1 & 63 ) != 0 && - ( B2 & 63 ) != 0 && - B1 != B2 ) - Move_Zp2_Point( exc, point, -dx, -dy, TRUE ); - } - } - else if ( exc->face->sph_compatibility_mode ) - { - if ( exc->sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) - { - dx = FT_PIX_ROUND( B1 + dx ) - B1; - dy = FT_PIX_ROUND( B1 + dy ) - B1; - } - - /* skip post-iup deltas */ - if ( exc->iup_called && - ( ( exc->sph_in_func_flags & SPH_FDEF_INLINE_DELTA_1 ) || - ( exc->sph_in_func_flags & SPH_FDEF_INLINE_DELTA_2 ) ) ) - goto Skip; - - if ( !( exc->sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) && - ( ( exc->is_composite && exc->GS.freeVector.y != 0 ) || - ( exc->zp2.tags[point] & FT_CURVE_TAG_TOUCH_Y ) || - ( exc->sph_tweak_flags & SPH_TWEAK_DO_SHPIX ) ) ) - Move_Zp2_Point( exc, point, 0, dy, TRUE ); - - /* save new point */ - if ( exc->GS.freeVector.y != 0 ) - { - B2 = exc->zp2.cur[point].y; - - /* reverse any disallowed moves */ - if ( ( B1 & 63 ) == 0 && - ( B2 & 63 ) != 0 && - B1 != B2 ) - Move_Zp2_Point( exc, point, 0, -dy, TRUE ); - } - } - else if ( exc->sph_in_func_flags & SPH_FDEF_TYPEMAN_DIAGENDCTRL ) - Move_Zp2_Point( exc, point, dx, dy, TRUE ); - } - else - Move_Zp2_Point( exc, point, dx, dy, TRUE ); - } - else -#endif -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility ) - { - /* Special case: allow SHPIX to move points in the twilight zone. */ - /* Otherwise, treat SHPIX the same as DELTAP. Unbreaks various */ - /* fonts such as older versions of Rokkitt and DTL Argo T Light */ - /* that would glitch severely after calling ALIGNRP after a */ - /* blocked SHPIX. */ - if ( in_twilight || - ( !( exc->iupx_called && exc->iupy_called ) && - ( ( exc->is_composite && exc->GS.freeVector.y != 0 ) || - ( exc->zp2.tags[point] & FT_CURVE_TAG_TOUCH_Y ) ) ) ) - Move_Zp2_Point( exc, point, 0, dy, TRUE ); - } - else -#endif - Move_Zp2_Point( exc, point, dx, dy, TRUE ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - Skip: -#endif - exc->GS.loop--; - } - - Fail: - exc->GS.loop = 1; - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* MSIRP[a]: Move Stack Indirect Relative Position */ - /* Opcode range: 0x3A-0x3B */ - /* Stack: f26.6 uint32 --> */ - /* */ - static void - Ins_MSIRP( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point = 0; - FT_F26Dot6 distance; -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - FT_F26Dot6 control_value_cutin = 0; - - - if ( SUBPIXEL_HINTING_INFINALITY ) - { - control_value_cutin = exc->GS.control_value_cutin; - - if ( exc->ignore_x_mode && - exc->GS.freeVector.x != 0 && - !( exc->sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) - control_value_cutin = 0; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - point = (FT_UShort)args[0]; - - if ( BOUNDS( point, exc->zp1.n_points ) || - BOUNDS( exc->GS.rp0, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - /* UNDOCUMENTED! The MS rasterizer does that with */ - /* twilight points (confirmed by Greg Hitchcock) */ - if ( exc->GS.gep1 == 0 ) - { - exc->zp1.org[point] = exc->zp0.org[exc->GS.rp0]; - exc->func_move_orig( exc, &exc->zp1, point, args[1] ); - exc->zp1.cur[point] = exc->zp1.org[point]; - } - - distance = PROJECT( exc->zp1.cur + point, exc->zp0.cur + exc->GS.rp0 ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* subpixel hinting - make MSIRP respect CVT cut-in; */ - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 && - FT_ABS( distance - args[1] ) >= control_value_cutin ) - distance = args[1]; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - exc->func_move( exc, &exc->zp1, point, args[1] - distance ); - - exc->GS.rp1 = exc->GS.rp0; - exc->GS.rp2 = point; - - if ( ( exc->opcode & 1 ) != 0 ) - exc->GS.rp0 = point; - } - - - /*************************************************************************/ - /* */ - /* MDAP[a]: Move Direct Absolute Point */ - /* Opcode range: 0x2E-0x2F */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_MDAP( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point; - FT_F26Dot6 cur_dist; - FT_F26Dot6 distance; - - - point = (FT_UShort)args[0]; - - if ( BOUNDS( point, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - if ( ( exc->opcode & 1 ) != 0 ) - { - cur_dist = FAST_PROJECT( &exc->zp0.cur[point] ); -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 ) - distance = Round_None( - exc, - cur_dist, - exc->tt_metrics.compensations[0] ) - cur_dist; - else -#endif - distance = exc->func_round( - exc, - cur_dist, - exc->tt_metrics.compensations[0] ) - cur_dist; - } - else - distance = 0; - - exc->func_move( exc, &exc->zp0, point, distance ); - - exc->GS.rp0 = point; - exc->GS.rp1 = point; - } - - - /*************************************************************************/ - /* */ - /* MIAP[a]: Move Indirect Absolute Point */ - /* Opcode range: 0x3E-0x3F */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_MIAP( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong cvtEntry; - FT_UShort point; - FT_F26Dot6 distance; - FT_F26Dot6 org_dist; - FT_F26Dot6 control_value_cutin; - - - control_value_cutin = exc->GS.control_value_cutin; - cvtEntry = (FT_ULong)args[1]; - point = (FT_UShort)args[0]; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 && - exc->GS.freeVector.y == 0 && - !( exc->sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) - control_value_cutin = 0; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - if ( BOUNDS( point, exc->zp0.n_points ) || - BOUNDSL( cvtEntry, exc->cvtSize ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - /* UNDOCUMENTED! */ - /* */ - /* The behaviour of an MIAP instruction is quite different when used */ - /* in the twilight zone. */ - /* */ - /* First, no control value cut-in test is performed as it would fail */ - /* anyway. Second, the original point, i.e. (org_x,org_y) of */ - /* zp0.point, is set to the absolute, unrounded distance found in the */ - /* CVT. */ - /* */ - /* This is used in the CVT programs of the Microsoft fonts Arial, */ - /* Times, etc., in order to re-adjust some key font heights. It */ - /* allows the use of the IP instruction in the twilight zone, which */ - /* otherwise would be invalid according to the specification. */ - /* */ - /* We implement it with a special sequence for the twilight zone. */ - /* This is a bad hack, but it seems to work. */ - /* */ - /* Confirmed by Greg Hitchcock. */ - - distance = exc->func_read_cvt( exc, cvtEntry ); - - if ( exc->GS.gep0 == 0 ) /* If in twilight zone */ - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* Only adjust if not in sph_compatibility_mode or ignore_x_mode. */ - /* Determined via experimentation and may be incorrect... */ - if ( !( SUBPIXEL_HINTING_INFINALITY && - ( exc->ignore_x_mode && - exc->face->sph_compatibility_mode ) ) ) -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - exc->zp0.org[point].x = TT_MulFix14( distance, - exc->GS.freeVector.x ); - exc->zp0.org[point].y = TT_MulFix14( distance, - exc->GS.freeVector.y ), - exc->zp0.cur[point] = exc->zp0.org[point]; - } -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - ( exc->sph_tweak_flags & SPH_TWEAK_MIAP_HACK ) && - distance > 0 && - exc->GS.freeVector.y != 0 ) - distance = 0; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - org_dist = FAST_PROJECT( &exc->zp0.cur[point] ); - - if ( ( exc->opcode & 1 ) != 0 ) /* rounding and control cut-in flag */ - { - if ( FT_ABS( distance - org_dist ) > control_value_cutin ) - distance = org_dist; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 ) - distance = Round_None( exc, - distance, - exc->tt_metrics.compensations[0] ); - else -#endif - distance = exc->func_round( exc, - distance, - exc->tt_metrics.compensations[0] ); - } - - exc->func_move( exc, &exc->zp0, point, distance - org_dist ); - - Fail: - exc->GS.rp0 = point; - exc->GS.rp1 = point; - } - - - /*************************************************************************/ - /* */ - /* MDRP[abcde]: Move Direct Relative Point */ - /* Opcode range: 0xC0-0xDF */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_MDRP( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point = 0; - FT_F26Dot6 org_dist, distance, minimum_distance; - - - minimum_distance = exc->GS.minimum_distance; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 && - !( exc->sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) - minimum_distance = 0; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - point = (FT_UShort)args[0]; - - if ( BOUNDS( point, exc->zp1.n_points ) || - BOUNDS( exc->GS.rp0, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - /* XXX: Is there some undocumented feature while in the */ - /* twilight zone? */ - - /* XXX: UNDOCUMENTED: twilight zone special case */ - - if ( exc->GS.gep0 == 0 || exc->GS.gep1 == 0 ) - { - FT_Vector* vec1 = &exc->zp1.org[point]; - FT_Vector* vec2 = &exc->zp0.org[exc->GS.rp0]; - - - org_dist = DUALPROJ( vec1, vec2 ); - } - else - { - FT_Vector* vec1 = &exc->zp1.orus[point]; - FT_Vector* vec2 = &exc->zp0.orus[exc->GS.rp0]; - - - if ( exc->metrics.x_scale == exc->metrics.y_scale ) - { - /* this should be faster */ - org_dist = DUALPROJ( vec1, vec2 ); - org_dist = FT_MulFix( org_dist, exc->metrics.x_scale ); - } - else - { - FT_Vector vec; - - - vec.x = FT_MulFix( vec1->x - vec2->x, exc->metrics.x_scale ); - vec.y = FT_MulFix( vec1->y - vec2->y, exc->metrics.y_scale ); - - org_dist = FAST_DUALPROJ( &vec ); - } - } - - /* single width cut-in test */ - - if ( FT_ABS( org_dist - exc->GS.single_width_value ) < - exc->GS.single_width_cutin ) - { - if ( org_dist >= 0 ) - org_dist = exc->GS.single_width_value; - else - org_dist = -exc->GS.single_width_value; - } - - /* round flag */ - - if ( ( exc->opcode & 4 ) != 0 ) - { -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 ) - distance = Round_None( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); - else -#endif - distance = exc->func_round( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); - } - else - distance = Round_None( - exc, - org_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); - - /* minimum distance flag */ - - if ( ( exc->opcode & 8 ) != 0 ) - { - if ( org_dist >= 0 ) - { - if ( distance < minimum_distance ) - distance = minimum_distance; - } - else - { - if ( distance > -minimum_distance ) - distance = -minimum_distance; - } - } - - /* now move the point */ - - org_dist = PROJECT( exc->zp1.cur + point, exc->zp0.cur + exc->GS.rp0 ); - - exc->func_move( exc, &exc->zp1, point, distance - org_dist ); - - Fail: - exc->GS.rp1 = exc->GS.rp0; - exc->GS.rp2 = point; - - if ( ( exc->opcode & 16 ) != 0 ) - exc->GS.rp0 = point; - } - - - /*************************************************************************/ - /* */ - /* MIRP[abcde]: Move Indirect Relative Point */ - /* Opcode range: 0xE0-0xFF */ - /* Stack: int32? uint32 --> */ - /* */ - static void - Ins_MIRP( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point; - FT_ULong cvtEntry; - - FT_F26Dot6 cvt_dist, - distance, - cur_dist, - org_dist, - control_value_cutin, - minimum_distance; -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - FT_Int B1 = 0; /* pacify compiler */ - FT_Int B2 = 0; - FT_Bool reverse_move = FALSE; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - - minimum_distance = exc->GS.minimum_distance; - control_value_cutin = exc->GS.control_value_cutin; - point = (FT_UShort)args[0]; - cvtEntry = (FT_ULong)( args[1] + 1 ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.x != 0 && - !( exc->sph_tweak_flags & SPH_TWEAK_NORMAL_ROUND ) ) - control_value_cutin = minimum_distance = 0; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - /* XXX: UNDOCUMENTED! cvt[-1] = 0 always */ - - if ( BOUNDS( point, exc->zp1.n_points ) || - BOUNDSL( cvtEntry, exc->cvtSize + 1 ) || - BOUNDS( exc->GS.rp0, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - if ( !cvtEntry ) - cvt_dist = 0; - else - cvt_dist = exc->func_read_cvt( exc, cvtEntry - 1 ); - - /* single width test */ - - if ( FT_ABS( cvt_dist - exc->GS.single_width_value ) < - exc->GS.single_width_cutin ) - { - if ( cvt_dist >= 0 ) - cvt_dist = exc->GS.single_width_value; - else - cvt_dist = -exc->GS.single_width_value; - } - - /* UNDOCUMENTED! The MS rasterizer does that with */ - /* twilight points (confirmed by Greg Hitchcock) */ - if ( exc->GS.gep1 == 0 ) - { - exc->zp1.org[point].x = exc->zp0.org[exc->GS.rp0].x + - TT_MulFix14( cvt_dist, - exc->GS.freeVector.x ); - exc->zp1.org[point].y = exc->zp0.org[exc->GS.rp0].y + - TT_MulFix14( cvt_dist, - exc->GS.freeVector.y ); - exc->zp1.cur[point] = exc->zp1.org[point]; - } - - org_dist = DUALPROJ( &exc->zp1.org[point], &exc->zp0.org[exc->GS.rp0] ); - cur_dist = PROJECT ( &exc->zp1.cur[point], &exc->zp0.cur[exc->GS.rp0] ); - - /* auto-flip test */ - - if ( exc->GS.auto_flip ) - { - if ( ( org_dist ^ cvt_dist ) < 0 ) - cvt_dist = -cvt_dist; - } - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.freeVector.y != 0 && - ( exc->sph_tweak_flags & SPH_TWEAK_TIMES_NEW_ROMAN_HACK ) ) - { - if ( cur_dist < -64 ) - cvt_dist -= 16; - else if ( cur_dist > 64 && cur_dist < 84 ) - cvt_dist += 32; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - /* control value cut-in and round */ - - if ( ( exc->opcode & 4 ) != 0 ) - { - /* XXX: UNDOCUMENTED! Only perform cut-in test when both points */ - /* refer to the same zone. */ - - if ( exc->GS.gep0 == exc->GS.gep1 ) - { - /* XXX: According to Greg Hitchcock, the following wording is */ - /* the right one: */ - /* */ - /* When the absolute difference between the value in */ - /* the table [CVT] and the measurement directly from */ - /* the outline is _greater_ than the cut_in value, the */ - /* outline measurement is used. */ - /* */ - /* This is from `instgly.doc'. The description in */ - /* `ttinst2.doc', version 1.66, is thus incorrect since */ - /* it implies `>=' instead of `>'. */ - - if ( FT_ABS( cvt_dist - org_dist ) > control_value_cutin ) - cvt_dist = org_dist; - } - - distance = exc->func_round( - exc, - cvt_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); - } - else - { - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /* do cvt cut-in always in MIRP for sph */ - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->GS.gep0 == exc->GS.gep1 ) - { - if ( FT_ABS( cvt_dist - org_dist ) > control_value_cutin ) - cvt_dist = org_dist; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - distance = Round_None( - exc, - cvt_dist, - exc->tt_metrics.compensations[exc->opcode & 3] ); - } - - /* minimum distance test */ - - if ( ( exc->opcode & 8 ) != 0 ) - { - if ( org_dist >= 0 ) - { - if ( distance < minimum_distance ) - distance = minimum_distance; - } - else - { - if ( distance > -minimum_distance ) - distance = -minimum_distance; - } - } - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY ) - { - B1 = exc->zp1.cur[point].y; - - /* Round moves if necessary */ - if ( exc->ignore_x_mode && - exc->GS.freeVector.y != 0 && - ( exc->sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) ) - distance = FT_PIX_ROUND( B1 + distance - cur_dist ) - B1 + cur_dist; - - if ( exc->ignore_x_mode && - exc->GS.freeVector.y != 0 && - ( exc->opcode & 16 ) == 0 && - ( exc->opcode & 8 ) == 0 && - ( exc->sph_tweak_flags & SPH_TWEAK_COURIER_NEW_2_HACK ) ) - distance += 64; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - exc->func_move( exc, &exc->zp1, point, distance - cur_dist ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY ) - { - B2 = exc->zp1.cur[point].y; - - /* Reverse move if necessary */ - if ( exc->ignore_x_mode ) - { - if ( exc->face->sph_compatibility_mode && - exc->GS.freeVector.y != 0 && - ( B1 & 63 ) == 0 && - ( B2 & 63 ) != 0 ) - reverse_move = TRUE; - - if ( ( exc->sph_tweak_flags & SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES ) && - exc->GS.freeVector.y != 0 && - ( B2 & 63 ) != 0 && - ( B1 & 63 ) != 0 ) - reverse_move = TRUE; - } - - if ( reverse_move ) - exc->func_move( exc, &exc->zp1, point, -( distance - cur_dist ) ); - } - -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - Fail: - exc->GS.rp1 = exc->GS.rp0; - - if ( ( exc->opcode & 16 ) != 0 ) - exc->GS.rp0 = point; - - exc->GS.rp2 = point; - } - - - /*************************************************************************/ - /* */ - /* ALIGNRP[]: ALIGN Relative Point */ - /* Opcode range: 0x3C */ - /* Stack: uint32 uint32... --> */ - /* */ - static void - Ins_ALIGNRP( TT_ExecContext exc ) - { - FT_UShort point; - FT_F26Dot6 distance; - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->iup_called && - ( exc->sph_tweak_flags & SPH_TWEAK_NO_ALIGNRP_AFTER_IUP ) ) - { - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - if ( exc->top < exc->GS.loop || - BOUNDS( exc->GS.rp0, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - while ( exc->GS.loop > 0 ) - { - exc->args--; - - point = (FT_UShort)exc->stack[exc->args]; - - if ( BOUNDS( point, exc->zp1.n_points ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - else - { - distance = PROJECT( exc->zp1.cur + point, - exc->zp0.cur + exc->GS.rp0 ); - - exc->func_move( exc, &exc->zp1, point, -distance ); - } - - exc->GS.loop--; - } - - Fail: - exc->GS.loop = 1; - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* ISECT[]: moves point to InterSECTion */ - /* Opcode range: 0x0F */ - /* Stack: 5 * uint32 --> */ - /* */ - static void - Ins_ISECT( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point, - a0, a1, - b0, b1; - - FT_F26Dot6 discriminant, dotproduct; - - FT_F26Dot6 dx, dy, - dax, day, - dbx, dby; - - FT_F26Dot6 val; - - FT_Vector R; - - - point = (FT_UShort)args[0]; - - a0 = (FT_UShort)args[1]; - a1 = (FT_UShort)args[2]; - b0 = (FT_UShort)args[3]; - b1 = (FT_UShort)args[4]; - - if ( BOUNDS( b0, exc->zp0.n_points ) || - BOUNDS( b1, exc->zp0.n_points ) || - BOUNDS( a0, exc->zp1.n_points ) || - BOUNDS( a1, exc->zp1.n_points ) || - BOUNDS( point, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - /* Cramer's rule */ - - dbx = exc->zp0.cur[b1].x - exc->zp0.cur[b0].x; - dby = exc->zp0.cur[b1].y - exc->zp0.cur[b0].y; - - dax = exc->zp1.cur[a1].x - exc->zp1.cur[a0].x; - day = exc->zp1.cur[a1].y - exc->zp1.cur[a0].y; - - dx = exc->zp0.cur[b0].x - exc->zp1.cur[a0].x; - dy = exc->zp0.cur[b0].y - exc->zp1.cur[a0].y; - - discriminant = FT_MulDiv( dax, -dby, 0x40 ) + - FT_MulDiv( day, dbx, 0x40 ); - dotproduct = FT_MulDiv( dax, dbx, 0x40 ) + - FT_MulDiv( day, dby, 0x40 ); - - /* The discriminant above is actually a cross product of vectors */ - /* da and db. Together with the dot product, they can be used as */ - /* surrogates for sine and cosine of the angle between the vectors. */ - /* Indeed, */ - /* dotproduct = |da||db|cos(angle) */ - /* discriminant = |da||db|sin(angle) . */ - /* We use these equations to reject grazing intersections by */ - /* thresholding abs(tan(angle)) at 1/19, corresponding to 3 degrees. */ - if ( 19 * FT_ABS( discriminant ) > FT_ABS( dotproduct ) ) - { - val = FT_MulDiv( dx, -dby, 0x40 ) + FT_MulDiv( dy, dbx, 0x40 ); - - R.x = FT_MulDiv( val, dax, discriminant ); - R.y = FT_MulDiv( val, day, discriminant ); - - /* XXX: Block in backward_compatibility and/or post-IUP? */ - exc->zp2.cur[point].x = exc->zp1.cur[a0].x + R.x; - exc->zp2.cur[point].y = exc->zp1.cur[a0].y + R.y; - } - else - { - /* else, take the middle of the middles of A and B */ - - /* XXX: Block in backward_compatibility and/or post-IUP? */ - exc->zp2.cur[point].x = ( exc->zp1.cur[a0].x + - exc->zp1.cur[a1].x + - exc->zp0.cur[b0].x + - exc->zp0.cur[b1].x ) / 4; - exc->zp2.cur[point].y = ( exc->zp1.cur[a0].y + - exc->zp1.cur[a1].y + - exc->zp0.cur[b0].y + - exc->zp0.cur[b1].y ) / 4; - } - - exc->zp2.tags[point] |= FT_CURVE_TAG_TOUCH_BOTH; - } - - - /*************************************************************************/ - /* */ - /* ALIGNPTS[]: ALIGN PoinTS */ - /* Opcode range: 0x27 */ - /* Stack: uint32 uint32 --> */ - /* */ - static void - Ins_ALIGNPTS( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort p1, p2; - FT_F26Dot6 distance; - - - p1 = (FT_UShort)args[0]; - p2 = (FT_UShort)args[1]; - - if ( BOUNDS( p1, exc->zp1.n_points ) || - BOUNDS( p2, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - distance = PROJECT( exc->zp0.cur + p2, exc->zp1.cur + p1 ) / 2; - - exc->func_move( exc, &exc->zp1, p1, distance ); - exc->func_move( exc, &exc->zp0, p2, -distance ); - } - - - /*************************************************************************/ - /* */ - /* IP[]: Interpolate Point */ - /* Opcode range: 0x39 */ - /* Stack: uint32... --> */ - /* */ - - /* SOMETIMES, DUMBER CODE IS BETTER CODE */ - - static void - Ins_IP( TT_ExecContext exc ) - { - FT_F26Dot6 old_range, cur_range; - FT_Vector* orus_base; - FT_Vector* cur_base; - FT_Int twilight; - - - if ( exc->top < exc->GS.loop ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - /* - * We need to deal in a special way with the twilight zone. - * Otherwise, by definition, the value of exc->twilight.orus[n] is (0,0), - * for every n. - */ - twilight = ( exc->GS.gep0 == 0 || - exc->GS.gep1 == 0 || - exc->GS.gep2 == 0 ); - - if ( BOUNDS( exc->GS.rp1, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - goto Fail; - } - - if ( twilight ) - orus_base = &exc->zp0.org[exc->GS.rp1]; - else - orus_base = &exc->zp0.orus[exc->GS.rp1]; - - cur_base = &exc->zp0.cur[exc->GS.rp1]; - - /* XXX: There are some glyphs in some braindead but popular */ - /* fonts out there (e.g. [aeu]grave in monotype.ttf) */ - /* calling IP[] with bad values of rp[12]. */ - /* Do something sane when this odd thing happens. */ - if ( BOUNDS( exc->GS.rp1, exc->zp0.n_points ) || - BOUNDS( exc->GS.rp2, exc->zp1.n_points ) ) - { - old_range = 0; - cur_range = 0; - } - else - { - if ( twilight ) - old_range = DUALPROJ( &exc->zp1.org[exc->GS.rp2], orus_base ); - else if ( exc->metrics.x_scale == exc->metrics.y_scale ) - old_range = DUALPROJ( &exc->zp1.orus[exc->GS.rp2], orus_base ); - else - { - FT_Vector vec; - - - vec.x = FT_MulFix( exc->zp1.orus[exc->GS.rp2].x - orus_base->x, - exc->metrics.x_scale ); - vec.y = FT_MulFix( exc->zp1.orus[exc->GS.rp2].y - orus_base->y, - exc->metrics.y_scale ); - - old_range = FAST_DUALPROJ( &vec ); - } - - cur_range = PROJECT( &exc->zp1.cur[exc->GS.rp2], cur_base ); - } - - for ( ; exc->GS.loop > 0; exc->GS.loop-- ) - { - FT_UInt point = (FT_UInt)exc->stack[--exc->args]; - FT_F26Dot6 org_dist, cur_dist, new_dist; - - - /* check point bounds */ - if ( BOUNDS( point, exc->zp2.n_points ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - continue; - } - - if ( twilight ) - org_dist = DUALPROJ( &exc->zp2.org[point], orus_base ); - else if ( exc->metrics.x_scale == exc->metrics.y_scale ) - org_dist = DUALPROJ( &exc->zp2.orus[point], orus_base ); - else - { - FT_Vector vec; - - - vec.x = FT_MulFix( exc->zp2.orus[point].x - orus_base->x, - exc->metrics.x_scale ); - vec.y = FT_MulFix( exc->zp2.orus[point].y - orus_base->y, - exc->metrics.y_scale ); - - org_dist = FAST_DUALPROJ( &vec ); - } - - cur_dist = PROJECT( &exc->zp2.cur[point], cur_base ); - - if ( org_dist ) - { - if ( old_range ) - new_dist = FT_MulDiv( org_dist, cur_range, old_range ); - else - { - /* This is the same as what MS does for the invalid case: */ - /* */ - /* delta = (Original_Pt - Original_RP1) - */ - /* (Current_Pt - Current_RP1) ; */ - /* */ - /* In FreeType speak: */ - /* */ - /* 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; - } - } - else - new_dist = 0; - - exc->func_move( exc, - &exc->zp2, - (FT_UShort)point, - new_dist - cur_dist ); - } - - Fail: - exc->GS.loop = 1; - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* UTP[a]: UnTouch Point */ - /* Opcode range: 0x29 */ - /* Stack: uint32 --> */ - /* */ - static void - Ins_UTP( TT_ExecContext exc, - FT_Long* args ) - { - FT_UShort point; - FT_Byte mask; - - - point = (FT_UShort)args[0]; - - if ( BOUNDS( point, exc->zp0.n_points ) ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - return; - } - - mask = 0xFF; - - if ( exc->GS.freeVector.x != 0 ) - mask &= ~FT_CURVE_TAG_TOUCH_X; - - if ( exc->GS.freeVector.y != 0 ) - mask &= ~FT_CURVE_TAG_TOUCH_Y; - - exc->zp0.tags[point] &= mask; - } - - - /* Local variables for Ins_IUP: */ - typedef struct IUP_WorkerRec_ - { - FT_Vector* orgs; /* original and current coordinate */ - FT_Vector* curs; /* arrays */ - FT_Vector* orus; - FT_UInt max_points; - - } IUP_WorkerRec, *IUP_Worker; - - - static void - _iup_worker_shift( IUP_Worker worker, - FT_UInt p1, - FT_UInt p2, - FT_UInt p ) - { - FT_UInt i; - FT_F26Dot6 dx; - - - dx = worker->curs[p].x - worker->orgs[p].x; - if ( dx != 0 ) - { - for ( i = p1; i < p; i++ ) - worker->curs[i].x += dx; - - for ( i = p + 1; i <= p2; i++ ) - worker->curs[i].x += dx; - } - } - - - static void - _iup_worker_interpolate( IUP_Worker worker, - FT_UInt p1, - FT_UInt p2, - FT_UInt ref1, - FT_UInt ref2 ) - { - FT_UInt i; - FT_F26Dot6 orus1, orus2, org1, org2, cur1, cur2, delta1, delta2; - - - if ( p1 > p2 ) - return; - - if ( BOUNDS( ref1, worker->max_points ) || - BOUNDS( ref2, worker->max_points ) ) - return; - - orus1 = worker->orus[ref1].x; - orus2 = worker->orus[ref2].x; - - if ( orus1 > orus2 ) - { - FT_F26Dot6 tmp_o; - FT_UInt tmp_r; - - - tmp_o = orus1; - orus1 = orus2; - orus2 = tmp_o; - - tmp_r = ref1; - ref1 = ref2; - ref2 = tmp_r; - } - - org1 = worker->orgs[ref1].x; - org2 = worker->orgs[ref2].x; - cur1 = worker->curs[ref1].x; - cur2 = worker->curs[ref2].x; - delta1 = cur1 - org1; - delta2 = cur2 - org2; - - if ( cur1 == cur2 || orus1 == orus2 ) - { - - /* trivial snap or shift of untouched points */ - for ( i = p1; i <= p2; i++ ) - { - FT_F26Dot6 x = worker->orgs[i].x; - - - if ( x <= org1 ) - x += delta1; - - else if ( x >= org2 ) - x += delta2; - - else - x = cur1; - - worker->curs[i].x = x; - } - } - else - { - FT_Fixed scale = 0; - FT_Bool scale_valid = 0; - - - /* interpolation */ - for ( i = p1; i <= p2; i++ ) - { - FT_F26Dot6 x = worker->orgs[i].x; - - - if ( x <= org1 ) - x += delta1; - - else if ( x >= org2 ) - x += delta2; - - else - { - if ( !scale_valid ) - { - scale_valid = 1; - scale = FT_DivFix( cur2 - cur1, orus2 - orus1 ); - } - - x = cur1 + FT_MulFix( worker->orus[i].x - orus1, scale ); - } - worker->curs[i].x = x; - } - } - } - - - /*************************************************************************/ - /* */ - /* IUP[a]: Interpolate Untouched Points */ - /* Opcode range: 0x30-0x31 */ - /* Stack: --> */ - /* */ - static void - Ins_IUP( TT_ExecContext exc ) - { - IUP_WorkerRec V; - FT_Byte mask; - - FT_UInt first_point; /* first point of contour */ - FT_UInt end_point; /* end point (last+1) of contour */ - - FT_UInt first_touched; /* first touched point in contour */ - FT_UInt cur_touched; /* current touched point in contour */ - - FT_UInt point; /* current point */ - FT_Short contour; /* current contour */ - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* See `ttinterp.h' for details on backward compatibility mode. */ - /* Allow IUP until it has been called on both axes. Immediately */ - /* return on subsequent ones. */ - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility ) - { - if ( exc->iupx_called && exc->iupy_called ) - return; - - if ( exc->opcode & 1 ) - exc->iupx_called = TRUE; - else - exc->iupy_called = TRUE; - } -#endif - - /* ignore empty outlines */ - if ( exc->pts.n_contours == 0 ) - return; - - if ( exc->opcode & 1 ) - { - mask = FT_CURVE_TAG_TOUCH_X; - V.orgs = exc->pts.org; - V.curs = exc->pts.cur; - V.orus = exc->pts.orus; - } - else - { - mask = FT_CURVE_TAG_TOUCH_Y; - V.orgs = (FT_Vector*)( (FT_Pos*)exc->pts.org + 1 ); - V.curs = (FT_Vector*)( (FT_Pos*)exc->pts.cur + 1 ); - V.orus = (FT_Vector*)( (FT_Pos*)exc->pts.orus + 1 ); - } - V.max_points = exc->pts.n_points; - - contour = 0; - point = 0; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode ) - { - exc->iup_called = TRUE; - if ( exc->sph_tweak_flags & SPH_TWEAK_SKIP_IUP ) - return; - } -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - do - { - end_point = exc->pts.contours[contour] - exc->pts.first_point; - first_point = point; - - if ( BOUNDS( end_point, exc->pts.n_points ) ) - end_point = exc->pts.n_points - 1; - - while ( point <= end_point && ( exc->pts.tags[point] & mask ) == 0 ) - point++; - - if ( point <= end_point ) - { - first_touched = point; - cur_touched = point; - - point++; - - while ( point <= end_point ) - { - if ( ( exc->pts.tags[point] & mask ) != 0 ) - { - _iup_worker_interpolate( &V, - cur_touched + 1, - point - 1, - cur_touched, - point ); - cur_touched = point; - } - - point++; - } - - if ( cur_touched == first_touched ) - _iup_worker_shift( &V, first_point, end_point, cur_touched ); - else - { - _iup_worker_interpolate( &V, - (FT_UShort)( cur_touched + 1 ), - end_point, - cur_touched, - first_touched ); - - if ( first_touched > 0 ) - _iup_worker_interpolate( &V, - first_point, - first_touched - 1, - cur_touched, - first_touched ); - } - } - contour++; - } while ( contour < exc->pts.n_contours ); - } - - - /*************************************************************************/ - /* */ - /* DELTAPn[]: DELTA exceptions P1, P2, P3 */ - /* Opcode range: 0x5D,0x71,0x72 */ - /* Stack: uint32 (2 * uint32)... --> */ - /* */ - static void - Ins_DELTAP( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong nump, k; - FT_UShort A; - FT_ULong C, P; - FT_Long B; -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - FT_UShort B1, B2; - - - if ( SUBPIXEL_HINTING_INFINALITY && - exc->ignore_x_mode && - exc->iup_called && - ( exc->sph_tweak_flags & SPH_TWEAK_NO_DELTAP_AFTER_IUP ) ) - goto Fail; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - P = (FT_ULong)exc->func_cur_ppem( exc ); - nump = (FT_ULong)args[0]; /* some points theoretically may occur more - than once, thus UShort isn't enough */ - - for ( k = 1; k <= nump; k++ ) - { - if ( exc->args < 2 ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Too_Few_Arguments ); - exc->args = 0; - goto Fail; - } - - exc->args -= 2; - - A = (FT_UShort)exc->stack[exc->args + 1]; - B = exc->stack[exc->args]; - - /* XXX: Because some popular fonts contain some invalid DeltaP */ - /* instructions, we simply ignore them when the stacked */ - /* point reference is off limit, rather than returning an */ - /* error. As a delta instruction doesn't change a glyph */ - /* in great ways, this shouldn't be a problem. */ - - if ( !BOUNDS( A, exc->zp0.n_points ) ) - { - C = ( (FT_ULong)B & 0xF0 ) >> 4; - - switch ( exc->opcode ) - { - case 0x5D: - break; - - case 0x71: - C += 16; - break; - - case 0x72: - C += 32; - break; - } - - C += exc->GS.delta_base; - - if ( P == C ) - { - B = ( (FT_ULong)B & 0xF ) - 8; - if ( B >= 0 ) - B++; - B *= 1L << ( 6 - exc->GS.delta_shift ); - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - - if ( SUBPIXEL_HINTING_INFINALITY ) - { - /* - * Allow delta move if - * - * - not using ignore_x_mode rendering, - * - glyph is specifically set to allow it, or - * - glyph is composite and freedom vector is not in subpixel - * direction. - */ - if ( !exc->ignore_x_mode || - ( exc->sph_tweak_flags & SPH_TWEAK_ALWAYS_DO_DELTAP ) || - ( exc->is_composite && exc->GS.freeVector.y != 0 ) ) - exc->func_move( exc, &exc->zp0, A, B ); - - /* Otherwise, apply subpixel hinting and compatibility mode */ - /* rules, always skipping deltas in subpixel direction. */ - else if ( exc->ignore_x_mode && exc->GS.freeVector.y != 0 ) - { - /* save the y value of the point now; compare after move */ - B1 = (FT_UShort)exc->zp0.cur[A].y; - - /* Standard subpixel hinting: Allow y move for y-touched */ - /* points. This messes up DejaVu ... */ - if ( !exc->face->sph_compatibility_mode && - ( exc->zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) ) - exc->func_move( exc, &exc->zp0, A, B ); - - /* compatibility mode */ - else if ( exc->face->sph_compatibility_mode && - !( exc->sph_tweak_flags & SPH_TWEAK_ALWAYS_SKIP_DELTAP ) ) - { - if ( exc->sph_tweak_flags & SPH_TWEAK_ROUND_NONPIXEL_Y_MOVES ) - B = FT_PIX_ROUND( B1 + B ) - B1; - - /* Allow delta move if using sph_compatibility_mode, */ - /* IUP has not been called, and point is touched on Y. */ - if ( !exc->iup_called && - ( exc->zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) ) - exc->func_move( exc, &exc->zp0, A, B ); - } - - B2 = (FT_UShort)exc->zp0.cur[A].y; - - /* Reverse this move if it results in a disallowed move */ - if ( exc->GS.freeVector.y != 0 && - ( ( exc->face->sph_compatibility_mode && - ( B1 & 63 ) == 0 && - ( B2 & 63 ) != 0 ) || - ( ( exc->sph_tweak_flags & - SPH_TWEAK_SKIP_NONPIXEL_Y_MOVES_DELTAP ) && - ( B1 & 63 ) != 0 && - ( B2 & 63 ) != 0 ) ) ) - exc->func_move( exc, &exc->zp0, A, -B ); - } - } - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - { - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* See `ttinterp.h' for details on backward compatibility */ - /* mode. */ - if ( SUBPIXEL_HINTING_MINIMAL && - exc->backward_compatibility ) - { - if ( !( exc->iupx_called && exc->iupy_called ) && - ( ( exc->is_composite && exc->GS.freeVector.y != 0 ) || - ( exc->zp0.tags[A] & FT_CURVE_TAG_TOUCH_Y ) ) ) - exc->func_move( exc, &exc->zp0, A, B ); - } - else -#endif - exc->func_move( exc, &exc->zp0, A, B ); - } - } - } - else - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Invalid_Reference ); - } - - Fail: - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* DELTACn[]: DELTA exceptions C1, C2, C3 */ - /* Opcode range: 0x73,0x74,0x75 */ - /* Stack: uint32 (2 * uint32)... --> */ - /* */ - static void - Ins_DELTAC( TT_ExecContext exc, - FT_Long* args ) - { - FT_ULong nump, k; - FT_ULong A, C, P; - FT_Long B; - - - P = (FT_ULong)exc->func_cur_ppem( exc ); - nump = (FT_ULong)args[0]; - - for ( k = 1; k <= nump; k++ ) - { - if ( exc->args < 2 ) - { - if ( exc->pedantic_hinting ) - exc->error = FT_THROW( Too_Few_Arguments ); - exc->args = 0; - goto Fail; - } - - exc->args -= 2; - - A = (FT_ULong)exc->stack[exc->args + 1]; - B = exc->stack[exc->args]; - - if ( BOUNDSL( A, exc->cvtSize ) ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Invalid_Reference ); - return; - } - } - else - { - C = ( (FT_ULong)B & 0xF0 ) >> 4; - - switch ( exc->opcode ) - { - case 0x73: - break; - - case 0x74: - C += 16; - break; - - case 0x75: - C += 32; - break; - } - - C += exc->GS.delta_base; - - if ( P == C ) - { - B = ( (FT_ULong)B & 0xF ) - 8; - if ( B >= 0 ) - B++; - B *= 1L << ( 6 - exc->GS.delta_shift ); - - exc->func_move_cvt( exc, A, B ); - } - } - } - - Fail: - exc->new_top = exc->args; - } - - - /*************************************************************************/ - /* */ - /* MISC. INSTRUCTIONS */ - /* */ - /*************************************************************************/ - - - /*************************************************************************/ - /* */ - /* GETINFO[]: GET INFOrmation */ - /* Opcode range: 0x88 */ - /* Stack: uint32 --> uint32 */ - /* */ - /* XXX: UNDOCUMENTED: Selector bits higher than 9 are currently (May */ - /* 2015) not documented in the OpenType specification. */ - /* */ - /* Selector bit 11 is incorrectly described as bit 8, while the */ - /* real meaning of bit 8 (vertical LCD subpixels) stays */ - /* undocumented. The same mistake can be found in Greg Hitchcock's */ - /* whitepaper. */ - /* */ - static void - Ins_GETINFO( TT_ExecContext exc, - FT_Long* args ) - { - FT_Long K; - TT_Driver driver = (TT_Driver)FT_FACE_DRIVER( exc->face ); - - - K = 0; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - /********************************/ - /* RASTERIZER VERSION */ - /* Selector Bit: 0 */ - /* Return Bit(s): 0-7 */ - /* */ - if ( SUBPIXEL_HINTING_INFINALITY && - ( args[0] & 1 ) != 0 && - exc->subpixel_hinting ) - { - if ( exc->ignore_x_mode ) - { - /* if in ClearType backward compatibility mode, */ - /* we sometimes change the TrueType version dynamically */ - K = exc->rasterizer_version; - FT_TRACE6(( "Setting rasterizer version %d\n", - exc->rasterizer_version )); - } - else - K = TT_INTERPRETER_VERSION_38; - } - else -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - if ( ( args[0] & 1 ) != 0 ) - K = driver->interpreter_version; - - /********************************/ - /* GLYPH ROTATED */ - /* Selector Bit: 1 */ - /* Return Bit(s): 8 */ - /* */ - if ( ( args[0] & 2 ) != 0 && exc->tt_metrics.rotated ) - K |= 1 << 8; - - /********************************/ - /* GLYPH STRETCHED */ - /* Selector Bit: 2 */ - /* Return Bit(s): 9 */ - /* */ - if ( ( args[0] & 4 ) != 0 && exc->tt_metrics.stretched ) - K |= 1 << 9; - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - /********************************/ - /* VARIATION GLYPH */ - /* Selector Bit: 3 */ - /* Return Bit(s): 10 */ - /* */ - /* XXX: UNDOCUMENTED! */ - if ( (args[0] & 8 ) != 0 && exc->face->blend ) - K |= 1 << 10; -#endif - - /********************************/ - /* BI-LEVEL HINTING AND */ - /* GRAYSCALE RENDERING */ - /* Selector Bit: 5 */ - /* Return Bit(s): 12 */ - /* */ - if ( ( args[0] & 32 ) != 0 && exc->grayscale ) - K |= 1 << 12; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - if ( SUBPIXEL_HINTING_MINIMAL ) - { - /********************************/ - /* HINTING FOR SUBPIXEL */ - /* Selector Bit: 6 */ - /* Return Bit(s): 13 */ - /* */ - /* v40 does subpixel hinting by default. */ - if ( ( args[0] & 64 ) != 0 ) - K |= 1 << 13; - - /********************************/ - /* VERTICAL LCD SUBPIXELS? */ - /* Selector Bit: 8 */ - /* Return Bit(s): 15 */ - /* */ - if ( ( args[0] & 256 ) != 0 && exc->vertical_lcd_lean ) - K |= 1 << 15; - - /********************************/ - /* SUBPIXEL POSITIONED? */ - /* Selector Bit: 10 */ - /* Return Bit(s): 17 */ - /* */ - /* XXX: FreeType supports it, dependent on what client does? */ - if ( ( args[0] & 1024 ) != 0 ) - K |= 1 << 17; - - /********************************/ - /* SYMMETRICAL SMOOTHING */ - /* Selector Bit: 11 */ - /* Return Bit(s): 18 */ - /* */ - /* The only smoothing method FreeType supports unless someone sets */ - /* FT_LOAD_TARGET_MONO. */ - if ( ( args[0] & 2048 ) != 0 ) - K |= 1 << 18; - - /********************************/ - /* CLEARTYPE HINTING AND */ - /* GRAYSCALE RENDERING */ - /* Selector Bit: 12 */ - /* Return Bit(s): 19 */ - /* */ - /* Grayscale rendering is what FreeType does anyway unless someone */ - /* sets FT_LOAD_TARGET_MONO or FT_LOAD_TARGET_LCD(_V) */ - if ( ( args[0] & 4096 ) != 0 && exc->grayscale_cleartype ) - K |= 1 << 19; - } -#endif - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - - if ( SUBPIXEL_HINTING_INFINALITY && - exc->rasterizer_version >= TT_INTERPRETER_VERSION_35 ) - { - - if ( exc->rasterizer_version >= 37 ) - { - /********************************/ - /* HINTING FOR SUBPIXEL */ - /* Selector Bit: 6 */ - /* Return Bit(s): 13 */ - /* */ - if ( ( args[0] & 64 ) != 0 && exc->subpixel_hinting ) - K |= 1 << 13; - - /********************************/ - /* COMPATIBLE WIDTHS ENABLED */ - /* Selector Bit: 7 */ - /* Return Bit(s): 14 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 128 ) != 0 && exc->compatible_widths ) - K |= 1 << 14; - - /********************************/ - /* VERTICAL LCD SUBPIXELS? */ - /* Selector Bit: 8 */ - /* Return Bit(s): 15 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 256 ) != 0 && exc->vertical_lcd ) - K |= 1 << 15; - - /********************************/ - /* HINTING FOR BGR? */ - /* Selector Bit: 9 */ - /* Return Bit(s): 16 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 512 ) != 0 && exc->bgr ) - K |= 1 << 16; - - if ( exc->rasterizer_version >= 38 ) - { - /********************************/ - /* SUBPIXEL POSITIONED? */ - /* Selector Bit: 10 */ - /* Return Bit(s): 17 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 1024 ) != 0 && exc->subpixel_positioned ) - K |= 1 << 17; - - /********************************/ - /* SYMMETRICAL SMOOTHING */ - /* Selector Bit: 11 */ - /* Return Bit(s): 18 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 2048 ) != 0 && exc->symmetrical_smoothing ) - K |= 1 << 18; - - /********************************/ - /* GRAY CLEARTYPE */ - /* Selector Bit: 12 */ - /* Return Bit(s): 19 */ - /* */ - /* Functionality still needs to be added */ - if ( ( args[0] & 4096 ) != 0 && exc->gray_cleartype ) - K |= 1 << 19; - } - } - } - -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - args[0] = K; - } - - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - - /*************************************************************************/ - /* */ - /* GETVARIATION[]: get normalized variation (blend) coordinates */ - /* Opcode range: 0x91 */ - /* Stack: --> f2.14... */ - /* */ - /* XXX: UNDOCUMENTED! There is no official documentation from Apple for */ - /* this bytecode instruction. Active only if a font has GX */ - /* variation axes. */ - /* */ - static void - Ins_GETVARIATION( TT_ExecContext exc, - FT_Long* args ) - { - FT_UInt num_axes = exc->face->blend->num_axis; - FT_Fixed* coords = exc->face->blend->normalizedcoords; - - FT_UInt i; - - - if ( BOUNDS( num_axes, exc->stackSize + 1 - exc->top ) ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - for ( i = 0; i < num_axes; i++ ) - args[i] = coords[i] >> 2; /* convert 16.16 to 2.14 format */ - } - - - /*************************************************************************/ - /* */ - /* GETDATA[]: no idea what this is good for */ - /* Opcode range: 0x92 */ - /* Stack: --> 17 */ - /* */ - /* XXX: UNDOCUMENTED! There is no documentation from Apple for this */ - /* very weird bytecode instruction. */ - /* */ - static void - Ins_GETDATA( FT_Long* args ) - { - args[0] = 17; - } - -#endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */ - - - static void - Ins_UNKNOWN( TT_ExecContext exc ) - { - TT_DefRecord* def = exc->IDefs; - TT_DefRecord* limit = def + exc->numIDefs; - - - for ( ; def < limit; def++ ) - { - if ( (FT_Byte)def->opc == exc->opcode && def->active ) - { - TT_CallRec* call; - - - if ( exc->callTop >= exc->callSize ) - { - exc->error = FT_THROW( Stack_Overflow ); - return; - } - - call = exc->callStack + exc->callTop++; - - call->Caller_Range = exc->curRange; - call->Caller_IP = exc->IP + 1; - call->Cur_Count = 1; - call->Def = def; - - Ins_Goto_CodeRange( exc, def->range, def->start ); - - exc->step_ins = FALSE; - return; - } - } - - exc->error = FT_THROW( Invalid_Opcode ); - } - - - /*************************************************************************/ - /* */ - /* RUN */ - /* */ - /* This function executes a run of opcodes. It will exit in the */ - /* following cases: */ - /* */ - /* - Errors (in which case it returns FALSE). */ - /* */ - /* - Reaching the end of the main code range (returns TRUE). */ - /* Reaching the end of a code range within a function call is an */ - /* error. */ - /* */ - /* - After executing one single opcode, if the flag `Instruction_Trap' */ - /* is set to TRUE (returns TRUE). */ - /* */ - /* On exit with TRUE, test IP < CodeSize to know whether it comes from */ - /* an instruction trap or a normal termination. */ - /* */ - /* */ - /* Note: The documented DEBUG opcode pops a value from the stack. This */ - /* behaviour is unsupported; here a DEBUG opcode is always an */ - /* error. */ - /* */ - /* */ - /* THIS IS THE INTERPRETER'S MAIN LOOP. */ - /* */ - /*************************************************************************/ - - - /* documentation is in ttinterp.h */ - - FT_EXPORT_DEF( FT_Error ) - TT_RunIns( TT_ExecContext exc ) - { - FT_ULong ins_counter = 0; /* executed instructions counter */ - FT_ULong num_twilight_points; - FT_UShort i; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - FT_Byte opcode_pattern[1][2] = { - /* #8 TypeMan Talk Align */ - { - 0x06, /* SPVTL */ - 0x7D, /* RDTG */ - }, - }; - FT_UShort opcode_patterns = 1; - FT_UShort opcode_pointer[1] = { 0 }; - FT_UShort opcode_size[1] = { 1 }; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - exc->iup_called = FALSE; -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL - /* Toggle backward compatibility according to what font says, except */ - /* when it's a `tricky' font that heavily relies on the interpreter to */ - /* render glyphs correctly, e.g. DFKai-SB. Backward compatibility */ - /* hacks may break it. */ - if ( SUBPIXEL_HINTING_MINIMAL && - !FT_IS_TRICKY( &exc->face->root ) ) - exc->backward_compatibility = !( exc->GS.instruct_control & 4 ); - else - exc->backward_compatibility = FALSE; - - exc->iupx_called = FALSE; - exc->iupy_called = FALSE; -#endif - - /* We restrict the number of twilight points to a reasonable, */ - /* heuristic value to avoid slow execution of malformed bytecode. */ - num_twilight_points = FT_MAX( 30, - 2 * ( exc->pts.n_points + exc->cvtSize ) ); - if ( exc->twilight.n_points > num_twilight_points ) - { - if ( num_twilight_points > 0xFFFFU ) - num_twilight_points = 0xFFFFU; - - FT_TRACE5(( "TT_RunIns: Resetting number of twilight points\n" - " from %d to the more reasonable value %d\n", - exc->twilight.n_points, - num_twilight_points )); - exc->twilight.n_points = (FT_UShort)num_twilight_points; - } - - /* Set up loop detectors. We restrict the number of LOOPCALL loops */ - /* and the number of JMPR, JROT, and JROF calls with a negative */ - /* argument to values that depend on various parameters like the */ - /* size of the CVT table or the number of points in the current */ - /* glyph (if applicable). */ - /* */ - /* The idea is that in real-world bytecode you either iterate over */ - /* all CVT entries (in the `prep' table), or over all points (or */ - /* contours, in the `glyf' table) of a glyph, and such iterations */ - /* don't happen very often. */ - exc->loopcall_counter = 0; - exc->neg_jump_counter = 0; - - /* The maximum values are heuristic. */ - if ( exc->pts.n_points ) - exc->loopcall_counter_max = FT_MAX( 50, - 10 * exc->pts.n_points ) + - FT_MAX( 50, - exc->cvtSize / 10 ); - else - exc->loopcall_counter_max = FT_MAX( 100, - 10 * exc->cvtSize ); - - /* as a protection against an unreasonable number of CVT entries */ - /* we assume at most 100 control values per glyph for the counter */ - if ( exc->loopcall_counter_max > - 100 * (FT_ULong)exc->face->root.num_glyphs ) - exc->loopcall_counter_max = 100 * (FT_ULong)exc->face->root.num_glyphs; - - FT_TRACE5(( "TT_RunIns: Limiting total number of loops in LOOPCALL" - " to %d\n", exc->loopcall_counter_max )); - - exc->neg_jump_counter_max = exc->loopcall_counter_max; - FT_TRACE5(( "TT_RunIns: Limiting total number of backward jumps" - " to %d\n", exc->neg_jump_counter_max )); - - /* set PPEM and CVT functions */ - exc->tt_metrics.ratio = 0; - if ( exc->metrics.x_ppem != exc->metrics.y_ppem ) - { - /* non-square pixels, use the stretched routines */ - exc->func_cur_ppem = Current_Ppem_Stretched; - exc->func_read_cvt = Read_CVT_Stretched; - exc->func_write_cvt = Write_CVT_Stretched; - exc->func_move_cvt = Move_CVT_Stretched; - } - else - { - /* square pixels, use normal routines */ - exc->func_cur_ppem = Current_Ppem; - exc->func_read_cvt = Read_CVT; - exc->func_write_cvt = Write_CVT; - exc->func_move_cvt = Move_CVT; - } - - Compute_Funcs( exc ); - Compute_Round( exc, (FT_Byte)exc->GS.round_state ); - - do - { - exc->opcode = exc->code[exc->IP]; - -#ifdef FT_DEBUG_LEVEL_TRACE - { - FT_Long cnt = FT_MIN( 8, exc->top ); - FT_Long n; - - - /* if tracing level is 7, show current code position */ - /* and the first few stack elements also */ - FT_TRACE6(( " " )); - FT_TRACE7(( "%06d ", exc->IP )); - FT_TRACE6(( opcode_name[exc->opcode] + 2 )); - FT_TRACE7(( "%*s", *opcode_name[exc->opcode] == 'A' - ? 2 - : 12 - ( *opcode_name[exc->opcode] - '0' ), - "#" )); - for ( n = 1; n <= cnt; n++ ) - FT_TRACE7(( " %d", exc->stack[exc->top - n] )); - FT_TRACE6(( "\n" )); - } -#endif /* FT_DEBUG_LEVEL_TRACE */ - - if ( ( exc->length = opcode_length[exc->opcode] ) < 0 ) - { - if ( exc->IP + 1 >= exc->codeSize ) - goto LErrorCodeOverflow_; - - exc->length = 2 - exc->length * exc->code[exc->IP + 1]; - } - - if ( exc->IP + exc->length > exc->codeSize ) - goto LErrorCodeOverflow_; - - /* First, let's check for empty stack and overflow */ - exc->args = exc->top - ( Pop_Push_Count[exc->opcode] >> 4 ); - - /* `args' is the top of the stack once arguments have been popped. */ - /* One can also interpret it as the index of the last argument. */ - if ( exc->args < 0 ) - { - if ( exc->pedantic_hinting ) - { - exc->error = FT_THROW( Too_Few_Arguments ); - goto LErrorLabel_; - } - - /* push zeroes onto the stack */ - for ( i = 0; i < Pop_Push_Count[exc->opcode] >> 4; i++ ) - exc->stack[i] = 0; - exc->args = 0; - } - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - if ( exc->opcode == 0x91 ) - { - /* this is very special: GETVARIATION returns */ - /* a variable number of arguments */ - - /* it is the job of the application to `activate' GX handling, */ - /* this is, calling any of the GX API functions on the current */ - /* font to select a variation instance */ - if ( exc->face->blend ) - exc->new_top = exc->args + exc->face->blend->num_axis; - } - else -#endif - exc->new_top = exc->args + ( Pop_Push_Count[exc->opcode] & 15 ); - - /* `new_top' is the new top of the stack, after the instruction's */ - /* execution. `top' will be set to `new_top' after the `switch' */ - /* statement. */ - if ( exc->new_top > exc->stackSize ) - { - exc->error = FT_THROW( Stack_Overflow ); - goto LErrorLabel_; - } - - exc->step_ins = TRUE; - exc->error = FT_Err_Ok; - -#ifdef TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY - - if ( SUBPIXEL_HINTING_INFINALITY ) - { - for ( i = 0; i < opcode_patterns; i++ ) - { - if ( opcode_pointer[i] < opcode_size[i] && - exc->opcode == opcode_pattern[i][opcode_pointer[i]] ) - { - opcode_pointer[i] += 1; - - if ( opcode_pointer[i] == opcode_size[i] ) - { - FT_TRACE6(( "sph: opcode ptrn: %d, %s %s\n", - i, - exc->face->root.family_name, - exc->face->root.style_name )); - - switch ( i ) - { - case 0: - break; - } - opcode_pointer[i] = 0; - } - } - else - opcode_pointer[i] = 0; - } - } - -#endif /* TT_SUPPORT_SUBPIXEL_HINTING_INFINALITY */ - - { - FT_Long* args = exc->stack + exc->args; - FT_Byte opcode = exc->opcode; - - - switch ( opcode ) - { - case 0x00: /* SVTCA y */ - case 0x01: /* SVTCA x */ - case 0x02: /* SPvTCA y */ - case 0x03: /* SPvTCA x */ - case 0x04: /* SFvTCA y */ - case 0x05: /* SFvTCA x */ - Ins_SxyTCA( exc ); - break; - - case 0x06: /* SPvTL // */ - case 0x07: /* SPvTL + */ - Ins_SPVTL( exc, args ); - break; - - case 0x08: /* SFvTL // */ - case 0x09: /* SFvTL + */ - Ins_SFVTL( exc, args ); - break; - - case 0x0A: /* SPvFS */ - Ins_SPVFS( exc, args ); - break; - - case 0x0B: /* SFvFS */ - Ins_SFVFS( exc, args ); - break; - - case 0x0C: /* GPv */ - Ins_GPV( exc, args ); - break; - - case 0x0D: /* GFv */ - Ins_GFV( exc, args ); - break; - - case 0x0E: /* SFvTPv */ - Ins_SFVTPV( exc ); - break; - - case 0x0F: /* ISECT */ - Ins_ISECT( exc, args ); - break; - - case 0x10: /* SRP0 */ - Ins_SRP0( exc, args ); - break; - - case 0x11: /* SRP1 */ - Ins_SRP1( exc, args ); - break; - - case 0x12: /* SRP2 */ - Ins_SRP2( exc, args ); - break; - - case 0x13: /* SZP0 */ - Ins_SZP0( exc, args ); - break; - - case 0x14: /* SZP1 */ - Ins_SZP1( exc, args ); - break; - - case 0x15: /* SZP2 */ - Ins_SZP2( exc, args ); - break; - - case 0x16: /* SZPS */ - Ins_SZPS( exc, args ); - break; - - case 0x17: /* SLOOP */ - Ins_SLOOP( exc, args ); - break; - - case 0x18: /* RTG */ - Ins_RTG( exc ); - break; - - case 0x19: /* RTHG */ - Ins_RTHG( exc ); - break; - - case 0x1A: /* SMD */ - Ins_SMD( exc, args ); - break; - - case 0x1B: /* ELSE */ - Ins_ELSE( exc ); - break; - - case 0x1C: /* JMPR */ - Ins_JMPR( exc, args ); - break; - - case 0x1D: /* SCVTCI */ - Ins_SCVTCI( exc, args ); - break; - - case 0x1E: /* SSWCI */ - Ins_SSWCI( exc, args ); - break; - - case 0x1F: /* SSW */ - Ins_SSW( exc, args ); - break; - - case 0x20: /* DUP */ - Ins_DUP( args ); - break; - - case 0x21: /* POP */ - Ins_POP(); - break; - - case 0x22: /* CLEAR */ - Ins_CLEAR( exc ); - break; - - case 0x23: /* SWAP */ - Ins_SWAP( args ); - break; - - case 0x24: /* DEPTH */ - Ins_DEPTH( exc, args ); - break; - - case 0x25: /* CINDEX */ - Ins_CINDEX( exc, args ); - break; - - case 0x26: /* MINDEX */ - Ins_MINDEX( exc, args ); - break; - - case 0x27: /* ALIGNPTS */ - Ins_ALIGNPTS( exc, args ); - break; - - case 0x28: /* RAW */ - Ins_UNKNOWN( exc ); - break; - - case 0x29: /* UTP */ - Ins_UTP( exc, args ); - break; - - case 0x2A: /* LOOPCALL */ - Ins_LOOPCALL( exc, args ); - break; - - case 0x2B: /* CALL */ - Ins_CALL( exc, args ); - break; - - case 0x2C: /* FDEF */ - Ins_FDEF( exc, args ); - break; - - case 0x2D: /* ENDF */ - Ins_ENDF( exc ); - break; - - case 0x2E: /* MDAP */ - case 0x2F: /* MDAP */ - Ins_MDAP( exc, args ); - break; - - case 0x30: /* IUP */ - case 0x31: /* IUP */ - Ins_IUP( exc ); - break; - - case 0x32: /* SHP */ - case 0x33: /* SHP */ - Ins_SHP( exc ); - break; - - case 0x34: /* SHC */ - case 0x35: /* SHC */ - Ins_SHC( exc, args ); - break; - - case 0x36: /* SHZ */ - case 0x37: /* SHZ */ - Ins_SHZ( exc, args ); - break; - - case 0x38: /* SHPIX */ - Ins_SHPIX( exc, args ); - break; - - case 0x39: /* IP */ - Ins_IP( exc ); - break; - - case 0x3A: /* MSIRP */ - case 0x3B: /* MSIRP */ - Ins_MSIRP( exc, args ); - break; - - case 0x3C: /* AlignRP */ - Ins_ALIGNRP( exc ); - break; - - case 0x3D: /* RTDG */ - Ins_RTDG( exc ); - break; - - case 0x3E: /* MIAP */ - case 0x3F: /* MIAP */ - Ins_MIAP( exc, args ); - break; - - case 0x40: /* NPUSHB */ - Ins_NPUSHB( exc, args ); - break; - - case 0x41: /* NPUSHW */ - Ins_NPUSHW( exc, args ); - break; - - case 0x42: /* WS */ - Ins_WS( exc, args ); - break; - - case 0x43: /* RS */ - Ins_RS( exc, args ); - break; - - case 0x44: /* WCVTP */ - Ins_WCVTP( exc, args ); - break; - - case 0x45: /* RCVT */ - Ins_RCVT( exc, args ); - break; - - case 0x46: /* GC */ - case 0x47: /* GC */ - Ins_GC( exc, args ); - break; - - case 0x48: /* SCFS */ - Ins_SCFS( exc, args ); - break; - - case 0x49: /* MD */ - case 0x4A: /* MD */ - Ins_MD( exc, args ); - break; - - case 0x4B: /* MPPEM */ - Ins_MPPEM( exc, args ); - break; - - case 0x4C: /* MPS */ - Ins_MPS( exc, args ); - break; - - case 0x4D: /* FLIPON */ - Ins_FLIPON( exc ); - break; - - case 0x4E: /* FLIPOFF */ - Ins_FLIPOFF( exc ); - break; - - case 0x4F: /* DEBUG */ - Ins_DEBUG( exc ); - break; - - case 0x50: /* LT */ - Ins_LT( args ); - break; - - case 0x51: /* LTEQ */ - Ins_LTEQ( args ); - break; - - case 0x52: /* GT */ - Ins_GT( args ); - break; - - case 0x53: /* GTEQ */ - Ins_GTEQ( args ); - break; - - case 0x54: /* EQ */ - Ins_EQ( args ); - break; - - case 0x55: /* NEQ */ - Ins_NEQ( args ); - break; - - case 0x56: /* ODD */ - Ins_ODD( exc, args ); - break; - - case 0x57: /* EVEN */ - Ins_EVEN( exc, args ); - break; - - case 0x58: /* IF */ - Ins_IF( exc, args ); - break; - - case 0x59: /* EIF */ - Ins_EIF(); - break; - - case 0x5A: /* AND */ - Ins_AND( args ); - break; - - case 0x5B: /* OR */ - Ins_OR( args ); - break; - - case 0x5C: /* NOT */ - Ins_NOT( args ); - break; - - case 0x5D: /* DELTAP1 */ - Ins_DELTAP( exc, args ); - break; - - case 0x5E: /* SDB */ - Ins_SDB( exc, args ); - break; - - case 0x5F: /* SDS */ - Ins_SDS( exc, args ); - break; - - case 0x60: /* ADD */ - Ins_ADD( args ); - break; - - case 0x61: /* SUB */ - Ins_SUB( args ); - break; - - case 0x62: /* DIV */ - Ins_DIV( exc, args ); - break; - - case 0x63: /* MUL */ - Ins_MUL( args ); - break; - - case 0x64: /* ABS */ - Ins_ABS( args ); - break; - - case 0x65: /* NEG */ - Ins_NEG( args ); - break; - - case 0x66: /* FLOOR */ - Ins_FLOOR( args ); - break; - - case 0x67: /* CEILING */ - Ins_CEILING( args ); - break; - - case 0x68: /* ROUND */ - case 0x69: /* ROUND */ - case 0x6A: /* ROUND */ - case 0x6B: /* ROUND */ - Ins_ROUND( exc, args ); - break; - - case 0x6C: /* NROUND */ - case 0x6D: /* NROUND */ - case 0x6E: /* NRRUND */ - case 0x6F: /* NROUND */ - Ins_NROUND( exc, args ); - break; - - case 0x70: /* WCVTF */ - Ins_WCVTF( exc, args ); - break; - - case 0x71: /* DELTAP2 */ - case 0x72: /* DELTAP3 */ - Ins_DELTAP( exc, args ); - break; - - case 0x73: /* DELTAC0 */ - case 0x74: /* DELTAC1 */ - case 0x75: /* DELTAC2 */ - Ins_DELTAC( exc, args ); - break; - - case 0x76: /* SROUND */ - Ins_SROUND( exc, args ); - break; - - case 0x77: /* S45Round */ - Ins_S45ROUND( exc, args ); - break; - - case 0x78: /* JROT */ - Ins_JROT( exc, args ); - break; - - case 0x79: /* JROF */ - Ins_JROF( exc, args ); - break; - - case 0x7A: /* ROFF */ - Ins_ROFF( exc ); - break; - - case 0x7B: /* ???? */ - Ins_UNKNOWN( exc ); - break; - - case 0x7C: /* RUTG */ - Ins_RUTG( exc ); - break; - - case 0x7D: /* RDTG */ - Ins_RDTG( exc ); - break; - - case 0x7E: /* SANGW */ - Ins_SANGW(); - break; - - case 0x7F: /* AA */ - Ins_AA(); - break; - - case 0x80: /* FLIPPT */ - Ins_FLIPPT( exc ); - break; - - case 0x81: /* FLIPRGON */ - Ins_FLIPRGON( exc, args ); - break; - - case 0x82: /* FLIPRGOFF */ - Ins_FLIPRGOFF( exc, args ); - break; - - case 0x83: /* UNKNOWN */ - case 0x84: /* UNKNOWN */ - Ins_UNKNOWN( exc ); - break; - - case 0x85: /* SCANCTRL */ - Ins_SCANCTRL( exc, args ); - break; - - case 0x86: /* SDPvTL */ - case 0x87: /* SDPvTL */ - Ins_SDPVTL( exc, args ); - break; - - case 0x88: /* GETINFO */ - Ins_GETINFO( exc, args ); - break; - - case 0x89: /* IDEF */ - Ins_IDEF( exc, args ); - break; - - case 0x8A: /* ROLL */ - Ins_ROLL( args ); - break; - - case 0x8B: /* MAX */ - Ins_MAX( args ); - break; - - case 0x8C: /* MIN */ - Ins_MIN( args ); - break; - - case 0x8D: /* SCANTYPE */ - Ins_SCANTYPE( exc, args ); - break; - - case 0x8E: /* INSTCTRL */ - Ins_INSTCTRL( exc, args ); - break; - - case 0x8F: /* ADJUST */ - case 0x90: /* ADJUST */ - Ins_UNKNOWN( exc ); - break; - -#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT - case 0x91: - /* it is the job of the application to `activate' GX handling, */ - /* this is, calling any of the GX API functions on the current */ - /* font to select a variation instance */ - if ( exc->face->blend ) - Ins_GETVARIATION( exc, args ); - else - Ins_UNKNOWN( exc ); - break; - - case 0x92: - /* there is at least one MS font (LaoUI.ttf version 5.01) that */ - /* uses IDEFs for 0x91 and 0x92; for this reason we activate */ - /* GETDATA for GX fonts only, similar to GETVARIATION */ - if ( exc->face->blend ) - Ins_GETDATA( args ); - else - Ins_UNKNOWN( exc ); - break; -#endif - - default: - if ( opcode >= 0xE0 ) - Ins_MIRP( exc, args ); - else if ( opcode >= 0xC0 ) - Ins_MDRP( exc, args ); - else if ( opcode >= 0xB8 ) - Ins_PUSHW( exc, args ); - else if ( opcode >= 0xB0 ) - Ins_PUSHB( exc, args ); - else - Ins_UNKNOWN( exc ); - } - } - - if ( exc->error ) - { - switch ( exc->error ) - { - /* looking for redefined instructions */ - case FT_ERR( Invalid_Opcode ): - { - TT_DefRecord* def = exc->IDefs; - TT_DefRecord* limit = def + exc->numIDefs; - - - for ( ; def < limit; def++ ) - { - if ( def->active && exc->opcode == (FT_Byte)def->opc ) - { - TT_CallRec* callrec; - - - if ( exc->callTop >= exc->callSize ) - { - exc->error = FT_THROW( Invalid_Reference ); - goto LErrorLabel_; - } - - callrec = &exc->callStack[exc->callTop]; - - callrec->Caller_Range = exc->curRange; - callrec->Caller_IP = exc->IP + 1; - callrec->Cur_Count = 1; - callrec->Def = def; - - if ( Ins_Goto_CodeRange( exc, - def->range, - def->start ) == FAILURE ) - goto LErrorLabel_; - - goto LSuiteLabel_; - } - } - } - - exc->error = FT_THROW( Invalid_Opcode ); - goto LErrorLabel_; - -#if 0 - break; /* Unreachable code warning suppression. */ - /* Leave to remind in case a later change the editor */ - /* to consider break; */ -#endif - - default: - goto LErrorLabel_; - -#if 0 - break; -#endif - } - } - - exc->top = exc->new_top; - - if ( exc->step_ins ) - exc->IP += exc->length; - - /* increment instruction counter and check if we didn't */ - /* run this program for too long (e.g. infinite loops). */ - if ( ++ins_counter > TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES ) - return FT_THROW( Execution_Too_Long ); - - LSuiteLabel_: - if ( exc->IP >= exc->codeSize ) - { - if ( exc->callTop > 0 ) - { - exc->error = FT_THROW( Code_Overflow ); - goto LErrorLabel_; - } - else - goto LNo_Error_; - } - } while ( !exc->instruction_trap ); - - LNo_Error_: - FT_TRACE4(( " %d instructions executed\n", ins_counter )); - return FT_Err_Ok; - - LErrorCodeOverflow_: - exc->error = FT_THROW( Code_Overflow ); - - LErrorLabel_: - if ( exc->error && !exc->instruction_trap ) - FT_TRACE1(( " The interpreter returned error 0x%x\n", exc->error )); - - return exc->error; - } - -#else /* !TT_USE_BYTECODE_INTERPRETER */ - - /* ANSI C doesn't like empty source files */ - typedef int _tt_interp_dummy; - -#endif /* !TT_USE_BYTECODE_INTERPRETER */ - - -/* END */