]> git.sur5r.net Git - glabels/commitdiff
2007-04-11 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Thu, 12 Apr 2007 02:27:48 +0000 (02:27 +0000)
committerJim Evins <evins@snaught.com>
Thu, 12 Apr 2007 02:27:48 +0000 (02:27 +0000)
* src/cairo-label-path.c: (gl_cairo_label_path),
(gl_cairo_rect_label_path), (gl_cairo_round_label_path),
(gl_cairo_cd_label_path):
* src/cairo-label-path.h:
* src/mini-preview-pixbuf.c: (draw_paper), (draw_label_outlines),
(draw_label_outline):
* src/print.c: (draw_outline), (clip_to_outline):
* src/view.c: (draw_bg_layer), (draw_fg_layer):
* src/wdgt-mini-preview.c: (draw_labels):
* src/wdgt-rotate-label.c: (drawingarea_update):
Modified to universally use gl_cairo_label_path() to create paths
for labels.  Added shadow to mini preview in rotate widget.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@651 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/ChangeLog
glabels2/src/cairo-label-path.c
glabels2/src/cairo-label-path.h
glabels2/src/mini-preview-pixbuf.c
glabels2/src/print.c
glabels2/src/view.c
glabels2/src/wdgt-mini-preview.c
glabels2/src/wdgt-rotate-label.c

index 1d4b430b90ff8b878c0c7919a43118f731434d53..c3fab5cd7c7f3e04fcd50c4f8f64549ab4fe3f85 100644 (file)
@@ -1,3 +1,18 @@
+2007-04-11  Jim Evins  <evins@snaught.com>
+
+       * src/cairo-label-path.c: (gl_cairo_label_path),
+       (gl_cairo_rect_label_path), (gl_cairo_round_label_path),
+       (gl_cairo_cd_label_path):
+       * src/cairo-label-path.h:
+       * src/mini-preview-pixbuf.c: (draw_paper), (draw_label_outlines),
+       (draw_label_outline):
+       * src/print.c: (draw_outline), (clip_to_outline):
+       * src/view.c: (draw_bg_layer), (draw_fg_layer):
+       * src/wdgt-mini-preview.c: (draw_labels):
+       * src/wdgt-rotate-label.c: (drawingarea_update):
+               Modified to universally use gl_cairo_label_path() to create paths
+               for labels.  Added shadow to mini preview in rotate widget.
+
 2007-04-10  Jim Evins  <evins@snaught.com>
 
        * libglabels/template.h:
index ac42a87a5e1d58c4321d0784601a4a2645d17d5a..cb63bb26cd48563896f8c09a0605e7b7cc6195c7 100644 (file)
 /*===========================================*/
 
 static void gl_cairo_rect_label_path             (cairo_t                *cr,
-                                                  glLabel                *label,
+                                                  glTemplate             *template,
+                                                  gboolean                rotate_flag,
                                                   gboolean                waste_flag);
 static void gl_cairo_round_label_path            (cairo_t                *cr,
-                                                  glLabel                *label,
+                                                  glTemplate             *template,
+                                                  gboolean                rotate_flag,
                                                   gboolean                waste_flag);
 static void gl_cairo_cd_label_path               (cairo_t                *cr,
-                                                  glLabel                *label,
+                                                  glTemplate             *template,
+                                                  gboolean                rotate_flag,
                                                   gboolean                waste_flag);
 
 \f
