org.apache.fop.pdf

## Class PDFFont

- java.lang.Object
- - org.apache.fop.pdf.PDFObject
  - - org.apache.fop.pdf.PDFDictionary
    - - org.apache.fop.pdf.PDFFont

- All Implemented Interfaces:
    PDFWritable
  Direct Known Subclasses:
    PDFFontNonBase14, PDFFontType0

      public class PDFFont
      extends PDFDictionary

  Class representing a /Font object.

  A more complete object expressing the base font name and encoding of a font along with an internal name for the font used within streams of content.

  Fonts are specified on page 198 and onwards of the PDF 1.3 spec.

- - ### Field Summary

    - ### Fields inherited from class org.apache.fop.pdf.PDFDictionary

      `entries, order`

    - ### Fields inherited from class org.apache.fop.pdf.PDFObject

      `log`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PDFFont(String fontname, FontType subtype, String basefont, Object encoding)` create the /Font object

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static PDFFont` | `createFont(String fontname, FontType subtype, String basefont, Object encoding)` factory method with the basic parameters
    `PDFName` | `getBaseFont()` Returns the name of the BaseFont.
    `String` | `getName()` Get the internal name used for this font.
    `protected PDFName` | `getPDFNameForFontType(FontType fontType)` Returns the PDF name for a certain font type.
    `int` | `output(OutputStream stream)` Write the PDF represention of this object
    `void` | `setEncoding(PDFEncoding encoding)` Sets the Encoding value of the font.
    `void` | `setEncoding(String encoding)` Sets the Encoding value of the font.
    `void` | `setToUnicode(PDFCMap cmap)` Sets a ToUnicode CMap.
    `protected void` | `validate()` Validates the PDF object prior to serialization.

    - ### Methods inherited from class org.apache.fop.pdf.PDFDictionary

      `containsKey, get, getChildren, getChildren, keySet, put, put, remove, writeDictionary`

    - ### Methods inherited from class org.apache.fop.pdf.PDFObject

      `contentEquals, encode, encodeBinaryToHexString, encodeString, encodeText, formatObject, getDocument, getDocumentSafely, getGeneration, getObjectID, getObjectNumber, getParent, hasObjectNumber, makeReference, outputInline, referencePDF, setDocument, setObjectNumber, setObjectNumber, setObjectNumber, setParent, supportsObjectStream, toPDF, toPDFString`

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

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

- - ### Constructor Detail

    - #### PDFFont

          public PDFFont(String fontname,
                         FontType subtype,
                         String basefont,
                         Object encoding)

      create the /Font object
      Parameters:
        `fontname` - the internal name for the font
        `subtype` - the font's subtype
        `basefont` - the base font name
        `encoding` - the character encoding schema used by the font

  - ### Method Detail

    - #### setEncoding

          public void setEncoding(String encoding)

      Sets the Encoding value of the font.
      Parameters:
        `encoding` - the encoding

    - #### setEncoding

          public void setEncoding(PDFEncoding encoding)

      Sets the Encoding value of the font.
      Parameters:
        `encoding` - the encoding

    - #### setToUnicode

          public void setToUnicode(PDFCMap cmap)

      Sets a ToUnicode CMap.
      Parameters:
        `cmap` - the ToUnicode character map

    - #### createFont

          public static PDFFont createFont(String fontname,
                                           FontType subtype,
                                           String basefont,
                                           Object encoding)

      factory method with the basic parameters
      Parameters:
        `fontname` - the internal name for the font
        `subtype` - the font's subtype
        `basefont` - the base font name
        `encoding` - the character encoding schema used by the font
      Returns:
        the generated PDFFont object

    - #### getName

          public String getName()

      Get the internal name used for this font.
      Returns:
        the internal name

    - #### getBaseFont

          public PDFName getBaseFont()

      Returns the name of the BaseFont.
      Returns:
        the BaseFont

    - #### getPDFNameForFontType

          protected PDFName getPDFNameForFontType(FontType fontType)

      Returns the PDF name for a certain font type.
      Parameters:
        `fontType` - font type
      Returns:
        String corresponding PDF name

    - #### validate

          protected void validate()

      Validates the PDF object prior to serialization.

    - #### output

          public int output(OutputStream stream)
                     throws IOException

      Write the PDF represention of this object
      Overrides:
        `output` in class `PDFDictionary`
      Parameters:
        `stream` - the stream to write the PDF to
      Returns:
        the number of bytes written
      Throws:
        `IOException` - if there is an error writing to the stream

Copyright © 2025 Apache Software Foundation. All rights reserved.