#10 Can't draw Barcodes to a MetaFile

Barcodes (5)

Exported from Bugzilla, issue 3698.

--- Comment added on 8/16/2002 11:38:04 AM ---
Customer wants to draw a barcode onto a metafile, the barcode components make
use of APIs internally that are incompatible with drawing to a metafile.

Make metafale the assumption?

Customer Reports:

-------------------->8 cut here 8<--------------------
Subject: Painting Barcodes to a Metafile DC
Date: Tue, 13 Aug 2002 12:40:41 -0400

I'm having problems painting Barcodes to a MetaFile dc. I have Systools3 and
D5 and I'm calling the PaintToDC method of TStBarCode. Has anyone had succes
doing this or anything similar. I have a similar routine that draws text
elements and lines directly to a TImage using the dc and it works fine. This
routine that I'm having the problem with is creating a metafile to be
printed. All other GDI calls work fine and print correctly.

-------------------->8 cut here 8<--------------------
Subject: Regarding barcodes in a metafile dc - if anyone cares
Date: Fri, 16 Aug 2002 12:43:43 -0400

I was finally able to get a barcode in a memory metafile but not exactly
like the documentation says. I resorted to creating a bitmap, painting the
barcode to the bitmap and then finally bitblting the bitmap to the metafile.
A few points to consider:

1. The barcode control uses calls to DrawText to render the code if ShowCode
is true. DrawText is not a supported WMF or EMF function. It's a user32
function, not a gdi32 function. The GDI attempts to convert DrawText to
combinations of calls to GetTextAlign, SetTextAlign and TextOut (and hence
GetTextAlign, SetTextAlign and TextOut metafile records) but isnt always
successful when doing this with certain DrawText uFormat parameters. The
barcode controls should probably be changed to just call GetTextAlign,
SetTextAlign and TextOut directly which are straight GDI functions and fully
supported in both types of metafiles.

2. The barcode control doesnt not seem to observe any mapping mode you might
have setup for a metafile dc. Once I set ShowCode to false, I could get the
barcode in the metafile but not the size I wanted. The call PixelsPerInchX
:= GetDeviceCaps(Canvas.Handle, LOGPIXELSX); in TStBarCode.DrawBarCode seems
to return a value based on the device units of the metafile reference dc,
not the Window Extents setup in the mapping mode (logical units). This
causes the barcode spacing to be miscalculated and the barcode looks wrong.
I'm not sure whose problem this is, after all, the control is asking for
logical units, not device units. I'm not sure why the dots per inch value is
being returned back as device units. Just my observation.

-------------------->8 cut here 8<--------------------