Index: base/applications/notepad/dialog.c =================================================================== --- base/applications/notepad/dialog.c (revision 69221) +++ base/applications/notepad/dialog.c (working copy) @@ -225,6 +225,31 @@ } } +RECT GetPrintingRect(HDC hdc, RECT margins) +{ + int iLogPixelsX, iLogPixelsY; + int iHorzRes, iVertRes; + int iPhysPageX, iPhysPageY, iPhysPageW, iPhysPageH; + RECT rcPrintRect; + + + iPhysPageX = GetDeviceCaps(hdc, PHYSICALOFFSETX); + iPhysPageY = GetDeviceCaps(hdc, PHYSICALOFFSETY); + iPhysPageW = GetDeviceCaps(hdc, PHYSICALWIDTH); + iPhysPageH = GetDeviceCaps(hdc, PHYSICALHEIGHT); + iLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX); + iLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY); + iHorzRes = GetDeviceCaps(hdc, HORZRES); + iVertRes = GetDeviceCaps(hdc, VERTRES); + + rcPrintRect.left = (margins.left * iLogPixelsX / 2540) - iPhysPageX; + rcPrintRect.top = (margins.top * iLogPixelsY / 2540) - iPhysPageY; + rcPrintRect.right = iHorzRes - (((margins.left * iLogPixelsX / 2540) - iPhysPageX) + ((margins.right * iLogPixelsX / 2540) - (iPhysPageW - iPhysPageX - iHorzRes))); + rcPrintRect.bottom = iVertRes - (((margins.top * iLogPixelsY / 2540) - iPhysPageY) + ((margins.bottom * iLogPixelsY / 2540) - (iPhysPageH - iPhysPageY - iVertRes))); + + return rcPrintRect; +} + static BOOL DoSaveFile(VOID) { BOOL bRet = TRUE; @@ -518,7 +543,7 @@ TEXTMETRIC tm; PRINTDLG printer; SIZE szMetric; - int cWidthPels, cHeightPels, border; + int border; int xLeft, yTop, pagecount, dopage, copycount; unsigned int i; LOGFONT hdrFont; @@ -526,7 +551,9 @@ DWORD size; LPTSTR pTemp; static const TCHAR times_new_roman[] = _T("Times New Roman"); + RECT rcPrintRect; + /* Get a small font and print some header info on each page */ ZeroMemory(&hdrFont, sizeof(hdrFont)); hdrFont.lfHeight = 100; @@ -591,9 +618,6 @@ return; } - /* Get the page dimensions in pixels. */ - cWidthPels = GetDeviceCaps(printer.hDC, HORZRES); - cHeightPels = GetDeviceCaps(printer.hDC, VERTRES); /* Get the file text */ if (printer.Flags & PD_SELECTION) @@ -623,6 +647,9 @@ size = GetWindowText(Globals.hEdit, pTemp, size); } + /* Get the current printing area */ + rcPrintRect = GetPrintingRect(printer.hDC, Globals.lMargins); + /* Ensure that each logical unit maps to one pixel */ SetMapMode(printer.hDC, MM_TEXT); @@ -629,7 +656,7 @@ /* Needed to get the correct height of a text line */ GetTextMetrics(printer.hDC, &tm); - border = 150; + border = 15; for (copycount=1; copycount <= printer.nCopies; copycount++) { i = 0; pagecount = 1; @@ -667,8 +694,11 @@ AlertPrintError(); return; } + + SetViewportOrgEx(printer.hDC, rcPrintRect.left, rcPrintRect.top, NULL); + /* Write a rectangle and header at the top of each page */ - Rectangle(printer.hDC, border, border, cWidthPels-border, border + tm.tmHeight * 2); + Rectangle(printer.hDC, border, border, rcPrintRect.right - border, border + tm.tmHeight * 2); /* I don't know what's up with this TextOut command. This comes out kind of mangled. */ @@ -680,7 +710,7 @@ } /* The starting point for the main text */ - xLeft = border * 2; + xLeft = 0; yTop = border + tm.tmHeight * 4; SelectObject(printer.hDC, old_font); @@ -689,7 +719,7 @@ * text one character at a time. */ do { if (pTemp[i] == '\n') { - xLeft = border * 2; + xLeft = 0; yTop += tm.tmHeight; } else if (pTemp[i] != '\r') { @@ -701,13 +731,13 @@ xLeft += szMetric.cx; /* Insert a line break if the current line does not fit into the printing area */ - if (xLeft > (cWidthPels - border * 2)) + if (xLeft > rcPrintRect.right) { - xLeft = border * 2; + xLeft = 0; yTop = yTop + tm.tmHeight; } } - } while (i++ < size && yTop < (cHeightPels - border * 2)); + } while (i++ < size && yTop < rcPrintRect.bottom); if (dopage) EndPage(printer.hDC); @@ -1184,10 +1214,7 @@ page.hwndOwner = Globals.hMainWnd; page.Flags = PSD_ENABLEPAGESETUPTEMPLATE | PSD_ENABLEPAGESETUPHOOK | PSD_MARGINS; page.hInstance = Globals.hInstance; - page.rtMargin.left = Globals.lMarginLeft; - page.rtMargin.top = Globals.lMarginTop; - page.rtMargin.right = Globals.lMarginRight; - page.rtMargin.bottom = Globals.lMarginBottom; + page.rtMargin = Globals.lMargins; page.hDevMode = Globals.hDevMode; page.hDevNames = Globals.hDevNames; page.lpPageSetupTemplateName = MAKEINTRESOURCE(DIALOG_PAGESETUP); @@ -1197,10 +1224,7 @@ Globals.hDevMode = page.hDevMode; Globals.hDevNames = page.hDevNames; - Globals.lMarginLeft = page.rtMargin.left; - Globals.lMarginTop = page.rtMargin.top; - Globals.lMarginRight = page.rtMargin.right; - Globals.lMarginBottom = page.rtMargin.bottom; + Globals.lMargins = page.rtMargin; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Index: base/applications/notepad/main.h =================================================================== --- base/applications/notepad/main.h (revision 69221) +++ base/applications/notepad/main.h (working copy) @@ -73,10 +73,7 @@ TCHAR szFileName[MAX_PATH]; TCHAR szFileTitle[MAX_PATH]; TCHAR szFilter[2 * MAX_STRING_LEN + 100]; - LONG lMarginTop; - LONG lMarginBottom; - LONG lMarginLeft; - LONG lMarginRight; + RECT lMargins; TCHAR szHeader[MAX_PATH]; TCHAR szFooter[MAX_PATH]; TCHAR szStatusBarLineCol[MAX_PATH]; Index: base/applications/notepad/settings.c =================================================================== --- base/applications/notepad/settings.c (revision 69221) +++ base/applications/notepad/settings.c (working copy) @@ -144,10 +144,10 @@ QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar); QueryString(hKey, _T("szHeader"), Globals.szHeader, ARRAY_SIZE(Globals.szHeader)); QueryString(hKey, _T("szTrailer"), Globals.szFooter, ARRAY_SIZE(Globals.szFooter)); - QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMarginLeft); - QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMarginTop); - QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMarginRight); - QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMarginBottom); + QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left); + QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top); + QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right); + QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom); QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left); QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top); @@ -239,10 +239,10 @@ SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0); SaveString(hKey, _T("szHeader"), Globals.szHeader); SaveString(hKey, _T("szTrailer"), Globals.szFooter); - SaveDword(hKey, _T("iMarginLeft"), Globals.lMarginLeft); - SaveDword(hKey, _T("iMarginTop"), Globals.lMarginTop); - SaveDword(hKey, _T("iMarginRight"), Globals.lMarginRight); - SaveDword(hKey, _T("iMarginBottom"), Globals.lMarginBottom); + SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left); + SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top); + SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right); + SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom); SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left); SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top); SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);