~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/postscript.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 * PostScript file plugin
4
4
 * PostScript writing and GhostScript interfacing code
70
70
 */
71
71
#define VERSIO 1.17
72
72
static char dversio[] = "v1.17  19-Sep-2004";
73
 
static char ident[] = "@(#) GIMP PostScript/PDF file-plugin v1.17  19-Sep-2004";
74
73
 
75
74
#include "config.h"
76
75
 
77
76
#include <errno.h>
78
 
#include <stdio.h>
79
 
#include <stdlib.h>
80
77
#include <string.h>
81
78
#include <time.h>
82
79
 
86
83
#include <unistd.h>
87
84
#endif
88
85
 
 
86
#include <glib/gstdio.h>
 
87
 
89
88
#include <libgimp/gimp.h>
90
89
#include <libgimp/gimpui.h>
91
90
 
108
107
#endif
109
108
 
110
109
 
 
110
#define LOAD_PS_PROC         "file-ps-load"
 
111
#define LOAD_EPS_PROC        "file-eps-load"
 
112
#define LOAD_PDF_PROC        "file-pdf-load"
 
113
#define LOAD_PS_SETARGS_PROC "file-ps-load-setargs"
 
114
#define LOAD_PS_THUMB_PROC   "file-ps-load-thumb"
 
115
#define SAVE_PS_PROC         "file-ps-save"
 
116
#define SAVE_EPS_PROC        "file-eps-save"
 
117
#define PLUG_IN_BINARY       "postscript"
 
118
 
 
119
 
111
120
#define STR_LENGTH 64
112
121
 
113
122
#ifndef G_OS_WIN32
121
130
/* Load info */
122
131
typedef struct
123
132
{
124
 
  guint resolution;        /* resolution (dpi) at which to run ghostscript */
 
133
  guint resolution;        /* resolution (dpi) at which to run ghostscript */ 
125
134
  guint width, height;     /* desired size (ghostscript may ignore this) */
126
135
  gint  use_bbox;          /* 0: use width/height, 1: try to use BoundingBox */
127
136
  gchar pages[STR_LENGTH]; /* Pages to load (eg.: 1,3,5-7) */
141
150
  1            /* dont use graphics antialiasing */
142
151
};
143
152
 
144
 
 
 
153
/* Widgets for width and height of postscript image to
 
154
*  be loaded, so that they can be updated when desired resolution is
 
155
*  changed
 
156
*/
 
157
GtkWidget      *ps_width_spinbutton;
 
158
GtkWidget      *ps_height_spinbutton;
 
159
    
145
160
/* Save info  */
146
161
typedef struct
147
162
{
198
213
                                gint32             drawable_ID);
199
214
 
200
215
static gint32 create_new_image (const gchar       *filename,
201
 
                                guint              pagenum,
202
 
                                guint              width,
203
 
                                guint              height,
204
 
                                GimpImageBaseType  type,
205
 
                                gint32            *layer_ID,
206
 
                                GimpDrawable     **drawable,
207
 
                                GimpPixelRgn      *pixel_rgn);
 
216
                                guint              pagenum,
 
217
                                guint              width,
 
218
                                guint              height,
 
219
                                GimpImageBaseType  type,
 
220
                                gint32            *layer_ID,
 
221
                                GimpDrawable     **drawable,
 
222
                                GimpPixelRgn      *pixel_rgn);
208
223
 
209
224
static void   check_load_vals  (void);
210
225
static void   check_save_vals  (void);
250
265
static void   save_ps_trailer  (FILE              *ofp);
251
266
static void   save_ps_preview  (FILE              *ofp,
252
267
                                gint32             drawable_ID);
253
 
static void   dither_grey      (guchar            *grey,
 
268
static void   dither_grey      (const guchar      *grey,
254
269
                                guchar            *bw,
255
270
                                gint               npix,
256
271
                                gint               linecount);
258
273
 
259
274
/* Dialog-handling */
260
275
 
261
 
static gboolean  load_dialog               (void);
262
 
static void      load_pages_entry_callback (GtkWidget *widget,
263
 
                                            gpointer   data);
 
276
static gint32    count_ps_pages             (const gchar *filename);
 
277
static gboolean  load_dialog                (const gchar *filename,
 
278
                                             gboolean     loadPDF);
 
279
static void      load_pages_entry_callback  (GtkWidget   *widget,
 
280
                                             gpointer     data);
 
281
                                                
 
282
static gboolean  resolution_change_callback (GtkAdjustment *adjustment,
 
283
                                             gpointer   data);
264
284
 
265
285
typedef struct
266
286
{
272
292
static void      save_unit_toggle_update  (GtkWidget *widget,
273
293
                                           gpointer   data);
274
294
 
275
 
GimpPlugInInfo PLUG_IN_INFO =
 
295
const GimpPlugInInfo PLUG_IN_INFO =
276
296
{
277
297
  NULL,  /* init_proc  */
278
298
  NULL,  /* quit_proc  */
290
310
                               unsigned char *dst);
291
311
 
292
312
 
293
 
static guint32 ascii85_buf;
294
 
static int ascii85_len = 0;
295
 
static int ascii85_linewidth = 0;
 
313
static guint32  ascii85_buf       = 0;
 
314
static gint     ascii85_len       = 0;
 
315
static gint     ascii85_linewidth = 0;
 
316
 
 
317
static GimpPageSelectorTarget ps_pagemode = GIMP_PAGE_SELECTOR_TARGET_LAYERS;
296
318
 
297
319
static void
298
320
ascii85_init (void)
335
357
          putc ('\n', ofp);
336
358
          ascii85_linewidth = 0;
337
359
        }
338
 
        putc (c[i], ofp);
 
360
        putc (c[i], ofp);
339
361
        ascii85_linewidth++;
340
362
      }
341
363
    }
497
519
   end_data = ftell (ofp);
498
520
   if (end_data > 0)
