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 suppression)"), 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", "DMTX-GS1", N_("Data Matrix (GS1)"), gl_barcode_zint_new,
273 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
275 { "zint", "DPL", N_("Deutsche Post Leitcode"), gl_barcode_zint_new,
276 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
278 { "zint", "DPI", N_("Deutsche Post Identcode"), gl_barcode_zint_new,
279 TRUE, TRUE, TRUE, FALSE, "12345678901", TRUE, 11},
281 { "zint", "KIX", N_("Dutch Post KIX Code"), gl_barcode_zint_new,
282 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
284 { "zint", "EAN", N_("EAN"), gl_barcode_zint_new,
285 TRUE, TRUE, TRUE, FALSE, "1234567890123", FALSE, 13},
287 { "zint", "GMTX", N_("Grid Matrix"), gl_barcode_zint_new,
288 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
290 { "zint", "GS1-128", N_("GS1-128"), gl_barcode_zint_new,
291 TRUE, TRUE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
293 { "zint", "RSS14", N_("GS1 DataBar-14"), gl_barcode_zint_new,
294 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
296 { "zint", "RSSLTD", "GS1 DataBar-14 Limited", gl_barcode_zint_new,
297 TRUE, TRUE, TRUE, FALSE, "1234567890123", TRUE, 13},
299 { "zint", "RSSEXP", "GS1 DataBar Extended", gl_barcode_zint_new,
300 TRUE, TRUE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
302 { "zint", "RSSS", N_("GS1 DataBar-14 Stacked"), gl_barcode_zint_new,
303 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
305 { "zint", "RSSSO", N_("GS1 DataBar-14 Stacked Omni."), gl_barcode_zint_new,
306 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
308 { "zint", "RSSSE", N_("GS1 DataBar Extended Stacked"), gl_barcode_zint_new,
309 FALSE, FALSE, TRUE, FALSE, "[01]12345678901234", FALSE, 18},
311 { "zint", "HIBC128", N_("HIBC Code 128"), gl_barcode_zint_new,
312 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
314 { "zint", "HIBC39", N_("HIBC Code 39"), gl_barcode_zint_new,
315 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
317 { "zint", "HIBCDM", N_("HIBC Data Matrix"), gl_barcode_zint_new,
318 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
320 { "zint", "HIBCQR", N_("HIBC QR Code"), gl_barcode_zint_new,
321 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
323 { "zint", "HIBCPDF", N_("HIBC PDF417"), gl_barcode_zint_new,
324 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
326 { "zint", "HIBCMPDF", N_("HIBC Micro PDF417"), gl_barcode_zint_new,
327 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
329 { "zint", "HIBCAZ", N_("HIBC Aztec Code"), gl_barcode_zint_new,
330 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
332 { "zint", "I25", N_("Interleaved 2 of 5"), gl_barcode_zint_new,
333 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
335 { "zint", "ISBN", N_("ISBN"), gl_barcode_zint_new,
336 TRUE, TRUE, TRUE, FALSE, "123456789", FALSE, 9},
338 { "zint", "ITF14", N_("ITF-14"), gl_barcode_zint_new,
339 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
341 { "zint", "JAPAN", N_("Japanese Postal"), gl_barcode_zint_new,
342 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
344 { "zint", "KOREA", N_("Korean Postal"), gl_barcode_zint_new,
345 TRUE, TRUE, TRUE, FALSE, "123456", FALSE, 6},
347 { "zint", "LOGM", N_("LOGMARS"), gl_barcode_zint_new,
348 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
350 { "zint", "MAXI", N_("Maxicode"), gl_barcode_zint_new,
351 FALSE, FALSE, FALSE, FALSE, "0000000000", TRUE, 10},
353 { "zint", "MPDF", N_("Micro PDF417"), gl_barcode_zint_new,
354 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
356 { "zint", "MQR", N_("Micro QR Code"), gl_barcode_zint_new,
357 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
359 { "zint", "MSI", N_("MSI Plessey"), gl_barcode_zint_new,
360 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
362 { "zint", "NVE", N_("NVE-18"), gl_barcode_zint_new,
363 TRUE, TRUE, TRUE, FALSE, "12345678901234567", FALSE, 17},
365 { "zint", "PDF", N_("PDF417"), gl_barcode_zint_new,
366 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
368 { "zint", "PDFT", N_("PDF417 Truncated"), gl_barcode_zint_new,
369 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
371 { "zint", "PLAN", N_("PLANET"), gl_barcode_zint_new,
372 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
374 { "zint", "POSTNET", N_("PostNet"), gl_barcode_zint_new,
375 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
377 { "zint", "PHARMA", N_("Pharmacode"), gl_barcode_zint_new,
378 FALSE, FALSE, TRUE, FALSE, "123456", FALSE, 6},
380 { "zint", "PHARMA2", N_("Pharmacode 2-track"), gl_barcode_zint_new,
381 FALSE, FALSE, TRUE, FALSE, "12345678", FALSE, 8},
383 { "zint", "PZN", N_("Pharmazentral Nummer (PZN)"), gl_barcode_zint_new,
384 TRUE, TRUE, TRUE, FALSE, "123456", FALSE, 6},
386 { "zint", "QR", N_("QR Code"), gl_barcode_zint_new,
387 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
389 { "zint", "RM4", N_("Royal Mail 4-State"), gl_barcode_zint_new,
390 FALSE, FALSE, TRUE, FALSE, "0000000000", TRUE, 10},
392 { "zint", "TELE", N_("Telepen"), gl_barcode_zint_new,
393 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
395 { "zint", "TELEX", N_("Telepen Numeric"), gl_barcode_zint_new,
396 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
398 { "zint", "UPC-A", N_("UPC-A"), gl_barcode_zint_new,
399 TRUE, TRUE, TRUE, FALSE, "12345678901", FALSE, 11},
401 { "zint", "UPC-E", N_("UPC-E"), gl_barcode_zint_new,
402 TRUE, TRUE, TRUE, FALSE, "1234567", FALSE, 7},
404 { "zint", "USPS", N_("USPS One Code"), gl_barcode_zint_new,
405 FALSE, FALSE, TRUE, FALSE, "12345678901234567890", TRUE, 20},
407 { "zint", "PLS", N_("UK Plessey"), gl_barcode_zint_new,
408 TRUE, TRUE, TRUE, FALSE, "0000000000", TRUE, 10},
410 #endif /* HAVE_LIBZINT */
412 #ifdef HAVE_LIBIEC16022
414 { "libiec16022", "IEC16022", N_("IEC16022 (DataMatrix)"), gl_barcode_iec16022_new,
415 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
417 #endif /* HAVE_LIBIEC16022 */
419 #ifdef HAVE_LIBQRENCODE
421 { "libqrencode", "IEC18004", N_("IEC18004 (QRCode)"), gl_barcode_iec18004_new,
422 FALSE, FALSE, TRUE, FALSE, "12345678", TRUE, 8},
424 #endif /* HAVE_LIBQRENCODE */
426 { NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE, NULL, FALSE, 0}
431 /*========================================================*/
432 /* Private function prototypes. */
433 /*========================================================*/
435 static gint backend_id_to_index (const gchar *id);
436 static gint backend_name_to_index (const gchar *name);
437 static gint style_id_to_index (const gchar *backend_id,
439 static gint style_name_to_index (const gchar *backend_id,
442 /*---------------------------------------------------------------------------*/
443 /* Convert backend id to index into backends table. */
444 /*---------------------------------------------------------------------------*/
446 backend_id_to_index (const gchar *id)
452 return 0; /* NULL request default. I.e., the first element. */
455 for (i=0; styles[i].id != NULL; i++)
457 if (g_ascii_strcasecmp (id, backends[i].id) == 0)
463 g_message( "Unknown barcode id \"%s\"", id );
468 /*---------------------------------------------------------------------------*/
469 /* Convert backend name to index into backends table. */
470 /*---------------------------------------------------------------------------*/
472 backend_name_to_index (const gchar *name)
478 return 0; /* NULL request default. I.e., the first element. */
481 for (i=0; styles[i].id != NULL; i++)
483 if (strcmp (name, gettext (backends[i].name)) == 0)
489 g_message( "Unknown barcode name \"%s\"", name );
494 /*---------------------------------------------------------------------------*/
495 /* Convert style id to index into styles table. */
496 /*---------------------------------------------------------------------------*/
498 style_id_to_index (const gchar *backend_id,
503 if (backend_id == NULL)
505 return 0; /* NULL request default. I.e., the first element. */
510 /* Search for first element with given backend_id. */
511 for (i=0; styles[i].id != NULL; i++)
513 if (g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0)
518 g_message( "Unknown barcode backend id \"%s\"", backend_id );
522 for (i=0; styles[i].id != NULL; i++)
524 if ((g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0) &&
525 (g_ascii_strcasecmp (id, styles[i].id) == 0))
531 g_message( "Unknown barcode id \"%s\"", id );
536 /*---------------------------------------------------------------------------*/
537 /* Convert style name to index into styles table. */
538 /*---------------------------------------------------------------------------*/
540 style_name_to_index (const gchar *backend_id,
545 if (backend_id == NULL)
547 return 0; /* NULL request default. I.e., the first element. */
552 /* Search for first element with given backend_id. */
553 for (i=0; styles[i].id != NULL; i++)
555 if (g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0)
560 g_message( "Unknown barcode backend id \"%s\"", backend_id );
564 for (i=0; styles[i].id != NULL; i++)
566 if ((g_ascii_strcasecmp (backend_id, styles[i].backend_id) == 0) &&
567 (strcmp (name, gettext (styles[i].name)) == 0))
573 g_message( "Unknown barcode name \"%s\"", name );
578 /*****************************************************************************/
579 /* Get a list of names for configured backends. */
580 /*****************************************************************************/
582 gl_barcode_backends_get_backend_list (void)
587 for (i=0; backends[i].id != NULL; i++)
589 list = g_list_prepend (list, g_strdup (gettext (backends[i].name)));
592 return g_list_reverse (list);
596 /*****************************************************************************/
597 /* Free up a previously allocated list of backend names. */
598 /*****************************************************************************/
600 gl_barcode_backends_free_backend_list (GList *backend_list)
604 for (p=backend_list; p != NULL; p=p->next)
610 g_list_free (backend_list);
614 /*****************************************************************************/
615 /* Convert backend id to name. */
616 /*****************************************************************************/
618 gl_barcode_backends_backend_id_to_name (const gchar *backend_id)
620 return gettext (backends[backend_id_to_index (backend_id)].name);
624 /*****************************************************************************/
625 /* Convert backend name to id. */
626 /*****************************************************************************/
628 gl_barcode_backends_backend_name_to_id (const gchar *backend_name)
630 return backends[backend_name_to_index (backend_name)].id;
634 /*****************************************************************************/
635 /* Test if backend id is valid. */
636 /*****************************************************************************/
638 gl_barcode_backends_is_backend_id_valid (const gchar *backend_id)
642 if (backend_id == NULL)
647 for (i=0; backends[i].id != NULL; i++)
649 if (g_ascii_strcasecmp (backend_id, backends[i].id) == 0)
659 /*****************************************************************************/
660 /* Guess backend id from style id (for backwards compatability). */
661 /*****************************************************************************/
663 gl_barcode_backends_guess_backend_id (const gchar *id)
669 return styles[0].backend_id;
672 for (i=0; styles[i].id != NULL; i++)
674 if (g_ascii_strcasecmp (id, styles[i].id) == 0)
676 return styles[i].backend_id;
680 g_message( "Unknown barcode id \"%s\"", id );
681 return styles[0].backend_id;
685 /*****************************************************************************/
686 /* Get a list of names for valid barcode styles. */
687 /*****************************************************************************/
689 gl_barcode_backends_get_styles_list (const gchar *backend_id)
694 for (i=0; styles[i].id != NULL; i++)
696 if ( g_ascii_strcasecmp (styles[i].backend_id, backend_id) == 0 )
698 list = g_list_prepend (list, g_strdup (gettext (styles[i].name)));
702 return g_list_reverse (list);
706 /*****************************************************************************/
707 /* Free up a previously allocated list of style names. */
708 /*****************************************************************************/
710 gl_barcode_backends_free_styles_list (GList *styles_list)
714 for (p=styles_list; p != NULL; p=p->next)
720 g_list_free (styles_list);
724 /*****************************************************************************/
725 /* Convert style to text. */
726 /*****************************************************************************/
728 gl_barcode_backends_style_id_to_name (const gchar *backend_id,
731 return gettext (styles[style_id_to_index (backend_id, id)].name);
735 /*****************************************************************************/
736 /* Convert name to style. */
737 /*****************************************************************************/
739 gl_barcode_backends_style_name_to_id (const gchar *backend_id,
742 return styles[style_name_to_index (backend_id, name)].id;
746 /*****************************************************************************/
747 /* Return an appropriate set of digits for the given barcode style. */
748 /*****************************************************************************/
750 gl_barcode_backends_style_default_digits (const gchar *backend_id,
756 i = style_id_to_index (backend_id, id);
758 if (styles[i].can_freeform)
760 return g_strnfill (MAX (n,1), '0');
764 return g_strdup (styles[i].default_digits);
769 /*****************************************************************************/
770 /* Query text capabilities. */
771 /*****************************************************************************/
773 gl_barcode_backends_style_can_text (const gchar *backend_id,
776 return styles[style_id_to_index (backend_id, id)].can_text;
781 gl_barcode_backends_style_text_optional (const gchar *backend_id,
784 return styles[style_id_to_index (backend_id, id)].text_optional;
788 /*****************************************************************************/
789 /* Query checksum capabilities. */
790 /*****************************************************************************/
792 gl_barcode_backends_style_can_csum (const gchar *backend_id,
795 return styles[style_id_to_index (backend_id, id)].can_checksum;
800 gl_barcode_backends_style_csum_optional (const gchar *backend_id,
803 return styles[style_id_to_index (backend_id, id)].checksum_optional;
807 /*****************************************************************************/
808 /* Query if freeform input is allowed. */
809 /*****************************************************************************/
811 gl_barcode_backends_style_can_freeform (const gchar *backend_id,
814 return styles[style_id_to_index (backend_id, id)].can_freeform;
818 /*****************************************************************************/
819 /* Query prefered number of digits of input. */
820 /*****************************************************************************/
822 gl_barcode_backends_style_get_prefered_n (const gchar *backend_id,
825 return styles[style_id_to_index (backend_id, id)].prefered_n;
829 /*****************************************************************************/
830 /* Call appropriate barcode backend to create barcode in intermediate format.*/
831 /*****************************************************************************/
833 gl_barcode_backends_new_barcode (const gchar *backend_id,
836 gboolean checksum_flag,
844 g_return_val_if_fail (digits!=NULL, NULL);
846 i = style_id_to_index (backend_id, id);
848 gbc = styles[i].new_barcode (styles[i].id,
861 * Local Variables: -- emacs
863 * c-basic-offset: 8 -- emacs
864 * tab-width: 8 -- emacs
865 * indent-tabs-mode: nil -- emacs