Skip to content

Fix lvfontio full width glyphs#10865

Merged
tannewt merged 3 commits into
adafruit:mainfrom
FoamyGuy:lvfontio_fix_full_width_glyphs
Mar 5, 2026
Merged

Fix lvfontio full width glyphs#10865
tannewt merged 3 commits into
adafruit:mainfrom
FoamyGuy:lvfontio_fix_full_width_glyphs

Conversation

@FoamyGuy
Copy link
Copy Markdown
Collaborator

@FoamyGuy FoamyGuy commented Mar 4, 2026

This PR has 3 fixes for lvfontio.

  • Fix header.default_advance_width from getting set to the wrong value. With Unifont 8x16/16x16 font the value of this was ending up as 4 which caused the right half of full-width glyphs not to render properly. Resolves: lvfontio only renders the left part of full width glyphs #10864. Fixed by ignoring zero advance glyphs when inferring the cell width.
  • Fix a call to f_read() with NULL last parameter. The LLM suggested this fix without explicit prompt while working on this file. I am unsure about it, but I did find that all of the other instances of f_read() in this file use the same kind of bytes_read var for this argument, so the fix makes this instance match the rest.
  • Fix right side slot possibly being overwritten by find_free_slot(). This one I even less sure about, but was also suggested by the LLM as a potential fix for only the left half of the glyphs showing, albeit not actually fixing that issue in practice. Resolved by adding slot_has_active_full_width_partner() and checking it before returning the slot.

Tested fix on Fruit Jam and confirmed it now shows the full width glyph:
image

Debugging and the proposed fix for this issue were done with help from LLM

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Just a couple of things.

Comment on lines +758 to +764
// Don't evict one half of a full-width pair while the other half is still in use.
if (slot > 0 && self->codepoints[slot - 1] == codepoint && self->reference_counts[slot - 1] > 0) {
return true;
}
if (slot + 1 < self->max_glyphs && self->codepoints[slot + 1] == codepoint && self->reference_counts[slot + 1] > 0) {
return true;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there is an edge case here where the slot if at the start or end. Instead of just testing the bounds, you'll want to do the + or - and then mod to wrap around.

Comment thread shared-module/lvfontio/OnDiskFont.c Outdated
// Ignore zero-advance glyphs when inferring the terminal cell width.
// Some fonts include placeholders/control glyphs with zero advance,
// which would otherwise skew default_advance_width too small.
if (glyph_advance > 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this would be slightly easier to read as an if (glyph_advance == 0) { first condition that falls through to the rest.

Comment thread shared-module/lvfontio/OnDiskFont.c Outdated

// Check if this is a full-width character by looking for a second slot
// with the same codepoint right after this one
bool cached_is_full_width = existing_slot + 1 < self->max_glyphs &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will likely have the same wrapping issue. I think my intent was to have one reference count in the left side of the glyph.

@FoamyGuy
Copy link
Copy Markdown
Collaborator Author

FoamyGuy commented Mar 4, 2026

Those changes are made in the latest commit. Updated both spots with modulo logic for wrapping, and changed the structure of the if statement for clarity. I retested the latest version on Fruit Jam and confirmed full width glyph is still showing as expected.

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks!

@tannewt tannewt merged commit 89a726e into adafruit:main Mar 5, 2026
525 checks 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.

lvfontio only renders the left part of full width glyphs

2 participants