1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * cairo_label_path.c: Cairo label path module
8 * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "cairo-label-path.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
46 static void gl_cairo_rect_label_path (cairo_t *cr,
50 static void gl_cairo_round_label_path (cairo_t *cr,
54 static void gl_cairo_cd_label_path (cairo_t *cr,
60 /*--------------------------------------------------------------------------*/
61 /* Create label path */
62 /*--------------------------------------------------------------------------*/
64 gl_cairo_label_path (cairo_t *cr,
69 const glTemplateLabelType *label_type;
71 gl_debug (DEBUG_PATH, "START");
73 label_type = gl_template_get_first_label_type (template);
75 switch (label_type->shape) {
77 case GL_TEMPLATE_SHAPE_RECT:
78 gl_cairo_rect_label_path (cr, template, rotate_flag, waste_flag);
81 case GL_TEMPLATE_SHAPE_ROUND:
82 gl_cairo_round_label_path (cr, template, rotate_flag, waste_flag);
85 case GL_TEMPLATE_SHAPE_CD:
86 gl_cairo_cd_label_path (cr, template, rotate_flag, waste_flag);
90 g_message ("Unknown label style");
94 gl_debug (DEBUG_PATH, "END");
97 /*--------------------------------------------------------------------------*/
98 /* Create rectangular label path */
99 /*--------------------------------------------------------------------------*/
101 gl_cairo_rect_label_path (cairo_t *cr,
102 glTemplate *template,
103 gboolean rotate_flag,
106 const glTemplateLabelType *label_type;
108 gdouble x_waste, y_waste;
110 gl_debug (DEBUG_PATH, "START");
112 label_type = gl_template_get_first_label_type (template);
113 r = label_type->size.rect.r;
120 gl_template_get_label_size (label_type, &h, &w);
123 x_waste = label_type->size.rect.y_waste;
124 y_waste = label_type->size.rect.x_waste;
129 gl_template_get_label_size (label_type, &w, &h);
132 x_waste = label_type->size.rect.x_waste;
133 y_waste = label_type->size.rect.y_waste;
140 cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste);
145 cairo_arc_negative (cr, r-x_waste, r-y_waste, r, 3*G_PI/2, G_PI);
146 cairo_arc_negative (cr, r-x_waste, h-r+y_waste, r, G_PI, G_PI/2);
147 cairo_arc_negative (cr, w-r+x_waste, h-r+y_waste, r, G_PI/2, 0.);
148 cairo_arc_negative (cr, w-r+x_waste, r-y_waste, r, 2*G_PI, 3*G_PI/2);
149 cairo_close_path (cr);
152 gl_debug (DEBUG_PATH, "END");
155 /*--------------------------------------------------------------------------*/
156 /* Create round label path */
157 /*--------------------------------------------------------------------------*/
159 gl_cairo_round_label_path (cairo_t *cr,
160 glTemplate *template,
161 gboolean rotate_flag,
164 const glTemplateLabelType *label_type;
168 gl_debug (DEBUG_PATH, "START");
170 label_type = gl_template_get_first_label_type (template);
174 gl_template_get_label_size (label_type, &h, &w);
178 gl_template_get_label_size (label_type, &w, &h);
183 waste = label_type->size.round.waste;
190 cairo_arc (cr, w/2, h/2, w/2+waste, 0.0, 2*G_PI);
191 cairo_close_path (cr);
193 gl_debug (DEBUG_PATH, "END");
196 /*--------------------------------------------------------------------------*/
197 /* Create cd label path */
198 /*--------------------------------------------------------------------------*/
200 gl_cairo_cd_label_path (cairo_t *cr,
201 glTemplate *template,
202 gboolean rotate_flag,
205 const glTemplateLabelType *label_type;
209 gdouble theta1, theta2;
212 gl_debug (DEBUG_PATH, "START");
214 label_type = gl_template_get_first_label_type (template);
218 gl_template_get_label_size (label_type, &h, &w);
222 gl_template_get_label_size (label_type, &w, &h);
228 r1 = label_type->size.cd.r1;
229 r2 = label_type->size.cd.r2;
233 waste = label_type->size.cd.waste;
241 * Outer path (may be clipped in the case of a business card type CD)
243 theta1 = acos (w / (2.0*r1));
244 theta2 = asin (h / (2.0*r1));
247 cairo_arc (cr, xc, yc, r1+waste, theta1, theta2);
248 cairo_arc (cr, xc, yc, r1+waste, G_PI-theta2, G_PI-theta1);
249 cairo_arc (cr, xc, yc, r1+waste, G_PI+theta1, G_PI+theta2);
250 cairo_arc (cr, xc, yc, r1+waste, 2*G_PI-theta2, 2*G_PI-theta1);
251 cairo_close_path (cr);
257 cairo_new_sub_path (cr);
258 cairo_arc (cr, xc, yc, r2-waste, 0.0, 2*G_PI);
259 cairo_close_path (cr);
261 gl_debug (DEBUG_PATH, "END");