aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2017-09-26 14:22:51 +0000
committerSimon Steiner <ssteiner@apache.org>2017-09-26 14:22:51 +0000
commit991b446034726979e931c3033ace13344b153a30 (patch)
tree0f46c991db540387675181b546d07b72c79668d2 /fop-core
parent10e0d1c238b40735c51c1bf841fe7bf4f6418dda (diff)
downloadxmlgraphics-fop-991b446034726979e931c3033ace13344b153a30.tar.gz
xmlgraphics-fop-991b446034726979e931c3033ace13344b153a30.zip
FOP-2742: SVG to PS NPE/text missing when using PFM file
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1809748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java6
-rw-r--r--fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java61
2 files changed, 66 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java
index bd96d80c5..c567506d8 100644
--- a/fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java
+++ b/fop-core/src/main/java/org/apache/fop/fonts/type1/Type1FontLoader.java
@@ -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
index 000000000..84b0b1ab1
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/fonts/type1/Type1FontLoaderTestCase.java
@@ -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();
+ }
+ }
+}