add xschem commands for specifying image size for png and pdf: xschem print svg file.svg 800 600; svg background color taken from svg_colors variable so it can be changed like any other color

This commit is contained in:
Stefan Frederik 2020-12-21 04:38:57 +01:00
parent d46abbeec1
commit 4ddc9654e8
8 changed files with 300 additions and 229 deletions

View File

@ -414,7 +414,7 @@ void ask_new_file(void)
Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL); Tcl_VarEval(interp, "update_recent_file {", fullname, "}", NULL);
my_strdup(1, &xctx->sch_path[xctx->currsch],"."); my_strdup(1, &xctx->sch_path[xctx->currsch],".");
xctx->sch_inst_number[xctx->currsch] = 1; xctx->sch_inst_number[xctx->currsch] = 1;
zoom_full(1, 0); zoom_full(1, 0, 1);
} }
} }
@ -1109,7 +1109,7 @@ void descend_schematic(int instnumber)
if(enable_drill) drill_hilight(); if(enable_drill) drill_hilight();
} }
dbg(1, "descend_schematic(): before zoom(): prep_hash_inst=%d\n", xctx->prep_hash_inst); dbg(1, "descend_schematic(): before zoom(): prep_hash_inst=%d\n", xctx->prep_hash_inst);
zoom_full(1, 0); zoom_full(1, 0, 1);
} }
} }
@ -1352,41 +1352,50 @@ void calc_drawing_bbox(xRect *boundbox, int selected)
} }
void zoom_full(int dr, int sel) /* bit0: invoke change_linewidth(), bit1: centered zoom */
void zoom_full(int dr, int sel, int flags)
{ {
xRect boundbox; xRect boundbox;
double yy1; double yzoom;
double shrink = 0.98; /* shrink drawing to make room for margins */
double bboxw, bboxh, schw, schh;
if(change_lw) { if(flags & 1) {
xctx->lw = 1.; if(change_lw) {
xctx->lw = 1.;
}
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw);
xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw);
xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2 - xctx->areay1;
} }
xctx->areax1 = -2*INT_WIDTH(xctx->lw);
xctx->areay1 = -2*INT_WIDTH(xctx->lw);
xctx->areax2 = xctx->xrect[0].width+2*INT_WIDTH(xctx->lw);
xctx->areay2 = xctx->xrect[0].height+2*INT_WIDTH(xctx->lw);
xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2 - xctx->areay1;
calc_drawing_bbox(&boundbox, sel); calc_drawing_bbox(&boundbox, sel);
xctx->zoom=(boundbox.x2-boundbox.x1)/(xctx->areaw-4*INT_WIDTH(xctx->lw)); schw = xctx->areaw-4*INT_WIDTH(xctx->lw);
yy1=(boundbox.y2-boundbox.y1)/(xctx->areah-4*INT_WIDTH(xctx->lw)); schh = xctx->areah-4*INT_WIDTH(xctx->lw);
if(yy1>xctx->zoom) xctx->zoom=yy1; bboxw = boundbox.x2-boundbox.x1;
xctx->zoom*=1.05; bboxh = boundbox.y2-boundbox.y1;
xctx->mooz=1/xctx->zoom; xctx->zoom = bboxw / schw;
xctx->xorigin=-boundbox.x1+(xctx->areaw-4*INT_WIDTH(xctx->lw))/40*xctx->zoom; yzoom = bboxh / schh;
xctx->yorigin=(xctx->areah-4*INT_WIDTH(xctx->lw))*xctx->zoom-boundbox.y2 - if(yzoom > xctx->zoom) xctx->zoom = yzoom;
(xctx->areah-4*INT_WIDTH(xctx->lw))/40*xctx->zoom; xctx->zoom /= shrink;
dbg(1, "zoom_full(): areaw=%d, areah=%d\n", xctx->areaw, xctx->areah); /* we do this here since change_linewidth may not be called if flags & 1 == 0*/
cadhalfdotsize = CADHALFDOTSIZE + 0.04 * (cadsnap-10);
change_linewidth(-1.); xctx->mooz = 1 / xctx->zoom;
if(dr) if(flags & 2) {
{ xctx->xorigin = -boundbox.x1 + (xctx->zoom * schw - bboxw) / 2; /* centered */
if(!has_x) return; xctx->yorigin = -boundbox.y1 + (xctx->zoom * schh - bboxh) / 2; /* centered */
draw(); } else {
xctx->xorigin = -boundbox.x1 + (1 - shrink) / 2 * xctx->zoom * schw;
xctx->yorigin = -boundbox.y1 + xctx->zoom * schh - bboxh - (1 - shrink) / 2 * xctx->zoom * schh;
} }
dbg(1, "zoom_full(): areaw=%d, areah=%d\n", xctx->areaw, xctx->areah);
if(flags & 1) change_linewidth(-1.);
if(dr && has_x) draw();
} }
void view_zoom(double z) void view_zoom(double z)
{ {
double factor; double factor;

View File

@ -1002,7 +1002,7 @@ int callback(int event, int mx, int my, KeySym key,
if(key=='*' && state==(Mod1Mask|ShiftMask) ) /* svg print , 20121108 */ if(key=='*' && state==(Mod1Mask|ShiftMask) ) /* svg print , 20121108 */
{ {
if(xctx->semaphore >= 2) break; if(xctx->semaphore >= 2) break;
svg_draw(); svg_draw(0, 0);
break; break;
} }
if(key=='*' && state==ShiftMask ) /* postscript print */ if(key=='*' && state==ShiftMask ) /* postscript print */
@ -1014,7 +1014,7 @@ int callback(int event, int mx, int my, KeySym key,
if(key=='*' && state==(ControlMask|ShiftMask) ) /* xpm print */ if(key=='*' && state==(ControlMask|ShiftMask) ) /* xpm print */
{ {
if(xctx->semaphore >= 2) break; if(xctx->semaphore >= 2) break;
print_image(); print_image(0, 0);
break; break;
} }
if(key=='u' && state==Mod1Mask) /* align to grid */ if(key=='u' && state==Mod1Mask) /* align to grid */
@ -1345,7 +1345,7 @@ int callback(int event, int mx, int my, KeySym key,
xctx->prep_net_structs = 0; xctx->prep_net_structs = 0;
xctx->prep_hi_structs = 0; xctx->prep_hi_structs = 0;
xctx->prep_hash_wires = 0; xctx->prep_hash_wires = 0;
zoom_full(1, 0); zoom_full(1, 0, 1);
break; break;
} }
@ -1357,7 +1357,7 @@ int callback(int event, int mx, int my, KeySym key,
} }
if(key=='f' && state == 0 ) /* full zoom */ if(key=='f' && state == 0 ) /* full zoom */
{ {
zoom_full(1, 0); zoom_full(1, 0, 1);
break; break;
} }
if((key=='z' && state==ControlMask)) /* zoom out */ if((key=='z' && state==ControlMask)) /* zoom out */

View File

@ -47,7 +47,7 @@ int textclip(int x1,int y1,int x2,int y2,
return 1; return 1;
} }
void print_image() void print_image(int user_w, int user_h)
{ {
int w, h, tmp, ww, hh, save_draw_grid, changed_size; int w, h, tmp, ww, hh, save_draw_grid, changed_size;
int modified_save; int modified_save;
@ -61,7 +61,10 @@ void print_image()
changed_size = 0; changed_size = 0;
w = ww = xctx->xschem_w; w = ww = xctx->xschem_w;
h = hh = xctx->xschem_h; h = hh = xctx->xschem_h;
if(!plotfile[0]) { if(user_w > 0 && user_h > 0 ) {
w = user_w; h = user_h;
if(w != xctx->xschem_w || h != xctx->xschem_h) changed_size = 1;
} else if(!plotfile[0]) {
my_snprintf(cmd, S(cmd), "input_line {Enter image size} {} {%dx%d}", xctx->xschem_w, xctx->xschem_h); my_snprintf(cmd, S(cmd), "input_line {Enter image size} {} {%dx%d}", xctx->xschem_w, xctx->xschem_h);
tcleval(cmd); tcleval(cmd);
if(sscanf(tclresult(), "%dx%d", &w, &h) != 2) { if(sscanf(tclresult(), "%dx%d", &w, &h) != 2) {
@ -76,7 +79,6 @@ void print_image()
if(r[0]) my_strncpy(plotfile, r, S(plotfile)); if(r[0]) my_strncpy(plotfile, r, S(plotfile));
else return; else return;
} }
modified_save=xctx->modified; /* 20161121 save state */ modified_save=xctx->modified; /* 20161121 save state */
push_undo(); push_undo();
trim_wires(); /* 20161121 add connection boxes on wires but undo at end */ trim_wires(); /* 20161121 add connection boxes on wires but undo at end */
@ -142,7 +144,7 @@ void print_image()
save_draw_grid = draw_grid; save_draw_grid = draw_grid;
draw_grid=0; draw_grid=0;
draw_pixmap=1; draw_pixmap=1;
if(changed_size) zoom_full(0, 0); if(changed_size) zoom_full(0, 0, 3); /* flags : 2 + 1 , center zoom & change_linewidth */
draw(); draw();
#ifdef __unix__ #ifdef __unix__

View File

@ -2251,7 +2251,7 @@ void descend_symbol(void)
remove_symbols(); /* must follow save (if) embedded */ remove_symbols(); /* must follow save (if) embedded */
load_schematic(1, abs_sym_path(name, ""), 1); load_schematic(1, abs_sym_path(name, ""), 1);
} }
zoom_full(1, 0); zoom_full(1, 0, 1);
} }
/* 20111023 align selected object to current grid setting */ /* 20111023 align selected object to current grid setting */

View File

@ -888,6 +888,8 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
printf("sch[%d]=%s\n",i,xctx->sch[i]); printf("sch[%d]=%s\n",i,xctx->sch[i]);
} }
printf("modified=%d\n", xctx->modified); printf("modified=%d\n", xctx->modified);
printf("areaw=%d\n", xctx->areaw);
printf("areah=%d\n", xctx->areah);
printf("color_ps=%d\n", color_ps); printf("color_ps=%d\n", color_ps);
printf("hilight_nets=%d\n", xctx->hilight_nets); printf("hilight_nets=%d\n", xctx->hilight_nets);
printf("need_reb_sel_arr=%d\n", xctx->need_reb_sel_arr); printf("need_reb_sel_arr=%d\n", xctx->need_reb_sel_arr);
@ -1365,7 +1367,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_VarEval(interp, "update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL); Tcl_VarEval(interp, "update_recent_file {", abs_sym_path(argv[2], ""), "}", NULL);
my_strdup(375, &xctx->sch_path[xctx->currsch],"."); my_strdup(375, &xctx->sch_path[xctx->currsch],".");
xctx->sch_inst_number[xctx->currsch] = 1; xctx->sch_inst_number[xctx->currsch] = 1;
zoom_full(1, 0); zoom_full(1, 0, 1);
} }
} }
else if(argc==2) { else if(argc==2) {
@ -1402,7 +1404,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
load_schematic(0, abs_sym_path(argv[2], ""), 1); load_schematic(0, abs_sym_path(argv[2], ""), 1);
my_strdup(374, &xctx->sch_path[xctx->currsch],"."); my_strdup(374, &xctx->sch_path[xctx->currsch],".");
xctx->sch_inst_number[xctx->currsch] = 1; xctx->sch_inst_number[xctx->currsch] = 1;
zoom_full(1, 0); zoom_full(1, 0, 1);
} }
} }
@ -1644,21 +1646,34 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
} }
/* 0 1 2 3 4 5
* xschem print png file.png 400 300 */
else if(!strcmp(argv[1],"print") ) { /* 20171022 added png, svg */ else if(!strcmp(argv[1],"print") ) { /* 20171022 added png, svg */
cmd_found = 1; cmd_found = 1;
if(argc >= 4) { if(argc < 3) {
my_strncpy(plotfile, argv[3], S(plotfile)); Tcl_SetResult(interp, "xschem print needs at least 1 more arguments: plot_type", TCL_STATIC);
} else { return TCL_ERROR;
plotfile[0] = '\0';
} }
if(argc==2 || (argc>=3 && !strcmp(argv[2],"pdf")) ) { if(argc >= 4) my_strncpy(plotfile, argv[3], S(plotfile));
if(!strcmp(argv[2],"pdf")) {
ps_draw(); ps_draw();
} }
else if(argc>=3 && !strcmp(argv[2],"png") ) { else if(!strcmp(argv[2],"png")) {
print_image(); int w = 0, h = 0;
if(argc >= 6) {
w = atoi(argv[4]);
h = atoi(argv[5]);
}
print_image(w, h);
} }
else if(argc>=3 && !strcmp(argv[2],"svg") ) { else if(!strcmp(argv[2],"svg")) {
svg_draw(); int w = 0, h = 0;
if(argc >= 6) {
w = atoi(argv[4]);
h = atoi(argv[5]);
}
svg_draw(w, h);
} }
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
} }
@ -1745,7 +1760,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
remove_symbols(); remove_symbols();
load_schematic(1, xctx->sch[xctx->currsch], 1); load_schematic(1, xctx->sch[xctx->currsch], 1);
if(argc >= 3 && !strcmp(argv[2], "zoom_full") ) { if(argc >= 3 && !strcmp(argv[2], "zoom_full") ) {
zoom_full(1, 0); zoom_full(1, 0, 1);
} else { } else {
draw(); draw();
} }
@ -2494,14 +2509,14 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(!strcmp(argv[1],"zoom_full")) else if(!strcmp(argv[1],"zoom_full"))
{ {
cmd_found = 1; cmd_found = 1;
zoom_full(1, 0); zoom_full(1, 0, 1);
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
} }
else if(!strcmp(argv[1],"zoom_hilighted")) else if(!strcmp(argv[1],"zoom_hilighted"))
{ {
cmd_found = 1; cmd_found = 1;
zoom_full(1, 2); zoom_full(1, 2, 1);
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
} }
@ -2522,7 +2537,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(!strcmp(argv[1],"zoom_selected")) else if(!strcmp(argv[1],"zoom_selected"))
{ {
cmd_found = 1; cmd_found = 1;
zoom_full(1, 1); zoom_full(1, 1, 1);
Tcl_ResetResult(interp); Tcl_ResetResult(interp);
} }
} }

