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-markup-path.h"
30 /*===========================================*/
32 /*===========================================*/
35 /*===========================================*/
37 /*===========================================*/
40 /*===========================================*/
41 /* Local function prototypes */
42 /*===========================================*/
44 static void gl_cairo_markup_margin_path (cairo_t *cr,
45 const lglTemplateMarkup *markup,
48 static void gl_cairo_markup_margin_rect_path (cairo_t *cr,
49 const lglTemplateMarkup *markup,
52 static void gl_cairo_markup_margin_round_path (cairo_t *cr,
53 const lglTemplateMarkup *markup,
56 static void gl_cairo_markup_margin_cd_path (cairo_t *cr,
57 const lglTemplateMarkup *markup,
60 static void gl_cairo_markup_line_path (cairo_t *cr,
61 const lglTemplateMarkup *markup);
63 static void gl_cairo_markup_circle_path (cairo_t *cr,
64 const lglTemplateMarkup *markup);
66 static void gl_cairo_markup_rect_path (cairo_t *cr,
67 const lglTemplateMarkup *markup);
70 /*--------------------------------------------------------------------------*/
71 /* Create markup path */
72 /*--------------------------------------------------------------------------*/
74 gl_cairo_markup_path (cairo_t *cr,
75 const lglTemplateMarkup *markup,
78 gl_debug (DEBUG_PATH, "START");
80 switch (markup->type) {
81 case LGL_TEMPLATE_MARKUP_MARGIN:
82 gl_cairo_markup_margin_path (cr, markup, label);
84 case LGL_TEMPLATE_MARKUP_LINE:
85 gl_cairo_markup_line_path (cr, markup);
87 case LGL_TEMPLATE_MARKUP_CIRCLE:
88 gl_cairo_markup_circle_path (cr, markup);
90 case LGL_TEMPLATE_MARKUP_RECT:
91 gl_cairo_markup_rect_path (cr, markup);
94 g_message ("Unknown template markup type");
98 gl_debug (DEBUG_PATH, "END");
102 /*---------------------------------------------------------------------------*/
103 /* PRIVATE. Draw margin markup. */
104 /*---------------------------------------------------------------------------*/
106 gl_cairo_markup_margin_path (cairo_t *cr,
107 const lglTemplateMarkup *markup,
110 const lglTemplateFrame *frame;
112 gl_debug (DEBUG_PATH, "START");
114 frame = (lglTemplateFrame *)label->template->frames->data;
116 switch (frame->shape) {
118 case LGL_TEMPLATE_FRAME_SHAPE_RECT:
119 gl_cairo_markup_margin_rect_path (cr, markup, label);
122 case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
123 gl_cairo_markup_margin_round_path (cr, markup, label);
126 case LGL_TEMPLATE_FRAME_SHAPE_CD:
127 gl_cairo_markup_margin_cd_path (cr, markup, label);
131 g_message ("Unknown template label style");
135 gl_debug (DEBUG_PATH, "END");
139 /*---------------------------------------------------------------------------*/
140 /* PRIVATE. Draw simple recangular margin. */
141 /*---------------------------------------------------------------------------*/
143 gl_cairo_markup_margin_rect_path (cairo_t *cr,
144 const lglTemplateMarkup *markup,
147 const lglTemplateFrame *frame;
150 gl_debug (DEBUG_PATH, "START");
152 frame = (lglTemplateFrame *)label->template->frames->data;
154 m = markup->margin.size;
156 lgl_template_frame_get_size (frame, &w, &h);
159 r = MAX (frame->rect.r - m, 0.0);
163 cairo_rectangle (cr, m, m, w, h);
168 cairo_arc_negative (cr, m+r, m+r, r, 3*G_PI/2, G_PI);
169 cairo_arc_negative (cr, m+r, m+h-r, r, G_PI, G_PI/2);
170 cairo_arc_negative (cr, m+w-r, m+h-r, r, G_PI/2, 0.);
171 cairo_arc_negative (cr, m+w-r, m+r, r, 2*G_PI, 3*G_PI/2);
172 cairo_close_path (cr);
175 gl_debug (DEBUG_PATH, "END");
179 /*---------------------------------------------------------------------------*/
180 /* PRIVATE. Draw round margin. */
181 /*---------------------------------------------------------------------------*/
183 gl_cairo_markup_margin_round_path (cairo_t *cr,
184 const lglTemplateMarkup *markup,
187 const lglTemplateFrame *frame;
190 gl_debug (DEBUG_PATH, "START");
192 frame = (lglTemplateFrame *)label->template->frames->data;
195 m = markup->margin.size;
197 cairo_arc (cr, r, r, r-m, 0, 2*G_PI);
198 cairo_close_path (cr);
200 gl_debug (DEBUG_PATH, "END");
204 /*---------------------------------------------------------------------------*/
205 /* PRIVATE. Draw CD margins. */
206 /*---------------------------------------------------------------------------*/
208 gl_cairo_markup_margin_cd_path (cairo_t *cr,
209 const lglTemplateMarkup *markup,
212 const lglTemplateFrame *frame;
214 gdouble theta1, theta2;
218 gl_debug (DEBUG_PATH, "START");
220 frame = (lglTemplateFrame *)label->template->frames->data;
222 lgl_template_frame_get_size (frame, &w, &h);
226 m = markup->margin.size;
227 r1 = frame->cd.r1 - m;
228 r2 = frame->cd.r2 + m;
232 * Outer path (may be clipped)
234 theta1 = acos ((w-2*m) / (2.0*r1));
235 theta2 = asin ((h-2*m) / (2.0*r1));
238 cairo_arc (cr, xc, yc, r1, theta1, theta2);
239 cairo_arc (cr, xc, yc, r1, G_PI-theta2, G_PI-theta1);
240 cairo_arc (cr, xc, yc, r1, G_PI+theta1, G_PI+theta2);
241 cairo_arc (cr, xc, yc, r1, 2*G_PI-theta2, 2*G_PI-theta1);
242 cairo_close_path (cr);
245 /* Inner path (hole) */
246 cairo_new_sub_path (cr);
247 cairo_arc (cr, xc, yc, r2, 0.0, 2*G_PI);
248 cairo_close_path (cr);
250 gl_debug (DEBUG_PATH, "END");
254 /*---------------------------------------------------------------------------*/
255 /* PRIVATE. Draw line markup. */
256 /*---------------------------------------------------------------------------*/
258 gl_cairo_markup_line_path (cairo_t *cr,
259 const lglTemplateMarkup *markup)
261 gl_debug (DEBUG_PATH, "START");
263 cairo_move_to (cr, markup->line.x1, markup->line.y1);
264 cairo_line_to (cr, markup->line.x2, markup->line.y2);
266 gl_debug (DEBUG_PATH, "END");
270 /*---------------------------------------------------------------------------*/
271 /* PRIVATE. Draw circle markup. */
272 /*---------------------------------------------------------------------------*/
274 gl_cairo_markup_circle_path (cairo_t *cr,
275 const lglTemplateMarkup *markup)
277 gl_debug (DEBUG_PATH, "START");
280 markup->circle.x0, markup->circle.y0,
283 cairo_close_path (cr);
285 gl_debug (DEBUG_PATH, "END");
289 /*---------------------------------------------------------------------------*/
290 /* PRIVATE. Draw rect markup. */
291 /*---------------------------------------------------------------------------*/
293 gl_cairo_markup_rect_path (cairo_t *cr,
294 const lglTemplateMarkup *markup)
296 gdouble x1 = markup->rect.x1;
297 gdouble y1 = markup->rect.y1;
298 gdouble w = markup->rect.w;
299 gdouble h = markup->rect.h;
300 gdouble r = markup->rect.r;
302 gl_debug (DEBUG_PATH, "START");
306 cairo_rectangle (cr, x1, y1, w, h);
311 cairo_arc_negative (cr, x1+r, y1+r, r, 3*G_PI/2, G_PI);
312 cairo_arc_negative (cr, x1+r, y1+h-r, r, G_PI, G_PI/2);
313 cairo_arc_negative (cr, x1+w-r, y1+h-r, r, G_PI/2, 0.);
314 cairo_arc_negative (cr, x1+w-r, y1+r, r, 2*G_PI, 3*G_PI/2);
315 cairo_close_path (cr);
318 gl_debug (DEBUG_PATH, "END");
324 * Local Variables: -- emacs
326 * c-basic-offset: 8 -- emacs
327 * tab-width: 8 -- emacs
328 * indent-tabs-mode: nil -- emacs