ReactOS 0.4.16-dev-1067-ge98bba2
cffparse.h File Reference
#include <ft2build.h>
Include dependency graph for cffparse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CFF_ParserRec_
 
struct  CFF_Field_Handler_
 

Macros

#define CFF_MAX_STACK_DEPTH   96
 
#define CFF2_MAX_STACK   513
 
#define CFF2_DEFAULT_STACK   513
 
#define CFF_CODE_TOPDICT   0x1000
 
#define CFF_CODE_PRIVATE   0x2000
 
#define CFF2_CODE_TOPDICT   0x3000
 
#define CFF2_CODE_FONTDICT   0x4000
 
#define CFF2_CODE_PRIVATE   0x5000
 

Typedefs

typedef struct CFF_ParserRec_ CFF_ParserRec
 
typedef struct CFF_ParserRec_CFF_Parser
 
typedef FT_Error(* CFF_Field_Reader) (CFF_Parser parser)
 
typedef struct CFF_Field_Handler_ CFF_Field_Handler
 

Enumerations

enum  {
  cff_kind_none = 0 , cff_kind_num , cff_kind_fixed , cff_kind_fixed_thousand ,
  cff_kind_string , cff_kind_bool , cff_kind_delta , cff_kind_callback ,
  cff_kind_blend , cff_kind_max
}
 

Functions

 cff_parse_num (CFF_Parser parser, FT_Byte **d)
 
 cff_parser_init (CFF_Parser parser, FT_UInt code, void *object, FT_Library library, FT_UInt stackSize, FT_UShort num_designs, FT_UShort num_axes)
 
 cff_parser_done (CFF_Parser parser)
 
 cff_parser_run (CFF_Parser parser, FT_Byte *start, FT_Byte *limit)
 

Macro Definition Documentation

◆ CFF2_CODE_FONTDICT

#define CFF2_CODE_FONTDICT   0x4000

Definition at line 48 of file cffparse.h.

◆ CFF2_CODE_PRIVATE

#define CFF2_CODE_PRIVATE   0x5000

Definition at line 49 of file cffparse.h.

◆ CFF2_CODE_TOPDICT

#define CFF2_CODE_TOPDICT   0x3000

Definition at line 47 of file cffparse.h.

◆ CFF2_DEFAULT_STACK

#define CFF2_DEFAULT_STACK   513

Definition at line 43 of file cffparse.h.

◆ CFF2_MAX_STACK

#define CFF2_MAX_STACK   513

Definition at line 42 of file cffparse.h.

◆ CFF_CODE_PRIVATE

#define CFF_CODE_PRIVATE   0x2000

Definition at line 46 of file cffparse.h.

◆ CFF_CODE_TOPDICT

#define CFF_CODE_TOPDICT   0x1000

Definition at line 45 of file cffparse.h.

◆ CFF_MAX_STACK_DEPTH

#define CFF_MAX_STACK_DEPTH   96

Definition at line 33 of file cffparse.h.

Typedef Documentation

◆ CFF_Field_Handler

◆ CFF_Field_Reader

typedef FT_Error(* CFF_Field_Reader) (CFF_Parser parser)

Definition at line 111 of file cffparse.h.

◆ CFF_Parser

◆ CFF_ParserRec

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
cff_kind_none 
cff_kind_num 
cff_kind_fixed 
cff_kind_fixed_thousand 
cff_kind_string 
cff_kind_bool 
cff_kind_delta 
cff_kind_callback 
cff_kind_blend 
cff_kind_max 

Definition at line 94 of file cffparse.h.

95 {
96 cff_kind_none = 0,
105
106 cff_kind_max /* do not remove */
107 };
@ cff_kind_callback
Definition: cffparse.h:103
@ cff_kind_bool
Definition: cffparse.h:101
@ cff_kind_fixed_thousand
Definition: cffparse.h:99
@ cff_kind_fixed
Definition: cffparse.h:98
@ cff_kind_max
Definition: cffparse.h:106
@ cff_kind_delta
Definition: cffparse.h:102
@ cff_kind_blend
Definition: cffparse.h:104
@ cff_kind_none
Definition: cffparse.h:96
@ cff_kind_string
Definition: cffparse.h:100
@ cff_kind_num
Definition: cffparse.h:97

