Font class

Font class

Contains font attributes (font name, font size, color, and so on) for an object. To learn more, visit the Working with Fonts documentation article.

You do not create instances of the Font class directly. You just use Font to access the font properties of the various objects such as Run, Paragraph, Style, DocumentBuilder.

Properties

Name Description
all_caps True if the font is formatted as all capital letters.
auto_color Returns the present calculated color of the text (black or white) to be used for ‘auto color’. If the color is not ‘auto’ then returns Font.color.
bidi Specifies whether the contents of this run shall have right-to-left characteristics.
bold True if the font is formatted as bold.
bold_bi True if the right-to-left text is formatted as bold.
border Returns a Border object that specifies border for the font.
color Gets or sets the color of the font.
complex_script Specifies whether the contents of this run shall be treated as complex script text regardless of their Unicode character values when determining the formatting for this run.
double_strike_through True if the font is formatted as double strikethrough text.
emboss True if the font is formatted as embossed.
emphasis_mark Gets or sets the emphasis mark applied to this formatting.
engrave True if the font is formatted as engraved.
fill Gets fill formatting for the Font.
hidden True if the font is formatted as hidden text.
highlight_color Gets or sets the highlight (marker) color.
italic True if the font is formatted as italic.
italic_bi True if the right-to-left text is formatted as italic.
kerning Gets or sets the font size at which kerning starts.
line_spacing Returns line spacing of this font (in points).
locale_id Gets or sets the locale identifier (language) of the formatted characters.
locale_id_bi Gets or sets the locale identifier (language) of the formatted right-to-left characters.
locale_id_far_east Gets or sets the locale identifier (language) of the formatted Asian characters.
name Gets or sets the name of the font.
name_ascii Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
name_bi Returns or sets the name of the font in a right-to-left language document.
name_far_east Returns or sets an East Asian font name.
name_other Returns or sets the font used for characters with character codes from 128 through 255.
no_proofing True when the formatted characters are not to be spell checked.
outline True if the font is formatted as outline.
position Gets or sets the position of text (in points) relative to the base line. A positive number raises the text, and a negative number lowers it.
scaling Gets or sets character width scaling in percent.
shading Returns a Shading object that refers to the shading formatting for the font.
shadow True if the font is formatted as shadowed.
size Gets or sets the font size in points.
size_bi Gets or sets the font size in points used in a right-to-left document.
small_caps True if the font is formatted as small capital letters.
snap_to_grid Specifies whether the current font should use the document grid characters per line settings when laying out.
spacing Returns or sets the spacing (in points) between characters .
strike_through True if the font is formatted as strikethrough text.
style Gets or sets the character style applied to this formatting.
style_identifier Gets or sets the locale independent style identifier of the character style applied to this formatting.
style_name Gets or sets the name of the character style applied to this formatting.
subscript True if the font is formatted as subscript.
superscript True if the font is formatted as superscript.
text_effect Gets or sets the font animation effect.
theme_color Gets or sets the theme color in the applied color scheme that is associated with this Font object.
theme_font Gets or sets the theme font in the applied font scheme that is associated with this Font object.
theme_font_ascii Gets or sets the theme font used for Latin text (characters with character codes from 0 (zero) through 127) in the applied font scheme that is associated with this Font object.
theme_font_bi Gets or sets the theme font in the applied font scheme that is associated with this Font object in a right-to-left language document.
theme_font_far_east Gets or sets the East Asian theme font in the applied font scheme that is associated with this Font object.
theme_font_other Gets or sets the theme font used for characters with character codes from 128 through 255 in the applied font scheme that is associated with this Font object.
tint_and_shade Gets or sets a double value that lightens or darkens a color.
underline Gets or sets the type of underline applied to the font.
underline_color Gets or sets the color of the underline applied to the font.

Methods

Name Description
clear_formatting() Resets to default font formatting.
has_dml_effect(dml_effect_type) Checks if particular DrawingML text effect is applied.

Examples

Shows how to insert a string surrounded by a border into a document.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.font.border.color = drawing.Color.green
builder.font.border.line_width = 2.5
builder.font.border.line_style = aw.LineStyle.DASH_DOT_STROKER

builder.write("Text surrounded by green border.")

doc.save(ARTIFACTS_DIR + "Border.font_border.docx")

Shows how to format a run of text using its font property.

doc = aw.Document()
run = aw.Run(doc, "Hello world!")

font = run.font
font.name = "Courier New"
font.size = 36
font.highlight_color = drawing.Color.yellow

doc.first_section.body.first_paragraph.append_child(run)
doc.save(ARTIFACTS_DIR + "Font.create_formatted_run.docx")

Shows how to create and use a paragraph style with list formatting.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

# Create a custom paragraph style.
style = doc.styles.add(aw.StyleType.PARAGRAPH, "MyStyle1")
style.font.size = 24
style.font.name = "Verdana"
style.paragraph_format.space_after = 12

# Create a list and make sure the paragraphs that use this style will use this list.
style.list_format.list = doc.lists.add(aw.lists.ListTemplate.BULLET_DEFAULT)
style.list_format.list_level_number = 0

# Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder.paragraph_format.style = style
builder.writeln("Hello World: MyStyle1, bulleted list.")

# Change the document builder's style to one that has no list formatting and write another paragraph.
builder.paragraph_format.style = doc.styles.get_by_name("Normal")
builder.writeln("Hello World: Normal.")

builder.document.save(ARTIFACTS_DIR + "Styles.paragraph_style_bulleted_list.docx")

See Also