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_LIBIEC16022
25 #include "bc-iec16022.h"
31 #include <iec16022ecc200.h>
36 /*========================================================*/
37 /* Private macros and constants. */
38 /*========================================================*/
39 #define MIN_PIXEL_SIZE 1.0
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
45 static lglBarcode *render_iec16022 (const gchar *grid,
52 /*****************************************************************************/
53 /* Generate intermediate representation of barcode. */
54 /*****************************************************************************/
56 gl_barcode_iec16022_new (const gchar *id,
58 gboolean checksum_flag,
64 gint i_width, i_height;
67 if ( *digits == '\0' )
75 grid = (gchar *)iec16022ecc200 (&i_width, &i_height, NULL,
76 strlen (digits), (unsigned char *)digits,
79 /* now render with our custom back-end,
80 to create appropriate intermdediate format */
81 gbc = render_iec16022 (grid, i_width, i_height, w, h);
88 /*--------------------------------------------------------------------------
89 * PRIVATE. Render to lglBarcode intermediate representation of barcode.
90 *--------------------------------------------------------------------------*/
92 render_iec16022 (const gchar *grid,
100 gdouble aspect_ratio, pixel_size;
102 /* Treat requested size as a bounding box, scale to maintain aspect
103 * ratio while fitting it in this bounding box. */
104 aspect_ratio = (gdouble)i_height / (gdouble)i_width;
105 if ( h > w*aspect_ratio )
107 h = w * aspect_ratio;
111 w = h / aspect_ratio;
114 /* Now determine pixel size. */
115 pixel_size = w / i_width;
116 if ( pixel_size < MIN_PIXEL_SIZE )
118 pixel_size = MIN_PIXEL_SIZE;
121 gbc = lgl_barcode_new ();
123 /* Now traverse the code string and create a list of boxes */
124 for ( y = i_height-1; y >= 0; y-- )
127 for ( x = 0; x < i_width; x++ )
132 lgl_barcode_add_box (gbc, x*pixel_size, y*pixel_size, pixel_size, pixel_size);
139 /* Fill in other info */
140 gbc->height = i_height * pixel_size;
141 gbc->width = i_width * pixel_size;
146 #endif /* HAVE_LIBIEC16022 */
151 * Local Variables: -- emacs
153 * c-basic-offset: 8 -- emacs
154 * tab-width: 8 -- emacs
155 * indent-tabs-mode: nil -- emacs