|
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 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 |
boolean | getAllCaps() | | void | setAllCaps(boolean value) | |
|
True if the font is formatted as all capital letters.
|
boolean | getBidi() | | void | setBidi(boolean value) | |
|
True if the formatted characters are right-to-left.
|
boolean | getBold() | | void | setBold(boolean value) | |
|
True if the font is formatted as bold.
|
boolean | getBoldBi() | | void | setBoldBi(boolean value) | |
|
True if the right-to-left text is formatted as bold.
|
Border | getBorder() | | |
Returns a Border object that specifies border for the font.
|
java.awt.Color | getColor() | | void | setColor(java.awt.Color value) | |
|
Gets or sets the color of the font.
|
boolean | getDoubleStrikeThrough() | | void | setDoubleStrikeThrough(boolean value) | |
|
True if the font is formatted as double strikethrough text.
|
boolean | getEmboss() | | void | setEmboss(boolean value) | |
|
True if the font is formatted as embossed.
|
boolean | getEngrave() | | void | setEngrave(boolean value) | |
|
True if the font is formatted as engraved.
|
boolean | getHidden() | | void | setHidden(boolean value) | |
|
True if the font is formatted as hidden text.
|
java.awt.Color | getHighlightColor() | | void | setHighlightColor(java.awt.Color value) | |
|
Gets or sets the highlight (marker) color.
|
boolean | getItalic() | | void | setItalic(boolean value) | |
|
True if the font is formatted as italic.
|
boolean | getItalicBi() | | void | setItalicBi(boolean value) | |
|
True if the right-to-left text is formatted as italic.
|
double | getKerning() | | void | setKerning(double value) | |
|
Gets or sets the font size at which kerning starts.
|
int | getLocaleId() | | void | setLocaleId(int value) | |
|
Gets or sets the locale identifier (language) of the formatted characters.
|
int | getLocaleIdBi() | | void | setLocaleIdBi(int value) | |
|
Gets or sets the locale identifier (language) of the formatted right-to-left characters.
|
int | getLocaleIdFarEast() | | void | setLocaleIdFarEast(int value) | |
|
Gets or sets the locale identifier (language) of the formatted Asian characters.
|
java.lang.String | getName() | | void | setName(java.lang.String value) | |
|
Gets or sets the name of the font.
|
java.lang.String | getNameAscii() | | void | setNameAscii(java.lang.String value) | |
|
Returns or sets the font used for Latin text (characters with character codes from 0 (zero) through 127).
|
java.lang.String | getNameBi() | | void | setNameBi(java.lang.String value) | |
|
Returns or sets the name of the font in a right-to-left language document.
|
java.lang.String | getNameFarEast() | | void | setNameFarEast(java.lang.String value) | |
|
Returns or sets an East Asian font name.
|
java.lang.String | getNameOther() | | void | setNameOther(java.lang.String value) | |
|
Returns or sets the font used for characters with character codes from 128 through 255.
|
boolean | getNoProofing() | | void | setNoProofing(boolean value) | |
|
True when the formatted characters are not to be spell checked.
|
boolean | getOutline() | | void | setOutline(boolean value) | |
|
True of the font is formatted as outline.
|
double | getPosition() | | 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.
|
int | getScaling() | | void | setScaling(int value) | |
|
Gets or sets character width scaling in percent.
|
Shading | getShading() | | |
Returns a Shading object that refers to the shading formatting for the font.
|
boolean | getShadow() | | void | setShadow(boolean value) | |
|
True if the font is formatted as shadowed.
|
double | getSize() | | void | setSize(double value) | |
|
Gets or sets the font size in points.
|
double | getSizeBi() | | void | setSizeBi(double value) | |
|
Gets or sets the font size in points used in a right-to-left document.
|
boolean | getSmallCaps() | | void | setSmallCaps(boolean value) | |
|
True if the font is formatted as small capital letters.
|
double | getSpacing() | | void | setSpacing(double value) | |
|
Returns or sets the spacing (in points) between characters .
|
boolean | getStrikeThrough() | | void | setStrikeThrough(boolean value) | |
|
True if the font is formatted as strikethrough text.
|
Style | getStyle() | | void | setStyle(Style value) | |
|
Gets or se | |