[Wine-patches] [eter-2.1] winspool.drv: Directly use printer job information instead of querying it from printer/job handle. (eterbug #9222)

Dmitry Timoshkov dtimoshkov на etersoft.ru
Ср Май 15 06:40:54 MSK 2013


---
 dlls/winspool.drv/info.c | 57 +++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 34 deletions(-)

diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c
index e8ae259..ea35893 100644
--- a/dlls/winspool.drv/info.c
+++ b/dlls/winspool.drv/info.c
@@ -8398,47 +8398,44 @@ end:
  *      helper function to pack printer name, task name, collate
  *      and number of pages into output string.
  */
-static void prepare_destination_string(HANDLE hPrinter, DWORD JobId, LPWSTR output)
+static void prepare_destination_string(const job_t *job, LPWSTR output)
 {
     static const WCHAR defaultname[] = {'n','o',' ','n','a','m','e',0};
     static const WCHAR comstr[] = {'|','l','p','r',' ','-','P','\'','%','s',
         '\'',' ','-','T','\'','%','s','\'',' ','-','#',' ','%','u',' ','-','o',
         ' ','C','o','l','l','a','t','e','=','%','s',' ','%','s',0};
 /* PM_SIDES */
-        static const WCHAR sidesnoDuplex[] = {'-','o',' ','s','i','d','e','s','=', 'o','n','e','-','s','i','d','e','d',0};
-        static const WCHAR sideslongDuplex[] = {'-','o',' ','s','i','d','e','s','=', 't','w','o','-','s','i','d','e','d','-',
+    static const WCHAR sidesnoDuplex[] = {'-','o',' ','s','i','d','e','s','=', 'o','n','e','-','s','i','d','e','d',0};
+    static const WCHAR sideslongDuplex[] = {'-','o',' ','s','i','d','e','s','=', 't','w','o','-','s','i','d','e','d','-',
         'l','o','n','g','-','e','d','g','e',0};
-        static const WCHAR sidesshortDuplex[] = {'-','o',' ','s','i','d','e','s','=', 't','w','o','-','s','i','d','e','d','-',
+    static const WCHAR sidesshortDuplex[] = {'-','o',' ','s','i','d','e','s','=', 't','w','o','-','s','i','d','e','d','-',
         's','h','o','r','t','-','e','d','g','e',0};
 /* PM_DUPLEX
         https://bugs.etersoft.ru/show_bug.cgi?id=3982#c5
 */
-        static const WCHAR noDuplex[] = {0};
-        static const WCHAR longDuplex[] = {'-','o',' ','D','u','p','l','e','x','=', 'D','u','p','l','e','x','N','o','T','u','m','b','l','e',0};
-        static const WCHAR shortDuplex[] = {'-','o',' ','D','u','p','l','e','x','=', 'D','u','p','l','e','x','T','u','m','b','l','e',0};
-
+    static const WCHAR noDuplex[] = {0};
+    static const WCHAR longDuplex[] = {'-','o',' ','D','u','p','l','e','x','=', 'D','u','p','l','e','x','N','o','T','u','m','b','l','e',0};
+    static const WCHAR shortDuplex[] = {'-','o',' ','D','u','p','l','e','x','=', 'D','u','p','l','e','x','T','u','m','b','l','e',0};
     static const WCHAR trueW[] = {'T','r','u','e',0};
     static const WCHAR falseW[] = {'F','a','l','s','e',0};
     const WCHAR* option_sides;
     const WCHAR* option_duplex;
-    LPWSTR docname;
-    JOB_INFO_2W *ji2 = NULL;
-    DWORD needed;
-    DEVMODEW *dm;
-
-    GetJobW(hPrinter, JobId, 2, NULL, 0, &needed);
-    ji2 = HeapAlloc(GetProcessHeap(), 0, needed);
-    if (!GetJobW(hPrinter, JobId, 2, (LPBYTE)ji2, needed, &needed))
-        ERR("GetJobW failed\n");
-    dm = ji2->pDevMode;
     /* if DEVMODE doesn't specify what we need - set sane defaults */
-    if (!(dm->dmFields & DM_COPIES)) dm->u1.s1.dmCopies = 1;
-    if (!(dm->dmFields & DM_DUPLEX)) dm->dmDuplex = DMDUP_SIMPLEX;
-    if (!(dm->dmFields & DM_COLLATE)) dm->dmCollate = DMCOLLATE_FALSE;
-    docname = ji2->pDocument;
+    int copies = 1, duplex = DMDUP_SIMPLEX, collate = DMCOLLATE_FALSE;
+    const WCHAR *docname = job->document_title;
 
-    switch (dm->dmDuplex)
+    if (job->devmode->dmFields & DM_COPIES)
+        copies = job->devmode->u1.s1.dmCopies;
+    if (job->devmode->dmFields & DM_DUPLEX)
+        duplex = job->devmode->dmDuplex;
+    if (job->devmode->dmFields & DM_COLLATE)
+        collate = job->devmode->dmCollate;
+
+    switch (duplex)
     {
+    default:
+        ERR("Unexpected value of dmDuplex field %d\n", duplex);
+        /* fall through */
     case DMDUP_SIMPLEX:
         option_sides = sidesnoDuplex;
         option_duplex = noDuplex;
@@ -8451,22 +8448,14 @@ static void prepare_destination_string(HANDLE hPrinter, DWORD JobId, LPWSTR outp
         option_sides = sidesshortDuplex;
         option_duplex = shortDuplex;
         break;
-    default:
-        option_sides = sidesnoDuplex;
-        option_duplex = noDuplex;
-        ERR("Unexpected value of dmDuplex field\n");
-        break;
     }
 
     if (eterprinting_method() == PM_SIDES)
         option_duplex = option_sides;
-    sprintfW(output, comstr, ji2->pPrinterName,lstrlenW(docname)?docname:defaultname,
-             dm->u1.s1.dmCopies, dm->dmCollate?trueW:falseW, option_duplex);
-    HeapFree(GetProcessHeap(), 0, ji2);
+    sprintfW(output, comstr, job->printer_name, docname && *docname ? docname : defaultname,
+             copies, collate == DMCOLLATE_TRUE ? trueW : falseW, option_duplex);
 }
 
-
-
 /*****************************************************************************
  *          ScheduleJob [WINSPOOL.@]
  *
@@ -8528,7 +8517,7 @@ BOOL WINAPI ScheduleJob( HANDLE hPrinter, DWORD dwJobID )
             /* Etersoft printing system                 */
             /* fix eterbug #4111 #4721, #2843, #3688    */
 
-            prepare_destination_string(hPrinter, dwJobID, output);
+            prepare_destination_string(job, output);
             TRACE("Destination string = '%s'\n", debugstr_w(output));
             /* End of Etersoft printing */
         }
-- 
1.8.2.3



Подробная информация о списке рассылки Wine-patches