[glabels/zint: 6/15] Provides barcode even if invalid for correct sizing



commit f3219c0e3e7800336ac13b8fbd8f62371c2398bb
Author: Sam Lown <me samlown com>
Date:   Sun Jun 13 17:36:44 2010 +0200

    Provides barcode even if invalid for correct sizing

 src/bc-zint.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/bc-zint.c b/src/bc-zint.c
index 55719d3..8db2c13 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;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]