/Code/Angel/Libraries/freetype-2.3.7/src/truetype/ttobjs.c

http://angel-engine.googlecode.com/ · C · 943 lines · 499 code · 194 blank · 250 comment · 66 complexity · d00ce89252f5634fd65921d2460e089a MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ttobjs.c */
  4. /* */
  5. /* Objects manager (body). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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 FT_INTERNAL_DEBUG_H
  19. #include FT_INTERNAL_CALC_H
  20. #include FT_INTERNAL_STREAM_H
  21. #include FT_TRUETYPE_IDS_H
  22. #include FT_TRUETYPE_TAGS_H
  23. #include FT_INTERNAL_SFNT_H
  24. #include "ttgload.h"
  25. #include "ttpload.h"
  26. #include "tterrors.h"
  27. #ifdef TT_USE_BYTECODE_INTERPRETER
  28. #include "ttinterp.h"
  29. #endif
  30. #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  31. #include FT_TRUETYPE_UNPATENTED_H
  32. #endif
  33. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  34. #include "ttgxvar.h"
  35. #endif
  36. /*************************************************************************/
  37. /* */
  38. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  39. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  40. /* messages during execution. */
  41. /* */
  42. #undef FT_COMPONENT
  43. #define FT_COMPONENT trace_ttobjs
  44. #ifdef TT_USE_BYTECODE_INTERPRETER
  45. /*************************************************************************/
  46. /* */
  47. /* GLYPH ZONE FUNCTIONS */
  48. /* */
  49. /*************************************************************************/
  50. /*************************************************************************/
  51. /* */
  52. /* <Function> */
  53. /* tt_glyphzone_done */
  54. /* */
  55. /* <Description> */
  56. /* Deallocate a glyph zone. */
  57. /* */
  58. /* <Input> */
  59. /* zone :: A pointer to the target glyph zone. */
  60. /* */
  61. FT_LOCAL_DEF( void )
  62. tt_glyphzone_done( TT_GlyphZone zone )
  63. {
  64. FT_Memory memory = zone->memory;
  65. if ( memory )
  66. {
  67. FT_FREE( zone->contours );
  68. FT_FREE( zone->tags );
  69. FT_FREE( zone->cur );
  70. FT_FREE( zone->org );
  71. FT_FREE( zone->orus );
  72. zone->max_points = zone->n_points = 0;
  73. zone->max_contours = zone->n_contours = 0;
  74. zone->memory = NULL;
  75. }
  76. }
  77. /*************************************************************************/
  78. /* */
  79. /* <Function> */
  80. /* tt_glyphzone_new */
  81. /* */
  82. /* <Description> */
  83. /* Allocate a new glyph zone. */
  84. /* */
  85. /* <Input> */
  86. /* memory :: A handle to the current memory object. */
  87. /* */
  88. /* maxPoints :: The capacity of glyph zone in points. */
  89. /* */
  90. /* maxContours :: The capacity of glyph zone in contours. */
  91. /* */
  92. /* <Output> */
  93. /* zone :: A pointer to the target glyph zone record. */
  94. /* */
  95. /* <Return> */
  96. /* FreeType error code. 0 means success. */
  97. /* */
  98. FT_LOCAL_DEF( FT_Error )
  99. tt_glyphzone_new( FT_Memory memory,
  100. FT_UShort maxPoints,
  101. FT_Short maxContours,
  102. TT_GlyphZone zone )
  103. {
  104. FT_Error error;
  105. FT_MEM_ZERO( zone, sizeof ( *zone ) );
  106. zone->memory = memory;
  107. if ( FT_NEW_ARRAY( zone->org, maxPoints ) ||
  108. FT_NEW_ARRAY( zone->cur, maxPoints ) ||
  109. FT_NEW_ARRAY( zone->orus, maxPoints ) ||
  110. FT_NEW_ARRAY( zone->tags, maxPoints ) ||
  111. FT_NEW_ARRAY( zone->contours, maxContours ) )
  112. {
  113. tt_glyphzone_done( zone );
  114. }
  115. else
  116. {
  117. zone->max_points = maxPoints;
  118. zone->max_contours = maxContours;
  119. }
  120. return error;
  121. }
  122. #endif /* TT_USE_BYTECODE_INTERPRETER */
  123. /*************************************************************************/
  124. /* */
  125. /* <Function> */
  126. /* tt_face_init */
  127. /* */
  128. /* <Description> */
  129. /* Initialize a given TrueType face object. */
  130. /* */
  131. /* <Input> */
  132. /* stream :: The source font stream. */
  133. /* */
  134. /* face_index :: The index of the font face in the resource. */
  135. /* */
  136. /* num_params :: Number of additional generic parameters. Ignored. */
  137. /* */
  138. /* params :: Additional generic parameters. Ignored. */
  139. /* */
  140. /* <InOut> */
  141. /* face :: The newly built face object. */
  142. /* */
  143. /* <Return> */
  144. /* FreeType error code. 0 means success. */
  145. /* */
  146. FT_LOCAL_DEF( FT_Error )
  147. tt_face_init( FT_Stream stream,
  148. FT_Face ttface, /* TT_Face */
  149. FT_Int face_index,
  150. FT_Int num_params,
  151. FT_Parameter* params )
  152. {
  153. FT_Error error;
  154. FT_Library library;
  155. SFNT_Service sfnt;
  156. TT_Face face = (TT_Face)ttface;
  157. library = face->root.driver->root.library;
  158. sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
  159. if ( !sfnt )
  160. goto Bad_Format;
  161. /* create input stream from resource */
  162. if ( FT_STREAM_SEEK( 0 ) )
  163. goto Exit;
  164. /* check that we have a valid TrueType file */
  165. error = sfnt->init_face( stream, face, face_index, num_params, params );
  166. if ( error )
  167. goto Exit;
  168. /* We must also be able to accept Mac/GX fonts, as well as OT ones. */
  169. /* The 0x00020000 tag is completely undocumented; some fonts from */
  170. /* Arphic made for Chinese Windows 3.1 have this. */
  171. if ( face->format_tag != 0x00010000L && /* MS fonts */
  172. face->format_tag != 0x00020000L && /* CJK fonts for Win 3.1 */
  173. face->format_tag != TTAG_true ) /* Mac fonts */
  174. {
  175. FT_TRACE2(( "[not a valid TTF font]\n" ));
  176. goto Bad_Format;
  177. }
  178. #ifdef TT_USE_BYTECODE_INTERPRETER
  179. face->root.face_flags |= FT_FACE_FLAG_HINTER;
  180. #endif
  181. /* If we are performing a simple font format check, exit immediately. */
  182. if ( face_index < 0 )
  183. return TT_Err_Ok;
  184. /* Load font directory */
  185. error = sfnt->load_face( stream, face, face_index, num_params, params );
  186. if ( error )
  187. goto Exit;
  188. error = tt_face_load_hdmx( face, stream );
  189. if ( error )
  190. goto Exit;
  191. if ( face->root.face_flags & FT_FACE_FLAG_SCALABLE )
  192. {
  193. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  194. if ( !face->root.internal->incremental_interface )
  195. error = tt_face_load_loca( face, stream );
  196. if ( !error )
  197. error = tt_face_load_cvt( face, stream );
  198. if ( !error )
  199. error = tt_face_load_fpgm( face, stream );
  200. if ( !error )
  201. error = tt_face_load_prep( face, stream );
  202. #else
  203. if ( !error )
  204. error = tt_face_load_loca( face, stream );
  205. if ( !error )
  206. error = tt_face_load_cvt( face, stream );
  207. if ( !error )
  208. error = tt_face_load_fpgm( face, stream );
  209. if ( !error )
  210. error = tt_face_load_prep( face, stream );
  211. #endif
  212. }
  213. #if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
  214. !defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
  215. {
  216. FT_Bool unpatented_hinting;
  217. int i;
  218. /* Determine whether unpatented hinting is to be used for this face. */
  219. unpatented_hinting = FT_BOOL
  220. ( library->debug_hooks[FT_DEBUG_HOOK_UNPATENTED_HINTING] != NULL );
  221. for ( i = 0; i < num_params && !face->unpatented_hinting; i++ )
  222. if ( params[i].tag == FT_PARAM_TAG_UNPATENTED_HINTING )
  223. unpatented_hinting = TRUE;
  224. /* Compare the face with a list of well-known `tricky' fonts. */
  225. /* This list shall be expanded as we find more of them. */
  226. if ( !unpatented_hinting )
  227. {
  228. static const char* const trick_names[] =
  229. {
  230. "DFKaiSho-SB", /* dfkaisb.ttf */
  231. "DFKai-SB", /* kaiu.ttf */
  232. "HuaTianSongTi?", /* htst3.ttf */
  233. "MingLiU", /* mingliu.ttf & mingliu.ttc */
  234. "PMingLiU", /* mingliu.ttc */
  235. "MingLi43", /* mingli.ttf */
  236. NULL
  237. };
  238. int nn;
  239. /* Note that we only check the face name at the moment; it might */
  240. /* be worth to do more checks for a few special cases. */
  241. for ( nn = 0; trick_names[nn] != NULL; nn++ )
  242. {
  243. if ( ttface->family_name &&
  244. ft_strstr( ttface->family_name, trick_names[nn] ) )
  245. {
  246. unpatented_hinting = 1;
  247. break;
  248. }
  249. }
  250. }
  251. ttface->internal->ignore_unpatented_hinter =
  252. FT_BOOL( !unpatented_hinting );
  253. }
  254. #endif /* TT_CONFIG_OPTION_UNPATENTED_HINTING &&
  255. !TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  256. /* initialize standard glyph loading routines */
  257. TT_Init_Glyph_Loading( face );
  258. Exit:
  259. return error;
  260. Bad_Format:
  261. error = TT_Err_Unknown_File_Format;
  262. goto Exit;
  263. }
  264. /*************************************************************************/
  265. /* */
  266. /* <Function> */
  267. /* tt_face_done */
  268. /* */
  269. /* <Description> */
  270. /* Finalize a given face object. */
  271. /* */
  272. /* <Input> */
  273. /* face :: A pointer to the face object to destroy. */
  274. /* */
  275. FT_LOCAL_DEF( void )
  276. tt_face_done( FT_Face ttface ) /* TT_Face */
  277. {
  278. TT_Face face = (TT_Face)ttface;
  279. FT_Memory memory = face->root.memory;
  280. FT_Stream stream = face->root.stream;
  281. SFNT_Service sfnt = (SFNT_Service)face->sfnt;
  282. /* for `extended TrueType formats' (i.e. compressed versions) */
  283. if ( face->extra.finalizer )
  284. face->extra.finalizer( face->extra.data );
  285. if ( sfnt )
  286. sfnt->done_face( face );
  287. /* freeing the locations table */
  288. tt_face_done_loca( face );
  289. tt_face_free_hdmx( face );
  290. /* freeing the CVT */
  291. FT_FREE( face->cvt );
  292. face->cvt_size = 0;
  293. /* freeing the programs */
  294. FT_FRAME_RELEASE( face->font_program );
  295. FT_FRAME_RELEASE( face->cvt_program );
  296. face->font_program_size = 0;
  297. face->cvt_program_size = 0;
  298. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  299. tt_done_blend( memory, face->blend );
  300. face->blend = NULL;
  301. #endif
  302. }
  303. /*************************************************************************/
  304. /* */
  305. /* SIZE FUNCTIONS */
  306. /* */
  307. /*************************************************************************/
  308. #ifdef TT_USE_BYTECODE_INTERPRETER
  309. /*************************************************************************/
  310. /* */
  311. /* <Function> */
  312. /* tt_size_run_fpgm */
  313. /* */
  314. /* <Description> */
  315. /* Run the font program. */
  316. /* */
  317. /* <Input> */
  318. /* size :: A handle to the size object. */
  319. /* */
  320. /* <Return> */
  321. /* FreeType error code. 0 means success. */
  322. /* */
  323. FT_LOCAL_DEF( FT_Error )
  324. tt_size_run_fpgm( TT_Size size )
  325. {
  326. TT_Face face = (TT_Face)size->root.face;
  327. TT_ExecContext exec;
  328. FT_Error error;
  329. /* debugging instances have their own context */
  330. if ( size->debug )
  331. exec = size->context;
  332. else
  333. exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
  334. if ( !exec )
  335. return TT_Err_Could_Not_Find_Context;
  336. TT_Load_Context( exec, face, size );
  337. exec->callTop = 0;
  338. exec->top = 0;
  339. exec->period = 64;
  340. exec->phase = 0;
  341. exec->threshold = 0;
  342. exec->instruction_trap = FALSE;
  343. exec->F_dot_P = 0x10000L;
  344. {
  345. FT_Size_Metrics* metrics = &exec->metrics;
  346. TT_Size_Metrics* tt_metrics = &exec->tt_metrics;
  347. metrics->x_ppem = 0;
  348. metrics->y_ppem = 0;
  349. metrics->x_scale = 0;
  350. metrics->y_scale = 0;
  351. tt_metrics->ppem = 0;
  352. tt_metrics->scale = 0;
  353. tt_metrics->ratio = 0x10000L;
  354. }
  355. /* allow font program execution */
  356. TT_Set_CodeRange( exec,
  357. tt_coderange_font,
  358. face->font_program,
  359. face->font_program_size );
  360. /* disable CVT and glyph programs coderange */
  361. TT_Clear_CodeRange( exec, tt_coderange_cvt );
  362. TT_Clear_CodeRange( exec, tt_coderange_glyph );
  363. if ( face->font_program_size > 0 )
  364. {
  365. error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
  366. if ( !error )
  367. error = face->interpreter( exec );
  368. }
  369. else
  370. error = TT_Err_Ok;
  371. if ( !error )
  372. TT_Save_Context( exec, size );
  373. return error;
  374. }
  375. /*************************************************************************/
  376. /* */
  377. /* <Function> */
  378. /* tt_size_run_prep */
  379. /* */
  380. /* <Description> */
  381. /* Run the control value program. */
  382. /* */
  383. /* <Input> */
  384. /* size :: A handle to the size object. */
  385. /* */
  386. /* <Return> */
  387. /* FreeType error code. 0 means success. */
  388. /* */
  389. FT_LOCAL_DEF( FT_Error )
  390. tt_size_run_prep( TT_Size size )
  391. {
  392. TT_Face face = (TT_Face)size->root.face;
  393. TT_ExecContext exec;
  394. FT_Error error;
  395. /* debugging instances have their own context */
  396. if ( size->debug )
  397. exec = size->context;
  398. else
  399. exec = ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
  400. if ( !exec )
  401. return TT_Err_Could_Not_Find_Context;
  402. TT_Load_Context( exec, face, size );
  403. exec->callTop = 0;
  404. exec->top = 0;
  405. exec->instruction_trap = FALSE;
  406. TT_Set_CodeRange( exec,
  407. tt_coderange_cvt,
  408. face->cvt_program,
  409. face->cvt_program_size );
  410. TT_Clear_CodeRange( exec, tt_coderange_glyph );
  411. if ( face->cvt_program_size > 0 )
  412. {
  413. error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
  414. if ( !error && !size->debug )
  415. error = face->interpreter( exec );
  416. }
  417. else
  418. error = TT_Err_Ok;
  419. /* save as default graphics state */
  420. size->GS = exec->GS;
  421. TT_Save_Context( exec, size );
  422. return error;
  423. }
  424. #endif /* TT_USE_BYTECODE_INTERPRETER */
  425. #ifdef TT_USE_BYTECODE_INTERPRETER
  426. static void
  427. tt_size_done_bytecode( FT_Size ftsize )
  428. {
  429. TT_Size size = (TT_Size)ftsize;
  430. TT_Face face = (TT_Face)ftsize->face;
  431. FT_Memory memory = face->root.memory;
  432. if ( size->debug )
  433. {
  434. /* the debug context must be deleted by the debugger itself */
  435. size->context = NULL;
  436. size->debug = FALSE;
  437. }
  438. FT_FREE( size->cvt );
  439. size->cvt_size = 0;
  440. /* free storage area */
  441. FT_FREE( size->storage );
  442. size->storage_size = 0;
  443. /* twilight zone */
  444. tt_glyphzone_done( &size->twilight );
  445. FT_FREE( size->function_defs );
  446. FT_FREE( size->instruction_defs );
  447. size->num_function_defs = 0;
  448. size->max_function_defs = 0;
  449. size->num_instruction_defs = 0;
  450. size->max_instruction_defs = 0;
  451. size->max_func = 0;
  452. size->max_ins = 0;
  453. size->bytecode_ready = 0;
  454. size->cvt_ready = 0;
  455. }
  456. /* Initialize bytecode-related fields in the size object. */
  457. /* We do this only if bytecode interpretation is really needed. */
  458. static FT_Error
  459. tt_size_init_bytecode( FT_Size ftsize )
  460. {
  461. FT_Error error;
  462. TT_Size size = (TT_Size)ftsize;
  463. TT_Face face = (TT_Face)ftsize->face;
  464. FT_Memory memory = face->root.memory;
  465. FT_Int i;
  466. FT_UShort n_twilight;
  467. TT_MaxProfile* maxp = &face->max_profile;
  468. size->bytecode_ready = 1;
  469. size->cvt_ready = 0;
  470. size->max_function_defs = maxp->maxFunctionDefs;
  471. size->max_instruction_defs = maxp->maxInstructionDefs;
  472. size->num_function_defs = 0;
  473. size->num_instruction_defs = 0;
  474. size->max_func = 0;
  475. size->max_ins = 0;
  476. size->cvt_size = face->cvt_size;
  477. size->storage_size = maxp->maxStorage;
  478. /* Set default metrics */
  479. {
  480. FT_Size_Metrics* metrics = &size->metrics;
  481. TT_Size_Metrics* metrics2 = &size->ttmetrics;
  482. metrics->x_ppem = 0;
  483. metrics->y_ppem = 0;
  484. metrics2->rotated = FALSE;
  485. metrics2->stretched = FALSE;
  486. /* set default compensation (all 0) */
  487. for ( i = 0; i < 4; i++ )
  488. metrics2->compensations[i] = 0;
  489. }
  490. /* allocate function defs, instruction defs, cvt, and storage area */
  491. if ( FT_NEW_ARRAY( size->function_defs, size->max_function_defs ) ||
  492. FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
  493. FT_NEW_ARRAY( size->cvt, size->cvt_size ) ||
  494. FT_NEW_ARRAY( size->storage, size->storage_size ) )
  495. goto Exit;
  496. /* reserve twilight zone */
  497. n_twilight = maxp->maxTwilightPoints;
  498. /* there are 4 phantom points (do we need this?) */
  499. n_twilight += 4;
  500. error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
  501. if ( error )
  502. goto Exit;
  503. size->twilight.n_points = n_twilight;
  504. size->GS = tt_default_graphics_state;
  505. /* set `face->interpreter' according to the debug hook present */
  506. {
  507. FT_Library library = face->root.driver->root.library;
  508. face->interpreter = (TT_Interpreter)
  509. library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
  510. if ( !face->interpreter )
  511. face->interpreter = (TT_Interpreter)TT_RunIns;
  512. }
  513. /* Fine, now run the font program! */
  514. error = tt_size_run_fpgm( size );
  515. Exit:
  516. if ( error )
  517. tt_size_done_bytecode( ftsize );
  518. return error;
  519. }
  520. FT_LOCAL_DEF( FT_Error )
  521. tt_size_ready_bytecode( TT_Size size )
  522. {
  523. FT_Error error = TT_Err_Ok;
  524. if ( !size->bytecode_ready )
  525. {
  526. error = tt_size_init_bytecode( (FT_Size)size );
  527. if ( error )
  528. goto Exit;
  529. }
  530. /* rescale CVT when needed */
  531. if ( !size->cvt_ready )
  532. {
  533. FT_UInt i;
  534. TT_Face face = (TT_Face) size->root.face;
  535. /* Scale the cvt values to the new ppem. */
  536. /* We use by default the y ppem to scale the CVT. */
  537. for ( i = 0; i < size->cvt_size; i++ )
  538. size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  539. /* all twilight points are originally zero */
  540. for ( i = 0; i < (FT_UInt)size->twilight.n_points; i++ )
  541. {
  542. size->twilight.org[i].x = 0;
  543. size->twilight.org[i].y = 0;
  544. size->twilight.cur[i].x = 0;
  545. size->twilight.cur[i].y = 0;
  546. }
  547. /* clear storage area */
  548. for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
  549. size->storage[i] = 0;
  550. size->GS = tt_default_graphics_state;
  551. error = tt_size_run_prep( size );
  552. if ( !error )
  553. size->cvt_ready = 1;
  554. }
  555. Exit:
  556. return error;
  557. }
  558. #endif /* TT_USE_BYTECODE_INTERPRETER */
  559. /*************************************************************************/
  560. /* */
  561. /* <Function> */
  562. /* tt_size_init */
  563. /* */
  564. /* <Description> */
  565. /* Initialize a new TrueType size object. */
  566. /* */
  567. /* <InOut> */
  568. /* size :: A handle to the size object. */
  569. /* */
  570. /* <Return> */
  571. /* FreeType error code. 0 means success. */
  572. /* */
  573. FT_LOCAL_DEF( FT_Error )
  574. tt_size_init( FT_Size ttsize ) /* TT_Size */
  575. {
  576. TT_Size size = (TT_Size)ttsize;
  577. FT_Error error = TT_Err_Ok;
  578. #ifdef TT_USE_BYTECODE_INTERPRETER
  579. size->bytecode_ready = 0;
  580. size->cvt_ready = 0;
  581. #endif
  582. size->ttmetrics.valid = FALSE;
  583. size->strike_index = 0xFFFFFFFFUL;
  584. return error;
  585. }
  586. /*************************************************************************/
  587. /* */
  588. /* <Function> */
  589. /* tt_size_done */
  590. /* */
  591. /* <Description> */
  592. /* The TrueType size object finalizer. */
  593. /* */
  594. /* <Input> */
  595. /* size :: A handle to the target size object. */
  596. /* */
  597. FT_LOCAL_DEF( void )
  598. tt_size_done( FT_Size ttsize ) /* TT_Size */
  599. {
  600. TT_Size size = (TT_Size)ttsize;
  601. #ifdef TT_USE_BYTECODE_INTERPRETER
  602. if ( size->bytecode_ready )
  603. tt_size_done_bytecode( ttsize );
  604. #endif
  605. size->ttmetrics.valid = FALSE;
  606. }
  607. /*************************************************************************/
  608. /* */
  609. /* <Function> */
  610. /* tt_size_reset */
  611. /* */
  612. /* <Description> */
  613. /* Reset a TrueType size when resolutions and character dimensions */
  614. /* have been changed. */
  615. /* */
  616. /* <Input> */
  617. /* size :: A handle to the target size object. */
  618. /* */
  619. FT_LOCAL_DEF( FT_Error )
  620. tt_size_reset( TT_Size size )
  621. {
  622. TT_Face face;
  623. FT_Error error = TT_Err_Ok;
  624. FT_Size_Metrics* metrics;
  625. size->ttmetrics.valid = FALSE;
  626. face = (TT_Face)size->root.face;
  627. metrics = &size->metrics;
  628. /* copy the result from base layer */
  629. *metrics = size->root.metrics;
  630. if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
  631. return TT_Err_Invalid_PPem;
  632. /* This bit flag, if set, indicates that the ppems must be */
  633. /* rounded to integers. Nearly all TrueType fonts have this bit */
  634. /* set, as hinting won't work really well otherwise. */
  635. /* */
  636. if ( face->header.Flags & 8 )
  637. {
  638. metrics->x_scale = FT_DivFix( metrics->x_ppem << 6,
  639. face->root.units_per_EM );
  640. metrics->y_scale = FT_DivFix( metrics->y_ppem << 6,
  641. face->root.units_per_EM );
  642. metrics->ascender =
  643. FT_PIX_ROUND( FT_MulFix( face->root.ascender, metrics->y_scale ) );
  644. metrics->descender =
  645. FT_PIX_ROUND( FT_MulFix( face->root.descender, metrics->y_scale ) );
  646. metrics->height =
  647. FT_PIX_ROUND( FT_MulFix( face->root.height, metrics->y_scale ) );
  648. metrics->max_advance =
  649. FT_PIX_ROUND( FT_MulFix( face->root.max_advance_width,
  650. metrics->x_scale ) );
  651. }
  652. /* compute new transformation */
  653. if ( metrics->x_ppem >= metrics->y_ppem )
  654. {
  655. size->ttmetrics.scale = metrics->x_scale;
  656. size->ttmetrics.ppem = metrics->x_ppem;
  657. size->ttmetrics.x_ratio = 0x10000L;
  658. size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
  659. 0x10000L,
  660. metrics->x_ppem );
  661. }
  662. else
  663. {
  664. size->ttmetrics.scale = metrics->y_scale;
  665. size->ttmetrics.ppem = metrics->y_ppem;
  666. size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
  667. 0x10000L,
  668. metrics->y_ppem );
  669. size->ttmetrics.y_ratio = 0x10000L;
  670. }
  671. #ifdef TT_USE_BYTECODE_INTERPRETER
  672. size->cvt_ready = 0;
  673. #endif /* TT_USE_BYTECODE_INTERPRETER */
  674. if ( !error )
  675. size->ttmetrics.valid = TRUE;
  676. return error;
  677. }
  678. /*************************************************************************/
  679. /* */
  680. /* <Function> */
  681. /* tt_driver_init */
  682. /* */
  683. /* <Description> */
  684. /* Initialize a given TrueType driver object. */
  685. /* */
  686. /* <Input> */
  687. /* driver :: A handle to the target driver object. */
  688. /* */
  689. /* <Return> */
  690. /* FreeType error code. 0 means success. */
  691. /* */
  692. FT_LOCAL_DEF( FT_Error )
  693. tt_driver_init( FT_Module ttdriver ) /* TT_Driver */
  694. {
  695. #ifdef TT_USE_BYTECODE_INTERPRETER
  696. TT_Driver driver = (TT_Driver)ttdriver;
  697. if ( !TT_New_Context( driver ) )
  698. return TT_Err_Could_Not_Find_Context;
  699. #else
  700. FT_UNUSED( ttdriver );
  701. #endif
  702. return TT_Err_Ok;
  703. }
  704. /*************************************************************************/
  705. /* */
  706. /* <Function> */
  707. /* tt_driver_done */
  708. /* */
  709. /* <Description> */
  710. /* Finalize a given TrueType driver. */
  711. /* */
  712. /* <Input> */
  713. /* driver :: A handle to the target TrueType driver. */
  714. /* */
  715. FT_LOCAL_DEF( void )
  716. tt_driver_done( FT_Module ttdriver ) /* TT_Driver */
  717. {
  718. #ifdef TT_USE_BYTECODE_INTERPRETER
  719. TT_Driver driver = (TT_Driver)ttdriver;
  720. /* destroy the execution context */
  721. if ( driver->context )
  722. {
  723. TT_Done_Context( driver->context );
  724. driver->context = NULL;
  725. }
  726. #else
  727. FT_UNUSED( ttdriver );
  728. #endif
  729. }
  730. /*************************************************************************/
  731. /* */
  732. /* <Function> */
  733. /* tt_slot_init */
  734. /* */
  735. /* <Description> */
  736. /* Initialize a new slot object. */
  737. /* */
  738. /* <InOut> */
  739. /* slot :: A handle to the slot object. */
  740. /* */
  741. /* <Return> */
  742. /* FreeType error code. 0 means success. */
  743. /* */
  744. FT_LOCAL_DEF( FT_Error )
  745. tt_slot_init( FT_GlyphSlot slot )
  746. {
  747. return FT_GlyphLoader_CreateExtra( slot->internal->loader );
  748. }
  749. /* END */