You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A paragraph containing soft hyphens, set in a narrow measure, renders with words split apart, wide gaps and overlapping glyphs. canvas's Knuth-Plass breaker treats U+00AD as a hyphenation point but positions the pieces incorrectly. Pasted text often contains soft hyphens, and fixing this is a prerequisite for real hyphenation.
Investigate: reproduce with canvas alone; fix upstream or strip U+00AD in emit as a stopgap. Tracked with the other canvas fixes.
Root cause found; it's in canvas, and it's shared by #60 and #69.
canvas already treats U+200B (zero-width space) and U+00AD (soft hyphen) as optional breaks (text/linebreak.go, GlyphsToItems). In RichText.ToText (text.go), the branch for a potential but unused break doesn't advance the glyph index past that character. Every unused U+200B or U+00AD on a line therefore shifts the rest of the line's text by one glyph. That's the garbling in #69, and it's why breaking long tokens at inserted U+200B (#60) currently renders as "Fallba / kAndVeryLongNam e".
Verified fix (applied to a scratch copy via a temporary replace; the repo is unchanged):
ifi+1<end {
// potential but unused hyphen: the soft hyphen or// zero-width space glyph stays in the span, invisibleift:=glyphs[bg].Text; t==""||t=="" {
glyphs[bg].XAdvance=0ifid:=glyphs[bg].SFNT.GlyphIndex(' '); id!=0 {
glyphs[bg].ID=id
}
}
bg+=items[i].Size
} elseif...
With the fix, inline code and URLs wrap at the inserted U+200B, soft-hyphenated paragraphs render cleanly, and pdftotext extracts the text intact. IBM Plex has no U+200B glyph, which is why the glyph is drawn as a zero-advance space.
Next: this needs a canvas change, either an upstream PR to tdewolff/canvas or a fork with a replace directive in the meantime. Note that go install …@version ignores replace directives, so a fork alone would leave go install builds unfixed. Waiting on the user's decision.
Upstream fix opened: tdewolff/canvas#397 ("Fix text shifting after an unused soft hyphen or zero-width space"), from the scttfrdmn/canvas fork, branch fix-unused-optional-break. It includes the regression test TestRichTextUnusedOptionalBreaks, which fails on canvas master and passes with the fix. How inkcap picks up the fix before upstream merges is still being decided (a replace directive or a module-renamed fork).
Activity
scttfrdmn commentedon Nov 16, 2026
Root cause found; it's in canvas, and it's shared by #60 and #69.
canvas already treats U+200B (zero-width space) and U+00AD (soft hyphen) as optional breaks (
text/linebreak.go,GlyphsToItems). InRichText.ToText(text.go), the branch for a potential but unused break doesn't advance the glyph index past that character. Every unused U+200B or U+00AD on a line therefore shifts the rest of the line's text by one glyph. That's the garbling in #69, and it's why breaking long tokens at inserted U+200B (#60) currently renders as "Fallba / kAndVeryLongNam e".Verified fix (applied to a scratch copy via a temporary
replace; the repo is unchanged):With the fix, inline code and URLs wrap at the inserted U+200B, soft-hyphenated paragraphs render cleanly, and
pdftotextextracts the text intact. IBM Plex has no U+200B glyph, which is why the glyph is drawn as a zero-advance space.Next: this needs a canvas change, either an upstream PR to tdewolff/canvas or a fork with a
replacedirective in the meantime. Note thatgo install …@versionignoresreplacedirectives, so a fork alone would leavego installbuilds unfixed. Waiting on the user's decision.scttfrdmn commentedon Nov 16, 2026
Upstream fix opened: tdewolff/canvas#397 ("Fix text shifting after an unused soft hyphen or zero-width space"), from the scttfrdmn/canvas fork, branch
fix-unused-optional-break. It includes the regression testTestRichTextUnusedOptionalBreaks, which fails on canvas master and passes with the fix. How inkcap picks up the fix before upstream merges is still being decided (a replace directive or a module-renamed fork).