bugfixes
[swftools.git] / lib / gfxpoly / test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <memory.h>
4 #include <math.h>
5 #include "../gfxtools.h"
6 #include "poly.h"
7 #include "convert.h"
8 #include "renderpoly.h"
9 #include "stroke.h"
10
11 gfxline_t*mkstar(int x1, int y1, int x2, int y2)
12 {
13     gfxline_t*l=0,*line = 0;
14     int x;
15     for(x=x1;x<=x2;x+=50) {
16         l = rfx_calloc(sizeof(gfxline_t));
17         l->type = gfx_moveTo;
18         l->x = x;l->y = y1;
19         line = gfxline_append(line, l);
20
21         l = rfx_calloc(sizeof(gfxline_t));
22         l->type = gfx_lineTo;
23         l->x = x2-x;l->y = y2;
24         line = gfxline_append(line, l);
25     }
26     return line;
27 }
28
29 gfxline_t* mkrandomshape(int range, int n)
30 {
31     int i;
32     gfxline_t* line = malloc(sizeof(gfxline_t)*n);
33     for(i=0;i<n;i++) {
34         line[i].type = i?gfx_lineTo:gfx_moveTo;
35         line[i].x = lrand48()%range - range/2;
36         line[i].y = lrand48()%range - range/2;
37         line[i].next = &line[i+1];
38     }
39     line[n-1].x = line[0].x;
40     line[n-1].y = line[0].y;
41     line[n-1].next = 0;
42     return line;
43 }
44
45 gfxline_t* mkchessboard()
46 {
47     gfxline_t*b = 0;
48     int x,y;
49     unsigned int r = 0;
50     int spacing = 20;
51
52     int num_caros = 40;
53     int l = 5;
54     char do_centerpiece=1;
55
56     //int num_caros = 4;
57     //int l=1;
58     //char do_centerpiece=0;
59
60     for(x=-l;x<=l;x++) 
61     for(y=-l;y<=l;y++) {
62         /* pseudo random */ 
63         r = crc32_add_byte(r, x);r = crc32_add_byte(r, y);
64         if(r&1) {
65             gfxline_t*box;
66             if(r&2) {
67                 box = gfxline_makerectangle(x*spacing,y*spacing,(x+1)*spacing,(y+1)*spacing);
68             } else {
69                 box = gfxline_makerectangle((x+1)*spacing,y*spacing,x*spacing,(y+1)*spacing);
70             }
71             b = gfxline_append(b, box);
72         }
73     }
74
75     int t;
76     for(t=0;t<num_caros;t++) {
77         r = crc32_add_byte(r, t);
78         int x=(r%10-5)*spacing;
79         int y=((r>>4)%10-5)*spacing;
80         int sizex = ((r>>8)%4)*spacing;
81         int sizey = sizex;
82         if(r&65536)
83             sizex = -sizex;
84         gfxline_t*l = malloc(sizeof(gfxline_t)*5);
85         l[0].type = gfx_moveTo;l[0].next = &l[1];
86         l[1].type = gfx_lineTo;l[1].next = &l[2];
87         l[2].type = gfx_lineTo;l[2].next = &l[3];
88         l[3].type = gfx_lineTo;l[3].next = &l[4];
89         l[4].type = gfx_lineTo;l[4].next = 0;
90         l[0].x = x;
91         l[0].y = y-sizey;
92         l[1].x = x+sizex;
93         l[1].y = y;
94         l[2].x = x;
95         l[2].y = y+sizey;
96         l[3].x = x-sizex;
97         l[3].y = y;
98         l[4].x = x;
99         l[4].y = y-sizey;
100         gfxline_append(b, l);
101     }
102     if(do_centerpiece) {
103         for(t=0;t<5;t++) {
104             gfxline_t*l = gfxline_makerectangle(-9*spacing,-10,9*spacing,10);
105             gfxmatrix_t matrix;
106             memset(&matrix, 0, sizeof(gfxmatrix_t));
107             double ua=t*0.43;
108             matrix.m00=cos(ua);matrix.m10=sin(ua);
109             matrix.m01=-sin(ua);matrix.m11=cos(ua);
110             gfxline_transform(l, &matrix);
111             gfxline_append(b, l);
112         }
113         gfxline_append(b, gfxline_makecircle(100,100,100,100));
114     }
115     return b;
116 }
117
118 gfxline_t* make_circles(int n)
119 {
120     gfxline_t*b = 0;
121     unsigned int c = 0;
122     int t;
123     for(t=0;t<n;t++) {
124         c = crc32_add_byte(c, t);
125         int x = c%200;
126         c = crc32_add_byte(c, t);
127         int y = c%200;;
128         c = crc32_add_byte(c, t^0x55);
129         int r = c%100;
130         gfxline_t*c = gfxline_makecircle(x,y,r,r);
131         b = gfxline_append(b, c);
132         //b = gfxline_append(b, gfxline_makerectangle(10,10,100,100));
133     }
134     return b;
135 }
136
137 static windcontext_t onepolygon = {1};
138 static windcontext_t twopolygons = {2};
139
140 int test_speed()
141 {
142     //gfxline_t* b = mkchessboard();
143     //gfxline_t* b = mkrandomshape(100,7);
144     gfxline_t* b = make_circles(30);
145
146     gfxmatrix_t m;
147     memset(&m, 0, sizeof(gfxmatrix_t));
148     int t;
149     for(t=0;t<360;t++) {
150         printf("%d\n", t);
151         m.m00 = cos(t*M_PI/180.0);
152         m.m01 = sin(t*M_PI/180.0);
153         m.m10 = -sin(t*M_PI/180.0);
154         m.m11 = cos(t*M_PI/180.0);
155         m.tx = 400*1.41/2;
156         m.ty = 400*1.41/2;
157         gfxline_t*l = gfxline_clone(b);
158         gfxline_transform(l, &m);
159         gfxpoly_t*poly = gfxpoly_from_fill(b, 0.05);
160
161         gfxpoly_t*poly2 = gfxpoly_process(poly, 0, &windrule_evenodd, &onepolygon);
162         gfxpoly_destroy(poly);
163         gfxpoly_destroy(poly2);
164         gfxline_free(l);
165     }
166     gfxline_free(b);
167 }
168
169 int testbox(int argn, char*argv[])
170 {
171     gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100);
172     gfxline_t*box2 = gfxline_makerectangle(-50,-50,150,150);
173     gfxpoly_t*poly1 = gfxpoly_from_fill(box1, 0.05);
174     gfxpoly_t*poly2 = gfxpoly_from_fill(box2, 0.05);
175     gfxline_free(box1);
176     gfxline_free(box2);
177     
178     gfxpoly_t*poly12 = gfxpoly_process(poly1, poly2, &windrule_intersect, &twopolygons);
179     gfxpoly_dump(poly12);
180     assert(gfxpoly_check(poly12, 0));
181     gfxpoly_destroy(poly12);
182 }
183
184 int teststroke(int argn, char*argv[])
185 {
186     //gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100);
187     gfxline_t*box1 = gfxline_makerectangle(100,100,200,200);
188     gfxpoly_t*poly = gfxpoly_from_stroke(box1, 10.0, gfx_capRound, gfx_joinMiter, 1000, 0.05);
189     assert(gfxpoly_check(poly, 1));
190 }
191
192 int test0(int argn, char*argv[])
193 {
194     gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100);
195     gfxline_t*box2 = gfxline_makerectangle(-100,-100,100,100);
196     gfxline_t*box3 = gfxline_makerectangle(-100,-100,100,100);
197     //gfxline_append(box2, box3);
198
199     gfxmatrix_t matrix;
200     memset(&matrix, 0, sizeof(gfxmatrix_t));
201     double ua=M_PI/4;
202     matrix.m00=cos(ua);matrix.m10=sin(ua);
203     matrix.m01=-sin(ua);matrix.m11=cos(ua);
204     gfxline_transform(box1, &matrix);
205     
206     //gfxline_t*b = 0;
207     //b = gfxline_append(b, box1);
208     //b = gfxline_append(b, box2);
209     //gfxline_dump(b, stderr, "");
210
211     gfxpoly_t*poly1 = gfxpoly_from_fill(box1, 0.05);
212     gfxpoly_t*poly2 = gfxpoly_from_fill(box2, 0.05);
213     
214     gfxline_free(box1);
215     gfxline_free(box2);
216     
217     //gfxpoly_t*poly3 = gfxpoly_process(poly1, poly2, &windrule_intersect, &twopolygons);
218     gfxpoly_t*poly3 = gfxpoly_process(poly1, poly2, &windrule_intersect, &twopolygons);
219     gfxpoly_dump(poly3);
220     
221     gfxline_t*line = gfxline_from_gfxpoly(poly3);
222
223     gfxline_dump(line, stdout, "");
224     gfxline_free(line);
225     gfxpoly_destroy(poly1);
226     gfxpoly_destroy(poly2);
227     gfxpoly_destroy(poly3);
228 }
229
230
231 int test1(int argn, char*argv[])
232 {
233     gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
234     gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
235     gfxline_t*box3 = gfxline_makerectangle(200,100,300,200);
236     gfxline_t*box4 = gfxline_makerectangle(300,200,400,400);
237     gfxline_t* board = mkchessboard();
238     gfxline_t*star = mkstar(50,50, 150,150);
239     gfxline_t*b = 0;
240     b = gfxline_append(b, box1);
241     b = gfxline_append(b, box2);
242     b = gfxline_append(b, box3);
243     b = gfxline_append(b, box4);
244
245     gfxmatrix_t matrix;
246     memset(&matrix, 0, sizeof(gfxmatrix_t));
247     matrix.m00 = 1.0;
248     matrix.m11 = 1.0;
249     matrix.tx = 200;
250     matrix.ty = 200;
251     gfxline_transform(board, &matrix);
252     b = gfxline_append(b, board);
253
254     //gfxline_transform(b, &matrix);
255
256     //gfxline_dump(b, stderr, "");
257     gfxpoly_t*poly = gfxpoly_from_fill(b, 0.05);
258     
259     gfxline_free(box1);
260     gfxline_free(box2);
261     gfxline_free(box3);
262     gfxline_free(star);
263
264     //gfxpoly_dump(poly);
265     gfxpoly_t*poly2 = gfxpoly_process(poly, 0, &windrule_evenodd, &onepolygon);
266     //gfxpoly_dump(poly2);
267     gfxpoly_save_arrows(poly2, "test.ps");
268     gfxpoly_destroy(poly);
269     gfxpoly_destroy(poly2);
270 }
271
272 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
273 {
274     int t;
275     gfxline_t* line = malloc(sizeof(gfxline_t)*num);
276     for(t=0;t<num;t++) {
277         line[t].type = t?gfx_lineTo:gfx_moveTo;
278         line[t].x = (lrand48()%width);
279         line[t].y = (lrand48()%height);
280         line[t].next = &line[t+1];
281     }
282     line[num-1].x = line[0].x;
283     line[num-1].y = line[0].y;
284     line[num-1].next = 0;
285
286     gfxpoly_t*poly1 = gfxpoly_from_fill(line, gridsize);
287     gfxline_free(line);
288
289     windrule_t*rule = &windrule_circular;
290     gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
291     if(bitmaptest) {
292         intbbox_t bbox = intbbox_new(0, 0, width, height);
293         unsigned char*bitmap1 = render_polygon(poly1, &bbox, 1.0, rule, &onepolygon);
294         assert(bitmap_ok(&bbox, bitmap1));
295         unsigned char*bitmap2 = render_polygon(poly2, &bbox, 1.0, &windrule_evenodd, &onepolygon);
296         assert(bitmap_ok(&bbox, bitmap2));
297         if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
298             save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
299             assert(!"bitmaps don't match");
300         }
301     }
302     gfxpoly_destroy(poly1);
303     gfxpoly_destroy(poly2);
304 }
305
306 int test2(int argn, char*argv[])
307 {
308     test_square(400,400, 3, 0.05, 1);
309
310     int t;
311     for(t=0;t<400;t++) {
312         fprintf(stderr, "%d\n", t);
313         test_square(400,400, 50, 0.05, 1);
314         test_square(200,3, 1000, 1.0, 0);
315         test_square(3,200, 1000, 1.0, 0);
316         test_square(10,10, 200, 1.0, 0);
317     }
318 }
319
320 #include "../rfxswf.h"
321 void test3(int argn, char*argv[])
322 {
323 #undef N
324 #undef RANGE
325 #define N 100
326 #define RANGE 400
327
328     //gfxline_t*line = mkrandomshape(RANGE, N);
329     //windrule_t*rule = &windrule_circular;
330     gfxline_t*line = mkchessboard();
331     //gfxline_t*line = make_circles(30);
332     windrule_t*rule = &windrule_evenodd;
333     //windrule_t*rule = &windrule_circular;
334
335     gfxmatrix_t m;
336     memset(&m, 0, sizeof(m));
337
338     SWF swf;
339     memset(&swf, 0, sizeof(SWF));
340     swf.movieSize.xmax = RANGE*20*1.41;
341     swf.movieSize.ymax = RANGE*20*1.41;
342     swf.fileVersion = 9;
343     swf.frameRate = 25*0x100;
344     TAG * tag = swf.firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
345     swf_SetU8(tag, 0);
346     swf_SetU8(tag, 0);
347     swf_SetU8(tag, 0);
348
349     int t;
350     for(t=0;t<360;t++) {
351         fprintf(stderr, "%d\n", t);
352         m.m00 = cos(t*M_PI/180.0);
353         m.m01 = sin(t*M_PI/180.0);
354         m.m10 = -sin(t*M_PI/180.0);
355         m.m11 = cos(t*M_PI/180.0);
356         m.tx = RANGE*1.41/2;
357         m.ty = RANGE*1.41/2;
358
359         gfxline_t*l = gfxline_clone(line);
360         gfxline_transform(l, &m);
361
362         gfxpoly_t*poly1 = gfxpoly_from_fill(l, 0.05);
363
364         gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
365         assert(gfxpoly_check(poly2, 0));
366
367         tag = swf_InsertTag(tag, ST_DEFINESHAPE);
368         SHAPE* s;
369         swf_ShapeNew(&s);
370         RGBA rgb;
371         rgb.r = rgb.g = 0x00; rgb.b = 0xff;
372         rgb.a = 255;
373         int fs = swf_ShapeAddSolidFillStyle(s,&rgb);
374         int ls = swf_ShapeAddLineStyle(s,20,&rgb);
375         swf_SetU16(tag,t+1);
376         swf_SetRect(tag,&swf.movieSize);
377         swf_SetShapeHeader(tag,s);
378
379 #define FILL
380 #ifdef FILL
381         swf_ShapeSetAll(tag,s,UNDEFINED_COORD,UNDEFINED_COORD,0,fs,0);
382
383         int i,j;
384         gfxpolystroke_t*stroke = poly2->strokes;
385         for(;stroke;stroke=stroke->next) {
386             for(j=0;j<stroke->num_points-1;j++) {
387                 point_t a = stroke->points[j];
388                 point_t b = stroke->points[j+1];
389 #define ROTATE
390 #ifdef ROTATE
391                 swf_ShapeSetMove(tag, s, a.y, a.x);
392                 swf_ShapeSetLine(tag, s, b.y - a.y, b.x - a.x);
393 #else
394                 swf_ShapeSetMove(tag, s, a.x, a.y);
395                 swf_ShapeSetLine(tag, s, b.x - a.x, b.y - a.y);
396 #endif
397             }
398         }
399 #else
400         swf_ShapeSetAll(tag,s,0,0,ls,0,0);
401         edge_t*e = poly2->edges;
402         while(e) {
403             swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
404             swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
405             
406             swf_ShapeSetCircle(tag, s, e->a.x, e->a.y, 5*20, 5*20);
407             swf_ShapeSetCircle(tag, s, e->b.x, e->b.y, 5*20, 5*20);
408             e = e->next;
409         }
410 #endif
411
412         swf_ShapeSetEnd(tag);
413         swf_ShapeFree(s);
414
415         gfxpoly_destroy(poly1);
416         gfxpoly_destroy(poly2);
417
418         gfxline_free(l);
419    
420         if(t) {
421             tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
422             swf_SetU16(tag, t);
423         }
424         tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
425         swf_ObjectPlace(tag,t+1,t+1,NULL,NULL,NULL);
426
427         tag = swf_InsertTag(tag, ST_SHOWFRAME);
428     }
429     tag = swf_InsertTag(tag, ST_END);
430
431     swf_SaveSWF(&swf, "test.swf");
432 }
433
434 void rotate90(gfxpoly_t*poly)
435 {
436     int i,j;
437     gfxpolystroke_t*stroke = poly->strokes;
438     for(;stroke;stroke=stroke->next) {
439         for(j=0;j<stroke->num_points;j++) {
440             point_t a = stroke->points[j];
441             stroke->points[j].x = a.y;
442             stroke->points[j].y = a.x;
443         }
444     }
445 }
446
447 #include <dirent.h>
448 void test4(int argn, char*argv[])
449 {
450     char*dir = "ps";
451     DIR*_dir = opendir(dir);
452     if(!_dir) return;
453     struct dirent*file;
454     while(1) {
455         file = readdir(_dir);
456         if (!file) 
457             break;
458         if(!strstr(file->d_name, ".ps")) 
459             continue;
460
461         char* filename;
462
463         if(argn<2)
464             filename = allocprintf("%s/%s", dir, file->d_name);
465         else
466             filename = argv[1];
467
468         windrule_t*rule = &windrule_evenodd;
469         gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01);
470
471         if(argn!=2)
472             free(filename);
473
474         double zoom = 1.0;
475
476         if(!gfxpoly_check(poly1, 0)) {
477             printf("bad polygon\n");
478             goto end_of_loop;
479         }
480
481         gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
482         gfxpoly_dump(poly2);
483         assert(gfxpoly_check(poly2, 1));
484
485         int pass;
486         for(pass=0;pass<2;pass++) {
487             intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
488             unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
489             unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_circular, &onepolygon);
490             if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) {
491                 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
492                 assert(!"error in bitmaps");
493             }
494             if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
495                 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
496                 assert(!"bitmaps don't match");
497             }
498             free(bitmap1);
499             free(bitmap2);
500
501             // second pass renders the 90° rotated version
502             rotate90(poly1);
503             rotate90(poly2);
504         }
505
506         gfxpoly_destroy(poly1);
507         gfxpoly_destroy(poly2);
508         
509         end_of_loop:
510         if(argn==2) 
511             break;
512     }
513     closedir(_dir);
514 }
515
516 #include "../gfxdevice.h"
517 #include "../pdf/pdf.h"
518
519 static int max_segments = 0;
520 static int max_any_segments = 0;
521 void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) 
522 {
523     //gfxpoly_t*c = gfxpoly_from_fill(line, 0.05);
524     //gfxpoly_free(c);
525
526     //gfxpoly_t*poly1 = gfxpoly_from_fill(line, 0.05);
527     gfxpoly_t*poly1 = gfxpoly_from_fill(line, 0.05);
528
529     //gfxline_dump(line, stderr, "");
530     //gfxpoly_dump(poly);
531
532     int size = gfxpoly_size(poly1);
533     if(size == 4) {
534         //rectangles are boring.
535         gfxpoly_destroy(poly1);
536         return;
537     }
538
539     max_any_segments = size > max_any_segments? size : max_any_segments;
540     if(size>100000) {
541         fprintf(stderr, "%d segments (skipping)\n", size);
542         return;
543     } else {
544         max_segments = size > max_segments? size : max_segments;
545         fprintf(stderr, "%d segments (max so far: %d/%d)\n", size, max_segments, max_any_segments);
546     }
547
548     if(!gfxpoly_check(poly1, 0)) {
549         gfxpoly_destroy(poly1);
550         fprintf(stderr, "bad polygon\n");
551         return;
552     }
553
554     windrule_t*rule = &windrule_evenodd;
555
556     double zoom = 1.0;
557     intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
558     unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
559     if(!bitmap_ok(&bbox, bitmap1)) {
560         fprintf(stderr, "bad polygon or error in renderer\n");
561         return;
562     }
563     gfxpoly_t*poly2 = gfxpoly_process(poly1, 0, rule, &onepolygon);
564     unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
565     if(!bitmap_ok(&bbox, bitmap2)) {
566         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
567         assert(!"error in bitmap");
568     }
569     if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
570         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
571         assert(!"bitmaps don't match");
572     }
573     free(bitmap1);
574     free(bitmap2);
575
576     gfxpoly_destroy(poly1);
577     gfxpoly_destroy(poly2);
578 }
579 int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) {
580     return 0;
581 }
582 void extract_polygons_startclip(gfxdevice_t*dev, gfxline_t*line) 
583 {
584     extract_polygons_fill(dev, line, 0);
585 }
586 void extract_polygons_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*imgcoord2devcoord, gfxcxform_t*cxform)
587 {
588     extract_polygons_fill(dev, line, 0);
589 }
590 void extract_polygons_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*gradcoord2devcoord)
591 {
592     extract_polygons_fill(dev, line, 0);
593 }
594 void extract_polygons_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action)
595 {
596     extract_polygons_fill(dev, line, 0);
597 }
598 void extract_polygons_addfont(gfxdevice_t*dev, gfxfont_t*font)
599 {
600     int t;
601     for(t=0;t<font->num_glyphs;t++) {
602         //extract_polygons_fill(dev, font->glyphs[t].line, 0);
603     }
604 }
605 void extract_polygons_endclip(gfxdevice_t*dev)
606 {
607 }
608 void extract_polygons_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
609 {
610 }
611 void extract_polygons_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyph, gfxcolor_t*color, gfxmatrix_t*matrix)
612 {
613 }
614     
615 gfxdevice_t extract_polygons = 
616 {
617 name: "extract polygons",
618 setparameter:extract_polygons_setparameter,
619 startclip: extract_polygons_startclip,
620 endclip: extract_polygons_endclip,
621 stroke: extract_polygons_stroke,
622 fill: extract_polygons_fill,
623 fillbitmap: extract_polygons_fillbitmap,
624 fillgradient: extract_polygons_fillgradient,
625 addfont: extract_polygons_addfont,
626 drawchar: extract_polygons_drawchar,
627 drawlink: extract_polygons_drawlink,
628 startpage: 0,
629 endpage: 0,
630 geterror: 0,
631 finish: 0,
632 internal: 0
633 };
634
635 #if 0
636 void test5(int argn, char*argv[])
637 {
638     gfxsource_t*driver = gfxsource_pdf_create();
639     char*dir = "pdfs";
640     DIR*_dir = opendir(dir);
641     if(!_dir) return;
642     struct dirent*file;
643     while(1) {
644         file = readdir(_dir);
645         if (!file) 
646             break;
647         if(!strstr(file->d_name, ".pdf")) 
648             continue;
649         char* filename = allocprintf("%s/%s", dir, file->d_name);
650
651         if(argn>1) 
652             filename = argv[1];
653
654         gfxdocument_t*doc = driver->open(driver, filename);
655         gfxdevice_t*out = &extract_polygons;
656         int t;
657         for(t=1;t<=doc->num_pages;t++) {
658             fprintf(stderr, "%s (page %d)\n", filename, t);
659             gfxpage_t* page = doc->getpage(doc, t);
660             page->render(page, out);
661             page->destroy(page);
662         }
663         doc->destroy(doc);
664         if(argn>1) 
665             break;
666         free(filename);
667     }
668     closedir(_dir);
669     driver->destroy(driver);
670 }
671 #endif
672
673 int main(int argn, char*argv[])
674 {
675     test0(argn, argv);
676 }
677