From 5a40c4dfd11230414a729347f136c1e670b4e9e9 Mon Sep 17 00:00:00 2001 From: Simon Steiner Date: Wed, 27 Mar 2019 13:40:08 +0000 Subject: FOP-2853: Error for SVG using TTF fallback to AFP git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1856399 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/afp/AFPFontConfig.java | 10 +- .../apache/fop/render/afp/AFPTrueTypeTestCase.java | 108 ++++++++++++++------- 2 files changed, 81 insertions(+), 37 deletions(-) diff --git a/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java b/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java index f6a0a2a75..0967bd1f8 100644 --- a/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java +++ b/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java @@ -46,6 +46,8 @@ import org.apache.fop.configuration.Configuration; import org.apache.fop.configuration.ConfigurationException; import org.apache.fop.events.EventProducer; import org.apache.fop.fonts.EmbedFontInfo; +import org.apache.fop.fonts.EmbeddingMode; +import org.apache.fop.fonts.EncodingMode; import org.apache.fop.fonts.FontConfig; import org.apache.fop.fonts.FontManager; import org.apache.fop.fonts.FontManagerConfigurator; @@ -380,10 +382,10 @@ public final class AFPFontConfig implements FontConfig { AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer) throws IOException { try { - Typeface tf = new LazyFont(new EmbedFontInfo( - new FontUris(new URI(fontUri), null) - , false, true, null, subfont), resourceResolver, false).getRealFont(); - + FontUris fontUris = new FontUris(new URI(fontUri), null); + EmbedFontInfo embedFontInfo = new EmbedFontInfo(fontUris, false, true, null, subfont, EncodingMode.AUTO, + EmbeddingMode.FULL, false, false); + Typeface tf = new LazyFont(embedFontInfo, resourceResolver, false).getRealFont(); AFPResourceAccessor accessor = getAccessor(resourceResolver); CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset, super.codePage, super.encoding, tf, accessor, eventProducer); diff --git a/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java b/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java index 0caf83df8..ac3ef803c 100644 --- a/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java @@ -73,18 +73,6 @@ public class AFPTrueTypeTestCase { @Test public void testAFPTrueType() throws IOException, SAXException, TransformerException, URISyntaxException { - String fopxconf = "\n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + " \n" - + ""; String fo = "\n" + " \n" + " \n" @@ -97,26 +85,6 @@ public class AFPTrueTypeTestCase { + " \n" + " \n" + ""; - - FopFactoryBuilder confBuilder = new FopConfParser( - new ByteArrayInputStream(fopxconf.getBytes()), - EnvironmentalProfileFactory.createRestrictedIO(new URI("."), - new MyResourceResolver())).getFopFactoryBuilder(); - FopFactory fopFactory = confBuilder.build(); - FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - Fop fop = fopFactory.newFop("application/x-afp", foUserAgent, bos); - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - Source src = new StreamSource(new ByteArrayInputStream(fo.getBytes())); - Result res = new SAXResult(fop.getDefaultHandler()); - transformer.transform(src, res); - bos.close(); - - StringBuilder sb = new StringBuilder(); - InputStream bis = new ByteArrayInputStream(bos.toByteArray()); - new AFPParser(false).read(bis, sb); - String format = "BEGIN RESOURCE_GROUP RG000001\n" + "BEGIN NAME_RESOURCE RES00001 Triplets: OBJECT_FUNCTION_SET_SPECIFICATION" + ",OBJECT_CLASSIFICATION,0x01,FULLY_QUALIFIED_NAME,\n" @@ -143,10 +111,84 @@ public class AFPTrueTypeTestCase { + "END PAGE_GROUP PGP00001\n" + "END DOCUMENT DOC00001\n"; - Assert.assertEquals(sb.toString(), format); + Assert.assertEquals(getAFP(fo), format); Assert.assertEquals("test/resources/fonts/ttf/DejaVuLGCSerif.ttf", font); } + @Test + public void testSVGAFPTrueType() throws IOException, SAXException, TransformerException, URISyntaxException { + String fo = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " W\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + Assert.assertTrue(getAFP(fo).contains("DATA GRAPHICS")); + } + + private String getAFP(String fo) throws IOException, TransformerException, SAXException, URISyntaxException { + String fopxconf = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + FopFactoryBuilder confBuilder = new FopConfParser( + new ByteArrayInputStream(fopxconf.getBytes()), + EnvironmentalProfileFactory.createRestrictedIO(new URI("."), + new MyResourceResolver())).getFopFactoryBuilder(); + FopFactory fopFactory = confBuilder.build(); + FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + Fop fop = fopFactory.newFop("application/x-afp", foUserAgent, bos); + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + Source src = new StreamSource(new ByteArrayInputStream(fo.getBytes())); + Result res = new SAXResult(fop.getDefaultHandler()); + transformer.transform(src, res); + bos.close(); + + StringBuilder sb = new StringBuilder(); + InputStream bis = new ByteArrayInputStream(bos.toByteArray()); + new AFPParser(false).read(bis, sb); + return sb.toString(); + } + class MyResourceResolver implements ResourceResolver { private ResourceResolver defaultResourceResolver = ResourceResolverFactory.createDefaultResourceResolver(); public Resource getResource(URI uri) throws IOException { -- cgit v1.2.3