📄 printer.cpp.svn-base
字号:
::GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, longDate, sizeof(longDate));
::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, sizeof(time));
if (nppGUI._printSettings.isHeaderPresent())
{
frPrint.rc.top += headerLineHeight + headerLineHeight / 2;
string headerLeftPart = nppGUI._printSettings._headerLeft;
if (headerLeftPart != "")
{
replaceStr(headerLeftPart, shortDateVar, shortDate);
replaceStr(headerLeftPart, longDateVar, longDate);
replaceStr(headerLeftPart, timeVar, time);
expandNppEnvironmentStrs(headerLeftPart.c_str(), headerL, sizeof(headerL), _pdlg.hwndOwner);
}
string headerMiddlePart = nppGUI._printSettings._headerMiddle;
if (headerMiddlePart != "")
{
replaceStr(headerMiddlePart, shortDateVar, shortDate);
replaceStr(headerMiddlePart, longDateVar, longDate);
replaceStr(headerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(headerMiddlePart.c_str(), headerM, sizeof(headerM), _pdlg.hwndOwner);
}
string headerRightPart = nppGUI._printSettings._headerRight;
if (headerRightPart != "")
{
replaceStr(headerRightPart, shortDateVar, shortDate);
replaceStr(headerRightPart, longDateVar, longDate);
replaceStr(headerRightPart, timeVar, time);
expandNppEnvironmentStrs(headerRightPart.c_str(), headerR, sizeof(headerR), _pdlg.hwndOwner);
}
}
if (nppGUI._printSettings.isFooterPresent())
{
frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;
string footerLeftPart = nppGUI._printSettings._footerLeft;
if (footerLeftPart != "")
{
replaceStr(footerLeftPart, shortDateVar, shortDate);
replaceStr(footerLeftPart, longDateVar, longDate);
replaceStr(footerLeftPart, timeVar, time);
expandNppEnvironmentStrs(footerLeftPart.c_str(), footerL, sizeof(footerL), _pdlg.hwndOwner);
}
string footerMiddlePart = nppGUI._printSettings._footerMiddle;
if (footerMiddlePart != "")
{
replaceStr(footerMiddlePart, shortDateVar, shortDate);
replaceStr(footerMiddlePart, longDateVar, longDate);
replaceStr(footerMiddlePart, timeVar, time);
expandNppEnvironmentStrs(footerMiddlePart.c_str(), footerM, sizeof(footerM), _pdlg.hwndOwner);
}
string footerRightPart = nppGUI._printSettings._footerRight;
if (footerRightPart != "")
{
replaceStr(footerRightPart, shortDateVar, shortDate);
replaceStr(footerRightPart, longDateVar, longDate);
replaceStr(footerRightPart, timeVar, time);
expandNppEnvironmentStrs(footerRightPart.c_str(), footerR, sizeof(footerR), _pdlg.hwndOwner);
}
}
bool isShown = _pSEView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER);
if (!nppGUI._printSettings._printLineNumber)
_pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, false);
size_t pageNum = 1;
bool printPage;
const char pageVar[] = "$(CURRENT_PRINTING_PAGE)";
while (lengthPrinted < lengthDoc)
{
printPage = (!(_pdlg.Flags & PD_PAGENUMS) ||
(pageNum >= _pdlg.nFromPage) && (pageNum <= _pdlg.nToPage));
if (!justDoIt)
printPage = false;
char pageString[32];
sprintf(pageString, "%0d", pageNum);
if (printPage)
{
::StartPage(_pdlg.hDC);
if (nppGUI._printSettings.isHeaderPresent())
{
::SelectObject(_pdlg.hDC, fontHeader);
::SetTextColor(_pdlg.hDC, RGB(0, 0, 0));
::SetBkColor(_pdlg.hDC, RGB(255, 255, 255));
UINT oldTASettings = ::SetTextAlign(_pdlg.hDC, TA_BOTTOM);
RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2,
frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2};
rcw.bottom = rcw.top + headerLineHeight;
SIZE size;
// Left part
if (headerL[0] != '\0')
{
string headerLeft(headerL);
size_t pos = headerLeft.find(pageVar);
if (pos != headerLeft.npos)
headerLeft.replace(pos, strlen(pageVar), pageString);
::ExtTextOut(_pdlg.hDC, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2,
ETO_OPAQUE, &rcw, headerLeft.c_str(), static_cast<int>(headerLeft.length()), NULL);
}
// Middle part
if (headerM != '\0')
{
string headerMiddle(headerM);
size_t pos = headerMiddle.find(pageVar);
if (pos != headerMiddle.npos)
headerMiddle.replace(pos, strlen(pageVar), pageString);
::GetTextExtentPoint32(_pdlg.hDC, headerMiddle.c_str(), static_cast<int>(headerMiddle.length()), &size);
::ExtTextOut(_pdlg.hDC, ((frPrint.rc.right - frPrint.rc.left)/2 + frPrint.rc.left) - (size.cx/2), frPrint.rc.top - headerLineHeight / 2,
ETO_CLIPPED, &rcw, headerMiddle.c_str(), static_cast<int>(headerMiddle.length()), NULL);
}
// Right part
if (headerR != '\0')
{
string headerRight(headerR);
size_t pos = headerRight.find(pageVar);
if (pos != headerRight.npos)
headerRight.replace(pos, strlen(pageVar), pageString);
::GetTextExtentPoint32(_pdlg.hDC, headerRight.c_str(), static_cast<int>(headerRight.length()), &size);
::ExtTextOut(_pdlg.hDC, frPrint.rc.right - size.cx, frPrint.rc.top - headerLineHeight / 2,
ETO_CLIPPED, &rcw, headerRight.c_str(), static_cast<int>(headerRight.length()), NULL);
}
::SetTextAlign(_pdlg.hDC, oldTASettings);
HPEN pen = ::CreatePen(0, 1, 0x00000000);
HPEN penOld = static_cast<HPEN>(::SelectObject(_pdlg.hDC, pen));
::MoveToEx(_pdlg.hDC, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, NULL);
::LineTo(_pdlg.hDC, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4);
::SelectObject(_pdlg.hDC, penOld);
::DeleteObject(pen);
}
}
frPrint.chrg.cpMin = lengthPrinted;
frPrint.chrg.cpMax = lengthDoc;
_pSEView->execute(SCI_SETPRINTCOLOURMODE, nppGUI._printSettings._printOption);
lengthPrinted = long(_pSEView->execute(SCI_FORMATRANGE, printPage, reinterpret_cast<LPARAM>(&frPrint)));
if (printPage)
{
if (nppGUI._printSettings.isFooterPresent())
{
::SelectObject(_pdlg.hDC, fontFooter);
::SetTextColor(_pdlg.hDC, RGB(0, 0, 0));
::SetBkColor(_pdlg.hDC, RGB(255, 255, 255));
UINT oldta = ::SetTextAlign(_pdlg.hDC, TA_TOP);
RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2,
frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2};
SIZE size;
// Left part
if (footerL[0] != '\0')
{
string footerLeft(footerL);
size_t pos = footerLeft.find(pageVar);
if (pos != footerLeft.npos)
footerLeft.replace(pos, strlen(pageVar), pageString);
::ExtTextOut(_pdlg.hDC, frPrint.rc.left + 5, frPrint.rc.bottom + footerLineHeight / 2,
ETO_OPAQUE, &rcw, footerLeft.c_str(), static_cast<int>(footerLeft.length()), NULL);
}
// Middle part
if (footerM[0] != '\0')
{
string footerMiddle(footerM);
size_t pos = footerMiddle.find(pageVar);
if (pos != footerMiddle.npos)
footerMiddle.replace(pos, strlen(pageVar), pageString);
::GetTextExtentPoint32(_pdlg.hDC, footerMiddle.c_str(), static_cast<int>(footerMiddle.length()), &size);
::ExtTextOut(_pdlg.hDC, ((frPrint.rc.right - frPrint.rc.left)/2 + frPrint.rc.left) - (size.cx/2), frPrint.rc.bottom + footerLineHeight / 2,
ETO_CLIPPED, &rcw, footerMiddle.c_str(), static_cast<int>(footerMiddle.length()), NULL);
}
// Right part
if (footerR[0] != '\0')
{
string footerRight(footerR);
size_t pos = footerRight.find(pageVar);
if (pos != footerRight.npos)
footerRight.replace(pos, strlen(pageVar), pageString);
::GetTextExtentPoint32(_pdlg.hDC, footerRight.c_str(), static_cast<int>(footerRight.length()), &size);
::ExtTextOut(_pdlg.hDC, frPrint.rc.right - size.cx, frPrint.rc.bottom + footerLineHeight / 2,
ETO_CLIPPED, &rcw, footerRight.c_str(), static_cast<int>(footerRight.length()), NULL);
}
::SetTextAlign(_pdlg.hDC, oldta);
HPEN pen = ::CreatePen(0, 1, 0x00000000);
HPEN penOld = static_cast<HPEN>(::SelectObject(_pdlg.hDC, pen));
::MoveToEx(_pdlg.hDC, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, NULL);
::LineTo(_pdlg.hDC, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4);
::SelectObject(_pdlg.hDC, penOld);
::DeleteObject(pen);
}
::EndPage(_pdlg.hDC);
}
pageNum++;
if ((_pdlg.Flags & PD_PAGENUMS) && (pageNum > _pdlg.nToPage))
break;
}
//char toto[10];
//::MessageBox(NULL, itoa(pageNum, toto, 10), "page total", MB_OK);
if (!nppGUI._printSettings._printLineNumber)
_pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, isShown);
_pSEView->execute(SCI_FORMATRANGE, FALSE, 0);
::EndDoc(_pdlg.hDC);
::DeleteDC(_pdlg.hDC);
if (fontHeader)
::DeleteObject(fontHeader);
if (fontFooter)
::DeleteObject(fontFooter);
return (pageNum - 1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -