Stringheight Web <> Desktop

Hi everybody,

Dim p as Picture
p = New Picture(100,100, 32)
p.Graphics.TextFont = “Verdana”
p.Graphics.TextSize = 12

MsgBox str(p.Graphics.StringHeight(“Test 123”,100))
MsgBox str(p.Graphics.Stringwidth(“Test 123”))

StringHeight:

Web: 28
Desktop: 14 (correct)

Stringwidth:

Web: 72
Desktop: 55

Why there are different values?

Xojo 2013r4.1

Best regards

Stephan, did you figure out why? I have the same problem.

StringHeight and most graphics on a web app will most probably not even work if the app is installed on a regular CentOS or Linux flavor, because it has no UI, therefore no fonts.

If the app runs on Mac, Windows or a LInux Box with UI, then chances are stringwidth will work.

The only way to have a reliable measurement is to get it in JavaScript, since the client knows the actual font used, as well as the scaling set by the user.

See https://blog.mastykarz.nl/measuring-the-length-of-a-string-in-pixels-using-javascript/
http://stackoverflow.com/questions/3341496/javascript-how-to-get-the-height-of-text-inside-of-a-textarea

Web and Desktop apps use different libraries.
So the result will always be different.

Thank you Michel and Christian.
Learning something new every day :slight_smile: