-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Preview.pas
6911 lines (6424 loc) · 207 KB
/
Preview.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
{------------------------------------------------------------------------------}
{ }
{ Print Preview Components }
{ by Kambiz R. Khojasteh }
{ }
{ http://www.delphiarea.com }
{ }
{ TPrintPreview v5.95 }
{ TPaperPreview v2.20 }
{ TThumbnailPreview v2.12 }
{ }
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{ Use Synopse library to output preview as PDF document }
{ Get the library from http://www.synopse.info }
{------------------------------------------------------------------------------}
{.$DEFINE PDF_SYNOPSE}
{------------------------------------------------------------------------------}
{ Use dsPDF library to output preview as PDF document }
{ Get the newest library from http://delphistep.cis.si/dspdf.htm }
{------------------------------------------------------------------------------}
{.$DEFINE PDF_DSPDF}
{------------------------------------------------------------------------------}
{ Use wPDF library to output preview as PDF document }
{ Get the newest library from https://www.wpcubed.com/pdf/products/wpdf/ }
{------------------------------------------------------------------------------}
{.$DEFINE PDF_WPDF}
{------------------------------------------------------------------------------}
{ Use cairo library to output preview as PDF document }
{ Get the newest library from https://github.com/ProHolz/CairoDelphi }
{------------------------------------------------------------------------------}
{.$DEFINE PDF_CAIRO}
{------------------------------------------------------------------------------}
{ Register Components in IDE }
{------------------------------------------------------------------------------}
{.$DEFINE REGISTER}
unit Preview;
interface
uses
System.SysUtils, System.Classes,
Winapi.Windows, Winapi.Messages, Winapi.WinSpool,
Vcl.Graphics, Vcl.Controls,Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
Vcl.ComCtrls, Vcl.Menus, Vcl.Printers;
{------------------------------------------------------------------------------}
{ If you need transparent image printing, set AllowTransparentDIB to True. }
{ }
{ Note: Transparency on printers is not guaranteed. Instead, combine images }
{ as needed, and then draw the final image to the printer. }
{------------------------------------------------------------------------------}
var
AllowTransparentDIB: Boolean = False;
const
crHand = 10;
crGrab = 11; //pvg
type
EPrintPreviewError = class(Exception);
EPreviewLoadError = class(EPrintPreviewError);
EPDFLibraryError = class(EPrintPreviewError);
EPDFError = class(EPrintPreviewError);
{ TTemporaryFileStream }
TTemporaryFileStream = class(THandleStream)
public
constructor Create;
destructor Destroy; override;
end;
{ TIntegerList }
TIntegerList = class(TList)
private
function GetItems(Index: Integer): Integer;
procedure SetItems(Index: Integer; Value: Integer);
public
function Add(Value: Integer): Integer;
procedure Insert(Index: Integer; Value: Integer);
function Remove(Value: Integer): Integer;
function Extract(Value: Integer): Integer;
function First: Integer;
function Last: Integer;
function IndexOf(Value: Integer): Integer;
procedure Sort;
procedure SaveToStream(Stream: TStream);
procedure LoadFromStream(Stream: TStream);
property Items[Index: Integer]: Integer read GetItems write SetItems; default;
end;
{ TMetafileList }
TMetafileList = class;
TMetafileEntryState = (msInMemory, msInStorage, msDirty);
TMetafileEntryStates = set of TMetafileEntryState;
TMetafileEntry = class(TObject)
private
FOwner: TMetafileList;
FMetafile: TMetafile;
FStates: TMetafileEntryStates;
FOffset: Int64;
FSize: Int64;
TouchCount: Integer;
procedure MetafileChanged(Sender: TObject);
protected
constructor CreateInMemory(AOwner: TMetafileList; AMetafile: TMetafile);
constructor CreateInStorage(AOwner: TMetafileList;
const AOffset, ASize: Int64);
procedure CopyToMemory;
procedure CopyToStorage;
function IsMoreRequiredThan(Another: TMetafileEntry): Boolean;
procedure Touch;
property Owner: TMetafileList read FOwner;
property States: TMetafileEntryStates read FStates;
property Offset: Int64 read FOffset;
property Size: Int64 read FSize;
public
constructor Create(AOwner: TMetafileList);
destructor Destroy; override;
property Metafile: TMetafile read FMetafile;
end;
TSingleChangeEvent = procedure(Sender: TObject; Index: Integer) of object;
TMultipleChangeEvent = procedure(Sender: TObject; StartIndex, EndIndex: Integer) of object;
TMetafileList = class(TObject)
private
FEntries: TList;
FCachedEntries: TList;
FStorage: TStream;
FCacheSize: Integer;
FOnSingleChange: TSingleChangeEvent;
FOnMultipleChange: TMultipleChangeEvent;
function GetCount: Integer;
function GetItems(Index: Integer): TMetafileEntry;
function GetMetafiles(Index: Integer): TMetafile;
procedure SetCacheSize(Value: Integer);
protected
procedure Reset;
procedure ReduceCacheEntries(NumOfEntries: Integer);
function GetCachedEntry(Index: Integer): TMetafileEntry;
procedure EntryChanged(Entry: TMetafileEntry);
procedure DoSingleChange(Index: Integer);
procedure DoMultipleChange(StartIndex, EndIndex: Integer);
property Storage: TStream read FStorage;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Add(AMetafile: TMetafile): Integer;
procedure Insert(Index: Integer; AMetafile: TMetafile);
procedure Delete(Index: Integer);
procedure Exchange(Index1, Index2: Integer);
procedure Move(Index, NewIndex: Integer);
function LoadFromStream(Stream: TStream): Boolean;
procedure SaveToStream(Stream: TStream);
procedure LoadFromFile(const FileName: String);
procedure SaveToFile(const FileName: String);
property Count: Integer read GetCount;
property Items[Index: Integer]: TMetafileEntry read GetItems;
property Metafiles[Index: Integer]: TMetafile read GetMetafiles; default;
property CacheSize: Integer read FCacheSize write SetCacheSize;
property OnSingleChange: TSingleChangeEvent read FOnSingleChange write FOnSingleChange;
property OnMultipleChange: TMultipleChangeEvent read FOnMultipleChange write FOnMultipleChange;
end;
{ TPaperPreviewOptions }
TUpdateSeverity = (usNone, usRedraw, usRecreate);
TPaperPreviewChangeEvent = procedure(Sender: TObject;
Severity: TUpdateSeverity) of object;
TPaperPreviewOptions = class(TPersistent)
private
FPaperColor: TColor;
FBorderColor: TColor;
FBorderWidth: TBorderWidth;
FShadowColor: TColor;
FShadowWidth: TBorderWidth;
FCursor: TCursor;
FDragCursor: TCursor;
FGrabCursor: TCursor; //pvg
FPopupMenu: TPopupMenu;
FHint: String;
FOnChange: TPaperPreviewChangeEvent;
procedure SetPaperColor(Value: TColor);
procedure SetBorderColor(Value: TColor);
procedure SetBorderWidth(Value: TBorderWidth);
procedure SetShadowColor(Value: TColor);
procedure SetShadowWidth(Value: TBorderWidth);
procedure SetCursor(Value: TCursor);
procedure SetDragCursor(Value: TCursor);
procedure SetGrabCursor(Value: TCursor); //pvg
procedure SetPopupMenu(Value: TPopupMenu);
procedure SetHint(const Value: String);
protected
procedure DoChange(Severity: TUpdateSeverity);
public
constructor Create;
procedure Assign(Source: TPersistent); override;
procedure AssignTo(Dest: TPersistent); override;
procedure CalcDimensions(PaperWidth, PaperHeight: Integer;
out PaperRect, BoxRect: TRect);
procedure Draw(Canvas: TCanvas; const BoxRect: TRect);
property OnChange: TPaperPreviewChangeEvent read FOnChange write FOnChange;
published
property BorderColor: TColor read FBorderColor write SetBorderColor default clBlack;
property BorderWidth: TBorderWidth read FBorderWidth write SetBorderWidth default 1;
property Cursor: TCursor read FCursor write SetCursor default crDefault;
property DragCursor: TCursor read FDragCursor write SetDragCursor default crHand;
property GrabCursor: TCursor read FGrabCursor write SetGrabCursor default crGrab; //pvg
property Hint: String read FHint write SetHint;
property PaperColor: TColor read FPaperColor write SetPaperColor default clWhite;
property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;
property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnShadow;
property ShadowWidth: TBorderWidth read FShadowWidth write SetShadowWidth default 3;
end;
{ TPaperPreview }
TPaperPaintEvent = procedure(Sender: TObject; Canvas: TCanvas;
const Rect: TRect) of object;
TPaperPreview = class(TCustomControl)
private
FPreservePaperSize: Boolean;
FPaperColor: TColor;
FBorderColor: TColor;
FBorderWidth: TBorderWidth;
FShadowColor: TColor;
FShadowWidth: TBorderWidth;
FShowCaption: Boolean;
FAlignment: TAlignment;
FWordWrap: Boolean;
FCaptionHeight: Integer;
FOnResize: TNotifyEvent;
FOnPaint: TPaperPaintEvent;
FOnMouseEnter: TNotifyEvent;
FOnMouseLeave: TNotifyEvent;
FPageRect: TRect;
OffScreen: TBitmap;
IsOffScreenPrepared: Boolean;
IsOffScreenReady: Boolean;
LastVisibleRect: TRect;
LastVisiblePageRect: TRect;
PageCanvas: TCanvas;
procedure SetPaperWidth(Value: Integer);
function GetPaperWidth: Integer;
procedure SetPaperHeight(Value: Integer);
function GetPaperHeight: Integer;
function GetPaperSize: TPoint;
procedure SetPaperSize(const Value: TPoint);
procedure SetPaperColor(Value: TColor);
procedure SetBorderColor(Value: TColor);
procedure SetBorderWidth(Value: TBorderWidth);
procedure SetShadowColor(Value: TColor);
procedure SetShadowWidth(Value: TBorderWidth);
procedure SetShowCaption(Value: Boolean);
procedure SetAlignment(Value: TAlignment);
procedure SetWordWrap(Value: Boolean);
procedure UpdateCaptionHeight;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure BiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
protected
procedure Paint; override;
procedure DrawPage(Canvas: TCanvas); virtual;
function ActualWidth(Value: Integer): Integer; virtual;
function ActualHeight(Value: Integer): Integer; virtual;
function LogicalWidth(Value: Integer): Integer; virtual;
function LogicalHeight(Value: Integer): Integer; virtual;
procedure InvalidateAll; virtual;
property CaptionHeight: Integer read FCaptionHeight;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Invalidate; override;
function ClientToPaper(const Pt: TPoint): TPoint;
function PaperToClient(const Pt: TPoint): TPoint;
procedure SetBoundsEx(ALeft, ATop, APaperWidth, APaperHeight: Integer);
property PaperSize: TPoint read GetPaperSize write SetPaperSize;
property PageRect: TRect read FPageRect;
published
property Align;
property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
property BiDiMode;
property BorderColor: TColor read FBorderColor write SetBorderColor default clBlack;
property BorderWidth: TBorderWidth read FBorderWidth write SetBorderWidth default 1;
property Caption;
property Color;
property Cursor;
property DragCursor;
property DragMode;
property Font;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property PaperColor: TColor read FPaperColor write SetPaperColor default clWhite;
property PaperWidth: Integer read GetPaperWidth write SetPaperWidth;
property PaperHeight: Integer read GetPaperHeight write SetPaperHeight;
property PreservePaperSize: Boolean read FPreservePaperSize write FPreservePaperSize default True;
property ShadowColor: TColor read FShadowColor write SetShadowColor default clBtnShadow;
property ShadowWidth: TBorderWidth read FShadowWidth write SetShadowWidth default 3;
property ShowCaption: Boolean read FShowCaption write SetShowCaption default False;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property WordWrap: Boolean read FWordWrap write SetWordWrap default True;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
property OnResize: TNotifyEvent read FOnResize write FOnResize;
property OnPaint: TPaperPaintEvent read FOnPaint write FOnPaint;
end;
{ TPrintPreview}
TPDFDocumentInfo = class;
TThumbnailPreview = class;
TVertAlign = (vaTop, vaCenter, vaBottom); //rmk
THorzAlign = (haLeft, haCenter, haRight); //rmk
TGrayscaleOption = (gsPreview, gsPrint);
TGrayscaleOptions = set of TGrayscaleOption;
TPreviewState = (psReady, psCreating, psPrinting, psEditing, psReplacing,
psInserting, psLoading, psSaving, psSavingPDF, psSavingTIF);
TZoomState = (zsZoomOther, zsZoomToWidth, zsZoomToHeight, zsZoomToFit);
TUnits = (mmPixel, mmLoMetric, mmHiMetric, mmLoEnglish, mmHiEnglish, mmTWIPS, mmPoints);
TPaperType = (pLetter, pLetterSmall, pTabloid, pLedger, pLegal, pStatement,
pExecutive, pA3, pA4, pA4Small, pA5, pB4, pB5, pFolio, pQuatro, p10x14,
p11x17, pNote, pEnv9, pEnv10, pEnv11, pEnv12, pEnv14, pCSheet, pDSheet,
pESheet, pEnvDL, pEnvC5, pEnvC3, pEnvC4, pEnvC6, pEnvC65, pEnvB4, pEnvB5,
pEnvB6, pEnvItaly, pEnvMonarch, pEnvPersonal, pFanfoldUSStd, pFanfoldGermanStd,
pFanfoldGermanLegal, pB4ISO, pJapanesePostcard, p9x11, p10x11, p15x11,
pEnvInvite, pLetterExtra, pLegalExtra, pTabloidExtra, pA4Extra, pLetterTransverse,
pA4Transverse, pLetterExtraTransverse, pAPlus, pBPlus, pLetterPlus, pA4Plus,
pA5Transverse, pB5Transverse, pA3Extra, pA5Extra, pB5Extra, pA2, pA3Transverse,
pA3ExtraTransverse, pCustom);
TPageProcessingChoice = (pcAccept, pcIgnore, pcCancellAll);
TPreviewPageProcessingEvent = procedure(Sender: TObject; PageNo: Integer;
var Choice: TPageProcessingChoice) of object;
TPreviewPageDrawEvent = procedure(Sender: TObject; PageNo: Integer;
Canvas: TCanvas) of object;
TPreviewProgressEvent = procedure(Sender: TObject; Done, Total: Integer) of object;
TPrintPreview = class(TScrollBox)
private
FThumbnailViews: TList;
FPaperView: TPaperPreview;
FPaperViewOptions: TPaperPreviewOptions;
FPrintJobTitle: String;
FPageList: TMetafileList;
FPageCanvas: TCanvas;
FUnits: TUnits;
FDeviceExt: TPoint;
FLogicalExt: TPoint;
FPageExt: TPoint;
FOrientation: TPrinterOrientation;
FCurrentPage: Integer;
FPaperType: TPaperType;
FState: TPreviewState;
FZoom: Integer;
FZoomState: TZoomState;
FZoomSavePos: Boolean;
FZoomMin: Integer;
FZoomMax: Integer;
FZoomStep: Integer;
FLastZoom: Integer;
FUsePrinterOptions: Boolean;
FDirectPrint: Boolean;
FDirectPrinting: Boolean;
FDirectPrintPageCount: Integer;
FOldMousePos: TPoint;
FCanScrollHorz: Boolean;
FCanScrollVert: Boolean;
FIsDragging: Boolean;
FCanvasPageNo: Integer;
FFormName: String;
FVirtualFormName: String;
FAnnotation: Boolean;
FBackground: Boolean;
FGrayscale: TGrayscaleOptions;
FGrayBrightness: Integer;
FGrayContrast: Integer;
FShowPrintableArea: Boolean;
FPrintableAreaColor: TColor;
FPDFDocumentInfo: TPDFDocumentInfo;
FOnBeginDoc: TNotifyEvent;
FOnEndDoc: TNotifyEvent;
FOnNewPage: TNotifyEvent;
FOnEndPage: TNotifyEvent;
FOnChange: TNotifyEvent;
FOnStateChange: TNotifyEvent;
FOnPaperChange: TNotifyEvent;
FOnProgress: TPreviewProgressEvent;
FOnPageProcessing: TPreviewPageProcessingEvent;
FOnBeforePrint: TNotifyEvent;
FOnAfterPrint: TNotifyEvent;
FOnZoomChange: TNotifyEvent;
FOnAnnotation: TPreviewPageDrawEvent;
FOnBackground: TPreviewPageDrawEvent;
FOnPrintAnnotation: TPreviewPageDrawEvent;
FOnPrintBackground: TPreviewPageDrawEvent;
PageMetafile: TMetafile;
AnnotationMetafile: TMetafile;
BackgroundMetafile: TMetafile;
WheelAccumulator: Integer;
ReferenceDC: HDC;
procedure SetPaperViewOptions(Value: TPaperPreviewOptions);
procedure SetUnits(Value: TUnits);
procedure SetPaperType(Value: TPaperType);
function GetPaperWidth: Integer;
procedure SetPaperWidth(Value: Integer);
function GetPaperHeight: Integer;
procedure SetPaperHeight(Value: Integer);
procedure SetAnnotation(Value: Boolean);
procedure SetBackground(Value: Boolean);
procedure SetGrayscale(Value: TGrayscaleOptions);
procedure SetGrayBrightness(Value: Integer);
procedure SetGrayContrast(Value: Integer);
function GetCacheSize: Integer;
procedure SetCacheSize(Value: Integer);
function GetFormName: String;
procedure SetFormName(const Value: String);
procedure SetPDFDocumentInfo(Value: TPDFDocumentInfo);
function GetPageBounds: TRect;
function GetPrinterPageBounds: TRect;
function GetPrinterPhysicalPageBounds: TRect;
procedure SetOrientation(Value: TPrinterOrientation);
procedure SetZoomState(Value: TZoomState);
procedure SetZoom(Value: Integer);
procedure SetZoomMin(Value: Integer);
procedure SetZoomMax(Value: Integer);
procedure SetCurrentPage(Value: Integer);
function GetTotalPages: Integer;
function GetPages(PageNo: Integer): TMetafile;
function GetCanvas: TCanvas;
function GetPrinterInstalled: Boolean;
function GetPrinter: TPrinter;
procedure SetShowPrintableArea(Value: Boolean);
procedure SetPrintableAreaColor(Value: TColor);
procedure SetDirectPrint(Value: Boolean);
function GetIsDummyFormName: Boolean;
function GetSystemDefaultUnits: TUnits;
function GetUserDefaultUnits: TUnits;
function IsZoomStored: Boolean;
procedure PaperClick(Sender: TObject);
procedure PaperDblClick(Sender: TObject);
procedure PaperMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure PaperMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure PaperMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure PaperViewOptionsChanged(Sender: TObject; Severity: TUpdateSeverity);
procedure PagesChanged(Sender: TObject; PageStartIndex, PageEndIndex: Integer);
procedure PageChanged(Sender: TObject; PageIndex: Integer);
procedure PaintPage(Sender: TObject; Canvas: TCanvas; const Rect: TRect);
procedure CNKeyDown(var Message: TWMKey); message CN_KEYDOWN;
procedure WMMouseWheel(var Message: TMessage); message WM_MOUSEWHEEL;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMHScroll(var Message: TWMScroll); message WM_HSCROLL;
procedure WMVScroll(var Message: TWMScroll); message WM_VSCROLL;
protected
procedure Loaded; override;
procedure Resize; override;
procedure DoPaperChange; virtual;
procedure DoAnnotation(PageNo: Integer); virtual;
procedure DoBackground(PageNo: Integer); virtual;
procedure DoProgress(Done, Total: Integer); virtual;
function DoPageProcessing(PageNo: Integer): TPageProcessingChoice; virtual;
procedure ChangeState(NewState: TPreviewState);
procedure PreviewPage(PageNo: Integer; Canvas: TCanvas; const Rect: TRect); virtual;
procedure PrintPage(PageNo: Integer; Canvas: TCanvas; const Rect: TRect); virtual;
function FindPaperTypeBySize(APaperWidth, APaperHeight: Integer): TPaperType;
function FindPaperTypeByID(ID: Integer): TPaperType;
function GetPaperTypeSize(APaperType: TPaperType;
out APaperWidth, APaperHeight: Integer; OutUnits: TUnits): Boolean;
procedure SetPaperSize(AWidth, AHeight: Integer);
procedure SetPaperSizeOrientation(AWidth, AHeight: Integer;
AOrientation: TPrinterOrientation);
procedure ResetPrinterDC;
procedure InitializePrinting; virtual;
procedure FinalizePrinting(Succeeded: Boolean); virtual;
function GetVisiblePageRect: TRect;
procedure SetVisiblePageRect(const Value: TRect);
procedure UpdateZoomEx(X, Y: Integer); virtual;
function CalculateViewSize(const Space: TPoint): TPoint; virtual;
procedure UpdateExtends; virtual;
procedure CreateMetafileCanvas(out AMetafile: TMetafile; out ACanvas: TCanvas); virtual;
procedure CloseMetafileCanvas(var AMetafile: TMetafile; var ACanvas: TCanvas); virtual;
procedure CreatePrinterCanvas(out ACanvas: TCanvas); virtual;
procedure ClosePrinterCanvas(var ACanvas: TCanvas); virtual;
procedure ScaleCanvas(ACanvas: TCanvas); virtual;
public
function HorzPixelsPerInch: Integer; virtual;
function VertPixelsPerInch: Integer; virtual;
protected
procedure RegisterThumbnailViewer(ThumbnailView: TThumbnailPreview); virtual;
procedure UnregisterThumbnailViewer(ThumbnailView: TThumbnailPreview); virtual;
procedure RebuildThumbnails; virtual;
procedure UpdateThumbnails(StartIndex, EndIndex: Integer); virtual;
procedure RepaintThumbnails(StartIndex, EndIndex: Integer); virtual;
procedure RecolorThumbnails(OnlyGrays: Boolean); virtual;
procedure SyncThumbnail; virtual;
function LoadPageInfo(Stream: TStream): Boolean; virtual;
procedure SavePageInfo(Stream: TStream); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ConvertPoints(var Points; NumPoints: Integer; InUnits, OutUnits: TUnits);
function ConvertXY(X, Y: Integer; InUnits, OutUnits: TUnits): TPoint;
function ConvertX(X: Integer; InUnits, OutUnits: TUnits): Integer;
function ConvertY(Y: Integer; InUnits, OutUnits: TUnits): Integer;
function ConvertRect(Rec: TRect; InUnits: TUnits; OutUnits: TUnits): TRect;
function BoundsFrom(AUnits: TUnits; ALeft, ATop, AWidth, AHeight: Integer): TRect;
function RectFrom(AUnits: TUnits; ALeft, ATop, ARight, ABottom: Integer): TRect;
function PointFrom(AUnits: TUnits; X, Y: Integer): TPoint;
function XFrom(AUnits: TUnits; X: Integer): Integer;
function YFrom(AUnits: TUnits; Y: Integer): Integer;
function ScreenToPreview(X, Y: Integer): TPoint;
function PreviewToScreen(X, Y: Integer): TPoint;
function ScreenToPaper(const Pt: TPoint): TPoint;
function PaperToScreen(const Pt: TPoint): TPoint;
function ClientToPaper(const Pt: TPoint): TPoint;
function PaperToClient(const Pt: TPoint): TPoint;
function PaintGraphic(X, Y: Integer; Graphic: TGraphic): TPoint;
function PaintGraphicEx(const Rect: TRect; Graphic: TGraphic;
Proportinal, ShrinkOnly, Center: Boolean): TRect;
function PaintGraphicEx2(const Rect: TRect; Graphic: TGraphic; //rmk
VertAlign: TVertAlign; HorzAlign: THorzAlign): TRect; //rmk
function PaintWinControl(X, Y: Integer; WinControl: TWinControl): TPoint;
function PaintWinControlEx(const Rect: TRect; WinControl: TWinControl;
Proportinal, ShrinkOnly, Center: Boolean): TRect;
function PaintWinControlEx2(const Rect: TRect; WinControl: TWinControl;
VertAlign: TVertAlign; HorzAlign: THorzAlign): TRect;
function PaintRichText(const Rect: TRect; RichEdit: TCustomRichEdit; MaxPages: Integer; pOffset: PInteger = nil): Integer; overload;
function PaintRichText(const Rect: TRect; RichWnd: HWND; MaxPages: Integer; pOffset: PInteger = nil): Integer; overload;
function GetRichTextRect(var Rect: TRect; RichEdit: TCustomRichEdit; pOffset: PInteger = nil): Integer; overload;
function GetRichTextRect(var Rect: TRect; RichWnd: HWND; pOffset: PInteger): Integer; overload;
procedure Clear;
function Delete(PageNo: Integer): Boolean;
function Move(PageNo, NewPageNo: Integer): Boolean;
function Exchange(PageNo1, PageNo2: Integer): Boolean;
function BeginReplace(PageNo: Integer): Boolean;
procedure EndReplace(Cancel: Boolean = False);
function BeginEdit(PageNo: Integer): Boolean;
procedure EndEdit(Cancel: Boolean = False);
function BeginInsert(PageNo: Integer): Boolean;
procedure EndInsert(Cancel: Boolean = False);
function BeginAppend: Boolean;
procedure EndAppend(Cancel: Boolean = False);
procedure BeginDoc;
procedure EndDoc;
procedure NewPage;
procedure Print;
procedure PrintPages(FromPage, ToPage: Integer);
procedure PrintPagesEx(Pages: TIntegerList);
procedure UpdateZoom;
procedure UpdateAnnotation;
procedure UpdateBackground;
procedure SetPrinterOptions;
procedure GetPrinterOptions;
procedure SetPageSetupParameters(PageSetupDialog: TPageSetupDialog);
function GetPageSetupParameters(PageSetupDialog: TPageSetupDialog): TRect;
function FetchFormNames(FormNames: TStrings): Boolean;
function GetFormSize(const AFormName: String; out FormWidth, FormHeight: Integer): Boolean;
function AddNewForm(const AFormName: String; FormWidth, FormHeight: DWORD): Boolean;
function RemoveForm(const AFormName: String): Boolean;
procedure DrawPage(PageNo: Integer; Canvas: TCanvas; const Rect: TRect; Gray: Boolean); virtual;
procedure LoadFromStream(Stream: TStream);
procedure SaveToStream(Stream: TStream);
procedure LoadFromFile(const FileName: String);
procedure SaveToFile(const FileName: String);
procedure SaveAsTIF(const FileName: String);
function CanSaveAsTIF: Boolean;
procedure SaveAsPDF(const FileName: String);
function CanSaveAsPDF: Boolean;
function IsPaperCustom: Boolean;
function IsPaperRotated: Boolean;
property Canvas: TCanvas read GetCanvas;
property CanvasPageNo: Integer read FCanvasPageNo;
property TotalPages: Integer read GetTotalPages;
property State: TPreviewState read FState;
property PageSize: TPoint read FPageExt;
property PageDevicePixels: TPoint read FDeviceExt;
property PageLogicalPixels: TPoint read FLogicalExt;
property PageBounds: TRect read GetPageBounds;
property PrinterPageBounds: TRect read GetPrinterPageBounds;
property PrinterPhysicalPageBounds: TRect read GetPrinterPhysicalPageBounds;
property PrinterInstalled: Boolean read GetPrinterInstalled;
property Printer: TPrinter read GetPrinter;
property PaperViewControl: TPaperPreview read FPaperView;
property CurrentPage: Integer read FCurrentPage write SetCurrentPage;
property FormName: String read GetFormName write SetFormName;
property IsDummyFormName: Boolean read GetIsDummyFormName;
property SystemDefaultUnits: TUnits read GetSystemDefaultUnits;
property UserDefaultUnits: TUnits read GetUserDefaultUnits;
property CanScrollHorz: Boolean read FCanScrollHorz;
property CanScrollVert: Boolean read FCanScrollVert;
property Pages[PageNo: Integer]: TMetafile read GetPages;
published
property Align default alClient;
property Annotation: Boolean read FAnnotation write SetAnnotation default False;
property Background: Boolean read FBackground write SetBackground default False;
property CacheSize: Integer read GetCacheSize write SetCacheSize default 10;
property DirectPrint: Boolean read FDirectPrint write SetDirectPrint default False;
property Grayscale: TGrayscaleOptions read FGrayscale write SetGrayscale default [];
property GrayBrightness: Integer read FGrayBrightness write SetGrayBrightness default 0;
property GrayContrast: Integer read FGrayContrast write SetGrayContrast default 0;
property Units: TUnits read FUnits write SetUnits default mmHiMetric;
property Orientation: TPrinterOrientation read FOrientation write SetOrientation default poPortrait;
property PaperType: TPaperType read FPaperType write SetPaperType default pA4;
property PaperView: TPaperPreviewOptions read FPaperViewOptions write SetPaperViewOptions;
property PaperWidth: Integer read GetPaperWidth write SetPaperWidth stored IsPaperCustom;
property PaperHeight: Integer read GetPaperHeight write SetPaperHeight stored IsPaperCustom;
property ParentFont default False;
property PDFDocumentInfo: TPDFDocumentInfo read FPDFDocumentInfo write SetPDFDocumentInfo;
property PrintableAreaColor: TColor read FPrintableAreaColor write SetPrintableAreaColor default clSilver;
property PrintJobTitle: String read FPrintJobTitle write FPrintJobTitle;
property ShowPrintableArea: Boolean read fShowPrintableArea write SetShowPrintableArea default False;
property TabStop default True;
property UsePrinterOptions: Boolean read FUsePrinterOptions write FUsePrinterOptions default False;
property ZoomState: TZoomState read FZoomState write SetZoomState default zsZoomToFit;
property Zoom: Integer read FZoom write SetZoom stored IsZoomStored;
property ZoomMin: Integer read FZoomMin write SetZoomMin default 10;
property ZoomMax: Integer read FZoomMax write SetZoomMax default 1000;
property ZoomSavePos: Boolean read FZoomSavePos write FZoomSavePos default True;
property ZoomStep: Integer read FZoomStep write FZoomStep default 10;
property OnBeginDoc: TNotifyEvent read FOnBeginDoc write FOnBeginDoc;
property OnEndDoc: TNotifyEvent read FOnEndDoc write FOnEndDoc;
property OnNewPage: TNotifyEvent read FOnNewPage write FOnNewPage;
property OnEndPage: TNotifyEvent read FOnEndPage write FOnEndPage;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnStateChange: TNotifyEvent read FOnStateChange write FOnStateChange;
property OnZoomChange: TNotifyEvent read FOnZoomChange write FOnZoomChange;
property OnPaperChange: TNotifyEvent read FOnPaperChange write FOnPaperChange;
property OnProgress: TPreviewProgressEvent read FOnProgress write FOnProgress;
property OnPageProcessing: TPreviewPageProcessingEvent read FOnPageProcessing write FOnPageProcessing;
property OnBeforePrint: TNotifyEvent read FOnBeforePrint write FOnBeforePrint;
property OnAfterPrint: TNotifyEvent read FOnAfterPrint write FOnAfterPrint;
property OnAnnotation: TPreviewPageDrawEvent read FOnAnnotation write FOnAnnotation;
property OnBackground: TPreviewPageDrawEvent read FOnBackground write FOnBackground;
property OnPrintAnnotation: TPreviewPageDrawEvent read FOnPrintAnnotation write FOnPrintAnnotation;
property OnPrintBackground: TPreviewPageDrawEvent read FOnPrintBackground write FOnPrintBackground;
end;
{ TThumbnailDragObject }
TThumbnailDragObject = class(TDragControlObject)
private
FDragImages: TDragImageList;
FPageNo: Integer;
FDropAfter: Boolean;
protected
function GetDragImages: TDragImageList; override;
function GetDragCursor(Accepted: Boolean; X, Y: Integer): TCursor; override;
public
constructor Create(AControl: TThumbnailPreview; APageNo: Integer); reintroduce;
destructor Destroy; override;
procedure HideDragImage; override;
procedure ShowDragImage; override;
property PageNo: Integer read FPageNo;
property DropAfter: Boolean read FDropAfter write FDropAfter;
end;
{ TThumbnailPreview }
TThumbnailGrayscale = (tgsPreview, tgsNever, tgsAlways);
TThumbnailMarkerOption = (moMove, moSizeTopLeft, moSizeTopRight,
moSizeBottomLeft, moSizeBottomRight);
TThumbnailMarkerAction = (maNone, maMove, maResize);
TPageNotifyEvent = procedure(Sender: TObject; PageNo: Integer) of object;
TPageInfoTipEvent = procedure(Sender: TObject; PageNo: Integer;
var InfoTip: String) of object;
TPageThumbnailDrawEvent = procedure(Sender: TObject; PageNo: Integer;
Canvas: TCanvas; const Rect: TRect; var DefaultDraw: Boolean) of object;
TThumbnailPreview = class(TCustomListView)
private
FZoom: Integer;
FMarkerColor: TColor;
FSpacingHorizontal: Integer;
FSpacingVertical: Integer;
FGrayscale: TThumbnailGrayscale;
FIsGrayscaled: Boolean;
FPrintPreview: TPrintPreview;
FPaperViewOptions: TPaperPreviewOptions;
FCurrentIndex: Integer;
FAllowReorder: Boolean;
FDropTarget: Integer;
FDisableTheme: Boolean;
FOnPageBeforeDraw: TPageThumbnailDrawEvent;
FOnPageAfterDraw: TPageThumbnailDrawEvent;
FOnPageInfoTip: TPageInfoTipEvent;
FOnPageClick: TPageNotifyEvent;
FOnPageDblClick: TPageNotifyEvent;
FOnPageSelect: TPageNotifyEvent;
FOnPageUnselect: TPageNotifyEvent;
PageRect, BoxRect: TRect;
Page: TBitmap;
CursorPageNo: Integer;
DefaultDragObject: TThumbnailDragObject;
MarkerRect, UpdatingMarkerRect: TRect;
MarkerOfs, MarkerPivotPt: TPoint;
MarkerAction: TThumbnailMarkerAction;
MarkerDragging: Boolean;
procedure SetZoom(Value: Integer);
procedure SetMarkerColor(Value: TColor);
procedure SetSpacingHorizontal(Value: Integer);
procedure SetSpacingVertical(Value: Integer);
procedure SetGrayscale(Value: TThumbnailGrayscale);
procedure SetPrintPreview(Value: TPrintPreview);
procedure SetPaperViewOptions(Value: TPaperPreviewOptions);
procedure PaperViewOptionsChanged(Sender: TObject; Severity: TUpdateSeverity);
procedure SetCurrentIndex(Index: Integer);
function GetSelected: Integer;
procedure SetSelected(Value: Integer);
procedure SetDisableTheme(Value: Boolean);
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure WMSetCursor(var Message: TWMSetCursor); message WM_SETCURSOR;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure ApplySpacing; virtual;
procedure InsertMark(Index: Integer; After: Boolean);
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Click; override;
procedure DblClick; override;
function GetPopupMenu: TPopupMenu; override;
function OwnerDataFetch(Item: TListItem; Request: TItemRequest): Boolean; override;
function OwnerDataHint(StartIndex, EndIndex: Integer): Boolean; override;
function IsCustomDrawn(Target: TCustomDrawTarget; Stage: TCustomDrawStage): Boolean; override;
function CustomDrawItem(Item: TListItem; State: TCustomDrawState;
Stage: TCustomDrawStage): Boolean; override;
procedure Change(Item: TListItem; Change: Integer); override;
procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState;
var Accept: Boolean); override;
procedure DoStartDrag(var DragObject: TDragObject); override;
procedure DoEndDrag(Target: TObject; X, Y: Integer); override;
procedure RebuildThumbnails;
procedure UpdateThumbnails(StartIndex, EndIndex: Integer);
procedure RepaintThumbnails(StartIndex, EndIndex: Integer);
procedure RecolorThumbnails;
procedure InvalidateMarker(Rect: TRect);
function GetMarkerArea: TRect;
procedure SetMarkerArea(const Value: TRect);
property CurrentIndex: Integer read FCurrentIndex write SetCurrentIndex;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DragDrop(Source: TObject; X, Y: Integer); override;
function PageAtCursor: Integer;
function PageAt(X, Y: Integer): Integer;
procedure GetSelectedPages(Pages: TIntegerList);
procedure SetSelectedPages(Pages: TIntegerList);
procedure DeleteSelected; override;
procedure PrintSelected; virtual;
property IsGrayscaled: Boolean read FIsGrayscaled;
property Selected: Integer read GetSelected write SetSelected;
property DropTarget: Integer read FDropTarget;
published
property Align default alLeft;
property AllowReorder: Boolean read FAllowReorder write FAllowReorder default False;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Color;
property Constraints;
property Ctl3D;
property DisableTheme: Boolean read FDisableTheme write SetDisableTheme default False;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FlatScrollBars;
property Grayscale: TThumbnailGrayscale read FGrayscale write SetGrayscale default tgsPreview;
property HideSelection;
property HotTrack;
property HotTrackStyles;
property HoverTime;
property IconOptions;
property MarkerColor: TColor read FMarkerColor write SetMarkerColor default clBlue;
property MultiSelect;
property PaperView: TPaperPreviewOptions read FPaperViewOptions write SetPaperViewOptions;
property ParentColor default True;
property ParentBiDiMode;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property PrintPreview: TPrintPreview read FPrintPreview write SetPrintPreview;
property ShowHint;
property SpacingHorizontal: Integer read FSpacingHorizontal write SetSpacingHorizontal default 8;
property SpacingVertical: Integer read FSpacingVertical write SetSpacingVertical default 8;
property TabOrder;
property TabStop default True;
property Visible;
property Zoom: Integer read FZoom write SetZoom default 10;
property OnClick;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnDragDrop;
property OnDragOver;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnPageBeforeDraw: TPageThumbnailDrawEvent read FOnPageBeforeDraw write FOnPageBeforeDraw;
property OnPageAfterDraw: TPageThumbnailDrawEvent read FOnPageAfterDraw write FOnPageAfterDraw;
property OnPageInfoTip: TPageInfoTipEvent read FOnPageInfoTip write FOnPageInfoTip;
property OnPageClick: TPageNotifyEvent read FOnPageClick write FOnPageClick;
property OnPageDblClick: TPageNotifyEvent read FOnPageDblClick write FOnPageDblClick;
property OnPageSelect: TPageNotifyEvent read FOnPageSelect write FOnPageSelect;
property OnPageUnselect: TPageNotifyEvent read FOnPageUnselect write FOnPageUnselect;
end;
{ TPDFDocumentInfo }
TPDFDocumentInfo = class(TPersistent)
private
FProducer: AnsiString;
FCreator: AnsiString;
FAuthor: AnsiString;
FSubject: AnsiString;
FTitle: AnsiString;
FKeywords: AnsiString;
public
procedure Assign(Source: TPersistent); override;
published
property Producer: AnsiString read FProducer write FProducer;
property Creator: AnsiString read FCreator write FCreator;
property Author: AnsiString read FAuthor write FAuthor;
property Subject: AnsiString read FSubject write FSubject;
property Title: AnsiString read FTitle write FTitle;
property Keywords: AnsiString read FKeywords write FKeywords;
end;
{$IFDEF PDF_DSPDF}
{ TdsPDF }
TdsPDF = class(TObject)
private
Handle: HMODULE;
pBeginDoc: function(FileName: PAnsiChar): Integer; stdcall;
pEndDoc: function: Integer; stdcall;
pNewPage: function: Integer; stdcall;
pPrintPageMemory: function(Buffer: Pointer; BufferSize: Integer): Integer; stdcall;
pPrintPageFile: function(FileName: PAnsiChar): Integer; stdcall;
pSetParameters: function(OffsetX, OffsetY: Integer; ConverterX, ConverterY: Double): Integer; stdcall;
pSetPage: function(PageSize, Orientation, Width, Height: Integer): Integer; stdcall;
pSetDocumentInfo: function(What: Integer; Value: PAnsiChar): Integer; stdcall;
function PDFPageSizeOf(PaperType: TPaperType): Integer;
public
constructor Create; virtual;
destructor Destroy; override;
function Exists: Boolean;
procedure SetDocumentInfoEx(Info: TPDFDocumentInfo);
function SetDocumentInfo(What: Integer; const Value: AnsiString): Integer;
function SetPage(PaperType: TPaperType; Orientation: TPrinterOrientation; mmWidth, mmHeight: Integer): Integer;
function SetParameters(OffsetX, OffsetY: Integer; const ConverterX, ConverterY: Double): Integer;
function BeginDoc(const FileName: AnsiString): Integer;
function EndDoc: Integer;
function NewPage: Integer;
function RenderMemory(Buffer: Pointer; BufferSize: Integer): Integer;
function RenderFile(const FileName: AnsiString): Integer;
function RenderMetaFile(Metafile: TMetafile): Integer;
end;
{$ENDIF}
{ GDIPlusSubset }
TGDIPlusSubset = class(TObject)
private
Handle: HMODULE;
Token: ULONG;
ThreadToken: ULONG;
pUnhook: Pointer;
protected
GdiplusStartup: function(out Token: ULONG; Input, Output: Pointer): HRESULT; stdcall;
GdiplusShutdown: procedure(Token: ULONG); stdcall;
GdipGetDpiX: function(Graphics: Pointer; out Resolution: Single): HRESULT; stdcall;
GdipGetDpiY: function(Graphics: Pointer; out Resolution: Single): HRESULT; stdcall;
GdipDrawImageRectRect: function(Graphics, Image: Pointer;
dstX, dstY, dstWidth, dstHeight, srcX, srcY, srcWidth, srcHeight: Single;
SrcUnit: Integer; ImageAttributes: Pointer; Callback: Pointer;
CallbackData: Pointer): HRESULT; stdcall;
GdipCreateFromHDC: function(hDC: HDC; out Graphics: Pointer): HRESULT; stdcall;
GdipGetImageGraphicsContext: function(Image: Pointer; out Graphics: Pointer): HRESULT; stdcall;
GdipDeleteGraphics: function(Graphics: Pointer): HRESULT; stdcall;
GdipCreateMetafileFromEmf: function(hEMF: HENHMETAFILE; DeleteEMF: BOOL; out Metafile: Pointer): HRESULT; stdcall;
GdipCreateBitmapFromScan0: function(Width, Height: Integer; Stride: Integer;
Format: Integer; scan0: PBYTE; out Bitmap: Pointer): HRESULT; stdcall;
GdipDisposeImage: function(Image: Pointer): HRESULT; stdcall;
GdipBitmapSetResolution: function(Bitmap: Pointer; dpiX, dpiY: Single): HRESULT; stdcall;
GdipGetImageHorizontalResolution: function(Image: Pointer; out Resolution: Single): HRESULT; stdcall;
GdipGetImageVerticalResolution: function(Image: Pointer; out Resolution: Single): HRESULT; stdcall;
GdipGetImageWidth: function(Image: Pointer; out Width: UINT): HRESULT; stdcall;
GdipGetImageHeight: function(Image: Pointer; out Height: UINT): HRESULT; stdcall;
GdipGraphicsClear: function(Graphics: Pointer; Color: UINT): HRESULT; stdcall;
GdipGetImageEncodersSize: function(out NumEncoders, Size: UINT): HRESULT; stdcall;
GdipGetImageEncoders: function(NumEncoders, Size: UINT; Encoders: Pointer): HRESULT; stdcall;
GdipSaveImageToFile: function(Image: Pointer; Filename: PWideChar;
const clsidEncoder: TGUID; EncoderParams: Pointer): HRESULT; stdcall;
GdipSaveAddImage: function(Image, NewImage: Pointer; EncoderParams: Pointer): HRESULT; stdcall;
protected
function CteateBitmap(Metafile: TMetafile; BackColor: TColor): Pointer;
function GetEncoderClsid(const MimeType: WideString; out Clsid: TGUID): Boolean;
public
constructor Create; virtual;
destructor Destroy; override;
function Exists: Boolean;
procedure Draw(Canvas: TCanvas; const Rect: TRect; Metafile: TMetafile);
function MultiFrameBegin(const FileName: WideString;
FirstPage: TMetafile; BackColor: TColor): Pointer;
procedure MultiFrameNext(MF: Pointer;
NextPage: TMetafile; BackColor: TColor);
procedure MultiFrameEnd(MF: Pointer);
end;
TPaperSizeInfo = record
ID: SmallInt;
Width, Height: Integer;
Units: TUnits;
end;
const
// Paper Sizes
PaperSizes: array[TPaperType] of TPaperSizeInfo = (
(ID: DMPAPER_LETTER; Width: 08500; Height: 11000; Units: mmHiEnglish),
(ID: DMPAPER_LETTER; Width: 08500; Height: 11000; Units: mmHiEnglish),
(ID: DMPAPER_TABLOID; Width: 11000; Height: 17000; Units: mmHiEnglish),
(ID: DMPAPER_LEDGER; Width: 17000; Height: 11000; Units: mmHiEnglish),
(ID: DMPAPER_LEGAL; Width: 08500; Height: 14000; Units: mmHiEnglish),
(ID: DMPAPER_STATEMENT; Width: 05500; Height: 08500; Units: mmHiEnglish),