I assume that scale(factor) method should be the simplest way to resize the whole canvas. In fact it is not true when it contains paths and text at the same time.
The problem was mentioned in
https://forum.lazarus.freepascal.org/index.php/topic,36284.0.html but still not solved. Here is another example.
procedure txt();
begin
with bmp.Canvas2D do begin
fillStyle ('rgb(0,0,0)');
fontEmHeight:=50;
FillText('Text',50,50);
end;
end;
procedure rct();
begin
with bmp.Canvas2D do begin
fillStyle ('rgb(255,0,0)');
FillRect(50,50,50,50);
end;
end;
procedure TForm2.FormPaint(Sender: TObject);
var c:single;
begin
bmp.SetSize(ClientWidth,ClientHeight);
bmp.Fill(BGRA(210,210,210));
with bmp.Canvas2D do begin
rct;
txt;
end;
bmp.Draw(Canvas,0,0);
end;
procedure TForm2.FormShow(Sender: TObject);
begin
bmp := TBGRABitmap.Create(ClientWidth,ClientHeight,BGRA(210,210,210));
bmp.fontRenderer:=TBGRAVectorizedFontRenderer.Create;
bmp.Canvas2D.save;
end;
The result is shown on the 1st picture and is quite expected.
Next I scaled the canvas with a factor of 2 before placing rect and text on it:
procedure TForm2.FormPaint(Sender: TObject);
var c:single;
begin
bmp.SetSize(ClientWidth,ClientHeight);
bmp.Fill(BGRA(210,210,210));
with bmp.Canvas2D do begin
scale(2);
rct;
txt;
end;
bmp.Draw(Canvas,0,0);
end;
The red square is changed correctly: the size is doubled and the starting point is moved accordingly (x and y are doubled).
The text size is doubled as well. However its staring point is not changed. As a result the whole picture is distorted.
Is it a bug or deliberate behavior?