|
|
-
The samples below use the Graphics.SetClip function to draw shaped borders in your pictures.
The trick here is to use the CombineMode.XOR enumeration, that forces the drawing to the external part of the shape, like in the samples below.
Playing with the source image below:
Prerequisites Visual FoxPro 9 and the GdiPlusX library from VFPX
Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently. http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
Sample 1: Ellipse shape
DO LOCFILE("System.app") WITH _Screen.System.Drawing * Get an image file LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) * Create a Gfx object that will allow us to make the transformation LOCAL loGfx as xfcGraphics loGfx = .Graphics.FromImage(loBmp) LOCAL lnWidth, lnHeight lnWidth = loBmp.Width lnHeight = loBmp.Height * Create GraphicsPath object. LOCAL loClipPath as xfcGraphicsPath loClipPath = .Drawing2D.GraphicsPath.New() * An Ellipse shape loClipPath.AddEllipse(0, 0, lnWidth, lnHeight) * Set clipping region to path. * CombineMode enumeration * http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx * CombineMode.Xor - Two clipping regions are combined by taking only the areas * enclosed by one or the other region, but not both. loGfx.SetClip(loClipPath, ; _Screen.System.Drawing.Drawing2D.CombineMode.Xor) * Fill rectangle to demonstrate clipping region. loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height) * Save the image to the disk and show loBmp.Save("Clipped.Jpg", "image/jpeg") RUN /n Explorer.Exe Clipped.Jpg ENDWITH
Sample 2: Doughnut shape
DO LOCFILE("System.app") WITH _Screen.System.Drawing * Get an image file LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) * Create a Gfx object that will allow us to make the transformation LOCAL loGfx as xfcGraphics loGfx = .Graphics.FromImage(loBmp) LOCAL lnWidth, lnHeight lnWidth = loBmp.Width lnHeight = loBmp.Height * Create GraphicsPath object. LOCAL loClipPath as xfcGraphicsPath loClipPath = .Drawing2D.GraphicsPath.New() * A Doughnut slice shape loClipPath.AddEllipse(0, 0, lnWidth, lnHeight * 2) loClipPath.AddEllipse(lnWidth / 4, lnHeight / 2, lnWidth/2, lnHeight * 4) * Set clipping region to path. * CombineMode enumeration * http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx * CombineMode.Xor - Two clipping regions are combined by taking only the areas * enclosed by one or the other region, but not both. loGfx.SetClip(loClipPath, ; _Screen.System.Drawing.Drawing2D.CombineMode.Xor) * Fill rectangle to demonstrate clipping region. loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height) * Save the image to the disk and show loBmp.Save("Clipped.Jpg", "image/jpeg") RUN /n Explorer.Exe Clipped.Jpg ENDWITH
Sample 3: Star shape
DO LOCFILE("System.app") WITH _Screen.System.Drawing * Get an image file LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) * Create a Gfx object that will allow us to make the transformation LOCAL loGfx as xfcGraphics loGfx = .Graphics.FromImage(loBmp) LOCAL lnWidth, lnHeight lnWidth = loBmp.Width lnHeight = loBmp.Height * Create GraphicsPath object. LOCAL loClipPath as xfcGraphicsPath loClipPath = .Drawing2D.GraphicsPath.New() * Source for the star drawing * http://www.java2s.com/Code/VB/2D/GraphicsPathDrawwithFillModeWinding.htm LOCAL lnRadius, lnPi, lnRadian72, n, lnEdges lnRadius = lnHeight / 2 lnPi = 3.141592 lnEdges = 5 lnRadian72 = (lnPi * 4.0 ) / lnEdges LOCAL laPoints(lnEdges) FOR n = 1 TO lnEdges laPoints(n) = .Point.New(; + lnRadius * SIN( n * lnRadian72 ) + lnRadius , ; - lnRadius * COS( n * lnRadian72 ) + lnRadius ) ENDFOR loClipPath.AddPolygon(@laPoints) * Set the Clip Mode to Winding * ClipMode enumeration *http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.fillmode.aspx loClipPath.FillMode = _Screen.System.Drawing.Drawing2D.FillMode.Winding * Set clipping region to path. * CombineMode enumeration * http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.combinemode.aspx * CombineMode.Xor - Two clipping regions are combined by taking only the areas * enclosed by one or the other region, but not both. loGfx.SetClip(loClipPath, ; _Screen.System.Drawing.Drawing2D.CombineMode.Xor) * Fill rectangle to demonstrate clipping region. loGfx.FillRectangle( .Brushes.White, 0, 0, loBmp.Width, loBmp.Height) * Save the image to the disk and show loBmp.Save("Clipped.Jpg", "image/jpeg") RUN /n Explorer.Exe Clipped.Jpg ENDWITH

Notice that the only difference between the code samples is the shape definition !
|
-
Drawing shapes with GdiPlusX is super easy, and we can very easilly transport this to solve some of our chart needs.
In this post I'm sending you a very primitive sample for creating Circular Gauge charts. Obviously I hope to apply the techniques shown here in FoxCharts. But FoxCharts is getting big, and I confess that learning from the methods in FoxCharts may not be easy for people that are not that familiar with GdiPlusX.
Please note that this is an unfinished sample. I'm posting it here to let people see that drawing is not that complicated. Just using some imagination, merging it with some geometrical thoughts, and voilá !

Download the Gauge sample, unzip and run TESTGAUGE.SCX ! I'm including the GdiPlusX sources to let everybody immediately run the samples.
Notice that you can control the colors of the background and pointer.
The pointer shape can be modified too. Play with all the spinners to modify the shape and size! And please tell me which you like most. I'll apreciate receiving some image samples with some desired gauge charts.
Below is the relevant code for the circular gauge drawing. You'll find it in the "BeforeDraw()" event of the ImageCanvas class. It extracts the information from the form controls, and it's very easy to adapt it to your needs.
LOCAL lnAngle, lnBaseW, lnBaseX, lnBaseY, lnTopW, lnHeightPercent, lnTopY LOCAL lnType, lnPointClr, lnBackClr, lnTicks lnTicks = Thisform.SpnTicks.Value lnType = Thisform.OptShape.Value lnAngle = Thisform.SpnAngle.Value lnBaseW = Thisform.SpnBottomW.Value lnTopW = Thisform.SpnTopW.Value lnBaseX = This.Width/2 -lnBaseW/2 lnBaseY = This.Height/2 lnHeightPercent = Thisform.SpnHeight.Value / 100 lnTopY = lnBaseY - (lnBaseY * lnHeightPercent) + lnTopW / 2 lnPointClr = Thisform.ShpPointerColor.BackColor lnBackClr = Thisform.ShpBackColor.BackColor LOCAL loGfx as xfcGraphics loGfx = This.oGfx
WITH _Screen.System.Drawing LOCAL loBrush as xfcSolidBrush loBrush = .SolidBrush.New(.Color.FromRGB(lnPointClr))
loGfx.Clear(.Color.FromRGB(Thisform.BackColor))
* Create a Shape for the pointer LOCAL loPath as xfcGraphicsPath loPath = .Drawing2D.GraphicsPath.New() loPath.StartFigure() loGfx.FillEllipse(.SolidBrush.New(.Color.FromRGB(lnBackClr)), ; This.Rectangle)
IF lnType = 1 loPath.AddArc(lnBaseX, This.Height/2 -lnBaseW/2, lnBaseW, lnBaseW, 0, 180) ENDIF
loPath.AddLine(lnBaseX, lnBaseY, This.Width/2 - lnTopW/2, lnTopY) IF lnType = 1 LOCAL laPoints(3) laPoints(1) = .Point.New(This.Width/2 - lnTopW/2, lnTopY) laPoints(2) = .Point.New(This.Width/2 , lnTopY - lnTopW / 2) laPoints(3) = .Point.New(This.Width/2 + lnTopW/2, lnTopY) loPath.AddCurve(@laPoints) ENDIF
loPath.AddLine( This.Width/2 + lnTopW/2, lnTopY, lnBaseX + lnBaseW, lnBaseY) loPath.CloseFigure()
* Rotate the shape pointer loGfx.TranslateTransform(This.Width/2, This.Height/2) loGfx.RotateTransform(lnAngle) loGfx.TranslateTransform(- This.Width/2, - This.Height/2)
* Draw the pointer loGfx.FillPath(loBrush, loPath)
* Restore the original Gfx rotation state loGfx.ResetTransform()
IF lnTicks > 0 FOR lnAngle = 0 TO 360 STEP 360 / lnTicks
* Rotate the Gfx loGfx.TranslateTransform(This.Width/2, This.Height/2) loGfx.RotateTransform(lnAngle) loGfx.TranslateTransform(- This.Width/2, - This.Height/2)
* Draw the ticks loGfx.DrawLine(.Pens.Black, This.Width/2, 0, This.Width/2, 10)
* Restore the original Gfx rotation state loGfx.ResetTransform() ENDFOR ENDIF
ENDWITH
Enjoy !!! Download Gauge Prototype sample with GdiPlusX
|
-
We forgot to add to GdiPlusX a specific function to allow sending Unicodes directly, similar to the function DrawString.
But as you'll see below, it's really simple to adapt the original function and provide this possibility:
In the sample below you'll see the function "DrawStringW", that is just an adapted version from the original xfcGraphics.DrawString function.
It accepts the same parameters and overloads from the original function - the sole difference is the first parameter that was introduced - the Graphics object.
Another helper function - "HexToUnicode" was introduced. It converts a string containing Hex values separated by a space into the Unicode needed by GdiPlus.dll to draw the string.
Just run the script and you'll obtain a result similar to the one below:

