Bug 1238964 Part 2: Move separate DEVMODE to nsIPrintSettings copying into nsPrintSettingsWin. r=jimm
authorBob Owen <bobowencode@gmail.com>
Tue, 12 Jan 2016 17:40:07 +0000
changeset 281251 fb4737474a9c50b44e0ec38e43d42ed8a119b7ee
parent 281250 e7d43e96b14cbd528b6b93342851d573d2c7eb73
child 281252 90a2e74d14ca2316692bd86ec6064ecafbcd715c
push id29934
push userphilringnalda@gmail.com
push dateSun, 24 Jan 2016 01:56:15 +0000
treeherdermozilla-central@d0df4221d105 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1238964
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1238964 Part 2: Move separate DEVMODE to nsIPrintSettings copying into nsPrintSettingsWin. r=jimm This also corrects what I think are long standing issues with the mapping to and from print settings on Windows. Firstly it only uses the DEVMODE flags to decide what should get stored, in the old code if paper size was not set, it would then use that possibly invalid paper size to map to length and width. Paper setting prefs are mapped back if they were stored or if they have been manually set to something sane. Secondly it corrects the calculation that was used to convert from millimeters to tenths of millimeters. It also gets rid of the paperSizeType field, which was only used on Windows and doesn't actually make sense according to the DEVMODE documentation as the dmPaperLength and dmPaperWidth fields override the dmPaperSize, but can in theory be specified at the same time.
embedding/components/printingui/ipc/PPrintingTypes.ipdlh
embedding/components/printingui/win/nsPrintDialogUtil.cpp
toolkit/components/printing/content/printjoboptions.js
widget/nsIPrintSettings.idl
widget/nsIPrintSettingsWin.idl
widget/nsPrintOptionsImpl.cpp
widget/nsPrintSettingsImpl.cpp
widget/nsPrintSettingsImpl.h
widget/windows/nsDeviceContextSpecWin.cpp
widget/windows/nsDeviceContextSpecWin.h
widget/windows/nsPrintSettingsWin.cpp
--- a/embedding/components/printingui/ipc/PPrintingTypes.ipdlh
+++ b/embedding/components/printingui/ipc/PPrintingTypes.ipdlh
@@ -46,17 +46,16 @@ struct PrintData {
   bool isCancelled;
   short printFrameTypeUsage;
   short  printFrameType;
   bool printSilent;
   bool shrinkToFit;
   bool showPrintProgress;
 
   nsString paperName;
-  short paperSizeType;
   short paperData;
   double paperWidth;
   double paperHeight;
   short paperSizeUnit;
   bool printReversed;
   bool printInColor;
   int32_t orientation;
   int32_t numCopies;
--- a/embedding/components/printingui/win/nsPrintDialogUtil.cpp
+++ b/embedding/components/printingui/win/nsPrintDialogUtil.cpp
@@ -69,234 +69,16 @@ static UINT gFrameSelectedRadioBtn = 0;
 
 // Indicates whether the native print dialog was successfully extended
 static bool gDialogWasExtended     = false;
 
 #define PRINTDLG_PROPERTIES "chrome://global/locale/printdialog.properties"
 
 static HWND gParentWnd = nullptr;
 
-//******************************************************
-// Define native paper sizes
-//******************************************************
-typedef struct {
-  short  mPaperSize; // native enum
-  double mWidth;
-  double mHeight;
-  bool mIsInches;
-} NativePaperSizes;
-
-// There are around 40 default print sizes defined by Windows
-const NativePaperSizes kPaperSizes[] = {
-  {DMPAPER_LETTER,    8.5,   11.0,  true},
-  {DMPAPER_LEGAL,     8.5,   14.0,  true},
-  {DMPAPER_A4,        210.0, 297.0, false},
-  {DMPAPER_TABLOID,   11.0,  17.0,  true},
-  {DMPAPER_LEDGER,    17.0,  11.0,  true},
-  {DMPAPER_STATEMENT, 5.5,   8.5,   true},
-  {DMPAPER_EXECUTIVE, 7.25,  10.5,  true},
-  {DMPAPER_A3,        297.0, 420.0, false},
-  {DMPAPER_A5,        148.0, 210.0, false},
-  {DMPAPER_CSHEET,    17.0,  22.0,  true},  
-  {DMPAPER_DSHEET,    22.0,  34.0,  true},  
-  {DMPAPER_ESHEET,    34.0,  44.0,  true},  
-  {DMPAPER_LETTERSMALL, 8.5, 11.0,  true},  
-  {DMPAPER_A4SMALL,   210.0, 297.0, false}, 
-  {DMPAPER_B4,        250.0, 354.0, false}, 
-  {DMPAPER_B5,        182.0, 257.0, false},
-  {DMPAPER_FOLIO,     8.5,   13.0,  true},
-  {DMPAPER_QUARTO,    215.0, 275.0, false},
-  {DMPAPER_10X14,     10.0,  14.0,  true},
-  {DMPAPER_11X17,     11.0,  17.0,  true},
-  {DMPAPER_NOTE,      8.5,   11.0,  true},  
-  {DMPAPER_ENV_9,     3.875, 8.875, true},  
-  {DMPAPER_ENV_10,    40.125, 9.5,  true},  
-  {DMPAPER_ENV_11,    4.5,   10.375, true},  
-  {DMPAPER_ENV_12,    4.75,  11.0,  true},  
-  {DMPAPER_ENV_14,    5.0,   11.5,  true},  
-  {DMPAPER_ENV_DL,    110.0, 220.0, false}, 
-  {DMPAPER_ENV_C5,    162.0, 229.0, false}, 
-  {DMPAPER_ENV_C3,    324.0, 458.0, false}, 
-  {DMPAPER_ENV_C4,    229.0, 324.0, false}, 
-  {DMPAPER_ENV_C6,    114.0, 162.0, false}, 
-  {DMPAPER_ENV_C65,   114.0, 229.0, false}, 
-  {DMPAPER_ENV_B4,    250.0, 353.0, false}, 
-  {DMPAPER_ENV_B5,    176.0, 250.0, false}, 
-  {DMPAPER_ENV_B6,    176.0, 125.0, false}, 
-  {DMPAPER_ENV_ITALY, 110.0, 230.0, false}, 
-  {DMPAPER_ENV_MONARCH,  3.875,  7.5, true},  
-  {DMPAPER_ENV_PERSONAL, 3.625,  6.5, true},  
-  {DMPAPER_FANFOLD_US,   14.875, 11.0, true},  
-  {DMPAPER_FANFOLD_STD_GERMAN, 8.5, 12.0, true},  
-  {DMPAPER_FANFOLD_LGL_GERMAN, 8.5, 13.0, true},  
-};
-const int32_t kNumPaperSizes = 41;
-
-//----------------------------------------------------------------------------------
-// Map an incoming size to a Windows Native enum in the DevMode
-static void 
-MapPaperSizeToNativeEnum(LPDEVMODEW aDevMode,
-                         int16_t   aType, 
-                         double    aW, 
-                         double    aH)
-{
-
-#ifdef DEBUG_rods
-  BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION;
-  BOOL doingPaperSize   = aDevMode->dmFields & DM_PAPERSIZE;
-  BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH;
-  BOOL doingPaperWidth  = aDevMode->dmFields & DM_PAPERWIDTH;
-#endif
-
-  const double kThreshold = 0.05;
-  for (int32_t i=0;i<kNumPaperSizes;i++) {
-    double width  = kPaperSizes[i].mWidth;
-    double height = kPaperSizes[i].mHeight;
-    if (aW < width+kThreshold && aW > width-kThreshold && 
-        aH < height+kThreshold && aH > height-kThreshold) {
-      aDevMode->dmPaperSize = kPaperSizes[i].mPaperSize;
-      aDevMode->dmFields &= ~DM_PAPERLENGTH;
-      aDevMode->dmFields &= ~DM_PAPERWIDTH;
-      aDevMode->dmFields |= DM_PAPERSIZE;
-      return;
-    }
-  }
-
-  short width  = 0;
-  short height = 0;
-  if (aType == nsIPrintSettings::kPaperSizeInches) {
-    width  = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10);
-    height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10);
-
-  } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) {
-    width  = short(aW / 10.0);
-    height = short(aH / 10.0);
-  } else {
-    return; // don't set anything
-  }
-
-  // width and height is in 
-  aDevMode->dmPaperSize   = 0;
-  aDevMode->dmPaperWidth  = width;
-  aDevMode->dmPaperLength = height;
-
-  aDevMode->dmFields |= DM_PAPERSIZE;
-  aDevMode->dmFields |= DM_PAPERLENGTH;
-  aDevMode->dmFields |= DM_PAPERWIDTH;
-}
-
-//----------------------------------------------------------------------------------
-// Setup Paper Size & Orientation options into the DevMode
-// 
-static void 
-SetupDevModeFromSettings(LPDEVMODEW aDevMode, nsIPrintSettings* aPrintSettings)
-{
-  // Setup paper size
-  if (aPrintSettings) {
-    int16_t type;
-    aPrintSettings->GetPaperSizeType(&type);
-    if (type == nsIPrintSettings::kPaperSizeNativeData) {
-      int16_t paperEnum;
-      aPrintSettings->GetPaperData(&paperEnum);
-      aDevMode->dmPaperSize = paperEnum;
-      aDevMode->dmFields &= ~DM_PAPERLENGTH;
-      aDevMode->dmFields &= ~DM_PAPERWIDTH;
-      aDevMode->dmFields |= DM_PAPERSIZE;
-    } else {
-      int16_t unit;
-      double width, height;
-      aPrintSettings->GetPaperSizeUnit(&unit);
-      aPrintSettings->GetPaperWidth(&width);
-      aPrintSettings->GetPaperHeight(&height);
-      MapPaperSizeToNativeEnum(aDevMode, unit, width, height);
-    }
-
-    // Setup Orientation
-    int32_t orientation;
-    aPrintSettings->GetOrientation(&orientation);
-    aDevMode->dmOrientation = orientation == nsIPrintSettings::kPortraitOrientation?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE;
-    aDevMode->dmFields |= DM_ORIENTATION;
-
-    // Setup Number of Copies
-    int32_t copies;
-    aPrintSettings->GetNumCopies(&copies);
-    aDevMode->dmCopies = copies;
-    aDevMode->dmFields |= DM_COPIES;
-
-  }
-
-}
-
-//----------------------------------------------------------------------------------
-// Helper Function - Free and reallocate the string
-static nsresult 
-SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, 
-                            LPDEVMODEW         aDevMode)
-{
-  if (aPrintSettings == nullptr) {
-    return NS_ERROR_FAILURE;
-  }
-
-  aPrintSettings->SetIsInitializedFromPrinter(true);
-  if (aDevMode->dmFields & DM_ORIENTATION) {
-    int32_t orientation  = aDevMode->dmOrientation == DMORIENT_PORTRAIT?
-                           nsIPrintSettings::kPortraitOrientation:nsIPrintSettings::kLandscapeOrientation;
-    aPrintSettings->SetOrientation(orientation);
-  }
-
-  // Setup Number of Copies
-  if (aDevMode->dmFields & DM_COPIES) {
-    aPrintSettings->SetNumCopies(int32_t(aDevMode->dmCopies));
-  }
-
-  // Scaling
-  // Since we do the scaling, grab their value and reset back to 100
-  if (aDevMode->dmFields & DM_SCALE) {
-    double origScale = 1.0;
-    aPrintSettings->GetScaling(&origScale);
-    double scale = double(aDevMode->dmScale) / 100.0f;
-    if (origScale == 1.0 || scale != 1.0) {
-      aPrintSettings->SetScaling(scale);
-    }
-    aDevMode->dmScale = 100;
-    // To turn this on you must change where the mPrt->mShrinkToFit is being set in the DocumentViewer
-    //aPrintSettings->SetShrinkToFit(false);
-  }
-
-  if (aDevMode->dmFields & DM_PAPERSIZE) {
-    aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeNativeData);
-    aPrintSettings->SetPaperData(aDevMode->dmPaperSize);
-    for (int32_t i=0;i<kNumPaperSizes;i++) {
-      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
-        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeMillimeters);
-        break;
-      }
-    }
-
-  } else if (aDevMode->dmFields & DM_PAPERLENGTH && aDevMode->dmFields & DM_PAPERWIDTH) {
-    bool found = false;
-    for (int32_t i=0;i<kNumPaperSizes;i++) {
-      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
-        aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
-        aPrintSettings->SetPaperWidth(kPaperSizes[i].mWidth);
-        aPrintSettings->SetPaperHeight(kPaperSizes[i].mHeight);
-        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches?nsIPrintSettings::kPaperSizeInches:nsIPrintSettings::kPaperSizeMillimeters);
-        found = true;
-        break;
-      }
-    }
-    if (!found) {
-      return NS_ERROR_FAILURE;
-    }
-  } else {
-    return NS_ERROR_FAILURE;
-  }
-  return NS_OK;
-}
-
 //----------------------------------------------------------------------------------
 // Return localized bundle for resource strings
 static nsresult
 GetLocalizedBundle(const char * aPropFileName, nsIStringBundle** aStrBundle)
 {
   NS_ENSURE_ARG_POINTER(aPropFileName);
   NS_ENSURE_ARG_POINTER(aStrBundle);
 
@@ -719,17 +501,19 @@ HGLOBAL CreateGlobalDevModeAndInit(const
     }
 
     // Lock memory and copy contents from DEVMODE (current printer)
     // to Global Memory DEVMODE
     LPDEVMODEW devMode = (DEVMODEW *)::GlobalLock(hGlobalDevMode);
     if (devMode) {
       memcpy(devMode, pNewDevMode, dwNeeded);
       // Initialize values from the PrintSettings
-      SetupDevModeFromSettings(devMode, aPS);
+      nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aPS);
+      MOZ_ASSERT(psWin);
+      psWin->CopyToNative(devMode);
 
       // Sets back the changes we made to the DevMode into the Printer Driver
       dwRet = ::DocumentPropertiesW(gParentWnd, hPrinter, printName, devMode, devMode, DM_IN_BUFFER | DM_OUT_BUFFER);
       if (dwRet != IDOK) {
         ::GlobalUnlock(hGlobalDevMode);
         ::GlobalFree(hGlobalDevMode);
         ::HeapFree(::GetProcessHeap(), 0, pNewDevMode);
         ::ClosePrinter(hPrinter);
@@ -987,19 +771,18 @@ ShowNativePrintDialog(HWND              
 
     // Transfer the settings from the native data to the PrintSettings
     LPDEVMODEW devMode = (LPDEVMODEW)::GlobalLock(prntdlg.hDevMode);
     if (!devMode || !prntdlg.hDC) {
       ::GlobalFree(hGlobalDevMode);
       return NS_ERROR_FAILURE;
     }
     psWin->SetDevMode(devMode); // copies DevMode
-    SetPrintSettingsFromDevMode(aPrintSettings, devMode);
+    psWin->CopyFromNative(prntdlg.hDC, devMode);
     ::GlobalUnlock(prntdlg.hDevMode);
-    psWin->CopyFromNative(prntdlg.hDC);
     ::DeleteDC(prntdlg.hDC);
 
 #if defined(DEBUG_rods) || defined(DEBUG_dcone)
     bool    printSelection = prntdlg.Flags & PD_SELECTION;
     bool    printAllPages  = prntdlg.Flags & PD_ALLPAGES;
     bool    printNumPages  = prntdlg.Flags & PD_PAGENUMS;
     int32_t fromPageNum    = 0;
     int32_t toPageNum      = 0;
--- a/toolkit/components/printing/content/printjoboptions.js
+++ b/toolkit/components/printing/content/printjoboptions.js
@@ -227,28 +227,26 @@ function createPaperSizeList(selectedInx
   }
 
   //dialog.paperList = selectElement;
 }
 
 //---------------------------------------------------
 function loadDialog()
 {
-  var print_paper_type       = 0;
   var print_paper_unit       = 0;
   var print_paper_width      = 0.0;
   var print_paper_height     = 0.0;
   var print_paper_name       = "";
   var print_color            = true;
   var print_jobtitle         = "";
 
   gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
 
   if (gPrintSettings) {
-    print_paper_type       = gPrintSettings.paperSizeType;
     print_paper_unit       = gPrintSettings.paperSizeUnit;
     print_paper_width      = gPrintSettings.paperWidth;
     print_paper_height     = gPrintSettings.paperHeight;
     print_paper_name       = gPrintSettings.paperName;
     print_color            = gPrintSettings.printInColor;
     print_jobtitle         = gPrintSettings.title;
   }
 
@@ -348,51 +346,48 @@ function onLoad()
   paramBlock.SetInt(0, 0);
 
   loadDialog();
 }
 
 //---------------------------------------------------
 function onAccept()
 {
-  var print_paper_type        = gPrintSettingsInterface.kPaperSizeDefined;
   var print_paper_unit        = gPrintSettingsInterface.kPaperSizeInches;
   var print_paper_width       = 0.0;
   var print_paper_height      = 0.0;
   var print_paper_name        = "";
 
   if (gPrintSettings != null) {
     var paperSelectedInx = dialog.paperList.selectedIndex;
     if (gPaperArray[paperSelectedInx].inches) {
       print_paper_unit = gPrintSettingsInterface.kPaperSizeInches;
     } else {
       print_paper_unit = gPrintSettingsInterface.kPaperSizeMillimeters;
     }
     print_paper_width      = gPaperArray[paperSelectedInx].width;
     print_paper_height     = gPaperArray[paperSelectedInx].height;
     print_paper_name       = gPaperArray[paperSelectedInx].name;
 
-    gPrintSettings.paperSizeType   = print_paper_type;
     gPrintSettings.paperSizeUnit   = print_paper_unit;
     gPrintSettings.paperWidth      = print_paper_width;
     gPrintSettings.paperHeight     = print_paper_height;
     gPrintSettings.paperName       = print_paper_name;
 
     // save these out so they can be picked up by the device spec
     gPrintSettings.printInColor     = dialog.colorRadio.selected;
     gPrintSettings.title            = dialog.jobTitleInput.value;
 
     gPrintSettings.edgeTop          = dialog.topInput.value;
     gPrintSettings.edgeBottom       = dialog.bottomInput.value;
     gPrintSettings.edgeLeft         = dialog.leftInput.value;
     gPrintSettings.edgeRight        = dialog.rightInput.value;
 
     if (doDebug) {
       dump("onAccept******************************\n");
-      dump("paperSizeType    "+print_paper_type+" (should be 1)\n");
       dump("paperSizeUnit    "+print_paper_unit+"\n");
       dump("paperWidth       "+print_paper_width+"\n");
       dump("paperHeight      "+print_paper_height+"\n");
       dump("paperName       '"+print_paper_name+"'\n");
 
       dump("printInColor     "+gPrintSettings.printInColor+"\n");
     }
   } else {
--- a/widget/nsIPrintSettings.idl
+++ b/widget/nsIPrintSettings.idl
@@ -17,17 +17,17 @@
   [ref] native nsNativeIntMarginRef(nsIntMargin);
   [ref] native IntegerArray(nsTArray<int32_t>);
   
 interface nsIPrintSession;
 
 /**
  * Simplified graphics interface for JS rendering.
  */
-[scriptable, uuid(04dd3a01-a74e-44aa-8d49-2c30478fd7b8)]
+[scriptable, uuid(ecc5cbad-57fc-4731-b0bd-09e865bd62ad)]
 
 interface nsIPrintSettings : nsISupports
 {
   /**
    * PrintSettings to be Saved Navigation Constants
    */
   const unsigned long kInitSaveOddEvenPages   = 0x00000001;
   const unsigned long kInitSaveHeaderLeft     = 0x00000002;
@@ -218,17 +218,16 @@ interface nsIPrintSettings : nsISupports
   attribute short   printFrameTypeUsage; /* indicates whether to use the interal value or not  */
   attribute short   printFrameType;
   attribute boolean printSilent;	     /* print without putting up the dialog */
   attribute boolean shrinkToFit;	     /* shrinks content to fit on page      */
   attribute boolean showPrintProgress;   /* indicates whether the progress dialog should be shown */
 
   /* Additional XP Related */
   attribute wstring paperName;     /* name of paper */
-  attribute short   paperSizeType; /* use native data or is defined here */
   attribute short   paperData;     /* native data value */
   attribute double  paperWidth;    /* width of the paper in inches or mm */
   attribute double  paperHeight;   /* height of the paper in inches or mm */
   attribute short   paperSizeUnit; /* paper is in inches or mm */
 
   attribute boolean printReversed;
   attribute boolean printInColor;  /* a false means grayscale */
   attribute long    orientation;   /*  see orientation consts */
--- a/widget/nsIPrintSettingsWin.idl
+++ b/widget/nsIPrintSettingsWin.idl
@@ -13,17 +13,17 @@
  * Native types
  */
   [ptr] native nsDevMode(DEVMODEW);
   native nsHdc(HDC);
 
 /**
  * Simplified PrintSettings for Windows interface 
  */
-[scriptable, uuid(57c22cc1-311f-44c3-bb49-4d1cf411a3b5)]
+[scriptable, uuid(c63eed41-6ac5-459e-8a64-033eb9ad770a)]
 
 interface nsIPrintSettingsWin : nsISupports
 {
   /**
    * Data Members
    *
    * Each of these data members make a copy 
    * of the contents. If you get the value, 
@@ -51,11 +51,19 @@ interface nsIPrintSettingsWin : nsISuppo
    */
   [noscript] attribute double printableWidthInInches;
   [noscript] attribute double printableHeightInInches;
 
   /**
    * Copy relevant print settings from native Windows device.
    *
    * @param hdc HDC to copy from
+   * @param devMode DEVMODE to copy from
    */
-  [notxpcom] void copyFromNative(in nsHdc hdc);
+  [notxpcom] void copyFromNative(in nsHdc hdc, in nsDevMode devMode);
+
+  /**
+   * Copy relevant print settings to native windows structures.
+   *
+   * @param devMode DEVMODE to be populated.
+   */
+  [notxpcom] void copyToNative(in nsDevMode devMode);
 };
--- a/widget/nsPrintOptionsImpl.cpp
+++ b/widget/nsPrintOptionsImpl.cpp
@@ -59,17 +59,16 @@ static const char kPrintHeaderStrRight[]
 static const char kPrintFooterStrLeft[]   = "print_footerleft";
 static const char kPrintFooterStrCenter[] = "print_footercenter";
 static const char kPrintFooterStrRight[]  = "print_footerright";
 
 // Additional Prefs
 static const char kPrintReversed[]      = "print_reversed";
 static const char kPrintInColor[]       = "print_in_color";
 static const char kPrintPaperName[]     = "print_paper_name";
-static const char kPrintPaperSizeType[] = "print_paper_size_type";
 static const char kPrintPaperData[]     = "print_paper_data";
 static const char kPrintPaperSizeUnit[] = "print_paper_size_unit";
 static const char kPrintPaperWidth[]    = "print_paper_width";
 static const char kPrintPaperHeight[]   = "print_paper_height";
 static const char kPrintOrientation[]   = "print_orientation";
 static const char kPrinterName[]        = "print_printer";
 static const char kPrintToFile[]        = "print_to_file";
 static const char kPrintToFileName[]    = "print_to_filename";
@@ -171,17 +170,16 @@ nsPrintOptions::SerializeToPrintData(nsI
   aSettings->GetPrintSilent(&data->printSilent());
   aSettings->GetShrinkToFit(&data->shrinkToFit());
   aSettings->GetShowPrintProgress(&data->showPrintProgress());
 
   nsXPIDLString paperName;
   aSettings->GetPaperName(getter_Copies(paperName));
   data->paperName() = paperName;
 
-  aSettings->GetPaperSizeType(&data->paperSizeType());
   aSettings->GetPaperData(&data->paperData());
   aSettings->GetPaperWidth(&data->paperWidth());
   aSettings->GetPaperHeight(&data->paperHeight());
   aSettings->GetPaperSizeUnit(&data->paperSizeUnit());
 
   aSettings->GetPrintReversed(&data->printReversed());
   aSettings->GetPrintInColor(&data->printInColor());
   aSettings->GetOrientation(&data->orientation());
@@ -288,17 +286,16 @@ nsPrintOptions::DeserializeToPrintSettin
   settings->SetPrintFrameTypeUsage(data.printFrameTypeUsage());
   settings->SetPrintFrameType(data.printFrameType());
   settings->SetPrintSilent(data.printSilent());
   settings->SetShrinkToFit(data.shrinkToFit());
   settings->SetShowPrintProgress(data.showPrintProgress());
 
   settings->SetPaperName(data.paperName().get());
 
-  settings->SetPaperSizeType(data.paperSizeType());
   settings->SetPaperData(data.paperData());
   settings->SetPaperWidth(data.paperWidth());
   settings->SetPaperHeight(data.paperHeight());
   settings->SetPaperSizeUnit(data.paperSizeUnit());
 
   settings->SetPrintReversed(data.printReversed());
   settings->SetPrintInColor(data.printInColor());
   settings->SetOrientation(data.orientation());
@@ -518,39 +515,36 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
   NS_SUCCEEDED(                                         \
     ReadPrefDouble(                                     \
       GetPrefName(_prefname, aPrinterName), _retval     \
     )                                                   \
   )
 
   // Paper size prefs are read as a group
   if (aFlags & nsIPrintSettings::kInitSavePaperSize) {
-    int32_t sizeUnit, sizeType;
+    int32_t sizeUnit;
     double width, height;
 
     bool success = GETINTPREF(kPrintPaperSizeUnit, &sizeUnit)
-                  && GETINTPREF(kPrintPaperSizeType, &sizeType)
                   && GETDBLPREF(kPrintPaperWidth, width)
                   && GETDBLPREF(kPrintPaperHeight, height)
                   && GETSTRPREF(kPrintPaperName, &str);
 
     // Bug 315687: Sanity check paper size to avoid paper size values in
     // mm when the size unit flag is inches. The value 100 is arbitrary
     // and can be changed.
     if (success) {
       success = (sizeUnit != nsIPrintSettings::kPaperSizeInches)
              || (width < 100.0)
              || (height < 100.0);
     }
 
     if (success) {
       aPS->SetPaperSizeUnit(sizeUnit);
       DUMP_INT(kReadStr, kPrintPaperSizeUnit, sizeUnit);
-      aPS->SetPaperSizeType(sizeType);
-      DUMP_INT(kReadStr, kPrintPaperSizeType, sizeType);
       aPS->SetPaperWidth(width);
       DUMP_DBL(kReadStr, kPrintPaperWidth, width);
       aPS->SetPaperHeight(height);
       DUMP_DBL(kReadStr, kPrintPaperHeight, height);
       aPS->SetPaperName(str.get());
       DUMP_STR(kReadStr, kPrintPaperName, str.get());
     }
   }
@@ -772,33 +766,29 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
       WriteInchesIntFromTwipsPref(GetPrefName(kUnwriteableMarginRight, aPrinterName),
                                   unwriteableMargin.right);
       DUMP_INT(kWriteStr, kUnwriteableMarginRight, unwriteableMargin.top);
     }
   }
 
   // Paper size prefs are saved as a group
   if (aFlags & nsIPrintSettings::kInitSavePaperSize) {
-    int16_t sizeUnit, sizeType;
+    int16_t sizeUnit;
     double width, height;
     char16_t *name;
  
     if (
       NS_SUCCEEDED(aPS->GetPaperSizeUnit(&sizeUnit)) &&
-      NS_SUCCEEDED(aPS->GetPaperSizeType(&sizeType)) &&
       NS_SUCCEEDED(aPS->GetPaperWidth(&width)) &&
       NS_SUCCEEDED(aPS->GetPaperHeight(&height)) &&
       NS_SUCCEEDED(aPS->GetPaperName(&name))
     ) {
       DUMP_INT(kWriteStr, kPrintPaperSizeUnit, sizeUnit);
       Preferences::SetInt(GetPrefName(kPrintPaperSizeUnit, aPrinterName),
                           int32_t(sizeUnit));
-      DUMP_INT(kWriteStr, kPrintPaperSizeType, sizeType);
-      Preferences::SetInt(GetPrefName(kPrintPaperSizeType, aPrinterName),
-                          int32_t(sizeType));
       DUMP_DBL(kWriteStr, kPrintPaperWidth, width);
       WritePrefDouble(GetPrefName(kPrintPaperWidth, aPrinterName), width);
       DUMP_DBL(kWriteStr, kPrintPaperHeight, height);
       WritePrefDouble(GetPrefName(kPrintPaperHeight, aPrinterName), height);
       DUMP_STR(kWriteStr, kPrintPaperName, name);
       Preferences::SetString(GetPrefName(kPrintPaperName, aPrinterName), name);
     }
   }
@@ -1408,17 +1398,16 @@ Tester::Tester()
     ps->SetPrintRange(15);
     ps->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get());
     ps->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get());
     ps->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get());
     ps->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get());
     ps->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get());
     ps->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get());
     ps->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get());
-    ps->SetPaperSizeType(10);
     ps->SetPaperData(1);
     ps->SetPaperWidth(100.0);
     ps->SetPaperHeight(50.0);
     ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
     ps->SetPrintReversed(true);
     ps->SetPrintInColor(true);
     ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
     ps->SetNumCopies(2);
--- a/widget/nsPrintSettingsImpl.cpp
+++ b/widget/nsPrintSettingsImpl.cpp
@@ -30,17 +30,16 @@ nsPrintSettings::nsPrintSettings() :
   mHowToEnableFrameUI(kFrameEnableNone),
   mIsCancelled(false),
   mPrintSilent(false),
   mPrintPreview(false),
   mShrinkToFit(true),
   mShowPrintProgress(true),
   mPrintPageDelay(50),
   mPaperData(0),
-  mPaperSizeType(kPaperSizeDefined),
   mPaperWidth(8.5),
   mPaperHeight(11.0),
   mPaperSizeUnit(kPaperSizeInches),
   mPrintReversed(false),
   mPrintInColor(true),
   mOrientation(kPortraitOrientation),
   mNumCopies(1),
   mPrintToFile(false),
@@ -841,28 +840,16 @@ NS_IMETHODIMP nsPrintSettings::GetPaperS
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetPaperSizeUnit(int16_t aPaperSizeUnit)
 {
   mPaperSizeUnit = aPaperSizeUnit;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetPaperSizeType(int16_t *aPaperSizeType)
-{
-  NS_ENSURE_ARG_POINTER(aPaperSizeType);
-  *aPaperSizeType = mPaperSizeType;
-  return NS_OK;
-}
-NS_IMETHODIMP nsPrintSettings::SetPaperSizeType(int16_t aPaperSizeType)
-{
-  mPaperSizeType = aPaperSizeType;
-  return NS_OK;
-}
-
 NS_IMETHODIMP nsPrintSettings::GetPaperData(int16_t *aPaperData)
 {
   NS_ENSURE_ARG_POINTER(aPaperData);
   *aPaperData = mPaperData;
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetPaperData(int16_t aPaperData)
 {
@@ -1023,17 +1010,16 @@ nsPrintSettings& nsPrintSettings::operat
   mHowToEnableFrameUI  = rhs.mHowToEnableFrameUI;
   mIsCancelled         = rhs.mIsCancelled;
   mPrintFrameTypeUsage = rhs.mPrintFrameTypeUsage;
   mPrintFrameType      = rhs.mPrintFrameType;
   mPrintSilent         = rhs.mPrintSilent;
   mShrinkToFit         = rhs.mShrinkToFit;
   mShowPrintProgress   = rhs.mShowPrintProgress;
   mPaperName           = rhs.mPaperName;
-  mPaperSizeType       = rhs.mPaperSizeType;
   mPaperData           = rhs.mPaperData;
   mPaperWidth          = rhs.mPaperWidth;
   mPaperHeight         = rhs.mPaperHeight;
   mPaperSizeUnit       = rhs.mPaperSizeUnit;
   mPrintReversed       = rhs.mPrintReversed;
   mPrintInColor        = rhs.mPrintInColor;
   mOrientation         = rhs.mOrientation;
   mNumCopies           = rhs.mNumCopies;
--- a/widget/nsPrintSettingsImpl.h
+++ b/widget/nsPrintSettingsImpl.h
@@ -76,17 +76,16 @@ protected:
   nsString      mTitle;
   nsString      mURL;
   nsString      mPageNumberFormat;
   nsString      mHeaderStrs[NUM_HEAD_FOOT];
   nsString      mFooterStrs[NUM_HEAD_FOOT];
 
   nsString      mPaperName;
   int16_t       mPaperData;
-  int16_t       mPaperSizeType;
   double        mPaperWidth;
   double        mPaperHeight;
   int16_t       mPaperSizeUnit;
 
   bool          mPrintReversed;
   bool          mPrintInColor; // a false means grayscale
   int32_t       mOrientation;  // see orientation consts
   int32_t       mResolution;
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -85,73 +85,16 @@ nsTArray<LPWSTR>* GlobalPrinters::mPrint
 
 struct AutoFreeGlobalPrinters
 {
   ~AutoFreeGlobalPrinters() {
     GlobalPrinters::GetInstance()->FreeGlobalPrinters();
   }
 };
 
-
-//******************************************************
-// Define native paper sizes
-//******************************************************
-typedef struct {
-  short  mPaperSize; // native enum
-  double mWidth;
-  double mHeight;
-  bool mIsInches;
-} NativePaperSizes;
-
-// There are around 40 default print sizes defined by Windows
-const NativePaperSizes kPaperSizes[] = {
-  {DMPAPER_LETTER,    8.5,   11.0,  true},
-  {DMPAPER_LEGAL,     8.5,   14.0,  true},
-  {DMPAPER_A4,        210.0, 297.0, false},
-  {DMPAPER_B4,        250.0, 354.0, false}, 
-  {DMPAPER_B5,        182.0, 257.0, false},
-  {DMPAPER_TABLOID,   11.0,  17.0,  true},
-  {DMPAPER_LEDGER,    17.0,  11.0,  true},
-  {DMPAPER_STATEMENT, 5.5,   8.5,   true},
-  {DMPAPER_EXECUTIVE, 7.25,  10.5,  true},
-  {DMPAPER_A3,        297.0, 420.0, false},
-  {DMPAPER_A5,        148.0, 210.0, false},
-  {DMPAPER_CSHEET,    17.0,  22.0,  true},  
-  {DMPAPER_DSHEET,    22.0,  34.0,  true},  
-  {DMPAPER_ESHEET,    34.0,  44.0,  true},  
-  {DMPAPER_LETTERSMALL, 8.5, 11.0,  true},  
-  {DMPAPER_A4SMALL,   210.0, 297.0, false}, 
-  {DMPAPER_FOLIO,     8.5,   13.0,  true},
-  {DMPAPER_QUARTO,    215.0, 275.0, false},
-  {DMPAPER_10X14,     10.0,  14.0,  true},
-  {DMPAPER_11X17,     11.0,  17.0,  true},
-  {DMPAPER_NOTE,      8.5,   11.0,  true},  
-  {DMPAPER_ENV_9,     3.875, 8.875, true},  
-  {DMPAPER_ENV_10,    40.125, 9.5,  true},  
-  {DMPAPER_ENV_11,    4.5,   10.375, true},  
-  {DMPAPER_ENV_12,    4.75,  11.0,  true},  
-  {DMPAPER_ENV_14,    5.0,   11.5,  true},  
-  {DMPAPER_ENV_DL,    110.0, 220.0, false}, 
-  {DMPAPER_ENV_C5,    162.0, 229.0, false}, 
-  {DMPAPER_ENV_C3,    324.0, 458.0, false}, 
-  {DMPAPER_ENV_C4,    229.0, 324.0, false}, 
-  {DMPAPER_ENV_C6,    114.0, 162.0, false}, 
-  {DMPAPER_ENV_C65,   114.0, 229.0, false}, 
-  {DMPAPER_ENV_B4,    250.0, 353.0, false}, 
-  {DMPAPER_ENV_B5,    176.0, 250.0, false}, 
-  {DMPAPER_ENV_B6,    176.0, 125.0, false}, 
-  {DMPAPER_ENV_ITALY, 110.0, 230.0, false}, 
-  {DMPAPER_ENV_MONARCH,  3.875,  7.5, true},  
-  {DMPAPER_ENV_PERSONAL, 3.625,  6.5, true},  
-  {DMPAPER_FANFOLD_US,   14.875, 11.0, true},  
-  {DMPAPER_FANFOLD_STD_GERMAN, 8.5, 12.0, true},  
-  {DMPAPER_FANFOLD_LGL_GERMAN, 8.5, 13.0, true},  
-};
-const int32_t kNumPaperSizes = 41;
-
 //----------------------------------------------------------------------------------
 nsDeviceContextSpecWin::nsDeviceContextSpecWin()
 {
   mDriverName    = nullptr;
   mDeviceName    = nullptr;
   mDevMode       = nullptr;
 
 }
@@ -368,106 +311,16 @@ void nsDeviceContextSpecWin::SetDevMode(
 
 //------------------------------------------------------------------
 void 
 nsDeviceContextSpecWin::GetDevMode(LPDEVMODEW &aDevMode)
 {
   aDevMode = mDevMode;
 }
 
-//----------------------------------------------------------------------------------
-// Map an incoming size to a Windows Native enum in the DevMode
-static void 
-MapPaperSizeToNativeEnum(LPDEVMODEW aDevMode,
-                         int16_t   aType, 
-                         double    aW, 
-                         double    aH)
-{
-
-#ifdef DEBUG_rods
-  BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION;
-  BOOL doingPaperSize   = aDevMode->dmFields & DM_PAPERSIZE;
-  BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH;
-  BOOL doingPaperWidth  = aDevMode->dmFields & DM_PAPERWIDTH;
-#endif
-
-  for (int32_t i=0;i<kNumPaperSizes;i++) {
-    if (kPaperSizes[i].mWidth == aW && kPaperSizes[i].mHeight == aH) {
-      aDevMode->dmPaperSize = kPaperSizes[i].mPaperSize;
-      aDevMode->dmFields &= ~DM_PAPERLENGTH;
-      aDevMode->dmFields &= ~DM_PAPERWIDTH;
-      aDevMode->dmFields |= DM_PAPERSIZE;
-      return;
-    }
-  }
-
-  short width  = 0;
-  short height = 0;
-  if (aType == nsIPrintSettings::kPaperSizeInches) {
-    width  = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aW))) / 10);
-    height = short(NS_TWIPS_TO_MILLIMETERS(NS_INCHES_TO_TWIPS(float(aH))) / 10);
-
-  } else if (aType == nsIPrintSettings::kPaperSizeMillimeters) {
-    width  = short(aW / 10.0);
-    height = short(aH / 10.0);
-  } else {
-    return; // don't set anything
-  }
-
-  // width and height is in 
-  aDevMode->dmPaperSize   = 0;
-  aDevMode->dmPaperWidth  = width;
-  aDevMode->dmPaperLength = height;
-
-  aDevMode->dmFields |= DM_PAPERSIZE;
-  aDevMode->dmFields |= DM_PAPERLENGTH;
-  aDevMode->dmFields |= DM_PAPERWIDTH;
-}
-
-//----------------------------------------------------------------------------------
-// Setup Paper Size & Orientation options into the DevMode
-// 
-static void 
-SetupDevModeFromSettings(LPDEVMODEW aDevMode, nsIPrintSettings* aPrintSettings)
-{
-  // Setup paper size
-  if (aPrintSettings) {
-    int16_t type;
-    aPrintSettings->GetPaperSizeType(&type);
-    if (type == nsIPrintSettings::kPaperSizeNativeData) {
-      int16_t paperEnum;
-      aPrintSettings->GetPaperData(&paperEnum);
-      aDevMode->dmPaperSize = paperEnum;
-      aDevMode->dmFields &= ~DM_PAPERLENGTH;
-      aDevMode->dmFields &= ~DM_PAPERWIDTH;
-      aDevMode->dmFields |= DM_PAPERSIZE;
-    } else {
-      int16_t unit;
-      double width, height;
-      aPrintSettings->GetPaperSizeUnit(&unit);
-      aPrintSettings->GetPaperWidth(&width);
-      aPrintSettings->GetPaperHeight(&height);
-      MapPaperSizeToNativeEnum(aDevMode, unit, width, height);
-    }
-
-    // Setup Orientation
-    int32_t orientation;
-    aPrintSettings->GetOrientation(&orientation);
-    aDevMode->dmOrientation = orientation == nsIPrintSettings::kPortraitOrientation?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE;
-    aDevMode->dmFields |= DM_ORIENTATION;
-
-    // Setup Number of Copies
-    int32_t copies;
-    aPrintSettings->GetNumCopies(&copies);
-    aDevMode->dmCopies = copies;
-    aDevMode->dmFields |= DM_COPIES;
-  }
-
-}
-
 #define DISPLAY_LAST_ERROR 
 
 //----------------------------------------------------------------------------------
 // Setup the object's data member with the selected printer's data
 nsresult
 nsDeviceContextSpecWin::GetDataFromPrinter(char16ptr_t aName, nsIPrintSettings* aPS)
 {
   nsresult rv = NS_ERROR_FAILURE;
@@ -496,17 +349,19 @@ nsDeviceContextSpecWin::GetDataFromPrint
     pDevMode = (LPDEVMODEW)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, dwNeeded);
     if (!pDevMode) return NS_ERROR_FAILURE;
 
     // Get the default DevMode for the printer and modify it for our needs.
     dwRet = DocumentPropertiesW(nullptr, hPrinter, name,
                                pDevMode, nullptr, DM_OUT_BUFFER);
 
     if (dwRet == IDOK && aPS) {
-      SetupDevModeFromSettings(pDevMode, aPS);
+      nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aPS);
+      MOZ_ASSERT(psWin);
+      psWin->CopyToNative(pDevMode);
       // Sets back the changes we made to the DevMode into the Printer Driver
       dwRet = ::DocumentPropertiesW(nullptr, hPrinter, name,
                                    pDevMode, pDevMode,
                                    DM_IN_BUFFER | DM_OUT_BUFFER);
     }
 
     if (dwRet != IDOK) {
       ::HeapFree(::GetProcessHeap(), 0, pDevMode);
@@ -527,105 +382,16 @@ nsDeviceContextSpecWin::GetDataFromPrint
   } else {
     rv = NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
     PR_PL(("***** nsDeviceContextSpecWin::GetDataFromPrinter - Couldn't open printer: [%s]\n", NS_ConvertUTF16toUTF8(aName).get()));
     DISPLAY_LAST_ERROR
   }
   return rv;
 }
 
-//----------------------------------------------------------------------------------
-// Setup Paper Size options into the DevMode
-// 
-// When using a data member it may be a HGLOCAL or LPDEVMODE
-// if it is a HGLOBAL then we need to "lock" it to get the LPDEVMODE
-// and unlock it when we are done.
-void 
-nsDeviceContextSpecWin::SetupPaperInfoFromSettings()
-{
-  LPDEVMODEW devMode;
-
-  GetDevMode(devMode);
-  NS_ASSERTION(devMode, "DevMode can't be NULL here");
-  if (devMode) {
-    SetupDevModeFromSettings(devMode, mPrintSettings);
-  }
-}
-
-//----------------------------------------------------------------------------------
-// Helper Function - Free and reallocate the string
-nsresult 
-nsDeviceContextSpecWin::SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, 
-                                                    LPDEVMODEW         aDevMode)
-{
-  if (aPrintSettings == nullptr) {
-    return NS_ERROR_FAILURE;
-  }
-  aPrintSettings->SetIsInitializedFromPrinter(true);
-
-  BOOL doingNumCopies   = aDevMode->dmFields & DM_COPIES;
-  BOOL doingOrientation = aDevMode->dmFields & DM_ORIENTATION;
-  BOOL doingPaperSize   = aDevMode->dmFields & DM_PAPERSIZE;
-  BOOL doingPaperLength = aDevMode->dmFields & DM_PAPERLENGTH;
-  BOOL doingPaperWidth  = aDevMode->dmFields & DM_PAPERWIDTH;
-
-  if (doingOrientation) {
-    int32_t orientation  = aDevMode->dmOrientation == DMORIENT_PORTRAIT?
-      int32_t(nsIPrintSettings::kPortraitOrientation):nsIPrintSettings::kLandscapeOrientation;
-    aPrintSettings->SetOrientation(orientation);
-  }
-
-  // Setup Number of Copies
-  if (doingNumCopies) {
-    aPrintSettings->SetNumCopies(int32_t(aDevMode->dmCopies));
-  }
-
-  if (aDevMode->dmFields & DM_SCALE) {
-    double scale = double(aDevMode->dmScale) / 100.0f;
-    if (scale != 1.0) {
-      aPrintSettings->SetScaling(scale);
-      aDevMode->dmScale = 100;
-      // To turn this on you must change where the mPrt->mShrinkToFit is being set in the DocumentViewer
-      //aPrintSettings->SetShrinkToFit(false);
-    }
-  }
-
-  if (doingPaperSize) {
-    aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeNativeData);
-    aPrintSettings->SetPaperData(aDevMode->dmPaperSize);
-    for (int32_t i=0;i<kNumPaperSizes;i++) {
-      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
-        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches
-          ?int16_t(nsIPrintSettings::kPaperSizeInches):nsIPrintSettings::kPaperSizeMillimeters);
-        break;
-      }
-    }
-
-  } else if (doingPaperLength && doingPaperWidth) {
-    bool found = false;
-    for (int32_t i=0;i<kNumPaperSizes;i++) {
-      if (kPaperSizes[i].mPaperSize == aDevMode->dmPaperSize) {
-        aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined);
-        aPrintSettings->SetPaperWidth(kPaperSizes[i].mWidth);
-        aPrintSettings->SetPaperHeight(kPaperSizes[i].mHeight);
-        aPrintSettings->SetPaperSizeUnit(kPaperSizes[i].mIsInches
-          ?int16_t(nsIPrintSettings::kPaperSizeInches):nsIPrintSettings::kPaperSizeMillimeters);
-        found = true;
-        break;
-      }
-    }
-    if (!found) {
-      return NS_ERROR_FAILURE;
-    }
-  } else {
-    return NS_ERROR_FAILURE;
-  }
-  return NS_OK;
-}
-
 //***********************************************************
 //  Printer Enumerator
 //***********************************************************
 nsPrinterEnumeratorWin::nsPrinterEnumeratorWin()
 {
 }
 
 nsPrinterEnumeratorWin::~nsPrinterEnumeratorWin()
@@ -671,27 +437,26 @@ nsPrinterEnumeratorWin::InitPrintSetting
 
   LPDEVMODEW devmode;
   devSpecWin->GetDevMode(devmode);
   if (NS_WARN_IF(!devmode)) {
     return NS_ERROR_FAILURE;
   }
 
   aPrintSettings->SetPrinterName(aPrinterName);
-  nsDeviceContextSpecWin::SetPrintSettingsFromDevMode(aPrintSettings, devmode);
 
   // We need to get information from the device as well.
   HDC dc = ::CreateICW(kDriverName, aPrinterName, nullptr, devmode);
   if (NS_WARN_IF(!dc)) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aPrintSettings);
   MOZ_ASSERT(psWin);
-  psWin->CopyFromNative(dc);
+  psWin->CopyFromNative(dc, devmode);
   ::DeleteDC(dc);
 
   return NS_OK;
 }
 
 
 //----------------------------------------------------------------------------------
 // Enumerate all the Printers from the global array and pass their
--- a/widget/windows/nsDeviceContextSpecWin.h
+++ b/widget/windows/nsDeviceContextSpecWin.h
@@ -46,27 +46,22 @@ public:
   // whether it is from the Global memory handle or just the DevMode
   // To get the DevMode from the Global memory Handle it must lock it 
   // So this call must be paired with a call to UnlockGlobalHandle
   void GetDevMode(LPDEVMODEW &aDevMode);
 
   // helper functions
   nsresult GetDataFromPrinter(char16ptr_t aName, nsIPrintSettings* aPS = nullptr);
 
-  static nsresult SetPrintSettingsFromDevMode(nsIPrintSettings* aPrintSettings, 
-                                              LPDEVMODEW         aDevMode);
-
 protected:
 
   void SetDeviceName(char16ptr_t aDeviceName);
   void SetDriverName(char16ptr_t aDriverName);
   void SetDevMode(LPDEVMODEW aDevMode);
 
-  void SetupPaperInfoFromSettings();
-
   virtual ~nsDeviceContextSpecWin();
 
   wchar_t*      mDriverName;
   wchar_t*      mDeviceName;
   LPDEVMODEW mDevMode;
 
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
 };
--- a/widget/windows/nsPrintSettingsWin.cpp
+++ b/widget/windows/nsPrintSettingsWin.cpp
@@ -155,19 +155,60 @@ nsPrintSettingsWin::GetEffectivePageSize
   } else {
     *aHeight = NS_INCHES_TO_TWIPS(mPrintableWidthInInches);
     *aWidth = NS_INCHES_TO_TWIPS(mPrintableHeightInInches);
   }
   return NS_OK;
 }
 
 void
-nsPrintSettingsWin::CopyFromNative(HDC aHdc)
+nsPrintSettingsWin::CopyFromNative(HDC aHdc, DEVMODEW* aDevMode)
 {
   MOZ_ASSERT(aHdc);
+  MOZ_ASSERT(aDevMode);
+
+  mIsInitedFromPrinter = true;
+  if (aDevMode->dmFields & DM_ORIENTATION) {
+    mOrientation = int32_t(aDevMode->dmOrientation == DMORIENT_PORTRAIT
+                           ? kPortraitOrientation : kLandscapeOrientation);
+  }
+
+  if (aDevMode->dmFields & DM_COPIES) {
+    mNumCopies = aDevMode->dmCopies;
+  }
+
+  // Since we do the scaling, grab their value and reset back to 100.
+  if (aDevMode->dmFields & DM_SCALE) {
+    double scale = double(aDevMode->dmScale) / 100.0f;
+    if (mScaling == 1.0 || scale != 1.0) {
+      mScaling = scale;
+    }
+    aDevMode->dmScale = 100;
+  }
+
+  if (aDevMode->dmFields & DM_PAPERSIZE) {
+    mPaperData = aDevMode->dmPaperSize;
+  } else {
+    mPaperData = -1;
+  }
+
+  // The length and width in DEVMODE are always in tenths of a millimeter, so
+  // storing them in millimeters is easiest.
+  mPaperSizeUnit = kPaperSizeMillimeters;
+  if (aDevMode->dmFields & DM_PAPERLENGTH) {
+    mPaperHeight = aDevMode->dmPaperLength / 10l;
+  } else {
+    mPaperHeight = -1l;
+  }
+
+  if (aDevMode->dmFields & DM_PAPERWIDTH) {
+    mPaperWidth = aDevMode->dmPaperWidth / 10l;
+  } else {
+    mPaperWidth = -1l;
+  }
 
   // On Windows we currently create a surface using the printable area of the
   // page and don't set the unwriteable [sic] margins. Using the unwriteable
   // margins doesn't appear to work on Windows, but I am not sure if this is a
   // bug elsewhere in our code or a Windows quirk.
   int32_t printableWidthInDots = GetDeviceCaps(aHdc, HORZRES);
   int32_t printableHeightInDots = GetDeviceCaps(aHdc, VERTRES);
   int32_t widthDPI = GetDeviceCaps(aHdc, LOGPIXELSX);
@@ -182,16 +223,67 @@ nsPrintSettingsWin::CopyFromNative(HDC a
     mPrintableHeightInInches = double(printableWidthInDots) / widthDPI;
     mPrintableWidthInInches = double(printableHeightInDots) / heightDPI;
   }
 
   // Using Y to match existing code, X DPI should be the same for printing.
   mResolution = heightDPI;
 }
 
