[glabels] Some minor barcode cleanup
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels] Some minor barcode cleanup
- Date: Thu, 27 May 2010 00:09:30 +0000 (UTC)
commit 26990ef637b55a385c9b61308bc6ecbb9234334b
Author: Jim Evins <evins snaught com>
Date: Wed May 26 20:02:17 2010 -0400
Some minor barcode cleanup
- Added DEBUG_BARCODE so that verbosity on stdout of new libzint backend
can be controlled.
- Removed artifact comments and some minor formatting changes in libzint
backend.
- In object editor, make preview format track the number of digits in the
digits spinbox in real-time.
src/bc-zint.c | 20 ++++--------------
src/bc.c | 2 +-
src/debug.c | 2 +
src/debug.h | 2 +
src/object-editor-bc-page.c | 44 ++++++++++++++++++++++++++++++++++--------
5 files changed, 45 insertions(+), 25 deletions(-)
---
diff --git a/src/bc-zint.c b/src/bc-zint.c
index 0ad8086..5e45d40 100644
--- a/src/bc-zint.c
+++ b/src/bc-zint.c
@@ -87,26 +87,21 @@ gl_barcode_zint_new (const gchar *id,
}
*/
- // g_message ("Zint Requested Dimensions: %f x %f", w, h);
-
result = ZBarcode_Encode(symbol, (unsigned char *)digits, 0);
if (result) {
ZBarcode_Delete (symbol);
- g_message ("Zint Error: %s", symbol->errtxt);
+ gl_debug (DEBUG_BARCODE, "Zint Error: %s", symbol->errtxt);
return NULL;
}
/* Scale calculated after height, always maintain aspect ratio */
- // symbol->height = (h > 0.0 ? (gint)h : 50);
symbol->scale = (w / symbol->width);
- symbol->height = h / symbol->scale; // height always in standard size
+ symbol->height = h / symbol->scale; /* height always in standard size */
/* Convert Sums provided by zint encode */
gbc = render_zint(symbol, text_flag);
- // g_message ("Zint Barcode Dimensions: %f x %f", gbc->width, gbc->height);
-
ZBarcode_Delete(symbol);
return gbc;
@@ -149,7 +144,6 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) {
if (symbol->height < 15) {
symbol->height = 15;
}
- // symbol->height = 50;
if(text_flag && strlen(symbol->text) != 0) {
textheight = 9.0;
@@ -157,7 +151,7 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) {
} else {
textheight = textoffset = 0.0;
}
- // Update height for texts
+ /* Update height for texts */
symbol->height -= textheight + textoffset;
large_bar_count = 0;
@@ -240,7 +234,6 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) {
line->length = (row_height - 5.0) * scaler;
}
latch = 0;
- // g_message ("Zint Adding Line at: %f x %f dim: %f x %f", line->x, line->y, line->width, line->length);
gl_barcode_add_shape (gbc, (glBarcodeShape *)line);
} else {
/* a space */
@@ -254,14 +247,11 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) {
/* That's done the actual data area, everything else is human-friendly */
-
-
-
/* Add the text */
xoffset -= comp_offset;
if (text_flag) {
- // caculate start xoffset to center text
+ /* caculate start xoffset to center text */
xoffset = symbol->width / 2.0;
xoffset -= (strlen(symbol->text) / 2) * 5.0;
@@ -273,7 +263,7 @@ static glBarcode *render_zint(struct zint_symbol *symbol, gboolean text_flag) {
bchar->fsize = 8.0 * scaler;
bchar->c = (gchar) *p;
gl_barcode_add_shape (gbc, (glBarcodeShape *)bchar);
- // Poor mans kerning
+ /* Poor mans kerning */
if (*p == '(') {
xoffset += 3.0;
} else if (*p == ')') {
diff --git a/src/bc.c b/src/bc.c
index 0761f6e..f03b584 100644
--- a/src/bc.c
+++ b/src/bc.c
@@ -159,7 +159,7 @@ static const Backend backends[] = {
#ifdef HAVE_LIBZINT
- { "GS1-128", N_("GS1-128"), gl_barcode_zint_new,
+ { "GS1-128", N_("GS1-128"), gl_barcode_zint_new,
TRUE, TRUE, FALSE, FALSE, "[00]001234560000000018", TRUE, 16},
#endif /* HAVE_LIBZINT */
diff --git a/src/debug.c b/src/debug.c
index 97972e5..23432d9 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -93,6 +93,8 @@ gl_debug_init (void)
debug_flags |= GLABELS_DEBUG_PATH;
if (g_getenv ("GLABELS_DEBUG_FIELD_BUTTON") != NULL)
debug_flags |= GLABELS_DEBUG_FIELD_BUTTON;
+ if (g_getenv ("GLABELS_DEBUG_BARCODE") != NULL)
+ debug_flags |= GLABELS_DEBUG_BARCODE;
}
diff --git a/src/debug.h b/src/debug.h
index b8bed98..59a862b 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -63,6 +63,7 @@ typedef enum {
GLABELS_DEBUG_WDGT = 1 << 20,
GLABELS_DEBUG_PATH = 1 << 21,
GLABELS_DEBUG_FIELD_BUTTON = 1 << 22,
+ GLABELS_DEBUG_BARCODE = 1 << 23,
} glDebugSection;
@@ -93,6 +94,7 @@ typedef enum {
#define DEBUG_WDGT GLABELS_DEBUG_WDGT, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_PATH GLABELS_DEBUG_PATH, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_FIELD_BUTTON GLABELS_DEBUG_FIELD_BUTTON, __FILE__, __LINE__, __FUNCTION__
+#define DEBUG_BARCODE GLABELS_DEBUG_BARCODE,__FILE__, __LINE__, __FUNCTION__
void gl_debug_init (void);
diff --git a/src/object-editor-bc-page.c b/src/object-editor-bc-page.c
index b3b2fe2..1f4f684 100644
--- a/src/object-editor-bc-page.c
+++ b/src/object-editor-bc-page.c
@@ -57,8 +57,9 @@
/* Local function prototypes */
/*===========================================*/
-static void style_changed_cb (glObjectEditor *editor);
-static void bc_radio_toggled_cb (glObjectEditor *editor);
+static void style_changed_cb (glObjectEditor *editor);
+static void bc_radio_toggled_cb (glObjectEditor *editor);
+static void data_digits_spin_changed_cb (glObjectEditor *editor);
/*--------------------------------------------------------------------------*/
@@ -148,7 +149,7 @@ gl_object_editor_prepare_bc_page (glObjectEditor *editor)
G_OBJECT (editor));
g_signal_connect_swapped (G_OBJECT (editor->priv->data_digits_spin),
"changed",
- G_CALLBACK (gl_object_editor_changed_cb),
+ G_CALLBACK (data_digits_spin_changed_cb),
G_OBJECT (editor));
gl_debug (DEBUG_EDITOR, "END");
@@ -186,12 +187,8 @@ style_changed_cb (glObjectEditor *editor)
gl_barcode_csum_optional (id));
editor->priv->data_format_fixed_flag = !gl_barcode_can_freeform (id);
- digits = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin));
- if (editor->priv->data_format_fixed_flag) {
- digits = gl_barcode_get_prefered_n(id);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin),
- digits);
- }
+ digits = gl_barcode_get_prefered_n(id);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin), digits);
ex_string = gl_barcode_default_digits (id, digits);
gtk_label_set_text (GTK_LABEL(editor->priv->data_ex_label), ex_string);
@@ -425,6 +422,35 @@ bc_radio_toggled_cb (glObjectEditor *editor)
}
+/*--------------------------------------------------------------------------*/
+/* PRIVATE. digits spin changed callback. */
+/*--------------------------------------------------------------------------*/
+static void
+data_digits_spin_changed_cb (glObjectEditor *editor)
+{
+ gchar *style_string;
+ const gchar *id;
+ guint digits;
+ gchar *ex_string;
+
+ if (editor->priv->stop_signals) return;
+
+ style_string = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->bc_style_combo));
+ if ( *style_string != 0 ) {
+ id = gl_barcode_name_to_id (style_string);
+
+ digits = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin));
+ ex_string = gl_barcode_default_digits (id, digits);
+ gtk_label_set_text (GTK_LABEL(editor->priv->data_ex_label), ex_string);
+ }
+
+ g_free (style_string);
+ g_free (ex_string);
+
+ gl_object_editor_changed_cb (editor);
+}
+
+
/*
* Local Variables: -- emacs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]