fpspreadsheet: Fix Excel readers updating the workbook's default font.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5838 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-04-21 10:38:54 +00:00
parent de744bedf1
commit 59f0da6d91
4 changed files with 24 additions and 0 deletions

View File

@ -513,6 +513,7 @@ var
lOptions: Word; lOptions: Word;
Len: Byte; Len: Byte;
lFontName: UTF8String; lFontName: UTF8String;
isDefaultFont: Boolean;
begin begin
FFont := TsFont.Create; FFont := TsFont.Create;
@ -534,8 +535,13 @@ begin
AStream.ReadBuffer(lFontName[1], Len); AStream.ReadBuffer(lFontName[1], Len);
FFont.FontName := lFontName; FFont.FontName := lFontName;
isDefaultFont := FFontList.Count = 0;
{ Add font to internal font list } { Add font to internal font list }
FFontList.Add(FFont); FFontList.Add(FFont);
if isDefaultFont then
Workbook.SetDefaultFont(FFont.FontName, FFont.Size);
end; end;
procedure TsSpreadBIFF2Reader.ReadFONTCOLOR(AStream: TStream); procedure TsSpreadBIFF2Reader.ReadFONTCOLOR(AStream: TStream);

View File

@ -961,6 +961,7 @@ var
Len: Byte; Len: Byte;
fontname: ansistring; fontname: ansistring;
font: TsFont; font: TsFont;
isDefaultFont: Boolean;
begin begin
font := TsFont.Create; font := TsFont.Create;
@ -1025,6 +1026,8 @@ begin
AStream.ReadBuffer(fontname[1], Len); AStream.ReadBuffer(fontname[1], Len);
font.FontName := ConvertEncoding(fontname, FCodePage, encodingUTF8); font.FontName := ConvertEncoding(fontname, FCodePage, encodingUTF8);
isDefaultFont := FFontList.Count = 0;
{ Add font to internal font list. Will be copied to workbook's font list later { Add font to internal font list. Will be copied to workbook's font list later
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. }
@ -1032,6 +1035,9 @@ begin
{ Excel does not have zero-based font #4! } { Excel does not have zero-based font #4! }
if FFontList.Count = 4 then FFontList.Add(nil); if FFontList.Count = 4 then FFontList.Add(nil);
if isDefaultFont then
FWorkbook.SetDefaultFont(font.FontName, font.Size);
end; end;
// Read the FORMAT record for formatting numerical data // Read the FORMAT record for formatting numerical data

View File

@ -1792,6 +1792,7 @@ var
Len: Byte; Len: Byte;
font: TsFont; font: TsFont;
rtParams: TsRichTextParams; rtParams: TsRichTextParams;
isDefaultFont: Boolean;
begin begin
font := TsFont.Create; font := TsFont.Create;
@ -1849,6 +1850,8 @@ begin
Len := AStream.ReadByte(); Len := AStream.ReadByte();
font.FontName := ReadString(AStream, Len, rtParams); // rtParams is not used here. font.FontName := ReadString(AStream, Len, rtParams); // rtParams is not used here.
isDefaultFont := FFontList.Count = 0;
{ Add font to internal font list; will be transferred to workbook later because { Add font to internal font list; will be transferred to workbook later because
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! }
@ -1856,6 +1859,9 @@ begin
{ Excel does not have zero-based font #4! } { Excel does not have zero-based font #4! }
if FFontList.Count = 4 then FFontList.Add(nil); if FFontList.Count = 4 then FFontList.Add(nil);
if isDefaultFont then
Workbook.SetDefaultFont(font.FontName, font.Size);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------

View File

@ -1392,7 +1392,10 @@ var
nodename: String; nodename: String;
s: String; s: String;
acceptDuplicates: Boolean; acceptDuplicates: Boolean;
isDefaultFont: Boolean;
begin begin
isDefaultFont := FFontList.Count = 0;
fnt := Workbook.GetDefaultFont; fnt := Workbook.GetDefaultFont;
if fnt <> nil then if fnt <> nil then
begin begin
@ -1497,6 +1500,9 @@ begin
fnt.Position := fntPos; fnt.Position := fntPos;
Result := FFontList.Add(fnt); Result := FFontList.Add(fnt);
if isDefaultFont then
Workbook.SetDefaultFont(fnt.FontName, fnt.Size);
end; end;
procedure TsSpreadOOXMLReader.ReadFonts(ANode: TDOMNode); procedure TsSpreadOOXMLReader.ReadFonts(ANode: TDOMNode);