2007-10-31

Rotate texts in your reports for old VFP versions.

This post is for people that still did not upgrade to vfp9.

As ken murphy said in one of his latest posts in foxite forum: "... the capabilities of the vfp 9 report generator alone are worth the price of the upgrade. everything else is a bonus."


When I worked with VFP7  I created a function that uses GpImage2 GDI+ class, that you can download from this link. GPIMAGE2 CLASS


Have a look at the file "teste.frx" that is in the "examples" folder of the class. below is a screenshot with the possible results using the report designer





How to use:

After downloading the file, run teste.frx, it uses a simple class i've created called gdipstring, it's very easy to use. if you open gdipstring.prg, you'll see on the initial notes the parameters used.



Basically, you'll need to:

  • add an image object

  • dimenson the image to the desired size of the string you need

  • double click the image object, select "from file"


  • call the function gdipstring, as shown:
(GdipString( ;
    lcDimensionType, ; 
    lnWidth, ;
    lnHeight, ; 
    lcString, ; 
    lcFontName, ;
    lnFontSize, ; 
    lcFontStyle, ; 
    lcTextalignment, ;
    lnRotation))


Parameters:

tcDimensionType = character"p" ou "i" - dimensions in pixels or inches
tnWidth     = numeric, widthtnHeight    = numeric, height
tcString    = character, text string
tcFontName  = character, font name
tnFontSize  = numeric, font size
tcFontStyle = character, font style
           b - bold     i - italic     u - underline     s - 
tcTextAlignment = character, alignment
           c - center     l - left     r - right
tnRotation  = numeric, direction
           0 - normal (not recomended)
           1 - vertical - rotate 90º
           2 - horizontal - rotate 180º (upside down)
           3 - vertical - totate 270º




For example, if you put in from file : (gdipstring("p",190,31,"foxbrasil","arial",20,"ub","c",2)) you'll have : string "foxbrasil", arial, size 20, underline bold, centered, upside down drawn inside the virtual rectangle of size 190,31 in pixels.



Very important:

Don't forget to put the expression between parenthesis () !!

After running the report, you need to delete manually the temporary files used to create the gradients, with just one line of code:

delete file (addbs(getenv("temp")) + "tmp*.jpg")

Neither GpImage2 nor gdipstring are not under development anymore. i'm just sharing it, bacause maybe some people that still did not upgrade to vfp9 need some gdi+ usage. today, when i reopened the source code for GdipString, I found many things that can be enhanced. if you have interest in improving it, feel free to do so, and please send your updates so that other may benefit too.



About GpImage2:

The class GpImage2 brings a wrapper class to gdiplus.dll that allows to use most of the GDI+ functions. visit the link below, download the source, and run the samples available in the "examples" folder. there you'll find a simple class that permits to create some interesting charts, drawings, reports with vertical labels, etc.

https://vfpimaging.blogspot.com/p/gpimage2.html

If you're not using Windows XP or VFP8, you'll need to download the distributable version. There's a good explanation on GpImage's website.

Here you'll find some other samples, at the "FAQs" page.

https://vfpimaging.blogspot.com/p/gpimage2-faqs.html

2007-10-30

How to put one image over another in a form

This is a very basic and easy stuff.

The image that will stay on the top must have some kind of transparency set. It is recommended that you use a BMP of 24bits. VFP will automatically convert the white parts of the image into transparent, like in the picture below, if you set the "BackStyle" property of the image object to 0 - Transparent. don't forget to set the picture to "Bring to front" in the "layout" toolbar.





The 1st form shows the 2 images separated, but with opaque backgrounds. Then, in the 2nd, I set the background to transparent, then dropped a part of the image for you to see how it is done. You can get more information in this post too:

Bmps with transparent backgrounds http://vfpimaging.blogspot.com/2007/10/bmps-with-transparent-backgrounds_881.html

Another good way is to use PNGs, that support alpha (transparencies), but the most recomended, and best supported by VFP is the use of BMPs, as shown.



Update - Oct 30, 2007

Bernard Bout remembers that "also note that all white areas of an image will become transparent. for instance in the second image in cesars post the form background is visible through the eye of the brazilian man. if this is not what you want then you must "mask" out the white parts of the bitmap that you want to be not transparent.
Just open the image and paint the white areas you want to keep black. The image should be the same size. paint all the other parts white and save it as a bmp but with a .msk extension. VFP will automatically use this file to "mask" out the white areas from being transparent."



For this case, I usually edit the image, and change the pure RGB "whites" - rgb(255,255,255) that I want to keep to another close white, such as RGB(254,254,254) nobody will notice the difference and it works very nice, with the advantage of not needing to create an extra image file.

