Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[BUG] Text object dimensions not set

1401896743
Casey
Sheet Author
(this is a crosspost from the API forum, after investigating more I'm convinced this is an API bug) Text objects aren't getting their dimensions set like other objects. Symptoms: When creating a text object, width and height default to 0, despite the fact the text object has non-zero dimensions. Setting the width and height parameters in createObj or manually with .set() has no effect Since 'left' and 'top' are calculated based on the center of the text, it's virtually impossible to correctly position arbitrary sized text objects without knowing their dimensions on screen. Manually rotating a text object (using the rotate handle) causes the dimensions to be available via the API. But when you set the rotation with the API, the dimensions are never updated and remain 0. Consequence: As it stands positioning text objects with the API is impossible because of their variable width and the fact the coordinates are zeroed on the center of the object.
1401915025

Edited 1401915136
Riley D.
Roll20 Team
Hmmm...looking at this, I'm not sure why I ever included the width/height properties on the Text object in the API in the first place, as there is no concept of width/height for text objects in the actual program, just font_size. The graphics engine obviously has a way to figure out the bounding rect of a text object, though, so maybe I'll see if I can port that code to the API at some point in the future. At any rate, it's not a bug in the sense that "this isn't getting set and it should be", it's a bug in the sense that "these properties should not have existed in the first place for text objects", since as you noted that are always just 0. I can see how you would want to get the bounding rect of a text object, though, so I'll see what can be done in that regard. However, it's not really ever going to be possible to *set* the width/height of a text object, as noted it's just based on font_size.
1401916428
Lithl
Pro
Sheet Author
API Scripter
A calculateDimensions(textObj) function (or similar) would be perfectly acceptable, I think. Java, for example, uses getStringBounds in the Font class, returning a Rectangle2D. It absolutely makes sense to not be able to set the bounds (that would require automatic word-wrapping, which we don't have), but a calculation is useful.
1401916663

Edited 1401916764
Casey
Sheet Author
Thanks for looking at this Riley. I guess this is indeed a feature request then :) I find it interesting that the width/height values are populated AFTER the object is manually rotated. You've obviously hooked up the API to the right variable/event in some place. Maybe hooking it the rest of the way up won't be too difficult? I'd really appreciate it if you could see about populating those width/height values. Like I said before its basically impossible to position text objects in relation to other objects, which is pretty crucial for the game automation script I'm working on. Or, an alternative would be to zero the bounding rect for text objects at the top/bottom left/right of the path. This at least would let us (imperfectly) layout text objects horizontally. A workaround Brian and I considered (in the API thread) was to pre calculate the width, height of every character for every possible font size, line height and font family. This data would be compiled into a lookup table, and included in an API script. Needless to say, this would (1) require tons of work and (2) severely bloat the size of API scripts unnecessarily. Edit: Riffing of what Brian said, I also support making width and height readonly values. No reason they should be editable, except indirectly through the editing the font family, size, and text values.
having issues , i made a campaign and cant get back on it to edit it, how do i do that, please message me back if you could, thanks :)
You should post that as a different thread, since it is unreleated to this issue and will probably be ignored.
1402505063
Casey
Sheet Author
@Riley to give you an idea of what I am trying to do, here's a screenshot. I'm trying to programmatically layout a simple list of tokens (the dice) next to some text. This seemingly simple task is basically impossible since the text dimensions are unknown. Ideally I'd like to be able to know the text dimensions, and even wrap it after a specific length. This is a crucial piece of the game system I'm playing on :S These items move around a lot on the table, are added and removed frequently, so currently, manually placing them eats up tons of time.