Skip to content

Conversation

@Smrtnyk
Copy link
Contributor

@Smrtnyk Smrtnyk commented Oct 23, 2025

closes #10775

@codesandbox
Copy link

codesandbox bot commented Oct 23, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

Build Stats

file / KB (diff) bundled minified
fabric 916.817 (+0.037) 301.696 (-0.015)

@Smrtnyk Smrtnyk force-pushed the When-the-line-height-of-the-text-is-set-to-0,-the-text-cannot-be-displayed branch from 1fa5453 to 13965e4 Compare October 23, 2025 17:29
height = 0;
for (let i = 0, len = this._textLines.length; i < len; i++) {
lineHeight = this.getHeightOfLine(i);
height += i === len - 1 ? lineHeight / this.lineHeight : lineHeight;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these calculations with 0 where giving NaN so I had to do fallbacks to fontSize
it passes still all unit tests and all visual tests
and you can see the new visual test output I added

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there's a small issue — the visual appearance of a line-height set to 0.01 should be almost the same as when it's set to 0, but judging from the image, the latter appears to be shifted a few pixels upward overall.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that is what I was not sure about, the first rendering of 0.1 is the current behavior
the rendering of 0 is the new behavior (previously would not even be shown) because I am now falling back to the font size if line height is 0, to avoid having NaN.
I agree with you, they should be almost the same
I have another idea, will give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhe-he could you recheck the visual screenshot again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

There’s still an issue — it’s probably caused by something that hasn’t been taken into account somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm So, this solution doesn't take in consideration style for fontsize. everything is so complicated with text.

does it make sense to go into every tiny detail
I mean this is already better than it was
maybe we can improve it incrementaly as we add more and more tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that for lineHeight = 0 we are assuming that fontSize is the size of the line, while the size of the line is the biggest fontSize in the line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have an improvement coming

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to go into every tiny detail
I mean this is already better than it was
maybe we can improve it incrementaly as we add more and more tests

No it doesn't make sense to exagerate.
LineHeight 0 would work without style, but the change in calcTextHeight would have caused a bug for the normal text that had style in the last line and that could be fairly common.

In general if reading it you get an idea and you think you can make it better quickly, you do it, otherwise no.
For example the clipPath i have no idea what to do in the other PR seems a mistery to unravel, and the partial fix is fine, i rather spend time in more useful issues than perfecting that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end we fixed the issue, we added a test, and we removed 15 bytes of code instead of adding 200.
So was win / win.

@Smrtnyk Smrtnyk force-pushed the When-the-line-height-of-the-text-is-set-to-0,-the-text-cannot-be-displayed branch from 04ccb4b to e3e5e9b Compare October 24, 2025 17:14
@Smrtnyk Smrtnyk force-pushed the When-the-line-height-of-the-text-is-set-to-0,-the-text-cannot-be-displayed branch from e3e5e9b to b8c6eec Compare October 27, 2025 14:51
@asturur asturur merged commit de9d722 into fabricjs:master Oct 31, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: When the line height of the text is set to 0, the text cannot be displayed.

4 participants