]> git.saurik.com Git - wxWidgets.git/blobdiff - src/richtext/richtextprint.cpp
revert r73185, it should no longer be needed after r73231
[wxWidgets.git] / src / richtext / richtextprint.cpp
index cc4714cdd3fdd458986c4d323870f39d25f6a709..59c331d02fc940b570ed949db53b3ccc7b3d7792 100644 (file)
@@ -97,26 +97,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 +131,8 @@ void wxRichTextPrintout::OnPreparePrinting()
                             m_pageBreaksStart.Add(lastStartPos);
                             m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd());
                             m_pageYOffsets.Add(yOffset);
+
+                            m_numPages ++;
                         }
                     }
 
@@ -140,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);
     }
 }
 
@@ -345,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);