]> git.sur5r.net Git - glabels/blob - libglbarcode/lgl-barcode.h
Refactored core barcode subsystem.
[glabels] / libglbarcode / lgl-barcode.h
1 /*
2  *  lgl-barcode.h
3  *  Copyright (C) 2001-2010  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #ifndef __LGL_BARCODE_H__
22 #define __LGL_BARCODE_H__
23
24 #include <glib.h>
25
26 G_BEGIN_DECLS
27
28
29 /********************************/
30 /* Barcode Intermediate Format. */
31 /********************************/
32
33 typedef struct {
34
35         gdouble  width;
36         gdouble  height;
37
38         GList   *shapes;    /* List of lglBarcodeShape drawing primitives */
39
40 } lglBarcode;
41
42
43 /********************************/
44 /* Barcode Construction.        */
45 /********************************/
46
47 lglBarcode      *lgl_barcode_new              (void);
48
49 void             lgl_barcode_free             (lglBarcode     *bc);
50
51 void             lgl_barcode_add_line         (lglBarcode     *bc,
52                                                gdouble         x,
53                                                gdouble         y,
54                                                gdouble         length,
55                                                gdouble         width);
56
57 void             lgl_barcode_add_box          (lglBarcode     *bc,
58                                                gdouble         x,
59                                                gdouble         y,
60                                                gdouble         width,
61                                                gdouble         height);
62
63 void             lgl_barcode_add_char         (lglBarcode     *bc,
64                                                gdouble         x,
65                                                gdouble         y,
66                                                gdouble         fsize,
67                                                gchar           c);
68
69 void             lgl_barcode_add_string       (lglBarcode     *bc,
70                                                gdouble         x,
71                                                gdouble         y,
72                                                gdouble         fsize,
73                                                gchar          *string,
74                                                gsize           length);
75
76 void             lgl_barcode_add_ring         (lglBarcode     *bc,
77                                                gdouble         x,
78                                                gdouble         y,
79                                                gdouble         radius,
80                                                gdouble         line_width);
81
82 void             lgl_barcode_add_hexagon      (lglBarcode     *bc,
83                                                gdouble         x,
84                                                gdouble         y,
85                                                gdouble         height);
86
87 /*******************************/
88 /* Barcode Drawing Primitives. */
89 /*******************************/
90
91 typedef enum {
92         LGL_BARCODE_SHAPE_LINE,
93         LGL_BARCODE_SHAPE_BOX,
94         LGL_BARCODE_SHAPE_CHAR,
95         LGL_BARCODE_SHAPE_STRING,
96         LGL_BARCODE_SHAPE_RING,
97         LGL_BARCODE_SHAPE_HEXAGON,
98 } lglBarcodeShapeType;
99
100 typedef struct {
101
102         /* Begin Common Fields */
103         lglBarcodeShapeType  type;
104         gdouble              x;
105         gdouble              y;
106         /* End Common Fields */
107
108 } lglBarcodeShapeAny;
109
110 /*
111  * lglBarcodeShapeLine:
112  *
113  * @ =  origin (x,y) from top left corner of barcode
114  *
115  *              +--@--+
116  *              |     |
117  *              |     |
118  *              |     |
119  *              |     | length
120  *              |     |
121  *              |     |
122  *              |     |
123  *              +-----+
124  *               width
125  */
126 typedef struct {
127
128         /* Begin Common Fields */
129         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_LINE. */
130         gdouble              x;
131         gdouble              y;
132         /* End Common Fields */
133
134         gdouble              length;
135         gdouble              width;
136
137 } lglBarcodeShapeLine;
138
139 /*
140  * lglBarcodeShapeBox:
141  *
142  * @ =  origin (x,y) from top left corner of barcode
143  *
144  *              @---------+
145  *              |         |
146  *              |         |
147  *              |         |
148  *              |         | height
149  *              |         |
150  *              |         |
151  *              |         |
152  *              +---------+
153  *                 width
154  */
155 typedef struct {
156
157         /* Begin Common Fields */
158         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_BOX. */
159         gdouble              x;
160         gdouble              y;
161         /* End Common Fields */
162
163         gdouble              width;
164         gdouble              height;
165
166 } lglBarcodeShapeBox;
167
168 /*
169  * lglBarcodeShapeChar:
170  *
171  * @ =  origin (x,y) from top left corner of barcode
172  *
173  *              ____ ------------
174  *             /    \           ^
175  *            /  /\  \          |
176  *           /  /__\  \         |
177  *          /  ______  \        | ~fsize
178  *         /  /      \  \       |
179  *        /__/        \__\      |
180  *                              v
181  *       @ ----------------------
182  */
183 typedef struct {
184
185         /* Begin Common Fields */
186         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_CHAR. */
187         gdouble              x;
188         gdouble              y;
189         /* End Common Fields */
190
191         gdouble              fsize;
192         gchar                c;
193
194 } lglBarcodeShapeChar;
195
196 /*
197  * lglBarcodeShapeString:
198  *
199  * @ =  origin (x,y) from top left corner of barcode
200  *
201  *              ____        _  ------------------
202  *             /    \      | |                  ^
203  *            /  /\  \     | |                  |
204  *           /  /__\  \    | |___     ____      |
205  *          /  ______  \   | ._  \   /  __|     | ~fsize
206  *         /  /      \  \  | |_)  | |  (__      |
207  *        /__/        \__\ |_.___/   \____|     |
208  *                                              v
209  *                           @ ------------------
210  *                           x = horizontal center
211  */
212 typedef struct {
213
214         /* Begin Common Fields */
215         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_STRING. */
216         gdouble              x;
217         gdouble              y;
218         /* End Common Fields */
219
220         gdouble              fsize;
221         gchar               *string;
222
223 } lglBarcodeShapeString;
224
225 /*
226  * lglBarcodeShapeRing:
227  *
228  * @ = origin (x,y) is centre of circle
229  *
230  *                v  line_width
231  *           _.-""""-._
232  *         .'   ____   `.
233  *        /   .'  ^ `.   \
234  *       |   /        \   |
235  *       |   |    @---|---|------
236  *       |   \        /   |     ^
237  *        \   `.____.'   /      | radius
238  *         `._    ...._.'.......|
239  *            `-....-'
240  */
241
242 typedef struct {
243
244         /* Begin Common Fields */
245         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_RING. */
246         gdouble              x;
247         gdouble              y;
248         /* End Common Fields */
249
250         gdouble              radius;
251         gdouble              line_width;
252
253 } lglBarcodeShapeRing;
254
255 /*
256  * lglBarcodeShapeHexagon;
257  *
258  * @ = origin (x,y) is top of hexagon
259  *
260  *                  @ ------------------
261  *              _-"   "-_              ^
262  *          _-"           "-_          |
263  *       +"                   "+       |
264  *       |                     |       |
265  *       |                     |       |
266  *       |                     |       | height
267  *       |                     |       |
268  *       |                     |       |
269  *       +_                   _+       |
270  *         "-_             _-"         |
271  *            "-_       _-"            |
272  *               "-_ _-"               v
273  *                  " ------------------
274  *
275  */
276
277 typedef struct {
278
279         /* Begin Common Fields */
280         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_HEXAGON. */
281         gdouble              x;
282         gdouble              y;
283         /* End Common Fields */
284
285         gdouble              height;
286
287 } lglBarcodeShapeHexagon;
288
289 typedef union {
290
291         lglBarcodeShapeType    type;
292         lglBarcodeShapeAny     any;
293
294         lglBarcodeShapeLine    line;
295         lglBarcodeShapeBox     box;
296         lglBarcodeShapeChar    bchar;
297         lglBarcodeShapeString  string;
298         lglBarcodeShapeRing    ring;
299         lglBarcodeShapeHexagon hexagon;
300
301 } lglBarcodeShape;
302
303
304 G_END_DECLS
305
306 #endif /* __LGL_BARCODE_H__ */
307
308
309
310 /*
311  * Local Variables:       -- emacs
312  * mode: C                -- emacs
313  * c-basic-offset: 8      -- emacs
314  * tab-width: 8           -- emacs
315  * indent-tabs-mode: nil  -- emacs
316  * End:                   -- emacs
317  */