[glabels/vala] Initial vala implementation of IEC16022 backend.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Initial vala implementation of IEC16022 backend.
- Date: Fri, 28 Sep 2012 03:32:58 +0000 (UTC)
commit 8c591d529ef34af02d1dbe1926d407be8540cec3
Author: Jim Evins <evins snaught com>
Date: Thu Sep 27 23:32:19 2012 -0400
Initial vala implementation of IEC16022 backend.
configure.ac | 49 ++++++++++
glabels/Makefile.am | 5 +
glabels/barcode_backends.vala | 2 +
glabels/barcode_backends/iec16022.vala | 140 +++++++++++++++++++++++++++++
glabels/barcode_backends/libiec16022.vapi | 21 +++++
5 files changed, 217 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f8a56c4..a8b96d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,6 +69,7 @@ AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
+dnl Required dependencies
GLIB_REQUIRED=2.28.0
GTK_REQUIRED=3.0.9
LIBXML_REQUIRED=2.7.8
@@ -78,6 +79,31 @@ GDK_PIXBUF_REQUIRED=2.24.0
LIBRSVG_REQUIRED=2.36.0
PANGOCAIRO_REQUIRED=1.30.0
+dnl Optional dependencies
+LIBEBOOK_REQUIRED=2.30.3
+LIBBARCODE_REQUIRED=0.98
+LIBQRENCODE_REQUIRED=3.1.0
+LIBIEC16022_REQUIRED=0.2.4
+LIBZINT_REQUIRED=2.4.0
+
+dnl Make above strings available for packaging files (e.g. rpm spec files)
+AC_SUBST(GLIB_REQUIRED)
+AC_SUBST(GTK_REQUIRED)
+AC_SUBST(LIBXML_REQUIRED)
+AC_SUBST(GEE_REQUIRED)
+AC_SUBST(LIBRSVG_REQUIRED)
+AC_SUBST(CAIRO_REQUIRED)
+AC_SUBST(PANGO_REQUIRED)
+AC_SUBST(GDK_PIXBUF_REQUIRED)
+AC_SUBST(LIBRSVG_REQUIRED)
+AC_SUBST(PANGOCAIRO_REQUIRED)
+AC_SUBST(LIBEBOOK_REQUIRED)
+AC_SUBST(LIBBARCODE_REQUIRED)
+AC_SUBST(LIBQRENCODE_REQUIRED)
+AC_SUBST(LIBIEC16022_REQUIRED)
+AC_SUBST(LIBZINT_REQUIRED)
+
+
PKG_CHECK_MODULES(GLABELS, [\
glib-2.0 >= $GLIB_REQUIRED \
gobject-2.0 >= $GLIB_REQUIRED \
@@ -137,6 +163,28 @@ else
fi
+dnl ---------------------------------------------------------------------------
+dnl - Check for IEC16022 Barcode backend
+dnl ---------------------------------------------------------------------------
+AC_ARG_WITH(libiec16022,
+ [AS_HELP_STRING([--without-libiec16022],[build without IEC 16022 support])])
+have_libiec16022=no
+if test "x$with_libiec16022" != xno; then
+ PKG_CHECK_MODULES(LIBIEC16022, libiec16022 >= $LIBIEC16022_REQUIRED,
+ [have_libiec16022=yes], [have_libiec16022=no])
+fi
+
+if test "x$have_libiec16022" = "xyes"; then
+ AC_DEFINE(HAVE_LIBIEC16022,1,[Define to 1 for IEC 16022 support])
+ LIBIEC16022_VALAFLAGS="-D HAVE_LIBIEC16022"
+ AC_SUBST(LIBIEC16022_VALAFLAGS)
+ AC_SUBST(LIBIEC16022_CFLAGS)
+ AC_SUBST(LIBIEC16022_LIBS)
+else
+ help_libiec16022="(See http://datenfreihafen.org/projects/iec16022.html)"
+fi
+
+
AC_CONFIG_FILES([Makefile
vapi/Makefile
libglabels/Makefile
@@ -179,5 +227,6 @@ Configuration:
Optional barcode backends:
GNU Barcode ............. ${have_libbarcode} ${help_libbarcode}
+ IEC 16022 ............... ${have_libiec16022} ${help_libiec16022}
"
diff --git a/glabels/Makefile.am b/glabels/Makefile.am
index 10d8340..8ddc3ce 100644
--- a/glabels/Makefile.am
+++ b/glabels/Makefile.am
@@ -11,7 +11,9 @@ glabels_4_SOURCES = \
glabels.vala \
barcode_backends.vala \
barcode_backends/gnu_barcode.vala \
+ barcode_backends/iec16022.vala \
barcode_backends/libbarcode.vapi \
+ barcode_backends/libiec16022.vapi \
barcode_menu.vala \
barcode_menu_button.vala \
barcode_menu_item.vala \
@@ -94,6 +96,7 @@ INCLUDES = \
-DDATADIR=\""$(datadir)"\" \
-DGLABELS_BRANCH=\""$(GLABELS_BRANCH)"\" \
$(LIBBARCODE_CFLAGS) \
+ $(LIBIEC16022_CFLAGS) \
$(NULL)
VALAFLAGS = \
@@ -109,6 +112,7 @@ VALAFLAGS = \
--pkg libglabels-4 \
--pkg libglbarcode-4 \
$(LIBBARCODE_VALAFLAGS) \
+ $(LIBIEC16022_VALAFLAGS) \
$(NULL)
@@ -117,6 +121,7 @@ glabels_4_LDADD = \
-L../libglbarcode -lglbarcode-4.0 \
$(GLABELS_LIBS) \
$(LIBBARCODE_LIBS) \
+ $(LIBIEC16022_LIBS) \
$(NULL)
diff --git a/glabels/barcode_backends.vala b/glabels/barcode_backends.vala
index d0d5367..7c3ed98 100644
--- a/glabels/barcode_backends.vala
+++ b/glabels/barcode_backends.vala
@@ -396,6 +396,8 @@ namespace glabels
register_backend( "iec16022", _("IEC16022") );
+ glbarcode.Factory.register_type( "iec16022:IEC16022", typeof(BackendIec16022.Datamatrix) );
+
register_style( "iec16022:IEC16022", "iec16022", _("DataMatrix"),
false, false, true, false, "12345678", true, 8 );
diff --git a/glabels/barcode_backends/iec16022.vala b/glabels/barcode_backends/iec16022.vala
new file mode 100644
index 0000000..1ebf9a8
--- /dev/null
+++ b/glabels/barcode_backends/iec16022.vala
@@ -0,0 +1,140 @@
+/* iec16022.vala
+ *
+ * Copyright (C) 2012 Jim Evins <evins snaught com>
+ *
+ * This file is part of libglbarcode.
+ *
+ * libglabels is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libglabels is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libglabels. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#if HAVE_LIBIEC16022
+
+using GLib;
+using glbarcode.Constants;
+
+namespace glabels
+{
+
+ namespace BackendIec16022
+ {
+
+ /**
+ * Datamatrix Barcode
+ */
+ public class Datamatrix : glbarcode.Barcode
+ {
+
+ private const double MIN_PIXEL_SIZE = 1.0;
+
+
+ /**
+ * Datamatrix Barcode data validation method
+ */
+ protected override bool validate( string data )
+ {
+ if ( (data.length == 0) || (data.length > iec16022.MAXBARCODE ) )
+ {
+ return false;
+ }
+
+ for ( int i = 0; i < data.length; i++ )
+ {
+ if ( (data[i] & 0x80) != 0 )
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Datamatrix Barcode encoding method
+ */
+ protected override string encode( string data )
+ {
+ return ""; /* Actual encoding done in vectorize. */
+ }
+
+
+ /**
+ * Datamatrix Barcode vectorization method
+ */
+ protected override void vectorize( string coded_data, string data, string text )
+ {
+ /*
+ * First encode using IEC16022 Barcode library.
+ */
+ int i_width = 0;
+ int i_height = 0;
+
+ char[] grid = iec16022.ecc200( ref i_width, ref i_height, null,
+ data.length, data,
+ null, null, null );
+
+ /*
+ * Now do the actual vectorization.
+ */
+
+ /* Treat requested size as a bounding box, scale to maintain aspect
+ * ratio while fitting it in this bounding box. */
+ double aspect_ratio = (double)i_height / (double)i_width;
+ if ( h > w*aspect_ratio )
+ {
+ h = w * aspect_ratio;
+ }
+ else
+ {
+ w = h / aspect_ratio;
+ }
+
+ /* Now determine pixel size. */
+ double pixel_size = w / i_width;
+ if ( pixel_size < MIN_PIXEL_SIZE )
+ {
+ pixel_size = MIN_PIXEL_SIZE;
+ }
+
+ /* Now traverse the code string and create a list of boxes */
+ for ( int iy = i_height-1, i = 0; iy >= 0; iy-- )
+ {
+
+ for ( int ix = 0; ix < i_width; ix++, i++ )
+ {
+
+ if ( grid[i] != 0 )
+ {
+ add_box( ix*pixel_size, iy*pixel_size, pixel_size, pixel_size );
+ }
+
+ }
+
+ }
+
+ /* Fill in other info */
+ w = i_width * pixel_size;
+ h = i_height * pixel_size;
+
+ }
+
+
+ }
+
+ }
+
+}
+
+#endif
diff --git a/glabels/barcode_backends/libiec16022.vapi b/glabels/barcode_backends/libiec16022.vapi
new file mode 100644
index 0000000..35a869a
--- /dev/null
+++ b/glabels/barcode_backends/libiec16022.vapi
@@ -0,0 +1,21 @@
+
+/*
+ * Minimal VAPI file for LIBIEC16022 Barcode library.
+ */
+
+#if HAVE_LIBIEC16022
+
+namespace iec16022
+{
+
+ [CCode (cheader_filename = "iec16022ecc200.h", cname = "iec16022ecc200", array_length = false)]
+ public char[] ecc200( ref int iw, ref int ih, char** encoding,
+ int len, string data,
+ int* lenp, int* maxp, int* eccp );
+
+ [CCode (cheader_filename = "iec16022ecc200.h", cname = "MAXBARCODE")]
+ public const int MAXBARCODE;
+
+}
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]