{******************************************} { } { FastReport v4.0 } { HTML table export filter } { } { Copyright (c) 1998-2008 } { by Alexander Fediachov, } { Fast Reports Inc. } { } {******************************************} unit FMX.frxExportHTML; interface {$I fmx.inc} {$I frx.inc} {$I fmx.inc} uses System.SysUtils, System.Classes, FMX.Types, System.UITypes, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.frxClass, FMX.frxExportMatrix, FMX.frxProgress, fmx.frxImageConverter, System.UIConsts, System.Variants, FMX.Edit, FMX.ListBox, FMX.frxBaseModalForm {$IFDEF DELPHI18} ,FMX.StdCtrls {$ENDIF} {$IFDEF DELPHI19} , FMX.Graphics {$ENDIF}; type TfrxHTMLExportDialog = class(TfrxForm) SaveDialog1: TSaveDialog; GroupQuality: TGroupBox; StylesCB: TCheckBox; PicsSameCB: TCheckBox; FixWidthCB: TCheckBox; NavigatorCB: TCheckBox; MultipageCB: TCheckBox; GroupPageRange: TGroupBox; DescrL: TLabel; AllRB: TRadioButton; CurPageRB: TRadioButton; PageNumbersRB: TRadioButton; PageNumbersE: TEdit; OpenAfterCB: TCheckBox; OkB: TButton; CancelB: TButton; BackgrCB: TCheckBox; PicturesL: TLabel; PFormatCB: TComboBox; ListBoxItem1: TListBoxItem; ListBoxItem2: TListBoxItem; ListBoxItem3: TListBoxItem; ListBoxItem4: TListBoxItem; procedure FormCreate(Sender: TObject); procedure PageNumbersEChange(Sender: TObject); procedure PageNumbersEKeyPress(Sender: TObject; var Key: Char); procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar; Shift: TShiftState); end; TfrxHTMLExportGetNavTemplate = procedure(const ReportName: String; Multipage: Boolean; PicsInSameFolder: Boolean; Prefix: String; TotalPages: Integer; var Template: String) of object; TfrxHTMLExportGetMainTemplate = procedure(const Title: String; const FrameFolder: String; Multipage: Boolean; var Template: String) of object; {$I frxFMX_PlatformsAttribute.inc} TfrxHTMLExport = class(TfrxCustomExportFilter) private Exp: TStream; FAbsLinks: Boolean; FCurrentPage: Integer; FExportPictures: Boolean; FExportStyles: Boolean; FFixedWidth: Boolean; FMatrix: TfrxIEMatrix; FMozillaBrowser: Boolean; FMultipage: Boolean; FNavigator: Boolean; FOpenAfterExport: Boolean; FPicsInSameFolder: Boolean; FPicturesCount: Integer; FProgress: TfrxProgress; FServer: Boolean; FPrintLink: String; FRefreshLink: String; FBackground: Boolean; FBackImage: TBitmap; FBackImageExist: Boolean; FReportPath: String; FCentered: Boolean; FEmptyLines: Boolean; FURLTarget: String; FPictureType: TfrxPictureType; // FAvExports: String; // FSession: String; FPrint: Boolean; FUseTemplates: Boolean; FGetNavTemplate: TfrxHTMLExportGetNavTemplate; FGetMainTemplate: TfrxHTMLExportGetMainTemplate; FHTMLDocumentBegin: TStrings; FHTMLDocumentBody: TStrings; FHTMLDocumentEnd: TStrings; procedure WriteExpLn(const str: String); procedure WriteExpLnA(const str: AnsiString); procedure ExportPage; function ChangeReturns(const Str: String): String; function TruncReturns(const Str: WideString): WideString; function GetPicsFolder: String; function GetPicsFolderRel: String; function GetFrameFolder: String; function ReverseSlash(const S: String): String; function HTMLCodeStr(const Str: String): String; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; function ShowModal: TModalResult; override; function Start: Boolean; override; procedure Finish; override; procedure FinishPage(Page: TfrxReportPage; Index: Integer); override; procedure StartPage(Page: TfrxReportPage; Index: Integer); override; procedure ExportObject(Obj: TfrxComponent); override; class function GetDescription: String; override; property Server: Boolean read FServer write FServer; property PrintLink: String read FPrintLink write FPrintLink; property RefreshLink: String read FRefreshLink write FRefreshLink; property ReportPath: String read FReportPath write FReportPath; property UseTemplates: Boolean read FUseTemplates write FUseTemplates; property OnGetMainTemplate: TfrxHTMLExportGetMainTemplate read FGetMainTemplate write FGetMainTemplate; property OnGetNavTemplate: TfrxHTMLExportGetNavTemplate read FGetNavTemplate write FGetNavTemplate; published property OpenAfterExport: Boolean read FOpenAfterExport write FOpenAfterExport default False; property FixedWidth: Boolean read FFixedWidth write FFixedWidth default False; property ExportPictures: Boolean read FExportPictures write FExportPictures default True; property PicsInSameFolder: Boolean read FPicsInSameFolder write FPicsInSameFolder default False; property ExportStyles: Boolean read FExportStyles write FExportStyles default True; property Navigator: Boolean read FNavigator write FNavigator default False; property Multipage: Boolean read FMultipage write FMultipage default False; property MozillaFrames: Boolean read FMozillaBrowser write FMozillaBrowser default False; property AbsLinks: Boolean read FAbsLinks write FAbsLinks default False; property Background: Boolean read FBackground write FBackground; property Centered: Boolean read FCentered write FCentered; property EmptyLines: Boolean read FEmptyLines write FEmptyLines; property OverwritePrompt; property HTMLDocumentBegin: TStrings read FHTMLDocumentBegin; property HTMLDocumentBody: TStrings read FHTMLDocumentBody; property HTMLDocumentEnd: TStrings read FHTMLDocumentEnd; property URLTarget: String read FURLTarget write FURLTarget; property Print: Boolean read FPrint write FPrint; property PictureType: TfrxPictureType read FPictureType write FPictureType; end; implementation uses FMX.frxUtils, {FMX.frxFileUtils,} FMX.frxUnicodeUtils, FMX.frxRes, FMX.frxrcExports, System.Math, FMX.frxGraphicUtils, FMX.frxFMX {$IFDEF MSWINDOWS} , Winapi.ShellAPI {$ENDIF} {$IFDEF LINUX} ,FMUX.Api {$ENDIF}; {$R *.fmx} const Xdivider = 1; Ydivider = 1.03; Navigator_src = ''#13#10 + '
' + '' + '' + ''; end; if FMatrix.Width < 2 then columnWidths := columnWidths + ' | '; columnWidths := columnWidths + ' |
'; if Length(Obj.URL) > 0 then begin if Obj.URL[1] = '@' then if FMultipage then begin Obj.URL := StringReplace(Obj.URL, '@', '', []); Obj.URL := ReverseSlash(GetPicsFolderRel + Trim(Obj.URL) + '.html') end else Obj.URL := StringReplace(Obj.URL, '@', '#PageN', []); if FURLTarget <> '' then s := ' target=' + FURLTarget else s := ''; buff := buff + ''; hlink := True; end else hlink := False; if Obj.IsText then begin text := Trim(ChangeReturns(TruncReturns(Obj.Memo.Text))); if Length(text) > 0 then buff := buff + text else buff := buff + ' '; end else if Obj.Image <> nil then begin s := GetPicsFolder + 'img' + IntToStr(FPicturesCount) + '.' + GetPicFileExtension(PictureType); s1 := ExtractFilePath(s); if (s1 = ChangeFileExt(ExtractFileName(frxUnixPath2WinPath(FileName)), '.files' + PathDelim)) or (s1 = '') then s := ExtractFilePath(filename) + s; SaveGraphicAs(Obj.Image, s, PictureType); Files.Add(s); s := ReverseSlash(GetPicsFolderRel + 'img' + IntToStr(FPicturesCount) + '.' + GetPicFileExtension(PictureType)); buff := buff + Format('', [UTF8Encode(s), Obj.Image.Width, Obj.Image.Height]); Inc(FPicturesCount); end; if hlink then buff := buff + ''; buff := buff + ' | '; end; end else buff := buff + ''; end; WriteExpLn(buff); WriteExpLn(' |