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[]featureListprivate java.lang.StringlastUsedSupportedScriptprivate static org.apache.commons.logging.LogLOGprivate java.util.Map<java.lang.Integer,java.lang.Integer>lookupCacheprivate GlyphSubstitutionTable.LookupTable[]lookupListprivate java.util.Map<java.lang.Integer,java.lang.Integer>reverseLookupprivate java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable>scriptListstatic java.lang.StringTAG-
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 intapplyFeature(GlyphSubstitutionTable.FeatureRecord featureRecord, int gid)private booleancontainsFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)private intdoLookup(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 ofFeatureRecords from a collection ofLangSysTables.private java.util.Collection<GlyphSubstitutionTable.LangSysTable>getLangSysTables(java.lang.String scriptTag)intgetSubstitution(int gid, java.lang.String[] scriptTags, java.util.List<java.lang.String> enabledFeatures)Apply glyph substitutions to the supplied gid.intgetUnsubstitution(int sgid)For a substitute-gid (obtained fromgetSubstitution(int, String[], List)), retrieve the original gid.(package private) voidread(TrueTypeFont ttf, TTFDataStream data)This will read the required data from the stream.(package private) GlyphSubstitutionTable.CoverageTablereadCoverageTable(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.FeatureRecord[]readFeatureList(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.FeatureTablereadFeatureTable(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.LangSysTablereadLangSysTable(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.LookupTable[]readLookupList(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.LookupSubTablereadLookupSubTable(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.LookupTablereadLookupTable(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.RangeRecordreadRangeRecord(TTFDataStream data)(package private) java.util.LinkedHashMap<java.lang.String,GlyphSubstitutionTable.ScriptTable>readScriptList(TTFDataStream data, long offset)(package private) GlyphSubstitutionTable.ScriptTablereadScriptTable(TTFDataStream data, long offset)private voidremoveFeature(java.util.List<GlyphSubstitutionTable.FeatureRecord> featureRecords, java.lang.String featureTag)private java.lang.StringselectScriptTag(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:TTFTableThis 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 ofFeatureRecords from a collection ofLangSysTables. 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- TheLangSysTables indicatingFeatureRecords to search forenabledFeatures- An optional list of feature tags (nullto allow all)- Returns:
- The indicated
FeatureRecords
-
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 thescriptTagswhich 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
-
-