* contrib/hbzebra/coredraw.c
* contrib/hbzebra/hbzebra.hbx
+ added new PRG function:
hb_zebra_getsize( <hZebra>, @<nWidth>, @<nHeight> ) -> <nError>
it calculates size in points of the created barcode and returns 0 on
success or error code
+ contrib/hbzebra/tests/gtgfx.prg
+ borrowed from Viktor's fork, thanks
2014-09-18 22:32 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
+ added on-screen barcode example, created by elch
(with some minor cleanups)
https://groups.google.com/d/msg/harbour-users/_Wht51JZGgE/ZXyvaJNH9ggJ
feb4fc0e20
* contrib/sddoci/core.c
* map ostrlen() to strlen() or wcslen() in OCI_CHARSET_UNICODE builds
; TOFIX: this library uses wchar_t for unicode strings, it means that
in *nixes where wchar_t is 32-bit integer mapping to Harbour
HB_WCHAR is wrong and has to be fixed
* include/hbapifs.h
* src/harbour.def
* src/rtl/filebuf.c
+ added new C function:
HB_BOOL hb_fileSave( const char * pszFileName,
const void * buffer, HB_SIZE nSize );
* include/harbour.hbx
* src/harbour.def
* src/rtl/vfile.c
+ added new PRG function:
hb_vfSave( <cFileName>, <cFileBody> ) --> <lOK>
* src/rtl/vfile.c
* set FError() code in hb_vfLoad()
187 lines
5.7 KiB
C
187 lines
5.7 KiB
C
/*
|
|
* Zebra barcode library
|
|
*
|
|
* Copyright 2010 Viktor Szakats (vszakats.net/harbour)
|
|
* Copyright 2010 Mindaugas Kavaliauskas <dbtopas at dbtopas.lt>
|
|
*
|
|
* 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 "hbzebra.h"
|
|
#include "hbvm.h"
|
|
|
|
typedef void ( *HB_ZEBRA_CALLBACK )( void * cargo, double dX, double dY, double dWidth, double dHeight );
|
|
|
|
int hb_zebra_draw( PHB_ZEBRA pZebra, HB_ZEBRA_CALLBACK pCallback, void * cargo, double dX, double dY, double dWidth, double dHeight, int iFlags )
|
|
{
|
|
double dLast;
|
|
HB_SIZE n, nLen, nCount;
|
|
HB_BOOL fLastBit;
|
|
int i, iCol = pZebra->iCol;
|
|
|
|
HB_SYMBOL_UNUSED( iFlags );
|
|
|
|
if( pZebra->iError != 0 )
|
|
return HB_ZEBRA_ERROR_INVALIDZEBRA;
|
|
|
|
nLen = hb_bitbuffer_len( pZebra->pBits );
|
|
fLastBit = hb_bitbuffer_get( pZebra->pBits, 0 );
|
|
dLast = dX;
|
|
nCount = 0;
|
|
i = 0;
|
|
for( n = 0; n < nLen; n++ )
|
|
{
|
|
HB_BOOL fBit = hb_bitbuffer_get( pZebra->pBits, n );
|
|
if( fBit != fLastBit )
|
|
{
|
|
if( fLastBit && pCallback )
|
|
pCallback( cargo, dLast, dY, dWidth * nCount, dHeight );
|
|
|
|
dLast += dWidth * nCount;
|
|
nCount = 0;
|
|
fLastBit = fBit;
|
|
}
|
|
nCount++;
|
|
if( ++i == iCol )
|
|
{
|
|
if( nCount )
|
|
{
|
|
if( fBit && pCallback )
|
|
pCallback( cargo, dLast, dY, dWidth * nCount, dHeight );
|
|
nCount = 0;
|
|
}
|
|
i = 0;
|
|
dY += dHeight;
|
|
dLast = dX;
|
|
if( n + 1 < nLen )
|
|
fLastBit = hb_bitbuffer_get( pZebra->pBits, n + 1 );
|
|
}
|
|
}
|
|
if( fLastBit && nCount && pCallback )
|
|
pCallback( cargo, dLast, dY, dWidth * nCount, dHeight );
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hb_zebra_draw_codeblock_callback( void * pDrawBlock, double dX, double dY, double dWidth, double dHeight )
|
|
{
|
|
if( pDrawBlock && HB_IS_BLOCK( pDrawBlock ) && hb_vmRequestReenter() )
|
|
{
|
|
hb_vmPushEvalSym();
|
|
hb_vmPush( ( PHB_ITEM ) pDrawBlock );
|
|
hb_vmPushDouble( dX, HB_DEFAULT_DECIMALS );
|
|
hb_vmPushDouble( dY, HB_DEFAULT_DECIMALS );
|
|
hb_vmPushDouble( dWidth, HB_DEFAULT_DECIMALS );
|
|
hb_vmPushDouble( dHeight, HB_DEFAULT_DECIMALS );
|
|
hb_vmSend( 4 );
|
|
hb_vmRequestRestore();
|
|
}
|
|
}
|
|
|
|
int hb_zebra_draw_codeblock( PHB_ZEBRA pZebra, PHB_ITEM pDrawBlock, double dX, double dY, double dWidth, double dHeight, int iFlags )
|
|
{
|
|
return hb_zebra_draw( pZebra, hb_zebra_draw_codeblock_callback, pDrawBlock, dX, dY, dWidth, dHeight, iFlags );
|
|
}
|
|
|
|
HB_FUNC( HB_ZEBRA_DRAW )
|
|
{
|
|
PHB_ZEBRA pZebra = hb_zebra_param( 1 );
|
|
|
|
if( pZebra )
|
|
{
|
|
PHB_ITEM pDrawBlock = hb_param( 2, HB_IT_BLOCK );
|
|
if( pDrawBlock )
|
|
hb_retni( hb_zebra_draw_codeblock( pZebra, pDrawBlock, hb_parnd( 3 ), hb_parnd( 4 ), hb_parnd( 5 ), hb_parnd( 6 ), hb_parni( 7 ) ) );
|
|
else
|
|
hb_errRT_BASE( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
|
}
|
|
}
|
|
|
|
int hb_zebra_getsize( PHB_ZEBRA pZebra, int * piWidth, int * piHeight )
|
|
{
|
|
HB_SIZE n, nLen;
|
|
int iRow, iCol, iMaxCol = pZebra->iCol, iWidth, iHeight;
|
|
|
|
if( pZebra->iError != 0 )
|
|
{
|
|
*piWidth = *piHeight = 0;
|
|
return HB_ZEBRA_ERROR_INVALIDZEBRA;
|
|
}
|
|
|
|
nLen = hb_bitbuffer_len( pZebra->pBits );
|
|
iWidth = iHeight = 0;
|
|
iCol = iRow = 1;
|
|
for( n = 0; n < nLen; n++ )
|
|
{
|
|
if( hb_bitbuffer_get( pZebra->pBits, n ) )
|
|
{
|
|
if( iCol > iWidth )
|
|
iWidth = iCol;
|
|
if( iRow > iHeight )
|
|
iHeight = iRow;
|
|
}
|
|
if( iCol++ == iMaxCol )
|
|
{
|
|
++iRow;
|
|
iCol = 1;
|
|
}
|
|
}
|
|
|
|
*piWidth = iWidth;
|
|
*piHeight = iHeight;
|
|
|
|
return 0;
|
|
}
|
|
|
|
HB_FUNC( HB_ZEBRA_GETSIZE )
|
|
{
|
|
PHB_ZEBRA pZebra = hb_zebra_param( 1 );
|
|
|
|
if( pZebra )
|
|
{
|
|
int iWidth, iHeight;
|
|
|
|
hb_retni( hb_zebra_getsize( pZebra, &iWidth, &iHeight ) );
|
|
hb_storni( iWidth, 2 );
|
|
hb_storni( iHeight, 3 );
|
|
}
|
|
}
|