- m_Renderer -> SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
- m_Renderer -> SetSize(ppmm_h * (mm_w - m_MarginLeft - m_MarginTop),
- ppmm_v * (mm_h - m_MarginTop - m_MarginBottom) -
- m_FooterHeight - m_HeaderHeight -
- ((m_HeaderHeight == 0) ? 0 : m_MarginSpace * ppmm_v) -
- ((m_FooterHeight == 0) ? 0 : m_MarginSpace * ppmm_v)
- );
- m_Renderer -> SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir);
- CountPages();
- return TRUE;
+ m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
+
+ const int printAreaW = int(ppmm_h * (mm_w - m_MarginLeft - m_MarginRight));
+ int printAreaH = int(ppmm_v * (mm_h - m_MarginTop - m_MarginBottom));
+ if ( m_HeaderHeight )
+ printAreaH -= int(m_HeaderHeight + m_MarginSpace * ppmm_v);
+ if ( m_FooterHeight )
+ printAreaH -= int(m_FooterHeight + m_MarginSpace * ppmm_v);
+
+ m_Renderer->SetSize(printAreaW, printAreaH);
+ m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir);
+
+ if ( CheckFit(wxSize(printAreaW, printAreaH),
+ wxSize(m_Renderer->GetTotalWidth(),
+ m_Renderer->GetTotalHeight())) )
+ {
+ // do paginate the document
+ CountPages();
+ }
+ //else: if we don't call CountPages() m_PageBreaks remains empty and our
+ // GetPageInfo() will return 0 as max page and so nothing will be
+ // printed
+}
+
+bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage)
+{
+ if (!wxPrintout::OnBeginDocument(startPage, endPage)) return false;
+
+ return true;