Direct2D: TextFont and TextSize are different in Controls and Graphics

We use Graphics.StringWidth in many places to determine the required Width of Controls (and re-arrange the Layout according to that).
This works fine on macOS and Windows (up until Xojo 2016r3).

With Xojo 2016r4 and newer (probably because of the new Graphics Framework Direct2D/DirectWrite), this causes the following issues:

  1. The Font used in Controls is NOT the same as in Graphics (Canvas)

Which leads to the issue that:
2) Graphics.StringWidth can’t be used for determining the mininum required width of the Control

With Font “System 11”:
ScaleFactor 2.5: Graphics.StringWidth is too big (compared to assigning that Font/Size to a Control)
ScaleFactor 1.0: Graphics.StringWidth is much too small (compared to assigning that Font/Size to a Control)

While I’ve reported what I see here: <>
I’m curious to know if there are any workarounds?
Or does anyone know what’s going on? What are the differences of Fonts in Controls and Graphics? Is there some way to calculate the differences between them?

Or do i need to respect some other settings of the Control (e.g. CharacterSpacing) when trying to get the exact same Font in a Graphics?

It true, the move to D2D from 2016R3 to 2016R4 had impact and needed some rework on existing gui’s at my side.
The problem I had with it those days that this move forced me to stay with 2016R3 for while even more than one new release came out.

I also have every kind of issue with the Direct2D. I consider a shame to be forced to use Xojo 2016 in 2018 because of these issues :frowning:

Same here - but for the better :slight_smile: Graphics in HiDPI are much better with Direct2D (and Xojo-Graphics is more consistent to macOS Retina - 2016r3 was quite a mess with “1px off” here or there).

I just haven’t figured out how to get the same Font (Size and “appearance”, e.g. LetterSpacing or whatever) in a Xojo Graphics, so that I can draw a String (and do some maths/measure) exactly the same as the Controls do…

I was going to compare drawing methods between controls and a canvas and perform some other tests on this topic but I got stuck…


Looks like its been wrong all the way back before 2016r3, that’s the oldest version I have installed.


Considering all controls use Point for their text size I’d wait for a fixed alpha before trying to chase this.