mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-22 06:19:21 +02:00
LazReport, two additional export filters - TfrImageExportFilter, TfrHtmlDivExportFilter, from Michel Gawrycki
git-svn-id: trunk@38952 -
This commit is contained in:
parent
1b11439a5b
commit
7152323181
14
.gitattributes
vendored
14
.gitattributes
vendored
@ -1863,6 +1863,20 @@ components/lazreport/source/addons/addfunction/lrAddFunctionLibrary.pas svneol=n
|
||||
components/lazreport/source/addons/addfunction/lr_add_function.lpk svneol=native#text/plain
|
||||
components/lazreport/source/addons/addfunction/lr_add_function.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/addfunction/lr_add_function_const.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/lr_e_extexp.lrs svneol=native#text/plain
|
||||
components/lazreport/source/addons/imgexport/lr_e_extreg.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/lr_e_htmldiv.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/lr_e_img.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/lr_extexp.lpk svneol=native#text/plain
|
||||
components/lazreport/source/addons/imgexport/lr_extexp.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/test/test.ico -text
|
||||
components/lazreport/source/addons/imgexport/test/test.lpi svneol=native#text/plain
|
||||
components/lazreport/source/addons/imgexport/test/test.lpr svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/test/test.res -text
|
||||
components/lazreport/source/addons/imgexport/test/testunit1.lfm svneol=native#text/plain
|
||||
components/lazreport/source/addons/imgexport/test/testunit1.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/imgexport/tfrhtmldivexport.png -text
|
||||
components/lazreport/source/addons/imgexport/tfrimageexport.png -text
|
||||
components/lazreport/source/addons/lrcodereport/lr_codereport.lrs svneol=native#text/plain
|
||||
components/lazreport/source/addons/lrcodereport/lr_codereport.pas svneol=native#text/pascal
|
||||
components/lazreport/source/addons/lrcodereport/lr_codereport_pkg.lpk svneol=native#text/plain
|
||||
|
@ -12,6 +12,7 @@ Junior Goncalves (br)
|
||||
Julio Jiménez B. (es)
|
||||
Luiz Americo (br)
|
||||
Mattias Gaertner (de)
|
||||
Michel Gawrycki ( )
|
||||
Olivier Guilbaud (fr)
|
||||
Petr Smolik (cz)
|
||||
Tony Whyman ( )
|
||||
|
53
components/lazreport/source/addons/imgexport/lr_e_extexp.lrs
Normal file
53
components/lazreport/source/addons/imgexport/lr_e_extexp.lrs
Normal file
@ -0,0 +1,53 @@
|
||||
LazarusResources.Add('tfrhtmldivexport','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147#0#0#0#9'pHYs'#0#0#11#19#0#0#11
|
||||
+#19#1#0#154#156#24#0#0#0#7'tIME'#7#220#9#21#17#9''''#170#211'tM'#0#0#2#18'ID'
|
||||
+'ATH'#199#213#148'?h'#19'a'#24#198#127#215#166#181#8#206#154#233#210'1'#224
|
||||
+'P'#28#180#174#130#161'!'#139#139'nf('#201#149#148#138'`n'#16#145' '#10#157
|
||||
+#226' '#13#25#218#155#130#22'*'#8'"'#132#11'w%E'#151'6'#224#191'E2'#137'w'
|
||||
+#136#6#7#11#14#150'ZI'#206#161#220#245#254#165#185#180':'#248'L'#223#189'w'
|
||||
+#239#247#188#207'='#207#247#193'?'#134#0' '#229#243'V'#212#134#229#149#21'!'
|
||||
+#172#222#133#171#2#220#3'&'#129#15']('#142#193'+l'#130'('#144#242'y'#171#181
|
||||
+#185#25':L'#15#158#238#193#217#207'0'#209#133'\'#15#190#0#196#220#31#205#164
|
||||
+'R}''oh'#218#161#202'F'#224#154#189#222#133#141'q'#184#29' '#24#180'I'#20#252
|
||||
+#132'3'#227#176#214#131'['#1#130#147#23#238#0#176#211'Z'#12#168'ih'#26'SW'
|
||||
+#238's'#243'I'#155#233#133#166#243#155#178#233'$'#243#153#184#0#240#27#206
|
||||
+#143#194#154#5'wc'#240'"@0'#140#154'l:'#9'@MmS'#173'w'#172#185'L\'#18#224'A'
|
||||
+#15#174#199'@'#183#191#235'K'#16#166#224#253#243#18#143'fgy'#179#157#160#166
|
||||
+#182#201#166#147'd'#211'Ijj'#155#2','#3#140#130'f'#203#251#14#167'<'#4';'#173
|
||||
+#197'H'#10#230'3q'#161'Z'#239'Xn'#146#139'4'#217#170'\'#10'D'#248#175#165#8
|
||||
+#160'Z'#239'X'#182#31#161#4'QS4'#189#208't'#166'w{RS'#247#3#224'V2PAC'#211
|
||||
+#152'I'#165'<'#228#246'f'#253#204#223#170#12#169#192'_'#247'{`'#167#201#29
|
||||
+#217#0#193#156'$'#13'u'#160#220'$'#254#243#16#184#236#212#215#219#214'QO'#238
|
||||
+#167'o'#191#0#152'<}'#194'S/'#20'K'#24'/+'#130#163'`'#253#221#143'c]'#17#31
|
||||
+#191#238#134#214'='#30#148's'#9'd'#197'p'#214'oM8'''#30#188#183#159'M'#211'd'
|
||||
+'I'#183#184'qY@'#20'Ed'#197#240#244#250'.'#193#254'X'#213#13#167'IV'#12'V'
|
||||
+#245#253#181'('#138#206#230#131#16' ('#231#18#148's'#137'C'#155'd'#197'p&'#31
|
||||
+#154'@V'#140'H'#141#166'iF'#242'f'#228#168#166'.'#233#193#224#133#169'wbz'
|
||||
+#220#20#249#241#236#241#195#131#152#22#138'%'#254'['#252#1'(D'#6'9'#2#1'OS'#0
|
||||
+#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
||||
LazarusResources.Add('tfrimageexport','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147#0#0#0#9'pHYs'#0#0#11#19#0#0#11
|
||||
+#19#1#0#154#156#24#0#0#0#7'tIME'#7#220#9#21#17#4'!'#246#30#175'5'#0#0#1#170
|
||||
+'IDATH'#199#181#149'!L'#195'@'#20#134#191'[V'#131'A`'#192'a'#235'p`'#8#4#209
|
||||
+#208'`'#176'lI'#5'I'''#22#18'<'#2#129#192#147#144#9'pMn'#179#24#178#165'b'#22
|
||||
+'&Hp'#19#16','#24'H0'#152#137#135#232#214'm'#165'+w'#11'\ry'#185'ww'#239#127
|
||||
+#255#187#191#175#240#207'C'#1#212#194'PL/\]_+k'#148'Z'#24#138#201#168#133#161
|
||||
+#244#238#238#196'&vyr'#177#235'y3'#15'v'#226'x'#174#18#149#255'"'#136'1'#192
|
||||
+#194#250#9#0'_'#189#243#31'l:q'#204#218#254#25#199#186#207#198'Q7-S'#224#187
|
||||
+#212#247'V'#148#17#128#13#155#192'w'#1#136#218'}'#26#183#175'2'#11'd&@'#30
|
||||
+#131#199#155'S.'#14#15'y'#248'X%j'#247#9'|'#151#192'w'#11'A'#166#0#190'z'#231
|
||||
+'F'#12#234'{+'#170'q'#251'*Y'#144#127'WQ'#30#139#185'T'#180'q'#212'M'#179#159
|
||||
+'|'#147#168#157#8#224#254'rG'#25'3'#232#196'1'#187#158'7'#5'^T'#146#192'w'
|
||||
+#185#191#180'd'#144#245'g'#223'`'#164#166'<'#201#26#245#162#173#205#237'\'
|
||||
+#255#231#210'N'#202'$'#240']'#22#223#187#233'^5'#168#170#20#0#160#168#199'<?'
|
||||
+#189'P='#168#0' ('#20#227#163#141#248'-a'#229'-'#143'/8'#211#177#127#29':'
|
||||
+#210'"'#3#210#201'@'#138''''#227#12'J'#230'}}'#156#181#20'$'#151#221'+'#219
|
||||
+#255'@'#164'pW'#181#166'='#165#191#11#14#180'~'#186#172#0'd'#134#5#5#173#252
|
||||
+#178#149#204#131#171#164#186'N'#19#229'4'#135'6Y'#11#160#209'v'#237':'#183'<'
|
||||
+'N'#19#6#149#196'R'#1#18#171#28#128#10':'#26'~'#3'T'#237#30'VGZ '#145'*'#232
|
||||
+#161#20#181'@'#214#142#206' s'#0'`;'#1#248#6#155'm'#23#25'7'#246';<'#0#0#0#0
|
||||
+'IEND'#174'B`'#130
|
||||
]);
|
23
components/lazreport/source/addons/imgexport/lr_e_extreg.pas
Normal file
23
components/lazreport/source/addons/imgexport/lr_e_extreg.pas
Normal file
@ -0,0 +1,23 @@
|
||||
unit LR_e_extreg;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, LR_e_img, LR_e_htmldiv, LResources;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents('LazReport', [TfrImageExport, TfrHtmlDivExport]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I lr_e_extexp.lrs}
|
||||
|
||||
end.
|
||||
|
316
components/lazreport/source/addons/imgexport/lr_e_htmldiv.pas
Normal file
316
components/lazreport/source/addons/imgexport/lr_e_htmldiv.pas
Normal file
@ -0,0 +1,316 @@
|
||||
{*****
|
||||
|
||||
Copyright (c) 2012 Michał Gawrycki (michal.gawrycki(a.t.)gmsystems.pl
|
||||
License: modified LGPL (see 'COPYING.modifiedLGPL.txt' in Lazarus directory)
|
||||
|
||||
*****}
|
||||
|
||||
unit LR_e_htmldiv;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LR_Class, Graphics;
|
||||
|
||||
type
|
||||
TfrHtmlDivExport = class(TComponent)
|
||||
|
||||
end;
|
||||
|
||||
{ TfrHtmlDivExportFilter }
|
||||
|
||||
TfrHtmlDivExportFilter = class(TfrExportFilter)
|
||||
private
|
||||
FCurPage: integer;
|
||||
FImgCnt: Integer;
|
||||
FPageStyle: String;
|
||||
FExportImages: Boolean;
|
||||
FEmbeddedImages: Boolean;
|
||||
procedure WriteString(AValue: string);
|
||||
public
|
||||
constructor Create(AStream: TStream); override;
|
||||
procedure OnBeginDoc; override;
|
||||
procedure OnEndDoc; override;
|
||||
procedure OnBeginPage; override;
|
||||
procedure OnEndPage; override;
|
||||
procedure OnData(x, y: integer; View: TfrView); override;
|
||||
procedure OnText(x, y: integer; const Text: string; View: TfrView); override;
|
||||
property PageStyle: String read FPageStyle write FPageStyle;
|
||||
property ExportImages: Boolean read FExportImages write FExportImages;
|
||||
property EmbeddedImages: Boolean read FEmbeddedImages write FEmbeddedImages;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
base64, LR_BarC;
|
||||
|
||||
const
|
||||
HTML_REPORT_HEADER = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
|
||||
+ LineEnding + '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
|
||||
+ LineEnding + '<head>' + LineEnding +
|
||||
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' +
|
||||
LineEnding + '<title>%s</title>' + LineEnding + '<style type="text/css">' +
|
||||
LineEnding + '.page {position: relative;%s}' + LineEnding + '.fV {position: absolute;}'
|
||||
+ LineEnding + '</style>' + LineEnding + '</head>' + LineEnding + '<body>' + LineEnding;
|
||||
HTML_REPORT_END = '</body></html>';
|
||||
HTML_PAGE_START =
|
||||
'<div class="page" style="width:%dpx;min-width:%0:dpx;height:%dpx;min-height:%1:dpx;">'
|
||||
+ LineEnding;
|
||||
HTML_PAGE_END = '</div>' + LineEnding;
|
||||
HTML_BOX = '<div class="fV" style="%s"></div>' + LineEnding;
|
||||
HTML_IMG1 = '<img class="fV" style="%s" src="';
|
||||
HTML_IMG2 = ' " />' + LineEnding;
|
||||
HTML_TEXT = '<div class="fV" style="%s">%s</div>' + LineEnding;
|
||||
|
||||
type
|
||||
|
||||
{ TChunkStream }
|
||||
|
||||
TChunkStream = class(TOwnerStream)
|
||||
private
|
||||
FPos: Integer;
|
||||
FChunkSize: Integer;
|
||||
FSeparator: String;
|
||||
public
|
||||
constructor Create(ASource: TStream);
|
||||
function Write(const Buffer; Count: Longint): Longint; override;
|
||||
property ChunkSize: Integer read FChunkSize write FChunkSize;
|
||||
property Separator: String read FSeparator write FSeparator;
|
||||
end;
|
||||
|
||||
{ TChunkStream }
|
||||
|
||||
constructor TChunkStream.Create(ASource: TStream);
|
||||
begin
|
||||
inherited Create(ASource);
|
||||
FPos := 0;
|
||||
FSeparator := LineEnding;
|
||||
FChunkSize := 79;
|
||||
end;
|
||||
|
||||
function TChunkStream.Write(const Buffer; Count: Longint): Longint;
|
||||
var
|
||||
I: Integer;
|
||||
J,K: Integer;
|
||||
begin
|
||||
Result := Count;
|
||||
I := 0;
|
||||
if FPos > 0 then
|
||||
begin
|
||||
I := FChunkSize - FPos;
|
||||
if I > Count then
|
||||
begin
|
||||
Source.Write(Buffer, Count);
|
||||
FPos := FPos + Count;
|
||||
Exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
Source.Write(Buffer, I);
|
||||
Source.Write(FSeparator[1], Length(FSeparator));
|
||||
FPos := 0;
|
||||
end;
|
||||
end;
|
||||
if ((Count - I) > FChunkSize) then
|
||||
J := (Count - I) div FChunkSize
|
||||
else
|
||||
begin
|
||||
Source.Write(PChar(@Buffer)[I], Count - I);
|
||||
FPos := (Count - I);
|
||||
Exit;
|
||||
end;
|
||||
for K := 0 to J - 1 do
|
||||
begin
|
||||
Source.Write(PChar(@Buffer)[(K * FChunkSize)], FChunkSize);
|
||||
Source.WriteBuffer(FSeparator[1], Length(FSeparator));
|
||||
end;
|
||||
J := (Count - I) mod FChunkSize;
|
||||
if J > 0 then
|
||||
begin
|
||||
Source.Write(PChar(@Buffer)[((K + 1) * FChunkSize)], J);
|
||||
FPos := J;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TfrHtmlDivExportFilter }
|
||||
|
||||
function ColorToCSS(AColor: TColor): string;
|
||||
begin
|
||||
Result := Format('#%.2x%.2x%.2x', [Red(AColor), Green(AColor), Blue(AColor)]);
|
||||
end;
|
||||
|
||||
function SizeToCSS(X, Y, W, H: integer): string;
|
||||
begin
|
||||
Result := Format(
|
||||
'width:%dpx;min-width:%0:dpx;height:%dpx;min-height:%1:dpx;left:%dpx;top:%dpx;',
|
||||
[W, H, X, Y]);
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.WriteString(AValue: string);
|
||||
begin
|
||||
Stream.Write(AValue[1], Length(AValue));
|
||||
end;
|
||||
|
||||
constructor TfrHtmlDivExportFilter.Create(AStream: TStream);
|
||||
begin
|
||||
inherited Create(AStream);
|
||||
FCurPage := 0;
|
||||
FImgCnt := 0;
|
||||
FPageStyle := '';
|
||||
FExportImages := True;
|
||||
FEmbeddedImages := True;
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnBeginDoc;
|
||||
begin
|
||||
WriteString(Format(HTML_REPORT_HEADER, [CurReport.Title, FPageStyle]));
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnEndDoc;
|
||||
begin
|
||||
WriteString(HTML_REPORT_END);
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnBeginPage;
|
||||
begin
|
||||
Inc(FCurPage);
|
||||
WriteString(Format(HTML_PAGE_START, [CurReport.EMFPages[FCurPage - 1]^.PrnInfo.Pgw,
|
||||
CurReport.EMFPages[FCurPage - 1]^.PrnInfo.Pgh]));
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnEndPage;
|
||||
begin
|
||||
WriteString(HTML_PAGE_END);
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnData(x, y: integer; View: TfrView);
|
||||
|
||||
function BorderStyleToCSS: string;
|
||||
begin
|
||||
case View.FrameStyle of
|
||||
frsSolid, frsDouble: Result := 'solid';
|
||||
frsDash, frsDashDot, frsDashDotDot: Result := 'dashed';
|
||||
frsDot: Result := 'dotted';
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
W, H: integer;
|
||||
BrdW: integer;
|
||||
BLeft, BTop, BRight, BBottom: integer;
|
||||
St: string;
|
||||
B64: TBase64EncodingStream;
|
||||
Png: TPortableNetworkGraphic;
|
||||
BCBmp: TBitmap;
|
||||
CS: TChunkStream;
|
||||
begin
|
||||
W := View.dx;
|
||||
H := View.dy;
|
||||
|
||||
BrdW := Round(View.FrameWidth);
|
||||
|
||||
if frbLeft in View.Frames then
|
||||
BLeft := BrdW
|
||||
else
|
||||
BLeft := 0;
|
||||
if frbTop in View.Frames then
|
||||
BTop := BrdW
|
||||
else
|
||||
BTop := 0;
|
||||
if frbRight in View.Frames then
|
||||
BRight := BrdW
|
||||
else
|
||||
BRight := 0;
|
||||
if frbBottom in View.Frames then
|
||||
BBottom := BrdW
|
||||
else
|
||||
BBottom := 0;
|
||||
|
||||
if BLeft > 0 then
|
||||
Dec(W, BrdW);
|
||||
if BTop > 0 then
|
||||
Dec(H, BrdW);
|
||||
|
||||
St := SizeToCSS(X, Y, W, H);
|
||||
|
||||
St := St + Format('border-left:%0:dpx %4:s %5:s;border-top:%1:dpx %4:s %5:s;' +
|
||||
'border-right:%2:dpx %4:s %5:s;border-bottom:%3:dpx %4:s %5:s;',
|
||||
[BLeft, BTop, BRight, BBottom, BorderStyleToCSS, ColorToCSS(View.FrameColor)]);
|
||||
|
||||
if View.FillColor <> clNone then
|
||||
St := St + 'background-color:' + ColorToCSS(View.FillColor) + ';';
|
||||
|
||||
if ExportImages and ((View is TfrPictureView) or (View is TfrBarCodeView)) then
|
||||
begin
|
||||
WriteString(Format(HTML_IMG1, [St]));
|
||||
Inc(FImgCnt);
|
||||
if EmbeddedImages then
|
||||
WriteString('data:image/png;base64,')
|
||||
else
|
||||
WriteString(ExtractFileName(TFileStream(Stream).FileName) + '_image_' + IntToStr(FImgCnt) + '.png');
|
||||
Png := TPortableNetworkGraphic.Create;
|
||||
if EmbeddedImages then
|
||||
begin
|
||||
CS := TChunkStream.Create(Stream);
|
||||
B64 := TBase64EncodingStream.Create(CS);
|
||||
end;
|
||||
if View is TfrBarCodeView then
|
||||
begin
|
||||
BCBmp := TfrBarCodeView(View).GenerateBitmap;
|
||||
Png.Assign(BCBmp);
|
||||
BCBmp.Free;
|
||||
end
|
||||
else
|
||||
if View is TfrPictureView then
|
||||
begin
|
||||
Png.SetSize(View.dx, View.dy);
|
||||
if TfrPictureView(View).Stretched then
|
||||
Png.Canvas.StretchDraw(Rect(0, 0, View.dx, View.dy), TfrPictureView(View).Picture.Graphic)
|
||||
else
|
||||
Png.Canvas.Draw(0, 0, TfrPictureView(View).Picture.Graphic);
|
||||
end;
|
||||
if EmbeddedImages then
|
||||
begin
|
||||
Png.SaveToStream(B64);
|
||||
B64.Flush;
|
||||
B64.Free;
|
||||
CS.Free;
|
||||
end
|
||||
else
|
||||
Png.SaveToFile(TFileStream(Stream).FileName + '_image_' + IntToStr(FImgCnt) + '.png');
|
||||
Png.Free;
|
||||
WriteString(HTML_IMG2);
|
||||
end
|
||||
else
|
||||
WriteString(Format(HTML_BOX, [St]));
|
||||
end;
|
||||
|
||||
procedure TfrHtmlDivExportFilter.OnText(x, y: integer; const Text: string; View: TfrView);
|
||||
var
|
||||
St: string;
|
||||
begin
|
||||
if Trim(Text) = '' then
|
||||
Exit;
|
||||
St := SizeToCSS(X, Y, View.dx, View.dy);
|
||||
if View is TfrMemoView then
|
||||
begin
|
||||
St := St + 'font-family:''' + TfrMemoView(View).Font.Name +
|
||||
''';font-size:' + IntToStr(TfrMemoView(View).Font.Size) +
|
||||
'pt;color:' + ColorToCSS(TfrMemoView(View).Font.Color) + ';';
|
||||
if fsBold in TfrMemoView(View).Font.Style then
|
||||
St := St + 'font-weight:bold;';
|
||||
if fsItalic in TfrMemoView(View).Font.Style then
|
||||
St := St + 'font-style:italic;';
|
||||
if fsUnderline in TfrMemoView(View).Font.Style then
|
||||
St := St + 'text-decoration:underline;';
|
||||
end;
|
||||
WriteString(Format(HTML_TEXT, [St, Text]));
|
||||
end;
|
||||
|
||||
initialization
|
||||
frRegisterExportFilter(TfrHtmlDivExportFilter, 'HTML (div-based) (*.html)', '*.html');
|
||||
|
||||
end.
|
104
components/lazreport/source/addons/imgexport/lr_e_img.pas
Normal file
104
components/lazreport/source/addons/imgexport/lr_e_img.pas
Normal file
@ -0,0 +1,104 @@
|
||||
{*****
|
||||
|
||||
Copyright (c) 2012 Michał Gawrycki (michal.gawrycki(a.t.)gmsystems.pl
|
||||
License: modified LGPL (see 'COPYING.modifiedLGPL.txt' in Lazarus directory)
|
||||
|
||||
*****}
|
||||
|
||||
unit LR_e_img;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LR_Class, Graphics;
|
||||
|
||||
type
|
||||
TfrImageExport = class(TComponent)
|
||||
|
||||
end;
|
||||
|
||||
{ TfrImageExportFilter }
|
||||
|
||||
TfrImageExportFilter = class(TfrExportFilter)
|
||||
private
|
||||
FBmp: TFPImageBitmap;
|
||||
FCurPage: Integer;
|
||||
FFileName: String;
|
||||
FFileExt: String;
|
||||
FZoom: Extended;
|
||||
FJQuality: TJPEGQualityRange;
|
||||
FColor: TColor;
|
||||
public
|
||||
constructor Create(AStream: TStream); override;
|
||||
destructor Destroy; override;
|
||||
procedure OnBeginDoc; override;
|
||||
procedure OnEndPage; override;
|
||||
property Zoom: Extended read FZoom write FZoom;
|
||||
property JPEGQuality: TJPEGQualityRange read FJQuality write FJQuality;
|
||||
property BackgroundColor: TColor read FColor write FColor;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TfrImageExportFilter }
|
||||
|
||||
constructor TfrImageExportFilter.Create(AStream: TStream);
|
||||
begin
|
||||
inherited Create(AStream);
|
||||
FFileName := TFileStream(AStream).FileName;
|
||||
FFileExt := LowerCase(ExtractFileExt(FFileName));
|
||||
FFileName := ChangeFileExt(FFileName, '');
|
||||
FZoom := 1;
|
||||
FCurPage := 0;
|
||||
FJQuality := 75;
|
||||
FColor := clWhite;
|
||||
if FFileExt = '.jpg' then
|
||||
FBmp := TJPEGImage.Create
|
||||
else
|
||||
if FFileExt = '.png' then
|
||||
FBmp := TPortableNetworkGraphic.Create
|
||||
else
|
||||
FBmp := TBitmap.Create;
|
||||
end;
|
||||
|
||||
destructor TfrImageExportFilter.Destroy;
|
||||
begin
|
||||
FBmp.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TfrImageExportFilter.OnBeginDoc;
|
||||
begin
|
||||
if FBmp is TJPEGImage then
|
||||
TJPEGImage(FBmp).CompressionQuality := FJQuality;
|
||||
end;
|
||||
|
||||
procedure TfrImageExportFilter.OnEndPage;
|
||||
var
|
||||
TmpVisible: Boolean;
|
||||
begin
|
||||
Inc(FCurPage);
|
||||
FBmp.SetSize(Round(CurReport.EMFPages[FCurPage - 1]^.PrnInfo.Pgw * FZoom),
|
||||
Round(CurReport.EMFPages[FCurPage - 1]^.PrnInfo.Pgh * FZoom));
|
||||
FBmp.Canvas.Brush.Color := FColor;
|
||||
FBmp.Canvas.Brush.Style := bsSolid;
|
||||
FBmp.Canvas.FillRect(0, 0, FBmp.Width, FBmp.Height);
|
||||
TmpVisible := CurReport.EMFPages[FCurPage - 1]^.Visible;
|
||||
CurReport.EMFPages[FCurPage - 1]^.Visible := True;
|
||||
CurReport.EMFPages.Draw(FCurPage - 1, FBmp.Canvas, Rect(0, 0, FBmp.Width, FBmp.Height));
|
||||
CurReport.EMFPages[FCurPage - 1]^.Visible := TmpVisible;
|
||||
if FCurPage = 1 then
|
||||
FBmp.SaveToStream(Stream)
|
||||
else
|
||||
FBmp.SaveToFile(FFileName + '_' + IntToStr(FCurPage) + FFileExt);
|
||||
end;
|
||||
|
||||
initialization
|
||||
frRegisterExportFilter(TfrImageExportFilter, 'Bitmap file (*.bmp)', '*.bmp');
|
||||
frRegisterExportFilter(TfrImageExportFilter, 'JPEG file (*.jpg)', '*.jpg');
|
||||
frRegisterExportFilter(TfrImageExportFilter, 'PNG file (*.png)', '*.png');
|
||||
|
||||
end.
|
||||
|
53
components/lazreport/source/addons/imgexport/lr_extexp.lpk
Normal file
53
components/lazreport/source/addons/imgexport/lr_extexp.lpk
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<Package Version="4">
|
||||
<PathDelim Value="\"/>
|
||||
<Name Value="lr_extexp"/>
|
||||
<Author Value="Michal Gawrycki"/>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Description Value="TfrImageExport - export report to image file set (bmp, jpg, png)
|
||||
TfrHtmDivExport - export report to html file with images"/>
|
||||
<Files Count="3">
|
||||
<Item1>
|
||||
<Filename Value="lr_e_img.pas"/>
|
||||
<UnitName Value="LR_e_img"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Filename Value="lr_e_htmldiv.pas"/>
|
||||
<UnitName Value="LR_e_htmldiv"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Filename Value="lr_e_extreg.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="LR_e_extreg"/>
|
||||
</Item3>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="lazreport"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="FCL"/>
|
||||
</Item2>
|
||||
</RequiredPkgs>
|
||||
<UsageOptions>
|
||||
<UnitPath Value="$(PkgOutDir)"/>
|
||||
</UsageOptions>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
</Package>
|
||||
</CONFIG>
|
21
components/lazreport/source/addons/imgexport/lr_extexp.pas
Normal file
21
components/lazreport/source/addons/imgexport/lr_extexp.pas
Normal file
@ -0,0 +1,21 @@
|
||||
{ This file was automatically created by Lazarus. Do not edit!
|
||||
This source is only used to compile and install the package.
|
||||
}
|
||||
|
||||
unit lr_extexp;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
LR_e_img, LR_e_htmldiv, LR_e_extreg, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterUnit('LR_e_extreg', @LR_e_extreg.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterPackage('lr_extexp', @Register);
|
||||
end.
|
BIN
components/lazreport/source/addons/imgexport/test/test.ico
Normal file
BIN
components/lazreport/source/addons/imgexport/test/test.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
97
components/lazreport/source/addons/imgexport/test/test.lpi
Normal file
97
components/lazreport/source/addons/imgexport/test/test.lpi
Normal file
@ -0,0 +1,97 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="test"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="3">
|
||||
<Item1>
|
||||
<PackageName Value="lr_extexp"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="lazreport"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item3>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="test.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="test"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="testunit1.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="testunit1"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="test"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<MsgFileName Value=""/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
21
components/lazreport/source/addons/imgexport/test/test.lpr
Normal file
21
components/lazreport/source/addons/imgexport/test/test.lpr
Normal file
@ -0,0 +1,21 @@
|
||||
program test;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, testunit1
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
BIN
components/lazreport/source/addons/imgexport/test/test.res
Normal file
BIN
components/lazreport/source/addons/imgexport/test/test.res
Normal file
Binary file not shown.
1539
components/lazreport/source/addons/imgexport/test/testunit1.lfm
Normal file
1539
components/lazreport/source/addons/imgexport/test/testunit1.lfm
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,91 @@
|
||||
unit testunit1;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LR_Class, LR_BarC, LR_RRect, LR_Shape, LR_ChBox,
|
||||
LR_Desgn, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin, ComCtrls,
|
||||
LR_e_htmldiv, LR_e_img;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
Button2: TButton;
|
||||
CheckBox1: TCheckBox;
|
||||
CheckBox2: TCheckBox;
|
||||
ColorButton1: TColorButton;
|
||||
Edit1: TEdit;
|
||||
FloatSpinEdit1: TFloatSpinEdit;
|
||||
frBarCodeObject1: TfrBarCodeObject;
|
||||
frCheckBoxObject1: TfrCheckBoxObject;
|
||||
frDesigner1: TfrDesigner;
|
||||
frHtmlDivExport1: TfrHtmlDivExport;
|
||||
frImageExport1: TfrImageExport;
|
||||
frReport1: TfrReport;
|
||||
frRoundRectObject1: TfrRoundRectObject;
|
||||
frShapeObject1: TfrShapeObject;
|
||||
GroupBox1: TGroupBox;
|
||||
GroupBox2: TGroupBox;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Label3: TLabel;
|
||||
Label4: TLabel;
|
||||
SaveDialog1: TSaveDialog;
|
||||
SpinEdit1: TSpinEdit;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure Button2Click(Sender: TObject);
|
||||
procedure frReport1ExportFilterSetup(Sender: TfrExportFilter);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
LCLIntf;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
begin
|
||||
frReport1.ShowReport;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button2Click(Sender: TObject);
|
||||
begin
|
||||
frReport1.DesignReport;
|
||||
end;
|
||||
|
||||
procedure TForm1.frReport1ExportFilterSetup(Sender: TfrExportFilter);
|
||||
begin
|
||||
if Sender is TfrImageExportFilter then
|
||||
with TfrImageExportFilter(Sender) do
|
||||
begin
|
||||
Zoom := FloatSpinEdit1.Value;
|
||||
JPEGQuality := SpinEdit1.Value;
|
||||
BackgroundColor := ColorButton1.ButtonColor;
|
||||
end
|
||||
else
|
||||
if Sender is TfrHtmlDivExportFilter then
|
||||
with TfrHtmlDivExportFilter(Sender) do
|
||||
begin
|
||||
PageStyle := Edit1.Text;
|
||||
ExportImages := CheckBox1.Checked;
|
||||
EmbeddedImages := CheckBox2.Checked;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 645 B |
BIN
components/lazreport/source/addons/imgexport/tfrimageexport.png
Normal file
BIN
components/lazreport/source/addons/imgexport/tfrimageexport.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 541 B |
Loading…
Reference in New Issue
Block a user