From ed477b90a5adb51f482425c7d025ac212fa08561 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 12 Dec 2023 01:14:40 +0100 Subject: [PATCH] eps export --- doc/xschem_man/developer_info.html | 4 ++- src/callback.c | 13 +++++---- src/draw.c | 2 +- src/psprint.c | 46 ++++++++++++++++++++++++++---- src/scheduler.c | 19 ++++++++---- src/spice_netlist.c | 8 +++--- src/xinit.c | 2 +- src/xschem.h | 4 +-- src/xschem.tcl | 1 + 9 files changed, 73 insertions(+), 26 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index 63b09c36..2be4f4ce 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -545,7 +545,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns" -
  • abort_operation
  • @@ -1055,6 +1054,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
        xschem print png file.png  [400 300]       [ -300 -200 300 200 ]
        xschem print svg file.svg  [400 300]       [ -300 -200 300 200 ]
        xschem print ps  file.ps   [400 300]       [ -300 -200 300 200 ]
    +   xschem print eps file.eps  [400 300]       [ -300 -200 300 200 ]
        xschem print pdf file.pdf  [400 300]       [ -300 -200 300 200 ]
        xschem print ps_full  file.ps
        xschem print pdf_full file.pdf
    @@ -1465,6 +1465,8 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns" + + diff --git a/src/callback.c b/src/callback.c index 20b6fdf8..e756d96e 100644 --- a/src/callback.c +++ b/src/callback.c @@ -1568,18 +1568,21 @@ int rstate; /* (reduced state, without ShiftMask) */ draw(); break; } - if(key == '+' && state&ControlMask) /* change line width */ + if(key == '+' && state & ControlMask) /* change line width */ { - xctx->lw+=0.1; + xctx->lw = round_to_n_digits(xctx->lw + 0.5, 2); change_linewidth(xctx->lw); + tclsetboolvar("change_lw", 0); draw(); break; } - if(key == '-' && state&ControlMask) /* change line width */ + if(key == '-' && state & ControlMask) /* change line width */ { - xctx->lw-=0.1;if(xctx->lw<0.0) xctx->lw=0.0; + xctx->lw = round_to_n_digits(xctx->lw - 0.5, 2); + if(xctx->lw < 0.0) xctx->lw = 0.0; change_linewidth(xctx->lw); + tclsetboolvar("change_lw", 0); draw(); break; } @@ -2186,7 +2189,7 @@ int rstate; /* (reduced state, without ShiftMask) */ if(key=='*' && rstate == 0 ) /* postscript print */ { if(xctx->semaphore >= 2) break; - ps_draw(7, 0); + ps_draw(7, 0, 0); break; } if(key=='*' && rstate == ControlMask) /* xpm print */ diff --git a/src/draw.c b/src/draw.c index 71cd426c..65f2604d 100644 --- a/src/draw.c +++ b/src/draw.c @@ -149,7 +149,7 @@ void print_image() } else tcleval( "convert_to_png plot.xpm plot.png"); #else char *psfile = NULL; - create_ps(&psfile, 7, 0); + create_ps(&psfile, 7, 0, 0); if (xctx->plotfile[0]) { my_snprintf(cmd, S(cmd), "convert_to_png {%s} {%s}", psfile, xctx->plotfile); tcleval(cmd); diff --git a/src/psprint.c b/src/psprint.c index a78e88e8..db2cb3da 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -977,7 +977,7 @@ static void fill_ps_colors() * 1: Do a full zoom before generating ps/pdf * 2: set paper size to bounding box instead of a4/letter */ -void create_ps(char **psfile, int what, int fullzoom) +void create_ps(char **psfile, int what, int fullzoom, int eps) { double dx, dy, scale, scaley; int landscape=1; @@ -1079,22 +1079,49 @@ void create_ps(char **psfile, int what, int fullzoom) pagey = tmp; } if(fullzoom == 2) { /* set media size to bbox */ + double sc; my_strncpy(papername, "bbox", S(papername)); pagex = xctx->xrect[0].width; pagey = xctx->xrect[0].height; + if(pagex > pagey) { + sc = 842. / pagex; + pagex = my_round(pagex * sc); + pagey = my_round(pagey * sc); + } else { + sc = 842. / pagey; + pagex = my_round(pagex * sc); + pagey = my_round(pagey * sc); + } margin = 0.0; } if(what & 1) {/* prolog */ dbg(1, "ps_draw(): bbox: x1=%g y1=%g x2=%g y2=%g\n", boundbox.x1, boundbox.y1, boundbox.x2, boundbox.y2); - fprintf(fd, "%%!PS-Adobe-3.0\n"); + if(!eps) { + fprintf(fd, "%%!PS-Adobe-3.0\n"); + } else { + fprintf(fd, "%%!PS-Adobe-2.0 EPSF-2.0\n"); + fprintf(fd, "%%%%BoundingBox: 0 0 %g %g\n", pagex, pagey); + } /* fprintf(fd, "%%%%DocumentMedia: %s %g %g 80 () ()\n", landscape ? "a4land" : "a4", pagex, pagey); */ fprintf(fd, "%%%%DocumentMedia: %s %g %g 80 () ()\n", papername, pagex, pagey); fprintf(fd, "%%%%PageOrientation: %s\n", landscape ? "Landscape" : "Portrait"); fprintf(fd, "%%%%Title: xschem plot\n"); fprintf(fd, "%%%%Creator: xschem\n"); - fprintf(fd, "%%%%Pages: (atend)\n"); + if(!eps) fprintf(fd, "%%%%Pages: (atend)\n"); fprintf(fd, "%%%%EndComments\n"); + + if(eps) { + fprintf(fd, "%%%%BeginProlog\n"); + fprintf(fd, "save\n"); + fprintf(fd, "countdictstack\n"); + fprintf(fd, "mark\n"); + fprintf(fd, "newpath\n"); + fprintf(fd, "/showpage {} def\n"); + fprintf(fd, "/setpagedevice {pop} def\n"); + fprintf(fd, "%%%%EndProlog\n"); + fprintf(fd, "%%%%Page 1 1\n"); + } fprintf(fd, "%%%%BeginProlog\n\n"); for(i = 0; i < sizeof(utf8_enc)/sizeof(char *); ++i) { @@ -1289,6 +1316,13 @@ void create_ps(char **psfile, int what, int fullzoom) if(what & 4) { /* trailer */ fprintf(fd, "%%%%trailer\n"); fprintf(fd, "%%%%Pages: %d\n", numpages); + if(eps) { + fprintf(fd, "%%%%Trailer\n"); + fprintf(fd, "cleartomark\n"); + fprintf(fd, "countdictstack\n"); + fprintf(fd, "exch sub { end } repeat\n"); + fprintf(fd, "restore\n"); + } fprintf(fd, "%%%%EOF\n"); fclose(fd); } @@ -1303,7 +1337,7 @@ void create_ps(char **psfile, int what, int fullzoom) } -int ps_draw(int what, int fullzoom) +int ps_draw(int what, int fullzoom, int eps) { char tmp[2*PATH_MAX+40]; static char lastdir[PATH_MAX] = ""; @@ -1316,7 +1350,7 @@ int ps_draw(int what, int fullzoom) /* tclvareval("tk_getSaveFile -title {Select destination file} -initialfile {", * get_cell(xctx->sch[xctx->currsch], 0) , ".pdf} -initialdir {", lastdir, "}", NULL); */ tclvareval("save_file_dialog {Select destination file} *.{ps,pdf} INITIALLOADDIR {", pwd_dir, "/", - get_cell(xctx->sch[xctx->currsch], 0), ".pdf}", NULL); + get_cell(xctx->sch[xctx->currsch], 0), eps ? ".eps}": ".pdf}", NULL); r = tclresult(); if(r[0]) { my_strncpy(xctx->plotfile, r, S(xctx->plotfile)); @@ -1326,7 +1360,7 @@ int ps_draw(int what, int fullzoom) else return 0; } } - create_ps(&psfile, what, fullzoom); + create_ps(&psfile, what, fullzoom, eps); if(what & 4) { /* trailer */ if(xctx->plotfile[0]) { my_snprintf(tmp, S(tmp), "convert_to_pdf {%s} {%s}", psfile, xctx->plotfile); diff --git a/src/scheduler.c b/src/scheduler.c index a1672c18..295369e9 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -3050,6 +3050,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg * xschem print png file.png [400 300] [ -300 -200 300 200 ] * xschem print svg file.svg [400 300] [ -300 -200 300 200 ] * xschem print ps file.ps [400 300] [ -300 -200 300 200 ] + * xschem print eps file.eps [400 300] [ -300 -200 300 200 ] * xschem print pdf file.pdf [400 300] [ -300 -200 300 200 ] * xschem print ps_full file.ps * xschem print pdf_full file.pdf @@ -3066,12 +3067,18 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg tclvareval("file normalize {", argv[3], "}", NULL); my_strncpy(xctx->plotfile, Tcl_GetStringResult(interp), S(xctx->plotfile)); } - if(!strcmp(argv[2], "pdf") || !strcmp(argv[2],"ps")) { + if(!strcmp(argv[2], "pdf") || !strcmp(argv[2],"ps") || !strcmp(argv[2],"eps")) { double save_lw = xctx->lw; int fullzoom = 0; int w = 0, h = 0; + int eps = 0; double x1, y1, x2, y2; - if(argc == 6 && xctx->lastsel == 0) { + + if(!strcmp(argv[2],"eps")) eps = 1; + if(eps && xctx->lastsel == 0) { + if(has_x) tcleval("alert_ {EPS export works only on a selection} {}"); + else dbg(0, "EPS export works only on a selection\n"); + } else if(argc == 6 && xctx->lastsel == 0 && eps == 0) { fullzoom = 2; w = atoi(argv[4]); h = atoi(argv[5]); @@ -3081,7 +3088,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg set_viewport_size(w, h, xctx->lw); zoom_full(0, 0, 2 * tclgetboolvar("zoom_full_center"), 0.97); resetwin(1, 1, 1, w, h); - ps_draw(7, fullzoom); + ps_draw(7, fullzoom, eps); save_restore_zoom(0, &zi); resetwin(1, 1, 1, 0, 0); change_linewidth(save_lw); @@ -3111,18 +3118,18 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg set_viewport_size(w, h, xctx->lw); zoom_box(x1, y1, x2, y2, 1.0); resetwin(1, 1, 1, w, h); - ps_draw(7, fullzoom); + ps_draw(7, fullzoom, eps); save_restore_zoom(0, &zi); resetwin(1, 1, 1, 0, 0); change_linewidth(save_lw); } else { fullzoom = 0; - ps_draw(7, fullzoom); + ps_draw(7, fullzoom, eps); } } else if(!strcmp(argv[2], "pdf_full") || !strcmp(argv[2],"ps_full")) { int fullzoom = 1; - ps_draw(7, fullzoom); + ps_draw(7, fullzoom, 0); } else if(!strcmp(argv[2], "png")) { double save_lw = xctx->lw; diff --git a/src/spice_netlist.c b/src/spice_netlist.c index f8a3a216..4b8fab65 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -55,11 +55,11 @@ void hier_psprint(char **res, int what) /* netlister driver */ save = xctx->do_copy_area; xctx->do_copy_area = 0; - if((what & 1) && !ps_draw(1, 1)) return; /* prolog */ + if((what & 1) && !ps_draw(1, 1, 0)) return; /* prolog */ xctx->push_undo(); str_hash_init(&subckt_table, HASHSIZE); zoom_full(0, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97); - if(what & 1) ps_draw(2, 1); /* page */ + if(what & 1) ps_draw(2, 1, 0); /* page */ if(what & 2) { /* print cellname */ my_strcat(_ALLOC_ID_, res, hier_psprint_mtime(xctx->sch[xctx->currsch])); my_strcat(_ALLOC_ID_, res, " {"); @@ -108,7 +108,7 @@ void hier_psprint(char **res, int what) /* netlister driver */ load_schematic(1,filename, 0, 1); get_additional_symbols(1); zoom_full(0, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97); - if(what & 1) ps_draw(2, 1); /* page */ + if(what & 1) ps_draw(2, 1, 0); /* page */ if(what & 2) { /* print cellname */ my_strcat(_ALLOC_ID_, res, hier_psprint_mtime(xctx->sch[xctx->currsch])); my_strcat(_ALLOC_ID_, res, " {"); @@ -133,7 +133,7 @@ void hier_psprint(char **res, int what) /* netlister driver */ xctx->prev_set_modify = save_prev_mod; my_strncpy(xctx->current_name, rel_sym_path(xctx->sch[xctx->currsch]), S(xctx->current_name)); xctx->do_copy_area = save; - if(what & 1) ps_draw(4, 1); /* trailer */ + if(what & 1) ps_draw(4, 1, 0); /* trailer */ zoom_full(0, 0, 1 + 2 * tclgetboolvar("zoom_full_center"), 0.97); draw(); } diff --git a/src/xinit.c b/src/xinit.c index 1eab612a..7021f257 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -2843,7 +2843,7 @@ int Tcl_AppInit(Tcl_Interp *inter) xctx->areaw = xctx->areax2-xctx->areax1; xctx->areah = xctx->areay2-xctx->areay1; zoom_full(0, 0, 2 * tclgetboolvar("zoom_full_center"), 0.97); - ps_draw(7, 0); + ps_draw(7, 0, 0); } else if(cli_opt_do_print == 2) { if(!has_x) { dbg(0, "xschem: can not do a png export if no X11 present / Xserver running (check if DISPLAY set).\n"); diff --git a/src/xschem.h b/src/xschem.h index 31f82a4d..d7842c02 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -1281,7 +1281,7 @@ extern Hilight_hashentry *hilight_lookup(const char *token, int value, int what) extern int search(const char *tok, const char *val, int sub, int sel, int match_case); extern int process_options(int argc, char **argv); extern void calc_drawing_bbox(xRect *boundbox, int selected); -extern int ps_draw(int what, int fullzoom); +extern int ps_draw(int what, int fullzoom, int eps); extern void svg_draw(void); extern void svg_embedded_graph(FILE *fd, xRect *r, double rx1, double ry1, double rx2, double ry2); extern void set_viewport_size(int w, int h, double lw); @@ -1692,6 +1692,6 @@ extern int pending_events(void); extern void get_square(double x, double y, int *xx, int *yy); extern const char *create_tmpdir(char *prefix); extern FILE *open_tmpfile(char *prefix, char **filename); -extern void create_ps(char** psfile, int what, int fullzoom); +extern void create_ps(char** psfile, int what, int fullzoom, int eps); extern void MyXCopyArea(Display* display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y); #endif /*CADGLOBALS */ diff --git a/src/xschem.tcl b/src/xschem.tcl index 1c6978d4..44ef502e 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -6917,6 +6917,7 @@ proc build_widgets { {topwin {} } } { # added svg, png 20171022 $topwin.menubar.file.menu add cascade -label "Image export" -menu $topwin.menubar.file.menu.im_exp menu $topwin.menubar.file.menu.im_exp -tearoff 0 + $topwin.menubar.file.menu.im_exp add command -label "EPS Selection Export" -command "xschem print eps" $topwin.menubar.file.menu.im_exp add command -label "PDF/PS Export" -command "xschem print pdf" -accelerator {*} $topwin.menubar.file.menu.im_exp add command -label "PDF/PS Export Full" -command "xschem print pdf_full" $topwin.menubar.file.menu.im_exp add command -label "Hierarchical PDF/PS Export" -command "xschem hier_psprint"