Anyway, if you still prefer to create a mask, choose to create a 1bpp monochrome image format. Usually people save in "24bits" mode. but as msk pictures are only B&W, monochrome will bring the possibility to have the smallest image file size. Comparing to a monochrome image, the 24bpp image will be 24 times bigger in size.

In MSPAINT, for instance, choose, in "SaveAs..."




Other important notes about MSK files:

In VFP HELP for pictureval:

"You cannot specify a mask (msk) file with the pictureval property. If you are using BMP images and want a mask, you should use the picture property instead. you can also use a different image format such as gif which has transparency defined within the image."

how to: enhance control display a very nice explanation about msk files

2007-10-29

MY THANK YOU TO PABLO ROCA and PortalFox Sysops

recently i've known some bad news for the spanish speaking community. pablo roca is not a mvp anymore - see his article not renewed as mvp - but still alive! .


i've never had any direct contact with him. not in emails, neither in a forum, never. but i'm very thankful to him and all portalfox sysops and contributors.


for those who don't know, portalfox is the main and free portal for spanish-speaking developers, located at http://www.portalfox.com. they do an amazing job, providing great and inventive contents, and translate everything that they find could help spanush speaking vfp users, such as the vfp ide, vfp help files, articles, codes, etc. even for brazilians, due to some similarities in the language, many of us constantly visit portalfox.


all that i can say is a big thank you to you, pablo roca (spain), and also to isaac venegas (usa), esparta palma (mexico), luis maria guayan (argentina), ana bisbe (spain) and all your collaborators.


long life to portalfox !

2007-10-24

BMPs with Transparent Backgrounds

Here are some notes on bmp transparencies on vfp, based in some conclusions I took after some discussions in Foxite, specially the ones with Bernard Bout.

BMP image files, when used in the picture property of the image control usually show whites - RGB(255,255,255) as transparent. VFP creates a temporary mask for our pictures in order to show this way.



Picture 1: BMPs can have whites converted to transparent when using the "Picture" property and Backstyle set to "Transparent".

But this works only for the 'Picture' property, not for 'PictureVal' !

The code below creates a simple image on the fly, and saves it to disk. The image on the left uses the picture property, and the right one uses 'PictureVal'.


ImportantRequires VFP9 and GdiplusX library to run.
https://github.com/VFPX/GDIPlusX



PUBLIC oForm
oform = NEWOBJECT("form1")
oform.SHOW
RETURN

DEFINE CLASS form1 AS FORM
 TOP = 13
 LEFT = 17
 HEIGHT = 168
 WIDTH = 314
 DOCREATE = .T.
 CAPTION = "testing pictureval rendering"
 NAME = "form1"

 ADD OBJECT image1 AS IMAGE WITH ;
  BACKSTYLE = 0, ;
  HEIGHT = 120, ;
  LEFT = 24, ;
  TOP = 24, ;
  WIDTH = 120, ;
  NAME = "image1"

 ADD OBJECT image2 AS IMAGE WITH ;
  BACKSTYLE = 0, ;
  HEIGHT = 120, ;
  LEFT = 168, ;
  TOP = 24, ;
  WIDTH = 120, ;
  NAME = "image2"

 PROCEDURE INIT
  DO LOCFILE("system.app")
  LOCAL lobmp AS xfcbitmap
  LOCAL logfx AS xfcgraphics
  WITH _SCREEN.SYSTEM.drawing
   lobmp = .BITMAP.new(60, 60, 0, .imaging.pixelformat.format24bpprgb)
   logfx = .graphics.fromimage(lobmp)
   logfx.CLEAR(.COLOR.white)
   logfx.drawrectangle(.PEN.new(.COLOR.red, 3), 10,10,40,40)
   lobmp.SAVE("c:\tempbmp.bmp", .imaging.imageformat.bmp)
  ENDWITH
  THISFORM.image1.PICTURE = "c:\tempbmp.bmp"
  THISFORM.image2.PICTUREVAL = FILETOSTR("c:\tempbmp.bmp")
 ENDPROC
 ENDDEFINE


Picture 2: BMPs show whites as transparent only when using the "picture" property. When using "Pictureval", images are shown without a transparent mask.

The image from the left uses the picture property, and the right one uses the pictureval property in the most simple aproach: FILETOSTRING("c:\MyPicture.bmp")
That shows us that unfortunately we can't obtain transparencies in BMPs using the pictureval property.

Fortunately, in VFP9 SP2 the VFP team fixed the PNG rendering problem, and we can use PNGs with our VFP image objects. But in this case, we need to set manually the alpha channel, specifying which color (or colors) will become transparent.
With GdiplusX these things become really easy. Just one line will do the trick:

