Table of Contents

Class FormattingEditingExtensions

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

Formatting, styles and lists applied to a DocumentSpan as DocumentEdits: each can be undone exactly and names the paragraphs it changed, as the text edits of TextEditingExtensions do.

public static class FormattingEditingExtensions
Inheritance
FormattingEditingExtensions
Inherited Members

Remarks

  • A span runs in document order from its start to its end and may cross paragraphs, table cells and sections. Paragraphs in a header, a footer, a note or a shape's text box that lie between its ends (but hold neither) are not part of it.
  • Character formatting reaches the text, tabs, breaks and other run content the span covers; a text run the span starts or ends inside is split there. A field's result is formatted, its code is not. A paragraph's mark is formatted when the span runs past it into the next paragraph, and an empty paragraph's mark when the span is the empty point in it (so text typed there takes the formatting).
  • Every changed object gets a changed copy of its format bag; the original bag is what Undo() puts back. An object whose bag comes out equal (as ContentEquals judges) is left untouched, so applying formatting that is already there changes nothing and the edit is empty.

Methods

ApplyCharacterStyle(WordDocument, DocumentSpan, string?)

Applies a character style to the content a span covers; direct formatting stays.

ApplyList(WordDocument, DocumentSpan, ListKind)

Puts every paragraph a span touches in a list of kind. The list of the first paragraph, or else of the paragraph before it, is continued when it is of that kind; otherwise a list is added to the document from Word's default template for the kind. A paragraph keeps its list level (0 when it had none).

ApplyListTemplate(WordDocument, DocumentSpan, ListTemplate)

Puts every paragraph a span touches in a list defined by a template (Word's galleries: ListLibrary), as one edit: a new list from the template, unless the paragraph before the span is in a list made from the same template, which is continued. A paragraph keeps its list level (0 when it had none).

ApplyParagraphStyle(WordDocument, DocumentSpan, string?)

Applies a paragraph style to every paragraph a span touches; direct formatting stays.

ChangeListLevel(WordDocument, DocumentSpan, int)

Moves every listed paragraph a span touches delta levels deeper (positive) or shallower (negative), within levels 0 to 8. Paragraphs in no list are left as they are.

ContinueNumbering(WordDocument, Paragraph)

Continues the previous list's numbering at a paragraph (Word's Continue Numbering): the paragraph and the rest of its list from there join the nearest list before it with the same definition. Nothing changes when there is none.

FormatParagraphs(WordDocument, DocumentSpan, Action<ParagraphFormat>)

Changes the paragraph formatting of every paragraph a span touches.

FormatSections(WordDocument, DocumentSpan, Action<SectionFormat>)

Changes the section formatting (page size, orientation, margins, columns …) of every section a span touches, as Word's page setup does for the sections a selection covers.

FormatSettings(WordDocument, DocumentPosition, Action<DocumentSettings>)

Changes the document's settings (settings.xml: different odd and even pages, default tab stop, …) as one undoable edit. The change runs on a copy that replaces the settings; undo puts the instance back.

FormatText(WordDocument, DocumentSpan, Action<CharacterFormat>)

Changes the character formatting of the content a span covers.

GetCoveredParagraphs(DocumentSpan)

Returns what a span covers, paragraph by paragraph in document order, as FormatText(WordDocument, DocumentSpan, Action<CharacterFormat>) reaches it: the direct character formatting of each piece of run content and whether the paragraph's mark is covered. For an empty span the one entry is the formatting text typed there takes, as InsertText(WordDocument, DocumentPosition, string, CharacterFormat?) gives it. A style resolver turns these into the formatting in effect (StyleResolver.ResolveSpanFormatting).

RemoveList(WordDocument, DocumentSpan)

Takes every paragraph a span touches out of its list. A paragraph whose style puts it in a list is given the explicit "no list" (w:numId 0) Word writes; any other loses its list properties.

RestartNumbering(WordDocument, Paragraph, int)

Restarts a list's numbering at a paragraph (Word's Restart at 1, Set Numbering Value): the paragraph and the rest of its list from there go to a new list instance of the same definition whose level starts at the value given.

SetPageColor(WordDocument, DocumentPosition, DocColor?)

Sets the page colour, Design > Page Color, as one undoable edit (WQ-0101): the document's background (w:background) and, for a colour, w:displayBackgroundShape, which Word writes with it and without which the colour is not painted. A null colour (No Color) removes the background and leaves the setting.