fpspreadsheet: Fix pagelayout unit test. Passed now.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4124 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-05-11 14:29:55 +00:00
parent c42a8fdedb
commit 6a84c55899
3 changed files with 95 additions and 21 deletions

View File

@ -70,6 +70,7 @@ type
procedure AddCurrTextElement;
procedure AddElement(AToken: TsHeaderFooterToken);
procedure AddFontStyle(AStyle: TsHeaderFooterFontStyle);
procedure AddNewLine;
function FindCurrFont: Integer;
function GetCurrFontIndex: Integer; virtual;
procedure Parse; virtual;
@ -80,6 +81,7 @@ type
ADefaultFont: TsHeaderFooterFont); overload;
destructor Destroy; override;
function BuildHeaderFooter: String;
property Sections:TsHeaderFooterSections read FSections;
end;
const
@ -91,10 +93,6 @@ uses
Math,
fpsUtils;
const
FONTSTYLE_SYMBOLS: array[TsHeaderFooterFontStyle] of char =
('B', 'I', 'U', 'E', 'S', 'H', 'O', 'X', 'Y');
constructor TsHeaderFooterFont.Create;
begin
inherited;
@ -212,13 +210,24 @@ begin
Include(FCurrFont.Style, AStyle);
end;
procedure TsHeaderFooterParser.AddNewLine;
begin
if FCurrText <> '' then
AddCurrTextElement;
ScanNewLine;
end;
function TsHeaderFooterParser.BuildHeaderFooter: String;
const
FONTSTYLE_SYMBOLS: array[TsHeaderFooterFontStyle] of char =
('B', 'I', 'U', 'E', 'S', 'H', 'O', 'Y', 'X');
var
sec: TsHeaderFooterSectionIndex;
element: TsHeaderFooterElement;
fnt, prevfnt: TsHeaderFooterFont;
fs: TsHeaderFooterFontStyle;
i: Integer;
s: String;
begin
Result := '';
for sec := hfsLeft to hfsRight do
@ -246,7 +255,11 @@ begin
then
Result := Result + '&' + FONTSTYLE_SYMBOLS[fs];
if fnt.Color <> prevfnt.Color then
Result := Result + '&K' + ColorToHTMLColorStr(fnt.Color, true);
begin
s := ColorToHTMLColorStr(fnt.Color, true); // --> 00RRGGBB
Delete(s, 1, 2); // Excel wants only the RRGGBB
Result := Result + '&K' + s;
end;
prevfnt := fnt;
end;
case element.Token of
@ -329,7 +342,7 @@ begin
while (FCurrent < FEnd) and (FStatus = hfpsOK) do begin
case FToken of
'&': ScanSymbol;
#13, #10: ScanNewLine;
#13, #10: AddNewLine;
else FCurrText := FCurrText + FToken;
end;
FToken := NextToken;
@ -394,9 +407,6 @@ end;
procedure TsHeaderFooterParser.ScanNewLine;
begin
if FCurrText <> '' then
AddCurrTextElement;
case FToken of
#13: begin
AddElement(hftNewLine);

View File

@ -508,7 +508,7 @@ begin
nodeName := pnode.NodeName;
if nodeName = 'text:p' then
begin
// if not firstP then AddElement(hftNewLine);
if not firstP then AddElement(hftNewLine);
childpnode := pnode.FirstChild;
while Assigned(childpnode) do
begin
@ -1668,7 +1668,7 @@ begin
s := GetAttrValue(ANode, 'style:text-underline-style');
if not ((s = '') or (s = 'none')) then
Include(fntStyles, fssUnderline);
s := GetAttrValue(ANode, 'style:text-strike-through-style');
s := GetAttrValue(ANode, 'style:text-line-through-style');
if not ((s = '') or (s = 'none')) then
Include(fntStyles, fssStrikeout);
@ -1959,7 +1959,7 @@ begin
Include(AFontStyle, hfsUnderline);
end;
s := GetAttrValue(ANode, 'style:text-strike-through-style');
s := GetAttrValue(ANode, 'style:text-line-through-style');
if not ((s = '') or (s = 'none')) then
Include(AFontStyle, hfsStrikeout);

View File