Prerequisites Visual FoxPro 9 and the GdiPlusX library from VFPX
Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently. http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
DO LOCFILE("System.App")
LOCAL n, x, y, lnColor LOCAL loBmp as xfcBitmap, loGfx as xfcGraphics, loFont as xfcFont LOCAL loBrush as xfcSolidBrush LOCAL laWords(9,2) * Greek laWords(1,1) = "Greek" laWords(1,2) = "03B5 03B9 03C1 03AE 03BD 03B7" * Korean laWords(2,1) = "Korean" laWords(2,2) = "D3C9 D654" * Hebrew laWords(3,1) = "Hebrew" laWords(3,2) = "05E9 05DC 05D5 05DD" * Bulgarian laWords(4,1) = "Bulgarian" laWords(4,2) = "043C 0438 0440" * Arabic laWords(5,1) = "Arabic" laWords(5,2) = "0633 0644 0627 0645" * Simplified Chinese laWords(6,1) = "Chinese" laWords(6,2) = "548C 5E73" * Thai laWords(7,1) = "Thai" laWords(7,2) = "0E04 0E27 0E32 0E21 0E2A 0E07 0E1A" * Russian laWords(8,1) = "Russian" laWords(8,2) = "043C 0438 0440" * Japanese laWords(9,1) = "Japanese" laWords(9,2) = "5E73 548C" WITH _Screen.System.Drawing loFont = .Font.New("Tahoma", 18) loBmp = .Bitmap.New(350,370) loGfx = .Graphics.FromImage(loBmp) loGfx.Clear(.Color.White) loGfx.DrawString("Gdi+X Drawing Unicodes", loFont,; .Brushes.Black, 10,5) FOR n = 1 TO 9 y = n * 35 x = 160
lnColor = RGB(RAND() * 255, RAND() * 255, RAND() * 255) * Create a SolidBrush with randomic color loBrush = .SolidBrush.New(.Color.FromRGB(lnColor))
* Draw the language name loGfx.DrawString(laWords(n,1), .Font.New("Tahoma", 10),; .Brushes.Black, 65, y + 5)
* Draw the text in Unicodes =DrawStringW(loGfx, HexToUnicode(laWords(n,2)), loFont,; loBrush, x, y) ENDFOR loBmp.Save("TestUnicodes.Png", .Imaging.ImageFormat.Png) ENDWITH
FUNCTION DrawStringW(toGfx, ; tcString, toFont AS xfcFont, toBrush AS xfcBrush, tnX, tnY ; , toFormat AS xfcStringFormat) *********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toPoint AS xfcPointF ; , toFormat AS xfcStringFormat *********** tcString, toFont AS xfcFont, toBrush AS xfcBrush, toRectangle AS xfcRectangleF ; , toFormat AS xfcStringFormat
LOCAL lqLayoutRect LOCAL lnWidth, lnHeight, loPoint AS xfcPointF, loRect AS xfcRectangleF LOCAL lhFormat STORE 0 TO lnWidth, lnHeight STORE NULL TO loPoint, loRect m.lqLayoutRect = 0h00
** Handle overload parameters DO CASE CASE VARTYPE(tnX) = "N"
CASE VARTYPE(tnX) = "O" AND INLIST(tnX.BaseName,"Point","PointF") m.loPoint = m.tnX m.toFormat = m.tnY m.loPoint.GetExtent(@tnX, @tnY)
CASE VARTYPE(tnX) = "O" AND INLIST(tnX.BaseName,"Rectangle","RectangleF") m.loRect = m.tnX m.toFormat = m.tnY m.loRect.GetExtent(@tnX, @tnY, @lnWidth, @lnHeight) ENDCASE
** Optional parameter ** The C++ classes show this parameter as NULL if not specified IF VARTYPE(m.toFormat) = "O" m.lhFormat = m.toFormat.Handle ELSE m.lhFormat = 0 ENDIF
m.lqLayoutRect = BINTOC(m.tnX,"F")+BINTOC(m.tnY,"F")+; BINTOC(m.lnWidth,"F")+BINTOC(m.lnHeight,"F")
=xfcGdipDrawString(toGfx.Handle, m.tcString+0h00, LENC(tcString)/2, ; m.toFont.Handle, @lqLayoutRect, m.lhFormat, m.toBrush.Handle) ENDFUNC
FUNCTION HexToUnicode(tcHex) LOCAL n, lcHex, lcUnicode lcUnicode = SPACE(0) FOR n = 1 TO GETWORDCOUNT(tcHex, SPACE(1)) lcHex = EVALUATE("0x" + GETWORDNUM(tcHex, n, SPACE(1))) lcUnicode = lcUnicode + BINTOC(lcHex, "4RS") ENDFOR RETURN lcUnicode ENDFUNC
|
-
This is just an update for an old post with the same title. Erik Gomez and Russel Campbell had some problems on the conversions of some specific PNG images, so I recoded this function, this time using a safer code.
NEW UPDATE:
Thanks to Bernard Bout and Craig Boyd, I've updated the code below. In fact it contained a small bug, that was not adjusting the White colors. Now it seems to be working nice. Thanks !
This runs a little bit slower than the other aproach, but in my tests, the success was 100%.
The function below converts any button image to a BMP to be used in VFP forms.
There are lots of cool and free icons available on the web, but the vast majority are in .ICO, GIF or PNG image formats, that are not very familiar and reliable to be used in VFP. For us, the best image format, for a lot of reasons, is the BMP format.
Some transformations are needed to make this BMP to show exactly how we desire, specially when converting source images in a PNG, GIF or ICO formats.
VFP shows the pure white - RGB(255,255,255) as transparent in our buttons and image objects. The code below first converts the original whites to RGB(254,254,254) that is visually the same, but does not become transparent, and eliminates the need to create a mask image (.MSK) and next, converts the background color of the original bitmap to pure white, that will show transparent in VFP forms.
For more details, please check these prior posts:
BMPs with Transparent Backgrounds
How to put one image over another in a form
IMPORTANT Requires VFP9 and GdiPlusX to run. Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently. http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
Save the program below as BUTTON2BMP.PRG, and call it this way:
Button2Bmp(GETPICT(), "c:\NewIcon.bmp")
When you compile this program in your executable, please don't forget to remove the LOCFILE() command, and just use a DO System.App instead
LPARAMETERS tcSourceFile, tcDestFile
* tcSourcefile = GETPICT()
* tcDestFile = FORCEEXT(tcSourceFile, "Bmp")
DO LOCFILE("System.App")
LOCAL loBmp AS xfcBitmap
LOCAL loGfx AS xfcGraphics
LOCAL loBorderClr AS xfcColor
LOCAL loRect AS xfcRectangle
LOCAL loAttr AS xfcImageAttributes
LOCAL loColorMap AS xfcColorMap
LOCAL loDestBmp as xfcBitmap
WITH _SCREEN.SYSTEM.Drawing
loColorMap = .Imaging.ColorMap.New()
loAttr = .Imaging.ImageAttributes.New()
loBmp = .Bitmap.FromFile(tcSourceFile)
loGfx = .Graphics.FromImage(loBmp)
loDestBmp = .Bitmap.New(loBmp.Width, loBmp.Height, .Imaging.PixelFormat.Format24bppRGB)
loDestGfx = .Graphics.FromImage(loDestBmp)
* Clear the new bitmap
loDestGfx.Clear(.Color.White)
* By Craig Boyd - For enhancing the smoothless and quality
loDestGfx.SmoothingMode = .Drawing2D.SmoothingMode.HighQuality
loDestGfx.InterpolationMode = .Drawing2D.InterpolationMode.HighQualityBicubic
loDestGfx.PixelOffsetMode = .Drawing2D.PixelOffsetMode.HighQuality
loRect = loBmp.GetBounds()
* Get the top left pixel color, presuming this color is the BackGround color to become transparent
* For our BMP case, this will become PURE WHITE - RGB(255,255,255)
* that becomes transparent when used in VFP objects
loBorderClr = loBmp.GetPixel(0,0)
* Convert original Whites RGB(255,255,255) to OFF WHITE - RGB(254,254,254)
* this way, the whites will remain without the need of a mask
loColorMap.OldColor = .Color.White
loColorMap.NewColor = .Color.FromARGB(255,254,254,254)
loAttr.SetRemapTable(loColorMap)
loDestGfx.DrawImage(loBmp, loRect, loRect, .GraphicsUnit.Pixel, loAttr)
* Next step, convert the borders to pure White, RGB(255,255,255) that will become transparent in buttons
loColorMap.OldColor = loBorderClr
loColorMap.NewColor = .Color.White
loAttr.SetRemapTable(loColorMap)
loDestGfx.DrawImage(loDestBmp, loRect, loRect, .GraphicsUnit.Pixel, loAttr)
loDestBmp.Save(tcDestFile, .Imaging.ImageFormat.Bmp)
ENDWITH
|
-
New features: - Vertical lines and bars in the scale background - Alpha allowed in all of the chart shapes and in scale background - Triangular and cylinder bar charts - Angles compensation for pie and doughnut charts, allowing charts with good precision when width is bigger than the height (by Bo Durban). - New sample, see: FoxCharts_New, that allows you to interactively change almost every property of the charts, creating lots of different and interesting charts. - Included an EXE sample project, for testing purposes - BackGround line of chart can be set in width, and also use some predefined dotted lines - Hiding slices from pies or doughnuts allowed - MemberData scripts for picking colors - in the properties window, double clicking any property that receives a color, will fire the colorpicker window - Colors may be passed using the RGB value, or using a VFP expression, like: "=RGB(0,0,255)" or even just like the way VFP uses for its native color properties: "0,0,255".
Lots of fixes were applied in this version - Fixed cylinder and bars positions. - Fixed font assignment - Fixed class initialization that caused erros - Now the class does not show the "X" image in the class initialization - Fixed plain gradient Pie chart bug, that sometimes did not show the chart - Fixed print command - FoxCharts resizes faster - .... and many minor other fixes
SPECIAL THANKS: To the FoxBrazilian friends: Peter Wagner, Grego, Emerson Reed, Minari, Moshe, Arcadio, Edgar, Paulo Henrique, Ninja Takehana, Walfrans, Joni and others for their extensive testing, and for providing important suggestions. And also: Bo Durban (the best) and Carlos Alloatti (always there, with great insights) These guys have been providing important help and support. THANKS VERY MUCH !
Any feedback will be very much appreciated. If you would like to contribute, find any bug or would like to have some specific features, feel free to post in the VFPX Discussions forum or send directly a message to vfpimaging@hotmail.com
Get the latest release directly from the VFPX / FoxCharts page at Codeplex:
http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=14851
Below are some pictures showing what FoxCharts can do so far:
Enjoy !
|
-
As I've shown in a previous post from last year, this is totally possible for us in VFP, using the GdiPlusX library together with ReportListeners, remember?

