com.aspose.words

Class FontInfo

  • java.lang.Object
    • com.aspose.words.FontInfo
  • All Implemented Interfaces:
    java.lang.Cloneable
    public class FontInfo 
    extends java.lang.Object

Specifies information about a font used in the document.

You do not create instances of this class directly. Use the DocumentBase.FontInfos property to access the collection of fonts defined in a document.

Example:

Shows how to gather the details of what fonts are present in a document.
Document doc = new Document(getMyDir() + "Document.doc");

FontInfoCollection fonts = doc.getFontInfos();
int fontIndex = 1;

// The fonts info extracted from this document does not necessarily mean that the fonts themselves are
// used in the document. If a font is present but not used then most likely they were referenced at some time
// and then removed from the Document.
for (FontInfo info : fonts) {
    // Print out some important details about the font.
    System.out.println(MessageFormat.format("Font #{0}", fontIndex));
    System.out.println(MessageFormat.format("Name: {0}", info.getName()));
    System.out.println(MessageFormat.format("IsTrueType: {0}", info.isTrueType()));
    fontIndex++;
}
See Also:
FontInfoCollection, DocumentBase.FontInfos

Property Getters/Setters Summary
java.lang.StringgetAltName()
void
setAltName(java.lang.Stringvalue)
           Gets or sets the alternate name for the font.
intgetCharset()
void
setCharset(intvalue)
           Gets or sets the character set for the font.
intgetFamily()
void
setFamily(intvalue)
           Gets or sets the font family this font belongs to. The value of the property is FontFamily integer constant.
booleanisTrueType()
void
isTrueType(booleanvalue)
           Indicates that this font is a TrueType or OpenType font as opposed to a raster or vector font. Default is true.
java.lang.StringgetName()
Gets the name of the font.
byte[]getPanose()
void
setPanose(byte[]value)
           Gets or sets the PANOSE typeface classification number.
