[gimp] plug-ins: port file-pdf-save to GimpPlugIn and libgmp objects



commit 3d7c04418106825014f7bc64bf4f7391285c91e8
Author: Michael Natterer <mitch gimp org>
Date:   Tue Aug 27 14:12:50 2019 +0200

    plug-ins: port file-pdf-save to GimpPlugIn and libgmp objects

 plug-ins/common/Makefile.am     |   2 -
 plug-ins/common/file-pdf-save.c | 997 ++++++++++++++++++++++------------------
 plug-ins/common/plugin-defs.pl  |   2 +-
 3 files changed, 538 insertions(+), 463 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index dd3ab6fd0e..192d308f26 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -921,8 +921,6 @@ file_pdf_load_LDADD = \
 
 file_pdf_save_CFLAGS = $(CAIRO_PDF_CFLAGS)
 
-file_pdf_save_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
 file_pdf_save_SOURCES = \
        file-pdf-save.c
 
diff --git a/plug-ins/common/file-pdf-save.c b/plug-ins/common/file-pdf-save.c
index e771052851..cbbc909118 100644
--- a/plug-ins/common/file-pdf-save.c
+++ b/plug-ins/common/file-pdf-save.c
@@ -115,7 +115,6 @@
 
 
 #define SAVE_PROC               "file-pdf-save"
-#define SAVE2_PROC              "file-pdf-save2"
 #define SAVE_MULTI_PROC         "file-pdf-save-multi"
 #define PLUG_IN_BINARY          "file-pdf-save"
 #define PLUG_IN_ROLE            "gimp-file-pdf-save"
@@ -141,17 +140,11 @@ GQuark gimp_plugin_pdf_save_error_quark (void);
 
 typedef enum
 {
-  SA_RUN_MODE,
-  SA_IMAGE,
-  SA_DRAWABLE,
-  SA_FILENAME,
-  SA_RAW_FILENAME,
   SA_VECTORIZE,
   SA_IGNORE_HIDDEN,
   SA_APPLY_MASKS,
   SA_LAYERS_AS_PAGES,
-  SA_REVERSE_ORDER,
-  SA_ARG_COUNT
+  SA_REVERSE_ORDER
 } SaveArgs;
 
 typedef enum
@@ -162,9 +155,7 @@ typedef enum
   SMA_VECTORIZE,
   SMA_IGNORE_HIDDEN,
   SMA_APPLY_MASKS,
-  SMA_FILENAME,
-  SMA_RAWFILENAME,
-  SMA_ARG_COUNT
+  SMA_FILENAME
 } SaveMultiArgs;
 
 typedef struct
@@ -178,9 +169,9 @@ typedef struct
 
 typedef struct
 {
-  gint32  images[MAX_PAGE_COUNT];
-  guint32 image_count;
-  gchar   file_name[MAX_FILE_NAME_LENGTH];
+  GimpImage *images[MAX_PAGE_COUNT];
+  guint32    image_count;
+  gchar      file_name[MAX_FILE_NAME_LENGTH];
 } PdfMultiPage;
 
 typedef struct
@@ -194,7 +185,7 @@ enum
   THUMB,
   PAGE_NUMBER,
   IMAGE_NAME,
-  IMAGE_ID
+  IMAGE
 };
 
 typedef struct
@@ -205,69 +196,97 @@ typedef struct
 } Page;
 
 
-static void              query                      (void);
+typedef struct _Pdf      Pdf;
+typedef struct _PdfClass PdfClass;
 
-static void              run                        (const gchar     *name,
-                                                     gint             nparams,
-                                                     const GimpParam *param,
-                                                     gint            *nreturn_vals,
-                                                     GimpParam      **return_vals);
+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))
 
-static gboolean          init_vals                  (const gchar     *name,
-                                                     gint             nparams,
-                                                     const GimpParam *param,
-                                                     gboolean        *single,
-                                                     gboolean        *defaults,
-                                                     GimpRunMode     *run_mode);
+GType                   pdf_get_type             (void) G_GNUC_CONST;
 
-static void              init_image_list_defaults   (gint32           image);
+static GList          * pdf_query_procedures     (GimpPlugIn           *plug_in);
+static GimpProcedure  * pdf_create_procedure     (GimpPlugIn           *plug_in,
+                                                  const gchar          *name);
 
-static void              validate_image_list        (void);
+static GimpValueArray * pdf_save                 (GimpProcedure        *procedure,
+                                                  GimpRunMode           run_mode,
+                                                  GimpImage            *image,
+                                                  GimpDrawable         *drawable,
+                                                  GFile                *file,
+                                                  const GimpValueArray *args,
+                                                  gpointer              run_data);
+static GimpValueArray * pdf_save_multi           (GimpProcedure        *procedure,
+                                                  const GimpValueArray *args,
+                                                  gpointer              run_data);
 
-static gboolean          gui_single                 (void);
+static GimpValueArray * pdf_save_image           (GimpProcedure        *procedure,
+                                                  gboolean              single_image,
+                                                  gboolean              defaults_proc);
 
-static gboolean          gui_multi                  (void);
+static void             init_image_list_defaults (GimpImage            *image);
 
-static void              reverse_order_toggled      (GtkToggleButton *reverse_order,
-                                                     GtkButton       *layers_as_pages);
+static void             validate_image_list      (void);
 
-static void              choose_file_call           (GtkWidget       *browse_button,
-                                                     gpointer         file_entry);
+static gboolean         gui_single               (void);
+static gboolean         gui_multi                (void);
 
-static gboolean          get_image_list             (void);
+static void             reverse_order_toggled    (GtkToggleButton      *reverse_order,
+                                                  GtkButton            *layers_as_pages);
 
-static GtkTreeModel    * create_model               (void);
+static void             choose_file_call         (GtkWidget            *browse_button,
+                                                  gpointer              file_entry);
 
-static void              add_image_call             (GtkWidget       *widget,
-                                                     gpointer         img_combo);
-static void              del_image_call             (GtkWidget       *widget,
-                                                     gpointer         icon_view);
-static void              remove_call                (GtkTreeModel    *tree_model,
-                                                     GtkTreePath     *path,
-                                                     gpointer         user_data);
-static void              recount_pages              (void);
+static gboolean         get_image_list           (void);
 
-static cairo_surface_t * get_cairo_surface          (gint32           drawable_ID,
-                                                     gboolean         as_mask,
-                                                     GError         **error);
+static GtkTreeModel   * create_model             (void);
 
-static GimpRGB           get_layer_color            (gint32           layer_ID,
-                                                     gboolean        *single);
+static void             add_image_call           (GtkWidget            *widget,
+                                                  gpointer              img_combo);
+static void             del_image_call           (GtkWidget            *widget,
+                                                  gpointer              icon_view);
+static void             remove_call              (GtkTreeModel         *tree_model,
+                                                  GtkTreePath          *path,
+                                                  gpointer              user_data);
+static void             recount_pages            (void);
 
