You've already forked lazarus-ccr
fpspreadsheet: Fix mis-positioning of images read from ods files in WorksheetGrid
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5801 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -3897,7 +3897,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
idx := FWorkbook.FindEmbeddedObj(ExtractFileName(href));
|
idx := FWorkbook.FindEmbeddedObj(ExtractFileName(href));
|
||||||
FWorksheet.CalcImageCell(idx, x, y, w, h, r, c, dr, dc, sx, sy);
|
FWorksheet.CalcImageCell(idx, x, y, w, h, r, c, dr, dc, sx, sy);
|
||||||
FWorksheet.WriteImage(r, c, idx, dr, dc, sx, sy);
|
FWorksheet.WriteImage(r, c, idx, dc, dr, sx, sy); // order of dc and dr is correct!
|
||||||
end;
|
end;
|
||||||
childShapeNode := childShapeNode.NextSibling;
|
childShapeNode := childShapeNode.NextSibling;
|
||||||
end;
|
end;
|
||||||
|
@ -544,6 +544,7 @@ type
|
|||||||
out x, y, AWidth, AHeight: Double);
|
out x, y, AWidth, AHeight: Double);
|
||||||
function GetImage(AIndex: Integer): TsImage;
|
function GetImage(AIndex: Integer): TsImage;
|
||||||
function GetImageCount: Integer;
|
function GetImageCount: Integer;
|
||||||
|
function GetPointerToImage(AIndex: Integer): PsImage;
|
||||||
procedure RemoveAllImages;
|
procedure RemoveAllImages;
|
||||||
procedure RemoveImage(AIndex: Integer);
|
procedure RemoveImage(AIndex: Integer);
|
||||||
function WriteImage(ARow, ACol: Cardinal; AFileName: String;
|
function WriteImage(ARow, ACol: Cardinal; AFileName: String;
|
||||||
@ -3764,6 +3765,11 @@ begin
|
|||||||
Result := img^;
|
Result := img^;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TsWorksheet.GetPointerToImage(AIndex: Integer): PsImage;
|
||||||
|
begin
|
||||||
|
Result := PsImage(FImages[AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Returns the count of images that are embedded into this sheet.
|
Returns the count of images that are embedded into this sheet.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
@ -3781,6 +3787,15 @@ var
|
|||||||
begin
|
begin
|
||||||
ACol := 0;
|
ACol := 0;
|
||||||
sum := 0;
|
sum := 0;
|
||||||
|
colW := GetColWidth(0, FWorkbook.Units);
|
||||||
|
while (sum + colW < x) do begin
|
||||||
|
sum := sum + colW;
|
||||||
|
inc(ACol);
|
||||||
|
colW := GetColWidth(ACol, FWorkbook.Units);
|
||||||
|
end;
|
||||||
|
AColOffs := x - sum;
|
||||||
|
{
|
||||||
|
sum := 0;
|
||||||
repeat
|
repeat
|
||||||
colW := GetColWidth(ACol, FWorkbook.Units);;
|
colW := GetColWidth(ACol, FWorkbook.Units);;
|
||||||
sum := sum + colW;
|
sum := sum + colW;
|
||||||
@ -3789,7 +3804,18 @@ begin
|
|||||||
sum := sum - colW;
|
sum := sum - colW;
|
||||||
AColOffs := x - sum;
|
AColOffs := x - sum;
|
||||||
dec(ACol);
|
dec(ACol);
|
||||||
|
}
|
||||||
|
|
||||||
|
ARow := 0;
|
||||||
|
sum := 0;
|
||||||
|
rowH := CalcRowHeight(0);
|
||||||
|
while (sum + rowH < y) do begin
|
||||||
|
sum := sum + rowH;
|
||||||
|
inc(ARow);
|
||||||
|
rowH := CalcRowHeight(ARow);
|
||||||
|
end;
|
||||||
|
ARowOffs := y - sum;
|
||||||
|
{
|
||||||
ARow := 0;
|
ARow := 0;
|
||||||
sum := 0;
|
sum := 0;
|
||||||
repeat
|
repeat
|
||||||
@ -3800,6 +3826,7 @@ begin
|
|||||||
sum := sum - rowH;
|
sum := sum - rowH;
|
||||||
ARowOffs := y - sum;
|
ARowOffs := y - sum;
|
||||||
dec(ARow);
|
dec(ARow);
|
||||||
|
}
|
||||||
|
|
||||||
embObj := FWorkbook.GetEmbeddedObj(AIndex);
|
embObj := FWorkbook.GetEmbeddedObj(AIndex);
|
||||||
AScaleX := AWidth / embObj.ImageWidth;
|
AScaleX := AWidth / embObj.ImageWidth;
|
||||||
|
@ -2180,7 +2180,7 @@ procedure TsCustomWorksheetGrid.DrawImages;
|
|||||||
|
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
img: TsImage;
|
img: PsImage;
|
||||||
obj: TsEmbeddedObj;
|
obj: TsEmbeddedObj;
|
||||||
clipArea, imgRect, R: TRect;
|
clipArea, imgRect, R: TRect;
|
||||||
w, h: Integer;
|
w, h: Integer;
|
||||||
@ -2192,34 +2192,34 @@ begin
|
|||||||
ColRowToOffset(false, false, HeaderCount, clipArea.Top, tmp);
|
ColRowToOffset(false, false, HeaderCount, clipArea.Top, tmp);
|
||||||
|
|
||||||
for i := 0 to Worksheet.GetImageCount-1 do begin
|
for i := 0 to Worksheet.GetImageCount-1 do begin
|
||||||
img := Worksheet.GetImage(i);
|
img := Worksheet.GetPointerToImage(i);
|
||||||
obj := Workbook.GetEmbeddedObj(img.Index);
|
obj := Workbook.GetEmbeddedObj(img^.Index);
|
||||||
|
|
||||||
w := ToPixels(obj.ImageWidth * img.ScaleX);
|
w := ToPixels(obj.ImageWidth * img^.ScaleX);
|
||||||
h := ToPixels(obj.ImageHeight * img.ScaleY);
|
h := ToPixels(obj.ImageHeight * img^.ScaleY);
|
||||||
|
|
||||||
imgRect := CellRect(img.Col + HeaderCount, img.Row + HeaderCount);
|
imgRect := CellRect(img^.Col + HeaderCount, img^.Row + HeaderCount);
|
||||||
imgRect.Right := imgRect.Left + w;
|
imgRect.Right := imgRect.Left + w;
|
||||||
imgRect.Bottom := imgRect.Top + h;
|
imgRect.Bottom := imgRect.Top + h;
|
||||||
OffsetRect(imgRect, ToPixels(img.OffsetX), ToPixels(img.OffsetY));
|
OffsetRect(imgRect, ToPixels(img^.OffsetX), ToPixels(img^.OffsetY));
|
||||||
|
|
||||||
if not IntersectRect(R, clipArea, imgRect) then
|
if not IntersectRect(R, clipArea, imgRect) then
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if img.Bitmap = nil then begin
|
if img^.Bitmap = nil then begin
|
||||||
// Load image into bitmap and scale to required size
|
// Load image into bitmap and scale to required size
|
||||||
img.Bitmap := TBitmap.Create;
|
img^.Bitmap := TBitmap.Create;
|
||||||
TBitmap(img.Bitmap).SetSize(w, h);
|
TBitmap(img^.Bitmap).SetSize(w, h);
|
||||||
TBitmap(img.Bitmap).PixelFormat := pf32Bit;
|
TBitmap(img^.Bitmap).PixelFormat := pf32Bit;
|
||||||
TBitmap(img.Bitmap).Transparent := true;
|
TBitmap(img^.Bitmap).Transparent := true;
|
||||||
pic := TPicture.Create;
|
pic := TPicture.Create;
|
||||||
try
|
try
|
||||||
obj.Stream.Position := 0;
|
obj.Stream.Position := 0;
|
||||||
pic.LoadFromStream(obj.Stream);
|
pic.LoadFromStream(obj.Stream);
|
||||||
if pic.Bitmap <> nil then
|
if pic.Bitmap <> nil then
|
||||||
TBitmap(img.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Bitmap)
|
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Bitmap)
|
||||||
else if pic.Graphic <> nil then
|
else if pic.Graphic <> nil then
|
||||||
TBitmap(img.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Graphic);
|
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Graphic);
|
||||||
finally
|
finally
|
||||||
pic.Free;
|
pic.Free;
|
||||||
end;
|
end;
|
||||||
@ -2229,7 +2229,7 @@ begin
|
|||||||
Canvas.SaveHandleState;
|
Canvas.SaveHandleState;
|
||||||
try
|
try
|
||||||
InterSectClipRect(Canvas.Handle, R.Left, R.Top, R.Right, R.Bottom);
|
InterSectClipRect(Canvas.Handle, R.Left, R.Top, R.Right, R.Bottom);
|
||||||
Canvas.Draw(imgRect.Left, imgRect.Top, TBitmap(img.Bitmap));
|
Canvas.Draw(imgRect.Left, imgRect.Top, TBitmap(img^.Bitmap));
|
||||||
finally
|
finally
|
||||||
Canvas.RestoreHandleState;
|
Canvas.RestoreHandleState;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user