shithub: freetype+ttf2subf

Download patch

ref: 2f70965f9f094385654f881d73cb73a82b3e6ada
parent: 0d52639603e266f662e8639b4aa7514d5ff6f384
author: David Turner <[email protected]>
date: Wed Jan 22 17:45:28 EST 2003

* include/freetype/ftbdf.h, include/freetype/internal/bdftypes.h,
    src/base/ftbdf.c, src/bdf/bdfdrivr.c, src/pcf/pcfdrivr.c,
    src/pcf/pcfread.h:

      adding a new API, named FT_Get_BDF_Property to retrieve the BDF
      properties of a given PCF or BDF font

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-01-22  David Turner  <[email protected]>
+
+    * include/freetype/ftbdf.h, include/freetype/internal/bdftypes.h,
+    src/base/ftbdf.c, src/bdf/bdfdrivr.c, src/pcf/pcfdrivr.c,
+    src/pcf/pcfread.h:
+
+      adding a new API, named FT_Get_BDF_Property to retrieve the BDF
+      properties of a given PCF or BDF font
+
+
 2003-01-18  Werner Lemberg  <[email protected]>
 
 	* builds/unix/ltmain.sh: Regenerated with `libtoolize --force
@@ -145,7 +155,7 @@
 
 2002-12-02  Antoine Leca  <[email protected]>
 
-	* src/base/ftobjs.c: Modified the logic to get Unicode charmaps. 
+	* src/base/ftobjs.c: Modified the logic to get Unicode charmaps.
 	Now it loads UCS-4 charmaps when there is one.
 	* src/base/ftobjs.c (find_unicode_charmap): New function.
 	* src/base/ftobjs.c (open_face): Refer to the above one.
@@ -200,7 +210,7 @@
 	the use of system-wide zlib.
 
 	Note that this macro, as well as
-	FT_CONFIG_OPTION_BYTECODE_INTERPRETER, is not #undef-ed anymore. 
+	FT_CONFIG_OPTION_BYTECODE_INTERPRETER, is not #undef-ed anymore.
 	This allows the build system to define them depending on the
 	configuration (typically by adding -D flags at compile time).
 
--- a/include/freetype/ftbdf.h
+++ b/include/freetype/ftbdf.h
@@ -45,6 +45,73 @@
 
  /**********************************************************************
   *
+  * @enum:
+  *    FT_PropertyType
+  *
+  * @description:
+  *    list of BDF property types
+  *
+  * @values:
+  *    BDF_PROPERTY_TYPE_NONE ::
+  *      value 0 is used to indicate a missing property
+  *
+  *    BDF_PROPERTY_TYPE_ATOM ::
+  *      property is a string atom
+  *
+  *    BDF_PROPERTY_TYPE_INTEGER ::
+  *      property is a 32-bit signed integer
+  *
+  *    BDF_PROPERTY_TYPE_CARDINAL ::
+  *      property is a 32-bit unsigned integer
+  */
+  typedef enum
+  {
+    BDF_PROPERTY_TYPE_NONE     = 0,
+    BDF_PROPERTY_TYPE_ATOM     = 1,
+    BDF_PROPERTY_TYPE_INTEGER  = 2,
+    BDF_PROPERTY_TYPE_CARDINAL = 3
+
+  } BDF_PropertyType;
+
+
+ /**********************************************************************
+  *
+  * @type:  BDF_Property
+  *
+  * @description:
+  *    handle to a @BDF_PropertyRec structure used to model a given
+  *    BDF/PCF property
+  */
+  typedef struct BDF_PropertyRec_*   BDF_Property;
+
+ /**********************************************************************
+  *
+  * @struct:  BDF_PropertyRec
+  *
+  * @description:
+  *    models a given BDF/PCF property
+  *
+  * @note:
+  *    type       :: property type
+  *    u.atom     :: atom string, when type is @BDF_PROPERTY_TYPE_ATOM
+  *    u.integer  :: signed integer, when type is @BDF_PROPERTY_TYPE_INTEGER
+  *    u.cardinal :: unsigned integer, when type is @BDF_PROPERTY_TYPE_CARDINAL
+  */
+  typedef struct BDF_PropertyRec_
+  {
+    BDF_PropertyType   type;
+    union {
+      const char*   atom;
+      FT_Int32      integer;
+      FT_UInt32     cardinal;
+
+    } u;
+
+  } BDF_PropertyRec;
+
+
+ /**********************************************************************
+  *
   * @function:
   *    FT_Get_BDF_Charset_ID
   *
@@ -73,6 +140,37 @@
   FT_Get_BDF_Charset_ID( FT_Face       face,
                          const char*  *acharset_encoding,
                          const char*  *acharset_registry );
+
+ /**********************************************************************
+  *
+  * @function:
+  *    FT_Get_BDF_Property
+  *
+  * @description:
+  *    Retrieves a BDF property from a BDF or PCF font file
+  *
+  * @input:
+  *    face :: handle to input face
+  *    name :: property name
+  *
+  * @output:
+  *    aproperty :: the property
+  *
+  * @return:
+  *   FreeType error code.  0 means success.
+  *
+  * @note:
+  *   This function works with BDF _and_ PCF fonts. It returns an error
+  *   otherwise. it also returns an error when the property is not in the
+  *   font.
+  *
+  *   in case of error, "aproperty->type" is always set to
+  *   @BDF_PROPERTY_TYPE_NONE
+  */
+  FT_EXPORT( FT_Error )
+  FT_Get_BDF_Property( FT_Face           face,
+                       const char*       prop_name,
+                       BDF_PropertyRec  *aproperty );
 
  /* */
 
--- a/include/freetype/internal/bdftypes.h
+++ b/include/freetype/internal/bdftypes.h
@@ -29,6 +29,7 @@
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
+#include FT_BDF_H
 
 
 FT_BEGIN_HEADER
@@ -43,6 +44,10 @@
 
   } BDF_Public_FaceRec, *BDF_Public_Face;
 
+
+  typedef FT_Error  (*BDF_GetPropertyFunc)( FT_Face           face,
+                                            const char*       prop_name,
+                                            BDF_PropertyRec  *aproperty );
 
 FT_END_HEADER
 
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -462,6 +462,8 @@
   FT_Get_Module_Interface( FT_Library   library,
                            const char*  mod_name );
 
+ /* */
+
 
   /*************************************************************************/
   /*************************************************************************/
--- a/src/base/ftbdf.c
+++ b/src/base/ftbdf.c
@@ -20,7 +20,23 @@
 #include FT_INTERNAL_BDF_TYPES_H
 #include FT_INTERNAL_OBJECTS_H
 
+  static FT_Bool
+  test_font_type( FT_Face face, const char*  name )
+  {
+    if ( face && face->driver )
+    {
+      FT_Module  driver = (FT_Module)face->driver;
 
+      if ( driver->clazz && driver->clazz->module_name )
+      {
+        if ( ft_strcmp( driver->clazz->module_name, name ) == 0 )
+          return 1;
+      }
+    }
+    return 0;
+  }
+
+
   FT_EXPORT_DEF( FT_Error )
   FT_Get_BDF_Charset_ID( FT_Face       face,
                          const char*  *acharset_encoding,
@@ -29,35 +45,52 @@
     FT_Error     error;
     const char*  encoding = NULL;
     const char*  registry = NULL;
-    
 
+
     error = FT_Err_Invalid_Argument;
-    
-    if ( face != NULL && face->driver != NULL )
+
+    if ( test_font_type( face, "bdf" ) )
     {
-      FT_Module  driver = (FT_Module) face->driver;
-      
+      BDF_Public_Face  bdf_face = (BDF_Public_Face)face;
 
-      if ( driver->clazz && driver->clazz->module_name         &&
-           ft_strcmp( driver->clazz->module_name, "bdf" ) == 0 )
-      {
-        BDF_Public_Face  bdf_face = (BDF_Public_Face)face;
-        
 
-        encoding = (const char*) bdf_face->charset_encoding;
-        registry = (const char*) bdf_face->charset_registry;
-        error    = 0;
-      }           
+      encoding = (const char*) bdf_face->charset_encoding;
+      registry = (const char*) bdf_face->charset_registry;
+      error    = 0;
     }
-  
+
     if ( acharset_encoding )
       *acharset_encoding = encoding;
-    
+
     if ( acharset_registry )
       *acharset_registry = registry;
-    
+
     return error;
-  }                         
+  }
 
+
+  FT_EXPORT( FT_Error )
+  FT_Get_BDF_Property( FT_Face           face,
+                       const char*       prop_name,
+                       BDF_PropertyRec  *aproperty )
+  {
+    FT_Error   error;
+
+    error = FT_Err_Invalid_Argument;
+
+    aproperty->type = BDF_PROPERTY_TYPE_NONE;
+
+    if ( face != NULL && face->driver != NULL )
+    {
+      FT_Driver              driver = face->driver;
+      BDF_GetPropertyFunc    func;
+
+      func = (BDF_GetPropertyFunc) driver->root.clazz->get_interface(
+                             FT_MODULE( driver ), "get_bdf_property" );
+      if ( func )
+        error = func( face, prop_name, aproperty );
+    }
+    return error;
+  }
 
 /* END */
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -29,6 +29,7 @@
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_OBJECTS_H
+#include FT_BDF_H
 
 #include "bdf.h"
 #include "bdfdrivr.h"
@@ -631,6 +632,58 @@
   }
 
 
+  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, (char*)prop_name );
+    if ( prop != NULL )
+    {
+      switch ( prop->format )
+      {
+        case BDF_ATOM:
+          aproperty->type   = BDF_PROPERTY_TYPE_ATOM;
+          aproperty->u.atom = prop->value.atom;
+          break;
+
+        case BDF_INTEGER:
+          aproperty->type      = BDF_PROPERTY_TYPE_INTEGER;
+          aproperty->u.integer = prop->value.int32;
+          break;
+
+        case BDF_CARDINAL:
+          aproperty->type       = BDF_PROPERTY_TYPE_CARDINAL;
+          aproperty->u.cardinal = prop->value.card32;
+          break;
+
+        default:
+          goto Fail;
+      }
+      return 0;
+    }
+  Fail:
+    return FT_Err_Invalid_Argument;
+  }
+
+
+  static FT_Module_Interface
+  bdf_driver_requester( FT_Module    module,
+                        const char*  name )
+  {
+    FT_UNUSED( module );
+
+    if ( name && ft_strcmp( name, "get_bdf_property" ) == 0 )
+      return (FT_Module_Interface) bdf_get_bdf_property;
+
+    return NULL;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const FT_Driver_ClassRec  bdf_driver_class =
   {
@@ -646,7 +699,7 @@
 
       (FT_Module_Constructor)0,
       (FT_Module_Destructor) 0,
-      (FT_Module_Requester)  0
+      (FT_Module_Requester)  bdf_driver_requester
     },
 
     sizeof ( BDF_FaceRec ),
--- a/src/pcf/pcf.h
+++ b/src/pcf/pcf.h
@@ -229,7 +229,6 @@
   pcf_load_font( FT_Stream,
                  PCF_Face );
 
-
 FT_END_HEADER
 
 #endif /* __PCF_H__ */
--- a/src/pcf/pcfdriver.c
+++ b/src/pcf/pcfdriver.c
@@ -32,10 +32,12 @@
 #include FT_INTERNAL_OBJECTS_H
 #include FT_GZIP_H
 #include FT_ERRORS_H
+#include FT_BDF_H
 
 #include "pcf.h"
 #include "pcfdriver.h"
 #include "pcfutil.h"
+#include "pcfread.h"
 
 #include "pcferror.h"
 
@@ -458,6 +460,49 @@
   }
 
 
+  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 != NULL )
+    {
+      if ( prop->isString )
+      {
+        aproperty->type   = BDF_PROPERTY_TYPE_ATOM;
+        aproperty->u.atom = prop->value.atom;
+      }
+      else
+      {
+       /* apparently, 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 = prop->value.integer;
+      }
+      return 0;
+    }
+    return FT_Err_Invalid_Argument;
+  }
+
+
+  static FT_Module_Interface
+  pcf_driver_requester( FT_Module    module,
+                        const char*  name )
+  {
+    FT_UNUSED( module );
+
+    if ( name && ft_strcmp( name, "get_bdf_property" ) == 0 )
+      return (FT_Module_Interface) pcf_get_bdf_property;
+
+    return NULL;
+  }
+
+
   FT_CALLBACK_TABLE_DEF
   const FT_Driver_ClassRec  pcf_driver_class =
   {
@@ -473,7 +518,7 @@
 
       (FT_Module_Constructor)0,
       (FT_Module_Destructor) 0,
-      (FT_Module_Requester)  0
+      (FT_Module_Requester)  pcf_driver_requester
     },
 
     sizeof( PCF_FaceRec ),
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -33,6 +33,7 @@
 
 #include "pcf.h"
 #include "pcfdriver.h"
+#include "pcfread.h"
 
 #include "pcferror.h"
 
@@ -316,7 +317,7 @@
   };
 
 
-  static PCF_Property
+  FT_LOCAL_DEF( PCF_Property )
   pcf_find_property( PCF_Face          face,
                      const FT_String*  prop )
   {
--- /dev/null
+++ b/src/pcf/pcfread.h
@@ -1,0 +1,45 @@
+/*  pcfread.h
+
+    FreeType font driver for pcf fonts
+
+  Copyright 2000-2001 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.
+*/
+
+
+#ifndef __PCFREAD_H__
+#define __PCFREAD_H__
+
+
+#include <ft2build.h>
+
+FT_BEGIN_HEADER
+
+  FT_LOCAL( PCF_Property )
+  pcf_find_property( PCF_Face          face,
+                     const FT_String*  prop );
+
+FT_END_HEADER
+
+#endif /* __PCFUTIL_H__ */
+
+
+/* END */