]> git.sur5r.net Git - glabels/blob - glabels2/libglabels/template.h
2006-09-12 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / libglabels / template.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /*
4  *  (LIBGLABELS) Template library for GLABELS
5  *
6  *  template.h:  template module header file
7  *
8  *  Copyright (C) 2001-2006  Jim Evins <evins@snaught.com>.
9  *
10  *  This file is part of the LIBGLABELS library.
11  *
12  *  This library is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Library General Public
14  *  License as published by the Free Software Foundation; either
15  *  version 2 of the License, or (at your option) any later version.
16  *
17  *  This library is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  *  Library General Public License for more details.
21  *
22  *  You should have received a copy of the GNU Library General Public
23  *  License along with this library; if not, write to the Free
24  *  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  *  MA 02111-1307, USA
26  */
27
28 #ifndef __TEMPLATE_H__
29 #define __TEMPLATE_H__
30
31 #include <glib/gtypes.h>
32 #include <glib/glist.h>
33
34 G_BEGIN_DECLS
35
36 typedef struct _glTemplate          glTemplate;
37 typedef struct _glTemplateLabelType glTemplateLabelType;
38 typedef struct _glTemplateLayout    glTemplateLayout;
39 typedef struct _glTemplateMarkup    glTemplateMarkup;
40 typedef struct _glTemplateOrigin    glTemplateOrigin;
41
42 /*
43  *   Top-level Template Structure
44  */
45 struct _glTemplate {
46
47         gchar               *name;
48         gchar               *description;
49         gchar               *page_size;
50         gdouble              page_width;
51         gdouble              page_height;
52
53         /* List of (gchar *) category ids. */
54         GList               *categories;
55
56         /* List of (glTemplateLabelType *) label type structures.
57          * Currently glabels only supports a single label type per
58          * template. */
59         GList               *label_types;
60
61         /* List of (gchar *) aliases. */
62         GList               *aliases;
63
64 };
65
66
67 /*
68  *   Possible Label Shapes
69  */
70 typedef enum {
71         GL_TEMPLATE_SHAPE_RECT,
72         GL_TEMPLATE_SHAPE_ROUND,
73         GL_TEMPLATE_SHAPE_CD,
74 } glTemplateLabelShape;
75
76
77 /*
78  *   Label Type Structure
79  */
80 struct _glTemplateLabelType{
81
82         gchar                *id;       /* Id, currently always "0" */
83         GList                *layouts;  /* List of glTemplateLayouts */
84         GList                *markups;  /* List of glTemplateMarkups */
85
86         glTemplateLabelShape  shape;
87
88         union {
89
90                 struct {
91                         gdouble        w;        /* Width */
92                         gdouble        h;        /* Height */
93                         gdouble        r;        /* Corner radius */
94                         gdouble        x_waste;  /* Amount of horiz overprint allowed. */
95                         gdouble        y_waste;  /* Amount of vert overprint allowed. */
96                 } rect;
97
98                 struct {
99                         gdouble        r;      /* Radius */
100                         gdouble        waste;  /* Amount of overprint allowed. */
101
102                 } round;
103
104                 struct {
105                         gdouble        r1;     /* Outer radius */
106                         gdouble        r2;     /* Inner radius (hole) */
107                         gdouble        w;      /* Clip width, business card CDs */
108                         gdouble        h;      /* Clip height, business card CDs */
109                         gdouble        waste;  /* Amount of overprint allowed. */
110                 } cd;
111
112         } size;
113
114 };
115
116
117 /*
118  *   Label Layout Structure
119  */
120 struct _glTemplateLayout {
121
122         gint                  nx;  /* Number of labels across */
123         gint                  ny;  /* Number of labels up and down */
124
125         gdouble               x0;  /* Left of grid from left edge of paper */
126         gdouble               y0;  /* Top of grid from top edge of paper */
127
128         gdouble               dx;  /* Horizontal pitch of grid */
129         gdouble               dy;  /* Vertical pitch of grid */
130
131 };
132
133
134 /*
135  * Possible Markup Types
136  */
137 typedef enum {
138         GL_TEMPLATE_MARKUP_MARGIN,
139         GL_TEMPLATE_MARKUP_LINE,
140         GL_TEMPLATE_MARKUP_CIRCLE,
141 } glTemplateMarkupType;
142
143
144 /*
145  *   Label Markup Structure (Helpful lines drawn in glabels to help locate objects)
146  */
147 struct _glTemplateMarkup {
148
149         glTemplateMarkupType   type;
150
151         union {
152
153                 struct {
154                         gdouble                size;  /* Margin size */
155                 } margin;
156
157                 struct {
158                         gdouble                x1, y1; /* 1st endpoint */
159                         gdouble                x2, y2; /* 2nd endpoint */
160                 } line;
161
162                 struct {
163                         gdouble                x0, y0; /* Center of circle */
164                         gdouble                r;      /* Radius of circle */
165                 } circle;
166                 
167         } data;
168
169 };
170
171
172 /*
173  *  Origin coordinates
174  */
175 struct _glTemplateOrigin {
176
177         gdouble               x, y; /* Label origin relative to upper 
178                                      * upper left hand corner of paper */
179
180 };
181
182
183
184 /*
185  * Module Initialization
186  */
187 void                 gl_template_init                 (void);
188
189 void                 gl_template_register             (const glTemplate    *template);
190
191 /*
192  * Known templates query functions
193  */
194 GList               *gl_template_get_name_list        (const gchar         *page_size,
195                                                        const gchar         *category);
196
197 void                 gl_template_free_name_list       (GList               *names);
198
199 glTemplate          *gl_template_from_name            (const gchar         *name);
200
201
202 /* 
203  * Template query functions
204  */
205 gchar                     *gl_template_get_name_with_desc   (const glTemplate   *template);
206
207 const glTemplateLabelType *gl_template_get_first_label_type (const glTemplate   *template);
208
209 gboolean                   gl_template_does_page_size_match (const glTemplate   *template,
210                                                              const gchar        *page_size);
211
212 gboolean                   gl_template_does_category_match  (const glTemplate   *template,
213                                                              const gchar        *category);
214
215
216 /*
217  * Label Type query functions
218  */
219 void                 gl_template_get_label_size  (const glTemplateLabelType *label_type,
220                                                   gdouble                   *w,
221                                                   gdouble                   *h);
222
223 gint                 gl_template_get_n_labels    (const glTemplateLabelType *label_type);
224
225 glTemplateOrigin    *gl_template_get_origins     (const glTemplateLabelType *label_type);
226
227
228 /*
229  * Template Construction
230  */
231 glTemplate          *gl_template_new                  (const gchar         *name,
232                                                        const gchar         *description,
233                                                        const gchar         *page_size,
234                                                        gdouble              page_width,
235                                                        gdouble              page_height);
236
237 void                 gl_template_add_category         (glTemplate          *template,
238                                                        const gchar         *category);
239
240 void                 gl_template_add_label_type       (glTemplate          *template,
241                                                        glTemplateLabelType *label_type);
242
243 void                 gl_template_add_alias            (glTemplate          *template,
244                                                        const gchar         *alias);
245
246 glTemplateLabelType *gl_template_rect_label_type_new  (const gchar         *id,
247                                                        gdouble              w,
248                                                        gdouble              h,
249                                                        gdouble              r,
250                                                        gdouble              x_waste,
251                                                        gdouble              y_waste);
252
253 glTemplateLabelType *gl_template_round_label_type_new (const gchar         *id,
254                                                        gdouble              r,
255                                                        gdouble              waste);
256
257 glTemplateLabelType *gl_template_cd_label_type_new    (const gchar         *id,
258                                                        gdouble              r1,
259                                                        gdouble              r2,
260                                                        gdouble              w,
261                                                        gdouble              h,
262                                                        gdouble              waste);
263
264 void                 gl_template_add_layout           (glTemplateLabelType *label_type,
265                                                        glTemplateLayout    *layout);
266
267 void                 gl_template_add_markup           (glTemplateLabelType *label_type,
268                                                        glTemplateMarkup    *markup);
269
270 glTemplateLayout    *gl_template_layout_new           (gint                 nx,
271                                                        gint                 ny,
272                                                        gdouble              x0,
273                                                        gdouble              y0,
274                                                        gdouble              dx,
275                                                        gdouble              dy);
276
277 glTemplateMarkup    *gl_template_markup_margin_new    (gdouble              size);
278
279 glTemplateMarkup    *gl_template_markup_line_new      (gdouble              x1,
280                                                        gdouble              y1,
281                                                        gdouble              x2,
282                                                        gdouble              y2);
283
284 glTemplateMarkup    *gl_template_markup_circle_new    (gdouble              x0,
285                                                        gdouble              y0,
286                                                        gdouble              r);
287
288 glTemplate          *gl_template_dup                  (const glTemplate    *orig);
289
290 void                 gl_template_free                 (glTemplate          *template);
291
292 glTemplateLabelType *gl_template_label_type_dup       (const glTemplateLabelType *orig_ltype);
293 void                 gl_template_label_type_free      (glTemplateLabelType       *ltype);
294
295 glTemplateLayout    *gl_template_layout_dup           (const glTemplateLayout    *orig_layout);
296 void                 gl_template_layout_free          (glTemplateLayout          *layout);
297
298 glTemplateMarkup    *gl_template_markup_dup           (const glTemplateMarkup    *orig_markup);
299 void                 gl_template_markup_free          (glTemplateMarkup          *markup);
300
301
302 /*
303  * Debugging functions
304  */
305 void                 gl_template_print_known_templates (void);
306 void                 gl_template_print_aliases         (const glTemplate    *template);
307
308
309 G_END_DECLS
310
311 #endif