Author: vhennebert
Date: Thu Feb 20 21:45:20 2014
New Revision: 1570362

URL: http://svn.apache.org/r1570362
Log:
FOP-2346: UnsupportedOperationException when handling an SVG containing a 
font-face

Modified:
    xmlgraphics/fop/trunk/lib/batik-all-trunk.jar
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPFontFamilyResolver.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/AggregatingFontFamilyResolver.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPGVTFontFamily.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FilteringFontFamilyResolver.java
    
xmlgraphics/fop/trunk/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java

Modified: xmlgraphics/fop/trunk/lib/batik-all-trunk.jar
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/lib/batik-all-trunk.jar?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
Binary files - no diff available.

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPFontFamilyResolver.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPFontFamilyResolver.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPFontFamilyResolver.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/svg/AFPFontFamilyResolver.java
 Thu Feb 20 21:45:20 2014
@@ -22,6 +22,8 @@ package org.apache.fop.afp.svg;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.batik.gvt.font.GVTFontFace;
+
 import org.apache.fop.afp.AFPEventProducer;
 import org.apache.fop.afp.fonts.DoubleByteFont;
 import org.apache.fop.events.EventBroadcaster;
@@ -69,7 +71,8 @@ public class AFPFontFamilyResolver exten
                     notifyDBFontRejection(font.getFontName());
                 } else {
                     return new FOPGVTFontFamily(fontInfo, fontFamily,
-                            new FontTriplet(fontFamily, Font.STYLE_NORMAL, 
Font.WEIGHT_NORMAL));
+                            new FontTriplet(fontFamily, Font.STYLE_NORMAL, 
Font.WEIGHT_NORMAL),
+                            new GVTFontFace(fontFamily));
                 }
 
             }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/AggregatingFontFamilyResolver.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/AggregatingFontFamilyResolver.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/AggregatingFontFamilyResolver.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/AggregatingFontFamilyResolver.java
 Thu Feb 20 21:45:20 2014
@@ -19,9 +19,11 @@
 
 package org.apache.fop.svg.font;
 
+import java.io.InputStream;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.batik.bridge.FontFace;
 import org.apache.batik.gvt.font.FontFamilyResolver;
 import org.apache.batik.gvt.font.GVTFontFamily;
 
@@ -33,19 +35,19 @@ public class AggregatingFontFamilyResolv
         this.resolvers = Arrays.<FontFamilyResolver>asList(resolvers);
     }
 