Function Documentation

◆ cff_parse_num()

cff_parse_num ( CFF_Parser  parser,
FT_Byte **  d 
)

Definition at line 454 of file cffparse.c.

456 {
457 if ( **d == 30 )
458 {
459 /* binary-coded decimal is truncated to integer */
460 return cff_parse_real( *d, parser->limit, 0, NULL ) >> 16;
461 }
462
463 else if ( **d == 255 )
464 {
465 /* 16.16 fixed point is used internally for CFF2 blend results. */
466 /* Since these are trusted values, a limit check is not needed. */
467
468 /* After the 255, 4 bytes give the number. */
469 /* The blend value is converted to integer, with rounding; */
470 /* due to the right-shift we don't need the lowest byte. */
471#if 0
472 return (FT_Short)(
473 ( ( ( (FT_UInt32)*( d[0] + 1 ) << 24 ) |
474 ( (FT_UInt32)*( d[0] + 2 ) << 16 ) |
475 ( (FT_UInt32)*( d[0] + 3 ) << 8 ) |
476 (FT_UInt32)*( d[0] + 4 ) ) + 0x8000U ) >> 16 );
477#else
478 return (FT_Short)(
479 ( ( ( (FT_UInt32)*( d[0] + 1 ) << 16 ) |
480 ( (FT_UInt32)*( d[0] + 2 ) << 8 ) |
481 (FT_UInt32)*( d[0] + 3 ) ) + 0x80U ) >> 8 );
482#endif
483 }
484
485 else
486 return cff_parse_integer( *d, parser->limit );
487 }
static FT_Long cff_parse_integer(FT_Byte *start, FT_Byte *limit)
Definition: cffparse.c:92
static FT_Fixed cff_parse_real(FT_Byte *start, FT_Byte *limit, FT_Long power_ten, FT_Long *scaling)
Definition: cffparse.c:179
#define NULL
Definition: types.h:112
signed short FT_Short
Definition: fttypes.h:198
#define d
Definition: ke_i.h:81
Definition: import.c:81

Referenced by cff_blend_doBlend(), cff_parse_blend(), cff_parse_cid_ros(), cff_parse_maxstack(), cff_parse_multiple_master(), cff_parse_private_dict(), cff_parse_vsindex(), and cff_parser_run().

◆ cff_parser_done()

cff_parser_done ( CFF_Parser  parser)

Definition at line 81 of file cffparse.c.

82 {
83 FT_Memory memory = parser->library->memory; /* for FT_FREE */
84
85
87 }
#define FT_FREE(ptr)
Definition: ftmemory.h:328
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:65
static char memory[1024 *256]
Definition: process.c:116
enum parser_state stack[4]
Definition: inffile.c:91

Referenced by cff_load_private_dict(), and cff_subfont_load().

◆ cff_parser_init()

cff_parser_init ( CFF_Parser  parser,
FT_UInt  code,
void object,
FT_Library  library,
FT_UInt  stackSize,
FT_UShort  num_designs,
FT_UShort  num_axes 
)

Definition at line 42 of file cffparse.c.

