Index: toolkit/components/printing/content/printdialog.js
===================================================================
RCS file: /cvsroot/mozilla/toolkit/components/printing/content/printdialog.js,v
retrieving revision 1.6
diff -u -8 -p -r1.6 printdialog.js
--- toolkit/components/printing/content/printdialog.js	9 Mar 2005 18:54:03 -0000	1.6
+++ toolkit/components/printing/content/printdialog.js	8 Apr 2010 14:57:15 -0000
@@ -278,16 +278,22 @@ function loadDialog()
     gOriginalNumCopies  = gPrintSettings.numCopies;
 
     print_copies        = gPrintSettings.numCopies;
     print_frametype     = gPrintSettings.printFrameType;
     print_howToEnableUI = gPrintSettings.howToEnableFrameUI;
     print_selection_radio_enabled = gPrintSettings.GetPrintOptions(gPrintSetInterface.kEnableSelectionRB);
   }
 
+  // BUGFIX: retrieve global settings
+  var prefs_p = getPrintSettings_p();
+
+  gPrintSettings.shrinkToFit = prefs_p.shrinkToFit;
+  gPrintSettings.scaling = prefs_p.scaling;
+
   if (doDebug) {
     dump("loadDialog*********************************************\n");
     dump("print_tofile            "+print_tofile+"\n");
     dump("print_frame             "+print_frametype+"\n");
     dump("print_howToEnableUI     "+print_howToEnableUI+"\n");
     dump("selection_radio_enabled "+print_selection_radio_enabled+"\n");
   }
 
@@ -401,36 +407,16 @@ function onAccept()
       dump("printRange     "+gPrintSettings.printRange+"\n");
       dump("printerName    "+gPrintSettings.printerName+"\n");
       dump("startPageRange "+gPrintSettings.startPageRange+"\n");
       dump("endPageRange   "+gPrintSettings.endPageRange+"\n");
       dump("printToFile    "+gPrintSettings.printToFile+"\n");
     }
   }
 
-  var saveToPrefs = false;
-
-  saveToPrefs = gPrefs.getBoolPref("print.save_print_settings");
-
-  if (saveToPrefs && printService != null) {
-    var flags = gPrintSetInterface.kInitSavePaperSizeType  | 
-                gPrintSetInterface.kInitSavePaperSizeUnit  |
-                gPrintSetInterface.kInitSavePaperWidth     | 
-                gPrintSetInterface.kInitSavePaperHeight    |
-                gPrintSetInterface.kInitSavePaperName      | 
-                gPrintSetInterface.kInitSaveColorSpace     |
-                gPrintSetInterface.kInitSaveInColor        |
-                gPrintSetInterface.kInitSaveResolutionName |
-                gPrintSetInterface.kInitSaveDownloadFonts  |
-                gPrintSetInterface.kInitSavePrintCommand   |
-                gPrintSetInterface.kInitSaveShrinkToFit    |
-                gPrintSetInterface.kInitSaveScaling;
-    printService.savePrintSettingsToPrefs(gPrintSettings, true, flags);
-  }
-
   // set return value to "print"
   if (paramBlock) {
     paramBlock.SetInt(0, 1);
   } else {
     dump("*** FATAL ERROR: No paramBlock\n");
   }
 
   return true;
@@ -465,8 +451,53 @@ function chooseFile()
     }
   } catch(ex) {
     dump(ex);
   }
 
   return false;
 }
 
+  /* Functions taken from xpfe/communicator/resources/content/printing.js
+   * Needed to retrieve some global options as it is made in "print preview".
+   * Corrects a bug that prevented some settings like shrinktofit and scaling
+   * from beeing correctly applied to prints
+   */
+
+function setPrinterDefaultsForSelectedPrinter_p(aPSSVC, aPrintSettings)
+{
+  if (!aPrintSettings.printerName)
+    aPrintSettings.printerName = aPSSVC.defaultPrinterName;
+
+  // First get any defaults from the printer
+  aPSSVC.initPrintSettingsFromPrinter(aPrintSettings.printerName, aPrintSettings);
+  // now augment them with any values from last time
+  aPSSVC.initPrintSettingsFromPrefs(aPrintSettings, true,  aPrintSettings.kInitSaveAll);
+}
+
+function getPrintSettings_p()
+{
+  var gPrintSettingsAreGlobal = false;
+  var gSavePrintSettings = false;
+
+  var pref = Components.classes["@mozilla.org/preferences-service;1"]
+                       .getService(Components.interfaces.nsIPrefBranch);
+
+  if (pref) {
+    gPrintSettingsAreGlobal = pref.getBoolPref("print.use_global_printsettings", false);
+    gSavePrintSettings = pref.getBoolPref("print.save_print_settings", false);
+  }
+
+  var printSettings;
+  try {
+    var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"]
+                          .getService(Components.interfaces.nsIPrintSettingsService);
+    if (gPrintSettingsAreGlobal) {
+      printSettings = PSSVC.globalPrintSettings;
+      this.setPrinterDefaultsForSelectedPrinter_p(PSSVC, printSettings);
+    } else {
+      printSettings = PSSVC.newPrintSettings;
+    }
+  } catch (e) {
+    dump("getPrintSettings: "+e+"\n");
+  }
+  return printSettings;
+}
