2011-12-23 18:00 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt)

+ contrib/hbzebra/qrcode.c
  * contrib/hbzebra/hbzebra.ch
  * contrib/hbzebra/hbzebra.hbp
  * contrib/hbzebra/hbzebra.hbx
    + QR Code
    ; Christmas gift for Harbour project :)
    ; TODO: encoding optimisation using mode switching

  * contrib/hbzebra/hbzebra.h
  * contrib/hbzebra/core.c
    + hb_bitbuffer_buffer(), hb_bitbuffer_not(), hb_bitbuffer_cat_int_rev()
    * formatting

  * contrib/hbzebra/tests/testcair.prg
  * contrib/hbzebra/tests/testhpdf.prg
  * contrib/hbzebra/tests/testwin.prg
    * updated to include QR Code

  * contrib/hbzebra/datamtrx.c
    * minor modification: code text support
This commit is contained in:
Mindaugas Kavaliauskas
2011-12-23 16:00:44 +00:00
parent d4128116bb
commit 256ca1b83c
11 changed files with 1447 additions and 30 deletions

View File

@@ -16,6 +16,28 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-12-23 18:00 UTC+0200 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt)
+ contrib/hbzebra/qrcode.c
* contrib/hbzebra/hbzebra.ch
* contrib/hbzebra/hbzebra.hbp
* contrib/hbzebra/hbzebra.hbx
+ QR Code
; Christmas gift for Harbour project :)
; TODO: encoding optimisation using mode switching
* contrib/hbzebra/hbzebra.h
* contrib/hbzebra/core.c
+ hb_bitbuffer_buffer(), hb_bitbuffer_not(), hb_bitbuffer_cat_int_rev()
* formatting
* contrib/hbzebra/tests/testcair.prg
* contrib/hbzebra/tests/testhpdf.prg
* contrib/hbzebra/tests/testwin.prg
* updated to include QR Code
* contrib/hbzebra/datamtrx.c
* minor modification: code text support
2011-12-23 10:43 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* harbour/include/hbapicdp.h
* harbour/src/rtl/cdpapi.c

View File

