/src/3rdparty/freetype/src/truetype/ttinterp.c

https://bitbucket.org/ultra_iter/qt-vtl · C · 7828 lines · 4619 code · 1510 blank · 1699 comment · 555 complexity · df3230a96bde7acccab615c24d4a044b MD5 · raw file

Large files are truncated click here to view the full file

  1. /***************************************************************************/
  2. /* */
  3. /* ttinterp.c */
  4. /* */
  5. /* TrueType bytecode interpreter (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_CALC_H
  20. #include FT_TRIGONOMETRY_H
  21. #include FT_SYSTEM_H
  22. #include "ttinterp.h"
  23. #include "tterrors.h"
  24. #ifdef TT_USE_BYTECODE_INTERPRETER
  25. #define TT_MULFIX FT_MulFix
  26. #define TT_MULDIV FT_MulDiv
  27. #define TT_MULDIV_NO_ROUND FT_MulDiv_No_Round
  28. /*************************************************************************/
  29. /* */
  30. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  31. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  32. /* messages during execution. */
  33. /* */
  34. #undef FT_COMPONENT
  35. #define FT_COMPONENT trace_ttinterp
  36. /*************************************************************************/
  37. /* */
  38. /* In order to detect infinite loops in the code, we set up a counter */
  39. /* within the run loop. A single stroke of interpretation is now */
  40. /* limited to a maximal number of opcodes defined below. */
  41. /* */
  42. #define MAX_RUNNABLE_OPCODES 1000000L
  43. /*************************************************************************/
  44. /* */
  45. /* There are two kinds of implementations: */
  46. /* */
  47. /* a. static implementation */
  48. /* */
  49. /* The current execution context is a static variable, which fields */
  50. /* are accessed directly by the interpreter during execution. The */
  51. /* context is named `cur'. */
  52. /* */
  53. /* This version is non-reentrant, of course. */
  54. /* */
  55. /* b. indirect implementation */
  56. /* */
  57. /* The current execution context is passed to _each_ function as its */
  58. /* first argument, and each field is thus accessed indirectly. */
  59. /* */
  60. /* This version is fully re-entrant. */
  61. /* */
  62. /* The idea is that an indirect implementation may be slower to execute */
  63. /* on low-end processors that are used in some systems (like 386s or */
  64. /* even 486s). */
  65. /* */
  66. /* As a consequence, the indirect implementation is now the default, as */
  67. /* its performance costs can be considered negligible in our context. */
  68. /* Note, however, that we kept the same source with macros because: */
  69. /* */
  70. /* - The code is kept very close in design to the Pascal code used for */
  71. /* development. */
  72. /* */
  73. /* - It's much more readable that way! */
  74. /* */
  75. /* - It's still open to experimentation and tuning. */
  76. /* */
  77. /*************************************************************************/
  78. #ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */
  79. #define CUR (*exc) /* see ttobjs.h */
  80. /*************************************************************************/
  81. /* */
  82. /* This macro is used whenever `exec' is unused in a function, to avoid */
  83. /* stupid warnings from pedantic compilers. */
  84. /* */
  85. #define FT_UNUSED_EXEC FT_UNUSED( exc )
  86. #else /* static implementation */
  87. #define CUR cur
  88. #define FT_UNUSED_EXEC int __dummy = __dummy
  89. static
  90. TT_ExecContextRec cur; /* static exec. context variable */
  91. /* apparently, we have a _lot_ of direct indexing when accessing */
  92. /* the static `cur', which makes the code bigger (due to all the */
  93. /* four bytes addresses). */
  94. #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
  95. /*************************************************************************/
  96. /* */
  97. /* The instruction argument stack. */
  98. /* */
  99. #define INS_ARG EXEC_OP_ FT_Long* args /* see ttobjs.h for EXEC_OP_ */
  100. /*************************************************************************/
  101. /* */
  102. /* This macro is used whenever `args' is unused in a function, to avoid */
  103. /* stupid warnings from pedantic compilers. */
  104. /* */
  105. #define FT_UNUSED_ARG FT_UNUSED_EXEC; FT_UNUSED( args )
  106. /*************************************************************************/
  107. /* */
  108. /* The following macros hide the use of EXEC_ARG and EXEC_ARG_ to */
  109. /* increase readability of the code. */
  110. /* */
  111. /*************************************************************************/
  112. #define SKIP_Code() \
  113. SkipCode( EXEC_ARG )
  114. #define GET_ShortIns() \
  115. GetShortIns( EXEC_ARG )
  116. #define NORMalize( x, y, v ) \
  117. Normalize( EXEC_ARG_ x, y, v )
  118. #define SET_SuperRound( scale, flags ) \
  119. SetSuperRound( EXEC_ARG_ scale, flags )
  120. #define ROUND_None( d, c ) \
  121. Round_None( EXEC_ARG_ d, c )
  122. #define INS_Goto_CodeRange( range, ip ) \
  123. Ins_Goto_CodeRange( EXEC_ARG_ range, ip )
  124. #define CUR_Func_move( z, p, d ) \
  125. CUR.func_move( EXEC_ARG_ z, p, d )
  126. #define CUR_Func_move_orig( z, p, d ) \
  127. CUR.func_move_orig( EXEC_ARG_ z, p, d )
  128. #define CUR_Func_round( d, c ) \
  129. CUR.func_round( EXEC_ARG_ d, c )
  130. #define CUR_Func_read_cvt( index ) \
  131. CUR.func_read_cvt( EXEC_ARG_ index )
  132. #define CUR_Func_write_cvt( index, val ) \
  133. CUR.func_write_cvt( EXEC_ARG_ index, val )
  134. #define CUR_Func_move_cvt( index, val ) \
  135. CUR.func_move_cvt( EXEC_ARG_ index, val )
  136. #define CURRENT_Ratio() \
  137. Current_Ratio( EXEC_ARG )
  138. #define CURRENT_Ppem() \
  139. Current_Ppem( EXEC_ARG )
  140. #define CUR_Ppem() \
  141. Cur_PPEM( EXEC_ARG )
  142. #define INS_SxVTL( a, b, c, d ) \
  143. Ins_SxVTL( EXEC_ARG_ a, b, c, d )
  144. #define COMPUTE_Funcs() \
  145. Compute_Funcs( EXEC_ARG )
  146. #define COMPUTE_Round( a ) \
  147. Compute_Round( EXEC_ARG_ a )
  148. #define COMPUTE_Point_Displacement( a, b, c, d ) \
  149. Compute_Point_Displacement( EXEC_ARG_ a, b, c, d )
  150. #define MOVE_Zp2_Point( a, b, c, t ) \
  151. Move_Zp2_Point( EXEC_ARG_ a, b, c, t )
  152. #define CUR_Func_project( v1, v2 ) \
  153. CUR.func_project( EXEC_ARG_ (v1)->x - (v2)->x, (v1)->y - (v2)->y )
  154. #define CUR_Func_dualproj( v1, v2 ) \
  155. CUR.func_dualproj( EXEC_ARG_ (v1)->x - (v2)->x, (v1)->y - (v2)->y )
  156. #define CUR_fast_project( v ) \
  157. CUR.func_project( EXEC_ARG_ (v)->x, (v)->y )
  158. #define CUR_fast_dualproj( v ) \
  159. CUR.func_dualproj( EXEC_ARG_ (v)->x, (v)->y )
  160. /*************************************************************************/
  161. /* */
  162. /* Instruction dispatch function, as used by the interpreter. */
  163. /* */
  164. typedef void (*TInstruction_Function)( INS_ARG );
  165. /*************************************************************************/
  166. /* */
  167. /* A simple bounds-checking macro. */
  168. /* */
  169. #define BOUNDS( x, n ) ( (FT_UInt)(x) >= (FT_UInt)(n) )
  170. #undef SUCCESS
  171. #define SUCCESS 0
  172. #undef FAILURE
  173. #define FAILURE 1
  174. #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  175. #define GUESS_VECTOR( V ) \
  176. if ( CUR.face->unpatented_hinting ) \
  177. { \
  178. CUR.GS.V.x = (FT_F2Dot14)( CUR.GS.both_x_axis ? 0x4000 : 0 ); \
  179. CUR.GS.V.y = (FT_F2Dot14)( CUR.GS.both_x_axis ? 0 : 0x4000 ); \
  180. }
  181. #else
  182. #define GUESS_VECTOR( V )
  183. #endif
  184. /*************************************************************************/
  185. /* */
  186. /* CODERANGE FUNCTIONS */
  187. /* */
  188. /*************************************************************************/
  189. /*************************************************************************/
  190. /* */
  191. /* <Function> */
  192. /* TT_Goto_CodeRange */
  193. /* */
  194. /* <Description> */
  195. /* Switches to a new code range (updates the code related elements in */
  196. /* `exec', and `IP'). */
  197. /* */
  198. /* <Input> */
  199. /* range :: The new execution code range. */
  200. /* */
  201. /* IP :: The new IP in the new code range. */
  202. /* */
  203. /* <InOut> */
  204. /* exec :: The target execution context. */
  205. /* */
  206. /* <Return> */
  207. /* FreeType error code. 0 means success. */
  208. /* */
  209. FT_LOCAL_DEF( FT_Error )
  210. TT_Goto_CodeRange( TT_ExecContext exec,
  211. FT_Int range,
  212. FT_Long IP )
  213. {
  214. TT_CodeRange* coderange;
  215. FT_ASSERT( range >= 1 && range <= 3 );
  216. coderange = &exec->codeRangeTable[range - 1];
  217. FT_ASSERT( coderange->base != NULL );
  218. /* NOTE: Because the last instruction of a program may be a CALL */
  219. /* which will return to the first byte *after* the code */
  220. /* range, we test for IP <= Size instead of IP < Size. */
  221. /* */
  222. FT_ASSERT( (FT_ULong)IP <= coderange->size );
  223. exec->code = coderange->base;
  224. exec->codeSize = coderange->size;
  225. exec->IP = IP;
  226. exec->curRange = range;
  227. return TT_Err_Ok;
  228. }
  229. /*************************************************************************/
  230. /* */
  231. /* <Function> */
  232. /* TT_Set_CodeRange */
  233. /* */
  234. /* <Description> */
  235. /* Sets a code range. */
  236. /* */
  237. /* <Input> */
  238. /* range :: The code range index. */
  239. /* */
  240. /* base :: The new code base. */
  241. /* */
  242. /* length :: The range size in bytes. */
  243. /* */
  244. /* <InOut> */
  245. /* exec :: The target execution context. */
  246. /* */
  247. /* <Return> */
  248. /* FreeType error code. 0 means success. */
  249. /* */
  250. FT_LOCAL_DEF( FT_Error )
  251. TT_Set_CodeRange( TT_ExecContext exec,
  252. FT_Int range,
  253. void* base,
  254. FT_Long length )
  255. {
  256. FT_ASSERT( range >= 1 && range <= 3 );
  257. exec->codeRangeTable[range - 1].base = (FT_Byte*)base;
  258. exec->codeRangeTable[range - 1].size = length;
  259. return TT_Err_Ok;
  260. }
  261. /*************************************************************************/
  262. /* */
  263. /* <Function> */
  264. /* TT_Clear_CodeRange */
  265. /* */
  266. /* <Description> */
  267. /* Clears a code range. */
  268. /* */
  269. /* <Input> */
  270. /* range :: The code range index. */
  271. /* */
  272. /* <InOut> */
  273. /* exec :: The target execution context. */
  274. /* */
  275. /* <Return> */
  276. /* FreeType error code. 0 means success. */
  277. /* */
  278. /* <Note> */
  279. /* Does not set the Error variable. */
  280. /* */
  281. FT_LOCAL_DEF( FT_Error )
  282. TT_Clear_CodeRange( TT_ExecContext exec,
  283. FT_Int range )
  284. {
  285. FT_ASSERT( range >= 1 && range <= 3 );
  286. exec->codeRangeTable[range - 1].base = NULL;
  287. exec->codeRangeTable[range - 1].size = 0;
  288. return TT_Err_Ok;
  289. }
  290. /*************************************************************************/
  291. /* */
  292. /* EXECUTION CONTEXT ROUTINES */
  293. /* */
  294. /*************************************************************************/
  295. /*************************************************************************/
  296. /* */
  297. /* <Function> */
  298. /* TT_Done_Context */
  299. /* */
  300. /* <Description> */
  301. /* Destroys a given context. */
  302. /* */
  303. /* <Input> */
  304. /* exec :: A handle to the target execution context. */
  305. /* */
  306. /* memory :: A handle to the parent memory object. */
  307. /* */
  308. /* <Return> */
  309. /* FreeType error code. 0 means success. */
  310. /* */
  311. /* <Note> */
  312. /* Only the glyph loader and debugger should call this function. */
  313. /* */
  314. FT_LOCAL_DEF( FT_Error )
  315. TT_Done_Context( TT_ExecContext exec )
  316. {
  317. FT_Memory memory = exec->memory;
  318. /* points zone */
  319. exec->maxPoints = 0;
  320. exec->maxContours = 0;
  321. /* free stack */
  322. FT_FREE( exec->stack );
  323. exec->stackSize = 0;
  324. /* free call stack */
  325. FT_FREE( exec->callStack );
  326. exec->callSize = 0;
  327. exec->callTop = 0;
  328. /* free glyph code range */
  329. FT_FREE( exec->glyphIns );
  330. exec->glyphSize = 0;
  331. exec->size = NULL;
  332. exec->face = NULL;
  333. FT_FREE( exec );
  334. return TT_Err_Ok;
  335. }
  336. /*************************************************************************/
  337. /* */
  338. /* <Function> */
  339. /* Init_Context */
  340. /* */
  341. /* <Description> */
  342. /* Initializes a context object. */
  343. /* */
  344. /* <Input> */
  345. /* memory :: A handle to the parent memory object. */
  346. /* */
  347. /* <InOut> */
  348. /* exec :: A handle to the target execution context. */
  349. /* */
  350. /* <Return> */
  351. /* FreeType error code. 0 means success. */
  352. /* */
  353. static FT_Error
  354. Init_Context( TT_ExecContext exec,
  355. FT_Memory memory )
  356. {
  357. FT_Error error;
  358. FT_TRACE1(( "Init_Context: new object at 0x%08p\n", exec ));
  359. exec->memory = memory;
  360. exec->callSize = 32;
  361. if ( FT_NEW_ARRAY( exec->callStack, exec->callSize ) )
  362. goto Fail_Memory;
  363. /* all values in the context are set to 0 already, but this is */
  364. /* here as a remainder */
  365. exec->maxPoints = 0;
  366. exec->maxContours = 0;
  367. exec->stackSize = 0;
  368. exec->glyphSize = 0;
  369. exec->stack = NULL;
  370. exec->glyphIns = NULL;
  371. exec->face = NULL;
  372. exec->size = NULL;
  373. return TT_Err_Ok;
  374. Fail_Memory:
  375. FT_ERROR(( "Init_Context: not enough memory for 0x%08lx\n",
  376. (FT_Long)exec ));
  377. TT_Done_Context( exec );
  378. return error;
  379. }
  380. /*************************************************************************/
  381. /* */
  382. /* <Function> */
  383. /* Update_Max */
  384. /* */
  385. /* <Description> */
  386. /* Checks the size of a buffer and reallocates it if necessary. */
  387. /* */
  388. /* <Input> */
  389. /* memory :: A handle to the parent memory object. */
  390. /* */
  391. /* multiplier :: The size in bytes of each element in the buffer. */
  392. /* */
  393. /* new_max :: The new capacity (size) of the buffer. */
  394. /* */
  395. /* <InOut> */
  396. /* size :: The address of the buffer's current size expressed */
  397. /* in elements. */
  398. /* */
  399. /* buff :: The address of the buffer base pointer. */
  400. /* */
  401. /* <Return> */
  402. /* FreeType error code. 0 means success. */
  403. /* */
  404. static FT_Error
  405. Update_Max( FT_Memory memory,
  406. FT_ULong* size,
  407. FT_Long multiplier,
  408. void* _pbuff,
  409. FT_ULong new_max )
  410. {
  411. FT_Error error;
  412. void** pbuff = (void**)_pbuff;
  413. if ( *size < new_max )
  414. {
  415. if ( FT_REALLOC( *pbuff, *size * multiplier, new_max * multiplier ) )
  416. return error;
  417. *size = new_max;
  418. }
  419. return TT_Err_Ok;
  420. }
  421. /*************************************************************************/
  422. /* */
  423. /* <Function> */
  424. /* TT_Load_Context */
  425. /* */
  426. /* <Description> */
  427. /* Prepare an execution context for glyph hinting. */
  428. /* */
  429. /* <Input> */
  430. /* face :: A handle to the source face object. */
  431. /* */
  432. /* size :: A handle to the source size object. */
  433. /* */
  434. /* <InOut> */
  435. /* exec :: A handle to the target execution context. */
  436. /* */
  437. /* <Return> */
  438. /* FreeType error code. 0 means success. */
  439. /* */
  440. /* <Note> */
  441. /* Only the glyph loader and debugger should call this function. */
  442. /* */
  443. FT_LOCAL_DEF( FT_Error )
  444. TT_Load_Context( TT_ExecContext exec,
  445. TT_Face face,
  446. TT_Size size )
  447. {
  448. FT_Int i;
  449. FT_ULong tmp;
  450. TT_MaxProfile* maxp;
  451. FT_Error error;
  452. exec->face = face;
  453. maxp = &face->max_profile;
  454. exec->size = size;
  455. if ( size )
  456. {
  457. exec->numFDefs = size->num_function_defs;
  458. exec->maxFDefs = size->max_function_defs;
  459. exec->numIDefs = size->num_instruction_defs;
  460. exec->maxIDefs = size->max_instruction_defs;
  461. exec->FDefs = size->function_defs;
  462. exec->IDefs = size->instruction_defs;
  463. exec->tt_metrics = size->ttmetrics;
  464. exec->metrics = size->metrics;
  465. exec->maxFunc = size->max_func;
  466. exec->maxIns = size->max_ins;
  467. for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
  468. exec->codeRangeTable[i] = size->codeRangeTable[i];
  469. /* set graphics state */
  470. exec->GS = size->GS;
  471. exec->cvtSize = size->cvt_size;
  472. exec->cvt = size->cvt;
  473. exec->storeSize = size->storage_size;
  474. exec->storage = size->storage;
  475. exec->twilight = size->twilight;
  476. }
  477. /* XXX: We reserve a little more elements on the stack to deal safely */
  478. /* with broken fonts like arialbs, courbs, timesbs, etc. */
  479. tmp = exec->stackSize;
  480. error = Update_Max( exec->memory,
  481. &tmp,
  482. sizeof ( FT_F26Dot6 ),
  483. (void*)&exec->stack,
  484. maxp->maxStackElements + 32 );
  485. exec->stackSize = (FT_UInt)tmp;
  486. if ( error )
  487. return error;
  488. tmp = exec->glyphSize;
  489. error = Update_Max( exec->memory,
  490. &tmp,
  491. sizeof ( FT_Byte ),
  492. (void*)&exec->glyphIns,
  493. maxp->maxSizeOfInstructions );
  494. exec->glyphSize = (FT_UShort)tmp;
  495. if ( error )
  496. return error;
  497. exec->pts.n_points = 0;
  498. exec->pts.n_contours = 0;
  499. exec->zp1 = exec->pts;
  500. exec->zp2 = exec->pts;
  501. exec->zp0 = exec->pts;
  502. exec->instruction_trap = FALSE;
  503. return TT_Err_Ok;
  504. }
  505. /*************************************************************************/
  506. /* */
  507. /* <Function> */
  508. /* TT_Save_Context */
  509. /* */
  510. /* <Description> */
  511. /* Saves the code ranges in a `size' object. */
  512. /* */
  513. /* <Input> */
  514. /* exec :: A handle to the source execution context. */
  515. /* */
  516. /* <InOut> */
  517. /* size :: A handle to the target size object. */
  518. /* */
  519. /* <Return> */
  520. /* FreeType error code. 0 means success. */
  521. /* */
  522. /* <Note> */
  523. /* Only the glyph loader and debugger should call this function. */
  524. /* */
  525. FT_LOCAL_DEF( FT_Error )
  526. TT_Save_Context( TT_ExecContext exec,
  527. TT_Size size )
  528. {
  529. FT_Int i;
  530. /* XXXX: Will probably disappear soon with all the code range */
  531. /* management, which is now rather obsolete. */
  532. /* */
  533. size->num_function_defs = exec->numFDefs;
  534. size->num_instruction_defs = exec->numIDefs;
  535. size->max_func = exec->maxFunc;
  536. size->max_ins = exec->maxIns;
  537. for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
  538. size->codeRangeTable[i] = exec->codeRangeTable[i];
  539. return TT_Err_Ok;
  540. }
  541. /*************************************************************************/
  542. /* */
  543. /* <Function> */
  544. /* TT_Run_Context */
  545. /* */
  546. /* <Description> */
  547. /* Executes one or more instructions in the execution context. */
  548. /* */
  549. /* <Input> */
  550. /* debug :: A Boolean flag. If set, the function sets some internal */
  551. /* variables and returns immediately, otherwise TT_RunIns() */
  552. /* is called. */
  553. /* */
  554. /* This is commented out currently. */
  555. /* */
  556. /* <Input> */
  557. /* exec :: A handle to the target execution context. */
  558. /* */
  559. /* <Return> */
  560. /* TrueType error code. 0 means success. */
  561. /* */
  562. /* <Note> */
  563. /* Only the glyph loader and debugger should call this function. */
  564. /* */
  565. FT_LOCAL_DEF( FT_Error )
  566. TT_Run_Context( TT_ExecContext exec,
  567. FT_Bool debug )
  568. {
  569. FT_Error error;
  570. if ( ( error = TT_Goto_CodeRange( exec, tt_coderange_glyph, 0 ) )
  571. != TT_Err_Ok )
  572. return error;
  573. exec->zp0 = exec->pts;
  574. exec->zp1 = exec->pts;
  575. exec->zp2 = exec->pts;
  576. exec->GS.gep0 = 1;
  577. exec->GS.gep1 = 1;
  578. exec->GS.gep2 = 1;
  579. exec->GS.projVector.x = 0x4000;
  580. exec->GS.projVector.y = 0x0000;
  581. exec->GS.freeVector = exec->GS.projVector;
  582. exec->GS.dualVector = exec->GS.projVector;
  583. #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  584. exec->GS.both_x_axis = TRUE;
  585. #endif
  586. exec->GS.round_state = 1;
  587. exec->GS.loop = 1;
  588. /* some glyphs leave something on the stack. so we clean it */
  589. /* before a new execution. */
  590. exec->top = 0;
  591. exec->callTop = 0;
  592. #if 1
  593. FT_UNUSED( debug );
  594. return exec->face->interpreter( exec );
  595. #else
  596. if ( !debug )
  597. return TT_RunIns( exec );
  598. else
  599. return TT_Err_Ok;
  600. #endif
  601. }
  602. /* The default value for `scan_control' is documented as FALSE in the */
  603. /* TrueType specification. This is confusing since it implies a */
  604. /* Boolean value. However, this is not the case, thus both the */
  605. /* default values of our `scan_type' and `scan_control' fields (which */
  606. /* the documentation's `scan_control' variable is split into) are */
  607. /* zero. */
  608. const TT_GraphicsState tt_default_graphics_state =
  609. {
  610. 0, 0, 0,
  611. { 0x4000, 0 },
  612. { 0x4000, 0 },
  613. { 0x4000, 0 },
  614. #ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
  615. TRUE,
  616. #endif
  617. 1, 64, 1,
  618. TRUE, 68, 0, 0, 9, 3,
  619. 0, FALSE, 0, 1, 1, 1
  620. };
  621. /* documentation is in ttinterp.h */
  622. FT_EXPORT_DEF( TT_ExecContext )
  623. TT_New_Context( TT_Driver driver )
  624. {
  625. TT_ExecContext exec;
  626. FT_Memory memory;
  627. memory = driver->root.root.memory;
  628. exec = driver->context;
  629. if ( !driver->context )
  630. {
  631. FT_Error error;
  632. /* allocate object */
  633. if ( FT_NEW( exec ) )
  634. goto Exit;
  635. /* initialize it */
  636. error = Init_Context( exec, memory );
  637. if ( error )
  638. goto Fail;
  639. /* store it into the driver */
  640. driver->context = exec;
  641. }
  642. Exit:
  643. return driver->context;
  644. Fail:
  645. return 0;
  646. }
  647. /*************************************************************************/
  648. /* */
  649. /* Before an opcode is executed, the interpreter verifies that there are */
  650. /* enough arguments on the stack, with the help of the `Pop_Push_Count' */
  651. /* table. */
  652. /* */
  653. /* For each opcode, the first column gives the number of arguments that */
  654. /* are popped from the stack; the second one gives the number of those */
  655. /* that are pushed in result. */
  656. /* */
  657. /* Opcodes which have a varying number of parameters in the data stream */
  658. /* (NPUSHB, NPUSHW) are handled specially; they have a negative value in */
  659. /* the `opcode_length' table, and the value in `Pop_Push_Count' is set */
  660. /* to zero. */
  661. /* */
  662. /*************************************************************************/
  663. #undef PACK
  664. #define PACK( x, y ) ( ( x << 4 ) | y )
  665. static
  666. const FT_Byte Pop_Push_Count[256] =
  667. {
  668. /* opcodes are gathered in groups of 16 */
  669. /* please keep the spaces as they are */
  670. /* SVTCA y */ PACK( 0, 0 ),
  671. /* SVTCA x */ PACK( 0, 0 ),
  672. /* SPvTCA y */ PACK( 0, 0 ),
  673. /* SPvTCA x */ PACK( 0, 0 ),
  674. /* SFvTCA y */ PACK( 0, 0 ),
  675. /* SFvTCA x */ PACK( 0, 0 ),
  676. /* SPvTL // */ PACK( 2, 0 ),
  677. /* SPvTL + */ PACK( 2, 0 ),
  678. /* SFvTL // */ PACK( 2, 0 ),
  679. /* SFvTL + */ PACK( 2, 0 ),
  680. /* SPvFS */ PACK( 2, 0 ),
  681. /* SFvFS */ PACK( 2, 0 ),
  682. /* GPV */ PACK( 0, 2 ),
  683. /* GFV */ PACK( 0, 2 ),
  684. /* SFvTPv */ PACK( 0, 0 ),
  685. /* ISECT */ PACK( 5, 0 ),
  686. /* SRP0 */ PACK( 1, 0 ),
  687. /* SRP1 */ PACK( 1, 0 ),
  688. /* SRP2 */ PACK( 1, 0 ),
  689. /* SZP0 */ PACK( 1, 0 ),
  690. /* SZP1 */ PACK( 1, 0 ),
  691. /* SZP2 */ PACK( 1, 0 ),
  692. /* SZPS */ PACK( 1, 0 ),
  693. /* SLOOP */ PACK( 1, 0 ),
  694. /* RTG */ PACK( 0, 0 ),
  695. /* RTHG */ PACK( 0, 0 ),
  696. /* SMD */ PACK( 1, 0 ),
  697. /* ELSE */ PACK( 0, 0 ),
  698. /* JMPR */ PACK( 1, 0 ),
  699. /* SCvTCi */ PACK( 1, 0 ),
  700. /* SSwCi */ PACK( 1, 0 ),
  701. /* SSW */ PACK( 1, 0 ),
  702. /* DUP */ PACK( 1, 2 ),
  703. /* POP */ PACK( 1, 0 ),
  704. /* CLEAR */ PACK( 0, 0 ),
  705. /* SWAP */ PACK( 2, 2 ),
  706. /* DEPTH */ PACK( 0, 1 ),
  707. /* CINDEX */ PACK( 1, 1 ),
  708. /* MINDEX */ PACK( 1, 0 ),
  709. /* AlignPTS */ PACK( 2, 0 ),
  710. /* INS_$28 */ PACK( 0, 0 ),
  711. /* UTP */ PACK( 1, 0 ),
  712. /* LOOPCALL */ PACK( 2, 0 ),
  713. /* CALL */ PACK( 1, 0 ),
  714. /* FDEF */ PACK( 1, 0 ),
  715. /* ENDF */ PACK( 0, 0 ),
  716. /* MDAP[0] */ PACK( 1, 0 ),
  717. /* MDAP[1] */ PACK( 1, 0 ),
  718. /* IUP[0] */ PACK( 0, 0 ),
  719. /* IUP[1] */ PACK( 0, 0 ),
  720. /* SHP[0] */ PACK( 0, 0 ),
  721. /* SHP[1] */ PACK( 0, 0 ),
  722. /* SHC[0] */ PACK( 1, 0 ),
  723. /* SHC[1] */ PACK( 1, 0 ),
  724. /* SHZ[0] */ PACK( 1, 0 ),
  725. /* SHZ[1] */ PACK( 1, 0 ),
  726. /* SHPIX */ PACK( 1, 0 ),
  727. /* IP */ PACK( 0, 0 ),
  728. /* MSIRP[0] */ PACK( 2, 0 ),
  729. /* MSIRP[1] */ PACK( 2, 0 ),
  730. /* AlignRP */ PACK( 0, 0 ),
  731. /* RTDG */ PACK( 0, 0 ),
  732. /* MIAP[0] */ PACK( 2, 0 ),
  733. /* MIAP[1] */ PACK( 2, 0 ),
  734. /* NPushB */ PACK( 0, 0 ),
  735. /* NPushW */ PACK( 0, 0 ),
  736. /* WS */ PACK( 2, 0 ),
  737. /* RS */ PACK( 1, 1 ),
  738. /* WCvtP */ PACK( 2, 0 ),
  739. /* RCvt */ PACK( 1, 1 ),
  740. /* GC[0] */ PACK( 1, 1 ),
  741. /* GC[1] */ PACK( 1, 1 ),
  742. /* SCFS */ PACK( 2, 0 ),
  743. /* MD[0] */ PACK( 2, 1 ),
  744. /* MD[1] */ PACK( 2, 1 ),
  745. /* MPPEM */ PACK( 0, 1 ),
  746. /* MPS */ PACK( 0, 1 ),
  747. /* FlipON */ PACK( 0, 0 ),
  748. /* FlipOFF */ PACK( 0, 0 ),
  749. /* DEBUG */ PACK( 1, 0 ),
  750. /* LT */ PACK( 2, 1 ),
  751. /* LTEQ */ PACK( 2, 1 ),
  752. /* GT */ PACK( 2, 1 ),
  753. /* GTEQ */ PACK( 2, 1 ),
  754. /* EQ */ PACK( 2, 1 ),
  755. /* NEQ */ PACK( 2, 1 ),
  756. /* ODD */ PACK( 1, 1 ),
  757. /* EVEN */ PACK( 1, 1 ),
  758. /* IF */ PACK( 1, 0 ),
  759. /* EIF */ PACK( 0, 0 ),
  760. /* AND */ PACK( 2, 1 ),
  761. /* OR */ PACK( 2, 1 ),
  762. /* NOT */ PACK( 1, 1 ),
  763. /* DeltaP1 */ PACK( 1, 0 ),
  764. /* SDB */ PACK( 1, 0 ),
  765. /* SDS */ PACK( 1, 0 ),
  766. /* ADD */ PACK( 2, 1 ),
  767. /* SUB */ PACK( 2, 1 ),
  768. /* DIV */ PACK( 2, 1 ),
  769. /* MUL */ PACK( 2, 1 ),
  770. /* ABS */ PACK( 1, 1 ),
  771. /* NEG */ PACK( 1, 1 ),
  772. /* FLOOR */ PACK( 1, 1 ),
  773. /* CEILING */ PACK( 1, 1 ),
  774. /* ROUND[0] */ PACK( 1, 1 ),
  775. /* ROUND[1] */ PACK( 1, 1 ),
  776. /* ROUND[2] */ PACK( 1, 1 ),
  777. /* ROUND[3] */ PACK( 1, 1 ),
  778. /* NROUND[0] */ PACK( 1, 1 ),
  779. /* NROUND[1] */ PACK( 1, 1 ),
  780. /* NROUND[2] */ PACK( 1, 1 ),
  781. /* NROUND[3] */ PACK( 1, 1 ),
  782. /* WCvtF */ PACK( 2, 0 ),
  783. /* DeltaP2 */ PACK( 1, 0 ),
  784. /* DeltaP3 */ PACK( 1, 0 ),
  785. /* DeltaCn[0] */ PACK( 1, 0 ),
  786. /* DeltaCn[1] */ PACK( 1, 0 ),
  787. /* DeltaCn[2] */ PACK( 1, 0 ),
  788. /* SROUND */ PACK( 1, 0 ),
  789. /* S45Round */ PACK( 1, 0 ),
  790. /* JROT */ PACK( 2, 0 ),
  791. /* JROF */ PACK( 2, 0 ),
  792. /* ROFF */ PACK( 0, 0 ),
  793. /* INS_$7B */ PACK( 0, 0 ),
  794. /* RUTG */ PACK( 0, 0 ),
  795. /* RDTG */ PACK( 0, 0 ),
  796. /* SANGW */ PACK( 1, 0 ),
  797. /* AA */ PACK( 1, 0 ),
  798. /* FlipPT */ PACK( 0, 0 ),
  799. /* FlipRgON */ PACK( 2, 0 ),
  800. /* FlipRgOFF */ PACK( 2, 0 ),
  801. /* INS_$83 */ PACK( 0, 0 ),
  802. /* INS_$84 */ PACK( 0, 0 ),
  803. /* ScanCTRL */ PACK( 1, 0 ),
  804. /* SDVPTL[0] */ PACK( 2, 0 ),
  805. /* SDVPTL[1] */ PACK( 2, 0 ),
  806. /* GetINFO */ PACK( 1, 1 ),
  807. /* IDEF */ PACK( 1, 0 ),
  808. /* ROLL */ PACK( 3, 3 ),
  809. /* MAX */ PACK( 2, 1 ),
  810. /* MIN */ PACK( 2, 1 ),
  811. /* ScanTYPE */ PACK( 1, 0 ),
  812. /* InstCTRL */ PACK( 2, 0 ),
  813. /* INS_$8F */ PACK( 0, 0 ),
  814. /* INS_$90 */ PACK( 0, 0 ),
  815. /* INS_$91 */ PACK( 0, 0 ),
  816. /* INS_$92 */ PACK( 0, 0 ),
  817. /* INS_$93 */ PACK( 0, 0 ),
  818. /* INS_$94 */ PACK( 0, 0 ),
  819. /* INS_$95 */ PACK( 0, 0 ),
  820. /* INS_$96 */ PACK( 0, 0 ),
  821. /* INS_$97 */ PACK( 0, 0 ),
  822. /* INS_$98 */ PACK( 0, 0 ),
  823. /* INS_$99 */ PACK( 0, 0 ),
  824. /* INS_$9A */ PACK( 0, 0 ),
  825. /* INS_$9B */ PACK( 0, 0 ),
  826. /* INS_$9C */ PACK( 0, 0 ),
  827. /* INS_$9D */ PACK( 0, 0 ),
  828. /* INS_$9E */ PACK( 0, 0 ),
  829. /* INS_$9F */ PACK( 0, 0 ),
  830. /* INS_$A0 */ PACK( 0, 0 ),
  831. /* INS_$A1 */ PACK( 0, 0 ),
  832. /* INS_$A2 */ PACK( 0, 0 ),
  833. /* INS_$A3 */ PACK( 0, 0 ),
  834. /* INS_$A4 */ PACK( 0, 0 ),
  835. /* INS_$A5 */ PACK( 0, 0 ),
  836. /* INS_$A6 */ PACK( 0, 0 ),
  837. /* INS_$A7 */ PACK( 0, 0 ),
  838. /* INS_$A8 */ PACK( 0, 0 ),
  839. /* INS_$A9 */ PACK( 0, 0 ),
  840. /* INS_$AA */ PACK( 0, 0 ),
  841. /* INS_$AB */ PACK( 0, 0 ),
  842. /* INS_$AC */ PACK( 0, 0 ),
  843. /* INS_$AD */ PACK( 0, 0 ),
  844. /* INS_$AE */ PACK( 0, 0 ),
  845. /* INS_$AF */ PACK( 0, 0 ),
  846. /* PushB[0] */ PACK( 0, 1 ),
  847. /* PushB[1] */ PACK( 0, 2 ),
  848. /* PushB[2] */ PACK( 0, 3 ),
  849. /* PushB[3] */ PACK( 0, 4 ),
  850. /* PushB[4] */ PACK( 0, 5 ),
  851. /* PushB[5] */ PACK( 0, 6 ),
  852. /* PushB[6] */ PACK( 0, 7 ),
  853. /* PushB[7] */ PACK( 0, 8 ),
  854. /* PushW[0] */ PACK( 0, 1 ),
  855. /* PushW[1] */ PACK( 0, 2 ),
  856. /* PushW[2] */ PACK( 0, 3 ),
  857. /* PushW[3] */ PACK( 0, 4 ),
  858. /* PushW[4] */ PACK( 0, 5 ),
  859. /* PushW[5] */ PACK( 0, 6 ),
  860. /* PushW[6] */ PACK( 0, 7 ),
  861. /* PushW[7] */ PACK( 0, 8 ),
  862. /* MDRP[00] */ PACK( 1, 0 ),
  863. /* MDRP[01] */ PACK( 1, 0 ),
  864. /* MDRP[02] */ PACK( 1, 0 ),
  865. /* MDRP[03] */ PACK( 1, 0 ),
  866. /* MDRP[04] */ PACK( 1, 0 ),
  867. /* MDRP[05] */ PACK( 1, 0 ),
  868. /* MDRP[06] */ PACK( 1, 0 ),
  869. /* MDRP[07] */ PACK( 1, 0 ),
  870. /* MDRP[08] */ PACK( 1, 0 ),
  871. /* MDRP[09] */ PACK( 1, 0 ),
  872. /* MDRP[10] */ PACK( 1, 0 ),
  873. /* MDRP[11] */ PACK( 1, 0 ),
  874. /* MDRP[12] */ PACK( 1, 0 ),
  875. /* MDRP[13] */ PACK( 1, 0 ),
  876. /* MDRP[14] */ PACK( 1, 0 ),
  877. /* MDRP[15] */ PACK( 1, 0 ),
  878. /* MDRP[16] */ PACK( 1, 0 ),
  879. /* MDRP[17] */ PACK( 1, 0 ),
  880. /* MDRP[18] */ PACK( 1, 0 ),
  881. /* MDRP[19] */ PACK( 1, 0 ),
  882. /* MDRP[20] */ PACK( 1, 0 ),
  883. /* MDRP[21] */ PACK( 1, 0 ),
  884. /* MDRP[22] */ PACK( 1, 0 ),
  885. /* MDRP[23] */ PACK( 1, 0 ),
  886. /* MDRP[24] */ PACK( 1, 0 ),
  887. /* MDRP[25] */ PACK( 1, 0 ),
  888. /* MDRP[26] */ PACK( 1, 0 ),
  889. /* MDRP[27] */ PACK( 1, 0 ),
  890. /* MDRP[28] */ PACK( 1, 0 ),
  891. /* MDRP[29] */ PACK( 1, 0 ),
  892. /* MDRP[30] */ PACK( 1, 0 ),
  893. /* MDRP[31] */ PACK( 1, 0 ),
  894. /* MIRP[00] */ PACK( 2, 0 ),
  895. /* MIRP[01] */ PACK( 2, 0 ),
  896. /* MIRP[02] */ PACK( 2, 0 ),
  897. /* MIRP[03] */ PACK( 2, 0 ),
  898. /* MIRP[04] */ PACK( 2, 0 ),
  899. /* MIRP[05] */ PACK( 2, 0 ),
  900. /* MIRP[06] */ PACK( 2, 0 ),
  901. /* MIRP[07] */ PACK( 2, 0 ),
  902. /* MIRP[08] */ PACK( 2, 0 ),
  903. /* MIRP[09] */ PACK( 2, 0 ),
  904. /* MIRP[10] */ PACK( 2, 0 ),
  905. /* MIRP[11] */ PACK( 2, 0 ),
  906. /* MIRP[12] */ PACK( 2, 0 ),
  907. /* MIRP[13] */ PACK( 2, 0 ),
  908. /* MIRP[14] */ PACK( 2, 0 ),
  909. /* MIRP[15] */ PACK( 2, 0 ),
  910. /* MIRP[16] */ PACK( 2, 0 ),
  911. /* MIRP[17] */ PACK( 2, 0 ),
  912. /* MIRP[18] */ PACK( 2, 0 ),
  913. /* MIRP[19] */ PACK( 2, 0 ),
  914. /* MIRP[20] */ PACK( 2, 0 ),
  915. /* MIRP[21] */ PACK( 2, 0 ),
  916. /* MIRP[22] */ PACK( 2, 0 ),
  917. /* MIRP[23] */ PACK( 2, 0 ),
  918. /* MIRP[24] */ PACK( 2, 0 ),
  919. /* MIRP[25] */ PACK( 2, 0 ),
  920. /* MIRP[26] */ PACK( 2, 0 ),
  921. /* MIRP[27] */ PACK( 2, 0 ),
  922. /* MIRP[28] */ PACK( 2, 0 ),
  923. /* MIRP[29] */ PACK( 2, 0 ),
  924. /* MIRP[30] */ PACK( 2, 0 ),
  925. /* MIRP[31] */ PACK( 2, 0 )
  926. };
  927. static
  928. const FT_Char opcode_length[256] =
  929. {
  930. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  931. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  932. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  933. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  934. -1,-2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  935. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  936. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  937. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  938. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  939. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  940. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  941. 2, 3, 4, 5, 6, 7, 8, 9, 3, 5, 7, 9, 11,13,15,17,
  942. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  943. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  944. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  945. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  946. };
  947. #undef PACK
  948. #if 1
  949. static FT_Int32
  950. TT_MulFix14( FT_Int32 a,
  951. FT_Int b )
  952. {
  953. FT_Int32 sign;
  954. FT_UInt32 ah, al, mid, lo, hi;
  955. sign = a ^ b;
  956. if ( a < 0 )
  957. a = -a;
  958. if ( b < 0 )
  959. b = -b;
  960. ah = (FT_UInt32)( ( a >> 16 ) & 0xFFFFU );
  961. al = (FT_UInt32)( a & 0xFFFFU );
  962. lo = al * b;
  963. mid = ah * b;
  964. hi = mid >> 16;
  965. mid = ( mid << 16 ) + ( 1 << 13 ); /* rounding */
  966. lo += mid;
  967. if ( lo < mid )
  968. hi += 1;
  969. mid = ( lo >> 14 ) | ( hi << 18 );
  970. return sign >= 0 ? (FT_Int32)mid : -(FT_Int32)mid;
  971. }
  972. #else
  973. /* compute (a*b)/2^14 with maximal accuracy and rounding */
  974. static FT_Int32
  975. TT_MulFix14( FT_Int32 a,
  976. FT_Int b )
  977. {
  978. FT_Int32 m, s, hi;
  979. FT_UInt32 l, lo;
  980. /* compute ax*bx as 64-bit value */
  981. l = (FT_UInt32)( ( a & 0xFFFFU ) * b );
  982. m = ( a >> 16 ) * b;
  983. lo = l + (FT_UInt32)( m << 16 );
  984. hi = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo < l );
  985. /* divide the result by 2^14 with rounding */
  986. s = hi >> 31;
  987. l = lo + (FT_UInt32)s;
  988. hi += s + ( l < lo );
  989. lo = l;
  990. l = lo + 0x2000U;
  991. hi += l < lo;
  992. return ( hi << 18 ) | ( l >> 14 );
  993. }
  994. #endif
  995. /* compute (ax*bx+ay*by)/2^14 with maximal accuracy and rounding */
  996. static FT_Int32
  997. TT_DotFix14( FT_Int32 ax,
  998. FT_Int32 ay,
  999. FT_Int bx,
  1000. FT_Int by )
  1001. {
  1002. FT_Int32 m, s, hi1, hi2, hi;
  1003. FT_UInt32 l, lo1, lo2, lo;
  1004. /* compute ax*bx as 64-bit value */
  1005. l = (FT_UInt32)( ( ax & 0xFFFFU ) * bx );
  1006. m = ( ax >> 16 ) * bx;
  1007. lo1 = l + (FT_UInt32)( m << 16 );
  1008. hi1 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo1 < l );
  1009. /* compute ay*by as 64-bit value */
  1010. l = (FT_UInt32)( ( ay & 0xFFFFU ) * by );
  1011. m = ( ay >> 16 ) * by;
  1012. lo2 = l + (FT_UInt32)( m << 16 );
  1013. hi2 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo2 < l );
  1014. /* add them */
  1015. lo = lo1 + lo2;
  1016. hi = hi1 + hi2 + ( lo < lo1 );
  1017. /* divide the result by 2^14 with rounding */
  1018. s = hi >> 31;
  1019. l = lo + (FT_UInt32)s;
  1020. hi += s + ( l < lo );
  1021. lo = l;
  1022. l = lo + 0x2000U;
  1023. hi += ( l < lo );
  1024. return ( hi << 18 ) | ( l >> 14 );
  1025. }
  1026. /* return length of given vector */
  1027. #if 0
  1028. static FT_Int32
  1029. TT_VecLen( FT_Int32 x,
  1030. FT_Int32 y )
  1031. {
  1032. FT_Int32 m, hi1, hi2, hi;
  1033. FT_UInt32 l, lo1, lo2, lo;
  1034. /* compute x*x as 64-bit value */
  1035. lo = (FT_UInt32)( x & 0xFFFFU );
  1036. hi = x >> 16;
  1037. l = lo * lo;
  1038. m = hi * lo;
  1039. hi = hi * hi;
  1040. lo1 = l + (FT_UInt32)( m << 17 );
  1041. hi1 = hi + ( m >> 15 ) + ( lo1 < l );
  1042. /* compute y*y as 64-bit value */
  1043. lo = (FT_UInt32)( y & 0xFFFFU );
  1044. hi = y >> 16;
  1045. l = lo * lo;
  1046. m = hi * lo;
  1047. hi = hi * hi;
  1048. lo2 = l + (FT_UInt32)( m << 17 );
  1049. hi2 = hi + ( m >> 15 ) + ( lo2 < l );
  1050. /* add them to get 'x*x+y*y' as 64-bit value */
  1051. lo = lo1 + lo2;
  1052. hi = hi1 + hi2 + ( lo < lo1 );
  1053. /* compute the square root of this value */
  1054. {
  1055. FT_UInt32 root, rem, test_div;
  1056. FT_Int count;
  1057. root = 0;
  1058. {
  1059. rem = 0;
  1060. count = 32;
  1061. do
  1062. {
  1063. rem = ( rem << 2 ) | ( (FT_UInt32)hi >> 30 );
  1064. hi = ( hi << 2 ) | ( lo >> 30 );
  1065. lo <<= 2;
  1066. root <<= 1;
  1067. test_div = ( root << 1 ) + 1;
  1068. if ( rem >= test_