X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7193abfbc8e8e66555b38dad56dce5fcfaee3204..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/richtext/richtextprint.cpp diff --git a/src/richtext/richtextprint.cpp b/src/richtext/richtextprint.cpp index b491ac947b..837d3b0c58 100644 --- a/src/richtext/richtextprint.cpp +++ b/src/richtext/richtextprint.cpp @@ -3,7 +3,6 @@ // Purpose: Rich text printing classes // Author: Julian Smart // Created: 2006-10-24 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -97,26 +96,30 @@ void wxRichTextPrintout::OnPreparePrinting() if (((lineY + line->GetSize().y) > rect.GetBottom()) || hasHardPageBreak) { - // New page starting at this line - int newY = rect.y; + // Only if we're not at the start of the document, and + // even then, only if either it's a hard break or if the object + // can fit in a whole page (otherwise there's no point in making + // the rest of this page blank). + if (lastLine && (hasHardPageBreak || (line->GetSize().y <= rect.GetHeight()))) + { + // New page starting at this line + int newY = rect.y; - // We increase the offset by the difference between new and old positions + // We increase the offset by the difference between new and old positions - int increaseOffsetBy = lineY - newY; - yOffset += increaseOffsetBy; + int increaseOffsetBy = lineY - newY; + yOffset += increaseOffsetBy; - if (!lastLine) - lastLine = line; + m_pageBreaksStart.Add(lastStartPos); + m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd()); + m_pageYOffsets.Add(yOffset); - m_pageBreaksStart.Add(lastStartPos); - m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd()); - m_pageYOffsets.Add(yOffset); + lastStartPos = line->GetAbsoluteRange().GetStart(); + m_numPages ++; + } - lastStartPos = line->GetAbsoluteRange().GetStart(); lastLine = line; - m_numPages ++; - // Now create page breaks for the rest of the line, if it's larger than the page height int contentLeft = line->GetSize().y - rect.GetHeight(); while (contentLeft >= 0) @@ -127,6 +130,8 @@ void wxRichTextPrintout::OnPreparePrinting() m_pageBreaksStart.Add(lastStartPos); m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd()); m_pageYOffsets.Add(yOffset); + + m_numPages ++; } } @@ -140,12 +145,9 @@ void wxRichTextPrintout::OnPreparePrinting() } // Closing page break - if (m_pageBreaksStart.GetCount() == 0 || (m_pageBreaksEnd[m_pageBreaksEnd.GetCount()-1] < (GetRichTextBuffer()->GetOwnRange().GetEnd()-1))) - { - m_pageBreaksStart.Add(lastStartPos); - m_pageBreaksEnd.Add(GetRichTextBuffer()->GetOwnRange().GetEnd()); - m_pageYOffsets.Add(yOffset); - } + m_pageBreaksStart.Add(lastStartPos); + m_pageBreaksEnd.Add(GetRichTextBuffer()->GetOwnRange().GetEnd()); + m_pageYOffsets.Add(yOffset); } } @@ -345,8 +347,8 @@ void wxRichTextPrintout::CalculateScaling(wxDC* dc, wxRect& textRect, wxRect& he // The dimensions used for indentation etc. have to be unscaled // during printing to be correct when scaling is applied. - // if (!IsPreview()) - m_richTextBuffer->SetScale(scale); + // Also, correct the conversions in wxRTC using DC instead of print DC. + m_richTextBuffer->SetScale(scale * float(dc->GetPPI().x)/float(ppiPrinterX)); // Calculate margins int marginLeft = wxRichTextObject::ConvertTenthsMMToPixels(ppiPrinterX, m_marginLeft); @@ -503,6 +505,7 @@ void wxRichTextPrinting::SetRichTextBufferPreview(wxRichTextBuffer* buf) m_richTextBufferPreview = buf; } +#if wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PreviewFile(const wxString& richTextFile) { SetRichTextBufferPreview(new wxRichTextBuffer); @@ -522,6 +525,7 @@ bool wxRichTextPrinting::PreviewFile(const wxString& richTextFile) p2->SetRichTextBuffer(m_richTextBufferPrinting); return DoPreview(p1, p2); } +#endif // wxUSE_FFILE && wxUSE_STREAMS bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) { @@ -537,7 +541,8 @@ bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) return DoPreview(p1, p2); } -bool wxRichTextPrinting::PrintFile(const wxString& richTextFile) +#if wxUSE_FFILE && wxUSE_STREAMS +bool wxRichTextPrinting::PrintFile(const wxString& richTextFile, bool showPrintDialog) { SetRichTextBufferPrinting(new wxRichTextBuffer); @@ -550,19 +555,20 @@ bool wxRichTextPrinting::PrintFile(const wxString& richTextFile) wxRichTextPrintout *p = CreatePrintout(); p->SetRichTextBuffer(m_richTextBufferPrinting); - bool ret = DoPrint(p); + bool ret = DoPrint(p, showPrintDialog); delete p; return ret; } +#endif // wxUSE_FFILE && wxUSE_STREAMS -bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer& buffer) +bool wxRichTextPrinting::PrintBuffer(const wxRichTextBuffer& buffer, bool showPrintDialog) { SetRichTextBufferPrinting(new wxRichTextBuffer(buffer)); wxRichTextPrintout *p = CreatePrintout(); p->SetRichTextBuffer(m_richTextBufferPrinting); - bool ret = DoPrint(p); + bool ret = DoPrint(p, showPrintDialog); delete p; return ret; } @@ -587,12 +593,12 @@ bool wxRichTextPrinting::DoPreview(wxRichTextPrintout *printout1, wxRichTextPrin return true; } -bool wxRichTextPrinting::DoPrint(wxRichTextPrintout *printout) +bool wxRichTextPrinting::DoPrint(wxRichTextPrintout *printout, bool showPrintDialog) { wxPrintDialogData printDialogData(*GetPrintData()); wxPrinter printer(&printDialogData); - if (!printer.Print(m_parentWindow, printout, true)) + if (!printer.Print(m_parentWindow, printout, showPrintDialog)) { return false; }