Class FontFileReader
java.lang.Object
org.docx4j.fonts.fop.fonts.truetype.FontFileReader
public class FontFileReader
extends java.lang.Object
Reads a TrueType font file into a byte array and
provides file like functions for array access.
-
Constructor Summary
Constructors Constructor Description FontFileReader(java.io.InputStream in)ConstructorFontFileReader(java.lang.String fileName)Constructor -
Method Summary
Modifier and Type Method Description byte[]getBytes(int offset, int length)Return a copy of the internal arrayintgetCurrentPos()Returns current file position.intgetFileSize()Returns the size of the file.byteread()Read 1 byte.bytereadTTFByte()Read 1 signed byte.intreadTTFLong()Read 4 bytes.shortreadTTFShort()Read 2 bytes signed.shortreadTTFShort(long pos)Read 2 bytes signed at position pos without changing current position.java.lang.StringreadTTFString()Read a NUL terminated ISO-8859-1 string.java.lang.StringreadTTFString(int len)Read an ISO-8859-1 string of len bytes.java.lang.StringreadTTFString(int len, int encodingID)Read an ISO-8859-1 string of len bytes.intreadTTFUByte()Read 1 unsigned byte.longreadTTFULong()Read 4 bytes.intreadTTFUShort()Read 2 bytes unsigned.intreadTTFUShort(long pos)Read 2 bytes unsigned at position pos without changing current position.voidseekAdd(long add)Set current file position to offsetvoidseekSet(long offset)Set current file position to offsetvoidskip(long add)Skip a given number of bytes.voidwriteTTFUShort(int pos, int val)Write a USHort at a given position.
-
Constructor Details
-
FontFileReader
public FontFileReader(java.lang.String fileName) throws java.io.IOExceptionConstructor- Parameters:
fileName- filename to read- Throws:
java.io.IOException- In case of an I/O problem
-
FontFileReader
public FontFileReader(java.io.InputStream in) throws java.io.IOExceptionConstructor- Parameters:
in- InputStream to read from- Throws:
java.io.IOException- In case of an I/O problem
-
-
Method Details
-
seekSet
public void seekSet(long offset) throws java.io.IOExceptionSet current file position to offset- Parameters:
offset- The new offset to set- Throws:
java.io.IOException- In case of an I/O problem
-
seekAdd
public void seekAdd(long add) throws java.io.IOExceptionSet current file position to offset- Parameters:
add- The number of bytes to advance- Throws:
java.io.IOException- In case of an I/O problem
-
skip
public void skip(long add) throws java.io.IOExceptionSkip a given number of bytes.- Parameters:
add- The number of bytes to advance- Throws:
java.io.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
-
read
public byte read() throws java.io.IOExceptionRead 1 byte.- Returns:
- One byte
- Throws:
java.io.IOException- If EOF is reached
-
readTTFByte
public final byte readTTFByte() throws java.io.IOExceptionRead 1 signed byte.- Returns:
- One byte
- Throws:
java.io.IOException- If EOF is reached
-
readTTFUByte
public final int readTTFUByte() throws java.io.IOExceptionRead 1 unsigned byte.- Returns:
- One unsigned byte
- Throws:
java.io.IOException- If EOF is reached
-
readTTFShort
public final short readTTFShort() throws java.io.IOExceptionRead 2 bytes signed.- Returns:
- One signed short
- Throws:
java.io.IOException- If EOF is reached
-
readTTFUShort
public final int readTTFUShort() throws java.io.IOExceptionRead 2 bytes unsigned.- Returns:
- One unsigned short
- Throws:
java.io.IOException- If EOF is reached
-
writeTTFUShort
public final void writeTTFUShort(int pos, int val) throws java.io.IOExceptionWrite a USHort at a given position.- Parameters:
pos- The absolute position to write toval- The value to write- Throws:
java.io.IOException- If EOF is reached
-
readTTFShort
public final short readTTFShort(long pos) throws java.io.IOExceptionRead 2 bytes signed at position pos without changing current position.- Parameters:
pos- The absolute position to read from- Returns:
- One signed short
- Throws:
java.io.IOException- If EOF is reached
-
readTTFUShort
public final int readTTFUShort(long pos) throws java.io.IOExceptionRead 2 bytes unsigned at position pos without changing current position.- Parameters:
pos- The absolute position to read from- Returns:
- One unsigned short
- Throws:
java.io.IOException- If EOF is reached
-
readTTFLong
public final int readTTFLong() throws java.io.IOExceptionRead 4 bytes.- Returns:
- One signed integer
- Throws:
java.io.IOException- If EOF is reached
-
readTTFULong
public final long readTTFULong() throws java.io.IOExceptionRead 4 bytes.- Returns:
- One unsigned integer
- Throws:
java.io.IOException- If EOF is reached
-
readTTFString
public final java.lang.String readTTFString() throws java.io.IOExceptionRead a NUL terminated ISO-8859-1 string.- Returns:
- A String
- Throws:
java.io.IOException- If EOF is reached
-
readTTFString
public final java.lang.String readTTFString(int len) throws java.io.IOExceptionRead an ISO-8859-1 string of len bytes.- Parameters:
len- The length of the string to read- Returns:
- A String
- Throws:
java.io.IOException- If EOF is reached
-
readTTFString
public final java.lang.String readTTFString(int len, int encodingID) throws java.io.IOExceptionRead an ISO-8859-1 string of len bytes.- Parameters:
len- The length of the string to read- Returns:
- A String
- Throws:
java.io.IOException- If EOF is reached
-
getBytes
public byte[] getBytes(int offset, int length) throws java.io.IOExceptionReturn a copy of the internal array- Parameters:
offset- The absolute offset to start reading fromlength- The number of bytes to read- Returns:
- An array of bytes
- Throws:
java.io.IOException- if out of bounds
-