Class GlyphSubstitutionTable


  • public class GlyphSubstitutionTable
    extends TTFTable
    A glyph substitution 'GSUB' table in a TrueType or OpenType font.
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • scriptList

        private java.util.Map<java.lang.String,​ScriptTable> scriptList
      • 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
      • WORDPATTERN

        private static final java.util.regex.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

      • GlyphSubstitutionTable

        GlyphSubstitutionTable()
    • 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.
        Overrides:
        read in class TTFTable
        Parameters:
        ttf - The font that is being read.
        data - The stream to read the data from.
        Throws:
        java.io.IOException - If there is an error reading the data.
      • 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 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​(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 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​(java.lang.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 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