FPCanvas: FillRect/Ellipse etc. paint 1px too much to right&bottom
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Example: FPCanvas.FillRect(0, 0, 50, 50) paints a rectangle with 51x51 pixels.
1.) This is inconsistent with other image libraries (LCL Graphics, Delphi VCL Graphics, BGRABitmap etc.) that paint a rectangle with 50x50 pixels.
2.) In FPCanvas if you draw Rect(0, 0, 50, 50) and Rect(50, 0, 100, 50) there is a 1px overlay between them. (Seen e.g. with dmAlphaBlend painting as in #34266 (closed).)
3.) Rect(0, 0, 50, 50) has a width/height of 50 pixels - see "function TRect.getWidth" in FPC sources. In FPCanvas if you draw Rect(0, 0, 50, 50) it is 51x51 pixels.
4.) In FPCanvas if you draw Rect(0, 0, 0, 0) you get a 1px dot.
Other painting routines (Ellipse ...) are affected as well.
Conclusion:
All rectangle-aware draw methods should not include the right/bottom coordinate into the painting area.
Steps to reproduce:
The following program compares LCL Graphics with FPCanvas. You can easily remove LCL units and the procedure DrawLCL to make it FPC-only.
program FPCanvasDraw;
{$mode objfpc}{$H+}
uses
FPImage, FPImgCanv, FPCanvas, FPWriteBMP, Classes, SysUtils, Graphics, Interfaces;
procedure DrawFPC;
var
xNew: TFPMemoryImage;
xCanvas: TFPImageCanvas;
xRect: TRect;
begin
xNew := nil;
xCanvas := nil;
try
xNew := TFPMemoryImage.Create(5, 5);
xCanvas := TFPImageCanvas.Create(xNew);
xCanvas.Pen.Style := psClear;
xCanvas.Brush.FPColor := colRed;
xCanvas.FillRect(0, 0, xNew.Width, xNew.Height);
// draw rectagle
xRect.Top := 1;
xRect.Left := 1;
xRect.Width := 3;
xRect.Height := 3;
xCanvas.Brush.FPColor := colYellow;
xCanvas.FillRect(xRect); // draws a 4x4 rectangle !!!
xNew.SaveToFile('fpc.bmp');
finally
xCanvas.Free;
xNew.Free;
end;
end;
procedure DrawLCL;
var
xNew: TBitmap;
xCanvas: TCanvas;
xRect: TRect;
begin
xNew := TBitmap.Create;
try
xNew.SetSize(5, 5);
xCanvas := xNew.Canvas;
xCanvas.Pen.Style := psClear;
xCanvas.Brush.Color := clRed;
xCanvas.FillRect(0, 0, xNew.Width, xNew.Height);
// draw rectagle
xRect.Top := 1;
xRect.Left := 1;
xRect.Width := 3;
xRect.Height := 3;
xCanvas.Brush.Color := clYellow;
xCanvas.FillRect(xRect);
xNew.SaveToFile('lcl.bmp');
finally
xNew.Free;
end;
end;
begin
DrawFPC;
DrawLCL;
end.
Mantis conversion info:
- Mantis ID: 35070
- Version: 3.3.1
- Monitored by: » AntonK (Anton Kavalenka)