Skip to content

Long URLs, identifiers and inline code overflow the page and table cells #60

Closed

Description

@scttfrdmn

A long URL or a long inline-code identifier (`pkg.(*T).method`) runs past the right margin, and in a wide table neighbouring cells overlap. The Knuth-Plass breaker has no break opportunity inside a long token.

Fix direction: in emit/buildText, insert zero-width break opportunities after / . _ - ? & = in link text and code spans, and fall back to a forced character break when a single token is still wider than the measure. In table.go, cellWidths/solve should cap a column's minimum width so other columns aren't starved.
Test: no glyph's x-extent exceeds the right margin or its cell, for a long URL in body text and in a table.

From the post-0.5.0 gap and feature review.

Activity

  1. added
    type: bug
    area: layout
    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. added a commit that references this issue on Nov 16, 2026
  5. moved this from Todo to In Progress in inkcapon Nov 16, 2026
  6. 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: layouttype: bug

    Type

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions