Reported by Brad Stowers; checked by Borland (D4.02 readme)
The D3 documention lists a property named PageRect for the TRichEdit
control which claims to be the printable area in twips (1/20th of a point,
or 1/1440 of an inch). The source code, on the other hand, uses a formula
that converts from pixels, not twips: (from SOURCE\VCL\COMCTRLS.PAS,
TRichEdit.Print method)
else begin
rc.left := PageRect.Left * 1440 div LogX;
rc.top := PageRect.Top * 1440 div LogY;
rc.right := PageRect.Right * 1440 div LogX;
rc.bottom := PageRect.Bottom * 1440 div LogY;
end;
What this does is convert from pixels *TO* twips.
The bug is in Delphi 3.0 (3.01 could not be checked yet) and Delphi 2.01,
although in 2.01, PageRect was undocumented, so it's not really a bug there.
To reproduce the bug:
Try to manually set PageRect to a know value of twips, say for 2" margins:
MyRichEdit.PageRect := Rect(2*1440, 2*1440, round(6.5*1440), 9*1440);
MyRichEdit.Print('test');
It won't work. But if you use pixels, it will:
var
LogX, LogY: integer;
begin
LogX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
LogY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
MyRichEdit.PageRect := Rect(2*LogX, 2*LogY, round(6.5*LogX), 9*LogY);
MyRichEdit.Print('test');
end;
Also, it might be good to note that you have to manually adjust for the
non-printable area, too. If you use the above, and your printer has a
non-printable area of 1/2" on the left, you will really get a left margin
of 2 1/2" inches. I left that out in the example to make the code a little
more clear. |