Commit 97704b158ed7eafde7eac8794e1c7df55a58fff7

Ewald Hew 2017-09-25T06:33:28

Add Adobe engine configuration. Use the previously changed PS_Driver in type1 module to store hinting engine configuration. * include/freetype/ftt1drv.h: New file. Duplicate and rename config options from CFF. * include/freetype/config/ftheader.h (FT_TYPE1_DRIVER_H): New macro. * src/type1/t1driver.c (t1_driver_class): Update declaration. * src/type1/t1objs.c: Include FT_TYPE1_DRIVER_H. (T1_Driver_Init): Update code.

diff --git a/ChangeLog b/ChangeLog
index d6d0be1..bfe2237 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2017-09-25  Ewald Hew  <ewaldhew@gmail.com>
 
+	[type1] Add Adobe engine configuration.
+
+	Use the previously changed PS_Driver in type1 module to store
+	hinting engine configuration.
+
+	* include/freetype/ftt1drv.h: New file.
+	Duplicate and rename config options from CFF.
+	* include/freetype/config/ftheader.h (FT_TYPE1_DRIVER_H): New macro.
+
+	* src/type1/t1driver.c (t1_driver_class): Update declaration.
+	* src/type1/t1objs.c: Include FT_TYPE1_DRIVER_H.
+	(T1_Driver_Init): Update code.
+
+2017-09-25  Ewald Hew  <ewaldhew@gmail.com>
+
 	[cff] Move and rename `CFF_Driver'.
 
 	This is so that we can use the same hinting engine parameters for
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index d491af5..ce3b7ee 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -370,6 +370,19 @@
   /*************************************************************************
    *
    * @macro:
+   *   FT_TYPE1_DRIVER_H
+   *
+   * @description:
+   *   A macro used in #include statements to name the file containing
+   *   structures and macros related to the Type~1 driver module.
+   *
+   */
+#define FT_TYPE1_DRIVER_H  <freetype/ftt1drv.h>
+
+
+  /*************************************************************************
+   *
+   * @macro:
    *   FT_TYPE1_TABLES_H
    *
    * @description:
diff --git a/include/freetype/ftt1drv.h b/include/freetype/ftt1drv.h
new file mode 100644
index 0000000..116b33b
--- /dev/null
+++ b/include/freetype/ftt1drv.h
@@ -0,0 +1,116 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftt1drv.h                                                              */
+/*                                                                         */
+/*    FreeType API for controlling the Type 1 driver (specification only). */
+/*                                                                         */
+/*  Copyright 2013-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 FTT1DRV_H_
+#define FTT1DRV_H_
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#ifdef FREETYPE_H
+#error "freetype.h of FreeType 1 has been loaded!"
+#error "Please fix the directory search order for header files"
+#error "so that freetype.h of FreeType 2 is found first."
+#endif
+
+
+FT_BEGIN_HEADER
+
+
+
+  /**************************************************************************
+   *
+   * @property:
+   *   hinting-engine[type1]
+   *
+   * @description:
+   *   Thanks to Adobe, which contributed a new hinting (and parsing)
+   *   engine, an application can select between `freetype' and `adobe' if
+   *   compiled with T1_CONFIG_OPTION_OLD_ENGINE.  If this configuration
+   *   macro isn't defined, `hinting-engine' does nothing.
+   *
+   *   The default engine is `freetype' if T1_CONFIG_OPTION_OLD_ENGINE is
+   *   defined, and `adobe' otherwise.
+   *
+   *   The following example code demonstrates how to select Adobe's hinting
+   *   engine (omitting the error handling).
+   *
+   *   {
+   *     FT_Library  library;
+   *     FT_UInt     hinting_engine = FT_T1_HINTING_ADOBE;
+   *
+   *
+   *     FT_Init_FreeType( &library );
+   *
+   *     FT_Property_Set( library, "type1",
+   *                               "hinting-engine", &hinting_engine );
+   *   }
+   *
+   * @note:
+   *   This property can be used with @FT_Property_Get also.
+   *
+   *   This property can be set via the `FREETYPE_PROPERTIES' environment
+   *   variable (using values `adobe' or `freetype').
+   */
+
+
+  /**************************************************************************
+   *
+   * @enum:
+   *   FT_T1_HINTING_XXX
+   *
+   * @description:
+   *   A list of constants used for the @hinting-engine[type1] property to
+   *   select the hinting engine for Type 1 fonts.
+   *
+   * @values:
+   *   FT_T1_HINTING_FREETYPE ::
+   *     Use the old FreeType hinting engine.
+   *
+   *   FT_T1_HINTING_ADOBE ::
+   *     Use the hinting engine contributed by Adobe.
+   *
+   */
+#define FT_T1_HINTING_FREETYPE  0
+#define FT_T1_HINTING_ADOBE     1
+
+  /**************************************************************************
+   *
+   * @constant:
+   *   FT_PARAM_TAG_RANDOM_SEED
+   *
+   * @description:
+   *   An @FT_Parameter tag to be used with @FT_Face_Properties.  The
+   *   corresponding 32bit signed integer argument overrides the CFF
+   *   module's random seed value with a face-specific one; see
+   *   @random-seed.
+   *
+   */
+#define FT_PARAM_TAG_RANDOM_SEED \
+          FT_MAKE_TAG( 's', 'e', 'e', 'd' )
+
+  /* */
+
+
+FT_END_HEADER
+
+
+#endif /* FTT1DRV_H_ */
+
+
+/* END */
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index c208994..866a824 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -713,7 +713,7 @@
       FT_MODULE_DRIVER_SCALABLE   |
       FT_MODULE_DRIVER_HAS_HINTER,
 
