fix font string parsing to support full CSS font shorthand syntax#226
Merged
Conversation
The old parser split on the first space, causing any font string with style/weight keywords (e.g. "bold 12px Arial") to silently corrupt the font state (size = NaN, family = "12px Arial"). Replaced it with parseFontString() which iterates tokens and correctly recognises style (italic, oblique), variant (small-caps), weight keywords and numeric weights (100–900), then requires a unit-suffixed size token (px/pt/em/rem/etc.) before taking the remainder as the family name. Invalid strings now leave _font unchanged. The getter is updated to reconstruct a proper CSS font string from all stored properties. Added test/font-parsing.test.ts with 39 tests covering all previously untested combinations. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
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.
The old parser split on the first space, causing any font string with style/weight keywords (e.g. "bold 12px Arial") to silently corrupt the font state (size = NaN, family = "12px Arial").
Replaced it with parseFontString() which iterates tokens and correctly recognises style (italic, oblique), variant (small-caps), weight keywords and numeric weights (100–900), then requires a unit-suffixed size token (px/pt/em/rem/etc.) before taking the remainder as the family name. Invalid strings now leave _font unchanged. The getter is updated to reconstruct a proper CSS font string from all stored properties.
Added test/font-parsing.test.ts with 39 tests covering all previously untested combinations.
Types of changes
Checklist
Description