small code refactoring
authorMatthias Kramm <kramm@matthias-kramms-macbook-pro.local>
Tue, 26 May 2009 22:51:41 +0000 (15:51 -0700)
committerMatthias Kramm <kramm@matthias-kramms-macbook-pro.local>
Tue, 26 May 2009 22:52:29 +0000 (15:52 -0700)
lib/devices/swf.c
lib/gfxpoly/poly.c
lib/gfxpoly/test.c

index c23783b..0467bf7 100644 (file)
@@ -89,6 +89,7 @@ typedef struct _swfoutput_internal
     int config_enablezlib;
     int config_insertstoptag;
     int config_watermark;
     int config_enablezlib;
     int config_insertstoptag;
     int config_watermark;
+    int config_noclips;
     int config_flashversion;
     int config_reordertags;
     int config_showclipshapes;
     int config_flashversion;
     int config_reordertags;
     int config_showclipshapes;
@@ -2021,6 +2022,8 @@ int swf_setparameter(gfxdevice_t*dev, const char*name, const char*value)
        i->config_caplinewidth = atof(value);
     } else if(!strcmp(name, "linktarget")) {
        i->config_linktarget = strdup(value);
        i->config_caplinewidth = atof(value);
     } else if(!strcmp(name, "linktarget")) {
        i->config_linktarget = strdup(value);
+    } else if(!strcmp(name, "noclips")) {
+       i->config_noclips = atoi(value);
     } else if(!strcmp(name, "dumpfonts")) {
        i->config_dumpfonts = atoi(value);
     } else if(!strcmp(name, "animate")) {
     } else if(!strcmp(name, "dumpfonts")) {
        i->config_dumpfonts = atoi(value);
     } else if(!strcmp(name, "animate")) {
@@ -2313,6 +2316,8 @@ static void drawoutline(gfxdevice_t*dev, gfxline_t*line)
 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
 static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+    if(i->config_noclips)
+       return;
 
     endtext(dev);
     endshape(dev);
 
     endtext(dev);
     endshape(dev);
@@ -2379,6 +2384,8 @@ static void swf_startclip(gfxdevice_t*dev, gfxline_t*line)
 static void swf_endclip(gfxdevice_t*dev)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
 static void swf_endclip(gfxdevice_t*dev)
 {
     swfoutput_internal*i = (swfoutput_internal*)dev->internal;
+    if(i->config_noclips)
+       return;
     if(i->textid>=0)
        endtext(dev);
     if(i->shapeid>=0)
     if(i->textid>=0)
        endtext(dev);
     if(i->shapeid>=0)
index 239cba6..fad4916 100644 (file)
@@ -485,6 +485,8 @@ static void schedule_crossing(status_t*status, segment_t*s1, segment_t*s2)
         return;
     }
 
         return;
     }
 
+#define REMEMBER_CROSSINGS
+#ifdef REMEMBER_CROSSINGS
     if(dict_contains(&s1->scheduled_crossings, (void*)(ptroff_t)s2->nr)) {
         /* FIXME: this whole segment hashing thing is really slow */
 #ifdef DEBUG
     if(dict_contains(&s1->scheduled_crossings, (void*)(ptroff_t)s2->nr)) {
         /* FIXME: this whole segment hashing thing is really slow */
 #ifdef DEBUG
@@ -495,6 +497,7 @@ static void schedule_crossing(status_t*status, segment_t*s1, segment_t*s2)
 #endif
         return; // we already know about this one
     }
 #endif
         return; // we already know about this one
     }
