Vertically aligning text in a field

Geoff Canyon gcanyon at gmail.com
Sat Dec 20 18:59:30 EST 2014


Not sure what's up with the offset that seems constant and inherent, but
this corrects for it. It does nothing about the apparent offset caused by
the difference between the textheight and and textsize of the first line,
because if the size varies, the textsize returns "mixed." In any case, this
works for me to a reasonable degree of accuracy:

   set the topmargin of fld 1 to (8 + the height of fld 1 - the
formattedheight of line 1 to -1 of fld 1) div 2

Here's a demo stack that shows what this does. Each time you click the Test
button the text changes, then vertically aligns, then puts in two
equal-height boxes above and below to show the results.

https://dl.dropboxusercontent.com/u/41182876/vertical%20text%20demo.livecode

On Sat, Dec 20, 2014 at 11:24 AM, J. Landman Gay <jacque at hyperactivesw.com>
wrote:

> On 12/20/2014, 1:18 PM, J. Landman Gay wrote:
>
>  I found that by adding a small number of pixels to the top margin I
>> could get it close, which is what Bernd was doing too. I've been trying
>> to figure out where the problem is, but like him, I don't see anything
>> offhand. I'm pretty sure the engine must either be adding padding to the
>> top line, or else not reporting the underhang of the last line, which
>> makes the formattedWhatever functions not quite exact.
>>
>
> On the theory that the problem isn't at the top but rather at the bottom,
> I calculated the amount of space occupied by the (imaginary) line 0 in the
> field. I think in general 2/3 of the text is placed above the baseline and
> 1/3 of it is placed below that. So the top line would be offset by 1/3 the
> textheight of the (nonexistent) line 0.
>
> This seems to come closer to what we want:
>
> put round(the effective textheight of fld 1 * .66) into tUnderHang
>     set the topmargin of fld 1 to (the height of fld 1 - (the
> formattedheight of line 1 to -1 of fld 1) + tUnderHang) div 2
>
>
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list