mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Plot Codablock symbols to file and in Studio
This commit is contained in:
parent
a7bcef4ef7
commit
d86ac40b20
@ -31,15 +31,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "gs1.h"
|
#include "gs1.h"
|
||||||
|
|
||||||
#define uchar unsigned char
|
#define uchar unsigned char
|
||||||
|
|
||||||
/* FTab Flagzeichen - Addierbar */
|
/* FTab Flagzeichen - Addierbar */
|
||||||
@ -50,18 +50,35 @@
|
|||||||
#define CShift 16
|
#define CShift 16
|
||||||
#define CFill 32
|
#define CFill 32
|
||||||
#define CodeFNC1 64
|
#define CodeFNC1 64
|
||||||
#define ZTNum (CodeA+CodeB+CodeC)
|
#define ZTNum (CodeA+CodeB+CodeC)
|
||||||
#define ZTFNC1 (CodeA+CodeB+CodeC+CodeFNC1)
|
#define ZTFNC1 (CodeA+CodeB+CodeC+CodeFNC1)
|
||||||
|
|
||||||
/* ASCII-Extension for Codablock-F */
|
/* ASCII-Extension for Codablock-F */
|
||||||
#define aFNC1 (uchar)(128)
|
#define aFNC1 (uchar)(128)
|
||||||
#define aFNC2 (uchar)(129)
|
#define aFNC2 (uchar)(129)
|
||||||
#define aFNC3 (uchar)(130)
|
#define aFNC3 (uchar)(130)
|
||||||
#define aFNC4 (uchar)(131)
|
#define aFNC4 (uchar)(131)
|
||||||
#define aCodeA (uchar)(132)
|
#define aCodeA (uchar)(132)
|
||||||
#define aCodeB (uchar)(133)
|
#define aCodeB (uchar)(133)
|
||||||
#define aCodeC (uchar)(134)
|
#define aCodeC (uchar)(134)
|
||||||
#define aShift (uchar)(135)
|
#define aShift (uchar)(135)
|
||||||
|
|
||||||
|
static const char *C128Table[107] = {
|
||||||
|
/* Code 128 character encodation - Table 1 */
|
||||||
|
"212222", "222122", "222221", "121223", "121322", "131222", "122213",
|
||||||
|
"122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222",
|
||||||
|
"123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222",
|
||||||
|
"321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323",
|
||||||
|
"131123", "131321", "112313", "132113", "132311", "211313", "231113", "231311", "112133",
|
||||||
|
"112331", "132131", "113123", "113321", "133121", "313121", "211331", "231131", "213113",
|
||||||
|
"213311", "213131", "311123", "311321", "331121", "312113", "312311", "332111", "314111",
|
||||||
|
"221411", "431111", "111224", "111422", "121124", "121421", "141122", "141221", "112214",
|
||||||
|
"112412", "122114", "122411", "142112", "142211", "241211", "221114", "413111", "241112",
|
||||||
|
"134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112",
|
||||||
|
"421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311",
|
||||||
|
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
|
||||||
|
"2331112"
|
||||||
|
};
|
||||||
|
|
||||||
/* Code F Analysing-Chart */
|
/* Code F Analysing-Chart */
|
||||||
typedef struct sCharacterSetTable
|
typedef struct sCharacterSetTable
|
||||||
@ -357,7 +374,7 @@ int Columns2Rows(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
memset(pSet,0,dataLength*sizeof(int));
|
memset(pSet,0,dataLength*sizeof(int));
|
||||||
}else{
|
}else{
|
||||||
/* Calculate real Length of OneLiner */
|
/* Calculate real Length of OneLiner */
|
||||||
/* This is -2 BASED !!! */
|
/* This is -2 BASED !!! */
|
||||||
useColumns-=emptyColumns;
|
useColumns-=emptyColumns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,7 +411,7 @@ int Columns2Rows(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
printf(" -> out: rowsCur <%i>, useColumns <%i>, fillings <%i>\n",rowsCur,useColumns,fillings);
|
printf(" -> out: rowsCur <%i>, useColumns <%i>, fillings <%i>\n",rowsCur,useColumns,fillings);
|
||||||
#endif
|
#endif
|
||||||
*pUseColumns=useColumns;
|
*pUseColumns=useColumns;
|
||||||
*pRows=rowsCur;
|
*pRows=rowsCur;
|
||||||
*pFillings=fillings;
|
*pFillings=fillings;
|
||||||
return 0;
|
return 0;
|
||||||
@ -411,7 +428,7 @@ int Columns2Rows(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||||
int * pRows, int * pUseColumns, int * pSet, int * pFillings)
|
int * pRows, int * pUseColumns, int * pSet, int * pFillings)
|
||||||
{
|
{
|
||||||
int errorCur;
|
int errorCur;
|
||||||
int rowsCur;
|
int rowsCur;
|
||||||
int rowsRequested; /* Number of Lines Requested */
|
int rowsRequested; /* Number of Lines Requested */
|
||||||
int backupRows;
|
int backupRows;
|
||||||
@ -422,11 +439,11 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
int backupColumns;
|
int backupColumns;
|
||||||
int fBackupOk; /* The memorysed set is o.k. */
|
int fBackupOk; /* The memorysed set is o.k. */
|
||||||
int testListSize = 0;
|
int testListSize = 0;
|
||||||
int pTestList[62];
|
int pTestList[62];
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
int *pBackupSet[dataLength];
|
int *pBackupSet[dataLength];
|
||||||
#else
|
#else
|
||||||
int *pBackupSet = (int *)_alloca(dataLength*sizeof(int));
|
int *pBackupSet = (int *)_alloca(dataLength*sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rowsRequested=*pRows;
|
rowsRequested=*pRows;
|
||||||
@ -452,13 +469,13 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
pTestList[testListSize] = testColumns;
|
pTestList[testListSize] = testColumns;
|
||||||
testListSize++;
|
testListSize++;
|
||||||
useColumns=testColumns; /* Make a copy because it may be modified */
|
useColumns=testColumns; /* Make a copy because it may be modified */
|
||||||
errorCur = Columns2Rows(T, data, dataLength, &rowsCur, &useColumns, pSet, &fillings);
|
errorCur = Columns2Rows(T, data, dataLength, &rowsCur, &useColumns, pSet, &fillings);
|
||||||
if (errorCur != 0)
|
if (errorCur != 0)
|
||||||
return errorCur;
|
return errorCur;
|
||||||
if (rowsCur<=rowsRequested) {
|
if (rowsCur<=rowsRequested) {
|
||||||
/* Less or exactly line number found */
|
/* Less or exactly line number found */
|
||||||
/* check if column count below already tested or Count = 1*/
|
/* check if column count below already tested or Count = 1*/
|
||||||
int fInTestList = (rowsCur == 1);
|
int fInTestList = (rowsCur == 1);
|
||||||
int posCur;
|
int posCur;
|
||||||
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
|
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
|
||||||
if ( pTestList[posCur] == testColumns-1 )
|
if ( pTestList[posCur] == testColumns-1 )
|
||||||
@ -491,7 +508,7 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
--testColumns;
|
--testColumns;
|
||||||
} else {
|
} else {
|
||||||
/* > To many lines */
|
/* > To many lines */
|
||||||
int fInTestList = fBackupOk;
|
int fInTestList = fBackupOk;
|
||||||
int posCur;
|
int posCur;
|
||||||
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
|
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
|
||||||
if ( pTestList[posCur] == testColumns+1 )
|
if ( pTestList[posCur] == testColumns+1 )
|
||||||
@ -518,114 +535,116 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print a character in character set A
|
/* Print a character in character set A
|
||||||
*/
|
*/
|
||||||
void A2C128_A(uchar **ppOutPos,uchar c)
|
void A2C128_A(uchar **ppOutPos,uchar c)
|
||||||
{
|
{
|
||||||
uchar * pOutPos = *ppOutPos;
|
uchar * pOutPos = *ppOutPos;
|
||||||
switch(c){
|
switch(c){
|
||||||
case aCodeB: *pOutPos=100; break;
|
case aCodeB: *pOutPos=100; break;
|
||||||
case aFNC4: *pOutPos=101; break;
|
case aFNC4: *pOutPos=101; break;
|
||||||
case aFNC1: *pOutPos=102; break;
|
case aFNC1: *pOutPos=102; break;
|
||||||
case aFNC2: *pOutPos=97; break;
|
case aFNC2: *pOutPos=97; break;
|
||||||
case aFNC3: *pOutPos=96; break;
|
case aFNC3: *pOutPos=96; break;
|
||||||
case aCodeC: *pOutPos=99; break;
|
case aCodeC: *pOutPos=99; break;
|
||||||
case aShift: *pOutPos=98; break;
|
case aShift: *pOutPos=98; break;
|
||||||
default:
|
default:
|
||||||
/* +++ HaO 13.11.98 c>' ' && c < '\x1F' corrected */
|
/* +++ HaO 13.11.98 c>' ' && c < '\x1F' corrected */
|
||||||
if(c>=' ' && c<='_')
|
if(c>=' ' && c<='_')
|
||||||
*pOutPos=(uchar)(c-' ');
|
*pOutPos=(uchar)(c-' ');
|
||||||
else
|
else
|
||||||
*pOutPos=(uchar)(c+64);
|
*pOutPos=(uchar)(c+64);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*ppOutPos)++;
|
(*ppOutPos)++;
|
||||||
}
|
}
|
||||||
/* Output c in Set B
|
/* Output c in Set B
|
||||||
*/
|
*/
|
||||||
void A2C128_B(uchar **ppOutPos,uchar c)
|
void A2C128_B(uchar **ppOutPos,uchar c)
|
||||||
{
|
{
|
||||||
uchar * pOutPos = *ppOutPos;
|
uchar * pOutPos = *ppOutPos;
|
||||||
switch(c){
|
switch(c){
|
||||||
case aFNC1: *pOutPos=102; break;
|
case aFNC1: *pOutPos=102; break;
|
||||||
case aFNC2: *pOutPos=97; break;
|
case aFNC2: *pOutPos=97; break;
|
||||||
case aFNC3: *pOutPos=96; break;
|
case aFNC3: *pOutPos=96; break;
|
||||||
case aFNC4: *pOutPos=100; break;
|
case aFNC4: *pOutPos=100; break;
|
||||||
case aCodeA: *pOutPos=101; break;
|
case aCodeA: *pOutPos=101; break;
|
||||||
case aCodeC: *pOutPos=99; break;
|
case aCodeC: *pOutPos=99; break;
|
||||||
case aShift: *pOutPos=98; break;
|
case aShift: *pOutPos=98; break;
|
||||||
default: *pOutPos=(uchar)(c-' '); break;
|
default: *pOutPos=(uchar)(c-' '); break;
|
||||||
}
|
}
|
||||||
++(*ppOutPos);
|
++(*ppOutPos);
|
||||||
}
|
}
|
||||||
/* Output c1, c2 in Set C
|
/* Output c1, c2 in Set C
|
||||||
*/
|
*/
|
||||||
void A2C128_C(uchar **ppOutPos,uchar c1,uchar c2)
|
void A2C128_C(uchar **ppOutPos,uchar c1,uchar c2)
|
||||||
{
|
{
|
||||||
uchar * pOutPos = *ppOutPos;
|
uchar * pOutPos = *ppOutPos;
|
||||||
switch(c1){
|
switch(c1){
|
||||||
case aFNC1: *pOutPos=102; break;
|
case aFNC1: *pOutPos=102; break;
|
||||||
case aCodeB: *pOutPos=100; break;
|
case aCodeB: *pOutPos=100; break;
|
||||||
case aCodeA: *pOutPos=101; break;
|
case aCodeA: *pOutPos=101; break;
|
||||||
default: *pOutPos=(char)(10 * (c1- '0') + (c2 - '0'));break;
|
default: *pOutPos=(char)(10 * (c1- '0') + (c2 - '0'));break;
|
||||||
}
|
}
|
||||||
(*ppOutPos)++;
|
(*ppOutPos)++;
|
||||||
}
|
}
|
||||||
/* Output a character in Characterset
|
/* Output a character in Characterset
|
||||||
*/
|
*/
|
||||||
void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
|
void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
|
||||||
{
|
{
|
||||||
if (CharacterSet==CodeA)
|
if (CharacterSet==CodeA)
|
||||||
A2C128_A(ppOutPos,c1);
|
A2C128_A(ppOutPos,c1);
|
||||||
else if(CharacterSet==CodeB)
|
else if(CharacterSet==CodeB)
|
||||||
A2C128_B(ppOutPos,c1);
|
A2C128_B(ppOutPos,c1);
|
||||||
else
|
else
|
||||||
A2C128_C(ppOutPos,c1,c2);
|
A2C128_C(ppOutPos,c1,c2);
|
||||||
}
|
}
|
||||||
/* XLate Table A of Codablock-F Specification and call output
|
/* XLate Table A of Codablock-F Specification and call output
|
||||||
*/
|
*/
|
||||||
void SummeASCII(uchar **ppOutPos, int Sum, int CharacterSet)
|
void SummeASCII(uchar **ppOutPos, int Sum, int CharacterSet)
|
||||||
{
|
{
|
||||||
switch (CharacterSet){
|
switch (CharacterSet){
|
||||||
case CodeA:
|
case CodeA:
|
||||||
A2C128_A(ppOutPos, (uchar)Sum);
|
A2C128_A(ppOutPos, (uchar)Sum);
|
||||||
break;
|
break;
|
||||||
case CodeB:
|
case CodeB:
|
||||||
if (Sum<=31)
|
if (Sum<=31)
|
||||||
A2C128_B(ppOutPos, (uchar)(Sum+96));
|
A2C128_B(ppOutPos, (uchar)(Sum+96));
|
||||||
else if(Sum<=47)
|
else if(Sum<=47)
|
||||||
A2C128_B(ppOutPos, (uchar)Sum);
|
A2C128_B(ppOutPos, (uchar)Sum);
|
||||||
else
|
else
|
||||||
A2C128_B(ppOutPos, (uchar)(Sum+10));
|
A2C128_B(ppOutPos, (uchar)(Sum+10));
|
||||||
break;
|
break;
|
||||||
case CodeC:
|
case CodeC:
|
||||||
A2C128_C(ppOutPos
|
A2C128_C(ppOutPos
|
||||||
,(char)(Sum/10+'0') ,(uchar)(Sum%10+'0'));
|
,(char)(Sum/10+'0') ,(uchar)(Sum%10+'0'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||||
int charCur;
|
int charCur;
|
||||||
int dataLength;
|
int dataLength;
|
||||||
int Error;
|
int Error;
|
||||||
int rows, columns, useColumns;
|
int rows, columns, useColumns;
|
||||||
int fillings;
|
int fillings;
|
||||||
int Sum1,Sum2;
|
int Sum1,Sum2;
|
||||||
uchar * pOutPos;
|
uchar * pOutPos;
|
||||||
int rowCur;
|
int rowCur;
|
||||||
int characterSetCur;
|
int characterSetCur;
|
||||||
int emptyColumns;
|
int emptyColumns;
|
||||||
#ifdef _MSC_VER
|
char dest[1000];
|
||||||
CharacterSetTable *T;
|
int r, c;
|
||||||
unsigned char *data;
|
#ifdef _MSC_VER
|
||||||
int *pSet;
|
CharacterSetTable *T;
|
||||||
uchar * pOutput;
|
unsigned char *data;
|
||||||
#endif
|
int *pSet;
|
||||||
|
uchar * pOutput;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Parameter check */
|
/* Parameter check */
|
||||||
/* option1: rows 0: automatic, 1..44 */
|
/* option1: rows 0: automatic, 1..44 */
|
||||||
rows = symbol->option_1;
|
rows = symbol->option_1;
|
||||||
if (rows > 44) {
|
if (rows > 44) {
|
||||||
strcpy(symbol->errtxt, "Row parameter not in 0..44");
|
strcpy(symbol->errtxt, "Row parameter not in 0..44");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
@ -635,25 +654,25 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
if ( ! (columns <= 0 || (columns >= 6 && columns <=66)) ) {
|
if ( ! (columns <= 0 || (columns >= 6 && columns <=66)) ) {
|
||||||
strcpy(symbol->errtxt, "Columns parameter not in 0,6..66");
|
strcpy(symbol->errtxt, "Columns parameter not in 0,6..66");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
/* There are 5 Codewords for Organisation Start(2),row(1),CheckSum,Stop */
|
/* There are 5 Codewords for Organisation Start(2),row(1),CheckSum,Stop */
|
||||||
useColumns = columns - 5;
|
useColumns = columns - 5;
|
||||||
/* GS1 not implemented */
|
/* GS1 not implemented */
|
||||||
if (symbol->input_mode == GS1_MODE) {
|
if (symbol->input_mode == GS1_MODE) {
|
||||||
strcpy(symbol->errtxt, "GS1 mode not supported");
|
strcpy(symbol->errtxt, "GS1 mode not supported");
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
return ZINT_ERROR_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
unsigned char data[length*2+1];
|
unsigned char data[length*2+1];
|
||||||
#else
|
#else
|
||||||
data = (unsigned char *) _alloca(length * 2+1);
|
data = (unsigned char *) _alloca(length * 2+1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dataLength = 0;
|
dataLength = 0;
|
||||||
if (symbol->output_options & READER_INIT) {
|
if (symbol->output_options & READER_INIT) {
|
||||||
data[dataLength] = aFNC3;
|
data[dataLength] = aFNC3;
|
||||||
dataLength++;
|
dataLength++;
|
||||||
}
|
}
|
||||||
/* Replace all Codes>127 with <fnc4>Code-128 */
|
/* Replace all Codes>127 with <fnc4>Code-128 */
|
||||||
for (charCur=0;charCur<length;charCur++) {
|
for (charCur=0;charCur<length;charCur++) {
|
||||||
if (source[charCur]>127)
|
if (source[charCur]>127)
|
||||||
@ -667,13 +686,13 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Build character set table */
|
/* Build character set table */
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
CharacterSetTable T[dataLength];
|
CharacterSetTable T[dataLength];
|
||||||
int pSet[dataLength];
|
int pSet[dataLength];
|
||||||
#else
|
#else
|
||||||
T=(CharacterSetTable *)_alloca(dataLength*sizeof(CharacterSetTable));
|
T=(CharacterSetTable *)_alloca(dataLength*sizeof(CharacterSetTable));
|
||||||
pSet = (int *)_alloca(dataLength*sizeof(int));
|
pSet = (int *)_alloca(dataLength*sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
CreateCharacterSetTable(T,data,dataLength);
|
CreateCharacterSetTable(T,data,dataLength);
|
||||||
|
|
||||||
/* Find final row and column count */
|
/* Find final row and column count */
|
||||||
@ -705,7 +724,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
/* Checksum */
|
/* Checksum */
|
||||||
Sum1=Sum2=0;
|
Sum1=Sum2=0;
|
||||||
if (rows>1)
|
if (rows>1)
|
||||||
{
|
{
|
||||||
int charCur;
|
int charCur;
|
||||||
for (charCur=0 ; charCur<dataLength ; charCur++) {
|
for (charCur=0 ; charCur<dataLength ; charCur++) {
|
||||||
Sum1=(Sum1 + (charCur%86+1)*data[charCur])%86;
|
Sum1=(Sum1 + (charCur%86+1)*data[charCur])%86;
|
||||||
@ -743,206 +762,219 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
|||||||
fputc((pSet[DPos]&CFill)==0?'.':'X',stdout);
|
fputc((pSet[DPos]&CFill)==0?'.':'X',stdout);
|
||||||
fputc('\n',stdout);
|
fputc('\n',stdout);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
columns = useColumns + 5;
|
columns = useColumns + 5;
|
||||||
|
|
||||||
/* >>> Build C128 code numbers */
|
/* >>> Build C128 code numbers */
|
||||||
/* The C128 column count contains Start (2CW), Row ID, Checksum, Stop */
|
/* The C128 column count contains Start (2CW), Row ID, Checksum, Stop */
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
uchar pOutput[columns * rows];
|
uchar pOutput[columns * rows];
|
||||||
#else
|
#else
|
||||||
pOutput = (char *)_alloca(columns * rows * sizeof(char));
|
pOutput = (char *)_alloca(columns * rows * sizeof(char));
|
||||||
#endif
|
#endif
|
||||||
pOutPos = pOutput;
|
pOutPos = pOutput;
|
||||||
charCur=0;
|
charCur=0;
|
||||||
/* >> Loop over Lines */
|
/* >> Loop over Lines */
|
||||||
for (rowCur=0 ; rowCur<rows ; rowCur++) {
|
for (rowCur=0 ; rowCur<rows ; rowCur++) {
|
||||||
if (charCur>=dataLength)
|
if (charCur>=dataLength)
|
||||||
{
|
{
|
||||||
/* >> Empty line with StartCCodeBCodeC */
|
/* >> Empty line with StartCCodeBCodeC */
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
/* CDB Start C*/
|
/* CDB Start C*/
|
||||||
pOutPos+=sprintf(pOutPos,"\x67\x63");
|
pOutPos+=sprintf(pOutPos,"\x67\x63");
|
||||||
SummeASCII(&pOutPos,rowCur+42,CodeC);
|
SummeASCII(&pOutPos,rowCur+42,CodeC);
|
||||||
emptyColumns=useColumns-2;
|
emptyColumns=useColumns-2;
|
||||||
while (emptyColumns>0)
|
while (emptyColumns>0)
|
||||||
{
|
{
|
||||||
if(characterSetCur==CodeC)
|
if(characterSetCur==CodeC)
|
||||||
{
|
{
|
||||||
A2C128_C(&pOutPos,aCodeB,'\0');
|
A2C128_C(&pOutPos,aCodeB,'\0');
|
||||||
characterSetCur=CodeB;
|
characterSetCur=CodeB;
|
||||||
}else{
|
}else{
|
||||||
A2C128_B(&pOutPos,aCodeC);
|
A2C128_B(&pOutPos,aCodeC);
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
}
|
}
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
/* >> Normal Line */
|
/* >> Normal Line */
|
||||||
/* > Startcode */
|
/* > Startcode */
|
||||||
switch (pSet[charCur] & (CodeA+CodeB+CodeC)){
|
switch (pSet[charCur] & (CodeA+CodeB+CodeC)){
|
||||||
case CodeA:
|
case CodeA:
|
||||||
if (rows==1)
|
if (rows==1)
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x67");
|
pOutPos+=sprintf((char *)pOutPos,"\x67");
|
||||||
else
|
else
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x62");
|
pOutPos+=sprintf((char *)pOutPos,"\x67\x62");
|
||||||
characterSetCur=CodeA;
|
characterSetCur=CodeA;
|
||||||
break;
|
break;
|
||||||
case CodeB:
|
case CodeB:
|
||||||
if (rows==1)
|
if (rows==1)
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x68");
|
pOutPos+=sprintf((char *)pOutPos,"\x68");
|
||||||
else
|
else
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x64");
|
pOutPos+=sprintf((char *)pOutPos,"\x67\x64");
|
||||||
characterSetCur=CodeB;
|
characterSetCur=CodeB;
|
||||||
break;
|
break;
|
||||||
case CodeC:
|
case CodeC:
|
||||||
if (rows==1)
|
if (rows==1)
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x69");
|
pOutPos+=sprintf((char *)pOutPos,"\x69");
|
||||||
else
|
else
|
||||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x63");
|
pOutPos+=sprintf((char *)pOutPos,"\x67\x63");
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (rows>1)
|
if (rows>1)
|
||||||
{
|
{
|
||||||
/* > Set F1 */
|
/* > Set F1 */
|
||||||
/* In first line : # of Lines */
|
/* In first line : # of Lines */
|
||||||
/* In Case of CodeA we shifted to CodeB */
|
/* In Case of CodeA we shifted to CodeB */
|
||||||
SummeASCII(&pOutPos
|
SummeASCII(&pOutPos
|
||||||
,(rowCur==0)?rows-2:rowCur+42
|
,(rowCur==0)?rows-2:rowCur+42
|
||||||
,(characterSetCur==CodeA)?CodeB:characterSetCur
|
,(characterSetCur==CodeA)?CodeB:characterSetCur
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/* >>> Data */
|
/* >>> Data */
|
||||||
emptyColumns=useColumns;
|
emptyColumns=useColumns;
|
||||||
/* +++ One liner don't have start/stop code */
|
/* +++ One liner don't have start/stop code */
|
||||||
if (rows == 1)
|
if (rows == 1)
|
||||||
emptyColumns +=2;
|
emptyColumns +=2;
|
||||||
/* >> Character loop */
|
/* >> Character loop */
|
||||||
while (emptyColumns>0)
|
while (emptyColumns>0)
|
||||||
{
|
{
|
||||||
/* ? Change character set */
|
/* ? Change character set */
|
||||||
/* not at first possition (It was then the start set) */
|
/* not at first possition (It was then the start set) */
|
||||||
/* +++ special case for one-ligner */
|
/* +++ special case for one-ligner */
|
||||||
if (emptyColumns<useColumns && !(rows == 1 && charCur==0) )
|
if (emptyColumns<useColumns && !(rows == 1 && charCur==0) )
|
||||||
{
|
{
|
||||||
if ((pSet[charCur]&CodeA)!=0)
|
if ((pSet[charCur]&CodeA)!=0)
|
||||||
{
|
{
|
||||||
/* Change to A */
|
/* Change to A */
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,aCodeA,'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,aCodeA,'\0');
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
characterSetCur=CodeA;
|
characterSetCur=CodeA;
|
||||||
} else if ((pSet[charCur]&CodeB)!=0)
|
} else if ((pSet[charCur]&CodeB)!=0)
|
||||||
{
|
{
|
||||||
/* Change to B */
|
/* Change to B */
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,aCodeB,'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,aCodeB,'\0');
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
characterSetCur=CodeB;
|
characterSetCur=CodeB;
|
||||||
} else if ((pSet[charCur]&CodeC)!=0)
|
} else if ((pSet[charCur]&CodeC)!=0)
|
||||||
{
|
{
|
||||||
/* Change to C */
|
/* Change to C */
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,aCodeC,'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,aCodeC,'\0');
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((pSet[charCur]&CodeA)!=0)
|
if ((pSet[charCur]&CodeA)!=0)
|
||||||
{
|
{
|
||||||
/* >> Shift it and put out the shiftet character */
|
/* >> Shift it and put out the shiftet character */
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,aShift,'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,aShift,'\0');
|
||||||
emptyColumns-=2;
|
emptyColumns-=2;
|
||||||
characterSetCur=(characterSetCur==CodeB)?CodeA:CodeB;
|
characterSetCur=(characterSetCur==CodeB)?CodeA:CodeB;
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,data[charCur],'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,data[charCur],'\0');
|
||||||
characterSetCur=(characterSetCur==CodeB)?CodeA:CodeB;
|
characterSetCur=(characterSetCur==CodeB)?CodeA:CodeB;
|
||||||
}else{
|
}else{
|
||||||
/* Normal Character */
|
/* Normal Character */
|
||||||
if (characterSetCur==CodeC)
|
if (characterSetCur==CodeC)
|
||||||
{
|
{
|
||||||
if (data[charCur]==aFNC1)
|
if (data[charCur]==aFNC1)
|
||||||
A2C128_C(&pOutPos,aFNC1,'\0');
|
A2C128_C(&pOutPos,aFNC1,'\0');
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
A2C128_C(&pOutPos,data[charCur],data[charCur+1]);
|
A2C128_C(&pOutPos,data[charCur],data[charCur+1]);
|
||||||
++charCur;
|
++charCur;
|
||||||
/* We need this here to get the good index */
|
/* We need this here to get the good index */
|
||||||
/* for the termination flags in Set. */
|
/* for the termination flags in Set. */
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
ASCIIZ128(&pOutPos,characterSetCur,data[charCur],'\0');
|
ASCIIZ128(&pOutPos,characterSetCur,data[charCur],'\0');
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
}
|
}
|
||||||
/* >> End Criteria */
|
/* >> End Criteria */
|
||||||
if ((pSet[charCur] & CFill)!=0)
|
if ((pSet[charCur] & CFill)!=0)
|
||||||
{
|
{
|
||||||
/* Fill Line but leave space for checks in last line */
|
/* Fill Line but leave space for checks in last line */
|
||||||
if(rowCur==rows-1 && emptyColumns>=2)
|
if(rowCur==rows-1 && emptyColumns>=2)
|
||||||
emptyColumns-=2;
|
emptyColumns-=2;
|
||||||
while(emptyColumns>0)
|
while(emptyColumns>0)
|
||||||
{
|
{
|
||||||
switch(characterSetCur){
|
switch(characterSetCur){
|
||||||
case CodeC:
|
case CodeC:
|
||||||
A2C128_C(&pOutPos,aCodeB,'\0');
|
A2C128_C(&pOutPos,aCodeB,'\0');
|
||||||
characterSetCur=CodeB;
|
characterSetCur=CodeB;
|
||||||
break;
|
break;
|
||||||
case CodeB:
|
case CodeB:
|
||||||
A2C128_B(&pOutPos,aCodeC);
|
A2C128_B(&pOutPos,aCodeC);
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
break;
|
break;
|
||||||
case CodeA:
|
case CodeA:
|
||||||
A2C128_A(&pOutPos,aCodeC);
|
A2C128_A(&pOutPos,aCodeC);
|
||||||
characterSetCur=CodeC;
|
characterSetCur=CodeC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
--emptyColumns;
|
--emptyColumns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((pSet[charCur] & CEnd)!=0)
|
if ((pSet[charCur] & CEnd)!=0)
|
||||||
emptyColumns=0;
|
emptyColumns=0;
|
||||||
++charCur;
|
++charCur;
|
||||||
} /* Loop over characters */
|
} /* Loop over characters */
|
||||||
} /* if filling-Line / normal */
|
} /* if filling-Line / normal */
|
||||||
|
|
||||||
/* Add checksum in last line */
|
/* Add checksum in last line */
|
||||||
if(rows>1 && rowCur==rows-1)
|
if(rows>1 && rowCur==rows-1)
|
||||||
{
|
{
|
||||||
SummeASCII(&pOutPos,Sum1,characterSetCur);
|
SummeASCII(&pOutPos,Sum1,characterSetCur);
|
||||||
SummeASCII(&pOutPos,Sum2,characterSetCur);
|
SummeASCII(&pOutPos,Sum2,characterSetCur);
|
||||||
}
|
}
|
||||||
/* Add Code 128 checksum */
|
/* Add Code 128 checksum */
|
||||||
{
|
{
|
||||||
int Sum=0;
|
int Sum=0;
|
||||||
int Pos=0;
|
int Pos=0;
|
||||||
for ( ; Pos < useColumns+2 ; Pos++)
|
for ( ; Pos < useColumns+2 ; Pos++)
|
||||||
{
|
{
|
||||||
Sum = (Sum +
|
Sum = (Sum +
|
||||||
((Pos==0?1:Pos) * pOutput[columns*rowCur+Pos]) % 103
|
((Pos==0?1:Pos) * pOutput[columns*rowCur+Pos]) % 103
|
||||||
) % 103;
|
) % 103;
|
||||||
}
|
}
|
||||||
*pOutPos=(uchar)Sum;
|
*pOutPos=(uchar)Sum;
|
||||||
pOutPos++;
|
pOutPos++;
|
||||||
}
|
}
|
||||||
/* Add end character */
|
/* Add end character */
|
||||||
*pOutPos=106;
|
*pOutPos=106;
|
||||||
pOutPos++;
|
pOutPos++;
|
||||||
} /* End Lineloop */
|
} /* End Lineloop */
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
/* Dump the output to the screen
|
/* Dump the output to the screen
|
||||||
*/
|
*/
|
||||||
printf("\nCode 128 Code Numbers:\n");
|
printf("\nCode 128 Code Numbers:\n");
|
||||||
{ /* start a new level of local variables */
|
{ /* start a new level of local variables */
|
||||||
int DPos, DPos2;
|
int DPos, DPos2;
|
||||||
for (DPos=0 ; DPos< rows ; DPos++)
|
for (DPos=0 ; DPos< rows ; DPos++)
|
||||||
{
|
{
|
||||||
for (DPos2=0 ; DPos2 < columns ; DPos2++)
|
for (DPos2=0 ; DPos2 < columns ; DPos2++)
|
||||||
{
|
{
|
||||||
printf("% 3i ",(int)(pOutput[DPos*columns+DPos2]));
|
printf("% 3i ",(int)(pOutput[DPos*columns+DPos2]));
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("rows=%i columns=%i fillings=%i\n", rows, columns, fillings);
|
printf("rows=%i columns=%i fillings=%i\n", rows, columns, fillings);
|
||||||
#endif
|
#endif
|
||||||
return ZINT_ERROR_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
for (r = 0; r < rows; r++) {
|
||||||
|
strcpy(dest, "");
|
||||||
|
for(c = 0; c < columns; c++) {
|
||||||
|
strcat(dest, C128Table[pOutput[r * columns + c]]);
|
||||||
|
}
|
||||||
|
expand(symbol, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(symbol->output_options & BARCODE_BIND)) {
|
||||||
|
symbol->output_options += BARCODE_BIND;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -167,38 +167,27 @@ void expand(struct zint_symbol *symbol, const char data[]) {
|
|||||||
|
|
||||||
/* Indicates which symbologies can have row binding */
|
/* Indicates which symbologies can have row binding */
|
||||||
int is_stackable(const int symbology) {
|
int is_stackable(const int symbology) {
|
||||||
|
int retval = 0;
|
||||||
|
|
||||||
if (symbology < BARCODE_PDF417) {
|
if (symbology < BARCODE_PDF417) {
|
||||||
return 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
if (symbology == BARCODE_CODE128B) {
|
|
||||||
return 1;
|
switch (symbology) {
|
||||||
}
|
case BARCODE_CODE128B:
|
||||||
if (symbology == BARCODE_ISBNX) {
|
case BARCODE_ISBNX:
|
||||||
return 1;
|
case BARCODE_EAN14:
|
||||||
}
|
case BARCODE_NVE18:
|
||||||
if (symbology == BARCODE_EAN14) {
|
case BARCODE_KOREAPOST:
|
||||||
return 1;
|
case BARCODE_PLESSEY:
|
||||||
}
|
case BARCODE_TELEPEN_NUM:
|
||||||
if (symbology == BARCODE_NVE18) {
|
case BARCODE_ITF14:
|
||||||
return 1;
|
case BARCODE_CODE32:
|
||||||
}
|
case BARCODE_CODABLOCK:
|
||||||
if (symbology == BARCODE_KOREAPOST) {
|
retval = 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (symbology == BARCODE_PLESSEY) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (symbology == BARCODE_TELEPEN_NUM) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (symbology == BARCODE_ITF14) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (symbology == BARCODE_CODE32) {
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
|
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
|
||||||
|
@ -515,7 +515,9 @@ namespace Zint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Add row binding */
|
/* Add row binding */
|
||||||
if (((m_zintSymbol->symbology == BARCODE_CODE16K) || (m_zintSymbol->symbology == BARCODE_CODE49)) && (row != 0)) {
|
if (((m_zintSymbol->symbology == BARCODE_CODE16K)
|
||||||
|
|| (m_zintSymbol->symbology == BARCODE_CODE49)
|
||||||
|
|| (m_zintSymbol->symbology == BARCODE_CODABLOCK)) && (row != 0)) {
|
||||||
painter.fillRect(0, y - 1, m_zintSymbol->width, 2, QBrush(m_fgColor));
|
painter.fillRect(0, y - 1, m_zintSymbol->width, 2, QBrush(m_fgColor));
|
||||||
}
|
}
|
||||||
y += m_zintSymbol->row_height[row];
|
y += m_zintSymbol->row_height[row];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user