java.lang.Object
org.sejda.sambox.pdmodel.font.BaseTTFSubsetter
Skeletal implementation for a TTF subsetter. To be used to subset embedded TrueType font and Type
0 fonts with CIDFontType2 descendant This is based on the
TTFSubsetter in FontBox.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final COSDictionaryprivate org.apache.fontbox.ttf.TrueTypeFontprivate final COSStreamprivate final org.sejda.io.SeekableSourceprivate static final org.slf4j.Loggerprivate intprivate static final byte[] -
Constructor Summary
ConstructorsConstructorDescriptionBaseTTFSubsetter(COSDictionary existingFont, COSStream fontFileStream) BaseTTFSubsetter(COSDictionary existingFont, COSStream fontFileStream, org.apache.fontbox.ttf.TrueTypeFont font) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidCreates a subset of the font file containing only the glyphs added to this subsetter.protected byte[]protected byte[]buildGlyfTable(long[] newOffsets) protected byte[]protected byte[]protected byte[]protected byte[]buildLocaTable(long[] newOffsets) protected byte[]protected byte[]buildNameTable(String subsetFontName) protected byte[]protected byte[]private voidcopyBytes(OutputStream os, long offset, int count) abstract COSStreamorg.apache.fontbox.ttf.TrueTypeFontgetFont()private booleanisComposite(ByteBuffer glyphData) private intlog2(int num) voidAdds all the given mappings code -> GID to this subsettervoidsetNumberOfGlyphs(int numberOfGlyphs) Initialize the subsetter before performing a subset(package private) booleanshouldCopyNameRecord(org.apache.fontbox.ttf.NameRecord nr) private longtoUInt32(byte[] bytes) private longtoUInt32(int high, int low) protected voidupdateChecksum(DataOutputStream out, Map<String, byte[]> tables) private longwriteFileHeader(DataOutputStream out, int nTables) private voidwriteFixed(DataOutputStream out, double f) private voidwriteLongDateTime(DataOutputStream out, Calendar calendar) private voidwriteSInt16(DataOutputStream out, short i) voidwriteTableBody(OutputStream os, byte[] bytes) private longwriteTableHeader(DataOutputStream out, String tag, long offset, byte[] bytes) private voidwriteUint16(DataOutputStream out, int i) private voidwriteUint32(DataOutputStream out, long l)
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
PAD_BUF
private static final byte[] PAD_BUF -
fontSource
private final org.sejda.io.SeekableSource fontSource -
glyphIds
-
codeToGIDLookup
-
fontFileStream
-
existingFont
-
font
private org.apache.fontbox.ttf.TrueTypeFont font -
numberOfGlyphs
private int numberOfGlyphs
-
-
Constructor Details
-
BaseTTFSubsetter
public BaseTTFSubsetter(COSDictionary existingFont, COSStream fontFileStream, org.apache.fontbox.ttf.TrueTypeFont font) throws IOException - Parameters:
existingFont- the font dictionary that will be updatedfontFileStream- the corresponding not subsetted FontFile2font- the existing and already parsed font. If null the fontFileStream will be parsed to get the ttf font when needed- Throws:
IOException
-
BaseTTFSubsetter
- Throws:
IOException
-
-
Method Details
-
putAll
Adds all the given mappings code -> GID to this subsetter- Parameters:
codesToGID-
-
apply
Creates a subset of the font file containing only the glyphs added to this subsetter. If anything happens null is returned -
getFont
- Throws:
IOException
-
getGlyphIds
-
doSubset
- Throws:
IOException
-
setNumberOfGlyphs
public void setNumberOfGlyphs(int numberOfGlyphs) Initialize the subsetter before performing a subset -
updateChecksum
- Throws:
IOException
-
addCompositeGlyphs
- Throws:
IOException
-
isComposite
-
buildHeadTable
- Throws:
IOException
-
buildHheaTable
- Throws:
IOException
-
buildMaxpTable
- Throws:
IOException
-
buildNameTable
- Throws:
IOException
-
shouldCopyNameRecord
boolean shouldCopyNameRecord(org.apache.fontbox.ttf.NameRecord nr) -
buildGlyfTable
- Throws:
IOException
-
buildLocaTable
- Throws:
IOException
-
buildHmtxTable
- Throws:
IOException
-
buildPostTable
- Throws:
IOException
-
buildOS2Table
- Throws:
IOException
-
buildCMapTable
- Throws:
IOException
-
copyBytes
- Throws:
IOException
-
writeFixed
- Throws:
IOException
-
writeUint32
- Throws:
IOException
-
writeUint16
- Throws:
IOException
-
writeSInt16
- Throws:
IOException
-
writeLongDateTime
- Throws:
IOException
-
writeFileHeader
- Parameters:
out- The data output stream.nTables- The number of table.- Returns:
- The file offset of the first TTF table to write.
- Throws:
IOException- Upon errors.
-
writeTableHeader
private long writeTableHeader(DataOutputStream out, String tag, long offset, byte[] bytes) throws IOException - Throws:
IOException
-
writeTableBody
- Throws:
IOException
-
toUInt32
private long toUInt32(int high, int low) -
toUInt32
private long toUInt32(byte[] bytes) -
log2
private int log2(int num)
-