2000-12-08 03:42:29 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* cffparse.c */
|
|
|
|
/* */
|
|
|
|
/* CFF token stream parser (body) */
|
|
|
|
/* */
|
2002-03-30 17:41:09 +01:00
|
|
|
/* Copyright 1996-2001, 2002 by */
|
2000-12-08 03:42:29 +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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
#include <ft2build.h>
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "cffparse.h"
|
2000-12-08 03:42:29 +01:00
|
|
|
#include FT_INTERNAL_STREAM_H
|
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "cfferrs.h"
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* 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
|
2001-01-03 01:21:59 +01:00
|
|
|
#define FT_COMPONENT trace_cffparse
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
cff_kind_none = 0,
|
|
|
|
cff_kind_num,
|
|
|
|
cff_kind_fixed,
|
|
|
|
cff_kind_string,
|
|
|
|
cff_kind_bool,
|
|
|
|
cff_kind_delta,
|
|
|
|
cff_kind_callback,
|
|
|
|
|
|
|
|
cff_kind_max /* do not remove */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* now generate handlers for the most simple fields */
|
2002-03-30 17:41:09 +01:00
|
|
|
typedef FT_Error (*CFF_Field_Reader)( CFF_Parser parser );
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
typedef struct CFF_Field_Handler_
|
|
|
|
{
|
|
|
|
int kind;
|
|
|
|
int code;
|
|
|
|
FT_UInt offset;
|
|
|
|
FT_Byte size;
|
|
|
|
CFF_Field_Reader reader;
|
|
|
|
FT_UInt array_max;
|
|
|
|
FT_UInt count_offset;
|
|
|
|
|
|
|
|
} CFF_Field_Handler;
|
|
|
|
|
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_LOCAL_DEF( void )
|
* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added
to support charmaps for CFF fonts
* src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
sources, and removing some bugs in the Encoding and Charset loaders
2002-07-10 18:52:06 +02:00
|
|
|
cff_parser_init( CFF_Parser parser,
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_UInt code,
|
|
|
|
void* object )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2002-07-28 07:05:24 +02:00
|
|
|
FT_MEM_ZERO( parser, sizeof ( *parser ) );
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
parser->top = parser->stack;
|
|
|
|
parser->object_code = code;
|
|
|
|
parser->object = object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
/* read an integer */
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Long
|
|
|
|
cff_parse_integer( FT_Byte* start,
|
|
|
|
FT_Byte* limit )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
FT_Byte* p = start;
|
|
|
|
FT_Int v = *p++;
|
|
|
|
FT_Long val = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if ( v == 28 )
|
|
|
|
{
|
|
|
|
if ( p + 2 > limit )
|
|
|
|
goto Bad;
|
|
|
|
|
|
|
|
val = (FT_Short)( ( (FT_Int)p[0] << 8 ) | p[1] );
|
|
|
|
p += 2;
|
|
|
|
}
|
|
|
|
else if ( v == 29 )
|
|
|
|
{
|
|
|
|
if ( p + 4 > limit )
|
|
|
|
goto Bad;
|
|
|
|
|
|
|
|
val = ( (FT_Long)p[0] << 24 ) |
|
|
|
|
( (FT_Long)p[1] << 16 ) |
|
|
|
|
( (FT_Long)p[2] << 8 ) |
|
|
|
|
p[3];
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
else if ( v < 247 )
|
|
|
|
{
|
|
|
|
val = v - 139;
|
|
|
|
}
|
|
|
|
else if ( v < 251 )
|
|
|
|
{
|
|
|
|
if ( p + 1 > limit )
|
|
|
|
goto Bad;
|
|
|
|
|
|
|
|
val = ( v - 247 ) * 256 + p[0] + 108;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( p + 1 > limit )
|
|
|
|
goto Bad;
|
|
|
|
|
|
|
|
val = -( v - 251 ) * 256 - p[0] - 108;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return val;
|
|
|
|
|
|
|
|
Bad:
|
|
|
|
val = 0;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read a real */
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Fixed
|
|
|
|
cff_parse_real( FT_Byte* start,
|
|
|
|
FT_Byte* limit,
|
|
|
|
FT_Int power_ten )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
FT_Byte* p = start;
|
|
|
|
FT_Long num, divider, result, exp;
|
|
|
|
FT_Int sign = 0, exp_sign = 0;
|
2001-06-19 10:28:24 +02:00
|
|
|
FT_UInt nib;
|
|
|
|
FT_UInt phase;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
num = 0;
|
|
|
|
divider = 1;
|
|
|
|
|
|
|
|
/* first of all, read the integer part */
|
|
|
|
phase = 4;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* If we entered this iteration with phase == 4, we need to */
|
|
|
|
/* read a new byte. This also skips past the intial 0x1E. */
|
|
|
|
if ( phase )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Make sure we don't read past the end. */
|
|
|
|
if ( p >= limit )
|
|
|
|
goto Bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the nibble. */
|
|
|
|
nib = ( p[0] >> phase ) & 0xF;
|
|
|
|
phase = 4 - phase;
|
|
|
|
|
|
|
|
if ( nib == 0xE )
|
|
|
|
sign = 1;
|
|
|
|
else if ( nib > 9 )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
result = result * 10 + nib;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read decimal part, if any */
|
|
|
|
if ( nib == 0xa )
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* If we entered this iteration with phase == 4, we need */
|
|
|
|
/* to read a new byte. */
|
|
|
|
if ( phase )
|
2000-12-08 17:17:16 +01:00
|
|
|
{
|
2000-12-08 03:42:29 +01:00
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Make sure we don't read past the end. */
|
|
|
|
if ( p >= limit )
|
|
|
|
goto Bad;
|
2000-12-08 17:17:16 +01:00
|
|
|
}
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
/* Get the nibble. */
|
|
|
|
nib = ( p[0] >> phase ) & 0xF;
|
|
|
|
phase = 4 - phase;
|
|
|
|
if ( nib >= 10 )
|
|
|
|
break;
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
if ( divider < 10000000L )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
num = num * 10 + nib;
|
|
|
|
divider *= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read exponent, if any */
|
|
|
|
if ( nib == 12 )
|
|
|
|
{
|
|
|
|
exp_sign = 1;
|
|
|
|
nib = 11;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nib == 11 )
|
|
|
|
{
|
|
|
|
exp = 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* If we entered this iteration with phase == 4, we need */
|
|
|
|
/* to read a new byte. */
|
|
|
|
if ( phase )
|
2000-12-08 17:17:16 +01:00
|
|
|
{
|
2000-12-08 03:42:29 +01:00
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Make sure we don't read past the end. */
|
|
|
|
if ( p >= limit )
|
|
|
|
goto Bad;
|
2000-12-08 17:17:16 +01:00
|
|
|
}
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
/* Get the nibble. */
|
|
|
|
nib = ( p[0] >> phase ) & 0xF;
|
|
|
|
phase = 4 - phase;
|
|
|
|
if ( nib >= 10 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
exp = exp * 10 + nib;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( exp_sign )
|
|
|
|
exp = -exp;
|
|
|
|
|
|
|
|
power_ten += exp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* raise to power of ten if needed */
|
|
|
|
while ( power_ten > 0 )
|
|
|
|
{
|
|
|
|
result = result * 10;
|
|
|
|
num = num * 10;
|
|
|
|
|
|
|
|
power_ten--;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ( power_ten < 0 )
|
|
|
|
{
|
|
|
|
result = result / 10;
|
|
|
|
divider = divider * 10;
|
|
|
|
|
|
|
|
power_ten++;
|
|
|
|
}
|
|
|
|
|
2001-02-07 02:11:54 +01:00
|
|
|
/* Move the integer part into the high 16 bits. */
|
|
|
|
result <<= 16;
|
|
|
|
|
|
|
|
/* Place the decimal part into the low 16 bits. */
|
2000-12-08 03:42:29 +01:00
|
|
|
if ( num )
|
2001-02-07 02:11:54 +01:00
|
|
|
result |= FT_DivFix( num, divider );
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
if ( sign )
|
|
|
|
result = -result;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return result;
|
|
|
|
|
|
|
|
Bad:
|
|
|
|
result = 0;
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read a number, either integer or real */
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Long
|
|
|
|
cff_parse_num( FT_Byte** d )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
return ( **d == 30 ? ( cff_parse_real ( d[0], d[1], 0 ) >> 16 )
|
|
|
|
: cff_parse_integer( d[0], d[1] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
/* read a floating point number, either integer or real */
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Fixed
|
|
|
|
cff_parse_fixed( FT_Byte** d )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
return ( **d == 30 ? cff_parse_real ( d[0], d[1], 0 )
|
|
|
|
: cff_parse_integer( d[0], d[1] ) << 16 );
|
|
|
|
}
|
|
|
|
|
2001-02-07 02:11:54 +01:00
|
|
|
/* read a floating point number, either integer or real, */
|
|
|
|
/* but return 1000 times the number read in. */
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Fixed
|
|
|
|
cff_parse_fixed_thousand( FT_Byte** d )
|
2001-02-07 02:11:54 +01:00
|
|
|
{
|
2001-02-10 18:45:01 +01:00
|
|
|
return **d ==
|
|
|
|
30 ? cff_parse_real ( d[0], d[1], 3 )
|
|
|
|
: (FT_Fixed)FT_MulFix( cff_parse_integer( d[0], d[1] ) << 16, 1000 );
|
2001-02-07 02:11:54 +01:00
|
|
|
}
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
2002-03-30 17:41:09 +01:00
|
|
|
cff_parse_font_matrix( CFF_Parser parser )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2002-03-14 09:57:10 +01:00
|
|
|
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_Matrix* matrix = &dict->font_matrix;
|
|
|
|
FT_Vector* offset = &dict->font_offset;
|
|
|
|
FT_UShort* upm = &dict->units_per_em;
|
|
|
|
FT_Byte** data = parser->stack;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Fixed temp;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2000-12-30 23:14:58 +01:00
|
|
|
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Stack_Underflow;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
if ( parser->top >= parser->stack + 6 )
|
|
|
|
{
|
2001-02-07 02:11:54 +01:00
|
|
|
matrix->xx = cff_parse_fixed_thousand( data++ );
|
|
|
|
matrix->yx = cff_parse_fixed_thousand( data++ );
|
|
|
|
matrix->xy = cff_parse_fixed_thousand( data++ );
|
|
|
|
matrix->yy = cff_parse_fixed_thousand( data++ );
|
|
|
|
offset->x = cff_parse_fixed_thousand( data++ );
|
|
|
|
offset->y = cff_parse_fixed_thousand( data );
|
2000-12-24 10:57:28 +01:00
|
|
|
|
|
|
|
temp = ABS( matrix->yy );
|
|
|
|
|
2001-05-11 20:08:58 +02:00
|
|
|
*upm = (FT_UShort)FT_DivFix( 0x10000L, FT_DivFix( temp, 1000 ) );
|
2001-02-07 02:11:54 +01:00
|
|
|
|
2000-12-24 10:57:28 +01:00
|
|
|
if ( temp != 0x10000L )
|
|
|
|
{
|
|
|
|
matrix->xx = FT_DivFix( matrix->xx, temp );
|
|
|
|
matrix->yx = FT_DivFix( matrix->yx, temp );
|
|
|
|
matrix->xy = FT_DivFix( matrix->xy, temp );
|
|
|
|
matrix->yy = FT_DivFix( matrix->yy, temp );
|
|
|
|
offset->x = FT_DivFix( offset->x, temp );
|
|
|
|
offset->y = FT_DivFix( offset->y, temp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note that the offsets must be expressed in integer font units */
|
|
|
|
offset->x >>= 16;
|
|
|
|
offset->y >>= 16;
|
|
|
|
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Ok;
|
2000-12-08 03:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
2002-03-30 17:41:09 +01:00
|
|
|
cff_parse_font_bbox( CFF_Parser parser )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2002-03-14 09:57:10 +01:00
|
|
|
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_BBox* bbox = &dict->font_bbox;
|
|
|
|
FT_Byte** data = parser->stack;
|
|
|
|
FT_Error error;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Stack_Underflow;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
if ( parser->top >= parser->stack + 4 )
|
|
|
|
{
|
2001-03-17 20:01:25 +01:00
|
|
|
bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) );
|
|
|
|
bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) );
|
|
|
|
bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) );
|
|
|
|
bbox->yMax = FT_RoundFix( cff_parse_fixed( data ) );
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Ok;
|
2000-12-08 03:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
2002-03-30 17:41:09 +01:00
|
|
|
cff_parse_private_dict( CFF_Parser parser )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2002-03-14 09:57:10 +01:00
|
|
|
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_Byte** data = parser->stack;
|
|
|
|
FT_Error error;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Stack_Underflow;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
if ( parser->top >= parser->stack + 2 )
|
|
|
|
{
|
|
|
|
dict->private_size = cff_parse_num( data++ );
|
|
|
|
dict->private_offset = cff_parse_num( data );
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Ok;
|
2000-12-08 03:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
2002-03-30 17:41:09 +01:00
|
|
|
cff_parse_cid_ros( CFF_Parser parser )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2002-03-14 09:57:10 +01:00
|
|
|
CFF_FontRecDict dict = (CFF_FontRecDict)parser->object;
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_Byte** data = parser->stack;
|
|
|
|
FT_Error error;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Stack_Underflow;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
if ( parser->top >= parser->stack + 3 )
|
|
|
|
{
|
|
|
|
dict->cid_registry = (FT_UInt)cff_parse_num ( data++ );
|
|
|
|
dict->cid_ordering = (FT_UInt)cff_parse_num ( data++ );
|
|
|
|
dict->cid_supplement = (FT_ULong)cff_parse_num( data );
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Ok;
|
2000-12-08 03:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CFF_FIELD_NUM( code, name ) \
|
|
|
|
CFF_FIELD( code, name, cff_kind_num )
|
|
|
|
#define CFF_FIELD_FIXED( code, name ) \
|
|
|
|
CFF_FIELD( code, name, cff_kind_fixed )
|
|
|
|
#define CFF_FIELD_STRING( code, name ) \
|
|
|
|
CFF_FIELD( code, name, cff_kind_string )
|
|
|
|
#define CFF_FIELD_BOOL( code, name ) \
|
|
|
|
CFF_FIELD( code, name, cff_kind_bool )
|
|
|
|
#define CFF_FIELD_DELTA( code, name, max ) \
|
|
|
|
CFF_FIELD( code, name, cff_kind_delta )
|
|
|
|
|
|
|
|
#define CFF_FIELD_CALLBACK( code, name ) \
|
|
|
|
{ \
|
|
|
|
cff_kind_callback, \
|
|
|
|
code | CFFCODE, \
|
|
|
|
0, 0, \
|
|
|
|
cff_parse_ ## name, \
|
|
|
|
0, 0 \
|
|
|
|
},
|
|
|
|
|
|
|
|
#undef CFF_FIELD
|
|
|
|
#define CFF_FIELD( code, name, kind ) \
|
|
|
|
{ \
|
|
|
|
kind, \
|
|
|
|
code | CFFCODE, \
|
|
|
|
FT_FIELD_OFFSET( name ), \
|
|
|
|
FT_FIELD_SIZE( name ), \
|
|
|
|
0, 0, 0 \
|
|
|
|
},
|
|
|
|
|
|
|
|
#undef CFF_FIELD_DELTA
|
|
|
|
#define CFF_FIELD_DELTA( code, name, max ) \
|
|
|
|
{ \
|
|
|
|
cff_kind_delta, \
|
|
|
|
code | CFFCODE, \
|
|
|
|
FT_FIELD_OFFSET( name ), \
|
|
|
|
FT_FIELD_SIZE_DELTA( name ), \
|
|
|
|
0, \
|
|
|
|
max, \
|
|
|
|
FT_FIELD_OFFSET( num_ ## name ) \
|
|
|
|
},
|
|
|
|
|
|
|
|
#define CFFCODE_TOPDICT 0x1000
|
|
|
|
#define CFFCODE_PRIVATE 0x2000
|
|
|
|
|
|
|
|
static const CFF_Field_Handler cff_field_handlers[] =
|
|
|
|
{
|
|
|
|
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "cfftoken.h"
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added
to support charmaps for CFF fonts
* src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
sources, and removing some bugs in the Encoding and Charset loaders
2002-07-10 18:52:06 +02:00
|
|
|
cff_parser_run( CFF_Parser parser,
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_Byte* start,
|
|
|
|
FT_Byte* limit )
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
|
|
|
FT_Byte* p = start;
|
2001-01-03 01:21:59 +01:00
|
|
|
FT_Error error = CFF_Err_Ok;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
parser->top = parser->stack;
|
|
|
|
parser->start = start;
|
|
|
|
parser->limit = limit;
|
|
|
|
parser->cursor = start;
|
|
|
|
|
|
|
|
while ( p < limit )
|
|
|
|
{
|
2001-06-19 10:28:24 +02:00
|
|
|
FT_UInt v = *p;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
if ( v >= 27 && v != 31 )
|
|
|
|
{
|
|
|
|
/* it's a number; we will push its position on the stack */
|
|
|
|
if ( parser->top - parser->stack >= CFF_MAX_STACK_DEPTH )
|
|
|
|
goto Stack_Overflow;
|
|
|
|
|
|
|
|
*parser->top ++ = p;
|
|
|
|
|
|
|
|
/* now, skip it */
|
|
|
|
if ( v == 30 )
|
|
|
|
{
|
|
|
|
/* skip real number */
|
|
|
|
p++;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if ( p >= limit )
|
|
|
|
goto Syntax_Error;
|
|
|
|
v = p[0] >> 4;
|
|
|
|
if ( v == 15 )
|
|
|
|
break;
|
|
|
|
v = p[0] & 0xF;
|
|
|
|
if ( v == 15 )
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( v == 28 )
|
|
|
|
p += 2;
|
|
|
|
else if ( v == 29 )
|
|
|
|
p += 4;
|
|
|
|
else if ( v > 246 )
|
|
|
|
p += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is not a number, hence it's an operator. Compute its code */
|
|
|
|
/* and look for it in our current list. */
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
FT_UInt code;
|
|
|
|
FT_UInt num_args = (FT_UInt)
|
|
|
|
( parser->top - parser->stack );
|
2000-12-08 03:42:29 +01:00
|
|
|
const CFF_Field_Handler* field;
|
|
|
|
|
|
|
|
|
|
|
|
/* first of all, a trivial check */
|
|
|
|
if ( num_args < 1 )
|
|
|
|
goto Stack_Underflow;
|
|
|
|
|
|
|
|
*parser->top = p;
|
|
|
|
code = v;
|
|
|
|
if ( v == 12 )
|
|
|
|
{
|
|
|
|
/* two byte operator */
|
|
|
|
p++;
|
|
|
|
code = 0x100 | p[0];
|
|
|
|
}
|
|
|
|
code = code | parser->object_code;
|
|
|
|
|
|
|
|
for ( field = cff_field_handlers; field->kind; field++ )
|
|
|
|
{
|
|
|
|
if ( field->code == (FT_Int)code )
|
|
|
|
{
|
|
|
|
/* we found our field's handler; read it */
|
|
|
|
FT_Long val;
|
|
|
|
FT_Byte* q = (FT_Byte*)parser->object + field->offset;
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
switch ( field->kind )
|
|
|
|
{
|
|
|
|
case cff_kind_bool:
|
|
|
|
case cff_kind_string:
|
|
|
|
case cff_kind_num:
|
|
|
|
val = cff_parse_num( parser->stack );
|
|
|
|
goto Store_Number;
|
|
|
|
|
|
|
|
case cff_kind_fixed:
|
|
|
|
val = cff_parse_fixed( parser->stack );
|
|
|
|
|
|
|
|
Store_Number:
|
|
|
|
switch ( field->size )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
*(FT_Byte*)q = (FT_Byte)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
*(FT_Short*)q = (FT_Short)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
*(FT_Int32*)q = (FT_Int)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* for 64-bit systems where long is 8 bytes */
|
|
|
|
*(FT_Long*)q = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case cff_kind_delta:
|
|
|
|
{
|
|
|
|
FT_Byte* qcount = (FT_Byte*)parser->object +
|
|
|
|
field->count_offset;
|
|
|
|
|
|
|
|
FT_Byte** data = parser->stack;
|
|
|
|
|
|
|
|
|
|
|
|
if ( num_args > field->array_max )
|
|
|
|
num_args = field->array_max;
|
|
|
|
|
|
|
|
/* store count */
|
|
|
|
*qcount = (FT_Byte)num_args;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
while ( num_args > 0 )
|
|
|
|
{
|
|
|
|
val += cff_parse_num( data++ );
|
|
|
|
switch ( field->size )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
*(FT_Byte*)q = (FT_Byte)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
*(FT_Short*)q = (FT_Short)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
*(FT_Int32*)q = (FT_Int)val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* for 64-bit systems */
|
|
|
|
*(FT_Long*)q = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
q += field->size;
|
|
|
|
num_args--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* callback */
|
|
|
|
error = field->reader( parser );
|
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
goto Found;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is an unknown operator, or it is unsupported; */
|
|
|
|
/* we will ignore it for now. */
|
|
|
|
|
|
|
|
Found:
|
|
|
|
/* clear stack */
|
|
|
|
parser->top = parser->stack;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
|
|
|
|
Stack_Overflow:
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Invalid_Argument;
|
2000-12-08 03:42:29 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Stack_Underflow:
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Invalid_Argument;
|
2000-12-08 03:42:29 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
Syntax_Error:
|
2001-01-03 01:21:59 +01:00
|
|
|
error = CFF_Err_Invalid_Argument;
|
2000-12-08 03:42:29 +01:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|