Skip to content

Soft hyphens (U+00AD) garble justified lines #69

Closed

Description

@scttfrdmn

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.

From the post-0.5.0 gap and feature review.

Activity

  1. added
    type: bug
    area: typography
    on Nov 16, 2026
  2. scttfrdmn commented on Nov 16, 2026

    @scttfrdmn
    OwnerAuthor

    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):

    if i+1 < end {
        // potential but unused hyphen: the soft hyphen or
        // zero-width space glyph stays in the span, invisible
        if t := glyphs[bg].Text; t == "­" || t == "​" {
            glyphs[bg].XAdvance = 0
            if id := glyphs[bg].SFNT.GlyphIndex(' '); id != 0 {
                glyphs[bg].ID = id
            }
        }
        bg += items[i].Size
    } else if ...

    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.

  3. scttfrdmn commented on Nov 16, 2026

    @scttfrdmn
    OwnerAuthor

    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).

  4. moved this from Todo to In Progress in inkcapon Nov 16, 2026
  5. moved this from In Progress to Done in inkcapon Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typographytype: bug

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions