Package com.independentsoft.office.pdf

# 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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `static int`
  `OBJECT_COUNT`
  Number of PDF objects produced by `buildObjects(int, boolean)`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `byte[][]`
  `buildObjects​(int firstObjectId, boolean compress)`
  Builds the five PDF objects of this font.
  `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>`.
  `double`
  `getCharWidth​(char c, double fontSize)`
  Measures a single character width in points.
  `TrueTypeFont`
  `getFont()`
  Gets the underlying TrueType font.
  `String`
  `getResourceName()`
  Gets the resource name used in page content streams, for example "EF1".
  `double`
  `getStringWidth​(String text, double fontSize)`
  Measures text width in points.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### OBJECT_COUNT

    public static final int OBJECT_COUNT
    Number of PDF objects produced by `buildObjects(int, boolean)`.
    See Also:
      Constant Field Values

- ## 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.