3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #ifdef HAVE_LIBQRENCODE
25 #include "bc-iec18004.h"
36 /*========================================================*/
37 /* Private macros and constants. */
38 /*========================================================*/
40 #define MIN_PIXEL_SIZE 1.0
43 /*===========================================*/
44 /* Local function prototypes */
45 /*===========================================*/
46 static glBarcode *render_iec18004 (const gchar *grid,
53 /*****************************************************************************/
54 /* Generate intermediate representation of barcode. */
55 /*****************************************************************************/
57 gl_barcode_iec18004_new (const gchar *id,
59 gboolean checksum_flag,
64 gint i_width, i_height;
68 if ( strlen (digits) == 0 )
76 qrcode = QRcode_encodeString ((const char *)digits, 0, QR_ECLEVEL_M,
83 i_width = i_height = qrcode->width;
84 gbc = render_iec18004 ((const gchar *)qrcode->data, i_width, i_height,
87 QRcode_free ( qrcode );
93 /*--------------------------------------------------------------------------
94 * PRIVATE. Render to glBarcode intermediate representation of barcode.
95 *--------------------------------------------------------------------------*/
97 render_iec18004 (const gchar *grid,
105 gdouble aspect_ratio, pixel_size;
107 /* Treat requested size as a bounding box, scale to maintain aspect
108 * ratio while fitting it in this bounding box. */
109 aspect_ratio = (gdouble)i_height / (gdouble)i_width;
110 if ( h > w*aspect_ratio ) {
111 h = w * aspect_ratio;
113 w = h / aspect_ratio;
116 /* Now determine pixel size. */
117 pixel_size = w / i_width;
118 if ( pixel_size < MIN_PIXEL_SIZE )
120 pixel_size = MIN_PIXEL_SIZE;
123 gbc = gl_barcode_new ();
125 /* Now traverse the code string and create a list of boxes */
126 for ( y = 0; y < i_height; y++ )
128 for ( x = 0; x < i_width; x++ )
131 /* Symbol data is represented as an array contains
132 * width*width uchars. Each uchar represents a module
133 * (dot). If the less significant bit of the uchar
134 * is 1, the corresponding module is black. The other
135 * bits are meaningless for us. */
138 gl_barcode_add_box (gbc, x*pixel_size, y*pixel_size, pixel_size, pixel_size);
145 /* Fill in other info */
146 gbc->height = i_height * pixel_size;
147 gbc->width = i_width * pixel_size;
152 #endif /* HAVE_LIBQRENCODE */
157 * Local Variables: -- emacs
159 * c-basic-offset: 8 -- emacs
160 * tab-width: 8 -- emacs
161 * indent-tabs-mode: nil -- emacs