Bug in graphics.PenWidth when using ScaleY?

Lon story short, I’m writing some WYSIWYG editor. Users will create, save, load and print. The software uses mm as units so users enter the object size in mm this sizes are stores as is.

The when doing printing i use the maximum resolution of the printer, get a ScaleFactor and asign to the scale property.

Dim pageSetup As PrinterSetup
pageSetup = New PrinterSetup
pageSetup.MaxHorizontalResolution = -1
pageSetup.MaxVerticalResolution = -1
g = OpenPrinter(pageSetup)
If g <> Nil Then
	'Letter size
	Dim PageWidth As Integer = 216 
	Dim PageHeighth As Integer = 279
	xScaleFactor =  pageSetup.PageWidth / PageWidth 'mm
	yScaleFactor =  pageSetup.PageHeight / PageHeighth 'mm
	g.ScaleX = xScaleFactor
	g.ScaleY = yScaleFactor
	g.PenHeight = 0.5
	g.PenWidth = 0.5

	g.DrawString("This text is 10mm from the left and 10mm from the top", 10, 10)
	g.DrawLine(29, 30, PageWidth - 29, 30)

This works great, units are saved as mm and everyting is drawn in the correct place.


In this case the line is not drawn because PenHeight and PenWidth is of type Integer, so is rounded to 0, but 1mm is too wide for a line.

So, How to draw a line 0.5 mm wide while using ScaleX and ScaleY in graphics?


Edit: Fix Code tags

With a 300 dpi printer, 1 pixel (dot) is only 0.08466666 millimeter. So it should not be terribly difficult to get to 0.5.

Thats right, in a 300dpi printer I can use a 6px line to get the 0.5mm, but, that is working all with pixels and aply the scaling factor to every single object to be printed.

But the point is, what is for the g.ScaleX for if it can’t be used with fractional values.

Okay, so I’m hoping that this will be addressed with the new framework, in the meantime you may have to wait.

If you’re targeting the macOS, it will take some time, but you can replace the Xojo code with declares or plugins which work directly with Core Graphics, as Core Graphics allows for fractional widths.

Otherwise you’re going to have to use some clever maths, you need to increase the resolution of the graphics class. So that it gives you smaller pixels, and then at that point you can simulate a line width of 0.5.