/src/compiler/android-ndk/jni/freetype/src/truetype/ttobjs.c

http://ftk.googlecode.com/ · C · 951 lines · 501 code · 200 blank · 250 comment · 68 complexity · ddc0be9cf84a2a87309c79c95b1ca391 MD5 · raw file

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