gtksourceview r1845 - in trunk: . docs/reference docs/reference/tmpl gtksourceview tests



Author: paolo
Date: Mon Jan 14 17:07:01 2008
New Revision: 1845
URL: http://svn.gnome.org/viewvc/gtksourceview?rev=1845&view=rev

Log:
New gtk-print based printing API.
Merged from the "printing" branch.



Added:
   trunk/docs/reference/tmpl/printcompositor.sgml
      - copied unchanged from r1840, /branches/printing/docs/reference/tmpl/printcompositor.sgml
   trunk/gtksourceview/gtksourceprintcompositor.c
      - copied, changed from r1840, /branches/printing/gtksourceview/gtksourceprintcompositor.c
   trunk/gtksourceview/gtksourceprintcompositor.h
      - copied unchanged from r1840, /branches/printing/gtksourceview/gtksourceprintcompositor.h
Removed:
   trunk/docs/reference/tmpl/printjob.sgml
Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/docs/reference/gtksourceview-2.0-sections.txt
   trunk/docs/reference/gtksourceview-2.0.types
   trunk/docs/reference/gtksourceview-docs.sgml
   trunk/gtksourceview/Makefile.am
   trunk/gtksourceview/gtksourcebuffer.c
   trunk/gtksourceview/gtksourceview.c
   trunk/tests/test-widget.c

Modified: trunk/docs/reference/gtksourceview-2.0-sections.txt
==============================================================================
--- trunk/docs/reference/gtksourceview-2.0-sections.txt	(original)
+++ trunk/docs/reference/gtksourceview-2.0-sections.txt	Mon Jan 14 17:07:01 2008
@@ -224,3 +224,57 @@
 gtk_source_iter_forward_search
 <SUBSECTION Standard>
 </SECTION>
+
+<SECTION>
+<FILE>printcompositor</FILE>
+<TITLE>GtkSourcePrintCompositor</TITLE>
+<INCLUDE>gtksourceview/gtksourceprintcompositor.h</INCLUDE>
+GtkSourcePrintCompositor
+gtk_source_print_compositor_new
+gtk_source_print_compositor_new_from_view
+gtk_source_print_compositor_get_buffer
+gtk_source_print_compositor_set_tab_width
+gtk_source_print_compositor_get_tab_width
+gtk_source_print_compositor_set_wrap_mode
+gtk_source_print_compositor_get_wrap_mode
+gtk_source_print_compositor_set_highlight_syntax
+gtk_source_print_compositor_get_highlight_syntax
+gtk_source_print_compositor_set_print_line_numbers
+gtk_source_print_compositor_get_print_line_numbers
+gtk_source_print_compositor_set_body_font_name
+gtk_source_print_compositor_get_body_font_name
+gtk_source_print_compositor_set_line_numbers_font_name
+gtk_source_print_compositor_get_line_numbers_font_name
+gtk_source_print_compositor_set_header_font_name
+gtk_source_print_compositor_get_header_font_name
+gtk_source_print_compositor_set_footer_font_name
+gtk_source_print_compositor_get_footer_font_name
+gtk_source_print_compositor_get_top_margin
+gtk_source_print_compositor_set_top_margin
+gtk_source_print_compositor_get_bottom_margin
+gtk_source_print_compositor_set_bottom_margin
+gtk_source_print_compositor_get_left_margin
+gtk_source_print_compositor_set_left_margin
+gtk_source_print_compositor_get_right_margin
+gtk_source_print_compositor_set_right_margin
+gtk_source_print_compositor_set_print_header
+gtk_source_print_compositor_get_print_header
+gtk_source_print_compositor_set_print_footer
+gtk_source_print_compositor_get_print_footer
+gtk_source_print_compositor_set_header_format
+gtk_source_print_compositor_set_footer_format
+gtk_source_print_compositor_get_n_pages
+gtk_source_print_compositor_paginate
+gtk_source_print_compositor_get_pagination_progress
+gtk_source_print_compositor_draw_page
+<SUBSECTION Standard>
+GTK_SOURCE_PRINT_COMPOSITOR
+GTK_IS_SOURCE_PRINT_COMPOSITOR
+GTK_TYPE_SOURCE_PRINT_COMPOSITOR
+gtk_source_print_compositor_get_type
+GTK_SOURCE_PRINT_COMPOSITOR_CLASS
+GTK_IS_SOURCE_PRINT_COMPOSITOR_CLASS
+GTK_SOURCE_PRINT_COMPOSITOR_GET_CLASS
+GtkSourcePrintCompositorPrivate
+</SECTION>
+

Modified: trunk/docs/reference/gtksourceview-2.0.types
==============================================================================
--- trunk/docs/reference/gtksourceview-2.0.types	(original)
+++ trunk/docs/reference/gtksourceview-2.0.types	Mon Jan 14 17:07:01 2008
@@ -1,6 +1,7 @@
 #include <gtksourceview/gtksourceview.h>
 #include <gtksourceview/gtksourcebuffer.h>
 #include <gtksourceview/gtksourcelanguage.h>
+#include <gtksourceview/gtksourceprintcompositor.h>
 #include <gtksourceview/gtksourcelanguagemanager.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
 #include <gtksourceview/gtksourcemark.h>
@@ -9,6 +10,7 @@
 gtk_source_buffer_get_type
 gtk_source_language_get_type
 gtk_source_language_manager_get_type
+gtk_source_print_compositor_get_type
 gtk_source_style_get_type
 gtk_source_style_scheme_get_type
 gtk_source_style_scheme_manager_get_type

Modified: trunk/docs/reference/gtksourceview-docs.sgml
==============================================================================
--- trunk/docs/reference/gtksourceview-docs.sgml	(original)
+++ trunk/docs/reference/gtksourceview-docs.sgml	Mon Jan 14 17:07:01 2008
@@ -19,6 +19,7 @@
     <xi:include href="xml/view.xml"/>
     <xi:include href="xml/language.xml"/>
     <xi:include href="xml/languagemanager.xml"/>
+    <xi:include href="xml/printcompositor.xml"/>    
     <xi:include href="xml/style.xml"/>
     <xi:include href="xml/stylescheme.xml"/>
     <xi:include href="xml/styleschememanager.xml"/>

Modified: trunk/gtksourceview/Makefile.am
==============================================================================
--- trunk/gtksourceview/Makefile.am	(original)
+++ trunk/gtksourceview/Makefile.am	Mon Jan 14 17:07:01 2008
@@ -44,7 +44,9 @@
 	gtksourcestyle.h			\
 	gtksourcestyleschememanager.h		\
 	gtksourcestylescheme.h			\
-	gtksourcemark.h
+	gtksourcemark.h				\
+	gtksourceprintcompositor.h
+
 
 libgtksourceview_2_0_la_SOURCES = 	\
 	gtksourcebuffer.c 		\
@@ -72,6 +74,7 @@
 	gtksourcecontextengine.h	\
 	gtksourcecontextengine.c	\
 	gtksourcemark.c			\	
+	gtksourceprintcompositor.c      \
 	$(libgtksourceview_headers)
 
 # do not distribute generated files

Modified: trunk/gtksourceview/gtksourcebuffer.c
==============================================================================
--- trunk/gtksourceview/gtksourcebuffer.c	(original)
+++ trunk/gtksourceview/gtksourcebuffer.c	Mon Jan 14 17:07:01 2008
@@ -1023,7 +1023,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_BUFFER (buffer), FALSE);
 
-	return buffer->priv->highlight_brackets;
+	return (buffer->priv->highlight_brackets != FALSE);
 }
 
 /**
@@ -1067,7 +1067,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_BUFFER (buffer), FALSE);
 
-	return buffer->priv->highlight_syntax;
+	return (buffer->priv->highlight_syntax != FALSE);
 }
 
 /**
@@ -1092,8 +1092,8 @@
 
 	if (buffer->priv->highlight_syntax != highlight)
 	{
-	buffer->priv->highlight_syntax = highlight;
-	g_object_notify (G_OBJECT (buffer), "highlight-syntax");
+		buffer->priv->highlight_syntax = highlight;
+		g_object_notify (G_OBJECT (buffer), "highlight-syntax");
 	}
 }
 

Copied: trunk/gtksourceview/gtksourceprintcompositor.c (from r1840, /branches/printing/gtksourceview/gtksourceprintcompositor.c)
==============================================================================
--- /branches/printing/gtksourceview/gtksourceprintcompositor.c	(original)
+++ trunk/gtksourceview/gtksourceprintcompositor.c	Mon Jan 14 17:07:01 2008
@@ -34,14 +34,13 @@
 #include "gtksourceview-i18n.h" 
 #include "gtksourceprintcompositor.h"
 
-
+/*
 #define ENABLE_DEBUG
 #define ENABLE_PROFILE
+*/
 
