com.aspose.words

  • java.lang.Object
    • com.aspose.words.Font
public class Font 
extends java.lang.Object

Contains font attributes (font name, font size, color, and so on) for an object.

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.

Example:

Shows how to format a run of text using its font property.
Document doc = new Document();
Run run = new Run(doc, "Hello world!");

Font font = run.getFont();
font.setName("Courier New");
font.setSize(36.0);
font.setHighlightColor(Color.YELLOW);

doc.getFirstSection().getBody().getFirstParagraph().appendChild(run);
doc.save(getArtifactsDir() + "Font.CreateFormattedRun.docx");

Example:

Shows how to insert a string surrounded by a border into a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.getFont().getBorder().setColor(Color.GREEN);
builder.getFont().getBorder().setLineWidth(2.5);
builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);

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

doc.save(getArtifactsDir() + "Border.FontBorder.docx");

Example:

Shows how to create and use a paragraph style with list formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create a paragraph style and specify some formatting for it
Style style = doc.getStyles().add(StyleType.PARAGRAPH, "MyStyle1");
style.getFont().setSize(24.0);
style.getFont().setName("Verdana");
style.getParagraphFormat().setSpaceAfter(12.0);

// Create a list and make sure the paragraphs that use this style will use this list
style.getListFormat().setList(doc.getLists().add(ListTemplate.BULLET_DEFAULT));
style.getListFormat().setListLevelNumber(0);

// Apply the paragraph style to the current paragraph in the document and add some text
builder.getParagraphFormat().setStyle(style);
builder.writeln("Hello World: MyStyle1, bulleted list.");

// Change to a paragraph style that has no list formatting
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
builder.writeln("Hello World: Normal.");

builder.getDocument().save(getArtifactsDir() + "Styles.ParagraphStyleBulletedList.docx");

Property Getters/Setters Summary
booleangetAllCaps()
void
setAllCaps(booleanvalue)
           True if the font is formatted as all capital letters.
java.awt.ColorgetAutoColor()
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.
booleangetBidi()
void
setBidi(booleanvalue)
           Specifies whether the contents of this run shall have right-to-left characteristics.
booleangetBold()
void
setBold(booleanvalue)
           True if the font is formatted as bold.
booleangetBoldBi()
void
setBoldBi(booleanvalue)
           True if the right-to-left text is formatted as bold.
BordergetBorder()
Returns a Border object that specifies border for the font.
java.awt.ColorgetColor()
void
setColor(java.awt.Colorvalue)
           Gets or sets the color of the font.
booleangetComplexScript()
void
setComplexScript(booleanvalue)
           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.
booleangetDoubleStrikeThrough()
void
           True if the font is formatted as double strikethrough text.
booleangetEmboss()
void
setEmboss(booleanvalue)
           True if the font is formatted as embossed.
intgetEmphasisMark()
void
setEmphasisMark(intvalue)
           Gets or sets the emphasis mark applied to this formatting. The value of the property is EmphasisMark integer constant.
booleangetEngrave()
void
setEngrave(booleanvalue)
           True if the font is formatted as engraved.
booleangetHidden()
void
setHidden(booleanvalue)
           True if the font is formatted as hidden text.
java.awt.ColorgetHighlightColor()
void
setHighlightColor(java.awt.Colorvalue)
           Gets or sets the highlight (marker) color.
booleangetItalic()
void
setItalic(booleanvalue)
           True if the font is formatted as italic.
booleangetItalicBi()
void
setItalicBi(booleanvalue)
           True if the right-to-left text is formatted as italic.
doublegetKerning()
void
setKerning(doublevalue)
           Gets or sets the font size at which kerning starts.
doublegetLineSpacing()
Returns line spacing of this font (in points).
intgetLocaleId()
void
setLocaleId(intvalue)
           Gets or sets the locale identifier (language) of the formatted characters.
intgetLocaleIdBi()
void
setLocaleIdBi(intvalue)
           Gets or sets the locale identifier (language) of the formatted right-to-left characters.
intgetLocaleIdFarEast()
void
           Gets or sets the locale identifier (language) of the formatted Asian characters.
java.lang.StringgetName()
void
setName(java.lang.Stringvalue)
           Gets or sets the name of the font.
java.lang.StringgetNameAscii()
void
setNameAscii(java.lang.Stringvalue)
           Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
java.lang.StringgetNameBi()
void
setNameBi(java.lang.Stringvalue)
           Returns or sets the name of the font in a right-to-left language document.
java.lang.StringgetNameFarEast()
void
setNameFarEast(java.lang.Stringvalue)
           Returns or sets an East Asian font name.
java.lang.StringgetNameOther()
void
setNameOther(java.lang.Stringvalue)
           Returns or sets the font used for characters with character codes from 128 through 255.
booleangetNoProofing()
void
setNoProofing(booleanvalue)
           True when the formatted characters are not to be spell checked.
booleangetOutline()
void
setOutline(booleanvalue)
           True if the font is formatted as outline.
doublegetPosition()
void
setPosition(doublevalue)
           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.
intgetScaling()
void
setScaling(intvalue)
           Gets or sets character width scaling in percent.
ShadinggetShading()
Returns a Shading object that refers to the shading formatting for the font.
booleangetShadow()
void
setShadow(booleanvalue)
           True if the font is formatted as shadowed.
