#1 2012-07-01 16:16:00

Gemsys
Member
Registered: 2011-06-12
Posts: 6

Size of Text

I am confused, or doing somthing wrong, or not understanding somthing.

I use the following code in the start of my Printer program

   pdfDoc := TPdfDocumentGDI.Create;
   pdfDoc.Info.Author:='';
   pdfDoc.Info.Creator:='';
   pdfDoc.DefaultPaperSize:=psA4;
   pdfDoc.CompressionMethod:=cmFlateDecode;
   pdfDoc.ScreenLogPixels  := 600;                      // I assume this is in pixels per inch

   pdfPage := pdfDoc.AddPage;
   pdfDoc.VCLCanvas.Pen.Width:=1;
   pdfDoc.VCLCanvas.font.name := 'Arial';
   pdfDoc.VCLCanvas.font.height := round(10 * (pdfDoc.ScreenLogPixels / 72)) ;  //10pnt

   chwidth :=  pdfDoc.VCLCanvas.textwidth('n');      //= 0.676 pixels
   chheight := pdfDoc.VCLCanvas.textheight('n');     //= 1.27e-311 pixels

My printer program relies heavily on sizeing text for things like wordwrap, grid layout, page positioning.  Can anybody tell me how I can obtain the true width of some text in pixels (or points or em's or anything!)

Thanks in advance
Geoff

Offline

#2 2012-07-02 05:34:33

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

Re: Size of Text

I suspect that in order to set a font to 10 points, you'd need to call either Font.Size := 10
Font.Height is the size in pixels.
Just as with any other VCL font.
See http://docs.embarcadero.com/products/ra … _Size.html

Offline

#3 2012-07-02 21:22:08

Gemsys
Member
Registered: 2011-06-12
Posts: 6

Re: Size of Text

I have actually tried both ways thus:

        pdfDoc.VCLCanvas.font.size := 10;

since the VCL font Size property is in pnts. I've also tried

        pdfDoc.VCLCanvas.font.size :=  round(10 * (pdfDoc.ScreenLogPixels / 72))

incase the there is an error and the size were loading in pixels.  I've also tried assigning a standart TFont, but however I set the font size the responce to

       chwidth :=  pdfDoc.VCLCanvas.textwidth('n');   //= 2.64e-308

is always the same.  (Yesterday the value was 0.67, but having reloaded Delphi the result today is always 2.64e-308. and this applies for all letters and letter strings.  eg 'n' 'm' 'nn' 'i' 'abcedfghijklmnopqrstuvwxyz') 

Textwidth is also a property of pdfDoc, but trying to access this results in an AV though I can't see why.  It should just return a value of 0.  (ie the only line is          Result := 0    ).

Textwidth() is used extensively in SynPDF (as might be expected) so I guess it works, thus my only conclusion is that I am not setting somthing up correctly. 

Can anybody tell me what I am doing wrong, or give me another way of accessing the text width please.

Thanks in advance,
Geoff

Offline

#4 2012-07-03 13:38:33

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

Re: Size of Text

Did you try to set UseSetTextJustification = false as stated by http://synopse.info/forum/viewtopic.php?pid=1839#p1839 ?

See also http://synopse.info/forum/viewtopic.php?pid=1909#p1909

Offline

#5 2012-07-03 23:07:44

Gemsys
Member
Registered: 2011-06-12
Posts: 6

Re: Size of Text

I had read thriough the second reference but not the first.  I will try that tomorrow.  THANKS

Geoff

Offline

Board footer

Powered by FluxBB