Skip to content

Conversation

@rdon-key
Copy link

@rdon-key rdon-key commented Sep 3, 2025

This pull request fixes an issue where GetGlyph could return the glyph of the next larger rune if the requested rune was not found in the font.
As a result, undefined characters could be rendered as completely unrelated glyphs (see #58).

Changes

  • Updated GetGlyph in both const1bit and const2bit packages:
    • Added an equality check (==) during the binary search.
    • Introduced a found flag to ensure that if no match is found, the function always falls back to index 0.
  • Updated function comments to explicitly state that undefined runes return the glyph at index 0.

Verification

  • Verified with const2bit fonts (WebAssembly rendering).
  • Could not test with const1bit fonts locally, but the implementation is identical.
tinyfont.WriteLine(target, &testfont, 10, 50, "①②③④⑤", color.RGBA{0, 0, 0, 255})
image

Impact

  • Undefined runes will no longer render as unrelated valid glyphs.
  • Instead, they consistently fall back to glyph 0 (commonly a space or placeholder).

Fixes #58

Copy link
Member

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. The content of the PR is excellent. I’d just like to request a few minor changes. @rdon-key

}

offset := uint32(font.OffsetMap[s*6+3])<<16 + uint32(font.OffsetMap[s*6+4])<<8 + uint32(font.OffsetMap[s*6+5])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the parts unrelated to the changes in this PR.
Of course, fixing them in a separate PR is totally fine.

@rdon-key rdon-key force-pushed the Bugfix/undefined-rune branch from 68ba123 to 0fc3f92 Compare November 10, 2025 04:32
@rdon-key
Copy link
Author

All unrelated changes have been reverted.
This PR now only includes the fallback fix for undefined runes.
Thanks for your review!

Copy link
Member

@sago35 sago35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for your contribution.
Now merging.

@sago35 sago35 merged commit 00be9f7 into tinygo-org:dev Nov 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants