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 Details

  • Constructor Details

    • GlyphSubstitutionTable

      GlyphSubstitutionTable()
  • Method Details

    • read

      void read(TrueTypeFont ttf, TTFDataStream data) throws IOException
      Description copied from class: TTFTable
      This will read the required data from the stream.
      Overrides:
      read in class TTFTable
      Parameters:
      ttf - The font that is being read.
      data - The stream to read the data from.
      Throws:
      IOException - If there is an error reading the data.
    • readScriptList

      private Map<String,ScriptTable> readScriptList(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readScriptTable

      private ScriptTable readScriptTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readLangSysTable

      private LangSysTable readLangSysTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readFeatureList

      private FeatureListTable readFeatureList(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readFeatureTable

      private FeatureTable readFeatureTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readLookupList

      private LookupListTable readLookupList(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readLookupSubtable

      private LookupSubTable readLookupSubtable(TTFDataStream data, long offset, int lookupType) throws IOException
      Throws:
      IOException
    • readLookupTable

      private LookupTable readLookupTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readSingleLookupSubTable

      private LookupSubTable readSingleLookupSubTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readMultipleSubstitutionSubtable

      private LookupSubTable readMultipleSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readAlternateSubstitutionSubtable

      private LookupSubTable readAlternateSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readLigatureSubstitutionSubtable

      private LookupSubTable readLigatureSubstitutionSubtable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • readLigatureSetTable

      private LigatureSetTable readLigatureSetTable(TTFDataStream data, long ligatureSetTableLocation, int coverageGlyphId) throws IOException
      Throws:
      IOException
    • readLigatureTable

      private LigatureTable readLigatureTable(TTFDataStream data, long ligatureTableLocation, int coverageGlyphId) throws IOException
      Throws:
      IOException
    • readCoverageTable

      private CoverageTable readCoverageTable(TTFDataStream data, long offset) throws IOException
      Throws:
      IOException
    • selectScriptTag

      private String selectScriptTag(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 Collection<LangSysTable> getLangSysTables(String scriptTag)
    • getFeatureRecords

      private List<FeatureRecord> getFeatureRecords(Collection<LangSysTable> langSysTables, 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 - The LangSysTables indicating FeatureRecords to search for
      enabledFeatures - An optional list of feature tags (null to allow all)
      Returns:
      The indicated FeatureRecords
    • containsFeature

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

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

      private int applyFeature(FeatureRecord featureRecord, int gid)
    • doLookup

      private int doLookup(LookupTable lookupTable, int gid)
    • getSubstitution

      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 - GID
      scriptTags - Script tags applicable to the gid (see OpenTypeScript)
      enabledFeatures - list of features to apply
      Returns:
      the id of the glyph substitution
    • getUnsubstitution

      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 - 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(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 GsubWorker implementation 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 null if no such script in the font
    • getSupportedScriptTags

      public Set<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 IOException
      Throws:
      IOException