-static void              drawText                   (gint32           text_id,
-                                                     gdouble          opacity,
-                                                     cairo_t         *cr,
-                                                     gdouble          x_res,
-                                                     gdouble          y_res);
+static cairo_surface_t *get_cairo_surface        (GimpDrawable         *drawable,
+                                                  gboolean              as_mask,
+                                                  GError              **error);
+
+static GimpRGB          get_layer_color          (GimpLayer            *layer,
+                                                  gboolean             *single);
+
+static void             drawText                 (GimpLayer            *layer,
+                                                  gdouble               opacity,
+                                                  cairo_t              *cr,
+                                                  gdouble               x_res,
+                                                  gdouble               y_res);
+
+static gboolean         draw_layer               (GimpLayer           **layers,
+                                                  gint                  n_layers,
+                                                  gint                  j,
+                                                  cairo_t              *cr,
+                                                  gdouble               x_res,
+                                                  gdouble               y_res,
+                                                  const gchar          *name,
+                                                  GError              **error);
+
+
+G_DEFINE_TYPE (Pdf, pdf, GIMP_TYPE_PLUG_IN)
+
+GIMP_MAIN (PDF_TYPE)
 
-static gboolean          draw_layer                 (gint32          *layers,
-                                                     gint             n_layers,
-                                                     gint             j,
-                                                     cairo_t         *cr,
-                                                     gdouble          x_res,
-                                                     gdouble          y_res,
-                                                     const gchar     *name,
-                                                     GError         **error);
 
 static gboolean     dnd_remove = TRUE;
 static PdfMultiPage multi_page;
@@ -285,203 +304,353 @@ static GtkTreeModel *model;
 static GtkWidget    *file_choose;
 static gchar        *file_name;
 
-GimpPlugInInfo PLUG_IN_INFO =
-{
-  NULL,
-  NULL,
-  query,
-  run
-};
 
 G_DEFINE_QUARK (gimp-plugin-pdf-save-error-quark, gimp_plugin_pdf_save_error)
 
-MAIN()
+static void
+pdf_class_init (PdfClass *klass)
+{
+  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;
+}
 
 static void
