ref: e2d12842e1e2717545643faa2a8b8f0ccb22b9ba
parent: 17dd0634f240030b2d59a8e5985cae251ca237b9
author: David Turner <[email protected]>
date: Sun Sep 21 13:15:55 EDT 2003
* include/freetype/internal/fnttypes.h, include/freetype/internal/ftserv.h, src/base/ftbdf.c, src/base/ftmm.c, src/base/ftobjs.c, src/base/ftpfr.c, src/base/ftwinfnt.c, src/base/ftxf86.c, src/pfr/pfrdrivr.c, src/winfonts/winfnt.c, src/winfonts/winfnt.h, include/freetype/internal/service/svwinfnt.h,: simplification of service lookup macros, updating the PFR and WINFNT font drivers to new services
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,15 @@
removing various compiler warnings
+ * include/freetype/internal/fnttypes.h,
+ include/freetype/internal/ftserv.h, src/base/ftbdf.c, src/base/ftmm.c,
+ src/base/ftobjs.c, src/base/ftpfr.c, src/base/ftwinfnt.c,
+ src/base/ftxf86.c, src/pfr/pfrdrivr.c, src/winfonts/winfnt.c,
+ src/winfonts/winfnt.h, include/freetype/internal/service/svwinfnt.h,:
+
+ simplification of service lookup macros, updating the PFR and
+ WINFNT font drivers to new services
+
2003-09-19 David Bevan <[email protected]>
--- a/include/freetype/internal/fnttypes.h
+++ /dev/null
@@ -1,104 +1,0 @@
-/***************************************************************************/
-/* */
-/* fnttypes.h */
-/* */
-/* Basic Windows FNT/FON type definitions and interface (specification */
-/* only). */
-/* */
-/* Copyright 1996-2001, 2002, 2003 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
-
-#ifndef __FNTTYPES_H__
-#define __FNTTYPES_H__
-
-
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_WINFONTS_H
-
-
-FT_BEGIN_HEADER
-
-
- typedef struct WinMZ_HeaderRec_
- {
- FT_UShort magic;
- /* skipped content */
- FT_UShort lfanew;
-
- } WinMZ_HeaderRec;
-
-
- typedef struct WinNE_HeaderRec_
- {
- FT_UShort magic;
- /* skipped content */
- FT_UShort resource_tab_offset;
- FT_UShort rname_tab_offset;
-
- } WinNE_HeaderRec;
-
-
- typedef struct WinNameInfoRec_
- {
- FT_UShort offset;
- FT_UShort length;
- FT_UShort flags;
- FT_UShort id;
- FT_UShort handle;
- FT_UShort usage;
-
- } WinNameInfoRec;
-
-
- typedef struct WinResourceInfoRec_
- {
- FT_UShort type_id;
- FT_UShort count;
-
- } WinResourceInfoRec;
-
-
-#define WINFNT_MZ_MAGIC 0x5A4D
-#define WINFNT_NE_MAGIC 0x454E
-
-
- typedef struct FNT_FontRec_
- {
- FT_ULong offset;
- FT_Int size_shift;
-
- FT_WinFNT_HeaderRec header;
-
- FT_Byte* fnt_frame;
- FT_ULong fnt_size;
-
- } FNT_FontRec, *FNT_Font;
-
-
- typedef struct FNT_FaceRec_
- {
- FT_FaceRec root;
- FNT_Font font;
-
- FT_CharMap charmap_handle;
- FT_CharMapRec charmap; /* a single charmap per face */
-
- } FNT_FaceRec, *FNT_Face;
-
-
-FT_END_HEADER
-
-#endif /* __FNTTYPES_H__ */
-
-
-/* END */
--- a/include/freetype/internal/ftserv.h
+++ b/include/freetype/internal/ftserv.h
@@ -46,7 +46,7 @@
* id ::
* A string describing the service as defined in the service's
* header files (e.g. FT_SERVICE_ID_MULTI_MASTERS which expands to
- * `multi-masters').
+ * `multi-masters'). It will be prefixed with "FT_SERVICE_ID_" !!
*
* face ::
* The source face handle.
@@ -60,17 +60,17 @@
* A variable that receives the service pointer. Will be NULL
* if not found.
*/
-#define FT_FACE_FIND_SERVICE( ptrtype, ptr, face, id ) \
- FT_BEGIN_STMNT \
- FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
- \
- \
- (ptr) = NULL; \
- if ( module->clazz->get_interface ) \
- (ptr) = (ptrtype)module->clazz->get_interface( module, id ); \
+#define FT_FACE_FIND_SERVICE( ptr, face, id ) \
+ FT_BEGIN_STMNT \
+ FT_Module module = FT_MODULE( FT_FACE(face)->driver ); \
+ FT_Pointer* pptr = (FT_Pointer*) &(ptr); \
+ \
+ /* the strange cast is to allow C++ compilation */ \
+ *pptr = NULL; \
+ if ( module->clazz->get_interface ) \
+ *pptr = module->clazz->get_interface( module, FT_SERVICE_ID_ ## id ); \
FT_END_STMNT
-
/*************************************************************************/
/*************************************************************************/
/***** *****/
@@ -122,13 +122,19 @@
*
* All fields should have the type FT_Pointer to relax compilation
* dependencies. We assume the developer isn't completely stupid.
+ *
+ * Each field must be named service_XXXX where XXX correspond to
+ * the correct FT_SERVICE_ID_XXXX macro. see the definition of
+ * FT_FACE_LOOKUP_SERVICE below to see why
+ *
*/
typedef struct FT_ServiceCacheRec_
{
- FT_Pointer postscript_name;
- FT_Pointer multi_masters;
- FT_Pointer glyph_dict;
- FT_Pointer pfr_metrics;
+ FT_Pointer service_POSTSCRIPT_NAME;
+ FT_Pointer service_MULTI_MASTERS;
+ FT_Pointer service_GLYPH_DICT;
+ FT_Pointer service_PFR_METRICS;
+ FT_Pointer service_WINFNT;
} FT_ServiceCacheRec, *FT_ServiceCache;
@@ -165,22 +171,27 @@
* ptr ::
* A variable receiving the service data. NULL if not available.
*/
-#define FT_FACE_LOOKUP_SERVICE( face, ptrtype, ptr, field, id ) \
- FT_BEGIN_STMNT \
- (ptr) = (ptrtype)FT_FACE(face)->internal->services.field ; \
- if ( (ptr) == FT_SERVICE_UNAVAILABLE ) \
- (ptr) = NULL; \
- else if ( (ptr) == NULL ) \
- { \
- FT_FACE_FIND_SERVICE( ptrtype, ptr, face, id ); \
- \
- FT_FACE(face)->internal->services.field = \
- (FT_Pointer)( (ptr) != NULL ? (ptr) \
- : FT_SERVICE_UNAVAILABLE ); \
- } \
+#define FT_FACE_LOOKUP_SERVICE( face, ptr, id ) \
+ FT_BEGIN_STMNT \
+ FT_Pointer* pptr = (FT_Pointer*)&(ptr); \
+ FT_Pointer svc; \
+ \
+ /* the strange cast is to allow C++ compilation */ \
+ \
+ svc = FT_FACE(face)->internal->services. service_ ## id ; \
+ if ( svc == FT_SERVICE_UNAVAILABLE ) \
+ svc = NULL; \
+ else if ( svc == NULL ) \
+ { \
+ FT_FACE_FIND_SERVICE( svc, face, id ); \
+ \
+ FT_FACE(face)->internal->services. service_ ## id = \
+ (FT_Pointer)( svc != NULL ? svc \
+ : FT_SERVICE_UNAVAILABLE ); \
+ *pptr = svc; \
+ } \
FT_END_STMNT
-
/*
* A macro used to define new service structure types.
*/
@@ -205,7 +216,9 @@
#define FT_SERVICE_XFREE86_NAME_H <freetype/internal/services/svxf86nm.h>
#define FT_SERVICE_SFNT_H <freetype/internal/services/svsfnt.h>
#define FT_SERVICE_PFR_H <freetype/internal/services/svpfr.h>
+#define FT_SERVICE_WINFNT_H <freetype/internal/services/svwinfnt.h>
+ /* */
FT_END_HEADER
--- /dev/null
+++ b/include/freetype/internal/services/svwinfnt.h
@@ -1,0 +1,47 @@
+/***************************************************************************/
+/* */
+/* svwinfnt.h */
+/* */
+/* The FreeType Windows FNT/FONT service */
+/* */
+/* Copyright 2003 by */
+/* David Turner, Robert Wilhelm, and Werner Lemberg. */
+/* */
+/* This file is part of the FreeType project, and may only be used, */
+/* modified, and distributed under the terms of the FreeType project */
+/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
+/* this file you indicate that you have read the license and */
+/* understand and accept it fully. */
+/* */
+/***************************************************************************/
+
+
+#ifndef __SVWINFNT_H__
+#define __SVWINFNT_H__
+
+
+#include FT_INTERNAL_SERVICE_H
+#include FT_WINFONTS_H
+
+FT_BEGIN_HEADER
+
+
+#define FT_SERVICE_ID_WINFNT "winfonts"
+
+ typedef FT_Error (*FT_WinFnt_GetHeaderFunc)( FT_Face face,
+ FT_WinFNT_HeaderRec *aheader );
+
+ FT_DEFINE_SERVICE( WinFnt )
+ {
+ FT_WinFnt_GetHeaderFunc get_header;
+ };
+
+ /* */
+
+FT_END_HEADER
+
+
+#endif /* __SVWINFNT_H__ */
+
+
+/* END */
--- a/src/base/ftbdf.c
+++ b/src/base/ftbdf.c
@@ -37,12 +37,12 @@
if ( face )
{
FT_Service_BDF service;
-
- FT_FACE_FIND_SERVICE( FT_Service_BDF, service,
+
+ FT_FACE_FIND_SERVICE( service,
face,
- FT_SERVICE_ID_BDF );
-
+ BDF );
+
if ( service && service->get_charset_id )
error = service->get_charset_id( face, &encoding, ®istry );
}
@@ -49,7 +49,7 @@
if ( acharset_encoding )
*acharset_encoding = encoding;
-
+
if ( acharset_registry )
*acharset_registry = registry;
@@ -72,12 +72,12 @@
if ( face )
{
FT_Service_BDF service;
-
- FT_FACE_FIND_SERVICE( FT_Service_BDF, service,
+
+ FT_FACE_FIND_SERVICE( service,
face,
- FT_SERVICE_ID_BDF );
-
+ BDF );
+
if ( service && service->get_property )
error = service->get_property( face, prop_name, aproperty );
}
--- a/src/base/ftmm.c
+++ b/src/base/ftmm.c
@@ -37,21 +37,20 @@
FT_Service_MultiMasters *aservice )
{
FT_Error error;
-
+
*aservice = NULL;
-
+
if ( !face )
return FT_Err_Invalid_Face_Handle;
-
+
error = FT_Err_Invalid_Argument;
-
+
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
FT_FACE_LOOKUP_SERVICE( face,
- FT_Service_MultiMasters, *aservice,
- multi_masters,
- FT_SERVICE_ID_MULTI_MASTERS );
+ *aservice,
+ MULTI_MASTERS );
}
return error;
@@ -75,7 +74,7 @@
if ( service->get_mm )
error = service->get_mm( face, amaster );
}
-
+
return error;
}
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -38,8 +38,8 @@
{
FT_Pointer result = NULL;
FT_ServiceDesc desc = service_descriptors;
-
+
if ( desc && service_id )
{
for ( ; desc->serv_id != NULL; desc++ )
@@ -53,7 +53,7 @@
}
return result;
- }
+ }
FT_BASE_DEF( void )
@@ -1188,7 +1188,7 @@
pfb_data[4] = 0;
pfb_data[5] = 0;
pfb_pos = 7;
- pfb_lenpos = 2;
+ pfb_lenpos = 2;
len = 0;
type = 1;
@@ -1527,12 +1527,12 @@
#ifdef FT_MACINTOSH
/*
- I know this section is within code which is normally turned off
+ I know this section is within code which is normally turned off
for the Mac. It provides an alternative approach to reading the
mac resource forks on OS/X in the event that a user does not wish
to compile ftmac.c.
*/
-
+
if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format ||
FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation ) &&
( args->flags & FT_OPEN_PATHNAME ) )
@@ -2399,34 +2399,10 @@
FT_Service_GlyphDict service;
-#if 0
-
FT_FACE_LOOKUP_SERVICE( face,
- FT_Service_GlyphDict, service,
- glyph_dict,
- FT_SERVICE_ID_GLYPH_DICT );
+ service,
+ GLYPH_DICT );
-#else
-
- service = (FT_Service_GlyphDict)face->internal->services.glyph_dict;
- if ( service == FT_SERVICE_UNAVAILABLE )
- service = NULL;
- else if ( service == NULL )
- {
- FT_Module module = FT_MODULE( face->driver );
-
-
- if ( module->clazz->get_interface )
- service = (FT_Service_GlyphDict)module->clazz->get_interface(
- module, FT_SERVICE_ID_GLYPH_DICT );
-
- face->internal->services.glyph_dict =
- service != NULL ? (FT_Pointer)service
- : FT_SERVICE_UNAVAILABLE;
- }
-
-#endif /* 1 */
-
if ( service && service->name_index )
result = service->name_index( face, glyph_name );
}
@@ -2458,9 +2434,8 @@
FT_FACE_LOOKUP_SERVICE( face,
- FT_Service_GlyphDict, service,
- glyph_dict,
- FT_SERVICE_ID_GLYPH_DICT );
+ service,
+ GLYPH_DICT );
if ( service && service->get_name )
error = service->get_name( face, glyph_index, buffer, buffer_max );
@@ -2487,9 +2462,8 @@
FT_FACE_LOOKUP_SERVICE( face,
- FT_Service_PsName, service,
- postscript_name,
- FT_SERVICE_ID_POSTSCRIPT_NAME );
+ service,
+ POSTSCRIPT_NAME );
if ( service && service->get_ps_name )
result = service->get_ps_name( face );
@@ -2512,13 +2486,13 @@
if ( face && FT_IS_SFNT( face ) )
{
- FT_FACE_FIND_SERVICE( FT_Service_SFNT_Table, service,
+ FT_FACE_FIND_SERVICE( service,
face,
- FT_SERVICE_ID_SFNT_TABLE );
+ SFNT_TABLE );
if ( service != NULL )
table = service->get_table( face, tag );
}
-
+
return table;
}
@@ -2538,12 +2512,12 @@
if ( !face || !FT_IS_SFNT( face ) )
return FT_Err_Invalid_Face_Handle;
- FT_FACE_FIND_SERVICE( FT_Service_SFNT_Table, service,
+ FT_FACE_FIND_SERVICE( service,
face,
- FT_SERVICE_ID_SFNT_TABLE );
+ SFNT_TABLE );
if ( service == NULL )
return FT_Err_Unimplemented_Feature;
-
+
return service->load_table( face, tag, offset, buffer, length );
}
--- a/src/base/ftpfr.c
+++ b/src/base/ftpfr.c
@@ -26,8 +26,7 @@
{
FT_Service_PfrMetrics service;
- FT_FACE_LOOKUP_SERVICE( face, FT_Service_PfrMetrics, service,
- pfr_metrics, FT_SERVICE_ID_PFR_METRICS );
+ FT_FACE_LOOKUP_SERVICE( face, service, PFR_METRICS );
return service;
}
--- a/src/base/ftwinfnt.c
+++ b/src/base/ftwinfnt.c
@@ -18,8 +18,8 @@
#include <ft2build.h>
#include FT_WINFONTS_H
-#include FT_INTERNAL_FNT_TYPES_H
#include FT_INTERNAL_OBJECTS_H
+#include FT_SERVICE_WINFNT_H
FT_EXPORT_DEF( FT_Error )
@@ -26,32 +26,21 @@
FT_Get_WinFNT_Header( FT_Face face,
FT_WinFNT_HeaderRec *header )
{
- FT_Error error;
+ FT_Service_WinFnt service;
+ FT_Error error;
-
error = FT_Err_Invalid_Argument;
- if ( face != NULL && face->driver != NULL )
+ if ( face != NULL )
{
- FT_Module driver = (FT_Module) face->driver;
+ FT_FACE_LOOKUP_SERVICE( face, service, WINFNT );
-
- if ( driver->clazz && driver->clazz->module_name &&
- ft_strcmp( driver->clazz->module_name, "winfonts" ) == 0 )
+ if ( service != NULL )
{
- FNT_Face fnt_face = (FNT_Face)face;
- FNT_Font font = fnt_face->font;
-
-
- if ( font )
- {
- FT_MEM_COPY( header, &font->header, sizeof ( *header ) );
- error = FT_Err_Ok;
- }
+ error = service->get_header( face, header );
}
}
- return error;
+ return error;
}
-
/* END */
--- a/src/base/ftxf86.c
+++ b/src/base/ftxf86.c
@@ -28,8 +28,9 @@
if ( face )
- FT_FACE_FIND_SERVICE( const char*, result,
- face, FT_SERVICE_ID_XF86_NAME );
+ FT_FACE_FIND_SERVICE( result,
+ face,
+ XF86_NAME );
return result;
}
--- a/src/pfr/pfrdrivr.c
+++ b/src/pfr/pfrdrivr.c
@@ -19,13 +19,13 @@
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
-#include FT_INTERNAL_PFR_H
+#include FT_SERVICE_PFR_H
+#include FT_SERVICE_XFREE86_NAME_H
#include "pfrdrivr.h"
#include "pfrobjs.h"
#include "pfrerror.h"
-
static FT_Error
pfr_get_kerning( PFR_Face face,
FT_UInt left,
@@ -52,6 +52,10 @@
return PFR_Err_Ok;
}
+ /*
+ * PFR METRICS SERVICE
+ *
+ */
static FT_Error
pfr_get_advance( PFR_Face face,
@@ -119,14 +123,36 @@
FT_CALLBACK_TABLE_DEF
- const FT_PFR_ServiceRec pfr_service_rec =
+ const FT_Service_PfrMetricsRec pfr_metrics_service_rec =
{
(FT_PFR_GetMetricsFunc) pfr_get_metrics,
- (FT_PFR_GetKerningFunc) pfr_get_kerning,
+ (FT_PFR_GetKerningFunc) pfr_face_get_kerning,
(FT_PFR_GetAdvanceFunc) pfr_get_advance
};
+ /*
+ * SERVICE LIST
+ *
+ */
+ static const FT_ServiceDescRec pfr_services[] =
+ {
+ { FT_SERVICE_ID_PFR_METRICS, & pfr_metrics_service_rec },
+ { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_PFR },
+ { NULL, NULL }
+ };
+
+
+ static FT_Module_Interface
+ pfr_get_service( FT_Driver driver,
+ const FT_String* service_id )
+ {
+ FT_UNUSED( driver );
+
+ return ft_service_list_lookup( pfr_services, service_id );
+ }
+
+
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec pfr_driver_class =
{
@@ -140,11 +166,11 @@
0x10000L,
0x20000L,
- (FT_PFR_Service) &pfr_service_rec, /* format interface */
+ NULL,
(FT_Module_Constructor)NULL,
(FT_Module_Destructor) NULL,
- (FT_Module_Requester) NULL
+ (FT_Module_Requester) pfr_get_service
},
sizeof( PFR_FaceRec ),
--- a/src/winfonts/winfnt.c
+++ b/src/winfonts/winfnt.c
@@ -21,13 +21,12 @@
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_OBJECTS_H
-#include FT_INTERNAL_FNT_TYPES_H
#include "winfnt.h"
-
#include "fnterrs.h"
+#include FT_SERVICE_WINFNT_H
+#include FT_SERVICE_XFREE86_NAME_H
-
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
@@ -632,6 +631,47 @@
}
+ static FT_Error
+ winfnt_get_header( FT_Face face,
+ FT_WinFNT_HeaderRec *aheader )
+ {
+ FNT_Font font = ((FNT_Face)face)->font;
+
+ *aheader = font->header;
+
+ return 0;
+ }
+
+ static const FT_Service_WinFntRec winfnt_service_rec =
+ {
+ winfnt_get_header
+ };
+
+ /*
+ * SERVICE LIST
+ *
+ */
+
+ static const FT_ServiceDescRec winfnt_services[] =
+ {
+ { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_WINFNT },
+ { FT_SERVICE_ID_WINFNT, & winfnt_service_rec },
+ { NULL, NULL }
+ };
+
+
+ static FT_Module_Interface
+ winfnt_get_service( FT_Driver driver,
+ const FT_String* service_id )
+ {
+ FT_UNUSED( driver );
+
+ return ft_service_list_lookup( winfnt_services, service_id );
+ }
+
+
+
+
FT_CALLBACK_TABLE_DEF
const FT_Driver_ClassRec winfnt_driver_class =
{
@@ -648,7 +688,7 @@
(FT_Module_Constructor)0,
(FT_Module_Destructor) 0,
- (FT_Module_Requester) 0
+ (FT_Module_Requester) winfnt_get_service
},
sizeof( FNT_FaceRec ),
--- a/src/winfonts/winfnt.h
+++ b/src/winfonts/winfnt.h
@@ -21,10 +21,77 @@
#include <ft2build.h>
+#include FT_WINFONTS_H
#include FT_INTERNAL_DRIVER_H
FT_BEGIN_HEADER
+
+ typedef struct WinMZ_HeaderRec_
+ {
+ FT_UShort magic;
+ /* skipped content */
+ FT_UShort lfanew;
+
+ } WinMZ_HeaderRec;
+
+
+ typedef struct WinNE_HeaderRec_
+ {
+ FT_UShort magic;
+ /* skipped content */
+ FT_UShort resource_tab_offset;
+ FT_UShort rname_tab_offset;
+
+ } WinNE_HeaderRec;
+
+
+ typedef struct WinNameInfoRec_
+ {
+ FT_UShort offset;
+ FT_UShort length;
+ FT_UShort flags;
+ FT_UShort id;
+ FT_UShort handle;
+ FT_UShort usage;
+
+ } WinNameInfoRec;
+
+
+ typedef struct WinResourceInfoRec_
+ {
+ FT_UShort type_id;
+ FT_UShort count;
+
+ } WinResourceInfoRec;
+
+
+#define WINFNT_MZ_MAGIC 0x5A4D
+#define WINFNT_NE_MAGIC 0x454E
+
+
+ typedef struct FNT_FontRec_
+ {
+ FT_ULong offset;
+ FT_Int size_shift;
+
+ FT_WinFNT_HeaderRec header;
+
+ FT_Byte* fnt_frame;
+ FT_ULong fnt_size;
+
+ } FNT_FontRec, *FNT_Font;
+
+
+ typedef struct FNT_FaceRec_
+ {
+ FT_FaceRec root;
+ FNT_Font font;
+
+ FT_CharMap charmap_handle;
+ FT_CharMapRec charmap; /* a single charmap per face */
+
+ } FNT_FaceRec, *FNT_Face;
FT_EXPORT_VAR( const FT_Driver_ClassRec ) winfnt_driver_class;