g.TextHeight vs g.StringHeight

Greetings,

Apparently I need to draw some text on a canvas, and while trying to get the text height so I can calculate the rest, using the deprecated

g.StringHeight I get the proper height while on the new g.TextHeight I get always 15

Can somebody please explain to he how this should be properly used ?

In my case I draw same text in same location but I get 2 different sizes depending on the api I use.

XOJO 2020 R1.2 in my case in macOS Catalina, if that matters.

Thanks in advance.

Can you please post your code to see what’s going on here? Don’t have problems using g.TextHeight.

StringHeight & TextHeight serve two different functions:

StringHeight can be used to measure the height of a string that can wrap over multiple lines.

TextHeight tells you the overall height of the font which is the equivalent of 1 line.

Well yes and no, as based on the XOJO Documentation it says that " Graphics.StringHeight - This item was deprecated in version 2019r2 .
Please use Graphics.TextHeight as a replacement." so, normally based on official documentation that part is deprecated and we should use " Graphics.TextHeight" that in theory should do same thing, but as you said It doesn’t so deprecated or not, we still can use it but you cannot deprecate something , change the usage of it, usually when you deprecate something you replace it with something that works better or it should work better than the previous and do the same functions or more, in this case it does less and does not do whatever it was supposed to do. So in our case if we want same functionality as StringHeight what we should use that it is not deprecated ?

I get same results for h and h2. On my system with the default font, the result is 57.

Dim txt As String = "this is a long sentence that should wrap and have several lines"

Dim h as double = g.stringheight(txt, 100) //Result is 57

dim h2 as double = g.TextHeight(txt, 100) //Result is 57

Dim lineHeight As double = g.TextHeight //Result is 15

Indeed, I guess I use it wrong, as I was getting the line height instead of the actual text height so that figures the issues I had.

Thanks for pointing that up

Ah - I see TextHeight has been extended so that it can accept the string and wrap width. I was not aware of that.

A quick test on my Mac using 2020r1 seems to indicate that it is working (a & b give the same result)

Dim a, b As Double

a = g.StringHeight("abcdefghijklmnopqrstuvwxyz", 20)
b = g.TextHeight("abcdefghijklmnopqrstuvwxyz", 20)

break

That was the confusion for me as well.

StringHeight(Text, WrapWidth) and TextHeight(Text, WrapWidth) both call the framework function RuntimeGraphicsStringHeight as far as I see.

Makes sense.

I just wasn’t aware that TextHeight could be used the same way as StringHeight now.