-query (void)
+pdf_init (Pdf *pdf)
 {
-  static GimpParamDef save_args[] =
-  {
-    { GIMP_PDB_INT32,    "run-mode",      "Run mode" },
-    { GIMP_PDB_IMAGE,    "image",         "Input image" },
-    { GIMP_PDB_DRAWABLE, "drawable",      "Input drawable" },
-    { GIMP_PDB_STRING,   "filename",      "The name of the file to save the image in" },
-    { GIMP_PDB_STRING,   "raw-filename",  "The name of the file to save the image in" },
-    { GIMP_PDB_INT32,    "vectorize",     "Convert bitmaps to vector graphics where possible. TRUE or FALSE" 
},
-    { GIMP_PDB_INT32,    "ignore-hidden", "Omit hidden layers and layers with zero opacity. TRUE or FALSE" },
-    { GIMP_PDB_INT32,    "apply-masks",   "Apply layer masks before saving. TRUE or FALSE (Keeping them will 
not change the output)" }
-  };
-
-  static GimpParamDef save2_args[] =
-  {
-    { GIMP_PDB_INT32,    "run-mode",        "Run mode" },
-    { GIMP_PDB_IMAGE,    "image",           "Input image" },
-    { GIMP_PDB_DRAWABLE, "drawable",        "Input drawable" },
-    { GIMP_PDB_STRING,   "filename",        "The name of the file to save the image in" },
-    { GIMP_PDB_STRING,   "raw-filename",    "The name of the file to save the image in" },
-    { GIMP_PDB_INT32,    "vectorize",       "Convert bitmaps to vector graphics where possible. TRUE or 
FALSE" },
-    { GIMP_PDB_INT32,    "ignore-hidden",   "Omit hidden layers and layers with zero opacity. TRUE or FALSE" 
},
-    { GIMP_PDB_INT32,    "apply-masks",     "Apply layer masks before saving. TRUE or FALSE (Keeping them 
will not change the output)" },
-    { GIMP_PDB_INT32,    "layers-as-pages", "Layers as pages (bottom layers first). TRUE or FALSE" },
-    { GIMP_PDB_INT32,    "reverse-order",   "Reverse the pages order (top layers first). TRUE or FALSE" }
-  };
-
-  static GimpParamDef save_multi_args[] =
-  {
-    { GIMP_PDB_INT32,      "run-mode",        "Run mode" },
-    { GIMP_PDB_INT32,      "count",           "The amount of images entered (This will be the amount of 
pages). 1 <= count <= MAX_PAGE_COUNT" },
-    { GIMP_PDB_INT32ARRAY, "images",          "Input image for each page (An image can appear more than 
once)" },
-    { GIMP_PDB_INT32,      "vectorize",       "Convert bitmaps to vector graphics where possible. TRUE or 
FALSE" },
-    { GIMP_PDB_INT32,      "ignore-hidden",   "Omit hidden layers and layers with zero opacity. TRUE or 
FALSE" },
-    { GIMP_PDB_INT32,      "apply-masks",     "Apply layer masks before saving. TRUE or FALSE (Keeping them 
will not change the output)" },
-    { GIMP_PDB_STRING,     "filename",        "The name of the file to save the image in" },
-    { GIMP_PDB_STRING,     "raw-filename",    "The name of the file to save the image in" }
-  };
-
-  gimp_install_procedure (SAVE_PROC,
-                          "Save files in PDF format",
-                          "Saves 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.",
-                          "Barak Itkin",
-                          "Copyright Barak Itkin",
-                          "August 2009",
-                          N_("Portable Document Format"),
-                          "RGB*, GRAY*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_args), 0,
-                          save_args, NULL);
-
-  gimp_install_procedure (SAVE2_PROC,
-                          "Save files in PDF format",
-                          "Saves 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.\n"
-                          "This procedure adds an extra parameter to "
-                          "file-pdf-save to save layers as pages.",
-                          "Barak Itkin, Lionel N., Jehan",
-                          "Copyright Barak Itkin, Lionel N., Jehan",
-                          "August 2009, 2017",
-                          N_("Portable Document Format"),
-                          "RGB*, GRAY*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save2_args), 0,
-                          save2_args, NULL);
-
-  gimp_install_procedure (SAVE_MULTI_PROC,
-                          "Save files in PDF format",
-                          "Saves 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.",
-                          "Barak Itkin",
-                          "Copyright Barak Itkin",
-                          "August 2009",
-                          N_("_Create multipage PDF..."),
-                          "RGB*, GRAY*, INDEXED*",
-                          GIMP_PLUGIN,
-                          G_N_ELEMENTS (save_multi_args), 0,
-                          save_multi_args, NULL);
+}
 
-#if 0
-  gimp_plugin_menu_register (SAVE_MULTI_PROC,
-                             "<Image>/File/Create/PDF");
-#endif
+static GList *
+pdf_query_procedures (GimpPlugIn *plug_in)
+{
+  GList *list = NULL;
 
-  gimp_register_file_handler_mime (SAVE2_PROC, "application/pdf");
-  gimp_register_save_handler (SAVE2_PROC, "pdf", "");
+  list = g_list_append (list, g_strdup (SAVE_PROC));
+  list = g_list_append (list, g_strdup (SAVE_MULTI_PROC));
+
+  return list;
 }
 
-static cairo_status_t
-write_func (void                *fp,
-            const unsigned char *data,
-            unsigned int         size)
+static GimpProcedure *
+pdf_create_procedure (GimpPlugIn  *plug_in,
+                        const gchar *name)
 {
-  return fwrite (data, 1, size, fp) == size ? CAIRO_STATUS_SUCCESS
-                                            : CAIRO_STATUS_WRITE_ERROR;
+  GimpProcedure *procedure = NULL;
+
+  if (! strcmp (name, SAVE_PROC))
+    {
+      procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                           pdf_save, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "*");
+
+      gimp_procedure_set_menu_label (procedure, N_("Portable Document Format"));
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Save files in PDF format",
+                                        "Saves 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,
+                                      "Barak Itkin, Lionel N., Jehan",
+                                      "Copyright Barak Itkin, Lionel N., Jehan",
+                                      "August 2009, 2017");
+
+      gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
+                                          "application/pdf");
+      gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
+                                          "pdf");
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "vectorize",
+                             "Vectorize",
+                             "Convert bitmaps to vector graphics where possible.",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "ignore-hidden",
+                             "Ignore hidden",
+                             "Omit hidden layers and layers with zero opacity.",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "apply-masks",
+                             "Apply masks",
+                             "Apply layer masks before saving (Keeping them "
+                             "will not change the output),",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "layers-as-pages",
+                             "Layers as pages",
+                             "Layers as pages (bottom layers first).",
+                             FALSE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "reverse-order",
+                             "Reverse order",
+                             "Reverse the pages order (top layers first).",
+                             FALSE,
+                             G_PARAM_READWRITE);
+    }
+  else if (! strcmp (name, SAVE_MULTI_PROC))
+    {
+      procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
+                                      pdf_save_multi, NULL, NULL);
+
+      gimp_procedure_set_image_types (procedure, "*");
+
+      gimp_procedure_set_menu_label (procedure, N_("_Create multipage PDF..."));
+#if 0
+      gimp_procedure_add_menu_path (procedure, "<Image>/File/Create/PDF");
+#endif
+
+      gimp_procedure_set_documentation (procedure,
+                                        "Save files in PDF format",
+                                        "Saves 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,
+                                      "Barak Itkin",
+                                      "Copyright Barak Itkin",
+                                      "August 2009");
+
+      GIMP_PROC_ARG_ENUM (procedure, "run-mode",
+                          "Run mode",
+                          "The run mode",
+                          GIMP_TYPE_RUN_MODE,
+                          GIMP_RUN_INTERACTIVE,
+                          G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_INT (procedure, "count",
+                         "Count",
+                         "The number of images entered (This will be the "
+                         "number of pages).",
+                         1, MAX_PAGE_COUNT, 1,
+                         G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_INT32_ARRAY (procedure, "images",
+                                 "Images",
+                                 "Input image for each page (An image can "
+                                 "appear more than once)",
+                                 G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "vectorize",
+                             "Vectorize",
+                             "Convert bitmaps to vector graphics where possible.",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "ignore-hidden",
+                             "Ignore hidden",
+                             "Omit hidden layers and layers with zero opacity.",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_BOOLEAN (procedure, "apply-masks",
+                             "Apply masks",
+                             "Apply layer masks before saving (Keeping them "
+                             "will not change the output),",
+                             TRUE,
+                             G_PARAM_READWRITE);
+
+      GIMP_PROC_ARG_STRING (procedure, "uri",
+                            "URI",
+                            "The URI of the file to save to",
+                            NULL,
+                            GIMP_PARAM_READWRITE);
+    }
+
+  return procedure;
 }
 
-static void
-run (const gchar      *name,
-     gint              nparams,
-     const GimpParam  *param,
-     gint             *nreturn_vals,
-     GimpParam       **return_vals)
+static GimpValueArray *
+pdf_save (GimpProcedure        *procedure,
+          GimpRunMode           run_mode,
+          GimpImage            *image,
+          GimpDrawable         *drawable,
+          GFile                *file,
+          const GimpValueArray *args,
+          gpointer              run_data)
 {
-  static GimpParam        values[2];
-  GimpPDBStatusType       status = GIMP_PDB_SUCCESS;
-  GimpRunMode             run_mode;
-  gboolean                single_image;
-  gboolean                defaults_proc;
-  cairo_surface_t        *pdf_file;
-  cairo_t                *cr;
-  GimpExportCapabilities  capabilities;
-  FILE                   *fp;
-  gint                    i;
-  GError                 *error = NULL;
+  gboolean had_saved_list = FALSE;
+  gboolean defaults = FALSE;
 
   INIT_I18N ();
   gegl_init (NULL, NULL);
 
-  /* Setting mandatory output values */
-  *nreturn_vals = 1;
-  *return_vals  = values;
-
-  values[0].type          = GIMP_PDB_STATUS;
-  values[0].data.d_status = status;
-
   /* Initializing all the settings */
   multi_page.image_count = 0;
 
-  if (! init_vals (name, nparams, param, &single_image,
-                   &defaults_proc, &run_mode))
+  file_name = g_file_get_path (file);
+
+  if (run_mode == GIMP_RUN_NONINTERACTIVE)
     {
-      values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
-      return;
+      optimize.apply_masks     = GIMP_VALUES_GET_BOOLEAN (args, SA_APPLY_MASKS);
+      optimize.vectorize       = GIMP_VALUES_GET_BOOLEAN (args, SA_VECTORIZE);
+      optimize.ignore_hidden   = GIMP_VALUES_GET_BOOLEAN (args, SA_IGNORE_HIDDEN);
+      optimize.layers_as_pages = GIMP_VALUES_GET_BOOLEAN (args, SA_LAYERS_AS_PAGES);
+      optimize.reverse_order   = GIMP_VALUES_GET_BOOLEAN (args, SA_REVERSE_ORDER);
     }
+  else
+    defaults = TRUE;
+
+  switch (run_mode)
+    {
+    case GIMP_RUN_NONINTERACTIVE:
+      init_image_list_defaults (image);
+      break;
+
+    case GIMP_RUN_INTERACTIVE:
+      /* Possibly retrieve data */
+      gimp_get_data (DATA_OPTIMIZE, &optimize);
+      had_saved_list = gimp_get_data (DATA_IMAGE_LIST, &multi_page);
+
+      if (had_saved_list && (file_name == NULL || strlen (file_name) == 0))
+        {
+          file_name = multi_page.file_name;
+        }
+
+      init_image_list_defaults (image);
+      break;
+
+    case GIMP_RUN_WITH_LAST_VALS:
+      /* Possibly retrieve data */
+      init_image_list_defaults (image);
+      gimp_get_data (DATA_OPTIMIZE, &optimize);
+      break;
+    }
+
+  validate_image_list ();
 
-  /* Starting the executions */
   if (run_mode == GIMP_RUN_INTERACTIVE)
     {
-      if (single_image)
+      if (! gui_single ())
         {
-          if (! gui_single ())
-            {
-              values[0].data.d_status = GIMP_PDB_CANCEL;
-              return;
-            }
+          return gimp_procedure_new_return_values (procedure,
+                                                   GIMP_PDB_CANCEL,
+                                                   NULL);
         }
-      else if (! gui_multi ())
+    }
+
+  return pdf_save_image (procedure, TRUE, defaults);
+}
+
+static GimpValueArray *
+pdf_save_multi (GimpProcedure        *procedure,
+                const GimpValueArray *args,
+                gpointer              run_data)
+{
+  GimpRunMode  run_mode;
+  GimpImage   *image = NULL;
+  GFile       *file;
+  gboolean     had_saved_list = FALSE;
+
+  INIT_I18N ();
+  gegl_init (NULL, NULL);
+
+  run_mode = GIMP_VALUES_GET_ENUM (args, 0);
+
+  file = g_file_new_for_uri (GIMP_VALUES_GET_STRING (args, SMA_FILENAME));
+  file_name = g_file_get_path (file);
+
+  /* Initializing all the settings */
+  multi_page.image_count = 0;
+
+  optimize.apply_masks   = GIMP_VALUES_GET_BOOLEAN (args, SMA_APPLY_MASKS);
+  optimize.vectorize     = GIMP_VALUES_GET_BOOLEAN (args, SMA_VECTORIZE);
+  optimize.ignore_hidden = GIMP_VALUES_GET_BOOLEAN (args, SMA_IGNORE_HIDDEN);
+
+  switch (run_mode)
+    {
+      const gint32 *image_ids;
+      gint          i;
+
+    case GIMP_RUN_NONINTERACTIVE:
+      multi_page.image_count = GIMP_VALUES_GET_INT (args, SMA_COUNT);
+      image_ids = GIMP_VALUES_GET_INT32_ARRAY (args, SMA_IMAGES);
+      if (image_ids)
+        for (i = 0; i < multi_page.image_count; i++)
+          multi_page.images[i] = gimp_image_get_by_id (image_ids[i]);
+      break;
+
+    case GIMP_RUN_INTERACTIVE:
+      /* Possibly retrieve data */
+      gimp_get_data (DATA_OPTIMIZE, &optimize);
+      had_saved_list = gimp_get_data (DATA_IMAGE_LIST, &multi_page);
+
+      if (had_saved_list && (file_name == NULL || strlen (file_name) == 0))
         {
-          values[0].data.d_status = GIMP_PDB_CANCEL;
-          return;
+          file_name = multi_page.file_name;
         }
 
-      if (file_name == NULL)
+      if (! had_saved_list)
+        init_image_list_defaults (image);
+      break;
+
+    case GIMP_RUN_WITH_LAST_VALS:
+      /* Possibly retrieve data */
+      had_saved_list = gimp_get_data (DATA_IMAGE_LIST, &multi_page);
+      if (had_saved_list)
+        file_name = multi_page.file_name;
+
+      gimp_get_data (DATA_OPTIMIZE, &optimize);
+      break;
+    }
+
+  validate_image_list ();
+
+  /* Starting the executions */
+  if (run_mode == GIMP_RUN_INTERACTIVE)
+    {
+      if (! gui_multi ())
         {
-          values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
-          gimp_message (_("You must select a file to save!"));
-          return;
+          return gimp_procedure_new_return_values (procedure,
+                                                   GIMP_PDB_CANCEL,
+                                                   NULL);
         }
     }
 
+  return pdf_save_image (procedure, FALSE, FALSE);
+}
+
+static cairo_status_t
+write_func (void                *fp,
+            const unsigned char *data,
+            unsigned int         size)
+{
+  return fwrite (data, 1, size, fp) == size ? CAIRO_STATUS_SUCCESS
+                                            : CAIRO_STATUS_WRITE_ERROR;
+}
+
+static GimpValueArray *
+pdf_save_image (GimpProcedure *procedure,
+                gboolean       single_image,
+                gboolean       defaults_proc)
+{
+  cairo_surface_t        *pdf_file;
+  cairo_t                *cr;
+  GimpExportCapabilities  capabilities;
+  FILE                   *fp;
+  gint                    i;
+  GError                 *error = NULL;
+
   fp = g_fopen (file_name, "wb");
-  if (fp == NULL)
+  if (! fp)
     {
-      *nreturn_vals = 2;
+      g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                   _("Could not open '%s' for writing: %s"),
+                   gimp_filename_to_utf8 (file_name), g_strerror (errno));
 
-      values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
-      values[1].type          = GIMP_PDB_STRING;
-      if (error == NULL)
-        {
-          g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                       _("Could not open '%s' for writing: %s"),
-                       gimp_filename_to_utf8 (file_name), g_strerror (errno));
-        }
-      values[1].data.d_string = error->message;
-      return;
+      return gimp_procedure_new_return_values (procedure,
+                                               GIMP_PDB_EXECUTION_ERROR,
+                                               error);
     }
 
   pdf_file = cairo_pdf_surface_create_for_stream (write_func, fp, 1, 1);
