[gedit-list] First pass hack of gedit and gtksourceview port to gtkprintoperation
- From: "John (J5) Palmieri" <johnp redhat com>
- To: gedit-list gnome org
- Cc: gtk-devel-list gnome org
- Subject: [gedit-list] First pass hack of gedit and gtksourceview port to gtkprintoperation
- Date: Fri, 28 Apr 2006 15:25:40 -0400
Here are my patches for the gtkprintoperation port of gedit and
gtksourceview. They are pretty hacked up as I went in and slashed out
the gnome-print code and forced gtkprint in it's place. I would use
these as guides to those who know the gedit code much better than I.
They really shouldn't be used as production code.
The patches as they stand simply pop up the dialog and then print once
you select a printer. Pagination doesn't work correctly for some
reason.
What is left to do:
* handle settings
* use the page-setup dialog
* use the status API
* preview (this needs to be implemented in gtkprint first)
gnome-print to gtkprint tips:
* gnome-print starts at page 1, gtkprint starts at page 0
* when changing font names to font descriptions use
pango_font_description_from_string
* gnome-print uses the lower left corner as it's origin gtkprint(cairo)
uses the top left corner
* gnome_print_moveto, lineto etc. maps to cairo_move_to, line_to, etc.
* gnome_print_pango_layout_line maps to pango_cairo_show_layout_line
--
John (J5) Palmieri <johnp redhat com>
Index: gedit-commands-file-print.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands-file-print.c,v
retrieving revision 1.2
diff -u -r1.2 gedit-commands-file-print.c
--- gedit-commands-file-print.c 12 Dec 2005 17:27:55 -0000 1.2
+++ gedit-commands-file-print.c 28 Apr 2006 18:17:47 -0000
@@ -36,6 +36,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <gtk/gtkprintoperation.h>
#include "gedit-commands.h"
#include "gedit-window.h"
@@ -153,14 +154,42 @@
gtk_widget_destroy (dialog);
}
+static void
+begin_print (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ GeditPrintJob *pjob)
+{
+ gint num_pages;
+
+ gtk_source_print_job_set_print_context (pjob, context);
+ gtk_source_print_job_prepare (pjob);
+ num_pages = gtk_source_print_job_get_page_count (pjob);
+ g_message ("printing %i pages", num_pages);
+ gtk_print_operation_set_nr_of_pages (operation,
+ num_pages);
+
+}
+
+static void
+draw_page (GtkPrintOperation *operation,
+ GtkPrintContext *context,
+ int page_nr,
+ GeditPrintJob *pjob)
+{
+ g_message ("Print page %i", ++page_nr);
+ gtk_source_print_job_print_page (pjob, page_nr, context);
+}
+
void
gedit_cmd_file_print (GtkAction *action,
GeditWindow *window)
{
GeditDocument *doc;
GeditPrintJob *pjob;
- GtkWidget *print_dialog;
- GtkWindowGroup *wg;
+ GtkWidget *error_dialog;
+ GtkPrintOperation *print;
+ GtkPrintOperationResult res;
+ GError *error;
gedit_debug (DEBUG_COMMANDS);
@@ -170,22 +199,25 @@
pjob = gedit_print_job_new (doc);
- print_dialog = gedit_print_dialog_new (pjob);
-
- wg = gedit_window_get_group (window);
+ print = gtk_print_operation_new ();
- gtk_window_group_add_window (wg,
- GTK_WINDOW (print_dialog));
+ gtk_print_operation_set_unit (print, GTK_UNIT_POINTS);
- gtk_window_set_transient_for (GTK_WINDOW (print_dialog),
- GTK_WINDOW (window));
- gtk_window_set_modal (GTK_WINDOW (print_dialog), TRUE);
+ g_signal_connect (print, "begin_print", G_CALLBACK (begin_print), pjob);
+ g_signal_connect (print, "draw-page", G_CALLBACK (draw_page), pjob);
- g_signal_connect (print_dialog,
- "response",
- G_CALLBACK (print_dialog_response_cb),
- pjob);
-
- gtk_widget_show (print_dialog);
+ error = NULL;
+ res = gtk_print_operation_run (print, GTK_WINDOW (window), &error);
+
+ if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "Error printing file:\n%s",
+ error->message);
+ g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+ gtk_widget_show (error_dialog);
+ g_error_free (error);
+ }
}
-
Index: gedit-print.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-print.c,v
retrieving revision 1.46
diff -u -r1.46 gedit-print.c
--- gedit-print.c 12 Dec 2005 17:27:55 -0000 1.46
+++ gedit-print.c 28 Apr 2006 18:17:47 -0000
@@ -168,7 +168,6 @@
gnome_print_config_set_int (config, GNOME_PRINT_KEY_NUM_COPIES, 1);
gnome_print_config_set_boolean (config, GNOME_PRINT_KEY_COLLATE, FALSE);
- gtk_source_print_job_set_config (pjob, config);
gtk_source_print_job_set_highlight (pjob,
gtk_source_buffer_get_highlight (buffer) &&
@@ -276,15 +275,10 @@
void
gedit_print_job_save_config (GeditPrintJob *job)
{
- GnomePrintConfig *config;
-
g_return_if_fail (GEDIT_IS_PRINT_JOB (job));
- config = gtk_source_print_job_get_config (GTK_SOURCE_PRINT_JOB (job));
-
- save_print_config_to_file (config);
}
-
+#if 0
GtkWidget *
gedit_print_dialog_new (GeditPrintJob *job)
{
@@ -308,8 +302,6 @@
else
selection_flag = GNOME_PRINT_RANGE_SELECTION;
- config = gtk_source_print_job_get_config (GTK_SOURCE_PRINT_JOB (job));
-
dialog = g_object_new (GNOME_TYPE_PRINT_DIALOG, "print_config", config, NULL);
gnome_print_dialog_construct (GNOME_PRINT_DIALOG (dialog),
@@ -340,3 +332,4 @@
return dialog;
}
+#endif
Index: gedit-tab.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-tab.c,v
retrieving revision 1.10
diff -u -r1.10 gedit-tab.c
--- gedit-tab.c 13 Mar 2006 07:40:06 -0000 1.10
+++ gedit-tab.c 28 Apr 2006 18:17:48 -0000
@@ -2023,6 +2023,7 @@
static void
preview_finished_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
{
+#if 0
GnomePrintJob *gjob;
GtkWidget *preview = NULL;
@@ -2040,22 +2041,23 @@
g_object_unref (pjob);
gedit_tab_set_state (tab, GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW);
+#endif
}
static void
print_finished_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
{
- GnomePrintJob *gjob;
+ //GnomePrintJob *gjob;
g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
set_message_area (tab, NULL); /* destroy the message area */
- gjob = gtk_source_print_job_get_print_job (pjob);
+ //gjob = gtk_source_print_job_get_print_job (pjob);
- gnome_print_job_print (gjob);
- g_object_unref (gjob);
+ //gnome_print_job_print (gjob);
+ //g_object_unref (gjob);
- gedit_print_job_save_config (GEDIT_PRINT_JOB (pjob));
+ //gedit_print_job_save_config (GEDIT_PRINT_JOB (pjob));
g_object_unref (pjob);
Index: gtksourceprintjob.c
===================================================================
RCS file: /cvs/gnome/gtksourceview/gtksourceview/gtksourceprintjob.c,v
retrieving revision 1.19
diff -u -r1.19 gtksourceprintjob.c
--- gtksourceprintjob.c 4 Jan 2006 15:35:00 -0000 1.19
+++ gtksourceprintjob.c 28 Apr 2006 18:19:30 -0000
@@ -39,8 +39,6 @@
#include "gtksourcetag.h"
#include "gtksourceprintjob.h"
-#include <libgnomeprint/gnome-print-pango.h>
-
#ifdef ENABLE_PROFILE
#define PROFILE(x) x
#else
@@ -98,7 +96,7 @@
struct _GtkSourcePrintJobPrivate
{
/* General job configuration */
- GnomePrintConfig *config;
+ //PrintConfig *config;
GtkSourceBuffer *buffer;
guint tabs_width;
GtkWrapMode wrap_mode;
@@ -133,8 +131,7 @@
/* Job state */
gboolean printing;
guint idle_printing_tag;
- GnomePrintContext *print_ctxt;
- GnomePrintJob *print_job;
+ GtkPrintContext *print_context;
PangoContext *pango_context;
PangoTabArray *tab_array;
gint page;
@@ -258,15 +255,7 @@
klass->begin_page = gtk_source_print_job_begin_page;
klass->finished = NULL;
-
- g_object_class_install_property (object_class,
- PROP_CONFIG,
- g_param_spec_object ("config",
- _("Configuration"),
- _("Configuration options for "
- "the print job"),
- GNOME_TYPE_PRINT_CONFIG,
- G_PARAM_READWRITE));
+
g_object_class_install_property (object_class,
PROP_BUFFER,
g_param_spec_object ("buffer",
@@ -274,6 +263,8 @@
_("GtkSourceBuffer object to print"),
GTK_TYPE_SOURCE_BUFFER,
G_PARAM_READWRITE));
+
+
g_object_class_install_property (object_class,
PROP_TABS_WIDTH,
g_param_spec_uint ("tabs_width",
@@ -401,7 +392,6 @@
job->priv = priv;
/* default job configuration */
- priv->config = NULL;
priv->buffer = NULL;
priv->tabs_width = 8;
@@ -430,8 +420,7 @@
/* initial state */
priv->printing = FALSE;
- priv->print_ctxt = NULL;
- priv->print_job = NULL;
+ priv->print_context = NULL;
priv->page = 0;
priv->page_count = 0;
@@ -480,8 +469,6 @@
if (priv != NULL)
{
- if (priv->config != NULL)
- gnome_print_config_unref (priv->config);
if (priv->buffer != NULL)
g_object_unref (priv->buffer);
if (priv->font != NULL)
@@ -497,10 +484,6 @@
g_free (priv->footer_format_right);
g_free (priv->footer_format_center);
- if (priv->print_ctxt != NULL)
- g_object_unref (priv->print_ctxt);
- if (priv->print_job != NULL)
- g_object_unref (priv->print_job);
if (priv->pango_context != NULL)
g_object_unref (priv->pango_context);
if (priv->tab_array != NULL)
@@ -528,10 +511,6 @@
switch (prop_id)
{
- case PROP_CONFIG:
- g_value_set_object (value, job->priv->config);
- break;
-
case PROP_BUFFER:
g_value_set_object (value, job->priv->buffer);
break;
@@ -602,14 +581,10 @@
switch (prop_id)
{
- case PROP_CONFIG:
- gtk_source_print_job_set_config (job, g_value_get_object (value));
- break;
-
case PROP_BUFFER:
gtk_source_print_job_set_buffer (job, g_value_get_object (value));
break;
-
+
case PROP_TABS_WIDTH:
gtk_source_print_job_set_tabs_width (job, g_value_get_uint (value));
break;
@@ -669,8 +644,6 @@
static void
gtk_source_print_job_begin_page (GtkSourcePrintJob *job)
{
- g_return_if_fail (job->priv->printing);
-
if (job->priv->print_header && job->priv->header_height > 0)
{
gdouble x, y;
@@ -728,13 +701,13 @@
/* Draws the first line in a layout; we use this for one-line layouts
* to get baseline alignment */
static void
-show_first_layout_line (GnomePrintContext *print_ctxt,
+show_first_layout_line (cairo_t *print_ctx,
PangoLayout *layout)
{
PangoLayoutLine *line;
line = pango_layout_get_lines (layout)->data;
- gnome_print_pango_layout_line (print_ctxt, line);
+ pango_cairo_show_layout_line (print_ctx, line);
}
static PangoLayout *
@@ -758,8 +731,6 @@
static void
ensure_print_config (GtkSourcePrintJob *job)
{
- if (job->priv->config == NULL)
- job->priv->config = gnome_print_config_default ();
if (job->priv->font == NULL)
job->priv->font = pango_font_description_from_string (DEFAULT_FONT_NAME);
}
@@ -770,23 +741,6 @@
PangoLayout *layout;
gdouble ascent, descent;
- gnome_print_job_get_page_size_from_config (job->priv->config,
- &job->priv->page_width,
- &job->priv->page_height);
-
- gnome_print_config_get_length (job->priv->config,
- (guchar*)GNOME_PRINT_KEY_PAGE_MARGIN_TOP,
- &job->priv->doc_margin_top, NULL);
- gnome_print_config_get_length (job->priv->config,
- (guchar*)GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM,
- &job->priv->doc_margin_bottom, NULL);
- gnome_print_config_get_length (job->priv->config,
- (guchar*)GNOME_PRINT_KEY_PAGE_MARGIN_LEFT,
- &job->priv->doc_margin_left, NULL);
- gnome_print_config_get_length (job->priv->config,
- (guchar*)GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT,
- &job->priv->doc_margin_right, NULL);
-
/* set default fonts for numbers and header/footer */
if (job->priv->numbers_font == NULL)
job->priv->numbers_font = pango_font_description_copy (job->priv->font);
@@ -869,15 +823,8 @@
static gboolean
setup_pango_context (GtkSourcePrintJob *job)
{
- PangoFontMap *font_map;
gint real_tab_width;
- if (!job->priv->pango_context)
- {
- font_map = gnome_print_pango_get_default_font_map ();
- job->priv->pango_context = gnome_print_pango_create_context (font_map);
- }
-
pango_context_set_language (job->priv->pango_context, job->priv->language);
pango_context_set_font_description (job->priv->pango_context, job->priv->font);
@@ -897,85 +844,22 @@
return TRUE;
}
-/* ----- Helper functions */
-
-static gchar *
-font_description_to_gnome_font_name (PangoFontDescription *desc)
+void
+gtk_source_print_job_set_pango_context (GtkSourcePrintJob *job,
+ PangoContext *context)
{
- GnomeFontFace *font_face;
- gchar *retval;
+ if (job->priv->pango_context)
+ g_object_unref (job->priv->pango_context);
- /* Will always return some font */
- font_face = gnome_font_face_find_closest_from_pango_description (desc);
-
- retval = g_strdup_printf("%s %f",
- gnome_font_face_get_name (font_face),
- (double) pango_font_description_get_size (desc) / PANGO_SCALE);
- g_object_unref (font_face);
-
- return retval;
+ job->priv->pango_context = context;
}
+/* ----- Helper functions */
+
/*
* The following routines are duplicated in gedit/gedit/gedit-prefs-manager.c
*/
-/* Do this ourselves since gnome_font_find_closest() doesn't call
- * gnome_font_face_find_closest() (probably a gnome-print bug)
- */
-static void
-face_and_size_from_full_name (const gchar *name,
- GnomeFontFace **face,
- gdouble *size)
-{
- char *copy;
- char *str_size;
-
- copy = g_strdup (name);
- str_size = strrchr (copy, ' ');
- if (str_size)
- {
- *str_size = 0;
- str_size ++;
- *size = atof (str_size);
- }
- else
- {
- *size = 12;
- }
-
- *face = gnome_font_face_find_closest ((guchar*)copy);
- g_free (copy);
-}
-
-static PangoFontDescription *
-font_description_from_gnome_font_name (const char *font_name)
-{
- GnomeFontFace *face;
- PangoFontDescription *desc;
- PangoStyle style;
- PangoWeight weight;
- gdouble size;
-
- face_and_size_from_full_name (font_name, &face, &size);
-
- /* Pango and GnomePrint have basically the same numeric weight values */
- weight = (PangoWeight) gnome_font_face_get_weight_code (face);
- style = gnome_font_face_is_italic (face) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, (const gchar*)gnome_font_face_get_family_name (face));
- pango_font_description_set_weight (desc, weight);
- pango_font_description_set_style (desc, style);
- pango_font_description_set_size (desc, size * PANGO_SCALE);
-
- g_object_unref (face);
-
- return desc;
-}
-
-/* ---- TextStyle functions */
-
static TextStyle *
text_style_new (GtkSourcePrintJob *job, GtkSourceTag *tag)
{
@@ -1434,15 +1318,12 @@
static void
begin_page (GtkSourcePrintJob *job)
{
- gnome_print_beginpage (job->priv->print_ctxt, NULL);
-
g_signal_emit (job, print_job_signals [BEGIN_PAGE], 0);
}
static void
end_page (GtkSourcePrintJob *job)
{
- gnome_print_showpage (job->priv->print_ctxt);
}
static void
@@ -1452,13 +1333,16 @@
gdouble y)
{
PangoLayout *layout;
+ cairo_t *ctx;
+
+ ctx = gtk_print_context_get_cairo (job->priv->print_context);
layout = get_line_number_layout (job, line_number);
x = x + job->priv->numbers_width - get_layout_width (layout) - NUMBERS_TEXT_SEPARATION;
- gnome_print_moveto (job->priv->print_ctxt, x, y);
+ cairo_move_to (ctx, x, y);
- show_first_layout_line (job->priv->print_ctxt, layout);
+ show_first_layout_line (ctx, layout);
g_object_unref (layout);
}
@@ -1480,7 +1364,8 @@
gdouble x,
gdouble *y,
gdouble *baseline_out,
- gboolean force_fit)
+ gboolean force_fit,
+ gboolean skip_output)
{
PangoLayout *layout;
PangoLayoutIter *iter;
@@ -1517,22 +1402,31 @@
}
baseline = (gdouble) pango_layout_iter_get_baseline (iter) / PANGO_SCALE;
- baseline = *y + page_skip - baseline; /* Adjust to global coordinates */
+ baseline += *y + page_skip;
+
+ if (baseline == *y)
+ baseline += max;
+
if (current_line == 0)
*baseline_out = baseline;
- gnome_print_moveto (job->priv->print_ctxt,
- x + (gdouble) logical_rect.x / PANGO_SCALE,
- baseline);
- gnome_print_pango_layout_line (job->priv->print_ctxt,
- pango_layout_iter_get_line (iter));
+ if (!skip_output) {
+ cairo_t *ctx;
+
+ ctx = gtk_print_context_get_cairo (job->priv->print_context);
+ cairo_move_to (ctx,
+ x + (gdouble) logical_rect.x / PANGO_SCALE,
+ baseline);
+ pango_cairo_show_layout_line (ctx,
+ pango_layout_iter_get_line (iter));
+ }
current_line++;
}
while (pango_layout_iter_next_line (iter));
job->priv->available_height -= max - page_skip;
- *y -= max - page_skip;
+ *y = baseline;
pango_layout_iter_free (iter);
g_object_unref (layout);
@@ -1540,22 +1434,30 @@
return result;
}
-static void
-print_page (GtkSourcePrintJob *job)
+void
+gtk_source_print_job_print_page (GtkSourcePrintJob *job,
+ gint page_nr,
+ GtkPrintContext *context)
{
GSList *l;
gdouble x, y;
gint line;
gboolean force_fit = TRUE;
-
+ gboolean skip_page;
+
+ gtk_source_print_job_set_print_context (job, context);
job->priv->page++;
-
+
+ g_message ("page %i, page_nr %i", job->priv->page, page_nr);
+ g_assert (!(job->priv->page > page_nr));
+
+ if (page_nr < job->priv->page)
+ skip_page = TRUE;
begin_page (job);
job->priv->available_height = job->priv->text_height;
- y = job->priv->page_height -
- job->priv->doc_margin_top - job->priv->margin_top -
+ y = job->priv->doc_margin_top + job->priv->margin_top +
job->priv->header_height;
x = job->priv->doc_margin_left + job->priv->margin_left +
job->priv->numbers_width;
@@ -1568,13 +1470,14 @@
gdouble baseline = 0;
gint last_line = line;
- line = print_paragraph (job, para, line, x, &y, &baseline, force_fit);
+ line = print_paragraph (job, para, line, x, &y, &baseline, force_fit, skip_page);
if (last_line == 0 && line != 0)
{
/* We printed the first line of a paragraph */
if (job->priv->print_numbers > 0 &&
- ((para->line_number % job->priv->print_numbers) == 0))
+ ((para->line_number % job->priv->print_numbers) == 0) &&
+ !skip_page)
print_line_number (job,
para->line_number,
job->priv->doc_margin_left +
@@ -1594,6 +1497,14 @@
end_page (job);
job->priv->current_paragraph = l;
job->priv->current_paragraph_line = line;
+
+ job->priv->print_context = NULL;
+
+ if (skip_page)
+ gtk_source_print_job_print_page (job,
+ page_nr,
+ context);
+
}
static void
@@ -1602,16 +1513,12 @@
job->priv->current_paragraph = job->priv->paragraphs;
job->priv->page = 0;
job->priv->printed_lines = 0;
+}
- if (job->priv->print_job != NULL)
- g_object_unref (job->priv->print_job);
- if (job->priv->print_ctxt != NULL)
- g_object_unref (job->priv->print_ctxt);
-
- job->priv->print_job = gnome_print_job_new (job->priv->config);
- job->priv->print_ctxt = gnome_print_job_get_context (job->priv->print_job);
-
- gnome_print_pango_update_context (job->priv->pango_context, job->priv->print_ctxt);
+static void
+print_page (GtkSourcePrintJob *job)
+{
+
}
static void
@@ -1619,8 +1526,6 @@
{
while (job->priv->current_paragraph != NULL)
print_page (job);
-
- gnome_print_job_close (job->priv->print_job);
}
static gboolean
@@ -1632,7 +1537,6 @@
if (job->priv->current_paragraph == NULL)
{
- gnome_print_job_close (job->priv->print_job);
job->priv->printing = FALSE;
job->priv->idle_printing_tag = 0;
@@ -1657,22 +1561,16 @@
* Return value: the new print job object.
**/
GtkSourcePrintJob *
-gtk_source_print_job_new (GnomePrintConfig *config)
+gtk_source_print_job_new (void)
{
GtkSourcePrintJob *job;
- g_return_val_if_fail (config == NULL || GNOME_IS_PRINT_CONFIG (config), NULL);
-
job = GTK_SOURCE_PRINT_JOB (g_object_new (GTK_TYPE_SOURCE_PRINT_JOB, NULL));
- if (config != NULL)
- gtk_source_print_job_set_config (job, config);
-
return job;
}
/**
* gtk_source_print_job_new_with_buffer:
- * @config: an optional #GnomePrintConfig.
* @buffer: the #GtkSourceBuffer to print (might be %NULL).
*
* Creates a new print job to print @buffer.
@@ -1680,72 +1578,21 @@
* Return value: a new print job object.
**/
GtkSourcePrintJob *
-gtk_source_print_job_new_with_buffer (GnomePrintConfig *config,
- GtkSourceBuffer *buffer)
+gtk_source_print_job_new_with_buffer (GtkSourceBuffer *buffer)
{
GtkSourcePrintJob *job;
- g_return_val_if_fail (config == NULL || GNOME_IS_PRINT_CONFIG (config), NULL);
g_return_val_if_fail (buffer == NULL || GTK_IS_SOURCE_BUFFER (buffer), NULL);
- job = gtk_source_print_job_new (config);
+ job = gtk_source_print_job_new ();
if (buffer != NULL)
gtk_source_print_job_set_buffer (job, buffer);
return job;
}
-/* --- print job basic configuration */
-
-/**
- * gtk_source_print_job_set_config:
- * @job: a #GtkSourcePrintJob.
- * @config: a #GnomePrintConfig object to get printing configuration from.
- *
- * Sets the print configuration for the job. If you don't set a
- * configuration object for the print job, when needed one will be
- * created with gnome_print_config_default().
- **/
-void
-gtk_source_print_job_set_config (GtkSourcePrintJob *job,
- GnomePrintConfig *config)
-{
- g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (GNOME_IS_PRINT_CONFIG (config));
- g_return_if_fail (!job->priv->printing);
-
- if (config == job->priv->config)
- return;
-
- if (job->priv->config != NULL)
- gnome_print_config_unref (job->priv->config);
-
- job->priv->config = config;
- gnome_print_config_ref (config);
-
- g_object_notify (G_OBJECT (job), "config");
-}
-
-/**
- * gtk_source_print_job_get_config:
- * @job: a #GtkSourcePrintJob.
- *
- * Gets the current #GnomePrintConfig the print job will use. If not
- * previously set, this will create a default configuration and return
- * it. The returned object reference is owned by the print job.
- *
- * Return value: the #GnomePrintConfig for the print job.
- **/
-GnomePrintConfig *
-gtk_source_print_job_get_config (GtkSourcePrintJob *job)
-{
- g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
-
- ensure_print_config (job);
-
- return job->priv->config;
-}
+/* --- print job basic configuration */
/**
* gtk_source_print_job_set_buffer:
* @job: a #GtkSourcePrintJob.
@@ -1761,7 +1608,6 @@
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
g_return_if_fail (GTK_IS_SOURCE_BUFFER (buffer));
- g_return_if_fail (!job->priv->printing);
if (buffer == job->priv->buffer)
return;
@@ -1793,6 +1639,7 @@
return job->priv->buffer;
}
+
/* --- print job layout and style configuration */
/**
@@ -1810,7 +1657,6 @@
guint tabs_width)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (tabs_width == job->priv->tabs_width)
return;
@@ -1850,7 +1696,6 @@
GtkWrapMode wrap)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (wrap == job->priv->wrap_mode)
return;
@@ -1890,7 +1735,6 @@
gboolean highlight)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
highlight = (highlight != FALSE);
@@ -1933,7 +1777,6 @@
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
g_return_if_fail (desc != NULL);
- g_return_if_fail (!job->priv->printing);
desc = pango_font_description_copy (desc);
if (job->priv->font != NULL)
@@ -1963,18 +1806,7 @@
gtk_source_print_job_set_font (GtkSourcePrintJob *job,
const gchar *font_name)
{
- PangoFontDescription *desc;
-
- g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (font_name != NULL);
- g_return_if_fail (!job->priv->printing);
-
- desc = font_description_from_gnome_font_name (font_name);
- if (desc)
- {
- gtk_source_print_job_set_font_desc (job, desc);
- pango_font_description_free (desc);
- }
+ gtk_source_print_job_set_font_desc (job, pango_font_description_from_string (font_name));
}
/**
@@ -2023,7 +1855,7 @@
ensure_print_config (job);
- return font_description_to_gnome_font_name (job->priv->font);
+ return "";
}
/**
@@ -2045,14 +1877,10 @@
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
g_return_if_fail (GTK_IS_SOURCE_VIEW (view));
- g_return_if_fail (!job->priv->printing);
if (GTK_IS_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))))
buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
- if (job->priv->buffer == NULL && buffer != NULL)
- gtk_source_print_job_set_buffer (job, buffer);
-
gtk_source_print_job_set_tabs_width (job, gtk_source_view_get_tabs_width (view));
if (buffer != NULL)
gtk_source_print_job_set_highlight (job, gtk_source_buffer_get_highlight (buffer));
@@ -2076,7 +1904,6 @@
PangoFontDescription *desc)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (desc)
desc = pango_font_description_copy (desc);
@@ -2107,22 +1934,9 @@
gtk_source_print_job_set_numbers_font (GtkSourcePrintJob *job,
const gchar *font_name)
{
- PangoFontDescription *desc;
-
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
- if (font_name != NULL)
- {
- desc = font_description_from_gnome_font_name (font_name);
- if (desc)
- {
- gtk_source_print_job_set_numbers_font_desc (job, desc);
- pango_font_description_free (desc);
- }
- }
- else
- gtk_source_print_job_set_numbers_font (job, NULL);
+ gtk_source_print_job_set_numbers_font_desc (job, pango_font_description_from_string (font_name));
}
/**
@@ -2166,10 +1980,7 @@
{
g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
- if (job->priv->numbers_font != NULL)
- return font_description_to_gnome_font_name (job->priv->numbers_font);
- else
- return NULL;
+ return NULL;
}
/**
@@ -2186,7 +1997,6 @@
guint interval)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (interval == job->priv->print_numbers)
return;
@@ -2243,7 +2053,6 @@
gdouble right)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (top >= 0)
job->priv->margin_top = top;
@@ -2291,14 +2100,13 @@
/* --- printing operations */
static gboolean
-gtk_source_print_job_prepare (GtkSourcePrintJob *job,
+gtk_source_print_job_prepare_range (GtkSourcePrintJob *job,
const GtkTextIter *start,
const GtkTextIter *end)
{
PROFILE (GTimer *timer);
g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), FALSE);
- g_return_val_if_fail (!job->priv->printing, FALSE);
g_return_val_if_fail (job->priv->buffer != NULL, FALSE);
g_return_val_if_fail (start != NULL && end != NULL, FALSE);
@@ -2332,6 +2140,21 @@
return TRUE;
}
+gboolean
+gtk_source_print_job_prepare (GtkSourcePrintJob *job)
+{
+ GtkTextIter start, end;
+
+ setup_for_print (job);
+
+ job->priv->printing = TRUE;
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (job->priv->buffer), &start, &end);
+ gtk_source_print_job_prepare_range (job, &start, &end);
+
+ setup_for_print (job);
+ return TRUE;
+}
+
/**
* gtk_source_print_job_print:
* @job: a configured #GtkSourcePrintJob.
@@ -2347,18 +2170,14 @@
* Return value: a closed #GnomePrintJob with the printed document, or
* %NULL if printing could not be completed.
**/
-GnomePrintJob *
+void
gtk_source_print_job_print (GtkSourcePrintJob *job)
{
GtkTextIter start, end;
- g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
- g_return_val_if_fail (!job->priv->printing, NULL);
- g_return_val_if_fail (job->priv->buffer != NULL, NULL);
-
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (job->priv->buffer), &start, &end);
- return gtk_source_print_job_print_range (job, &start, &end);
+ gtk_source_print_job_print_range (job, &start, &end);
}
/**
@@ -2374,22 +2193,13 @@
* Return value: a closed #GnomePrintJob with the text from @start to
* @end printed, or %NULL if @job could not print.
**/
-GnomePrintJob *
+void
gtk_source_print_job_print_range (GtkSourcePrintJob *job,
const GtkTextIter *start,
const GtkTextIter *end)
{
- g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
- g_return_val_if_fail (!job->priv->printing, NULL);
- g_return_val_if_fail (job->priv->buffer != NULL, NULL);
- g_return_val_if_fail (start != NULL && end != NULL, NULL);
- g_return_val_if_fail (gtk_text_iter_get_buffer (start) ==
- GTK_TEXT_BUFFER (job->priv->buffer) &&
- gtk_text_iter_get_buffer (end) ==
- GTK_TEXT_BUFFER (job->priv->buffer), NULL);
-
- if (!gtk_source_print_job_prepare (job, start, end))
- return NULL;
+ if (!gtk_source_print_job_prepare_range (job, start, end))
+ return;
/* real work starts here */
setup_for_print (job);
@@ -2398,8 +2208,6 @@
print_job (job);
job->priv->printing = FALSE;
- g_object_ref (job->priv->print_job);
- return job->priv->print_job;
}
/* --- asynchronous printing */
@@ -2436,7 +2244,6 @@
GSource *idle_source;
g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), FALSE);
- g_return_val_if_fail (!job->priv->printing, FALSE);
g_return_val_if_fail (job->priv->buffer != NULL, FALSE);
g_return_val_if_fail (start != NULL && end != NULL, FALSE);
g_return_val_if_fail (gtk_text_iter_get_buffer (start) ==
@@ -2444,7 +2251,7 @@
gtk_text_iter_get_buffer (end) ==
GTK_TEXT_BUFFER (job->priv->buffer), FALSE);
- if (!gtk_source_print_job_prepare (job, start, end))
+ if (!gtk_source_print_job_prepare_range (job, start, end))
return FALSE;
/* real work starts here */
@@ -2486,7 +2293,6 @@
gtk_source_print_job_cancel (GtkSourcePrintJob *job)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (job->priv->printing);
if (job->priv->idle_printing_tag > 0)
{
@@ -2494,10 +2300,7 @@
job->priv->current_paragraph = NULL;
job->priv->idle_printing_tag = 0;
job->priv->printing = FALSE;
- g_object_unref (job->priv->print_job);
- g_object_unref (job->priv->print_ctxt);
- job->priv->print_job = NULL;
- job->priv->print_ctxt = NULL;
+ job->priv->print_context = NULL;
}
}
@@ -2518,15 +2321,10 @@
* Return value: a new reference to the @job's #GnomePrintJob, or
* %NULL.
**/
-GnomePrintJob *
+void
gtk_source_print_job_get_print_job (GtkSourcePrintJob *job)
{
- g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
-
- if (job->priv->print_job)
- g_object_ref (job->priv->print_job);
-
- return job->priv->print_job;
+ return;
}
/* --- information for asynchronous ops and headers and footers callback */
@@ -2544,7 +2342,6 @@
gtk_source_print_job_get_page (GtkSourcePrintJob *job)
{
g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), 0);
- g_return_val_if_fail (job->priv->printing, 0);
return job->priv->page;
}
@@ -2570,29 +2367,6 @@
return job->priv->page_count;
}
-/**
- * gtk_source_print_job_get_print_context:
- * @job: a printing #GtkSourcePrintJob.
- *
- * Determines the #GnomePrintContext of the current job. This
- * function is only valid while printing. Normally you would use this
- * function to print in the margins set by
- * gtk_source_print_job_set_margins() in a handler for the <link
- * linkend="GtkSourcePrintJob-begin-page">"begin_page"</link>
- * signal.
- *
- * Return value: the current #GnomePrintContext. The returned object
- * is owned by @job.
- **/
-GnomePrintContext *
-gtk_source_print_job_get_print_context (GtkSourcePrintJob *job)
-{
- g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
- g_return_val_if_fail (job->priv->printing, NULL);
-
- return job->priv->print_ctxt;
-}
-
/* ---- Header and footer (default implementation) */
/* Most of this code taken from GLib's g_date_strftime() in gdate.c
@@ -2726,19 +2500,22 @@
gchar *text;
gdouble width;
gdouble xx;
+ cairo_t *ctx;
+
+ ctx = gtk_print_context_get_cairo (job->priv->print_context);
width = job->priv->text_width + job->priv->numbers_width;
text = evaluate_format_string (job, format);
if (text != NULL)
{
- layout = pango_layout_new (job->priv->pango_context);
+ layout = gtk_print_context_create_layout (job->priv->print_context);
pango_layout_set_font_description (layout, job->priv->header_footer_font);
pango_layout_set_text (layout, text, -1);
xx = x + x_align * (width - get_layout_width (layout));
- gnome_print_moveto (job->priv->print_ctxt, xx, y);
- show_first_layout_line (job->priv->print_ctxt, layout);
+ cairo_move_to (ctx, xx, y);
+ show_first_layout_line (ctx, layout);
g_free (text);
g_object_unref (layout);
@@ -2775,11 +2552,13 @@
/* separator */
if (job->priv->header_separator)
{
+ cairo_t *ctx;
+ ctx = gtk_print_context_get_cairo (job->priv->print_context);
yy = y - (SEPARATOR_SPACING * (ascent + descent));
- gnome_print_setlinewidth (job->priv->print_ctxt, SEPARATOR_LINE_WIDTH);
- gnome_print_moveto (job->priv->print_ctxt, x, yy);
- gnome_print_lineto (job->priv->print_ctxt, x + width, yy);
- gnome_print_stroke (job->priv->print_ctxt);
+ cairo_set_line_width (ctx, SEPARATOR_LINE_WIDTH);
+ cairo_move_to (ctx, x, yy);
+ cairo_line_to (ctx, x + width, yy);
+ cairo_stroke (ctx);
}
}
@@ -2813,12 +2592,14 @@
/* separator */
if (job->priv->footer_separator)
{
+ cairo_t *ctx;
+ ctx = gtk_print_context_get_cairo (job->priv->print_context);
yy = y - job->priv->footer_height +
(SEPARATOR_SPACING * (ascent + descent));
- gnome_print_setlinewidth (job->priv->print_ctxt, SEPARATOR_LINE_WIDTH);
- gnome_print_moveto (job->priv->print_ctxt, x, yy);
- gnome_print_lineto (job->priv->print_ctxt, x + width, yy);
- gnome_print_stroke (job->priv->print_ctxt);
+ cairo_set_line_width (ctx, SEPARATOR_LINE_WIDTH);
+ cairo_move_to (ctx, x, yy);
+ cairo_line_to (ctx, x + width, yy);
+ cairo_stroke (ctx);
}
}
@@ -2840,7 +2621,6 @@
gboolean setting)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
setting = (setting != FALSE);
@@ -2889,7 +2669,6 @@
gboolean setting)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
setting = (setting != FALSE);
@@ -2934,7 +2713,6 @@
PangoFontDescription *desc)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
if (desc)
desc = pango_font_description_copy (desc);
@@ -2965,22 +2743,9 @@
gtk_source_print_job_set_header_footer_font (GtkSourcePrintJob *job,
const gchar *font_name)
{
- PangoFontDescription *desc;
-
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
- if (font_name != NULL)
- {
- desc = font_description_from_gnome_font_name (font_name);
- if (desc)
- {
- gtk_source_print_job_set_header_footer_font_desc (job, desc);
- pango_font_description_free (desc);
- }
- }
- else
- gtk_source_print_job_set_header_footer_font_desc (job, NULL);
+ gtk_source_print_job_set_header_footer_font_desc (job, NULL);
}
/**
@@ -3024,10 +2789,7 @@
{
g_return_val_if_fail (GTK_IS_SOURCE_PRINT_JOB (job), NULL);
- if (job->priv->header_footer_font != NULL)
- return font_description_to_gnome_font_name (job->priv->header_footer_font);
- else
- return NULL;
+ return NULL;
}
/**
@@ -3060,7 +2822,6 @@
gboolean separator)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
/* FIXME: validate given strings? */
g_free (job->priv->header_format_left);
@@ -3090,7 +2851,6 @@
gboolean separator)
{
g_return_if_fail (GTK_IS_SOURCE_PRINT_JOB (job));
- g_return_if_fail (!job->priv->printing);
/* FIXME: validate given strings? */
g_free (job->priv->footer_format_left);
@@ -3100,4 +2860,12 @@
job->priv->footer_format_center = g_strdup (center);
job->priv->footer_format_right = g_strdup (right);
job->priv->footer_separator = separator;
+}
+
+void
+gtk_source_print_job_set_print_context (GtkSourcePrintJob *job,
+ GtkPrintContext *context)
+{
+ job->priv->print_context = context;
+ gtk_source_print_job_set_pango_context (job, gtk_print_context_create_context (context));
}
Index: gtksourceprintjob.h
===================================================================
RCS file: /cvs/gnome/gtksourceview/gtksourceview/gtksourceprintjob.h,v
retrieving revision 1.3
diff -u -r1.3 gtksourceprintjob.h
--- gtksourceprintjob.h 15 Jul 2004 21:58:38 -0000 1.3
+++ gtksourceprintjob.h 28 Apr 2006 18:19:30 -0000
@@ -24,8 +24,6 @@
#ifndef __GTK_SOURCE_PRINT_JOB_H__
#define __GTK_SOURCE_PRINT_JOB_H__
-#include <libgnomeprint/gnome-print-config.h>
-#include <libgnomeprint/gnome-print-job.h>
#include <gtksourceview/gtksourceview.h>
G_BEGIN_DECLS
@@ -63,13 +61,10 @@
GType gtk_source_print_job_get_type (void) G_GNUC_CONST;
/* constructor functions */
-GtkSourcePrintJob *gtk_source_print_job_new (GnomePrintConfig *config);
-GtkSourcePrintJob *gtk_source_print_job_new_with_buffer (GnomePrintConfig *config,
- GtkSourceBuffer *buffer);
+GtkSourcePrintJob *gtk_source_print_job_new (void);
+GtkSourcePrintJob *gtk_source_print_job_new_with_buffer (GtkSourceBuffer *buffer);
+
/* print job basic configuration */
-void gtk_source_print_job_set_config (GtkSourcePrintJob *job,
- GnomePrintConfig *config);
-GnomePrintConfig *gtk_source_print_job_get_config (GtkSourcePrintJob *job);
void gtk_source_print_job_set_buffer (GtkSourcePrintJob *job,
GtkSourceBuffer *buffer);
GtkSourceBuffer *gtk_source_print_job_get_buffer (GtkSourcePrintJob *job);
@@ -118,8 +113,8 @@
PangoFontDescription *gtk_source_print_job_get_header_footer_font_desc (GtkSourcePrintJob *job);
/* printing operations */
-GnomePrintJob *gtk_source_print_job_print (GtkSourcePrintJob *job);
-GnomePrintJob *gtk_source_print_job_print_range (GtkSourcePrintJob *job,
+void gtk_source_print_job_print (GtkSourcePrintJob *job);
+void gtk_source_print_job_print_range (GtkSourcePrintJob *job,
const GtkTextIter *start,
const GtkTextIter *end);
@@ -128,13 +123,13 @@
const GtkTextIter *start,
const GtkTextIter *end);
void gtk_source_print_job_cancel (GtkSourcePrintJob *job);
-GnomePrintJob *gtk_source_print_job_get_print_job (GtkSourcePrintJob *job);
+
+/* TODO: return the gtk print job */
+void gtk_source_print_job_get_print_job (GtkSourcePrintJob *job);
/* information for asynchronous ops and headers and footers callback */
guint gtk_source_print_job_get_page (GtkSourcePrintJob *job);
guint gtk_source_print_job_get_page_count (GtkSourcePrintJob *job);
-GnomePrintContext *gtk_source_print_job_get_print_context (GtkSourcePrintJob *job);
-
/* header and footer */
void gtk_source_print_job_set_print_header (GtkSourcePrintJob *job,
@@ -157,6 +152,20 @@
const gchar *center,
const gchar *right,
gboolean separator);
+
+void
+gtk_source_print_job_print_page (GtkSourcePrintJob *job,
+ gint page_nr,
+ GtkPrintContext *context);
+
+
+gboolean
+gtk_source_print_job_prepare (GtkSourcePrintJob *job);
+
+void gtk_source_print_job_set_print_context (GtkSourcePrintJob *job,
+ GtkPrintContext *context);
+void gtk_source_print_job_set_pango_context (GtkSourcePrintJob *job,
+ PangoContext *context);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]