1{
2    This file is part of the Free Component Library.
3    Copyright (c) 2016 Michael Van Canneyt, member of the Free Pascal development team
4
5    Configure FPReport to fpimage export dialog to be used in LCL preview.
6
7    See the file COPYING.FPC, included in this distribution,
8    for details about the copyright.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 **********************************************************************}
15
16unit cfgfpreportimageexport;
17
18{$mode objfpc}{$H+}
19
20interface
21
22uses
23  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
24  StdCtrls, ButtonPanel, ExtCtrls, Spin, fpreport, fpreportfpimageexport;
25
26type
27  { TConfigFPImageExportForm }
28
29  TConfigFPImageExportForm = class(TForm)
30    BPExport: TButtonPanel;
31    CBDPI: TComboBox;
32    ESeparator: TEdit;
33    FEBaseFileName: TFileNameEdit;
34    GBOptions: TGroupBox;
35    LCBDPI: TLabel;
36    LSEDigits: TLabel;
37    LFEPDF: TLabel;
38    LESeparator: TLabel;
39    SEDigits: TSpinEdit;
40    procedure FormCreate(Sender: TObject);
41  private
42    procedure GetImageFilter;
43    procedure LocalizeForm;
44    { private declarations }
45  public
46    { public declarations TFPReportExportfpImage }
47    Procedure ConfigToForm(AExporter: TFPReportExportfpImage);
48    Procedure FormToConfig(AExporter: TFPReportExportfpImage);
49  end;
50
51  { TFPImageConfigObj }
52
53  TFPImageConfigObj = Class
54  public
55    Procedure RegisterHandler;
56    procedure DoConfig(Sender: TObject; AExporter: TFPReportExporter; var Cancelled: Boolean);
57  end;
58
59var
60  ConfigPDFExportForm: TConfigFPImageExportForm;
61
62Procedure RegisterPDFExportConfig;
63
64implementation
65
66uses fpimage, fppdf;
67
68{$R *.lfm}
69
70Var
71  Cfg : TFPImageConfigObj;
72
73Resourcestring
74  sConfigImageFormCaption = 'Export to Images';
75  SImageFileName    = '&FileName';
76  SImageFilters = 'PDF Files|*.pdf|All files|*.*';
77  SImageDPI = '&DPI';
78  SImageDigits = '&Min. digits' ;
79  SImageSeparator = '&Separator' ;
80  SIMageOptions = 'Options';
81  SFiles = 'Files';
82
83Procedure RegisterPDFExportConfig;
84
85begin
86  FreeAndNil(Cfg);
87  Cfg:=TFPImageConfigObj.Create;
88  Cfg.RegisterHandler;
89end;
90
91{ TConfigFPImageExportForm }
92
93procedure TConfigFPImageExportForm.LocalizeForm;
94
95
96begin
97  Caption:=sConfigImageFormCaption;
98  LFEPDF.Caption:= SImageFileName;
99  FEBaseFileName.Filter:=SImageFilters;
100  LCBDPI.Caption:=SImageDPI;
101  LSEDigits.Caption:=SImageDigits;
102  GBOptions.Caption:=SImageOptions;
103  LESeparator.Caption:=SImageSeparator;
104  GetImageFilter;
105end;
106
107procedure TConfigFPImageExportForm.GetImageFilter;
108
109Var
110  I : Integer;
111  S,TN : String;
112
113begin
114  S:='';
115  with ImageHandlers do
116    For I:=0 to Count-1 do
117      begin
118      TN:=TypeNames[I];
119      if (S<>'') then
120        S:=S+'|';
121
122      S:=S+TN+' '+SFiles+'|*'+{$IFDEF VER2_6_4}DefaultExtention[TN]{$else}DefaultExtension[TN]{$ENDIF};
123      end;
124  FEBaseFileName.Filter:=S;
125end;
126
127procedure TConfigFPImageExportForm.FormCreate(Sender: TObject);
128begin
129  LocalizeForm;
130end;
131
132procedure TConfigFPImageExportForm.ConfigToForm(AExporter: TFPReportExportfpImage);
133begin
134  CBDPI.Text:=IntToStr(AExporter.DPI);
135end;
136
137procedure TConfigFPImageExportForm.FormToConfig(AExporter: TFPReportExportfpImage);
138Var
139  Sep : String;
140
141begin
142  AExporter.BaseFileName:=FEBaseFileName.FileName;
143  Sep:=StringReplace(ESeparator.Caption,'%','%%',[]);
144  if SEDigits.Value=1 then
145    AExporter.SequenceFormat:=Sep+'%d'
146  else
147    AExporter.SequenceFormat:=Sep+'%.'+IntToStr(SEDigits.Value)+'d';
148end;
149
150
151{ TFPImageConfigObj }
152
153procedure TFPImageConfigObj.RegisterHandler;
154begin
155  if ReportExportManager.FindExporter(TFPReportExportfpImage.Name)<>Nil then
156    ReportExportManager.RegisterConfigHandler(TFPReportExportfpImage.Name,@DoConfig);
157end;
158
159procedure TFPImageConfigObj.DoConfig(Sender: TObject; AExporter: TFPReportExporter;
160  var Cancelled: Boolean);
161begin
162  Cancelled:=True;
163  With TConfigFPImageExportForm.Create(Application) do
164    try
165      ConfigToForm(AExporter as TFPReportExportfpImage);
166      Cancelled:=ShowModal<>mrOK;
167      if not Cancelled then
168        FormToConfig(AExporter as TFPReportExportfpImage);
169    finally
170      Free;
171    end;
172end;
173
174initialization
175  RegisterPDFExportConfig;
176finalization
177  FreeAndNil(Cfg);
178end.
179
180