From f4e5a1d71b62a55071ce66a04c0f2e09271d0546 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Fri, 19 Sep 2014 22:12:30 +0930 Subject: [PATCH 12/12] pdftocairo: Add additional call to DocumentProperties to merge new settings with old as specified by MSDN documentation. --- utils/pdftocairo-win32.cc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/utils/pdftocairo-win32.cc b/utils/pdftocairo-win32.cc index f6ca7ea..8a9a312 100644 --- a/utils/pdftocairo-win32.cc +++ b/utils/pdftocairo-win32.cc @@ -8,6 +8,7 @@ static HDC hdc; static DEVMODEA *devmode; +static char *printerName; struct Win32Option { @@ -141,22 +142,20 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF GooString *printOpt, GBool duplex) { - if (printer->getCString()[0] == 0) - { - DWORD szName = 0; - GetDefaultPrinterA(NULL, &szName); - char *devname = (char*)gmalloc(szName); - GetDefaultPrinterA(devname, &szName); - printer->Set(devname); - gfree(devname); + if (printer->getCString()[0] == 0) { + DWORD size = 0; + GetDefaultPrinterA(NULL, &size); + printerName = (char*)gmalloc(size); + GetDefaultPrinterA(printerName, &size); + } else { + printerName = gstrndup(printer->getCString(), printer->getLength()); } - char *cPrinter = printer->getCString(); //Query the size of the DEVMODE struct - LONG szProp = DocumentPropertiesA(NULL, NULL, cPrinter, NULL, NULL, 0); + LONG szProp = DocumentPropertiesA(NULL, NULL, printerName, NULL, NULL, 0); if (szProp < 0) { - fprintf(stderr, "Error: Printer \"%s\" not found", cPrinter); + fprintf(stderr, "Error: Printer \"%s\" not found", printerName); exit(99); } devmode = (DEVMODEA*)gmalloc(szProp); @@ -164,17 +163,18 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF devmode->dmSize = sizeof(DEVMODEA); devmode->dmSpecVersion = DM_SPECVERSION; //Load the current default configuration for the printer into devmode - if (DocumentPropertiesA(NULL, NULL, cPrinter, devmode, NULL, DM_OUT_BUFFER) < 0) + if (DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, DM_OUT_BUFFER) < 0) { - fprintf(stderr, "Error: Printer \"%s\" not found", cPrinter); + fprintf(stderr, "Error: Printer \"%s\" not found", printerName); exit(99); } fillCommonPrinterOptions(w, h, duplex); fillPrinterOptions(duplex, printOpt); - hdc = CreateDCA(NULL, cPrinter, NULL, devmode); + DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER); + hdc = CreateDCA(NULL, printerName, NULL, devmode); if (!hdc) { - fprintf(stderr, "Error: Printer \"%s\" not found", cPrinter); + fprintf(stderr, "Error: Printer \"%s\" not found", printerName); exit(99); } @@ -200,6 +200,7 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF void win32BeginPage(double *w, double *h, GBool useFullPage) { fillPagePrinterOptions(*w, *h); + DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER); ResetDCA(hdc, devmode); // Get actual paper size or if useFullPage is false the printable area. @@ -243,6 +244,7 @@ void win32EndDocument() EndDoc(hdc); DeleteDC(hdc); gfree(devmode); + gfree(printerName); } #endif // CAIRO_HAS_WIN32_SURFACE -- 2.1.0