Align baselines of 2 fields

Knapp Martin martyknappster at gmail.com
Thu Jun 21 14:30:22 EDT 2018


Bernd,
I ran this at least 50 times and in the vast majority of cases the baselines align. In a few cases, as Bob noted, it was off by 1 pixel. But that will be OK for my use. I let users pick any font but sizes are limited from 8 to 20.

Thanks you guys. A very resourceful group, as usual!

Marty

> On Jun 21, 2018, at 11:00 AM, Niggemann, Bernd via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Hi Marty, 
> 
> depending how liberal you are in letting users choose fonts and sizes you might get "unexpected" results by aligning to field 1
> 
> 
> try this stress test
> 
> 
> ---------------------------------
> on mouseUp
>   lock screen
>   set the textfont of field 1 to any line of the fontNames
>   set the textfont of field 2 to any line of the fontNames
>   set the textSize of field 1 to random(20) + 10
>   set the textSize of field 2 to random(20) + 10
>  -- put the textFont of field 1 into field "Font1"
>  -- put the textFont of field 2 into field "Font2"
>   unlock screen
> end mouseUp
> ---------------------------------
> 
> then align via your script
> Your layout can start "moving"
> 
> Additionally not all fonts report proper ascents and descents
> 
> 
> 
> Kind regards
> Bernd
> 
>> Marty wrote:
>> This works for me, assuming you want to leave field 1 where it is and align field 2:
>> 
>> on alignFieldBaselines pField1, pField2
>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>> local fFormattedBottom1, fFormattedBottom2
>> 
>> put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
>> put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2
>> 
>> put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
>> put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2
>> 
>> put the bottom of fld pField1 into tBot1
>> put the bottom of fld pField2 into tBot2
>> 
>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>> 
>> put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef
>> 
>> set the bottom of fld pField2 to tRef   
>> end alignFieldBaselines
> 
> _______________________________________________
> 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