X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/44219ff04fedc5ede9842494fa29fbcb1fec04b0..c7bd016e16408bbd88a89a9089b35edcebedcb3e:/src/richtext/richtextprint.cpp diff --git a/src/richtext/richtextprint.cpp b/src/richtext/richtextprint.cpp index 0032487f4c..5aa23ca70f 100644 --- a/src/richtext/richtextprint.cpp +++ b/src/richtext/richtextprint.cpp @@ -50,7 +50,7 @@ void wxRichTextPrintout::OnPreparePrinting() { wxBusyCursor wait; - m_numPages = 0; + m_numPages = 1; m_pageBreaksStart.Clear(); m_pageBreaksEnd.Clear(); @@ -80,18 +80,22 @@ void wxRichTextPrintout::OnPreparePrinting() // child is a paragraph wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph); wxASSERT (child != NULL); - + wxRichTextLineList::compatibility_iterator node2 = child->GetLines().GetFirst(); while (node2) { wxRichTextLine* line = node2->GetData(); - + // Set the line to the page-adjusted position line->SetPosition(wxPoint(line->GetPosition().x, line->GetPosition().y - yOffset)); int lineY = child->GetPosition().y + line->GetPosition().y; - if ((lineY + line->GetSize().y) > rect.GetBottom()) + // Break the page if either we're going off the bottom, or this paragraph specifies + // an explicit page break + + if (((lineY + line->GetSize().y) > rect.GetBottom()) || + ((node2 == child->GetLines().GetFirst()) && child->GetAttributes().HasPageBreak())) { // New page starting at this line int newY = rect.y; @@ -123,11 +127,10 @@ void wxRichTextPrintout::OnPreparePrinting() } // Closing page break - if (m_pageBreaksStart.GetCount() > 0 && (m_pageBreaksEnd[m_pageBreaksEnd.GetCount()-1] < (GetRichTextBuffer()->GetRange().GetEnd()-1))) + if (m_pageBreaksStart.GetCount() == 0 || (m_pageBreaksEnd[m_pageBreaksEnd.GetCount()-1] < (GetRichTextBuffer()->GetRange().GetEnd()-1))) { m_pageBreaksStart.Add(lastStartPos); m_pageBreaksEnd.Add(GetRichTextBuffer()->GetRange().GetEnd()); - m_numPages ++; } } } @@ -324,8 +327,8 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he dc->SetUserScale(overallScale, overallScale); - wxRect rect(marginLeft/scale, marginTop/scale, - (pageWidth - marginLeft - marginRight)/scale, (pageHeight - marginTop - marginBottom)/scale); + wxRect rect((int) (marginLeft/scale), (int) (marginTop/scale), + (int) ((pageWidth - marginLeft - marginRight)/scale), (int)((pageHeight - marginTop - marginBottom)/scale)); headerRect = wxRect(0, 0, 0, 0); @@ -344,7 +347,7 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he int charHeight = dc->GetCharHeight(); - int headerHeight = charHeight + headerMargin/scale; + int headerHeight = (int) (charHeight + headerMargin/scale); headerRect = wxRect(rect.x, rect.y, rect.width, headerHeight); @@ -369,7 +372,7 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he int charHeight = dc->GetCharHeight(); - int footerHeight = charHeight + footerMargin/scale; + int footerHeight = (int) (charHeight + footerMargin/scale); footerRect = wxRect(rect.x, rect.y + rect.height, rect.width, footerHeight); @@ -435,6 +438,17 @@ wxPrintData *wxRichTextPrinting::GetPrintData() return m_printData; } +/// Set print and page setup data +void wxRichTextPrinting::SetPrintData(const wxPrintData& printData) +{ + (*GetPrintData()) = printData; +} + +void wxRichTextPrinting::SetPageSetupData(const wxPageSetupData& pageSetupData) +{ + (*GetPageSetupData()) = pageSetupData; +} + /// Set the rich text buffer pointer, deleting the existing object if present void wxRichTextPrinting::SetRichTextBufferPrinting(wxRichTextBuffer* buf) {