Printing in Windows - drawstring gives incorrect character spacing

I have searched this issue and only come across one reference to it with no solution.
I’m using Xojo 2014r1.1 on Windows7. My project consists of a single window with one push button containing the following code:

Dim g As Graphics
If g<>nil then
g.TextFont=“Times New Roman”
g.Drawstring “A BUNCH OF TEXT IN HERE”, 100, 100
End If

The line of text prints, but the spacing between characters is inconsistent and looks erratic.
The version compiled for the Mac works fine.
If I print to a PDF on the PC, then print the PDF, it works fine.

In all cases below, the issue persists:
Different font: Arial or Times New Roman (basic system fonts)
Different Printer: HP LaserJet M806, HP Laserjet 3050
Different Windows PC&OS: Windows 2008 running in bootcamp on a Mac, Win7 running on SONY vaio
Use GDI+ (on & off) when compling
Different printer driver: PS vs PCL6

Any help would be appreciated.

Select a higher resolution. For example, this prints much better

  Dim g As Graphics
  dim ps as new PrinterSetup
  ps.MaxHorizontalResolution= 300
  ps.MaxVerticalResolution= 300
  If g<>nil then
    g.TextFont="Times New Roman"
    g.Drawstring "A BUNCH OF TEXT IN HERE", 416, 416
  End If

Is “Times New Roman” the real font name on your installed Windows 7 ?

…and don’t forget you can draw to a big picture, then draw that picture, scaled down, to the printer. That’s the standard way of getting nice crisp text.

I wouldn’t recommend that approach on Windows.

Why not, out of interest?

Windows doesn’t do as good a job of antialiasing as OS X. I don’t know about Linux.

Tim, thanks for the help. This seems to work but I’m still testing.
I see that the default Res is 72dpi and since I’ve changed it to 300dpi, the text is smaller in the actual print.
I specified the (graphics.TextUnit = FontUnits.Point) and the text got slightly bigger but no where the size specified in points.
I assume I have to do some sort of translation between the point size I want on the printout vs. the maxRes I specify.
Would this be base on a 72dpi Res? E.g. to get x point text at 300dpi the fontsize would have to be (x/72)*300?

Yes, you’d need to scale all your drawing - font sizes, coordinates, lengths - by ps.HorizontalResolution / 72. (And ps.VerticalResolution / 72 for Y coordinates, heights, etc.)

Thanks again,
First time programming for PC. Never had to worry about these on Mac.

I have done as instructed above. I used a printersetup, defined a maxRes, scaled my font size and drawstring co-ordinates and all of the text is now printing fine. My only issue now is that the sizes of the fonts appear differently when I run the compliled version on Windows vs. on the Mac.

When I remove (graphics.TextUnit = FontUnits.Point), both Mac & PC print the same size text.
Go figure.

Karen - multiple reports or a single one? Sounds like a single one.

When doing a cross-platform reporting before, I’ve had to “manually tweak” values to get two reports to match. Hard to say what the root cause was. (fonts is a possibility)

[code] #if TargetWin32 then
//windows printing stuff here

#else //assume TargetMacOS
//mac printing stuff here


//shared printing stuff here


You can set different scaling values for each platform for example. This is DEFINITELY a work around; It’d be better to know the root cause, but it will let you handle each platform differently inside the same method, with much of the code being shared.

Also - The size difference is only on the compiled Windows version? So it’s the same when you run the Windows version in the debugger? That’s something I haven’t seen.

You don’t have any:

[code] #if DebugBuild then


statements in your code do you?

Another GOTCHA to be aware of… Setting the MaxHorizontalResolution and MaxVerticalResolution to a given value does NOT mean that is the value that will be used… it will adjust to whatever the printer is actually capable of.

For example… my printer does NOT do 300dpi… it does 360. So if I set it to 300 I get 180 (next step down)… if I set to 400 I get 360 …
but you need to have the exact value to rescale you font size

Which is why you use ps.HorizontalResolution and let the printer tell you what it selected. (and VerticalResolution, too, of course -never assume they’re the same.)

Anthony - no I don’t have #If debugbuild then# statements in my code. I was gonna resort to using the Target___ condition if I couldn’t get this to work.

Dave/Tim - Oddly, I chose 300 for testing and work great for the program’s needs. I then tried printing to the printer at various different resolutions, and it all seemed the same. Am I to understand that once I choose 300 maxHRes & maxVRes, that it doesn’t matter what output options I choose in the printer dialog, everything will print at 300?

No, but if you scale everything by HorizontalResolution/72, it will look the same regardless of the resolution.

Is that all you do? What about lines and images?

I saw some code on the forums to get resolution and use it to scale fonts and stuff but I can’t find it anywhere.

I thought I had spacing resolved a while back (1 year or more ago) and I realized lately that the problem is back (or never went away). I tried the above code exactly as it is on a Windows 8.1 machine with the font at 9 and I get odd spacing. I also tried 1200 as well as -1 for resolution numbers (-1 supposed to make it printer max?).

Any suggestions?

here is my code:

Dim g As Graphics
dim ps as new PrinterSetup
ps.MaxHorizontalResolution= 300
ps.MaxVerticalResolution= 300
If g<>nil then
g.TextFont=“Times New Roman”
g.Drawstring “Tim Meadows - Ministry Account”, 200, 200
End If

Please define “odd spacing”. Have you compared with a print from WordPad, for instance ?