Class FontEncoding

java.lang.Object
com.itextpdf.io.font.FontEncoding

public class FontEncoding extends Object
  • Field Details

    • FONT_SPECIFIC

      public static final String FONT_SPECIFIC
      See Also:
    • NOTDEF

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

      protected 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 com.itextpdf.io.util.IntHashtable unicodeToCode
      Mapping map from unicode to simple code according to the encoding.
    • codeToUnicode

      protected int[] codeToUnicode
    • differences

      protected String[] differences
      Encoding names.
    • unicodeDifferences

      protected com.itextpdf.io.util.IntHashtable unicodeDifferences
      Encodings unicode differences
  • Constructor Details

    • FontEncoding

      protected FontEncoding()
  • Method Details

    • createFontEncoding

      public static FontEncoding createFontEncoding (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
    • fillFontEncoding

      public static void fillFontEncoding (FontEncoding encoding)
      Fill FontEncoding object with default data.
      Parameters:
      encoding - FontEncoding to fill.
    • getBaseEncoding

      public 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 String getDifference (int index)
    • setDifference

      public void setDifference (int index, 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 (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 (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 String normalizeEncoding (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