@@ -59,27 +62,28 @@ static void gl_cairo_cd_label_path               (cairo_t                *cr,
 /*--------------------------------------------------------------------------*/
 void
 gl_cairo_label_path (cairo_t           *cr,
-                     glLabel           *label,
+                     glTemplate        *template,
+                     gboolean           rotate_flag,
                      gboolean           waste_flag)
 {
         const glTemplateLabelType *label_type;
 
         gl_debug (DEBUG_PATH, "START");
 
-        label_type = gl_template_get_first_label_type (label->template);
+        label_type = gl_template_get_first_label_type (template);
 
         switch (label_type->shape) {
 
         case GL_TEMPLATE_SHAPE_RECT:
-                gl_cairo_rect_label_path (cr, label, waste_flag);
+                gl_cairo_rect_label_path (cr, template, rotate_flag, waste_flag);
                 break;
 
         case GL_TEMPLATE_SHAPE_ROUND:
-                gl_cairo_round_label_path (cr, label, waste_flag);
+                gl_cairo_round_label_path (cr, template, rotate_flag, waste_flag);
                 break;
 
         case GL_TEMPLATE_SHAPE_CD:
-                gl_cairo_cd_label_path (cr, label, waste_flag);
+                gl_cairo_cd_label_path (cr, template, rotate_flag, waste_flag);
                 break;
 
         default:
@@ -95,7 +99,8 @@ gl_cairo_label_path (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 gl_cairo_rect_label_path (cairo_t           *cr,
-                          glLabel           *label,
+                          glTemplate        *template,
+                          gboolean           rotate_flag,
                           gboolean           waste_flag)
 {
         const glTemplateLabelType *label_type;
@@ -104,21 +109,32 @@ gl_cairo_rect_label_path (cairo_t           *cr,
 
         gl_debug (DEBUG_PATH, "START");
 
-        label_type = gl_template_get_first_label_type (label->template);
-        gl_label_get_size (label, &w, &h);
+        label_type = gl_template_get_first_label_type (template);
         r = label_type->size.rect.r;
 
-        if (waste_flag)
+        x_waste = 0.0;
+        y_waste = 0.0;
+
+        if (rotate_flag)
         {
-                x_waste = label_type->size.rect.x_waste;
-                y_waste = label_type->size.rect.x_waste;
+                gl_template_get_label_size (label_type, &h, &w);
+                if (waste_flag)
+                {
+                        x_waste = label_type->size.rect.y_waste;
+                        y_waste = label_type->size.rect.x_waste;
+                }
         }
         else
         {
-                x_waste = 0.0;
-                y_waste = 0.0;
+                gl_template_get_label_size (label_type, &w, &h);
+                if (waste_flag)
+                {
+                        x_waste = label_type->size.rect.x_waste;
+                        y_waste = label_type->size.rect.y_waste;
+                }
         }
 
+
         if ( r == 0.0 )
         {
                 cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste);
@@ -141,7 +157,8 @@ gl_cairo_rect_label_path (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 gl_cairo_round_label_path (cairo_t           *cr,
-                           glLabel           *label,
+                           glTemplate        *template,
+                           gboolean           rotate_flag,
                            gboolean           waste_flag)
 {
         const glTemplateLabelType *label_type;
@@ -150,9 +167,17 @@ gl_cairo_round_label_path (cairo_t           *cr,
 
         gl_debug (DEBUG_PATH, "START");
 
-        label_type = gl_template_get_first_label_type (label->template);
-        gl_label_get_size (label, &w, &h);
+        label_type = gl_template_get_first_label_type (template);
         
+        if (rotate_flag)
+        {
+                gl_template_get_label_size (label_type, &h, &w);
+        }
+        else
+        {
+                gl_template_get_label_size (label_type, &w, &h);
+        }
+
         if (waste_flag)
         {
                 waste = label_type->size.round.waste;
@@ -173,7 +198,8 @@ gl_cairo_round_label_path (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 gl_cairo_cd_label_path (cairo_t           *cr,
-                        glLabel           *label,
+                        glTemplate        *template,
+                        gboolean           rotate_flag,
                         gboolean           waste_flag)
 {
         const glTemplateLabelType *label_type;
@@ -185,8 +211,16 @@ gl_cairo_cd_label_path (cairo_t           *cr,
 
         gl_debug (DEBUG_PATH, "START");
 
-        label_type = gl_template_get_first_label_type (label->template);
-        gl_label_get_size (label, &w, &h);
+        label_type = gl_template_get_first_label_type (template);
+
+        if (rotate_flag)
+        {
+                gl_template_get_label_size (label_type, &h, &w);
+        }
+        else
+        {
+                gl_template_get_label_size (label_type, &w, &h);
+        }
 
         xc = w/2.0;
         yc = h/2.0;
index 79f1cd5b44ae6a301439dda95c7ea087607b29f1..386f63b3dcc118943a67a45465e30cf4ea99c30b 100644 (file)
 #define __CAIRO_LABEL_PATH_H__
 
 #include <cairo.h>
-#include "label.h"
+#include <libglabels/template.h>
 
 G_BEGIN_DECLS
 
 void gl_cairo_label_path (cairo_t                *cr,
-                          glLabel                *label,
+                          glTemplate             *template,
+                          gboolean                rotate_flag,
                           gboolean                waste_flag);
 
 G_END_DECLS
index b8f5e99abd6a7a1c8bf435cdac50634553358551..1fd467d11cb8c9572f2013e047e20ff4913a3276 100644 (file)
@@ -25,6 +25,7 @@
 #include <config.h>
 
 #include "mini-preview-pixbuf.h"
+#include "cairo-label-path.h"
 
 #include <cairo.h>
 #include <math.h>
 /*===========================================*/
 
 static void draw_paper                (cairo_t           *cr,
-                                      const glTemplate  *template,
+                                      glTemplate        *template,
                                       gdouble            scale);
 
 static void draw_label_outlines       (cairo_t           *cr,
-                                      const glTemplate  *template,
+                                      glTemplate        *template,
                                       gdouble            scale);
 
 static void draw_label_outline        (cairo_t           *cr,
-                                      const glTemplate  *template,
-                                      gdouble            x0,
-                                      gdouble            y0);
-
-static void draw_rect_label_outline   (cairo_t           *cr,
-                                      const glTemplate  *template,
-                                      gdouble            x0,
-                                      gdouble            y0);
-
-static void draw_round_label_outline  (cairo_t           *cr,
-                                      const glTemplate  *template,
-                                      gdouble            x0,
-                                      gdouble            y0);
-
-static void draw_cd_label_outline     (cairo_t           *cr,
-                                      const glTemplate  *template,
+                                      glTemplate        *template,
                                       gdouble            x0,
                                       gdouble            y0);
 
@@ -143,7 +129,7 @@ gl_mini_preview_pixbuf_new (glTemplate *template,
 /*--------------------------------------------------------------------------*/
 static void
 draw_paper (cairo_t           *cr,
-           const glTemplate  *template,
+           glTemplate        *template,
            gdouble            scale)
 {
        gl_debug (DEBUG_MINI_PREVIEW, "START");
@@ -165,7 +151,7 @@ draw_paper (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 draw_label_outlines (cairo_t           *cr,
-                    const glTemplate  *template,
+                    glTemplate        *template,
                     gdouble            scale)
 {
        const glTemplateLabelType *label_type;
@@ -201,150 +187,17 @@ draw_label_outlines (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 draw_label_outline (cairo_t           *cr,
-                   const glTemplate  *template,
+                   glTemplate        *template,
                    gdouble            x0,
                    gdouble            y0)
 {
-       const glTemplateLabelType *label_type;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       label_type = gl_template_get_first_label_type (template);
-
-       switch (label_type->shape) {
-
-       case GL_TEMPLATE_SHAPE_RECT:
-               draw_rect_label_outline (cr, template, x0, y0);
-               break;
-
-       case GL_TEMPLATE_SHAPE_ROUND:
-               draw_round_label_outline (cr, template, x0, y0);
-               break;
-
-       case GL_TEMPLATE_SHAPE_CD:
-               draw_cd_label_outline (cr, template, x0, y0);
-               break;
-
-       default:
-               g_message ("Unknown label style");
-               break;
-       }
-
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw rectangular label outline.                                */
-/*--------------------------------------------------------------------------*/
-static void
-draw_rect_label_outline (cairo_t           *cr,
-                        const glTemplate  *template,
-                        gdouble            x0,
-                        gdouble            y0)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
-
        gl_debug (DEBUG_MINI_PREVIEW, "START");
 
        cairo_save (cr);
 
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
+        cairo_translate (cr, x0, y0);
 
-       cairo_rectangle (cr, x0, y0, w, h);
-
-       cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
-        cairo_fill_preserve (cr);
-
-       cairo_set_source_rgb (cr, 0.25, 0.25, 0.25);
-       cairo_stroke (cr);
-
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw round label outline.                                      */
-/*--------------------------------------------------------------------------*/
-static void
-draw_round_label_outline (cairo_t           *cr,
-                         const glTemplate  *template,
-                         gdouble            x0,
-                         gdouble            y0)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
-
-       cairo_arc (cr, x0+w/2, y0+h/2, w/2, 0.0, 2*M_PI);
-
-       cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
-        cairo_fill_preserve (cr);
-
-       cairo_set_source_rgb (cr, 0.25, 0.25, 0.25);
-       cairo_stroke (cr);
-
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw cd label outline.                                         */
-/*--------------------------------------------------------------------------*/
-static void
-draw_cd_label_outline (cairo_t           *cr,
-                      const glTemplate  *template,
-                      gdouble            x0,
-                      gdouble            y0)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
-       gdouble                    xc, yc;
-       gdouble                    r1, r2;
-        gdouble                    theta1, theta2;
-
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
-
-       xc = x0 + w/2.0;
-       yc = y0 + h/2.0;
-
-       r1 = label_type->size.cd.r1;
-       r2 = label_type->size.cd.r2;
-
-        theta1 = acos (w / (2.0*r1));
-        theta2 = asin (h / (2.0*r1));
-
-        /* Outer radius, may be clipped in the case of business card CDs. */
-        /* Do as a series of 4 arcs, to account for clipping. */
-        cairo_new_path (cr);
-        cairo_arc (cr, xc, yc, r1, theta1, theta2);
-        cairo_arc (cr, xc, yc, r1, M_PI-theta2, M_PI-theta1);
-        cairo_arc (cr, xc, yc, r1, M_PI+theta1, M_PI+theta2);
-        cairo_arc (cr, xc, yc, r1, 2*M_PI-theta2, 2*M_PI-theta1);
-        cairo_close_path (cr);
-
-       /* Hole */
-        cairo_new_sub_path (cr);
-       cairo_arc (cr, xc, yc, r2, 0.0, 2*M_PI);
+        gl_cairo_label_path (cr, template, FALSE, FALSE);
 
        cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
         cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
@@ -352,11 +205,9 @@ draw_cd_label_outline (cairo_t           *cr,
 
        cairo_set_source_rgb (cr, 0.25, 0.25, 0.25);
        cairo_stroke (cr);
-       
+
        cairo_restore (cr);
 
        gl_debug (DEBUG_MINI_PREVIEW, "END");
 }
 
-
-
index 621f4e29b6a3b32259a5013eacbda993d7821c2c..15f07135986b34624ea70148c40da46b6ff63922 100644 (file)
@@ -535,7 +535,7 @@ draw_outline (PrintInfo *pi,
        cairo_set_source_rgba (pi->cr, 0.0, 0.0, 0.0, 1.0);
        cairo_set_line_width  (pi->cr, 0.25);
 
-        gl_cairo_label_path (pi->cr, label, FALSE);
+        gl_cairo_label_path (pi->cr, label->template, FALSE, FALSE);
 
         cairo_stroke (pi->cr);
 
@@ -553,7 +553,7 @@ clip_to_outline (PrintInfo *pi,
 {
        gl_debug (DEBUG_PRINT, "START");
 
-        gl_cairo_label_path (pi->cr, label, TRUE);
+        gl_cairo_label_path (pi->cr, label->template, FALSE, TRUE);
 
         cairo_set_fill_rule (pi->cr, CAIRO_FILL_RULE_EVEN_ODD);
         cairo_clip (pi->cr);
index 19de24842b7f9f2da35e3a79f6ce82c9d4939760..9cc6243c53d4cce34f27140969db20ede07ef693 100644 (file)
@@ -746,7 +746,7 @@ draw_bg_layer (glView  *view,
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-        gl_cairo_label_path (cr, view->label, FALSE);
+        gl_cairo_label_path (cr, view->label->template, view->label->rotate_flag, FALSE);
 
         cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
         cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
@@ -874,7 +874,7 @@ draw_fg_layer (glView  *view,
        g_return_if_fail (view && GL_IS_VIEW (view));
        g_return_if_fail (view->label && GL_IS_LABEL (view->label));
 
-        gl_cairo_label_path (cr, view->label, FALSE);
+        gl_cairo_label_path (cr, view->label->template, view->label->rotate_flag, FALSE);
 
         cairo_set_line_width (cr, 3.0/(view->home_scale * view->zoom));
         cairo_set_source_rgb (cr, 0.68, 0.85, 0.90);
index 01501399a7db9cce4111ee51704a9edfe02ccd41..49e4a472ff5a1ffd3f63f63bc39c5b5b7a65e53e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <math.h>
 
+#include "cairo-label-path.h"
 #include "marshal.h"
 #include "color.h"
 
@@ -117,24 +118,8 @@ static void draw_paper                         (glWdgtMiniPreview      *preview,
                                                gdouble                 line_width);
 static void draw_labels                        (glWdgtMiniPreview      *preview,
                                                cairo_t                *cr,
-                                               const glTemplate       *template,
+                                               glTemplate             *template,
                                                gdouble                 line_width);
-static void create_label_path                  (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               gdouble                 x0,
-                                               gdouble                 y0);
-static void create_rect_label_path             (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               gdouble                 x0,
-                                               gdouble                 y0);
-static void create_round_label_path            (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               gdouble                 x0,
-                                               gdouble                 y0);
-static void create_cd_label_path               (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               gdouble                 x0,
-                                               gdouble                 y0);
 
 static gint find_closest_label                 (glWdgtMiniPreview      *preview,
                                                gdouble                 x,
@@ -680,7 +665,7 @@ draw_paper (glWdgtMiniPreview      *preview,
 static void
 draw_labels (glWdgtMiniPreview *preview,
             cairo_t           *cr,
-            const glTemplate  *template,
+            glTemplate        *template,
             gdouble            line_width)
 {
         const glTemplateLabelType *label_type;
@@ -703,7 +688,8 @@ draw_labels (glWdgtMiniPreview *preview,
 
                cairo_save (cr);
 
-                create_label_path (cr, template, origins[i].x, origins[i].y);
+                cairo_translate (cr, origins[i].x, origins[i].y);
+                gl_cairo_label_path (cr, template, FALSE, FALSE);
 
                if ( ((i+1) >= preview->priv->highlight_first) &&
                     ((i+1) <= preview->priv->highlight_last) )
@@ -733,133 +719,3 @@ draw_labels (glWdgtMiniPreview *preview,
         gl_debug (DEBUG_MINI_PREVIEW, "END");
 }
 
-/*--------------------------------------------------------------------------*/
-/* Create label path                                                        */
-/*--------------------------------------------------------------------------*/
-static void
-create_label_path (cairo_t           *cr,
-                  const glTemplate  *template,
-                  gdouble            x0,
-                  gdouble            y0)
-{
-        const glTemplateLabelType *label_type;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        label_type = gl_template_get_first_label_type (template);
-
-        switch (label_type->shape) {
-
-        case GL_TEMPLATE_SHAPE_RECT:
-                create_rect_label_path (cr, template, x0, y0);
-                break;
-
-        case GL_TEMPLATE_SHAPE_ROUND:
-                create_round_label_path (cr, template, x0, y0);
-                break;
-
-        case GL_TEMPLATE_SHAPE_CD:
-                create_cd_label_path (cr, template, x0, y0);
-                break;
-
-        default:
-                g_message ("Unknown label style");
-                break;
-        }
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Create rectangular label path                                            */
-/*--------------------------------------------------------------------------*/
-static void
-create_rect_label_path (cairo_t           *cr,
-                       const glTemplate  *template,
-                       gdouble            x0,
-                       gdouble            y0)
-{
-        const glTemplateLabelType *label_type;
-        gdouble                    w, h;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        label_type = gl_template_get_first_label_type (template);
-        gl_template_get_label_size (label_type, &w, &h);
-
-        cairo_rectangle (cr, x0, y0, w, h);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Create round label path                                                  */
-/*--------------------------------------------------------------------------*/
-static void
-create_round_label_path (cairo_t           *cr,
-                        const glTemplate  *template,
-                        gdouble            x0,
-                        gdouble            y0)
-{
-        const glTemplateLabelType *label_type;
-        gdouble                    w, h;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        label_type = gl_template_get_first_label_type (template);
-        gl_template_get_label_size (label_type, &w, &h);
-
-        cairo_arc (cr, x0+w/2, y0+h/2, w/2, 0.0, 2*M_PI);
-       cairo_close_path (cr);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* Create cd label path                                                     */
-/*--------------------------------------------------------------------------*/
-static void
-create_cd_label_path (cairo_t           *cr,
-                     const glTemplate  *template,
-                     gdouble            x0,
-                     gdouble            y0)
-{
-        const glTemplateLabelType *label_type;
-        gdouble                    w, h;
-        gdouble                    xc, yc;
-        gdouble                    r1, r2;
-       gdouble                    theta1, theta2;
-
-        gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-        label_type = gl_template_get_first_label_type (template);
-        gl_template_get_label_size (label_type, &w, &h);
-
-        xc = x0 + w/2.0;
-        yc = y0 + h/2.0;
-
-        r1 = label_type->size.cd.r1;
-        r2 = label_type->size.cd.r2;
-
-       /*
-        * Outer path (may be clipped)
-        */
-       theta1 = acos (w / (2.0*r1));
-       theta2 = asin (h / (2.0*r1));
-
-       cairo_new_path (cr);
-       cairo_arc (cr, xc, yc, r1, theta1, theta2);
-       cairo_arc (cr, xc, yc, r1, M_PI-theta2, M_PI-theta1);
-       cairo_arc (cr, xc, yc, r1, M_PI+theta1, M_PI+theta2);
-       cairo_arc (cr, xc, yc, r1, 2*M_PI-theta2, 2*M_PI-theta1);
-       cairo_close_path (cr);
-
-
-        /* Inner path (hole) */
-       cairo_new_sub_path (cr);
-        cairo_arc (cr, xc, yc, r2, 0.0, 2*M_PI);
-       cairo_close_path (cr);
-
-        gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
index f0f19ce296f8828d20602a2d9d9c6938524f2a5f..dbeb8150a89e10845387d295c57132a9a4dd9ddb 100644 (file)
@@ -36,6 +36,7 @@
 #include "marshal.h"
 #include "color.h"
 #include <libglabels/template.h>
+#include "cairo-label-path.h"
 
 #include "debug.h"
 
 #define LINE_COLOR             GL_COLOR(0,0,0)
 #define FILL_COLOR             GL_COLOR(255,255,255)
 
+#define SHADOW_X_OFFSET 3
+#define SHADOW_Y_OFFSET 3
+
+
 /*===========================================*/
 /* Private types                             */
 /*===========================================*/
@@ -86,22 +91,6 @@ static void drawingarea_update                 (GtkDrawingArea         *drawing_
                                                glTemplate             *template,
                                                gboolean                rotate_flag);
 
-static void draw_rect_label_outline            (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               guint                   line_color,
-                                               guint                   fill_color);
-
-static void draw_round_label_outline           (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               guint                   line_color,
-                                               guint                   fill_color);
-
-
-static void draw_cd_label_outline              (cairo_t                *cr,
-                                               const glTemplate       *template,
-                                               guint                   line_color,
-                                               guint                   fill_color);
-
 static gboolean expose_cb                      (GtkWidget              *drawingarea,
                                                GdkEventExpose         *event,
                                                gpointer                user_data);
@@ -243,7 +232,7 @@ drawingarea_update (GtkDrawingArea *drawing_area,
        const glTemplateLabelType *label_type;
        gdouble                    m, m_canvas, w, h, scale;
        GtkStyle                  *style;
-       guint                      line_color, fill_color;
+       guint                      line_color, fill_color, shadow_color;
        cairo_t                   *cr;
 
        if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (drawing_area)))
@@ -261,172 +250,59 @@ drawingarea_update (GtkDrawingArea *drawing_area,
 
        label_type = gl_template_get_first_label_type (template);
 
-       gl_template_get_label_size (label_type, &w, &h);
+        if (rotate_flag)
+        {
+                gl_template_get_label_size (label_type, &h, &w);
+        }
+        else
+        {
+                gl_template_get_label_size (label_type, &w, &h);
+        }
        m = MAX (w, h);
        scale = MINI_PREVIEW_MAX_PIXELS / m;
        m_canvas = MINI_PREVIEW_CANVAS_PIXELS / scale;
 
+        style = gtk_widget_get_style (GTK_WIDGET (drawing_area));
+
        /* Adjust sensitivity (should the canvas be grayed?) */
        if (w != h) {
                line_color = LINE_COLOR;
                fill_color = FILL_COLOR;
        } else {
-               style = gtk_widget_get_style (GTK_WIDGET (drawing_area));
                line_color = gl_color_from_gdk_color (&style->text[GTK_STATE_INSENSITIVE]);
                fill_color = gl_color_from_gdk_color (&style->base[GTK_STATE_INSENSITIVE]);
        }
 
+       shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]);
+
+
        cr = gdk_cairo_create (GTK_WIDGET (drawing_area)->window);
   
        cairo_identity_matrix (cr);
        cairo_translate (cr, MINI_PREVIEW_CANVAS_PIXELS/2, MINI_PREVIEW_CANVAS_PIXELS/2);
         cairo_scale (cr, scale, scale);
-       if (rotate_flag)
-       {
-               cairo_rotate (cr, M_PI/2.0);
-       }
-
-       cairo_set_line_width (cr, 1.0/scale);
-
-       switch (label_type->shape) {
-
-       case GL_TEMPLATE_SHAPE_RECT:
-               draw_rect_label_outline (cr, template, line_color, fill_color);
-               break;
-
-       case GL_TEMPLATE_SHAPE_ROUND:
-               draw_round_label_outline (cr, template, line_color, fill_color);
-               break;
-
-       case GL_TEMPLATE_SHAPE_CD:
-               draw_cd_label_outline (cr, template, line_color, fill_color);
-               break;
-
-       default:
-               g_message ("Unknown label style");
-               break;
-       }
-
-       cairo_destroy (cr);
-
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw rectangular label outline.                                */
-/*--------------------------------------------------------------------------*/
-static void
-draw_rect_label_outline (cairo_t           *cr,
-                        const glTemplate  *template,
-                        guint              line_color,
-                        guint              fill_color)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
-
-       cairo_rectangle (cr, -w/2.0, -h/2.0, w, h);
-
-       cairo_set_source_rgb (cr,
-                             GL_COLOR_F_RED(fill_color),
-                             GL_COLOR_F_GREEN(fill_color),
-                             GL_COLOR_F_BLUE(fill_color));
-       cairo_fill_preserve (cr);
-
-       cairo_set_source_rgb (cr,
-                             GL_COLOR_F_RED(line_color),
-                             GL_COLOR_F_GREEN(line_color),
-                             GL_COLOR_F_BLUE(line_color));
-       cairo_stroke (cr);
-
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw round label outline.                                      */
-/*--------------------------------------------------------------------------*/
-static void
-draw_round_label_outline (cairo_t           *cr,
-                         const glTemplate  *template,
-                         guint              line_color,
-                         guint              fill_color)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
+        cairo_translate (cr, -w/2.0, -h/2.0);
 
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
-
-       cairo_save (cr);
-
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
-
-       cairo_arc (cr, 0.0, 0.0, w/2, 0.0, 2*M_PI);
+        /*
+         * Shadow
+         */
+        cairo_save (cr);
+        cairo_translate (cr, SHADOW_X_OFFSET/scale, SHADOW_Y_OFFSET/scale);
+        gl_cairo_label_path (cr, template, rotate_flag, FALSE);
 
        cairo_set_source_rgb (cr,
-                             GL_COLOR_F_RED(fill_color),
-                             GL_COLOR_F_GREEN(fill_color),
-                             GL_COLOR_F_BLUE(fill_color));
-       cairo_fill_preserve (cr);
-
-       cairo_set_source_rgb (cr,
-                             GL_COLOR_F_RED(line_color),
-                             GL_COLOR_F_GREEN(line_color),
-                             GL_COLOR_F_BLUE(line_color));
-       cairo_stroke (cr);
-
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw cd label outline.                                         */
-/*--------------------------------------------------------------------------*/
-static void
-draw_cd_label_outline (cairo_t           *cr,
-                      const glTemplate  *template,
-                      guint              line_color,
-                      guint              fill_color)
-{
-       const glTemplateLabelType *label_type;
-       gdouble                    w, h;
-       gdouble                    r1, r2;
-        gdouble                    theta1, theta2;
-
-       gl_debug (DEBUG_MINI_PREVIEW, "START");
+                             GL_COLOR_F_RED(shadow_color),
+                             GL_COLOR_F_GREEN(shadow_color),
+                             GL_COLOR_F_BLUE(shadow_color));
+        cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+       cairo_fill (cr);
+        cairo_restore (cr);
 
-       cairo_save (cr);
+        /*
+         * Label + outline
+         */
+        gl_cairo_label_path (cr, template, rotate_flag, FALSE);
 
-       label_type = gl_template_get_first_label_type (template);
-       gl_template_get_label_size (label_type, &w, &h);
-
-       r1 = label_type->size.cd.r1;
-       r2 = label_type->size.cd.r2;
-
-        /* Outer radius, may be clipped in the case of business card CDs. */
-        /* Do as a series of 4 arcs, to account for clipping. */
-        theta1 = acos (w / (2.0*r1));
-        theta2 = asin (h / (2.0*r1));
-
-        cairo_new_path (cr);
-        cairo_arc (cr, 0.0, 0.0, r1, theta1, theta2);
-        cairo_arc (cr, 0.0, 0.0, r1, M_PI-theta2, M_PI-theta1);
-        cairo_arc (cr, 0.0, 0.0, r1, M_PI+theta1, M_PI+theta2);
-        cairo_arc (cr, 0.0, 0.0, r1, 2*M_PI-theta2, 2*M_PI-theta1);
-        cairo_close_path (cr);
-
-       /* Hole */
-        cairo_new_sub_path (cr);
-       cairo_arc (cr, 0.0, 0.0, r2, 0.0, 2*M_PI);
-       
        cairo_set_source_rgb (cr,
                              GL_COLOR_F_RED(fill_color),
                              GL_COLOR_F_GREEN(fill_color),
@@ -434,19 +310,20 @@ draw_cd_label_outline (cairo_t           *cr,
         cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
        cairo_fill_preserve (cr);
 
+       cairo_set_line_width (cr, 1.0/scale);
        cairo_set_source_rgb (cr,
                              GL_COLOR_F_RED(line_color),
                              GL_COLOR_F_GREEN(line_color),
                              GL_COLOR_F_BLUE(line_color));
        cairo_stroke (cr);
 
-       cairo_restore (cr);
 
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
+       cairo_destroy (cr);
+
 }
 
 /*--------------------------------------------------------------------------*/
-/* PRIVATE.  Draw cd label outline.                                         */
+/* PRIVATE.  Expose handler.                                                */
 /*--------------------------------------------------------------------------*/
 static gboolean
 expose_cb (GtkWidget *drawingarea, GdkEventExpose *event, gpointer user_data)