Page 1 of 1

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

Posted: Mon Nov 04, 2013 10:56 am
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

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

Posted: Mon Nov 04, 2013 6:14 pm
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.

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

Posted: Mon Nov 04, 2013 8:21 pm
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.