Discussion:
[Lazarus] Printer printable width&height
Michael Van Canneyt via Lazarus
2018-07-28 13:05:31 UTC
Permalink
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 ?

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


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

Michael.



--
Graeme Geldenhuys via Lazarus
2018-07-28 17:52:21 UTC
Permalink
Post by Michael Van Canneyt via Lazarus
How to obtain the origin of the printable area ?
Is the PageWidth/Pageheight relative to this origin ?
As far as I know (or how I always understood print drivers), the
PageWidth and PageHeight is the full page size (eg: A4 = 210x297mm).

The printable area is printer dependent. eg: my laser printer can't
print in a 5mm border around the page. Yet my inkjet printer can print
full page size. Same software was used to test this.

Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key: http://tinyurl.com/graeme-pgp
--
Michael Van Canneyt via Lazarus
2018-07-29 08:50:35 UTC
Permalink
Post by Graeme Geldenhuys via Lazarus
Post by Michael Van Canneyt via Lazarus
How to obtain the origin of the printable area ?
Is the PageWidth/Pageheight relative to this origin ?
As far as I know (or how I always understood print drivers), the
PageWidth and PageHeight is the full page size (eg: A4 = 210x297mm).
No, as far as I can see, this is paperwidth and papersize.
Post by Graeme Geldenhuys via Lazarus
The printable area is printer dependent. eg: my laser printer can't
print in a 5mm border around the page. Yet my inkjet printer can print
full page size. Same software was used to test this.
I know this, and it looks like this is why PageWidth and PageHeight were
introduced.

But without knowing what the origin of this pagewidth&pagesize is, these are
useless properties.

I must now resort to trial and error to draw a rectangle with sides at equal
distances from the paper borders. e.g. 1 cm from the paper edges. The
'logical' choices (as also used in the selectprinter demo) do not seem to work.

Michael.
--
Jesus Reyes A. via Lazarus
2018-08-09 05:55:36 UTC
Permalink
En Sat, 28 Jul 2018 08:05:31 -0500, Michael Van Canneyt via Lazarus
Post by Michael Van Canneyt via Lazarus
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.
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.
Post by Michael Van Canneyt via Lazarus
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
Post by Michael Van Canneyt via Lazarus
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.
--
Michael Van Canneyt via Lazarus
2018-08-09 07:32:52 UTC
Permalink
Post by Jesus Reyes A. via Lazarus
En Sat, 28 Jul 2018 08:05:31 -0500, Michael Van Canneyt via Lazarus
Post by Michael Van Canneyt via Lazarus
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.
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.
This does not correspond to my findings.

I did many tests (using a lot of paper in the process) and found
that (0,0) is the origin of the printable area, NOT the paper area.
Post by Jesus Reyes A. via Lazarus
Post by Michael Van Canneyt via Lazarus
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
Yes.

I printed a rectangle with 2 cm sides, at (0,0), and it is printed exactly
where workrect top,left says it should be, so my conclusion is that (0,0)
is the origin of the printable area.

(which, in my opinion, also makes more sense)
Post by Jesus Reyes A. via Lazarus
Post by Michael Van Canneyt via Lazarus
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.
I know, I already corrected that before carrying out tests.
Post by Jesus Reyes A. via Lazarus
As the TPageSetupDialog works with the current printer just need to check
that selected printer is not changed after TPageSetupDialog execution.
Little chance of that.
There is only 1 printer, and 1 paper type on my system.
Post by Jesus Reyes A. via Lazarus
About why the selectprinter demo is wrong have to check, last time I did
it worked fine in windows, linux at least, IIRC.
Well, definitely not today on a HP laserjet P2015n, linux mint, 64bit, GTK2.
I can send a picture of the produced output if you want :-)

Michael.
Jesus Reyes A. via Lazarus
2018-08-10 09:31:04 UTC
Permalink
Post by Michael Van Canneyt via Lazarus
Post by Jesus Reyes A. via Lazarus
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.
This does not correspond to my findings.
I did many tests (using a lot of paper in the process) and found
that (0,0) is the origin of the printable area, NOT the paper area.
Yes sorry I got confused. The origin should be the printable area.
Post by Michael Van Canneyt via Lazarus
Post by Jesus Reyes A. via Lazarus
About why the selectprinter demo is wrong have to check, last time I did
it worked fine in windows, linux at least, IIRC.
Well, definitely not today on a HP laserjet P2015n, linux mint, 64bit, GTK2.
I can send a picture of the produced output if you want :-)
Tested again, it seems to work in my old hp laserjet 1200, the linux mint
I have in a virtualbox was not able to connect through usb apparently due
a driver problem in my pc, so I compiled the program saved it in a usb
stick and boot a xubuntu live session which detected the hp 1200 printer
without problems, ran the selectprinter app and after changed the paper
size which defaulted to A4 (mine is Letter) it printed correctly the demo.
I would took a picture of it but the toner is so old that its barely
noticeable but I checked with a ruler and the measures were +- 0.5-1.0 mm,
acceptable to me.

My guess is that your problem might be a bad PPD file for your printer,
check the *ImageableArea values for your selected paper, the
*PaperDimension first value minus the *ImageableArea third value should be
the same as the the *ImageableArea first value (for symmetrical printable
margins). You can also try another printer driver if available.

Jesus Reyes A.
--

Continue reading on narkive:
Loading...