@@ -494,8 +663,9 @@ run (const gchar      *name,
                    "selected location isn't read only!"),
                  cairo_status_to_string (cairo_surface_status (pdf_file)));
 
-      values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
-      return;
+      return gimp_procedure_new_return_values (procedure,
+                                               GIMP_PDB_EXECUTION_ERROR,
+                                               error);
     }
 
   cr = cairo_create (pdf_file);
@@ -513,16 +683,16 @@ run (const gchar      *name,
 
   for (i = 0; i < multi_page.image_count; i++)
     {
-      gint32    image_ID = multi_page.images[i];
-      gint32   *layers;
-      gint32    n_layers;
-      gdouble   x_res, y_res;
-      gdouble   x_scale, y_scale;
-      gint32    temp;
-      gint      j;
-
-      temp = gimp_image_get_active_drawable (image_ID);
-      if (temp < 1)
+      GimpImage    *image = multi_page.images[i];
+      GimpLayer   **layers;
+      gint32        n_layers;
+      gdouble       x_res, y_res;
+      gdouble       x_scale, y_scale;
+      GimpDrawable *temp;
+      gint          j;
+
+      temp = gimp_image_get_active_drawable (image);
+      if (! temp)
         continue;
 
       /* Save the state of the surface before any changes, so that
@@ -530,7 +700,7 @@ run (const gchar      *name,
        */
       cairo_save (cr);
 
-      if (! (gimp_export_image (&image_ID, &temp, NULL,
+      if (! (gimp_export_image (&image, &temp, NULL,
                                 capabilities) == GIMP_EXPORT_EXPORT))
         {
           /* gimp_drawable_histogram() only works within the bounds of
@@ -539,17 +709,18 @@ run (const gchar      *name,
            * reselect, let's just always work on a duplicate of the
            * image.
            */
-          image_ID = gimp_image_duplicate (image_ID);
+          image = gimp_image_duplicate (image);
         }
-      gimp_selection_none (image_ID);
 
-      gimp_image_get_resolution (image_ID, &x_res, &y_res);
+      gimp_selection_none (image);
+
+      gimp_image_get_resolution (image, &x_res, &y_res);
       x_scale = 72.0 / x_res;
       y_scale = 72.0 / y_res;
 
       cairo_pdf_surface_set_size (pdf_file,
-                                  gimp_image_width (image_ID) * x_scale,
-                                  gimp_image_height (image_ID) * y_scale);
+                                  gimp_image_width  (image) * x_scale,
+                                  gimp_image_height (image) * y_scale);
 
       /* This way we set how many pixels are there in every inch.
        * It's very important for PangoCairo
@@ -565,19 +736,19 @@ run (const gchar      *name,
        */
       cairo_scale (cr, x_scale, y_scale);
 
-      layers = gimp_image_get_layers (image_ID, &n_layers);
+      layers = gimp_image_get_layers (image, &n_layers);
 
       /* Fill image with background color -
        * otherwise the output PDF will always show white for background,
        * and may display artifacts at transparency boundaries
        */
-      if (gimp_drawable_has_alpha (layers[n_layers - 1]))
+      if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layers[n_layers - 1])))
         {
           GimpRGB color;
 
           cairo_rectangle (cr, 0.0, 0.0,
-                           gimp_image_width (image_ID),
-                           gimp_image_height (image_ID));
+                           gimp_image_width  (image),
+                           gimp_image_height (image));
           gimp_context_get_background (&color);
           cairo_set_source_rgb (cr,
                                 color.r,
@@ -589,34 +760,34 @@ run (const gchar      *name,
       /* Now, we should loop over the layers of each image */
       for (j = 0; j < n_layers; j++)
         {
-          if (! draw_layer (layers, n_layers, j, cr, x_res, y_res, name, &error))
+          if (! draw_layer (layers, n_layers, j, cr, x_res, y_res,
+                            gimp_procedure_get_name (procedure),
+                            &error))
             {
-              *nreturn_vals = 2;
-
               /* free the resources */
               g_free (layers);
               cairo_surface_destroy (pdf_file);
               cairo_destroy (cr);
               fclose (fp);
 
-              values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
-
-              values[1].type          = GIMP_PDB_STRING;
-              values[1].data.d_string = error->message;
-              return;
+              return gimp_procedure_new_return_values (procedure,
+                                                       GIMP_PDB_EXECUTION_ERROR,
+                                                       error);
             }
         }
+
       g_free (layers);
 
       /* We are done with this image - Show it!
        * Unless that's a multi-page to avoid blank page at the end
        */
-      if (g_strcmp0 (name, SAVE2_PROC) != 0 ||
-          ! optimize.layers_as_pages)
+
+      if (! optimize.layers_as_pages)
         cairo_show_page (cr);
+
       cairo_restore (cr);
 
-      gimp_image_delete (image_ID);
+      gimp_image_delete (image);
     }
 
   /* We are done with all the images - time to free the resources */
@@ -633,134 +804,19 @@ run (const gchar      *name,
       g_strlcpy (multi_page.file_name, file_name, MAX_FILE_NAME_LENGTH);
       gimp_set_data (DATA_IMAGE_LIST, &multi_page, sizeof (multi_page));
     }
+
+  return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, error);
 }
 
 /******************************************************/
 /* Beginning of parameter handling functions          */
 /******************************************************/
 
