Class PdfType0Font


  • public class PdfType0Font
    extends PdfFont
    • Field Detail

      • DEFAULT_ENCODING

        private static final java.lang.String DEFAULT_ENCODING
        This is the default encoding to use.
        See Also:
        Constant Field Values
      • MAX_CID_CODE_LENGTH

        private static final int MAX_CID_CODE_LENGTH
        The code length shall not be greater than 4.
        See Also:
        Constant Field Values
      • rotbits

        private static final byte[] rotbits
      • CID_FONT_TYPE_0

        protected static final int CID_FONT_TYPE_0
        CIDFont Type0 (Type1 outlines).
        See Also:
        Constant Field Values
      • CID_FONT_TYPE_2

        protected static final int CID_FONT_TYPE_2
        CIDFont Type2 (TrueType outlines).
        See Also:
        Constant Field Values
      • vertical

        protected boolean vertical
      • usedGlyphs

        protected java.util.Set<java.lang.Integer> usedGlyphs
      • cidFontType

        protected int cidFontType
      • specificUnicodeDifferences

        protected char[] specificUnicodeDifferences
      • embeddedToUnicode

        private final CMapToUnicode embeddedToUnicode
    • Constructor Detail

      • PdfType0Font

        PdfType0Font​(TrueTypeFont ttf,
                     java.lang.String cmap)
      • PdfType0Font

        PdfType0Font​(CidFont font,
                     java.lang.String cmap)
    • Method Detail

      • getUniMapFromOrdering

        public static java.lang.String getUniMapFromOrdering​(java.lang.String ordering,
                                                             boolean horizontal)
        Get Unicode mapping name from ordering.
        Parameters:
        ordering - the text ordering to base to unicode mapping on
        horizontal - identifies whether the encoding is horizontal or vertical
        Returns:
        Unicode mapping name
      • getGlyph

        public Glyph getGlyph​(int unicode)
        Description copied from class: PdfFont
        Get glyph by unicode
        Specified by:
        getGlyph in class PdfFont
        Parameters:
        unicode - a unicode code point
        Returns:
        Glyph if it exists or .NOTDEF if supported, otherwise null.
      • containsGlyph

        public boolean containsGlyph​(int unicode)
        Description copied from class: PdfFont
        Check whether font contains glyph with specified unicode.
        Overrides:
        containsGlyph in class PdfFont
        Parameters:
        unicode - a unicode code point
        Returns:
        true if font contains glyph, represented with the unicode code point, otherwise false.
      • convertToBytesUsingCMap

        private byte[] convertToBytesUsingCMap​(java.lang.String text)
      • convertToBytes

        public byte[] convertToBytes​(java.lang.String text)
        Description copied from class: PdfFont
        Converts the text into bytes to be placed in the document. The conversion is done according to the font and the encoding and the characters used are stored.
        Specified by:
        convertToBytes in class PdfFont
        Parameters:
        text - the text to convert
        Returns:
        the conversion
      • converToBytesUsingEncoder

        private byte[] converToBytesUsingEncoder​(java.lang.String text,
                                                 CMapCharsetEncoder encoder)
      • appendGlyphs

        public int appendGlyphs​(java.lang.String text,
                                int from,
                                int to,
                                java.util.List<Glyph> glyphs)
        Description copied from class: PdfFont
        Append all supported glyphs and return number of processed chars. Composite font supports surrogate pairs.
        Specified by:
        appendGlyphs in class PdfFont
        Parameters:
        text - String to convert to glyphs.
        from - from index of the text.
        to - to index of the text.
        glyphs - array for a new glyphs, shall not be null.
        Returns:
        number of processed chars from text.
      • appendUniGlyphs

        private int appendUniGlyphs​(java.lang.String text,
                                    int from,
                                    int to,
                                    java.util.List<Glyph> glyphs)
      • appendAnyGlyph

        public int appendAnyGlyph​(java.lang.String text,
                                  int from,
                                  java.util.List<Glyph> glyphs)
        Description copied from class: PdfFont
        Append any single glyph, even notdef. Returns number of processed chars: 2 in case surrogate pair, otherwise 1.
        Specified by:
        appendAnyGlyph in class PdfFont
        Parameters:
        text - String to convert to glyphs.
        from - from index of the text.
        glyphs - array for a new glyph, shall not be null.
        Returns:
        number of processed chars: 2 in case surrogate pair, otherwise 1
      • isAppendableGlyph

        private boolean isAppendableGlyph​(Glyph glyph)
      • decodeIntoGlyphLine

        public GlyphLine decodeIntoGlyphLine​(PdfString characterCodes)
        Decodes sequence of character codes (e.g. from content stream) into a GlyphLine
        Specified by:
        decodeIntoGlyphLine in class PdfFont
        Parameters:
        characterCodes - the string which is interpreted as a sequence of character codes. Note, that PdfString acts as a storage for char code values specific to given font, therefore individual character codes must not be interpreted as code units of the UTF-16 encoding
        Returns:
        the GlyphLine containing the glyphs encoded by the passed string
      • appendDecodedCodesToGlyphsList

        public boolean appendDecodedCodesToGlyphsList​(java.util.List<Glyph> list,
                                                      PdfString characterCodes)
        Decodes sequence of character codes (e.g. from content stream) to sequence of glyphs and appends them to the passed list.
        Overrides:
        appendDecodedCodesToGlyphsList in class PdfFont
        Parameters:
        list - the list to the end of which decoded glyphs are to be added
        characterCodes - the string which is interpreted as a sequence of character codes. Note, that PdfString acts as a storage for char code values specific to given font, therefore individual character codes must not be interpreted as code units of the UTF-16 encoding
        Returns:
        true if all codes where successfully decoded, false otherwise
      • flush

        public void flush()
        Description copied from class: PdfFont
        To manually flush a PdfObject behind this wrapper, you have to ensure that this object is added to the document, i.e. it has an indirect reference. Basically this means that before flushing you need to explicitly call PdfObjectWrapper.makeIndirect(PdfDocument). For example: wrapperInstance.makeIndirect(document).flush(); Note that not every wrapper require this, only those that have such warning in documentation.
        Overrides:
        flush in class PdfFont
      • convertToBytes

        private void convertToBytes​(Glyph glyph,
                                    ByteBuffer result)
      • getOrdering

        private static java.lang.String getOrdering​(PdfDictionary cidFont)
      • containsCodeInCodeSpaceRange

        private static boolean containsCodeInCodeSpaceRange​(java.util.List<byte[]> codeSpaceRanges,
                                                            int code,
                                                            int length)
      • bytesToLong

        private static long bytesToLong​(byte[] bytes)
      • flushFontData

        private void flushFontData()
      • getCidFont

        protected PdfDictionary getCidFont​(PdfDictionary fontDescriptor,
                                           java.lang.String fontName,
                                           boolean isType2)
        Generates the CIDFontType2 dictionary.
        Parameters:
        fontDescriptor - the font descriptor dictionary
        fontName - a name of the font
        isType2 - true, if the font is CIDFontType2 (TrueType glyphs), otherwise false, i.e. CIDFontType0 (Type1/CFF glyphs)
        Returns:
        fully initialized CIDFont
      • generateWidthsArray

        private PdfObject generateWidthsArray()
      • getToUnicode

        public PdfStream getToUnicode()
        Creates a ToUnicode CMap to allow copy and paste from Acrobat.
        Returns:
        the stream representing this CMap or null
      • toHex4

        private static java.lang.String toHex4​(char ch)
      • getCompatibleUniMap

        private java.lang.String getCompatibleUniMap​(java.lang.String registry)
      • normalizeEncoding

        private static java.lang.String normalizeEncoding​(java.lang.String encoding)