Class Font

    • Method Detail

      • create

        public static Font create​(Document targetDocument,
                                  Stream stream,
                                  boolean embedded)
                           throws java.io.IOException,
                                  UnknownFormatException,
                                  CorruptException,
                                  ConformanceException

        Create a new font object from font file data.

        Supported formats are:
        • Type1
        • CFF
        • TrueType
        • OpenType
        The returned font object is not yet used on any page, but it is associated with the given target document.
        Parameters:
        targetDocument - the output document with which the returned object is associated
        stream - the font file data stream
        embedded - true if the font shall be embedded in the document. Note that this parameter must be true for PDF/A documents.
        Returns:
        the newly created font object
        Throws:
        java.io.IOException - Error reading from the font file or writing to the document
        UnknownFormatException - The font data has an unknown format
        CorruptException - The font data is corrupt
        ConformanceException - Parameter embedded is false for PDF/A document
        java.lang.IllegalArgumentException - if the targetDocument argument has already been closed
        java.lang.IllegalArgumentException - if the targetDocument argument is read-only
        java.lang.IllegalArgumentException - if the stream argument is null
        java.lang.IllegalArgumentException - if targetDocument is null
        java.lang.IllegalArgumentException - if stream is null
      • createFromSystem

        public static Font createFromSystem​(Document targetDocument,
                                            java.lang.String family,
                                            java.lang.String style,
                                            boolean embedded)
                                     throws java.io.IOException,
                                            NotFoundException,
                                            UnknownFormatException,
                                            CorruptException,
                                            ConformanceException

        Create a new font object from an installed font.

        The returned font object is not yet used on any page, but it is associated with the given target document.
        Parameters:
        targetDocument - the output document with which the returned object is associated
        family - the font family name (e.g. "Arial")
        style - the font style (e.g. "Bold")
        embedded - true if the font shall be embedded in the document. Note that this parameter must be true for PDF/A documents.
        Returns:
        the newly created font object
        Throws:
        NotFoundException - There is no such font installed
        java.io.IOException - Error reading the font file or writing to the document
        UnknownFormatException - The font data has an unknown format
        CorruptException - The font data is corrupt
        ConformanceException - Parameter embedded is false for PDF/A document
        java.lang.IllegalArgumentException - if the targetDocument argument has already been closed
        java.lang.IllegalArgumentException - if the targetDocument argument is read-only
        java.lang.IllegalArgumentException - if the family argument is null
        java.lang.IllegalArgumentException - if targetDocument is null
      • getCharacterWidth

        public double getCharacterWidth​(int character)

        the width of a single glyph.

        The width of a unicode character (in pt) relative to a font size of 1 pt.

        If an error occurs (because the font or the owning document has already been closed) this method returns 0. But a return value of 0 is not generally an indication for failure.

        Parameters:
        character - the unicode character code.
        Returns:
        the width of the character
      • getBaseFont

        public java.lang.String getBaseFont()
                                     throws CorruptException

        the PostScript name of the font (Getter)

        Throws:
        java.lang.IllegalStateException - if the font has already been closed
        CorruptException - if the font's base name is missing or cannot be decoded
      • getWeight

        public FontWeight getWeight()

        the visual weight of the font. (Getter)

        Indicates the visual weight (degree of blackness or thickness of strokes) of the characters in the font. If the font does not define this value, null is returned.
        Throws:
        java.lang.IllegalStateException - if the font has already been closed
      • getItalicAngle

        public double getItalicAngle()

        the italic angle of the font. (Getter)

        The angle is expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font. (For example, the 9-o’clock position is 90 degrees, and the 3-o’clock position is –90 degrees.) The value is negative for fonts that slope to the right, as almost all italic fonts do.
        Throws:
        java.lang.IllegalStateException - if the font has already been closed
      • getAscent

        public double getAscent()

        the ascent of the font. (Getter)

        The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.
        Throws:
        java.lang.IllegalStateException - if the font has already been closed
      • getDescent

        public double getDescent()

        the descent of the font. (Getter)

        The maximum depth below the baseline reached by glyphs in this font. The value is a negative number.
        Throws:
        java.lang.IllegalStateException - if the font has already been closed
      • getCapHeight

        public double getCapHeight()

        the cap height of the font. (Getter)

        The vertical coordinate of the top of flat capital letters, measured from the baseline.
        Throws:
        java.lang.IllegalStateException - if the font has already been closed