|
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); |
_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
