com.aspose.words
Class Font

java.lang.Object
    extended by 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 add a formatted run of text to a document using the object model.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Create a new run of text.
Run run = new Run(doc, "Hello");

// Specify character formatting for the run of text.
Font f = run.getFont();
f.setName("Courier New");
f.setSize(36);
f.setHighlightColor(Color.YELLOW);

// Append the run of text to the end of the first paragraph
// in the body of the first section of the document.
doc.getFirstSection().getBody().getParagraphs().get(0).appendChild(run);

Example:

Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Document doc = new Document();

// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.removeAllChildren();


// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
Section section = new Section(doc);

// Append the section to the document.
doc.appendChild(section);

// Lets set some properties for the section.
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);


// The section that we created is empty, lets populate it. The section needs at least the Body node.
Body body = new Body(doc);
section.appendChild(body);


// The body needs to have at least one paragraph.
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document.
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information.
Paragraph para = new Paragraph(doc);
body.appendChild(para);

// We can set some formatting for the paragraph
para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);


// So far we have one empty pararagraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);


// As a matter of interest, you can retrieve text of the whole document and
// see that \u000c is automatically appended. \u000c is the end of section character.
Assert.assertEquals("Hello World!\u000c", doc.getText());

// Save the document.
doc.save(getMyDir() + "Section.CreateFromScratch Out.doc");

Property Getters/Setters Summary
booleangetAllCaps()
voidsetAllCaps(boolean value)
           True if the font is formatted as all capital letters.
booleangetBidi()
voidsetBidi(boolean value)
           True to specify that the reading order for this run shall be right to left.
booleangetBold()
voidsetBold(boolean value)
           True if the font is formatted as bold.
booleangetBoldBi()
voidsetBoldBi(boolean value)
           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()
voidsetColor(java.awt.Color value)
           Gets or sets the color of the font.
booleangetComplexScript()
voidsetComplexScript(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.
booleangetDoubleStrikeThrough()
voidsetDoubleStrikeThrough(boolean value)
           True if the font is formatted as double strikethrough text.
booleangetEmboss()
voidsetEmboss(boolean value)
           True if the font is formatted as embossed.
booleangetEngrave()
voidsetEngrave(boolean value)
           True if the font is formatted as engraved.
booleangetHidden()
voidsetHidden(boolean value)
           True if the font is formatted as hidden text.
java.awt.ColorgetHighlightColor()
voidsetHighlightColor(java.awt.Color value)
           Gets or sets the highlight (marker) color.
booleangetItalic()
voidsetItalic(boolean value)
           True if the font is formatted as italic.
booleangetItalicBi()
voidsetItalicBi(boolean value)
           True if the right-to-left text is formatted as italic.
doublegetKerning()
voidsetKerning(double value)
           Gets or sets the font size at which kerning starts.
intgetLocaleId()
voidsetLocaleId(int value)
           Gets or sets the locale identifier (language) of the formatted characters.
intgetLocaleIdBi()
voidsetLocaleIdBi(int value)
           Gets or sets the locale identifier (language) of the formatted right-to-left characters.
intgetLocaleIdFarEast()
voidsetLocaleIdFarEast(int value)
           Gets or sets the locale identifier (language) of the formatted Asian characters.
java.lang.StringgetName()
voidsetName(java.lang.String value)
           Gets or sets the name of the font.
java.lang.StringgetNameAscii()
voidsetNameAscii(java.lang.String value)
           Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
java.lang.StringgetNameBi()
voidsetNameBi(java.lang.String value)
           Returns or sets the name of the font in a right-to-left language document.
java.lang.StringgetNameFarEast()
voidsetNameFarEast(java.lang.String value)
           Returns or sets an East Asian font name.
java.lang.StringgetNameOther()
voidsetNameOther(java.lang.String value)
           Returns or sets the font used for characters with character codes from 128 through 255.
booleangetNoProofing()
voidsetNoProofing(boolean value)
           True when the formatted characters are not to be spell checked.
booleangetOutline()
voidsetOutline(boolean value)
           True of the font is formatted as outline.
doublegetPosition()
voidsetPosition(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.
intgetScaling()
voidsetScaling(int value)
           Gets or sets character width scaling in percent.
ShadinggetShading()
           Returns a Shading object that refers to the shading formatting for the font.
booleangetShadow()
voidsetShadow(boolean value)
           True if the font is formatted as shadowed.
doublegetSize()
voidsetSize(double value)
           Gets or sets the font size in points.
doublegetSizeBi()
voidsetSizeBi(double value)
           Gets or sets the font size in points used in a right-to-left document.
booleangetSmallCaps()
voidsetSmallCaps(boolean value)
           True if the font is formatted as small capital letters.
doublegetSpacing()
voidsetSpacing(double value)
           Returns or sets the spacing (in points) between characters .
booleangetStrikeThrough()
voidsetStrikeThrough(boolean value)
           True if the font is formatted as strikethrough text.
StylegetStyle()
voidsetStyle(Style value)
           Gets or sets the character style applied to this formatting.
intgetStyleIdentifier()
voidsetStyleIdentifier(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.
java.lang.StringgetStyleName()
voidsetStyleName(java.lang.String value)
           Gets or sets the name of the character style applied to this formatting.
booleangetSubscript()
voidsetSubscript(boolean value)
           True if the font is formatted as subscript.
booleangetSuperscript()
voidsetSuperscript(boolean value)
           True if the font is formatted as superscript.
intgetTextEffect()
voidsetTextEffect(int value)
           Gets or sets the font animation effect. The value of the property is TextEffect integer constant.
intgetUnderline()
voidsetUnderline(int value)
           Gets or sets the type of underline applied to the font. The value of the property is Underline integer constant.
java.awt.ColorgetUnderlineColor()
voidsetUnderlineColor(java.awt.Color value)
           Gets or sets the color of the underline applied to the font.
 
Method Summary
voidclearFormatting()
           Resets to default font formatting.
java.lang.ObjectfetchInheritedBorderAttr(int key)
          Reserved for internal use.
java.lang.ObjectfetchInheritedShadingAttr(int key)
          Reserved for internal use.
java.lang.ObjectgetDirectBorderAttr(int key)
          Reserved for internal use.
voidsetBorderAttr(int key, java.lang.Object value)
          Reserved for internal use.
 

Property Getters/Setters Detail

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:

Inserts formatted text using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);

builder.write("Sample text.");

Example:

Shows how to add a formatted run of text to a document using the object model.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Create a new run of text.
Run run = new Run(doc, "Hello");

// Specify character formatting for the run of text.
Font f = run.getFont();
f.setName("Courier New");
f.setSize(36);
f.setHighlightColor(Color.YELLOW);

// Append the run of text to the end of the first paragraph
// in the body of the first section of the document.
doc.getFirstSection().getBody().getParagraphs().get(0).appendChild(run);

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:

A pretty unusual example of how Microsoft Word can combine two different fonts in one run.
DocumentBuilder builder = new DocumentBuilder();

// This tells Microsoft Word to use Arial for characters 0..127 and
// Times New Roman for characters 128..255.
// Looks like a pretty strange case to me, but it is possible.
builder.getFont().setNameAscii("Arial");
builder.getFont().setNameOther("Times New Roman");

builder.writeln("Hello, Привет");

builder.getDocument().save(getMyDir() + "Font.Names Out.doc");
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 insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");
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 Chinese or any other Far East language.
DocumentBuilder builder = new DocumentBuilder();

builder.getFont().setSize(48);

// Specify the font name. Make sure it the font has the glyphs that you want to dislplay.
builder.getFont().setNameFarEast("SimSun");

// Specify the locale so Microsoft Word recognizes this text as Chinese.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdFarEast(2052);

// Insert some Chinese text.
builder.writeln("你好世界");

builder.getDocument().save(getMyDir() + "Font.FarEast Out.doc");
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:

A pretty unusual example of how Microsoft Word can combine two different fonts in one run.
DocumentBuilder builder = new DocumentBuilder();

// This tells Microsoft Word to use Arial for characters 0..127 and
// Times New Roman for characters 128..255.
// Looks like a pretty strange case to me, but it is possible.
builder.getFont().setNameAscii("Arial");
builder.getFont().setNameOther("Times New Roman");

builder.writeln("Hello, Привет");

builder.getDocument().save(getMyDir() + "Font.Names Out.doc");
See Also:
Name

getSize/setSize

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

Example:

Inserts formatted text using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);

builder.write("Sample text.");

Example:

Shows how to add a formatted run of text to a document using the object model.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Create a new run of text.
Run run = new Run(doc, "Hello");

// Specify character formatting for the run of text.
Font f = run.getFont();
f.setName("Courier New");
f.setSize(36);
f.setHighlightColor(Color.YELLOW);

// Append the run of text to the end of the first paragraph
// in the body of the first section of the document.
doc.getFirstSection().getBody().getParagraphs().get(0).appendChild(run);

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 insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");

getBold/setBold

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

Example:

Inserts formatted text using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);

builder.write("Sample text.");

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 insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");

getItalic/setItalic

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

Example:

Shows how to create a run of formatted text.
Run run = new Run(doc, "Hello");
run.getFont().setEmboss(true);
run.getFont().setItalic(true);

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 insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");

getColor/setColor

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

Example:

Inserts formatted text using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);

builder.write("Sample text.");

Example:

Inserts a hyperlink into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.write("Please make sure to visit ");

// Specify font formatting for the hyperlink.
builder.getFont().setColor(Color.BLUE);
builder.getFont().setUnderline(Underline.SINGLE);
// Insert the link.
builder.insertHyperlink("Aspose Website", "http://www.aspose.com", false);

// Revert to default formatting.
builder.getFont().clearFormatting();

builder.write(" for more information.");

doc.save(getMyDir() + "DocumentBuilder.InsertHyperlink Out.doc");

getStrikeThrough/setStrikeThrough

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

Example:

Shows how to use strike-through character formatting properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

Run run = new Run(doc, "Double strike through text");
run.getFont().setDoubleStrikeThrough(true);
para.appendChild(run);

run = new Run(doc, "Single strike through text");
run.getFont().setStrikeThrough(true);
para.appendChild(run);

getDoubleStrikeThrough/setDoubleStrikeThrough

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

Example:

Shows how to use strike-through character formatting properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

Run run = new Run(doc, "Double strike through text");
run.getFont().setDoubleStrikeThrough(true);
para.appendChild(run);

run = new Run(doc, "Single strike through text");
run.getFont().setStrikeThrough(true);
para.appendChild(run);

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.
Run run = new Run(doc, "Hello");
run.getFont().setEngrave(true);

getOutline/setOutline

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

Example:

Shows how to create a run of text formatted as outline.
Run run = new Run(doc, "Hello");
run.getFont().setOutline(true);

getEmboss/setEmboss

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

Example:

Shows how to create a run of formatted text.
Run run = new Run(doc, "Hello");
run.getFont().setEmboss(true);
run.getFont().setItalic(true);

getEngrave/setEngrave

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

Example:

Shows how to create a run of text formatted as engraved.
Run run = new Run(doc, "Hello");
run.getFont().setEngrave(true);

getSuperscript/setSuperscript

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

Example:

Shows how to use subscript, superscript and baseline text position properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

// Add a run of text that is raised 5 points above the baseline.
Run run = new Run(doc, "Raised text");
run.getFont().setPosition(5);
para.appendChild(run);

// Add a run of normal text.
run = new Run(doc, "Normal text");
para.appendChild(run);
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);

getSubscript/setSubscript

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

Example:

Shows how to use subscript, superscript and baseline text position properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

// Add a run of text that is raised 5 points above the baseline.
Run run = new Run(doc, "Raised text");
run.getFont().setPosition(5);
para.appendChild(run);

// Add a run of normal text.
run = new Run(doc, "Normal text");
para.appendChild(run);
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);

getSmallCaps/setSmallCaps

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

Example:

Shows how to use all capitals and small capitals character formatting properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

Run run = new Run(doc, "All capitals");
run.getFont().setAllCaps(true);
para.appendChild(run);

run = new Run(doc, "SMALL CAPITALS");
run.getFont().setSmallCaps(true);
para.appendChild(run);

getAllCaps/setAllCaps

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

Example:

Shows how to use all capitals and small capitals character formatting properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

Run run = new Run(doc, "All capitals");
run.getFont().setAllCaps(true);
para.appendChild(run);

run = new Run(doc, "SMALL CAPITALS");
run.getFont().setSmallCaps(true);
para.appendChild(run);

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 hidden run of text.
Run run = new Run(doc, "Hello");
run.getFont().setHidden(true);

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 use the underline character formatting properties.
Run run = new Run(doc, "Hello");
run.getFont().setUnderline(Underline.DOTTED);
run.getFont().setUnderlineColor(Color.RED);

Example:

Inserts formatted text using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();

// Specify font formatting before adding text.
Font font = builder.getFont();
font.setSize(16);
font.setBold(true);
font.setColor(Color.BLUE);
font.setName("Arial");
font.setUnderline(Underline.DASH);

