Author: ssteiner Date: Wed Mar 27 13:40:08 2019 New Revision: 1856399 URL: http://svn.apache.org/viewvc?rev=1856399&view=rev Log: FOP-2853: Error for SVG using TTF fallback to AFP
Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java Modified: xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java?rev=1856399&r1=1856398&r2=1856399&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/main/java/org/apache/fop/render/afp/AFPFontConfig.java Wed Mar 27 13:40:08 2019 @@ -46,6 +46,8 @@ import org.apache.fop.configuration.Conf 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 impleme 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); Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java?rev=1856399&r1=1856398&r2=1856399&view=diff ============================================================================== --- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java (original) +++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java Wed Mar 27 13:40:08 2019 @@ -73,18 +73,6 @@ public class AFPTrueTypeTestCase { @Test public void testAFPTrueType() throws IOException, SAXException, TransformerException, URISyntaxException { - String fopxconf = "<fop version=\"1.0\">\n" - + " <renderers>\n" - + " <renderer mime=\"application/x-afp\">\n" - + " <fonts>\n" - + " <font name=\"Univers\" embed-url=\"test/resources/fonts/ttf/DejaVuLGCSerif.ttf\">\n" - + " <font-triplet name=\"Univers\" style=\"normal\" weight=\"normal\"/>\n" - + " <font-triplet name=\"any\" style=\"normal\" weight=\"normal\"/>\n" - + " </font>\n" - + " </fonts>\n" - + " </renderer>\n" - + " </renderers>\n" - + "</fop>"; String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n" + " <fo:layout-master-set>\n" + " <fo:simple-page-master master-name=\"simple\">\n" @@ -97,26 +85,6 @@ public class AFPTrueTypeTestCase { + " </fo:flow>\n" + " </fo:page-sequence>\n" + "</fo:root>"; - - 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 = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" " + + "xmlns:fox=\"http://xmlgraphics.apache.org/fop/extensions\" " + + "xmlns:svg=\"http://www.w3.org/2000/svg\">\n" + + " <fo:layout-master-set>\n" + + " <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n" + + " <fo:region-body />\n" + + " </fo:simple-page-master>\n" + + " </fo:layout-master-set>\n" + + " <fo:page-sequence master-reference=\"simple\">\n" + + " <fo:flow flow-name=\"xsl-region-body\"> \n" + + " <fo:block font-size=\"0\">\n" + + " <fo:instream-foreign-object content-height=\"792pt\" content-width=\"612pt\">\n" + + " <svg:svg viewBox=\"0 0 816 1056\" height=\"1056\" width=\"816\" id=\"svg2\" " + + "version=\"1.1\">\n" + + " <svg:g transform=\"matrix(1.3333333,0,0,-1.3333333,0,1056)\" id=\"g10\">\n" + + " <svg:g id=\"g12\">\n" + + " <svg:g id=\"g14\">\n" + + " <svg:g transform=\"translate(36,18)\" id=\"g40\">\n" + + " <svg:text id=\"text44\" style=\"font-variant:normal;font-weight:normal;" + + "font-size:9px;font-family:Univers;-inkscape-font-specification:ArialMT;writing-mode:lr-tb;" + + "fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none\" " + + "transform=\"matrix(1,0,0,-1,44.92,11.4)\">\n" + + " <svg:tspan id=\"tspan42\" y=\"0\" x=\"0.0\">W</svg:tspan>\n" + + " </svg:text>\n" + + " </svg:g>\n" + + " <svg:g id=\"g2672\"/>\n" + + " </svg:g>\n" + + " </svg:g>\n" + + " </svg:g>\n" + + " </svg:svg>\n" + + " </fo:instream-foreign-object>\n" + + " </fo:block>\n" + + " </fo:flow>\n" + + " </fo:page-sequence>\n" + + "</fo:root>"; + Assert.assertTrue(getAFP(fo).contains("DATA GRAPHICS")); + } + + private String getAFP(String fo) throws IOException, TransformerException, SAXException, URISyntaxException { + String fopxconf = "<fop version=\"1.0\">\n" + + " <renderers>\n" + + " <renderer mime=\"application/x-afp\">\n" + + " <fonts>\n" + + " <font name=\"Univers\" embed-url=\"test/resources/fonts/ttf/DejaVuLGCSerif.ttf\">\n" + + " <font-triplet name=\"Univers\" style=\"normal\" weight=\"normal\"/>\n" + + " <font-triplet name=\"any\" style=\"normal\" weight=\"normal\"/>\n" + + " </font>\n" + + " </fonts>\n" + + " </renderer>\n" + + " </renderers>\n" + + "</fop>"; + 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 { --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org