X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/906c935a80b10d53cecf57f71ab5f3f4f1d529ec..ad653fa23069c5d9378247084f03c9a718c3ad62:/src/richtext/richtextprint.cpp diff --git a/src/richtext/richtextprint.cpp b/src/richtext/richtextprint.cpp index 0bdbb0b031..59c331d02f 100644 --- a/src/richtext/richtextprint.cpp +++ b/src/richtext/richtextprint.cpp @@ -67,7 +67,8 @@ void wxRichTextPrintout::OnPreparePrinting() { GetRichTextBuffer()->Invalidate(wxRICHTEXT_ALL); - GetRichTextBuffer()->Layout(*GetDC(), rect, wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT); + wxRichTextDrawingContext context(GetRichTextBuffer()); + GetRichTextBuffer()->Layout(*GetDC(), context, rect, rect, wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT); // Now calculate the page breaks @@ -96,37 +97,43 @@ 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) { yOffset += rect.GetHeight(); contentLeft -= rect.GetHeight(); - + m_pageBreaksStart.Add(lastStartPos); m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd()); m_pageYOffsets.Add(yOffset); - } + + m_numPages ++; + } } lastLine = line; @@ -139,12 +146,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); } } @@ -286,7 +290,7 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) } wxRichTextRange rangeToDraw(m_pageBreaksStart[page-1], m_pageBreaksEnd[page-1]); - + wxPoint oldOrigin = dc->GetLogicalOrigin(); double scaleX, scaleY; dc->GetUserScale(& scaleX, & scaleY); @@ -294,13 +298,14 @@ void wxRichTextPrintout::RenderPage(wxDC *dc, int page) int yOffset = 0; if (page > 1) yOffset = m_pageYOffsets[page-2]; - + if (yOffset != oldOrigin.y) dc->SetLogicalOrigin(oldOrigin.x, oldOrigin.y + yOffset); dc->SetClippingRegion(wxRect(textRect.x, textRect.y + yOffset, textRect.width, textRect.height)); - GetRichTextBuffer()->Draw(*dc, rangeToDraw, wxRichTextSelection(), textRect, 0 /* descent */, wxRICHTEXT_DRAW_IGNORE_CACHE|wxRICHTEXT_DRAW_PRINT /* flags */); + wxRichTextDrawingContext context(GetRichTextBuffer()); + GetRichTextBuffer()->Draw(*dc, context, rangeToDraw, wxRichTextSelection(), textRect, 0 /* descent */, wxRICHTEXT_DRAW_IGNORE_CACHE|wxRICHTEXT_DRAW_PRINT /* flags */); dc->DestroyClippingRegion(); @@ -343,8 +348,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); @@ -475,7 +480,7 @@ void wxRichTextPrinting::SetPrintData(const wxPrintData& printData) (*GetPrintData()) = printData; } -void wxRichTextPrinting::SetPageSetupData(const wxPageSetupData& pageSetupData) +void wxRichTextPrinting::SetPageSetupData(const wxPageSetupDialogData& pageSetupData) { (*GetPageSetupData()) = pageSetupData; } @@ -535,7 +540,7 @@ bool wxRichTextPrinting::PreviewBuffer(const wxRichTextBuffer& buffer) return DoPreview(p1, p2); } -bool wxRichTextPrinting::PrintFile(const wxString& richTextFile) +bool wxRichTextPrinting::PrintFile(const wxString& richTextFile, bool showPrintDialog) { SetRichTextBufferPrinting(new wxRichTextBuffer); @@ -548,19 +553,19 @@ 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; } -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; } @@ -585,12 +590,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; }