Page 1 of 1

Rectangular Data Matrix barcode

PostPosted: Thu Aug 17, 2017 3:07 pm
by Enrico Maria Giordano
Somebody knows how to print rectangular Data Matrix barcode? I tried with hbzebra and it works for square Data Matrix code. I don't understand how to get rectangular code without stretching the code itself.

EMG

Re: Rectangular Data Matrix barcode

PostPosted: Thu Aug 17, 2017 4:39 pm
by Silvio.Falconi
perhaps
Image

with barlib we can make the 1D barcodes

with hzebra we can make 2D barcodes ( i think this lib also on working)

Why we cannot make a lib with all barcodes ?

for a sample I made also circular barcodes for dvd shop

I think Mastintin can help you

Re: Rectangular Data Matrix barcode

PostPosted: Thu Aug 17, 2017 7:11 pm
by Massimo Linossi
Enrico, you can try this. Works perfectly.
With the standard libraries you can't make the data matrix barcode rectangular.
https://www.barcodetools.com/datamatrix/datamatrix-activex/introduction.html

Re: Rectangular Data Matrix barcode

PostPosted: Thu Aug 17, 2017 7:28 pm
by Enrico Maria Giordano
Thank you, but I'm searching for something simpler and possibly free.

EMG

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 1:38 pm
by Enrico Maria Giordano
Found! This is a working sample:

Code: Select all  Expand view
#include "Fivewin.ch"


#define HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE 0x0200


FUNCTION MAIN()

    LOCAL oPrn

    PRINT oPrn PREVIEW
        PAGE
            DATAMATRIX( oPrn, "12345678901234567890123456789012345678901234567890", 1000, 1000, HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE )
        ENDPAGE
    ENDPRINT

    RETURN NIL


FUNCTION DATAMATRIX( oPrn, cCod, nWidth, nHeight, nFlags )

    LOCAL hDCDesk := GETDC( GETDESKTOPWINDOW() )

    LOCAL hDCMem := CREATECOMPATIBLEDC( hDCDesk )

    LOCAL hBrush := CREATESOLIDBRUSH( 0 )
    LOCAL hBack  := CREATESOLIDBRUSH( CLR_WHITE )

    LOCAL hBmp := CREATECOMPATIBLEBITMAP( hDCDesk, nWidth, nHeight )

    LOCAL hBmpOld := SELECTOBJECT( hDCMem, hBmp )  

    LOCAL hZebra := HB_ZEBRA_CREATE_DATAMATRIX( cCod, nFlags )

    LOCAL hDib

    FILLRECT( hDCMem, { 0, 0, nHeight, nWidth }, hBack )

    HB_ZEBRA_DRAW( hZebra, { | x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, 20, 20 )

    hDib = DIBFROMBITMAP( hBmp )

    DIBDRAW( oPrn:hDCOut, hDib, , 500, 500 )

    GLOBALFREE( hDib )

    SELECTOBJECT( hDCMem, hBmpOld )

    DELETEOBJECT( hBrush )
    DELETEOBJECT( hBack )

    HB_ZEBRA_DESTROY( hZebra )

    DELETEOBJECT( hBmp )

    DELETEDC( hDCMem )

    RELEASEDC( GETDESKTOPWINDOW(), hDCDesk )

    RETURN NIL


EMG

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 2:10 pm
by karinha
Good morning Enrico.

Why does not this work?

Thank you.

Code: Select all  Expand view

#include "Fivewin.ch"

#define HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE 0x0200

FUNCTION MAIN()

    LOCAL oPrn, cText

    // Original by Enrico,
    // cText := "12345678901234567890123456789012345678901234567890"
    // cText := MemoRead( ".\QRCODE.TXT" )

    // Asi, no funciona.
    cText := "35141146377222003730599000004630001158179941|20141105134922|10.00|61694805808|m+4o8FY1lig1zcy6VU3t7INVwE6kiA/ykLXKDFZfb9gu0g4wl3Fk2HYaRhSt8G+yk9mP/R65m3R7V2IO8CxnmO1oVtlamB6UKA+UZZqDNEqtYlhQzLySNzMG0thaNMZsq5RxmQ3eQLPw8LLez3MqWvUveFXNSSq6AGEX2+KOdavteo3K2L06SQoVIjwkmcgRzqhfHP3y8t2wfr1nw/WAnaCF9ZY/K4dTykk3hsXcan/MKCTBlcSOhNgSh3sdsQHpl2w2tmbLBsYBLFkuvKlwzHarNJQ1RfRznGdojHglQH1KVtbAUXKke54pdRt3JL7nJlR+Lbmtd2tjcT2vRyTepw=="

    PRINT oPrn PREVIEW MODAL
        PAGE
            DATAMATRIX( oPrn, cText, 1000, 1000, HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE )
        ENDPAGE
    ENDPRINT

RETURN NIL


FUNCTION DATAMATRIX( oPrn, cCod, nWidth, nHeight, nFlags )

    LOCAL hDCDesk := GETDC( GETDESKTOPWINDOW() )

    LOCAL hDCMem := CREATECOMPATIBLEDC( hDCDesk )

    LOCAL hBrush := CREATESOLIDBRUSH( 0 )
    LOCAL hBack  := CREATESOLIDBRUSH( CLR_WHITE )

    LOCAL hBmp := CREATECOMPATIBLEBITMAP( hDCDesk, nWidth, nHeight )

    LOCAL hBmpOld := SELECTOBJECT( hDCMem, hBmp )  

    LOCAL hZebra := HB_ZEBRA_CREATE_DATAMATRIX( cCod, nFlags )

    LOCAL hDib

    FILLRECT( hDCMem, { 0, 0, nHeight, nWidth }, hBack )

    HB_ZEBRA_DRAW( hZebra, { | x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBrush ) }, 0, 0, 20, 20 )

    hDib = DIBFROMBITMAP( hBmp )

    DIBDRAW( oPrn:hDCOut, hDib, , 500, 500 )

    GLOBALFREE( hDib )

    SELECTOBJECT( hDCMem, hBmpOld )

    DELETEOBJECT( hBrush )
    DELETEOBJECT( hBack )

    HB_ZEBRA_DESTROY( hZebra )

    DELETEOBJECT( hBmp )

    DELETEDC( hDCMem )

    RELEASEDC( GETDESKTOPWINDOW(), hDCDesk )

