#DEFINE IMAGE_WIDTH 180
#DEFINE IMAGE_HEIGHT 60
#DEFINE IMAGE_TARGETFILE SYS(2023)+"\barcode.bmp"
#DEFINE IMAGE_BACKCOLOR ARGB(255,255,255,255)
#DEFINE IMAGE_FORECOLOR ARGB(64,64,64,255)
#DEFINE IMAGE_FONT "Arial"
#DEFINE BARCODE_FORECOLOR ARGB(0,0,0,255)
* replace with valid barcode font name
#DEFINE BARCODE_FONT "barcod39"
* an instance of gdiplusinit should be created before
* and released after using any of gdi+ objects
SET PROCEDURE TO gdiplus ADDITIVE
PRIVATE gdiplus As gdiplusinit, img As gdibitmap
gdiplus = CREATEOBJECT("gdiplusinit")
PRIVATE oFont1 As gdifont, oFont2 As gdifont, oFont3 As gdifont,;
oMatrix as gdimatrix
STORE 0 TO oFont1, oFont2, oFont3, oMatrix
DO CreateFonts
DO CreateMatrix
DO GenerateData
DO BrowseResults
* end of main
PROCEDURE GenBarcode(cBarcode, cMailtype)
LOCAL oImage As gdibitmap, oImage1 As gdibitmap
* create blank image
oImage = CREATEOBJECT("gdibitmap",;
IMAGE_WIDTH, IMAGE_HEIGHT)
* printing text including barcode on the first image
WITH oImage
* setting the background, otherwise it is black
.graphics.FillRectangle(IMAGE_BACKCOLOR,;
0, 0, .imgwidth, .imgheight)
.graphics.DrawText(m.cBarcode,;
oFont1, 2, 5, .imgwidth, .imgheight)
.graphics.DrawText(ALLTRIM(m.cMailtype),;
oFont2, .imgwidth-70, 3, 68, .imgheight)
.graphics.DrawText(m.cBarcode,;
oFont2, 10, .imgheight-16, .imgwidth, 14)
.graphics.DrawText(MDY(DATE()),;
oFont3, .imgwidth-80, .imgheight-14, 78, 13)
ENDWITH
* the first image is saved to bitmap file
* then imported to general field
oImage.savetofile(IMAGE_TARGETFILE)
SELECT cs
APPEND GENERAL barcode FROM IMAGE_TARGETFILE
* create another blank image
* note that image width and height are switched
oImage1 = CREATEOBJECT("gdibitmap", IMAGE_HEIGHT, IMAGE_WIDTH)
WITH oImage1
* setting the background, otherwise it is black
.graphics.FillRectangle(IMAGE_BACKCOLOR,;
0, 0, .imgwidth, .imgheight)
* rotation matrix applied
.graphics.SetTransform(oMatrix)
* the second image is used as a canvas
* to draw the first image on it
* note that X coordinate is not zero
.graphics.drawimage(oImage, -.imgheight, 0)
ENDWITH
oImage1.savetofile(IMAGE_TARGETFILE)
SELECT cs
APPEND GENERAL barcode1 FROM IMAGE_TARGETFILE
PROCEDURE CreateMatrix
oMatrix = CREATEOBJECT("gdimatrix")
oMatrix.Rotate(270)
PROCEDURE CreateFonts
LOCAL oFontcollection As gdifontcollection
oFontcollection = CREATEOBJECT("gdifontcollection")
LOCAL oFamily as gdifontfamily
oFamily = oFontcollection.GetFontFamily(BARCODE_FONT)
IF EMPTY(oFamily.familyname)
* barcode font not found, default font used
oFamily = oFontcollection.GetFontFamily(_screen.FontName)
oFont1 = CREATEOBJECT("gdifont", oFamily,;
14, 1, BARCODE_FORECOLOR)
= MESSAGEBOX("Barcode font [" + BARCODE_FONT +;
"] not found on the local computer. " + CHR(13) +;
"The " + _screen.FontName + " font is used instead. ",;
64, "Font not found")
ELSE
oFont1 = CREATEOBJECT("gdifont", oFamily,;
28, 0, BARCODE_FORECOLOR)
ENDIF
oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
oFont2 = CREATEOBJECT("gdifont", oFamily,;
8, 0, IMAGE_FORECOLOR)
oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
oFont3 = CREATEOBJECT("gdifont", oFamily,;
7, 0, IMAGE_FORECOLOR)
PROCEDURE GenerateData
CREATE CURSOR cs (firstname C(20), lastname C(30), city C(50),;
state C(2), zip C(7), mailtype C(50))
* preparing test data
* these are entirely fictional names and addresses
* any coincidence is completely unintentional
* the mailtypes do not make any sense either
INSERT INTO cs VALUES ("JOHN", "BROWN", "HOUSTON", "TX",;
"12545", "First Class Mail and Periodicals")
INSERT INTO cs VALUES ("MARK", "HARRIS", "CHICAGO", "IL",;
"01331", "Standard Mail ")
INSERT INTO cs VALUES ("MARTHA", "COLLETTE", "LONG BEACH", "NY",;
"06783", "First Class Mail and Periodicals")
INSERT INTO cs VALUES ("RICHARD", "COOK", "WASHINGTON", "DC",;
"11106", "First Class Mail and Periodicals")
INSERT INTO cs VALUES ("ALANA", "WOOLF", "NEW YORK", "NY",;
"10306", "Standard Mail ")
INSERT INTO cs VALUES ("DAVID", "KNIGHT", "TRENTON", "NJ",;
"01524", "Standard Letters")
INSERT INTO cs VALUES ("JAMES", "GARRISON", "SAN ANTONIO", "TX",;
"32906", "Standard Letters")
* adding two GENERAL fields for storing images
ALTER TABLE cs ADD COLUMN barcode G && regular
ALTER TABLE cs ADD COLUMN barcode1 G && rotated
SELECT cs
SCAN ALL
DO GenBarcode WITH;
ALLTRIM(cs.zip)+cs.state, cs.mailtype
ENDSCAN
PROCEDURE BrowseResults
DEFINE WINDOW cs FROM 1,1 TO 14,114 IN SCREEN;
SYSTEM FONT "Arial", 8 FLOAT CLOSE
DEFINE WINDOW barcode FROM 15,1 TO 25,30 IN SCREEN;
SYSTEM FLOAT CLOSE
DEFINE WINDOW barcode1 FROM 15,40 TO 35,50 IN SCREEN;
SYSTEM FLOAT CLOSE
SELECT cs
GO TOP
MODIFY GENERAL barcode WINDOW barcode NOWAIT
MODIFY GENERAL barcode1 WINDOW barcode1 NOWAIT
BROWSE FIELDS firstname:16, lastname:16,;
city:25, state:8, zip:12, mailtype:30,;
barcode, barcode1;
NORMAL WINDOW cs NOWAIT
|