various fixes to the FT_CMaps support

This commit is contained in:
David Turner 2002-03-22 17:09:52 +00:00
parent fb285cbd0b
commit 636fdbd4a4
11 changed files with 171 additions and 174 deletions

View File

@ -76,7 +76,7 @@ FT_BEGIN_HEADER
/*************************************************************************/
#undef FT_CONFIG_OPTION_USE_CMAPS
#define FT_CONFIG_OPTION_USE_CMAPS
#define TT_CONFIG_CMAP_FORMAT_0
#define TT_CONFIG_CMAP_FORMAT_2
#define TT_CONFIG_CMAP_FORMAT_4

View File

@ -127,8 +127,8 @@ FT_BEGIN_HEADER
/* validator structure */
typedef struct FT_ValidatorRec_
{
FT_Byte* base; /* address of table in memory */
FT_Byte* limit; /* 'base' + sizeof(table) in memory */
const FT_Byte* base; /* address of table in memory */
const FT_Byte* limit; /* 'base' + sizeof(table) in memory */
FT_ValidationLevel level; /* validation level */
FT_Error error; /* error returned. 0 means success */
@ -136,13 +136,17 @@ FT_BEGIN_HEADER
} FT_ValidatorRec;
#define FT_VALIDATOR(x) ((FT_Validator)(x))
FT_BASE( void )
ft_validator_init( FT_Validator valid,
FT_Byte* base,
FT_Byte* limit,
const FT_Byte* base,
const FT_Byte* limit,
FT_ValidationLevel level );
FT_BASE( FT_Int )
ft_validator_run( FT_Validator valid );
/* sets the error field in a validator, then calls 'longjmp' to return */
/* to high-level caller. Using 'setjmp/longjmp' avoids many stupid */
/* error checks within the validation routines.. */
@ -450,6 +454,7 @@ FT_BEGIN_HEADER
#define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
#define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
#define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
#define FT_FACE_STREAM( x ) FT_FACE( x )->stream
#define FT_SIZE_FACE( x ) FT_SIZE( x )->face
#define FT_SLOT_FACE( x ) FT_SLOT( x )->face

View File

@ -26,6 +26,37 @@
#include FT_OUTLINE_H
#include <string.h> /* for strcmp() */
#include <setjmp.h> /* for setjmp() and longjmp() */
FT_BASE_DEF( void )
ft_validator_init( FT_Validator valid,
const FT_Byte* base,
const FT_Byte* limit,
FT_ValidationLevel level )
{
valid->base = base;
valid->limit = limit;
valid->level = level;
valid->error = 0;
}
FT_BASE_DEF( FT_Int )
ft_validator_run( FT_Validator valid )
{
int result;
result = setjmp( valid->jump_buffer );
return result;
}
FT_BASE_DEF( void )
ft_validator_error( FT_Validator valid,
FT_Error error )
{
valid->error = error;
longjmp( valid->jump_buffer, 1 );
}
/*************************************************************************/
@ -1443,29 +1474,47 @@
/* documentation is in freetype.h */
#ifdef FT_CONFIG_OPTION_USE_CMAPS
FT_EXPORT_DEF( FT_UInt )
FT_Get_Char_Index( FT_Face face,
FT_ULong charcode )
{
FT_UInt result;
FT_UInt result = 0;
if ( face && face->charmap )
{
FT_CMap cmap = FT_CMAP( face->charmap );
result = cmap->clazz->char_index( cmap, charcode );
}
return result;
}
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
FT_EXPORT_DEF( FT_UInt )
FT_Get_Char_Index( FT_Face face,
FT_ULong charcode )
{
FT_UInt result = 0;
FT_Driver driver;
result = 0;
if ( face && face->charmap )
{
#ifdef FT_CONFIG_OPTION_USE_CMAPS
FT_CMap cmap = FT_CMAP( face->charmap );
result = cmap->clazz->char_index( cmap, charcode );
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
driver = face->driver;
result = driver->clazz->get_char_index( face->charmap, charcode );
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
}
return result;
}
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_ULong )
@ -1490,6 +1539,35 @@
/* documentation is in freetype.h */
#ifdef FT_CONFIG_OPTION_USE_CMAPS
FT_EXPORT_DEF( FT_ULong )
FT_Get_Next_Char( FT_Face face,
FT_ULong charcode,
FT_UInt *agindex )
{
FT_ULong result = 0;
FT_UInt gindex = 0;
if ( face && face->charmap )
{
FT_UInt32 code = (FT_UInt32)charcode;
FT_CMap cmap = FT_CMAP( face->charmap );
gindex = cmap->clazz->char_next( cmap, &code );
result = ( gindex == 0 ) ? 0 : code;
}
if ( agindex )
*agindex = gindex;
return result;
}
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
FT_EXPORT_DEF( FT_ULong )
FT_Get_Next_Char( FT_Face face,
FT_ULong charcode,
@ -1502,12 +1580,6 @@
if ( face && face->charmap )
{
#ifdef FT_CONFIG_OPTION_USE_CMAPS
FT_CMap cmap = FT_CMAP( face->charmap );
gindex = cmap->clazz->char_next( cmap, &charcode );
result = ( gindex == 0 ) ? 0 : charcode;
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
driver = face->driver;
result = driver->clazz->get_next_char( face->charmap, charcode );
if ( result != 0 )
@ -1516,7 +1588,6 @@
if ( gindex == 0 )
result = 0;
}
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
}
if ( agindex )
@ -1525,6 +1596,8 @@
return result;
}
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
/* documentation is in freetype.h */

