[glabels/zint] Added support for Maxicode barcodes using the libzint backend.



commit 2ef27d0e798c9c6f72c946ed502bc7d670ab4a07
Author: Robin Stuart <robin zint org uk>
Date:   Sat Aug 21 23:04:21 2010 -0400

    Added support for Maxicode barcodes using the libzint backend.

 src/bc-backends.c   |    3 +
 src/bc-zint.c       |   27 +++--
 src/bc.c            |   38 ++++++
 src/bc.h            |   76 ++++++++++++
 src/label-barcode.c |  327 +++++++++++++++++++++++++++------------------------
 5 files changed, 309 insertions(+), 162 deletions(-)
---
diff --git a/src/bc-backends.c b/src/bc-backends.c
index b7a6e23..89c202a 100644
--- a/src/bc-backends.c
+++ b/src/bc-backends.c
@@ -308,6 +308,9 @@ static const Backend backends[] = {
         { "LOGM", N_("LOGMARS"), gl_barcode_zint_new,
           TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
 
+        { "MAXI", N_("Maxicode"), gl_barcode_zint_new,
+          FALSE, FALSE, FALSE, FALSE, "0000000000", TRUE, 10},
+
         { "MPDF", N_("Micro PDF417"), gl_barcode_zint_new,
           FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
 
diff --git a/src/bc-zint.c b/src/bc-zint.c
index d8f3ebd..d96e5d7 100644
--- a/src/bc-zint.c
+++ b/src/bc-zint.c
@@ -123,6 +123,7 @@ gl_barcode_zint_new (const gchar          *id,
 	if (g_ascii_strcasecmp (id, "TELEX") == 0) { symbol->symbology = BARCODE_TELEPEN_NUM; }
 	if (g_ascii_strcasecmp (id, "JAPAN") == 0) { symbol->symbology = BARCODE_JAPANPOST; }
 	if (g_ascii_strcasecmp (id, "KOREA") == 0) { symbol->symbology = BARCODE_KOREAPOST; }
+	if (g_ascii_strcasecmp (id, "MAXI") == 0) { symbol->symbology = BARCODE_MAXICODE; }
 	if (g_ascii_strcasecmp (id, "MPDF") == 0) { symbol->symbology = BARCODE_MICROPDF417; }
 	if (g_ascii_strcasecmp (id, "MSI") == 0) { symbol->symbology = BARCODE_MSI_PLESSEY; }
 	if (g_ascii_strcasecmp (id, "MQR") == 0) { symbol->symbology = BARCODE_MICROQR; }
@@ -173,19 +174,16 @@ gl_barcode_zint_new (const gchar          *id,
 
 /*--------------------------------------------------------------------------
  * PRIVATE. Render to glBarcode the provided Zint symbol.
- *
- * Based on the SVG output from Zint library, handles lots of otherwise
- * internal  Zint code to convert directly to glBarcode representation.
- *
  *--------------------------------------------------------------------------*/
 static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag)
 {
         glBarcode            *gbc;
 
-        struct zint_render        *render;
-        struct zint_render_line   *zline;
-        struct zint_render_string *zstring;
-
+        struct zint_render         *render;
+        struct zint_render_line    *zline;
+        struct zint_render_string  *zstring;
+        struct zint_render_ring    *zring;
+        struct zint_render_hexagon *zhexagon;
 
         render = symbol->rendered;
         gbc = gl_barcode_new ();
@@ -195,9 +193,16 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag)
                 gl_barcode_add_box (gbc, zline->x, zline->y, zline->width, zline->length);
         }
 
-	/*
-	 * Repeat loop for characters
-	 */
+        for ( zring = render->rings; zring != NULL; zring = zring->next )
+        {
+                gl_barcode_add_ring (gbc, zring->x, zring->y, zring->radius, zring->line_width);
+        }
+
+        for ( zhexagon = render->hexagons; zhexagon != NULL; zhexagon = zhexagon->next )
+        {
+                gl_barcode_add_hexagon (gbc, zhexagon->x, zhexagon->y);
+        }
+
         if(text_flag)
         {
                 for ( zstring = render->strings; zstring != NULL; zstring = zstring->next )
diff --git a/src/bc.c b/src/bc.c
index aa5529c..0df1d32 100644
--- a/src/bc.c
+++ b/src/bc.c
@@ -182,6 +182,44 @@ gl_barcode_add_string (glBarcode      *bc,
         gl_barcode_add_shape (bc, (glBarcodeShape *)string_shape);
 }
 
+/*****************************************************************************/
+/* Add ring.                                                                 */
+/*****************************************************************************/
+void
+gl_barcode_add_ring (glBarcode      *bc,
+                     gdouble         x,
+                     gdouble         y,
+                     gdouble         radius,
+                     gdouble         line_width)
+{
+        glBarcodeShapeRing *ring_shape = g_new0 (glBarcodeShapeRing, 1);
+        ring_shape->type = GL_BARCODE_SHAPE_RING;
+
+        ring_shape->x          = x;
+        ring_shape->y          = y;
+        ring_shape->radius     = radius;
+        ring_shape->line_width = line_width;
+
+        gl_barcode_add_shape (bc, (glBarcodeShape *)ring_shape);
+}
+
+/*****************************************************************************/
+/* Add hexagon.                                                              */
+/*****************************************************************************/
+void
+gl_barcode_add_hexagon (glBarcode      *bc,
+                        gdouble         x,
+                        gdouble         y)
+{
+        glBarcodeShapeHexagon *hexagon_shape = g_new0 (glBarcodeShapeHexagon, 1);
+        hexagon_shape->type = GL_BARCODE_SHAPE_HEXAGON;
+
+        hexagon_shape->x      = x;
+        hexagon_shape->y      = y;
+
+        gl_barcode_add_shape (bc, (glBarcodeShape *)hexagon_shape);
+}
+
 
 /*****************************************************************************/
 /* Add shape to barcode.                                                     */
diff --git a/src/bc.h b/src/bc.h
index 06503c2..70512ae 100644
--- a/src/bc.h
+++ b/src/bc.h
@@ -74,6 +74,15 @@ void             gl_barcode_add_string       (glBarcode      *bc,
                                               gchar          *string,
                                               gsize           length);
 
+void             gl_barcode_add_ring         (glBarcode      *bc,
+                                              gdouble         x,
+                                              gdouble         y,
+                                              gdouble         radius,
+                                              gdouble         line_width);
+
+void             gl_barcode_add_hexagon      (glBarcode      *bc,
+                                              gdouble         x,
+                                              gdouble         y);
 
 /*******************************/
 /* Barcode Drawing Primitives. */
@@ -84,6 +93,8 @@ typedef enum {
         GL_BARCODE_SHAPE_BOX,
         GL_BARCODE_SHAPE_CHAR,
         GL_BARCODE_SHAPE_STRING,
+        GL_BARCODE_SHAPE_RING,
+        GL_BARCODE_SHAPE_HEXAGON,
 } glBarcodeShapeType;
 
 typedef struct {
@@ -211,6 +222,69 @@ typedef struct {
 
 } glBarcodeShapeString;
 
+/*
+ * glBarcodeShapeRing:
+ *
+ * @ = origin (x,y) is centre of circle
+ *
+ *                v  line_width
+ *           _.-""""-._
+ *         .'   ____   `.
+ *        /   .'  ^ `.   \
+ *       |   /        \   |
+ *       |   |    @---|---|------
+ *       |   \        /   |     ^
+ *        \   `.____.'   /      | radius
+ *         `._    ...._.'.......|
+ *            `-....-'
+ */
+
+typedef struct {
+
+        /* Begin Common Fields */
+        glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_RING. */
+        gdouble             x;
+        gdouble             y;
+        /* End Common Fields */
+
+        gdouble             radius;
+        gdouble             line_width;
+
+} glBarcodeShapeRing;
+
+/*
+ * glBarcodeShapeHexagon;
+ *
+ * @ = origin (x,y) is top of hexagon
+ *
+ *                  @
+ *              _-"   "-_
+ *          _-"           "-_
+ *       +"                   "+
+ *       |                     |
+ *       |                     |
+ *       |                     |
+ *       |                     |
+ *       |                     |
+ *       +_                   _+
+ *         "-_             _-"
+ *            "-_       _-"
+ *               "-_ _-"
+ *                  "
+ *
+ * NOTE: For Maxicode hexagons height is always 1.02mm, width is always 0.88mm
+ */
+
+typedef struct {
+
+        /* Begin Common Fields */
+        glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_HEXAGON. */
+        gdouble             x;
+        gdouble             y;
+        /* End Common Fields */
+
+} glBarcodeShapeHexagon;
+
 typedef union {
 
         glBarcodeShapeType    type;
@@ -220,6 +294,8 @@ typedef union {
         glBarcodeShapeBox     box;
         glBarcodeShapeChar    bchar;
         glBarcodeShapeString  string;
+        glBarcodeShapeRing    ring;
+        glBarcodeShapeHexagon hexagon;
 
 } glBarcodeShape;
 
diff --git a/src/label-barcode.c b/src/label-barcode.c
index bb5fba7..a57721f 100644
--- a/src/label-barcode.c
+++ b/src/label-barcode.c
@@ -29,12 +29,12 @@
 
 #include "debug.h"
 
-
 /*========================================================*/
 /* Private macros and constants.                          */
 /*========================================================*/
 
 #define FONT_SCALE (72.0/96.0)
+#define PI 3.141592654
 
 
 /*========================================================*/
@@ -42,12 +42,12 @@
 /*========================================================*/
 
 struct _glLabelBarcodePrivate {
-	glTextNode     *text_node;
-	gchar          *id;
-	glColorNode    *color_node;
-	gboolean        text_flag;
-	gboolean        checksum_flag;
-	guint           format_digits;
+        glTextNode     *text_node;
+        gchar          *id;
+        glColorNode    *color_node;
+        gboolean        text_flag;
+        gboolean        checksum_flag;
+        guint           format_digits;
 };
 
 
@@ -63,14 +63,14 @@ struct _glLabelBarcodePrivate {
 static void  gl_label_barcode_finalize      (GObject             *object);
 
 static void  copy                           (glLabelObject       *dst_object,
-					     glLabelObject       *src_object);
+                                             glLabelObject       *src_object);
 
 static void  get_size                       (glLabelObject       *object,
-					     gdouble             *w,
-					     gdouble             *h);
+                                             gdouble             *w,
+                                             gdouble             *h);
 
 static void  set_line_color                 (glLabelObject       *object,
-					     glColorNode         *line_color,
+                                             glColorNode         *line_color,
                                              gboolean             checkpoint);
 
 static glColorNode *get_line_color          (glLabelObject       *object);
@@ -95,44 +95,44 @@ G_DEFINE_TYPE (glLabelBarcode, gl_label_barcode, GL_TYPE_LABEL_OBJECT);
 static void
 gl_label_barcode_class_init (glLabelBarcodeClass *class)
 {
-	GObjectClass       *object_class       = G_OBJECT_CLASS (class);
-	glLabelObjectClass *label_object_class = GL_LABEL_OBJECT_CLASS (class);
+        GObjectClass       *object_class       = G_OBJECT_CLASS (class);
+        glLabelObjectClass *label_object_class = GL_LABEL_OBJECT_CLASS (class);
 
-	gl_label_barcode_parent_class = g_type_class_peek_parent (class);
+        gl_label_barcode_parent_class = g_type_class_peek_parent (class);
 
-	label_object_class->copy           = copy;
-	label_object_class->get_size       = get_size;
-	label_object_class->set_line_color = set_line_color;
-	label_object_class->get_line_color = get_line_color;
+        label_object_class->copy           = copy;
+        label_object_class->get_size       = get_size;
+        label_object_class->set_line_color = set_line_color;
+        label_object_class->get_line_color = get_line_color;
         label_object_class->draw_object    = draw_object;
         label_object_class->draw_shadow    = NULL;
         label_object_class->object_at      = object_at;
 
-	object_class->finalize = gl_label_barcode_finalize;
+        object_class->finalize = gl_label_barcode_finalize;
 }
 
 
 static void
 gl_label_barcode_init (glLabelBarcode *lbc)
 {
-	lbc->priv = g_new0 (glLabelBarcodePrivate, 1);
-	lbc->priv->text_node  = gl_text_node_new_from_text ("");
+        lbc->priv = g_new0 (glLabelBarcodePrivate, 1);
+        lbc->priv->text_node  = gl_text_node_new_from_text ("");
 }
 
 
 static void
 gl_label_barcode_finalize (GObject *object)
 {
-	glLabelBarcode *lbc = GL_LABEL_BARCODE (object);
+        glLabelBarcode *lbc = GL_LABEL_BARCODE (object);
 
-	g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
+        g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
 
-	gl_text_node_free (&lbc->priv->text_node);
-	g_free (lbc->priv->id);
-	gl_color_node_free (&(lbc->priv->color_node));
-	g_free (lbc->priv);
+        gl_text_node_free (&lbc->priv->text_node);
+        g_free (lbc->priv->id);
+        gl_color_node_free (&(lbc->priv->color_node));
+        g_free (lbc->priv);
 
-	G_OBJECT_CLASS (gl_label_barcode_parent_class)->finalize (object);
+        G_OBJECT_CLASS (gl_label_barcode_parent_class)->finalize (object);
 }
 
 
@@ -143,10 +143,10 @@ GObject *
 gl_label_barcode_new (glLabel *label,
                       gboolean checkpoint)
 {
-	glLabelBarcode      *lbc;
-	glColorNode         *line_color_node;
+        glLabelBarcode      *lbc;
+        glColorNode         *line_color_node;
 
-	lbc = g_object_new (gl_label_barcode_get_type(), NULL);
+        lbc = g_object_new (gl_label_barcode_get_type(), NULL);
 
         if (label != NULL)
         {
@@ -165,7 +165,7 @@ gl_label_barcode_new (glLabel *label,
                 gl_label_object_set_parent (GL_LABEL_OBJECT (lbc), label);
         }
 
-	return G_OBJECT (lbc);
+        return G_OBJECT (lbc);
 }
 
 
@@ -176,33 +176,33 @@ static void
 copy (glLabelObject *dst_object,
       glLabelObject *src_object)
 {
-	glLabelBarcode      *lbc     = (glLabelBarcode *)src_object;
-	glLabelBarcode      *new_lbc = (glLabelBarcode *)dst_object;
-	glTextNode          *text_node;
-	gchar               *id;
-	gboolean             text_flag;
-	gboolean             checksum_flag;
-	glColorNode         *color_node;
-	guint                format_digits;
+        glLabelBarcode      *lbc     = (glLabelBarcode *)src_object;
+        glLabelBarcode      *new_lbc = (glLabelBarcode *)dst_object;
+        glTextNode          *text_node;
+        gchar               *id;
+        gboolean             text_flag;
+        gboolean             checksum_flag;
+        glColorNode         *color_node;
+        guint                format_digits;
 
-	gl_debug (DEBUG_LABEL, "START");
+        gl_debug (DEBUG_LABEL, "START");
 
-	g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
-	g_return_if_fail (new_lbc && GL_IS_LABEL_BARCODE (new_lbc));
+        g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
+        g_return_if_fail (new_lbc && GL_IS_LABEL_BARCODE (new_lbc));
 
-	text_node = gl_label_barcode_get_data (lbc);
-	gl_label_barcode_get_props (lbc, &id, &text_flag, &checksum_flag, &format_digits);
-	color_node = get_line_color (src_object);
+        text_node = gl_label_barcode_get_data (lbc);
+        gl_label_barcode_get_props (lbc, &id, &text_flag, &checksum_flag, &format_digits);
+        color_node = get_line_color (src_object);
 
-	gl_label_barcode_set_data (new_lbc, text_node, FALSE);
-	gl_label_barcode_set_props (new_lbc, id, text_flag, checksum_flag, format_digits, FALSE);
-	set_line_color (dst_object, color_node, FALSE);
+        gl_label_barcode_set_data (new_lbc, text_node, FALSE);
+        gl_label_barcode_set_props (new_lbc, id, text_flag, checksum_flag, format_digits, FALSE);
+        set_line_color (dst_object, color_node, FALSE);
 
-	gl_color_node_free (&color_node);
-	gl_text_node_free (&text_node);
-	g_free (id);
+        gl_color_node_free (&color_node);
+        gl_text_node_free (&text_node);
+        g_free (id);
 
-	gl_debug (DEBUG_LABEL, "END");
+        gl_debug (DEBUG_LABEL, "END");
 }
 
 
@@ -211,16 +211,16 @@ copy (glLabelObject *dst_object,
 /*****************************************************************************/
 void
 gl_label_barcode_set_data (glLabelBarcode *lbc,
-			   glTextNode     *text_node,
+                           glTextNode     *text_node,
                            gboolean        checkpoint)
 {
         glLabel *label;
 
-	gl_debug (DEBUG_LABEL, "START");
+        gl_debug (DEBUG_LABEL, "START");
 
-	g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
+        g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
 
-	if (!gl_text_node_equal (lbc->priv->text_node, text_node))
+        if (!gl_text_node_equal (lbc->priv->text_node, text_node))
         {
                 if ( checkpoint )
                 {
@@ -228,35 +228,35 @@ gl_label_barcode_set_data (glLabelBarcode *lbc,
                         gl_label_checkpoint (label, _("Barcode data"));
                 }
                 
-		gl_text_node_free (&lbc->priv->text_node);
-		lbc->priv->text_node = gl_text_node_dup (text_node);
+                gl_text_node_free (&lbc->priv->text_node);
+                lbc->priv->text_node = gl_text_node_dup (text_node);
 
-		gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
-	}
+                gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
+        }
 
-	gl_debug (DEBUG_LABEL, "END");
+        gl_debug (DEBUG_LABEL, "END");
 }
 
 
 void
 gl_label_barcode_set_props (glLabelBarcode *lbc,
-			    gchar          *id,
-			    gboolean        text_flag,
-			    gboolean        checksum_flag,
-			    guint           format_digits,
+                            gchar          *id,
+                            gboolean        text_flag,
+                            gboolean        checksum_flag,
+                            guint           format_digits,
                             gboolean        checkpoint)
 {
         glLabel *label;
 
-	gl_debug (DEBUG_LABEL, "START");
+        gl_debug (DEBUG_LABEL, "START");
 
-	g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
+        g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
 
-	if ( ((lbc->priv->id == NULL) && (id != NULL))
-	     || ((lbc->priv->id != NULL) && (id != NULL) && (g_ascii_strcasecmp (lbc->priv->id, id) != 0))
-	     || (lbc->priv->text_flag != text_flag)
-	     || (lbc->priv->checksum_flag != checksum_flag)
-	     || (lbc->priv->format_digits != format_digits))
+        if ( ((lbc->priv->id == NULL) && (id != NULL))
+             || ((lbc->priv->id != NULL) && (id != NULL) && (g_ascii_strcasecmp (lbc->priv->id, id) != 0))
+             || (lbc->priv->text_flag != text_flag)
+             || (lbc->priv->checksum_flag != checksum_flag)
+             || (lbc->priv->format_digits != format_digits))
         {
                 if ( checkpoint )
                 {
@@ -264,15 +264,15 @@ gl_label_barcode_set_props (glLabelBarcode *lbc,
                         gl_label_checkpoint (label, _("Barcode property"));
                 }
 
-		lbc->priv->id               = g_strdup (id);
-		lbc->priv->text_flag        = text_flag;
-		lbc->priv->checksum_flag    = checksum_flag;
-		lbc->priv->format_digits    = format_digits;
+                lbc->priv->id               = g_strdup (id);
+                lbc->priv->text_flag        = text_flag;
+                lbc->priv->checksum_flag    = checksum_flag;
+                lbc->priv->format_digits    = format_digits;
 
-		gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
-	}
+                gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
+        }
 
-	gl_debug (DEBUG_LABEL, "END");
+        gl_debug (DEBUG_LABEL, "END");
 }
 
 
@@ -282,25 +282,25 @@ gl_label_barcode_set_props (glLabelBarcode *lbc,
 glTextNode *
 gl_label_barcode_get_data (glLabelBarcode *lbc)
 {
-	g_return_val_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc), NULL);
+        g_return_val_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc), NULL);
 
-	return gl_text_node_dup (lbc->priv->text_node);
+        return gl_text_node_dup (lbc->priv->text_node);
 }
 
 
 void
 gl_label_barcode_get_props (glLabelBarcode *lbc,
-			    gchar          **id,
-			    gboolean       *text_flag,
-			    gboolean       *checksum_flag,
-			    guint          *format_digits)
+                            gchar          **id,
+                            gboolean       *text_flag,
+                            gboolean       *checksum_flag,
+                            guint          *format_digits)
 {
-	g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
+        g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
 
-	*id               = g_strdup (lbc->priv->id);
-	*text_flag        = lbc->priv->text_flag;
-	*checksum_flag    = lbc->priv->checksum_flag;
-	*format_digits    = lbc->priv->format_digits;
+        *id               = g_strdup (lbc->priv->id);
+        *text_flag        = lbc->priv->text_flag;
+        *checksum_flag    = lbc->priv->checksum_flag;
+        *format_digits    = lbc->priv->format_digits;
 }
 
 
@@ -309,47 +309,47 @@ gl_label_barcode_get_props (glLabelBarcode *lbc,
 /*---------------------------------------------------------------------------*/
 static void
 get_size (glLabelObject *object,
-	  gdouble       *w,
-	  gdouble       *h)
+          gdouble       *w,
+          gdouble       *h)
 {
-	glLabelBarcode      *lbc = (glLabelBarcode *)object;
-	gchar               *data;
-	gdouble              w_parent, h_parent;
-	glBarcode           *gbc;
+        glLabelBarcode      *lbc = (glLabelBarcode *)object;
+        gchar               *data;
+        gdouble              w_parent, h_parent;
+        glBarcode           *gbc;
 
-	gl_debug (DEBUG_LABEL, "START");
+        gl_debug (DEBUG_LABEL, "START");
 
-	g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
+        g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
 
-	gl_label_object_get_raw_size (object, &w_parent, &h_parent);
+        gl_label_object_get_raw_size (object, &w_parent, &h_parent);
 
-	if (lbc->priv->text_node->field_flag) {
-		data = gl_barcode_backends_default_digits (lbc->priv->id,
+        if (lbc->priv->text_node->field_flag) {
+                data = gl_barcode_backends_default_digits (lbc->priv->id,
                                                            lbc->priv->format_digits);
-	} else {
-		data = gl_text_node_expand (lbc->priv->text_node, NULL);
-	}
+        } else {
+                data = gl_text_node_expand (lbc->priv->text_node, NULL);
+        }
 
-	gbc = gl_barcode_backends_new_barcode (lbc->priv->id,
+        gbc = gl_barcode_backends_new_barcode (lbc->priv->id,
                                                lbc->priv->text_flag,
                                                lbc->priv->checksum_flag,
                                                w_parent,
                                                h_parent,
                                                data);
-	g_free (data);
+        g_free (data);
 
-	if ( gbc == NULL ) {
-		/* Try again with default digits. */
-		data = gl_barcode_backends_default_digits (lbc->priv->id,
-						  lbc->priv->format_digits);
-		gbc = gl_barcode_backends_new_barcode (lbc->priv->id,
+        if ( gbc == NULL ) {
+                /* Try again with default digits. */
+                data = gl_barcode_backends_default_digits (lbc->priv->id,
+                                                  lbc->priv->format_digits);
+                gbc = gl_barcode_backends_new_barcode (lbc->priv->id,
                                                        lbc->priv->text_flag,
                                                        lbc->priv->checksum_flag,
                                                        w_parent,
                                                        h_parent,
                                                        data);
                 g_free (data);
-	}
+        }
 
         if ( gbc != NULL )
         {
@@ -363,9 +363,9 @@ get_size (glLabelObject *object,
                 *h = 72;
         }
 
-	gl_barcode_free (&gbc);
+        gl_barcode_free (&gbc);
 
-	gl_debug (DEBUG_LABEL, "END");
+        gl_debug (DEBUG_LABEL, "END");
 }
 
 
@@ -374,15 +374,15 @@ get_size (glLabelObject *object,
 /*---------------------------------------------------------------------------*/
 static void
 set_line_color (glLabelObject *object,
-		glColorNode   *line_color_node,
+                glColorNode   *line_color_node,
                 gboolean       checkpoint)
 {
-	glLabelBarcode *lbarcode = (glLabelBarcode *)object;
+        glLabelBarcode *lbarcode = (glLabelBarcode *)object;
         glLabel        *label;
 
-	g_return_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode));
+        g_return_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode));
 
-	if ( !gl_color_node_equal(lbarcode->priv->color_node, line_color_node) )
+        if ( !gl_color_node_equal(lbarcode->priv->color_node, line_color_node) )
         {
                 if ( checkpoint )
                 {
@@ -390,10 +390,10 @@ set_line_color (glLabelObject *object,
                         gl_label_checkpoint (label, _("Barcode data"));
                 }
 
-		gl_color_node_free (&(lbarcode->priv->color_node));
-		lbarcode->priv->color_node = gl_color_node_dup (line_color_node);
-		gl_label_object_emit_changed (GL_LABEL_OBJECT(lbarcode));
-	}
+                gl_color_node_free (&(lbarcode->priv->color_node));
+                lbarcode->priv->color_node = gl_color_node_dup (line_color_node);
+                gl_label_object_emit_changed (GL_LABEL_OBJECT(lbarcode));
+        }
 }
 
 
@@ -403,11 +403,11 @@ set_line_color (glLabelObject *object,
 static glColorNode*
 get_line_color (glLabelObject *object)
 {
-	glLabelBarcode *lbarcode = (glLabelBarcode *)object;
+        glLabelBarcode *lbarcode = (glLabelBarcode *)object;
 
-	g_return_val_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode), NULL);
+        g_return_val_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode), NULL);
 
-	return gl_color_node_dup (lbarcode->priv->color_node);
+        return gl_color_node_dup (lbarcode->priv->color_node);
 }
 
 
@@ -426,6 +426,8 @@ draw_object (glLabelObject *object,
         glBarcodeShape       *shape;
         glBarcodeShapeLine   *line;
         glBarcodeShapeBox    *box;
+        glBarcodeShapeRing   *ring;
+        glBarcodeShapeHexagon *hexagon;
         glBarcodeShapeChar   *bchar;
         glBarcodeShapeString *bstring;
         GList                *p;
@@ -444,36 +446,36 @@ draw_object (glLabelObject *object,
         gint                  iw, ih;
         gdouble               layout_width;
 
-	gl_debug (DEBUG_LABEL, "START");
+        gl_debug (DEBUG_LABEL, "START");
 
         gl_label_object_get_position (object, &x0, &y0);
         gl_label_object_get_matrix (object, &matrix);
 
-	text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE (object));
-	gl_label_barcode_get_props (GL_LABEL_BARCODE (object),
-				    &id, &text_flag, &checksum_flag, &format_digits);
-					
-	color_node = gl_label_object_get_line_color (object);
-	color = gl_color_node_expand (color_node, record);
+        text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE (object));
+        gl_label_barcode_get_props (GL_LABEL_BARCODE (object),
+                                    &id, &text_flag, &checksum_flag, &format_digits);
+
+        color_node = gl_label_object_get_line_color (object);
+        color = gl_color_node_expand (color_node, record);
         if (color_node->field_flag && screen_flag)
         {
                 color = GL_COLOR_MERGE_DEFAULT;
         }
-	gl_color_node_free (&color_node);
-	
-	gl_label_object_get_size (object, &w, &h);
+        gl_color_node_free (&color_node);
+
+        gl_label_object_get_size (object, &w, &h);
 
-	text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
+        text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
         text = gl_text_node_expand (text_node, record);
-	if (text_node->field_flag && screen_flag) {
-		text = gl_barcode_backends_default_digits (id, format_digits);
-	}
+        if (text_node->field_flag && screen_flag) {
+                text = gl_barcode_backends_default_digits (id, format_digits);
+        }
 
-	gbc = gl_barcode_backends_new_barcode (id, text_flag, checksum_flag, w, h, text);
+        gbc = gl_barcode_backends_new_barcode (id, text_flag, checksum_flag, w, h, text);
 
         cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (color));
 
