Resolve Latin-1 in Code 128 bug

This commit is contained in:
hooper114 2009-11-09 09:18:08 +00:00
parent 35cacaef67
commit fdb6485ef1
6 changed files with 37 additions and 47 deletions

View File

@ -7,10 +7,6 @@ zint:
$(MAKE) -C backend/
$(MAKE) -C frontend/
zint_noqr:
$(MAKE) NO_QR=true -C backend/
$(MAKE) -C frontend/
install:
$(MAKE) install -C backend/
$(MAKE) install -C frontend/

View File

@ -4,7 +4,7 @@ project(zint)
find_package(PNG)
set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.c)
set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.c png.c)
set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c)
set(zint_POSTAL_SRCS postal.c auspost.c imail.c)
set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c maxicode.c composite.c aztec.c code49.c code1.c gridmtx.c)
@ -12,7 +12,6 @@ set(zint_SRCS ${zint_COMMON_SRCS} ${zint_ONEDIM_SRCS} ${zint_POSTAL_SRCS} ${zint
if(PNG_FOUND)
include_directories( ${PNG_INCLUDES} )
set(zint_SRCS ${zint_SRCS} png.c)
else(PNG_FOUND)
add_definitions (-DNO_PNG)
endif(PNG_FOUND)

View File

@ -553,11 +553,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
/* Stop character */
concat(dest, C128Table[106]);
expand(symbol, dest);
for(i = 0; i < length; i++) {
symbol->text[i] = source[i] ? source[i] : ' ';
}
symbol->text[length] = '\0';
return error_number;
}

View File

@ -131,10 +131,10 @@ extern int code_one(struct zint_symbol *symbol, unsigned char source[], int leng
extern int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Grid Matrix */
#ifndef NO_PNG
int png_handle(struct zint_symbol *symbol, int rotate_angle);
int bmp_handle(struct zint_symbol *symbol, int rotate_angle);
extern int png_handle(struct zint_symbol *symbol, int rotate_angle);
#endif
extern int bmp_handle(struct zint_symbol *symbol, int rotate_angle);
extern int ps_plot(struct zint_symbol *symbol);
extern int svg_plot(struct zint_symbol *symbol);
@ -498,12 +498,12 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt
case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); break;
case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); break;
case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); break;
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, source, length); break;
case BARCODE_PDF417: error_number = pdf417enc(symbol, source, length); break;
case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, source, length); break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, source, length); break;
case BARCODE_MAXICODE: error_number = maxicode(symbol, source, length); break;
case BARCODE_AZTEC: error_number = aztec(symbol, source, length); break;
case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length); break;
case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length); break;
case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length); break;
case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length); break;
case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); break;
case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); break;
}
return error_number;
@ -607,7 +607,16 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
error_number = reduced_charset(symbol, local_source, length);
break;
}
if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) {
for(i = 0; i < length; i++) {
if(local_source[i] == '\0') {
symbol->text[i] = ' ';
} else {
symbol->text[i] = local_source[i];
}
}
}
if(error_number == 0) {
error_number = error_buffer;
@ -670,7 +679,6 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle)
return error_number;
}
#ifndef NO_PNG
int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle)
{
int error_number;
@ -691,7 +699,6 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle)
error_tag(symbol->errtxt, error_number);
return error_number;
}
#endif
int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle) {
/* Depreciated - will be removed in later version */
@ -713,7 +720,6 @@ int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input,
return error_number;
}
#ifndef NO_PNG
int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle)
{
int error_number;
@ -728,7 +734,6 @@ int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input,
error_number = ZBarcode_Buffer(symbol, rotate_angle);
return error_number;
}
#endif
int ZBarcode_Encode_and_Print_Rotated(struct zint_symbol *symbol, unsigned char *input, int rotate_angle) {
/* Depreciated - will be removed in later version */
@ -803,7 +808,6 @@ int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, i
return ZBarcode_Print(symbol, rotate_angle);
}
#ifndef NO_PNG
int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle)
{
int error_number;
@ -817,4 +821,3 @@ int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename,
return ZBarcode_Buffer(symbol, rotate_angle);
}
#endif

View File

@ -19,15 +19,6 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
This file initially included the code to output barcodes to PNG images. To this has been
added routines to ouput the symbol in a byte array for manipulation within an external
program - the difference can be seen as "PNG mode" and "BMP mode". The reason they have been
lumped together here is because they use much the same functions and so it saves memory to
put them together. The problem is that it means the "BMP mode" functions are not available
unless PNG encoding is enabled. This is a compromise and I hope it doesn't cause anybody problems.
*/
#include <stdio.h>
#ifdef _MSC_VER
#include <fcntl.h>
@ -53,6 +44,7 @@
#define PNG_DATA 100
#define BMP_DATA 200
#ifndef NO_PNG
struct mainprog_info_type {
long width;
long height;
@ -308,6 +300,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width
fclose(wpng_info.outfile);
return 0;
}
#endif /* NO_PNG */
int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle)
{
@ -460,7 +453,11 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c
int error_number;
if(image_type == PNG_DATA) {
#ifndef NO_PNG
error_number = png_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
#else
return ERROR_INVALID_OPTION;
#endif
} else {
error_number = bmp_pixel_plot(symbol, image_height, image_width, pixelbuf, rotate_angle);
}
@ -644,32 +641,30 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
void to_latin1(unsigned char source[], unsigned char preprocessed[])
{
int j, i, next, input_length;
int j, i, input_length;
input_length = ustrlen(source);
j = 0;
i = 0;
next = 0;
while (i < input_length) {
do {
if(source[i] < 128) {
preprocessed[j] = source[i];
j++;
next = i + 1;
i++;
} else {
if(source[i] == 0xC2) {
preprocessed[j] = source[i + 1];
j++;
next = i + 2;
i += 2;
}
if(source[i] == 0xC3) {
preprocessed[j] = source[i + 1] + 64;
j++;
next = i + 2;
i += 2;
}
}
i = next;
}
} while (i < input_length);
preprocessed[j] = '\0';
return;
@ -693,7 +688,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
#else
unsigned char* local_text = (unsigned char*)_alloca(ustrlen(symbol->text) + 1);
#endif
to_latin1(symbol->text, local_text);
textdone = 0;
@ -1088,6 +1083,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type)
return error_number;
}
#ifndef NO_PNG
int png_handle(struct zint_symbol *symbol, int rotate_angle)
{
int error;
@ -1100,6 +1096,7 @@ int png_handle(struct zint_symbol *symbol, int rotate_angle)
return error;
}
#endif /* NO_PNG */
int bmp_handle(struct zint_symbol *symbol, int rotate_angle)
{

View File

@ -22,7 +22,7 @@ namespace Zint
static const qreal maxi_diagonal=11;
static const qreal maxi_width=1.73205807568877*maxi_diagonal/2;
static const char* fontstyle="Ariel";
static const char* fontstyle="Arial";
static const int fontPixelSizeSmall=6;
static const int fontPixelSizeLarge=8;
@ -313,7 +313,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
bool textdone;
int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0;
int yoffset = 0;
QString caption = (const char*)m_zintSymbol->text;
QString caption = QString::fromUtf8((const char *)m_zintSymbol->text, -1);
QFont fontSmall(fontstyle);
fontSmall.setPixelSize(fontPixelSizeSmall);
QFont fontLarge(fontstyle);
@ -692,7 +692,7 @@ void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode
if((caption.isEmpty() == false) && (textdone == false)) {
/* Add text to any other symbol */
painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7,Qt::AlignCenter, caption);
painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7, Qt::AlignCenter, caption);
}
painter.restore();
}