RETURN NIL
 


Regards, saludos.

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 2:15 pm
by Enrico Maria Giordano
Probably the code is too long.

EMG

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 2:17 pm
by Enrico Maria Giordano
It does work this way:

Code: Select all  Expand view
DATAMATRIX( oPrn, cText, 1000, 1000, 0 )


EMG

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 2:24 pm
by karinha
Great Enrico. You are fantastic. Thank you very much.

Image

Regards, saludos.

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 5:30 pm
by Silvio.Falconi
why here I see it ?

Image

Re: Rectangular Data Matrix barcode

PostPosted: Fri Aug 18, 2017 5:34 pm
by Silvio.Falconi
on ctext what we can insert ?
for a sample for a catalog product ?

Re: Rectangular Data Matrix barcode

PostPosted: Sat Aug 19, 2017 9:54 am
by Enrico Maria Giordano
Simplified and added more parameters:

Code: Select all  Expand view
#include "Fivewin.ch"


#define HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE 0x0200


FUNCTION MAIN()

    LOCAL oPrn

    PRINT oPrn PREVIEW
        PAGE
            DATAMATRIX( oPrn,  500, 500, "12345678901234567890123456789012345678901234567890", 1000, 1000, HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE )
            DATAMATRIX( oPrn, 1000, 500, "12345678901234567890123456789012345678901234567890", 1000, 1000, HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE )
            DATAMATRIX( oPrn, 1500, 500, "18201106000006117254120000195947121000000010003896", 1000, 1000, HB_ZEBRA_FLAG_DATAMATRIX_RECTANGLE )
        ENDPAGE
    ENDPRINT

    RETURN NIL


FUNCTION DATAMATRIX( oPrn, nRow, nCol, cCode, nWidth, nHeight, nFlags, nCodeWidth, nCodeHeight )

    LOCAL hDCMem := CREATECOMPATIBLEDC( oPrn:hDC )

    LOCAL hBBrush := CREATESOLIDBRUSH( CLR_BLACK )
    LOCAL hWBrush := CREATESOLIDBRUSH( CLR_WHITE )

    LOCAL hBmp := CREATECOMPATIBLEBITMAP( oPrn:hDC, nWidth, nHeight )

    LOCAL hBmpOld := SELECTOBJECT( hDCMem, hBmp )  

    LOCAL hZebra := HB_ZEBRA_CREATE_DATAMATRIX( cCode, nFlags )

    LOCAL hDib

    DEFAULT nCodeWidth  := 10
    DEFAULT nCodeHeight := 10

    FILLRECT( hDCMem, { 0, 0, nHeight, nWidth }, hWBrush )

    HB_ZEBRA_DRAW( hZebra, { | x, y, w, h | FillRect( hDCMem, { y, x, y +  h, x + w }, hBBrush ) }, 0, 0, nCodeWidth, nCodeHeight )

    HB_ZEBRA_DESTROY( hZebra )

    SELECTOBJECT( hDCMem, hBmpOld )

    hDib = DIBFROMBITMAP( hBmp )

    DIBDRAW( oPrn:hDCOut, hDib, , nRow, nCol )

    GLOBALFREE( hDib )

    DELETEOBJECT( hBmp )

    DELETEOBJECT( hBBrush )
    DELETEOBJECT( hWBrush )

    DELETEDC( hDCMem )

    RETURN NIL


EMG