FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Generar C贸digo de barras
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Generar C贸digo de barras
Posted: Sat Dec 07, 2024 11:35 PM
Tambien tuve ese problema para poder hacer el codigo de barra gs1-128, ya que utiliza otros parametros, para distinguirlo del code-128, el amigo Daniel Garcia gil hizo unas adaptacion que necesita el gs1-128,para que funcionara modifico el hzebra.prg:
Code (fw): Select all Collapse
#include "FiveWin.ch"

REQUEST FWZEBRA


function Main()

聽 聽local oPrn,cTexto2
聽 聽local cText,oFont 
聽 聽local cCodigo:=space(13)
聽 聽local cFactura:=space(12)
聽 聽local cValor:=0
聽 聽local cFecha:=space(8)

聽 聽cCodigo 聽 聽:= "7709998978584"
聽 聽cFactura 聽 := "202400124317"
聽 聽cValor 聽 聽 := 244478
聽 聽cFecha 聽 聽 := "20240831"


聽 聽 cText := chr(0xf1) + "415" + cCodigo + "8020" + cFactura + chr(0xf1) + "3900" + STRTRAN(STR(cValor ,10)," ","0") + chr(0xf1) + "96" + cFecha 
聽 聽 cTexto2 := "(415)"+cCodigo+"(8020)"+cFactura+"(3900)"+STRTRAN(STR(cValor,10)," ","0")+"(96)"+cFecha 

聽 聽DEFINE FONT oFont NAME "TAHOMA" 聽 聽 聽 聽 聽SIZE -20.5, 50 聽OF oPrn



聽PRINT oPrn NAME "Impresi贸n en Vertical.." PREVIEW
聽oPrn:SetPage(5) 聽// LEGAL

聽PAGE

聽 聽 聽 @11.3, 5 PRINT TO oPrn TEXT cText AS BARCODE TYPE "CODE128" ; //"ITF" ;
聽 聽 聽 SIZE 12, 1 CM COLOR CLR_BLACK //PINSIZE 5

聽 聽 聽 @ 12.0, 4.8 PRINT TO oPrn TEXT cTexto2 ;
聽 聽 聽 SIZE 11, 1 CM FONT oFont ALIGN "C"



聽 聽ENDPAGE
聽 聽ENDPRINT

return nil

#include 'hbzebra.prg'
Este es el hzebra:
Code (fw): Select all Collapse
//---------------------------------
#pragma BEGINDUMP
#include <hbzebra.h>
#include <hbvm.h>

// Since the FNCn characters are not ASCII, define versions here to
// simplify encoding strings that include them.
#define CODE128_FNC1 '\xf1'
// #define CODE128_FNC1 29
#define CODE128_FNC2 '\xf2'
#define CODE128_FNC3 '\xf3'
#define CODE128_FNC4 '\xf4'

HB_SIZE code128_estimate_len(const char *s);
PHB_ZEBRA code128_encode_raw(const char *s, HB_SIZE nLen, HB_SIZE maxlength);

#define CODE128_QUIET_ZONE_LEN 10
#define CODE128_CHAR_LEN 11
#define CODE128_STOP_CODE_LEN 13

#define CODE128_START_CODE_A 103
#define CODE128_START_CODE_B 104
#define CODE128_START_CODE_C 105

#define CODE128_MODE_A 'a'
#define CODE128_MODE_B 'b'
#define CODE128_MODE_C 'c'

#define CODE128_MIN_ENCODE_LEN (CODE128_QUIET_ZONE_LEN * 2 + CODE128_CHAR_LEN * 2 + CODE128_STOP_CODE_LEN)

