diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 38599c7d09b8fb1c6cf347f807446c44b6b45612..02f767c2c05bb7a814e4d40dcc753ef4e92dc472 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -2167,7 +2167,7 @@ function gui_text_new(canvasname, myname, type, isselected, x, y, text, font) { if (g !== null) { g.appendChild(svg_text); } else { - gui_post("gui_text_new: can't find parent group"); + gui_post("gui_text_new: can't find parent group " + myname); } if (isselected) { @@ -3052,6 +3052,37 @@ function gui_plot_vis(cid, basex, basey, data_array, attr_array, tag_array) { } } +function gui_drawnumber_vis(cid, parent_tag, tag, x, y, scale_x, scale_y, + font, fontsize, text) { + gui_post("font is " + font); + var lines, i, len, tspan; + var g = get_item(cid, parent_tag); + var svg_text = create_item(cid, 'text', { + // x and y are fudge factors. Text on the tk canvas used an anchor + // at the top-right corner of the text's bbox. SVG uses the baseline. + // There's probably a programmatic way to do this, but for now-- fudge factors + // based on the DejaVu Sans Mono font. :) + transform: 'scale(' + scale_x + ',' + scale_y + ') ' + + 'translate(' + x + ')', + y: y, + // Turns out we can't do 'hanging' baseline + // because it's borked when scaled. Bummer... + // 'dominant-baseline': 'hanging', + 'shape-rendering': 'optimizeSpeed', + 'font-size': font + 'px', + id: tag + }); + + // fill svg_text with tspan content by splitting on '\n' + text_to_tspans(cid, svg_text, text); + + if (g !== null) { + g.appendChild(svg_text); + } else { + gui_post("gui_drawnumber: can't find parent group" + parent_tag); + } +} + function add_popup(cid, popup) { popup_menu[cid] = popup; } diff --git a/pd/src/g_template.c b/pd/src/g_template.c index 30a12276ccae5fa9b917dddbd7910d568a9d50e4..bf4e8055d4869af242c7c30572f9fcff47c284c9 100644 --- a/pd/src/g_template.c +++ b/pd/src/g_template.c @@ -6122,30 +6122,54 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, SETSYMBOL(&at, fielddesc_getsymbol(&x->x_value, template, data, 0)); else SETFLOAT(&at, fielddesc_getfloat(&x->x_value, template, data, 0)); drawnumber_sprintf(x, buf, &at); - /*sys_vgui(".x%lx.c create text %d %d -anchor nw -fill %s -text {%s}", - glist_getcanvas(glist), xloc, yloc, colorstring, buf); - sys_vgui(" -font {{%s} -%d %s}", sys_font, - sys_hostfontsize(fontsize), sys_fontweight);*/ - sys_vgui(".x%lx.c create ptext %d " - "[expr {[font metrics {{%s} %d} -ascent] + %d}] " - "-textanchor start -fill %s -text {%s}\\\n", - glist_getcanvas(glist), xloc, sys_font, - sys_hostfontsize(fontsize), yloc, colorstring, buf); + //sys_vgui(".x%lx.c create ptext %d " + // "[expr {[font metrics {{%s} %d} -ascent] + %d}] " + // "-textanchor start -fill %s -text {%s}\\\n", + // glist_getcanvas(glist), xloc, sys_font, + // sys_hostfontsize(fontsize), yloc, colorstring, buf); /* have to remove fontweight for the time being... */ - sys_vgui(" -fontfamily {%s} -fontsize %d", sys_font, fontsize); - sys_vgui(" -matrix { {%g 0} {0 %g} {0 0} }", xscale, yscale); + //sys_vgui(" -fontfamily {%s} -fontsize %d", sys_font, fontsize); + //sys_vgui(" -matrix { {%g 0} {0 %g} {0 0} }", xscale, yscale); + + char parent_tagbuf[MAXPDSTRING]; if (in_array) - sys_vgui(" -parent .scelem%lx.%lx \\\n", parentglist, data); + { + //sys_vgui(" -parent .scelem%lx.%lx \\\n", parentglist, data); + sprintf(parent_tagbuf,"scelem%lx.%lx", (long unsigned int)parentglist, (long unsigned int)data); + } else - sys_vgui(" -parent .dgroup%lx.%lx \\\n", - x->x_canvas, data); - - sys_vgui(" -tags {.x%lx.x%lx.template%lx scalar%lx}\n", - glist_getcanvas(glist), glist, data, sc); + { + //sys_vgui(" -parent .dgroup%lx.%lx \\\n", + // x->x_canvas, data); + sprintf(parent_tagbuf, "dgroup%lx.%lx", (long unsigned int)x->x_canvas, (long unsigned int)data); + } + char tagbuf[MAXPDSTRING]; + //sys_vgui(" -tags {.x%lx.x%lx.template%lx scalar%lx}\n", + // glist_getcanvas(glist), glist, data, sc); + sprintf(tagbuf, "drawnumber%lx.%lx", (long unsigned int)x, (long unsigned int)data); + + gui_vmess("gui_drawnumber_vis", "xssiiffsis", + glist_getcanvas(glist), + parent_tagbuf, + tagbuf, + xloc, + yloc, // Wrong-- we need to take font height into account + xscale, + yscale, + sys_font, + fontsize, + buf); + } + else + { + //sys_vgui(".x%lx.c delete .x%lx.x%lx.template%lx\n", + // glist_getcanvas(glist), glist_getcanvas(glist), glist, data); + char tagbuf[MAXPDSTRING]; + sprintf(tagbuf, "drawnumber%lx.%lx", (long unsigned int)x, (long unsigned int)data); + gui_vmess("gui_draw_erase_item", "xs", glist_getcanvas(glist), + tagbuf); } - else sys_vgui(".x%lx.c delete .x%lx.x%lx.template%lx\n", - glist_getcanvas(glist), glist_getcanvas(glist), glist, data); } static t_float drawnumber_motion_ycumulative;