[glide] Begin adding some vector based PDF printing



commit 7b99746b54d90ba18fa2dc103f3abc115bc9f546
Author: Robert Carr <racarr Valentine localdomain>
Date:   Mon Apr 26 19:15:50 2010 -0400

    Begin adding some vector based PDF printing

 po/Makefile              |    2 +-
 po/Makefile.in           |    2 +-
 src/Makefile.am          |    6 +++-
 src/glide-actor.c        |   10 ++++++
 src/glide-actor.h        |    7 ++++
 src/glide-cairo-util.c   |   29 ++++++++++++++++
 src/glide-cairo-util.h   |   31 ++++++++++++++++++
 src/glide-pdf-exporter.c |   79 +++++++++++++++++++++++++++++++++++++++++++++
 src/glide-pdf-exporter.h |   31 ++++++++++++++++++
 src/glide-slide.c        |   46 ++++++++++++++++++++++++++
 src/glide-window.c       |   80 ++--------------------------------------------
 11 files changed, 243 insertions(+), 80 deletions(-)
---
diff --git a/po/Makefile b/po/Makefile
index abaf402..10deb7e 100644
--- a/po/Makefile
+++ b/po/Makefile
@@ -21,7 +21,7 @@ GETTEXT_PACKAGE = glide
 PACKAGE = glide
 VERSION = 0.1
 
-SHELL = /bin/bash
+SHELL = /bin/sh
 
 srcdir = .
 top_srcdir = ..
diff --git a/po/Makefile.in b/po/Makefile.in
index ed307bb..29ec924 100644
--- a/po/Makefile.in
+++ b/po/Makefile.in
@@ -21,7 +21,7 @@ GETTEXT_PACKAGE = glide
 PACKAGE = glide
 VERSION = 0.1
 
-SHELL = /bin/bash
+SHELL = /bin/sh
 
 srcdir = .
 top_srcdir = ..
diff --git a/src/Makefile.am b/src/Makefile.am
index 28fa80f..ef94359 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,7 +51,11 @@ glide_SOURCES = \
 	glide-animations.c \
 	glide-animations.h \
 	glide-undo-manager.c \
-	glide-undo-manager.h
+	glide-undo-manager.h \
+	glide-pdf-exporter.c \
+	glide-pdf-exporter.h \
+	glide-cairo-util.c \
+	glide-cairo-util.h
 
 glide_LDFLAGS = \
 	-Wl,--export-dynamic
diff --git a/src/glide-actor.c b/src/glide-actor.c
index eefa9fc..9fac5b7 100644
--- a/src/glide-actor.c
+++ b/src/glide-actor.c
@@ -236,6 +236,16 @@ glide_actor_deserialize (GlideActor *actor, JsonObject *actor_obj)
   glide_json_object_restore_actor_geometry (actor_obj, CLUTTER_ACTOR (actor));
 }
 
+void 
+glide_actor_print (GlideActor *a, cairo_t *cr)
+{
+  GlideActorClass *klass;
+  
+  klass = GLIDE_ACTOR_GET_CLASS (a);
+  if (klass->print)
+    klass->print (a, cr);
+}
+
 
 GlideActor *
 glide_actor_construct_from_json (JsonObject *actor_obj)
diff --git a/src/glide-actor.h b/src/glide-actor.h
index 9ead61e..bf240bd 100644
--- a/src/glide-actor.h
+++ b/src/glide-actor.h
@@ -25,6 +25,9 @@
 
 #include <clutter/clutter.h>
 #include <json-glib/json-glib.h>
+
+#include <cairo.h>
+
 #include "glide-stage-manager.h"
 
 G_BEGIN_DECLS
@@ -68,6 +71,8 @@ struct _GlideActorClass
   
   void (* selected) (GlideActor *actor);
   void (* deselected) (GlideActor *actor);
+  
+  void (* print) (GlideActor *actor, cairo_t *cr);
 };
 
 #define GLIDE_ACTOR_DISPLAY_NAME(actor) \
@@ -91,6 +96,8 @@ void glide_actor_deserialize (GlideActor *actor, JsonObject *obj);
 
 GlideUndoManager *glide_actor_get_undo_manager (GlideActor *actor);
 
+void glide_actor_print (GlideActor *actor, cairo_t *cr);
+
 
 
 G_END_DECLS
