Fix page margins in Windows once and for all. Clip the source bitmap by the equivalent amount given by the printer driver. Also set the default left margin of the emulated Imagewriter to 1/4 inch.

This commit is contained in:
Christopher Mason 2015-02-04 05:39:25 +00:00
parent 766a0744d8
commit a823643faa

View File

@ -246,7 +246,7 @@ void Imagewriter::resetPrinter()
ESCCmd = 0; ESCCmd = 0;
numParam = neededParam = 0; numParam = neededParam = 0;
topMargin = 0.0; topMargin = 0.0;
leftMargin = 0.0; leftMargin = 0.25; //Most all Apple II software including GS/OS assume a 1/4 inch margin on an Imagewriter
rightMargin = pageWidth = defaultPageWidth; rightMargin = pageWidth = defaultPageWidth;
bottomMargin = pageHeight = defaultPageHeight; bottomMargin = pageHeight = defaultPageHeight;
lineSpacing = (Real64)1/6; lineSpacing = (Real64)1/6;
@ -1628,21 +1628,16 @@ SDL_FreeSurface(image);*/
Bit16u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH); Bit16u physW = GetDeviceCaps(printerDC, PHYSICALWIDTH);
Bit16u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT); Bit16u physH = GetDeviceCaps(printerDC, PHYSICALHEIGHT);
Bit16u offsetW = GetDeviceCaps(printerDC, PHYSICALOFFSETX); Bit16u printeroffsetW = GetDeviceCaps(printerDC, PHYSICALOFFSETX); //printer x offset in actual pixels
Bit16u offsetH = GetDeviceCaps(printerDC, PHYSICALOFFSETY); Bit16u printeroffsetH = GetDeviceCaps(printerDC, PHYSICALOFFSETY); //printer y offset in actual pixels
Bit16u deviceDPIW = GetDeviceCaps(printerDC, LOGPIXELSX);
Real64 scaleW, scaleH; Bit16u deviceDPIH = GetDeviceCaps(printerDC, LOGPIXELSY);
Real64 physoffsetW = (Real64)printeroffsetW/deviceDPIW; //printer x offset in inches
if (page->w > physW) Real64 physoffsetH = (Real64)printeroffsetH/deviceDPIH; //printer y offset in inches
scaleW = (Real64)page->w / (Real64)physW; Bit16u dpiW = page->w/defaultPageWidth; //Get currently set DPI of the emulated printer in an indirect way
else Bit16u dpiH = page->h/defaultPageHeight;
scaleW = (Real64)physW / (Real64)page->w; Real64 soffsetW = physoffsetW*dpiW; //virtual page x offset in actual pixels
Real64 soffsetH = physoffsetH*dpiH; //virtual page y offset in actual pixels
if (page->h > physH)
scaleH = (Real64)page->h / (Real64)physH;
else
scaleH = (Real64)physH / (Real64)page->h;
HDC memHDC = CreateCompatibleDC(printerDC); HDC memHDC = CreateCompatibleDC(printerDC);
BITMAPINFO *BitmapInfo; BITMAPINFO *BitmapInfo;
HBITMAP bitmap; HBITMAP bitmap;
@ -1697,7 +1692,7 @@ SDL_FreeSurface(image);*/
memcpy (Pixels, page->pixels, memcpy (Pixels, page->pixels,
BitmapInfo->bmiHeader.biSizeImage); BitmapInfo->bmiHeader.biSizeImage);
Prev = SelectObject (memHDC, bitmap); Prev = SelectObject (memHDC, bitmap);
StretchBlt(printerDC, -offsetW, -offsetH, physW, physH, memHDC, 0, 0, page->w, page->h, SRCCOPY); StretchBlt(printerDC, 0, 0, physW, physH, memHDC, soffsetW, soffsetH, page->w, page->h, SRCCOPY);
SelectObject (memHDC,Prev); SelectObject (memHDC,Prev);
DeleteObject (bitmap); DeleteObject (bitmap);
} }