SET PROCEDURE TO gdiplus ADDITIVE
LOCAL oListener As TListener
oListener = CREATEOBJECT("TListener")
DO GenerateData
* create your own report as shown on the picture above
* Picture control is not required
* just provide some empty space at the detail`s left margin
REPORT FORM test OBJECT oListener NOCONSOLE
* end of main
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")
DEFINE CLASS TListener As ReportListener
#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)
#DEFINE BARCODE_FONT "barcod39"
ListenerType=1 && renders all pages
InDetails=.F.
gdiplus=NULL
font1=NULL
font2=NULL
font3=NULL
matrix=NULL
PROCEDURE Init
ReportListener::Init()
THIS.gdiplus = CREATEOBJECT("gdiplusinit")
THIS.CreateFonts
THIS.CreateMatrix
PROTECTED 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)
THIS.font1 = CREATEOBJECT("gdifont", oFamily,;
14, 1, BARCODE_FORECOLOR)
ELSE
THIS.font1 = CREATEOBJECT("gdifont", oFamily,;
28, 0, BARCODE_FORECOLOR)
ENDIF
oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
THIS.font2 = CREATEOBJECT("gdifont", oFamily,;
8, 0, IMAGE_FORECOLOR)
oFamily = oFontcollection.GetFontFamily(IMAGE_FONT)
THIS.font3 = CREATEOBJECT("gdifont", oFamily,;
7, 0, IMAGE_FORECOLOR)
PROTECTED PROCEDURE CreateMatrix
THIS.matrix = CREATEOBJECT("gdimatrix")
THIS.matrix.Rotate(270)
PROCEDURE BeforeBand
LPARAMETERS nBandObjCode, nFRXRecNo
DODEFAULT(nBandObjCode, nFRXRecNo)
IF nBandObjCode = 4
THIS.InDetails=.T.
ENDIF
PROCEDURE Render(nFRXRecNo, nLeft,nTop,nWidth,nHeight,;
nObjectContinuationType, cContentsToBeRendered, GDIPlusImage)
IF THIS.InDetails
THIS.PrintBarcode(nLeft,nTop)
THIS.InDetails = .F.
ENDIF
DODEFAULT(nFRXRecNo, nLeft,nTop,nWidth,nHeight,;
nObjectContinuationType, ;
cContentsToBeRendered, GDIPlusImage)
PROTECTED PROCEDURE PrintBarcode(nLeft, nTop)
LOCAL cBarcode, cMailtype
cBarcode = ALLTRIM(cs.zip) + "-" + cs.state
cMailtype = ALLTRIM(cs.mailtype)
LOCAL oImage As gdibitmap, graphics As graphics
oImage = CREATEOBJECT("gdibitmap", IMAGE_WIDTH, IMAGE_HEIGHT)
WITH oImage
.graphics.FillRectangle(IMAGE_BACKCOLOR,;
0, 0, .imgwidth, .imgheight)
.graphics.DrawText(m.cBarcode,;
THIS.font1, 2, 5, .imgwidth, .imgheight)
.graphics.DrawText(ALLTRIM(m.cMailtype),;
THIS.font2, .imgwidth-70, 3, 68, .imgheight)
.graphics.DrawText(m.cBarcode,;
THIS.font2, 10, .imgheight-16, .imgwidth, 14)
.graphics.DrawText(MDY(DATE()),;
THIS.font3, .imgwidth-80, .imgheight-14, 78, 13)
ENDWITH
LOCAL oImage1 As gdibitmap
oImage1 = CREATEOBJECT("gdibitmap", IMAGE_HEIGHT, IMAGE_WIDTH)
WITH oImage1
.graphics.FillRectangle(IMAGE_BACKCOLOR,;
0, 0, .imgwidth, .imgheight)
.graphics.SetTransform(THIS.matrix)
.graphics.drawimage(oImage, -oImage.imgwidth, 0)
nResult = GdipDrawImageRectI(THIS.GDIPlusGraphics,;
.himage, 500, nTop-300, .imgwidth*10, .imgheight*10)
ENDWITH
ENDDEFINE
|