Top Description Fields Constructors Methods
org.apache.fontbox.ttf

public Class GlyphSubstitutionTable

extends TTFTable
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Collection, .Collections, .HashMap, .Iterator, .LinkedHashMap, .List, .Map, .Set, java.util.regex.Pattern, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.ttf.gsub.GlyphSubstitutionDataExtractor, org.apache.fontbox.ttf.model.GsubData, org.apache.fontbox.ttf.table.common.CoverageTable, .CoverageTableFormat1, .CoverageTableFormat2, .FeatureListTable, .FeatureRecord, .FeatureTable, .LangSysTable, .LookupListTable, .LookupSubTable, .LookupTable, .RangeRecord, .ScriptTable, org.apache.fontbox.ttf.table.gsub.AlternateSetTable, .LigatureSetTable, .LigatureTable, .LookupTypeAlternateSubstitutionFormat1, .LookupTypeLigatureSubstitutionSubstFormat1, .LookupTypeMultipleSubstitutionFormat1, .LookupTypeSingleSubstFormat1, .LookupTypeSingleSubstFormat2, .SequenceTable

A glyph substitution 'GSUB' table in a TrueType or OpenType font.
Author
Aaron Madlon-Kay

Field Summary

Modifier and TypeField and Description
private FeatureListTable
private GsubData
private String
private static final Log
private final Map<Integer, Integer>
private LookupListTable
private final Map<Integer, Integer>
private Map<String, ScriptTable>
public static final String
private static final Pattern
WORDPATTERN

The regex represents 4 'word characters' [a-zA-Z_0-9], see java.util.regex.ASCII#WORD.

Inherited from org.apache.fontbox.ttf.TTFTable:
initialized

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private int
applyFeature(FeatureRecord featureRecord, int gid)

private boolean
containsFeature(List<FeatureRecord> featureRecords, String featureTag)

private int
doLookup(LookupTable lookupTable, int gid)

private List<FeatureRecord>

Returns:

The indicated FeatureRecords
getFeatureRecords
(Collection<LangSysTable>
The LangSysTables indicating FeatureRecords to search for
langSysTables
,
final List<String>
An optional list of feature tags (null to allow all)
enabledFeatures
)

Get a list of FeatureRecords from a collection of LangSysTables.

public GsubData

Returns:

the GsubData instance representing the table
getGsubData
()

Returns a GsubData instance containing all scripts of the table.

public GsubData

Returns:

GSUB data for the given script or null if no such script in the font
getGsubData
(String
a script tag for which the data is needed
scriptTag
)

Builds a new GsubData instance for given script tag.

private Collection<LangSysTable>
public int

Returns:

the id of the glyph substitution
getSubstitution
(int
GID
gid
,
String[]
Script tags applicable to the gid (see OpenTypeScript)
scriptTags
,
List<String>
list of features to apply
enabledFeatures
)

Apply glyph substitutions to the supplied gid.

public Set<String>

Returns:

a read-only view of the script tags for which this GSUB table has records
getSupportedScriptTags
()

public int

Returns:

the original gid of a substitute-gid
getUnsubstitution
(int
Substitute GID
sgid
)

For a substitute-gid (obtained from getSubstitution(int, String[], List)), retrieve the original gid.

pack-priv void
read(TrueTypeFont
The font that is being read.
ttf
,
TTFDataStream
The stream to read the data from.
data
)

Overrides org.apache.fontbox.ttf.TTFTable.read.

This will read the required data from the stream.

private LookupSubTable
private CoverageTable
readCoverageTable(TTFDataStream data, long offset)

private FeatureListTable
readFeatureList(TTFDataStream data, long offset)

private FeatureTable
readFeatureTable(TTFDataStream data, long offset)

private LangSysTable
readLangSysTable(TTFDataStream data, long offset)

private LigatureSetTable
readLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId)

private LookupSubTable
private LigatureTable
readLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId)

private LookupListTable
readLookupList(TTFDataStream data, long offset)

private LookupSubTable
readLookupSubtable(TTFDataStream data, long offset, int lookupType)

private LookupTable
readLookupTable(TTFDataStream data, long offset)

private LookupSubTable
private RangeRecord
private Map<String, ScriptTable>
readScriptList(TTFDataStream data, long offset)

private ScriptTable
readScriptTable(TTFDataStream data, long offset)

private LookupSubTable
private void
removeFeature(List<FeatureRecord> featureRecords, String featureTag)

private String

Returns:

The best OpenType script tag
selectScriptTag
(String[] tags)

Choose from one of the supplied OpenType script tags, depending on what the font supports and potentially on context.

Inherited from org.apache.fontbox.ttf.TTFTable:
getCheckSumgetInitializedgetLengthgetOffsetgetTagreadHeaderssetCheckSumsetLengthsetOffsetsetTag

Field Detail

featureListTableback to summary
private FeatureListTable featureListTable
gsubDataback to summary
private GsubData gsubData
lastUsedSupportedScriptback to summary
private String lastUsedSupportedScript
LOGback to summary
private static final Log LOG
lookupCacheback to summary
private final Map<Integer, Integer> lookupCache
lookupListTableback to summary
private LookupListTable lookupListTable
reverseLookupback to summary
private final Map<Integer, Integer> reverseLookup
scriptListback to summary
private Map<String, ScriptTable> scriptList
TAGback to summary
public static final String TAG
WORDPATTERNback to summary
private static final Pattern WORDPATTERN

The regex represents 4 'word characters' [a-zA-Z_0-9], see java.util.regex.ASCII#WORD.

Note

the ' '-character is not matched!

Constructor Detail

GlyphSubstitutionTableback to summary
pack-priv GlyphSubstitutionTable()

Method Detail

applyFeatureback to summary
private int applyFeature(FeatureRecord featureRecord, int gid)
containsFeatureback to summary
private boolean containsFeature(List<FeatureRecord> featureRecords, String featureTag)
doLookupback to summary
private int doLookup(LookupTable lookupTable, int gid)
getFeatureRecordsback to summary
private List<FeatureRecord> getFeatureRecords(Collection<LangSysTable> langSysTables, final List<String> enabledFeatures)

Get a list of FeatureRecords from a collection of LangSysTables. Optionally filter the returned features by supplying a list of allowed feature tags in enabledFeatures. Note that features listed as required (LangSysTable#requiredFeatureIndex) will be included even if not explicitly enabled.

Parameters
langSysTables:Collection<LangSysTable>

The LangSysTables indicating FeatureRecords to search for

enabledFeatures:List<String>

An optional list of feature tags (null to allow all)

Returns:List<FeatureRecord>

The indicated FeatureRecords

getGsubDataback to summary
public GsubData getGsubData()

Returns a GsubData instance containing all scripts of the table.

Returns:GsubData

the GsubData instance representing the table

getGsubDataback to summary
public GsubData getGsubData(String scriptTag)

Builds a new GsubData instance for given script tag. In contrast to neighbour getGsubData() 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 given scriptTag (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 corresponding org.apache.fontbox.ttf.gsub.GsubWorker implementation for it.

Note

This method performs searching on every invocation (no results are cached)

Parameters
scriptTag:String

a script tag for which the data is needed

Returns:GsubData

GSUB data for the given script or null if no such script in the font

getLangSysTablesback to summary
private Collection<LangSysTable> getLangSysTables(String scriptTag)
getSubstitutionback to summary
public int getSubstitution(int gid, String[] scriptTags, List<String> enabledFeatures)

Apply glyph substitutions to the supplied gid. The applicable substitutions are determined by the scriptTags which indicate the language of the gid, and by the list of enabledFeatures. 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:int

GID

scriptTags:String[]

Script tags applicable to the gid (see OpenTypeScript)

enabledFeatures:List<String>

list of features to apply

Returns:int

the id of the glyph substitution

getSupportedScriptTagsback to summary
public Set<String> getSupportedScriptTags()
Returns:Set<String>

a read-only view of the script tags for which this GSUB table has records

getUnsubstitutionback to summary
public int getUnsubstitution(int sgid)

For a substitute-gid (obtained from getSubstitution(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:int

Substitute GID

Returns:int

the original gid of a substitute-gid

readback to summary
pack-priv void read(TrueTypeFont ttf, TTFDataStream data) throws IOException

Overrides org.apache.fontbox.ttf.TTFTable.read.

Doc from org.apache.fontbox.ttf.TTFTable.read.

This will read the required data from the stream.

Parameters
ttf:TrueTypeFont

The font that is being read.

data:TTFDataStream

The stream to read the data from.

Annotations
@Override
@SuppressWarnings:squid:S1854
Exceptions
IOException:
If there is an error reading the data.
readAlternateSubstitutionSubtableback to summary
private LookupSubTable readAlternateSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
readCoverageTableback to summary
private CoverageTable readCoverageTable(TTFDataStream data, long offset) throws IOException
readFeatureListback to summary
private FeatureListTable readFeatureList(TTFDataStream data, long offset) throws IOException
readFeatureTableback to summary
private FeatureTable readFeatureTable(TTFDataStream data, long offset) throws IOException
readLangSysTableback to summary
private LangSysTable readLangSysTable(TTFDataStream data, long offset) throws IOException
readLigatureSetTableback to summary
private LigatureSetTable readLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId) throws IOException
readLigatureSubstitutionSubtableback to summary
private LookupSubTable readLigatureSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
readLigatureTableback to summary
private LigatureTable readLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId) throws IOException
readLookupListback to summary
private LookupListTable readLookupList(TTFDataStream data, long offset) throws IOException
readLookupSubtableback to summary
private LookupSubTable readLookupSubtable(TTFDataStream data, long offset, int lookupType) throws IOException
readLookupTableback to summary
private LookupTable readLookupTable(TTFDataStream data, long offset) throws IOException
readMultipleSubstitutionSubtableback to summary
private LookupSubTable readMultipleSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
readRangeRecordback to summary
private RangeRecord readRangeRecord(TTFDataStream data) throws IOException
readScriptListback to summary
private Map<String, ScriptTable> readScriptList(TTFDataStream data, long offset) throws IOException
readScriptTableback to summary
private ScriptTable readScriptTable(TTFDataStream data, long offset) throws IOException
readSingleLookupSubTableback to summary
private LookupSubTable readSingleLookupSubTable(TTFDataStream data, long offset) throws IOException
removeFeatureback to summary
private void removeFeature(List<FeatureRecord> featureRecords, String featureTag)
selectScriptTagback to summary
private String selectScriptTag(String[] tags)

Choose from one of the supplied OpenType script tags, depending on what the font supports and potentially on context.

Returns:String

The best OpenType script tag