~ubuntu-branches/ubuntu/quantal/gutenprint/quantal

« back to all changes in this revision

Viewing changes to src/cups/rastertoprinter.c

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2012-02-14 22:41:51 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20120214224151-81lkvr2cow0u55f5
Tags: 5.2.8~pre1-0ubuntu1
* New upstream release
  - Added support for Canon BJC 4550, S330, S520, S530D, S630, S750, S820,
    S830D, S900, S9000, PIXMA mini220, mini320, mini360, i50, i70, i450,
    i455, i470D. i550, i900D, i950, i960, i6100, i6500, i9100, i9900,
    iP3300, iP3500, iP3600, iP4900, iP6210D, iP6220D, iP6310D, iP7100,
    iP7500, iP8100, iP8600, iP9910, MP140, MP190, MP210, MP240, MP375R,
    MP470, MP490, MP530, MP900, MG2100, MG3100, MG4100, MG5300, MG6200,
    MG8200, EPSON ME Office 940FW, PX 204, PX 504A, Stylus CX3900, NX530,
    NX635, SX535WD, Stylus Office BX535WD, BX630FW, BX635FWD, TX620FWD,
    Stylus Photo RX650, WorkForce 545, 630, 645, Stylus Pro 7900/9900
    (Partial -- no orange/green inks).
  - Printers redefined: Canon BJC 3000, S300, S500, S600, S800, PIXMA i80,
    i560, i850, i860, i865, iP2000, iP4100, iP5000, MP600, MP750, MP760,
    MP770, MP780, MP790, MP970
  - Support for the following printers was greatly improved, or tested:
    Canon PIXMA MP700, MP710, MP730, MP740, MP950, MP960, MX340, MX350,
    iP4000, MG5100
  - Canon BJC series printers using photo cartridge have printing modes
    added that will select this cartridge.
  - A crash with the EPSON Stylus Photo R3000 has been fixed.
  - Chinese (Mandarin), Galician, and Ukrainian translations have
    been added.
* debian/patches/0001-patch-stdio.h-is-required-by-commandtoepson-and-comm.patch:
  Removed, applied upstream.
* 0002-genppd-don-t-write-color-profile-information-with-br.patch: Refreshed
  with quilt.
* debian/printer-driver-gutenprint.ppd-updater,
  debian/foomatic-db-gutenprint.ppd-updater: Support also pre-releases with
  "-preX" version number extension.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * "$Id: rastertoprinter.c,v 1.137 2011/04/09 00:19:59 rlk Exp $"
 
2
 * "$Id: rastertoprinter.c,v 1.139 2011/12/18 16:20:31 rlk Exp $"
3
3
 *
4
4
 *   Gutenprint based raster filter for the Common UNIX Printing System.
5
5
 *
36
36
 * Include necessary headers...
37
37
 */
38
38
 
 
39
#if 0
 
40
#define ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
41
#endif
 
42
 
39
43
#ifdef HAVE_CONFIG_H
40
44
#include <config.h>
41
45
#endif
53
57
#include <limits.h>
54
58
#endif
55
59
#include "i18n.h"
 
60
#include <gutenprint/xml.h>
56
61
 
57
62
/* Solaris with gcc has problems because gcc's limits.h doesn't #define */
58
63
/* this */
64
69
 * Structure for page raster data...
65
70
 */
66
71
 
 
72
#if (CUPS_VERSION_MAJOR > 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR > 1))
 
73
#define CUPS_HEADER_T cups_page_header2_t
 
74
#define CUPS_READ_HEADER cupsRasterReadHeader2
 
75
#else
 
76
#define CUPS_HEADER_T cups_page_header_t
 
77
#define CUPS_READ_HEADER cupsRasterReadHeader
 
78
#endif
 
79
 
67
80
typedef struct
68
81
{
69
82
  cups_raster_t         *ras;           /* Raster stream to read from */
83
96
  int                   adjusted_height;
84
97
  int                   last_percent;
85
98
  int                   shrink_to_fit;
86
 
  cups_page_header_t    header;         /* Page header from file */
 
99
  CUPS_HEADER_T         header;         /* Page header from file */
87
100
} cups_image_t;
88
101
 
89
102
static void     cups_writefunc(void *file, const char *buf, size_t bytes);
114
127
static double total_bytes_printed = 0;
115
128
static int print_messages_as_errors = 0;
116
129
static int suppress_messages = 0;
117
 
static stp_string_list_t *po = NULL;
 
130
static int suppress_verbose_messages = 0;
 
131
static const stp_string_list_t *po = NULL;
 
132
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
133
static const char *save_file_name = NULL;
 
134
static const char *load_file_name = NULL;
 
135
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
 
136
 
 
137
extern void stpi_vars_print_error(const stp_vars_t *v, const char *prefix);
118
138
 
119
139
static void
120
140
set_string_parameter(stp_vars_t *v, const char *name, const char *val)
132
152
  stp_describe_parameter(v, name, &desc);
133
153
  if (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)