499
521
   {
500
 
     sprintf (s, "%ld ASCII Bytes", end_data-ps_data_pos.begin_data);
 
522
     sprintf (s, "%ld ASCII Bytes", end_data - ps_data_pos.begin_data);
501
523
     if (fseek (ofp, ps_data_pos.eol - strlen (s), SEEK_SET) == 0)
502
524
     {
503
525
       fprintf (ofp, "%s", s);
514
536
static void
515
537
query (void)
516
538
{
517
 
  static GimpParamDef load_args[] =
 
539
  static const GimpParamDef load_args[] =
518
540
  {
519
 
    { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
520
 
    { GIMP_PDB_STRING, "filename", "The name of the file to load" },
521
 
    { GIMP_PDB_STRING, "raw_filename", "The name of the file to load" }
 
541
    { GIMP_PDB_INT32,  "run-mode",     "Interactive, non-interactive" },
 
542
    { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
 
543
    { GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
522
544
  };
523
 
  static GimpParamDef load_return_vals[] =
 
545
  static const GimpParamDef load_return_vals[] =
524
546
  {
525
547
    { GIMP_PDB_IMAGE, "image", "Output image" }
526
548
  };
527
549
 
528
 
  static GimpParamDef set_load_args[] =
 
550
  static const GimpParamDef set_load_args[] =
529
551
  {
530
 
    { GIMP_PDB_INT32, "resolution", "Resolution to interprete image (dpi)" },
531
 
    { GIMP_PDB_INT32, "width", "Desired width" },
532
 
    { GIMP_PDB_INT32, "height", "Desired height" },
533
 
    { GIMP_PDB_INT32, "check_bbox", "0: Use width/height, 1: Use BoundingBox" },
534
 
    { GIMP_PDB_STRING, "pages", "Pages to load (e.g.: 1,3,5-7)" },
535
 
    { GIMP_PDB_INT32, "coloring", "4: b/w, 5: grey, 6: colour image, 7: automatic" },
536
 
    { GIMP_PDB_INT32, "TextAlphaBits", "1, 2, or 4" },
537
 
    { GIMP_PDB_INT32, "GraphicsAlphaBits", "1, 2, or 4" }
 
552
    { GIMP_PDB_INT32,  "resolution", "Resolution to interprete image (dpi)"    },
 
553
    { GIMP_PDB_INT32,  "width",      "Desired width"                           },
 
554
    { GIMP_PDB_INT32,  "height",     "Desired height"                          },
 
555
    { GIMP_PDB_INT32,  "check-bbox", "0: Use width/height, 1: Use BoundingBox" },
 
556
    { GIMP_PDB_STRING, "pages",      "Pages to load (e.g.: 1,3,5-7)"           },
 
557
    { GIMP_PDB_INT32,  "coloring",   "4: b/w, 5: grey, 6: colour image, 7: automatic" },
 
558
    { GIMP_PDB_INT32,  "TextAlphaBits",     "1, 2, or 4" },
 
559
    { GIMP_PDB_INT32,  "GraphicsAlphaBits", "1, 2, or 4" }
538
560
  };
539
561
 
540
 
  static GimpParamDef thumb_args[] =
 
562
  static const GimpParamDef thumb_args[] =
541
563
  {
542
564
    { GIMP_PDB_STRING, "filename",     "The name of the file to load"  },
543
 
    { GIMP_PDB_INT32,  "thumb_size",   "Preferred thumbnail size"      }
 
565
    { GIMP_PDB_INT32,  "thumb-size",   "Preferred thumbnail size"      }
544
566
  };
545
 
  static GimpParamDef thumb_return_vals[] =
 
567
  static const GimpParamDef thumb_return_vals[] =
546
568
  {
547
569
    { GIMP_PDB_IMAGE, "image",         "Output image" }
548
570
  };
549
571
 
550
 
  static GimpParamDef save_args[] =
 
572
  static const GimpParamDef save_args[] =
551
573
  {
552
 
    { GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
553
 
    { GIMP_PDB_IMAGE, "image", "Input image" },
554
 
    { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" },
555
 
    { GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
556
 
    { GIMP_PDB_STRING, "raw_filename",
557
 
            "The name of the file to save the image in" },
558
 
    { GIMP_PDB_FLOAT, "width", "Width of the image in PostScript file (0: use input image size)" },
559
 
    { GIMP_PDB_FLOAT, "height", "Height of image in PostScript file (0: use input image size)" },
560
 
    { GIMP_PDB_FLOAT, "x_offset", "X-offset to image from lower left corner" },
561
 
    { GIMP_PDB_FLOAT, "y_offset", "Y-offset to image from lower left corner" },
562
 
    { GIMP_PDB_INT32, "unit", "Unit for width/height/offset. 0: inches, 1: millimeters" },
563
 
    { GIMP_PDB_INT32, "keep_ratio", "0: use width/height, 1: keep aspect ratio" },
564
 
    { GIMP_PDB_INT32, "rotation", "0, 90, 180, 270" },
565
 
    { GIMP_PDB_INT32, "eps_flag", "0: PostScript, 1: Encapsulated PostScript" },
566
 
    { GIMP_PDB_INT32, "preview", "0: no preview, >0: max. size of preview" },
567
 
    { GIMP_PDB_INT32, "level", "1: PostScript Level 1, 2: PostScript Level 2" }
 
574
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
 
575
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
 
576
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
 
577
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
 
578
    { GIMP_PDB_STRING,   "raw-filename", "The name of the file to save the image in" },
 
579
    { GIMP_PDB_FLOAT,    "width",        "Width of the image in PostScript file (0: use input image size)" },
 
580
    { GIMP_PDB_FLOAT,    "height",       "Height of image in PostScript file (0: use input image size)" },
 
581
    { GIMP_PDB_FLOAT,    "x-offset",     "X-offset to image from lower left corner" },
 
582
    { GIMP_PDB_FLOAT,    "y-offset",     "Y-offset to image from lower left corner" },
 
583
    { GIMP_PDB_INT32,    "unit",         "Unit for width/height/offset. 0: inches, 1: millimeters" },
 
584
    { GIMP_PDB_INT32,    "keep-ratio",   "0: use width/height, 1: keep aspect ratio" },
 
585
    { GIMP_PDB_INT32,    "rotation",     "0, 90, 180, 270" },
 
586
    { GIMP_PDB_INT32,    "eps-flag",     "0: PostScript, 1: Encapsulated PostScript" },
 
587
    { GIMP_PDB_INT32,    "preview",      "0: no preview, >0: max. size of preview" },
 
588
    { GIMP_PDB_INT32,    "level",        "1: PostScript Level 1, 2: PostScript Level 2" }
568
589
  };
569
590
 
570
 
  gimp_install_procedure ("file_ps_load",
 
591
  gimp_install_procedure (LOAD_PS_PROC,
571
592
                          "load PostScript documents",
572
593
                          "load PostScript documents",
573
594
                          "Peter Kirchgessner <peter@kirchgessner.net>",
580
601
                          G_N_ELEMENTS (load_return_vals),
581
602
                          load_args, load_return_vals);
582
603
 
583
 
  gimp_register_file_handler_mime ("file_ps_load", "application/postscript");
584
 
  gimp_register_magic_load_handler ("file_ps_load",
585
 
                                    "ps",
586
 
                                    "",
 
604
  gimp_register_file_handler_mime (LOAD_PS_PROC, "application/postscript");
 
605
  gimp_register_magic_load_handler (LOAD_PS_PROC,
 
606
                                    "ps",
 
607
                                    "",
587
608
                                    "0,string,%!,0,long,0xc5d0d3c6");
588
609
 
589
 
  gimp_install_procedure ("file_eps_load",
 
610
  gimp_install_procedure (LOAD_EPS_PROC,
590
611
                          "load Encapsulated PostScript images",
591
612
                          "load Encapsulated PostScript images",
592
613
                          "Peter Kirchgessner <peter@kirchgessner.net>",
599
620
                          G_N_ELEMENTS (load_return_vals),
600
621
                          load_args, load_return_vals);
601
622
 
602
 
  gimp_register_file_handler_mime ("file_eps_load", "image/x-eps");
603
 
  gimp_register_magic_load_handler ("file_eps_load",
604
 
                                    "eps",
605
 
                                    "",
 
623
  gimp_register_file_handler_mime (LOAD_EPS_PROC, "image/x-eps");
 
624
  gimp_register_magic_load_handler (LOAD_EPS_PROC,
 
625
                                    "eps",
 
626
                                    "",
606
627
                                    "0,string,%!,0,long,0xc5d0d3c6");
607
628
 
608
 
  gimp_install_procedure ("file_pdf_load",
 
629
#ifndef HAVE_POPPLER
 
630
  gimp_install_procedure (LOAD_PDF_PROC,
609
631
                          "load PDF documents",
610
632
                          "load PDF documents",
611
633
                          "Peter Kirchgessner <peter@kirchgessner.net>",
618
640
                          G_N_ELEMENTS (load_return_vals),
619
641
                          load_args, load_return_vals);
620
642
 
621
 
  gimp_register_file_handler_mime ("file_pdf_load", "application/pdf");
622
 
  gimp_register_magic_load_handler ("file_pdf_load",
623
 
                                    "pdf",
624
 
                                    "",
 
643
  gimp_register_file_handler_mime (LOAD_PDF_PROC, "application/pdf");
 
644
  gimp_register_magic_load_handler (LOAD_PDF_PROC,
 
645
                                    "pdf",
 
646
                                    "",
625
647
                                    "0,string,%PDF");
 
648
#endif
626
649
 
627
 
  gimp_install_procedure ("file_ps_load_setargs",
628
 
                          "set additional parameters for procedure file_ps_load",
629
 
                          "set additional parameters for procedure file_ps_load",
 
650
  gimp_install_procedure (LOAD_PS_SETARGS_PROC,
 
651
                          "set additional parameters for procedure file-ps-load",
 
652
                          "set additional parameters for procedure file-ps-load",
630
653
                          "Peter Kirchgessner <peter@kirchgessner.net>",
631
654
                          "Peter Kirchgessner",
632
655
                          dversio,
636
659
                          G_N_ELEMENTS (set_load_args), 0,
637
660
                          set_load_args, NULL);
638
661
 
639
 
  gimp_install_procedure ("file_ps_load_thumb",
640
 
                          "Loads a small preview from a Postscript or PDF document",
 
662
  gimp_install_procedure (LOAD_PS_THUMB_PROC,
 
663
                          "Loads a small preview from a PostScript or PDF document",
641
664
                          "",
642
665
                          "Peter Kirchgessner <peter@kirchgessner.net>",
643
666
                          "Peter Kirchgessner",
644
667
                          dversio,
645
 
                          NULL,
646
 
                          NULL,
 
668
                          NULL,
 
669
                          NULL,
647
670
                          GIMP_PLUGIN,
648
671
                          G_N_ELEMENTS (thumb_args),
649
672
                          G_N_ELEMENTS (thumb_return_vals),
650
673
                          thumb_args, thumb_return_vals);
651
674
 
652
 
  gimp_register_thumbnail_loader ("file_ps_load",  "file_ps_load_thumb");
653
 
  gimp_register_thumbnail_loader ("file_eps_load", "file_ps_load_thumb");
654
 
  gimp_register_thumbnail_loader ("file_pdf_load", "file_ps_load_thumb");
655
 
 
656
 
  gimp_install_procedure ("file_ps_save",
 
675
  gimp_register_thumbnail_loader (LOAD_PS_PROC,  LOAD_PS_THUMB_PROC);
 
676
  gimp_register_thumbnail_loader (LOAD_EPS_PROC, LOAD_PS_THUMB_PROC);
 
677
 
 
678
#ifndef HAVE_POPPLER
 
679
  gimp_register_thumbnail_loader (LOAD_PDF_PROC, LOAD_PS_THUMB_PROC);
 
680
#endif
 
681
 
 
682
  gimp_install_procedure (SAVE_PS_PROC,
657
683
                          "save image as PostScript docuement",
658
 
                          "PostScript saving handles all image types except those with alpha channels.",
 
684
                          "PostScript saving handles all image types except "
 
685
                          "those with alpha channels.",
659
686
                          "Peter Kirchgessner <peter@kirchgessner.net>",
660
687
                          "Peter Kirchgessner",
661
688
                          dversio,
665
692
                          G_N_ELEMENTS (save_args), 0,
666
693
                          save_args, NULL);
667
694
 
668
 
  gimp_register_file_handler_mime ("file_ps_save", "application/postscript");
669
 
  gimp_register_save_handler ("file_ps_save", "ps", "");
 
695
  gimp_register_file_handler_mime (SAVE_PS_PROC, "application/postscript");
 
696
  gimp_register_save_handler (SAVE_PS_PROC, "ps", "");
670
697
 
671
 
  gimp_install_procedure ("file_eps_save",
 
698
  gimp_install_procedure (SAVE_EPS_PROC,
672
699
                          "save image as Encapsulated PostScript image",
673
 
                          "PostScript saving handles all image types except those with alpha channels.",
 
700
                          "PostScript saving handles all image types except "
 
701
                          "those with alpha channels.",
674
702
                          "Peter Kirchgessner <peter@kirchgessner.net>",
675
703
                          "Peter Kirchgessner",
676
704
                          dversio,
680
708
                          G_N_ELEMENTS (save_args), 0,
681
709
                          save_args, NULL);
682
710
 
683
 
  gimp_register_file_handler_mime ("file_eps_save", "application/x-eps");
684
 
  gimp_register_save_handler ("file_eps_save", "eps", "");
 
711
  gimp_register_file_handler_mime (SAVE_EPS_PROC, "application/x-eps");
 
712
  gimp_register_save_handler (SAVE_EPS_PROC, "eps", "");
685
713
}
686
714
 
687
715
static void
747
775
  values[0].type          = GIMP_PDB_STATUS;
748
776
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
749
777
 
750
 
  if (strcmp (name, "file_ps_load")  == 0  ||
751
 
      strcmp (name, "file_eps_load") == 0  ||
752
 
      strcmp (name, "file_pdf_load") == 0)
 
778
  if (strcmp (name, LOAD_PS_PROC)  == 0  ||
 
779
      strcmp (name, LOAD_EPS_PROC) == 0  ||
 
780
      strcmp (name, LOAD_PDF_PROC) == 0)
753
781
    {
754
782
      switch (run_mode)
755
 
        {
 
783
        {
756
784
        case GIMP_RUN_INTERACTIVE:
757
785
          /*  Possibly retrieve data  */
758
 
          gimp_get_data ("file_ps_load", &plvals);
 
786
          gimp_get_data (LOAD_PS_PROC, &plvals);
759
787
 
760
 
          if (! load_dialog ())
761
 
            status = GIMP_PDB_CANCEL;
 
788
          if (! load_dialog (param[1].data.d_string,
 
789
                             ! strcmp (name, LOAD_PDF_PROC)))
 
790
            status = GIMP_PDB_CANCEL;
762
791
          break;
763
792
 
764
793
        case GIMP_RUN_NONINTERACTIVE:
766
795
          if (nparams != 3)
767
796
            status = GIMP_PDB_CALLING_ERROR;
768
797
          else    /* Get additional interpretation arguments */
769
 
            gimp_get_data ("file_ps_load", &plvals);
 
798
            gimp_get_data (LOAD_PS_PROC, &plvals);
770
799
          break;
771
800
 
772
801
        case GIMP_RUN_WITH_LAST_VALS:
773
802
          /* Possibly retrieve data */
774
 
          gimp_get_data ("file_ps_load", &plvals);
 
803
          gimp_get_data (LOAD_PS_PROC, &plvals);
775
804
          break;
776
805
 
777
806
        default:
778
807
          break;
779
 
        }
 
808
        }
780
809
 
781
810
      if (status == GIMP_PDB_SUCCESS)
782
 
        {
783
 
          check_load_vals ();
784
 
          image_ID = load_image (param[1].data.d_string);
 
811
        {
 
812
          check_load_vals ();
 
813
          image_ID = load_image (param[1].data.d_string);
785
814
 
786
 
          if (image_ID != -1)
787
 
            {
788
 
              *nreturn_vals = 2;
789
 
              values[1].type         = GIMP_PDB_IMAGE;
790
 
              values[1].data.d_image = image_ID;
791
 
            }
792
 
          else
793
 
            {
794
 
              status = GIMP_PDB_EXECUTION_ERROR;
795
 
            }
796
 
        }
 
815
          if (image_ID != -1)
 
816
            {
 
817
              *nreturn_vals = 2;
 
818
              values[1].type         = GIMP_PDB_IMAGE;
 
819
              values[1].data.d_image = image_ID;
 
820
            }
 
821
          else
 
822
            {
 
823
              status = GIMP_PDB_EXECUTION_ERROR;
 
824
            }
 
825
        }
797
826
 
798
827
      /*  Store plvals data  */
799
828
      if (status == GIMP_PDB_SUCCESS)
800
 
        gimp_set_data ("file_ps_load", &plvals, sizeof (PSLoadVals));
 
829
        gimp_set_data (LOAD_PS_PROC, &plvals, sizeof (PSLoadVals));
801
830
    }
802
 
  else if (strcmp (name, "file_ps_load_thumb") == 0)
 
831
  else if (strcmp (name, LOAD_PS_THUMB_PROC) == 0)
803
832
    {
804
833
      if (nparams < 2)
805
834
        {
824
853
 
825
854
          if (image_ID != -1)
826
855
            {
827
 
              *nreturn_vals = 2;
828
 
              values[1].type         = GIMP_PDB_IMAGE;
829
 
              values[1].data.d_image = image_ID;
 
856
              *nreturn_vals = 2;
 
857
              values[1].type         = GIMP_PDB_IMAGE;
 
858
              values[1].data.d_image = image_ID;
830
859
            }
831
860
          else
832
861
            {
834
863
            }
835
864
        }
836
865
    }
837
 
  else if (strcmp (name, "file_ps_save")  == 0 ||
838
 
           strcmp (name, "file_eps_save") == 0)
 
866
  else if (strcmp (name, SAVE_PS_PROC)  == 0 ||
 
867
           strcmp (name, SAVE_EPS_PROC) == 0)
839
868
    {
840
 
      psvals.eps = strcmp (name, "file_ps_save");
 
869
      psvals.eps = strcmp (name, SAVE_PS_PROC);
841
870
 
842
871
      image_ID = orig_image_ID = param[1].data.d_int32;
843
872
      drawable_ID = param[2].data.d_int32;
844
873
 
845
874
      /* eventually export the image */
846
875
      switch (run_mode)
847
 
        {
848
 
        case GIMP_RUN_INTERACTIVE:
849
 
        case GIMP_RUN_WITH_LAST_VALS:
850
 
          gimp_ui_init ("ps", FALSE);
851
 
          export = gimp_export_image (&image_ID, &drawable_ID,
 
876
        {
 
877
        case GIMP_RUN_INTERACTIVE:
 
878
        case GIMP_RUN_WITH_LAST_VALS:
 
879
          gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
880
          export = gimp_export_image (&image_ID, &drawable_ID,
852
881
                                      psvals.eps ? "EPS" : "PostScript",
853
 
                                      (GIMP_EXPORT_CAN_HANDLE_RGB |
854
 
                                       GIMP_EXPORT_CAN_HANDLE_GRAY |
855
 
                                       GIMP_EXPORT_CAN_HANDLE_INDEXED));
856
 
          if (export == GIMP_EXPORT_CANCEL)
857
 
            {
858
 
              values[0].data.d_status = GIMP_PDB_CANCEL;
859
 
              return;
860
 
            }
861
 
          break;
862
 
        default:
863
 
          break;
864
 
        }
 
882
                                      (GIMP_EXPORT_CAN_HANDLE_RGB |
 
883
                                       GIMP_EXPORT_CAN_HANDLE_GRAY |
 
884
                                       GIMP_EXPORT_CAN_HANDLE_INDEXED));
 
885
          if (export == GIMP_EXPORT_CANCEL)
 
886
            {
 
887
              values[0].data.d_status = GIMP_PDB_CANCEL;
 
888
              return;
 
889
            }
 
890
          break;
 
891
        default:
 
892
          break;
 
893
        }
865
894
 
866
895
      switch (run_mode)
867
896
        {
879
908
        case GIMP_RUN_NONINTERACTIVE:
880
909
          /*  Make sure all the arguments are there!  */
881
910
          if (nparams != 15)
882
 
            {
883
 
              status = GIMP_PDB_CALLING_ERROR;
884
 
            }
 
911
            {
 
912
              status = GIMP_PDB_CALLING_ERROR;
 
913
            }
885
914
          else
886
 
            {
887
 
              psvals.width        = param[5].data.d_float;
888
 
              psvals.height       = param[6].data.d_float;
889
 
              psvals.x_offset     = param[7].data.d_float;
890
 
              psvals.y_offset     = param[8].data.d_float;
891
 
              psvals.unit_mm      = (param[9].data.d_int32 != 0);
892
 
              psvals.keep_ratio   = (param[10].data.d_int32 != 0);
893
 
              psvals.rotate       = param[11].data.d_int32;
894
 
              psvals.eps          = param[12].data.d_int32;
895
 
              psvals.preview      = (param[13].data.d_int32 != 0);
896
 
              psvals.preview_size = param[13].data.d_int32;
897
 
              psvals.level        = param[14].data.d_int32;
898
 
            }
 
915
            {
 
916
              psvals.width        = param[5].data.d_float;
 
917
              psvals.height       = param[6].data.d_float;
 
918
              psvals.x_offset     = param[7].data.d_float;
 
919
              psvals.y_offset     = param[8].data.d_float;
 
920
              psvals.unit_mm      = (param[9].data.d_int32 != 0);
 
921
              psvals.keep_ratio   = (param[10].data.d_int32 != 0);
 
922
              psvals.rotate       = param[11].data.d_int32;
 
923
              psvals.eps          = param[12].data.d_int32;
 
924
              psvals.preview      = (param[13].data.d_int32 != 0);
 
925
              psvals.preview_size = param[13].data.d_int32;
 
926
              psvals.level        = param[14].data.d_int32;
 
927
            }
899
928
          break;
900
929
 
901
930
        case GIMP_RUN_WITH_LAST_VALS:
908
937
        }
909
938
 
910
939
      if (status == GIMP_PDB_SUCCESS)
911
 
        {
912
 
          if ((psvals.width == 0.0) || (psvals.height == 0.0))
913
 
            ps_set_save_size (&psvals, orig_image_ID);
 
940
        {
 
941
          if ((psvals.width == 0.0) || (psvals.height == 0.0))
 
942
            ps_set_save_size (&psvals, orig_image_ID);
914
943
 
915
 
          check_save_vals ();
916
 
          if (save_image (param[3].data.d_string, image_ID, drawable_ID))
917
 
            {
918
 
              /*  Store psvals data  */
919
 
              gimp_set_data (name, &psvals, sizeof (PSSaveVals));
920
 
            }
921
 
          else
922
 
            {
923
 
              status = GIMP_PDB_EXECUTION_ERROR;
924
 
            }
925
 
        }
 
944
          check_save_vals ();
 
945
          if (save_image (param[3].data.d_string, image_ID, drawable_ID))
 
946
            {
 
947
              /*  Store psvals data  */
 
948
              gimp_set_data (name, &psvals, sizeof (PSSaveVals));
 
949
            }
 
950
          else
 
951
            {
 
952
              status = GIMP_PDB_EXECUTION_ERROR;
 
953
            }
 
954
        }
926
955
 
927
956
      if (export == GIMP_EXPORT_EXPORT)
928
 
        gimp_image_delete (image_ID);
 
957
        gimp_image_delete (image_ID);
929
958
    }
930
 
  else if (strcmp (name, "file_ps_load_setargs") == 0)
 
959
  else if (strcmp (name, LOAD_PS_SETARGS_PROC) == 0)
931
960
    {
932
961
      /*  Make sure all the arguments are there!  */
933
962
      if (nparams != 8)
934
 
        {
935
 
          status = GIMP_PDB_CALLING_ERROR;
936
 
        }
 
963
        {
 
964
          status = GIMP_PDB_CALLING_ERROR;
 
965
        }
937
966
      else
938
 
        {
939
 
          plvals.resolution = param[0].data.d_int32;
940
 
          plvals.width      = param[1].data.d_int32;
941
 
          plvals.height     = param[2].data.d_int32;
942
 
          plvals.use_bbox   = param[3].data.d_int32;
943
 
          if (param[4].data.d_string != NULL)
944
 
            strncpy (plvals.pages, param[4].data.d_string,
945
 
                     sizeof (plvals.pages));
946
 
          else
947
 
            plvals.pages[0] = '\0';
948
 
          plvals.pages[sizeof (plvals.pages) - 1] = '\0';
949
 
          plvals.pnm_type      = param[5].data.d_int32;
950
 
          plvals.textalpha     = param[6].data.d_int32;
951
 
          plvals.graphicsalpha = param[7].data.d_int32;
952
 
          check_load_vals ();
953
 
          gimp_set_data ("file_ps_load", &plvals, sizeof (PSLoadVals));
954
 
        }
 
967
        {
 
968
          plvals.resolution = param[0].data.d_int32;
 
969
          plvals.width      = param[1].data.d_int32;
 
970
          plvals.height     = param[2].data.d_int32;
 
971
          plvals.use_bbox   = param[3].data.d_int32;
 
972
          if (param[4].data.d_string != NULL)
 
973
            strncpy (plvals.pages, param[4].data.d_string,
 
974
                     sizeof (plvals.pages));
 
975
          else
 
976
            plvals.pages[0] = '\0';
 
977
          plvals.pages[sizeof (plvals.pages) - 1] = '\0';
 
978
          plvals.pnm_type      = param[5].data.d_int32;
 
979
          plvals.textalpha     = param[6].data.d_int32;
 
980
          plvals.graphicsalpha = param[7].data.d_int32;
 
981
          check_load_vals ();
 
982
 
 
983
          gimp_set_data (LOAD_PS_PROC, &plvals, sizeof (PSLoadVals));
 
984
        }
955
985
    }
956
986
  else
957
987
    {
965
995
static gint32
966
996
load_image (const gchar *filename)
967
997
{
968
 
  gint32 image_ID, *image_list, *nl;
969
 
  guint page_count;
970
 
  gint  ChildPid;
971
 
  FILE *ifp;
972
 
  char *temp;
973
 
  int  llx, lly, urx, ury;
974
 
  int  k, n_images, max_images, max_pagenum;
975
 
  int  is_epsf;
 
998
  gint32  image_ID = 0;
 
999
  gint32 *image_list, *nl;
 
1000
  guint   page_count;
 
1001
  gint    ChildPid;
 
1002
  FILE   *ifp;
 
1003
  char   *temp;
 
1004
  int     llx, lly, urx, ury;
 
1005
  int     k, n_images, max_images, max_pagenum;
 
1006
  int     is_epsf;
976
1007
 
977
1008
#ifdef PS_DEBUG
978
1009
  g_print ("load_image:\n resolution = %d\n", plvals.resolution);
984
1015
#endif
985
1016
 
986
1017
  /* Try to see if PostScript file is available */
987
 
  ifp = fopen (filename, "r");
 
1018
  ifp = g_fopen (filename, "r");
988
1019
  if (ifp == NULL)
989
1020
    {
990
1021
      g_message (_("Could not open '%s' for reading: %s"),
993
1024
    }
994
1025
  fclose (ifp);
995
1026
 
996
 
  temp = g_strdup_printf (_("Opening '%s'..."),
997
 
                          gimp_filename_to_utf8 (filename));
998
 
  gimp_progress_init (temp);
999
 
  g_free (temp);
 
1027
  gimp_progress_init_printf (_("Opening '%s'"),
 
1028
                             gimp_filename_to_utf8 (filename));
1000
1029
 
1001
1030
  ifp = ps_open (filename, &plvals, &llx, &lly, &urx, &ury, &is_epsf,
1002
1031
                 &ChildPid);
1019
1048
    {
1020
1049
      max_pagenum = -1;
1021
1050
      for (temp = plvals.pages; *temp != '\0'; temp++)
1022
 
        {
1023
 
          if ((*temp < '0') || (*temp > '9'))
 
1051
        {
 
1052
          if ((*temp < '0') || (*temp > '9'))
1024
1053
            continue; /* Search next digit */
1025
 
          sscanf (temp, "%d", &k);
1026
 
          if (k > max_pagenum)
 
1054
          sscanf (temp, "%d", &k);
 
1055
          if (k > max_pagenum)
1027
1056
            max_pagenum = k;
1028
 
          while ((*temp >= '0') && (*temp <= '9'))
 
1057
          while ((*temp >= '0') && (*temp <= '9'))
1029
1058
            temp++;
1030
 
          temp--;
1031
 
        }
 
1059
          temp--;
 
1060
        }
1032
1061
 
1033
1062
      if (max_pagenum < 1)
1034
1063
        max_pagenum = 9999;
1038
1067
  for (page_count = 1; page_count <= max_pagenum; page_count++)
1039
1068
    {
1040
1069
      if (page_in_list (plvals.pages, page_count))
1041
 
        {
1042
 
          image_ID = load_ps (filename, page_count, ifp, llx, lly, urx, ury);
1043
 
          if (image_ID == -1)
 
1070
        {
 
1071
          image_ID = load_ps (filename, page_count, ifp, llx, lly, urx, ury);
 
1072
          if (image_ID == -1)
1044
1073
            break;
1045
1074
 
1046
 
          gimp_image_set_resolution (image_ID,
1047
 
                                     (double) plvals.resolution,
1048
 
                                     (double) plvals.resolution);
 
1075
          gimp_image_set_resolution (image_ID,
 
1076
                                     (double) plvals.resolution,
 
1077
                                     (double) plvals.resolution);
1049
1078
 
1050
 
          if (n_images == max_images)
1051
 
            {
1052
 
              nl = (gint32 *) g_realloc (image_list,
1053
 
                                         (max_images+10)*sizeof (gint32));
1054
 
              if (nl == NULL) break;
1055
 
              image_list = nl;
1056
 
              max_images += 10;
1057
 
            }
1058
 
          image_list[n_images++] = image_ID;
1059
 
        }
 
1079
          if (n_images == max_images)
 
1080
            {
 
1081
              nl = (gint32 *) g_realloc (image_list,
 
1082
                                         (max_images+10)*sizeof (gint32));
 
1083
              if (nl == NULL) break;
 
1084
              image_list = nl;
 
1085
              max_images += 10;
 
1086
            }
 
1087
          image_list[n_images++] = image_ID;
 
1088
        }
1060
1089
      else  /* Skip an image */
1061
 
        {
 
1090
        {
1062
1091
          image_ID = -1;
1063
 
          if (! skip_ps (ifp))
 
1092
          if (! skip_ps (ifp))
1064
1093
            break;
1065
 
        }
 
1094
        }
1066
1095
    }
1067
1096
 
1068
1097
  ps_close (ifp, ChildPid);
1069
1098
 
1070
 
  /* Display images in reverse order. The last will be displayed by GIMP itself*/
1071
 
  if (l_run_mode != GIMP_RUN_NONINTERACTIVE)
1072
 
    {
1073
 
      for (k = n_images-1; k >= 1; k--)
1074
 
        gimp_display_new (image_list[k]);
1075
 
    }
1076
 
 
1077
 
  image_ID = (n_images > 0) ? image_list[0] : -1;
 
1099
  if (ps_pagemode == GIMP_PAGE_SELECTOR_TARGET_LAYERS)
 
1100
    {
 
1101
      for (k = 0; k < n_images; k++)
 
1102
        {
 
1103
          gchar *name;
 
1104
 
 
1105
          if (k == 0)
 
1106
            {
 
1107
              image_ID = image_list[0];
 
1108
 
 
1109
              name = g_strdup_printf (_("%s-pages"), filename);
 
1110
              gimp_image_set_filename (image_ID, name);
 
1111
              g_free (name);
 
1112
            }
 
1113
          else
 
1114
            {
 
1115
              gint32 current_layer;
 
1116
              gint32 tmp_ID;
 
1117
 
 
1118
              tmp_ID = gimp_image_get_active_drawable (image_list[k]);
 
1119
 
 
1120
              name = gimp_drawable_get_name (tmp_ID);
 
1121
 
 
1122
              current_layer = gimp_layer_new_from_drawable (tmp_ID, image_ID);
 
1123
              gimp_drawable_set_name (current_layer, name);
 
1124
              gimp_image_add_layer (image_ID, current_layer, -1);
 
1125
              gimp_image_delete (image_list[k]);
 
1126
 
 
1127
              g_free (name);
 
1128
            }
 
1129
        }
 
1130
 
 
1131
      gimp_image_undo_enable (image_ID);
 
1132
    }
 
1133
  else
 
1134
    {
 
1135
      /* Display images in reverse order.
 
1136
       * The last will be displayed by GIMP itself
 
1137
       */
 
1138
      for (k = n_images - 1; k >= 0; k--)
 
1139
        {
 
1140
          gimp_image_undo_enable (image_list[k]);
 
1141
          gimp_image_clean_all (image_list[k]);
 
1142
 
 
1143
          if (l_run_mode != GIMP_RUN_NONINTERACTIVE && k > 0)
 
1144
            gimp_display_new (image_list[k]);
 
1145
        }
 
1146
 
 
1147
      image_ID = (n_images > 0) ? image_list[0] : -1;
 
1148
    }
 
1149
 
1078
1150
  g_free (image_list);
1079
1151
 
1080
1152
  return image_ID;
1089
1161
  FILE* ofp;
1090
1162
  GimpImageType drawable_type;
1091
1163
  gint retval;
1092
 
  char *temp = ident; /* Just to satisfy lint/gcc */
1093
1164
 
1094
1165
  /* initialize */
1095
1166
 
1117
1188
    }
1118
1189
 
1119
1190
  /* Open the output file. */
1120
 
  ofp = fopen (filename, "wb");
 
1191
  ofp = g_fopen (filename, "wb");
1121
1192
  if (!ofp)
1122
1193
    {
1123
1194
      g_message (_("Could not open '%s' for writing: %s"),
1125
1196
      return FALSE;
1126
1197
    }
1127
1198
 
1128
 
  temp = g_strdup_printf (_("Saving '%s'..."),
1129
 
                          gimp_filename_to_utf8 (filename));
1130
 
  gimp_progress_init (temp);
1131
 
  g_free (temp);
 
1199
  gimp_progress_init_printf (_("Saving '%s'"),
 
1200
                             gimp_filename_to_utf8 (filename));
1132
1201
 
1133
1202
  save_ps_header (ofp, filename);
1134
1203
 
1212
1281
  while (*c1)    /* Remove all whitespace and break on unsupported characters */
1213
1282
    {
1214
1283
      if ((*c1 >= '0') && (*c1 <= '9'))
1215
 
        {
1216
 
          *(c0++) = *c1;
1217
 
        }
 
1284
        {
 
1285
          *(c0++) = *c1;
 
1286
        }
1218
1287
      else if ((*c1 == '-') || (*c1 == ','))
1219
 
        { /* Try to remove double occurances of these characters */
1220
 
          if (c0 == tmplist)
1221
 
            {
1222
 
              *(c0++) = *c1;
1223
 
            }
1224
 
          else
1225
 
            {
1226
 
              if (*(c0-1) != *c1)
1227
 
                *(c0++) = *c1;
1228
 
            }
1229
 
        }
 
1288
        { /* Try to remove double occurances of these characters */
 
1289
          if (c0 == tmplist)
 
1290
            {
 
1291
              *(c0++) = *c1;
 
1292
            }
 
1293
          else
 
1294
            {
 
1295
              if (*(c0-1) != *c1)
 
1296
                *(c0++) = *c1;
 
1297
            }
 
1298
        }
1230
1299
      else
1231
1300
        break;
1232
1301
 
1245
1314
  for (c0 = tmplist; *c0 != '\0'; c0++)
1246
1315
    {
1247
1316
      switch (state)
1248
 
        {
1249
 
        case READ_STARTNUM:
1250
 
          if (*c0 == ',')
1251
 
            {
1252
 
              if ((start_num > 0) && (start_num == (int)page_num))
 
1317
        {
 
1318
        case READ_STARTNUM:
 
1319
          if (*c0 == ',')
 
1320
            {
 
1321
              if ((start_num > 0) && (start_num == (int)page_num))
1253
1322
                return -1;
1254
 
              start_num = -1;
1255
 
            }
1256
 
          else if (*c0 == '-')
1257
 
            {
1258
 
              if (start_num < 0) start_num = 1;
1259
 
              state = READ_ENDNUM;
1260
 
            }
1261
 
          else /* '0' - '9' */
1262
 
            {
1263
 
              if (start_num < 0) start_num = 0;
1264
 
              start_num *= 10;
1265
 
              start_num += *c0 - '0';
1266
 
            }
1267
 
          break;
 
1323
              start_num = -1;
 
1324
            }
 
1325
          else if (*c0 == '-')
 
1326
            {
 
1327
              if (start_num < 0) start_num = 1;
 
1328
              state = READ_ENDNUM;
 
1329
            }
 
1330
          else /* '0' - '9' */
 
1331
            {
 
1332
              if (start_num < 0) start_num = 0;
 
1333
              start_num *= 10;
 
1334
              start_num += *c0 - '0';
 
1335
            }
 
1336
          break;
1268
1337
 
1269
 
        case READ_ENDNUM:
1270
 
          if (*c0 == ',')
1271
 
            {
1272
 
              if (end_num < 0) end_num = 9999;
1273
 
              CHK_LIST (start_num, end_num, (int)page_num);
1274
 
              start_num = end_num = -1;
1275
 
              state = READ_STARTNUM;
1276
 
            }
1277
 
          else if (*c0 == '-')
1278
 
            {
1279
 
              CHK_LIST (start_num, end_num, (int)page_num);
1280
 
              start_num = end_num;
1281
 
              end_num = -1;
1282
 
            }
1283
 
          else /* '0' - '9' */
1284
 
            {
1285
 
              if (end_num < 0) end_num = 0;
1286
 
              end_num *= 10;
1287
 
              end_num += *c0 - '0';
1288
 
            }
1289
 
          break;
1290
 
        }
 
1338
        case READ_ENDNUM:
 
1339
          if (*c0 == ',')
 
1340
            {
 
1341
              if (end_num < 0) end_num = 9999;
 
1342
              CHK_LIST (start_num, end_num, (int)page_num);
 
1343
              start_num = end_num = -1;
 
1344
              state = READ_STARTNUM;
 
1345
            }
 
1346
          else if (*c0 == '-')
 
1347
            {
 
1348
              CHK_LIST (start_num, end_num, (int)page_num);
 
1349
              start_num = end_num;
 
1350
              end_num = -1;
 
1351
            }
 
1352
          else /* '0' - '9' */
 
1353
            {
 
1354
              if (end_num < 0) end_num = 0;
 
1355
              end_num *= 10;
 
1356
              end_num += *c0 - '0';
 
1357
            }
 
1358
          break;
 
1359
        }
1291
1360
    }
1292
1361
  if (state == READ_STARTNUM)
1293
1362
    {
1294
1363
      if (start_num > 0)
1295
 
        return (start_num == (int) page_num);
 
1364
        return (start_num == (int) page_num);
1296
1365
    }
1297
1366
  else
1298
1367
    {
1381
1450
  FILE *ifp;
1382
1451
  int retval = -1;
1383
1452
 
1384
 
  ifp = fopen (filename, "rb");
 
1453
  ifp = g_fopen (filename, "rb");
1385
1454
  if (ifp == NULL)
1386
1455
    return -1;
1387
1456
 
1396
1465
      while ((*src == ' ') || (*src == '\t') || (*src == ':')) src++;
1397
1466
      if (strncmp (src, "(atend)", 7) == 0) continue;
1398
1467
      if (sscanf (src, "%d%d%d%d", x0, y0, x1, y1) == 4)
1399
 
        retval = 0;
 
1468
        retval = 0;
1400
1469
      break;
1401
1470
    }
1402
1471
  fclose (ifp);
1419
1488
         gint             *is_epsf,
1420
1489
         gint             *ChildPidPtr)
1421
1490
{
1422
 
  char *gs, *driver;
 
1491
  const gchar *gs;
 
1492
  gchar *driver;
1423
1493
  GPtrArray *cmdA;
1424
1494
  gchar **pcmdA;
1425
1495
  FILE *fd_popen = NULL;
1448
1518
  /* Check if it is a EPS-file */
1449
1519
  *is_epsf = 0;
1450
1520
 
1451
 
  eps_file = fopen (filename, "rb");
 
1521
  eps_file = g_fopen (filename, "rb");
1452
1522
 
1453
1523
  if (eps_file != NULL)
1454
1524
    {
1533
1603
  pnmfile = "-";
1534
1604
#endif
1535
1605
 
1536
 
  gs = getenv ("GS_PROG");
 
1606
  gs = g_getenv ("GS_PROG");
1537
1607
  if (gs == NULL)
1538
1608
    gs = DEFAULT_GS_PROG;
1539
1609
 
1569
1639
  g_ptr_array_add (cmdA, g_strdup ("-dNOPAUSE"));
1570
1640
 
1571
1641
  /* If no additional options specified, use at least -dSAFER */
1572
 
  if (getenv ("GS_OPTIONS") == NULL)
 
1642
  if (g_getenv ("GS_OPTIONS") == NULL)
1573
1643
    g_ptr_array_add (cmdA, g_strdup ("-dSAFER"));
1574
1644
 
1575
1645
  /* Output file name */
1628
1698
                                  NULL,         /* stderr */
1629
1699
                                  &Gerr) )
1630
1700
    {
1631
 
      g_message (_("Error starting ghostscript (%s)"), Gerr->message);
 
1701
      g_message (_("Error starting Ghostscript. Make sure that Ghostscript is installed and - if necessary - use the environment variable GS_PROG to tell GIMP about its location.\n(%s)"), Gerr->message);
1632
1702
      g_error_free (Gerr);
1633
1703
 
1634
1704
      *ChildPidPtr = 0;
1658
1728
                      NULL,       /* exit code */
1659
1729
                      &Gerr) )
1660
1730
    {
1661
 
      g_message (_("Error starting ghostscript: %s"), Gerr->message);
 
1731
      g_message (_("Error starting Ghostscript. Make sure that Ghostscript is installed and - if necessary - use the environment variable GS_PROG to tell GIMP about its location.\n(%s)"), Gerr->message);
1662
1732
      g_error_free (Gerr);
1663
1733
 
1664
 
      unlink (pnmfile);
 
1734
      g_unlink (pnmfile);
1665
1735
 
1666
1736
      goto out;
1667
1737
    }
1669
1739
  /* Don't care about exit status of ghostscript. */
1670
1740
  /* Just try to read what it wrote. */
1671
1741
 
1672
 
  fd_popen = fopen (pnmfile, "rb");
 
1742
  fd_popen = g_fopen (pnmfile, "rb");
1673
1743
 
1674
1744
#endif
1675
1745
 
1728
1798
#else  /*  USE_REAL_OUTPUTFILE  */
1729
1799
 /* If a real outputfile was used, close the file and remove it. */
1730
1800
  fclose (ifp);
1731
 
  unlink (pnmfile);
 
1801
  g_unlink (pnmfile);
1732
1802
#endif
1733
1803
}
1734
1804
 
1756
1826
      if (thrd == '\r') thrd = getc (ifp);
1757
1827
#endif
1758
1828
      if ((thrd == '\n') && (frst == 'P') && (scnd >= '1') && (scnd <= '6'))
1759
 
        break;
 
1829
        break;
1760
1830
      frst = scnd;
1761
1831
      scnd = thrd;
1762
1832
      thrd = getc (ifp);
1782
1852
  if (pnmtype != 4)  /* Read maxval */
1783
1853
    {
1784
1854
      for (;;)
1785
 
        {
1786
 
          if (fgets (line, sizeof (line)-1, ifp) == NULL)
 
1855
        {
 
1856
          if (fgets (line, sizeof (line)-1, ifp) == NULL)
1787
1857
            return -1;
1788
 
          if (line[0] != '#')
 
1858
          if (line[0] != '#')
1789
1859
            break;
1790
 
        }
 
1860
        }
1791
1861
      if (sscanf (line, "%d", maxval) != 1)
1792
1862
        return -1;
1793
1863
    }
1809
1879
{
1810
1880
  gint32         image_ID;
1811
1881
  GimpImageType  gdtype;
 
1882
  gchar         *tmp;
1812
1883
 
1813
1884
  if (type == GIMP_GRAY) gdtype = GIMP_GRAY_IMAGE;
1814
1885
  else if (type == GIMP_INDEXED) gdtype = GIMP_INDEXED_IMAGE;
1815
1886
  else gdtype = GIMP_RGB_IMAGE;
1816
1887
 
1817
1888
  image_ID = gimp_image_new (width, height, type);
1818
 
 
1819
 
  if (pagenum > 1)
1820
 
    {
1821
 
      gchar *tmp;
1822
 
 
1823
 
      tmp = g_strdup_printf ("%s-pg%ld", filename, (long)pagenum);
1824
 
      gimp_image_set_filename (image_ID, tmp);
1825
 
      g_free (tmp);
1826
 
    }
1827
 
  else
1828
 
    {
1829
 
      gimp_image_set_filename (image_ID, filename);
1830
 
    }
1831
 
 
1832
 
  *layer_ID = gimp_layer_new (image_ID, "Background", width, height,
1833
 
                              gdtype, 100, GIMP_NORMAL_MODE);
 
1889
  gimp_image_undo_disable (image_ID);
 
1890
 
 
1891
  tmp = g_strdup_printf ("%s-%d", filename, pagenum);
 
1892
  gimp_image_set_filename (image_ID, tmp);
 
1893
  g_free (tmp);
 
1894
 
 
1895
  tmp = g_strdup_printf (_("Page %d"), pagenum);
 
1896
  *layer_ID = gimp_layer_new (image_ID, tmp, width, height,
 
1897
                              gdtype, 100, GIMP_NORMAL_MODE);
 
1898
  g_free (tmp);
 
1899
 
1834
1900
  gimp_image_add_layer (image_ID, *layer_ID, 0);
1835
1901
 
1836
1902
  *drawable = gimp_drawable_get (*layer_ID);
1837
1903
  gimp_pixel_rgn_init (pixel_rgn, *drawable, 0, 0, (*drawable)->width,
1838
 
                       (*drawable)->height, TRUE, FALSE);
 
1904
                       (*drawable)->height, TRUE, FALSE);
1839
1905
 
1840
1906
  return image_ID;
1841
1907
}
1924
1990
      /* Get an array for mapping 8 bits in a byte to 8 bytes */
1925
1991
      temp = bit2byte;
1926
1992
      for (j = 0; j < 256; j++)
1927
 
        for (i = 7; i >= 0; i--)
1928
 
          *(temp++) = ((j & (1 << i)) != 0);
 
1993
        for (i = 7; i >= 0; i--)
 
1994
          *(temp++) = ((j & (1 << i)) != 0);
1929
1995
    }
1930
1996
  else if (pnmtype == 5)  /* Portable Greymap */
1931
1997
    {
1945
2011
    return -1;
1946
2012
 
1947
2013
  image_ID = create_new_image (filename, pagenum,
1948
 
                               image_width, image_height, imagetype,
1949
 
                               &layer_ID, &drawable, &pixel_rgn);
 
2014
                               image_width, image_height, imagetype,
 
2015
                               &layer_ID, &drawable, &pixel_rgn);
1950
2016
 
1951
2017
  tile_height = gimp_tile_height ();
1952
2018
  data = g_malloc (tile_height * image_width * bpp);
1961
2027
 
1962
2028
    for (i = 0; i < height; i++)
1963
2029
      {
1964
 
        e = (fread (bitline, 1, nread, ifp) != nread);
1965
 
        if (total_scan_lines >= image_height) continue;
1966
 
        err |= e;
1967
 
        if (err) break;
1968
 
 
1969
 
        j = width;      /* Map 1 byte of bitimage to 8 bytes of indexed image */
1970
 
        temp = bitline;
1971
 
        byteptr = byteline;
1972
 
        while (j >= 8)
1973
 
          {
1974
 
            memcpy (byteptr, bit2byte + *(temp++)*8, 8);
1975
 
            byteptr += 8;
1976
 
            j -= 8;
1977
 
          }
1978
 
        if (j > 0)
1979
 
          memcpy (byteptr, bit2byte + *temp*8, j);
1980
 
 
1981
 
        memcpy (dest, byteline+skip_left, image_width);
1982
 
        dest += image_width;
1983
 
        scan_lines++;
1984
 
        total_scan_lines++;
1985
 
 
1986
 
        if ((i % 20) == 0)
1987
 
          gimp_progress_update ((double)(i+1) / (double)image_height);
1988
 
 
1989
 
        if ((scan_lines == tile_height) || ((i+1) == image_height))
1990
 
          {
1991
 
            gimp_pixel_rgn_set_rect (&pixel_rgn, data, 0, i-scan_lines+1,
1992
 
                                     image_width, scan_lines);
1993
 
            scan_lines = 0;
1994
 
            dest = data;
1995
 
          }
1996
 
        if (err) break;
 
2030
        e = (fread (bitline, 1, nread, ifp) != nread);
 
2031
        if (total_scan_lines >= image_height) continue;
 
2032
        err |= e;
 
2033
        if (err) break;
 
2034
 
 
2035
        j = width;      /* Map 1 byte of bitimage to 8 bytes of indexed image */
 
2036
        temp = bitline;
 
2037
        byteptr = byteline;
 
2038
        while (j >= 8)
 
2039
          {
 
2040
            memcpy (byteptr, bit2byte + *(temp++)*8, 8);
 
2041
            byteptr += 8;
 
2042
            j -= 8;
 
2043
          }
 
2044
        if (j > 0)
 
2045
          memcpy (byteptr, bit2byte + *temp*8, j);
 
2046
 
 
2047
        memcpy (dest, byteline+skip_left, image_width);
 
2048
        dest += image_width;
 
2049
        scan_lines++;
 
2050
        total_scan_lines++;
 
2051
 
 
2052
        if ((i % 20) == 0)
 
2053
          gimp_progress_update ((double)(i+1) / (double)image_height);
 
2054
 
 
2055
        if ((scan_lines == tile_height) || ((i+1) == image_height))
 
2056
          {
 
2057
            gimp_pixel_rgn_set_rect (&pixel_rgn, data, 0, i-scan_lines+1,
 
2058
                                     image_width, scan_lines);
 
2059
            scan_lines = 0;
 
2060
            dest = data;
 
2061
          }
 
2062
        if (err) break;
1997
2063
      }
1998
2064
    }
1999
2065
  else   /* Read gray/rgb-image */
2000
2066
    {
2001
2067
      for (i = 0; i < height; i++)
2002
 
        {
2003
 
          e = (fread (byteline, bpp, width, ifp) != width);
2004
 
          if (total_scan_lines >= image_height) continue;
2005
 
          err |= e;
2006
 
          if (err) break;
2007
 
 
2008
 
          memcpy (dest, byteline+skip_left*bpp, image_width*bpp);
2009
 
          dest += image_width*bpp;
2010
 
          scan_lines++;
2011
 
          total_scan_lines++;
2012
 
 
2013
 
          if ((i % 20) == 0)
2014
 
            gimp_progress_update ((double)(i+1) / (double)image_height);
2015
 
 
2016
 
          if ((scan_lines == tile_height) || ((i+1) == image_height))
2017
 
            {
2018
 
              gimp_pixel_rgn_set_rect (&pixel_rgn, data, 0, i-scan_lines+1,
2019
 
                                       image_width, scan_lines);
2020
 
              scan_lines = 0;
2021
 
              dest = data;
2022
 
            }
2023
 
          if (err) break;
2024
 
        }
 
2068
        {
 
2069
          e = (fread (byteline, bpp, width, ifp) != width);
 
2070
          if (total_scan_lines >= image_height) continue;
 
2071
          err |= e;
 
2072
          if (err) break;
 
2073
 
 
2074
          memcpy (dest, byteline+skip_left*bpp, image_width*bpp);
 
2075
          dest += image_width*bpp;
 
2076
          scan_lines++;
 
2077
          total_scan_lines++;
 
2078
 
 
2079
          if ((i % 20) == 0)
 
2080
            gimp_progress_update ((double)(i+1) / (double)image_height);
 
2081
 
 
2082
          if ((scan_lines == tile_height) || ((i+1) == image_height))
 
2083
            {
 
2084
              gimp_pixel_rgn_set_rect (&pixel_rgn, data, 0, i-scan_lines+1,
 
2085
                                       image_width, scan_lines);
 
2086
              scan_lines = 0;
 
2087
              dest = data;
 
2088
            }
 
2089
          if (err) break;
 
2090
        }
2025
2091
    }
2026
2092
 
2027
2093
  g_free (data);
2094
2160
      f1 = width_inch / width;
2095
2161
      f2 = height_inch / height;
2096
2162
      if (f1 < f2)
2097
 
        height_inch = width_inch * (double)(height)/(double)(width);
 
2163
        height_inch = width_inch * (double)(height)/(double)(width);
2098
2164
      else
2099
 
        width_inch = fabs (height_inch) * (double)(width)/(double)(height);
 
2165
        width_inch = fabs (height_inch) * (double)(width)/(double)(height);
2100
2166
    }
2101
2167
  if ((psvals.rotate == 0) || (psvals.rotate == 180))
2102
2168
    {
2189
2255
/* If linecount is less than zero, all used memory is freed. */
2190
2256
 
2191
2257
static void
2192
 
dither_grey (guchar *grey,
2193
 
             guchar *bw,
2194
 
             gint    npix,
2195
 
             gint    linecount)
 
2258
dither_grey (const guchar *grey,
 
2259
             guchar       *bw,
 
2260
             gint          npix,
 
2261
             gint          linecount)
2196
2262
{
2197
 
  register guchar *greyptr, *bwptr, mask;
2198
 
  register int *fse;
2199
 
  int x, greyval, fse_inline;
2200
 
  static int *fs_error = NULL;
2201
 
  static int do_init_arrays = 1;
2202
 
  static int limit_array[1278];
2203
 
  static int east_error[256],seast_error[256],south_error[256],swest_error[256];
2204
 
  int *limit = &(limit_array[512]);
 
2263
  static gboolean do_init_arrays = TRUE;
 
2264
  static gint *fs_error = NULL;
 
2265
  static gint  limit[1278];
 
2266
  static gint  east_error[256];
 
2267
  static gint  seast_error[256];
 
2268
  static gint  south_error[256];
 
2269
  static gint  swest_error[256];
 
2270
 
 
2271
  register const guchar *greyptr;
 
2272
  register guchar *bwptr, mask;
 
2273
  register gint *fse;
 
2274
  gint x, greyval, fse_inline;
2205
2275
 
2206
2276
  if (linecount <= 0)
2207
2277
    {
2208
 
      if (fs_error) g_free (fs_error-1);
2209
 
      if (linecount < 0) return;
2210
 
      fs_error = g_new (int, npix+2);
2211
 
      memset ((char *)fs_error, 0, (npix+2)*sizeof (int));
2212
 
      fs_error++;
 
2278
      g_free (fs_error);
 
2279
 
 
2280
      if (linecount < 0)
 
2281
        return;
 
2282
 
 
2283
      fs_error = g_new0 (gint, npix + 2);
2213
2284
 
2214
2285
      /* Initialize some arrays that speed up dithering */
2215
2286
      if (do_init_arrays)
2216
 
        {
2217
 
          do_init_arrays = 0;
2218
 
          for (x = -511; x <= 766; x++)
2219
 
            limit[x] = (x < 0) ? 0 : ((x > 255) ? 255 : x);
2220
 
          for (greyval = 0; greyval < 256; greyval++)
2221
 
            {
2222
 
              east_error[greyval] = (greyval < 128) ? ((greyval * 79) >> 8)
2223
 
                : (((greyval-255)*79) >> 8);
2224
 
              seast_error[greyval] = (greyval < 128) ? ((greyval * 34) >> 8)
2225
 
                : (((greyval-255)*34) >> 8);
2226
 
              south_error[greyval] = (greyval < 128) ? ((greyval * 56) >> 8)
2227
 
                : (((greyval-255)*56) >> 8);
2228
 
              swest_error[greyval] = (greyval < 128) ? ((greyval * 12) >> 8)
2229
 
                : (((greyval-255)*12) >> 8);
2230
 
            }
2231
 
        }
 
2287
        {
 
2288
          gint i;
 
2289
 
 
2290
          do_init_arrays = FALSE;
 
2291
 
 
2292
          for (i = 0, x = -511; x <= 766; i++, x++)
 
2293
            limit[i] = (x < 0) ? 0 : ((x > 255) ? 255 : x);
 
2294
 
 
2295
          for (greyval = 0; greyval < 256; greyval++)
 
2296
            {
 
2297
              east_error[greyval] = (greyval < 128) ?
 
2298
                ((greyval * 79) >> 8) : (((greyval - 255) * 79) >> 8);
 
2299
              seast_error[greyval] = (greyval < 128) ?
 
2300
                ((greyval * 34) >> 8) : (((greyval - 255) * 34) >> 8);
 
2301
              south_error[greyval] = (greyval < 128) ?
 
2302
                ((greyval * 56) >> 8) : (((greyval - 255) * 56) >> 8);
 
2303
              swest_error[greyval] = (greyval < 128) ?
 
2304
                ((greyval * 12) >> 8) : (((greyval - 255) * 12) >> 8);
 
2305
            }
 
2306
        }
2232
2307
    }
2233
 
  if (fs_error == NULL) return;
2234
 
 
2235
 
  memset (bw, 0, (npix+7)/8); /* Initialize with white */
 
2308
 
 
2309
  g_return_if_fail (fs_error != NULL);
 
2310
 
 
2311
  memset (bw, 0, (npix + 7) / 8); /* Initialize with white */
2236
2312
 
2237
2313
  greyptr = grey;
2238
2314
  bwptr = bw;
2239
2315
  mask = 0x80;
2240
 
  fse_inline = fs_error[0];
2241
 
  for (x = 0, fse = fs_error; x < npix; x++, fse++)
 
2316
 
 
2317
  fse_inline = fs_error[1];
 
2318
 
 
2319
  for (x = 0, fse = fs_error + 1; x < npix; x++, fse++)
2242
2320
    {
2243
 
      greyval = limit[*(greyptr++) + fse_inline];  /* 0 <= greyval <= 255 */
2244
 
      if (greyval < 128) *bwptr |= mask;  /* Set a black pixel */
 
2321
      greyval =
 
2322
        limit[*(greyptr++) + fse_inline + 512];  /* 0 <= greyval <= 255 */
 
2323
 
 
2324
      if (greyval < 128)
 
2325
        *bwptr |= mask;  /* Set a black pixel */
2245
2326
 
2246
2327
      /* Error distribution */
2247
2328
      fse_inline = east_error[greyval] + fse[1];
2250
2331
      fse[-1] += swest_error[greyval];
2251
2332
 
2252
2333
      mask >>= 1;   /* Get mask for next b/w-pixel */
 
2334
 
2253
2335
      if (!mask)
2254
 
        {
2255
 
          mask = 0x80;
2256
 
          bwptr++;
2257
 
        }
 
2336
        {
 
2337
          mask = 0x80;
 
2338
          bwptr++;
 
2339
        }
2258
2340
    }
2259
2341
}
2260
2342
 
2281
2363
 
2282
2364
  /* Calculate size of preview */
2283
2365
  if (   (drawable->width <= psvals.preview_size)
2284
 
         && (drawable->height <= psvals.preview_size))
 
2366
         && (drawable->height <= psvals.preview_size))
2285
2367
    {
2286
2368
      width = drawable->width;
2287
2369
      height = drawable->height;
2291
2373
      f1 = (double)psvals.preview_size / (double)drawable->width;
2292
2374
      f2 = (double)psvals.preview_size / (double)drawable->height;
2293
2375
      if (f1 < f2)
2294
 
        {
2295
 
          width = psvals.preview_size;
2296
 
          height = drawable->height * f1;
2297
 
          if (height <= 0) height = 1;
2298
 
        }
 
2376
        {
 
2377
          width = psvals.preview_size;
 
2378
          height = drawable->height * f1;
 
2379
          if (height <= 0) height = 1;
 
2380
        }
2299
2381
      else
2300
 
        {
2301
 
          height = psvals.preview_size;
2302
 
          width = drawable->width * f1;
2303
 
          if (width <= 0) width = 1;
2304
 
        }
 
2382
        {
 
2383
          height = psvals.preview_size;
 
2384
          width = drawable->width * f1;
 
2385
          if (width <= 0) width = 1;
 
2386
        }
2305
2387
    }
2306
2388
 
2307
2389
  nbsl = (width+7)/8;  /* Number of bytes per scanline in bitmap */
2311
2393
  src_row = (guchar *)g_malloc (drawable->width * drawable->bpp);
2312
2394
 
2313
2395
  fprintf (ofp, "%%%%BeginPreview: %d %d 1 %d\n", width, height,
2314
 
           ((nbsl*2+nchar_pl-1)/nchar_pl)*height);
 
2396
           ((nbsl*2+nchar_pl-1)/nchar_pl)*height);
2315
2397
 
2316
2398
  gimp_pixel_rgn_init (&src_rgn, drawable, 0, 0, drawable->width,
2317
 
                       drawable->height, FALSE, FALSE);
 
2399
                       drawable->height, FALSE, FALSE);
2318
2400
 
2319
2401
  cmap = NULL;     /* Check if we need a colour table */
2320
2402
  if (gimp_drawable_type (drawable_ID) == GIMP_INDEXED_IMAGE)
2329
2411
 
2330
2412
      greyptr = grey;
2331
2413
      if (drawable->bpp == 3)   /* RGB-image */
2332
 
        {
2333
 
          for (x = 0; x < width; x++)
2334
 
            {                       /* Convert to grey */
2335
 
              src_ptr = src_row + ((x * drawable->width) / width) * 3;
2336
 
              *(greyptr++) = (3*src_ptr[0] + 6*src_ptr[1] + src_ptr[2]) / 10;
2337
 
            }
2338
 
        }
 
2414
        {
 
2415
          for (x = 0; x < width; x++)
 
2416
            {                       /* Convert to grey */
 
2417
              src_ptr = src_row + ((x * drawable->width) / width) * 3;
 
2418
              *(greyptr++) = (3*src_ptr[0] + 6*src_ptr[1] + src_ptr[2]) / 10;
 
2419
            }
 
2420
        }
2339
2421
      else if (cmap)    /* Indexed image */
2340
 
        {
2341
 
          for (x = 0; x < width; x++)
2342
 
            {
2343
 
              src_ptr = src_row + ((x * drawable->width) / width);
2344
 
              cind = *src_ptr;   /* Get colour index and convert to grey */
2345
 
              src_ptr = (cind >= ncols) ? cmap : (cmap + 3*cind);
2346
 
              *(greyptr++) = (3*src_ptr[0] + 6*src_ptr[1] + src_ptr[2]) / 10;
2347
 
            }
2348
 
        }
 
2422
        {
 
2423
          for (x = 0; x < width; x++)
 
2424
            {
 
2425
              src_ptr = src_row + ((x * drawable->width) / width);
 
2426
              cind = *src_ptr;   /* Get colour index and convert to grey */
 
2427
              src_ptr = (cind >= ncols) ? cmap : (cmap + 3*cind);
 
2428
              *(greyptr++) = (3*src_ptr[0] + 6*src_ptr[1] + src_ptr[2]) / 10;
 
2429
            }
 
2430
        }
2349
2431
      else             /* Grey image */
2350
 
        {
2351
 
          for (x = 0; x < width; x++)
2352
 
            *(greyptr++) = *(src_row + ((x * drawable->width) / width));
2353
 
        }
 
2432
        {
 
2433
          for (x = 0; x < width; x++)
 
2434
            *(greyptr++) = *(src_row + ((x * drawable->width) / width));
 
2435
        }
2354
2436
 
2355
2437
      /* Now we have a greyscale line for the desired width. */
2356
2438
      /* Dither it to b/w */
2360
2442
      out_count = 0;
2361
2443
      bwptr = bw;
2362
2444
      for (x = 0; x < nbsl; x++)
2363
 
        {
2364
 
          if (out_count == 0) fprintf (ofp, "%% ");
2365
 
          fprintf (ofp, "%02x", *(bwptr++));
2366
 
          out_count += 2;
2367
 
          if (out_count >= nchar_pl)
2368
 
            {
2369
 
              fprintf (ofp, "\n");
2370
 
              out_count = 0;
2371
 
            }
2372
 
        }
 
2445
        {
 
2446
          if (out_count == 0) fprintf (ofp, "%% ");
 
2447
          fprintf (ofp, "%02x", *(bwptr++));
 
2448
          out_count += 2;
 
2449
          if (out_count >= nchar_pl)
 
2450
            {
 
2451
              fprintf (ofp, "\n");
 
2452
              out_count = 0;
 
2453
            }
 
2454
        }
2373
2455
      if (out_count != 0)
2374
 
        fprintf (ofp, "\n");
 
2456
        fprintf (ofp, "\n");
2375
2457
 
2376
2458
      if ((y % 20) == 0)
2377
 
        gimp_progress_update ((double)(y) / (double)height);
 
2459
        gimp_progress_update ((double)(y) / (double)height);
2378
2460
    }
2379
2461
 
2380
2462
  fprintf (ofp, "%%%%EndPreview\n");
2440
2522
    {
2441
2523
      if ((i % tile_height) == 0) GET_GRAY_TILE (data); /* Get more data */
2442
2524
      if (!level2)
2443
 
        {
2444
 
          for (j = 0; j < width; j++)
2445
 
            {
2446
 
              putc (hex[(*src) >> 4], ofp);
2447
 
              putc (hex[(*(src++)) & 0x0f], ofp);
2448
 
              if (((j+1) % 39) == 0) putc ('\n', ofp);
2449
 
            }
2450
 
          putc ('\n', ofp);
2451
 
        }
 
2525
        {
 
2526
          for (j = 0; j < width; j++)
 
2527
            {
 
2528
              putc (hex[(*src) >> 4], ofp);
 
2529
              putc (hex[(*(src++)) & 0x0f], ofp);
 
2530
              if (((j+1) % 39) == 0) putc ('\n', ofp);
 
2531
            }
 
2532
          putc ('\n', ofp);
 
2533
        }
2452
2534
      else
2453
 
        {int nout;
 
2535
        {int nout;
2454
2536
 
2455
2537
          compress_packbits (width, src, &nout, packb);
2456
2538
          ascii85_nout (nout, packb, ofp);
2457
2539
          src += width;
2458
 
        }
 
2540
        }
2459
2541
 
2460
2542
      if ((i % 20) == 0)
2461
 
        gimp_progress_update ((double) i / (double) height);
 
2543
        gimp_progress_update ((double) i / (double) height);
2462
2544
    }
2463
2545
 
2464
2546
  if (level2)
2554
2636
      mask = 0x80;
2555
2637
      /* Build a bitmap for a scanline */
2556
2638
      for (j = 0; j < width; j++)
2557
 
        {
2558
 
          ct = cmap + *(src++)*3;
2559
 
          if (ct[0] || ct[1] || ct[2])
2560
 
            *dst |= mask;
2561
 
          if (mask == 0x01) { mask = 0x80; dst++; } else mask >>= 1;
2562
 
        }
 
2639
        {
 
2640
          ct = cmap + *(src++)*3;
 
2641
          if (ct[0] || ct[1] || ct[2])
 
2642
            *dst |= mask;
 
2643
          if (mask == 0x01) { mask = 0x80; dst++; } else mask >>= 1;
 
2644
        }
2563
2645
      if (!level2)
2564
 
        {
2565
 
          /* Convert to hexstring */
2566
 
          for (j = 0; j < nbsl; j++)
2567
 
            {
2568
 
              hex_scanline[j*2] = (unsigned char)hex[scanline[j] >> 4];
2569
 
              hex_scanline[j*2+1] = (unsigned char)hex[scanline[j] & 0x0f];
2570
 
            }
2571
 
          /* Write out hexstring */
2572
 
          j = nbsl * 2;
2573
 
          dst = hex_scanline;
2574
 
          while (j > 0)
2575
 
            {
2576
 
              nwrite = (j > 78) ? 78 : j;
2577
 
              fwrite (dst, nwrite, 1, ofp);
2578
 
              putc ('\n', ofp);
2579
 
              j -= nwrite;
2580
 
              dst += nwrite;
2581
 
            }
2582
 
        }
 
2646
        {
 
2647
          /* Convert to hexstring */
 
2648
          for (j = 0; j < nbsl; j++)
 
2649
            {
 
2650
              hex_scanline[j*2] = (unsigned char)hex[scanline[j] >> 4];
 
2651
              hex_scanline[j*2+1] = (unsigned char)hex[scanline[j] & 0x0f];
 
2652
            }
 
2653
          /* Write out hexstring */
 
2654
          j = nbsl * 2;
 
2655
          dst = hex_scanline;
 
2656
          while (j > 0)
 
2657
            {
 
2658
              nwrite = (j > 78) ? 78 : j;
 
2659
              fwrite (dst, nwrite, 1, ofp);
 
2660
              putc ('\n', ofp);
 
2661
              j -= nwrite;
 
2662
              dst += nwrite;
 
2663
            }
 
2664
        }
2583
2665
      else
2584
 
        {int nout;
 
2666
        {int nout;
2585
2667
 
2586
2668
          compress_packbits (nbsl, scanline, &nout, packb);
2587
2669
          ascii85_nout (nout, packb, ofp);
2588
 
        }
 
2670
        }
2589
2671
 
2590
2672
      if ((i % 20) == 0)
2591
 
        gimp_progress_update ((double) i / (double) height);
 
2673
        gimp_progress_update ((double) i / (double) height);
2592
2674
    }
2593
2675
 
2594
2676
  if (level2)
2646
2728
  for (j = 0; j < 256; j++)
2647
2729
    {
2648
2730
      if (j >= ncols)
2649
 
        {
2650
 
          memcpy (ct, background, 6);
2651
 
          ct += 6;
2652
 
        }
 
2731
        {
 
2732
          memcpy (ct, background, 6);
 
2733
          ct += 6;
 
2734
        }
2653
2735
      else
2654
 
        {
2655
 
          bw &=    ((cmap[0] == 0) && (cmap[1] == 0) && (cmap[2] == 0))
 
2736
        {
 
2737
          bw &=    ((cmap[0] == 0) && (cmap[1] == 0) && (cmap[2] == 0))
2656
2738
            || ((cmap[0] == 255) && (cmap[1] == 255) && (cmap[2] == 255));
2657
 
          *(ct++) = (guchar)hex[(*cmap) >> 4];
2658
 
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
2659
 
          *(ct++) = (guchar)hex[(*cmap) >> 4];
2660
 
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
2661
 
          *(ct++) = (guchar)hex[(*cmap) >> 4];
2662
 
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
2663
 
        }
 
2739
          *(ct++) = (guchar)hex[(*cmap) >> 4];
 
2740
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
 
2741
          *(ct++) = (guchar)hex[(*cmap) >> 4];
 
2742
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
 
2743
          *(ct++) = (guchar)hex[(*cmap) >> 4];
 
2744
          *(ct++) = (guchar)hex[(*(cmap++)) & 0x0f];
 
2745
        }
2664
2746
    }
2665
2747
  if (bw)
2666
2748
    return (save_bw (ofp, image_ID, drawable_ID));
2717
2799
    {
2718
2800
      if ((i % tile_height) == 0) GET_INDEX_TILE (data); /* Get more data */
2719
2801
      if (!level2)
2720
 
        {
2721
 
          for (j = 0; j < width; j++)
2722
 
            {
2723
 
              fwrite (coltab+(*(src++))*6, 6, 1, ofp);
2724
 
              if (((j+1) % 13) == 0) putc ('\n', ofp);
2725
 
            }
2726
 
          putc ('\n', ofp);
2727
 
        }
 
2802
        {
 
2803
          for (j = 0; j < width; j++)
 
2804
            {
 
2805
              fwrite (coltab+(*(src++))*6, 6, 1, ofp);
 
2806
              if (((j+1) % 13) == 0) putc ('\n', ofp);
 
2807
            }
 
2808
          putc ('\n', ofp);
 
2809
        }
2728
2810
      else
2729
2811
        {guchar *plane_ptr, *src_ptr;
2730
2812
         int rgb, nout;
2745
2827
        }
2746
2828
 
2747
2829
      if ((i % 20) == 0)
2748
 
        gimp_progress_update ((double) i / (double) height);
 
2830
        gimp_progress_update ((double) i / (double) height);
2749
2831
    }
2750
2832
 
2751
2833
  ps_end_data (ofp);
2839
2921
    {
2840
2922
      if ((i % tile_height) == 0) GET_RGB_TILE (data); /* Get more data */
2841
2923
      if (!level2)
2842
 
        {
2843
 
          for (j = 0; j < width; j++)
2844
 
            {
2845
 
              putc (hex[(*src) >> 4], ofp);        /* Red */
2846
 
              putc (hex[(*(src++)) & 0x0f], ofp);
2847
 
              putc (hex[(*src) >> 4], ofp);        /* Green */
2848
 
              putc (hex[(*(src++)) & 0x0f], ofp);
2849
 
              putc (hex[(*src) >> 4], ofp);        /* Blue */
2850
 
              putc (hex[(*(src++)) & 0x0f], ofp);
2851
 
              if (((j+1) % 13) == 0) putc ('\n', ofp);
2852
 
            }
2853
 
          putc ('\n', ofp);
2854
 
        }
 
2924
        {
 
2925
          for (j = 0; j < width; j++)
 
2926
            {
 
2927
              putc (hex[(*src) >> 4], ofp);        /* Red */
 
2928
              putc (hex[(*(src++)) & 0x0f], ofp);
 
2929
              putc (hex[(*src) >> 4], ofp);        /* Green */
 
2930
              putc (hex[(*(src++)) & 0x0f], ofp);
 
2931
              putc (hex[(*src) >> 4], ofp);        /* Blue */
 
2932
              putc (hex[(*(src++)) & 0x0f], ofp);
 
2933
              if (((j+1) % 13) == 0) putc ('\n', ofp);
 
2934
            }
 
2935
          putc ('\n', ofp);
 
2936
        }
2855
2937
      else
2856
 
        {guchar *plane_ptr, *src_ptr;
 
2938
        {guchar *plane_ptr, *src_ptr;
2857
2939
         int rgb, nout;
2858
2940
 
2859
2941
          for (rgb = 0; rgb < 3; rgb++)
2861
2943
            src_ptr = src + rgb;
2862
2944
            plane_ptr = plane;
2863
2945
            for (j = 0; j < width; j++)
2864
 
            {
 
2946
            {
2865
2947
              *(plane_ptr++) = *src_ptr;
2866
2948
              src_ptr += 3;
2867
2949
            }
2868
2950
            compress_packbits (width, plane, &nout, packb);
2869
2951
            ascii85_init ();
2870
 
            ascii85_nout (nout, packb, ofp);
 
2952
            ascii85_nout (nout, packb, ofp);
2871
2953
            ascii85_out (128, ofp); /* Write EOD of RunLengthDecode filter */
2872
2954
            ascii85_done (ofp);
2873
2955
          }
2874
2956
          src += 3*width;
2875
 
        }
 
2957
        }
2876
2958
 
2877
2959
      if ((i % 20) == 0)
2878
 
        gimp_progress_update ((double) i / (double) height);
 
2960
        gimp_progress_update ((double) i / (double) height);
2879
2961
    }
2880
2962
 
2881
2963
  ps_end_data (ofp);
2902
2984
 
2903
2985
/*  Load interface functions  */
2904
2986
 
 
2987
static gint32
 
2988
count_ps_pages (const gchar *filename)
 
2989
{
 
2990
  FILE   *psfile         = NULL;
 
2991
  gchar  *curr_line      = NULL;
 
2992
  gint32  num_pages      = 0;
 
2993
  gint32  showpage_count = 0;
 
2994
 
 
2995
  if (strncmp (g_ascii_strup (filename + (strlen (filename) - 3), 3), "EPS", 3) == 0)
 
2996
    return 1;
 
2997
 
 
2998
  psfile = g_fopen (filename, "r");
 
2999
 
 
3000
  if (psfile == NULL)
 
3001
    {
 
3002
      g_message (_("Could not open '%s' for reading: %s"),
 
3003
                 gimp_filename_to_utf8 (filename), g_strerror (errno));
 
3004
      return 0;
 
3005
    }
 
3006
 
 
3007
  curr_line = g_malloc0 (1024 * sizeof (gchar));
 
3008
 
 
3009
  while (num_pages == 0 && !feof (psfile))
 
3010
    {
 
3011
      fgets (curr_line, 1023, psfile);
 
3012
 
 
3013
      if (strncmp (curr_line + 2, "Pages:", 6) == 0)
 
3014
        sscanf (curr_line + strlen ("%%Pages:"), "%d", &num_pages);
 
3015
      else if (strncmp (curr_line, "showpage", 8) == 0)
 
3016
        showpage_count++;
 
3017
    }
 
3018
 
 
3019
  if (feof (psfile) && num_pages < 1 && showpage_count > 0)
 
3020
    num_pages = showpage_count;
 
3021
 
 
3022
  g_free (curr_line);
 
3023
  fclose (psfile);
 
3024
 
 
3025
  return num_pages;
 
3026
}
 
3027
 
2905
3028
static gboolean
2906
 
load_dialog (void)
 
3029
load_dialog (const gchar *filename,
 
3030
             gboolean     loadPDF)
2907
3031
{
2908
3032
  GtkWidget *dialog;
2909
3033
  GtkWidget *main_vbox;
2913
3037
  GtkWidget *table;
2914
3038
  GtkWidget *spinbutton;
2915
3039
  GtkObject *adj;
2916
 
  GtkWidget *entry;
 
3040
  GtkWidget *entry    = NULL;
 
3041
  GtkWidget *target   = NULL;
2917
3042
  GtkWidget *toggle;
 
3043
  GtkWidget *selector = NULL;
 
3044
  gint32     page_count;
 
3045
  gchar     *range    = NULL;
2918
3046
  gboolean   run;
2919
3047
 
2920
 
  gimp_ui_init ("ps", FALSE);
2921
 
 
2922
 
  dialog = gimp_dialog_new (_("Load PostScript"), "ps",
 
3048
  page_count = count_ps_pages (filename);
 
3049
 
 
3050
  gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
3051
 
 
3052
  dialog = gimp_dialog_new (_("Import from PostScript"), PLUG_IN_BINARY,
2923
3053
                            NULL, 0,
2924
 
                            gimp_standard_help_func, "file-ps-load",
2925
 
 
2926
 
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2927
 
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
2928
 
 
2929
 
                            NULL);
 
3054
                            gimp_standard_help_func, LOAD_PS_PROC,
 
3055
 
 
3056
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
3057
                            _("_Import"),     GTK_RESPONSE_OK,
 
3058
 
 
3059
                            NULL);
 
3060
 
 
3061
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
3062
                                           GTK_RESPONSE_OK,
 
3063
                                           GTK_RESPONSE_CANCEL,
 
3064
                                           -1);
2930
3065
 
2931
3066
  main_vbox = gtk_vbox_new (FALSE, 12);
2932
3067
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
2933
3068
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), main_vbox,
2934
 
                      FALSE, FALSE, 0);
 
3069
                      TRUE, TRUE, 0);
2935
3070
  gtk_widget_show (main_vbox);
2936
3071
 
 
3072
  if (page_count > 1)
 
3073
    {
 
3074
      selector = gimp_page_selector_new ();
 
3075
      gtk_box_pack_start (GTK_BOX (main_vbox), selector, TRUE, TRUE, 0);
 
3076
      gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (selector),
 
3077
                                      page_count);
 
3078
      gimp_page_selector_set_target (GIMP_PAGE_SELECTOR (selector),
 
3079
                                     ps_pagemode);
 
3080
 
 
3081
      gtk_widget_show (selector);
 
3082
 
 
3083
      g_signal_connect_swapped (selector, "activate",
 
3084
                                G_CALLBACK (gtk_window_activate_default),
 
3085
                                dialog);
 
3086
    }
 
3087
 
2937
3088
  hbox = gtk_hbox_new (TRUE, 12);
2938
3089
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
2939
3090
  gtk_widget_show (hbox);
2953
3104
  gtk_widget_show (table);
2954
3105
 
2955
3106
  spinbutton = gimp_spin_button_new (&adj, plvals.resolution,
2956
 
                                     5, 1440, 1, 10, 0, 1, 0);
 
3107
                                     5, 1440, 1, 10, 0, 1, 0);
2957
3108
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
2958
 
                             _("Resolution:"), 0.0, 0.5,
2959
 
                             spinbutton, 1, FALSE);
2960
 
  g_signal_connect (adj, "value_changed",
 
3109
                             _("Resolution:"), 0.0, 0.5,
 
3110
                             spinbutton, 1, FALSE);
 
3111
          
 
3112
  g_signal_connect (adj, "value-changed",
 
3113
                    G_CALLBACK (resolution_change_callback),
 
3114
                    &plvals.resolution);
 
3115
          
 
3116
  g_signal_connect (adj, "value-changed",
2961
3117
                    G_CALLBACK (gimp_int_adjustment_update),
2962
3118
                    &plvals.resolution);
2963
3119
 
2964
 
  spinbutton = gimp_spin_button_new (&adj, plvals.width,
2965
 
                                     1, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 0);
 
3120
 
 
3121
          
 
3122
  ps_width_spinbutton = gimp_spin_button_new (&adj, plvals.width,
 
3123
                                              1, GIMP_MAX_IMAGE_SIZE, 
 
3124
                                              1, 10, 0, 1, 0);
2966
3125
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
2967
 
                             _("_Width:"), 0.0, 0.5,
2968
 
                             spinbutton, 1, FALSE);
2969
 
  g_signal_connect (adj, "value_changed",
 
3126
                             _("_Width:"), 0.0, 0.5,
 
3127
                             ps_width_spinbutton, 1, FALSE);
 
3128
  g_signal_connect (adj, "value-changed",
2970
3129
                    G_CALLBACK (gimp_int_adjustment_update),
2971
3130
                    &plvals.width);
2972
3131
 
2973
 
  spinbutton = gimp_spin_button_new (&adj, plvals.height,
2974
 
                                     1, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 0);
 
3132
  ps_height_spinbutton = gimp_spin_button_new (&adj, plvals.height,
 
3133
                                               1, GIMP_MAX_IMAGE_SIZE, 
 
3134
                                               1, 10, 0, 1, 0);
2975
3135
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
2976
 
                             _("_Height:"), 0.0, 0.5,
2977
 
                             spinbutton, 1, FALSE);
2978
 
  g_signal_connect (adj, "value_changed",
 
3136
                             _("_Height:"), 0.0, 0.5,
 
3137
                             ps_height_spinbutton, 1, FALSE);
 
3138
  g_signal_connect (adj, "value-changed",
2979
3139
                    G_CALLBACK (gimp_int_adjustment_update),
2980
3140
                    &plvals.height);
2981
3141
 
2982
 
  entry = gtk_entry_new ();
2983
 
  gtk_widget_set_size_request (entry, 80, -1);
2984
 
  gtk_entry_set_text (GTK_ENTRY (entry), plvals.pages);
2985
 
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
2986
 
                             _("Pages:"), 0.0, 0.5,
2987
 
                             entry, 1, FALSE);
2988
 
  g_signal_connect (entry, "changed",
2989
 
                    G_CALLBACK (load_pages_entry_callback),
2990
 
                    NULL);
2991
 
  gimp_help_set_help_data (GTK_WIDGET (entry),
2992
 
                           _("Pages to load (e.g.: 1-4 or 1,3,5-7)"), NULL);
 
3142
  if (loadPDF || page_count == 0)
 
3143
    {
 
3144
      entry = gtk_entry_new ();
 
3145
      gtk_widget_set_size_request (entry, 80, -1);
 
3146
      gtk_entry_set_text (GTK_ENTRY (entry), plvals.pages);
 
3147
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
 
3148
                                 _("Pages:"), 0.0, 0.5,
 
3149
                                 entry, 1, FALSE);
 
3150
 
 
3151
      g_signal_connect (entry, "changed",
 
3152
                        G_CALLBACK (load_pages_entry_callback),
 
3153
                        NULL);
 
3154
      gimp_help_set_help_data (GTK_WIDGET (entry),
 
3155
                               _("Pages to load (e.g.: 1-4 or 1,3,5-7)"), NULL);
 
3156
 
 
3157
      target = gtk_combo_box_new_text ();
 
3158
      gtk_combo_box_insert_text (GTK_COMBO_BOX (target),
 
3159
                                 GIMP_PAGE_SELECTOR_TARGET_LAYERS, _("Layers"));
 
3160
      gtk_combo_box_insert_text (GTK_COMBO_BOX (target),
 
3161
                                 GIMP_PAGE_SELECTOR_TARGET_IMAGES, _("Images"));
 
3162
      gtk_combo_box_set_active (GTK_COMBO_BOX (target), (int) ps_pagemode);
 
3163
      gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
 
3164
                                 _("Open as"), 0.0, 0.5,
 
3165
                                 target, 1, FALSE);
 
3166
    }
2993
3167
 
2994
3168
  toggle = gtk_check_button_new_with_label (_("Try Bounding Box"));
2995
3169
  gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
3005
3179
 
3006
3180
  /* Colouring */
3007
3181
  frame = gimp_int_radio_group_new (TRUE, _("Coloring"),
3008
 
                                    G_CALLBACK (gimp_radio_button_update),
3009
 
                                    &plvals.pnm_type, plvals.pnm_type,
3010
 
 
3011
 
                                    _("B/W"),       4, NULL,
3012
 
                                    _("Gray"),      5, NULL,
3013
 
                                    _("Color"),     6, NULL,
3014
 
                                    _("Automatic"), 7, NULL,
3015
 
 
3016
 
                                    NULL);
 
3182
                                    G_CALLBACK (gimp_radio_button_update),
 
3183
                                    &plvals.pnm_type, plvals.pnm_type,
 
3184
 
 
3185
                                    _("B/W"),       4, NULL,
 
3186
                                    _("Gray"),      5, NULL,
 
3187
                                    _("Color"),     6, NULL,
 
3188
                                    _("Automatic"), 7, NULL,
 
3189
 
 
3190
                                    NULL);
