Package org.apache.fontbox.ttf
Class TrueTypeCollection
- java.lang.Object
-
- org.apache.fontbox.ttf.TrueTypeCollection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class TrueTypeCollection extends java.lang.Object implements java.io.CloseableA TrueType Collection, now more properly known as a "Font Collection" as it may contain either TrueType or OpenType fonts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTrueTypeCollection.TrueTypeFontHeadersProcessorImplement the callback method to callprocessAllFontHeaders(File, TrueTypeFontHeadersProcessor).static interfaceTrueTypeCollection.TrueTypeFontProcessorImplement the callback method to callprocessAllFonts(TrueTypeFontProcessor).
-
Field Summary
Fields Modifier and Type Field Description private long[]fontOffsetsprivate intnumFontsprivate TTFDataStreamstream
-
Constructor Summary
Constructors Modifier Constructor Description TrueTypeCollection(java.io.File file)Creates a new TrueTypeCollection from a .ttc file.TrueTypeCollection(java.io.InputStream stream)Creates a new TrueTypeCollection from a .ttc input stream.privateTrueTypeCollection(TTFDataStream stream)Creates a new TrueTypeCollection from a RandomAccessRead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private static TTFDataStreamcreateBufferedDataStream(RandomAccessRead randomAccessRead, boolean closeAfterReading)private TTFParsercreateFontParserAtIndexAndSeek(int idx)private TrueTypeFontgetFontAtIndex(int idx)TrueTypeFontgetFontByName(java.lang.String name)Get a TT font from a collection.static voidprocessAllFontHeaders(java.io.File ttcFile, TrueTypeCollection.TrueTypeFontHeadersProcessor trueTypeFontProcessor)Run the callback for each TT font in the collection.voidprocessAllFonts(TrueTypeCollection.TrueTypeFontProcessor trueTypeFontProcessor)Run the callback for each TT font in the collection.
-
-
-
Field Detail
-
stream
private final TTFDataStream stream
-
numFonts
private final int numFonts
-
fontOffsets
private final long[] fontOffsets
-
-
Constructor Detail
-
TrueTypeCollection
public TrueTypeCollection(java.io.File file) throws java.io.IOExceptionCreates a new TrueTypeCollection from a .ttc file.- Parameters:
file- The TTC file.- Throws:
java.io.IOException- If the font could not be parsed.
-
TrueTypeCollection
public TrueTypeCollection(java.io.InputStream stream) throws java.io.IOExceptionCreates a new TrueTypeCollection from a .ttc input stream.- Parameters:
stream- A TTC input stream.- Throws:
java.io.IOException- If the font could not be parsed.
-
TrueTypeCollection
private TrueTypeCollection(TTFDataStream stream) throws java.io.IOException
Creates a new TrueTypeCollection from a RandomAccessRead.- Parameters:
randomAccessRead-closeAfterReading-trueto close randomAccessReadbuffered-trueto useRandomAccessReadDataStream,falseto useRandomAccessReadUnbufferedDataStream- Throws:
java.io.IOException- If the font could not be parsed.
-
-
Method Detail
-
createBufferedDataStream
private static TTFDataStream createBufferedDataStream(RandomAccessRead randomAccessRead, boolean closeAfterReading) throws java.io.IOException
- Throws:
java.io.IOException
-
processAllFonts
public void processAllFonts(TrueTypeCollection.TrueTypeFontProcessor trueTypeFontProcessor) throws java.io.IOException
Run the callback for each TT font in the collection.- Parameters:
trueTypeFontProcessor- the object with the callback method.- Throws:
java.io.IOException- if something went wrong when parsing any font or calling the TrueTypeFontProcessor
-
processAllFontHeaders
public static void processAllFontHeaders(java.io.File ttcFile, TrueTypeCollection.TrueTypeFontHeadersProcessor trueTypeFontProcessor) throws java.io.IOExceptionRun the callback for each TT font in the collection.- Parameters:
trueTypeFontProcessor- the object with the callback method.- Throws:
java.io.IOException- if something went wrong when parsing any font
-
getFontAtIndex
private TrueTypeFont getFontAtIndex(int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
createFontParserAtIndexAndSeek
private TTFParser createFontParserAtIndexAndSeek(int idx) throws java.io.IOException
- Throws:
java.io.IOException
-
getFontByName
public TrueTypeFont getFontByName(java.lang.String name) throws java.io.IOException
Get a TT font from a collection.- Parameters:
name- The postscript name of the font.- Returns:
- The found font, nor null if none is found.
- Throws:
java.io.IOException- if there is an error reading the font data
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-