X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9f7e7edb78aa19d6aed53b113aa953c24d6335b1..960615f41009ac62e99f833afbec10d96bd2d2f9:/src/html/htmprint.cpp diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index 158483e3a9..6a22f88547 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -74,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; } @@ -81,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); @@ -96,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, @@ -105,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)) {} @@ -132,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(); } @@ -141,11 +150,14 @@ int wxHtmlDCRenderer::Render(int x, int y, else return GetTotalHeight(); } +int wxHtmlDCRenderer::GetTotalWidth() const +{ + return m_Cells ? m_Cells->GetWidth() : 0; +} -int wxHtmlDCRenderer::GetTotalHeight() +int wxHtmlDCRenderer::GetTotalHeight() const { - if (m_Cells) return m_Cells->GetHeight(); - else return 0; + return m_Cells ? m_Cells->GetHeight() : 0; } @@ -188,6 +200,40 @@ void wxHtmlPrintout::AddFilter(wxHtmlFilter *filter) m_Filters.Append(filter); } +bool +wxHtmlPrintout::CheckFit(const wxSize& pageArea, const wxSize& docArea) const +{ + if ( docArea.x > pageArea.x ) + { + wxMessageDialog + dlg + ( + NULL, + wxString::Format + ( + _("The document \"%s\" doesn't fit on the page " + "horizontally and will be truncated if printed.\n" + "\n" + "Would you like to proceed with printing it nevertheless?"), + GetTitle() + ), + _("Printing"), + wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxICON_QUESTION + ); + dlg.SetExtendedMessage + ( + _("If possible, try changing the layout parameters to " + "make the printout more narrow.") + ); + dlg.SetOKLabel(wxID_PRINT); + + if ( dlg.ShowModal() == wxID_CANCEL ) + return false; + } + + return true; +} + void wxHtmlPrintout::OnPreparePrinting() { int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h; @@ -200,8 +246,10 @@ 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); @@ -237,14 +285,27 @@ void wxHtmlPrintout::OnPreparePrinting() /* prepare main renderer: */ m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY); - m_Renderer->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)), - (int) (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) - )); + + 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); - CountPages(); + + 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)