PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/freetype/src/truetype/ttgload.c

https://bitbucket.org/cabalistic/ogredeps/
C | 2111 lines | 1358 code | 461 blank | 292 comment | 210 complexity | f5fa5e79435f791255d61acf451d5d32 MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, CPL-1.0, Unlicense, GPL-2.0, GPL-3.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, BSD-2-Clause, LGPL-2.1
  1. /***************************************************************************/
  2. /* */
  3. /* ttgload.c */
  4. /* */
  5. /* TrueType Glyph Loader (body). */
  6. /* */
  7. /* Copyright 1996-2012 */
  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_INTERNAL_SFNT_H
  22. #include FT_TRUETYPE_TAGS_H
  23. #include FT_OUTLINE_H
  24. #include "ttgload.h"
  25. #include "ttpload.h"
  26. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  27. #include "ttgxvar.h"
  28. #endif
  29. #include "tterrors.h"
  30. /*************************************************************************/
  31. /* */
  32. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  33. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  34. /* messages during execution. */
  35. /* */
  36. #undef FT_COMPONENT
  37. #define FT_COMPONENT trace_ttgload
  38. /*************************************************************************/
  39. /* */
  40. /* Composite glyph flags. */
  41. /* */
  42. #define ARGS_ARE_WORDS 0x0001
  43. #define ARGS_ARE_XY_VALUES 0x0002
  44. #define ROUND_XY_TO_GRID 0x0004
  45. #define WE_HAVE_A_SCALE 0x0008
  46. /* reserved 0x0010 */
  47. #define MORE_COMPONENTS 0x0020
  48. #define WE_HAVE_AN_XY_SCALE 0x0040
  49. #define WE_HAVE_A_2X2 0x0080
  50. #define WE_HAVE_INSTR 0x0100
  51. #define USE_MY_METRICS 0x0200
  52. #define OVERLAP_COMPOUND 0x0400
  53. #define SCALED_COMPONENT_OFFSET 0x0800
  54. #define UNSCALED_COMPONENT_OFFSET 0x1000
  55. /*************************************************************************/
  56. /* */
  57. /* Return the horizontal metrics in font units for a given glyph. */
  58. /* */
  59. FT_LOCAL_DEF( void )
  60. TT_Get_HMetrics( TT_Face face,
  61. FT_UInt idx,
  62. FT_Short* lsb,
  63. FT_UShort* aw )
  64. {
  65. ( (SFNT_Service)face->sfnt )->get_metrics( face, 0, idx, lsb, aw );
  66. FT_TRACE5(( " advance width (font units): %d\n", *aw ));
  67. FT_TRACE5(( " left side bearing (font units): %d\n", *lsb ));
  68. }
  69. /*************************************************************************/
  70. /* */
  71. /* Return the vertical metrics in font units for a given glyph. */
  72. /* Greg Hitchcock from Microsoft told us that if there were no `vmtx' */
  73. /* table, typoAscender/Descender from the `OS/2' table would be used */
  74. /* instead, and if there were no `OS/2' table, use ascender/descender */
  75. /* from the `hhea' table. But that is not what Microsoft's rasterizer */
  76. /* apparently does: It uses the ppem value as the advance height, and */
  77. /* sets the top side bearing to be zero. */
  78. /* */
  79. FT_LOCAL_DEF( void )
  80. TT_Get_VMetrics( TT_Face face,
  81. FT_UInt idx,
  82. FT_Short* tsb,
  83. FT_UShort* ah )
  84. {
  85. if ( face->vertical_info )
  86. ( (SFNT_Service)face->sfnt )->get_metrics( face, 1, idx, tsb, ah );
  87. #if 1 /* Empirically determined, at variance with what MS said */
  88. else
  89. {
  90. *tsb = 0;
  91. *ah = face->root.units_per_EM;
  92. }
  93. #else /* This is what MS said to do. It isn't what they do, however. */
  94. else if ( face->os2.version != 0xFFFFU )
  95. {
  96. *tsb = face->os2.sTypoAscender;
  97. *ah = face->os2.sTypoAscender - face->os2.sTypoDescender;
  98. }
  99. else
  100. {
  101. *tsb = face->horizontal.Ascender;
  102. *ah = face->horizontal.Ascender - face->horizontal.Descender;
  103. }
  104. #endif
  105. FT_TRACE5(( " advance height (font units): %d\n", *ah ));
  106. FT_TRACE5(( " top side bearing (font units): %d\n", *tsb ));
  107. }
  108. static void
  109. tt_get_metrics( TT_Loader loader,
  110. FT_UInt glyph_index )
  111. {
  112. TT_Face face = (TT_Face)loader->face;
  113. FT_Short left_bearing = 0, top_bearing = 0;
  114. FT_UShort advance_width = 0, advance_height = 0;
  115. TT_Get_HMetrics( face, glyph_index,
  116. &left_bearing,
  117. &advance_width );
  118. TT_Get_VMetrics( face, glyph_index,
  119. &top_bearing,
  120. &advance_height );
  121. loader->left_bearing = left_bearing;
  122. loader->advance = advance_width;
  123. loader->top_bearing = top_bearing;
  124. loader->vadvance = advance_height;
  125. if ( !loader->linear_def )
  126. {
  127. loader->linear_def = 1;
  128. loader->linear = advance_width;
  129. }
  130. }
  131. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  132. static void
  133. tt_get_metrics_incr_overrides( TT_Loader loader,
  134. FT_UInt glyph_index )
  135. {
  136. TT_Face face = (TT_Face)loader->face;
  137. FT_Short left_bearing = 0, top_bearing = 0;
  138. FT_UShort advance_width = 0, advance_height = 0;
  139. /* If this is an incrementally loaded font check whether there are */
  140. /* overriding metrics for this glyph. */
  141. if ( face->root.internal->incremental_interface &&
  142. face->root.internal->incremental_interface->funcs->get_glyph_metrics )
  143. {
  144. FT_Incremental_MetricsRec metrics;
  145. FT_Error error;
  146. metrics.bearing_x = loader->left_bearing;
  147. metrics.bearing_y = 0;
  148. metrics.advance = loader->advance;
  149. metrics.advance_v = 0;
  150. error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
  151. face->root.internal->incremental_interface->object,
  152. glyph_index, FALSE, &metrics );
  153. if ( error )
  154. goto Exit;
  155. left_bearing = (FT_Short)metrics.bearing_x;
  156. advance_width = (FT_UShort)metrics.advance;
  157. #if 0
  158. /* GWW: Do I do the same for vertical metrics? */
  159. metrics.bearing_x = 0;
  160. metrics.bearing_y = loader->top_bearing;
  161. metrics.advance = loader->vadvance;
  162. error = face->root.internal->incremental_interface->funcs->get_glyph_metrics(
  163. face->root.internal->incremental_interface->object,
  164. glyph_index, TRUE, &metrics );
  165. if ( error )
  166. goto Exit;
  167. top_bearing = (FT_Short)metrics.bearing_y;
  168. advance_height = (FT_UShort)metrics.advance;
  169. #endif /* 0 */
  170. loader->left_bearing = left_bearing;
  171. loader->advance = advance_width;
  172. loader->top_bearing = top_bearing;
  173. loader->vadvance = advance_height;
  174. if ( !loader->linear_def )
  175. {
  176. loader->linear_def = 1;
  177. loader->linear = advance_width;
  178. }
  179. }
  180. Exit:
  181. return;
  182. }
  183. #endif /* FT_CONFIG_OPTION_INCREMENTAL */
  184. /*************************************************************************/
  185. /* */
  186. /* Translates an array of coordinates. */
  187. /* */
  188. static void
  189. translate_array( FT_UInt n,
  190. FT_Vector* coords,
  191. FT_Pos delta_x,
  192. FT_Pos delta_y )
  193. {
  194. FT_UInt k;
  195. if ( delta_x )
  196. for ( k = 0; k < n; k++ )
  197. coords[k].x += delta_x;
  198. if ( delta_y )
  199. for ( k = 0; k < n; k++ )
  200. coords[k].y += delta_y;
  201. }
  202. #undef IS_HINTED
  203. #define IS_HINTED( flags ) ( ( flags & FT_LOAD_NO_HINTING ) == 0 )
  204. /*************************************************************************/
  205. /* */
  206. /* The following functions are used by default with TrueType fonts. */
  207. /* However, they can be replaced by alternatives if we need to support */
  208. /* TrueType-compressed formats (like MicroType) in the future. */
  209. /* */
  210. /*************************************************************************/
  211. FT_CALLBACK_DEF( FT_Error )
  212. TT_Access_Glyph_Frame( TT_Loader loader,
  213. FT_UInt glyph_index,
  214. FT_ULong offset,
  215. FT_UInt byte_count )
  216. {
  217. FT_Error error;
  218. FT_Stream stream = loader->stream;
  219. /* for non-debug mode */
  220. FT_UNUSED( glyph_index );
  221. FT_TRACE4(( "Glyph %ld\n", glyph_index ));
  222. /* the following line sets the `error' variable through macros! */
  223. if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( byte_count ) )
  224. return error;
  225. loader->cursor = stream->cursor;
  226. loader->limit = stream->limit;
  227. return TT_Err_Ok;
  228. }
  229. FT_CALLBACK_DEF( void )
  230. TT_Forget_Glyph_Frame( TT_Loader loader )
  231. {
  232. FT_Stream stream = loader->stream;
  233. FT_FRAME_EXIT();
  234. }
  235. FT_CALLBACK_DEF( FT_Error )
  236. TT_Load_Glyph_Header( TT_Loader loader )
  237. {
  238. FT_Byte* p = loader->cursor;
  239. FT_Byte* limit = loader->limit;
  240. if ( p + 10 > limit )
  241. return TT_Err_Invalid_Outline;
  242. loader->n_contours = FT_NEXT_SHORT( p );
  243. loader->bbox.xMin = FT_NEXT_SHORT( p );
  244. loader->bbox.yMin = FT_NEXT_SHORT( p );
  245. loader->bbox.xMax = FT_NEXT_SHORT( p );
  246. loader->bbox.yMax = FT_NEXT_SHORT( p );
  247. FT_TRACE5(( " # of contours: %d\n", loader->n_contours ));
  248. FT_TRACE5(( " xMin: %4d xMax: %4d\n", loader->bbox.xMin,
  249. loader->bbox.xMax ));
  250. FT_TRACE5(( " yMin: %4d yMax: %4d\n", loader->bbox.yMin,
  251. loader->bbox.yMax ));
  252. loader->cursor = p;
  253. return TT_Err_Ok;
  254. }
  255. FT_CALLBACK_DEF( FT_Error )
  256. TT_Load_Simple_Glyph( TT_Loader load )
  257. {
  258. FT_Error error;
  259. FT_Byte* p = load->cursor;
  260. FT_Byte* limit = load->limit;
  261. FT_GlyphLoader gloader = load->gloader;
  262. FT_Int n_contours = load->n_contours;
  263. FT_Outline* outline;
  264. TT_Face face = (TT_Face)load->face;
  265. FT_UShort n_ins;
  266. FT_Int n_points;
  267. FT_Byte *flag, *flag_limit;
  268. FT_Byte c, count;
  269. FT_Vector *vec, *vec_limit;
  270. FT_Pos x;
  271. FT_Short *cont, *cont_limit, prev_cont;
  272. FT_Int xy_size = 0;
  273. /* check that we can add the contours to the glyph */
  274. error = FT_GLYPHLOADER_CHECK_POINTS( gloader, 0, n_contours );
  275. if ( error )
  276. goto Fail;
  277. /* reading the contours' endpoints & number of points */
  278. cont = gloader->current.outline.contours;
  279. cont_limit = cont + n_contours;
  280. /* check space for contours array + instructions count */
  281. if ( n_contours >= 0xFFF || p + ( n_contours + 1 ) * 2 > limit )
  282. goto Invalid_Outline;
  283. prev_cont = FT_NEXT_SHORT( p );
  284. if ( n_contours > 0 )
  285. cont[0] = prev_cont;
  286. if ( prev_cont < 0 )
  287. goto Invalid_Outline;
  288. for ( cont++; cont < cont_limit; cont++ )
  289. {
  290. cont[0] = FT_NEXT_SHORT( p );
  291. if ( cont[0] <= prev_cont )
  292. {
  293. /* unordered contours: this is invalid */
  294. goto Invalid_Outline;
  295. }
  296. prev_cont = cont[0];
  297. }
  298. n_points = 0;
  299. if ( n_contours > 0 )
  300. {
  301. n_points = cont[-1] + 1;
  302. if ( n_points < 0 )
  303. goto Invalid_Outline;
  304. }
  305. /* note that we will add four phantom points later */
  306. error = FT_GLYPHLOADER_CHECK_POINTS( gloader, n_points + 4, 0 );
  307. if ( error )
  308. goto Fail;
  309. /* reading the bytecode instructions */
  310. load->glyph->control_len = 0;
  311. load->glyph->control_data = 0;
  312. if ( p + 2 > limit )
  313. goto Invalid_Outline;
  314. n_ins = FT_NEXT_USHORT( p );
  315. FT_TRACE5(( " Instructions size: %u\n", n_ins ));
  316. if ( n_ins > face->max_profile.maxSizeOfInstructions )
  317. {
  318. FT_TRACE0(( "TT_Load_Simple_Glyph: too many instructions (%d)\n",
  319. n_ins ));
  320. error = TT_Err_Too_Many_Hints;
  321. goto Fail;
  322. }
  323. if ( ( limit - p ) < n_ins )
  324. {
  325. FT_TRACE0(( "TT_Load_Simple_Glyph: instruction count mismatch\n" ));
  326. error = TT_Err_Too_Many_Hints;
  327. goto Fail;
  328. }
  329. #ifdef TT_USE_BYTECODE_INTERPRETER
  330. if ( IS_HINTED( load->load_flags ) )
  331. {
  332. load->glyph->control_len = n_ins;
  333. load->glyph->control_data = load->exec->glyphIns;
  334. FT_MEM_COPY( load->exec->glyphIns, p, (FT_Long)n_ins );
  335. }
  336. #endif /* TT_USE_BYTECODE_INTERPRETER */
  337. p += n_ins;
  338. outline = &gloader->current.outline;
  339. /* reading the point tags */
  340. flag = (FT_Byte*)outline->tags;
  341. flag_limit = flag + n_points;
  342. FT_ASSERT( flag != NULL );
  343. while ( flag < flag_limit )
  344. {
  345. if ( p + 1 > limit )
  346. goto Invalid_Outline;
  347. *flag++ = c = FT_NEXT_BYTE( p );
  348. if ( c & 8 )
  349. {
  350. if ( p + 1 > limit )
  351. goto Invalid_Outline;
  352. count = FT_NEXT_BYTE( p );
  353. if ( flag + (FT_Int)count > flag_limit )
  354. goto Invalid_Outline;
  355. for ( ; count > 0; count-- )
  356. *flag++ = c;
  357. }
  358. }
  359. /* reading the X coordinates */
  360. vec = outline->points;
  361. vec_limit = vec + n_points;
  362. flag = (FT_Byte*)outline->tags;
  363. x = 0;
  364. if ( p + xy_size > limit )
  365. goto Invalid_Outline;
  366. for ( ; vec < vec_limit; vec++, flag++ )
  367. {
  368. FT_Pos y = 0;
  369. FT_Byte f = *flag;
  370. if ( f & 2 )
  371. {
  372. if ( p + 1 > limit )
  373. goto Invalid_Outline;
  374. y = (FT_Pos)FT_NEXT_BYTE( p );
  375. if ( ( f & 16 ) == 0 )
  376. y = -y;
  377. }
  378. else if ( ( f & 16 ) == 0 )
  379. {
  380. if ( p + 2 > limit )
  381. goto Invalid_Outline;
  382. y = (FT_Pos)FT_NEXT_SHORT( p );
  383. }
  384. x += y;
  385. vec->x = x;
  386. /* the cast is for stupid compilers */
  387. *flag = (FT_Byte)( f & ~( 2 | 16 ) );
  388. }
  389. /* reading the Y coordinates */
  390. vec = gloader->current.outline.points;
  391. vec_limit = vec + n_points;
  392. flag = (FT_Byte*)outline->tags;
  393. x = 0;
  394. for ( ; vec < vec_limit; vec++, flag++ )
  395. {
  396. FT_Pos y = 0;
  397. FT_Byte f = *flag;
  398. if ( f & 4 )
  399. {
  400. if ( p + 1 > limit )
  401. goto Invalid_Outline;
  402. y = (FT_Pos)FT_NEXT_BYTE( p );
  403. if ( ( f & 32 ) == 0 )
  404. y = -y;
  405. }
  406. else if ( ( f & 32 ) == 0 )
  407. {
  408. if ( p + 2 > limit )
  409. goto Invalid_Outline;
  410. y = (FT_Pos)FT_NEXT_SHORT( p );
  411. }
  412. x += y;
  413. vec->y = x;
  414. /* the cast is for stupid compilers */
  415. *flag = (FT_Byte)( f & FT_CURVE_TAG_ON );
  416. }
  417. outline->n_points = (FT_UShort)n_points;
  418. outline->n_contours = (FT_Short) n_contours;
  419. load->cursor = p;
  420. Fail:
  421. return error;
  422. Invalid_Outline:
  423. error = TT_Err_Invalid_Outline;
  424. goto Fail;
  425. }
  426. FT_CALLBACK_DEF( FT_Error )
  427. TT_Load_Composite_Glyph( TT_Loader loader )
  428. {
  429. FT_Error error;
  430. FT_Byte* p = loader->cursor;
  431. FT_Byte* limit = loader->limit;
  432. FT_GlyphLoader gloader = loader->gloader;
  433. FT_SubGlyph subglyph;
  434. FT_UInt num_subglyphs;
  435. num_subglyphs = 0;
  436. do
  437. {
  438. FT_Fixed xx, xy, yy, yx;
  439. FT_UInt count;
  440. /* check that we can load a new subglyph */
  441. error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs + 1 );
  442. if ( error )
  443. goto Fail;
  444. /* check space */
  445. if ( p + 4 > limit )
  446. goto Invalid_Composite;
  447. subglyph = gloader->current.subglyphs + num_subglyphs;
  448. subglyph->arg1 = subglyph->arg2 = 0;
  449. subglyph->flags = FT_NEXT_USHORT( p );
  450. subglyph->index = FT_NEXT_USHORT( p );
  451. /* check space */
  452. count = 2;
  453. if ( subglyph->flags & ARGS_ARE_WORDS )
  454. count += 2;
  455. if ( subglyph->flags & WE_HAVE_A_SCALE )
  456. count += 2;
  457. else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
  458. count += 4;
  459. else if ( subglyph->flags & WE_HAVE_A_2X2 )
  460. count += 8;
  461. if ( p + count > limit )
  462. goto Invalid_Composite;
  463. /* read arguments */
  464. if ( subglyph->flags & ARGS_ARE_WORDS )
  465. {
  466. subglyph->arg1 = FT_NEXT_SHORT( p );
  467. subglyph->arg2 = FT_NEXT_SHORT( p );
  468. }
  469. else
  470. {
  471. subglyph->arg1 = FT_NEXT_CHAR( p );
  472. subglyph->arg2 = FT_NEXT_CHAR( p );
  473. }
  474. /* read transform */
  475. xx = yy = 0x10000L;
  476. xy = yx = 0;
  477. if ( subglyph->flags & WE_HAVE_A_SCALE )
  478. {
  479. xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  480. yy = xx;
  481. }
  482. else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
  483. {
  484. xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  485. yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  486. }
  487. else if ( subglyph->flags & WE_HAVE_A_2X2 )
  488. {
  489. xx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  490. yx = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  491. xy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  492. yy = (FT_Fixed)FT_NEXT_SHORT( p ) << 2;
  493. }
  494. subglyph->transform.xx = xx;
  495. subglyph->transform.xy = xy;
  496. subglyph->transform.yx = yx;
  497. subglyph->transform.yy = yy;
  498. num_subglyphs++;
  499. } while ( subglyph->flags & MORE_COMPONENTS );
  500. gloader->current.num_subglyphs = num_subglyphs;
  501. #ifdef TT_USE_BYTECODE_INTERPRETER
  502. {
  503. FT_Stream stream = loader->stream;
  504. /* we must undo the FT_FRAME_ENTER in order to point */
  505. /* to the composite instructions, if we find some. */
  506. /* We will process them later. */
  507. /* */
  508. loader->ins_pos = (FT_ULong)( FT_STREAM_POS() +
  509. p - limit );
  510. }
  511. #endif
  512. loader->cursor = p;
  513. Fail:
  514. return error;
  515. Invalid_Composite:
  516. error = TT_Err_Invalid_Composite;
  517. goto Fail;
  518. }
  519. FT_LOCAL_DEF( void )
  520. TT_Init_Glyph_Loading( TT_Face face )
  521. {
  522. face->access_glyph_frame = TT_Access_Glyph_Frame;
  523. face->read_glyph_header = TT_Load_Glyph_Header;
  524. face->read_simple_glyph = TT_Load_Simple_Glyph;
  525. face->read_composite_glyph = TT_Load_Composite_Glyph;
  526. face->forget_glyph_frame = TT_Forget_Glyph_Frame;
  527. }
  528. static void
  529. tt_prepare_zone( TT_GlyphZone zone,
  530. FT_GlyphLoad load,
  531. FT_UInt start_point,
  532. FT_UInt start_contour )
  533. {
  534. zone->n_points = (FT_UShort)( load->outline.n_points - start_point );
  535. zone->n_contours = (FT_Short) ( load->outline.n_contours -
  536. start_contour );
  537. zone->org = load->extra_points + start_point;
  538. zone->cur = load->outline.points + start_point;
  539. zone->orus = load->extra_points2 + start_point;
  540. zone->tags = (FT_Byte*)load->outline.tags + start_point;
  541. zone->contours = (FT_UShort*)load->outline.contours + start_contour;
  542. zone->first_point = (FT_UShort)start_point;
  543. }
  544. /*************************************************************************/
  545. /* */
  546. /* <Function> */
  547. /* TT_Hint_Glyph */
  548. /* */
  549. /* <Description> */
  550. /* Hint the glyph using the zone prepared by the caller. Note that */
  551. /* the zone is supposed to include four phantom points. */
  552. /* */
  553. static FT_Error
  554. TT_Hint_Glyph( TT_Loader loader,
  555. FT_Bool is_composite )
  556. {
  557. TT_GlyphZone zone = &loader->zone;
  558. FT_Pos origin;
  559. #ifdef TT_USE_BYTECODE_INTERPRETER
  560. FT_UInt n_ins;
  561. #else
  562. FT_UNUSED( is_composite );
  563. #endif
  564. #ifdef TT_USE_BYTECODE_INTERPRETER
  565. if ( loader->glyph->control_len > 0xFFFFL )
  566. {
  567. FT_TRACE1(( "TT_Hint_Glyph: too long instructions " ));
  568. FT_TRACE1(( "(0x%lx byte) is truncated\n",
  569. loader->glyph->control_len ));
  570. }
  571. n_ins = (FT_UInt)( loader->glyph->control_len );
  572. #endif
  573. origin = zone->cur[zone->n_points - 4].x;
  574. origin = FT_PIX_ROUND( origin ) - origin;
  575. if ( origin )
  576. translate_array( zone->n_points, zone->cur, origin, 0 );
  577. #ifdef TT_USE_BYTECODE_INTERPRETER
  578. /* save original point position in org */
  579. if ( n_ins > 0 )
  580. FT_ARRAY_COPY( zone->org, zone->cur, zone->n_points );
  581. /* Reset graphics state. */
  582. loader->exec->GS = ((TT_Size)loader->size)->GS;
  583. /* XXX: UNDOCUMENTED! Hinting instructions of a composite glyph */
  584. /* completely refer to the (already) hinted subglyphs. */
  585. if ( is_composite )
  586. {
  587. loader->exec->metrics.x_scale = 1 << 16;
  588. loader->exec->metrics.y_scale = 1 << 16;
  589. FT_ARRAY_COPY( zone->orus, zone->cur, zone->n_points );
  590. }
  591. else
  592. {
  593. loader->exec->metrics.x_scale =
  594. ((TT_Size)loader->size)->metrics.x_scale;
  595. loader->exec->metrics.y_scale =
  596. ((TT_Size)loader->size)->metrics.y_scale;
  597. }
  598. #endif
  599. /* round pp2 and pp4 */
  600. zone->cur[zone->n_points - 3].x =
  601. FT_PIX_ROUND( zone->cur[zone->n_points - 3].x );
  602. zone->cur[zone->n_points - 1].y =
  603. FT_PIX_ROUND( zone->cur[zone->n_points - 1].y );
  604. #ifdef TT_USE_BYTECODE_INTERPRETER
  605. if ( n_ins > 0 )
  606. {
  607. FT_Bool debug;
  608. FT_Error error;
  609. FT_GlyphLoader gloader = loader->gloader;
  610. FT_Outline current_outline = gloader->current.outline;
  611. error = TT_Set_CodeRange( loader->exec, tt_coderange_glyph,
  612. loader->exec->glyphIns, n_ins );
  613. if ( error )
  614. return error;
  615. loader->exec->is_composite = is_composite;
  616. loader->exec->pts = *zone;
  617. debug = FT_BOOL( !( loader->load_flags & FT_LOAD_NO_SCALE ) &&
  618. ((TT_Size)loader->size)->debug );
  619. error = TT_Run_Context( loader->exec, debug );
  620. if ( error && loader->exec->pedantic_hinting )
  621. return error;
  622. /* store drop-out mode in bits 5-7; set bit 2 also as a marker */
  623. current_outline.tags[0] |=
  624. ( loader->exec->GS.scan_type << 5 ) | FT_CURVE_TAG_HAS_SCANMODE;
  625. }
  626. #endif
  627. /* save glyph phantom points */
  628. if ( !loader->preserve_pps )
  629. {
  630. loader->pp1 = zone->cur[zone->n_points - 4];
  631. loader->pp2 = zone->cur[zone->n_points - 3];
  632. loader->pp3 = zone->cur[zone->n_points - 2];
  633. loader->pp4 = zone->cur[zone->n_points - 1];
  634. }
  635. return TT_Err_Ok;
  636. }
  637. /*************************************************************************/
  638. /* */
  639. /* <Function> */
  640. /* TT_Process_Simple_Glyph */
  641. /* */
  642. /* <Description> */
  643. /* Once a simple glyph has been loaded, it needs to be processed. */
  644. /* Usually, this means scaling and hinting through bytecode */
  645. /* interpretation. */
  646. /* */
  647. static FT_Error
  648. TT_Process_Simple_Glyph( TT_Loader loader )
  649. {
  650. FT_GlyphLoader gloader = loader->gloader;
  651. FT_Error error = TT_Err_Ok;
  652. FT_Outline* outline;
  653. FT_Int n_points;
  654. outline = &gloader->current.outline;
  655. n_points = outline->n_points;
  656. /* set phantom points */
  657. outline->points[n_points ] = loader->pp1;
  658. outline->points[n_points + 1] = loader->pp2;
  659. outline->points[n_points + 2] = loader->pp3;
  660. outline->points[n_points + 3] = loader->pp4;
  661. outline->tags[n_points ] = 0;
  662. outline->tags[n_points + 1] = 0;
  663. outline->tags[n_points + 2] = 0;
  664. outline->tags[n_points + 3] = 0;
  665. n_points += 4;
  666. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  667. if ( ((TT_Face)loader->face)->doblend )
  668. {
  669. /* Deltas apply to the unscaled data. */
  670. FT_Vector* deltas;
  671. FT_Memory memory = loader->face->memory;
  672. FT_Int i;
  673. error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face),
  674. loader->glyph_index,
  675. &deltas,
  676. n_points );
  677. if ( error )
  678. return error;
  679. for ( i = 0; i < n_points; ++i )
  680. {
  681. outline->points[i].x += deltas[i].x;
  682. outline->points[i].y += deltas[i].y;
  683. }
  684. FT_FREE( deltas );
  685. }
  686. #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
  687. if ( IS_HINTED( loader->load_flags ) )
  688. {
  689. tt_prepare_zone( &loader->zone, &gloader->current, 0, 0 );
  690. FT_ARRAY_COPY( loader->zone.orus, loader->zone.cur,
  691. loader->zone.n_points + 4 );
  692. }
  693. /* scale the glyph */
  694. if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
  695. {
  696. FT_Vector* vec = outline->points;
  697. FT_Vector* limit = outline->points + n_points;
  698. FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale;
  699. FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale;
  700. for ( ; vec < limit; vec++ )
  701. {
  702. vec->x = FT_MulFix( vec->x, x_scale );
  703. vec->y = FT_MulFix( vec->y, y_scale );
  704. }
  705. loader->pp1 = outline->points[n_points - 4];
  706. loader->pp2 = outline->points[n_points - 3];
  707. loader->pp3 = outline->points[n_points - 2];
  708. loader->pp4 = outline->points[n_points - 1];
  709. }
  710. if ( IS_HINTED( loader->load_flags ) )
  711. {
  712. loader->zone.n_points += 4;
  713. error = TT_Hint_Glyph( loader, 0 );
  714. }
  715. return error;
  716. }
  717. /*************************************************************************/
  718. /* */
  719. /* <Function> */
  720. /* TT_Process_Composite_Component */
  721. /* */
  722. /* <Description> */
  723. /* Once a composite component has been loaded, it needs to be */
  724. /* processed. Usually, this means transforming and translating. */
  725. /* */
  726. static FT_Error
  727. TT_Process_Composite_Component( TT_Loader loader,
  728. FT_SubGlyph subglyph,
  729. FT_UInt start_point,
  730. FT_UInt num_base_points )
  731. {
  732. FT_GlyphLoader gloader = loader->gloader;
  733. FT_Vector* base_vec = gloader->base.outline.points;
  734. FT_UInt num_points = gloader->base.outline.n_points;
  735. FT_Bool have_scale;
  736. FT_Pos x, y;
  737. have_scale = FT_BOOL( subglyph->flags & ( WE_HAVE_A_SCALE |
  738. WE_HAVE_AN_XY_SCALE |
  739. WE_HAVE_A_2X2 ) );
  740. /* perform the transform required for this subglyph */
  741. if ( have_scale )
  742. {
  743. FT_UInt i;
  744. for ( i = num_base_points; i < num_points; i++ )
  745. FT_Vector_Transform( base_vec + i, &subglyph->transform );
  746. }
  747. /* get offset */
  748. if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) )
  749. {
  750. FT_UInt k = subglyph->arg1;
  751. FT_UInt l = subglyph->arg2;
  752. FT_Vector* p1;
  753. FT_Vector* p2;
  754. /* match l-th point of the newly loaded component to the k-th point */
  755. /* of the previously loaded components. */
  756. /* change to the point numbers used by our outline */
  757. k += start_point;
  758. l += num_base_points;
  759. if ( k >= num_base_points ||
  760. l >= num_points )
  761. return TT_Err_Invalid_Composite;
  762. p1 = gloader->base.outline.points + k;
  763. p2 = gloader->base.outline.points + l;
  764. x = p1->x - p2->x;
  765. y = p1->y - p2->y;
  766. }
  767. else
  768. {
  769. x = subglyph->arg1;
  770. y = subglyph->arg2;
  771. if ( !x && !y )
  772. return TT_Err_Ok;
  773. /* Use a default value dependent on */
  774. /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED. This is useful for old TT */
  775. /* fonts which don't set the xxx_COMPONENT_OFFSET bit. */
  776. if ( have_scale &&
  777. #ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED
  778. !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) )
  779. #else
  780. ( subglyph->flags & SCALED_COMPONENT_OFFSET ) )
  781. #endif
  782. {
  783. #if 0
  784. /*************************************************************************/
  785. /* */
  786. /* This algorithm is what Apple documents. But it doesn't work. */
  787. /* */
  788. int a = subglyph->transform.xx > 0 ? subglyph->transform.xx
  789. : -subglyph->transform.xx;
  790. int b = subglyph->transform.yx > 0 ? subglyph->transform.yx
  791. : -subglyph->transform.yx;
  792. int c = subglyph->transform.xy > 0 ? subglyph->transform.xy
  793. : -subglyph->transform.xy;
  794. int d = subglyph->transform.yy > 0 ? subglyph->transform.yy
  795. : -subglyph->transform.yy;
  796. int m = a > b ? a : b;
  797. int n = c > d ? c : d;
  798. if ( a - b <= 33 && a - b >= -33 )
  799. m *= 2;
  800. if ( c - d <= 33 && c - d >= -33 )
  801. n *= 2;
  802. x = FT_MulFix( x, m );
  803. y = FT_MulFix( y, n );
  804. #else /* 0 */
  805. /*************************************************************************/
  806. /* */
  807. /* This algorithm is a guess and works much better than the above. */
  808. /* */
  809. FT_Fixed mac_xscale = FT_SqrtFixed(
  810. (FT_Int32)FT_MulFix( subglyph->transform.xx,
  811. subglyph->transform.xx ) +
  812. (FT_Int32)FT_MulFix( subglyph->transform.xy,
  813. subglyph->transform.xy ) );
  814. FT_Fixed mac_yscale = FT_SqrtFixed(
  815. (FT_Int32)FT_MulFix( subglyph->transform.yy,
  816. subglyph->transform.yy ) +
  817. (FT_Int32)FT_MulFix( subglyph->transform.yx,
  818. subglyph->transform.yx ) );
  819. x = FT_MulFix( x, mac_xscale );
  820. y = FT_MulFix( y, mac_yscale );
  821. #endif /* 0 */
  822. }
  823. if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
  824. {
  825. FT_Fixed x_scale = ((TT_Size)loader->size)->metrics.x_scale;
  826. FT_Fixed y_scale = ((TT_Size)loader->size)->metrics.y_scale;
  827. x = FT_MulFix( x, x_scale );
  828. y = FT_MulFix( y, y_scale );
  829. if ( subglyph->flags & ROUND_XY_TO_GRID )
  830. {
  831. x = FT_PIX_ROUND( x );
  832. y = FT_PIX_ROUND( y );
  833. }
  834. }
  835. }
  836. if ( x || y )
  837. translate_array( num_points - num_base_points,
  838. base_vec + num_base_points,
  839. x, y );
  840. return TT_Err_Ok;
  841. }
  842. /*************************************************************************/
  843. /* */
  844. /* <Function> */
  845. /* TT_Process_Composite_Glyph */
  846. /* */
  847. /* <Description> */
  848. /* This is slightly different from TT_Process_Simple_Glyph, in that */
  849. /* its sole purpose is to hint the glyph. Thus this function is */
  850. /* only available when bytecode interpreter is enabled. */
  851. /* */
  852. static FT_Error
  853. TT_Process_Composite_Glyph( TT_Loader loader,
  854. FT_UInt start_point,
  855. FT_UInt start_contour )
  856. {
  857. FT_Error error;
  858. FT_Outline* outline;
  859. FT_UInt i;
  860. outline = &loader->gloader->base.outline;
  861. /* make room for phantom points */
  862. error = FT_GLYPHLOADER_CHECK_POINTS( loader->gloader,
  863. outline->n_points + 4,
  864. 0 );
  865. if ( error )
  866. return error;
  867. outline->points[outline->n_points ] = loader->pp1;
  868. outline->points[outline->n_points + 1] = loader->pp2;
  869. outline->points[outline->n_points + 2] = loader->pp3;
  870. outline->points[outline->n_points + 3] = loader->pp4;
  871. outline->tags[outline->n_points ] = 0;
  872. outline->tags[outline->n_points + 1] = 0;
  873. outline->tags[outline->n_points + 2] = 0;
  874. outline->tags[outline->n_points + 3] = 0;
  875. #ifdef TT_USE_BYTECODE_INTERPRETER
  876. {
  877. FT_Stream stream = loader->stream;
  878. FT_UShort n_ins, max_ins;
  879. FT_ULong tmp;
  880. /* TT_Load_Composite_Glyph only gives us the offset of instructions */
  881. /* so we read them here */
  882. if ( FT_STREAM_SEEK( loader->ins_pos ) ||
  883. FT_READ_USHORT( n_ins ) )
  884. return error;
  885. FT_TRACE5(( " Instructions size = %d\n", n_ins ));
  886. /* check it */
  887. max_ins = ((TT_Face)loader->face)->max_profile.maxSizeOfInstructions;
  888. if ( n_ins > max_ins )
  889. {
  890. /* acroread ignores this field, so we only do a rough safety check */
  891. if ( (FT_Int)n_ins > loader->byte_len )
  892. {
  893. FT_TRACE1(( "TT_Process_Composite_Glyph: "
  894. "too many instructions (%d) for glyph with length %d\n",
  895. n_ins, loader->byte_len ));
  896. return TT_Err_Too_Many_Hints;
  897. }
  898. tmp = loader->exec->glyphSize;
  899. error = Update_Max( loader->exec->memory,
  900. &tmp,
  901. sizeof ( FT_Byte ),
  902. (void*)&loader->exec->glyphIns,
  903. n_ins );
  904. loader->exec->glyphSize = (FT_UShort)tmp;
  905. if ( error )
  906. return error;
  907. }
  908. else if ( n_ins == 0 )
  909. return TT_Err_Ok;
  910. if ( FT_STREAM_READ( loader->exec->glyphIns, n_ins ) )
  911. return error;
  912. loader->glyph->control_data = loader->exec->glyphIns;
  913. loader->glyph->control_len = n_ins;
  914. }
  915. #endif
  916. tt_prepare_zone( &loader->zone, &loader->gloader->base,
  917. start_point, start_contour );
  918. /* Some points are likely touched during execution of */
  919. /* instructions on components. So let's untouch them. */
  920. for ( i = start_point; i < loader->zone.n_points; i++ )
  921. loader->zone.tags[i] &= ~FT_CURVE_TAG_TOUCH_BOTH;
  922. loader->zone.n_points += 4;
  923. return TT_Hint_Glyph( loader, 1 );
  924. }
  925. /* Calculate the four phantom points. */
  926. /* The first two stand for horizontal origin and advance. */
  927. /* The last two stand for vertical origin and advance. */
  928. #define TT_LOADER_SET_PP( loader ) \
  929. do { \
  930. (loader)->pp1.x = (loader)->bbox.xMin - (loader)->left_bearing; \
  931. (loader)->pp1.y = 0; \
  932. (loader)->pp2.x = (loader)->pp1.x + (loader)->advance; \
  933. (loader)->pp2.y = 0; \
  934. (loader)->pp3.x = 0; \
  935. (loader)->pp3.y = (loader)->top_bearing + (loader)->bbox.yMax; \
  936. (loader)->pp4.x = 0; \
  937. (loader)->pp4.y = (loader)->pp3.y - (loader)->vadvance; \
  938. } while ( 0 )
  939. /*************************************************************************/
  940. /* */
  941. /* <Function> */
  942. /* load_truetype_glyph */
  943. /* */
  944. /* <Description> */
  945. /* Loads a given truetype glyph. Handles composites and uses a */
  946. /* TT_Loader object. */
  947. /* */
  948. static FT_Error
  949. load_truetype_glyph( TT_Loader loader,
  950. FT_UInt glyph_index,
  951. FT_UInt recurse_count,
  952. FT_Bool header_only )
  953. {
  954. FT_Error error = TT_Err_Ok;
  955. FT_Fixed x_scale, y_scale;
  956. FT_ULong offset;
  957. TT_Face face = (TT_Face)loader->face;
  958. FT_GlyphLoader gloader = loader->gloader;
  959. FT_Bool opened_frame = 0;
  960. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  961. FT_Vector* deltas = NULL;
  962. #endif
  963. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  964. FT_StreamRec inc_stream;
  965. FT_Data glyph_data;
  966. FT_Bool glyph_data_loaded = 0;
  967. #endif
  968. /* some fonts have an incorrect value of `maxComponentDepth', */
  969. /* thus we allow depth 1 to catch the majority of them */
  970. if ( recurse_count > 1 &&
  971. recurse_count > face->max_profile.maxComponentDepth )
  972. {
  973. error = TT_Err_Invalid_Composite;
  974. goto Exit;
  975. }
  976. /* check glyph index */
  977. if ( glyph_index >= (FT_UInt)face->root.num_glyphs )
  978. {
  979. error = TT_Err_Invalid_Glyph_Index;
  980. goto Exit;
  981. }
  982. loader->glyph_index = glyph_index;
  983. if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
  984. {
  985. x_scale = ((TT_Size)loader->size)->metrics.x_scale;
  986. y_scale = ((TT_Size)loader->size)->metrics.y_scale;
  987. }
  988. else
  989. {
  990. x_scale = 0x10000L;
  991. y_scale = 0x10000L;
  992. }
  993. tt_get_metrics( loader, glyph_index );
  994. /* Set `offset' to the start of the glyph relative to the start of */
  995. /* the `glyf' table, and `byte_len' to the length of the glyph in */
  996. /* bytes. */
  997. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  998. /* If we are loading glyph data via the incremental interface, set */
  999. /* the loader stream to a memory stream reading the data returned */
  1000. /* by the interface. */
  1001. if ( face->root.internal->incremental_interface )
  1002. {
  1003. error = face->root.internal->incremental_interface->funcs->get_glyph_data(
  1004. face->root.internal->incremental_interface->object,
  1005. glyph_index, &glyph_data );
  1006. if ( error )
  1007. goto Exit;
  1008. glyph_data_loaded = 1;
  1009. offset = 0;
  1010. loader->byte_len = glyph_data.length;
  1011. FT_MEM_ZERO( &inc_stream, sizeof ( inc_stream ) );
  1012. FT_Stream_OpenMemory( &inc_stream,
  1013. glyph_data.pointer, glyph_data.length );
  1014. loader->stream = &inc_stream;
  1015. }
  1016. else
  1017. #endif /* FT_CONFIG_OPTION_INCREMENTAL */
  1018. offset = tt_face_get_location( face, glyph_index,
  1019. (FT_UInt*)&loader->byte_len );
  1020. if ( loader->byte_len > 0 )
  1021. {
  1022. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1023. /* for the incremental interface, `glyf_offset' is always zero */
  1024. if ( !loader->glyf_offset &&
  1025. !face->root.internal->incremental_interface )
  1026. #else
  1027. if ( !loader->glyf_offset )
  1028. #endif /* FT_CONFIG_OPTION_INCREMENTAL */
  1029. {
  1030. FT_TRACE2(( "no `glyf' table but non-zero `loca' entry\n" ));
  1031. error = TT_Err_Invalid_Table;
  1032. goto Exit;
  1033. }
  1034. error = face->access_glyph_frame( loader, glyph_index,
  1035. loader->glyf_offset + offset,
  1036. loader->byte_len );
  1037. if ( error )
  1038. goto Exit;
  1039. opened_frame = 1;
  1040. /* read glyph header first */
  1041. error = face->read_glyph_header( loader );
  1042. if ( error || header_only )
  1043. goto Exit;
  1044. }
  1045. if ( loader->byte_len == 0 || loader->n_contours == 0 )
  1046. {
  1047. loader->bbox.xMin = 0;
  1048. loader->bbox.xMax = 0;
  1049. loader->bbox.yMin = 0;
  1050. loader->bbox.yMax = 0;
  1051. if ( header_only )
  1052. goto Exit;
  1053. /* must initialize points before (possibly) overriding */
  1054. /* glyph metrics from the incremental interface */
  1055. TT_LOADER_SET_PP( loader );
  1056. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1057. tt_get_metrics_incr_overrides( loader, glyph_index );
  1058. #endif
  1059. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  1060. if ( ((TT_Face)(loader->face))->doblend )
  1061. {
  1062. /* this must be done before scaling */
  1063. FT_Memory memory = loader->face->memory;
  1064. error = TT_Vary_Get_Glyph_Deltas( (TT_Face)(loader->face),
  1065. glyph_index, &deltas, 4 );
  1066. if ( error )
  1067. goto Exit;
  1068. loader->pp1.x += deltas[0].x; loader->pp1.y += deltas[0].y;
  1069. loader->pp2.x += deltas[1].x; loader->pp2.y += deltas[1].y;
  1070. loader->pp3.x += deltas[2].x; loader->pp3.y += deltas[2].y;
  1071. loader->pp4.x += deltas[3].x; loader->pp4.y += deltas[3].y;
  1072. FT_FREE( deltas );
  1073. }
  1074. #endif
  1075. if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
  1076. {
  1077. loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
  1078. loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
  1079. loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
  1080. loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
  1081. }
  1082. error = TT_Err_Ok;
  1083. goto Exit;
  1084. }
  1085. /* must initialize points before (possibly) overriding */
  1086. /* glyph metrics from the incremental interface */
  1087. TT_LOADER_SET_PP( loader );
  1088. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1089. tt_get_metrics_incr_overrides( loader, glyph_index );
  1090. #endif
  1091. /***********************************************************************/
  1092. /***********************************************************************/
  1093. /***********************************************************************/
  1094. /* if it is a simple glyph, load it */
  1095. if ( loader->n_contours > 0 )
  1096. {
  1097. error = face->read_simple_glyph( loader );
  1098. if ( error )
  1099. goto Exit;
  1100. /* all data have been read */
  1101. face->forget_glyph_frame( loader );
  1102. opened_frame = 0;
  1103. error = TT_Process_Simple_Glyph( loader );
  1104. if ( error )
  1105. goto Exit;
  1106. FT_GlyphLoader_Add( gloader );
  1107. }
  1108. /***********************************************************************/
  1109. /***********************************************************************/
  1110. /***********************************************************************/
  1111. /* otherwise, load a composite! */
  1112. else if ( loader->n_contours == -1 )
  1113. {
  1114. FT_UInt start_point;
  1115. FT_UInt start_contour;
  1116. FT_ULong ins_pos; /* position of composite instructions, if any */
  1117. start_point = gloader->base.outline.n_points;
  1118. start_contour = gloader->base.outline.n_contours;
  1119. /* for each subglyph, read composite header */
  1120. error = face->read_composite_glyph( loader );
  1121. if ( error )
  1122. goto Exit;
  1123. /* store the offset of instructions */
  1124. ins_pos = loader->ins_pos;
  1125. /* all data we need are read */
  1126. face->forget_glyph_frame( loader );
  1127. opened_frame = 0;
  1128. #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
  1129. if ( face->doblend )
  1130. {
  1131. FT_Int i, limit;
  1132. FT_SubGlyph subglyph;
  1133. FT_Memory memory = face->root.memory;
  1134. /* this provides additional offsets */
  1135. /* for each component's translation */
  1136. if ( ( error = TT_Vary_Get_Glyph_Deltas(
  1137. face,
  1138. glyph_index,
  1139. &deltas,
  1140. gloader->current.num_subglyphs + 4 )) != 0 )
  1141. goto Exit;
  1142. subglyph = gloader->current.subglyphs + gloader->base.num_subglyphs;
  1143. limit = gloader->current.num_subglyphs;
  1144. for ( i = 0; i < limit; ++i, ++subglyph )
  1145. {
  1146. if ( subglyph->flags & ARGS_ARE_XY_VALUES )
  1147. {
  1148. /* XXX: overflow check for subglyph->{arg1,arg2}. */
  1149. /* deltas[i].{x,y} must be within signed 16-bit, */
  1150. /* but the restriction of summed delta is not clear */
  1151. subglyph->arg1 += (FT_Int16)deltas[i].x;
  1152. subglyph->arg2 += (FT_Int16)deltas[i].y;
  1153. }
  1154. }
  1155. loader->pp1.x += deltas[i + 0].x; loader->pp1.y += deltas[i + 0].y;
  1156. loader->pp2.x += deltas[i + 1].x; loader->pp2.y += deltas[i + 1].y;
  1157. loader->pp3.x += deltas[i + 2].x; loader->pp3.y += deltas[i + 2].y;
  1158. loader->pp4.x += deltas[i + 3].x; loader->pp4.y += deltas[i + 3].y;
  1159. FT_FREE( deltas );
  1160. }
  1161. #endif /* TT_CONFIG_OPTION_GX_VAR_SUPPORT */
  1162. if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
  1163. {
  1164. loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
  1165. loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
  1166. loader->pp3.y = FT_MulFix( loader->pp3.y, y_scale );
  1167. loader->pp4.y = FT_MulFix( loader->pp4.y, y_scale );
  1168. }
  1169. /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
  1170. /* `as is' in the glyph slot (the client application will be */
  1171. /* responsible for interpreting these data)... */
  1172. if ( loader->load_flags & FT_LOAD_NO_RECURSE )
  1173. {
  1174. FT_GlyphLoader_Add( gloader );
  1175. loader->glyph->format = FT_GLYPH_FORMAT_COMPOSITE;
  1176. goto Exit;
  1177. }
  1178. /*********************************************************************/
  1179. /*********************************************************************/
  1180. /*********************************************************************/
  1181. {
  1182. FT_UInt n, num_base_points;
  1183. FT_SubGlyph subglyph = 0;
  1184. FT_UInt num_points = start_point;
  1185. FT_UInt num_subglyphs = gloader->current.num_subglyphs;
  1186. FT_UInt num_base_subgs = gloader->base.num_subglyphs;
  1187. FT_Stream old_stream = loader->stream;
  1188. FT_Int old_byte_len = loader->byte_len;
  1189. FT_GlyphLoader_Add( gloader );
  1190. /* read each subglyph independently */
  1191. for ( n = 0; n < num_subglyphs; n++ )
  1192. {
  1193. FT_Vector pp[4];
  1194. /* Each time we call load_truetype_glyph in this loop, the */
  1195. /* value of `gloader.base.subglyphs' can change due to table */
  1196. /* reallocations. We thus need to recompute the subglyph */
  1197. /* pointer on each iteration. */
  1198. subglyph = gloader->base.subglyphs + num_base_subgs + n;
  1199. pp[0] = loader->pp1;
  1200. pp[1] = loader->pp2;
  1201. pp[2] = loader->pp3;
  1202. pp[3] = loader->pp4;
  1203. num_base_points = gloader->base.outline.n_points;
  1204. error = load_truetype_glyph( loader, subglyph->index,
  1205. recurse_count + 1, FALSE );
  1206. if ( error )
  1207. goto Exit;
  1208. /* restore subglyph pointer */
  1209. subglyph = gloader->base.subglyphs + num_base_subgs + n;
  1210. if ( !( subglyph->flags & USE_MY_METRICS ) )
  1211. {
  1212. loader->pp1 = pp[0];
  1213. loader->pp2 = pp[1];
  1214. loader->pp3 = pp[2];
  1215. loader->pp4 = pp[3];
  1216. }
  1217. num_points = gloader->base.outline.n_points;
  1218. if ( num_points == num_base_points )
  1219. continue;
  1220. /* gloader->base.outline consists of three parts: */
  1221. /* 0 -(1)-> start_point -(2)-> num_base_points -(3)-> n_points. */
  1222. /* */
  1223. /* (1): exists from the beginning */
  1224. /* (2): components that have been loaded so far */
  1225. /* (3): the newly loaded component */
  1226. TT_Process_Composite_Component( loader, subglyph, start_point,
  1227. num_base_points );
  1228. }
  1229. loader->stream = old_stream;
  1230. loader->byte_len = old_byte_len;
  1231. /* process the glyph */
  1232. loader->ins_pos = ins_pos;
  1233. if ( IS_HINTED( loader->load_flags ) &&
  1234. #ifdef TT_USE_BYTECODE_INTERPRETER
  1235. subglyph->flags & WE_HAVE_INSTR &&
  1236. #endif
  1237. num_points > start_point )
  1238. TT_Process_Composite_Glyph( loader, start_point, start_contour );
  1239. }
  1240. }
  1241. else
  1242. {
  1243. /* invalid composite count (negative but not -1) */
  1244. error = TT_Err_Invalid_Outline;
  1245. goto Exit;
  1246. }
  1247. /***********************************************************************/
  1248. /***********************************************************************/
  1249. /***********************************************************************/
  1250. Exit:
  1251. if ( opened_frame )
  1252. face->forget_glyph_frame( loader );
  1253. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1254. if ( glyph_data_loaded )
  1255. face->root.internal->incremental_interface->funcs->free_glyph_data(
  1256. face->root.internal->incremental_interface->object,
  1257. &glyph_data );
  1258. #endif
  1259. return error;
  1260. }
  1261. static FT_Error
  1262. compute_glyph_metrics( TT_Loader loader,
  1263. FT_UInt glyph_index )
  1264. {
  1265. FT_BBox bbox;
  1266. TT_Face face = (TT_Face)loader->face;
  1267. FT_Fixed y_scale;
  1268. TT_GlyphSlot glyph = loader->glyph;
  1269. TT_Size size = (TT_Size)loader->size;
  1270. y_scale = 0x10000L;
  1271. if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
  1272. y_scale = size->root.metrics.y_scale;
  1273. if ( glyph->format != FT_GLYPH_FORMAT_COMPOSITE )
  1274. FT_Outline_Get_CBox( &glyph->outline, &bbox );
  1275. else
  1276. bbox = loader->bbox;
  1277. /* get the device-independent horizontal advance; it is scaled later */
  1278. /* by the base layer. */
  1279. glyph->linearHoriAdvance = loader->linear;
  1280. glyph->metrics.horiBearingX = bbox.xMin;
  1281. glyph->metrics.horiBearingY = bbox.yMax;
  1282. glyph->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
  1283. /* adjust advance width to the value contained in the hdmx table */
  1284. if ( !face->postscript.isFixedPitch &&
  1285. IS_HINTED( loader->load_flags ) )
  1286. {
  1287. FT_Byte* widthp;
  1288. widthp = tt_face_get_device_metrics( face,
  1289. size->root.metrics.x_ppem,
  1290. glyph_index );
  1291. if ( widthp )
  1292. glyph->metrics.horiAdvance = *widthp << 6;
  1293. }
  1294. /* set glyph dimensions */
  1295. glyph->metrics.width = bbox.xMax - bbox.xMin;
  1296. glyph->metrics.height = bbox.yMax - bbox.yMin;
  1297. /* Now take care of vertical metrics. In the case where there is */
  1298. /* no vertical information within the font (relatively common), */
  1299. /* create some metrics manually */
  1300. {
  1301. FT_Pos top; /* scaled vertical top side bearing */
  1302. FT_Pos advance; /* scaled vertical advance height */
  1303. /* Get the unscaled top bearing and advance height. */
  1304. if ( face->vertical_info &&
  1305. face->vertical.number_Of_VMetrics > 0 )
  1306. {
  1307. top = (FT_Short)FT_DivFix( loader->pp3.y - bbox.yMax,
  1308. y_scale );
  1309. if ( loader->pp3.y <= loader->pp4.y )
  1310. advance = 0;
  1311. else
  1312. advance = (FT_UShort)FT_DivFix( loader->pp3.y - loader->pp4.y,
  1313. y_scale );
  1314. }
  1315. else
  1316. {
  1317. FT_Pos height;
  1318. /* XXX Compute top side bearing and advance height in */
  1319. /* Get_VMetrics instead of here. */
  1320. /* NOTE: The OS/2 values are the only `portable' ones, */
  1321. /* which is why we use them, if there is an OS/2 */
  1322. /* table in the font. Otherwise, we use the */
  1323. /* values defined in the horizontal header. */
  1324. height = (FT_Short)FT_DivFix( bbox.yMax - bbox.yMin,
  1325. y_scale );
  1326. if ( face->os2.version != 0xFFFFU )
  1327. advance = (FT_Pos)( face->os2.sTypoAscender -
  1328. face->os2.sTypoDescender );
  1329. else
  1330. advance = (FT_Pos)( face->horizontal.Ascender -
  1331. face->horizontal.Descender );
  1332. top = ( advance - height ) / 2;
  1333. }
  1334. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1335. {
  1336. FT_Incremental_InterfaceRec* incr;
  1337. FT_Incremental_MetricsRec metrics;
  1338. FT_Error error;
  1339. incr = face->root.internal->incremental_interface;
  1340. /* If this is an incrementally loaded font see if there are */
  1341. /* overriding metrics for this glyph. */
  1342. if ( incr && incr->funcs->get_glyph_metrics )
  1343. {
  1344. metrics.bearing_x = 0;
  1345. metrics.bearing_y = top;
  1346. metrics.advance = advance;
  1347. error = incr->funcs->get_glyph_metrics( incr->object,
  1348. glyph_index,
  1349. TRUE,
  1350. &metrics );
  1351. if ( error )
  1352. return error;
  1353. top = metrics.bearing_y;
  1354. advance = metrics.advance;
  1355. }
  1356. }
  1357. /* GWW: Do vertical metrics get loaded incrementally too? */
  1358. #endif /* FT_CONFIG_OPTION_INCREMENTAL */
  1359. glyph->linearVertAdvance = advance;
  1360. /* scale the metrics */
  1361. if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
  1362. {
  1363. top = FT_MulFix( top, y_scale );
  1364. advance = FT_MulFix( advance, y_scale );
  1365. }
  1366. /* XXX: for now, we have no better algorithm for the lsb, but it */
  1367. /* should work fine. */
  1368. /* */
  1369. glyph->metrics.vertBearingX = glyph->metrics.horiBearingX -
  1370. glyph->metrics.horiAdvance / 2;
  1371. glyph->metrics.vertBearingY = top;
  1372. glyph->metrics.vertAdvance = advance;
  1373. }
  1374. return 0;
  1375. }
  1376. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  1377. static FT_Error
  1378. load_sbit_image( TT_Size size,
  1379. TT_GlyphSlot glyph,
  1380. FT_UInt glyph_index,
  1381. FT_Int32 load_flags )
  1382. {
  1383. TT_Face face;
  1384. SFNT_Service sfnt;
  1385. FT_Stream stream;
  1386. FT_Error error;
  1387. TT_SBit_MetricsRec metrics;
  1388. face = (TT_Face)glyph->face;
  1389. sfnt = (SFNT_Service)face->sfnt;
  1390. stream = face->root.stream;
  1391. error = sfnt->load_sbit_image( face,
  1392. size->strike_index,
  1393. glyph_index,
  1394. (FT_Int)load_flags,
  1395. stream,
  1396. &glyph->bitmap,
  1397. &metrics );
  1398. if ( !error )
  1399. {
  1400. glyph->outline.n_points = 0;
  1401. glyph->outline.n_contours = 0;
  1402. glyph->metrics.width = (FT_Pos)metrics.width << 6;
  1403. glyph->metrics.height = (FT_Pos)metrics.height << 6;
  1404. glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6;
  1405. glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6;
  1406. glyph->metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6;
  1407. glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6;
  1408. glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6;
  1409. glyph->metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6;
  1410. glyph->format = FT_GLYPH_FORMAT_BITMAP;
  1411. if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
  1412. {
  1413. glyph->bitmap_left = metrics.vertBearingX;
  1414. glyph->bitmap_top = metrics.vertBearingY;
  1415. }
  1416. else
  1417. {
  1418. glyph->bitmap_left = metrics.horiBearingX;
  1419. glyph->bitmap_top = metrics.horiBearingY;
  1420. }
  1421. }
  1422. return error;
  1423. }
  1424. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  1425. static FT_Error
  1426. tt_loader_init( TT_Loader loader,
  1427. TT_Size size,
  1428. TT_GlyphSlot glyph,
  1429. FT_Int32 load_flags,
  1430. FT_Bool glyf_table_only )
  1431. {
  1432. TT_Face face;
  1433. FT_Stream stream;
  1434. FT_Bool pedantic = FT_BOOL( load_flags & FT_LOAD_PEDANTIC );
  1435. face = (TT_Face)glyph->face;
  1436. stream = face->root.stream;
  1437. FT_MEM_ZERO( loader, sizeof ( TT_LoaderRec ) );
  1438. #ifdef TT_USE_BYTECODE_INTERPRETER
  1439. /* load execution context */
  1440. if ( IS_HINTED( load_flags ) && !glyf_table_only )
  1441. {
  1442. TT_ExecContext exec;
  1443. FT_Bool grayscale;
  1444. if ( !size->cvt_ready )
  1445. {
  1446. FT_Error error = tt_size_ready_bytecode( size, pedantic );
  1447. if ( error )
  1448. return error;
  1449. }
  1450. /* query new execution context */
  1451. exec = size->debug ? size->context
  1452. : ( (TT_Driver)FT_FACE_DRIVER( face ) )->context;
  1453. if ( !exec )
  1454. return TT_Err_Could_Not_Find_Context;
  1455. grayscale =
  1456. FT_BOOL( FT_LOAD_TARGET_MODE( load_flags ) != FT_RENDER_MODE_MONO );
  1457. TT_Load_Context( exec, face, size );
  1458. /* a change from mono to grayscale rendering (and vice versa) */
  1459. /* requires a re-execution of the CVT program */
  1460. if ( grayscale != exec->grayscale )
  1461. {
  1462. FT_UInt i;
  1463. FT_TRACE4(( "tt_loader_init: grayscale change,"
  1464. " re-executing `prep' table\n" ));
  1465. exec->grayscale = grayscale;
  1466. for ( i = 0; i < size->cvt_size; i++ )
  1467. size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
  1468. tt_size_run_prep( size, pedantic );
  1469. }
  1470. /* see whether the cvt program has disabled hinting */
  1471. if ( exec->GS.instruct_control & 1 )
  1472. load_flags |= FT_LOAD_NO_HINTING;
  1473. /* load default graphics state -- if needed */
  1474. if ( exec->GS.instruct_control & 2 )
  1475. exec->GS = tt_default_graphics_state;
  1476. exec->pedantic_hinting = FT_BOOL( load_flags & FT_LOAD_PEDANTIC );
  1477. loader->exec = exec;
  1478. loader->instructions = exec->glyphIns;
  1479. }
  1480. #endif /* TT_USE_BYTECODE_INTERPRETER */
  1481. /* seek to the beginning of the glyph table -- for Type 42 fonts */
  1482. /* the table might be accessed from a Postscript stream or something */
  1483. /* else... */
  1484. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  1485. if ( face->root.internal->incremental_interface )
  1486. loader->glyf_offset = 0;
  1487. else
  1488. #endif
  1489. {
  1490. FT_Error error = face->goto_table( face, TTAG_glyf, stream, 0 );
  1491. if ( error == TT_Err_Table_Missing )
  1492. loader->glyf_offset = 0;
  1493. else if ( error )
  1494. {
  1495. FT_ERROR(( "tt_loader_init: could not access glyph table\n" ));
  1496. return error;
  1497. }
  1498. else
  1499. loader->glyf_offset = FT_STREAM_POS();
  1500. }
  1501. /* get face's glyph loader */
  1502. if ( !glyf_table_only )
  1503. {
  1504. FT_GlyphLoader gloader = glyph->internal->loader;
  1505. FT_GlyphLoader_Rewind( gloader );
  1506. loader->gloader = gloader;
  1507. }
  1508. loader->load_flags = load_flags;
  1509. loader->face = (FT_Face)face;
  1510. loader->size = (FT_Size)size;
  1511. loader->glyph = (FT_GlyphSlot)glyph;
  1512. loader->stream = stream;
  1513. return TT_Err_Ok;
  1514. }
  1515. /*************************************************************************/
  1516. /* */
  1517. /* <Function> */
  1518. /* TT_Load_Glyph */
  1519. /* */
  1520. /* <Description> */
  1521. /* A function used to load a single glyph within a given glyph slot, */
  1522. /* for a given size. */
  1523. /* */
  1524. /* <Input> */
  1525. /* glyph :: A handle to a target slot object where the glyph */
  1526. /* will be loaded. */
  1527. /* */
  1528. /* size :: A handle to the source face size at which the glyph */
  1529. /* must be scaled/loaded. */
  1530. /* */
  1531. /* glyph_index :: The index of the glyph in the font file. */
  1532. /* */
  1533. /* load_flags :: A flag indicating what to load for this glyph. The */
  1534. /* FT_LOAD_XXX constants can be used to control the */
  1535. /* glyph loading process (e.g., whether the outline */
  1536. /* should be scaled, whether to load bitmaps or not, */
  1537. /* whether to hint the outline, etc). */
  1538. /* */
  1539. /* <Return> */
  1540. /* FreeType error code. 0 means success. */
  1541. /* */
  1542. FT_LOCAL_DEF( FT_Error )
  1543. TT_Load_Glyph( TT_Size size,
  1544. TT_GlyphSlot glyph,
  1545. FT_UInt glyph_index,
  1546. FT_Int32 load_flags )
  1547. {
  1548. TT_Face face;
  1549. FT_Error error;
  1550. TT_LoaderRec loader;
  1551. face = (TT_Face)glyph->face;
  1552. error = TT_Err_Ok;
  1553. #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
  1554. /* try to load embedded bitmap if any */
  1555. /* */
  1556. /* XXX: The convention should be emphasized in */
  1557. /* the documents because it can be confusing. */
  1558. if ( size->strike_index != 0xFFFFFFFFUL &&
  1559. ( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
  1560. {
  1561. error = load_sbit_image( size, glyph, glyph_index, load_flags );
  1562. if ( !error )
  1563. {
  1564. FT_Face root = &face->root;
  1565. if ( FT_IS_SCALABLE( root ) )
  1566. {
  1567. /* for the bbox we need the header only */
  1568. (void)tt_loader_init( &loader, size, glyph, load_flags, TRUE );
  1569. (void)load_truetype_glyph( &loader, glyph_index, 0, TRUE );
  1570. glyph->linearHoriAdvance = loader.linear;
  1571. glyph->linearVertAdvance = loader.top_bearing + loader.bbox.yMax -
  1572. loader.vadvance;
  1573. }
  1574. return TT_Err_Ok;
  1575. }
  1576. }
  1577. #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
  1578. /* if FT_LOAD_NO_SCALE is not set, `ttmetrics' must be valid */
  1579. if ( !( load_flags & FT_LOAD_NO_SCALE ) && !size->ttmetrics.valid )
  1580. return TT_Err_Invalid_Size_Handle;
  1581. if ( load_flags & FT_LOAD_SBITS_ONLY )
  1582. return TT_Err_Invalid_Argument;
  1583. error = tt_loader_init( &loader, size, glyph, load_flags, FALSE );
  1584. if ( error )
  1585. return error;
  1586. glyph->format = FT_GLYPH_FORMAT_OUTLINE;
  1587. glyph->num_subglyphs = 0;
  1588. glyph->outline.flags = 0;
  1589. /* main loading loop */
  1590. error = load_truetype_glyph( &loader, glyph_index, 0, FALSE );
  1591. if ( !error )
  1592. {
  1593. if ( glyph->format == FT_GLYPH_FORMAT_COMPOSITE )
  1594. {
  1595. glyph->num_subglyphs = loader.gloader->base.num_subglyphs;
  1596. glyph->subglyphs = loader.gloader->base.subglyphs;
  1597. }
  1598. else
  1599. {
  1600. glyph->outline = loader.gloader->base.outline;
  1601. glyph->outline.flags &= ~FT_OUTLINE_SINGLE_PASS;
  1602. /* Translate array so that (0,0) is the glyph's origin. Note */
  1603. /* that this behaviour is independent on the value of bit 1 of */
  1604. /* the `flags' field in the `head' table -- at least major */
  1605. /* applications like Acroread indicate that. */
  1606. if ( loader.pp1.x )
  1607. FT_Outline_Translate( &glyph->outline, -loader.pp1.x, 0 );
  1608. }
  1609. #ifdef TT_USE_BYTECODE_INTERPRETER
  1610. if ( IS_HINTED( load_flags ) )
  1611. {
  1612. if ( loader.exec->GS.scan_control )
  1613. {
  1614. /* convert scan conversion mode to FT_OUTLINE_XXX flags */
  1615. switch ( loader.exec->GS.scan_type )
  1616. {
  1617. case 0: /* simple drop-outs including stubs */
  1618. glyph->outline.flags |= FT_OUTLINE_INCLUDE_STUBS;
  1619. break;
  1620. case 1: /* simple drop-outs excluding stubs */
  1621. /* nothing; it's the default rendering mode */
  1622. break;
  1623. case 4: /* smart drop-outs including stubs */
  1624. glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS |
  1625. FT_OUTLINE_INCLUDE_STUBS;
  1626. break;
  1627. case 5: /* smart drop-outs excluding stubs */
  1628. glyph->outline.flags |= FT_OUTLINE_SMART_DROPOUTS;
  1629. break;
  1630. default: /* no drop-out control */
  1631. glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS;
  1632. break;
  1633. }
  1634. }
  1635. else
  1636. glyph->outline.flags |= FT_OUTLINE_IGNORE_DROPOUTS;
  1637. }
  1638. #endif /* TT_USE_BYTECODE_INTERPRETER */
  1639. compute_glyph_metrics( &loader, glyph_index );
  1640. }
  1641. /* Set the `high precision' bit flag. */
  1642. /* This is _critical_ to get correct output for monochrome */
  1643. /* TrueType glyphs at all sizes using the bytecode interpreter. */
  1644. /* */
  1645. if ( !( load_flags & FT_LOAD_NO_SCALE ) &&
  1646. size->root.metrics.y_ppem < 24 )
  1647. glyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
  1648. return error;
  1649. }
  1650. /* END */