intgetPitch()
void
setPitch(intvalue)
           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.
 

    • Property Getters/Setters Detail

      • getAltName/setAltName

        public java.lang.String getAltName() / public void setAltName(java.lang.String value)
        
        Gets or sets the alternate name for the font.

        Cannot be null. Can be an empty string.

        Example:

        Shows how to get information about each font in a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        
        // We can iterate over all the fonts with an enumerator
        Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
        // Print detailed information about each font to the console
        while (fontCollectionEnumerator.hasNext()) {
            FontInfo fontInfo = fontCollectionEnumerator.next();
            if (fontInfo != null) {
                System.out.println("Font name: " + fontInfo.getName());
                System.out.println("Alt name: " + fontInfo.getAltName()); // Alt names are usually blank
                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)
        
        Gets or sets the character set for the font.

        Example:

        Shows how to get information about each font in a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        
        // We can iterate over all the fonts with an enumerator
        Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
        // Print detailed information about each font to the console
        while (fontCollectionEnumerator.hasNext()) {
            FontInfo fontInfo = fontCollectionEnumerator.next();
            if (fontInfo != null) {
                System.out.println("Font name: " + fontInfo.getName());
                System.out.println("Alt name: " + fontInfo.getAltName()); // Alt names are usually blank
                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));
            }
        }
      • getFamily/setFamily

        public int getFamily() / public void setFamily(int value)
        
        Gets or sets the font family this font belongs to. The value of the property is FontFamily integer constant.

        Example:

        Shows how to get information about each font in a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        
        // We can iterate over all the fonts with an enumerator
        Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
        // Print detailed information about each font to the console
        while (fontCollectionEnumerator.hasNext()) {
            FontInfo fontInfo = fontCollectionEnumerator.next();
            if (fontInfo != null) {
                System.out.println("Font name: " + fontInfo.getName());
                System.out.println("Alt name: " + fontInfo.getAltName()); // Alt names are usually blank
                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)
        
        Indicates that this font is a TrueType or OpenType font as opposed to a raster or vector font. Default is true.

        Example:

        Shows how to gather the details of what fonts are present in a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        FontInfoCollection fonts = doc.getFontInfos();
        int fontIndex = 1;
        
        // The fonts info extracted from this document does not necessarily mean that the fonts themselves are
        // used in the document. If a font is present but not used then most likely they were referenced at some time
        // and then removed from the Document.
        for (FontInfo info : fonts) {
            // Print out some important details about the font.
            System.out.println(MessageFormat.format("Font #{0}", fontIndex));
            System.out.println(MessageFormat.format("Name: {0}", info.getName()));
            System.out.println(MessageFormat.format("IsTrueType: {0}", info.isTrueType()));
            fontIndex++;
        }
      • getName

        public java.lang.String getName()
        
        Gets the name of the font.

        Cannot be null. Can be an empty string.

        Example:

        Shows how to gather the details of what fonts are present in a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        
        FontInfoCollection fonts = doc.getFontInfos();
        int fontIndex = 1;
        
        // The fonts info extracted from this document does not necessarily mean that the fonts themselves are
        // used in the document. If a font is present but not used then most likely they were referenced at some time
        // and then removed from the Document.
        for (FontInfo info : fonts) {
            // Print out some important details about the font.
            System.out.println(MessageFormat.format("Font #{0}", fontIndex));
            System.out.println(MessageFormat.format("Name: {0}", info.getName()));
            System.out.println(MessageFormat.format("IsTrueType: {0}", info.isTrueType()));
            fontIndex++;
        }
      • getPanose/setPanose

        public byte[] getPanose() / public void setPanose(byte[] value)
        
        Gets or sets the PANOSE typeface classification number.

        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 get information about each font in a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        
        // We can iterate over all the fonts with an enumerator
        Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
        // Print detailed information about each font to the console
        while (fontCollectionEnumerator.hasNext()) {
            FontInfo fontInfo = fontCollectionEnumerator.next();
            if (fontInfo != null) {
                System.out.println("Font name: " + fontInfo.getName());
                System.out.println("Alt name: " + fontInfo.getAltName()); // Alt names are usually blank
                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)
        
        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.

        Example:

        Shows how to get information about each font in a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        
        // We can iterate over all the fonts with an enumerator
        Iterator<FontInfo> fontCollectionEnumerator = doc.getFontInfos().iterator();
        // Print detailed information about each font to the console
        while (fontCollectionEnumerator.hasNext()) {
            FontInfo fontInfo = fontCollectionEnumerator.next();
            if (fontInfo != null) {
                System.out.println("Font name: " + fontInfo.getName());
                System.out.println("Alt name: " + fontInfo.getAltName()); // Alt names are usually blank
                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)
        Gets a specific embedded font file.
        Parameters:
        format - A EmbeddedFontFormat value. Specifies the font format to retrieve.
        style - A EmbeddedFontStyle value. Specifies the font style to retrieve.
        Returns:
        Returns null if the specified font is not embedded.

        Example:

        Shows how to extract embedded font from a document.
        Document doc = new Document(getMyDir() + "Font.Embedded.docx");
        // Let's get the font we are interested in
        FontInfo mittelschriftInfo = doc.getFontInfos().get(2);
        // We can now extract this embedded font
        byte[] embeddedFontBytes = mittelschriftInfo.getEmbeddedFont(EmbeddedFontFormat.OPEN_TYPE, EmbeddedFontStyle.REGULAR);
        Assert.assertNotNull(embeddedFontBytes);
        // Then we can save the font to our directory
        Files.write(Paths.get(getArtifactsDir() + "Alte DIN 1451 Mittelschrift.ttf"), embeddedFontBytes,
                new StandardOpenOption[]{StandardOpenOption.CREATE, StandardOpenOption.APPEND});
        
        // If we want to extract a font from a .doc as opposed to a .docx, we need to make sure to set the appropriate embedded font format
        doc = new Document(getMyDir() + "Font.Embedded.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));