Table of Contents

Drop caps

A drop cap is a paragraph's first letter set large, beside its first lines (Word's Insert > Drop Cap). DocWright lays out Word's drop caps where Word draws them, and gives, changes and takes away a drop cap as Word's dialog does, each one undo step.

using DocWright.Core.Primitives;
using DocWright.Dom;
using DocWright.Dom.Editing;
using DocWright.Layout;

var settings = new DropCapSettings
{
    Position = TextFrameDropCap.Drop,      // or Margin: left of the text
    Lines = 3,                             // 1 to 10, Word's default 3
    Distance = new Twips(0),               // from the text
    FontFamily = null,                     // the text's font, or one chosen
};

DropCapGeometry geometry = DropCapMeasurer.Measure(document, paragraph, settings, fontEngine);
DocumentEdit edit = document.SetDropCap(DocumentPosition.StartOf(paragraph), paragraph, settings, geometry);

DropCap? cap = document.ReadDropCap(paragraph);                    // from the paragraph or the cap's own
document.RemoveDropCap(DocumentPosition.StartOf(paragraph), paragraph);   // Drop Cap: None
  • The dropped text is the paragraph's leading quotes or brackets and its first letter (“O), moved into a framed paragraph of its own before the rest, written as Word writes it.
  • DropCapMeasurer gives Word's numbers: the cap's size makes the letter's glyph run from the top of the first line to the last line's baseline, its lowering puts the glyph's bottom on that baseline, and its line is as tall as the lines it spans. They are measured from the faces the engine draws with.
  • The text beside the cap starts after it and its distance, for the lines it spans; a cap in the margin ends at the margin and takes nothing from the text.
  • SetDropCap on a paragraph that has a cap changes it; RemoveDropCap puts the letter back, without the cap's size.

Lines with exact spacing have their baseline four fifths of the way down, as Word puts it; that is where a drop cap's letter stands in its line.