Package org.apache.fontbox.ttf
Class GlyphSubstitutionTable
- java.lang.Object
-
- org.apache.fontbox.ttf.TTFTable
-
- org.apache.fontbox.ttf.GlyphSubstitutionTable
-
public class GlyphSubstitutionTable extends TTFTable
A glyph substitution 'GSUB' table in a TrueType or OpenType font.
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description private GlyphSubstitutionTable.FeatureRecord[]
featureList
private java.lang.String
lastUsedSupportedScript
private static org.apache.commons.logging.Log
LOG
private java.util.Map<java.lang.Integer,java.lang.Integer>
lookupCache
private GlyphSubstitutionTable.LookupTable[]
lookupList
private java.util.Map<java.lang.Integer,java.lang.Integer>
reverseLookup
private java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable>
scriptList
static java.lang.String
TAG
-
Fields inherited from class org.apache.fontbox.ttf.TTFTable
font, initialized
-
-
Constructor Summary
Constructors Constructor Description GlyphSubstitutionTable(TrueTypeFont font)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
applyFeature(GlyphSubstitutionTable.FeatureRecord featureRecord, int gid)
private boolean
containsFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)
private int
doLookup(GlyphSubstitutionTable.LookupTable lookupTable, int gid)
private java.util.List<GlyphSubstitutionTable.FeatureRecord>
getFeatureRecords(java.util.Collection<GlyphSubstitutionTable.LangSysTable> langSysTables, java.util.List<java.lang.String> enabledFeatures)
Get a list ofFeatureRecord
s from a collection ofLangSysTable
s.private java.util.Collection<GlyphSubstitutionTable.LangSysTable>
getLangSysTables(java.lang.String scriptTag)
int
getSubstitution(int gid, java.lang.String[] scriptTags, java.util.List<java.lang.String> enabledFeatures)
Apply glyph substitutions to the supplied gid.int
getUnsubstitution(int sgid)
For a substitute-gid (obtained fromgetSubstitution(int, String[], List)
), retrieve the original gid.(package private) void
read(TrueTypeFont ttf, TTFDataStream data)
This will read the required data from the stream.(package private) GlyphSubstitutionTable.CoverageTable
readCoverageTable(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.FeatureRecord[]
readFeatureList(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.FeatureTable
readFeatureTable(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.LangSysTable
readLangSysTable(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.LookupTable[]
readLookupList(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.LookupSubTable
readLookupSubTable(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.LookupTable
readLookupTable(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.RangeRecord
readRangeRecord(TTFDataStream data)
(package private) java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable>
readScriptList(TTFDataStream data, long offset)
(package private) GlyphSubstitutionTable.ScriptTable
readScriptTable(TTFDataStream data, long offset)
private void
removeFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)
private java.lang.String
selectScriptTag(java.lang.String[] tags)
Choose from one of the supplied OpenType script tags, depending on what the font supports and potentially on context.-
Methods inherited from class org.apache.fontbox.ttf.TTFTable
getCheckSum, getInitialized, getLength, getOffset, getTag, setCheckSum, setLength, setOffset, setTag
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
scriptList
private java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable> scriptList
-
featureList
private GlyphSubstitutionTable.FeatureRecord[] featureList
-
lookupList
private GlyphSubstitutionTable.LookupTable[] lookupList
-
lookupCache
private final java.util.Map<java.lang.Integer,java.lang.Integer> lookupCache
-
reverseLookup
private final java.util.Map<java.lang.Integer,java.lang.Integer> reverseLookup
-
lastUsedSupportedScript
private java.lang.String lastUsedSupportedScript
-
-
Constructor Detail
-
GlyphSubstitutionTable
GlyphSubstitutionTable(TrueTypeFont font)
-
-
Method Detail
-
read
void read(TrueTypeFont ttf, TTFDataStream data) throws java.io.IOException
Description copied from class:TTFTable
This will read the required data from the stream.
-
readScriptList
java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable> readScriptList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readScriptTable
GlyphSubstitutionTable.ScriptTable readScriptTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLangSysTable
GlyphSubstitutionTable.LangSysTable readLangSysTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readFeatureList
GlyphSubstitutionTable.FeatureRecord[] readFeatureList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readFeatureTable
GlyphSubstitutionTable.FeatureTable readFeatureTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupList
GlyphSubstitutionTable.LookupTable[] readLookupList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupTable
GlyphSubstitutionTable.LookupTable readLookupTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupSubTable
GlyphSubstitutionTable.LookupSubTable readLookupSubTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readCoverageTable
GlyphSubstitutionTable.CoverageTable readCoverageTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
selectScriptTag
private java.lang.String selectScriptTag(java.lang.String[] tags)
Choose from one of the supplied OpenType script tags, depending on what the font supports and potentially on context.- Parameters:
tags
-- Returns:
- The best OpenType script tag
-
getLangSysTables
private java.util.Collection<GlyphSubstitutionTable.LangSysTable> getLangSysTables(java.lang.String scriptTag)
-
getFeatureRecords
private java.util.List<GlyphSubstitutionTable.FeatureRecord> getFeatureRecords(java.util.Collection<GlyphSubstitutionTable.LangSysTable> langSysTables, java.util.List<java.lang.String> enabledFeatures)
Get a list ofFeatureRecord
s from a collection ofLangSysTable
s. Optionally filter the returned features by supplying a list of allowed feature tags inenabledFeatures
. Note that features listed as required (LangSysTable#requiredFeatureIndex
) will be included even if not explicitly enabled.- Parameters:
langSysTables
- TheLangSysTable
s indicatingFeatureRecord
s to search forenabledFeatures
- An optional list of feature tags (null
to allow all)- Returns:
- The indicated
FeatureRecord
s
-
containsFeature
private boolean containsFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)
-
removeFeature
private void removeFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)
-
applyFeature
private int applyFeature(GlyphSubstitutionTable.FeatureRecord featureRecord, int gid)
-
doLookup
private int doLookup(GlyphSubstitutionTable.LookupTable lookupTable, int gid)
-
getSubstitution
public int getSubstitution(int gid, java.lang.String[] scriptTags, java.util.List<java.lang.String> enabledFeatures)
Apply glyph substitutions to the supplied gid. The applicable substitutions are determined by thescriptTags
which indicate the language of the gid, and by the list ofenabledFeatures
. To ensure that a single gid isn't mapped to multiple substitutions, subsequent invocations with the same gid will return the same result as the first, regardless of script or enabled features.- Parameters:
gid
- GIDscriptTags
- Script tags applicable to the gid (seeOpenTypeScript
)enabledFeatures
- list of features to apply
-
getUnsubstitution
public int getUnsubstitution(int sgid)
For a substitute-gid (obtained fromgetSubstitution(int, String[], List)
), retrieve the original gid. Only gids previously substituted by this instance can be un-substituted. If you are trying to unsubstitute before you substitute, something is wrong.- Parameters:
sgid
- Substitute GID
-
readRangeRecord
GlyphSubstitutionTable.RangeRecord readRangeRecord(TTFDataStream data) throws java.io.IOException
- Throws:
java.io.IOException
-
-