3017
3191
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
3018
3192
  gtk_widget_show (frame);
3019
3193
 
3022
3196
  gtk_widget_show (hbox);
3023
3197
 
3024
3198
  frame = gimp_int_radio_group_new (TRUE, _("Text antialiasing"),
3025
 
                                    G_CALLBACK (gimp_radio_button_update),
3026
 
                                    &plvals.textalpha, plvals.textalpha,
3027
 
 
3028
 
                                    _("None"),   1, NULL,
3029
 
                                    _("Weak"),   2, NULL,
3030
 
                                    _("Strong"), 4, NULL,
3031
 
 
3032
 
                                    NULL);
 
3199
                                    G_CALLBACK (gimp_radio_button_update),
 
3200
                                    &plvals.textalpha, plvals.textalpha,
 
3201
 
 
3202
                                    _("None"),   1, NULL,
 
3203
                                    _("Weak"),   2, NULL,
 
3204
                                    _("Strong"), 4, NULL,
 
3205
 
 
3206
                                    NULL);
3033
3207
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
3034
3208
  gtk_widget_show (frame);
3035
3209
 
3036
3210
  frame = gimp_int_radio_group_new (TRUE, _("Graphic antialiasing"),
3037
 
                                    G_CALLBACK (gimp_radio_button_update),
3038
 
                                    &plvals.graphicsalpha, plvals.graphicsalpha,
3039
 
 
3040
 
                                    _("None"),   1, NULL,
3041
 
                                    _("Weak"),   2, NULL,
3042
 
                                    _("Strong"), 4, NULL,
3043
 
 
3044
 
                                    NULL);
 
3211
                                    G_CALLBACK (gimp_radio_button_update),
 
3212
                                    &plvals.graphicsalpha, plvals.graphicsalpha,
 
3213
 
 
3214
                                    _("None"),   1, NULL,
 
3215
                                    _("Weak"),   2, NULL,
 
3216
                                    _("Strong"), 4, NULL,
 
3217
 
 
3218
                                    NULL);
3045
3219
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, TRUE, 0);
3046
3220
  gtk_widget_show (frame);
3047
3221
 
3049
3223
 
3050
3224
  run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
3051
3225
 
 
3226
  if (selector)
 
3227
    {
 
3228
      range = gimp_page_selector_get_selected_range (GIMP_PAGE_SELECTOR (selector));
 
3229
 
 
3230
      if (strlen (range) < 1)
 
3231
        {
 
3232
          gimp_page_selector_select_all (GIMP_PAGE_SELECTOR (selector));
 
3233
          range = gimp_page_selector_get_selected_range (GIMP_PAGE_SELECTOR (selector));
 
3234
        }
 
3235
 
 
3236
      strncpy (plvals.pages, range, sizeof (plvals.pages));
 
3237
      plvals.pages[strlen (range)] = '\0';
 
3238
 
 
3239
      ps_pagemode = gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (selector));
 
3240
    }
 
3241
  else if (loadPDF || page_count == 0)
 
3242
    {
 
3243
      ps_pagemode = gtk_combo_box_get_active (GTK_COMBO_BOX (target));
 
3244
    }
 
3245
  else
 
3246
    {
 
3247
      strncpy (plvals.pages, "1", 1);
 
3248
      plvals.pages[1] = '\0';
 
3249
      ps_pagemode = GIMP_PAGE_SELECTOR_TARGET_IMAGES;
 
3250
    }
 
3251
 
3052
3252
  gtk_widget_destroy (dialog);
3053
3253
 
3054
3254
  return run;
3056
3256
 
3057
3257
static void
3058
3258
load_pages_entry_callback (GtkWidget *widget,
3059
 
                           gpointer   data)
 
3259
                           gpointer   data)
3060
3260
{
3061
3261
  gsize nelem = sizeof (plvals.pages);
3062
3262
 
3085
3285
  vals = g_new (SaveDialogVals, 1);
3086
3286
  vals->level = (psvals.level > 1);
3087
3287
 
3088
 
  dialog = gimp_dialog_new (_("Save as PostScript"), "ps",
 
3288
  dialog = gimp_dialog_new (_("Save as PostScript"), PLUG_IN_BINARY,
3089
3289
                            NULL, 0,
3090
 
                            gimp_standard_help_func, "file-ps-save",
3091
 
 
3092
 
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
3093
 
                            GTK_STOCK_OK,     GTK_RESPONSE_OK,
3094
 
 
3095
 
                            NULL);
 
3290
                            gimp_standard_help_func, SAVE_PS_PROC,
 
3291
 
 
3292
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
3293
                            GTK_STOCK_SAVE,   GTK_RESPONSE_OK,
 
3294
 
 
3295
                            NULL);
 
3296
 
 
3297
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
3298
                                           GTK_RESPONSE_OK,
 
3299
                                           GTK_RESPONSE_CANCEL,
 
3300
                                           -1);
 
