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.

Remarks

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

NameDescription
all_capsTrue if the font is formatted as all capital letters.
auto_colorReturns 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.
bidiSpecifies whether the contents of this run shall have right-to-left characteristics.
boldTrue if the font is formatted as bold.
bold_biTrue if the right-to-left text is formatted as bold.
borderReturns a Border object that specifies border for the font.
colorGets or sets the color of the font.
complex_scriptSpecifies 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_throughTrue if the font is formatted as double strikethrough text.
embossTrue if the font is formatted as embossed.
emphasis_markGets or sets the emphasis mark applied to this formatting.
engraveTrue if the font is formatted as engraved.
fillGets fill formatting for the Font.
hiddenTrue if the font is formatted as hidden text.
highlight_colorGets or sets the highlight (marker) color.
italicTrue if the font is formatted as italic.
italic_biTrue if the right-to-left text is formatted as italic.
kerningGets or sets the font size at which kerning starts.
line_spacingReturns line spacing of this font (in points).
locale_idGets or sets the locale identifier (language) of the formatted characters.
locale_id_biGets or sets the locale identifier (language) of the formatted right-to-left characters.
locale_id_far_eastGets or sets the locale identifier (language) of the formatted Asian characters.
nameGets or sets the name of the font.
name_asciiReturns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
name_biReturns or sets the name of the font in a right-to-left language document.
name_far_eastReturns or sets an East Asian font name.
name_otherReturns or sets the font used for characters with character codes from 128 through 255.
no_proofingTrue when the formatted characters are not to be spell checked.
outlineTrue if the font is formatted as outline.
positionGets 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.
scalingGets or sets character width scaling in percent.
shadingReturns a Shading object that refers to the shading formatting for the font.
shadowTrue if the font is formatted as shadowed.
sizeGets or sets the font size in points.
size_biGets or sets the font size in points used in a right-to-left document.
small_capsTrue if the font is formatted as small capital letters.
snap_to_gridSpecifies whether the current font should use the document grid characters per line settings when laying out.
spacingReturns or sets the spacing (in points) between characters .
strike_throughTrue if the font is formatted as strikethrough text.
styleGets or sets the character style applied to this formatting.
style_identifierGets or sets the locale independent style identifier of the character style applied to this formatting.
style_nameGets or sets the name of the character style applied to this formatting.
subscriptTrue if the font is formatted as subscript.
superscriptTrue if the font is formatted as superscript.
text_effectGets or sets the font animation effect.
theme_colorGets or sets the theme color in the applied color scheme that is associated with this Font object.
theme_fontGets or sets the theme font in the applied font scheme that is associated with this Font object.
theme_font_asciiGets 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_biGets 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_eastGets or sets the East Asian theme font in the applied font scheme that is associated with this Font object.
theme_font_otherGets 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_shadeGets or sets a double value that lightens or darkens a color.
underlineGets or sets the type of underline applied to the font.
underline_colorGets or sets the color of the underline applied to the font.

Methods

NameDescription
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=doc)
builder.font.border.color = aspose.pydrawing.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(file_name=ARTIFACTS_DIR + 'Border.FontBorder.docx')

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

doc = aw.Document()
run = aw.Run(doc=doc, text='Hello world!')
font = run.font
font.name = 'Courier New'
font.size = 36
font.highlight_color = aspose.pydrawing.Color.yellow
doc.first_section.body.first_paragraph.append_child(run)
doc.save(file_name=ARTIFACTS_DIR + 'Font.CreateFormattedRun.docx')

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

doc = aw.Document()
builder = aw.DocumentBuilder(doc=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(list_template=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(file_name=ARTIFACTS_DIR + 'Styles.ParagraphStyleBulletedList.docx')

See Also