Anyone know how to get the size of a string in pixels? I dont need the number of characters in the sting. I need the size of the string in pixels. I know this is complicated by the fact that the font type and size and other variables could change. I need to check the size in pixels after it has been formatted. lol.
Thanks.
Please create a dummy picture, set the font you need and then query graphics.TextWidth.
See
https://documentation.xojo.com/api/graphics/graphics.html#graphics-textwidth
Awesome. Sounds very easy. Thank you.
As soon as I set some of the graphics properties, it quits functioning correctly. Here is my code.
Var d As Double
Var p As New Picture(100, 100, 32)
// Remove these 4 lines and it works.
p.Graphics.FontName = sFontName
p.Graphics.FontSize = iFontSize
p.Graphics.Bold = bFontBold
p.Graphics.Italic = bFontItalic
d = p.Graphics.TextWidth(sStringIn)
Return d
Im passing in correct values in the variable. I need to be able to tell it what size font and the name of the font and other stuff. Does this look correct? Thanks.
Note that this may work locally on your PC or Mac, because the fonts are there.
However, if and when you upload this code to a Linux host, the fonts must be added there, otherwise it won’t work.
This may help: https://www.howtogeek.com/769894/how-to-install-google-and-microsoft-fonts-on-linux/