3301
 
 
3302
  gimp_window_set_transient (GTK_WINDOW (dialog));
3096
3303
 
3097
3304
  /* Main hbox */
3098
3305
  hbox = gtk_hbox_new (FALSE, 12);
3123
3330
  gtk_widget_show (table);
3124
3331
 
3125
3332
  spinbutton = gimp_spin_button_new (&vals->adjustment[0], psvals.width,
3126
 
                                     1e-5, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
 
3333
                                     1e-5, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
3127
3334
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
3128
 
                             _("_Width:"), 0.0, 0.5,
3129
 
                             spinbutton, 1, FALSE);
3130
 
  g_signal_connect (vals->adjustment[0], "value_changed",
 
3335
                             _("_Width:"), 0.0, 0.5,
 
3336
                             spinbutton, 1, FALSE);
 
3337
  g_signal_connect (vals->adjustment[0], "value-changed",
3131
3338
                    G_CALLBACK (gimp_double_adjustment_update),
3132
3339
                    &psvals.width);
3133
3340
 
3134
3341
  spinbutton = gimp_spin_button_new (&vals->adjustment[1], psvals.height,
3135
 
                                     1e-5, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
 
3342
                                     1e-5, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
3136
3343
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
3137
 
                             _("_Height:"), 0.0, 0.5,
3138
 
                             spinbutton, 1, FALSE);
