3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU 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.
12 * gLabels 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 General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "cairo-label-path.h"
27 #include "cairo-ellipse-path.h"
32 /*===========================================*/
34 /*===========================================*/
37 /*===========================================*/
39 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
46 static void gl_cairo_rect_label_path (cairo_t *cr,
47 const lglTemplate *template,
50 static void gl_cairo_ellipse_label_path (cairo_t *cr,
51 const lglTemplate *template,
54 static void gl_cairo_round_label_path (cairo_t *cr,
55 const lglTemplate *template,
58 static void gl_cairo_cd_label_path (cairo_t *cr,
59 const lglTemplate *template,
64 /*--------------------------------------------------------------------------*/
65 /* Create label path */
66 /*--------------------------------------------------------------------------*/
68 gl_cairo_label_path (cairo_t *cr,
69 const lglTemplate *template,
73 const lglTemplateFrame *frame;
75 gl_debug (DEBUG_PATH, "START");
77 frame = (lglTemplateFrame *)template->frames->data;
79 switch (frame->shape) {
81 case LGL_TEMPLATE_FRAME_SHAPE_RECT:
82 gl_cairo_rect_label_path (cr, template, rotate_flag, waste_flag);
85 case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
86 gl_cairo_ellipse_label_path (cr, template, rotate_flag, waste_flag);
89 case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
90 gl_cairo_round_label_path (cr, template, rotate_flag, waste_flag);
93 case LGL_TEMPLATE_FRAME_SHAPE_CD:
94 gl_cairo_cd_label_path (cr, template, rotate_flag, waste_flag);
98 g_message ("Unknown label style");
102 gl_debug (DEBUG_PATH, "END");
106 /*--------------------------------------------------------------------------*/
107 /* Create rectangular label path */
108 /*--------------------------------------------------------------------------*/
110 gl_cairo_rect_label_path (cairo_t *cr,
111 const lglTemplate *template,
112 gboolean rotate_flag,
115 const lglTemplateFrame *frame;
117 gdouble x_waste, y_waste;
119 gl_debug (DEBUG_PATH, "START");
121 frame = (lglTemplateFrame *)template->frames->data;
129 lgl_template_frame_get_size (frame, &h, &w);
132 x_waste = frame->rect.y_waste;
133 y_waste = frame->rect.x_waste;
138 lgl_template_frame_get_size (frame, &w, &h);
141 x_waste = frame->rect.x_waste;
142 y_waste = frame->rect.y_waste;
149 cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste);
154 cairo_arc_negative (cr, r-x_waste, r-y_waste, r, 3*G_PI/2, G_PI);
155 cairo_arc_negative (cr, r-x_waste, h-r+y_waste, r, G_PI, G_PI/2);
156 cairo_arc_negative (cr, w-r+x_waste, h-r+y_waste, r, G_PI/2, 0.);
157 cairo_arc_negative (cr, w-r+x_waste, r-y_waste, r, 2*G_PI, 3*G_PI/2);
158 cairo_close_path (cr);
161 gl_debug (DEBUG_PATH, "END");
165 /*--------------------------------------------------------------------------*/
166 /* Create elliptical label path */
167 /*--------------------------------------------------------------------------*/
169 gl_cairo_ellipse_label_path (cairo_t *cr,
170 const lglTemplate *template,
171 gboolean rotate_flag,
174 const lglTemplateFrame *frame;
178 gl_debug (DEBUG_PATH, "START");
180 frame = (lglTemplateFrame *)template->frames->data;
184 lgl_template_frame_get_size (frame, &h, &w);
188 lgl_template_frame_get_size (frame, &w, &h);
194 waste = frame->ellipse.waste;
198 cairo_translate (cr, -waste, -waste);
199 gl_cairo_ellipse_path (cr, (w+waste)/2.0, (h+waste)/2.0);
202 gl_debug (DEBUG_PATH, "END");
206 /*--------------------------------------------------------------------------*/
207 /* Create round label path */
208 /*--------------------------------------------------------------------------*/
210 gl_cairo_round_label_path (cairo_t *cr,
211 const lglTemplate *template,
212 gboolean rotate_flag,
215 const lglTemplateFrame *frame;
219 gl_debug (DEBUG_PATH, "START");
221 frame = (lglTemplateFrame *)template->frames->data;
225 lgl_template_frame_get_size (frame, &h, &w);
229 lgl_template_frame_get_size (frame, &w, &h);
234 waste = frame->round.waste;
242 cairo_arc (cr, w/2, h/2, w/2+waste, 0.0, 2*G_PI);
243 cairo_close_path (cr);
245 gl_debug (DEBUG_PATH, "END");
249 /*--------------------------------------------------------------------------*/
250 /* Create cd label path */
251 /*--------------------------------------------------------------------------*/
253 gl_cairo_cd_label_path (cairo_t *cr,
254 const lglTemplate *template,
255 gboolean rotate_flag,
258 const lglTemplateFrame *frame;
262 gdouble theta1, theta2;
265 gl_debug (DEBUG_PATH, "START");
267 frame = (lglTemplateFrame *)template->frames->data;
271 lgl_template_frame_get_size (frame, &h, &w);
275 lgl_template_frame_get_size (frame, &w, &h);
286 waste = frame->cd.waste;
294 * Outer path (may be clipped in the case of a business card type CD)
296 theta1 = acos (w / (2.0*r1));
297 theta2 = asin (h / (2.0*r1));
300 cairo_arc (cr, xc, yc, r1+waste, theta1, theta2);
301 cairo_arc (cr, xc, yc, r1+waste, G_PI-theta2, G_PI-theta1);
302 cairo_arc (cr, xc, yc, r1+waste, G_PI+theta1, G_PI+theta2);
303 cairo_arc (cr, xc, yc, r1+waste, 2*G_PI-theta2, 2*G_PI-theta1);
304 cairo_close_path (cr);
310 cairo_new_sub_path (cr);
311 cairo_arc (cr, xc, yc, r2-waste, 0.0, 2*G_PI);
312 cairo_close_path (cr);
314 gl_debug (DEBUG_PATH, "END");
320 * Local Variables: -- emacs
322 * c-basic-offset: 8 -- emacs
323 * tab-width: 8 -- emacs
324 * indent-tabs-mode: nil -- emacs