Commit e61505be authored by William Skaggs's avatar William Skaggs

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* plug-ins/print/print.[ch]
	* plug-ins/print/print-draw-page.[ch]
	* plug-ins/print/print-page-layout.c
	* plug-ins/print/print-settings.c: implement preview internally,
	assorted other small changes.
parent d09aba09
2006-06-29 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* plug-ins/print/print.[ch]
* plug-ins/print/print-draw-page.[ch]
* plug-ins/print/print-page-layout.c
* plug-ins/print/print-settings.c: implement preview internally,
assorted other small changes.
2006-06-29 Sven Neumann <sven@gimp.org>
* plug-ins/common/screenshot.c: use macros in an attempt to make
......
......@@ -27,9 +27,12 @@
#include "print.h"
#include "print-draw-page.h"
#include "libgimp/stdplugins-intl.h"
/* In points */
#define HEADER_HEIGHT (20*72/25.4)
#define EPSILON 0.0001
static guchar * get_image_pixels (PrintData *data,
gint *width_ptr,
......@@ -41,7 +44,7 @@ static void draw_info_header (GtkPrintContext *context,
PrintData *data);
void
gboolean
draw_page_cairo (GtkPrintContext *context,
PrintData *data)
{
......@@ -76,20 +79,20 @@ draw_page_cairo (GtkPrintContext *context,
scale_x = cr_dpi_x / image_xres;
scale_y = cr_dpi_y / image_yres;
if (scale_x * image_width > cr_width)
if (scale_x * image_width > cr_width + EPSILON)
{
g_message ("Image width (%g in) is larger than printable width (%g in).",
g_message (_("Image width (%lg in) is larger than printable width (%lg in)."),
image_width / image_xres, cr_width / cr_dpi_x);
gtk_print_operation_cancel (data->operation);
return;
return FALSE;
}
if (scale_y * image_height > cr_height)
if (scale_y * image_height > cr_height + EPSILON)
{
g_message ("Image height (%g in) is larger than printable height (%g in).",
g_message (_("Image height (%lg in) is larger than printable height (%lg in)."),
image_height / image_yres, cr_height / cr_dpi_y);
gtk_print_operation_cancel (data->operation);
return;
return FALSE;
}
/* print header if it is requested */
......@@ -115,6 +118,7 @@ draw_page_cairo (GtkPrintContext *context,
g_free (pixels);
return TRUE;
}
static guchar *
......
......@@ -16,5 +16,5 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
void draw_page_cairo (GtkPrintContext *context,
PrintData *data);
gboolean draw_page_cairo (GtkPrintContext *context,
PrintData *data);
......@@ -156,6 +156,9 @@ run_page_setup_dialog (GtkWidget *widget,
page_setup, settings);
gtk_print_operation_set_default_page_setup (operation, page_setup);
/* needed for previewing */
data->orientation = gtk_page_setup_get_orientation (page_setup);
}
#define SB_WIDTH 8
......
......@@ -307,8 +307,6 @@ load_print_settings_from_key_file (PrintData *data,
}
g_strfreev (keys);
gtk_print_operation_set_print_settings (operation, settings);
/* page setup parameters */
page_setup = gtk_print_operation_get_default_page_setup (operation);
......@@ -322,6 +320,8 @@ load_print_settings_from_key_file (PrintData *data,
orientation = g_key_file_get_integer (key_file, "page-setup",
"orientation", &error);
gtk_page_setup_set_orientation (page_setup, orientation);
gtk_print_settings_set_orientation (settings, orientation);
data->orientation = orientation;
}
gtk_print_operation_set_default_page_setup (operation, page_setup);
......@@ -343,6 +343,8 @@ load_print_settings_from_key_file (PrintData *data,
else
data->unit = GIMP_UNIT_INCH;
gtk_print_operation_set_print_settings (operation, settings);
return TRUE;
}
......
......@@ -23,6 +23,8 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include <glib/gstdio.h>
#include "print.h"
#include "print-settings.h"
#include "print-page-layout.h"
......@@ -65,6 +67,12 @@ static void custom_widget_apply (GtkPrintOperation *operation,
GtkWidget *widget,
gpointer user_data);
static gboolean print_preview (GtkPrintOperation *operation,
GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkWindow *parent,
gpointer user_data);
const GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -178,6 +186,8 @@ print_image (gint32 image_ID,
G_CALLBACK (create_custom_widget), data);
g_signal_connect (operation, "custom-widget-apply",
G_CALLBACK (custom_widget_apply), data);
g_signal_connect (operation, "preview",
G_CALLBACK (print_preview), data);
gtk_print_operation_set_custom_tab_label (operation, _("Layout"));
......@@ -185,7 +195,8 @@ print_image (gint32 image_ID,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
NULL, &error);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
if (res == GTK_PRINT_OPERATION_RESULT_APPLY ||
res == GTK_PRINT_OPERATION_RESULT_IN_PROGRESS)
{
save_print_settings (data);
}
......@@ -278,3 +289,107 @@ custom_widget_apply (GtkPrintOperation *operation,
gimp_image_undo_group_end (data->image_id);
}
}
#define PREVIEW_SCALE 72
static gboolean
print_preview (GtkPrintOperation *operation,
GtkPrintOperationPreview *preview,
GtkPrintContext *context,
GtkWindow *parent,
gpointer user_data)
{
PrintData *data = user_data;
GtkPageSetup *page_setup = gtk_print_context_get_page_setup (context);
GtkPaperSize *paper_size;
gdouble paper_width;
gdouble paper_height;
gdouble top_margin;
gdouble bottom_margin;
gdouble left_margin;
gdouble right_margin;
gint preview_width;
gint preview_height;
cairo_t *cr;
cairo_surface_t *surface;
GtkPageOrientation orientation;
paper_size = gtk_page_setup_get_paper_size (page_setup);
paper_width = gtk_paper_size_get_width (paper_size, GTK_UNIT_INCH);
paper_height = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);
top_margin = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_INCH);
bottom_margin = gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_INCH);
left_margin = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_INCH);
right_margin = gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_INCH);
/* the print context does not have the page orientation, it is transformed */
orientation = data->orientation;
if (orientation == GTK_PAGE_ORIENTATION_PORTRAIT ||
orientation == GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT)
{
preview_width = PREVIEW_SCALE * paper_width;
preview_height = PREVIEW_SCALE * paper_height;
}
else
{
preview_width = PREVIEW_SCALE * paper_height;
preview_height = PREVIEW_SCALE * paper_width;
}
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
preview_width, preview_height);
if (CAIRO_STATUS_SUCCESS != cairo_surface_status (surface))
{
g_message ("Unable to create preview (not enough memory?)");
return TRUE;
}
cr = cairo_create (surface);
gtk_print_context_set_cairo_context (context, cr, PREVIEW_SCALE, PREVIEW_SCALE);
/* fill page with white */
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_new_path (cr);
cairo_rectangle (cr, 0, 0, preview_width, preview_height);
cairo_fill (cr);
cairo_translate (cr, left_margin * PREVIEW_SCALE, right_margin * PREVIEW_SCALE);
if (draw_page_cairo (context, data))
{
cairo_status_t status;
gchar *fname;
fname = gimp_temp_name ("png");
status = cairo_surface_write_to_png (surface, fname);
cairo_destroy (cr);
cairo_surface_destroy (surface);
if (status == CAIRO_STATUS_SUCCESS)
{
GtkWidget *dialog;
GtkWidget *image;
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (dialog), _("Print Preview"));
image = gtk_image_new_from_file (fname);
g_unlink (fname);
g_free (fname);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
}
return TRUE;
}
......@@ -30,5 +30,6 @@ typedef struct
gdouble xres;
gdouble yres;
gboolean print_size_changed;
GtkPageOrientation orientation;
} PrintData;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment