You've already forked lazarus-ccr
fpspreadsheet: More efficient clipping in drawing of images on WorksheetGrid
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5802 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -2191,49 +2191,53 @@ begin
|
|||||||
ColRowToOffset(true, false, HeaderCount, clipArea.Left, tmp);
|
ColRowToOffset(true, false, HeaderCount, clipArea.Left, tmp);
|
||||||
ColRowToOffset(false, false, HeaderCount, clipArea.Top, tmp);
|
ColRowToOffset(false, false, HeaderCount, clipArea.Top, tmp);
|
||||||
|
|
||||||
for i := 0 to Worksheet.GetImageCount-1 do begin
|
// Draw bitmap over grid. Take care of clipping.
|
||||||
img := Worksheet.GetPointerToImage(i);
|
Canvas.SaveHandleState;
|
||||||
obj := Workbook.GetEmbeddedObj(img^.Index);
|
try
|
||||||
|
InterSectClipRect(Canvas.Handle,
|
||||||
|
clipArea.Left, clipArea.Top, clipArea.Right, clipArea.Bottom);
|
||||||
|
|
||||||
w := ToPixels(obj.ImageWidth * img^.ScaleX);
|
for i := 0 to Worksheet.GetImageCount-1 do begin
|
||||||
h := ToPixels(obj.ImageHeight * img^.ScaleY);
|
img := Worksheet.GetPointerToImage(i);
|
||||||
|
obj := Workbook.GetEmbeddedObj(img^.Index);
|
||||||
|
|
||||||
imgRect := CellRect(img^.Col + HeaderCount, img^.Row + HeaderCount);
|
w := ToPixels(obj.ImageWidth * img^.ScaleX);
|
||||||
imgRect.Right := imgRect.Left + w;
|
h := ToPixels(obj.ImageHeight * img^.ScaleY);
|
||||||
imgRect.Bottom := imgRect.Top + h;
|
|
||||||
OffsetRect(imgRect, ToPixels(img^.OffsetX), ToPixels(img^.OffsetY));
|
|
||||||
|
|
||||||
if not IntersectRect(R, clipArea, imgRect) then
|
imgRect := CellRect(img^.Col + HeaderCount, img^.Row + HeaderCount);
|
||||||
continue;
|
imgRect.Right := imgRect.Left + w;
|
||||||
|
imgRect.Bottom := imgRect.Top + h;
|
||||||
|
OffsetRect(imgRect, ToPixels(img^.OffsetX), ToPixels(img^.OffsetY));
|
||||||
|
|
||||||
if img^.Bitmap = nil then begin
|
// Nothing to do if image is outside the visible grid area
|
||||||
// Load image into bitmap and scale to required size
|
if not IntersectRect(R, clipArea, imgRect) then
|
||||||
img^.Bitmap := TBitmap.Create;
|
continue;
|
||||||
TBitmap(img^.Bitmap).SetSize(w, h);
|
|
||||||
TBitmap(img^.Bitmap).PixelFormat := pf32Bit;
|
// If not yet done load image stream into bitmap and scale to required size
|
||||||
TBitmap(img^.Bitmap).Transparent := true;
|
if img^.Bitmap = nil then begin
|
||||||
pic := TPicture.Create;
|
img^.Bitmap := TBitmap.Create;
|
||||||
try
|
TBitmap(img^.Bitmap).SetSize(w, h);
|
||||||
obj.Stream.Position := 0;
|
TBitmap(img^.Bitmap).PixelFormat := pf32Bit;
|
||||||
pic.LoadFromStream(obj.Stream);
|
TBitmap(img^.Bitmap).Transparent := true;
|
||||||
if pic.Bitmap <> nil then
|
pic := TPicture.Create;
|
||||||
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Bitmap)
|
try
|
||||||
else if pic.Graphic <> nil then
|
obj.Stream.Position := 0;
|
||||||
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Graphic);
|
pic.LoadFromStream(obj.Stream);
|
||||||
finally
|
if pic.Bitmap <> nil then
|
||||||
pic.Free;
|
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Bitmap)
|
||||||
|
else if pic.Graphic <> nil then
|
||||||
|
TBitmap(img^.Bitmap).Canvas.StretchDraw(Rect(0, 0, w, h), pic.Graphic);
|
||||||
|
finally
|
||||||
|
pic.Free;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
// Draw bitmap over grid. Take care of clipping.
|
// Draw the bitmap
|
||||||
Canvas.SaveHandleState;
|
|
||||||
try
|
|
||||||
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
|
|
||||||
Canvas.RestoreHandleState;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
|
Canvas.RestoreHandleState;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user