]> git.sur5r.net Git - glabels/blob - glabels2/libglabels/template.h
2007-10-01 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 _lglTemplate                lglTemplate;
37
38 typedef union  _lglTemplateFrame           lglTemplateFrame;
39 typedef struct _lglTemplateFrameAll        lglTemplateFrameAll;
40 typedef struct _lglTemplateFrameRect       lglTemplateFrameRect;
41 typedef struct _lglTemplateFrameRound      lglTemplateFrameRound;
42 typedef struct _lglTemplateFrameCD         lglTemplateFrameCD;
43
44 typedef struct _lglTemplateLayout          lglTemplateLayout;
45
46 typedef union  _lglTemplateMarkup          lglTemplateMarkup;
47 typedef struct _lglTemplateMarkupMargin    lglTemplateMarkupMargin;
48 typedef struct _lglTemplateMarkupLine      lglTemplateMarkupLine;
49 typedef struct _lglTemplateMarkupCircle    lglTemplateMarkupCircle;
50 typedef struct _lglTemplateMarkupRect      lglTemplateMarkupRect;
51
52 typedef struct _lglTemplateOrigin          lglTemplateOrigin;
53
54 /*
55  *   Top-level Template Structure
56  */
57 struct _lglTemplate {
58
59         gchar               *name;
60         gchar               *description;
61         gchar               *page_size;
62         gdouble              page_width;
63         gdouble              page_height;
64
65         /* List of (gchar *) category ids. */
66         GList               *categories;
67
68         /* List of (lglTemplateFrame *) label frame structures.
69          * Currently glabels only supports a single label frame per
70          * template. */
71         GList               *frames;
72
73         /* List of (gchar *) aliases. */
74         GList               *aliases;
75
76 };
77
78
79 /*
80  *   Possible Frame Shapes
81  */
82 typedef enum {
83         LGL_TEMPLATE_FRAME_SHAPE_RECT,
84         LGL_TEMPLATE_FRAME_SHAPE_ROUND,
85         LGL_TEMPLATE_FRAME_SHAPE_CD,
86 } lglTemplateFrameShape;
87
88
89 /*
90  *   Frame Structure
91  */
92 struct _lglTemplateFrameAll {
93
94         /* Begin Common Fields */
95         lglTemplateFrameShape shape;
96
97         gchar                *id;       /* Id, currently always "0" */
98         GList                *layouts;  /* List of lglTemplateLayouts */
99         GList                *markups;  /* List of lglTemplateMarkups */
100         /* End Common Fields */
101 };
102
103 struct _lglTemplateFrameRect {
104
105         /* Begin Common Fields */
106         lglTemplateFrameShape shape;    /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */
107
108         gchar                *id;       /* Id, currently always "0" */
109         GList                *layouts;  /* List of lglTemplateLayouts */
110         GList                *markups;  /* List of lglTemplateMarkups */
111         /* End Common Fields */
112
113         gdouble               w;        /* Width */
114         gdouble               h;        /* Height */
115         gdouble               r;        /* Corner radius */
116         gdouble               x_waste;  /* Amount of horiz overprint allowed. */
117         gdouble               y_waste;  /* Amount of vert overprint allowed. */
118 };
119
120 struct _lglTemplateFrameRound {
121
122         /* Begin Common Fields */
123         lglTemplateFrameShape shape;    /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */
124
125         gchar                *id;       /* Id, currently always "0" */
126         GList                *layouts;  /* List of lglTemplateLayouts */
127         GList                *markups;  /* List of lglTemplateMarkups */
128         /* End Common Fields */
129
130         gdouble               r;      /* Radius */
131         gdouble               waste;  /* Amount of overprint allowed. */
132 };
133
134 struct _lglTemplateFrameCD {
135
136         /* Begin Common Fields */
137         lglTemplateFrameShape shape;    /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */
138
139         gchar                *id;       /* Id, currently always "0" */
140         GList                *layouts;  /* List of lglTemplateLayouts */
141         GList                *markups;  /* List of lglTemplateMarkups */
142         /* End Common Fields */
143
144         gdouble               r1;     /* Outer radius */
145         gdouble               r2;     /* Inner radius (hole) */
146         gdouble               w;      /* Clip width, business card CDs */
147         gdouble               h;      /* Clip height, business card CDs */
148         gdouble               waste;  /* Amount of overprint allowed. */
149 };
150
151 union _lglTemplateFrame{
152
153         lglTemplateFrameShape shape;
154
155         lglTemplateFrameAll   all;
156         lglTemplateFrameRect  rect;
157         lglTemplateFrameRound round;
158         lglTemplateFrameCD    cd;
159 };
160
161
162 /*
163  *   Label Layout Structure
164  */
165 struct _lglTemplateLayout {
166
167         gint                  nx;  /* Number of labels across */
168         gint                  ny;  /* Number of labels up and down */
169
170         gdouble               x0;  /* Left of grid from left edge of paper */
171         gdouble               y0;  /* Top of grid from top edge of paper */
172
173         gdouble               dx;  /* Horizontal pitch of grid */
174         gdouble               dy;  /* Vertical pitch of grid */
175
176 };
177
178
179 /*
180  * Possible Markup Types
181  */
182 typedef enum {
183         LGL_TEMPLATE_MARKUP_MARGIN,
184         LGL_TEMPLATE_MARKUP_LINE,
185         LGL_TEMPLATE_MARKUP_CIRCLE,
186         LGL_TEMPLATE_MARKUP_RECT,
187 } lglTemplateMarkupType;
188
189
190 /*
191  *   Label Markup Structure (Helpful lines drawn in glabels to help locate objects)
192  */
193 struct _lglTemplateMarkupMargin {
194
195         lglTemplateMarkupType  type;  /* Always LGL_TEMPLATE_MARKUP_MARGIN */
196
197         gdouble                size;  /* Margin size */
198 };
199
200 struct _lglTemplateMarkupLine {
201
202         lglTemplateMarkupType  type;   /* Always LGL_TEMPLATE_MARKUP_LINE */
203
204         gdouble                x1, y1; /* 1st endpoint */
205         gdouble                x2, y2; /* 2nd endpoint */
206 };
207
208 struct _lglTemplateMarkupCircle {
209
210         lglTemplateMarkupType  type;   /* Always LGL_TEMPLATE_MARKUP_CIRCLE */
211
212         gdouble                x0, y0; /* Center of circle */
213         gdouble                r;      /* Radius of circle */
214 };
215
216 struct _lglTemplateMarkupRect {
217
218         lglTemplateMarkupType  type;   /* Always LGL_TEMPLATE_MARKUP_RECT */
219
220         gdouble                x1, y1; /* Upper left corner */
221         gdouble                w, h;   /* Width and height. */
222         gdouble                r;      /* Radius of corners. */
223 };
224
225 union _lglTemplateMarkup {
226
227         lglTemplateMarkupType   type;
228
229         lglTemplateMarkupMargin margin;
230         lglTemplateMarkupLine   line;
231         lglTemplateMarkupCircle circle;
232         lglTemplateMarkupRect   rect;
233 };
234
235
236 /*
237  *  Origin coordinates
238  */
239 struct _lglTemplateOrigin {
240
241         gdouble               x, y; /* Label origin relative to upper 
242                                      * upper left hand corner of paper */
243
244 };
245
246
247
248 /*
249  * Template registration
250  */
251 void                 lgl_template_register              (const lglTemplate    *template);
252
253 /*
254  * Known templates query functions
255  */
256 GList               *lgl_template_get_name_list_unique (const gchar         *page_size,
257                                                         const gchar         *category);
258
259 GList               *lgl_template_get_name_list_all    (const gchar         *page_size,
260                                                         const gchar         *category);
261
262 void                 lgl_template_free_name_list       (GList               *names);
263
264 lglTemplate         *lgl_template_from_name            (const gchar         *name);
265
266
267 /* 
268  * Template query functions
269  */
270 const lglTemplateFrame    *lgl_template_get_first_frame      (const lglTemplate   *template);
271
272 gboolean                   lgl_template_does_page_size_match (const lglTemplate   *template,
273                                                               const gchar         *page_size);
274
275 gboolean                   lgl_template_does_category_match  (const lglTemplate   *template,
276                                                               const gchar         *category);
277
278
279 /*
280  * Frame query functions
281  */
282 void                 lgl_template_frame_get_size       (const lglTemplateFrame    *frame,
283                                                         gdouble                   *w,
284                                                         gdouble                   *h);
285
286 gint                 lgl_template_frame_get_n_labels   (const lglTemplateFrame    *frame);
287
288 lglTemplateOrigin   *lgl_template_frame_get_origins    (const lglTemplateFrame    *frame);
289
290
291 /*
292  * Template Construction
293  */
294 lglTemplate         *lgl_template_new                  (const gchar          *name,
295                                                         const gchar          *description,
296                                                         const gchar          *page_size,
297                                                         gdouble               page_width,
298                                                         gdouble               page_height);
299
300 void                 lgl_template_add_category         (lglTemplate          *template,
301                                                         const gchar          *category);
302
303 void                 lgl_template_add_frame            (lglTemplate          *template,
304                                                         lglTemplateFrame     *frame);
305
306 void                 lgl_template_add_alias            (lglTemplate          *template,
307                                                         const gchar          *alias);
308
309 lglTemplateFrame    *lgl_template_frame_rect_new       (const gchar          *id,
310                                                         gdouble               w,
311                                                         gdouble               h,
312                                                         gdouble               r,
313                                                         gdouble               x_waste,
314                                                         gdouble               y_waste);
315
316 lglTemplateFrame    *lgl_template_frame_round_new      (const gchar          *id,
317                                                         gdouble               r,
318                                                         gdouble               waste);
319
320 lglTemplateFrame    *lgl_template_frame_cd_new         (const gchar          *id,
321                                                         gdouble               r1,
322                                                         gdouble               r2,
323                                                         gdouble               w,
324                                                         gdouble               h,
325                                                         gdouble               waste);
326
327 void                 lgl_template_frame_add_layout     (lglTemplateFrame     *frame,
328                                                         lglTemplateLayout    *layout);
329
330 void                 lgl_template_frame_add_markup     (lglTemplateFrame     *frame,
331                                                         lglTemplateMarkup    *markup);
332
333 lglTemplateLayout   *lgl_template_layout_new           (gint                  nx,
334                                                         gint                  ny,
335                                                         gdouble               x0,
336                                                         gdouble               y0,
337                                                         gdouble               dx,
338                                                         gdouble               dy);
339
340 lglTemplateMarkup   *lgl_template_markup_margin_new    (gdouble               size);
341
342 lglTemplateMarkup   *lgl_template_markup_line_new      (gdouble               x1,
343                                                         gdouble               y1,
344                                                         gdouble               x2,
345                                                         gdouble               y2);
346
347 lglTemplateMarkup   *lgl_template_markup_circle_new    (gdouble               x0,
348                                                         gdouble               y0,
349                                                         gdouble               r);
350
351 lglTemplateMarkup   *lgl_template_markup_rect_new      (gdouble               x1,
352                                                         gdouble               y1,
353                                                         gdouble               w,
354                                                         gdouble               h,
355                                                         gdouble               r);
356
357 lglTemplate         *lgl_template_dup                  (const lglTemplate    *orig_template);
358
359 void                 lgl_template_free                 (lglTemplate          *template);
360
361 lglTemplateFrame    *lgl_template_frame_dup            (const lglTemplateFrame     *orig_frame);
362 void                 lgl_template_frame_free           (lglTemplateFrame           *frame);
363
364 lglTemplateLayout   *lgl_template_layout_dup           (const lglTemplateLayout    *orig_layout);
365 void                 lgl_template_layout_free          (lglTemplateLayout          *layout);
366
367 lglTemplateMarkup   *lgl_template_markup_dup           (const lglTemplateMarkup    *orig_markup);
368 void                 lgl_template_markup_free          (lglTemplateMarkup          *markup);
369
370
371 /*
372  * Debugging functions
373  */
374 void                 lgl_template_print_known_templates (void);
375 void                 lgl_template_print_aliases         (const lglTemplate    *template);
376
377
378 G_END_DECLS
379
380 #endif