]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Scale PDF pages within the imageable area of the page.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 3 Mar 2003 17:10:24 +0000 (17:10 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 3 Mar 2003 17:10:24 +0000 (17:10 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@3417 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES.txt
pdftops/GlobalParams.cxx
pdftops/GlobalParams.h
pdftops/PSOutputDev.cxx
pdftops/pdftops.cxx

index caf788ba9c9c122ca18184aff0658c5fbb53e161..b3cacfa1c1ee292227cef6a2b1ebed8fed0f39dc 100644 (file)
@@ -1,8 +1,10 @@
-CHANGES.txt - 02/28/2003
+CHANGES.txt - 03/03/2003
 ------------------------
 
 CHANGES IN CUPS V1.1.19
 
+       - The pdftops filter now scales PDF pages within the
+         printable area of the page.
        - The pstops filter didn't include the page-label and
          classification boxes when printing EPS or non-
          conformant PS files.
index 0eb3c1461bf32f6cb32bdaa478abb5aa4b4a9f71..dc8127a1ae45609ffd8a2d2deddc5fe6db15d714 100644 (file)
@@ -174,6 +174,10 @@ GlobalParams::GlobalParams(char *cfgFileName) {
   psPaperWidth = defPaperWidth;
   psPaperHeight = defPaperHeight;
 #endif
+  psLeft = 0;
+  psBottom = 0;
+  psRight = psPaperWidth;
+  psTop = psPaperHeight;
   psDuplex = gFalse;
   psLevel = psLevel2;
   psFile = NULL;
@@ -920,6 +924,16 @@ GString *GlobalParams::getPSFile() {
   return s;
 }
 
+void GlobalParams::getPSImageableArea(int &left, int &bottom, int &right, int &top) {
+  globalParamsLock;
+  left   = psLeft;
+  bottom = psBottom;
+  right  = psRight;
+  top    = psTop;
+  globalParamsUnlock;
+}
+
+
 int GlobalParams::getPSPaperWidth() {
   int w;
 
@@ -1216,6 +1230,15 @@ void GlobalParams::setPSFile(char *file) {
   globalParamsUnlock;
 }
 
+void GlobalParams::setPSImageableArea(int left, int bottom, int right, int top) {
+  globalParamsLock;
+  psLeft   = left;
+  psBottom = bottom;
+  psRight  = right;
+  psTop    = top;
+  globalParamsUnlock;
+}
+
 GBool GlobalParams::setPSPaperSize(char *size) {
   globalParamsLock;
   if (!strcmp(size, "letter")) {
@@ -1230,10 +1253,17 @@ GBool GlobalParams::setPSPaperSize(char *size) {
   } else if (!strcmp(size, "A3")) {
     psPaperWidth = 842;
     psPaperHeight = 1190;
+  } else if (!strcmp(size, "Universal")) {
+    psPaperWidth = 595;
+    psPaperHeight = 792;
   } else {
     globalParamsUnlock;
     return gFalse;
   }
+  psLeft = 0;
+  psBottom = 0;
+  psRight = psPaperWidth;
+  psTop = psPaperHeight;
   globalParamsUnlock;
   return gTrue;
 }
@@ -1241,12 +1271,16 @@ GBool GlobalParams::setPSPaperSize(char *size) {
 void GlobalParams::setPSPaperWidth(int width) {
   globalParamsLock;
   psPaperWidth = width;
+  psLeft = 0;
+  psRight = psPaperWidth;
   globalParamsUnlock;
 }
 
 void GlobalParams::setPSPaperHeight(int height) {
   globalParamsLock;
   psPaperHeight = height;
+  psBottom = 0;
+  psTop = psPaperHeight;
   globalParamsUnlock;
 }
 
index d7f13db2531e7e0e7c425376f6cf06791882a3bd..6f0da8505ae34077c20518edc1e156e4abbdf4d9 100644 (file)
@@ -142,6 +142,7 @@ public:
   DisplayFontParam *getDisplayFont(GString *fontName);
   DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
   GString *getPSFile();
+  void getPSImageableArea(int &left, int &bottom, int &right, int &top);
   int getPSPaperWidth();
   int getPSPaperHeight();
   GBool getPSDuplex();
@@ -176,6 +177,7 @@ public:
   void addDisplayFont(DisplayFontParam *param);
   void setPSFile(char *file);
   GBool setPSPaperSize(char *size);
+  void setPSImageableArea(int left, int bottom, int right, int top);
   void setPSPaperWidth(int width);
   void setPSPaperHeight(int height);
   void setPSDuplex(GBool duplex);
@@ -254,6 +256,10 @@ private:
   GString *psFile;             // PostScript file or command (for xpdf)
   int psPaperWidth;            // paper size, in PostScript points, for
   int psPaperHeight;           //   PostScript output
+  int psLeft;                  // imageable area, in PostScript points,
+  int psBottom;                        //   for PostScript output
+  int psRight;                 //   ...
+  int psTop;                   //   ...
   GBool psDuplex;              // enable duplexing in PostScript?
   PSLevel psLevel;             // PostScript level to generate
   GHash *psFonts;              // PostScript font info, indexed by PDF
index 8008b64c443f69a155b15b33fb0a0468edb2e3c9..bdeabbb8037250130cf2217a0c882265f374f7fe 100644 (file)
@@ -621,6 +621,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA,
     writePSFmt("%%%%DocumentMedia: plain %d %d 0 () ()\n",
               paperWidth, paperHeight);
     writePSFmt("%%%%Pages: %d\n", lastPage - firstPage + 1);
+    writePSFmt("%%%%BoundingBox: 0 0 %d %d\n", paperWidth, paperHeight);
     writePS("%%EndComments\n");
     writePS("%%BeginDefaults\n");
     writePS("%%PageMedia: plain\n");
@@ -1684,29 +1685,37 @@ void PSOutputDev::setupImage(Ref id, Stream *str) {
 
 void PSOutputDev::startPage(int pageNum, GfxState *state) {
   int x1, y1, x2, y2, width, height, t;
+  int imageWidth, imageHeight;
+  int left, bottom, right, top;
 
+  globalParams->getPSImageableArea(left, bottom, right, top);
+  imageWidth  = right - left;
+  imageHeight = top - bottom;
 
   switch (mode) {
 
   case psModePS:
     writePSFmt("%%%%Page: %d %d\n", pageNum, seqPage);
-    writePS("%%BeginPageSetup\n");
 
     // rotate, translate, and scale page
     x1 = (int)(state->getX1() + 0.5);
     y1 = (int)(state->getY1() + 0.5);
     x2 = (int)(state->getX2() + 0.5);
     y2 = (int)(state->getY2() + 0.5);
+    writePSFmt("%%%%PageBoundingBox: %d %d %d %d\n",
+              (int)floor(x1), (int)floor(y1),
+              (int)ceil(x2), (int)ceil(y2));
+    writePS("%%BeginPageSetup\n");
     width = x2 - x1;
     height = y2 - y1;
-    if (width > height && width > paperWidth) {
+    if (width > height && width > imageWidth) {
       landscape = gTrue;
       writePSFmt("%%%%PageOrientation: %s\n",
                 state->getCTM()[0] ? "Landscape" : "Portrait");
       writePS("pdfStartPage\n");
       writePS("90 rotate\n");
       tx = -x1;
-      ty = -(y1 + paperWidth);
+      ty = -(y1 + imageWidth);
       t = width;
       width = height;
       height = t;
@@ -1718,18 +1727,20 @@ void PSOutputDev::startPage(int pageNum, GfxState *state) {
       tx = -x1;
       ty = -y1;
     }
-    if (width < paperWidth) {
-      tx += (paperWidth - width) / 2;
+    tx += left;
+    ty += bottom;
+    if (width < imageWidth) {
+      tx += (imageWidth - width) / 2;
     }
-    if (height < paperHeight) {
-      ty += (paperHeight - height) / 2;
+    if (height < imageHeight) {
+      ty += (imageHeight - height) / 2;
     }
     if (tx != 0 || ty != 0) {
       writePSFmt("%g %g translate\n", tx, ty);
     }
-    if (width > paperWidth || height > paperHeight) {
-      xScale = (double)paperWidth / (double)width;
-      yScale = (double)paperHeight / (double)height;
+    if (width > imageWidth || height > imageHeight) {
+      xScale = (double)imageWidth / (double)width;
+      yScale = (double)imageHeight / (double)height;
       if (yScale < xScale) {
        xScale = yScale;
       } else {
index 9a78dfbbd28d98d2c0483dbeefce74bcb5d1642c..422295aa1e32d64c73e73bf0eccf9e11017b4d32 100644 (file)
@@ -45,6 +45,7 @@ int main(int argc, char *argv[]) {
   char         buffer[8192];
   int          bytes;
   int          width, length;
+  int          left, bottom, right, top;
   int          duplex;
 
 
@@ -78,6 +79,10 @@ int main(int argc, char *argv[]) {
   }
 
   // Default to "Universal" size - min of A4 and Letter...
+  left   = 0;
+  bottom = 0;
+  right  = 595;
+  top    = 792;
   width  = 595;
   length = 792;
   level  = psLevel2;
@@ -95,6 +100,10 @@ int main(int argc, char *argv[]) {
 
     if ((size = ppdPageSize(ppd, NULL)) != NULL)
     {
+      left   = (int)size->left;
+      bottom = (int)size->bottom;
+      right  = (int)size->right;
+      top    = (int)size->top;
       width  = (int)size->width;
       length = (int)size->length;
     }
@@ -145,6 +154,7 @@ int main(int argc, char *argv[]) {
 
   globalParams->setPSPaperWidth(width);
   globalParams->setPSPaperHeight(length);
+  globalParams->setPSImageableArea(left, bottom, right, top);
   globalParams->setPSDuplex(duplex);
   globalParams->setPSLevel(level);
   globalParams->setPSASCIIHex(level == psLevel1);