-    public String lookup(String familyName) {
+    public GVTFontFamily resolve(String familyName) {
         for (FontFamilyResolver resolver : resolvers) {
-            String lookup = resolver.lookup(familyName);
-            if (lookup != null) {
-                return lookup;
+            GVTFontFamily family = resolver.resolve(familyName);
+            if (family != null) {
+                return family;
             }
         }
         return null;
     }
 
-    public GVTFontFamily resolve(String familyName) {
+    public GVTFontFamily resolve(String familyName, FontFace fontFace) {
         for (FontFamilyResolver resolver : resolvers) {
-            GVTFontFamily family = resolver.resolve(familyName);
+            GVTFontFamily family = resolver.resolve(familyName, fontFace);
             if (family != null) {
                 return family;
             }
@@ -53,6 +55,17 @@ public class AggregatingFontFamilyResolv
         return null;
     }
 
+    public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws 
Exception {
+        for (FontFamilyResolver resolver : resolvers) {
+            try {
+                return resolver.loadFont(in, fontFace);
+            } catch (Exception e) {
+                // Try the next one
+            }
+        }
+        return null;
+    }
+
     public GVTFontFamily getDefault() {
         return resolve("any");
     }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPFontFamilyResolverImpl.java
 Thu Feb 20 21:45:20 2014
@@ -19,8 +19,13 @@
 
 package org.apache.fop.svg.font;
 
+import java.io.InputStream;
 import java.util.Map;
 
+import org.apache.batik.bridge.FontFace;
+import org.apache.batik.gvt.font.GVTFontFace;
+import org.apache.batik.gvt.font.GVTFontFamily;
+
 import org.apache.fop.fonts.Font;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontTriplet;
@@ -34,20 +39,27 @@ public class FOPFontFamilyResolverImpl i
         this.fontInfo = fontInfo;
     }
 
-    public String lookup(String familyName) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+    public FOPGVTFontFamily resolve(String familyName) {
+        return resolve(familyName, new GVTFontFace(familyName));
     }
 
-    public FOPGVTFontFamily resolve(String familyName) {
+    public FOPGVTFontFamily resolve(String familyName, FontFace fontFace) {
+        return resolve(familyName, (GVTFontFace) 
FontFace.createFontFace(familyName, fontFace));
+    }
+
+    private FOPGVTFontFamily resolve(String familyName, GVTFontFace fontFace) {
         FOPGVTFontFamily gvtFontFamily = null;
         FontTriplet triplet = fontInfo.fontLookup(familyName, 
Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
         if (fontInfo.hasFont(familyName, Font.STYLE_NORMAL, 
Font.WEIGHT_NORMAL)) {
-            gvtFontFamily = new FOPGVTFontFamily(fontInfo, familyName, 
triplet);
+            gvtFontFamily = new FOPGVTFontFamily(fontInfo, familyName, 
triplet, fontFace);
         }
         return gvtFontFamily;
     }
 
+    public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws 
Exception {
+        throw new UnsupportedOperationException("Not implemented");
+    }
+
     public FOPGVTFontFamily getDefault() {
         return resolve("any");
     }
@@ -58,7 +70,8 @@ public class FOPFontFamilyResolverImpl i
             if (font.hasChar(c)) {
                 String fontFamily = font.getFamilyNames().iterator().next();
                 return new FOPGVTFontFamily(fontInfo, fontFamily,
-                        new FontTriplet(fontFamily, Font.STYLE_NORMAL, 
Font.WEIGHT_NORMAL));
+                        new FontTriplet(fontFamily, Font.STYLE_NORMAL, 
Font.WEIGHT_NORMAL),
+                        new GVTFontFace(fontFamily));
             }
         }
         return null;

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPGVTFontFamily.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPGVTFontFamily.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPGVTFontFamily.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FOPGVTFontFamily.java 
Thu Feb 20 21:45:20 2014
@@ -38,10 +38,13 @@ public class FOPGVTFontFamily implements
 
     private final String familyName;
 
-    public FOPGVTFontFamily(FontInfo fontInfo, String familyName, FontTriplet 
triplet) {
+    private GVTFontFace fontFace;
+
+    public FOPGVTFontFamily(FontInfo fontInfo, String familyName, FontTriplet 
triplet, GVTFontFace fontFace) {
         this.fontInfo = fontInfo;
         this.fontTriplet = triplet;
         this.familyName = familyName;
+        this.fontFace = fontFace;
     }
 
     public String getFamilyName() {
@@ -49,8 +52,7 @@ public class FOPGVTFontFamily implements
     }
 
     public GVTFontFace getFontFace() {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        return fontFace;
     }
 
     public FOPGVTFont deriveFont(float size, AttributedCharacterIterator aci) {

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FilteringFontFamilyResolver.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FilteringFontFamilyResolver.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FilteringFontFamilyResolver.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/font/FilteringFontFamilyResolver.java
 Thu Feb 20 21:45:20 2014
@@ -19,6 +19,11 @@
 
 package org.apache.fop.svg.font;
 
+import java.io.InputStream;
+
+import org.apache.batik.bridge.FontFace;
+import org.apache.batik.gvt.font.GVTFontFamily;
+
 
 public class FilteringFontFamilyResolver implements FOPFontFamilyResolver {
 
@@ -28,14 +33,18 @@ public class FilteringFontFamilyResolver
         this.delegate = delegate;
     }
 
-    public String lookup(String familyName) {
-        return delegate.lookup(familyName);
-    }
-
     public FOPGVTFontFamily resolve(String familyName) {
         return delegate.resolve(familyName);
     }
 
+    public GVTFontFamily resolve(String familyName, FontFace fontFace) {
+        return delegate.resolve(familyName, fontFace);
+    }
+
+    public GVTFontFamily loadFont(InputStream in, FontFace fontFace) throws 
Exception {
+        return delegate.loadFont(in, fontFace);
+    }
+
     public FOPGVTFontFamily getDefault() {
         return delegate.getDefault();
     }

Modified: 
xmlgraphics/fop/trunk/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java?rev=1570362&r1=1570361&r2=1570362&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
 (original)
+++ 
xmlgraphics/fop/trunk/test/java/org/apache/fop/svg/font/FOPFontFamilyResolverTestCase.java
 Thu Feb 20 21:45:20 2014
@@ -81,7 +81,7 @@ public class FOPFontFamilyResolverTestCa
 
     @Test
     public void testDeriveFont() {
-        FOPGVTFontFamily family = (FOPGVTFontFamily) 
resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF);
+        FOPGVTFontFamily family = 
resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF);
         FOPGVTFont font = family.deriveFont(10, Collections.emptyMap());
         assertEquals(10, font.getSize(), 0);
         assertTrue(font.canDisplay('\u01F6'));
@@ -91,7 +91,7 @@ public class FOPFontFamilyResolverTestCa
     @Test
     @Ignore("FOP metrics don't match AWT, but not sure who is right and who is 
wrong")
     public void testLineMetrics() throws FontFormatException, IOException {
-        FOPGVTFontFamily family = (FOPGVTFontFamily) 
resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF);
+        FOPGVTFontFamily family = 
resolver.resolve(FontInfoBuilder.DEJAVU_LGC_SERIF);
         FOPGVTFont font = family.deriveFont(10, Collections.emptyMap());
         GVTLineMetrics fopMetrics = font.getLineMetrics("", null);
         LineMetrics awtMetrics = getAWTLineMetrics();



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to