doublegetSize()
void
setSize(doublevalue)
           Gets or sets the font size in points.
doublegetSizeBi()
void
setSizeBi(doublevalue)
           Gets or sets the font size in points used in a right-to-left document.
booleangetSmallCaps()
void
setSmallCaps(booleanvalue)
           True if the font is formatted as small capital letters.
booleangetSnapToGrid()
void
setSnapToGrid(booleanvalue)
           Specifies whether the current font should use the document grid characters per line settings when laying out.
doublegetSpacing()
void
setSpacing(doublevalue)
           Returns or sets the spacing (in points) between characters .
booleangetStrikeThrough()
void
setStrikeThrough(booleanvalue)
           True if the font is formatted as strikethrough text.
StylegetStyle()
void
setStyle(Style value)
           Gets or sets the character style applied to this formatting.
intgetStyleIdentifier()
void
           Gets or sets the locale independent style identifier of the character style applied to this formatting. The value of the property is StyleIdentifier integer constant.
java.lang.StringgetStyleName()
void
setStyleName(java.lang.Stringvalue)
           Gets or sets the name of the character style applied to this formatting.
booleangetSubscript()
void
setSubscript(booleanvalue)
           True if the font is formatted as subscript.
booleangetSuperscript()
void
setSuperscript(booleanvalue)
           True if the font is formatted as superscript.
intgetTextEffect()
void
setTextEffect(intvalue)
           Gets or sets the font animation effect. The value of the property is TextEffect integer constant.
intgetUnderline()
void
setUnderline(intvalue)
           Gets or sets the type of underline applied to the font. The value of the property is Underline integer constant.
java.awt.ColorgetUnderlineColor()
void
setUnderlineColor(java.awt.Colorvalue)
           Gets or sets the color of the underline applied to the font.
 
