2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * bc.c: GLabels barcode module
6 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "bc-postnet.h"
26 #include "bc-gnubarcode.h"
30 /*****************************************************************************/
31 /* Call appropriate barcode backend to create barcode in intermediate format.*/
32 /*****************************************************************************/
34 gl_barcode_new (glBarcodeStyle style,
43 case GL_BARCODE_STYLE_POSTNET:
44 /* Use the POSTNET backend module */
45 gbc = gl_barcode_postnet_new (digits);
49 /* Use the GNU barcode library backend */
50 gbc = gl_barcode_gnubarcode_new (style, text_flag, scale, digits);
57 /*****************************************************************************/
58 /* Free previously created barcode. */
59 /*****************************************************************************/
61 gl_barcode_free (glBarcode ** gbc)
67 for (p = (*gbc)->lines; p != NULL; p = p->next) {
71 g_list_free ((*gbc)->lines);
74 for (p = (*gbc)->chars; p != NULL; p = p->next) {
78 g_list_free ((*gbc)->chars);
86 /*****************************************************************************/
87 /* Return an appropriate set of digits for the given barcode style. */
88 /*****************************************************************************/
90 gl_barcode_default_digits (glBarcodeStyle style)
94 case GL_BARCODE_STYLE_POSTNET:
95 return g_strdup ("000000000");
96 case GL_BARCODE_STYLE_EAN:
97 return g_strdup ("000000000000 00000");
98 case GL_BARCODE_STYLE_UPC:
99 return g_strdup ("00000000000 00000");
100 case GL_BARCODE_STYLE_ISBN:
101 return g_strdup ("0-00000-000-0 00000");
102 case GL_BARCODE_STYLE_39:
103 case GL_BARCODE_STYLE_128:
104 case GL_BARCODE_STYLE_128C:
105 case GL_BARCODE_STYLE_128B:
106 case GL_BARCODE_STYLE_I25:
107 case GL_BARCODE_STYLE_CBR:
108 case GL_BARCODE_STYLE_MSI:
109 case GL_BARCODE_STYLE_PLS:
110 return g_strdup ("0000000000");
112 return g_strdup ("0");
117 /*****************************************************************************/
118 /* Convert style to text. */
119 /*****************************************************************************/
121 gl_barcode_style_to_text (glBarcodeStyle style)
124 case GL_BARCODE_STYLE_POSTNET:
126 case GL_BARCODE_STYLE_EAN:
128 case GL_BARCODE_STYLE_UPC:
130 case GL_BARCODE_STYLE_ISBN:
132 case GL_BARCODE_STYLE_39:
134 case GL_BARCODE_STYLE_128:
136 case GL_BARCODE_STYLE_128C:
138 case GL_BARCODE_STYLE_128B:
140 case GL_BARCODE_STYLE_I25:
142 case GL_BARCODE_STYLE_CBR:
144 case GL_BARCODE_STYLE_MSI:
146 case GL_BARCODE_STYLE_PLS:
149 g_warning( "Illegal barcode style %d", style );
154 /*****************************************************************************/
155 /* Convert text to style. */
156 /*****************************************************************************/
158 gl_barcode_text_to_style (const gchar * text)
161 if (g_strcasecmp (text, "POSTNET") == 0) {
162 return GL_BARCODE_STYLE_POSTNET;
164 if (g_strcasecmp (text, "EAN") == 0) {
165 return GL_BARCODE_STYLE_EAN;
167 if (g_strcasecmp (text, "UPC") == 0) {
168 return GL_BARCODE_STYLE_UPC;
170 if (g_strcasecmp (text, "ISBN") == 0) {
171 return GL_BARCODE_STYLE_ISBN;
173 if (g_strcasecmp (text, "Code39") == 0) {
174 return GL_BARCODE_STYLE_39;
176 if (g_strcasecmp (text, "Code128") == 0) {
177 return GL_BARCODE_STYLE_128;
179 if (g_strcasecmp (text, "Code128C") == 0) {
180 return GL_BARCODE_STYLE_128C;
182 if (g_strcasecmp (text, "Code128B") == 0) {
183 return GL_BARCODE_STYLE_128B;
185 if (g_strcasecmp (text, "I25") == 0) {
186 return GL_BARCODE_STYLE_I25;
188 if (g_strcasecmp (text, "CBR") == 0) {
189 return GL_BARCODE_STYLE_CBR;
191 if (g_strcasecmp (text, "MSI") == 0) {
192 return GL_BARCODE_STYLE_MSI;
194 if (g_strcasecmp (text, "PLS") == 0) {
195 return GL_BARCODE_STYLE_PLS;
197 g_warning( "Unknown barcode style text \"%s\"", text );
198 return GL_BARCODE_STYLE_POSTNET;