diff --git a/src/glide-cairo-util.c b/src/glide-cairo-util.c
new file mode 100644
index 0000000..05cc796
--- /dev/null
+++ b/src/glide-cairo-util.c
@@ -0,0 +1,29 @@
+/*
+ * glide-cairo-util.c
+ * This file is part of glide
+ *
+ * Copyright (C) 2010 - Robert Carr
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include "glide-cairo-util.h"
+
+void
+glide_cairo_set_clutter_color (cairo_t *cr, ClutterColor *c)
+{
+  cairo_set_source_rgba (cr, c->red/255.0, c->green/255.0, c->blue/255.0, c->alpha/255.0);
+}
diff --git a/src/glide-cairo-util.h b/src/glide-cairo-util.h
new file mode 100644
index 0000000..86886dc
--- /dev/null
+++ b/src/glide-cairo-util.h
@@ -0,0 +1,31 @@
+/*
+ * glide-cairo-util.h
+ * This file is part of glide
+ *
+ * Copyright (C) 2010 - Robert Carr
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#ifndef __GLIDE_CAIRO_UTIL_H__
+#define __GLIDE_CAIRO_UTIL_H__
+
+#include <cairo.h>
+#include <clutter/clutter.h>
+
+void glide_cairo_set_clutter_color (cairo_t *cr, ClutterColor *c);
+
+#endif
diff --git a/src/glide-pdf-exporter.c b/src/glide-pdf-exporter.c
new file mode 100644
index 0000000..f5e3c9e
--- /dev/null
+++ b/src/glide-pdf-exporter.c
@@ -0,0 +1,79 @@
+/*
+ * glide-pdf-exporter.c
+ * This file is part of glide
+ *
+ * Copyright (C) 2010 - Robert Carr
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+#include "glide-pdf-exporter.h"
+#include "glide-actor.h"
+#include "glide-gtk-util.h"
+
+#include <cairo.h>
+#include <cairo-pdf.h>
+
+static void
+glide_pdf_exporter_export_real (GlideDocument *d,
+				const gchar *filename)
+{
+  cairo_surface_t *pdf_surface;
+  cairo_t *cr;
+  gint width, height, i;
+  
+  glide_document_get_size (d, &width, &height);
+  
+  pdf_surface = cairo_pdf_surface_create (filename, width, height);
+  cr = cairo_create (pdf_surface);
+  
+  for (i = 0; i < glide_document_get_n_slides (d); i++)
+    {
+      GlideSlide *s = glide_document_get_nth_slide (d, i);
+      
+      glide_actor_print (GLIDE_ACTOR (s), cr);
+      cairo_surface_show_page (pdf_surface);
+    }
+    
+  cairo_surface_flush (pdf_surface);
+  
+  cairo_destroy (cr);
+  cairo_surface_destroy (pdf_surface);
+  
+}
+
+static void
+glide_pdf_exporter_response_callback (GtkDialog *dialog,
+				      int response,
+				      gpointer user_data)
+{
+  GlideDocument *d = (GlideDocument *)user_data;
+  if (response == GTK_RESPONSE_ACCEPT)
+    {
+      gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+      
+      glide_pdf_exporter_export_real (d, filename);
+      g_free (filename);
+    }
+  
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+void
+glide_pdf_exporter_export (GlideDocument *document)
+{
+  glide_gtk_util_show_save_dialog (G_CALLBACK (glide_pdf_exporter_response_callback), document);
+}
diff --git a/src/glide-pdf-exporter.h b/src/glide-pdf-exporter.h
new file mode 100644
index 0000000..42e2430
--- /dev/null
+++ b/src/glide-pdf-exporter.h
@@ -0,0 +1,31 @@
+/*
+ * glide-pdf-exporter.h
+ * This file is part of glide
+ *
+ * Copyright (C) 2010 - Robert Carr
+ *
+ * This program 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
+ * (at your option) any later version.
+ *
+ * This program 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.
+ */
+
+
+#ifndef __GLIDE_PDF_EXPORTER_H__
+#define __GLIDE_PDF_EXPORTER_H__
+
+#include "glide-document.h"
+
+void glide_pdf_exporter_export (GlideDocument *document);
+
+#endif
diff --git a/src/glide-slide.c b/src/glide-slide.c
index 343a485..392d6c9 100644
--- a/src/glide-slide.c
+++ b/src/glide-slide.c
@@ -30,6 +30,8 @@
 
 #include "glide-debug.h"
 
+#include "glide-cairo-util.h"
+
 static void clutter_container_iface_init (ClutterContainerIface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GlideSlide, glide_slide, GLIDE_TYPE_ACTOR,
@@ -488,6 +490,49 @@ glide_slide_serialize (GlideActor *self)
 }
 
 static void
