Center text within a field?

Joe Lewis Wilkins pepetoo at cox.net
Wed Jun 6 20:09:30 EDT 2007


I realize it would take a lot of initial work, but you guys seem up  
for it: why not just use a lookup table with the exact values you  
need for each font "condition" listed? Of course, you can limit the  
amount of preparation by just limiting the acceptable fonts and  
perhaps some of the other ranges as well. This way the table of  
values could be expanded over time and by others if need be without  
coming up with any "exact" formulation at the outset. Just a thought!

Joe Wilkins

On Jun 6, 2007, at 4:47 PM, J. Landman Gay wrote:

> 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.




More information about the use-livecode mailing list