refactor(fontweight): allow unknown fontweight value #8
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.
Related with servo/servo#21076.
Given reproducible code snippet
When try to read weight from
Microsoft Yahei
, only onLight
weight will throw exception. surprisingly whileDWRITE_FONT_WEIGHT
enum doesn't specify it in documented listYahei
's light fontweight is not300
:but having adjusted value of
290
and enum conversion fails since there isn't matching value.This PR refactors
FontWeight
enum to not use discriminator values, and addFontWeight::Unknown(u32)
type to allow fallback if C enum contains non-matching values to enum values. There are couple of way I tried, but wasn't entirely sure around each approaches - except require manual matching from u32 value to enum and vice versa, this approach provides simplest way to resolve issue.Unknown(u32)
will provide fallback even if it occursStill, technically this can be breaking change if any consumer uses direct casting to u32 of enum values instead of using
to_u32()
interface: but so far I know there doesn't seem way to create non-breaking change if we'd like to have fallback values.Note: this doesn't resolve servo side crash immediately - servo need to implement to handle fallback values.