-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathharupdf.page.pas
1098 lines (935 loc) · 34 KB
/
harupdf.page.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 harupdf.page;
{ MIT License
Copyright (c) 2017 THaruPDF, Damian Woroch, http://r1me.pl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. }
{$IFDEF FPC}{$mode objfpc}{$H+}{$ENDIF}
interface
uses
{$IFNDEF FPC}
System.Classes,
System.Types,
System.SysUtils,
System.DateUtils,
System.Generics.Collections,
{$ELSE}
Classes,
Types,
SysUtils,
DateUtils,
fgl,
{$ENDIF}
hpdf,
hpdf_consts,
hpdf_error,
hpdf_types,
harupdf.image,
harupdf.font,
harupdf.destination,
harupdf.annotation,
harupdf.view3d;
type
THaruPage = class(TObject)
protected
FOwner: TObject;
FPageHandle: HPDF_Page;
FDestinations: THaruDestinations;
FAnnotations: THaruAnnotations;
function GetWidth: Single;
procedure SetWidth(AWidth: Single);
function GetHeight: Single;
procedure SetHeight(AHeight: Single);
function GetCurrentFont: THaruFont;
function GetCurrentFontSize: Single;
function GetCharSpace: Single;
procedure SetCharSpace(ACharSpace: Single);
function GetWordSpace: Single;
procedure SetWordSpace(AWordSpace: Single);
function GetTextLeading: Single;
procedure SetTextLeading(ATextLeading: Single);
function GetHorizontalScalling: Single;
procedure SetHorizontalScalling(AHorizontalScalling: Single);
function GetTextRenderingMode: THPDF_TextRenderingMode;
procedure SetTextRenderingMode(ATextRenderingMode: THPDF_TextRenderingMode);
function GetTextRise: Single;
procedure SetTextRise(ATextRise: Single);
function GetTextMatrix: THPDF_TransMatrix;
procedure SetTextMatrix(ATextMatrix: THPDF_TransMatrix);
function GetGMode: Word;
function GetGStateDepth: Cardinal;
function GetFlat: Single;
procedure SetFlat(AFlat: Single);
function GetGrayFill: Single;
procedure SetGrayFill(AGrayFill: Single);
function GetGrayStroke: Single;
procedure SetGrayStroke(AGrayStroke: Single);
function GetRGBFill: THPDF_RGBColor;
procedure SetRGBFill(ARGBFill: THPDF_RGBColor);
function GetRGBStroke: THPDF_RGBColor;
procedure SetRGBStroke(ARGBStroke: THPDF_RGBColor);
function GetCMYKFill: THPDF_CMYKColor;
procedure SetCMYKFill(ACMYKFill: THPDF_CMYKColor);
function GetCMYKStroke: THPDF_CMYKColor;
procedure SetCMYKStroke(ACMYKStroke: THPDF_CMYKColor);
function GetStrokingColorSpace: THPDF_ColorSpace;
function GetFillingColorSpace: THPDF_ColorSpace;
function GetLineWidth: Single;
procedure SetLineWidth(ALineWidth: Single);
function GetLineCap: THPDF_LineCap;
procedure SetLineCap(ALineCap: THPDF_LineCap);
function GetLineJoin: THPDF_LineJoin;
procedure SetLineJoin(ALineJoin: THPDF_LineJoin);
function GetMiterLimit: Single;
procedure SetMiterLimit(AMiterLimit: Single);
function GetTransMatrix: THPDF_TransMatrix;
public
property PageHandle: HPDF_Page read FPageHandle;
// Changes the width of a page
property Width: Single read GetWidth write SetWidth;
// Changes the height of a page
property Height: Single read GetHeight write SetHeight;
// Sets different page boundaries
procedure SetBoundary(ABoundary: THPDF_PageBoundary; ARect: TRectF);
// Changes the size and direction of a page to a predefined size
procedure SetSize(APageSize: THPDF_PageSizes; APageDirection: THPDF_PageDirection);
// Sets rotation angle of the page
procedure SetRotate(ARotationAngle: Word);
// Sets zoom factor of the page
procedure SetZoom(AZoom: Single);
// Gets page's current font
property Font: THaruFont read GetCurrentFont;
// Gets the size of the page's current font
property FontSize: Single read GetCurrentFontSize;
// Sets the type of font and size leading
function SetFontAndSize(AFont: THaruFont; AFontSize: Single): Boolean;
// Sets character spacing
property CharSpace: Single read GetCharSpace write SetCharSpace;
// Sets word spacing
property WordSpace: Single read GetWordSpace write SetWordSpace;
// Sets line spacing
property TextLeading: Single read GetTextLeading write SetTextLeading;
// Sets horizontal scalling for text showing
property HorizontalScalling: Single read GetHorizontalScalling write SetHorizontalScalling;
//
procedure SetJustifyRatio(AWordSpace, ACharacterSpace, AKashida: Single);
//
procedure SetInterlinearAnnotationRatio(ARatio: Single);
// Sets text rendering mode
property TextRenderingMode: THPDF_TextRenderingMode read GetTextRenderingMode write
SetTextRenderingMode;
// Sets text rising
property TextRise: Single read GetTextRise write SetTextRise;
// Sets a transformation matrix for text to be drawn in using ShowText
property TextMatrix: THPDF_TransMatrix read GetTextMatrix write SetTextMatrix;
// Begins a text object and sets the text position to (0, 0)
function BeginText: Boolean;
// Ends a text object
procedure EndText;
// Gets the current position for text showing
function GetCurrentTextPos: TPointF;
// Changes the current text position, using the specified offset values
procedure MoveTextPos(Ax, Ay: Single);
// Changes the current text position, using the specified offset values,
// the text-leading is set to -y
procedure MoveTextPos2(Ax, Ay: Single);
// Moves current position for the text showing to a next line
function MoveToNextLine: Boolean;
// Prints the text at the current position on the page
function ShowText(const AText: string; ATextPtr: Pointer = nil): Boolean;
// Moves the current text position to the start of the next line,
// then prints the text at the current position
function ShowTextNextLine(const AText: string; ATextPtr: Pointer = nil): Boolean; overload;
// Moves the current text position to the start of the next line, sets
// word spacing and character spacing. Prints the text at the current position
function ShowTextNextLine(const AText: string; AWordSpace, ACharacterSpace: Single;
ATextPtr: Pointer = nil): Boolean; overload;
// Prints the text on the specified position
function TextOut(Ax, Ay: Single; const AText: string; ATextPtr: Pointer = nil): Boolean;
//
procedure TextOutCircle(Ax, Ay, ARadius, AStartAngle: Single; const AText: String);
// Prints the text inside the specified region
function TextRect(ARect: TRectF; ATextAlignment: Cardinal; const AText: string;
out ATextLen: Integer; ATextPtr: Pointer = nil): Boolean;
// Gets the width of the text in current fontsize, character spacing and word spacing
function TextWidth(AText: string; ATextPtr: Pointer = nil): Single; overload;
// Calculates the byte length which can be included within the specified width
function MeasureText(AText: string; AWidth: Single; AOptions: TMeasureTextOptions;
ATextPtr: Pointer = nil): Integer;
//
function MeasureTextLines(AText: string; ALineWidth: Single; AOptions: TMeasureTextOptions;
AMaxLines: Integer; ATextPtr: Pointer = nil): Integer;
property Destinations: THaruDestinations read FDestinations write FDestinations;
property Annotations: THaruAnnotations read FAnnotations write FAnnotations;
// Gets the current graphics mode
property GMode: Word read GetGMode;
// Saves the page's current graphics parameter to the stack
function GSave: Boolean;
// Restore the graphics state which is saved by GSave
procedure GRestore;
// Gets the number of the page's graphics state stack
property GStateDepth: Cardinal read GetGStateDepth;
// Applies the graphics state to the page
procedure SetExtGState(AExtGState: HPDF_ExtGState);
// Sets filling color. Valid only when the page's stroking color space is HPDF_CS_DEVICE_GRAY
property GrayFill: Single read GetGrayFill write SetGrayFill;
// Sets stroking color. Valid only when the page's stroking color space is HPDF_CS_DEVICE_GRAY
property GrayStroke: Single read GetGrayStroke write SetGrayStroke;
// Sets filling color. Valid only when the page's filling color space is HPDF_CS_DEVICE_RGB
property RGBFill: THPDF_RGBColor read GetRGBFill write SetRGBFill;
// Sets stroking color. Valid only when the page's filling color space is HPDF_CS_DEVICE_RGB
property RGBStroke: THPDF_RGBColor read GetRGBStroke write SetRGBStroke;
// Sets filling color. Valid only when the page's filling color space is HPDF_CS_DEVICE_CMYK
property CMYKFill: THPDF_CMYKColor read GetCMYKFill write SetCMYKFill;
// Sets stroking color. Valid only when the page's filling color space is HPDF_CS_DEVICE_CMYK
property CMYKStroke: THPDF_CMYKColor read GetCMYKStroke write SetCMYKStroke;
// Gets the current value of the page's stroking color space
property StrokingColorSpace: THPDF_ColorSpace read GetStrokingColorSpace;
// Gets the current value of the page's stroking color space
property FillingColorSpace: THPDF_ColorSpace read GetFillingColorSpace;
// Sets the width of the line used to stroke a path
property LineWidth: Single read GetLineWidth write SetLineWidth;
// Sets the shape to be used at the ends of lines
property LineCap: THPDF_LineCap read GetLineCap write SetLineCap;
// Sets the line join style in the page
property LineJoin: THPDF_LineJoin read GetLineJoin write SetLineJoin;
// Sets the maximum miter length
property MiterLimit: Single read GetMiterLimit write SetMiterLimit;
// Sets the dash pattern for lines in the page
function GetDash: THPDF_DashMode;
procedure SetDash(const ADash: array of Single; APhase: Single);
// Gets the current position for path painting
function GetCurrentPos: TPointF;
// Sets the current position for path painting
procedure MoveTo(Ax, Ay: Single);
// Appends a path from the current point to the specified point
procedure LineTo(Ax, Ay: Single);
// Appends a Bézier curve to the current path using the control points (x1, y1) and (x2, y2) and (x3, y3)
procedure CurveTo(Ax1, Ay1: Single; Ax2, Ay2: Single; Ax3, Ay3: Single);
// Appends a Bézier curve to the current path using the current point and (x2, y2) and (x3, y3) as control points
procedure CurveTo2(Ax2, Ay2: Single; Ax3, Ay3: Single);
// Appends a Bézier curve to the current path using the current point and (x1, y1) and (x3, y3) as control points
procedure CurveTo3(Ax1, Ay1: Single; Ax3, Ay3: Single);
// Appends a straight line from the current point to the start point of sub path
procedure ClosePath;
// Appends a rectangle to the current path
procedure Rectangle(Ax, Ay: Single; AWidth, AHeight: Single); overload;
procedure Rectangle(ARect: TRectF); overload;
// Appends a circle to the current path
procedure Circle(Ax, Ay: Single; ARadius: Single);
// Appends an ellipse to the current path
procedure Ellipse(Ax, Ay: Single; ARadiusX, ARadiusY: Single);
// Appends a circle arc to the current path
procedure Arc(Ax, Ay: Single; ARadius: Single; Angle1, Angle2: Single);
// Paints the current path
procedure Stroke;
// Closes the current path, then paints the path
procedure ClosePathStroke;
// Fills the current path using the nonzero winding number rule
procedure Fill;
// Fills the current path using the even-odd rule
procedure Eofill;
// Fills the current path using the nonzero winding number rule, then paints the path
procedure FillStroke;
// Fills the current path using the even-odd rule, then paints the path
procedure EofillStroke;
// Closes the current path, fills the current path using the nonzero winding number rule, then paints the path
procedure ClosePathFillStroke;
// Closes the current path, fills the current path using the even-odd rule, then paints the path
procedure ClosePathEofillStroke;
// Ends the path object without filling or painting
procedure EndPath;
// Modifies the current clipping path by intersecting it with the current path using the nonzero winding number rule
procedure Clip;
// Modifies the current clipping path by intersecting it with the current path using the even-odd rule
procedure Eoclip;
// Shows an image in one operation
function DrawImage(AImage: THaruImage; Ax, Ay: Single; AWidth: Single = -1; AHeight: Single = -1): Boolean;
//
function CreateXObjectFromImage(ARect: TRectF; AImage: THaruImage; AZoom: Boolean):
HPDF_XObject;
//
function CreateXObjectAsWhiteRect(ARect: TRectF): HPDF_XObject;
//
function ExecuteXObject(AObject: HPDF_XObject): Boolean;
//
function Create3DView(AU3D: THaruU3D; A3DAnnotation: THaruAnnotation; AName: String): THaru3DView;
//
function Create3DAnnotExData: HPDF_ExData;
//
procedure AnnotExData_Set3DMeasurement(AExData: HPDF_ExData; AMeasure: THaru3DMeasure);
// Gets the current transformation matrix of the page
property TransMatrix: THPDF_TransMatrix read GetTransMatrix;
// Concatenates the page's current transformation matrix and specified matrix
function Concat(Aa, Ab, Ac, Ad, Ax, Ay: Single): Boolean;
// Sets page flatness
property Flat: Single read GetFlat write SetFlat;
// Defines transition style for the page
procedure SetSlideShow(AType: THPDF_TransitionStyle; ADispTime: Single; ATransTime: Single);
constructor Create(AOwner: TObject; APageHandle: HPDF_Page);
destructor Destroy; override;
end;
THaruPagesList = {$IFNDEF FPC}TList{$ELSE}specialize TFPGList{$ENDIF}<THaruPage>;
type
THaruPages = class(TObject)
protected
FOwner: TObject;
FPages: THaruPagesList;
function GetCurrentPage: THaruPage;
function GetPageByIdx(APageIndex: Integer): THaruPage;
function GetCount: Integer;
public
property Items[APageIndex: Integer]: THaruPage read GetPageByIdx; default;
property Count: Integer read GetCount;
function GetPageByHandle(APageHandle: HPDF_Page): THaruPage;
// The maximum number of pages becomes 8191 * APagePerPages. Must be set before adding any page
procedure SetPagesConfiguration(APagePerPages: Integer);
// Returns the current page object
property CurrentPage: THaruPage read GetCurrentPage;
// Creates a new page and adds it after the last page of a document
function Add: THaruPage;
// Creates a new page and inserts it just before the specified page
function InsertPage(ATargetPage: THaruPage): THaruPage; overload;
function InsertPage(ATargetPageIndex: Integer): THaruPage; overload;
// Call to begin/end writing shared content to a stream
function BeginEndSharedContent(APage: THaruPage; var AContentStream: HPDF_DICT): Boolean;
// Inserts shared content on the page
function InsertSharedContent(APage: THaruPage; const AContentStream: HPDF_DICT): Boolean;
constructor Create(AOwner: TObject);
destructor Destroy; override;
end;
implementation
uses
harupdf.document,
harupdf.utils;
{ THaruPage }
constructor THaruPage.Create(AOwner: TObject; APageHandle: HPDF_Page);
begin
FOwner := AOwner;
FPageHandle := APageHandle;
FDestinations := THaruDestinations.Create(Self);
FAnnotations := THaruAnnotations.Create(Self, AOwner);
end;
destructor THaruPage.Destroy;
begin
FDestinations.Free;
FAnnotations.Free;
inherited;
end;
function THaruPage.GetWidth: Single;
begin
Result := HPDF_Page_GetWidth(FPageHandle);
end;
procedure THaruPage.SetWidth(AWidth: Single);
begin
HPDF_Page_SetWidth(FPageHandle, AWidth);
end;
function THaruPage.GetHeight: Single;
begin
Result := HPDF_Page_GetHeight(FPageHandle);
end;
procedure THaruPage.SetHeight(AHeight: Single);
begin
HPDF_Page_SetHeight(FPageHandle, AHeight);
end;
procedure THaruPage.SetBoundary(ABoundary: THPDF_PageBoundary; ARect: TRectF);
begin
HPDF_Page_SetBoundary(FPageHandle, ABoundary, ARect.Left, ARect.Bottom, ARect.Right, ARect.Top);
end;
procedure THaruPage.SetSize(APageSize: THPDF_PageSizes; APageDirection: THPDF_PageDirection);
begin
HPDF_Page_SetSize(FPageHandle, APageSize, APageDirection);
end;
procedure THaruPage.SetRotate(ARotationAngle: Word);
begin
HPDF_Page_SetRotate(FPageHandle, ARotationAngle);
end;
procedure THaruPage.SetZoom(AZoom: Single);
begin
HPDF_Page_SetZoom(FPageHandle, AZoom);
end;
function THaruPage.GetCurrentFont: THaruFont;
var
hCurrentFont: HPDF_Font;
begin
hCurrentFont := HPDF_Page_GetCurrentFont(FPageHandle);
Result := THaruDocument(FOwner).Fonts.GetFontByHandle(hCurrentFont);
end;
function THaruPage.GetCurrentFontSize: Single;
begin
Result := HPDF_Page_GetCurrentFontSize(FPageHandle);
end;
function THaruPage.SetFontAndSize(AFont: THaruFont; AFontSize: Single): Boolean;
begin
Result := (HPDF_Page_SetFontAndSize(FPageHandle, AFont.FontHandle, AFontSize) = HPDF_OK);
end;
function THaruPage.GetCharSpace: Single;
begin
Result := HPDF_Page_GetCharSpace(FPageHandle);
end;
procedure THaruPage.SetCharSpace(ACharSpace: Single);
begin
HPDF_Page_SetCharSpace(FPageHandle, ACharSpace);
end;
function THaruPage.GetWordSpace: Single;
begin
Result := HPDF_Page_GetWordSpace(FPageHandle);
end;
procedure THaruPage.SetWordSpace(AWordSpace: Single);
begin
HPDF_Page_SetWordSpace(FPageHandle, AWordSpace);
end;
function THaruPage.GetTextLeading: Single;
begin
Result := HPDF_Page_GetTextLeading(FPageHandle);
end;
procedure THaruPage.SetTextLeading(ATextLeading: Single);
begin
HPDF_Page_SetTextLeading(FPageHandle, ATextLeading);
end;
function THaruPage.GetHorizontalScalling: Single;
begin
Result := HPDF_Page_GetHorizontalScalling(FPageHandle);
end;
procedure THaruPage.SetHorizontalScalling(AHorizontalScalling: Single);
begin
HPDF_Page_SetHorizontalScalling(FPageHandle, AHorizontalScalling);
end;
procedure THaruPage.SetJustifyRatio(AWordSpace, ACharacterSpace, AKashida: Single);
begin
HPDF_Page_SetJustifyRatio(FPageHandle, AWordSpace, ACharacterSpace, AKashida);
end;
procedure THaruPage.SetInterlinearAnnotationRatio(ARatio: Single);
begin
HPDF_Page_InterlinearAnnotationRatio(FPageHandle, ARatio);
end;
function THaruPage.GetTextRenderingMode: THPDF_TextRenderingMode;
begin
Result := HPDF_Page_GetTextRenderingMode(FPageHandle);
end;
procedure THaruPage.SetTextRenderingMode(ATextRenderingMode: THPDF_TextRenderingMode);
begin
HPDF_Page_SetTextRenderingMode(FPageHandle, ATextRenderingMode);
end;
function THaruPage.GetTextRise: Single;
begin
Result := HPDF_Page_GetTextRise(FPageHandle);
end;
procedure THaruPage.SetTextRise(ATextRise: Single);
begin
HPDF_Page_SetTextRise(FPageHandle, ATextRise);
end;
function THaruPage.GetTextMatrix: THPDF_TransMatrix;
begin
Result := HPDF_Page_GetTextMatrix(FPageHandle);
end;
procedure THaruPage.SetTextMatrix(ATextMatrix: THPDF_TransMatrix);
begin
HPDF_Page_SetTextMatrix(FPageHandle, ATextMatrix.a, ATextMatrix.b, ATextMatrix.c,
ATextMatrix.d, ATextMatrix.x, ATextMatrix.y);
end;
function THaruPage.BeginText: Boolean;
begin
Result := (HPDF_Page_BeginText(FPageHandle) = HPDF_OK);
end;
procedure THaruPage.EndText;
begin
HPDF_Page_EndText(FPageHandle);
end;
function THaruPage.GetGrayFill: Single;
begin
Result := HPDF_Page_GetGrayFill(FPageHandle);
end;
procedure THaruPage.SetGrayFill(AGrayFill: Single);
begin
HPDF_Page_SetGrayFill(FPageHandle, AGrayFill);
end;
function THaruPage.GetGrayStroke: Single;
begin
Result := HPDF_Page_GetGrayStroke(FPageHandle);
end;
procedure THaruPage.SetGrayStroke(AGrayStroke: Single);
begin
HPDF_Page_SetGrayStroke(FPageHandle, AGrayStroke);
end;
function THaruPage.GetRGBFill: THPDF_RGBColor;
begin
Result := HPDF_Page_GetRGBFill(FPageHandle);
end;
procedure THaruPage.SetRGBFill(ARGBFill: THPDF_RGBColor);
begin
HPDF_Page_SetRGBFill(FPageHandle, ARGBFill.r, ARGBFill.g, ARGBFill.b);
end;
function THaruPage.GetRGBStroke: THPDF_RGBColor;
begin
Result := HPDF_Page_GetRGBStroke(FPageHandle);
end;
procedure THaruPage.SetRGBStroke(ARGBStroke: THPDF_RGBColor);
begin
HPDF_Page_SetRGBStroke(FPageHandle, ARGBStroke.r, ARGBStroke.g, ARGBStroke.b);
end;
function THaruPage.GetCMYKFill: THPDF_CMYKColor;
begin
Result := HPDF_Page_GetCMYKFill(FPageHandle);
end;
procedure THaruPage.SetCMYKFill(ACMYKFill: THPDF_CMYKColor);
begin
HPDF_Page_SetCMYKFill(FPageHandle, ACMYKFill.c, ACMYKFill.m, ACMYKFill.y, ACMYKFill.k);
end;
function THaruPage.GetCMYKStroke: THPDF_CMYKColor;
begin
Result := HPDF_Page_GetCMYKStroke(FPageHandle);
end;
procedure THaruPage.SetCMYKStroke(ACMYKStroke: THPDF_CMYKColor);
begin
HPDF_Page_SetCMYKStroke(FPageHandle, ACMYKStroke.c, ACMYKStroke.m, ACMYKStroke.y, ACMYKStroke.k);
end;
function THaruPage.GetStrokingColorSpace: THPDF_ColorSpace;
begin
Result := HPDF_Page_GetStrokingColorSpace(FPageHandle);
end;
function THaruPage.GetFillingColorSpace: THPDF_ColorSpace;
begin
Result := HPDF_Page_GetFillingColorSpace(FPageHandle);
end;
function THaruPage.GetLineWidth: Single;
begin
Result := HPDF_Page_GetLineWidth(FPageHandle);
end;
procedure THaruPage.SetLineWidth(ALineWidth: Single);
begin
HPDF_Page_SetLineWidth(FPageHandle, ALineWidth);
end;
function THaruPage.GetLineCap: THPDF_LineCap;
begin
Result := HPDF_Page_GetLineCap(FPageHandle);
end;
procedure THaruPage.SetLineCap(ALineCap: THPDF_LineCap);
begin
HPDF_Page_SetLineCap(FPageHandle, ALineCap);
end;
function THaruPage.GetLineJoin: THPDF_LineJoin;
begin
Result := HPDF_Page_GetLineJoin(FPageHandle);
end;
procedure THaruPage.SetLineJoin(ALineJoin: THPDF_LineJoin);
begin
HPDF_Page_SetLineJoin(FPageHandle, ALineJoin);
end;
function THaruPage.GetMiterLimit: Single;
begin
Result := HPDF_Page_GetMiterLimit(FPageHandle);
end;
procedure THaruPage.SetMiterLimit(AMiterLimit: Single);
begin
HPDF_Page_SetMiterLimit(FPageHandle, AMiterLimit);
end;
function THaruPage.GetDash: THPDF_DashMode;
begin
Result := HPDF_Page_GetDash(FPageHandle);
end;
procedure THaruPage.SetDash(const ADash: array of Single; APhase: Single);
begin
if Length(ADash) > 0 then
HPDF_Page_SetDash(FPageHandle, @ADash[0], Length(ADash), APhase)
else
HPDF_Page_SetDash(FPageHandle, nil, 0, 0);
end;
function THaruPage.DrawImage(AImage: THaruImage; Ax, Ay: Single; AWidth, AHeight: Single):
Boolean;
begin
if Assigned(AImage) then
begin
if (AWidth = -1) and
(AHeight = -1) then
begin
Result := (HPDF_Page_DrawImage(FPageHandle, AImage.ImageHandle, Ax, Ay, AImage.Width,
AImage.Height) = HPDF_OK);
end else
Result := (HPDF_Page_DrawImage(FPageHandle, AImage.ImageHandle, Ax, Ay, AWidth, AHeight) =
HPDF_OK);
end else
Result := False;
end;
function THaruPage.CreateXObjectFromImage(ARect: TRectF; AImage: THaruImage; AZoom: Boolean):
HPDF_XObject;
begin
Result := HPDF_Page_CreateXObjectFromImage(THaruDocument(FOwner).DocumentHandle, FPageHandle,
RectFToHaruRect(ARect), AImage.ImageHandle, BooleanToHaruBool(AZoom));
end;
function THaruPage.CreateXObjectAsWhiteRect(ARect: TRectF): HPDF_XObject;
begin
Result := HPDF_Page_CreateXObjectAsWhiteRect(THaruDocument(FOwner).DocumentHandle, FPageHandle,
RectFToHaruRect(ARect));
end;
function THaruPage.ExecuteXObject(AObject: HPDF_XObject): Boolean;
begin
Result := (HPDF_Page_ExecuteXObject(FPageHandle, AObject) = HPDF_OK);
end;
function THaruPage.Create3DView(AU3D: THaruU3D; A3DAnnotation: THaruAnnotation;
AName: String): THaru3DView;
var
hView: HPDF_Dict;
pName: PUTF8Char;
begin
pName := StringToPUTF8Char(AName);
hView := HPDF_Page_Create3DView(FPageHandle, AU3D.U3DHandle, A3DAnnotation.AnnotationHandle,
pName);
Result := THaru3DView.Create(hView);
end;
function THaruPage.Create3DAnnotExData: HPDF_ExData;
begin
Result := HPDF_Page_Create3DAnnotExData(FPageHandle);
end;
procedure THaruPage.AnnotExData_Set3DMeasurement(AExData: HPDF_ExData; AMeasure: THaru3DMeasure);
begin
HPDF_3DAnnotExData_Set3DMeasurement(AExData, AMeasure.MeasureHandle);
end;
function THaruPage.GetTransMatrix: THPDF_TransMatrix;
begin
Result := HPDF_Page_GetTransMatrix(FPageHandle);
end;
function THaruPage.Concat(Aa, Ab, Ac, Ad, Ax, Ay: Single): Boolean;
begin
Result := (HPDF_Page_Concat(FPageHandle, Aa, Ab, Ac, Ad, Ax, Ay) = HPDF_OK);
end;
function THaruPage.GetGStateDepth: Cardinal;
begin
Result := HPDF_Page_GetGStateDepth(FPageHandle);
end;
procedure THaruPage.SetExtGState(AExtGState: HPDF_ExtGState);
begin
HPDF_Page_SetExtGState(FPageHandle, AExtGState);
end;
function THaruPage.GetCurrentPos: TPointF;
var
pos: THPDF_Point;
begin
pos := HPDF_Page_GetCurrentPos(FPageHandle);
Result.x := pos.x;
Result.y := pos.y;
end;
procedure THaruPage.MoveTo(Ax, Ay: Single);
begin
HPDF_Page_MoveTo(FPageHandle, Ax, Ay);
end;
procedure THaruPage.LineTo(Ax, Ay: Single);
begin
HPDF_Page_LineTo(FPageHandle, Ax, Ay);
end;
procedure THaruPage.CurveTo(Ax1, Ay1: Single; Ax2, Ay2: Single; Ax3, Ay3: Single);
begin
HPDF_Page_CurveTo(FPageHandle, Ax1, Ay1, Ax2, Ay2, Ax3, Ay3);
end;
procedure THaruPage.CurveTo2(Ax2, Ay2: Single; Ax3, Ay3: Single);
begin
HPDF_Page_CurveTo2(FPageHandle, Ax2, Ay2, Ax3, Ay3);
end;
procedure THaruPage.CurveTo3(Ax1, Ay1: Single; Ax3, Ay3: Single);
begin
HPDF_Page_CurveTo3(FPageHandle, Ax1, Ay1, Ax3, Ay3);
end;
procedure THaruPage.ClosePath;
begin
HPDF_Page_ClosePath(FPageHandle);
end;
procedure THaruPage.Rectangle(Ax, Ay: Single; AWidth, AHeight: Single);
begin
HPDF_Page_Rectangle(FPageHandle, Ax, Ay, AWidth, AHeight);
end;
procedure THaruPage.Rectangle(ARect: TRectF);
begin
HPDF_Page_Rectangle(FPageHandle, ARect.Left, ARect.Top, ARect.Width, ARect.Height);
end;
procedure THaruPage.Circle(Ax, Ay: Single; ARadius: Single);
begin
HPDF_Page_Circle(FPageHandle, Ax, Ay, ARadius);
end;
procedure THaruPage.Ellipse(Ax, Ay: Single; ARadiusX, ARadiusY: Single);
begin
HPDF_Page_Ellipse(FPageHandle, Ax, Ay, ARadiusX, ARadiusY);
end;
procedure THaruPage.Arc(Ax, Ay: Single; ARadius: Single; Angle1, Angle2: Single);
begin
HPDF_Page_Arc(FPageHandle, Ax, Ay, ARadius, Angle1, Angle2);
end;
procedure THaruPage.Stroke;
begin
HPDF_Page_Stroke(FPageHandle);
end;
procedure THaruPage.ClosePathStroke;
begin
HPDF_Page_ClosePathStroke(FPageHandle);
end;
procedure THaruPage.Fill;
begin
HPDF_Page_Fill(FPageHandle);
end;
procedure THaruPage.Eofill;
begin
HPDF_Page_Eofill(FPageHandle);
end;
procedure THaruPage.FillStroke;
begin
HPDF_Page_FillStroke(FPageHandle);
end;
procedure THaruPage.EofillStroke;
begin
HPDF_Page_EofillStroke(FPageHandle);
end;
procedure THaruPage.ClosePathFillStroke;
begin
HPDF_Page_ClosePathFillStroke(FPageHandle);
end;
procedure THaruPage.ClosePathEofillStroke;
begin
HPDF_Page_ClosePathEofillStroke(FPageHandle);
end;
procedure THaruPage.EndPath;
begin
HPDF_Page_EndPath(FPageHandle);
end;
procedure THaruPage.Clip;
begin
HPDF_Page_Clip(FPageHandle);
end;
procedure THaruPage.Eoclip;
begin
HPDF_Page_Eoclip(FPageHandle);
end;
function THaruPage.GetFlat: Single;
begin
Result := HPDF_Page_GetFlat(FPageHandle);
end;
procedure THaruPage.SetFlat(AFlat: Single);
begin
HPDF_Page_SetFlat(FPageHandle, AFlat);
end;
procedure THaruPage.SetSlideShow(AType: THPDF_TransitionStyle;
ADispTime: Single; ATransTime: Single);
begin
HPDF_Page_SetSlideShow(FPageHandle, AType, ADispTime, ATransTime);
end;
function THaruPage.TextWidth(AText: string; ATextPtr: Pointer): Single;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := HPDF_Page_TextWidth(FPageHandle, pText);
end;
function THaruPage.MeasureText(AText: string; AWidth: Single; AOptions: TMeasureTextOptions; ATextPtr: Pointer): Integer;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := HPDF_Page_MeasureText(FPageHandle, pText, AWidth, MeasureTextOptionsToInt(AOptions), nil);
end;
function THaruPage.MeasureTextLines(AText: string; ALineWidth: Single; AOptions: TMeasureTextOptions;
AMaxLines: Integer; ATextPtr: Pointer): Integer;
var
lWidth: THPDF_TextLineWidth;
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := HPDF_Page_MeasureTextLines(FPageHandle, pText, ALineWidth,
MeasureTextOptionsToInt(AOptions), lWidth, AMaxLines);
end;
function THaruPage.GetGMode: Word;
begin
Result := HPDF_Page_GetGMode(FPageHandle);
end;
function THaruPage.GSave: Boolean;
begin
Result := (HPDF_Page_GSave(FPageHandle) = HPDF_OK);
end;
procedure THaruPage.GRestore;
begin
HPDF_Page_GRestore(FPageHandle);
end;
function THaruPage.GetCurrentTextPos: TPointF;
var
pos: THPDF_Point;
begin
pos := HPDF_Page_GetCurrentTextPos(FPageHandle);
Result.x := pos.x;
Result.y := pos.y;
end;
procedure THaruPage.MoveTextPos(Ax, Ay: Single);
begin
HPDF_Page_MoveTextPos(FPageHandle, Ax, Ay);
end;
procedure THaruPage.MoveTextPos2(Ax, Ay: Single);
begin
HPDF_Page_MoveTextPos2(FPageHandle, Ax, Ay);
end;
function THaruPage.MoveToNextLine: Boolean;
begin
Result := (HPDF_Page_MoveToNextLine(FPageHandle) = HPDF_OK);
end;
function THaruPage.ShowText(const AText: string; ATextPtr: Pointer): Boolean;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := (HPDF_Page_ShowText(FPageHandle, pText) = HPDF_OK);
end;
function THaruPage.ShowTextNextLine(const AText: string; ATextPtr: Pointer): Boolean;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := (HPDF_Page_ShowTextNextLine(FPageHandle, pText) = HPDF_OK);
end;
function THaruPage.ShowTextNextLine(const AText: string; AWordSpace, ACharacterSpace: Single;
ATextPtr: Pointer): Boolean;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := (HPDF_Page_ShowTextNextLineEx(FPageHandle, AWordSpace, ACharacterSpace, pText) = HPDF_OK);
end;
function THaruPage.TextOut(Ax, Ay: Single; const AText: string; ATextPtr: Pointer): Boolean;
var
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
Result := (HPDF_Page_TextOut(FPageHandle, Ax, Ay, pText) = HPDF_OK);
end;
procedure THaruPage.TextOutCircle(Ax, Ay, ARadius, AStartAngle: Single; const AText: String);
var
angle1, angle2: Single;
rad1, rad2: Single;
x, y: Single;
i: Integer;
begin
if (Length(AText) > 0) then
begin
angle1 := 360 / Length(AText);
angle2 := 180;
for i := 1 to Length(AText) do
begin
rad1 := (angle2 - AStartAngle) / 180 * Pi;
rad2 := (angle2 - AStartAngle + 90) / 180 * Pi;
x := Ax + cos(rad2) * ARadius;
y := Ay + sin(rad2) * ARadius;
Self.TextMatrix := THPDF_TransMatrix.Create(cos(rad1), sin(rad1), -sin(rad1), cos(rad1), x, y);
Self.ShowText(AText[i]);
angle2 := angle2 - angle1;
end;
end;
end;
function THaruPage.TextRect(ARect: TRectF; ATextAlignment: Cardinal; const AText: String;
out ATextLen: Integer; ATextPtr: Pointer): Boolean;
var
res: HPDF_STATUS;
pText: PUTF8Char;
begin
pText := StringToPUTF8Char(AText, ATextPtr);
try
res := HPDF_Page_TextRect(FPageHandle, ARect.Left, ARect.Top, ARect.Right, ARect.Bottom,
pText, ATextAlignment, @ATextLen);
Result := (res = HPDF_OK) or (res = HPDF_PAGE_INSUFFICIENT_SPACE);
except
on E: EHaruPDFException do
Result := (E.ErrorCode = HPDF_PAGE_INSUFFICIENT_SPACE);
end;
end;
{ THaruPages }
constructor THaruPages.Create(AOwner: TObject);
begin