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 #include "bc-iec16022.h"
29 #include <iec16022ecc200.h>
34 /*========================================================*/
35 /* Private macros and constants. */
36 /*========================================================*/
37 #define MIN_PIXEL_SIZE 1.0
40 /*===========================================*/
41 /* Local function prototypes */
42 /*===========================================*/
43 static glBarcode *render_iec16022 (const gchar *grid,
50 /*****************************************************************************/
51 /* Generate intermediate representation of barcode. */
52 /*****************************************************************************/
54 gl_barcode_iec16022_new (const gchar *id,
56 gboolean checksum_flag,
62 gint i_width, i_height;
65 if ( strlen (digits) == 0 )
73 grid = (gchar *)iec16022ecc200 (&i_width, &i_height, NULL,
74 strlen (digits), (unsigned char *)digits,
77 /* now render with our custom back-end,
78 to create appropriate intermdediate format */
79 gbc = render_iec16022 (grid, i_width, i_height, w, h);
86 /*--------------------------------------------------------------------------
87 * PRIVATE. Render to glBarcode intermediate representation of barcode.
88 *--------------------------------------------------------------------------*/
90 render_iec16022 (const gchar *grid,
99 gdouble aspect_ratio, pixel_size;
101 /* Treat requested size as a bounding box, scale to maintain aspect
102 * ratio while fitting it in this bounding box. */
103 aspect_ratio = (gdouble)i_height / (gdouble)i_width;
104 if ( h > w*aspect_ratio ) {
105 h = w * aspect_ratio;
107 w = h / aspect_ratio;
110 /* Now determine pixel size. */
111 pixel_size = w / i_width;
112 if ( pixel_size < MIN_PIXEL_SIZE )
114 pixel_size = MIN_PIXEL_SIZE;
117 gbc = g_new0 (glBarcode, 1);
119 /* Now traverse the code string and create a list of boxes */
120 for ( y = i_height-1; y >= 0; y-- )
123 for ( x = 0; x < i_width; x++ )
128 line = g_new0 (glBarcodeLine, 1);
129 line->x = x*pixel_size + pixel_size/2.0;
130 line->y = y*pixel_size;
131 line->length = pixel_size;
132 line->width = pixel_size;
133 gbc->lines = g_list_append (gbc->lines, line);
140 /* Fill in other info */
141 gbc->height = i_height * pixel_size;
142 gbc->width = i_width * pixel_size;
150 * Local Variables: -- emacs
152 * c-basic-offset: 8 -- emacs
153 * tab-width: 8 -- emacs
154 * indent-tabs-mode: nil -- emacs