BUT I've been receiving some emails about the Full-Justified ReportListener I published last year.
It did not deal with the possibility of multipage reports. In fact, when a string that had to be printed in FullJustified mode had to be divided in more than one page, in the next page the whole string was redrawn.
To solve this, I needed to make some adjustments in the report listener source, more specifically in the "Render" event, in order to deal with the parameters "nObjectContinuationType" and "cContentsToBeRendered". I had totally missed them. In the first version, I was only using the "Text" property that I retrieved in the "EvaluateContents" method. The first tells us if the text could be totally drawn, or partially. The 2nd, brings the text that is to be drawn, not the whole text.
It's amazing how we can control our output with all these new enhancements from the VFP9 Reporting System. In fact, we can control almost everything !
It's a pity I couldn't explore this tool as much as I would like, the possibilities seem to be infinite.
In HELP I found all the info I needed to fix it:
- nObjectContinuationType
* Indicates the current continuation state for the rendered element. When layout elements span pages, they are rendered in multiple sections (once for each page). * Value Continuation Type * 0 Complete (no continuation). * 1 Start of layout element occurrence, will not finish on the current page. * 2 Mid-element, neither started nor finished on the current page. * 3 End of element, completed on the current page.
- cContentsToBeRendered
* Indicates the text to be rendered for Expression (Field) and Label layout elements. * If your derived class sends the text value through some additional processing, such as storage in a table, you can use the STRCONV() function, and its optional regional script parameter, to convert the string to DBCS first. For more information, see STRCONV( ) Function.
Some important tweaks and fixes were needed in the GdiPlusX library too, more specifically in the xfcGraphics.DrawStringJustified function. I added to it a new parameter, "tlJustifyLast", in order fo force the justifying in the last sentence. This is for the case of reports, when an unfinished sentence needs to be justified as well.
The source code is below, you can adapt it to your needs !
The idea is to add a "<FJ>" tag in the USER tab or in the beginning of any string from a textbox in a report, to tell the ReportListener that it will draw the text using the DRAWSTRINGJUSTIFIED method from GdiPlusX. Special thanks to Victor Espinoza, from Miami, FL, for his important feedback, suggestions and fixes.
The "FullJustifyListener" performs the following actions:
- Initializes GdiPlusX
- Creates a GDI+ Graphics object that will be used to draw in the report
- Stores in an array the required information needed to draw the string(Font, Size, Style and Color)
- Before Rendering the string, checks if the "<FJ>" tag is at the beginning of text or at the "USER" tab in the report designer - if yes, draws the string using the new method.
Here are the steps for you to bring this to your reports:
1 - Download the updated GdiPlusX library - the System.App file
VERY IMPORTANT - READ THIS !
This report listener needs the updated version of the GdiPlusX main file of the library, "System.App". As it will take some time till a new version will be released, I've uploaded this file separately, so that people can try this feature from now.
Go to this link: http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=8606
And download the file "GdiPlusX Updated System.App for FullJustified purposes"
If you prefer, this file is found in the downloadable source code from this article.
2 - Save the ReportListener:
Please Copy and Paste the code below, and save it as FJLISTENER.PRG in the samples folder of GdiPlusX
* Program : FJLISTENER.PRG * Version : 2.0 * Purpose : Provides a Report Listener that allows rendering text in * Full Justify alignment. * Authors : Cesar Ch http://weblogs.foxite.com/vfpimaging * Class based on article "Listening to a report" by Doug Hennig * New tweaked version allows drawing strings that need to be divided in more than one page
* Special thanks to Victor Espinoza * http://msdn2.microsoft.com/en-us/library/ms947682.aspx
DEFINE CLASS FullJustifyListener AS FXListener oGDIGraphics = NULL nSaveGraphicsHandle = 0 nTimes = 1 DIMENSION aRecords[1] * Before we run the report, go through the FRX and store information about any * field with our expected directive in its USER memo into the aRecords array. FUNCTION BEFOREREPORT DODEFAULT() * Check if we already have the "System" object in "_Screen" IF NOT PEMSTATUS(_Screen,"System",5) DO LOCFILE("System.App") ENDIF WITH This .oGDIGraphics = _SCREEN.SYSTEM.Drawing.Graphics.New() .SetFRXDataSession() DIMENSION .aRecords[reccount(), 13] SCAN FOR "<FJ>" $ UPPER(User) .aRecords[recno(), 13] = "FJ" ENDSCAN .ResetDataSession() ENDWITH ENDFUNC
FUNCTION BEFOREBAND(nBandObjCode, nFRXRecNo) This.SharedGDIPlusGraphics = This.GDIPLUSGRAPHICS This.oGDIGraphics.Handle = This.SharedGDIPlusGraphics DODEFAULT(nBandObjCode, nFRXRecNo) ENDFUNC PROCEDURE RENDER(tnFRXRecNo,; tnLeft,tnTop,tnWidth,tnHeight,; nObjectContinuationType, ; cContentsToBeRendered, GDIPlusImage)
LOCAL lcText, llFlag llFlag = .F. lcText = This.aRecords(tnFRXRecNo,1)
IF (VARTYPE(lcText) = "C" AND LEFT(lcText,4) = "<FJ>") OR ; (VARTYPE(This.aRecords(tnFRXRecNo,13)) = "C" AND This.aRecords(tnFRXRecNo,13) == "FJ")
IF nObjectContinuationType > 0
* nObjectContinuationType * ----------------------- * Indicates the current continuation state for the rendered element. When layout elements span pages, they are rendered in multiple sections (once for each page). * Value Continuation Type * 0 Complete (no continuation). * 1 Start of layout element occurrence, will not finish on the current page. * 2 Mid-element, neither started nor finished on the current page. * 3 End of element, completed on the current page.
* cContentsToBeRendered * --------------------- * Indicates the text to be rendered for Expression (Field) and Label layout elements. * If your derived class sends the text value through some additional processing, such as storage in a table, you can use the STRCONV() function, and its optional regional script parameter, to convert the string to DBCS first. For more information, see STRCONV( ) Function.
lcText = STRCONV(cContentsToBeRendered,6)
IF INLIST(nObjectContinuationType, 1, 2) llFlag = .T. ENDIF ENDIF IF UPPER(LEFT(lcText,4)) = "<FJ>" lcText = SUBSTR(lcText,5) && Remove the <FJ> tag from string ENDIF
WITH _SCREEN.SYSTEM.Drawing
This.oGDIGraphics.Handle = This.GDIPlusGraphics *!* Create a GDI+ Rectangle which specifies where on the *!* surface we're drawing the text. LOCAL loRectF as xfcRectangleF loRectF = .RectangleF.New(tnLeft, tnTop, tnWidth, tnHeight)
LOCAL loFont as xfcFont loFont = .Font.New(This.aRecords(tnFRXRecNo,2) ; , This.aRecords(tnFRXRecNo,4), This.aRecords(tnFRXRecNo,3) ; , .GraphicsUnit.Point)
* Retrieve colors for the background LOCAL lnRed, lnGreen, lnBlue, lnAlpha lnRed = This.aRecords[tnFRXRecno,5] lnGreen = This.aRecords[tnFRXRecno,6] lnBlue = This.aRecords[tnFRXRecno,7] lnAlpha = This.aRecords[tnFRXRecno,8] LOCAL loBackBrush as xfcSolidBrush loBackBrush = .SolidBrush.New(; .Color.FromArgb(lnAlpha,lnRed, lnGreen, lnBlue))
This.oGdiGraphics.FillRectangle(loBackBrush, tnLeft, tnTop, tnWidth, tnHeight)
* Retieve colors for the Text lnRed = This.aRecords[tnFRXRecno,9] lnGreen = This.aRecords[tnFRXRecno,10] lnBlue = This.aRecords[tnFRXRecno,11] lnAlpha = This.aRecords[tnFRXRecno,12] LOCAL loTextBrush as xfcSolidBrush loTextBrush = .SolidBrush.New(; .Color.FromArgb(lnAlpha,lnRed, lnGreen, lnBlue))
This.oGdiGraphics.DrawStringJustified(lcText, loFont, loTextBrush, loRectF, llFlag)
ENDWITH ELSE *!* If we're not drawing a full justified string, *!* let Fox draw the text as usual. DODEFAULT(tnFRXRecNo, tnLeft, tnTop, tnWidth, tnHeight, ; nObjectContinuationType, cContentsToBeRendered, GDIPlusImage) ENDIF
*!* Since we already drew the text, we don't want the default *!* behavior to occur. NODEFAULT ENDPROC
FUNCTION EvaluateContents(tnFRXRecno, toObjProperties) * Get the FRX data This.aRecords[tnFRXRecno,1] = toObjProperties.Text This.aRecords[tnFRXRecno,2] = toObjProperties.FontName This.aRecords[tnFRXRecno,3] = toObjProperties.FontStyle This.aRecords[tnFRXRecno,4] = toObjProperties.FontSize This.aRecords[tnFRXRecno,5] = toObjProperties.FillRed This.aRecords[tnFRXRecno,6] = toObjProperties.FillGreen This.aRecords[tnFRXRecno,7] = toObjProperties.FillBlue This.aRecords[tnFRXRecno,8] = toObjProperties.FillAlpha This.aRecords[tnFRXRecno,9] = toObjProperties.PenRed This.aRecords[tnFRXRecno,10] = toObjProperties.PenGreen This.aRecords[tnFRXRecno,11] = toObjProperties.PenBlue This.aRecords[tnFRXRecno,12] = toObjProperties.PenAlpha ENDFUNC
ENDDEFINE
3 - Update the report:
Below is a short tutorial for the beginners:
- Open any of your reports, that contains a field of more than one line that will receive the effect. Double-Click on that field, select the GENERAL tab, and add BEFORE your expression, this simple string: [ "<FJ>" + ], like in the picture below.