Method Summary
voidclearFormatting()
Resets to default font formatting.
booleanhasDmlEffect(int dmlEffectType)
Checks if particular DrawingML text effect is applied.
 

    • Property Getters/Setters Detail

      • getAllCaps/setAllCaps

        public boolean getAllCaps() / public void setAllCaps(boolean value)
        
        True if the font is formatted as all capital letters.

        Example:

        Shows how to format a run to display its contents in capitals.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // There are two ways of getting a run to display its lowercase text in uppercase without changing the contents.
        // 1 -  Set the AllCaps flag to display all characters in regular capitals:
        Run run = new Run(doc, "all capitals");
        run.getFont().setAllCaps(true);
        para.appendChild(run);
        
        para = (Paragraph)para.getParentNode().appendChild(new Paragraph(doc));
        
        // 2 -  Set the SmallCaps flag to display all characters in small capitals:
        // If a character is lower case, it will appear in its upper case form
        // but will have the same height as the lower case (the font's x-height).
        // Characters that were in upper case originally will look the same.
        run = new Run(doc, "Small Capitals");
        run.getFont().setSmallCaps(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.Caps.docx");
      • getAutoColor

        public java.awt.Color getAutoColor()
        
        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.

        When text has 'automatic color', the actual color of text is calculated automatically so that it is readable against the background color. As you change the background color, the text color will automatically switch to black or white in MS Word to maximize legibility.

      • getBidi/setBidi

        public boolean getBidi() / public void setBidi(boolean value)
        
        Specifies whether the contents of this run shall have right-to-left characteristics.

        This property, when on, shall not be used with strongly left-to-right text. Any behavior under that condition is unspecified. This property, when off, shall not be used with strong right-to-left text. Any behavior under that condition is unspecified.

        When the contents of this run are displayed, all characters shall be treated as complex script characters for formatting purposes. This means that BoldBi, ItalicBi, SizeBi and a corresponding font name will be used when rendering this run.

        Also, when the contents of this run are displayed, this property acts as a right-to-left override for characters which are classified as "weak types" and "neutral types".

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
      • getBold/setBold

        public boolean getBold() / public void setBold(boolean value)
        
        True if the font is formatted as bold.

        Example:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");
      • getBoldBi/setBoldBi

        public boolean getBoldBi() / public void setBoldBi(boolean value)
        
        True if the right-to-left text is formatted as bold.

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
      • getBorder

        public Border getBorder()
        
        Returns a Border object that specifies border for the font.

        Example:

        Shows how to insert a string surrounded by a border into a document.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().getBorder().setColor(Color.GREEN);
        builder.getFont().getBorder().setLineWidth(2.5);
        builder.getFont().getBorder().setLineStyle(LineStyle.DASH_DOT_STROKER);
        
        builder.write("Text surrounded by green border.");
        
        doc.save(getArtifactsDir() + "Border.FontBorder.docx");
      • getColor/setColor

        public java.awt.Color getColor() / public void setColor(java.awt.Color value)
        
        Gets or sets the color of the font.

        Example:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");

        Example:

        Shows how to insert a hyperlink field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("For more information, please visit the ");
        
        // Insert a hyperlink, and apply formatting to emphasize it.
        // The hyperlink will be a clickable piece of text which will take us to the location specified in the URL.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Aspose website", "http://www.aspose.com", false);
        builder.getFont().clearFormatting();
        builder.writeln(".");
        
        // Ctrl + left clicking the link in the text in Microsoft Word will take us to the URL via a new web browser window.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlink.docx");
      • getComplexScript/setComplexScript

        public boolean getComplexScript() / public void setComplexScript(boolean value)
        
        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.

        Example:

        Shows how to add text that is always treated as complex script.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setComplexScript(true);
        
        builder.writeln("Text treated as complex script.");
        
        doc.save(getArtifactsDir() + "Font.ComplexScript.docx");
      • getDoubleStrikeThrough/setDoubleStrikeThrough

        public boolean getDoubleStrikeThrough() / public void setDoubleStrikeThrough(boolean value)
        
        True if the font is formatted as double strikethrough text.

        Example:

        Shows how to add a line strikethrough to text.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        Run run = new Run(doc, "Text with a single-line strikethrough.");
        run.getFont().setStrikeThrough(true);
        para.appendChild(run);
        
        para = (Paragraph)para.getParentNode().appendChild(new Paragraph(doc));
        
        run = new Run(doc, "Text with a double-line strikethrough.");
        run.getFont().setDoubleStrikeThrough(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.StrikeThrough.docx");
      • getEmboss/setEmboss

        public boolean getEmboss() / public void setEmboss(boolean value)
        
        True if the font is formatted as embossed.

        Example:

        Shows how to apply engraving/embossing effects to text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(36.0);
        builder.getFont().setColor(Color.WHITE);
        
        // Below are two ways of using shadows to apply a 3D-like effect to the text.
        // 1 -  Engrave text to make it look like the letters are sunken into the page:
        builder.getFont().setEngrave(true);
        
        builder.writeln("This text is engraved.");
        
        // 2 -  Emboss text to make it look like the letters pop out of the page:
        builder.getFont().setEngrave(false);
        builder.getFont().setEmboss(true);
        
        builder.writeln("This text is embossed.");
        
        doc.save(getArtifactsDir() + "Font.EngraveEmboss.docx");
      • getEmphasisMark/setEmphasisMark

        public int getEmphasisMark() / public void setEmphasisMark(int value)
        
        Gets or sets the emphasis mark applied to this formatting. The value of the property is EmphasisMark integer constant.

        Example:

        Shows how to add additional character rendered above/below the glyph-character.
        DocumentBuilder builder = new DocumentBuilder();
        
        // Possible types of emphasis mark:
        // https://apireference.aspose.com/words/net/aspose.words/emphasismark
        builder.getFont().setEmphasisMark(emphasisMark); 
        
        builder.write("Emphasis text");
        builder.writeln();
        builder.getFont().clearFormatting();
        builder.write("Simple text");
        
        builder.getDocument().save(getArtifactsDir() + "Fonts.SetEmphasisMark.docx");
      • getEngrave/setEngrave

        public boolean getEngrave() / public void setEngrave(boolean value)
        
        True if the font is formatted as engraved.

        Example:

        Shows how to apply engraving/embossing effects to text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(36.0);
        builder.getFont().setColor(Color.WHITE);
        
        // Below are two ways of using shadows to apply a 3D-like effect to the text.
        // 1 -  Engrave text to make it look like the letters are sunken into the page:
        builder.getFont().setEngrave(true);
        
        builder.writeln("This text is engraved.");
        
        // 2 -  Emboss text to make it look like the letters pop out of the page:
        builder.getFont().setEngrave(false);
        builder.getFont().setEmboss(true);
        
        builder.writeln("This text is embossed.");
        
        doc.save(getArtifactsDir() + "Font.EngraveEmboss.docx");
      • getHidden/setHidden

        public boolean getHidden() / public void setHidden(boolean value)
        
        True if the font is formatted as hidden text.

        Example:

        Shows how to create a run of hidden text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // With the Hidden flag set to true, any text that we create using this Font object will be invisible in the document.
        // We will not see or highlight hidden text unless we enable the "Hidden text" option
        // found in Microsoft Word via File -> Options -> Display. The text will still be there,
        // and we will be able to access this text programmatically.
        // It is not advised to use this method to hide sensitive information.
        builder.getFont().setHidden(true);
        builder.getFont().setSize(36.0);
        
        builder.writeln("This text will not be visible in the document.");
        
        doc.save(getArtifactsDir() + "Font.Hidden.docx");
      • getHighlightColor/setHighlightColor

        public java.awt.Color getHighlightColor() / public void setHighlightColor(java.awt.Color value)
        
        Gets or sets the highlight (marker) color.

        Example:

        Shows how to format a run of text using its font property.
        Document doc = new Document();
        Run run = new Run(doc, "Hello world!");
        
        Font font = run.getFont();
        font.setName("Courier New");
        font.setSize(36.0);
        font.setHighlightColor(Color.YELLOW);
        
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(run);
        doc.save(getArtifactsDir() + "Font.CreateFormattedRun.docx");
      • getItalic/setItalic

        public boolean getItalic() / public void setItalic(boolean value)
        
        True if the font is formatted as italic.

        Example:

        Shows how to write italicized text using a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(36.0);
        builder.getFont().setItalic(true);
        builder.writeln("Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Italic.docx");
      • getItalicBi/setItalicBi

        public boolean getItalicBi() / public void setItalicBi(boolean value)
        
        True if the right-to-left text is formatted as italic.

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
      • getKerning/setKerning

        public double getKerning() / public void setKerning(double value)
        
        Gets or sets the font size at which kerning starts.

        Example:

        Shows how to specify the font size at which kerning begins to take effect.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        builder.getFont().setName("Arial Black");
        
        // Set the builder's font size, and minimum size at which kerning will take effect.
        // The font size falls below the kerning threshold, so the run bellow will not have kerning.
        builder.getFont().setSize(18.0);
        builder.getFont().setKerning(24.0);
        
        builder.writeln("TALLY. (Kerning not applied)");
        
        // Set the kerning threshold so that the builder's current font size is above it.
        // Any text we add from this point will have kerning applied. The spaces between characters
        // will be adjusted, normally resulting in a slightly more aesthetically pleasing text run.
        builder.getFont().setKerning(12.0);
        
        builder.writeln("TALLY. (Kerning applied)");
        
        doc.save(getArtifactsDir() + "Font.Kerning.docx");
      • getLineSpacing

        public double getLineSpacing()
        
        Returns line spacing of this font (in points).

        Example:

        Shows how to get a font's line spacing, in points.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set different fonts for the DocumentBuilder, and verify their line spacing.
        builder.getFont().setName("Calibri");
        Assert.assertEquals(13.7d, builder.getFont().getLineSpacing(), 1);
        
        builder.getFont().setName("Times New Roman");
        Assert.assertEquals(13.7d, builder.getFont().getLineSpacing(), 1);
      • getLocaleId/setLocaleId

        public int getLocaleId() / public void setLocaleId(int value)
        
        Gets or sets the locale identifier (language) of the formatted characters. For the list of locale identifiers see https://msdn.microsoft.com/en-us/library/cc233965.aspx

        Example:

        Shows how to set the locale of the text that we are adding with a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // If we set the font's locale to English and insert some Russian text,
        // the English locale spell checker will not recognize the text and detect it as a spelling error.
        builder.getFont().setLocaleId(1033);
        builder.writeln("Привет!");
        
        // Set a matching locale for the text that we are about to add to apply the appropriate spell checker.
        builder.getFont().setLocaleId(1049);
        builder.writeln("Привет!");
        
        doc.save(getArtifactsDir() + "Font.LocaleId.docx");
      • getLocaleIdBi/setLocaleIdBi

        public int getLocaleIdBi() / public void setLocaleIdBi(int value)
        
        Gets or sets the locale identifier (language) of the formatted right-to-left characters. For the list of locale identifiers see https://msdn.microsoft.com/en-us/library/cc233965.aspx

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
      • getLocaleIdFarEast/setLocaleIdFarEast

        public int getLocaleIdFarEast() / public void setLocaleIdFarEast(int value)
        
        Gets or sets the locale identifier (language) of the formatted Asian characters. For the list of locale identifiers see https://msdn.microsoft.com/en-us/library/cc233965.aspx

        Example:

        Shows how to insert and format text in a Far East language.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font settings that the document builder will apply to any text that it inserts.
        builder.getFont().setName("Courier New");
        builder.getFont().setLocaleId(1033);
        
        // Name "FarEast" equivalents for our font and locale.
        // If the builder inserts Asian characters with this Font configuration, then each run that contains
        // these characters will display them using the "FarEast" font/locale instead of the default.
        // This could be useful when a western font does not have ideal representations for Asian characters.
        builder.getFont().setNameFarEast("SimSun");
        builder.getFont().setLocaleIdFarEast(2052);
        
        // This text will be displayed in the default font/locale.
        builder.writeln("Hello world!");
        
        // Since these are Asian characters, this run will apply our "FarEast" font/locale equivalents.
        builder.writeln("你好世界");
        
        doc.save(getArtifactsDir() + "Font.FarEast.docx");
      • getName/setName

        public java.lang.String getName() / public void setName(java.lang.String value)
        
        Gets or sets the name of the font.

        When getting, returns NameAscii.

        When setting, sets NameAscii, NameBi, NameFarEast and NameOther to the specified value.

        Example:

        Shows how to format a run of text using its font property.
        Document doc = new Document();
        Run run = new Run(doc, "Hello world!");
        
        Font font = run.getFont();
        font.setName("Courier New");
        font.setSize(36.0);
        font.setHighlightColor(Color.YELLOW);
        
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(run);
        doc.save(getArtifactsDir() + "Font.CreateFormattedRun.docx");

        Example:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");
      • getNameAscii/setNameAscii

        public java.lang.String getNameAscii() / public void setNameAscii(java.lang.String value)
        
        Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).

        Example:

        Shows how Microsoft Word can combine two different fonts in one run.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Suppose a run that we use the builder to insert while using this font configuration
        // contains characters within the ASCII characters' range. In that case,
        // it will display those characters using this font.
        builder.getFont().setNameAscii("Calibri");
        
        // With no other font specified, the builder will also apply this font to all characters that it inserts.
        Assert.assertEquals("Calibri", builder.getFont().getName());
        
        // Specify a font to use for all characters outside of the ASCII range.
        // Ideally, this font should have a glyph for each required non-ASCII character code.
        builder.getFont().setNameOther("Courier New");
        
        // Insert a run with one word consisting of ASCII characters, and one word with all characters outside that range.
        // Each character will be displayed using either of the fonts, depending on.
        builder.writeln("Hello, Привет");
        
        doc.save(getArtifactsDir() + "Font.NameAscii.docx");
        See Also:
        Name
      • getNameBi/setNameBi

        public java.lang.String getNameBi() / public void setNameBi(java.lang.String value)
        
        Returns or sets the name of the font in a right-to-left language document.

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
        See Also:
        Name
      • getNameFarEast/setNameFarEast

        public java.lang.String getNameFarEast() / public void setNameFarEast(java.lang.String value)
        
        Returns or sets an East Asian font name.

        Example:

        Shows how to insert and format text in a Far East language.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font settings that the document builder will apply to any text that it inserts.
        builder.getFont().setName("Courier New");
        builder.getFont().setLocaleId(1033);
        
        // Name "FarEast" equivalents for our font and locale.
        // If the builder inserts Asian characters with this Font configuration, then each run that contains
        // these characters will display them using the "FarEast" font/locale instead of the default.
        // This could be useful when a western font does not have ideal representations for Asian characters.
        builder.getFont().setNameFarEast("SimSun");
        builder.getFont().setLocaleIdFarEast(2052);
        
        // This text will be displayed in the default font/locale.
        builder.writeln("Hello world!");
        
        // Since these are Asian characters, this run will apply our "FarEast" font/locale equivalents.
        builder.writeln("你好世界");
        
        doc.save(getArtifactsDir() + "Font.FarEast.docx");
        See Also:
        Name
      • getNameOther/setNameOther

        public java.lang.String getNameOther() / public void setNameOther(java.lang.String value)
        
        Returns or sets the font used for characters with character codes from 128 through 255.

        Example:

        Shows how Microsoft Word can combine two different fonts in one run.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Suppose a run that we use the builder to insert while using this font configuration
        // contains characters within the ASCII characters' range. In that case,
        // it will display those characters using this font.
        builder.getFont().setNameAscii("Calibri");
        
        // With no other font specified, the builder will also apply this font to all characters that it inserts.
        Assert.assertEquals("Calibri", builder.getFont().getName());
        
        // Specify a font to use for all characters outside of the ASCII range.
        // Ideally, this font should have a glyph for each required non-ASCII character code.
        builder.getFont().setNameOther("Courier New");
        
        // Insert a run with one word consisting of ASCII characters, and one word with all characters outside that range.
        // Each character will be displayed using either of the fonts, depending on.
        builder.writeln("Hello, Привет");
        
        doc.save(getArtifactsDir() + "Font.NameAscii.docx");
        See Also:
        Name
      • getNoProofing/setNoProofing

        public boolean getNoProofing() / public void setNoProofing(boolean value)
        
        True when the formatted characters are not to be spell checked.

        Example:

        Shows how to prevent text from being spell checked by Microsoft Word.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Normally, Microsoft Word emphasizes spelling errors with a jagged red underline.
        // We can un-set the NoProofing flag to create a portion of text that
        // bypasses the spell checker while completely disabling it.
        builder.getFont().setNoProofing(true);
        
        builder.writeln("Proofing has been disabled, so these spelking errrs will not display red lines underneath.");
        
        doc.save(getArtifactsDir() + "Font.NoProofing.docx");
      • getOutline/setOutline

        public boolean getOutline() / public void setOutline(boolean value)
        
        True if the font is formatted as outline.

        Example:

        Shows how to create a run of text formatted as outline.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set the Outline flag to change the text's fill color to white and
        // leave a thin outline around each character in the original color of the text. 
        builder.getFont().setOutline(true);
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setSize(36.0);
        
        builder.writeln("This text has an outline.");
        
        doc.save(getArtifactsDir() + "Font.Outline.docx");
      • getPosition/setPosition

        public double getPosition() / public void setPosition(double value)
        
        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.

        Example:

        Shows how to format text to offset its position.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // Raise this run of text 5 points above the baseline.
        Run run = new Run(doc, "Raised text. ");
        run.getFont().setPosition(5.0);
        para.appendChild(run);
        
        // Lower this run of text 10 points below the baseline.
        run = new Run(doc, "Lowered text. ");
        run.getFont().setPosition(-10);
        para.appendChild(run);
        
        // Add a run of normal text.
        run = new Run(doc, "Text in its default position. ");
        para.appendChild(run);
        
        // Add a run of text that appears as subscript.
        run = new Run(doc, "Subscript. ");
        run.getFont().setSubscript(true);
        para.appendChild(run);
        
        // Add a run of text that appears as superscript.
        run = new Run(doc, "Superscript.");
        run.getFont().setSuperscript(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.PositionSubscript.docx");
      • getScaling/setScaling

        public int getScaling() / public void setScaling(int value)
        
        Gets or sets character width scaling in percent.

        Example:

        Shows how to set horizontal scaling and spacing for characters.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add run of text, and increase character width to 150%.
        builder.getFont().setScaling(150);
        builder.writeln("Wide characters");
        
        // Add run of text, and add 1pt of extra horizontal spacing between each character.
        builder.getFont().setSpacing(1.0);
        builder.writeln("Expanded by 1pt");
        
        // Add run of text, and bring characters closer together by 1pt.
        builder.getFont().setSpacing(-1);
        builder.writeln("Condensed by 1pt");
        
        doc.save(getArtifactsDir() + "Font.ScalingSpacing.docx");
      • getShading

        public Shading getShading()
        
        Returns a Shading object that refers to the shading formatting for the font.

        Example:

        Shows how to apply shading to text created by a document builder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setColor(Color.WHITE);
        
        // One way to make the text created using our white font color visible
        // is to apply a background shading effect.
        Shading shading = builder.getFont().getShading();
        shading.setTexture(TextureIndex.TEXTURE_DIAGONAL_UP);
        shading.setBackgroundPatternColor(Color.RED);
        shading.setForegroundPatternColor(Color.BLUE);
        
        builder.writeln("White text on an orange background with a two-tone texture.");
        
        doc.save(getArtifactsDir() + "Font.Shading.docx");
      • getShadow/setShadow

        public boolean getShadow() / public void setShadow(boolean value)
        
        True if the font is formatted as shadowed.

        Example:

        Shows how to create a run of text formatted with a shadow.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Set the Shadow flag to apply an offset shadow effect,
        // making it look like the letters are floating above the page.
        builder.getFont().setShadow(true);
        builder.getFont().setSize(36.0);
        
        builder.writeln("This text has a shadow.");
        
        doc.save(getArtifactsDir() + "Font.Shadow.docx");
      • getSize/setSize

        public double getSize() / public void setSize(double value)
        
        Gets or sets the font size in points.

        Example:

        Shows how to format a run of text using its font property.
        Document doc = new Document();
        Run run = new Run(doc, "Hello world!");
        
        Font font = run.getFont();
        font.setName("Courier New");
        font.setSize(36.0);
        font.setHighlightColor(Color.YELLOW);
        
        doc.getFirstSection().getBody().getFirstParagraph().appendChild(run);
        doc.save(getArtifactsDir() + "Font.CreateFormattedRun.docx");

        Example:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");
      • getSizeBi/setSizeBi

        public double getSizeBi() / public void setSizeBi(double value)
        
        Gets or sets the font size in points used in a right-to-left document.

        Example:

        Shows how to define separate sets of font settings for right-to-left, and right-to-left text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Define a set of font settings for left-to-right text.
        builder.getFont().setName("Courier New");
        builder.getFont().setSize(16.0);
        builder.getFont().setItalic(false);
        builder.getFont().setBold(false);
        builder.getFont().setLocaleId(1033);
        
        // Define another set of font settings for right-to-left text.
        builder.getFont().setNameBi("Andalus");
        builder.getFont().setSizeBi(48.0);
        
        // Specify that the right-to-left text in this run is bold and italic
        builder.getFont().setItalicBi(true);
        builder.getFont().setBoldBi(true);
        builder.getFont().setLocaleIdBi(1025);
        
        // We can use the Bidi flag to indicate whether the text we are about to add
        // with the document builder is right-to-left. When we add text with this flag set to true,
        // it will be formatted using the right-to-left set of font settings.
        builder.getFont().setBidi(true);
        builder.write("مرحبًا");
        
        // Set the flag to false, and then add left-to-right text.
        // The document builder will format these using the left-to-right set of font settings.
        builder.getFont().setBidi(false);
        builder.write(" Hello world!");
        
        doc.save(getArtifactsDir() + "Font.Bidi.docx");
      • getSmallCaps/setSmallCaps

        public boolean getSmallCaps() / public void setSmallCaps(boolean value)
        
        True if the font is formatted as small capital letters.

        Example:

        Shows how to format a run to display its contents in capitals.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // There are two ways of getting a run to display its lowercase text in uppercase without changing the contents.
        // 1 -  Set the AllCaps flag to display all characters in regular capitals:
        Run run = new Run(doc, "all capitals");
        run.getFont().setAllCaps(true);
        para.appendChild(run);
        
        para = (Paragraph)para.getParentNode().appendChild(new Paragraph(doc));
        
        // 2 -  Set the SmallCaps flag to display all characters in small capitals:
        // If a character is lower case, it will appear in its upper case form
        // but will have the same height as the lower case (the font's x-height).
        // Characters that were in upper case originally will look the same.
        run = new Run(doc, "Small Capitals");
        run.getFont().setSmallCaps(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.Caps.docx");
      • getSnapToGrid/setSnapToGrid

        public boolean getSnapToGrid() / public void setSnapToGrid(boolean value)
        
        Specifies whether the current font should use the document grid characters per line settings when laying out.
      • getSpacing/setSpacing

        public double getSpacing() / public void setSpacing(double value)
        
        Returns or sets the spacing (in points) between characters .

        Example:

        Shows how to set horizontal scaling and spacing for characters.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add run of text, and increase character width to 150%.
        builder.getFont().setScaling(150);
        builder.writeln("Wide characters");
        
        // Add run of text, and add 1pt of extra horizontal spacing between each character.
        builder.getFont().setSpacing(1.0);
        builder.writeln("Expanded by 1pt");
        
        // Add run of text, and bring characters closer together by 1pt.
        builder.getFont().setSpacing(-1);
        builder.writeln("Condensed by 1pt");
        
        doc.save(getArtifactsDir() + "Font.ScalingSpacing.docx");
      • getStrikeThrough/setStrikeThrough

        public boolean getStrikeThrough() / public void setStrikeThrough(boolean value)
        
        True if the font is formatted as strikethrough text.

        Example:

        Shows how to add a line strikethrough to text.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        Run run = new Run(doc, "Text with a single-line strikethrough.");
        run.getFont().setStrikeThrough(true);
        para.appendChild(run);
        
        para = (Paragraph)para.getParentNode().appendChild(new Paragraph(doc));
        
        run = new Run(doc, "Text with a double-line strikethrough.");
        run.getFont().setDoubleStrikeThrough(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.StrikeThrough.docx");
      • getStyle/setStyle

        public Style getStyle() / public void setStyle(Style value)
        
        Gets or sets the character style applied to this formatting.

        Example:

        Applies a double underline to all runs in a document that are formatted with custom character styles.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Insert a custom style, and apply it to text created using a document builder.
        Style style = doc.getStyles().add(StyleType.CHARACTER, "MyStyle");
        style.getFont().setColor(Color.RED);
        style.getFont().setName("Courier New");
        
        builder.getFont().setStyleName("MyStyle");
        builder.write("This text is in a custom style.");
        
        // Iterate over every run, and add a double underline to every custom style.
        for (Run run : (Iterable<Run>) doc.getChildNodes(NodeType.RUN, true)) {
            Style charStyle = run.getFont().getStyle();
        
            if (!charStyle.getBuiltIn())
                run.getFont().setUnderline(Underline.DOUBLE);
        }
        
        doc.save(getArtifactsDir() + "Font.Style.docx");
      • getStyleIdentifier/setStyleIdentifier

        public int getStyleIdentifier() / public void setStyleIdentifier(int value)
        
        Gets or sets the locale independent style identifier of the character style applied to this formatting. The value of the property is StyleIdentifier integer constant.

        Example:

        Shows how to change the style of existing text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are two ways of referencing styles.
        // 1 -  Using the style name:
        builder.getFont().setStyleName("Emphasis");
        builder.writeln("Text originally in \"Emphasis\" style");
        
        // 2 -  Using a built-in style identifier:
        builder.getFont().setStyleIdentifier(StyleIdentifier.INTENSE_EMPHASIS);
        builder.writeln("Text originally in \"Intense Emphasis\" style");
        
        // Convert all uses of one style to another,
        // using the above methods to reference old and new styles.
        for (Run run : (Iterable<Run>)doc.getChildNodes(NodeType.RUN, true))
        {
            if (run.getFont().getStyleName().equals("Emphasis"))
                run.getFont().setStyleName("Strong");
        
            if (((run.getFont().getStyleIdentifier()) == (StyleIdentifier.INTENSE_EMPHASIS)))
                run.getFont().setStyleIdentifier(StyleIdentifier.STRONG);
        }
        
        doc.save(getArtifactsDir() + "Font.ChangeStyle.docx");
      • getStyleName/setStyleName

        public java.lang.String getStyleName() / public void setStyleName(java.lang.String value)
        
        Gets or sets the name of the character style applied to this formatting.

        Example:

        Shows how to change the style of existing text.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Below are two ways of referencing styles.
        // 1 -  Using the style name:
        builder.getFont().setStyleName("Emphasis");
        builder.writeln("Text originally in \"Emphasis\" style");
        
        // 2 -  Using a built-in style identifier:
        builder.getFont().setStyleIdentifier(StyleIdentifier.INTENSE_EMPHASIS);
        builder.writeln("Text originally in \"Intense Emphasis\" style");
        
        // Convert all uses of one style to another,
        // using the above methods to reference old and new styles.
        for (Run run : (Iterable<Run>)doc.getChildNodes(NodeType.RUN, true))
        {
            if (run.getFont().getStyleName().equals("Emphasis"))
                run.getFont().setStyleName("Strong");
        
            if (((run.getFont().getStyleIdentifier()) == (StyleIdentifier.INTENSE_EMPHASIS)))
                run.getFont().setStyleIdentifier(StyleIdentifier.STRONG);
        }
        
        doc.save(getArtifactsDir() + "Font.ChangeStyle.docx");
      • getSubscript/setSubscript

        public boolean getSubscript() / public void setSubscript(boolean value)
        
        True if the font is formatted as subscript.

        Example:

        Shows how to format text to offset its position.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // Raise this run of text 5 points above the baseline.
        Run run = new Run(doc, "Raised text. ");
        run.getFont().setPosition(5.0);
        para.appendChild(run);
        
        // Lower this run of text 10 points below the baseline.
        run = new Run(doc, "Lowered text. ");
        run.getFont().setPosition(-10);
        para.appendChild(run);
        
        // Add a run of normal text.
        run = new Run(doc, "Text in its default position. ");
        para.appendChild(run);
        
        // Add a run of text that appears as subscript.
        run = new Run(doc, "Subscript. ");
        run.getFont().setSubscript(true);
        para.appendChild(run);
        
        // Add a run of text that appears as superscript.
        run = new Run(doc, "Superscript.");
        run.getFont().setSuperscript(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.PositionSubscript.docx");
      • getSuperscript/setSuperscript

        public boolean getSuperscript() / public void setSuperscript(boolean value)
        
        True if the font is formatted as superscript.

        Example:

        Shows how to format text to offset its position.
        Document doc = new Document();
        Paragraph para = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // Raise this run of text 5 points above the baseline.
        Run run = new Run(doc, "Raised text. ");
        run.getFont().setPosition(5.0);
        para.appendChild(run);
        
        // Lower this run of text 10 points below the baseline.
        run = new Run(doc, "Lowered text. ");
        run.getFont().setPosition(-10);
        para.appendChild(run);
        
        // Add a run of normal text.
        run = new Run(doc, "Text in its default position. ");
        para.appendChild(run);
        
        // Add a run of text that appears as subscript.
        run = new Run(doc, "Subscript. ");
        run.getFont().setSubscript(true);
        para.appendChild(run);
        
        // Add a run of text that appears as superscript.
        run = new Run(doc, "Superscript.");
        run.getFont().setSuperscript(true);
        para.appendChild(run);
        
        doc.save(getArtifactsDir() + "Font.PositionSubscript.docx");
      • getTextEffect/setTextEffect

        public int getTextEffect() / public void setTextEffect(int value)
        
        Gets or sets the font animation effect. The value of the property is TextEffect integer constant.

        Example:

        Shows how to apply a visual effect to a run.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setSize(36.0);
        builder.getFont().setTextEffect(TextEffect.SPARKLE_TEXT);
        
        builder.writeln("Text with a sparkle effect.");
        
        // Older versions of Microsoft Word only support font animation effects.
        doc.save(getArtifactsDir() + "Font.SparklingText.doc");
      • getUnderline/setUnderline

        public int getUnderline() / public void setUnderline(int value)
        
        Gets or sets the type of underline applied to the font. The value of the property is Underline integer constant.

        Example:

        Shows how to configure the style and color of a text underline.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setUnderline(Underline.DOTTED);
        builder.getFont().setUnderlineColor(Color.RED);
        
        builder.writeln("Underlined text.");
        
        doc.save(getArtifactsDir() + "Font.Underlines.docx");

        Example:

        Shows how to insert formatted text using DocumentBuilder.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Specify font formatting, then add text.
        Font font = builder.getFont();
        font.setSize(16.0);
        font.setBold(true);
        font.setColor(Color.BLUE);
        font.setName("Courier New");
        font.setUnderline(Underline.DASH);
        
        builder.write("Hello world!");

        Example:

        Shows how to insert a hyperlink field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("For more information, please visit the ");
        
        // Insert a hyperlink, and apply formatting to emphasize it.
        // The hyperlink will be a clickable piece of text which will take us to the location specified in the URL.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Aspose website", "http://www.aspose.com", false);
        builder.getFont().clearFormatting();
        builder.writeln(".");
        
        // Ctrl + left clicking the link in the text in Microsoft Word will take us to the URL via a new web browser window.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlink.docx");
      • getUnderlineColor/setUnderlineColor

        public java.awt.Color getUnderlineColor() / public void setUnderlineColor(java.awt.Color value)
        
        Gets or sets the color of the underline applied to the font.

        Example:

        Shows how to configure the style and color of a text underline.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getFont().setUnderline(Underline.DOTTED);
        builder.getFont().setUnderlineColor(Color.RED);
        
        builder.writeln("Underlined text.");
        
        doc.save(getArtifactsDir() + "Font.Underlines.docx");
    • Method Detail

      • clearFormatting

        public void clearFormatting()
        Resets to default font formatting.

        Removes all font formatting specified explicitly on the object from which Font was obtained so the font formatting will be inherited from the appropriate parent.

        Example:

        Shows how to insert a hyperlink field.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.write("For more information, please visit the ");
        
        // Insert a hyperlink, and apply formatting to emphasize it.
        // The hyperlink will be a clickable piece of text which will take us to the location specified in the URL.
        builder.getFont().setColor(Color.BLUE);
        builder.getFont().setUnderline(Underline.SINGLE);
        builder.insertHyperlink("Aspose website", "http://www.aspose.com", false);
        builder.getFont().clearFormatting();
        builder.writeln(".");
        
        // Ctrl + left clicking the link in the text in Microsoft Word will take us to the URL via a new web browser window.
        doc.save(getArtifactsDir() + "DocumentBuilder.InsertHyperlink.docx");
      • hasDmlEffect

        public boolean hasDmlEffect(int dmlEffectType)
        Checks if particular DrawingML text effect is applied.
        Parameters:
        dmlEffectType - A TextDmlEffect value. DrawingML text effect type.
        Returns:
        True if particular DrawingML text effect is applied.

        Example:

        Shows how to check if a run displays a DrawingML text effect.
        Document doc = new Document(getMyDir() + "DrawingML text effects.docx");
        
        RunCollection runs = doc.getFirstSection().getBody().getFirstParagraph().getRuns();
        
        Assert.assertTrue(runs.get(0).getFont().hasDmlEffect(TextDmlEffect.SHADOW));
        Assert.assertTrue(runs.get(1).getFont().hasDmlEffect(TextDmlEffect.SHADOW));
        Assert.assertTrue(runs.get(2).getFont().hasDmlEffect(TextDmlEffect.REFLECTION));
        Assert.assertTrue(runs.get(3).getFont().hasDmlEffect(TextDmlEffect.EFFECT_3_D));
        Assert.assertTrue(runs.get(4).getFont().hasDmlEffect(TextDmlEffect.FILL));