Commit 1a1750fb8aa4865e428af0f1cc35c625c5fcf9d9

Werner Lemberg 2014-10-16T22:54:01

[cff] Add `CFF_CONFIG_OPTION_DARKENING_PARAMETERS' config macro. * devel/ftoption.h, include/config/ftoption.h (CFF_CONFIG_OPTION_DARKENING_PARAMETERS): New macro. * src/cff/cffobjs.c (SET_DARKENING_PARAMETERS, SET_DARKENING_PARAMETERS_0): New macros. (cff_driver_init): Use new macros.

diff --git a/ChangeLog b/ChangeLog
index aace963..55abfe7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2014-10-16  Behdad Esfahbod  <behdad@behdad.org>
+	    Werner Lemberg  <wl@gnu.org>
+
+	[cff] Add `CFF_CONFIG_OPTION_DARKENING_PARAMETERS' config macro.
+
+	* devel/ftoption.h, include/config/ftoption.h
+	(CFF_CONFIG_OPTION_DARKENING_PARAMETERS): New macro.
+
+	* src/cff/cffobjs.c (SET_DARKENING_PARAMETERS,
+	SET_DARKENING_PARAMETERS_0): New macros.
+	(cff_driver_init): Use new macros.
+
 2014-10-14  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
 	[truetype] Limit delta shift range.
diff --git a/devel/ftoption.h b/devel/ftoption.h
index d7b6a63..97f9cc2 100644
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    User-selectable configuration macros (specification only).           */
 /*                                                                         */
-/*  Copyright 1996-2013 by                                                 */
+/*  Copyright 1996-2014 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -773,6 +773,23 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* Using CFF_CONFIG_OPTION_DARKENING_PARAMETERS it is possible to set up */
+  /* the default values of the four control points that define the stem    */
+  /* darkening behaviour of the (new) CFF engine.  For more details please */
+  /* read the documentation of the `darkening-parameters' property of the  */
+  /* cff driver module (file `ftcffdrv.h'), which allows the control at    */
+  /* run-time.                                                             */
+  /*                                                                       */
+  /* Do *not* undefine this macro!                                         */
+  /*                                                                       */
+#define CFF_CONFIG_OPTION_DARKENING_PARAMETERS   500, 400, \
+                                                1000, 275, \
+                                                1667, 275, \
+                                                2333,   0
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* CFF_CONFIG_OPTION_OLD_ENGINE controls whether the pre-Adobe CFF       */
   /* engine gets compiled into FreeType.  If defined, it is possible to    */
   /* switch between the two engines using the `hinting-engine' property of */
diff --git a/include/config/ftoption.h b/include/config/ftoption.h
index 5b11f0e..46979e7 100644
--- a/include/config/ftoption.h
+++ b/include/config/ftoption.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    User-selectable configuration macros (specification only).           */
 /*                                                                         */
-/*  Copyright 1996-2013 by                                                 */
+/*  Copyright 1996-2014 by                                                 */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -773,6 +773,23 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* Using CFF_CONFIG_OPTION_DARKENING_PARAMETERS it is possible to set up */
+  /* the default values of the four control points that define the stem    */
+  /* darkening behaviour of the (new) CFF engine.  For more details please */
+  /* read the documentation of the `darkening-parameters' property of the  */
+  /* cff driver module (file `ftcffdrv.h'), which allows the control at    */
+  /* run-time.                                                             */
+  /*                                                                       */
+  /* Do *not* undefine this macro!                                         */
+  /*                                                                       */
+#define CFF_CONFIG_OPTION_DARKENING_PARAMETERS   500, 400, \
+                                                1000, 275, \
+                                                1667, 275, \
+                                                2333,   0
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* CFF_CONFIG_OPTION_OLD_ENGINE controls whether the pre-Adobe CFF       */
   /* engine gets compiled into FreeType.  If defined, it is possible to    */
   /* switch between the two engines using the `hinting-engine' property of */
diff --git a/include/ftcffdrv.h b/include/ftcffdrv.h
index e4d039d..49c1e6e 100644
--- a/include/ftcffdrv.h
+++ b/include/ftcffdrv.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType API for controlling the CFF driver (specification only).    */
 /*                                                                         */
-/*  Copyright 2013 by                                                      */
+/*  Copyright 2013, 2014 by                                                */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -212,9 +212,11 @@ FT_BEGIN_HEADER
    *     stem width >= 2.333px: darkening amount = 0px
    *   }
    *
-   *   and piecewise linear in-between.  Using the `darkening-parameters'
-   *   property, these four control points can be changed, as the following
-   *   example demonstrates.
+   *   and piecewise linear in-between.  At configuration time, these four
+   *   control points can be set with the macro
+   *   `CFF_CONFIG_OPTION_DARKENING_PARAMETERS'.  At runtime, the control
+   *   points can be changed using the `darkening-parameters' property, as
+   *   the following example demonstrates.
    *
    *   {
    *     FT_Library  library;
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index cac4ac2..b42aa88 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -1049,13 +1049,41 @@
   }
 
 
+#define SET_DARKENING_PARAMETERS_0( driver,                                \
+                                    x1, y1,                                \
+                                    x2, y2,                                \
+                                    x3, y3,                                \
+                                    x4, y4 )                               \
+          FT_BEGIN_STMNT                                                   \
+            /* checks copied from `cff_property_set' in `cffdrivr.c' */    \
+            typedef int  static_assert_darkening_parameters[               \
+              ( x1 < 0   || x2 < 0   || x3 < 0   || x4 < 0   ||            \
+                y1 < 0   || y2 < 0   || y3 < 0   || y4 < 0   ||            \
+                x1 > x2  || x2 > x3  || x3 > x4              ||            \
+                y1 > 500 || y2 > 500 || y3 > 500 || y4 > 500 ) ? -1 : +1]; \
+                                                                           \
+                                                                           \
+            driver->darken_params[0] = x1;                                 \
+            driver->darken_params[1] = y1;                                 \
+            driver->darken_params[2] = x2;                                 \
+            driver->darken_params[3] = y2;                                 \
+            driver->darken_params[4] = x3;                                 \
+            driver->darken_params[5] = y3;                                 \
+            driver->darken_params[6] = x4;                                 \
+            driver->darken_params[7] = y4;                                 \
+          FT_END_STMNT
+
+#define SET_DARKENING_PARAMETERS( driver, params )     \
+          SET_DARKENING_PARAMETERS_0( driver, params )
+
+
   FT_LOCAL_DEF( FT_Error )
   cff_driver_init( FT_Module  module )        /* CFF_Driver */
   {
     CFF_Driver  driver = (CFF_Driver)module;
 
 
-    /* set default property values, cf `ftcffdrv.h' */
+    /* set default property values, cf. `ftcffdrv.h' */
 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
     driver->hinting_engine    = FT_CFF_HINTING_FREETYPE;
 #else
@@ -1063,14 +1091,8 @@
 #endif
     driver->no_stem_darkening = FALSE;
 
-    driver->darken_params[0] =  500;
-    driver->darken_params[1] =  400;
-    driver->darken_params[2] = 1000;
-    driver->darken_params[3] =  275;
-    driver->darken_params[4] = 1667;
-    driver->darken_params[5] =  275;
-    driver->darken_params[6] = 2333;
-    driver->darken_params[7] =    0;
+    SET_DARKENING_PARAMETERS( driver,
+                              CFF_CONFIG_OPTION_DARKENING_PARAMETERS );
 
     return FT_Err_Ok;
   }