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,
106 gdouble aspect_ratio, pixel_size;
108 /* Treat requested size as a bounding box, scale to maintain aspect
109 * ratio while fitting it in this bounding box. */
110 aspect_ratio = (gdouble)i_height / (gdouble)i_width;
111 if ( h > w*aspect_ratio ) {
112 h = w * aspect_ratio;
114 w = h / aspect_ratio;
117 /* Now determine pixel size. */
118 pixel_size = w / i_width;
119 if ( pixel_size < MIN_PIXEL_SIZE )
121 pixel_size = MIN_PIXEL_SIZE;
124 gbc = g_new0 (glBarcode, 1);
126 /* Now traverse the code string and create a list of boxes */
127 for ( y = 0; y < i_height; y++ )
129 for ( x = 0; x < i_width; x++ )
132 /* Symbol data is represented as an array contains
133 * width*width uchars. Each uchar represents a module
134 * (dot). If the less significant bit of the uchar
135 * is 1, the corresponding module is black. The other
136 * bits are meaningless for us. */
139 line = g_new0 (glBarcodeLine, 1);
140 line->x = x*pixel_size + pixel_size/2.0;
141 line->y = y*pixel_size;
142 line->length = pixel_size;
143 line->width = pixel_size;
144 gbc->lines = g_list_append (gbc->lines, line);
151 /* Fill in other info */
152 gbc->height = i_height * pixel_size;
153 gbc->width = i_width * pixel_size;
158 #endif /* HAVE_LIBQRENCODE */
163 * Local Variables: -- emacs
165 * c-basic-offset: 8 -- emacs
166 * tab-width: 8 -- emacs
167 * indent-tabs-mode: nil -- emacs