Align baselines of 2 fields

Bob Sneidar bobsneidar at iotecdigital.com
Thu Jun 21 20:23:52 CEST 2018


Okay new version. This adds an offset parameter for those cases where the baselines do not exactly align due to font weirdnesses. I also added the ability to pass a short name of a field, or else the long ID. Enjoy!

Bob S


on alignFieldBaselines pField1, pField2, pOffset
   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
   local fFormattedBottom1, fFormattedBottom2
   
   -- check passed parameters
   try
      if word 1 to 2 of pField1 is not "Field ID" then put the long id of field pField1 into pField1
      if word 1 to 2 of pField2 is not "Field ID" then put the long id of field pField2 into pField2
      if pOffset is empty then put 0 into pOffset
   catch theError
      return "Invalid parameter passed."
   end try
   
   -- get the formatted bottoms of both fields
   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
   
   -- calculate the descents of both fields
   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
   
   -- get the bottom of both fields
   put the bottom of pField1 into tBot1
   put the bottom of pField2 into tBot2
   
   -- calculate the differences
   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
   
   -- calculate and set the new bottom for field 2
   put the bottom of pField1 -(tDiff1 - tDiff2) into tRef
   set the bottom of pField2 to tRef  + pOffset
end alignFieldBaselines


More information about the use-livecode mailing list