From fdb6485ef1f7f9d78b8d5a8531ab8840ce2bb525 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Mon, 9 Nov 2009 09:18:08 +0000 Subject: [PATCH] Resolve Latin-1 in Code 128 bug --- Makefile | 4 ---- backend/CMakeLists.txt | 3 +-- backend/code128.c | 5 ----- backend/library.c | 33 ++++++++++++++++++--------------- backend/png.c | 33 +++++++++++++++------------------ backend_qt4/qzint.cpp | 6 +++--- 6 files changed, 37 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index 86768a59..7ea49a68 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index da32be3a..385f015d 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -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) diff --git a/backend/code128.c b/backend/code128.c index c6582403..b495ec48 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -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; } diff --git a/backend/library.c b/backend/library.c index 53d2f03d..e3ba949f 100644 --- a/backend/library.c +++ b/backend/library.c @@ -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 \ No newline at end of file diff --git a/backend/png.c b/backend/png.c index 074d8920..6df4351c 100644 --- a/backend/png.c +++ b/backend/png.c @@ -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 #ifdef _MSC_VER #include @@ -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) { diff --git a/backend_qt4/qzint.cpp b/backend_qt4/qzint.cpp index 46af1069..2330cbe3 100644 --- a/backend_qt4/qzint.cpp +++ b/backend_qt4/qzint.cpp @@ -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(); }