@@ -58,9 +58,6 @@ class GlyphToType3
5858 int num_pts, num_ctr; /* number of points, number of coutours */
5959 FWord *xcoor, *ycoor; /* arrays of x and y coordinates */
6060 BYTE *tt_flags; /* array of TrueType flags */
61- double *area_ctr;
62- char *check_ctr;
63- int *ctrset; /* in contour index followed by out contour index */
6461
6562 int stack_depth; /* A book-keeping variable for keeping track of the depth of the PS stack */
6663
@@ -70,10 +67,6 @@ class GlyphToType3
7067 void stack (TTStreamWriter& stream, int new_elem);
7168 void stack_end (TTStreamWriter& stream);
7269 void PSConvert (TTStreamWriter& stream);
73- int nextinctr (int co, int ci);
74- int nextoutctr (int co);
75- int nearout (int ci);
76- double intest (int co, int ci);
7770 void PSCurveto (TTStreamWriter& stream,
7871 FWord x0, FWord y0,
7972 FWord x1, FWord y1,
@@ -147,65 +140,18 @@ void GlyphToType3::stack_end(TTStreamWriter& stream) /* calle
147140 }
148141} /* end of stack_end() */
149142
150- /*
151- ** Find the area of a contour?
152- */
153- double area (FWord *x, FWord *y, int n)
154- {
155- int i;
156- double sum;
157-
158- sum=x[n-1 ]*y[0 ]-y[n-1 ]*x[0 ];
159- for (i=0 ; i<=n-2 ; i++) sum += x[i]*y[i+1 ] - y[i]*x[i+1 ];
160- return sum;
161- }
162-
163143/*
164144** We call this routine to emmit the PostScript code
165145** for the character we have loaded with load_char().
166146*/
167147void GlyphToType3::PSConvert (TTStreamWriter& stream)
168148{
169- int i,j,k;
170-
171- assert (area_ctr == NULL );
172- area_ctr=(double *)calloc (num_ctr, sizeof (double ));
173- memset (area_ctr, 0 , (num_ctr*sizeof (double )));
174- assert (check_ctr == NULL );
175- check_ctr=(char *)calloc (num_ctr, sizeof (char ));
176- memset (check_ctr, 0 , (num_ctr*sizeof (char )));
177- assert (ctrset == NULL );
178- ctrset=(int *)calloc (num_ctr, 2 *sizeof (int ));
179- memset (ctrset, 0 , (num_ctr*2 *sizeof (int )));
180-
181- check_ctr[0 ]=1 ;
182- area_ctr[0 ]=area (xcoor, ycoor, epts_ctr[0 ]+1 );
183-
184- for (i=1 ; i<num_ctr; i++)
185- {
186- area_ctr[i]=area (xcoor+epts_ctr[i-1 ]+1 , ycoor+epts_ctr[i-1 ]+1 , epts_ctr[i]-epts_ctr[i-1 ]);
187- }
149+ int j, k;
188150
189- for (i=0 ; i<num_ctr; i++)
190- {
191- if (area_ctr[i]>0 )
192- {
193- ctrset[2 *i]=i;
194- ctrset[2 *i+1 ]=nearout (i);
195- }
196- else
197- {
198- ctrset[2 *i]=-1 ;
199- ctrset[2 *i+1 ]=-1 ;
200- }
201- }
202-
203- /* Step thru the coutours. */
204- /* I believe that a contour is a detatched */
205- /* set of curves and lines. */
206- for (i = j = k = 0 ;
207- i != NOMOREOUTCTR && i < num_ctr;
208- k = nextinctr (i, k), (k == NOMOREINCTR && (i = k = nextoutctr (i))))
151+ /* Step thru the contours.
152+ * j = index to xcoor, ycoor, tt_flags (point data)
153+ * k = index to epts_ctr (which points belong to the same contour) */
154+ for (j = k = 0 ; k < num_ctr; k++)
209155 {
210156 // A TrueType contour consists of on-path and off-path points.
211157 // Two consecutive on-path points are to be joined with a
@@ -294,126 +240,8 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
294240 /* Now, we can fill the whole thing. */
295241 stack (stream, 1 );
296242 stream.puts ( pdf_mode ? " f" : " _cl" );
297-
298- /* Free our work arrays. */
299- free (area_ctr);
300- free (check_ctr);
301- free (ctrset);
302- area_ctr = NULL ;
303- check_ctr = NULL ;
304- ctrset = NULL ;
305243} /* end of PSConvert() */
306244
307- int GlyphToType3::nextoutctr (int co)
308- {
309- int j;
310-
311- for (j=0 ; j<num_ctr; j++)
312- {
313- if (check_ctr[j]==0 && area_ctr[j] < 0 )
314- {
315- check_ctr[j]=1 ;
316- return j;
317- }
318- }
319-
320- return NOMOREOUTCTR;
321- } /* end of nextoutctr() */
322-
323- int GlyphToType3::nextinctr (int co, int ci)
324- {
325- int j;
326-
327- for (j=0 ; j<num_ctr; j++)
328- {
329- if (ctrset[2 *j+1 ]==co)
330- if (check_ctr[ctrset[2 *j]]==0 )
331- {
332- check_ctr[ctrset[2 *j]]=1 ;
333- return ctrset[2 *j];
334- }
335- }
336-
337- return NOMOREINCTR;
338- }
339-
340- /*
341- ** find the nearest out contour to a specified in contour.
342- */
343- int GlyphToType3::nearout (int ci)
344- {
345- int k = 0 ; /* !!! is this right? */
346- int co;
347- double a, a1=0 ;
348-
349- for (co=0 ; co < num_ctr; co++)
350- {
351- if (area_ctr[co] < 0 )
352- {
353- a=intest (co,ci);
354- if (a<0 && a1==0 )
355- {
356- k=co;
357- a1=a;
358- }
359- if (a<0 && a1!=0 && a>a1)
360- {
361- k=co;
362- a1=a;
363- }
364- }
365- }
366-
367- return k;
368- } /* end of nearout() */
369-
370- double GlyphToType3::intest (int co, int ci)
371- {
372- int i, j, start, end;
373- double r1, r2, a;
374- FWord xi[3 ], yi[3 ];
375-
376- j=start=(co==0 )?0 :(epts_ctr[co-1 ]+1 );
377- end=epts_ctr[co];
378- i=(ci==0 )?0 :(epts_ctr[ci-1 ]+1 );
379- xi[0 ] = xcoor[i];
380- yi[0 ] = ycoor[i];
381- r1=sqr (xcoor[start] - xi[0 ]) + sqr (ycoor[start] - yi[0 ]);
382-
383- for (i=start; i<=end; i++)
384- {
385- r2 = sqr (xcoor[i] - xi[0 ])+sqr (ycoor[i] - yi[0 ]);
386- if (r2 < r1)
387- {
388- r1=r2;
389- j=i;
390- }
391- }
392- if (j==start)
393- {
394- xi[1 ]=xcoor[end];
395- yi[1 ]=ycoor[end];
396- }
397- else
398- {
399- xi[1 ]=xcoor[j-1 ];
400- yi[1 ]=ycoor[j-1 ];
401- }
402- if (j==end)
403- {
404- xi[2 ]=xcoor[start];
405- yi[2 ]=ycoor[start];
406- }
407- else
408- {
409- xi[2 ]=xcoor[j+1 ];
410- yi[2 ]=ycoor[j+1 ];
411- }
412- a=area (xi, yi, 3 );
413-
414- return a;
415- } /* end of intest() */
416-
417245void GlyphToType3::PSMoveto (TTStreamWriter& stream, int x, int y)
418246{
419247 stream.printf (pdf_mode ? " %d %d m\n " : " %d %d _m\n " ,
@@ -466,11 +294,6 @@ GlyphToType3::~GlyphToType3()
466294 free (xcoor); /* The X coordinates */
467295 free (ycoor); /* The Y coordinates */
468296 free (epts_ctr); /* The array of contour endpoints */
469- // These last three should be NULL. Just
470- // free'ing them for safety.
471- free (area_ctr);
472- free (check_ctr);
473- free (ctrset);
474297}
475298
476299/*
@@ -754,9 +577,6 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
754577 xcoor = NULL ;
755578 ycoor = NULL ;
756579 epts_ctr = NULL ;
757- area_ctr = NULL ;
758- check_ctr = NULL ;
759- ctrset = NULL ;
760580 stack_depth = 0 ;
761581 pdf_mode = font->target_type < 0 ;
762582
0 commit comments