From e17429c92cd8c162e4a53e93e0b3e8f9c5cd98ee Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 4 Mar 2016 23:43:40 +0000 Subject: [PATCH] fpspreadsheet: Load images for header/footer into workbook's embedded streams list. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4531 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpspagelayout.pas | 28 +++++++++++++++------- components/fpspreadsheet/fpspreadsheet.pas | 11 +++++---- components/fpspreadsheet/fpstypes.pas | 18 +++++++------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/components/fpspreadsheet/fpspagelayout.pas b/components/fpspreadsheet/fpspagelayout.pas index 67c0b3340..9cb1f3c56 100644 --- a/components/fpspreadsheet/fpspagelayout.pas +++ b/components/fpspreadsheet/fpspagelayout.pas @@ -49,10 +49,10 @@ type procedure Assign(ASource: TsPageLayout); { Images embedded in header and/or footer } - procedure AddHeaderImage(ASection: TsHeaderFooterSection; - const AFilename: String); - procedure AddFooterImage(ASection: TsHeaderFooterSection; - const AFilename: String); + procedure AddHeaderImage(AHeaderIndex: Integer; + ASection: TsHeaderFooterSection; const AFilename: String); + procedure AddFooterImage(AFooterIndex: Integer; + ASection: TsHeaderFooterSection; const AFilename: String); { Repeated rows and columns } function HasRepeatedCols: Boolean; @@ -248,30 +248,42 @@ begin FPrintranges[i] := ASource.FPrintRanges[i]; end; -procedure TsPageLayout.AddHeaderImage(ASection: TsHeaderFooterSection; - const AFilename: String); +procedure TsPageLayout.AddHeaderImage(AHeaderIndex: Integer; + ASection: TsHeaderFooterSection; const AFilename: String); var book: TsWorkbook; idx: Integer; begin + if FWorksheet = nil then + raise Exception.Create('[TsPageLayout.AddHeaderImage] Worksheet is nil.'); book := TsWorksheet(FWorksheet).Workbook; idx := book.FindEmbeddedStream(AFilename); if idx = -1 then + begin idx := book.AddEmbeddedStream(AFilename); + book.GetEmbeddedStream(idx).LoadFromFile(AFileName); + end; FHeaderImages[ASection].Index := idx; + FHeaders[AHeaderIndex] := FHeaders[AHeaderIndex] + '&G'; end; -procedure TsPageLayout.AddFooterImage(ASection: TsHeaderFooterSection; - const AFileName: String); +procedure TsPageLayout.AddFooterImage(AFooterIndex: Integer; + ASection: TsHeaderFooterSection; const AFileName: String); var book: TsWorkbook; idx: Integer; begin + if FWorksheet = nil then + raise Exception.Create('[TsPageLayout.AddFooterImage] Worksheet is nil.'); book := TsWorksheet(FWorksheet).Workbook; idx := book.FindEmbeddedStream(AFilename); if idx = -1 then + begin idx := book.AddEmbeddedStream(AFilename); + book.GetEmbeddedStream(idx).LoadFromFile(AFileName); + end; FFooterImages[ASection].Index := idx; + FFooters[AFooterIndex] := FFooters[AFooterIndex] + '&G'; end; {@@ ---------------------------------------------------------------------------- diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index 82899c8a8..97f402228 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -3423,11 +3423,12 @@ end; @param ARow Index of the row at which the image begins (top edge) @param ACol Index of the column at which the image begins (left edge) @param AFileName Name of the image file - @param AOffsetX The image is offset horizontally by this pixel count from - the left edge of the anchor cell. May reach into another - cell. - @param AOffsetY The image is offset vertically by this pixel count from the - top edge of the anchor cell. May reach into another cell. + @param AOffsetX The image is offset horizontally from the left edge of + the anchor cell. May reach into another cell. + Value is in millimeters. + @param AOffsetY The image is offset vertically from the top edge of the + anchor cell. May reach into another cell. + Value is in millimeters. @param AScaleX Horizontal scaling factor of the image @param AScaleY Vertical scaling factor of the image @return Index into the internal image list. diff --git a/components/fpspreadsheet/fpstypes.pas b/components/fpspreadsheet/fpstypes.pas index 12a20858d..66afd616b 100644 --- a/components/fpspreadsheet/fpstypes.pas +++ b/components/fpspreadsheet/fpstypes.pas @@ -658,15 +658,15 @@ type { Index of format record in the workbook's FCellFormatList } FormatIndex: Integer; { Cell content } - UTF8StringValue: String; // Strings cannot be part of a variant record - RichTextParams: TsRichTextParams; // Formatting of individual text ranges - FormulaValue: String; + UTF8StringValue: String; // Strings cannot be part of a variant record + RichTextParams: TsRichTextParams; // Formatting of individual text ranges + FormulaValue: String; // Formula for calculation of cell content case ContentType: TCellContentType of // variant part must be at the end cctEmpty : (); // has no data at all cctFormula : (); // FormulaValue is outside the variant record cctNumber : (Numbervalue: Double); cctUTF8String : (); // UTF8StringValue is outside the variant record - cctDateTime : (DateTimevalue: TDateTime); + cctDateTime : (DateTimeValue: TDateTime); cctBool : (BoolValue: boolean); cctError : (ErrorValue: TsErrorValue); end; @@ -676,16 +676,16 @@ type {@@ Embedded image } TsImage = record - Row, Col: Cardinal; - Index: Integer; - OffsetX, OffsetY: Double; // mm - ScaleX, ScaleY: Double; + Row, Col: Cardinal; // cell for top/left edge of the image (anchor) + Index: Integer; // index into the workbook's embedded streams list + OffsetX, OffsetY: Double; // mm, relative to anchor + ScaleX, ScaleY: Double; // scaling factor of image end; PsImage = ^TsImage; {@@ Image embedded in header or footer} TsHeaderFooterImage = record - Index: Integer; + Index: Integer; // index into the workbook's embedded streams list end; {@@ Page orientation for printing }