View File

@ -249,56 +249,6 @@
static FT_Encoding
find_encoding( int platform_id,
int encoding_id )
{
typedef struct TEncoding
{
int platform_id;
int encoding_id;
FT_Encoding encoding;
} TEncoding;
static
const TEncoding tt_encodings[] =
{
{ TT_PLATFORM_ISO, -1, ft_encoding_unicode },
{ TT_PLATFORM_APPLE_UNICODE, -1, ft_encoding_unicode },
{ TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, ft_encoding_apple_roman },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, ft_encoding_unicode },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, ft_encoding_sjis },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, ft_encoding_gb2312 },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, ft_encoding_big5 },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, ft_encoding_wansung },
{ TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, ft_encoding_johab }
};
const TEncoding *cur, *limit;
cur = tt_encodings;
limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] );
for ( ; cur < limit; cur++ )
{
if ( cur->platform_id == platform_id )
{
if ( cur->encoding_id == encoding_id ||
cur->encoding_id == -1 )
return cur->encoding;
}
}
return ft_encoding_none;
}
FT_LOCAL_DEF( FT_Error )
CFF_Face_Init( FT_Stream stream,
CFF_Face face,
@ -498,48 +448,8 @@
flags |= FT_STYLE_FLAG_BOLD;
root->style_flags = flags;
/* set the charmaps if any */
if ( sfnt_format )
{
/*****************************************************************/
/* */
/* Polish the charmaps. */
/* */
/* Try to set the charmap encoding according to the platform & */
/* encoding ID of each charmap. */
/* */
TT_CharMap charmap;
FT_Int n;
charmap = face->charmaps;
root->num_charmaps = face->num_charmaps;
/* allocate table of pointers */
if ( FT_NEW_ARRAY( root->charmaps, root->num_charmaps ) )
goto Exit;
for ( n = 0; n < root->num_charmaps; n++, charmap++ )
{
FT_Int platform = charmap->cmap.platformID;
FT_Int encoding = charmap->cmap.platformEncodingID;
charmap->root.face = (FT_Face)face;
charmap->root.platform_id = (FT_UShort)platform;
charmap->root.encoding_id = (FT_UShort)encoding;
charmap->root.encoding = find_encoding( platform, encoding );
/* now, set root->charmap with a unicode charmap */
/* wherever available */
if ( !root->charmap &&
charmap->root.encoding == ft_encoding_unicode )
root->charmap = (FT_CharMap)charmap;
root->charmaps[n] = (FT_CharMap)charmap;
}
}
/* XXX: no charmaps for pure CFF fonts for now !! */
}
}

View File

