Fix pagination in stc sample

1. Fix setting page size if printing is done in the landscape mode.
2. Store ranges of printed characters for all pages (not only recent page)
while doing pagination (in GetPageInfo) to allow printing pages (with
OnPrintPage) in any order (not only sequentially).

Closes #17107.
This commit is contained in:
Artur Wieczorek
2017-05-25 23:30:52 +02:00
parent 8f8534361c
commit 528c559953
2 changed files with 24 additions and 18 deletions

View File

@@ -837,10 +837,9 @@ EditProperties::EditProperties (Edit *edit,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
EditPrint::EditPrint (Edit *edit, const wxChar *title) EditPrint::EditPrint (Edit *edit, const wxChar *title)
: wxPrintout(title) { : wxPrintout(title)
m_edit = edit; , m_edit(edit)
m_printed = 0; {
} }
bool EditPrint::OnPrintPage (int page) { bool EditPrint::OnPrintPage (int page) {
@@ -852,10 +851,8 @@ bool EditPrint::OnPrintPage (int page) {
PrintScaling (dc); PrintScaling (dc);
// print page // print page
if (page == 1) m_printed = 0; m_edit->FormatRange(true, page == 1 ? 0 : m_pageEnds[page-2], m_pageEnds[page-1],
m_printed = m_edit->FormatRange (1, m_printed, m_edit->GetLength(),
dc, dc, m_printRect, m_pageRect); dc, dc, m_printRect, m_pageRect);
return true; return true;
} }
@@ -887,6 +884,12 @@ void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *
wxSize page = g_pageSetupData->GetPaperSize(); wxSize page = g_pageSetupData->GetPaperSize();
page.x = static_cast<int> (page.x * ppiScr.x / 25.4); page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
page.y = static_cast<int> (page.y * ppiScr.y / 25.4); page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
// In landscape mode we need to swap the width and height
if ( g_pageSetupData->GetPrintData().GetOrientation() == wxLANDSCAPE )
{
wxSwap(page.x, page.y);
}
m_pageRect = wxRect (0, m_pageRect = wxRect (0,
0, 0,
page.x, page.x,
@@ -911,9 +914,12 @@ void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *
page.y - (top + bottom)); page.y - (top + bottom));
// count pages // count pages
while (HasPage (*maxPage)) { m_pageEnds.Clear();
m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(), int printed = 0;
while ( printed < m_edit->GetLength() ) {
printed = m_edit->FormatRange(false, printed, m_edit->GetLength(),
dc, dc, m_printRect, m_pageRect); dc, dc, m_printRect, m_pageRect);
m_pageEnds.Add(printed);
*maxPage += 1; *maxPage += 1;
} }
if (*maxPage > 0) *minPage = 1; if (*maxPage > 0) *minPage = 1;
@@ -921,9 +927,9 @@ void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *
*selPageTo = *maxPage; *selPageTo = *maxPage;
} }
bool EditPrint::HasPage (int WXUNUSED(page)) { bool EditPrint::HasPage (int page)
{
return (m_printed < m_edit->GetLength()); return page <= (int)m_pageEnds.Count();
} }
bool EditPrint::PrintScaling (wxDC *dc){ bool EditPrint::PrintScaling (wxDC *dc){

View File

@@ -165,16 +165,16 @@ public:
EditPrint (Edit *edit, const wxChar *title = wxT("")); EditPrint (Edit *edit, const wxChar *title = wxT(""));
//! event handlers //! event handlers
bool OnPrintPage (int page); bool OnPrintPage (int page) wxOVERRIDE;
bool OnBeginDocument (int startPage, int endPage); bool OnBeginDocument (int startPage, int endPage) wxOVERRIDE;
//! print functions //! print functions
bool HasPage (int page); bool HasPage (int page) wxOVERRIDE;
void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo); void GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) wxOVERRIDE;
private: private:
Edit *m_edit; Edit *m_edit;
int m_printed; wxArrayInt m_pageEnds;
wxRect m_pageRect; wxRect m_pageRect;
wxRect m_printRect; wxRect m_printRect;