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"
30 /*===========================================*/
32 /*===========================================*/
35 /*===========================================*/
37 /*===========================================*/
40 /*===========================================*/
41 /* Local function prototypes */
42 /*===========================================*/
44 static void gl_cairo_rect_label_path (cairo_t *cr,
45 lglTemplate *template,
48 static void gl_cairo_round_label_path (cairo_t *cr,
49 lglTemplate *template,
52 static void gl_cairo_cd_label_path (cairo_t *cr,
53 lglTemplate *template,
58 /*--------------------------------------------------------------------------*/
59 /* Create label path */
60 /*--------------------------------------------------------------------------*/
62 gl_cairo_label_path (cairo_t *cr,
63 lglTemplate *template,
67 const lglTemplateFrame *frame;
69 gl_debug (DEBUG_PATH, "START");
71 frame = (lglTemplateFrame *)template->frames->data;
73 switch (frame->shape) {
75 case LGL_TEMPLATE_FRAME_SHAPE_RECT:
76 gl_cairo_rect_label_path (cr, template, rotate_flag, waste_flag);
79 case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
80 gl_cairo_round_label_path (cr, template, rotate_flag, waste_flag);
83 case LGL_TEMPLATE_FRAME_SHAPE_CD:
84 gl_cairo_cd_label_path (cr, template, rotate_flag, waste_flag);
88 g_message ("Unknown label style");
92 gl_debug (DEBUG_PATH, "END");
96 /*--------------------------------------------------------------------------*/
97 /* Create rectangular label path */
98 /*--------------------------------------------------------------------------*/
100 gl_cairo_rect_label_path (cairo_t *cr,
101 lglTemplate *template,
102 gboolean rotate_flag,
105 const lglTemplateFrame *frame;
107 gdouble x_waste, y_waste;
109 gl_debug (DEBUG_PATH, "START");
111 frame = (lglTemplateFrame *)template->frames->data;
119 lgl_template_frame_get_size (frame, &h, &w);
122 x_waste = frame->rect.y_waste;
123 y_waste = frame->rect.x_waste;
128 lgl_template_frame_get_size (frame, &w, &h);
131 x_waste = frame->rect.x_waste;
132 y_waste = frame->rect.y_waste;
139 cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste);
144 cairo_arc_negative (cr, r-x_waste, r-y_waste, r, 3*G_PI/2, G_PI);
145 cairo_arc_negative (cr, r-x_waste, h-r+y_waste, r, G_PI, G_PI/2);
146 cairo_arc_negative (cr, w-r+x_waste, h-r+y_waste, r, G_PI/2, 0.);
147 cairo_arc_negative (cr, w-r+x_waste, r-y_waste, r, 2*G_PI, 3*G_PI/2);
148 cairo_close_path (cr);
151 gl_debug (DEBUG_PATH, "END");
155 /*--------------------------------------------------------------------------*/
156 /* Create round label path */
157 /*--------------------------------------------------------------------------*/
159 gl_cairo_round_label_path (cairo_t *cr,
160 lglTemplate *template,
161 gboolean rotate_flag,
164 const lglTemplateFrame *frame;
168 gl_debug (DEBUG_PATH, "START");
170 frame = (lglTemplateFrame *)template->frames->data;
174 lgl_template_frame_get_size (frame, &h, &w);
178 lgl_template_frame_get_size (frame, &w, &h);
183 waste = frame->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");
197 /*--------------------------------------------------------------------------*/
198 /* Create cd label path */
199 /*--------------------------------------------------------------------------*/
201 gl_cairo_cd_label_path (cairo_t *cr,
202 lglTemplate *template,
203 gboolean rotate_flag,
206 const lglTemplateFrame *frame;
210 gdouble theta1, theta2;
213 gl_debug (DEBUG_PATH, "START");
215 frame = (lglTemplateFrame *)template->frames->data;
219 lgl_template_frame_get_size (frame, &h, &w);
223 lgl_template_frame_get_size (frame, &w, &h);
234 waste = frame->cd.waste;
242 * Outer path (may be clipped in the case of a business card type CD)
244 theta1 = acos (w / (2.0*r1));
245 theta2 = asin (h / (2.0*r1));
248 cairo_arc (cr, xc, yc, r1+waste, theta1, theta2);
249 cairo_arc (cr, xc, yc, r1+waste, G_PI-theta2, G_PI-theta1);
250 cairo_arc (cr, xc, yc, r1+waste, G_PI+theta1, G_PI+theta2);
251 cairo_arc (cr, xc, yc, r1+waste, 2*G_PI-theta2, 2*G_PI-theta1);
252 cairo_close_path (cr);
258 cairo_new_sub_path (cr);
259 cairo_arc (cr, xc, yc, r2-waste, 0.0, 2*G_PI);
260 cairo_close_path (cr);
262 gl_debug (DEBUG_PATH, "END");
268 * Local Variables: -- emacs
270 * c-basic-offset: 8 -- emacs
271 * tab-width: 8 -- emacs
272 * indent-tabs-mode: nil -- emacs