3139
 
  g_signal_connect (vals->adjustment[1], "value_changed",
 
3344
                             _("_Height:"), 0.0, 0.5,
 
3345
                             spinbutton, 1, FALSE);
 
3346
  g_signal_connect (vals->adjustment[1], "value-changed",
3140
3347
                    G_CALLBACK (gimp_double_adjustment_update),
3141
3348
                    &psvals.height);
3142
3349
 
3143
3350
  spinbutton = gimp_spin_button_new (&vals->adjustment[2], psvals.x_offset,
3144
 
                                     0.0, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
 
3351
                                     0.0, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
3145
3352
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
3146
 
                             _("_X offset:"), 0.0, 0.5,
3147
 
                             spinbutton, 1, FALSE);
3148
 
  g_signal_connect (vals->adjustment[2], "value_changed",
 
3353
                             _("_X offset:"), 0.0, 0.5,
 
3354
                             spinbutton, 1, FALSE);
 
3355
  g_signal_connect (vals->adjustment[2], "value-changed",
3149
3356
                    G_CALLBACK (gimp_double_adjustment_update),
3150
3357
                    &psvals.x_offset);
3151
3358
 
3152
3359
  spinbutton = gimp_spin_button_new (&vals->adjustment[3], psvals.y_offset,
3153
 
                                     0.0, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
 
3360
                                     0.0, GIMP_MAX_IMAGE_SIZE, 1, 10, 0, 1, 2);
