diff --git a/src/scheduler.c b/src/scheduler.c index 38792e74..bbd76765 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -266,19 +266,31 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg * Ask user to choose a png/jpg file and start a GUI placement of the image */ else if(!strcmp(argv[1], "add_image")) { - char str[PATH_MAX+100]; + char *f = NULL; if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;} unselect_all(1); - tcleval("tk_getOpenFile -filetypes {{{Images} {.jpg .jpeg .png}} {{All files} *} }"); + tcleval("tk_getOpenFile -filetypes {{{Images} {.jpg .jpeg .png .svg}} {{All files} *} }"); + if(tclresult()[0]) { - my_snprintf(str, S(str), "flags=image,unscaled\nalpha=0.8\nimage=%s\n", tclresult()); + char *str = NULL; + my_strdup2(_ALLOC_ID_, &f, tclresult()); + my_mstrcat(_ALLOC_ID_, &str, "flags=image,unscaled\nalpha=0.8\nimage=", f, "\n", NULL); + + if(strstr(f, ".svg") == f + strlen(f) - 4 ) { + if(tcleval("info exists svg_to_png")[0] == '1') { + my_mstrcat(_ALLOC_ID_, &str, "filter=\"", tclgetvar("svg_to_png"), "\"\n", NULL); + } + } storeobject(-1, xctx->mousex_snap-100, xctx->mousey_snap-100, xctx->mousex_snap+100, xctx->mousey_snap+100, xRECT, GRIDLAYER, SELECTED, str); + + my_free(_ALLOC_ID_, &str); xctx->need_reb_sel_arr=1; rebuild_selected_array(); move_objects(START,0,0,0); xctx->ui_state |= START_SYMPIN; } + if(f) my_free(_ALLOC_ID_, &f); Tcl_ResetResult(interp); } diff --git a/src/xschem.tcl b/src/xschem.tcl index 46e09b88..a24283d7 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -7825,7 +7825,7 @@ proc build_widgets { {topwin {} } } { toolbar_add ToolInsertArc "xschem arc" "Insert Arc" $topwin $topwin.menubar.tools.menu add command -label "Insert circle" -command "xschem circle" -accelerator Ctrl+Shift+C toolbar_add ToolInsertCircle "xschem circle" "Insert Circle" $topwin - $topwin.menubar.tools.menu add command -label "Insert JPG/PNG image" -command "xschem add_image" + $topwin.menubar.tools.menu add command -label "Insert JPG/PNG/SVG image" -command "xschem add_image" $topwin.menubar.tools.menu add command -label "Grab screen area" -command "xschem grabscreen" \ -accelerator {Print Scrn} $topwin.menubar.tools.menu add command -label "Search" -accelerator Ctrl+F -command property_search diff --git a/src/xschemrc b/src/xschemrc index 24742ecf..d703a157 100644 --- a/src/xschemrc +++ b/src/xschemrc @@ -309,6 +309,15 @@ # set to_pdf ps2pdf # set to_pdf {ps2pdf -dAutoRotatePages=/None} +########################################################################### +#### IMPORT SVG IMAGES +########################################################################### +#### this is a filter command that processes svg files and writes png data +#### listed in my personal order of preference. +#### filter must read stdin and write to stdout. +# set svg_to_png {rsvg-convert} +# set svg_to_png {inkscape --pipe --export-type=png --export-filename=-} +# set svg_to_png {convert - png:-} ########################################################################### #### UNDO: SAVE ON DISK OR KEEP IN MEMORY