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"
27 #include "cairo-ellipse-path.h"
32 /*===========================================*/
34 /*===========================================*/
37 /*===========================================*/
39 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
46 static void gl_cairo_markup_margin_path (cairo_t *cr,
47 const lglTemplateMarkup *markup,
50 static void gl_cairo_markup_margin_rect_path (cairo_t *cr,
51 const lglTemplateMarkup *markup,
54 static void gl_cairo_markup_margin_ellipse_path (cairo_t *cr,
55 const lglTemplateMarkup *markup,
58 static void gl_cairo_markup_margin_round_path (cairo_t *cr,
59 const lglTemplateMarkup *markup,
62 static void gl_cairo_markup_margin_cd_path (cairo_t *cr,
63 const lglTemplateMarkup *markup,
66 static void gl_cairo_markup_line_path (cairo_t *cr,
67 const lglTemplateMarkup *markup);
69 static void gl_cairo_markup_circle_path (cairo_t *cr,
70 const lglTemplateMarkup *markup);
72 static void gl_cairo_markup_rect_path (cairo_t *cr,
73 const lglTemplateMarkup *markup);
75 static void gl_cairo_markup_ellipse_path (cairo_t *cr,
76 const lglTemplateMarkup *markup);
79 /*--------------------------------------------------------------------------*/
80 /* Create markup path */
81 /*--------------------------------------------------------------------------*/
83 gl_cairo_markup_path (cairo_t *cr,
84 const lglTemplateMarkup *markup,
87 gl_debug (DEBUG_PATH, "START");
89 switch (markup->type) {
90 case LGL_TEMPLATE_MARKUP_MARGIN:
91 gl_cairo_markup_margin_path (cr, markup, label);
93 case LGL_TEMPLATE_MARKUP_LINE:
94 gl_cairo_markup_line_path (cr, markup);
96 case LGL_TEMPLATE_MARKUP_CIRCLE:
97 gl_cairo_markup_circle_path (cr, markup);
99 case LGL_TEMPLATE_MARKUP_RECT:
100 gl_cairo_markup_rect_path (cr, markup);
102 case LGL_TEMPLATE_MARKUP_ELLIPSE:
103 gl_cairo_markup_ellipse_path (cr, markup);
106 g_message ("Unknown template markup type");
110 gl_debug (DEBUG_PATH, "END");
114 /*---------------------------------------------------------------------------*/
115 /* PRIVATE. Draw margin markup. */
116 /*---------------------------------------------------------------------------*/
118 gl_cairo_markup_margin_path (cairo_t *cr,
119 const lglTemplateMarkup *markup,
122 const lglTemplate *template;
123 const lglTemplateFrame *frame;
125 gl_debug (DEBUG_PATH, "START");
127 template = gl_label_get_template (label);
128 frame = (lglTemplateFrame *)template->frames->data;
130 switch (frame->shape) {
132 case LGL_TEMPLATE_FRAME_SHAPE_RECT:
133 gl_cairo_markup_margin_rect_path (cr, markup, label);
136 case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE:
137 gl_cairo_markup_margin_ellipse_path (cr, markup, label);
140 case LGL_TEMPLATE_FRAME_SHAPE_ROUND:
141 gl_cairo_markup_margin_round_path (cr, markup, label);
144 case LGL_TEMPLATE_FRAME_SHAPE_CD:
145 gl_cairo_markup_margin_cd_path (cr, markup, label);
149 g_message ("Unknown template label style");
153 gl_debug (DEBUG_PATH, "END");
157 /*---------------------------------------------------------------------------*/
158 /* PRIVATE. Draw simple recangular margin. */
159 /*---------------------------------------------------------------------------*/
161 gl_cairo_markup_margin_rect_path (cairo_t *cr,
162 const lglTemplateMarkup *markup,
165 const lglTemplate *template;
166 const lglTemplateFrame *frame;
169 gl_debug (DEBUG_PATH, "START");
171 template = gl_label_get_template (label);
172 frame = (lglTemplateFrame *)template->frames->data;
174 m = markup->margin.size;
176 lgl_template_frame_get_size (frame, &w, &h);
179 r = MAX (frame->rect.r - m, 0.0);
183 cairo_rectangle (cr, m, m, w, h);
188 cairo_arc_negative (cr, m+r, m+r, r, 3*G_PI/2, G_PI);
189 cairo_arc_negative (cr, m+r, m+h-r, r, G_PI, G_PI/2);
190 cairo_arc_negative (cr, m+w-r, m+h-r, r, G_PI/2, 0.);
191 cairo_arc_negative (cr, m+w-r, m+r, r, 2*G_PI, 3*G_PI/2);
192 cairo_close_path (cr);
195 gl_debug (DEBUG_PATH, "END");
199 /*---------------------------------------------------------------------------*/
200 /* PRIVATE. Draw elliptical margin. */
201 /*---------------------------------------------------------------------------*/
203 gl_cairo_markup_margin_ellipse_path (cairo_t *cr,
204 const lglTemplateMarkup *markup,
207 const lglTemplate *template;
208 const lglTemplateFrame *frame;
211 gl_debug (DEBUG_PATH, "START");
213 template = gl_label_get_template (label);
214 frame = (lglTemplateFrame *)template->frames->data;
216 m = markup->margin.size;
218 lgl_template_frame_get_size (frame, &w, &h);
223 cairo_translate (cr, m, m);
224 gl_cairo_ellipse_path (cr, w/2.0, h/2.0);
227 gl_debug (DEBUG_PATH, "END");
231 /*---------------------------------------------------------------------------*/
232 /* PRIVATE. Draw round margin. */
233 /*---------------------------------------------------------------------------*/
235 gl_cairo_markup_margin_round_path (cairo_t *cr,
236 const lglTemplateMarkup *markup,
239 const lglTemplate *template;
240 const lglTemplateFrame *frame;
243 gl_debug (DEBUG_PATH, "START");
245 template = gl_label_get_template (label);
246 frame = (lglTemplateFrame *)template->frames->data;
249 m = markup->margin.size;
251 cairo_arc (cr, r, r, r-m, 0, 2*G_PI);
252 cairo_close_path (cr);
254 gl_debug (DEBUG_PATH, "END");
258 /*---------------------------------------------------------------------------*/
259 /* PRIVATE. Draw CD margins. */
260 /*---------------------------------------------------------------------------*/
262 gl_cairo_markup_margin_cd_path (cairo_t *cr,
263 const lglTemplateMarkup *markup,
266 const lglTemplate *template;
267 const lglTemplateFrame *frame;
269 gdouble theta1, theta2;
273 gl_debug (DEBUG_PATH, "START");
275 template = gl_label_get_template (label);
276 frame = (lglTemplateFrame *)template->frames->data;
278 lgl_template_frame_get_size (frame, &w, &h);
282 m = markup->margin.size;
283 r1 = frame->cd.r1 - m;
284 r2 = frame->cd.r2 + m;
288 * Outer path (may be clipped)
290 theta1 = acos ((w-2*m) / (2.0*r1));
291 theta2 = asin ((h-2*m) / (2.0*r1));
294 cairo_arc (cr, xc, yc, r1, theta1, theta2);
295 cairo_arc (cr, xc, yc, r1, G_PI-theta2, G_PI-theta1);
296 cairo_arc (cr, xc, yc, r1, G_PI+theta1, G_PI+theta2);
297 cairo_arc (cr, xc, yc, r1, 2*G_PI-theta2, 2*G_PI-theta1);
298 cairo_close_path (cr);
301 /* Inner path (hole) */
302 cairo_new_sub_path (cr);
303 cairo_arc (cr, xc, yc, r2, 0.0, 2*G_PI);
304 cairo_close_path (cr);
306 gl_debug (DEBUG_PATH, "END");
310 /*---------------------------------------------------------------------------*/
311 /* PRIVATE. Draw line markup. */
312 /*---------------------------------------------------------------------------*/
314 gl_cairo_markup_line_path (cairo_t *cr,
315 const lglTemplateMarkup *markup)
317 gl_debug (DEBUG_PATH, "START");
319 cairo_move_to (cr, markup->line.x1, markup->line.y1);
320 cairo_line_to (cr, markup->line.x2, markup->line.y2);
322 gl_debug (DEBUG_PATH, "END");
326 /*---------------------------------------------------------------------------*/
327 /* PRIVATE. Draw circle markup. */
328 /*---------------------------------------------------------------------------*/
330 gl_cairo_markup_circle_path (cairo_t *cr,
331 const lglTemplateMarkup *markup)
333 gl_debug (DEBUG_PATH, "START");
336 markup->circle.x0, markup->circle.y0,
339 cairo_close_path (cr);
341 gl_debug (DEBUG_PATH, "END");
345 /*---------------------------------------------------------------------------*/
346 /* PRIVATE. Draw rect markup. */
347 /*---------------------------------------------------------------------------*/
349 gl_cairo_markup_rect_path (cairo_t *cr,
350 const lglTemplateMarkup *markup)
352 gdouble x1 = markup->rect.x1;
353 gdouble y1 = markup->rect.y1;
354 gdouble w = markup->rect.w;
355 gdouble h = markup->rect.h;
356 gdouble r = markup->rect.r;
358 gl_debug (DEBUG_PATH, "START");
362 cairo_rectangle (cr, x1, y1, w, h);
367 cairo_arc_negative (cr, x1+r, y1+r, r, 3*G_PI/2, G_PI);
368 cairo_arc_negative (cr, x1+r, y1+h-r, r, G_PI, G_PI/2);
369 cairo_arc_negative (cr, x1+w-r, y1+h-r, r, G_PI/2, 0.);
370 cairo_arc_negative (cr, x1+w-r, y1+r, r, 2*G_PI, 3*G_PI/2);
371 cairo_close_path (cr);
374 gl_debug (DEBUG_PATH, "END");
378 /*---------------------------------------------------------------------------*/
379 /* PRIVATE. Draw ellipse markup. */
380 /*---------------------------------------------------------------------------*/
382 gl_cairo_markup_ellipse_path (cairo_t *cr,
383 const lglTemplateMarkup *markup)
385 gdouble x1 = markup->ellipse.x1;
386 gdouble y1 = markup->ellipse.y1;
387 gdouble w = markup->ellipse.w;
388 gdouble h = markup->ellipse.h;
390 gl_debug (DEBUG_PATH, "START");
393 cairo_translate (cr, x1, y1);
394 gl_cairo_ellipse_path (cr, w/2.0, h/2.0);
397 gl_debug (DEBUG_PATH, "END");
403 * Local Variables: -- emacs
405 * c-basic-offset: 8 -- emacs
406 * tab-width: 8 -- emacs
407 * indent-tabs-mode: nil -- emacs