]> git.sur5r.net Git - glabels/blob - libglbarcode/lgl-barcode-create.c
Imported Upstream version 3.0.0
[glabels] / libglbarcode / lgl-barcode-create.c
1 /*
2  *  lgl-barcode-create.c
3  *  Copyright (C) 2010  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of libglbarcode.
6  *
7  *  libglbarcode is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser 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.
11  *
12  *  libglbarcode 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 Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with libglbarcode.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22
23 #include "lgl-barcode-create.h"
24
25 #include "lgl-barcode-postnet.h"
26 #include "lgl-barcode-onecode.h"
27 #include "lgl-barcode-code39.h"
28
29
30 /*===========================================*/
31 /* Private macros and constants.             */
32 /*===========================================*/
33
34
35 /*===========================================*/
36 /* Private types                             */
37 /*===========================================*/
38
39 typedef lglBarcode *(*BarcodeNewFunc) (lglBarcodeType  type,
40                                        gboolean        text_flag,
41                                        gboolean        checksum_flag,
42                                        gdouble         w,
43                                        gdouble         h,
44                                        const gchar    *data);
45
46
47 /*===========================================*/
48 /* Private globals                           */
49 /*===========================================*/
50
51 BarcodeNewFunc create_func[LGL_BARCODE_N_TYPES] = {
52
53         /* LGL_BARCODE_TYPE_POSTNET    */ lgl_barcode_postnet_new,
54         /* LGL_BARCODE_TYPE_POSTNET_5  */ lgl_barcode_postnet_new,
55         /* LGL_BARCODE_TYPE_POSTNET_9  */ lgl_barcode_postnet_new,
56         /* LGL_BARCODE_TYPE_POSTNET_11 */ lgl_barcode_postnet_new,
57         /* LGL_BARCODE_TYPE_CEPNET     */ lgl_barcode_postnet_new,
58
59         /* LGL_BARCODE_TYPE_ONECODE    */ lgl_barcode_onecode_new,
60
61         /* LGL_BARCODE_TYPE_CODE39     */ lgl_barcode_code39_new,
62         /* LGL_BARCODE_TYPE_CODE39_EXT */ lgl_barcode_code39_new,
63 };
64
65 /*===========================================*/
66 /* Local function prototypes                 */
67 /*===========================================*/
68
69
70 /****************************************************************************/
71 /**
72  * lgl_barcode_create:
73  * @type:           Barcode type selection (#lglBarcodeType)
74  * @text_flag:      %TRUE to show text, if supported by barcode type
75  * @checksum_flag:  %TRUE to include checksum, if supported or optional for barcode type
76  * @w:              Suggested width of barcode
77  * @h:              Suggested height of barcode
78  * @data:           Data to encode into barcode
79  *
80  * Create a new barcode structure, encoding @data with selected barcode type and
81  * characteristics.
82  *
83  * Barcode dimensions (@w and @h) are in points ( 1 point = 1/72 inch ).
84  * If either @w or @h are zero, the barcode will be rendered in a nominal size
85  * appropriate for the barcode type and data.  The actual size of the resulting
86  * barcode may also be limited by required tolerances of line sizes and spacing
87  * for the given barcode type. 
88  *
89  *
90  * Returns: A newly allocated #lglBarcode structure.  Use lgl_barcode_free() to
91  *          free it.
92  */
93 lglBarcode *
94 lgl_barcode_create (lglBarcodeType     type,
95                     gboolean           text_flag,
96                     gboolean           checksum_flag,
97                     gdouble            w,
98                     gdouble            h,
99                     const gchar       *data)
100 {
101         if ( (type < 0) || (type >= LGL_BARCODE_N_TYPES) )
102         {
103                 g_message ("Invalid barcode type.");
104                 return NULL;
105         }
106
107         return create_func[type] (type, text_flag, checksum_flag, w, h, data);
108 }
109
110
111
112 /*
113  * Local Variables:       -- emacs
114  * mode: C                -- emacs
115  * c-basic-offset: 8      -- emacs
116  * tab-width: 8           -- emacs
117  * indent-tabs-mode: nil  -- emacs
118  * End:                   -- emacs
119  */