@@ -65,6 +65,7 @@ PHB_BITBUFFER hb_bitbuffer_create( void )
return pBitBuffer;
}
void hb_bitbuffer_destroy( PHB_BITBUFFER pBitBuffer )
{
if( pBitBuffer->pBuffer )
@@ -72,12 +73,32 @@ void hb_bitbuffer_destroy( PHB_BITBUFFER pBitBuffer )
hb_xfree( pBitBuffer );
}
HB_SIZE hb_bitbuffer_len( PHB_BITBUFFER pBitBuffer )
{
return pBitBuffer->nLen;
}
unsigned char * hb_bitbuffer_buffer( PHB_BITBUFFER pBitBuffer )
{
return pBitBuffer->pBuffer;
}
HB_BOOL hb_bitbuffer_get( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos )
{
return nPos > pBitBuffer->nLen ? HB_FALSE :
( ( pBitBuffer->pBuffer[ nPos >> 3 ] >> ( nPos & 7 ) ) & 1 );
}
void hb_bitbuffer_set( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos, HB_BOOL fValue )
{
if( pBitBuffer->nAlloc * 8 <= nPos )
{
HB_SIZE nNewAlloc = ( ( pBitBuffer->nAlloc >> 1 ) + nPos + 8 ) / 8;
pBitBuffer->pBuffer = ( HB_BYTE * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
pBitBuffer->pBuffer = ( unsigned char * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
hb_xmemset( pBitBuffer->pBuffer + pBitBuffer->nAlloc, 0, nNewAlloc - pBitBuffer->nAlloc );
pBitBuffer->nAlloc = nNewAlloc;
}
@@ -91,6 +112,21 @@ void hb_bitbuffer_set( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos, HB_BOOL fValue )
pBitBuffer->nLen = nPos + 1;
}
void hb_bitbuffer_not( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos )
{
if( pBitBuffer->nAlloc * 8 <= nPos )
{
HB_SIZE nNewAlloc = ( ( pBitBuffer->nAlloc >> 1 ) + nPos + 8 ) / 8;
pBitBuffer->pBuffer = ( unsigned char * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
hb_xmemset( pBitBuffer->pBuffer + pBitBuffer->nAlloc, 0, nNewAlloc - pBitBuffer->nAlloc );
pBitBuffer->nAlloc = nNewAlloc;
}
* ( pBitBuffer->pBuffer + ( nPos >> 3 ) ) ^= 1 << ( nPos & 0x7 );
}
void hb_bitbuffer_cat_int( PHB_BITBUFFER pBitBuffer, int iValue, int iLen )
{
int i;
@@ -98,7 +134,7 @@ void hb_bitbuffer_cat_int( PHB_BITBUFFER pBitBuffer, int iValue, int iLen )
if( ( pBitBuffer->nLen + iLen ) >= pBitBuffer->nAlloc * 8 )
{
int nNewAlloc = pBitBuffer->nAlloc + ( ( pBitBuffer->nAlloc >> 1 ) + iLen + 7 ) / 8;
pBitBuffer->pBuffer = ( HB_BYTE * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
pBitBuffer->pBuffer = ( unsigned char * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
hb_xmemset( pBitBuffer->pBuffer + pBitBuffer->nAlloc, 0, nNewAlloc - pBitBuffer->nAlloc );
pBitBuffer->nAlloc = nNewAlloc;
}
@@ -111,16 +147,27 @@ void hb_bitbuffer_cat_int( PHB_BITBUFFER pBitBuffer, int iValue, int iLen )
hb_bitbuffer_set( pBitBuffer, pBitBuffer->nLen, iValue & ( 1 << i ) );
}
HB_SIZE hb_bitbuffer_len( PHB_BITBUFFER pBitBuffer )
void hb_bitbuffer_cat_int_rev( PHB_BITBUFFER pBitBuffer, int iValue, int iLen )
{
return pBitBuffer->nLen;
int i;
if( ( pBitBuffer->nLen + iLen ) >= pBitBuffer->nAlloc * 8 )
{
int nNewAlloc = pBitBuffer->nAlloc + ( ( pBitBuffer->nAlloc >> 1 ) + iLen + 7 ) / 8;
pBitBuffer->pBuffer = ( unsigned char * ) hb_xrealloc( pBitBuffer->pBuffer, nNewAlloc );
hb_xmemset( pBitBuffer->pBuffer + pBitBuffer->nAlloc, 0, nNewAlloc - pBitBuffer->nAlloc );
pBitBuffer->nAlloc = nNewAlloc;
}
if( ( unsigned int ) iLen > sizeof( int ) * 8 )
iLen = sizeof( int ) * 8;
/* TODO: optimize */
for( i = iLen - 1; i >= 0; i-- )
hb_bitbuffer_set( pBitBuffer, pBitBuffer->nLen, iValue & ( 1 << i ) );
}
HB_BOOL hb_bitbuffer_get( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos )
{
return nPos > pBitBuffer->nLen ? HB_FALSE :
( ( pBitBuffer->pBuffer[ nPos >> 3 ] >> ( nPos & 7 ) ) & 1 );
}
/* ================ GC pointer ================ */
@@ -135,6 +182,7 @@ static HB_GARBAGE_FUNC( hb_zebra_destructor )
}
}
static const HB_GC_FUNCS s_gcZebraFuncs =
{
hb_zebra_destructor,
@@ -148,6 +196,7 @@ PHB_ZEBRA hb_zebraItemGet( PHB_ITEM pItem )
return ppZebra ? *ppZebra : NULL;
}
PHB_ITEM hb_zebraItemPut( PHB_ITEM pItem, PHB_ZEBRA pZebra )
{
PHB_ZEBRA * ppZebra = ( PHB_ZEBRA * ) hb_gcAllocate( sizeof( PHB_ZEBRA ), &s_gcZebraFuncs );
@@ -156,6 +205,7 @@ PHB_ITEM hb_zebraItemPut( PHB_ITEM pItem, PHB_ZEBRA pZebra )
return hb_itemPutPtrGC( pItem, ppZebra );
}
void hb_zebraItemClear( PHB_ITEM pItem )
{
PHB_ZEBRA * ppZebra = ( PHB_ZEBRA * ) hb_itemGetPtrGC( pItem, &s_gcZebraFuncs );
@@ -164,6 +214,7 @@ void hb_zebraItemClear( PHB_ITEM pItem )
* ppZebra = NULL;
}
PHB_ZEBRA hb_zebra_param( int iParam )
{
PHB_ZEBRA * ppZebra = ( PHB_ZEBRA * ) hb_parptrGC( &s_gcZebraFuncs, iParam );
@@ -175,6 +226,7 @@ PHB_ZEBRA hb_zebra_param( int iParam )
return NULL;
}
void hb_zebra_ret( PHB_ZEBRA pZebra )
{
hb_zebraItemPut( hb_stackReturnItem(), pZebra );
@@ -190,6 +242,7 @@ PHB_ZEBRA hb_zebra_create( void )
return pZebra;
}
void hb_zebra_destroy( PHB_ZEBRA pZebra )
{
if( pZebra->szCode )
@@ -199,6 +252,7 @@ void hb_zebra_destroy( PHB_ZEBRA pZebra )
hb_xfree( pZebra );
}
HB_FUNC( HB_ZEBRA_DESTROY )
{
PHB_ZEBRA pZebra = hb_zebra_param( 1 );
@@ -209,6 +263,7 @@ HB_FUNC( HB_ZEBRA_DESTROY )
}
}
HB_FUNC( HB_ZEBRA_GETERROR )
{
PHB_ZEBRA pZebra = hb_zebra_param( 1 );
@@ -218,6 +273,7 @@ HB_FUNC( HB_ZEBRA_GETERROR )
}
}
HB_FUNC( HB_ZEBRA_GETCODE )
{
PHB_ZEBRA pZebra = hb_zebra_param( 1 );

View File

@@ -465,7 +465,8 @@ PHB_ZEBRA hb_zebra_create_datamatrix( const char * szCode, HB_SIZE nLen, int iFl
#endif
pZebra->iCol = pSize->iCol;
pZebra->szCode = hb_strdup( "" );
pZebra->szCode = hb_strdup( szCode );
pZebra->pBits = hb_bitbuffer_create();
/* allocate bitbuffer */

View File

@@ -70,6 +70,7 @@
#define HB_ZEBRA_TYPE_PDF417 257
#define HB_ZEBRA_TYPE_DATAMATRIX 258
#define HB_ZEBRA_TYPE_QRCODE 259
/* Generate errors */
#define HB_ZEBRA_ERROR_INVALIDCODE 1
@@ -104,4 +105,10 @@
#define HB_ZEBRA_FLAG_DATAMATRIX_SQUARE 0x0100
#define HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE 0x0200
#define HB_ZEBRA_FLAG_QR_LEVEL_MASK 0x0700
#define HB_ZEBRA_FLAG_QR_LEVEL_L 0x0100
#define HB_ZEBRA_FLAG_QR_LEVEL_M 0x0200
#define HB_ZEBRA_FLAG_QR_LEVEL_Q 0x0300
#define HB_ZEBRA_FLAG_QR_LEVEL_H 0x0400
#endif /* HB_ZEBRA_CH_ */

View File

@@ -58,10 +58,10 @@
typedef struct
{
HB_BYTE * pBuffer;
HB_SIZE nLen;
HB_SIZE nAlloc;
void * pCargo;
unsigned char * pBuffer;
HB_SIZE nLen;
HB_SIZE nAlloc;
void * pCargo;
} HB_BITBUFFER, * PHB_BITBUFFER;
typedef struct
@@ -75,12 +75,15 @@ typedef struct
HB_EXTERN_BEGIN
extern HB_EXPORT PHB_BITBUFFER hb_bitbuffer_create( void );
extern HB_EXPORT void hb_bitbuffer_destroy( PHB_BITBUFFER pBitBuffer );
extern HB_EXPORT void hb_bitbuffer_set( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos, HB_BOOL fValue );
extern HB_EXPORT void hb_bitbuffer_cat_int( PHB_BITBUFFER pBitBuffer, int iValue, int iLen );
extern HB_EXPORT HB_SIZE hb_bitbuffer_len( PHB_BITBUFFER pBitBuffer );
extern HB_EXPORT HB_BOOL hb_bitbuffer_get( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos );
extern HB_EXPORT PHB_BITBUFFER hb_bitbuffer_create( void );
extern HB_EXPORT void hb_bitbuffer_destroy( PHB_BITBUFFER pBitBuffer );
extern HB_EXPORT HB_SIZE hb_bitbuffer_len( PHB_BITBUFFER pBitBuffer );
extern HB_EXPORT unsigned char * hb_bitbuffer_buffer( PHB_BITBUFFER pBitBuffer );
extern HB_EXPORT HB_BOOL hb_bitbuffer_get( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos );
extern HB_EXPORT void hb_bitbuffer_set( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos, HB_BOOL fValue );
extern HB_EXPORT void hb_bitbuffer_not( PHB_BITBUFFER pBitBuffer, HB_SIZE nPos );
extern HB_EXPORT void hb_bitbuffer_cat_int( PHB_BITBUFFER pBitBuffer, int iValue, int iLen );
extern HB_EXPORT void hb_bitbuffer_cat_int_rev( PHB_BITBUFFER pBitBuffer, int iValue, int iLen );
extern HB_EXPORT PHB_ZEBRA hb_zebra_create( void );
extern HB_EXPORT void hb_zebra_destroy( PHB_ZEBRA pZebra );

View File

@@ -29,3 +29,4 @@ itf.c
msi.c
pdf417.c
datamtrx.c
qrcode.c

View File

@@ -36,6 +36,7 @@ DYNAMIC HB_ZEBRA_CREATE_EAN8
DYNAMIC HB_ZEBRA_CREATE_ITF
DYNAMIC HB_ZEBRA_CREATE_MSI
DYNAMIC HB_ZEBRA_CREATE_PDF417
DYNAMIC HB_ZEBRA_CREATE_QRCODE
DYNAMIC HB_ZEBRA_CREATE_UPCA
DYNAMIC HB_ZEBRA_CREATE_UPCE
DYNAMIC HB_ZEBRA_DESTROY

File diff suppressed because it is too large Load Diff

View File

@@ -37,11 +37,11 @@ PROCEDURE main()
DrawBarcode( hCairo, 360, 1, "CODE11", "12", HB_ZEBRA_FLAG_WIDE3 )
DrawBarcode( hCairo, 380, 1, "CODE11", "1234567890", HB_ZEBRA_FLAG_CHECKSUM + HB_ZEBRA_FLAG_WIDE3 )
DrawBarcode( hCairo, 400, 1, "CODE128", "Code 128")
DrawBarcode( hCairo, 420, 1, "CODE128", "1234567890")
DrawBarcode( hCairo, 420, 1, "CODE128", "61300073570004616")
DrawBarcode( hCairo, 440, 1, "CODE128", "Wikipedia")
DrawBarcode( hCairo, 460, 1, "PDF417", "Hello, World of Harbour!!! It's 2D barcode PDF417 :)" )
DrawBarcode( hCairo, 540, 1, "DATAMATRIX", "Hello, World of Harbour!!! It's 2D barcode DataMatrix :)")
DrawBarcode( hCairo, 580, 1, "QRCODE", "http://harbour-project.org/" )
cairo_destroy( hCairo )
cairo_surface_write_to_png( hSurface, "testcair.png" )
cairo_surface_destroy( hSurface )
@@ -49,7 +49,7 @@ PROCEDURE main()
PROCEDURE DrawBarcode( hCairo, nY, nLineWidth, cType, cCode, nFlags )
LOCAL hZebra, nLineHeight
LOCAL hZebra, nLineHeight, cTxt
SWITCH cType
CASE "EAN13" ; hZebra := hb_zebra_create_ean13( cCode, nFlags ) ; EXIT
@@ -65,6 +65,7 @@ PROCEDURE DrawBarcode( hCairo, nY, nLineWidth, cType, cCode, nFlags )
CASE "CODE128" ; hZebra := hb_zebra_create_code128( cCode, nFlags ) ; EXIT
CASE "PDF417" ; hZebra := hb_zebra_create_pdf417( cCode, nFlags ); nLineHeight := nLineWidth * 3 ; EXIT
CASE "DATAMATRIX" ; hZebra := hb_zebra_create_datamatrix( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
CASE "QRCODE" ; hZebra := hb_zebra_create_qrcode( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
ENDSWITCH
IF hZebra != NIL
IF hb_zebra_geterror( hZebra ) == 0
@@ -73,8 +74,10 @@ PROCEDURE DrawBarcode( hCairo, nY, nLineWidth, cType, cCode, nFlags )
ENDIF
cairo_move_to( hCairo, 40, nY + 13 )
cairo_show_text( hCairo, cType )
cairo_move_to( hCairo, 100, nY + 13 )
cairo_show_text( hCairo, hb_zebra_getcode( hZebra ) )
IF LEN( cTxt := hb_zebra_getcode( hZebra ) ) < 20
cairo_move_to( hCairo, 100, nY + 13 )
cairo_show_text( hCairo, cTxt )
ENDIF
hb_zebra_draw_cairo( hZebra, hCairo, 220, nY, nLineWidth, nLineHeight )
ELSE
? "Type", cType, "Code", cCode, "Error", hb_zebra_geterror( hZebra )
@@ -92,7 +95,8 @@ STATIC FUNCTION hb_zebra_draw_cairo( hZebra, hCairo, ... )
ENDIF
cairo_save( hCairo )
hb_zebra_draw( hZebra, {| x, y, w, h | cairo_rectangle( hCairo, x, y, w, h ), cairo_fill( hCairo ) }, ... )
hb_zebra_draw( hZebra, {| x, y, w, h | cairo_rectangle( hCairo, x, y, w, h ) }, ... )
cairo_fill( hCairo )
cairo_restore( hCairo )
RETURN 0

View File

@@ -46,6 +46,7 @@ PROCEDURE Main()
DrawBarcode( page, 440, 1, "CODE128", "Wikipedia")
DrawBarcode( page, 460, 1, "PDF417", "Hello, World of Harbour!!! It's 2D barcode PDF417 :)" )
DrawBarcode( page, 540, 1, "DATAMATRIX", "Hello, World of Harbour!!! It's 2D barcode DataMatrix :)")
DrawBarcode( page, 580, 1, "QRCODE", "http://harbour-project.org/" )
FErase( "testhpdf.pdf" )
? HPDF_SaveToFile( pdf, "testhpdf.pdf" )
@@ -53,7 +54,7 @@ PROCEDURE Main()
RETURN
PROCEDURE DrawBarcode( page, nY, nLineWidth, cType, cCode, nFlags )
LOCAL hZebra, nLineHeight
LOCAL hZebra, nLineHeight, cTxt
nY := HPDF_Page_GetHeight( page ) - nY
@@ -71,6 +72,7 @@ PROCEDURE DrawBarcode( page, nY, nLineWidth, cType, cCode, nFlags )
CASE "CODE128" ; hZebra := hb_zebra_create_code128( cCode, nFlags ) ; EXIT
CASE "PDF417" ; hZebra := hb_zebra_create_pdf417( cCode, nFlags ); nLineHeight := nLineWidth * 3 ; EXIT
CASE "DATAMATRIX" ; hZebra := hb_zebra_create_datamatrix( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
CASE "QRCODE" ; hZebra := hb_zebra_create_qrcode( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
ENDSWITCH
IF hZebra != NIL
@@ -80,7 +82,10 @@ PROCEDURE DrawBarcode( page, nY, nLineWidth, cType, cCode, nFlags )
ENDIF
HPDF_Page_BeginText( page )
HPDF_Page_TextOut( page, 40, nY - 13, cType )
HPDF_Page_TextOut( page, 150, nY - 13, hb_zebra_getcode( hZebra ) )
cTxt := hb_zebra_getcode( hZebra )
IF LEN( cTxt ) < 20
HPDF_Page_TextOut( page, 150, nY - 13, cTxt )
ENDIF
HPDF_Page_EndText( page )
hb_zebra_draw_hpdf( hZebra, page, 300, nY, nLineWidth, -nLineHeight )
ELSE

View File

@@ -74,6 +74,7 @@ PROCEDURE Main()
DrawBarcode( hDC, 440, 1, "CODE128", "Wikipedia")
DrawBarcode( hDC, 460, 1, "PDF417", "Hello, World of Harbour!!! It's 2D barcode PDF417 :)" )
DrawBarcode( hDC, 540, 1, "DATAMATRIX", "Hello, World of Harbour!!! It's 2D barcode DataMatrix :)")
DrawBarcode( hDC, 580, 1, "QRCODE", "http://harbour-project.org/" )
wapi_EndPage( hDC )
ENDIF
@@ -86,7 +87,7 @@ PROCEDURE Main()
#define _SCALE_ 7.2
PROCEDURE DrawBarcode( hDC, nY, nLineWidth, cType, cCode, nFlags )
LOCAL hZebra, nLineHeight
LOCAL hZebra, nLineHeight, cTxt
SWITCH cType
CASE "EAN13" ; hZebra := hb_zebra_create_ean13( cCode, nFlags ) ; EXIT
@@ -102,6 +103,7 @@ PROCEDURE DrawBarcode( hDC, nY, nLineWidth, cType, cCode, nFlags )
CASE "CODE128" ; hZebra := hb_zebra_create_code128( cCode, nFlags ) ; EXIT
CASE "PDF417" ; hZebra := hb_zebra_create_pdf417( cCode, nFlags ); nLineHeight := nLineWidth * 3 ; EXIT
CASE "DATAMATRIX" ; hZebra := hb_zebra_create_datamatrix( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
CASE "QRCODE" ; hZebra := hb_zebra_create_qrcode( cCode, nFlags ); nLineHeight := nLineWidth ; EXIT
ENDSWITCH
nY *= _SCALE_
@@ -113,7 +115,9 @@ PROCEDURE DrawBarcode( hDC, nY, nLineWidth, cType, cCode, nFlags )
nLineHeight := 16
ENDIF
wapi_TextOut( hDC, 40 * _SCALE_, nY, cType )
wapi_TextOut( hDC, 150 * _SCALE_, nY, hb_zebra_getcode( hZebra ) )
IF LEN( cTxt := hb_zebra_getcode( hZebra ) ) < 20
wapi_TextOut( hDC, 150 * _SCALE_, nY, cTxt )
ENDIF
hb_zebra_draw_wapi( hZebra, hDC, wapi_CreateSolidBrush( 0 ), 300 * _SCALE_, nY, nLineWidth, nLineHeight * _SCALE_ )
ELSE
? "Type", cType, "Code", cCode, "Error", hb_zebra_geterror( hZebra )