-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
zint_lmf.pas
1093 lines (944 loc) · 25 KB
/
zint_lmf.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit zint_lmf;
// Source: http://bugs.freepascal.org/view.php?id=14333
{$mode delphi}{$H+}
interface
uses
Types,
Classes, SysUtils,
Graphics,FPCanvas, FPImage, syncobjs;
type
TlmfList = class;
TlmfImage=class(TGraphic)
private
forgX,forgY,
fWidth,fHeight:integer;
kx,ky:double;
fList:TlmfList;
fCrs:TCriticalSection;
protected
procedure AssignTo(Dest:TPersistent);override;
function GetWidth:integer;override;
procedure SetWidth(AVal:integer);override;
function GetHeight:integer;override;
procedure SetHeight(AVal:integer);override;
function GetEmpty:boolean;override;
function GetTransparent: Boolean; override;
procedure SetTransparent(Value: Boolean); override;
//procedure Erase;override;
function ScaleX(ax:integer):integer;
function ScaleY(ay:integer):integer;
public
constructor Create;override;
destructor Destroy;override;
procedure Clear;override;
procedure SaveToStream(Stream: TStream); override;
procedure LoadFromStream(Stream: TStream); override;
procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
property List:TlmfList read fList;
end;
TlmfList=class(TComponent)
private
fWidth,fHeight:integer;
public
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
function GetChildOwner: TComponent; override;
published
property Width:integer read fWidth write fWidth;
property Height:integer read fHeight write fHeight;
end;
TlmfObject=class(TComponent)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);virtual;abstract;
end;
TlmfAnchor=class(TlmfObject)
private
fPos:TPoint;
public
constructor Create(Ax,Ay:integer);virtual;
published
property px:integer read fPos.x write fpos.x;
property py:integer read fPos.y write fpos.y;
end;
TlmfMoveTo=class(TlmfAnchor)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfLineTo=class(TlmfAnchor)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfLine=class(TlmfAnchor)
private
fEndPos:TPoint;
public
constructor Create(x1,y1,x2,y2:integer);overload;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property px1:integer read fEndPos.x write fEndpos.x;
property py1:integer read fEndPos.y write fEndpos.y;
end;
TlmfText=class(TlmfAnchor)
private
fText:string;
// fHeight:integer;
// fStyle:TTextStyle;
protected
procedure DefineProperties(Filer: TFiler); override;
public
constructor Create(x,y:integer; const AText:string);overload;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Text:string read fText write fText;
// property Height:integer read fHeight write fHeight;
//property Style:TTextStyle read fTextStyle write fTextStyle;
end;
TlmfColor=class(TlmfAnchor)
private
fColor:TfpColor;
public
constructor Create(x,y:integer; AColor:TfpColor);overload;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property r:word read fColor.red write fColor.red;
property g:word read fColor.green write fColor.green;
property b:word read fColor.blue write fColor.blue;
property a:word read fColor.alpha write fColor.alpha;
end;
TlmfClip=class(TlmfObject)
private
fClip:TRect;
public
constructor Create(AClip:TRect);virtual;overload;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Left:integer read fClip.Left write fClip.Left;
property Top:integer read fClip.Top write fClip.Top;
property Right:integer read fClip.Right write fClip.Right;
property Bottom:integer read fClip.Bottom write fClip.Bottom;
end;
TlmfRect=class(TlmfClip)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfFillRect=class(TlmfRect)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfEllipse=class(TlmfClip)
public
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfFont=class(TlmfObject)
private
fFont:TFont;
fHeight,fRotation:integer;
fName:string;
public
constructor Create(AnOwner:TComponent);override;
destructor Destroy;override;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Font:TFont read fFont write fFont;
property Height:integer read fHeight write fHeight;
property Rotation:integer read fRotation write fRotation;
end;
TlmfBrush=class(TlmfObject)
private
fBrush:TBrush;
public
constructor Create(AnOwner:TComponent);override;
destructor Destroy;override;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Brush:TBrush read fBrush write fBrush;
end;
TlmfPen=class(TlmfObject)
private
fPen:TPen;
public
constructor Create(AnOwner:TComponent);override;
destructor Destroy;override;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Pen:TPen read fPen write fPen;
end;
TlmfGraph=class(TlmfClip)
private
fGraph:TPicture;
public
constructor Create(AnOwner:TComponent);override;
destructor Destroy;override;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Graph:TPicture read fGraph write fGraph;
end;
TlmfPolyline=class(TlmfRect)
private
pts:array of TPoint;
protected
procedure StorePoints(AStream:TStream);virtual;
procedure LoadPoints(AStream:TStream);virtual;
procedure DefineProperties(Afiler:TFiler);override;
public
constructor Create(Points:PPoint;NumPts:integer);overload;
destructor Destroy;override;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
end;
TlmfPolygon=class(TlmfPolyline)
private
fWinding:boolean;
public
constructor Create(Points:PPoint;NumPts:integer;Winding:boolean=false);overload;
procedure Action(fImage:TlmfImage;ACanvas:TCanvas);override;
published
property Winding:boolean read fWinding write fWinding;
end;
TlmfCanvas=class(TCanvas)
private
fClipRect:TRect;
fState:TCanvasState;
fImage:TlmfImage;
protected
procedure CreateFont;override;
procedure CreateBrush;override;
procedure CreatePen;override;
function DoCreateDefaultFont : TFPCustomFont; override;
function DoCreateDefaultPen : TFPCustomPen; override;
function DoCreateDefaultBrush : TFPCustomBrush; override;
procedure DoGetTextSize (text:string; var w,h:integer);override;
function DoAllowBrush (ABrush : TFPCustomBrush) : boolean; override;
procedure DoMoveTo(x, y: integer); override;
procedure DoLineTo(x, y: integer); override;
procedure DoLine(x1, y1, x2, y2: integer); override;
// procedure DoEllipseFill (const Bounds:TRect); override;
procedure DoEllipse (const Bounds:TRect); override;
procedure DoRectangleFill (Const Bounds:TRect); override;
procedure SetPixel(X,Y: Integer; Value: TColor); override;
procedure SetColor (x,y:integer; const Value:TFPColor); override;
function GetColor (x,y:integer) : TFPColor; override;
procedure SetClipRect(const AValue: TRect); override;
function GetClipRect:TRect; override;
procedure RequiredState(ReqState: TCanvasState); override;
procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect);override;
public
constructor Create(Almf:TlmfImage);
procedure TextOut (x,y:integer;const text:string); override; // already in fpcanvas
function TextExtent(const Text: string): TSize;override;
procedure TextRect(ARect: TRect; X, Y: integer; const Text: string;
const Style: TTextStyle); override;
procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); override;
procedure Rectangle(X1,Y1,X2,Y2: Integer); override; // already in fpcanvas
procedure Polyline(Points: PPoint; NumPts: Integer);override;
procedure Polygon(Points: PPoint; NumPts: Integer; Winding: boolean = False);override;
procedure Ellipse (x1,y1,x2,y2:integer); override;
end;
implementation
uses lcltype,lclintf;
constructor TlmfImage.Create;
begin
inherited Create;
fCrs:=syncobjs.TCriticalSection.Create;
fList:=TlmfList.Create(nil);
end;
destructor TlmfImage.Destroy;
begin
Clear;
fList.Free;
inherited Destroy;
fCrs.Free;
end;
procedure TlmfImage.AssignTo(Dest:TPersistent);
var
mf:TMemoryStream;
begin
if Dest is TlmfImage then
begin
mf:=TMemoryStream.Create;
try
mf.WriteComponent(fList);
mf.Position:=0;
mf.ReadComponent(TlmfImage(Dest).fList);
TlmfImage(Dest).fWidth:=fWidth;
TlmfImage(Dest).fHeight:=fHeight;
finally
mf.Free;
end;
end
else
inherited AssignTo(Dest);
end;
procedure TlmfImage.Clear;
var
i:integer;
item:TObject;
begin
fList.DestroyComponents;
(* for i:=fList.Count-1 downto 0 do
begin
item:=TObject(fList[i]);
fList.Delete(i);
item.Free;
end;*)
end;
function TlmfImage.GetWidth:integer;
begin
Result:=flist.fWidth;
end;
procedure TlmfImage.SetWidth(AVal:integer);
begin
if (AVal=fWidth) then exit;
fWidth:=AVal;
fList.fWidth:=fWidth;
Self.Modified:=true;
end;
function TlmfImage.GetHeight:integer;
begin
Result:=fList.fHeight;
end;
function TlmfImage.ScaleX(ax:integer):integer;
begin
Result:=fOrgX+trunc(ax*kx);
//if Result>Width then Result:=width;
end;
function TlmfImage.ScaleY(ay:integer):integer;
begin
Result:=fOrgY+trunc(ay*ky);
//if Result>height then Result:=height;
end;
procedure TlmfImage.SetHeight(AVal:integer);
begin
if (AVal=fHeight) then exit;
fHeight:=AVal;
fList.fHeight:=fHeight;
Modified:=true;
end;
function TlmfImage.GetEmpty:boolean;
begin
Result:=Assigned(fList) and (fList.ComponentCount>0);
end;
procedure TlmfImage.Draw(ACanvas: TCanvas; const Rect: TRect);
var
i:integer;
begin
fCrs.Acquire;
try
fOrgX:=Rect.Left;
fOrgY:=Rect.Top;
kx:=(Rect.Right-Rect.Left)/Width;
ky:=(Rect.Bottom-Rect.Top)/Height;
ACanvas.MoveTo(ScaleX(Rect.Left),ScaleY(Rect.Top));
for i:=0 to fList.ComponentCount-1 do
begin
TlmfObject(flist.Components[i]).Action(Self,ACanvas);
end;
finally
kx:=1;
ky:=1;
fCrs.Release;
end;
end;
function TlmfImage.GetTransparent: Boolean;
begin
Result:=true; // assume it is always
end;
procedure TlmfImage.SetTransparent(Value: Boolean);
begin
// nothing to do
end;
procedure TlmfImage.SaveToStream(Stream: TStream);
begin
Stream.WriteComponent(fList);
end;
procedure TlmfImage.LoadFromStream(Stream: TStream);
begin
Stream.ReadComponent(fList);
//Stream.
end;
// TlmfCanvas
constructor TlmfCanvas.Create(Almf:TlmfImage);
begin
fImage:=Almf;
inherited Create;
end;
procedure TlmfCanvas.RequiredState(ReqState: TCanvasState);
var
Needed: TCanvasState;
begin
Needed := ReqState - fState;
if Needed <> [] then
begin
if csHandleValid in Needed then
begin
RealizeAntialiasing;
Include(FState, csHandleValid);
end;
if csFontValid in Needed then
CreateFont;
if csPenValid in Needed then
begin
CreatePen;
if Pen.Style in [psDash, psDot, psDashDot, psDashDotDot]
then Include(Needed, csBrushValid);
end;
if csBrushValid in Needed then
CreateBrush;
end;
end;
// workaround
function TlmfCanvas.DoCreateDefaultFont : TFPCustomFont;
begin
Result:=TFont.Create;
Result.Name:='Sans';
Result.Size:=10;
TFont(Result).Orientation:=0;
end;
function TlmfCanvas.DoCreateDefaultPen : TFPCustomPen;
begin
Result:=TPen.Create;
TPen(Result).Color:=clBlack;
Tpen(Result).Style:=psSolid;
end;
function TlmfCanvas.DoCreateDefaultBrush : TFPCustomBrush;
begin
Result:=TBrush.Create;
Result.Style:=bsClear;
Tbrush(Result).Color:=clNone;
end;
procedure TlmfCanvas.DoMoveTo(x, y: integer);
var
item:TlmfMoveTo;
begin
item:=TlmfMoveTo.Create(x,y);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.DoLineTo(x, y: integer);
var
item:TlmfAnchor;
begin
RequiredState([csPenValid]);
item:=TlmfLineTo.Create(x,y);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.DoLine(x1, y1, x2, y2: integer);
var
item:TlmfAnchor;
begin
RequiredState([csPenValid]);
item:=TlmfLine.Create(x1,y1,x2,y2);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.DoEllipse (const Bounds:TRect);
var
item:TlmfEllipse;
begin
RequiredState([csPenValid,csBrushValid]);
item:=TlmfEllipse.Create(Bounds);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.TextOut (x,y:integer;const text:string);
var
item:TlmfText;
begin
RequiredState([csFontValid,csBrushValid]);
item:=TlmfText.Create(x,y,text);
fImage.fList.InsertComponent(item);
// item.fHeight:=Font.Height;
// fillchar(item.fStyle,sizeof(item.fStyle),0);
end;
procedure TlmfCanvas.TextRect(ARect: TRect; X, Y: integer; const Text: string;
const Style: TTextStyle);
var
item:TlmfText;
begin
RequiredState([csFontValid,csBrushValid]);
item:=TlmfText.Create(x,y,text);
fImage.fList.InsertComponent(item);
// item.fHeight:=Font.Height;
// item.fStyle:=Style;
end;
procedure TlmfCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic);
var
item:TlmfGraph;
begin
//RequiredState([csFontValid,csBrushValid]);
item:=TlmfGraph.Create(nil);
fImage.fList.InsertComponent(item);
item.fGraph.Assign(SrcGraphic);
item.fClip:=DestRect;
end;
procedure TlmfCanvas.CopyRect(const Dest: TRect; SrcCanvas: TCanvas;
const Source: TRect);
var
SH, SW, DH, DW: Integer;
item:TlmfGraph;
bmp:TBitmap;
Begin
if SrcCanvas= nil then exit;
SH := Source.Bottom - Source.Top;
SW := Source.Right - Source.Left;
if (SH=0) or (SW=0) then exit;
DH := Dest.Bottom - Dest.Top;
DW := Dest.Right - Dest.Left;
if (Dh=0) or (DW=0) then exit;
TlmfCanvas(SrcCanvas).RequiredState([csHandleValid]);
Changing;
RequiredState([csHandleValid]);
bmp:=TBitmap.Create;
try
bmp.SetSize(SW,SH);
bmp.Canvas.CopyRect(Rect(0,0,SW,SH),SrcCanvas,Source);
Self.StretchDraw(Dest,bmp); // this stores graphic
finally
bmp.Free;
end;
Changed;
end;
procedure TlmfCanvas.SetColor (x,y:integer; const Value:TFPColor);
var
item:TlmfAnchor;
begin
item:=TlmfColor.Create(x,y,Value);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.SetPixel(X,Y: Integer; Value: TColor);
begin
SetColor(x,y,TColorToFPColor(Value));
end;
function TlmfCanvas.GetColor (x,y:integer) : TFPColor;
begin
Result.alpha:=0;
Result.red:=0;
Result.green:=0;
Result.blue:=0;
end;
procedure TlmfCanvas.SetClipRect(const AValue: TRect);
var
item:TlmfObject;
begin
inherited SetClipRect(AValue);
fClipRect:=AValue;
item:=TlmfClip.Create(AValue);
fImage.fList.InsertComponent(item);
end;
function TlmfCanvas.GetClipRect:TRect;
begin
Result:=fClipRect;
end;
procedure TlmfCanvas.Rectangle(X1,Y1,X2,Y2: Integer);
var
item:TlmfObject;
begin
RequiredState([csPenValid,csBrushValid]); // this adds TlmfPen
item:=TlmfRect.Create(Rect(x1,y1,x2,y2));
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.DoRectangleFill (Const Bounds:TRect);
var
item:TlmfFillRect;
begin
RequiredState([csBrushValid,csPenvalid]); // this adds TlmfBrush, TlmfPen
item:=TlmfFillRect.Create(nil);
fImage.fList.InsertComponent(item);
end;
function TlmfCanvas.DoAllowBrush (ABrush : TFPCustomBrush) : boolean;
begin
Result:=true;
end;
procedure TlmfCanvas.CreateFont;
var
item:TlmfFont;
begin
item:=TlmfFont.Create(nil);
item.fRotation:=TFont(Font).Orientation;
item.Font.Assign(Font);
item.fHeight:=Font.Height;
item.fName:=Font.Name;
item.fRotation:=TFont(item.Font).Orientation;
//writems('Created font "%s" size=%d rot=%d',[item.Font.Name,item.Font.Size,TrotFont(item.Font).Rotation]);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.CreateBrush;
var
item:TlmfBrush;
begin
item:=TlmfBrush.Create(nil);
item.Brush.Assign(Brush);
fImage.fList.InsertComponent(item);
end;
procedure TlmfCanvas.CreatePen;
var
item:TlmfPen;
begin
item:=TlmfPen.Create(nil);
item.Pen.Assign(Pen);
fImage.fList.InsertComponent(item);
end;
type
TSafeObject=class(TObject)
Font:TFont;
ext:TSize;
str:string;
procedure MeasureExtent;
end;
procedure TSafeObject.MeasureExtent;
var
dc:HDC;
ofh:HFONT;
begin
dc:=CreateCompatibleDC(0);
try
try
ofh:=SelectObject(dc,Font.Handle);
GetTextExtentPoint(dc, PChar(str), Length(str), ext);
// writeln('Result.cx=',Result.cx,' Result.cy=',result.cy);
SelectObject(dc,ofh);
//
finally
DeleteDC(dc);
end
except
writeln('wrong string:',str);
end;
end;
function TlmfCanvas.TextExtent(const Text: string): TSize;
var
so:TSafeObject;
begin
Result.cX := 0;
Result.cY := 0;
if Text='' then exit;
RequiredState([csHandleValid,csFontValid]);
so:=TSafeObject.Create;
try
so.Font:=Self.Font;
so.Str:=Text;
TThread.Synchronize(nil,so.MeasureExtent);
Result:=so.ext;
finally
so.Free;
end;
(*Result.cx:=round(Result.cx*1200/96);
Result.cy:=round(Result.cy*1200/96);*)
end;
procedure TlmfCanvas.DoGetTextSize (text:string; var w,h:integer);
var
sz:TSize;
begin
sz:=TextExtent(Text);
w:=sz.cx;
h:=sz.cy;
end;
procedure TlmfCanvas.Polyline(Points: PPoint; NumPts: Integer);
var
item:TlmfPolyLine;
begin
Changing;
RequiredState([csHandleValid, csPenValid]);
item:=TlmfPolyline.Create(Points,NumPts);
item.fClip:=Self.ClipRect;
fImage.fList.InsertComponent(item);
Changed;
end;
procedure TlmfCanvas.Polygon(Points: PPoint; NumPts: Integer;
Winding: boolean = False);
var
item:TlmfPolygon;
begin
if NumPts<=0 then exit;
Changing;
RequiredState([csHandleValid, csBrushValid, csPenValid]);
item:=TlmfPolygon.Create(Points,NumPts);
item.fClip:=Self.ClipRect;
fImage.fList.InsertComponent(item);
Changed;
end;
procedure TlmfCanvas.Ellipse (x1,y1,x2,y2:integer);
begin
DoEllipse(Rect(x1,y1,x2,y2));
end;
// LMF list
procedure TlmfList.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
Proc(Components[i]);
end;
end;
function TlmfList.GetChildOwner: TComponent;
begin
Result:=self;
end;
/// LMF object
constructor TlmfAnchor.Create(Ax,Ay:integer);
begin
inherited Create(nil);
fPos.X:=Ax;
fPos.Y:=Ay;
end;
procedure TlmfMoveTo.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.MoveTo(fImage.ScaleX(fPos.X),fImage.ScaleY(fPos.Y));
end;
procedure TlmfLineTo.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.LineTo(fImage.ScaleX(fPos.X),fImage.ScaleY(fPos.Y));
end;
constructor TlmfLine.Create(x1,y1,x2,y2:integer);
begin
inherited Create(x1,y1);
fEndPos.X:=x2;
fEndPos.Y:=y2;
end;
procedure TlmfLine.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.Line(
fImage.ScaleX(fPos.X),
fImage.ScaleY(fPos.Y),
fImage.ScaleX(fEndPos.X),
fImage.ScaleY(fEndPos.Y));
end;
constructor TlmfText.Create(x,y:integer; const AText:string);
begin
inherited Create(x,y);
fText:=AText;
end;
procedure TlmfText.Action(fImage:TlmfImage;ACanvas:TCanvas);
var
fnt:TFont;
ofh:Hfont;
begin
(* if (fRotation<>0) then
begin
fnt:=CreateOrtFont(round(fImage.ky*fHeight),fRotation div 10,ACanvas.Font.PixelsPerInch);
Acanvas.Font.Assign(fnt);
Acanvas.Font.Name:='Arial';
{$message 'This is font-selection workaround'}
ofh:=SelectObject(ACanvas.Handle,fnt.Handle);
ACanvas.TextOut(fImage.ScaleX(fPos.X),fImage.ScaleY(fPos.Y),fText);
ofh:=SelectObject(ACanvas.Handle,ofh);
fnt.Free;
end
else
begin
ACanvas.Font.Height:=round(fImage.ky*fHeight);
ACanvas.TextOut(fImage.ScaleX(fPos.X),fImage.ScaleY(fPos.Y),fText);
end;*)
ACanvas.TextOut(fImage.ScaleX(fPos.X),fImage.ScaleY(fPos.Y),fText);
end;
procedure TlmfText.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
end;
// pixel mode
constructor TlmfColor.Create(x,y:integer; AColor:TfpColor);
begin
inherited Create(x,y);
fColor:=AColor;
end;
procedure TlmfColor.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.Colors[
fImage.ScaleX(fpos.x),
fImage.ScaleY(fpos.y)]:=fColor;
end;
// cliprect
constructor TlmfClip.Create(AClip:TRect);
begin
inherited Create(nil);
fClip:=AClip;
end;
procedure TlmfClip.Action(fImage:TlmfImage;ACanvas:TCanvas);
var
newClip:TRect;
begin
// reset the clipping
if (fClip.Left=0) and (fClip.Top=0) and (fClip.Right=MaxInt) and (fClip.Bottom=MaxInt) then
begin
// this clip rect have not to scale
ACanvas.Clipping:=false;
ACanvas.ClipRect:=fClip; // actually does clipping through virtualization
SelectClipRgn(ACanvas.Handle,0)
end
else
begin
newClip:=Rect(fImage.ScaleX(fClip.Left),fImage.ScaleY(fClip.Top),
fImage.Scalex(fClip.Right),fImage.ScaleY(fClip.Bottom));
ACanvas.ClipRect:=newClip; // actually does nothing
// this is real clipping
lclintf.IntersectClipRect(ACanvas.Handle,
newClip.Left,newClip.Top,newClip.Right,newClip.Bottom);
end;
end;
// rectangle
procedure TlmfRect.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
// ACanvas.Brush.Style:=bsClear;
ACanvas.Rectangle(fImage.ScaleX(fClip.Left),fImage.ScaleY(fClip.Top),
fImage.Scalex(fClip.Right),fImage.ScaleY(fClip.Bottom));
end;
procedure TlmfFillRect.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.FillRect(
fImage.ScaleX(fClip.Left),fImage.ScaleY(fClip.Top),
fImage.Scalex(fClip.Right),fImage.ScaleY(fClip.Bottom));
end;
procedure TlmfEllipse.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.Ellipse(
fImage.ScaleX(fClip.Left),
fImage.ScaleY(fClip.Top),
fImage.Scalex(fClip.Right),
fImage.ScaleY(fClip.Bottom));
end;
constructor TlmfFont.Create(AnOwner:TComponent);
begin
inherited Create(AnOwner);
fFont:=TFont.Create;
end;
destructor TlmfFont.Destroy;
begin
fFont.Free;
inherited Destroy;
end;
procedure TlmfFont.Action(fImage:TlmfImage;ACanvas:TCanvas);
var
AFont:TFont;
rot,ht:integer;
ofh:Hfont;
begin
rot:=fRotation;//TRotFont(fFont).Rotation;
Acanvas.Font.Assign(fFont);
ht:=abs(round(fImage.ky*fHeight));
if ht<=0 then ht:=1;
Acanvas.Font.Height:=-ht;
ACanvas.Font.Orientation:=rot;
end;
constructor TlmfBrush.Create(AnOwner:TComponent);
begin
inherited Create(AnOwner);
fBrush:=TBrush.Create;
end;
destructor TlmfBrush.Destroy;
begin
fBrush.Free;
inherited Destroy;
end;
procedure TlmfBrush.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.Brush.Assign(fBrush);
end;
constructor TlmfPen.Create(AnOwner:TComponent);
begin
inherited Create(AnOwner);
fPen:=TPen.Create;
end;
destructor TlmfPen.Destroy;
begin
fPen.Free;
inherited Destroy;
end;
procedure TlmfPen.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.Pen.Assign(fPen);
ACanvas.Pen.Width:=round(fImage.ky*fPen.Width);
end;
constructor TlmfGraph.Create(AnOwner:TComponent);
begin
inherited Create(AnOwner);
fGraph:=TPicture.Create;
end;
destructor TlmfGraph.Destroy;
begin
fGraph.Free;
inherited Destroy;
end;
procedure TlmfGraph.Action(fImage:TlmfImage;ACanvas:TCanvas);
begin
ACanvas.StretchDraw(
(*Rect(
fClip.Left,
fClip.Top,
fClip.Right,
fClip.Bottom)*)
Rect(
fImage.ScaleX(fClip.Left),
fImage.ScaleY(fClip.Top),