Recent

Author Topic: Change DPI of lcl-pdf Unit  (Read 414 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 516
  • Weitental is a very beautiful garbage depot.
Change DPI of lcl-pdf Unit
« on: August 03, 2022, 02:48:28 pm »
Hello,

the Unit "fpPDF" (C:\lazarus\fpc\3.2.0\source\packages\fcl-pdf\src) has a constant "cDefaultDPI" set to 72.
but when using Screen.PixelsperInch i get 96.

When Using functions like this:
Code: Pascal  [Select][+][-]
  1. function PDFTomm(APixels: TPDFFloat): Single;
  2. begin
  3.   Result := (APixels * cInchToMM) / cDefaultDPI;
  4. end;
  5.  
i do not get the correct value for this:
Code: Pascal  [Select][+][-]
  1.    PDFTomm(lFC.TextWidth(Tx, fFontSize))
  2.  
if i use the correct DPI Value i get the correct String length, but then my other Values do not match this value.
can i somehow change it to this:
Code: Pascal  [Select][+][-]
  1. function PDFTomm(APixels: TPDFFloat): Single;
  2. begin
  3.   Result := (APixels * cInchToMM) / Screen.PixelsPerInch;
  4. end;
  5.  


Example:
Code:
Code: Pascal  [Select][+][-]
  1.    Pos1.Y:= Pos1.Y - fDSpace;
  2.    Tx:= 'TESTING';
  3.    P.WriteText(Pos1.X, Pos1.Y, Tx);
  4.    //DPI 72
  5.    Pos1.Y:= Pos1.Y - fDSpace;
  6.    Tx:= 'TESTING';
  7.    P.WriteText(Pos1.X +PDFTomm(lFC.TextWidth(Tx, fFontSize)), Pos1.Y, Tx);
  8.    //DPI 96
  9.    Pos1.Y:= Pos1.Y - fDSpace;
  10.    Tx:= 'TESTING';
  11.    P.WriteText(Pos1.X +(lFC.TextWidth(Tx, fFontSize)) * (25.4 / Screen.PixelsPerInch), Pos1.Y, Tx);
  12.  

attached is what i draw whit this Code. I Added the same text 2 more times but the starting x Value adds up with the calculated Length of the String. i get the correct length with 96 dpi (Screen.PixelperInch)  but not the righ length with PDFToMM (Procedure from Unit "fpGUI", with constant 72 DPI).

Edit: noticed that my pdf "Paper" is smaller than others, but i was using:
Code: Pascal  [Select][+][-]
  1.    P.PaperType:= ptA4;
  2.  
« Last Edit: August 03, 2022, 03:46:38 pm by Weitentaaal »

 

TinyPortal © 2005-2018