1 /***************************************************************************/
5 /* OpenType and CFF data/program tables loader (body). */
7 /* Copyright 1996-2001, 2002 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_OBJECTS_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
24 #include FT_TRUETYPE_TAGS_H
33 static const FT_UShort cff_isoadobe_charset[229] =
266 static const FT_UShort cff_expert_charset[166] =
436 static const FT_UShort cff_expertsubset_charset[87] =
527 static const FT_UShort cff_standard_encoding[256] =
787 static const FT_UShort cff_expert_encoding[256] =
1049 FT_LOCAL_DEF( FT_UShort )
1050 cff_get_standard_encoding( FT_UInt charcode )
1052 return (FT_UShort)(charcode < 256 ? cff_standard_encoding[charcode] : 0);
1056 /*************************************************************************/
1058 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
1059 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
1060 /* messages during execution. */
1063 #define FT_COMPONENT trace_cffload
1066 /* read a CFF offset from memory */
1068 cff_get_offset( FT_Byte* p,
1074 for ( result = 0; off_size > 0; off_size-- )
1085 cff_new_index( CFF_Index idx,
1090 FT_Memory memory = stream->memory;
1094 FT_MEM_ZERO( idx, sizeof ( *idx ) );
1096 idx->stream = stream;
1097 if ( !FT_READ_USHORT( count ) &&
1106 /* there is at least one element; read the offset size, */
1107 /* then access the offset table to compute the index's total size */
1108 if ( FT_READ_BYTE( offsize ) )
1111 idx->stream = stream;
1113 idx->off_size = offsize;
1114 data_size = (FT_ULong)( count + 1 ) * offsize;
1116 if ( FT_NEW_ARRAY( idx->offsets, count + 1 ) ||
1117 FT_FRAME_ENTER( data_size ) )
1120 poff = idx->offsets;
1121 p = (FT_Byte*)stream->cursor;
1123 for ( ; (FT_Short)count >= 0; count-- )
1125 poff[0] = cff_get_offset( p, offsize );
1132 idx->data_offset = FT_STREAM_POS();
1133 data_size = poff[-1] - 1;
1138 if ( FT_FRAME_EXTRACT( data_size, idx->bytes ) )
1144 if ( FT_STREAM_SKIP( data_size ) )
1151 FT_FREE( idx->offsets );
1158 cff_done_index( CFF_Index idx )
1162 FT_Stream stream = idx->stream;
1163 FT_Memory memory = stream->memory;
1167 FT_FRAME_RELEASE( idx->bytes );
1169 FT_FREE( idx->offsets );
1170 FT_MEM_ZERO( idx, sizeof ( *idx ) );
1175 /* allocate a table containing pointers to an index's elements */
1177 cff_index_get_pointers( CFF_Index idx,
1181 FT_Memory memory = idx->stream->memory;
1182 FT_ULong n, offset, old_offset;
1188 if ( idx->count > 0 && !FT_NEW_ARRAY( t, idx->count + 1 ) )
1191 for ( n = 0; n <= idx->count; n++ )
1193 offset = idx->offsets[n];
1195 offset = old_offset;
1197 t[n] = idx->bytes + offset - 1;
1199 old_offset = offset;
1208 FT_LOCAL_DEF( FT_Error )
1209 cff_index_access_element( CFF_Index idx,
1212 FT_ULong* pbyte_len )
1217 if ( idx && idx->count > element )
1219 /* compute start and end offsets */
1220 FT_ULong off1, off2 = 0;
1223 off1 = idx->offsets[element];
1229 off2 = idx->offsets[element];
1231 } while ( off2 == 0 && element < idx->count );
1237 /* access element */
1240 *pbyte_len = off2 - off1;
1244 /* this index was completely loaded in memory, that's easy */
1245 *pbytes = idx->bytes + off1 - 1;
1249 /* this index is still on disk/file, access it through a frame */
1250 FT_Stream stream = idx->stream;
1253 if ( FT_STREAM_SEEK( idx->data_offset + off1 - 1 ) ||
1254 FT_FRAME_EXTRACT( off2 - off1, *pbytes ) )
1260 /* empty index element */
1266 error = CFF_Err_Invalid_Argument;
1273 FT_LOCAL_DEF( void )
1274 cff_index_forget_element( CFF_Index idx,
1277 if ( idx->bytes == 0 )
1279 FT_Stream stream = idx->stream;
1282 FT_FRAME_RELEASE( *pbytes );
1287 FT_LOCAL_DEF( FT_String* )
1288 cff_index_get_name( CFF_Index idx,
1291 FT_Memory memory = idx->stream->memory;
1295 FT_String* name = 0;
1298 error = cff_index_access_element( idx, element, &bytes, &byte_len );
1302 if ( !FT_ALLOC( name, byte_len + 1 ) )
1304 FT_MEM_COPY( name, bytes, byte_len );
1307 cff_index_forget_element( idx, &bytes );
1314 FT_LOCAL_DEF( FT_String* )
1315 cff_index_get_sid_string( CFF_Index idx,
1317 PSNames_Service psnames_service )
1319 /* if it is not a standard string, return it */
1321 return cff_index_get_name( idx, sid - 391 );
1323 /* that's a standard string, fetch a copy from the PSName module */
1325 FT_String* name = 0;
1326 const char* adobe_name = psnames_service->adobe_std_strings( sid );
1332 FT_Memory memory = idx->stream->memory;
1336 len = (FT_UInt)ft_strlen( adobe_name );
1337 if ( !FT_ALLOC( name, len + 1 ) )
1339 FT_MEM_COPY( name, adobe_name, len );
1351 /*************************************************************************/
1352 /*************************************************************************/
1354 /*** FD Select table support ***/
1356 /*************************************************************************/
1357 /*************************************************************************/
1361 CFF_Done_FD_Select( CFF_FDSelect fdselect,
1364 if ( fdselect->data )
1365 FT_FRAME_RELEASE( fdselect->data );
1367 fdselect->data_size = 0;
1368 fdselect->format = 0;
1369 fdselect->range_count = 0;
1374 CFF_Load_FD_Select( CFF_FDSelect fdselect,
1385 if ( FT_STREAM_SEEK( offset ) || FT_READ_BYTE( format ) )
1388 fdselect->format = format;
1389 fdselect->cache_count = 0; /* clear cache */
1393 case 0: /* format 0, that's simple */
1394 fdselect->data_size = num_glyphs;
1397 case 3: /* format 3, a tad more complex */
1398 if ( FT_READ_USHORT( num_ranges ) )
1401 fdselect->data_size = num_ranges * 3 + 2;
1404 if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) )
1408 default: /* hmm... that's wrong */
1409 error = CFF_Err_Invalid_File_Format;
1417 FT_LOCAL_DEF( FT_Byte )
1418 cff_fd_select_get( CFF_FDSelect fdselect,
1419 FT_UInt glyph_index )
1424 switch ( fdselect->format )
1427 fd = fdselect->data[glyph_index];
1431 /* first, compare to cache */
1432 if ( (FT_UInt)( glyph_index - fdselect->cache_first ) <
1433 fdselect->cache_count )
1435 fd = fdselect->cache_fd;
1439 /* then, lookup the ranges array */
1441 FT_Byte* p = fdselect->data;
1442 FT_Byte* p_limit = p + fdselect->data_size;
1444 FT_UInt first, limit;
1447 first = FT_NEXT_USHORT( p );
1450 if ( glyph_index < first )
1454 limit = FT_NEXT_USHORT( p );
1456 if ( glyph_index < limit )
1461 fdselect->cache_first = first;
1462 fdselect->cache_count = limit-first;
1463 fdselect->cache_fd = fd2;
1468 } while ( p < p_limit );
1480 /*************************************************************************/
1481 /*************************************************************************/
1483 /*** CFF font support ***/
1485 /*************************************************************************/
1486 /*************************************************************************/
1489 cff_charset_done( CFF_Charset charset,
1492 FT_Memory memory = stream->memory;
1495 FT_FREE( charset->sids );
1496 charset->format = 0;
1497 charset->offset = 0;
1502 cff_charset_load( CFF_Charset charset,
1505 FT_ULong base_offset,
1508 FT_Memory memory = stream->memory;
1510 FT_UShort glyph_sid;
1513 /* If the the offset is greater than 2, we have to parse the */
1514 /* charset table. */
1520 charset->offset = base_offset + offset;
1522 /* Get the format of the table. */
1523 if ( FT_STREAM_SEEK( charset->offset ) ||
1524 FT_READ_BYTE( charset->format ) )
1527 /* Allocate memory for sids. */
1528 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
1531 /* assign the .notdef glyph */
1532 charset->sids[0] = 0;
1534 switch ( charset->format )
1537 if ( num_glyphs > 0 )
1539 if ( FT_FRAME_ENTER( ( num_glyphs - 1 ) * 2 ) )
1542 for ( j = 1; j < num_glyphs; j++ )
1543 charset->sids[j] = FT_GET_USHORT();
1558 while ( j < num_glyphs )
1561 /* Read the first glyph sid of the range. */
1562 if ( FT_READ_USHORT( glyph_sid ) )
1565 /* Read the number of glyphs in the range. */
1566 if ( charset->format == 2 )
1568 if ( FT_READ_USHORT( nleft ) )
1573 if ( FT_READ_BYTE( nleft ) )
1577 /* Fill in the range of sids -- `nleft + 1' glyphs. */
1578 for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ )
1579 charset->sids[j] = glyph_sid;
1585 FT_ERROR(( "cff_charset_load: invalid table format!\n" ));
1586 error = CFF_Err_Invalid_File_Format;
1592 /* Parse default tables corresponding to offset == 0, 1, or 2. */
1593 /* CFF specification intimates the following: */
1595 /* In order to use a predefined charset, the following must be */
1596 /* true: The charset constructed for the glyphs in the font's */
1597 /* charstrings dictionary must match the predefined charset in */
1598 /* the first num_glyphs */
1600 charset->offset = offset; /* record charset type */
1602 switch ( (FT_UInt)offset )
1605 if ( num_glyphs > 229 )
1607 FT_ERROR(("cff_charset_load: implicit charset larger than\n"
1608 "predefined charset (Adobe ISO-Latin)!\n" ));
1609 error = CFF_Err_Invalid_File_Format;
1613 /* Allocate memory for sids. */
1614 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
1617 /* Copy the predefined charset into the allocated memory. */
1618 FT_MEM_COPY( charset->sids, cff_isoadobe_charset,
1619 num_glyphs * sizeof ( FT_UShort ) );
1624 if ( num_glyphs > 166 )
1626 FT_ERROR(( "cff_charset_load: implicit charset larger than\n"
1627 "predefined charset (Adobe Expert)!\n" ));
1628 error = CFF_Err_Invalid_File_Format;
1632 /* Allocate memory for sids. */
1633 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
1636 /* Copy the predefined charset into the allocated memory. */
1637 FT_MEM_COPY( charset->sids, cff_expert_charset,
1638 num_glyphs * sizeof ( FT_UShort ) );
1643 if ( num_glyphs > 87 )
1645 FT_ERROR(( "cff_charset_load: implicit charset larger than\n"
1646 "predefined charset (Adobe Expert Subset)!\n" ));
1647 error = CFF_Err_Invalid_File_Format;
1651 /* Allocate memory for sids. */
1652 if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
1655 /* Copy the predefined charset into the allocated memory. */
1656 FT_MEM_COPY( charset->sids, cff_expertsubset_charset,
1657 num_glyphs * sizeof ( FT_UShort ) );
1662 error = CFF_Err_Invalid_File_Format;
1669 /* Clean up if there was an error. */
1671 if ( charset->sids )
1673 FT_FREE( charset->sids );
1674 charset->format = 0;
1675 charset->offset = 0;
1685 cff_encoding_done( CFF_Encoding encoding )
1687 encoding->format = 0;
1688 encoding->offset = 0;
1689 encoding->count = 0;
1695 cff_encoding_load( CFF_Encoding encoding,
1696 CFF_Charset charset,
1699 FT_ULong base_offset,
1705 FT_UShort glyph_sid;
1709 /* Check for charset->sids. If we do not have this, we fail. */
1710 if ( !charset->sids )
1712 error = CFF_Err_Invalid_File_Format;
1716 /* Zero out the code to gid/sid mappings. */
1717 for ( j = 0; j < 256; j++ )
1719 encoding->sids [j] = 0;
1720 encoding->codes[j] = 0;
1723 /* Note: The encoding table in a CFF font is indexed by glyph index, */
1724 /* where the first encoded glyph index is 1. Hence, we read the char */
1725 /* code (`glyph_code') at index j and make the assignment: */
1727 /* encoding->codes[glyph_code] = j + 1 */
1729 /* We also make the assignment: */
1731 /* encoding->sids[glyph_code] = charset->sids[j + 1] */
1733 /* This gives us both a code to GID and a code to SID mapping. */
1738 encoding->offset = base_offset + offset;
1740 /* we need to parse the table to determine its size */
1741 if ( FT_STREAM_SEEK( encoding->offset ) ||
1742 FT_READ_BYTE( encoding->format ) ||
1743 FT_READ_BYTE( count ) )
1746 switch ( encoding->format & 0x7F )
1752 /* by convention, GID 0 is always ".notdef" and is never */
1753 /* coded in the font. Hence, the number of codes found */
1754 /* in the table is 'count+1' */
1756 encoding->count = count + 1;
1758 if ( FT_FRAME_ENTER( count ) )
1761 p = (FT_Byte*)stream->cursor;
1763 for ( j = 1; j <= count; j++ )
1767 /* Make sure j is not too big. */
1768 if ( j < num_glyphs )
1770 /* Assign code to GID mapping. */
1771 encoding->codes[glyph_code] = (FT_UShort)j;
1773 /* Assign code to SID mapping. */
1774 encoding->sids[glyph_code] = charset->sids[j];
1789 encoding->count = 0;
1791 /* Parse the Format1 ranges. */
1792 for ( j = 0; j < count; j++, i += nleft )
1794 /* Read the first glyph code of the range. */
1795 if ( FT_READ_BYTE( glyph_code ) )
1798 /* Read the number of codes in the range. */
1799 if ( FT_READ_BYTE( nleft ) )
1802 /* Increment nleft, so we read `nleft + 1' codes/sids. */
1805 /* compute max number of character codes */
1806 if ( (FT_UInt)nleft > encoding->count )
1807 encoding->count = nleft;
1809 /* Fill in the range of codes/sids. */
1810 for ( k = i; k < nleft + i; k++, glyph_code++ )
1812 /* Make sure k is not too big. */
1813 if ( k < num_glyphs && glyph_code < 256 )
1815 /* Assign code to GID mapping. */
1816 encoding->codes[glyph_code] = (FT_UShort)k;
1818 /* Assign code to SID mapping. */
1819 encoding->sids[glyph_code] = charset->sids[k];
1824 /* simple check, one never knows what can be found in a font */
1825 if ( encoding->count > 256 )
1826 encoding->count = 256;
1831 FT_ERROR(( "cff_encoding_load: invalid table format!\n" ));
1832 error = CFF_Err_Invalid_File_Format;
1836 /* Parse supplemental encodings, if any. */
1837 if ( encoding->format & 0x80 )
1842 /* count supplements */
1843 if ( FT_READ_BYTE( count ) )
1846 for ( j = 0; j < count; j++ )
1848 /* Read supplemental glyph code. */
1849 if ( FT_READ_BYTE( glyph_code ) )
1852 /* Read the SID associated with this glyph code. */
1853 if ( FT_READ_USHORT( glyph_sid ) )
1856 /* Assign code to SID mapping. */
1857 encoding->sids[glyph_code] = glyph_sid;
1859 /* First, lookup GID which has been assigned to */
1860 /* SID glyph_sid. */
1861 for ( gindex = 0; gindex < num_glyphs; gindex++ )
1863 if ( charset->sids[gindex] == glyph_sid )
1865 encoding->codes[glyph_code] = (FT_UShort) gindex;
1877 /* We take into account the fact a CFF font can use a predefined */
1878 /* encoding without containing all of the glyphs encoded by this */
1879 /* encoding (see the note at the end of section 12 in the CFF */
1880 /* specification). */
1882 switch ( (FT_UInt)offset )
1885 /* First, copy the code to SID mapping. */
1886 FT_MEM_COPY( encoding->sids, cff_standard_encoding,
1887 256 * sizeof ( FT_UShort ) );
1892 /* First, copy the code to SID mapping. */
1893 FT_MEM_COPY( encoding->sids, cff_expert_encoding,
1894 256 * sizeof ( FT_UShort ) );
1897 /* Construct code to GID mapping from code to SID mapping */
1900 encoding->count = 0;
1903 for ( j = 0; j < 256; j++ )
1905 /* If j is encoded, find the GID for it. */
1906 if ( encoding->sids[j] )
1908 for ( i = 1; i < num_glyphs; i++ )
1909 /* We matched, so break. */
1910 if ( charset->sids[i] == encoding->sids[j] )
1913 /* i will be equal to num_glyphs if we exited the above */
1914 /* loop without a match. In this case, we also have to */
1915 /* fix the code to SID mapping. */
1916 if ( i == num_glyphs )
1918 encoding->codes[j] = 0;
1919 encoding->sids [j] = 0;
1923 encoding->codes[j] = (FT_UShort)i;
1925 /* update encoding count */
1926 if ( encoding->count < j+1 )
1927 encoding->count = j+1;
1934 FT_ERROR(( "cff_encoding_load: invalid table format!\n" ));
1935 error = CFF_Err_Invalid_File_Format;
1942 /* Clean up if there was an error. */
1948 cff_subfont_load( CFF_SubFont font,
1952 FT_ULong base_offset )
1955 CFF_ParserRec parser;
1958 CFF_FontRecDict top = &font->font_dict;
1959 CFF_Private priv = &font->private_dict;
1962 cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict );
1965 FT_MEM_ZERO( top, sizeof ( *top ) );
1967 top->underline_position = -100;
1968 top->underline_thickness = 50;
1969 top->charstring_type = 2;
1970 top->font_matrix.xx = 0x10000L;
1971 top->font_matrix.yy = 0x10000L;
1972 top->cid_count = 8720;
1974 error = cff_index_access_element( idx, font_index, &dict, &dict_len ) ||
1975 cff_parser_run( &parser, dict, dict + dict_len );
1977 cff_index_forget_element( idx, &dict );
1982 /* if it is a CID font, we stop there */
1983 if ( top->cid_registry )
1986 /* parse the private dictionary, if any */
1987 if ( top->private_offset && top->private_size )
1990 FT_MEM_ZERO( priv, sizeof ( *priv ) );
1992 priv->blue_shift = 7;
1993 priv->blue_fuzz = 1;
1995 priv->expansion_factor = (FT_Fixed)0.06 * 0x10000L;
1996 priv->blue_scale = (FT_Fixed)0.039625 * 0x10000L;
1998 cff_parser_init( &parser, CFF_CODE_PRIVATE, priv );
2000 if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) ||
2001 FT_FRAME_ENTER( font->font_dict.private_size ) )
2004 error = cff_parser_run( &parser,
2005 (FT_Byte*)stream->cursor,
2006 (FT_Byte*)stream->limit );
2012 /* read the local subrs, if any */
2013 if ( priv->local_subrs_offset )
2015 if ( FT_STREAM_SEEK( base_offset + top->private_offset +
2016 priv->local_subrs_offset ) )
2019 error = cff_new_index( &font->local_subrs_index, stream, 1 );
2023 font->num_local_subrs = font->local_subrs_index.count;
2024 error = cff_index_get_pointers( &font->local_subrs_index,
2025 &font->local_subrs );
2036 cff_subfont_done( FT_Memory memory,
2037 CFF_SubFont subfont )
2041 cff_done_index( &subfont->local_subrs_index );
2042 FT_FREE( subfont->local_subrs );
2047 FT_LOCAL_DEF( FT_Error )
2048 cff_font_load( FT_Stream stream,
2052 static const FT_Frame_Field cff_header_fields[] =
2055 #define FT_STRUCTURE CFF_FontRec
2057 FT_FRAME_START( 4 ),
2058 FT_FRAME_BYTE( version_major ),
2059 FT_FRAME_BYTE( version_minor ),
2060 FT_FRAME_BYTE( header_size ),
2061 FT_FRAME_BYTE( absolute_offsize ),
2066 FT_Memory memory = stream->memory;
2067 FT_ULong base_offset;
2068 CFF_FontRecDict dict;
2072 font->stream = stream;
2073 font->memory = memory;
2074 dict = &font->top_font.font_dict;
2075 base_offset = FT_STREAM_POS();
2077 /* read CFF font header */
2078 if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) )
2082 if ( font->version_major != 1 ||
2083 font->header_size < 4 ||
2084 font->absolute_offsize > 4 )
2086 FT_TRACE2(( "[not a CFF font header!]\n" ));
2087 error = CFF_Err_Unknown_File_Format;
2091 /* skip the rest of the header */
2092 if ( FT_STREAM_SKIP( font->header_size - 4 ) )
2095 /* read the name, top dict, string and global subrs index */
2096 if ( FT_SET_ERROR( cff_new_index( &font->name_index, stream, 0 )) ||
2097 FT_SET_ERROR( cff_new_index( &font->font_dict_index, stream, 0 )) ||
2098 FT_SET_ERROR( cff_new_index( &font->string_index, stream, 0 )) ||
2099 FT_SET_ERROR( cff_new_index( &font->global_subrs_index, stream, 1 )) )
2102 /* well, we don't really forget the `disabled' fonts... */
2103 font->num_faces = font->name_index.count;
2104 if ( face_index >= (FT_Int)font->num_faces )
2106 FT_ERROR(( "cff_font_load: incorrect face index = %d\n",
2108 error = CFF_Err_Invalid_Argument;
2111 /* in case of a font format check, simply exit now */
2112 if ( face_index < 0 )
2115 /* now, parse the top-level font dictionary */
2116 error = cff_subfont_load( &font->top_font,
2117 &font->font_dict_index,
2124 /* now, check for a CID font */
2125 if ( dict->cid_registry )
2127 CFF_IndexRec fd_index;
2132 /* this is a CID-keyed font, we must now allocate a table of */
2133 /* sub-fonts, then load each of them separately */
2134 if ( FT_STREAM_SEEK( base_offset + dict->cid_fd_array_offset ) )
2137 error = cff_new_index( &fd_index, stream, 0 );
2141 if ( fd_index.count > CFF_MAX_CID_FONTS )
2143 FT_ERROR(( "cff_font_load: FD array too large in CID font\n" ));
2147 /* allocate & read each font dict independently */
2148 font->num_subfonts = fd_index.count;
2149 if ( FT_NEW_ARRAY( sub, fd_index.count ) )
2152 /* setup pointer table */
2153 for ( idx = 0; idx < fd_index.count; idx++ )
2154 font->subfonts[idx] = sub + idx;
2156 /* now load each sub font independently */
2157 for ( idx = 0; idx < fd_index.count; idx++ )
2159 sub = font->subfonts[idx];
2160 error = cff_subfont_load( sub, &fd_index, idx,
2161 stream, base_offset );
2166 /* now load the FD Select array */
2167 error = CFF_Load_FD_Select( &font->fd_select,
2168 (FT_UInt)dict->cid_count,
2170 base_offset + dict->cid_fd_select_offset );
2173 cff_done_index( &fd_index );
2179 font->num_subfonts = 0;
2181 /* read the charstrings index now */
2182 if ( dict->charstrings_offset == 0 )
2184 FT_ERROR(( "cff_font_load: no charstrings offset!\n" ));
2185 error = CFF_Err_Unknown_File_Format;
2189 if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) )
2192 error = cff_new_index( &font->charstrings_index, stream, 0 );
2196 /* explicit the global subrs */
2197 font->num_global_subrs = font->global_subrs_index.count;
2198 font->num_glyphs = font->charstrings_index.count;
2200 error = cff_index_get_pointers( &font->global_subrs_index,
2201 &font->global_subrs ) ;
2206 /* read the Charset and Encoding tables when available */
2207 if ( font->num_glyphs > 0 )
2209 error = cff_charset_load( &font->charset, font->num_glyphs, stream,
2210 base_offset, dict->charset_offset );
2214 error = cff_encoding_load( &font->encoding,
2219 dict->encoding_offset );
2224 /* get the font name */
2225 font->font_name = cff_index_get_name( &font->name_index, face_index );
2232 FT_LOCAL_DEF( void )
2233 cff_font_done( CFF_Font font )
2235 FT_Memory memory = font->memory;
2239 cff_done_index( &font->global_subrs_index );
2240 cff_done_index( &font->string_index );
2241 cff_done_index( &font->font_dict_index );
2242 cff_done_index( &font->name_index );
2243 cff_done_index( &font->charstrings_index );
2245 /* release font dictionaries, but only if working with */
2246 /* a CID keyed CFF font */
2247 if ( font->num_subfonts > 0 )
2249 for ( idx = 0; idx < font->num_subfonts; idx++ )
2250 cff_subfont_done( memory, font->subfonts[idx] );
2252 FT_FREE( font->subfonts );
2255 cff_encoding_done( &font->encoding );
2256 cff_charset_done( &font->charset, font->stream );
2258 cff_subfont_done( memory, &font->top_font );
2260 CFF_Done_FD_Select( &font->fd_select, font->stream );
2262 FT_FREE( font->global_subrs );
2263 FT_FREE( font->font_name );