Graphics pen width and height

I’m assessing Xojo for a project using an iMac Retina to upgrade a simple standalone app currently on a PC. I am an experienced programmer in C and C# and find Xojo intuitive and very easy to learn. The speed of learning Xojo makes it ideal for one-off apps. In order to go with Xojo I needed to assess two things: working with SQLite and printingprecise vector graphics.

Migrating data to SQLite and attaching to a Xojo app was really straightforward but the graphics is not quite as required. I need to be able to print (on a high resolution inkjet printer) circles and lines at defined coordinates in black with a precise line thickness. While creating the circles and lines was straightforward, I found I couldn’t control graphics pen.width and pen.height as I wanted. If I set both to 0, I got a very thin line while, with both set to 1, I got a line about 4 or 5 times thicker - and I need a thickness somewhere in between. Can anyone give me advice on how to get more precise control of line thickness?


You are at the mercy of the printer’s dpi setting.
If it is 72dpi, then graphics are coarse.

You get much more precise control if you render into PDFs because the sizes are expressed in doubles and relate to the page size… its the job of the rendering engine to get it as good as it can.

When you get the graphics from the printer, request the best resolution you can at the time.
Check the resolution of the graphics object you get back.

If you want a line that is 1/36 of an inch thick, then you need to consider how many pixels make up 1/32 inch

at 72 dpi, a 1/36inch line needs a pen width of 2

at 144 dpi, you need a penwidth of 4
and so on.

A penwidth of 1 will give you the thinnest line possible at any resolution, but at 1200 dpi it will be allmost invisible on all but the best quality coated paper.

This is not entirely true. While a printer’s default resolution is usually 72dpi, you can request that it be set higher (assuming the printer can handle that resolution).

Check out for a good explanation of how this works. You’ll want to set the “max” resolutions (horizontal and vertical) and then actually check the horizontal and vertical resolutions to make sure the printer driver can do it.

I usually work between the two and find a resolution that the printer can do in both directions so the math can be done once, and most printers today can do at least 300 or 600dpi anyway. As Jeff mentioned, once you have that, figuring out the pen width and height that you need is relatively easy.

I’m using a Canon M860 that I had preselected to be at photographic resolution, which is what is giving me the results I described. It must be at the default you described because a pen height = 1 and pen width = 1 gives me roughly 0.4mm wide lines, which is about 72 dpi. Obviously the printer was ignoring my preselected photographic resolution!

Many thanks to you both for the advice. I’ll read up on printer resolution.

One thing that people “assume” about modern printers is that you can set the resolution to what you “desire”… This is NOT true, you must set it to a resolution that it supports, or in most cases it will default to 72dpi. So you need to be cognizant of the printer involved with your app, or the results will not be what you thought they should be.

If you always want the BEST the printer can do, set the H and V resolutions to -1

I tried using -1 for H & V resolutions but that just doubled the scale of the graphics and line thickness. I checked the horizontal and vertical resolutions and they were both 72 as well as the max values. As these are read-only, it isn’t clear to me why a 9600dpi printer would return 72 dpi.

This is my test code:

Dim settings as String
Dim p as PrinterSetup
p=New PrinterSetup
If p.PageSetupDialog Then
End If

p.MaxHorizontalResolution= -1
p.MaxVerticalResolution= -1

Dim g As Graphics
g = OpenPrinterDialog(Nil, Window1)

g.PenWidth = 1
g.PenHeight =1

After OpenPrinterDialog, check the values of p.HorizontalResolution and p.VerticalResolution. That will tell you what the printer actually selected. Are they what you expect?

You need to set the -1 before you open the printer.

Try this

[code] Dim g As Graphics
Dim p as New PrinterSetup

p.MaxHorizontalResolution= -1
p.MaxVerticalResolution= -1

g = OpenPrinterDialog(p, Window1)

Yes, I had checked the values of p.HorizontalResolution and p.VerticalResolution and they were 72. But Jeff, you’ve solved the problem. It now works fine. Thanks for your help.