fix: don't panic on whitespace glyphs; mark FT_BitmapGlyph cast unsafe#4
Open
MartenH wants to merge 2 commits into
Open
fix: don't panic on whitespace glyphs; mark FT_BitmapGlyph cast unsafe#4MartenH wants to merge 2 commits into
MartenH wants to merge 2 commits into
Conversation
Whitespace glyphs such as U+0020 SPACE legitimately load with an empty
outline (n_points == 0). load_glyph() panicked on this in debug builds
("FT_Outline_Translate requires loaded outline, got empty"), so any text
containing a space aborted a debug build.
FT_Outline_Translate on an empty outline is a no-op anyway, so guard the
translate on n_points > 0 and drop the panic. Release builds already
called FT_Outline_Translate unconditionally; this just makes the empty
case explicit and stops the debug-only abort.
Casting &C.FT_GlyphRec to &C.FT_BitmapGlyphRec is a pointer-type cast,
which V flags with a warning outside an unsafe block. Wrap it in unsafe {}
to make the intent explicit and silence the warning, consistent with the
other C-interop pointer casts in this module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small fixes found while bringing up vglyph on a native-Windows build (mingw-w64 / gcc 16), but neither is Windows-specific.
1. Don't panic on whitespace glyphs with empty outlines
Whitespace glyphs such as
U+0020 SPACElegitimately load with an empty outline (n_points == 0). In the subpixel-shift path,load_glyph()panicked on this in debug builds:So any text containing a space aborts a debug build.
FT_Outline_Translateon an empty outline is a no-op anyway, so this guards the translate onn_points > 0and drops the panic. Release builds already calledFT_Outline_Translateunconditionally; this just makes the empty case explicit and removes the debug-only abort.2. Wrap the
FT_BitmapGlyphRecpointer cast inunsafeload_stroked_glyph()casts&C.FT_GlyphRec→&C.FT_BitmapGlyphRec, a pointer-type cast that V warns about outside anunsafeblock. Wrapped inunsafe {}to make the intent explicit and silence the warning, consistent with the other C-interop pointer casts in the module.Both changes are
v fmt-clean. Verified by building a vglyph-based GUI app on both Linux and native Windows.