Class EmbeddedFont

java.lang.Object
com.independentsoft.office.pdf.EmbeddedFont

public class EmbeddedFont extends Object
A TrueType font embedded in a PDF file as a Type0/CIDFontType2 font with Identity-H encoding. Tracks the glyphs used by the document and produces the PDF font objects including a ToUnicode CMap for text extraction.
  • Field Details

  • Method Details

    • getResourceName

      public String getResourceName()
      Gets the resource name used in page content streams, for example "EF1".
      Returns:
      the resource name
    • getFont

      public TrueTypeFont getFont()
      Gets the underlying TrueType font.
      Returns:
      the font
    • encode

      public String encode(String text)
      Encodes text as a hexadecimal string of glyph ids for use with Identity-H encoding, registering each glyph as used: <00410042>.
      Parameters:
      text - the text
      Returns:
      the hexadecimal string without the enclosing angle brackets
    • getStringWidth

      public double getStringWidth(String text, double fontSize)
      Measures text width in points.
      Parameters:
      text - the text
      fontSize - the font size in points
      Returns:
      the width in points
    • getCharWidth

      public double getCharWidth(char c, double fontSize)
      Measures a single character width in points.
      Parameters:
      c - the character
      fontSize - the font size in points
      Returns:
      the width in points
    • buildObjects

      public byte[][] buildObjects(int firstObjectId, boolean compress) throws IOException
      Builds the five PDF objects of this font. The objects use consecutive ids starting at firstObjectId in this order: Type0 font, CIDFontType2 font, font descriptor, FontFile2 stream, ToUnicode stream.
      Parameters:
      firstObjectId - the id of the first object
      compress - whether to Flate-compress the font file and the ToUnicode stream
      Returns:
      one complete "N 0 obj ... endobj" byte array per object
      Throws:
      IOException - Signals that an I/O exception has occurred.