2010-11-10 14:58 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbzebra/hbzebra.ch
  * contrib/hbzebra/hbzebra.hbp
  + contrib/hbzebra/d_gen.c
    + Added generic HB_ZEBRA_DRAW() drawing function. It
      needs a codeblock accepting x, y, width, height parameters.

  * contrib/hbzebra/tests/testcair.prg
  * contrib/hbzebra/tests/testhpdf.prg
  * contrib/hbzebra/tests/testwin.prg
    + Reimplemented using generic HB_ZEBRA_DRAW() function and
      simple callbacks.

  * contrib/hbzebra/hbzebra.ch
    + Added 'used by C code' note.
This commit is contained in:
Viktor Szakats
2010-11-10 14:03:05 +00:00
parent f87f0646de
commit 29674e8b3c
7 changed files with 179 additions and 5 deletions

View File

@@ -16,6 +16,22 @@
The license applies to all entries newer than 2009-04-28.
*/
2010-11-10 14:58 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbzebra/hbzebra.ch
* contrib/hbzebra/hbzebra.hbp
+ contrib/hbzebra/d_gen.c
+ Added generic HB_ZEBRA_DRAW() drawing function. It
needs a codeblock accepting x, y, width, height parameters.
* contrib/hbzebra/tests/testcair.prg
* contrib/hbzebra/tests/testhpdf.prg
* contrib/hbzebra/tests/testwin.prg
+ Reimplemented using generic HB_ZEBRA_DRAW() function and
simple callbacks.
* contrib/hbzebra/hbzebra.ch
+ Added 'used by C code' note.
2010-11-10 13:08 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbzebra/hbzebra.hbp
- contrib/hbzebra/cairo.c
@@ -82,7 +98,7 @@
* contrib/hbzebra/itf.c
* contrib/hbzebra/codabar.c
* Silenced three warnings.
; TOFIX: Remains one:
; TOFIX: Remains one: [DONE]
../../../../../contrib/hbzebra/code128.c: In function 'hb_zebra_create_code128':
../../../../../contrib/hbzebra/code128.c:316:19: warning: suggest parentheses around '&&' within '||'

View File

@@ -0,0 +1,121 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Zebra barcode library
*
* Copyright 2010 Viktor Szakats (harbour.01 syenar.hu)
* Copyright 2010 Mindaugas Kavaliauskas <dbtopas at dbtopas.lt>
* www - http://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.
*
*/
#include "hbzebra.h"
#include "hbvm.h"
int hb_zebra_draw_wapi( PHB_ZEBRA pZebra, PHB_ITEM pDrawBlock, double dX, double dY, double dWidth, double dHeight, int iFlags )
{
double dLast;
HB_SIZE n, nLen, nCount;
HB_BOOL fBit, fLastBit;
HB_SYMBOL_UNUSED( iFlags );
if( pZebra->iError != 0 )
return HB_ZEBRA_ERROR_INVALIDZEBRA;
if( ! pDrawBlock || ! HB_IS_BLOCK( pDrawBlock ) )
return HB_ZEBRA_ERROR_ARGUMENT;
nLen = hb_bitbuffer_len( pZebra->pBits );
fLastBit = hb_bitbuffer_get( pZebra->pBits, 0 );
dLast = dX;
nCount = 1;
for( n = 1; n < nLen; n++ )
{
fBit = hb_bitbuffer_get( pZebra->pBits, n );
if( fBit != fLastBit )
{
if( fLastBit && hb_vmRequestReenter() )
{
hb_vmPushEvalSym();
hb_vmPush( pDrawBlock );
hb_vmPushDouble( dLast, 2 );
hb_vmPushDouble( dY, 2 );
hb_vmPushDouble( dWidth * nCount, 2 );
hb_vmPushDouble( dHeight, 2 );
hb_vmSend( 4 );
hb_vmRequestRestore();
}
dLast += dWidth * nCount;
nCount = 0;
fLastBit = fBit;
}
nCount++;
}
if( fLastBit && hb_vmRequestReenter() )
{
hb_vmPushEvalSym();
hb_vmPush( pDrawBlock );
hb_vmPushDouble( dLast, 2 );
hb_vmPushDouble( dY, 2 );
hb_vmPushDouble( dWidth * nCount, 2 );
hb_vmPushDouble( dHeight, 2 );
hb_vmSend( 4 );
hb_vmRequestRestore();
}
return 0;
}
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_wapi( pZebra, pDrawBlock, hb_parnd( 3 ), hb_parnd( 4 ), hb_parnd( 5 ), hb_parnd( 6 ), hb_parni( 7 ) ) );
}
}