static const unsigned short s_code[] = {
聽 聽 00633, /* 聽 聽 聽 聽 聽 00 */
聽 聽 00663, /* ! 聽 聽! 聽 聽01 */
聽 聽 01463, /* " 聽 聽" 聽 聽02 */
聽 聽 00311, /* # 聽 聽# 聽 聽03 */
聽 聽 00611, /* $ 聽 聽$ 聽 聽04 */
聽 聽 00621, /* % 聽 聽% 聽 聽05 */
聽 聽 00231, /* & 聽 聽& 聽 聽06 */
聽 聽 00431, /* ' 聽 聽' 聽 聽07 */
聽 聽 00461, /* ( 聽 聽( 聽 聽08 */
聽 聽 00223, /* ) 聽 聽) 聽 聽09 */
聽 聽 00423, /* * 聽 聽* 聽 聽10 */
聽 聽 00443, /* + 聽 聽+ 聽 聽11 */
聽 聽 00715, /* , 聽 聽, 聽 聽12 */
聽 聽 00731, /* - 聽 聽- 聽 聽13 */
聽 聽 01631, /* . 聽 聽. 聽 聽14 */
聽 聽 00635, /* / 聽 聽/ 聽 聽15 */
聽 聽 00671, /* 0 聽 聽0 聽 聽16 */
聽 聽 01471, /* 1 聽 聽1 聽 聽17 */
聽 聽 01163, /* 2 聽 聽2 聽 聽18 */
聽 聽 00723, /* 3 聽 聽3 聽 聽19 */
聽 聽 01623, /* 4 聽 聽4 聽 聽20 */
聽 聽 00473, /* 5 聽 聽5 聽 聽21 */
聽 聽 00563, /* 6 聽 聽6 聽 聽22 */
聽 聽 01667, /* 7 聽 聽7 聽 聽23 */
聽 聽 00627, /* 8 聽 聽8 聽 聽24 */
聽 聽 00647, /* 9 聽 聽9 聽 聽25 */
聽 聽 01447, /* : 聽 聽: 聽 聽26 */
聽 聽 00467, /* ; 聽 聽; 聽 聽27 */
聽 聽 00547, /* < 聽 聽< 聽 聽28 */
聽 聽 01147, /* = 聽 聽= 聽 聽29 */
聽 聽 00333, /* > 聽 聽> 聽 聽30 */
聽 聽 01433, /* ? 聽 聽? 聽 聽31 */
聽 聽 01543, /* @ 聽 聽@ 聽 聽32 */
聽 聽 00305, /* A 聽 聽A 聽 聽33 */
聽 聽 00321, /* B 聽 聽B 聽 聽34 */
聽 聽 01421, /* C 聽 聽C 聽 聽35 */
聽 聽 00215, /* D 聽 聽D 聽 聽36 */
聽 聽 00261, /* E 聽 聽E 聽 聽37 */
聽 聽 01061, /* F 聽 聽F 聽 聽38 */
聽 聽 00213, /* G 聽 聽G 聽 聽39 */
聽 聽 00243, /* H 聽 聽H 聽 聽40 */
聽 聽 01043, /* I 聽 聽I 聽 聽41 */
聽 聽 00355, /* J 聽 聽J 聽 聽42 */
聽 聽 01615, /* K 聽 聽K 聽 聽43 */
聽 聽 01661, /* L 聽 聽L 聽 聽44 */
聽 聽 00335, /* M 聽 聽M 聽 聽45 */
聽 聽 01435, /* N 聽 聽N 聽 聽46 */
聽 聽 01561, /* O 聽 聽O 聽 聽47 */
聽 聽 01567, /* P 聽 聽P 聽 聽48 */
聽 聽 01613, /* Q 聽 聽Q 聽 聽49 */
聽 聽 01643, /* R 聽 聽R 聽 聽50 */
聽 聽 00273, /* S 聽 聽S 聽 聽51 */
聽 聽 01073, /* T 聽 聽T 聽 聽52 */
聽 聽 01673, /* U 聽 聽U 聽 聽53 */
聽 聽 00327, /* V 聽 聽V 聽 聽54 */
聽 聽 01427, /* W 聽 聽W 聽 聽55 */
聽 聽 01507, /* X 聽 聽X 聽 聽56 */
聽 聽 00267, /* Y 聽 聽Y 聽 聽57 */
聽 聽 01067, /* Z 聽 聽Z 聽 聽58 */
聽 聽 01307, /* [ 聽 聽[ 聽 聽59 */
聽 聽 01367, /* \ 聽 聽\ 聽 聽60 */
聽 聽 01023, /* ] 聽 聽] 聽 聽61 */
聽 聽 01217, /* ^ 聽 聽^ 聽 聽62 */
聽 聽 00145, /* _ 聽 聽_ 聽 聽63 */
聽 聽 00605, /* NUL 聽 ` 聽 64 */
聽 聽 00151, /* SOH 聽 a 聽 65 */
聽 聽 01411, /* STX 聽 b 聽 66 */
聽 聽 00641, /* ETX 聽 c 聽 67 */
聽 聽 01441, /* EOT 聽 d 聽 68 */
聽 聽 00115, /* ENQ 聽 e 聽 69 */
聽 聽 00415, /* ACK 聽 f 聽 70 */
聽 聽 00131, /* BEL 聽 g 聽 71 */
聽 聽 01031, /* BS 聽 聽h 聽 72 */
聽 聽 00541, /* HT 聽 聽i 聽 73 */
聽 聽 01141, /* LF 聽 聽j 聽 74 */
聽 聽 01103, /* VT 聽 聽k 聽 75 */
聽 聽 00123, /* FF 聽 聽l 聽 76 */
聽 聽 01357, /* CR 聽 聽m 聽 77 */
聽 聽 00503, /* SO 聽 聽n 聽 78 */
聽 聽 01361, /* SI 聽 聽o 聽 79 */
聽 聽 00745, /* DLE 聽 p 聽 80 */
聽 聽 00751, /* DC1 聽 q 聽 81 */
聽 聽 01711, /* DC2 聽 r 聽 82 */
聽 聽 00475, /* DC3 聽 s 聽 83 */
聽 聽 00571, /* DC4 聽 t 聽 84 */
聽 聽 01171, /* NAK 聽 u 聽 85 */
聽 聽 00457, /* SYN 聽 v 聽 86 */
聽 聽 00517, /* ETB 聽 w 聽 87 */
聽 聽 01117, /* CAN 聽 x 聽 88 */
聽 聽 01733, /* EM 聽 聽y 聽 89 */
聽 聽 01573, /* SUB 聽 z 聽 90 */
聽 聽 01557, /* ESC 聽 { 聽 91 */
聽 聽 00365, /* FS 聽 聽| 聽 92 */
聽 聽 01705, /* GS 聽 聽} 聽 93 */
聽 聽 01721, /* RS 聽 聽~ 聽 94 */
聽 聽 00275, /* US 聽 DEL 聽95 */
聽 聽 01075, /* FNC3 FNC3 96 */
聽 聽 00257, /* FNC2 FNC2 97 */
聽 聽 01057, /* ShiB ShiA 98 */
聽 聽 01735, /* CodC CodC 99 */
聽 聽 01675, /* CodB FNC4 CodB 100 */
聽 聽 01727, /* FNC4 CodA CodA 101 */
聽 聽 01657, /* FNC1 FNC1 FNC1 102 */
聽 聽 00413, /* Start Code A 聽 103 */
聽 聽 00113, /* Start Code B 聽 104 */
聽 聽 00713 聽/* Start Code C 聽 105 */ 聽 聽 聽 聽
};

struct code128_step
{
聽 int prev_ix; 聽 聽 聽 聽 聽 聽// Index of previous step, if any
聽 const char *next_input; // Remaining input
聽 unsigned short len; 聽 聽 // The length of the pattern so far (includes this step)
聽 char mode; 聽 聽 聽 聽 聽 聽 聽// State for the current encoding
聽 signed char code; 聽 聽 聽 // What code should be written for this step
};

struct code128_state
{
聽 struct code128_step *steps;
聽 int allocated_steps;
聽 int current_ix;
聽 int todo_ix;
聽 int best_ix;

聽 HB_SIZE maxlength;
};

HB_SIZE code128_estimate_len(const char *s)
{
聽 return CODE128_QUIET_ZONE_LEN + CODE128_CHAR_LEN 聽// start code
聽 聽 聽 聽 聽+ CODE128_CHAR_LEN * (strlen(s) * 11 / 10) // contents + 10% padding
聽 聽 聽 聽 聽+ CODE128_CHAR_LEN 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // checksum
聽 聽 聽 聽 聽+ CODE128_STOP_CODE_LEN + CODE128_QUIET_ZONE_LEN;
}

static unsigned char code128_switch_code(char from_mode, char to_mode)
{
聽 switch (from_mode)
聽 {
聽 case CODE128_MODE_A:
聽 聽 switch (to_mode)
聽 聽 {
聽 聽 case CODE128_MODE_B:
聽 聽 聽 return 100;
聽 聽 case CODE128_MODE_C:
聽 聽 聽 return 99;
聽 聽 }

聽 case CODE128_MODE_B:
聽 聽 switch (to_mode)
聽 聽 {
聽 聽 case CODE128_MODE_A:
聽 聽 聽 return 101;
聽 聽 case CODE128_MODE_C:
聽 聽 聽 return 99;
聽 聽 }

聽 case CODE128_MODE_C:
聽 聽 switch (to_mode)
聽 聽 {
聽 聽 case CODE128_MODE_B:
聽 聽 聽 return 100;
聽 聽 case CODE128_MODE_A:
聽 聽 聽 return 101;
聽 聽 }
聽 }

聽 return 0;
}

static signed char code128a_ascii_to_code(char value)
{
聽 if (value >= ' ' && value <= '_')
聽 聽 return value - ' ';
聽 else if (value >= 0 && value < ' ')
聽 聽 return value + 64;
聽 else if (value == CODE128_FNC1)
聽 聽 return 102;
聽 else if (value == CODE128_FNC2)
聽 聽 return 97;
聽 else if (value == CODE128_FNC3)
聽 聽 return 96;
聽 else if (value == CODE128_FNC4)
聽 聽 return 101;
聽 else
聽 聽 return -1;
}

static signed char code128b_ascii_to_code(char value)
{
聽 if (value >= 32) // value <= 127 is implied
聽 聽 return value - 32;
聽 else if (value == CODE128_FNC1)
聽 聽 return 102;
聽 else if (value == CODE128_FNC2)
聽 聽 return 97;
聽 else if (value == CODE128_FNC3)
聽 聽 return 96;
聽 else if (value == CODE128_FNC4)
聽 聽 return 100;
聽 else
聽 聽 return -1;
}

static signed char code128c_ascii_to_code(const char *values)
{
聽 if (values[0] == CODE128_FNC1)
聽 聽 return 102;

聽 if (values[0] >= '0' && values[0] <= '9' &&
聽 聽 聽 values[1] >= '0' && values[1] <= '9')
聽 {
聽 聽 char code = 10 * (values[0] - '0') + (values[1] - '0');
聽 聽 return code;
聽 }

聽 return -1;
}

static int code128_do_a_step(struct code128_step *base, int prev_ix, int ix)
{
聽 struct code128_step *previous_step = &base[prev_ix];
聽 struct code128_step *step = &base[ix];

聽 char value = *previous_step->next_input;
聽 // NOTE: Currently we can't encode NULL
聽 if (value == 0)
聽 聽 return 0;

聽 step->code = code128a_ascii_to_code(value);
聽 if (step->code < 0)
聽 聽 return 0;

聽 step->prev_ix = prev_ix;
聽 step->next_input = previous_step->next_input + 1;
聽 step->mode = CODE128_MODE_A;
聽 step->len = previous_step->len + CODE128_CHAR_LEN;
聽 if (step->mode != previous_step->mode)
聽 聽 step->len += CODE128_CHAR_LEN; // Need to switch modes

聽 return 1;
}

static int code128_do_b_step(struct code128_step *base, int prev_ix, int ix)
{
聽 struct code128_step *previous_step = &base[prev_ix];
聽 struct code128_step *step = &base[ix];

聽 char value = *previous_step->next_input;
聽 // NOTE: Currently we can't encode NULL
聽 if (value == 0)
聽 聽 return 0;

聽 step->code = code128b_ascii_to_code(value);
聽 if (step->code < 0)
聽 聽 return 0;

聽 step->prev_ix = prev_ix;
聽 step->next_input = previous_step->next_input + 1;
聽 step->mode = CODE128_MODE_B;
聽 step->len = previous_step->len + CODE128_CHAR_LEN;
聽 if (step->mode != previous_step->mode)
聽 聽 step->len += CODE128_CHAR_LEN; // Need to switch modes

聽 return 1;
}

static int code128_do_c_step(struct code128_step *base, int prev_ix, int ix)
{
聽 struct code128_step *previous_step = &base[prev_ix];
聽 struct code128_step *step = &base[ix];

聽 char value = *previous_step->next_input;
聽 // NOTE: Currently we can't encode NULL
聽 if (value == 0)
聽 聽 return 0;

聽 step->code = code128c_ascii_to_code(previous_step->next_input);
聽 if (step->code < 0)
聽 聽 return 0;

聽 step->prev_ix = prev_ix;
聽 step->next_input = previous_step->next_input + 1;

聽 // Mode C consumes 2 characters for codes 0-99
聽 if (step->code < 100)
聽 聽 step->next_input++;

聽 step->mode = CODE128_MODE_C;
聽 step->len = previous_step->len + CODE128_CHAR_LEN;
聽 if (step->mode != previous_step->mode)
聽 聽 step->len += CODE128_CHAR_LEN; // Need to switch modes

聽 return 1;
}

static struct code128_step *code128_alloc_step(struct code128_state *state)
{
聽 struct code128_step *step;
聽 if (state->todo_ix >= state->allocated_steps)
聽 {
聽 聽 state->allocated_steps += 1024;
聽 聽 state->steps = (struct code128_step *)hb_xrealloc(state->steps, state->allocated_steps * sizeof(struct code128_step));
聽 }

聽 step = &state->steps[state->todo_ix];

聽 hb_xmemset(step, 0, sizeof(*step));
聽 return step;
}

static void code128_do_step(struct code128_state *state)
{
聽 struct code128_step *step = &state->steps[state->current_ix];
聽 char mode;
聽 int mode_c_worked = 0;

聽 if (*step->next_input == 0)
聽 {
聽 聽 // Done, so see if we have a new shortest encoding.
聽 聽 if ((step->len < (unsigned short)state->maxlength) ||
聽 聽 聽 聽 (state->best_ix < 0 && step->len == (unsigned short)state->maxlength))
聽 聽 {
聽 聽 聽 state->best_ix = state->current_ix;

聽 聽 聽 // Update maxlength to avoid considering anything longer
聽 聽 聽 state->maxlength = step->len;
聽 聽 }
聽 聽 return;
聽 }

聽 // Don't try if we're already at or beyond the max acceptable
聽 // length;
聽 if (step->len >= (unsigned short)state->maxlength)
聽 聽 return;
聽 mode = step->mode;

聽 code128_alloc_step(state);
聽 

聽 // Always try mode C
聽 if (code128_do_c_step(state->steps, state->current_ix, state->todo_ix))
聽 {
聽 聽 state->todo_ix++;
聽 聽 code128_alloc_step(state);
聽 聽 mode_c_worked = 1;
聽 }

聽 if (mode == CODE128_MODE_A)
聽 {
聽 聽 // If A works, stick with A. There's no advantage to switching
聽 聽 // to B proactively if A still works.
聽 聽 if (code128_do_a_step(state->steps, state->current_ix, state->todo_ix) ||
聽 聽 聽 聽 code128_do_b_step(state->steps, state->current_ix, state->todo_ix))
聽 聽 聽 state->todo_ix++;
聽 }
聽 else if (mode == CODE128_MODE_B)
聽 {
聽 聽 // The same logic applies here. There's no advantage to switching
聽 聽 // proactively to A if B still works.
聽 聽 if (code128_do_b_step(state->steps, state->current_ix, state->todo_ix) ||
聽 聽 聽 聽 code128_do_a_step(state->steps, state->current_ix, state->todo_ix))
聽 聽 聽 state->todo_ix++;
聽 }
聽 else if (!mode_c_worked)
聽 {
聽 聽 // In mode C. If mode C worked and we're in mode C, trying anything
聽 聽 // else is pointless since the mode C encoding will be shorter and
聽 聽 // there won't be any mode switches.

聽 聽 // If we're leaving mode C, though, try both in case one ends up
聽 聽 // better than the other.
聽 聽 if (code128_do_a_step(state->steps, state->current_ix, state->todo_ix))
聽 聽 {
聽 聽 聽 state->todo_ix++;
聽 聽 聽 code128_alloc_step(state);
聽 聽 }
聽 聽 if (code128_do_b_step(state->steps, state->current_ix, state->todo_ix))
聽 聽 {
聽 聽 聽 state->todo_ix++;
聽 聽 }
聽 }
}

PHB_ZEBRA code128_encode_raw(const char *szCode, HB_SIZE nLen, HB_SIZE maxlength)
{
聽 PHB_ZEBRA pZebra;
聽 struct code128_state state;
聽 HB_SIZE i, j;
聽 int csum;
聽 HB_SIZE num_codes;
聽 unsigned char * codes;
聽 struct code128_step *step;

聽 const HB_SIZE overhead = CODE128_QUIET_ZONE_LEN + CODE128_CHAR_LEN // checksum
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ CODE128_STOP_CODE_LEN + CODE128_QUIET_ZONE_LEN;
聽 pZebra = hb_zebra_create();
聽 pZebra->iType = HB_ZEBRA_TYPE_CODE128;

聽 if (maxlength < overhead + CODE128_CHAR_LEN + CODE128_CHAR_LEN)
聽 {
聽 聽 // Need space to encode the start character and one additional
聽 聽 // character.
聽 聽 pZebra->iError = HB_ZEBRA_ERROR_INVALIDCODE;
聽 聽 return pZebra;
聽 }

聽 /* make print string */
聽 pZebra->szCode = (char *)hb_xgrab(nLen + 1);
聽 j = 0;
聽 for (i = 0; i < nLen; i++)
聽 {
聽 聽 if ((szCode[i] >= 32 && szCode[i] <= 126))
聽 聽 聽 pZebra->szCode[j++] = szCode[i];
聽 }
聽 pZebra->szCode[j] = '\0';
聽 printf("codigo %s\n", pZebra->szCode);

聽 state.allocated_steps = 256;
聽 state.steps = (struct code128_step *)hb_xgrab(state.allocated_steps * sizeof(struct code128_step));
聽 state.current_ix = 0;
聽 state.todo_ix = 0;
聽 state.maxlength = maxlength - overhead;
聽 state.best_ix = -1;
聽 // Initialize the first 3 steps for the 3 encoding routes (A, B, C)
聽 state.steps[0].prev_ix = -1;
聽 state.steps[0].next_input = szCode;
聽 state.steps[0].len = CODE128_CHAR_LEN;
聽 state.steps[0].mode = CODE128_MODE_C;
聽 state.steps[0].code = CODE128_START_CODE_C;

聽 state.steps[1].prev_ix = -1;
聽 state.steps[1].next_input = szCode;
聽 state.steps[1].len = CODE128_CHAR_LEN;
聽 state.steps[1].mode = CODE128_MODE_A;
聽 state.steps[1].code = CODE128_START_CODE_A;

聽 state.steps[2].prev_ix = -1;
聽 state.steps[2].next_input = szCode;
聽 state.steps[2].len = CODE128_CHAR_LEN;
聽 state.steps[2].mode = CODE128_MODE_B;
聽 state.steps[2].code = CODE128_START_CODE_B;

聽 state.todo_ix = 3;

聽 // Keep going until no more work
聽 do
聽 {
聽 聽 code128_do_step(&state);
聽 聽 state.current_ix++;
聽 } while (state.current_ix != state.todo_ix);

聽 // If no best_step, then fail.
聽 if (state.best_ix < 0)
聽 {
聽 聽 pZebra->iError = HB_ZEBRA_ERROR_INVALIDCODE;
聽 聽 return pZebra;
聽 }

聽 // Determine the list of codes
聽 num_codes = state.maxlength / CODE128_CHAR_LEN;
聽 codes = hb_xgrab( sizeof( unsigned char ) * num_codes );
聽 step = &state.steps[state.best_ix];

聽 for (i = num_codes - 1; i > 0; --i)
聽 {
聽 聽 struct code128_step *prev_step = &state.steps[step->prev_ix];
聽 聽 codes[i] = step->code;
聽 聽 if (step->mode != prev_step->mode)
聽 聽 {
聽 聽 聽 --i;
聽 聽 聽 codes[i] = code128_switch_code(prev_step->mode, step->mode);
聽 聽 聽 if (codes[i] == 0)
聽 聽 聽 {
聽 聽 聽 聽 pZebra->iError = HB_ZEBRA_ERROR_INVALIDCODE;
聽 聽 聽 聽 return pZebra;
聽 聽 聽 }
聽 聽 }
聽 聽 step = prev_step;
聽 }
聽 codes[0] = step->code;
聽 //

聽 pZebra->pBits = hb_bitbuffer_create();
聽 csum = codes[0];

聽 for (i = 0; i < num_codes; i++)
聽 {
聽 聽 hb_bitbuffer_cat_int(pZebra->pBits, s_code[codes[i]], 11);
聽 聽 csum += i * codes[i];
聽 }

聽 // /* checksum */
聽 hb_bitbuffer_cat_int(pZebra->pBits, s_code[csum % 103], 11);

聽 hb_bitbuffer_cat_int(pZebra->pBits, 0x1AE3, 13);

聽 hb_xfree(state.steps);
聽 hb_xfree( codes );
聽 return pZebra;
}

