ref: 6930b45f78abc193e84544f804cead9436b86ad5
parent: 6b8fcd530e01ba850b2ca649d533eab8075fd042
author: David Turner <[email protected]>
date: Wed Jul 19 13:13:03 EDT 2000
- introduced FT_Get_Glyph_Name (see freetype.h) to access individual glyph names. Changed some drivers to support it through a new interface named "glyph_name". - introduced FT_Get_Sfnt_Name (see ftnames.h) to access the SFNT name table in a TrueType/OpenType file..
--- a/include/freetype/config/ftoption.h
+++ b/include/freetype/config/ftoption.h
@@ -182,25 +182,6 @@
/*************************************************************************/
/* */
- /* 5-levels Anti Aliasing support */
- /* */
- /* FreeType 2 provides a new `smooth' renderer that is capable of */
- /* producing anti-aliased glyph bitmaps with up to 256 gray-levels. */
- /* */
- /* However, for compatibility purposes with FreeType 1.x, the standard */
- /* raster is still capable of generating anti-aliased bitmaps with */
- /* 5 gray levels. */
- /* */
- /* If you do not need this capability (i.e., if you always use the */
- /* `smooth' renderer for anti-aliased glyphs), we suggest you to */
- /* undefine this configuration macro, as it will save both code and */
- /* memory. */
- /* */
-#undef FT_CONFIG_OPTION_5_GRAY_LEVELS
-
-
- /*************************************************************************/
- /* */
/* Debug level */
/* */
/* FreeType can be compiled in debug or trace mode. In debug mode, */
@@ -294,7 +275,20 @@
/*************************************************************************/
+ /* */
+ /* Define TT_CONFIG_OPTION_SFNT_NAMES if your applications need to */
+ /* access the internal name table in a SFNT-based format like TrueType */
+ /* or OpenType. The name table contains various strings used to */
+ /* describe the font, like family name, copyright, version, etc.. */
+ /* It does not contain any glyph name though.. */
+ /* */
+ /* Accessing sfnt names is done through the functions declared in */
+ /* <freetype/ftnames.h> */
+ /* */
+#define TT_CONFIG_OPTION_SFNT_NAMES
+
/*************************************************************************/
+ /*************************************************************************/
/**** ****/
/**** T R U E T Y P E D R I V E R C O N F I G U R A T I O N ****/
/**** ****/
@@ -365,7 +359,6 @@
/* */
#define T1_MAX_CHARSTRINGS_OPERANDS 32
-
/*************************************************************************/
/* */
/* Define T1_CONFIG_OPTION_DISABLE_HINTER if you want to generate a */
@@ -382,7 +375,6 @@
/* unable to produce kerning distances. */
/* */
#undef T1_CONFIG_OPTION_NO_AFM
-
/*************************************************************************/
/* */
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -768,6 +768,16 @@
/* */
#define FT_FACE_FLAG_MULTIPLE_MASTERS 0x100
+ /*************************************************************************/
+ /* */
+ /* <Constant> */
+ /* FT_FACE_FLAG_GLYPH_NAMES */
+ /* */
+ /* <Description> */
+ /* A bit-field constant, used to indicate that the font contains */
+ /* glyph names that can be retrieved through FT_Get_Glyph_Name. */
+ /* */
+#define FT_FACE_FLAG_GLYPH_NAMES 0x200
/*************************************************************************/
/* */
@@ -798,6 +808,8 @@
( face->face_flags & FT_FACE_FLAG_FIXED_SIZES )
#define FT_HAS_FAST_GLYPHS( face ) \
( face->face_flags & FT_FACE_FLAG_FAST_GLYPHS )
+#define FT_HAS_GLYPH_NAMES( face ) \
+ ( face->face_flags & FT_FACE_FLAG_GLYPH_NAMES )
#define FT_HAS_MULTIPLE_MASTERS( face ) \
( face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS )
@@ -2034,6 +2046,47 @@
FT_UInt right_glyph,
FT_UInt kern_mode,
FT_Vector* kerning );
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Get_Glyph_Name */
+ /* */
+ /* <Description> */
+ /* Retrieves the ASCII name of a given glyph in a face. This only */
+ /* works for those faces where FT_HAS_GLYPH_NAME(face) returns */
+ /* true. */
+ /* */
+ /* <Input> */
+ /* face :: A handle to a source face object. */
+ /* glyph_index :: the glyph index. */
+ /* */
+ /* buffer :: pointer to a target buffer where the name will be */
+ /* copied.. */
+ /* */
+ /* buffer_max :: the maximal number of bytes available in the buffer */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* An error is returned when the face doesn't provide glyph names */
+ /* or when the glyph index is invalid. In all cases of failure, the */
+ /* first byte of "buffer" will be set to 0 to indicate an empty */
+ /* name. */
+ /* */
+ /* The glyph name is truncated to fit within the buffer if it's too */
+ /* long. The returned string is always zero-terminated */
+ /* */
+ /* This function is not compiled within the library if the config */
+ /* macro FT_CONFIG_OPTION_NO_GLYPH_NAMES is defined in */
+ /* <freetype/config/ftoptions.h> */
+ /* */
+ FT_EXPORT_DEF( FT_Error ) FT_Get_Glyph_Name( FT_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max );
/*************************************************************************/
--- /dev/null
+++ b/include/freetype/ftnames.h
@@ -1,0 +1,46 @@
+/***************************************************************************/
+/* */
+/* ftnames.h */
+/* */
+/* Simple interface to access SFNT name tables (which are used */
+/* to hold font names, copyright info, notices, etc..) */
+/* */
+/* This is _not_ used to retrieve glyph names !! */
+/* */
+/* Copyright 1996-2000 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 FTNAMES_H
+#define FTNAMES_H
+
+#include <freetype/freetype.h>
+
+ typedef struct FT_SfntName_
+ {
+ FT_UShort platform_id;
+ FT_UShort encoding_id;
+ FT_UShort language_id;
+ FT_UShort name_id;
+
+ FT_Byte* string;
+ FT_UInt string_len; /* in bytes */
+
+ } FT_SfntName;
+
+
+ FT_EXPORT_DEF(FT_UInt) FT_Get_Sfnt_Name_Count( FT_Face face );
+
+ FT_EXPORT_DEF(FT_Error) FT_Get_Sfnt_Name( FT_Face face,
+ FT_UInt index,
+ FT_SfntName* aname );
+
+
+#endif /* FTNAMES_H */
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -372,7 +372,7 @@
/* managing and loading font files of a given format. */
/* */
/* <Fields> */
- /* root :: Contains the fields of the root module class. */
+ /* root :: contains the fields of the root module class */
/* */
/* clazz :: A pointer to the font driver's class. Note that */
/* this is NOT root.clazz. `class' wasn't used */
@@ -454,11 +454,14 @@
/* handle to the current renderer for the */
/* ft_glyph_format_outline format. */
/* */
+ /* raster_pool_size :: size of the render pool in bytes */
+ /* */
/* raster_pool :: The raster object's render pool. This can */
/* ideally be changed dynamically at run-time. */
/* */
- /* raster_pool_size :: The size of the render pool in bytes. */
/* */
+ /* */
+
typedef struct FT_LibraryRec_
{
FT_Memory memory; /* library's memory manager */
@@ -488,6 +491,11 @@
BASE_DEF( FT_Error ) FT_Render_Glyph_Internal( FT_Library library,
FT_GlyphSlot slot,
FT_UInt render_mode );
+
+ typedef FT_Error (*FT_Glyph_Name_Requester)( FT_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max );
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
--- a/src/base/ftbase.c
+++ b/src/base/ftbase.c
@@ -24,17 +24,19 @@
#include "ftlist.c"
#include "ftoutln.c"
#include "ftextend.c"
+#include "ftnames.c"
-#else
+#else /* FT_FLAT_COMPILE */
-#include <ftcalc.c>
-#include <ftobjs.c>
-#include <ftstream.c>
-#include <ftlist.c>
-#include <ftoutln.c>
-#include <ftextend.c>
+#include <base/ftcalc.c>
+#include <base/ftobjs.c>
+#include <base/ftstream.c>
+#include <base/ftlist.c>
+#include <base/ftoutln.c>
+#include <base/ftextend.c>
+#include <base/ftnames.c>
-#endif
+#endif /* FT_FLAT_COMPILE */
/* END */
--- /dev/null
+++ b/src/base/ftnames.c
@@ -1,0 +1,44 @@
+#include <freetype/ftnames.h>
+#include <freetype/internal/tttypes.h>
+
+#ifdef FT_CONFIG_OPTION_GLYPH_NAMES
+#endif /* FT_CONFIG_OPTION_GLYPH_NAMES */
+
+
+
+
+#ifdef FT_CONFIG_OPTION_SFNT_NAMES
+ FT_EXPORT_FUNC(FT_UInt) FT_Get_Sfnt_Name_Count( FT_Face face )
+ {
+ return ( face && FT_IS_SFNT(face) ? ((TT_Face)face)->num_names : 0 );
+ }
+
+
+ FT_EXPORT_FUNC(FT_Error) FT_Get_Sfnt_Name( FT_Face face,
+ FT_UInt index,
+ FT_SfntName* aname )
+ {
+ FT_Error error = FT_Err_Invalid_Argument;
+
+ if ( face && FT_IS_SFNT(face) )
+ {
+ TT_Face ttface = (TT_Face)face;
+
+ if (index < ttface->num_names)
+ {
+ TT_NameRec* name = ttface->name_table.names + index;
+
+ aname->platform_id = name->platformID;
+ aname->encoding_id = name->encodingID;
+ aname->language_id = name->languageID;
+ aname->name_id = name->nameID;
+ aname->string = (FT_Byte*)name->string;
+ aname->string_len = name->stringLength;
+
+ error = FT_Err_Ok;
+ }
+ }
+
+ return error;
+ }
+#endif /* FT_CONFIG_OPTION_SFNT_NAMES */
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -2253,6 +2253,72 @@
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Get_Glyph_Name */
+ /* */
+ /* <Description> */
+ /* Retrieves the ASCII name of a given glyph in a face. This only */
+ /* works for those faces where FT_HAS_GLYPH_NAME(face) returns */
+ /* true. */
+ /* */
+ /* <Input> */
+ /* face :: A handle to a source face object. */
+ /* glyph_index :: the glyph index. */
+ /* */
+ /* buffer :: pointer to a target buffer where the name will be */
+ /* copied.. */
+ /* */
+ /* buffer_max :: the maximal number of bytes available in the buffer */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* An error is returned when the face doesn't provide glyph names */
+ /* or when the glyph index is invalid. In all cases of failure, the */
+ /* first byte of "buffer" will be set to 0 to indicate an empty */
+ /* name. */
+ /* */
+ /* The glyph name is truncated to fit within the buffer if it's too */
+ /* long. The returned string is always zero-terminated */
+ /* */
+ /* This function is not compiled within the library if the config */
+ /* macro FT_CONFIG_OPTION_NO_GLYPH_NAMES is defined in */
+ /* <freetype/config/ftoptions.h> */
+ /* */
+ FT_EXPORT_FUNC( FT_Error ) FT_Get_Glyph_Name( FT_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max )
+ {
+ FT_Error error = FT_Err_Invalid_Argument;
+
+ /* clean up buffer */
+ if (buffer && buffer_max > 0)
+ ((FT_Byte*)buffer)[0] = 0;
+
+ if ( face && glyph_index < (FT_UInt)face->num_glyphs && FT_HAS_GLYPH_NAMES(face) )
+ {
+ /* now, lookup for glyph name */
+ FT_Driver driver = face->driver;
+ FT_Module_Class* clazz = FT_MODULE_CLASS(driver);
+
+ if (clazz->get_interface)
+ {
+ FT_Glyph_Name_Requester requester;
+
+ requester = (FT_Glyph_Name_Requester)
+ clazz->get_interface( FT_MODULE(driver), "glyph_name" );
+ if (requester)
+ error = requester( face, glyph_index, buffer, buffer_max );
+ }
+ }
+ return error;
+ }
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_Get_Sfnt_Table */
/* */
/* <Description> */
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -89,7 +89,33 @@
}
+#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
static
+ FT_Error get_sfnt_glyph_name( TT_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max )
+ {
+ FT_String* gname;
+ FT_Error error;
+
+ error = TT_Get_PS_Name( face, glyph_index, &gname );
+ if (!error && buffer_max > 0)
+ {
+ FT_UInt len = strlen( gname );
+
+ if (len >= buffer_max)
+ len = buffer_max-1;
+
+ MEM_Copy( buffer, gname, len );
+ ((FT_Byte*)buffer)[len] = 0;
+ }
+
+ return error;
+ }
+#endif
+
+ static
FT_Module_Interface SFNT_Get_Interface( FT_Module module,
const char* interface )
{
@@ -98,6 +124,10 @@
if ( strcmp( interface, "get_sfnt" ) == 0 )
return (FT_Module_Interface)get_sfnt_table;
+#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
+ if ( strcmp( interface, "glyph_name" ) == 0 )
+ return (FT_Module_Interface)get_sfnt_glyph_name;
+#endif
return 0;
}
--- a/src/sfnt/sfobjs.c
+++ b/src/sfnt/sfobjs.c
@@ -318,6 +318,12 @@
FT_FACE_FLAG_SFNT | /* SFNT file format */
FT_FACE_FLAG_HORIZONTAL; /* horizontal data */
+#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
+ /* might need more polish to detect the presence of a Postscript name */
+ /* table in the font.. */
+ flags |= FT_FACE_FLAG_GLYPH_NAMES;
+#endif
+
/* fixed width font? */
if ( face->postscript.isFixedPitch )
flags |= FT_FACE_FLAG_FIXED_WIDTH;
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -106,6 +106,44 @@
#endif /* T1_CONFIG_OPTION_NO_AFM */
+ static
+ FT_Error get_t1_glyph_name( T1_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max )
+ {
+ FT_String* gname;
+
+ gname = face->type1.glyph_names[glyph_index];
+ if (buffer_max > 0)
+ {
+ FT_UInt len = strlen( gname );
+
+ if (len >= buffer_max)
+ len = buffer_max-1;
+
+ MEM_Copy( buffer, gname, len );
+ ((FT_Byte*)buffer)[len] = 0;
+ }
+
+ return 0;
+ }
+
+
+ static
+ FT_Module_Interface T1_Get_Interface( FT_Module module,
+ const char* interface )
+ {
+ FT_UNUSED( module );
+
+ if ( strcmp( interface, "glyph_name" ) == 0 )
+ return (FT_Module_Interface)get_t1_glyph_name;
+
+ return 0;
+ }
+
+
+
/*************************************************************************/
/* */
/* <Function> */
@@ -282,6 +320,7 @@
}
+
const FT_Driver_Class t1_driver_class =
{
{
@@ -296,11 +335,7 @@
(FT_Module_Constructor)0,
(FT_Module_Destructor) 0,
-#ifdef T1_CONFIG_OPTION_NO_AFM
- (FT_Module_Requester) Get_Interface
-#else
- (FT_Module_Requester) 0
-#endif
+ (FT_Module_Requester) T1_Get_Interface
},
sizeof( T1_FaceRec ),
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -337,6 +337,8 @@
root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
+ root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
+
if ( type1->font_info.is_fixed_pitch )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
--- a/src/type1z/z1driver.c
+++ b/src/type1z/z1driver.c
@@ -50,6 +50,31 @@
#define FT_COMPONENT trace_z1driver
+
+ static
+ FT_Error get_z1_glyph_name( T1_Face face,
+ FT_UInt glyph_index,
+ FT_Pointer buffer,
+ FT_UInt buffer_max )
+ {
+ FT_String* gname;
+
+ gname = face->type1.glyph_names[glyph_index];
+ if (buffer_max > 0)
+ {
+ FT_UInt len = strlen( gname );
+
+ if (len >= buffer_max)
+ len = buffer_max-1;
+
+ MEM_Copy( buffer, gname, len );
+ ((FT_Byte*)buffer)[len] = 0;
+ }
+
+ return 0;
+ }
+
+
/*************************************************************************/
/* */
/* <Function> */
@@ -84,6 +109,9 @@
FT_UNUSED( driver );
FT_UNUSED( interface );
+ if ( strcmp( (const char*)interface, "glyph_name" ) == 0 )
+ return (FT_Module_Interface)get_z1_glyph_name;
+
#ifndef Z1_CONFIG_OPTION_NO_MM_SUPPORT
if ( strcmp( (const char*)interface, "get_mm" ) == 0 )
return (FT_Module_Interface)Z1_Get_Multi_Master;
@@ -99,7 +127,6 @@
#ifndef Z1_CONFIG_OPTION_NO_AFM
-
/*************************************************************************/
/* */
--- a/src/type1z/z1objs.c
+++ b/src/type1z/z1objs.c
@@ -209,6 +209,8 @@
root->face_flags |= FT_FACE_FLAG_HORIZONTAL;
+ root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
+
if ( face->type1.font_info.is_fixed_pitch )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;