tomboy r1997 - in trunk: . Tomboy/Addins/PrintNotes



Author: sharm
Date: Mon May 12 07:12:52 2008
New Revision: 1997
URL: http://svn.gnome.org/viewvc/tomboy?rev=1997&view=rev

Log:
* Tomboy.mdp, Tomboy/Addins/PrintNotes/PrintNotesNoteAddin.cs,
  Tomboy/Addins/PrintNotes/PrintNotes.addin.xml,
  Tomboy/Addins/PrintNotes/Makefile.am: Update printing addin to use
  Gtk.Print.
* Tomboy/Addins/PrintNotes/gtksourceprintjob.c,
  Tomboy/Addins/PrintNotes/gtksourceprintjob.h,
  Tomboy/Addins/PrintNotes/gedit-print.c,
  Tomboy/Addins/PrintNotes/COPYING,
  Tomboy/Addins/PrintNotes/gedit-print.h, COPYING: Delete old
  gedit/gnomeprint-based print code.
* configure.in: Require gtk-sharp >= 2.10.

Removed:
   trunk/Tomboy/Addins/PrintNotes/COPYING
   trunk/Tomboy/Addins/PrintNotes/gedit-print.c
   trunk/Tomboy/Addins/PrintNotes/gedit-print.h
   trunk/Tomboy/Addins/PrintNotes/gtksourceprintjob.c
   trunk/Tomboy/Addins/PrintNotes/gtksourceprintjob.h
Modified:
   trunk/COPYING
   trunk/ChangeLog
   trunk/Tomboy.mdp
   trunk/Tomboy/Addins/PrintNotes/Makefile.am
   trunk/Tomboy/Addins/PrintNotes/PrintNotes.addin.xml
   trunk/Tomboy/Addins/PrintNotes/PrintNotesNoteAddin.cs
   trunk/configure.in

Modified: trunk/COPYING
==============================================================================
--- trunk/COPYING	(original)
+++ trunk/COPYING	Mon May 12 07:12:52 2008
@@ -1,8 +1,3 @@
-The tomboy package is distributed under the LGPL with exception of
-the Printing Support (PrintNotes) Addin.  The PrintNotes Addin is
-distributed under the GPL.  You may view a copy of the GPL inside
-the Tomboy/Addins/PrintNotes/COPYING file.
-
 		  GNU LESSER GENERAL PUBLIC LICENSE
 		       Version 2.1, February 1999
 

Modified: trunk/Tomboy.mdp
==============================================================================
--- trunk/Tomboy.mdp	(original)
+++ trunk/Tomboy.mdp	Mon May 12 07:12:52 2008
@@ -216,6 +216,7 @@
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
     <ProjectReference type="Gac" localcopy="True" refto="pango-sharp, Version=2.10.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+    <ProjectReference type="Gac" localcopy="True" refto="Mono.Cairo, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
   </References>
   <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="./Makefile.am" ExecuteTargetName="run">
     <BuildFilesVar />

Modified: trunk/Tomboy/Addins/PrintNotes/Makefile.am
==============================================================================
--- trunk/Tomboy/Addins/PrintNotes/Makefile.am	(original)
+++ trunk/Tomboy/Addins/PrintNotes/Makefile.am	Mon May 12 07:12:52 2008
@@ -9,7 +9,8 @@
 	$(LINK_TOMBOY_EXE)			\
 	$(TOMBOY_LIBS) 				\
 	$(LINK_MONO_ADDINS)			\
-	-r:Mono.Posix
+	-r:Mono.Posix				\
+	-r:Mono.Cairo
 
 ADDIN_NAME = PrintNotes
 TARGET = $(ADDIN_NAME).dll
@@ -35,29 +36,5 @@
 	$(TARGET).mdb \
 	$(TARGET)
 
-##
-## Build libprintnotes for gedit print capability
-##
-
-INCLUDES =								\
-	-I$(top_srcdir)						\
-	-DG_LOG_DOMAIN=\"libprintnotes\"	\
-	-DGTK_DISABLE_DEPRECATED			\
-	-DGDK_DISABLE_DEPRECATED			\
-	-DG_DISABLE_DEPRECATED				\
-	$(LIBTOMBOY_CFLAGS)
-
-printnoteslibdir = $(pkglibdir)
-printnoteslib_LTLIBRARIES = libprintnotes.la
-
-libprintnotes_la_SOURCES =				\
-	gedit-print.h						\
-	gedit-print.c						\
-	gtksourceprintjob.h					\
-	gtksourceprintjob.c
-
-libprintnotes_la_LDFLAGS = -export-dynamic -module -avoid-version
-libprintnotes_la_LIBADD = $(LIBTOMBOY_LIBS)
-
 maintainer-clean-local:
 	rm -f Makefile.in

Modified: trunk/Tomboy/Addins/PrintNotes/PrintNotes.addin.xml
==============================================================================
--- trunk/Tomboy/Addins/PrintNotes/PrintNotes.addin.xml	(original)
+++ trunk/Tomboy/Addins/PrintNotes/PrintNotes.addin.xml	Mon May 12 07:12:52 2008
@@ -5,7 +5,7 @@
 	description="Allows you to print a note."
 	category="Desktop Integration"
 	defaultEnabled="true"
-	version="0.1">
+	version="0.2">
 
 	<Runtime>
 		<Import assembly="PrintNotes.dll" />

Modified: trunk/Tomboy/Addins/PrintNotes/PrintNotesNoteAddin.cs
==============================================================================
--- trunk/Tomboy/Addins/PrintNotes/PrintNotesNoteAddin.cs	(original)
+++ trunk/Tomboy/Addins/PrintNotes/PrintNotesNoteAddin.cs	Mon May 12 07:12:52 2008
@@ -1,22 +1,27 @@
 
 using System;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using Mono.Unix;
 
 using Gtk;
 
 using Tomboy;
-
+ 
 namespace Tomboy.PrintNotes
 {
 	public class PrintNotesNoteAddin : NoteAddin
 	{
-		Gtk.ImageMenuItem item;
-
+		private Gtk.ImageMenuItem item;
+		private int font_size = 12;			
+		private List<int> pageBreaks;
+		private Pango.Layout layout;
+	
 		public override void Initialize ()
 		{
 			item = new Gtk.ImageMenuItem (Catalog.GetString ("Print"));
-			item.Image = new Gtk.Image (Gtk.Stock.Print, Gtk.IconSize.Menu);
+			item.Image = new Gtk.Image (Gtk.Stock.Print,
+			                            Gtk.IconSize.Menu);
 			item.Activated += PrintButtonClicked;
 			item.Show ();
 			AddPluginMenuItem (item);
@@ -33,17 +38,126 @@
 		{
 			// Do nothing.
 		}
-
-		[DllImport("libprintnotes")]
-		static extern void gedit_print (IntPtr text_view_handle);
-
-		//
-		// Handle Print menu item Click
-		//
-
-		void PrintButtonClicked (object sender, EventArgs args)
+		
+		private void PrintButtonClicked (object sender, EventArgs args)
+		{
+			Gtk.PrintOperation op = new PrintOperation ();
+			op.BeginPrint += OnBeginPrint;
+			op.DrawPage += OnDrawPage;
+			op.EndPrint += OnEndPrint;
+			
+			op.Run (Gtk.PrintOperationAction.PrintDialog, this.Window);
+		}
+		
+		private void OnBeginPrint (object sender, Gtk.BeginPrintArgs args)
+		{
+			PrintContext context = args.Context;
+			double width = context.Width;
+			double height = context.Height;
+			
+			layout = context.CreatePangoLayout ();
+			
+			Pango.FontDescription desc =
+				Pango.FontDescription.FromString ("sans " +
+				                                  font_size);
+			layout.FontDescription = desc;
+			
+			layout.Width = Pango.Units.FromDouble (context.Width);
+			
+			Gtk.TextIter start_iter, end_iter;
+			Buffer.GetBounds (out start_iter, out end_iter);
+			layout.SetText (
+				Buffer.GetText (start_iter, end_iter, false));
+			
+			int numLines = layout.LineCount;
+			
+			pageBreaks = new List<int> ();
+			double pageHeight = 0;
+			
+			for (int i = 0; i < numLines; i++) {
+				Pango.Rectangle inkRect =
+					new Pango.Rectangle ();
+				Pango.Rectangle logicalRect =
+					new Pango.Rectangle ();
+				
+				Pango.LayoutLine layoutLine =
+					layout.GetLine (i);
+				layoutLine.GetExtents (ref inkRect,
+				                       ref logicalRect);
+				
+				double lineHeight = logicalRect.Height / 1024.0;
+				
+				if (pageHeight + lineHeight > height) {
+					pageBreaks.Add (i);
+					pageHeight = 0;
+				}
+				
+				pageHeight += lineHeight;
+			}
+			
+			PrintOperation op = (PrintOperation) sender;
+			op.NPages = pageBreaks.Count + 1;
+		}
+		
+		public void OnDrawPage (object sender, Gtk.DrawPageArgs args)
+		{
+			Cairo.Context cr = args.Context.CairoContext;
+			
+			int start, end, i;
+			
+			if (args.PageNr == 0)
+				start = 0;
+			else
+				start = pageBreaks [args.PageNr - 1];
+			
+			if (pageBreaks.Count <= args.PageNr)
+				end = layout.LineCount;
+			else
+				end = pageBreaks [args.PageNr];
+			
+			i = 0;
+			Pango.LayoutIter iter = layout.Iter;
+			do {
+				int baseline = 0;
+				
+				if (i >= start) {
+					Pango.LayoutLine line = iter.Line;
+					Pango.Rectangle logicalRect =
+						new Pango.Rectangle ();
+					Pango.Rectangle dummyRect =
+						new Pango.Rectangle ();
+
+					line.GetExtents (ref dummyRect, 
+					                 ref logicalRect);
+					baseline = iter.Baseline;
+					
+					if (i == start) {
+						cr.MoveTo (0, 0);
+					}
+					
+					Pango.CairoHelper.ShowLayoutLine (cr, line);
+					
+					int height, width;
+					layout.GetSize (out width, out height);
+					cr.RelMoveTo (0, (int)
+					              (logicalRect.Height /
+					               Pango.Scale.PangoScale));
+				}
+				
+				i++;
+			}			
+			while (i < end && iter.NextLine ());
+		}
+		
+		private void OnEndPrint (object sender, Gtk.EndPrintArgs args)
 		{
-			gedit_print (Note.Window.Editor.Handle);
+			layout = null;
+			pageBreaks.Clear ();
+			
+			// TODO: How to fix this error when quitting?
+			// "Cairo.Context: called from finalization thread
+			// programmer is missing a call to Dispose"
+			// May be a cairo/pango/gtk-sharp problem?
 		}
 	}
 }

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon May 12 07:12:52 2008
@@ -44,7 +44,7 @@
 # Gdk and Atk are needed for libtrayicon
 #
 GDK20_MINIMUM_VERSION=2.6.0
-GTK20_MINIMUM_VERSION=2.6.0
+GTK20_MINIMUM_VERSION=2.10.0
 ATK_MINIMUM_VERSION=1.2.4
 
 PKG_CHECK_MODULES(LIBTOMBOY, 



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