View File

@ -567,181 +567,224 @@ static void fill_svg_colors()
} }
void svg_draw(void) void svg_draw(int w, int h)
{ {
double dx, dy; double dx, dy;
int c,i, textlayer; int c,i, textlayer;
int old_grid; int old_grid;
int modified_save; int modified_save;
char *tmpstring=NULL; char *tmpstring=NULL;
const char *r, *textfont; const char *r, *textfont;
int savew, saveh;
double savexor, saveyor, savezoom, savelw;
if(!plotfile[0]) { double xor, yor, zoom, lw;
my_strdup(61, &tmpstring, "tk_getSaveFile -title {Select destination file} -initialdir [pwd]");
tcleval(tmpstring);
r = tclresult();
my_free(963, &tmpstring);
if(r[0]) my_strncpy(plotfile, r, S(plotfile));
else return;
}
svg_restore_lw();
if( w > 0 && h > 0 ) {
svg_colors=my_calloc(419, cadlayers, sizeof(Svg_color)); savew = xctx->xschem_w;
if(svg_colors==NULL){ saveh = xctx->xschem_h;
fprintf(errfp, "svg_draw(): calloc error\n");tcleval( "exit"); savelw = xctx->lw;
} savexor = xctx->xorigin;
saveyor = xctx->yorigin;
fill_svg_colors(); savezoom = xctx->zoom;
old_grid=draw_grid; lw = 0.8;
draw_grid=0; xor = 0.0;
yor = 0.0;
dx=xctx->areax2-xctx->areax1; zoom = 1.0;
dy=xctx->areay2-xctx->areay1;
dbg(1, "svg_draw(): dx=%g dy=%g\n", dx, dy); /* give: w, h, xor, yor, zoom, lw */
xctx->xrect[0].x = 0;
xctx->xrect[0].y = 0;
modified_save=xctx->modified; xctx->xschem_w = xctx->xrect[0].width = w;
push_undo(); xctx->xschem_h = xctx->xrect[0].height = h;
trim_wires(); /* 20161121 add connection boxes on wires but undo at end */ xctx->areax2 = w+2*INT_WIDTH(lw);
xctx->areay2 = h+2*INT_WIDTH(lw);
xctx->areax1 = -2*INT_WIDTH(lw);
if(plotfile[0]) fd=fopen(plotfile, "w"); xctx->areay1 = -2*INT_WIDTH(lw);
else fd=fopen("plot.svg", "w"); xctx->lw = lw;
my_strncpy(plotfile,"", S(plotfile)); xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2-xctx->areay1;
xctx->xorigin = xor;
fprintf(fd, "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%g\" height=\"%g\" version=\"1.1\">\n", dx, dy); xctx->yorigin = yor;
xctx->zoom = zoom;
fprintf(fd, "<style type=\"text/css\">\n"); /* use css stylesheet 20121119 */ xctx->mooz = 1 / zoom;
for(i=0;i<cadlayers;i++){ zoom_full(0, 0, 2); /* draw, sel, center|change_linew */
fprintf(fd, ".l%d{\n", i); }
if(fill_type[i] == 1) if(!plotfile[0]) {
fprintf(fd, " fill: #%02x%02x%02x;\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue); my_strdup(61, &tmpstring, "tk_getSaveFile -title {Select destination file} -initialdir [pwd]");
else if(fill_type[i] == 2) tcleval(tmpstring);
fprintf(fd, " fill: #%02x%02x%02x; fill-opacity: 0.5;\n", r = tclresult();
svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue); my_free(963, &tmpstring);
else if(r[0]) my_strncpy(plotfile, r, S(plotfile));
fprintf(fd, " fill: none;\n"); else return;
fprintf(fd, " stroke: #%02x%02x%02x;\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue); }
fprintf(fd, " stroke-linecap:round;\n"); svg_restore_lw();
fprintf(fd, " stroke-linejoin:round;\n"); svg_colors=my_calloc(419, cadlayers, sizeof(Svg_color));
fprintf(fd, " stroke-width: %g;\n", svg_linew); if(svg_colors==NULL){
fprintf(fd, "}\n"); fprintf(errfp, "svg_draw(): calloc error\n");tcleval( "exit");
} }
fill_svg_colors();
fprintf(fd, "text {font-family: Sans Serif;}\n"); old_grid=draw_grid;
fprintf(fd, "</style>\n"); draw_grid=0;
dx=xctx->areax2-xctx->areax1;
if(dark_colorscheme) { dy=xctx->areay2-xctx->areay1;
/* black background */ dbg(1, "svg_draw(): dx=%g dy=%g\n", dx, dy);
fprintf(fd,
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" fill=\"rgb(%d,%d,%d)\" "
"stroke=\"rgb(%d,%d,%d)\" stroke-width=\"%g\" />\n", modified_save=xctx->modified;
0.0, 0.0, dx, dy, 0, 0, 0, 0, 0, 0, svg_linew); push_undo();
} else { trim_wires(); /* 20161121 add connection boxes on wires but undo at end */
/* white background */
fprintf(fd,
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" fill=\"rgb(%d,%d,%d)\" " if(plotfile[0]) fd=fopen(plotfile, "w");
"stroke=\"rgb(%d,%d,%d)\" stroke-width=\"%g\" />\n", else fd=fopen("plot.svg", "w");
0.0, 0.0, dx, dy, 255, 255, 255, 255, 255, 255, svg_linew); my_strncpy(plotfile,"", S(plotfile));
}
svg_drawgrid(); fprintf(fd, "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%g\" height=\"%g\" version=\"1.1\">\n", dx, dy);
for(i=0;i<xctx->texts;i++)
{ fprintf(fd, "<style type=\"text/css\">\n"); /* use css stylesheet 20121119 */
textlayer = xctx->text[i].layer; for(i=0;i<cadlayers;i++){
if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER; fprintf(fd, ".l%d{\n", i);
if(fill_type[i] == 1)
fprintf(fd, " fill: #%02x%02x%02x;\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue);
my_snprintf(svg_font_family, S(svg_font_family), svg_font_name); else if(fill_type[i] == 2)
my_snprintf(svg_font_style, S(svg_font_style), "normal"); fprintf(fd, " fill: #%02x%02x%02x; fill-opacity: 0.5;\n",
my_snprintf(svg_font_weight, S(svg_font_weight), "normal"); svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue);
else
textfont = xctx->text[i].font; fprintf(fd, " fill: none;\n");
if( (textfont && textfont[0])) { fprintf(fd, " stroke: #%02x%02x%02x;\n", svg_colors[i].red, svg_colors[i].green, svg_colors[i].blue);
my_snprintf(svg_font_family, S(svg_font_family), textfont); fprintf(fd, " stroke-linecap:round;\n");
} fprintf(fd, " stroke-linejoin:round;\n");
if( xctx->text[i].flags & TEXT_BOLD) fprintf(fd, " stroke-width: %g;\n", svg_linew);
my_snprintf(svg_font_weight, S(svg_font_weight), "bold"); fprintf(fd, "}\n");
if( xctx->text[i].flags & TEXT_ITALIC) }
my_snprintf(svg_font_style, S(svg_font_style), "italic");
if( xctx->text[i].flags & TEXT_OBLIQUE) fprintf(fd, "text {font-family: Sans Serif;}\n");
my_snprintf(svg_font_style, S(svg_font_style), "oblique"); fprintf(fd, "</style>\n");
if(text_svg) /* background */
svg_draw_string(textlayer, xctx->text[i].txt_ptr, fprintf(fd,
xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter, "<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" fill=\"rgb(%d,%d,%d)\" "
xctx->text[i].x0,xctx->text[i].y0, "stroke=\"rgb(%d,%d,%d)\" stroke-width=\"%g\" />\n",
xctx->text[i].xscale, xctx->text[i].yscale); 0.0, 0.0, dx, dy,
else svg_colors[0].red, svg_colors[0].green, svg_colors[0].blue,
old_svg_draw_string(textlayer, xctx->text[i].txt_ptr, svg_colors[0].red, svg_colors[0].green, svg_colors[0].blue,
xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter, svg_linew);
xctx->text[i].x0,xctx->text[i].y0, svg_drawgrid();
xctx->text[i].xscale, xctx->text[i].yscale); for(i=0;i<xctx->texts;i++)
}
for(c=0;c<cadlayers;c++)
{
for(i=0;i<xctx->lines[c];i++)
svg_drawline(c, xctx->line[c][i].bus, xctx->line[c][i].x1, xctx->line[c][i].y1,
xctx->line[c][i].x2, xctx->line[c][i].y2, xctx->line[c][i].dash);
for(i=0;i<xctx->rects[c];i++)
{ {
svg_filledrect(c, xctx->rect[c][i].x1, xctx->rect[c][i].y1, textlayer = xctx->text[i].layer;
xctx->rect[c][i].x2, xctx->rect[c][i].y2, xctx->rect[c][i].dash); if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
my_snprintf(svg_font_family, S(svg_font_family), svg_font_name);
my_snprintf(svg_font_style, S(svg_font_style), "normal");
my_snprintf(svg_font_weight, S(svg_font_weight), "normal");
textfont = xctx->text[i].font;
if( (textfont && textfont[0])) {
my_snprintf(svg_font_family, S(svg_font_family), textfont);
}
if( xctx->text[i].flags & TEXT_BOLD)
my_snprintf(svg_font_weight, S(svg_font_weight), "bold");
if( xctx->text[i].flags & TEXT_ITALIC)
my_snprintf(svg_font_style, S(svg_font_style), "italic");
if( xctx->text[i].flags & TEXT_OBLIQUE)
my_snprintf(svg_font_style, S(svg_font_style), "oblique");
if(text_svg)
svg_draw_string(textlayer, xctx->text[i].txt_ptr,
xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter,
xctx->text[i].x0,xctx->text[i].y0,
xctx->text[i].xscale, xctx->text[i].yscale);
else
old_svg_draw_string(textlayer, xctx->text[i].txt_ptr,
xctx->text[i].rot, xctx->text[i].flip, xctx->text[i].hcenter, xctx->text[i].vcenter,
xctx->text[i].x0,xctx->text[i].y0,
xctx->text[i].xscale, xctx->text[i].yscale);
} }
for(i=0;i<xctx->arcs[c];i++)
for(c=0;c<cadlayers;c++)
{ {
svg_drawarc(c, xctx->arc[c][i].fill, xctx->arc[c][i].x, xctx->arc[c][i].y, xctx->arc[c][i].r, for(i=0;i<xctx->lines[c];i++)
xctx->arc[c][i].a, xctx->arc[c][i].b, xctx->arc[c][i].dash); svg_drawline(c, xctx->line[c][i].bus, xctx->line[c][i].x1, xctx->line[c][i].y1,
} xctx->line[c][i].x2, xctx->line[c][i].y2, xctx->line[c][i].dash);
for(i=0;i<xctx->polygons[c];i++) { for(i=0;i<xctx->rects[c];i++)
svg_drawpolygon(c, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points, {
xctx->poly[c][i].fill, xctx->poly[c][i].dash); svg_filledrect(c, xctx->rect[c][i].x1, xctx->rect[c][i].y1,
} xctx->rect[c][i].x2, xctx->rect[c][i].y2, xctx->rect[c][i].dash);
for(i=0;i<xctx->instances;i++) {
svg_draw_symbol(i,c,0,0,0.0,0.0);
}
}
for(i=0;i<xctx->wires;i++)
{
svg_drawline(WIRELAYER, xctx->wire[i].bus, xctx->wire[i].x1,
xctx->wire[i].y1,xctx->wire[i].x2,xctx->wire[i].y2, 0);
}
{
double x1, y1, x2, y2;
struct wireentry *wireptr;
int i;
update_conn_cues(0, 0);
/* draw connecting dots */
x1 = X_TO_XSCHEM(xctx->areax1);
y1 = Y_TO_XSCHEM(xctx->areay1);
x2 = X_TO_XSCHEM(xctx->areax2);
y2 = Y_TO_XSCHEM(xctx->areay2);
for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) {
i = wireptr->n;
if( xctx->wire[i].end1 >1 ) { /* 20150331 draw_dots */
svg_drawcircle(WIRELAYER, 1, xctx->wire[i].x1, xctx->wire[i].y1, cadhalfdotsize, 0, 360);
}
if( xctx->wire[i].end2 >1 ) { /* 20150331 draw_dots */
svg_drawcircle(WIRELAYER, 1, xctx->wire[i].x2, xctx->wire[i].y2, cadhalfdotsize, 0, 360);
}
} }
} for(i=0;i<xctx->arcs[c];i++)
{
svg_drawarc(c, xctx->arc[c][i].fill, xctx->arc[c][i].x, xctx->arc[c][i].y, xctx->arc[c][i].r,
xctx->arc[c][i].a, xctx->arc[c][i].b, xctx->arc[c][i].dash);
}
for(i=0;i<xctx->polygons[c];i++) {
svg_drawpolygon(c, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points,
xctx->poly[c][i].fill, xctx->poly[c][i].dash);
}
for(i=0;i<xctx->instances;i++) {
svg_draw_symbol(i,c,0,0,0.0,0.0);
}
}
for(i=0;i<xctx->wires;i++)
{
svg_drawline(WIRELAYER, xctx->wire[i].bus, xctx->wire[i].x1,
xctx->wire[i].y1,xctx->wire[i].x2,xctx->wire[i].y2, 0);
}
{
double x1, y1, x2, y2;
struct wireentry *wireptr;
int i;
update_conn_cues(0, 0);
/* draw connecting dots */
x1 = X_TO_XSCHEM(xctx->areax1);
y1 = Y_TO_XSCHEM(xctx->areay1);
x2 = X_TO_XSCHEM(xctx->areax2);
y2 = Y_TO_XSCHEM(xctx->areay2);
for(init_wire_iterator(x1, y1, x2, y2); ( wireptr = wire_iterator_next() ) ;) {
i = wireptr->n;
if( xctx->wire[i].end1 >1 ) { /* 20150331 draw_dots */
svg_drawcircle(WIRELAYER, 1, xctx->wire[i].x1, xctx->wire[i].y1, cadhalfdotsize, 0, 360);
}
if( xctx->wire[i].end2 >1 ) { /* 20150331 draw_dots */
svg_drawcircle(WIRELAYER, 1, xctx->wire[i].x2, xctx->wire[i].y2, cadhalfdotsize, 0, 360);
}
}
}
dbg(1, "svg_draw(): INT_WIDTH(lw)=%d\n",INT_WIDTH(xctx->lw));
fprintf(fd, "</svg>\n");
fclose(fd);
dbg(1, "svg_draw(): INT_WIDTH(lw)=%d\n",INT_WIDTH(xctx->lw)); if(w > 0 && h > 0 ) {
fprintf(fd, "</svg>\n"); xctx->xrect[0].x = 0;
fclose(fd); xctx->xrect[0].y = 0;
draw_grid=old_grid; xctx->xschem_w = xctx->xrect[0].width = savew;
my_free(964, &svg_colors); xctx->xschem_h = xctx->xrect[0].height = saveh;
xctx->areax2 = savew+2*INT_WIDTH(savelw);
pop_undo(0); xctx->areay2 = saveh+2*INT_WIDTH(savelw);
xctx->modified=modified_save; xctx->areax1 = -2*INT_WIDTH(savelw);
xctx->areay1 = -2*INT_WIDTH(savelw);
xctx->lw = savelw;
xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2-xctx->areay1;
xctx->xorigin = savexor;
xctx->yorigin = saveyor;
xctx->zoom = savezoom;
xctx->mooz = 1 / savezoom;
}
draw_grid=old_grid;
my_free(964, &svg_colors);
pop_undo(0);
xctx->modified=modified_save;
} }

View File

@ -426,6 +426,7 @@ void alloc_xschem_data()
} }
xctx->window = xctx->save_pixmap = 0; xctx->window = xctx->save_pixmap = 0;
xctx->xrect[0].width = xctx->xrect[0].height = xctx->xrect[0].x = xctx->xrect[0].y = 0; xctx->xrect[0].width = xctx->xrect[0].height = xctx->xrect[0].x = xctx->xrect[0].y = 0;
xctx->xschem_w = xctx->xschem_h = 0;
#if HAS_CAIRO==1 #if HAS_CAIRO==1
xctx->cairo_ctx = xctx->cairo_save_ctx = NULL; xctx->cairo_ctx = xctx->cairo_save_ctx = NULL;
xctx->cairo_sfc = xctx->cairo_save_sfc = NULL; xctx->cairo_sfc = xctx->cairo_save_sfc = NULL;
@ -779,7 +780,7 @@ void preview_window(const char *what, const char *tk_win_path, const char *filen
dbg(1, "preview_window() draw, load schematic\n"); dbg(1, "preview_window() draw, load schematic\n");
load_schematic(1,filename, 0); load_schematic(1,filename, 0);
} }
zoom_full(1, 0); /* draw */ zoom_full(1, 0, 1); /* draw */
xctx = save_xctx; xctx = save_xctx;
} }
else if(!strcmp(what, "destroy")) { else if(!strcmp(what, "destroy")) {
@ -824,7 +825,7 @@ void new_schematic(const char *what, const char *tk_win_path, const char *filena
xctx->window = new_window; xctx->window = new_window;
resetwin(1, 0, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */ resetwin(1, 0, 1); /* create preview pixmap. resetwin(create_pixmap, clear_pixmap, force) */
load_schematic(1,filename, 0); load_schematic(1,filename, 0);
zoom_full(1, 0); /* draw */ zoom_full(1, 0, 1); /* draw */
} else if(!strcmp(what, "redraw")) { } else if(!strcmp(what, "redraw")) {
Xschem_ctx *save; Xschem_ctx *save;
save = xctx; save = xctx;
@ -1020,7 +1021,7 @@ void resetwin(int create_pixmap, int clear_pixmap, int force)
} }
} }
if(pending_fullzoom) { if(pending_fullzoom) {
zoom_full(0, 0); zoom_full(0, 0, 1);
pending_fullzoom=0; pending_fullzoom=0;
} }
dbg(1, "resetwin(): Window reset\n"); dbg(1, "resetwin(): Window reset\n");
@ -1575,7 +1576,7 @@ int Tcl_AppInit(Tcl_Interp *inter)
zoom_full(0, 0); /* Necessary to tell xschem the zoom_full(0, 0, 1); /* Necessary to tell xschem the
* initial area to display * initial area to display
*/ */
pending_fullzoom=1; pending_fullzoom=1;
@ -1618,17 +1619,17 @@ int Tcl_AppInit(Tcl_Interp *inter)
xctx->areay1 = -2; xctx->areay1 = -2;
xctx->areaw = xctx->areax2-xctx->areax1; xctx->areaw = xctx->areax2-xctx->areax1;
xctx->areah = xctx->areay2-xctx->areay1; xctx->areah = xctx->areay2-xctx->areay1;
zoom_full(0, 0); zoom_full(0, 0, 2);
ps_draw(); ps_draw();
} else if(do_print == 2) { } else if(do_print == 2) {
if(!has_x) { if(!has_x) {
dbg(0, "xschem: can not do a png export if no X11 present / Xserver running (check if DISPLAY set).\n"); dbg(0, "xschem: can not do a png export if no X11 present / Xserver running (check if DISPLAY set).\n");
} else { } else {
tcleval("tkwait visibility .drw"); tcleval("tkwait visibility .drw");
print_image(); print_image(0, 0);
} }
} }
else svg_draw(); else svg_draw(0, 0);
} }
if(do_simulation) { if(do_simulation) {

View File

@ -821,8 +821,8 @@ extern int search(const char *tok, const char *val, int sub, int sel, int what);
extern int process_options(int argc, char **argv); extern int process_options(int argc, char **argv);
extern void calc_drawing_bbox(xRect *boundbox, int selected); extern void calc_drawing_bbox(xRect *boundbox, int selected);
extern void ps_draw(void); extern void ps_draw(void);
extern void svg_draw(void); extern void svg_draw(int w, int h);
extern void print_image(); extern void print_image(int user_w, int user_h);
extern const char *skip_dir(const char *str); extern const char *skip_dir(const char *str);
extern const char *get_cell(const char *str, int no_of_dir); extern const char *get_cell(const char *str, int no_of_dir);
extern const char *get_cell_w_ext(const char *str, int no_of_dir); extern const char *get_cell_w_ext(const char *str, int no_of_dir);
@ -831,13 +831,14 @@ extern const char *abs_sym_path(const char *s, const char *ext);
extern const char *add_ext(const char *f, const char *ext); extern const char *add_ext(const char *f, const char *ext);
extern void make_symbol(void); extern void make_symbol(void);
extern const char *get_sym_template(char *s, char *extra); extern const char *get_sym_template(char *s, char *extra);
extern void zoom_full(int draw, int sel); extern void zoom_full(int draw, int sel, int flags); /* bit0: invoke change_linewidth(), bit1: centered zoom */
extern void updatebbox(int count,xRect *boundbox,xRect *tmp); extern void updatebbox(int count,xRect *boundbox,xRect *tmp);
extern void draw_selection(GC g, int interruptable); extern void draw_selection(GC g, int interruptable);
extern void delete(void); extern void delete(void);
extern void delete_only_rect_line_arc_poly(void); extern void delete_only_rect_line_arc_poly(void);
extern void polygon_bbox(double *x, double *y, int points, double *bx1, double *by1, double *bx2, double *by2); extern void polygon_bbox(double *x, double *y, int points, double *bx1, double *by1, double *bx2, double *by2);
extern void arc_bbox(double x, double y, double r, double a, double b, double *bx1, double *by1, double *bx2, double *by2); extern void arc_bbox(double x, double y, double r, double a, double b,
double *bx1, double *by1, double *bx2, double *by2);
extern void bbox(int what,double x1,double y1, double x2, double y2); extern void bbox(int what,double x1,double y1, double x2, double y2);
extern int set_text_custom_font(xText *txt); extern int set_text_custom_font(xText *txt);
extern int text_bbox(const char * str,double xscale, double yscale, extern int text_bbox(const char * str,double xscale, double yscale,