Issue with transparent text in Canvas

I have a strange issue with drawing transparent text via DrawString() in a Canvas. On OS X all is fine but on Windows (10, 8, 7) the text’s running width is different. Please see screenshots below.
It makes no different if the Canvas is double-buffered or I use an direct transparent color (&c000000a0) or Graphics.Transparency.
Is this a Windows bug or is it Xojo?

Has nothing to do with transparent or opaque in this instance. The font metrics between OSX and Windows are NOT the same. the stringwidth of any given string maybe different depending on the characters and font involved.

It was this exact issue that caused me to suspend developement of my cross-platform PDF class until I could figure out a work-around

[quote=263536:@Carsten Belling]I have a strange issue with drawing transparent text via DrawString() in a Canvas. On OS X all is fine but on Windows (10, 8, 7) the text’s running width is different. Please see screenshots below.
It makes no different if the Canvas is double-buffered or I use an direct transparent color (&c000000a0) or Graphics.Transparency.
Is this a Windows bug or is it Xojo?
[/quote]

Code for how you figure out the positioning ?
Thats more likely where the issue is

Dave, this has definitely to do with transparency. I’m talking not about different font metrics between OS X and Windows.
Here is the link to download the sample file:

Do you have gdiplus enabled?

Yes, you can’t use transparency w/o GDI+.

I’d file a bug report with that sample attached
Not sure why it should used a condensed style when transparent & it may be a bug

GDI is used for opaque text drawing irrespective of the UseGDIPlus flag. From my understanding, GDI+ text drawing is significantly slower and this tradeoff was required to keep the IDE usable.

@Norman Palardy: Thanks!
I tested a little bit more and I think it’s “expected behavior”; it’s the same effect as if you use DrawString() in a picture with an alpha channel. GDI+ don’t use subpixel rendering here and the result (in pixels) is exactly the same as drawing transparent text in a Canvas. We can see this also in the Windows UI where text is drawn on a translucent background – no subpixel rendering, only simple anti-aliasing.

… which leads me to another problem: As you can see in the screenshots above, the running width of the transparent text takes a few pixels more than the opaque text. In HiDPI mode, the transparent text is narrower than the opaque text. If you use Graphics.StringWidth() in HiDPI mode, the result is a few pixels to small. Probably the reason for this is that StringWidth() calculates the width with a different renderning mechanism (always simple anti-aliasing, no matter how the text will be actually drawn).

Bonkers workaround:

If Xojo ignores GDI+ settings for opaque text
And GDI /GDI+ render differently
If you need to know that transparent and non-transparent text will line up, then

Make even your opaque text transtparent, with the least amount of transparency you can dial in.

eg g.Transparency = if ( CheckBox1.Value, 50.0, 0.001 )

I’ve learned a lot about GDI(+) last night :wink: and I think Xojo should give more love to Windows (as it has done for Cocoa)!
GDI+ knows different text rendering modes and with direct GDI+ calls it is no problem to draw transparent text in high quality, even with subpixel rendering.

The goal for a future release is to move to Direct2D and DirectWrite.