2002-02-22 19:28:11 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
2002-03-31 20:48:24 +02:00
|
|
|
/* ttcmap0.c */
|
2002-02-22 19:28:11 +01:00
|
|
|
/* */
|
2002-03-31 20:48:24 +02:00
|
|
|
/* TrueType new character mapping table (cmap) support (body). */
|
2002-02-22 19:28:11 +01:00
|
|
|
/* */
|
2003-04-23 20:21:48 +02:00
|
|
|
/* Copyright 2002, 2003 by */
|
2002-02-22 19:28:11 +01:00
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
2002-03-22 16:02:38 +01:00
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
2002-02-22 19:28:11 +01:00
|
|
|
#include "ttload.h"
|
2002-03-22 16:02:38 +01:00
|
|
|
#include "ttcmap0.h"
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
#include "sferrors.h"
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
|
|
|
|
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
|
|
|
|
/* messages during execution. */
|
|
|
|
/* */
|
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_ttcmap
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
#define TT_PEEK_SHORT FT_PEEK_SHORT
|
|
|
|
#define TT_PEEK_USHORT FT_PEEK_USHORT
|
|
|
|
#define TT_PEEK_LONG FT_PEEK_LONG
|
|
|
|
#define TT_PEEK_ULONG FT_PEEK_ULONG
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
#define TT_NEXT_SHORT FT_NEXT_SHORT
|
|
|
|
#define TT_NEXT_USHORT FT_NEXT_USHORT
|
|
|
|
#define TT_NEXT_LONG FT_NEXT_LONG
|
|
|
|
#define TT_NEXT_ULONG FT_NEXT_ULONG
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-02-28 17:10:29 +01:00
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap_init( TT_CMap cmap,
|
|
|
|
FT_Byte* table )
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
cmap->data = table;
|
2002-03-01 03:26:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2002-02-28 17:10:29 +01:00
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 0 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 0 */
|
|
|
|
/* length 2 USHORT table length in bytes */
|
|
|
|
/* language 4 USHORT Mac language code */
|
|
|
|
/* glyph_ids 6 BYTE[256] array of glyph indices */
|
|
|
|
/* 262 */
|
|
|
|
/* */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_0
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap0_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte* p = table + 2;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt length = TT_NEXT_USHORT( p );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( table + length > valid->limit || length < 262 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check glyph indices whenever necessary */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt n, idx;
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
p = table + 6;
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( n = 0; n < 256; n++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = *p++;
|
|
|
|
if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap0_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
return char_code < 256 ? table[6 + char_code] : 0;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap0_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt32 charcode = *pchar_code;
|
|
|
|
FT_UInt32 result = 0;
|
|
|
|
FT_UInt gindex = 0;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
table += 6; /* go to glyph ids */
|
2002-03-22 16:02:38 +01:00
|
|
|
while ( ++charcode < 256 )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
gindex = table[charcode];
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
result = charcode;
|
2002-02-22 19:28:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = result;
|
|
|
|
return gindex;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-28 17:10:29 +01:00
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap0_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 4;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap0_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-26 03:38:39 +01:00
|
|
|
sizeof( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap0_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap0_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
0,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap0_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap0_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_0 */
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 2 *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** This is used for certain CJK encodings that encode text in a *****/
|
|
|
|
/***** mixed 8/16 bits encoding along the following lines: *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** * Certain byte values correspond to an 8-bit character code *****/
|
|
|
|
/***** (typically in the range 0..127 for ASCII compatibility). *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** * Certain byte values signal the first byte of a 2-byte *****/
|
|
|
|
/***** character code (but these values are also valid as the *****/
|
|
|
|
/***** second byte of a 2-byte character). *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** The following charmap lookup and iteration functions all *****/
|
|
|
|
/***** assume that the value "charcode" correspond to following: *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** - For one byte characters, "charcode" is simply the *****/
|
|
|
|
/***** character code. *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** - For two byte characters, "charcode" is the 2-byte *****/
|
|
|
|
/***** character code in big endian format. More exactly: *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** (charcode >> 8) is the first byte value *****/
|
|
|
|
/***** (charcode & 0xFF) is the second byte value *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** Note that not all values of "charcode" are valid according *****/
|
|
|
|
/***** to these rules, and the function moderately check the *****/
|
|
|
|
/***** arguments. *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 2 */
|
|
|
|
/* length 2 USHORT table length in bytes */
|
|
|
|
/* language 4 USHORT Mac language code */
|
|
|
|
/* keys 6 USHORT[256] sub-header keys */
|
|
|
|
/* subs 518 SUBHEAD[NSUBS] sub-headers array */
|
|
|
|
/* glyph_ids 518+NSUB*8 USHORT[] glyph id array */
|
|
|
|
/* */
|
|
|
|
/* The `keys' table is used to map charcode high-bytes to sub-headers. */
|
|
|
|
/* The value of `NSUBS' is the number of sub-headers defined in the */
|
|
|
|
/* table and is computed by finding the maximum of the `keys' table. */
|
|
|
|
/* */
|
|
|
|
/* Note that for any n, `keys[n]' is a byte offset within the `subs' */
|
|
|
|
/* table, i.e., it is the corresponding sub-header index multiplied */
|
|
|
|
/* by 8. */
|
|
|
|
/* */
|
|
|
|
/* Each sub-header has the following format: */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* first 0 USHORT first valid low-byte */
|
|
|
|
/* count 2 USHORT number of valid low-bytes */
|
|
|
|
/* delta 4 SHORT see below */
|
|
|
|
/* offset 6 USHORT see below */
|
|
|
|
/* */
|
|
|
|
/* A sub-header defines, for each high-byte, the range of valid */
|
|
|
|
/* low-bytes within the charmap. Note that the range defined by `first' */
|
|
|
|
/* and `count' must be completely included in the interval [0..255] */
|
|
|
|
/* according to the specification. */
|
|
|
|
/* */
|
|
|
|
/* If a character code is contained within a given sub-header, then */
|
|
|
|
/* mapping it to a glyph index is done as follows: */
|
|
|
|
/* */
|
|
|
|
/* * The value of `offset' is read. This is a _byte_ distance from the */
|
|
|
|
/* location of the `offset' field itself into a slice of the */
|
|
|
|
/* `glyph_ids' table. Let's call it `slice' (it's a USHORT[] too). */
|
|
|
|
/* */
|
|
|
|
/* * The value `slice[char.lo - first]' is read. If it is 0, there is */
|
|
|
|
/* no glyph for the charcode. Otherwise, the value of `delta' is */
|
|
|
|
/* added to it (modulo 65536) to form a new glyph index. */
|
|
|
|
/* */
|
|
|
|
/* It is up to the validation routine to check that all offsets fall */
|
|
|
|
/* within the glyph ids table (and not within the `subs' table itself or */
|
|
|
|
/* outside of the CMap). */
|
|
|
|
/* */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_2
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap2_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* p = table + 2; /* skip format */
|
|
|
|
FT_UInt length = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt n, max_subs;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* keys; /* keys table */
|
|
|
|
FT_Byte* subs; /* sub-headers */
|
|
|
|
FT_Byte* glyph_ids; /* glyph id array */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( table + length > valid->limit || length < 6 + 512 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
keys = table + 6;
|
|
|
|
|
|
|
|
/* parse keys to compute sub-headers count */
|
2002-03-22 16:02:38 +01:00
|
|
|
p = keys;
|
|
|
|
max_subs = 0;
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( n = 0; n < 256; n++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt idx = TT_NEXT_USHORT( p );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* value must be multiple of 8 */
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID && ( idx & 7 ) != 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
idx >>= 3;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx > max_subs )
|
|
|
|
max_subs = idx;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_ASSERT( p == table + 518 );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
subs = p;
|
2002-03-31 20:48:24 +02:00
|
|
|
glyph_ids = subs + (max_subs + 1) * 8;
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( glyph_ids > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* parse sub-headers */
|
|
|
|
for ( n = 0; n <= max_subs; n++ )
|
|
|
|
{
|
|
|
|
FT_UInt first_code, code_count, offset;
|
|
|
|
FT_Int delta;
|
|
|
|
FT_Byte* ids;
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
first_code = TT_NEXT_USHORT( p );
|
|
|
|
code_count = TT_NEXT_USHORT( p );
|
|
|
|
delta = TT_NEXT_SHORT( p );
|
|
|
|
offset = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check range within 0..255 */
|
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID )
|
|
|
|
{
|
|
|
|
if ( first_code >= 256 || first_code + code_count > 256 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check offset */
|
|
|
|
if ( offset != 0 )
|
|
|
|
{
|
|
|
|
ids = p - 2 + offset;
|
|
|
|
if ( ids < glyph_ids || ids + code_count*2 > table + length )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_OFFSET;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check glyph ids */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* limit = p + code_count * 2;
|
|
|
|
FT_UInt idx;
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
for ( ; p < limit; )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = TT_NEXT_USHORT( p );
|
|
|
|
if ( idx != 0 )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = ( idx + delta ) & 0xFFFFU;
|
|
|
|
if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* return sub header corresponding to a given character code */
|
2002-03-31 20:48:24 +02:00
|
|
|
/* NULL on invalid charcode */
|
2002-02-22 19:28:11 +01:00
|
|
|
static FT_Byte*
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap2_get_subheader( FT_Byte* table,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
|
|
|
FT_Byte* result = NULL;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
if ( char_code < 0x10000UL )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt char_lo = (FT_UInt)( char_code & 0xFF );
|
|
|
|
FT_UInt char_hi = (FT_UInt)( char_code >> 8 );
|
|
|
|
FT_Byte* p = table + 6; /* keys table */
|
|
|
|
FT_Byte* subs = table + 518; /* subheaders table */
|
|
|
|
FT_Byte* sub;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
if ( char_hi == 0 )
|
|
|
|
{
|
|
|
|
/* an 8-bit character code -- we use subHeader 0 in this case */
|
2002-03-31 20:48:24 +02:00
|
|
|
/* to test whether the character code is in the charmap */
|
2002-02-22 19:28:11 +01:00
|
|
|
/* */
|
|
|
|
sub = subs; /* jump to first sub-header */
|
|
|
|
|
|
|
|
/* check that the sub-header for this byte is 0, which */
|
|
|
|
/* indicates that it's really a valid one-byte value */
|
|
|
|
/* Otherwise, return 0 */
|
|
|
|
/* */
|
2002-03-31 20:48:24 +02:00
|
|
|
p += char_lo * 2;
|
|
|
|
if ( TT_PEEK_USHORT( p ) != 0 )
|
2002-02-22 19:28:11 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* a 16-bit character code */
|
|
|
|
|
2003-12-24 14:37:58 +01:00
|
|
|
/* jump to key entry */
|
|
|
|
p += char_hi * 2;
|
|
|
|
/* jump to sub-header */
|
|
|
|
sub = subs + ( FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 8 ) );
|
|
|
|
|
|
|
|
/* check that the high byte isn't a valid one-byte value */
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( sub == subs )
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
result = sub;
|
|
|
|
}
|
|
|
|
Exit:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap2_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_Byte* subheader;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
subheader = tt_cmap2_get_subheader( table, char_code );
|
|
|
|
if ( subheader )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* p = subheader;
|
|
|
|
FT_UInt idx = (FT_UInt)(char_code & 0xFF);
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt start, count;
|
|
|
|
FT_Int delta;
|
|
|
|
FT_UInt offset;
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_USHORT( p );
|
|
|
|
count = TT_NEXT_USHORT( p );
|
|
|
|
delta = TT_NEXT_SHORT ( p );
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
idx -= start;
|
|
|
|
if ( idx < count && offset != 0 )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p += offset + 2 * idx;
|
|
|
|
idx = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx != 0 )
|
|
|
|
result = (FT_UInt)( idx + delta ) & 0xFFFFU;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
tt_cmap2_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pcharcode )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt gindex = 0;
|
|
|
|
FT_UInt32 result = 0;
|
|
|
|
FT_UInt32 charcode = *pcharcode + 1;
|
|
|
|
FT_Byte* subheader;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
while ( charcode < 0x10000UL )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
subheader = tt_cmap2_get_subheader( table, charcode );
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( subheader )
|
|
|
|
{
|
|
|
|
FT_Byte* p = subheader;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt start = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt count = TT_NEXT_USHORT( p );
|
|
|
|
FT_Int delta = TT_NEXT_SHORT ( p );
|
|
|
|
FT_UInt offset = TT_PEEK_USHORT( p );
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt char_lo = (FT_UInt)( charcode & 0xFF );
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt pos, idx;
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( offset == 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
goto Next_SubHeader;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( char_lo < start )
|
|
|
|
{
|
|
|
|
char_lo = start;
|
|
|
|
pos = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pos = (FT_UInt)( char_lo - start );
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
p += offset + pos * 2;
|
2003-12-24 02:10:46 +01:00
|
|
|
charcode = FT_PAD_FLOOR( charcode, 256 ) + char_lo;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
for ( ; pos < count; pos++, charcode++ )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx != 0 )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = ( idx + delta ) & 0xFFFFU;
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
result = charcode;
|
2002-02-22 19:28:11 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* jump to next sub-header, i.e. higher byte value */
|
|
|
|
Next_SubHeader:
|
2003-12-24 02:10:46 +01:00
|
|
|
charcode = FT_PAD_FLOOR( charcode, 256 ) + 256;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2002-03-22 16:02:38 +01:00
|
|
|
*pcharcode = result;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
return gindex;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap2_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 4;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap2_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-26 03:38:39 +01:00
|
|
|
sizeof( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap2_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap2_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
2,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap2_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap2_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_2 */
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 4 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 4 */
|
|
|
|
/* length 2 USHORT table length */
|
|
|
|
/* in bytes */
|
|
|
|
/* language 4 USHORT Mac language code */
|
|
|
|
/* */
|
|
|
|
/* segCountX2 6 USHORT 2*NUM_SEGS */
|
|
|
|
/* searchRange 8 USHORT 2*(1 << LOG_SEGS) */
|
|
|
|
/* entrySelector 10 USHORT LOG_SEGS */
|
|
|
|
/* rangeShift 12 USHORT segCountX2 - */
|
|
|
|
/* searchRange */
|
|
|
|
/* */
|
|
|
|
/* endCount 14 USHORT[NUM_SEGS] end charcode for */
|
|
|
|
/* each segment; last */
|
|
|
|
/* is 0xFFFF */
|
|
|
|
/* */
|
|
|
|
/* pad 14+NUM_SEGS*2 USHORT padding */
|
|
|
|
/* */
|
|
|
|
/* startCount 16+NUM_SEGS*2 USHORT[NUM_SEGS] first charcode for */
|
|
|
|
/* each segment */
|
|
|
|
/* */
|
|
|
|
/* idDelta 16+NUM_SEGS*4 SHORT[NUM_SEGS] delta for each */
|
|
|
|
/* segment */
|
|
|
|
/* idOffset 16+NUM_SEGS*6 SHORT[NUM_SEGS] range offset for */
|
|
|
|
/* each segment; can be */
|
|
|
|
/* zero */
|
|
|
|
/* */
|
|
|
|
/* glyphIds 16+NUM_SEGS*8 USHORT[] array of glyph id */
|
|
|
|
/* ranges */
|
|
|
|
/* */
|
|
|
|
/* Character codes are modelled by a series of ordered (increasing) */
|
|
|
|
/* intervals called segments. Each segment has start and end codes, */
|
|
|
|
/* provided by the `startCount' and `endCount' arrays. Segments must */
|
|
|
|
/* not be overlapping and the last segment should always contain the */
|
|
|
|
/* `0xFFFF' endCount. */
|
|
|
|
/* */
|
|
|
|
/* The fields `searchRange', `entrySelector' and `rangeShift' are better */
|
|
|
|
/* ignored (they are traces of over-engineering in the TrueType */
|
|
|
|
/* specification). */
|
|
|
|
/* */
|
|
|
|
/* Each segment also has a signed `delta', as well as an optional offset */
|
|
|
|
/* within the `glyphIds' table. */
|
|
|
|
/* */
|
|
|
|
/* If a segment's idOffset is 0, the glyph index corresponding to any */
|
|
|
|
/* charcode within the segment is obtained by adding the value of */
|
|
|
|
/* `idDelta' directly to the charcode, modulo 65536. */
|
|
|
|
/* */
|
|
|
|
/* Otherwise, a glyph index is taken from the glyph ids sub-array for */
|
|
|
|
/* the segment, and the value of `idDelta' is added to it. */
|
|
|
|
/* */
|
2002-09-25 01:39:58 +02:00
|
|
|
/* */
|
|
|
|
/* Finally, note that certain fonts contain invalid charmaps that */
|
|
|
|
/* contain end=0xFFFF, start=0xFFFF, delta=0x0001, offset=0xFFFF at the */
|
|
|
|
/* of their charmaps (e.g. opens___.ttf which comes with OpenOffice.org) */
|
|
|
|
/* we need special code to deal with them correctly... */
|
|
|
|
/* */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_4
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap4_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* p = table + 2; /* skip format */
|
|
|
|
FT_UInt length = TT_NEXT_USHORT( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte *ends, *starts, *offsets, *deltas, *glyph_ids;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt num_segs;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-10-07 12:12:43 +02:00
|
|
|
|
|
|
|
/* in certain fonts, the `length' field is invalid and goes */
|
|
|
|
/* out of bound. We try to correct this here... */
|
* src/pfr/pfrsbit.h, src/pfr/pfrsbit.c, src/pfr/pfrload.c,
src/pfr/pfrgload.c, src/pfr/pfrobjs.c, src/pfr/pfrtypes.h,
Jamfile, src/base/ftobjs.c: adding support for embedded bitmaps to
the PFR driver, and rewriting its kerning loader / handler to use all
kerning pairs in a physical font (and not just the first item).
* src/tools/docmaker/content.py, src/tools/docmaker/sources.py,
src/tools/docmaker/tohtml.py: fixing a few nasty bugs
* src/sfnt/ttcmap0.c: the validator for format 4 sub-tables is
now capable of dealing with invalid "length" fields at the start
of the sub-table. This allows fonts like "mg______.ttf" (i.e.
Marriage) to return accurate charmaps.
2002-10-05 16:57:03 +02:00
|
|
|
if ( length < 16 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
* src/pfr/pfrsbit.h, src/pfr/pfrsbit.c, src/pfr/pfrload.c,
src/pfr/pfrgload.c, src/pfr/pfrobjs.c, src/pfr/pfrtypes.h,
Jamfile, src/base/ftobjs.c: adding support for embedded bitmaps to
the PFR driver, and rewriting its kerning loader / handler to use all
kerning pairs in a physical font (and not just the first item).
* src/tools/docmaker/content.py, src/tools/docmaker/sources.py,
src/tools/docmaker/tohtml.py: fixing a few nasty bugs
* src/sfnt/ttcmap0.c: the validator for format 4 sub-tables is
now capable of dealing with invalid "length" fields at the start
of the sub-table. This allows fonts like "mg______.ttf" (i.e.
Marriage) to return accurate charmaps.
2002-10-05 16:57:03 +02:00
|
|
|
if ( table + length > valid->limit )
|
|
|
|
{
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
FT_INVALID_TOO_SHORT;
|
|
|
|
|
|
|
|
length = (FT_UInt)( valid->limit - table );
|
|
|
|
}
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
p = table + 6;
|
2002-03-31 20:48:24 +02:00
|
|
|
num_segs = TT_NEXT_USHORT( p ); /* read segCountX2 */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID )
|
|
|
|
{
|
|
|
|
/* check that we have an even value here */
|
|
|
|
if ( num_segs & 1 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
num_segs /= 2;
|
|
|
|
|
|
|
|
/* check the search parameters - even though we never use them */
|
|
|
|
/* */
|
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID )
|
|
|
|
{
|
|
|
|
/* check the values of 'searchRange', 'entrySelector', 'rangeShift' */
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt search_range = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt entry_selector = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt range_shift = TT_NEXT_USHORT( p );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( ( search_range | range_shift ) & 1 ) /* must be even values */
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
search_range /= 2;
|
|
|
|
range_shift /= 2;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/* `search range' is the greatest power of 2 that is <= num_segs */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( search_range > num_segs ||
|
|
|
|
search_range * 2 < num_segs ||
|
|
|
|
search_range + range_shift != num_segs ||
|
|
|
|
search_range != ( 1U << entry_selector ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
ends = table + 14;
|
2002-03-31 20:48:24 +02:00
|
|
|
starts = table + 16 + num_segs * 2;
|
|
|
|
deltas = starts + num_segs * 2;
|
|
|
|
offsets = deltas + num_segs * 2;
|
|
|
|
glyph_ids = offsets + num_segs * 2;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( glyph_ids > table + length )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check last segment, its end count must be FFFF */
|
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p = ends + ( num_segs - 1 ) * 2;
|
|
|
|
if ( TT_PEEK_USHORT( p ) != 0xFFFFU )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/* check that segments are sorted in increasing order and do not */
|
|
|
|
/* overlap; check also the offsets */
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-04-28 12:25:55 +02:00
|
|
|
FT_UInt start, end, last = 0, offset, n;
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Int delta;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( n = 0; n < num_segs; n++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p = starts + n * 2;
|
|
|
|
start = TT_PEEK_USHORT( p );
|
|
|
|
p = ends + n * 2;
|
|
|
|
end = TT_PEEK_USHORT( p );
|
|
|
|
p = deltas + n * 2;
|
|
|
|
delta = TT_PEEK_SHORT( p );
|
|
|
|
p = offsets + n * 2;
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-22 23:37:40 +01:00
|
|
|
if ( start > end )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-05-02 08:50:58 +02:00
|
|
|
/* this test should be performed at default validation level; */
|
|
|
|
/* unfortunately, some popular Asian fonts present overlapping */
|
|
|
|
/* ranges in their charmaps */
|
2002-05-01 10:40:32 +02:00
|
|
|
/* */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
|
|
|
if ( n > 0 && start <= last )
|
|
|
|
FT_INVALID_DATA;
|
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-09-25 01:39:58 +02:00
|
|
|
if ( offset && offset != 0xFFFFU )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
|
|
|
p += offset; /* start of glyph id array */
|
|
|
|
|
|
|
|
/* check that we point within the glyph ids table only */
|
2003-04-23 20:21:48 +02:00
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
|
|
|
if ( p < glyph_ids ||
|
|
|
|
p + ( end - start + 1 ) * 2 > table + length )
|
|
|
|
FT_INVALID_DATA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( p < glyph_ids ||
|
|
|
|
p + ( end - start + 1 ) * 2 > valid->limit )
|
|
|
|
FT_INVALID_DATA;
|
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
/* check glyph indices within the segment range */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
2002-09-25 01:39:58 +02:00
|
|
|
FT_UInt i, idx;
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-09-25 01:39:58 +02:00
|
|
|
for ( i = start; i < end; i++ )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = FT_NEXT_USHORT( p );
|
|
|
|
if ( idx != 0 )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = (FT_UInt)( idx + delta ) & 0xFFFFU;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
2002-09-25 01:39:58 +02:00
|
|
|
else if ( offset == 0xFFFFU )
|
|
|
|
{
|
|
|
|
/* Some fonts (erroneously?) use a range offset of 0xFFFF */
|
|
|
|
/* to mean missing glyph in cmap table */
|
|
|
|
/* */
|
|
|
|
if ( valid->level >= FT_VALIDATE_PARANOID ||
|
|
|
|
n != num_segs - 1 ||
|
|
|
|
!( start == 0xFFFFU && end == 0xFFFFU && delta == 0x1U ) )
|
|
|
|
FT_INVALID_DATA;
|
|
|
|
}
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
last = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap4_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt result = 0;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
if ( char_code < 0x10000UL )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt idx, num_segs2;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_Int delta;
|
2002-05-01 10:40:32 +02:00
|
|
|
FT_UInt code = (FT_UInt)char_code;
|
|
|
|
FT_Byte* p;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
p = table + 6;
|
2003-12-24 02:10:46 +01:00
|
|
|
num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 ); /* be paranoid! */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
#if 1
|
2002-05-02 08:50:58 +02:00
|
|
|
/* Some fonts have more than 170 segments in their charmaps! */
|
|
|
|
/* We changed this function to use a more efficient binary */
|
|
|
|
/* search for improving performance */
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-05-02 08:50:58 +02:00
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = num_segs2 >> 1;
|
|
|
|
FT_UInt mid, start, end, offset;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
while ( min < max )
|
|
|
|
{
|
|
|
|
mid = ( min + max ) >> 1;
|
2002-05-02 08:50:58 +02:00
|
|
|
p = table + 14 + mid * 2;
|
2002-06-11 01:03:35 +02:00
|
|
|
end = TT_NEXT_USHORT( p );
|
2002-05-01 10:40:32 +02:00
|
|
|
p += num_segs2;
|
|
|
|
start = TT_PEEK_USHORT( p);
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( code < start )
|
|
|
|
max = mid;
|
|
|
|
else if ( code > end )
|
2002-05-02 08:50:58 +02:00
|
|
|
min = mid + 1;
|
2002-05-01 10:40:32 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* we found the segment */
|
|
|
|
idx = code;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
p += num_segs2;
|
|
|
|
delta = TT_PEEK_SHORT( p );
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
p += num_segs2;
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-09-25 01:39:58 +02:00
|
|
|
if ( offset == 0xFFFFU )
|
|
|
|
goto Exit;
|
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( offset != 0 )
|
|
|
|
{
|
2002-05-02 08:50:58 +02:00
|
|
|
p += offset + 2 * ( idx - start );
|
2002-05-01 10:40:32 +02:00
|
|
|
idx = TT_PEEK_USHORT( p );
|
|
|
|
}
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( idx != 0 )
|
2002-05-02 08:50:58 +02:00
|
|
|
result = (FT_UInt)( idx + delta ) & 0xFFFFU;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
#else /* 0 - old code */
|
2002-05-02 08:50:58 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
{
|
|
|
|
FT_UInt n;
|
|
|
|
FT_Byte* q;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
p = table + 14; /* ends table */
|
|
|
|
q = table + 16 + num_segs2; /* starts table */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
for ( n = 0; n < num_segs2; n += 2 )
|
|
|
|
{
|
|
|
|
FT_UInt end = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt start = TT_NEXT_USHORT( q );
|
|
|
|
FT_UInt offset;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( code < start )
|
|
|
|
break;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( code <= end )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-05-01 10:40:32 +02:00
|
|
|
idx = code;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
p = q + num_segs2 - 2;
|
|
|
|
delta = TT_PEEK_SHORT( p );
|
|
|
|
p += num_segs2;
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-09-25 01:39:58 +02:00
|
|
|
if ( offset == 0xFFFFU )
|
|
|
|
goto Exit;
|
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( offset != 0 )
|
|
|
|
{
|
|
|
|
p += offset + 2 * ( idx - start );
|
|
|
|
idx = TT_PEEK_USHORT( p );
|
|
|
|
}
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
if ( idx != 0 )
|
|
|
|
result = (FT_UInt)( idx + delta ) & 0xFFFFU;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-02 08:50:58 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
#endif /* 0 */
|
2002-05-02 08:50:58 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-05-01 10:40:32 +02:00
|
|
|
Exit:
|
2002-02-22 19:28:11 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
|
|
|
tt_cmap4_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt32 result = 0;
|
|
|
|
FT_UInt gindex = 0;
|
2003-05-07 12:21:13 +02:00
|
|
|
FT_UInt32 char_code = *pchar_code;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_UInt code, num_segs2;
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2003-05-07 12:21:13 +02:00
|
|
|
if ( char_code >= 0xFFFFUL )
|
2002-02-22 19:28:11 +01:00
|
|
|
goto Exit;
|
|
|
|
|
2003-05-07 12:21:13 +02:00
|
|
|
code = (FT_UInt)char_code + 1;
|
2002-02-22 19:28:11 +01:00
|
|
|
p = table + 6;
|
2003-12-24 02:10:46 +01:00
|
|
|
num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT(p), 2 ); /* ensure even-ness */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2003-05-07 12:21:13 +02:00
|
|
|
#if 1
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
2003-05-07 12:21:13 +02:00
|
|
|
/* Some fonts have more than 170 segments in their charmaps! */
|
|
|
|
/* We changed this function to use a more efficient binary */
|
|
|
|
/* search */
|
|
|
|
FT_UInt offset;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Int delta;
|
2003-05-07 12:21:13 +02:00
|
|
|
FT_UInt min = 0;
|
|
|
|
FT_UInt max = num_segs2 >> 1;
|
|
|
|
FT_UInt mid, start, end;
|
|
|
|
FT_UInt hi;
|
|
|
|
|
|
|
|
|
|
|
|
/* we begin by finding the segment which end is
|
|
|
|
closer to our code point */
|
2003-05-19 14:45:28 +02:00
|
|
|
hi = max + 1;
|
2003-05-07 12:21:13 +02:00
|
|
|
while ( min < max )
|
|
|
|
{
|
|
|
|
mid = ( min + max ) >> 1;
|
|
|
|
p = table + 14 + mid * 2;
|
|
|
|
end = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
if ( end < code )
|
|
|
|
min = mid + 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hi = mid;
|
|
|
|
max = mid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hi > max )
|
|
|
|
{
|
|
|
|
/* the point is behind the last segment;
|
|
|
|
we will exit right now */
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = table + 14 + hi * 2;
|
|
|
|
end = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
p += 2 + num_segs2;
|
|
|
|
start = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
if ( code < start )
|
|
|
|
code = start;
|
|
|
|
|
|
|
|
p += num_segs2;
|
|
|
|
delta = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
p += num_segs2;
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
if ( offset != 0 && offset != 0xFFFFU )
|
|
|
|
{
|
|
|
|
/* parse the glyph ids array for non-zero index */
|
|
|
|
p += offset + ( code - start ) * 2;
|
|
|
|
while ( code <= end )
|
|
|
|
{
|
|
|
|
gindex = TT_NEXT_USHORT( p );
|
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
|
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
result = code;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( offset == 0xFFFFU )
|
|
|
|
{
|
|
|
|
/* an offset of 0xFFFF means an empty glyph in certain fonts! */
|
|
|
|
code = end + 1;
|
|
|
|
}
|
|
|
|
else /* offset == 0 */
|
|
|
|
{
|
|
|
|
gindex = (FT_UInt)( code + delta ) & 0xFFFFU;
|
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
result = code;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* old code -- kept for reference */
|
|
|
|
|
|
|
|
for ( ;; )
|
|
|
|
{
|
|
|
|
FT_UInt offset, n;
|
|
|
|
FT_Int delta;
|
|
|
|
FT_Byte* q;
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
p = table + 14; /* ends table */
|
|
|
|
q = table + 16 + num_segs2; /* starts table */
|
|
|
|
|
|
|
|
for ( n = 0; n < num_segs2; n += 2 )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt end = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt start = TT_NEXT_USHORT( q );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( code < start )
|
|
|
|
code = start;
|
|
|
|
|
|
|
|
if ( code <= end )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p = q + num_segs2 - 2;
|
|
|
|
delta = TT_PEEK_SHORT( p );
|
|
|
|
p += num_segs2;
|
|
|
|
offset = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-09-25 01:39:58 +02:00
|
|
|
if ( offset != 0 && offset != 0xFFFFU )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
|
|
|
/* parse the glyph ids array for non-0 index */
|
2002-03-31 20:48:24 +02:00
|
|
|
p += offset + ( code - start ) * 2;
|
2002-02-22 19:28:11 +01:00
|
|
|
while ( code <= end )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
gindex = (FT_UInt)( gindex + delta ) & 0xFFFFU;
|
|
|
|
if ( gindex != 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
code++;
|
|
|
|
}
|
|
|
|
}
|
2002-09-25 01:39:58 +02:00
|
|
|
else if ( offset == 0xFFFFU )
|
|
|
|
{
|
2002-09-27 20:17:17 +02:00
|
|
|
/* an offset of 0xFFFF means an empty glyph in certain fonts! */
|
2002-09-25 01:39:58 +02:00
|
|
|
code = end;
|
|
|
|
break;
|
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
else
|
|
|
|
gindex = (FT_UInt)( code + delta ) & 0xFFFFU;
|
|
|
|
|
|
|
|
if ( gindex == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = code;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* loop to next trial charcode */
|
|
|
|
if ( code >= 0xFFFFU )
|
|
|
|
break;
|
|
|
|
|
|
|
|
code++;
|
|
|
|
}
|
2003-05-07 12:21:13 +02:00
|
|
|
|
|
|
|
#endif /* !1 */
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
Exit:
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = result;
|
|
|
|
return gindex;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap4_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 4;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap4_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
sizeof ( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap4_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap4_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
4,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap4_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap4_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_4 */
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 6 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 4 */
|
|
|
|
/* length 2 USHORT table length in bytes */
|
|
|
|
/* language 4 USHORT Mac language code */
|
|
|
|
/* */
|
|
|
|
/* first 6 USHORT first segment code */
|
|
|
|
/* count 8 USHORT segment size in chars */
|
|
|
|
/* glyphIds 10 USHORT[count] glyph ids */
|
|
|
|
/* */
|
|
|
|
/* A very simplified segment mapping. */
|
|
|
|
/* */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_6
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap6_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte* p;
|
2003-04-23 21:48:24 +02:00
|
|
|
FT_UInt length, count;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( table + 10 > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
p = table + 2;
|
2002-03-31 20:48:24 +02:00
|
|
|
length = TT_NEXT_USHORT( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2003-04-23 21:48:24 +02:00
|
|
|
p = table + 8; /* skip language and start index */
|
2002-03-31 20:48:24 +02:00
|
|
|
count = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( table + length > valid->limit || length < 10 + count * 2 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check glyph indices */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
|
|
|
FT_UInt gindex;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( ; count > 0; count-- )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = TT_NEXT_USHORT( p );
|
|
|
|
if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap6_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_Byte* p = table + 6;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt start = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt count = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt idx = (FT_UInt)( char_code - start );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx < count )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p += 2 * idx;
|
|
|
|
result = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap6_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt32 result = 0;
|
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
|
|
|
FT_UInt gindex = 0;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_Byte* p = table + 6;
|
|
|
|
FT_UInt start = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt count = TT_NEXT_USHORT( p );
|
|
|
|
FT_UInt idx;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
if ( char_code >= 0x10000UL )
|
2002-02-22 19:28:11 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
if ( char_code < start )
|
|
|
|
char_code = start;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = (FT_UInt)( char_code - start );
|
|
|
|
p += 2 * idx;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
for ( ; idx < count; idx++ )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
result = char_code;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
char_code++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = result;
|
|
|
|
return gindex;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-28 17:10:29 +01:00
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap6_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 4;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_USHORT( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap6_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
sizeof ( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap6_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap6_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
6,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap6_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap6_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_6 */
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 8 *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** It's hard to completely understand what the OpenType spec *****/
|
|
|
|
/***** says about this format, but here is my conclusion. *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** The purpose of this format is to easily map UTF-16 text to *****/
|
|
|
|
/***** glyph indices. Basically, the `char_code' must be in one of *****/
|
|
|
|
/***** the following formats: *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** - A 16-bit value that isn't part of the Unicode Surrogates *****/
|
|
|
|
/***** Area (i.e. U+D800-U+DFFF). *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** - A 32-bit value, made of two surrogate values, i.e.. if *****/
|
|
|
|
/***** `char_code = (char_hi << 16) | char_lo', then both *****/
|
|
|
|
/***** `char_hi' and `char_lo' must be in the Surrogates Area. *****/
|
|
|
|
/***** Area. *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** The 'is32' table embedded in the charmap indicates whether a *****/
|
|
|
|
/***** given 16-bit value is in the surrogates area or not. *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** So, for any given `char_code', we can assert the following: *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** If `char_hi == 0' then we must have `is32[char_lo] == 0'. *****/
|
|
|
|
/***** *****/
|
|
|
|
/***** If `char_hi != 0' then we must have both *****/
|
|
|
|
/***** `is32[char_hi] != 0' and `is32[char_lo] != 0'. *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 8 */
|
|
|
|
/* reseved 2 USHORT reserved */
|
|
|
|
/* length 4 ULONG length in bytes */
|
|
|
|
/* language 8 ULONG Mac language code */
|
|
|
|
/* is32 12 BYTE[8192] 32-bitness bitmap */
|
|
|
|
/* count 8204 ULONG number of groups */
|
|
|
|
/* */
|
|
|
|
/* This header is followed by 'count' groups of the following format: */
|
|
|
|
/* */
|
|
|
|
/* start 0 ULONG first charcode */
|
|
|
|
/* end 4 ULONG last charcode */
|
|
|
|
/* startId 8 ULONG start glyph id for the group */
|
|
|
|
/* */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_8
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap8_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
|
|
|
FT_Byte* p = table + 4;
|
|
|
|
FT_Byte* is32;
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_UInt32 length;
|
|
|
|
FT_UInt32 num_groups;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( table + 16 + 8192 > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
length = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( table + length > valid->limit || length < 8208 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
is32 = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
p = is32 + 8192; /* skip `is32' array */
|
|
|
|
num_groups = TT_NEXT_ULONG( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( p + num_groups * 12 > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check groups, they must be in increasing order */
|
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_UInt32 n, start, end, start_id, count, last = 0;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( n = 0; n < num_groups; n++ )
|
|
|
|
{
|
|
|
|
FT_UInt hi, lo;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( start > end )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( n > 0 && start <= last )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
count = (FT_UInt32)( end - start + 1 );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( start & ~0xFFFFU )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
/* start_hi != 0; check that is32[i] is 1 for each i in */
|
|
|
|
/* the `hi' and `lo' of the range [start..end] */
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( ; count > 0; count--, start++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
hi = (FT_UInt)( start >> 16 );
|
|
|
|
lo = (FT_UInt)( start & 0xFFFFU );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( (is32[hi >> 3] & ( 0x80 >> ( hi & 7 ) ) ) == 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) == 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
/* start_hi == 0; check that is32[i] is 0 for each i in */
|
2002-02-22 19:28:11 +01:00
|
|
|
/* the range [start..end] */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/* end_hi cannot be != 0! */
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( end & ~0xFFFFU )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( ; count > 0; count--, start++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
lo = (FT_UInt)( start & 0xFFFFU );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( (is32[lo >> 3] & ( 0x80 >> ( lo & 7 ) ) ) != 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
last = end;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap8_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_Byte* p = table + 8204;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 num_groups = TT_NEXT_ULONG( p );
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt32 start, end, start_id;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( ; num_groups > 0; num_groups-- )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( char_code < start )
|
|
|
|
break;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( char_code <= end )
|
|
|
|
{
|
2002-09-28 18:40:57 +02:00
|
|
|
result = (FT_UInt)( start_id + char_code - start );
|
2002-02-22 19:28:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap8_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_UInt32 result = 0;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
2002-02-22 19:28:11 +01:00
|
|
|
FT_UInt gindex = 0;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte* p = table + 8204;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 num_groups = TT_NEXT_ULONG( p );
|
2002-07-01 23:50:12 +02:00
|
|
|
FT_UInt32 start, end, start_id;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
p = table + 8208;
|
|
|
|
|
2002-07-01 23:50:12 +02:00
|
|
|
for ( ; num_groups > 0; num_groups-- )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( char_code < start )
|
|
|
|
char_code = start;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( char_code <= end )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = (FT_UInt)( char_code - start + start_id );
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
result = char_code;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
Exit:
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = result;
|
|
|
|
return gindex;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap8_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 8;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap8_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
sizeof ( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap8_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap8_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
8,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap8_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap8_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_8 */
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 10 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 10 */
|
|
|
|
/* reserved 2 USHORT reserved */
|
|
|
|
/* length 4 ULONG length in bytes */
|
|
|
|
/* language 8 ULONG Mac language code */
|
|
|
|
/* */
|
|
|
|
/* start 12 ULONG first char in range */
|
|
|
|
/* count 16 ULONG number of chars in range */
|
|
|
|
/* glyphIds 20 USHORT[count] glyph indices covered */
|
|
|
|
/* */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_10
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap10_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte* p = table + 4;
|
2003-04-23 21:48:24 +02:00
|
|
|
FT_ULong length, count;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( table + 20 > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
length = TT_NEXT_ULONG( p );
|
2003-04-23 21:48:24 +02:00
|
|
|
p = table + 16;
|
2002-03-31 20:48:24 +02:00
|
|
|
count = TT_NEXT_ULONG( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( table + length > valid->limit || length < 20 + count * 2 )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
/* check glyph indices */
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
|
|
|
FT_UInt gindex;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
for ( ; count > 0; count-- )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = TT_NEXT_USHORT( p );
|
|
|
|
if ( gindex >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap10_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt result = 0;
|
|
|
|
FT_Byte* p = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 start = TT_NEXT_ULONG( p );
|
|
|
|
FT_UInt32 count = TT_NEXT_ULONG( p );
|
|
|
|
FT_UInt32 idx = (FT_ULong)( char_code - start );
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( idx < count )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
p += 2 * idx;
|
|
|
|
result = TT_PEEK_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap10_char_next( TT_CMap cmap,
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
|
|
|
FT_UInt gindex = 0;
|
|
|
|
FT_Byte* p = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 start = TT_NEXT_ULONG( p );
|
|
|
|
FT_UInt32 count = TT_NEXT_ULONG( p );
|
|
|
|
FT_UInt32 idx;
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
if ( char_code < start )
|
|
|
|
char_code = start;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
idx = (FT_UInt32)( char_code - start );
|
|
|
|
p += 2 * idx;
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
for ( ; idx < count; idx++ )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
gindex = TT_NEXT_USHORT( p );
|
2002-02-22 19:28:11 +01:00
|
|
|
if ( gindex != 0 )
|
|
|
|
break;
|
|
|
|
char_code++;
|
|
|
|
}
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = char_code;
|
|
|
|
return gindex;
|
2002-02-22 19:28:11 +01:00
|
|
|
}
|
|
|
|
|
2002-02-28 17:10:29 +01:00
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap10_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 8;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap10_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
sizeof ( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap10_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap10_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
10,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap10_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap10_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_10 */
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FORMAT 12 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* TABLE OVERVIEW */
|
|
|
|
/* -------------- */
|
|
|
|
/* */
|
|
|
|
/* NAME OFFSET TYPE DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* format 0 USHORT must be 12 */
|
|
|
|
/* reserved 2 USHORT reserved */
|
|
|
|
/* length 4 ULONG length in bytes */
|
|
|
|
/* language 8 ULONG Mac language code */
|
|
|
|
/* count 12 ULONG number of groups */
|
|
|
|
/* 16 */
|
|
|
|
/* */
|
|
|
|
/* This header is followed by `count' groups of the following format: */
|
|
|
|
/* */
|
|
|
|
/* start 0 ULONG first charcode */
|
|
|
|
/* end 4 ULONG last charcode */
|
|
|
|
/* startId 8 ULONG start glyph id for the group */
|
|
|
|
/* */
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_12
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( void )
|
2002-02-22 19:28:11 +01:00
|
|
|
tt_cmap12_validate( FT_Byte* table,
|
|
|
|
FT_Validator valid )
|
|
|
|
{
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_ULong length;
|
|
|
|
FT_ULong num_groups;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
if ( table + 16 > valid->limit )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
p = table + 4;
|
2002-03-31 20:48:24 +02:00
|
|
|
length = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
p = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
num_groups = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( table + length > valid->limit || length < 16 + 12 * num_groups )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_TOO_SHORT;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
/* check groups, they must be in increasing order */
|
|
|
|
{
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_ULong n, start, end, start_id, last = 0;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
for ( n = 0; n < num_groups; n++ )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( start > end )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( n > 0 && start <= last )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_DATA;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( valid->level >= FT_VALIDATE_TIGHT )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( start_id + end - start >= TT_VALID_GLYPH_COUNT( valid ) )
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_INVALID_GLYPH_ID;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
last = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-01 03:26:22 +01:00
|
|
|
tt_cmap12_char_index( TT_CMap cmap,
|
|
|
|
FT_UInt32 char_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_UInt result = 0;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* p = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 num_groups = TT_NEXT_ULONG( p );
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt32 start, end, start_id;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
for ( ; num_groups > 0; num_groups-- )
|
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( char_code < start )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ( char_code <= end )
|
|
|
|
{
|
2002-09-28 18:40:57 +02:00
|
|
|
result = (FT_UInt)( start_id + char_code - start );
|
2002-02-27 22:25:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_CALLBACK_DEF( FT_UInt )
|
2002-03-31 20:48:24 +02:00
|
|
|
tt_cmap12_char_next( TT_CMap cmap,
|
|
|
|
FT_UInt32 *pchar_code )
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_Byte* table = cmap->data;
|
|
|
|
FT_UInt32 result = 0;
|
2002-03-22 16:02:38 +01:00
|
|
|
FT_UInt32 char_code = *pchar_code + 1;
|
2002-02-27 22:25:47 +01:00
|
|
|
FT_UInt gindex = 0;
|
|
|
|
FT_Byte* p = table + 12;
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_UInt32 num_groups = TT_NEXT_ULONG( p );
|
2002-07-01 23:50:12 +02:00
|
|
|
FT_UInt32 start, end, start_id;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
p = table + 16;
|
2002-02-27 22:25:47 +01:00
|
|
|
|
2002-07-01 23:50:12 +02:00
|
|
|
for ( ; num_groups > 0; num_groups-- )
|
2002-02-27 22:25:47 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
start = TT_NEXT_ULONG( p );
|
|
|
|
end = TT_NEXT_ULONG( p );
|
|
|
|
start_id = TT_NEXT_ULONG( p );
|
2002-02-27 22:25:47 +01:00
|
|
|
|
|
|
|
if ( char_code < start )
|
|
|
|
char_code = start;
|
|
|
|
|
|
|
|
if ( char_code <= end )
|
|
|
|
{
|
|
|
|
gindex = (FT_UInt)(char_code - start + start_id);
|
|
|
|
if ( gindex != 0 )
|
|
|
|
{
|
|
|
|
result = char_code;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
2002-03-22 16:02:38 +01:00
|
|
|
*pchar_code = result;
|
|
|
|
return gindex;
|
2002-02-27 22:25:47 +01:00
|
|
|
}
|
2002-02-22 19:28:11 +01:00
|
|
|
|
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_CALLBACK_DEF( FT_Error )
|
|
|
|
tt_cmap12_get_info( TT_CMap cmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_Byte* p = cmap->data + 8;
|
|
|
|
|
|
|
|
|
|
|
|
cmap_info->language = (FT_ULong)TT_PEEK_ULONG( p );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
const TT_CMap_ClassRec tt_cmap12_class_rec =
|
2002-02-22 19:28:11 +01:00
|
|
|
{
|
2002-02-28 17:10:29 +01:00
|
|
|
{
|
2002-03-31 20:48:24 +02:00
|
|
|
sizeof ( TT_CMapRec ),
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
(FT_CMap_InitFunc) tt_cmap_init,
|
|
|
|
(FT_CMap_DoneFunc) NULL,
|
|
|
|
(FT_CMap_CharIndexFunc)tt_cmap12_char_index,
|
|
|
|
(FT_CMap_CharNextFunc) tt_cmap12_char_next
|
2002-02-28 17:10:29 +01:00
|
|
|
},
|
2002-03-01 03:26:22 +01:00
|
|
|
12,
|
2003-12-17 15:28:22 +01:00
|
|
|
(TT_CMap_ValidateFunc) tt_cmap12_validate,
|
|
|
|
(TT_CMap_Info_GetFunc) tt_cmap12_get_info
|
2002-02-22 19:28:11 +01:00
|
|
|
};
|
|
|
|
|
2002-02-28 17:10:29 +01:00
|
|
|
|
2002-02-22 19:28:11 +01:00
|
|
|
#endif /* TT_CONFIG_CMAP_FORMAT_12 */
|
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-22 16:02:38 +01:00
|
|
|
static const TT_CMap_Class tt_cmap_classes[] =
|
2002-03-01 03:26:22 +01:00
|
|
|
{
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_0
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap0_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_2
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap2_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_4
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap4_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_6
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap6_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_8
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap8_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_10
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap10_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_CMAP_FORMAT_12
|
2002-03-22 16:02:38 +01:00
|
|
|
&tt_cmap12_class_rec,
|
2002-03-01 03:26:22 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
/* parse the `cmap' table and build the corresponding TT_CMap objects */
|
|
|
|
/* in the current face */
|
|
|
|
/* */
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
tt_face_build_cmaps( TT_Face face )
|
2002-03-01 03:26:22 +01:00
|
|
|
{
|
2002-03-30 17:14:48 +01:00
|
|
|
FT_Byte* table = face->cmap_table;
|
|
|
|
FT_Byte* limit = table + face->cmap_size;
|
2002-11-06 23:32:54 +01:00
|
|
|
FT_UInt volatile num_cmaps;
|
|
|
|
FT_Byte* volatile p = table;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-03-22 18:09:52 +01:00
|
|
|
if ( p + 4 > limit )
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
return SFNT_Err_Invalid_Table;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
|
|
|
/* only recognize format 0 */
|
2002-03-31 20:48:24 +02:00
|
|
|
if ( TT_NEXT_USHORT( p ) != 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
{
|
|
|
|
p -= 2;
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
FT_ERROR(( "tt_face_build_cmaps: unsupported `cmap' table format = %d\n",
|
2002-03-31 20:48:24 +02:00
|
|
|
TT_PEEK_USHORT( p ) ));
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
return SFNT_Err_Invalid_Table;
|
2002-03-22 16:02:38 +01:00
|
|
|
}
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
num_cmaps = TT_NEXT_USHORT( p );
|
2002-03-01 03:26:22 +01:00
|
|
|
|
|
|
|
for ( ; num_cmaps > 0 && p + 8 <= limit; num_cmaps-- )
|
|
|
|
{
|
|
|
|
FT_CharMapRec charmap;
|
|
|
|
FT_UInt32 offset;
|
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
charmap.platform_id = TT_NEXT_USHORT( p );
|
|
|
|
charmap.encoding_id = TT_NEXT_USHORT( p );
|
|
|
|
charmap.face = FT_FACE( face );
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
charmap.encoding = FT_ENCODING_NONE; /* will be filled later */
|
2002-03-31 20:48:24 +02:00
|
|
|
offset = TT_NEXT_ULONG( p );
|
2002-03-01 03:26:22 +01:00
|
|
|
|
|
|
|
if ( offset && table + offset + 2 < limit )
|
|
|
|
{
|
2002-03-30 17:14:48 +01:00
|
|
|
FT_Byte* cmap = table + offset;
|
2003-06-07 07:13:22 +02:00
|
|
|
volatile FT_UInt format = TT_PEEK_USHORT( cmap );
|
2002-11-06 23:32:54 +01:00
|
|
|
const TT_CMap_Class* volatile pclazz = tt_cmap_classes;
|
2002-03-30 17:14:48 +01:00
|
|
|
TT_CMap_Class clazz;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
for ( ; *pclazz; pclazz++ )
|
|
|
|
{
|
|
|
|
clazz = *pclazz;
|
|
|
|
if ( clazz->format == format )
|
|
|
|
{
|
2002-03-22 18:09:52 +01:00
|
|
|
volatile TT_ValidatorRec valid;
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-03-31 20:48:24 +02:00
|
|
|
|
|
|
|
ft_validator_init( FT_VALIDATOR( &valid ), cmap, limit,
|
2002-03-22 18:09:52 +01:00
|
|
|
FT_VALIDATE_DEFAULT );
|
2002-06-11 01:03:35 +02:00
|
|
|
|
2002-09-28 18:40:57 +02:00
|
|
|
valid.num_glyphs = (FT_UInt)face->root.num_glyphs;
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-06-11 01:03:35 +02:00
|
|
|
if ( ft_setjmp( FT_VALIDATOR( &valid )->jump_buffer ) == 0 )
|
2002-03-22 16:02:38 +01:00
|
|
|
{
|
|
|
|
/* validate this cmap sub-table */
|
2002-03-31 20:48:24 +02:00
|
|
|
clazz->validate( cmap, FT_VALIDATOR( &valid ) );
|
2002-03-22 16:02:38 +01:00
|
|
|
}
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2002-03-22 18:09:52 +01:00
|
|
|
if ( valid.validator.error == 0 )
|
|
|
|
(void)FT_CMap_New( (FT_CMap_Class)clazz, cmap, &charmap, NULL );
|
2002-03-01 03:26:22 +01:00
|
|
|
else
|
2002-03-31 20:48:24 +02:00
|
|
|
{
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
FT_ERROR(( "tt_face_build_cmaps:" ));
|
2002-03-31 20:48:24 +02:00
|
|
|
FT_ERROR(( " broken cmap sub-table ignored!\n" ));
|
|
|
|
}
|
2002-03-01 03:26:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-17 15:28:22 +01:00
|
|
|
FT_LOCAL( FT_Error )
|
|
|
|
tt_get_cmap_info( FT_CharMap charmap,
|
|
|
|
TT_CMapInfo *cmap_info )
|
|
|
|
{
|
|
|
|
FT_CMap cmap = (FT_CMap)charmap;
|
|
|
|
TT_CMap_Class clazz = (TT_CMap_Class)cmap->clazz;
|
|
|
|
|
|
|
|
|
|
|
|
return clazz->get_cmap_info( charmap, cmap_info );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-27 22:25:47 +01:00
|
|
|
/* END */
|