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
|
{
This file is part of the Free Component Library.
Copyright (c) 2016 Michael Van Canneyt, member of the Free Pascal development team
Configure FPReport to fpimage export dialog to be used in LCL preview.
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 cfgfpreportimageexport;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, EditBtn,
StdCtrls, ButtonPanel, ExtCtrls, Spin, fpreport, fpreportfpimageexport;
type
{ TConfigFPImageExportForm }
TConfigFPImageExportForm = class(TForm)
BPExport: TButtonPanel;
CBDPI: TComboBox;
ESeparator: TEdit;
FEBaseFileName: TFileNameEdit;
GBOptions: TGroupBox;
LCBDPI: TLabel;
LSEDigits: TLabel;
LFEPDF: TLabel;
LESeparator: TLabel;
SEDigits: TSpinEdit;
procedure FormCreate(Sender: TObject);
private
procedure GetImageFilter;
procedure LocalizeForm;
{ private declarations }
public
{ public declarations TFPReportExportfpImage }
Procedure ConfigToForm(AExporter: TFPReportExportfpImage);
Procedure FormToConfig(AExporter: TFPReportExportfpImage);
end;
{ TFPImageConfigObj }
TFPImageConfigObj = Class
public
Procedure RegisterHandler;
procedure DoConfig(Sender: TObject; AExporter: TFPReportExporter; var Cancelled: Boolean);
end;
var
ConfigPDFExportForm: TConfigFPImageExportForm;
Procedure RegisterPDFExportConfig;
implementation
uses fpimage, fppdf;
{$R *.lfm}
Var
Cfg : TFPImageConfigObj;
Resourcestring
sConfigImageFormCaption = 'Export to Images';
SImageFileName = '&FileName';
SImageFilters = 'PDF Files|*.pdf|All files|*.*';
SImageDPI = '&DPI';
SImageDigits = '&Min. digits' ;
SImageSeparator = '&Separator' ;
SIMageOptions = 'Options';
SFiles = 'Files';
Procedure RegisterPDFExportConfig;
begin
FreeAndNil(Cfg);
Cfg:=TFPImageConfigObj.Create;
Cfg.RegisterHandler;
end;
{ TConfigFPImageExportForm }
procedure TConfigFPImageExportForm.LocalizeForm;
begin
Caption:=sConfigImageFormCaption;
LFEPDF.Caption:= SImageFileName;
FEBaseFileName.Filter:=SImageFilters;
LCBDPI.Caption:=SImageDPI;
LSEDigits.Caption:=SImageDigits;
GBOptions.Caption:=SImageOptions;
LESeparator.Caption:=SImageSeparator;
GetImageFilter;
end;
procedure TConfigFPImageExportForm.GetImageFilter;
Var
I : Integer;
S,TN : String;
begin
S:='';
with ImageHandlers do
For I:=0 to Count-1 do
begin
TN:=TypeNames[I];
if (S<>'') then
S:=S+'|';
S:=S+TN+' '+SFiles+'|*'+{$IFDEF VER2_6_4}DefaultExtention[TN]{$else}DefaultExtension[TN]{$ENDIF};
end;
FEBaseFileName.Filter:=S;
end;
procedure TConfigFPImageExportForm.FormCreate(Sender: TObject);
begin
LocalizeForm;
end;
procedure TConfigFPImageExportForm.ConfigToForm(AExporter: TFPReportExportfpImage);
begin
CBDPI.Text:=IntToStr(AExporter.DPI);
end;
procedure TConfigFPImageExportForm.FormToConfig(AExporter: TFPReportExportfpImage);
Var
Sep : String;
begin
AExporter.BaseFileName:=FEBaseFileName.FileName;
Sep:=StringReplace(ESeparator.Caption,'%','%%',[]);
if SEDigits.Value=1 then
AExporter.SequenceFormat:=Sep+'%d'
else
AExporter.SequenceFormat:=Sep+'%.'+IntToStr(SEDigits.Value)+'d';
end;
{ TFPImageConfigObj }
procedure TFPImageConfigObj.RegisterHandler;
begin
if ReportExportManager.FindExporter(TFPReportExportfpImage.Name)<>Nil then
ReportExportManager.RegisterConfigHandler(TFPReportExportfpImage.Name,@DoConfig);
end;
procedure TFPImageConfigObj.DoConfig(Sender: TObject; AExporter: TFPReportExporter;
var Cancelled: Boolean);
begin
Cancelled:=True;
With TConfigFPImageExportForm.Create(Application) do
try
ConfigToForm(AExporter as TFPReportExportfpImage);
Cancelled:=ShowModal<>mrOK;
if not Cancelled then
FormToConfig(AExporter as TFPReportExportfpImage);
finally
Free;
end;
end;
initialization
RegisterPDFExportConfig;
finalization
FreeAndNil(Cfg);
end.
|