Another better option is to add the tag to the USER tab, that is available only in VFP9 Report Designer. Just like before, double-click in the desired field, select the "OTHER" tab, then click on the "EDIT USER DATA" button, and add the <FJ> tag to the window, just like the picture below. This is the most recommended approach, because the original data will not be affected, and if one day you decide to stop using the report listener, your report data will not be affected.

4 - Run the report
* Tell VFP that we'll be using the new report features SET REPORTBEHAVIOR 90 LOCAL loReportListener loReportListener = CREATEOBJECT("FullJustifyListener") loReportListener.ListenerType = 1 REPORT FORM YourReport OBJECT loReportListener
Below a last screenshot, showing the of the continued field issue solved:

Enjoy !!!
CLICK HERE TO DOWNLOAD THE SOURCE CODE AND SAMPLE FROM THIS ARTICLE
|
-
The GdiPlusX library is intended to be compatible with the .NET Framework’s System.Drawing namespace. That means that you can use the MSDN online documentation for the “System.Drawing” in order to obtain accurate information about the GdiPlusX classes. objects and functions. More than that, you can also convert the huge amount of samples published in various forums, blogs, articles and e-magazines to be used in VFP. It really does not matter if the sample was published in VB, C or ASP. The conversion to VFP is really intuitive.
When GdiPlusX was coded, we used a .NET conversion tool, called Reflector, which showed us all the source codes involved in each function, bringing us the possibility to code calling the same API functions, working with the same parameters.
BUT, during the coding phase, we had some great discussions about things that could be enhanced in order to ease user’s lives.
We had a premise not changing the behavior of any function, even if we disagreed with some things there, in order to keep the full compatibility.
On the other hand, we have decided that we could add new functions
Below is a short list of some functions that have been added to GdiPlusX, that are not present in the .NET original classes. Most of them have already been used in some samples posted in this blog, but till now, no documentation was published. So, here are some of those new functions, that came to my mind. Probably Bo or Craig will remember to add something here. I hope to be updating this post with some other improvements that only VFP users have available.
Of course, we know that GdiPlusX still needs some documentation, and we’re working on it. But for now, we hope that the list below will bring you some help.
xfcGraphics class
DrawStringJustified
Draws the specified text string at the specified location with the specified Brush and Font objects in a Full Justified format.
Parameters: tcString, ;
toFont as xfcFont, ;
toBrush as xfcBrush, ;
toRectangle as xfcRectangle
where:
tcString: text to be drawn
toFont: Gdi+X font object
toBrush: Gdi+X brush object
toRectangle: Gdi+X Rectangle object with position and dimensions to draw
Returns: Nothing
See also: Full-Justified Text with GdiPlus-X
Full Justified Texts in your reports with GdiPlus X
GdiPlusX Sample: FullJustified.scx / FullJustify.Prg
Code sample:
LOCAL lcText TEXT TO lcText NOSHOW This library was intended to provide Visual FoxPro 9.0 developers with an object based library to wrap the 600+ functions included with the GDI+ API. The intent is to mimic the System.Drawing namespace in the .NET Framework. All classes in the library are based on the classes included in the System.Drawing namespace and other classes that are dependencies for classes in the System.Drawing namespace. Some additional additional functionality has been added to take advantage of features built in to VFP 9.0 ENDTEXT
DO LOCFILE ("System.app") WITH _Screen.System.Drawing LOCAL loGfx as xfcGraphics loGfx = .Graphics.FromHwnd(_Screen.HWnd) loGfx.DrawStringJustified(lcText, .Font.New("Tahoma",12); , .Brushes.Red, .Rectangle.New(0,0,250,400)) ENDWITH
xfcBitmap class
ToClipboard
Sends the current bitmap to the clipboard
Parameters: None
Returns: Nothing
See also: Send Images to the Clipboard with GdiPlus-X Revisited
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) loBmp.ToClipboard() ENDWITH
FromClipboard
Creates a GDI+ bitmap object from the clipboard data
Parameters: None
Returns: Gdi+ bitmap object
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing
LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromClipboard() loBmp.Save("c:\FromClip.png", .Imaging.ImageFormat.Png)
ENDWITH
FromVarbinary
Creates an Image object from the specified VarBinary string. Useful to start manipulating an image directly without having to convert the binaries from the image to a file.
Parameters: tcBinary
Returns: GdiPlusX Bitmap object
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing
LOCAL lcBinary lcBinary = FILETOSTR(GETPICT())
LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromVarBinary(lcBinary) loBmp.Save("c:\FromVarBinary.png", .Imaging.ImageFormat.Png)
ENDWITH
FromScreen
Captures the specified window or object image to a new GDI+ bitmap object
Parameters:
tHWnd, tiX, tiY, tiWidth, tiHeight, tlEnsureVisible
toForm [, tiX, tiY, tiWidth, tiHeight [, tlEnsureVisible]]
toControl [, tlEnsureVisible]
Returns: Gdi+ bitmap object
See also: Capture Screens with GdiPlus-X
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing
LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromScreen() loBmp.Save("c:\FromScreen.png", .Imaging.ImageFormat.Png)
ENDWITH
GetMonochrome
Returns a monochrome GDI+ bitmap (1bpp) of this Image object.
The image must be saved in the BMP Image Format in order to keep the 1bpp format. Because the resulting bitmap is in an indexed pixel format, GDI+ cannot create a xfcGraphics object in order to draw on it. This function is recommended to be used immediately before saving to a file, in order to obtain the minimum file size. For some specific TIFF compression types, a monochrome image of 1bpp is required too, see more details in these articles:
Parameters: None
Returns: Gdi+ bitmap object
See also: Convert Images to Monochrome with GdiPlus X
Using TIFFs with the new GDI+ classes - UPDATE
TIFFS and the latest release of GdiPlusX
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing
LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT())
LOCAL loMonoch as xfcBitmap loMonoch = loBmp.GetMonochrome()
loMonoch.Save("c:\Monoch.bmp", .Imaging.ImageFormat.Bmp)
ENDWITH
GetPictureVal
Returns a String containing the PictureVal of this Image object, according to the ImageFormat passed. You can retrieve the binaries of the image with NO disk access, in any Image format supported by GDI+
Parameters: ImageFormat Object
EncoderParameter Object (optional)
Returns: String
See also: Manipulate images with no disk access with GdiPlusX
Code sample:
DO LOCFILE("System.App")
LOCAL loBmp as xfcBitmap * Obtaining the PictureVal directly WITH _Screen.System.Drawing loBmp = .Bitmap.FromFile(GETPICT()) Thisform.Image1.PictureVal = loBmp.GetPictureVal (.Imaging.ImageFormat.Bmp) ENDWITH
GetPictureValFromHBitmap
Returns a String containing the PictureVal of this Image object using the HBitmap GDI technique. The binaries retrieved are always in BMP format, what makes it a big string in most times. But, in most cases, this technique runs about 40% faster than using GetPictureVal() function shown above. The ImageCanvas objects uses this function to obtain the binaries from the images drawn.
Parameters: None
Returns: String
See also: Manipulate images with no disk access with GdiPlusX
DO LOCFILE("System.App")
LOCAL loBmp as xfcBitmap
* Obtaining the PictureVal directly WITH _Screen.System.Drawing loBmp = .Bitmap.FromFile(GETPICT()) Thisform.Image1.PictureVal = loBmp.GetPictureValFromHBitmap()
ENDWITH
ApplyColorMatrix
Applies the received color matrix to the current bitmap object
This is very useful, and provides an easy and quick way to apply image transformations in just one step, without having to use the ImageAttributes class.
Parameters:
toColorMatrix
Returns: NULL
See also: Special effects on images with GdiPlusX- Part1
Special effects on images with GdiPlusX – Part2
Draw Logos in your images with GdiPlusX - Part 2
Code sample:
DO LOCFILE("System.app")
WITH _Screen .System.Drawing LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) LOCAL loClrMatrix as xfcColorMAtrix loClrMatrix = .Imaging.ColorMatrix.New(; 0.33, 0.33, 0.33, 0, 0, ; 0.33, 0.33, 0.33, 0, 0, ; 0.33, 0.33, 0.33, 0, 0, ; 0, 0, 0, 1, 0, ; 0, 0, 0, 0, 1) loBmp.ApplyColorMatrix(loClrMatrix) loBmp.Save("c:\ClrMatrix.Png", .Imaging.ImageFormat.Png) ENDWITH
GetMask
Returns a Bitmap object with the mask from the current bitmap
In fact this function returns a bitmap with all the transparent parts of the image. Useful when you need to convert a PNG image that contains transparencies to be used in the BMP image format.
Parameters: None
Returns: Gdi+ bitmap object
See also: Convert your buttons to BMPs keeping transparency with GdiPlusX
ToPrinter
Sends the image object to the Printer
Parameters: tnStretch, tcPrinterName, tnOrientation, tnAlignment
tnStretch
* Specifies how an image is sized to fit inside a control.
* 0 - Clip. The image is clipped to fit the page. (Default)
* 1 - Isometric. The image resizes to fit the page while maintaining its original proportions.
* 2 - Stretch. The image resizes to fit the page, but does not maintain its original proportions.
tcPrinterName
* Specifies the name of the printer, the same of GETPRINTER()
tnOrientation:
* 0 - Portrait
* 1 - Landscape
tnAlignment
* Specifies a numerical value representing the alignment of the image in the page.
* 0 - Vertically Centered Left.
* 1 - Vertically Centered Right.
* 2 - Centered. Centers image vertically and horizontally.
* 4 - Top Left. Aligns image in top left corner of the page.
* 5 - Top Right. Aligns image in top right corner of the page.
* 6 - Top Center. Aligns image at the top and horizontally centered on the page.
* 7 - Bottom Left. Aligns image in the bottom left corner of the page.
* 8 - Bottom Right. Aligns image in bottom right corner of the page.
* 9 - Bottom Center. Aligns image at the bottom and vertically centered on the page.
Returns: Nothing
Code sample:
DO LOCFILE("System.app")
WITH _Screen.System.Drawing LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT()) loBmp.ToPrinter() ENDWITH
xfcColorMatrix class
MatrixMultiply
Returns a new Color Matrix object resulting of the multiplication of two color matrices. This is very useful when more than one color matrix is needed to be applied to an image. Multiplying the color matrices before they are applied to the image will bring a HUGE gain of performance.
Parameters: toColorMatrixOne, ;
toColorMatrixTwo
Returns: a new color matrix containing the resultant matrix
Code sample:
DO LOCFILE("System.app")
WITH _Screen
.System.Drawing
LOCAL loBmp as xfcBitmap loBmp = .Bitmap.FromFile(GETPICT())
LOCAL loClrMatrix1 as xfcColorMatrix && GreyScale matrix loClrMatrix1 = .Imaging.ColorMatrix.New(; 0.33, 0.33, 0.33, 0, 0, ; 0.33, 0.33, 0.33, 0, 0, ; 0.33, 0.33, 0.33, 0, 0, ; 0, 0, 0, 1, 0, ; 0, 0, 0, 0, 1)
LOCAL loClrMatrix2 as xfcColorMatrix && Half Brightness Matrix loClrMatrix2 = .Imaging.ColorMatrix.New(; 0.5, 0, 0, 0, 0, ; 0, 0.5, 0, 0, 0, ; 0, 0, 0.5, 0, 0, ; 0, 0, 0, 1, 0, ; 0, 0, 0, 0, 1)
LOCAL loNewClrMatrix as xfcColorMatrix loNewClrMatrix = loClrMatrix1.Multiply(loClrMatrix1, loClrMatrix2)
loBmp.ApplyColorMatrix(loNewClrMatrix) loBmp.Save("c:\MultClrMatrix.Png", .Imaging.ImageFormat.Png)
ENDWITH
xfcSize class
ToRectangle
Returns a xfcRectangle object from the current xfcSizeF object
xfcSizef class
ToRectanglef
Returns a xfcRectangleF object from the current xfcSizeF object
|
-
Here's a new release of FoxCharts
https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=VFPX&ReleaseId=13477
Prerequisites: Visual FoxPro 9 and the GdiPlusX library from VFPX

