notepad: Make notepad print something reasonable.

This commit is contained in:
Duane Clark 2006-07-16 16:20:30 -07:00 committed by Alexandre Julliard
parent 22cf1c9e4d
commit a60ee9c43f

View file

@ -30,6 +30,9 @@
#include "main.h" #include "main.h"
#include "dialog.h" #include "dialog.h"
#define SPACES_IN_TAB 8
#define PRINT_LEN_MAX 120
static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 }; static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
@ -375,10 +378,12 @@ VOID DIALOG_FilePrint(VOID)
HFONT font, old_font=0; HFONT font, old_font=0;
DWORD size; DWORD size;
LPWSTR pTemp; LPWSTR pTemp;
static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 }; WCHAR cTemp[PRINT_LEN_MAX];
static const WCHAR print_fontW[] = { 'C','o','u','r','i','e','r',0 };
static const WCHAR letterM[] = { 'M',0 };
/* Get a small font and print some header info on each page */ /* Get a small font and print some header info on each page */
hdrFont.lfHeight = 100; hdrFont.lfHeight = -35;
hdrFont.lfWidth = 0; hdrFont.lfWidth = 0;
hdrFont.lfEscapement = 0; hdrFont.lfEscapement = 0;
hdrFont.lfOrientation = 0; hdrFont.lfOrientation = 0;
@ -391,7 +396,7 @@ VOID DIALOG_FilePrint(VOID)
hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
hdrFont.lfQuality = PROOF_QUALITY; hdrFont.lfQuality = PROOF_QUALITY;
hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN; hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
lstrcpy(hdrFont.lfFaceName, times_new_romanW); lstrcpy(hdrFont.lfFaceName, print_fontW);
font = CreateFontIndirect(&hdrFont); font = CreateFontIndirect(&hdrFont);
@ -404,13 +409,12 @@ VOID DIALOG_FilePrint(VOID)
printer.hInstance = Globals.hInstance; printer.hInstance = Globals.hInstance;
/* Set some default flags */ /* Set some default flags */
printer.Flags = PD_RETURNDC; printer.Flags = PD_RETURNDC | PD_NOSELECTION;
printer.nFromPage = 0; printer.nFromPage = 0;
printer.nMinPage = 1; printer.nMinPage = 1;
/* we really need to calculate number of pages to set nMaxPage and nToPage */ /* we really need to calculate number of pages to set nMaxPage and nToPage */
printer.nToPage = 0; printer.nToPage = 0;
printer.nMaxPage = -1; printer.nMaxPage = -1;
/* Let commdlg manage copy settings */ /* Let commdlg manage copy settings */
printer.nCopies = (WORD)PD_USEDEVMODECOPIES; printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
@ -445,21 +449,25 @@ VOID DIALOG_FilePrint(VOID)
size = GetWindowText(Globals.hEdit, pTemp, size); size = GetWindowText(Globals.hEdit, pTemp, size);
border = 150; border = 150;
old_font = SelectObject(printer.hDC, Globals.hFont);
GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
for (copycount=1; copycount <= printer.nCopies; copycount++) { for (copycount=1; copycount <= printer.nCopies; copycount++) {
i = 0; i = 0;
pagecount = 1; pagecount = 1;
do { do {
static const WCHAR letterM[] = { 'M',0 }; if (printer.Flags & PD_PAGENUMS) {
/* a specific range of pages is selected, so
if (pagecount >= printer.nFromPage && * skip pages that are not to be printed
/* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/ */
pagecount <= printer.nToPage) if (pagecount > printer.nToPage)
dopage = 1; break;
else if (pagecount >= printer.nFromPage)
dopage = 1;
else
dopage = 0;
}
else else
dopage = 0; dopage = 1;
old_font = SelectObject(printer.hDC, font);
GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
if (dopage) { if (dopage) {
if (StartPage(printer.hDC) <= 0) { if (StartPage(printer.hDC) <= 0) {
@ -469,40 +477,47 @@ VOID DIALOG_FilePrint(VOID)
return; return;
} }
/* Write a rectangle and header at the top of each page */ /* Write a rectangle and header at the top of each page */
SelectObject(printer.hDC, font);
Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2); Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
/* I don't know what's up with this TextOut command. This comes out
kind of mangled.
*/
TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle)); TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
} }
SelectObject(printer.hDC, Globals.hFont);
/* The starting point for the main text */ /* The starting point for the main text */
xLeft = border*2; xLeft = border;
yTop = border+szMetric.cy*4; yTop = border+szMetric.cy*4;
SelectObject(printer.hDC, old_font);
GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
/* Since outputting strings is giving me problems, output the main
text one character at a time.
*/
do { do {
if (pTemp[i] == '\n') { int k=0, m;
xLeft = border*2; /* find the end of the line */
yTop += szMetric.cy; while (i < size && pTemp[i] != '\n' && pTemp[i] != '\r') {
if (pTemp[i] == '\t') {
/* replace tabs with spaces */
for (m=0; m<SPACES_IN_TAB; m++) {
if (k < PRINT_LEN_MAX)
cTemp[k++] = ' ';
}
}
else if (k < PRINT_LEN_MAX)
cTemp[k++] = pTemp[i];
i++;
} }
else if (pTemp[i] != '\r') { if (dopage)
if (dopage) TextOut(printer.hDC, xLeft, yTop, cTemp, k);
TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1); /* find the next line */
xLeft += szMetric.cx; while (i < size && (pTemp[i] == '\n' || pTemp[i] == '\r')) {
if (pTemp[i] == '\n')
yTop += szMetric.cy;
i++;
} }
} while (i++<size && yTop<(cHeightPels-border*2)); } while (i<size && yTop<(cHeightPels-border*2));
if (dopage) if (dopage)
EndPage(printer.hDC); EndPage(printer.hDC);
pagecount++; pagecount++;
} while (i<size); } while (i<size);
} }
SelectObject(printer.hDC, old_font);
EndDoc(printer.hDC); EndDoc(printer.hDC);
DeleteDC(printer.hDC); DeleteDC(printer.hDC);