reduce svg size by avoiding redundant attributes in elements, fix a regression in scheduler.c (missing else clause)

This commit is contained in:
Stefan Schippers 2020-11-18 23:20:50 +01:00
parent 4f53cd8dbd
commit 070ec71800
4 changed files with 22 additions and 27 deletions

View File

@ -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) ) {

View File

@ -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,
"<circle cx=\"%g\" cy=\"%g\" r=\"%g\" stroke=\"rgb(%d,%d,%d)\" fill=\"rgb(%d,%d,%d)\" stroke-width=\"%g\"/>\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, "<circle class=\"l%d\" cx=\"%g\" cy=\"%g\" r=\"%g\"/>\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, "<circle cx=\"%g\" cy=\"%g\" r=\"%g\" ", xx, yy, rr);
fprintf(fd, "<circle class=\"l%d\" cx=\"%g\" cy=\"%g\" r=\"%g\" ", gc, xx, yy, rr);
if(dash) fprintf(fd, "stroke-dasharray=\"%g,%g\" ", 1.4*dash/xctx->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,"<path class=\"l%d\" ", gc);
if(dash) fprintf(fd, "stroke-dasharray=\"%g,%g\" ", 1.4*dash/xctx->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,"<text fill=\"%s\" xml:space=\"preserve\" font-family=\"%s\" font-size=\"%g\" "
"font-weight=\"%s \" font-style=\"%s\" "
"transform=\"translate(%g, %g) rotate(%d)\">",
col, svg_font_family, size*xctx->mooz, svg_font_weight, svg_font_style, ix, iy, rot1*90);
fprintf(fd,"<text fill=\"%s\" xml:space=\"preserve\" font-size=\"%g\" ", col, size*xctx->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, "</style>\n");
if(dark_colorscheme) {

View File

@ -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}

View File

@ -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
}