3154
3361
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
3155
 
                             _("_Y offset:"), 0.0, 0.5,
3156
 
                             spinbutton, 1, FALSE);
3157
 
  g_signal_connect (vals->adjustment[3], "value_changed",
 
3362
                             _("_Y offset:"), 0.0, 0.5,
 
3363
                             spinbutton, 1, FALSE);
 
3364
  g_signal_connect (vals->adjustment[3], "value-changed",
3158
3365
                    G_CALLBACK (gimp_double_adjustment_update),
3159
3366
                    &psvals.y_offset);
3160
3367
 
3164
3371
  gtk_widget_show (toggle);
3165
3372
 
3166
3373
  gimp_help_set_help_data (toggle,
3167
 
                           _("When toggled, the resulting image will be scaled to fit "
3168
 
                             "into the given size without changing the aspect ratio."),
3169
 
                           "#keep_aspect_ratio"),
 
3374
                           _("When toggled, the resulting image will be "
 
3375
                             "scaled to fit into the given size without "
 
3376
                             "changing the aspect ratio."),
 
3377
                           "#keep_aspect_ratio"),
3170
3378
 
3171
3379
  g_signal_connect (toggle, "toggled",
3172
3380
                    G_CALLBACK (gimp_toggle_button_update),
3174
3382
 
3175
3383
  /* Unit */
3176
3384
  uframe = gimp_int_radio_group_new (TRUE, _("Unit"),
3177
 
                                     G_CALLBACK (save_unit_toggle_update),
3178
 
                                     vals, psvals.unit_mm,
3179
 
 
3180
 
                                     _("_Inch"),       FALSE, NULL,
3181
 
                                     _("_Millimeter"), TRUE,  NULL,
3182
 
 
3183
 
                                     NULL);
 
3385
                                     G_CALLBACK (save_unit_toggle_update),
 
3386
                                     vals, psvals.unit_mm,
 
3387
 
 
3388
                                     _("_Inch"),       FALSE, NULL,
 
3389
                                     _("_Millimeter"), TRUE,  NULL,
 
3390
 
 
3391
                                     NULL);
3184
3392
 
3185
3393
  gtk_box_pack_start (GTK_BOX (main_vbox[0]), uframe, TRUE, TRUE, 0);
3186
3394
  gtk_widget_show (uframe);
3190
3398
 
3191
3399
  /* Rotation */
3192
3400
  frame = gimp_int_radio_group_new (TRUE, _("Rotation"),
3193
 
                                    G_CALLBACK (gimp_radio_button_update),
3194
 
                                    &psvals.rotate, psvals.rotate,
3195
 
 
3196
 
                                    "_0",   0,   NULL,
3197
 
                                    "_90",  90,  NULL,
3198
 
                                    "_180", 180, NULL,
3199
 
                                    "_270", 270, NULL,
3200
 
 
3201
 
                                    NULL);
 
3401
                                    G_CALLBACK (gimp_radio_button_update),
 
3402
                                    &psvals.rotate, psvals.rotate,
 
3403
 
 
3404
                                    "_0",   0,   NULL,
 
3405
                                    "_90",  90,  NULL,
 
3406
                                    "_180", 180, NULL,
 
3407
                                    "_270", 270, NULL,
 
3408
 
 
3409
                                    NULL);
3202
3410
 
3203
3411
  gtk_box_pack_start (GTK_BOX (main_vbox[1]), frame, TRUE, TRUE, 0);
3204
3412
  gtk_widget_show (frame);
3247
3455
  gtk_widget_set_sensitive (table, psvals.preview);
3248
3456
 
3249
3457
  spinbutton = gimp_spin_button_new (&adj, psvals.preview_size,
3250
 
                                     0, 1024, 1, 10, 0, 1, 0);
 
3458
                                     0, 1024, 1, 10, 0, 1, 0);
3251
3459
  gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
3252
 
                             _("Preview _size:"), 1.0, 0.5,
3253
 
                             spinbutton, 1, FALSE);
 
3460
                             _("Preview _size:"), 1.0, 0.5,
 
3461
                             spinbutton, 1, FALSE);
3254
3462
  gtk_widget_show (spinbutton);
3255
3463
 
3256
 
  g_signal_connect (adj, "value_changed",
 
3464
  g_signal_connect (adj, "value-changed",
3257
3465
                    G_CALLBACK (gimp_int_adjustment_update),
3258
3466
                    &psvals.preview_size);
3259
3467
 
3276
3484
 
3277
3485
static void
3278
3486
save_unit_toggle_update (GtkWidget *widget,
3279
 
                         gpointer   data)
 
3487
                         gpointer   data)
3280
3488
{
3281
3489
  if (GTK_TOGGLE_BUTTON (widget)->active)
3282
3490
    {
3293
3501
      psvals.unit_mm = unit_mm;
3294
3502
 
3295
3503
      if (unit_mm)
3296
 
        factor = 25.4;
 
3504
        factor = 25.4;
3297
3505
      else
3298
 
        factor = 1.0 / 25.4;
 
3506
        factor = 1.0 / 25.4;
3299
3507
 
3300
3508
      for (i = 0; i < 4; i++)
3301
 
        {
3302
 
          value = GTK_ADJUSTMENT (vals->adjustment[i])->value * factor;
3303
 
 
3304
 
          gtk_adjustment_set_value (GTK_ADJUSTMENT (vals->adjustment[i]), value);
3305
 
        }
3306
 
    }
 
3509
        {
 
3510
          value = GTK_ADJUSTMENT (vals->adjustment[i])->value * factor;
 
3511
 
 
3512
          gtk_adjustment_set_value (GTK_ADJUSTMENT (vals->adjustment[i]),
 
3513
                                    value);
 
3514
        }
 
3515
    }
 
3516
}
 
3517
 
 
3518
static gboolean
 
3519
resolution_change_callback (GtkAdjustment *adjustment,
 
3520
                            gpointer       data)
 
3521
{
 
3522
  guint    *old_resolution = (guint *) data;
 
3523
  gdouble ratio;
 
3524
 
 
3525
  if (*old_resolution)
 
3526
    {
 
3527
      ratio = (gdouble) adjustment->value / *old_resolution; 
 
3528
    } 
 
3529
  else
 
3530
    {
 
3531
      ratio = 1;
 
3532
    }
 
3533
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (ps_width_spinbutton),
 
3534
                             GTK_SPIN_BUTTON (ps_width_spinbutton)->
 
3535
                                 adjustment->value * ratio);  
 
3536
 
 
3537
  gtk_spin_button_set_value (GTK_SPIN_BUTTON (ps_height_spinbutton),
 
3538
                             GTK_SPIN_BUTTON (ps_height_spinbutton)->
 
3539
                                 adjustment->value * ratio); 
 
3540
                                   
 
3541
  return TRUE;
 
3542
 
3307
3543
}