3 * Copyright (C) 2001-2010 Jim Evins <evins@snaught.com>.
5 * This file is part of libglbarcode.
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.
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.
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/>.
23 #include "lgl-barcode.h"
26 /*========================================================*/
27 /* Private macros and constants. */
28 /*========================================================*/
31 /*========================================================*/
33 /*========================================================*/
36 /*========================================================*/
37 /* Private globals. */
38 /*========================================================*/
41 /*========================================================*/
42 /* Private function prototypes. */
43 /*========================================================*/
45 static void lgl_barcode_add_shape (lglBarcode *bc,
46 lglBarcodeShape *shape);
48 static void lgl_barcode_shape_free (lglBarcodeShape *shape);
51 /*****************************************************************************/
55 * Allocate a new #lglBarcode structure.
57 * This function allocates a new #lglBarcode structure.
60 * This function is intended to be used internally by barcode implementations.
61 * Typically an end-user would use lgl_barcode_create() instead.
65 * Returns: A newly allocated #lglBarcode structure. Use lgl_barcode_free() to
70 lgl_barcode_new (void)
72 return g_new0 (lglBarcode, 1);
76 /*****************************************************************************/
79 * @bc: The #lglBarcode structure to free
81 * Free a previously allocated #lglBarcode structure.
85 lgl_barcode_free (lglBarcode *bc)
92 for (p = bc->shapes; p != NULL; p = p->next)
94 lgl_barcode_shape_free ((lglBarcodeShape *)p->data);
96 g_list_free (bc->shapes);
104 /*****************************************************************************/
106 * lgl_barcode_add_line:
107 * @bc: An #lglBarcode structure
108 * @x: x coordinate of top of line
109 * @y: y coordinate of top of line
110 * @length: Length of line
111 * @width: Width of line
113 * Add a vertical line to barcode. Coordinates are relative to top left corner
114 * of barcode. All units are in points ( 1 point = 1/72 inch ).
117 * This function is intended to be used internally by barcode implementations.
122 lgl_barcode_add_line (lglBarcode *bc,
128 lglBarcodeShapeLine *line_shape = g_new0 (lglBarcodeShapeLine, 1);
129 line_shape->type = LGL_BARCODE_SHAPE_LINE;
133 line_shape->length = length;
134 line_shape->width = width;
136 lgl_barcode_add_shape (bc, (lglBarcodeShape *)line_shape);
140 /*****************************************************************************/
142 * lgl_barcode_add_box:
143 * @bc: An #lglBarcode structure
144 * @x: x coordinate of top left corner of box
145 * @y: y coordinate of top left corner of box
146 * @width: Width of box
147 * @height: Height of box
149 * Add a box to barcode. Coordinates are relative to top left corner
150 * of barcode. All units are in points ( 1 point = 1/72 inch ).
153 * This function is intended to be used internally by barcode implementations.
158 lgl_barcode_add_box (lglBarcode *bc,
164 lglBarcodeShapeBox *box_shape = g_new0 (lglBarcodeShapeBox, 1);
165 box_shape->type = LGL_BARCODE_SHAPE_BOX;
169 box_shape->width = width;
170 box_shape->height = height;
172 lgl_barcode_add_shape (bc, (lglBarcodeShape *)box_shape);
176 /*****************************************************************************/
178 * lgl_barcode_add_char:
179 * @bc: An #lglBarcode structure
180 * @x: x coordinate of left baseline of character
181 * @y: y coordinate of left baseline of character
183 * @c: Character to add
185 * Add an ASCII character to barcode. Coordinates are relative to top left corner
186 * of barcode. All units are in points ( 1 point = 1/72 inch ).
189 * This function is intended to be used internally by barcode implementations.
194 lgl_barcode_add_char (lglBarcode *bc,
200 lglBarcodeShapeChar *char_shape = g_new0 (lglBarcodeShapeChar, 1);
201 char_shape->type = LGL_BARCODE_SHAPE_CHAR;
205 char_shape->fsize = fsize;
208 lgl_barcode_add_shape (bc, (lglBarcodeShape *)char_shape);
212 /*****************************************************************************/
214 * lgl_barcode_add_string:
215 * @bc: An #lglBarcode structure
216 * @x: x coordinate of horizontal center of baseline of string
217 * @y: y coordinate of horizontal center of baseline of string
219 * @string: String to add
220 * @length: Number of bytes in string
222 * Add a character string to barcode. Coordinates are relative to top left corner
223 * of barcode. All units are in points ( 1 point = 1/72 inch ).
226 * This function is intended to be used internally by barcode implementations.
231 lgl_barcode_add_string (lglBarcode *bc,
238 lglBarcodeShapeString *string_shape = g_new0 (lglBarcodeShapeString, 1);
239 string_shape->type = LGL_BARCODE_SHAPE_STRING;
243 string_shape->fsize = fsize;
244 string_shape->string = g_strndup(string, length);
246 lgl_barcode_add_shape (bc, (lglBarcodeShape *)string_shape);
249 /*****************************************************************************/
251 * lgl_barcode_add_ring:
252 * @bc: An #lglBarcode structure
253 * @x: x coordinate of center of circle
254 * @y: y coordinate of center of circle
255 * @radius: Radius of ring (center of line)
256 * @line_width: Width of line
258 * Add a ring to barcode. Coordinates are relative to top left corner
259 * of barcode. All units are in points ( 1 point = 1/72 inch ).
262 * This function is intended to be used internally by barcode implementations.
267 lgl_barcode_add_ring (lglBarcode *bc,
273 lglBarcodeShapeRing *ring_shape = g_new0 (lglBarcodeShapeRing, 1);
274 ring_shape->type = LGL_BARCODE_SHAPE_RING;
278 ring_shape->radius = radius;
279 ring_shape->line_width = line_width;
281 lgl_barcode_add_shape (bc, (lglBarcodeShape *)ring_shape);
284 /*****************************************************************************/
286 * lgl_barcode_add_hexagon:
287 * @bc: An #lglBarcode structure
288 * @x: x coordinate of top point of hexagon
289 * @y: y coordinate of top point of hexagon
290 * @height: Height of hexagon
292 * Add a regular hexagon (oriented with vertexes at top and bottom) to barcode.
293 * Coordinates are relative to top left corner of barcode. All units are in
294 * points ( 1 point = 1/72 inch ).
297 * This function is intended to be used internally by barcode implementations.
302 lgl_barcode_add_hexagon (lglBarcode *bc,
307 lglBarcodeShapeHexagon *hexagon_shape = g_new0 (lglBarcodeShapeHexagon, 1);
308 hexagon_shape->type = LGL_BARCODE_SHAPE_HEXAGON;
310 hexagon_shape->x = x;
311 hexagon_shape->y = y;
312 hexagon_shape->height = height;
314 lgl_barcode_add_shape (bc, (lglBarcodeShape *)hexagon_shape);
318 /*****************************************************************************/
319 /* Add shape to barcode. */
320 /*****************************************************************************/
322 lgl_barcode_add_shape (lglBarcode *bc,
323 lglBarcodeShape *shape)
325 g_return_if_fail (bc);
326 g_return_if_fail (shape);
328 bc->shapes = g_list_prepend (bc->shapes, shape);
332 /*****************************************************************************/
333 /* Free a shape primitive. */
334 /*****************************************************************************/
336 lgl_barcode_shape_free (lglBarcodeShape *shape)
341 case LGL_BARCODE_SHAPE_STRING:
342 g_free (shape->string.string);
356 * Local Variables: -- emacs
358 * c-basic-offset: 8 -- emacs
359 * tab-width: 8 -- emacs
360 * indent-tabs-mode: nil -- emacs