Center text within a field?
J. Landman Gay
jacque at hyperactivesw.com
Wed Jun 6 18:47:49 CDT 2007
Trevor DeVore wrote:
> On Jun 6, 2007, at 4:01 PM, J. Landman Gay wrote:
>> Version 2:
>> on mouseUp
>> set the width of fld 1 to the width of grc 1
>> get the textsize of fld 1
>> if it < 20 then add 5 to it
>> set the textheight of fld 1 to it
>> set the height of fld 1 to it
>> set the loc of fld 1 to the loc of grc 1
>> end mouseUp
>> For this one, set the fixedLineHeight of the field to true, and the
>> margins to 0. (It also depends on the font and size of the field
>> rather than individual textchunks.)
>> It seems to work with the webdings example and a few others I tried up
>> to a textsize around 100. More than that and it starts to drift
>> downward, depending on the font. If the above isn't suitable I guess
>> your image solution is the way to go.
> This one works for webdings for me as well. I tried it with Arial (on
> Mac), textsize set to 48 and the "1" drifted towards the top of the
> circle. Does Arial work on your machine?
Pretty close to center, but yeah, it drifts up a bit. What the handler
needs is a math calculation. I stuck in the "if" clause because very
small fonts got clipped at the top without adding some overhead, whereas
larger sizes shouldn't have any additional textheight at all. So the
math would ideally calculate a variable textheight based on the text
size. Small sizes would get extra textheight and large sizes would get less.
For example, the Ariel 48 text works if the textheight is 55, so the
textheight needs to be calculated by multiplying the text size times
about 1.15. For 12-point, a textheight of about 20 seems right. For 100
point, textheight (using Ariel) requires about 135. But for Webdings,
100 point text needs 100 textheight.
So it's font dependent and we're back where we started. :( You may be
stuck with your images after all, since there is no good way to read the
actual positioning of the glyph inside its text box.
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode