From 070ec71800e0367a0ac49fdfc1e0ba67eeb68f9b Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Wed, 18 Nov 2020 23:20:50 +0100 Subject: [PATCH] reduce svg size by avoiding redundant attributes in elements, fix a regression in scheduler.c (missing else clause) --- src/scheduler.c | 2 +- src/svgdraw.c | 41 +++++++++------------ xschem_library/examples/0_examples_top.sch | 4 +- xschem_library/examples/mos_power_ampli.sch | 2 +- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index b4741d2d..ff914e28 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -1907,7 +1907,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg if( strlen(argv[3]) < sizeof(svg_font_name) ) { my_strncpy(svg_font_name, argv[3], S(svg_font_name)); } - } + } else #ifdef HAS_CAIRO if(!strcmp(argv[2],"cairo_font_name")) { if( strlen(argv[3]) < sizeof(cairo_font_name) ) { diff --git a/src/svgdraw.c b/src/svgdraw.c index 6751ae8d..1daee58d 100644 --- a/src/svgdraw.c +++ b/src/svgdraw.c @@ -35,7 +35,7 @@ typedef struct { static Svg_color *svg_colors; static char svg_font_weight[80] = "normal"; /* normal, bold, bolder, lighter */ -static char svg_font_family[80] = "sans-serif"; /* serif, monospace, Helvetica, Arial */ +static char svg_font_family[80] = "Sans Serif"; /* serif, monospace, Helvetica, Arial */ static char svg_font_style[80] = "normal"; /* normal, italic, oblique */ static double svg_linew; /* current width of lines / rectangles */ static Svg_color svg_stroke; @@ -146,10 +146,13 @@ static void svg_drawcircle(int gc, int fillarc, double x,double y,double r,doubl if( rectclip(areax1,areay1,areax2,areay2,&x1,&y1,&x2,&y2) ) { + /* fprintf(fd, "\n", xx, yy, rr, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); + */ + fprintf(fd, "\n", gc, xx, yy, rr); } } @@ -172,16 +175,10 @@ 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, "zoom, 1.4*dash/xctx->zoom); - if(fillarc) - 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, "stroke=\"rgb(%d,%d,%d)\" fill=\"none\" stroke-width=\"%g\"/>\n", - svg_stroke.red, svg_stroke.green, svg_stroke.blue, svg_linew); + if(!fillarc) fprintf(fd, "style=\"fill:none;\""); + fprintf(fd, "/>\n"); } else { xx1 = rr * cos(a * XSCH_PI / 180.) + xx; yy1 = -rr * sin(a * XSCH_PI / 180.) + yy; @@ -192,11 +189,8 @@ static void svg_drawarc(int gc, int fillarc, double x,double y,double r,double a fprintf(fd,"zoom, 1.4*dash/xctx->zoom); - if(fillarc) - fprintf(fd,"style=\"fill:%02x%02x%02x;\" d=\"", svg_stroke.red, svg_stroke.green, svg_stroke.blue); - else - fprintf(fd,"style=\"fill:none;\" d=\""); - fprintf(fd, "M%g %g A%g %g 0 %d %d %g %g\"/>\n", xx1, yy1, rr, rr, fa, fs, xx2, yy2); + if(!fillarc) fprintf(fd,"style=\"fill:none;\" "); + fprintf(fd, "d=\"M%g %g A%g %g 0 %d %d %g %g\"/>\n", xx1, yy1, rr, rr, fa, fs, xx2, yy2); } } } @@ -251,11 +245,13 @@ static void svg_draw_string_line(int layer, char *s, double x, double y, double else if(rot==2 && flip==1) {iy=iy-fontheight-lines+line_delta+fontascent;} else if(rot==3 && flip==1) {iy=iy+line_offset;ix+=line_delta+fontascent;} - fprintf(fd,"", - col, svg_font_family, size*xctx->mooz, svg_font_weight, svg_font_style, ix, iy, rot1*90); - + fprintf(fd,"mooz); + if(strcmp(svg_font_weight, "normal")) fprintf(fd, "font-weight=\"%s\" ", svg_font_weight); + if(strcmp(svg_font_style, "normal")) fprintf(fd, "font-style=\"%s\" ", svg_font_style); + if(strcmp(svg_font_family, "Sans Serif")) fprintf(fd, "font-family=\"%s\" ", svg_font_family); + if(rot1) fprintf(fd, "transform=\"translate(%g, %g) rotate(%d)\" ", ix, iy, rot1*90); + else fprintf(fd, "transform=\"translate(%g, %g)\" ", ix, iy); + fprintf(fd, ">"); while(*s) { switch(*s) { case '<': @@ -285,9 +281,6 @@ static void svg_draw_string(int layer, const char *str, int rot, int flip, int h int llength=0; if(str==NULL || !has_x ) return; size = xscale*52.; - if(size*xctx->mooz<3.0) return; /* too small */ - if(size*xctx->mooz>1600) return; /* too big */ - height = size*xctx->mooz * 1.147; ascent = size*xctx->mooz * 0.908; descent = size*xctx->mooz * 0.219; @@ -660,6 +653,8 @@ void svg_draw(void) fprintf(fd, " stroke-width: %g;\n", svg_linew); fprintf(fd, "}\n"); } + + fprintf(fd, "text {font-family: Sans Serif;}\n"); fprintf(fd, "\n"); if(dark_colorscheme) { diff --git a/xschem_library/examples/0_examples_top.sch b/xschem_library/examples/0_examples_top.sch index 1ad03455..4fcd98e0 100644 --- a/xschem_library/examples/0_examples_top.sch +++ b/xschem_library/examples/0_examples_top.sch @@ -35,8 +35,8 @@ wires} 1010 -330 0 0 0.6 0.6 {layer=4} T {XSCHEM OBJECTS} 910 -720 0 0 0.6 0.6 {layer=7} T {Components} 1010 -210 0 0 0.6 0.6 {layer=4} T {TEXT} 890 -620 0 0 0.5 0.5 {layer=8} -T {TEXT} 890 -670 1 0 0.7 0.7 {layer=6 font=FreeMono} -T {Text} 900 -660 0 0 0.5 0.5 {layer=7 font="Times"} +T {TEXT} 890 -670 1 0 0.7 0.7 {layer=6 font=Monospace} +T {Text} 900 -660 0 0 0.5 0.5 {layer=7 font="serif"} T {TEXT} 990 -660 1 0 0.5 0.5 {weight=bold} T {Text} 1010 -650 0 0 0.6 0.6 {layer=4} T {Arcs/Circles} 1010 -120 0 0 0.6 0.6 {layer=4} diff --git a/xschem_library/examples/mos_power_ampli.sch b/xschem_library/examples/mos_power_ampli.sch index 476e8a62..70bcc2f3 100644 --- a/xschem_library/examples/mos_power_ampli.sch +++ b/xschem_library/examples/mos_power_ampli.sch @@ -279,7 +279,7 @@ C {ngspice_probe.sym} 730 -810 2 1 {name=p46} C {ngspice_probe.sym} 440 -950 0 0 {name=p50} C {ngspice_probe.sym} 200 -470 0 0 {name=p45} C {ngspice_probe.sym} 340 -600 0 0 {name=p51} -C {ngspice_get_expr.sym} 350 -860 0 0 {name=r17 +C {ngspice_get_expr.sym} 330 -900 0 1 {name=r17 node="[ngspice::get_current v2]" descr = current }