#1 2016-05-31 09:09:37

petrih
Member
Registered: 2015-10-22
Posts: 8

Text font messed up with small font and clear brush

Here's an example code:

procedure TForm1.Button1Click(Sender: TObject);
var
  Doc: TPdfDocumentGDI;
  Rect: TRect;
begin
  Doc:=TPdfDocumentGDI.Create;
  Doc.AddPage;

  Doc.VCLCanvas.Brush.Style:=bsClear;
  Doc.VCLCanvas.Font.Name := 'Arial';
  Doc.VCLCanvas.Font.Size := 1;
  Doc.VCLCanvas.Font.PixelsPerInch := 75;

  Rect := TRect.Create(2,0,594,16);
  Doc.VCLCanvas.TextRect(Rect, 2, 0, '...');

  Rect.Top := 16;
  Rect.Bottom := 31;
  Doc.VCLCanvas.Font.Size := 9;
  Doc.VCLCanvas.TextRect(Rect, 2, 19, 'Abc');

  Doc.SaveToFile('test.pdf');
end;

It creates a simple pdf, draws '...' to the canvas at font size 1, then draws 'Abc' at font size 9 under it and finally saves it to a file.

The problem is that 'Abc' is sort of stretched across, completely messing the text:
9NozuxJ.png

Any idea what is causing this or is it a bug in the PDF engine?

Offline

#2 2016-05-31 13:45:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Text font messed up with small font and clear brush

AFAIK Font.PixelsPerInch is not supported yet.

Offline

#3 2016-06-01 05:57:34

petrih
Member
Registered: 2015-10-22
Posts: 8

Re: Text font messed up with small font and clear brush

Thanks for tip! Tested without PixelsPerInc and still some problems. Font size 9 prints out as it should be now, but at least font sizes 8, 10 and 11 (possibly more) still has the same problem.

procedure TForm1.Button3Click(Sender: TObject);
var
  Doc: TPdfDocumentGDI;
  Rect: TRect;
begin
  Doc:=TPdfDocumentGDI.Create;
  Doc.AddPage;

  Doc.VCLCanvas.Brush.Style:=bsClear;
  Doc.VCLCanvas.Font.Name := 'Arial';
  Doc.VCLCanvas.Font.Size := 1;
  Rect := TRect.Create(195,28,594,41);
  Doc.VCLCanvas.TextRect(Rect, 218, 28, '...');


  Rect.Top := 45;
  Rect.Bottom := 59;
  Doc.VCLCanvas.Font.Size := 10; // this works with 9, but breaks with 8, 10, 11
  Doc.VCLCanvas.TextRect(Rect, 218, 45, 'Test');

  Doc.SaveToFile('test.pdf');
end;

Offline

#4 2016-06-01 08:34:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Text font messed up with small font and clear brush

Perhaps the DPI on VCL/metafile side is too small.
(there is no DPI limitation involved at PDF size, since it uses floating point coordinates)

Offline

#5 2016-06-01 10:43:23

petrih
Member
Registered: 2015-10-22
Posts: 8

Re: Text font messed up with small font and clear brush

Meaning the ScreenLogPixels-property? Tried messing with it but seems it doesn't affect this. Interesting thing is that if I draw text at font 9, every textrect after it is drawn properly.

  Doc:=TPdfDocumentGDI.Create;
  Doc.ScreenLogPixels := 72;
  Doc.AddPage;

  Doc.VCLCanvas.Brush.Style:=bsClear;
  Doc.VCLCanvas.Font.Name := 'Arial';
  Doc.VCLCanvas.Font.Size := 1;
  Rect := TRect.Create(195,28,594,41);
  Doc.VCLCanvas.TextRect(Rect, 218, 28, '...');

  Rect.Top := 45;
  Rect.Bottom := 59;
  Doc.VCLCanvas.Font.Size := 8;
  Doc.VCLCanvas.TextRect(Rect, 218, 45, 'Test');
  Rect.Top := 60;
  Rect.Bottom := 76;
  Doc.VCLCanvas.Font.Size := 9;
  Doc.VCLCanvas.TextRect(Rect, 218, 60, 'Test');
  Rect.Top := 77;
  Rect.Bottom := 92;
  Doc.VCLCanvas.Font.Size := 8;
  Doc.VCLCanvas.TextRect(Rect, 218, 77, 'Test');

  Doc.SaveToFile('test.pdf');

Running this gives pdf looking bit like this, in 200% zoom in pdf viewer:
Z9vtWDZ.png?1
Topmost line is the three dots drawn in font size 1, which triggers weird font for subsequent textrects. Second line is the font size 8 Test-text, which is in the weird font. Third line is font size 9 Test-text, which is drawn as expected and after this any further textrects are in the expected font, such as the fourth line size 8 Test-text.

Offline

Board footer

Powered by FluxBB