Minor bugfixes

This commit is contained in:
hooper114 2009-11-02 15:47:08 +00:00
parent 054bd02dcc
commit 242e57f536
6 changed files with 259 additions and 165 deletions

View File

@ -171,12 +171,15 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
int i, j, k, error_number;
char bars[7], spaces[7], mixed[14], dest[1000];
unsigned char *temp = source;
unsigned int temp_len = length;
#ifndef _MSC_VER
unsigned char temp[length + 2];
#else
unsigned char* temp = (unsigned char *)_alloca((length + 2) * sizeof(unsigned char));
#endif
error_number = 0;
if(length > 90) {
if(length > 89) {
strcpy(symbol->errtxt, "Input too long");
return ERROR_TOO_LONG;
}
@ -186,24 +189,20 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
return error_number;
}
ustrcpy(temp, (unsigned char *) "");
/* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered then add a leading zero */
if ((length % 2) != 0)
{
/* there are an odd number of input characters */
if (NULL == (temp = (unsigned char*)malloc(++temp_len)))
{
strcpy(symbol->errtxt, "Memory allocation failed");
return ERROR_MEMORY;
}
temp[0] = '0';
ustrcpy(temp + 1, source);
ustrcpy(temp, (unsigned char *) "0");
length++;
}
uconcat(temp, source);
/* start character */
strcpy(dest, "1111");
for(i = 0; i < temp_len; i+=2 )
for(i = 0; i < length; i+=2 )
{
/* look up the bars and the spaces and put them in two strings */
strcpy(bars, "");
@ -227,8 +226,6 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
expand(symbol, dest);
ustrcpy(symbol->text, temp);
if (temp != source)
free(source);
return error_number;
}

View File

