From 05651fd7013fcd9ffe1e2a92266075cba65371d8 Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Fri, 4 Sep 2020 02:25:45 +0200 Subject: [PATCH] dashed objects in svg export --- src/check.c | 2 +- src/draw.c | 22 +++++++++----- src/svgdraw.c | 81 ++++++++++++++++++++++++++++++--------------------- 3 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/check.c b/src/check.c index a0c75dcd..4c56c497 100644 --- a/src/check.c +++ b/src/check.c @@ -87,6 +87,7 @@ void update_conn_cues(int draw_cues, int dr_win) double x1, y1, x2, y2; struct wireentry *wireptr; + hash_wires(); /* must be done also if lastwire==0 to clear wiretable */ if(!lastwire) return; if(!draw_dots) return; if(cadhalfdotsize*mooz<0.7) return; @@ -94,7 +95,6 @@ void update_conn_cues(int draw_cues, int dr_win) y1 = Y_TO_XSCHEM(areay1); x2 = X_TO_XSCHEM(areax2); y2 = Y_TO_XSCHEM(areay2); - hash_wires(); for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) { k=wireptr->n; /* optimization when editing small areas (detailed zoom) of a huge schematic */ diff --git a/src/draw.c b/src/draw.c index 63b51625..e46ba6c8 100644 --- a/src/draw.c +++ b/src/draw.c @@ -22,6 +22,14 @@ #include "xschem.h" + +/* Window doesn't work with LineDoubleDash, but will with LineOnOffDash */ +#ifdef __unix__ +#define xDashType LineDoubleDash +#else +#define xDashType LineOnOffDash +#endif + static double textx1,textx2,texty1,texty2; int textclip(int x1,int y1,int x2,int y2, @@ -817,13 +825,13 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw ,LineDoubleDash, CapButt , JoinBevel); + XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); } if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); if(draw_pixmap) XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); if(dash) { - XSetLineAttributes (display, gc[c], lw ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], lw, LineSolid, CapRound, JoinRound); } } } @@ -840,9 +848,9 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], bus_width ,LineDoubleDash, CapButt , JoinBevel); + XSetLineAttributes (display, gc[c], bus_width, xDashType, CapButt, JoinBevel); } else { - XSetLineAttributes (display, gc[c], bus_width , LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc[c], bus_width, LineSolid, CapRound, JoinRound); } if(draw_window) XDrawLine(display, window, gc[c], x1, y1, x2, y2); if(draw_pixmap) XDrawLine(display, save_pixmap, gc[c], x1, y1, x2, y2); @@ -1158,7 +1166,7 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, char dash_arr[2]; dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw ,LineDoubleDash, CapButt , JoinBevel); + XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); } if(draw_window) { @@ -1345,7 +1353,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil char dash_arr[2]; dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw ,LineDoubleDash, CapButt , JoinBevel); + XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); } if(draw_window) XDrawLines(display, window, gc[c], p, points, CoordModeOrigin); if(draw_pixmap) @@ -1407,7 +1415,7 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double if(dash) { dash_arr[0] = dash_arr[1] = dash; XSetDashes(display, gc[c], 0, dash_arr, 2); - XSetLineAttributes (display, gc[c], lw ,LineDoubleDash, CapButt , JoinBevel); + XSetLineAttributes (display, gc[c], lw, xDashType, CapButt, JoinBevel); } if(draw_window) XDrawRectangle(display, window, gc[c], (int)x1, (int)y1, (unsigned int)x2 - (unsigned int)x1, diff --git a/src/svgdraw.c b/src/svgdraw.c index d80756db..dbfc04e0 100644 --- a/src/svgdraw.c +++ b/src/svgdraw.c @@ -63,11 +63,11 @@ static void set_svg_colors(unsigned int pixel) } -static void svg_xdrawline(int layer, double x1, double y1, double x2, double y2) +static void svg_xdrawline(int layer, double x1, double y1, double x2, double y2, int dash) { - - fprintf(fd,"\n", x1, y1, x2, y2); + fprintf(fd,"\n", x1, y1, x2, y2); } static void svg_xdrawpoint(int layer, double x1, double y1) @@ -76,13 +76,14 @@ static void svg_xdrawpoint(int layer, double x1, double y1) fprintf(fd,"M%g %gL%g %gL%g%gL%g %gL%g %gz\"/>\n", x1, y1, x1+1.0, y1, x1+1.0, y1+1.0, x1, y1+1.0, x1, y1); } -static void svg_xfillrectangle(int layer, double x1, double y1, double x2, double y2) +static void svg_xfillrectangle(int layer, double x1, double y1, double x2, double y2, int dash) { - fprintf(fd,"\n", x1, y1, x2, y1, x2, y2, x1, y2, x1, y1); + fprintf(fd,"\n", x1, y1, x2, y1, x2, y2, x1, y2, x1, y1); } -static void svg_drawpolygon(int c, int what, double *x, double *y, int points) +static void svg_drawpolygon(int c, int what, double *x, double *y, int points, int fill, int dash) { double x1,y1,x2,y2; double xx, yy; @@ -95,18 +96,24 @@ static void svg_drawpolygon(int c, int what, double *x, double *y, int points) if( !rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { return; } - - fprintf(fd,"\n"); + /* fprintf(fd, "z\"/>\n"); */ + fprintf(fd, "\"/>\n"); } -static void svg_filledrect(int gc, double rectx1,double recty1,double rectx2,double recty2) +static void svg_filledrect(int gc, double rectx1,double recty1,double rectx2,double recty2, int dash) { double x1,y1,x2,y2; @@ -116,7 +123,7 @@ static void svg_filledrect(int gc, double rectx1,double recty1,double rectx2,dou y2=Y_TO_SVG(recty2); if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { - svg_xfillrectangle(gc, x1,y1,x2,y2); + svg_xfillrectangle(gc, x1,y1,x2,y2, dash); } } @@ -141,7 +148,7 @@ static void svg_drawcircle(int gc, int fillarc, double x,double y,double r,doubl } } -static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a, double b) +static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a, double b, int dash) { double xx,yy,rr; double x1, y1, x2, y2; @@ -160,12 +167,16 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { if(b == 360.) { + fprintf(fd, "\n", - xx, yy, rr, gc, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); + fprintf(fd, + "fill=\"rgb(%d,%d,%d)\" stroke=\"rgb(%d,%d,%d)\" stroke-width=\"%g\"/>\n", + svg_stroke.red, svg_stroke.green, svg_stroke.blue, + svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); else - fprintf(fd, "\n", - xx, yy, rr, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); + fprintf(fd, "stroke=\"rgb(%d,%d,%d)\" fill=\"none\" stroke-width=\"%g\"/>\n", + svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); } else { xx1 = rr * cos(a * XSCH_PI / 180.) + xx; yy1 = -rr * sin(a * XSCH_PI / 180.) + yy; @@ -174,17 +185,19 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a fa = b > 180 ? 1 : 0; fs = b > 0 ? 0 : 1; + fprintf(fd,"\n", xx1, yy1, rr, rr, fa, fs, xx2, yy2); } } } -static void svg_drawline(int gc, double linex1,double liney1,double linex2,double liney2) +static void svg_drawline(int gc, double linex1,double liney1,double linex2,double liney2, int dash) { double x1,y1,x2,y2; @@ -194,7 +207,7 @@ static void svg_drawline(int gc, double linex1,double liney1,double linex2,doubl y2=Y_TO_SVG(liney2); if( clip(&x1,&y1,&x2,&y2) ) { - svg_xdrawline(gc, x1, y1, x2, y2); + svg_xdrawline(gc, x1, y1, x2, y2, dash); } } @@ -241,7 +254,7 @@ static void svg_draw_string(int gctext, const char *str, ROTATION(x1,y1,curr_x1,curr_y1,rx1,ry1); ROTATION(x1,y1,curr_x2,curr_y2,rx2,ry2); ORDER(rx1,ry1,rx2,ry2); - svg_drawline(gctext, rx1, ry1, rx2, ry2); + svg_drawline(gctext, rx1, ry1, rx2, ry2, 0); } pos++; } @@ -259,11 +272,11 @@ static void svg_drawgrid() set_svg_colors(GRIDLAYER); if(y>areay1 && yareax1 && xpolygons[layer];j++) /* 20171115 */ @@ -342,7 +355,7 @@ static void svg_draw_symbol(int n,int layer,int tmp_flip, int rot, x[k]+= x0; y[k] += y0; } - svg_drawpolygon(layer, NOW, x, y, polygon.points); + svg_drawpolygon(layer, NOW, x, y, polygon.points, polygon.fill, polygon.dash); my_free(961, &x); my_free(962, &y); } @@ -359,7 +372,7 @@ static void svg_draw_symbol(int n,int layer,int tmp_flip, int rot, angle = fmod(angle, 360.); if(angle<0.) angle+=360.; ROTATION(0.0,0.0,arc.x,arc.y,x1,y1); - svg_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b); + svg_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b, arc.dash); } if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< (inst_ptr[n].ptr+instdef)->rects[layer];j++) @@ -368,7 +381,7 @@ static void svg_draw_symbol(int n,int layer,int tmp_flip, int rot, ROTATION(0.0,0.0,box.x1,box.y1,x1,y1); ROTATION(0.0,0.0,box.x2,box.y2,x2,y2); RECTORDER(x1,y1,x2,y2); - svg_filledrect(layer, x0+x1, y0+y1, x0+x2, y0+y2); + svg_filledrect(layer, x0+x1, y0+y1, x0+x2, y0+y2, box.dash); } if( (layer==TEXTWIRELAYER && !(inst_ptr[n].flags&2) ) || (sym_txt && (layer==TEXTLAYER) && (inst_ptr[n].flags&2) ) ) @@ -525,17 +538,17 @@ void svg_draw(void) { set_svg_colors(c); for(i=0;i