Class PDCIDFont

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract int codeToCID​(int code)
      Returns the CID for the given character code.
      abstract int codeToGID​(int code)
      Returns the GID for the given character code.
      protected abstract byte[] encode​(int unicode)
      Encodes the given Unicode code point for use in a PDF content stream.
      float getAverageFontWidth()
      This will get the average font width for all characters.
      java.lang.String getBaseFont()
      The PostScript name of the font.
      abstract org.apache.fontbox.util.BoundingBox getBoundingBox()
      Returns the font's bounding box.
      PDCIDSystemInfo getCIDSystemInfo()
      Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).
      COSDictionary getCOSObject()
      Convert this standard java object to a COS object.
      PDFontDescriptor getFontDescriptor()
      Returns the font descriptor, may be null.
      abstract Matrix getFontMatrix()
      Returns the font matrix, which represents the transformation from glyph space to text space.
      abstract float getHeight​(int code)
      Returns the height of the given character, in glyph space.
      java.lang.String getName()
      Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
      PDType0Font getParent()
      Returns the Type 0 font which is the parent of this font.
      Vector getPositionVector​(int code)
      Returns the position vector (v), in text space, for the given character.
      float getVerticalDisplacementVectorY​(int code)
      Returns the y-component of the vertical displacement vector (w1).
      float getWidth​(int code)
      Returns the advance width of the given character, in glyph space.
      abstract float getWidthFromFont​(int code)
      Returns the width of a glyph in the embedded font file.
      boolean hasExplicitWidth​(int code)
      Returns true if the Font dictionary specifies an explicit width for the given glyph.
      abstract boolean isEmbedded()
      Returns true if the font file is embedded in the PDF.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCOSObject

        public COSDictionary getCOSObject()
        Description copied from interface: COSObjectable
        Convert this standard java object to a COS object.
        Specified by:
        getCOSObject in interface COSObjectable
        Returns:
        The cos object that matches this Java object.
      • getBaseFont

        public java.lang.String getBaseFont()
        The PostScript name of the font.
        Returns:
        The postscript name of the font.
      • getName

        public java.lang.String getName()
        Description copied from interface: PDFontLike
        Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
        Specified by:
        getName in interface PDFontLike
      • getFontMatrix

        public abstract Matrix getFontMatrix()
        Description copied from interface: PDFontLike
        Returns the font matrix, which represents the transformation from glyph space to text space.
        Specified by:
        getFontMatrix in interface PDFontLike
      • getParent

        public final PDType0Font getParent()
        Returns the Type 0 font which is the parent of this font.
        Returns:
        parent Type 0 font
      • getBoundingBox

        public abstract org.apache.fontbox.util.BoundingBox getBoundingBox()
                                                                    throws java.io.IOException
        Description copied from interface: PDFontLike
        Returns the font's bounding box.
        Specified by:
        getBoundingBox in interface PDFontLike
        Throws:
        java.io.IOException
      • hasExplicitWidth

        public boolean hasExplicitWidth​(int code)
                                 throws java.io.IOException
        Description copied from interface: PDFontLike
        Returns true if the Font dictionary specifies an explicit width for the given glyph. This includes Width, W but not default widths entries.
        Specified by:
        hasExplicitWidth in interface PDFontLike
        Parameters:
        code - character code
        Throws:
        java.io.IOException - if the font could not be read
      • getPositionVector

        public Vector getPositionVector​(int code)
        Description copied from interface: PDFontLike
        Returns the position vector (v), in text space, for the given character. This represents the position of vertical origin relative to horizontal origin, for horizontal writing it will always be (0, 0). For vertical writing both x and y are set.
        Specified by:
        getPositionVector in interface PDFontLike
        Parameters:
        code - character code
        Returns:
        position vector
      • getVerticalDisplacementVectorY

        public float getVerticalDisplacementVectorY​(int code)
        Returns the y-component of the vertical displacement vector (w1).
        Parameters:
        code - character code
        Returns:
        w1y
      • getHeight

        public abstract float getHeight​(int code)
                                 throws java.io.IOException
        Description copied from interface: PDFontLike
        Returns the height of the given character, in glyph space. This can be expensive to calculate. Results are only approximate.

        Warning: This method is deprecated in PDFBox 2.0 because there is no meaningful value which it can return. The PDFontLike.getWidth(int) method returns the advance width of a glyph, but there is no corresponding advance height. The logical height of a character is the same for every character in a font, so if you want that, retrieve the font bbox's height. Otherwise if you want the visual bounds of the glyph then call getPath(..) on the appropriate PDFont subclass to retrieve the glyph outline as a GeneralPath.

        Specified by:
        getHeight in interface PDFontLike
        Parameters:
        code - character code
        Throws:
        java.io.IOException
      • getWidth

        public float getWidth​(int code)
                       throws java.io.IOException
        Description copied from interface: PDFontLike
        Returns the advance width of the given character, in glyph space.

        If you want the visual bounds of the glyph then call getPath(..) on the appropriate PDFont subclass to retrieve the glyph outline as a GeneralPath instead.

        Specified by:
        getWidth in interface PDFontLike
        Parameters:
        code - character code
        Throws:
        java.io.IOException
      • getWidthFromFont

        public abstract float getWidthFromFont​(int code)
                                        throws java.io.IOException
        Description copied from interface: PDFontLike
        Returns the width of a glyph in the embedded font file.
        Specified by:
        getWidthFromFont in interface PDFontLike
        Parameters:
        code - character code
        Returns:
        width in glyph space
        Throws:
        java.io.IOException - if the font could not be read
      • isEmbedded

        public abstract boolean isEmbedded()
        Description copied from interface: PDFontLike
        Returns true if the font file is embedded in the PDF.
        Specified by:
        isEmbedded in interface PDFontLike
      • getAverageFontWidth

        public float getAverageFontWidth()
        Description copied from interface: PDFontLike
        This will get the average font width for all characters.
        Specified by:
        getAverageFontWidth in interface PDFontLike
        Returns:
        The width is in 1000 unit of text space, ie 333 or 777
      • getCIDSystemInfo

        public PDCIDSystemInfo getCIDSystemInfo()
        Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).
      • codeToCID

        public abstract int codeToCID​(int code)
        Returns the CID for the given character code. If not found then CID 0 is returned.
        Parameters:
        code - character code
        Returns:
        CID
      • codeToGID

        public abstract int codeToGID​(int code)
                               throws java.io.IOException
        Returns the GID for the given character code.
        Parameters:
        code - character code
        Returns:
        GID
        Throws:
        java.io.IOException
      • encode

        protected abstract byte[] encode​(int unicode)
                                  throws java.io.IOException
        Encodes the given Unicode code point for use in a PDF content stream. Content streams use a multi-byte encoding with 1 to 4 bytes.

        This method is called when embedding text in PDFs and when filling in fields.

        Parameters:
        unicode - Unicode code point.
        Returns:
        Array of 1 to 4 PDF content stream bytes.
        Throws:
        java.io.IOException - If the text could not be encoded.