Skip to content

theme

theme

Custom element classes for the theme part, word/theme/theme1.xml.

Only the two subtrees that a word-processing document actually resolves against are modelled: a:fontScheme, which is where a theme typeface such as minorHAnsi turns into a real font name, and a:clrScheme, which is where a theme colour turns into an RGB value. a:fmtScheme — the fill, line and effect matrices — is a drawing-formatting model of its own and is left as opaque XML.

CT_TextFont

Bases: BaseOxmlElement

a:latin, a:ea and a:cs, each naming one typeface of a font collection.

CT_FontCollection

Bases: BaseOxmlElement

a:majorFont or a:minorFont, the typefaces of one half of the font scheme.

a:latin is the one a w:rFonts/@w:asciiTheme of majorHAnsi or minorHAnsi resolves to; a:ea and a:cs serve the East Asian and complex-script slots.

typeface_for

typeface_for(script: str) -> str | None

The typeface for script, one of "latin", "ea" or "cs".

None when the slot carries the empty typeface Word writes to mean "no override", which is what a:ea and a:cs hold in the default Office theme.

Source code in src/docx/oxml/theme.py
def typeface_for(self, script: str) -> str | None:
    """The typeface for `script`, one of `"latin"`, `"ea"` or `"cs"`.

    |None| when the slot carries the empty typeface Word writes to mean "no
    override", which is what `a:ea` and `a:cs` hold in the default Office theme.
    """
    textFont = getattr(self, script)
    return textFont.typeface or None

CT_FontScheme

Bases: BaseOxmlElement

a:fontScheme, the major and minor font collections of a theme.

CT_SRgbColor

Bases: BaseOxmlElement

a:srgbClr, a colour given as an explicit RGB value.

CT_SystemColor

Bases: BaseOxmlElement

a:sysClr, a colour taken from the operating system's palette.

@lastClr is the RGB value the producing application last resolved it to, which is the only concrete value available to a consumer that is not the operating system in question.

CT_ThemeColor

Bases: BaseOxmlElement

One slot of a:clrScheme, e.g. a:accent1.

The colour itself is one of several child element types; only the two Word writes for a theme are modelled.

rgb property

rgb: RGBColor | str | None

The RGB value of this colour slot, or None when there is none to give.

A system colour reports the @lastClr the producing application resolved it to; that is the closest thing to a concrete value a consumer outside that operating system can have.

CT_ColorScheme

Bases: BaseOxmlElement

a:clrScheme, the twelve theme colours.

color

color(slot: str) -> CT_ThemeColor | None

The a:{slot} child, or None when the scheme does not define it.

Source code in src/docx/oxml/theme.py
def color(self, slot: str) -> CT_ThemeColor | None:
    """The `a:{slot}` child, or |None| when the scheme does not define it."""
    from docx.oxml.ns import qn

    return self.find(qn("a:%s" % slot))  # pyright: ignore[reportReturnType]

CT_BaseStyles

Bases: BaseOxmlElement

a:themeElements, the part of a theme that documents resolve against.

CT_OfficeStyleSheet

Bases: BaseOxmlElement

a:theme, the root element of a theme part.