X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b4a980f4f57a4e7eea00c55cbb3d139f97d90c20..d90ef8e4c243a66548765fa1e502dbb55589d723:/src/html/htmprint.cpp diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index ae29a67390..f4c978dbf3 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -33,6 +33,10 @@ #include "wx/wfstream.h" +// default font size of normal text (HTML font size 0) for printing, in points: +#define DEFAULT_PRINT_FONT_SIZE 12 + + //-------------------------------------------------------------------------------- // wxHtmlDCRenderer //-------------------------------------------------------------------------------- @@ -46,6 +50,7 @@ wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject() m_Parser = new wxHtmlWinParser(); m_FS = new wxFileSystem(); m_Parser->SetFS(m_FS); + SetStandardFonts(DEFAULT_PRINT_FONT_SIZE); } @@ -69,6 +74,9 @@ void wxHtmlDCRenderer::SetDC(wxDC *dc, double pixel_scale) void wxHtmlDCRenderer::SetSize(int width, int height) { + wxCHECK_RET( width, "width must be non-zero" ); + wxCHECK_RET( height, "height must be non-zero" ); + m_Width = width; m_Height = height; } @@ -76,9 +84,10 @@ void wxHtmlDCRenderer::SetSize(int width, int height) void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepath, bool isdir) { - if (m_DC == NULL) return; + wxCHECK_RET( m_DC, "SetDC() must be called before SetHtmlText()" ); + wxCHECK_RET( m_Width, "SetSize() must be called before SetHtmlText()" ); - if (m_Cells != NULL) delete m_Cells; + wxDELETE(m_Cells); m_FS->ChangePathTo(basepath, isdir); m_Cells = (wxHtmlContainerCell*) m_Parser->Parse(html); @@ -91,8 +100,10 @@ void wxHtmlDCRenderer::SetFonts(const wxString& normal_face, const wxString& fix const int *sizes) { m_Parser->SetFonts(normal_face, fixed_face, sizes); - if (m_DC == NULL && m_Cells != NULL) + + if ( m_Cells ) m_Cells->Layout(m_Width); + // else: SetHtmlText() not yet called, no need for relayout } void wxHtmlDCRenderer::SetStandardFonts(int size, @@ -100,17 +111,20 @@ void wxHtmlDCRenderer::SetStandardFonts(int size, const wxString& fixed_face) { m_Parser->SetStandardFonts(size, normal_face, fixed_face); - if (m_DC == NULL && m_Cells != NULL) + + if ( m_Cells ) m_Cells->Layout(m_Width); + // else: SetHtmlText() not yet called, no need for relayout } int wxHtmlDCRenderer::Render(int x, int y, wxArrayInt& known_pagebreaks, int from, int dont_render, int to) { - int pbreak, hght; + wxCHECK_MSG( m_Cells, 0, "SetHtmlText() must be called before Render()" ); + wxCHECK_MSG( m_DC, 0, "SetDC() must be called before Render()" ); - if (m_Cells == NULL || m_DC == NULL) return 0; + int pbreak, hght; pbreak = (int)(from + m_Height); while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks)) {} @@ -127,7 +141,7 @@ int wxHtmlDCRenderer::Render(int x, int y, m_DC->SetClippingRegion(x, y, m_Width, hght); m_Cells->Draw(*m_DC, x, (y - from), - y, pbreak + (y /*- from*/), + y, y + hght, rinfo); m_DC->DestroyClippingRegion(); } @@ -161,6 +175,7 @@ wxHtmlPrintout::wxHtmlPrintout(const wxString& title) : wxPrintout(title) m_Footers[0] = m_Footers[1] = wxEmptyString; m_HeaderHeight = m_FooterHeight = 0; SetMargins(); // to default values + SetStandardFonts(DEFAULT_PRINT_FONT_SIZE); } @@ -194,13 +209,16 @@ void wxHtmlPrintout::OnPreparePrinting() int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); + wxUnusedVar(ppiPrinterX); int ppiScreenX, ppiScreenY; GetPPIScreen(&ppiScreenX, &ppiScreenY); + wxUnusedVar(ppiScreenX); wxDisplaySize(&scr_w, &scr_h); GetDC()->GetSize(&dc_w, &dc_h); - GetDC()->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth); + GetDC()->SetUserScale((double)dc_w / (double)pageWidth, + (double)dc_h / (double)pageHeight); /* prepare headers/footers renderer: */ @@ -251,7 +269,7 @@ bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage) bool wxHtmlPrintout::OnPrintPage(int page) { wxDC *dc = GetDC(); - if (dc) + if (dc && dc->IsOk()) { if (HasPage(page)) RenderPage(dc, page); @@ -406,11 +424,12 @@ void wxHtmlPrintout::RenderPage(wxDC *dc, int page) GetPPIScreen(&ppiScreenX, &ppiScreenY); wxUnusedVar(ppiScreenX); - dc->SetUserScale((double)dc_w / (double)pageWidth, (double)dc_w / (double)pageWidth); + dc->SetUserScale((double)dc_w / (double)pageWidth, + (double)dc_h / (double)pageHeight); m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY); - dc->SetBackgroundMode(wxTRANSPARENT); + dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); m_Renderer->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks, @@ -500,7 +519,7 @@ wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxWindow *parentWin m_PageSetupData->SetMarginTopLeft(wxPoint(25, 25)); m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25)); - SetFonts(wxEmptyString, wxEmptyString, NULL); + SetStandardFonts(DEFAULT_PRINT_FONT_SIZE); }