pprdrv_tt2.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. /* -*- mode: c++; c-basic-offset: 4 -*- */
  2. /*
  3. * Modified for use within matplotlib
  4. * 5 July 2007
  5. * Michael Droettboom
  6. */
  7. /*
  8. ** ~ppr/src/pprdrv/pprdrv_tt2.c
  9. ** Copyright 1995, Trinity College Computing Center.
  10. ** Written by David Chappell.
  11. **
  12. ** Permission to use, copy, modify, and distribute this software and its
  13. ** documentation for any purpose and without fee is hereby granted, provided
  14. ** that the above copyright notice appear in all copies and that both that
  15. ** copyright notice and this permission notice appear in supporting
  16. ** documentation. This software is provided "as is" without express or
  17. ** implied warranty.
  18. **
  19. ** TrueType font support. These functions allow PPR to generate
  20. ** PostScript fonts from Microsoft compatible TrueType font files.
  21. **
  22. ** The functions in this file do most of the work to convert a
  23. ** TrueType font to a type 3 PostScript font.
  24. **
  25. ** Most of the material in this file is derived from a program called
  26. ** "ttf2ps" which L. S. Ng posted to the usenet news group
  27. ** "comp.sources.postscript". The author did not provide a copyright
  28. ** notice or indicate any restrictions on use.
  29. **
  30. ** Last revised 11 July 1995.
  31. */
  32. #include <cstdlib>
  33. #include <cmath>
  34. #include <cstring>
  35. #include <memory>
  36. #include "pprdrv.h"
  37. #include "truetype.h"
  38. #include <algorithm>
  39. #include <stack>
  40. #include <list>
  41. class GlyphToType3
  42. {
  43. private:
  44. GlyphToType3& operator=(const GlyphToType3& other);
  45. GlyphToType3(const GlyphToType3& other);
  46. /* The PostScript bounding box. */
  47. int llx,lly,urx,ury;
  48. int advance_width;
  49. /* Variables to hold the character data. */
  50. int *epts_ctr; /* array of contour endpoints */
  51. int num_pts, num_ctr; /* number of points, number of coutours */
  52. FWord *xcoor, *ycoor; /* arrays of x and y coordinates */
  53. BYTE *tt_flags; /* array of TrueType flags */
  54. int stack_depth; /* A book-keeping variable for keeping track of the depth of the PS stack */
  55. bool pdf_mode;
  56. void load_char(TTFONT* font, BYTE *glyph);
  57. void stack(TTStreamWriter& stream, int new_elem);
  58. void stack_end(TTStreamWriter& stream);
  59. void PSConvert(TTStreamWriter& stream);
  60. void PSCurveto(TTStreamWriter& stream,
  61. FWord x0, FWord y0,
  62. FWord x1, FWord y1,
  63. FWord x2, FWord y2);
  64. void PSMoveto(TTStreamWriter& stream, int x, int y);
  65. void PSLineto(TTStreamWriter& stream, int x, int y);
  66. void do_composite(TTStreamWriter& stream, struct TTFONT *font, BYTE *glyph);
  67. public:
  68. GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int charindex, bool embedded = false);
  69. ~GlyphToType3();
  70. };
  71. // Each point on a TrueType contour is either on the path or off it (a
  72. // control point); here's a simple representation for building such
  73. // contours. Added by Jouni Seppänen 2012-05-27.
  74. enum Flag { ON_PATH, OFF_PATH };
  75. struct FlaggedPoint
  76. {
  77. enum Flag flag;
  78. FWord x;
  79. FWord y;
  80. FlaggedPoint(Flag flag_, FWord x_, FWord y_): flag(flag_), x(x_), y(y_) {};
  81. };
  82. double area(FWord *x, FWord *y, int n);
  83. #define sqr(x) ((x)*(x))
  84. #define NOMOREINCTR -1
  85. #define NOMOREOUTCTR -1
  86. /*
  87. ** This routine is used to break the character
  88. ** procedure up into a number of smaller
  89. ** procedures. This is necessary so as not to
  90. ** overflow the stack on certain level 1 interpreters.
  91. **
  92. ** Prepare to push another item onto the stack,
  93. ** starting a new proceedure if necessary.
  94. **
  95. ** Not all the stack depth calculations in this routine
  96. ** are perfectly accurate, but they do the job.
  97. */
  98. void GlyphToType3::stack(TTStreamWriter& stream, int new_elem)
  99. {
  100. if ( !pdf_mode && num_pts > 25 ) /* Only do something of we will */
  101. {
  102. /* have a log of points. */
  103. if (stack_depth == 0)
  104. {
  105. stream.put_char('{');
  106. stack_depth=1;
  107. }
  108. stack_depth += new_elem; /* Account for what we propose to add */
  109. if (stack_depth > 100)
  110. {
  111. stream.puts("}_e{");
  112. stack_depth = 3 + new_elem; /* A rough estimate */
  113. }
  114. }
  115. } /* end of stack() */
  116. void GlyphToType3::stack_end(TTStreamWriter& stream) /* called at end */
  117. {
  118. if ( !pdf_mode && stack_depth )
  119. {
  120. stream.puts("}_e");
  121. stack_depth=0;
  122. }
  123. } /* end of stack_end() */
  124. /*
  125. ** We call this routine to emmit the PostScript code
  126. ** for the character we have loaded with load_char().
  127. */
  128. void GlyphToType3::PSConvert(TTStreamWriter& stream)
  129. {
  130. int j, k;
  131. /* Step thru the contours.
  132. * j = index to xcoor, ycoor, tt_flags (point data)
  133. * k = index to epts_ctr (which points belong to the same contour) */
  134. for(j = k = 0; k < num_ctr; k++)
  135. {
  136. // A TrueType contour consists of on-path and off-path points.
  137. // Two consecutive on-path points are to be joined with a
  138. // line; off-path points between on-path points indicate a
  139. // quadratic spline, where the off-path point is the control
  140. // point. Two consecutive off-path points have an implicit
  141. // on-path point midway between them.
  142. std::list<FlaggedPoint> points;
  143. // Represent flags and x/y coordinates as a C++ list
  144. for (; j <= epts_ctr[k]; j++)
  145. {
  146. if (!(tt_flags[j] & 1)) {
  147. points.push_back(FlaggedPoint(OFF_PATH, xcoor[j], ycoor[j]));
  148. } else {
  149. points.push_back(FlaggedPoint(ON_PATH, xcoor[j], ycoor[j]));
  150. }
  151. }
  152. if (points.size() == 0) {
  153. // Don't try to access the last element of an empty list
  154. continue;
  155. }
  156. // For any two consecutive off-path points, insert the implied
  157. // on-path point.
  158. FlaggedPoint prev = points.back();
  159. for (std::list<FlaggedPoint>::iterator it = points.begin();
  160. it != points.end();
  161. it++)
  162. {
  163. if (prev.flag == OFF_PATH && it->flag == OFF_PATH)
  164. {
  165. points.insert(it,
  166. FlaggedPoint(ON_PATH,
  167. (prev.x + it->x) / 2,
  168. (prev.y + it->y) / 2));
  169. }
  170. prev = *it;
  171. }
  172. // Handle the wrap-around: insert a point either at the beginning
  173. // or at the end that has the same coordinates as the opposite point.
  174. // This also ensures that the initial point is ON_PATH.
  175. if (points.front().flag == OFF_PATH)
  176. {
  177. assert(points.back().flag == ON_PATH);
  178. points.insert(points.begin(), points.back());
  179. }
  180. else
  181. {
  182. assert(points.front().flag == ON_PATH);
  183. points.push_back(points.front());
  184. }
  185. // The first point
  186. stack(stream, 3);
  187. PSMoveto(stream, points.front().x, points.front().y);
  188. // Step through the remaining points
  189. std::list<FlaggedPoint>::const_iterator it = points.begin();
  190. for (it++; it != points.end(); /* incremented inside */)
  191. {
  192. const FlaggedPoint& point = *it;
  193. if (point.flag == ON_PATH)
  194. {
  195. stack(stream, 3);
  196. PSLineto(stream, point.x, point.y);
  197. it++;
  198. } else {
  199. std::list<FlaggedPoint>::const_iterator prev = it, next = it;
  200. prev--;
  201. next++;
  202. assert(prev->flag == ON_PATH);
  203. assert(next->flag == ON_PATH);
  204. stack(stream, 7);
  205. PSCurveto(stream,
  206. prev->x, prev->y,
  207. point.x, point.y,
  208. next->x, next->y);
  209. it++;
  210. it++;
  211. }
  212. }
  213. }
  214. /* Now, we can fill the whole thing. */
  215. stack(stream, 1);
  216. stream.puts( pdf_mode ? "f" : "_cl" );
  217. } /* end of PSConvert() */
  218. void GlyphToType3::PSMoveto(TTStreamWriter& stream, int x, int y)
  219. {
  220. stream.printf(pdf_mode ? "%d %d m\n" : "%d %d _m\n",
  221. x, y);
  222. }
  223. void GlyphToType3::PSLineto(TTStreamWriter& stream, int x, int y)
  224. {
  225. stream.printf(pdf_mode ? "%d %d l\n" : "%d %d _l\n",
  226. x, y);
  227. }
  228. /*
  229. ** Emit a PostScript "curveto" command, assuming the current point
  230. ** is (x0, y0), the control point of a quadratic spline is (x1, y1),
  231. ** and the endpoint is (x2, y2). Note that this requires a conversion,
  232. ** since PostScript splines are cubic.
  233. */
  234. void GlyphToType3::PSCurveto(TTStreamWriter& stream,
  235. FWord x0, FWord y0,
  236. FWord x1, FWord y1,
  237. FWord x2, FWord y2)
  238. {
  239. double sx[3], sy[3], cx[3], cy[3];
  240. sx[0] = x0;
  241. sy[0] = y0;
  242. sx[1] = x1;
  243. sy[1] = y1;
  244. sx[2] = x2;
  245. sy[2] = y2;
  246. cx[0] = (2*sx[1]+sx[0])/3;
  247. cy[0] = (2*sy[1]+sy[0])/3;
  248. cx[1] = (sx[2]+2*sx[1])/3;
  249. cy[1] = (sy[2]+2*sy[1])/3;
  250. cx[2] = sx[2];
  251. cy[2] = sy[2];
  252. stream.printf("%d %d %d %d %d %d %s\n",
  253. (int)cx[0], (int)cy[0], (int)cx[1], (int)cy[1],
  254. (int)cx[2], (int)cy[2], pdf_mode ? "c" : "_c");
  255. }
  256. /*
  257. ** Deallocate the structures which stored
  258. ** the data for the last simple glyph.
  259. */
  260. GlyphToType3::~GlyphToType3()
  261. {
  262. free(tt_flags); /* The flags array */
  263. free(xcoor); /* The X coordinates */
  264. free(ycoor); /* The Y coordinates */
  265. free(epts_ctr); /* The array of contour endpoints */
  266. }
  267. /*
  268. ** Load the simple glyph data pointed to by glyph.
  269. ** The pointer "glyph" should point 10 bytes into
  270. ** the glyph data.
  271. */
  272. void GlyphToType3::load_char(TTFONT* font, BYTE *glyph)
  273. {
  274. int x;
  275. BYTE c, ct;
  276. /* Read the contour endpoints list. */
  277. epts_ctr = (int *)calloc(num_ctr,sizeof(int));
  278. for (x = 0; x < num_ctr; x++)
  279. {
  280. epts_ctr[x] = getUSHORT(glyph);
  281. glyph += 2;
  282. }
  283. /* From the endpoint of the last contour, we can */
  284. /* determine the number of points. */
  285. num_pts = epts_ctr[num_ctr-1]+1;
  286. #ifdef DEBUG_TRUETYPE
  287. debug("num_pts=%d",num_pts);
  288. stream.printf("%% num_pts=%d\n",num_pts);
  289. #endif
  290. /* Skip the instructions. */
  291. x = getUSHORT(glyph);
  292. glyph += 2;
  293. glyph += x;
  294. /* Allocate space to hold the data. */
  295. tt_flags = (BYTE *)calloc(num_pts,sizeof(BYTE));
  296. xcoor = (FWord *)calloc(num_pts,sizeof(FWord));
  297. ycoor = (FWord *)calloc(num_pts,sizeof(FWord));
  298. /* Read the flags array, uncompressing it as we go. */
  299. /* There is danger of overflow here. */
  300. for (x = 0; x < num_pts; )
  301. {
  302. tt_flags[x++] = c = *(glyph++);
  303. if (c&8) /* If next byte is repeat count, */
  304. {
  305. ct = *(glyph++);
  306. if ( (x + ct) > num_pts )
  307. {
  308. throw TTException("Error in TT flags");
  309. }
  310. while (ct--)
  311. {
  312. tt_flags[x++] = c;
  313. }
  314. }
  315. }
  316. /* Read the x coordinates */
  317. for (x = 0; x < num_pts; x++)
  318. {
  319. if (tt_flags[x] & 2) /* one byte value with */
  320. {
  321. /* external sign */
  322. c = *(glyph++);
  323. xcoor[x] = (tt_flags[x] & 0x10) ? c : (-1 * (int)c);
  324. }
  325. else if (tt_flags[x] & 0x10) /* repeat last */
  326. {
  327. xcoor[x] = 0;
  328. }
  329. else /* two byte signed value */
  330. {
  331. xcoor[x] = getFWord(glyph);
  332. glyph+=2;
  333. }
  334. }
  335. /* Read the y coordinates */
  336. for (x = 0; x < num_pts; x++)
  337. {
  338. if (tt_flags[x] & 4) /* one byte value with */
  339. {
  340. /* external sign */
  341. c = *(glyph++);
  342. ycoor[x] = (tt_flags[x] & 0x20) ? c : (-1 * (int)c);
  343. }
  344. else if (tt_flags[x] & 0x20) /* repeat last value */
  345. {
  346. ycoor[x] = 0;
  347. }
  348. else /* two byte signed value */
  349. {
  350. ycoor[x] = getUSHORT(glyph);
  351. glyph+=2;
  352. }
  353. }
  354. /* Convert delta values to absolute values. */
  355. for (x = 1; x < num_pts; x++)
  356. {
  357. xcoor[x] += xcoor[x-1];
  358. ycoor[x] += ycoor[x-1];
  359. }
  360. for (x=0; x < num_pts; x++)
  361. {
  362. xcoor[x] = topost(xcoor[x]);
  363. ycoor[x] = topost(ycoor[x]);
  364. }
  365. } /* end of load_char() */
  366. /*
  367. ** Emmit PostScript code for a composite character.
  368. */
  369. void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYTE *glyph)
  370. {
  371. USHORT flags;
  372. USHORT glyphIndex;
  373. int arg1;
  374. int arg2;
  375. /* Once around this loop for each component. */
  376. do
  377. {
  378. flags = getUSHORT(glyph); /* read the flags word */
  379. glyph += 2;
  380. glyphIndex = getUSHORT(glyph); /* read the glyphindex word */
  381. glyph += 2;
  382. if (flags & ARG_1_AND_2_ARE_WORDS)
  383. {
  384. /* The tt spec. seems to say these are signed. */
  385. arg1 = getSHORT(glyph);
  386. glyph += 2;
  387. arg2 = getSHORT(glyph);
  388. glyph += 2;
  389. }
  390. else /* The tt spec. does not clearly indicate */
  391. {
  392. /* whether these values are signed or not. */
  393. arg1 = *(signed char *)(glyph++);
  394. arg2 = *(signed char *)(glyph++);
  395. }
  396. if (flags & WE_HAVE_A_SCALE)
  397. {
  398. glyph += 2;
  399. }
  400. else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
  401. {
  402. glyph += 4;
  403. }
  404. else if (flags & WE_HAVE_A_TWO_BY_TWO)
  405. {
  406. glyph += 8;
  407. }
  408. else
  409. {
  410. }
  411. /* Debugging */
  412. #ifdef DEBUG_TRUETYPE
  413. stream.printf("%% flags=%d, arg1=%d, arg2=%d\n",
  414. (int)flags,arg1,arg2);
  415. #endif
  416. if (pdf_mode)
  417. {
  418. if ( flags & ARGS_ARE_XY_VALUES )
  419. {
  420. /* We should have been able to use 'Do' to reference the
  421. subglyph here. However, that doesn't seem to work with
  422. xpdf or gs (only acrobat), so instead, this just includes
  423. the subglyph here inline. */
  424. stream.printf("q 1 0 0 1 %d %d cm\n", topost(arg1), topost(arg2));
  425. }
  426. else
  427. {
  428. stream.printf("%% unimplemented shift, arg1=%d, arg2=%d\n",arg1,arg2);
  429. }
  430. GlyphToType3(stream, font, glyphIndex, true);
  431. if ( flags & ARGS_ARE_XY_VALUES )
  432. {
  433. stream.printf("\nQ\n");
  434. }
  435. }
  436. else
  437. {
  438. /* If we have an (X,Y) shif and it is non-zero, */
  439. /* translate the coordinate system. */
  440. if ( flags & ARGS_ARE_XY_VALUES )
  441. {
  442. if ( arg1 != 0 || arg2 != 0 )
  443. stream.printf("gsave %d %d translate\n", topost(arg1), topost(arg2) );
  444. }
  445. else
  446. {
  447. stream.printf("%% unimplemented shift, arg1=%d, arg2=%d\n",arg1,arg2);
  448. }
  449. /* Invoke the CharStrings procedure to print the component. */
  450. stream.printf("false CharStrings /%s get exec\n",
  451. ttfont_CharStrings_getname(font,glyphIndex));
  452. /* If we translated the coordinate system, */
  453. /* put it back the way it was. */
  454. if ( flags & ARGS_ARE_XY_VALUES && (arg1 != 0 || arg2 != 0) )
  455. {
  456. stream.puts("grestore ");
  457. }
  458. }
  459. }
  460. while (flags & MORE_COMPONENTS);
  461. } /* end of do_composite() */
  462. /*
  463. ** Return a pointer to a specific glyph's data.
  464. */
  465. BYTE *find_glyph_data(struct TTFONT *font, int charindex)
  466. {
  467. ULONG off;
  468. ULONG length;
  469. /* Read the glyph offset from the index to location table. */
  470. if (font->indexToLocFormat == 0)
  471. {
  472. off = getUSHORT( font->loca_table + (charindex * 2) );
  473. off *= 2;
  474. length = getUSHORT( font->loca_table + ((charindex+1) * 2) );
  475. length *= 2;
  476. length -= off;
  477. }
  478. else
  479. {
  480. off = getULONG( font->loca_table + (charindex * 4) );
  481. length = getULONG( font->loca_table + ((charindex+1) * 4) );
  482. length -= off;
  483. }
  484. if (length > 0)
  485. {
  486. return font->glyf_table + off;
  487. }
  488. else
  489. {
  490. return (BYTE*)NULL;
  491. }
  492. } /* end of find_glyph_data() */
  493. GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int charindex, bool embedded /* = false */)
  494. {
  495. BYTE *glyph;
  496. tt_flags = NULL;
  497. xcoor = NULL;
  498. ycoor = NULL;
  499. epts_ctr = NULL;
  500. stack_depth = 0;
  501. pdf_mode = font->target_type < 0;
  502. /* Get a pointer to the data. */
  503. glyph = find_glyph_data( font, charindex );
  504. /* If the character is blank, it has no bounding box, */
  505. /* otherwise read the bounding box. */
  506. if ( glyph == (BYTE*)NULL )
  507. {
  508. llx=lly=urx=ury=0; /* A blank char has an all zero BoundingBox */
  509. num_ctr=0; /* Set this for later if()s */
  510. }
  511. else
  512. {
  513. /* Read the number of contours. */
  514. num_ctr = getSHORT(glyph);
  515. /* Read PostScript bounding box. */
  516. llx = getFWord(glyph + 2);
  517. lly = getFWord(glyph + 4);
  518. urx = getFWord(glyph + 6);
  519. ury = getFWord(glyph + 8);
  520. /* Advance the pointer. */
  521. glyph += 10;
  522. }
  523. /* If it is a simple character, load its data. */
  524. if (num_ctr > 0)
  525. {
  526. load_char(font, glyph);
  527. }
  528. else
  529. {
  530. num_pts=0;
  531. }
  532. /* Consult the horizontal metrics table to determine */
  533. /* the character width. */
  534. if ( charindex < font->numberOfHMetrics )
  535. {
  536. advance_width = getuFWord( font->hmtx_table + (charindex * 4) );
  537. }
  538. else
  539. {
  540. advance_width = getuFWord( font->hmtx_table + ((font->numberOfHMetrics-1) * 4) );
  541. }
  542. /* Execute setcachedevice in order to inform the font machinery */
  543. /* of the character bounding box and advance width. */
  544. stack(stream, 7);
  545. if (pdf_mode)
  546. {
  547. if (!embedded) {
  548. stream.printf("%d 0 %d %d %d %d d1\n",
  549. topost(advance_width),
  550. topost(llx), topost(lly), topost(urx), topost(ury) );
  551. }
  552. }
  553. else if (font->target_type == PS_TYPE_42_3_HYBRID)
  554. {
  555. stream.printf("pop gsave .001 .001 scale %d 0 %d %d %d %d setcachedevice\n",
  556. topost(advance_width),
  557. topost(llx), topost(lly), topost(urx), topost(ury) );
  558. }
  559. else
  560. {
  561. stream.printf("%d 0 %d %d %d %d _sc\n",
  562. topost(advance_width),
  563. topost(llx), topost(lly), topost(urx), topost(ury) );
  564. }
  565. /* If it is a simple glyph, convert it, */
  566. /* otherwise, close the stack business. */
  567. if ( num_ctr > 0 ) /* simple */
  568. {
  569. PSConvert(stream);
  570. }
  571. else if ( num_ctr < 0 ) /* composite */
  572. {
  573. do_composite(stream, font, glyph);
  574. }
  575. if (font->target_type == PS_TYPE_42_3_HYBRID)
  576. {
  577. stream.printf("\ngrestore\n");
  578. }
  579. stack_end(stream);
  580. }
  581. /*
  582. ** This is the routine which is called from pprdrv_tt.c.
  583. */
  584. void tt_type3_charproc(TTStreamWriter& stream, struct TTFONT *font, int charindex)
  585. {
  586. GlyphToType3 glyph(stream, font, charindex);
  587. } /* end of tt_type3_charproc() */
  588. /*
  589. ** Some of the given glyph ids may refer to composite glyphs.
  590. ** This function adds all of the dependencies of those composite
  591. ** glyphs to the glyph id vector. Michael Droettboom [06-07-07]
  592. */
  593. void ttfont_add_glyph_dependencies(struct TTFONT *font, std::vector<int>& glyph_ids)
  594. {
  595. std::sort(glyph_ids.begin(), glyph_ids.end());
  596. std::stack<int> glyph_stack;
  597. for (std::vector<int>::iterator i = glyph_ids.begin();
  598. i != glyph_ids.end(); ++i)
  599. {
  600. glyph_stack.push(*i);
  601. }
  602. while (glyph_stack.size())
  603. {
  604. int gind = glyph_stack.top();
  605. glyph_stack.pop();
  606. BYTE* glyph = find_glyph_data( font, gind );
  607. if (glyph != (BYTE*)NULL)
  608. {
  609. int num_ctr = getSHORT(glyph);
  610. if (num_ctr <= 0) // This is a composite glyph
  611. {
  612. glyph += 10;
  613. USHORT flags = 0;
  614. do
  615. {
  616. flags = getUSHORT(glyph);
  617. glyph += 2;
  618. gind = (int)getUSHORT(glyph);
  619. glyph += 2;
  620. std::vector<int>::iterator insertion =
  621. std::lower_bound(glyph_ids.begin(), glyph_ids.end(), gind);
  622. if (insertion == glyph_ids.end() || *insertion != gind)
  623. {
  624. glyph_ids.insert(insertion, gind);
  625. glyph_stack.push(gind);
  626. }
  627. if (flags & ARG_1_AND_2_ARE_WORDS)
  628. {
  629. glyph += 4;
  630. }
  631. else
  632. {
  633. glyph += 2;
  634. }
  635. if (flags & WE_HAVE_A_SCALE)
  636. {
  637. glyph += 2;
  638. }
  639. else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
  640. {
  641. glyph += 4;
  642. }
  643. else if (flags & WE_HAVE_A_TWO_BY_TWO)
  644. {
  645. glyph += 8;
  646. }
  647. }
  648. while (flags & MORE_COMPONENTS);
  649. }
  650. }
  651. }
  652. }
  653. /* end of file */