ttobjs.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /***************************************************************************/
  2. /* */
  3. /* ttobjs.c */
  4. /* */
  5. /* Objects manager (body). */
  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 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 FT_INTERNAL_POSTSCRIPT_NAMES_H
  25. #include "ttgload.h"
  26. #include "ttpload.h"
  27. #include "tterrors.h"
  28. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  29. #include "ttinterp.h"
  30. #endif
  31. /*************************************************************************/
  32. /* */
  33. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  34. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  35. /* messages during execution. */
  36. /* */
  37. #undef FT_COMPONENT
  38. #define FT_COMPONENT trace_ttobjs
  39. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  40. /*************************************************************************/
  41. /* */
  42. /* GLYPH ZONE FUNCTIONS */
  43. /* */
  44. /*************************************************************************/
  45. /*************************************************************************/
  46. /* */
  47. /* <Function> */
  48. /* tt_glyphzone_done */
  49. /* */
  50. /* <Description> */
  51. /* Deallocates a glyph zone. */
  52. /* */
  53. /* <Input> */
  54. /* zone :: A pointer to the target glyph zone. */
  55. /* */
  56. FT_LOCAL_DEF( void )
  57. tt_glyphzone_done( TT_GlyphZone zone )
  58. {
  59. FT_Memory memory = zone->memory;
  60. FT_FREE( zone->contours );
  61. FT_FREE( zone->tags );
  62. FT_FREE( zone->cur );
  63. FT_FREE( zone->org );
  64. zone->max_points = zone->n_points = 0;
  65. zone->max_contours = zone->n_contours = 0;
  66. }
  67. /*************************************************************************/
  68. /* */
  69. /* <Function> */
  70. /* tt_glyphzone_new */
  71. /* */
  72. /* <Description> */
  73. /* Allocates a new glyph zone. */
  74. /* */
  75. /* <Input> */
  76. /* memory :: A handle to the current memory object. */
  77. /* */
  78. /* maxPoints :: The capacity of glyph zone in points. */
  79. /* */
  80. /* maxContours :: The capacity of glyph zone in contours. */
  81. /* */
  82. /* <Output> */
  83. /* zone :: A pointer to the target glyph zone record. */
  84. /* */
  85. /* <Return> */
  86. /* FreeType error code. 0 means success. */
  87. /* */
  88. FT_LOCAL_DEF( FT_Error )
  89. tt_glyphzone_new( FT_Memory memory,
  90. FT_UShort maxPoints,
  91. FT_Short maxContours,
  92. TT_GlyphZone zone )
  93. {
  94. FT_Error error;
  95. if ( maxPoints > 0 )
  96. maxPoints += 2;
  97. FT_MEM_ZERO( zone, sizeof ( *zone ) );
  98. zone->memory = memory;
  99. if ( FT_NEW_ARRAY( zone->org, maxPoints * 2 ) ||
  100. FT_NEW_ARRAY( zone->cur, maxPoints * 2 ) ||
  101. FT_NEW_ARRAY( zone->tags, maxPoints ) ||
  102. FT_NEW_ARRAY( zone->contours, maxContours ) )
  103. {
  104. tt_glyphzone_done( zone );
  105. }
  106. return error;
  107. }
  108. #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  109. /*************************************************************************/
  110. /* */
  111. /* <Function> */
  112. /* tt_face_init */
  113. /* */
  114. /* <Description> */
  115. /* Initializes a given TrueType face object. */
  116. /* */
  117. /* <Input> */
  118. /* stream :: The source font stream. */
  119. /* */
  120. /* face_index :: The index of the font face in the resource. */
  121. /* */
  122. /* num_params :: Number of additional generic parameters. Ignored. */
  123. /* */
  124. /* params :: Additional generic parameters. Ignored. */
  125. /* */
  126. /* <InOut> */
  127. /* face :: The newly built face object. */
  128. /* */
  129. /* <Return> */
  130. /* FreeType error code. 0 means success. */
  131. /* */
  132. FT_LOCAL_DEF( FT_Error )
  133. tt_face_init( FT_Stream stream,
  134. TT_Face face,
  135. FT_Int face_index,
  136. FT_Int num_params,
  137. FT_Parameter* params )
  138. {
  139. FT_Error error;
  140. FT_Library library;
  141. SFNT_Service sfnt;
  142. library = face->root.driver->root.library;
  143. sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
  144. if ( !sfnt )
  145. goto Bad_Format;
  146. /* create input stream from resource */
  147. if ( FT_STREAM_SEEK( 0 ) )
  148. goto Exit;
  149. /* check that we have a valid TrueType file */
  150. error = sfnt->init_face( stream, face, face_index, num_params, params );
  151. if ( error )
  152. goto Exit;
  153. /* We must also be able to accept Mac/GX fonts, as well as OT ones */
  154. if ( face->format_tag != 0x00010000L && /* MS fonts */
  155. face->format_tag != TTAG_true ) /* Mac fonts */
  156. {
  157. FT_TRACE2(( "[not a valid TTF font]\n" ));
  158. goto Bad_Format;
  159. }
  160. /* If we are performing a simple font format check, exit immediately */
  161. if ( face_index < 0 )
  162. return TT_Err_Ok;
  163. /* Load font directory */
  164. error = sfnt->load_face( stream, face, face_index, num_params, params );
  165. if ( error )
  166. goto Exit;
  167. if ( face->root.face_flags & FT_FACE_FLAG_SCALABLE )
  168. {
  169. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  170. if ( !face->root.internal->incremental_interface )
  171. error = tt_face_load_loca( face, stream );
  172. if ( !error )
  173. error = tt_face_load_cvt ( face, stream ) ||
  174. tt_face_load_fpgm ( face, stream );
  175. #else
  176. if ( !error )
  177. error = tt_face_load_loca( face, stream ) ||
  178. tt_face_load_cvt ( face, stream ) ||
  179. tt_face_load_fpgm ( face, stream );
  180. #endif
  181. }
  182. /* initialize standard glyph loading routines */
  183. TT_Init_Glyph_Loading( face );
  184. Exit:
  185. return error;
  186. Bad_Format:
  187. error = TT_Err_Unknown_File_Format;
  188. goto Exit;
  189. }
  190. /*************************************************************************/
  191. /* */
  192. /* <Function> */
  193. /* tt_face_done */
  194. /* */
  195. /* <Description> */
  196. /* Finalizes a given face object. */
  197. /* */
  198. /* <Input> */
  199. /* face :: A pointer to the face object to destroy. */
  200. /* */
  201. FT_LOCAL_DEF( void )
  202. tt_face_done( TT_Face face )
  203. {
  204. FT_Memory memory = face->root.memory;
  205. FT_Stream stream = face->root.stream;
  206. SFNT_Service sfnt = (SFNT_Service)face->sfnt;
  207. /* for `extended TrueType formats' (i.e. compressed versions) */
  208. if ( face->extra.finalizer )
  209. face->extra.finalizer( face->extra.data );
  210. if ( sfnt )
  211. sfnt->done_face( face );
  212. /* freeing the locations table */
  213. FT_FREE( face->glyph_locations );
  214. face->num_locations = 0;
  215. /* freeing the CVT */
  216. FT_FREE( face->cvt );
  217. face->cvt_size = 0;
  218. /* freeing the programs */
  219. FT_FRAME_RELEASE( face->font_program );
  220. FT_FRAME_RELEASE( face->cvt_program );
  221. face->font_program_size = 0;
  222. face->cvt_program_size = 0;
  223. }
  224. /*************************************************************************/
  225. /* */
  226. /* SIZE FUNCTIONS */
  227. /* */
  228. /*************************************************************************/
  229. /*************************************************************************/
  230. /* */
  231. /* <Function> */
  232. /* tt_size_init */
  233. /* */
  234. /* <Description> */
  235. /* Initializes a new TrueType size object. */
  236. /* */
  237. /* <InOut> */
  238. /* size :: A handle to the size object. */
  239. /* */
  240. /* <Return> */
  241. /* FreeType error code. 0 means success. */
  242. /* */
  243. FT_LOCAL_DEF( FT_Error )
  244. tt_size_init( TT_Size size )
  245. {
  246. FT_Error error = TT_Err_Ok;
  247. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  248. TT_Face face = (TT_Face)size->root.face;
  249. FT_Memory memory = face->root.memory;
  250. FT_Int i;
  251. TT_ExecContext exec;
  252. FT_UShort n_twilight;
  253. TT_MaxProfile* maxp = &face->max_profile;
  254. size->ttmetrics.valid = FALSE;
  255. size->max_function_defs = maxp->maxFunctionDefs;
  256. size->max_instruction_defs = maxp->maxInstructionDefs;
  257. size->num_function_defs = 0;
  258. size->num_instruction_defs = 0;
  259. size->max_func = 0;
  260. size->max_ins = 0;
  261. size->cvt_size = face->cvt_size;
  262. size->storage_size = maxp->maxStorage;
  263. /* Set default metrics */
  264. {
  265. FT_Size_Metrics* metrics = &size->root.metrics;
  266. TT_Size_Metrics* metrics2 = &size->ttmetrics;
  267. metrics->x_ppem = 0;
  268. metrics->y_ppem = 0;
  269. metrics2->rotated = FALSE;
  270. metrics2->stretched = FALSE;
  271. /* set default compensation (all 0) */
  272. for ( i = 0; i < 4; i++ )
  273. metrics2->compensations[i] = 0;
  274. }
  275. /* allocate function defs, instruction defs, cvt, and storage area */
  276. if ( FT_NEW_ARRAY( size->function_defs, size->max_function_defs ) ||
  277. FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
  278. FT_NEW_ARRAY( size->cvt, size->cvt_size ) ||
  279. FT_NEW_ARRAY( size->storage, size->storage_size ) )
  280. goto Fail_Memory;
  281. /* reserve twilight zone */
  282. n_twilight = maxp->maxTwilightPoints;
  283. error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
  284. if ( error )
  285. goto Fail_Memory;
  286. size->twilight.n_points = n_twilight;
  287. /* set `face->interpreter' according to the debug hook present */
  288. {
  289. FT_Library library = face->root.driver->root.library;
  290. face->interpreter = (TT_Interpreter)
  291. library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
  292. if ( !face->interpreter )
  293. face->interpreter = (TT_Interpreter)TT_RunIns;
  294. }
  295. /* Fine, now execute the font program! */
  296. exec = size->context;
  297. /* size objects used during debugging have their own context */
  298. if ( !size->debug )
  299. exec = TT_New_Context( face );
  300. if ( !exec )
  301. {
  302. error = TT_Err_Could_Not_Find_Context;
  303. goto Fail_Memory;
  304. }
  305. size->GS = tt_default_graphics_state;
  306. TT_Load_Context( exec, face, size );
  307. exec->callTop = 0;
  308. exec->top = 0;
  309. exec->period = 64;
  310. exec->phase = 0;
  311. exec->threshold = 0;
  312. {
  313. FT_Size_Metrics* metrics = &exec->metrics;
  314. TT_Size_Metrics* tt_metrics = &exec->tt_metrics;
  315. metrics->x_ppem = 0;
  316. metrics->y_ppem = 0;
  317. metrics->x_scale = 0;
  318. metrics->y_scale = 0;
  319. tt_metrics->ppem = 0;
  320. tt_metrics->scale = 0;
  321. tt_metrics->ratio = 0x10000L;
  322. }
  323. exec->instruction_trap = FALSE;
  324. exec->cvtSize = size->cvt_size;
  325. exec->cvt = size->cvt;
  326. exec->F_dot_P = 0x10000L;
  327. /* allow font program execution */
  328. TT_Set_CodeRange( exec,
  329. tt_coderange_font,
  330. face->font_program,
  331. face->font_program_size );
  332. /* disable CVT and glyph programs coderange */
  333. TT_Clear_CodeRange( exec, tt_coderange_cvt );
  334. TT_Clear_CodeRange( exec, tt_coderange_glyph );
  335. if ( face->font_program_size > 0 )
  336. {
  337. error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
  338. if ( !error )
  339. error = face->interpreter( exec );
  340. if ( error )
  341. goto Fail_Exec;
  342. }
  343. else
  344. error = TT_Err_Ok;
  345. TT_Save_Context( exec, size );
  346. if ( !size->debug )
  347. TT_Done_Context( exec );
  348. #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  349. size->ttmetrics.valid = FALSE;
  350. return error;
  351. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  352. Fail_Exec:
  353. if ( !size->debug )
  354. TT_Done_Context( exec );
  355. Fail_Memory:
  356. tt_size_done( size );
  357. return error;
  358. #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  359. }
  360. /*************************************************************************/
  361. /* */
  362. /* <Function> */
  363. /* tt_size_done */
  364. /* */
  365. /* <Description> */
  366. /* The TrueType size object finalizer. */
  367. /* */
  368. /* <Input> */
  369. /* size :: A handle to the target size object. */
  370. /* */
  371. FT_LOCAL_DEF( void )
  372. tt_size_done( TT_Size size )
  373. {
  374. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  375. FT_Memory memory = size->root.face->memory;
  376. if ( size->debug )
  377. {
  378. /* the debug context must be deleted by the debugger itself */
  379. size->context = NULL;
  380. size->debug = FALSE;
  381. }
  382. FT_FREE( size->cvt );
  383. size->cvt_size = 0;
  384. /* free storage area */
  385. FT_FREE( size->storage );
  386. size->storage_size = 0;
  387. /* twilight zone */
  388. tt_glyphzone_done( &size->twilight );
  389. FT_FREE( size->function_defs );
  390. FT_FREE( size->instruction_defs );
  391. size->num_function_defs = 0;
  392. size->max_function_defs = 0;
  393. size->num_instruction_defs = 0;
  394. size->max_instruction_defs = 0;
  395. size->max_func = 0;
  396. size->max_ins = 0;
  397. #endif
  398. size->ttmetrics.valid = FALSE;
  399. }
  400. /*************************************************************************/
  401. /* */
  402. /* <Function> */
  403. /* Reset_Outline_Size */
  404. /* */
  405. /* <Description> */
  406. /* Resets a TrueType outline size when resolutions and character */
  407. /* dimensions have been changed. */
  408. /* */
  409. /* <Input> */
  410. /* size :: A handle to the target size object. */
  411. /* */
  412. static FT_Error
  413. Reset_Outline_Size( TT_Size size )
  414. {
  415. TT_Face face;
  416. FT_Error error = TT_Err_Ok;
  417. FT_Size_Metrics* metrics;
  418. if ( size->ttmetrics.valid )
  419. return TT_Err_Ok;
  420. face = (TT_Face)size->root.face;
  421. metrics = &size->root.metrics;
  422. if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
  423. return TT_Err_Invalid_PPem;
  424. /* compute new transformation */
  425. if ( metrics->x_ppem >= metrics->y_ppem )
  426. {
  427. size->ttmetrics.scale = metrics->x_scale;
  428. size->ttmetrics.ppem = metrics->x_ppem;
  429. size->ttmetrics.x_ratio = 0x10000L;
  430. size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
  431. 0x10000L,
  432. metrics->x_ppem );
  433. }
  434. else
  435. {
  436. size->ttmetrics.scale = metrics->y_scale;
  437. size->ttmetrics.ppem = metrics->y_ppem;
  438. size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
  439. 0x10000L,
  440. metrics->y_ppem );
  441. size->ttmetrics.y_ratio = 0x10000L;
  442. }
  443. /* Compute root ascender, descender, test height, and max_advance */
  444. metrics->ascender = ( FT_MulFix( face->root.ascender,
  445. metrics->y_scale ) + 32 ) & -64;
  446. metrics->descender = ( FT_MulFix( face->root.descender,
  447. metrics->y_scale ) + 32 ) & -64;
  448. metrics->height = ( FT_MulFix( face->root.height,
  449. metrics->y_scale ) + 32 ) & -64;
  450. metrics->max_advance = ( FT_MulFix( face->root.max_advance_width,
  451. metrics->x_scale ) + 32 ) & -64;
  452. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  453. /* set to `invalid' by default */
  454. size->strike_index = 0xFFFFU;
  455. #endif
  456. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  457. {
  458. TT_ExecContext exec;
  459. FT_UInt i, j;
  460. /* Scale the cvt values to the new ppem. */
  461. /* We use by default the y ppem to scale the CVT. */
  462. for ( i = 0; i < size->cvt_size; i++ )
  463. size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  464. /* All twilight points are originally zero */
  465. for ( j = 0; j < (FT_UInt)size->twilight.n_points; j++ )
  466. {
  467. size->twilight.org[j].x = 0;
  468. size->twilight.org[j].y = 0;
  469. size->twilight.cur[j].x = 0;
  470. size->twilight.cur[j].y = 0;
  471. }
  472. /* clear storage area */
  473. for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
  474. size->storage[i] = 0;
  475. size->GS = tt_default_graphics_state;
  476. /* get execution context and run prep program */
  477. if ( size->debug )
  478. exec = size->context;
  479. else
  480. exec = TT_New_Context( face );
  481. /* debugging instances have their own context */
  482. if ( !exec )
  483. return TT_Err_Could_Not_Find_Context;
  484. TT_Load_Context( exec, face, size );
  485. TT_Set_CodeRange( exec,
  486. tt_coderange_cvt,
  487. face->cvt_program,
  488. face->cvt_program_size );
  489. TT_Clear_CodeRange( exec, tt_coderange_glyph );
  490. exec->instruction_trap = FALSE;
  491. exec->top = 0;
  492. exec->callTop = 0;
  493. if ( face->cvt_program_size > 0 )
  494. {
  495. error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
  496. if ( error )
  497. goto End;
  498. if ( !size->debug )
  499. error = face->interpreter( exec );
  500. }
  501. else
  502. error = TT_Err_Ok;
  503. size->GS = exec->GS;
  504. /* save default graphics state */
  505. End:
  506. TT_Save_Context( exec, size );
  507. if ( !size->debug )
  508. TT_Done_Context( exec );
  509. /* debugging instances keep their context */
  510. }
  511. #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
  512. if ( !error )
  513. size->ttmetrics.valid = TRUE;
  514. return error;
  515. }
  516. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  517. /*************************************************************************/
  518. /* */
  519. /* <Function> */
  520. /* Reset_SBit_Size */
  521. /* */
  522. /* <Description> */
  523. /* Resets a TrueType sbit size when resolutions and character */
  524. /* dimensions have been changed. */
  525. /* */
  526. /* <Input> */
  527. /* size :: A handle to the target size object. */
  528. /* */
  529. static FT_Error
  530. Reset_SBit_Size( TT_Size size )
  531. {
  532. TT_Face face;
  533. FT_Error error = TT_Err_Ok;
  534. FT_ULong strike_index;
  535. FT_Size_Metrics* metrics;
  536. FT_Size_Metrics* sbit_metrics;
  537. SFNT_Service sfnt;
  538. metrics = &size->root.metrics;
  539. if ( size->strike_index != 0xFFFFU )
  540. return TT_Err_Ok;
  541. face = (TT_Face)size->root.face;
  542. sfnt = (SFNT_Service)face->sfnt;
  543. sbit_metrics = &size->strike_metrics;
  544. error = sfnt->set_sbit_strike(face,
  545. metrics->x_ppem, metrics->y_ppem,
  546. &strike_index);
  547. if ( !error )
  548. {
  549. TT_SBit_Strike strike = face->sbit_strikes + strike_index;
  550. sbit_metrics->x_ppem = metrics->x_ppem;
  551. sbit_metrics->y_ppem = metrics->y_ppem;
  552. #if 0
  553. /*
  554. * sbit_metrics->?_scale
  555. * are not used now.
  556. */
  557. sbit_metrics->x_scale = 1 << 16;
  558. sbit_metrics->y_scale = 1 << 16;
  559. #endif
  560. sbit_metrics->ascender = strike->hori.ascender << 6;
  561. sbit_metrics->descender = strike->hori.descender << 6;
  562. /* XXX: Is this correct? */
  563. sbit_metrics->height = sbit_metrics->ascender -
  564. sbit_metrics->descender;
  565. /* XXX: Is this correct? */
  566. sbit_metrics->max_advance = ( strike->hori.min_origin_SB +
  567. strike->hori.max_width +
  568. strike->hori.min_advance_SB ) << 6;
  569. size->strike_index = strike_index;
  570. }
  571. else
  572. {
  573. size->strike_index = 0xFFFFU;
  574. sbit_metrics->x_ppem = 0;
  575. sbit_metrics->y_ppem = 0;
  576. sbit_metrics->ascender = 0;
  577. sbit_metrics->descender = 0;
  578. sbit_metrics->height = 0;
  579. sbit_metrics->max_advance = 0;
  580. }
  581. return error;
  582. }
  583. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  584. /*************************************************************************/
  585. /* */
  586. /* <Function> */
  587. /* tt_size_reset */
  588. /* */
  589. /* <Description> */
  590. /* Resets a TrueType size when resolutions and character dimensions */
  591. /* have been changed. */
  592. /* */
  593. /* <Input> */
  594. /* size :: A handle to the target size object. */
  595. /* */
  596. FT_LOCAL_DEF( FT_Error )
  597. tt_size_reset( TT_Size size )
  598. {
  599. FT_Face face;
  600. FT_Error error = TT_Err_Ok;
  601. face = size->root.face;
  602. if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
  603. {
  604. if ( !size->ttmetrics.valid )
  605. error = Reset_Outline_Size( size );
  606. if ( error )
  607. return error;
  608. }
  609. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  610. if ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES )
  611. {
  612. if ( size->strike_index == 0xFFFFU )
  613. error = Reset_SBit_Size( size );
  614. if ( !error && !( face->face_flags & FT_FACE_FLAG_SCALABLE ) )
  615. size->root.metrics = size->strike_metrics;
  616. }
  617. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  618. if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
  619. return TT_Err_Ok;
  620. else
  621. return error;
  622. }
  623. /*************************************************************************/
  624. /* */
  625. /* <Function> */
  626. /* tt_driver_init */
  627. /* */
  628. /* <Description> */
  629. /* Initializes a given TrueType driver object. */
  630. /* */
  631. /* <Input> */
  632. /* driver :: A handle to the target driver object. */
  633. /* */
  634. /* <Return> */
  635. /* FreeType error code. 0 means success. */
  636. /* */
  637. FT_LOCAL_DEF( FT_Error )
  638. tt_driver_init( TT_Driver driver )
  639. {
  640. FT_Error error;
  641. /* set `extra' in glyph loader */
  642. error = FT_GlyphLoader_CreateExtra( FT_DRIVER( driver )->glyph_loader );
  643. return error;
  644. }
  645. /*************************************************************************/
  646. /* */
  647. /* <Function> */
  648. /* tt_driver_done */
  649. /* */
  650. /* <Description> */
  651. /* Finalizes a given TrueType driver. */
  652. /* */
  653. /* <Input> */
  654. /* driver :: A handle to the target TrueType driver. */
  655. /* */
  656. FT_LOCAL_DEF( void )
  657. tt_driver_done( TT_Driver driver )
  658. {
  659. #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  660. /* destroy the execution context */
  661. if ( driver->context )
  662. {
  663. TT_Destroy_Context( driver->context, driver->root.root.memory );
  664. driver->context = NULL;
  665. }
  666. #else
  667. FT_UNUSED( driver );
  668. #endif
  669. }
  670. /* END */