49 {
50 FT_Memory memory = library->memory; /* for FT_NEW_ARRAY */
51 FT_Error error; /* for FT_NEW_ARRAY */
52
53
54 FT_ZERO( parser );
55
56#if 0
57 parser->top = parser->stack;
58#endif
59 parser->object_code = code;
60 parser->object = object;
61 parser->library = library;
62 parser->num_designs = num_designs;
63 parser->num_axes = num_axes;
64
65 /* allocate the stack buffer */
66 if ( FT_NEW_ARRAY( parser->stack, stackSize ) )
67 {
69 goto Exit;
70 }
71
72 parser->stackSize = stackSize;
73 parser->top = parser->stack; /* empty stack */
74
75 Exit:
76 return error;
77 }
FT_Library library
Definition: cffdrivr.c:661
#define FT_NEW_ARRAY(ptr, count)
Definition: ftmemory.h:332
#define FT_ZERO(p)
Definition: ftmemory.h:237
int FT_Error
Definition: fttypes.h:299
#define error(str)
Definition: mkdosfs.c:1605
static void Exit(void)
Definition: sock.c:1330
FT_Memory memory
Definition: ftobjs.h:897
Definition: inflate.c:139

Referenced by cff_load_private_dict(), and cff_subfont_load().

◆ cff_parser_run()

cff_parser_run ( CFF_Parser  parser,
FT_Byte start,
FT_Byte limit 
)

Definition at line 1138 of file cffparse.c.

