I am trying to paint a string in a canvas character by character but it seems hard to make a final image that resembles the drawstring method.
I have read the documentation for the stringwidth (which I use to get the position of the next character) but appears it is hard to find the next position of the character and not the baseline.
Have you got any ideas how to deal with this? I am trying on Win.
I just ran a quick test using a variety of fonts and sizes and I see no difference between drawing the string as a whole vs. drawing each character individually. And the StringWidth of the entire string is the same as the sum of the StringWidth of each character.
Again, just a quick and dirty test, but it seems to indicate that this should work.
There could be a difference if Xojo takes kerning into account. For instance, when a font contains kerning, ‘AV’, ‘To’ or ‘Va’ use closer spacing between characters. Then drawing characters individually will not report the correct character spacing, whereas drawing the entire string will.
On Mac, the system takes kerning into account for all applications, so it should be apparent. For Windows, it requires additional settings, and chances are it does not show for DrawString.
In any event, drawing individual characters is not the best approach. I have always build the string to draw, word by word or character by character, until it fits the space allowed, and draw it all at once. (For word wrapping, obviously.) The three things I use StringWidth for are
Justifying (right/center/decimal aligned) a column of text
Wrapping a string in a fixed width column
Drawing styled text manually
In no case do I ever deal with individual character widths. Build the string and measure the width of the entire thing.
OK. I just tested a special font to better see kerning.
On Mac, Kerning is taken into account. So drawing character by character and using stringwidth will lead to incorrect character spacing with elaborate fonts. Drawing an entire string is preferable.
On PC, stringwidth like many applications does not use kerning, so drawing character by character and using stringwidth should provide the same result as drawing a string.
I do not know what the OP wants to achieve, but using Drawstring should be possible, even for an animation.
Forgive me, I tend to reason as regular typography. You are right, mixing colors requires character by character. At any rate it is difficult to speculate until the OP provides more information.
If kerning is used depends on who draws it. I bet there are older and newer APIs on Mac and Windows which do things differently.
Not to forget that rendering in console/web projects is completely different.
[quote=93985:@Christian Schmitz]If kerning is used depends on who draws it. I bet there are older and newer APIs on Mac and Windows which do things differently.
Not to forget that rendering in console/web projects is completely different.[/quote]
Mac has been rendering kerning for some 20 years. As for Windows, I tested under Windows 8.1, and it seems the situation has not changed since Vista : kerning is available buried somewhere in the API, but not used as default. Word has been using it since 2007 or so, but not WordPad for instance.