]> git.sur5r.net Git - glabels/blob - docs/libglbarcode/intro.sgml
Imported Upstream version 3.0.0
[glabels] / docs / libglbarcode / intro.sgml
1 <refentry id="libglbarcode-intro" revision="07 Nov 2010">
2 <refmeta>
3 <refentrytitle role="top_of_page" id="libglbarcode-intro.top_of_page">Introduction</refentrytitle>
4 <manvolnum>3</manvolnum>
5 <refmiscinfo>
6   LIBGLBARCODE-3.0 Library
7 </refmiscinfo>
8 </refmeta>
9
10 <refnamediv>
11 <refname>Introduction</refname>
12 <refpurpose>
13 Introduction to libglbarcode library
14 </refpurpose>
15 </refnamediv>
16
17
18 <refsect1>
19 <title>Overview</title>
20
21 <para>
22 Libglbarcode provides the core barcode functionality for <application>glabels</application>.  It provides
23 an intermediate barcode format, a small set of built-in barcode back-ends, and a cairo renderer.  While
24 libglbarcode does not currently include a large set of built-in barcode back-ends or renderers, its
25 simple architecture would easily support extending its functionality beyond the needs of
26 <application>glabels</application>.
27 </para>
28
29 </refsect1>
30
31
32 <refsect1>
33 <title>Basic Usage</title>
34
35 <programlisting>
36
37 #include &lt;libglbarcode/lgl-barcode-create.h&gt;
38 #include &lt;libglbarcode/lgl-barcode-render-to-cairo.h&gt;
39
40 void
41 example (gchar   *data,
42          cairo_t *cr)
43 {
44         glBarcode *bc;
45
46         bc = lgl_barcode_create (LGL_BARCODE_TYPE_CODE39, TRUE, FALSE, 0, 0, data);
47
48         /* Render to cairo context.  Assume context has appropriate scale and translation.
49          * Scale should be such that world units are points (1 point = 1/72 inch) and that
50          * positive y values go downward.
51          */
52         lgl_barcode_render_to_cairo (bc, cr);
53
54         lgl_free (bc);
55 }
56
57 </programlisting>
58
59
60 </refsect1>
61
62
63 <refsect1>
64 <title>Writing Renderers</title>
65
66 <para>
67 The <link linkend="lglBarcode">lglBarcode</link> structure is independent of
68 barcode type, and consists of a simple list of drawing primitives.
69 A renderer simply traverses this list translating these primitives into native
70 drawing commands for its target format or device.
71 All renderers will follow this simple pattern as illustrated in the example
72 below.
73 </para>
74
75 <programlisting>
76
77 #include &lt;libglbarcode/lgl-barcode.h&gt;
78 #include &lt;xxx.h&gt;
79
80 void
81 lgl_barcode_render_to_xxx (const lglBarcode  *bc)
82 {
83         GList                  *p;
84
85         lglBarcodeShape        *shape;
86         lglBarcodeShapeLine    *line;
87         lglBarcodeShapeBox     *box;
88         lglBarcodeShapeChar    *bchar;
89         lglBarcodeShapeString  *bstring;
90         lglBarcodeShapeRing    *ring;
91         lglBarcodeShapeHexagon *hexagon;
92
93
94         for (p = bc->shapes; p != NULL; p = p->next) {
95
96                 shape = (lglBarcodeShape *)p->data;
97
98                 switch (shape->type)
99                 {
100
101                 case LGL_BARCODE_SHAPE_LINE:
102                         line = (lglBarcodeShapeLine *) shape;
103
104                         xxx_plot_line (line->x, line->y,
105                                        line->x, line->y + line->length,
106                                        line->width );
107                         break;
108
109                 case LGL_BARCODE_SHAPE_BOX:
110                         box = (lglBarcodeShapeBox *) shape;
111
112                         xxx_plot_rectangle (box->x, box->y,
113                                             box->width, box->height);
114                         break;
115
116                 case LGL_BARCODE_SHAPE_CHAR:
117                         bchar = (lglBarcodeShapeChar *) shape;
118
119                         ...
120                         xxx_plot_char (...);
121                         break;
122
123                 case LGL_BARCODE_SHAPE_STRING:
124                         bstring = (lglBarcodeShapeString *) shape;
125
126                         ...
127                         xxx_plot_string (...);
128                         break;
129
130                 case LGL_BARCODE_SHAPE_RING:
131                         ring = (lglBarcodeShapeRing *) shape;
132
133                         ...
134                         xxx_plot_circle (...);
135                         break;
136
137                 case LGL_BARCODE_SHAPE_HEXAGON:
138                         hexagon = (lglBarcodeShapeHexagon *) shape;
139
140                         ...
141                         xxx_plot_polygon (...);
142                         break;
143
144                 default:
145                         g_assert_not_reached ();
146                         break;
147
148                 }
149
150         }
151
152 }
153
154
155 </programlisting>
156
157
158 </refsect1>
159
160
161 </refentry>