Board index » delphi » Screen coords to printer coords and vice versa

Screen coords to printer coords and vice versa

Can anybody explain how i compute the x- and y-coordinates in the following
code fragments so i get reasonably identical output?

{ Sending output to a printer }
  Printer.BeginDoc;
  Printer.Canvas.Font.Name := <some font name>;
  Printer.Canvas.Font.Size := <some font size>;
  Printer.Canvas.TextOut(x, y, 'A little text of mine');        
  Printer.EndDoc;

{ Sending output to a PaintBox }
  PaintBox1.Canvas.Font.Name := <some font name>;
  PaintBox1.Canvas.Font.Size := <some font size>;
  PaintBox1.Canvas.TextOut(x, y, 'A little text of mine');

I've experimented a lot and have discovered that multiplying the PaintBox
coordinates by 72 gives me approximately what i want for the printed output.
Is this a coincidence? Is there a way to compute the actual number? Is 72 just
another magic number?

Canvas.Font.Height, and Canvas.Font.Size, and Canvas.Font.PixelsPerInch are
identical for both the Printer and PaintBox objects.

Thanx for your time and patience
- Soren

 

Re:Screen coords to printer coords and vice versa


st>I've experimented a lot and have discovered that multiplying the PaintBox
st>coordinates by 72 gives me approximately what i want for the printed outpu
st>Is this a coincidence? Is there a way to compute the actual number? Is 72
st>another magic number?

Drop the experimenting and get a good book. Petzolds Programming Windows has
lots about this subject (it is geared toward C, but most of it is really just
API calls anyhow).

A quick answer might be: Place your device context (Canvas.Handle) into the
same mapping mode (say, MM_HIENGLISH for accuracy) on both screen and printer,
use the same coordinates, and things should fall into place on most output
devices.

Note that in order to get things to shape up on the monitor, it is often
necessary to query a *printer* DC for size/pos info, as the printer with its
higher resolution will be the more accurate device.

--
Mr.Hillbilly (eiv...@infolink.no) http://www.sn.no/~eivind
 tHyperSoft HyperReader 1.0t

Other Threads