TPrintPreview units

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

TPrintPreview units

Postby rodonnell » August 21st, 2009, 9:40 pm

Hello all,

Many thanks for a great component - it's just what I need for a small project I'm working on at the moment which has to generate printed material from both a plastic card printer and an ordinary A4 laser.

One thing which I can't understand - how do you get accurately the pixels per inch (PPI) of the selected printer? For example, this -

Code: Select all
// PrintPreview is a TPrintPreview object.
PrintPreview.Printer.PrinterIndex := PrintPreview.Printer.Printers.IndexOf('Brother HL-2070N series');
ShowMessage(IntToStr(PrintPreview.Canvas.Font.PixelsPerInch));


- returns 96 PPI, whereas the real resolution of the printer is 1200 DPI. In addition, if I do this:

Code: Select all
PrintPreview.Canvas.Font.Size := 9;
LineLength := PrintPreview.Canvas.TextWidth('a');
ShowMessage(IntToStr(LineLength));


- I get 83, which at 96 PPI would make a 9-point letter 'a' nearly an inch wide!! :shock: So obviously I'm not understanding the relationship between pixels and DPI, or else I'm doing something plain wrong, and I'd appreciate any help you can give me.

The reason for this is that I'm trying to write a procedure which will break wrap long lines of text correctly on the page, so I need to be able to calculate lengths accurately.

Many thanks,

Ray O'Donnell.
rodonnell
Member
Member
 
Posts: 2
Joined: August 21st, 2009, 9:11 pm

Re: TPrintPreview units

Postby Kambiz » August 21st, 2009, 10:10 pm

The component generate pages independent of the printer resolution. Then, during print it maps page resolution to printer resolution.

However, to have a better result, you should avoid using mmPixel measurement unit.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview units

Postby Kambiz » August 21st, 2009, 10:12 pm

By the way, result of Canvas.TextWidth is meaningful when it is called between BeginDoc/EndDoc block, and its value depends on the selected measurement unit.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: TPrintPreview units

Postby rodonnell » August 23rd, 2009, 5:46 pm

Thanks for the replies, Kambiz - that pointed my brain in the right direction! My mistake was calling Canvas.TextWidth() outside BeginDoc/EndDoc. Once I put it inside this block, TextWidth() returned its answer in terms of the current units (mmLoMetric in my case), which was what I needed.

A further question.... If TPrintPreview.DirectPrint is set to true, will the return value of Canvas.TextWidth() be in terms of the printer pixles (1200 DPI for my laser printer), or will it still be in the TPrintPreview.Units as above?

Thanks and regards,

Ray O'Donnell.
rodonnell
Member
Member
 
Posts: 2
Joined: August 21st, 2009, 9:11 pm

Re: TPrintPreview units

Postby Kambiz » August 24th, 2009, 3:29 am

By setting DirectPrint to True, Canvas will be the printer canvas but the units still are in the PrintPreview units. Of course in this case the resolution of printer is considered.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron