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 2020/05/12 06:47:32 UTC

svn commit: r1877628 - in /pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: FileSystemFontProvider.java FontMapperImpl.java

Author: tilman
Date: Tue May 12 06:47:32 2020
New Revision: 1877628

URL: http://svn.apache.org/viewvc?rev=1877628&view=rev
Log:
PDFBOX-4824: get OpenTypeFont from collection + add debug logging

Modified:
    pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
    pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1877628&r1=1877627&r2=1877628&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Tue May 12 06:47:32 2020
@@ -229,7 +229,21 @@ final class FileSystemFontProvider exten
         {
             try
             {
-                // todo JH: we don't yet support loading CFF fonts from OTC collections

+                if (file.getName().toLowerCase().endsWith(".ttc"))
+                {
+                    @SuppressWarnings("squid:S2095")
+                    // ttc not closed here because it is needed later when ttf is accessed,
+                    // e.g. rendering PDF with non-embedded font which is in ttc file in our font directory
+                    TrueTypeCollection ttc = new TrueTypeCollection(file);
+                    TrueTypeFont ttf = ttc.getFontByName(postScriptName);
+                    if (ttf == null)
+                    {
+                        ttc.close();
+                        throw new IOException("Font " + postScriptName + " not found in " + file);
+                    }
+                    return (OpenTypeFont) ttf;
+                }
+
                 OTFParser parser = new OTFParser(false, true);
                 OpenTypeFont otf = parser.parse(file);
 

Modified: pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java?rev=1877628&r1=1877627&r2=1877628&view=diff
==============================================================================
--- pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java (original)
+++ pdfbox/branches/issue45/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FontMapperImpl.java Tue May 12 06:47:32 2020
@@ -28,6 +28,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.PriorityQueue;
 import java.util.Set;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.FontBoxFont;
 import org.apache.fontbox.ttf.OpenTypeFont;
 import org.apache.fontbox.ttf.TTFParser;
@@ -41,6 +43,8 @@ import org.apache.fontbox.type1.Type1Fon
  */
 final class FontMapperImpl implements FontMapper
 {
+    private static final Log LOG = LogFactory.getLog(FontMapperImpl.class);
+
     private static final FontCache fontCache = new FontCache(); // todo: static cache isn't ideal
     private FontProvider fontProvider;
     private Map<String, FontInfo> fontInfoByName;
@@ -467,6 +471,10 @@ final class FontMapperImpl implements Fo
         FontInfo info = fontInfoByName.get(postScriptName);
         if (info != null && info.getFormat() == format)
         {
+            if (LOG.isDebugEnabled())
+            {
+                LOG.debug(String.format("getFont('%s','%s') returns %s", format, postScriptName, info));
+            }
             return info;
         }
         return null;
@@ -513,6 +521,10 @@ final class FontMapperImpl implements Fo
                 FontMatch bestMatch = queue.poll();
                 if (bestMatch != null)
                 {
+                    if (LOG.isDebugEnabled())
+                    {
+                        LOG.debug("Best match for '" + baseFont + "': " + bestMatch.info);
+                    }
                     FontBoxFont font = bestMatch.info.getFont();
                     if (font instanceof OpenTypeFont)
                     {