From c15370de048b1e46ae69459fc702fcd3c75b7810 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 15 Feb 2004 16:28:39 +0000 Subject: [PATCH] 2004-02-15 Jim Evins * 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. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@414 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 59 +++++++ glabels2/data/glabels-2.0.dtd | 38 +++-- glabels2/src/bc-gnubarcode.c | 212 +++++++++++++++++++++---- glabels2/src/bc-gnubarcode.h | 4 +- glabels2/src/bc-postnet.c | 65 +++++++- glabels2/src/bc-postnet.h | 4 +- glabels2/src/bc.c | 202 +++++++++++++++-------- glabels2/src/bc.h | 39 ++--- glabels2/src/label-barcode.c | 25 +-- glabels2/src/label-barcode.h | 4 +- glabels2/src/object-editor-bc-page.c | 24 +-- glabels2/src/object-editor-size-page.c | 23 ++- glabels2/src/object-editor.glade | 4 +- glabels2/src/object-editor.h | 4 +- glabels2/src/print.c | 23 +-- glabels2/src/view-barcode.c | 27 ++-- glabels2/src/xml-label-04.c | 9 +- glabels2/src/xml-label-191.c | 9 +- glabels2/src/xml-label.c | 16 +- 19 files changed, 570 insertions(+), 221 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 41a4a8e8..f6ac66c0 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,62 @@ +2004-02-15 Jim Evins + + * 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 * src/stock-pixmaps/Makefile.am: diff --git a/glabels2/data/glabels-2.0.dtd b/glabels2/data/glabels-2.0.dtd index 287dfd3a..872e3317 100644 --- a/glabels2/data/glabels-2.0.dtd +++ b/glabels2/data/glabels-2.0.dtd @@ -16,17 +16,33 @@ - diff --git a/glabels2/src/bc-gnubarcode.c b/glabels2/src/bc-gnubarcode.c index 2bacb0d7..2ea7798b 100644 --- a/glabels2/src/bc-gnubarcode.c +++ b/glabels2/src/bc-gnubarcode.c @@ -46,68 +46,137 @@ /*===========================================*/ /* 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); /*****************************************************************************/ /* 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; } @@ -307,3 +376,80 @@ render_pass1 (struct Barcode_Item *bci, 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); +} + diff --git a/glabels2/src/bc-gnubarcode.h b/glabels2/src/bc-gnubarcode.h index ab186eed..136d0978 100644 --- a/glabels2/src/bc-gnubarcode.h +++ b/glabels2/src/bc-gnubarcode.h @@ -26,12 +26,12 @@ 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 diff --git a/glabels2/src/bc-postnet.c b/glabels2/src/bc-postnet.c index c333b2d1..b0be19da 100644 --- a/glabels2/src/bc-postnet.c +++ b/glabels2/src/bc-postnet.c @@ -65,26 +65,51 @@ static gchar *frame_symbol = "1"; /*===========================================*/ /* 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); /****************************************************************************/ /* 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); @@ -92,6 +117,8 @@ gl_barcode_postnet_new (glBarcodeStyle style, 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++) { @@ -126,7 +153,7 @@ gl_barcode_postnet_new (glBarcodeStyle style, /* PRIVATE. Generate string of symbols, representing barcode. */ /*--------------------------------------------------------------------------*/ static gchar * -postnet_code (gchar *digits) +postnet_code (const gchar *digits) { gchar *p; gint len; @@ -138,8 +165,8 @@ postnet_code (gchar *digits) 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; @@ -163,3 +190,27 @@ postnet_code (gchar *digits) 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); +} + diff --git a/glabels2/src/bc-postnet.h b/glabels2/src/bc-postnet.h index 717f1043..0753290a 100644 --- a/glabels2/src/bc-postnet.h +++ b/glabels2/src/bc-postnet.h @@ -26,12 +26,12 @@ 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 diff --git a/glabels2/src/bc.c b/glabels2/src/bc.c index 8c431f1b..d818a9a2 100644 --- a/glabels2/src/bc.c +++ b/glabels2/src/bc.c @@ -21,6 +21,8 @@ */ #include +#include + #include "bc.h" #include "bc-postnet.h" #include "bc-gnubarcode.h" @@ -36,6 +38,7 @@ /*========================================================*/ typedef struct { + gchar *id; gchar *name; glBarcodeNewFunc new; gboolean can_text; @@ -50,44 +53,94 @@ typedef struct { /* 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} + }; /*========================================================*/ @@ -95,28 +148,71 @@ Backend backends[GL_BARCODE_N_STYLES] = { /*========================================================*/ +/*---------------------------------------------------------------------------*/ +/* 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=0) && (style=0) && (style=0) && (style=0) && (style=0) && (style=0) && (styleprivate->style = style; + lbc->private->id = g_strdup (id); lbc->private->text_flag = text_flag; lbc->private->checksum_flag = checksum_flag; @@ -241,13 +242,13 @@ 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) { 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; } @@ -273,12 +274,12 @@ get_size (glLabelObject *object, 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, @@ -287,8 +288,8 @@ get_size (glLabelObject *object, 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, diff --git a/glabels2/src/label-barcode.h b/glabels2/src/label-barcode.h index b8955345..d2fda717 100644 --- a/glabels2/src/label-barcode.h +++ b/glabels2/src/label-barcode.h @@ -61,13 +61,13 @@ GObject *gl_label_barcode_new (glLabel *label); 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); diff --git a/glabels2/src/object-editor-bc-page.c b/glabels2/src/object-editor-bc-page.c index a4659e9d..ea31d23e 100644 --- a/glabels2/src/object-editor-bc-page.c +++ b/glabels2/src/object-editor-bc-page.c @@ -121,24 +121,24 @@ static void 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 */ @@ -153,7 +153,7 @@ style_changed_cb (glObjectEditor *editor) /*****************************************************************************/ void gl_object_editor_set_bc_style (glObjectEditor *editor, - glBarcodeStyle style, + gchar *id, gboolean text_flag, gboolean checksum_flag) { @@ -172,7 +172,7 @@ gl_object_editor_set_bc_style (glObjectEditor *editor, 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); @@ -190,9 +190,9 @@ gl_object_editor_set_bc_style (glObjectEditor *editor, 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), @@ -212,7 +212,7 @@ gl_object_editor_set_bc_style (glObjectEditor *editor, /*****************************************************************************/ void gl_object_editor_get_bc_style (glObjectEditor *editor, - glBarcodeStyle *style, + gchar **id, gboolean *text_flag, gboolean *checksum_flag) { @@ -223,7 +223,7 @@ gl_object_editor_get_bc_style (glObjectEditor *editor, 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)); diff --git a/glabels2/src/object-editor-size-page.c b/glabels2/src/object-editor-size-page.c index e31815d5..aec58954 100644 --- a/glabels2/src/object-editor-size-page.c +++ b/glabels2/src/object-editor-size-page.c @@ -120,11 +120,11 @@ gl_object_editor_prepare_size_page (glObjectEditor *editor, 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)); @@ -147,6 +147,8 @@ aspect_toggle_cb (glObjectEditor *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)) { @@ -157,6 +159,8 @@ aspect_toggle_cb (glObjectEditor *editor) editor->priv->size_aspect_ratio = h / w; } + + gl_debug (DEBUG_EDITOR, "END"); } /*--------------------------------------------------------------------------*/ @@ -168,6 +172,8 @@ w_spin_cb (glObjectEditor *editor) 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)) { @@ -190,6 +196,7 @@ w_spin_cb (glObjectEditor *editor) 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"); } /*--------------------------------------------------------------------------*/ @@ -198,9 +205,12 @@ w_spin_cb (glObjectEditor *editor) 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)) { @@ -222,6 +232,7 @@ h_spin_cb (glObjectEditor *editor) 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"); } /*--------------------------------------------------------------------------*/ @@ -234,6 +245,8 @@ size_reset_cb (glObjectEditor *editor) 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); @@ -278,6 +291,8 @@ size_reset_cb (glObjectEditor *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"); } /*****************************************************************************/ diff --git a/glabels2/src/object-editor.glade b/glabels2/src/object-editor.glade index 44c3f1b5..c85236c1 100644 --- a/glabels2/src/object-editor.glade +++ b/glabels2/src/object-editor.glade @@ -1502,7 +1502,7 @@ True - False + True True False True @@ -1512,7 +1512,7 @@ True True - True + False True 0 diff --git a/glabels2/src/object-editor.h b/glabels2/src/object-editor.h index bf9273f4..ff47e423 100644 --- a/glabels2/src/object-editor.h +++ b/glabels2/src/object-editor.h @@ -221,12 +221,12 @@ void gl_object_editor_set_text_buffer (glObjectEditor *editor, * 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); diff --git a/glabels2/src/print.c b/glabels2/src/print.c index 769cac6b..19429bee 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -992,15 +992,15 @@ draw_barcode_object (PrintInfo *pi, 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; @@ -1010,14 +1010,15 @@ draw_barcode_object (PrintInfo *pi, 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) { diff --git a/glabels2/src/view-barcode.c b/glabels2/src/view-barcode.c index 6b5dc852..22d40549 100644 --- a/glabels2/src/view-barcode.c +++ b/glabels2/src/view-barcode.c @@ -258,7 +258,7 @@ update_object_from_editor_cb (glObjectEditor *editor, { gdouble x, y, w, h; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag, cs_flag; guint color; @@ -282,11 +282,12 @@ update_object_from_editor_cb (glObjectEditor *editor, 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, @@ -307,7 +308,7 @@ update_editor_from_object_cb (glLabelObject *object, { gdouble w, h; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag, cs_flag; guint color; glMerge *merge; @@ -318,10 +319,11 @@ update_editor_from_object_cb (glLabelObject *object, 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)); @@ -447,7 +449,7 @@ gl_view_barcode_create_event_handler (GnomeCanvas *canvas, 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), @@ -476,7 +478,7 @@ gl_view_barcode_create_event_handler (GnomeCanvas *canvas, 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), @@ -518,7 +520,7 @@ draw_barcode (glViewBarcode *view_barcode) glLabelObject *object; GnomeCanvasItem *item; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag; gboolean checksum_flag; guint color; @@ -539,12 +541,12 @@ draw_barcode (glViewBarcode *view_barcode) /* 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); } @@ -565,7 +567,7 @@ draw_barcode (glViewBarcode *view_barcode) 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"); @@ -641,6 +643,7 @@ draw_barcode (glViewBarcode *view_barcode) /* clean up */ gl_barcode_free (&gbc); g_free (digits); + g_free (id); gl_debug (DEBUG_VIEW, "END"); } diff --git a/glabels2/src/xml-label-04.c b/glabels2/src/xml-label-04.c index 26f9835b..152457dc 100644 --- a/glabels2/src/xml-label-04.c +++ b/glabels2/src/xml-label-04.c @@ -412,7 +412,7 @@ static void xml04_parse_barcode_props (xmlNodePtr node, glLabelBarcode *object) { - glBarcodeStyle style; + gchar *id; gboolean text_flag; guint color; gdouble scale; @@ -424,16 +424,14 @@ xml04_parse_barcode_props (xmlNodePtr node, 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; @@ -450,6 +448,7 @@ xml04_parse_barcode_props (xmlNodePtr node, gl_label_barcode_set_data (object, text_node); gl_text_node_free (&text_node); + g_free (id); gl_debug (DEBUG_XML, "END"); } diff --git a/glabels2/src/xml-label-191.c b/glabels2/src/xml-label-191.c index 731c866f..87d0c50b 100644 --- a/glabels2/src/xml-label-191.c +++ b/glabels2/src/xml-label-191.c @@ -510,7 +510,7 @@ xml191_parse_barcode_props (xmlNodePtr node, gdouble w, h; gchar *string; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag; gboolean checksum_flag; guint color; @@ -524,9 +524,7 @@ xml191_parse_barcode_props (xmlNodePtr node, 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); @@ -548,10 +546,11 @@ xml191_parse_barcode_props (xmlNodePtr node, 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"); diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index 45267883..c08394ae 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -676,7 +676,7 @@ xml_parse_object_barcode (xmlNodePtr node, gdouble w, h; gchar *string; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag; gboolean checksum_flag; guint color; @@ -697,15 +697,14 @@ xml_parse_object_barcode (xmlNodePtr node, 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"); @@ -1343,7 +1342,7 @@ xml_create_object_barcode (xmlNodePtr root, gdouble x, y; gdouble w, h; glTextNode *text_node; - glBarcodeStyle style; + gchar *id; gboolean text_flag; gboolean checksum_flag; guint color; @@ -1365,12 +1364,13 @@ xml_create_object_barcode (xmlNodePtr root, /* 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)); -- 2.39.5