File: fpreportlclexport.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (1142 lines) | stat: -rw-r--r-- 36,370 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
{
    This file is part of the Free Component Library.
    Copyright (c) 2016 Michael Van Canneyt, member of the Free Pascal development team

    FPReport generic LCL Export filter. Can also be used in design mode.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
unit fpreportlclexport;

{$mode objfpc}{$H+}
{ $DEFINE DEBUGRD}

interface

uses
  Classes,
  SysUtils,
  fpImage,
  fpReport,
  contnrs,
  types,
  graphics,
  forms;

Const
  // Design mode constants
  BandTitleMargin = 2;             // Margin used in band title displaying name of band, in pixels.
  BandTitleOffset = 12;            // Space between band title and previous band, in pixels
  ElementHCornerLength = 4;        // Length of horitonzal corner handle
  ElementVCornerLength = 6;        // Length of horitonzal corner handle
  clSelectionRect = clDkGray;    // Color for selected elements rectangle
  clEmementCorner = clBlack;       // Color for element corner indicators.
  ReSizeHandleHalfWidth = 3;       // Half width of selection resize handle
  ReSizeHandleWidth = 2 * ReSizeHandleHalfWidth; // Full width of selection resize handle;

{  btUnknown,btPageHeader,btReportTitle,btColumnHeader,btDataHeader,btGroupHeader,btDataband,btGroupFooter,
                               btDataFooter,btColumnFooter,btReportSummary,btPageFooter,btChild);}

type
  {
    The LCL renderer does not support hyperlinks by itself.
    It collects a series of URLs and Rects when rendering.
    The user of the LCL renderer can use this collection to implement
    onClick and MouseMove handlers that query the List using the IndexOfPoint or FindLinkAtPoint methods.
    If links overlap, the last added link will be used.
  }

  { THyperLinkItem }

  THyperLinkItem = Class(TCollectionItem)
  private
    FRect: TRect;
    FURL: String;
  Public
    Property Rect : TRect Read FRect Write FRect;
    Property URL : String Read FURL Write FURL;
  end;

  { THyperLinkList }

  THyperLinkList = Class(TCollection)
  private
    function GetL(AIndex : Integer): THyperLinkItem;
  Public
    Function IndexOfPoint(APoint : TPoint) : Integer;
    Function IndexOfPoint(AX,AY : Integer) : Integer;
    Function FindLinkAtPoint(APoint : TPoint) : THyperlinkItem;
    Function FindLinkAtPoint(AX,AY : Integer) : THyperlinkItem;
    Function AddLink(Const ARect : TRect; Const AURL : String) : THyperlinkItem;
    Property Links[AIndex : Integer] : THyperLinkItem Read GetL; default;
  end;

  { TFPReportExportCanvas }
  TReportDrawMode = (dmRender,dmDesign);

  TFPReportExportCanvas = class(TFPReportExporter)
  private
    FCanvas : TCanvas;
    FDrawMode: TReportDrawMode;
    FHDPI: integer;
    FHorzOffset: Integer;
    FImageWidth: integer;
    FImageHeight: integer;
    FFonts : TFPObjectHashTable;
    FPageIndex : Integer;
    FPages : TFPList;
    FShowBandTypeNames: Boolean;
    FVDPI: integer;
    FVertOffset: Integer;
    FZoom: Double;
    FHyperLinks : THyperLinkList;
    FBandHandleHeight : Integer;
    function GetCurrentPage: TFPReportPage;
    function GetHyperLinksEnabled: Boolean;
    function GetLayout(AElement: TFPReportElement): TFPReportLayout;
    function GetPageCount: Integer;
    procedure PrepareCanvas;
    procedure SetHyperlinksEnabled(AValue: Boolean);
    procedure SetPageIndex(AValue: Integer);
  protected
    procedure RenderFrame(const AFrame: TFPReportFrame; const ARect: Trect;  const ABackgroundColor: TColor);
    Procedure RenderImage(aRect : TFPReportRect; var AImage: TFPCustomImage) ; override;
    function BandColorCode(ABand: TFPReportCustomBandClass; Edge : Boolean): TColor; virtual;
    procedure DrawBandLabel(Aband: TFPReportCustomBand; l: TFPReportLayout); virtual;
    procedure DrawBandRect(Aband: TFPReportCustomBand; l: TFPReportLayout); virtual;
    Function CreateHyperlinks : THyperLinkList; virtual;
    procedure DrawElementCorners(E: TFPReportElement; R: TRect); virtual;
    function GetFont(const AFontName: String): TFont;
    procedure SetupPageRender(const APage: TFPReportPage);
    procedure DoExecute(const ARTObjects: TFPList); override;
    procedure RenderBand(Aband: TFPReportCustomBand); virtual;
    procedure RenderFrame(const ABand: TFPReportCustomBand; const AFrame: TFPReportFrame; const APos: TFPReportPoint; const AWidth, AHeight: TFPReportUnits); virtual;
    procedure RenderMemo(const ABand: TFPReportCustomBand; const AMemo: TFPReportCustomMemo); virtual;
    procedure RenderShape(const ABand: TFPReportCustomBand; const AShape: TFPReportCustomShape); virtual;
    procedure RenderImage(const ABand: TFPReportCustomBand; const AImage: TFPReportCustomImage); virtual;
    procedure RenderCheckbox(const ABand: TFPReportCustomBand; const ACheckbox: TFPReportCustomCheckbox); virtual;
    Function GetBandHandleHeight : Integer;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    // Rendering options
    procedure   RenderElement(ABand: TFPReportCustomBand;  Element: TFPReportElement); virtual;
    procedure   RenderCurrentPage; virtual;
    procedure   DrawSelectionHandle(ACenter: TPoint; AColor: TColor); virtual;
    Procedure   DrawSelectionRect(ARect : Trect); virtual;
    // Moved here to be usable externally
    procedure RenderShapeCircle(const lpt1: TFPReportPoint; const ALayout: TFPReportLayout);
    procedure RenderShapeEllipse(const lpt1: TFPReportPoint; const ALayout: TFPReportLayout);
    procedure RenderShapeLine(lpt1: TFPReportPoint;  const AOrientation: TFPReportOrientation; const ALayout: TFPReportLayout);
    procedure RenderShapeRect(const lpt1: TFPReportPoint; const ALayout: TFPReportLayout);
    procedure RenderShapeTriangle(Alpt: TFPReportPoint; const AOrientation: TFPReportOrientation; const ALayout: TFPReportLayout);
    // Some size/position routines
    Procedure   GetCurrentPageRenderSize(Out AWidth,AHeight : Integer);
    Procedure   GetPageRenderSize(APage : TFPReportCustomPage; Out AWidth,AHeight : Integer);
    function    CoordToPoint(const APos: TFPReportPoint;  const AWidth: TFPReportUnits=0; const AHeight: TFPReportUnits=0): TPoint;
    function    CoordToRect(const APos: TFPReportPoint; const AWidth: TFPReportUnits=0; const AHeight: TFPReportUnits=0): TRect;
    function    HmmToPixels(const AValue: TFPReportUnits): Integer;
    function    VmmToPixels(const AValue: TFPReportUnits): Integer;
    Function    GetPageRect(APage : TFPReportCustomPage; WithoutMargin : Boolean = False)  : TRect;
    Function    GetBandRect(L : TFPReportLayout;IncludeHandle: Boolean) : TRect;
    Function    GetBandRect(ABand : TFPReportCustomBand; IncludeHandle : Boolean) : TRect;
    Function    GetElementRect(BandLayout,ElementLayout : TFPReportLayout) : TRect;
    Function    GetElementRect(ABand : TFPReportCustomBand; AElement : TFPReportElement) : TRect;
    Class function RGBtoBGR(const AColor: UInt32): TColor;
    Class function BGRToRGB(const AColor: TColor): TFPReportColor;
    // Properties
    property    HDPI: integer read FHDPI write FHDPI;
    property    VDPI: integer read FVDPI write FVDPI;
    property    Zoom : Double read FZoom write FZoom;
    Property    Canvas : TCanvas Read FCanvas Write FCanvas;
    Property    PageIndex : Integer Read FPageIndex Write SetPageIndex;
    Property    PageCount : Integer Read GetPageCount;
    Property    CurrentPage : TFPReportPage Read GetCurrentPage;
    Property    HorzOffset : Integer Read FHorzOffset Write FHorzOffset;
    Property    VertOffset : Integer Read FVertOffset Write FVertOffset;
    // collect links ?
    Property    HyperLinksEnabled : Boolean Read GetHyperLinksEnabled Write SetHyperlinksEnabled;
    // List of collected hyperlinks. Only valid when HyperLinksEnabled = True.
    Property    HyperLinks : THyperLinkList Read FHyperLinks;
    // Design mode or not
    Property    DrawMode : TReportDrawMode Read FDrawMode Write FDrawMode;
    // ShowBandTypeNames
    Property ShowBandTypeNames : Boolean Read FShowBandTypeNames Write FShowBandTypeNames;
  end;

