OLD | NEW |
1 /***************************************************************************/ | 1 /***************************************************************************/ |
2 /* */ | 2 /* */ |
3 /* cffload.c */ | 3 /* cffload.c */ |
4 /* */ | 4 /* */ |
5 /* OpenType and CFF data/program tables loader (body). */ | 5 /* OpenType and CFF data/program tables loader (body). */ |
6 /* */ | 6 /* */ |
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ | 7 /* Copyright 1996-2011 by */ |
8 /* 2010 by */ | |
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
10 /* */ | 9 /* */ |
11 /* This file is part of the FreeType project, and may only be used, */ | 10 /* This file is part of the FreeType project, and may only be used, */ |
12 /* modified, and distributed under the terms of the FreeType project */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
14 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
15 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
16 /* */ | 15 /* */ |
17 /***************************************************************************/ | 16 /***************************************************************************/ |
18 | 17 |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 FT_UInt sid = encoding->sids[j]; | 1261 FT_UInt sid = encoding->sids[j]; |
1263 FT_UInt gid = 0; | 1262 FT_UInt gid = 0; |
1264 | 1263 |
1265 | 1264 |
1266 if ( sid ) | 1265 if ( sid ) |
1267 gid = cff_charset_cid_to_gindex( charset, sid ); | 1266 gid = cff_charset_cid_to_gindex( charset, sid ); |
1268 | 1267 |
1269 if ( gid != 0 ) | 1268 if ( gid != 0 ) |
1270 { | 1269 { |
1271 encoding->codes[j] = (FT_UShort)gid; | 1270 encoding->codes[j] = (FT_UShort)gid; |
1272 encoding->count = j + 1; | 1271 encoding->count = j + 1; |
1273 } | 1272 } |
1274 else | 1273 else |
1275 { | 1274 { |
1276 encoding->codes[j] = 0; | 1275 encoding->codes[j] = 0; |
1277 encoding->sids [j] = 0; | 1276 encoding->sids [j] = 0; |
1278 } | 1277 } |
1279 } | 1278 } |
1280 break; | 1279 break; |
1281 | 1280 |
1282 default: | 1281 default: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 top->family_name = 0xFFFFU; | 1329 top->family_name = 0xFFFFU; |
1331 top->weight = 0xFFFFU; | 1330 top->weight = 0xFFFFU; |
1332 top->embedded_postscript = 0xFFFFU; | 1331 top->embedded_postscript = 0xFFFFU; |
1333 | 1332 |
1334 top->cid_registry = 0xFFFFU; | 1333 top->cid_registry = 0xFFFFU; |
1335 top->cid_ordering = 0xFFFFU; | 1334 top->cid_ordering = 0xFFFFU; |
1336 top->cid_font_name = 0xFFFFU; | 1335 top->cid_font_name = 0xFFFFU; |
1337 | 1336 |
1338 error = cff_index_access_element( idx, font_index, &dict, &dict_len ); | 1337 error = cff_index_access_element( idx, font_index, &dict, &dict_len ); |
1339 if ( !error ) | 1338 if ( !error ) |
| 1339 { |
| 1340 FT_TRACE4(( " top dictionary:\n" )); |
1340 error = cff_parser_run( &parser, dict, dict + dict_len ); | 1341 error = cff_parser_run( &parser, dict, dict + dict_len ); |
| 1342 } |
1341 | 1343 |
1342 cff_index_forget_element( idx, &dict ); | 1344 cff_index_forget_element( idx, &dict ); |
1343 | 1345 |
1344 if ( error ) | 1346 if ( error ) |
1345 goto Exit; | 1347 goto Exit; |
1346 | 1348 |
1347 /* if it is a CID font, we stop there */ | 1349 /* if it is a CID font, we stop there */ |
1348 if ( top->cid_registry != 0xFFFFU ) | 1350 if ( top->cid_registry != 0xFFFFU ) |
1349 goto Exit; | 1351 goto Exit; |
1350 | 1352 |
1351 /* parse the private dictionary, if any */ | 1353 /* parse the private dictionary, if any */ |
1352 if ( top->private_offset && top->private_size ) | 1354 if ( top->private_offset && top->private_size ) |
1353 { | 1355 { |
1354 /* set defaults */ | 1356 /* set defaults */ |
1355 FT_MEM_ZERO( priv, sizeof ( *priv ) ); | 1357 FT_MEM_ZERO( priv, sizeof ( *priv ) ); |
1356 | 1358 |
1357 priv->blue_shift = 7; | 1359 priv->blue_shift = 7; |
1358 priv->blue_fuzz = 1; | 1360 priv->blue_fuzz = 1; |
1359 priv->lenIV = -1; | 1361 priv->lenIV = -1; |
1360 priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); | 1362 priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); |
1361 priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); | 1363 priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); |
1362 | 1364 |
1363 cff_parser_init( &parser, CFF_CODE_PRIVATE, priv, library ); | 1365 cff_parser_init( &parser, CFF_CODE_PRIVATE, priv, library ); |
1364 | 1366 |
1365 if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) || | 1367 if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) || |
1366 FT_FRAME_ENTER( font->font_dict.private_size ) ) | 1368 FT_FRAME_ENTER( font->font_dict.private_size ) ) |
1367 goto Exit; | 1369 goto Exit; |
1368 | 1370 |
| 1371 FT_TRACE4(( " private dictionary:\n" )); |
1369 error = cff_parser_run( &parser, | 1372 error = cff_parser_run( &parser, |
1370 (FT_Byte*)stream->cursor, | 1373 (FT_Byte*)stream->cursor, |
1371 (FT_Byte*)stream->limit ); | 1374 (FT_Byte*)stream->limit ); |
1372 FT_FRAME_EXIT(); | 1375 FT_FRAME_EXIT(); |
1373 if ( error ) | 1376 if ( error ) |
1374 goto Exit; | 1377 goto Exit; |
1375 | 1378 |
1376 /* ensure that `num_blue_values' is even */ | 1379 /* ensure that `num_blue_values' is even */ |
1377 priv->num_blue_values &= ~1; | 1380 priv->num_blue_values &= ~1; |
1378 } | 1381 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 | 1451 |
1449 /* read CFF font header */ | 1452 /* read CFF font header */ |
1450 if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) | 1453 if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) ) |
1451 goto Exit; | 1454 goto Exit; |
1452 | 1455 |
1453 /* check format */ | 1456 /* check format */ |
1454 if ( font->version_major != 1 || | 1457 if ( font->version_major != 1 || |
1455 font->header_size < 4 || | 1458 font->header_size < 4 || |
1456 font->absolute_offsize > 4 ) | 1459 font->absolute_offsize > 4 ) |
1457 { | 1460 { |
1458 FT_TRACE2(( "[not a CFF font header]\n" )); | 1461 FT_TRACE2(( " not a CFF font header\n" )); |
1459 error = CFF_Err_Unknown_File_Format; | 1462 error = CFF_Err_Unknown_File_Format; |
1460 goto Exit; | 1463 goto Exit; |
1461 } | 1464 } |
1462 | 1465 |
1463 /* skip the rest of the header */ | 1466 /* skip the rest of the header */ |
1464 if ( FT_STREAM_SKIP( font->header_size - 4 ) ) | 1467 if ( FT_STREAM_SKIP( font->header_size - 4 ) ) |
1465 goto Exit; | 1468 goto Exit; |
1466 | 1469 |
1467 /* read the name, top dict, string and global subrs index */ | 1470 /* read the name, top dict, string and global subrs index */ |
1468 if ( FT_SET_ERROR( cff_index_init( &font->name_index, | 1471 if ( FT_SET_ERROR( cff_index_init( &font->name_index, |
(...skipping 18 matching lines...) Expand all Loading... |
1487 FT_ERROR(( "cff_font_load: incorrect face index = %d\n", | 1490 FT_ERROR(( "cff_font_load: incorrect face index = %d\n", |
1488 face_index )); | 1491 face_index )); |
1489 error = CFF_Err_Invalid_Argument; | 1492 error = CFF_Err_Invalid_Argument; |
1490 } | 1493 } |
1491 | 1494 |
1492 /* in case of a font format check, simply exit now */ | 1495 /* in case of a font format check, simply exit now */ |
1493 if ( face_index < 0 ) | 1496 if ( face_index < 0 ) |
1494 goto Exit; | 1497 goto Exit; |
1495 | 1498 |
1496 /* now, parse the top-level font dictionary */ | 1499 /* now, parse the top-level font dictionary */ |
| 1500 FT_TRACE4(( "parsing top-level\n" )); |
1497 error = cff_subfont_load( &font->top_font, | 1501 error = cff_subfont_load( &font->top_font, |
1498 &font->font_dict_index, | 1502 &font->font_dict_index, |
1499 face_index, | 1503 face_index, |
1500 stream, | 1504 stream, |
1501 base_offset, | 1505 base_offset, |
1502 library ); | 1506 library ); |
1503 if ( error ) | 1507 if ( error ) |
1504 goto Exit; | 1508 goto Exit; |
1505 | 1509 |
1506 if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) | 1510 if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) ) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 goto Fail_CID; | 1543 goto Fail_CID; |
1540 | 1544 |
1541 /* set up pointer table */ | 1545 /* set up pointer table */ |
1542 for ( idx = 0; idx < fd_index.count; idx++ ) | 1546 for ( idx = 0; idx < fd_index.count; idx++ ) |
1543 font->subfonts[idx] = sub + idx; | 1547 font->subfonts[idx] = sub + idx; |
1544 | 1548 |
1545 /* now load each subfont independently */ | 1549 /* now load each subfont independently */ |
1546 for ( idx = 0; idx < fd_index.count; idx++ ) | 1550 for ( idx = 0; idx < fd_index.count; idx++ ) |
1547 { | 1551 { |
1548 sub = font->subfonts[idx]; | 1552 sub = font->subfonts[idx]; |
| 1553 FT_TRACE4(( "parsing subfont %u\n", idx )); |
1549 error = cff_subfont_load( sub, &fd_index, idx, | 1554 error = cff_subfont_load( sub, &fd_index, idx, |
1550 stream, base_offset, library ); | 1555 stream, base_offset, library ); |
1551 if ( error ) | 1556 if ( error ) |
1552 goto Fail_CID; | 1557 goto Fail_CID; |
1553 } | 1558 } |
1554 | 1559 |
1555 /* now load the FD Select array */ | 1560 /* now load the FD Select array */ |
1556 error = CFF_Load_FD_Select( &font->fd_select, | 1561 error = CFF_Load_FD_Select( &font->fd_select, |
1557 font->charstrings_index.count, | 1562 font->charstrings_index.count, |
1558 stream, | 1563 stream, |
1559 base_offset + dict->cid_fd_select_offset ); | 1564 base_offset + dict->cid_fd_select_offset ); |
1560 | 1565 |
1561 Fail_CID: | 1566 Fail_CID: |
1562 cff_index_done( &fd_index ); | 1567 cff_index_done( &fd_index ); |
1563 | 1568 |
1564 if ( error ) | 1569 if ( error ) |
1565 goto Exit; | 1570 goto Exit; |
1566 } | 1571 } |
1567 else | 1572 else |
1568 font->num_subfonts = 0; | 1573 font->num_subfonts = 0; |
1569 | 1574 |
1570 /* read the charstrings index now */ | 1575 /* read the charstrings index now */ |
1571 if ( dict->charstrings_offset == 0 ) | 1576 if ( dict->charstrings_offset == 0 ) |
1572 { | 1577 { |
1573 FT_ERROR(( "cff_font_load: no charstrings offset\n" )); | 1578 FT_ERROR(( "cff_font_load: no charstrings offset\n" )); |
1574 error = CFF_Err_Unknown_File_Format; | 1579 error = CFF_Err_Invalid_File_Format; |
1575 goto Exit; | 1580 goto Exit; |
1576 } | 1581 } |
1577 | 1582 |
1578 font->num_glyphs = font->charstrings_index.count; | 1583 font->num_glyphs = font->charstrings_index.count; |
1579 | 1584 |
1580 error = cff_index_get_pointers( &font->global_subrs_index, | 1585 error = cff_index_get_pointers( &font->global_subrs_index, |
1581 &font->global_subrs, NULL ); | 1586 &font->global_subrs, NULL ); |
1582 | 1587 |
1583 if ( error ) | 1588 if ( error ) |
1584 goto Exit; | 1589 goto Exit; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 FT_FREE( font->font_info ); | 1657 FT_FREE( font->font_info ); |
1653 | 1658 |
1654 FT_FREE( font->font_name ); | 1659 FT_FREE( font->font_name ); |
1655 FT_FREE( font->global_subrs ); | 1660 FT_FREE( font->global_subrs ); |
1656 FT_FREE( font->strings ); | 1661 FT_FREE( font->strings ); |
1657 FT_FREE( font->string_pool ); | 1662 FT_FREE( font->string_pool ); |
1658 } | 1663 } |
1659 | 1664 |
1660 | 1665 |
1661 /* END */ | 1666 /* END */ |
OLD | NEW |