when inserting a svg image automatically set the filter attribute to rasterize svg to png (if tcl variable svg_to_png is set in xschemrc), "rsvg-convert" or "inkscape" or imagemagick "convert" can be used. see template xschemrc in src/

This commit is contained in:
stefan schippers 2024-10-27 13:06:49 +01:00
parent 2c82e26dcb
commit 9894d31437
3 changed files with 25 additions and 4 deletions

View File

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

View File

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

View File

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