+void
+nsPrintSettingsWin::CopyToNative(DEVMODEW* aDevMode)
+{
+  MOZ_ASSERT(aDevMode);
+
+  if (mPaperData >= 0) {
+    aDevMode->dmPaperSize = mPaperData;
+    aDevMode->dmFields |= DM_PAPERSIZE;
+  } else {
+    aDevMode->dmPaperSize = 0;
+    aDevMode->dmFields &= ~DM_PAPERSIZE;
+  }
+
+  double paperHeight;
+  double paperWidth;
+  if (mPaperSizeUnit == kPaperSizeMillimeters) {
+    paperHeight = mPaperHeight;
+    paperWidth = mPaperWidth;
+  } else {
+    paperHeight = mPaperHeight * MM_PER_INCH_FLOAT;
+    paperWidth = mPaperWidth * MM_PER_INCH_FLOAT;
+  }
+
+  // Set a sensible limit on the minimum height and width.
+  if (paperHeight >= MM_PER_INCH_FLOAT) {
+    // In DEVMODEs, physical lengths are stored in tenths of millimeters.
+    aDevMode->dmPaperLength = paperHeight * 10l;
+    aDevMode->dmFields |= DM_PAPERLENGTH;
+  } else {
+    aDevMode->dmPaperLength = 0;
+    aDevMode->dmFields &= ~DM_PAPERLENGTH;
+  }
+
+  if (paperWidth >= MM_PER_INCH_FLOAT) {
+    aDevMode->dmPaperWidth = paperWidth * 10l;
+    aDevMode->dmFields |= DM_PAPERWIDTH;
+  } else {
+    aDevMode->dmPaperWidth = 0;
+    aDevMode->dmFields &= ~DM_PAPERWIDTH;
+  }
+
+  // Setup Orientation
+  aDevMode->dmOrientation = mOrientation == kPortraitOrientation
+                            ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
+  aDevMode->dmFields |= DM_ORIENTATION;
+
+  // Setup Number of Copies
+  aDevMode->dmCopies = mNumCopies;
+  aDevMode->dmFields |= DM_COPIES;
+}
+
 //-------------------------------------------
 nsresult 
 nsPrintSettingsWin::_Clone(nsIPrintSettings **_retval)
 {
   RefPtr<nsPrintSettingsWin> printSettings = new nsPrintSettingsWin(*this);
   printSettings.forget(_retval);
   return NS_OK;
 }
