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:
wp_xxyyzz
2017-03-08 21:36:13 +00:00
parent ea421f483d
commit 48d87a0caf

View File

@@ -2191,6 +2191,12 @@ begin
ColRowToOffset(true, false, HeaderCount, clipArea.Left, tmp);
ColRowToOffset(false, false, HeaderCount, clipArea.Top, tmp);
// Draw bitmap over grid. Take care of clipping.
Canvas.SaveHandleState;
try
InterSectClipRect(Canvas.Handle,
clipArea.Left, clipArea.Top, clipArea.Right, clipArea.Bottom);
for i := 0 to Worksheet.GetImageCount-1 do begin
img := Worksheet.GetPointerToImage(i);
obj := Workbook.GetEmbeddedObj(img^.Index);
@@ -2203,11 +2209,12 @@ begin
imgRect.Bottom := imgRect.Top + h;
OffsetRect(imgRect, ToPixels(img^.OffsetX), ToPixels(img^.OffsetY));
// Nothing to do if image is outside the visible grid area
if not IntersectRect(R, clipArea, imgRect) then
continue;
// If not yet done load image stream into bitmap and scale to required size
if img^.Bitmap = nil then begin
// Load image into bitmap and scale to required size
img^.Bitmap := TBitmap.Create;
TBitmap(img^.Bitmap).SetSize(w, h);
TBitmap(img^.Bitmap).PixelFormat := pf32Bit;
@@ -2225,15 +2232,12 @@ begin
end;
end;
// Draw bitmap over grid. Take care of clipping.
Canvas.SaveHandleState;
try
InterSectClipRect(Canvas.Handle, R.Left, R.Top, R.Right, R.Bottom);
// Draw the bitmap
Canvas.Draw(imgRect.Left, imgRect.Top, TBitmap(img^.Bitmap));
finally
Canvas.RestoreHandleState;
end;
finally
Canvas.RestoreHandleState;
end;
end;