const
  cInchToMM = 25.4;
  RGBA_Width = 4;

implementation

uses
  fpwritepng,
  math;

Resourcestring
  SErrPageOutOfRange = 'Page index %d out of allowed range [0..%d]';

type

  { for access to Protected methods }
  TReportImageFriend = class(TFPReportCustomImage);
  TReportCheckboxFriend = class(TFPReportCustomCheckbox);

{ TFPImageFriend }


function GetColorComponent(Var AColor: UInt32): Word;
begin
  Result:=AColor and $FF;
  Result:=Result or (Result shl 8);
  AColor:=AColor shr 8;
end;

Class function TFPReportExportCanvas.RGBtoBGR(const AColor: UInt32): TColor;
var
  C : UInt32;
  R,G,B : Byte;
begin
  C:=AColor;
  B:= GetColorComponent(C);
  G:= GetColorComponent(C);
  R:= GetColorComponent(C);
//    Alpha := GetColorComponent(C);
  Result:=RGBToColor(R,G,B);
end;

class function TFPReportExportCanvas.BGRToRGB(const AColor: TColor): TFPReportColor;

var
  R,G,B : Byte;

begin
  RedGreenBlue(ColorToRGB(AColor),R,G,B);
  Result:=RGBToReportColor(R,G,B);
end;

{ THyperLinkList }

function THyperLinkList.GetL(AIndex : Integer): THyperLinkItem;
begin
  Result:=Items[AIndex] as THyperLinkItem;
end;

function THyperLinkList.IndexOfPoint(APoint: TPoint): Integer;
begin
  Result:=Count-1;
  While (Result>=0) and (Not ptInRect(GetL(Result).Rect,APoint)) do
    Dec(Result);
end;

function THyperLinkList.IndexOfPoint(AX, AY: Integer): Integer;
begin
  Result:=IndexOfPoint(Point(AX,AY));
end;

function THyperLinkList.FindLinkAtPoint(APoint: TPoint): THyperlinkItem;

Var
  I : Integer;

begin
  I:=IndexOfPoint(APoint);
  If I=-1 then
    Result:=Nil
  else
    Result:=GetL(I);
end;

function THyperLinkList.FindLinkAtPoint(AX, AY: Integer): THyperlinkItem;
begin
  Result:=FindLinkAtPoint(Point(AX,AY));
end;

function THyperLinkList.AddLink(const ARect: TRect; const AURL: String): THyperlinkItem;
begin
  Result:=Add as THyperLinkItem;
  Result.FRect:=ARect;
  Result.FURL:=AURL;
end;


{ TFPReportExportCanvas }


