Values with two spellings
WordprocessingML spells some values two ways that mean the same thing: the Transitional left and the Strict start, lrTb and tb. A document DocWright reads and saves keeps the spelling it had, so typing in one paragraph leaves every other paragraph exactly as it was.
Spell a value, read it back, edit, save
using DocWright.Core.Document;
using DocWright.Core.Primitives;
using DocWright.Dom;
using DocWright.Dom.Editing;
var converter = new DocWrightConverter();
using var document = new WordDocument();
document.AppendParagraph("Typed into");
Paragraph quote = document.AppendParagraph("Indented from the leading edge");
quote.Format.Alignment = ParagraphAlignment.End; // w:jc "end", not "right"
quote.Format.IndentLeft = new Twips(720);
quote.Format.IndentSpelling = MarkupSpelling.Strict; // w:ind w:start, not w:left
using var saved = new MemoryStream();
converter.Save(document, saved, ".docx");
// Read it back, type into the first paragraph and take the typing out again.
saved.Position = 0;
using WordDocument reloaded = converter.Load(saved);
Paragraph first = reloaded.Sections[0].Blocks.OfType<Paragraph>().First();
DocumentEdit typed = reloaded.InsertText(DocumentPosition.EndOf(first), "!");
reloaded.DeleteRange(new DocumentSpan(typed.Before, typed.After));
ParagraphFormat format = reloaded.Sections[0].Blocks.OfType<Paragraph>().ElementAt(1).Format;
Console.WriteLine(format.Alignment + ", " + format.IndentSpelling + ", " + format.IndentLeft);
using var resaved = new MemoryStream();
converter.Save(reloaded, resaved, ".docx");
Output
End, Strict, 720tw
every part unchanged: True
The last line compares every part of the two saves byte for byte.
Where each spelling is kept
| Value | Spellings | Kept on |
|---|---|---|
w:jc, w:tab |
start/end or left/right |
Distinct members: ParagraphAlignment.Start and .Left, TabStopKind.Start and .Left |
w:ind |
w:start/w:end or w:left/w:right |
ParagraphFormat.IndentSpelling |
| Border and cell-margin sides | w:start/w:end or w:left/w:right elements |
Spelling on ParagraphBorders, TableBorders, CellBorders, TableCellMargins |
w:textDirection |
tb, rl, lr, tbV, rlV, lrV or lrTb, tbRl, btLr, lrTbV, tbRlV, tbLrV |
TextDirectionSpelling on CellFormat and SectionFormat |
w:tblLook |
the w:val bit mask, the six attributes, or both |
TableLook.Spelling |
Rules
- Spelling is not meaning. Style resolution, layout, PDF and image output read the value alone, and every comparison ignores the spelling.
Clonecopies it. - A document built in memory gets the Transitional spelling unless you set one, which is what DocWright wrote before.
- An ISO/IEC 29500 Strict package is read through the SDK's Strict-to-Transitional translation and saved in the Transitional spelling.
- Not kept: the on/off spelling (
"on"and"true"are written"1"), the order of a property element's attributes, and aw:tblLookbit mask that contradicts its own attributes.
An attribute DocWright does not model on a property element, such as w:ind w:startChars or w:spacing w:beforeLines, is kept on its element and written after the modelled attributes, so an edit to the modelled values still reaches the file. UnknownXml.UnmappedAttributes names them.