]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2686: Error for Type1 font without extension for TIFF output
authorSimon Steiner <ssteiner@apache.org>
Mon, 6 Feb 2017 09:50:05 +0000 (09:50 +0000)
committerSimon Steiner <ssteiner@apache.org>
Mon, 6 Feb 2017 09:50:05 +0000 (09:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1781856 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java
fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java [new file with mode: 0644]

index 9c11db2e01908c955135a8a8d00a01fc5780ddcd..06907f4035526f5014410b3c8a04228b46316c42 100644 (file)
@@ -71,13 +71,14 @@ public abstract class FontLoader {
         this.resourceResolver = resourceResolver;
     }
 
-    private static boolean isType1(URI fontURI) {
-        return fontURI.toASCIIString().toLowerCase().endsWith(".pfb");
+    private static boolean isType1(FontUris fontUris) {
+        return fontUris.getEmbed().toASCIIString().toLowerCase().endsWith(".pfb") || fontUris.getAfm() != null
+            || fontUris.getPfm() != null;
     }
 
     /**
      * Loads a custom font from a URI. In the case of Type 1 fonts, the PFB file must be specified.
-     * @param fontFileURI the URI to the font
+     * @param fontUris the URI to the font
      * @param subFontName the sub-fontname of a font (for TrueType Collections, null otherwise)
      * @param embedded indicates whether the font is embedded or referenced
      * @param embeddingMode the embedding mode of the font
@@ -93,7 +94,7 @@ public abstract class FontLoader {
             boolean embedded, EmbeddingMode embeddingMode, EncodingMode encodingMode,
             boolean useKerning, boolean useAdvanced, InternalResourceResolver resourceResolver,
             boolean simulateStyle, boolean embedAsType1) throws IOException {
-        boolean type1 = isType1(fontUris.getEmbed());
+        boolean type1 = isType1(fontUris);
         FontLoader loader;
         if (type1) {
             if (encodingMode == EncodingMode.CID) {
index 4ad2044cb324f834ce45304efd6253b5b3db61e7..e494ed65cc81f3ebf4d6728796e9ddb00a077bf3 100644 (file)
@@ -73,7 +73,7 @@ public class ConfiguredFontCollection implements FontCollection {
             internalName = "F" + num++;
             try {
                 URI fontURI = configFontInfo.getEmbedURI();
-                FontMetricsMapper font = null;
+                FontMetricsMapper font;
                 URI metricsURI = configFontInfo.getMetricsURI();
                 // If the user specified an XML-based metrics file, we'll use it
                 // Otherwise, calculate metrics directly from the font file.
@@ -82,7 +82,7 @@ public class ConfiguredFontCollection implements FontCollection {
                     InputStream fontSource = resourceResolver.getResource(fontURI);
                     font = new CustomFontMetricsMapper(fontMetrics, fontSource);
                 } else {
-                    FontUris fontUris = new FontUris(fontURI, null);
+                    FontUris fontUris = configFontInfo.getFontUris();
                     CustomFont fontMetrics = FontLoader.loadFont(fontUris,
                             configFontInfo.getSubFontName(), true,
                             configFontInfo.getEmbeddingMode(), configFontInfo.getEncodingMode(),
diff --git a/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java b/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java
new file mode 100644 (file)
index 0000000..7e2f8d4
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+/* $Id$ */
+package org.apache.fop.render.java2d;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.apps.io.InternalResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
+import org.apache.fop.fonts.EmbedFontInfo;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontTriplet;
+import org.apache.fop.fonts.FontUris;
+
+public class ConfiguredFontCollectionTestCase {
+    @Test
+    public void testConfiguredFontCollection() throws IOException {
+        File pfb = getFontFileNoExension("test/resources/fonts/type1/c0419bt_.pfb");
+        File afm = getFontFileNoExension("test/resources/fonts/type1/c0419bt_.afm");
+        Assert.assertFalse(pfb.getName().endsWith(".pfb"));
+        try {
+            FontUris fontUris = new FontUris(pfb.toURI(), null, afm.toURI(), null);
+            EmbedFontInfo e = new EmbedFontInfo(fontUris, true, true, new ArrayList<FontTriplet>(), null);
+            List<EmbedFontInfo> x = Collections.singletonList(e);
+            InternalResourceResolver rr =
+                    ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI());
+            ConfiguredFontCollection c = new ConfiguredFontCollection(rr, x, true);
+            FontInfo fi = new FontInfo();
+            int num = c.setup(0, fi);
+            Assert.assertEquals(num, 1);
+            Assert.assertEquals(fi.getFonts().values().iterator().next().getFontName(), "Courier10PitchBT-Roman");
+        } finally {
+            pfb.delete();
+            afm.delete();
+        }
+    }
+
+    private File getFontFileNoExension(String s) throws IOException {
+        FileInputStream pfb = new FileInputStream(s);
+        File tmp = File.createTempFile("fop", "font");
+        FileOutputStream os = new FileOutputStream(tmp);
+        IOUtils.copy(pfb, os);
+        os.close();
+        pfb.close();
+        return tmp;
+    }
+}