@ -277,7 +277,8 @@ type
implementation
uses
typinfo, fpsutils;
typinfo, contnrs,
fpsutils, fpsHeaderFooterParser;
// uriparser, lazfileutils, fpsutils;
const
@ -402,6 +403,50 @@ var
sollPageLayout: Array of TsPageLayout;
actualPageLayout: TsPageLayout;
TempFile: string; //write xls/xml to this file and read back from it
function SameParsedHeaderFooter(AText1, AText2: String;
AWorkbook: TsWorkbook): Boolean;
var
parser1, parser2: TsHeaderFooterParser;
list1, list2: TObjectList;
s: TsHeaderFooterSectionIndex;
el: Integer;
defFnt: TsHeaderFooterFont;
begin
Result := false;
list1 := TObjectList.Create;
list2 := TObjectList.Create;
defFnt := TsHeaderFooterFont.Create(AWorkbook.GetDefaultFont);
try
parser1 := TsHeaderFooterParser.Create(AText1, list1, defFnt);
parser2 := TsHeaderFooterParser.Create(AText2, list2, defFnt);
try
for s := Low(TsHeaderFooterSectionIndex) to High(TsHeaderFooterSectionIndex) do
begin
if Length(parser1.Sections[s]) <> Length(parser2.Sections[s]) then
exit;
for el := 0 to Length(parser1.Sections[s])-1 do
begin
if parser1.Sections[s][el].Token <> parser2.Sections[s][el].Token then
exit;
if parser1.Sections[s][el].TextValue <> parser2.Sections[s][el].TextValue then
exit;
if parser1.Sections[s][el].FontIndex <> parser2.Sections[s][el].FontIndex then
exit;
end;
end;
Result := true;
finally
parser1.Free;
parser2.Free;
end;
finally;
defFnt.Free;
list1.Free;
list2.Free;
end;
end;
begin
TempFile := GetTempFileName;
@ -477,12 +522,15 @@ begin
8: // Header/footer font symbol test
begin
Headers[HEADER_FOOTER_INDEX_ALL] :=
'&LH&Y2&YO cm&X2&X'+
'&C&"Times New Roman"&18This is big'+
'&RThis is &Bbold&B,'+ LineEnding+'&Iitalic&I,'+LineEnding+
'&LH'+
'&Y2&YO cm&X2'+
'&C'+
'&"Times New Roman"&18This is big'+
'&R'+
'This is &Bbold&B,'+ LineEnding+'&Iitalic&I,'+LineEnding+
'&Uunderlined&U,'+LineEnding+'&Edouble underlined&E,'+
'&Sstriked-out&S,'+LineEnding+'&Ooutlined&O,'+LineEnding+
'&Hshadow&S';
'&Hshadow';
Footers[HEADER_FOOTER_INDEX_ALL] :=
'&L&"Arial"&8Arial small'+
'&C&"Courier new"&32Courier big'+
@ -579,10 +627,16 @@ begin
end;
6, 7, 8, 9: // Header/footer tests
begin
CheckEquals(sollPageLayout[p].Headers[1], actualPageLayout.Headers[1],
'Header value mismatch, sheet "' + MyWorksheet.Name + '"');
CheckEquals(sollPageLayout[p].Footers[1], actualPageLayout.Footers[1],
'Footer value mismatch, sheet "' + MyWorksheet.Name + '"');
if (sollPageLayout[p].Headers[1] <> actualPageLayout.Headers[1]) and
not SameParsedHeaderFooter(sollPagelayout[p].Headers[1], actualPageLayout.Headers[1], MyWorkbook)
then
CheckEquals(sollPageLayout[p].Headers[1], actualPageLayout.Headers[1],
'Header value mismatch, sheet "' + MyWorksheet.Name + '"');
if (sollPageLayout[p].Footers[1] <> actualPageLayout.Footers[1]) and
not SameParsedHeaderFooter(sollPagelayout[p].Footers[1], actualPageLayout.Footers[1], MyWorkbook)
then
CheckEquals(sollPageLayout[p].Footers[1], actualPageLayout.Footers[1],
'Footer value mismatch, sheet "' + MyWorksheet.Name + '"');
end;
end;
end;
@ -593,6 +647,16 @@ begin
end;
end;
{
soll:
'&LH&Y2&YO cm&X2&X&C&"Times New Roman"&18This is big&RThis is &Bbold&B,'#13#10'&Iitalic&I,'#13#10'&Uunderlined&U,'#13#10'&Edouble underlined&E,&Sstriked-out&S,'#13#10'&Ooutlined&O,'#13#10'&Hshadow&H'
actual:
'&LH&Y2&YO cm&X2 &C&"Times New Roman"&18This is big&RThis is &Bbold&B,'#13#10'&Iitalic&I,'#13#10'&Uunderlined&U,'#13#10'&Edouble underlined&E,&Sstriked-out&S,'#13#10'&Ooutlined&O,'#13#10'&Hshadow'
'&LH&Y2&YO cm&X2&C&"Times New Roman"&18This is big&RThis is &Bbold&B,'#13#10'&Iitalic&I,'#13#10'&Uunderlined&U,'#13#10'&Edouble underlined&E,&Sstriked-out&S,'#13#10'&Ooutlined&O,'#13#10'&Hshadow'
'&LH&Y2&YO cm&X2 &C&"Times New Roman"&18This is big&RThis is &Bbold&B,'#13#10'&Iitalic&I,'#13#10'&Uunderlined&U,'#13#10'&Edouble underlined&E,striked-out,'#13#10'&Ooutlined&O,'#13#10'&Hshadow'
}
{ Tests for BIFF2 file format }