fixes paper orientation and size, issue #7077

git-svn-id: trunk@9487 -
This commit is contained in:
jesus 2006-06-23 06:41:28 +00:00
parent ce953254e7
commit 816204bcbc
3 changed files with 73 additions and 45 deletions

View File

@ -628,6 +628,7 @@ begin
{$IFDEF UseCache}
if aValue=DoGetOrientation then exit;
Exclude(FStates,cpsOrientationValid);
Exclude(FStates,cpsPaperRectValid);
{$ENDIF}
inherited DoSetOrientation(aValue);
@ -701,14 +702,77 @@ begin
begin
fCachePaperRectResult:=1; //CUPS return margins
fCachePaperRect.PhysicalRect.Right:=Trunc(P^.Width);
fCachePaperRect.PhysicalRect.Bottom:=Trunc(P^.Length);
// Margins.
//
// Cups gives dimensions based on postcript language
// user space coordinates system which is something like
//
// +y +--> +x
// ^ but our system is |
// | v
// +--> +x +y
//
// so values in x are the same, but we need to invert values in y,
// the given bottom value is the margin size at the bottom, we need
// to re-calc. our bottom offset, and the given top value is offset
// top value of imageable area, we need to re-calc. our top offset,
// which is the margin size at the top of the page.
//
// The current implementation assumes that paper is fed short-edge-first
// either in portrait orientation, or in landscape orientation.
//
// In landscape orientation, printable margins should preserved.
// It's based on a 90 degree counterclock wise paper rotation
//
// FEED DIRECTION FEED DIRECTION
//
// /\ /\
// / \ / \
// || ||
// || ||
//
// PORTRAIT ORIENTATION LANDSCAPE ORIENTATION
//
// +-----------------+ +-----------------+
// | t | | t |
// | +---------+ | | +---------+ |
// | | | | | | | |
// | | ( ) | | | | v | |
// | | | | | | |\ | | |
// | l | >--+--< | r | | l | ---+-() | r |
// | | | | | | |/ | | |
// | | / \ | | | | ^ | |
// | | / \ | | | | | |
// | +---------+ | | +---------+ |
// | | | |
// | b | | b |
// +-----------------+ +-----------------+
//
// todo: check meaning of poReverseXXXXX
//
if Orientation in [poPortrait, poReversePortrait] then begin
fCachePaperRect.PhysicalRect.Right:=Trunc(P^.Width);
fCachePaperRect.PhysicalRect.Bottom:=Trunc(P^.Length);
fCachePaperRect.WorkRect.Left:=Trunc(P^.Left);
fCachePaperRect.WorkRect.Right:=Trunc(P^.Right);
fCachePaperRect.WorkRect.Top:=Trunc(P^.Length-P^.Top);
fCachePaperRect.WorkRect.Bottom:=Trunc(P^.Length-P^.Bottom);
end else begin
FCachePaperRect.PhysicalRect.Right:=Trunc(P^.Length);
FCachePaperRect.PhysicalRect.Bottom:=Trunc(P^.Width);
FCachePaperRect.WorkRect.Left:=Trunc(P^.Length-P^.Top);
FCachePaperRect.WorkRect.Right:=Trunc(P^.Length-P^.Bottom);
FCachePaperRect.WorkRect.Top:=Trunc(P^.Width-P^.Right);
FCachePaperRect.WorkRect.Bottom:=Trunc(p^.width - P^.left);
end;
//Margings
fCachePaperRect.WorkRect.Left:=Trunc(P^.Left);
fCachePaperRect.WorkRect.Right:=Trunc(P^.Right);
fCachePaperRect.WorkRect.Top:=Trunc(P^.Length-P^.Top);
fCachePaperRect.WorkRect.Bottom:=Trunc(P^.Length-P^.Bottom);
//debugln('TCUPSPrinter.DoGetPaperRect PhysicalRect=',dbgs(fCachePaperRect.PhysicalRect),' WorkRect=',dbgs(fCachePaperRect.WorkRect));
end;
end;

View File

@ -456,7 +456,7 @@ begin
Left :=Windows.GetDeviceCaps(fDC, PHYSICALOFFSETX);
Top :=Windows.GetDeviceCaps(fDC, PHYSICALOFFSETY);
Right :=Left + Windows.GetDeviceCaps(fDC, HORZRES);
Bottom:=Bottom + Windows.GetDeviceCaps(fDC, VERTRES);
Bottom:=Top + Windows.GetDeviceCaps(fDC, VERTRES);
end;
end else begin
// for other papers return at least the physical size

View File

@ -761,43 +761,7 @@ begin
Margins:=fOwnedPrinter.DoGetPaperRect(aName,TmpPaperRect);
if Margins>=0 then
begin
if fOwnedPrinter.Orientation in [poPortrait,poReversePortrait] then
begin
Result.PhysicalRect:=TmpPaperRect.PhysicalRect;
if Margins=1 then
Result.WorkRect:=TmpPaperRect.WorkRect
else
begin
Result.WorkRect.Left:=Result.PhysicalRect.Left+TmpPaperRect.WorkRect.Left;
Result.WorkRect.Right:=Result.PhysicalRect.Right-TmpPaperRect.WorkRect.Right;
Result.WorkRect.Top:=Result.PhysicalRect.Top+TmpPaperRect.WorkRect.Top;
Result.WorkRect.Bottom:=Result.PhysicalRect.Bottom-TmpPaperRect.WorkRect.Bottom;
end;
end
else
begin
//If the selected orientation is not normal, reverse
//length with width
Result.PhysicalRect.Right:=TmpPaperRect.PhysicalRect.Bottom;
Result.PhysicalRect.Bottom:=TmpPaperRect.PhysicalRect.Right;
if Margins=1 then
begin
Result.WorkRect.Right:=TmpPaperRect.WorkRect.Bottom;
Result.WorkRect.Left:=TmpPaperRect.WorkRect.Left;
Result.WorkRect.Bottom:=TmpPaperRect.WorkRect.Right;
Result.WorkRect.Top:=TmpPaperRect.WorkRect.Top;
end
else
begin
// workrect is margins
Result.WorkRect.Left:=Result.PhysicalRect.Left+TmpPaperRect.WorkRect.left;
Result.WorkRect.Right:=Result.PhysicalRect.Right-TmpPaperRect.WorkRect.Bottom;
Result.WorkRect.Top:=Result.PhysicalRect.Top+TmpPaperRect.WorkRect.top;
Result.WorkRect.Bottom:=Result.PhysicalRect.Bottom-TmpPaperRect.WorkRect.right;
end;
end;
Result := TmpPaperRect;
end
else raise EPrinter.Create(Format('The paper "%s" as not definied rect ! ',[aName]));
end