Class TrueTypeFontUnicode

  • All Implemented Interfaces:
    java.util.Comparator<int[]>

    class TrueTypeFontUnicode
    extends TrueTypeFont
    implements java.util.Comparator<int[]>
    Represents a True Type font with Unicode encoding. All the character in the font can be used directly by using the encoding Identity-H or Identity-V. This is the only way to represent some character sets such as Thai.
    • Field Detail

      • SUPPORTED_LANGUAGES_FOR_OTF

        private static final java.util.List<Language> SUPPORTED_LANGUAGES_FOR_OTF
      • glyphSubstitutionMap

        private java.util.Map<java.lang.String,​Glyph> glyphSubstitutionMap
      • supportedLanguage

        private Language supportedLanguage
      • rotbits

        private static final byte[] rotbits
    • Constructor Detail

      • TrueTypeFontUnicode

        TrueTypeFontUnicode​(java.lang.String ttFile,
                            java.lang.String enc,
                            boolean emb,
                            byte[] ttfAfm,
                            boolean forceRead)
                     throws DocumentException,
                            java.io.IOException
        Creates a new TrueType font addressed by Unicode characters. The font will always be embedded.
        Parameters:
        ttFile - the location of the font on file. The file must end in '.ttf'. The modifiers after the name are ignored.
        enc - the encoding to be applied to this font
        emb - true if the font is to be embedded in the PDF
        ttfAfm - the font as a byte array
        Throws:
        DocumentException - the font is invalid
        java.io.IOException - the font file could not be read
    • Method Detail

      • process

        void process​(byte[] ttfAfm,
                     boolean preload)
              throws DocumentException,
                     java.io.IOException
        Description copied from class: TrueTypeFont
        Reads the font data.
        Overrides:
        process in class TrueTypeFont
        Parameters:
        ttfAfm - the font as a byte array, possibly null
        Throws:
        DocumentException - the font is invalid
        java.io.IOException - the font file could not be read
      • getWidth

        public int getWidth​(int char1)
        Gets the width of a char in normalized 1000 units.
        Overrides:
        getWidth in class BaseFont
        Parameters:
        char1 - the unicode char to get the width of
        Returns:
        the width in normalized 1000 units
      • getWidth

        public int getWidth​(java.lang.String text)
        Gets the width of a String in normalized 1000 units.
        Overrides:
        getWidth in class BaseFont
        Parameters:
        text - the String to get the width of
        Returns:
        the width in normalized 1000 units
      • getToUnicode

        public PdfStream getToUnicode​(java.lang.Object[] metrics)
        Creates a ToUnicode CMap to allow copy and paste from Acrobat.
        Parameters:
        metrics - metrics[0] contains the glyph index and metrics[2] contains the Unicode code
        Returns:
        the stream representing this CMap or null
      • toHex4

        private static java.lang.String toHex4​(int n)
      • toHex

        static java.lang.String toHex​(int n)
        Gets an hex string in the format "<HHHH>".
        Parameters:
        n - the number
        Returns:
        the hex string
      • getCIDFontType2

        public PdfDictionary getCIDFontType2​(PdfIndirectReference fontDescriptor,
                                             java.lang.String subsetPrefix,
                                             java.lang.Object[] metrics)
        Generates the CIDFontTyte2 dictionary.
        Parameters:
        fontDescriptor - the indirect reference to the font descriptor
        subsetPrefix - the subset prefix
        metrics - the horizontal width metrics
        Returns:
        a stream
      • getFontBaseType

        public PdfDictionary getFontBaseType​(PdfIndirectReference descendant,
                                             java.lang.String subsetPrefix,
                                             PdfIndirectReference toUnicode)
        Generates the font dictionary.
        Parameters:
        descendant - the descendant dictionary
        subsetPrefix - the subset prefix
        toUnicode - the ToUnicode stream
        Returns:
        the stream
      • GetCharFromGlyphId

        public int GetCharFromGlyphId​(int gid)
      • compare

        public int compare​(int[] o1,
                           int[] o2)
        The method used to sort the metrics array.
        Specified by:
        compare in interface java.util.Comparator<int[]>
        Parameters:
        o1 - the first element
        o2 - the second element
        Returns:
        the comparison
      • writeFont

        void writeFont​(PdfWriter writer,
                       PdfIndirectReference ref,
                       java.lang.Object[] params)
                throws DocumentException,
                       java.io.IOException
        Outputs to the writer the font dictionaries and streams.
        Overrides:
        writeFont in class TrueTypeFont
        Parameters:
        writer - the writer for this document
        ref - the font indirect reference
        params - several parameters that depend on the font type
        Throws:
        java.io.IOException - on error
        DocumentException - error in generating the object
      • convertToBytes

        public byte[] convertToBytes​(java.lang.String text)
        A forbidden operation. Will throw a null pointer exception.
        Overrides:
        convertToBytes in class BaseFont
        Parameters:
        text - the text
        Returns:
        always null
      • convertToBytes

        byte[] convertToBytes​(int char1)
        Description copied from class: BaseFont
        Converts a char to a byte array according to the font's encoding.
        Overrides:
        convertToBytes in class BaseFont
        Parameters:
        char1 - the char to be converted
        Returns:
        an array of byte representing the conversion according to the font's encoding
      • getMetricsTT

        public int[] getMetricsTT​(int c)
        Gets the glyph index and metrics for a character.
        Overrides:
        getMetricsTT in class TrueTypeFont
        Parameters:
        c - the character
        Returns:
        an int array with {glyph index, width}
      • charExists

        public boolean charExists​(int c)
        Checks if a character exists in this font.
        Overrides:
        charExists in class BaseFont
        Parameters:
        c - the character to check
        Returns:
        true if the character has a glyph, false otherwise
      • setCharAdvance

        public boolean setCharAdvance​(int c,
                                      int advance)
        Sets the character advance.
        Overrides:
        setCharAdvance in class BaseFont
        Parameters:
        c - the character
        advance - the character advance normalized to 1000 units
        Returns:
        true if the advance was set, false otherwise
      • getCharBBox

        public int[] getCharBBox​(int c)
        Description copied from class: BaseFont
        Gets the smallest box enclosing the character contours. It will return null if the font has not the information or the character has no contours, as in the case of the space, for example. Characters with no contours may also return [0,0,0,0].
        Overrides:
        getCharBBox in class BaseFont
        Parameters:
        c - the character to get the contour bounding box from
        Returns:
        an array of four floats with the bounding box in the format [llx,lly,urx,ury] or null
      • getGlyphSubstitutionMap

        protected java.util.Map<java.lang.String,​Glyph> getGlyphSubstitutionMap()
      • getSupportedLanguage

        Language getSupportedLanguage()
      • readGsubTable

        private void readGsubTable()
                            throws java.io.IOException
        Throws:
        java.io.IOException