svn commit: r1781856 - in /xmlgraphics/fop/trunk/fop-core/src: main/java/org/apache/fop/fonts/FontLoader.java main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java

[email protected]
Newsgroups gmane.text.xml.fop.cvs
Message-ID <[email protected]>
Author: ssteiner
Date: Mon Feb  6 09:50:05 2017
New Revision: 1781856

URL: http://svn.apache.org/viewvc?rev=1781856&view=rev
Log:
FOP-2686: Error for Type1 font without extension for TIFF output

Added:
    xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java   (with props)
Modified:
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java
    xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java?rev=1781856&r1=1781855&r2=1781856&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/fonts/FontLoader.java Mon Feb  6 09:50:05 2017
@@ -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) {

Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java?rev=1781856&r1=1781855&r2=1781856&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java Mon Feb  6 09:50:05 2017
@@ -73,7 +73,7 @@ public class ConfiguredFontCollection im
             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 im
                     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(),

Added: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java?rev=1781856&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java (added)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java Mon Feb  6 09:50:05 2017
@@ -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;
+    }
+}

Propchange: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/java2d/ConfiguredFontCollectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.