+#endif
 
     double det = (double)s1->delta.x*s2->delta.y - (double)s1->delta.y*s2->delta.x;
     if(!det) {
 
     double det = (double)s1->delta.x*s2->delta.y - (double)s1->delta.y*s2->delta.x;
     if(!det) {
@@ -582,6 +585,10 @@ static void schedule_crossing(status_t*status, segment_t*s1, segment_t*s2)
     p.x = (int32_t)ceil((-la*s2->delta.x + lb*s1->delta.x) / det);
     p.y = (int32_t)ceil((+lb*s1->delta.y - la*s2->delta.y) / det);
 
     p.x = (int32_t)ceil((-la*s2->delta.x + lb*s1->delta.x) / det);
     p.y = (int32_t)ceil((+lb*s1->delta.y - la*s2->delta.y) / det);
 
+#ifndef REMEMBER_CROSSINGS
+    if(p.y < status->y) return;
+#endif
+
     assert(p.y >= status->y);
 #ifdef CHECKS
     assert(p.x >= s1->minx && p.x <= s1->maxx);
     assert(p.y >= status->y);
 #ifdef CHECKS
     assert(p.x >= s1->minx && p.x <= s1->maxx);
@@ -590,17 +597,21 @@ static void schedule_crossing(status_t*status, segment_t*s1, segment_t*s2)
     point_t pair;
     pair.x = s1->nr;
     pair.y = s2->nr;
     point_t pair;
     pair.x = s1->nr;
     pair.y = s2->nr;
+#ifdef REMEMBER_CROSSINGS
     assert(!dict_contains(status->seen_crossings, &pair));
     dict_put(status->seen_crossings, &pair, 0);
 #endif
     assert(!dict_contains(status->seen_crossings, &pair));
     dict_put(status->seen_crossings, &pair, 0);
 #endif
+#endif
 #ifdef DEBUG
     fprintf(stderr, "schedule crossing between [%d] and [%d] at (%d,%d)\n", s1->nr, s2->nr, p.x, p.y);
 #endif
 
 #ifdef DEBUG
     fprintf(stderr, "schedule crossing between [%d] and [%d] at (%d,%d)\n", s1->nr, s2->nr, p.x, p.y);
 #endif
 
+#ifdef REMEMBER_CROSSINGS
     /* we insert into each other's intersection history because these segments might switch
        places and we still want to look them up quickly after they did */
     dict_put(&s1->scheduled_crossings, (void*)(ptroff_t)(s2->nr), 0);
     dict_put(&s2->scheduled_crossings, (void*)(ptroff_t)(s1->nr), 0);
     /* we insert into each other's intersection history because these segments might switch
        places and we still want to look them up quickly after they did */
     dict_put(&s1->scheduled_crossings, (void*)(ptroff_t)(s2->nr), 0);
     dict_put(&s2->scheduled_crossings, (void*)(ptroff_t)(s1->nr), 0);
+#endif
 
     event_t e = event_new();
     e.type = EVENT_CROSS;
 
     event_t e = event_new();
     e.type = EVENT_CROSS;
@@ -1047,18 +1058,22 @@ static void event_apply(status_t*status, event_t*e)
 #ifdef DEBUG
                fprintf(stderr, "Ignore this crossing ([%d] not next to [%d])\n", e->s1->nr, e->s2->nr);
 #endif
 #ifdef DEBUG
                fprintf(stderr, "Ignore this crossing ([%d] not next to [%d])\n", e->s1->nr, e->s2->nr);
 #endif
+#ifdef REMEMBER_CROSSINGS
                 /* ignore this crossing for now (there are some line segments in between).
                    it'll get rescheduled as soon as the "obstacles" are gone */
                 char del1 = dict_del(&e->s1->scheduled_crossings, (void*)(ptroff_t)e->s2->nr);
                 char del2 = dict_del(&e->s2->scheduled_crossings, (void*)(ptroff_t)e->s1->nr);
                 assert(del1 && del2);
                 /* ignore this crossing for now (there are some line segments in between).
                    it'll get rescheduled as soon as the "obstacles" are gone */
                 char del1 = dict_del(&e->s1->scheduled_crossings, (void*)(ptroff_t)e->s2->nr);
                 char del2 = dict_del(&e->s2->scheduled_crossings, (void*)(ptroff_t)e->s1->nr);
                 assert(del1 && del2);
+#endif
 #ifdef CHECKS
                 point_t pair;
                 pair.x = e->s1->nr;
                 pair.y = e->s2->nr;
 #ifdef CHECKS
                 point_t pair;
                 pair.x = e->s1->nr;
                 pair.y = e->s2->nr;
+#ifdef REMEMBER_CROSSINGS
                 assert(dict_contains(status->seen_crossings, &pair));
                 dict_del(status->seen_crossings, &pair);
 #endif
                 assert(dict_contains(status->seen_crossings, &pair));
                 dict_del(status->seen_crossings, &pair);
 #endif
+#endif
             }
         }
     }
             }
         }
     }
@@ -1276,6 +1291,7 @@ gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windconte
     xrow_destroy(status.xrow);
 
     gfxcompactpoly_t*p = (gfxcompactpoly_t*)status.writer.finish(&status.writer);
     xrow_destroy(status.xrow);
 
     gfxcompactpoly_t*p = (gfxcompactpoly_t*)status.writer.finish(&status.writer);
+
     add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
     gfxpoly_t*pp = gfxpoly_from_gfxcompactpoly(p);
     gfxcompactpoly_destroy(p);
     add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
     gfxpoly_t*pp = gfxpoly_from_gfxcompactpoly(p);
     gfxcompactpoly_destroy(p);
index 82ceb9a..c67f193 100644 (file)
@@ -143,7 +143,7 @@ int test_speed()
     gfxmatrix_t m;
     memset(&m, 0, sizeof(gfxmatrix_t));
     int t;
     gfxmatrix_t m;
     memset(&m, 0, sizeof(gfxmatrix_t));
     int t;
-    for(t=0;t<10;t++) {
+    for(t=0;t<360;t++) {
        printf("%d\n", t);
        m.m00 = cos(t*M_PI/180.0);
        m.m01 = sin(t*M_PI/180.0);
        printf("%d\n", t);
        m.m00 = cos(t*M_PI/180.0);
        m.m01 = sin(t*M_PI/180.0);