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 .
×
Advertisement Create a free account

How to calculate the width and height of a Text object?

1401263549

Edited 1401264505
Casey
Sheet Author
Text objects don't seem to get their dimensions set like other objects. When creating a text object, width and height default to 0, despite the fact the text 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 the dimensions on screen. Anyone have a way to measure the dimensions of a text object? Edit: Further research reveals that when a text object is manually rotated (using the handle), the dimensions are calculated and set in the object, but when you set the rotation with the API, the dimensions are never updated :S
1401871704
Casey
Sheet Author
Does anyone have any insight to this issue? As it stands positioning text object's is impossible with the API because of their variable width.
1401895160
Brian
Sheet Author
API Scripter
Perhaps you could develop a function to calculate it based on the text, font_size, and font_family properties? The fact that we have access to a small number of fonts helps here, although it would still be an arduous task considering the fonts are variable-width.
1401896053
Casey
Sheet Author
Yea, I've considered this. Arduous indeed :| One would have to calculate the width of every single character at every available font size for all the fonts. The results could be put into some sort of lookup table. That is a crapton of work to workaround such a simple bug.
1401898002
Brian
Sheet Author
API Scripter
Casey said: One would have to calculate the width of every single character at every available font size for all the fonts. Height and line-spacing as well, since the text can include newlines. I certainly have no intention of writing such a function. =P
1401898497
Casey
Sheet Author
Ugh, yea. You'd have to write the program outside Roll20, have it do the calculations and then export a javascript/json data set :\ Please Roll 20, just fix the bug :|