1141 {
1142 FT_Byte* p = start;
1144
1145#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1146 PSAux_Service psaux;
1147
1148 FT_Library library = parser->library;
1150
1151 FT_ListRec t2s;
1152
1153
1154 FT_ZERO( &t2s );
1155#endif
1156
1157 parser->top = parser->stack;
1158 parser->start = start;
1159 parser->limit = limit;
1160 parser->cursor = start;
1161
1162 while ( p < limit )
1163 {
1164 FT_UInt v = *p;
1165
1166
1167 /* Opcode 31 is legacy MM T2 operator, not a number. */
1168 /* Opcode 255 is reserved and should not appear in fonts; */
1169 /* it is used internally for CFF2 blends. */
1170 if ( v >= 27 && v != 31 && v != 255 )
1171 {
1172 /* it's a number; we will push its position on the stack */
1173 if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
1174 goto Stack_Overflow;
1175
1176 *parser->top++ = p;
1177
1178 /* now, skip it */
1179 if ( v == 30 )
1180 {
1181 /* skip real number */
1182 p++;
1183 for (;;)
1184 {
1185 /* An unterminated floating point number at the */
1186 /* end of a dictionary is invalid but harmless. */
1187 if ( p >= limit )
1188 goto Exit;
1189 v = p[0] >> 4;
1190 if ( v == 15 )
1191 break;
1192 v = p[0] & 0xF;
1193 if ( v == 15 )
1194 break;
1195 p++;
1196 }
1197 }
1198 else if ( v == 28 )
1199 p += 2;
1200 else if ( v == 29 )
1201 p += 4;
1202 else if ( v > 246 )
1203 p += 1;
1204 }
1205#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1206 else if ( v == 31 )
1207 {
1208 /* a Type 2 charstring */
1209
1211 CFF_FontRec cff_rec;
1212 FT_Byte* charstring_base;
1213 FT_ULong charstring_len;
1214
1215 FT_Fixed* stack;
1217 FT_Byte* q;
1218
1219
1220 charstring_base = ++p;
1221
1222 /* search `endchar' operator */
1223 for (;;)
1224 {
1225 if ( p >= limit )
1226 goto Exit;
1227 if ( *p == 14 )
1228 break;
1229 p++;
1230 }
1231
1232 charstring_len = (FT_ULong)( p - charstring_base ) + 1;
1233
1234 /* construct CFF_Decoder object */
1235 FT_ZERO( &decoder );
1236 FT_ZERO( &cff_rec );
1237
1238 cff_rec.top_font.font_dict.num_designs = parser->num_designs;
1239 cff_rec.top_font.font_dict.num_axes = parser->num_axes;
1240 decoder.cff = &cff_rec;
1241
1242 psaux = (PSAux_Service)FT_Get_Module_Interface( library, "psaux" );
1243 if ( !psaux )
1244 {
1245 FT_ERROR(( "cff_parser_run: cannot access `psaux' module\n" ));
1246 error = FT_THROW( Missing_Module );
1247 goto Exit;
1248 }
1249
1250 error = psaux->cff_decoder_funcs->parse_charstrings_old(
1251 &decoder, charstring_base, charstring_len, 1 );
1252 if ( error )
1253 goto Exit;
1254
1255 /* Now copy the stack data in the temporary decoder object, */
1256 /* converting it back to charstring number representations */
1257 /* (this is ugly, I know). */
1258
1259 node = (FT_ListNode)memory->alloc( memory,
1260 sizeof ( FT_ListNodeRec ) );
1261 if ( !node )
1262 goto Out_Of_Memory_Error;
1263
1264 /* `5' is the conservative upper bound of required bytes per stack */
1265 /* element. */
1266 q = (FT_Byte*)memory->alloc( memory,
1267 5 * ( decoder.top - decoder.stack ) );
1268 if ( !q )
1269 goto Out_Of_Memory_Error;
1270
1271 node->data = q;
1272
1273 FT_List_Add( &t2s, node );
1274
1275 stack = decoder.stack;
1276
1277 while ( stack < decoder.top )
1278 {
1279 FT_ULong num;
1280 FT_Bool neg;
1281
1282
1283 if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
1284 goto Stack_Overflow;
1285
1286 *parser->top++ = q;
1287
1288 if ( *stack < 0 )
1289 {
1290 num = (FT_ULong)NEG_LONG( *stack );
1291 neg = 1;
1292 }
1293 else
1294 {
1295 num = (FT_ULong)*stack;
1296 neg = 0;
1297 }
1298
1299 if ( num & 0xFFFFU )
1300 {
1301 if ( neg )
1302 num = (FT_ULong)-num;
1303
1304 *q++ = 255;
1305 *q++ = ( num & 0xFF000000U ) >> 24;
1306 *q++ = ( num & 0x00FF0000U ) >> 16;
1307 *q++ = ( num & 0x0000FF00U ) >> 8;
1308 *q++ = num & 0x000000FFU;
1309 }
1310 else
1311 {
1312 num >>= 16;
1313
1314 if ( neg )
1315 {
1316 if ( num <= 107 )
1317 *q++ = (FT_Byte)( 139 - num );
1318 else if ( num <= 1131 )
1319 {
1320 *q++ = (FT_Byte)( ( ( num - 108 ) >> 8 ) + 251 );
1321 *q++ = (FT_Byte)( ( num - 108 ) & 0xFF );
1322 }
1323 else
1324 {
1325 num = (FT_ULong)-num;
1326
1327 *q++ = 28;
1328 *q++ = (FT_Byte)( num >> 8 );
1329 *q++ = (FT_Byte)( num & 0xFF );
1330 }
1331 }
1332 else
1333 {
1334 if ( num <= 107 )
1335 *q++ = (FT_Byte)( num + 139 );
1336 else if ( num <= 1131 )
1337 {
1338 *q++ = (FT_Byte)( ( ( num - 108 ) >> 8 ) + 247 );
1339 *q++ = (FT_Byte)( ( num - 108 ) & 0xFF );
1340 }
1341 else
1342 {
1343 *q++ = 28;
1344 *q++ = (FT_Byte)( num >> 8 );
1345 *q++ = (FT_Byte)( num & 0xFF );
1346 }
1347 }
1348 }
1349
1350 stack++;
1351 }
1352 }
1353#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
1354 else
1355 {
1356 /* This is not a number, hence it's an operator. Compute its code */
1357 /* and look for it in our current list. */
1358
1359 FT_UInt code;
1360 FT_UInt num_args;
1361 const CFF_Field_Handler* field;
1362
1363
1364 if ( (FT_UInt)( parser->top - parser->stack ) >= parser->stackSize )
1365 goto Stack_Overflow;
1366
1367 num_args = (FT_UInt)( parser->top - parser->stack );
1368 *parser->top = p;
1369 code = v;
1370
1371 if ( v == 12 )
1372 {
1373 /* two byte operator */
1374 p++;
1375 if ( p >= limit )
1376 goto Syntax_Error;
1377
1378 code = 0x100 | p[0];
1379 }
1380 code = code | parser->object_code;
1381
1382 for ( field = cff_field_handlers; field->kind; field++ )
1383 {
1384 if ( field->code == (FT_Int)code )
1385 {
1386 /* we found our field's handler; read it */
1387 FT_Long val;
1388 FT_Byte* q = (FT_Byte*)parser->object + field->offset;
1389
1390
1391#ifdef FT_DEBUG_LEVEL_TRACE
1392 FT_TRACE4(( " %s", field->id ));
1393#endif
1394
1395 /* check that we have enough arguments -- except for */
1396 /* delta encoded arrays, which can be empty */
1397 if ( field->kind != cff_kind_delta && num_args < 1 )
1398 goto Stack_Underflow;
1399
1400 switch ( field->kind )
1401 {
1402 case cff_kind_bool:
1403 case cff_kind_string:
1404 case cff_kind_num:
1406 goto Store_Number;
1407
1408 case cff_kind_fixed:
1410 goto Store_Number;
1411
1414
1415 Store_Number:
1416 switch ( field->size )
1417 {
1418 case (8 / FT_CHAR_BIT):
1419 *(FT_Byte*)q = (FT_Byte)val;
1420 break;
1421
1422 case (16 / FT_CHAR_BIT):
1423 *(FT_Short*)q = (FT_Short)val;
1424 break;
1425
1426 case (32 / FT_CHAR_BIT):
1427 *(FT_Int32*)q = (FT_Int)val;
1428 break;
1429
1430 default: /* for 64-bit systems */
1431 *(FT_Long*)q = val;
1432 }
1433
1434#ifdef FT_DEBUG_LEVEL_TRACE
1435 switch ( field->kind )
1436 {
1437 case cff_kind_bool:
1438 FT_TRACE4(( " %s\n", val ? "true" : "false" ));
1439 break;
1440
1441 case cff_kind_string:
1442 FT_TRACE4(( " %ld (SID)\n", val ));
1443 break;
1444
1445 case cff_kind_num:
1446 FT_TRACE4(( " %ld\n", val ));
1447 break;
1448
1449 case cff_kind_fixed:
1450 FT_TRACE4(( " %f\n", (double)val / 65536 ));
1451 break;
1452
1454 FT_TRACE4(( " %f\n", (double)val / 65536 / 1000 ));
1455
1456 default:
1457 ; /* never reached */
1458 }
1459#endif
1460
1461 break;
1462
1463 case cff_kind_delta:
1464 {
1465 FT_Byte* qcount = (FT_Byte*)parser->object +
1466 field->count_offset;
1467
1468 FT_Byte** data = parser->stack;
1469
1470
1471 if ( num_args > field->array_max )
1472 num_args = field->array_max;
1473
1474 FT_TRACE4(( " [" ));
1475
1476 /* store count */
1477 *qcount = (FT_Byte)num_args;
1478
1479 val = 0;
1480 while ( num_args > 0 )
1481 {
1483 switch ( field->size )
1484 {
1485 case (8 / FT_CHAR_BIT):
1486 *(FT_Byte*)q = (FT_Byte)val;
1487 break;
1488
1489 case (16 / FT_CHAR_BIT):
1490 *(FT_Short*)q = (FT_Short)val;
1491 break;
1492
1493 case (32 / FT_CHAR_BIT):
1494 *(FT_Int32*)q = (FT_Int)val;
1495 break;
1496
1497 default: /* for 64-bit systems */
1498 *(FT_Long*)q = val;
1499 }
1500
1501 FT_TRACE4(( " %ld", val ));
1502
1503 q += field->size;
1504 num_args--;
1505 }
1506
1507 FT_TRACE4(( "]\n" ));
1508 }
1509 break;
1510
1511 default: /* callback or blend */
1512 error = field->reader( parser );
1513 if ( error )
1514 goto Exit;
1515 }
1516 goto Found;
1517 }
1518 }
1519
1520 /* this is an unknown operator, or it is unsupported; */
1521 /* we will ignore it for now. */
1522
1523 Found:
1524 /* clear stack */
1525 /* TODO: could clear blend stack here, */
1526 /* but we don't have access to subFont */
1527 if ( field->kind != cff_kind_blend )
1528 parser->top = parser->stack;
1529 }
1530 p++;
1531 } /* while ( p < limit ) */
1532
1533 Exit:
1534#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1535 FT_List_Finalize( &t2s, destruct_t2s_item, memory, NULL );
1536#endif
1537 return error;
1538
1539#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
1540 Out_Of_Memory_Error:
1541 error = FT_THROW( Out_Of_Memory );
1542 goto Exit;
1543#endif
1544
1545 Stack_Overflow:
1546 error = FT_THROW( Invalid_Argument );
1547 goto Exit;
1548
1549 Stack_Underflow:
1550 error = FT_THROW( Invalid_Argument );
1551 goto Exit;
1552
1553 Syntax_Error:
1554 error = FT_THROW( Invalid_Argument );
1555 goto Exit;
1556 }
return Found
Definition: dirsup.c:1270
static FT_Fixed cff_parse_fixed(CFF_Parser parser, FT_Byte **d)
Definition: cffparse.c:536
cff_parse_num(CFF_Parser parser, FT_Byte **d)
Definition: cffparse.c:454
static FT_Fixed cff_parse_fixed_scaled(CFF_Parser parser, FT_Byte **d, FT_Long scaling)
Definition: cffparse.c:546
static const CFF_Field_Handler cff_field_handlers[]
Definition: cffparse.c:1058
return FT_Err_Ok
Definition: ftbbox.c:527
#define NEG_LONG(a)
Definition: ftcalc.h:479
#define ADD_LONG(a, b)
Definition: ftcalc.h:473
#define FT_CHAR_BIT
Definition: ftconfig.h:69
#define FT_ERROR(varformat)
Definition: ftdebug.h:209
#define FT_THROW(e)
Definition: ftdebug.h:241
#define FT_TRACE4(varformat)
Definition: ftdebug.h:189
FT_List_Finalize(FT_List list, FT_List_Destructor destroy, FT_Memory memory, void *user)
Definition: ftutil.c:413
FT_List_Add(FT_List list, FT_ListNode node)
Definition: ftutil.c:269
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
Definition: ftobjs.c:4992
struct FT_ListNodeRec_ * FT_ListNode
Definition: fttypes.h:523
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
signed long FT_Fixed
Definition: fttypes.h:287
signed long FT_Long
Definition: fttypes.h:242
unsigned int FT_UInt
Definition: fttypes.h:231
signed int FT_Int
Definition: fttypes.h:220
GLuint start
Definition: gl.h:1545
const GLdouble * v
Definition: gl.h:2040
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLint limit
Definition: glext.h:10326
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat GLfloat p
Definition: glext.h:8902
GLuint GLuint num
Definition: glext.h:9618
if(dx< 0)
Definition: linetemp.h:194
struct PSAux_ServiceRec_ * PSAux_Service
FT_UShort num_designs
Definition: cfftypes.h:231
FT_UShort num_axes
Definition: cfftypes.h:232
CFF_SubFontRec top_font
Definition: cfftypes.h:378
CFF_FontRecDictRec font_dict
Definition: cfftypes.h:305
const CFF_Decoder_FuncsRec * cff_decoder_funcs
Definition: psaux.h:1376
Definition: parser.c:44
const CHAR * start
Definition: inffile.c:87
Definition: format.c:80
Definition: dlist.c:348
GLvoid * data
Definition: dlist.c:359
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by cff_load_private_dict(), and cff_subfont_load().