fpspreadsheet: Fix display of images inserted in WorksheetGrid under gtk as black areas.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7331 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2020-03-11 12:34:46 +00:00
parent 5457aab56b
commit 5def48c316
6 changed files with 46 additions and 68 deletions

View File

@ -4124,7 +4124,7 @@ var
begin
img := PsImage(FImages[AIndex]);
if (img <> nil) then begin
if (img^.Bitmap <> nil) then img^.Bitmap.Free;
if (img^.Picture <> nil) then img^.Picture.Free;
img^.HyperlinkTarget := '';
img^.HyperlinkToolTip := '';
end;

View File

@ -829,7 +829,7 @@ type
Index: Integer; // index into the workbook's embedded streams list
OffsetX, OffsetY: Double; // mm, relative to anchor
ScaleX, ScaleY: Double; // scaling factor of image
Bitmap: TObject; // used for bitmap for display in grid
Picture: TObject; // used for TPicture to display in grid
HyperlinkTarget: String; // Hyperlink assigned to the image
HyperlinkToolTip: String; // Tooltip for hyperlink of the image
end;

View File

@ -2580,7 +2580,7 @@ begin
AValue.OffsetY := AOffsetY;
AValue.ScaleX := AScaleX;
AValue.ScaleY := AScaleY;
AValue.Bitmap := nil; // to be initialized by viewing application
AValue.Picture := nil; // to be initialized by viewing application
AValue.Index := -1;
AValue.HyperlinkTarget := '';
AValue.HyperlinkToolTip := '';

View File

@ -1810,7 +1810,6 @@ procedure TsWorkbookTabControl.ListenerNotification(
var
i: Integer;
sheet: TsWorksheet;
sheetName: String;
begin
Unused(AData);

View File

@ -2965,7 +2965,6 @@ var
imgRect: TRect;
w, h: Integer;
coloffs, rowoffs: Integer;
pic: TPicture;
rgn: HRGN;
fc, fr: Integer;
R: TRect = (Left:0; Top:0; Right: 0; Bottom: 0);
@ -2977,72 +2976,51 @@ begin
GetScrollOffset(rowOffs, colOffs);
fc := FHeaderCount + FFrozenCols;
fr := FHeaderCount + FFrozenRows;
(*
Canvas.SaveHandleState;
try
// Draw bitmap over grid. Take care of clipping.
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);
// Frozen part of the grid draw only images which are anchored there.
case AGridPart of
DRAW_NON_FROZEN:
;
DRAW_FROZEN_ROWS:
if (integer(img^.Row) >= fr) then Continue;
DRAW_FROZEN_COLS:
if (integer(img^.Col) >= fc) then Continue;
DRAW_FROZEN_CORNER:
if (integer(img^.Row) >= fr) or (integer(img^.Col) >= fc) then Continue;
end;
for i := 0 to Worksheet.GetImageCount-1 do begin
img := Worksheet.GetPointerToImage(i);
obj := Workbook.GetEmbeddedObj(img^.Index);
// Size of image and its position
w := ToPixels(obj.ImageWidth * img^.ScaleX);
h := ToPixels(obj.ImageHeight * img^.ScaleY);
imgRect := GetImageRect(img, w, h, rowoffs, coloffs);
// 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
img^.Bitmap := TBitmap.Create;
TBitmap(img^.Bitmap).SetSize(w, h);
TBitmap(img^.Bitmap).PixelFormat := pf32Bit;
TBitmap(img^.Bitmap).Transparent := true;
end;
pic := TPicture.Create;
try
obj.Stream.Position := 0;
pic.LoadFromStream(obj.Stream);
if pic.Bitmap <> nil then
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;
// Draw the bitmap
rgn := CreateRectRgn(clipArea.Left, clipArea.Top, clipArea.Right, clipArea.Bottom);
try
SelectClipRgn(Canvas.Handle, rgn);
Canvas.Draw(imgRect.Left, imgRect.Top, TBitmap(img^.Bitmap));
finally
DeleteObject(rgn);
end;
// Frozen part of the grid draw only images which are anchored there.
case AGridPart of
DRAW_NON_FROZEN:
;
DRAW_FROZEN_ROWS:
if (integer(img^.Row) >= fr) then Continue;
DRAW_FROZEN_COLS:
if (integer(img^.Col) >= fc) then Continue;
DRAW_FROZEN_CORNER:
if (integer(img^.Row) >= fr) or (integer(img^.Col) >= fc) then Continue;
end;
{
finally
Canvas.RestoreHandleState;
end; }
// Size of image and its position
w := ToPixels(obj.ImageWidth * img^.ScaleX);
h := ToPixels(obj.ImageHeight * img^.ScaleY);
imgRect := GetImageRect(img, w, h, rowoffs, coloffs);
// 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 picture and scale to required size
if img^.Picture = nil then
begin
img^.Picture := TPicture.Create;
obj.Stream.Position := 0;
TPicture(img^.Picture).LoadFromStream(obj.Stream);
end;
// Scale and draw image
rgn := CreateRectRgn(clipArea.Left, clipArea.Top, clipArea.Right, clipArea.Bottom);
try
SelectClipRgn(Canvas.Handle, rgn);
R := Rect(0, 0, w, h);
OffsetRect(R, imgRect.Left, imgRect.Top);
Canvas.StretchDraw(R, TPicture(img^.Picture).Graphic);
finally
DeleteObject(rgn);
end;
end;
end;
{@@ ----------------------------------------------------------------------------

View File

@ -106,7 +106,8 @@ type
implementation
uses
Types, Math, LCLType, LCLIntf, LazUTF8, fpsUtils;
Types, Math, LCLType, LCLIntf, LazUTF8,
fpsUtils;
const
{@@ Font size factor for sub-/superscript characters }