Class Font

java.lang.Object
com.datalogics.PDFL.Font

public class Font extends Object
Represents a font. Defines the typeface, size, style (bold, italic), Unicode values, and other details. The Font class represents a font installed on the system.

  • Constructor Details

    • Font

      public Font(String fontName)
      Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

      When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

      PDFL enforces the following requirements on fonts:

      • TrueTypes used as CID fonts must be embedded.

      • All CID fonts that are embedded must be subsetted.

      • CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

    • Font

      public Font(String fontName, EnumSet<FontCreateFlags> createFlags)
      Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

      When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

      PDFL enforces the following requirements on fonts:

      • TrueTypes used as CID fonts must be embedded.

      • All CID fonts that are embedded must be subsetted.

      • CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

      Parameters:
      fontName - the name of the font to create
      createFlags - flags specifying embedding and other options for the use of a font in the document
    • Font

      public Font(String fontName, EnumSet<FontCreateFlags> createFlags, WritingMode wrMode)
      Find a font with the specified name, and construct a Font object from it. Otherwise, it makes a font with the default encoding (MacRomanEncoding on Macs, WinAnsiEncoding elsewhere, or for symbol fonts, their own custom encoding). There is not a way to specify another encoding for the font.

      When setting text, it checks to see if the text is representable in the font's encoding. If it is not, then DLE makes a "unicode font" with an Identity-H or Identity-V encoding and uses that to set the text. For non-Type0 fonts, this may result in two versions of a font in the output document.

      PDFL enforces the following requirements on fonts:

      • TrueTypes used as CID fonts must be embedded.

      • All CID fonts that are embedded must be subsetted.

      • CID fonts that are marked as embedded get their DoNotEmbed flag turned off (or else PDFL won't make a PDEFont from the SysFont).

      Parameters:
      fontName - the name of the font to create
      createFlags - flags specifying embedding and other options for the use of a font in the document
      wrMode - determines whether text will be printed horizontally or vertically
  • Method Details

    • delete

      public void delete()
      Destructor.
    • getFontList

      public static List<Font> getFontList()
      Get a list of available fonts.
      Returns:
      The list of available fonts.
    • getAscent

      public double getAscent()
      Returns:
      The Ascent value of the font in glyph space units.
    • getAvgWidth

      public double getAvgWidth()
      Returns:
      The AvgWidth value of the font in glyph space units, or 0 if not defined.
    • getCapHeight

      public double getCapHeight()
      Returns:
      The CapHeight value of the font in glyph space units, or 0 if not defined.
    • getDescent

      public double getDescent()
      Returns:
      The descent value of the font. \\xrefitem pdelayer_apis "PDE Layer" "PDE Layer" PDSysFont PDSysFontGetAttrs \\xrefitem pdelayer_apis "PDE Layer" "PDE Layer" PDEFont PDEFontGetAttrs \\xrefitem pdlayer_apis "PD Layer" "PD Layer" PDFont PDFontGetMetrics
    • getEncoding

      public String getEncoding()
      Return the encoding of the font.
      Returns:
      The encoding of the font, eg:
      • WinAnsiEncoding

      • MacRomanEncoding

    • getItalicAngle

      public double getItalicAngle()
      Returns:
      The ItalicAngle value of the font in degrees.
    • getLeading

      public double getLeading()
      Returns:
      The leading value of the font, or 0 if not present.
    • getMaxWidth

      public double getMaxWidth()
      Returns:
      The MaxWidth value of the font in glyph space units, or 0 if not present.
    • getMissingWidth

      public double getMissingWidth()
      Returns:
      The MissingWidth value of the font in glyph space units, or 0 if not present.
    • getBBox

      public Rect getBBox()
      The Bounding Box rectangle of the font.
    • getName

      public String getName()
      Get the name of the font.
      Returns:
      The name of the font.
    • getFullName

      public String getFullName()
      Get the Full Name of the font.
      Returns:
      The Full Name of the font. Note: This method only returns a meaningful result for TrueType-based technology fonts.
    • getStemH

      public double getStemH()
      Returns:
      The StemH value of the font in glyph space units, or 0 if not present.
    • getStemV

      public double getStemV()
      Returns:
      The StemV value of the font in glyph space units, or 0 if not present.
    • getType

      public String getType()
      Get the type of the font.
      Returns:
      The type of the font.
      • Type0

      • Type1

      • MMType1

      • TrueType

    • getCidFontType

      public String getCidFontType()
    • getXHeight

      public double getXHeight()
      Returns:
      The XHeight value of the font in glyph space units, or 0 if not present.
    • getFlags

      public EnumSet<FontFlags> getFlags()
      Get the font flags for a font.
    • getEncodingInfo

      public EncodingInfo getEncodingInfo()
      Get the populated CEncoding object.
    • getWritingMode

      public WritingMode getWritingMode()
      Returns:
      The WritingMode of the font.
    • isTextRepresentable

      public boolean isTextRepresentable(String text)
      Is this text representable in this font?

      Parameters:
      text - the text to check
    • findIndexOfFirstUnrepresentableChar

      public long findIndexOfFirstUnrepresentableChar(String text)
      Find the index of the first character that cannot be represented in this font. This will return the index of the first character in the string for which the font has no glyph. If all characters can be represented (i.e. if IsTextRepresentable() would return true), this will return the length of the string.

      Parameters:
      text - the text to check
      Returns:
      The index of the first character that cannot be represented in this font.
    • getPDFDict

      public PDFDict getPDFDict()
      Retrieve the PDFDict representation of this object

    • isFromDoc

      public boolean isFromDoc()
    • getEmbedded

      public boolean getEmbedded()
      Tests that Font is embedded in the document it was created for returns true if the font is embedded and returns false if it is not

    • embedNow

      public void embedNow(Document doc)
      Embeds the Font.

      Parameters:
      doc - the Document the Font is embedded into
    • measureTextWidth

      public double measureTextWidth(String text, double fontSize)
      Measures the width of the specified text in points, using the Font at the specified size.

      Parameters:
      text - the Text to be measured
      fontSize - the Font size to be used