Remove "known_pagebreaks" from wxHtmlCell::AdjustPagebreak()

This parameter is not actually needed for any reasonable page breaking
algorithm, as it shouldn't care about any previous page breaks except
for the last one, which is already known as "*pagebreak - pageHeight" in
this function.

Removing it will allow to stop using wxArrayInt in the code using this
method and switch to an std::vector<int> instead.

This is not a backwards compatible change, but it seems that there is
very little code actually overriding this function (none could be found
in any open source repositories) and updating it should be as simple as
removing the now unneeded argument.
This commit is contained in:
Vadim Zeitlin
2018-05-24 18:05:58 +02:00
parent c58d81d32d
commit b9b6ccb804
7 changed files with 44 additions and 45 deletions

View File

@@ -69,6 +69,9 @@ Changes in behaviour which may result in build errors
- wxHtmlDCRenderer::Render() arguments have changed, simply omit the ones not - wxHtmlDCRenderer::Render() arguments have changed, simply omit the ones not
existing in the function signature any more to update the code using it. existing in the function signature any more to update the code using it.
- wxHtmlCell::AdjustPagebreak() has lost its "known_pagebreaks" argument,
update your code if you override this method (you shouldn't be calling it).
3.1.2: (released 2018-??-??) 3.1.2: (released 2018-??-??)
---------------------------- ----------------------------

View File

@@ -279,16 +279,20 @@ public:
const wxPoint& pos, const wxPoint& pos,
const wxMouseEvent& event); const wxMouseEvent& event);
// This method used to adjust pagebreak position. The parameter is variable // This method is called when paginating HTML, e.g. when printing.
// that contains y-coordinate of page break (= horizontal line that should //
// not be crossed by words, images etc.). If this cell cannot be divided // On input, pagebreak contains y-coordinate of page break (i.e. the
// into two pieces (each one on another page) then it moves the pagebreak // horizontal line that should not be crossed by words, images etc.)
// few pixels up. // relative to the parent cell on entry and may be modified to request a
// page break at a position before it if this cell cannot be divided into
// two pieces (each one on its own page).
//
// Note that page break must still happen on the current page, i.e. the
// returned value must be strictly greater than "*pagebreak - pageHeight"
// and less or equal to "*pagebreak" for the value of pagebreak on input.
// //
// Returned value : true if pagebreak was modified, false otherwise // Returned value : true if pagebreak was modified, false otherwise
virtual bool AdjustPagebreak(int *pagebreak, virtual bool AdjustPagebreak(int *pagebreak, int pageHeight) const;
const wxArrayInt& known_pagebreaks,
int pageHeight) const;
// Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default // Sets cell's behaviour on pagebreaks (see AdjustPagebreak). Default
// is true - the cell can be split on two pages // is true - the cell can be split on two pages
@@ -450,9 +454,7 @@ public:
virtual void DrawInvisible(wxDC& dc, int x, int y, virtual void DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingInfo& info) wxOVERRIDE; wxHtmlRenderingInfo& info) wxOVERRIDE;
virtual bool AdjustPagebreak(int *pagebreak, virtual bool AdjustPagebreak(int *pagebreak, int pageHeight) const wxOVERRIDE;
const wxArrayInt& known_pagebreaks,
int pageHeight) const wxOVERRIDE;
// insert cell at the end of m_Cells list // insert cell at the end of m_Cells list
void InsertCell(wxHtmlCell *cell); void InsertCell(wxHtmlCell *cell);

View File

@@ -64,7 +64,7 @@ public:
// Finds the next page break after the specified (vertical) position. // Finds the next page break after the specified (vertical) position.
// Returns wxNOT_FOUND if passed in position is the last page break. // Returns wxNOT_FOUND if passed in position is the last page break.
int FindNextPageBreak(const wxArrayInt& known_pagebreaks, int pos); int FindNextPageBreak(int pos);
// [x,y] is position of upper-left corner of printing rectangle (see SetSize) // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
// from is y-coordinate of the very first visible cell // from is y-coordinate of the very first visible cell

View File

@@ -187,28 +187,31 @@ public:
wxHtmlCell(); wxHtmlCell();
/** /**
This method is used to adjust pagebreak position. This method is called when paginating HTML, e.g.\ when printing.
The first parameter is a variable that contains the y-coordinate of the page break
(= horizontal line that should not be crossed by words, images etc.).
If this cell cannot be divided into two pieces (each one on another page)
then it either moves the pagebreak a few pixels up, if possible, or, if
the cell cannot fit on the page at all, then the cell is forced to
split unconditionally.
Returns @true if pagebreak was modified, @false otherwise. User code should never call this function, but may need to override it
in custom HTML cell classes with any specific page breaking
requirements.
On input, @a pagebreak contains y-coordinate of page break (i.e. the
horizontal line that should not be crossed by words, images etc.)
relative to the parent cell on entry and may be modified to request a
page break at a position before it if this cell cannot be divided into
two pieces (each one on its own page).
Note that page break must still happen on the current page, i.e. the
returned value must be strictly greater than @code *pagebreak -
pageHeight @endcode and less or equal to @c *pagebreak for the value of
@a pagebreak on input.
@param pagebreak @param pagebreak
position in pixels of the pagebreak. position in pixels of the pagebreak.
@param known_pagebreaks
the list of the previous pagebreaks
@param pageHeight @param pageHeight
the height in pixels of the page drawable area the height in pixels of the page drawable area
@return @true if pagebreak was modified, @false otherwise.
*/ */
virtual bool AdjustPagebreak(int* pagebreak, virtual bool AdjustPagebreak(int* pagebreak, int pageHeight) const;
const wxArrayInt& known_pagebreaks,
int pageHeight) const;
/** /**
Renders the cell. Renders the cell.

View File

@@ -157,9 +157,7 @@ wxHtmlCell::GetMouseCursorAt(wxHtmlWindowInterface *window,
bool bool
wxHtmlCell::AdjustPagebreak(int *pagebreak, wxHtmlCell::AdjustPagebreak(int *pagebreak, int pageHeight) const
const wxArrayInt& WXUNUSED(known_pagebreaks),
int pageHeight) const
{ {
// Notice that we always break the cells bigger than the page height here // Notice that we always break the cells bigger than the page height here
// as otherwise we wouldn't be able to break them at all. // as otherwise we wouldn't be able to break them at all.
@@ -697,19 +695,17 @@ int wxHtmlContainerCell::GetIndentUnits(int ind) const
bool bool
wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int pageHeight) const
const wxArrayInt& known_pagebreaks,
int pageHeight) const
{ {
if (!m_CanLiveOnPagebreak) if (!m_CanLiveOnPagebreak)
return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, pageHeight); return wxHtmlCell::AdjustPagebreak(pagebreak, pageHeight);
bool rt = false; bool rt = false;
int pbrk = *pagebreak - m_PosY; int pbrk = *pagebreak - m_PosY;
for ( wxHtmlCell *c = GetFirstChild(); c; c = c->GetNext() ) for ( wxHtmlCell *c = GetFirstChild(); c; c = c->GetNext() )
{ {
if (c->AdjustPagebreak(&pbrk, known_pagebreaks, pageHeight)) if (c->AdjustPagebreak(&pbrk, pageHeight))
rt = true; rt = true;
} }
if (rt) if (rt)

View File

@@ -140,8 +140,7 @@ void wxHtmlDCRenderer::SetStandardFonts(int size,
// else: SetHtmlText() not yet called, no need for relayout // else: SetHtmlText() not yet called, no need for relayout
} }
int wxHtmlDCRenderer::FindNextPageBreak(const wxArrayInt& known_pagebreaks, int wxHtmlDCRenderer::FindNextPageBreak(int pos)
int pos)
{ {
// Stop looking for page breaks if the previous one was already at the end // Stop looking for page breaks if the previous one was already at the end
// of the last page. // of the last page.
@@ -152,7 +151,7 @@ int wxHtmlDCRenderer::FindNextPageBreak(const wxArrayInt& known_pagebreaks,
return wxNOT_FOUND; return wxNOT_FOUND;
int posNext = pos + m_Height; int posNext = pos + m_Height;
if ( m_Cells->AdjustPagebreak(&posNext, known_pagebreaks, m_Height) ) if ( m_Cells->AdjustPagebreak(&posNext, m_Height) )
{ {
// Check that AdjustPagebreak() returns the page break at a strictly // Check that AdjustPagebreak() returns the page break at a strictly
// greater position than that of the previous page, otherwise // greater position than that of the previous page, otherwise
@@ -486,7 +485,7 @@ void wxHtmlPrintout::CountPages()
for ( int pos = 0; pos != wxNOT_FOUND; ) for ( int pos = 0; pos != wxNOT_FOUND; )
{ {
m_PageBreaks.Add( pos); m_PageBreaks.Add( pos);
pos = m_Renderer.FindNextPageBreak(m_PageBreaks, pos); pos = m_Renderer.FindNextPageBreak(pos);
} }
} }

View File

@@ -65,9 +65,7 @@ class wxHtmlPageBreakCell : public wxHtmlCell
public: public:
wxHtmlPageBreakCell() {} wxHtmlPageBreakCell() {}
bool AdjustPagebreak(int* pagebreak, bool AdjustPagebreak(int* pagebreak, int pageHeight) const wxOVERRIDE;
const wxArrayInt& known_pagebreaks,
int pageHeight) const wxOVERRIDE;
void Draw(wxDC& WXUNUSED(dc), void Draw(wxDC& WXUNUSED(dc),
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
@@ -79,9 +77,7 @@ private:
}; };
bool bool
wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int pageHeight) const
const wxArrayInt& WXUNUSED(known_pagebreaks),
int pageHeight) const
{ {
// Request a page break at the position of this cell if it's on the current // 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 // page. Note that it's important not to do it unconditionally or we could