FontFileReader (Apache FOP Core 2.11 API)
Date: 2025-04-24

org.apache.fop.fonts.truetype

## Class FontFileReader

- java.lang.Object
- - org.apache.fop.fonts.truetype.FontFileReader

-     public class FontFileReader
      extends Object

  Reads a TrueType font file into a byte array and provides file like functions for array access.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FontFileReader(InputStream in)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `getAllBytes()` Returns the full byte array representation of the file.
    `byte[]` | `getBytes(int offset, int length)` Return a copy of the internal array
    `int` | `getCurrentPos()` Returns current file position.
    `int` | `getFileSize()` Returns the size of the file.
    `byte` | `readTTFByte()` Read 1 signed byte.
    `int` | `readTTFLong()` Read 4 bytes.
    `short` | `readTTFShort()` Read 2 bytes signed.
    `short` | `readTTFShort(long pos)` Read 2 bytes signed at position pos without changing current position.
    `String` | `readTTFString()` Read a NUL terminated ISO-8859-1 string.
    `String` | `readTTFString(int len)` Read an ISO-8859-1 string of len bytes.
    `String` | `readTTFString(int len, int encodingID)` Read an ISO-8859-1 string of len bytes.
    `int` | `readTTFUByte()` Read 1 unsigned byte.
    `long` | `readTTFULong()` Read 4 bytes.
    `int` | `readTTFUShort()` Read 2 bytes unsigned.
    `int` | `readTTFUShort(long pos)` Read 2 bytes unsigned at position pos without changing current position.
    `void` | `seekSet(long offset)` Set current file position to offset
    `void` | `skip(long add)` Skip a given number of bytes.
    `void` | `writeTTFUShort(long pos, int val)` Write a USHort at a given position.

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

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

- - ### Constructor Detail

    - #### FontFileReader

          public FontFileReader(InputStream in)
                         throws IOException

      Constructor
      Parameters:
        `in` - InputStream to read from
      Throws:
        `IOException` - In case of an I/O problem

  - ### Method Detail

    - #### seekSet

          public void seekSet(long offset)
                       throws IOException

      Set current file position to offset
      Parameters:
        `offset` - The new offset to set
      Throws:
        `IOException` - In case of an I/O problem

    - #### skip

          public void skip(long add)
                    throws IOException

      Skip a given number of bytes.
      Parameters:
        `add` - The number of bytes to advance
      Throws:
        `IOException` - In case of an I/O problem

    - #### getCurrentPos

          public int getCurrentPos()

      Returns current file position.
      Returns:
        int The current position.

    - #### getFileSize

          public int getFileSize()

      Returns the size of the file.
      Returns:
        int The filesize

    - #### readTTFByte

          public final byte readTTFByte()
                                 throws IOException

      Read 1 signed byte.
      Returns:
        One byte
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFUByte

          public final int readTTFUByte()
                                 throws IOException

      Read 1 unsigned byte.
      Returns:
        One unsigned byte
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFShort

          public final short readTTFShort()
                                   throws IOException

      Read 2 bytes signed.
      Returns:
        One signed short
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFUShort

          public final int readTTFUShort()
                                  throws IOException

      Read 2 bytes unsigned.
      Returns:
        One unsigned short
      Throws:
        `IOException` - If EOF is reached

    - #### writeTTFUShort

          public final void writeTTFUShort(long pos,
                                           int val)
                                    throws IOException

      Write a USHort at a given position.
      Parameters:
        `pos` - The absolute position to write to
        `val` - The value to write
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFShort

          public final short readTTFShort(long pos)
                                   throws IOException

      Read 2 bytes signed at position pos without changing current position.
      Parameters:
        `pos` - The absolute position to read from
      Returns:
        One signed short
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFUShort

          public final int readTTFUShort(long pos)
                                  throws IOException

      Read 2 bytes unsigned at position pos without changing current position.
      Parameters:
        `pos` - The absolute position to read from
      Returns:
        One unsigned short
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFLong

          public final int readTTFLong()
                                throws IOException

      Read 4 bytes.
      Returns:
        One signed integer
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFULong

          public final long readTTFULong()
                                  throws IOException

      Read 4 bytes.
      Returns:
        One unsigned integer
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFString

          public final String readTTFString()
                                     throws IOException

      Read a NUL terminated ISO-8859-1 string.
      Returns:
        A String
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFString

          public final String readTTFString(int len)
                                     throws IOException

      Read an ISO-8859-1 string of len bytes.
      Parameters:
        `len` - The length of the string to read
      Returns:
        A String
      Throws:
        `IOException` - If EOF is reached

    - #### readTTFString

          public final String readTTFString(int len,
                                            int encodingID)
                                     throws IOException

      Read an ISO-8859-1 string of len bytes.
      Parameters:
        `len` - The length of the string to read
        `encodingID` - the string encoding id (presently ignored; always uses UTF-16BE)
      Returns:
        A String
      Throws:
        `IOException` - If EOF is reached

    - #### getBytes

          public byte[] getBytes(int offset,
                                 int length)
                          throws IOException

      Return a copy of the internal array
      Parameters:
        `offset` - The absolute offset to start reading from
        `length` - The number of bytes to read
      Returns:
        An array of bytes
      Throws:
        `IOException` - if out of bounds

    - #### getAllBytes

          public byte[] getAllBytes()

      Returns the full byte array representation of the file.
      Returns:
        byte array.

Copyright © 2025 Apache Software Foundation. All rights reserved.