diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 111bd05e2..8dda6aede 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -1304,8 +1304,10 @@ procedure TsSpreadOpenDocReader.ReadAutomaticStyles(AStylesNode: TDOMNode); var nodeName: String; layoutNode, fontNode: TDOMNode; - node, child: TDOMNode; + node, child, childchild: TDOMNode; s: String; + href: String; + imgpos: String; data: TPageLayoutData; isHeader: Boolean; h, dist: Double; @@ -1316,6 +1318,7 @@ var fntStyle: TsHeaderFooterFontStyles; fntColor: TsColor; n: Integer; + hfs: TsHeaderFooterSectionIndex; begin if not Assigned(AStylesNode) then exit; @@ -1472,19 +1475,35 @@ begin // Note: TopMargin and HeaderMargin are not yet the same as in Excel // Will be fixed in ReadMasterStyles where it will be known // whether the header is displayed. - { - data.PageLayout.HeaderMargin := data.PageLayout.TopMargin; - data.PageLayout.TopMargin := data.PageLayout.HeaderMargin + h + dist; - } end else begin data.Pagelayout.FooterMargin := h + dist; - { - data.PageLayout.FooterMargin := data.PageLayout.BottomMargin; - data.PageLayout.BottomMargin := data.PageLayout.FooterMargin + h + dist; - } end; end; + childchild := child.FirstChild; + while Assigned(childchild) do + begin + nodeName := childchild.NodeName; + if nodeName = 'style:background-image' then + begin + href := GetAttrValue(childchild, 'xlink:href'); + imgpos := GetAttrValue(childchild, 'style:position'); + if (href <> '') and (imgpos <> '') then + begin + n := FWorkbook.FindEmbeddedObj(ExtractFileName(href)); + if n > -1 then + begin + if pos('left', imgpos) > 0 then hfs := hfsLeft else + if pos('right', imgpos) > 0 then hfs := hfsRight else + hfs := hfsCenter; + if isHeader then + data.PageLayout.AddHeaderImage(HEADER_FOOTER_INDEX_ALL, hfs, n) else + data.PageLayout.AddFooterImage(HEADER_FOOTER_INDEX_ALL, hfs, n); + end; + end; + end; + childchild := childchild.NextSibling; + end; child := child.NextSibling; end; end; @@ -1521,6 +1540,8 @@ var pagelayout: TsPageLayout; j: Integer; h: Double; + hfs: TsHeaderFooterSectionIndex; + hfnew: Array[TsHeaderFooterSectionIndex] of string; begin if AStylesNode = nil then @@ -1556,7 +1577,17 @@ begin begin s := ReadHeaderFooterText(styleNode); if s <> '' then - pageLayout.Headers[HEADER_FOOTER_INDEX_ODD] := s; + begin + // If the header contains an image add the code &G. + with pagelayout do begin + SplitHeaderFooterText(s, + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + for hfs in TsHeaderFooterSectionIndex do + if HeaderImages[hfs].Index > -1 then hfnew[hfs] := '&G' + hfnew[hfs]; + Headers[HEADER_FOOTER_INDEX_ODD] := JoinHeaderFooterText( + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + end; + end; s := GetAttrValue(styleNode, 'style:display'); if s <> 'false' then begin @@ -1570,8 +1601,16 @@ begin s := ReadHeaderFooterText(styleNode); if s <> '' then begin - pageLayout.Headers[HEADER_FOOTER_INDEX_EVEN] := s; - with pageLayout do Options := Options + [poDifferentOddEven]; + // If the header contains an image add the code &G. + with pagelayout do begin + SplitHeaderFooterText(s, + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + for hfs in TsHeaderFooterSectionIndex do + if HeaderImages[hfs].Index > -1 then hfnew[hfs] := '&G' + hfnew[hfs]; + Headers[HEADER_FOOTER_INDEX_ODD] := JoinHeaderFooterText( + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + Options := Options + [poDifferentOddEven]; + end; end; s := GetAttrValue(styleNode, 'style:display'); if s = 'false' then @@ -1586,7 +1625,14 @@ begin begin s := ReadHeaderFooterText(styleNode); if s <> '' then - pageLayout.Footers[HEADER_FOOTER_INDEX_ODD] := s; + with pagelayout do begin + SplitHeaderFooterText(s, + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + for hfs in TsHeaderFooterSectionIndex do + if FooterImages[hfs].Index > -1 then hfnew[hfs] := '&G' + hfnew[hfs]; + Footers[HEADER_FOOTER_INDEX_ODD] := JoinHeaderFooterText( + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + end; s := GetAttrValue(styleNode, 'style:display'); if s <> 'false' then begin @@ -1600,8 +1646,15 @@ begin s := ReadHeaderFooterText(styleNode); if s <> '' then begin - pageLayout.Footers[HEADER_FOOTER_INDEX_EVEN] := s; - with pageLayout do Options := Options + [poDifferentOddEven]; + with pagelayout do begin + SplitHeaderFooterText(s, + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + for hfs in TsHeaderFooterSectionIndex do + if FooterImages[hfs].Index > -1 then hfnew[hfs] := '&G' + hfnew[hfs]; + Footers[HEADER_FOOTER_INDEX_EVEN] := JoinHeaderFooterText( + hfnew[hfsLeft], hfnew[hfsCenter], hfnew[hfsRight]); + Options := Options + [poDifferentOddEven]; + end; end; s := GetAttrValue(styleNode, 'style:display'); if s = 'false' then diff --git a/components/fpspreadsheet/fpspagelayout.pas b/components/fpspreadsheet/fpspagelayout.pas index 6d1410e76..b07ca375a 100644 --- a/components/fpspreadsheet/fpspagelayout.pas +++ b/components/fpspreadsheet/fpspagelayout.pas @@ -46,10 +46,6 @@ type procedure SetScalingFactor(AValue: Integer); procedure SetStartPageNumber(AValue: Integer); - protected - function JoinHeaderFooterText(const ALeft, ACenter, ARight: String): String; - procedure SplitHeaderFooterText(const AText: String; out ALeft, ACenter, ARight: String); - public constructor Create(AWorksheet: pointer); procedure Assign(ASource: TsPageLayout); @@ -72,6 +68,9 @@ type procedure AddFooterImage(AFooterIndex: Integer; ASection: TsHeaderFooterSectionIndex; AImageIndex: Integer); overload; + function JoinHeaderFooterText(const ALeft, ACenter, ARight: String): String; + procedure SplitHeaderFooterText(const AText: String; out ALeft, ACenter, ARight: String); + procedure GetImageSections(out AHeaderTags, AFooterTags: String); function HasHeaderFooterImages: Boolean; @@ -273,7 +272,7 @@ end; Adds an image to the header. @param AHeaderIndex 0 = header of first page, 1 = header of odd pages, - 2 = 2 header of even pages + 2 = header of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the header. @@ -301,7 +300,7 @@ end; Adds an image to the header. @param AHeaderIndex 0 = header of first page, 1 = header of odd pages, - 2 = 2 header of even pages + 2 = header of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the header. @@ -327,7 +326,7 @@ end; Adds an image to the header. @param AHeaderIndex 0 = header of first page, 1 = header of odd pages, - 2 = 2 header of even pages + 2 = header of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the header. @@ -351,7 +350,7 @@ end; Adds an image to the footer, @param AFooterIndex 0 = footer of first page, 1 = footer of odd pages, - 2 = 2 footer of even pages + 2 = footer of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the footer. @@ -379,7 +378,7 @@ end; Adds an image to the footer, @param AFooterIndex 0 = footer of first page, 1 = footer of odd pages, - 2 = 2 footer of even pages + 2 = footer of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the footer. @@ -404,7 +403,7 @@ end; Adds an image to the footer, @param AFooterIndex 0 = footer of first page, 1 = footer of odd pages, - 2 = 2 footer of even pages + 2 = footer of even pages @param ASection Specifies whether the image is inserted in the left (hfsLeft), center (hfsCenter) or right (hfsRight) part of the footer. @@ -692,7 +691,7 @@ end; procedure TsPageLayout.SplitHeaderFooterText(const AText: String; out ALeft, ACenter, ARight: String); var - pL, pC, pR: Integer; + pL, pC, pR, n: Integer; P, PStart: PChar; begin ALeft := ''; @@ -723,22 +722,14 @@ begin end; if (pL > 0) then begin - if pC > 0 then - ALeft := Copy(AText, pL+2, pC - pL - 1) - else - if pR > 0 then - ARight := Copy(AText, pL, pR - pL - 1) - else - ALeft := Copy(AText, pL+2, MaxInt); - exit; + if pC > 0 then n := pC - pL - 2 else + if pR > 0 then n := pR - pL - 2 else n := MaxInt; + ALeft := Copy(AText, pL+2, n); end; if (pC > 0) then begin - if pR > 0 then - ACenter := Copy(AText, pC+2, pR - pC - 1) - else - ACenter := Copy(AText, pC+2, MaxInt); - exit; + if pR > 0 then n := pR - pC - 2 else n := MaxInt; + ACenter := Copy(AText, pC+2, n); end; if (pR > 0) then ARight := Copy(AText, pR+2, MaxInt); diff --git a/components/fpspreadsheet/fpspreadsheetctrls.pas b/components/fpspreadsheet/fpspreadsheetctrls.pas index 2e0b65b9b..b1b2a2e40 100644 --- a/components/fpspreadsheet/fpspreadsheetctrls.pas +++ b/components/fpspreadsheet/fpspreadsheetctrls.pas @@ -3314,6 +3314,27 @@ begin AStrings.Add(Format(' Header=%s', [StringReplace(ASheet.PageLayout.Headers[1], LineEnding, '\n', [rfReplaceAll])])); AStrings.Add(Format(' Footer=%s', [StringReplace(ASheet.PageLayout.Footers[1], LineEnding, '\n', [rfReplaceAll])])); end; + + if ASheet.PageLayout.HeaderImages[hfsLeft].Index > -1 then + AStrings.Add(' HeaderImage, left=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.HeaderImages[hfsLeft].Index).FileName]) else + AStrings.Add(' HeaderImage, left ='); + if ASheet.PageLayout.HeaderImages[hfsCenter].Index > -1 then + AStrings.Add(' HeaderImage, center=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.HeaderImages[hfsCenter].Index).FileName]) else + AStrings.Add(' HeaderImage, center='); + if ASheet.PageLayout.HeaderImages[hfsRight].Index > -1 then + AStrings.Add(' HeaderImage, right=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.HeaderImages[hfsRight].Index).FileName]) else + AStrings.Add(' HeaderImage, right='); + + if ASheet.PageLayout.FooterImages[hfsLeft].Index > -1 then + AStrings.Add(' FooterImage, left=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.FooterImages[hfsLeft].Index).FileName]) else + AStrings.Add(' FooterImage, left ='); + if ASheet.PageLayout.FooterImages[hfsCenter].Index > -1 then + AStrings.Add(' FooterImage, center=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.FooterImages[hfsCenter].Index).FileName]) else + AStrings.Add(' FooterImage, center='); + if ASheet.PageLayout.FooterImages[hfsRight].Index > -1 then + AStrings.Add(' FooterImage, right=%s', [ASheet.Workbook.GetEmbeddedObj(ASheet.PageLayout.FooterImages[hfsRight].Index).FileName]) else + AStrings.Add(' FooterImage, right='); + s := ''; for po in TsPrintOption do if po in ASheet.PageLayout.Options then s := s + '; ' + GetEnumName(typeInfo(TsPrintOption), ord(po));