134
154
    {
135
 
      if (choice < 0)
 
155
#if 0
 
156
      if (stp_check_string_parameter(v, name, STP_PARAMETER_ACTIVE))
 
157
        {
 
158
          if (! suppress_messages)
 
159
            fprintf(stderr, "DEBUG: Gutenprint:   Not overriding special parameter %s (%s)\n",
 
160
                    name, stp_get_string_parameter(v, name));
 
161
        }
 
162
      else
 
163
#endif
 
164
        if (choice < 0)
136
165
        {
137
166
          stp_clear_string_parameter(v, name);
138
167
          if (! suppress_messages)
168
197
static void
169
198
print_debug_block(const stp_vars_t *v, const cups_image_t *cups)
170
199
{
171
 
  stp_parameter_list_t params;
172
 
  int nparams;
173
 
  int i;
174
200
  fprintf(stderr, "DEBUG: Gutenprint: Page data:\n");
175
201
  fprintf(stderr, "DEBUG: Gutenprint:   MediaClass = \"%s\"\n", cups->header.MediaClass);
176
202
  fprintf(stderr, "DEBUG: Gutenprint:   MediaColor = \"%s\"\n", cups->header.MediaColor);
221
247
  fprintf(stderr, "DEBUG: Gutenprint:   cupsRowCount = %d\n", cups->header.cupsRowCount);
222
248
  fprintf(stderr, "DEBUG: Gutenprint:   cupsRowFeed = %d\n", cups->header.cupsRowFeed);
223
249
  fprintf(stderr, "DEBUG: Gutenprint:   cupsRowStep = %d\n", cups->header.cupsRowStep);
224
 
  fprintf(stderr, "DEBUG: Gutenprint:   stp_get_driver(v) |%s|\n", stp_get_driver(v));
225
 
  fprintf(stderr, "DEBUG: Gutenprint:   stp_get_left(v) %d\n", stp_get_left(v));
226
 
  fprintf(stderr, "DEBUG: Gutenprint:   stp_get_top(v) %d\n", stp_get_top(v));
227
 
  fprintf(stderr, "DEBUG: Gutenprint:   stp_get_page_width(v) %d\n", stp_get_page_width(v));
228
 
  fprintf(stderr, "DEBUG: Gutenprint:   stp_get_page_height(v) %d\n", stp_get_page_height(v));
229
250
  fprintf(stderr, "DEBUG: Gutenprint:   shrink page to fit %d\n", cups->shrink_to_fit);
230
 
  params = stp_get_parameter_list(v);
231
 
  nparams = stp_parameter_list_count(params);
232
 
  for (i = 0; i < nparams; i++)
233
 
    {
234
 
      const stp_parameter_t *p = stp_parameter_list_param(params, i);
235
 
      switch (p->p_type)
236
 
        {
237
 
        case STP_PARAMETER_TYPE_STRING_LIST:
238
 
          fprintf(stderr, "DEBUG: Gutenprint:   stp_get_string %s(v) |%s| %d\n",
239
 
                  p->name, stp_get_string_parameter(v, p->name) ?
240
 
                  stp_get_string_parameter(v, p->name) : "NULL",
241
 
                  stp_get_string_parameter_active(v, p->name));
242
 
          break;
243
 
        case STP_PARAMETER_TYPE_DOUBLE:
244
 
          fprintf(stderr, "DEBUG: Gutenprint:   stp_get_float %s(v) |%.3f| %d\n",
245
 
                  p->name, stp_get_float_parameter(v, p->name),
246
 
                  stp_get_float_parameter_active(v, p->name));
247
 
          break;
248
 
        case STP_PARAMETER_TYPE_DIMENSION:
249
 
          fprintf(stderr, "DEBUG: Gutenprint:   stp_get_dimension %s(v) |%d| %d\n",
250
 
                  p->name, stp_get_dimension_parameter(v, p->name),
251
 
                  stp_get_dimension_parameter_active(v, p->name));
252
 
          break;
253
 
        case STP_PARAMETER_TYPE_INT:
254
 
          fprintf(stderr, "DEBUG: Gutenprint:   stp_get_int %s(v) |%d| %d\n",
255
 
                  p->name, stp_get_int_parameter(v, p->name),
256
 
                  stp_get_int_parameter_active(v, p->name));
257
 
          break;
258
 
        case STP_PARAMETER_TYPE_BOOLEAN:
259
 
          fprintf(stderr, "DEBUG: Gutenprint:   stp_get_boolean %s(v) |%d| %d\n",
260
 
                  p->name, stp_get_boolean_parameter(v, p->name),
261
 
                  stp_get_boolean_parameter_active(v, p->name));
262
 
          break;
263
 
          /*
264
 
           * We don't handle raw, curve, or filename arguments.
265
 
           */
266
 
        default:
267
 
          break;
268
 
        }
269
 
    }
 
251
  stpi_vars_print_error(v, "DEBUG");
270
252
  fprintf(stderr, "DEBUG: Gutenprint: End page data\n");
271
 
  stp_parameter_list_destroy(params);
272
253
}
273
254
 
274
255
static int
290
271
  int nparams = stp_parameter_list_count(params);
291
272
  int i;
292
273
  if (! suppress_messages)
293
 
    fprintf(stderr, "DEBUG: Gutenprint: Validating options\n");
 
274
    fprintf(stderr, "DEBUG: Gutenprint:   Validating options\n");
294
275
  for (i = 0; i < nparams; i++)
295
276
    {
296
277
      const stp_parameter_t *param = stp_parameter_list_param(params, i);
304
285
              if (! suppress_messages)
305
286
                {
306
287
                  const char *val = stp_get_string_parameter(v, desc.name);
307
 
                  fprintf(stderr, "DEBUG: Gutenprint:   Clearing string %s (%s)\n",
 
288
                  fprintf(stderr, "DEBUG: Gutenprint:     Clearing string %s (%s)\n",
308
289
                          desc.name, val ? val : "(null)");
309
290
                }
310
291
              stp_clear_string_parameter(v, desc.name);
311
292
              if (!desc.read_only && desc.is_mandatory && desc.is_active)
312
293
                {
313
294
                  if (! suppress_messages)
314
 
                    fprintf(stderr, "DEBUG: Gutenprint:   Setting default string %s to %s\n",
 
295
                    fprintf(stderr, "DEBUG: Gutenprint:     Setting default string %s to %s\n",
315
296
                            desc.name, desc.deflt.str ? desc.deflt.str : "(null)");
316
297
                  stp_set_string_parameter(v, desc.name, desc.deflt.str);
317
298
                  if (strcmp(desc.name, "PageSize") == 0)
321
302
                      if (ps->width > 0)
322
303
                        {
323
304
                          if (! suppress_messages)
324
 
                            fprintf(stderr, "DEBUG: Gutenprint:   Setting page width to %d\n",
 
305
                            fprintf(stderr, "DEBUG: Gutenprint:     Setting page width to %d\n",
325
306
                                    ps->width);
326
307
                          if (ps->width < stp_get_page_width(v))
327
308
                            stp_set_page_width(v, ps->width);
329
310
                      if (ps->height > 0)
330
311
                        {
331
312
                          if (! suppress_messages)
332
 
                            fprintf(stderr, "DEBUG: Gutenprint:   Setting page height to %d\n",
 
313
                            fprintf(stderr, "DEBUG: Gutenprint:     Setting page height to %d\n",
333
314
                                    ps->height);
334
315
                          if (ps->height < stp_get_page_height(v))
335
316
                            stp_set_page_height(v, ps->height);
341
322
      stp_parameter_description_destroy(&desc);
342
323
    }
343
324
  if (! suppress_messages)
344
 
    fprintf(stderr, "DEBUG: Gutenprint: Done validating options\n");
 
325
    fprintf(stderr, "DEBUG: Gutenprint:   Done validating options\n");
345
326
  stp_parameter_list_destroy(params);
346
327
}
347
328
 
472
453
        set_string_parameter(v, "Duplex", "DuplexNoTumble");
473
454
    }
474
455
 
475
 
  cups->shrink_to_fit = stp_get_int_parameter(v, "CUPSShrinkPage");
 
456
  cups->shrink_to_fit =
 
457
    (stp_check_int_parameter(v, "CUPSShrinkPage", STP_PARAMETER_ACTIVE) ?
 
458
     stp_get_int_parameter(v, "CUPSShrinkPage") : 0);
476
459
 
477
460
  set_string_parameter(v, "JobMode", "Job");
478
461
  validate_options(v, cups);
483
466
                         &(cups->bottom), &(cups->top));
484
467
  if (! suppress_messages)
485
468
    {
486
 
      fprintf(stderr, "DEBUG:   Gutenprint: limits w %d l %d r %d  h %d t %d b %d\n",
 
469
      fprintf(stderr, "DEBUG: Gutenprint:   limits w %d l %d r %d  h %d t %d b %d\n",
487
470
              cups->width, cups->left, cups->right, cups->height, cups->top, cups->bottom);
488
 
      fprintf(stderr, "DEBUG:   Gutenprint: max limits l %d r %d t %d b %d\n",
 
471
      fprintf(stderr, "DEBUG: Gutenprint:   max limits l %d r %d t %d b %d\n",
489
472
              tmp_left, tmp_right, tmp_top, tmp_bottom);
490
473
    }
491
474
 
509
492
      else
510
493
        cups->left_trim = 0;
511
494
      if (! suppress_messages)
512
 
        fprintf(stderr, "DEBUG:   Gutenprint: left margin %d\n", cups->left_trim);
 
495
        fprintf(stderr, "DEBUG: Gutenprint:   left margin %d\n", cups->left_trim);
513
496
    }
514
497
  else
515
498
    {
625
608
  if (cups->adjusted_height > cups->header.cupsHeight)
626
609
    cups->adjusted_height = cups->header.cupsHeight;
627
610
  if (! suppress_messages)
628
 
    fprintf(stderr, "DEBUG: Gutenprint:   CUPS settings w %d (%d) l %d r %d  h %d (%d) t %d b %d\n",
629
 
            cups->width, cups->adjusted_width, cups->left, cups->right,
630
 
            cups->height, cups->adjusted_height, cups->top, cups->bottom);
 
611
    {
 
612
      fprintf(stderr, "DEBUG: Gutenprint:   CUPS settings w %d l %d r %d  h %d t %d b %d\n",
 
613
              cups->width, cups->left, cups->right,
 
614
              cups->height, cups->top, cups->bottom);
 
615
      fprintf(stderr, "DEBUG: Gutenprint:        adjusted w %d h %d\n",
 
616
              cups->adjusted_width, cups->adjusted_height);
 
617
 
 
618
    }
631
619
 
632
620
  if (! suppress_messages)
633
621
    fprintf(stderr, "DEBUG: Gutenprint: End initialize page\n");
641
629
  if (buffer)
642
630
    {
643
631
      if (! suppress_messages)
644
 
        fprintf(stderr, "DEBUG: Gutenprint: Purging %d rows\n",
645
 
                cups->header.cupsHeight - cups->row);
 
632
        fprintf(stderr, "DEBUG: Gutenprint: Purging %d row%s\n",
 
633
                cups->header.cupsHeight - cups->row,
 
634
                ((cups->header.cupsHeight - cups->row) == 1 ? "" : "s"));
646
635
      while (cups->row < cups->header.cupsHeight)
647
636
        {
648
637
          cupsRasterReadPixels(cups->ras, (unsigned char *)buffer,
758
747
          if (val && ((strlen(val) > 0 && strcmp(val, "None") != 0) ||
759
748
                      (desc.p_type == STP_PARAMETER_TYPE_STRING_LIST)))
760
749
            {
 
750
              stp_curve_t *curve;
 
751
              stp_raw_t *raw;
761
752
              switch (desc.p_type)
762
753
                {
763
754
                case STP_PARAMETER_TYPE_STRING_LIST:
792
783
                  stp_set_boolean_parameter
793
784
                    (v, desc.name, strcasecmp(val, "true") == 0 ? 1 : 0);
794
785
                  break;
795
 
                case STP_PARAMETER_TYPE_CURVE: /* figure this out later... */
 
786
                case STP_PARAMETER_TYPE_CURVE:
 
787
                  curve = stp_curve_create_from_string(val);
 
788
                  if (! suppress_messages)
 
789
                    fprintf(stderr, "DEBUG: Gutenprint:   Set curve %s to %s\n",
 
790
                            desc.name, curve ? val : "(NULL)");
 
791
                  if (curve)
 
792
                    {
 
793
                      stp_set_curve_parameter(v, desc.name, curve);
 
794
                      stp_curve_destroy(curve);
 
795
                    }
 
796
                  break;
 
797
                case STP_PARAMETER_TYPE_RAW: /* figure this out later, too */
 
798
                  raw = stp_xmlstrtoraw(val);
 
799
                  if (! suppress_messages)
 
800
                    fprintf(stderr, "DEBUG: Gutenprint:   Set raw %s to %s\n",
 
801
                            desc.name, raw ? val : "(NULL)");
 
802
                  if (raw)
 
803
                    {
 
804
                      stp_set_raw_parameter(v, desc.name, raw->data, raw->bytes);
 
805
                      stp_free((void *)raw->data);
 
806
                      stp_free(raw);
 
807
                    }
 
808
                  break;
796
809
                case STP_PARAMETER_TYPE_FILE: /* Probably not, security hole */
797
 
                case STP_PARAMETER_TYPE_RAW: /* figure this out later, too */
798
810
                  if (! suppress_messages)
799
811
                    fprintf(stderr, "DEBUG: Gutenprint:   Ignoring option %s %s type %d\n",
800
812
                            desc.name, val, desc.p_type);
806
818
          else if (val)
807
819
            {
808
820
              if (! suppress_messages)
809
 
                fprintf(stderr, "DEBUG: Gutenprint:   Not setting %s to '%s'\n",
 
821
                fprintf(stderr, "DEBUG: Gutenprint:     Not setting %s to '%s'\n",
810
822
                        desc.name, val);
811
823
            }
812
824
          else
813
825
            {
814
826
              if (! suppress_messages)
815
 
                fprintf(stderr, "DEBUG: Gutenprint:   Not setting %s to (null)\n",
 
827
                fprintf(stderr, "DEBUG: Gutenprint:     Not setting %s to (null)\n",
816
828
                        desc.name);
817
829
            }
818
830
        }
824
836
  stp_parameter_list_destroy(params);
825
837
}
826
838
 
 
839
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
840
static void
 
841
save_options(const char *save_name, const stp_vars_t *v)
 
842
{
 
843
  FILE *f_options;
 
844
  int i;
 
845
  stp_vars_t *c = stp_vars_create();
 
846
  stp_parameter_list_t params = stp_get_parameter_list(v);
 
847
  stp_parameter_t desc;
 
848
  stp_mxml_node_t *mxml = NULL;
 
849
  int param_count;
 
850
 
 
851
  if (!params)
 
852
    {
 
853
      stp_vars_destroy(c);
 
854
      return;
 
855
    }
 
856
  f_options = fopen(save_name, "w");
 
857
  if (!f_options)
 
858
    {
 
859
      stp_parameter_list_destroy(params);
 
860
      stp_vars_destroy(c);
 
861
      return;
 
862
    }
 
863
  param_count = stp_parameter_list_count(params);
 
864
  stp_set_driver(c, stp_get_driver(v));
 
865
  if (!suppress_messages)
 
866
    fprintf(stderr, "DEBUG: Gutenprint: Saving parameters to %s\n", save_name);
 
867
  for (i = 0; i < param_count; i++)
 
868
    {
 
869
      const stp_parameter_t *lparam =
 
870
        stp_parameter_list_param(params, i);
 
871
      stp_describe_parameter(v, lparam->name, &desc);
 
872
      if (desc.read_only || !strcmp(desc.name, "ChannelBitDepth") ||
 
873
          !stp_parameter_has_category_value(v, &desc, "Color", "Yes"))
 
874
        {
 
875
          if (!suppress_messages)
 
876
            fprintf(stderr, "DEBUG: Gutenprint:    skipping non-color %s\n",
 
877
                    desc.name);
 
878
          stp_parameter_description_destroy(&desc);
 
879
          continue;
 
880
        }
 
881
      switch (desc.p_type)
 
882
        {
 
883
        case STP_PARAMETER_TYPE_STRING_LIST:
 
884
          if (stp_check_string_parameter(v, desc.name,
 
885
                                         STP_PARAMETER_DEFAULTED))
 
886
            {
 
887
              if (!suppress_messages)
 
888
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING string %s %s\n",
 
889
                        desc.name, stp_get_string_parameter(v, desc.name));
 
890
              stp_set_string_parameter(c, desc.name,
 
891
                                       stp_get_string_parameter(v, desc.name));
 
892
            }
 
893
          else if (desc.is_mandatory)
 
894
            {
 
895
              if (!suppress_messages)
 
896
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted string %s %s\n",
 
897
                        desc.name, desc.deflt.str);
 
898
              stp_set_string_parameter(c, desc.name, desc.deflt.str);
 
899
            }
 
900
          else if (!suppress_messages)
 
901
            fprintf(stderr, "DEBUG: Gutenprint:    skipping string %s\n", desc.name);
 
902
          break;
 
903
        case STP_PARAMETER_TYPE_RAW:
 
904
          if (stp_check_raw_parameter(v, desc.name,
 
905
                                      STP_PARAMETER_DEFAULTED))
 
906
            {
 
907
              const stp_raw_t *raw = stp_get_raw_parameter(v, desc.name);
 
908
              if (!suppress_messages)
 
909
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING raw %s\n", desc.name);
 
910
              stp_set_raw_parameter(c, desc.name, raw->data, raw->bytes);
 
911
            }
 
912
          else if (!suppress_messages)
 
913
            fprintf(stderr, "DEBUG: Gutenprint:    skipping raw %s\n",
 
914
                    desc.name);
 
915
          break;
 
916
        case STP_PARAMETER_TYPE_BOOLEAN:
 
917
          if (stp_check_boolean_parameter(v, desc.name, STP_PARAMETER_DEFAULTED))
 
918
            {
 
919
              if (!suppress_messages)
 
920
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING bool %s %d\n",
 
921
                        desc.name, stp_get_boolean_parameter(v, desc.name));
 
922
              stp_set_boolean_parameter(c, desc.name,
 
923
                                        stp_get_boolean_parameter(v, desc.name));
 
924
            }
 
925
          else if (desc.is_mandatory)
 
926
            {
 
927
              if (!suppress_messages)
 
928
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted bool %s %d\n",
 
929
                        desc.name, desc.deflt.boolean);
 
930
              stp_set_boolean_parameter(c, desc.name, desc.deflt.boolean);
 
931
            }
 
932
          else if (!suppress_messages)
 
933
            fprintf(stderr, "DEBUG: Gutenprint:    skipping bool %s\n", desc.name);
 
934
          break;
 
935
        case STP_PARAMETER_TYPE_INT:
 
936
          if (stp_check_int_parameter(v, desc.name, STP_PARAMETER_DEFAULTED))
 
937
            {
 
938
              if (!suppress_messages)
 
939
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING int %s %d\n",
 
940
                        desc.name, stp_get_int_parameter(v, desc.name));
 
941
              stp_set_int_parameter(c, desc.name, stp_get_int_parameter(v, desc.name));
 
942
            }
 
943
          else if (desc.is_mandatory)
 
944
            {
 
945
              if (!suppress_messages)
 
946
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted int %s %d\n",
 
947
                        desc.name, desc.deflt.integer);
 
948
              stp_set_int_parameter(c, desc.name, desc.deflt.integer);
 
949
            }
 
950
          else if (!suppress_messages)
 
951
            fprintf(stderr, "DEBUG: Gutenprint:    skipping int %s\n", desc.name);
 
952
          break;
 
953
        case STP_PARAMETER_TYPE_DOUBLE:
 
954
          if (stp_check_float_parameter(v, desc.name, STP_PARAMETER_DEFAULTED))
 
955
            {
 
956
              if (!suppress_messages)
 
957
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING float %s %f\n",
 
958
                        desc.name, stp_get_float_parameter(v, desc.name));
 
959
              stp_set_float_parameter(c, desc.name,
 
960
                                      stp_get_float_parameter(v, desc.name));
 
961
            }
 
962
          else if (desc.is_mandatory)
 
963
            {
 
964
              if (!suppress_messages)
 
965
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted float %s %f\n",
 
966
                        desc.name, desc.deflt.dbl);
 
967
              stp_set_float_parameter(c, desc.name, desc.deflt.dbl);
 
968
            }
 
969
          else if (!suppress_messages)
 
970
            fprintf(stderr, "DEBUG: Gutenprint:    skipping float %s\n", desc.name);
 
971
          break;
 
972
        case STP_PARAMETER_TYPE_DIMENSION:
 
973
          if (stp_check_dimension_parameter(v, desc.name, STP_PARAMETER_DEFAULTED))
 
974
            {
 
975
              if (!suppress_messages)
 
976
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING dimension %s %d\n",
 
977
                        desc.name, stp_get_dimension_parameter(v, desc.name));
 
978
              stp_set_dimension_parameter(c, desc.name,
 
979
                                          stp_get_dimension_parameter(v, desc.name));
 
980
            }
 
981
          else if (desc.is_mandatory)
 
982
            {
 
983
              if (!suppress_messages)
 
984
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted dimension %s %d\n",
 
985
                        desc.name, desc.deflt.dimension);
 
986
              stp_set_dimension_parameter(c, desc.name, desc.deflt.dimension);
 
987
            }
 
988
          else if (!suppress_messages)
 
989
            fprintf(stderr, "DEBUG: Gutenprint:    skipping dimension %s\n", desc.name);
 
990
          break;
 
991
        case STP_PARAMETER_TYPE_CURVE:
 
992
          if (stp_check_curve_parameter(v, desc.name, STP_PARAMETER_DEFAULTED))
 
993
            {
 
994
              if (!suppress_messages)
 
995
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING curve %s\n", desc.name);
 
996
              stp_set_curve_parameter(c, desc.name,
 
997
                                      stp_get_curve_parameter(v, desc.name));
 
998
            }
 
999
          else if (desc.is_mandatory)
 
1000
            {
 
1001
              if (!suppress_messages)
 
1002
                fprintf(stderr, "DEBUG: Gutenprint:  SAVING defaulted curve %s\n", desc.name);
 
1003
              stp_set_curve_parameter(c, desc.name, desc.deflt.curve);
 
1004
            }
 
1005
          else if (!suppress_messages)
 
1006
            fprintf(stderr, "DEBUG: Gutenprint:    skipping curve %s\n",
 
1007
                    desc.name);
 
1008
          break;
 
1009
        default:
 
1010
          if (!suppress_messages)
 
1011
            fprintf(stderr, "DEBUG: Gutenprint:   Ignoring unknown type parameter %s (%d)\n",
 
1012
                    desc.name, desc.p_type);
 
1013
          break;
 
1014
        }
 
1015
      stp_parameter_description_destroy(&desc);
 
1016
    }
 
1017
  stp_parameter_list_destroy(params);
 
1018
  mxml = stp_xmltree_create_from_vars(c);
 
1019
  if (mxml)
 
1020
    {
 
1021
      fputs("<?xml version=\"1.0\"?>\n\n", f_options);
 
1022
      stp_mxmlSaveFile(mxml, f_options, STP_MXML_NO_CALLBACK);
 
1023
      stp_mxmlDelete(mxml);
 
1024
    }
 
1025
  (void) fclose(f_options);
 
1026
  stp_vars_destroy(c);
 
1027
  if (!suppress_messages)
 
1028
    fprintf(stderr, "DEBUG: Gutenprint: Done saving parameters to %s\n", save_name);
 
1029
}
 
1030
 
 
1031
static stp_vars_t *
 
1032
load_options(const char *load_name)
 
1033
{
 
1034
  FILE *f_options = fopen(load_name, "r");
 
1035
  if (f_options)
 
1036
    {
 
1037
      stp_vars_t *settings = NULL;
 
1038
      stp_mxml_node_t *mxml;
 
1039
      mxml = stp_mxmlLoadFile(NULL, f_options, STP_MXML_NO_CALLBACK);
 
1040
      if (mxml)
 
1041
        {
 
1042
          stp_mxml_node_t *nxml =
 
1043
            stp_mxmlFindElement(mxml, mxml, "vars", NULL, NULL,
 
1044
                                STP_MXML_DESCEND);
 
1045
          if (nxml)
 
1046
            {
 
1047
              settings = stp_vars_create_from_xmltree_ref(nxml->child, mxml);
 
1048
              if (! suppress_messages)
 
1049
                fprintf(stderr, "DEBUG: Gutenprint: loading options from %s\n",
 
1050
                        load_file_name);
 
1051
              if (! suppress_messages)
 
1052
                stpi_vars_print_error(settings, "DEBUG");
 
1053
            }
 
1054
        }
 
1055
      else
 
1056
        fprintf(stderr, "DEBUG: Unable to load options from %s\n",
 
1057
                load_file_name);
 
1058
      fclose(f_options);
 
1059
      return settings;
 
1060
    }
 
1061
  return NULL;
 
1062
}
 
1063
 
 
1064
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
 
1065
 
827
1066
/*
828
1067
 * 'main()' - Main entry and processing of driver.
829
1068
 */
851
1090
  struct timeval        t1, t2;
852
1091
  struct timezone       tz;
853
1092
  char                  *page_size_name = NULL;
 
1093
  int                   aborted = 0;
 
1094
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
1095
  stp_vars_t            *loaded_settings = NULL;
 
1096
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
854
1097
 
855
1098
 
856
1099
 /*
862
1105
  if (getenv("STP_SUPPRESS_MESSAGES"))
863
1106
    suppress_messages = 1;
864
1107
 
 
1108
  if (getenv("STP_SUPPRESS_VERBOSE_MESSAGES"))
 
1109
    suppress_verbose_messages = 1;
 
1110
 
865
1111
 /*
866
1112
  * Initialize libgutenprint
867
1113
  */
893
1139
 
894
1140
  if (! suppress_messages)
895
1141
    {
896
 
      fprintf(stderr, "DEBUG: Gutenprint %s Starting\n", version_id);
897
 
      fprintf(stderr, "DEBUG: Gutenprint command line: %s '%s' '%s' '%s' '%s' %s%s%s%s\n",
 
1142
      fprintf(stderr, "DEBUG: Gutenprint: ============================================================\n");
 
1143
      fprintf(stderr, "DEBUG: Gutenprint: VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
 
1144
      fprintf(stderr, "DEBUG: Gutenprint: %s Starting\n", version_id);
 
1145
      fprintf(stderr, "DEBUG: Gutenprint: command line: %s '%s' '%s' '%s' '%s' %s%s%s%s\n",
898
1146
              argv[0], argv[1], argv[2], argv[3], argv[4], "<args>",
899
1147
              argc >= 7 ? " '" : "",
900
1148
              argc >= 7 ? argv[6] : "",
911
1159
    return (1);
912
1160
  }
913
1161
  if (! suppress_messages)
914
 
    fprintf(stderr, "DEBUG: Gutenprint using PPD file %s\n", ppdfile);
 
1162
    fprintf(stderr, "DEBUG: Gutenprint: using PPD file %s\n", ppdfile);
915
1163
 
916
1164
  if ((ppd = ppdOpenFile(ppdfile)) == NULL)
917
1165
  {
960
1208
    fprintf(stderr, "DEBUG: Gutenprint: If you have upgraded your version of Gutenprint\n");
961
1209
    fprintf(stderr, "DEBUG: Gutenprint: recently, you must reinstall all printer queues.\n");
962
1210
    fprintf(stderr, "DEBUG: Gutenprint: If the previous installed version of Gutenprint\n");
963
 
    fprintf(stderr, "DEBUG: Gutenprint: was 4.3.19 or higher, you can use the `cups-genppdupdate.%s'\n", release_version_id);
 
1211
    fprintf(stderr, "DEBUG: Gutenprint: was 5.0.0 or higher, you can use the `cups-genppdupdate.%s'\n", release_version_id);
964
1212
    fprintf(stderr, "DEBUG: Gutenprint: program to do this; if the previous installed version\n");
965
1213
    fprintf(stderr, "DEBUG: Gutenprint: was older, you can use the Modify Printer command via\n");
966
1214
    fprintf(stderr, "DEBUG: Gutenprint: the CUPS web interface: http://localhost:631/printers.\n");
988
1236
    {
989
1237
      int i;
990
1238
      for (i = 0; i < num_options; i++)
991
 
        if (! suppress_messages)
992
 
          fprintf(stderr, "DEBUG: Gutenprint: CUPS option %d %s = %s\n",
993
 
                  i, options[i].name, options[i].value);
 
1239
        {
 
1240
          if (! suppress_messages)
 
1241
            fprintf(stderr, "DEBUG: Gutenprint:  CUPS option %d %s = %s\n",
 
1242
                    i, options[i].name, options[i].value);
 
1243
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
1244
          if (!strcmp(options[i].name, "SaveFileName"))
 
1245
            save_file_name = options[i].value;
 
1246
          if (!strcmp(options[i].name, "LoadFileName"))
 
1247
            load_file_name = options[i].value;
 
1248
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
 
1249
        }
994
1250
    }
995
1251
 
996
1252
 /*
1031
1287
    fprintf(stderr, "DEBUG: Gutenprint: Using fd %d\n", fd);
1032
1288
 
1033
1289
  stp_set_printer_defaults(default_settings, printer);
 
1290
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
1291
  if (load_file_name)
 
1292
    loaded_settings = load_options(load_file_name);
 
1293
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
1034
1294
  stp_set_float_parameter(default_settings, "AppGamma", 1.0);
1035
1295
  set_all_options(default_settings, options, num_options, ppd);
1036
 
  stp_merge_printvars(default_settings, stp_printer_get_defaults(printer));
 
1296
 
1037
1297
  ppdClose(ppd);
1038
1298
 
1039
1299
  cups.ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
1052
1312
   * the page.
1053
1313
   */
1054
1314
  signal(SIGTERM, cancel_job);
1055
 
  while (cupsRasterReadHeader(cups.ras, &cups.header))
 
1315
  while (CUPS_READ_HEADER(cups.ras, &cups.header))
1056
1316
    {
1057
1317
      /*
1058
1318
       * We don't know how many pages we're going to print, and
1070
1330
       */
1071
1331
      if (! suppress_messages)
1072
1332
        {
1073
 
          fprintf(stderr, "DEBUG: Gutenprint: Printing page %d\n", cups.page + 1);
 
1333
          fprintf(stderr, "DEBUG: Gutenprint: ================ Printing page %d      ================\n", cups.page + 1);
1074
1334
          fprintf(stderr, "PAGE: %d 1\n", cups.page + 1);
1075
1335
        }
1076
1336
      v = initialize_page(&cups, default_settings, page_size_name);
 
1337
#ifdef ENABLE_CUPS_LOAD_SAVE_OPTIONS
 
1338
      if (loaded_settings)
 
1339
        stp_copy_vars_from(v, loaded_settings);
 
1340
      if (save_file_name)
 
1341
        {
 
1342
          save_options(save_file_name, v);
 
1343
          save_file_name = NULL;
 
1344
        }
 
1345
#endif /* ENABLE_CUPS_LOAD_SAVE_OPTIONS */
 
1346
      if (! suppress_messages)
 
1347
        {
 
1348
          fprintf(stderr, "DEBUG: Gutenprint: Interim page settings:\n");
 
1349
          stpi_vars_print_error(v, "DEBUG");
 
1350
        }
 
1351
      stp_merge_printvars(v, stp_printer_get_defaults(printer));
1077
1352
      stp_set_int_parameter(v, "PageNumber", cups.page);
1078
1353
      cups.row = 0;
1079
1354
      if (! suppress_messages)
1085
1360
          fprintf(stderr, "DEBUG: Gutenprint: Make sure that you are using ESP Ghostscript rather\n");
1086
1361
          fprintf(stderr, "DEBUG: Gutenprint: than GNU or AFPL Ghostscript with CUPS.\n");
1087
1362
          fprintf(stderr, "DEBUG: Gutenprint: If this is not the cause, set LogLevel to debug to identify the problem.\n");
1088
 
          goto cups_abort;
 
1363
          aborted = 1;
 
1364
          break;
1089
1365
        }
1090
1366
 
1091
1367
      if (!initialized_job)
1095
1371
        }
1096
1372
 
1097
1373
      if (!stp_print(v, &theImage))
1098
 
          goto cups_abort;
 
1374
        {
 
1375
          aborted = 1;
 
1376
          break;
 
1377
        }
1099
1378
      print_messages_as_errors = 0;
1100
1379
 
1101
1380
      fflush(stdout);
1106
1385
      if (cups.row < cups.header.cupsHeight)
1107
1386
        purge_excess_data(&cups);
1108
1387
      if (! suppress_messages)
1109
 
        fprintf(stderr, "DEBUG: Gutenprint: Done printing page %d\n", cups.page + 1);
 
1388
        fprintf(stderr, "DEBUG: Gutenprint: ================ Done printing page %d ================\n", cups.page + 1);
1110
1389
      cups.page ++;
1111
1390
    }
1112
1391
  if (v)
1113
1392
    {
1114
1393
      if (! suppress_messages)
1115
 
        fprintf(stderr, "DEBUG: Gutenprint: Ending job\n");
 
1394
        fprintf(stderr, "DEBUG: Gutenprint: %s job\n",
 
1395
                aborted ? "Aborted" : "Ending");
1116
1396
      stp_end_job(v, &theImage);
1117
1397
      fflush(stdout);
1118
1398
      stp_vars_destroy(v);
1123
1403
  clocks_per_sec = sysconf(_SC_CLK_TCK);
1124
1404
  fprintf(stderr, "DEBUG: Gutenprint: Printed total %.0f bytes\n",
1125
1405
          total_bytes_printed);
1126
 
  fprintf(stderr, "DEBUG: Gutenprint: Used %.3f seconds user, %.3f seconds system, %.3f seconds elapsed\n",
 
1406
  fprintf(stderr, "DEBUG: Gutenprint: Time %.3f user, %.3f sys, %.3f elapsed\n",
1127
1407
          (double) tms.tms_utime / clocks_per_sec,
1128
1408
          (double) tms.tms_stime / clocks_per_sec,
1129
1409
          (double) (t2.tv_sec - t1.tv_sec) +
1130
1410
          ((double) (t2.tv_usec - t1.tv_usec)) / 1000000.0);
1131
 
  stp_vars_destroy(default_settings);
1132
 
  if (page_size_name)
1133
 
    stp_free(page_size_name);
1134
 
  if (fd != 0)
1135
 
    close(fd);
1136
 
  return 0;
1137
 
 
1138
 
cups_abort:
1139
 
  if (v)
 
1411
  if (!suppress_messages)
1140
1412
    {
1141
 
      stp_end_job(v, &theImage);
1142
 
      fflush(stdout);
1143
 
      stp_vars_destroy(v);
 
1413
      fprintf(stderr, "DEBUG: Gutenprint: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
 
1414
      fprintf(stderr, "DEBUG: Gutenprint: ============================================================\n");
1144
1415
    }
1145
 
  cupsRasterClose(cups.ras);
1146
 
  clk = times(&tms);
1147
 
  (void) gettimeofday(&t2, &tz);
1148
 
  clocks_per_sec = sysconf(_SC_CLK_TCK);
1149
 
  fprintf(stderr, "DEBUG: Gutenprint: Printed total %.0f bytes\n",
1150
 
          total_bytes_printed);
1151
 
  fprintf(stderr, "DEBUG: Gutenprint: Used %.3f seconds user, %.3f seconds system, %.3f seconds elapsed\n",
1152
 
          (double) tms.tms_utime / clocks_per_sec,
1153
 
          (double) tms.tms_stime / clocks_per_sec,
1154
 
          (double) (t2.tv_sec - t1.tv_sec) +
1155
 
          ((double) (t2.tv_usec - t1.tv_usec)) / 1000000.0);
1156
 
  stp_i18n_printf(po, _("ERROR: Invalid Gutenprint driver settings!\n"));
1157
1416
  stp_vars_destroy(default_settings);
1158
1417
  if (page_size_name)
1159
1418
    stp_free(page_size_name);
1160
1419
  if (fd != 0)
1161
1420
    close(fd);
1162
 
  return 1;
 
1421
  return aborted ? 1 : 0;
1163
1422
}
1164
1423
 
1165
1424
 
1282
1541
 
1283
1542
  if (cups->row < cups->header.cupsHeight)
1284
1543
  {
1285
 
    if (! suppress_messages)
 
1544
    if (! suppress_messages && ! suppress_verbose_messages)
1286
1545
      fprintf(stderr, "DEBUG2: Gutenprint: Reading %d %d\n",
1287
1546
              bytes_per_line, cups->row);
1288
1547
    while (cups->row <= row && cups->row < cups->header.cupsHeight)
1289
1548
      {
1290
1549
        if (left_margin > 0)
1291
1550
          {
1292
 
            if (! suppress_messages)
 
1551
            if (! suppress_messages && ! suppress_verbose_messages)
1293
1552
              fprintf(stderr, "DEBUG2: Gutenprint: Tossing left %d (%d)\n",
1294
1553
                      left_margin, cups->left_trim);
1295
1554
            throwaway_data(left_margin, cups);
1298
1557
        cups->row ++;
1299
1558
        if (margin + right_margin > 0)
1300
1559
          {
1301
 
            if (!suppress_messages)
 
1560
            if (! suppress_messages && ! suppress_verbose_messages)
1302
1561
              fprintf(stderr, "DEBUG2: Gutenprint: Tossing right %d (%d) + %d\n",
1303
1562
                      right_margin, cups->right_trim, margin);
1304
1563
            throwaway_data(margin + right_margin, cups);
1445
1704
 
1446
1705
 
1447
1706
/*
1448
 
 * End of "$Id: rastertoprinter.c,v 1.137 2011/04/09 00:19:59 rlk Exp $".
 
1707
 * End of "$Id: rastertoprinter.c,v 1.139 2011/12/18 16:20:31 rlk Exp $".
1449
1708
 */