As you can see, 2 new charts are now available:
- Stacked Area
- Cylinder
- The StackedArea chart can be defined using the "ChartType" property, that must be set to the numeric 10
- The Cylinder chart is derived from the original Bars chart. To have it, select ChartType for the bar option, and then set the BarType property to numeric 1 (0 = Bar Default; 1 = Cylinder)
Apart from this, many other important modifications were applied:
The main difference is that now FoxCharts' base class is a Container, that contains the GdiPlusX ImageCanvas, and the legend objects, responsible for drawing all the text needed.
Now we can customize any of those labels in lots of ways. Every piece of text, legend in the chart now has the following properties:
Alignment - 0 Left; 1 Right; 2 Center BackColor BackColorAlpha - this is cool, (0-255) determines the transparency of the background of the label Caption FontBold FontItalic FontName FontSize FontStrikethru FontUnderline ForeColor ForeColorAlpha - determines the transparency of the label
The legends are represented by the following objects:
Title SubTitle XAxis XAxisLegend2 YAxis ShapeLegend ScaleLegend SideLegend
This way, every piece of text in the chart can be fully customized, not only the font, but the backcolor and the alpha (transparency). Now you can also change the alignment of the text, for example, to set the title to Right Alignment, all you have to do is to:
Thisform.FoxCharts1.Title.Alignment = 1 && Right
I still need to remind you that this is still a preview version, destined for people that are interested in helping testing this tool.
Please continue sending your suggestions and feedback! It is really very appreciated
https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=VFPX&ReleaseId=13477
Contains the ALPHA version of the FoxCharts project.
Unzip the file and run the form ChartsSample to see how it works.
This version also distributes the two main files from GdiPlusX - System.app and GdiPlusX.vcx. If you are already a GdiPlusX user, you can use your own GdiPlusX version. Just make sure to be using the latest GdiPlusX version.
GdiPlusX is also a VFPX project. For more information, please visit the GdiPlusX page at VFPX.
More information and pictures about this project can be obtained at the VFPIMAGING weblog:
http://weblogs.foxite.com/vfpimaging/archive/2008/04/04/5919.aspx
http://weblogs.foxite.com/vfpimaging/archive/2008/04/24/6040.aspx
This new release contains lots of enhancements:
Chart Types - Bar charts - Multiple bars - Stacked bars
- Pie - Doughnut
- Lines - Area - Stacked Area - Points and Shapes
Color variations: - Basic colors - Custom colors - Gradient colors - Random colors - Monochrome - Gradient or solid colors
Legends in many places: Axys, shapes, side legends
Scales
Customize: - Titles - Subtitles - Backgrounds (solid or gradient) - Fonts - Colors
|
-
Cropping an image is super simple using GdiPlusX
Prerequisites Visual FoxPro 9 and the GdiPlusX library from VFPX
Please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently. http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home
The cropping is done by the fuction "Clone()" from the Bitmap class. All we need is to pass a Rectangle object containing the X, Y, Width and Height of the desired image to be cropped.
Original Image 
Top Left 
Center 
Bottom Right 
Run the code below, selecting any image, and you will see the image cropped in three ways: the top-left part of the image, the bottom-right part, and the center.
LOCAL lcSource, lnWidth, lnHeight lcSource = GETPICT() IF EMPTY(lcSource) RETURN ENDIF
DO LOCFILE("System.App")
WITH _SCREEN.System.Drawing * Load Image to GdiplusX LOCAL loBmp AS xfcBitmap loBmp = .Bitmap.FromFile(lcSource) lnWidth = loBmp.Width lnHeight = loBmp.Height
* Crop Image LOCAL loCropped AS xfcBitmap
* Crop Top-Left LOCAL loRect as xfcRectangle loRect = .Rectangle.New(0, 0, lnWidth / 2, lnHeight /2) loCropped = loBmp.Clone(loRect) loCropped.Save("c:\Crop-TopLeft.png", .Imaging.ImageFormat.Png) RUN /N explorer.EXE c:\Crop-TopLeft.png * Crop Bottom-Right * Now, the Rectangle region will be created inside the Clone function loCropped = loBmp.Clone(.Rectangle.New(lnWidth / 2, lnHeight /2, lnWidth /2, lnHeight /2)) loCropped.Save("c:\Crop-BottomRight.png", .Imaging.ImageFormat.Png) RUN /N explorer.EXE c:\Crop-bottomright.png
* Crop Center loCropped = loBmp.Clone(.Rectangle.New(lnWidth / 4, lnHeight /4, lnWidth /2, lnHeight /2)) loCropped.Save("c:\Crop-Center.png", .Imaging.ImageFormat.Png) RUN /N explorer.EXE c:\Crop-Center.png
ENDWITH RETURN
|
-
-
I'm happy to announce that FoxCharts has recently been accepted as a VFPX project.
Today I've just uploaded to VFPX at CodePlex a new version of FoxCharts. This is version 0.14 - still ALPHA - NOT FOR PRODUCTION !
Prerequisites: Visual FoxPro 9 and the GdiPlusX library from VFPX
First of all I have to thank you all for your kind comments and feedback you provided in my last post. I had never expected to receive so many comments, in this blog, at the other VFP forums and by email. I really apreciated that. Be sure that your feedback resulted in a superpowered motivation to improve it.
It is also important to tell everybody of the importance that both Bo Durban and Craig Boyd have in this project. They are the menthors and fathers of GdiPlusX. Without GdiPlusX this project would become almost impossible. If I had to use any other of the Gdi+ classes available for VFP, for sure it would have taken much more time - Believe-me, I've tried them all.
Using GdiPlusX I can be indeed much more productive. Once you understand how it works, things become really easy and simple.
At first sight, when I saw one of the first versions that Bo and Craig designed for GdiPlusX I was really amazed, and I said to myself - I have to go deeper into this.
Bo Durban has also provided important help, providing important suggestions, support and testing. Thanks also to EmersonReed, Luis Maria Guayan and Leandro Walfrans for your tips and support.
This version also distributes the two main files from GdiPlusX - System.app and GdiPlusX.vcx. If you are already a GdiPlusX user, you can use your own GdiPlusX version. Just make sure to be using the latest version.
This new release contains lots of enhancements:
Chart Types - Bar charts - Multiple bars - Stacked bars
- Pie - Doughnut
- Lines - Area - Points and Shapes
Color variations: - Basic colors - Custom colors - Gradient colors - Random colors - Monochrome - Gradient or solid colors
Legends in many places: Axys, shapes, side legends
Scales - automatic or customized
Customize: - Titles - Subtitles - Backgrounds (solid or gradient) - Fonts - Colors
The sample form shows most of the features that are available. Run the form "ChartsSample.scx" and play changing the various properties, generating some cool charts like the ones below.