-/*
 #undef ENABLE_DEBUG
 #undef ENABLE_PROFILE
-*/
 
 #ifdef ENABLE_DEBUG
 #define DEBUG(x) (x)

Modified: trunk/gtksourceview/gtksourceview.c
==============================================================================
--- trunk/gtksourceview/gtksourceview.c	(original)
+++ trunk/gtksourceview/gtksourceview.c	Mon Jan 14 17:07:01 2008
@@ -1736,7 +1736,7 @@
 	g_return_val_if_fail (view != NULL, FALSE);
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->show_line_numbers;
+	return (view->priv->show_line_numbers != FALSE);
 }
 
 /**
@@ -1924,8 +1924,7 @@
 guint
 gtk_source_view_get_tab_width (GtkSourceView *view)
 {
-	g_return_val_if_fail (view != NULL, FALSE);
-	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
+	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), DEFAULT_TAB_WIDTH);
 
 	return view->priv->tab_width;
 }
@@ -2740,7 +2739,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->auto_indent;
+	return (view->priv->auto_indent != FALSE);
 }
 
 /**
@@ -2780,7 +2779,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->insert_spaces;
+	return (view->priv->insert_spaces != FALSE);
 }
 
 /**
@@ -2823,7 +2822,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->indent_on_tab;
+	return (view->priv->indent_on_tab != FALSE);
 }
 
 /**
@@ -2930,7 +2929,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->highlight_current_line;
+	return (view->priv->highlight_current_line != FALSE);
 }
 
 /**
@@ -2970,7 +2969,7 @@
 {
 	g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), FALSE);
 
-	return view->priv->show_right_margin;
+	return (view->priv->show_right_margin != FALSE);
 }
 
 /**
@@ -3017,7 +3016,6 @@
 /**
  * gtk_source_view_set_right_margin_position:
  * @view: a #GtkSourceView.
- * @pos: the position of the margin to set.
  * @pos: the width in characters where to position the right margin.
  *
  * Sets the position of the right margin in the given @view.
@@ -3043,7 +3041,7 @@
 /**
  * gtk_source_view_set_smart_home_end:
  * @view: a #GtkSourceView.
- * @smart_he: the desired behavior among #GtkSourceSmartHomeEndType
+ * @smart_he: the desired behavior among #GtkSourceSmartHomeEndType.
  *
  * Set the desired movement of the cursor when HOME and END keys
  * are pressed.
@@ -3069,7 +3067,7 @@
  * Returns a #GtkSourceSmartHomeEndType end value specifying
  * how the cursor will move when HOME and END keys are pressed.
  *
- * Return value: a #GtkSourceSmartHomeEndType
+ * Return value: a #GtkSourceSmartHomeEndTypeend value.
  **/
 GtkSourceSmartHomeEndType
 gtk_source_view_get_smart_home_end (GtkSourceView *view)

Modified: trunk/tests/test-widget.c
==============================================================================
--- trunk/tests/test-widget.c	(original)
+++ trunk/tests/test-widget.c	Mon Jan 14 17:07:01 2008
@@ -34,6 +34,7 @@
 #include <gtksourceview/gtksourcelanguage.h>
 #include <gtksourceview/gtksourcelanguagemanager.h>
 #include <gtksourceview/gtksourcestyleschememanager.h>
+#include <gtksourceview/gtksourceprintcompositor.h>
 #ifdef TEST_XML_MEM
 #include <libxml/xmlreader.h>
 #endif
@@ -60,6 +61,8 @@
 
 static void       open_file_cb                   (GtkAction       *action,
 						  gpointer         user_data);
+static void       print_file_cb                  (GtkAction       *action,
+						  gpointer         user_data);						  
 static void       debug_thing_3_cb		 (GtkAction       *action,
 						  gpointer         user_data);
 
