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 lglBarcode *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 ( *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 lglBarcode 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 )
112 h = w * aspect_ratio;
116 w = h / aspect_ratio;
119 /* Now determine pixel size. */
120 pixel_size = w / i_width;
121 if ( pixel_size < MIN_PIXEL_SIZE )
123 pixel_size = MIN_PIXEL_SIZE;
126 gbc = lgl_barcode_new ();
128 /* Now traverse the code string and create a list of boxes */
129 for ( y = 0; y < i_height; y++ )
131 for ( x = 0; x < i_width; x++ )
134 /* Symbol data is represented as an array contains
135 * width*width uchars. Each uchar represents a module
136 * (dot). If the less significant bit of the uchar
137 * is 1, the corresponding module is black. The other
138 * bits are meaningless for us. */
141 lgl_barcode_add_box (gbc, x*pixel_size, y*pixel_size, pixel_size, pixel_size);
148 /* Fill in other info */
149 gbc->height = i_height * pixel_size;
150 gbc->width = i_width * pixel_size;
155 #endif /* HAVE_LIBQRENCODE */
160 * Local Variables: -- emacs
162 * c-basic-offset: 8 -- emacs
163 * tab-width: 8 -- emacs
164 * indent-tabs-mode: nil -- emacs