lightning-js / renderer

Lightning 3 Renderer
Apache License 2.0
54 stars 23 forks source link

Text Rendering: Reported Text Height Change Proposal #170

Closed frank-weindel closed 5 months ago

frank-weindel commented 8 months ago

The following proposal aims to make the Reported Text Height, which is provided during the loaded event for Text Nodes, consistent between SDF and Canvas text renderers, closer to how HTML/CSS works, and solve some issues that have been reported around the current implementation:

The phases are divided as such to make it easier to grok the issues and their solutions. We could very well implement and release all of phases at once.

Phase 1: Make Reported Text Height dimension of text based purely on Line Height and number of lines rendered (plus offsetY)

Phase 2: Determine Default Line Height by Font Metrics

Phase 3: Make the Default Vertical Align text property value "middle"

chiefcll commented 8 months ago

👍

suresh-gangumalla commented 8 months ago

As per phase 2 proposal, With inter-Black MSDF type, "Wonka" text will have a line height of 48, and "Migration" text will have a line height of 56, based on the maximum character height in each word

If two texts have different line heights, how does the final rendered height become the same for a given font size?

frank-weindel commented 7 months ago

@suresh-gangumalla In Phase 2, the calculation of the Default Line Height is across all characters of the font, not just characters used in the text property of a text node. So both "Wonka" and "Migration" should result in the same Default Line Height since they both use the same font "Inter-Black".

frank-weindel commented 5 months ago

Updated the Phase 2 of the proposal to now rely on font metrics being provided explicitly by the developer (and extractable with the msdf-generator tool). This will have the added bonus of text between Canvas and SDF text renderers being able to be laid out consistently.