~ubuntu-branches/ubuntu/quantal/cups-filters/quantal-proposed

« back to all changes in this revision

Viewing changes to filter/imagetopdf.c

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter, Till Kamppeter, Martin Pitt
  • Date: 2012-03-30 08:49:48 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120330084948-7h3u3zfikkvuywmk
Tags: 1.0.11-1
[ Till Kamppeter ]
* New upstream release
   - Updated all code copied from Poppler to the current state of Poppler,
     to fix any bugs or security vulnerabilities which were in that
     Poppler code.
   - Made Poppler-based PDF filters building with various versions of
     Poppler.
   - Deactivated NIME conversion rules which are not used by the PDF-
     based printing workflow.
   - Added generic PPD for native PDF printers.
   - Cleaned up sample PPD file HP-Color_LaserJet_CM3530_MFP-PDF.ppd.
   - imagetopdf: Added support for native PDF printers.
   - imagetopdf, imagetoraster: Let image input "scale to fit"
     by default. This makes photo printing via AirPrint work,
     as the iOS devices send JPEG but do not allow setting options.
   - pdftops: Generally do not compress fonts and images, and
     also do not do CCITT compression for bitmap glyphs to make
     the PostScript output more compatible with buggy PostScript
     interpreters. The output gets 30-50% longer but will work on
     many more different printer models. Problems were also
     discovered on HP and not only on Brother (LP: #960666).

[ Martin Pitt ]
* Drop debian/patches/poppler-pre-0.18.patch and patch machinery around it.
  It's not necessary with the current upstream version any more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "common.h"
40
40
#include <cupsfilters/image.h>
41
41
#include <math.h>
 
42
#include <ctype.h>
42
43
 
43
44
#if CUPS_VERSION_MAJOR < 1 \
44
45
  || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 2)
626
627
}
627
628
 
628
629
/*
 
630
 * Copied ppd_decode() from CUPS which is not exported to the API
 
631
 */
 
632
 
 
633
static int                              /* O - Length of decoded string */
 
634
ppd_decode(char *string)                /* I - String to decode */
 
635
{
 
636
  char  *inptr,                         /* Input pointer */
 
637
        *outptr;                        /* Output pointer */
 
638
 
 
639
 
 
640
  inptr  = string;
 
641
  outptr = string;
 
642
 
 
643
  while (*inptr != '\0')
 
644
    if (*inptr == '<' && isxdigit(inptr[1] & 255))
 
645
    {
 
646
     /*
 
647
      * Convert hex to 8-bit values...
 
648
      */
 
649
 
 
650
      inptr ++;
 
651
      while (isxdigit(*inptr & 255))
 
652
      {
 
653
        if (isalpha(*inptr))
 
654
          *outptr = (tolower(*inptr) - 'a' + 10) << 4;
 
655
        else
 
656
          *outptr = (*inptr - '0') << 4;
 
657
 
 
658
        inptr ++;
 
659
 
 
660
        if (!isxdigit(*inptr & 255))
 
661
          break;
 
662
 
 
663
        if (isalpha(*inptr))
 
664
          *outptr |= tolower(*inptr) - 'a' + 10;
 
665
        else
 
666
          *outptr |= *inptr - '0';
 
667
 
 
668
        inptr ++;
 
669
        outptr ++;
 
670
      }
 
671
 
 
672
      while (*inptr != '>' && *inptr != '\0')
 
673
        inptr ++;
 
674
      while (*inptr == '>')
 
675
        inptr ++;
 
676
    }
 
677
    else
 
678
      *outptr++ = *inptr++;
 
679
 
 
680
  *outptr = '\0';
 
681
 
 
682
  return ((int)(outptr - string));
 
683
}
 
684
 
 
685
/*
629
686
 * 'main()' - Main entry...
630
687
 */
631
688
 
641
698
  int           xppi, yppi;             /* Pixels-per-inch */
642
699
  int           hue, sat;               /* Hue and saturation adjustment */
643
700
  int           emit_jcl;
 
701
  int           pdf_printer = 0;
644
702
  char          filename[1024];         /* Name of file to print */
645
703
  int deviceCopies = 1;
646
704
  int deviceCollate = 0;
