TextOut on printer canvas creates black rectangles
Hello,
I use TPrinter.Canvas.TextOut to write text on a printer. Each of the
text strings should appear in a certain color (usually black) being
"embedded" in a rectangle of a different color (e.g. yellow or white),
something similar to the appearance of a TStringGrid.
The output works fine on some laser printers I tried, but goes wrong
completely when using a color printer like HP deskjet 1220C: Instead of
the text, a filled black rectangle of the size of the textrect is
printed in all cases where the background color is different from white.
The problem already appered on D3, now I use D4up3. Did not yet try on
D6...
I read in the WIN API under "TextOut" that there may be a problem with
getting the path from a text output when deriving a region from it,
adding the "textrect" path to the outline of the text. This could be
avoided by changing the device context background to TRANSPARENT with
SetBkMode. I wonder if there is a better solution not diving into the
API...
I tried setting the Brush.Style to bsClear before TextOut and it worked
somehow then, but is there a better solution which can be applied for
all types of printers? Why doesn't my laser printer (Lexmark Optra P+)
(mis)use the brush style property when writing text?
Here's some source clip:
{ Set colors for drawing }
Printer.Canvas.Brush.Color := clLtGray;
Printer.Canvas.Font .Color := clBlack;
{ Paint the 'background rectangle' of the text field }
CRect.Top := ...;
CRect.Left := ...;
...
Printer.Canvas.Pen .Color := clBlack;
Printer.Canvas.Brush.Style := bsSolid;
Printer.Canvas.Rectangle(CRect.Left,CRect.Top,CRect.Right,CRect.Bottom);
{ Output cell text }
Printer.Canvas.Brush.Style := bsClear; // needs to be done on my
HP deskjet
Printer.Canvas.TextOut(CRect.Left+OffsetX, CRect.Top+OffsetY,
SomeText);
end;
Thanks for help (I already visited efg's computer lab...)!