-/* A function that takes care of loading the basic parameters
- */
-static gboolean
-init_vals (const gchar      *name,
-           gint              nparams,
-           const GimpParam  *param,
-           gboolean         *single_image,
-           gboolean         *defaults_proc,
-           GimpRunMode      *run_mode)
-{
-  gboolean had_saved_list = FALSE;
-  gboolean single;
-  gboolean defaults = FALSE;
-  gint32   i;
-  gint32   image;
-
-  if ((g_str_equal (name, SAVE_PROC) && nparams == SA_ARG_COUNT - 2) ||
-      (g_str_equal (name, SAVE2_PROC) && nparams == SA_ARG_COUNT))
-    {
-      GFile *file = g_file_new_for_uri (param[SA_FILENAME].data.d_string);
-
-      single = TRUE;
-      *run_mode = param[SA_RUN_MODE].data.d_int32;
-      image = param[SA_IMAGE].data.d_int32;
-      file_name = g_file_get_path (file);
-
-      if (*run_mode == GIMP_RUN_NONINTERACTIVE)
-        {
-          optimize.apply_masks = param[SA_APPLY_MASKS].data.d_int32;
-          optimize.vectorize = param[SA_VECTORIZE].data.d_int32;
-          optimize.ignore_hidden = param[SA_IGNORE_HIDDEN].data.d_int32;
-          if (nparams == SA_ARG_COUNT)
-          {
-            optimize.layers_as_pages = param[SA_LAYERS_AS_PAGES].data.d_int32;
-            optimize.reverse_order = param[SA_REVERSE_ORDER].data.d_int32;
-          }
-        }
-      else
-        defaults = TRUE;
-    }
-  else if (g_str_equal (name, SAVE_MULTI_PROC))
-    {
-      GFile *file = g_file_new_for_uri (param[SMA_FILENAME].data.d_string);
-
-      single = FALSE;
-      if (nparams != SMA_ARG_COUNT)
-        return FALSE;
-
-      *run_mode = param[SMA_RUN_MODE].data.d_int32;
-      image = -1;
-      file_name = g_file_get_path (file);
-
-      optimize.apply_masks = param[SMA_APPLY_MASKS].data.d_int32;
-      optimize.vectorize = param[SMA_VECTORIZE].data.d_int32;
-      optimize.ignore_hidden = param[SMA_IGNORE_HIDDEN].data.d_int32;
-    }
-  else
-    {
-      return FALSE;
-    }
-
-  switch (*run_mode)
-    {
-    case GIMP_RUN_NONINTERACTIVE:
-      if (single)
-        {
-          init_image_list_defaults (image);
-        }
-      else
-        {
-          multi_page.image_count = param[SMA_COUNT].data.d_int32;
-          if (param[SMA_IMAGES].data.d_int32array != NULL)
-            for (i = 0; i < param[SMA_COUNT].data.d_int32; i++)
-              multi_page.images[i] = param[SMA_IMAGES].data.d_int32array[i];
-        }
-      break;
-
-    case GIMP_RUN_INTERACTIVE:
-      /* Possibly retrieve data */
-      gimp_get_data (DATA_OPTIMIZE, &optimize);
-      had_saved_list = gimp_get_data (DATA_IMAGE_LIST, &multi_page);
-
-      if (had_saved_list && (file_name == NULL || strlen (file_name) == 0))
-        {
-          file_name = multi_page.file_name;
-        }
-
-      if (single || ! had_saved_list )
-        init_image_list_defaults (image);
-      break;
-
-    case GIMP_RUN_WITH_LAST_VALS:
-      /* Possibly retrieve data */
-      if (! single)
-        {
-          had_saved_list = gimp_get_data (DATA_IMAGE_LIST, &multi_page);
-          if (had_saved_list)
-            {
-              file_name = multi_page.file_name;
-            }
-        }
-      else
-        {
-          init_image_list_defaults (image);
-        }
-      gimp_get_data (DATA_OPTIMIZE, &optimize);
-      break;
-    }
-
-  *defaults_proc = defaults;
-  *single_image = single;
-
-  validate_image_list ();
-
-  return TRUE;
-}
-
 /* A function that initializes the image list to default values */
 static void