builder.write("Sample text.");

Example:

Inserts a hyperlink into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.write("Please make sure to visit ");

// Specify font formatting for the hyperlink.
builder.getFont().setColor(Color.BLUE);
builder.getFont().setUnderline(Underline.SINGLE);
// Insert the link.
builder.insertHyperlink("Aspose Website", "http://www.aspose.com", false);

// Revert to default formatting.
builder.getFont().clearFormatting();

builder.write(" for more information.");

doc.save(getMyDir() + "DocumentBuilder.InsertHyperlink Out.doc");

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 use the underline character formatting properties.
Run run = new Run(doc, "Hello");
run.getFont().setUnderline(Underline.DOTTED);
run.getFont().setUnderlineColor(Color.RED);

getScaling/setScaling

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

Example:

Shows how to use character scaling and spacing properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

// Add a run of text with characters 150% width of normal characters.
Run run = new Run(doc, "Wide characters");
run.getFont().setScaling(150);
para.appendChild(run);

// Add a run of text with extra 1pt space between characters.
run = new Run(doc, "Expanded by 1pt");
run.getFont().setSpacing(1);
para.appendChild(run);

// Add a run of text with with space between characters reduced by 1pt.
run = new Run(doc, "Condensed by 1pt");
run.getFont().setSpacing(-1);
para.appendChild(run);

getSpacing/setSpacing

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

Example:

Shows how to use character scaling and spacing properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

// Add a run of text with characters 150% width of normal characters.
Run run = new Run(doc, "Wide characters");
run.getFont().setScaling(150);
para.appendChild(run);

// Add a run of text with extra 1pt space between characters.
run = new Run(doc, "Expanded by 1pt");
run.getFont().setSpacing(1);
para.appendChild(run);

// Add a run of text with with space between characters reduced by 1pt.
run = new Run(doc, "Condensed by 1pt");
run.getFont().setSpacing(-1);
para.appendChild(run);

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 use subscript, superscript and baseline text position properties.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Get the paragraph from the document, we will be adding runs of text to it.
Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 0, true);

// Add a run of text that is raised 5 points above the baseline.
Run run = new Run(doc, "Raised text");
run.getFont().setPosition(5);
para.appendChild(run);

// Add a run of normal text.
run = new Run(doc, "Normal text");
para.appendChild(run);
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);

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 starts.
Run run = new Run(doc, "Hello");
run.getFont().setKerning(24);

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 add a formatted run of text to a document using the object model.
// Create an empty document. It contains one empty paragraph.
Document doc = new Document();

// Create a new run of text.
Run run = new Run(doc, "Hello");

// Specify character formatting for the run of text.
Font f = run.getFont();
f.setName("Courier New");
f.setSize(36);
f.setHighlightColor(Color.YELLOW);

// Append the run of text to the end of the first paragraph
// in the body of the first section of the document.
doc.getFirstSection().getBody().getParagraphs().get(0).appendChild(run);

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.

getBidi/setBidi

public boolean getBidi() / public void setBidi(boolean value)
True to specify that the reading order for this run shall be right to left.

This setting determines the way in which the run contents are presented in the document when punctuation characters are part of the run's contents.

Example:

Shows how to insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");

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.

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 specify that the run of text is not to be spell checked by Microsoft Word.
Run run = new Run(doc, "Hello");
run.getFont().setNoProofing(true);

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 http://www.microsoft.com/globaldev/reference/lcid-all.mspx.

Example:

Shows how to specify the language of a text run so Microsoft Word can use a proper spell checker.
//Create a run of text that contains Russian text.
Run run = new Run(doc, "Привет");

//Specify the locale so Microsoft Word recognizes this text as Russian.
//For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
run.getFont().setLocaleId(1049);

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 http://www.microsoft.com/globaldev/reference/lcid-all.mspx

Example:

Shows how to insert and format right-to-left text.
DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);

// Specify the font and font size to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
builder.getFont().setSizeBi(48);

// Specify that the right-to-left text in this run is bold and italic.
builder.getFont().setItalicBi(true);
builder.getFont().setBoldBi(true);

// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.
builder.writeln("مرحبًا");

builder.getDocument().save(getMyDir() + "Font.Bidi Out.doc");

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 http://www.microsoft.com/globaldev/reference/lcid-all.mspx

Example:

