f-spot r3697 - in trunk: . icons src src/Widgets



Author: sdelcroix
Date: Tue Feb 19 09:31:57 2008
New Revision: 3697
URL: http://svn.gnome.org/viewvc/f-spot?rev=3697&view=rev

Log:
2008-02-19  Stephane Delcroix  <sdelcroix novell com>

	* src/Widgets/CairoUtils.cs:
	* src/Loupe.cs: Obsoleting method now available in the bindings

	* src/Makefile.am:
	* src/Widgets/CustomPrintWidget.cs:
	* src/PrintOperation.cs:
	* src/MainWindow.cs:
	* src/PrintDialog.cs: new Gtk2.10 print dialog and operation, #ifdef
	old code for backward compatibility

	* configure.in: require Mono.Cairo

	* icons/Makefile.am:
	* icons/flower.png: sample image for the print dialog


Added:
   trunk/icons/flower.png   (contents, props changed)
   trunk/src/PrintOperation.cs
   trunk/src/Widgets/CustomPrintWidget.cs
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/icons/Makefile.am
   trunk/src/Loupe.cs
   trunk/src/MainWindow.cs
   trunk/src/Makefile.am
   trunk/src/PrintDialog.cs
   trunk/src/Widgets/CairoUtils.cs

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Feb 19 09:31:57 2008
@@ -42,7 +42,7 @@
 
 dnl -- check for various mono DLLs that we need.
 
-needed_dlls="Mono.Data.SqliteClient Mono.Posix System.Runtime.Remoting System.Web System.Web.Services"
+needed_dlls="Mono.Data.SqliteClient Mono.Posix System.Runtime.Remoting System.Web System.Web.Services Mono.Cairo"
 for i in $needed_dlls; do
   AC_MSG_CHECKING([for $i.dll])
   if test ! \( -e `$PKG_CONFIG --variable=prefix mono`/lib/mono/2.0/$i.dll -o -e `$PKG_CONFIG --variable=prefix mono`/lib64/mono/2.0//$i.dll \); then

Modified: trunk/icons/Makefile.am
==============================================================================
--- trunk/icons/Makefile.am	(original)
+++ trunk/icons/Makefile.am	Tue Feb 19 09:31:57 2008
@@ -127,5 +127,6 @@
 
 	
 MAINTAINERCLEANFILES = Makefile.in
-EXTRA_DIST = $(wildcard *.png *.svg)
+EXTRA_DIST = $(wildcard *.png *.svg)	\
+	flower.png
 

Added: trunk/icons/flower.png
==============================================================================
Binary file. No diff available.

Modified: trunk/src/Loupe.cs
==============================================================================
--- trunk/src/Loupe.cs	(original)
+++ trunk/src/Loupe.cs	Tue Feb 19 09:31:57 2008
@@ -572,6 +572,7 @@
 								double        pixbuf_x,
 								double        pixbuf_y);
 
