SynPDF icon indicating copy to clipboard operation
SynPDF copied to clipboard

DrawText without DT_NOCLIP doesn't do horizontal clipping

Open stijnsanders opened this issue 5 months ago • 2 comments

considering this code, I expect the second rectangle to have text clipped to the inside of the rectangle, both for the bottom in vertical direction, as to the right in the horizontal direction (als perhaps also on the left when using DT_CENTER, but haven't tested it here):

uses SynPDF;

procedure TestDrawTextClipping;
var
  b:TBitmap;
  p:TPdfDocumentGDI;
  c:TCanvas;
  i:integer;
  s:string;
  r:TRect;
begin
  //b:=TBitmap.Create;
  p:=TPdfDocumentGDI.Create;
  try
	//b.Width:=800;b.Height:=1000;c:=b.Canvas;
	p.AddPage; c:=p.VCLCanvas;

	c.Lock;
	try
	  c.Pen.Style:=psSolid;
	  c.Pen.Color:=clBlack;
	  c.Pen.Width:=1;
	  c.Brush.Style:=bsClear;

	  s:='';
	  for i:=0 to 7 do s:=s+'test1 test2 test3 test4 test5'#13#10;

	  r:=Rect(10,10,100,100);
	  c.Rectangle(r);
	  DrawText(c.Handle,PChar(s),Length(s),r,DT_LEFT or DT_NOCLIP);

	  r:=Rect(10,510,100,600);
	  c.Rectangle(r);
	  DrawText(c.Handle,PChar(s),Length(s),r,DT_LEFT);

	finally
	  c.Unlock;
	end;

	//b.SaveToFile('test.bmp');
	p.SaveToFile('test.pdf');
  finally
	//b.Free;
	p.Free;
  end;
end;

test.pdf

stijnsanders avatar Jul 15 '25 14:07 stijnsanders

Hi, you can try my version of SynPdf, I have tried to implement basic clipping functions. PDFEngine Clipping Implementation + Output stream optimizations

MtwStark avatar Jul 21 '25 14:07 MtwStark

Have you considered a pull request? What are the chances of your fix to get merged/added here?

stijnsanders avatar Jul 24 '25 21:07 stijnsanders