Commit 5a379c11 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

Escape non-printable characters in the document title and also

truncate it to 0x80 characters.
parent 6eb0c353
...@@ -250,11 +250,65 @@ INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value, ...@@ -250,11 +250,65 @@ INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
return 1; 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 ) INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
{ {
char *buf; char *buf, *escaped_title;
INPUTSLOT *slot; INPUTSLOT *slot;
PAGESIZE *page; PAGESIZE *page;
DUPLEX *duplex; DUPLEX *duplex;
...@@ -263,8 +317,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title ) ...@@ -263,8 +317,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
TRACE("'%s'\n", debugstr_a(title)); TRACE("'%s'\n", debugstr_a(title));
escaped_title = escape_title(title);
buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) + buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
(title ? strlen(title) : 0) + 30 ); strlen(escaped_title) + 30 );
if(!buf) { if(!buf) {
WARN("HeapAlloc failed\n"); WARN("HeapAlloc failed\n");
return 0; return 0;
...@@ -278,8 +333,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title ) ...@@ -278,8 +333,9 @@ INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY; ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
/* FIXME should do something better with BBox */ /* 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) ) != if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
strlen(buf) ) { strlen(buf) ) {
WARN("WriteSpool error\n"); WARN("WriteSpool error\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment