diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h index dbc8e363b..4439983b1 100644 --- a/include/freetype/config/ftoption.h +++ b/include/freetype/config/ftoption.h @@ -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 */ + /* */ + /* */ +#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 */ diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index e5f4bd29d..14953a84b 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -768,6 +768,16 @@ /* */ #define FT_FACE_FLAG_MULTIPLE_MASTERS 0x100 + /*************************************************************************/ + /* */ + /* */ + /* FT_FACE_FLAG_GLYPH_NAMES */ + /* */ + /* */ + /* 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 ); + /*************************************************************************/ + /* */ + /* */ + /* FT_Get_Glyph_Name */ + /* */ + /* */ + /* 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. */ + /* */ + /* */ + /* 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 */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + /* */ + /* 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 */ + /* */ + /* */ + FT_EXPORT_DEF( FT_Error ) FT_Get_Glyph_Name( FT_Face face, + FT_UInt glyph_index, + FT_Pointer buffer, + FT_UInt buffer_max ); + + /*************************************************************************/ /* */ /* */ diff --git a/include/freetype/ftnames.h b/include/freetype/ftnames.h new file mode 100644 index 000000000..394943c54 --- /dev/null +++ b/include/freetype/ftnames.h @@ -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 + + 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 */ diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index e08ea6e84..912ed1e21 100644 --- 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. */ /* */ /* */ - /* 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 diff --git a/src/base/ftbase.c b/src/base/ftbase.c index f9d9bbf8e..a110af42b 100644 --- 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 -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -#endif +#endif /* FT_FLAT_COMPILE */ /* END */ diff --git a/src/base/ftnames.c b/src/base/ftnames.c new file mode 100644 index 000000000..b7f80df95 --- /dev/null +++ b/src/base/ftnames.c @@ -0,0 +1,44 @@ +#include +#include + +#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 */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index bbfb3624f..84d2ca022 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -2250,6 +2250,72 @@ } + /*************************************************************************/ + /* */ + /* */ + /* FT_Get_Glyph_Name */ + /* */ + /* */ + /* 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. */ + /* */ + /* */ + /* 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 */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + /* */ + /* 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 */ + /* */ + /* */ + 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; + } + + /*************************************************************************/ /* */ /* */ diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index 60e6045c6..ce7745b93 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -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; } diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 3557ffbdc..1f79db9b2 100644 --- 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; diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c index 4aef16425..3634399c4 100644 --- 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; + } + + + /*************************************************************************/ /* */ /* */ @@ -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 ), diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c index 0eeef8abf..1e6f9ca2a 100644 --- 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; diff --git a/src/type1z/z1driver.c b/src/type1z/z1driver.c index 6d25b3c15..ec854f95a 100644 --- 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; + } + + /*************************************************************************/ /* */ /* */ @@ -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 - /*************************************************************************/ /* */ /* */ diff --git a/src/type1z/z1objs.c b/src/type1z/z1objs.c index 7e2f78692..e452bb5ed 100644 --- 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;