mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 05:16:48 +02:00
Printers, Added default list of papers in case there are no printers, fixes to cups dialogs
git-svn-id: trunk@23779 -
This commit is contained in:
parent
84db565553
commit
dc2a5b26a1
@ -32,6 +32,9 @@ begin
|
|||||||
|
|
||||||
combo.Tag:=-1;
|
combo.Tag:=-1;
|
||||||
combo.Enabled:=false;
|
combo.Enabled:=false;
|
||||||
|
|
||||||
|
if THackCUPSPrinter(Printer).CupsPPD=nil then
|
||||||
|
exit;
|
||||||
if Option=nil then
|
if Option=nil then
|
||||||
begin
|
begin
|
||||||
if OptionStr='' then
|
if OptionStr='' then
|
||||||
|
@ -48,8 +48,6 @@ end;
|
|||||||
|
|
||||||
destructor TCUPSPrinter.destroy;
|
destructor TCUPSPrinter.destroy;
|
||||||
begin
|
begin
|
||||||
SetLength(FPapers, 0);
|
|
||||||
|
|
||||||
if assigned(fRawModeStream) then
|
if assigned(fRawModeStream) then
|
||||||
fRawModeStream.Free;
|
fRawModeStream.Free;
|
||||||
|
|
||||||
@ -185,83 +183,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// adds a list of known papers
|
|
||||||
procedure TCUPSPrinter.CreatePapers;
|
|
||||||
procedure add(AnIndex:Integer; aname:string; aPhysRect,aWrkRect:TRect);
|
|
||||||
begin
|
|
||||||
with fPapers[AnIndex] do begin
|
|
||||||
PaperName := aName;
|
|
||||||
PhysicalRect := aPhysRect;
|
|
||||||
WorkRect := aWrkRect;
|
|
||||||
WinCode:= 0;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
function PRRect(const ALeft,ATop,ARight,ABottom: Integer): TRect;
|
|
||||||
begin
|
|
||||||
Result.Left := ALeft;
|
|
||||||
Result.Top := ATop;
|
|
||||||
Result.Right := round(ARight * Printer.XDPI / 72);
|
|
||||||
Result.Bottom := round(ABottom * Printer.XDPI / 72);
|
|
||||||
end;
|
|
||||||
begin
|
|
||||||
SetLength(fPapers, 3);
|
|
||||||
add(0, 'Letter', PRRect(0, 0, 612, 792 ), PRRect(0, 0, 612, 792 ));
|
|
||||||
add(1, 'A4', PRRect(0, 0, 595, 892 ), PRRect(0, 0, 595, 892 ));
|
|
||||||
add(2, 'Legal', PRRect(0, 0, 612, 1008), PRRect(0, 0, 612, 1008));
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCUPSPrinter.IndexOfPaper(aPaperName: string): integer;
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
result := -1;
|
|
||||||
for i:=0 to Length(fPapers)-1 do
|
|
||||||
if CompareText(fPapers[i].PaperName, aPapername)=0 then begin
|
|
||||||
result := i;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCUPSPrinter.InternalGetDefPaperName: string;
|
|
||||||
begin
|
|
||||||
if Length(Fpapers)=0 then
|
|
||||||
CreatePapers;
|
|
||||||
result := fPapers[0].PaperName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCUPSPrinter.InternalGetCurPaperName: string;
|
|
||||||
begin
|
|
||||||
if Length(fPapers)=0 then
|
|
||||||
CreatePapers;
|
|
||||||
result := fPapers[fCurrentPaper].PaperName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TCUPSPrinter.InternalGetPaperRect(aPaperName:string;
|
|
||||||
var PaperRect:TPaperRect);
|
|
||||||
var
|
|
||||||
i: LongInt;
|
|
||||||
begin
|
|
||||||
if Length(fPapers)=0 then
|
|
||||||
CreatePapers;
|
|
||||||
i := IndexOfPaper(aPaperName);
|
|
||||||
if i<0 then
|
|
||||||
i := FCurrentPaper;
|
|
||||||
|
|
||||||
with fPapers[i] do
|
|
||||||
if orientation in [poPortrait, poReversePortrait] then begin
|
|
||||||
PaperRect.PhysicalRect := PhysicalRect;
|
|
||||||
PaperRect.WorkRect := WorkRect;
|
|
||||||
end else begin
|
|
||||||
PaperRect.PhysicalRect.Right := PhysicalRect.Bottom;
|
|
||||||
PaperRect.Physicalrect.Bottom := PhysicalRect.Right;
|
|
||||||
|
|
||||||
PaperRect.WorkRect.Left := WorkRect.Top;
|
|
||||||
PaperRect.WorkRect.Top := PhysicalRect.Right-WorkRect.Right;
|
|
||||||
PaperRect.WorkRect.Right := WorkRect.Bottom;
|
|
||||||
PaperRect.WorkRect.Bottom := PhysicalRect.Right-Workrect.Left;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCUPSPrinter.CupsPapersListValid: boolean;
|
function TCUPSPrinter.CupsPapersListValid: boolean;
|
||||||
var
|
var
|
||||||
Lst: TStringlist;
|
Lst: TStringlist;
|
||||||
@ -884,6 +805,10 @@ Var i,Num : Integer;
|
|||||||
P : Pcups_dest_t;
|
P : Pcups_dest_t;
|
||||||
begin
|
begin
|
||||||
inherited DoEnumPrinters(Lst);
|
inherited DoEnumPrinters(Lst);
|
||||||
|
{$IFDEF NOPRINTERS}
|
||||||
|
Lst.Clear;
|
||||||
|
Exit;
|
||||||
|
{$ENDIF}
|
||||||
if not CUPSLibInstalled then Exit;
|
if not CUPSLibInstalled then Exit;
|
||||||
|
|
||||||
Num:=cupsGetDests(@fcupsPrinters);
|
Num:=cupsGetDests(@fcupsPrinters);
|
||||||
@ -902,8 +827,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCUPSPrinter.DoEnumPapers(Lst: TStrings);
|
procedure TCUPSPrinter.DoEnumPapers(Lst: TStrings);
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TCUPSPrinter.DoEnumPapers ',dbgsName(Self)]);
|
//DebugLn(['TCUPSPrinter.DoEnumPapers ',dbgsName(Self)]);
|
||||||
inherited DoEnumPapers(Lst);
|
inherited DoEnumPapers(Lst);
|
||||||
@ -911,15 +834,6 @@ begin
|
|||||||
GetEnumAttributeString('media-supported',Lst);
|
GetEnumAttributeString('media-supported',Lst);
|
||||||
|
|
||||||
fCupsPapersCount := lst.Count;
|
fCupsPapersCount := lst.Count;
|
||||||
if FCupsPapersCount=0 then begin
|
|
||||||
// printer doesn't support attribute media-supported, return
|
|
||||||
// our printer list
|
|
||||||
if Length(FPapers)=0 then
|
|
||||||
CreatePapers;
|
|
||||||
for i:=0 to Length(fPapers)-1 do
|
|
||||||
lst.Add(fPapers[i].PaperName);
|
|
||||||
fCurrentPaper := 0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCUPSPrinter.DoSetPrinter(aName: string): Integer;
|
function TCUPSPrinter.DoSetPrinter(aName: string): Integer;
|
||||||
@ -1065,7 +979,7 @@ begin
|
|||||||
if not (cpsDefaultPaperNameValid in FStates) then begin
|
if not (cpsDefaultPaperNameValid in FStates) then begin
|
||||||
fCachedGetDefaultPaperName:=inherited DoGetDefaultPaperName;
|
fCachedGetDefaultPaperName:=inherited DoGetDefaultPaperName;
|
||||||
if not CupsPapersListValid then
|
if not CupsPapersListValid then
|
||||||
FCachedGetDefaultPaperName:=InternalGetDefPaperName
|
FCachedGetDefaultPaperName:=PaperSize.DefaultPaperName
|
||||||
else begin
|
else begin
|
||||||
fCachedGetDefaultPaperName:=
|
fCachedGetDefaultPaperName:=
|
||||||
GetAttributeString('media-default',fCachedGetDefaultPaperName);
|
GetAttributeString('media-default',fCachedGetDefaultPaperName);
|
||||||
@ -1083,7 +997,7 @@ begin
|
|||||||
// paper is not yet retrieved for first time
|
// paper is not yet retrieved for first time
|
||||||
// first try to see if there is a list of papers available
|
// first try to see if there is a list of papers available
|
||||||
if not CupsPapersListValid then
|
if not CupsPapersListValid then
|
||||||
fCachedPaperName := InternalGetCurPaperName
|
FCachedPaperName := PaperSize.PaperName
|
||||||
else begin
|
else begin
|
||||||
fCachedPaperName := cupsGetOption('PageSize');
|
fCachedPaperName := cupsGetOption('PageSize');
|
||||||
{$IFDEF UseCache}
|
{$IFDEF UseCache}
|
||||||
@ -1095,8 +1009,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCUPSPrinter.DoSetPaperName(aName: string);
|
procedure TCUPSPrinter.DoSetPaperName(aName: string);
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF UseCache}
|
{$IFDEF UseCache}
|
||||||
if aName=DoGetPaperName then exit;
|
if aName=DoGetPaperName then exit;
|
||||||
@ -1104,11 +1016,9 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
inherited DoSetPaperName(aName);
|
inherited DoSetPaperName(aName);
|
||||||
|
|
||||||
if FCupsPapersCount<=0 then begin
|
if FCupsPapersCount<=0 then
|
||||||
i := IndexOfPaper(aName);
|
PaperSize.PaperName:=AName
|
||||||
if i>=0 then
|
else
|
||||||
fCurrentPaper := i;
|
|
||||||
end else
|
|
||||||
cupsAddOption('PageSize',aName)
|
cupsAddOption('PageSize',aName)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1224,8 +1134,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if P=nil then begin
|
if P=nil then begin
|
||||||
// FCachePaperRect couldn't be determined, use our internal list
|
FCachePaperRect := PaperSize.PaperRectOf[AName];
|
||||||
InternalGetPaperRect(aName, FCachePaperRect);
|
|
||||||
fCachePaperRectResult:=1
|
fCachePaperRectResult:=1
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -67,14 +67,7 @@ type
|
|||||||
cpsResolutionValid
|
cpsResolutionValid
|
||||||
);
|
);
|
||||||
TCUPSPrinterStates = set of TCUPSPrinterState;
|
TCUPSPrinterStates = set of TCUPSPrinterState;
|
||||||
|
|
||||||
TPaperItem = record
|
|
||||||
PaperName: string[40];
|
|
||||||
PhysicalRect: TRect;
|
|
||||||
WorkRect: TRect;
|
|
||||||
WinCode: Integer;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCUPSPrinter }
|
{ TCUPSPrinter }
|
||||||
|
|
||||||
TCUPSPrinter = Class(TPrinter)
|
TCUPSPrinter = Class(TPrinter)
|
||||||
@ -103,14 +96,7 @@ type
|
|||||||
procedure DoCupsConnect;
|
procedure DoCupsConnect;
|
||||||
|
|
||||||
private
|
private
|
||||||
fPapers: array of TPaperItem;
|
|
||||||
fCupsPapersCount: Integer;
|
fCupsPapersCount: Integer;
|
||||||
fCurrentPaper: Integer;
|
|
||||||
procedure CreatePapers;
|
|
||||||
function IndexOfPaper(aPaperName: string): integer;
|
|
||||||
function InternalGetDefPaperName: string;
|
|
||||||
function InternalGetCurPaperName: string;
|
|
||||||
procedure InternalGetPaperRect(aPaperName:string; var PaperRect:TPaperRect);
|
|
||||||
function CupsPapersListValid: boolean;
|
function CupsPapersListValid: boolean;
|
||||||
function InternalGetResolution(ForX: boolean): Integer;
|
function InternalGetResolution(ForX: boolean): Integer;
|
||||||
{$IFDEF DebugCUPS}
|
{$IFDEF DebugCUPS}
|
||||||
|
@ -3,37 +3,37 @@ object framePageSetup: TframePageSetup
|
|||||||
Height = 435
|
Height = 435
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 403
|
Width = 403
|
||||||
ClientHeight = 431
|
ClientHeight = 435
|
||||||
ClientWidth = 399
|
ClientWidth = 403
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
DesignLeft = 427
|
DesignLeft = 388
|
||||||
DesignTop = 126
|
DesignTop = 96
|
||||||
object panSetup: TPanel
|
object panSetup: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 211
|
Height = 211
|
||||||
Top = 220
|
Top = 224
|
||||||
Width = 399
|
Width = 403
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 211
|
ClientHeight = 211
|
||||||
ClientWidth = 399
|
ClientWidth = 403
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object gpPaper: TGroupBox
|
object gpPaper: TGroupBox
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 98
|
Height = 98
|
||||||
Top = 6
|
Top = 6
|
||||||
Width = 387
|
Width = 391
|
||||||
Align = alTop
|
Align = alTop
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
Caption = 'Paper'
|
Caption = 'Paper'
|
||||||
ClientHeight = 81
|
ClientHeight = 81
|
||||||
ClientWidth = 383
|
ClientWidth = 387
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object lblPaper: TLabel
|
object lblPaper: TLabel
|
||||||
Left = 14
|
Left = 14
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 11
|
Top = 11
|
||||||
Width = 41
|
Width = 39
|
||||||
Caption = 'Paper:'
|
Caption = 'Paper:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -41,7 +41,7 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 14
|
Left = 14
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 51
|
Top = 51
|
||||||
Width = 49
|
Width = 46
|
||||||
Caption = 'Source:'
|
Caption = 'Source:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -49,11 +49,9 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 78
|
Left = 78
|
||||||
Height = 29
|
Height = 29
|
||||||
Top = 3
|
Top = 3
|
||||||
Width = 298
|
Width = 302
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
AutoComplete = False
|
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
ItemWidth = 0
|
|
||||||
OnChange = cbPaperChange
|
OnChange = cbPaperChange
|
||||||
Style = csDropDownList
|
Style = csDropDownList
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
@ -62,11 +60,9 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 78
|
Left = 78
|
||||||
Height = 29
|
Height = 29
|
||||||
Top = 43
|
Top = 43
|
||||||
Width = 298
|
Width = 302
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
AutoComplete = False
|
|
||||||
ItemHeight = 0
|
ItemHeight = 0
|
||||||
ItemWidth = 0
|
|
||||||
Style = csDropDownList
|
Style = csDropDownList
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
@ -84,9 +80,9 @@ object framePageSetup: TframePageSetup
|
|||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object radPortrait: TRadioButton
|
object radPortrait: TRadioButton
|
||||||
Left = 14
|
Left = 14
|
||||||
Height = 22
|
Height = 21
|
||||||
Top = 14
|
Top = 14
|
||||||
Width = 71
|
Width = 65
|
||||||
Caption = 'Portrait'
|
Caption = 'Portrait'
|
||||||
Checked = True
|
Checked = True
|
||||||
OnClick = radPortraitClick
|
OnClick = radPortraitClick
|
||||||
@ -95,9 +91,9 @@ object framePageSetup: TframePageSetup
|
|||||||
end
|
end
|
||||||
object radLandscape: TRadioButton
|
object radLandscape: TRadioButton
|
||||||
Left = 14
|
Left = 14
|
||||||
Height = 22
|
Height = 21
|
||||||
Top = 44
|
Top = 44
|
||||||
Width = 92
|
Width = 86
|
||||||
Caption = 'Landscape'
|
Caption = 'Landscape'
|
||||||
OnClick = radPortraitClick
|
OnClick = radPortraitClick
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
@ -108,19 +104,19 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 132
|
Left = 132
|
||||||
Height = 95
|
Height = 95
|
||||||
Top = 110
|
Top = 110
|
||||||
Width = 261
|
Width = 265
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
Caption = 'Margins'
|
Caption = 'Margins'
|
||||||
ClientHeight = 78
|
ClientHeight = 78
|
||||||
ClientWidth = 257
|
ClientWidth = 261
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
object panMargins: TPanel
|
object panMargins: TPanel
|
||||||
AnchorSideLeft.Control = gpMargins
|
AnchorSideLeft.Control = gpMargins
|
||||||
AnchorSideLeft.Side = asrCenter
|
AnchorSideLeft.Side = asrCenter
|
||||||
AnchorSideTop.Control = gpMargins
|
AnchorSideTop.Control = gpMargins
|
||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
Left = 4
|
Left = 6
|
||||||
Height = 72
|
Height = 72
|
||||||
Top = 3
|
Top = 3
|
||||||
Width = 249
|
Width = 249
|
||||||
@ -132,7 +128,7 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 127
|
Left = 127
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 50
|
Top = 50
|
||||||
Width = 50
|
Width = 47
|
||||||
Caption = 'Bottom:'
|
Caption = 'Bottom:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -140,7 +136,7 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 6
|
Left = 6
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 48
|
Top = 48
|
||||||
Width = 26
|
Width = 25
|
||||||
Caption = 'Top:'
|
Caption = 'Top:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -148,7 +144,7 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 127
|
Left = 127
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 14
|
Top = 14
|
||||||
Width = 37
|
Width = 35
|
||||||
Caption = 'Right:'
|
Caption = 'Right:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -156,34 +152,34 @@ object framePageSetup: TframePageSetup
|
|||||||
Left = 6
|
Left = 6
|
||||||
Height = 16
|
Height = 16
|
||||||
Top = 14
|
Top = 14
|
||||||
Width = 28
|
Width = 26
|
||||||
Caption = 'Left:'
|
Caption = 'Left:'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
object txtBottom: TEdit
|
object txtBottom: TEdit
|
||||||
Left = 183
|
Left = 183
|
||||||
Height = 23
|
Height = 25
|
||||||
Top = 43
|
Top = 43
|
||||||
Width = 64
|
Width = 64
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object txtTop: TEdit
|
object txtTop: TEdit
|
||||||
Left = 40
|
Left = 40
|
||||||
Height = 23
|
Height = 25
|
||||||
Top = 43
|
Top = 43
|
||||||
Width = 56
|
Width = 56
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
object txtRight: TEdit
|
object txtRight: TEdit
|
||||||
Left = 183
|
Left = 183
|
||||||
Height = 23
|
Height = 25
|
||||||
Top = 7
|
Top = 7
|
||||||
Width = 64
|
Width = 64
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
end
|
end
|
||||||
object txtLeft: TEdit
|
object txtLeft: TEdit
|
||||||
Left = 40
|
Left = 40
|
||||||
Height = 23
|
Height = 25
|
||||||
Top = 7
|
Top = 7
|
||||||
Width = 56
|
Width = 56
|
||||||
TabOrder = 3
|
TabOrder = 3
|
||||||
@ -194,13 +190,13 @@ object framePageSetup: TframePageSetup
|
|||||||
object panPreview: TPanel
|
object panPreview: TPanel
|
||||||
AnchorSideTop.Control = panSetup
|
AnchorSideTop.Control = panSetup
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 220
|
Height = 224
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 399
|
Width = 403
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 220
|
ClientHeight = 224
|
||||||
ClientWidth = 399
|
ClientWidth = 403
|
||||||
Constraints.MinHeight = 142
|
Constraints.MinHeight = 142
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
OnMouseDown = pbPreviewMouseDown
|
OnMouseDown = pbPreviewMouseDown
|
||||||
@ -210,9 +206,9 @@ object framePageSetup: TframePageSetup
|
|||||||
AnchorSideLeft.Side = asrCenter
|
AnchorSideLeft.Side = asrCenter
|
||||||
AnchorSideTop.Control = panPreview
|
AnchorSideTop.Control = panPreview
|
||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
Left = 149
|
Left = 151
|
||||||
Height = 130
|
Height = 130
|
||||||
Top = 45
|
Top = 47
|
||||||
Width = 100
|
Width = 100
|
||||||
OnMouseDown = pbPreviewMouseDown
|
OnMouseDown = pbPreviewMouseDown
|
||||||
OnMouseWheelDown = pbPreviewMouseWheelDown
|
OnMouseWheelDown = pbPreviewMouseWheelDown
|
||||||
|
@ -2,58 +2,57 @@
|
|||||||
|
|
||||||
LazarusResources.Add('TframePageSetup','FORMDATA',[
|
LazarusResources.Add('TframePageSetup','FORMDATA',[
|
||||||
'TPF0'#15'TframePageSetup'#14'framePageSetup'#4'Left'#2#0#6'Height'#3#179#1#3
|
'TPF0'#15'TframePageSetup'#14'framePageSetup'#4'Left'#2#0#6'Height'#3#179#1#3
|
||||||
+'Top'#2#0#5'Width'#3#147#1#12'ClientHeight'#3#175#1#11'ClientWidth'#3#143#1#8
|
+'Top'#2#0#5'Width'#3#147#1#12'ClientHeight'#3#179#1#11'ClientWidth'#3#147#1#8
|
||||||
+'TabOrder'#2#0#10'DesignLeft'#3#171#1#9'DesignTop'#2'~'#0#6'TPanel'#8'panSet'
|
+'TabOrder'#2#0#10'DesignLeft'#3#132#1#9'DesignTop'#2'`'#0#6'TPanel'#8'panSet'
|
||||||
+'up'#4'Left'#2#0#6'Height'#3#211#0#3'Top'#3#220#0#5'Width'#3#143#1#5'Align'#7
|
+'up'#4'Left'#2#0#6'Height'#3#211#0#3'Top'#3#224#0#5'Width'#3#147#1#5'Align'#7
|
||||||
+#8'alBottom'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#3#211#0#11'ClientWi'
|
+#8'alBottom'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#3#211#0#11'ClientWi'
|
||||||
+'dth'#3#143#1#8'TabOrder'#2#0#0#9'TGroupBox'#7'gpPaper'#4'Left'#2#6#6'Height'
|
+'dth'#3#147#1#8'TabOrder'#2#0#0#9'TGroupBox'#7'gpPaper'#4'Left'#2#6#6'Height'
|
||||||
+#2'b'#3'Top'#2#6#5'Width'#3#131#1#5'Align'#7#5'alTop'#20'BorderSpacing.Aroun'
|
+#2'b'#3'Top'#2#6#5'Width'#3#135#1#5'Align'#7#5'alTop'#20'BorderSpacing.Aroun'
|
||||||
+'d'#2#6#7'Caption'#6#5'Paper'#12'ClientHeight'#2'Q'#11'ClientWidth'#3''#1#8
|
+'d'#2#6#7'Caption'#6#5'Paper'#12'ClientHeight'#2'Q'#11'ClientWidth'#3#131#1#8
|
||||||
+'TabOrder'#2#0#0#6'TLabel'#8'lblPaper'#4'Left'#2#14#6'Height'#2#16#3'Top'#2
|
+'TabOrder'#2#0#0#6'TLabel'#8'lblPaper'#4'Left'#2#14#6'Height'#2#16#3'Top'#2
|
||||||
+#11#5'Width'#2')'#7'Caption'#6#6'Paper:'#11'ParentColor'#8#0#0#6'TLabel'#9'l'
|
+#11#5'Width'#2''''#7'Caption'#6#6'Paper:'#11'ParentColor'#8#0#0#6'TLabel'#9
|
||||||
+'blSource'#4'Left'#2#14#6'Height'#2#16#3'Top'#2'3'#5'Width'#2'1'#7'Caption'#6
|
+'lblSource'#4'Left'#2#14#6'Height'#2#16#3'Top'#2'3'#5'Width'#2'.'#7'Caption'
|
||||||
+#7'Source:'#11'ParentColor'#8#0#0#9'TComboBox'#7'cbPaper'#4'Left'#2'N'#6'Hei'
|
+#6#7'Source:'#11'ParentColor'#8#0#0#9'TComboBox'#7'cbPaper'#4'Left'#2'N'#6'H'
|
||||||
+'ght'#2#29#3'Top'#2#3#5'Width'#3'*'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akR'
|
+'eight'#2#29#3'Top'#2#3#5'Width'#3'.'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'a'
|
||||||
+'ight'#0#12'AutoComplete'#8#10'ItemHeight'#2#0#9'ItemWidth'#2#0#8'OnChange'#7
|
+'kRight'#0#10'ItemHeight'#2#0#8'OnChange'#7#13'cbPaperChange'#5'Style'#7#14
|
||||||
+#13'cbPaperChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0#0#0#9'TComb'
|
+'csDropDownList'#8'TabOrder'#2#0#0#0#9'TComboBox'#8'cbSource'#4'Left'#2'N'#6
|
||||||
+'oBox'#8'cbSource'#4'Left'#2'N'#6'Height'#2#29#3'Top'#2'+'#5'Width'#3'*'#1#7
|
+'Height'#2#29#3'Top'#2'+'#5'Width'#3'.'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7
|
||||||
+'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#12'AutoComplete'#8#10'ItemHeigh'
|
+'akRight'#0#10'ItemHeight'#2#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1
|
||||||
+'t'#2#0#9'ItemWidth'#2#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1#0#0#0
|
+#0#0#0#9'TGroupBox'#13'gpOrientation'#4'Left'#2#6#6'Height'#2'_'#3'Top'#2'n'
|
||||||
+#9'TGroupBox'#13'gpOrientation'#4'Left'#2#6#6'Height'#2'_'#3'Top'#2'n'#5'Wid'
|
+#5'Width'#2'x'#5'Align'#7#6'alLeft'#20'BorderSpacing.Around'#2#6#7'Caption'#6
|
||||||
+'th'#2'x'#5'Align'#7#6'alLeft'#20'BorderSpacing.Around'#2#6#7'Caption'#6#11
|
+#11'Orientation'#12'ClientHeight'#2'N'#11'ClientWidth'#2't'#8'TabOrder'#2#1#0
|
||||||
+'Orientation'#12'ClientHeight'#2'N'#11'ClientWidth'#2't'#8'TabOrder'#2#1#0#12
|
+#12'TRadioButton'#11'radPortrait'#4'Left'#2#14#6'Height'#2#21#3'Top'#2#14#5
|
||||||
+'TRadioButton'#11'radPortrait'#4'Left'#2#14#6'Height'#2#22#3'Top'#2#14#5'Wid'
|
+'Width'#2'A'#7'Caption'#6#8'Portrait'#7'Checked'#9#7'OnClick'#7#16'radPortra'
|
||||||
+'th'#2'G'#7'Caption'#6#8'Portrait'#7'Checked'#9#7'OnClick'#7#16'radPortraitC'
|
+'itClick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#12'TRadioButton'#12'ra'
|
||||||
+'lick'#5'State'#7#9'cbChecked'#8'TabOrder'#2#0#0#0#12'TRadioButton'#12'radLa'
|
+'dLandscape'#4'Left'#2#14#6'Height'#2#21#3'Top'#2','#5'Width'#2'V'#7'Caption'
|
||||||
+'ndscape'#4'Left'#2#14#6'Height'#2#22#3'Top'#2','#5'Width'#2'\'#7'Caption'#6
|
+#6#9'Landscape'#7'OnClick'#7#16'radPortraitClick'#8'TabOrder'#2#1#7'TabStop'
|
||||||
+#9'Landscape'#7'OnClick'#7#16'radPortraitClick'#8'TabOrder'#2#1#7'TabStop'#8
|
+#8#0#0#0#9'TGroupBox'#9'gpMargins'#4'Left'#3#132#0#6'Height'#2'_'#3'Top'#2'n'
|
||||||
+#0#0#0#9'TGroupBox'#9'gpMargins'#4'Left'#3#132#0#6'Height'#2'_'#3'Top'#2'n'#5
|
+#5'Width'#3#9#1#5'Align'#7#8'alClient'#20'BorderSpacing.Around'#2#6#7'Captio'
|
||||||
+'Width'#3#5#1#5'Align'#7#8'alClient'#20'BorderSpacing.Around'#2#6#7'Caption'
|
+'n'#6#7'Margins'#12'ClientHeight'#2'N'#11'ClientWidth'#3#5#1#8'TabOrder'#2#2
|
||||||
+#6#7'Margins'#12'ClientHeight'#2'N'#11'ClientWidth'#3#1#1#8'TabOrder'#2#2#0#6
|
+#0#6'TPanel'#10'panMargins'#22'AnchorSideLeft.Control'#7#9'gpMargins'#19'Anc'
|
||||||
+'TPanel'#10'panMargins'#22'AnchorSideLeft.Control'#7#9'gpMargins'#19'AnchorS'
|
+'horSideLeft.Side'#7#9'asrCenter'#21'AnchorSideTop.Control'#7#9'gpMargins'#18
|
||||||
+'ideLeft.Side'#7#9'asrCenter'#21'AnchorSideTop.Control'#7#9'gpMargins'#18'An'
|
+'AnchorSideTop.Side'#7#9'asrCenter'#4'Left'#2#6#6'Height'#2'H'#3'Top'#2#3#5
|
||||||
+'chorSideTop.Side'#7#9'asrCenter'#4'Left'#2#4#6'Height'#2'H'#3'Top'#2#3#5'Wi'
|
+'Width'#3#249#0#10'BevelOuter'#7#7'bvSpace'#12'ClientHeight'#2'H'#11'ClientW'
|
||||||
+'dth'#3#249#0#10'BevelOuter'#7#7'bvSpace'#12'ClientHeight'#2'H'#11'ClientWid'
|
+'idth'#3#249#0#8'TabOrder'#2#0#0#6'TLabel'#9'lblBottom'#4'Left'#2#127#6'Heig'
|
||||||
+'th'#3#249#0#8'TabOrder'#2#0#0#6'TLabel'#9'lblBottom'#4'Left'#2''#6'Height'
|
+'ht'#2#16#3'Top'#2'2'#5'Width'#2'/'#7'Caption'#6#7'Bottom:'#11'ParentColor'#8
|
||||||
+#2#16#3'Top'#2'2'#5'Width'#2'2'#7'Caption'#6#7'Bottom:'#11'ParentColor'#8#0#0
|
+#0#0#6'TLabel'#6'lblTop'#4'Left'#2#6#6'Height'#2#16#3'Top'#2'0'#5'Width'#2#25
|
||||||
+#6'TLabel'#6'lblTop'#4'Left'#2#6#6'Height'#2#16#3'Top'#2'0'#5'Width'#2#26#7
|
+#7'Caption'#6#4'Top:'#11'ParentColor'#8#0#0#6'TLabel'#8'lblRight'#4'Left'#2
|
||||||
+'Caption'#6#4'Top:'#11'ParentColor'#8#0#0#6'TLabel'#8'lblRight'#4'Left'#2''
|
+#127#6'Height'#2#16#3'Top'#2#14#5'Width'#2'#'#7'Caption'#6#6'Right:'#11'Pare'
|
||||||
+#6'Height'#2#16#3'Top'#2#14#5'Width'#2'%'#7'Caption'#6#6'Right:'#11'ParentCo'
|
+'ntColor'#8#0#0#6'TLabel'#7'lblLeft'#4'Left'#2#6#6'Height'#2#16#3'Top'#2#14#5
|
||||||
+'lor'#8#0#0#6'TLabel'#7'lblLeft'#4'Left'#2#6#6'Height'#2#16#3'Top'#2#14#5'Wi'
|
+'Width'#2#26#7'Caption'#6#5'Left:'#11'ParentColor'#8#0#0#5'TEdit'#9'txtBotto'
|
||||||
+'dth'#2#28#7'Caption'#6#5'Left:'#11'ParentColor'#8#0#0#5'TEdit'#9'txtBottom'
|
+'m'#4'Left'#3#183#0#6'Height'#2#25#3'Top'#2'+'#5'Width'#2'@'#8'TabOrder'#2#0
|
||||||
+#4'Left'#3#183#0#6'Height'#2#23#3'Top'#2'+'#5'Width'#2'@'#8'TabOrder'#2#0#0#0
|
+#0#0#5'TEdit'#6'txtTop'#4'Left'#2'('#6'Height'#2#25#3'Top'#2'+'#5'Width'#2'8'
|
||||||
+#5'TEdit'#6'txtTop'#4'Left'#2'('#6'Height'#2#23#3'Top'#2'+'#5'Width'#2'8'#8
|
+#8'TabOrder'#2#1#0#0#5'TEdit'#8'txtRight'#4'Left'#3#183#0#6'Height'#2#25#3'T'
|
||||||
+'TabOrder'#2#1#0#0#5'TEdit'#8'txtRight'#4'Left'#3#183#0#6'Height'#2#23#3'Top'
|
+'op'#2#7#5'Width'#2'@'#8'TabOrder'#2#2#0#0#5'TEdit'#7'txtLeft'#4'Left'#2'('#6
|
||||||
+#2#7#5'Width'#2'@'#8'TabOrder'#2#2#0#0#5'TEdit'#7'txtLeft'#4'Left'#2'('#6'He'
|
+'Height'#2#25#3'Top'#2#7#5'Width'#2'8'#8'TabOrder'#2#3#0#0#0#0#0#6'TPanel'#10
|
||||||
+'ight'#2#23#3'Top'#2#7#5'Width'#2'8'#8'TabOrder'#2#3#0#0#0#0#0#6'TPanel'#10
|
|
||||||
+'panPreview'#21'AnchorSideTop.Control'#7#8'panSetup'#4'Left'#2#0#6'Height'#3
|
+'panPreview'#21'AnchorSideTop.Control'#7#8'panSetup'#4'Left'#2#0#6'Height'#3
|
||||||
+#220#0#3'Top'#2#0#5'Width'#3#143#1#5'Align'#7#8'alClient'#10'BevelOuter'#7#6
|
+#224#0#3'Top'#2#0#5'Width'#3#147#1#5'Align'#7#8'alClient'#10'BevelOuter'#7#6
|
||||||
+'bvNone'#12'ClientHeight'#3#220#0#11'ClientWidth'#3#143#1#21'Constraints.Min'
|
+'bvNone'#12'ClientHeight'#3#224#0#11'ClientWidth'#3#147#1#21'Constraints.Min'
|
||||||
+'Height'#3#142#0#8'TabOrder'#2#1#11'OnMouseDown'#7#18'pbPreviewMouseDown'#8
|
+'Height'#3#142#0#8'TabOrder'#2#1#11'OnMouseDown'#7#18'pbPreviewMouseDown'#8
|
||||||
+'OnResize'#7#16'panPreviewResize'#0#9'TPaintBox'#9'pbPreview'#22'AnchorSideL'
|
+'OnResize'#7#16'panPreviewResize'#0#9'TPaintBox'#9'pbPreview'#22'AnchorSideL'
|
||||||
+'eft.Control'#7#10'panPreview'#19'AnchorSideLeft.Side'#7#9'asrCenter'#21'Anc'
|
+'eft.Control'#7#10'panPreview'#19'AnchorSideLeft.Side'#7#9'asrCenter'#21'Anc'
|
||||||
+'horSideTop.Control'#7#10'panPreview'#18'AnchorSideTop.Side'#7#9'asrCenter'#4
|
+'horSideTop.Control'#7#10'panPreview'#18'AnchorSideTop.Side'#7#9'asrCenter'#4
|
||||||
+'Left'#3#149#0#6'Height'#3#130#0#3'Top'#2'-'#5'Width'#2'd'#11'OnMouseDown'#7
|
+'Left'#3#151#0#6'Height'#3#130#0#3'Top'#2'/'#5'Width'#2'd'#11'OnMouseDown'#7
|
||||||
+#18'pbPreviewMouseDown'#16'OnMouseWheelDown'#7#23'pbPreviewMouseWheelDown'#14
|
+#18'pbPreviewMouseDown'#16'OnMouseWheelDown'#7#23'pbPreviewMouseWheelDown'#14
|
||||||
+'OnMouseWheelUp'#7#21'pbPreviewMouseWheelUp'#7'OnPaint'#7#14'pbPreviewPaint'
|
+'OnMouseWheelUp'#7#21'pbPreviewMouseWheelUp'#7'OnPaint'#7#14'pbPreviewPaint'
|
||||||
+#0#0#0#0
|
+#0#0#0#0
|
||||||
|
@ -113,8 +113,7 @@ begin
|
|||||||
Canvas.Rectangle(R);
|
Canvas.Rectangle(R);
|
||||||
|
|
||||||
// hard margins
|
// hard margins
|
||||||
Canvas.Pen.Color := RGBToColor(255,127,127);
|
Canvas.Pen.Color := RGBToColor(255,204,204);
|
||||||
Canvas.Brush.Color := RGBToColor(255,127,127);
|
|
||||||
DrawMargin(0, FHardMargins.Left );
|
DrawMargin(0, FHardMargins.Left );
|
||||||
DrawMargin(1, FHardMargins.Top );
|
DrawMargin(1, FHardMargins.Top );
|
||||||
DrawMargin(2, FHardMargins.Right );
|
DrawMargin(2, FHardMargins.Right );
|
||||||
@ -135,7 +134,12 @@ end;
|
|||||||
|
|
||||||
procedure TframePageSetup.cbPaperChange(Sender: TObject);
|
procedure TframePageSetup.cbPaperChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Printer.PaperSize.PaperName := GetCupsComboKeyValue(cbPaper);
|
if Printer.PaperSize.DefaultPapers then
|
||||||
|
begin
|
||||||
|
if cbPaper.ItemIndex>=0 then
|
||||||
|
Printer.PaperSize.PaperName := cbPaper.Items[cbPaper.ItemIndex];
|
||||||
|
end else
|
||||||
|
Printer.PaperSize.PaperName := GetCupsComboKeyValue(cbPaper);
|
||||||
UpdatePageSize;
|
UpdatePageSize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -227,7 +231,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if [psoMargins,psoPapers]*FOptions<>[] then
|
if [psoMargins,psoPapers]*FOptions<>[] then
|
||||||
|
begin
|
||||||
SetupCupsCombo(cbPaper, nil, 'PageSize');
|
SetupCupsCombo(cbPaper, nil, 'PageSize');
|
||||||
|
if (cbPaper.Items.Count=0) then
|
||||||
|
begin
|
||||||
|
// no cups printer papers, use default ones
|
||||||
|
cbPaper.Items := Printer.PaperSize.SupportedPapers;
|
||||||
|
cbPaper.ItemIndex:= cbPaper.Items.IndexOf(Printer.PaperSize.PaperName);
|
||||||
|
cbPaper.Enabled:=true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
if psoPapers in FOptions then
|
if psoPapers in FOptions then
|
||||||
SetupCupsCOmbo(cbSource, nil, 'InputSlot')
|
SetupCupsCOmbo(cbSource, nil, 'InputSlot')
|
||||||
@ -255,9 +268,13 @@ begin
|
|||||||
// find the tallest paper
|
// find the tallest paper
|
||||||
FHeightTallest := 0;
|
FHeightTallest := 0;
|
||||||
j := -1;
|
j := -1;
|
||||||
|
if cbPaper.Enabled then
|
||||||
for i:=0 to cbPaper.Items.Count-1 do
|
for i:=0 to cbPaper.Items.Count-1 do
|
||||||
begin
|
begin
|
||||||
R := Printer.PaperSize.PaperRectOf[GetCupsComboKeyValue(cbPaper, i)];
|
if Printer.PaperSize.DefaultPapers then
|
||||||
|
R := Printer.PaperSize.PaperRectOf[cbPaper.Items[i]]
|
||||||
|
else
|
||||||
|
R := Printer.PaperSize.PaperRectOf[GetCupsComboKeyValue(cbPaper, i)];
|
||||||
with R.PhysicalRect do
|
with R.PhysicalRect do
|
||||||
if FHeightTallest<(Bottom-Top) then
|
if FHeightTallest<(Bottom-Top) then
|
||||||
begin
|
begin
|
||||||
|
148
lcl/printers.pas
148
lcl/printers.pas
@ -120,6 +120,11 @@ type
|
|||||||
WorkRect : TRect;
|
WorkRect : TRect;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TPaperItem = record
|
||||||
|
PaperName: string[40];
|
||||||
|
PaperRect: TPaperRect;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TPaperSize }
|
{ TPaperSize }
|
||||||
|
|
||||||
TPaperSize = Class(TObject)
|
TPaperSize = Class(TObject)
|
||||||
@ -139,11 +144,19 @@ type
|
|||||||
function GetSupportedPapers: TStrings;
|
function GetSupportedPapers: TStrings;
|
||||||
procedure SetPaperName(const AName: string);
|
procedure SetPaperName(const AName: string);
|
||||||
function PaperRectOfName(const AName: string) : TPaperRect;
|
function PaperRectOfName(const AName: string) : TPaperRect;
|
||||||
protected
|
private
|
||||||
|
fInternalPapers : array of TPaperItem;
|
||||||
|
fDefaultPapers : boolean;
|
||||||
|
fDefaultPaperIndex : Integer;
|
||||||
|
procedure CreateInternalPapers;
|
||||||
|
procedure FillDefaultPapers;
|
||||||
|
function GetDefaultPaperRect(const AName: string; var APaperRect:TPaperRect): Integer;
|
||||||
|
function IndexOfDefaultPaper(const AName: string): Integer;
|
||||||
public
|
public
|
||||||
constructor Create(aOwner : TPrinter); overload;
|
constructor Create(aOwner : TPrinter); overload;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
|
property DefaultPapers : boolean read fDefaultPapers;
|
||||||
property Width : Integer read GetPhysPaperWidth;
|
property Width : Integer read GetPhysPaperWidth;
|
||||||
property Height : Integer read GetPhysPaperHeight;
|
property Height : Integer read GetPhysPaperHeight;
|
||||||
property PaperName : string read GetPaperName write SetPaperName;
|
property PaperName : string read GetPaperName write SetPaperName;
|
||||||
@ -526,9 +539,7 @@ end;
|
|||||||
|
|
||||||
function TPrinter.GetOrientation: TPrinterOrientation;
|
function TPrinter.GetOrientation: TPrinterOrientation;
|
||||||
begin
|
begin
|
||||||
Result:=poPortrait;
|
Result:=DoGetOrientation;
|
||||||
if Printers.Count>0 then
|
|
||||||
Result:=DoGetOrientation;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Returns the height in points (pixels) of printable area
|
// Returns the height in points (pixels) of printable area
|
||||||
@ -608,8 +619,7 @@ end;
|
|||||||
procedure TPrinter.SetOrientation(const AValue: TPrinterOrientation);
|
procedure TPrinter.SetOrientation(const AValue: TPrinterOrientation);
|
||||||
begin
|
begin
|
||||||
CheckPrinting(False);
|
CheckPrinting(False);
|
||||||
if Printers.Count>0 then
|
DoSetOrientation(aValue);
|
||||||
DoSetOrientation(aValue);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//Set the selected printer
|
//Set the selected printer
|
||||||
@ -645,7 +655,7 @@ end;
|
|||||||
//If not Printer selected, Select the default printer
|
//If not Printer selected, Select the default printer
|
||||||
procedure TPrinter.SelectCurrentPrinterOrDefault;
|
procedure TPrinter.SelectCurrentPrinterOrDefault;
|
||||||
begin
|
begin
|
||||||
if fPrinterIndex<0 then
|
if (fPrinterIndex<0) and (Printers.Count>0) then
|
||||||
PrinterIndex:=0;
|
PrinterIndex:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -810,9 +820,76 @@ end;
|
|||||||
|
|
||||||
{ TPaperSize }
|
{ TPaperSize }
|
||||||
|
|
||||||
|
procedure TPaperSize.CreateInternalPapers;
|
||||||
|
procedure add(AnIndex:Integer; aname:string; aPhysRect,aWrkRect:TRect);
|
||||||
|
begin
|
||||||
|
with fInternalPapers[AnIndex] do begin
|
||||||
|
PaperName := aName;
|
||||||
|
PaperRect.PhysicalRect := aPhysRect;
|
||||||
|
PaperRect.WorkRect := aWrkRect;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
function PRRect(const ALeft,ATop,ARight,ABottom: Integer): TRect;
|
||||||
|
begin
|
||||||
|
Result.Left := ALeft;
|
||||||
|
Result.Top := ATop;
|
||||||
|
Result.Right := round(ARight * FOwnedPrinter.XDPI / 72);
|
||||||
|
Result.Bottom := round(ABottom * FOwnedPrinter.XDPI / 72);
|
||||||
|
end;
|
||||||
|
begin
|
||||||
|
if Length(fInternalPapers)=0 then
|
||||||
|
begin
|
||||||
|
SetLength(fInternalPapers, 3);
|
||||||
|
add(0, 'Letter', PRRect(0, 0, 612, 792 ), PRRect(0, 0, 612, 792 ));
|
||||||
|
add(1, 'A4', PRRect(0, 0, 595, 892 ), PRRect(0, 0, 595, 892 ));
|
||||||
|
add(2, 'Legal', PRRect(0, 0, 612, 1008), PRRect(0, 0, 612, 1008));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TPaperSize.FillDefaultPapers;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
FSupportedPapers.Clear;
|
||||||
|
CreateInternalPapers;
|
||||||
|
for i:=0 to Length(FInternalPapers)-1 do
|
||||||
|
FSupportedPapers.Add(FInternalPapers[i].PaperName);
|
||||||
|
FDefaultPaperIndex := 0;
|
||||||
|
FDefaultPapers := true;
|
||||||
|
end;
|
||||||
|
|
||||||
function TPaperSize.GetDefaultPaperName: string;
|
function TPaperSize.GetDefaultPaperName: string;
|
||||||
begin
|
begin
|
||||||
Result:=fOwnedPrinter.DoGetDefaultPaperName;
|
if fDefaultPapers then
|
||||||
|
Result := FSupportedPapers[0]
|
||||||
|
else
|
||||||
|
Result := fOwnedPrinter.DoGetDefaultPaperName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TPaperSize.GetDefaultPaperRect(const AName: string;
|
||||||
|
var APaperRect:TPaperRect): Integer;
|
||||||
|
begin
|
||||||
|
Result := IndexOfDefaultPaper(AName);
|
||||||
|
if Result>=0 then
|
||||||
|
with FInternalPapers[Result].PaperRect do begin
|
||||||
|
if FOwnedPrinter.Orientation in [poPortrait, poReversePortrait] then
|
||||||
|
begin
|
||||||
|
APaperRect.PhysicalRect := PhysicalRect;
|
||||||
|
APaperRect.WorkRect := WorkRect;
|
||||||
|
end else
|
||||||
|
begin
|
||||||
|
APaperRect.PhysicalRect.Left := 0;
|
||||||
|
APaperRect.PhysicalRect.Top := 0;
|
||||||
|
APaperRect.PhysicalRect.Right := PhysicalRect.Bottom;
|
||||||
|
APaperRect.Physicalrect.Bottom := PhysicalRect.Right;
|
||||||
|
|
||||||
|
APaperRect.WorkRect.Left := WorkRect.Top;
|
||||||
|
APaperRect.WorkRect.Top := PhysicalRect.Right-WorkRect.Right;
|
||||||
|
APaperRect.WorkRect.Right := WorkRect.Bottom;
|
||||||
|
APaperRect.WorkRect.Bottom := PhysicalRect.Right-Workrect.Left;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPaperSize.GetPhysPaperHeight: Integer;
|
function TPaperSize.GetPhysPaperHeight: Integer;
|
||||||
@ -822,7 +899,11 @@ end;
|
|||||||
|
|
||||||
function TPaperSize.GetPaperName: string;
|
function TPaperSize.GetPaperName: string;
|
||||||
begin
|
begin
|
||||||
Result:=fOwnedPrinter.DoGetPaperName;
|
if fDefaultPapers then
|
||||||
|
Result := SupportedPapers[FDefaultPaperIndex]
|
||||||
|
else
|
||||||
|
Result := fOwnedPrinter.DoGetPaperName;
|
||||||
|
|
||||||
if Result='' then
|
if Result='' then
|
||||||
Result:=DefaultPaperName;
|
Result:=DefaultPaperName;
|
||||||
end;
|
end;
|
||||||
@ -839,26 +920,48 @@ end;
|
|||||||
|
|
||||||
function TPaperSize.GetSupportedPapers: TStrings;
|
function TPaperSize.GetSupportedPapers: TStrings;
|
||||||
begin
|
begin
|
||||||
if (fOwnedPrinter.Printers.Count>0) and
|
if (fSupportedPapers.Count=0) or
|
||||||
((fSupportedPapers.Count=0)
|
(fLastPrinterIndex<>fOwnedPrinter.PrinterIndex) then
|
||||||
or (fLastPrinterIndex<>fOwnedPrinter.PrinterIndex)) then
|
|
||||||
begin
|
begin
|
||||||
fOwnedPrinter.SelectCurrentPrinterOrDefault;
|
fOwnedPrinter.SelectCurrentPrinterOrDefault;
|
||||||
|
|
||||||
fSupportedPapers.Clear;
|
fSupportedPapers.Clear;
|
||||||
|
fDefaultPapers := false;
|
||||||
//DebugLn(['TPaperSize.GetSupportedPapers ',dbgsName(fOwnedPrinter),' ',dbgsName(Printer),' ',fOwnedPrinter=Printer]);
|
//DebugLn(['TPaperSize.GetSupportedPapers ',dbgsName(fOwnedPrinter),' ',dbgsName(Printer),' ',fOwnedPrinter=Printer]);
|
||||||
fOwnedPrinter.DoEnumPapers(fSupportedPapers);
|
fOwnedPrinter.DoEnumPapers(fSupportedPapers);
|
||||||
|
|
||||||
|
if fSupportedPapers.Count=0 then
|
||||||
|
FillDefaultPapers;
|
||||||
|
|
||||||
fLastPrinterIndex:=fOwnedPrinter.PrinterIndex;
|
fLastPrinterIndex:=fOwnedPrinter.PrinterIndex;
|
||||||
end;
|
end;
|
||||||
Result:=fSupportedPapers;
|
Result:=fSupportedPapers;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPaperSize.IndexOfDefaultPaper(const AName: string): Integer;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
for i:=0 to Length(fInternalPapers)-1 do
|
||||||
|
if CompareText(fInternalPapers[i].PaperName, AName)=0 then
|
||||||
|
begin
|
||||||
|
Result := i;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPaperSize.SetPaperName(const AName: string);
|
procedure TPaperSize.SetPaperName(const AName: string);
|
||||||
begin
|
begin
|
||||||
if SupportedPapers.IndexOf(aName)<>-1 then
|
if SupportedPapers.IndexOf(aName)<>-1 then
|
||||||
begin
|
begin
|
||||||
if aName<>PaperName then
|
if aName<>PaperName then
|
||||||
fOwnedPrinter.DoSetPaperName(aName)
|
begin
|
||||||
|
if fDefaultPapers then
|
||||||
|
FDefaultPaperIndex := IndexOfDefaultPaper(AName)
|
||||||
|
else
|
||||||
|
FOwnedPrinter.DoSetPaperName(aName)
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
|
raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
|
||||||
@ -873,16 +976,17 @@ begin
|
|||||||
|
|
||||||
if SupportedPapers.IndexOf(AName)<>-1 then
|
if SupportedPapers.IndexOf(AName)<>-1 then
|
||||||
begin
|
begin
|
||||||
Margins:=fOwnedPrinter.DoGetPaperRect(aName,TmpPaperRect);
|
|
||||||
|
if fDefaultPapers then
|
||||||
|
Margins := GetDefaultPaperRect(AName, TmpPaperRect)
|
||||||
|
else
|
||||||
|
Margins := fOwnedPrinter.DoGetPaperRect(aName,TmpPaperRect);
|
||||||
|
|
||||||
if Margins>=0 then
|
if Margins>=0 then
|
||||||
begin
|
Result := TmpPaperRect
|
||||||
Result := TmpPaperRect;
|
else
|
||||||
end
|
raise EPrinter.Create(Format('The paper "%s" has no defined rectangle ! ',[aName]));
|
||||||
else raise EPrinter.Create(Format('The paper "%s" has no defined rectangle ! ',[aName]));
|
|
||||||
{end else if (AName='') and (SupportedPapers.Count=0) then begin
|
|
||||||
DebugLn(['WARNING: TPaperSize.PaperRectOfName: printer has no paper rect. Using 1000,1000']);
|
|
||||||
Result.PhysicalRect:=Rect(0,0,1000,1000);
|
|
||||||
Result.WorkRect:=Result.PhysicalRect;}
|
|
||||||
end
|
end
|
||||||
else raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
|
else raise EPrinter.Create(Format('Paper "%s" not supported !',[aName]));
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user