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,19 +990,28 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
}
}
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; }
if(input_latch == 1) {
auto_ecc_level = 3;
if(layers == 1) { auto_ecc_level = 5; }
if((layers == 2) || (layers == 3)) { auto_ecc_level = 4; }
ecc_level = auto_ecc_level;
if(data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) {
layers++;
}
}
ecc_level = auto_ecc_level;
if((symbol->option_1 >= 1) && (symbol->option_1 <= 5)) {
if(symbol->option_1 > min_ecc_level) {
ecc_level = symbol->option_1;
} else {
ecc_level = min_ecc_level;
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;
} else {
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));
}
}

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(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 + 1] == 'A') {
second = posn(RHODIUM, (char) jisdata[position + i + 1]);
count = 2;
prod = (first * 45) + second;
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,61 +1,62 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>grpDM</class>
<widget class="QWidget" name="grpDM" >
<property name="geometry" >
<widget class="QWidget" name="grpDM">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>410</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3" >
<item row="0" column="0" >
<layout class="QHBoxLayout" name="horizontalLayout" >
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<widget class="QLabel" name="label">
<property name="text">
<string>Encoding &amp;Mode:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>cmbDMMode</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbDMMode" >
<widget class="QComboBox" name="cmbDMMode">
<item>
<property name="text" >
<property name="text">
<string>ECC 200 (Recommended)</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>ECC 000</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>ECC 050</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>ECC 080</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>ECC 100</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>ECC 140</string>
</property>
</item>
@ -63,134 +64,134 @@
</item>
</layout>
</item>
<item row="1" column="0" >
<widget class="QGroupBox" name="grpDMNon200" >
<property name="title" >
<item row="1" column="0">
<widget class="QGroupBox" name="grpDMNon200">
<property name="title">
<string>Non ECC 200 Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" >
<item row="0" column="0" >
<widget class="QLabel" name="lblDMNon200Size" >
<property name="text" >
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="lblDMNon200Size">
<property name="text">
<string>Si&amp;ze:</string>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>cmbDMNon200Size</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="cmbDMNon200Size" >
<item row="0" column="1">
<widget class="QComboBox" name="cmbDMNon200Size">
<item>
<property name="text" >
<property name="text">
<string>Automatic</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>9 x 9</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>11 x 11</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>13 x 13</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>15 x 15</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>17 x 17</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>19 x 19</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>21 x 21</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>23 x 23</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>25 x 25</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>27 x 27</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>29 x 29</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>31 x 31</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>33 x 33</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>35 x 35</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>37 x 37</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>39 x 39</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>41 x 41</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>43 x 43</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>45 x 45</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>47 x 47</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>49 x 49</string>
</property>
</item>
@ -199,216 +200,226 @@
</layout>
</widget>
</item>
<item row="2" column="0" >
<widget class="QGroupBox" name="grpDM200" >
<property name="title" >
<item row="2" column="0">
<widget class="QGroupBox" name="grpDM200">
<property name="title">
<string>ECC 200 Options</string>
</property>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QRadioButton" name="radDM200Stand" >
<property name="text" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QRadioButton" name="radDM200Stand">
<property name="text">
<string>S&amp;tandard</string>
</property>
<property name="checked" >
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QRadioButton" name="radDM200HIBC" >
<property name="text" >
<item row="0" column="2">
<widget class="QRadioButton" name="radDM200HIBC">
<property name="text">
<string>&amp;HIBC Data Matrix</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QRadioButton" name="radDM200GS1" >
<property name="text" >
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="radDM200GS1">
<property name="text">
<string>&amp;GS-1 Data Mode</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="lblDM200Size" >
<property name="text" >
<item row="2" column="0">
<widget class="QLabel" name="lblDM200Size">
<property name="text">
<string>Si&amp;ze:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>cmbDM200Size</cstring>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2" >
<widget class="QComboBox" name="cmbDM200Size" >
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="cmbDM200Size">
<item>
<property name="text" >
<property name="text">
<string>Automatic</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>10 x 10</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>12 x 12</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>14 x 14</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>16 x 16</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>18 x 18</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>20 x 20</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>22 x 22</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>24 x 24</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>26 x 26</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>32 x 32</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>36 x 36</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>40 x 40</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>44 x 44</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>48 x 48</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>52 x 52</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>64 x 64</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>72 x 72</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>80 x 80</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>88 x 88</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>96 x 96</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>104 x 104</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>120 x 120</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>132 x 132</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>144 x 144</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>8 x 18</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>8 x 32</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>12 x 26</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>12 x 36</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>16 x 36</string>
</property>
</item>
<item>
<property name="text" >
<property name="text">
<string>16 x 48</string>
</property>
</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>
</layout>
</item>
<item>
<spacer name="verticalSpacer" >
<property name="orientation" >
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>71</height>

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 */