- // 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)
+ wxRichTextLine* line = node2->GetData();
+
+ int lineY = child->GetPosition().y + line->GetPosition().y - yOffset;
+ bool hasHardPageBreak = ((node2 == child->GetLines().GetFirst()) && child->GetAttributes().HasPageBreak());
+
+ // 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()) || hasHardPageBreak)
+ {
+ // 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
+
+ int increaseOffsetBy = lineY - newY;
+ yOffset += increaseOffsetBy;
+
+ m_pageBreaksStart.Add(lastStartPos);
+ m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd());
+ m_pageYOffsets.Add(yOffset);
+
+ lastStartPos = line->GetAbsoluteRange().GetStart();
+ m_numPages ++;
+ }
+