@ -72,10 +72,10 @@ THE SOFTWARE.
FT_CALLBACK_DEF( FT_UInt )
pcf_cmap_char_index( FT_CMap cmap,
pcf_cmap_char_index( PCF_CMap cmap,
FT_UInt32 charcode )
{
PCF_Encoding encoding = cmap->encodings;
PCF_Encoding encodings = cmap->encodings;
FT_UInt min, max, mid;
FT_UInt result = 0;
@ -140,7 +140,7 @@ THE SOFTWARE.
if ( ++min < cmap->num_encodings )
{
charcode = encodings[min].enc;
glyph = encodings[min].glyph;
result = encodings[min].glyph;
}
Exit:

View File

@ -19,6 +19,7 @@
#include <ft2build.h>
#include "sfobjs.h"
#include "ttload.h"
#include "ttcmap0.h"
#include FT_INTERNAL_SFNT_H
#include FT_INTERNAL_POSTSCRIPT_NAMES_H
#include FT_TRUETYPE_IDS_H
@ -384,7 +385,6 @@
{
FT_Face root = &face->root;
FT_Int flags = 0;
TT_CharMap charmap;
FT_Int n;
FT_Memory memory;
@ -456,12 +456,12 @@
/* */
#ifdef FT_CONFIG_OPTION_USE_CMAPS
error = TT_Build_CMaps( face );
if (error) goto Exit;
TT_Build_CMaps( face ); /* ignore errors */
/* set the encoding fields */
{
FT_UInt n;
FT_Int n;
for ( n = 0; n < root->num_charmaps; n++ )
{
@ -480,32 +480,36 @@
}
#else /* !FT_CONFIG_OPTION_USE_CMAPS */
charmap = face->charmaps;
root->num_charmaps = face->num_charmaps;
/* allocate table of pointers */
if ( FT_NEW_ARRAY( root->charmaps, root->num_charmaps ) )
goto Exit;
for ( n = 0; n < root->num_charmaps; n++, charmap++ )
{
FT_Int platform = charmap->cmap.platformID;
FT_Int encoding = charmap->cmap.platformEncodingID;
charmap->root.face = (FT_Face)face;
charmap->root.platform_id = (FT_UShort)platform;
charmap->root.encoding_id = (FT_UShort)encoding;
charmap->root.encoding = sfnt_find_encoding( platform, encoding );
/* now, set root->charmap with a unicode charmap */
/* wherever available */
if ( !root->charmap &&
charmap->root.encoding == ft_encoding_unicode )
root->charmap = (FT_CharMap)charmap;
root->charmaps[n] = (FT_CharMap)charmap;
TT_CharMap charmap = face->charmaps;
charmap = face->charmaps;
root->num_charmaps = face->num_charmaps;
/* allocate table of pointers */
if ( FT_NEW_ARRAY( root->charmaps, root->num_charmaps ) )
goto Exit;
for ( n = 0; n < root->num_charmaps; n++, charmap++ )
{
FT_Int platform = charmap->cmap.platformID;
FT_Int encoding = charmap->cmap.platformEncodingID;
charmap->root.face = (FT_Face)face;
charmap->root.platform_id = (FT_UShort)platform;
charmap->root.encoding_id = (FT_UShort)encoding;
charmap->root.encoding = sfnt_find_encoding( platform, encoding );
/* now, set root->charmap with a unicode charmap */
/* wherever available */
if ( !root->charmap &&
charmap->root.encoding == ft_encoding_unicode )
root->charmap = (FT_CharMap)charmap;
root->charmaps[n] = (FT_CharMap)charmap;
}
}
#endif /* !FT_CONFIG_OPTION_USE_CMAPS */

View File

@ -1549,15 +1549,12 @@
FT_LOCAL_DEF( FT_Error )
TT_Build_CMaps( TT_Face face )
{
TT_CMap_Class clazz;
FT_ValidatorRec valid;
FT_UInt num_cmaps;
FT_Byte* table = face->cmap_table;
FT_Byte* limit = table + face->cmap_size;
FT_Byte* p = table;
FT_UInt format;
if ( p + 4 < limit )
if ( p + 4 > limit )
return FT_Err_Invalid_Table;
/* only recognize format 0 */
@ -1582,29 +1579,31 @@
if ( offset && table + offset + 2 < limit )
{
FT_Byte* cmap = table + offset;
FT_UInt format = TT_PEEK_USHORT(cmap);
TT_CMap_Class* pclazz = tt_cmap_classes;
TT_CMap_Class clazz;
FT_Byte* cmap = table + offset;
FT_UInt format = TT_PEEK_USHORT(cmap);
const TT_CMap_Class* pclazz = tt_cmap_classes;
TT_CMap_Class clazz;
for ( ; *pclazz; pclazz++ )
{
clazz = *pclazz;
if ( clazz->format == format )
{
volatile TT_Validator valid;
volatile TT_ValidatorRec valid;
ft_validator_init( FT_VALIDATOR(&valid), cmap, limit,
FT_VALIDATE_DEFAULT );
valid.num_glyphs = face->root.num_glyphs;
if ( ft_validator_init( FT_VALIDATOR(&valid), cmap, limit,
FT_VALIDATE_LEVEL_DEFAULT ) == 0 )
if ( setjmp( FT_VALIDATOR(&valid)->jump_buffer ) == 0 )
{
/* validate this cmap sub-table */
clazz->validate( cmap, FT_VALIDATOR(&valid) );
}
if ( valid.error == 0 )
(void)FT_CMap_New( clazz, cmap, face, NULL );
if ( valid.validator.error == 0 )
(void)FT_CMap_New( (FT_CMap_Class)clazz, cmap, &charmap, NULL );
else
FT_ERROR(( "%s: broken cmap sub-table ignored !!\n",
"TT_Build_CMaps" ));

View File

@ -49,8 +49,8 @@ FT_BEGIN_HEADER
typedef struct TT_ValidatorRec_
{
FT_Validator validator;
FT_UInt num_glyphs;
FT_ValidatorRec validator;
FT_UInt num_glyphs;
} TT_ValidatorRec, *TT_Validator;

View File

@ -1128,9 +1128,6 @@
FT_Stream stream )
{
FT_Error error;
FT_Memory memory = stream->memory;
FT_Long table_start;
TT_CMapDirRec cmap_dir;
error = face->goto_table( face, TTAG_cmap, stream, &face->cmap_size );
if ( error )

View File

@ -436,7 +436,7 @@
if ( psnames && psaux )
{
FT_CharMapRec charmap;
FT_CMap_Classes cmap_classes = psaux->cmap_classes;
T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes;
FT_CMap_Class clazz;
charmap.face = root;
@ -446,7 +446,7 @@
charmap.encoding_id = 1;
charmap.encoding = ft_encoding_unicode;
FT_CMap_New( root, cmap_classes->unicode, &charmap, NULL );
FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL );
/* now, generate an Adobe Standard encoding when appropriate */
charmap.platform_id = 7;
@ -473,9 +473,9 @@
break;
case T1_ENCODING_TYPE_ISOLATIN1:
charmap.encoding = ft_encoding_adobe_latin_1;
charmap.encoding = ft_encoding_latin_1;
charmap.encoding_id = 3;
clazz = cmap_classes->latin_1;
clazz = cmap_classes->unicode;
break;
default:
@ -483,7 +483,7 @@
}
if ( clazz )
FT_CMap_New( root, clazz, &charmap, NULL );
FT_CMap_New( clazz, NULL, &charmap, NULL );
}
}

View File

@ -323,7 +323,7 @@
static FT_Error
fnt_cmap_init( FT_CMap cmap )
fnt_cmap_init( FNT_CMap cmap )
{
FNT_Face face = (FNT_Face) FT_CMAP_FACE(cmap);
FNT_Font font = face->fonts;
@ -336,7 +336,7 @@
static FT_UInt
fnt_cmap_char_index( FT_CMap cmap,
fnt_cmap_char_index( FNT_CMap cmap,
FT_UInt32 char_code )
{
FT_UInt gindex = 0;
@ -350,7 +350,7 @@
static FT_UInt
fnt_cmap_char_next( FT_CMap cmap,
fnt_cmap_char_next( FNT_CMap cmap,
FT_UInt32 *pchar_code )
{
FT_UInt gindex = 0;
@ -734,20 +734,29 @@
(FT_Face_DoneFunc) FNT_Face_Done,
(FT_Size_InitFunc) 0,
(FT_Size_DoneFunc) 0,
(FT_Slot_InitFunc)0,
(FT_Slot_DoneFunc)0,
(FT_Slot_InitFunc) 0,
(FT_Slot_DoneFunc) 0,
(FT_Size_ResetPointsFunc) FNT_Size_Set_Pixels,
(FT_Size_ResetPixelsFunc)FNT_Size_Set_Pixels,
(FT_Slot_LoadFunc) FNT_Load_Glyph,
#ifdef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharIndexFunc) 0,
#else
(FT_CharMap_CharIndexFunc) FNT_Get_Char_Index,
#endif
(FT_Face_GetKerningFunc) 0,
(FT_Face_AttachFunc) 0,
(FT_Face_GetAdvancesFunc) 0,
#ifdef FT_CONFIG_OPTION_USE_CMAPS
(FT_CharMap_CharNextFunc) 0
#else
(FT_CharMap_CharNextFunc) FNT_Get_Next_Char
#endif
};