* 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
diff --git a/ChangeLog b/ChangeLog
index 96b45d3..57edb2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-01-22 David Turner <david@freetype.org>
+
+ * 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 <wl@gnu.org>
* builds/unix/ltmain.sh: Regenerated with `libtoolize --force
@@ -145,7 +155,7 @@
2002-12-02 Antoine Leca <Antoine-Freetype@Leca-Marti.org>
- * 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 c33f9fc..71735e3 100644
--- a/include/freetype/ftbdf.h
+++ b/include/freetype/ftbdf.h
@@ -45,6 +45,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:
* FT_Get_BDF_Charset_ID
*
@@ -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 cd4dcab..3a1ec64 100644
--- a/include/freetype/internal/bdftypes.h
+++ b/include/freetype/internal/bdftypes.h
@@ -29,6 +29,7 @@ THE SOFTWARE.
#include <ft2build.h>
#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 5ccd5dc..759d121 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 0457955..3e76e9f 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;
- }
+ }
+
+
+ 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 0e9197f..c156bd8 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 949d1b8..1b7b585 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 e995b8e..ab2fef5 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 6a1a8a2..e3bbf06 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 0000000..5f54ba6
--- /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 <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 */