X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2786b6232c5967dd79278a20d9558d79bebc41f8..a3a8d81d487ae4f03d8b70bce20bddbfc48c5776:/src/richtext/richtextprint.cpp diff --git a/src/richtext/richtextprint.cpp b/src/richtext/richtextprint.cpp index 5319131f74..2efffa46a5 100644 --- a/src/richtext/richtextprint.cpp +++ b/src/richtext/richtextprint.cpp @@ -50,13 +50,13 @@ void wxRichTextPrintout::OnPreparePrinting() { wxBusyCursor wait; - m_numPages = 0; + m_numPages = 1; m_pageBreaksStart.Clear(); m_pageBreaksEnd.Clear(); - + int lastStartPos = 0; - + wxRect rect, headerRect, footerRect; /// Sets the DC scaling and returns important page rectangles @@ -67,13 +67,13 @@ void wxRichTextPrintout::OnPreparePrinting() GetRichTextBuffer()->Invalidate(wxRICHTEXT_ALL); GetRichTextBuffer()->Layout(*GetDC(), rect, wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT); - + // Now calculate the page breaks - + int yOffset = 0; - + wxRichTextLine* lastLine = NULL; - + wxRichTextObjectList::compatibility_iterator node = GetRichTextBuffer()->GetChildren().GetFirst(); while (node) { @@ -85,35 +85,39 @@ void wxRichTextPrintout::OnPreparePrinting() 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; - + // We increase the offset by the difference between new and old positions - + int increaseOffsetBy = lineY - newY; yOffset += increaseOffsetBy; - + line->SetPosition(wxPoint(line->GetPosition().x, newY - child->GetPosition().y)); if (!lastLine) lastLine = line; - + m_pageBreaksStart.Add(lastStartPos); m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd()); - + lastStartPos = line->GetAbsoluteRange().GetStart(); - + m_numPages ++; } - + lastLine = line; node2 = node2->GetNext(); @@ -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 ++; } } } @@ -170,7 +173,7 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) return; wxBusyCursor wait; - + wxRect textRect, headerRect, footerRect; /// Sets the DC scaling and returns important page rectangles @@ -186,9 +189,9 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) dc->SetTextForeground(m_headerFooterData.GetTextColour()); else dc->SetTextForeground(*wxBLACK); - dc->SetBackgroundMode(wxTRANSPARENT); + dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); - // Draw header, if any + // Draw header, if any wxRichTextOddEvenPage oddEven = ((page % 2) == 1) ? wxRICHTEXT_PAGE_ODD : wxRICHTEXT_PAGE_EVEN; wxString headerTextCentre = m_headerFooterData.GetHeaderText(oddEven, wxRICHTEXT_PAGE_CENTRE); @@ -201,7 +204,7 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) //int tx, ty; //dc->GetTextExtent(headerTextLeft, & tx, & ty); - + int x = headerRect.GetLeft(); int y = headerRect.GetX(); dc->DrawText(headerTextLeft, x, y); @@ -229,7 +232,7 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) dc->DrawText(headerTextRight, x, y); } - // Draw footer, if any + // Draw footer, if any wxString footerTextCentre = m_headerFooterData.GetFooterText(oddEven, wxRICHTEXT_PAGE_CENTRE); wxString footerTextLeft = m_headerFooterData.GetFooterText(oddEven, wxRICHTEXT_PAGE_LEFT); wxString footerTextRight = m_headerFooterData.GetFooterText(oddEven, wxRICHTEXT_PAGE_RIGHT); @@ -267,7 +270,7 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) int y = footerRect.GetBottom() - ty; dc->DrawText(footerTextRight, x, y); } - } + } wxRichTextRange rangeToDraw(m_pageBreaksStart[page-1], m_pageBreaksEnd[page-1]); @@ -301,7 +304,7 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he int w, h; dc->GetSize(&w, &h); GetPageSizePixels(&pageWidth, &pageHeight); - + // If printer pageWidth == current DC width, then this doesn't // change. But w might be the preview bitmap width, so scale down. float previewScale = (float)(w/(float)pageWidth); @@ -311,22 +314,22 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he // during printing to be correct when scaling is applied. if (!IsPreview()) m_richTextBuffer->SetScale(scale); - + // Calculate margins int marginLeft = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginLeft); int marginTop = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginTop); int marginRight = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginRight); int marginBottom = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginBottom); - + // Header and footer margins int headerMargin = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_headerFooterData.GetHeaderMargin()); int footerMargin = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_headerFooterData.GetFooterMargin()); - + dc->SetUserScale(overallScale, overallScale); wxRect rect((int) (marginLeft/scale), (int) (marginTop/scale), (int) ((pageWidth - marginLeft - marginRight)/scale), (int)((pageHeight - marginTop - marginBottom)/scale)); - + headerRect = wxRect(0, 0, 0, 0); if (!m_headerFooterData.GetHeaderText(wxRICHTEXT_PAGE_ODD, wxRICHTEXT_PAGE_LEFT).IsEmpty() || @@ -341,15 +344,15 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he dc->SetFont(m_headerFooterData.GetFont()); else dc->SetFont(*wxNORMAL_FONT); - + int charHeight = dc->GetCharHeight(); - + int headerHeight = (int) (charHeight + headerMargin/scale); headerRect = wxRect(rect.x, rect.y, rect.width, headerHeight); rect.y += headerHeight; - rect.height -= headerHeight; + rect.height -= headerHeight; } footerRect = wxRect(0, 0, 0, 0); @@ -366,14 +369,14 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he dc->SetFont(m_headerFooterData.GetFont()); else dc->SetFont(*wxNORMAL_FONT); - + int charHeight = dc->GetCharHeight(); - + int footerHeight = (int) (charHeight + footerMargin/scale); footerRect = wxRect(rect.x, rect.y + rect.height, rect.width, footerHeight); - rect.height -= footerHeight; + rect.height -= footerHeight; } textRect = rect; @@ -411,7 +414,7 @@ wxRichTextPrinting::wxRichTextPrinting(const wxString& name, wxWindow *parentWin m_parentWindow = parentWindow; m_title = name; m_printData = NULL; - + m_previewRect = wxRect(wxPoint(100, 100), wxSize(800, 800)); m_pageSetupData = new wxPageSetupDialogData; @@ -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) { @@ -467,7 +481,7 @@ bool wxRichTextPrinting::PreviewFile(const wxString& richTextFile) } else SetRichTextBufferPrinting(new wxRichTextBuffer(*m_richTextBufferPreview)); - + wxRichTextPrintout *p1 = CreatePrintout(); p1->SetRichTextBuffer(m_richTextBufferPreview); @@ -483,7 +497,7 @@ bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) wxRichTextPrintout *p1 = CreatePrintout(); p1->SetRichTextBuffer(m_richTextBufferPreview); - + wxRichTextPrintout *p2 = CreatePrintout(); p2->SetRichTextBuffer(m_richTextBufferPrinting);