+		[Obsolete ("use Gdk.CairoHelper.SetSourcePixbuf instead")]
 		static void SetSourcePixbuf (Context ctx, Gdk.Pixbuf pixbuf, double x, double y)
 		{
 			gdk_cairo_set_source_pixbuf (ctx.Handle, pixbuf.Handle, x, y);

Modified: trunk/src/MainWindow.cs
==============================================================================
--- trunk/src/MainWindow.cs	(original)
+++ trunk/src/MainWindow.cs	Tue Feb 19 09:31:57 2008
@@ -1533,7 +1533,12 @@
 	
 	void HandlePrintCommand (object sender, EventArgs e)
 	{
+#if !GTK_2_10
 		new FSpot.PrintDialog (SelectedPhotos ());
+#else
+		FSpot.PrintOperation print = new FSpot.PrintOperation (SelectedPhotos ());
+		print.Run (PrintOperationAction.PrintDialog, null);
+#endif
 	}
 
 	private Gtk.Dialog info_display_window;

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Feb 19 09:31:57 2008
@@ -196,6 +196,7 @@
 	$(srcdir)/Preferences.cs 		\
 	$(srcdir)/PreviewPopup.cs 		\
 	$(srcdir)/PrintDialog.cs		\
+	$(srcdir)/PrintOperation.cs		\
 	$(srcdir)/ProgressDialog.cs		\
 	$(srcdir)/RatingFilter.cs		\
 	$(srcdir)/QueuedSqliteDatabase.cs	\
@@ -239,6 +240,7 @@
 	$(srcdir)/Widgets/CairoUtils.cs		\
 	$(srcdir)/Widgets/ComplexMenuItem.cs	\
 	$(srcdir)/Widgets/CompositeUtils.cs	\
+	$(srcdir)/Widgets/CustomPrintWidget.cs	\
 	$(srcdir)/Widgets/Dissolve.cs		\
 	$(srcdir)/Widgets/FindBar.cs		\
 	$(srcdir)/Widgets/GdkUtils.cs		\
@@ -288,6 +290,7 @@
 	-pkg:gtk-sharp-2.0			\
 	-pkg:gnome-sharp-2.0			\
 	-r:Mono.Posix				\
+	-r:MCairo=Mono.Cairo			\
 	$(GCONF_PKG)				\
 	$(LINK_DBUS)
 
@@ -307,6 +310,7 @@
 	-r:Mono.Data.SqliteClient		\
 	-r:Mono.Posix				\
 	-r:Mono.Security			\
+	-r:MCairo=Mono.Cairo			\
 	-r:ICSharpCode.SharpZipLib		\
 	-r:FSpot.Core.dll			\
 	-r:FSpot.Query.dll			\
@@ -327,7 +331,8 @@
 	$(F_SPOT_DISTRESOURCES)				\
 	$(top_srcdir)/COPYING				\
 	$(top_srcdir)/icons/f-spot-not.png		\
-	$(top_srcdir)/icons/f-spot-logo.svg
+	$(top_srcdir)/icons/f-spot-logo.svg		\
+	$(top_srcdir)/icons/flower.png
 
 RESOURCES = $(foreach res,$(F_SPOT_RESOURCES), $(addprefix -resource:,$(res)),$(notdir $(res)))
 

Modified: trunk/src/PrintDialog.cs
==============================================================================
--- trunk/src/PrintDialog.cs	(original)
+++ trunk/src/PrintDialog.cs	Tue Feb 19 09:31:57 2008
@@ -3,6 +3,7 @@
 using Gtk;
 using FSpot.UI.Dialog;
 
+#if !GTK_2_10
 namespace FSpot {
 	public class PrintDialog {
 		[Glade.Widget] private Gtk.Dialog print_dialog;
@@ -199,3 +200,4 @@
 		}
 	}
 }
+#endif

