From 780667fe1e2ef395bd2f3447fc20df851a6dc2dc Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Thu, 12 Feb 2004 20:05:22 +0000 Subject: [PATCH] Bracket code inserted by the PASSTHROUGH escapes by %%{Begin,End}Document. This stops cups' pstops becoming confused if it comes across an %%EOF in an imported eps file. The hack in PSDRV_Rectangle to fix eps files in office2k turns out to be almost what Windows really does - update the code and the comment to match Windows behaviour more precisely. --- dlls/wineps/escape.c | 11 ++++++++++- dlls/wineps/graphics.c | 11 +++++++---- dlls/wineps/ps.c | 8 ++++++++ dlls/wineps/psdrv.h | 2 ++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/dlls/wineps/escape.c b/dlls/wineps/escape.c index e730e3948ae..dbc343a4346 100644 --- a/dlls/wineps/escape.c +++ b/dlls/wineps/escape.c @@ -31,6 +31,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(psdrv); +static const char psbegindocument[] = +"%%BeginDocument: Wine passthrough\n"; + /********************************************************************** * ExtEscape (WINEPS.@) */ @@ -214,6 +217,10 @@ INT PSDRV_ExtEscape( PSDRV_PDEVICE *physDev, INT nEscape, INT cbInput, LPCVOID i * length of the string, rather than 2 more. So we'll use the WORD at * in_data[0] instead. */ + if(!physDev->job.in_passthrough) { + WriteSpool16(physDev->job.hJob, (LPSTR)psbegindocument, sizeof(psbegindocument)-1); + physDev->job.in_passthrough = TRUE; + } return WriteSpool16(physDev->job.hJob,((char*)in_data)+2,*(WORD*)in_data); } @@ -373,7 +380,9 @@ INT PSDRV_StartDoc( PSDRV_PDEVICE *physDev, const DOCINFOA *doc ) physDev->job.banding = FALSE; physDev->job.OutOfPage = TRUE; physDev->job.PageNo = 0; - + physDev->job.quiet = FALSE; + physDev->job.in_passthrough = FALSE; + physDev->job.had_passthrough_rect = FALSE; if(doc->lpszDocName) { physDev->job.DocName = HeapAlloc(GetProcessHeap(), 0, strlen(doc->lpszDocName)+1); strcpy(physDev->job.DocName, doc->lpszDocName); diff --git a/dlls/wineps/graphics.c b/dlls/wineps/graphics.c index f5a040e6284..121343dec33 100644 --- a/dlls/wineps/graphics.c +++ b/dlls/wineps/graphics.c @@ -124,11 +124,14 @@ BOOL PSDRV_Rectangle( PSDRV_PDEVICE *physDev, INT left, INT top, INT right, INT rect.bottom = bottom; LPtoDP( physDev->hdc, (POINT *)&rect, 2 ); - /* HACK to get inserted eps files printing from Office 2k */ - if(GetROP2(physDev->hdc) == R2_NOP) { + /* Windows does something truely hacky here. If we're in passthrough mode + and our rop is R2_NOP, then we output the string below. This is used in + Office 2k when inserting eps files */ + if(physDev->job.in_passthrough && !physDev->job.had_passthrough_rect && GetROP2(physDev->hdc) == R2_NOP) { char buf[256]; - sprintf(buf, "%ld %ld %ld %ld B\n", rect.right - rect.left, rect.bottom - rect.top, rect.left, rect.top); - PSDRV_WriteSpool(physDev, buf, strlen(buf)); + sprintf(buf, "N %ld %ld %ld %ld B\n", rect.right - rect.left, rect.bottom - rect.top, rect.left, rect.top); + WriteSpool16(physDev->job.hJob, buf, strlen(buf)); + physDev->job.had_passthrough_rect = TRUE; return TRUE; } diff --git a/dlls/wineps/ps.c b/dlls/wineps/ps.c index 78433bb5ccf..a594d3ff5fa 100644 --- a/dlls/wineps/ps.c +++ b/dlls/wineps/ps.c @@ -60,6 +60,7 @@ static const char psprolog[] = " for\n" "} bind def\n" "/B {pop pop pop pop} def\n" +"/N {newpath} def\n" "/havetype42gdir {version cvi 2015 ge} bind def\n"; static const char psbeginsetup[] = @@ -195,6 +196,8 @@ static const char psarrayput[] = static const char psarraydef[] = "/%s %d array def\n"; +static const char psenddocument[] = +"\n%%EndDocument\n"; DWORD PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, DWORD cch) { @@ -205,6 +208,11 @@ DWORD PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, DWORD cch) return 0; } + if(physDev->job.in_passthrough) { /* Was in PASSTHROUGH mode */ + WriteSpool16( physDev->job.hJob, (LPSTR)psenddocument, sizeof(psenddocument)-1 ); + physDev->job.in_passthrough = physDev->job.had_passthrough_rect = FALSE; + } + if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */ if( !PSDRV_StartPage(physDev) ) return 0; diff --git a/dlls/wineps/psdrv.h b/dlls/wineps/psdrv.h index f08a1b6f7f1..849fa7a0937 100644 --- a/dlls/wineps/psdrv.h +++ b/dlls/wineps/psdrv.h @@ -321,6 +321,8 @@ typedef struct { BOOL OutOfPage; /* Page header not sent yet */ INT PageNo; BOOL quiet; /* Don't actually output anything */ + BOOL in_passthrough; /* In PASSTHROUGH mode */ + BOOL had_passthrough_rect; /* See the comment in PSDRV_Rectangle */ } JOB; typedef struct {