Skip to content

Commit

Permalink
Fix empty line rendering, 2nd try.
Browse files Browse the repository at this point in the history
Our first attempt in rev. 2f7b346 didn't quite work out because the
tspans were placed in slightly different y positions than before. So
we're back to relative baseline offsets now, and use the "hidden tspan"
trick from this article to make empty lines render correctly:

https://stackoverflow.com/a/58429593

Thanks to stackoverflow member Nate_C for this neat idea!
  • Loading branch information
agraef committed Sep 20, 2024
1 parent 0fabb29 commit 4451b70
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pd/nw/pdgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3796,14 +3796,17 @@ function text_to_tspans(cid, svg_text, text) {
fontsize = svg_text.getAttribute("font-size").slice(0, -2);
var dy = text_line_height_kludge(+fontsize, "gui");
for (i = 0; i < len; i++) {
// ag: We need to specify absolute y offsets for the baseline
// positions here. Relative dy offsets, which were used previously,
// don't advance the y position if no glyphs are rendered, so empty
// lines aren't rendered correctly.
tspan = create_item(cid, "tspan", {
y: ((i+1)*dy) + "px",
dy: i==0 ? 0 : dy + "px",
x: 0
});
if (/^\s*$/.test(lines[i])) {
// ag: empty spans won't render correctly, so add something other
// than a blank and hide the contents of the tspan. See
// https://stackoverflow.com/a/58429593
tspan.style.visibility = "hidden"
lines[i] = ".";
}
// find a way to abstract away the canvas array and the DOM here
text_node = patchwin[cid].window.document
.createTextNode(lines[i]);
Expand Down

0 comments on commit 4451b70

Please sign in to comment.