Added: trunk/src/PrintOperation.cs
==============================================================================
--- (empty file)
+++ trunk/src/PrintOperation.cs	Tue Feb 19 09:31:57 2008
@@ -0,0 +1,225 @@
+/*
+ * FSpot.PrintOperation.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+#if GTK_2_10
+extern alias MCairo;
+using System;
+using System.Runtime.InteropServices;
+
+using FSpot.Widgets;
+
+namespace FSpot
+{
+	public class PrintOperation : Gtk.PrintOperation
+	{
+		IBrowsableItem [] selected_photos;
+		int photos_per_page = 1;
+		CustomPrintWidget.FitMode fit = CustomPrintWidget.FitMode.Scaled;
+		bool repeat, white_borders, crop_marks;
+		string comment;
+
+		public PrintOperation (IBrowsableItem [] selected_photos) : base ()
+		{
+			this.selected_photos = selected_photos;
+			NPages = selected_photos.Length;
+		}
+
+		protected override void OnBeginPrint (Gtk.PrintContext context)
+		{
+			base.OnBeginPrint (context);
+		}
+
+		protected override Gtk.Widget OnCreateCustomWidget ()
+		{
+			Gtk.Widget widget = new CustomPrintWidget ();
+			widget.ShowAll ();
+			(widget as CustomPrintWidget).Changed += OnCustomWidgetChanged;
+			OnCustomWidgetChanged (widget);
+			return widget;
+		}
+
+		protected override void OnCustomWidgetApply (Gtk.Widget widget)
+		{
+			CustomPrintWidget cpw = widget as CustomPrintWidget;
+			UseFullPage = cpw.UseFullPage;
+			photos_per_page = cpw.PhotosPerPage;
+			repeat = cpw.Repeat;
+			NPages = repeat ? selected_photos.Length :(int) Math.Ceiling (1.0 * selected_photos.Length / photos_per_page);
+			fit = cpw.Fitmode;
+			white_borders = cpw.WhiteBorders;
+			crop_marks = cpw.CropMarks;
+			comment = cpw.CustomText;
+		}
+
+		protected void OnCustomWidgetChanged (Gtk.Widget widget)
+		{
+			OnCustomWidgetApply (widget);
+			using (MCairo::Cairo.ImageSurface surface = new MCairo::Cairo.ImageSurface (MCairo::Cairo.Format.ARGB32, 360, 254)) {
+				using (MCairo::Cairo.Context gr = new MCairo::Cairo.Context (surface)) {
+					gr.Color = new MCairo::Cairo.Color (1, 1, 1);
+					gr.Rectangle (0, 0, 360, 254);
+					gr.Fill ();
+					using (Gdk.Pixbuf pixbuf = Gdk.Pixbuf.LoadFromResource ("flower.png")) {
+						DrawImage (gr, pixbuf,0, 0, 360, 254);
+					}
+				}
+				(widget as CustomPrintWidget).PreviewImage.Pixbuf = CreatePixbuf (surface);
+			}
+		}
+
+		protected override void OnDrawPage (Gtk.PrintContext context, int page_nr)
+		{
+			base.OnDrawPage (context, page_nr);
+			MCairo::Cairo.Context cr = context.CairoContext;	
+
+			int ppx, ppy;
+			switch (photos_per_page) {
+			default:
+			case 1: ppx = ppy =1; break;
+			case 2: ppx = 1; ppy = 2; break;
+			case 4: ppx = ppy = 2; break;
+			case 9: ppx = ppy = 3; break;
+			}
+
+			//FIXME: if paper is landscape, swap ppx with ppy
+
+			double w = context.Width / ppx;
+			double h = context.Height / ppy;
+
+			for (int x = 0; x <= ppx; x++) {
+				for (int y = 0; y <= ppy; y++) {
+					int p_index = repeat ? page_nr : page_nr * photos_per_page + y * ppx + x;
+					if (crop_marks)
+						DrawCropMarks (cr, x*w, y*h, w*.1);
+					if (x == ppx || y == ppy || p_index >= selected_photos.Length)
+						continue;
+					using (ImageFile img = new ImageFile (selected_photos[p_index].DefaultVersionUri))
+					{
+						Gdk.Pixbuf pixbuf = img.Load ();
+						//Gdk.Pixbuf pixbuf = img.Load (100, 100);
+						bool rotated = false;
+						if (Math.Sign ((double)pixbuf.Width/pixbuf.Height - 1.0) != Math.Sign (w/h - 1.0)) {
+							Gdk.Pixbuf d_pixbuf = pixbuf.RotateSimple (Gdk.PixbufRotation.Counterclockwise);
+							pixbuf.Dispose ();
+							pixbuf = d_pixbuf;
+							rotated = true;
+						}
+
+						DrawImage (cr, pixbuf, x * w, y * h, w, h);
+						DrawComment (context, (x + 1) * w, (rotated ? y : y + 1) * h, (rotated ? w : h) * .025, comment, rotated);
+						pixbuf.Dispose ();
+					}
+				}
+			}
+
+		}
+
+		protected override void OnEndPrint (Gtk.PrintContext context)
+		{
+			base.OnEndPrint (context);
+			context.Dispose ();
+		}
+
+		protected override void OnRequestPageSetup (Gtk.PrintContext context, int page_nr, Gtk.PageSetup setup)
+		{
+			base.OnRequestPageSetup (context, page_nr, setup);
+		}
+
+		private void DrawCropMarks (MCairo::Cairo.Context cr, double x, double y, double length)
+		{
+			cr.Save ();
+			cr.Color = new MCairo::Cairo.Color (0, 0, 0);
+			cr.MoveTo (x - length/2, y);
+			cr.LineTo (x + length/2, y);
+			cr.MoveTo (x, y - length/2);
+			cr.LineTo (x, y + length/2);
+			cr.LineWidth = .2;
+			cr.SetDash (new double[] {length*.4, length*.2}, 0);
+			cr.Stroke ();
+			cr.Restore ();
+		}
+
+		private static void DrawComment (Gtk.PrintContext context, double x, double y, double h, string comment, bool rotated)
+		{
+			if (comment == null || comment == String.Empty)
+				return;
+
+			MCairo::Cairo.Context cr = context.CairoContext;
+			cr.Save ();
+			Pango.Layout layout = context.CreatePangoLayout ();
+			Pango.FontDescription desc = Pango.FontDescription.FromString ("sans 14");
+			layout.FontDescription = desc;
+			layout.SetText (comment);
+			int lay_w, lay_h;
+			layout.GetPixelSize (out lay_w, out lay_h);
+			double scale = h/lay_h;
+			if (rotated) {
+				cr.Translate (x - h, y + lay_w * scale);
+				cr.Rotate (- Math.PI / 2);
+			}
+			else
+				cr.Translate (x - lay_w * scale, y - h);
+			cr.Scale (scale, scale);
+			Pango.CairoHelper.ShowLayout (context.CairoContext, layout);
+			cr.Restore ();
+		}
+	
+
+		private void DrawImage (MCairo::Cairo.Context cr, Gdk.Pixbuf pixbuf, double x, double y, double w, double h)
+		{
+			double scalex, scaley;
+			switch (fit) {
+			case CustomPrintWidget.FitMode.Zoom:
+				scalex = scaley = Math.Max (w/pixbuf.Width, h/pixbuf.Height);
+				break;
+			case CustomPrintWidget.FitMode.Fill:
+				scalex = w/pixbuf.Width;
+				scaley = h/pixbuf.Height;
+				break;
+			default:
+			case CustomPrintWidget.FitMode.Scaled:
+				scalex = scaley = Math.Min (w/pixbuf.Width, h/pixbuf.Height);
+				break;
+			}	
+
+			double rectw = w / scalex;
+			double recth = h / scaley;
+
+			cr.Save ();
+			if (white_borders)
+				cr.Translate (w * .025, h * .025);
+
+			cr.Translate (x, y);
+			if (white_borders)
+				cr.Scale (.95, .95);
+			cr.Scale (scalex, scaley);
+			cr.Rectangle (0, 0, rectw, recth);
+			Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, (rectw - pixbuf.Width) / 2.0, (recth - pixbuf.Height) / 2.0);
+			cr.Fill ();
+
+			if (white_borders) {
+				cr.Rectangle (0, 0 ,rectw, recth);
+				cr.Color = new MCairo::Cairo.Color (0, 0, 0);
+				cr.LineWidth = 1 / scalex;
+				cr.Stroke ();
+			}
+			cr.Restore ();
+		}
+
+		[DllImport("libfspot")]
+		static extern IntPtr f_pixbuf_from_cairo_surface (IntPtr handle);
+		
+		private static Gdk.Pixbuf CreatePixbuf (MCairo::Cairo.Surface s)
+		{
+			IntPtr result = f_pixbuf_from_cairo_surface (s.Handle);
+			return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
+		}
+	}
+}
+#endif

Modified: trunk/src/Widgets/CairoUtils.cs
==============================================================================
--- trunk/src/Widgets/CairoUtils.cs	(original)
+++ trunk/src/Widgets/CairoUtils.cs	Tue Feb 19 09:31:57 2008
@@ -28,6 +28,7 @@
 								double        pixbuf_x,
 								double        pixbuf_y);
 		
+		[Obsolete ("use Gdk.CairoHelper.SetSourcePixbuf instead")]
 		public static void SetSourcePixbuf (Context ctx, Gdk.Pixbuf pixbuf, double x, double y)
 		{
 			gdk_cairo_set_source_pixbuf (ctx.Handle, pixbuf.Handle, x, y);

Added: trunk/src/Widgets/CustomPrintWidget.cs
==============================================================================
--- (empty file)
+++ trunk/src/Widgets/CustomPrintWidget.cs	Tue Feb 19 09:31:57 2008
@@ -0,0 +1,134 @@
+/*
+ * FSpot.Widgets.CustomPrintWidget.cs
+ *
+ * Author(s):
+ *	Stephane Delcroix  <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+using Gtk;
+
+namespace FSpot.Widgets
+{
+	public class CustomPrintWidget : VBox
+	{
+		public delegate void ChangedHandler (Gtk.Widget widget);
+
+		public enum FitMode {
+			Zoom,
+			Scaled,
+			Fill,
+		}
+
+		Gtk.Image preview_image;
+		CheckButton fullpage;
+
+		RadioButton ppp1, ppp2, ppp4, ppp9;
+		RadioButton zoom, fill, scaled;
+
+		CheckButton repeat, white_border, crop_marks;
+		Entry custom_text;
+	
+		public event ChangedHandler Changed;
+		private void TriggerChanged (object sender, EventArgs e)
+		{
+			if (Changed != null)
+				Changed (this);
+		}
+
+		public bool CropMarks {
+			get { return crop_marks.Active; }
+		}
+
+		public string CustomText {
+			get { return custom_text.Text; }
+		}
+
+		public FitMode Fitmode {
+			get {
+				if (zoom.Active)	return FitMode.Zoom;
+				else if (fill.Active)	return FitMode.Fill;
+				else if (scaled.Active)	return FitMode.Scaled;
+				else
+					throw new Exception ("Something is fucked on this GUI");
+			}
+		}
+
+		public int PhotosPerPage {
+			get {
+				if (ppp1.Active)	return 1;
+				else if (ppp2.Active)	return 2;
+				else if (ppp4.Active)	return 4;
+				else if (ppp9.Active)	return 9;
+				else
+					throw new Exception ("Something is fucked on this GUI");
+			}
+		}
+
+		public Gtk.Image PreviewImage {
+			get { return preview_image; }
+		}
+
+		public bool Repeat {
+			get { return repeat.Active; }
+		}
+
+		public bool UseFullPage {
+			get { return fullpage.Active; }
+		}
+
+		public bool WhiteBorders {
+			get { return white_border.Active; }
+		}
+
+		public CustomPrintWidget () : base ()
+		{
+			HBox upper = new HBox ();
+			preview_image = new Gtk.Image ();
+			upper.PackStart (preview_image, false, false, 0);
+
+			Frame ppp_frame = new Frame ("Photos per page");
+			VBox vb = new VBox ();
+
+			vb.PackStart (ppp1 = new RadioButton ("1"), false, false, 0);
+			vb.PackStart (ppp2 = new RadioButton (ppp1, "2"), false, false, 0);
+			vb.PackStart (ppp4 = new RadioButton (ppp1, "4"), false, false, 0);
+			vb.PackStart (ppp9 = new RadioButton (ppp1, "9"), false, false, 0);
+//			ppp1.Toggled += TriggerChanged;
+//			ppp2.Toggled += TriggerChanged;
+//			ppp4.Toggled += TriggerChanged;
+//			ppp9.Toggled += TriggerChanged;
+
+			vb.PackStart (repeat = new CheckButton ("Repeat"), false, false, 0);
+			vb.PackStart (crop_marks = new CheckButton ("Print cut marks"), false, false, 0);
+//			crop_marks.Toggled += TriggerChanged;
+
+			ppp_frame.Child = vb;
+			upper.PackStart (ppp_frame, true, true, 0);
+
+			this.PackStart (upper, true, true, 0);
+			this.PackStart (fullpage = new CheckButton ("Full Page (no margin)"), false, false, 0);
+			
+			HBox hb = new HBox ();
+			hb.PackStart (zoom = new RadioButton ("Zoom"), false, false, 0);
+			hb.PackStart (fill = new RadioButton (zoom, "Fill"), false, false, 0);
+			hb.PackStart (scaled = new RadioButton (zoom, "Scaled"), false, false, 0);
+			this.PackStart (hb, false, false, 0);
+			zoom.Toggled += TriggerChanged;
+			fill.Toggled += TriggerChanged;
+			scaled.Toggled += TriggerChanged;
+
+			this.PackStart (white_border = new CheckButton ("White borders"), false, false, 0);
+			white_border.Toggled += TriggerChanged;
+
+			hb = new HBox ();
+			hb.PackStart (new Label ("Custom Text: "), false, false, 0);
+
+			hb.PackStart (custom_text = new Entry (), true, true, 0);
+			this.PackStart (hb, false, false, 0);
+			TriggerChanged (this, null);
+		}
+	}
+}



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