]> git.sur5r.net Git - glabels/blobdiff - glabels2/src/mini-preview-pixbuf.c
2009-09-17 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / mini-preview-pixbuf.c
index 6d2a6fc803eb1a219101f3ead69d55d31f59cae0..0651263f287384f119a60e8ebb274394aa5e640c 100644 (file)
@@ -1,25 +1,21 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
 /*
- *  (GLABELS) Label and Business Card Creation program for GNOME
- *
- *  mini-preview-pixbuf.c:  mini preview pixbuf module
+ *  mini-preview-pixbuf.c
+ *  Copyright (C) 2006-2009  Jim Evins <evins@snaught.com>.
  *
- *  Copyright (C) 2006  Jim Evins <evins@snaught.com>.
+ *  This file is part of gLabels.
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  gLabels is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
+ *  gLabels is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <config.h>
 #include <cairo.h>
 #include <math.h>
 
+#include "cairo-label-path.h"
+
 #include "debug.h"
 
+/*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+#define PAPER_RGB_ARGS          0.95,  0.95,  0.95
+#define PAPER_OUTLINE_RGB_ARGS  0.0,   0.0,   0.0
+#define LABEL_RGB_ARGS          1.0,   1.0,   1.0
+#define LABEL_OUTLINE_RGB_ARGS  0.25,  0.25,  0.25
+
+#define PAPER_OUTLINE_WIDTH_PIXELS  1.0
+#define LABEL_OUTLINE_WIDTH_PIXELS  1.0
+
 /*===========================================*/
 /* Private types                             */
 /*===========================================*/
 /*===========================================*/
 
 static void draw_paper                (cairo_t           *cr,
-                                      const glTemplate  *template,
+                                      lglTemplate       *template,
                                       gdouble            scale);
 
 static void draw_label_outlines       (cairo_t           *cr,
-                                      const glTemplate  *template,
+                                      lglTemplate       *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,
+                                      lglTemplate       *template,
                                       gdouble            x0,
                                       gdouble            y0);
 
@@ -80,9 +75,9 @@ static void draw_cd_label_outline     (cairo_t           *cr,
 /* Create new pixbuf with mini preview of template                          */
 /****************************************************************************/
 GdkPixbuf *
-gl_mini_preview_pixbuf_new (glTemplate *template,
-                           gint        width,
-                           gint        height)
+gl_mini_preview_pixbuf_new (lglTemplate *template,
+                           gint         width,
+                           gint         height)
 {
        cairo_surface_t   *surface;
        cairo_t           *cr;
@@ -110,7 +105,7 @@ gl_mini_preview_pixbuf_new (glTemplate *template,
         cairo_paint (cr);
        cairo_restore (cr);
 
-       cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
+       cairo_set_antialias (cr, CAIRO_ANTIALIAS_GRAY);
 
        /* Set scale and offset */
        w = width - 1;
@@ -143,17 +138,17 @@ gl_mini_preview_pixbuf_new (glTemplate *template,
 /*--------------------------------------------------------------------------*/
 static void
 draw_paper (cairo_t           *cr,
-           const glTemplate  *template,
+           lglTemplate       *template,
            gdouble            scale)
 {
        gl_debug (DEBUG_MINI_PREVIEW, "START");
 
        cairo_save (cr);
        cairo_rectangle (cr, 0.0, 0.0, template->page_width, template->page_height);
-       cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+       cairo_set_source_rgb (cr, PAPER_RGB_ARGS);
        cairo_fill_preserve (cr);
-       cairo_set_line_width (cr, 1/scale);
-       cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+       cairo_set_line_width (cr, PAPER_OUTLINE_WIDTH_PIXELS/scale);
+       cairo_set_source_rgb (cr, PAPER_OUTLINE_RGB_ARGS);
        cairo_stroke (cr);
        cairo_restore (cr);
 
@@ -165,24 +160,23 @@ draw_paper (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 draw_label_outlines (cairo_t           *cr,
-                    const glTemplate  *template,
+                    lglTemplate       *template,
                     gdouble            scale)
 {
-       const glTemplateLabelType *label_type;
-       gint                       i, n_labels;
-       glTemplateOrigin          *origins;
+       const lglTemplateFrame *frame;
+       gint                    i, n_labels;
+       lglTemplateOrigin      *origins;
 
        gl_debug (DEBUG_MINI_PREVIEW, "START");
 
        cairo_save (cr);
 
-       cairo_set_line_width (cr, 1.0/scale);
-       cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+       cairo_set_line_width (cr, LABEL_OUTLINE_WIDTH_PIXELS/scale);
 
-       label_type = gl_template_get_first_label_type (template);
+        frame = (lglTemplateFrame *)template->frames->data;
 
-       n_labels = gl_template_get_n_labels (label_type);
-       origins  = gl_template_get_origins (label_type);
+       n_labels = lgl_template_frame_get_n_labels (frame);
+       origins  = lgl_template_frame_get_origins (frame);
 
        for ( i=0; i < n_labels; i++ ) {
 
@@ -202,62 +196,23 @@ draw_label_outlines (cairo_t           *cr,
 /*--------------------------------------------------------------------------*/
 static void
 draw_label_outline (cairo_t           *cr,
-                   const glTemplate  *template,
+                   lglTemplate       *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;
+        cairo_translate (cr, x0, y0);
 
-       case GL_TEMPLATE_SHAPE_ROUND:
-               draw_round_label_outline (cr, template, x0, y0);
-               break;
+        gl_cairo_label_path (cr, template, FALSE, FALSE);
 
-       case GL_TEMPLATE_SHAPE_CD:
-               draw_cd_label_outline (cr, template, x0, y0);
-               break;
+       cairo_set_source_rgb (cr, LABEL_RGB_ARGS);
+        cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+        cairo_fill_preserve (cr);
 
-       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_rectangle (cr, x0, y0, w, h);
+       cairo_set_source_rgb (cr, LABEL_OUTLINE_RGB_ARGS);
        cairo_stroke (cr);
 
        cairo_restore (cr);
@@ -265,91 +220,13 @@ draw_rect_label_outline (cairo_t           *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_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;
-
-       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;
-
-       if ( w == h )
-       {
-               /* Simple CD */
-               cairo_arc (cr, xc, yc, r1, 0.0, 2*M_PI);
-               cairo_stroke (cr);
-       }
-       else
-       {
-               /* Credit Card CD (One or both dimensions trucated) */
-               gdouble theta1, theta2;
-
-               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);
-               cairo_stroke (cr);
-       }
-
-       /* Hole */
-       cairo_arc (cr, xc, yc, r2, 0.0, 2*M_PI);
-       cairo_stroke (cr);
-       
-       cairo_restore (cr);
-
-       gl_debug (DEBUG_MINI_PREVIEW, "END");
-}
-
 
 
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */