-
Notifications
You must be signed in to change notification settings - Fork 666
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
TextFormatter.getWidthForTextInEm vs SVGContext.measureText used for width calculations #1465
Comments
I vote for speed ;) did anyone ever have serious issues with the precision? |
I have been investigating the speed issue and I found a possible solution to get speed but also accuracy. What I did:
The above showed, as expected, that SVGContext was much slower but it also revealed that the CanvasContext variant was very accurate and fast enough.
"a very long String with Mixed Case Text,(0123456789)" 1000 iterations without cache
@sschmidTU @AaronDavidNewman @ronyeh what do you think? |
It seems promising but where do you get a HTMLCanvasElement when you are in SvgContext? |
Aaron brings up a good point. There can be implementations where SVG is supported but Canvas is not. For example, see the demos in: vexflow/demos/node/ (especially svg.js). If we want to use the canvas implementation for measuring text, we need to make sure we have a fallback to the existing or SVG-only method of measuring text. Let's try not to break the small demos in |
@AaronDavidNewman @ronyeh please have a look at the file changes in #1466 |
Did you try using an SVGContext for the measurement, but different than the main one used for the music? The real problem with using SVGContext is the forced reflow, because you are forcing a redraw every time you measure. Canvas may also be faster in general, I don't know. I think this idea has promise, but I don't think we should keep a canvas element in FontInfo. I think we should continue to use TextFormatter for this purpose, regardless of how the estimation is actually done. Because TextFormatter has information about fonts and how they're used that isn't contained elsewhere. And we may find an even better way to do estimation in the future (like a browser API) and the dependent logic won't have to change.
|
No I did not.
The measures above indicate 100 times quicker
Do you want me to move the methods from Font to TextFormatter?
I would leave the conetxt as an internal detail. As you said this might change to a different implementation in the future.
If the canvas method works for all, I would use this one and reduce the ammount of static data.
I think that with the speed we have, the cache is not required. |
As discussed in #1459 measureText is slower, however much more precise in the calculation.
If we want to move away from this function we should improve the TextFormatter calculation.
The text was updated successfully, but these errors were encountered: