2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-07-16 06:54:59 +08:00
|
|
|
*
|
2010-08-28 00:43:00 +08:00
|
|
|
* file-pdf-load.c - PDF file loader
|
2005-07-18 18:16:45 +08:00
|
|
|
*
|
2005-07-16 06:54:59 +08:00
|
|
|
* Copyright (C) 2005 Nathan Summers
|
|
|
|
*
|
2011-04-21 16:27:13 +08:00
|
|
|
* Some code in render_page_to_surface() borrowed from
|
|
|
|
* poppler.git/glib/poppler-page.cc.
|
2011-04-20 21:25:44 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-07-16 06:54:59 +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
|
2005-07-16 06:54:59 +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/>.
|
2005-07-16 06:54:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
2008-05-24 04:38:52 +08:00
|
|
|
#undef GTK_DISABLE_SINGLE_INCLUDES
|
2005-07-16 06:54:59 +08:00
|
|
|
#include <poppler.h>
|
2008-05-24 04:38:52 +08:00
|
|
|
#define GTK_DISABLE_SINGLE_INCLUDES
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
|
|
|
|
2005-07-19 00:52:03 +08:00
|
|
|
|
2007-05-04 06:13:48 +08:00
|
|
|
/**
|
|
|
|
** the following was formerly part of
|
|
|
|
** gimpresolutionentry.h and gimpresolutionentry.c,
|
|
|
|
** moved here because this is the only thing that uses
|
|
|
|
** it, and it is undesirable to maintain all that api.
|
|
|
|
** Most unused functions have been removed.
|
|
|
|
**/
|
|
|
|
#define GIMP_TYPE_RESOLUTION_ENTRY (gimp_resolution_entry_get_type ())
|
|
|
|
#define GIMP_RESOLUTION_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_RESOLUTION_ENTRY, GimpResolutionEntry))
|
|
|
|
#define GIMP_RESOLUTION_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_RESOLUTION_ENTRY, GimpResolutionEntryClass))
|
|
|
|
#define GIMP_IS_RESOLUTION_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GIMP_TYPE_RESOLUTION_ENTRY))
|
|
|
|
#define GIMP_IS_RESOLUTION_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_RESOLUTION_ENTRY))
|
|
|
|
#define GIMP_RESOLUTION_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_RESOLUTION_ENTRY, GimpResolutionEntryClass))
|
|
|
|
|
|
|
|
|
2007-08-07 17:44:23 +08:00
|
|
|
typedef struct _GimpResolutionEntry GimpResolutionEntry;
|
2007-05-04 06:13:48 +08:00
|
|
|
typedef struct _GimpResolutionEntryClass GimpResolutionEntryClass;
|
|
|
|
|
|
|
|
typedef struct _GimpResolutionEntryField GimpResolutionEntryField;
|
|
|
|
|
|
|
|
struct _GimpResolutionEntryField
|
|
|
|
{
|
|
|
|
GimpResolutionEntry *gre;
|
|
|
|
GimpResolutionEntryField *corresponding;
|
|
|
|
|
|
|
|
gboolean size;
|
|
|
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
guint changed_signal;
|
|
|
|
|
2014-06-23 05:01:31 +08:00
|
|
|
GtkAdjustment *adjustment;
|
2007-05-04 06:13:48 +08:00
|
|
|
GtkWidget *spinbutton;
|
|
|
|
|
|
|
|
gdouble phy_size;
|
|
|
|
|
|
|
|
gdouble value;
|
|
|
|
gdouble min_value;
|
|
|
|
gdouble max_value;
|
|
|
|
|
|
|
|
gint stop_recursion;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct _GimpResolutionEntry
|
|
|
|
{
|
2018-05-11 17:52:08 +08:00
|
|
|
GtkGrid parent_instance;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
GimpUnit size_unit;
|
|
|
|
GimpUnit unit;
|
|
|
|
|
|
|
|
GtkWidget *unitmenu;
|
|
|
|
GtkWidget *chainbutton;
|
|
|
|
|
|
|
|
GimpResolutionEntryField width;
|
|
|
|
GimpResolutionEntryField height;
|
|
|
|
GimpResolutionEntryField x;
|
|
|
|
GimpResolutionEntryField y;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GimpResolutionEntryClass
|
|
|
|
{
|
2018-05-11 17:52:08 +08:00
|
|
|
GtkGridClass parent_class;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
void (* value_changed) (GimpResolutionEntry *gse);
|
|
|
|
void (* refval_changed) (GimpResolutionEntry *gse);
|
|
|
|
void (* unit_changed) (GimpResolutionEntry *gse);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GType gimp_resolution_entry_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
GtkWidget * gimp_resolution_entry_new (const gchar *width_label,
|
|
|
|
gdouble width,
|
|
|
|
const gchar *height_label,
|
|
|
|
gdouble height,
|
|
|
|
GimpUnit size_unit,
|
2007-05-04 15:16:05 +08:00
|
|
|
const gchar *res_label,
|
|
|
|
gdouble initial_res,
|
|
|
|
GimpUnit initial_unit);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
GtkWidget * gimp_resolution_entry_attach_label (GimpResolutionEntry *gre,
|
|
|
|
const gchar *text,
|
|
|
|
gint row,
|
|
|
|
gint column,
|
|
|
|
gfloat alignment);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
gdouble gimp_resolution_entry_get_x_in_dpi (GimpResolutionEntry *gre);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
gdouble gimp_resolution_entry_get_y_in_dpi (GimpResolutionEntry *gre);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* signal callback convenience functions */
|
|
|
|
void gimp_resolution_entry_update_x_in_dpi (GimpResolutionEntry *gre,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
void gimp_resolution_entry_update_y_in_dpi (GimpResolutionEntry *gre,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
WIDTH_CHANGED,
|
|
|
|
HEIGHT_CHANGED,
|
|
|
|
X_CHANGED,
|
|
|
|
Y_CHANGED,
|
|
|
|
UNIT_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gimp_resolution_entry_class_init (GimpResolutionEntryClass *class);
|
|
|
|
static void gimp_resolution_entry_init (GimpResolutionEntry *gre);
|
|
|
|
|
|
|
|
static void gimp_resolution_entry_update_value (GimpResolutionEntryField *gref,
|
|
|
|
gdouble value);
|
2018-06-25 00:15:16 +08:00
|
|
|
static void gimp_resolution_entry_value_callback (GtkAdjustment *adjustment,
|
2007-05-04 06:13:48 +08:00
|
|
|
gpointer data);
|
|
|
|
static void gimp_resolution_entry_update_unit (GimpResolutionEntry *gre,
|
|
|
|
GimpUnit unit);
|
|
|
|
static void gimp_resolution_entry_unit_callback (GtkWidget *widget,
|
|
|
|
GimpResolutionEntry *gre);
|
|
|
|
|
|
|
|
static void gimp_resolution_entry_field_init (GimpResolutionEntry *gre,
|
|
|
|
GimpResolutionEntryField *gref,
|
|
|
|
GimpResolutionEntryField *corresponding,
|
|
|
|
guint changed_signal,
|
|
|
|
gdouble initial_val,
|
|
|
|
GimpUnit initial_unit,
|
|
|
|
gboolean size,
|
|
|
|
gint spinbutton_width);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
static void gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
|
|
|
|
GtkWidget *label,
|
|
|
|
gdouble size);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
** end of gimpresolutionentry stuff
|
|
|
|
** the actual code can be found at the end of this file
|
|
|
|
**/
|
2019-08-20 08:32:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define LOAD_PROC "file-pdf-load"
|
|
|
|
#define LOAD_THUMB_PROC "file-pdf-load-thumb"
|
|
|
|
#define PLUG_IN_BINARY "file-pdf-load"
|
|
|
|
#define PLUG_IN_ROLE "gimp-file-pdf-load"
|
|
|
|
|
|
|
|
#define THUMBNAIL_SIZE 128
|
|
|
|
|
|
|
|
#define GIMP_PLUGIN_PDF_LOAD_ERROR gimp_plugin_pdf_load_error_quark ()
|
|
|
|
static GQuark
|
|
|
|
gimp_plugin_pdf_load_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gimp-plugin-pdf-load-error-quark");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Structs for the load dialog */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpPageSelectorTarget target;
|
|
|
|
gdouble resolution;
|
|
|
|
gboolean antialias;
|
|
|
|
gchar *PDF_password;
|
|
|
|
} PdfLoadVals;
|
|
|
|
|
|
|
|
static PdfLoadVals loadvals =
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
GIMP_PAGE_SELECTOR_TARGET_LAYERS,
|
|
|
|
100.00, /* 100 dpi */
|
|
|
|
TRUE,
|
|
|
|
NULL
|
2005-07-16 06:54:59 +08:00
|
|
|
};
|
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint n_pages;
|
|
|
|
gint *pages;
|
|
|
|
} PdfSelectedPages;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _Pdf Pdf;
|
|
|
|
typedef struct _PdfClass PdfClass;
|
|
|
|
|
|
|
|
struct _Pdf
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PdfClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define PDF_TYPE (pdf_get_type ())
|
|
|
|
#define PDF (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PDF_TYPE, Pdf))
|
|
|
|
|
|
|
|
GType pdf_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * pdf_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * pdf_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * pdf_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
static GimpValueArray * pdf_load_thumb (GimpProcedure *procedure,
|
|
|
|
GFile *file,
|
|
|
|
gint size,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data);
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
static GimpImage * load_image (PopplerDocument *doc,
|
2019-08-20 08:32:15 +08:00
|
|
|
const gchar *filename,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpPageSelectorTarget target,
|
|
|
|
guint32 resolution,
|
|
|
|
gboolean antialias,
|
|
|
|
PdfSelectedPages *pages);
|
|
|
|
|
|
|
|
static GimpPDBStatusType load_dialog (PopplerDocument *doc,
|
|
|
|
PdfSelectedPages *pages);
|
|
|
|
|
|
|
|
static PopplerDocument * open_document (const gchar *filename,
|
|
|
|
const gchar *PDF_password,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **error);
|
|
|
|
|
|
|
|
static cairo_surface_t * get_thumb_surface (PopplerDocument *doc,
|
|
|
|
gint page,
|
|
|
|
gint preferred_size);
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
static GdkPixbuf * get_thumb_pixbuf (PopplerDocument *doc,
|
2019-08-20 08:32:15 +08:00
|
|
|
gint page,
|
|
|
|
gint preferred_size);
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
static GimpLayer * layer_from_surface (GimpImage *image,
|
2019-08-20 08:32:15 +08:00
|
|
|
const gchar *layer_name,
|
|
|
|
gint position,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
gdouble progress_start,
|
|
|
|
gdouble progress_scale);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Pdf, pdf, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (PDF_TYPE)
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2019-08-20 08:32:15 +08:00
|
|
|
pdf_class_init (PdfClass *klass)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = pdf_query_procedures;
|
|
|
|
plug_in_class->create_procedure = pdf_create_procedure;
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-20 08:32:15 +08:00
|
|
|
pdf_init (Pdf *pdf)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
pdf_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
|
|
|
|
|
|
|
list = g_list_append (list, g_strdup (LOAD_PROC));
|
|
|
|
list = g_list_append (list, g_strdup (LOAD_THUMB_PROC));
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProcedure *
|
|
|
|
pdf_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
|
|
|
if (! strcmp (name, LOAD_PROC))
|
|
|
|
{
|
|
|
|
procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
|
|
|
|
pdf_load, NULL, NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_menu_label (procedure, N_("Portable Document Format"));
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Load file in PDF format",
|
|
|
|
"Loads files in Adobe's Portable "
|
|
|
|
"Document Format. PDF is designed to "
|
|
|
|
"be easily processed by a variety "
|
|
|
|
"of different platforms, and is a "
|
|
|
|
"distant cousin of PostScript.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Nathan Summers, Lionel N.",
|
|
|
|
"Nathan Summers, Lionel N.",
|
|
|
|
"2005, 2017");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"application/pdf");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"pdf");
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"0, string,%PDF-");
|
|
|
|
|
|
|
|
gimp_load_procedure_set_thumbnail_loader (GIMP_LOAD_PROCEDURE (procedure),
|
|
|
|
LOAD_THUMB_PROC);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "pdf-password",
|
|
|
|
"PDF password",
|
|
|
|
"The password to decrypt the encrypted PDF file",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_INT (procedure, "n-pages",
|
|
|
|
"N pages",
|
|
|
|
"Number of pages to load (0 for all)",
|
|
|
|
0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_INT32_ARRAY (procedure, "pages",
|
|
|
|
"Pages",
|
|
|
|
"The pages to load in the expected order",
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
}
|
|
|
|
else if (! strcmp (name, LOAD_THUMB_PROC))
|
|
|
|
{
|
|
|
|
procedure = gimp_thumbnail_procedure_new (plug_in, name, GIMP_PLUGIN,
|
|
|
|
pdf_load_thumb, NULL, NULL);
|
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
|
|
|
"Loads a preview from a PDF file.",
|
|
|
|
"Loads a small preview of the first "
|
|
|
|
"page of the PDF format file. Uses "
|
|
|
|
"the embedded thumbnail if present.",
|
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Nathan Summers",
|
|
|
|
"Nathan Summers",
|
|
|
|
"2005");
|
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
|
|
|
pdf_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GimpImage *image = NULL;
|
|
|
|
PopplerDocument *doc = NULL;
|
|
|
|
PdfSelectedPages pages = { 0, NULL };
|
|
|
|
GError *error = NULL;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
INIT_I18N ();
|
2019-07-22 20:56:04 +08:00
|
|
|
gegl_init (NULL, NULL);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
gimp_get_data (LOAD_PROC, &loadvals);
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
|
|
|
doc = open_document (g_file_get_path (file),
|
|
|
|
loadvals.PDF_password,
|
|
|
|
run_mode, &error);
|
|
|
|
|
|
|
|
if (! doc)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
status = load_dialog (doc, &pages);
|
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
gimp_set_data (LOAD_PROC, &loadvals, sizeof(loadvals));
|
|
|
|
}
|
|
|
|
break;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
/* FIXME: implement last vals mode */
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
break;
|
2019-08-19 18:05:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
doc = open_document (g_file_get_path (file),
|
|
|
|
GIMP_VALUES_GET_STRING (args, 0),
|
|
|
|
run_mode, &error);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (doc)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
PopplerPage *test_page = poppler_document_get_page (doc, 0);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (test_page)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
gint i;
|
|
|
|
gint doc_n_pages;
|
|
|
|
|
|
|
|
doc_n_pages = poppler_document_get_n_pages (doc);
|
|
|
|
/* The number of imported pages may be bigger than
|
|
|
|
* the number of pages from the original document.
|
|
|
|
* Indeed it is possible to duplicate some pages
|
|
|
|
* by setting the same number several times in the
|
|
|
|
* "pages" argument.
|
|
|
|
* Not ceiling this value is *not* an error.
|
|
|
|
*/
|
|
|
|
pages.n_pages = GIMP_VALUES_GET_INT (args, 1);
|
|
|
|
if (pages.n_pages <= 0)
|
2017-09-11 03:55:41 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
pages.n_pages = doc_n_pages;
|
|
|
|
pages.pages = g_new (gint, pages.n_pages);
|
|
|
|
for (i = 0; i < pages.n_pages; i++)
|
|
|
|
pages.pages[i] = i;
|
2017-09-11 03:55:41 +08:00
|
|
|
}
|
2019-08-20 08:32:15 +08:00
|
|
|
else
|
2017-09-11 03:55:41 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
const gint32 *p = GIMP_VALUES_GET_INT32_ARRAY (args, 2);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
pages.pages = g_new (gint, pages.n_pages);
|
2007-10-07 05:34:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
for (i = 0; i < pages.n_pages; i++)
|
2017-09-25 09:22:50 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
if (p[i] >= doc_n_pages)
|
2017-09-25 09:22:50 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
g_set_error (&error, GIMP_PLUGIN_PDF_LOAD_ERROR, 0,
|
|
|
|
/* TRANSLATORS: first argument is file name,
|
|
|
|
* second is out-of-range page number,
|
|
|
|
* third is number of pages.
|
|
|
|
* Specify order as in English if needed.
|
|
|
|
*/
|
|
|
|
ngettext ("PDF document '%1$s' has %3$d page. Page %2$d is out of range.",
|
|
|
|
"PDF document '%1$s' has %3$d pages. Page %2$d is out of range.",
|
|
|
|
doc_n_pages),
|
|
|
|
gimp_file_get_utf8_name (file),
|
|
|
|
p[i],
|
|
|
|
doc_n_pages);
|
|
|
|
break;
|
2017-09-25 09:22:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
pages.pages[i] = p[i];
|
2017-09-25 09:22:50 +08:00
|
|
|
}
|
|
|
|
}
|
2007-10-07 05:34:12 +08:00
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
g_object_unref (test_page);
|
2005-07-21 03:39:46 +08:00
|
|
|
}
|
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
else
|
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
g_object_unref (doc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
image = load_image (doc,
|
|
|
|
g_file_get_path (file),
|
|
|
|
run_mode,
|
|
|
|
loadvals.target,
|
|
|
|
loadvals.resolution,
|
|
|
|
loadvals.antialias,
|
|
|
|
&pages);
|
2019-08-20 08:32:15 +08:00
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (doc)
|
|
|
|
g_object_unref (doc);
|
2007-04-27 18:12:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
g_free (pages.pages);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
if (! image)
|
2019-08-20 08:32:15 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
2008-11-11 07:15:40 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
2008-11-11 07:15:40 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
return return_vals;
|
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
static GimpValueArray *
|
|
|
|
pdf_load_thumb (GimpProcedure *procedure,
|
|
|
|
GFile *file,
|
|
|
|
gint size,
|
|
|
|
const GimpValueArray *args,
|
|
|
|
gpointer run_data)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
gdouble width = 0;
|
|
|
|
gdouble height = 0;
|
|
|
|
gdouble scale;
|
2019-08-23 05:22:48 +08:00
|
|
|
GimpImage *image = NULL;
|
2019-08-20 08:32:15 +08:00
|
|
|
gint num_pages = 0;
|
|
|
|
PopplerDocument *doc = NULL;
|
|
|
|
cairo_surface_t *surface = NULL;
|
|
|
|
GError *error = NULL;
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
gegl_init (NULL, NULL);
|
2007-04-27 18:12:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
doc = open_document (g_file_get_path (file),
|
|
|
|
NULL,
|
|
|
|
GIMP_RUN_NONINTERACTIVE,
|
|
|
|
&error);
|
2019-07-22 18:07:04 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (doc)
|
|
|
|
{
|
|
|
|
PopplerPage *page = poppler_document_get_page (doc, 0);
|
2007-04-27 18:12:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (page)
|
|
|
|
{
|
|
|
|
poppler_page_get_size (page, &width, &height);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
g_object_unref (page);
|
|
|
|
}
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
num_pages = poppler_document_get_n_pages (doc);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
surface = get_thumb_surface (doc, 0, size);
|
2007-04-27 18:12:12 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
g_object_unref (doc);
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
if (surface)
|
2008-08-18 05:39:44 +08:00
|
|
|
{
|
2019-08-20 08:32:15 +08:00
|
|
|
image = gimp_image_new (cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface),
|
|
|
|
GIMP_RGB);
|
|
|
|
|
|
|
|
gimp_image_undo_disable (image);
|
|
|
|
|
|
|
|
layer_from_surface (image, "thumbnail", 0, surface, 0.0, 1.0);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
gimp_image_clean_all (image);
|
2008-08-18 05:39:44 +08:00
|
|
|
}
|
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
scale = loadvals.resolution / gimp_unit_get_factor (GIMP_UNIT_POINT);
|
|
|
|
|
|
|
|
width *= scale;
|
|
|
|
height *= scale;
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
if (! image)
|
2019-08-20 08:32:15 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
|
|
|
GIMP_VALUES_SET_INT (return_vals, 2, width);
|
|
|
|
GIMP_VALUES_SET_INT (return_vals, 3, height);
|
|
|
|
GIMP_VALUES_SET_ENUM (return_vals, 4, GIMP_RGB_IMAGE);
|
|
|
|
GIMP_VALUES_SET_INT (return_vals, 5, num_pages);
|
2019-07-22 20:56:04 +08:00
|
|
|
|
2019-08-20 08:32:15 +08:00
|
|
|
return return_vals;
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static PopplerDocument*
|
2008-08-18 05:39:44 +08:00
|
|
|
open_document (const gchar *filename,
|
2017-09-11 03:55:41 +08:00
|
|
|
const gchar *PDF_password,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GError **load_error)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
|
|
|
PopplerDocument *doc;
|
2019-01-03 05:51:31 +08:00
|
|
|
GFile *file;
|
2008-08-18 05:39:44 +08:00
|
|
|
GError *error = NULL;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-01-03 05:51:31 +08:00
|
|
|
file = g_file_new_for_path (filename);
|
|
|
|
doc = poppler_document_new_from_gfile (file, PDF_password, NULL, &error);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2017-09-11 02:34:45 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2017-08-31 23:45:01 +08:00
|
|
|
{
|
2017-09-11 03:55:41 +08:00
|
|
|
GtkWidget *label;
|
|
|
|
|
2017-09-11 02:34:45 +08:00
|
|
|
label = gtk_label_new (_("PDF is password protected, please input the password:"));
|
2017-09-11 04:53:47 +08:00
|
|
|
while (error &&
|
|
|
|
error->domain == POPPLER_ERROR &&
|
|
|
|
error->code == POPPLER_ERROR_ENCRYPTED)
|
2017-08-31 23:45:01 +08:00
|
|
|
{
|
2017-09-11 02:34:45 +08:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *entry;
|
|
|
|
gint run;
|
|
|
|
|
|
|
|
dialog = gimp_dialog_new (_("Encrypted PDF"), PLUG_IN_ROLE,
|
|
|
|
NULL, 0,
|
|
|
|
NULL, NULL,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_OK"), GTK_RESPONSE_OK,
|
|
|
|
NULL);
|
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
vbox, TRUE, TRUE, 0);
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
|
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), entry);
|
|
|
|
|
|
|
|
gtk_widget_show_all (dialog);
|
|
|
|
|
|
|
|
run = gimp_dialog_run (GIMP_DIALOG (dialog));
|
|
|
|
if (run == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
g_clear_error (&error);
|
2019-01-03 05:51:31 +08:00
|
|
|
doc = poppler_document_new_from_gfile (file,
|
|
|
|
gtk_entry_get_text (GTK_ENTRY (entry)),
|
|
|
|
NULL, &error);
|
2017-09-11 02:34:45 +08:00
|
|
|
}
|
|
|
|
label = gtk_label_new (_("Wrong password! Please input the right one:"));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
if (run == GTK_RESPONSE_CANCEL || run == GTK_RESPONSE_DELETE_EVENT)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-08-31 23:45:01 +08:00
|
|
|
}
|
2017-09-11 02:34:45 +08:00
|
|
|
gtk_widget_destroy (label);
|
2017-08-31 23:45:01 +08:00
|
|
|
}
|
2019-01-03 05:51:31 +08:00
|
|
|
g_object_unref (file);
|
2017-08-31 23:45:01 +08:00
|
|
|
|
2010-05-16 17:00:53 +08:00
|
|
|
/* We can't g_mapped_file_unref(mapped_file) as apparently doc has
|
|
|
|
* references to data in there. No big deal, this is just a
|
|
|
|
* short-lived plug-in.
|
|
|
|
*/
|
2008-08-18 05:39:44 +08:00
|
|
|
if (! doc)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2008-08-18 05:39:44 +08:00
|
|
|
g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
2010-05-16 17:00:53 +08:00
|
|
|
_("Could not load '%s': %s"),
|
2008-08-18 05:39:44 +08:00
|
|
|
gimp_filename_to_utf8 (filename),
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
2005-07-16 06:54:59 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
static GimpLayer *
|
|
|
|
layer_from_surface (GimpImage *image,
|
2011-04-21 10:18:25 +08:00
|
|
|
const gchar *layer_name,
|
|
|
|
gint position,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
gdouble progress_start,
|
|
|
|
gdouble progress_scale)
|
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
GimpLayer *layer;
|
2011-04-21 10:18:25 +08:00
|
|
|
|
2019-07-22 18:33:27 +08:00
|
|
|
layer = gimp_layer_new_from_surface (image, layer_name, surface,
|
|
|
|
progress_start,
|
|
|
|
progress_start + progress_scale);
|
2019-08-23 05:22:48 +08:00
|
|
|
gimp_image_insert_layer (image, layer, NULL, position);
|
2011-04-21 10:18:25 +08:00
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
render_page_to_surface (PopplerPage *page,
|
|
|
|
int width,
|
|
|
|
int height,
|
2012-02-02 22:04:07 +08:00
|
|
|
double scale,
|
|
|
|
gboolean antialias)
|
2011-04-20 21:25:44 +08:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
cairo_translate (cr, 0.0, 0.0);
|
|
|
|
|
|
|
|
if (scale != 1.0)
|
|
|
|
cairo_scale (cr, scale, scale);
|
|
|
|
|
2012-02-02 22:04:07 +08:00
|
|
|
if (! antialias)
|
|
|
|
{
|
2012-02-03 00:26:30 +08:00
|
|
|
cairo_font_options_t *options = cairo_font_options_create ();
|
2012-02-02 22:04:07 +08:00
|
|
|
|
|
|
|
cairo_get_font_options (cr, options);
|
|
|
|
cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_NONE);
|
|
|
|
cairo_set_font_options (cr, options);
|
|
|
|
cairo_font_options_destroy (options);
|
2012-02-03 00:26:30 +08:00
|
|
|
|
|
|
|
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
|
2012-02-02 22:04:07 +08:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:25:44 +08:00
|
|
|
poppler_page_render (page, cr);
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
|
|
|
|
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2011-04-21 10:18:25 +08:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
/* This is currently unused, but we'll have it here in case the military
|
|
|
|
wants it. */
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
render_page_to_pixbuf (PopplerPage *page,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
double scale)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
surface = render_page_to_surface (page, width, height, scale);
|
|
|
|
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
|
|
|
|
cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface));
|
2011-04-20 21:25:44 +08:00
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
#endif
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
static GimpImage *
|
2005-08-23 07:05:12 +08:00
|
|
|
load_image (PopplerDocument *doc,
|
|
|
|
const gchar *filename,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpPageSelectorTarget target,
|
|
|
|
guint32 resolution,
|
2012-02-02 22:04:07 +08:00
|
|
|
gboolean antialias,
|
2005-08-23 07:05:12 +08:00
|
|
|
PdfSelectedPages *pages)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
GimpImage *image = NULL;
|
|
|
|
GimpImage **images = NULL;
|
|
|
|
gint i;
|
|
|
|
gdouble scale;
|
|
|
|
gdouble doc_progress = 0;
|
2005-08-23 07:05:12 +08:00
|
|
|
|
|
|
|
if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
|
2019-08-23 05:22:48 +08:00
|
|
|
images = g_new0 (GimpImage *, pages->n_pages);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2005-09-30 16:16:10 +08:00
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
2005-09-30 02:34:08 +08:00
|
|
|
gimp_filename_to_utf8 (filename));
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
scale = resolution / gimp_unit_get_factor (GIMP_UNIT_POINT);
|
|
|
|
|
|
|
|
/* read the file */
|
|
|
|
|
|
|
|
for (i = 0; i < pages->n_pages; i++)
|
2005-07-18 18:16:45 +08:00
|
|
|
{
|
2005-08-15 18:30:39 +08:00
|
|
|
PopplerPage *page;
|
|
|
|
gchar *page_label;
|
|
|
|
gdouble page_width;
|
|
|
|
gdouble page_height;
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2005-08-15 18:30:39 +08:00
|
|
|
|
|
|
|
page = poppler_document_get_page (doc, pages->pages[i]);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
poppler_page_get_size (page, &page_width, &page_height);
|
|
|
|
width = page_width * scale;
|
|
|
|
height = page_height * scale;
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-08-23 07:05:12 +08:00
|
|
|
g_object_get (G_OBJECT (page), "label", &page_label, NULL);
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
if (! image)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2005-08-15 18:30:39 +08:00
|
|
|
gchar *name;
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
image = gimp_image_new (width, height, GIMP_RGB);
|
|
|
|
gimp_image_undo_disable (image);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2005-08-23 07:05:12 +08:00
|
|
|
if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
|
|
|
|
name = g_strdup_printf (_("%s-%s"), filename, page_label);
|
|
|
|
else
|
|
|
|
name = g_strdup_printf (_("%s-pages"), filename);
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
gimp_image_set_filename (image, name);
|
2005-08-15 18:30:39 +08:00
|
|
|
g_free (name);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
gimp_image_set_resolution (image, resolution, resolution);
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
2012-02-02 22:04:07 +08:00
|
|
|
surface = render_page_to_surface (page, width, height, scale, antialias);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
layer_from_surface (image, page_label, i, surface,
|
2011-04-21 10:18:25 +08:00
|
|
|
doc_progress, 1.0 / pages->n_pages);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
g_free (page_label);
|
2011-04-21 10:18:25 +08:00
|
|
|
cairo_surface_destroy (surface);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
doc_progress = (double) (i + 1) / pages->n_pages;
|
|
|
|
gimp_progress_update (doc_progress);
|
2005-08-23 07:05:12 +08:00
|
|
|
|
|
|
|
if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
|
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
images[i] = image;
|
2005-08-23 07:05:12 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
gimp_image_clean_all (image);
|
2005-08-23 07:05:12 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
image = 0;
|
2005-08-23 07:05:12 +08:00
|
|
|
}
|
2011-04-11 01:05:08 +08:00
|
|
|
}
|
|
|
|
gimp_progress_update (1.0);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
if (image)
|
2005-08-23 07:05:12 +08:00
|
|
|
{
|
2019-08-23 05:22:48 +08:00
|
|
|
gimp_image_undo_enable (image);
|
|
|
|
gimp_image_clean_all (image);
|
2005-08-23 07:05:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target == GIMP_PAGE_SELECTOR_TARGET_IMAGES)
|
2005-08-15 18:30:39 +08:00
|
|
|
{
|
2005-08-23 07:05:12 +08:00
|
|
|
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
|
|
|
{
|
|
|
|
/* Display images in reverse order. The last will be
|
|
|
|
* displayed by GIMP itself
|
|
|
|
*/
|
|
|
|
for (i = pages->n_pages - 1; i > 0; i--)
|
|
|
|
gimp_display_new (images[i]);
|
|
|
|
}
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
image = images[0];
|
2005-08-23 07:05:12 +08:00
|
|
|
|
|
|
|
g_free (images);
|
2005-08-15 18:30:39 +08:00
|
|
|
}
|
|
|
|
|
2019-08-23 05:22:48 +08:00
|
|
|
return image;
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
static cairo_surface_t *
|
|
|
|
get_thumb_surface (PopplerDocument *doc,
|
|
|
|
gint page_num,
|
|
|
|
gint preferred_size)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
|
|
|
PopplerPage *page;
|
2011-04-21 10:18:25 +08:00
|
|
|
cairo_surface_t *surface;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
page = poppler_document_get_page (doc, page_num);
|
|
|
|
|
|
|
|
if (! page)
|
|
|
|
return NULL;
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
surface = poppler_page_get_thumbnail (page);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
if (! surface)
|
2005-07-16 06:54:59 +08:00
|
|
|
{
|
2007-04-27 18:12:12 +08:00
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
|
|
|
gdouble scale;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
poppler_page_get_size (page, &width, &height);
|
|
|
|
|
2007-04-27 18:12:12 +08:00
|
|
|
scale = (gdouble) preferred_size / MAX (width, height);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
width *= scale;
|
|
|
|
height *= scale;
|
|
|
|
|
2012-02-02 22:04:07 +08:00
|
|
|
surface = render_page_to_surface (page, width, height, scale, TRUE);
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
|
|
|
|
2005-07-16 07:48:09 +08:00
|
|
|
g_object_unref (page);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2011-04-21 10:18:25 +08:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
get_thumb_pixbuf (PopplerDocument *doc,
|
|
|
|
gint page_num,
|
|
|
|
gint preferred_size)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
surface = get_thumb_surface (doc, page_num, preferred_size);
|
|
|
|
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0,
|
|
|
|
cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface));
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
PopplerDocument *document;
|
|
|
|
GimpPageSelector *selector;
|
|
|
|
gboolean stop_thumbnailing;
|
|
|
|
} ThreadData;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpPageSelector *selector;
|
|
|
|
gint page_no;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
} IdleData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
idle_set_thumbnail (gpointer data)
|
|
|
|
{
|
|
|
|
IdleData *idle_data = data;
|
|
|
|
|
|
|
|
gimp_page_selector_set_page_thumbnail (idle_data->selector,
|
|
|
|
idle_data->page_no,
|
|
|
|
idle_data->pixbuf);
|
|
|
|
g_object_unref (idle_data->pixbuf);
|
|
|
|
g_free (idle_data);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
thumbnail_thread (gpointer data)
|
|
|
|
{
|
|
|
|
ThreadData *thread_data = data;
|
|
|
|
gint n_pages;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
n_pages = poppler_document_get_n_pages (thread_data->document);
|
|
|
|
|
|
|
|
for (i = 0; i < n_pages; i++)
|
|
|
|
{
|
|
|
|
IdleData *idle_data = g_new0 (IdleData, 1);
|
|
|
|
|
|
|
|
idle_data->selector = thread_data->selector;
|
|
|
|
idle_data->page_no = i;
|
|
|
|
|
|
|
|
/* FIXME get preferred size from somewhere? */
|
2011-04-21 10:18:25 +08:00
|
|
|
idle_data->pixbuf = get_thumb_pixbuf (thread_data->document, i,
|
|
|
|
THUMBNAIL_SIZE);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
g_idle_add (idle_set_thumbnail, idle_data);
|
|
|
|
|
|
|
|
if (thread_data->stop_thumbnailing)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-07 20:53:26 +08:00
|
|
|
static GimpPDBStatusType
|
2005-07-16 06:54:59 +08:00
|
|
|
load_dialog (PopplerDocument *doc,
|
|
|
|
PdfSelectedPages *pages)
|
|
|
|
{
|
2005-07-18 18:16:45 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *vbox;
|
2006-03-17 23:43:15 +08:00
|
|
|
GtkWidget *title;
|
2005-07-18 18:16:45 +08:00
|
|
|
GtkWidget *selector;
|
2006-03-17 23:43:15 +08:00
|
|
|
GtkWidget *resolution;
|
2012-02-02 22:04:07 +08:00
|
|
|
GtkWidget *antialias;
|
2005-07-18 18:16:45 +08:00
|
|
|
GtkWidget *hbox;
|
2005-07-16 07:48:09 +08:00
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
ThreadData thread_data;
|
|
|
|
GThread *thread;
|
|
|
|
|
|
|
|
gint i;
|
|
|
|
gint n_pages;
|
|
|
|
|
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
2005-07-17 16:29:02 +08:00
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
gboolean run;
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2011-04-09 02:31:34 +08:00
|
|
|
dialog = gimp_dialog_new (_("Import from PDF"), PLUG_IN_ROLE,
|
2005-07-16 06:54:59 +08:00
|
|
|
NULL, 0,
|
2005-08-15 18:30:39 +08:00
|
|
|
gimp_standard_help_func, LOAD_PROC,
|
2005-07-16 06:54:59 +08:00
|
|
|
|
2017-02-12 23:18:24 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Import"), GTK_RESPONSE_OK,
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
2005-07-16 06:54:59 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2007-05-15 15:12:15 +08:00
|
|
|
gimp_window_set_transient (GTK_WINDOW (dialog));
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2005-07-16 06:54:59 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
|
2011-03-04 17:44:58 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
vbox, TRUE, TRUE, 0);
|
2005-07-16 06:54:59 +08:00
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2005-07-16 07:48:09 +08:00
|
|
|
/* Title */
|
2006-03-17 23:43:15 +08:00
|
|
|
title = gimp_prop_label_new (G_OBJECT (doc), "title");
|
2010-03-28 18:34:38 +08:00
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (title), PANGO_ELLIPSIZE_END);
|
2006-03-17 23:43:15 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), title, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (title);
|
2005-07-16 07:48:09 +08:00
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
/* Page Selector */
|
|
|
|
selector = gimp_page_selector_new ();
|
2007-05-02 22:30:17 +08:00
|
|
|
gtk_widget_set_size_request (selector, 380, 360);
|
2005-07-16 06:54:59 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), selector, TRUE, TRUE, 0);
|
2007-05-02 22:30:17 +08:00
|
|
|
gtk_widget_show (selector);
|
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
n_pages = poppler_document_get_n_pages (doc);
|
2011-12-07 20:27:28 +08:00
|
|
|
|
|
|
|
if (n_pages <= 0)
|
2011-12-08 02:09:31 +08:00
|
|
|
{
|
|
|
|
g_message (_("Error getting number of pages from the given PDF file."));
|
|
|
|
return GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
2011-12-07 20:27:28 +08:00
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (selector), n_pages);
|
2007-05-02 22:30:17 +08:00
|
|
|
gimp_page_selector_set_target (GIMP_PAGE_SELECTOR (selector),
|
|
|
|
loadvals.target);
|
2005-07-16 07:48:09 +08:00
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
for (i = 0; i < n_pages; i++)
|
2005-07-16 07:48:09 +08:00
|
|
|
{
|
|
|
|
PopplerPage *page;
|
|
|
|
gchar *label;
|
|
|
|
|
|
|
|
page = poppler_document_get_page (doc, i);
|
|
|
|
g_object_get (G_OBJECT (page), "label", &label, NULL);
|
|
|
|
|
|
|
|
gimp_page_selector_set_page_label (GIMP_PAGE_SELECTOR (selector), i,
|
|
|
|
label);
|
|
|
|
|
2005-07-17 16:29:02 +08:00
|
|
|
if (i == 0)
|
|
|
|
poppler_page_get_size (page, &width, &height);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-07-16 07:48:09 +08:00
|
|
|
g_object_unref (page);
|
|
|
|
g_free (label);
|
|
|
|
}
|
2017-09-25 05:54:49 +08:00
|
|
|
/* Since selecting none will be equivalent to selecting all, this is
|
|
|
|
* only useful as a feedback for the default behavior of selecting all
|
|
|
|
* pages. */
|
2017-09-25 07:53:59 +08:00
|
|
|
gimp_page_selector_select_all (GIMP_PAGE_SELECTOR (selector));
|
2005-07-16 07:48:09 +08:00
|
|
|
|
2005-10-28 22:57:32 +08:00
|
|
|
g_signal_connect_swapped (selector, "activate",
|
|
|
|
G_CALLBACK (gtk_window_activate_default),
|
|
|
|
dialog);
|
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
thread_data.document = doc;
|
|
|
|
thread_data.selector = GIMP_PAGE_SELECTOR (selector);
|
|
|
|
thread_data.stop_thumbnailing = FALSE;
|
|
|
|
|
2012-11-21 08:47:11 +08:00
|
|
|
thread = g_thread_new ("thumbnailer", thumbnail_thread, &thread_data);
|
2005-07-16 06:54:59 +08:00
|
|
|
|
|
|
|
/* Resolution */
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2006-03-17 23:43:15 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
2005-07-18 18:16:45 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2006-03-17 23:43:15 +08:00
|
|
|
resolution = gimp_resolution_entry_new (_("_Width (pixels):"), width,
|
|
|
|
_("_Height (pixels):"), height,
|
|
|
|
GIMP_UNIT_POINT,
|
2007-05-04 15:16:05 +08:00
|
|
|
_("_Resolution:"),
|
|
|
|
loadvals.resolution, GIMP_UNIT_INCH);
|
2005-07-17 16:29:02 +08:00
|
|
|
|
2006-03-17 23:43:15 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), resolution, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (resolution);
|
2005-07-17 16:29:02 +08:00
|
|
|
|
2006-03-17 23:43:15 +08:00
|
|
|
g_signal_connect (resolution, "x-changed",
|
|
|
|
G_CALLBACK (gimp_resolution_entry_update_x_in_dpi),
|
|
|
|
&loadvals.resolution);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2012-02-02 22:04:07 +08:00
|
|
|
/* Antialiasing*/
|
2012-02-03 00:28:35 +08:00
|
|
|
antialias = gtk_check_button_new_with_mnemonic (_("Use _Anti-aliasing"));
|
2012-02-02 22:04:07 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (antialias), loadvals.antialias);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), antialias, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
g_signal_connect (antialias, "toggled",
|
|
|
|
G_CALLBACK (gimp_toggle_button_update), &loadvals.antialias);
|
|
|
|
gtk_widget_show (antialias);
|
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
/* Setup done; display the dialog */
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
|
|
|
|
/* run the dialog */
|
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-08-23 07:05:12 +08:00
|
|
|
loadvals.target =
|
|
|
|
gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
pages->pages =
|
2005-07-16 06:54:59 +08:00
|
|
|
gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (selector),
|
|
|
|
&pages->n_pages);
|
|
|
|
|
|
|
|
/* select all if none selected */
|
|
|
|
if (pages->n_pages == 0)
|
|
|
|
{
|
|
|
|
gimp_page_selector_select_all (GIMP_PAGE_SELECTOR (selector));
|
|
|
|
|
2005-07-18 18:16:45 +08:00
|
|
|
pages->pages =
|
2005-07-16 06:54:59 +08:00
|
|
|
gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (selector),
|
|
|
|
&pages->n_pages);
|
|
|
|
}
|
2005-07-18 18:16:45 +08:00
|
|
|
|
2005-07-16 06:54:59 +08:00
|
|
|
/* cleanup */
|
|
|
|
thread_data.stop_thumbnailing = TRUE;
|
|
|
|
g_thread_join (thread);
|
|
|
|
|
2011-12-07 20:53:26 +08:00
|
|
|
return run ? GIMP_PDB_SUCCESS : GIMP_PDB_CANCEL;
|
2005-07-16 06:54:59 +08:00
|
|
|
}
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
** code for GimpResolutionEntry widget, formerly in libgimpwidgets
|
2007-05-04 15:16:05 +08:00
|
|
|
**/
|
|
|
|
|
|
|
|
static guint gimp_resolution_entry_signals[LAST_SIGNAL] = { 0 };
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
static GtkGridClass *parent_class = NULL;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_resolution_entry_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gre_type = 0;
|
|
|
|
|
|
|
|
if (! gre_type)
|
|
|
|
{
|
|
|
|
const GTypeInfo gre_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpResolutionEntryClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_resolution_entry_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpResolutionEntry),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_resolution_entry_init,
|
|
|
|
};
|
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gre_type = g_type_register_static (GTK_TYPE_GRID,
|
2007-05-04 06:13:48 +08:00
|
|
|
"GimpResolutionEntry",
|
|
|
|
&gre_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gre_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_class_init (GimpResolutionEntryClass *klass)
|
|
|
|
{
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gimp_resolution_entry_signals[HEIGHT_CHANGED] =
|
|
|
|
g_signal_new ("height-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gimp_resolution_entry_signals[WIDTH_CHANGED] =
|
|
|
|
g_signal_new ("width-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gimp_resolution_entry_signals[X_CHANGED] =
|
|
|
|
g_signal_new ("x-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpResolutionEntryClass, value_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gimp_resolution_entry_signals[Y_CHANGED] =
|
|
|
|
g_signal_new ("y-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpResolutionEntryClass, refval_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gimp_resolution_entry_signals[UNIT_CHANGED] =
|
|
|
|
g_signal_new ("unit-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpResolutionEntryClass, unit_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
klass->value_changed = NULL;
|
|
|
|
klass->refval_changed = NULL;
|
|
|
|
klass->unit_changed = NULL;
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_init (GimpResolutionEntry *gre)
|
|
|
|
{
|
2007-05-04 15:16:05 +08:00
|
|
|
gre->unitmenu = NULL;
|
|
|
|
gre->unit = GIMP_UNIT_INCH;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (gre), 2);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (gre), 4);
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_field_init (GimpResolutionEntry *gre,
|
|
|
|
GimpResolutionEntryField *gref,
|
|
|
|
GimpResolutionEntryField *corresponding,
|
|
|
|
guint changed_signal,
|
|
|
|
gdouble initial_val,
|
|
|
|
GimpUnit initial_unit,
|
|
|
|
gboolean size,
|
|
|
|
gint spinbutton_width)
|
|
|
|
{
|
|
|
|
gint digits;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
|
|
|
|
|
|
|
|
gref->gre = gre;
|
|
|
|
gref->corresponding = corresponding;
|
|
|
|
gref->changed_signal = gimp_resolution_entry_signals[changed_signal];
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
gref->value = initial_val /
|
|
|
|
gimp_unit_get_factor (initial_unit) *
|
|
|
|
corresponding->value *
|
|
|
|
gimp_unit_get_factor (gre->unit);
|
|
|
|
|
|
|
|
gref->phy_size = initial_val /
|
|
|
|
gimp_unit_get_factor (initial_unit);
|
|
|
|
}
|
|
|
|
else
|
2007-05-04 15:16:05 +08:00
|
|
|
{
|
|
|
|
gref->value = initial_val;
|
|
|
|
}
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
gref->min_value = GIMP_MIN_RESOLUTION;
|
|
|
|
gref->max_value = GIMP_MAX_RESOLUTION;
|
|
|
|
gref->adjustment = NULL;
|
|
|
|
|
|
|
|
gref->stop_recursion = 0;
|
|
|
|
|
|
|
|
gref->size = size;
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
gref->label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"xalign", 0.0,
|
|
|
|
"yalign", 0.5,
|
|
|
|
NULL);
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (gref->label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
gimp_resolution_entry_format_label (gre, gref->label, gref->phy_size);
|
|
|
|
}
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
digits = size ? 0 : MIN (gimp_unit_get_digits (initial_unit), 5) + 1;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-06-25 00:15:16 +08:00
|
|
|
gref->adjustment = gtk_adjustment_new (gref->value,
|
|
|
|
gref->min_value,
|
|
|
|
gref->max_value,
|
|
|
|
1.0, 10.0, 0.0);
|
2019-03-09 20:25:19 +08:00
|
|
|
gref->spinbutton = gimp_spin_button_new (gref->adjustment,
|
|
|
|
1.0, digits);
|
2014-06-23 05:01:31 +08:00
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (gref->spinbutton), TRUE);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
if (spinbutton_width > 0)
|
|
|
|
{
|
|
|
|
if (spinbutton_width < 17)
|
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (gref->spinbutton),
|
|
|
|
spinbutton_width);
|
|
|
|
else
|
|
|
|
gtk_widget_set_size_request (gref->spinbutton,
|
|
|
|
spinbutton_width, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_new:
|
|
|
|
* @width_label: Optional label for the width control.
|
|
|
|
* @width: Width of the item, specified in terms of @size_unit.
|
|
|
|
* @height_label: Optional label for the height control.
|
|
|
|
* @height: Height of the item, specified in terms of @size_unit.
|
|
|
|
* @size_unit: Unit used to specify the width and height.
|
2007-05-04 15:16:05 +08:00
|
|
|
* @res_label: Optional label for the resolution entry.
|
|
|
|
* @initial_res: The initial resolution.
|
2007-05-04 06:13:48 +08:00
|
|
|
* @initial_unit: The initial unit.
|
|
|
|
*
|
|
|
|
* Creates a new #GimpResolutionEntry widget.
|
|
|
|
*
|
2018-05-11 17:52:08 +08:00
|
|
|
* The #GimpResolutionEntry is derived from #GtkGrid and will have
|
2007-05-04 06:13:48 +08:00
|
|
|
* an empty border of one cell width on each side plus an empty column left
|
|
|
|
* of the #GimpUnitMenu to allow the caller to add labels or other widgets.
|
|
|
|
*
|
|
|
|
* A #GimpChainButton is displayed if independent is set to %TRUE.
|
|
|
|
*
|
|
|
|
* Returns: A pointer to the new #GimpResolutionEntry widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_resolution_entry_new (const gchar *width_label,
|
|
|
|
gdouble width,
|
|
|
|
const gchar *height_label,
|
|
|
|
gdouble height,
|
|
|
|
GimpUnit size_unit,
|
2007-05-04 15:16:05 +08:00
|
|
|
const gchar *res_label,
|
|
|
|
gdouble initial_res,
|
|
|
|
GimpUnit initial_unit)
|
2007-05-04 06:13:48 +08:00
|
|
|
{
|
|
|
|
GimpResolutionEntry *gre;
|
2010-11-01 04:38:27 +08:00
|
|
|
GtkTreeModel *model;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
gre = g_object_new (GIMP_TYPE_RESOLUTION_ENTRY, NULL);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
gre->unit = initial_unit;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
gimp_resolution_entry_field_init (gre, &gre->x,
|
|
|
|
&gre->width,
|
|
|
|
X_CHANGED,
|
2007-05-04 15:16:05 +08:00
|
|
|
initial_res, initial_unit,
|
|
|
|
FALSE, 0);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->x.spinbutton, 1, 3, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
g_signal_connect (gre->x.adjustment, "value-changed",
|
|
|
|
G_CALLBACK (gimp_resolution_entry_value_callback),
|
|
|
|
&gre->x);
|
|
|
|
|
|
|
|
gtk_widget_show (gre->x.spinbutton);
|
|
|
|
|
2010-11-01 04:38:27 +08:00
|
|
|
gre->unitmenu = gimp_unit_combo_box_new ();
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (gre->unitmenu));
|
|
|
|
gimp_unit_store_set_has_pixels (GIMP_UNIT_STORE (model), FALSE);
|
|
|
|
gimp_unit_store_set_has_percent (GIMP_UNIT_STORE (model), FALSE);
|
2011-11-18 23:40:49 +08:00
|
|
|
g_object_set (model,
|
|
|
|
"short-format", _("pixels/%a"),
|
|
|
|
"long-format", _("pixels/%a"),
|
|
|
|
NULL);
|
2010-11-01 04:38:27 +08:00
|
|
|
gimp_unit_combo_box_set_active (GIMP_UNIT_COMBO_BOX (gre->unitmenu),
|
|
|
|
initial_unit);
|
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->unitmenu, 3, 3, 1, 1);
|
2010-11-01 04:38:27 +08:00
|
|
|
g_signal_connect (gre->unitmenu, "changed",
|
2007-05-04 06:13:48 +08:00
|
|
|
G_CALLBACK (gimp_resolution_entry_unit_callback),
|
|
|
|
gre);
|
|
|
|
gtk_widget_show (gre->unitmenu);
|
|
|
|
|
|
|
|
gimp_resolution_entry_field_init (gre, &gre->width,
|
|
|
|
&gre->x,
|
|
|
|
WIDTH_CHANGED,
|
|
|
|
width, size_unit,
|
2007-05-04 15:16:05 +08:00
|
|
|
TRUE, 0);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->width.spinbutton, 1, 1, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->width.label, 3, 1, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
g_signal_connect (gre->width.adjustment, "value-changed",
|
|
|
|
G_CALLBACK (gimp_resolution_entry_value_callback),
|
|
|
|
&gre->width);
|
|
|
|
|
|
|
|
gtk_widget_show (gre->width.spinbutton);
|
|
|
|
gtk_widget_show (gre->width.label);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
gimp_resolution_entry_field_init (gre, &gre->height, &gre->x,
|
2007-05-04 06:13:48 +08:00
|
|
|
HEIGHT_CHANGED,
|
|
|
|
height, size_unit,
|
2007-05-04 15:16:05 +08:00
|
|
|
TRUE, 0);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->height.spinbutton, 1, 2, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), gre->height.label, 3, 2, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
g_signal_connect (gre->height.adjustment, "value-changed",
|
|
|
|
G_CALLBACK (gimp_resolution_entry_value_callback),
|
|
|
|
&gre->height);
|
|
|
|
|
|
|
|
gtk_widget_show (gre->height.spinbutton);
|
|
|
|
gtk_widget_show (gre->height.label);
|
|
|
|
|
|
|
|
if (width_label)
|
|
|
|
gimp_resolution_entry_attach_label (gre, width_label, 1, 0, 0.0);
|
|
|
|
|
|
|
|
if (height_label)
|
|
|
|
gimp_resolution_entry_attach_label (gre, height_label, 2, 0, 0.0);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
if (res_label)
|
|
|
|
gimp_resolution_entry_attach_label (gre, res_label, 3, 0, 0.0);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
return GTK_WIDGET (gre);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_attach_label:
|
|
|
|
* @gre: The #GimpResolutionEntry you want to add a label to.
|
|
|
|
* @text: The text of the label.
|
|
|
|
* @row: The row where the label will be attached.
|
|
|
|
* @column: The column where the label will be attached.
|
|
|
|
* @alignment: The horizontal alignment of the label.
|
|
|
|
*
|
2018-05-11 17:52:08 +08:00
|
|
|
* Attaches a #GtkLabel to the #GimpResolutionEntry (which is a #GtkGrid).
|
2007-05-04 06:13:48 +08:00
|
|
|
*
|
|
|
|
* Returns: A pointer to the new #GtkLabel widget.
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_resolution_entry_attach_label (GimpResolutionEntry *gre,
|
|
|
|
const gchar *text,
|
|
|
|
gint row,
|
|
|
|
gint column,
|
|
|
|
gfloat alignment)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), NULL);
|
|
|
|
g_return_val_if_fail (text != NULL, NULL);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (text);
|
|
|
|
|
|
|
|
if (column == 0)
|
|
|
|
{
|
2009-10-10 20:40:23 +08:00
|
|
|
GList *children;
|
|
|
|
GList *list;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2009-10-10 20:40:23 +08:00
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (gre));
|
|
|
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
2007-05-04 06:13:48 +08:00
|
|
|
{
|
2009-10-10 20:40:23 +08:00
|
|
|
GtkWidget *child = list->data;
|
|
|
|
gint left_attach;
|
|
|
|
gint top_attach;
|
|
|
|
|
|
|
|
gtk_container_child_get (GTK_CONTAINER (gre), child,
|
|
|
|
"left-attach", &left_attach,
|
|
|
|
"top-attach", &top_attach,
|
|
|
|
NULL);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2009-10-10 20:40:23 +08:00
|
|
|
if (left_attach == 1 && top_attach == row)
|
2007-05-04 06:13:48 +08:00
|
|
|
{
|
2009-10-10 20:40:23 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), child);
|
2007-05-04 06:13:48 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-10 20:40:23 +08:00
|
|
|
|
|
|
|
g_list_free (children);
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-09 01:11:20 +08:00
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), alignment);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-05-11 17:52:08 +08:00
|
|
|
gtk_grid_attach (GTK_GRID (gre), label, column, row, 1, 1);
|
2007-05-04 06:13:48 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_get_x_in_dpi;
|
|
|
|
* @gre: The #GimpResolutionEntry you want to know the resolution of.
|
|
|
|
*
|
|
|
|
* Returns the X resolution of the #GimpResolutionEntry in pixels per inch.
|
|
|
|
**/
|
|
|
|
gdouble
|
|
|
|
gimp_resolution_entry_get_x_in_dpi (GimpResolutionEntry *gre)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
|
|
|
|
|
2009-07-07 23:09:21 +08:00
|
|
|
/* dots_in_one_unit * units_in_one_inch -> dpi */
|
|
|
|
return gre->x.value * gimp_unit_get_factor (gre->unit);
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_get_y_in_dpi;
|
|
|
|
* @gre: The #GimpResolutionEntry you want to know the resolution of.
|
|
|
|
*
|
|
|
|
* Returns the Y resolution of the #GimpResolutionEntry in pixels per inch.
|
|
|
|
**/
|
|
|
|
gdouble
|
|
|
|
gimp_resolution_entry_get_y_in_dpi (GimpResolutionEntry *gre)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre), 0);
|
|
|
|
|
2009-07-07 23:09:21 +08:00
|
|
|
return gre->y.value * gimp_unit_get_factor (gre->unit);
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_update_value (GimpResolutionEntryField *gref,
|
|
|
|
gdouble value)
|
|
|
|
{
|
|
|
|
if (gref->stop_recursion > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gref->value = value;
|
|
|
|
|
|
|
|
gref->stop_recursion++;
|
|
|
|
|
|
|
|
if (gref->size)
|
|
|
|
gimp_resolution_entry_update_value (gref->corresponding,
|
|
|
|
gref->value /
|
|
|
|
gref->phy_size /
|
|
|
|
gimp_unit_get_factor (gref->gre->unit));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gdouble factor = gimp_unit_get_factor (gref->gre->unit);
|
|
|
|
|
2007-05-04 15:16:05 +08:00
|
|
|
gimp_resolution_entry_update_value (&gref->gre->width,
|
|
|
|
gref->value *
|
|
|
|
gref->gre->width.phy_size *
|
|
|
|
factor);
|
|
|
|
|
|
|
|
gimp_resolution_entry_update_value (&gref->gre->height,
|
|
|
|
gref->value *
|
|
|
|
gref->gre->height.phy_size *
|
|
|
|
factor);
|
2007-05-04 06:13:48 +08:00
|
|
|
}
|
|
|
|
|
2014-06-23 05:01:31 +08:00
|
|
|
gtk_adjustment_set_value (gref->adjustment, value);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
gref->stop_recursion--;
|
|
|
|
|
|
|
|
g_signal_emit (gref->gre, gref->changed_signal, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-25 00:15:16 +08:00
|
|
|
gimp_resolution_entry_value_callback (GtkAdjustment *adjustment,
|
|
|
|
gpointer data)
|
2007-05-04 06:13:48 +08:00
|
|
|
{
|
2007-05-04 15:16:05 +08:00
|
|
|
GimpResolutionEntryField *gref = (GimpResolutionEntryField *) data;
|
|
|
|
gdouble new_value;
|
2007-05-04 06:13:48 +08:00
|
|
|
|
2018-06-25 00:15:16 +08:00
|
|
|
new_value = gtk_adjustment_get_value (adjustment);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
if (gref->value != new_value)
|
|
|
|
gimp_resolution_entry_update_value (gref, new_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_update_unit (GimpResolutionEntry *gre,
|
|
|
|
GimpUnit unit)
|
|
|
|
{
|
|
|
|
GimpUnit old_unit;
|
|
|
|
gint digits;
|
|
|
|
gdouble factor;
|
|
|
|
|
|
|
|
old_unit = gre->unit;
|
|
|
|
gre->unit = unit;
|
|
|
|
|
|
|
|
digits = (gimp_unit_get_digits (GIMP_UNIT_INCH) -
|
|
|
|
gimp_unit_get_digits (unit));
|
|
|
|
|
|
|
|
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (gre->x.spinbutton),
|
|
|
|
MAX (3 + digits, 3));
|
|
|
|
|
|
|
|
factor = gimp_unit_get_factor (old_unit) / gimp_unit_get_factor (unit);
|
|
|
|
|
|
|
|
gre->x.min_value *= factor;
|
|
|
|
gre->x.max_value *= factor;
|
|
|
|
gre->x.value *= factor;
|
|
|
|
|
2010-10-25 07:35:35 +08:00
|
|
|
gtk_adjustment_set_value (gre->x.adjustment, gre->x.value);
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
gimp_resolution_entry_format_label (gre,
|
|
|
|
gre->width.label, gre->width.phy_size);
|
|
|
|
gimp_resolution_entry_format_label (gre,
|
|
|
|
gre->height.label, gre->height.phy_size);
|
|
|
|
|
|
|
|
g_signal_emit (gre, gimp_resolution_entry_signals[UNIT_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_unit_callback (GtkWidget *widget,
|
|
|
|
GimpResolutionEntry *gre)
|
|
|
|
{
|
|
|
|
GimpUnit new_unit;
|
|
|
|
|
2010-11-01 04:38:27 +08:00
|
|
|
new_unit = gimp_unit_combo_box_get_active (GIMP_UNIT_COMBO_BOX (widget));
|
2007-05-04 06:13:48 +08:00
|
|
|
|
|
|
|
if (gre->unit != new_unit)
|
|
|
|
gimp_resolution_entry_update_unit (gre, new_unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_update_x_in_dpi:
|
|
|
|
* @gre: the #GimpResolutionEntry
|
|
|
|
* @data: a pointer to a gdouble
|
|
|
|
*
|
|
|
|
* Convenience function to set a double to the X resolution, suitable
|
|
|
|
* for use as a signal callback.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_resolution_entry_update_x_in_dpi (GimpResolutionEntry *gre,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gdouble *val;
|
|
|
|
|
|
|
|
g_return_if_fail (gre != NULL);
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
|
|
|
|
|
|
|
|
val = (gdouble *) data;
|
|
|
|
|
|
|
|
*val = gimp_resolution_entry_get_x_in_dpi (gre);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_resolution_entry_update_y_in_dpi:
|
|
|
|
* @gre: the #GimpResolutionEntry
|
|
|
|
* @data: a pointer to a gdouble
|
|
|
|
*
|
|
|
|
* Convenience function to set a double to the Y resolution, suitable
|
|
|
|
* for use as a signal callback.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_resolution_entry_update_y_in_dpi (GimpResolutionEntry *gre,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gdouble *val;
|
|
|
|
|
|
|
|
g_return_if_fail (gre != NULL);
|
|
|
|
g_return_if_fail (data != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_RESOLUTION_ENTRY (gre));
|
|
|
|
|
|
|
|
val = (gdouble *) data;
|
|
|
|
|
|
|
|
*val = gimp_resolution_entry_get_y_in_dpi (gre);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_resolution_entry_format_label (GimpResolutionEntry *gre,
|
|
|
|
GtkWidget *label,
|
|
|
|
gdouble size)
|
|
|
|
{
|
|
|
|
gchar *format = g_strdup_printf ("%%.%df %%s",
|
|
|
|
gimp_unit_get_digits (gre->unit));
|
|
|
|
gchar *text = g_strdup_printf (format,
|
|
|
|
size * gimp_unit_get_factor (gre->unit),
|
|
|
|
gimp_unit_get_plural (gre->unit));
|
|
|
|
g_free (format);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|