pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1824353 - in /pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf: SubstitutingCmapLookup.java TrueTypeFont.java
Date Thu, 15 Feb 2018 20:07:49 GMT
Author: tilman
Date: Thu Feb 15 20:07:48 2018
New Revision: 1824353

URL: http://svn.apache.org/viewvc?rev=1824353&view=rev
Log:
PDFBOX-4106: implement GSUB substitution, by Aaron Madlon-Kay

Added:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java
  (with props)
Modified:
    pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java

Added: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java?rev=1824353&view=auto
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java
(added)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java
Thu Feb 15 20:07:48 2018
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.fontbox.ttf;
+
+import java.util.List;
+
+/**
+ * A cmap lookup that performs substitution via the 'GSUB' table.
+ *
+ * @author Aaron Madlon-Kay
+ */
+public class SubstitutingCmapLookup implements CmapLookup
+{
+    private final CmapSubtable cmap;
+    private final GlyphSubstitutionTable gsub;
+    private final List<String> enabledFeatures;
+
+    public SubstitutingCmapLookup(CmapSubtable cmap, GlyphSubstitutionTable gsub,
+            List<String> enabledFeatures)
+    {
+        this.cmap = cmap;
+        this.gsub = gsub;
+        this.enabledFeatures = enabledFeatures;
+    }
+
+    @Override
+    public int getGlyphId(int characterCode)
+    {
+        int gid = cmap.getGlyphId(characterCode);
+        String[] scriptTags = OpenTypeScript.getScriptTags(characterCode);
+        return gsub.getSubstitution(gid, scriptTags, enabledFeatures);
+    }
+
+    @Override
+    public List<Integer> getCharCodes(int gid)
+    {
+        return cmap.getCharCodes(gsub.getUnsubstitution(gid));
+    }
+}

Propchange: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/SubstitutingCmapLookup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java?rev=1824353&r1=1824352&r2=1824353&view=diff
==============================================================================
--- pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java (original)
+++ pdfbox/trunk/fontbox/src/main/java/org/apache/fontbox/ttf/TrueTypeFont.java Thu Feb 15
20:07:48 2018
@@ -20,8 +20,10 @@ import java.awt.geom.GeneralPath;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,6 +46,7 @@ public class TrueTypeFont implements Fon
     
     private final Object lockReadtable = new Object();
     private final Object lockPSNames = new Object();
+    private final List<String> enabledGsubFeatures = new ArrayList<>();
 
     /**
      * Constructor.  Clients should use the TTFParser to create a new TrueTypeFont object.
@@ -551,6 +554,15 @@ public class TrueTypeFont implements Fon
     public CmapLookup getUnicodeCmapLookup(boolean isStrict) throws IOException
     {
         CmapSubtable cmap = getUnicodeCmapImpl(isStrict);
+        if (!enabledGsubFeatures.isEmpty())
+        {
+            GlyphSubstitutionTable table = getGsub();
+            if (table != null)
+            {
+                return new SubstitutingCmapLookup(cmap, (GlyphSubstitutionTable) table,
+                        Collections.unmodifiableList(enabledGsubFeatures));
+            }
+        }
         return cmap;
     }
 
@@ -719,6 +731,27 @@ public class TrueTypeFont implements Fon
         return Arrays.<Number>asList(0.001f * scale, 0, 0, 0.001f * scale, 0, 0);
     }
 
+    /**
+     * Enable a particular glyph substitution feature. This feature might not be supported
by the
+     * font, or might not be implemented in PDFBox yet.
+     *
+     * @param featureTag The GSUB feature to enable
+     */
+    public void enableGsubFeature(String featureTag)
+    {
+        enabledGsubFeatures.add(featureTag);
+    }
+
+    /**
+     * Disable a particular glyph substitution feature.
+     *
+     * @param featureTag The GSUB feature to disable
+     */
+    public void disableGsubFeature(String featureTag)
+    {
+        enabledGsubFeatures.remove(featureTag);
+    }
+
     @Override
     public String toString()
     {



Mime
View raw message