Package org.apache.fontbox.ttf
Class TrueTypeCollection
java.lang.Object
org.apache.fontbox.ttf.TrueTypeCollection
- All Implemented Interfaces:
Closeable,AutoCloseable
A TrueType Collection, now more properly known as a "Font Collection" as it may contain either
TrueType or OpenType fonts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceImplement the callback method to callprocessAllFontHeaders(File, TrueTypeFontHeadersProcessor).static interfaceImplement the callback method to callprocessAllFonts(TrueTypeFontProcessor). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long[]private final intprivate final TTFDataStream -
Constructor Summary
ConstructorsModifierConstructorDescriptionTrueTypeCollection(File file) Creates a new TrueTypeCollection from a .ttc file.TrueTypeCollection(InputStream stream) Creates a new TrueTypeCollection from a .ttc input stream.privateTrueTypeCollection(TTFDataStream stream) Creates a new TrueTypeCollection from a TTFDataStream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private static TTFDataStreamcreateBufferedDataStream(RandomAccessRead randomAccessRead, boolean closeAfterReading) private TTFParsercreateFontParserAtIndexAndSeek(int idx) private TrueTypeFontgetFontAtIndex(int idx) getFontByName(String name) Get a TT font from a collection.static voidprocessAllFontHeaders(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 Details
-
stream
-
numFonts
private final int numFonts -
fontOffsets
private final long[] fontOffsets
-
-
Constructor Details
-
TrueTypeCollection
Creates a new TrueTypeCollection from a .ttc file.- Parameters:
file- The TTC file.- Throws:
IOException- If the font could not be parsed.
-
TrueTypeCollection
Creates a new TrueTypeCollection from a .ttc input stream.- Parameters:
stream- A TTC input stream.- Throws:
IOException- If the font could not be parsed.
-
TrueTypeCollection
Creates a new TrueTypeCollection from a TTFDataStream.- Parameters:
stream- A data stream to read.- Throws:
IOException- If the font could not be parsed.
-
-
Method Details
-
createBufferedDataStream
private static TTFDataStream createBufferedDataStream(RandomAccessRead randomAccessRead, boolean closeAfterReading) throws IOException - Throws:
IOException
-
processAllFonts
public void processAllFonts(TrueTypeCollection.TrueTypeFontProcessor trueTypeFontProcessor) throws IOException Run the callback for each TT font in the collection.- Parameters:
trueTypeFontProcessor- the object with the callback method.- Throws:
IOException- if something went wrong when parsing any font or calling the TrueTypeFontProcessor
-
processAllFontHeaders
public static void processAllFontHeaders(File ttcFile, TrueTypeCollection.TrueTypeFontHeadersProcessor trueTypeFontProcessor) throws IOException Run the callback for each TT font in the collection.- Parameters:
trueTypeFontProcessor- the object with the callback method.- Throws:
IOException- if something went wrong when parsing any font
-
getFontAtIndex
- Throws:
IOException
-
createFontParserAtIndexAndSeek
- Throws:
IOException
-
getFontByName
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:
IOException- if there is an error reading the font data
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-