Class FontEncoding

  • Direct Known Subclasses:
    DocFontEncoding

    public class FontEncoding
    extends java.lang.Object
    • Field Detail

      • emptyBytes

        private static final byte[] emptyBytes
      • NOTDEF

        public static final java.lang.String NOTDEF
        A not defined character in a custom PDF encoding.
        See Also:
        Constant Field Values
      • baseEncoding

        protected java.lang.String baseEncoding
        Base font encoding.
      • fontSpecific

        protected boolean fontSpecific
        true if the font must use its built in encoding. In that case the encoding is only used to map a char to the position inside the font, not to the expected char name.
      • unicodeToCode

        protected IntHashtable unicodeToCode
        Mapping map from unicode to simple code according to the encoding.
      • codeToUnicode

        protected int[] codeToUnicode
      • differences

        protected java.lang.String[] differences
        Encoding names.
      • unicodeDifferences

        protected IntHashtable unicodeDifferences
        Encodings unicode differences
    • Constructor Detail

      • FontEncoding

        protected FontEncoding()
    • Method Detail

      • createFontEncoding

        public static FontEncoding createFontEncoding​(java.lang.String baseEncoding)
      • createEmptyFontEncoding

        public static FontEncoding createEmptyFontEncoding()
      • createFontSpecificEncoding

        public static FontEncoding createFontSpecificEncoding()
        This encoding will base on font encoding (FontSpecific encoding in Type 1 terminology)
        Returns:
        created font specific encoding
      • getBaseEncoding

        public java.lang.String getBaseEncoding()
      • isFontSpecific

        public boolean isFontSpecific()
      • addSymbol

        public boolean addSymbol​(int code,
                                 int unicode)
      • getUnicode

        public int getUnicode​(int index)
        Gets unicode value for corresponding font's char code.
        Parameters:
        index - font's char code
        Returns:
        -1, if the char code unsupported or valid unicode.
      • getUnicodeDifference

        public int getUnicodeDifference​(int index)
      • hasDifferences

        public boolean hasDifferences()
      • getDifference

        public java.lang.String getDifference​(int index)
      • setDifference

        public void setDifference​(int index,
                                  java.lang.String difference)
        Sets a new value in the differences array. See differences.
        Parameters:
        index - position to replace
        difference - new difference value
      • convertToBytes

        public byte[] convertToBytes​(java.lang.String text)
        Converts a String to a byte array according to the encoding. String could contain a unicode symbols or font specific codes.
        Parameters:
        text - the String to be converted.
        Returns:
        an array of byte representing the conversion according to the encoding
      • convertToByte

        public int convertToByte​(int unicode)
        Converts a unicode symbol or font specific code to byte according to the encoding.
        Parameters:
        unicode - a unicode symbol or FontSpecif code to be converted.
        Returns:
        a byte representing the conversion according to the encoding
      • canEncode

        public boolean canEncode​(int unicode)
        Check whether a unicode symbol or font specific code can be converted to byte according to the encoding.
        Parameters:
        unicode - a unicode symbol or font specific code to be checked.
        Returns:
        true if ch could be encoded.
      • canDecode

        public boolean canDecode​(int code)
        Check whether a byte code can be converted to unicode symbol according to the encoding.
        Parameters:
        code - a byte code to be checked.
        Returns:
        true if code could be decoded.
      • isBuiltWith

        public boolean isBuiltWith​(java.lang.String encoding)
        Checks whether the FontEncoding was built with corresponding encoding.
        Parameters:
        encoding - an encoding
        Returns:
        true, if the FontEncoding was built with the encoding. Otherwise false.
      • fillCustomEncoding

        protected void fillCustomEncoding()
      • fillNamedEncoding

        protected void fillNamedEncoding()
      • fillStandardEncoding

        protected void fillStandardEncoding()
      • normalizeEncoding

        protected static java.lang.String normalizeEncoding​(java.lang.String enc)
        Normalize the encoding names. "winansi" is changed to "Cp1252" and "macroman" is changed to "MacRoman".
        Parameters:
        enc - the encoding to be normalized
        Returns:
        the normalized encoding