These parts hold what applies to the whole document: how it is edited and laid out, which fonts it asks for, and the theme its colours and fonts draw on.
settings.xml
word/settings.xml has the root w:settings.
| Element | Meaning |
|---|---|
w:zoom | The zoom Word shows: w:percent. |
w:trackRevisions | Tracking of changes is on. |
w:documentProtection | Editing restrictions: w:edit (readOnly, comments, trackedChanges, forms), w:enforcement, and a password hash. This restricts editing in Word; it does not encrypt the file. |
w:defaultTabStop | The spacing of default tab stops, in twips. |
w:evenAndOddHeaders | Different headers on even and odd pages. |
w:updateFields | Update the fields when the document is opened. |
w:attachedTemplate | The template, by relationship ID. The relationship is often external. |
w:footnotePr, w:endnotePr | Note properties for the document, and which notes are the separators. |
w:compat | Compatibility settings, below. |
w:rsids | The list of editing sessions, used by the w:rsid… attributes. |
w:docVars | Named strings stored with the document: w:docVar. |
w:themeFontLang, w:clrSchemeMapping | Which theme fonts and colours apply to what. |
w:decimalSymbol, w:listSeparator | The characters to use in fields and calculations. |
Compatibility mode
w:compat holds settings that keep the layout of older documents. In files
from Word 2010 onwards, one of them says which version of Word’s rules apply:
<w:compat>
<w:compatSetting w:name="compatibilityMode"
w:uri="http://schemas.microsoft.com/office/word" w:val="15"/>
</w:compat>
| Value | Rules of |
|---|---|
| 12 | Word 2007 |
| 14 | Word 2010 |
| 15 | Word 2013 and later |
Language compatibility settings
ECMA-376 Part 1 §17.15.3 defines a last group of w:compat children that change
behaviour for some languages only. They sit in the document settings part. The specification
says they are usually set when the document is made in one of these languages: for
ja-JP, ko-KR, zh-CN, zh-SG, zh-TW, zh-HK, zh-MO and ii-CN, doNotLeaveBackslashAlone,
doNotExpandShiftReturn, balanceSingleByteDoubleByteWidth,
adjustLineHeightInTable, ulTrailSpace and spaceForUL;
for th-TH, lo-LA, km-KH, bo-CN and hy-AM, applyBreakingRules. Every one is a plain
on/off element (§17.17.4); absent means off.
| Element | When on |
|---|---|
w:adjustLineHeightInTable | The extra line pitch of a w:docGrid of type lines is also added to lines inside table cells. Normally it is not. |
w:applyBreakingRules | Legacy Ethiopic and Amharic line breaking: no break opportunity after a character between U+1361 and U+1368; a break that would fall after one happens before it. Normally a break is allowed after them. |
w:balanceSingleByteDoubleByteWidth | The half-width and full-width space of fixed-pitch fonts are adjusted to a 1 to 2 ratio. The change is very small. |
w:doNotExpandShiftReturn | A line that ends in a soft line break (w:br) is not fully justified in a justified paragraph, in the same way as the last line. |
w:doNotLeaveBackslashAlone | U+005C is displayed as the yen sign U+00A5. The stored character does not change. |
w:spaceForUL | For an underlined run that has East Asian characters and is not baseline-aligned, the larger of 3 percent of the font size and 40 twentieths of a point (31 for Japanese text) is added to the font descent. |
w:ulTrailSpace | Underlining is also drawn under trailing spaces at the end of a line. Normally it is not. |
w:compatSetting (§17.15.3.4) carries a named setting with w:name,
w:uri and w:val; its meaning belongs to whoever defines the namespace.
The earlier compatibility section of this page shows compatibilityMode in the Word
namespace.
What the viewer does
None of the seven elements is applied: the viewer does not read them. Documents that rely on them draw slightly differently from Word: lines in table cells lose the grid pitch, justified lines ending in a soft break are stretched, a backslash stays a backslash, and underline under trailing spaces and the extra descent for underlined East Asian text are not drawn. These rules need East Asian layout that the viewer does not have, so they stay unimplemented.
webSettings.xml
word/webSettings.xml holds settings for saving as a web page, such as
w:optimizeForBrowser and w:allowPNG, and the HTML division
information of documents that came from a web page.
The root is w:webSettings (ECMA-376 Part 1 §17.15.2.45). In the transitional
schema (CT_WebSettings in wml.xsd) the children come in this order, all
optional: w:frameset, w:divs, w:encoding,
w:optimizeForBrowser, w:relyOnVML, w:allowPNG,
w:doNotRelyOnCSS, w:doNotSaveAsSingleFile,
w:doNotOrganizeInFolder, w:doNotUseLongFileNames,
w:pixelsPerInch, w:targetScreenSz and w:saveSmartTagsAsXml.
Part 1 §17.15.2 has no section for w:relyOnVML; it appears only in the schema.
| Element | Meaning, and the default when it is absent |
|---|---|
w:encoding | The character set used when saving as a web page, as an IANA charset name. If the name is not known, the system default is used. |
w:optimizeForBrowser | Customise web output for a target profile named in w:target. The reserved values are W3C XHTML+CSS1, W3C HTML4+CSS1, W3C XHTML+CSS2 and W3C HTML4+CSS2; product names must not be used. With no target the HTML version is application-defined. |
w:allowPNG | PNG may be used as a graphic format in the saved page. |
w:doNotRelyOnCSS | Do not rely on CSS for font face formatting. |
w:doNotSaveAsSingleFile | Prefer the multi-file web page format over the single-file one. |
w:doNotOrganizeInFolder | Do not put supporting files in a subdirectory. |
w:doNotUseLongFileNames | File names must fit 8.3. |
w:pixelsPerInch | Pixels per inch for pictures and table cells in the saved page. Absent means 96. Typical range 19 to 480; common values 72, 96 and 120. |
w:targetScreenSz | Smallest screen the page is aimed at, as 800x600 style text. Absent means 800x600. |
w:saveSmartTagsAsXml | Also write smart tag data into an XML property bag in the head of the saved page. Absent means no. |
HTML division information
w:divs holds one w:div for each HTML div of the source page. A
w:div has a w:id, optional w:blockQuote and
w:bodyDiv flags (bodyDiv is ignored when blockQuote is also set,
and on any div that is not the main one), margins w:marLeft, w:marRight,
w:marTop and w:marBottom in twentieths of a point, a
w:divBdr with w:top, w:left, w:bottom and
w:right borders (the common border definition of §17.3.4), and nested
w:divsChild divs. Paragraphs and table rows point at a div through w:divId.
The specification says the div information shall be reflected in the formatting of the resulting
paragraphs. The example in §17.15.2.24 converts 100 px to 1500 twentieths of a point at 96 px per
inch.
Framesets
When w:frameset has at least one child frame or frameset, the document is only a frameset
definition and its normal content is not displayed (§17.15.2.19). The pieces:
| Element | Meaning |
|---|---|
w:frameLayout | rows, cols or none (ST_FrameLayout). Absent means the frames are stacked vertically. |
w:frame | One frame: w:sz, w:name, w:title, w:longDesc, w:sourceFileName, w:linkedToFile, w:marW, w:marH (pixels), w:scrollbar and w:noResizeAllowed. |
w:sz | Width for cols, height for rows, read against the parent frameset's layout. A trailing * is relative to the other frames, a trailing % is a percentage, and a plain number is pixels, converted through w:pixelsPerInch. On a root frameset it is ignored. |
w:sourceFileName | A relationship in the web settings part's own relationships file, of the frame type. Absent means the content is created as needed. |
w:longDesc | A hyperlink relationship to the long description of the frame. |
w:linkedToFile | Keep the link to the source file as written when the frameset is saved elsewhere. |
w:scrollbar | on, off or auto (ST_FrameScrollbar). Absent means show it only when needed. |
w:noResizeAllowed | The frame size is fixed in the saved page. Absent means it can be resized. |
w:framesetSplitbar | The splitters: w:w (width, default 90, which is 4.5 points), w:color, w:flatBorders and w:noBorder. Only the root frameset's values are honoured; w:noBorder switches all splitters off and the other splitter properties are then ignored. |
What the viewer does
The viewer lists the web settings part by name (as part of the package listing) but does not read
its contents. It does not apply w:divs (so div margins and borders are not drawn), does not
follow w:divId, and does not draw framesets: a document with a root frameset shows its normal
body, where the specification says the body is not displayed. Settings that only act when saving as a
web page (encoding, file naming, PNG, pixels per inch, target screen, smart tags) have no effect
in a viewer.
The font table
word/fontTable.xml describes each font the document uses, so that another
computer can find a match. It does not hold the fonts themselves.
<w:font w:name="Calibri">
<w:panose1 w:val="020F0502020204030204"/>
<w:charset w:val="00"/>
<w:family w:val="swiss"/>
<w:pitch w:val="variable"/>
</w:font>
| Child element | Meaning |
|---|---|
w:altName | Another name for the font. |
w:panose1 | The PANOSE classification, used to find similar fonts. |
w:charset | The character set. |
w:family | roman, swiss, modern, script, decorative or auto. |
w:pitch | variable, fixed or default. |
w:sig | Unicode and code page signature of the font. |
w:embedRegular, w:embedBold, w:embedItalic, w:embedBoldItalic | An embedded font: a relationship ID and a w:fontKey. |
An embedded font is an .odttf part in word/fonts/, which is a
font file with its first 32 bytes XOR-ed with the key.
The rules, from ECMA-376 Part 1 §17.8
w:fontsis the root of the part. There is onew:fontfor each face used in the document, and itsw:namelinks it tow:rFontsin the content.w:altNameis a comma-separated list of other names, tried in turn when the primary name is not found. Adjacent commas are ignored. The names are in the encoding of the part's XML declaration.w:charsethas the attributew:characterSet(an IANA name such asGBK). The spec's own example uses that form; the transitional schema also allowsw:val, a one-byte hexadecimal number, as in the sample above. With no element, ISO/IEC 8859-1 is assumed.w:familyisdecorative,modern,roman,script,swissorauto(defaultauto).w:pitchisfixed,variableordefault(defaultdefault).w:panose1is the PANOSE number of ISO/IEC 14496-22 §5.2.7.17, written as ten two-digit hexadecimal bytes;020F0603050405020304means 2, 15, 6, 3, 5 and so on.w:sighasw:usb0tow:usb3(Unicode ranges) andw:csb0,w:csb1(code pages), in the form of the OpenType OS/2 table (§5.2.7.18 and §5.2.7.28). A Unicode range bit is set only when the font supports the whole range.w:notTrueTypemarks a font without TrueType outlines; without it TrueType is assumed.- The four
w:embed...elements carryr:id(a relationship of the font type),w:fontKey(a GUID) andw:subsetted(the font holds only the glyphs the document uses). - In the settings part,
w:embedTrueTypeFontsasks the writer to embed the fonts in use;w:embedSystemFontsadds the common system fonts andw:saveSubsetFontssubsets them. The last two have no effect unlessw:embedTrueTypeFontsis on.
Un-obfuscating an embedded font
Section 17.8.1 gives the method. Take the GUID of w:fontKey and reverse the order of its
bytes. XOR the first 16 bytes of the font part with that, then XOR bytes 16 to 31 with it again. The
rest of the file is unchanged. The spec's example key
001B70DC-AA60-4AD5-90EC-18A0948E1EAE becomes AE1E8E94-A018-EC90-D54A-60AADC701B00
in the XOR. Writing is the same operation. The result is for viewing the document only.
Font substitution
When the named font is missing, §17.8.2 recommends matching in this order of priority: sig,
charset, panose1, pitch, family,
altName, notTrueType. Applications may use better logic.
What the viewer does
The Overview “Fonts” table lists every font of the font table with its family, pitch, character set,
Panose-1 number, alternate names, w:sig bit fields, w:notTrueType and each
embed* element (target part, fontKey, subsetted), as stored (test “fonts: panose, alternate names, signature, notTrueType and embedded font keys are listed”). Each embedded font part is un-obfuscated with its fontKey as described above; the table says
“deobfuscated: TrueType, N bytes” (or OpenType (CFF), TrueType collection), “stored without obfuscation” when the part is already a font, or that the key does
not give a font file. A font the page view uses by name is loaded into the page images with @font-face from the
undone bytes; the test unscrambles a stand-in font with the spec example's key written out as bytes and finds the same bytes in the page. A font over 400 KB, or one past 4 MB of font data in all (the data is repeated in every page image), is left out with a note. The glyphs are not drawn in a test, but the un-obfuscation was run on a real file: the Apache POI test document saut_page.docx carries 16 obfuscated fonts (Times New Roman, Arial, Liberation Serif and others, regular, bold, italic and bold italic); every part comes out as a TrueType file, and fontconfig's fc-scan, an independent reader, names the family from the font table with the weight and slant of its embed* element (80 checks, test-docx-embedfont.mjs). The stand-in font of test-docx-built has only the sfnt tag of a TrueType file. The viewer does not try
alternate names, and does not match substitutes by PANOSE, signature or family. Where no font is embedded, text is drawn in the
browser's own choice of font for the name in w:rFonts, so line breaks can differ from
Word where the font is not installed.
The same Overview shows the web page settings part: a table “Web page settings” lists every element of
word/webSettings.xml as stored, to a depth of eight levels so that nested w:div trees under
w:divsChild are included (test “settings: web page settings (17.15.2) are listed”). They steer how Word saves the document as a web page, so the page view does not act on them.
The theme
word/theme/theme1.xml, reached by the theme relationship, is a
DrawingML part with the root a:theme and a:themeElements:
| Element | Holds |
|---|---|
a:clrScheme | The colours: dk1, lt1, dk2, lt2, accent1 to accent6, hlink, folHlink. |
a:fontScheme | Heading and body fonts: a:majorFont and a:minorFont, with a typeface for each script. |
a:fmtScheme | Line, fill and effect styles for shapes. |
Styles refer to these through attributes such as w:themeColor and
w:asciiTheme, so changing the theme changes the document’s look.
The rules, from ECMA-376 Part 1 §20.1
a:theme(§20.1.6.9) has anameand holdsa:themeElements(§20.1.6.10), which holds the colour scheme, font scheme and format scheme, in that order.a:objectDefaults(default shape, line and text box formatting, §20.1.6.7),a:extraClrSchemeLst(extra schemes with their own colour maps, kept for backward compatibility, §20.1.6.4 and §20.1.6.5) anda:custClrLst(a custom palette, §20.1.6.3) follow.a:themeOverride(§20.1.6.12) changes the colours, fonts or effects of a single object, and Part 1 says it is used only for non-top-level masters of a presentation.a:clrScheme(§20.1.6.2) always lists twelve colours in a fixed order: index 0 to 11 aredk1,lt1,dk2,lt2,accent1toaccent6,hlinkandfolHlink. Each holds one colour, for examplea:sysClr(windowTextorwindow) ora:srgbClr. Itsnamemay appear in a user interface.- Word does not use the scheme names directly in
w:themeColor. The first four,dark1,light1,dark2andlight2, name the scheme colours.text1,background1,text2andbackground2go throughw:clrSchemeMappingin the settings part, which is the document's own version of the colour map (§20.1.6.1:bg1,tx1,bg2,tx2and the accents each point at a scheme colour, so light and dark can be swapped). a:fontScheme(§20.1.4.1.18) has aname, aa:majorFontfor headings and aa:minorFontfor body text. Each holdsa:latin,a:eaanda:csfaces, and any number ofa:fontelements, each pairing an ISO 15924script(Jpan,Hang,Araband so on) with atypeface.a:fmtScheme(§20.1.4.1.14) is the style matrix:a:fillStyleLst,a:lnStyleLst,a:effectStyleLstanda:bgFillStyleLst. The first three each list a subtle, a moderate and an intense style; a shape picks one of each by index (a:lnRef,a:fillRef,a:effectRef, anda:fontRefwithidxofmajororminor). Inside a style, the colourphClrstands for the colour of the referencing shape.
What the viewer does
The viewer reads the twelve scheme colours (the a:srgbClr value, or the
lastClr of an a:sysClr) and the w:clrSchemeMapping, and turns
w:themeColor with w:themeTint and w:themeShade into a colour for
text, borders and shading. For fonts it reads only the a:latin face of the major and the
minor font; every theme font attribute, including the East Asian and complex script ones, is
replaced by that one face. It does not read a:ea, a:cs or the
per-script a:font list, and does not use the format scheme, a:objectDefaults,
the extra colour schemes, the custom colour list or a theme override. A shape's
a:schemeClr fill is looked up in the scheme with tx1, tx2,
bg1 and bg2 taken as dk1, dk2, lt1
and lt2 (the colour map is not applied there), and a name it does not know gives grey.
Shapes that point into the style matrix with a:lnRef, a:fillRef or
a:effectRef are not followed: the viewer has no code for those references, so such a shape
takes its line, fill and effect from its own properties only.
Settings in detail
Compared with ECMA-376 Part 1 §17.15.1, the transitional schema (CT_Settings
in wml.xsd) and the implementation notes in MS-OI29500 §2.1.383–2.1.452.
w:settings is a sequence of more than a hundred optional children and the order is
fixed. The ones this page covers come in this order: w:writeProtection,
w:view, w:zoom, w:trackRevisions,
w:documentProtection, w:defaultTabStop,
w:evenAndOddHeaders, w:updateFields, w:footnotePr,
w:endnotePr, w:compat, w:docVars,
w:rsids, m:mathPr, w:themeFontLang,
w:clrSchemeMapping, w:shapeDefaults,
w:decimalSymbol, w:listSeparator.
| Element | Attributes and values | Default when omitted |
|---|---|---|
w:zoom (§17.15.1.94) | w:val optional: none, fullPage, bestFit, textFit. w:percent is required in the schema and is a whole number with a percent sign, for example 71%. If both are present, w:percent is only used when w:val is none. | Any magnification the application likes. A missing w:val counts as none. |
w:trackRevisions (§17.15.1.89) | On/off. | Changes are not tracked. |
w:documentProtection (§17.15.1.29) | w:edit: none, readOnly, comments, trackedChanges, forms. w:enforcement and w:formatting are on/off. The password check uses w:algorithmName (MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-256, SHA-384, SHA-512, WHIRLPOOL), w:hashValue and w:saltValue (base64) and w:spinCount. The transitional schema also allows the older w:cryptProviderType, w:cryptAlgorithmClass, w:cryptAlgorithmType, w:cryptAlgorithmSid, w:cryptSpinCount, w:cryptProvider, w:algIdExt, w:algIdExtSource, w:cryptProviderTypeExt, w:cryptProviderTypeExtSource, w:hash and w:salt. | No protection. Without w:edit, no editing restriction. |
w:defaultTabStop (§17.15.1.25) | w:val in twips (twentieths of a point). | 720 twips (0.5 inch). Automatic tab stops come at multiples of the value after the last custom stop. |
w:themeFontLang (§17.15.1.88) | w:val (Latin text), w:eastAsia, w:bidi: language tags that pick the script entry in the theme’s a:majorFont or a:minorFont. | The a:latin, a:ea and a:cs fonts of the theme. |
w:compat (§17.15.1.21) | Holds flag children and w:compatSetting children, whose w:name, w:uri and w:val are all optional strings in the schema. | No compatibility settings. |
w:docVars | w:docVar with required w:name and w:val. | None. |
Divergence from spec
- Zoom. The schema requires
w:percent; Word does not always write it, and treats0as omitted. Word 2013 ignoresw:zoomwhen it reads a document (MS-OI29500 §2.1.427). Apache POI reads a missing percent as 100 and divides a parsed percent by 1000 (XWPFSettings.javalines 94–103). - Tab stop range. The standard gives an unsigned long; Word stores a short with a minimum of 0 (MS-OI29500 §2.1.399).
- Protection. The standard says a missing
w:enforcementmeans “not enforced”; Word enforces when it is missing. The salt is prepended, as binary bytes, not as the base64 text. The first hash of password plus salt is not counted inw:spinCount, and Word accepts 0 to 10,000,000 (MS-OI29500 §2.1.402 a–e). Word uses the modernw:algorithmNameform when the registry valueUseIsoPasswordVerifieris 1 (§2.1.402 f). Apache POI writes the older form with spin count 100000 (XWPFSettings.javalines 276–290) and refuses to check a spin count above the agile-encryption maximum (lines 310–311). - Update on open. Word does not keep
w:updateFieldsin every save (MS-OI29500 §2.1.424). - Theme font languages. When
w:themeFontLangis missing, Word works the default out from the Office install language and the installed keyboards, not from the theme (MS-OI29500 §2.1.423). - python-docx has an element class only for
w:settings, with the full child order (_tag_seq) and one property,evenAndOddHeaders(pydocx-oxml-settings.pylines 13–133). POI exposes zoom percent, document protection, track revisions, even and odd headings, mirror margins and update fields. - docx4j (
docx4j-DocumentSettingsPart.java). Compatibility settings in the Word namespace (http://schemas.microsoft.com/office/word) are looked up byw:name(lines 147–168);overrideTableStyleFontSizeAndJustificationcounts as on for1,trueoryesand as off when missing (lines 202–215), while the setter replaces the wholew:compatelement (lines 170–177). Legacy password hashing mapsw:cryptAlgorithmSid1 to MD2, 2 MD4, 3 MD5, 4 SHA-1, 12 SHA-256, 13 SHA-384 and 14 SHA-512, with provider type RSA_FULL for 1 to 4 and RSA_AES for 12 to 14 (lines 353–387), a 16-byte random salt and a spin count of 100000 (lines 390–395); the check reads the same table (lines 430–455). Tracked-changes protection also setsw:trackRevisions, because Word 2010 does not enforce it otherwise (lines 317–323).w:attachedTemplateis written as an external relationship (lines 494–527). The part declaresw14ignorable whenw14:docId,w:conflictMode,w:discardImageEditingDataorw:defaultImageDpiis present, andw15forw15:chartTrackingRefBasedorw15:docId(lines 101–131). docx4j’sCommentsPartandDocPropsCorePartadd nothing beyond part name, content type and relationship type;DocPropsCorePartdisables DTDs and external entities when reading.
The page viewer reads three settings: w:evenAndOddHeaders (which header the even pages use) and w:defaultTabStop (default 720) at pages.js lines 134–135, and w:clrSchemeMapping, which maps theme colour names such as bg1 and tx1 to the scheme (props.js line 223). It does not act on w:zoom (the window zoom of the saving application, 17.15.1.94: the pages are drawn at 100 percent; Word 2013 itself ignores it when it reads a document, MS-OI29500 §2.1.427, so not applying it matches Word), protection (it restricts editing, nothing to draw), w:themeFontLang or the compatibility flags; page layout always follows the mode-15 rules. Every element of the settings part, with its attributes and text, to four levels deep, is listed in the Overview tab under “Settings (every element in word/settings.xml)”, so these values are shown even where they are not applied (test “settings: zoom, protection, themeFontLang and compat settings are listed”). The explorer’s document summary lists the compatibility mode, protection, attached template and track-changes state (word.js lines 725–728). Its schema check knows one writer fault: w:themeFontLang with a w:fareast attribute, where the schema says w:eastAsia (schema.js line 31).