-init_image_list_defaults (gint32 image)
+init_image_list_defaults (GimpImage *image)
 {
-  if (image != -1)
+  if (image)
     {
       multi_page.images[0]   = image;
       multi_page.image_count = 1;
@@ -1083,16 +1139,16 @@ create_model (void)
    * up to multi_page.image_count are valid
    */
   model = gtk_list_store_new (4,
-                              GDK_TYPE_PIXBUF, /* THUMB */
-                              G_TYPE_STRING,   /* PAGE_NUMBER */
-                              G_TYPE_STRING,   /* IMAGE_NAME */
-                              G_TYPE_INT);     /* IMAGE_ID */
+                              GDK_TYPE_PIXBUF,  /* THUMB */
+                              G_TYPE_STRING,    /* PAGE_NUMBER */
+                              G_TYPE_STRING,    /* IMAGE_NAME */
+                              GIMP_TYPE_IMAGE); /* IMAGE */
 
   for (i = 0 ; i < multi_page.image_count && i < MAX_PAGE_COUNT ; i++)
     {
-      GtkTreeIter iter;
-      gint32      image = multi_page.images[i];
-      GdkPixbuf  *pixbuf;
+      GtkTreeIter  iter;
+      GimpImage   *image = multi_page.images[i];
+      GdkPixbuf   *pixbuf;
 
       pixbuf = gimp_image_get_thumbnail (image, THUMB_WIDTH, THUMB_HEIGHT,
                                          GIMP_PIXBUF_SMALL_CHECKS);
@@ -1102,7 +1158,7 @@ create_model (void)
                           THUMB,       pixbuf,
                           PAGE_NUMBER, g_strdup_printf (_("Page %d"), i + 1),
                           IMAGE_NAME,  gimp_image_get_name (image),
-                          IMAGE_ID,    image,
+                          IMAGE,       image,
                           -1);
 
       g_object_unref (pixbuf);
@@ -1126,13 +1182,16 @@ get_image_list (void)
        valid;
        valid = gtk_tree_model_iter_next (model, &iter))
     {
-      gint32 image;
+      GimpImage *image;
 
       gtk_tree_model_get (model, &iter,
-                          IMAGE_ID, &image,
+                          IMAGE, &image,
                           -1);
+
       multi_page.images[multi_page.image_count] = image;
       multi_page.image_count++;
+
+      g_object_unref (image);
     }
 
   if (multi_page.image_count == 0)
