OK, I found the problems I was having. The first was that I got no printout if FastPrint was false. The problem is in BltBitmapAsDIB():
- Code: Select all
procedure BltBitmapAsDIB(DestDc : hdc; {Handle of where to blt}
x : word; {Bit at x}
y : word; {Blt at y}
Width : word; {Width to stretch}
Height : word; {Height to stretch}
bm : TBitmap); {the TBitmap to Blt}
The X and Y parameters are defined as words and are being passed negative values. The reason is that the X and Y parameters when printing ultimately come from the GetPrinterPageBounds() routine:
- Code: Select all
function GetPrinterPageBounds: TRect;
begin
Result.Left := 0;
Result.Top := 0;
if UsePrinterOptions then
begin
Result.Right := GetDeviceCaps(Printer.Handle, PHYSICALWIDTH);
Result.Bottom := GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT);
end
else
begin
Result.Right := ConvertUnits(FPageExt.X,
GetDeviceCaps(Printer.Handle, LOGPIXELSX), FUnits, mmPixel);
Result.Bottom := ConvertUnits(FPageExt.Y,
GetDeviceCaps(Printer.Handle, LOGPIXELSY), FUnits, mmPixel);
end;
OffsetRect(Result,
-GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX),
-GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY));
end;
Result.Left and Result.Top will always be negative coming out of this routine because of the OffsetRect() call. The values get converted to large positive values because of the WORD declarations and the bitmap gets printed way off the page. Changing the declarations to INTEGER seems to work OK.
My second problem was also related to GetPrinterPageBounds() routine. It returns values based on the physical size of the page rather than the logical size of the page. In my case that's an issue, but it may be better the way it is for everyone else. My problem arises because inkjets tend to have much larger bottom margins than laser printers and my output was getting cropped. I'd like to propose this change to GetPrinterPageBounds():
- Code: Select all
Replace
Result.Right := GetDeviceCaps(Printer.Handle, PHYSICALWIDTH);
Result.Bottom := GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT);
with
Result.Right := GetDeviceCaps(Printer.Handle, HORZRES);
Result.Bottom := GetDeviceCaps(Printer.Handle, VERTRES);
This would mean that if UsePrinterOptions is true, that the page size is based on the printable area of the page rather than on the full size of the page in question. Any thoughts?
Thanks again for a great component set!