plug-ins/print/Makefile.am new files.

2008-02-04  Sven Neumann  <sven@gimp.org>

	* plug-ins/print/Makefile.am
	* plug-ins/print/print-page-setup.[ch]: new files.

	* plug-ins/print/print-page-layout.c
	* plug-ins/print/print-settings.c
	* plug-ins/print/print.c: first draft of a Page Setup menu entry
	instead of the "Adjust Page Size" button (bug #513291).
	
	* plug-ins/print/print.h
	* plug-ins/print/print-draw-page.c: removed unused code.

svn path=/trunk/; revision=24789
This commit is contained in:
Sven Neumann 2008-02-04 16:59:45 +00:00 committed by Sven Neumann
parent 7af7be609d
commit b7d37bd4a5
9 changed files with 171 additions and 348 deletions

View File

@ -1,3 +1,16 @@
2008-02-04 Sven Neumann <sven@gimp.org>
* plug-ins/print/Makefile.am
* plug-ins/print/print-page-setup.[ch]: new files.
* plug-ins/print/print-page-layout.c
* plug-ins/print/print-settings.c
* plug-ins/print/print.c: first draft of a Page Setup menu entry
instead of the "Adjust Page Size" button (bug #513291).
* plug-ins/print/print.h
* plug-ins/print/print-draw-page.c: removed unused code.
2008-02-04 Sven Neumann <sven@gimp.org>
* app/paint/gimpbrushcore.c (gimp_brush_core_create_bound_segs):

View File

@ -44,6 +44,8 @@ print_SOURCES = \
print-draw-page.h \
print-page-layout.c \
print-page-layout.h \
print-page-setup.h \
print-page-setup.c \
print-preview.c \
print-preview.h \
print-settings.c \

View File

@ -33,16 +33,10 @@
#define INT_BLEND(a,b,alpha,tmp) (INT_MULT((a) - (b), alpha, tmp) + (b))
static void convert_from_rgb (guchar *pixels,
gint width);
static void convert_from_rgba (guchar *pixels,
gint width);
#if 0
static void draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data);
#endif
static void convert_from_rgb (guchar *pixels,
gint width);
static void convert_from_rgba (guchar *pixels,
gint width);
gboolean
@ -80,19 +74,6 @@ draw_page_cairo (GtkPrintContext *context,
scale_x = cr_dpi_x / data->xres;
scale_y = cr_dpi_y / data->yres;
#if 0
/* print header if it is requested */
if (data->show_info_header)
{
draw_info_header (context, cr, data);
/* In points */
#define HEADER_HEIGHT (20 * 72.0 / 25.4)
cairo_translate (cr, 0, HEADER_HEIGHT);
cr_height -= HEADER_HEIGHT;
}
#endif
cairo_translate (cr,
data->offset_x / cr_dpi_x * 72.0,
data->offset_y / cr_dpi_y * 72.0);
@ -182,134 +163,3 @@ convert_from_rgba (guchar *pixels,
cairo_data[i] = 0xFF000000 | (r << 16) | (g << 8) | b;
}
}
#if 0
static void
draw_info_header (GtkPrintContext *context,
cairo_t *cr,
PrintData *data)
{
PangoLayout *layout;
PangoFontDescription *desc;
gdouble text_height;
gdouble text_width;
gdouble fname_text_width;
gint layout_height;
gint layout_width;
gchar date_buffer[100];
GDate *date;
const gchar *name_str;
GimpParasite *parasite;
const gchar *end_ptr;
gchar *filename;
gdouble cr_width;
cairo_save (cr);
cr_width = gtk_print_context_get_width (context);
cairo_rectangle (cr, 0, 0, cr_width, HEADER_HEIGHT);
cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
cairo_fill_preserve (cr);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
layout = gtk_print_context_create_pango_layout (context);
desc = pango_font_description_from_string ("sans 14");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_layout_set_width (layout, -1);
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
/* image name */
pango_layout_set_text (layout, gimp_image_get_name (data->image_id), -1);
pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble) layout_height / PANGO_SCALE;
cairo_move_to (cr, 0.02 * cr_width, (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout);
/* user name */
name_str = g_get_real_name ();
if (name_str && g_utf8_validate (name_str, -1, &end_ptr))
{
pango_layout_set_text (layout, name_str, -1);
pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr, 0.5 * cr_width - 0.5 * text_width,
(HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout);
}
/* date */
date = g_date_new ();
g_date_set_time_t (date, time (NULL));
g_date_strftime (date_buffer, 100, "%x", date);
g_date_free (date);
pango_layout_set_text (layout, date_buffer, -1);
pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr,
0.98 * cr_width - text_width,
(HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout);
/* file name if any */
filename = gimp_image_get_filename (data->image_id);
if (filename)
{
pango_layout_set_text (layout,
gimp_filename_to_utf8 (filename), -1);
g_free (filename);
pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble) layout_height / PANGO_SCALE;
fname_text_width = (gdouble) layout_width / PANGO_SCALE;
cairo_move_to (cr,
0.02 * cr_width, 4 * (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout);
}
else
{
fname_text_width = 0;
}
/* image comment if it is short */
parasite = gimp_image_parasite_find (data->image_id, "gimp-comment");
if (parasite)
{
pango_layout_set_text (layout, gimp_parasite_data (parasite), -1);
pango_layout_get_size (layout, &layout_width, &layout_height);
text_height = (gdouble) layout_height / PANGO_SCALE;
text_width = (gdouble) layout_width / PANGO_SCALE;
if (fname_text_width + text_width < 0.8 * cr_width &&
text_height < 0.5 * HEADER_HEIGHT)
{
cairo_move_to (cr, 0.98 * cr_width - text_width,
4 * (HEADER_HEIGHT - text_height) / 5);
pango_cairo_show_layout (cr, layout);
}
gimp_parasite_free (parasite);
}
g_object_unref (layout);
cairo_restore (cr);
}
#endif

View File

@ -58,13 +58,12 @@ enum
};
static void run_page_setup_dialog (GtkWidget *widget,
PrintData *data);
static void print_page_setup_notify (GtkPrintOperation *operation);
static GtkWidget * print_size_frame (PrintData *data,
static GtkWidget * print_size_frame (PrintData *data,
GtkSizeGroup *label_group,
GtkSizeGroup *entry_group);
static GtkWidget * print_offset_frame (PrintData *data,
static GtkWidget * print_offset_frame (PrintData *data,
GtkSizeGroup *label_group,
GtkSizeGroup *entry_group);
@ -145,14 +144,6 @@ print_page_layout_gui (PrintData *data)
gtk_box_pack_start (GTK_BOX (hbox), info.area_label, TRUE, TRUE, 0);
gtk_widget_show (info.area_label);
button = gtk_button_new_with_mnemonic (_("_Adjust Page Size "
"and Orientation"));
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (run_page_setup_dialog),
data);
gtk_widget_show (button);
/* main hbox */
main_hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (layout), main_hbox, TRUE, TRUE, 0);
@ -170,20 +161,6 @@ print_page_layout_gui (PrintData *data)
label_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
entry_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
#if 0
/* Commented out until the header becomes a little more configurable
* and we can provide a user interface to include/exclude information.
*/
button = gtk_check_button_new_with_label ("Print image header");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
data->show_info_header);
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
g_signal_connect (G_OBJECT (button), "toggled",
G_CALLBACK (gimp_toggle_button_update),
&data->show_info_header);
gtk_widget_show (button);
#endif
/* size entry area for the image's print size */
frame = print_size_frame (data, label_group, entry_group);
@ -221,45 +198,31 @@ print_page_layout_gui (PrintData *data)
print_size_info_set_page_setup (&info);
g_signal_connect (data->operation, "notify::default-page-setup",
G_CALLBACK (print_page_setup_notify),
&info);
return layout;
}
static void
run_page_setup_dialog (GtkWidget *widget,
PrintData *data)
{
GtkPrintOperation *operation = data->operation;
GtkPrintSettings *settings;
GtkPageSetup *page_setup;
GtkWidget *toplevel;
/* find a transient parent if possible */
toplevel = gtk_widget_get_toplevel (widget);
if (! GTK_WIDGET_TOPLEVEL (toplevel))
toplevel = NULL;
settings = gtk_print_operation_get_print_settings (operation);
if (! settings)
settings = gtk_print_settings_new ();
page_setup = gtk_print_operation_get_default_page_setup (operation);
page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (toplevel),
page_setup, settings);
gtk_print_operation_set_default_page_setup (operation, page_setup);
gimp_print_preview_set_page_setup (GIMP_PRINT_PREVIEW (info.preview),
page_setup);
print_size_info_set_page_setup (&info);
}
#define SB_WIDTH 8
static void
print_page_setup_notify (GtkPrintOperation *operation)
{
GtkPageSetup *setup;
setup = gtk_print_operation_get_default_page_setup (operation);
gimp_print_preview_set_page_setup (GIMP_PRINT_PREVIEW (info.preview),
setup);
print_size_info_set_page_setup (&info);
}
static GtkWidget *
print_size_frame (PrintData *data,
print_size_frame (PrintData *data,
GtkSizeGroup *label_group,
GtkSizeGroup *entry_group)
{
@ -901,7 +864,7 @@ print_size_info_set_page_setup (PrintSizeInfo *info)
if (info->chain && gimp_chain_button_get_active (info->chain))
{
gdouble ratio_x = page_width / (gdouble) info->image_width;
gdouble ratio_x = page_width / (gdouble) info->image_width;
gdouble ratio_y = page_height / (gdouble) info->image_height;
if (ratio_x < ratio_y)

View File

@ -0,0 +1,91 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "print-page-setup.h"
static void print_page_setup_save (GtkPrintOperation *operation);
void
print_page_setup_dialog (GtkPrintOperation *operation)
{
GtkPrintSettings *settings = gtk_print_settings_new ();
GtkPageSetup *setup;
print_page_setup_load (operation);
setup = gtk_print_operation_get_default_page_setup (operation);
setup = gtk_print_run_page_setup_dialog (NULL, setup, settings);
gtk_print_operation_set_default_page_setup (operation, setup);
print_page_setup_save (operation);
}
gboolean
print_page_setup_load (GtkPrintOperation *operation)
{
GtkPageSetup *setup;
gchar *filename;
filename = g_build_filename (gimp_directory (), "print-page-setup", NULL);
setup = gtk_page_setup_new_from_file (filename, NULL);
g_free (filename);
if (setup)
{
gtk_print_operation_set_default_page_setup (operation, setup);
g_object_unref (setup);
return TRUE;
}
return FALSE;
}
static void
print_page_setup_save (GtkPrintOperation *operation)
{
GtkPageSetup *setup;
gchar *filename;
GError *error = NULL;
setup = gtk_print_operation_get_default_page_setup (operation);
filename = g_build_filename (gimp_directory (), "print-page-setup", NULL);
gtk_page_setup_to_file (setup, filename, &error);
if (error)
{
g_message ("Error saving page setup as resource file: %s",
error->message);
g_error_free (error);
}
g_free (filename);
}

View File

@ -0,0 +1,22 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
void print_page_setup_dialog (GtkPrintOperation *operation);
gboolean print_page_setup_load (GtkPrintOperation *operation);

View File

@ -16,9 +16,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define PRINT_SETTINGS_MAJOR_VERSION 0
#define PRINT_SETTINGS_MINOR_VERSION 3
#include "config.h"
#include <libgimp/gimp.h>
@ -28,6 +25,10 @@
#include "print-settings.h"
#define PRINT_SETTINGS_MAJOR_VERSION 0
#define PRINT_SETTINGS_MINOR_VERSION 4
static GKeyFile * print_settings_key_file_from_settings (PrintData *data);
static void save_print_settings_resource_file (GKeyFile *settings_key_file);
@ -117,7 +118,6 @@ print_settings_key_file_from_settings (PrintData *data)
GtkPrintOperation *operation = data->operation;
GtkPrintSettings *settings;
GKeyFile *key_file = g_key_file_new ();
GtkPageSetup *page_setup;
g_key_file_set_list_separator (key_file, '=');
@ -130,57 +130,8 @@ print_settings_key_file_from_settings (PrintData *data)
/* save the contents of the GtkPrintSettings for the operation */
settings = gtk_print_operation_get_print_settings (operation);
if (settings)
{
gtk_print_settings_foreach (settings, add_print_setting_to_key_file,
key_file);
}
/* page setup */
page_setup = gtk_print_operation_get_default_page_setup (operation);
if (page_setup)
{
GtkPaperSize *paper_size;
GtkPageOrientation orientation;
const gchar *name;
orientation = gtk_page_setup_get_orientation (page_setup);
g_key_file_set_integer (key_file, "page-setup", "orientation",
orientation);
paper_size = gtk_page_setup_get_paper_size (page_setup);
name = gtk_paper_size_get_name (paper_size);
if (name)
{
g_key_file_set_string (key_file, "paper-size", "name", name);
name = gtk_paper_size_get_ppd_name (paper_size);
if (name)
{
g_key_file_set_string (key_file, "paper-size", "ppd-name",
name);
}
if (name || gtk_paper_size_is_custom (paper_size))
{
g_key_file_set_string (key_file, "paper-size", "display-name",
gtk_paper_size_get_display_name (paper_size));
g_key_file_set_double (key_file, "paper-size", "width",
gtk_paper_size_get_width (paper_size,
GTK_UNIT_POINTS));
g_key_file_set_double (key_file, "paper-size", "height",
gtk_paper_size_get_height (paper_size,
GTK_UNIT_POINTS));
}
}
}
#if 0
/* other settings */
g_key_file_set_boolean (key_file, "other-settings", "show-header",
data->show_info_header);
#endif
gtk_print_settings_foreach (settings, add_print_setting_to_key_file,
key_file);
return key_file;
}
@ -314,47 +265,12 @@ print_settings_key_file_from_parasite (gint32 image_ID)
return check_version (key_file);
}
static GtkPaperSize *
load_paper_size_from_key_file (GKeyFile *key_file)
{
const gchar *name;
const gchar *ppd_name;
const gchar *display_name;
gdouble width;
gdouble height;
name = g_key_file_get_string (key_file, "paper-size", "name",
NULL);
ppd_name = g_key_file_get_string (key_file, "paper-size", "ppd-name",
NULL);
display_name = g_key_file_get_string (key_file, "paper-size", "display-name",
NULL);
width = g_key_file_get_double (key_file, "paper-size", "width", NULL);
height = g_key_file_get_double (key_file, "paper-size", "height", NULL);
if (ppd_name && display_name)
{
return gtk_paper_size_new_from_ppd (ppd_name,
display_name, width, height);
}
if (name && display_name)
{
return gtk_paper_size_new_custom (name,
display_name, width, height,
GTK_UNIT_POINTS);
}
return gtk_paper_size_new (name);
}
static gboolean
load_print_settings_from_key_file (PrintData *data,
GKeyFile *key_file)
{
GtkPrintOperation *operation = data->operation;
GtkPrintSettings *settings;
GtkPageSetup *page_setup;
gchar **keys;
gsize n_keys;
gint i;
@ -383,34 +299,6 @@ load_print_settings_from_key_file (PrintData *data,
g_strfreev (keys);
/* page setup parameters */
page_setup = gtk_print_operation_get_default_page_setup (operation);
if (! page_setup)
page_setup = gtk_page_setup_new ();
if (g_key_file_has_key (key_file, "paper-size", "name", NULL))
{
GtkPaperSize *paper_size = load_paper_size_from_key_file (key_file);
gtk_page_setup_set_paper_size_and_default_margins (page_setup,
paper_size);
}
if (g_key_file_has_key (key_file, "page-setup", "orientation", NULL))
{
GtkPageOrientation orientation;
orientation = g_key_file_get_integer (key_file,
"page-setup", "orientation", NULL);
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);
g_object_unref (page_setup);
if (g_key_file_has_key (key_file, "image-setup", "unit", NULL))
{
data->unit = g_key_file_get_integer (key_file,
@ -447,20 +335,6 @@ load_print_settings_from_key_file (PrintData *data,
"image-setup", "use-full-page", NULL);
}
#if 0
/* other settings */
if (g_key_file_has_key (key_file, "other-settings", "show-header", NULL))
{
data->show_info_header = g_key_file_get_boolean (key_file,
"other-settings",
"show-header", NULL);
}
else
#endif
{
data->show_info_header = FALSE;
}
gtk_print_operation_set_print_settings (operation, settings);
return TRUE;

View File

@ -26,6 +26,7 @@
#include "print.h"
#include "print-settings.h"
#include "print-page-layout.h"
#include "print-page-setup.h"
#include "print-draw-page.h"
#include "libgimp/stdplugins-intl.h"
@ -192,6 +193,8 @@ print_image (gint32 image_ID,
print_operation_set_name (operation, orig_image_ID);
print_page_setup_load (operation);
/* fill in the PrintData struct */
data.num_pages = 1;
data.image_id = orig_image_ID;
@ -263,11 +266,17 @@ print_image (gint32 image_ID,
static GimpPDBStatusType
page_setup (gint32 image_ID)
{
GtkPrintOperation *operation;
gimp_ui_init (PLUG_IN_BINARY, FALSE);
gimp_message ("Page Setup is not yet implemented");
operation = gtk_print_operation_new ();
print_page_setup_dialog (operation);
g_object_unref (operation);
return GIMP_PDB_EXECUTION_ERROR;
/* FIXME: notify the print procedure about the changed page setup */
return GIMP_PDB_SUCCESS;
}
static void

View File

@ -30,7 +30,6 @@ typedef struct
gint32 image_id;
gint32 drawable_id;
GimpUnit unit;
gboolean show_info_header;
gdouble xres;
gdouble yres;
GimpUnit image_unit;