*
* bc-gnubarcode.c: front-end to GNU-barcode-library module
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* Some of this code is borrowed from the postscript renderer (ps.c)
* from the GNU barcode library:
/* Local function prototypes */
/*===========================================*/
static glBarcode *render_pass1 (struct Barcode_Item *bci,
- gboolean text_flag,
- gdouble scale);
+ gint flags);
+
\f
/*****************************************************************************/
/* Generate intermediate representation of barcode. */
glBarcode *
gl_barcode_gnubarcode_new (glBarcodeStyle style,
gboolean text_flag,
- gdouble scale,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
gchar *digits)
{
glBarcode *gbc;
flags = BARCODE_ANY;
break;
}
+
+ if (!text_flag) {
+ flags |= BARCODE_NO_ASCII;
+ }
+ if (!checksum_flag) {
+ flags |= BARCODE_NO_CHECKSUM;
+ }
+
+ bci->scalef = 0.0;
+ bci->width = w;
+ bci->height = h;
+
Barcode_Encode (bci, flags);
if (!bci->partial || !bci->textinfo) {
g_warning ("Barcode Data Invalid");
/* now render with our custom back-end,
to create appropriate intermdediate format */
- gbc = render_pass1 (bci, text_flag, scale);
+ gbc = render_pass1 (bci, flags);
Barcode_Delete (bci);
return gbc;
*--------------------------------------------------------------------------*/
static glBarcode *
render_pass1 (struct Barcode_Item *bci,
- gboolean text_flag,
- gdouble scale)
+ gint flags)
{
+ gint validbits = BARCODE_NO_ASCII;
glBarcode *gbc;
glBarcodeLine *line;
glBarcodeChar *bchar;
+ gdouble scalef = 1.0;
gdouble x;
gint i, j, barlen;
gdouble f1, f2;
gdouble x0, y0, yr;
guchar *p, c;
+ if (bci->width > (2*bci->margin)) {
+ bci->width -= 2*bci->margin;
+ }
+ if (bci->height > (2*bci->margin)) {
+ bci->height -= 2*bci->margin;
+ }
+
+ /* If any flag is clear in "flags", inherit it from "bci->flags" */
+ if (!(flags & BARCODE_NO_ASCII)) {
+ flags |= bci->flags & BARCODE_NO_ASCII;
+ }
+ flags = bci->flags = (flags & validbits) | (bci->flags & ~validbits);
+
/* First calculate barlen */
barlen = bci->partial[0] - '0';
for (p = bci->partial + 1; *p != 0; p++) {
}
}
+ /* The scale factor depends on bar length */
+ if (!bci->scalef) {
+ if (!bci->width) bci->width = barlen; /* default */
+ scalef = bci->scalef = (double)bci->width / (double)barlen;
+ if (scalef < 0.5) scalef = 0.5;
+ }
+
/* The width defaults to "just enough" */
- bci->width = barlen * scale + 1;
+ bci->width = barlen * scalef + 1;
+
+ /* But it can be too small, in this case enlarge and center the area */
+ if (bci->width < barlen * scalef) {
+ int wid = barlen * scalef + 1;
+ bci->xoff -= (wid - bci->width)/2 ;
+ bci->width = wid;
+ /* Can't extend too far on the left */
+ if (bci->xoff < 0) {
+ bci->width += -bci->xoff;
+ bci->xoff = 0;
+ }
+ }
/* The height defaults to 80 points (rescaled) */
if (!bci->height)
- bci->height = 80 * scale;
+ bci->height = 80 * scalef;
+
+ /* If too small (5 + text), reduce the scale factor and center */
+ i = 5 + 10 * ((bci->flags & BARCODE_NO_ASCII)==0);
+ if (bci->height < i * scalef ) {
+#if 0
+ double scaleg = ((double)bci->height) / i;
+ int wid = bci->width * scaleg / scalef;
+ bci->xoff += (bci->width - wid)/2;
+ bci->width = wid;
+ scalef = scaleg;
+#else
+ bci->height = i * scalef;
+#endif
+ }
gbc = g_new0 (glBarcode, 1);
/* Now traverse the code string and create a list of lines */
- x = bci->margin + (bci->partial[0] - '0') * scale;
+ x = bci->margin + (bci->partial[0] - '0') * scalef;
for (p = bci->partial + 1, i = 1; *p != 0; p++, i++) {
/* special cases: '+' and '-' */
if (*p == '+' || *p == '-') {
else
j = *p - 'a' + 1;
if (i % 2) { /* bar */
- x0 = x + (j * scale) / 2;
+ x0 = x + (j * scalef) / 2;
y0 = bci->margin;
yr = bci->height;
- if (text_flag) { /* leave space for text */
+ if (!(bci->flags & BARCODE_NO_ASCII)) { /* leave space for text */
if (mode == '-') {
/* text below bars: 10 or 5 points */
- yr -= (isdigit (*p) ? 10 : 5) * scale;
+ yr -= (isdigit (*p) ? 10 : 5) * scalef;
} else { /* '+' */
/* above bars: 10 or 0 from bottom,
and 10 from top */
- y0 += 10 * scale;
- yr -= (isdigit (*p) ? 20 : 10) * scale;
+ y0 += 10 * scalef;
+ yr -= (isdigit (*p) ? 20 : 10) * scalef;
}
}
line = g_new0 (glBarcodeLine, 1);
line->x = x0;
line->y = y0;
line->length = yr;
- line->width = (j * scale) - SHRINK_AMOUNT;
+ line->width = (j * scalef) - SHRINK_AMOUNT;
gbc->lines = g_list_append (gbc->lines, line);
}
- x += j * scale;
+ x += j * scalef;
}
/* Now the text */
mode = '-'; /* reinstantiate default */
- if (text_flag) {
+ if (!(bci->flags & BARCODE_NO_ASCII)) {
for (p = bci->textinfo; p; p = strchr (p, ' ')) {
while (*p == ' ')
p++;
continue;
}
bchar = g_new0 (glBarcodeChar, 1);
- bchar->x = f1 * scale + bci->margin;
+ bchar->x = f1 * scalef + bci->margin;
if (mode == '-') {
bchar->y =
- bci->margin + bci->height - 8 * scale;
+ bci->margin + bci->height - 8 * scalef;
} else {
bchar->y = bci->margin;
}
- bchar->fsize = f2 * FONT_SCALE * scale;
+ bchar->fsize = f2 * FONT_SCALE * scalef;
bchar->c = c;
gbc->chars = g_list_append (gbc->chars, bchar);
}
gbc->height = bci->height + 2.0 * bci->margin;
gbc->width = bci->width + 2.0 * bci->margin;
+#if 0
+ g_print ("w=%f, h=%f\n", gbc->width, gbc->height);
+#endif
+
return gbc;
}
*
* bc_gnubarcode.h: front-end to GNU-barcode-library module header file
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
glBarcode *gl_barcode_gnubarcode_new (glBarcodeStyle style,
gboolean text_flag,
- gdouble scale,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
gchar *digits);
G_END_DECLS
*
* bc_postnet.c: GLabels POSTNET barcode module
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* Generate list of lines that form the barcode for the given digits. */
/****************************************************************************/
glBarcode *
-gl_barcode_postnet_new (gchar *digits)
+gl_barcode_postnet_new (glBarcodeStyle style,
+ gboolean text_flag,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
+ gchar *digits)
{
gchar *code, *p;
glBarcode *gbc;
*
* bc_postnet.h: GLabels POSTNET barcode module header file
*
- * Copyright (C) 2001 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
G_BEGIN_DECLS
-glBarcode *gl_barcode_postnet_new (gchar *digits);
+glBarcode *gl_barcode_postnet_new (glBarcodeStyle style,
+ gboolean text_flag,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
+ gchar *digits);
G_END_DECLS
*
* bc.c: GLabels barcode module
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "bc-gnubarcode.h"
#include "debug.h"
+
+/*========================================================*/
+/* Private macros and constants. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+typedef struct {
+ gchar *name;
+ glBarcodeNewFunc new;
+ gboolean can_text;
+ gboolean text_optional;
+ gboolean can_checksum;
+ gboolean checksum_optional;
+ gchar *default_digits;
+} Backend;
+
+
+/*========================================================*/
+/* Private globals. */
+/*========================================================*/
+
+Backend backends[GL_BARCODE_N_STYLES] = {
+
+ { "POSTNET", gl_barcode_postnet_new,
+ FALSE, FALSE, TRUE, FALSE, "000000000"},
+
+ { "EAN", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000000000 00000"},
+
+ { "UPC", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "00000000000 00000"},
+
+ { "ISBN", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0-00000-000-0 00000"},
+
+ { "Code39", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "Code128", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "Code128C", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "Code128B", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "I25", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "CBR", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "MSI", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+ { "PLS", gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0000000000"},
+
+};
+
+/*========================================================*/
+/* Private function prototypes. */
+/*========================================================*/
+
\f
/*****************************************************************************/
/* Call appropriate barcode backend to create barcode in intermediate format.*/
glBarcode *
gl_barcode_new (glBarcodeStyle style,
gboolean text_flag,
- gdouble scale,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
gchar *digits)
{
glBarcode *gbc;
- switch (style) {
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), NULL);
+ g_return_val_if_fail (digits!=NULL, NULL);
- case GL_BARCODE_STYLE_POSTNET:
- /* Use the POSTNET backend module */
- gbc = gl_barcode_postnet_new (digits);
- break;
+ gbc = backends[style].new (style,
+ text_flag,
+ checksum_flag,
+ w,
+ h,
+ digits);
- default:
- /* Use the GNU barcode library backend */
- gbc = gl_barcode_gnubarcode_new (style,
- text_flag,
- scale,
- digits);
- break;
-
- }
return gbc;
}
-\f
+
/*****************************************************************************/
/* Free previously created barcode. */
/*****************************************************************************/
*gbc = NULL;
}
}
-\f
+
+/*****************************************************************************/
+/* Get a list of names for valid barcode styles. */
+/*****************************************************************************/
+GList *
+gl_barcode_get_styles_list (void)
+{
+ glBarcodeStyle style;
+ GList *list = NULL;
+
+ for (style=0; style <GL_BARCODE_N_STYLES; style++) {
+ list = g_list_append (list, g_strdup (backends[style].name));
+ }
+
+ return list;
+}
+
+/*****************************************************************************/
+/* Free up a previously allocated list of style names. */
+/*****************************************************************************/
+void
+gl_barcode_free_styles_list (GList *styles_list)
+{
+ GList *p;
+
+ for (p=styles_list; p != NULL; p=p->next) {
+ g_free (p->data);
+ p->data = NULL;
+ }
+
+ g_list_free (styles_list);
+}
+
+
/*****************************************************************************/
/* Return an appropriate set of digits for the given barcode style. */
/*****************************************************************************/
gchar *
gl_barcode_default_digits (glBarcodeStyle style)
{
- switch (style) {
-
- case GL_BARCODE_STYLE_POSTNET:
- return g_strdup ("000000000");
- case GL_BARCODE_STYLE_EAN:
- return g_strdup ("000000000000 00000");
- case GL_BARCODE_STYLE_UPC:
- return g_strdup ("00000000000 00000");
- case GL_BARCODE_STYLE_ISBN:
- return g_strdup ("0-00000-000-0 00000");
- case GL_BARCODE_STYLE_39:
- case GL_BARCODE_STYLE_128:
- case GL_BARCODE_STYLE_128C:
- case GL_BARCODE_STYLE_128B:
- case GL_BARCODE_STYLE_I25:
- case GL_BARCODE_STYLE_CBR:
- case GL_BARCODE_STYLE_MSI:
- case GL_BARCODE_STYLE_PLS:
- return g_strdup ("0000000000");
- default:
- return g_strdup ("0");
- }
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), "0");
+ return g_strdup (backends[style].default_digits);
+}
+
+/*****************************************************************************/
+/* Query text capabilities. */
+/*****************************************************************************/
+gboolean
+gl_barcode_can_text (glBarcodeStyle style)
+{
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
+
+ return backends[style].can_text;
+}
+
+gboolean
+gl_barcode_text_optional (glBarcodeStyle style)
+{
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
+
+ return backends[style].text_optional;
+}
+
+/*****************************************************************************/
+/* Query checksum capabilities. */
+/*****************************************************************************/
+gboolean
+gl_barcode_can_csum (glBarcodeStyle style)
+{
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
+
+ return backends[style].can_checksum;
+}
+
+gboolean
+gl_barcode_csum_optional (glBarcodeStyle style)
+{
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
+
+ return backends[style].checksum_optional;
}
/*****************************************************************************/
const gchar *
gl_barcode_style_to_text (glBarcodeStyle style)
{
- switch (style) {
- case GL_BARCODE_STYLE_POSTNET:
- return "POSTNET";
- case GL_BARCODE_STYLE_EAN:
- return "EAN";
- case GL_BARCODE_STYLE_UPC:
- return "UPC";
- case GL_BARCODE_STYLE_ISBN:
- return "ISBN";
- case GL_BARCODE_STYLE_39:
- return "Code39";
- case GL_BARCODE_STYLE_128:
- return "Code128";
- case GL_BARCODE_STYLE_128C:
- return "Code128C";
- case GL_BARCODE_STYLE_128B:
- return "Code128B";
- case GL_BARCODE_STYLE_I25:
- return "I25";
- case GL_BARCODE_STYLE_CBR:
- return "CBR";
- case GL_BARCODE_STYLE_MSI:
- return "MSI";
- case GL_BARCODE_STYLE_PLS:
- return "PLS";
- default:
- g_warning( "Illegal barcode style %d", style );
- return "?";
- }
+ g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), NULL);
+
+ return backends[style].name;
}
/*****************************************************************************/
gl_barcode_text_to_style (const gchar *text)
{
- if (g_strcasecmp (text, "POSTNET") == 0) {
- return GL_BARCODE_STYLE_POSTNET;
- }
- if (g_strcasecmp (text, "EAN") == 0) {
- return GL_BARCODE_STYLE_EAN;
- }
- if (g_strcasecmp (text, "UPC") == 0) {
- return GL_BARCODE_STYLE_UPC;
- }
- if (g_strcasecmp (text, "ISBN") == 0) {
- return GL_BARCODE_STYLE_ISBN;
- }
- if (g_strcasecmp (text, "Code39") == 0) {
- return GL_BARCODE_STYLE_39;
- }
- if (g_strcasecmp (text, "Code128") == 0) {
- return GL_BARCODE_STYLE_128;
- }
- if (g_strcasecmp (text, "Code128C") == 0) {
- return GL_BARCODE_STYLE_128C;
- }
- if (g_strcasecmp (text, "Code128B") == 0) {
- return GL_BARCODE_STYLE_128B;
- }
- if (g_strcasecmp (text, "I25") == 0) {
- return GL_BARCODE_STYLE_I25;
- }
- if (g_strcasecmp (text, "CBR") == 0) {
- return GL_BARCODE_STYLE_CBR;
- }
- if (g_strcasecmp (text, "MSI") == 0) {
- return GL_BARCODE_STYLE_MSI;
- }
- if (g_strcasecmp (text, "PLS") == 0) {
- return GL_BARCODE_STYLE_PLS;
- } else {
- g_warning( "Unknown barcode style text \"%s\"", text );
- return GL_BARCODE_STYLE_POSTNET;
+ glBarcodeStyle style;
+
+ for (style=0; style <GL_BARCODE_N_STYLES; style++) {
+ if (g_strcasecmp (text, backends[style].name) == 0) {
+ return style;
+ }
}
+ g_warning( "Unknown barcode style text \"%s\"", text );
+ return GL_BARCODE_STYLE_POSTNET;
}
*
* bc.h: GLabels barcode module header file
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
GL_BARCODE_STYLE_128C,
GL_BARCODE_STYLE_128B,
GL_BARCODE_STYLE_I25,
- GL_BARCODE_STYLE_128RAW,
GL_BARCODE_STYLE_CBR,
GL_BARCODE_STYLE_MSI,
GL_BARCODE_STYLE_PLS,
+
+ GL_BARCODE_N_STYLES
} glBarcodeStyle;
typedef struct {
GList *chars; /* List of glBarcodeChar */
} glBarcode;
+typedef glBarcode *(*glBarcodeNewFunc) (glBarcodeStyle style,
+ gboolean text_flag,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
+ gchar *digits);
+
+
#define GL_BARCODE_FONT_FAMILY "Helvetica"
#define GL_BARCODE_FONT_WEIGHT GNOME_FONT_BOOK
-glBarcode *gl_barcode_new (glBarcodeStyle style,
- gboolean text_flag,
- gdouble scale,
- gchar *digits);
+glBarcode *gl_barcode_new (glBarcodeStyle style,
+ gboolean text_flag,
+ gboolean checksum_flag,
+ gdouble w,
+ gdouble h,
+ gchar *digits);
+
+void gl_barcode_free (glBarcode **bc);
+
+GList *gl_barcode_get_styles_list (void);
+void gl_barcode_free_styles_list (GList *styles_list);
+
+gchar *gl_barcode_default_digits (glBarcodeStyle style);
-void gl_barcode_free (glBarcode **bc);
+gboolean gl_barcode_can_text (glBarcodeStyle style);
+gboolean gl_barcode_text_optional (glBarcodeStyle style);
-gchar *gl_barcode_default_digits (glBarcodeStyle style);
+gboolean gl_barcode_can_csum (glBarcodeStyle style);
+gboolean gl_barcode_csum_optional (glBarcodeStyle style);
-const gchar *gl_barcode_style_to_text (glBarcodeStyle style);
-glBarcodeStyle gl_barcode_text_to_style (const gchar *text);
+const gchar *gl_barcode_style_to_text (glBarcodeStyle style);
+glBarcodeStyle gl_barcode_text_to_style (const gchar *text);
G_END_DECLS
glBarcodeStyle style;
guint color;
gboolean text_flag;
- gdouble scale;
+ gboolean checksum_flag;
};
/*========================================================*/
/* Private globals. */
/*========================================================*/
-static GObjectClass *parent_class = NULL;
+static glLabelObjectClass *parent_class = NULL;
static guint instance = 0;
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
gdouble scale;
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, &style, &text_flag, &color, &scale);
+ gl_label_barcode_get_props (lbc, &style, &text_flag, &checksum_flag, &color);
gl_label_barcode_set_data (new_lbc, text_node);
- gl_label_barcode_set_props (new_lbc,style, text_flag, color, scale);
+ gl_label_barcode_set_props (new_lbc,style, text_flag, checksum_flag, color);
gl_text_node_free (&text_node);
gl_label_barcode_set_props (glLabelBarcode *lbc,
glBarcodeStyle style,
gboolean text_flag,
- guint color,
- gdouble scale)
+ gboolean checksum_flag,
+ guint color)
{
gl_debug (DEBUG_LABEL, "START");
lbc->private->style = style;
lbc->private->text_flag = text_flag;
+ lbc->private->checksum_flag = checksum_flag;
lbc->private->color = color;
- lbc->private->scale = scale;
gl_label_object_emit_changed (GL_LABEL_OBJECT(lbc));
gl_label_barcode_get_props (glLabelBarcode *lbc,
glBarcodeStyle *style,
gboolean *text_flag,
- guint *color,
- gdouble *scale)
+ gboolean *checksum_flag,
+ guint *color)
{
g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
*style = lbc->private->style;
*text_flag = lbc->private->text_flag;
+ *checksum_flag = lbc->private->checksum_flag;
*color = lbc->private->color;
- *scale = lbc->private->scale;
}
/*---------------------------------------------------------------------------*/
{
glLabelBarcode *lbc = (glLabelBarcode *)object;
gchar *data;
+ gdouble w_parent, h_parent;
glBarcode *gbc;
gl_debug (DEBUG_LABEL, "START");
g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
- data = gl_barcode_default_digits (lbc->private->style);
+ (* parent_class->get_size) (object, &w_parent, &h_parent);
+
+
+ if (lbc->private->text_node->field_flag) {
+ data = gl_barcode_default_digits (lbc->private->style);
+ } else {
+ data = gl_text_node_expand (lbc->private->text_node, NULL);
+ }
+
gbc = gl_barcode_new (lbc->private->style,
lbc->private->text_flag,
- lbc->private->scale,
+ lbc->private->checksum_flag,
+ w_parent,
+ h_parent,
data);
+ if ( gbc == NULL ) {
+ /* Try again with default digits. */
+ data = gl_barcode_default_digits (lbc->private->style);
+ gbc = gl_barcode_new (lbc->private->style,
+ lbc->private->text_flag,
+ lbc->private->checksum_flag,
+ w_parent,
+ h_parent,
+ data);
+ }
+
*w = gbc->width;
*h = gbc->height;
gl_barcode_free (&gbc);
+ g_free (data);
gl_debug (DEBUG_LABEL, "END");
}
void gl_label_barcode_set_props (glLabelBarcode *lbc,
glBarcodeStyle style,
gboolean text_flag,
- guint color,
- gdouble scale);
+ gboolean checksum_flag,
+ guint color);
glTextNode *gl_label_barcode_get_data (glLabelBarcode *lbc);
void gl_label_barcode_get_props (glLabelBarcode *lbc,
glBarcodeStyle *style,
gboolean *text_flag,
- guint *color,
- gdouble *scale);
+ gboolean *checksum_flag,
+ guint *color);
G_END_DECLS
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
+ gdouble w, h;
gl_debug (DEBUG_PRINT, "START");
text_node = gl_label_barcode_get_data (object);
gl_label_barcode_get_props (object,
- &style, &text_flag, &color, &scale);
+ &style, &text_flag, &checksum_flag, &color);
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
text = gl_text_node_expand (text_node, record);
- gbc = gl_barcode_new (style, text_flag, scale, text);
+ gbc = gl_barcode_new (style, text_flag, checksum_flag, w, h, text);
g_free (text);
gl_text_node_free (&text_node);
gl_view_object_set_view (GL_VIEW_OBJECT(view_barcode), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_barcode),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_SIMPLE);
+ GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
/* Create analogous canvas items. */
draw_barcode (view_barcode);
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
glMerge *merge;
GtkSizeGroup *label_size_group;
GtkWidget *window;
gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
+ &style, &text_flag, &checksum_flag, &color);
gl_label_get_size (GL_LABEL(object->parent),
&label_width, &label_height);
merge = gl_label_get_merge (GL_LABEL(object->parent));
gl_wdgt_bc_style_set_label_size_group (GL_WDGT_BC_STYLE(view_barcode->private->bc_style),
label_size_group);
gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE (view_barcode->private->bc_style),
- style, text_flag);
+ style, text_flag, checksum_flag);
gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
view_barcode->private->bc_style);
g_signal_connect (G_OBJECT (view_barcode->private->bc_style),
gl_wdgt_bc_props_set_label_size_group (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
label_size_group);
gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
- scale, color);
+ color);
gl_hig_category_add_widget (GL_HIG_CATEGORY(wsection),
view_barcode->private->bc_props);
g_signal_connect ( G_OBJECT(view_barcode->private->bc_props),
glLabelObject *object;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
-
gl_debug (DEBUG_VIEW, "START");
object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
- gl_wdgt_bc_props_get_params (text_props, &scale, &color);
+ &style, &text_flag, &checksum_flag, &color);
+ gl_wdgt_bc_props_get_params (text_props, &color);
g_signal_handlers_block_by_func (G_OBJECT(object),
update_dialog_cb, view_barcode);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, color, scale);
+ style, text_flag, checksum_flag, color);
g_signal_handlers_unblock_by_func (G_OBJECT(object),
update_dialog_cb, view_barcode);
glLabelObject *object;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
gl_debug (DEBUG_VIEW, "START");
object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
- gl_wdgt_bc_style_get_params (bc_style, &style, &text_flag);
+ &style, &text_flag, &checksum_flag, &color);
+ gl_wdgt_bc_style_get_params (bc_style, &style, &text_flag, &checksum_flag);
g_signal_handlers_block_by_func (G_OBJECT(object),
update_dialog_cb, view_barcode);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, color, scale);
+ style, text_flag, checksum_flag, color);
g_signal_handlers_unblock_by_func (G_OBJECT(object),
update_dialog_cb, view_barcode);
/*---------------------------------------------------------------------------*/
static void
position_changed_cb (glWdgtPosition *position,
- glViewBarcode *view_barcode)
+ glViewBarcode *view_barcode)
{
glLabelObject *object;
gdouble x, y;
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
/* Query properties of object. */
text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
+ &style, &text_flag, &checksum_flag, &color);
gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
merge = gl_label_get_merge (GL_LABEL(object->parent));
gl_wdgt_bc_data_set_field_defs (GL_WDGT_BC_DATA(view_barcode->private->bc_data),
merge);
gl_wdgt_bc_props_set_params (GL_WDGT_BC_PROPS(view_barcode->private->bc_props),
- scale, color);
+ color);
gl_wdgt_bc_style_set_params (GL_WDGT_BC_STYLE(view_barcode->private->bc_style),
- style, text_flag);
+ style, text_flag, checksum_flag);
gl_wdgt_position_set_position (GL_WDGT_POSITION(view_barcode->private->position),
x, y);
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
+ gdouble w, h;
glBarcodeLine *line;
glBarcodeChar *bchar;
glBarcode *gbc;
/* Query label object and properties */
object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
+ &style, &text_flag, &checksum_flag, &color);
+ gl_label_object_get_size (object, &w, &h);
text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
if (text_node->field_flag) {
digits = gl_barcode_default_digits (style);
FALSE,
10.0);
- gbc = gl_barcode_new (style, text_flag, scale, digits);
+ gbc = gl_barcode_new (style, text_flag, checksum_flag, w, h, digits);
if (gbc == NULL) {
cstring = _("Invalid barcode");
static void update_simple (glViewHighlight *view_highlight);
+static void get_origin_and_corners (glViewHighlight *view_highlight,
+ gdouble *x0,
+ gdouble *y0,
+ gdouble *x1,
+ gdouble *y1,
+ gdouble *x2,
+ gdouble *y2);
+
static int tl_resize_event_handler (GnomeCanvasItem *handle_item,
GdkEvent *event,
glViewHighlight *view_highlight);
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Top-left" Resize event handler. */
+/* PRIVATE. Get origin and corners relative to object. */
+/*---------------------------------------------------------------------------*/
+static void
+get_origin_and_corners (glViewHighlight *view_highlight,
+ gdouble *x0,
+ gdouble *y0,
+ gdouble *x1,
+ gdouble *y1,
+ gdouble *x2,
+ gdouble *y2)
+{
+ glLabelObject *object;
+
+ object = view_highlight->private->object;;
+
+ /* origin, relative to item */
+ gl_label_object_get_position (object, x0, y0);
+ gnome_canvas_item_w2i (view_highlight->private->group, x0, y0);
+
+ /* Top left corner, relative to item */
+ *x1 = 0.0;
+ *y1 = 0.0;
+
+ /* Bottom right corner, relative to item */
+ gl_label_object_get_size (object, x2, y2);
+}
+
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. "Top-left" Resize event handler. */
/*---------------------------------------------------------------------------*/
static int
tl_resize_event_handler (GnomeCanvasItem *handle_item,
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
x1 = MIN (event->motion.x, x2 - MIN_ITEM_SIZE);
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE);
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
x1 = MIN (event->button.x, x2 - MIN_ITEM_SIZE);
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
x1 = event->button.x;
object = view_highlight->private->object;;
- /* origin, relative to item */
- gl_label_object_get_position (object, &x0, &y0);
- gnome_canvas_item_w2i (view_highlight->private->group, &x0, &y0);
-
- /* Top left corner, relative to item */
- x1 = 0.0;
- y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, &x2, &y2);
-
-
switch (event->type) {
case GDK_BUTTON_PRESS:
switch (event->button.button) {
case 1:
dragging = FALSE;
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_ungrab (handle_item,
event->button.time);
gnome_canvas_item_w2i (view_highlight->private->group,
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
+ get_origin_and_corners (view_highlight,
+ &x0, &y0, &x1, &y1, &x2, &y2);
gnome_canvas_item_w2i (view_highlight->private->group,
&event->button.x, &event->button.y);
/* x1 unchanged */
static void
gl_wdgt_bc_props_instance_init (glWdgtBCProps *prop)
{
- prop->scale_spin = NULL;
prop->color_picker = NULL;
}
wvbox = GTK_WIDGET (prop);
- /* ---- Scale line ---- */
- whbox = gl_hig_hbox_new ();
- gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox);
-
- /* Scale Label */
- prop->scale_label = gtk_label_new (_("Scale:"));
- gtk_misc_set_alignment (GTK_MISC (prop->scale_label), 0, 0.5);
- gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), prop->scale_label);
-
- /* Scale widget */
- adjust = gtk_adjustment_new (100.0, 50.0, 200.0, 10.0, 10.0, 10.0);
- prop->scale_spin =
- gtk_spin_button_new (GTK_ADJUSTMENT (adjust), 10.0, 0);
- g_signal_connect_swapped (G_OBJECT (prop->scale_spin), "changed",
- G_CALLBACK (changed_cb),
- G_OBJECT (prop));
- gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), prop->scale_spin);
-
- /* scale % Label */
- wlabel = gtk_label_new (_("%"));
- gtk_misc_set_alignment (GTK_MISC (wlabel), 0, 0.5);
- gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wlabel);
-
/* ---- Color line ---- */
whbox = gl_hig_hbox_new ();
gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), whbox);
/***************************************************************************/
void
gl_wdgt_bc_props_get_params (glWdgtBCProps *prop,
- gdouble *scale,
guint *color)
{
guint8 r, g, b, a;
- /* ------- Get updated scale ------ */
- *scale =
- gtk_spin_button_get_value (GTK_SPIN_BUTTON(prop->scale_spin));
- *scale /= 100.0;
-
/* ------- Get updated line color ------ */
gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (prop->color_picker),
&r, &g, &b, &a);
/***************************************************************************/
void
gl_wdgt_bc_props_set_params (glWdgtBCProps *prop,
- gdouble scale,
guint color)
{
- scale *= 100.0;
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop->scale_spin), scale);
-
gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (prop->color_picker),
GL_COLOR_I_RED (color),
GL_COLOR_I_GREEN (color),
gl_wdgt_bc_props_set_label_size_group (glWdgtBCProps *prop,
GtkSizeGroup *label_size_group)
{
- gtk_size_group_add_widget (label_size_group, prop->scale_label);
gtk_size_group_add_widget (label_size_group, prop->color_label);
}
struct _glWdgtBCProps {
glHigVBox parent_widget;
- GtkWidget *scale_label;
- GtkWidget *scale_spin;
-
GtkWidget *color_label;
GtkWidget *color_picker;
};
GtkWidget *gl_wdgt_bc_props_new (void);
void gl_wdgt_bc_props_get_params (glWdgtBCProps *prop,
- gdouble *scale,
guint *color);
void gl_wdgt_bc_props_set_params (glWdgtBCProps *prop,
- gdouble scale,
guint color);
void gl_wdgt_bc_props_set_label_size_group (glWdgtBCProps *prop,
static void gl_wdgt_bc_style_finalize (GObject *object);
static void gl_wdgt_bc_style_construct (glWdgtBCStyle *bc_style);
-static void changed_cb (glWdgtBCStyle *bc_style);
+static void style_changed_cb (glWdgtBCStyle *bc_style);
+static void checkbox_changed_cb (glWdgtBCStyle *bc_style);
+
\f
/****************************************************************************/
/* Boilerplate Object stuff. */
/* Style entry widget */
wcombo = gtk_combo_new ();
- style_list = NULL;
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_POSTNET));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_EAN));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_UPC));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_ISBN));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_39));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128B));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_128C));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_I25));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_CBR));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_MSI));
- style_list = g_list_append (style_list,
- (gchar *)gl_barcode_style_to_text(GL_BARCODE_STYLE_PLS));
+ style_list = gl_barcode_get_styles_list ();;
gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), style_list);
- g_list_free (style_list);
+ gl_barcode_free_styles_list (style_list);
bc_style->style_entry = GTK_COMBO (wcombo)->entry;
gtk_entry_set_editable (GTK_ENTRY (bc_style->style_entry), FALSE);
gtk_widget_set_size_request (wcombo, 200, -1);
- g_signal_connect_swapped (G_OBJECT (bc_style->style_entry), "changed",
- G_CALLBACK (changed_cb),
- G_OBJECT (bc_style));
gl_hig_hbox_add_widget (GL_HIG_HBOX(whbox), wcombo);
/* Text checkbox widget */
bc_style->text_check =
- gtk_check_button_new_with_label (_("Show text with barcode"));
+ gtk_check_button_new_with_label (_("Text"));
gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), bc_style->text_check);
+
+
+ /* Checksum checkbox widget */
+ bc_style->checksum_check =
+ gtk_check_button_new_with_label (_("Checksum"));
+ gl_hig_vbox_add_widget (GL_HIG_VBOX(wvbox), bc_style->checksum_check);
+
+
+ /* Connect signal callbacks */
+ g_signal_connect_swapped (G_OBJECT (bc_style->style_entry), "changed",
+ G_CALLBACK (style_changed_cb),
+ G_OBJECT (bc_style));
g_signal_connect_swapped (G_OBJECT (bc_style->text_check), "toggled",
- G_CALLBACK (changed_cb),
+ G_CALLBACK (checkbox_changed_cb),
+ G_OBJECT (bc_style));
+ g_signal_connect_swapped (G_OBJECT (bc_style->checksum_check), "toggled",
+ G_CALLBACK (checkbox_changed_cb),
G_OBJECT (bc_style));
+}
+/*--------------------------------------------------------------------------*/
+/* PRIVATE. Callback for when style has changed. */
+/*--------------------------------------------------------------------------*/
+static void
+style_changed_cb (glWdgtBCStyle *bc_style)
+{
+ gchar *style_string;
+ glBarcodeStyle style;
+
+ style_string =
+ gtk_editable_get_chars (GTK_EDITABLE(bc_style->style_entry),
+ 0, -1);
+
+ /* Don't emit if entry is empty. */
+ if ( *style_string != 0 ) {
+ style = gl_barcode_text_to_style (style_string);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bc_style->text_check),
+ gl_barcode_can_text (style));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(bc_style->checksum_check),
+ gl_barcode_can_csum (style));
+
+ gtk_widget_set_sensitive (bc_style->text_check,
+ gl_barcode_text_optional (style));
+ gtk_widget_set_sensitive (bc_style->checksum_check,
+ gl_barcode_csum_optional (style));
+
+
+ /* Emit our "changed" signal */
+ g_signal_emit (G_OBJECT (bc_style),
+ wdgt_bc_style_signals[CHANGED], 0);
+ }
+
+ g_free (style_string);
}
/*--------------------------------------------------------------------------*/
-/* PRIVATE. Callback for when any control in the widget has changed. */
+/* PRIVATE. Callback for when either checkbox has changed. */
/*--------------------------------------------------------------------------*/
static void
-changed_cb (glWdgtBCStyle *bc_style)
+checkbox_changed_cb (glWdgtBCStyle *bc_style)
{
/* Emit our "changed" signal */
g_signal_emit (G_OBJECT (bc_style),
void
gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style,
glBarcodeStyle *style,
- gboolean *text_flag)
+ gboolean *text_flag,
+ gboolean *checksum_flag)
{
gchar *style_string;
*text_flag =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bc_style->text_check));
+ *checksum_flag =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bc_style->checksum_check));
+
g_free (style_string);
}
void
gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style,
glBarcodeStyle style,
- gboolean text_flag)
+ gboolean text_flag,
+ gboolean checksum_flag)
{
const gchar *style_string;
gint pos;
style_string = gl_barcode_style_to_text (style);
g_signal_handlers_block_by_func (G_OBJECT(bc_style->style_entry),
- G_CALLBACK (changed_cb),
+ G_CALLBACK (style_changed_cb),
bc_style);
gtk_editable_delete_text (GTK_EDITABLE (bc_style->style_entry),
0, -1);
g_signal_handlers_unblock_by_func (G_OBJECT(bc_style->style_entry),
- G_CALLBACK(changed_cb),
+ G_CALLBACK(style_changed_cb),
bc_style);
pos = 0;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bc_style->text_check),
text_flag);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bc_style->checksum_check),
+ checksum_flag);
+
}
/****************************************************************************/
GtkWidget *style_entry;
GtkWidget *text_check;
+ GtkWidget *checksum_check;
};
struct _glWdgtBCStyleClass {
void gl_wdgt_bc_style_get_params (glWdgtBCStyle *bc_style,
glBarcodeStyle *style,
- gboolean *text_flag);
+ gboolean *text_flag,
+ gboolean *checksum_flag);
void gl_wdgt_bc_style_set_params (glWdgtBCStyle *bc_style,
glBarcodeStyle style,
- gboolean text_flag);
+ gboolean text_flag,
+ gboolean checksum_flag);
void gl_wdgt_bc_style_set_label_size_group (glWdgtBCStyle *bc_style,
GtkSizeGroup *label_size_group);
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
gl_debug (DEBUG_XML, "START");
g_free (string);
text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
-
- scale = gl_xml_get_prop_double (node, "scale", 1.0);
+ checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE);
text_node = g_new0 (glTextNode, 1);
for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, color, scale);
+ style, text_flag, checksum_flag, color);
gl_text_node_free (&text_node);
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
+ gboolean checksum_flag;
guint color;
- gdouble scale;
xmlNodePtr child;
gl_debug (DEBUG_XML, "START");
text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &color, &scale);
+ &style, &text_flag, &checksum_flag, &color);
gl_xml_set_prop_uint_hex (object_node, "color", color);
xmlSetProp (object_node, "style", gl_barcode_style_to_text (style));
gl_xml_set_prop_boolean (object_node, "text", text_flag);
- gl_xml_set_prop_double (object_node, "scale", scale);
+ gl_xml_set_prop_boolean (object_node, "checksum", checksum_flag);
if (text_node->field_flag) {
child = xmlNewChild (object_node, ns, "Field", NULL);