You've already forked lazarus-ccr
fpspreadsheet: Fix writing of header/footer fonts to ods files. Some cleanup.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4127 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -141,7 +141,6 @@ function ParamsOfNumFormatStr(AWorkbook: TsWorkbook;
|
|||||||
ANumFormatStr: String; var AResult: TsNumFormatParams): Integer;
|
ANumFormatStr: String; var AResult: TsNumFormatParams): Integer;
|
||||||
var
|
var
|
||||||
parser: TsNumFormatParser;
|
parser: TsNumFormatParser;
|
||||||
i: Integer;
|
|
||||||
begin
|
begin
|
||||||
Assert(AResult <> nil);
|
Assert(AResult <> nil);
|
||||||
if ANumFormatstr = 'General' then ANumFormatStr := '';
|
if ANumFormatstr = 'General' then ANumFormatStr := '';
|
||||||
|
@ -185,6 +185,7 @@ type
|
|||||||
procedure CreateStreams;
|
procedure CreateStreams;
|
||||||
procedure DestroyStreams;
|
procedure DestroyStreams;
|
||||||
procedure ListAllColumnStyles;
|
procedure ListAllColumnStyles;
|
||||||
|
procedure ListAllHeaderFooterFonts;
|
||||||
procedure ListAllNumFormats; override;
|
procedure ListAllNumFormats; override;
|
||||||
procedure ListAllRowStyles;
|
procedure ListAllRowStyles;
|
||||||
procedure ResetStreams;
|
procedure ResetStreams;
|
||||||
@ -398,7 +399,6 @@ end;
|
|||||||
|
|
||||||
function TsSpreadOpenDocHeaderFooterParser.BuildHeaderFooterAsXMLString: String;
|
function TsSpreadOpenDocHeaderFooterParser.BuildHeaderFooterAsXMLString: String;
|
||||||
var
|
var
|
||||||
list: TStringList;
|
|
||||||
regionStr: array[TsHeaderFooterSectionIndex] of String;
|
regionStr: array[TsHeaderFooterSectionIndex] of String;
|
||||||
sec: TsHeaderFooterSectionIndex;
|
sec: TsHeaderFooterSectionIndex;
|
||||||
element: TsHeaderFooterElement;
|
element: TsHeaderFooterElement;
|
||||||
@ -479,7 +479,7 @@ end;
|
|||||||
|
|
||||||
procedure TsSpreadOpenDocHeaderFooterParser.Parse;
|
procedure TsSpreadOpenDocHeaderFooterParser.Parse;
|
||||||
var
|
var
|
||||||
node, pnode, childpnode, childspannode, textnode: TDOMNode;
|
node, pnode, childpnode, childspannode: TDOMNode;
|
||||||
nodeName: String;
|
nodeName: String;
|
||||||
s: String;
|
s: String;
|
||||||
firstP: Boolean;
|
firstP: Boolean;
|
||||||
@ -1115,7 +1115,6 @@ var
|
|||||||
data: TPageLayoutData;
|
data: TPageLayoutData;
|
||||||
isHeader: Boolean;
|
isHeader: Boolean;
|
||||||
h: Double;
|
h: Double;
|
||||||
idx: Integer;
|
|
||||||
fnt: TXMLHeaderFooterFont;
|
fnt: TXMLHeaderFooterFont;
|
||||||
defFnt: TsFont;
|
defFnt: TsFont;
|
||||||
fntName: String;
|
fntName: String;
|
||||||
@ -1136,6 +1135,7 @@ begin
|
|||||||
fntName := defFnt.FontName;
|
fntName := defFnt.FontName;
|
||||||
fntSize := defFnt.Size;
|
fntSize := defFnt.Size;
|
||||||
fntColor := defFnt.Color;
|
fntColor := defFnt.Color;
|
||||||
|
fntStyle := [];
|
||||||
s := GetAttrValue(layoutNode, 'style:family');
|
s := GetAttrValue(layoutNode, 'style:family');
|
||||||
if s = 'text' then
|
if s = 'text' then
|
||||||
begin
|
begin
|
||||||
@ -1298,7 +1298,7 @@ end;
|
|||||||
{ Reads the master styles nodes which contain the header/footer texts }
|
{ Reads the master styles nodes which contain the header/footer texts }
|
||||||
procedure TsSpreadOpenDocReader.ReadMasterStyles(AStylesNode: TDOMNode);
|
procedure TsSpreadOpenDocReader.ReadMasterStyles(AStylesNode: TDOMNode);
|
||||||
var
|
var
|
||||||
masternode, stylenode, regionnode: TDOMNode;
|
masternode, stylenode: TDOMNode;
|
||||||
nodeName: String;
|
nodeName: String;
|
||||||
s: String;
|
s: String;
|
||||||
data: TMasterPageData;
|
data: TMasterPageData;
|
||||||
@ -3267,6 +3267,36 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ Collects the fonts used by headers and footers in the FHeaderFooterFontList }
|
||||||
|
procedure TsSpreadOpenDocWriter.ListAllHeaderFooterFonts;
|
||||||
|
|
||||||
|
{ Add the fonts used in the specified header/footer line to the
|
||||||
|
HeaderFooterFontList. This is done while the HeaderFooterParser is created. }
|
||||||
|
procedure AddFontsOfHeaderFooter(AText: String; ADefaultFont: TsHeaderFooterFont);
|
||||||
|
begin
|
||||||
|
TsSpreadOpenDocHeaderFooterParser.Create(AText, FHeaderFooterFontList, ADefaultFont).Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
defFnt: TsHeaderFooterFont;
|
||||||
|
i: Integer;
|
||||||
|
sheet: TsWorksheet;
|
||||||
|
begin
|
||||||
|
defFnt := TsHeaderFooterFont.Create(Workbook.GetDefaultFont);
|
||||||
|
try
|
||||||
|
for i:=0 to Workbook.GetWorksheetCount-1 do
|
||||||
|
begin
|
||||||
|
sheet := Workbook.GetWorksheetByIndex(i);
|
||||||
|
AddFontsOfHeaderFooter(sheet.pageLayout.Headers[1], defFnt);
|
||||||
|
AddFontsOfHeaderFooter(sheet.PageLayout.Headers[2], defFnt);
|
||||||
|
AddFontsOfHeaderFooter(sheet.PageLayout.Footers[1], defFnt);
|
||||||
|
AddFontsOfHeaderFooter(sheet.PageLayout.Footers[2], defFnt);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
defFnt.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ Contains all number formats used in the workbook. Overrides the inherited
|
{ Contains all number formats used in the workbook. Overrides the inherited
|
||||||
method to assign a unique name according to the OpenDocument syntax ("N<number>"
|
method to assign a unique name according to the OpenDocument syntax ("N<number>"
|
||||||
to the format items. }
|
to the format items. }
|
||||||
@ -3576,7 +3606,11 @@ begin
|
|||||||
'<office:scripts />');
|
'<office:scripts />');
|
||||||
|
|
||||||
// Fonts
|
// Fonts
|
||||||
WriteFontNames(FSContent);
|
AppendToStream(FSContent,
|
||||||
|
'<office:font-face-decls>');
|
||||||
|
WriteFontNames(FSContent);
|
||||||
|
AppendToStream(FSContent,
|
||||||
|
'</office:font-face-decls>');
|
||||||
|
|
||||||
// Automatic styles
|
// Automatic styles
|
||||||
AppendToStream(FSContent,
|
AppendToStream(FSContent,
|
||||||
@ -3819,45 +3853,20 @@ begin
|
|||||||
Result := Result + '</office:annotation>';
|
Result := Result + '</office:annotation>';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Writes the declaration of the font faces used in the workbook.
|
||||||
|
Is used in styles.xml and content.xml.
|
||||||
|
|
||||||
|
Procedure must be enclosed by
|
||||||
|
<office:font-face-decls> ... </office:font-face-decls>
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsSpreadOpenDocWriter.WriteFontNames(AStream: TStream);
|
procedure TsSpreadOpenDocWriter.WriteFontNames(AStream: TStream);
|
||||||
var
|
var
|
||||||
L: TStringList;
|
L: TStringList;
|
||||||
fnt: TsFont;
|
fnt: TsFont;
|
||||||
hfFnt: TXMLHeaderFooterFont;
|
hfFnt: TXMLHeaderFooterFont;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
defFnt: TsHeaderFooterFont;
|
|
||||||
sheet: TsWorksheet;
|
|
||||||
|
|
||||||
{ Add the fonts used in the specified header/footer line to the
|
|
||||||
HeaderFooterFontList. This is done while the HeaderFooterParser is created. }
|
|
||||||
procedure AddFontsOfHeaderFooter(AText: String; ADefaultFont: TsHeaderFooterFont);
|
|
||||||
begin
|
|
||||||
TsSpreadOpenDocHeaderFooterParser.Create(AText, FHeaderFooterFontList, ADefaultFont).Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// At first take care of the headers and footers, their fonts are not stored
|
|
||||||
// in the Workbook's FontList. Here were store the fonts in the
|
|
||||||
// FHeaderFooterFontList of the reader which is needed also when writing
|
|
||||||
// headers and footers.
|
|
||||||
defFnt := TsHeaderFooterFont.Create(Workbook.GetDefaultFont);
|
|
||||||
try
|
|
||||||
for i:=0 to Workbook.GetWorksheetCount-1 do
|
|
||||||
begin
|
|
||||||
sheet := Workbook.GetWorksheetByIndex(i);
|
|
||||||
AddFontsOfHeaderFooter(sheet.pageLayout.Headers[1], defFnt);
|
|
||||||
AddFontsOfHeaderFooter(sheet.PageLayout.Headers[2], defFnt);
|
|
||||||
AddFontsOfHeaderFooter(sheet.PageLayout.Footers[1], defFnt);
|
|
||||||
AddFontsOfHeaderFooter(sheet.PageLayout.Footers[2], defFnt);
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
defFnt.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Begin writing to stream
|
|
||||||
AppendToStream(AStream,
|
|
||||||
'<office:font-face-decls>');
|
|
||||||
|
|
||||||
// Collect all unique font names in a string list
|
// Collect all unique font names in a string list
|
||||||
L := TStringList.Create;
|
L := TStringList.Create;
|
||||||
try
|
try
|
||||||
@ -3882,10 +3891,6 @@ begin
|
|||||||
finally
|
finally
|
||||||
L.Free;
|
L.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Write end node
|
|
||||||
AppendToStream(AStream,
|
|
||||||
'</office:font-face-decls>');
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.WriteMasterStyles(AStream: TStream);
|
procedure TsSpreadOpenDocWriter.WriteMasterStyles(AStream: TStream);
|
||||||
@ -3919,9 +3924,6 @@ var
|
|||||||
const
|
const
|
||||||
IS_HEADER = true;
|
IS_HEADER = true;
|
||||||
IS_FOOTER = false;
|
IS_FOOTER = false;
|
||||||
var
|
|
||||||
headerstyleStr: array[1..2] of String; // 1=odd=right, 2=even=left
|
|
||||||
footerStyleStr: array[1..2] of String;
|
|
||||||
begin
|
begin
|
||||||
Result := Format(
|
Result := Format(
|
||||||
'<style:master-page style:name="%s" ' +
|
'<style:master-page style:name="%s" ' +
|
||||||
@ -4268,6 +4270,7 @@ begin
|
|||||||
ListAllNumFormats;
|
ListAllNumFormats;
|
||||||
ListAllColumnStyles;
|
ListAllColumnStyles;
|
||||||
ListAllRowStyles;
|
ListAllRowStyles;
|
||||||
|
ListAllHeaderFooterFonts;
|
||||||
|
|
||||||
{ Create the streams that will hold the file contents }
|
{ Create the streams that will hold the file contents }
|
||||||
CreateStreams;
|
CreateStreams;
|
||||||
@ -4547,7 +4550,7 @@ var
|
|||||||
begin
|
begin
|
||||||
fnt := Workbook.GetDefaultFont;
|
fnt := Workbook.GetDefaultFont;
|
||||||
Result := Format(
|
Result := Format(
|
||||||
'<style:text-properties style:font-name="%s" fo:font-size="%.1f" />',
|
'<style:text-properties style:font-name="%s" fo:font-size="%.1fpt" />',
|
||||||
[fnt.FontName, fnt.Size], FPointSeparatorSettings
|
[fnt.FontName, fnt.Size], FPointSeparatorSettings
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
@ -4666,9 +4669,6 @@ end;
|
|||||||
|
|
||||||
function TsSpreadOpenDocWriter.WritePageLayoutAsXMLString(AStyleName: String;
|
function TsSpreadOpenDocWriter.WritePageLayoutAsXMLString(AStyleName: String;
|
||||||
const APageLayout: TsPageLayout): String;
|
const APageLayout: TsPageLayout): String;
|
||||||
const
|
|
||||||
ORIENTATIONS: Array[TsPageOrientation] of string = ('portrait', 'landscape');
|
|
||||||
PAGEORDERS: Array[boolean] of string = ('ttb', 'ltr');
|
|
||||||
var
|
var
|
||||||
pageLayoutStr: String;
|
pageLayoutStr: String;
|
||||||
headerStyleStr: String;
|
headerStyleStr: String;
|
||||||
|
@ -3974,7 +3974,6 @@ var
|
|||||||
number: Double;
|
number: Double;
|
||||||
currSym: String;
|
currSym: String;
|
||||||
fmt: TsCellFormat;
|
fmt: TsCellFormat;
|
||||||
nf: TsNumberFormat;
|
|
||||||
numFmtParams: TsNumFormatParams;
|
numFmtParams: TsNumFormatParams;
|
||||||
maxDig: Integer;
|
maxDig: Integer;
|
||||||
begin
|
begin
|
||||||
|
@ -1156,7 +1156,6 @@ end;
|
|||||||
|
|
||||||
procedure TsNumFormatParams.SetNegativeRed(AEnable: Boolean);
|
procedure TsNumFormatParams.SetNegativeRed(AEnable: Boolean);
|
||||||
var
|
var
|
||||||
section: TsNumFormatSection;
|
|
||||||
el: Integer;
|
el: Integer;
|
||||||
begin
|
begin
|
||||||
// Enable negative-value color
|
// Enable negative-value color
|
||||||
|
@ -2794,7 +2794,6 @@ var
|
|||||||
sfrint, sfrnum, sfrdenom: String;
|
sfrint, sfrnum, sfrdenom: String;
|
||||||
sfrsym, sintnumspace, snumsymspace, ssymdenomspace: String;
|
sfrsym, sintnumspace, snumsymspace, ssymdenomspace: String;
|
||||||
i, numEl: Integer;
|
i, numEl: Integer;
|
||||||
mixed: Boolean;
|
|
||||||
prec: Double;
|
prec: Double;
|
||||||
begin
|
begin
|
||||||
sintnumspace := '';
|
sintnumspace := '';
|
||||||
@ -2810,7 +2809,6 @@ begin
|
|||||||
i := AIndex;
|
i := AIndex;
|
||||||
if AElements[i].Token in (INT_TOKENS + [nftIntTh]) then begin
|
if AElements[i].Token in (INT_TOKENS + [nftIntTh]) then begin
|
||||||
// Split-off integer
|
// Split-off integer
|
||||||
mixed := true;
|
|
||||||
if (AValue >= 1) then
|
if (AValue >= 1) then
|
||||||
begin
|
begin
|
||||||
frint := trunc(AValue);
|
frint := trunc(AValue);
|
||||||
@ -2835,7 +2833,6 @@ begin
|
|||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
// "normal" fraction
|
// "normal" fraction
|
||||||
mixed := false;
|
|
||||||
sfrint := '';
|
sfrint := '';
|
||||||
if ADigits > 0 then
|
if ADigits > 0 then
|
||||||
FloatToFraction(AValue, prec, MaxInt, maxdenom, frnum, frdenom)
|
FloatToFraction(AValue, prec, MaxInt, maxdenom, frnum, frdenom)
|
||||||
@ -2867,7 +2864,7 @@ begin
|
|||||||
AIndex := i+1;
|
AIndex := i+1;
|
||||||
|
|
||||||
// Special cases
|
// Special cases
|
||||||
if {mixed and }(frnum = 0) then
|
if (frnum = 0) then
|
||||||
begin
|
begin
|
||||||
if sfrnum = '' then begin
|
if sfrnum = '' then begin
|
||||||
sintnumspace := '';
|
sintnumspace := '';
|
||||||
|
@ -1198,12 +1198,6 @@ var
|
|||||||
err: TsErrorValue;
|
err: TsErrorValue;
|
||||||
ok: Boolean;
|
ok: Boolean;
|
||||||
cell: PCell;
|
cell: PCell;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fmt: TsCellFormat;
|
|
||||||
begin
|
begin
|
||||||
{ Index to XF Record }
|
{ Index to XF Record }
|
||||||
ReadRowColXF(AStream, ARow, ACol, XF);
|
ReadRowColXF(AStream, ARow, ACol, XF);
|
||||||
@ -1318,7 +1312,7 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsSpreadBIFFReader.ReadMargin(AStream: TStream; AMargin: Integer);
|
procedure TsSpreadBIFFReader.ReadMargin(AStream: TStream; AMargin: Integer);
|
||||||
var
|
var
|
||||||
dbl: Double;
|
dbl: Double = 0.0;
|
||||||
begin
|
begin
|
||||||
AStream.ReadBuffer(dbl, SizeOf(dbl));
|
AStream.ReadBuffer(dbl, SizeOf(dbl));
|
||||||
case AMargin of
|
case AMargin of
|
||||||
@ -1488,7 +1482,7 @@ end;
|
|||||||
procedure TsSpreadBIFFReader.ReadPageSetup(AStream: TStream);
|
procedure TsSpreadBIFFReader.ReadPageSetup(AStream: TStream);
|
||||||
var
|
var
|
||||||
w: Word;
|
w: Word;
|
||||||
dbl: Double;
|
dbl: Double = 0.0;
|
||||||
begin
|
begin
|
||||||
// Paper size
|
// Paper size
|
||||||
w := WordLEToN(AStream.ReadWord);
|
w := WordLEToN(AStream.ReadWord);
|
||||||
@ -3669,7 +3663,6 @@ begin
|
|||||||
end else
|
end else
|
||||||
lCell.ContentType := cctEmpty;
|
lCell.ContentType := cctEmpty;
|
||||||
WriteCellToStream(AStream, @lCell);
|
WriteCellToStream(AStream, @lCell);
|
||||||
// WriteCellCallback(@lCell, AStream);
|
|
||||||
value := varNULL;
|
value := varNULL;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user