mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-16 12:39:16 +02:00
LazReport, fix identifying papers by size
git-svn-id: trunk@46243 -
This commit is contained in:
parent
5030be7b0a
commit
0a7975bb19
@ -645,14 +645,25 @@ var
|
|||||||
i, aWidth, aHeight, BDeltaW, BDeltaH, BIndex,Cw,Ch: Integer;
|
i, aWidth, aHeight, BDeltaW, BDeltaH, BIndex,Cw,Ch: Integer;
|
||||||
PaperRect: TPaperRect;
|
PaperRect: TPaperRect;
|
||||||
ValidSize: Boolean;
|
ValidSize: Boolean;
|
||||||
|
CurDx, CurDy: Integer;
|
||||||
|
{$ifdef DbgPrinter_detail}
|
||||||
|
BestDw, BestDh: Integer;
|
||||||
|
|
||||||
|
function dbgsp: string;
|
||||||
|
begin
|
||||||
|
if i>=0 then
|
||||||
|
result := format(' askW=%d askH=%d rspW=%d rspH=%d',
|
||||||
|
[aWidth, aHeight, PPDPaperInfo[i].X, PPDPaperInfo[i].Y]);
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
begin
|
begin
|
||||||
result := -1;
|
result := -1;
|
||||||
|
|
||||||
ValidSize := true;
|
ValidSize := true;
|
||||||
try
|
try
|
||||||
PaperRect := prn.Printer.PaperSize.PaperRectOf[aPaperName];
|
PaperRect := prn.Printer.PaperSize.PaperRectOf[aPaperName];
|
||||||
aWidth := PaperRect.PhysicalRect.Right-PaperRect.PhysicalRect.Left;
|
aWidth := round((PaperRect.PhysicalRect.Right-PaperRect.PhysicalRect.Left) * 72 / prn.Printer.XDPI);
|
||||||
aHeight := PaperRect.PhysicalRect.Bottom-PaperRect.PhysicalRect.Top;
|
aHeight := round((PaperRect.PhysicalRect.Bottom-PaperRect.PhysicalRect.Top) * 72 / prn.Printer.YDPI);
|
||||||
except
|
except
|
||||||
ValidSize := false;
|
ValidSize := false;
|
||||||
end;
|
end;
|
||||||
@ -660,17 +671,28 @@ begin
|
|||||||
BIndex := -1;
|
BIndex := -1;
|
||||||
BDeltaW := 2013;
|
BDeltaW := 2013;
|
||||||
BDeltaH := 2013;
|
BDeltaH := 2013;
|
||||||
|
{$ifdef DbgPrinter_detail}
|
||||||
|
BestDw := BDeltaW;
|
||||||
|
BestDh := BDeltaH;
|
||||||
|
{$endif}
|
||||||
|
|
||||||
// name and size match
|
// name
|
||||||
for i:=0 to PAPERCOUNT-1 do
|
for i:=0 to PAPERCOUNT-1 do
|
||||||
with PPDPaperInfo[i] do begin
|
with PPDPaperInfo[i] do
|
||||||
if CompareText(aPaperName, Name)=0 then
|
begin
|
||||||
|
if CompareText(Name, aPaperName)=0 then
|
||||||
begin
|
begin
|
||||||
// perfect name match, no need to look anymore
|
// found
|
||||||
{$ifdef DbgPrinter_detail}DebugLn('i=%d Perfect Name Match %s',[i, Name]);{$Endif}
|
{$ifdef DbgPrinter_detail}DebugLn('i=%d Perfect Name Match %s %s',[i, Name, dbgsp]);{$Endif}
|
||||||
BIndex := i;
|
result := Typ;
|
||||||
Break;
|
exit;
|
||||||
end else
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// size match
|
||||||
|
for i:=0 to PAPERCOUNT-1 do
|
||||||
|
with PPDPaperInfo[i] do
|
||||||
|
begin
|
||||||
if ValidSize and (X>=aWidth) and (Y>=aHeight) then
|
if ValidSize and (X>=aWidth) and (Y>=aHeight) then
|
||||||
begin
|
begin
|
||||||
// only interested on papers that are same or bigger size than match paper
|
// only interested on papers that are same or bigger size than match paper
|
||||||
@ -679,24 +701,31 @@ begin
|
|||||||
if (Cw=0) and (Ch=0) then
|
if (Cw=0) and (Ch=0) then
|
||||||
begin
|
begin
|
||||||
// no need to look more, perfect match
|
// no need to look more, perfect match
|
||||||
{$ifdef DbgPrinter_detail}DebugLn('i=%d Perfect Size Match w=%d h=%d "%s"->%s',[i,X,Y,aPaperName,Name]);{$Endif}
|
{$ifdef DbgPrinter_detail}DebugLn('i=%d Perfect Size Match w=%d h=%d "%s"->%s %s',[i,X,Y,aPaperName,Name, dbgsp]);{$Endif}
|
||||||
BIndex := i;
|
BIndex := i;
|
||||||
break;
|
break;
|
||||||
end else
|
end else
|
||||||
if (Cw<6) and (Ch<6) and (Cw<=BDeltaW) and (Cw<=BDeltaH) then
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DbgPrinter_detail}DebugLn('i=%d Close Size cw=%d ch=%d "%s"->%s',[i,cw,ch,aPaperName,Name]);{$endif}
|
{$ifdef DbgPrinter_detail}
|
||||||
// we are interested only on differences with searched paper of
|
if (Cw<BestDw) and (Ch<BestDh) then begin
|
||||||
// about 2 mm or less (1 mm is aprox 3 points)
|
BestDw := Cw;
|
||||||
BIndex := i;
|
BestDh := Ch;
|
||||||
BDeltaW := Cw;
|
end;
|
||||||
BDeltaH := CH;
|
{$endif}
|
||||||
end
|
if (Cw<6) and (Ch<6) and (Cw<=BDeltaW) and (Cw<=BDeltaH) then
|
||||||
{$ifdef DbgPrinter_detail}
|
begin
|
||||||
//else
|
{$ifdef DbgPrinter_detail}DebugLn('i=%d Close Size cw=%d ch=%d "%s"->%s %s',[i,cw,ch,aPaperName,Name, dbgsp]);{$endif}
|
||||||
// DebugLn('i=%d Missed cw=%d ch=%d %s',[i, cw, ch, Name])
|
// we are interested only on differences with searched paper of
|
||||||
{$endif}
|
// about 2 mm or less (1 mm is aprox 3 points)
|
||||||
;
|
BIndex := i;
|
||||||
|
BDeltaW := Cw;
|
||||||
|
BDeltaH := CH;
|
||||||
|
end
|
||||||
|
{$ifdef DbgPrinter_detail}
|
||||||
|
//else
|
||||||
|
// DebugLn('i=%d Missed cw=%d ch=%d %s',[i, cw, ch, Name])
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -706,7 +735,7 @@ begin
|
|||||||
end
|
end
|
||||||
{$ifdef DbgPrinter_detail}
|
{$ifdef DbgPrinter_detail}
|
||||||
else
|
else
|
||||||
DebugLn(['Matching Paper ',aPaperName,' failed'])
|
DebugLn('Matching Paper %s failed BestDw=%d BestDh=%d',[aPaperName, BestDw, BestDh])
|
||||||
{$endif}
|
{$endif}
|
||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user