@@ -272,17 +364,16 @@ Tester::Tester()
     ps->SetPrintRange(15);
     ps->SetHeaderStrLeft(NS_ConvertUTF8toUTF16("Left").get());
     ps->SetHeaderStrCenter(NS_ConvertUTF8toUTF16("Center").get());
     ps->SetHeaderStrRight(NS_ConvertUTF8toUTF16("Right").get());
     ps->SetFooterStrLeft(NS_ConvertUTF8toUTF16("Left").get());
     ps->SetFooterStrCenter(NS_ConvertUTF8toUTF16("Center").get());
     ps->SetFooterStrRight(NS_ConvertUTF8toUTF16("Right").get());
     ps->SetPaperName(NS_ConvertUTF8toUTF16("Paper Name").get());
-    ps->SetPaperSizeType(10);
     ps->SetPaperData(1);
     ps->SetPaperWidth(100.0);
     ps->SetPaperHeight(50.0);
     ps->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
     ps->SetPrintReversed(true);
     ps->SetPrintInColor(true);
     ps->SetOrientation(nsIPrintSettings::kLandscapeOrientation);
     ps->SetPrintCommand(NS_ConvertUTF8toUTF16("Command").get());
@@ -301,10 +392,9 @@ Tester::Tester()
 
     nsCOMPtr<nsIPrintSettings> psClone;
     ps2->Clone(getter_AddRefs(psClone));
 
   }
 
 }
 Tester gTester;
-#endif
-
+#endif
\ No newline at end of file