Improve text renderer font default #442
Merged
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.
There is an inconsistency in the handling of default fonts depending on if you invoke the TextTexture renderer and call _calculateRenderInfo() directly (as I guess might be done as a pre-render measurement) or if you invoke the TextTexture normally in an attached Lightning Element via the 'text' property.
This Lightning playground example that @michielvandergeest sent me shows this inconsistency clearly. Press the 1, 2, 3, 4 keys and notice that as the text at the top changes, the measurements for pre and post render below are not the same, even though the same exact properties (both omitting
fontFace
) are passed in for both of those cases.If the
fontFace
property is not explicitly set, the default font actually used for text rendering differs in the two cases:null
is used which is automatically stringified as the font name "null", which is an invalid font name. The browser falls back to using a default font of its choosing.defaultFontFace
Stage setting is used. Which by default is "sans-serif".The
defaultFontFace
setting is pulled out only at the beginning of the_getSourceLoader()
method in the TextTexture. This code, as I understand it, is not hit when using the "Pre-render" method.The solution is the move the resolution code that converts a
null
into the Stage defineddefaultFontFace
into the method that builds the CSS font string that is passed to the Canvas2D context. This way no matter how the TextTexture is invoked/rendered it uses a consistent default.To-Do: