Author: ssteiner Date: Mon Jun 29 14:07:16 2020 New Revision: 1879331 URL: http://svn.apache.org/viewvc?rev=1879331&view=rev Log: FOP-2950: Display font error at top level exception
Modified: xmlgraphics/fop-pdf-images/trunk/lib/fop.jar xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java Modified: xmlgraphics/fop-pdf-images/trunk/lib/fop.jar URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/fop.jar?rev=1879331&r1=1879330&r2=1879331&view=diff ============================================================================== Binary files - no diff available. Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java?rev=1879331&r1=1879330&r2=1879331&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java Mon Jun 29 14:07:16 2020 @@ -324,8 +324,9 @@ public class ImageConverterPDF2G2D exten 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; Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java?rev=1879331&r1=1879330&r2=1879331&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java (original) +++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/ImageConverterPDF2G2DTestCase.java Mon Jun 29 14:07:16 2020 @@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream; 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.image.load 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 @@ public class ImageConverterPDF2G2DTestCa @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 @@ public class ImageConverterPDF2G2DTestCa 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 @@ public class ImageConverterPDF2G2DTestCa 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")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org