wine/dlls/wineps ps.c

Alexandre Julliard julliard at wine.codeweavers.com
Wed Nov 9 06:55:19 CST 2005


ChangeSet ID:	21195
CVSROOT:	/opt/cvs-commit
Module name:	wine
Changes by:	julliard at winehq.org	2005/11/09 06:55:18

Modified files:
	dlls/wineps    : ps.c 

Log message:
	Huw Davies <huw at codeweavers.com>
	Escape non-printable characters in the document title and also
	truncate it to 0x80 characters.

Patch: http://cvs.winehq.org/patch.py?id=21195

Old revision  New revision  Changes     Path
 1.33          1.34          +60 -4      wine/dlls/wineps/ps.c

Index: wine/dlls/wineps/ps.c
diff -u -p wine/dlls/wineps/ps.c:1.33 wine/dlls/wineps/ps.c:1.34
--- wine/dlls/wineps/ps.c:1.33	9 Nov 2005 12:55:18 -0000
+++ wine/dlls/wineps/ps.c	9 Nov 2005 12:55:18 -0000
@@ -250,11 +250,65 @@ INT PSDRV_WriteFeature(HANDLE16 hJob, ch
     return 1;
 }
 
-
+/********************************************************
+ *         escape_title
+ *
+ * Helper for PSDRV_WriteHeader.  Escape any non-printable characters
+ * as octal.  If we've had to use an escape then surround the entire string
+ * in brackets.  Truncate string to represent at most 0x80 characters.
+ *
+ */
+static char *escape_title(LPCSTR str)
+{
+    char *ret, *cp;
+    int i, extra = 0;
+
+    if(!str)
+    {
+        ret = HeapAlloc(GetProcessHeap(), 0, 1);
+        *ret = '\0';
+        return ret;
+    }
+
+    for(i = 0; i < 0x80 && str[i]; i++)
+    {
+        if(!isprint(str[i]))
+           extra += 3;
+    }
+
+    if(!extra)
+    {
+        ret = HeapAlloc(GetProcessHeap(), 0, i + 1);
+        memcpy(ret, str, i);
+        ret[i] = '\0';
+        return ret;
+    }
+
+    extra += 2; /* two for the brackets */
+    cp = ret = HeapAlloc(GetProcessHeap(), 0, i + extra + 1);
+    *cp++ = '(';
+    for(i = 0; i < 0x80 && str[i]; i++)
+    {
+        if(!isprint(str[i]))
+        {
+            BYTE b = (BYTE)str[i];
+            *cp++ = '\\';
+            *cp++ = ((b >> 6) & 0x7) + '0';
+            *cp++ = ((b >> 3) & 0x7) + '0';
+            *cp++ = ((b)      & 0x7) + '0';
+        }
+        else
+            *cp++ = str[i];
+    }
+    *cp++ = ')';
+    *cp = '\0';
+    return ret;
+}
+       
 
 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
 {
-    char *buf;
+    char *buf, *escaped_title;
     INPUTSLOT *slot;
     PAGESIZE *page;
     DUPLEX *duplex;
@@ -263,8 +317,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *ph
 
     TRACE("'%s'\n", debugstr_a(title));
 
+    escaped_title = escape_title(title);
     buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
-                     (title ? strlen(title) : 0) + 30 );
+                     strlen(escaped_title) + 30 );
     if(!buf) {
         WARN("HeapAlloc failed\n");
         return 0;
@@ -278,8 +333,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *ph
     ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
     /* FIXME should do something better with BBox */
 
-    sprintf(buf, psheader, title ? title : "", llx, lly, urx, ury);
+    sprintf(buf, psheader, escaped_title, llx, lly, urx, ury);
 
+    HeapFree(GetProcessHeap(), 0, escaped_title);
     if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
 	                                             strlen(buf) ) {
         WARN("WriteSpool error\n");



More information about the wine-cvs mailing list