Author: tilman
Date: Sat Feb 17 16:25:03 2018
New Revision: 1824606

URL: http://svn.apache.org/viewvc?rev=1824606&view=rev
Log:
PDFBOX-4106: Remove early outs leading to spurious warnings + add javadoc, by 
Aaron Madlon-Kay

Modified:
    
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java

Modified: 
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
URL: 
http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java?rev=1824606&r1=1824605&r2=1824606&view=diff
==============================================================================
--- 
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
 (original)
+++ 
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
 Sat Feb 17 16:25:03 2018
@@ -382,6 +382,10 @@ public class GlyphSubstitutionTable exte
     private List<FeatureRecord> getFeatureRecords(Collection<LangSysTable> 
langSysTables,
             final List<String> enabledFeatures)
     {
+        if (langSysTables.isEmpty())
+        {
+            return Collections.emptyList();
+        }
         List<FeatureRecord> result = new ArrayList<FeatureRecord>();
         for (LangSysTable langSysTable : langSysTables)
         {
@@ -477,6 +481,19 @@ public class GlyphSubstitutionTable exte
         return gid;
     }
 
+    /**
+     * Apply glyph substitutions to the supplied gid. The applicable 
substitutions are determined by
+     * the {@code scriptTags} which indicate the language of the gid, and by 
the
+     * {@code enabledFeatures} which acts as a whitelist.
+     *
+     * 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.
+     *
+     * @param gid GID
+     * @param scriptTags Script tags applicable to the gid (see {@link 
OpenTypeScript})
+     * @param enabledFeatures Whitelist of features to apply
+     */
     public int getSubstitution(int gid, String[] scriptTags, List<String> 
enabledFeatures)
     {
         if (gid == -1)
@@ -491,16 +508,9 @@ public class GlyphSubstitutionTable exte
             // as we need a one-to-one mapping.
             return cached;
         }
-        Collection<LangSysTable> langSysTables = 
getLangSysTables(selectScriptTag(scriptTags));
-        if (langSysTables.isEmpty())
-        {
-            return gid;
-        }
+        String scriptTag = selectScriptTag(scriptTags);
+        Collection<LangSysTable> langSysTables = getLangSysTables(scriptTag);
         List<FeatureRecord> featureRecords = getFeatureRecords(langSysTables, 
enabledFeatures);
-        if (featureRecords.isEmpty())
-        {
-            return gid;
-        }
         int sgid = gid;
         for (FeatureRecord featureRecord : featureRecords)
         {
@@ -511,6 +521,15 @@ public class GlyphSubstitutionTable exte
         return sgid;
     }
 
+    /**
+     * For a substitute-gid (obtained from {@link #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.
+     *
+     * @param sgid Substitute GID
+     */
     public int getUnsubstitution(int sgid)
     {
         Integer gid = reverseLookup.get(sgid);


Reply via email to