You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/17 16:24:38 UTC

svn commit: r1824605 - /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java

Author: tilman
Date: Sat Feb 17 16:24:38 2018
New Revision: 1824605

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

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

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java?rev=1824605&r1=1824604&r2=1824605&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/GlyphSubstitutionTable.java Sat Feb 17 16:24:38 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<>();
         for (LangSysTable langSysTable : langSysTables)
         {
@@ -476,6 +480,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)
@@ -490,16 +507,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)
         {
@@ -510,6 +520,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);