@@ -1154,12 +1213,14 @@ add_image_call (GtkWidget *widget,
 {
   GtkListStore *store;
   GtkTreeIter   iter;
-  gint32        image;
+  gint32        image_id;
+  GimpImage    *image;
   GdkPixbuf    *pixbuf;
 
   dnd_remove = FALSE;
 
-  gimp_int_combo_box_get_active (img_combo, &image);
+  gimp_int_combo_box_get_active (img_combo, &image_id);
+  image = gimp_image_get_by_id (image_id);
 
   store = GTK_LIST_STORE (model);
 
@@ -1172,7 +1233,7 @@ add_image_call (GtkWidget *widget,
                                                     multi_page.image_count+1),
                       THUMB,       pixbuf,
                       IMAGE_NAME,  gimp_image_get_name (image),
-                      IMAGE_ID,    image,
+                      IMAGE,       image,
                       -1);
 
   g_object_unref (pixbuf);
@@ -1278,9 +1339,9 @@ recount_pages (void)
 /******************************************************/
 
 static cairo_surface_t *
-get_cairo_surface (gint32     drawable_ID,
-                   gboolean   as_mask,
-                   GError   **error)
+get_cairo_surface (GimpDrawable  *drawable,
+                   gboolean       as_mask,
+                   GError       **error)
 {
   GeglBuffer      *src_buffer;
   GeglBuffer      *dest_buffer;
@@ -1290,14 +1351,14 @@ get_cairo_surface (gint32     drawable_ID,
   gint             width;
   gint             height;
 
-  src_buffer = gimp_drawable_get_buffer (drawable_ID);
+  src_buffer = gimp_drawable_get_buffer (drawable);
 
   width  = gegl_buffer_get_width  (src_buffer);
   height = gegl_buffer_get_height (src_buffer);
 
   if (as_mask)
     format = CAIRO_FORMAT_A8;
-  else if (gimp_drawable_has_alpha (drawable_ID))
+  else if (gimp_drawable_has_alpha (drawable))
     format = CAIRO_FORMAT_ARGB32;
   else
     format = CAIRO_FORMAT_RGB24;
@@ -1353,8 +1414,8 @@ get_cairo_surface (gint32     drawable_ID,
  * convert bitmaps to vector where possible
  */
 static GimpRGB
-get_layer_color (gint32    layer_ID,
-                 gboolean *single)
+get_layer_color (GimpLayer *layer,
+                 gboolean  *single)
 {
   GimpRGB col;
   gdouble red, green, blue, alpha;
@@ -1368,7 +1429,7 @@ get_layer_color (gint32    layer_ID,
   alpha = 0;
   dev = 0;
 
-  if (gimp_drawable_is_indexed (layer_ID))
+  if (gimp_drawable_is_indexed (GIMP_DRAWABLE (layer)))
     {
       /* FIXME: We can't do a proper histogram on indexed layers! */
       *single = FALSE;
@@ -1376,17 +1437,22 @@ get_layer_color (gint32    layer_ID,
       return col;
     }
 
-  if (gimp_drawable_bpp (layer_ID) >= 3)
+  if (gimp_drawable_bpp (GIMP_DRAWABLE (layer)) >= 3)
     {
       /* Are we in RGB mode? */
 
-      gimp_drawable_histogram (layer_ID, GIMP_HISTOGRAM_RED, 0.0, 1.0,
+      gimp_drawable_histogram (GIMP_DRAWABLE (layer),
+                               GIMP_HISTOGRAM_RED, 0.0, 1.0,
                                &red, &dev, &median, &pixels, &count, &precentile);
       devSum += dev;
-      gimp_drawable_histogram (layer_ID, GIMP_HISTOGRAM_GREEN, 0.0, 1.0,
+
+      gimp_drawable_histogram (GIMP_DRAWABLE (layer),
+                               GIMP_HISTOGRAM_GREEN, 0.0, 1.0,
                                &green, &dev, &median, &pixels, &count, &precentile);
       devSum += dev;
-      gimp_drawable_histogram (layer_ID, GIMP_HISTOGRAM_BLUE, 0.0, 1.0,
+
+      gimp_drawable_histogram (GIMP_DRAWABLE (layer),
+                               GIMP_HISTOGRAM_BLUE, 0.0, 1.0,
                                &blue, &dev, &median, &pixels, &count, &precentile);
       devSum += dev;
     }
@@ -1394,15 +1460,17 @@ get_layer_color (gint32    layer_ID,
     {
       /* We are in Grayscale mode (or Indexed) */
 
-      gimp_drawable_histogram (layer_ID, GIMP_HISTOGRAM_VALUE, 0.0, 1.0,
+      gimp_drawable_histogram (GIMP_DRAWABLE (layer),
+                               GIMP_HISTOGRAM_VALUE, 0.0, 1.0,
                                &red, &dev, &median, &pixels, &count, &precentile);
       devSum += dev;
       green = red;
       blue = red;
     }
 
-  if (gimp_drawable_has_alpha (layer_ID))
-    gimp_drawable_histogram (layer_ID, GIMP_HISTOGRAM_ALPHA, 0.0, 1.0,
+  if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
+    gimp_drawable_histogram (GIMP_DRAWABLE (layer),
+                             GIMP_HISTOGRAM_ALPHA, 0.0, 1.0,
                              &alpha, &dev, &median, &pixels, &count, &precentile);
   else
     alpha = 255;
@@ -1410,10 +1478,10 @@ get_layer_color (gint32    layer_ID,
   devSum += dev;
   *single = devSum == 0;
 
-  col.r = red/255;
-  col.g = green/255;
-  col.b = blue/255;
-  col.a = alpha/255;
+  col.r = red   / 255;
+  col.g = green / 255;
+  col.b = blue  / 255;
+  col.a = alpha / 255;
 
   return col;
 }
@@ -1424,15 +1492,15 @@ get_layer_color (gint32    layer_ID,
  * (freetype and pango differences)
  */
 static void
-drawText (gint32    text_id,
-          gdouble   opacity,
-          cairo_t  *cr,
-          gdouble   x_res,
-          gdouble   y_res)
+drawText (GimpLayer *layer,
+          gdouble    opacity,
+          cairo_t   *cr,
+          gdouble    x_res,
+          gdouble    y_res)
 {
-  GimpImageType         type   = gimp_drawable_type (text_id);
-  gchar                *text   = gimp_text_layer_get_text (text_id);
-  gchar                *markup = gimp_text_layer_get_markup (text_id);
+  GimpImageType         type   = gimp_drawable_type (GIMP_DRAWABLE (layer));
+  gchar                *text   = gimp_text_layer_get_text (layer);
+  gchar                *markup = gimp_text_layer_get_markup (layer);
   gchar                *font_family;
   gchar                *language;
   cairo_font_options_t *options;
@@ -1463,22 +1531,23 @@ drawText (gint32    text_id,
   cairo_get_font_options (cr, options);
 
   /* Position */
-  gimp_drawable_offsets (text_id, &x, &y);
+  gimp_drawable_offsets (GIMP_DRAWABLE (layer), &x, &y);
   cairo_translate (cr, x, y);
 
   /* Color */
   /* When dealing with a gray/indexed image, the viewed color of the text layer
    * can be different than the one kept in the memory */
   if (type == GIMP_RGBA_IMAGE)
-    gimp_text_layer_get_color (text_id, &color);
+    gimp_text_layer_get_color (layer, &color);
   else
-    gimp_image_pick_color (gimp_item_get_image (text_id),
-                           text_id, x, y, FALSE, FALSE, 0, &color);
+    gimp_image_pick_color (gimp_item_get_image (GIMP_ITEM (layer)),
+                           GIMP_DRAWABLE (layer), x, y, FALSE, FALSE, 0,
+                           &color);
 
   cairo_set_source_rgba (cr, color.r, color.g, color.b, opacity);
 
   /* Hinting */
-  hinting = gimp_text_layer_get_hint_style (text_id);
+  hinting = gimp_text_layer_get_hint_style (layer);
   switch (hinting)
     {
     case GIMP_TEXT_HINT_STYLE_NONE:
@@ -1499,7 +1568,7 @@ drawText (gint32    text_id,
     }
 
   /* Antialiasing */
-  if (gimp_text_layer_get_antialias (text_id))
+  if (gimp_text_layer_get_antialias (layer))
     cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_DEFAULT);
   else
     cairo_font_options_set_antialias (options, CAIRO_ANTIALIAS_NONE);
@@ -1517,13 +1586,13 @@ drawText (gint32    text_id,
   pango_cairo_context_set_font_options (context, options);
 
   /* Language */
-  language = gimp_text_layer_get_language (text_id);
+  language = gimp_text_layer_get_language (layer);
   if (language)
     pango_context_set_language (context,
                                 pango_language_from_string(language));
 
   /* Text Direction */
-  dir = gimp_text_layer_get_base_direction (text_id);
+  dir = gimp_text_layer_get_base_direction (layer);
 
   switch (dir)
     {
@@ -1571,7 +1640,7 @@ drawText (gint32    text_id,
   pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
 
   /* Font */
-  font_family = gimp_text_layer_get_font (text_id);
+  font_family = gimp_text_layer_get_font (layer);
 
   /* We need to find a way to convert GIMP's returned font name to a
    * normal Pango name... Hopefully GIMP 2.8 with Pango will fix it.
@@ -1579,7 +1648,7 @@ drawText (gint32    text_id,
   font_description = pango_font_description_from_string (font_family);
 
   /* Font Size */
-  size = gimp_text_layer_get_font_size (text_id, &unit);
+  size = gimp_text_layer_get_font_size (layer, &unit);
   size = gimp_units_to_pixels (size, unit, y_res);
   pango_font_description_set_absolute_size (font_description, size * PANGO_SCALE);
 
@@ -1587,13 +1656,17 @@ drawText (gint32    text_id,
 
   /* Width */
   if (! PANGO_GRAVITY_IS_VERTICAL (pango_context_get_base_gravity (context)))
-    pango_layout_set_width (layout, gimp_drawable_width (text_id) * PANGO_SCALE);
+    pango_layout_set_width (layout,
+                            gimp_drawable_width (GIMP_DRAWABLE (layer)) *
+                            PANGO_SCALE);
   else
-    pango_layout_set_width (layout, gimp_drawable_height (text_id) * PANGO_SCALE);
+    pango_layout_set_width (layout,
+                            gimp_drawable_height (GIMP_DRAWABLE (layer)) *
+                            PANGO_SCALE);
 
   /* Justification, and Alignment */
   justify = FALSE;
-  j = gimp_text_layer_get_justification (text_id);
+  j = gimp_text_layer_get_justification (layer);
   align = PANGO_ALIGN_LEFT;
   switch (j)
     {
@@ -1615,15 +1688,15 @@ drawText (gint32    text_id,
   pango_layout_set_justify (layout, justify);
 
   /* Indentation */
-  indent = gimp_text_layer_get_indent (text_id);
+  indent = gimp_text_layer_get_indent (layer);
   pango_layout_set_indent (layout, (int)(PANGO_SCALE * indent));
 
   /* Line Spacing */
-  line_spacing = gimp_text_layer_get_line_spacing (text_id);
+  line_spacing = gimp_text_layer_get_line_spacing (layer);
   pango_layout_set_spacing (layout, (int)(PANGO_SCALE * line_spacing));
 
   /* Letter Spacing */
-  letter_spacing = gimp_text_layer_get_letter_spacing (text_id);
+  letter_spacing = gimp_text_layer_get_letter_spacing (layer);
   letter_spacing_at = pango_attr_letter_spacing_new ((int)(PANGO_SCALE * letter_spacing));
   pango_attr_list_insert (attr_list, letter_spacing_at);
 
@@ -1640,14 +1713,14 @@ drawText (gint32    text_id,
   if (dir == GIMP_TEXT_DIRECTION_TTB_RTL ||
       dir == GIMP_TEXT_DIRECTION_TTB_RTL_UPRIGHT)
     {
-      cairo_translate (cr, gimp_drawable_width (text_id), 0);
+      cairo_translate (cr, gimp_drawable_width (GIMP_DRAWABLE (layer)), 0);
       cairo_rotate (cr, G_PI_2);
     }
 
   if (dir == GIMP_TEXT_DIRECTION_TTB_LTR ||
       dir == GIMP_TEXT_DIRECTION_TTB_LTR_UPRIGHT)
     {
-      cairo_translate (cr, 0, gimp_drawable_height (text_id));
+      cairo_translate (cr, 0, gimp_drawable_height (GIMP_DRAWABLE (layer)));
       cairo_rotate (cr, -G_PI_2);
     }
 
@@ -1668,7 +1741,7 @@ drawText (gint32    text_id,
 }
 
 static gboolean
-draw_layer (gint32       *layers,
+draw_layer (GimpLayer   **layers,
             gint          n_layers,
             gint          j,
             cairo_t      *cr,
@@ -1677,23 +1750,23 @@ draw_layer (gint32       *layers,
             const gchar  *name,
             GError      **error)
 {
-  gint32 layer_ID;
+  GimpLayer *layer;
 
   if (optimize.reverse_order && optimize.layers_as_pages)
-    layer_ID = layers [j];
+    layer = layers [j];
   else
-    layer_ID = layers [n_layers - j - 1];
+    layer = layers [n_layers - j - 1];
 
-  if (gimp_item_is_group (layer_ID))
+  if (gimp_item_is_group (GIMP_ITEM (layer)))
     {
-      gint *children;
-      gint  children_num;
-      gint  i;
+      GimpItem **children;
+      gint       children_num;
+      gint       i;
 
-      children = gimp_item_get_children (layer_ID, &children_num);
+      children = gimp_item_get_children (GIMP_ITEM (layer), &children_num);
       for (i = 0; i < children_num; i++)
         {
-          if (! draw_layer (children, children_num, i,
+          if (! draw_layer ((GimpLayer **) children, children_num, i,
                             cr, x_res, y_res, name, error))
             {
               g_free (children);
@@ -1705,38 +1778,40 @@ draw_layer (gint32       *layers,
   else
     {
       cairo_surface_t *mask_image = NULL;
-      gint32           mask_ID    = -1;
+      GimpLayerMask   *mask       = NULL;
       gdouble          opacity;
 
-      opacity = gimp_layer_get_opacity (layer_ID) / 100.0;
+      opacity = gimp_layer_get_opacity (layer) / 100.0;
 
-      if ((gimp_item_get_visible (layer_ID) && opacity > 0.0) ||
+      if ((gimp_item_get_visible (GIMP_ITEM (layer)) && opacity > 0.0) ||
           ! optimize.ignore_hidden)
         {
           gint x, y;
 
-          mask_ID = gimp_layer_get_mask (layer_ID);
-          if (mask_ID != -1)
+          mask = gimp_layer_get_mask (layer);
+          if (mask)
             {
-              mask_image = get_cairo_surface (mask_ID, TRUE, error);
+              mask_image = get_cairo_surface (GIMP_DRAWABLE (mask), TRUE,
+                                              error);
 
               if (*error)
                 return FALSE;
             }
-          gimp_drawable_offsets (layer_ID, &x, &y);
 
-          if (! gimp_item_is_text_layer (layer_ID))
+          gimp_drawable_offsets (GIMP_DRAWABLE (layer), &x, &y);
+
+          if (! gimp_item_is_text_layer (GIMP_ITEM (layer)))
             {
               /* For raster layers */
 
               GimpRGB  layer_color;
               gboolean single_color = FALSE;
 
-              layer_color = get_layer_color (layer_ID, &single_color);
+              layer_color = get_layer_color (layer, &single_color);
 
               cairo_rectangle (cr, x, y,
-                               gimp_drawable_width (layer_ID),
-                               gimp_drawable_height (layer_ID));
+                               gimp_drawable_width  (GIMP_DRAWABLE (layer)),
+                               gimp_drawable_height (GIMP_DRAWABLE (layer)));
 
               if (optimize.vectorize && single_color)
                 {
@@ -1745,7 +1820,7 @@ draw_layer (gint32       *layers,
                                          layer_color.g,
                                          layer_color.b,
                                          layer_color.a * opacity);
-                  if (mask_ID != -1)
+                  if (mask)
                     cairo_mask_surface (cr, mask_image, x, y);
                   else
                     cairo_fill (cr);
@@ -1754,7 +1829,8 @@ draw_layer (gint32       *layers,
                 {
                   cairo_surface_t *layer_image;
 
-                  layer_image = get_cairo_surface (layer_ID, FALSE, error);
+                  layer_image = get_cairo_surface (GIMP_DRAWABLE (layer), FALSE,
+                                                   error);
 
                   if (*error)
                     return FALSE;
@@ -1766,7 +1842,7 @@ draw_layer (gint32       *layers,
                   cairo_paint_with_alpha (cr, opacity);
                   cairo_pop_group_to_source (cr);
 
-                  if (mask_ID != -1)
+                  if (mask)
                     cairo_mask_surface (cr, mask_image, x, y);
                   else
                     cairo_paint (cr);
@@ -1779,15 +1855,16 @@ draw_layer (gint32       *layers,
           else
             {
               /* For text layers */
-              drawText (layer_ID, opacity, cr, x_res, y_res);
+              drawText (layer, opacity, cr, x_res, y_res);
             }
+
           /* draw new page if "layers as pages" option is checked */
-          if (optimize.layers_as_pages &&
-              g_strcmp0 (name, SAVE2_PROC) == 0)
+          if (optimize.layers_as_pages)
             cairo_show_page (cr);
         }
+
       /* We are done with the layer - time to free some resources */
-      if (mask_ID != -1)
+      if (mask)
         cairo_surface_destroy (mask_image);
     }
 
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index dd19c89f79..5d6923f192 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -39,7 +39,7 @@
     'file-png' => { ui => 1, gegl => 1, libs => 'PNG_LIBS', cflags => 'PNG_CFLAGS' },
     'file-pnm' => { ui => 1, gegl => 1 },
     'file-pdf-load' => { ui => 1, gegl => 1, libs => 'POPPLER_LIBS', cflags => 'POPPLER_CFLAGS' },
-    'file-pdf-save' => { ui => 1, gegl => 1, optional => 1, libs => 'CAIRO_PDF_LIBS', cflags => 
'CAIRO_PDF_CFLAGS', old_api => 1 },
+    'file-pdf-save' => { ui => 1, gegl => 1, optional => 1, libs => 'CAIRO_PDF_LIBS', cflags => 
'CAIRO_PDF_CFLAGS' },
     'file-ps' => { ui => 1, gegl => 1, optional => 1, libs => 'GS_LIBS' },
     'file-psp' => { ui => 1, gegl => 1, libs => 'Z_LIBS' },
     'file-raw-data' => { ui => 1, gegl => 1 },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]