From 2f70965f9f094385654f881d73cb73a82b3e6ada Mon Sep 17 00:00:00 2001 From: David Turner Date: Wed, 22 Jan 2003 22:45:28 +0000 Subject: [PATCH] * 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 --- ChangeLog | 14 +++- include/freetype/ftbdf.h | 98 ++++++++++++++++++++++++++++ include/freetype/internal/bdftypes.h | 5 ++ include/freetype/internal/ftobjs.h | 2 + src/base/ftbdf.c | 71 ++++++++++++++------ src/bdf/bdfdrivr.c | 55 +++++++++++++++- src/pcf/pcf.h | 1 - src/pcf/pcfdriver.c | 47 ++++++++++++- src/pcf/pcfread.c | 3 +- src/pcf/pcfread.h | 45 +++++++++++++ 10 files changed, 316 insertions(+), 25 deletions(-) create mode 100644 src/pcf/pcfread.h diff --git a/ChangeLog b/ChangeLog index 96b45d320..57edb2a53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-01-22 David Turner + + * 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 * builds/unix/ltmain.sh: Regenerated with `libtoolize --force @@ -145,7 +155,7 @@ 2002-12-02 Antoine Leca - * 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). diff --git a/include/freetype/ftbdf.h b/include/freetype/ftbdf.h index c33f9fc21..71735e3c6 100644 --- a/include/freetype/ftbdf.h +++ b/include/freetype/ftbdf.h @@ -43,6 +43,73 @@ FT_BEGIN_HEADER /*************************************************************************/ + /********************************************************************** + * + * @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: @@ -74,6 +141,37 @@ FT_BEGIN_HEADER 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 ); + /* */ FT_END_HEADER diff --git a/include/freetype/internal/bdftypes.h b/include/freetype/internal/bdftypes.h index cd4dcabd8..3a1ec6435 100644 --- a/include/freetype/internal/bdftypes.h +++ b/include/freetype/internal/bdftypes.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include #include FT_FREETYPE_H +#include FT_BDF_H FT_BEGIN_HEADER @@ -44,6 +45,10 @@ FT_BEGIN_HEADER } BDF_Public_FaceRec, *BDF_Public_Face; + typedef FT_Error (*BDF_GetPropertyFunc)( FT_Face face, + const char* prop_name, + BDF_PropertyRec *aproperty ); + FT_END_HEADER diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index 5ccd5dc08..759d121bd 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -462,6 +462,8 @@ FT_BEGIN_HEADER FT_Get_Module_Interface( FT_Library library, const char* mod_name ); + /* */ + /*************************************************************************/ /*************************************************************************/ diff --git a/src/base/ftbdf.c b/src/base/ftbdf.c index 04579554b..3e76e9f32 100644 --- a/src/base/ftbdf.c +++ b/src/base/ftbdf.c @@ -20,6 +20,22 @@ #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, @@ -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; - } + 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 */ diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c index 0e9197f07..c156bd8ac 100644 --- a/src/bdf/bdfdrivr.c +++ b/src/bdf/bdfdrivr.c @@ -29,6 +29,7 @@ THE SOFTWARE. #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 @@ THE SOFTWARE. } + 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 @@ THE SOFTWARE. (FT_Module_Constructor)0, (FT_Module_Destructor) 0, - (FT_Module_Requester) 0 + (FT_Module_Requester) bdf_driver_requester }, sizeof ( BDF_FaceRec ), diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h index 949d1b8aa..1b7b585ef 100644 --- a/src/pcf/pcf.h +++ b/src/pcf/pcf.h @@ -229,7 +229,6 @@ FT_BEGIN_HEADER pcf_load_font( FT_Stream, PCF_Face ); - FT_END_HEADER #endif /* __PCF_H__ */ diff --git a/src/pcf/pcfdriver.c b/src/pcf/pcfdriver.c index e995b8eef..ab2fef527 100644 --- a/src/pcf/pcfdriver.c +++ b/src/pcf/pcfdriver.c @@ -32,10 +32,12 @@ THE SOFTWARE. #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 @@ THE SOFTWARE. } + 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 @@ THE SOFTWARE. (FT_Module_Constructor)0, (FT_Module_Destructor) 0, - (FT_Module_Requester) 0 + (FT_Module_Requester) pcf_driver_requester }, sizeof( PCF_FaceRec ), diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 6a1a8a296..e3bbf0606 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -33,6 +33,7 @@ THE SOFTWARE. #include "pcf.h" #include "pcfdriver.h" +#include "pcfread.h" #include "pcferror.h" @@ -316,7 +317,7 @@ THE SOFTWARE. }; - static PCF_Property + FT_LOCAL_DEF( PCF_Property ) pcf_find_property( PCF_Face face, const FT_String* prop ) { diff --git a/src/pcf/pcfread.h b/src/pcf/pcfread.h new file mode 100644 index 000000000..5f54ba6eb --- /dev/null +++ b/src/pcf/pcfread.h @@ -0,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 + +FT_BEGIN_HEADER + + FT_LOCAL( PCF_Property ) + pcf_find_property( PCF_Face face, + const FT_String* prop ); + +FT_END_HEADER + +#endif /* __PCFUTIL_H__ */ + + +/* END */