Package com.itextpdf.io.font
Class TrueTypeFont
- java.lang.Object
-
- com.itextpdf.io.font.FontProgram
-
- com.itextpdf.io.font.TrueTypeFont
-
- Direct Known Subclasses:
DocTrueTypeFont
public class TrueTypeFont extends FontProgram
-
-
Field Summary
Fields Modifier and Type Field Description protected int[][]
bBoxes
private OpenTypeParser
fontParser
private byte[]
fontStreamBytes
private OpenTypeGdefTableReader
gdefTable
private GlyphPositioningTableReader
gposTable
private GlyphSubstitutionTableReader
gsubTable
protected boolean
isVertical
protected IntHashtable
kerning
The map containing the kerning information.-
Fields inherited from class com.itextpdf.io.font.FontProgram
avgWidth, codeToGlyph, DEFAULT_WIDTH, encodingScheme, fontIdentification, fontMetrics, fontNames, HORIZONTAL_SCALING_FACTOR, isFontSpecific, registry, unicodeToGlyph, UNITS_NORMALIZATION
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TrueTypeFont()
TrueTypeFont(byte[] ttf)
(package private)
TrueTypeFont(byte[] ttc, int ttcIndex)
private
TrueTypeFont(OpenTypeParser fontParser)
TrueTypeFont(java.lang.String path)
(package private)
TrueTypeFont(java.lang.String ttcPath, int ttcIndex)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.util.Map<java.lang.Integer,int[]>
getActiveCmap()
java.lang.String[]
getCodePagesSupported()
Gets the code pages supported by the font.int
getDirectoryOffset()
The offset from the start of the file to the table directory.byte[]
getFontStreamBytes()
OpenTypeGdefTableReader
getGdefTable()
GlyphPositioningTableReader
getGposTable()
GlyphSubstitutionTableReader
getGsubTable()
int
getKerning(Glyph first, Glyph second)
Gets the kerning between two glyphs.int
getNumberOfCmaps()
Gets the number of the “cmap” subtables for the currentTrueTypeFont
program.int
getPdfFontFlags()
byte[]
getSubset(java.util.Set<java.lang.Integer> glyphs, boolean subset)
boolean
hasKernPairs()
private void
initializeFontProperties()
boolean
isBuiltWith(java.lang.String fontProgram)
Checks whether theFontProgram
was built with corresponding fontName.boolean
isCff()
boolean
isCmapPresent(int platformID, int encodingID)
Checks whether currentTrueTypeFont
program contains the “cmap” subtable with provided platform ID and encoding ID.java.util.Set<java.lang.Integer>
mapGlyphsCidsToGids(java.util.Set<java.lang.Integer> glyphs)
Maps a set of glyph CIDs (as used in PDF file) to corresponding GID values (as a glyph primary identifier in the font file).protected void
readGdefTable()
protected void
readGposTable()
protected void
readGsubTable()
private static int[]
toCompactRange(java.util.List<int[]> ranges)
Normalizes given ranges by making sure that first values in pairs are lower than second values and merges overlapping ranges in one.void
updateUsedGlyphs(java.util.SortedSet<java.lang.Integer> usedGlyphs, boolean subset, java.util.List<int[]> subsetRanges)
The method will update usedGlyphs with additional range or with all glyphs if there is no subset.-
Methods inherited from class com.itextpdf.io.font.FontProgram
convertGlyphSpaceToTextSpace, convertGlyphSpaceToTextSpace, convertGlyphSpaceToTextSpace, convertTextSpaceToGlyphSpace, countOfGlyphs, fixSpaceIssue, getAvgWidth, getCharBBox, getFontIdentification, getFontMetrics, getFontNames, getGlyph, getGlyphByCode, getKerning, getRegistry, getWidth, isFontSpecific, setBbox, setBold, setCapHeight, setFixedPitch, setFontFamily, setFontName, setFontStretch, setFontWeight, setItalicAngle, setRegistry, setStemH, setStemV, setTypoAscender, setTypoDescender, setXHeight, toString, trimFontStyle
-
-
-
-
Field Detail
-
fontParser
private OpenTypeParser fontParser
-
bBoxes
protected int[][] bBoxes
-
isVertical
protected boolean isVertical
-
gsubTable
private GlyphSubstitutionTableReader gsubTable
-
gposTable
private GlyphPositioningTableReader gposTable
-
gdefTable
private OpenTypeGdefTableReader gdefTable
-
kerning
protected IntHashtable kerning
The map containing the kerning information. It represents the content of table 'kern'. The key is anInteger
where the top 16 bits are the glyph number for the first character and the lower 16 bits are the glyph number for the second character. The value is the amount of kerning in normalized 1000 units as anInteger
. This value is usually negative.
-
fontStreamBytes
private byte[] fontStreamBytes
-
-
Constructor Detail
-
TrueTypeFont
private TrueTypeFont(OpenTypeParser fontParser) throws java.io.IOException
- Throws:
java.io.IOException
-
TrueTypeFont
protected TrueTypeFont()
-
TrueTypeFont
public TrueTypeFont(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
TrueTypeFont
public TrueTypeFont(byte[] ttf) throws java.io.IOException
- Throws:
java.io.IOException
-
TrueTypeFont
TrueTypeFont(java.lang.String ttcPath, int ttcIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
TrueTypeFont
TrueTypeFont(byte[] ttc, int ttcIndex) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
hasKernPairs
public boolean hasKernPairs()
- Overrides:
hasKernPairs
in classFontProgram
-
getKerning
public int getKerning(Glyph first, Glyph second)
Gets the kerning between two glyphs.- Specified by:
getKerning
in classFontProgram
- Parameters:
first
- the first glyphsecond
- the second glyph- Returns:
- the kerning to be applied
-
isCff
public boolean isCff()
-
getActiveCmap
public java.util.Map<java.lang.Integer,int[]> getActiveCmap()
-
getFontStreamBytes
public byte[] getFontStreamBytes()
-
getPdfFontFlags
public int getPdfFontFlags()
- Specified by:
getPdfFontFlags
in classFontProgram
-
getDirectoryOffset
public int getDirectoryOffset()
The offset from the start of the file to the table directory. It is 0 for TTF and may vary for TTC depending on the chosen font.- Returns:
- directory Offset
-
getGsubTable
public GlyphSubstitutionTableReader getGsubTable()
-
getGposTable
public GlyphPositioningTableReader getGposTable()
-
getGdefTable
public OpenTypeGdefTableReader getGdefTable()
-
getSubset
public byte[] getSubset(java.util.Set<java.lang.Integer> glyphs, boolean subset)
-
mapGlyphsCidsToGids
public java.util.Set<java.lang.Integer> mapGlyphsCidsToGids(java.util.Set<java.lang.Integer> glyphs)
Maps a set of glyph CIDs (as used in PDF file) to corresponding GID values (as a glyph primary identifier in the font file). This call is only meaningful for fonts that return true forisCff()
. For other types of fonts, GID and CID are always the same, so that call would essentially return a set of the same values.- Parameters:
glyphs
- a set of glyph CIDs- Returns:
- a set of glyph ids corresponding to the passed glyph CIDs
-
isCmapPresent
public boolean isCmapPresent(int platformID, int encodingID)
Checks whether currentTrueTypeFont
program contains the “cmap” subtable with provided platform ID and encoding ID.- Parameters:
platformID
- platform IDencodingID
- encoding ID- Returns:
true
if “cmap” subtable with provided platform ID and encoding ID is present in the font program,false
otherwise
-
getNumberOfCmaps
public int getNumberOfCmaps()
Gets the number of the “cmap” subtables for the currentTrueTypeFont
program.- Returns:
- the number of the “cmap” subtables
-
readGdefTable
protected void readGdefTable() throws java.io.IOException
- Throws:
java.io.IOException
-
readGsubTable
protected void readGsubTable() throws java.io.IOException
- Throws:
java.io.IOException
-
readGposTable
protected void readGposTable() throws java.io.IOException
- Throws:
java.io.IOException
-
initializeFontProperties
private void initializeFontProperties() throws java.io.IOException
- Throws:
java.io.IOException
-
getCodePagesSupported
public java.lang.String[] getCodePagesSupported()
Gets the code pages supported by the font.- Returns:
- the code pages supported by the font
-
isBuiltWith
public boolean isBuiltWith(java.lang.String fontProgram)
Description copied from class:FontProgram
Checks whether theFontProgram
was built with corresponding fontName. Default value is false unless overridden.- Overrides:
isBuiltWith
in classFontProgram
- Parameters:
fontProgram
- a font name or path to a font program- Returns:
- true, if the FontProgram was built with the fontProgram. Otherwise false.
-
close
public void close() throws java.io.IOException
- Throws:
java.io.IOException
-
updateUsedGlyphs
public void updateUsedGlyphs(java.util.SortedSet<java.lang.Integer> usedGlyphs, boolean subset, java.util.List<int[]> subsetRanges)
The method will update usedGlyphs with additional range or with all glyphs if there is no subset. This set of used glyphs can be used for building width array and ToUnicode CMAP.- Parameters:
usedGlyphs
- a set of integers, which are glyph ids that denote used glyphs. This set is updated inside of the method if needed.subset
- subset statussubsetRanges
- additional subset ranges
-
toCompactRange
private static int[] toCompactRange(java.util.List<int[]> ranges)
Normalizes given ranges by making sure that first values in pairs are lower than second values and merges overlapping ranges in one.- Parameters:
ranges
- aList
of integer arrays, which are constituted by pairs of ints that denote each range limits. Each integer array size shall be a multiple of two- Returns:
- single merged array consisting of pairs of integers, each of them denoting a range
-
-