+ int i,j;
+ gfxpolystroke_t*stroke = poly->strokes;
+ for(;stroke;stroke=stroke->next) {
+ for(j=0;j<stroke->num_points;j++) {
+ point_t a = stroke->points[j];
+ stroke->points[j].x = a.y;
+ stroke->points[j].y = a.x;
+ }
+ }
+}
+
+#include <dirent.h>
+void test4(int argn, char*argv[])
+{
+ char*dir = "ps";
+ DIR*_dir = opendir(dir);
+ if(!_dir) return;
+ struct dirent*file;
+ while(1) {
+ file = readdir(_dir);
+ if (!file)
+ break;
+ if(!strstr(file->d_name, ".ps"))
+ continue;
+
+ char* filename;
+
+ if(argn<2)
+ filename = allocprintf("%s/%s", dir, file->d_name);
+ else
+ filename = argv[1];
+
+ windrule_t*rule = &windrule_evenodd;
+ gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01);
+
+ if(argn!=2)
+ free(filename);
+
+ double zoom = 1.0;
+
+ if(!gfxpoly_check(poly1)) {
+ printf("bad polygon\n");
+ continue;
+ }
+
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
+
+ int pass;
+ for(pass=0;pass<2;pass++) {
+ intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
+ unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
+ unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
+ if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) {
+ save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+ assert(!"error in bitmaps");
+ }
+ if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
+ save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+ assert(!"bitmaps don't match");
+ }
+ free(bitmap1);
+ free(bitmap2);
+
+ // second pass renders the 90° rotated version
+ rotate90(poly1);
+ rotate90(poly2);
+ }
+
+ gfxpoly_destroy(poly1);
+ gfxpoly_destroy(poly2);
+ if(argn==2)
+ break;
+ }
+ closedir(_dir);
+}
+
+#include "../gfxdevice.h"
+#include "../pdf/pdf.h"
+
+void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
+{
+ //gfxpoly_t*c = gfxpoly_from_gfxline(line, 0.05);
+ //gfxpoly_free(c);
+
+ gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, 0.05);
+
+ //gfxline_dump(line, stderr, "");
+ //gfxpoly_dump(poly);
+
+ if(gfxpoly_size(poly1)>100000) {
+ fprintf(stderr, "%d segments (skipping)\n", gfxpoly_size(poly1));
+ return;
+ } else {
+ //fprintf(stderr, "%d segments\n", gfxpoly_size(poly));
+ }
+
+ if(!gfxpoly_check(poly1)) {
+ gfxpoly_destroy(poly1);
+ fprintf(stderr, "bad polygon\n");
+ return;
+ }
+
+ windrule_t*rule = &windrule_evenodd;
+
+ double zoom = 1.0;
+ intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
+ unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
+ if(!bitmap_ok(&bbox, bitmap1)) {
+ fprintf(stderr, "bad polygon or error in renderer\n");
+ return;
+ }
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
+ unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
+ if(!bitmap_ok(&bbox, bitmap2)) {
+ save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+ assert(!"error in bitmap");
+ }
+ if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
+ save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+ assert(!"bitmaps don't match");
+ }
+ free(bitmap1);
+ free(bitmap2);
+
+ gfxpoly_destroy(poly1);
+ gfxpoly_destroy(poly2);