Artículo original: Watermark your reports with GdiPlusX
http://vfpimaging.blogspot.com/2007/07/watermark-your-reports-with-gdiplusx.html
Autor: Cesar Ch.
Traducido por: Luis María Guayán
Aquí está un ReportListener que genera imágenes como marcas de agua en informes.
Muy simple para configurar, solo establezca algunas propiedades, como la imagen del logo, el ancho, la altura y el porcentaje de transparencia.
_SCREEN.AddProperty("System", NEWOBJECT("xfcSystem", LOCFILE("system.vcx","vcx")))
LOCAL loListener as ReportListener
loListener = CREATEOBJECT("WatermarkListener")
loListener.LISTENERTYPE = 1
loListener.WaterMarkImage = ADDBS(HOME()) + "Graphics\Gifs\morphfox.gif"
loListener.WaterMarkType = 2 && 1 = Color ; 2 = Escala de grises
loListener.WaterMarkTransparency = 0.25 && 0 = Transparente ; 1 = Opaco
loListener.WaterMarkWidthRatio = 0.75 && 0 - 1
loListener.WaterMarkHeightRatio = 0.75 && 0 - 1
* Ejecute el informe usando el nuevo motor de informes (la salida objeto-asistida)
REPORT FORM (ADDBS(HOME()) + "samples/solution/europa/employeesmd.frx") OBJECT loListener
RETURN
Abajo están algunos ejemplos generados con la clase WaterMarkListener. (El código fuente está al final de este artículo)
IMPORTANTE
Requiere VFP9 y GdiPlusX para funcionar.
¡Por favor asegúrese que tiene la última versión!
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
1.
WaterMarkType = 1 && 1 = Color ; 2 = Escala de grises WaterMarkTransparency = 1 && 0 = Transparent ; 1 = Opaco WaterMarkWidthRatio = 0.90 && 0 - 1 WaterMarkHeightRatio = 0.90 && 0 - 1
2.
WaterMarkType = 1 && 1 = Color ; 2 = Escala de grises WaterMarkTransparency = 0.25 && 0 = Transparent ; 1 = Opaco WaterMarkWidthRatio = 0.50 && 0 - 1 WaterMarkHeightRatio = 0.50 && 0 - 1
3.
WaterMarkType = 2 && 1 = Color ; 2 = Escala de grises WaterMarkTransparency = 0.10 && 0 = Transparent ; 1 = Opaco WaterMarkWidthRatio = 1 && 0 - 1 WaterMarkHeightRatio = 1 && 0 - 1
4.
WaterMarkType = 2 && 1 = Color ; 2 = Escala de grises WaterMarkTransparency = 0.25 && 0 = Transparent ; 1 = Opaco WaterMarkWidthRatio = 0.75 && 0 - 1 WaterMarkHeightRatio = 0.75 && 0 - 1
_SCREEN.AddProperty("System", NEWOBJECT("xfcSystem", LOCFILE("system.vcx","vcx")))
LOCAL loListener as ReportListener
loListener = CREATEOBJECT("WatermarkListener")
loListener.LISTENERTYPE = 1
loListener.WaterMarkImage = ADDBS(HOME()) + "Graphics\Gifs\morphfox.gif"
loListener.WaterMarkType = 2 && 1 = Color ; 2 = Escala de grises
loListener.WaterMarkTransparency = 0.25 && 0 = Transparent ; 1 = Opaco
loListener.WaterMarkWidthRatio = 0.75 && 0 - 1
loListener.WaterMarkHeightRatio = 0.75 && 0 - 1
* Ejecute el informe usando el nuevo motor de informes (la salida objeto-asistida)
REPORT FORM (ADDBS(HOME()) + "samples/solution/europa/employeesmd.frx") OBJECT loListener
RETURN
DEFINE CLASS WatermarkListener AS _ReportListener OF ADDBS(HOME()) + "FFC\" + "_ReportListener.VCX"
NewPage = .T.
oGDIGraphics = NULL
WaterMarkImage = ""
WaterMarkType = 1 && 1 = Color ; 2 = Escala de grises
WaterMarkTransparency = 0.50 && 0 = Transparente ; 1 = Opaco
WaterMarkWidthRatio = 0.50
WaterMarkHeightRatio = 0.50
FUNCTION BEFOREREPORT
DODEFAULT()
This.oGDIGraphics = _SCREEN.SYSTEM.Drawing.Graphics.New() && CREATEOBJECT('GPGraphics')
ENDFUNC
FUNCTION BEFOREBAND(nBandObjCode, nFRXRecNo)
#DEFINE FRX_OBJCOD_PAGEHEADER 1
IF nBandObjCode==FRX_OBJCOD_PAGEHEADER
This.NewPage = .T.
IF NOT This.IsSuccessor
This.SharedGDIPlusGraphics = This.GDIPLUSGRAPHICS
ENDIF
This.oGDIGraphics.Handle = This.SharedGDIPlusGraphics
ENDIF
DODEFAULT(nBandObjCode, nFRXRecNo)
ENDFUNC
PROCEDURE RENDER(nFRXRecNo,;
nLeft,nTop,nWidth,nHeight,;
nObjectContinuationType, ;
cContentsToBeRendered, GDIPlusImage)
WITH _SCREEN.SYSTEM.Drawing
IF This.NewPage
LOCAL lnX, lnY, lnWidth, lnHeight
lnX = (1 - This.WaterMarkWidthRatio) / 2
lnY = (1 - This.WaterMarkHeightRatio) / 2
lnWidth = This.WaterMarkWidthRatio
lnHeight = This.WaterMarkHeightRatio
* Creo un Rectangulo de tamaño 60% de la página del informe
LOCAL loRect AS xfcRectangle
loRect = .Rectangle.New(lnX * This.sharedPageWidth, ;
lnY * This.sharedPageHeight, ;
This.sharedPageWidth * lnWidth, ;
This.sharedPageHeight * lnHeight)
* Cargo el archivo de imagen a GDI+
LOCAL loBmp as xfcBitmap
loBmp = .Bitmap.New(This.WaterMarkImage)
LOCAL loClrMatrix AS xfcColorMatrix
IF This.WaterMarkType = 2 && 1 = Color ; 2 = Escala de grises
loClrMatrix = .Imaging.ColorMatrix.New( ;
.33, .33, .33, 0 , 0, ;
.33, .33, .33, 0 , 0, ;
.33, .33, .33, 0 , 0, ;
0, 0, 0, This.WaterMarkTransparency, 0, ;
0, 0, 0, 0, 0)
ELSE
loClrMatrix = .Imaging.ColorMatrix.New()
loClrMatrix.Matrix33 = This.WaterMarkTransparency
ENDIF
LOCAL loAttr AS xfcImageAttributes
loAttr = .Imaging.ImageAttributes.New()
loAttr.SetColorMatrix(loClrMatrix)
This.oGdiGraphics.DrawImage(loBmp, loRect, loBmp.GetBounds(), 2, loAttr)
This.NewPage = .F.
ENDIF
ENDWITH
DODEFAULT(nFRXRecNo,;
nLeft,nTop,nWidth,nHeight,;
nObjectContinuationType, ;
cContentsToBeRendered, GDIPlusImage)
ENDPROC
ENDDEFINE
No hay comentarios. :
Publicar un comentario
Los comentarios son moderados, por lo que pueden demorar varias horas para su publicación.