diff --git a/examples/svg/nmos_out_BSIM330_svg-2.sp b/examples/svg/nmos_out_BSIM330_svg-2.sp index 00f3a3c45..3550e1d88 100644 --- a/examples/svg/nmos_out_BSIM330_svg-2.sp +++ b/examples/svg/nmos_out_BSIM330_svg-2.sp @@ -26,7 +26,7 @@ set nolegend * the default settings * "svgwidth", "svgheight", "svgfont-size", "svgfont-width", "svguse-color", "svgstroke-width", "svggrid-width", -set svg_intopts = ( 512 384 20 0 1 5 2 ) +set svg_intopts = ( 512 384 16 8 1 5 2 ) * "svgbackground", "svgfont-family", "svgfont" setcs svg_stropts = ( yellow Arial Arial ) @@ -42,7 +42,7 @@ set nounits hardcopy plot_10.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage / V' ylabel 'Drain current / µA' unset svg_intopts -set svg_intopts = ( 512 384 16 0 1 5 2 ) +set svg_intopts = ( 512 384 6 0 1 5 2 ) hardcopy plot_11.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage / V' ylabel 'Drain current / µA' diff --git a/examples/svg/nmos_out_BSIM330_svg.sp b/examples/svg/nmos_out_BSIM330_svg.sp index db2c83354..aac50c99b 100644 --- a/examples/svg/nmos_out_BSIM330_svg.sp +++ b/examples/svg/nmos_out_BSIM330_svg.sp @@ -30,7 +30,7 @@ set nolegend * the default settings * "svgwidth", "svgheight", "svgfont-size", "svgfont-width", "svguse-color", "svgstroke-width", "svggrid-width", -set svg_intopts = ( 512 384 20 0 1 2 0 ) +set svg_intopts = ( 512 384 16 0 1 2 0 ) * "svgbackground", "svgfont-family", "svgfont" setcs svg_stropts = ( blue Arial Arial ) @@ -44,25 +44,33 @@ set color1=blue set color2=green hardcopy plot_1.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage' ylabel 'Drain current' -set svg_intopts = ( 512, 384, 16, 0, 1, 2, 0 ) +set svg_intopts = ( 512, 384, 14, 0, 1, 2, 0 ) set color0=blue set color1=white set color2=red hardcopy plot_2.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage' ylabel 'Drain current' -set svg_intopts = ( 512, 384, 16, 0, 0, 2, 2 ) +set svg_intopts = ( 512, 384, 12, 0, 0, 2, 2 ) set color0=black set color1=yellow set color2=white hardcopy plot_3.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage' ylabel 'Drain current' +* reset the colors +set svg_intopts = ( 512, 384, 12, 0, 1, 2, 2 ) unset color0 unset color1 unset color2 hardcopy plot_4.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage' ylabel 'Drain current' +* choose backgroundfrom color list +set color0="#F0E68C" +set color1="#DDA0DD" +set color2"#EE82EE" +hardcopy plot_5.svg vss#branch title 'Drain current versus drain voltage' xlabel 'Drain voltage' ylabel 'Drain current' + * for MS Windows only if $oscompiled = 1 | $oscompiled = 8 @@ -71,6 +79,7 @@ if $oscompiled = 1 | $oscompiled = 8 shell Start plot_2.svg shell Start plot_3.svg shell Start plot_4.svg + shell Start plot_5.svg else * for CYGWIN, Linux shell feh --magick-timeout 1 plot_0.svg & @@ -78,6 +87,7 @@ else shell feh --magick-timeout 1 plot_2.svg & shell feh --magick-timeout 1 plot_3.svg & shell feh --magick-timeout 1 plot_4.svg & + shell feh --magick-timeout 1 plot_5.svg & end .endc diff --git a/src/frontend/svg.c b/src/frontend/svg.c index cfeff7cfa..083a9bf9a 100644 --- a/src/frontend/svg.c +++ b/src/frontend/svg.c @@ -101,7 +101,7 @@ static FILE *plotfile; static int screenflag = 0; static int hcopygraphid; -const char *colors[] = {"black", +const char *svgcolors[] = {"black", "white", "red", "blue", @@ -123,6 +123,8 @@ const char *colors[] = {"black", "#949494", /*19: gray for smith grid */ "#888"}; /*20: gray for normal grid */ +static char** colors; + /* Set scale, color and size of the plot */ int SVG_Init(void) @@ -130,6 +132,27 @@ SVG_Init(void) char colorN[16], colorstring[30], strbuf[512]; unsigned int colorid, i; struct variable *vb, *va; + bool intopts_isset = FALSE, stropts_isset = FALSE; + unsigned int numberofcolors = NUMELEMS(svgcolors); + + /* set intopts and stropts as basic data */ + if (cp_getvar("svg_intopts", CP_LIST, &va, 0)) { + i = 0; + while (i < NUM_INTS && va) { + Cfg.ints[i++] = va->va_num; + va = va->va_next; + } + intopts_isset = TRUE; + } + if (cp_getvar("svg_stropts", CP_LIST, &vb, 0)) { + i = 0; + while (i < NUM_STRINGS && vb) { + tfree(Cfg.strings[i]); + Cfg.strings[i++] = strdup(vb->va_string); + vb = vb->va_next; + } + stropts_isset = TRUE; + } /* plot size */ if (!cp_getvar("hcopywidth", CP_STRING, &Cfg.ints[SVG_WIDTH], sizeof(Cfg.ints[SVG_WIDTH]))) { @@ -159,49 +182,32 @@ SVG_Init(void) if (cp_getvar("hcopyfont", CP_STRING, &strbuf, sizeof(strbuf))) { Cfg.strings[SVG_FONT] = strdup(strbuf); - } else { + } + else if (!stropts_isset) { Cfg.strings[SVG_FONT] = strdup("Helvetica"); } + if (cp_getvar("hcopyfontfamily", CP_STRING, &strbuf, sizeof(strbuf))) { Cfg.strings[SVG_FONT_FAMILY] = strdup(strbuf); } - else { + else if (!stropts_isset){ Cfg.strings[SVG_FONT_FAMILY] = strdup("Helvetica"); } - if (!cp_getvar("hcopyfontsize", CP_NUM, &Cfg.ints[SVG_FONT_SIZE], 0)) { - Cfg.ints[SVG_FONT_SIZE] = 10; - Cfg.ints[SVG_FONT_WIDTH] = 6; - } - else { - if ((Cfg.ints[SVG_FONT_SIZE] < 10) || (Cfg.ints[SVG_FONT_SIZE] > 18)) - Cfg.ints[SVG_FONT_SIZE] = 10; - } + cp_getvar("hcopyfontsize", CP_NUM, &Cfg.ints[SVG_FONT_SIZE], 0); - /* override the above when intopts and stropts are set */ - if (cp_getvar("svg_intopts", CP_LIST, &va, 0)) { - i = 0; - while (i < NUM_INTS && va) { - Cfg.ints[i++] = va->va_num; - va = va->va_next; - } - } - if (cp_getvar("svg_stropts", CP_LIST, &vb, 0)) { - i = 0; - while (i < NUM_STRINGS && vb) { - tfree(Cfg.strings[i]); - Cfg.strings[i++] = strdup(vb->va_string); - vb = vb->va_next; - } - } + colors = TMALLOC(char*, numberofcolors); /* Look for colour overrides: HTML/X11 #xxxxxx style. */ - for (colorid = 0; colorid < NUMELEMS(colors); ++colorid) { + for (colorid = 0; colorid < numberofcolors; ++colorid) { sprintf(colorN, "color%d", colorid); if (cp_getvar(colorN, CP_STRING, colorstring, sizeof(colorstring))) { colors[colorid] = strdup(colorstring); if (colorid == 0) - Cfg.strings[SVG_BACKGROUND] = colors[0]; + Cfg.strings[SVG_BACKGROUND] = strdup(colors[0]); + } + else { + colors[colorid] = strdup(svgcolors[colorid]); } } @@ -213,12 +219,11 @@ SVG_Init(void) /* Black and white. */ dispdev->numcolors = 2; } else { - dispdev->numcolors = NUMELEMS(colors); + dispdev->numcolors = NUMELEMS(svgcolors); } if (SVGuse_color == 1) { /* Suppress dashes in favour of color. */ - dispdev->numlinestyles = 2; } else { dispdev->numlinestyles = NUMELEMS(linestyles); @@ -311,6 +316,8 @@ SVG_Close(void) * without having reached SVG_NewViewport */ + int i; + if (plotfile) { closepath(DEVDEP_P(currentgraph)); fprintf(plotfile, "\n"); @@ -318,6 +325,12 @@ SVG_Close(void) plotfile = NULL; } + if (colors) { + for (i = 0; i < NUMELEMS(svgcolors); i++) + tfree(colors[i]); + tfree(colors); + } + /* In case of hardcopy command destroy the hardcopy graph * and reset currentgraph to graphid 1, if possible */ @@ -454,7 +467,6 @@ SVG_SetLinestyle(int linestyleid) /* Caller ignores dispdev->numlinestyles. Keep quiet, * but allow dotted grid. */ - currentgraph->linestyle = 0; return 0; } @@ -476,7 +488,7 @@ SVG_SetLinestyle(int linestyleid) int SVG_SetColor(int colorid) { - if (colorid < 0 || colorid > (int)NUMELEMS(colors)) { + if (colorid < 0 || colorid > (int)NUMELEMS(svgcolors)) { internalerror("bad colorid inside SVG_SelectColor"); return 1; }