Printing in Windows - drawstring gives incorrect character spacing

I ran your code and while 9 point text at 300 dpi is really tiny/almost unreadable, the spacing looked ok to me.

Betting its the microscopic size thats “odd”
9 point is “9 point at 72 DPI” and so it needs to be scaled based on whatever the printers resolution is
Didn’t we just go around this circle on another thread ?

OK, my co-worker was gone for 3 weeks and has just returned, so I have time again for this. My print is not horribly tiny or virtually unreadable, which is because it is scaled using 72 point NOT the printer default, which is also why I have odd spacing (one character in a word being virtually by itself while other characters are scrunched together). For all the info in the various threads, I do not see a good example of what to do to fix this.

I also have tried using “-1” as well as “1200” instead of “300” and no matter what I put in it uses 72 instead.
ps.MaxHorizontalResolution= -1
ps.MaxVerticalResolution= -1

Does anyone have sample code that I should be able to plug into my program and see it work?

Thanks,

dim scalefactor as double
scaleFactor = graphics.HorizontalResolution / 72

// now draw EVERYTHING at whatever size * scaleFactor

g.textSize = g.textSize * scaleFactor
// now draw strings etc and they’ll be scaled right

etc

Did you set the MaxRes before you opened the printer? Setting them after has no effect.

And as been mentioned before… you cannot just pick arbitrary printer resolutions, it must be a resolution supported by that particular make and model. Some printer drivers switch back to 72dpi if you ask for an unsupported resolution, others will “round” up or down to a resolution that IS supported. You need to experiment with your hardware to see what results the software drivers return.

This looks very much like what happens with justified, but that mode is not available in DrawString…

It would greatly help if you posted a sample project, and most importantly, a picture of what you describe. Then it would become a lot easier to experiment and suggest remedies.

Well, I have tried various combinations and what I keep coming up with is this: no matter what I make my “MaxHorizontalResolution” (or the vertical) the actual HorizontalResolution (and vertical) continues to be 72. I have tried 300, 600, 1200, and -1. I am on Windows 8.1 with Xojo 2015r1 and an HP LaserJet m401.

Here is a scan of the print job… with the following “project” (this is all the code one one button).

=====================
Dim g As Graphics
dim ps as new PrinterSetup
dim scalefactor as double

ps.MaxHorizontalResolution= 1200
ps.MaxVerticalResolution= 1200

g=OpenPrinterDialog(ps)

scaleFactor = ps.HorizontalResolution / 72

If g<>nil then
g.TextFont=“Times New Roman”
g.textSize = 9 * scaleFactor
g.Drawstring “Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz”, 200, 200

End If

  1. what do I need to do to get the “HorizontalResolution” to change??

Here is a link to the sample. In the word “Ministry” - Notice the “st” are hugging each other while the “i” right before it is lonely. Also the "u’ is lonely while “st” on one side and “vw” on the other side are much closer.

Sample Print

What is the font you have used ?

As the above code says:
g.TextFont=“Times New Roman”

Although it does it as well with Arial and others.

[quote=226418:@Tim Meadows]As the above code says:
g.TextFont=“Times New Roman”

Although it does it as well with Arial and others.[/quote]

I believe what you get is due to the small point size and the low resolution. Each character is represented by less than 6 pixels. There is not enough resolution for small distances between characters to show correctly, because of quantum effects. When the only choice for the imager is between a full pixel which creates too much space, and no pixel, which collides, you obtain your lonely u and colliding st.

The issue should subside with a higher printing resolution.

Which brings me back to my question above:

No matter what I make my “MaxHorizontalResolution” (or the vertical) the actual HorizontalResolution (and vertical) continues to be 72. I have tried 300, 600, 1200, and -1. I am on Windows 8.1 with Xojo 2015r1 and an HP LaserJet m401.

This line does not change a thing!
ps.MaxHorizontalResolution= -1
ps.MaxVerticalResolution= -1

What do I need to do to get the “HorizontalResolution” (and/or vertical) to change??

Here is a link to the actual project with Times and Arial printing. No matter what I try I get a res of 72 ?!?!?!?

Sample Project

After some minor mods to your code it runs and looks great on my Mac going to a Canon ink jet printer. You can see it here:

I used the -1 on the resolutions and put a break point in so I could look ps and see that it set the resolutions to 600.

Now, you have to realize that once you are changing the resolution from 72 everything has to be multiplied by the scaling factor. Not only sizes like your test size, but also positioning values. So, to accomplish that I changed your code to look like this:

[code]Dim g As Graphics
dim ps as new PrinterSetup
dim scalefactor as double
dim leftLoc As Integer
ps.MaxHorizontalResolution = -1
ps.MaxVerticalResolution = -1

g=OpenPrinterDialog(ps)

scaleFactor = ps.HorizontalResolution / 72
leftLoc = 200 * scalefactor

If g<>nil then
g.TextFont=“Times New Roman”
g.textSize = 8 * scaleFactor
g.Drawstring “Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz”, leftLoc, 100 * scalefactor

g.textSize = 9 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 120 * scalefactor

g.textSize = 10 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 140 * scalefactor

g.textSize = 11 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 160 * scalefactor

g.textSize = 12 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 180 * scalefactor

g.textSize = 13 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 200 * scalefactor


g.TextFont="Arial"
g.textSize = 8 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 300 * scalefactor

g.textSize = 9 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 320 * scalefactor

g.textSize = 10 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 340 * scalefactor

g.textSize = 11 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 360 * scalefactor

g.textSize = 12 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 380 * scalefactor

g.textSize = 13 * scaleFactor
g.Drawstring "Tim Meadows - Ministry Account - abcdefghijklmnopqrstuvwxyz", leftLoc, 400 * scalefactor

End If[/code]

I, personally, never use anything but the -1 when setting things up. That way I don’t have to worry about what resolutions the printer does or does not work with.

PS, when looking at the printer setup it had the PageWidth as 4800 and the page height as 6600.

Thanks Harrie. Here is my output with your changes cut and pasted into my project here.

See the spacing in “Meadows” on the larger two font sizes?

Is it a Windows problem? Certain version of Windows?

I keep getting 72 res NOT 600 (which is default) or 1200 (which I changed default to) for my printer.

Tim

Can you run it on another printer to eliminate that as a possible problem

Just did! I finally thought to go to another printer and … No problem! It looks great. I’ll try a different print driver, update it or something. Look great on the copier and switched it to 600!

Thanks for the help!

That is indeed absolutely horrible.

Glad you found the problem. It is not too common; but, it is not the first time that I have seen a printer go awry. Not too sure that a change in drivers will fix the problem. Seems more like a mechanical defect; however, I will not bet a paycheck on that idea.