]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2552: TrueType in AFP adding extra slash to end of font uri
authorSimon Steiner <ssteiner@apache.org>
Wed, 16 Dec 2015 13:46:42 +0000 (13:46 +0000)
committerSimon Steiner <ssteiner@apache.org>
Wed, 16 Dec 2015 13:46:42 +0000 (13:46 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1720357 13f79535-47bb-0310-9956-ffa450edef68

src/foschema/fop-configuration.xsd
src/java/org/apache/fop/afp/AFPResourceManager.java
src/java/org/apache/fop/render/afp/AFPFontConfig.java
test/java/org/apache/fop/render/afp/AFPTrueTypeTestCase.java

index d3c0b3885b49a49fba20a788d4c8ecd7587b4655..bd1c20d08484f8bbe1d027e75dec5b17f04d08ee 100644 (file)
     <xsd:attribute name="embed-url-afm" type="xsd:anyURI" use="optional"/>
     <xsd:attribute name="embed-url-pfm" type="xsd:anyURI" use="optional"/>
     <xsd:attribute name="sub-font" type="xsd:string" use="optional"/>
+    <xsd:attribute name="name" type="xsd:string" use="optional"/>
     <xsd:attribute name="embedding-mode" use="optional">
       <xsd:simpleType>
         <xsd:restriction base="xsd:string">
index d4df8daab243fb5ecd006324cda054a9645ee111..f5910d7d95b57fa6b3c49756bb0a3626a95203bb 100644 (file)
@@ -338,7 +338,8 @@ public class AFPResourceManager {
                 AFPResourceAccessor accessor = charSet.getResourceAccessor();
                 if (afpFont.getFontType() == FontType.TRUETYPE) {
 
-                    createIncludedResource(afpFont.getFontName(), accessor.resolveURI("."), accessor,
+                    createIncludedResource(afpFont.getFontName(),
+                            ((AFPFontConfig.AFPTrueTypeFont) afpFont).getUri(), accessor,
                             ResourceObject.TYPE_OBJECT_CONTAINER, true,
                             ((AFPFontConfig.AFPTrueTypeFont) afpFont).getTTC());
                 } else {
@@ -414,12 +415,7 @@ public class AFPResourceManager {
                 ActiveEnvironmentGroup.setupTruetypeMDR(res, false);
 
                 ObjectContainer oc = factory.createObjectContainer();
-                InputStream is;
-                try {
-                    is = accessor.createInputStream(new URI("."));
-                } catch (URISyntaxException e) {
-                    throw new IOException(e);
-                }
+                InputStream is = accessor.createInputStream(uri);
 
                 if (ttc != null) {
                     oc.setData(extractTTC(ttc, is));
index 341123331065c03b1c77568fd66a33fb39ff3669..35b2cc3f55d8ff92bf570ce6542b5c76fe1862e9 100644 (file)
@@ -364,41 +364,45 @@ public final class AFPFontConfig implements FontConfig {
     static final class TrueTypeFontConfig extends AFPFontConfigData {
         private String characterset;
         private String subfont;
+        private String fontUri;
 
         private TrueTypeFontConfig(List<FontTriplet> triplets, String type, String codePage,
                                    String encoding, String characterset, String name, String subfont,
                                    boolean embeddable, String uri) {
-            super(triplets, type, codePage, encoding, name, embeddable, uri);
+            super(triplets, type, codePage, encoding, name, embeddable, null);
             this.characterset = characterset;
             this.subfont = subfont;
+            this.fontUri = uri;
         }
 
         @Override
         AFPFontInfo getFontInfo(InternalResourceResolver resourceResolver, AFPEventProducer eventProducer)
                 throws IOException {
-            Typeface tf;
             try {
-                tf = new LazyFont(new EmbedFontInfo(
-                        new FontUris(new URI(uri), null)
+                Typeface tf = new LazyFont(new EmbedFontInfo(
+                        new FontUris(new URI(fontUri), null)
                         , false, true, null, subfont), resourceResolver, false).getRealFont();
+
+                AFPResourceAccessor accessor = getAccessor(resourceResolver);
+                CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset,
+                        super.codePage, super.encoding, tf, accessor, eventProducer);
+                OutlineFont font = new AFPTrueTypeFont(super.name, super.embeddable, characterSet,
+                            eventProducer, subfont, new URI(fontUri));
+                return getFontInfo(font, this);
             } catch (URISyntaxException e) {
                 throw new IOException(e);
             }
-            AFPResourceAccessor accessor = getAccessor(resourceResolver);
-            CharacterSet characterSet = CharacterSetBuilder.getDoubleByteInstance().build(characterset, super.codePage,
-                    super.encoding, tf, accessor, eventProducer);
-            OutlineFont font = new AFPTrueTypeFont(super.name, super.embeddable, characterSet,
-                    eventProducer, subfont);
-            return getFontInfo(font, this);
         }
     }
 
     public static class AFPTrueTypeFont extends OutlineFont {
         private String ttc;
+        private URI uri;
         public AFPTrueTypeFont(String name, boolean embeddable, CharacterSet charSet, AFPEventProducer eventProducer,
-                               String ttc) {
+                               String ttc, URI uri) {
             super(name, embeddable, charSet, eventProducer);
             this.ttc = ttc;
+            this.uri = uri;
         }
 
         public FontType getFontType() {
@@ -408,6 +412,10 @@ public final class AFPFontConfig implements FontConfig {
         public String getTTC() {
             return ttc;
         }
+
+        public URI getUri() {
+            return uri;
+        }
     }
 
     static final class OutlineFontConfig extends AFPFontConfigData {
index 6e6bbfe94c10d97511cc85e1f0b6bd787cd97c9b..333a2398319798d635420589ec0d8957e3c53f54 100644 (file)
@@ -24,6 +24,9 @@ import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
@@ -40,17 +43,22 @@ import org.xml.sax.SAXException;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import org.apache.xmlgraphics.io.Resource;
+import org.apache.xmlgraphics.io.ResourceResolver;
+
 import org.apache.fop.afp.AFPPaintingState;
 import org.apache.fop.afp.AFPResourceManager;
 import org.apache.fop.afp.DataStream;
 import org.apache.fop.afp.Factory;
 import org.apache.fop.afp.fonts.FopCharacterSet;
 import org.apache.fop.afp.modca.PageObject;
+import org.apache.fop.apps.EnvironmentalProfileFactory;
 import org.apache.fop.apps.FOUserAgent;
 import org.apache.fop.apps.Fop;
 import org.apache.fop.apps.FopConfParser;
 import org.apache.fop.apps.FopFactory;
 import org.apache.fop.apps.FopFactoryBuilder;
+import org.apache.fop.apps.io.ResourceResolverFactory;
 import org.apache.fop.fonts.EmbeddingMode;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
@@ -60,8 +68,10 @@ import org.apache.fop.render.intermediate.IFException;
 import junit.framework.Assert;
 
 public class AFPTrueTypeTestCase {
+    private String font;
+
     @Test
-    public void testAFPTrueType() throws IOException, SAXException, TransformerException {
+    public void testAFPTrueType() throws IOException, SAXException, TransformerException, URISyntaxException {
         String fopxconf = "<fop version=\"1.0\">\n"
                 + "  <renderers>\n"
                 + "    <renderer mime=\"application/x-afp\">\n"
@@ -88,7 +98,9 @@ public class AFPTrueTypeTestCase {
                 + "</fo:root>";
 
         FopFactoryBuilder confBuilder = new FopConfParser(
-                new ByteArrayInputStream(fopxconf.getBytes()), new File(".").toURI()).getFopFactoryBuilder();
+                new ByteArrayInputStream(fopxconf.getBytes()),
+                EnvironmentalProfileFactory.createRestrictedIO(new URI("."),
+                        new MyResourceResolver())).getFopFactoryBuilder();
         FopFactory fopFactory = confBuilder.build();
         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -131,6 +143,22 @@ public class AFPTrueTypeTestCase {
                 + "END DOCUMENT DOC00001\n";
 
         Assert.assertEquals(sb.toString(), format);
+        Assert.assertEquals("test/resources/fonts/ttf/DejaVuLGCSerif.ttf", font);
+    }
+
+    class MyResourceResolver implements ResourceResolver {
+        private ResourceResolver defaultResourceResolver = ResourceResolverFactory.createDefaultResourceResolver();
+        public Resource getResource(URI uri) throws IOException {
+            if (!"tmp".equals(uri.getScheme())) {
+                font = uri.getPath();
+                uri = new File(".", uri.getPath()).toURI();
+            }
+            return defaultResourceResolver.getResource(uri);
+        }
+
+        public OutputStream getOutputStream(URI uri) throws IOException {
+            return defaultResourceResolver.getOutputStream(uri);
+        }
     }
 
     @Test
@@ -174,7 +202,7 @@ public class AFPTrueTypeTestCase {
             MultiByteFont font = new MultiByteFont(null, EmbeddingMode.AUTO);
             font.setWidthArray(new int[100]);
             f.addMetrics("any", new AFPFontConfig.AFPTrueTypeFont("", true,
-                    new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null));
+                    new FopCharacterSet("", "UTF-16BE", "", font, null, null), null, null, null));
             return f;
         }
     }