Laying out text
paul at livecode.org
Mon Feb 23 05:04:26 CET 2015
> On Feb 22, 2015, at 5:18 PM, Dr. Hawkins <dochawk at gmail.com> wrote:
> measureText . . .
> Should "width" give the same dimension as the formattedWidth if one put the
> text into the field?
No, if you use measureText it only measures the text according to the parameters that you supply, it doesn't take into account any properties other than font and font size AFAIK, whereas formattedWidth measures the text in the field along with the margins effectively giving the field width.
> And can this one be done without opening the card containign the field
Yes, measure text can take the font/size from different controls too, so if the field doesn't exist yet you can use a reference to another control, group, card or stack.
e.g. If your card 1 was set with a font of Helvetica and a text size of 14…
put measureText("Measure this text",card 1) into theTextWidth
… theTextWidth would equal 106 and "Measure this text" does not need to be on card 1.
Try it, it works very well from my experience, although I suspect there may be some caveats that I haven't discovered yet.
More information about the use-livecode