fpspreadsheet: Add font support for headers/footers from ods files

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4116 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-05-05 17:38:39 +00:00
parent 3a810728cf
commit 12d3dae6ed
3 changed files with 66 additions and 5 deletions

View File

@@ -71,7 +71,6 @@
<ComponentName Value="MainForm"/> <ComponentName Value="MainForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="main"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="..\shared\scsvparamsform.pas"/> <Filename Value="..\shared\scsvparamsform.pas"/>
@@ -101,7 +100,6 @@
<ComponentName Value="CurrencyForm"/> <ComponentName Value="CurrencyForm"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="scurrencyform"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="..\shared\shyperlinkform.pas"/> <Filename Value="..\shared\shyperlinkform.pas"/>

View File

@@ -67,6 +67,7 @@ type
FRowList: TFPList; FRowList: TFPList;
FPageLayoutList: TFPList; FPageLayoutList: TFPList;
FMasterPageList: TFPList; FMasterPageList: TFPList;
FHeaderFooterFontList: TStringList;
FDateMode: TDateMode; FDateMode: TDateMode;
// Applies internally stored column widths to current worksheet // Applies internally stored column widths to current worksheet
procedure ApplyColWidths; procedure ApplyColWidths;
@@ -639,6 +640,7 @@ begin
FRowList := TFPList.Create; FRowList := TFPList.Create;
FPageLayoutList := TFPList.Create; FPageLayoutList := TFPList.Create;
FMasterPageList := TFPList.Create; FMasterPageList := TFPList.Create;
FHeaderFooterFontList := TStringList.Create;
// Set up the default palette in order to have the default color names correct. // Set up the default palette in order to have the default color names correct.
Workbook.UseDefaultPalette; Workbook.UseDefaultPalette;
@@ -668,6 +670,7 @@ begin
for j := FMasterPageList.Count-1 downto 0 do TObject(FMasterPageList[j]).Free; for j := FMasterPageList.Count-1 downto 0 do TObject(FMasterPageList[j]).Free;
FMasterPageList.Free; FMasterPageList.Free;
FHeaderFooterFontList.Free;
inherited Destroy; inherited Destroy;
end; end;
@@ -883,12 +886,13 @@ end;
procedure TsSpreadOpenDocReader.ReadAutomaticStyles(AStylesNode: TDOMNode); procedure TsSpreadOpenDocReader.ReadAutomaticStyles(AStylesNode: TDOMNode);
var var
nodeName: String; nodeName: String;
layoutNode: TDOMNode; layoutNode, fontNode: TDOMNode;
node, child: TDOMNode; node, child: TDOMNode;
s: String; s: String;
data: TPageLayoutData; data: TPageLayoutData;
isHeader: Boolean; isHeader: Boolean;
h: Double; h: Double;
idx: Integer;
begin begin
if not Assigned(AStylesNode) then if not Assigned(AStylesNode) then
exit; exit;
@@ -896,7 +900,20 @@ begin
while layoutNode <> nil do while layoutNode <> nil do
begin begin
nodeName := layoutNode.NodeName; nodeName := layoutNode.NodeName;
if nodeName = 'style:page-layout' then begin if nodeName = 'style:style' then
begin
s := GetAttrValue(layoutNode, 'style:family');
if s = 'text' then
begin
s := GetAttrValue(layoutNode, 'style:name');
fontNode := layoutNode.FirstChild;
idx := ReadFont(fontNode);
FHeaderFooterFontList.AddObject(s, TObject(PtrInt(idx)));
end;
end
else
if nodeName = 'style:page-layout' then
begin
data := TPageLayoutData.Create; data := TPageLayoutData.Create;
InitPageLayout(data.PageLayout); InitPageLayout(data.PageLayout);
data.Name := GetAttrValue(layoutNode, 'style:name'); data.Name := GetAttrValue(layoutNode, 'style:name');
@@ -1030,8 +1047,12 @@ var
regionNode, textNode, spanNode: TDOMNode; regionNode, textNode, spanNode: TDOMNode;
nodeName: String; nodeName: String;
s: String; s: String;
currFont: TsFont;
fnt: TsFont;
idx: Integer;
begin begin
Result := ''; Result := '';
currFont := FWorkbook.GetDefaultFont;
regionNode := ANode.FirstChild; regionNode := ANode.FirstChild;
while regionNode <> nil do while regionNode <> nil do
begin begin
@@ -1066,6 +1087,46 @@ begin
end; end;
'text:span': 'text:span':
begin begin
// Extract font parameters used
s := GetAttrValue(textNode, 'text:style-name');
if s <> '' then
begin
idx := FHeaderFooterFontList.IndexOf(s);
if idx > -1 then
begin
fnt := FWorkbook.GetFont(PtrInt(FHeaderFooterFontList.Objects[idx]));
if fnt <> nil then
begin
if (fnt.FontName <> currFont.FontName) then
begin
if (fnt.Size <> currFont.Size) then
Result := Format('%s&"%s,%.1f"', [Result, fnt.FontName, fnt.Size])
else
Result := Format('%s&"%s"', [Result, fnt.FontName]);
end;
if ((fssBold in fnt.Style) and not (fssBold in currFont.Style)) or
(not (fssBold in fnt.Style) and (fssBold in currFont.Style))
then
Result := Result + '&B';
if ((fssItalic in fnt.Style) and not (fssItalic in currFont.Style)) or
(not (fssItalic in fnt.Style) and (fssItalic in currFont.Style))
then
Result := Result + '&I';
if ((fssUnderline in fnt.Style) and not (fssUnderline in currFont.Style)) or
(not (fssUnderline in fnt.Style) and (fssUnderline in currFont.Style))
then
Result := Result + '&U';
if ((fssStrikeout in fnt.Style) and not (fssStrikeout in currFont.Style)) or
(not (fssStrikeout in fnt.Style) and (fssStrikeout in currFont.Style))
then
Result := Result + '&S';
{ Currently no support for &E double strikeout, &H shadowed text, &O outlined text, &X superscript, &Y subscript }
currFont := fnt;
end;
end;
end;
// Extract text
spanNode := textNode.FirstChild; spanNode := textNode.FirstChild;
while spanNode <> nil do while spanNode <> nil do
begin begin
@@ -1487,8 +1548,10 @@ begin
end else end else
if (APreferredIndex > -1) then if (APreferredIndex > -1) then
begin begin
{ --- wp: No more missing font #4 now !!!
if (APreferredIndex = 4) then if (APreferredIndex = 4) then
raise Exception.Create('Cannot replace font #4'); raise Exception.Create('Cannot replace font #4');
}
FWorkbook.ReplaceFont(APreferredIndex, fntName, fntSize, fntStyles, fntColor); FWorkbook.ReplaceFont(APreferredIndex, fntName, fntSize, fntStyles, fntColor);
Result := APreferredIndex; Result := APreferredIndex;
end else end else

View File

@@ -2921,7 +2921,7 @@ begin
AStrings.Add(Format(' Start page number=%d', [ASheet.pageLayout.StartPageNumber])) AStrings.Add(Format(' Start page number=%d', [ASheet.pageLayout.StartPageNumber]))
else else
AStrings.Add (' Start page number=automatic'); AStrings.Add (' Start page number=automatic');
AStrings.Add(Format(' Scaling factor=%.0f%%', [ASheet.PageLayout.ScalingFactor])); AStrings.Add(Format(' Scaling factor=%d%%', [ASheet.PageLayout.ScalingFactor]));
AStrings.Add(Format(' Copies=%d', [ASheet.PageLayout.Copies])); AStrings.Add(Format(' Copies=%d', [ASheet.PageLayout.Copies]));
if (ASheet.PageLayout.Options * [poDifferentOddEven, poDifferentFirst] <> []) then if (ASheet.PageLayout.Options * [poDifferentOddEven, poDifferentFirst] <> []) then
begin begin