diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index a6548385d698511325468f7cfddc46b4070cdd45..435724e074aa2326dfc5c61fab8bb80bcfe40f16 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -1221,8 +1221,6 @@ function text_to_tspans(canvasname, svg_text, text) { // Get fontsize (minus the trailing "px") fontsize = svg_text.getAttribute('font-size').slice(0, -2); -gui_post("font size is " + (fontsize + 2)); - for (i = 0; i < len; i++) { tspan = create_item(canvasname, 'tspan', { dy: i == 0 ? 0 : text_line_height_kludge(+fontsize, 'gui') + 'px', @@ -1293,6 +1291,10 @@ function gui_text_new(canvasname, myname, type, isselected, left_margin, font_he var lines, i, len, tspan; var g = get_gobj(canvasname, myname); var svg_text = create_item(canvasname, 'text', { + // Maybe it's just me, but the svg spec's explanation of how + // text x/y and tspan x/y interact is difficult to understand. + // So here we just translate by the right amount for the left-margin, + // guaranteeing all tspan children will line up where they should be transform: 'translate(' + left_margin + ')', y: font_height + gobj_font_y_kludge(font), // Turns out we can't do 'hanging' baseline @@ -2218,33 +2220,60 @@ function gui_plot_vis(cid, basex, basey, data_array, attr_array, tag_array) { } } +// This function doubles as a visfn for drawnumber. Furthermore it doubles +// as a way to update attributes for drawnumber/symbol without having to +// recreate the object. The "flag" argument is 1 for creating a new element, +// and -1 to set attributes on the existing object. function gui_drawnumber_vis(cid, parent_tag, tag, x, y, scale_x, scale_y, - font, fontsize, text) { + font, fontsize, fontcolor, text, flag, visibility) { 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); + var svg_text; + if (flag === 1) { + 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. :) + + // For an explanation of why we translate by "x" instead of setting + // the x attribute, see comment in gui_text_new + 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', + fill: fontcolor, + visibility: visibility === 1 ? 'normal' : 'hidden', + 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); + } } else { - gui_post("gui_drawnumber: can't find parent group" + parent_tag); + svg_text = get_item(cid, tag); + configure_item(svg_text, { + 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', + fill: fontcolor, + visibility: visibility === 1 ? 'normal' : 'hidden', + id: tag + }); + svg_text.textContent = ""; + text_to_tspans(cid, svg_text, text); } } diff --git a/pd/src/g_template.c b/pd/src/g_template.c index 267a0b58c75d48164fb40bab442d01fa01a9f6a6..877722606c4294f331bdd768996948fb70c624f4 100644 --- a/pd/src/g_template.c +++ b/pd/src/g_template.c @@ -6252,8 +6252,8 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, }*/ /* see comment in plot_vis() */ - if (vis && !fielddesc_getfloat(&x->x_vis, template, data, 0)) - return; + //if (vis && !fielddesc_getfloat(&x->x_vis, template, data, 0)) + // return; if (vis) { t_atom at; @@ -6310,8 +6310,7 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, //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", + gui_vmess("gui_drawnumber_vis", "xssiiffsissii", glist_getcanvas(glist), parent_tagbuf, tagbuf, @@ -6321,7 +6320,10 @@ static void drawnumber_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, yscale, sys_font, fontsize, - buf); + colorstring, + buf, + vis, + (int)fielddesc_getfloat(&x->x_vis, template, data, 0)); } else { @@ -6705,8 +6707,8 @@ static void drawsymbol_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, }*/ /* see comment in plot_vis() */ - if (vis && !fielddesc_getfloat(&x->x_vis, template, data, 0)) - return; + //if (vis && !fielddesc_getfloat(&x->x_vis, template, data, 0)) + // return; if (vis) { t_atom at; @@ -6764,7 +6766,7 @@ static void drawsymbol_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, // 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", + gui_vmess("gui_drawnumber_vis", "xssiiffsissii", glist_getcanvas(glist), parent_tagbuf, tagbuf, @@ -6774,7 +6776,10 @@ static void drawsymbol_vis(t_gobj *z, t_glist *glist, t_glist *parentglist, yscale, sys_font, fontsize, - buf); + colorstring, + buf, + vis, + (int)fielddesc_getfloat(&x->x_vis, template, data, 0)); } else { @@ -7597,12 +7602,16 @@ void svg_parentwidgettogui(t_gobj *z, t_scalar *sc, t_glist *owner, } else if (pd_class(&z->g_pd) == curve_class) { - /* We just call the visfn with a flag of -1 to signal + /* For old commands we call the visfn with a flag of -1 to signal changing attributes instead of creating a new one. Not sure what to do with arrays yet-- we'll probably need a parentglist below instead of a "0" */ curve_vis(z, owner, 0, sc, data, template, 0, 0, -1); } + else if (pd_class(&z->g_pd) == drawnumber_class) + drawnumber_vis(z, owner, 0, sc, data, template, 0, 0, -1); + else if (pd_class(&z->g_pd) == drawsymbol_class) + drawsymbol_vis(z, owner, 0, sc, data, template, 0, 0, -1); } /* ---------------------- setup function ---------------------------- */