1616** documentation. This software is provided "as is" without express or
1717** implied warranty.
1818**
19- ** TrueType font support. These functions allow PPR to generate
19+ ** TrueType font support. These functions allow PPR to generate
2020** PostScript fonts from Microsoft compatible TrueType font files.
2121**
2222** The functions in this file do most of the work to convert a
2323** TrueType font to a type 3 PostScript font.
2424**
2525** 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
26+ ** "ttf2ps" which L. S. Ng posted to the usenet news group
2727** "comp.sources.postscript". The author did not provide a copyright
2828** notice or indicate any restrictions on use.
2929**
3030** Last revised 11 July 1995.
3131*/
3232
3333#include " global_defines.h"
34- #include < math.h >
35- #include < stdlib.h >
36- #include < string.h >
37- #include < memory.h >
38- #include " pprdrv.h"
34+ #include < cmath >
35+ #include < cstdlib >
36+ #include < cstring >
37+ #include < memory>
38+ #include " pprdrv.h"
3939#include " truetype.h"
4040#include < algorithm>
4141#include < stack>
@@ -59,7 +59,7 @@ class GlyphToType3 {
5959 int *ctrset; /* in contour index followed by out contour index */
6060
6161 int stack_depth; /* A book-keeping variable for keeping track of the depth of the PS stack */
62-
62+
6363 bool pdf_mode;
6464
6565 void load_char (TTFONT* font, BYTE *glyph);
@@ -88,7 +88,7 @@ double area(FWord *x, FWord *y, int n);
8888
8989/*
9090** This routine is used to break the character
91- ** procedure up into a number of smaller
91+ ** procedure up into a number of smaller
9292** procedures. This is necessary so as not to
9393** overflow the stack on certain level 1 interpreters.
9494**
@@ -131,21 +131,21 @@ void GlyphToType3::stack_end(TTStreamWriter& stream) /* called at end */
131131** Find the area of a contour?
132132*/
133133double area (FWord *x, FWord *y, int n)
134- {
134+ {
135135 int i;
136136 double sum;
137-
137+
138138 sum=x[n-1 ]*y[0 ]-y[n-1 ]*x[0 ];
139139 for (i=0 ; i<=n-2 ; i++) sum += x[i]*y[i+1 ] - y[i]*x[i+1 ];
140140 return sum;
141- }
141+ }
142142
143143/*
144144** We call this routine to emmit the PostScript code
145145** for the character we have loaded with load_char().
146146*/
147147void GlyphToType3::PSConvert (TTStreamWriter& stream)
148- {
148+ {
149149 int i,j,k,fst,start_offpt;
150150 int end_offpt = 0 ;
151151
@@ -162,10 +162,10 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
162162 check_ctr[0 ]=1 ;
163163 area_ctr[0 ]=area (xcoor, ycoor, epts_ctr[0 ]+1 );
164164
165- for (i=1 ; i<num_ctr; i++)
165+ for (i=1 ; i<num_ctr; i++)
166166 area_ctr[i]=area (xcoor+epts_ctr[i-1 ]+1 , ycoor+epts_ctr[i-1 ]+1 , epts_ctr[i]-epts_ctr[i-1 ]);
167167
168- for (i=0 ; i<num_ctr; i++)
168+ for (i=0 ; i<num_ctr; i++)
169169 {
170170 if (area_ctr[i]>0 )
171171 {
@@ -254,26 +254,26 @@ int GlyphToType3::nextoutctr(int co)
254254 {
255255 int j;
256256
257- for (j=0 ; j<num_ctr; j++)
257+ for (j=0 ; j<num_ctr; j++)
258258 if (check_ctr[j]==0 && area_ctr[j] < 0 ) {
259259 check_ctr[j]=1 ;
260260 return j;
261261 }
262-
262+
263263 return NOMOREOUTCTR;
264264 } /* end of nextoutctr() */
265265
266266int GlyphToType3::nextinctr (int co, int ci)
267267 {
268268 int j;
269-
269+
270270 for (j=0 ; j<num_ctr; j++)
271- if (ctrset[2 *j+1 ]==co)
271+ if (ctrset[2 *j+1 ]==co)
272272 if (check_ctr[ctrset[2 *j]]==0 ) {
273273 check_ctr[ctrset[2 *j]]=1 ;
274274 return ctrset[2 *j];
275275 }
276-
276+
277277 return NOMOREINCTR;
278278 }
279279
@@ -285,8 +285,8 @@ int GlyphToType3::nearout(int ci)
285285 int k = 0 ; /* !!! is this right? */
286286 int co;
287287 double a, a1=0 ;
288-
289- for (co=0 ; co < num_ctr; co++)
288+
289+ for (co=0 ; co < num_ctr; co++)
290290 {
291291 if (area_ctr[co] < 0 )
292292 {
@@ -303,7 +303,7 @@ int GlyphToType3::nearout(int ci)
303303 }
304304 }
305305 }
306-
306+
307307 return k;
308308 } /* end of nearout() */
309309
@@ -312,14 +312,14 @@ double GlyphToType3::intest(int co, int ci)
312312 int i, j, start, end;
313313 double r1, r2, a;
314314 FWord xi[3 ], yi[3 ];
315-
315+
316316 j=start=(co==0 )?0 :(epts_ctr[co-1 ]+1 );
317317 end=epts_ctr[co];
318318 i=(ci==0 )?0 :(epts_ctr[ci-1 ]+1 );
319319 xi[0 ] = xcoor[i];
320320 yi[0 ] = ycoor[i];
321321 r1=sqr (xcoor[start] - xi[0 ]) + sqr (ycoor[start] - yi[0 ]);
322-
322+
323323 for (i=start; i<=end; i++) {
324324 r2 = sqr (xcoor[i] - xi[0 ])+sqr (ycoor[i] - yi[0 ]);
325325 if (r2 < r1) {
@@ -331,17 +331,17 @@ double GlyphToType3::intest(int co, int ci)
331331 if (j==start) { xi[1 ]=xcoor[end]; yi[1 ]=ycoor[end]; }
332332 if (j==end) { xi[2 ]=xcoor[start]; yi[2 ]=ycoor[start]; }
333333 a=area (xi, yi, 3 );
334-
334+
335335 return a;
336336 } /* end of intest() */
337337
338338void GlyphToType3::PSMoveto (TTStreamWriter& stream, int x, int y) {
339- stream.printf (pdf_mode ? " %d %d m\n " : " %d %d _m\n " ,
339+ stream.printf (pdf_mode ? " %d %d m\n " : " %d %d _m\n " ,
340340 x, y);
341341}
342342
343343void GlyphToType3::PSLineto (TTStreamWriter& stream, int x, int y) {
344- stream.printf (pdf_mode ? " %d %d l\n " : " %d %d _l\n " ,
344+ stream.printf (pdf_mode ? " %d %d l\n " : " %d %d _l\n " ,
345345 x, y);
346346}
347347
@@ -369,8 +369,8 @@ void GlyphToType3::PSCurveto(TTStreamWriter& stream, FWord x, FWord y, int s, in
369369 cx[2 ] = (sx[2 ]+2 *sx[1 ])/3 ;
370370 cy[2 ] = (sy[2 ]+2 *sy[1 ])/3 ;
371371
372- stream.printf (pdf_mode ?
373- " %d %d %d %d %d %d c\n " :
372+ stream.printf (pdf_mode ?
373+ " %d %d %d %d %d %d c\n " :
374374 " %d %d %d %d %d %d _c\n " ,
375375 (int )cx[1 ], (int )cy[1 ], (int )cx[2 ], (int )cy[2 ],
376376 (int )cx[3 ], (int )cy[3 ]);
@@ -513,22 +513,22 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
513513 USHORT yscale;
514514 USHORT scale01;
515515 USHORT scale10;
516-
516+
517517 /* Once around this loop for each component. */
518518 do {
519- flags = getUSHORT (glyph); /* read the flags word */
519+ flags = getUSHORT (glyph); /* read the flags word */
520520 glyph += 2 ;
521521
522522 glyphIndex = getUSHORT (glyph); /* read the glyphindex word */
523523 glyph += 2 ;
524-
524+
525525 if (flags & ARG_1_AND_2_ARE_WORDS)
526526 { /* The tt spec. seems to say these are signed. */
527527 arg1 = getSHORT (glyph);
528528 glyph += 2 ;
529529 arg2 = getSHORT (glyph);
530530 glyph += 2 ;
531- }
531+ }
532532 else /* The tt spec. does not clearly indicate */
533533 { /* whether these values are signed or not. */
534534 arg1 = *(glyph++);
@@ -538,7 +538,7 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
538538 if (flags & WE_HAVE_A_SCALE)
539539 {
540540 xscale = yscale = getUSHORT (glyph);
541- glyph += 2 ;
541+ glyph += 2 ;
542542 scale01 = scale10 = 0 ;
543543 }
544544 else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
@@ -548,7 +548,7 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
548548 yscale = getUSHORT (glyph);
549549 glyph += 2 ;
550550 scale01 = scale10 = 0 ;
551- }
551+ }
552552 else if (flags & WE_HAVE_A_TWO_BY_TWO)
553553 {
554554 xscale = getUSHORT (glyph);
@@ -597,20 +597,20 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
597597 {
598598 stream.printf (" %% unimplemented shift, arg1=%d, arg2=%d\n " ,arg1,arg2);
599599 }
600-
600+
601601 /* Invoke the CharStrings procedure to print the component. */
602602 stream.printf (" false CharStrings /%s get exec\n " ,
603603 ttfont_CharStrings_getname (font,glyphIndex));
604-
604+
605605 /* If we translated the coordinate system, */
606606 /* put it back the way it was. */
607607 if ( flags & ARGS_ARE_XY_VALUES && (arg1 != 0 || arg2 != 0 ) ) {
608608 stream.puts (" grestore " );
609609 }
610610 }
611-
611+
612612 } while (flags & MORE_COMPONENTS);
613-
613+
614614 } /* end of do_composite() */
615615
616616/*
@@ -676,7 +676,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
676676 llx = getFWord (glyph + 2 );
677677 lly = getFWord (glyph + 4 );
678678 urx = getFWord (glyph + 6 );
679- ury = getFWord (glyph + 8 );
679+ ury = getFWord (glyph + 8 );
680680
681681 /* Advance the pointer. */
682682 glyph += 10 ;
@@ -691,7 +691,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
691691 /* Consult the horizontal metrics table to determine */
692692 /* the character width. */
693693 if ( charindex < font->numberOfHMetrics )
694- advance_width = getuFWord ( font->hmtx_table + (charindex * 4 ) );
694+ advance_width = getuFWord ( font->hmtx_table + (charindex * 4 ) );
695695 else
696696 advance_width = getuFWord ( font->hmtx_table + ((font->numberOfHMetrics -1 ) * 4 ) );
697697
@@ -718,7 +718,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
718718 {
719719 do_composite (stream, font, glyph);
720720 }
721-
721+
722722 stack_end (stream);
723723}
724724
@@ -763,16 +763,16 @@ void ttfont_add_glyph_dependencies(struct TTFONT *font, std::vector<int>& glyph_
763763 gind = (int )getUSHORT (glyph);
764764 glyph += 2 ;
765765
766- std::vector<int >::iterator insertion =
766+ std::vector<int >::iterator insertion =
767767 std::lower_bound (glyph_ids.begin (), glyph_ids.end (), gind);
768768 if (*insertion != gind) {
769769 glyph_ids.insert (insertion, gind);
770770 glyph_stack.push (gind);
771771 }
772-
772+
773773 if (flags & ARG_1_AND_2_ARE_WORDS)
774774 glyph += 4 ;
775- else
775+ else
776776 glyph += 2 ;
777777
778778 if (flags & WE_HAVE_A_SCALE)
0 commit comments