- 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..
This commit is contained in:
David Turner 2000-07-19 17:13:03 +00:00
parent 6b8fcd530e
commit 6930b45f78
13 changed files with 350 additions and 37 deletions

View File

@ -180,25 +180,6 @@
#undef FT_EXPORT_FUNC
/*************************************************************************/
/* */
/* 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 */
@ -293,6 +274,19 @@
#define TT_CONFIG_OPTION_POSTSCRIPT_NAMES
/*************************************************************************/
/* */
/* 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
/*************************************************************************/
/*************************************************************************/
/**** ****/
@ -365,7 +359,6 @@
/* */
#define T1_MAX_CHARSTRINGS_OPERANDS 32
/*************************************************************************/
/* */
/* Define T1_CONFIG_OPTION_DISABLE_HINTER if you want to generate a */
@ -383,7 +376,6 @@
/* */
#undef T1_CONFIG_OPTION_NO_AFM
/*************************************************************************/
/* */
/* Define this configuration macro if you want to prevent the */

View File

@ -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 )
@ -2036,6 +2048,47 @@
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 );
/*************************************************************************/
/* */
/* <Function> */

View File

@ -0,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 */

View File

@ -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 */
@ -489,6 +492,11 @@
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

View File

@ -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 */

44
src/base/ftnames.c Normal file
View File

@ -0,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 */

View File

@ -2250,6 +2250,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> */

View File

@ -89,6 +89,32 @@
}
#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;
}

View File

@ -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;

View File

@ -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 ),

View File

@ -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;

View File

@ -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;
@ -100,7 +128,6 @@
#ifndef Z1_CONFIG_OPTION_NO_AFM
/*************************************************************************/
/* */
/* <Function> */

View File

@ -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;