-      sizeof ( FT_DriverRec ),
+      sizeof ( PS_DriverRec ),
 
       "type1",
       0x10000L,
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 5ac1292..dab556f 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -21,6 +21,7 @@
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_STREAM_H
 #include FT_TRUETYPE_IDS_H
+#include FT_TYPE1_DRIVER_H
 
 #include "t1gload.h"
 #include "t1load.h"
@@ -578,9 +579,38 @@
   /*    FreeType error code.  0 means success.                             */
   /*                                                                       */
   FT_LOCAL_DEF( FT_Error )
-  T1_Driver_Init( FT_Module  driver )
+  T1_Driver_Init( FT_Module  module )
   {
-    FT_UNUSED( driver );
+    PS_Driver  driver = (PS_Driver)module;
+
+    FT_UInt32  seed;
+
+
+    /* set default property values, cf. `ftt1drv.h' */
+    driver->hinting_engine = FT_T1_HINTING_FREETYPE;
+
+    driver->no_stem_darkening = TRUE;
+
+    driver->darken_params[0] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X1;
+    driver->darken_params[1] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y1;
+    driver->darken_params[2] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X2;
+    driver->darken_params[3] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y2;
+    driver->darken_params[4] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X3;
+    driver->darken_params[5] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y3;
+    driver->darken_params[6] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_X4;
+    driver->darken_params[7] = CFF_CONFIG_OPTION_DARKENING_PARAMETER_Y4;
+
+    /* compute random seed from some memory addresses */
+    seed = (FT_UInt32)( (FT_Offset)(char*)&seed          ^
+                        (FT_Offset)(char*)&module        ^
+                        (FT_Offset)(char*)module->memory );
+    seed = seed ^ ( seed >> 10 ) ^ ( seed >> 20 );
+
+    driver->random_seed = (FT_Int32)seed;
+    if ( driver->random_seed < 0 )
+      driver->random_seed = -driver->random_seed;
+    else if ( driver->random_seed == 0 )
+      driver->random_seed = 123456789;
 
     return FT_Err_Ok;
   }