-	if (gbc == NULL) {
+        if (gbc == NULL) {
 
                 layout = pango_cairo_create_layout (cr);
 
@@ -497,9 +499,9 @@ draw_object (glLabelObject *object,
 
                 g_object_unref (layout);
 
-	} else {
+        } else {
 
-		for (p = gbc->shapes; p != NULL; p = p->next) {
+                for (p = gbc->shapes; p != NULL; p = p->next) {
                         shape = (glBarcodeShape *)p->data;
                         switch (shape->type)
                         {
@@ -572,23 +574,46 @@ draw_object (glLabelObject *object,
 
                                 break;
 
+                        case GL_BARCODE_SHAPE_RING:
+                                ring = (glBarcodeShapeRing *) shape;
+
+                                cairo_arc (cr, ring->x, ring->y, ring->radius, 0.0, 2 * PI);
+                                cairo_set_line_width (cr, ring->line_width);
+                                cairo_stroke (cr);
+
+                                break;
+
+                        case GL_BARCODE_SHAPE_HEXAGON:
+                                hexagon = (glBarcodeShapeHexagon *) shape;
+
+                                cairo_move_to (cr, hexagon->x, hexagon->y);
+                                cairo_line_to (cr, hexagon->x + 1.25, hexagon->y + 0.70);
+                                cairo_line_to (cr, hexagon->x + 1.25, hexagon->y + 2.18);
+                                cairo_line_to (cr, hexagon->x, hexagon->y + 2.89);
+                                cairo_line_to (cr, hexagon->x - 1.25, hexagon->y + 2.18);
+                                cairo_line_to (cr, hexagon->x - 1.25, hexagon->y + 0.70);
+                                cairo_close_path (cr);
+                                cairo_fill (cr);
+
+                                break;
+
                         default:
                                 g_assert_not_reached ();
                                 break;
 
                         }
 
-		}
+                }
 
-		gl_barcode_free (&gbc);
+                gl_barcode_free (&gbc);
 
-	}
+        }
 
-	g_free (text);
-	gl_text_node_free (&text_node);
-	g_free (id);
+        g_free (text);
+        gl_text_node_free (&text_node);
+        g_free (id);
 
-	gl_debug (DEBUG_LABEL, "END");
+        gl_debug (DEBUG_LABEL, "END");
 }
 
 



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