+glide_slide_print_background_image (GlideSlide *s,
+				    cairo_t *cr)
+{
+  GdkPixbuf *p;
+  gfloat width, height;
+  
+  clutter_actor_get_size (CLUTTER_ACTOR (s), &width, &height);
+  
+  // TODO: Error
+  p = gdk_pixbuf_new_from_file_at_size (s->priv->background, width, height, NULL);
+  gdk_cairo_set_source_pixbuf (cr, p, 0, 0);
+  
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
+  
+  g_object_unref (G_OBJECT (p));
+}
+
+static void
+glide_slide_print_background (GlideSlide *s,
+			      cairo_t *cr)
+{
+  gfloat width, height;
+  
+  clutter_actor_get_size (CLUTTER_ACTOR (s), &width, &height);
+  glide_cairo_set_clutter_color (cr, &s->priv->color);
+  
+  cairo_rectangle (cr, 0, 0, width, height);
+  cairo_fill (cr);
+  
+  glide_slide_print_background_image (s, cr);
+}
+
+static void
+glide_slide_print (GlideActor *a,
+		   cairo_t *cr)
+{
+  GlideSlide *s = GLIDE_SLIDE (a);
+  
+  glide_slide_print_background (s, cr);
+}
+
+static void
 glide_slide_class_init (GlideSlideClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -495,6 +540,7 @@ glide_slide_class_init (GlideSlideClass *klass)
   GlideActorClass *glide_class = GLIDE_ACTOR_CLASS (klass);
   
   glide_class->serialize = glide_slide_serialize;
+  glide_class->print = glide_slide_print;
   
   object_class->get_property = glide_slide_get_property;
   object_class->set_property = glide_slide_set_property;
diff --git a/src/glide-window.c b/src/glide-window.c
index efcd6bc..aa207bf 100644
--- a/src/glide-window.c
+++ b/src/glide-window.c
@@ -25,9 +25,6 @@
 #include <gdk/gdkkeysyms.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
-#include <cairo.h>
-#include <cairo-pdf.h>
-
 #include "glide-window.h"
 #include "glide-window-private.h"
 
@@ -45,6 +42,8 @@
 
 #include "glide-dirs.h"
 
+#include "glide-pdf-exporter.h"
+
 #define GLIDE_WINDOW_UI_OBJECT(w, obj) (gtk_builder_get_object (w->priv->builder, obj))
 
 
@@ -1381,86 +1380,13 @@ glide_window_load_ui (GlideWindow *w)
   gtk_widget_reparent (main_box, GTK_WIDGET (w));
 }
 
-static void
-glide_window_export_pdf_real (GlideWindow *w,
-			      const gchar *filename)
-{
-  cairo_surface_t *pdf_surface;
-  cairo_t *cr;
-  gint width, height;
-  gint o_slide;
-  int i = 0;
-  
-  glide_window_fullscreen_stage (w);  
-  while (g_main_context_pending (NULL))
-    g_main_context_iteration (NULL, TRUE);
-  
-  width = clutter_actor_get_width (w->priv->stage);
-  height = clutter_actor_get_height (w->priv->stage);
-
-  pdf_surface = cairo_pdf_surface_create (filename, width, height);
-  cr = cairo_create (pdf_surface);
-  
-  o_slide = glide_stage_manager_get_current_slide (w->priv->manager);
-  
-  for (i = 0; i < glide_document_get_n_slides (w->priv->document); i++)
-    {
-      guchar *pixels;
-      guchar *p;
-      GdkPixbuf *pb;
-
-      glide_stage_manager_set_current_slide (w->priv->manager, i);
-
-      pixels = clutter_stage_read_pixels (CLUTTER_STAGE (w->priv->stage), 0, 0, width, height);
-      for (p = pixels + width * height * 4; p > pixels; p -= 3)
-	*(--p) = 255; 
-
-
-      pb = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE,
-				     8, width, height, width * 4,
-				     (GdkPixbufDestroyNotify) g_free,
-				     NULL); 
-      
-      gdk_cairo_set_source_pixbuf (cr, pb, 0, 0);
-      cairo_rectangle (cr, 0, 0, width, height);
-      cairo_fill (cr);
-
-      cairo_surface_show_page (pdf_surface);      
-      
-      g_object_unref (G_OBJECT (pb));
-    }
-  cairo_surface_flush (pdf_surface);
-
-  cairo_destroy (cr);
-  cairo_surface_destroy (pdf_surface);
-  
-  glide_window_unfullscreen_stage (w);
-  glide_stage_manager_set_current_slide (w->priv->manager, o_slide);
-}
-
-static void
-glide_window_export_pdf_response_callback (GtkDialog *dialog,
-					  int response,
-					  gpointer user_data)
-{
-  GlideWindow *w = (GlideWindow *) user_data;
-  if (response == GTK_RESPONSE_ACCEPT)
-    {
-      gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-      
-      glide_window_export_pdf_real (w, filename);
-    }
-  
-  gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
 void
 glide_window_export_pdf_action_activate (GtkAction *action,
 					 gpointer user_data)
 {
   GlideWindow *w = (GlideWindow *)user_data;
   
-  glide_gtk_util_show_save_dialog(G_CALLBACK (glide_window_export_pdf_response_callback), w);
+  glide_pdf_exporter_export (w->priv->document);
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]