From: <ah...@us...> - 2009-08-23 11:55:58
|
Revision: 12465 http://jvcl.svn.sourceforge.net/jvcl/?rev=12465&view=rev Author: ahuser Date: 2009-08-23 11:55:49 +0000 (Sun, 23 Aug 2009) Log Message: ----------- Mantis #4877: TJvRichEditToHtml under Delphi 2009 Modified Paths: -------------- trunk/jvcl/run/JvRichEditToHtml.pas Modified: trunk/jvcl/run/JvRichEditToHtml.pas =================================================================== --- trunk/jvcl/run/JvRichEditToHtml.pas 2009-08-23 10:43:09 UTC (rev 12464) +++ trunk/jvcl/run/JvRichEditToHtml.pas 2009-08-23 11:55:49 UTC (rev 12465) @@ -36,7 +36,7 @@ {$IFDEF UNITVERSIONING} JclUnitVersioning, {$ENDIF UNITVERSIONING} - SysUtils, Classes, Graphics, Forms, ComCtrls, + SysUtils, Classes, Graphics, Forms, ComCtrls, TypInfo, JvRgbToHtml, JvStrToHtml, JvRichEdit, JvComponentBase, JclStrings; type @@ -79,26 +79,29 @@ FEndSection: string; FEndPara: string; FTitle: string; - FFooter: TStringList; - FHeader: TStringList; + FFooter: TStrings; + FHeader: TStrings; function AttToHtml(Value: TFontInfo): string; - function ParaToHtml(Value: TJvParaAttributesRec): string;overload; - function ParaToHtml(Value: TJvRichEditParaAttributesRec): string;overload; - function GetFooter: TStrings; - function GetHeader: TStrings; + function ParaToHtml(Value: TJvParaAttributesRec): string; overload; + function ParaToHtml(Value: TJvRichEditParaAttributesRec): string; overload; procedure SetFooter(const Value: TStrings); procedure SetHeader(const Value: TStrings); + function IsFooterStored: Boolean; + function IsHeaderStored: Boolean; + procedure WriteEmptyStrings(Writer: TWriter); + protected + procedure DefineProperties(Filer: TFiler); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure ConvertToHtml(Value: TRichEdit; const FileName: string);overload; - procedure ConvertToHtml(Value: TJvRichEdit; const FileName: string);overload; - procedure ConvertToHtmlStrings(Value: TRichEdit; Strings: TStrings);overload; - procedure ConvertToHtmlStrings(Value: TJvRichEdit; Strings: TStrings);overload; + procedure ConvertToHtml(Value: TRichEdit; const FileName: string); overload; + procedure ConvertToHtml(Value: TJvRichEdit; const FileName: string); overload; + procedure ConvertToHtmlStrings(Value: TRichEdit; Strings: TStrings); overload; + procedure ConvertToHtmlStrings(Value: TJvRichEdit; Strings: TStrings); overload; published property Title: string read FTitle write FTitle; - property Header: TStrings read GetHeader write SetHeader; - property Footer: TStrings read GetFooter write SetFooter; + property Header: TStrings read FHeader write SetHeader stored IsHeaderStored; + property Footer: TStrings read FFooter write SetFooter stored IsFooterStored; end; {$IFDEF UNITVERSIONING} @@ -152,6 +155,18 @@ cHTMLListBegin = '<LI>'; cHTMLListEnd = '</LI>'; + cDefaultHeader: array[0..4] of string = ( + '<HTML>', + ' <HEAD>', + ' <TITLE><#TITLE></TITLE>', + ' </HEAD>', + ' <BODY>' + ); + cDefaultFooter: array[0..1] of string = ( + ' </BODY>', + '</HTML>' + ); + //=== { TFontInfo } ========================================================== constructor TFontInfo.Create(APixelsPerInch: Integer); @@ -204,23 +219,24 @@ FFontData.Height := -MulDiv(Value, FPixelsPerInch, 72); end; +type + TWriterAccess = class(TWriter); + //=== { TJvRichEditToHtml } ================================================== constructor TJvRichEditToHtml.Create(AOwner: TComponent); +var + I: Integer; begin inherited Create(AOwner); FCToH := TJvRgbToHtml.Create(Self); FCharToH := TJvStrToHtml.Create(Self); FHeader := TStringList.Create; - FHeader.Add('<HTML>'); - FHeader.Add(' <HEAD>'); - FHeader.Add(' <TITLE><#TITLE></TITLE>'); - FHeader.Add(' </HEAD>'); - FHeader.Add(' <BODY>'); - + for I := 0 to High(cDefaultHeader) do + FHeader.Add(cDefaultHeader[I]); FFooter := TStringList.Create; - FFooter.Add(' </BODY>'); - FFooter.Add('</HTML>'); + for I := 0 to High(cDefaultFooter) do + FFooter.Add(cDefaultFooter[I]); end; destructor TJvRichEditToHtml.Destroy; @@ -391,7 +407,7 @@ end else begin - if CharInSet(Text[J], ['A'..'Z', 'a'..'z', '0'..'9']) then + if CharIsAlphaNum(Text[J]) then St.Append(Text[J]) else St.Append(CharToHtml(Text[J])); @@ -501,7 +517,7 @@ end else begin - if CharInSet(Text[J], ['A'..'Z', 'a'..'z', '0'..'9']) then + if CharIsAlphaNum(Text[J]) then St.Append(Text[J]) else St.Append(CharToHtml(Text[J])); @@ -561,11 +577,11 @@ begin case Value.Alignment of Classes.taLeftJustify: - Result := 'ALIGN="LEFT"'; + Result := 'STYLE="text-align: left;"'; Classes.taRightJustify: - Result := 'ALIGN="RIGHT"'; + Result := 'STYLE="text-align: right;"'; Classes.taCenter: - Result := 'ALIGN="CENTER"'; + Result := 'STYLE="text-align: center;"'; end; if Value.Numbering = ComCtrls.nsBullet then begin @@ -579,26 +595,88 @@ end end; -function TJvRichEditToHtml.GetFooter: TStrings; +procedure TJvRichEditToHtml.SetFooter(const Value: TStrings); begin - Result := FFooter; + if Value <> FFooter then + FFooter.Assign(Value); end; -function TJvRichEditToHtml.GetHeader: TStrings; +procedure TJvRichEditToHtml.SetHeader(const Value: TStrings); begin - Result := FHeader; + if Value <> FHeader then + FHeader.Assign(Value); end; -procedure TJvRichEditToHtml.SetFooter(const Value: TStrings); +function TJvRichEditToHtml.IsFooterStored: Boolean; +var + I: Integer; begin - FFooter.Assign(Value); + Result := Footer.Count <> Length(cDefaultFooter); + if not Result then + begin + Result := True; + for I := 0 to High(cDefaultFooter) do + if Footer[I] <> cDefaultFooter[I] then + Exit; + Result := False; + end; end; -procedure TJvRichEditToHtml.SetHeader(const Value: TStrings); +function TJvRichEditToHtml.IsHeaderStored: Boolean; +var + I: Integer; begin - FHeader.Assign(Value); + Result := Header.Count <> Length(cDefaultHeader); + if not Result then + begin + Result := True; + for I := 0 to High(cDefaultHeader) do + if Header[I] <> cDefaultHeader[I] then + Exit; + Result := False; + end; end; +procedure TJvRichEditToHtml.WriteEmptyStrings(Writer: TWriter); +begin + Writer.WriteListBegin; + Writer.WriteListEnd; +end; + +procedure TJvRichEditToHtml.DefineProperties(Filer: TFiler); + + function DoWriteHeader: Boolean; + begin + Result := Header.Count = 0; + if Result and (Filer.Ancestor <> nil) then + begin + Result := True; + if Filer.Ancestor is TJvRichEditToHtml then + Result := not Header.Equals(TJvRichEditToHtml(Filer.Ancestor).Header) + end; + end; + + function DoWriteFooter: Boolean; + begin + Result := Footer.Count = 0; + if Result and (Filer.Ancestor <> nil) then + begin + Result := True; + if Filer.Ancestor is TJvRichEditToHtml then + Result := not Footer.Equals(TJvRichEditToHtml(Filer.Ancestor).Footer) + end; + end; + +begin + inherited DefineProperties(Filer); + { Write empty Header/Footer to DFM because the default value differs from '' } + if Filer is TWriter then + begin + Filer.DefineProperty('Header.Strings', nil, WriteEmptyStrings, DoWriteHeader); + Filer.DefineProperty('Footer.Strings', nil, WriteEmptyStrings, DoWriteFooter); + end; +end; + {$IFDEF UNITVERSIONING} initialization RegisterUnitVersion(HInstance, UnitVersioning); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |