Barcode Generation (FWER_BarCode)

Fonte: source/classes/fwbarcod.prg, source/function/fwzebra.prg

FWER_BarCode is FiveWin's built-in barcode rendering engine. It supports 17 barcode symbologies through a native GDI engine, with optional fallback to the hbzebra library for 2D codes (QR, DataMatrix, PDF417). Barcodes can be rendered on windows, dialogs, printers, and PDF output.

Symbology Reference

nBCodeTypeSymbologyDescription
1Code 39Standard Code 39 (3-of-9) alphanumeric
2Code 39 + checkCode 39 with mandatory check digit
3Code 128 autoCode 128 with automatic mode selection (A/B/C)
4Code 128 ACode 128 mode A (uppercase, control chars)
5Code 128 BCode 128 mode B (full ASCII)
6Code 128 CCode 128 mode C (numeric pairs, highest density)
7EAN-8EAN-8 (8-digit product code)
8EAN-13EAN-13 (13-digit product code, most common retail)
9UPC-AUPC-A (12-digit US product code)
10CodabarCodabar (libraries, blood banks, FedEx)
11Supplement 55-digit supplement for EAN/UPC
12Industrial 2 of 5Industrial 2 of 5 numeric
13Industrial 2 of 5 + checkIndustrial 2 of 5 with check digit
14Interleaved 2 of 5Interleaved 2 of 5 (high-density numeric)
15Interleaved 2 of 5 + checkInterleaved 2 of 5 with check digit
16Matrix 2 of 5Matrix 2 of 5 numeric
17Matrix 2 of 5 + checkMatrix 2 of 5 with check digit

DATA Members

DATADefaultDescription
hDC--Device context handle (window, dialog, printer)
cText""Barcode text to encode
nTop, nLeft--Position coordinates
nWidth, nHeight200, 20Barcode dimensions
nColText0 (black)Bar (pin) color
nColPaneRGB(255,255,255)Background color
lHorizontal.T.Horizontal (.T.) or vertical (.F.) orientation
lTransparent.F.Transparent background
nPinWidth--Individual bar (pin) width in pixels

Methods

MethodDescription
New( hDC, cText, nTop, nLeft, nW, nH, nType, nClrT, nClrP, lHorz, lTransp, nPinW, nFlags, lPrinter )Create a barcode object. Accepts numeric type (1-17) or string alias ("EAN13", "128", "39", etc.)
ShowBarcode()Render the barcode to the device context using the configured parameters
CreateBarcode( cCode )Generate the bar pattern string for a given code
CheckDigit()Compute and append the appropriate check digit for the current symbology

Free Funções

FW_SayBarCode()

Direct barcode rendering without creating an object instance:

FW_SayBarCode( oWnd, cText, aRect, cType, nClrT, nClrB, lVert, lTransp )

Parameters: oWnd (window/dialog/printer), cText (data to encode), aRect (array { nTop, nLeft, nBottom, nRight }), cType (symbology string), nClrT/nClrB (fore/back colors), lVert (vertical orientation), lTransp (transparent background).

FW_BarCodeBmp()

Generates a standalone bitmap handle of the barcode for use in reports or image controls.

Example: EAN-13 on Printer

#include "FiveWin.ch"

FUNCTION PrintBarcode()
   LOCAL oPrn, nRow := 2.0  // cm from top

   PRINT oPrn NAME "Barcode Test"
   PAGE
      oPrn:Say( nRow, 1.0, "Product Barcode:" )
      nRow += 0.8

      // Method 1: Using FWER_BarCode directly
      FWER_BarCode():New( oPrn:hDC, "5901234567890", ;
                          oPrn:CmToPix( nRow ),        // nTop
                          oPrn:CmToPix( 1.0 ),         // nLeft
                          oPrn:CmToPix( 5.0 ),         // nWidth
                          oPrn:CmToPix( 2.5 ),         // nHeight
                          8, 0, 16777215, .T., .F. ):ShowBarcode()

      // Method 2: Using FW_SayBarCode convenience function
      nRow += 3.0
      FW_SayBarCode( oPrn, "5901234567890", ;
                     { oPrn:CmToPix( nRow ), oPrn:CmToPix( 1.0 ), ;
                       oPrn:CmToPix( nRow + 2.5 ), oPrn:CmToPix( 6.0 ) }, ;
                     "EAN13", 0, 16777215 )
   ENDPAGE
   ENDPRINT
RETURN NIL

Notes

Veja Também