]> git.sur5r.net Git - glabels/blob - libglbarcode/lgl-barcode.h
Imported Upstream version 3.0.0
[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 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 #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 /**
34  * lglBarcode:
35  *  @width:    Width of barcode bounding box (points)
36  *  @height:   Height of barcode bounding box (points)
37  *  @shapes:   List of #lglBarcodeShape drawing primitives
38  *
39  * This structure contains the libglbarcode intermediate barcode format.  This
40  * structure contains a simple vectorized representation of the barcode.  This
41  * vectorized representation is easy to interpret by a rendering backend for
42  * either vector or raster formats.  A simple API is provided for constructing
43  * barcodes in this format.
44  *
45  */
46 typedef struct {
47
48         gdouble  width;
49         gdouble  height;
50
51         GList   *shapes;    /* List of lglBarcodeShape drawing primitives */
52
53 } lglBarcode;
54
55
56 /********************************/
57 /* Barcode Construction.        */
58 /********************************/
59
60 lglBarcode      *lgl_barcode_new              (void);
61
62 void             lgl_barcode_free             (lglBarcode     *bc);
63
64 void             lgl_barcode_add_line         (lglBarcode     *bc,
65                                                gdouble         x,
66                                                gdouble         y,
67                                                gdouble         length,
68                                                gdouble         width);
69
70 void             lgl_barcode_add_box          (lglBarcode     *bc,
71                                                gdouble         x,
72                                                gdouble         y,
73                                                gdouble         width,
74                                                gdouble         height);
75
76 void             lgl_barcode_add_char         (lglBarcode     *bc,
77                                                gdouble         x,
78                                                gdouble         y,
79                                                gdouble         fsize,
80                                                gchar           c);
81
82 void             lgl_barcode_add_string       (lglBarcode     *bc,
83                                                gdouble         x,
84                                                gdouble         y,
85                                                gdouble         fsize,
86                                                gchar          *string,
87                                                gsize           length);
88
89 void             lgl_barcode_add_ring         (lglBarcode     *bc,
90                                                gdouble         x,
91                                                gdouble         y,
92                                                gdouble         radius,
93                                                gdouble         line_width);
94
95 void             lgl_barcode_add_hexagon      (lglBarcode     *bc,
96                                                gdouble         x,
97                                                gdouble         y,
98                                                gdouble         height);
99
100 /*******************************/
101 /* Barcode Drawing Primitives. */
102 /*******************************/
103
104 typedef enum {
105         LGL_BARCODE_SHAPE_LINE,
106         LGL_BARCODE_SHAPE_BOX,
107         LGL_BARCODE_SHAPE_CHAR,
108         LGL_BARCODE_SHAPE_STRING,
109         LGL_BARCODE_SHAPE_RING,
110         LGL_BARCODE_SHAPE_HEXAGON
111 } lglBarcodeShapeType;
112
113
114 typedef struct {
115
116         /* Begin Common Fields */
117         lglBarcodeShapeType  type;
118         gdouble              x;
119         gdouble              y;
120         /* End Common Fields */
121
122 } lglBarcodeShapeAny;
123
124
125 /**
126  * lglBarcodeShapeLine:
127  * @type:   Always %LGL_BARCODE_SHAPE_LINE
128  * @x:      x coordinate of top of line
129  * @y:      y coordinate of top of line
130  * @length: Length of line
131  * @width:  Width of line
132  *
133  * A vertical line drawing primitive.
134  *
135  *<programlisting>
136  *
137  * @ =  origin (x,y) from top left corner of barcode
138  *
139  *              +--@--+
140  *              |     |
141  *              |     |
142  *              |     |
143  *              |     | length
144  *              |     |
145  *              |     |
146  *              |     |
147  *              +-----+
148  *               width
149  *
150  *</programlisting>
151  *
152  * All units are in points ( 1 point = 1/72 inch ).
153  */
154 typedef struct {
155
156         /* Begin Common Fields */
157         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_LINE. */
158         gdouble              x;
159         gdouble              y;
160         /* End Common Fields */
161
162         gdouble              length;
163         gdouble              width;
164
165 } lglBarcodeShapeLine;
166
167
168 /**
169  * lglBarcodeShapeBox:
170  * @type:   Always %LGL_BARCODE_SHAPE_BOX
171  * @x:      x coordinate of top left corner of box
172  * @y:      y coordinate of top left corner of box
173  * @width:  Width of box
174  * @height: Height of box
175  *
176  * A solid box drawing primitive.
177  *
178  *<programlisting>
179  *
180  * @ =  origin (x,y) from top left corner of barcode
181  *
182  *              @---------+
183  *              |         |
184  *              |         |
185  *              |         |
186  *              |         | height
187  *              |         |
188  *              |         |
189  *              |         |
190  *              +---------+
191  *                 width
192  *
193  *</programlisting>
194  *
195  * All units are in points ( 1 point = 1/72 inch ).
196  */
197 typedef struct {
198
199         /* Begin Common Fields */
200         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_BOX. */
201         gdouble              x;
202         gdouble              y;
203         /* End Common Fields */
204
205         gdouble              width;
206         gdouble              height;
207
208 } lglBarcodeShapeBox;
209
210
211 /**
212  * lglBarcodeShapeChar:
213  * @type:   Always %LGL_BARCODE_SHAPE_CHAR
214  * @x:      x coordinate of left baseline of character
215  * @y:      y coordinate of left baseline of character
216  * @fsize:  Font size
217  * @c:      Character to add
218  *
219  * An single byte character drawing primitive.
220  *
221  *<programlisting>
222  *
223  * @ =  origin (x,y) from top left corner of barcode
224  *
225  *              ____ ------------
226  *             /    \           ^
227  *            /  /\  \          |
228  *           /  /__\  \         |
229  *          /  ______  \        | ~fsize
230  *         /  /      \  \       |
231  *        /__/        \__\      |
232  *                              v
233  *       @ ----------------------
234  *
235  *</programlisting>
236  *
237  * All units are in points ( 1 point = 1/72 inch ).
238  */
239 typedef struct {
240
241         /* Begin Common Fields */
242         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_CHAR. */
243         gdouble              x;
244         gdouble              y;
245         /* End Common Fields */
246
247         gdouble              fsize;
248         gchar                c;
249
250 } lglBarcodeShapeChar;
251
252
253 /**
254  * lglBarcodeShapeString:
255  * @type:   Always %LGL_BARCODE_SHAPE_STRING
256  * @x:      x coordinate of horizontal center of baseline of string
257  * @y:      y coordinate of horizontal center of baseline of string
258  * @fsize:  Font size
259  * @string: String to add
260  * @length: Number of bytes in string
261  *
262  * A character string drawing primitive.
263  *
264  *<programlisting>
265  *
266  * @ =  origin (x,y) from top left corner of barcode
267  *
268  *              ____        _  ------------------
269  *             /    \      | |                  ^
270  *            /  /\  \     | |                  |
271  *           /  /__\  \    | |___     ____      |
272  *          /  ______  \   | ._  \   /  __|     | ~fsize
273  *         /  /      \  \  | |_)  | |  (__      |
274  *        /__/        \__\ |_.___/   \____|     |
275  *                                              v
276  *                           @ ------------------
277  *                           x = horizontal center
278  *
279  *</programlisting>
280  *
281  * All units are in points ( 1 point = 1/72 inch ).
282  */
283 typedef struct {
284
285         /* Begin Common Fields */
286         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_STRING. */
287         gdouble              x;
288         gdouble              y;
289         /* End Common Fields */
290
291         gdouble              fsize;
292         gchar               *string;
293
294 } lglBarcodeShapeString;
295
296
297 /**
298  * lglBarcodeShapeRing:
299  * @type:       Always %LGL_BARCODE_SHAPE_RING
300  * @x:          x coordinate of center of circle
301  * @y:          y coordinate of center of circle
302  * @radius:     Radius of ring (center of line)
303  * @line_width: Width of line
304  *
305  * A ring (an open circle) drawing primitive.
306  *
307  *<programlisting>
308  *
309  * @ = origin (x,y) is centre of circle
310  *
311  *                v  line_width
312  *           _.-""""-._
313  *         .'   ____   `.
314  *        /   .'  ^ `.   \
315  *       |   /        \   |
316  *       |   |    @---|---|------
317  *       |   \        /   |     ^
318  *        \   `.____.'   /      | radius
319  *         `._    ...._.'.......|
320  *            `-....-'
321  *
322  *</programlisting>
323  *
324  * All units are in points ( 1 point = 1/72 inch ).
325  */
326
327 typedef struct {
328
329         /* Begin Common Fields */
330         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_RING. */
331         gdouble              x;
332         gdouble              y;
333         /* End Common Fields */
334
335         gdouble              radius;
336         gdouble              line_width;
337
338 } lglBarcodeShapeRing;
339
340
341 /**
342  * lglBarcodeShapeHexagon:
343  * @type:   Always %LGL_BARCODE_SHAPE_HEXAGON
344  * @x:      x coordinate of top point of hexagon
345  * @y:      y coordinate of top point of hexagon
346  * @height: Height of hexagon
347  *
348  * A solid regular hexagon (oriented with vertexes at top and bottom) drawing primitive.
349  *
350  *<programlisting>
351  *
352  * @ = origin (x,y) is top of hexagon
353  *
354  *                  @ ------------------
355  *              _-"   "-_              ^
356  *          _-"           "-_          |
357  *       +"                   "+       |
358  *       |                     |       |
359  *       |                     |       |
360  *       |                     |       | height
361  *       |                     |       |
362  *       |                     |       |
363  *       +_                   _+       |
364  *         "-_             _-"         |
365  *            "-_       _-"            |
366  *               "-_ _-"               v
367  *                  " ------------------
368  *
369  *</programlisting>
370  *
371  * All units are in points ( 1 point = 1/72 inch ).
372  */
373
374 typedef struct {
375
376         /* Begin Common Fields */
377         lglBarcodeShapeType  type; /* Always LGL_BARCODE_SHAPE_HEXAGON. */
378         gdouble              x;
379         gdouble              y;
380         /* End Common Fields */
381
382         gdouble              height;
383
384 } lglBarcodeShapeHexagon;
385
386
387 typedef union {
388
389         lglBarcodeShapeType    type;
390         lglBarcodeShapeAny     any;
391
392         lglBarcodeShapeLine    line;
393         lglBarcodeShapeBox     box;
394         lglBarcodeShapeChar    bchar;
395         lglBarcodeShapeString  string;
396         lglBarcodeShapeRing    ring;
397         lglBarcodeShapeHexagon hexagon;
398
399 } lglBarcodeShape;
400
401
402 G_END_DECLS
403
404 #endif /* __LGL_BARCODE_H__ */
405
406
407
408 /*
409  * Local Variables:       -- emacs
410  * mode: C                -- emacs
411  * c-basic-offset: 8      -- emacs
412  * tab-width: 8           -- emacs
413  * indent-tabs-mode: nil  -- emacs
414  * End:                   -- emacs
415  */