@@ -101,6 +104,8 @@
 
 static GtkActionEntry view_action_entries[] = {
 	{ "FileMenu", NULL, "_File" },
+	{ "Print", GTK_STOCK_PRINT, "_Print", "<control>P",
+	  "Print the current file", G_CALLBACK (print_file_cb) },
 	{ "ViewMenu", NULL, "_View" },
 	{ "NewView", GTK_STOCK_NEW, "_New View", NULL,
 	  "Create a new view of the file", G_CALLBACK (new_view_cb) },
@@ -214,6 +219,7 @@
 "  <menubar name=\"MainMenu\">"
 "    <menu action=\"FileMenu\">"
 "      <menuitem action=\"Open\"/>"
+"      <menuitem action=\"Print\"/>"
 "      <menuitem action=\"DebugThing3\"/>"
 "      <separator/>"
 "      <menuitem action=\"Quit\"/>"
@@ -794,6 +800,216 @@
 	gtk_widget_destroy (chooser);
 }
 
+#define NON_BLOCKING_PAGINATION
+
+#ifndef NON_BLOCKING_PAGINATION
+
+static void
+begin_print (GtkPrintOperation        *operation, 
+	     GtkPrintContext          *context,
+	     GtkSourcePrintCompositor *compositor)
+{
+	gint n_pages;
+	
+	while (!gtk_source_print_compositor_paginate (compositor, context))
+		;
+
+	n_pages = gtk_source_print_compositor_get_n_pages (compositor);
+	gtk_print_operation_set_n_pages (operation, n_pages);
+}
+
+#else
+
+static gboolean
+paginate (GtkPrintOperation        *operation, 
+	  GtkPrintContext          *context,
+	  GtkSourcePrintCompositor *compositor)
+{
+	g_print ("Pagination progress: %.2f %%\n", gtk_source_print_compositor_get_pagination_progress (compositor) * 100.0);
+	
+	if (gtk_source_print_compositor_paginate (compositor, context))
+	{
+		gint n_pages;
+
+		g_assert (gtk_source_print_compositor_get_pagination_progress (compositor) == 1.0);
+		g_print ("Pagination progress: %.2f %%\n", gtk_source_print_compositor_get_pagination_progress (compositor) * 100.0);
+		        
+		n_pages = gtk_source_print_compositor_get_n_pages (compositor);
+		gtk_print_operation_set_n_pages (operation, n_pages);
+
+
+		
+		return TRUE;
+	}
+     
+	return FALSE;
+}
+
+#endif
+
+#define ENABLE_CUSTOM_OVERLAY
+
+static void
+draw_page (GtkPrintOperation        *operation,
+	   GtkPrintContext          *context,
+	   gint                      page_nr,
+	   GtkSourcePrintCompositor *compositor)
+{
+#ifdef ENABLE_CUSTOM_OVERLAY
+
+	/* This part of the code shows how to add a custom overlay to the
+	   printed text generated by GtkSourcePrintCompositor */
+
+	cairo_t *cr;
+	PangoLayout *layout;
+	PangoFontDescription *desc;
+	PangoRectangle rect;
+
+	
+	cr = gtk_print_context_get_cairo_context (context);
+	
+	cairo_save (cr);
+	
+	layout = gtk_print_context_create_pango_layout (context);
+
+	pango_layout_set_text (layout, "Draft", -1);
+
+	desc = pango_font_description_from_string ("Sans Bold 120");
+	pango_layout_set_font_description (layout, desc);
+	pango_font_description_free (desc);
+
+	
+	pango_layout_get_extents (layout, NULL, &rect);
+		
+  	cairo_move_to (cr, 
+  		       (gtk_print_context_get_width (context) - ((double) rect.width / (double) PANGO_SCALE)) / 2,
+  		       (gtk_print_context_get_height (context) - ((double) rect.height / (double) PANGO_SCALE)) / 2);
+	  		       
+	pango_cairo_layout_path (cr, layout);
+	
+  	/* Font Outline */
+	cairo_set_source_rgba (cr, 0.85, 0.85, 0.85, 0.80);
+	cairo_set_line_width (cr, 0.5);
+	cairo_stroke_preserve (cr);
+
+	/* Font Fill */
+	cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.60);
+	cairo_fill (cr);
+	  	  
+	g_object_unref (layout);
+	cairo_restore (cr);
+#endif
+
+	/* To print page_nr you only need to call the following function */
+	gtk_source_print_compositor_draw_page (compositor, context, page_nr);
+}
+
+static void
+end_print (GtkPrintOperation        *operation, 
+	   GtkPrintContext          *context,
+	   GtkSourcePrintCompositor *compositor)
+{
+	g_object_unref (compositor);
+}
+
+#define LINE_NUMBERS_FONT_NAME	"Sans 8"
+#define HEADER_FONT_NAME	"Sans 11"
+#define FOOTER_FONT_NAME	"Sans 11"
+#define BODY_FONT_NAME		"Monospace 9"
+	
+/*
+#define SETUP_FROM_VIEW 
+*/
+
+#undef SETUP_FROM_VIEW 
+
+
+static void
+print_file_cb (GtkAction *action, gpointer user_data)
+{
+	GtkSourceView *view;
+	GtkSourceBuffer *buffer;
+	GtkSourcePrintCompositor *compositor;
+	GtkPrintOperation *operation;	
+	const gchar *filename;
+	gchar *basename;
+	
+	g_return_if_fail (GTK_IS_SOURCE_VIEW (user_data));
+	
+	view = GTK_SOURCE_VIEW (user_data);
+
+	buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); 
+	
+	filename = g_object_get_data (G_OBJECT (buffer), "filename");	
+	basename = g_filename_display_basename (filename);
+	
+#ifdef SETUP_FROM_VIEW
+	compositor = gtk_source_print_compositor_new_from_view (view);
+#else
+	
+	compositor = gtk_source_print_compositor_new (buffer);
+
+	gtk_source_print_compositor_set_tab_width (compositor,
+						   gtk_source_view_get_tab_width (view));
+
+	gtk_source_print_compositor_set_wrap_mode (compositor,
+						   gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view)));
+
+	gtk_source_print_compositor_set_print_line_numbers (compositor, 1);
+
+	gtk_source_print_compositor_set_body_font_name (compositor,
+							BODY_FONT_NAME);
+
+	/* To test line numbers font != text font */
+	gtk_source_print_compositor_set_line_numbers_font_name (compositor,
+								LINE_NUMBERS_FONT_NAME);
+
+	gtk_source_print_compositor_set_header_format (compositor,
+						       TRUE,
+						       "Printed on %A",
+						       "test-widget",
+						       "%F");
+
+	gtk_source_print_compositor_set_footer_format (compositor,
+						       TRUE,
+						       "%T",
+						       basename,
+						       "Page %N/%Q");
+
+	gtk_source_print_compositor_set_print_header (compositor, TRUE);
+	gtk_source_print_compositor_set_print_footer (compositor, TRUE);
+
+	gtk_source_print_compositor_set_header_font_name (compositor,
+							  HEADER_FONT_NAME);
+
+	gtk_source_print_compositor_set_footer_font_name (compositor,
+							  FOOTER_FONT_NAME);
+#endif	
+	operation = gtk_print_operation_new ();
+			
+	gtk_print_operation_set_job_name (operation, basename);
+	
+	gtk_print_operation_set_show_progress (operation, TRUE);
+
+#ifndef NON_BLOCKING_PAGINATION	
+  	g_signal_connect (G_OBJECT (operation), "begin-print", 
+			  G_CALLBACK (begin_print), compositor);
+#else
+  	g_signal_connect (G_OBJECT (operation), "paginate", 
+			  G_CALLBACK (paginate), compositor);
+#endif
+	g_signal_connect (G_OBJECT (operation), "draw-page", 
+			  G_CALLBACK (draw_page), compositor);
+	g_signal_connect (G_OBJECT (operation), "end-print", 
+			  G_CALLBACK (end_print), compositor);
+
+	gtk_print_operation_run (operation, 
+				 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
+				 NULL, NULL);
+
+	g_object_unref (operation);
+	g_free (basename);
+}
 
 /* View UI callbacks ------------------------------------------------------------------ */
 



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