View File

@@ -50,6 +50,8 @@
*
*/
/* NOTE: This file is also used by C code. */
#ifndef HB_ZEBRA_CH_
#define HB_ZEBRA_CH_
@@ -72,6 +74,7 @@
/* Draw errors */
#define HB_ZEBRA_ERROR_INVALIDZEBRA 101
#define HB_ZEBRA_ERROR_ARGUMENT 102
/* Generate flags */
#define HB_ZEBRA_FLAG_CHECKSUM 1
@@ -83,4 +86,4 @@
/* Barcode dependent options >= 0x100 */
#endif /* HB_ZEBRA_CH_ */
#endif /* HB_ZEBRA_CH_ */

View File

@@ -36,6 +36,8 @@ msi.c
-depimplibd=cairo:cairo
-depfinish=cairo
d_gen.c
{HBMK_HAS_CAIRO}d_cairo.c
{HBMK_HAS_CAIRO}../hbcairo/hbcairo.hbc

View File

@@ -8,7 +8,7 @@
PROCEDURE main()
LOCAL hCairo, hSurface
hSurface := cairo_pdf_surface_create( "test1.pdf", 567, 794 ) // A4
hSurface := cairo_pdf_surface_create( "testcair.pdf", 567, 794 ) // A4
hCairo := cairo_create( hSurface )
cairo_set_source_rgb( hCairo, 1.0, 1.0, 1.0 )
@@ -41,7 +41,7 @@ PROCEDURE main()
DrawBarcode( hCairo, 440, 1, "CODE128", "Wikipedia")
cairo_destroy( hCairo )
cairo_surface_write_to_png( hSurface, "test1.png" )
cairo_surface_write_to_png( hSurface, "testcair.png" )
cairo_surface_destroy( hSurface )
RETURN
@@ -86,3 +86,15 @@ PROCEDURE DrawBarcode( hCairo, nY, nLineWidth, cType, cCode, nFlags )
? "Invalid barcode type", cType
ENDIF
RETURN
STATIC FUNCTION hb_zebra_draw_cairo( hZebra, hCairo, ... )
IF hb_zebra_GetError( hZebra ) != 0
RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
ENDIF
cairo_save( 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

@@ -82,3 +82,15 @@ PROCEDURE DrawBarcode( page, nY, nLineWidth, cType, cCode, nFlags )
ENDIF
RETURN
STATIC FUNCTION hb_zebra_draw_hpdf( hZebra, page, ... )
IF hb_zebra_GetError( hZebra ) != 0
RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
ENDIF
HPDF_Page_SetLineWidth( page, 0.1 ) /* Standard line width */
hb_zebra_draw( hZebra, {| x, y, w, h | HPDF_Page_Rectangle( page, x, y, w, h ) }, ... )
HPDF_Page_FillStroke( page )
RETURN 0

View File

@@ -107,7 +107,7 @@ PROCEDURE DrawBarcode( hDC, nY, nLineWidth, cType, cCode, nFlags )
IF hb_zebra_geterror( hZebra ) == 0
wapi_TextOut( hDC, 40 * _SCALE_, nY, cType )
wapi_TextOut( hDC, 150 * _SCALE_, nY, hb_zebra_getcode( hZebra ) )
hb_zebra_draw_wapi( hZebra, hDC, 300 * _SCALE_, nY, nLineWidth, 16 * _SCALE_,, wapi_CreateSolidBrush( 0 ) )
hb_zebra_draw_wapi( hZebra, hDC, wapi_CreateSolidBrush( 0 ), 300 * _SCALE_, nY, nLineWidth, 16 * _SCALE_ )
ELSE
? "Type", cType, "Code", cCode, "Error", hb_zebra_geterror( hZebra )
ENDIF
@@ -117,3 +117,11 @@ PROCEDURE DrawBarcode( hDC, nY, nLineWidth, cType, cCode, nFlags )
ENDIF
RETURN
STATIC FUNCTION hb_zebra_draw_wapi( hZebra, hDC, hBrush, ... )
IF hb_zebra_GetError( hZebra ) != 0
RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
ENDIF
RETURN hb_zebra_draw( hZebra, {| x, y, w, h | wapi_FillRect( hDC, { x, y, x + w, y + h }, hBrush ) }, ... )