]> git.sur5r.net Git - glabels/blob - src/bc.h
Fix drawing problems with view.c
[glabels] / src / bc.h
1 /*
2  *  bc.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 __BC_H__
22 #define __BC_H__
23
24 #include <glib.h>
25 #include <pango/pango.h>
26
27 G_BEGIN_DECLS
28
29
30 #define GL_BARCODE_FONT_FAMILY      "Sans"
31 #define GL_BARCODE_FONT_WEIGHT      PANGO_WEIGHT_NORMAL
32
33
34 /********************************/
35 /* Barcode Intermediate Format. */
36 /********************************/
37
38 typedef struct {
39
40         gdouble  width;
41         gdouble  height;
42
43         GList   *shapes;    /* List of glBarcodeShape drawing primitives */
44
45 } glBarcode;
46
47
48 glBarcode       *gl_barcode_new              (void);
49
50 void             gl_barcode_free             (glBarcode     **bc);
51
52 void             gl_barcode_add_line         (glBarcode      *bc,
53                                               gdouble         x,
54                                               gdouble         y,
55                                               gdouble         length,
56                                               gdouble         width);
57
58 void             gl_barcode_add_box          (glBarcode      *bc,
59                                               gdouble         x,
60                                               gdouble         y,
61                                               gdouble         width,
62                                               gdouble         height);
63
64 void             gl_barcode_add_char         (glBarcode      *bc,
65                                               gdouble         x,
66                                               gdouble         y,
67                                               gdouble         fsize,
68                                               gchar           c);
69
70 void             gl_barcode_add_string       (glBarcode      *bc,
71                                               gdouble         x,
72                                               gdouble         y,
73                                               gdouble         fsize,
74                                               gchar          *string,
75                                               gsize           length);
76
77 void             gl_barcode_add_ring         (glBarcode      *bc,
78                                               gdouble         x,
79                                               gdouble         y,
80                                               gdouble         radius,
81                                               gdouble         line_width);
82
83 void             gl_barcode_add_hexagon      (glBarcode      *bc,
84                                               gdouble         x,
85                                               gdouble         y);
86
87 /*******************************/
88 /* Barcode Drawing Primitives. */
89 /*******************************/
90
91 typedef enum {
92         GL_BARCODE_SHAPE_LINE,
93         GL_BARCODE_SHAPE_BOX,
94         GL_BARCODE_SHAPE_CHAR,
95         GL_BARCODE_SHAPE_STRING,
96         GL_BARCODE_SHAPE_RING,
97         GL_BARCODE_SHAPE_HEXAGON,
98 } glBarcodeShapeType;
99
100 typedef struct {
101
102         /* Begin Common Fields */
103         glBarcodeShapeType  type;
104         gdouble             x;
105         gdouble             y;
106         /* End Common Fields */
107
108 } glBarcodeShapeAny;
109
110 /*
111  * glBarcodeShapeLine:
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         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_LINE. */
130         gdouble             x;
131         gdouble             y;
132         /* End Common Fields */
133
134         gdouble             length;
135         gdouble             width;
136
137 } glBarcodeShapeLine;
138
139 /*
140  * glBarcodeShapeBox:
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         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_BOX. */
159         gdouble             x;
160         gdouble             y;
161         /* End Common Fields */
162
163         gdouble             width;
164         gdouble             height;
165
166 } glBarcodeShapeBox;
167
168 /*
169  * glBarcodeShapeChar:
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         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_CHAR. */
187         gdouble             x;
188         gdouble             y;
189         /* End Common Fields */
190
191         gdouble             fsize;
192         gchar               c;
193
194 } glBarcodeShapeChar;
195
196 /*
197  * glBarcodeShapeString:
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         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_STRING. */
216         gdouble             x;
217         gdouble             y;
218         /* End Common Fields */
219
220         gdouble             fsize;
221         gchar              *string;
222
223 } glBarcodeShapeString;
224
225 /*
226  * glBarcodeShapeRing:
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         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_RING. */
246         gdouble             x;
247         gdouble             y;
248         /* End Common Fields */
249
250         gdouble             radius;
251         gdouble             line_width;
252
253 } glBarcodeShapeRing;
254
255 /*
256  * glBarcodeShapeHexagon;
257  *
258  * @ = origin (x,y) is top of hexagon
259  *
260  *                  @
261  *              _-"   "-_
262  *          _-"           "-_
263  *       +"                   "+
264  *       |                     |
265  *       |                     |
266  *       |                     |
267  *       |                     |
268  *       |                     |
269  *       +_                   _+
270  *         "-_             _-"
271  *            "-_       _-"
272  *               "-_ _-"
273  *                  "
274  *
275  * NOTE: For Maxicode hexagons height is always 1.02mm, width is always 0.88mm
276  */
277
278 typedef struct {
279
280         /* Begin Common Fields */
281         glBarcodeShapeType  type; /* Always GL_BARCODE_SHAPE_HEXAGON. */
282         gdouble             x;
283         gdouble             y;
284         /* End Common Fields */
285
286 } glBarcodeShapeHexagon;
287
288 typedef union {
289
290         glBarcodeShapeType    type;
291         glBarcodeShapeAny     any;
292
293         glBarcodeShapeLine    line;
294         glBarcodeShapeBox     box;
295         glBarcodeShapeChar    bchar;
296         glBarcodeShapeString  string;
297         glBarcodeShapeRing    ring;
298         glBarcodeShapeHexagon hexagon;
299
300 } glBarcodeShape;
301
302
303 G_END_DECLS
304
305 #endif /* __BC_H__ */
306
307
308
309 /*
310  * Local Variables:       -- emacs
311  * mode: C                -- emacs
312  * c-basic-offset: 8      -- emacs
313  * tab-width: 8           -- emacs
314  * indent-tabs-mode: nil  -- emacs
315  * End:                   -- emacs
316  */