-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMiroRep.pas
194 lines (174 loc) · 4.48 KB
/
MiroRep.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
{*******************************************************}
{ }
{ Delphi Miro Utilities }
{ }
{ Copyright (c) 1997, 1998 IT LOGISTICA Srl }
{ }
{*******************************************************}
{ 10/11/98 Aggiunta Preview }
{*******************************************************}
unit MiroRep;
interface
uses Classes, NikShape,Controls, ListShape, Graphics;
type
TMiroRep = class(TComponent)
private
_iCount : integer; // conta i componenti presenti
NewObj : TNikShape;
FS : TFileStream;
aColl : TListShape;
bStartedDoc : boolean;
procedure ClearList;
public
procedure Preview(aCanvas : TCanvas);
constructor Create(AOwner : TComponent); overload;
constructor Create(AOwner : TComponent; const sPath : string); overload;
destructor Destroy; override;
function FindComponent(const sName : string) : TNikShape;
procedure Setta(const sName, sVal : string);
procedure Load(const sPath : string);
procedure Print;
procedure StartJob;
procedure EndJob;
end;
implementation
uses Printers, SysUtils{fmOpenRead};
procedure TMiroRep.Preview(aCanvas : TCanvas);
var
WmfCanvas: TMetafileCanvas;
Wmf : TMetafile;
a : integer;
aNik : TNikShape;
begin
if _iCount = 0 then exit;
try
Wmf := TMetafile.Create;
Wmf.Enhanced := True {False} ;
Wmf.Width := 800;
Wmf.Height := 600;
Wmf.MMWidth := 29600;
Wmf.MMHeight := 21000;
Wmf.Inch := 96;
// create the virtual canvas
WmfCanvas := TMetafileCanvas.CreateWithComment(Wmf, 0, 'MiroRep', 'Miro metafile');
try
for a := 0 to aColl.GetNumItems-1 do
begin
aNik := aColl.GetElement(a) as TNikShape;
if aNik <> nil then
(aNik as TNikShape).Paint2Canvas(WmfCanvas);
end;
finally
WmfCanvas.Free;
end;
// NB nel TMetaFile il contenuto e' trasferito solo dopo la TMetaFileCanvas.free!
aCanvas.StretchDraw (aCanvas.ClipRect, Wmf);
finally
Wmf.Free;
end;
end;
constructor TMiroRep.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
aColl := TListShape.Create;
bStartedDoc := False;
end;
constructor TMiroRep.Create(AOwner : TComponent; const sPath : string);
begin
inherited Create(AOwner);
aColl := TListShape.Create;
bStartedDoc := False;
Load(sPath);
end;
destructor TMiroRep.Destroy;
begin
aColl.Free;
inherited Destroy;
end;
procedure TMiroRep.Setta(const sName, sVal : string);
var aSh : TNikShape;
begin
aSh := FindComponent(sName);
if aSh = nil then exit;
aSh.Testo := sVal;
end;
function TMiroRep.FindComponent(const sName : string) : TNikShape;
var i : integer; aSh : TNikShape;
begin
Result:=nil;
for i:=1 to aColl.GetNumItems do
begin
aSh := aColl.GetElement(i);
if UpperCase(aSh.Nome) = UpperCase(sName) then
begin
Result := aSh;
exit;
end;
end;
if Result = nil then
raise Exception.Create('Campo non trovato '+sName);
end;
procedure TMiroRep.ClearList;
var i : integer;
begin
for i := 1 to aColl.GetNumItems do
aColl.KillItem(0); {successively removes first item to empty list}
end;
procedure TMiroRep.Load(const sPath : string);
var NewObj : TNikShape;
begin
// Pulisce la lista se c'era gia'
ClearList;
_iCount := 0;
try
FS := TFileStream.Create(sPath,fmOpenRead or fmShareDenyWrite);
except
raise Exception.Create('Fallita apertura file '+sPath);
end;
try
while FS.Position < FS.Size do
begin
NewObj := TNikShape.Create(Self);
FS.ReadComponent(NewObj);
inc(_iCount);
if NewObj.ImagePath <> '' then
NewObj.SetImage(NewObj.ImagePath);
// Setta le impostazioni della stampante
if NewObj.Shape = stSetup then
NewObj.SetDriverMode
else
aColl.AddToList(NewObj);
end;
finally
FS.Free;
end;
end;
procedure TMiroRep.StartJob;
begin
if not bStartedDoc then
begin
Printer.BeginDoc;
bStartedDoc := True;
end
else
Printer.NewPage;
end;
procedure TMiroRep.EndJob;
begin
bStartedDoc := False;
Printer.EndDoc;
end;
procedure TMiroRep.Print;
var
a : Integer; aNik : TNikShape;
begin
StartJob;
for a := 0 to aColl.GetNumItems-1 do
begin
aNik := aColl.GetElement(a) as TNikShape;
if aNik <> nil then
aNik.Print;
end;
// Printer.EndDoc;
end;
end.