2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2006-06-23 05:58:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2006-06-23 05:58:56 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-06-23 05:58:56 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2006-06-23 05:58:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
#include "print.h"
|
|
|
|
#include "print-settings.h"
|
|
|
|
#include "print-page-layout.h"
|
2008-02-05 00:59:45 +08:00
|
|
|
#include "print-page-setup.h"
|
2006-06-27 06:48:05 +08:00
|
|
|
#include "print-draw-page.h"
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-23 16:46:46 +08:00
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#define PLUG_IN_BINARY "print"
|
|
|
|
#define PLUG_IN_ROLE "gimp-print"
|
|
|
|
#define PRINT_PROC_NAME "file-print-gtk"
|
|
|
|
|
|
|
|
#ifndef EMBED_PAGE_SETUP
|
|
|
|
#define PAGE_SETUP_PROC_NAME "file-print-gtk-page-setup"
|
|
|
|
#define PRINT_TEMP_PROC_NAME "file-print-gtk-page-setup-notify-temp"
|
|
|
|
#endif
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
|
2014-04-16 17:15:35 +08:00
|
|
|
G_DEFINE_QUARK (gimp-plugin-print-error-quark, gimp_plugin_print_error)
|
2006-12-26 20:36:43 +08:00
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
typedef struct _Print Print;
|
|
|
|
typedef struct _PrintClass PrintClass;
|
|
|
|
|
|
|
|
struct _Print
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PrintClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define PRINT_TYPE (print_get_type ())
|
2023-10-19 00:29:37 +08:00
|
|
|
#define PRINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PRINT_TYPE, Print))
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
GType print_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * print_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * print_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * print_run (GimpProcedure *procedure,
|
2019-08-18 19:45:58 +08:00
|
|
|
GimpRunMode run_mode,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpImage *image,
|
2021-04-02 08:55:46 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2023-06-21 07:24:15 +08:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 01:41:52 +08:00
|
|
|
gpointer run_data);
|
|
|
|
|
2019-08-19 01:22:26 +08:00
|
|
|
static GimpPDBStatusType print_image (GimpImage *image,
|
2019-08-14 01:41:52 +08:00
|
|
|
gboolean interactive,
|
|
|
|
GError **error);
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-19 01:22:26 +08:00
|
|
|
static GimpPDBStatusType page_setup (GimpImage *image);
|
2012-08-07 22:02:43 +08:00
|
|
|
#endif
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
static void print_show_error (const gchar *message);
|
2007-07-24 15:22:35 +08:00
|
|
|
static void print_operation_set_name (GtkPrintOperation *operation,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpImage *image);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2007-07-24 15:22:35 +08:00
|
|
|
static void begin_print (GtkPrintOperation *operation,
|
|
|
|
GtkPrintContext *context,
|
|
|
|
PrintData *data);
|
|
|
|
static void end_print (GtkPrintOperation *operation,
|
|
|
|
GtkPrintContext *context,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpLayer **layer);
|
2007-07-24 15:22:35 +08:00
|
|
|
static void draw_page (GtkPrintOperation *print,
|
|
|
|
GtkPrintContext *context,
|
|
|
|
gint page_nr,
|
|
|
|
PrintData *data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2007-07-24 15:22:35 +08:00
|
|
|
static GtkWidget * create_custom_widget (GtkPrintOperation *operation,
|
|
|
|
PrintData *data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-19 01:22:26 +08:00
|
|
|
static gchar * print_temp_proc_name (GimpImage *image);
|
|
|
|
static gchar * print_temp_proc_install (GimpImage *image);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
/* Keep a reference to the current GtkPrintOperation
|
|
|
|
* for access by the temporary procedure.
|
|
|
|
*/
|
|
|
|
static GtkPrintOperation *print_operation = NULL;
|
|
|
|
#endif
|
|
|
|
|
2006-12-29 22:26:55 +08:00
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
G_DEFINE_TYPE (Print, print, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (PRINT_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_class_init (PrintClass *klass)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2019-08-14 01:41:52 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
plug_in_class->query_procedures = print_query_procedures;
|
|
|
|
plug_in_class->create_procedure = print_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-14 01:41:52 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-14 01:41:52 +08:00
|
|
|
print_init (Print *print)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2019-08-14 01:41:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
print_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
|
|
|
|
list = g_list_append (list, g_strdup (PRINT_PROC_NAME));
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-14 01:41:52 +08:00
|
|
|
list = g_list_append (list, g_strdup (PAGE_SETUP_PROC_NAME));
|
2012-08-07 22:02:43 +08:00
|
|
|
#endif
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
return list;
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
static GimpProcedure *
|
|
|
|
print_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, PRINT_PROC_NAME))
|
|
|
|
{
|
2023-10-02 00:23:57 +08:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
print_run, NULL, NULL);
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
2021-04-02 08:55:46 +08:00
|
|
|
gimp_procedure_set_sensitivity_mask (procedure,
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLE |
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_DRAWABLES |
|
|
|
|
GIMP_PROCEDURE_SENSITIVE_NO_DRAWABLES);
|
2019-08-14 01:41:52 +08:00
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("_Print..."));
|
2019-08-14 01:41:52 +08:00
|
|
|
gimp_procedure_set_icon_name (procedure, GIMP_ICON_DOCUMENT_PRINT);
|
2023-07-13 21:34:40 +08:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/File/[Send]");
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-05 04:50:53 +08:00
|
|
|
_("Print the image"),
|
2019-08-14 01:41:52 +08:00
|
|
|
"Print the image using the "
|
|
|
|
"GTK+ Print API.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Bill Skaggs, Sven Neumann, Stefan Röllin",
|
|
|
|
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",
|
|
|
|
"2006 - 2008");
|
|
|
|
|
|
|
|
}
|
|
|
|
#ifndef EMBED_PAGE_SETUP
|
|
|
|
else if (! strcmp (name, PAGE_SETUP_PROC_NAME))
|
|
|
|
{
|
2023-10-02 00:23:57 +08:00
|
|
|
procedure = gimp_image_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
print_run, NULL, NULL);
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Page Set_up..."));
|
2019-08-14 01:41:52 +08:00
|
|
|
gimp_procedure_set_icon_name (procedure, GIMP_ICON_DOCUMENT_PAGE_SETUP);
|
2023-07-13 21:34:40 +08:00
|
|
|
gimp_procedure_add_menu_path (procedure, "<Image>/File/[Send]");
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2022-07-05 04:50:53 +08:00
|
|
|
_("Adjust page size and orientation "
|
|
|
|
"for printing"),
|
2019-08-14 01:41:52 +08:00
|
|
|
"Adjust page size and orientation "
|
|
|
|
"for printing the image using the "
|
|
|
|
"GTK+ Print API.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Bill Skaggs, Sven Neumann, Stefan Röllin",
|
|
|
|
"Sven Neumann <sven@gimp.org>",
|
|
|
|
"2008");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
print_run (GimpProcedure *procedure,
|
2019-08-18 19:45:58 +08:00
|
|
|
GimpRunMode run_mode,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpImage *image,
|
2021-04-02 08:55:46 +08:00
|
|
|
gint n_drawables,
|
|
|
|
GimpDrawable **drawables,
|
2023-06-21 07:24:15 +08:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 01:41:52 +08:00
|
|
|
gpointer run_data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2019-08-14 01:41:52 +08:00
|
|
|
GimpPDBStatusType status;
|
2008-08-24 01:11:40 +08:00
|
|
|
GError *error = NULL;
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2012-09-22 05:33:01 +08:00
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
if (strcmp (gimp_procedure_get_name (procedure),
|
|
|
|
PRINT_PROC_NAME) == 0)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2019-08-19 01:22:26 +08:00
|
|
|
status = print_image (image, run_mode == GIMP_RUN_INTERACTIVE, &error);
|
2008-08-24 01:11:40 +08:00
|
|
|
|
|
|
|
if (error && run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
{
|
|
|
|
print_show_error (error->message);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-14 01:41:52 +08:00
|
|
|
else if (strcmp (gimp_procedure_get_name (procedure),
|
|
|
|
PAGE_SETUP_PROC_NAME) == 0)
|
2012-08-07 22:02:43 +08:00
|
|
|
{
|
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
{
|
2019-08-19 01:22:26 +08:00
|
|
|
status = page_setup (image);
|
2012-08-07 22:02:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-06-23 05:58:56 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2008-02-01 15:10:55 +08:00
|
|
|
static GimpPDBStatusType
|
2019-08-19 01:22:26 +08:00
|
|
|
print_image (GimpImage *image,
|
2008-08-24 01:11:40 +08:00
|
|
|
gboolean interactive,
|
|
|
|
GError **error)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2008-08-24 01:11:40 +08:00
|
|
|
GtkPrintOperation *operation;
|
|
|
|
GtkPrintOperationResult result;
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpLayer *layer;
|
2008-08-24 01:11:40 +08:00
|
|
|
PrintData data;
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
|
|
|
gchar *temp_proc;
|
|
|
|
#endif
|
2007-07-20 04:32:53 +08:00
|
|
|
|
2008-08-08 03:22:19 +08:00
|
|
|
/* create a print layer from the projection */
|
2019-08-19 01:22:26 +08:00
|
|
|
layer = gimp_layer_new_from_visible (image, image, PRINT_PROC_NAME);
|
2007-07-20 04:32:53 +08:00
|
|
|
|
2007-07-24 15:22:35 +08:00
|
|
|
operation = gtk_print_operation_new ();
|
|
|
|
|
2008-04-07 18:38:38 +08:00
|
|
|
gtk_print_operation_set_n_pages (operation, 1);
|
2019-08-19 01:22:26 +08:00
|
|
|
print_operation_set_name (operation, image);
|
2007-07-24 15:22:35 +08:00
|
|
|
|
2019-08-19 01:22:26 +08:00
|
|
|
print_page_setup_load (operation, image);
|
2008-02-05 00:59:45 +08:00
|
|
|
|
2007-07-24 15:05:06 +08:00
|
|
|
/* fill in the PrintData struct */
|
2019-08-19 01:22:26 +08:00
|
|
|
data.image = image;
|
|
|
|
data.drawable = GIMP_DRAWABLE (layer);
|
2008-12-31 05:36:04 +08:00
|
|
|
data.unit = gimp_get_default_unit ();
|
2019-08-19 01:22:26 +08:00
|
|
|
data.image_unit = gimp_image_get_unit (image);
|
2008-12-31 05:36:04 +08:00
|
|
|
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;
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2019-08-19 01:22:26 +08:00
|
|
|
gimp_image_get_resolution (image, &data.xres, &data.yres);
|
2006-12-26 20:36:43 +08:00
|
|
|
|
2008-02-26 02:59:04 +08:00
|
|
|
print_settings_load (&data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2008-10-22 23:01:34 +08:00
|
|
|
gtk_print_operation_set_unit (operation, GTK_UNIT_PIXEL);
|
2008-02-24 21:08:51 +08:00
|
|
|
|
2006-12-26 05:03:27 +08:00
|
|
|
g_signal_connect (operation, "begin-print",
|
|
|
|
G_CALLBACK (begin_print),
|
2007-07-24 05:17:47 +08:00
|
|
|
&data);
|
2006-12-26 05:03:27 +08:00
|
|
|
g_signal_connect (operation, "draw-page",
|
|
|
|
G_CALLBACK (draw_page),
|
2007-07-24 05:17:47 +08:00
|
|
|
&data);
|
2006-12-26 05:03:27 +08:00
|
|
|
g_signal_connect (operation, "end-print",
|
|
|
|
G_CALLBACK (end_print),
|
2012-02-12 20:51:18 +08:00
|
|
|
&layer);
|
2008-02-05 05:49:08 +08:00
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
|
|
|
print_operation = operation;
|
2019-08-19 01:22:26 +08:00
|
|
|
temp_proc = print_temp_proc_install (image);
|
2019-08-14 01:41:52 +08:00
|
|
|
gimp_plug_in_extension_enable (gimp_get_plug_in ());
|
2012-08-07 22:02:43 +08:00
|
|
|
#endif
|
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
if (interactive)
|
|
|
|
{
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
2008-02-01 15:10:55 +08:00
|
|
|
|
2007-07-25 18:48:25 +08:00
|
|
|
g_signal_connect_swapped (operation, "end-print",
|
2008-02-26 02:59:04 +08:00
|
|
|
G_CALLBACK (print_settings_save),
|
2007-07-25 18:48:25 +08:00
|
|
|
&data);
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
g_signal_connect (operation, "create-custom-widget",
|
2006-12-26 05:03:27 +08:00
|
|
|
G_CALLBACK (create_custom_widget),
|
2007-07-24 05:17:47 +08:00
|
|
|
&data);
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2007-08-09 05:48:31 +08:00
|
|
|
gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));
|
2006-06-27 06:48:05 +08:00
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifdef EMBED_PAGE_SETUP
|
2012-02-12 20:51:18 +08:00
|
|
|
gtk_print_operation_set_embed_page_setup (operation, TRUE);
|
2012-08-07 22:02:43 +08:00
|
|
|
#endif
|
2012-02-12 20:51:18 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
result = gtk_print_operation_run (operation,
|
|
|
|
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
|
|
|
NULL, error);
|
2012-02-12 20:51:18 +08:00
|
|
|
|
|
|
|
if (result == GTK_PRINT_OPERATION_RESULT_APPLY ||
|
|
|
|
result == GTK_PRINT_OPERATION_RESULT_IN_PROGRESS)
|
|
|
|
{
|
2019-08-19 01:22:26 +08:00
|
|
|
print_page_setup_save (operation, image);
|
2012-02-12 20:51:18 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
else
|
2006-12-26 05:03:27 +08:00
|
|
|
{
|
2008-08-24 01:11:40 +08:00
|
|
|
result = gtk_print_operation_run (operation,
|
|
|
|
GTK_PRINT_OPERATION_ACTION_PRINT,
|
|
|
|
NULL, error);
|
2006-12-26 05:03:27 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-14 01:41:52 +08:00
|
|
|
gimp_plug_in_remove_temp_procedure (gimp_get_plug_in (), temp_proc);
|
2012-08-07 22:02:43 +08:00
|
|
|
g_free (temp_proc);
|
|
|
|
print_operation = NULL;
|
|
|
|
#endif
|
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
g_object_unref (operation);
|
|
|
|
|
2019-08-19 01:22:26 +08:00
|
|
|
if (gimp_item_is_valid (GIMP_ITEM (layer)))
|
|
|
|
gimp_item_delete (GIMP_ITEM (layer));
|
2007-07-20 04:32:53 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
switch (result)
|
2007-07-26 05:26:36 +08:00
|
|
|
{
|
2008-08-24 01:11:40 +08:00
|
|
|
case GTK_PRINT_OPERATION_RESULT_APPLY:
|
|
|
|
case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
|
|
|
|
return GIMP_PDB_SUCCESS;
|
|
|
|
|
|
|
|
case GTK_PRINT_OPERATION_RESULT_CANCEL:
|
|
|
|
return GIMP_PDB_CANCEL;
|
|
|
|
|
|
|
|
case GTK_PRINT_OPERATION_RESULT_ERROR:
|
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2007-07-26 05:26:36 +08:00
|
|
|
}
|
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
2008-02-01 15:10:55 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 22:02:43 +08:00
|
|
|
#ifndef EMBED_PAGE_SETUP
|
|
|
|
static GimpPDBStatusType
|
2019-08-19 01:22:26 +08:00
|
|
|
page_setup (GimpImage *image)
|
2012-08-07 22:02:43 +08:00
|
|
|
{
|
libgimp, plug-ins: move gimp_pdb_run_procedure*() to gimp_procedure_run*().
The gimp_procedure_run() already existed, though it was with an ordered
GimpValueArray array of arguments. Its usage feels redundant to the series of
gimp_pdb_run_procedure*() functions (which is confusing), but
gimp_procedure_run() was actually a bit more generic, because it does not
necessarily calls GimpProcedure-s through the PDB! For instance, it can runs a
local GimpProcedure, such as the case of one procedure which would want to call
another procedure in the same plug-in, but without having to go through PDB. Of
course, for local code, you may as well run relevant functions directly, yet it
makes sense that if one of the redundant-looking function is removed, it should
be the more specific one. Also gimp_procedure_run() feels a lot simpler and
logical, API wise.
A main difference in usage is that now, plug-in developers have to first
explicitly look up the GimpPdbProcedure with gimp_pdb_lookup_procedure() when
they wish to call PDB procedures on the wire. This was done anyway in the
gimp_pdb_run_procedure*() code, now it's explicit (rather than calling by name
directly).
Concretely:
* gimp_pdb_run_procedure(), gimp_pdb_run_procedure_config() and
gimp_pdb_run_procedure_valist() are removed.
* gimp_procedure_run() API is modified to use a variable args list instead of a
GimpValueArray.
* gimp_procedure_run_config() and gimp_procedure_run_valist() are added.
* gimp_procedure_run_config() in particular will be the one used in bindings
which don't have variable args support through a (rename-to
gimp_procedure_run) annotation.
2023-10-18 23:11:20 +08:00
|
|
|
GtkPrintOperation *operation;
|
|
|
|
GimpProcedure *procedure;
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
gchar *name;
|
2012-08-07 22:02:43 +08:00
|
|
|
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
operation = gtk_print_operation_new ();
|
|
|
|
|
2019-08-19 01:22:26 +08:00
|
|
|
print_page_setup_load (operation, image);
|
2012-08-07 22:02:43 +08:00
|
|
|
print_page_setup_dialog (operation);
|
2019-08-19 01:22:26 +08:00
|
|
|
print_page_setup_save (operation, image);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
g_object_unref (operation);
|
|
|
|
|
|
|
|
/* now notify a running print procedure about this change */
|
2019-08-19 01:22:26 +08:00
|
|
|
name = print_temp_proc_name (image);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
/* we don't want the core to show an error message if the
|
|
|
|
* temporary procedure does not exist
|
|
|
|
*/
|
2019-08-14 01:41:52 +08:00
|
|
|
gimp_plug_in_set_pdb_error_handler (gimp_get_plug_in (),
|
|
|
|
GIMP_PDB_ERROR_HANDLER_PLUGIN);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
2024-04-19 00:42:30 +08:00
|
|
|
/* Notify the Print plug-in if Page Setup was called from there */
|
libgimp, plug-ins: move gimp_pdb_run_procedure*() to gimp_procedure_run*().
The gimp_procedure_run() already existed, though it was with an ordered
GimpValueArray array of arguments. Its usage feels redundant to the series of
gimp_pdb_run_procedure*() functions (which is confusing), but
gimp_procedure_run() was actually a bit more generic, because it does not
necessarily calls GimpProcedure-s through the PDB! For instance, it can runs a
local GimpProcedure, such as the case of one procedure which would want to call
another procedure in the same plug-in, but without having to go through PDB. Of
course, for local code, you may as well run relevant functions directly, yet it
makes sense that if one of the redundant-looking function is removed, it should
be the more specific one. Also gimp_procedure_run() feels a lot simpler and
logical, API wise.
A main difference in usage is that now, plug-in developers have to first
explicitly look up the GimpPdbProcedure with gimp_pdb_lookup_procedure() when
they wish to call PDB procedures on the wire. This was done anyway in the
gimp_pdb_run_procedure*() code, now it's explicit (rather than calling by name
directly).
Concretely:
* gimp_pdb_run_procedure(), gimp_pdb_run_procedure_config() and
gimp_pdb_run_procedure_valist() are removed.
* gimp_procedure_run() API is modified to use a variable args list instead of a
GimpValueArray.
* gimp_procedure_run_config() and gimp_procedure_run_valist() are added.
* gimp_procedure_run_config() in particular will be the one used in bindings
which don't have variable args support through a (rename-to
gimp_procedure_run) annotation.
2023-10-18 23:11:20 +08:00
|
|
|
procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (), name);
|
2024-04-19 00:42:30 +08:00
|
|
|
if (procedure)
|
|
|
|
{
|
|
|
|
return_vals = gimp_procedure_run (procedure, "image", image, NULL);
|
|
|
|
gimp_value_array_unref (return_vals);
|
|
|
|
}
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
return GIMP_PDB_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-26 05:26:36 +08:00
|
|
|
static void
|
2008-08-24 01:11:40 +08:00
|
|
|
print_show_error (const gchar *message)
|
2007-07-26 05:26:36 +08:00
|
|
|
{
|
2008-08-24 01:11:40 +08:00
|
|
|
GtkWidget *dialog;
|
2007-07-27 00:22:17 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
dialog = gtk_message_dialog_new (NULL, 0,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK,
|
2014-04-17 04:36:23 +08:00
|
|
|
"%s",
|
2008-08-24 01:11:40 +08:00
|
|
|
_("An error occurred while trying to print:"));
|
2006-12-30 22:08:33 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
2008-11-04 22:05:24 +08:00
|
|
|
"%s", message);
|
2006-12-30 22:08:33 +08:00
|
|
|
|
2008-08-24 01:11:40 +08:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2007-07-24 15:22:35 +08:00
|
|
|
static void
|
|
|
|
print_operation_set_name (GtkPrintOperation *operation,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpImage *image)
|
2007-07-24 15:22:35 +08:00
|
|
|
{
|
2019-08-19 01:22:26 +08:00
|
|
|
gchar *name = gimp_image_get_name (image);
|
2007-07-24 15:22:35 +08:00
|
|
|
|
2007-07-26 03:50:28 +08:00
|
|
|
gtk_print_operation_set_job_name (operation, name);
|
2007-07-24 15:22:35 +08:00
|
|
|
|
2007-07-24 16:56:09 +08:00
|
|
|
g_free (name);
|
2007-07-24 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
2006-06-23 05:58:56 +08:00
|
|
|
static void
|
|
|
|
begin_print (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2007-07-20 04:32:53 +08:00
|
|
|
gtk_print_operation_set_use_full_page (operation, data->use_full_page);
|
2006-12-27 21:46:27 +08:00
|
|
|
|
|
|
|
gimp_progress_init (_("Printing"));
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
end_print (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
2019-08-19 01:22:26 +08:00
|
|
|
GimpLayer **layer)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2008-08-08 03:22:19 +08:00
|
|
|
/* we don't need the print layer any longer, delete it */
|
2019-08-19 01:22:26 +08:00
|
|
|
if (gimp_item_is_valid (GIMP_ITEM (*layer)))
|
2007-07-25 15:36:15 +08:00
|
|
|
{
|
2019-08-19 01:22:26 +08:00
|
|
|
gimp_item_delete (GIMP_ITEM (*layer));
|
|
|
|
*layer = NULL;
|
2007-07-25 15:36:15 +08:00
|
|
|
}
|
2006-12-29 23:36:54 +08:00
|
|
|
|
2007-07-25 18:48:25 +08:00
|
|
|
gimp_progress_end ();
|
2007-08-16 02:19:52 +08:00
|
|
|
|
|
|
|
/* generate events to solve the problems described in bug #466928 */
|
2008-02-25 23:06:03 +08:00
|
|
|
g_timeout_add_seconds (1, (GSourceFunc) gtk_true, NULL);
|
2006-12-29 22:26:55 +08:00
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
draw_page (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
GtkPrintContext *context,
|
2007-07-24 15:05:06 +08:00
|
|
|
gint page_nr,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2014-04-16 17:15:35 +08:00
|
|
|
GError *error = NULL;
|
2008-02-22 18:03:01 +08:00
|
|
|
|
2014-04-16 17:15:35 +08:00
|
|
|
if (print_draw_page (context, data, &error))
|
|
|
|
{
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_show_error (error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
|
|
|
|
2014-04-16 17:15:35 +08:00
|
|
|
|
2006-06-27 06:48:05 +08:00
|
|
|
/*
|
|
|
|
* This callback creates a "custom" widget that gets inserted into the
|
|
|
|
* print operation dialog.
|
|
|
|
*/
|
|
|
|
static GtkWidget *
|
|
|
|
create_custom_widget (GtkPrintOperation *operation,
|
2006-12-26 05:03:27 +08:00
|
|
|
PrintData *data)
|
2006-06-23 05:58:56 +08:00
|
|
|
{
|
2008-02-27 04:06:30 +08:00
|
|
|
return print_page_layout_gui (data, PRINT_PROC_NAME);
|
2006-06-23 05:58:56 +08:00
|
|
|
}
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
#ifndef EMBED_PAGE_SETUP
|
2019-08-14 01:41:52 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
print_temp_proc_run (GimpProcedure *procedure,
|
2023-06-15 22:53:54 +08:00
|
|
|
GimpProcedureConfig *config,
|
2019-08-14 01:41:52 +08:00
|
|
|
gpointer run_data)
|
2012-08-07 22:02:43 +08:00
|
|
|
{
|
2023-06-15 22:53:54 +08:00
|
|
|
GimpImage *image;
|
|
|
|
|
|
|
|
g_object_get (config, "image", &image, NULL);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
if (print_operation)
|
2019-08-19 01:22:26 +08:00
|
|
|
print_page_setup_load (print_operation, image);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
2023-06-15 22:53:54 +08:00
|
|
|
g_object_unref (image);
|
|
|
|
|
2019-08-14 01:41:52 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
2012-08-07 22:02:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2019-08-19 01:22:26 +08:00
|
|
|
print_temp_proc_name (GimpImage *image)
|
2012-08-07 22:02:43 +08:00
|
|
|
{
|
2023-04-30 21:53:16 +08:00
|
|
|
return g_strdup_printf (PRINT_TEMP_PROC_NAME "-%d",
|
|
|
|
gimp_image_get_id (image));
|
2012-08-07 22:02:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2019-08-19 01:22:26 +08:00
|
|
|
print_temp_proc_install (GimpImage *image)
|
2012-08-07 22:02:43 +08:00
|
|
|
{
|
2019-08-14 01:41:52 +08:00
|
|
|
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
2019-08-19 01:22:26 +08:00
|
|
|
gchar *name = print_temp_proc_name (image);
|
2019-08-14 01:41:52 +08:00
|
|
|
GimpProcedure *procedure;
|
|
|
|
|
2023-06-17 00:34:53 +08:00
|
|
|
procedure = gimp_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_TEMPORARY,
|
|
|
|
print_temp_proc_run, NULL, NULL);
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"DON'T USE THIS ONE",
|
|
|
|
"Temporary procedure to notify the "
|
|
|
|
"Print plug-in about changes to the "
|
|
|
|
"Page Setup.",
|
|
|
|
NULL);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Sven Neumann",
|
|
|
|
"Sven Neumann",
|
|
|
|
"2008");
|
|
|
|
|
2024-06-13 00:53:12 +08:00
|
|
|
gimp_procedure_add_image_argument (procedure, "image",
|
|
|
|
"Image",
|
|
|
|
"The image to notify about",
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-14 01:41:52 +08:00
|
|
|
|
|
|
|
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
|
|
|
g_object_unref (procedure);
|
2012-08-07 22:02:43 +08:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
#endif
|