[Lazarus] Printer printable width&height

Jesus Reyes A. jesusrmx at gmail.com
Thu Aug 9 07:55:36 CEST 2018

En Sat, 28 Jul 2018 08:05:31 -0500, Michael Van Canneyt via Lazarus  
<lazarus at lists.lazarus-ide.org> escribió:

> Hi,
> The selectprinter demo prints a kind of test page.
> However, on linux the rectangle it draws on the page seems to be off. The
> left margin seems to be about right, but the bottom and top margins fall  
> off
> the page.
> If I try to code something myself, I would code it like this:
> procedure TMainForm.GetPageRect(Out PageRect : TRect);
>    Function ToPixels(aUnit,ares : Integer) : Integer;
>    begin
>      if PSDemo.Units in [pmDefault,pmMillimeters] then
>        // 1/1000 of a mm
>        Result:=Round(((aUnit div 1000) / 25.4) * Ares)
>      else
>        Result:=aUnit * Ares
>    end;
> Var
>    LM,RM,TM,BM,H,W : Integer;
> begin
>    H:=Printer.PaperSize.Height;
>    W:=Printer.PaperSize.Width;
>    LM:=ToPixels(PSDemo.MarginLeft,Printer.XDPI);
>    RM:=ToPixels(PSDemo.MarginRight,Printer.XDPI);
>    TM:=ToPixels(PSDemo.MarginLeft,Printer.YDPI);
>    BM:=ToPixels(PSDemo.MarginBottom,Printer.YDPI);
>    PageRect:=Rect(LM,TM,W-RM,H-BM);
> end;
> PSDemo is a TPageSetupDialog. The values displayed by the lazarus test
> program match more or less what my code gets. Similarly, if I draw a  
> rectangle with the rectangle defined as above, the bottom-right falls  
> off the page.
> So the question is: what is the origin of the printer canvas ? Top-left  
> corner of the paper (What it should be IMO ?)
> Or is it the Top-left corner of the printable area of the page ?

The top-left of the paper canvas is 0,0 and coincide with the area of the  
whole paper. Any drawing outside of this area would be clipped. Some  
printers also do not allow drawing outside of the working area.

> How to obtain the origin of the printable area ?
> Is the PageWidth/Pageheight relative to this origin ?

The printable area should be Printer.PaperSize.PaperRect.WorkRect

> Or is there something else wrong in the printer class or the demo code ?
> (using GTK2, 64-bit)

Should not matter in this case but it seems TM is using the left margin  
instead of the top margin.
As the TPageSetupDialog works with the current printer just need to check  
that selected printer is not changed after TPageSetupDialog execution.

About why the selectprinter demo is wrong have to check, last time I did  
it worked fine in windows, linux at least, IIRC.

Jesus Reyes A.

More information about the Lazarus mailing list