SharpLeaf Tutorials > Text Flow Tutorials > Widow and Orphan Control

Widow and Orphan Control

SharpLeaf provides simple ParagraphStyle settings to prevent odd paragraph splitting across page or frame boundary.

Keeping lines together

The Keep property of a ParagraphStyle determines the minimum number of lines that can be on their own at the start or end of a paragraph, when a frame skip occurs.

  // Disable widow/orphan control (the default value anyway)
   lf.Style.Keep=1;

The default setting produces a single line on its own at the top of the second frame.

  // Enable widow/orphan control, forbidding one line on its own
   lf.Style.Keep=2;

Setting the Keep to two make the text flow slightly nicer, as the penultimate line is pushed onto the second frame although it could fit in the first.

  // Enable widow/orphan control, forbidding one or two lines on their own
   lf.Style.Keep=3;

In this case it is impossible to keep 3 lines together on each side of the frame skip, so the whole paragraph is started on the next frame. This is why Keep values are generally low – they quickly produce a lot of blank space at the end of frames.

Ensuring space available at the start of end of a paragraph

Here’s a example of a Title paragraph that fits right at the bottom of a frame. Its subject paragraph ends up on the next frame.


The Keep setting will not address this problem as no paragraph is split across frames. The ParagraphStyle class provides two properties that address it:

  • SpaceStarting: Space to bottom of frame that should be available at the start of the paragraph.
  • SpaceFollowing: Space to bottom of frame that should be available after the end of the paragraph.

See the visual glossary for an illustration.

  // Skip to next frame if less than 4 lines available at title font from start of paragraph
   title.SpaceStarting = -4;

Now a frame skip occurs to ensure that the Title paragraph has some room to flow a few paragraph lines right below it.

In the case of small paragraphs such as titles, the two properties are nearly equivalent. But they can be also be used on normal paragraphs that should be attached to upcoming inclusions. In the case of SpaceFollowing on long paragraphs, the frame skip will happen Keep lines before the end of the paragraph.

See also ...

Text Flow Tutorials | Flowing Paragraphs | Paragraph Glossary | SharpLeaf.Style Property | ParagraphStyle.Keep Property | ParagraphStyle.SpaceFollowing Property | ParagraphStyle.SpaceStarting Property


Send comments on this topic
© Dyalog Ltd 2016