diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3d8d43c4ed..e0adf16002 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,12 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-04-10 11:20 UTC+0200 Lorenzo Fiorini (lorenzo.fiorini/at/gmail.com) + * harbour/contrib/gd + * added new directory + * harbour wrapper classes for www.libgd.prg graphic library + * see README and hbgd.txt for docs + 2007-04-06 15:38 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * harbour/source/rtl/persist.prg * harbour/source/rtl/tbrowse.prg diff --git a/harbour/contrib/gd/ChangeLog b/harbour/contrib/gd/ChangeLog new file mode 100644 index 0000000000..4f86a479f0 --- /dev/null +++ b/harbour/contrib/gd/ChangeLog @@ -0,0 +1,339 @@ +/* + * $Id$ + */ + +/* Use this format for the entry headers: + YYYY-MM-DD HH:MM UTC[-|+]hhmm Your Full Name + For example: + 2002-12-01 23:12 UTC+0100 Foo Bar +*/ + +2007-04-05 10:00 UTC+0200 Lorenzo Fiorini + * ported from xHarbour/contrib/gd + * changed name of the lib from gdlib to hbgd + * changed dirs and make files + * deleted some files + * changed images + * changed C and prg for Harbour + +2006-03-28 14:06 UTC-0300 Laverson Espindola + * contrib/gd/source/gdbarcode.prg + * contrib/gd/source/gdbar.prg + + added method to create barcode of the type 2 of 5 + * contrig/gd/samples/barcode/bartest.prg + + added sample to use barcode of the type 2 of 5 + +2006-03-21 00:38 UTC+0100 Francesco Saverio Giudice + * contrib/gd/Rules.make + * contrib/gd/make_vc.bat + * fixed make files + + * contrib/gd/source/gdwrp.c + * fixed linux compilation to align to gd ver. 2.0.28 + +2006-03-12 23:15 UTC+0100 Francesco Saverio Giudice + * contrib/gd/make_b32.bat + * contrib/gd/makefile.bc + * fixed BCC compilation + +2006-01-21 01:45 UTC+0100 Francesco Saverio Giudice + * contrib/gd/source/gd.prg + + added functions: + gdImageToString( oImage ) -> cImageString + return a string containing binary image + check oImage:cType for image type: jpeg, gif or png + gdImageToFile( oImage, cFileName ) -> NIL + Create an image file (as cFileName + "." + oImage:cType) + + * contrib/gd/source/gdimage.prg + + added ToString() method, this choose right ToString*() method reading cType property + + added ToFile( cFile ) method, this choose right ToString*() method reading cType property + and create an image file + + + contrib/gd/include/gdexternal.ch + external gd functions declaration + + + contrib/gd/tests/tostring.prg + sample for tostring() and SaveToFile() methods + +2006-01-08 23:28 UTC+0100 Francesco Saverio Giudice + * contrib/gd/source/gdwrp.c + + added save image to string + * contrib/gd/source/gdimage.prg + + added ToString*() methods, fixed Output*() methods + + /* + Now it is possible to get an image into a string using ToString*() methods. + Sample: + oImage := GDImage( 200, 200 ) + .... + cImage := oImage:ToStringJPeg() + */ + +2006-01-08 02:47 UTC+0100 Francesco Saverio Giudice + * contrib/gd/source/gdwrp.c + * fixed error + formatting + * contrib/gd/source/gd.prg + * fixed gdImageFromFile() + +2005-12-26 23:16 UTC+0100 Francesco Saverio Giudice + * contrib/gd/source/gdwrp.c + * fixed error parameters number + +2005-12-26 22:58 UTC+0100 Francesco Saverio Giudice + * contrib/gd/source/gdwrp.c + * gdImageStringFTEx + + added new parameters: linespacing (default 1.05) + charmap (default gdFTEX_Unicode) + resolution (default 96 dpi) + * contrib/gd/source/gd.prg + * changed gdImageStringFT accordling with new parameters + * contrib/gd/source/gdimage.prg + * changed SayFreeType() method accordling with new parameters + + contrib/gd/tests/testdpi.prg + + added sample showing dpi changes + * contrib/gd/include/gd.h + * minor formatting + + /* + Added new parameters not handled before to alter dpi in string drawing + As per request of Rene Gladis + */ + +2005-12-12 14:06 UTC-0300 Laverson Espindola + * source\gdbar.prg + ! Added new parameters in construtor class TCode + default "image_bar/", to output image, this suggestion from Francesco Saverio Giudice. + +2005-12-09 18:30 UTC-0300 Laverson Espindola + * source\gdwrp.c + ! Added missing castings to make MSVC happy + * make_vc.bat + * makefile.nt + + Added MSVC building files + * makemsvcimport.bat + + Utility to create import lib from GD DLL + * source\gdbar.prg + * source\gdbarcode.prg + + Added barcode generation routines + * samples\barcode\bartest.prg + * samples\barcode\bldtest.bat + * samples\barcode\bldtestvc.bat + + Added barcode sample + * README.txt + * MAKEFILE.BC + ! Updated with BarCode stuff + +2005-11-07 01:37 UTC+0100 Francesco Saverio Giudice + + * contrib/gd/README.txt + * updated + +2005-11-07 00:15 UTC+0100 Francesco Saverio Giudice + + * contrib/gd/source/gdwrp.c + + added gdImageGifAnimBegin, gdImageGifAnimAdd, gdImageGifAnimEnd + + + contrib/gd/tests/animgif.prg + + test of gdImageGifAnim*() functions + + /* Added Animated GIF functions ! */ + +2005-11-06 16:48 UTC+0100 Francesco Saverio Giudice + + * contrib/gd/source/gdwrp.c + + added GTIMAGECREATEPALETTE as alias of GDIMAGECREATE + + contrib/gd/tests/antialiased.prg + + test of gdImageSetAntiAliased() function + thanks to Jorge Mason for requesting it + +2005-10-31 01:37 UTC+0100 Francesco Saverio Giudice + + + contrib/gd/Rules.make + * reverted. file needed + +2005-10-31 01:20 UTC+0100 Francesco Saverio Giudice + + * contrib/gd/source/gdwrp.c + * contrib/gd/source/gdimage.prg + * contrib/gd/source/gd.prg + * fixed some warnings + + * contrib/gd/include/gd.h + * contrib/gd/include/gd.ch + * contrib/gd/source/gdimage.c + * contrib/gd/source/gdwrp.c + * guarded gd version. + for linux gd last version is 2.0.28 (i.e. Fedora Core 3) + for windows gd last version is 2.0.33 + if your distribution is different please update header files + this is needed because some functions are missing in 2.0.28 + + - contrib/gd/Rules.make + - contrib/gd/test/Makefile + - contrib/gd/test/Makefile.linux + - contrib/gd/test/Makefile.mingw32 + + contrib/gd/test/bldtest.sh + + contrib/gd/test/dll_b32.bat + + contrib/gd/test/dll_b32.mak + + contrib/gd/samples/counter/bldtest.sh + + contrib/gd/samples/counter/dll_b32.bat + + contrib/gd/samples/counter/dll_b32.mak + * contrib/gd/README.txt + + * updated compilation batches for windows dll and linux + + now for windows: bldtest gdtest (full static) + dll_b32 gdtest (dll version - needs harbour.dll) + for linux : . bldtest.sh gdtest + +2005-10-30 02:32 UTC+0200 Francesco Saverio Giudice + + * contrib/gd/source/gdwrp.c + * replaced + im = hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); + with + im = hb_parptr( 1 ); + and + im_handle = hb_itemPutPtr( NULL, ( BYTE *) im ); + hb_itemReturn(im_handle); + hb_itemRelease(im_handle); + with + hb_retptr( im ) + +2005-10-25 18:07 UTC+0200 Francesco Saverio Giudice + + * contrib/gd/MAKE_B32.BAT + * fixed bgd.dll name + (thanks to Dener) + +2005-10-25 10:31 UTC+0200 Francesco Saverio Giudice + + - contrib/gd/bgd.dll + + contrib/gd/bgd.dll_download.url + * removed from bgd.dll from CVS 2.9 MB (sorry) + and added a link to gdwin32.zip from Thomas Boutell's website + to download it. + * contrib/gd/README.txt + * updated + * contrib/gd/MAKE_B32.BAT + * check if bgd.dll exists + +2005-10-25 02:43 UTC+0200 Francesco Saverio Giudice + + * contrib/gd/tests/gdtest.prg + * contrib/gd/tests/gdtestcls.prg + * some fixes + + * contrib/gd/README.txt + * updated + + + contrib/gd/samples + + added a samples directory + + + contrib/gd/samples/counter/bldtest.bat + + contrib/gd/samples/counter/counter.prg + + contrib/gd/samples/counter/digits + + contrib/gd/samples/counter/digits/57chevy.gif + + contrib/gd/samples/counter/digits/7seg.gif + + contrib/gd/samples/counter/digits/brsd.gif + + contrib/gd/samples/counter/digits/digib.gif + + contrib/gd/samples/counter/digits/digitmania.url + + contrib/gd/samples/counter/digits/fdb.gif + + contrib/gd/samples/counter/digits/jelly.gif + + contrib/gd/samples/counter/digits/odb.gif + + contrib/gd/samples/counter/digits/odw.gif + + contrib/gd/samples/counter/digits/pdg.gif + + contrib/gd/samples/counter/digits/pdw.gif + + added a counter sample + + /* + A first sample: an image counter + to build: bldtest counter + to run: counter + to have a random number using 57chevy.gif as base image + or: counter 372647 odb.gif + to have a fixed number with odb.gif as base image + + base images from digitmania + + Enjoy! + + Francesco + + */ + +2005-10-25 01:14 UTC+0200 Francesco Saverio Giudice + + * contrib/gd/tests/bldtest.bat + * fixed build error + +2005-10-25 01:02 UTC+0200 Francesco Saverio Giudice + + * contrib/gd/tests/gdtest.prg + * contrib/gd/tests/gdtestcls.prg + * added output directory check and create if not exists + +2005-10-24 15:10 UTC+0200 Francesco Saverio Giudice + + + contrib/gd + + + /bgd.dll + + /Rules.make + + /Makefile + + /MAKE_B32.BAT + + /MAKEFILE.BC + + /README.txt + + /ChangeLog + + /doc/entities.html + + /doc/GD Graphics Library.url + + /doc/gd-license.txt + + /doc/gdlib.txt + + /doc/index.html + + /doc/libfreetype-license.txt + + /doc/libjpeg-license.txt + + /doc/libpng-license.txt + + /doc/win32-readme.txt + + /doc/zlib-license.txt + + /env/makeb32.env + + /env/makelib.b32 + + /env/bccWin32.Mak + + /include/gd.h + + /include/gdcache.h + + /include/gdfontg.h + + /include/gdfontl.h + + /include/gdfontmb.h + + /include/gdfonts.h + + /include/gdfontt.h + + /include/gdfx.h + + /include/gdhelpers.h + + /include/gd_io.h + + /include/jisx0208.h + + /include/wbmp.h + + /include/gd.ch + + /source/gd.prg + + /source/gdchart.prg + + /source/Makefile + + /source/gdwrp.c + + /source/gdimage.prg + + /tests/images_in + + /tests/images_out + + /tests/Makefile + + /tests/Makefile.linux + + /tests/Makefile.mingw32 + + /tests/setfont.bat + + /tests/bldtest.bat + + /tests/test_out.prg + + /tests/gdtest.prg + + /tests/gdtestcls.prg + + /tests/images_in/xharbour.jpg + + /tests/images_in/italia.gif + + /tests/images_in/fsg.jpg + + /tests/images_out/ + + + first upload + + /* + Please look at README.txt + */ + diff --git a/harbour/contrib/gd/Makefile b/harbour/contrib/gd/Makefile new file mode 100644 index 0000000000..0e93ba5e74 --- /dev/null +++ b/harbour/contrib/gd/Makefile @@ -0,0 +1,22 @@ + +ROOT = ../../ + +C_SOURCES=\ + gdwrp.c \ + +PRG_SOURCES=\ + gd.prg \ + gdbar.prg \ + gdchart.prg \ + gdimage.prg \ + gdbarcod.prg + +LIBNAME=hbgd + +include $(TOP)$(ROOT)config/lib.cf + +ifeq ($(HB_COMPILER),mingw32) + CFLAGS := $(CFLAGS) -I/usr/include +else + CFLAGS := $(CFLAGS) -I/usr/include +endif diff --git a/harbour/contrib/gd/README b/harbour/contrib/gd/README new file mode 100644 index 0000000000..bafb2945bd --- /dev/null +++ b/harbour/contrib/gd/README @@ -0,0 +1,42 @@ +/* + * $Id$ + */ + +/* + * The following parts are Copyright of the individual authors. + * www - http://www.xharbour.org http://www.harbour-project.org + * + * Copyright 2004-2005 Francesco Saverio Giudice + * README file explaining howto compile GD + * + * See doc/license.txt for licensing terms. + * + */ + +hbgd library is a wrapper around www.libgd.org graphic library + +COMPILING +========= + +on GNU system use: + make install + + ** requirements: gd, gd-devel, libpng, libpng-devel, libjpeg, libjpeg-devel, + freetype, freetype-devel, zlib, zlib-devel + +DOCUMENTATION +============= + +Not yet finished hbgd.txt is the help file. + +SAMPLES +======= + +For samples look at tests dir. +gdtest.prg is an API test application +gdtestcls.prg is a GDImage/GDChart Class test application +test_out.prg is a sample of a cgi application for windows (I have to complete it). +antialiased.prg shows how apply anti-alias to lines. +animgif.prg is a sample to create an animated gif. +bartest.prg is a sample to create barcodes with GD Library. + diff --git a/harbour/contrib/gd/gd.ch b/harbour/contrib/gd/gd.ch new file mode 100644 index 0000000000..18d5e4c61d --- /dev/null +++ b/harbour/contrib/gd/gd.ch @@ -0,0 +1,153 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * GD graphic library header file. + * + * Copyright 2004-2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + +#ifndef GD_CH +#define GD_CH + + +#if ( defined(HB_OS_WIN_32) || defined(__WIN32__) ) + #define GD_VERS 2033 +#else + #define GD_VERS 2028 +#endif + +/* The maximum number of palette entries in palette-based images. + In the wonderful new world of gd 2.0, you can of course have + many more colors when using truecolor mode. */ + +#define gdMaxColors 256 + +#define gdAlphaMax 127 +#define gdAlphaOpaque 0 +#define gdAlphaTransparent 127 +#define gdRedMax 255 +#define gdGreenMax 255 +#define gdBlueMax 255 + +/* For backwards compatibility only. Use gdImageSetStyle() + for MUCH more flexible line drawing. Also see + gdImageSetBrush(). */ +#define gdDashSize 4 + +/* Special colors. */ + +#define gdStyled (-2) +#define gdBrushed (-3) +#define gdStyledBrushed (-4) +#define gdTiled (-5) + +/* NOT the same as the transparent color index. + This is used in line styles only. */ +#define gdTransparent (-6) + +#define gdAntiAliased (-7) + +#define gdFTEX_LINESPACE 1 +#define gdFTEX_CHARMAP 2 +#define gdFTEX_RESOLUTION 4 + +/* These are NOT flags; set one in 'charmap' if you set the + gdFTEX_CHARMAP bit in 'flags'. */ +#define gdFTEX_Unicode 0 +#define gdFTEX_Shift_JIS 1 +#define gdFTEX_Big5 2 + +#define gdArc 0 +#define gdPie gdArc +#define gdChord 1 +#define gdNoFill 2 +#define gdEdged 4 + + +#define GD2_CHUNKSIZE 128 +#define GD2_CHUNKSIZE_MIN 64 +#define GD2_CHUNKSIZE_MAX 4096 + +#define GD2_VERS 2 +#define GD2_ID "gd2" + +#define GD2_FMT_RAW 1 +#define GD2_FMT_COMPRESSED 2 + +#define GD_CMP_IMAGE 1 /* Actual image IS different */ +#define GD_CMP_NUM_COLORS 2 /* Number of Colours in pallette differ */ +#define GD_CMP_COLOR 4 /* Image colours differ */ +#define GD_CMP_SIZE_X 8 /* Image width differs */ +#define GD_CMP_SIZE_Y 16 /* Image heights differ */ +#define GD_CMP_TRANSPARENT 32 /* Transparent colour */ +#define GD_CMP_BACKGROUND 64 /* Background colour */ +#define GD_CMP_INTERLACE 128 /* Interlaced setting */ +#define GD_CMP_TRUECOLOR 256 /* Truecolor vs palette differs */ + +/* resolution affects ttf font rendering, particularly hinting */ +#define GD_RESOLUTION 96 /* pixels per inch */ + +/* Legal values for Disposal. gdDisposalNone is always used by + the built-in optimizer if previm is passed. */ +#define gdDisposalUnknown 0 +#define gdDisposalNone 1 +#define gdDisposalRestoreBackground 2 +#define gdDisposalRestorePrevious 3 + + +/* FSG - text alignment */ +#define gdAlignLeft 0 +#define gdAlignCenter 1 +#define gdAlignRight 2 + +#endif // GD_CH diff --git a/harbour/contrib/gd/gd.prg b/harbour/contrib/gd/gd.prg new file mode 100644 index 0000000000..b418d21786 --- /dev/null +++ b/harbour/contrib/gd/gd.prg @@ -0,0 +1,248 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * GD graphic library prg level (client api) interface code. + * + * Copyright 2004 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + +#include "common.ch" + +FUNCTION gdImageChar( im, font, x, y, char, color ) +RETURN gdImageString( im, font, x, y, char, color ) + +FUNCTION gdImageCharUp( im, font, x, y, char, color ) +RETURN gdImageStringUp( im, font, x, y, char, color ) + +FUNCTION gdImageCircle( im, cx, cy, w, color ) +RETURN gdImageArc( im, cx, cy, w, w, 0, 360, color ) + +FUNCTION gdImageFilledCircle( im, cx, cy, w, color ) +RETURN gdImageFilledEllipse( im, cx, cy, w, w, color ) + +FUNCTION gdImageEllipse( im, cx, cy, w, h, color ) +RETURN gdImageArc( im, cx, cy, w, h, 0, 360, color ) + +FUNCTION gdImageFTWidth( fontname, ptsize, angle ) + LOCAL nWidth := 0 + LOCAL cErr + LOCAL aRect := Array(8) + DEFAULT fontname TO "Arial" + DEFAULT ptsize TO 8 + DEFAULT angle TO 0 + cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, "M" ) + //__OutDebug( "ptsize", ptsize, aRect ) + IF cErr == "" + nWidth := aRect[3] - aRect[1] + ENDIF + +RETURN nWidth + +FUNCTION gdImageFTHeight( fontname, ptsize, angle ) + LOCAL nWidth := 0 + LOCAL cErr + LOCAL aRect := Array(8) + DEFAULT fontname TO "Arial" + DEFAULT ptsize TO 8 + DEFAULT angle TO 0 + + cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, "M" ) + IF cErr == "" + nWidth := aRect[2] - aRect[8] + ENDIF + +RETURN nWidth + +FUNCTION gdImageFTSize( string, fontname, ptsize, angle ) + LOCAL nWidth := 0 + LOCAL nHeight := 0 + LOCAL nX, nY + LOCAL cErr + LOCAL aRect := Array(8) + DEFAULT fontname TO "Arial" + DEFAULT ptsize TO 8 + DEFAULT angle TO 0 + cErr := gdImageStringFTEx( , @aRect, 0, fontname, ptsize, angle, 0, 0, string ) + //__OutDebug( "ptsize", ptsize, aRect ) + IF cErr == "" + nWidth := aRect[3] - aRect[1] + nHeight := aRect[2] - aRect[8] + nX := aRect[1] + nY := aRect[2] + ENDIF + +RETURN { nWidth, nHeight, nX, nY } + +FUNCTION gdImageStringFT( im, fg, fontname, ptsize, angle, x, y, string, ; + linespacing, charmap, resolution ) + LOCAL cErr + LOCAL aRect := Array(8) + cErr := gdImageStringFTEx( , @aRect, fg, fontname, ptsize, angle, x, y, string, linespacing, charmap, resolution ) + IF cErr == "" + cErr := gdImageStringFTEx( im, aRect, fg, fontname, ptsize, angle, x, y, string, linespacing, charmap, resolution ) + ENDIF +RETURN cErr + +FUNCTION gdImageFromFile( cFile ) + LOCAL cPath, cName, cExt, cDrive + LOCAL cType, cMime + LOCAL hFile := {=>} + LOCAL oImage + + IF File( cFile ) + HB_FNameSplit( cFile, @cPath, @cName, @cExt, @cDrive ) + //TraceLog( cFile, cPath, cName, cExt, cDrive ) + cExt := Lower( cExt ) + DO CASE + CASE cExt == ".jpg" .OR. cExt == ".jpeg" + hFile[ "file" ] := cFile + hFile[ "path" ] := cPath + hFile[ "name" ] := cName + hFile[ "ext" ] := cExt + hFile[ "drive" ] := cDrive + cType := "jpeg" + cMime := "image/jpeg" + oImage := GDImage():LoadFromJpeg( cFile ) + + + CASE cExt == ".gif" + hFile[ "file" ] := cFile + hFile[ "path" ] := cPath + hFile[ "name" ] := cName + hFile[ "ext" ] := cExt + hFile[ "drive" ] := cDrive + cType := "gif" + cMime := "image/gif" + oImage := GDImage():LoadFromGif( cFile ) + + + CASE cExt == ".png" + hFile[ "file" ] := cFile + hFile[ "path" ] := cPath + hFile[ "name" ] := cName + hFile[ "ext" ] := cExt + hFile[ "drive" ] := cDrive + cType := "png" + cMime := "image/png" + oImage := GDImage():LoadFromPng( cFile ) + ENDCASE + + ENDIF + +RETURN { oImage, hFile, cType, cMime } + +FUNCTION gdImageToString( oImage ) + LOCAL cString + + //Tracelog( "oImage, oImage:ClassName, oImage:IsDerivedFrom( 'GDIMAGE' )", ; + // oImage, oImage:ClassName, oImage:IsDerivedFrom( 'GDIMAGE' ) ) + + IF ValType( oImage ) == "O" .AND. ( oImage:ClassName == "GDIMAGE" .OR. oImage:IsDerivedFrom( "GDIMAGE" ) ) + WITH OBJECT oImage + IF :cType <> NIL + DO CASE + CASE :cType == "jpeg" + cString := :ToStringJpeg() + CASE :cType == "gif" + cString := :ToStringGif() + CASE :cType == "png" + cString := :ToStringPng() + ENDCASE + ENDIF + END + ENDIF +RETURN cString + +PROCEDURE gdImageToFile( oImage, cFile ) + LOCAL cString, cExt + + DEFAULT cFile TO "image" + + //Tracelog( "oImage, oImage:ClassName, oImage:IsDerivedFrom( 'GDIMAGE' )", ; + // oImage, oImage:ClassName, oImage:IsDerivedFrom( 'GDIMAGE' ) ) + + IF ValType( oImage ) == "O" .AND. ( oImage:ClassName == "GDIMAGE" .OR. oImage:IsDerivedFrom( "GDIMAGE" ) ) + WITH OBJECT oImage + IF :cType <> NIL + DO CASE + CASE :cType == "jpeg" + cString := :ToStringJpeg() + cExt := "jpg" + CASE :cType == "gif" + cString := :ToStringGif() + cExt := "gif" + CASE :cType == "png" + cString := :ToStringPng() + cExt := "png" + ENDCASE + IF cString <> NIL + MemoWrit( cFile + "." + cExt, cString ) + ENDIF + ENDIF + END + ENDIF + +RETURN + +/* + + ////aRect := { 10, 40, 100, 40, 100, 20, 10, 20 } //Array(8) + //aRect := Array(8) + ////TraceLog( "aRect = " + hb_dumpVar( aRect ) ) + //gdImageStringFtEx( , @aRect, blue, "arial", 20, 30, 20, 90, 'Test') + ////TraceLog( "aRect = " + hb_dumpVar( aRect ) ) + //? "aRect = " + hb_dumpVar( aRect ) + //gdImageStringFtEx(im, aRect, blue, "arial", 20, 30, 20, 90, 'Test') + ////TraceLog( "aRect = " + hb_dumpVar( aRect ) ) + +*/ diff --git a/harbour/contrib/gd/gdbar.prg b/harbour/contrib/gd/gdbar.prg new file mode 100644 index 0000000000..c5c827290f --- /dev/null +++ b/harbour/contrib/gd/gdbar.prg @@ -0,0 +1,358 @@ +/* + * xHarbour Project source code: + * BAR engine library class + * + * Copyright 2005-2005 Laverson Espíndola + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ +#include "gd.ch" +#include "hbclass.ch" +#include "common.ch" + +#define IMG_FORMAT_PNG 1 +#define IMG_FORMAT_JPEG 2 +#define IMG_FORMAT_WBMP 4 +#define IMG_FORMAT_GIF 8 +#define IMG_QUALITY 95 + +#define THICKNESS_I250 0 +#define THICKNESS_I251 0 +CLASS TBarCode FROM GDImage + + // class attributes + DATA positionX AS NUMERIC INIT 4 + DATA positionY AS NUMERIC + DATA maxHeight AS NUMERIC INIT 25 + DATA maxHDefa AS NUMERIC INIT 25 + DATA lastX AS NUMERIC + DATA lastY AS NUMERIC + DATA error AS NUMERIC + DATA imWidth AS NUMERIC + + // Barcode attributes + DATA Parity + DATA LeftHand_Even AS ARRAY + DATA Right_Hand AS ARRAY + DATA LeftHand_Odd AS ARRAY + DATA keys AS ARRAY + + DATA book AS LOGICAL INIT .F. + DATA acode AS ARRAY + DATA KeysModeA AS CHARACTER + DATA KeysModeB AS CHARACTER + DATA KeysModeC AS ARRAY + + // image attributes + DATA res AS NUMERIC + DATA textfont AS NUMERIC + DATA text AS CHARACTER + DATA filename AS CHARACTER + DATA color_b AS ARRAY + DATA color_f AS ARRAY + DATA FillColor AS NUMERIC + DATA BackColor AS NUMERIC + DATA lDrawValue AS LOGICAL INIT .T. + + // Methods + METHOD CreateBar( sx, sy, filename, ccolor) + METHOD Configure( nmaxHeight, aFillColor, aBackColor, nres, ntextfont, lbook, lDrawValue ) + METHOD Allocate() + METHOD DrawError(ptext) + METHOD DrawSingleBar(pcode ) + METHOD DrawSingleI25( pcode ) + METHOD DrawText() + METHOD nextX() + METHOD Finish( image_style, quality ) + METHOD SetText( ptext ) + METHOD ResetColor() + METHOD CheckCode() + METHOD CheckValInArray(cchar) + +ENDCLASS + +METHOD CreateBar( sx, sy, filename, ccolor ) CLASS TBarCode + + ::Create(sx, sy) + + DEFAULT ccolor TO {255,255,255} + + ::setcolor( ccolor[1], ccolor[2], ccolor[3] ) + + ::error := 0 + ::positionY := 0 + ::imWidth := sx + + if !empty( filename ) + ::filename := filename + endif + + ::FillColor := ::setcolor( ::color_f[1] ,::color_f[2] ,::color_f[3] ) + ::BackColor := ::setcolor( ::color_b[1] ,::color_b[2] ,::color_b[3] ) + + ::Setfont("Arial") + + // configures Fontes + If ::textfont == 1 ; ::SetFontSmall() + ElseIf ::textfont == 2 ; ::SetFontLarge() + ElseIf ::textfont == 3 ; ::SetFontMediumBold() + ElseIf ::textfont == 4 ; ::SetFontGiant() + ElseIf ::textfont == 5 ; ::SetFontTiny() + EndIf + + ::SetFontPitch(::textfont) + + // always restores + ::maxHeight := ::maxHDefa + +Return Self + +METHOD Configure( nmaxHeight, aFillColor, aBackColor, nres, ntextfont, lbook, lDrawValue ) CLASS TBarCode + + DEFAULT lbook TO .F. + DEFAULT lDrawValue TO .T. + DEFAULT nmaxHeight TO 25 + DEFAULT ntextfont TO 2 + DEFAULT nres TO 2 + DEFAULT aBackColor TO {255,255,255} + DEFAULT aFillColor TO {0,0,0} + + ::book := lbook + ::maxHeight := nmaxHeight + ::res := nres + ::textfont := ntextfont + ::lDrawValue := lDrawValue + + ::color_b := aClone(aBackColor) + ::color_f := aClone(aFillColor) + + +RETURN NIL + +METHOD SetText( ptext ) CLASS TBarCode + + ::text := ptext + +Return NIL + +METHOD ResetColor() CLASS TBarCode + + ::FillColor := ::setcolor( ::color_f[1] ,::color_f[2] ,::color_f[3] ) + ::BackColor := ::setcolor( ::color_b[1] ,::color_b[2] ,::color_b[3] ) + +Return NIL + +METHOD Allocate() CLASS TBarCode + + LOCAL R := ::color_b[1] + LOCAL G := ::color_b[2] + LOCAL B := ::color_b[3] + +Return ::SetColor(R,G,B) + +METHOD DrawSingleBar( pcode ) CLASS TBarCode + + LOCAL i := 0 + LOCAL j := 0 + + For j := 1 To Len( pcode ) + + For i := 1 TO ::res + ::Line( ::positionX + i , ::positionY , ::positionX + i , (::positionY+::maxHeight) ,; + If( SubStr(pcode,j,1) $ "0", ::BackColor, ::FillColor ) ) + Next + + ::NextX() + + Next + +Return NIL + +METHOD DrawSingleI25( pcode ) CLASS TBarCode + + LOCAL i := 0 + LOCAL j := 0 + + LOCAL widthSlimBar := 1 + LOCAL widthFatBar := 3 + + LOCAL imgBar + LOCAL imgWid + LOCAL end_y + LOCAL qw + + ::positionX := 10 + + For j := 1 To Len( pcode ) + + imgBar := If( j % 2 == 0, ::FillColor, ::BackColor ) + imgWid := If( SubStr(pcode,j,1) =="0" , widthSlimBar, widthFatBar ) + + end_y := ::maxHeight + + For qw := 1 TO imgWid + ::Line( ::positionX, 1, ::positionX, end_y, imgBar) + ::nextX(.T.) + Next + + Next + +Return NIL + + +METHOD DrawError(ptext) CLASS TBarCode + + ::Say( 5, ::error*15, ptext, ::FillColor ) + + ::error++ + + ::lastX := If( (::GetFontWidth()*Len(ptext) ) > ::lastX , ( ::GetFontWidth()*Len(ptext)) , ::lastX ) + ::lastY := ::error*15 + +Return NIL + +METHOD nextX(lI25) CLASS TBarCode + + DEFAULT li25 TO .F. + + If li25 + ::positionX ++ + Else + ::positionX += ::res + EndIf + +Return NIL + +METHOD DrawText(lIsI25) CLASS TBarCode + + LOCAL xPosition + + DEFAULT lIsI25 TO .F. + + If lIsI25 + If( ::textfont != 0 ) + xPosition := 10 * ::GetFontWidth() + ::say( xPosition, ::maxHeight, "*" + ::text + "*" , ::FillColor ) + ::lastY := ::maxHeight + ::GetFontHeight() + EndIf + Else + If( ::textfont != 0 ) + xPosition := ( ::positionX / 2) - ( Len( ::text ) /2 ) * ::GetFontWidth() + ::say( xPosition, ::maxHeight, ::text, ::FillColor ) + ::lastY := ::maxHeight + ::GetFontHeight() + EndIf + EndIf + +Return .T. + +METHOD CheckCode() CLASS TBarCode + + LOCAL lRet := .T. + LOCAL i + + For i := 1 To Len( ::text ) + If( !IsInt( ::CheckValInArray( ::text[i] ) ) ) + ::DrawError("Character "+::text[i]+" not allowed .") + lRet := .F. + EndIf + Next + +Return lRet + +METHOD CheckValInArray(cchar) CLASS TBarCode + + LOCAL npos + LOCAL uret + + npos := ASCAN( ::keys, { |x| x[1]== cchar } ) + + If npos > 0 + uret := npos + Else + uret := NIL + EndIf + +Return uret + +METHOD Finish( image_style, quality, nFG ) CLASS TBarCode + + DEFAULT image_style TO IMG_FORMAT_PNG + DEFAULT quality TO 95 + DEFAULT nFG TO {255,255,255} + + If Empty( ::filename ) .OR. ::filename = NIL + ::filename := ::text + EndIf + + If image_style == IMG_FORMAT_PNG + + ::SavePng( ::filename ) + + Elseif image_style == IMG_FORMAT_JPEG + + ::Savejpeg( ::filename, quality ) + + ElseIf image_style == IMG_FORMAT_WBMP + + ::SaveWBmp( ::filename, nFG ) + + ElseIf image_style == IMG_FORMAT_GIF + + ::SaveGif( ::filename ) + + EndIf + +Return .T. + +FUNCTION IsInt( pvar ) + + If Valtype( pvar ) == "C" + Return .F. + EndIf + +Return .T. diff --git a/harbour/contrib/gd/gdbarcod.prg b/harbour/contrib/gd/gdbarcod.prg new file mode 100644 index 0000000000..ff79e47936 --- /dev/null +++ b/harbour/contrib/gd/gdbarcod.prg @@ -0,0 +1,694 @@ +/* + * xHarbour Project source code: + * CodeBar engine library class + * + * Copyright 2005-2005 Laverson Espíndola + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ +#include "hbclass.ch" +#include "common.ch" + +#define CODEC 100 +#define CODEB 101 +#define CODEA 102 +#define FNC1 103 +#define STARTA 104 +#define STARTB 105 +#define STARTC 106 + +CLASS TCode FROM TBarCode + + DATA nType + + // EAN-13 ISBN + METHOD New( nType ) CONSTRUCTOR + METHOD Draw( cText ) + + METHOD Draw13( cText ) + METHOD DrawText13() + + // EAN-8 + METHOD Draw8( cText ) + METHOD DrawText8() + + // EAN-128 + METHOD Draw128( cText, cModeCode ) + + // I25 + METHOD DrawI25( cText ) + METHOD GenCodei25() + + // Utils + METHOD FindCharCode( cstring, cchar ) + METHOD MixCode(bar_string) + METHOD Findcode( uval ) + +ENDCLASS + +METHOD New( nTypeCode ) CLASS TCode + + Local ii + + If ( nTypeCode == 13 .OR.; + nTypeCode == 8 ) + + ::LeftHand_Odd := {"0011001", "0010011", "0111101", "0100011", "0110001", "0101111", "0111011", "0110111", "0001011","0001101"} + ::LeftHand_Even := {"0110011", "0011011", "0100001", "0011101", "0111001", "0000101", "0010001", "0001001", "0010111","0100111"} + ::Right_Hand := {"1100110", "1101100", "1000010", "1011100", "1001110", "1010000", "1000100", "1001000", "1110100","1110010"} + ::Parity := {"OOEOEE", "OOEEOE", "OOEEEO", "OEOOEE", "OEEOOE", "OEEEOO", "OEOEOE", "OEOEEO", "OEEOEO","OOOOOO" } + ::keys := {'1','2','3','4','5','6','7','8','9','0'} + + ElseIf nTypeCode == 128 // 128 + + ::aCode :={ "212222","222122","222221","121223","121322","131222","122213","122312","132212","221213",; + "221312","231212","112232","122132","122231","113222","123122","123221","223211","221132",; + "221231","213212","223112","312131","311222","321122","321221","312212","322112","322211",; + "212123","212321","232121","111323","131123","131321","112313","132113","132311","211313",; + "231113","231311","112133","112331","132131","113123","113321","133121","313121","211331",; + "231131","213113","213311","213131","311123","311321","331121","312113","312311","332111",; + "314111","221411","431111","111224","111422","121124","121421","141122","141221","112214",; + "112412","122114","122411","142112","142211","241211","221114","213111","241112","134111",; + "111242","121142","121241","114212","124112","124211","411212","421112","421211","212141",; + "214121","412121","111143","111341","131141","114113","114311","411113","411311","113141",; + "114131","311141","411131","211412","211214","211232","2331112"; + } + + ::KeysmodeA := " " + [!"#$%&\()*+-.,/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ] + "[\]^_" + ::KeysmodeB := " " + [!"#$%&\()*+-.,/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ] + "[\]^_abcdefghijklmnopqrstuvwxyz{|}~" + + ::KeysModeC := Array(99) + + For ii := 1 TO 99 + ::KeysmodeC[ii] := StrZero(ii,2) + Next + + ElseIf nTypeCode == 25 + + ::keys := {'1','2','3','4','5','6','7','8','9','0'} + + ::aCode := Array(12) + + ::aCode[1] := "10001" //1 digit + ::aCode[2] := "01001" //2 digit + ::aCode[3] := "11000" //3 digit + ::aCode[4] := "00101" //4 digit + ::aCode[5] := "10100" //5 digit + ::aCode[6] := "01100" //6 digit + ::aCode[7] := "00011" //7 digit + ::aCode[8] := "10010" //8 digit + ::aCode[9] := "01010" //9 digit + ::aCode[10] := "00110" //0 digit + ::acode[11] := "10000" //pre-amble + ::acode[12] := "100" //post-amble + + Else + + Alert(" Invalid type to barcode !") + + Return NIL + + EndIf + + ::nType := nTypeCode + +Return SELF + +METHOD Draw( cText ) CLASS TCode + + if ::nType == 13 + ::Draw13( cText ) + elseif ::nType == 8 + ::Draw8( cText ) + elseif ::nType == 128 + ::Draw128( cText ) + elseif ::nType == 25 + ::DrawI25( cText ) + endif + +Return NIL + +METHOD Draw13(cText) CLASS TCode + + LOCAL lerror := .f. + LOCAL nchkSum :=0 + LOCAL nChk :=0 + LOCAL ii,jj + LOCAL xParity + + ::Settext( ctext ) + + // Valid characters + If !::CheckCode() + lerror := .T. + EndIf + + If !lerror + + If( ::book .AND. Len( ::text) != 10 ) + ::DrawError("Must contains 10 chars if ISBN is true.") + lerror = .T. + EndIf + + // book, we changed the code to the right + If ( ::book .And. Len( ::text )==10 ) + ::text := "978"+substr(::text,1, Len( ::text )-1 ) + EndIF + + // contain only 12 characters ? + If Len( ::text ) != 12 + ::DrawError( "Must contains 12 chars, the 13th digit is automatically added.") + lerror = .t. + EndIf + + If !lerror + + // If we have to write text, we moved the barcode to the right to have space to put digit + ::positionX = If( ::textfont == 0 , 0, 10 ) + + xParity := ::Parity[ Val( ::text[1] ) ] + + // First Bar + ::positionX := 10 + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("101") + + // start code + ::maxHeight := ::maxHeight - 9 + + For ii := 1 To Len( ::text ) + + // Calculate check digit + If Mod( ((Len(::text) + 1) - ii), 2 ) = 0 + nchkSum := nchkSum + Int( Val( Substr(::text , ii, 1) ) ) + Else + nchkSum := nchkSum + Int( Val( Substr( ::text , ii, 1) ) ) * 3 + EndIf + + // ANow, the bar of the middle + If ii = 8 + ::positionX += 1 + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("101") + ::maxHeight := ::maxHeight - 9 + ::positionX += 1 + EndIf + + jj := Val( SubStr( ::text, ii, 1) ) + + If jj = 0 + jj := 10 + EndIf + + If ii > 1 .And. ii < 8 + + ::DrawSingleBar( If( Substr(xParity, ii - 1, 1) = "E",; + ::LeftHand_Even[jj],; + ::LeftHand_Odd[jj] ) ) + ElseIf ii > 1 .And. ii >= 8 + + ::DrawSingleBar( ::Right_Hand[jj] ) + + EndIf + + Next + + jj := Mod( nchkSum, 10 ) + + If jj <> 0 + nChk = 10 - jj + EndIf + + If nChk == 0 + nChk := 10 + EndIf + + ::DrawSingleBar( ::Right_Hand[nChk] ) + + // Now, finish bar + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("101") + + ::lastX := ::positionX + ::lastY := ::maxHeight + + ctext+=AllTrim( Str( nChk,1 ) ) + + // Draw Text + If ::lDrawValue + ::Settext( ctext ) + ::DrawText13() + EndIf + + EndIf + + EndIf + +Return NIL + +METHOD DrawText13() CLASS TCode + + if ( ::textfont != 0 ) + + ::Say( 2, ::maxHeight-( ::GetFontHeight() / 2 ),SubStr( ::text,1,1) , ::FillColor ) + ::Say( (10+(3*::res+48*::res)/2)-(::GetFontWidth()*(6/2)),::maxHeight+1,substr(::text,2,6), ::FillColor ) + ::Say( 10+46*::res+(3*::res+46*::res)/2-::GetFontWidth()*(6/2),::maxHeight+1,substr(::text,8,6),::FillColor) + + EndIf + + ::lastY := ::maxHeight + ::GetFontHeight() + +Return NIL + +METHOD Draw8( cText ) CLASS TCode + + LOCAL lerror := .f. + LOCAL ii,jj + LOCAL xParity + LOCAL nchkSum := 0 + LOCAL nChk := 0 + + ::Settext( ctext ) + + // Valid characters + If !::CheckCode() + lerror := .T. + EndIf + + If !lerror + + ::positionX = If( ::textfont == 0 , 0, 10 ) + + xParity := ::Parity[ 7 ] + + // First Bar + ::positionX := 10 + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("101") + + // Start Code + ::maxHeight := ::maxHeight - 9 + + For ii = 1 To Len(::text) + + If Mod( ((Len(::text) + 1 ) - ii ), 2 ) = 0 + nchkSum := nchkSum + Int( Val(Substr( ::text, ii, 1) ) ) + Else + nchkSum := nchkSum + Int( Val(Substr( ::text, ii, 1) ) ) * 3 + EndIf + + If ii = 5 + ::positionX += 1 + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("01010") + ::maxHeight := ::maxHeight - 9 + ::positionX += 1 + EndIf + + jj := Val( SubStr( ::text, ii, 1) ) + + If jj == 0 + jj := 10 + EndIf + + If ii < 5 + ::DrawSingleBar( ::LeftHand_Odd[jj] ) + ElseIf ii >= 5 + ::DrawSingleBar( ::Right_Hand[jj] ) + EndIf + + Next + + jj := Mod( nchkSum, 10 ) + + If jj <> 0 + nChk = 10 - jj + EndIf + + ::DrawSingleBar(::Right_Hand[nChk]) + + // Now, finish bar + ::maxHeight := ::maxHeight + 9 + ::DrawSingleBar("101") + + ::lastX := ::positionX + ::lastY := ::maxHeight + + ctext+=AllTrim( Str( nChk,1 ) ) + + // Draw text + If ::lDrawValue + ::Settext( ctext ) + ::DrawText8() + EndIf + + + EndIf + +Return NIL + +METHOD DrawText8() CLASS TCode + + ::say( 10+( (3*::res+34*::res)/2-::GetFontWidth()*(4/2) ),::maxHeight+1, substr( ::text,1,4 ),::fillcolor) + ::say(10+(32*::res+(3*::res+32*::res)/2-::GetFontWidth()*(4/2)),::maxHeight+1,substr(::text,5,4),::fillcolor) + + ::lastY := ::maxHeight + ::GetFontHeight() + +Return NIL + +METHOD FIndCharCode( cstring, cchar ) CLASS TCode + + LOCAL i + LOCAL nC := 0 + LOCAL nret := 0 + + FOR i := 1 TO Len( cstring ) + + If SubStr( cstring, i, 1 ) == cchar + ++nC + nRet := nC + EXIT + EndIf + + ++nC + + NEXT + +Return nret + +METHOD Draw128( cText, cModeCode ) CLASS TCode + + Local cchar, nvalchar, n, i + + Local nSum := 0 + Local nC := 0 + LOCAL npos := 0 + LOCAL value_test := 0 + Local lTypeCodeC := .F. + Local lTypeCodeA := .F. + LOCAL lerror := .F. + Local cBarCode := "" + Local cconc := "" + + DEFAULT cModeCode TO "B" + + ::settext( cText ) + + If !Empty( cModeCode ) + If valtype(cModeCode)='C' .and. Upper(cModeCode) $'ABC' + cModeCode := Upper(cModeCode) + Else + ::DrawError("Code 128 Modes are A,B o C. Character values.") + lerror := .T. + EndIf + EndIf + + // Checking if all chars are allowed + For i := 1 TO Len( ::text ) + + If cModeCode == "C" + + npos := AsCAn( ::KeysmodeC, { |x| x ==::Text[i]+::Text[i+1] } ) + + If npos == 0 + ::DrawError("With Code C, you must provide always pair of two integers. Char "+::text[i]+::text[i+1]+" not allowed." ) + lerror := .T. + EndIf + + ElseIf cModeCode == "B" + + If ::FIndCharCode( ::KeysmodeB, ::Text[i] ) == 0 + ::DrawError('Char '+::text[i]+" not allowed.") + lerror = .T. + EndIf + + ElseiF cModeCode == "A" + + If ::FIndCharCode( ::KeysmodeA, ::text[i] ) == 0 + ::DrawError('Char '+::text[i]+" not allowed.") + lerror := .T. + EndIf + + EndIf + + Next + + If !lerror + + If Empty(cModeCode) + + If Str( Val( ::text ), Len( ::text ) ) = ::text + + lTypeCodeC := .T. + cconc := ::aCode[ STARTC ] + nSum := STARTB + + Else + + For n := 1 TO Len( ::text ) + nC += If( substr( ::text ,n,1 ) > 31, 1, 0 ) + Next + + If nC < Len( ::text ) / 2 + lTypeCodeA:= .t. + cconc := ::aCode[STARTA] + nSum := FNC1 + Else + cconc := ::aCode[STARTB] + nSum := STARTA + EndIf + + EndIf + + Else + + If cModeCode =='C' + + lTypeCodeC := .T. + cconc := ::aCode[STARTC] + nSum := STARTB + + Elseif cModeCode =='A' + + lTypeCodeA := .t. + cconc := ::aCode[STARTB] + nSum := FNC1 + + Else + + cconc := ::aCode[STARTB] + nSum := STARTA + + EndIf + + EndIf + + nC := 0 + + For n := 1 To Len( ::text ) + + nC ++ + + cchar := Substr(::text,n,1) + + if lTypeCodeC + + If Len( ::TEXT ) = n + cconc += ::aCode[101] + nvalchar := Asc(cchar)-31 + Else + nvalchar := Val(Substr( ::text,n,2 ) ) + 1 + n++ + EndIf + + Elseif lTypeCodeA + + If cchar > '_' + cconc += ::aCode[101] + nvalchar := Asc(cchar)-31 + Elseif cchar <= ' ' + nvalchar := Asc(cchar)+64 + Else + nvalchar := Asc(cchar)-31 + Endif + + Else + + If cchar < ' ' + cconc += ::aCode[CODEA] + nvalchar := Asc(cchar)+64 + Else + nvalchar := Asc(cchar)-31 + EndIf + + Endif + nSum += (nvalchar-1)*nC + cconc := cconc +::aCode[nvalchar] + + next + + nSum := nSum%103 +1 + cconc := cconc + ::aCode[ nSum ] +::aCode[107] + + For n:=1 To Len(cconc) STEP 2 + cBarCode +=Replicate('1', Val( Substr( cconc, n,1 ) ) ) + cBarCode +=Replicate('0', Val( substr( cconc, n+1,1 ) ) ) + Next + + ::DrawSingleBar( cBarCode ) + + ::lastX := ::positionX + ::lastY := ::maxHeight + + // Draw Text + If ::lDrawValue + ::Settext( ctext ) + ::DrawText() + EndIf + + EndIf + +Return NIL + +METHOD DrawI25( cText ) CLASS TCode + + ::settext( cText ) + + ::GenCodei25() + +Return NIL + +METHOD GenCodei25() CLASS TCode + + LOCAL lError := .F. + LOCAL bc_string := ::text + LOCAL new_string := "" + + If ( Len(::text) % 2 )!= 0 + ::DrawError("Invalid barcode lenght") + lError := .T. + Endif + + If !lError + + bc_string = upper( ::text ) + + // encode itemId to I25 barcode standard. ////////////////////////////////////// + + bc_string = ::MixCode( bc_string ) + + /////////////////////////////////////////////////////////////////////////////////////////////// + //Adding Start and Stop Pattern + + ::DrawSingleI25( ::acode[11] + bc_string + ::acode[12] ) + + ::lastY := ::maxHeight + + // Draw Text + If ::lDrawValue + ::DrawText(.T.) + EndIf + + EndIf + +Return NIL + +/* + It makes mixe of the value to be codified by the Bar code I25 +*/ +METHOD MixCode(value) CLASS TCode + + LOCAL l,i,k + LOCAL s + LOCAL bar_string := "" + LOCAL cfirst + LOCAL cnext + + l := Len( value ) + + If ( l % 2 ) != 0 + ::DrawError("Code cannot be intercalated: Invalid length (mix)") + Else + + i := 1 + s := "" + + While i < l + + cFirst := ::Findcode( value[i] ) + cnext := ::Findcode( value[i+1] ) + + // Mix of the codes + // NNNNWNNWWW + // N N N W W + For k := 1 TO 5 + s += cFirst[k] + cnext[k] + Next + + i += 2 + + EndDo + + bar_string := s + + EndIf + +Return bar_string + +METHOD Findcode( uval ) CLASS TCode + + LOCAL npos + LOCAL cretc + + npos := AsCan( ::keys, { |x| x[1] == uval } ) + cretc := ::acode[npos] + +Return cretc +/* +EOF +*/ diff --git a/harbour/contrib/gd/gdchart.prg b/harbour/contrib/gd/gdchart.prg new file mode 100644 index 0000000000..dbf58c7640 --- /dev/null +++ b/harbour/contrib/gd/gdchart.prg @@ -0,0 +1,889 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * GD graphic library chart class + * + * Copyright 2004-2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + + +#include "common.ch" +#include "hbclass.ch" +#include "gd.ch" + +#define DEFAULT( x, y ) IIF( x == NIL, x := y, ) + +CLASS GDChart FROM GDImage + + DATA cTitle + DATA cAxisX + DATA cAxisY + DATA nWidth + DATA nHeight + DATA nScaleX + DATA nScaleY + + DATA aSeries + DATA aDataOfHashes // Hash contains graph datas + DATA hDefs + + + METHOD New( sx, sy ) CONSTRUCTOR + METHOD AddData() + METHOD AddDef() + METHOD SetData() + METHOD SetDefs() + + METHOD PieChart() + METHOD VerticalBarChart() + METHOD HorizontalBarChart() + METHOD LineChart() + +ENDCLASS + +METHOD New( sx, sy ) CLASS GDChart + + DEFAULT sx TO 320 + DEFAULT sy TO 200 + + ::cTitle := "Chart" + ::aSeries := {} + ::hDefs := Hash() + ::aDataOfHashes := {} + + ::Create( sx, sy ) +RETURN Self + +METHOD AddData( hData ) CLASS GDChart + IF ValType( hData ) == "H" + aAdd( ::aDataOfHashes, hData ) + ENDIF +RETURN Self + +METHOD SetData( aData ) CLASS GDChart + IF ValType( aData ) == "A" + ::aDataOfHashes := aData + ENDIF +RETURN Self + +METHOD AddDef( cDefKey, xDefVal ) CLASS GDChart + IF ValType( cDefKey ) == "C" + hSet( ::hDefs, Upper( cDefKey ), xDefVal ) + ENDIF +RETURN Self + +METHOD SetDefs( hDefs ) CLASS GDChart + IF ValType( hDefs ) == "H" + ::hDefs := hDefs + ENDIF +RETURN Self + +METHOD PieChart() CLASS GDChart + LOCAL hElement, nTot := 0 + LOCAL nDegree := 0 + LOCAL lFilled, lExtruded, nExtrude, nTotExtr := 0, pTile + LOCAL colorp + LOCAL nVal, nDim + LOCAL nPosX, nPosY + LOCAL cLabel, hFont, cFontName, nPitch, nAngle, textcolor + LOCAL x, y, nWidth + LOCAL aPieDataOfHash, hDefs + LOCAL cFontPitch + + aPieDataOfHash := ::aDataOfHashes + hDefs := ::hDefs + + x := HGetValue( hDefs, "POSX" ) + y := HGetValue( hDefs, "POSY" ) + nWidth := HGetValue( hDefs, "WIDTH" ) + cFontPitch := HGetValue( hDefs, "FONTPITCH" ) + + DEFAULT x TO ::CenterWidth() + DEFAULT y TO ::CenterHeight() + DEFAULT nWidth TO Min( ::Width(), ::Height() ) + DEFAULT cFontPitch TO "TINY" + + DO CASE + CASE cFontPitch == "TINY" + ::SetFontTiny() + CASE cFontPitch == "SMALL" + ::SetFontSmall() + CASE cFontPitch == "MEDIUM" + ::SetFontMediumBold() + CASE cFontPitch == "LARGE" + ::SetFontLarge() + CASE cFontPitch == "GIANT" + ::SetFontGiant() + ENDCASE + + //__OutDebug( "x, y, nWidth", x, y, nWidth ) + + + /* + hData := ["TITLE"], ["VALUE"], ["FILLED"], ["COLOR"], ["TILE"], ["EXTRUDE"] + */ + + // Before sum of values to determine perentual + FOR EACH hElement IN aPieDataOfHash + nTot += hElement["VALUE"] + // Check extrution + IF ( nExtrude := HGetValue( hElement, "EXTRUDE" ) ) <> NIL + nTotExtr := Max( nTotExtr, nExtrude ) + ENDIF + NEXT + + nWidth -= ( nTotExtr + 2 ) * 2 + + //__OutDebug( "nTotExtr, nWidth", nTotExtr, nWidth ) + + // Second, + FOR EACH hElement IN aPieDataOfHash + cLabel := HGetValue( hElement, "LABEL" ) + lFilled := HGetValue( hElement, "FILLED" ) + nExtrude := HGetValue( hElement, "EXTRUDE" ) + pTile := HGetValue( hElement, "TILE" ) + IF nExtrude <> NIL + lExtruded := TRUE + ELSE + lExtruded := FALSE + ENDIF + colorp := HGetValue( hElement, "COLOR" ) + nVal := hElement["VALUE"] + nDim := 360 * ( ( nVal / nTot ) * 100 ) / 100 + DEFAULT lFilled TO FALSE + DEFAULT nExtrude TO 0 + DEFAULT colorp TO ::SetColor( 0, 0, 0 ) + IF lExtruded + nPosX := x + nExtrude * cos(::Radians( nDegree + nDim / 2 )) + nPosY := y + nExtrude * sin(::Radians( nDegree + nDim / 2 )) + ELSE + nPosX := x + nPosY := y + ENDIF + IF pTile <> NIL + ::SetTile( pTile ) + colorp := gdTiled + ELSE + if ISARRAY( colorp ) + colorp := ::SetColor( colorp[1], colorp[2], colorp[3] ) + endif + ENDIF + IF lFilled + ::Arc( nPosX, nPosY, nWidth, nWidth, nDegree, nDegree + nDim, TRUE, colorp, gdPie ) + ELSE + ::Arc( nPosX, nPosY, nWidth, nWidth, nDegree, nDegree + nDim, TRUE, colorp, gdNoFill + gdEdged ) + ENDIF + IF cLabel <> NIL + //hFont := HGetValue( hElement, "FONT" ) + //IF hFont == NIL + // ::SetFontMediumBold() + cFontName := NIL + nPitch := NIL + nAngle := NIL + textcolor := NIL + //ELSE + // cFontName := HGetValue( hFont, "NAME" ) + // nPitch := HGetValue( hFont, "PITCH" ) + // nAngle := HGetValue( hFont, "ANGLE" ) + // textcolor := HGetValue( hFont, "COLOR" ) + // DEFAULT cFontName TO "Arial" + // DEFAULT nPitch TO 8 + // DEFAULT nAngle TO 0 + //ENDIF + nPosX := nPosX + ( (nExtrude + nWidth) / 4 ) * cos(::Radians( nDegree + nDim / 2 )) + nPosY := nPosY + ( (nExtrude + nWidth) / 4 ) * sin(::Radians( nDegree + nDim / 2 )) + IF textcolor == NIL + colorp := ::GetPixel( nPosX, nPosY ) + textcolor := ::SetColor( 255 - ::Red( colorp ), 255 - ::Green( colorp ), 255 - ::Blue( colorp ) ) + ENDIF + //cTitle := LTrim( Str( nVal ) ) + IF hFont == NIL + ::Say( nPosX, nPosY, cLabel, textcolor, gdAlignCenter ) + ELSE + ::SayFreeType( nPosX, nPosY, cLabel, cFontName, nPitch, nAngle, textcolor, gdAlignCenter ) + ENDIF + ENDIF + + nDegree += nDim + 0.1 + NEXT +RETURN Self + +METHOD VerticalBarChart() CLASS GDChart + LOCAL hElement, nTot := 0 + LOCAL nDegree := 0 + LOCAL lFilled, lExtruded, nExtrude, pTile + LOCAL colorp + LOCAL nVal, nDim + LOCAL nPosX, nPosY + LOCAL nSize, nMax + LOCAL nBorder, nThick, n + LOCAL x, y, nWidth, nHeight, nMaxValue, color, nMaxLabel, cLabel + LOCAL lShowAxis, lShowGrid + + LOCAL nLeftLabelSpace //:= 40 + LOCAL nRightLabelSpace //:= 40 + LOCAL nBottomLabelSpace //:= 40 + LOCAL nTopLabelSpace := 40 + LOCAL lShowLabelLeft := TRUE + LOCAL lShowLabelRight := TRUE //FALSE + LOCAL lShowLabelBottom := TRUE + LOCAL lShowLabelTop := FALSE + LOCAL cAxisPict + LOCAL cFontPitch + + LOCAL aDataOfHash, hDefs + + aDataOfHash := ::aDataOfHashes + hDefs := ::hDefs + + x := HGetValue( hDefs, "POSX" ) + y := HGetValue( hDefs, "POSY" ) + nWidth := HGetValue( hDefs, "WIDTH" ) + nHeight := HGetValue( hDefs, "HEIGHT" ) + nMaxValue := HGetValue( hDefs, "MAXVALUE" ) + color := HGetValue( hDefs, "COLOR" ) + lShowAxis := HGetValue( hDefs, "SHOWAXIS" ) + lShowGrid := HGetValue( hDefs, "SHOWGRID" ) + cAxisPict := HGetValue( hDefs, "AXISPICT" ) + cFontPitch := HGetValue( hDefs, "FONTPITCH" ) + + DEFAULT x TO 0 + DEFAULT y TO 0 + DEFAULT nWidth TO ::Width() + DEFAULT nHeight TO ::Height() + DEFAULT color TO ::GetColor() + DEFAULT lShowAxis TO TRUE + DEFAULT lShowGrid TO TRUE + DEFAULT cAxisPict TO "@E 9,999.99" + DEFAULT cFontPitch TO "TINY" + + DEFAULT nBorder TO 4 + + /* + hData := ["TITLE"], ["VALUE"], ["FILLED"], ["COLOR"], ["TILE"], ["EXTRUDE"] + */ + + DO CASE + CASE cFontPitch == "TINY" + ::SetFontTiny() + CASE cFontPitch == "SMALL" + ::SetFontSmall() + CASE cFontPitch == "MEDIUM" + ::SetFontMediumBold() + CASE cFontPitch == "LARGE" + ::SetFontLarge() + CASE cFontPitch == "GIANT" + ::SetFontGiant() + ENDCASE + + + + // Before sum of values to determine perentual + nMaxLabel := 0 + nMax := 0 + FOR EACH hElement IN aDataOfHash + IF HB_EnumIndex() == 1 + nMax := hElement["VALUE"] + ELSE + nMax := Max( nMax, hElement["VALUE"] ) + ENDIF + cLabel := HGetValue( hElement, "LABEL" ) + nMaxLabel := Max( nMaxLabel, Len( IIF( cLabel <> NIL, cLabel, "" ) ) ) + nTot += hElement["VALUE"] + NEXT + + //__OutDebug( "Len( LTrim( Str( nMax ) ) )", Len( LTrim( cStr( nMax ) ) ), Str( nMax ) ) + + DEFAULT nLeftLabelSpace TO nBorder + Len( LTrim( Transform( nMax, cAxisPict ) ) ) * ::GetFontWidth() + nBorder + DEFAULT nRightLabelSpace TO nLeftLabelSpace //nBorder + Len( LTrim( Str( nMax ) ) ) * ::GetFontWidth() + nBorder + DEFAULT nBottomLabelSpace TO nBorder + nMaxLabel * ::GetFontWidth() + nBorder + DEFAULT nMaxValue TO nMax + + IF lShowAxis + IF lShowLabelLeft + x += nLeftLabelSpace + nWidth -= nLeftLabelSpace + ENDIF + IF lShowLabelRight + nWidth -= nRightLabelSpace + ENDIF + IF lShowLabelBottom + y += nBottomLabelSpace + nHeight -= nBottomLabelSpace + ENDIF + IF lShowLabelTop + nHeight -= nTopLabelSpace + ENDIF + ENDIF + + nSize := nWidth / Len( aDataOfHash ) + + IF lShowGrid + ::Rectangle( x, ::Height() - ( y + nHeight ), x + nWidth, ::Height() - y, FALSE, color ) + + nThick := ::SetThickness( 1 ) + + ::ResetStyles() + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::SetStyle() + FOR n := 10 TO 100 STEP 10 + nDim := ( ( nMaxValue / 100 ) * n ) + nPosY := ( nDim / nMaxValue ) * nHeight + //__OutDebug( "nDim", nDim ) + ::Line( x, ::Height() - ( y + nPosY), x + nWidth, ::Height() - ( y + nPosY ), gdStyled ) + NEXT + ::SetThickness( nThick ) + ENDIF + IF lShowAxis + // Y Axis + FOR n := 10 TO 100 STEP 10 + nDim := ( ( nMaxValue / 100 ) * n ) + cLabel := LTrim( Transform( nDim, cAxisPict ) ) + nPosY := ( nDim / nMaxValue ) * nHeight + IF lShowLabelLeft + ::Say( x - nLeftLabelSpace + nBorder, ::Height() - ( y + nPosY ), PadL( cLabel, Len( LTrim( Transform( nMaxValue, cAxisPict ) ) ) ), color ) + ENDIF + IF lShowLabelRight + ::Say( x + nWidth + nBorder, ::Height() - ( y + nPosY ), cLabel, color ) + ENDIF + NEXT + ENDIF + + // Second, + FOR EACH hElement IN aDataOfHash + cLabel := HGetValue( hElement, "LABEL" ) + lFilled := HGetValue( hElement, "FILLED" ) + nExtrude := HGetValue( hElement, "EXTRUDE" ) + pTile := HGetValue( hElement, "TILE" ) + IF nExtrude <> NIL + lExtruded := TRUE + ELSE + lExtruded := FALSE + ENDIF + colorp := HGetValue( hElement, "COLOR" ) + nVal := hElement["VALUE"] + nDim := ( nVal / nMaxValue ) * nHeight + + DEFAULT lFilled TO FALSE + DEFAULT nExtrude TO 0 + DEFAULT colorp TO ::SetColor( 0, 0, 0 ) + + nPosX := x + ( nSize * ( HB_EnumIndex() - 1 ) ) + nPosY := y + IF pTile <> NIL + ::SetTile( pTile ) + colorp := gdTiled + ELSE + if ISARRAY( colorp ) + colorp := ::SetColor( colorp[1], colorp[2], colorp[3] ) + endif + ENDIF + ::Rectangle( nPosX + nBorder, ::Height() - ( nPosY + nDim ), nPosX + nSize - nBorder, ::Height() - nPosY, lFilled, colorp ) + + IF lShowAxis + // Y Axis + IF lShowLabelBottom + ::SayVertical( nPosX + nSize / 2 - ::GetFontHeight() / 2, ::Height() - nBorder, PadL( cLabel, nMaxLabel ), color ) + ENDIF + ENDIF + + NEXT +RETURN Self + +METHOD HorizontalBarChart() CLASS GDChart + LOCAL hElement, nTot := 0 + LOCAL nDegree := 0 + LOCAL lFilled, lExtruded, nExtrude, pTile + LOCAL colorp + LOCAL nVal, nDim + LOCAL nPosX, nPosY + LOCAL nSize, nMax + LOCAL nBorder, nThick, n + LOCAL x, y, nWidth, nHeight, nMaxValue, color, nMaxLabel, cLabel + LOCAL lShowAxis, lShowGrid + + LOCAL nLeftLabelSpace //:= 40 + LOCAL nRightLabelSpace //:= 40 + LOCAL nBottomLabelSpace //:= 40 + LOCAL nTopLabelSpace //:= 40 + LOCAL lShowLabelLeft := TRUE + LOCAL lShowLabelRight := TRUE + LOCAL lShowLabelBottom := TRUE + LOCAL lShowLabelTop := TRUE + LOCAL cAxisPict + LOCAL cFontPitch + + LOCAL aDataOfHash, hDefs + + aDataOfHash := ::aDataOfHashes + hDefs := ::hDefs + + x := HGetValue( hDefs, "POSX" ) + y := HGetValue( hDefs, "POSY" ) + nWidth := HGetValue( hDefs, "WIDTH" ) + nHeight := HGetValue( hDefs, "HEIGHT" ) + nMaxValue := HGetValue( hDefs, "MAXVALUE" ) + color := HGetValue( hDefs, "COLOR" ) + lShowAxis := HGetValue( hDefs, "SHOWAXIS" ) + lShowGrid := HGetValue( hDefs, "SHOWGRID" ) + cAxisPict := HGetValue( hDefs, "AXISPICT" ) + cFontPitch := HGetValue( hDefs, "FONTPITCH" ) + + DEFAULT x TO 0 + DEFAULT y TO 0 + DEFAULT nWidth TO ::Width() + DEFAULT nHeight TO ::Height() + DEFAULT color TO ::GetColor() + DEFAULT lShowAxis TO TRUE + DEFAULT lShowGrid TO TRUE + DEFAULT cAxisPict TO "@E 9,999.99" + DEFAULT cFontPitch TO "TINY" + + DEFAULT nBorder TO 4 + + /* + hData := ["TITLE"], ["VALUE"], ["FILLED"], ["COLOR"], ["TILE"], ["EXTRUDE"] + */ + + DO CASE + CASE cFontPitch == "TINY" + ::SetFontTiny() + CASE cFontPitch == "SMALL" + ::SetFontSmall() + CASE cFontPitch == "MEDIUM" + ::SetFontMediumBold() + CASE cFontPitch == "LARGE" + ::SetFontLarge() + CASE cFontPitch == "GIANT" + ::SetFontGiant() + ENDCASE + + // Before sum of values to determine perentual + nMaxLabel := 0 + nMax := 0 + FOR EACH hElement IN aDataOfHash + IF HB_EnumIndex() == 1 + nMax := hElement["VALUE"] + ELSE + nMax := Max( nMax, hElement["VALUE"] ) + ENDIF + cLabel := HGetValue( hElement, "LABEL" ) + nMaxLabel := Max( nMaxLabel, Len( IIF( cLabel <> NIL, cLabel, "" ) ) ) + nTot += hElement["VALUE"] + NEXT + DEFAULT nLeftLabelSpace TO nBorder + nMaxLabel * ::GetFontWidth() + nBorder + DEFAULT nRightLabelSpace TO nBorder + ( Len( LTrim( Transform( nMax, cAxisPict ) ) ) * ::GetFontWidth() / 2 ) + DEFAULT nTopLabelSpace TO nBorder + ::GetFontHeight() + nBorder + DEFAULT nBottomLabelSpace TO nTopLabelSpace // nBorder + ::GetFontHeight() + nBorder + DEFAULT nMaxValue TO nMax + + IF lShowAxis + IF lShowLabelLeft + x += nLeftLabelSpace + nWidth -= nLeftLabelSpace + ENDIF + IF lShowLabelRight + nWidth -= nRightLabelSpace + ENDIF + IF lShowLabelBottom + y += nBottomLabelSpace + nHeight -= nBottomLabelSpace + ENDIF + IF lShowLabelTop + nHeight -= nTopLabelSpace + ENDIF + ENDIF + + nSize := nHeight / Len( aDataOfHash ) + + IF lShowGrid + ::Rectangle( x, ::Height() - ( y + nHeight ), x + nWidth, ::Height() - y, FALSE, color ) + + nThick := ::SetThickness( 1 ) + + ::ResetStyles() + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::SetStyle() + FOR n := 10 TO 100 STEP 10 + nDim := ( ( nMaxValue / 100 ) * n ) + nPosX := ( nDim / nMaxValue ) * nWidth + ::Line( x + nPosX, y, x + nPosX, y + nHeight, gdStyled ) + NEXT + ::SetThickness( nThick ) + ENDIF + IF lShowAxis + // X Axis + FOR n := 0 TO 100 STEP 10 + nDim := ( ( nMaxValue / 100 ) * n ) + cLabel := LTrim( Transform( nDim, cAxisPict ) ) + nPosX := ( nDim / nMaxValue ) * nWidth - ( ( Len( cLabel ) / 2 ) * ::GetFontWidth() ) + IF lShowLabelTop + ::Say( x + nPosX, y - nTopLabelSpace + nBorder, cLabel, color ) + ENDIF + IF lShowLabelBottom + ::Say( x + nPosX, y + nHeight + nBorder, cLabel, color ) + ENDIF + NEXT + ENDIF + + // Second, + FOR EACH hElement IN aDataOfHash + cLabel := HGetValue( hElement, "LABEL" ) + lFilled := HGetValue( hElement, "FILLED" ) + nExtrude := HGetValue( hElement, "EXTRUDE" ) + pTile := HGetValue( hElement, "TILE" ) + IF nExtrude <> NIL + lExtruded := TRUE + ELSE + lExtruded := FALSE + ENDIF + colorp := HGetValue( hElement, "COLOR" ) + nVal := hElement["VALUE"] + nDim := ( nVal / nMaxValue ) * nWidth + //__OutDebug( "nDim", nDim ) + DEFAULT lFilled TO FALSE + DEFAULT nExtrude TO 0 + DEFAULT colorp TO ::SetColor( 0, 0, 0 ) + + nPosX := x + nPosY := y + ( nSize * ( HB_EnumIndex() - 1 ) ) + + IF pTile <> NIL + ::SetTile( pTile ) + colorp := gdTiled + ELSE + if ISARRAY( colorp ) + colorp := ::SetColor( colorp[1], colorp[2], colorp[3] ) + endif + ENDIF + ::Rectangle( nPosX, nPosY + nBorder, nPosX + nDim, nPosY + nSize - nBorder, lFilled, colorp ) + + IF lShowAxis + // Y Axis + IF lShowLabelBottom + ::Say( nBorder, nPosY + nSize / 2 - ::GetFontHeight() / 2, PadL( cLabel, nMaxLabel ), color ) + ENDIF + ENDIF + + NEXT +RETURN Self + +METHOD LineChart() CLASS GDChart + LOCAL hElement + LOCAL nDegree := 0 + LOCAL lFilled, lExtruded, nExtrude, pTile + LOCAL colorp + LOCAL nVal, nDim + LOCAL nPosX, nPosY + LOCAL cLabel + LOCAL nSize, nMax, nMin, nTotRange, nCeiling + LOCAL nBorder, nThick, n + LOCAL x, y, nWidth, nHeight, nMaxValue, nMinValue, color, nMaxLabel, nMinLabel + LOCAL lShowAxis, lShowGrid + + LOCAL nLeftLabelSpace //:= 40 + LOCAL nRightLabelSpace //:= 40 + LOCAL nBottomLabelSpace //:= 40 + LOCAL nTopLabelSpace := 40 + LOCAL lShowLabelLeft := TRUE + LOCAL lShowLabelRight := TRUE //FALSE + LOCAL lShowLabelBottom := TRUE + LOCAL lShowLabelTop := FALSE + LOCAL cAxisPict + LOCAL cFontPitch + + LOCAL aDataOfHash, hDefs, aPoints + + aDataOfHash := ::aDataOfHashes + hDefs := ::hDefs + + x := HGetValue( hDefs, "POSX" ) + y := HGetValue( hDefs, "POSY" ) + nWidth := HGetValue( hDefs, "WIDTH" ) + nHeight := HGetValue( hDefs, "HEIGHT" ) + nMaxValue := HGetValue( hDefs, "MAXVALUE" ) + nMinValue := HGetValue( hDefs, "MINVALUE" ) + color := HGetValue( hDefs, "COLOR" ) + lShowAxis := HGetValue( hDefs, "SHOWAXIS" ) + lShowGrid := HGetValue( hDefs, "SHOWGRID" ) + cAxisPict := HGetValue( hDefs, "AXISPICT" ) + cFontPitch := HGetValue( hDefs, "FONTPITCH" ) + + DEFAULT x TO 0 + DEFAULT y TO 0 + DEFAULT nWidth TO ::Width() + DEFAULT nHeight TO ::Height() + DEFAULT color TO ::GetColor() + DEFAULT lShowAxis TO TRUE + DEFAULT lShowGrid TO TRUE + DEFAULT cAxisPict TO "@E 9,999.99" + DEFAULT cFontPitch TO "TINY" + + DEFAULT nBorder TO 4 + + /* + hData := ["TITLE"], ["VALUE"], ["FILLED"], ["COLOR"], ["TILE"], ["EXTRUDE"] + */ + + DO CASE + CASE cFontPitch == "TINY" + ::SetFontTiny() + CASE cFontPitch == "SMALL" + ::SetFontSmall() + CASE cFontPitch == "MEDIUM" + ::SetFontMediumBold() + CASE cFontPitch == "LARGE" + ::SetFontLarge() + CASE cFontPitch == "GIANT" + ::SetFontGiant() + ENDCASE + + // Before sum of values to determine percentual + nMaxLabel := 0 + nMax := 0 + FOR EACH hElement IN aDataOfHash + IF HB_EnumIndex() == 1 + nMax := hElement["VALUE"] + ELSE + nMax := Max( nMax, hElement["VALUE"] ) + ENDIF + cLabel := HGetValue( hElement, "LABEL" ) + nMaxLabel := Max( nMaxLabel, Len( IIF( cLabel <> NIL, cLabel, "" ) ) ) + NEXT + + // Before sum of values to determine percentual + nMinLabel := 0 + nMin := 0 + FOR EACH hElement IN aDataOfHash + IF HB_EnumIndex() == 1 + nMin := hElement["VALUE"] + ELSE + nMin := Min( nMin, hElement["VALUE"] ) + ENDIF + cLabel := HGetValue( hElement, "LABEL" ) + nMinLabel := Max( nMinLabel, Len( IIF( cLabel <> NIL, cLabel, "" ) ) ) + NEXT + + DEFAULT nLeftLabelSpace TO nBorder + Max( Len( LTrim( Transform( nMax, cAxisPict ) ) ), Len( LTrim( Transform( nMin, cAxisPict ) ) ) ) * ::GetFontWidth() + nBorder + DEFAULT nRightLabelSpace TO nLeftLabelSpace + DEFAULT nBottomLabelSpace TO nBorder + nMaxLabel * ::GetFontWidth() + nBorder + DEFAULT nMaxValue TO nMax + DEFAULT nMinValue TO nMin + + IF lShowAxis + IF lShowLabelLeft + x += nLeftLabelSpace + nWidth -= nLeftLabelSpace + ENDIF + IF lShowLabelRight + nWidth -= nRightLabelSpace + ENDIF + IF lShowLabelBottom + y += nBottomLabelSpace + nHeight -= nBottomLabelSpace + ENDIF + IF lShowLabelTop + nHeight -= nTopLabelSpace + ENDIF + ENDIF + + nSize := Len( aDataOfHash ) - 1 + + if nSize > 1 + nSize := nWidth / nSize + else + nSize := nWidth + endif + + nTotRange := nMaxValue + iif( nMinValue < 0, abs( nMinValue ), 0 ) + + nCeiling := 0 + + do while ( nTotRange / ( 10 ^ nCeiling ) ) > 100 + nCeiling++ + enddo + + nCeiling := 10 ^ nCeiling + + nMaxValue := ceiling( nMaxValue / nCeiling ) * nCeiling + nMinValue := iif( nMinValue < 0, -ceiling( abs( nMinValue ) / nCeiling ) * nCeiling, ceiling( nMinValue / nCeiling ) * nCeiling ) + + nTotRange := nMaxValue + iif( nMinValue < 0, abs( nMinValue ), 0 ) + + IF lShowGrid + ::Rectangle( x, ::Height() - ( y + nHeight ), x + nWidth, ::Height() - y, FALSE, color ) + + nThick := ::SetThickness( 1 ) + + ::ResetStyles() + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( color ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::AddStyle( gdTransparent ) + ::SetStyle() + FOR n := 10 TO 100 STEP 10 + nDim := ( ( nTotRange / 100 ) * n ) + nPosY := ( nDim / nTotRange ) * nHeight + //__OutDebug( "nDim", nDim ) + ::Line( x, ::Height() - ( y + nPosY), x + nWidth, ::Height() - ( y + nPosY ), gdStyled ) + NEXT + FOR EACH hElement IN aDataOfHash + nPosX := x + ( nSize * ( HB_EnumIndex() - 1 ) ) + ::Line( nPosX, ::Height() - y, nPosX, ::Height() - ( y + nHeight ), gdStyled ) + NEXT + ::SetThickness( nThick ) + ENDIF + + IF lShowAxis + // Y Axis + FOR n := 0 TO 100 STEP 10 + nDim := ( ( nTotRange / 100 ) * n ) + cLabel := LTrim( Transform( nMinValue + ( nTotRange / 10 ) * ( n / 10 ), cAxisPict ) ) + nPosY := ( nDim / nTotRange ) * nHeight + IF lShowLabelLeft + ::Say( x - nLeftLabelSpace + nBorder, ::Height() - ( y + nPosY ), cLabel, color ) + ENDIF + IF lShowLabelRight + ::Say( x + nWidth + nBorder, ::Height() - ( y + nPosY ), cLabel, color ) + ENDIF + NEXT + ENDIF + + // Second, + aPoints := {} + FOR EACH hElement IN aDataOfHash + cLabel := HGetValue( hElement, "LABEL" ) + lFilled := HGetValue( hElement, "FILLED" ) + nExtrude := HGetValue( hElement, "EXTRUDE" ) + pTile := HGetValue( hElement, "TILE" ) + IF nExtrude <> NIL + lExtruded := TRUE + ELSE + lExtruded := FALSE + ENDIF + colorp := HGetValue( hElement, "COLOR" ) + nVal := hElement["VALUE"] + nDim := ( ( nVal + abs( nMinValue ) ) / nTotRange ) * nHeight + + DEFAULT lFilled TO FALSE + DEFAULT nExtrude TO 0 + DEFAULT colorp TO ::SetColor( 0, 0, 0 ) + + nPosX := x + ( nSize * ( HB_EnumIndex() - 1 ) ) + nPosY := y + IF pTile <> NIL + ::SetTile( pTile ) + colorp := gdTiled + ELSE + if ISARRAY( colorp ) + colorp := ::SetColor( colorp[1], colorp[2], colorp[3] ) + endif + ENDIF + //::Rectangle( nPosX + nBorder, ::Height() - ( nPosY + nDim ), nPosX + nSize - nBorder, ::Height() - nPosY, lFilled, colorp ) + aAdd( aPoints, { nPosX, ::Height() - ( nPosY + nDim ) } ) + + IF lShowAxis + // Y Axis + IF lShowLabelBottom + ::SayVertical( nPosX - ::GetFontHeight() / 2, ::Height() - nBorder, PadL( cLabel, nMaxLabel ), color ) + ENDIF + ENDIF + + NEXT + + // Draw lines + nThick := ::SetThickness( 3 ) + + //::ResetStyles() + //::AddStyle( color ) + //::AddStyle( color ) + //::AddStyle( color ) + //::AddStyle( gdTransparent ) + //::AddStyle( gdTransparent ) + //::AddStyle( gdTransparent ) + //::AddStyle( gdTransparent ) + //::AddStyle( gdTransparent ) + //::SetStyle() + FOR n := 1 TO Len( aPoints ) - 1 + ::Line( aPoints[ n ][ 1 ], aPoints[ n ][ 2 ], aPoints[ n + 1 ][ 1 ], aPoints[ n + 1 ][ 2 ], color ) + NEXT + ::SetThickness( nThick ) + +RETURN Self + +STATIC FUNCTION HGetValue( hHash, cKey ) + LOCAL nPos + LOCAL xVal + IF hHash <> NIL + xVal := IIF( ( nPos := HGetPos( hHash, cKey )) == 0, NIL, HGetValueAt( hHash, nPos) ) + ENDIF + //RETURN IIF( cKey IN hHash:Keys, hHash[ cKey ], NIL ) +RETURN xVal diff --git a/harbour/contrib/gd/gdimage.prg b/harbour/contrib/gd/gdimage.prg new file mode 100644 index 0000000000..fc7a1a09bb --- /dev/null +++ b/harbour/contrib/gd/gdimage.prg @@ -0,0 +1,664 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * GD graphic library class + * + * Copyright 2004-2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + +#include "common.ch" +#include "hbclass.ch" +#include "gd.ch" + +#define DEFAULT( x, y ) IIF( x == NIL, x := y, ) + +CLASS GDImage + + HIDDEN: + DATA pImage + DATA pBrush + DATA pTile + DATA pFont + DATA pColor + + DATA cFontName INIT "Arial" + DATA nFontPitch INIT 20 + DATA nFontAngle INIT 0 + + DATA aPoints INIT {} + DATA aStyles INIT {} + DATA lDestroy INIT TRUE + + EXPORTED: + DATA hFile + DATA cType + DATA cMime + + METHOD New( sx, sy ) CONSTRUCTOR + + /* IMAGE CREATION, DESTRUCTION, LOADING AND SAVING */ + + // Create in memory + METHOD Create( sx, sy ) INLINE ::pImage := gdImageCreate( sx, sy ), Self + METHOD CreateTrueColor( sx, sy ) INLINE ::pImage := gdImageCreateTrueColor( sx, sy ), Self + + // Load From File + METHOD LoadFromPng( cFile ) INLINE ::pImage := gdImageCreateFromPng( cFile ), Self + METHOD LoadFromJpeg( cFile ) INLINE ::pImage := gdImageCreateFromJpeg( cFile ), Self + METHOD LoadFromWBmp( cFile ) INLINE ::pImage := gdImageCreateFromWBMP( cFile ), Self + METHOD LoadFromGd( cFile ) INLINE ::pImage := gdImageCreateFromGD( cFile ), Self + METHOD LoadFromGif( cFile ) INLINE ::pImage := gdImageCreateFromGif( cFile ), Self + + // Load From a specific File handle + METHOD InputPng( nHandle, nSize ) INLINE ::pImage := gdImageCreateFromPng( nHandle, nSize ), Self + METHOD InputJpeg( nHandle, nSize ) INLINE ::pImage := gdImageCreateFromJpeg( nHandle, nSize ), Self + METHOD InputWBmp( nHandle, nSize ) INLINE ::pImage := gdImageCreateFromWBMP( nHandle, nSize ), Self + METHOD InputGd( nHandle, nSize ) INLINE ::pImage := gdImageCreateFromGD( nHandle, nSize ), Self + METHOD InputGif( nHandle, nSize ) INLINE ::pImage := gdImageCreateFromGif( nHandle, nSize ), Self + + // Create from an image pointer in memory + METHOD CreateFromPng( pImage, nSize ) INLINE ::pImage := gdImageCreateFromPng( pImage, nSize ), Self + METHOD CreateFromJpeg( pImage, nSize ) INLINE ::pImage := gdImageCreateFromJpeg( pImage, nSize ), Self + METHOD CreateFromWBmp( pImage, nSize ) INLINE ::pImage := gdImageCreateFromWBMP( pImage, nSize ), Self + METHOD CreateFromGd( pImage, nSize ) INLINE ::pImage := gdImageCreateFromGD( pImage, nSize ), Self + METHOD CreateFromGif( pImage, nSize ) INLINE ::pImage := gdImageCreateFromGif( pImage, nSize ), Self + + METHOD LoadFromFile( cFile ) + + // Save To File Name + METHOD SavePng( cFile, nLevel ) INLINE gdImagePng( ::pImage, cFile, nLevel ) + METHOD SaveJpeg( cFile, nLevel ) INLINE gdImageJpeg( ::pImage, cFile, nLevel ) + METHOD SaveWBmp( cFile, nFG ) INLINE gdImageWBmp( ::pImage, cFile, nFG ) + METHOD SaveGd( cFile ) INLINE gdImageGd( ::pImage, cFile ) + METHOD SaveGif( cFile ) INLINE gdImageGif( ::pImage, cFile ) + + METHOD SaveToFile( cFile ) INLINE gdImageToFile( Self, cFile ) + + // Output To a specified File handle + METHOD OutputPng( nHandle, nLevel ) INLINE IIF( nHandle == NIL, nHandle := 1, ), gdImagePng( ::pImage, nHandle, nLevel ) + METHOD OutputJpeg( nHandle, nLevel ) INLINE IIF( nHandle == NIL, nHandle := 1, ), gdImageJpeg( ::pImage, nHandle, nLevel ) + METHOD OutputWBmp( nHandle, nFG ) INLINE IIF( nHandle == NIL, nHandle := 1, ), gdImageWBmp( ::pImage, nHandle, nFG ) + METHOD OutputGd( nHandle ) INLINE IIF( nHandle == NIL, nHandle := 1, ), gdImageGd( ::pImage, nHandle ) + METHOD OutputGif( nHandle ) INLINE IIF( nHandle == NIL, nHandle := 1, ), gdImageGif( ::pImage, nHandle ) + + // Output To a string + METHOD ToStringPng( nLevel ) INLINE gdImagePng( ::pImage, NIL, nLevel ) + METHOD ToStringJpeg( nLevel ) INLINE gdImageJpeg( ::pImage, NIL, nLevel ) + METHOD ToStringWBmp( nFG ) INLINE gdImageWBmp( ::pImage, NIL, nFG ) + METHOD ToStringGd() INLINE gdImageGd( ::pImage, NIL ) + METHOD ToStringGif() INLINE gdImageGif( ::pImage, NIL ) + + METHOD ToString() INLINE gdImageToString( Self ) + + // Destructor + METHOD Destroy() INLINE gdImageDestroy( ::pImage ) + DESTRUCTOR Destruct() + + + + /* DRAWING FUNCTIONS */ + METHOD SetPixel( x, y, color ) INLINE DEFAULT( color, ::pColor ), gdImageSetPixel( ::pImage, x, y, color ) + METHOD Line( x1, y1, x2, y2, color ) INLINE DEFAULT( color, ::pColor ), gdImageLine( ::pImage, x1, y1, x2, y2, color ) + METHOD DashedLine( x1, y1, x2, y2, color ) INLINE DEFAULT( color, ::pColor ), gdImageDashedLine( ::pImage, x1, y1, x2, y2, color ) + + // Functions usefull for polygons + METHOD Polygon( aPoints, lFilled, color ) +#if ( GD_VERS >= 2033 ) + METHOD OpenPolygon( aPoints, color ) +#endif + METHOD AddPoint( x, y ) INLINE aAdd( ::aPoints, { x, y } ) + METHOD ResetPoints() INLINE ::aPoints := {} + METHOD Points() INLINE Len( ::aPoints ) + + METHOD Rectangle( x1, y1, x2, y2, lFilled, color ) + METHOD Arc( x, y, nWidth, nHeight, nStartDegree, nEndDegree, lFilled, nColor ) + METHOD Ellipse( x, y, nWidth, nHeight, lFilled, nColor ) + METHOD Circle( x, y, nRadius, lFilled, nColor ) ; + INLINE ::Ellipse( x, y, nRadius, nRadius, lFilled, nColor ) + + METHOD Fill( x, y, color ) INLINE DEFAULT( color, ::pColor ), gdImageFill( ::pImage, x, y, color ) + METHOD FillToBorder( x, y, border, color ) ; + INLINE DEFAULT( color, ::pColor ), gdImageFillToBorder( ::pImage, x, y, border, color ) + METHOD SetAntiAliased( color ) INLINE DEFAULT( color, ::pColor ), gdImageSetAntiAliased( ::pImage, color ) + METHOD SetAntiAliasedDontBlend( lDontBlend, color ) ; + INLINE DEFAULT( color, ::pColor ), gdImageSetAntiAliasedDontBlend( ::pImage, color, lDontBlend ) + + METHOD SetBrush( pBrush ) INLINE gdImageSetBrush( ::pImage, pBrush:pImage ), ::pBrush := pBrush + METHOD SetTile( pTile ) INLINE gdImageSetTile( ::pImage, pTile:pImage ), ::pTile := pTile + + // Functions usefull for style + METHOD SetStyle( aStyle ) INLINE DEFAULT( aStyle, ::aStyles ), gdImageSetStyle( ::pImage, aStyle ) + METHOD AddStyle( pColor ) INLINE aAdd( ::aStyles, pColor ) + METHOD ResetStyles() INLINE ::aStyles := {} + METHOD StyleLenght() INLINE Len( ::aStyles ) + + METHOD SetThickness( nThickness ) INLINE gdImageSetThickness( ::pImage, nThickness ) + METHOD SetAlphaBlending( lAlphaBlending ) INLINE gdImageAlphaBlending( ::pImage, lAlphaBlending ) + METHOD SetSaveAlpha( lSaveAlpha ) INLINE gdImageSaveAlpha( ::pImage, lSaveAlpha ) + METHOD SetClippingArea( x1, y1, x2, y2 ) INLINE gdImageSetClip( ::pImage, x1, y1, x2, y2 ) + + /* QUERY FUNCTIONS */ + METHOD ColorsTotal() INLINE gdImageColorsTotal( ::pImage ) + METHOD Alpha( color ) INLINE DEFAULT( color, ::pColor ), gdImageAlpha( ::pImage, color ) + METHOD Red( color ) INLINE DEFAULT( color, ::pColor ), gdImageRed( ::pImage, color ) + METHOD Green( color ) INLINE DEFAULT( color, ::pColor ), gdImageGreen( ::pImage, color ) + METHOD Blue( color ) INLINE DEFAULT( color, ::pColor ), gdImageBlue( ::pImage, color ) + METHOD Width() INLINE gdImageSx( ::pImage ) + METHOD Height() INLINE gdImageSy( ::pImage ) + METHOD CenterWidth() INLINE ::Width() / 2 + METHOD CenterHeight() INLINE ::Height() / 2 + METHOD GetPixel( x, y ) INLINE gdImageGetPixel( ::pImage, x, y ) + METHOD GetColor() INLINE ::pColor + METHOD GetImagePtr() INLINE ::pImage + METHOD GetClippingArea() INLINE gdImageGetClip( ::pImage ) + METHOD IsBoundsSafe( x, y ) INLINE gdImageBoundsSafe( ::pImage, x, y ) + METHOD IsInterlaced() INLINE gdImageGetInterlaced( ::pImage ) + METHOD GetTransparent() INLINE gdImageGetTransparent( ::pImage ) + METHOD IsTransparent() INLINE ::GetTransparent() > 0 + METHOD IsTrueColor() INLINE gdImageTrueColor( ::pImage ) + + METHOD ConvertFromTrueColorToPalette( lDither, nColorsWanted ) ; + INLINE gdImageTrueColorToPalette ( ::pImage, lDither, nColorsWanted ) + METHOD CreatePaletteFromTrueColor( lDither, nColorsWanted ) ; + INLINE gdImageCreatePaletteFromTrueColor( ::pImage, lDither, nColorsWanted ) + METHOD GetPalette( x, y ) INLINE gdImagePalettePixel( ::pImage, x, y ) + METHOD GetTrueColor( x, y ) INLINE gdImageTrueColorPixel( ::pImage, x, y ) + METHOD GetThickness() INLINE gdImageGetThickness( ::pImage ) + + /* FONTS AND TEXT-HANDLING FUNCTIONS */ + METHOD SetFontSmall() INLINE ::pFont := gdFontGetSmall() + METHOD SetFontLarge() INLINE ::pFont := gdFontGetLarge() + METHOD SetFontMediumBold() INLINE ::pFont := gdFontGetMediumBold() + METHOD SetFontGiant() INLINE ::pFont := gdFontGetGiant() + METHOD SetFontTiny() INLINE ::pFont := gdFontGetTiny() + METHOD Say( x, y, cString, color, nAlign ) + METHOD SayVertical( x, y, cString, color ) INLINE DEFAULT( color, ::pColor ), gdImageStringUp( ::pImage, ::pFont, x, y, cString, color ) + + METHOD SetFontName( cFontName ) INLINE ::cFontName := cFontName + METHOD SetFontPitch( nPitch ) INLINE ::nFontPitch := nPitch + METHOD SetFontAngle( nAngle ) INLINE ::nFontAngle := nAngle + METHOD SayFreeType( x, y, cString, cFontName, nPitch, nAngle, color, nAlign, ; + nLineSpacing, nCharMap, nResolution ) + + METHOD SayFreeTypeCircle( x, y, cStringTop, cStringBottom, color, nRadius, nTextRadius, nFillPortion, cFontName, nPitch ) ; + INLINE DEFAULT( color, ::pColor ), gdImageStringFTCircle( ::pImage, x, y, nRadius, ; + nTextRadius, nFillPortion, cFontName, nPitch, cStringTop, cStringBottom, color ) + + METHOD GetFont() INLINE ::pFont + METHOD GetFontWidth( pFont ) INLINE DEFAULT( pFont, ::pFont ), gdFontGetWidth( pFont ) + METHOD GetFontHeight( pFont ) INLINE DEFAULT( pFont, ::pFont ), gdFontGetHeight( pFont ) + + METHOD GetFTFontWidth( cFontName, nPitch ) INLINE DEFAULT( cFontName, ::cFontName ), ; + DEFAULT( nPitch, ::nFontPitch ) , ; + gdImageFTWidth( cFontName, nPitch ) + + METHOD GetFTFontHeight( cFontName, nPitch ) INLINE DEFAULT( cFontName, ::cFontName ), ; + DEFAULT( nPitch, ::nFontPitch ) , ; + gdImageFTHeight( cFontName, nPitch ) + + METHOD GetFTStringSize( cString, cFontName, nPitch ) INLINE DEFAULT( cFontName, ::cFontName ), ; + DEFAULT( nPitch, ::nFontPitch ) , ; + gdImageFTSize( cString, cFontName, nPitch ) + + /* COLOR HANDLING FUNCTIONS */ + METHOD SetColor( r, g, b ) INLINE IIF( PCount() == 2, ::pColor := r, ::pColor := gdImageColorAllocate( ::pImage, r, g, b ) ) + METHOD DelColor( pColor ) INLINE ::pColor := NIL, gdImageColorDeAllocate( ::pImage, pColor ) + METHOD SetColorAlpha( r, g, b, a ) INLINE ::pColor := gdImageColorAllocateAlpha( ::pImage, r, g, b, a) + METHOD SetColorClosest( r, g, b ) INLINE ::pColor := gdImageColorClosest( ::pImage, r, g, b ) + METHOD SetColorClosestAlpha( r, g, b, a ) INLINE ::pColor := gdImageColorClosestAlpha( ::pImage, r, g, b, a) + METHOD SetColorClosestHWB( r, g, b ) INLINE ::pColor := gdImageColorClosestHWB( ::pImage, r, g, b ) + METHOD SetColorExact( r, g, b ) INLINE ::pColor := gdImageColorExact( ::pImage, r, g, b ) + METHOD SetColorResolve( r, g, b ) INLINE ::pColor := gdImageColorResolve( ::pImage, r, g, b ) + METHOD SetColorResolveAlpha( r, g, b, a ) INLINE ::pColor := gdImageColorResolveAlpha( ::pImage, r, g, b, a) + METHOD SetTransparent( pColor ) INLINE gdImageColorTransparent( ::pImage, pColor ) + METHOD SetSharpen( nPerc ) INLINE gdImageSharpen( ::pImage, nPerc ) + METHOD SetInterlace( lOnOff ) INLINE gdImageInterlace( ::pImage, lOnOff ) + METHOD SetInterlaceOn() INLINE gdImageInterlace( ::pImage, TRUE ) + METHOD SetInterlaceOff() INLINE gdImageInterlace( ::pImage, FALSE ) + + METHOD GetTrueColor( r, g, b ) INLINE gdTrueColor( r, g, b ) + METHOD GetTrueColorAlpha( r, g, b, a ) INLINE gdTrueColorAlpha( r, g, b, a ) + + /* COPY AND RESIZING FUNCTIONS */ + METHOD Copy() + METHOD CopyResized() + METHOD CopyResampled() + METHOD CopyRotated() + METHOD CopyMerge() + METHOD CopyMergeGray() + + /* New implemented */ + METHOD Clone() + METHOD CopyZoomed() + METHOD Crop() + METHOD Zoom() + METHOD Resize() + METHOD Rotate() + METHOD RotateInside( nAngle ) INLINE ::Rotate( nAngle, .T. ) + + METHOD PaletteCopy( oDestImage ) INLINE gdImagePaletteCopy( oDestImage:pImage, ::pImage ) + METHOD SquareToCircle( nRadius ) INLINE gdImageSquareToCircle( ::pImage, nRadius ) + METHOD Compare( oDestImage ) INLINE gdImageCompare( oDestImage:pImage, ::pImage ) + + + METHOD Radians( nAngle ) INLINE PI() * nAngle / 180 + METHOD Degres( nRadians ) INLINE nRadians * 180 / PI() + + METHOD Version() INLINE gdVersion() + +ENDCLASS + +METHOD New( sx, sy ) CLASS GDImage + ::Create( sx, sy ) +RETURN Self + +PROCEDURE Destruct() CLASS GDImage + //__OutDebug( "Destroyed" ) + IF ::lDestroy + ::Destroy() + ENDIF +RETURN + +METHOD Polygon( aPoints, lFilled, color ) CLASS GDImage + DEFAULT aPoints TO ::aPoints + DEFAULT lFilled TO FALSE + DEFAULT color TO ::pColor + IF lFilled + gdImageFilledPolygon( ::pImage, aPoints, color ) + ELSE + gdImagePolygon( ::pImage, aPoints, color ) + ENDIF +RETURN Self + +#if ( GD_VERS >= 2033 ) +METHOD OpenPolygon( aPoints, color ) CLASS GDImage + DEFAULT aPoints TO ::aPoints + DEFAULT color TO ::pColor + gdImageOpenPolygon( ::pImage, aPoints, color ) +RETURN Self +#endif + +METHOD Rectangle( x1, y1, x2, y2, lFilled, color ) CLASS GDImage + DEFAULT lFilled TO FALSE + DEFAULT color TO ::pColor + IF lFilled + gdImageFilledRectangle( ::pImage, x1, y1, x2, y2, color ) + ELSE + gdImageRectangle( ::pImage, x1, y1, x2, y2, color ) + ENDIF +RETURN Self + +METHOD Arc( x, y, nWidth, nHeight, nStartDegree, nEndDegree, lFilled, color, nStyle ) CLASS GDImage + DEFAULT lFilled TO FALSE + DEFAULT color TO ::pColor + DEFAULT nStyle TO gdArc + IF lFilled + gdImageFilledArc( ::pImage, x, y, nWidth, nHeight, nStartDegree, nEndDegree, color, nStyle ) + ELSE + gdImageArc( ::pImage, x, y, nWidth, nHeight, nStartDegree, nEndDegree, color ) + ENDIF +RETURN Self + +METHOD Ellipse( x, y, nWidth, nHeight, lFilled, color ) CLASS GDImage + DEFAULT lFilled TO FALSE + DEFAULT color TO ::pColor + IF lFilled + gdImageFilledEllipse( ::pImage, x, y, nWidth, nHeight, color ) + ELSE + gdImageEllipse( ::pImage, x, y, nWidth, nHeight, color ) + ENDIF +RETURN Self + +METHOD LoadFromFile( cFile ) CLASS GDImage + LOCAL aLoad + aLoad := gdImageFromFile( cFile ) + Self := aLoad[1]:Clone() + ::Destroy() + aLoad[1]:lDestroy := FALSE + aLoad[1] := NIL + + ::hFile := aLoad[2] + ::cType := aLoad[3] + ::cMime := aLoad[4] +RETURN Self + +METHOD Copy( nSrcX, nSrcY, nWidth, nHeight, nDstX, nDstY, oDestImage ) CLASS GDImage + + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nWidth TO ::Width() + DEFAULT nHeight TO ::Height() + DEFAULT nDstX TO 0 + DEFAULT nDstY TO 0 + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nWidth, nHeight ) + ELSE + oDestImage := GDImage():Create( nWidth, nHeight ) + ENDIF + ENDIF + gdImageCopy( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nWidth, nHeight ) +RETURN oDestImage + +METHOD CopyResized( nSrcX, nSrcY, nSrcWidth, nSrcHeight, nDstX, nDstY, nDstWidth, nDstHeight, oDestImage ) CLASS GDImage + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nSrcWidth TO ::Width() + DEFAULT nSrcHeight TO ::Height() + DEFAULT nDstX TO 0 + DEFAULT nDstY TO 0 + DEFAULT nDstWidth TO ::Width() + DEFAULT nDstHeight TO ::Height() + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nDstWidth, nDstHeight ) + ELSE + oDestImage := GDImage():Create( nDstWidth, nDstHeight ) + ENDIF + ENDIF + gdImageCopyResized( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nDstWidth, nDstHeight, nSrcWidth, nSrcHeight ) +RETURN oDestImage + +METHOD CopyResampled( nSrcX, nSrcY, nSrcWidth, nSrcHeight, nDstX, nDstY, nDstWidth, nDstHeight, oDestImage ) CLASS GDImage + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nSrcWidth TO ::Width() + DEFAULT nSrcHeight TO ::Height() + DEFAULT nDstX TO 0 + DEFAULT nDstY TO 0 + DEFAULT nDstWidth TO ::Width() + DEFAULT nDstHeight TO ::Height() + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nDstWidth, nDstHeight ) + ELSE + oDestImage := GDImage():Create( nDstWidth, nDstHeight ) + ENDIF + ENDIF + gdImageCopyResampled( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nDstWidth, nDstHeight, nSrcWidth, nSrcHeight ) +RETURN oDestImage + +METHOD CopyRotated( nSrcX, nSrcY, nWidth, nHeight, nDstX, nDstY, nAngle, oDestImage ) CLASS GDImage + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nWidth TO ::Width + DEFAULT nHeight TO ::Height + DEFAULT nDstX TO nWidth / 2 + DEFAULT nDstY TO nHeight / 2 + DEFAULT nAngle TO 90 + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nWidth, nHeight ) + ELSE + oDestImage := GDImage():Create( nWidth, nHeight ) + ENDIF + ENDIF + //__OutDebug( nAngle ) + gdImageCopyRotated( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nWidth, nHeight, nAngle ) +RETURN oDestImage + +METHOD CopyMerge( nSrcX, nSrcY, nWidth, nHeight, nDstX, nDstY, nPerc, oDestImage ) CLASS GDImage + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nWidth TO ::Width + DEFAULT nHeight TO ::Height + DEFAULT nDstX TO 0 + DEFAULT nDstY TO 0 + DEFAULT nPerc TO 100 + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nWidth, nHeight ) + ELSE + oDestImage := GDImage():Create( nWidth, nHeight ) + ENDIF + ENDIF + gdImageCopyMerge( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nWidth, nHeight, nPerc ) +RETURN oDestImage + +METHOD CopyMergeGray( nSrcX, nSrcY, nWidth, nHeight, nDstX, nDstY, nPerc, oDestImage ) CLASS GDImage + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nWidth TO ::Width + DEFAULT nHeight TO ::Height + DEFAULT nDstX TO 0 + DEFAULT nDstY TO 0 + DEFAULT nPerc TO 100 + + IF oDestImage == NIL + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nWidth, nHeight ) + ELSE + oDestImage := GDImage():Create( nWidth, nHeight ) + ENDIF + ENDIF + gdImageCopyMergeGray( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nWidth, nHeight, nPerc ) +RETURN oDestImage + +METHOD CopyZoomed( nPerc, nSrcX, nSrcY, nSrcWidth, nSrcHeight ) CLASS GDImage + LOCAL oDestImage + LOCAL nDstX, nDstY, nDstWidth, nDstHeight + + DEFAULT nPerc TO 100 + DEFAULT nSrcX TO 0 + DEFAULT nSrcY TO 0 + DEFAULT nSrcWidth TO ::Width() + DEFAULT nSrcHeight TO ::Height() + + IF nPerc < 0 + nPerc := 100 + ENDIF + + nDstX := 0 + nDstY := 0 + nDstWidth := nSrcWidth * nPerc / 100 + nDstHeight := nSrcHeight * nPerc / 100 + + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nDstWidth, nDstHeight ) + ELSE + oDestImage := GDImage():Create( nDstWidth, nDstHeight ) + ENDIF + gdImageCopyResampled( oDestImage:pImage, ::pImage, nDstX, nDstY, nSrcX, nSrcY, nDstWidth, nDstHeight, nSrcWidth, nSrcHeight ) + +RETURN oDestImage + +METHOD Rotate( nAngle, lInside ) CLASS GDImage + LOCAL oDestImage + LOCAL nWidth, nHeight + LOCAL nAngRad := nAngle * PI() / 180 + + DEFAULT lInside TO FALSE + + IF !lInside + nWidth := ::Width * cos( nAngRad ) + ::Height * sin( nAngRad ) + nHeight := ::Width * sin( nAngRad ) + ::Height * cos( nAngRad ) + ELSE + nWidth := ::Width + nHeight := ::Height + ENDIF + //__OutDebug( ::Width, ::Height ) + //__OutDebug( nWidth, nHeight ) + + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( nWidth, nHeight ) + ELSE + oDestImage := GDImage():Create( nWidth, nHeight ) + ENDIF + IF !lInside + ::CopyRotated( ,,,, nWidth - nWidth/2, nHeight - nHeight/2, nAngle, oDestImage ) + ELSE + ::CopyRotated( ,,,,,, nAngle, oDestImage ) + ENDIF + ::Destroy() + Self := __ObjCLone( oDestImage ) + + // Move new image to existing one + // Signal that this image must not be destroyed + oDestImage:lDestroy := FALSE + oDestImage := NIL + +RETURN Self + +METHOD Crop( nX, nY, nWidth, nHeight ) CLASS GDImage + LOCAL oDestImage + + oDestImage := ::CopyResized( nX, nY, nWidth, nHeight, 0, 0, nWidth, nHeight ) + ::Destroy() + Self := __ObjClone( oDestImage ) + + // Move new image to existing one + // Signal that this image must not be destroyed + oDestImage:lDestroy := FALSE + oDestImage := NIL + +RETURN Self + +METHOD Resize( nWidth, nHeight ) CLASS GDImage + LOCAL oDestImage + + oDestImage := ::CopyResampled( 0, 0, NIL, NIL, 0, 0, nWidth, nHeight ) + ::Destroy() + Self := __ObjClone( oDestImage ) + + // Move new image to existing one + // Signal that this image must not be destroyed + oDestImage:lDestroy := FALSE + oDestImage := NIL + +RETURN Self + +METHOD Zoom( nPerc ) CLASS GDImage + LOCAL oDestImage + + oDestImage := ::CopyZoomed( nPerc ) + ::Destroy() + Self := __ObjClone( oDestImage ) + + // Move new image to existing one + // Signal that this image must not be destroyed + oDestImage:lDestroy := FALSE + oDestImage := NIL + +RETURN Self + +METHOD Clone() CLASS GDImage + LOCAL oDestImage + + IF ::IsTrueColor() + oDestImage := GDImage():CreateTrueColor( ::Width, ::Height ) + ELSE + oDestImage := GDImage():Create( ::Width, ::Height ) + ENDIF + + ::Copy( 0, 0, ::Width, ::Height, 0, 0, oDestImage ) +// ::Destroy() + // Self := __ObjClone( oDestImage ) + +RETURN oDestImage + +METHOD Say( x, y, cString, color, nAlign ) CLASS GDImage + LOCAL nWidth, nLen + LOCAL nPosX + + DEFAULT color TO ::pColor + DEFAULT nAlign TO gdAlignLeft + + IF nAlign == gdAlignCenter + nWidth := ::GetFontWidth() + nLen := Len( cString ) + nPosX := x - ( nLen / 2 * nWidth ) + ELSEIF nAlign == gdAlignRight + nWidth := ::GetFontWidth() + nLen := Len( cString ) + nPosX := x - ( nLen * nWidth ) + ELSE + nPosX := x + ENDIF + + gdImageString( ::pImage, ::pFont, nPosX, y, cString, color ) +RETURN Self + +METHOD SayFreeType( x, y, cString, cFontName, nPitch, nAngle, color, nAlign, ; + nLineSpacing, nCharMap, nResolution ) CLASS GDImage + LOCAL nWidth, nLen + LOCAL nPosX + + DEFAULT nAlign TO gdAlignLeft + DEFAULT color TO ::pColor + DEFAULT cFontName TO ::cFontName + DEFAULT nPitch TO ::nFontPitch + DEFAULT nAngle TO ::nFontAngle + + IF nAlign == gdAlignCenter + nWidth := nPitch //gdImageFTWidth( cFontName, nPitch )//, ::Radians( nAngle ) ) //::GetFontWidth() + //__OutDebug( "nWidth", nWidth ) + nLen := Len( cString ) + nPosX := x - ( (nLen / 2) * nWidth ) + ELSEIF nAlign == gdAlignRight + nWidth := gdImageFTWidth( cFontName, nPitch ) //, ::Radians( nAngle ) ) //::GetFontWidth() + nLen := Len( cString ) + nPosX := x - ( nLen * nWidth ) + ELSE + nPosX := x + ENDIF + + gdImageStringFT( ::pImage, color, cFontName, nPitch, ::Radians( nAngle ), nPosX, y, ; + cString, nLineSpacing, nCharMap, nResolution ) + +RETURN Self + diff --git a/harbour/contrib/gd/gdwrp.c b/harbour/contrib/gd/gdwrp.c new file mode 100644 index 0000000000..d2c8eb1d68 --- /dev/null +++ b/harbour/contrib/gd/gdwrp.c @@ -0,0 +1,3950 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * GD graphic library low level (client api) interface code. + * + * Copyright 2004-2005 Francesco Saverio Giudice + * www - http://www.xharbour.org http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* + * + * See doc/license files for licensing terms. + * + */ + +/* NOTE: we need this to prevent base types redefinition */ +#define _CLIPDEFS_H +#if defined(HB_OS_WIN_32_USED) + #include +#endif + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbstack.h" +#include "hbapierr.h" +#include "hbapifs.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include "gd.h" +#include "gdfontt.h" +#include "gdfonts.h" +#include "gdfontmb.h" +#include "gdfontl.h" +#include "gdfontg.h" + +#define IMAGE_JPEG 1 +#define IMAGE_GIF 2 +#define IMAGE_PNG 3 +#define IMAGE_WBMP 4 +#define IMAGE_GD 5 + + +/* ---------------------------------------------------------------------------*/ +/* Internal functions */ +/* ---------------------------------------------------------------------------*/ + +static void * LoadImageFromHandle( FHANDLE fhandle, int sz ) +{ + void *iptr; + + if ( !( fhandle ) ) + { + fhandle = 0; // 0 = std input + } + + /* Read file */ + iptr = ( BYTE * ) hb_xgrab( sz ); + hb_fsReadLarge( fhandle, ( BYTE *) iptr, (ULONG) sz ); + // TraceLog( NULL, "Error dim %i, read %i", sz, iRead ); + + return iptr; + +} + +/* ---------------------------------------------------------------------------*/ + +static void * LoadImageFromFile( char *szFile, int *sz ) +{ + void *iptr; + FHANDLE fhandle; + + if ( ( fhandle = hb_fsOpen( ( BYTE * ) szFile, FO_READ ) ) != FS_ERROR ) + { + /* get lenght */ + *sz = hb_fsSeek( fhandle, 0, FS_END ); + /* rewind */ + hb_fsSeek( fhandle, 0, FS_SET ); + + /* Read file */ + iptr = ( BYTE * ) hb_xgrab( *sz ); + hb_fsReadLarge( fhandle, ( BYTE *) iptr, (ULONG) *sz ); + // TraceLog( NULL, "Error dim %i, read %i", sz, iRead ); + + /* Close file */ + hb_fsClose( fhandle ); + } + else + { + /* File error */ + iptr = NULL; + *sz = 0; + } + + return iptr; + +} + +/* ---------------------------------------------------------------------------*/ + +static void SaveImageToHandle( FHANDLE fhandle, void *iptr, int sz ) +{ + if ( !(fhandle) ) + { + fhandle = 1; // 1 = std output + } + + /* Write Image */ + hb_fsWriteLarge( fhandle, ( BYTE *) iptr, (ULONG) sz ); +} + +/* ---------------------------------------------------------------------------*/ + +static void SaveImageToFile( char *szFile, void *iptr, int sz ) +{ + FHANDLE fhandle; + + if ( ( fhandle = hb_fsCreate( ( BYTE * ) szFile, FC_NORMAL ) ) != FS_ERROR ) + { + /* Write Image */ + SaveImageToHandle( fhandle, ( BYTE *) iptr, (ULONG) sz ); + + /* Close file */ + hb_fsClose( fhandle ); + } +} + +/* ---------------------------------------------------------------------------*/ + +static void GDImageCreateFrom( int nType ) +{ + gdImagePtr im; + char *szFile; + int sz; + void *iptr; + + //TraceLog( NULL, "Params = %i, 1 = %i, 2 = %i \n\r", hb_pcount(), hb_parinfo( 1 ), hb_parinfo( 2 ) ); + + if ( hb_pcount() == 1 && + ( hb_parinfo( 1 ) & HB_IT_STRING ) + ) + { + /* Retrieve file name */ + szFile = hb_parcx( 1 ); + /* Retrieve image */ + iptr = LoadImageFromFile( szFile, &sz ); + } + + /* From Image Pointer + size */ + else if ( hb_pcount() == 2 && + ( hb_parinfo( 1 ) & HB_IT_POINTER ) && + ( hb_parinfo( 2 ) & HB_IT_NUMERIC ) + ) + { + + /* Retrieve image pointer */ + iptr = hb_parptr( 1 ); + /* Retrieve image size */ + sz = hb_parni( 2 ); + } + + /* From file handle */ + else if ( hb_pcount() == 2 && + ( hb_parinfo( 1 ) & HB_IT_NUMERIC ) && + ( hb_parinfo( 2 ) & HB_IT_NUMERIC ) + ) + { + + FHANDLE fhandle; + + /* Retrieve file handle */ + fhandle = ( hb_parinfo( 1 ) & HB_IT_NUMERIC ) ? hb_parnl( 1 ) : 0; // 0 = std input + /* Retrieve image size */ + sz = hb_parni( 2 ); + + /* retrieve image from handle */ + iptr = LoadImageFromHandle( fhandle, sz ); + + } + else + { + + // Parameter error + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECREATEFROM*", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + + if ( iptr && sz ) + { + /* Create Image */ + switch ( nType ) + { + case IMAGE_JPEG : + im = gdImageCreateFromJpegPtr( sz, ( BYTE *) iptr ); + break; + case IMAGE_GIF : + im = gdImageCreateFromGifPtr( sz, ( BYTE *) iptr ); + break; + case IMAGE_PNG : + im = gdImageCreateFromPngPtr( sz, ( BYTE *) iptr ); + break; + case IMAGE_WBMP : + im = gdImageCreateFromWBMPPtr( sz, ( BYTE *) iptr ); + break; + case IMAGE_GD : + im = gdImageCreateFromGdPtr( sz, ( BYTE *) iptr ); + break; + } + + /* Return image pointer */ + hb_retptr( im ); + + /* Free memory */ + hb_xfree( iptr ); + + } +} + +/* ---------------------------------------------------------------------------*/ + +static void GDImageSaveTo( int nType ) +{ + if ( hb_pcount() >= 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + char *szFile; + int sz; + void *iptr; + FHANDLE fhandle; + int level, fg; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr(1); + + /* Get file name or an output handler or NIL it I want a return string */ + if ( !( ISNIL(2) || + hb_parinfo( 2 ) & HB_IT_STRING || + hb_parinfo( 2 ) & HB_IT_NUMERIC ) ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, + "Second argument must be NIL or numeric or a string.", + "GDIMAGE* (Save functions)", 2, + hb_paramError( 2 ) ); + return; + } + + /* Retrieve compression level */ + //TraceLog( NULL, "Count = %i\n\r", hb_pcount() ); + /* check if is numeric */ + if ( !( ISNIL(3) || hb_parinfo( 3 ) & HB_IT_NUMERIC ) ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, + "Tirdh argument must be NIL or numeric.", + "GDIMAGE* (Save functions)", 1, + hb_paramError( 3 ) ); + return; + } + + if ( nType == IMAGE_JPEG ) + { + /* check range */ + level = ( hb_parinfo( 3 ) & HB_IT_NUMERIC ? hb_parni( 3 ) : -1 ); + if ( !( level >= -1 && level <= 95 ) ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, + "Compression level must be -1 (default) or a value between 0 and 95.", + "GDIMAGEJPEG (Save functions)", 1, + hb_paramError( 3 ) ); + return; + } + } + else if ( nType == IMAGE_PNG ) + { + /* check range */ + level = ( hb_parinfo( 3 ) & HB_IT_NUMERIC ? hb_parni( 3 ) : -1 ); + if ( !( level >= -1 && level <= 9 ) ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, + "Compression level must be -1 (default) or a value between 0 and 9.", + "GDIMAGEPNG (Save functions)", 1, + hb_paramError( 3 ) ); + return; + } + } + else if ( nType == IMAGE_WBMP ) + { + if ( !( hb_parinfo( 3 ) & HB_IT_NUMERIC ) ) + { + hb_errRT_BASE_SubstR( EG_ARG, 0, + "Foreground color nedeed", + "GDIMAGEWBMP (Save functions)", 1, + hb_paramError( 3 ) ); + return; + } + fg = hb_parni( 3 ); + } + + switch ( nType ) + { + case IMAGE_JPEG : + /* Get image Ptr */ + iptr = gdImageJpegPtr (im, &sz, level); + break; + case IMAGE_GIF : + /* Get image Ptr */ + iptr = gdImageGifPtr (im, &sz); + break; + case IMAGE_PNG : + /* Get image Ptr */ + iptr = gdImagePngPtrEx (im, &sz, level); + break; + case IMAGE_WBMP : + /* Get image Ptr */ + iptr = gdImageWBMPPtr (im, &sz, fg); + break; + case IMAGE_GD : + /* Get image Ptr */ + iptr = gdImageGdPtr (im, &sz); + break; + } + + /* If i get a file name */ + if ( hb_parinfo( 2 ) & HB_IT_STRING ) + { + szFile = hb_parcx( 2 ); + SaveImageToFile( szFile, iptr, sz ); + + } + + /* Write to file handle (1 = std output) */ + else if ( hb_parinfo( 2 ) & HB_IT_NUMERIC ) + { + /* Write to std output or to a passed file */ + fhandle = ( hb_parnl( 2 ) > -1 ) ? hb_parnl( 2 ) : 1 ; // 1 = std output + + /* Write Image */ + SaveImageToHandle( fhandle, iptr, sz ); + } + + /* Return image as string) */ + else + { + /* Return as string */ + hb_retclen( (const char *) iptr, (ULONG) sz ); + } + + /* Free memory */ + gdFree( iptr ); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGE* (save functions)", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ************************* WRAPPED FUNCTIONS ****************************** */ + +HB_FUNC( GDVERSION ) // gdImagePtr gdImageCreate(sx, sy) +{ +#if ( GD_VERS >= 2033 ) + hb_retc( "GD Version 2.0.33" ); +#else + hb_retc( "GD Version 2.0.28" ); +#endif +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* IMAGE CREATION, DESTRUCTION, LOADING AND SAVING */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATE ) // gdImagePtr gdImageCreate(sx, sy) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC ) + { + gdImagePtr im; + int sx, sy; + + /* Retrieve dimensions */ + sx = hb_parni( 1 ); + sy = hb_parni( 2 ); + + /* Create the image */ + im = gdImageCreate( sx, sy ); + + /* Return image pointer */ + hb_retptr( im ); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECREATE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEPALETTE ) // gdImagePtr gdImageCreatePalette(sx, sy) +{ + // Alias of GDCreate() + HB_FUNCNAME( GDIMAGECREATE )(); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATETRUECOLOR ) // gdImageCreateTrueColor(sx, sy) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC ) + { + gdImagePtr im; + int sx, sy; + + /* Retrieve dimensions */ + sx = hb_parni( 1 ); + sy = hb_parni( 2 ); + + /* Create the image */ + im = gdImageCreateTrueColor( sx, sy ); + + /* Return image pointer */ + hb_retptr( im ); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECREATETRUECOLOR", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEFROMJPEG ) // gdImageCreateFromJpegPtr(int size, void *data) + // implementation: gdImagePtr gdImageCreateFromJpeg( char *szFile ) +{ + GDImageCreateFrom( IMAGE_JPEG ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEFROMGIF ) // gdImageCreateFromGifPtr(int size, void *data) + // implementation: gdImagePtr gdImageCreateFromGif( char *szFile ) +{ + GDImageCreateFrom( IMAGE_GIF ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEFROMPNG ) // gdImageCreateFromPngPtr(int size, void *data) + // implementation: gdImagePtr gdImageCreateFromPng( char *szFile ) +{ + GDImageCreateFrom( IMAGE_PNG ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEFROMWBMP ) // gdImagePtr gdImageCreateFromWBMPPtr (int size, void *data) + // implementation: gdImagePtr gdImageCreateFromWBMP ( char *szFile ) +{ + GDImageCreateFrom( IMAGE_WBMP ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEFROMGD ) // gdImagePtr gdImageCreateFromGdPtr (int size, void *data) + // implementation: gdImagePtr gdImageCreateFromGd ( char *szFile ) +{ + GDImageCreateFrom( IMAGE_GD ); +} + + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEJPEG ) // original: void gdImageJpeg(gdImagePtr im, FILE *out) + // implementation: void gdImageJpeg(gdImagePtr im, char *szFile) +{ + GDImageSaveTo( IMAGE_JPEG ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGIF ) // original: void gdImageGif(gdImagePtr im, FILE *out) + // implementation: void gdImageGif(gdImagePtr im, char *szFile) +{ + GDImageSaveTo( IMAGE_GIF ); +} + +HB_FUNC( GDIMAGEPNG ) // original: void gdImagePngEx(gdImagePtr im, FILE *out, int level) + // implementation: void gdImagePng(gdImagePtr im, char *szFile [, int level] ) +{ + GDImageSaveTo( IMAGE_PNG ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEWBMP ) // original: void gdImageWBMP(gdImagePtr im, FILE *out) + // implementation: void gdImageWBMP(gdImagePtr im, char *szFile, int fg) +{ + GDImageSaveTo( IMAGE_WBMP ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGD ) // original: void gdImageGD(gdImagePtr im, FILE *out) + // implementation: void gdImageGD(gdImagePtr im, char *szFile) +{ + GDImageSaveTo( IMAGE_GD ); +} + + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEDESTROY ) // gdImageDestroy(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Destroy the image */ + gdImageDestroy( im ); + + } +} + + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* DRAWING FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETPIXEL ) // void gdImageSetPixel(gdImagePtr im, int x, int y, int color) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x, y; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve coord values */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + + /* Retrieve color value */ + color = hb_parni( 4 ); + + /* Draw a rectangle */ + gdImageSetPixel(im, x, y, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETPIXEL", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGELINE ) // void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve coord values */ + x1 = hb_parni( 2 ); + y1 = hb_parni( 3 ); + x2 = hb_parni( 4 ); + y2 = hb_parni( 5 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Draw a rectangle */ + gdImageLine(im, x1, y1, x2, y2, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGELINE", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEDASHEDLINE ) // void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve coord values */ + x1 = hb_parni( 2 ); + y1 = hb_parni( 3 ); + x2 = hb_parni( 4 ); + y2 = hb_parni( 5 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Draw a rectangle */ + gdImageDashedLine(im, x1, y1, x2, y2, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEDASHEDLINE", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEPOLYGON ) // original: void gdImagePolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color) + // implementation: void gdImagePolygon(gdImagePtr im, gdPointPtr points, int color) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_ARRAY && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + //gdPointPtr points; + int pointsTotal; + int color; + PHB_ITEM pPoints; + int i; + + /* Max Points of polygon */ + gdPoint points[50]; // TODO: make this dynamic + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point array */ + pPoints = hb_param( 2, HB_IT_ARRAY ); + pointsTotal = hb_arrayLen( pPoints ); + + for( i = 0; i < pointsTotal; i ++ ) + { + PHB_ITEM pPoint = hb_arrayGetItemPtr( pPoints, i+1 ); + if( HB_IS_ARRAY( pPoint ) ) + { + points[ i ].x = hb_arrayGetNI( pPoint, 1 ); + points[ i ].y = hb_arrayGetNI( pPoint, 2 ); + } + } + + /* Retrieve color value */ + color = hb_parni( 3 ); + + /* Draw a polygon */ + gdImagePolygon(im, (gdPointPtr) points, pointsTotal, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEPOLYGON", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ +#if ( GD_VERS >= 2033 ) +HB_FUNC( GDIMAGEOPENPOLYGON ) // original: void gdImageOpenPolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color) + // implementation: void gdImageOpenPolygon(gdImagePtr im, gdPointPtr points, int color) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_ARRAY && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + //gdPointPtr points; + int pointsTotal; + int color; + PHB_ITEM pPoints; + int i; + + /* Max Points of polygon */ + gdPoint points[50]; // TODO: make this dynamic + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point array */ + pPoints = hb_param( 2, HB_IT_ARRAY ); + pointsTotal = hb_arrayLen( pPoints ); + + for( i = 0; i < pointsTotal; i ++ ) + { + PHB_ITEM pPoint = hb_arrayGetItemPtr( pPoints, i+1 ); + if( HB_IS_ARRAY( pPoint ) ) + { + points[ i ].x = hb_arrayGetNI( pPoint, 1 ); + points[ i ].y = hb_arrayGetNI( pPoint, 2 ); + } + } + + /* Retrieve color value */ + color = hb_parni( 3 ); + + /* Draw a polygon */ + gdImageOpenPolygon(im, (gdPointPtr) points, pointsTotal, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEOPENPOLYGON", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} +#endif // ( GD_VERS >= 2033 ) + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGERECTANGLE ) // void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve coord values */ + x1 = hb_parni( 2 ); + y1 = hb_parni( 3 ); + x2 = hb_parni( 4 ); + y2 = hb_parni( 5 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Draw a rectangle */ + gdImageRectangle(im, x1, y1, x2, y2, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGERECTANGLE", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +//HB_FUNC( GDIMAGEELLIPSE ) // void gdImageEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color) +//{ +// if ( hb_pcount() == 6 && +// hb_parinfo( 1 ) & HB_IT_POINTER && +// hb_parinfo( 2 ) & HB_IT_NUMERIC && +// hb_parinfo( 3 ) & HB_IT_NUMERIC && +// hb_parinfo( 4 ) & HB_IT_NUMERIC && +// hb_parinfo( 5 ) & HB_IT_NUMERIC && +// hb_parinfo( 6 ) & HB_IT_NUMERIC +// ) +// { +// gdImagePtr im; +// int cx, cy, w, h, color; +// +// /* Retrieve image pointer */ +// im = (gdImagePtr) hb_parptr( 1 ); +// +// /* Retrieve point values */ +// cx = hb_parni( 2 ); +// cy = hb_parni( 3 ); +// /* Retrieve width and height values */ +// w = hb_parni( 4 ); +// h = hb_parni( 5 ); +// /* Retrieve color value */ +// color = hb_parni( 6 ); +// +// /* Draw an ellipse */ +// gdImageEllipse(im, cx, cy, w, h, color); +// +// } +// else +// { +// // Parameter error +// { +// hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, +// "GDIMAGEELLIPSE", 2, +// hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), +// hb_paramError( 5 ), hb_paramError( 6 ) ); +// return; +// } +// } +//} +// +///* ---------------------------------------------------------------------------*/ +// +HB_FUNC( GDIMAGEFILLEDPOLYGON ) // original: void gdImageFilledPolygon(gdImagePtr im, gdPointPtr points, int pointsTotal, int color) + // implementation: void gdImageFilledPolygon(gdImagePtr im, gdPointPtr points, int color) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_ARRAY && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + //gdPointPtr points; + int pointsTotal; + int color; + PHB_ITEM pPoints; + int i; + + /* Max Points of polygon */ + gdPoint points[50]; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point array */ + pPoints = hb_param( 2, HB_IT_ARRAY ); + pointsTotal = hb_arrayLen( pPoints ); + + for( i = 0; i < pointsTotal; i ++ ) + { + PHB_ITEM pPoint = hb_arrayGetItemPtr( pPoints, i+1 ); + if( HB_IS_ARRAY( pPoint ) ) + { + points[ i ].x = hb_arrayGetNI( pPoint, 1 ); + points[ i ].y = hb_arrayGetNI( pPoint, 2 ); + } + } + + /* Retrieve color value */ + color = hb_parni( 3 ); + + /* Draw a filled polygon */ + gdImageFilledPolygon(im, (gdPointPtr) points, pointsTotal, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILLEDPOLYGON", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEFILLEDRECTANGLE ) // void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve coord values */ + x1 = hb_parni( 2 ); + y1 = hb_parni( 3 ); + x2 = hb_parni( 4 ); + y2 = hb_parni( 5 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Draw a filled rectangle */ + gdImageFilledRectangle(im, x1, y1, x2, y2, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILLEDRECTANGLE", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEARC ) // void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color) +{ + if ( hb_pcount() == 8 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int cx, cy, w, h, s, e, color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point values */ + cx = hb_parni( 2 ); + cy = hb_parni( 3 ); + /* Retrieve width and height values */ + w = hb_parni( 4 ); + h = hb_parni( 5 ); + /* Retrieve starting and ending degree values */ + s = hb_parni( 6 ); + e = hb_parni( 7 ); + /* Retrieve color value */ + color = hb_parni( 8 ); + + /* Draw an arc */ + gdImageArc(im, cx, cy, w, h, s, e, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEARC", 8, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEFILLEDARC ) // void gdImageFilledArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color[, int style]) +{ + if ( hb_pcount() >= 8 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int cx, cy, w, h, s, e, color, style; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point values */ + cx = hb_parni( 2 ); + cy = hb_parni( 3 ); + /* Retrieve width and height values */ + w = hb_parni( 4 ); + h = hb_parni( 5 ); + /* Retrieve starting and ending degree values */ + s = hb_parni( 6 ); + e = hb_parni( 7 ); + /* Retrieve color value */ + color = hb_parni( 8 ); + + /* Retrieve style value */ + style = ( hb_parinfo( 9 ) & HB_IT_NUMERIC ? hb_parni( 9 ) : gdNoFill ); + + /* Draw a filled arc */ + gdImageFilledArc(im, cx, cy, w, h, s, e, color, style); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILLEDARC", 9, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEFILLEDELLIPSE ) // void gdImageFilledEllipse(gdImagePtr im, int cx, int cy, int w, int h, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int cx, cy, w, h, color; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve point values */ + cx = hb_parni( 2 ); + cy = hb_parni( 3 ); + /* Retrieve width and height values */ + w = hb_parni( 4 ); + h = hb_parni( 5 ); + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Draw a filled ellipse */ + gdImageFilledEllipse(im, cx, cy, w, h, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILLEDELLIPSE", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEFILLTOBORDER ) // void gdImageFillToBorder(gdImagePtr im, int x, int y, int border, int color) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x, y, border, color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve point values */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + /* Retrieve color to use as border */ + border = hb_parni( 4 ); + /* Retrieve color value */ + color = hb_parni( 5 ); + + /* Fill image to border */ + gdImageFillToBorder(im, x, y, border, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILLTOBORDER", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEFILL ) // void gdImageFill(gdImagePtr im, int x, int y, int color) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x, y, color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve point values */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + /* Retrieve color value */ + color = hb_parni( 4 ); + + /* Fill image */ + gdImageFill(im, x, y, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEFILL", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETANTIALIASED ) // void gdImageSetAntiAliased(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve color value */ + color = hb_parni( 2 ); + + /* Set Antialias */ + gdImageSetAntiAliased(im, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETANTIALIASED", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETANTIALIASEDDONTBLEND ) // void gdImageSetAntiAliasedDontBlend(gdImagePtr im, int c, int dont_blend) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + int dont_blend; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve color value */ + color = hb_parni( 2 ); + + /* Retrieve dont_blend value */ + dont_blend = hb_parni( 3 ); + + /* Set Antialias but don't blend */ + gdImageSetAntiAliasedDontBlend(im, color, dont_blend); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETANTIALIASEDDONTBLEND", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETBRUSH ) // void gdImageSetBrush(gdImagePtr im, gdImagePtr brush) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + gdImagePtr brush; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve brush pointer */ + brush = (gdImagePtr)hb_parptr( 2 ); + + /* Set Brush */ + gdImageSetBrush(im, brush); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETBRUSH", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETTILE ) // void gdImageSetTile(gdImagePtr im, gdImagePtr tile) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + gdImagePtr tile; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve tile pointer */ + tile = (gdImagePtr)hb_parptr( 2 ); + + /* Set Tile */ + gdImageSetTile(im, tile); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETTILE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETSTYLE ) // original: void gdImageSetStyle(gdImagePtr im, int *style, int styleLength) + // implementation: void gdImageSetStyle(gdImagePtr im, int *style) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_ARRAY + ) + { + gdImagePtr im; + PHB_ITEM pStyles; + int styleLength; + int i; + + /* Max numbery of Styles */ + int styles[50]; // TODO: make this dynamic + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve style array */ + pStyles = hb_param( 2, HB_IT_ARRAY ); + styleLength = hb_arrayLen( pStyles ); + + for( i = 0; i < styleLength; i ++ ) + { + styles[ i ] = hb_arrayGetNI( pStyles, i+1 ); + } + + /* Set style */ + gdImageSetStyle(im, (int *) styles, styleLength); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETSTYLE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETTHICKNESS ) // void gdImageSetThickness(gdImagePtr im, int thickness) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int thickness; + int oldthick; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve thickness value */ + thickness = hb_parni( 2 ); + + /* Previous value */ + oldthick = im->thick; + + /* Set thickness */ + gdImageSetThickness(im, thickness); + + /* Return previous */ + hb_retni( oldthick ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETTHICKNESS", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEALPHABLENDING ) // void gdImageAlphaBlending(gdImagePtr im, int blending) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL + ) + { + gdImagePtr im; + int blending; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve blending value - logical */ + blending = hb_parl( 2 ); + + /* Set blending */ + gdImageAlphaBlending(im, blending); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEALPHABLENDING", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESAVEALPHA ) // void gdImageSaveAlpha(gdImagePtr im, int saveFlag) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL + ) + { + gdImagePtr im; + int saveFlag; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value - logical */ + saveFlag = hb_parl( 2 ); + + /* Set saveFlag */ + gdImageSaveAlpha(im, saveFlag); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESAVEALPHA", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESETCLIP ) // void gdImageSetClip(gdImagePtr im, int x1, int y1, int x2, int y2) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve coords value */ + x1 = hb_parni( 2 ); + y1 = hb_parni( 3 ); + x2 = hb_parni( 4 ); + y2 = hb_parni( 5 ); + + /* Set clipping rectangle */ + gdImageSetClip(im, x1, y1, x2, y2); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESETCLIP", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGETCLIP ) // original: void gdImageGetClip(gdImagePtr im, int *x1P, int *y1P, int *x2P, int *y2P) + // implementation: array gdImageGetClip(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + int x1, y1, x2, y2; + PHB_ITEM pClipArray; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Get clipping rectangle */ + gdImageGetClip(im, &x1, &y1, &x2, &y2); + + /* Return clipping rectangle value in an array */ + pClipArray = hb_itemArrayNew( 4 ); + hb_itemPutNI( hb_arrayGetItemPtr( pClipArray, 1 ), x1 ); + hb_itemPutNI( hb_arrayGetItemPtr( pClipArray, 2 ), y1 ); + hb_itemPutNI( hb_arrayGetItemPtr( pClipArray, 3 ), x2 ); + hb_itemPutNI( hb_arrayGetItemPtr( pClipArray, 4 ), y2 ); + + /* return array */ + hb_itemRelease( hb_itemReturnForward( pClipArray ) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGETCLIP", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* QUERY FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + + +HB_FUNC( GDIMAGECOLORSTOTAL ) // int gdImageColorsTotal(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Get Colors total */ + hb_retni( gdImageColorsTotal(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORSTOTAL", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEALPHA ) // int gdImageAlpha(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Get Alpha Level */ + hb_retni( gdImageAlpha(im, color) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEALPHA", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGERED ) // int gdImageRed(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Get Red Level */ + hb_retni( gdImageRed(im, color) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGERED", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGREEN ) // int gdImageGreen(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Get Green Level */ + hb_retni( gdImageGreen(im, color) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGREEN", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEBLUE ) // int gdImageBlue(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Get Blue Level */ + hb_retni( gdImageBlue(im, color) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEBLUE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESX ) // int gdImageSX(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Get Image Width in pixels */ + hb_retni( gdImageSX(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESX", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESY ) // int gdImageSX(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Get Image Height in pixels */ + hb_retni( gdImageSY(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESY", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGETPIXEL ) // int gdImageGetPixel(gdImagePtr im, int x, int y) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x,y; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve coord value */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + + /* Get Color of a pixel */ + hb_retni( gdImageGetPixel(im, x, y) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGETPIXEL", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEBOUNDSSAFE ) // int gdImageBoundsSafe(gdImagePtr im, int x, int y) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x,y; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve coord value */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + + /* Get if pixel in Clipping region */ + hb_retl( gdImageBoundsSafe(im, x, y) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEBOUNDSSAFE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGETINTERLACED ) // int gdImageGetInterlaced(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Image is interlaced ? */ + hb_retl( gdImageGetInterlaced(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGETINTERLACED", 3, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGETTRANSPARENT ) // int gdImageGetTransparent(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Image is trasparent ? */ + hb_retl( gdImageGetTransparent(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGETTRANSPARENT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGETRUECOLOR ) // int gdImageTrueColor(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Is TrueColor ? */ + hb_retl( gdImageTrueColor(im) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGETRUECOLOR", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGETRUECOLORTOPALETTE ) // void gdImageTrueColorToPalette (gdImagePtr im, int ditherFlag, int colorsWanted) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int ditherFlag, colorsWanted; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve ditherFlag - logical */ + ditherFlag = hb_parl( 2 ); + + /* Retrieve number of color wanted */ + colorsWanted = hb_parni( 3 ); + + /* Converts a truecolor image to a palette-based image */ + gdImageTrueColorToPalette(im, ditherFlag, colorsWanted); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGETRUECOLORTOPALETTE", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECREATEPALETTEFROMTRUECOLOR ) // gdImagePtr gdImageCreatePaletteFromTrueColor(gdImagePtr im, int ditherFlag, int colorsWanted) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + gdImagePtr imNew; + int ditherFlag, colorsWanted; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve ditherFlag - logical */ + ditherFlag = hb_parl( 2 ); + + /* Retrieve number of color wanted */ + colorsWanted = hb_parni( 3 ); + + /* Converts a truecolor image to a palette-based image and return the image */ + imNew = gdImageCreatePaletteFromTrueColor(im, ditherFlag, colorsWanted); + + /* Return image pointer */ + hb_retptr( imNew ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECREATEPALETTEFROMTRUECOLOR", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEPALETTEPIXEL ) // int gdImagePalettePixel(gdImagePtr im, int x, int y) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x,y; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve coord value */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + + /* Get Color of a pixel */ + hb_retni( gdImagePalettePixel(im, x, y) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEPALETTEPIXEL", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGETRUECOLORPIXEL ) // int gdImageTrueColorPixel(gdImagePtr im, int x, int y) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int x,y; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve coord value */ + x = hb_parni( 2 ); + y = hb_parni( 3 ); + + /* Get Color of a pixel */ + hb_retni( gdImageTrueColorPixel(im, x, y) ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGETRUECOLORPIXEL", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEGETTHICKNESS ) // void gdImageGetThickness(gdImagePtr im) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdImagePtr im; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Return previous */ + hb_retni( im->thick ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGETTHICKNESS", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* FONTS AND TEXT-HANDLING FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETSMALL ) // gdFontPtr gdFontGetSmall(void) +{ + gdFontPtr font; + + /* Get font pointer */ + font = gdFontGetSmall(); + + /* Return font pointer */ + hb_retptr( font ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETLARGE ) // gdFontPtr gdFontGetLarge(void) +{ + gdFontPtr font; + + /* Get font pointer */ + font = gdFontGetLarge(); + + /* Return font pointer */ + hb_retptr( font ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETMEDIUMBOLD ) // gdFontPtr gdFontGetMediumBold(void) +{ + gdFontPtr font; + + /* Get font pointer */ + font = gdFontGetMediumBold(); + + /* Return font pointer */ + hb_retptr( font ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETGIANT ) // gdFontPtr gdFontGetGiant(void) +{ + gdFontPtr font; + + /* Get font pointer */ + font = gdFontGetGiant(); + + /* Return font pointer */ + hb_retptr( font ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETTINY ) // gdFontPtr gdFontGetTiny(void) +{ + gdFontPtr font; + + /* Get font pointer */ + font = gdFontGetTiny(); + + /* Return font pointer */ + hb_retptr( font ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESTRING ) // void gdImageChar(gdImagePtr im, gdFontPtr font, int x, int y, int c, int color) + // void gdImageString(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_STRING && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + gdFontPtr font; + int x, y, c, color; + unsigned char *s; + + /* Retrieve image pointer */ + im = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve font pointer */ + font = (gdFontPtr)hb_parptr( 2 ); + + /* Retrieve coord value */ + x = hb_parni( 3 ); + y = hb_parni( 4 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Write char */ + if ( hb_parclen(5) == 1 ) + { + /* Retrieve char value */ + c = hb_parni( 5 ); + gdImageChar(im, font, x, y, c, color); + } + else + { + /* Retrieve string value */ + s = ( unsigned char * )hb_parcx( 5 ); + gdImageString(im, font, x, y, s, color); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESTRING", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESTRINGUP ) // void gdImageCharUp(gdImagePtr im, gdFontPtr font, int x, int y, int c, int color) + // void gdImageStringUp(gdImagePtr im, gdFontPtr font, int x, int y, unsigned char *s, int color) +{ + if ( hb_pcount() == 6 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_STRING && + hb_parinfo( 6 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + gdFontPtr font; + int x, y, c, color; + unsigned char *s; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve font pointer */ + font = (gdFontPtr)hb_parptr( 2 ); + + /* Retrieve coord value */ + x = hb_parni( 3 ); + y = hb_parni( 4 ); + + /* Retrieve color value */ + color = hb_parni( 6 ); + + /* Write char */ + if ( hb_parclen(5) == 1 ) + { + /* Retrieve char value */ + c = hb_parni( 5 ); + gdImageCharUp(im, font, x, y, c, color); + } + else + { + /* Retrieve string value */ + s = ( unsigned char * )hb_parcx( 5 ); + gdImageStringUp(im, font, x, y, s, color); + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESTRINGUP", 6, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ +// char *gdImageStringFTEx(gdImagePtr im, int *brect, int fg, char *fontname, double ptsize, double angle, int x, int y, char *string, gdFTStringExtraPtr strex) +// implementation: cError := gdImageStringFTEx( im, aRect, int fg, cFontname, nPtSize, nAngle, x, y, cString, nLinespacing, nCharmap, nResolution ) +HB_FUNC( GDIMAGESTRINGFTEX ) +{ + // TraceLog( NULL, "Parameters: %i, Type 1 =%i=\n\r", hb_pcount(), hb_parinfo( 1 ) ); + + if ( hb_pcount() >= 9 && + ( ISNIL(1) || hb_parinfo( 1 ) & ( HB_IT_POINTER ) ) && + hb_parinfo( 2 ) & HB_IT_ARRAY && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_STRING && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_STRING + ) + { + gdImagePtr im; + gdFTStringExtra extra; + int fg; + char *fontname; + double ptsize, angle; + int x, y, i; + char *string; + PHB_ITEM pRect; + int aRect[8]; + char *err; + int flags; + double linespacing; + int charmap; + int resolution; + + /* Retrieve image pointer */ + im = (gdImagePtr)( hb_parinfo( 1 ) & HB_IT_POINTER ? hb_parptr( 1 ) : NULL ); + //TraceLog( NULL, "Image pointer: %p\n\r", im ); + + /* Retrieve rectangle array */ + pRect = hb_param( 2, HB_IT_ARRAY ); + for( i = 0; i < 8; i ++ ) + { + aRect[ i ] = hb_arrayGetNI( pRect, i+1 ); + } + + /* Retrieve foreground color value */ + fg = hb_parni( 3 ); + //TraceLog( NULL, "Forecolor: %i\n\r", fg ); + + /* Retrieve fontname value */ + fontname = hb_parc( 4 ); + //TraceLog( NULL, "Font: %s\n\r", fontname ); + + /* Retrieve point size value */ + ptsize = hb_parni( 5 ); + //TraceLog( NULL, "PTSize: %lf\n\r", ptsize ); + + /* Retrieve angle value in radians */ + angle = hb_parnd( 6 ); + //TraceLog( NULL, "Angle: %lf\n\r", angle ); + + /* Retrieve pos value */ + x = hb_parni( 7 ); + y = hb_parni( 8 ); + //TraceLog( NULL, "Pos: %i, %i\n\r", x, y ); + + /* Retrieve string value */ + string = hb_parcx( 9 ); + //TraceLog( NULL, "String: %s\n\r", string ); + + /* EXTENDED FLAGS */ + flags = 0; + + /* defaults */ + linespacing = 1.05; + charmap = gdFTEX_Unicode; + resolution = 96; + + /* Retrieve line spacing */ + if ( hb_parinfo( 10 ) & HB_IT_DOUBLE ) + { + linespacing = hb_parnd( 10 ); + flags |= gdFTEX_LINESPACE; + } + + /* Retrieve charmap */ + if ( hb_parinfo( 11 ) & HB_IT_NUMERIC ) + { + charmap = hb_parni( 11 ); + flags |= gdFTEX_CHARMAP; + } + + /* Retrieve resolution */ + if ( hb_parinfo( 12 ) & HB_IT_NUMERIC ) + { + resolution = hb_parni( 12 ); + flags |= gdFTEX_RESOLUTION; + } + + if ( !( flags == 0 ) ) + { + extra.flags = flags; + extra.linespacing = ( flags & gdFTEX_LINESPACE ? linespacing : 1.05 ); + extra.charmap = ( flags & gdFTEX_CHARMAP ? charmap : gdFTEX_Unicode ); + extra.hdpi = ( flags & gdFTEX_RESOLUTION ? resolution : 96 ); + extra.vdpi = ( flags & gdFTEX_RESOLUTION ? resolution : 96 ); + } + + /* Write string */ + err = gdImageStringFTEx(im, &aRect[0], fg, fontname, ptsize, angle, x, y, string, ( !( flags == 0 ) ? &extra : 0 )); + if ( !( err ) ) + { + /* Save in array the correct text rectangle dimensions */ + PHB_ITEM pRect; + for( i = 0; i < 8; i ++ ) + { + hb_itemPutNI( hb_arrayGetItemPtr( pRect, i+1 ), aRect[i] ); + } + } + hb_retc( err ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESTRINGFTEX", 12, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ), hb_paramError( 10 ), hb_paramError( 11 ), hb_paramError( 12 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESTRINGFTCIRCLE ) // char *gdImageStringFTCircle(gdImagePtr im, int cx, int cy, double radius, double textRadius, double fillPortion, char *font, double points, char *top, char *bottom, int fgcolor) +{ + //TraceLog( NULL, "Parameters: %i, Type 9 =%i=\n\r", hb_pcount(), hb_parinfo( 10 ) ); + + if ( hb_pcount() == 11 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_STRING && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + ( ISNIL( 9 ) || ( hb_parinfo( 9 ) & HB_IT_STRING ) ) && + ( ISNIL( 10 ) || ( hb_parinfo( 10 ) & HB_IT_STRING ) ) && + hb_parinfo( 11 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int cx, cy; + double radius, textRadius, fillPortion, points; + char *top; + char *bottom; + int fgcolor; + char *font; + char *err; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve pos value */ + cx = hb_parni( 2 ); + cy = hb_parni( 3 ); + + /* Retrieve radius value */ + radius = hb_parnd( 4 ); + + /* Retrieve textRadius value */ + textRadius = hb_parnd( 5 ); + + /* Retrieve textRadius value */ + fillPortion = hb_parnd( 6 ); + + /* Retrieve fontname value */ + font = hb_parcx( 7 ); + + /* Retrieve points value */ + points = hb_parnd( 8 ); + + /* Retrieve top string value */ + top = hb_parcx( 9 ); + + /* Retrieve top string value */ + bottom = hb_parcx( 10 ); + + /* Retrieve foreground color value */ + fgcolor = hb_parni( 11 ); + + /* Write string */ + err = gdImageStringFTCircle(im, cx, cy, radius, textRadius, fillPortion, font, points, top, bottom, fgcolor); + hb_retc( err ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESTRINGFTCIRCLE", 11, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ), hb_paramError( 10 ), hb_paramError( 11 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTCACHESETUP ) // int gdFontCacheSetup (void) +{ + /* This function initializes the font cache for freetype text output functions */ + hb_retl( gdFontCacheSetup() ); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTCACHESHUTDOWN ) // void gdFontCacheShutdown (void) +{ + /* This function initializes the font cache for freetype text output functions */ + gdFontCacheShutdown(); +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETWIDTH ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdFontPtr font; + + /* Retrieve font pointer */ + font = (gdFontPtr)hb_parptr( 1 ); + + /* Return value */ + hb_retni( font->w ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDFONTGETWIDTH", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDFONTGETHEIGHT ) +{ + if ( hb_pcount() == 1 && + hb_parinfo( 1 ) & HB_IT_POINTER + ) + { + gdFontPtr font; + + /* Retrieve font pointer */ + font = (gdFontPtr)hb_parptr( 1 ); + + /* Return value */ + hb_retni( font->h ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDFONTGETHEIGHT", 1, + hb_paramError( 1 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* COLOR HANDLING FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORALLOCATE ) // int gdImageColorAllocate(gdImagePtr im, int r, int g, int b) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Allocate color */ + color = gdImageColorAllocate(im, r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORALLOCATE", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORDEALLOCATE ) // void gdImageColorDeallocate(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Deallocate color */ + gdImageColorDeallocate(im, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORDEALLOCATE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORALLOCATEALPHA ) // int gdImageColorAllocateAlpha(gdImagePtr im, int r, int g, int b, int a) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + int a; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Retrieve Alpha value */ + a = hb_parni( 5 ); + + /* Allocate color */ + color = gdImageColorAllocateAlpha(im, r, g, b, a); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORALLOCATEALPHA", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORCLOSEST ) // int gdImageColorClosest(gdImagePtr im, int r, int g, int b) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Search color closest */ + color = gdImageColorClosest(im, r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORCLOSEST", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORCLOSESTALPHA ) // int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + int a; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Retrieve Alpha value */ + a = hb_parni( 5 ); + + /* Allocate color */ + color = gdImageColorClosestAlpha(im, r, g, b, a); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORCLOSESTALPHA", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORCLOSESTHWB ) // gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Search color closest */ + color = gdImageColorClosestHWB(im, r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORCLOSESTHWB", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLOREXACT ) // int gdImageColorExact(gdImagePtr im, int r, int g, int b) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Search if there is the color */ + color = gdImageColorExact(im, r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLOREXACT", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORRESOLVE ) // int gdImageColorResolve(gdImagePtr im, int r, int g, int b) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Search if there is the color or similar, if not it creates */ + color = gdImageColorResolve(im, r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORRESOLVE", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORRESOLVEALPHA ) // int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a) +{ + if ( hb_pcount() == 5 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int r, g, b; + int color; + int a; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve RGB values */ + r = hb_parni( 2 ); + g = hb_parni( 3 ); + b = hb_parni( 4 ); + + /* Retrieve Alpha value */ + a = hb_parni( 5 ); + + /* Allocate color */ + color = gdImageColorResolveAlpha(im, r, g, b, a); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORRESOLVEALPHA", 5, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOLORTRANSPARENT ) // void gdImageColorTransparent(gdImagePtr im, int color) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int color; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve saveFlag value */ + color = hb_parni( 2 ); + + /* Set transparent color (to define no transparent color set -1) */ + gdImageColorTransparent(im, color); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOLORTRANSPARENT", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDTRUECOLOR ) // int gdTrueColor(int red, int green, int blue) +{ + if ( hb_pcount() == 3 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC + ) + { + int r, g, b; + int color; + + /* Retrieve RGB values */ + r = hb_parni( 1 ); + g = hb_parni( 2 ); + b = hb_parni( 3 ); + + /* Allocate color */ + color = gdTrueColor(r, g, b); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDTRUECOLOR", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDTRUECOLORALPHA ) // int gdTrueColorAlpha(int red, int green, int blue, int alpha) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_NUMERIC && + hb_parinfo( 2 ) & HB_IT_NUMERIC && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + int r, g, b, a; + int color; + + /* Retrieve RGB values */ + r = hb_parni( 1 ); + g = hb_parni( 2 ); + b = hb_parni( 3 ); + a = hb_parni( 4 ); + + /* Allocate color */ + color = gdTrueColorAlpha(r, g, b, a); + + /* return color */ + hb_retni( color ); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDTRUECOLORALPHA", 4, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* COPY AND RESIZING FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPY ) // void gdImageCopy(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h) +{ + if ( hb_pcount() == 8 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + int dstX, dstY, srcX, srcY, w, h; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parni( 3 ); + dstY = hb_parni( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve width value */ + w = hb_parni( 7 ); + + /* Retrieve height value */ + h = hb_parni( 8 ); + + /* Perform copy */ + gdImageCopy(dst, src, dstX, dstY, srcX, srcY, w, h); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPY", 8, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPYRESIZED ) // void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) +{ + if ( hb_pcount() == 10 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_NUMERIC && + hb_parinfo( 10 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + int dstX, dstY, srcX, srcY; + int dstW, dstH, srcW, srcH; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parni( 3 ); + dstY = hb_parni( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve dest width value */ + dstW = hb_parni( 7 ); + + /* Retrieve dest height value */ + dstH = hb_parni( 8 ); + + /* Retrieve source width value */ + srcW = hb_parni( 9 ); + + /* Retrieve source height value */ + srcH = hb_parni( 10 ); + + /* Perform copy */ + gdImageCopyResized(dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYRESIZED", 10, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ), hb_paramError( 10 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPYRESAMPLED ) // void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) +{ + if ( hb_pcount() == 10 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_NUMERIC && + hb_parinfo( 10 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + int dstX, dstY, srcX, srcY; + int dstW, dstH, srcW, srcH; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parni( 3 ); + dstY = hb_parni( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve dest width value */ + dstW = hb_parni( 7 ); + + /* Retrieve dest height value */ + dstH = hb_parni( 8 ); + + /* Retrieve source width value */ + srcW = hb_parni( 9 ); + + /* Retrieve source height value */ + srcH = hb_parni( 10 ); + + /* Perform copy */ + gdImageCopyResampled(dst, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYRESAMPLED", 10, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ), hb_paramError( 10 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPYROTATED ) // void gdImageCopyRotated(gdImagePtr dst, gdImagePtr src, double dstX, double dstY, int srcX, int srcY, int srcW, int srcH, int angle) +{ + if ( hb_pcount() == 9 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + double dstX, dstY; + int srcX, srcY, srcW, srcH, angle; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parnd( 3 ); + dstY = hb_parnd( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve source width value */ + srcW = hb_parni( 7 ); + + /* Retrieve source height value */ + srcH = hb_parni( 8 ); + + /* Retrieve angle value */ + angle = hb_parni( 9 ); + + /* Perform rotation */ + gdImageCopyRotated(dst, src, dstX, dstY, srcX, srcY, srcW, srcH, angle); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYROTATED", 9, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPYMERGE ) // void gdImageCopyMerge(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) +{ + if ( hb_pcount() == 9 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + int dstX, dstY, srcX, srcY, w, h, pct; + + /* Retrieve destination image pointer */ + dst =(gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parni( 3 ); + dstY = hb_parni( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve width value */ + w = hb_parni( 7 ); + + /* Retrieve height value */ + h = hb_parni( 8 ); + + /* Retrieve percentual value */ + pct = hb_parni( 9 ); + + /* Perform copy */ + gdImageCopyMerge(dst, src, dstX, dstY, srcX, srcY, w, h, pct); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYMERGE", 9, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOPYMERGEGRAY ) // void gdImageCopyMergeGray(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) +{ + if ( hb_pcount() == 9 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + hb_parinfo( 8 ) & HB_IT_NUMERIC && + hb_parinfo( 9 ) & HB_IT_NUMERIC + ) + { + gdImagePtr dst, src; + int dstX, dstY, srcX, srcY, w, h, pct; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Retrieve destination pos value */ + dstX = hb_parni( 3 ); + dstY = hb_parni( 4 ); + + /* Retrieve source pos value */ + srcX = hb_parni( 5 ); + srcY = hb_parni( 6 ); + + /* Retrieve width value */ + w = hb_parni( 7 ); + + /* Retrieve height value */ + h = hb_parni( 8 ); + + /* Retrieve percentual value */ + pct = hb_parni( 9 ); + + /* Perform copy */ + gdImageCopyMergeGray(dst, src, dstX, dstY, srcX, srcY, w, h, pct); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYMERGEGRAY", 9, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ), + hb_paramError( 9 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEPALETTECOPY ) // void gdImagePaletteCopy(gdImagePtr dst, gdImagePtr src) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER + ) + { + gdImagePtr dst, src; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Perform copy */ + gdImagePaletteCopy(dst, src); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOPYMERGEGRAY", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESQUARETOCIRCLE ) // void gdImageSquareToCircle(gdImagePtr im, int radius) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int radius; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve radius value */ + radius = hb_parni( 2 ); + + /* TODO */ + gdImageSquareToCircle(im, radius); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESQUARETOCIRCLE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGESHARPEN ) // void gdImageSharpen(gdImagePtr im, int pct) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + int pct; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve percentual value */ + pct = hb_parni( 2 ); + + /* Sharpens the specified image */ + gdImageSharpen(im, pct); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGESHARPEN", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +/* ---------------------------------------------------------------------------*/ +/* MISCELLANEOUS FUNCTIONS */ +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGECOMPARE ) // int gdImageCompare(gdImagePtr im1, gdImagePtr im2) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_POINTER + ) + { + gdImagePtr dst, src; + + /* Retrieve destination image pointer */ + dst = (gdImagePtr)hb_parptr( 1 ); + + /* Retrieve source image pointer */ + src = (gdImagePtr)hb_parptr( 2 ); + + /* Compare images - if return <> 0 check value for infos */ + hb_retni( gdImageCompare(dst, src) ); + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGECOMPARE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +HB_FUNC( GDIMAGEINTERLACE ) // void gdImageInterlace(gdImagePtr im, int interlace) +{ + if ( hb_pcount() == 2 && + hb_parinfo( 1 ) & HB_IT_POINTER && + hb_parinfo( 2 ) & HB_IT_LOGICAL + ) + { + gdImagePtr im; + int interlace; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve interlace value */ + interlace = hb_parl( 2 ); + + /* Set interlace */ + gdImageInterlace(im, interlace); + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEINTERLACE", 2, + hb_paramError( 1 ), hb_paramError( 2 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +#if ( GD_VERS >= 2033 ) +//BGD_DECLARE(void *) gdImageGifAnimBeginPtr(gdImagePtr im, int *size, int GlobalCM, int Loops); +// implementation: (void *) gdImageGifAnimBegin( gdImagePtr im, cFile | nHandle, int GlobalCM, int Loops); +HB_FUNC( GDIMAGEGIFANIMBEGIN ) +{ + if ( hb_pcount() == 4 && + hb_parinfo( 1 ) & HB_IT_POINTER && + ( hb_parinfo( 2 ) & HB_IT_STRING || hb_parinfo( 2 ) & HB_IT_NUMERIC || ISNIL( 2 ) ) && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC + ) + { + gdImagePtr im; + void *iptr; + int size; + int GlobalCM, Loops; + + /* Retrieve image pointer */ + im = (gdImagePtr) hb_parptr( 1 ); + + /* Retrieve global color map value */ + GlobalCM = hb_parni( 3 ); + + /* Retrieve Loops value */ + Loops = hb_parni( 4 ); + + /* run function */ + iptr = gdImageGifAnimBeginPtr(im, &size, GlobalCM, Loops); + + /* Check if 2nd parameter is a file name or an handle */ + if ( hb_parinfo( 2 ) & HB_IT_STRING ) + { + char *szFile; + szFile = hb_parcx( 2 ); + + SaveImageToFile( szFile, iptr, size ); + } + else if ( hb_parinfo( 2 ) & HB_IT_NUMERIC || ISNIL( 2 ) ) + { + FHANDLE fhandle; + + /* Retrieve file handle */ + fhandle = ( hb_parinfo( 2 ) & HB_IT_NUMERIC ) ? hb_parnl( 2 ) : 1; // 1 = std output + + SaveImageToHandle( fhandle, iptr, size ); + + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGIFANIMBEGIN", 3, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +//BGD_DECLARE(void *) gdImageGifAnimAddPtr(gdImagePtr im, int *size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); +// implementation: (void *) gdImageGifAnimAdd( gdImagePtr im, cFile | nHandle, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm); +HB_FUNC( GDIMAGEGIFANIMADD ) +{ + if ( hb_pcount() == 8 && + hb_parinfo( 1 ) & HB_IT_POINTER && + ( hb_parinfo( 2 ) & HB_IT_STRING || hb_parinfo( 2 ) & HB_IT_NUMERIC || ISNIL( 2 ) ) && + hb_parinfo( 3 ) & HB_IT_NUMERIC && + hb_parinfo( 4 ) & HB_IT_NUMERIC && + hb_parinfo( 5 ) & HB_IT_NUMERIC && + hb_parinfo( 6 ) & HB_IT_NUMERIC && + hb_parinfo( 7 ) & HB_IT_NUMERIC && + ( hb_parinfo( 8 ) & HB_IT_POINTER || ISNIL( 8 ) ) + ) + { + gdImagePtr im, previm; + void *iptr; + int size; + int LocalCM, LeftOfs, TopOfs, Delay, Disposal; + + /* Retrieve parameters */ + im = (gdImagePtr)hb_parptr( 1 ); + + LocalCM = hb_parni( 3 ); + LeftOfs = hb_parni( 4 ); + TopOfs = hb_parni( 5 ); + Delay = hb_parni( 6 ); + Disposal = hb_parni( 7 ); + previm = (gdImagePtr)hb_parptr( 8 ); + + /* Run function and return value */ + iptr = gdImageGifAnimAddPtr(im, &size, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); + + /* Check if 2nd parameter is a file name or an handle */ + if ( hb_parinfo( 2 ) & HB_IT_STRING ) + { + char *szFile; + szFile = hb_parcx( 2 ); + + AddImageToFile( szFile, iptr, size ); + } + else if ( hb_parinfo( 2 ) & HB_IT_NUMERIC || ISNIL( 2 ) ) + { + FHANDLE fhandle; + + /* Retrieve file handle */ + fhandle = ( hb_parinfo( 2 ) & HB_IT_NUMERIC ) ? hb_parnl( 2 ) : 1; // 1 = std output + + SaveImageToHandle( fhandle, iptr, size ); + + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGIFANIMADD", 8, + hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ), hb_paramError( 4 ), + hb_paramError( 5 ), hb_paramError( 6 ), hb_paramError( 7 ), hb_paramError( 8 ) + ); + return; + } + } +} + +/* ---------------------------------------------------------------------------*/ + +//BGD_DECLARE(void *) gdImageGifAnimEndPtr(int *size); +// implementation: gdImageGifAnimEnd( cFile | nHandle ); +HB_FUNC( GDIMAGEGIFANIMEND ) +{ + if ( hb_pcount() == 1 && + ( hb_parinfo( 1 ) & HB_IT_STRING || hb_parinfo( 1 ) & HB_IT_NUMERIC || ISNIL( 1 ) ) + ) + { + void *iptr; + int size; + + /* Run function and return value */ + iptr = gdImageGifAnimEndPtr(&size); + + /* Check if 1st parameter is a file name or an handle */ + if ( hb_parinfo( 1 ) & HB_IT_STRING ) + { + char *szFile; + szFile = hb_parcx( 1 ); + + AddImageToFile( szFile, iptr, size ); + } + else if ( hb_parinfo( 2 ) & HB_IT_NUMERIC || ISNIL( 2 ) ) + { + FHANDLE fhandle; + + /* Retrieve file handle */ + fhandle = ( hb_parinfo( 1 ) & HB_IT_NUMERIC ) ? hb_parnl( 1 ) : 1; // 1 = std output + + SaveImageToHandle( fhandle, iptr, size ); + + } + + } + else + { + // Parameter error + { + hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, + "GDIMAGEGIFANIMEND", 1, + hb_paramError( 1 ) + ); + return; + } + } +} + + +/* ---------------------------------------------------------------------------*/ + +static void AddImageToFile( char *szFile, void *iptr, int sz ) +{ + FHANDLE fhandle; + + if ( ( fhandle = hb_fsOpen( ( BYTE * ) szFile, FO_READWRITE ) ) != FS_ERROR ) + { + /* move to end of file */ + hb_fsSeek(fhandle, 0, FS_END); + + /* Write Image */ + SaveImageToHandle( fhandle, ( BYTE *) iptr, (ULONG) sz ); + + /* Close file */ + hb_fsClose( fhandle ); + } +} + +#endif // ( GD_VERS >= 2033 ) diff --git a/harbour/contrib/gd/hbgd.txt b/harbour/contrib/gd/hbgd.txt new file mode 100644 index 0000000000..a26abceb62 --- /dev/null +++ b/harbour/contrib/gd/hbgd.txt @@ -0,0 +1,2058 @@ +/* + * $Id$ + */ + +/* + * The following parts are Copyright of the individual authors. + * www - http://www.xharbour.org http://www.harbour-project.org + * + * Copyright 2004-2005 Francesco Saverio Giudice + * Documentation for GD Library wrapper functions and classes + * + * See doc/license.txt for licensing terms. + * + */ + +/* $DOC$ + * $FUNCNAME$ + * The GD Library + * $CATEGORY$ + * Document + * $ONELINER$ + * Read me file for GD Library + * $DESCRIPTION$ + * HBGD is basically a wrapper of Thomas Boutell's GD Library version 2.0.33. + * GD Library is a powerfull graphic library very usefull expecially under CGI environment. + * + * HBGD actually contains almost all GD functions, more a set of functions that extends original + * library and a set of classes that make easier to work with this library. + * + * Thomas Boutell's GD library actually supports these graphic formats: + * PNG, JPEG, GIF, Animated GIF, GD, GD2, WBMP, XBM, XPM + * WBMP is Wireless Bitmap, not Windows Bitmap, and it is used for WAP. It is a B&W bitmap. + * + * HBGD actually supports PNG, JPEG, GIF, GD, WBMP + * The other Animated GIF, GD2, XBM and XPM are not wrapped actually. + * + * Using this library you can, as a little example: + * - create an image in memory, true color or with a 256 colors palette; + * - load and save an image of above formats and convert it to another supported format; + * - draw dots, lines, dashed lines, polygons, rectangles, arcs, circles and ellipses; + * - fill with colors; + * - draw with brushes; + * - check a point or part or full image with a lot of query functions; + * - draw characters and words with internal fonts or using truetype fonts; + * - write strings on a base line or on a circle line and with any angle degree; + * - copy, resize and rotate part or full image; + * + * and, over this, some functions to clone, crop, zoom, rotate outside and inside. + * + * The prefix for all functions is GD (i.e. gdImageCreate() ) + * + * You can use directly all API functions or TGD class. + * + * NOTE: Not all functions are wrapped. + * + * $SEEALSO$ + * Alphabetical list of functions, Categorized list of functions, GDImage Class, GDChart Class. + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageCreate() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Create a palette-based image in memory with no more that 256 colors. + * $SYNTAX$ + * gdImageCreate( , ) --> + * $ARGUMENTS$ + * - image width + * - image height + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageCreate() creates an empty image in memory. + * This image has no more than 256 colors. + * + * gdImageCreate() returns an image pointer or NIL if unable to create the image. + * The image pointer must be destroyed using gdImageDestroy() + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageCreate( 64, 64 ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreateTrueColor() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageCreateTrueColor() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Create a true color image in memory. + * $SYNTAX$ + * gdImageCreateTrueColor( , ) --> + * $ARGUMENTS$ + * - image width + * - image height + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageCreateTrueColor() creates an empty image in memory. + * This image has true colors. + * + * gdImageCreateTrueColor() returns an image pointer or NIL if unable to create the image. + * The image pointer must be destroyed using gdImageDestroy() + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageCreateTrueColor( 64, 64 ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageDestroy() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Free memory used from an image. + * $SYNTAX$ + * gdImageDestroy( ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageDestroy() frees memory used from an image. + * It's important to use this function before exiting from a program. + * + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageCreateTrueColor( 64, 64 ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFromJpeg() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Load a JPEG image file. + * $SYNTAX$ + * gdImageFromJpeg( | | [, ] ) --> + * $ARGUMENTS$ + * - Image file name + * - File handle + * - Memory image pointer + * - Image size + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageFromJpeg() creates a JPEG image from a file or a handle or another image in memory. + * + * You can use one of 3 syntax: + * + * pImage := gdImageFromJpeg( "myimage.jpg" ) + * + * or + * + * pImage := gdImageFromJpeg( nFileHandle, nSize ) + * + * or + * + * pImage := gdImageFromJpeg( pMemoryImagePtr, nSize ) + * + * the pImage pointer returned will be not NIL if successfull and will contains a memory pointer + * to the jpeg image. + * + * Remember to free memory with gdImageDestroy() before exit from application. + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromJpeg( "myimage.jpg" ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor(), gdImageDestroy(), gdImageFromGif(), gdImageFromPng(), gdImageFromGD(), gdImageFromWBmp() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFromGif() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Load a Gif image file. + * $SYNTAX$ + * gdImageFromGif( | | [, ] ) --> + * $ARGUMENTS$ + * - Image file name + * - File handle + * - Memory image pointer + * - Image size + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageFromGif() creates a GIF image from a file or a handle or another image in memory. + * + * You can use one of 3 syntax: + * + * pImage := gdImageFromGif( "myimage.gif" ) + * + * or + * + * pImage := gdImageFromGif( nFileHandle, nSize ) + * + * or + * + * pImage := gdImageFromGif( pMemoryImagePtr, nSize ) + * + * the pImage pointer returned will be not NIL if successfull and will contains a memory pointer + * to the gif image. + * + * Remember to free memory with gdImageDestroy() before exit from application. + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromGif( "myimage.gif" ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor(), gdImageDestroy(), gdImageFromJpeg(), gdImageFromPng(), gdImageFromGD(), gdImageFromWBmp() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFromPng() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Load a PNG image file. + * $SYNTAX$ + * gdImageFromPng( | | [, ] ) --> + * $ARGUMENTS$ + * - Image file name + * - File handle + * - Memory image pointer + * - Image size + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageFromPng() creates a PNG image from a file or a handle or another image in memory. + * + * You can use one of 3 syntax: + * + * pImage := gdImageFromPng( "myimage.png" ) + * + * or + * + * pImage := gdImageFromPng( nFileHandle, nSize ) + * + * or + * + * pImage := gdImageFromPng( pMemoryImagePtr, nSize ) + * + * the pImage pointer returned will be not NIL if successfull and will contains a memory pointer + * to the png image. + * + * Remember to free memory with gdImageDestroy() before exit from application. + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromPng( "myimage.png" ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor(), gdImageDestroy(), gdImageFromJpeg(), gdImageFromGif(), gdImageFromGD(), gdImageFromWBmp() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFromGD() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Load a GD image file. + * $SYNTAX$ + * gdImageFromGD( | | [, ] ) --> + * $ARGUMENTS$ + * - Image file name + * - File handle + * - Memory image pointer + * - Image size + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageFromGD() creates a GD image from a file or a handle or another image in memory. + * + * You can use one of 3 syntax: + * + * pImage := gdImageFromGD( "myimage.gd" ) + * + * or + * + * pImage := gdImageFromGD( nFileHandle, nSize ) + * + * or + * + * pImage := gdImageFromGD( pMemoryImagePtr, nSize ) + * + * the pImage pointer returned will be not NIL if successfull and will contains a memory pointer + * to the GD image. + * + * Remember to free memory with gdImageDestroy() before exit from application. + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromGD( "myimage.gd" ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor(), gdImageDestroy(), gdImageFromJpeg(), gdImageFromGif(), gdImageFromPng(), gdImageFromWBmp() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFromWBmp() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Load a WBmp image file. + * $SYNTAX$ + * gdImageFromWBmp( | | [, ] ) --> + * $ARGUMENTS$ + * - Image file name + * - File handle + * - Memory image pointer + * - Image size + * $RETURNS$ + * - Image pointer + * $DESCRIPTION$ + * gdImageFromWBmp() creates a WBmp image from a file or a handle or another image in memory. + * + * You can use one of 3 syntax: + * + * pImage := gdImageFromWBmp( "myimage.wbmp" ) + * + * or + * + * pImage := gdImageFromWBmp( nFileHandle, nSize ) + * + * or + * + * pImage := gdImageFromWBmp( pMemoryImagePtr, nSize ) + * + * the pImage pointer returned will be not NIL if successfull and will contains a memory pointer + * to the WBmp image. + * + * Remember to free memory with gdImageDestroy() before exit from application. + * HBGD uses it's own memory to manage an image, so it is important to use this function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromWBmp( "myimage.wbmp" ) + * // Use here image + * ......... + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageCreate(), gdImageCreateTrueColor(), gdImageDestroy(), gdImageFromJpeg(), gdImageFromGif(), gdImageFromPng(), gdImageFromGD() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageJpeg() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Save a JPEG image. + * $SYNTAX$ + * gdImageJpeg( , | [, ] ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Image file name + * - File handle + * - a numeric value between 0=max compression and 95=min compression (best quality) + * default is -1=auto + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageJpeg() saves a JPEG image to a file or a handle. + * + * You can use one of 2 syntax: + * + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * or + * + * gdImageJpeg( pImage, nFileHandle ) + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromGif( "myimage.gif" ) + * + * // Image conversion + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageFromGif() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageGif() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Save a GIF image. + * $SYNTAX$ + * gdImageGif( , | ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Image file name + * - File handle + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageGif() saves a GIF image to a file or a handle. + * + * You can use one of 2 syntax: + * + * gdImageGif( pImage, "myimage.gif" ) + * + * or + * + * gdImageGif( pImage, nFileHandle ) + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromJpeg( "myimage.jpg" ) + * + * // Image conversion + * gdImageGif( pImage, "myimage.gif" ) + * + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageFromJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImagePng() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Save a PNG image. + * $SYNTAX$ + * gdImagePng( , | [, ] ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Image file name + * - File handle + * - a numeric value between 0=no compression and 9=max compression + * default is -1=auto + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImagePng() saves a PNG image to a file or a handle. + * + * You can use one of 2 syntax: + * + * gdImagePng( pImage, "myimage.png" ) + * + * or + * + * gdImagePng( pImage, nFileHandle ) + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromGif( "myimage.gif" ) + * + * // Image conversion + * gdImagePng( pImage, "myimage.png" ) + * + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageFromGif() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageGD() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Save a GD image. + * $SYNTAX$ + * gdImageGd( , | ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Image file name + * - File handle + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageGd() saves a GD image to a file or a handle. + * + * You can use one of 2 syntax: + * + * gdImageGd( pImage, "myimage.gd" ) + * + * or + * + * gdImageGd( pImage, nFileHandle ) + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * + * pImage := gdImageFromGif( "myimage.gif" ) + * + * // Image conversion + * gdImageGd( pImage, "myimage.gd" ) + * + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageFromGif() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageWBmp() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Save a WBMP image. + * $SYNTAX$ + * gdImageWBmp( , | [, ] ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Image file name + * - File handle + * - foreground color value to be used as foreground, the others are background + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageWBmp() saves a WBMP image to a file or a handle. + * + * You can use one of 2 syntax: + * + * gdImageWBmp( pImage, "myimage.wbmp", nColor ) + * + * or + * + * gdImagePng( pImage, nFileHandle, nColor ) + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL white, black + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate background + * white := gdImageColorAllocate(pImage, 255, 255, 255) + * + * // Allocate drawing color + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * + * // Draw a rectangle + * gdImageRectangle(pImage, 0, 0, 99, 99, black) + * + * // Save the image with black as foreground color + * gdImageWBmp( pImage, "myimage.wbmp", black ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageRectangle(), gdColorAllocate() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetPixel() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Set a pixel to a particular color index. + * $SYNTAX$ + * gdImageSetPixel( , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Horizontal position + * - Vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageSetPixel() sets a pixel to a particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL white + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * white := gdImageColorAllocate(pImage, 255, 255, 255) + * + * // Draw a pixel + * gdImageSetPixel(pImage, 50, 50, white) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageLine() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a line between two end points (x1, y1 and x2, y2) with a particular color index. + * $SYNTAX$ + * gdImageLine( , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - 1st point horizontal position + * - 1st point vertical position + * - 2nd point horizontal position + * - 2nd point vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageLine() Draws a line between two end points (x1, y1 and x2, y2) + * with a particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a line + * gdImageLine(pImage, 10, 10, 90, 90, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageDashedLine() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a dashed line between two end points (x1, y1 and x2, y2) with a particular color index. + * $SYNTAX$ + * gdImageDashedLine( , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - 1st point horizontal position + * - 1st point vertical position + * - 2nd point horizontal position + * - 2nd point vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageDashedLine() Draws a dashed line between two end points (x1, y1 and x2, y2) + * with a particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a dashed line + * gdImageDashedLine(pImage, 10, 10, 90, 90, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImagePolygon() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a closed polygon with verticies (at least 3) with a particular color index. + * $SYNTAX$ + * gdImagePolygon( , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Array of point array { , } where + * is horizontal position + * is vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImagePolygon() Draws a closed polygon with verticies (at least 3) with a + * particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * LOCAL aVerticies := { ; + * { 50, 0 } ,; + * { 99, 99 } ,; + * { 0, 99 } ; + * } + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a polygon + * gdImagePolygon(pImage, aVerticies, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageOpenPolygon() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws an open polygon with verticies (at least 3) with a particular color index. + * $SYNTAX$ + * gdImageOpenPolygon( , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Array of point array { , } where + * is horizontal position + * is vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageOpenPolygon() Draws an open polygon with verticies (at least 3) with a + * particular color index. Unlike gdImagePolygon() the endpoints of the line sequence + * are not connected to close the polygon. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * LOCAL aVerticies := { ; + * { 50, 0 } ,; + * { 99, 99 } ,; + * { 0, 99 } ; + * } + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draws an open polygon + * gdImageOpenPolygon(pImage, aVerticies, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageRectangle() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a rectangle with a particular color index. + * $SYNTAX$ + * gdImageRectangle( , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - upper left point horizontal position + * - upper left point vertical position + * - lower right point horizontal position + * - lower right point vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageRectangle() draws a rectangle between 2 points with a + * particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a rectangle + * gdImageRectangle(pImage, 10, 10, 50, 50, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFilledPolygon() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a filled polygon with verticies (at least 3) with a particular color index. + * $SYNTAX$ + * gdImageFilledPolygon( , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Array of point array { , } where + * is horizontal position + * is vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFilledPolygon() Draws a filled polygon with verticies (at least 3) with a + * particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * LOCAL aVerticies := { ; + * { 50, 0 } ,; + * { 99, 99 } ,; + * { 0, 99 } ; + * } + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a filled polygon + * gdImageFilledPolygon(pImage, aVerticies, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFilledRectangle() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a filled rectangle with a particular color index. + * $SYNTAX$ + * gdImageFilledRectangle( , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - upper left point horizontal position + * - upper left point vertical position + * - lower right point horizontal position + * - lower right point vertical position + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFilledRectangle() draws a filled rectangle between 2 points with a + * particular color index. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw a filled rectangle + * gdImageFilledRectangle(pImage, 10, 10, 50, 50, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageArc() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a partial ellipse centered at a given point. + * $SYNTAX$ + * gdImageArc( , , , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - center point horizontal position + * - center point vertical position + * - width + * - height + * - start degree + * - end degree + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageArc() is used to draw a partial ellipse centered at the given point, + * with the specified width and height in pixels. The arc begins at the position + * in degrees specified by s and ends at the position specified by e. + * The arc is drawn in the color specified by the last argument. A circle can be drawn + * by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. + * must be greater than . Values greater than 360 are interpreted modulo 360. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw an ellipse + * gdImageArc(pImage, 50, 25, 98, 48, 0, 360, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFilledArc() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a partial filled ellipse centered at a given point. + * $SYNTAX$ + * gdImageArc( , , , , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - center point horizontal position + * - center point vertical position + * - width + * - height + * - start degree + * - end degree + * - Color index + * - fill style + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFilledArc() is used to draw a partial ellipse centered at the given point, + * with the specified width and height in pixels. The arc begins at the position + * in degrees specified by s and ends at the position specified by e. + * The arc is drawn in the color specified by the last argument. A circle can be drawn + * by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. + * must be greater than . Values greater than 360 are interpreted modulo 360. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * Last parameter is a bitwise OR of the following possibilities: + * gdArc + * gdChord + * gdPie (synonym for gdArc) + * gdNoFill + * gdEdged + * + * gdArc and gdChord are mutually exclusive; + * gdChord just connects the starting and ending angles with a straight line, + * while gdArc produces a rounded edge. gdPie is a synonym for gdArc. + * gdNoFill indicates that the arc or chord should be outlined, not filled. + * gdEdged, used together with gdNoFill, indicates that the beginning and ending + * angles should be connected to the center; this is a good way to outline + * (rather than fill) a 'pie slice' + * + * these constants are defined in gd.ch + * + * $EXAMPLES$ + * + * #include "gd.ch" + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw an ellipse + * gdImageFilledArc(pImage, 50, 25, 98, 48, 0, 360, blue, gdArc) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFilledEllipse() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * Draws a filled ellipse centered at a given point. + * $SYNTAX$ + * gdImageFilledEllipse( , , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - center point horizontal position + * - center point vertical position + * - width + * - height + * - Color index + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFilledEllipse() is used to draw a filled ellipse centered at the given point, + * with the specified width and height in pixels. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * // Draw an ellipse + * gdImageFilledEllipse(pImage, 50, 25, 98, 48, blue) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFillToBorder() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * floods a portion of the image with the specified color. + * $SYNTAX$ + * gdImageFillToBorder( , , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - start point horizontal position + * - start point vertical position + * - Color index where fill stops + * - Color index of filling color + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFillToBorder() floods a portion of the image with the specified color, + * beginning at the specified point and stopping at the specified border color. For a way of + * flooding an area defined by the color of the starting point, see gdImageFill(). + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * red := gdImageColorAllocate(pImage, 255, 0, 0) + * + * // Draw an ellipse + * gdImageArc(pImage, 50, 25, 98, 48, 0, 360, blue) + * + * // Fill the ellipse + * gdImageFillToBorder(pImage, 50, 50, blue, red) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageArc() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageFill() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * floods a portion of the image with the specified color. + * $SYNTAX$ + * gdImageFill( , , , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - start point horizontal position + * - start point vertical position + * - Color index of filling color + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageFill() floods a portion of the image with the specified color, beginning at the + * specified point and flooding the surrounding region of the same color as the starting point. + * For a way of flooding a region defined by a specific border color rather than by its interior + * color, see gdImageFillToBorder(). + * The fill color can be gdTiled, resulting in a tile fill using another image as the tile. + * However, the tile image cannot be transparent. If the image you wish to fill with has a + * transparent color index, call gdImageTransparent on the tile image and set the transparent + * color index to -1 to turn off its transparency. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * red := gdImageColorAllocate(pImage, 255, 0, 0) + * + * // Draw an ellipse + * gdImageArc(pImage, 50, 25, 98, 48, 0, 360, blue) + * + * // Fill the ellipse + * gdImageFill(pImage, 50, 50, red) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageArc() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetAntiAliased() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * specify the actual foreground color to be used when drawing antialiased lines. + * $SYNTAX$ + * gdImageSetAntiAliased( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Color index of filling color + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * "Antialiasing" is a process by which jagged edges associated with line drawing + * can be reduced by blending the foreground color with an appropriate percentage of + * the background, depending on how much of the pixel in question is actually within + * the boundaries of the line being drawn. All line-drawing functions, such as gdImageLine(), + * gdImageOpenPolygon() and gdImagePolygon(), will draw antialiased lines if the special "color" + * gdAntiAliased constant is used when calling them. + * + * gdImageSetAntiAliased is used to specify the actual foreground color to be used when drawing + * antialiased lines. You may set any color to be the foreground, however as of version 2.0.12 + * an alpha channel component is not supported. + * + * Antialiased lines can be drawn on both truecolor and palette-based images. However, + * attempts to draw antialiased lines on highly complex palette-based backgrounds may not give + * satisfactory results, due to the limited number of colors available in the palette. Antialiased + * line-drawing on simple backgrounds should work well with palette-based images; otherwise create + * or fetch a truecolor image instead. + * + * You need not take any special action when you are finished with antialised line drawing. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * #include "gd.ch" + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL blue, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * /* Background color (first allocated) */ + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * red := gdImageColorAllocate(pImage, 255, 0, 0) + * + * gdImageSetAntiAliased(pImage, blue) + * + * // Draw a smooth line + * gdImageLine(pImage, 0, 0, 99, 9, gdAntiAliased) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageLine(), gdAntiAliased, gdSetAntiAliasedDontBlend() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdSetAntiAliasedDontBlend() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * indicate the special color that the foreground should stand out more clearly against. + * $SYNTAX$ + * gdSetAntiAliasedDontBlend( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Color index of filling color + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * Normally, when drawing lines with the special gdAntiAliased "color," blending with + * the background to reduce jagged edges is the desired behavior. However, when it is + * desired that lines not be blended with one particular color when it is encountered + * in the background, the gdImageSetAntiAliasedDontBlend() function can be used to indicate + * the special color that the foreground should stand out more clearly against. + * + * To set the color index you have to use gdImageColorAllocate() function. + * + * $EXAMPLES$ + * + * #include "gd.ch" + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL black, white, blue + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color + * /* Background color (first allocated) */ + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * white := gdImageColorAllocate(pImage, 255, 255, 255) + * blue := gdImageColorAllocate(pImage, 0, 0, 255) + * + * gdImageSetAntiAliased(pImage, blue) + * + * // The portion of the line that crosses this white rectangle will not be blended smoothly + * gdImageSetAntiAliasedDontBlend(pImage, white) + * + * // Draw a smooth line + * gdImageLine(pImage, 0, 0, 99, 9, gdAntiAliased) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageLine(), gdAntiAliased, gdSetAntiAlias() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetBrush() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * A "brush" is an image used to draw wide, shaped strokes in another image. + * $SYNTAX$ + * gdImageSetBrush( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Brush Image pointer + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * A "brush" is an image used to draw wide, shaped strokes in another image. + * Just as a paintbrush is not a single point, a brush image need not be a single pixel. + * Any gd image can be used as a brush, and by setting the transparent color index of the + * brush image with gdImageColorTransparent, a brush of any shape can be created. + * All line-drawing functions, such as gdImageLine, gdImageOpenPolygon and gdImagePolygon, + * will use the current brush if the special "color" gdBrushed or gdStyledBrushed is used + * when calling them. + * gdImageSetBrush is used to specify the brush to be used in a particular image. + * You can set any image to be the brush. If the brush image does not have the same color + * map as the first image, any colors missing from the first image will be allocated. + * If not enough colors can be allocated, the closest colors already available will be used. + * This allows arbitrary PNGs to be used as brush images. It also means, however, that you + * should not set a brush unless you will actually use it; if you set a rapid succession of + * different brush images, you can quickly fill your color map, and the results will not be + * optimal. + * + * You need not take any special action when you are finished with a brush. As for any other image, + * if you will not be using the brush image for any further purpose, you should call gdImageDestroy. + * You must not use the color gdBrushed if the current brush has been destroyed; you can of course + * set a new brush to replace it. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage, pBrush + * LOCAL blue, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Open the brush PNG. For best results, portions of the brush that should be transparent + * // (ie, not part of the brush shape) should have the transparent color index. + * pBrush := gdImageCreateFromPng( "mybrush.png" ) + * + * // Allocate color (background color is the first allocate) + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * + * // Set the brush + * gdImageSetBrush(pImage, pBrush) + * + * // Draw a line from the upper left corner to the lower + * // right corner using the brush. + * gdImageLine(pImage, 0, 0, 99, 99, gdBrushed) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * // Destroy the brush image + * gdImageDestroy( pBrush ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageLine() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetTile() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * A "tile" is an image used to fill an area with a repeated pattern. + * $SYNTAX$ + * gdImageSetTile( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Tile Image pointer + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * A "tile" is an image used to fill an area with a repeated pattern. + * Any gd image can be used as a tile, and by setting the transparent color index of + * the tile image with gdImageColorTransparent, a tile that allows certain parts of + * the underlying area to shine through can be created. All region-filling functions, + * such as gdImageFill and gdImageFilledPolygon, will use the current tile if the special + * "color" gdTiled is used when calling them. + * + * gdImageSetTile is used to specify the tile to be used in a particular image. You can + * set any image to be the tile. If the tile image does not have the same color map as + * the first image, any colors missing from the first image will be allocated. If not + * enough colors can be allocated, the closest colors already available will be used. + * This allows arbitrary PNGs to be used as tile images. It also means, however, that you + * should not set a tile unless you will actually use it; if you set a rapid succession of + * different tile images, you can quickly fill your color map, and the results will not be optimal. + * + * You need not take any special action when you are finished with a tile. As for any other + * image, if you will not be using the tile image for any further purpose, you should call + * gdImageDestroy. You must not use the color gdTiled if the current tile has been destroyed; + * you can of course set a new tile to replace it. + * + * $EXAMPLES$ + * + * PROCEDURE Main() + * LOCAL pImage, pTile + * LOCAL blue, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Open the tile PNG. For best results, portions of the + * // tile that should be transparent (ie, allowing the + * // background to shine through) should have the transparent + * // color index. + * pTile := gdImageCreateFromPng( "mytile.png" ) + * + * // Allocate color (background color is the first allocate) + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * + * // Set the tile + * gdImageSetTile(pImage, pTile) + * + * // Fill an area using the tile + * gdImageFilledRectangle(pImage, 25, 25, 75, 75, gdTiled) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * // Destroy the tile image + * gdImageDestroy( pTile ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageFilledRectangle() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetStyle() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * set any desired series of colors to be repeated during the drawing of a line. + * $SYNTAX$ + * gdImageSetStyle( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - Array of colors and special colors used to "style" a line + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * It is often desirable to draw dashed lines, dotted lines, and other variations + * on a broken line. gdImageSetStyle can be used to set any desired series of colors, + * including a special color that leaves the background intact, to be repeated during + * the drawing of a line. + * To use gdImageSetStyle, create an array of integers and assign them the desired series + * of color values to be repeated. You can assign the special color value gdTransparent + * to indicate that the existing color should be left unchanged for that particular pixel + * (allowing a dashed line to be attractively drawn over an existing image). + * + * Then, to draw a line using the style, use the normal gdImageLine function with the + * special color value gdStyled. + * + * The style array is copied when you set the style, so you need not be concerned with + * keeping the array around indefinitely. This should not break existing code that assumes + * styles are not copied. + * + * You can also combine styles and brushes to draw the brush image at intervals instead of + * in a continuous stroke. When creating a style for use with a brush, the style values are + * interpreted differently: zero (0) indicates pixels at which the brush should not be drawn, + * while one (1) indicates pixels at which the brush should be drawn. To draw a styled, + * brushed line, you must use the special color value gdStyledBrushed. + * + * $EXAMPLES$ + * + * #include "gd.ch" + * + * PROCEDURE Main() + * LOCAL pImage, aStyleDotted := {}, aStyleDashed := {} + * LOCAL black, red + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color (background color is the first allocate) + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * red := gdImageColorAllocate(pImage, 255, 0, 0) + * + * // Set up dotted style. Leave every other pixel alone. + * aAdd( aStyleDotted, red ) + * aAdd( aStyleDotted, gdTransparent ) + * + * // Set up dashed style. Three on, three off. + * aAdd( aStyleDashed, red ) + * aAdd( aStyleDashed, red ) + * aAdd( aStyleDashed, red ) + * aAdd( aStyleDashed, gdTransparent ) + * aAdd( aStyleDashed, gdTransparent ) + * aAdd( aStyleDashed, gdTransparent ) + * + * // Set dotted style. + * gdImageSetStyle(pImage, aStyleDotted) + * + * // Draw a line from the upper left corner to the lower right corner. + * gdImageLine(pImage, 0, 0, 99, 99, gdStyled) + * + * // Now the dashed line. + * gdImageSetStyle(pImage, aStyleDashed) + * gdImageLine(pimage, 0, 99, 0, 99, gdStyled) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageLine() + * $END$ + */ + +/* $DOC$ + * $FUNCNAME$ + * gdImageSetThickness() + * $CATEGORY$ + * HBGD + * $ONELINER$ + * determines the width of lines drawn in pixels. + * $SYNTAX$ + * gdImageSetThickness( , ) --> NIL + * $ARGUMENTS$ + * - Image pointer + * - width of line in pixel + * $RETURNS$ + * NIL + * $DESCRIPTION$ + * gdImageSetThickness determines the width of lines drawn by the gdImageLine, + * gdImagePolygon, gdImageOpenPolygon and related functions, in pixels. + * + * $EXAMPLES$ + * + * #include "gd.ch" + * + * PROCEDURE Main() + * LOCAL pImage + * LOCAL black, white + * + * // Create an image in memory + * pImage := gdImageCreate( 100, 100 ) + * + * // Allocate color (background color is the first allocate) + * black := gdImageColorAllocate(pImage, 0, 0, 0) + * white := gdImageColorAllocate(pImage, 255, 255, 255) + * + * // Set thickness. + * gdImageSetThickness(pImage, 4) + * + * // Draw a fat line from the upper left corner to the lower right corner. + * gdImageLine(pImage, 0, 0, 99, 99, white) + * + * // Save the image + * gdImageJpeg( pImage, "myimage.jpg" ) + * + * // Destroy the image + * gdImageDestroy( pImage ) + * + * RETURN + * $STATUS$ + * R + * $COMPLIANCE$ + * GD Library + * $PLATFORMS$ + * All + * $FILES$ + * gdwrp.c + * $SEEALSO$ + * gdImageDestroy(), gdImageCreate(), gdImageColorAllocate(), gdImageJpeg(), gdImageLine() + * $END$ + */ +