From f3219c0e3e7800336ac13b8fbd8f62371c2398bb Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Sun, 13 Jun 2010 17:36:44 +0200 Subject: [PATCH] Provides barcode even if invalid for correct sizing --- src/bc-zint.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/bc-zint.c b/src/bc-zint.c index 55719d33..8db2c132 100644 --- a/src/bc-zint.c +++ b/src/bc-zint.c @@ -59,8 +59,9 @@ gl_barcode_zint_new (const gchar *id, { glBarcode *gbc; struct zint_symbol *symbol; - gint type; - gint result; + gint type; + gint result; + gchar errtxt[100]; symbol = ZBarcode_Create(); @@ -92,9 +93,18 @@ gl_barcode_zint_new (const gchar *id, result = ZBarcode_Encode(symbol, (unsigned char *)digits, 0); if (result) { - ZBarcode_Delete (symbol); gl_debug (DEBUG_BARCODE, "Zint Error: %s", symbol->errtxt); - return NULL; + strcpy(errtxt, symbol->errtxt); + ZBarcode_Delete (symbol); + // Invalid! Print out a Code128 barcode instead with message + symbol = ZBarcode_Create(); + symbol->symbology = BARCODE_CODE128; + result = ZBarcode_Encode(symbol, (unsigned char *)errtxt, 0); + if (result) { + gl_debug (DEBUG_BARCODE, "Zint Error: %s", symbol->errtxt); + ZBarcode_Delete (symbol); + return NULL; + } } /* Scale calculated after height, always maintain aspect ratio */ @@ -106,7 +116,7 @@ gl_barcode_zint_new (const gchar *id, */ if (!ZBarcode_Render(symbol, (unsigned int) !text_flag, (float) w, (float) h)) { ZBarcode_Delete(symbol); - g_message("Zint Rendering Error: %s", symbol->errtxt); + gl_debug(DEBUG_BARCODE, "Zint Rendering Error: %s", symbol->errtxt); return NULL; } -- 2.39.5