FOP-2950: Display font error at top level exception
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop-pdf-images/trunk@1879331 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/fop.jar b/lib/fop.jar
index 844011d..72fdcad 100644
--- a/lib/fop.jar
+++ b/lib/fop.jar
Binary files differ
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java b/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
index b8bb249..1f4255f 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
@@ -324,8 +324,9 @@
private CustomFont getFont(String name) throws IOException {
Object typeface = fonts.get(name);
if (typeface instanceof LazyFont) {
- Typeface rf = ((LazyFont) typeface).getRealFont();
- return (CustomFont) rf;
+ ((LazyFont) typeface).getEncodingName(); //used so exception raised on error
+ Typeface realFont = ((LazyFont) typeface).getRealFont();
+ return (CustomFont) realFont;
} else if (typeface instanceof CustomFontMetricsMapper) {
Typeface rf = ((CustomFontMetricsMapper) typeface).getRealFont();
return (CustomFont) rf;
diff --git a/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java b/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java
index f2d833a..707337f 100644
--- a/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.net.URI;
import org.junit.Assert;
import org.junit.Test;
@@ -42,6 +43,8 @@
import org.apache.xmlgraphics.java2d.GeneralGraphics2DImagePainter;
import org.apache.xmlgraphics.java2d.GraphicContext;
+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.EmbeddingMode;
import org.apache.fop.fonts.FontUris;
@@ -58,10 +61,7 @@
@Test
public void testFontsNotEmbedded() throws IOException, ImageException {
- Assert.assertTrue(pdfToPS(FONTSNOTEMBEDDED, "Helvetica-Bold"));
Assert.assertFalse(pdfToPS(FONTSNOTEMBEDDED, "xyz"));
-
- Assert.assertTrue(pdfToPS(FONTSNOTEMBEDDEDCID, "NewsMinIWA-Th"));
Assert.assertFalse(pdfToPS(FONTSNOTEMBEDDEDCID, "xyz"));
}
@@ -72,7 +72,12 @@
return lazyFont.font.fontUsed;
}
- private String pdfToPS(PDDocument doc, String pdf, String font, MyLazyFont lazyFont)
+ private void pdfToPS(String pdf, LazyFont lazyFont) throws IOException, ImageException {
+ PDDocument doc = PDDocument.load(new File(pdf));
+ pdfToPS(doc, pdf, "NewsMinIWA-Th", lazyFont);
+ }
+
+ private String pdfToPS(PDDocument doc, String pdf, String font, LazyFont lazyFont)
throws IOException, ImageException {
ImageConverterPDF2G2D i = new ImageConverterPDF2G2D();
ImageInfo imgi = new ImageInfo(pdf, "b");
@@ -145,4 +150,18 @@
String ps = pdfToPS(doc, pdf, null, null);
Assert.assertTrue(ps.contains("/ImageType 1"));
}
+
+ @Test
+ public void testPDFToPSFontError() throws Exception {
+ String msg = "";
+ InternalResourceResolver rr = ResourceResolverFactory.createDefaultInternalResourceResolver(new URI("."));
+ EmbedFontInfo embedFontInfo = new EmbedFontInfo(new FontUris(
+ new File("pom.xml").toURI(), null), false, false, null, "");
+ try {
+ pdfToPS(FONTSNOTEMBEDDEDCID, new LazyFont(embedFontInfo, rr, false));
+ } catch (Exception e) {
+ msg = e.getMessage();
+ }
+ Assert.assertTrue(msg, msg.contains("Reached EOF"));
+ }
}