This.oBmp.MakeTransparent(.Color.White)

Replace the above code's Init() procedure with the one below, that just changes the rendering to PNG, and uses the "MakeTransparent" method of the xfcBitmap GdiplusX library:

PROCEDURE INIT
 DO LOCFILE("system.app")
 LOCAL lobmp AS xfcbitmap
 LOCAL logfx AS xfcgraphics
 WITH _SCREEN.SYSTEM.drawing
  lobmp = .BITMAP.new(60, 60) && the default is 32bppargb
  logfx = .graphics.fromimage(lobmp)
  logfx.CLEAR(.COLOR.white)
  logfx.drawrectangle(.PEN.new(.COLOR.red, 3), 10,10,40,40)
  lobmp.maketransparent(.COLOR.white)
  lobmp.SAVE("c:\temppng.png", .imaging.imageformat.png)
 ENDWITH
 THISFORM.image1.PICTURE = "c:\temppng.png"
 THISFORM.image2.PICTUREVAL = FILETOSTR("c:\temppng.png")
ENDPROC




Picture 3: PNGs allow the use of the alpha channel, so transparencies are available both for picture and pictureval properties


Is that enough ?

Still not enough for Bernard - part 1

As he said in one foxite thread: "VFP does have a problem refreshing png's of any reasonable size. they do "flash". the best format to use with vfp is the bmp." - totally true - humpf ! That's very easy to reproduce, create any form, put an image object inside of it, using any png image. then, add another image, but this time use a BMP. set the anchor properties, run the form, and resize it, to understand what happens. maybe for the vast majority of people this is acceptable, but with BMPs we still can have a good result.



Still not enough for Bernard - part 2

He noticed that the bmps originated from the samples that I've been providing using GDI+ could not have their whites to become transparent when used in the image control.

!#*$¨*&¨($%+)(*#$%&(_*%¨#)&*(¨#&*()yuioh%&*_#(*&%(_*#$¨

The truth is that he had reported this last year, when i created a sample for his awesome One Note tabs - "vfp-x gdi+ code samples for "recreating one note tabs in vfp9" from bernard"

He has just brought this subject again in a recent foxite thread, and i finally took the time to make some new tests, and found the problem.

In most cases, when I created my bitmaps from scratch, I used the xfcBitmap.create() method, just like this:

local loBmp as xfcBitmap
loBmp = .Bitmap.New(lnWidth, lnHeight)

This by default created a bitmap with the dimensions lnwidth x lnheight, with 32bppargb pixelformat. that means that for each pixel of the bitmap we would be using 32bits, or 4 bytes - for red, green, blue and alpha (transparency).
but bmps don't support transparencies !
So, the alpha byte is totally useless for the bmp case, making our file to become 25% bigger...
The major problem is that vfp does not transform whites from 32bppargb bitmaps into transparent !!!
So, when creating a bitmap that will be saved in the bmp image format, never use 32bppargb. use 24bpprgb instead ! and this definitely solves our problem, and bernard will be able to continue to develop his masterpieces of design, hopefully, using gdiplusx.
Instead of :
loBmp = .Bitmap.New(lnWidth, lnHeight)

use:
loBmp = .Bitmap.New(60, 60, 0, .Imaging.PixelFormat.Format24BppRgb)

Thanks Bernard ! This was a good lesson to me, I've learned some good things in this investigation. Very nice, since this brings some new possibilities for some new controls.
The GdiplusX 'ImageCanvas' control will also receive some modifications, allowing to render in file mode, saving to TMP files, but using 24bpprgb, to allow the transparencies. Another modification that we agreed is to add a PNG render mode, since pngs allow the use of the alpha channel.
'Vfppaint' was also updated, allowing users to choose between 24bpprgb (new default value) and 32BppArgb.

New Report features from SP2 are ready to use !

since ms released the final service pack 2 for vfp last week, many complaints have arised. people are not trusting in this new version, and it seems that some problems that were fixed in sp1 came back in sp2.


fortunately, the report new features are really solid, trustable, and bring good value for us.


so, for this moment, it is safe to bring the report features to sp1, if you are having problems with sp2, till ms delivers a new version.


colin has just answered to koen piller in ut on this subject.


koen said: "it is very well possible to safe the 3 report*.app from sp2 than install vfp + sp1 and replace the 3 report*.app with the ones from sp2. this configuration will give you all the advantages of the new report enhancements without using all the other sp2 'improvements'."

and colin gives his final words, recommending to update the ffc classes as well: "remember to update the ffc classes as well, if you use them in your programs. you don't have to use reportoutput.app at all if you don't want to. the listener classes in _reportlisteners.vcx are good to go..."