[PATCH v2 0/5] MR5791: wineps.drv: Page size and orientation fixes
-- v2: wineps.drv: Add partial support for changing page size. wineps.drv: Write PageBoundingBox for every page. wineps.drv: Take all pages into account when computing bounding box. wineps.drv: Write page orientation hint for every page. https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/wineps.drv/ps.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/dlls/wineps.drv/ps.c b/dlls/wineps.drv/ps.c index 59e245b9b6c..149bfc81c36 100644 --- a/dlls/wineps.drv/ps.c +++ b/dlls/wineps.drv/ps.c @@ -526,19 +526,11 @@ INT PSDRV_WriteEndPage( print_ctx *ctx ) INT PSDRV_WriteNewPage( print_ctx *ctx ) { - char *buf; - char name[100]; signed int xtrans, ytrans, rotation; - int ret = 1; + char buf[256], name[16]; sprintf(name, "%d", ctx->job.PageNo); - buf = HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage) + 200 ); - if(!buf) { - WARN("HeapAlloc failed\n"); - return 0; - } - if(ctx->Devmode->dmPublic.dmOrientation == DMORIENT_LANDSCAPE) { if(ctx->pi->ppd->LandscapeOrientation == -90) { xtrans = GetDeviceCaps(ctx->hdc, PHYSICALHEIGHT) - @@ -564,10 +556,9 @@ INT PSDRV_WriteNewPage( print_ctx *ctx ) if( write_spool( ctx, buf, strlen(buf) ) != strlen(buf) ) { WARN("WriteSpool error\n"); - ret = 0; + return 0; } - HeapFree( GetProcessHeap(), 0, buf ); - return ret; + return 1; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/wineps.drv/ps.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dlls/wineps.drv/ps.c b/dlls/wineps.drv/ps.c index 149bfc81c36..e1be2261e15 100644 --- a/dlls/wineps.drv/ps.c +++ b/dlls/wineps.drv/ps.c @@ -51,12 +51,11 @@ static const char cups_collate_false[] = "%cupsJobTicket: collate=false\n"; static const char cups_collate_true[] = "%cupsJobTicket: collate=true\n"; static const char cups_ap_d_inputslot[] = "%cupsJobTicket: AP_D_InputSlot=\n"; /* intentionally empty value */ -static const char psheader[] = /* title llx lly urx ury orientation */ +static const char psheader[] = /* title llx lly urx ury */ "%%%%Creator: Wine PostScript Driver\n" "%%%%Title: %s\n" "%%%%BoundingBox: %d %d %d %d\n" "%%%%Pages: (atend)\n" -"%%%%Orientation: %s\n" "%%%%EndComments\n"; static const char psbeginprolog[] = @@ -94,8 +93,9 @@ static const char psendfeature[] = "\n%%EndFeature\n" "} stopped cleartomark\n"; -static const char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */ +static const char psnewpage[] = /* name, number, orientation, xres, yres, xtrans, ytrans, rot */ "%%%%Page: %s %d\n" +"%%%%PageOrientation: %s\n" "%%%%BeginPageSetup\n" "/pgsave save def\n" "72 %d div 72 %d div scale\n" @@ -402,7 +402,6 @@ INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) DUPLEX *duplex = find_duplex( ctx->pi->ppd, &ctx->Devmode->dmPublic ); int llx, lly, urx, ury; int ret, len; - const char * dmOrientation; struct ticket_info ticket_info = { page, duplex }; @@ -459,8 +458,7 @@ INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) } /* FIXME should do something better with BBox */ - dmOrientation = (ctx->Devmode->dmPublic.dmOrientation == DMORIENT_LANDSCAPE ? "Landscape" : "Portrait"); - sprintf(buf, psheader, escaped_title, llx, lly, urx, ury, dmOrientation); + sprintf(buf, psheader, escaped_title, llx, lly, urx, ury); HeapFree(GetProcessHeap(), 0, escaped_title); @@ -551,8 +549,9 @@ INT PSDRV_WriteNewPage( print_ctx *ctx ) } sprintf(buf, psnewpage, name, ctx->job.PageNo, - GetDeviceCaps(ctx->hdc, ASPECTX), GetDeviceCaps(ctx->hdc, ASPECTY), - xtrans, ytrans, rotation); + ctx->Devmode->dmPublic.dmOrientation == DMORIENT_LANDSCAPE ? "Landscape" : "Portrait", + GetDeviceCaps(ctx->hdc, ASPECTX), GetDeviceCaps(ctx->hdc, ASPECTY), + xtrans, ytrans, rotation); if( write_spool( ctx, buf, strlen(buf) ) != strlen(buf) ) { WARN("WriteSpool error\n"); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/wineps.drv/ps.c | 89 +++++++++++++++++++++++------------------ dlls/wineps.drv/psdrv.h | 1 + 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/dlls/wineps.drv/ps.c b/dlls/wineps.drv/ps.c index e1be2261e15..b78813466a3 100644 --- a/dlls/wineps.drv/ps.c +++ b/dlls/wineps.drv/ps.c @@ -51,10 +51,10 @@ static const char cups_collate_false[] = "%cupsJobTicket: collate=false\n"; static const char cups_collate_true[] = "%cupsJobTicket: collate=true\n"; static const char cups_ap_d_inputslot[] = "%cupsJobTicket: AP_D_InputSlot=\n"; /* intentionally empty value */ -static const char psheader[] = /* title llx lly urx ury */ +static const char psheader[] = /* title */ "%%%%Creator: Wine PostScript Driver\n" "%%%%Title: %s\n" -"%%%%BoundingBox: %d %d %d %d\n" +"%%%%BoundingBox: (atend)\n" "%%%%Pages: (atend)\n" "%%%%EndComments\n"; @@ -108,8 +108,9 @@ static const char psendpage[] = "pgsave restore\n" "showpage\n"; -static const char psfooter[] = /* pages */ +static const char psfooter[] = /* llx, lly, urx, ury, pages */ "%%%%Trailer\n" +"%%%%BoundingBox: %ld %ld %ld %ld\n" "%%%%Pages: %d\n" "%%%%EOF\n"; @@ -400,7 +401,6 @@ INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) INPUTSLOT *slot = find_slot( ctx->pi->ppd, &ctx->Devmode->dmPublic ); PAGESIZE *page = find_pagesize( ctx->pi->ppd, &ctx->Devmode->dmPublic ); DUPLEX *duplex = find_duplex( ctx->pi->ppd, &ctx->Devmode->dmPublic ); - int llx, lly, urx, ury; int ret, len; struct ticket_info ticket_info = { page, duplex }; @@ -419,46 +419,14 @@ INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) escaped_title = escape_title(title); buf = HeapAlloc( GetProcessHeap(), 0, sizeof(psheader) + - strlen(escaped_title) + 30 ); + strlen(escaped_title) ); if(!buf) { WARN("HeapAlloc failed\n"); HeapFree(GetProcessHeap(), 0, escaped_title); return 0; } - /* BBox co-ords are in default user co-ord system so urx < ury even in - landscape mode */ - if ((ctx->Devmode->dmPublic.dmFields & DM_PAPERSIZE) && page) - { - if (page->ImageableArea) - { - llx = page->ImageableArea->llx; - lly = page->ImageableArea->lly; - urx = page->ImageableArea->urx; - ury = page->ImageableArea->ury; - } - else - { - llx = lly = 0; - urx = page->PaperDimension->x; - ury = page->PaperDimension->y; - } - } - else if ((ctx->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) && - (ctx->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) - { - /* Devmode sizes in 1/10 mm */ - llx = lly = 0; - urx = ctx->Devmode->dmPublic.dmPaperWidth * 72.0 / 254.0; - ury = ctx->Devmode->dmPublic.dmPaperLength * 72.0 / 254.0; - } - else - { - llx = lly = urx = ury = 0; - } - /* FIXME should do something better with BBox */ - - sprintf(buf, psheader, escaped_title, llx, lly, urx, ury); + sprintf(buf, psheader, escaped_title); HeapFree(GetProcessHeap(), 0, escaped_title); @@ -498,7 +466,8 @@ INT PSDRV_WriteFooter( print_ctx *ctx ) return 0; } - sprintf(buf, psfooter, ctx->job.PageNo); + sprintf(buf, psfooter, ctx->bbox.left, ctx->bbox.top, + ctx->bbox.right, ctx->bbox.bottom, ctx->job.PageNo); if( write_spool( ctx, buf, strlen(buf) ) != strlen(buf) ) { WARN("WriteSpool error\n"); @@ -520,15 +489,57 @@ INT PSDRV_WriteEndPage( print_ctx *ctx ) } +static void get_bounding_box( print_ctx *ctx, RECT *bbox) +{ + PAGESIZE *page; + + /* BBox co-ords are in default user co-ord system so urx < ury even in + landscape mode */ + if ((ctx->Devmode->dmPublic.dmFields & DM_PAPERSIZE) && + (page = find_pagesize( ctx->pi->ppd, &ctx->Devmode->dmPublic ))) + { + if (page->ImageableArea) + { + bbox->left = page->ImageableArea->llx; + bbox->top = page->ImageableArea->lly; + bbox->right = page->ImageableArea->urx; + bbox->bottom = page->ImageableArea->ury; + } + else + { + bbox->left = bbox->top = 0; + bbox->right = page->PaperDimension->x; + bbox->bottom = page->PaperDimension->y; + } + } + else if ((ctx->Devmode->dmPublic.dmFields & DM_PAPERLENGTH) && + (ctx->Devmode->dmPublic.dmFields & DM_PAPERWIDTH)) + { + /* Devmode sizes in 1/10 mm */ + bbox->left = bbox->top = 0; + bbox->right = ctx->Devmode->dmPublic.dmPaperWidth * 72.0 / 254.0; + bbox->bottom = ctx->Devmode->dmPublic.dmPaperLength * 72.0 / 254.0; + } + else + { + bbox->left = bbox->top = bbox->right = bbox->bottom = 0; + } + /* FIXME should do something better with BBox */ +} + INT PSDRV_WriteNewPage( print_ctx *ctx ) { signed int xtrans, ytrans, rotation; char buf[256], name[16]; + RECT bbox; sprintf(name, "%d", ctx->job.PageNo); + get_bounding_box( ctx, &bbox ); + UnionRect( &ctx->bbox, &bbox, &ctx->bbox ); + if(ctx->Devmode->dmPublic.dmOrientation == DMORIENT_LANDSCAPE) { if(ctx->pi->ppd->LandscapeOrientation == -90) { xtrans = GetDeviceCaps(ctx->hdc, PHYSICALHEIGHT) - diff --git a/dlls/wineps.drv/psdrv.h b/dlls/wineps.drv/psdrv.h index 31adc36adfc..d1ac2cc06cd 100644 --- a/dlls/wineps.drv/psdrv.h +++ b/dlls/wineps.drv/psdrv.h @@ -368,6 +368,7 @@ typedef struct PSDRV_DEVMODE *Devmode; PRINTERINFO *pi; int pathdepth; + RECT bbox; } print_ctx; extern print_ctx *create_print_ctx( HDC hdc, const WCHAR *device, -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/wineps.drv/ps.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dlls/wineps.drv/ps.c b/dlls/wineps.drv/ps.c index b78813466a3..9896ea46bc7 100644 --- a/dlls/wineps.drv/ps.c +++ b/dlls/wineps.drv/ps.c @@ -93,8 +93,10 @@ static const char psendfeature[] = "\n%%EndFeature\n" "} stopped cleartomark\n"; -static const char psnewpage[] = /* name, number, orientation, xres, yres, xtrans, ytrans, rot */ +static const char psnewpage[] = /* name, number, llx, lly, urx, ury, orientation, + xres, yres, xtrans, ytrans, rot */ "%%%%Page: %s %d\n" +"%%%%PageBoundingBox: %ld %ld %ld %ld\n" "%%%%PageOrientation: %s\n" "%%%%BeginPageSetup\n" "/pgsave save def\n" @@ -560,6 +562,7 @@ INT PSDRV_WriteNewPage( print_ctx *ctx ) } sprintf(buf, psnewpage, name, ctx->job.PageNo, + bbox.left, bbox.top, bbox.right, bbox.bottom, ctx->Devmode->dmPublic.dmOrientation == DMORIENT_LANDSCAPE ? "Landscape" : "Portrait", GetDeviceCaps(ctx->hdc, ASPECTX), GetDeviceCaps(ctx->hdc, ASPECTY), xtrans, ytrans, rotation); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
From: Piotr Caban <piotr(a)codeweavers.com> --- dlls/wineps.drv/printproc.c | 2 ++ dlls/wineps.drv/ps.c | 14 ++++++++++++-- dlls/wineps.drv/psdrv.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dlls/wineps.drv/printproc.c b/dlls/wineps.drv/printproc.c index db2979f0fbe..84f4b9f5900 100644 --- a/dlls/wineps.drv/printproc.c +++ b/dlls/wineps.drv/printproc.c @@ -3110,6 +3110,8 @@ BOOL WINAPI PrintDocumentOnPrintProcessor(HANDLE pp, WCHAR *doc_name) if (ret) ret = PSDRV_ResetDC(data->ctx, devmode); + if (ret && devmode && (devmode->dmFields & DM_PAPERSIZE)) + ret = PSDRV_WritePageSize(data->ctx); free(devmode); if (!ret) goto cleanup; diff --git a/dlls/wineps.drv/ps.c b/dlls/wineps.drv/ps.c index 9896ea46bc7..8e52a97867a 100644 --- a/dlls/wineps.drv/ps.c +++ b/dlls/wineps.drv/ps.c @@ -397,6 +397,17 @@ static void write_cups_job_ticket( print_ctx *ctx, const struct ticket_info *inf write_spool( ctx, cups_ap_d_inputslot, sizeof(cups_ap_d_inputslot) - 1 ); } +INT PSDRV_WritePageSize( print_ctx *ctx ) +{ + PAGESIZE *page = find_pagesize( ctx->pi->ppd, &ctx->Devmode->dmPublic ); + + if (page && page->InvocationString) + PSDRV_WriteFeature( ctx, "*PageSize", page->Name, page->InvocationString ); + else + WARN("Page size not set\n"); + return 1; +} + INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) { char *buf, *escaped_title; @@ -444,8 +455,7 @@ INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ) if (slot && slot->InvocationString) PSDRV_WriteFeature( ctx, "*InputSlot", slot->Name, slot->InvocationString ); - if (page && page->InvocationString) - PSDRV_WriteFeature( ctx, "*PageSize", page->Name, page->InvocationString ); + PSDRV_WritePageSize( ctx ); if (duplex && duplex->InvocationString) PSDRV_WriteFeature( ctx, "*Duplex", duplex->Name, duplex->InvocationString ); diff --git a/dlls/wineps.drv/psdrv.h b/dlls/wineps.drv/psdrv.h index d1ac2cc06cd..2c4703de942 100644 --- a/dlls/wineps.drv/psdrv.h +++ b/dlls/wineps.drv/psdrv.h @@ -466,6 +466,7 @@ extern char PSDRV_UnicodeToANSI(int u); extern INT PSDRV_WriteHeader( print_ctx *ctx, LPCWSTR title ); extern INT PSDRV_WriteFooter( print_ctx *ctx ); +extern INT PSDRV_WritePageSize( print_ctx *ctx ); extern INT PSDRV_WriteNewPage( print_ctx *ctx ); extern INT PSDRV_WriteEndPage( print_ctx *ctx ); extern BOOL PSDRV_WriteMoveTo(print_ctx *ctx, INT x, INT y); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
Looks good. I've updated the comments next to the format strings to reflect the change in arguments (I'm not sure they're that helpful, but since they're there...) -- https://gitlab.winehq.org/wine/wine/-/merge_requests/5791#note_72429
This merge request was approved by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/5791
participants (3)
-
Huw Davies (@huw) -
Piotr Caban -
Piotr Caban (@piotr)