Q:

Scaling pixelvalues for printing

I'm trying to find some sense in some old code related to printing. 
When drawing a form to the printer, every size and position property get multiplied by a scale factor. The factor is calculated by the following code:
    { Printer device-specific information }
    FXScale := (GetDeviceCaps(Printer.Handle, LOGPIXELSX)/96) -
               ((2-(GetDeviceCaps(Printer.Handle, HORZRES)*2) /
               GetDeviceCaps(Printer.Handle, PHYSICALWIDTH)));
    FYScale := (GetDeviceCaps(Printer.Handle, LOGPIXELSY)/96) -
               ((2-(GetDeviceCaps(Printer.Handle, VERTRES)*2) /
               GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT)));

Can anyone explain what is happending here? I guess there is some mapping between screen resolution and printer resolution, but what about the rest? Why the 2's?

A:

OK, not sure I've got the complete answer, but maybe this will help spur someone else in the right direction:
FXScale = (LogPixelsX / 96) - (2 - ((2 * HorzRes) / PhysicalWidth))
        = (LogPixelsX / 96) - (2 - (2 * (HorzRes / PhysicalWidth)))
        = (LogPixelsX / 96) - (2 * (1 - (HorzRes / PhysicalWidth)))

Since PhysicalWidth is guaranteed to be greater than or equal to HorzRes (see MS documentation), 1 - (HorzRes / PhysicalWidth) = ((PhysicalWidth - HorzRes) / PhysicalWidth).  Then we have:
FXScale = (LogPixlesX / 96) - (2 * ((PhysicalWidth - HorzRes) / PhysicalWidth)

(LogPixelsX / 96) = Ratio of Printer DPI to Screen DPI
((PhysicalWidth - HorzRes) / PhysicalWidth) = Ratio of Non-Printable Width to Total Width of Paper

So, it  looks like calculate the ratio of printer DPI to screen DPI, then subtract double the ratio of non-printable width to total width of paper.  Maybe the 2 is to get a little bit away from the edge of the physical limits of the printer?

