16
16
** documentation. This software is provided "as is" without express or
17
17
** implied warranty.
18
18
**
19
- ** TrueType font support. These functions allow PPR to generate
19
+ ** TrueType font support. These functions allow PPR to generate
20
20
** PostScript fonts from Microsoft compatible TrueType font files.
21
21
**
22
22
** The functions in this file do most of the work to convert a
23
23
** TrueType font to a type 3 PostScript font.
24
24
**
25
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
26
+ ** "ttf2ps" which L. S. Ng posted to the usenet news group
27
27
** "comp.sources.postscript". The author did not provide a copyright
28
28
** notice or indicate any restrictions on use.
29
29
**
30
30
** Last revised 11 July 1995.
31
31
*/
32
32
33
33
#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"
39
39
#include " truetype.h"
40
40
#include < algorithm>
41
41
#include < stack>
@@ -59,7 +59,7 @@ class GlyphToType3 {
59
59
int *ctrset; /* in contour index followed by out contour index */
60
60
61
61
int stack_depth; /* A book-keeping variable for keeping track of the depth of the PS stack */
62
-
62
+
63
63
bool pdf_mode;
64
64
65
65
void load_char (TTFONT* font, BYTE *glyph);
@@ -88,7 +88,7 @@ double area(FWord *x, FWord *y, int n);
88
88
89
89
/*
90
90
** This routine is used to break the character
91
- ** procedure up into a number of smaller
91
+ ** procedure up into a number of smaller
92
92
** procedures. This is necessary so as not to
93
93
** overflow the stack on certain level 1 interpreters.
94
94
**
@@ -131,21 +131,21 @@ void GlyphToType3::stack_end(TTStreamWriter& stream) /* called at end */
131
131
** Find the area of a contour?
132
132
*/
133
133
double area (FWord *x, FWord *y, int n)
134
- {
134
+ {
135
135
int i;
136
136
double sum;
137
-
137
+
138
138
sum=x[n-1 ]*y[0 ]-y[n-1 ]*x[0 ];
139
139
for (i=0 ; i<=n-2 ; i++) sum += x[i]*y[i+1 ] - y[i]*x[i+1 ];
140
140
return sum;
141
- }
141
+ }
142
142
143
143
/*
144
144
** We call this routine to emmit the PostScript code
145
145
** for the character we have loaded with load_char().
146
146
*/
147
147
void GlyphToType3::PSConvert (TTStreamWriter& stream)
148
- {
148
+ {
149
149
int i,j,k,fst,start_offpt;
150
150
int end_offpt = 0 ;
151
151
@@ -162,10 +162,10 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
162
162
check_ctr[0 ]=1 ;
163
163
area_ctr[0 ]=area (xcoor, ycoor, epts_ctr[0 ]+1 );
164
164
165
- for (i=1 ; i<num_ctr; i++)
165
+ for (i=1 ; i<num_ctr; i++)
166
166
area_ctr[i]=area (xcoor+epts_ctr[i-1 ]+1 , ycoor+epts_ctr[i-1 ]+1 , epts_ctr[i]-epts_ctr[i-1 ]);
167
167
168
- for (i=0 ; i<num_ctr; i++)
168
+ for (i=0 ; i<num_ctr; i++)
169
169
{
170
170
if (area_ctr[i]>0 )
171
171
{
@@ -254,26 +254,26 @@ int GlyphToType3::nextoutctr(int co)
254
254
{
255
255
int j;
256
256
257
- for (j=0 ; j<num_ctr; j++)
257
+ for (j=0 ; j<num_ctr; j++)
258
258
if (check_ctr[j]==0 && area_ctr[j] < 0 ) {
259
259
check_ctr[j]=1 ;
260
260
return j;
261
261
}
262
-
262
+
263
263
return NOMOREOUTCTR;
264
264
} /* end of nextoutctr() */
265
265
266
266
int GlyphToType3::nextinctr (int co, int ci)
267
267
{
268
268
int j;
269
-
269
+
270
270
for (j=0 ; j<num_ctr; j++)
271
- if (ctrset[2 *j+1 ]==co)
271
+ if (ctrset[2 *j+1 ]==co)
272
272
if (check_ctr[ctrset[2 *j]]==0 ) {
273
273
check_ctr[ctrset[2 *j]]=1 ;
274
274
return ctrset[2 *j];
275
275
}
276
-
276
+
277
277
return NOMOREINCTR;
278
278
}
279
279
@@ -285,8 +285,8 @@ int GlyphToType3::nearout(int ci)
285
285
int k = 0 ; /* !!! is this right? */
286
286
int co;
287
287
double a, a1=0 ;
288
-
289
- for (co=0 ; co < num_ctr; co++)
288
+
289
+ for (co=0 ; co < num_ctr; co++)
290
290
{
291
291
if (area_ctr[co] < 0 )
292
292
{
@@ -303,7 +303,7 @@ int GlyphToType3::nearout(int ci)
303
303
}
304
304
}
305
305
}
306
-
306
+
307
307
return k;
308
308
} /* end of nearout() */
309
309
@@ -312,14 +312,14 @@ double GlyphToType3::intest(int co, int ci)
312
312
int i, j, start, end;
313
313
double r1, r2, a;
314
314
FWord xi[3 ], yi[3 ];
315
-
315
+
316
316
j=start=(co==0 )?0 :(epts_ctr[co-1 ]+1 );
317
317
end=epts_ctr[co];
318
318
i=(ci==0 )?0 :(epts_ctr[ci-1 ]+1 );
319
319
xi[0 ] = xcoor[i];
320
320
yi[0 ] = ycoor[i];
321
321
r1=sqr (xcoor[start] - xi[0 ]) + sqr (ycoor[start] - yi[0 ]);
322
-
322
+
323
323
for (i=start; i<=end; i++) {
324
324
r2 = sqr (xcoor[i] - xi[0 ])+sqr (ycoor[i] - yi[0 ]);
325
325
if (r2 < r1) {
@@ -331,17 +331,17 @@ double GlyphToType3::intest(int co, int ci)
331
331
if (j==start) { xi[1 ]=xcoor[end]; yi[1 ]=ycoor[end]; }
332
332
if (j==end) { xi[2 ]=xcoor[start]; yi[2 ]=ycoor[start]; }
333
333
a=area (xi, yi, 3 );
334
-
334
+
335
335
return a;
336
336
} /* end of intest() */
337
337
338
338
void 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 " ,
340
340
x, y);
341
341
}
342
342
343
343
void 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 " ,
345
345
x, y);
346
346
}
347
347
@@ -369,8 +369,8 @@ void GlyphToType3::PSCurveto(TTStreamWriter& stream, FWord x, FWord y, int s, in
369
369
cx[2 ] = (sx[2 ]+2 *sx[1 ])/3 ;
370
370
cy[2 ] = (sy[2 ]+2 *sy[1 ])/3 ;
371
371
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 " :
374
374
" %d %d %d %d %d %d _c\n " ,
375
375
(int )cx[1 ], (int )cy[1 ], (int )cx[2 ], (int )cy[2 ],
376
376
(int )cx[3 ], (int )cy[3 ]);
@@ -513,22 +513,22 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
513
513
USHORT yscale;
514
514
USHORT scale01;
515
515
USHORT scale10;
516
-
516
+
517
517
/* Once around this loop for each component. */
518
518
do {
519
- flags = getUSHORT (glyph); /* read the flags word */
519
+ flags = getUSHORT (glyph); /* read the flags word */
520
520
glyph += 2 ;
521
521
522
522
glyphIndex = getUSHORT (glyph); /* read the glyphindex word */
523
523
glyph += 2 ;
524
-
524
+
525
525
if (flags & ARG_1_AND_2_ARE_WORDS)
526
526
{ /* The tt spec. seems to say these are signed. */
527
527
arg1 = getSHORT (glyph);
528
528
glyph += 2 ;
529
529
arg2 = getSHORT (glyph);
530
530
glyph += 2 ;
531
- }
531
+ }
532
532
else /* The tt spec. does not clearly indicate */
533
533
{ /* whether these values are signed or not. */
534
534
arg1 = *(glyph++);
@@ -538,7 +538,7 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
538
538
if (flags & WE_HAVE_A_SCALE)
539
539
{
540
540
xscale = yscale = getUSHORT (glyph);
541
- glyph += 2 ;
541
+ glyph += 2 ;
542
542
scale01 = scale10 = 0 ;
543
543
}
544
544
else if (flags & WE_HAVE_AN_X_AND_Y_SCALE)
@@ -548,7 +548,7 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
548
548
yscale = getUSHORT (glyph);
549
549
glyph += 2 ;
550
550
scale01 = scale10 = 0 ;
551
- }
551
+ }
552
552
else if (flags & WE_HAVE_A_TWO_BY_TWO)
553
553
{
554
554
xscale = getUSHORT (glyph);
@@ -597,20 +597,20 @@ void GlyphToType3::do_composite(TTStreamWriter& stream, struct TTFONT *font, BYT
597
597
{
598
598
stream.printf (" %% unimplemented shift, arg1=%d, arg2=%d\n " ,arg1,arg2);
599
599
}
600
-
600
+
601
601
/* Invoke the CharStrings procedure to print the component. */
602
602
stream.printf (" false CharStrings /%s get exec\n " ,
603
603
ttfont_CharStrings_getname (font,glyphIndex));
604
-
604
+
605
605
/* If we translated the coordinate system, */
606
606
/* put it back the way it was. */
607
607
if ( flags & ARGS_ARE_XY_VALUES && (arg1 != 0 || arg2 != 0 ) ) {
608
608
stream.puts (" grestore " );
609
609
}
610
610
}
611
-
611
+
612
612
} while (flags & MORE_COMPONENTS);
613
-
613
+
614
614
} /* end of do_composite() */
615
615
616
616
/*
@@ -676,7 +676,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
676
676
llx = getFWord (glyph + 2 );
677
677
lly = getFWord (glyph + 4 );
678
678
urx = getFWord (glyph + 6 );
679
- ury = getFWord (glyph + 8 );
679
+ ury = getFWord (glyph + 8 );
680
680
681
681
/* Advance the pointer. */
682
682
glyph += 10 ;
@@ -691,7 +691,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
691
691
/* Consult the horizontal metrics table to determine */
692
692
/* the character width. */
693
693
if ( charindex < font->numberOfHMetrics )
694
- advance_width = getuFWord ( font->hmtx_table + (charindex * 4 ) );
694
+ advance_width = getuFWord ( font->hmtx_table + (charindex * 4 ) );
695
695
else
696
696
advance_width = getuFWord ( font->hmtx_table + ((font->numberOfHMetrics -1 ) * 4 ) );
697
697
@@ -718,7 +718,7 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
718
718
{
719
719
do_composite (stream, font, glyph);
720
720
}
721
-
721
+
722
722
stack_end (stream);
723
723
}
724
724
@@ -763,16 +763,16 @@ void ttfont_add_glyph_dependencies(struct TTFONT *font, std::vector<int>& glyph_
763
763
gind = (int )getUSHORT (glyph);
764
764
glyph += 2 ;
765
765
766
- std::vector<int >::iterator insertion =
766
+ std::vector<int >::iterator insertion =
767
767
std::lower_bound (glyph_ids.begin (), glyph_ids.end (), gind);
768
768
if (*insertion != gind) {
769
769
glyph_ids.insert (insertion, gind);
770
770
glyph_stack.push (gind);
771
771
}
772
-
772
+
773
773
if (flags & ARG_1_AND_2_ARE_WORDS)
774
774
glyph += 4 ;
775
- else
775
+ else
776
776
glyph += 2 ;
777
777
778
778
if (flags & WE_HAVE_A_SCALE)
0 commit comments