- // 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)
+ {
+ // 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;
+
+ if (!lastLine)
+ lastLine = line;
+
+ m_pageBreaksStart.Add(lastStartPos);
+ m_pageBreaksEnd.Add(lastLine->GetAbsoluteRange().GetEnd());
+ m_pageYOffsets.Add(yOffset);
+
+ lastStartPos = line->GetAbsoluteRange().GetStart();