Precise Text Positioning #9353
Replies: 2 comments 14 replies
-
Please share a reproduction |
Beta Was this translation helpful? Give feedback.
-
@FrothyFrog the text in fabric ( and every object ) is positioned by the top left corner of the bounding box. It would be nice if you could explain what you are looking for precise text positioning. |
Beta Was this translation helpful? Give feedback.
-
I'm recently new to Fabric and I find there's one thing that really puzzles me. There doesn't seem to be a clean way of precisely positioning text, but then again it may be that it's just as hard to find good documentation.
The bounding box data returned by a text object using getBoundingRect is clearly off to the point where it can't be used to reliably position the text, based on my understanding. The area (padding?) around the text within the bounding box varies greatly depending on the font size and angle. To precisely site the text you simply can't have a variable amount of space within the bounding box on all four sides of the text. Ideally, it should be a clean cutout, but it's not.
The only thing that seems to give a reliable metric on the text is using getCenterPoint after Left and Top have been set. This does indeed return the center, as opposed to calculating the center based on the data from GetBoundingRect, which should be usable but it falls far from the mark.
Generally, my technique is to find a move-to point and then move the text bounding box from its center to the move-to point. But I can't find any way to do this in Fabric, and I've searched for three days.
What is it I'm I missing, or is this just the way it is? Is there a resource that goes into detail on this?
Beta Was this translation helpful? Give feedback.
All reactions