@ -786,35 +786,33 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
optionsize = -1;
}
calcsize = 0;
for(i = 0; i < 30; i++) {
if(matrixbytes[i] < binlen) {
calcsize = 29;
for(i = 29; i > -1; i--) {
if(matrixbytes[i] > binlen) {
calcsize = i;
}
}
calcsize++;
if(calcsize <= optionsize) {
symbolsize = optionsize;
} else {
symbolsize = calcsize;
if(optionsize != -1) {
/* flag an error */
error_number = WARN_INVALID_OPTION;
strcpy(symbol->errtxt, "Data does not fit in selected symbol size");
}
}
if(symbol->option_3 == DM_SQUARE) {
/* Force to use square symbol */
switch(symbolsize) {
switch(calcsize) {
case 2:
case 4:
case 6:
case 9:
case 11:
case 14:
symbolsize++;
calcsize++;
}
}
symbolsize = optionsize;
if(calcsize > optionsize) {
symbolsize = calcsize;
if(optionsize != -1) {
/* flag an error */
error_number = WARN_INVALID_OPTION;
strcpy(symbol->errtxt, "Data does not fit in selected symbol size");
}
}

View File

@ -907,7 +907,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level;
int x, y, i, j, glyph;
char binary[9300];
int data_cw;
int data_cw, input_latch = 0;
int word[1460], data_max;
#ifndef _MSC_VER
@ -972,9 +972,17 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
for(i = 12; i > 0; i--) {
if(gm_max_cw[(i - 1)] >= data_cw) { min_layers = i; }
}
layers = auto_layers;
auto_ecc_level = 3;
if(layers == 1) { auto_ecc_level = 5; }
if((layers == 2) || (layers == 3)) { auto_ecc_level = 4; }
min_ecc_level = 1;
if(layers == 1) { min_ecc_level = 4; }
if((layers == 2) || (layers == 3)) { min_ecc_level = 2; }
ecc_level = auto_ecc_level;
if((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) {
input_latch = 1;
if(symbol->option_2 > min_layers) {
layers = symbol->option_2;
} else {
@ -982,14 +990,17 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
}
}
if(input_latch == 1) {
auto_ecc_level = 3;
if(layers == 1) { auto_ecc_level = 5; }
if((layers == 2) || (layers == 3)) { auto_ecc_level = 4; }
min_ecc_level = 1;
if(layers == 1) { min_ecc_level = 4; }
if((layers == 2) || (layers == 3)) { min_ecc_level = 2; }
ecc_level = auto_ecc_level;
if(data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) {
layers++;
}
}
if(input_latch == 0) {
if((symbol->option_1 >= 1) && (symbol->option_1 <= 5)) {
if(symbol->option_1 > min_ecc_level) {
ecc_level = symbol->option_1;
@ -997,6 +1008,12 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
ecc_level = min_ecc_level;
}
}
if(data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) {
do {
layers++;
} while ((data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) && (layers <= 13));
}
}
data_max = 1313;
switch(ecc_level) {

View File

@ -57,7 +57,7 @@ int in_alpha(int glyph) {
return retval;
}
void define_mode(char mode[], int jisdata[], int length)
void define_mode(char mode[], int jisdata[], int length, int gs1)
{
/* Values placed into mode[] are: K = Kanji, B = Binary, A = Alphanumeric, N = Numeric */
int i, mlen, j;
@ -68,6 +68,7 @@ void define_mode(char mode[], int jisdata[], int length)
} else {
mode[i] = 'B';
if(in_alpha(jisdata[i])) { mode[i] = 'A'; }
if(gs1 && (jisdata[i] == '[')) { mode[i] = 'A'; }
if((jisdata[i] >= '0') && (jisdata[i] <= '9')) { mode[i] = 'N'; }
}
}
@ -348,14 +349,65 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in
int count;
int first = 0, second = 0, prod;
first = posn(RHODIUM, (char) jisdata[position + i]);
count = 1;
prod = first;
if(mode[position + i + 1] == 'A') {
second = posn(RHODIUM, (char) jisdata[position + i + 1]);
if(percent == 0) {
if(gs1 && (jisdata[position + i] == '%')) {
first = posn(RHODIUM, '%');
second = posn(RHODIUM, '%');
count = 2;
prod = (first * 45) + second;
i++;
} else {
if(gs1 && (jisdata[position + i] == '[')) {
first = posn(RHODIUM, '%'); /* FNC1 */
} else {
first = posn(RHODIUM, (char) jisdata[position + i]);
}
count = 1;
i++;
prod = first;
if(mode[position + i] == 'A') {
if(gs1 && (jisdata[position + i] == '%')) {
second = posn(RHODIUM, '%');
count = 2;
prod = (first * 45) + second;
percent = 1;
} else {
if(gs1 && (jisdata[position + i] == '[')) {
second = posn(RHODIUM, '%'); /* FNC1 */
} else {
second = posn(RHODIUM, (char) jisdata[position + i]);
}
count = 2;
i++;
prod = (first * 45) + second;
}
}
}
} else {
first = posn(RHODIUM, '%');
count = 1;
i++;
prod = first;
percent = 0;
if(mode[position + i] == 'A') {
if(gs1 && (jisdata[position + i] == '%')) {
second = posn(RHODIUM, '%');
count = 2;
prod = (first * 45) + second;
percent = 1;
} else {
if(gs1 && (jisdata[position + i] == '[')) {
second = posn(RHODIUM, '%'); /* FNC1 */
} else {
second = posn(RHODIUM, (char) jisdata[position + i]);
}
count = 2;
i++;
prod = (first * 45) + second;
}
}
}
switch(count) {
@ -376,8 +428,6 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in
}
if(debug) { printf("0x%4X ", prod); }
i += count;
};
if(debug) { printf("\n"); }
@ -1116,7 +1166,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length)
break;
}
define_mode(mode, jisdata, length);
define_mode(mode, jisdata, length, gs1);
est_binlen = estimate_binary_length(mode, length, gs1);
ecc_level = LEVEL_L;
@ -1300,6 +1350,10 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length,
if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
if(debug) { printf("0x%4X ", prod); }
if(strlen(binary) > 128) {
return ERROR_TOO_LONG;
}
}
if(debug) { printf("\n"); }
@ -1332,6 +1386,10 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length,
if(byte & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
if(debug) { printf("0x%4X ", byte); }
if(strlen(binary) > 128) {
return ERROR_TOO_LONG;
}
}
if(debug) { printf("\n"); }
@ -1385,6 +1443,10 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length,
if(debug) { printf("0x%4X ", prod); }
if(strlen(binary) > 128) {
return ERROR_TOO_LONG;
}
i += 2;
};
@ -1444,6 +1506,10 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length,
if(debug) { printf("0x%4X (%d)", prod, prod); }
if(strlen(binary) > 128) {
return ERROR_TOO_LONG;
}
i += 3;
};
@ -2150,7 +2216,7 @@ int micro_apply_bitmask(unsigned char *grid, int size)
int microqr(struct zint_symbol *symbol, unsigned char source[], int length)
{
int i, j, glyph, size;
char binary_stream[130];
char binary_stream[200];
char full_stream[200];
int utfdata[40];
int jisdata[40];
@ -2203,7 +2269,7 @@ int microqr(struct zint_symbol *symbol, unsigned char source[], int length)
break;
}
define_mode(mode, jisdata, length);
define_mode(mode, jisdata, length, 0);
n_count = 0;
a_count = 0;

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>grpDM</class>
<widget class="QWidget" name="grpDM">
@ -5,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>410</width>
<height>339</height>
</rect>
</property>
@ -398,6 +399,16 @@
</item>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="chkDMRectangle">
<property name="text">
<string>Suppress Rectangular Symbols in Automatic Mode</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -374,6 +374,7 @@ void MainWindow::change_options()
connect(m_optionWidget->findChild<QObject*>("radDM200HIBC"), SIGNAL(clicked( bool )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("cmbDM200Size"), SIGNAL(currentIndexChanged( int )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("cmbDMNon200Size"), SIGNAL(currentIndexChanged( int )), SLOT(update_preview()));
connect(m_optionWidget->findChild<QObject*>("chkDMRectangle"), SIGNAL(stateChanged( int )), SLOT(update_preview()));
datamatrix_options();
}
@ -738,6 +739,10 @@ void MainWindow::update_preview()
m_bc.bc.setInputMode(GS1_MODE);
m_bc.bc.setWidth(m_optionWidget->findChild<QComboBox*>("cmbDM200Size")->currentIndex());
if(m_optionWidget->findChild<QCheckBox*>("chkDMRectangle")->isChecked())
m_bc.bc.setOption3(DM_SQUARE);
else
m_bc.bc.setOption3(0);
}
else
{ /* Not ECC 200 */