Shows how to insert and format text in Chinese or any other Far East language.
DocumentBuilder builder = new DocumentBuilder();

builder.getFont().setSize(48);

// Specify the font name. Make sure it the font has the glyphs that you want to dislplay.
builder.getFont().setNameFarEast("SimSun");

// Specify the locale so Microsoft Word recognizes this text as Chinese.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdFarEast(2052);

// Insert some Chinese text.
builder.writeln("你好世界");

builder.getDocument().save(getMyDir() + "Font.FarEast Out.doc");

getBorder

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

Example:

Inserts a string surrounded by a border into a document.
DocumentBuilder builder = new DocumentBuilder();

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

builder.write("run of text in a green border");

getShading

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

Example:

Shows how to apply shading for a run of text.
DocumentBuilder builder = new DocumentBuilder();

Shading shd = builder.getFont().getShading();
shd.setTexture(TextureIndex.TEXTURE_DIAGONAL_CROSS);
shd.setBackgroundPatternColor(Color.BLUE);
shd.setForegroundPatternColor(Color.BLACK);

builder.getFont().setColor(Color.WHITE);

builder.writeln("White text on a blue background with texture.");

getStyle/setStyle

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

Example:

Applies double underline to all runs in a document that are formatted with custom character styles.
Document doc = new Document(getMyDir() + "Font.Style.doc");

// Select all run nodes in the document.
NodeCollection<Run> runs = doc.getChildNodes(NodeType.RUN, true);

// Loop through every run node.
for (Run run : runs)
{
    Style charStyle = run.getFont().getStyle();

    // If the style of the run is not a built-in character style, apply double underline.
    if (!charStyle.getBuiltIn())
        run.getFont().setUnderline(Underline.DOUBLE);
}

doc.save(getMyDir() + "Font.Style Out.doc");

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 use style name to find text formatted with a specific character style and apply different character style.
Document doc = new Document(getMyDir() + "Font.StyleName.doc");

// Select all run nodes in the document.
NodeCollection<Run> runs = doc.getChildNodes(NodeType.RUN, true);

// Loop through every run node.
for (Run run : runs)
{
    // If the character style of the run is what we want, do what we need. Change the style in this case.
    // Note that names of built in styles could be different in documents
    // created by Microsoft Word versions for different languages.
    if ("Emphasis".equals(run.getFont().getStyleName()))
        run.getFont().setStyleName("Strong");
}

doc.save(getMyDir() + "Font.StyleName Out.doc");

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 use style identifier to find text formatted with a specific character style and apply different character style.
Document doc = new Document(getMyDir() + "Font.StyleIdentifier.doc");

// Select all run nodes in the document.
NodeCollection<Run> runs = doc.getChildNodes(NodeType.RUN, true);

// Loop through every run node.
for (Run run : runs)
{
    // If the character style of the run is what we want, do what we need. Change the style in this case.
    // Note that using StyleIdentifier we can identify a built-in style regardless
    // of the language of Microsoft Word used to create the document.
    if (run.getFont().getStyleIdentifier() == StyleIdentifier.EMPHASIS)
        run.getFont().setStyleIdentifier(StyleIdentifier.STRONG);
}

doc.save(getMyDir() + "Font.StyleIdentifier Out.doc");

Method Detail

clearFormatting

public void clearFormatting()
                    throws java.lang.Exception
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:

Inserts a hyperlink into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.write("Please make sure to visit ");

// Specify font formatting for the hyperlink.
builder.getFont().setColor(Color.BLUE);
builder.getFont().setUnderline(Underline.SINGLE);
// Insert the link.
builder.insertHyperlink("Aspose Website", "http://www.aspose.com", false);

// Revert to default formatting.
builder.getFont().clearFormatting();

builder.write(" for more information.");

doc.save(getMyDir() + "DocumentBuilder.InsertHyperlink Out.doc");

getDirectBorderAttr

public java.lang.Object getDirectBorderAttr(int key)
                          throws java.lang.Exception
Reserved for internal use.

fetchInheritedBorderAttr

public java.lang.Object fetchInheritedBorderAttr(int key)
                               throws java.lang.Exception
Reserved for internal use.

setBorderAttr

public void setBorderAttr(int key, java.lang.Object value)
                  throws java.lang.Exception
Reserved for internal use.

fetchInheritedShadingAttr

public java.lang.Object fetchInheritedShadingAttr(int key)
                                throws java.lang.Exception
Reserved for internal use.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.