]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2742: SVG to PS NPE/text missing when using PFM file
authorSimon Steiner <ssteiner@apache.org>
Tue, 26 Sep 2017 14:22:51 +0000 (14:22 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 26 Sep 2017 14:22:51 +0000 (14:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1809748 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java
fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java [new file with mode: 0644]

index bd96d80c5f34d22e1d9e29f3b2280fb6ae24754c..c567506d8a5a84da66bf2c5f68454e4856a788db 100644 (file)
@@ -19,6 +19,7 @@
 
 package org.apache.fop.fonts.type1;
 
+import java.awt.Rectangle;
 import java.awt.geom.RectangularShape;
 import java.io.IOException;
 import java.io.InputStream;
@@ -415,7 +416,10 @@ public class Type1FontLoader extends FontLoader {
             returnFont.setFirstChar(pfm.getFirstChar());
             returnFont.setLastChar(pfm.getLastChar());
             for (short i = pfm.getFirstChar(); i <= pfm.getLastChar(); i++) {
-                singleFont.setWidth(i, pfm.getCharWidth(i));
+                int cw = pfm.getCharWidth(i);
+                singleFont.setWidth(i, cw);
+                int[] bbox = pfm.getFontBBox();
+                singleFont.setBoundingBox(i, new Rectangle(bbox[0], bbox[1], cw, bbox[3]));
             }
             if (useKerning) {
                 returnFont.replaceKerningMap(pfm.getKerning());
diff --git a/fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java b/fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java
new file mode 100644 (file)
index 0000000..84b0b1a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.fonts.type1;
+
+import java.awt.Rectangle;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.commons.io.IOUtils;
+
+import org.apache.fop.apps.io.ResourceResolverFactory;
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.EmbeddingMode;
+import org.apache.fop.fonts.EncodingMode;
+import org.apache.fop.fonts.FontLoader;
+import org.apache.fop.fonts.FontUris;
+
+public class Type1FontLoaderTestCase {
+    @Test
+    public void testBoundingBox() throws IOException {
+        File pfb = new File("test/resources/fonts/type1/c0419bt_.pfb");
+        File pfbNoAFM = File.createTempFile("fop", "pfb");
+        File pfm = File.createTempFile("fop", "pfm");
+        try {
+            IOUtils.copy(new FileInputStream(pfb), new FileOutputStream(pfbNoAFM));
+
+            FileOutputStream fos = new FileOutputStream(pfm);
+            fos.write(new byte[512]);
+            fos.close();
+
+            FontUris fontUris = new FontUris(pfbNoAFM.toURI(), null, null, pfm.toURI());
+            CustomFont x = FontLoader.loadFont(fontUris, null, true, EmbeddingMode.AUTO, EncodingMode.AUTO, true, true,
+                    ResourceResolverFactory.createDefaultInternalResourceResolver(new File(".").toURI()), false, false);
+            Assert.assertEquals(x.getBoundingBox(0, 12).getBounds(), new Rectangle(-240, -60, 0, 60));
+        } finally {
+            pfbNoAFM.delete();
+            pfm.delete();
+        }
+    }
+}