question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Text's lineHeight implementation does not match HTML

See original GitHub issue

Text 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bigtimebuddycommented, Apr 1, 2021

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)

Screen Shot 2021-04-01 at 11 02 06 AM

0reactions
Bouhcommented, Apr 2, 2021

Here my result: https://jsfiddle.net/Bouh/0p1f5kc3/11/ image

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found