Font

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.

public class Font

Properties

NameDescription
AllCaps { get; set; }True if the font is formatted as all capital letters.
AutoColor { get; }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 Color.
Bidi { get; set; }Specifies whether the contents of this run shall have right-to-left characteristics.
Bold { get; set; }True if the font is formatted as bold.
BoldBi { get; set; }True if the right-to-left text is formatted as bold.
Border { get; }Returns a Border object that specifies border for the font.
Color { get; set; }Gets or sets the color of the font.
ComplexScript { get; set; }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.
DoubleStrikeThrough { get; set; }True if the font is formatted as double strikethrough text.
Emboss { get; set; }True if the font is formatted as embossed.
EmphasisMark { get; set; }Gets or sets the emphasis mark applied to this formatting.
Engrave { get; set; }True if the font is formatted as engraved.
Fill { get; }Gets fill formatting for the Font.
Hidden { get; set; }True if the font is formatted as hidden text.
HighlightColor { get; set; }Gets or sets the highlight (marker) color.
Italic { get; set; }True if the font is formatted as italic.
ItalicBi { get; set; }True if the right-to-left text is formatted as italic.
Kerning { get; set; }Gets or sets the font size at which kerning starts.
LineSpacing { get; }Returns line spacing of this font (in points).
LocaleId { get; set; }Gets or sets the locale identifier (language) of the formatted characters.
LocaleIdBi { get; set; }Gets or sets the locale identifier (language) of the formatted right-to-left characters.
LocaleIdFarEast { get; set; }Gets or sets the locale identifier (language) of the formatted Asian characters.
Name { get; set; }Gets or sets the name of the font.
NameAscii { get; set; }Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
NameBi { get; set; }Returns or sets the name of the font in a right-to-left language document.
NameFarEast { get; set; }Returns or sets an East Asian font name.
NameOther { get; set; }Returns or sets the font used for characters with character codes from 128 through 255.
NoProofing { get; set; }True when the formatted characters are not to be spell checked.
Outline { get; set; }True if the font is formatted as outline.
Position { get; set; }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 { get; set; }Gets or sets character width scaling in percent.
Shading { get; }Returns a Shading object that refers to the shading formatting for the font.
Shadow { get; set; }True if the font is formatted as shadowed.
Size { get; set; }Gets or sets the font size in points.
SizeBi { get; set; }Gets or sets the font size in points used in a right-to-left document.
SmallCaps { get; set; }True if the font is formatted as small capital letters.
SnapToGrid { get; set; }Specifies whether the current font should use the document grid characters per line settings when laying out.
Spacing { get; set; }Returns or sets the spacing (in points) between characters .
StrikeThrough { get; set; }True if the font is formatted as strikethrough text.
Style { get; set; }Gets or sets the character style applied to this formatting.
StyleIdentifier { get; set; }Gets or sets the locale independent style identifier of the character style applied to this formatting.
StyleName { get; set; }Gets or sets the name of the character style applied to this formatting.
Subscript { get; set; }True if the font is formatted as subscript.
Superscript { get; set; }True if the font is formatted as superscript.
TextEffect { get; set; }Gets or sets the font animation effect.
ThemeColor { get; set; }Gets or sets the theme color in the applied color scheme that is associated with this Font object.
ThemeFont { get; set; }Gets or sets the theme font in the applied font scheme that is associated with this Font object.
ThemeFontAscii { get; set; }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.
ThemeFontBi { get; set; }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.
ThemeFontFarEast { get; set; }Gets or sets the East Asian theme font in the applied font scheme that is associated with this Font object.
ThemeFontOther { get; set; }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.
TintAndShade { get; set; }Gets or sets a double value that lightens or darkens a color.
Underline { get; set; }Gets or sets the type of underline applied to the font.
UnderlineColor { get; set; }Gets or sets the color of the underline applied to the font.

Methods

NameDescription
ClearFormatting()Resets to default font formatting.
HasDmlEffect(TextDmlEffect)Checks if particular DrawingML text effect is applied.

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.

Examples

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

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

Aspose.Words.Font font = run.Font;
font.Name = "Courier New";
font.Size = 36;
font.HighlightColor = Color.Yellow;

doc.FirstSection.Body.FirstParagraph.AppendChild(run);
doc.Save(ArtifactsDir + "Font.CreateFormattedRun.docx");

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

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Font.Border.Color = Color.Green;
builder.Font.Border.LineWidth = 2.5d;
builder.Font.Border.LineStyle = LineStyle.DashDotStroker;

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

doc.Save(ArtifactsDir + "Border.FontBorder.docx");

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

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a custom paragraph style.
Style style = doc.Styles.Add(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(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["Normal"];
builder.Writeln("Hello World: Normal.");

builder.Document.Save(ArtifactsDir + "Styles.ParagraphStyleBulletedList.docx");

See Also