fpspreadsheet: Fix WorksheetGrid hanging if cell text contains a manual line break. Fix reading of new subscript and superscript font properties for biff5 and biff8 (Rich-text support not yet fully working here).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4208 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-07-10 09:13:19 +00:00
parent a5e3c273a6
commit e0b25c8f51
4 changed files with 43 additions and 15 deletions

View File

@@ -328,10 +328,10 @@ var
end; end;
#13, #13,
#10: begin #10: begin
dec(p); // dec(p);
width := savedWidth; //width := savedWidth;
numSpaces := savedspaces; //numSpaces := savedspaces;
PendingRtpIndex := savedRtpIndex; //PendingRtpIndex := savedRtpIndex;
exit; exit;
end; end;
else begin else begin

View File

@@ -643,7 +643,7 @@ begin
// Font index // Font index
i := WordLEToN(rec.FontIndex); i := WordLEToN(rec.FontIndex);
if i > 4 then dec(i); // Watch out for the nasty missing font #4... // if i > 4 then dec(i); // Watch out for the nasty missing font #4...
fmt.FontIndex := FixFontIndex(i); fmt.FontIndex := FixFontIndex(i);
{ {
fnt := TsFont(FFontList[i]); fnt := TsFont(FFontList[i]);
@@ -823,6 +823,7 @@ var
lOptions: Word; lOptions: Word;
lColor: Word; lColor: Word;
lWeight: Word; lWeight: Word;
lEsc: Word;
Len: Byte; Len: Byte;
fontname: ansistring; fontname: ansistring;
font: TsFont; font: TsFont;
@@ -859,10 +860,15 @@ begin
{ Font weight } { Font weight }
lWeight := WordLEToN(AStream.ReadWord); lWeight := WordLEToN(AStream.ReadWord);
if lWeight = 700 then Include(font.Style, fssBold); if lWeight >= 700 then Include(font.Style, fssBold);
{ Escapement type } { Escapement type }
AStream.ReadWord(); lEsc := WordLEToN(AStream.ReadWord);
case lEsc of
0: ;
1: font.Position := fpSuperscript;
2: font.Position := fpSubscript;
end;
{ Underline type } { Underline type }
if AStream.ReadByte > 0 then Include(font.Style, fssUnderline); if AStream.ReadByte > 0 then Include(font.Style, fssUnderline);
@@ -889,6 +895,9 @@ begin
as the font index in the internal list may be different from the index in as the font index in the internal list may be different from the index in
the workbook's list. } the workbook's list. }
FFontList.Add(font); FFontList.Add(font);
{ Excel does not have zero-based font #4! }
if FFontList.Count = 4 then FFontList.Add(nil);
end; end;
// Read the FORMAT record for formatting numerical data // Read the FORMAT record for formatting numerical data

View File

@@ -924,6 +924,7 @@ var
XF: Word; XF: Word;
AStrValue: ansistring; AStrValue: ansistring;
cell: PCell; cell: PCell;
rtfRuns: TsRichTextFormattingRuns;
begin begin
ReadRowColXF(AStream, ARow, ACol, XF); ReadRowColXF(AStream, ARow, ACol, XF);
@@ -940,15 +941,18 @@ begin
{ Save the data } { Save the data }
FWorksheet.WriteUTF8Text(cell, AStrValue); FWorksheet.WriteUTF8Text(cell, AStrValue);
//Read formatting runs (not supported)
// Read rich-text formatting runs
B := WordLEtoN(AStream.ReadWord); B := WordLEtoN(AStream.ReadWord);
SetLength(rtfRuns, B);
for L := 0 to B-1 do begin for L := 0 to B-1 do begin
AStream.ReadWord; // First formatted character rtfRuns[L].FirstIndex := WordLEToN(AStream.ReadWord); // Index of first formatted character
AStream.ReadWord; // Index to FONT record rtfRuns[L].FontIndex := WordLEToN(AStream.ReadByte); // Index of font used
end; end;
{Add attributes} {Add attributes}
ApplyCellFormatting(cell, XF); ApplyCellFormatting(cell, XF);
ApplyRichTextFormattingRuns(cell, rtfRuns);
if FIsVirtualMode then if FIsVirtualMode then
Workbook.OnReadCellData(Workbook, ARow, ACol, cell); Workbook.OnReadCellData(Workbook, ARow, ACol, cell);
@@ -1235,7 +1239,7 @@ begin
// Font index // Font index
i := WordLEToN(rec.FontIndex); i := WordLEToN(rec.FontIndex);
if i > 4 then dec(i); // Watch out for the nasty missing font #4... // if i > 4 then dec(i); // Watch out for the nasty missing font #4...
fnt := TsFont(FFontList[i]); fnt := TsFont(FFontList[i]);
fmt.FontIndex := Workbook.FindFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color); fmt.FontIndex := Workbook.FindFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color);
if fmt.FontIndex = -1 then if fmt.FontIndex = -1 then
@@ -1396,6 +1400,7 @@ var
lOptions: Word; lOptions: Word;
lColor: Word; lColor: Word;
lWeight: Word; lWeight: Word;
lEsc: Word;
Len: Byte; Len: Byte;
font: TsFont; font: TsFont;
begin begin
@@ -1434,7 +1439,13 @@ begin
if lWeight = 700 then Include(font.Style, fssBold); if lWeight = 700 then Include(font.Style, fssBold);
{ Escape type } { Escape type }
AStream.ReadWord(); { Escapement type }
lEsc := WordLEToN(AStream.ReadWord);
case lEsc of
0: ;
1: font.Position := fpSuperscript;
2: font.Position := fpSubscript;
end;
{ Underline type } { Underline type }
if AStream.ReadByte > 0 then Include(font.Style, fssUnderline); if AStream.ReadByte > 0 then Include(font.Style, fssUnderline);
@@ -1459,6 +1470,9 @@ begin
the font index in the internal list (= index in file) is not the same as the the font index in the internal list (= index in file) is not the same as the
index the font will have in the workbook's fontlist! } index the font will have in the workbook's fontlist! }
FFontList.Add(font); FFontList.Add(font);
{ Excel does not have zero-based font #4! }
if FFontList.Count = 4 then FFontList.Add(nil);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@@ -988,9 +988,14 @@ var
fnt: TsFont; fnt: TsFont;
begin begin
fnt := TsFont(FFontList[AFontIndex]); fnt := TsFont(FFontList[AFontIndex]);
if fnt = nil then // damned font 4!
Result := -1
else
begin
Result := FWorkbook.FindFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color, fnt.Position); Result := FWorkbook.FindFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color, fnt.Position);
if Result = -1 then if Result = -1 then
Result := FWorkbook.AddFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color, fnt.Position); Result := FWorkbook.AddFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color, fnt.Position);
end;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------