706
764
  * Process command-line options and write the prolog...
707
765
  */
708
766
 
709
 
  zoom = 0.0;
 
767
  zoom = 1.0;
710
768
  xppi = 0;
711
769
  yppi = 0;
712
770
  hue  = 0;
766
824
    }
767
825
  }
768
826
 
769
 
  /* adujst to even page when duplex */
 
827
  /* adjust to even page when duplex */
770
828
  if (((val = cupsGetOption("cupsEvenDuplex",num_options,options)) != 0 &&
771
829
             (!strcasecmp(val, "true") || !strcasecmp(val, "on") ||
772
830
               !strcasecmp(val, "yes"))) ||
815
873
  else if (((val =
816
874
             cupsGetOption("fit-to-page", num_options, options)) != NULL) ||
817
875
           ((val = cupsGetOption("fitplot", num_options, options)) != NULL))
 
876
  {
818
877
    if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
819
878
        !strcasecmp(val, "true"))
820
879
      zoom = 1.0;
 
880
    else
 
881
      zoom = 0.0;
 
882
  }
 
883
  else if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL)
 
884
    zoom = 0.0;
821
885
 
822
886
  if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
 
887
  {
823
888
    if (sscanf(val, "%dx%d", &xppi, &yppi) < 2)
824
889
      yppi = xppi;
 
890
    zoom = 0.0;
 
891
  }
825
892
 
826
893
  if ((val = cupsGetOption("position", num_options, options)) != NULL)
827
894
  {
1319
1386
  */
1320
1387
 
1321
1388
  if (emit_jcl) {
 
1389
    /* pdftopdf only adds JCL to the job if the printer is a native PDF
 
1390
       printer and the PPD is for this mode, having the "*JCLToPDFInterpreter:"
 
1391
       keyword. We need to read this keyword manually from the PPD and replace
 
1392
       the content of ppd->jcl_ps by the value of this keyword, so that
 
1393
       ppdEmitJCL() actalually adds JCL based on the presence on 
 
1394
       "*JCLToPDFInterpreter:". */
 
1395
    if ((attr = ppdFindAttr(ppd,"JCLToPDFInterpreter",NULL)) != NULL)
 
1396
    {
 
1397
      ppd->jcl_ps = strdup(attr->value);
 
1398
      ppd_decode(ppd->jcl_ps);
 
1399
      pdf_printer = 1;
 
1400
    } 
 
1401
    else
 
1402
    {
 
1403
      ppd->jcl_ps = NULL;
 
1404
      pdf_printer = 0;
 
1405
    }
1322
1406
    ppdEmitJCL(ppd, stdout, atoi(argv[1]), argv[2], argv[3]);
1323
1407
    emitJCLOptions(stdout,deviceCopies);
1324
1408
  }
1510
1594
          outPageObject(pageObjects[page],
1511
1595
            contentsObjs[ypages*xpage+ypage],
1512
1596
            imgObjs[ypages*xpage+ypage]);
 
1597
          if (pdf_printer)
 
1598
            fprintf(stderr, "PAGE: %d %d\n", page+1, 1);
1513
1599
        }
1514
1600
      if (EvenDuplex) {
1515
1601
        /* out empty page */
1516
1602
        outPageObject(pageObjects[page],-1,-1);
 
1603
        if (pdf_printer)
 
1604
          fprintf(stderr, "PAGE: %d %d\n", page+1, 1);
1517
1605
      }
1518
1606
    }
1519
1607
    free(contentsObjs);
1540
1628
        {
1541
1629
          /* out Page Object */
1542
1630
          outPageObject(pageObjects[page],contentsObj,imgObj);
 
1631
          if (pdf_printer)
 
1632
            fprintf(stderr, "PAGE: %d %d\n", page+1, 1);
1543
1633
        }
1544
1634
      }
1545
1635
    if (EvenDuplex) {
1549
1639
      for (p = 0;p < Copies;p++, page++)
1550
1640
      {
1551
1641
        outPageObject(pageObjects[page],-1,-1);
 
1642
        if (pdf_printer)
 
1643
          fprintf(stderr, "PAGE: %d %d\n", page+1, 1);
1552
1644
      }
1553
1645
    }
1554
1646
  }