From e9fc0f2a36208bb9641070a896c3616dd24a033a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 8 Aug 2021 15:24:43 +0000 Subject: [PATCH] fpspreadsheet: Fix ods reader crashing when the file contains an embedded chart. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8066 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/common/fpsopendocument.pas | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas index 893af8f56..50761cd2d 100644 --- a/components/fpspreadsheet/source/common/fpsopendocument.pas +++ b/components/fpspreadsheet/source/common/fpsopendocument.pas @@ -4731,24 +4731,25 @@ procedure TsSpreadOpenDocReader.ReadShape(ANode: TDOMNode; if href <> '' then begin idx := TsWorkbook(FWorkbook).FindEmbeddedObj(ExtractFileName(href)); - with FWorksheet as TsWorksheet do begin - // When called from a cell node, x and y are relative to the cell. - // When called from the Shapes node, x and y refer to the worksheet. - CalcImageCell(idx, x, y, w, h, r, c, dy, dx, sx, sy); // order of dx and dy is correct! - if ARow <> UNASSIGNED_ROW_COL_INDEX then begin - r := ARow; - dy := y; + if idx > -1 then + with FWorksheet as TsWorksheet do begin + // When called from a cell node, x and y are relative to the cell. + // When called from the Shapes node, x and y refer to the worksheet. + CalcImageCell(idx, x, y, w, h, r, c, dy, dx, sx, sy); // order of dx and dy is correct! + if ARow <> UNASSIGNED_ROW_COL_INDEX then begin + r := ARow; + dy := y; + end; + if ACol <> UNASSIGNED_ROW_COL_INDEX then begin + c := ACol; + dx := x; + end; + idx := WriteImage(r, c, idx, dx, dy, sx, sy); + if AHLink <> '' then begin + img := GetPointerToImage(idx); + img^.HyperlinkTarget := AHLink; + end; end; - if ACol <> UNASSIGNED_ROW_COL_INDEX then begin - c := ACol; - dx := x; - end; - idx := WriteImage(r, c, idx, dx, dy, sx, sy); - if AHLink <> '' then begin - img := GetPointerToImage(idx); - img^.HyperlinkTarget := AHLink; - end; - end; end; childNode := childnode.NextSibling; end;