-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Text cursor position is incorrect after changing fonts (using font face observer) #4739
Comments
fabricjs.com/loadfonts it's the same issue in this demo, just by switching to pacifico. |
The only way to get it working correctly I found, is by bypassing the cache system in the text: Is that really important for perf? When is it called? |
Very weird. I do not understand whey calculation should fail just from the cache. |
yes in my getFontCache, I always return empty object... But I don't understand why it's working like that. |
Ok the culprit is here. We change the fontCache[_char] and I see this value changing with no reason for the same character in a same text block :
If I comment this it's working. |
Maybe when we measure the single char we should measure it with a space in front? |
yes I see what you mean, but I think the font measurement is correct. |
can you show me here the IE fix? |
It's in _measureChar method. I can't find it in GitHub UI (only in the raw file if I search for "// try to fix a MS browsers oddity") |
just make a copy paste of your file, for reference here. |
jsfiddle.net/xsLgppan/72/ I updated the fiddle with the change. |
i m sorry you already posted the fix here:
so what is happening is that MS measure fonts in pixels. a = '11.3' => 11 ab = 22.6 => 23 b kerned was then ab - a = 12. and this was normally wrong. But we see that with pacifico this is a possible use case. So we need a better logic. |
Okay I understand now. So a little difference accumulates on long lines even with simple font like Roboto. And I see some discussion about it already happened long time ago :D Automattic/node-canvas#331 |
With font yellowtail on IE 11.0 with the fix, it's pretty bad. Without it it's working quite well. |
After that fix i inserted another safety measure about ie CACHE_FONT_SIZE = 200 so i measure everything at 200 so that rounding measurement are a bit killed in this way. |
indeed. And this is a smarter fix than the other condition |
LOL is easy to say what fix is smarter when you did not had to find them in the first place :D :D :D :D |
:-D In fact you already fixed all the bugs in advance, you just forget you did it :-D |
Version
2.0.1
Test Case
http://jsfiddle.net/blobinabottle/xsLgppan/16/
Steps to reproduce
Change the text to Roboto and check last words of the fist line, the text cursor got an incorrect position.

It's worst if you select pacifico (I'm selecting SIT :-)).

Expected Behavior
Cursor should be a the right position.
Is there anything to do to avoid this situation? I tried clearFabricFontCache but not sure I've done it right.
The text was updated successfully, but these errors were encountered: