use dynamic array for the page breaks positions (patch 1483976)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39396 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -22,6 +22,8 @@ INCOMPATIBLE CHANGES SINCE 2.6.x
|
|||||||
wxHtmlCell::GetMouseCursor(); old code overriding GetCursor() will
|
wxHtmlCell::GetMouseCursor(); old code overriding GetCursor() will
|
||||||
continue to work with WXWIN_COMPATIBILITY_2_6, but should be rewritten to
|
continue to work with WXWIN_COMPATIBILITY_2_6, but should be rewritten to
|
||||||
use GetMouseCursor().
|
use GetMouseCursor().
|
||||||
|
- wxHtmlCell::AdjustPagebreak() signature has changed, update your code if you
|
||||||
|
override it
|
||||||
- wxFontEnumerator::GetFacenames() and GetEncodings() now return arrays and
|
- wxFontEnumerator::GetFacenames() and GetEncodings() now return arrays and
|
||||||
not pointers to arrays
|
not pointers to arrays
|
||||||
- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted
|
- wxStaticBoxSizer now deletes the associated wxStaticBox when it is deleted
|
||||||
|
@@ -277,8 +277,7 @@ public:
|
|||||||
// Returned value : true if pagebreak was modified, false otherwise
|
// Returned value : true if pagebreak was modified, false otherwise
|
||||||
// Usage : while (container->AdjustPagebreak(&p)) {}
|
// Usage : while (container->AdjustPagebreak(&p)) {}
|
||||||
virtual bool AdjustPagebreak(int *pagebreak,
|
virtual bool AdjustPagebreak(int *pagebreak,
|
||||||
int *known_pagebreaks = NULL,
|
wxArrayInt& known_pagebreaks) const;
|
||||||
int number_of_pages = 0) 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
|
||||||
@@ -411,7 +410,8 @@ public:
|
|||||||
wxHtmlRenderingInfo& info);
|
wxHtmlRenderingInfo& info);
|
||||||
virtual void DrawInvisible(wxDC& dc, int x, int y,
|
virtual void DrawInvisible(wxDC& dc, int x, int y,
|
||||||
wxHtmlRenderingInfo& info);
|
wxHtmlRenderingInfo& info);
|
||||||
virtual bool AdjustPagebreak(int *pagebreak, int *known_pagebreaks = NULL, int number_of_pages = 0) const;
|
/* virtual bool AdjustPagebreak(int *pagebreak, int *known_pagebreaks = NULL, int number_of_pages = 0) const;*/
|
||||||
|
virtual bool AdjustPagebreak(int *pagebreak, wxArrayInt& known_pagebreaks) const;
|
||||||
|
|
||||||
// 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);
|
||||||
|
@@ -77,9 +77,8 @@ public:
|
|||||||
// set the same pagebreak twice.
|
// set the same pagebreak twice.
|
||||||
//
|
//
|
||||||
// CAUTION! Render() changes DC's user scale and does NOT restore it!
|
// CAUTION! Render() changes DC's user scale and does NOT restore it!
|
||||||
int Render(int x, int y, int from = 0, int dont_render = FALSE,
|
int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0,
|
||||||
int maxHeight = INT_MAX,
|
int dont_render = FALSE, int to = INT_MAX);
|
||||||
int *known_pagebreaks = NULL, int number_of_pages = 0);
|
|
||||||
|
|
||||||
// returns total height of the html document
|
// returns total height of the html document
|
||||||
// (compare Render's return value with this)
|
// (compare Render's return value with this)
|
||||||
@@ -181,7 +180,8 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int m_NumPages;
|
int m_NumPages;
|
||||||
int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
|
//int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
|
||||||
|
wxArrayInt m_PageBreaks;
|
||||||
|
|
||||||
wxString m_Document, m_BasePath;
|
wxString m_Document, m_BasePath;
|
||||||
bool m_BasePathIsDir;
|
bool m_BasePathIsDir;
|
||||||
|
@@ -219,7 +219,8 @@ wxCursor wxHtmlCell::GetMouseCursor(wxHtmlWindowInterface *window) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxHtmlCell::AdjustPagebreak(int *pagebreak, int* WXUNUSED(known_pagebreaks), int WXUNUSED(number_of_pages)) const
|
bool wxHtmlCell::AdjustPagebreak(int *pagebreak,
|
||||||
|
wxArrayInt& WXUNUSED(known_pagebreaks)) const
|
||||||
{
|
{
|
||||||
if ((!m_CanLiveOnPagebreak) &&
|
if ((!m_CanLiveOnPagebreak) &&
|
||||||
m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
|
m_PosY < *pagebreak && m_PosY + m_Height > *pagebreak)
|
||||||
@@ -699,32 +700,28 @@ int wxHtmlContainerCell::GetIndentUnits(int ind) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak,
|
||||||
bool wxHtmlContainerCell::AdjustPagebreak(int *pagebreak, int* known_pagebreaks, int number_of_pages) const
|
wxArrayInt& known_pagebreaks) const
|
||||||
{
|
{
|
||||||
if (!m_CanLiveOnPagebreak)
|
if (!m_CanLiveOnPagebreak)
|
||||||
return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks, number_of_pages);
|
return wxHtmlCell::AdjustPagebreak(pagebreak, known_pagebreaks);
|
||||||
|
|
||||||
else
|
wxHtmlCell *c = GetFirstChild();
|
||||||
|
bool rt = false;
|
||||||
|
int pbrk = *pagebreak - m_PosY;
|
||||||
|
|
||||||
|
while (c)
|
||||||
{
|
{
|
||||||
wxHtmlCell *c = GetFirstChild();
|
if (c->AdjustPagebreak(&pbrk, known_pagebreaks))
|
||||||
bool rt = false;
|
rt = true;
|
||||||
int pbrk = *pagebreak - m_PosY;
|
c = c->GetNext();
|
||||||
|
|
||||||
while (c)
|
|
||||||
{
|
|
||||||
if (c->AdjustPagebreak(&pbrk, known_pagebreaks, number_of_pages))
|
|
||||||
rt = true;
|
|
||||||
c = c->GetNext();
|
|
||||||
}
|
|
||||||
if (rt)
|
|
||||||
*pagebreak = pbrk + m_PosY;
|
|
||||||
return rt;
|
|
||||||
}
|
}
|
||||||
|
if (rt)
|
||||||
|
*pagebreak = pbrk + m_PosY;
|
||||||
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void wxHtmlContainerCell::Layout(int w)
|
void wxHtmlContainerCell::Layout(int w)
|
||||||
{
|
{
|
||||||
wxHtmlCell::Layout(w);
|
wxHtmlCell::Layout(w);
|
||||||
|
@@ -103,20 +103,19 @@ void wxHtmlDCRenderer::SetStandardFonts(int size,
|
|||||||
m_Cells->Layout(m_Width);
|
m_Cells->Layout(m_Width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxHtmlDCRenderer::Render(int x, int y,
|
||||||
int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render,
|
wxArrayInt& known_pagebreaks,
|
||||||
int maxHeight,
|
int from, int dont_render, int to)
|
||||||
int *known_pagebreaks, int number_of_pages)
|
|
||||||
{
|
{
|
||||||
int pbreak, hght;
|
int pbreak, hght;
|
||||||
|
|
||||||
if (m_Cells == NULL || m_DC == NULL) return 0;
|
if (m_Cells == NULL || m_DC == NULL) return 0;
|
||||||
|
|
||||||
pbreak = (int)(from + m_Height);
|
pbreak = (int)(from + m_Height);
|
||||||
while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks, number_of_pages)) {}
|
while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks)) {}
|
||||||
hght = pbreak - from;
|
hght = pbreak - from;
|
||||||
if (maxHeight < hght)
|
if(to < hght)
|
||||||
hght = maxHeight;
|
hght = to;
|
||||||
|
|
||||||
if (!dont_render)
|
if (!dont_render)
|
||||||
{
|
{
|
||||||
@@ -137,7 +136,6 @@ int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int wxHtmlDCRenderer::GetTotalHeight()
|
int wxHtmlDCRenderer::GetTotalHeight()
|
||||||
{
|
{
|
||||||
if (m_Cells) return m_Cells->GetHeight();
|
if (m_Cells) return m_Cells->GetHeight();
|
||||||
@@ -265,16 +263,19 @@ bool wxHtmlPrintout::OnPrintPage(int page)
|
|||||||
void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
|
void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
|
||||||
{
|
{
|
||||||
*minPage = 1;
|
*minPage = 1;
|
||||||
*maxPage = m_NumPages;
|
if ( m_NumPages >= (signed)m_PageBreaks.Count()-1)
|
||||||
|
*maxPage = m_NumPages;
|
||||||
|
else
|
||||||
|
*maxPage = (signed)m_PageBreaks.Count()-1;
|
||||||
*selPageFrom = 1;
|
*selPageFrom = 1;
|
||||||
*selPageTo = m_NumPages;
|
*selPageTo = (signed)m_PageBreaks.Count()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool wxHtmlPrintout::HasPage(int pageNum)
|
bool wxHtmlPrintout::HasPage(int pageNum)
|
||||||
{
|
{
|
||||||
return (pageNum >= 1 && pageNum <= m_NumPages);
|
return (pageNum >= 1 && pageNum-1 <= (signed)m_PageBreaks.Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -360,16 +361,24 @@ void wxHtmlPrintout::CountPages()
|
|||||||
ppmm_v = (float)pageHeight / mm_h;
|
ppmm_v = (float)pageHeight / mm_h;
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
m_NumPages = 0;
|
m_NumPages = 0;
|
||||||
|
// m_PageBreaks[0] = 0;
|
||||||
|
|
||||||
m_PageBreaks[0] = 0;
|
m_PageBreaks.Clear();
|
||||||
|
m_PageBreaks.Add( 0);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft),
|
pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft),
|
||||||
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
|
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
|
||||||
pos, true, INT_MAX, m_PageBreaks, m_NumPages);
|
m_PageBreaks,
|
||||||
m_PageBreaks[++m_NumPages] = pos;
|
pos, true, INT_MAX);
|
||||||
|
m_PageBreaks.Add( pos);
|
||||||
|
if( m_PageBreaks.Count() > wxHTML_PRINT_MAX_PAGES)
|
||||||
|
{
|
||||||
|
wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can continue any longer!"),
|
||||||
|
_("Warning"), wxCANCEL | wxICON_ERROR );
|
||||||
|
break;
|
||||||
|
}
|
||||||
} while (pos < m_Renderer->GetTotalHeight());
|
} while (pos < m_Renderer->GetTotalHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,19 +412,20 @@ void wxHtmlPrintout::RenderPage(wxDC *dc, int page)
|
|||||||
dc->SetBackgroundMode(wxTRANSPARENT);
|
dc->SetBackgroundMode(wxTRANSPARENT);
|
||||||
|
|
||||||
m_Renderer->Render((int) (ppmm_h * m_MarginLeft),
|
m_Renderer->Render((int) (ppmm_h * m_MarginLeft),
|
||||||
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
|
(int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks,
|
||||||
m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]);
|
m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]);
|
||||||
|
|
||||||
|
|
||||||
m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
|
m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
|
||||||
if (m_Headers[page % 2] != wxEmptyString)
|
if (m_Headers[page % 2] != wxEmptyString)
|
||||||
{
|
{
|
||||||
m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page));
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page));
|
||||||
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop));
|
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop), m_PageBreaks);
|
||||||
}
|
}
|
||||||
if (m_Footers[page % 2] != wxEmptyString)
|
if (m_Footers[page % 2] != wxEmptyString)
|
||||||
{
|
{
|
||||||
m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page));
|
m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page));
|
||||||
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight));
|
m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight), m_PageBreaks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +439,7 @@ wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page)
|
|||||||
num.Printf(wxT("%i"), page);
|
num.Printf(wxT("%i"), page);
|
||||||
r.Replace(wxT("@PAGENUM@"), num);
|
r.Replace(wxT("@PAGENUM@"), num);
|
||||||
|
|
||||||
num.Printf(wxT("%i"), m_NumPages);
|
num.Printf(wxT("%i"), m_PageBreaks.Count()-1);
|
||||||
r.Replace(wxT("@PAGESCNT@"), num);
|
r.Replace(wxT("@PAGESCNT@"), num);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@@ -72,8 +72,8 @@ public:
|
|||||||
wxHtmlPageBreakCell() {}
|
wxHtmlPageBreakCell() {}
|
||||||
|
|
||||||
bool AdjustPagebreak(int* pagebreak,
|
bool AdjustPagebreak(int* pagebreak,
|
||||||
int* known_pagebreaks = NULL,
|
wxArrayInt& known_pagebreaks) const;
|
||||||
int number_of_pages = 0) const;
|
|
||||||
void Draw(wxDC& WXUNUSED(dc),
|
void Draw(wxDC& WXUNUSED(dc),
|
||||||
int WXUNUSED(x), int WXUNUSED(y),
|
int WXUNUSED(x), int WXUNUSED(y),
|
||||||
int WXUNUSED(view_y1), int WXUNUSED(view_y2),
|
int WXUNUSED(view_y1), int WXUNUSED(view_y2),
|
||||||
@@ -89,7 +89,7 @@ extern "C" int wxCMPFUNC_CONV wxInteger_compare(void const* i0, void const* i1)
|
|||||||
return *(int*)i0 - *(int*)i1;
|
return *(int*)i0 - *(int*)i1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks, int number_of_pages) const
|
bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, wxArrayInt& known_pagebreaks) const
|
||||||
{
|
{
|
||||||
// When we are counting pages, 'known_pagebreaks' is non-NULL.
|
// When we are counting pages, 'known_pagebreaks' is non-NULL.
|
||||||
// That's the only time we change 'pagebreak'. Otherwise, pages
|
// That's the only time we change 'pagebreak'. Otherwise, pages
|
||||||
@@ -101,10 +101,10 @@ bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks,
|
|||||||
// vertical position. Otherwise we'd be setting a pagebreak above
|
// vertical position. Otherwise we'd be setting a pagebreak above
|
||||||
// the current cell, which is incorrect, or duplicating a
|
// the current cell, which is incorrect, or duplicating a
|
||||||
// pagebreak that has already been set.
|
// pagebreak that has already been set.
|
||||||
if(NULL == known_pagebreaks || *pagebreak <= m_PosY)
|
if( known_pagebreaks.Count() == 0 || *pagebreak <= m_PosY)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_PosY is only the vertical offset from the parent. The pagebreak
|
// 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
|
// required here is the total page offset, so m_PosY must be added
|
||||||
@@ -117,21 +117,21 @@ bool wxHtmlPageBreakCell::AdjustPagebreak(int* pagebreak, int* known_pagebreaks,
|
|||||||
// is known to be sorted in strictly increasing order. '1 + number_of_pages'
|
// is known to be sorted in strictly increasing order. '1 + number_of_pages'
|
||||||
// is used as a bsearch() argument because the array contains a leading
|
// is used as a bsearch() argument because the array contains a leading
|
||||||
// zero plus one element for each page.
|
// zero plus one element for each page.
|
||||||
int* where = (int*) bsearch(&total_height, known_pagebreaks,
|
int where = known_pagebreaks.Index( total_height);
|
||||||
1 + number_of_pages, sizeof(int),
|
|
||||||
wxInteger_compare);
|
|
||||||
// Add a pagebreak only if there isn't one already set here.
|
// Add a pagebreak only if there isn't one already set here.
|
||||||
if(NULL != where)
|
if( wxNOT_FOUND != where)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*pagebreak = m_PosY;
|
*pagebreak = m_PosY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TAG_HANDLER_BEGIN(P, "P")
|
TAG_HANDLER_BEGIN(P, "P")
|
||||||
TAG_HANDLER_CONSTR(P) { }
|
TAG_HANDLER_CONSTR(P) { }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user