All the relevant codes are in the INIT() event of the sample form. With very few lines of code you can create super cool and beautiful charts.
This sample also includes a report sample. Check the codes in the command button that generates a report to see one of the various ways we have to print our charts.

Important to remember that this is still an ALPHA version, and is not recommended to be used in production although it works nice.
Some important improvements still need to be applied, specially in the class initialization. The codes also need to be optimized. My priority was in obtaining the results, and in many places the performance can be improved.
If you have any tips, or can provide suggestions, or fixes, you are most welcome !
Enjoy !
Download the latest version directly from the FoxCharts page on VFPX:
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=FoxCharts&referringTitle=Home
The page for the latest release 0.14 Alpha:
http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=12847


Here are the properties that are currently provided in FoxCharts, that you can use to improve your charts:
| SourceAlias |
Character, the name of the alias that contains the needed fields that will create the chart |
| FieldValue1 |
Character, the field name of the cursor that contains the numeric values that contain the values that will create the chart. |
| FieldColor |
Character, the field name of the cursor that contains the RGB values of the custom colors for the chart |
| FieldDetachSlice |
Character, the field name of the cursor that contains the logical values that tell if the slice of the Pie or Donut chart will be detached or not |
| FieldHideSlice |
Character, the field name of the cursor that contains the logical values that tell if the slice of the Pie or Donut chart will be hidden or not |
| FieldLegend |
Character, the field name of the cursor that contains the character values that contain the main legends of the Pie or Donut charts |
| FieldLegend2 |
Character, the field name of the cursor that contains the character values that contain the secondary legends of the chart that will be drawn inside the slice, or point or bar. |
| FieldXAxys |
Character, the name of the field that contains the text to be drawn in the X axys |
|
|
| Color1 |
Numeric, the RGB value of the color from the first chart |
| Legend1 |
Character, the Legend text for the first sequence of values |
|
|
| ChartType |
Numeric, type of chart: 1 = Pie ; 2 = Donut ; 3 = Unspecified ; 4 = Point ; 5 = Line ; 6 = Area ; 7 = Simple Bar ; 8 = Multiple Bars ; 9 = Stacked Bars |
| ChartsCount |
Numeric, the number of Value sources |
|
|
| FontName |
Character, the name of the font to be used to display text |
|
|
| TitleFontSize |
Numeric, the font size for the main title |
| TitleCaption |
Character, the title caption |
| TitleForeColor |
Numeric, the title and subtitle forecolor RGB value |
| SubTitleCaption |
Character, the subtitle caption |
| SubTitleFontSize |
Numeric, the subtitle font size |
|
|
| ShowLegend |
Logical, Shows the side legends |
| LegendFontSize |
Numeric, the fontsize for the side legends |
| LegendForeColor |
Numeric, the legend fore color RGB value |
|
|
| ShowValuesonShapes |
Logical, determines if the values will be drawn inside the shapes of the chart |
| LegendOnShapeColor |
Numeric, the RGB value for the shape color |
| LegendOnShapeFontSize |
Numeric, the font size for legends on shape |
|
|
| ShowAxys |
Logical, for Line, Area or Point charts - determines if the X and Y axys will be drawn |
| AxysXCaption |
Character, the main text for the X axys |
| AxysYCaption |
Character, the main text for the Y axys |
| AxysColor |
Numeric, the RGB value for the Axys main color |
|
|
| BackColor |
Numeric, RGB value of the main backcolor |
| BackColor2 |
Numeric, RGB value of the secondary (destination) backcolor. This is used to create gradients, together with "BackColor" |
| BackGradientMode |
Numeric, if gradient background (having BackColor2 specified) - 0 - horizontal; 1 - vertical; 2 - diagonal1 ; 3 - diagonal 2 |
|
|
| ShowScale |
Logical, determines if the scale in the Y axys will be shown |
| Scale |
Numeric, the scale value for the Y axys; 0 = Automatic scale |
| ScaleBackType |
Numeric, the background scale type; 0 = none; 1 = lines; 2 = rectangle |
|
|
| ColorType |
Numeric, the type of colors of the chart: 0 = Basic Colors 1 = Custom (default) 2 = Random 3 = Scale of Gradients |
| BrushType |
Numeric, type of brush used to fill the chart: 1 - Solid Colors; 2 - Gradient Colors; 3 - Monochrome Hatch brush |
| GradientLevel |
Numeric, for gradient brush mode (-10 = destination black; 0 = solid color; +10 destination white) |
| AlphaChannel |
Numeric, 0-255 Determines the level of the transparency level; 255 = Opaque; 0 = transparent |
| _3D |
Numeric, the quantity of pixels that create the 3D effect (0 = plain) |
|
|
| Margin |
Numeric, specifies the margin width created in the text portion of the control. |
| DonutRatio |
Numeric, For Donut chart - the width of the donut related to its size ( 0.01 = full slice ; 0.99 = thin) |
| LineCaps |
Logical, for the case of plain line chart, shows rounded caps in each point. |
| LineShape |
|
| PointsShape |
Numeric, the shape to be used in a points chart: 0 = Round; 1 = Square; 2 = Triangle; 3 = Cross; 4 = Star; 5 = Man; 98 = GDI+X Path object; 99 = Custom Image |
| PointsShapeWidth |
Numeric, for Point chart, determines the width of the pen that will draw the shapes |
| PieDetachPixels |
Numeric, for Pie and Donut charts, the quantity of pixels to detach from center |
| BarsSpaceBetween |
Numeric, for bars chart - the distance in pixels between bars |
| Area3DTop |
Logical, when true, a line will be drawn on the top of the 3D Area chat |
|
|
| MultiChart |
Logical, determines if more than one kind of chart will run at the same time |
|
-
Till now I had seen many samples showing how we can make the Print button invisible from the Report Preview toolbar, but I had never seen the possibility to show it disabled. Here's a sample, totally based in Emerson Reed's, from an old post in his great blog: A sample on how to add features to Report Listener - http://weblogs.foxite.com/emersonreed/archive/2006/09/13/A_sample_on_how_to_add_features_to_Report_Listener.aspx
It brings the possibility to hide completely the Print button or to disable it - just set the properties "PrintButtonVisible" and "PrintButtonEnabled". Apart from this, it also allows to change the tooltips from the buttons. For my case this is really helpful, in order to have the translated tooltips to my native language.
I've only added 7 or 8 lines of code all the sample comes from Emerson. It was tricky to set the "enabled" property of the print button, because there's no property that allows us to set this, differently from the "Visible", that was allowed, using the property "AllowPrintfromPreview". Even setting the property "Enabled" directly in the ExtensionHandler class below, the button still appeared enabled.
.cmdPrint.Enabled = .F. && Did not work
My solution was to use BINDEVENT, in order to control the behavior whenever the report previewer tried to change the "Enabled" property:
BINDEVENT(THIS.PreviewForm.Toolbar.CmdPrint,"Enabled",This,"Disabled",1) Then, I added a custom function "Disabled", that forces the Print button to appear disabled: PROCEDURE Disabled THIS.PreviewForm.Toolbar.cmdPrint.Enabled = .F. ENDPROC
* See "Leveraging the default preview container" topic in HELP for more info * Report Listener based on Emerson Reed's sample from * http://weblogs.foxite.com/emersonreed/archive/2006/09/13/A_sample_on_how_to_add_features_to_Report_Listener.aspx
* Create a Report Listener object Local loReportListener loReportListener = Newobject("MyReportListener") With loReportListener .ListenerType = 1 && Preview .PrintButtonVisible = .T. .PrintButtonEnabled = .F. Endwith * Run a report from the samples of VFP using the new report engine (object-assisted output) REPORT FORM ; HOME() + 'Samples\Solution\Reports\colors.frx' ; OBJECT loReportListener RETURN * Custom Report Listener that adds some features Define Class MyReportListener As FXLISTENER Of Addbs(Home()) + "FFC\_ReportListener.VCX"
* Public properties PrintButtonVisible = .T. PrintButtonEnabled = .T. * Procedure LoadReport DoDefault() With This If .ListenerType==1 And Not Vartype(.PreviewContainer)=="O" .ExtendPreviewContainer() Endif Endwith Endproc * Function ExtendPreviewContainer Local loPreviewContainer loPreviewContainer = Null Do (_ReportPreview) With loPreviewContainer loPreviewContainer.AllowPrintfromPreview = This.PrintButtonVisible
LOCAL loExtHandler loExtHandler = CREATEOBJECT("MyExtensionHandler") loExtHandler.DisablePrintButton = NOT This.PrintButtonEnabled
loPreviewContainer.SetExtensionHandler(loExtHandler) This.PreviewContainer = loPreviewContainer Endfunc Enddefine
* Create a class that will extend Report Preview Define Class MyExtensionHandler As Custom DisablePrintButton = .F.
Procedure Show(iStyle) With This.PreviewForm With .Toolbar * Translate toolbar buttons ToolTips to Brazilian Portuguese language .cboZoom.ToolTipText = "Zoom" .cmdClose.ToolTipText = "Fechar a visualização" .cmdGoToPage.ToolTipText = "Ir para a página" .cmdPrint.ToolTipText = "Imprimir" IF This.DisablePrintButton * BINDEVENT(THIS.PreviewForm.Toolbar.CmdPrint, "Visible", This, "Invisible", 1)
* Here we control the ENABLED property BINDEVENT(THIS.PreviewForm.Toolbar.CmdPrint, "Enabled", This, "Disabled", 1) ENDIF
With .cntNext .cmdBottom.ToolTipText = "Última página" .cmdForward.ToolTipText = "Próxima página" Endwith
With .cntPrev .cmdBack.ToolTipText = "Página anterior" .cmdTop.ToolTipText = "Primeira página" Endwith
With .opgPageCount .opt1.ToolTipText = "Uma página" .opt2.ToolTipText = "Duas páginas" .opt3.ToolTipText = "Quatro páginas" Endwith * Endwith .WindowState = 2 && Maximize report preview Endwith DoDefault(iStyle)
ENDPROC
* Here is the relevant code to disable the button PROCEDURE Disabled THIS.PreviewForm.Toolbar.cmdPrint.Enabled = .F. ENDPROC * Enddefine
|
-
Wanna create some cool charts in VFP ?
With no ActiveX controls, dlls, or 3rd party products ?
What do you think of these ?




Recently, I’ve seen many discussions about people asking for charts components. Since GdiPlusX brings us all these possibilities, I thought it would be worth to start a project regarding this.
FoxCharts is a subclass of the ImageCanvas class from GdiPlusX, that allows us to direct draw in an image object, among many other cool and useful features, that are not in the scope of this post.
Goals of FoxCharts: - Create good looking and modern charts in pure VFP - NO ActiveX components - Easy to setup - Easy to customize. - Easy to save to disk or print - Open Source - Benefit from all the GdiPlusX drawing capabilities, allowing users to modify the charts the way they like. - Save as EMF, resulting in perfect charts when printed in VFP reports
Prerequisites: Visual FoxPro 9 and the GdiPlusX library from VFPX
In the source code you'll find a sample form, “NewChart.Scx” that allows to create different kinds of charts using this class.
Please note that as it is still in Alpha version, the codes that create the charts are still in the sample form. GpCharts.vcx is (at this moment) just a holder that contains the PEMs needed to draw. In development mode, double click the ImageCanvas object to see the source code that generates these charts.
The codes that will instantiate GpCharts reside in the INIT() event of the sample form, only there.
Currently available: Bars, Lines, Area, Pie and Donut charts, in various color variations, using gradients, custom colors, basic and random colors. Titles, subtitles and legends
To do: Enhance the data filling, create a builder, allow different kinds of charts to appear together (eg. Lines and bars). Legends in the Y and X axys.
And obviously: Fix some bugs !
If you are interested in developing and enhancing FoxCharts, feel free to post a comment here. Your suggestions, tips, critics, testing and bugs hunting will be most appreciated !
Download directly from the FoxCharts page in VFPX
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=FoxCharts&referringTitle=Home
|
-
-
Recently MVP Cetin Basoz posted a great script that generates an excellent color picker. This is so good and useful, that I added it to my "Tools" menu during development.
Thanks Cetin !
If you're interested, you can download it from here:
http://www.foxite.com/downloads/default.aspx?id=179
|
|
|