-
-
Notifications
You must be signed in to change notification settings - Fork 896
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
It would be great if konva would let us control ctx.textBaseline for Text #559
Comments
@kickthemooon what is your use case? Why exactly do you need it? |
The use case is that Canvas renders some fonts inproperly placing them to high in the Canvas so the font gets cut off at the top. Text baseline "alphabetic" (default) is the only textBaseline option that I could correlate to an actual font metric which is the font baseline. When alphabetic is used It is possible to caculate Y for the canvas text by having the font ascent to baseline ratio. https://jsfiddle.net/n1kLvro0/2/ That way the font is drawn on the canvas like it is rendered in an html element. |
Hmm. I am not sure how we will handle hit detection and |
I am closing the issue because I am not sure what exactly should we fix from But I am happy to see Pull Requests for some fixes, or direct demos with Konva where current default options don't work properly. |
Hey there @lavrton! You've got some great stuff going on with Konva, enjoying it very much. I just recently came across this issue where I personally was quite sure that Konva did render fonts correctly. We've been having issues with equalizing rendering for both frontend and backend, so I naturally put the blame on our immature backend libraries. The changes I made are public in this fork: https://github.com/bot-hydra/konva I didn't open up a pull request (yet) since I am not too sure about this solution being production-ready. Feel free to check out what I'm proposing and potentially use it as a hint for a proper implementation. For now I am hosting the modified module on GitHub packages, but would love to switch back once Konva actually supports correct text positioning! |
@rxsto It will be really nice if you can make a pull request and especially good if you can make any tests for that change. Probably, we can compare rendering with DOM text. |
I was able to fix the issue in my project. use measureText to get fontBoundingBoxAscent and fontBoundingBoxDescent; I'm not very familiar with the library internals, but probably following changes should be made measureSize function in Konva.Text should be extended to return fontBoundingBoxAscent and fontBoundingBoxDescent and then, probably in _sceneFunc, |
I need a help with testing. Ideas from @rxsto and @MykhailoIskiv gave me some thoughts to try the similar approach. To enable the fix:
|
Updated instructions on how to enable that mode until it is the default one. |
We have implemented this fix, and will do ongoing tests with our staging website and get back to you with results. Thanks for getting around to this issue, glad to see a fix in place! |
Closing the issue for having |
As far as I can understand from the code the canvas textBaseline is hard coded as "MIDDLE".
Would it be hard to make that configurable?
In my case I would need the default textBaseline "alphabetic" because alphabetic seems to be equal to the actual font baseline and I need to do some calculations relative to the font baseline.
The text was updated successfully, but these errors were encountered: