1 /* 2 * lgl-template.h 3 * Copyright (C) 2001-2010 Jim Evins <evins@snaught.com>. 4 * 5 * This file is part of libglabels. 6 * 7 * libglabels 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. 11 * 12 * libglabels 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. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with libglabels. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef __LGL_TEMPLATE_H__ 22 #define __LGL_TEMPLATE_H__ 23 24 #include <glib.h> 25 #include "lgl-units.h" 26 27 G_BEGIN_DECLS 28 29 typedef struct _lglTemplate lglTemplate; 30 31 typedef union _lglTemplateFrame lglTemplateFrame; 32 typedef struct _lglTemplateFrameAll lglTemplateFrameAll; 33 typedef struct _lglTemplateFrameRect lglTemplateFrameRect; 34 typedef struct _lglTemplateFrameEllipse lglTemplateFrameEllipse; 35 typedef struct _lglTemplateFrameRound lglTemplateFrameRound; 36 typedef struct _lglTemplateFrameCD lglTemplateFrameCD; 37 38 typedef struct _lglTemplateLayout lglTemplateLayout; 39 40 typedef union _lglTemplateMarkup lglTemplateMarkup; 41 typedef struct _lglTemplateMarkupMargin lglTemplateMarkupMargin; 42 typedef struct _lglTemplateMarkupLine lglTemplateMarkupLine; 43 typedef struct _lglTemplateMarkupCircle lglTemplateMarkupCircle; 44 typedef struct _lglTemplateMarkupRect lglTemplateMarkupRect; 45 typedef struct _lglTemplateMarkupEllipse lglTemplateMarkupEllipse; 46 47 typedef struct _lglTemplateOrigin lglTemplateOrigin; 48 49 /* 50 * Top-level Template Structure 51 */ 52 struct _lglTemplate { 53 54 gchar *brand; 55 gchar *part; 56 gchar *equiv_part; 57 58 gchar *description; 59 gchar *paper_id; 60 gdouble page_width; 61 gdouble page_height; 62 63 /* Meta information. */ 64 gchar *product_url; /* URL to manufacturer's product website. */ 65 GList *category_ids; /* List of (gchar *) category ids. */ 66 67 /* List of (lglTemplateFrame *) label frame structures. 68 * Currently glabels only supports a single label frame per 69 * template. */ 70 GList *frames; 71 72 }; 73 74 75 /* 76 * Possible Frame Shapes 77 */ 78 typedef enum { 79 LGL_TEMPLATE_FRAME_SHAPE_RECT, 80 LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE, 81 LGL_TEMPLATE_FRAME_SHAPE_ROUND, 82 LGL_TEMPLATE_FRAME_SHAPE_CD 83 } lglTemplateFrameShape; 84 85 86 /* 87 * Frame Structure 88 */ 89 struct _lglTemplateFrameAll { 90 91 /* Begin Common Fields */ 92 lglTemplateFrameShape shape; 93 94 gchar *id; /* Id, currently always "0" */ 95 GList *layouts; /* List of lglTemplateLayouts */ 96 GList *markups; /* List of lglTemplateMarkups */ 97 /* End Common Fields */ 98 }; 99 100 struct _lglTemplateFrameRect { 101 102 /* Begin Common Fields */ 103 lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */ 104 105 gchar *id; /* Id, currently always "0" */ 106 GList *layouts; /* List of lglTemplateLayouts */ 107 GList *markups; /* List of lglTemplateMarkups */ 108 /* End Common Fields */ 109 110 gdouble w; /* Width */ 111 gdouble h; /* Height */ 112 gdouble r; /* Corner radius */ 113 gdouble x_waste; /* Amount of horiz overprint allowed. */ 114 gdouble y_waste; /* Amount of vert overprint allowed. */ 115 }; 116 117 struct _lglTemplateFrameEllipse { 118 119 /* Begin Common Fields */ 120 lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE. */ 121 122 gchar *id; /* Id, currently always "0" */ 123 GList *layouts; /* List of lglTemplateLayouts */ 124 GList *markups; /* List of lglTemplateMarkups */ 125 /* End Common Fields */ 126 127 gdouble w; /* Width */ 128 gdouble h; /* Height */ 129 gdouble waste; /* Amount of overprint allowed. */ 130 }; 131 132 struct _lglTemplateFrameRound { 133 134 /* Begin Common Fields */ 135 lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */ 136 137 gchar *id; /* Id, currently always "0" */ 138 GList *layouts; /* List of lglTemplateLayouts */ 139 GList *markups; /* List of lglTemplateMarkups */ 140 /* End Common Fields */ 141 142 gdouble r; /* Radius */ 143 gdouble waste; /* Amount of overprint allowed. */ 144 }; 145 146 struct _lglTemplateFrameCD { 147 148 /* Begin Common Fields */ 149 lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */ 150 151 gchar *id; /* Id, currently always "0" */ 152 GList *layouts; /* List of lglTemplateLayouts */ 153 GList *markups; /* List of lglTemplateMarkups */ 154 /* End Common Fields */ 155 156 gdouble r1; /* Outer radius */ 157 gdouble r2; /* Inner radius (hole) */ 158 gdouble w; /* Clip width, business card CDs */ 159 gdouble h; /* Clip height, business card CDs */ 160 gdouble waste; /* Amount of overprint allowed. */ 161 }; 162 163 union _lglTemplateFrame{ 164 165 lglTemplateFrameShape shape; 166 167 lglTemplateFrameAll all; 168 lglTemplateFrameRect rect; 169 lglTemplateFrameEllipse ellipse; 170 lglTemplateFrameRound round; 171 lglTemplateFrameCD cd; 172 }; 173 174 175 /* 176 * Label Layout Structure 177 */ 178 struct _lglTemplateLayout { 179 180 gint nx; /* Number of labels across */ 181 gint ny; /* Number of labels up and down */ 182 183 gdouble x0; /* Left of grid from left edge of paper */ 184 gdouble y0; /* Top of grid from top edge of paper */ 185 186 gdouble dx; /* Horizontal pitch of grid */ 187 gdouble dy; /* Vertical pitch of grid */ 188 189 }; 190 191 192 /* 193 * Possible Markup Types 194 */ 195 typedef enum { 196 LGL_TEMPLATE_MARKUP_MARGIN, 197 LGL_TEMPLATE_MARKUP_LINE, 198 LGL_TEMPLATE_MARKUP_CIRCLE, 199 LGL_TEMPLATE_MARKUP_RECT, 200 LGL_TEMPLATE_MARKUP_ELLIPSE 201 } lglTemplateMarkupType; 202 203 204 /* 205 * Label Markup Structure (Helpful lines drawn in glabels to help locate objects) 206 */ 207 struct _lglTemplateMarkupMargin { 208 209 lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_MARGIN */ 210 211 gdouble size; /* Margin size */ 212 }; 213 214 struct _lglTemplateMarkupLine { 215 216 lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_LINE */ 217 218 gdouble x1, y1; /* 1st endpoint */ 219 gdouble x2, y2; /* 2nd endpoint */ 220 }; 221 222 struct _lglTemplateMarkupCircle { 223 224 lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_CIRCLE */ 225 226 gdouble x0, y0; /* Center of circle */ 227 gdouble r; /* Radius of circle */ 228 }; 229 230 struct _lglTemplateMarkupRect { 231 232 lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_RECT */ 233 234 gdouble x1, y1; /* Upper left corner */ 235 gdouble w, h; /* Width and height. */ 236 gdouble r; /* Radius of corners. */ 237 }; 238 239 struct _lglTemplateMarkupEllipse { 240 241 lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_ELLIPSE */ 242 243 gdouble x1, y1; /* Upper left corner */ 244 gdouble w, h; /* Width and height. */ 245 }; 246 247 union _lglTemplateMarkup { 248 249 lglTemplateMarkupType type; 250 251 lglTemplateMarkupMargin margin; 252 lglTemplateMarkupLine line; 253 lglTemplateMarkupCircle circle; 254 lglTemplateMarkupRect rect; 255 lglTemplateMarkupEllipse ellipse; 256 }; 257 258 259 /* 260 * Origin coordinates 261 */ 262 struct _lglTemplateOrigin { 263 264 gdouble x, y; /* Label origin relative to upper 265 * upper left hand corner of paper */ 266 267 }; 268 269 270 271 /* 272 * Template query functions 273 */ 274 gchar *lgl_template_get_name (const lglTemplate *template); 275 276 gboolean lgl_template_do_templates_match (const lglTemplate *template1, 277 const lglTemplate *template2); 278 279 gboolean lgl_template_does_brand_match (const lglTemplate *template, 280 const gchar *brand); 281 282 gboolean lgl_template_does_page_size_match (const lglTemplate *template, 283 const gchar *paper_id); 284 285 gboolean lgl_template_does_category_match (const lglTemplate *template, 286 const gchar *category_id); 287 288 gboolean lgl_template_are_templates_identical (const lglTemplate *template1, 289 const lglTemplate *template2); 290 291 292 293 294 /* 295 * Frame query functions 296 */ 297 void lgl_template_frame_get_size (const lglTemplateFrame *frame, 298 gdouble *w, 299 gdouble *h); 300 301 gint lgl_template_frame_get_n_labels (const lglTemplateFrame *frame); 302 303 lglTemplateOrigin *lgl_template_frame_get_origins (const lglTemplateFrame *frame); 304 305 gchar *lgl_template_frame_get_layout_description (const lglTemplateFrame *frame); 306 307 gchar *lgl_template_frame_get_size_description (const lglTemplateFrame *frame, 308 lglUnits units); 309 310 311 312 313 /* 314 * Template Construction 315 */ 316 lglTemplate *lgl_template_new (const gchar *brand, 317 const gchar *part, 318 const gchar *description, 319 const gchar *paper_id, 320 gdouble page_width, 321 gdouble page_height); 322 323 lglTemplate *lgl_template_new_from_equiv (const gchar *brand, 324 const gchar *part, 325 const gchar *equiv_part); 326 327 void lgl_template_add_category (lglTemplate *template, 328 const gchar *category_id); 329 330 void lgl_template_add_frame (lglTemplate *template, 331 lglTemplateFrame *frame); 332 333 lglTemplateFrame *lgl_template_frame_rect_new (const gchar *id, 334 gdouble w, 335 gdouble h, 336 gdouble r, 337 gdouble x_waste, 338 gdouble y_waste); 339 340 lglTemplateFrame *lgl_template_frame_ellipse_new (const gchar *id, 341 gdouble w, 342 gdouble h, 343 gdouble waste); 344 345 lglTemplateFrame *lgl_template_frame_round_new (const gchar *id, 346 gdouble r, 347 gdouble waste); 348 349 lglTemplateFrame *lgl_template_frame_cd_new (const gchar *id, 350 gdouble r1, 351 gdouble r2, 352 gdouble w, 353 gdouble h, 354 gdouble waste); 355 356 void lgl_template_frame_add_layout (lglTemplateFrame *frame, 357 lglTemplateLayout *layout); 358 359 void lgl_template_frame_add_markup (lglTemplateFrame *frame, 360 lglTemplateMarkup *markup); 361 362 lglTemplateLayout *lgl_template_layout_new (gint nx, 363 gint ny, 364 gdouble x0, 365 gdouble y0, 366 gdouble dx, 367 gdouble dy); 368 369 lglTemplateMarkup *lgl_template_markup_margin_new (gdouble size); 370 371 lglTemplateMarkup *lgl_template_markup_line_new (gdouble x1, 372 gdouble y1, 373 gdouble x2, 374 gdouble y2); 375 376 lglTemplateMarkup *lgl_template_markup_circle_new (gdouble x0, 377 gdouble y0, 378 gdouble r); 379 380 lglTemplateMarkup *lgl_template_markup_rect_new (gdouble x1, 381 gdouble y1, 382 gdouble w, 383 gdouble h, 384 gdouble r); 385 386 lglTemplateMarkup *lgl_template_markup_ellipse_new (gdouble x1, 387 gdouble y1, 388 gdouble w, 389 gdouble h); 390 391 lglTemplate *lgl_template_dup (const lglTemplate *orig_template); 392 393 void lgl_template_free (lglTemplate *template); 394 395 lglTemplateFrame *lgl_template_frame_dup (const lglTemplateFrame *orig_frame); 396 void lgl_template_frame_free (lglTemplateFrame *frame); 397 398 lglTemplateLayout *lgl_template_layout_dup (const lglTemplateLayout *orig_layout); 399 void lgl_template_layout_free (lglTemplateLayout *layout); 400 401 lglTemplateMarkup *lgl_template_markup_dup (const lglTemplateMarkup *orig_markup); 402 void lgl_template_markup_free (lglTemplateMarkup *markup); 403 404 405 /* 406 * Debugging functions. 407 */ 408 void lgl_template_print (const lglTemplate *template); 409 410 411 G_END_DECLS 412 413 #endif /* __LGL_TEMPLATE_H__ */ 414 415 416 417 /* 418 * Local Variables: -- emacs 419 * mode: C -- emacs 420 * c-basic-offset: 8 -- emacs 421 * tab-width: 8 -- emacs 422 * indent-tabs-mode: nil -- emacs 423 * End: -- emacs 424 */ 425