diff --git a/embedding/components/printingui/src/win/nsPrintDialogUtil.cpp b/embedding/components/printingui/src/win/nsPrintDialogUtil.cpp index 23210290f05..e9b72322d9a 100644 --- a/embedding/components/printingui/src/win/nsPrintDialogUtil.cpp +++ b/embedding/components/printingui/src/win/nsPrintDialogUtil.cpp @@ -976,6 +976,25 @@ ShowNativePrintDialog(HWND aHWnd, char* device = &(((char *)devnames)[devnames->wDeviceOffset]); char* driver = &(((char *)devnames)[devnames->wDriverOffset]); + // Check to see if the "Print To File" control is checked + // then take the name from devNames and set it in the PrintSettings + // + // NOTE: + // As per Microsoft SDK documentation the returned value offset from + // devnames->wOutputOffset is either "FILE:" or NULL + // if the "Print To File" checkbox is checked it MUST be "FILE:" + // We assert as an extra safety check. + if (prntdlg.Flags & PD_PRINTTOFILE) { + char* fileName = &(((char *)devnames)[devnames->wOutputOffset]); + NS_ASSERTION(strcmp(fileName, "FILE:") == 0, "FileName must be `FILE:`"); + aPrintSettings->SetToFileName(NS_ConvertASCIItoUCS2(fileName).get()); + aPrintSettings->SetPrintToFile(PR_TRUE); + } else { + // clear "print to file" info + aPrintSettings->SetPrintToFile(PR_FALSE); + aPrintSettings->SetToFileName(nsnull); + } + nsCOMPtr psWin(do_QueryInterface(aPrintSettings)); // Setup local Data members psWin->SetDeviceName(device); @@ -1294,6 +1313,25 @@ ShowNativePrintDialogEx(HWND aHWnd, char* device = &(((char *)devnames)[devnames->wDeviceOffset]); char* driver = &(((char *)devnames)[devnames->wDriverOffset]); + // Check to see if the "Print To File" control is checked + // then take the name from devNames and set it in the PrintSettings + // + // NOTE: + // As per Microsoft SDK documentation the returned value offset from + // devnames->wOutputOffset is either "FILE:" or NULL + // if the "Print To File" checkbox is checked it MUST be "FILE:" + // We assert as an extra safety check. + if (prntdlg.Flags & PD_PRINTTOFILE) { + char* fileName = &(((char *)devnames)[devnames->wOutputOffset]); + NS_ASSERTION(strcmp(fileName, "FILE:") == 0, "FileName must be `FILE:`"); + aPrintSettings->SetToFileName(NS_ConvertASCIItoUCS2(fileName).get()); + aPrintSettings->SetPrintToFile(PR_TRUE); + } else { + // clear "print to file" info + aPrintSettings->SetPrintToFile(PR_FALSE); + aPrintSettings->SetToFileName(nsnull); + } + nsCOMPtr psWin(do_QueryInterface(aPrintSettings)); // Setup local Data members psWin->SetDeviceName(device); diff --git a/gfx/src/windows/nsDeviceContextSpecWin.cpp b/gfx/src/windows/nsDeviceContextSpecWin.cpp index f9cc95a4973..a0f7d46e3a3 100644 --- a/gfx/src/windows/nsDeviceContextSpecWin.cpp +++ b/gfx/src/windows/nsDeviceContextSpecWin.cpp @@ -372,6 +372,21 @@ CheckForPrintToFile(nsIPrintSettings* aPS, LPTSTR aPrinterName, PRUnichar* aUPri CheckForPrintToFileWithName((char*)NS_ConvertUCS2toUTF8(aUPrinterName).get(), toFile); } #endif + // Since the driver wasn't a "Print To File" Driver, check to see + // if the name of the file has been set to the special "FILE:" + if (!toFile) { + nsXPIDLString toFileName; + aPS->GetToFileName(getter_Copies(toFileName)); + if (toFileName) { + if (*toFileName) { + if (toFileName.Equals(NS_LITERAL_STRING("FILE:"))) { + // this skips the setting of the "print to file" info below + // which we don't want to do. + return NS_OK; + } + } + } + } aPS->SetPrintToFile(toFile); if (toFile) { rv = GetFileNameForPrintSettings(aPS);