Handle fixed page size printer option.

Correctly handle the printer option "fixed page size". If set,
pages are centered and trimmed onto the fixed page, regardless
of the page size option.

(cherry picked from commit b002226b5c9a970960de39be535e97e861860866)

Conflicts:

	vcl/source/gdi/print3.cxx

Change-Id: I10f6f5a10268c452847f032e204df8f363be99a1
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index b8ed8d5..047ddc8 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -162,6 +162,9 @@
 
     // set by user through printer properties subdialog of printer settings dialog
     Size                                                        maDefaultPageSize;
+    // set by user through printer properties subdialog of print dialog.
+    // if set, pages are centered and trimmed onto the fixed page
+    Size                                                        maFixedPageSize;
     // set by user through printer properties subdialog of printer settings dialog
     sal_Int32                                                   mnDefaultPaperBin;
     // Set by user through printer properties subdialog of print dialog.
@@ -792,6 +795,7 @@
     mpImplData->maDefaultPageSize = mpImplData->mxPrinter->GetPaperSize();
     mpImplData->mxPrinter->Pop();
     mpImplData->mnFixedPaperBin = -1;
+    mpImplData->maFixedPageSize = Size();
 }
 
 void PrinterController::resetPrinterOptions( bool i_bFileOutput )
@@ -828,7 +832,7 @@
             // configured to use the driver papersize
             if (aNewPaperSize != mpImplData->maDefaultPageSize)
             {
-                mpImplData->maDefaultPageSize = aNewPaperSize;
+                mpImplData->maFixedPageSize = aNewPaperSize;
                 bInvalidateCache = getPapersizeFromSetup();
             }
 
@@ -844,6 +848,11 @@
             {
                 mpImplData->maPageCache.invalidate();
             }
+
+            if( aNewPaperSize != aPaperSize || nNewPaperBin != nPaperBin )
+            {
+                mpImplData->maPageCache.invalidate();
+            }
         }
         else
         {
@@ -928,11 +937,14 @@
 //print dialog
 void vcl::ImplPrinterControllerData::resetPaperToLastConfigured()
 {
+    Size aPaperSize(maDefaultPageSize);
+    if (maFixedPageSize.Width() > 0 && maFixedPageSize.Height() > 0)
+        aPaperSize = maFixedPageSize;
     mxPrinter->Push();
     mxPrinter->SetMapMode(MapMode(MAP_100TH_MM));
     Size aCurSize(mxPrinter->GetPaperSize());
-    if (aCurSize != maDefaultPageSize)
-        mxPrinter->SetPaperSizeUser(maDefaultPageSize, !isFixedPageSize());
+    if (aPaperSize != aCurSize)
+        mxPrinter->SetPaperSizeUser(aPaperSize, !isFixedPageSize());
     mxPrinter->Pop();
 }