java.lang.Object
com.aspose.words.FontInfo
public class FontInfo
To learn more, visit the Working with Fonts documentation article. You do not create instances of this class directly.
Use the Example:
Document doc = new Document(getMyDir() + "Embedded font.docx");
FontInfoCollection allFonts = doc.getFontInfos();
// Print all the used and unused fonts in the document.
for (int i = 0; i < allFonts.getCount(); i++) {
System.out.println("Font index #{i}");
System.out.println("\tName: {allFonts[i].Name}");
}
| Property Getters/Setters Summary | ||
|---|---|---|
java.lang.String | getAltName() | |
void | setAltName(java.lang.String value) | |
| Gets or sets the alternate name for the font. | ||
int | getCharset() | |
void | setCharset(int value) | |
| Gets or sets the character set for the font. | ||
FontEmbeddingLicensingRights | getEmbeddingLicensingRights() | |
| Gets the embedded font licensing rights. | ||
int | getFamily() | |
void | setFamily(int value) | |
| Gets or sets the font family this font belongs to. The value of the property is FontFamily integer constant. | ||
boolean | isTrueType() | |
void | isTrueType(boolean value) | |
Indicates that this font is a TrueType or OpenType font as opposed to a raster or vector font.
Default is true.
|
||
java.lang.String | getName() | |
| Gets the name of the font. | ||
byte[] | getPanose() | |
void | setPanose(byte[] value) | |
| Gets or sets the PANOSE typeface classification number. | ||
int | getPitch() | |
void | setPitch(int value) | |
| The pitch indicates if the font is fixed pitch, proportionally spaced, or relies on a default setting. The value of the property is FontPitch integer constant. | ||
| Method Summary | ||
|---|---|---|
byte[] | getEmbeddedFont(int format, int style) | |
| Gets a specific embedded font file. | ||
byte[] | getEmbeddedFontAsOpenType(int style) | |
| Gets an embedded font file in OpenType format. Fonts in Embedded OpenType format are converted to OpenType. | ||
| Property Getters/Setters Detail |
|---|
getAltName/setAltName | |
public java.lang.String getAltName() / public void setAltName(java.lang.String value) | |
Cannot be null. Can be an empty string.
Example:
Shows how to access and print details of each font in a document.
Document doc = new Document(getMyDir() + "Document.docx");
Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
while (fontCollectionEnumerator.hasNext()) {
FontInfo fontInfo = fontCollectionEnumerator.next();
if (fontInfo != null) {
System.out.println("Font name: " + fontInfo.getName());
// Alt names are usually blank.
System.out.println("Alt name: " + fontInfo.getAltName());
System.out.println("\t- Family: " + fontInfo.getFamily());
System.out.println("\t- " + (fontInfo.isTrueType() ? "Is TrueType" : "Is not TrueType"));
System.out.println("\t- Pitch: " + fontInfo.getPitch());
System.out.println("\t- Charset: " + fontInfo.getCharset());
System.out.println("\t- Panose:");
System.out.println("\t\tFamily Kind: " + (fontInfo.getPanose()[0] & 0xFF));
System.out.println("\t\tSerif Style: " + (fontInfo.getPanose()[1] & 0xFF));
System.out.println("\t\tWeight: " + (fontInfo.getPanose()[2] & 0xFF));
System.out.println("\t\tProportion: " + (fontInfo.getPanose()[3] & 0xFF));
System.out.println("\t\tContrast: " + (fontInfo.getPanose()[4] & 0xFF));
System.out.println("\t\tStroke Variation: " + (fontInfo.getPanose()[5] & 0xFF));
System.out.println("\t\tArm Style: " + (fontInfo.getPanose()[6] & 0xFF));
System.out.println("\t\tLetterform: " + (fontInfo.getPanose()[7] & 0xFF));
System.out.println("\t\tMidline: " + (fontInfo.getPanose()[8] & 0xFF));
System.out.println("\t\tX-Height: " + (fontInfo.getPanose()[9] & 0xFF));
}
}getCharset/setCharset | |
public int getCharset() / public void setCharset(int value) | |
Example:
Shows how to access and print details of each font in a document.
Document doc = new Document(getMyDir() + "Document.docx");
Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
while (fontCollectionEnumerator.hasNext()) {
FontInfo fontInfo = fontCollectionEnumerator.next();
if (fontInfo != null) {
System.out.println("Font name: " + fontInfo.getName());
// Alt names are usually blank.
System.out.println("Alt name: " + fontInfo.getAltName());
System.out.println("\t- Family: " + fontInfo.getFamily());
System.out.println("\t- " + (fontInfo.isTrueType() ? "Is TrueType" : "Is not TrueType"));
System.out.println("\t- Pitch: " + fontInfo.getPitch());
System.out.println("\t- Charset: " + fontInfo.getCharset());
System.out.println("\t- Panose:");
System.out.println("\t\tFamily Kind: " + (fontInfo.getPanose()[0] & 0xFF));
System.out.println("\t\tSerif Style: " + (fontInfo.getPanose()[1] & 0xFF));
System.out.println("\t\tWeight: " + (fontInfo.getPanose()[2] & 0xFF));
System.out.println("\t\tProportion: " + (fontInfo.getPanose()[3] & 0xFF));
System.out.println("\t\tContrast: " + (fontInfo.getPanose()[4] & 0xFF));
System.out.println("\t\tStroke Variation: " + (fontInfo.getPanose()[5] & 0xFF));
System.out.println("\t\tArm Style: " + (fontInfo.getPanose()[6] & 0xFF));
System.out.println("\t\tLetterform: " + (fontInfo.getPanose()[7] & 0xFF));
System.out.println("\t\tMidline: " + (fontInfo.getPanose()[8] & 0xFF));
System.out.println("\t\tX-Height: " + (fontInfo.getPanose()[9] & 0xFF));
}
}getEmbeddingLicensingRights | |
public FontEmbeddingLicensingRights getEmbeddingLicensingRights() | |
The value may be null if font is not embedded.
Example:
Shows how to get license rights information for embedded fonts (FontInfo).
Document doc = new Document(getMyDir() + "Embedded font rights.docx");
// Get the list of document fonts.
FontInfoCollection fontInfos = doc.getFontInfos();
for (FontInfo fontInfo : fontInfos)
{
if (fontInfo.getEmbeddingLicensingRights() != null)
{
System.out.println(fontInfo.getEmbeddingLicensingRights().getEmbeddingUsagePermissions());
System.out.println(fontInfo.getEmbeddingLicensingRights().getBitmapEmbeddingOnly());
System.out.println(fontInfo.getEmbeddingLicensingRights().getNoSubsetting());
}
}getFamily/setFamily | |
public int getFamily() / public void setFamily(int value) | |
Example:
Shows how to access and print details of each font in a document.
Document doc = new Document(getMyDir() + "Document.docx");
Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
while (fontCollectionEnumerator.hasNext()) {
FontInfo fontInfo = fontCollectionEnumerator.next();
if (fontInfo != null) {
System.out.println("Font name: " + fontInfo.getName());
// Alt names are usually blank.
System.out.println("Alt name: " + fontInfo.getAltName());
System.out.println("\t- Family: " + fontInfo.getFamily());
System.out.println("\t- " + (fontInfo.isTrueType() ? "Is TrueType" : "Is not TrueType"));
System.out.println("\t- Pitch: " + fontInfo.getPitch());
System.out.println("\t- Charset: " + fontInfo.getCharset());
System.out.println("\t- Panose:");
System.out.println("\t\tFamily Kind: " + (fontInfo.getPanose()[0] & 0xFF));
System.out.println("\t\tSerif Style: " + (fontInfo.getPanose()[1] & 0xFF));
System.out.println("\t\tWeight: " + (fontInfo.getPanose()[2] & 0xFF));
System.out.println("\t\tProportion: " + (fontInfo.getPanose()[3] & 0xFF));
System.out.println("\t\tContrast: " + (fontInfo.getPanose()[4] & 0xFF));
System.out.println("\t\tStroke Variation: " + (fontInfo.getPanose()[5] & 0xFF));
System.out.println("\t\tArm Style: " + (fontInfo.getPanose()[6] & 0xFF));
System.out.println("\t\tLetterform: " + (fontInfo.getPanose()[7] & 0xFF));
System.out.println("\t\tMidline: " + (fontInfo.getPanose()[8] & 0xFF));
System.out.println("\t\tX-Height: " + (fontInfo.getPanose()[9] & 0xFF));
}
}isTrueType/isTrueType | |
public boolean isTrueType() / public void isTrueType(boolean value) | |
true.
Example:
Shows how to print the details of what fonts are present in a document.
Document doc = new Document(getMyDir() + "Embedded font.docx");
FontInfoCollection allFonts = doc.getFontInfos();
// Print all the used and unused fonts in the document.
for (int i = 0; i < allFonts.getCount(); i++) {
System.out.println("Font index #{i}");
System.out.println("\tName: {allFonts[i].Name}");
}getName | |
public java.lang.String getName() | |
Cannot be null. Can be an empty string.
Example:
Shows how to print the details of what fonts are present in a document.
Document doc = new Document(getMyDir() + "Embedded font.docx");
FontInfoCollection allFonts = doc.getFontInfos();
// Print all the used and unused fonts in the document.
for (int i = 0; i < allFonts.getCount(); i++) {
System.out.println("Font index #{i}");
System.out.println("\tName: {allFonts[i].Name}");
}getPanose/setPanose | |
public byte[] getPanose() / public void setPanose(byte[] value) | |
PANOSE is a compact 10-byte description of a fonts critical visual characteristics, such as contrast, weight, and serif style. The digits represent Family Kind, Serif Style, Weight, Proportion, Contrast, Stroke Variation, Arm Style, Letterform, Midline, and X-Height.
Can be null.
Example:
Shows how to access and print details of each font in a document.
Document doc = new Document(getMyDir() + "Document.docx");
Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
while (fontCollectionEnumerator.hasNext()) {
FontInfo fontInfo = fontCollectionEnumerator.next();
if (fontInfo != null) {
System.out.println("Font name: " + fontInfo.getName());
// Alt names are usually blank.
System.out.println("Alt name: " + fontInfo.getAltName());
System.out.println("\t- Family: " + fontInfo.getFamily());
System.out.println("\t- " + (fontInfo.isTrueType() ? "Is TrueType" : "Is not TrueType"));
System.out.println("\t- Pitch: " + fontInfo.getPitch());
System.out.println("\t- Charset: " + fontInfo.getCharset());
System.out.println("\t- Panose:");
System.out.println("\t\tFamily Kind: " + (fontInfo.getPanose()[0] & 0xFF));
System.out.println("\t\tSerif Style: " + (fontInfo.getPanose()[1] & 0xFF));
System.out.println("\t\tWeight: " + (fontInfo.getPanose()[2] & 0xFF));
System.out.println("\t\tProportion: " + (fontInfo.getPanose()[3] & 0xFF));
System.out.println("\t\tContrast: " + (fontInfo.getPanose()[4] & 0xFF));
System.out.println("\t\tStroke Variation: " + (fontInfo.getPanose()[5] & 0xFF));
System.out.println("\t\tArm Style: " + (fontInfo.getPanose()[6] & 0xFF));
System.out.println("\t\tLetterform: " + (fontInfo.getPanose()[7] & 0xFF));
System.out.println("\t\tMidline: " + (fontInfo.getPanose()[8] & 0xFF));
System.out.println("\t\tX-Height: " + (fontInfo.getPanose()[9] & 0xFF));
}
}getPitch/setPitch | |
public int getPitch() / public void setPitch(int value) | |
Example:
Shows how to access and print details of each font in a document.
Document doc = new Document(getMyDir() + "Document.docx");
Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
while (fontCollectionEnumerator.hasNext()) {
FontInfo fontInfo = fontCollectionEnumerator.next();
if (fontInfo != null) {
System.out.println("Font name: " + fontInfo.getName());
// Alt names are usually blank.
System.out.println("Alt name: " + fontInfo.getAltName());
System.out.println("\t- Family: " + fontInfo.getFamily());
System.out.println("\t- " + (fontInfo.isTrueType() ? "Is TrueType" : "Is not TrueType"));
System.out.println("\t- Pitch: " + fontInfo.getPitch());
System.out.println("\t- Charset: " + fontInfo.getCharset());
System.out.println("\t- Panose:");
System.out.println("\t\tFamily Kind: " + (fontInfo.getPanose()[0] & 0xFF));
System.out.println("\t\tSerif Style: " + (fontInfo.getPanose()[1] & 0xFF));
System.out.println("\t\tWeight: " + (fontInfo.getPanose()[2] & 0xFF));
System.out.println("\t\tProportion: " + (fontInfo.getPanose()[3] & 0xFF));
System.out.println("\t\tContrast: " + (fontInfo.getPanose()[4] & 0xFF));
System.out.println("\t\tStroke Variation: " + (fontInfo.getPanose()[5] & 0xFF));
System.out.println("\t\tArm Style: " + (fontInfo.getPanose()[6] & 0xFF));
System.out.println("\t\tLetterform: " + (fontInfo.getPanose()[7] & 0xFF));
System.out.println("\t\tMidline: " + (fontInfo.getPanose()[8] & 0xFF));
System.out.println("\t\tX-Height: " + (fontInfo.getPanose()[9] & 0xFF));
}
}| Method Detail |
|---|
getEmbeddedFont | |
public byte[] getEmbeddedFont(int format, int style) | |
format - A style - A null if the specified font is not embedded.Example:
Shows how to extract an embedded font from a document, and save it to the local file system.
Document doc = new Document(getMyDir() + "Embedded font.docx");
FontInfo embeddedFont = doc.getFontInfos().get("Alte DIN 1451 Mittelschrift");
byte[] embeddedFontBytes = embeddedFont.getEmbeddedFont(EmbeddedFontFormat.OPEN_TYPE, EmbeddedFontStyle.REGULAR);
FileUtils.writeByteArrayToFile(new File(getArtifactsDir() + "Alte DIN 1451 Mittelschrift.ttf"), embeddedFontBytes);
// Embedded font formats may be different in other formats such as .doc.
// We need to know the correct format before we can extract the font.
doc = new Document(getMyDir() + "Embedded font.doc");
Assert.assertNull(doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFont(EmbeddedFontFormat.OPEN_TYPE, EmbeddedFontStyle.REGULAR));
Assert.assertNotNull(doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFont(EmbeddedFontFormat.EMBEDDED_OPEN_TYPE, EmbeddedFontStyle.REGULAR));
// Also, we can convert embedded OpenType format, which comes from .doc documents, to OpenType.
embeddedFontBytes = doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFontAsOpenType(EmbeddedFontStyle.REGULAR);
FileUtils.writeByteArrayToFile(new File(getArtifactsDir() + "Alte DIN 1451 Mittelschrift.otf"), embeddedFontBytes);getEmbeddedFontAsOpenType | |
public byte[] getEmbeddedFontAsOpenType(int style) | |
style - A null if the specified font is not embedded.Example:
Shows how to extract an embedded font from a document, and save it to the local file system.
Document doc = new Document(getMyDir() + "Embedded font.docx");
FontInfo embeddedFont = doc.getFontInfos().get("Alte DIN 1451 Mittelschrift");
byte[] embeddedFontBytes = embeddedFont.getEmbeddedFont(EmbeddedFontFormat.OPEN_TYPE, EmbeddedFontStyle.REGULAR);
FileUtils.writeByteArrayToFile(new File(getArtifactsDir() + "Alte DIN 1451 Mittelschrift.ttf"), embeddedFontBytes);
// Embedded font formats may be different in other formats such as .doc.
// We need to know the correct format before we can extract the font.
doc = new Document(getMyDir() + "Embedded font.doc");
Assert.assertNull(doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFont(EmbeddedFontFormat.OPEN_TYPE, EmbeddedFontStyle.REGULAR));
Assert.assertNotNull(doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFont(EmbeddedFontFormat.EMBEDDED_OPEN_TYPE, EmbeddedFontStyle.REGULAR));
// Also, we can convert embedded OpenType format, which comes from .doc documents, to OpenType.
embeddedFontBytes = doc.getFontInfos().get("Alte DIN 1451 Mittelschrift").getEmbeddedFontAsOpenType(EmbeddedFontStyle.REGULAR);
FileUtils.writeByteArrayToFile(new File(getArtifactsDir() + "Alte DIN 1451 Mittelschrift.otf"), embeddedFontBytes);