sfobjs.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /***************************************************************************/
  2. /* */
  3. /* sfobjs.c */
  4. /* */
  5. /* SFNT object management (base). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  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. */
  15. /* */
  16. /***************************************************************************/
  17. #include <ft2build.h>
  18. #include "sfobjs.h"
  19. #include "ttload.h"
  20. #include "ttcmap0.h"
  21. #include FT_INTERNAL_SFNT_H
  22. #include FT_INTERNAL_POSTSCRIPT_NAMES_H
  23. #include FT_TRUETYPE_IDS_H
  24. #include FT_TRUETYPE_TAGS_H
  25. #include "sferrors.h"
  26. /*************************************************************************/
  27. /* */
  28. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  29. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  30. /* messages during execution. */
  31. /* */
  32. #undef FT_COMPONENT
  33. #define FT_COMPONENT trace_sfobjs
  34. /* convert a UTF-16 name entry to ASCII */
  35. static FT_String*
  36. tt_name_entry_ascii_from_utf16( TT_NameEntry entry,
  37. FT_Memory memory )
  38. {
  39. FT_String* string;
  40. FT_UInt len, code, n;
  41. FT_Byte* read = (FT_Byte*)entry->string;
  42. len = (FT_UInt)entry->stringLength / 2;
  43. if ( FT_MEM_NEW_ARRAY( string, len + 1 ) )
  44. return NULL;
  45. for ( n = 0; n < len; n++ )
  46. {
  47. code = FT_NEXT_USHORT( read );
  48. if ( code < 32 || code > 127 )
  49. code = '?';
  50. string[n] = (char)code;
  51. }
  52. string[len] = 0;
  53. return string;
  54. }
  55. /* convert a UCS-4 name entry to ASCII */
  56. static FT_String*
  57. tt_name_entry_ascii_from_ucs4( TT_NameEntry entry,
  58. FT_Memory memory )
  59. {
  60. FT_String* string;
  61. FT_UInt len, code, n;
  62. FT_Byte* read = (FT_Byte*)entry->string;
  63. len = (FT_UInt)entry->stringLength / 4;
  64. if ( FT_MEM_NEW_ARRAY( string, len + 1 ) )
  65. return NULL;
  66. for ( n = 0; n < len; n++ )
  67. {
  68. code = (FT_UInt)FT_NEXT_ULONG( read );
  69. if ( code < 32 || code > 127 )
  70. code = '?';
  71. string[n] = (char)code;
  72. }
  73. string[len] = 0;
  74. return string;
  75. }
  76. /* convert an Apple Roman or symbol name entry to ASCII */
  77. static FT_String*
  78. tt_name_entry_ascii_from_other( TT_NameEntry entry,
  79. FT_Memory memory )
  80. {
  81. FT_String* string;
  82. FT_UInt len, code, n;
  83. FT_Byte* read = (FT_Byte*)entry->string;
  84. len = (FT_UInt)entry->stringLength;
  85. if ( FT_MEM_NEW_ARRAY( string, len + 1 ) )
  86. return NULL;
  87. for ( n = 0; n < len; n++ )
  88. {
  89. code = *read++;
  90. if ( code < 32 || code > 127 )
  91. code = '?';
  92. string[n] = (char)code;
  93. }
  94. string[len] = 0;
  95. return string;
  96. }
  97. typedef FT_String* (*TT_NameEntry_ConvertFunc)( TT_NameEntry entry,
  98. FT_Memory memory );
  99. /*************************************************************************/
  100. /* */
  101. /* <Function> */
  102. /* tt_face_get_name */
  103. /* */
  104. /* <Description> */
  105. /* Returns a given ENGLISH name record in ASCII. */
  106. /* */
  107. /* <Input> */
  108. /* face :: A handle to the source face object. */
  109. /* */
  110. /* nameid :: The name id of the name record to return. */
  111. /* */
  112. /* <Return> */
  113. /* Character string. NULL if no name is present. */
  114. /* */
  115. static FT_String*
  116. tt_face_get_name( TT_Face face,
  117. FT_UShort nameid )
  118. {
  119. FT_Memory memory = face->root.memory;
  120. FT_String* result = NULL;
  121. FT_UShort n;
  122. TT_NameEntryRec* rec;
  123. FT_Int found_apple = -1;
  124. FT_Int found_win = -1;
  125. FT_Int found_unicode = -1;
  126. TT_NameEntry_ConvertFunc convert;
  127. rec = face->name_table.names;
  128. for ( n = 0; n < face->num_names; n++, rec++ )
  129. {
  130. /* According to the OpenType 1.3 specification, only Microsoft or */
  131. /* Apple platform IDs might be used in the `name' table. The */
  132. /* `Unicode' platform is reserved for the `cmap' table, and the */
  133. /* `Iso' one is deprecated. */
  134. /* */
  135. /* However, the Apple TrueType specification doesn't say the same */
  136. /* thing and goes to suggest that all Unicode `name' table entries */
  137. /* should be coded in UTF-16 (in big-endian format I suppose). */
  138. /* */
  139. if ( rec->nameID == nameid && rec->stringLength > 0 )
  140. {
  141. switch ( rec->platformID )
  142. {
  143. case TT_PLATFORM_APPLE_UNICODE:
  144. case TT_PLATFORM_ISO:
  145. /* there is `languageID' to check there. We should use this */
  146. /* field only as a last solution when nothing else is */
  147. /* available. */
  148. /* */
  149. found_unicode = n;
  150. break;
  151. case TT_PLATFORM_MACINTOSH:
  152. if ( rec->languageID == TT_MAC_LANGID_ENGLISH )
  153. found_apple = n;
  154. break;
  155. case TT_PLATFORM_MICROSOFT:
  156. /* we only take a non-English name when there is nothing */
  157. /* else available in the font */
  158. /* */
  159. if ( found_win == -1 || ( rec->languageID & 0x3FF ) == 0x009 )
  160. {
  161. switch ( rec->encodingID )
  162. {
  163. case TT_MS_ID_SYMBOL_CS:
  164. case TT_MS_ID_UNICODE_CS:
  165. case TT_MS_ID_UCS_4:
  166. found_win = n;
  167. break;
  168. default:
  169. ;
  170. }
  171. }
  172. break;
  173. default:
  174. ;
  175. }
  176. }
  177. }
  178. /* some fonts contain invalid Unicode or Macintosh formatted entries; */
  179. /* we will thus favor names encoded in Windows formats if available */
  180. /* */
  181. convert = NULL;
  182. if ( found_win >= 0 )
  183. {
  184. rec = face->name_table.names + found_win;
  185. switch ( rec->encodingID )
  186. {
  187. case TT_MS_ID_UNICODE_CS:
  188. case TT_MS_ID_SYMBOL_CS:
  189. convert = tt_name_entry_ascii_from_utf16;
  190. break;
  191. case TT_MS_ID_UCS_4:
  192. convert = tt_name_entry_ascii_from_ucs4;
  193. break;
  194. default:
  195. ;
  196. }
  197. }
  198. else if ( found_apple >= 0 )
  199. {
  200. rec = face->name_table.names + found_apple;
  201. convert = tt_name_entry_ascii_from_other;
  202. }
  203. else if ( found_unicode >= 0 )
  204. {
  205. rec = face->name_table.names + found_unicode;
  206. convert = tt_name_entry_ascii_from_utf16;
  207. }
  208. if ( rec && convert )
  209. {
  210. if ( rec->string == NULL )
  211. {
  212. FT_Error error;
  213. FT_Stream stream = face->name_table.stream;
  214. if ( FT_NEW_ARRAY ( rec->string, rec->stringLength ) ||
  215. FT_STREAM_SEEK( rec->stringOffset ) ||
  216. FT_STREAM_READ( rec->string, rec->stringLength ) )
  217. {
  218. FT_FREE( rec->string );
  219. rec->stringLength = 0;
  220. result = NULL;
  221. goto Exit;
  222. }
  223. }
  224. result = convert( rec, memory );
  225. }
  226. Exit:
  227. return result;
  228. }
  229. static FT_Encoding
  230. sfnt_find_encoding( int platform_id,
  231. int encoding_id )
  232. {
  233. typedef struct TEncoding
  234. {
  235. int platform_id;
  236. int encoding_id;
  237. FT_Encoding encoding;
  238. } TEncoding;
  239. static
  240. const TEncoding tt_encodings[] =
  241. {
  242. { TT_PLATFORM_ISO, -1, FT_ENCODING_UNICODE },
  243. { TT_PLATFORM_APPLE_UNICODE, -1, FT_ENCODING_UNICODE },
  244. { TT_PLATFORM_MACINTOSH, TT_MAC_ID_ROMAN, FT_ENCODING_APPLE_ROMAN },
  245. { TT_PLATFORM_MICROSOFT, TT_MS_ID_SYMBOL_CS, FT_ENCODING_MS_SYMBOL },
  246. { TT_PLATFORM_MICROSOFT, TT_MS_ID_UCS_4, FT_ENCODING_UNICODE },
  247. { TT_PLATFORM_MICROSOFT, TT_MS_ID_UNICODE_CS, FT_ENCODING_UNICODE },
  248. { TT_PLATFORM_MICROSOFT, TT_MS_ID_SJIS, FT_ENCODING_MS_SJIS },
  249. { TT_PLATFORM_MICROSOFT, TT_MS_ID_GB2312, FT_ENCODING_MS_GB2312 },
  250. { TT_PLATFORM_MICROSOFT, TT_MS_ID_BIG_5, FT_ENCODING_MS_BIG5 },
  251. { TT_PLATFORM_MICROSOFT, TT_MS_ID_WANSUNG, FT_ENCODING_MS_WANSUNG },
  252. { TT_PLATFORM_MICROSOFT, TT_MS_ID_JOHAB, FT_ENCODING_MS_JOHAB }
  253. };
  254. const TEncoding *cur, *limit;
  255. cur = tt_encodings;
  256. limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] );
  257. for ( ; cur < limit; cur++ )
  258. {
  259. if ( cur->platform_id == platform_id )
  260. {
  261. if ( cur->encoding_id == encoding_id ||
  262. cur->encoding_id == -1 )
  263. return cur->encoding;
  264. }
  265. }
  266. return FT_ENCODING_NONE;
  267. }
  268. FT_LOCAL_DEF( FT_Error )
  269. sfnt_init_face( FT_Stream stream,
  270. TT_Face face,
  271. FT_Int face_index,
  272. FT_Int num_params,
  273. FT_Parameter* params )
  274. {
  275. FT_Error error;
  276. FT_Library library = face->root.driver->root.library;
  277. SFNT_Service sfnt;
  278. SFNT_HeaderRec sfnt_header;
  279. /* for now, parameters are unused */
  280. FT_UNUSED( num_params );
  281. FT_UNUSED( params );
  282. sfnt = (SFNT_Service)face->sfnt;
  283. if ( !sfnt )
  284. {
  285. sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
  286. if ( !sfnt )
  287. {
  288. error = SFNT_Err_Invalid_File_Format;
  289. goto Exit;
  290. }
  291. face->sfnt = sfnt;
  292. face->goto_table = sfnt->goto_table;
  293. }
  294. if ( !face->psnames )
  295. {
  296. face->psnames = (PSNames_Service)
  297. FT_Get_Module_Interface( library, "psnames" );
  298. }
  299. /* check that we have a valid TrueType file */
  300. error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header );
  301. if ( error )
  302. goto Exit;
  303. face->format_tag = sfnt_header.format_tag;
  304. face->num_tables = sfnt_header.num_tables;
  305. /* Load font directory */
  306. error = sfnt->load_directory( face, stream, &sfnt_header );
  307. if ( error )
  308. goto Exit;
  309. face->root.num_faces = face->ttc_header.count;
  310. if ( face->root.num_faces < 1 )
  311. face->root.num_faces = 1;
  312. Exit:
  313. return error;
  314. }
  315. #undef LOAD_
  316. #define LOAD_( x ) ( ( error = sfnt->load_##x( face, stream ) ) \
  317. != SFNT_Err_Ok )
  318. FT_LOCAL_DEF( FT_Error )
  319. sfnt_load_face( FT_Stream stream,
  320. TT_Face face,
  321. FT_Int face_index,
  322. FT_Int num_params,
  323. FT_Parameter* params )
  324. {
  325. FT_Error error;
  326. FT_Bool has_outline;
  327. FT_Bool is_apple_sbit;
  328. SFNT_Service sfnt = (SFNT_Service)face->sfnt;
  329. FT_UNUSED( face_index );
  330. FT_UNUSED( num_params );
  331. FT_UNUSED( params );
  332. /* Load tables */
  333. /* We now support two SFNT-based bitmapped font formats. They */
  334. /* are recognized easily as they do not include a `glyf' */
  335. /* table. */
  336. /* */
  337. /* The first format comes from Apple, and uses a table named */
  338. /* `bhed' instead of `head' to store the font header (using */
  339. /* the same format). It also doesn't include horizontal and */
  340. /* vertical metrics tables (i.e. `hhea' and `vhea' tables are */
  341. /* missing). */
  342. /* */
  343. /* The other format comes from Microsoft, and is used with */
  344. /* WinCE/PocketPC. It looks like a standard TTF, except that */
  345. /* it doesn't contain outlines. */
  346. /* */
  347. /* do we have outlines in there? */
  348. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  349. has_outline = FT_BOOL( face->root.internal->incremental_interface != 0 ||
  350. tt_face_lookup_table( face, TTAG_glyf ) != 0 ||
  351. tt_face_lookup_table( face, TTAG_CFF ) != 0 );
  352. #else
  353. has_outline = FT_BOOL( tt_face_lookup_table( face, TTAG_glyf ) != 0 ||
  354. tt_face_lookup_table( face, TTAG_CFF ) != 0 );
  355. #endif
  356. is_apple_sbit = 0;
  357. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  358. /* if this font doesn't contain outlines, we try to load */
  359. /* a `bhed' table */
  360. if ( !has_outline )
  361. is_apple_sbit = FT_BOOL( !LOAD_( bitmap_header ) );
  362. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  363. /* load the font header (`head' table) if this isn't an Apple */
  364. /* sbit font file */
  365. if ( !is_apple_sbit && LOAD_( header ) )
  366. goto Exit;
  367. /* the following tables are often not present in embedded TrueType */
  368. /* fonts within PDF documents, so don't check for them. */
  369. (void)LOAD_( max_profile );
  370. (void)LOAD_( charmaps );
  371. /* the following tables are optional in PCL fonts -- */
  372. /* don't check for errors */
  373. (void)LOAD_( names );
  374. (void)LOAD_( psnames );
  375. /* do not load the metrics headers and tables if this is an Apple */
  376. /* sbit font file */
  377. if ( !is_apple_sbit )
  378. {
  379. /* load the `hhea' and `hmtx' tables at once */
  380. error = sfnt->load_metrics( face, stream, 0 );
  381. if ( error )
  382. goto Exit;
  383. /* try to load the `vhea' and `vmtx' tables at once */
  384. error = sfnt->load_metrics( face, stream, 1 );
  385. if ( error )
  386. goto Exit;
  387. if ( LOAD_( os2 ) )
  388. goto Exit;
  389. }
  390. /* the optional tables */
  391. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  392. /* embedded bitmap support. */
  393. if ( sfnt->load_sbits && LOAD_( sbits ) )
  394. {
  395. /* return an error if this font file has no outlines */
  396. if ( error == SFNT_Err_Table_Missing && has_outline )
  397. error = SFNT_Err_Ok;
  398. else
  399. goto Exit;
  400. }
  401. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  402. if ( LOAD_( hdmx ) ||
  403. LOAD_( gasp ) ||
  404. LOAD_( kerning ) ||
  405. LOAD_( pclt ) )
  406. goto Exit;
  407. face->root.family_name = tt_face_get_name( face,
  408. TT_NAME_ID_FONT_FAMILY );
  409. face->root.style_name = tt_face_get_name( face,
  410. TT_NAME_ID_FONT_SUBFAMILY );
  411. /* now set up root fields */
  412. {
  413. FT_Face root = &face->root;
  414. FT_Int32 flags = 0;
  415. FT_Memory memory;
  416. memory = root->memory;
  417. /*********************************************************************/
  418. /* */
  419. /* Compute face flags. */
  420. /* */
  421. if ( has_outline == TRUE )
  422. flags = FT_FACE_FLAG_SCALABLE; /* scalable outlines */
  423. flags |= FT_FACE_FLAG_SFNT | /* SFNT file format */
  424. FT_FACE_FLAG_HORIZONTAL; /* horizontal data */
  425. #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
  426. /* might need more polish to detect the presence of a Postscript */
  427. /* name table in the font */
  428. flags |= FT_FACE_FLAG_GLYPH_NAMES;
  429. #endif
  430. /* fixed width font? */
  431. if ( face->postscript.isFixedPitch )
  432. flags |= FT_FACE_FLAG_FIXED_WIDTH;
  433. /* vertical information? */
  434. if ( face->vertical_info )
  435. flags |= FT_FACE_FLAG_VERTICAL;
  436. /* kerning available ? */
  437. if ( face->kern_pairs )
  438. flags |= FT_FACE_FLAG_KERNING;
  439. root->face_flags = flags;
  440. /*********************************************************************/
  441. /* */
  442. /* Compute style flags. */
  443. /* */
  444. flags = 0;
  445. if ( has_outline == TRUE && face->os2.version != 0xFFFF )
  446. {
  447. /* we have an OS/2 table; use the `fsSelection' field */
  448. if ( face->os2.fsSelection & 1 )
  449. flags |= FT_STYLE_FLAG_ITALIC;
  450. if ( face->os2.fsSelection & 32 )
  451. flags |= FT_STYLE_FLAG_BOLD;
  452. }
  453. else
  454. {
  455. /* this is an old Mac font, use the header field */
  456. if ( face->header.Mac_Style & 1 )
  457. flags |= FT_STYLE_FLAG_BOLD;
  458. if ( face->header.Mac_Style & 2 )
  459. flags |= FT_STYLE_FLAG_ITALIC;
  460. }
  461. root->style_flags = flags;
  462. /*********************************************************************/
  463. /* */
  464. /* Polish the charmaps. */
  465. /* */
  466. /* Try to set the charmap encoding according to the platform & */
  467. /* encoding ID of each charmap. */
  468. /* */
  469. tt_face_build_cmaps( face ); /* ignore errors */
  470. /* set the encoding fields */
  471. {
  472. FT_Int m;
  473. for ( m = 0; m < root->num_charmaps; m++ )
  474. {
  475. FT_CharMap charmap = root->charmaps[m];
  476. charmap->encoding = sfnt_find_encoding( charmap->platform_id,
  477. charmap->encoding_id );
  478. #if 0
  479. if ( root->charmap == NULL &&
  480. charmap->encoding == FT_ENCODING_UNICODE )
  481. {
  482. /* set 'root->charmap' to the first Unicode encoding we find */
  483. root->charmap = charmap;
  484. }
  485. #endif
  486. }
  487. }
  488. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  489. if ( face->num_sbit_strikes )
  490. {
  491. FT_ULong n;
  492. root->face_flags |= FT_FACE_FLAG_FIXED_SIZES;
  493. #if 0
  494. /* XXX: I don't know criteria whether layout is horizontal */
  495. /* or vertical. */
  496. if ( has_outline.... )
  497. {
  498. ...
  499. root->face_flags |= FT_FACE_FLAG_VERTICAL;
  500. }
  501. #endif
  502. root->num_fixed_sizes = face->num_sbit_strikes;
  503. if ( FT_NEW_ARRAY( root->available_sizes, face->num_sbit_strikes ) )
  504. goto Exit;
  505. for ( n = 0 ; n < face->num_sbit_strikes ; n++ )
  506. {
  507. root->available_sizes[n].width =
  508. face->sbit_strikes[n].x_ppem;
  509. root->available_sizes[n].height =
  510. face->sbit_strikes[n].y_ppem;
  511. }
  512. }
  513. else
  514. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  515. {
  516. root->num_fixed_sizes = 0;
  517. root->available_sizes = 0;
  518. }
  519. /*********************************************************************/
  520. /* */
  521. /* Set up metrics. */
  522. /* */
  523. if ( has_outline == TRUE )
  524. {
  525. /* XXX What about if outline header is missing */
  526. /* (e.g. sfnt wrapped outline)? */
  527. root->bbox.xMin = face->header.xMin;
  528. root->bbox.yMin = face->header.yMin;
  529. root->bbox.xMax = face->header.xMax;
  530. root->bbox.yMax = face->header.yMax;
  531. root->units_per_EM = face->header.Units_Per_EM;
  532. /* XXX: Computing the ascender/descender/height is very different */
  533. /* from what the specification tells you. Apparently, we */
  534. /* must be careful because */
  535. /* */
  536. /* - not all fonts have an OS/2 table; in this case, we take */
  537. /* the values in the horizontal header. However, these */
  538. /* values very often are not reliable. */
  539. /* */
  540. /* - otherwise, the correct typographic values are in the */
  541. /* sTypoAscender, sTypoDescender & sTypoLineGap fields. */
  542. /* */
  543. /* However, certains fonts have these fields set to 0. */
  544. /* Rather, they have usWinAscent & usWinDescent correctly */
  545. /* set (but with different values). */
  546. /* */
  547. /* As an example, Arial Narrow is implemented through four */
  548. /* files ARIALN.TTF, ARIALNI.TTF, ARIALNB.TTF & ARIALNBI.TTF */
  549. /* */
  550. /* Strangely, all fonts have the same values in their */
  551. /* sTypoXXX fields, except ARIALNB which sets them to 0. */
  552. /* */
  553. /* On the other hand, they all have different */
  554. /* usWinAscent/Descent values -- as a conclusion, the OS/2 */
  555. /* table cannot be used to compute the text height reliably! */
  556. /* */
  557. /* The ascender/descender/height are computed from the OS/2 table */
  558. /* when found. Otherwise, they're taken from the horizontal */
  559. /* header. */
  560. /* */
  561. root->ascender = face->horizontal.Ascender;
  562. root->descender = face->horizontal.Descender;
  563. root->height = (FT_Short)( root->ascender - root->descender +
  564. face->horizontal.Line_Gap );
  565. /* if the line_gap is 0, we add an extra 15% to the text height -- */
  566. /* this computation is based on various versions of Times New Roman */
  567. if ( face->horizontal.Line_Gap == 0 )
  568. root->height = (FT_Short)( ( root->height * 115 + 50 ) / 100 );
  569. #if 0
  570. /* some fonts have the OS/2 "sTypoAscender", "sTypoDescender" & */
  571. /* "sTypoLineGap" fields set to 0, like ARIALNB.TTF */
  572. if ( face->os2.version != 0xFFFF && root->ascender )
  573. {
  574. FT_Int height;
  575. root->ascender = face->os2.sTypoAscender;
  576. root->descender = -face->os2.sTypoDescender;
  577. height = root->ascender + root->descender + face->os2.sTypoLineGap;
  578. if ( height > root->height )
  579. root->height = height;
  580. }
  581. #endif /* 0 */
  582. root->max_advance_width = face->horizontal.advance_Width_Max;
  583. root->max_advance_height = (FT_Short)( face->vertical_info
  584. ? face->vertical.advance_Height_Max
  585. : root->height );
  586. root->underline_position = face->postscript.underlinePosition;
  587. root->underline_thickness = face->postscript.underlineThickness;
  588. /* root->max_points -- already set up */
  589. /* root->max_contours -- already set up */
  590. }
  591. }
  592. Exit:
  593. return error;
  594. }
  595. #undef LOAD_
  596. FT_LOCAL_DEF( void )
  597. sfnt_done_face( TT_Face face )
  598. {
  599. FT_Memory memory = face->root.memory;
  600. SFNT_Service sfnt = (SFNT_Service)face->sfnt;
  601. if ( sfnt )
  602. {
  603. /* destroy the postscript names table if it is loaded */
  604. if ( sfnt->free_psnames )
  605. sfnt->free_psnames( face );
  606. /* destroy the embedded bitmaps table if it is loaded */
  607. if ( sfnt->free_sbits )
  608. sfnt->free_sbits( face );
  609. }
  610. /* freeing the kerning table */
  611. FT_FREE( face->kern_pairs );
  612. face->num_kern_pairs = 0;
  613. /* freeing the collection table */
  614. FT_FREE( face->ttc_header.offsets );
  615. face->ttc_header.count = 0;
  616. /* freeing table directory */
  617. FT_FREE( face->dir_tables );
  618. face->num_tables = 0;
  619. {
  620. FT_Stream stream = FT_FACE_STREAM( face );
  621. /* simply release the 'cmap' table frame */
  622. FT_FRAME_RELEASE( face->cmap_table );
  623. face->cmap_size = 0;
  624. }
  625. /* freeing the horizontal metrics */
  626. FT_FREE( face->horizontal.long_metrics );
  627. FT_FREE( face->horizontal.short_metrics );
  628. /* freeing the vertical ones, if any */
  629. if ( face->vertical_info )
  630. {
  631. FT_FREE( face->vertical.long_metrics );
  632. FT_FREE( face->vertical.short_metrics );
  633. face->vertical_info = 0;
  634. }
  635. /* freeing the gasp table */
  636. FT_FREE( face->gasp.gaspRanges );
  637. face->gasp.numRanges = 0;
  638. /* freeing the name table */
  639. sfnt->free_names( face );
  640. /* freeing the hdmx table */
  641. sfnt->free_hdmx( face );
  642. /* freeing family and style name */
  643. FT_FREE( face->root.family_name );
  644. FT_FREE( face->root.style_name );
  645. /* freeing sbit size table */
  646. face->root.num_fixed_sizes = 0;
  647. if ( face->root.available_sizes )
  648. FT_FREE( face->root.available_sizes );
  649. face->sfnt = 0;
  650. }
  651. /* END */