HB_FUNC(HB_ZEBRA_CREATE_CODE128)
{
聽 PHB_ITEM pItem = hb_param(1, HB_IT_STRING);
聽 char *s = (char *)hb_itemGetCPtr(pItem);
聽 char raw[4096];
聽 int width;
聽 int iCountChar = 0;

聽 char *p = raw;
聽 for (; *s != '\0'; s++)
聽 {
聽 聽 if (strncmp(s, "[FNC1]", 6) == 0)
聽 聽 {
聽 聽 聽 *p++ = CODE128_FNC1;
聽 聽 聽 s += 5;
聽 聽 }
聽 聽 else if (*s != ' ')
聽 聽 {
聽 聽 聽 *p++ = *s;
聽 聽 }
聽 聽 iCountChar++;
聽 }
聽 *p = '\0';

聽 width = code128_estimate_len(hb_parc(1));

聽 if (pItem)
聽 聽 hb_zebra_ret(code128_encode_raw(raw, (HB_SIZE)iCountChar, width));
聽 else
聽 聽 hb_errRT_BASE(EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS);
}

#pragma ENDDUMP
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Generar C贸digo de barras
Posted: Sat Dec 07, 2024 11:41 PM
Esta es la configuracion del gs1-128:

[img]
https://postimg.cc/XBnyNKpP
[/img]
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Generar C贸digo de barras
Posted: Sat Dec 07, 2024 11:46 PM

Hasta donde se fwh, no proporciona el GS1-128, por eso tuve que adaptarlo, con la ayuda de DANIEL GARCIA GIL, yo lo necesitava para pagos de facturas en bancos, los bancos me lo regresaban. Hasta ahora funciona perfectamente.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Generar C贸digo de barras
Posted: Mon Dec 09, 2024 02:14 PM
Tambien tuve ese problema para poder hacer el codigo de barra gs1-128, ya que utiliza otros parametros, para distinguirlo del code-128, el amigo Daniel Garcia gil hizo unas adaptacion que necesita el gs1-128,para que funcionara modifico el hzebra.prg:
Mr. Daniel is Great !!
Does this code produce GS1 - 128 correctly?
Regards



G. N. Rao.

Hyderabad, India
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Generar C贸digo de barras
Posted: Tue Dec 10, 2024 05:47 PM

Lo Bueno seria tambi茅n que estuviera en imagen png/jpg, pueda ser que el amigo nageswaragunupudi, se anime y nos de ese regalo en la ultima actualizaci贸n de fwh de este a帽o.

Continue the discussion