plug-ins/print/print.[ch] plug-ins/print/print-draw-page.c

2008-12-30  Sven Neumann  <sven@gimp.org>

	* plug-ins/print/print.[ch]
	* plug-ins/print/print-draw-page.c
	* plug-ins/print/print-page-layout.c
	* plug-ins/print/print-settings.c: optionally draw crop-marks.


svn path=/trunk/; revision=27859
This commit is contained in:
Sven Neumann 2008-12-30 21:36:04 +00:00 committed by Sven Neumann
parent 012b46e427
commit 8ae65ad5a3
6 changed files with 156 additions and 55 deletions

View file

@ -1,3 +1,10 @@
2008-12-30 Sven Neumann <sven@gimp.org>
* plug-ins/print/print.[ch]
* plug-ins/print/print-draw-page.c
* plug-ins/print/print-page-layout.c
* plug-ins/print/print-settings.c: optionally draw crop-marks.
2008-12-30 Marco Ciampa <ciampix@libero.it>
* app/actions/error-console-actions.c: small typo fix.

View file

@ -29,7 +29,49 @@
#include "libgimp/stdplugins-intl.h"
static cairo_surface_t * print_cairo_surface_from_drawable (gint32 drawable_ID);
static cairo_surface_t * print_surface_from_drawable (gint32 drawable_ID);
static void print_draw_crop_marks (GtkPrintContext *context,
gdouble x,
gdouble y,
gdouble w,
gdouble h);
gboolean
print_draw_page (GtkPrintContext *context,
PrintData *data)
{
cairo_t *cr = gtk_print_context_get_cairo_context (context);
cairo_surface_t *surface;
gint width;
gint height;
gdouble scale_x;
gdouble scale_y;
surface = print_surface_from_drawable (data->drawable_id);
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
scale_x = gtk_print_context_get_dpi_x (context) / data->xres;
scale_y = gtk_print_context_get_dpi_y (context) / data->yres;
cairo_translate (cr, data->offset_x, data->offset_y);
if (data->draw_crop_marks)
print_draw_crop_marks (context,
0, 0, width * scale_x, height * scale_y);
cairo_scale (cr, scale_x, scale_y);
cairo_rectangle (cr, 0, 0, width, height);
cairo_set_source_surface (cr, surface, 0, 0);
cairo_fill (cr);
cairo_surface_destroy (surface);
return TRUE;
}
static inline void
convert_from_rgb (const guchar *src,
@ -127,35 +169,8 @@ convert_from_indexeda (const guchar *src,
}
}
gboolean
print_draw_page (GtkPrintContext *context,
PrintData *data)
{
cairo_t *cr;
cairo_surface_t *surface;
cr = gtk_print_context_get_cairo_context (context);
surface = print_cairo_surface_from_drawable (data->drawable_id);
cairo_translate (cr, data->offset_x, data->offset_y);
cairo_scale (cr,
gtk_print_context_get_dpi_x (context) / data->xres,
gtk_print_context_get_dpi_y (context) / data->yres);
cairo_rectangle (cr,
0, 0,
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
cairo_set_source_surface (cr, surface, 0, 0);
cairo_fill (cr);
cairo_surface_destroy (surface);
return TRUE;
}
static cairo_surface_t *
print_cairo_surface_from_drawable (gint32 drawable_ID)
print_surface_from_drawable (gint32 drawable_ID)
{
GimpDrawable *drawable = gimp_drawable_get (drawable_ID);
GimpPixelRgn region;
@ -243,3 +258,50 @@ print_cairo_surface_from_drawable (gint32 drawable_ID)
return surface;
}
static void
print_draw_crop_marks (GtkPrintContext *context,
gdouble x,
gdouble y,
gdouble w,
gdouble h)
{
cairo_t *cr = gtk_print_context_get_cairo_context (context);
gdouble len = MIN (gtk_print_context_get_width (context),
gtk_print_context_get_height (context)) / 20.0;
/* upper left */
cairo_move_to (cr, x - len, y);
cairo_line_to (cr, x - len / 5, y);
cairo_move_to (cr, x, y - len);
cairo_line_to (cr, x, y - len / 5);
/* upper right */
cairo_move_to (cr, x + w + len / 5, y);
cairo_line_to (cr, x + w + len, y);
cairo_move_to (cr, x + w, y - len);
cairo_line_to (cr, x + w, y - len / 5);
/* lower left */
cairo_move_to (cr, x - len, y + h);
cairo_line_to (cr, x - len / 5, y + h);
cairo_move_to (cr, x, y + h + len);
cairo_line_to (cr, x, y + h + len / 5);
/* lower right */
cairo_move_to (cr, x + w + len / 5, y + h);
cairo_line_to (cr, x + w + len, y + h);
cairo_move_to (cr, x + w, y + h + len);
cairo_line_to (cr, x + w, y + h + len / 5);
cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
cairo_set_line_width (cr, 2);
cairo_stroke (cr);
}

View file

@ -89,6 +89,8 @@ static void print_size_info_set_resolution (PrintSizeInfo *info,
static void print_size_info_set_page_setup (PrintSizeInfo *info);
static void print_draw_crop_marks_toggled (GtkWidget *widget);
static PrintSizeInfo info;
@ -155,6 +157,17 @@ print_page_layout_gui (PrintData *data,
NULL);
gtk_widget_show (button);
/* crop marks toggle */
button = gtk_check_button_new_with_mnemonic (_("_Draw Crop Marks"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
data->draw_crop_marks);
gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "toggled",
G_CALLBACK (print_draw_crop_marks_toggled),
NULL);
gtk_widget_show (button);
/* preview */
frame = gimp_frame_new (_("Preview"));
gtk_box_pack_start (GTK_BOX (main_hbox), frame, TRUE, TRUE, 0);
@ -715,7 +728,7 @@ print_size_info_resolution_changed (GtkWidget *widget)
static void
print_size_info_use_full_page_toggled (GtkWidget *widget)
{
gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
info.data->use_full_page = active;
@ -874,3 +887,12 @@ print_size_info_set_page_setup (PrintSizeInfo *info)
gimp_size_entry_set_refval_boundaries (info->resolution_entry, 1,
y, GIMP_MAX_RESOLUTION);
}
static void
print_draw_crop_marks_toggled (GtkWidget *widget)
{
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
info.data->draw_crop_marks = active;
}

View file

@ -98,6 +98,8 @@ print_settings_save (PrintData *data)
"center-mode", data->center);
g_key_file_set_boolean (key_file, "image-setup",
"use-full-page", data->use_full_page);
g_key_file_set_boolean (key_file, "image-setup",
"crop-marks", data->draw_crop_marks);
print_utils_key_file_save_as_parasite (key_file,
data->image_id,
@ -223,38 +225,44 @@ print_settings_load_from_key_file (PrintData *data,
if (g_key_file_has_key (key_file, "image-setup", "unit", NULL))
{
data->unit = g_key_file_get_integer (key_file,
"image-setup", "unit", NULL);
data->unit = g_key_file_get_integer (key_file, "image-setup",
"unit", NULL);
}
if (g_key_file_has_key (key_file, "image-setup", "x-resolution", NULL) &&
g_key_file_has_key (key_file, "image-setup", "y-resolution", NULL))
{
data->xres = g_key_file_get_double (key_file,
"image-setup", "x-resolution", NULL);
data->yres = g_key_file_get_double (key_file,
"image-setup", "y-resolution", NULL);
data->xres = g_key_file_get_double (key_file, "image-setup",
"x-resolution", NULL);
data->yres = g_key_file_get_double (key_file, "image-setup",
"y-resolution", NULL);
}
if (g_key_file_has_key (key_file, "image-setup", "x-offset", NULL) &&
g_key_file_has_key (key_file, "image-setup", "y-offset", NULL))
{
data->offset_x = g_key_file_get_double (key_file,
"image-setup", "x-offset", NULL);
data->offset_y = g_key_file_get_double (key_file,
"image-setup", "y-offset", NULL);
data->offset_x = g_key_file_get_double (key_file, "image-setup",
"x-offset", NULL);
data->offset_y = g_key_file_get_double (key_file, "image-setup",
"y-offset", NULL);
}
if (g_key_file_has_key (key_file, "image-setup", "center-mode", NULL))
{
data->center = g_key_file_get_integer (key_file,
"image-setup", "center-mode", NULL);
data->center = g_key_file_get_integer (key_file, "image-setup",
"center-mode", NULL);
}
if (g_key_file_has_key (key_file, "image-setup", "use-full-page", NULL))
{
data->use_full_page = g_key_file_get_boolean (key_file,
"image-setup", "use-full-page", NULL);
data->use_full_page = g_key_file_get_boolean (key_file, "image-setup",
"use-full-page", NULL);
}
if (g_key_file_has_key (key_file, "image-setup", "crop-marks", NULL))
{
data->draw_crop_marks = g_key_file_get_boolean (key_file, "image-setup",
"crop-marks", NULL);
}
gtk_print_operation_set_print_settings (operation, settings);

View file

@ -103,7 +103,7 @@ query (void)
"Print the image using the GTK+ Print API.",
"Bill Skaggs, Sven Neumann, Stefan Röllin",
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
"2006, 2007",
"2006 - 2008",
N_("_Print..."),
"*",
GIMP_PLUGIN,
@ -220,15 +220,16 @@ print_image (gint32 image_ID,
print_page_setup_load (operation, image_ID);
/* fill in the PrintData struct */
data.image_id = image_ID;
data.drawable_id = layer;
data.unit = gimp_get_default_unit ();
data.image_unit = gimp_image_get_unit (image_ID);
data.offset_x = 0;
data.offset_y = 0;
data.center = CENTER_BOTH;
data.use_full_page = FALSE;
data.operation = operation;
data.image_id = image_ID;
data.drawable_id = layer;
data.unit = gimp_get_default_unit ();
data.image_unit = gimp_image_get_unit (image_ID);
data.offset_x = 0;
data.offset_y = 0;
data.center = CENTER_BOTH;
data.use_full_page = FALSE;
data.draw_crop_marks = FALSE;
data.operation = operation;
gimp_image_get_resolution (image_ID, &data.xres, &data.yres);

View file

@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
typedef enum
{
CENTER_NONE = 0,
@ -36,6 +37,6 @@ typedef struct
gdouble offset_y;
PrintCenterMode center;
gboolean use_full_page;
gboolean draw_crop_marks;
GtkPrintOperation *operation;
} PrintData;