freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] master 84d3df7 2/4: Implement handling of `FREETYPE_PROPERTI


From: Werner LEMBERG
Subject: [freetype2] master 84d3df7 2/4: Implement handling of `FREETYPE_PROPERTIES' environment variable.
Date: Mon, 11 Jul 2016 13:13:12 +0000 (UTC)

branch: master
commit 84d3df75012a4b5b0b94966bcfaffd73d7f52824
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    Implement handling of `FREETYPE_PROPERTIES' environment variable.
    
    Recognizing properties follows in another commit.
    
    * devel/ftoption.h, include/freetype/config/ftoption.h
    (FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES): New macro.
    
    * include/freetype/config/ftstdlib.h (ft_getenv): New macro.
    
    * src/base/ftinit.c (ft_set_default_properties): New function to
    parse `FREETYPE_PROPERTIES' and calling `ft_property_string_set'.
    (FT_Init_FreeType): Updated.
---
 ChangeLog                          |   15 +++++
 devel/ftoption.h                   |   30 ++++++++++
 include/freetype/config/ftoption.h |   30 ++++++++++
 include/freetype/config/ftstdlib.h |    3 +-
 src/base/ftinit.c                  |  111 ++++++++++++++++++++++++++++++++++++
 5 files changed, 188 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 0853725..4f917b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2016-07-10  Werner Lemberg  <address@hidden>
+
+       Implement handling of `FREETYPE_PROPERTIES' environment variable.
+
+       Recognizing properties follows in another commit.
+
+       * devel/ftoption.h, include/freetype/config/ftoption.h
+       (FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES): New macro.
+
+       * include/freetype/config/ftstdlib.h (ft_getenv): New macro.
+
+       * src/base/ftinit.c (ft_set_default_properties): New function to
+       parse `FREETYPE_PROPERTIES' and calling `ft_property_string_set'.
+       (FT_Init_FreeType): Updated.
+
 2016-07-09  Werner Lemberg  <address@hidden>
 
        Add function `ft_property_string_set'.
diff --git a/devel/ftoption.h b/devel/ftoption.h
index d20df81..a29e464 100644
--- a/devel/ftoption.h
+++ b/devel/ftoption.h
@@ -77,6 +77,36 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* If you enable this configuration option, FreeType recognizes an       */
+  /* environment variable called `FREETYPE_PROPERTIES', which can be used  */
+  /* to control the various font drivers and modules.  The controllable    */
+  /* properties are listed in the section `Controlling FreeType Modules'   */
+  /* in the reference's table of contents; currently there are properties  */
+  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'), and  */
+  /* TrueType (file `ftttdrv.h').                                          */
+  /*                                                                       */
+  /* `FREETYPE_PROPERTIES' has the following syntax form (broken here into */
+  /* multiple lines for better readability).                               */
+  /*                                                                       */
+  /*   <optional whitespace>                                               */
+  /*   <module-name1> ':'                                                  */
+  /*   <property-name1> '=' <property-value1>                              */
+  /*   <whitespace>                                                        */
+  /*   <module-name2> ':'                                                  */
+  /*   <property-name2> '=' <property-value2>                              */
+  /*   ...                                                                 */
+  /*                                                                       */
+  /* Example:                                                              */
+  /*                                                                       */
+  /*   FREETYPE_PROPERTIES=truetype:interpreter-version=35 \               */
+  /*                       cff:no-stem-darkening=1 \                       */
+  /*                       autofitter:warping=1                            */
+  /*                                                                       */
+#define FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* Uncomment the line below if you want to activate sub-pixel rendering  */
   /* (a.k.a. LCD rendering, or ClearType) in this build of the library.    */
   /*                                                                       */
diff --git a/include/freetype/config/ftoption.h 
b/include/freetype/config/ftoption.h
index 7dd3f55..80f7e28 100644
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -77,6 +77,36 @@ FT_BEGIN_HEADER
 
   /*************************************************************************/
   /*                                                                       */
+  /* If you enable this configuration option, FreeType recognizes an       */
+  /* environment variable called `FREETYPE_PROPERTIES', which can be used  */
+  /* to control the various font drivers and modules.  The controllable    */
+  /* properties are listed in the section `Controlling FreeType Modules'   */
+  /* in the reference's table of contents; currently there are properties  */
+  /* for the auto-hinter (file `ftautoh.h'), CFF (file `ftcffdrv.h'), and  */
+  /* TrueType (file `ftttdrv.h').                                          */
+  /*                                                                       */
+  /* `FREETYPE_PROPERTIES' has the following syntax form (broken here into */
+  /* multiple lines for better readability).                               */
+  /*                                                                       */
+  /*   <optional whitespace>                                               */
+  /*   <module-name1> ':'                                                  */
+  /*   <property-name1> '=' <property-value1>                              */
+  /*   <whitespace>                                                        */
+  /*   <module-name2> ':'                                                  */
+  /*   <property-name2> '=' <property-value2>                              */
+  /*   ...                                                                 */
+  /*                                                                       */
+  /* Example:                                                              */
+  /*                                                                       */
+  /*   FREETYPE_PROPERTIES=truetype:interpreter-version=35 \               */
+  /*                       cff:no-stem-darkening=1 \                       */
+  /*                       autofitter:warping=1                            */
+  /*                                                                       */
+#define FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
+
+
+  /*************************************************************************/
+  /*                                                                       */
   /* Uncomment the line below if you want to activate sub-pixel rendering  */
   /* (a.k.a. LCD rendering, or ClearType) in this build of the library.    */
   /*                                                                       */
diff --git a/include/freetype/config/ftstdlib.h 
b/include/freetype/config/ftstdlib.h
index 562e255..58b95a7 100644
--- a/include/freetype/config/ftstdlib.h
+++ b/include/freetype/config/ftstdlib.h
@@ -142,7 +142,8 @@
   /**********************************************************************/
 
 
-#define ft_atol  atol
+#define ft_atol    atol
+#define ft_getenv  getenv
 
 
   /**********************************************************************/
diff --git a/src/base/ftinit.c b/src/base/ftinit.c
index c2dd0a7..02ef938 100644
--- a/src/base/ftinit.c
+++ b/src/base/ftinit.c
@@ -226,6 +226,115 @@
   }
 
 
+#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
+
+#define MAX_LENGTH  128
+
+  /*
+   * Set default properties derived from the `FREETYPE_PROPERTIES'
+   * environment variable.
+   *
+   * `FREETYPE_PROPERTIES' has the following syntax form (broken here into
+   * multiple lines for better readability)
+   *
+   *   <optional whitespace>
+   *   <module-name1> ':'
+   *   <property-name1> '=' <property-value1>
+   *   <whitespace>
+   *   <module-name2> ':'
+   *   <property-name2> '=' <property-value2>
+   *   ...
+   *
+   * Example:
+   *
+   *   FREETYPE_PROPERTIES=truetype:interpreter-version=35 \
+   *                       cff:no-stem-darkening=1 \
+   *                       autofitter:warping=1
+   *
+   */
+
+  static void
+  ft_set_default_properties( FT_Library  library )
+  {
+    const char*  env;
+    const char*  p;
+    const char*  q;
+
+    char  module_name[MAX_LENGTH + 1];
+    char  property_name[MAX_LENGTH + 1];
+    char  property_value[MAX_LENGTH + 1];
+
+    int  i;
+
+
+    env = ft_getenv( "FREETYPE_PROPERTIES" );
+    if ( !env )
+      return;
+
+    for ( p = env; *p; p++ )
+    {
+      /* skip leading whitespace and separators */
+      if ( *p == ' ' || *p == '\t' )
+        continue;
+
+      /* read module name, followed by `:' */
+      q = p;
+      for ( i = 0; i < MAX_LENGTH; i++ )
+      {
+        if ( !*p || *p == ':' )
+          break;
+        module_name[i] = *p++;
+      }
+      module_name[i] = '\0';
+
+      if ( !*p || *p != ':' || p == q )
+        break;
+
+      /* read property name, followed by `=' */
+      q = ++p;
+      for ( i = 0; i < MAX_LENGTH; i++ )
+      {
+        if ( !*p || *p == '=' )
+          break;
+        property_name[i] = *p++;
+      }
+      property_name[i] = '\0';
+
+      if ( !*p || *p != '=' || p == q )
+        break;
+
+      /* read property value, followed by whitespace (if any) */
+      q = ++p;
+      for ( i = 0; i < MAX_LENGTH; i++ )
+      {
+        if ( !*p || *p == ' ' || *p == '\t' )
+          break;
+        property_value[i] = *p++;
+      }
+      property_value[i] = '\0';
+
+      if ( !( *p == '\0' || *p == ' ' || *p == '\t' ) || p == q )
+        break;
+
+      /* we completely ignore errors */
+      ft_property_string_set( library,
+                              module_name,
+                              property_name,
+                              property_value );
+    }
+  }
+
+#else
+
+  static void
+  ft_set_default_properties( FT_Library  library )
+  {
+    FT_UNUSED( library );
+  }
+
+#endif
+
+
   /* documentation is in freetype.h */
 
   FT_EXPORT_DEF( FT_Error )
@@ -256,6 +365,8 @@
     else
       FT_Add_Default_Modules( *alibrary );
 
+    ft_set_default_properties( *alibrary );
+
     return error;
   }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]