From c58d81d32d7faa6dd53a124f27675b3d50b5567b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 24 May 2018 17:46:14 +0200 Subject: [PATCH] Simplify wxHtmlPageBreakCell::AdjustPagebreak() There is no need to look in the known page breaks array for a page break at the position of this cell, all we care about is whether this cell is on the current page or not: we must insert a page break if, and only if, it is. No real changes in behaviour, but the code is now much simpler to understand and this change paves way for removing "known_pagebreaks" entirely, as it was only added for the use in this function (see f2034f1b6e04a39f6d882cf6cdd53c11bf39f5d7 from 15 years ago), which doesn't even actually need it. It should also make pagination code somewhat faster. --- src/html/m_layout.cpp | 44 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/html/m_layout.cpp b/src/html/m_layout.cpp index 619ec2bb08..4dba82e6d1 100644 --- a/src/html/m_layout.cpp +++ b/src/html/m_layout.cpp @@ -80,47 +80,19 @@ private: bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, - const wxArrayInt& known_pagebreaks, - int WXUNUSED(pageHeight)) const + const wxArrayInt& WXUNUSED(known_pagebreaks), + int pageHeight) const { - // When we are counting pages, 'known_pagebreaks' is non-NULL. - // That's the only time we change 'pagebreak'. Otherwise, pages - // were already counted, 'known_pagebreaks' is NULL, and we don't - // do anything except return false. - // - // We also simply return false if the 'pagebreak' argument is - // less than (vertically above) or the same as the current - // vertical position. Otherwise we'd be setting a pagebreak above - // the current cell, which is incorrect, or duplicating a - // pagebreak that has already been set. - if( known_pagebreaks.GetCount() == 0 || *pagebreak <= m_PosY) - { - return false; - } - - // m_PosY is only the vertical offset from the parent. The pagebreak - // required here is the total page offset, so m_PosY must be added - // to the parent's offset and height. - int total_height = m_PosY; - for ( wxHtmlCell *parent = GetParent(); parent; parent = parent->GetParent() ) - { - total_height += parent->GetPosY(); - } - - - // Search the array of pagebreaks to see whether we've already set - // a pagebreak here. - int where = known_pagebreaks.Index( total_height); - // Add a pagebreak only if there isn't one already set here. - if( wxNOT_FOUND != where) - { - return false; - } - else + // Request a page break at the position of this cell if it's on the current + // page. Note that it's important not to do it unconditionally or we could + // end up in an infinite number of page breaks at this cell position. + if ( m_PosY < *pagebreak && m_PosY > *pagebreak - pageHeight ) { *pagebreak = m_PosY; return true; } + + return false; }