This has been reported numerous times BUT here goes again. I'm having trouble finding the length of a string to display with roImageCanvas. If the string is too long for a field, I either want to reduce the size of the font or chop some words off. But the call to GetOneLineWidth() returns something smaller than the actual size. So when I think I have a good size and the line is rendered, the routine in roImageCanvas likes to arbitrarily chop off the last word and wrap it to a new line.
So I wrote a small test to show this.The background of each character line is adjustable, so you can find the actual pixel size of a character.
This is the background width divided by the number of characters (20).
The first line displayed shows the character value and the size of the character for each of the font sizes I use.
The next six lines are the test strings with the adjustable background. The end of the line is the mnemonic and actual font index.
The "String Size" line is output from a routine I wrote to give a FASTER line width.
I found that the system's routine was upwards of 200ms to get the width. Mine around 50ms, always.
The "Actual Size" line is output from the GetOneLineWidth() routine.
Now notice that the GetOneLineWidth() routine reports "Large Font" at a size of 20, when in actuality it is 22. So for 20 "A"s, that would be 40 pixels off.
No wonder it wraps. I guess the code in roImageCanvas doesn't use the GetOneLineWidth() routine !
Test using default font - Mini(10) Small(13) Medium(17) Large(22) Big(30) Huge(36)I don't know why an external font is a lot closer, 1 pixel ??? BUT that could still be 20 pixels off.
Test using external font