function TFPReportExportCanvas.HmmToPixels(const AValue: TFPReportUnits): Integer;
begin
  Result := Round(AValue * (HDPI * Zoom/ cInchToMM));
end;

function TFPReportExportCanvas.VmmToPixels(const AValue: TFPReportUnits): Integer;
begin
  Result := Round(AValue * (VDPI * Zoom/ cInchToMM));
end;

procedure TFPReportExportCanvas.SetupPageRender(const APage: TFPReportPage);

begin
  if APage.Orientation = poPortrait then 
    begin
    FImageWidth := HmmToPixels(APage.PageSize.Width);
    FImageHeight := VmmToPixels(APage.PageSize.Height);
    end  
  else 
    begin
    FImageWidth := HmmToPixels(APage.PageSize.Height);
    FImageHeight := VmmToPixels(APage.PageSize.Width);
    end;
  PrepareCanvas;
end;


procedure TFPReportExportCanvas.PrepareCanvas;

begin
  Canvas.Pen.Style:=psSolid;
  Canvas.Pen.Color:=clBlack;
  Canvas.Brush.Style:=bsSolid;
  Canvas.Brush.Color:=clWhite;
  Canvas.FillRect(FHorzOffset,FVertOffset,FHorzOffset+FImageWidth-1,FVertOffset+FImageHeight-1);
  if Assigned(FHyperLinks) then
    FHyperLinks.Clear;
end;

function TFPReportExportCanvas.GetCurrentPage: TFPReportPage;
begin
  if Assigned(FPages) and (PageIndex<FPages.Count) then
    Result:=TFPReportPage(FPages[PageIndex])
  else
    Result:=Nil;
end;

function TFPReportExportCanvas.GetHyperLinksEnabled: Boolean;
begin
  Result:=Assigned(FHyperlinks);
end;

function TFPReportExportCanvas.GetPageCount: Integer;
begin
  if Assigned(FPages) then
    Result:=FPages.Count
  else
    Result:=0;
end;

function TFPReportExportCanvas.CoordToPoint(const APos: TFPReportPoint;
  const AWidth: TFPReportUnits; const AHeight: TFPReportUnits): TPoint;

begin
  Result.X:=HmmToPixels(APos.Left+AWidth)+FHorzOffset;
  Result.Y:=VmmToPixels(APos.Top+AHeight)+FVertOffset;
end;

function TFPReportExportCanvas.CoordToRect(const APos: TFPReportPoint;
  const AWidth: TFPReportUnits; const AHeight: TFPReportUnits): TRect;

begin
  Result.Left:=HmmToPixels(APos.Left)+FHorzOffset;
  Result.Top:=VmmToPixels(APos.Top)+FVertOffset;
  Result.Right:=HmmToPixels(APos.Left+AWidth)+FHorzOffset;
  Result.Bottom:=VmmToPixels(APos.Top+AHeight)+FVertOffset;
end;

function TFPReportExportCanvas.GetPageRect(APage: TFPReportCustomPage;
  WithoutMargin: Boolean): TRect;

Var
  W,H : Integer;

begin
  GetPageRenderSize(APage,W,H);
  Result:=Rect(FHorzOffset,FVertOffset,FHorzOffset+W,FVertOffset+H);
  if WithoutMargin then
    begin
    Result.Left:=Result.Left-hMMToPixels(APage.Margins.Left);
    Result.Top:=Result.Top-VMMToPixels(APage.Margins.Top);
    Result.Right:=Result.Right+hMMToPixels(APage.Margins.Right);
    Result.Bottom:=Result.Bottom+VMMToPixels(APage.Margins.Bottom);
    end;
end;

procedure TFPReportExportCanvas.RenderFrame(const AFrame: TFPReportFrame;
  const ARect: Trect; const ABackgroundColor: TColor);

var
  bStroke, bFill: boolean;
  C : TFPReportColor;

begin
  bStroke := AFrame.Color <> clNone;
  bFill := AFrame.BackgroundColor <> clNone;
  if not (bStroke or bFill) then
    exit;
  if AFrame.Color = fpReport.clNone then
    Canvas.Pen.Style := psClear
  else
  begin
    Canvas.Pen.Style:=AFrame.Pen;
    Canvas.Pen.Color:= RGBtoBGR(AFrame.Color);
    Canvas.Pen.Width:=AFrame.Width;
  end;
  {$IFDEF DEBUGRD}
  Writeln('Rendering frame [',AFrame.Shape,'] (',ARect.Left,',',ARect.Top,',',ARect.right,',',ARect.Bottom,') : ',(bStroke or bFill));
  {$ENDIF}
  if (AFrame.Shape=fsRectangle) and (bStroke or bFill) then
    begin
    if bFill then
      begin
      Canvas.Brush.Style:=bsSolid;
      C:=AFrame.BackgroundColor;
      if c=fpReport.clNone then
        C:=ABackgroundColor;
      if c=fpReport.clNone then
        C:=fpReport.clWhite;
      Canvas.Brush.Color := RGBtoBGR(C);
      FCanvas.FillRect(ARect);
      end;
    if bStroke then
      begin
      Canvas.Brush.Style:=bsClear;
      FCanvas.Rectangle(ARect);
      end;
    end;
  if (AFrame.Shape=fsNone) and bStroke then
    begin
    if (flTop in AFrame.Lines) then
      FCanvas.line(ARect.Left, ARect.Top,ARect.Right,ARect.Top);
    if (flbottom in AFrame.Lines) then
      FCanvas.line(ARect.Left, ARect.Bottom,ARect.Right,ARect.Bottom);
    if (flLeft in AFrame.Lines) then
      FCanvas.line(ARect.Left, ARect.Top,ARect.Left,ARect.Bottom);
    if (flRight in AFrame.Lines) then
      FCanvas.line(ARect.Right, ARect.Top,ARect.Right,ARect.Bottom);
    end;  { Frame.Shape = fsNone }
