From 05e6b4c389b2a89d41c5a90754edba27581259c5 Mon Sep 17 00:00:00 2001 From: Christopher Mason Date: Sun, 1 Feb 2015 20:13:14 +0000 Subject: [PATCH] Fix Windows printer output to be centered regardless of the margin offsets imposed by a printer driver. Switch emulated Imagewriter to using page units equivalent to Postscript points (1/72th of an inch) vs 1/10th of an inch. This is to aid in adding additional paper size support in the future. --- src/imagewriter.cpp | 8 +++++--- src/scc_imagewriter.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/imagewriter.cpp b/src/imagewriter.cpp index 9193501..18290b4 100644 --- a/src/imagewriter.cpp +++ b/src/imagewriter.cpp @@ -116,8 +116,8 @@ Imagewriter::Imagewriter(Bit16u dpi, Bit16u width, Bit16u height, char* output, this->multipageOutput = multipageOutput; this->port = port; - defaultPageWidth = (Real64)width/(Real64)10; - defaultPageHeight = (Real64)height/(Real64)10; + defaultPageWidth = (Real64)width/(Real64)72; + defaultPageHeight = (Real64)height/(Real64)72; // Create page page = SDL_CreateRGBSurface( @@ -1628,6 +1628,8 @@ SDL_FreeSurface(image);*/ Bit16u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH); Bit16u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT); + Bit16u offsetW = GetDeviceCaps(printerDC, PHYSICALOFFSETX); + Bit16u offsetH = GetDeviceCaps(printerDC, PHYSICALOFFSETY); Real64 scaleW, scaleH; @@ -1695,7 +1697,7 @@ SDL_FreeSurface(image);*/ memcpy (Pixels, page->pixels, BitmapInfo->bmiHeader.biSizeImage); Prev = SelectObject (memHDC, bitmap); - StretchBlt(printerDC, 0, 0, physW, physH, memHDC, 0, 0, page->w, page->h, SRCCOPY); + StretchBlt(printerDC, -offsetW, -offsetH, physW, physH, memHDC, 0, 0, page->w, page->h, SRCCOPY); SelectObject (memHDC,Prev); DeleteObject (bitmap); } diff --git a/src/scc_imagewriter.c b/src/scc_imagewriter.c index add3834..3f040bc 100644 --- a/src/scc_imagewriter.c +++ b/src/scc_imagewriter.c @@ -40,7 +40,7 @@ int scc_imagewriter_init(int port) { Scc *scc_ptr; scc_ptr = &(scc_stat[port]); - imagewriter_init(g_imagewriter_dpi,85,110,g_imagewriter_output,g_imagewriter_multipage != 0, port); + imagewriter_init(g_imagewriter_dpi,612,792,g_imagewriter_output,g_imagewriter_multipage != 0, port); scc_ptr->state = 4; return 4; }