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
allCapsTrue if the font is formatted as all capital letters.
autoColorReturns 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.
boldBiTrue 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.
complexScriptSpecifies 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.
doubleStrikeThroughTrue if the font is formatted as double strikethrough text.
embossTrue if the font is formatted as embossed.
emphasisMarkGets 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.
highlightColorGets or sets the highlight (marker) color.
italicTrue if the font is formatted as italic.
italicBiTrue if the right-to-left text is formatted as italic.
kerningGets or sets the font size at which kerning starts.
lineSpacingReturns line spacing of this font (in points).
localeIdGets or sets the locale identifier (language) of the formatted characters.
localeIdBiGets or sets the locale identifier (language) of the formatted right-to-left characters.
localeIdFarEastGets or sets the locale identifier (language) of the formatted Asian characters.
nameGets or sets the name of the font.
nameAsciiReturns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
nameBiReturns or sets the name of the font in a right-to-left language document.
nameFarEastReturns or sets an East Asian font name.
nameOtherReturns or sets the font used for characters with character codes from 128 through 255.
noProofingTrue when the formatted characters are not to be spell checked.
numberSpacingGets or sets the spacing type of the numeral being displayed.
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.
sizeBiGets or sets the font size in points used in a right-to-left document.
smallCapsTrue if the font is formatted as small capital letters.
snapToGridSpecifies 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 .
strikeThroughTrue if the font is formatted as strikethrough text.
styleGets or sets the character style applied to this formatting.
styleIdentifierGets or sets the locale independent style identifier of the character style applied to this formatting.
styleNameGets 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.
textEffectGets or sets the font animation effect.
themeColorGets or sets the theme color in the applied color scheme that is associated with this Font object.
themeFontGets or sets the theme font in the applied font scheme that is associated with this Font object.
themeFontAsciiGets 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.
themeFontBiGets or sets the theme font in the applied font scheme that is associated with this Font object in a right-to-left language document.
themeFontFarEastGets or sets the East Asian theme font in the applied font scheme that is associated with this Font object.
themeFontOtherGets 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.
tintAndShadeGets or sets a double value that lightens or darkens a color.
underlineGets or sets the type of underline applied to the font.
underlineColorGets or sets the color of the underline applied to the font.

Methods

NameDescription
clearFormatting()Resets to default font formatting.
hasDmlEffect(dmlEffectType)Checks if particular DrawingML text effect is applied.

Examples

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

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

let font = run.font;
font.name = "Courier New";
font.size = 36;
font.highlightColor = "#FFFF00";

doc.firstSection.body.firstParagraph.appendChild(run);
doc.save(base.artifactsDir + "Font.CreateFormattedRun.docx");

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

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

// Create a custom paragraph style.
let style = doc.styles.add(aw.StyleType.Paragraph, "MyStyle1");
style.font.size = 24;
style.font.name = "Verdana";
style.paragraphFormat.spaceAfter = 12;

// Create a list and make sure the paragraphs that use this style will use this list.
style.listFormat.list = doc.lists.add(aw.Lists.ListTemplate.BulletDefault);
style.listFormat.listLevelNumber = 0;

// Apply the paragraph style to the document builder's current paragraph, and then add some text.
builder.paragraphFormat.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.paragraphFormat.style = doc.styles.at("Normal");
builder.writeln("Hello World: Normal.");

builder.document.save(base.artifactsDir + "Styles.ParagraphStyleBulletedList.docx");

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

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

builder.font.border.color = "#008000";
builder.font.border.lineWidth = 2.5;
builder.font.border.lineStyle = aw.LineStyle.DashDotStroker;

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

doc.save(base.artifactsDir + "Border.FontBorder.docx");

See Also