end;

procedure TFPReportExportCanvas.RenderImage(aRect: TFPReportRect; var AImage: TFPCustomImage);
Var
  lpt : TFPReportPoint;
  pt : TPoint;
  G : TBitmap;

begin
  lPt.Left := aRect.Left;
  lPt.Top := aRect.Top;
  PT:=CoordToPoint(Lpt,0,0);
//  Canvas.StretchDraw(pt.X,pT.Y,mmToPixels(arect.Width), mmToPixels(arect.Height),AImage);
  G:=CreateBitmapFromFPImage(aImage);
  try
    Canvas.Draw(pt.X,pT.Y,G);
  Finally
    G.Free;
  end;
end;

procedure TFPReportExportCanvas.RenderFrame(const ABand: TFPReportCustomBand; const AFrame: TFPReportFrame;
  const APos: TFPReportPoint; const AWidth, AHeight: TFPReportUnits);

begin
  RenderFrame(AFrame,CoordToRect(APos,AWidth,AHeight), RGBtoBGR(ABand.Frame.BackgroundColor));
end;

Type
  THackReportMemo = class(TFPReportCustomMemo)
  published
    property  Font;
  end;

function TFPReportExportCanvas.GetFont(const AFontName: String): TFont;

Var
  ftFont : TFont;

begin
  Result:=Nil;
  Result:=TFont(FFonts.Items[AFontName]);
  If (Result=Nil) then
    begin
    ftFont:=TFont.create;
    ftFont.Name:=AFontName;
    Result:=ftFont;
    FFonts.Add(AFontName,Result);
    end;
end;

procedure TFPReportExportCanvas.RenderMemo(const ABand: TFPReportCustomBand; const AMemo: TFPReportCustomMemo);
var
  lPt1: TFPReportPoint;  // original Report point
  lMemo: THackReportMemo;
  i: integer;
  lXPos: TFPReportUnits;
  lYPos: TFPReportUnits;
  txtblk: TFPTextBlock;
  R,MR : TRect;
  BL,ML : TFPReportLayout;
