public static void ApplyStyle(this Document document, IDocumentStyle documentStyle, Document defaultPropertiesProvider = null) { defaultPropertiesProvider ??= document; if (documentStyle.DocumentStyleType == DocumentStyleType.Paragraph) { document.BeginUpdate(); var paragraphFromPosition = document.ParagraphFromPosition(); document.Paragraphs[paragraphFromPosition].Style = (ParagraphStyle)documentStyle.Get(document, defaultPropertiesProvider); document.EndUpdate(); } else { var range = document.WordFromPosition(); var charProps = document.BeginUpdateCharacters(range); charProps.Style = (CharacterStyle)documentStyle.Get(document, defaultPropertiesProvider); document.EndUpdateCharacters(charProps); } }
public static bool Ensure(this IDocumentStyle documentStyle, Document document, IDocumentStyle[] usedStyles = null, Document defaultPropertiesProvider = null) { defaultPropertiesProvider ??= document; usedStyles ??= document.UsedStyles(documentStyle.DocumentStyleType, defaultPropertiesProvider).ToArray(); if (usedStyles.Contains(documentStyle)) { return(false); } documentStyle.Get(document, defaultPropertiesProvider); return(true); }