mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Fixed bugs: C128 arbitrary data, C128 wrong checksum
This commit is contained in:
parent
2cf489eac2
commit
7b4009d19f
@ -42,7 +42,7 @@
|
||||
|
||||
#define uchar unsigned char
|
||||
|
||||
/* FTab Flagzeichen - Addierbar */
|
||||
/* FTab C128 flags - may be added */
|
||||
#define CodeA 1
|
||||
#define CodeB 2
|
||||
#define CodeC 4
|
||||
@ -168,7 +168,7 @@ void CreateCharacterSetTable(CharacterSetTable T[], unsigned char *data, int dat
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate the amount of numerical characters in pairs which will fit in
|
||||
/* Find the amount of numerical characters in pairs which will fit in
|
||||
* one bundle into the line (up to here). This is calculated online because
|
||||
* it depends on the space in the line.
|
||||
*/
|
||||
@ -192,17 +192,17 @@ int RemainingDigits(CharacterSetTable *T, int charCur,int emptyColumns)
|
||||
return digitCount;
|
||||
}
|
||||
|
||||
/* Calculates the used Characterset (Set) from columns.
|
||||
/* Find the Character distribution at a given column count.
|
||||
* If to many rows (>44) are requested the columns is extended.
|
||||
* A oneLigner may be shorter. Error is set to eCorrectWidthInOneLigner.
|
||||
* A oneLigner may be choosen if shorter.
|
||||
* Parameters :
|
||||
* Pcolumns Pointer on the Characters who fits in the Line
|
||||
* T Pointer on the Characters which fit in the row
|
||||
* If a different count is calculated it is corrected
|
||||
* in the callers workspace.
|
||||
* pFillings Output of filling characters
|
||||
* pSet Output of the character sets used, allocated by me.
|
||||
* Data The Data string to encode, exceptionnally not an out
|
||||
* Return value The lines requested.
|
||||
* Return value Resulting row count
|
||||
*/
|
||||
|
||||
int Columns2Rows(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
@ -416,26 +416,19 @@ int Columns2Rows(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
*pFillings=fillings;
|
||||
return 0;
|
||||
}
|
||||
/* Find columns if rows are given.
|
||||
* Error may be :
|
||||
* eLessLines : The exakt number of lines may only be constructed
|
||||
* with a filing line.
|
||||
* eMoreLines : Only Maddin knows why...
|
||||
* eCorrectWidthInOneLigner : A one-Ligner is shorter than demanded.
|
||||
* eExtendWidth : The Code is wider because otherwise the data amount.
|
||||
* would not fit in 50 lines.
|
||||
/* Find columns if row count is given.
|
||||
*/
|
||||
int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
int * pRows, int * pUseColumns, int * pSet, int * pFillings)
|
||||
{
|
||||
int errorCur;
|
||||
int rowsCur;
|
||||
int rowsRequested; /* Number of Lines Requested */
|
||||
int rowsRequested; /* Number of requested rows */
|
||||
int backupRows;
|
||||
int fillings;
|
||||
int backupFillings;
|
||||
int useColumns;
|
||||
int testColumns; /* To enter into Width2Lines */
|
||||
int testColumns; /* To enter into Width2Rows */
|
||||
int backupColumns;
|
||||
int fBackupOk; /* The memorysed set is o.k. */
|
||||
int testListSize = 0;
|
||||
@ -449,7 +442,7 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
rowsRequested=*pRows;
|
||||
|
||||
#ifdef _DEBUG
|
||||
fprintf(stderr,"Optimizer : Searching Lines <%i>\n",rowsRequested);
|
||||
fprintf(stderr,"Optimizer : Searching <%i> rows\n",rowsRequested);
|
||||
#endif
|
||||
|
||||
fBackupOk=0;
|
||||
@ -499,7 +492,7 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
pTestList[0] = testColumns;
|
||||
testListSize = 1;
|
||||
}
|
||||
/* > Test more Lines (shorter CDB) */
|
||||
/* > Test more rows (shorter CDB) */
|
||||
fBackupOk=(rowsCur==rowsRequested);
|
||||
memcpy(pBackupSet,pSet,dataLength*sizeof(int));
|
||||
backupFillings=fillings;
|
||||
@ -507,7 +500,7 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
backupRows=rowsCur;
|
||||
--testColumns;
|
||||
} else {
|
||||
/* > To many lines */
|
||||
/* > To many rows */
|
||||
int fInTestList = fBackupOk;
|
||||
int posCur;
|
||||
for (posCur = 0; posCur < testListSize && ! fInTestList; posCur++) {
|
||||
@ -515,16 +508,17 @@ int Rows2Columns(CharacterSetTable *T, unsigned char *data, int dataLength,
|
||||
fInTestList = 1;
|
||||
}
|
||||
if (fInTestList) {
|
||||
/* The next less-lines (larger) code was
|
||||
/* The next less-rows (larger) code was
|
||||
* already tested. So give the larger
|
||||
* back.
|
||||
*/
|
||||
memcpy(pSet,pBackupSet,dataLength*sizeof(int));
|
||||
*pFillings=backupFillings;
|
||||
*pRows=backupRows;
|
||||
*pUseColumns=backupColumns;
|
||||
return 0;
|
||||
}
|
||||
/* > Test less lines (longer code) */
|
||||
/* > Test less rows (longer code) */
|
||||
backupRows=rowsCur;
|
||||
memcpy(pBackupSet,pSet,dataLength*sizeof(int));
|
||||
backupFillings=fillings;
|
||||
@ -601,7 +595,7 @@ void ASCIIZ128(uchar **ppOutPos, int CharacterSet,uchar c1, uchar c2)
|
||||
}
|
||||
/* XLate Table A of Codablock-F Specification and call output
|
||||
*/
|
||||
void SummeASCII(uchar **ppOutPos, int Sum, int CharacterSet)
|
||||
void SumASCII(uchar **ppOutPos, int Sum, int CharacterSet)
|
||||
{
|
||||
switch (CharacterSet){
|
||||
case CodeA:
|
||||
@ -622,6 +616,8 @@ void SummeASCII(uchar **ppOutPos, int Sum, int CharacterSet)
|
||||
}
|
||||
}
|
||||
|
||||
/* Main function called by zint framework
|
||||
*/
|
||||
int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int charCur;
|
||||
int dataLength;
|
||||
@ -775,15 +771,18 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
#endif
|
||||
pOutPos = pOutput;
|
||||
charCur=0;
|
||||
/* >> Loop over Lines */
|
||||
/* >> Loop over rows */
|
||||
for (rowCur=0 ; rowCur<rows ; rowCur++) {
|
||||
if (charCur>=dataLength)
|
||||
{
|
||||
/* >> Empty line with StartCCodeBCodeC */
|
||||
characterSetCur=CodeC;
|
||||
/* CDB Start C*/
|
||||
pOutPos+=sprintf((char*)pOutPos,"\x67\x63");
|
||||
SummeASCII(&pOutPos,rowCur+42,CodeC);
|
||||
*pOutPos='\x67';
|
||||
pOutPos++;
|
||||
*pOutPos='\x63';
|
||||
pOutPos++;
|
||||
SumASCII(&pOutPos,rowCur+42,CodeC);
|
||||
emptyColumns=useColumns-2;
|
||||
while (emptyColumns>0)
|
||||
{
|
||||
@ -802,33 +801,45 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
/* > Startcode */
|
||||
switch (pSet[charCur] & (CodeA+CodeB+CodeC)){
|
||||
case CodeA:
|
||||
if (rows==1)
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x67");
|
||||
else
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x62");
|
||||
*pOutPos = '\x67';
|
||||
pOutPos++;
|
||||
if (rows>1) {
|
||||
*pOutPos = '\x62';
|
||||
pOutPos++;
|
||||
}
|
||||
characterSetCur=CodeA;
|
||||
break;
|
||||
case CodeB:
|
||||
if (rows==1)
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x68");
|
||||
else
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x64");
|
||||
if (rows==1) {
|
||||
*pOutPos = '\x68';
|
||||
pOutPos++;
|
||||
} else {
|
||||
*pOutPos = '\x67';
|
||||
pOutPos++;
|
||||
*pOutPos = '\x64';
|
||||
pOutPos++;
|
||||
}
|
||||
characterSetCur=CodeB;
|
||||
break;
|
||||
case CodeC:
|
||||
if (rows==1)
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x69");
|
||||
else
|
||||
pOutPos+=sprintf((char *)pOutPos,"\x67\x63");
|
||||
if (rows==1) {
|
||||
*pOutPos = '\x69';
|
||||
pOutPos++;
|
||||
} else {
|
||||
*pOutPos = '\x67';
|
||||
pOutPos++;
|
||||
*pOutPos = '\x63';
|
||||
pOutPos++;
|
||||
}
|
||||
characterSetCur=CodeC;
|
||||
break;
|
||||
}
|
||||
if (rows>1)
|
||||
{
|
||||
/* > Set F1 */
|
||||
/* In first line : # of Lines */
|
||||
/* In first line : # of rows */
|
||||
/* In Case of CodeA we shifted to CodeB */
|
||||
SummeASCII(&pOutPos
|
||||
SumASCII(&pOutPos
|
||||
,(rowCur==0)?rows-2:rowCur+42
|
||||
,(characterSetCur==CodeA)?CodeB:characterSetCur
|
||||
);
|
||||
@ -844,7 +855,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
/* ? Change character set */
|
||||
/* not at first possition (It was then the start set) */
|
||||
/* +++ special case for one-ligner */
|
||||
if (emptyColumns<useColumns && !(rows == 1 && charCur==0) )
|
||||
if (emptyColumns<useColumns || (rows == 1 && charCur!=0) )
|
||||
{
|
||||
if ((pSet[charCur]&CodeA)!=0)
|
||||
{
|
||||
@ -925,14 +936,14 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
/* Add checksum in last line */
|
||||
if(rows>1 && rowCur==rows-1)
|
||||
{
|
||||
SummeASCII(&pOutPos,Sum1,characterSetCur);
|
||||
SummeASCII(&pOutPos,Sum2,characterSetCur);
|
||||
SumASCII(&pOutPos,Sum1,characterSetCur);
|
||||
SumASCII(&pOutPos,Sum2,characterSetCur);
|
||||
}
|
||||
/* Add Code 128 checksum */
|
||||
{
|
||||
int Sum=0;
|
||||
int Pos=0;
|
||||
for ( ; Pos < useColumns+2 ; Pos++)
|
||||
for ( ; Pos < useColumns+3 ; Pos++)
|
||||
{
|
||||
Sum = (Sum +
|
||||
((Pos==0?1:Pos) * pOutput[columns*rowCur+Pos]) % 103
|
||||
@ -964,7 +975,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
printf("rows=%i columns=%i fillings=%i\n", rows, columns, fillings);
|
||||
#endif
|
||||
|
||||
|
||||
/* Paint the C128 patterns */
|
||||
for (r = 0; r < rows; r++) {
|
||||
strcpy(dest, "");
|
||||
for(c = 0; c < columns; c++) {
|
||||
|
Loading…
Reference in New Issue
Block a user