begin
  lMemo := THackReportMemo(AMemo);

  { Store the Top-Left coordinate of the Memo. We will be reusing this info. }
  BL:=GetLayout(Aband);
  ML:=GetLayout(AMemo);
  lPt1.Left := BL.Left + ML.Left;
  lPt1.Top := BL.Top + ML.Top ;
  MR:=CoordToRect(LPT1,ML.Width,ML.Height);

  { Frame must be drawn before the text as it could have a fill color. }
  RenderFrame(AMemo.Frame, MR, ABand.Frame.BackgroundColor);
  if DrawMode=dmDesign then
    begin
    DrawElementCorners(AMemo,MR);
    lMemo.RecalcLayout;
    end;
  { render the TextBlocks as-is. }
  for i := 0 to lMemo.TextBlockList.Count-1 do
  begin
    txtblk := lMemo.TextBlockList[i];
    Canvas.Font := GetFont(txtblk.FontName);
    Canvas.Font.Size:=Round(lMemo.Font.Size * Zoom);

    lXPos := lPt1.Left + txtblk.Pos.Left;
    lYPos := lPt1.Top + txtblk.Pos.Top;
    R:=Rect(HmmToPixels(lXPos) + FHorzOffset,
            VmmToPixels(lYPos) + FVertOffset,
            HmmToPixels(lXPos + txtblk.Width) + FHorzOffset,
            VmmToPixels(lYPos + txtblk.Height + (txtblk.Descender*3)) + FVertOffset);
    if txtblk.BGColor <> fpReport.clNone then // DON'T remove "fpReport." prefix.
    begin
      Canvas.Pen.Style := psClear;
      Canvas.Brush.Style := bsSolid;
      Canvas.Brush.Color := RGBtoBGR(txtblk.BGColor);
      Canvas.Rectangle(R);
{      Canvas.Rectangle(
          mmToPixels(lXPos) + FHorzOffset,
          mmToPixels(lYPos) + FVertOffset,
          mmToPixels(lXPos + txtblk.Width) + FHorzOffset,
          mmToPixels(lYPos + txtblk.Height + (txtblk.Descender*3)) + FVertOffset
      );}
    end;

    Canvas.Pen.Style := psSolid;
    Canvas.Brush.Style := bsClear;
    Canvas.Font.Color := RGBtoBGR(txtblk.FGColor);
    { LCL's Canvas.TextOut origin coordinate is Top-Left }
    if DrawMode=dmRender then
      begin
      Canvas.TextOut(
          HmmToPixels(lXPos) + FHorzOffset,
          VmmToPixels(lYPos) + FVertOffset,
          txtblk.Text
      );
      if Assigned(FHyperLinks) and (txtblk is TFPHTTPTextBlock) then
        FHyperLinks.AddLink(R,(txtblk as TFPHTTPTextBlock).URL);
      end
    else
      begin
      Canvas.TextRect(
          MR,
          HmmToPixels(lXPos) + FHorzOffset,
          VmmToPixels(lYPos) + FVertOffset,
          txtblk.Text
      )
      end;

  end;
end;

procedure TFPReportExportCanvas.RenderShapeCircle(const lpt1: TFPReportPoint;
  const ALayout: TFPReportLayout);

var
  lPt2: TFPReportPoint;  // original Report point
  R : TRect;
  LW : TFPReportUnits;

begin
  // Keep center of circle at center of rectangle
  lw := Min(ALayout.Width, ALayout.Height);
  lpt2.Left:=lPt1.Left+(ALayout.Width / 2)-lW/2;
  lpt2.Top:=lPt1.top+(ALayout.Height / 2)-lW/2;
  R:=CoordToRect(lpt2,LW,LW);
  Canvas.ellipse(R);
end;

procedure TFPReportExportCanvas.RenderShapeEllipse(const lpt1: TFPReportPoint;
  const ALayout: TFPReportLayout);

Var
  R : TRect;
begin
  R:=CoordToRect(lpt1,ALayout.Width,ALayout.Height);
  Canvas.ellipse(R);
end;

procedure TFPReportExportCanvas.RenderShapeLine(lpt1: TFPReportPoint;
  const AOrientation: TFPReportOrientation; const ALayout: TFPReportLayout);

var
  lPt2: TFPReportPoint;  // original Report point
  R1,R2 : TPoint;

begin
  case AOrientation of
  orNorth, orSouth:
     begin                                         //   |
     lPt1.Left := lPt1.Left + (ALayout.Width / 2); //   |
     lPt2.Left := lPt1.Left ;                      //   |
     lPt2.Top := LPT1.Top + ALayout.Height;        //   |
     end;
  orNorthEast, orSouthWest:
     begin                                         //    /
     lPt2.Left := lPt1.Left;                       //   /
     lPt1.Left := lPt1.Left + ALayout.Width;       //  /
     lPt2.Top := lPt1.Top + ALayout.Height;        // /
     end;
  orEast, orWest:
     begin                                         //
     lPt2.Left := lPt1.Left + ALayout.Width;       // ----
     lPt1.Top := lPt1.Top + (ALayout.Height / 2);  //
     lPt2.Top := lPt1.Top;                         //
     end;
  orSouthEast, orNorthWest:
     begin                                         // \
     lPt2.Left := lPt1.Left + ALayout.Width;       //  \
     lPt2.Top := lPt1.Top + ALayout.Height;        //   \
     end;                                          //    \
  end;
  R1:=CoordToPoint(lpt1);
  R2:=CoordToPoint(lpt2);
  Canvas.line(R1,R2);
end;

procedure TFPReportExportCanvas.RenderShapeRect(const lpt1: TFPReportPoint;
  const ALayout: TFPReportLayout);

Var
  ldx, ldy, lw: TFPReportUnits;
  P : TFPReportPoint;
begin
  lw := Min(ALayout.Width, ALayout.Height);
  if ALayout.Width = ALayout.Height then
  begin
    ldx := 0;
    ldy := 0;
  end
  else if ALayout.Width > ALayout.Height then
  begin
    ldx := (ALayout.Width - ALayout.Height) / 2;
    ldy := 0;
  end
  else if ALayout.Width < ALayout.Height then
  begin
    ldx := 0;
    ldy := (ALayout.Height - ALayout.Width) / 2;
  end;
  P.Left := lPt1.Left + ldx;
  { PDF origin coordinate is Bottom-Left, and Report Layout is Top-Left }
  P.Top := lPt1.Top + ldy;
  Canvas.rectangle(CoordToRect(P,lw,Lw));
end;

procedure TFPReportExportCanvas.RenderShapeTriangle(Alpt: TFPReportPoint;
  const AOrientation: TFPReportOrientation; const ALayout: TFPReportLayout);


  Procedure DrawLine(Const A,B : TFPReportPoint);

  begin
    Canvas.Line(CoordToPoint(A),CoordToPoint(B));
  end;

var
  lpt1,lPt2,lpt3: TFPReportPoint;  // original Report points for 3 corners of triangle.

begin
  case AOrientation of
  orNorth:
    begin
    lPt1.Left := ALPT.Left + (ALayout.Width / 2); //      1
    lPt1.Top  := ALPT.Top;                        //      /\
    lPt2.Left := ALPT.Left;                       //     /  \
    lPt2.Top  := ALPT.Top + ALayout.Height;       //    /____\
    lPt3.Left := ALPT.Left + ALayout.Width;       //  2       3
    lPt3.Top  := lPt2.Top;
    end;
  orNorthEast:
    begin
    lPt1.Left := ALPT.Left + (ALayout.Width );    //   +-------1
    lPt1.Top  := ALPT.Top;                        //   |       |
    lPt2.Left := ALPT.Left;                       //   2       |
    lPt2.Top  := ALPT.Top + ALayout.Height/2;     //   |       |
    lPt3.Left := ALPT.Left + ALayout.Width/2;     //   +---3---+
    lPt3.Top  := lPt1.Top + aLayout.height;
    end;
  orSouth:
    begin
    lPt1.Left := ALPT.Left;                        //  1 ------ 2
    lPt1.Top  := ALPT.Top;                         //    \    /
    lPt2.Left := ALPT.Left+ ALayout.Width;         //     \  /
    lPt2.Top  := ALPT.Top;                         //      \/
    lPt3.Left := ALPT.Left + (ALayout.Width / 2);  //      3
    lPt3.Top  := ALPT.Top+ALayout.Height;
    end;
  orSouthEast:
    begin
    lPt1.Left := ALPT.Left + (ALayout.Width/2);   //   +---1---+
    lPt1.Top  := ALPT.Top;                        //   |       |
    lPt2.Left := ALPT.Left;                       //   2       |
    lPt2.Top  := ALPT.Top + ALayout.Height/2;     //   |       |
    lPt3.Left := ALPT.Left + ALayout.Width;       //   +-------3
    lPt3.Top  := lPt1.Top + aLayout.height;
    end;
  orEast:
    begin
    lPt1.Left := ALPT.Left;                       //   1
    lPt1.Top  := Alpt.Top ;                       //   |\
    lPt2.Left := ALPT.Left + ALayout.Width;       //   | \ 2
    lPt2.Top  := ALPT.Top + (ALayout.Height / 2); //   | /
    lPt3.Left := ALPT.Left;                       //   |/
    lPt3.Top  := Alpt.Top + ALayout.Height;       //   3
    end;
  orNorthWest:
    begin
    lPt1.Left := ALPT.Left;                       //   1-------+
    lPt1.Top  := ALPT.Top;                        //   |       |
    lPt2.Left := ALPT.Left+ALayout.width;         //   |       2
    lPt2.Top  := ALPT.Top + ALayout.Height/2;     //   |       |
    lPt3.Left := ALPT.Left + ALayout.Width/2;     //   +---3---+
    lPt3.Top  := lPt1.Top + aLayout.height;
    end;
  orWest:
    begin
    lPt1.Left := ALPT.Left + ALayout.Width;      //       1
    lPt1.Top  := ALPT.Top;                       //      /|
    lPt2.Left := ALPT.Left;                      //   2 / |
    lPt2.Top  := ALPT.Top + ALayout.Height / 2;  //     \ |
    lPt3.Left := ALPT.Left + ALayout.Width;      //      \|
    lPt3.Top  := ALPT.Top+ ALayout.Height;       //       3
    end;
  orSouthWest:
    begin
    lPt1.Left := ALPT.Left+ ALayout.Height/2;     //   +---1---+
    lPt1.Top  := ALPT.Top;                        //   |       |
    lPt2.Left := ALPT.Left+ALayout.width;         //   |       2
    lPt2.Top  := ALPT.Top + ALayout.Height/2;     //   |       |
    lPt3.Left := ALPT.Left ;                      //   3-------+
    lPt3.Top  := lPt1.Top + aLayout.height;
    end;
  end;
  DrawLine(lpt1,lpt2);
  DrawLine(lpt2,lpt3);
  DrawLine(lpt3,lpt1);
end;

function TFPReportExportCanvas.GetBandHandleHeight: Integer;
begin
  if (FBandHandleHeight=0) and (Canvas<>Nil) then
    FBandHandleHeight:=Canvas.TextHeight('W');
  Result:=FBandHandleHeight;
end;

procedure TFPReportExportCanvas.RenderShape(const ABand: TFPReportCustomBand; const AShape: TFPReportCustomShape);

var
  lPt1: TFPReportPoint;  // original Report point
  BL,SL : TFPReportLayout;
  SR : Trect;

begin
  BL:=GetLayout(ABand);
  SL:=GetLayout(AShape);
  SR:=GetElementRect(BL,SL);
  { Frame must be drawn before the shape as it could have a fill color. }
  RenderFrame(AShape.Frame, SR, ABand.Frame.BackgroundColor);
  { exit if Shape will not be visible. }
  if (TFPReportShape(AShape).Color = fpreport.clNone)
  or (TFPReportShape(AShape).Color = AShape.Frame.BackgroundColor) then
    exit;
  Canvas.Pen.Color:=TFPReportShape(AShape).Color;
  Canvas.Pen.Style:=psSolid;
  Canvas.Pen.Width:=1;
  lPt1.Left := BL.Left + SL.Left;
  lPt1.Top := BL.Top + SL.Top;
  case TFPReportShape(AShape).ShapeType of
    stEllipse: RenderShapeEllipse(lpt1,SL);
    stCircle: RenderShapeCircle(lpt1,SL);
    stLine: RenderShapeLine(lpt1,TFPReportShape(AShape).Orientation, SL);
    stSquare: RenderShapeRect(lpt1,SL);
    stTriangle: RenderShapeTriangle(lpt1,TFPReportShape(AShape).Orientation, SL);
  end;
  if DrawMode=dmDesign then
    begin
    SR:=CoordToRect(LPT1,SL.Width,SL.Height);
    DrawElementCorners(AShape,SR);
    end;
end;

procedure TFPReportExportCanvas.RenderImage(const ABand: TFPReportCustomBand; const AImage: TFPReportCustomImage);
var
  lPt: TFPReportPoint;
  img: TReportImageFriend;
  PT : TPoint;
  R : TRect;
  G : TBitmap;
  BL,IL : TFPReportLayout;

begin
  img := TReportImageFriend(AImage);  { for access to Protected methods }
  BL:=GetLayout(ABand);
  IL:=GetLayout(AImage);
  lPt.Left := BL.Left + IL.Left;
  lPt.Top := BL.Top + IL.Top;
  PT:=CoordToPoint(Lpt,0,0);

  { Frame must be drawn before the Image as it could have a fill color. }
  RenderFrame(ABand, AImage.Frame, lPt, IL.Width, IL.Height);
  if not Assigned(img.Image) then
    Exit; { nothing further to do }
  G:=CreateBitmapFromFPImage(img.Image);
  try
    if img.Stretched then
      begin
      R:=Rect(pt.X,pT.Y,pt.X+HmmToPixels(IL.Width), pt.Y+VmmToPixels(IL.Height));
      Canvas.StretchDraw(R,G)
      end
    else
      Canvas.Draw(pt.X,pT.Y,G);
  finally
    G.Free;
  end;
  if DrawMode=dmDesign then
    DrawElementCorners(AImage,R);
end;

procedure TFPReportExportCanvas.RenderCheckbox(const ABand: TFPReportCustomBand; const ACheckbox: TFPReportCustomCheckbox);
var
  lPt: TFPReportPoint;
  pt : TPoint;
  cb: TReportCheckboxFriend;
  lImage: TFPCustomImage;
  G : TBitmap;
  R : TRect;
  BL,CL : TFPReportLayout;

begin
  cb := TReportCheckboxFriend(ACheckbox);  { for access to Protected methods }
  BL:=GetLayout(ABand);
  CL:=GetLayout(ACheckbox);
  lPt.Left := BL.Left + CL.Left;
  lPt.Top := BL.Top + CL.Top;
  Pt:=CoordToPoint(lpt);
  lImage:=cb.GetRTImage;
  G:=CreateBitmapFromFPImage(lImage);
  try
    R:=Rect(pt.X,Pt.Y,pt.X+HmmToPixels(CL.Width), pt.Y+VmmToPixels(CL.Height));
    Canvas.StretchDraw(R,g);
  finally
    G.Free;
  end;
  if DrawMode=dmDesign then
    DrawElementCorners(ACheckBox,R);
end;

constructor TFPReportExportCanvas.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FHDPI := Screen.PixelsPerInch;
  FVDPI := FHDPI;
  Zoom:=1;
  FImageWidth := 0;
  FImageHeight := 0;
  // store the original DPI, we will restore it later
  FFonts:=TFPObjectHashTable.Create(True);
  FShowBandTypeNames:=True;
end;

destructor TFPReportExportCanvas.Destroy;
begin
  FreeAndNil(FHyperLinks);
  FreeAndNil(FFonts);
  inherited Destroy;
end;

procedure TFPReportExportCanvas.GetCurrentPageRenderSize(out AWidth,
  AHeight: Integer);
begin
  GetPageRenderSize(CurrentPage,AWidth,AHeight);
end;

procedure TFPReportExportCanvas.GetPageRenderSize(APage: TFPReportCustomPage;
  out AWidth, AHeight: Integer);
begin
  if (APage.Orientation=poPortrait) then
    begin
    AWidth := HmmToPixels(APage.PageSize.Width);
    AHeight := VmmToPixels(APage.PageSize.Height);
    end
  else
    begin
    AWidth := VmmToPixels(APage.PageSize.Height);
    AHeight := HmmToPixels(APage.PageSize.Width);
    end;
end;

procedure TFPReportExportCanvas.RenderElement(ABand : TFPReportCustomBand; Element : TFPReportElement);

Var
  C : TFPReportPoint;
  LB,LE : TFPReportLayout;

begin
  {$IFDEF DEBUGRD}
  Writeln('Rendering element ',Element.ClassName,' (',Element.Name,')');
  {$ENDIF}
  if (Element is TFPReportCustomBand)  then
    RenderBand(Element as TFPReportCustomBand);
  if Element is TFPReportCustomMemo then
    RenderMemo(Aband,TFPReportCustomMemo(Element))
  else if Element is TFPReportCustomShape then
    RenderShape(ABand,TFPReportCustomShape(Element))
  else if Element is TFPReportCustomImage then
    RenderImage(Aband,TFPReportCustomImage(Element))
  else if Element is TFPReportCustomCheckbox then
    RenderCheckbox(ABand,TFPReportCustomCheckbox(Element))
  else if not (Element is TFPReportCustomBand) then
    begin
    LB:=GetLayout(ABand);
    LE:=GetLayout(Element);
    C.Left := LB.Left + LE.Left;
    C.Top := LB.Top + LE.Top ; // + Element.RTLayout.Height;
    RenderFrame(ABand, Element.Frame, C, LE.Width, LE.Height);
    C.Left:=LB.Left;
    C.Top:=LB.Top;
    RenderUnknownElement(C,Element,Self.VDPI);
    end;
end;

procedure TFPReportExportCanvas.SetHyperlinksEnabled(AValue: Boolean);
begin
  {$IFDEF DEBUGRD}Writeln('TFPReportExportCanvas.SetHyperlinksEnabled(',AValue,')');{$ENDIF}
  if (AValue=GetHyperLinksEnabled) then exit;
  If AValue then
    FHyperLinks:=CreateHyperlinks
  else
    FreeAndNil(FHyperLinks);
end;

procedure TFPReportExportCanvas.SetPageIndex(AValue: Integer);
begin
  if FPageIndex=AValue then Exit;
  FPageIndex:=AValue;
  if Assigned(Report) and (FPageIndex<0) or (FPageIndex>=PageCount) then
    Raise EReportError.CreateFmt(SErrPageOutOfRange,[FPageIndex,PageCount-1]);
  RenderCurrentPage;
end;

function TFPReportExportCanvas.CreateHyperlinks: THyperLinkList;
begin
  {$IFDEF DEBUGRD}Writeln('TFPReportExportCanvas.CreateHyperlinks');{$ENDIF}
  Result:=THyperLinkList.Create(THyperLinkItem);
end;

function TFPReportExportCanvas.GetLayout(AElement: TFPReportElement
  ): TFPReportLayout;

begin
  if DrawMode=dmRender then
    Result:=AElement.RTLayout
  else
    Result:=AElement.Layout;
end;

function TFPReportExportCanvas.BandColorCode(ABand: TFPReportCustomBandClass;
  Edge: Boolean): TColor;

begin
  if Edge then
    Result := RGBtoBGR(DefaultBandRectangleColors[ABand.ReportBandType])
  else
    Result := RGBtoBGR(DefaultBandColors[ABand.ReportBandType]);
end;

procedure TFPReportExportCanvas.DrawBandLabel(Aband: TFPReportCustomBand; l : TFPReportLayout);
Var
  N : String;
  TH,X,Y : Integer;
  TopLeft : TFPReportPoint;
begin
  TopLeft.Left:=L.Left;
  TopLeft.Top:=L.Top;
  N:=ABand.Name;
  if N='' then
    N:='Unnamed '+DefaultBandNames[ABand.ReportBandType]+' band'
  else if ShowBandTypeNames then
    N:=N+' ('+DefaultBandNames[ABand.ReportBandType]+')';
  Canvas.Font.Name:='default';
  Canvas.Font.Size:=10;
  Canvas.Font.Style:=[];
  Canvas.Font.Color:=clBlack;
  TH:=GetBandHandleHeight;
  X:=FHorzOffset+HmmToPixels(TopLeft.Left);
  Y:=FVertOffset+VmmToPixels(TopLeft.Top)-TH-2*BandTitleMargin;
  Canvas.Brush.Color:=BandColorCode(TFPReportCustomBandClass(ABand.ClassType),False);
  Canvas.Pen.Style:=psSolid;
  Canvas.Pen.Color:=BandColorCode(TFPReportCustomBandClass(ABand.ClassType),True);
  Canvas.Rectangle(X,Y,X+HmmToPixels(L.Width),Y+TH+2*BandTitleMargin);
  Y:=Y+BandTitleMargin;
  X:=X+BandTitleMargin;
 {$IFDEF DEBUGRD}Writeln('Writing name : Canvas.TextOut(',X,',',Y,',',N,')');{$ENDIF}
  Canvas.TextOut(X,Y,N);
end;

procedure TFPReportExportCanvas.DrawElementCorners(E : TFPReportElement; R : TRect);


begin
  Canvas.Pen.Style:=psSolid;
  Canvas.Pen.Color:=clEmementCorner;
  // Horizontal, top
  Canvas.Line(R.Left,R.Top,R.Left+ElementHCornerLength,R.Top);
  Canvas.Line(R.Right-ElementHCornerLength,R.Top,R.Right,R.Top);
  // Horizontal, bottom
  Canvas.Line(R.Left,R.Bottom,R.Left+ElementHCornerLength,R.Bottom);
  Canvas.Line(R.Right-ElementHCornerLength,R.Bottom,R.Right,R.Bottom);
  // Vertical, Top
  Canvas.Line(R.Left,R.Top,R.Left,R.Top+ElementVCornerLength);
  Canvas.Line(R.Right,R.Top,R.Right,R.Top+ElementVCornerLength);
  // Vertical, bottom
  Canvas.Line(R.Left,R.Bottom,R.Left,R.Bottom-ElementVCornerLength);
  Canvas.Line(R.Right,R.Bottom,R.Right,R.Bottom-ElementVCornerLength);
end;

procedure TFPReportExportCanvas.DrawBandRect(Aband: TFPReportCustomBand; l : TFPReportLayout);

Var
  DR : TRect;

begin
  DR:=GetBandRect(L,False);
  Canvas.Brush.Style:=bsClear;
  Canvas.Pen.Style:=psSolid;
  Canvas.Pen.Color:=BandColorCode(TFPReportCustomBandClass(ABand.ClassType),true);
  Canvas.Rectangle(DR);
  DrawElementCorners(ABand,DR);
end;

procedure TFPReportExportCanvas.RenderBand(Aband: TFPReportCustomBand);

Var
  lPt1: TFPReportPoint;  // original Report point
  I : integer;
  L : TFPReportLayout;

begin
  L:=GetLayout(ABand);
  {$IFDEF DEBUGRD}
  Writeln('Renderband ',ABand.ClassName,' : ',ABand.Name,' (',L.Width,' x ',L.Height,')');
  {$ENDIF}
  if DrawMode=dmDesign then
    begin
    DrawBandLabel(ABand,L);
    DrawBandRect(Aband,L);
    end;
  lpt1.Left:=L.Left;
  lpt1.Top:=L.Top;
  RenderFrame(Aband, Aband.Frame, lPt1, L.Width, L.Height);
  if DrawMode=dmRender then
    for I:=0 to Aband.ChildCount-1 do
      RenderElement(ABand,Aband.Child[i]);
end;

procedure TFPReportExportCanvas.RenderCurrentPage;

var
  b: integer;
  rpage: TFPReportPage;

begin
  If Not Assigned(Canvas) then exit;
  rpage := CurrentPage;
  If Not Assigned(rpage) then exit;
  SetupPageRender(rpage);
  for b := 0 to (rpage.BandCount - 1) do
    RenderBand(rpage.Bands[b]);
end;

function TFPReportExportCanvas.GetBandRect(L: TFPReportLayout;IncludeHandle: Boolean): TRect;

Var
  LPT1 : TFPReportPoint;

begin
  lpt1.Left:=L.Left;
  lpt1.Top:=L.Top;
  Result:=CoordToRect(LPT1,L.Width, L.Height);
  if IncludeHandle then
    Result.Top:=Result.Top-GetBandHandleHeight;
end;

function TFPReportExportCanvas.GetBandRect(ABand: TFPReportCustomBand;
  IncludeHandle: Boolean): TRect;
begin
  Result:=GetBandRect(GetLayout(ABand),IncludeHandle);
end;

function TFPReportExportCanvas.GetElementRect(BandLayout,
  ElementLayout: TFPReportLayout): TRect;

Var
  LPT1 : TFPReportPoint;

begin
  lpt1.Left:=BandLayout.Left+ElementLayout.Left;
  lpt1.Top:=BandLayout.Top+ElementLayout.Top;
  Result:=CoordToRect(LPT1,ElementLayout.Width,ElementLayout.Height);
end;

function TFPReportExportCanvas.GetElementRect(ABand: TFPReportCustomBand;
  AElement: TFPReportElement): TRect;
begin
  Result:=GetElementRect(GetLayout(ABand),GetLayout(AElement));
end;

procedure TFPReportExportCanvas.DrawSelectionHandle(ACenter: TPoint;
  AColor: TColor);

begin
  With Canvas do
    begin
    Brush.Color:=AColor;
    Brush.Style:=bsSolid;
    Pen.Color:=AColor;
    Pen.Style:=psSolid;
    {$IFDEF DEBUGRD}Writeln('Drawing selection handle at (',ACenter.X,',',ACenter.Y,')');{$ENDIF}
    with ACenter do
      Rectangle(X-ReSizeHandleHalfWidth,Y-ReSizeHandleHalfWidth,X+ReSizeHandleHalfWidth,Y+ReSizeHandleHalfWidth);
    end;
end;

procedure TFPReportExportCanvas.DrawSelectionRect(ARect: Trect);
begin
  Canvas.Brush.Style:=bsClear;
  Canvas.Pen.Color:=clSelectionRect;
  Canvas.Pen.Style:=psDash;
  Canvas.Rectangle(ARect);
end;

procedure TFPReportExportCanvas.DoExecute(const ARTObjects: TFPList);

begin
  FPages:=ARTObjects;
  RenderCurrentPage;
end;

end.