Hello guys.  I would like to get a little review on this patch, a follow
up to the patches that fix this problem on the screen.  Specifically,
I'm most concerned about making sure my dynamically allocated memory is
freed under all conditions and there's no potential snafus that I'm not
aware of.  Then, of course, if somebody sees something off, please do
comment.

It does indeed completely fix
http://bugs.winehq.org/show_bug.cgi?id=26091 (printed a cute piece of
music with dashed lines).

Thanks all!
Daniel
>From 1e279e21a9f4a989f6c96264af2dfb3e8f67b9a4 Mon Sep 17 00:00:00 2001
From: Daniel Santos <daniel.san...@pobox.com>
Date: Wed, 12 Oct 2011 22:54:44 -0500
Subject: wineps.drv: Implement PS_USERSTYLE on printers
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.3.4"

This is a multi-part message in MIME format.
--------------1.7.3.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


Tests are still missing (need to figure out where they go). Dynamic
memory is required and was added to struct PSPEN, when own_dash is
non-zero, then the memory pointed to by dash needs to be freed. Freeing
is handled by static inline psdrv_cleanup_pen() and called from
PSDRV_SelectPen (when replacing a pen with PS_USERSTYLE) or
PSDRV_DeleteDC.
---
 dlls/wineps.drv/init.c  |    1 +
 dlls/wineps.drv/pen.c   |   57 ++++++++++++++++++++++++++++++++++------------
 dlls/wineps.drv/psdrv.h |    8 ++++++
 3 files changed, 51 insertions(+), 15 deletions(-)


--------------1.7.3.4
Content-Type: text/x-patch; 
name="0004-wineps.drv-Implement-PS_USERSTYLE-on-printers.txt"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; 
filename="0004-wineps.drv-Implement-PS_USERSTYLE-on-printers.txt"

diff --git a/dlls/wineps.drv/init.c b/dlls/wineps.drv/init.c
index 3a6f89f..c2d8449 100644
--- a/dlls/wineps.drv/init.c
+++ b/dlls/wineps.drv/init.c
@@ -402,6 +402,7 @@ static BOOL PSDRV_DeleteDC( PHYSDEV dev )
 
     TRACE("\n");
 
+    psdrv_cleanup_pen( physDev );
     HeapFree( PSDRV_Heap, 0, physDev->Devmode );
     HeapFree( PSDRV_Heap, 0, physDev->job.output );
     HeapFree( PSDRV_Heap, 0, physDev );
diff --git a/dlls/wineps.drv/pen.c b/dlls/wineps.drv/pen.c
index d4ec53b..5d42a1f 100644
--- a/dlls/wineps.drv/pen.c
+++ b/dlls/wineps.drv/pen.c
@@ -19,6 +19,7 @@
  */
 
 #include <stdarg.h>
+#include <stdio.h>
 
 #include "windef.h"
 #include "winbase.h"
@@ -41,25 +42,21 @@ HPEN PSDRV_SelectPen( PHYSDEV dev, HPEN hpen )
 {
     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
     LOGPEN logpen;
-
-    if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
-    {
-        /* must be an extended pen */
-        EXTLOGPEN *elp;
-        INT size = GetObjectW( hpen, 0, NULL );
-
-        if (!size) return 0;
-
+    int i;
+    EXTLOGPEN *elp = NULL;
+    INT size = GetObjectW( hpen, 0, NULL );
+
+    if (!size) return 0;
+    else if (size == sizeof(logpen)) {
+        GetObjectW( hpen, sizeof(logpen), &logpen );
+    } else {
         elp = HeapAlloc( GetProcessHeap(), 0, size );
 
         GetObjectW( hpen, size, elp );
-        /* FIXME: add support for user style pens */
         logpen.lopnStyle = elp->elpPenStyle;
         logpen.lopnWidth.x = elp->elpWidth;
         logpen.lopnWidth.y = 0;
         logpen.lopnColor = elp->elpColor;
-
-        HeapFree( GetProcessHeap(), 0, elp );
     }
 
     TRACE("hpen = %p colour = %08x\n", hpen, logpen.lopnColor);
@@ -90,6 +87,9 @@ HPEN PSDRV_SelectPen( PHYSDEV dev, HPEN hpen )
     }
 
     PSDRV_CreateColor(dev, &physDev->pen.color, logpen.lopnColor);
+
+    psdrv_cleanup_pen( physDev );
+    physDev->pen.own_dash = 0;
     physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
 
     switch(physDev->pen.style) {
@@ -114,18 +114,45 @@ HPEN PSDRV_SelectPen( PHYSDEV dev, HPEN hpen )
        break;
 
     case PS_USERSTYLE:
-       FIXME("PS_USERSTYLE is not supported on ps device (printer)\n");
-       /* fall through */
+    {
+        /* buf in PSDRV_WriteSetPen should be 14 bytes with zero-length dash, 
so
+         * 240 should be a reasonable limit. */
+        char buf[240];
+        char *p = buf;
+        const char *pattern = "%d";     /* don't put a space in front of the 
1st number */
+        int buf_size = sizeof(buf);
+
+        for (i = 0; i < elp->elpNumEntries; ++i) {
+            p += snprintf(p, buf_size, pattern, elp->elpStyleEntry[i]);
+            buf_size = &buf[sizeof(buf)] - p;
+            if (buf_size <= 0) {
+                /* buffer underrun */
+                WARN("buffer underrun formatting PS_USERSTYLE into 
postscript\n");
+                break;
+            }
+            pattern = " %d";
+        }
+
+        if (! (physDev->pen.dash = HeapAlloc( GetProcessHeap(), 0, strlen(buf) 
+ 1 ) ) ) {
+            HeapFree( GetProcessHeap(), 0, elp );
+            return 0;
+        }
+        physDev->pen.own_dash = 1;
+        strcpy((char *)physDev->pen.dash, buf);
+        break;
+    }
 
     default:
        physDev->pen.dash = NULL;
     }
 
-    if ((physDev->pen.width > 1) && (physDev->pen.dash != NULL)) {
+    if ((physDev->pen.style != PS_USERSTYLE) && (physDev->pen.width > 1) && 
(physDev->pen.dash != NULL)) {
        physDev->pen.style = PS_SOLID;
          physDev->pen.dash = NULL;
     }
 
+    if (elp) HeapFree( GetProcessHeap(), 0, elp );
+
     physDev->pen.set = FALSE;
     return hpen;
 }
diff --git a/dlls/wineps.drv/psdrv.h b/dlls/wineps.drv/psdrv.h
index 8047942..caed5f3 100644
--- a/dlls/wineps.drv/psdrv.h
+++ b/dlls/wineps.drv/psdrv.h
@@ -337,6 +337,7 @@ typedef struct {
     const char*                dash;
     PSCOLOR            color;
     BOOL               set;
+    BOOL                own_dash;       /* TRUE if we need to free dash */
 } PSPEN;
 
 typedef struct {
@@ -390,6 +391,13 @@ static inline PSDRV_PDEVICE *get_psdrv_dev( PHYSDEV dev )
     return (PSDRV_PDEVICE *)dev;
 }
 
+static inline void psdrv_cleanup_pen(PSDRV_PDEVICE *dev) {
+    if (dev->pen.own_dash) {
+        HeapFree( GetProcessHeap(), 0, (LPVOID)dev->pen.dash );
+        dev->pen.own_dash = 0;
+    }
+}
+
 /*
  *  Every glyph name in the Adobe Glyph List and the 35 core PostScript fonts
  */

--------------1.7.3.4--




Reply via email to