Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(fabric.Text): Avoid reiterating measurements when width is 0 and measure also empty lines for consistency. #7497

Merged
merged 2 commits into from
Nov 25, 2021

Conversation

avra-m3
Copy link
Contributor

@avra-m3 avra-m3 commented Nov 18, 2021

Very small PR, I noticed we were hitting measure text more than expected and found this to be the cause.

Happy for this to be declined If I've misunderstood these checks :)

src/shapes/text.class.js Outdated Show resolved Hide resolved
@avra-m3
Copy link
Contributor Author

avra-m3 commented Nov 18, 2021

Looking into this further, fabric is actually dependent on the line === '' check failing as it doesn't create the charBounds value otherwise

lineInfo = this.measureLine(lineIndex);
width = lineInfo.width;
}
var lineInfo = this.measureLine(lineIndex);
Copy link
Member

Choose a reason for hiding this comment

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

does measureLine have the same check inside?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not as far as I have seen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I stepped through line by line, I got as far as this._measureChar with an empty string.

Copy link
Member

Choose a reason for hiding this comment

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

So why we want to skip the shortcut and go far down with the empty 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 m happy about the fix, i want to understand why we also remove the shortcut. Is not of immediate understanding to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I fixed the shortcut, it caused an error when a line consisted solely of a blank space because _charBounds[x] is undefined.

My understanding is that this._measureLine sets _charBounds for each line so we shouldn't skip it otherwise other parts of the code will fail :(.

We could restore the check but currently it's the equivalent of if(false) because [''] will never equal '',

Fixing it to act as a shortcut is probably possible, I'd need to investigate further and may have consequences when it comes to how different platforms measure blank newlines?.

Copy link
Member

Choose a reason for hiding this comment

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

no is ok as it is.
The fact that skipping measurements was creating error elsewhere is good to me.

@avra-m3
Copy link
Contributor Author

avra-m3 commented Nov 19, 2021

Run ChristiaanScheermeijer/jest-reporter-action@v0.4.0
Error: Resource not accessible by integration
How can I fix this test failure?

@asturur
Copy link
Member

asturur commented Nov 25, 2021

that failure is just the coverage, i have no idea how to make it work on forks.

@asturur asturur changed the title Fix what appear to be bugs in some of the text cache checks Fix(fabric.Text): Avoid reiterating measurements when width is 0 and measure also empty lines for consistency. Nov 25, 2021
@asturur asturur merged commit e8f9eea into fabricjs:master Nov 25, 2021
rockerBOO pushed a commit to rockerBOO/fabric.js that referenced this pull request Nov 27, 2021
@asturur asturur mentioned this pull request Jan 26, 2022
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.

3 participants