* *
* partial sync with the 3.4 fork codebase. These are the things
synces for the most part:
- copyright headers
- grammar/typos in comments and some readmes
- comment/whitespace/decorations
- variable scoping in C files
- DO CASE/SWITCH and some other alternate syntax usage
- minimal amount of human readable text in strings
- minor code updates
- HB_TRACE() void * casts for pointers and few other changes to
avoid C compiler warnings
- various other, minor code cleanups
- only Harbour/C code/headers were touched in src, utils, contrib,
include. No 3rd party code, no make files, and with just a few
exceptions, no 'tests' code was touched.
- certain components were not touched were 3.4 diverged too much
already, like f.e. hbmk2, hbssl, hbcurl, hbexpat
- the goal was that no actual program logic should be altered by
these changes. Except some possible minor exceptions, any such
change is probably a bug in this patch.
It's a massive patch, if you find anything broken after it, please
open an Issue with the details. Build test was done on macOS.
The goal is make it easier to see what actual code/logic was changed
in 3.4 compared to 3.2 and to make patches easier to apply in both
ways.
334 lines
8.8 KiB
Plaintext
334 lines
8.8 KiB
Plaintext
/*
|
|
* BAR engine library class
|
|
*
|
|
* Copyright 2005 Laverson Espindola <laverson.espindola@gmail.com>
|
|
*
|
|
* 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 program; see the file LICENSE.txt. If not, write to
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA (or visit https://www.gnu.org/licenses/).
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#include "gd.ch"
|
|
#include "hbclass.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
|
|
|
|
CREATE CLASS GDBar INHERIT GDImage
|
|
|
|
// Class attributes
|
|
VAR positionX AS NUMERIC INIT 4
|
|
VAR positionY AS NUMERIC
|
|
VAR maxHeight AS NUMERIC INIT 25
|
|
VAR maxHDefa AS NUMERIC INIT 25
|
|
VAR lastX AS NUMERIC
|
|
VAR lastY AS NUMERIC
|
|
VAR error AS NUMERIC
|
|
VAR imWidth AS NUMERIC
|
|
|
|
// Barcode attributes
|
|
VAR Parity
|
|
VAR LeftHand_Even AS ARRAY
|
|
VAR Right_Hand AS ARRAY
|
|
VAR LeftHand_Odd AS ARRAY
|
|
VAR keys AS ARRAY
|
|
|
|
VAR book AS LOGICAL INIT .F.
|
|
VAR acode AS ARRAY
|
|
VAR KeysModeA AS CHARACTER
|
|
VAR KeysModeB AS CHARACTER
|
|
VAR KeysModeC AS ARRAY
|
|
|
|
// Image attributes
|
|
VAR res AS NUMERIC
|
|
VAR textfont AS NUMERIC
|
|
VAR TEXT AS CHARACTER
|
|
VAR filename AS CHARACTER
|
|
VAR color_b AS ARRAY
|
|
VAR color_f AS ARRAY
|
|
VAR FillColor AS NUMERIC
|
|
VAR BackColor AS NUMERIC
|
|
VAR 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( lIsI25 )
|
|
METHOD nextX( lI25 )
|
|
METHOD Finish( image_style, quality, nFG )
|
|
METHOD SetText( ptext )
|
|
METHOD ResetColor()
|
|
METHOD CheckCode()
|
|
METHOD CheckValInArray( cChar )
|
|
|
|
ENDCLASS
|
|
|
|
METHOD CreateBar( sx, sy, filename, cColor ) CLASS GDBar
|
|
|
|
::Create( sx, sy )
|
|
|
|
hb_default( @cColor, { 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 GDBar
|
|
|
|
hb_default( @lBook , .F. )
|
|
hb_default( @lDrawValue , .T. )
|
|
hb_default( @nMaxHeight , 25 )
|
|
hb_default( @nTextFont , 2 )
|
|
hb_default( @nRes , 2 )
|
|
hb_default( @aBackColor , { 255, 255, 255 } )
|
|
hb_default( @aFillColor , { 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 GDBar
|
|
|
|
::text := ptext
|
|
|
|
RETURN NIL
|
|
|
|
METHOD ResetColor() CLASS GDBar
|
|
|
|
::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 GDBar
|
|
|
|
LOCAL R := ::color_b[ 1 ]
|
|
LOCAL G := ::color_b[ 2 ]
|
|
LOCAL B := ::color_b[ 3 ]
|
|
|
|
RETURN ::SetColor( R, G, B )
|
|
|
|
METHOD DrawSingleBar( pcode ) CLASS GDBar
|
|
|
|
LOCAL i
|
|
LOCAL j
|
|
|
|
FOR j := 1 TO Len( pcode )
|
|
|
|
FOR i := 1 TO ::res
|
|
::Line( ::positionX + i, ::positionY, ::positionX + i, ::positionY + ::maxHeight, ;
|
|
iif( SubStr( pcode, j, 1 ) $ "0", ::BackColor, ::FillColor ) )
|
|
NEXT
|
|
|
|
::NextX()
|
|
NEXT
|
|
|
|
RETURN NIL
|
|
|
|
METHOD DrawSingleI25( pcode ) CLASS GDBar
|
|
|
|
LOCAL j
|
|
|
|
LOCAL widthSlimBar := 1
|
|
LOCAL widthFatBar := 3
|
|
|
|
LOCAL imgBar
|
|
LOCAL imgWid
|
|
LOCAL end_y
|
|
LOCAL qw
|
|
|
|
::positionX := 10
|
|
|
|
FOR j := 1 TO Len( pcode )
|
|
|
|
imgBar := iif( j % 2 == 0, ::FillColor, ::BackColor )
|
|
imgWid := iif( 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 GDBar
|
|
|
|
::Say( 5, ::error * 15, ptext, ::FillColor )
|
|
|
|
::error++
|
|
|
|
::lastX := Max( ::GetFontWidth() * Len( ptext ), ::lastX )
|
|
::lastY := ::error * 15
|
|
|
|
RETURN NIL
|
|
|
|
METHOD nextX( lI25 ) CLASS GDBar
|
|
|
|
hb_default( @li25, .F. )
|
|
|
|
IF li25
|
|
::positionX++
|
|
ELSE
|
|
::positionX += ::res
|
|
ENDIF
|
|
|
|
RETURN NIL
|
|
|
|
METHOD DrawText( lIsI25 ) CLASS GDBar
|
|
|
|
LOCAL xPosition
|
|
|
|
hb_default( @lIsI25, .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 GDBar
|
|
|
|
LOCAL lRet := .T.
|
|
LOCAL i
|
|
|
|
FOR i := 1 TO Len( ::text )
|
|
IF HB_ISSTRING( ::CheckValInArray( SubStr( ::text, i, 1 ) ) )
|
|
::DrawError( "Character " + SubStr( ::text, i, 1 ) + " not allowed." )
|
|
lRet := .F.
|
|
ENDIF
|
|
NEXT
|
|
|
|
RETURN lRet
|
|
|
|
METHOD CheckValInArray( cChar ) CLASS GDBar
|
|
|
|
LOCAL nPos := AScan( ::keys, {| x | SubStr( x, 1, 1 ) == cChar } )
|
|
|
|
RETURN iif( nPos > 0, nPos, NIL )
|
|
|
|
METHOD Finish( image_style, quality, nFG ) CLASS GDBar
|
|
|
|
hb_default( @image_style, IMG_FORMAT_PNG )
|
|
hb_default( @quality , 95 )
|
|
hb_default( @nFG , { 255, 255, 255 } )
|
|
|
|
IF Empty( ::filename ) .OR. ::filename == NIL
|
|
|
|
// Output std handle == 1
|
|
|
|
// ::filename := ::text
|
|
IF image_style == IMG_FORMAT_PNG
|
|
::OutputPng()
|
|
ELSEIF image_style == IMG_FORMAT_JPEG
|
|
::OutputJpeg( , quality )
|
|
ELSEIF image_style == IMG_FORMAT_WBMP
|
|
::OutputWBmp( , nFG )
|
|
ELSEIF image_style == IMG_FORMAT_GIF
|
|
::OutputGif()
|
|
ENDIF
|
|
ELSE
|
|
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
|
|
ENDIF
|
|
|
|
RETURN .T.
|