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-backends.h"
26 #include <glib/gi18n.h>
28 #include "bc-builtin.h"
29 #include "bc-gnubarcode.h"
31 #include "bc-iec16022.h"
32 #include "bc-iec18004.h"
37 /*========================================================*/
38 /* Private macros and constants. */
39 /*========================================================*/
42 /*========================================================*/
44 /*========================================================*/
46 typedef lglBarcode *(*glBarcodeNewFunc) (const gchar *id,
48 gboolean checksum_flag,
64 glBarcodeNewFunc new_barcode;
66 gboolean text_optional;
67 gboolean can_checksum;
68 gboolean checksum_optional;
69 gchar *default_digits;
70 gboolean can_freeform;
75 /*========================================================*/
76 /* Private globals. */
77 /*========================================================*/
79 static const Backend backends[] = {
81 { "built-in", N_("Built-in") },
82 #ifdef HAVE_LIBBARCODE
83 { "gnu-barcode", "GNU Barcode" },
88 #ifdef HAVE_LIBIEC16022
89 { "libiec16022", "IEC16022" },
91 #ifdef HAVE_LIBQRENCODE
92 { "libqrencode", "QREncode" },
99 static const Style styles[] = {
101 { "built-in", "POSTNET", N_("POSTNET (any)"), gl_barcode_builtin_new,
102 FALSE, FALSE, TRUE, FALSE, "12345-6789-12", FALSE, 11},
104 { "built-in", "POSTNET-5", N_("POSTNET-5 (ZIP only)"), gl_barcode_builtin_new,
105 FALSE, FALSE, TRUE, FALSE, "12345", FALSE, 5},
107 { "built-in", "POSTNET-9", N_("POSTNET-9 (ZIP+4)"), gl_barcode_builtin_new,
108 FALSE, FALSE, TRUE, FALSE, "12345-6789", FALSE, 9},
110 { "built-in", "POSTNET-11", N_("POSTNET-11 (DPBC)"), gl_barcode_builtin_new,
111 FALSE, FALSE, TRUE, FALSE, "12345-6789-12", FALSE, 11},
113 { "built-in", "CEPNET", N_("CEPNET"), gl_barcode_builtin_new,
114 FALSE, FALSE, TRUE, FALSE, "12345-678", FALSE, 8},
116 { "built-in", "ONECODE", N_("One Code"), gl_barcode_builtin_new,
117 FALSE, FALSE, TRUE, FALSE, "12345678901234567890", FALSE, 20},
119 { "built-in", "Code39", N_("Code 39"), gl_barcode_builtin_new,
120 TRUE, TRUE, TRUE, TRUE, "1234567890", TRUE, 10},
122 { "built-in", "Code39Ext", N_("Code 39 Extended"), gl_barcode_builtin_new,
123 TRUE, TRUE, TRUE, TRUE, "1234567890", TRUE, 10},
125 #ifdef HAVE_LIBBARCODE
127 { "gnu-barcode", "EAN", N_("EAN (any)"), gl_barcode_gnubarcode_new,
128 TRUE, TRUE, TRUE, FALSE, "000000000000 00000", FALSE, 17},
130 { "gnu-barcode", "EAN-8", N_("EAN-8"), gl_barcode_gnubarcode_new,
131 TRUE, TRUE, TRUE, FALSE, "0000000", FALSE, 7},
133 { "gnu-barcode", "EAN-8+2", N_("EAN-8 +2"), gl_barcode_gnubarcode_new,
134 TRUE, TRUE, TRUE, FALSE, "0000000 00", FALSE, 9},
136 { "gnu-barcode", "EAN-8+5", N_("EAN-8 +5"), gl_barcode_gnubarcode_new,
137 TRUE, TRUE, TRUE, FALSE, "0000000 00000", FALSE, 12},
139 { "gnu-barcode", "EAN-13", N_("EAN-13"), gl_barcode_gnubarcode_new,
140 TRUE, TRUE, TRUE, FALSE, "000000000000", FALSE, 12},
142 { "gnu-barcode", "EAN-13+2", N_("EAN-13 +2"), gl_barcode_gnubarcode_new,
143 TRUE, TRUE, TRUE, FALSE, "000000000000 00", FALSE, 14},
145 { "gnu-barcode", "EAN-13+5", N_("EAN-13 +5"), gl_barcode_gnubarcode_new,
146 TRUE, TRUE, TRUE, FALSE, "000000000000 00000", FALSE, 17},
148 { "gnu-barcode", "UPC", N_("UPC (UPC-A or UPC-E)"), gl_barcode_gnubarcode_new,
149 TRUE, TRUE, TRUE, FALSE, "00000000000 00000", FALSE, 16},
151 { "gnu-barcode", "UPC-A", N_("UPC-A"), gl_barcode_gnubarcode_new,
152 TRUE, TRUE, TRUE, FALSE, "00000000000", FALSE, 11},
154 { "gnu-barcode", "UPC-A+2", N_("UPC-A +2"), gl_barcode_gnubarcode_new,
155 TRUE, TRUE, TRUE, FALSE, "00000000000 00", FALSE, 13},
157 { "gnu-barcode", "UPC-A+5", N_("UPC-A +5"), gl_barcode_gnubarcode_new,
158 TRUE, TRUE, TRUE, FALSE, "00000000000 00000", FALSE, 16},
160 { "gnu-barcode", "UPC-E", N_("UPC-E"), gl_barcode_gnubarcode_new,
161 TRUE, TRUE, TRUE, FALSE, "000000", FALSE, 6},
163 { "gnu-barcode", "UPC-E+2", N_("UPC-E +2"), gl_barcode_gnubarcode_new,
164 TRUE, TRUE, TRUE, FALSE, "000000 00", FALSE, 8},
166 { "gnu-barcode", "UPC-E+5", N_("UPC-E +5"), gl_barcode_gnubarcode_new,
167 TRUE, TRUE, TRUE, FALSE, "000000 00000", FALSE, 11},
169 { "gnu-barcode", "ISBN", N_("ISBN"), gl_barcode_gnubarcode_new,
170 TRUE, TRUE, TRUE, TRUE, "0-00000-000-0", FALSE, 10},
172 { "gnu-barcode", "ISBN+5", N_("ISBN +5"), gl_barcode_gnubarcode_new,
173 TRUE, TRUE, TRUE, TRUE, "0-00000-000-0 00000", FALSE, 15},
175 { "gnu-barcode", "Code39", N_("Code 39"), gl_barcode_gnubarcode_new,
176 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
178 { "gnu-barcode", "Code128", N_("Code 128"), gl_barcode_gnubarcode_new,
179 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
181 { "gnu-barcode", "Code128C", N_("Code 128C"), gl_barcode_gnubarcode_new,
182 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
184 { "gnu-barcode", "Code128B", N_("Code 128B"), gl_barcode_gnubarcode_new,
185 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
187 { "gnu-barcode", "I25", N_("Interleaved 2 of 5"), gl_barcode_gnubarcode_new,
188 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
190 { "gnu-barcode", "CBR", N_("Codabar"), gl_barcode_gnubarcode_new,
191 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
193 { "gnu-barcode", "MSI", N_("MSI"), gl_barcode_gnubarcode_new,
194 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
196 { "gnu-barcode", "PLS", N_("Plessey"), gl_barcode_gnubarcode_new,
197 TRUE, TRUE, TRUE, TRUE, "0000000000", TRUE, 10},
199 { "gnu-barcode", "Code93", N_("Code 93"), gl_barcode_gnubarcode_new,
200 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
202 #endif /* HAVE_LIBBARCODE */
206 { "zint", "AUSP", N_("Australia Post Standard"), gl_barcode_zint_new,
207 FALSE, FALSE, TRUE, FALSE, "12345678901234567890123", TRUE, 23},
209 { "zint", "AUSRP", N_("Australia Post Reply Paid"), gl_barcode_zint_new,
210 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
212 { "zint", "AUSRT", N_("Australia Post Route Code"), gl_barcode_zint_new,
213 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
215 { "zint", "AUSRD", N_("Australia Post Redirect"), gl_barcode_zint_new,
216 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
218 { "zint", "AZTEC", N_("Aztec Code"), gl_barcode_zint_new,
219 FALSE, FALSE, TRUE, FALSE, "1234567890", TRUE, 10},
221 { "zint", "AZRUN", N_("Aztec Rune"), gl_barcode_zint_new,
222 FALSE, FALSE, TRUE, FALSE, "255", TRUE, 3},
224 { "zint", "CBR", N_("Codabar"), gl_barcode_zint_new,
225 TRUE, TRUE, TRUE, FALSE, "ABCDABCDAB", TRUE, 10},
227 { "zint", "Code1", N_("Code One"), gl_barcode_zint_new,
228 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
230 { "zint", "Code11", N_("Code 11"), gl_barcode_zint_new,
231 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
233 { "zint", "C16K", N_("Code 16K"), gl_barcode_zint_new,
234 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
236 { "zint", "C25M", N_("Code 2 of 5 Matrix"), gl_barcode_zint_new,
237 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
239 { "zint", "C25I", N_("Code 2 of 5 IATA"), gl_barcode_zint_new,
240 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
242 { "zint", "C25DL", N_("Code 2 of 5 Data Logic"), gl_barcode_zint_new,
243 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
245 { "zint", "Code32", N_("Code 32 (Italian Pharmacode)"), gl_barcode_zint_new,
246 TRUE, TRUE, TRUE, FALSE, "12345678", TRUE, 8},
248 { "zint", "Code39", N_("Code 39"), gl_barcode_zint_new,
249 TRUE, TRUE, FALSE, FALSE, "0000000000", TRUE, 10},
251 { "zint", "Code39E", N_("Code 39 Extended"), gl_barcode_zint_new,
252 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
254 { "zint", "Code49", N_("Code 49"), gl_barcode_zint_new,
255 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
257 { "zint", "Code93", N_("Code 93"), gl_barcode_zint_new,
258 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
260 { "zint", "Code128", N_("Code 128"), gl_barcode_zint_new,
261 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
263 { "zint", "Code128B", N_("Code 128 (Mode C supression)"), gl_barcode_zint_new,
264 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
266 { "zint", "DAFT", N_("DAFT Code"), gl_barcode_zint_new,
267 FALSE, FALSE, FALSE, FALSE, "DAFTDAFTDAFTDAFT", TRUE, 16},
269 { "zint", "DMTX", N_("Data Matrix"), gl_barcode_zint_new,
270 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
272 { "zint", "DPL", N_("Deutsche Post Leitcode"), gl_barcode_zint_new,
273 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
275 { "zint", "DPI", N_("Deutsche Post Identcode"), gl_barcode_zint_new,
276 TRUE, TRUE, TRUE, FALSE, "12345678901", TRUE, 11},
278 { "zint", "KIX", N_("Dutch Post KIX Code"), gl_barcode_zint_new,
279 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
281 { "zint", "EAN", N_("EAN"), gl_barcode_zint_new,
282 TRUE, TRUE, TRUE, FALSE, "1234567890123", FALSE, 13},
284 { "zint", "GMTX", N_("Grid Matrix"), gl_barcode_zint_new,
285 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
287 { "zint", "GS1-128", N_("GS1-128"), gl_barcode_zint_new,
288 TRUE, TRUE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
290 { "zint", "RSS14", N_("GS1 DataBar-14"), gl_barcode_zint_new,
291 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
293 { "zint", "RSSLTD", "GS1 DataBar-14 Limited", gl_barcode_zint_new,
294 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
296 { "zint", "RSSEXP", "GS1 DataBar Extended", gl_barcode_zint_new,
297 TRUE, TRUE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
299 { "zint", "RSSS", N_("GS1 DataBar-14 Stacked"), gl_barcode_zint_new,
300 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
302 { "zint", "RSSSO", N_("GS1 DataBar-14 Stacked Omni."), gl_barcode_zint_new,
303 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
305 { "zint", "RSSSE", N_("GS1 DataBar Extended Stacked"), gl_barcode_zint_new,
306 FALSE, FALSE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
308 { "zint", "HIBC128", N_("HIBC Code 128"), gl_barcode_zint_new,
309 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
311 { "zint", "HIBC39", N_("HIBC Code 39"), gl_barcode_zint_new,
312 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
314 { "zint", "HIBCDM", N_("HIBC Data Matrix"), gl_barcode_zint_new,
315 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
317 { "zint", "HIBCQR", N_("HIBC QR Code"), gl_barcode_zint_new,
318 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
320 { "zint", "HIBCPDF", N_("HIBC PDF417"), gl_barcode_zint_new,
321 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
323 { "zint", "HIBCMPDF", N_("HIBC Micro PDF417"), gl_barcode_zint_new,
324 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
326 { "zint", "HIBCAZ", N_("HIBC Aztec Code"), gl_barcode_zint_new,
327 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
329 { "zint", "I25", N_("Interleaved 2 of 5"), gl_barcode_zint_new,
330 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
332 { "zint", "ISBN", N_("ISBN"), gl_barcode_zint_new,
333 TRUE, TRUE, TRUE, FALSE, "123456789", FALSE, 9},
335 { "zint", "ITF14", N_("ITF-14"), gl_barcode_zint_new,
336 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
338 { "zint", "JAPAN", N_("Japanese Postal"), gl_barcode_zint_new,
339 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
341 { "zint", "KOREA", N_("Korean Postal"), gl_barcode_zint_new,
342 TRUE, TRUE, TRUE, FALSE, "123456", FALSE, 6},
344 { "zint", "LOGM", N_("LOGMARS"), gl_barcode_zint_new,
345 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
347 { "zint", "MAXI", N_("Maxicode"), gl_barcode_zint_new,
348 FALSE, FALSE, FALSE, FALSE, "0000000000", TRUE, 10},
350 { "zint", "MPDF", N_("Micro PDF417"), gl_barcode_zint_new,
351 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
353 { "zint", "MQR", N_("Micro QR Code"), gl_barcode_zint_new,
354 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
356 { "zint", "MSI", N_("MSI Plessey"), gl_barcode_zint_new,
357 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
359 { "zint", "NVE", N_("NVE-18"), gl_barcode_zint_new,
360 TRUE, TRUE, TRUE, FALSE, "12345678901234567", FALSE, 17},
362 { "zint", "PDF", N_("PDF417"), gl_barcode_zint_new,
363 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
365 { "zint", "PDFT", N_("PDF417 Truncated"), gl_barcode_zint_new,
366 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
368 { "zint", "PLAN", N_("PLANET"), gl_barcode_zint_new,
369 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
371 { "zint", "POSTNET", N_("PostNet"), gl_barcode_zint_new,
372 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
374 { "zint", "PHARMA", N_("Pharmacode"), gl_barcode_zint_new,
375 FALSE, FALSE, TRUE, FALSE, "123456", FALSE, 6},
377 { "zint", "PHARMA2", N_("Pharmacode 2-track"), gl_barcode_zint_new,
378 FALSE, FALSE, TRUE, FALSE, "12345678", FALSE, 8},
380 { "zint", "PZN", N_("Pharmazentral Nummer (PZN)"), gl_barcode_zint_new,
381 TRUE, TRUE, TRUE, FALSE, "123456", FALSE, 6},
383 { "zint", "QR", N_("QR Code"), gl_barcode_zint_new,
384 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
386 { "zint", "RM4", N_("Royal Mail 4-State"), gl_barcode_zint_new,
387 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
389 { "zint", "TELE", N_("Telepen"), gl_barcode_zint_new,
390 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
392 { "zint", "TELEX", N_("Telepen Numeric"), gl_barcode_zint_new,
393 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
395 { "zint", "UPC-A", N_("UPC-A"), gl_barcode_zint_new,
396 TRUE, TRUE, TRUE, FALSE, "12345678901", FALSE, 11},
398 { "zint", "UPC-E", N_("UPC-E"), gl_barcode_zint_new,
399 TRUE, TRUE, TRUE, FALSE, "1234567", FALSE, 7},
401 { "zint", "USPS", N_("USPS One Code"), gl_barcode_zint_new,
402 FALSE, FALSE, TRUE, FALSE, "12345678901234567890", TRUE, 20},
404 { "zint", "PLS", N_("UK Plessey"), gl_barcode_zint_new,
405 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
407 #endif /* HAVE_LIBZINT */
409 #ifdef HAVE_LIBIEC16022
411 { "libiec16022", "IEC16022", N_("IEC16022 (DataMatrix)"), gl_barcode_iec16022_new,
412 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
414 #endif /* HAVE_LIBIEC16022 */
416 #ifdef HAVE_LIBQRENCODE
418 { "libqrencode", "IEC18004", N_("IEC18004 (QRCode)"), gl_barcode_iec18004_new,
419 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
421 #endif /* HAVE_LIBQRENCODE */
423 { NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL, FALSE, 0}
428 /*========================================================*/
429 /* Private function prototypes. */
430 /*========================================================*/
432 static gint backend_id_to_index (const gchar *id);
433 static gint backend_name_to_index (const gchar *name);
434 static gint style_id_to_index (const gchar *backend_id,
436 static gint style_name_to_index (const gchar *backend_id,
439 /*---------------------------------------------------------------------------*/
440 /* Convert backend id to index into backends table. */
441 /*---------------------------------------------------------------------------*/
443 backend_id_to_index (const gchar *id)
449 return 0; /* NULL request default. I.e., the first element. */
452 for (i=0; styles[i].id != NULL; i++)
454 if (g_ascii_strcasecmp (id, backends[i].id) == 0)
460 g_message( "Unknown barcode id \"%s\"", id );
465 /*---------------------------------------------------------------------------*/
466 /* Convert backend name to index into backends table. */
467 /*---------------------------------------------------------------------------*/
469 backend_name_to_index (const gchar *name)
475 return 0; /* NULL request default. I.e., the first element. */
478 for (i=0; styles[i].id != NULL; i++)
480 if (strcmp (name, gettext (backends[i].name)) == 0)
486 g_message( "Unknown barcode name \"%s\"", name );
491 /*---------------------------------------------------------------------------*/
492 /* Convert style id to index into styles table. */
493 /*---------------------------------------------------------------------------*/
495 style_id_to_index (const gchar *backend_id,
500 if (backend_id == NULL)
502 return 0; /* NULL request default. I.e., the first element. */
507 /* Search for first element with given backend_id. */
508 for (i=0; styles[i].id != NULL; i++)
510 if (g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0)
515 g_message( "Unknown barcode backend id \"%s\"", backend_id );
519 for (i=0; styles[i].id != NULL; i++)
521 if ((g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0) &&
522 (g_ascii_strcasecmp (id, styles[i].id) == 0))
528 g_message( "Unknown barcode id \"%s\"", id );
533 /*---------------------------------------------------------------------------*/
534 /* Convert style name to index into styles table. */
535 /*---------------------------------------------------------------------------*/
537 style_name_to_index (const gchar *backend_id,
542 if (backend_id == NULL)
544 return 0; /* NULL request default. I.e., the first element. */
549 /* Search for first element with given backend_id. */
550 for (i=0; styles[i].id != NULL; i++)
552 if (g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0)
557 g_message( "Unknown barcode backend id \"%s\"", backend_id );
561 for (i=0; styles[i].id != NULL; i++)
563 if ((g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0) &&
564 (strcmp (name, gettext (styles[i].name)) == 0))
570 g_message( "Unknown barcode name \"%s\"", name );
575 /*****************************************************************************/
576 /* Get a list of names for configured backends. */
577 /*****************************************************************************/
579 gl_barcode_backends_get_backend_list (void)
584 for (i=0; backends[i].id != NULL; i++)
586 list = g_list_prepend (list, g_strdup (gettext (backends[i].name)));
589 return g_list_reverse (list);
593 /*****************************************************************************/
594 /* Free up a previously allocated list of backend names. */
595 /*****************************************************************************/
597 gl_barcode_backends_free_backend_list (GList *backend_list)
601 for (p=backend_list; p != NULL; p=p->next)
607 g_list_free (backend_list);
611 /*****************************************************************************/
612 /* Convert backend id to name. */
613 /*****************************************************************************/
615 gl_barcode_backends_backend_id_to_name (const gchar *backend_id)
617 return gettext (backends[backend_id_to_index (backend_id)].name);
621 /*****************************************************************************/
622 /* Convert backend name to id. */
623 /*****************************************************************************/
625 gl_barcode_backends_backend_name_to_id (const gchar *backend_name)
627 return backends[backend_name_to_index (backend_name)].id;
631 /*****************************************************************************/
632 /* Test if backend id is valid. */
633 /*****************************************************************************/
635 gl_barcode_backends_is_backend_id_valid (const gchar *backend_id)
639 if (backend_id == NULL)
644 for (i=0; backends[i].id != NULL; i++)
646 if (g_ascii_strcasecmp (backend_id, backends[i].id) == 0)
656 /*****************************************************************************/
657 /* Guess backend id from style id (for backwards compatability). */
658 /*****************************************************************************/
660 gl_barcode_backends_guess_backend_id (const gchar *id)
666 return styles[0].backend_id;
669 for (i=0; styles[i].id != NULL; i++)
671 if (g_ascii_strcasecmp (id, styles[i].id) == 0)
673 return styles[i].backend_id;
677 g_message( "Unknown barcode id \"%s\"", id );
678 return styles[0].backend_id;
682 /*****************************************************************************/
683 /* Get a list of names for valid barcode styles. */
684 /*****************************************************************************/
686 gl_barcode_backends_get_styles_list (const gchar *backend_id)
691 for (i=0; styles[i].id != NULL; i++)
693 if ( g_ascii_strcasecmp (styles[i].backend_id, backend_id) == 0 )
695 list = g_list_prepend (list, g_strdup (gettext (styles[i].name)));
699 return g_list_reverse (list);
703 /*****************************************************************************/
704 /* Free up a previously allocated list of style names. */
705 /*****************************************************************************/
707 gl_barcode_backends_free_styles_list (GList *styles_list)
711 for (p=styles_list; p != NULL; p=p->next)
717 g_list_free (styles_list);
721 /*****************************************************************************/
722 /* Convert style to text. */
723 /*****************************************************************************/
725 gl_barcode_backends_style_id_to_name (const gchar *backend_id,
728 return gettext (styles[style_id_to_index (backend_id, id)].name);
732 /*****************************************************************************/
733 /* Convert name to style. */
734 /*****************************************************************************/
736 gl_barcode_backends_style_name_to_id (const gchar *backend_id,
739 return styles[style_name_to_index (backend_id, name)].id;
743 /*****************************************************************************/
744 /* Return an appropriate set of digits for the given barcode style. */
745 /*****************************************************************************/
747 gl_barcode_backends_style_default_digits (const gchar *backend_id,
753 i = style_id_to_index (backend_id, id);
755 if (styles[i].can_freeform)
757 return g_strnfill (MAX (n,1), '0');
761 return g_strdup (styles[i].default_digits);
766 /*****************************************************************************/
767 /* Query text capabilities. */
768 /*****************************************************************************/
770 gl_barcode_backends_style_can_text (const gchar *backend_id,
773 return styles[style_id_to_index (backend_id, id)].can_text;
778 gl_barcode_backends_style_text_optional (const gchar *backend_id,
781 return styles[style_id_to_index (backend_id, id)].text_optional;
785 /*****************************************************************************/
786 /* Query checksum capabilities. */
787 /*****************************************************************************/
789 gl_barcode_backends_style_can_csum (const gchar *backend_id,
792 return styles[style_id_to_index (backend_id, id)].can_checksum;
797 gl_barcode_backends_style_csum_optional (const gchar *backend_id,
800 return styles[style_id_to_index (backend_id, id)].checksum_optional;
804 /*****************************************************************************/
805 /* Query if freeform input is allowed. */
806 /*****************************************************************************/
808 gl_barcode_backends_style_can_freeform (const gchar *backend_id,
811 return styles[style_id_to_index (backend_id, id)].can_freeform;
815 /*****************************************************************************/
816 /* Query prefered number of digits of input. */
817 /*****************************************************************************/
819 gl_barcode_backends_style_get_prefered_n (const gchar *backend_id,
822 return styles[style_id_to_index (backend_id, id)].prefered_n;
826 /*****************************************************************************/
827 /* Call appropriate barcode backend to create barcode in intermediate format.*/
828 /*****************************************************************************/
830 gl_barcode_backends_new_barcode (const gchar *backend_id,
833 gboolean checksum_flag,
841 g_return_val_if_fail (digits!=NULL, NULL);
843 i = style_id_to_index (backend_id, id);
845 gbc = styles[i].new_barcode (styles[i].id,
858 * Local Variables: -- emacs
860 * c-basic-offset: 8 -- emacs
861 * tab-width: 8 -- emacs
862 * indent-tabs-mode: nil -- emacs