Text's lineHeight implementation does not match HTML
See original GitHub issueText lines are current aligned to the top. When for instance the lineHeight
is bigger than the fontSize
the gap gets added to the bottom.
This is not how HTML or graphics editors work.
Rubén from the Slack channel thinks this is due to this code in Text.ts:
linePositionY = ((style.strokeThickness / 2) + (i * lineHeight)) + fontProperties.ascent;
Maybe not everyone is building a graphics editor like me in PIXI, but I don’t see why PIXI shouldn’t be as close as possible to how HTML works.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Line-Height does not match the font-size - Stack Overflow
My question is: Why the bottom of the 'j' is out of the box of the text? It looks like if I put...
Read more >Text's lineHeight implementation does not match HTML #7344
Text lines are current aligned to the top. When for instance the lineHeight is bigger than the fontSize the gap gets added to...
Read more >line-height - CSS: Cascading Style Sheets - MDN Web Docs
The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text.
Read more >How to Tame Line Height in CSS
We will need some content, so let's an create an <h1> tag with some text and set the line-height to something obnoxiously huge,...
Read more >Proposed Line height in style attributes is not !important - W3C
This rule checks that the style attribute is not used to prevent adjusting line-height by using !important , except if it's at least...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Problem
To rephrase the problem a little more specifically:
PixiJS does not respect the line-height for the first line so it’s impossible to know where the baseline is positioned. With HTML-based text rendering, line-height is always added to the first line so you know exactly where the baseline is relative to the top of the element.
@nuthinking and I chatted, and he’s going to sponsor a bounty for someone who can fix this.
Example
Here’s a preview (HTML on top, PixiJS on bottom) from @nuthinking demo above:
https://jsfiddle.net/bigtimebuddy/t10wnyvf/ (moved to fiddle so we have a stable link)
Here my result: https://jsfiddle.net/Bouh/0p1f5kc3/11/
I’ve added few comment for see where are my changes. See for //ADDED by Bouh at the end of script tag in HTML part. If you are interested i can open a PR for it in few hours when i go back to my home for a proper & clean view on changes.