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.
-
-
Field Summary
Fields Modifier and Type Field Description private FeatureListTablefeatureListTableprivate GsubDatagsubDataprivate java.lang.StringlastUsedSupportedScriptprivate static org.apache.commons.logging.LogLOGprivate java.util.Map<java.lang.Integer,java.lang.Integer>lookupCacheprivate LookupListTablelookupListTableprivate java.util.Map<java.lang.Integer,java.lang.Integer>reverseLookupprivate java.util.Map<java.lang.String,ScriptTable>scriptListstatic java.lang.StringTAGprivate static java.util.regex.PatternWORDPATTERNThe regex represents 4 'word characters' [a-zA-Z_0-9], seejava.util.regex.ASCII#WORD.-
Fields inherited from class org.apache.fontbox.ttf.TTFTable
initialized
-
-
Constructor Summary
Constructors Constructor Description GlyphSubstitutionTable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intapplyFeature(FeatureRecord featureRecord, int gid)private booleancontainsFeature(java.util.List<FeatureRecord> featureRecords, java.lang.String featureTag)private intdoLookup(LookupTable lookupTable, int gid)private java.util.List<FeatureRecord>getFeatureRecords(java.util.Collection<LangSysTable> langSysTables, java.util.List<java.lang.String> enabledFeatures)Get a list ofFeatureRecords from a collection ofLangSysTables.GsubDatagetGsubData()Returns a GsubData instance containing all scripts of the table.GsubDatagetGsubData(java.lang.String scriptTag)Builds a newGsubDatainstance for given script tag.private java.util.Collection<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.java.util.Set<java.lang.String>getSupportedScriptTags()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.private LookupSubTablereadAlternateSubstitutionSubtable(TTFDataStream data, long offset)private CoverageTablereadCoverageTable(TTFDataStream data, long offset)private FeatureListTablereadFeatureList(TTFDataStream data, long offset)private FeatureTablereadFeatureTable(TTFDataStream data, long offset)private LangSysTablereadLangSysTable(TTFDataStream data, long offset)private LigatureSetTablereadLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId)private LookupSubTablereadLigatureSubstitutionSubtable(TTFDataStream data, long offset)private LigatureTablereadLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId)private LookupListTablereadLookupList(TTFDataStream data, long offset)private LookupSubTablereadLookupSubtable(TTFDataStream data, long offset, int lookupType)private LookupTablereadLookupTable(TTFDataStream data, long offset)private LookupSubTablereadMultipleSubstitutionSubtable(TTFDataStream data, long offset)private RangeRecordreadRangeRecord(TTFDataStream data)private java.util.Map<java.lang.String,ScriptTable>readScriptList(TTFDataStream data, long offset)private ScriptTablereadScriptTable(TTFDataStream data, long offset)private LookupSubTablereadSingleLookupSubTable(TTFDataStream data, long offset)private voidremoveFeature(java.util.List<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, readHeaders, 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.Map<java.lang.String,ScriptTable> scriptList
-
featureListTable
private FeatureListTable featureListTable
-
lookupListTable
private LookupListTable lookupListTable
-
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
-
gsubData
private GsubData gsubData
-
WORDPATTERN
private static final java.util.regex.Pattern WORDPATTERN
The regex represents 4 'word characters' [a-zA-Z_0-9], seejava.util.regex.ASCII#WORD.Note: the ' '-character is not matched!
-
-
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
private java.util.Map<java.lang.String,ScriptTable> readScriptList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readScriptTable
private ScriptTable readScriptTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLangSysTable
private LangSysTable readLangSysTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readFeatureList
private FeatureListTable readFeatureList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readFeatureTable
private FeatureTable readFeatureTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupList
private LookupListTable readLookupList(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupSubtable
private LookupSubTable readLookupSubtable(TTFDataStream data, long offset, int lookupType) throws java.io.IOException
- Throws:
java.io.IOException
-
readLookupTable
private LookupTable readLookupTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readSingleLookupSubTable
private LookupSubTable readSingleLookupSubTable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readMultipleSubstitutionSubtable
private LookupSubTable readMultipleSubstitutionSubtable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readAlternateSubstitutionSubtable
private LookupSubTable readAlternateSubstitutionSubtable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLigatureSubstitutionSubtable
private LookupSubTable readLigatureSubstitutionSubtable(TTFDataStream data, long offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readLigatureSetTable
private LigatureSetTable readLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId) throws java.io.IOException
- Throws:
java.io.IOException
-
readLigatureTable
private LigatureTable readLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId) throws java.io.IOException
- Throws:
java.io.IOException
-
readCoverageTable
private 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<LangSysTable> getLangSysTables(java.lang.String scriptTag)
-
getFeatureRecords
private java.util.List<FeatureRecord> getFeatureRecords(java.util.Collection<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<FeatureRecord> featureRecords, java.lang.String featureTag)
-
removeFeature
private void removeFeature(java.util.List<FeatureRecord> featureRecords, java.lang.String featureTag)
-
applyFeature
private int applyFeature(FeatureRecord featureRecord, int gid)
-
doLookup
private int doLookup(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- Returns:
- the id of the glyph substitution
-
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- Returns:
- the original gid of a substitute-gid
-
getGsubData
public GsubData getGsubData()
Returns a GsubData instance containing all scripts of the table.- Returns:
- the GsubData instance representing the table
-
getGsubData
public GsubData getGsubData(java.lang.String scriptTag)
Builds a newGsubDatainstance for given script tag. In contrast to neighbourgetGsubData()method, this one does not try to find the first supported language and load GSUB data for it. Instead, it fetches the data for the givenscriptTag(if it's supported by the font) leaving the language unspecified. It means that even after successful reading of GSUB data, the actual glyph substitution may not work if there is no correspondingGsubWorkerimplementation for it. Note: This method performs searching on every invocation (no results are cached)- Parameters:
scriptTag- a script tag for which the data is needed- Returns:
- GSUB data for the given script or
nullif no such script in the font
-
getSupportedScriptTags
public java.util.Set<java.lang.String> getSupportedScriptTags()
- Returns:
- a read-only view of the script tags for which this GSUB table has records
-
readRangeRecord
private RangeRecord readRangeRecord(TTFDataStream data) throws java.io.IOException
- Throws:
java.io.IOException
-
-