+2004-02-15 Jim Evins <evins@snaught.com>
+
+ * data/glabels-2.0.dtd:
+ Added specific subtypes for various barcode types.
+
+ * src/bc.h:
+ * src/bc.c: (id_to_index), (name_to_index), (gl_barcode_new),
+ (gl_barcode_get_styles_list), (gl_barcode_default_digits),
+ (gl_barcode_can_text), (gl_barcode_text_optional),
+ (gl_barcode_can_csum), (gl_barcode_csum_optional),
+ (gl_barcode_id_to_name), (gl_barcode_name_to_id):
+ Changed API to use a string id, rather than a fixed enumeration. Id and
+ name are separate strings. Added entries to backend table for specific
+ subtypes for various barcode types.
+
+ * src/bc-postnet.h:
+ * src/bc-postnet.c: (gl_barcode_postnet_new), (postnet_code),
+ (is_length_valid):
+ Modified to conform to above API. Now more stringent with data length
+ for various subtypes.
+
+ * src/bc-gnubarcode.h:
+ * src/bc-gnubarcode.c: (gl_barcode_gnubarcode_new),
+ (is_length_valid), (is_length1_valid), (is_length2_valid):
+ Modified to conform to above API. Now more stringent with data length
+ for various subtypes.
+
+ * src/label-barcode.h:
+ * src/label-barcode.c: (copy), (gl_label_barcode_set_props),
+ (gl_label_barcode_get_props), (get_size):
+ Modified to use above API for storing barcode type.
+
+ * src/object-editor.h:
+ * src/object-editor-bc-page.c: (style_changed_cb),
+ (gl_object_editor_set_bc_style), (gl_object_editor_get_bc_style):
+ Modified to use above API for storing barcode type.
+
+ * src/object-editor-size-page.c:
+ (gl_object_editor_prepare_size_page), (aspect_toggle_cb),
+ (w_spin_cb), (h_spin_cb), (size_reset_cb):
+ Added debug markers.
+
+ * src/object-editor.glade:
+ Made barcode style combo's text entry non-editable.
+
+ * src/print.c: (draw_barcode_object):
+ Modified to use above API for barcode type.
+
+ * src/view-barcode.c: (update_object_from_editor_cb),
+ (update_editor_from_object_cb),
+ (gl_view_barcode_create_event_handler), (draw_barcode):
+ Modified to use above API for barcode type.
+
+ * src/xml-label-04.c: (xml04_parse_barcode_props):
+ * src/xml-label-191.c: (xml191_parse_barcode_props):
+ * src/xml-label.c: (xml_parse_object_barcode),
+ (xml_create_object_barcode):
+ Modified to use above API for barcode type.
+
2004-02-07 Jim Evins <evins@snaught.com>
* src/stock-pixmaps/Makefile.am:
<!ENTITY % FONT_WEIGHT_TYPE "(Regular | Bold)">
<!-- Barcode related enumerations/types -->
-<!ENTITY % BC_STYLE_TYPE "(POSTNET |
- EAN |
- UPC |
- ISBN |
- Code39 |
- Code128 |
- Code128C |
- Code128B |
- I25 |
- CBR |
- MSI |
+<!ENTITY % BC_STYLE_TYPE "(POSTNET |
+ POSTNET-5 |
+ POSTNET-9 |
+ POSTNET-11 |
+ EAN |
+ EAN-8 |
+ EAN-8+2 |
+ EAN-8+5 |
+ EAN-13 |
+ EAN-13+2 |
+ EAN-13+5 |
+ UPC |
+ UPC-A |
+ UPC-A+2 |
+ UPC-A+5 |
+ UPC-E |
+ UPC-E+2 |
+ UPC-E+5 |
+ ISBN |
+ ISBN+5 |
+ Code39 |
+ Code128 |
+ Code128C |
+ Code128B |
+ I25 |
+ CBR |
+ MSI |
PLS)"
>
/*===========================================*/
/* Local function prototypes */
/*===========================================*/
-static glBarcode *render_pass1 (struct Barcode_Item *bci,
- gint flags);
+static glBarcode *render_pass1 (struct Barcode_Item *bci,
+ gint flags);
+
+static gboolean is_length_valid (const gchar *digits,
+ gint n1,
+ gint n2);
+
+static gboolean is_length1_valid (const gchar *digits,
+ gint n1,
+ gint n2);
+
+static gboolean is_length2_valid (const gchar *digits,
+ gint n1,
+ gint n2);
\f
/*****************************************************************************/
/* Generate intermediate representation of barcode. */
/*****************************************************************************/
glBarcode *
-gl_barcode_gnubarcode_new (glBarcodeStyle style,
+gl_barcode_gnubarcode_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits)
+ const gchar *digits)
{
glBarcode *gbc;
struct Barcode_Item *bci;
gint flags;
- bci = Barcode_Create (digits);
-
- /* First encode using GNU Barcode library */
- switch (style) {
- case GL_BARCODE_STYLE_EAN:
+ /* Assign type flag. Pre-filter by length for subtypes. */
+ if (g_strcasecmp (id, "EAN") == 0) {
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-8") == 0) {
+ if (!is_length_valid (digits, 7, 8)) {
+ return NULL;
+ }
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-8+2") == 0) {
+ if (!is_length1_valid (digits, 7, 8) || !is_length2_valid (digits, 2, 2)) {
+ return NULL;
+ }
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-8+5") == 0) {
+ if (!is_length1_valid (digits, 7, 8) || !is_length2_valid (digits, 5, 5)) {
+ return NULL;
+ }
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-13") == 0) {
+ if (!is_length_valid (digits, 12, 13)) {
+ return NULL;
+ }
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-13+2") == 0) {
+ if (!is_length1_valid (digits, 12,13) || !is_length2_valid (digits, 2,2)) {
+ return NULL;
+ }
+ flags = BARCODE_EAN;
+ } else if (g_strcasecmp (id, "EAN-13+5") == 0) {
+ if (!is_length1_valid (digits, 12,13) || !is_length2_valid (digits, 5,5)) {
+ return NULL;
+ }
flags = BARCODE_EAN;
- break;
- case GL_BARCODE_STYLE_UPC:
+ } else if (g_strcasecmp (id, "UPC") == 0) {
flags = BARCODE_UPC;
- break;
- case GL_BARCODE_STYLE_ISBN:
+ } else if (g_strcasecmp (id, "UPC-A") == 0) {
+ if (!is_length_valid (digits, 11, 12)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "UPC-A+2") == 0) {
+ if (!is_length1_valid (digits, 11,12) || !is_length2_valid (digits, 2,2)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "UPC-A+5") == 0) {
+ if (!is_length1_valid (digits, 11,12) || !is_length2_valid (digits, 5,5)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "UPC-E") == 0) {
+ if (!is_length_valid (digits, 6, 8)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "UPC-E+2") == 0) {
+ if (!is_length1_valid (digits, 6, 8) || !is_length2_valid (digits, 2,2)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "UPC-E+5") == 0) {
+ if (!is_length1_valid (digits, 6, 8) || !is_length2_valid (digits, 5,5)) {
+ return NULL;
+ }
+ flags = BARCODE_UPC;
+ } else if (g_strcasecmp (id, "ISBN") == 0) {
+ if (!is_length_valid (digits, 9, 10)) {
+ return NULL;
+ }
flags = BARCODE_ISBN;
- break;
- case GL_BARCODE_STYLE_39:
+ } else if (g_strcasecmp (id, "ISBN+5") == 0) {
+ if (!is_length1_valid (digits, 9, 10) || !is_length2_valid (digits, 5,5)) {
+ return NULL;
+ }
+ flags = BARCODE_ISBN;
+ } else if (g_strcasecmp (id, "Code39") == 0) {
flags = BARCODE_39;
- break;
- case GL_BARCODE_STYLE_128:
+ } else if (g_strcasecmp (id, "Code128") == 0) {
flags = BARCODE_128;
- break;
- case GL_BARCODE_STYLE_128C:
+ } else if (g_strcasecmp (id, "Code128C") == 0) {
flags = BARCODE_128C;
- break;
- case GL_BARCODE_STYLE_128B:
+ } else if (g_strcasecmp (id, "Code128B") == 0) {
flags = BARCODE_128B;
- break;
- case GL_BARCODE_STYLE_I25:
+ } else if (g_strcasecmp (id, "I25") == 0) {
flags = BARCODE_I25;
- break;
- case GL_BARCODE_STYLE_CBR:
+ } else if (g_strcasecmp (id, "CBR") == 0) {
flags = BARCODE_CBR;
- break;
- case GL_BARCODE_STYLE_MSI:
+ } else if (g_strcasecmp (id, "MSI") == 0) {
flags = BARCODE_MSI;
- break;
- case GL_BARCODE_STYLE_PLS:
+ } else if (g_strcasecmp (id, "PLS") == 0) {
flags = BARCODE_PLS;
- break;
- default:
- g_warning( "Illegal barcode style %d", style );
+ } else {
+ g_warning( "Illegal barcode id %s", id );
flags = BARCODE_ANY;
- break;
}
+
+ bci = Barcode_Create ((char *)digits);
+
+ /* First encode using GNU Barcode library */
if (!text_flag) {
flags |= BARCODE_NO_ASCII;
}
return gbc;
}
+
+/*--------------------------------------------------------------------------*/
+/* Validate specific length of string (for subtypes). */
+/*--------------------------------------------------------------------------*/
+static gboolean
+is_length_valid (const gchar *digits,
+ gint n1,
+ gint n2)
+{
+ gchar *p;
+ gint i;
+
+ if (!digits) {
+ return FALSE;
+ }
+
+ for (p = (gchar *)digits, i=0; *p != 0; p++) {
+ if (g_ascii_isdigit (*p)) {
+ i++;
+ }
+ }
+
+ return (i >= n1) && (i <= n2);
+}
+
+/*--------------------------------------------------------------------------*/
+/* Validate specific length of string (for subtypes). */
+/*--------------------------------------------------------------------------*/
+static gboolean
+is_length1_valid (const gchar *digits,
+ gint n1,
+ gint n2)
+{
+ gchar *p;
+ gint i;
+
+ if (!digits) {
+ return FALSE;
+ }
+
+ for (p = (gchar *)digits, i=0; !g_ascii_isspace (*p) && *p != 0; p++) {
+ if (g_ascii_isdigit (*p)) {
+ i++;
+ }
+ }
+
+ return (i >= n1) && (i <= n2);
+}
+
+/*--------------------------------------------------------------------------*/
+/* Validate specific length of second string (for subtypes). */
+/*--------------------------------------------------------------------------*/
+static gboolean
+is_length2_valid (const gchar *digits,
+ gint n1,
+ gint n2)
+{
+ gchar *p;
+ gint i;
+
+ if (!digits) {
+ return FALSE;
+ }
+
+ for (p = (gchar *)digits; !g_ascii_isspace (*p) && (*p != 0); p++) {
+ /* Skip over 1st string */
+ }
+
+ for (i=0; *p != 0; p++) {
+ if (g_ascii_isdigit (*p)) {
+ i++;
+ }
+ }
+
+ return (i >= n1) && (i <= n2);
+}
+
G_BEGIN_DECLS
-glBarcode *gl_barcode_gnubarcode_new (glBarcodeStyle style,
+glBarcode *gl_barcode_gnubarcode_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits);
+ const gchar *digits);
G_END_DECLS
/*===========================================*/
/* Local function prototypes */
/*===========================================*/
-static gchar *postnet_code (gchar *digits);
+static gchar *postnet_code (const gchar *digits);
+
+static gboolean is_length_valid (const gchar *digits,
+ gint n);
\f
/****************************************************************************/
/* Generate list of lines that form the barcode for the given digits. */
/****************************************************************************/
glBarcode *
-gl_barcode_postnet_new (glBarcodeStyle style,
+gl_barcode_postnet_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits)
+ const gchar *digits)
{
gchar *code, *p;
glBarcode *gbc;
glBarcodeLine *line;
gdouble x;
- gbc = g_new0 (glBarcode, 1);
+ /* Validate code length for all subtypes. */
+ if ( (g_strcasecmp (id, "POSTNET") == 0) ) {
+ if (!is_length_valid (digits, 5) &&
+ !is_length_valid (digits, 9) &&
+ !is_length_valid (digits, 11)) {
+ return NULL;
+ }
+ }
+ if ( (g_strcasecmp (id, "POSTNET-5") == 0) ) {
+ if (!is_length_valid (digits, 5)) {
+ return NULL;
+ }
+ }
+ if ( (g_strcasecmp (id, "POSTNET-9") == 0) ) {
+ if (!is_length_valid (digits, 9)) {
+ return NULL;
+ }
+ }
+ if ( (g_strcasecmp (id, "POSTNET-11") == 0) ) {
+ if (!is_length_valid (digits, 11)) {
+ return NULL;
+ }
+ }
/* First get code string */
code = postnet_code (digits);
return NULL;
}
+ gbc = g_new0 (glBarcode, 1);
+
/* Now traverse the code string and create a list of lines */
x = POSTNET_HORIZ_MARGIN;
for (p = code; *p != 0; p++) {
/* PRIVATE. Generate string of symbols, representing barcode. */
/*--------------------------------------------------------------------------*/
static gchar *
-postnet_code (gchar *digits)
+postnet_code (const gchar *digits)
{
gchar *p;
gint len;
code = g_string_new (frame_symbol);
sum = 0;
- for (p = digits, len = 0; (*p != 0) && (len < 11); p++) {
- if (isdigit (*p)) {
+ for (p = (gchar *)digits, len = 0; (*p != 0) && (len < 11); p++) {
+ if (g_ascii_isdigit (*p)) {
/* Only translate valid characters (0-9) */
d = (*p) - '0';
sum += d;
return ret;
}
+
+/*--------------------------------------------------------------------------*/
+/* Validate specific length of string (for subtypes). */
+/*--------------------------------------------------------------------------*/
+static gboolean
+is_length_valid (const gchar *digits,
+ gint n)
+{
+ gchar *p;
+ gint i;
+
+ if (!digits) {
+ return FALSE;
+ }
+
+ for (p = (gchar *)digits, i=0; *p != 0; p++) {
+ if (g_ascii_isdigit (*p)) {
+ i++;
+ }
+ }
+
+ return (i == n);
+}
+
G_BEGIN_DECLS
-glBarcode *gl_barcode_postnet_new (glBarcodeStyle style,
+glBarcode *gl_barcode_postnet_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits);
+ const gchar *digits);
G_END_DECLS
*/
#include <config.h>
+#include <libgnome/libgnome.h>
+
#include "bc.h"
#include "bc-postnet.h"
#include "bc-gnubarcode.h"
/*========================================================*/
typedef struct {
+ gchar *id;
gchar *name;
glBarcodeNewFunc new;
gboolean can_text;
/* Private globals. */
/*========================================================*/
-Backend backends[GL_BARCODE_N_STYLES] = {
+Backend backends[] = {
+
+ { "POSTNET", N_("POSTNET (any)"), gl_barcode_postnet_new,
+ FALSE, FALSE, TRUE, FALSE, "000000000"},
+
+ { "POSTNET-5", N_("POSTNET-5 (ZIP only)"), gl_barcode_postnet_new,
+ FALSE, FALSE, TRUE, FALSE, "00000"},
- { "POSTNET", gl_barcode_postnet_new,
+ { "POSTNET-9", N_("POSTNET-9 (ZIP+4)"), gl_barcode_postnet_new,
FALSE, FALSE, TRUE, FALSE, "000000000"},
- { "EAN", gl_barcode_gnubarcode_new,
+ { "POSTNET-11", N_("POSTNET-11 (DPBC)"), gl_barcode_postnet_new,
+ FALSE, FALSE, TRUE, FALSE, "00000000000"},
+
+ { "EAN", N_("EAN (any)"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, FALSE, "000000000000 00000"},
- { "UPC", gl_barcode_gnubarcode_new,
+ { "EAN-8", N_("EAN-8"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "0000000"},
+
+ { "EAN-8+2", N_("EAN-8 +2"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "0000000 00"},
+
+ { "EAN-8+5", N_("EAN-8 +5"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "0000000 00000"},
+
+ { "EAN-13", N_("EAN-13"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000000000"},
+
+ { "EAN-13+2", N_("EAN-13 +2"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000000000 00"},
+
+ { "EAN-13+5", N_("EAN-13 +5"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000000000 00000"},
+
+ { "UPC", N_("UPC (UPC-A or UPC-E)"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, FALSE, "00000000000 00000"},
- { "ISBN", gl_barcode_gnubarcode_new,
+ { "UPC-A", N_("UPC-A"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "00000000000"},
+
+ { "UPC-A+2", N_("UPC-A +2"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "00000000000 00"},
+
+ { "UPC-A+5", N_("UPC-A +5"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "00000000000 00000"},
+
+ { "UPC-E", N_("UPC-E"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000"},
+
+ { "UPC-E+2", N_("UPC-E +2"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000 00"},
+
+ { "UPC-E+5", N_("UPC-E +5"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, FALSE, "000000 00000"},
+
+ { "ISBN", N_("ISBN"), gl_barcode_gnubarcode_new,
+ TRUE, TRUE, TRUE, TRUE, "0-00000-000-0"},
+
+ { "ISBN+5", N_("ISBN +5"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0-00000-000-0 00000"},
- { "Code39", gl_barcode_gnubarcode_new,
+ { "Code39", N_("Code 39"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "Code128", gl_barcode_gnubarcode_new,
+ { "Code128", N_("Code 128"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "Code128C", gl_barcode_gnubarcode_new,
+ { "Code128C", N_("Code 128C"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "Code128B", gl_barcode_gnubarcode_new,
+ { "Code128B", N_("Code 128B"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "I25", gl_barcode_gnubarcode_new,
+ { "I25", N_("Interleaved 2 of 5"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "CBR", gl_barcode_gnubarcode_new,
+ { "CBR", N_("Codabar"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "MSI", gl_barcode_gnubarcode_new,
+ { "MSI", N_("MSI"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
- { "PLS", gl_barcode_gnubarcode_new,
+ { "PLS", N_("Plessey"), gl_barcode_gnubarcode_new,
TRUE, TRUE, TRUE, TRUE, "0000000000"},
+ { NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL}
+
};
/*========================================================*/
/*========================================================*/
\f
+/*---------------------------------------------------------------------------*/
+/* Convert id to index into above table. */
+/*---------------------------------------------------------------------------*/
+static gint
+id_to_index (const gchar *id)
+{
+ gint i;
+
+ if (id == 0) {
+ return 0; /* NULL request default. I.e., the first element. */
+ }
+
+ for (i=0; backends[i].id != NULL; i++) {
+ if (g_strcasecmp (id, backends[i].id) == 0) {
+ return i;
+ }
+ }
+
+ g_warning( "Unknown barcode id \"%s\"", id );
+ return 0;
+}
+
+/*---------------------------------------------------------------------------*/
+/* Convert name to index into above table. */
+/*---------------------------------------------------------------------------*/
+static gint
+name_to_index (const gchar *name)
+{
+ gint i;
+
+ g_return_val_if_fail (name!=NULL, 0);
+
+ for (i=0; backends[i].id != NULL; i++) {
+ if (g_strcasecmp (name, backends[i].name) == 0) {
+ return i;
+ }
+ }
+
+ g_warning( "Unknown barcode name \"%s\"", name );
+ return 0;
+}
+
/*****************************************************************************/
/* Call appropriate barcode backend to create barcode in intermediate format.*/
/*****************************************************************************/
glBarcode *
-gl_barcode_new (glBarcodeStyle style,
+gl_barcode_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits)
+ const gchar *digits)
{
glBarcode *gbc;
+ gint i;
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), NULL);
g_return_val_if_fail (digits!=NULL, NULL);
- gbc = backends[style].new (style,
- text_flag,
- checksum_flag,
- w,
- h,
- digits);
+ i = id_to_index (id);
+ gbc = backends[i].new (backends[i].id,
+ text_flag,
+ checksum_flag,
+ w,
+ h,
+ digits);
return gbc;
}
GList *
gl_barcode_get_styles_list (void)
{
- glBarcodeStyle style;
- GList *list = NULL;
+ gint i;
+ GList *list = NULL;
- for (style=0; style <GL_BARCODE_N_STYLES; style++) {
- list = g_list_append (list, g_strdup (backends[style].name));
+ for (i=0; backends[i].id != NULL; i++) {
+ list = g_list_append (list, g_strdup (backends[i].name));
}
return list;
/* Return an appropriate set of digits for the given barcode style. */
/*****************************************************************************/
gchar *
-gl_barcode_default_digits (glBarcodeStyle style)
+gl_barcode_default_digits (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), "0");
-
- return g_strdup (backends[style].default_digits);
+ return g_strdup (backends[id_to_index (id)].default_digits);
}
/*****************************************************************************/
/* Query text capabilities. */
/*****************************************************************************/
gboolean
-gl_barcode_can_text (glBarcodeStyle style)
+gl_barcode_can_text (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
-
- return backends[style].can_text;
+ return backends[id_to_index (id)].can_text;
}
gboolean
-gl_barcode_text_optional (glBarcodeStyle style)
+gl_barcode_text_optional (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
-
- return backends[style].text_optional;
+ return backends[id_to_index (id)].text_optional;
}
/*****************************************************************************/
/* Query checksum capabilities. */
/*****************************************************************************/
gboolean
-gl_barcode_can_csum (glBarcodeStyle style)
+gl_barcode_can_csum (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
-
- return backends[style].can_checksum;
+ return backends[id_to_index (id)].can_checksum;
}
gboolean
-gl_barcode_csum_optional (glBarcodeStyle style)
+gl_barcode_csum_optional (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), FALSE);
-
- return backends[style].checksum_optional;
+ return backends[id_to_index (id)].checksum_optional;
}
/*****************************************************************************/
/* Convert style to text. */
/*****************************************************************************/
const gchar *
-gl_barcode_style_to_text (glBarcodeStyle style)
+gl_barcode_id_to_name (const gchar *id)
{
- g_return_val_if_fail ((style>=0) && (style<GL_BARCODE_N_STYLES), NULL);
-
- return backends[style].name;
+ return backends[id_to_index (id)].name;
}
/*****************************************************************************/
-/* Convert text to style. */
+/* Convert name to style. */
/*****************************************************************************/
-glBarcodeStyle
-gl_barcode_text_to_style (const gchar *text)
+const gchar *
+gl_barcode_name_to_id (const gchar *name)
{
+ g_return_val_if_fail (name!=NULL, backends[0].id);
- 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;
+ return backends[name_to_index (name)].id;
}
G_BEGIN_DECLS
-typedef enum {
- GL_BARCODE_STYLE_POSTNET,
- GL_BARCODE_STYLE_EAN,
- GL_BARCODE_STYLE_UPC,
- GL_BARCODE_STYLE_ISBN,
- GL_BARCODE_STYLE_39,
- GL_BARCODE_STYLE_128,
- GL_BARCODE_STYLE_128C,
- GL_BARCODE_STYLE_128B,
- GL_BARCODE_STYLE_I25,
- GL_BARCODE_STYLE_CBR,
- GL_BARCODE_STYLE_MSI,
- GL_BARCODE_STYLE_PLS,
-
- GL_BARCODE_N_STYLES
-} glBarcodeStyle;
-
typedef struct {
gdouble x, y, length, width;
} glBarcodeLine;
GList *chars; /* List of glBarcodeChar */
} glBarcode;
-typedef glBarcode *(*glBarcodeNewFunc) (glBarcodeStyle style,
+typedef glBarcode *(*glBarcodeNewFunc) (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits);
+ const gchar *digits);
#define GL_BARCODE_FONT_FAMILY "Sans"
#define GL_BARCODE_FONT_WEIGHT GNOME_FONT_BOOK
-glBarcode *gl_barcode_new (glBarcodeStyle style,
+glBarcode *gl_barcode_new (const gchar *id,
gboolean text_flag,
gboolean checksum_flag,
gdouble w,
gdouble h,
- gchar *digits);
+ const 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);
+gchar *gl_barcode_default_digits (const gchar *id);
-gboolean gl_barcode_can_text (glBarcodeStyle style);
-gboolean gl_barcode_text_optional (glBarcodeStyle style);
+gboolean gl_barcode_can_text (const gchar *id);
+gboolean gl_barcode_text_optional (const gchar *id);
-gboolean gl_barcode_can_csum (glBarcodeStyle style);
-gboolean gl_barcode_csum_optional (glBarcodeStyle style);
+gboolean gl_barcode_can_csum (const gchar *id);
+gboolean gl_barcode_csum_optional (const gchar *id);
-const gchar *gl_barcode_style_to_text (glBarcodeStyle style);
-glBarcodeStyle gl_barcode_text_to_style (const gchar *text);
+const gchar *gl_barcode_id_to_name (const gchar *id);
+const gchar *gl_barcode_name_to_id (const gchar *name);
G_END_DECLS
struct _glLabelBarcodePrivate {
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
guint color;
gboolean text_flag;
gboolean checksum_flag;
glLabelBarcode *lbc = (glLabelBarcode *)src_object;
glLabelBarcode *new_lbc = (glLabelBarcode *)dst_object;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
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, &checksum_flag);
+ gl_label_barcode_get_props (lbc, &id, &text_flag, &checksum_flag);
color = get_line_color (src_object);
gl_label_barcode_set_data (new_lbc, text_node);
- gl_label_barcode_set_props (new_lbc,style, text_flag, checksum_flag);
+ gl_label_barcode_set_props (new_lbc, id, text_flag, checksum_flag);
set_line_color (dst_object, color);
gl_text_node_free (&text_node);
+ g_free (id);
gl_debug (DEBUG_LABEL, "END");
}
void
gl_label_barcode_set_props (glLabelBarcode *lbc,
- glBarcodeStyle style,
+ gchar *id,
gboolean text_flag,
gboolean checksum_flag)
{
g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
- lbc->private->style = style;
+ lbc->private->id = g_strdup (id);
lbc->private->text_flag = text_flag;
lbc->private->checksum_flag = checksum_flag;
void
gl_label_barcode_get_props (glLabelBarcode *lbc,
- glBarcodeStyle *style,
+ gchar **id,
gboolean *text_flag,
gboolean *checksum_flag)
{
g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
- *style = lbc->private->style;
+ *id = g_strdup (lbc->private->id);
*text_flag = lbc->private->text_flag;
*checksum_flag = lbc->private->checksum_flag;
}
if (lbc->private->text_node->field_flag) {
- data = gl_barcode_default_digits (lbc->private->style);
+ data = gl_barcode_default_digits (lbc->private->id);
} else {
data = gl_text_node_expand (lbc->private->text_node, NULL);
}
- gbc = gl_barcode_new (lbc->private->style,
+ gbc = gl_barcode_new (lbc->private->id,
lbc->private->text_flag,
lbc->private->checksum_flag,
w_parent,
if ( gbc == NULL ) {
/* Try again with default digits. */
- data = gl_barcode_default_digits (lbc->private->style);
- gbc = gl_barcode_new (lbc->private->style,
+ data = gl_barcode_default_digits (lbc->private->id);
+ gbc = gl_barcode_new (lbc->private->id,
lbc->private->text_flag,
lbc->private->checksum_flag,
w_parent,
void gl_label_barcode_set_data (glLabelBarcode *lbc,
glTextNode *text_node);
void gl_label_barcode_set_props (glLabelBarcode *lbc,
- glBarcodeStyle style,
+ gchar *id,
gboolean text_flag,
gboolean checksum_flag);
glTextNode *gl_label_barcode_get_data (glLabelBarcode *lbc);
void gl_label_barcode_get_props (glLabelBarcode *lbc,
- glBarcodeStyle *style,
+ gchar **id,
gboolean *text_flag,
gboolean *checksum_flag);
style_changed_cb (glObjectEditor *editor)
{
gchar *style_string;
- glBarcodeStyle style;
+ const gchar *id;
style_string =
gtk_editable_get_chars (GTK_EDITABLE(editor->priv->bc_style_entry), 0, -1);
/* Don't emit if entry is empty. */
if ( *style_string != 0 ) {
- style = gl_barcode_text_to_style (style_string);
+ id = gl_barcode_name_to_id (style_string);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(editor->priv->bc_text_check),
- gl_barcode_can_text (style));
+ gl_barcode_can_text (id));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(editor->priv->bc_cs_check),
- gl_barcode_can_csum (style));
+ gl_barcode_can_csum (id));
gtk_widget_set_sensitive (editor->priv->bc_text_check,
- gl_barcode_text_optional (style));
+ gl_barcode_text_optional (id));
gtk_widget_set_sensitive (editor->priv->bc_cs_check,
- gl_barcode_csum_optional (style));
+ gl_barcode_csum_optional (id));
/* Emit our "changed" signal */
/*****************************************************************************/
void
gl_object_editor_set_bc_style (glObjectEditor *editor,
- glBarcodeStyle style,
+ gchar *id,
gboolean text_flag,
gboolean checksum_flag)
{
G_CALLBACK (gl_object_editor_changed_cb),
editor);
- style_string = gl_barcode_style_to_text (style);
+ style_string = gl_barcode_id_to_name (id);
gtk_editable_delete_text (GTK_EDITABLE (editor->priv->bc_style_entry),
0, -1);
checksum_flag);
gtk_widget_set_sensitive (editor->priv->bc_text_check,
- gl_barcode_text_optional (style));
+ gl_barcode_text_optional (id));
gtk_widget_set_sensitive (editor->priv->bc_cs_check,
- gl_barcode_csum_optional (style));
+ gl_barcode_csum_optional (id));
g_signal_handlers_unblock_by_func (G_OBJECT(editor->priv->bc_style_entry),
G_CALLBACK (style_changed_cb),
/*****************************************************************************/
void
gl_object_editor_get_bc_style (glObjectEditor *editor,
- glBarcodeStyle *style,
+ gchar **id,
gboolean *text_flag,
gboolean *checksum_flag)
{
style_string =
gtk_editable_get_chars (GTK_EDITABLE(editor->priv->bc_style_entry),
0, -1);
- *style = gl_barcode_text_to_style (style_string);
+ *id = g_strdup (gl_barcode_name_to_id (style_string));
*text_flag =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_text_check));
G_CALLBACK (aspect_toggle_cb),
G_OBJECT (editor));
g_signal_connect_swapped (G_OBJECT (editor->priv->size_w_spin),
- "changed",
+ "value-changed",
G_CALLBACK (w_spin_cb),
G_OBJECT (editor));
g_signal_connect_swapped (G_OBJECT (editor->priv->size_h_spin),
- "changed",
+ "value-changed",
G_CALLBACK (h_spin_cb),
G_OBJECT (editor));
glWdgtChainButton *toggle;
gdouble w, h;
+ gl_debug (DEBUG_EDITOR, "START");
+
toggle = GL_WDGT_CHAIN_BUTTON (editor->priv->size_aspect_checkbutton);
if (gl_wdgt_chain_button_get_active (toggle)) {
editor->priv->size_aspect_ratio = h / w;
}
+
+ gl_debug (DEBUG_EDITOR, "END");
}
/*--------------------------------------------------------------------------*/
gdouble w, h;
glWdgtChainButton *toggle;
+ gl_debug (DEBUG_EDITOR, "START");
+
toggle = GL_WDGT_CHAIN_BUTTON (editor->priv->size_aspect_checkbutton);
if (gl_wdgt_chain_button_get_active (toggle)) {
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[SIZE_CHANGED], 0);
+ gl_debug (DEBUG_EDITOR, "END");
}
/*--------------------------------------------------------------------------*/
static void
h_spin_cb (glObjectEditor *editor)
{
- gdouble w, h;
+ gdouble w, h;
+ glWdgtChainButton *toggle;
+
+ gl_debug (DEBUG_EDITOR, "START");
- glWdgtChainButton *toggle = GL_WDGT_CHAIN_BUTTON (editor->priv->size_aspect_checkbutton);
+ toggle = GL_WDGT_CHAIN_BUTTON (editor->priv->size_aspect_checkbutton);
if (gl_wdgt_chain_button_get_active (toggle)) {
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[SIZE_CHANGED], 0);
+ gl_debug (DEBUG_EDITOR, "END");
}
/*--------------------------------------------------------------------------*/
gdouble w_max, h_max;
gdouble aspect_ratio;
+ gl_debug (DEBUG_EDITOR, "START");
+
g_signal_handlers_block_by_func (G_OBJECT (editor->priv->size_w_spin),
G_CALLBACK (w_spin_cb),
editor);
/* Emit our "changed" signal */
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[SIZE_CHANGED], 0);
+
+ gl_debug (DEBUG_EDITOR, "END");
}
/*****************************************************************************/
<child>
<widget class="GtkCombo" id="bc_style_combo">
<property name="visible">True</property>
- <property name="value_in_list">False</property>
+ <property name="value_in_list">True</property>
<property name="allow_empty">True</property>
<property name="case_sensitive">False</property>
<property name="enable_arrow_keys">True</property>
<widget class="GtkEntry" id="bc_style_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="editable">True</property>
+ <property name="editable">False</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
* Barcode Page
*/
void gl_object_editor_set_bc_style (glObjectEditor *editor,
- glBarcodeStyle style,
+ gchar *id,
gboolean text_flag,
gboolean checksum_flag);
void gl_object_editor_get_bc_style (glObjectEditor *editor,
- glBarcodeStyle *style,
+ gchar **id,
gboolean *text_flag,
gboolean *checksum_flag);
glLabelBarcode *object,
glMergeRecord *record)
{
- glBarcode *gbc;
- glBarcodeLine *line;
- glBarcodeChar *bchar;
- GList *li;
- gdouble y_offset;
- GnomeFont *font;
- gchar *text, *cstring;
- glTextNode *text_node;
- glBarcodeStyle style;
+ glBarcode *gbc;
+ glBarcodeLine *line;
+ glBarcodeChar *bchar;
+ GList *li;
+ gdouble y_offset;
+ GnomeFont *font;
+ gchar *text, *cstring;
+ glTextNode *text_node;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
text_node = gl_label_barcode_get_data (object);
gl_label_barcode_get_props (object,
- &style, &text_flag, &checksum_flag);
+ &id, &text_flag, &checksum_flag);
color = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
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, checksum_flag, w, h, text);
+ gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, text);
g_free (text);
gl_text_node_free (&text_node);
+ g_free (id);
if (gbc == NULL) {
{
gdouble x, y, w, h;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag, cs_flag;
guint color;
gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
gl_text_node_free (&text_node);
- gl_object_editor_get_bc_style (editor, &style, &text_flag, &cs_flag);
+ gl_object_editor_get_bc_style (editor, &id, &text_flag, &cs_flag);
color = gl_object_editor_get_bc_color (editor);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, cs_flag);
+ id, text_flag, cs_flag);
gl_label_object_set_line_color (object, color);
+ g_free (id);
g_signal_handlers_unblock_by_func (G_OBJECT(object),
update_editor_from_object_cb,
{
gdouble w, h;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag, cs_flag;
guint color;
glMerge *merge;
gl_object_editor_set_size (editor, w, h);
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &cs_flag);
+ &id, &text_flag, &cs_flag);
color = gl_label_object_get_line_color (object);
- gl_object_editor_set_bc_style (editor, style, text_flag, cs_flag);
+ gl_object_editor_set_bc_style (editor, id, text_flag, cs_flag);
gl_object_editor_set_bc_color (editor, color);
+ g_free (id);
text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
merge = gl_label_get_merge (GL_LABEL(object->parent));
gl_label_barcode_set_data (GL_LABEL_BARCODE(object),
text_node);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- GL_BARCODE_STYLE_POSTNET,
+ "POSTNET",
FALSE,
TRUE);
gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
gl_label_object_set_position (GL_LABEL_OBJECT(object),
x, y);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- GL_BARCODE_STYLE_POSTNET,
+ "POSTNET",
FALSE,
TRUE);
gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
glLabelObject *object;
GnomeCanvasItem *item;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
/* 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, &checksum_flag);
+ &id, &text_flag, &checksum_flag);
color = gl_label_object_get_line_color (object);
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);
+ digits = gl_barcode_default_digits (id);
} else {
digits = gl_text_node_expand (text_node, NULL);
}
FALSE,
10.0);
- gbc = gl_barcode_new (style, text_flag, checksum_flag, w, h, digits);
+ gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, digits);
if (gbc == NULL) {
cstring = _("Invalid barcode data");
/* clean up */
gl_barcode_free (&gbc);
g_free (digits);
+ g_free (id);
gl_debug (DEBUG_VIEW, "END");
}
xml04_parse_barcode_props (xmlNodePtr node,
glLabelBarcode *object)
{
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
guint color;
gdouble scale;
color = gl_xml_get_prop_uint (node, "color", 0);
- string = xmlGetProp (node, "style");
- style = gl_barcode_text_to_style (string);
- g_free (string);
+ id = xmlGetProp (node, "style");
text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
scale = gl_xml_get_prop_double (node, "scale", 1.0);
if (scale == 0.0) {
scale = 0.5; /* Set to a valid value */
}
- gl_label_barcode_set_props (object, style, text_flag, TRUE);
+ gl_label_barcode_set_props (object, id, text_flag, TRUE);
gl_label_object_set_line_color (GL_LABEL_OBJECT(object), color);
child = node->xmlChildrenNode;
gl_label_barcode_set_data (object, text_node);
gl_text_node_free (&text_node);
+ g_free (id);
gl_debug (DEBUG_XML, "END");
}
gdouble w, h;
gchar *string;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
color = gl_xml_get_prop_uint (node, "color", 0);
- string = xmlGetProp (node, "style");
- style = gl_barcode_text_to_style (string);
- g_free (string);
+ id = xmlGetProp (node, "style");
text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE);
gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, checksum_flag);
+ id, text_flag, checksum_flag);
gl_label_object_set_line_color (GL_LABEL_OBJECT(object), color);
gl_text_node_free (&text_node);
+ g_free (id);
gl_debug (DEBUG_XML, "END");
gdouble w, h;
gchar *string;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
/* prop attrs */
- string = xmlGetProp (node, "style");
- style = gl_barcode_text_to_style (string);
- g_free (string);
+ id = xmlGetProp (node, "style");
text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE);
color = gl_xml_get_prop_uint (node, "color", 0);
gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- style, text_flag, checksum_flag);
+ id, text_flag, checksum_flag);
gl_label_object_set_line_color (GL_LABEL_OBJECT(object), color);
+ g_free (id);
/* data or field attr */
string = xmlGetProp (node, "data");
gdouble x, y;
gdouble w, h;
glTextNode *text_node;
- glBarcodeStyle style;
+ gchar *id;
gboolean text_flag;
gboolean checksum_flag;
guint color;
/* Barcode properties attrs */
gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &style, &text_flag, &checksum_flag);
+ &id, &text_flag, &checksum_flag);
color = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
- xmlSetProp (node, "style", gl_barcode_style_to_text (style));
+ xmlSetProp (node, "style", id);
gl_xml_set_prop_boolean (node, "text", text_flag);
gl_xml_set_prop_boolean (node, "checksum", checksum_flag);
gl_xml_set_prop_uint_hex (node, "color", color);
+ g_free (id);
/* data OR field attr */
text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));