[DUG] Issue with TPrinter.
Kyley Harris
kyley at harrissoftware.com
Mon May 8 20:33:13 NZST 2006
Just thought I would share this for anyone else who uses TPrinter, and
Richedits too.
I have a routine that Talks to a printer driver to return text widths
using the printer canvas to get higher accuracy on font widths than
screen dpi.
This routine is to retrieve text height and width in twips (1440 per
inch) using print resolutions of typically 300 or 600 dpi. What I found
was that
If the dummy line was not inserted and called before assigning a font to
the printer canvas then the font information got scrambled. I traced the
code
And found that the DC handle, and the TFont handle are not initialized
correctly if you don't call textwidth, before changing the font.
Basically. The font of the printer ends up having a Screen PixelsPerInch
Value rather than 300, or 600 etc if this is not done. Only happens on
some printers :D
RichEdit canvas's can also suffer from this hassle.
if Printer.PrinterIndex <> PrinterIndex then
Printer.PrinterIndex := PrinterIndex;
if not Loaded then
begin
{ force the DC in the canvas to initialize properly. If this is
not the very first call to the printer canvas before assigning a font,
Then the font information gets corrupted }
Dummy := Printer.Canvas.TextWidth('MMMMMMMMMM');
XDPI := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
YDPI := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
Loaded := true;
end ;
printer.Canvas.Font := AFont;
asize.cx := MulDiv(Printer.Canvas.TextWidth(AText) , 1440 , XDPI);
asize.cy := MulDiv(Printer.Canvas.TextHeight(AText), 1440, YDPI);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20060508/2e00f10b/attachment.html
More information about the Delphi
mailing list