Is there a way to determine the baseline of text in a field?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Cairoo
Posts: 112
Joined: Wed Dec 05, 2012 5:54 pm

Is there a way to determine the baseline of text in a field?

Post by Cairoo »

Hello experts

I need to render mathematical formulae in my LiveCode cross-platform app. I tried going the MathML way with a browser but it just won't work consistently, so now I'm trying to write my own math rendering library. I ran into what seems to be a brick wall because I can't find a way to determine the baseline of text in a field. LC will let me find the height and line spacing, but it does no good in my quest for the baseline, which is crucial for lining up the math symbols with other formulae text.

Can anyone here help me out?

Thank you so much

Cairoo
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Is there a way to determine the baseline of text in a fi

Post by Mag »

Hi Cairoo, maybe you could solve the problem by setting the textShift of the chunk expression of the text instead of changing a property of the field, for example:

Code: Select all

on mouseUp
    set the textShift of word 1 to -1 of field myField to "-12" -- this example works well in a list field
end mouseUp
Please, see the attached stack.
Attachments
Shift.livecode.zip
(1.44 KiB) Downloaded 303 times
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Is there a way to determine the baseline of text in a fi

Post by jacque »

If you only need to do this for a single field (or several fields with the same text settings) then the easiest way is to keep changing the textshift of the text chunk until it looks right, then just hard-code that number into your script as a constant. Your script would set the textshift of the formula text to that number.

If you need to dynamically determine the textshift for fields of different textheights, then use the above method to find a good textshift number, and calculate what percentage of the textheight that number is. Store the percentage as a constant in the script. At run time, calculate the textshift by multiplying the textheight by that percentage. That should get you pretty close.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Post Reply