You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/04/12 11:02:02 UTC

svn commit: r647403 - in /xmlgraphics/fop/branches/fop-0_95: ./ src/java/org/apache/fop/fonts/ test/java/org/apache/fop/ test/java/org/apache/fop/fonts/

Author: jeremias
Date: Sat Apr 12 02:02:01 2008
New Revision: 647403

URL: http://svn.apache.org/viewvc?rev=647403&view=rev
Log:
Fixed NullPointerException when loading a TrueType font using XML font metric files.

Added:
    xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/
    xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java   (with props)
    xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl   (with props)
Modified:
    xmlgraphics/fop/branches/fop-0_95/build.xml
    xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/fonts/FontReader.java
    xmlgraphics/fop/branches/fop-0_95/status.xml
    xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/StandardTestSuite.java

Modified: xmlgraphics/fop/branches/fop-0_95/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/build.xml?rev=647403&r1=647402&r2=647403&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/build.xml (original)
+++ xmlgraphics/fop/branches/fop-0_95/build.xml Sat Apr 12 02:02:01 2008
@@ -707,6 +707,11 @@
         </fileset>
       </classpath>
     </javac>
+    <copy todir="${build.dir}/test-classes">
+      <fileset dir="${basedir}/test/java">
+        <include name="**/*.xsl"/>
+      </fileset>
+    </copy>
   </target>
 
   <target name="junit-transcoder" depends="junit-compile" description="Runs FOP's JUnit transcoder tests" if="junit.present">

Modified: xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/fonts/FontReader.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/fonts/FontReader.java?rev=647403&r1=647402&r2=647403&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/fonts/FontReader.java (original)
+++ xmlgraphics/fop/branches/fop-0_95/src/java/org/apache/fop/fonts/FontReader.java Sat Apr 12 02:02:01 2008
@@ -27,8 +27,6 @@
 
 import javax.xml.parsers.SAXParserFactory;
 
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.fonts.apps.TTFReader;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
@@ -36,6 +34,9 @@
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.DefaultHandler;
 
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.fonts.apps.TTFReader;
+
 /**
  * Class for reading a metric.xml file and creating a font object.
  * Typical usage:
@@ -228,11 +229,11 @@
         if ("font-name".equals(localName)) {
             returnFont.setFontName(content);
         } else if ("full-name".equals(localName)) {
-            multiFont.setFullName(content);
+            returnFont.setFullName(content);
         } else if ("family-name".equals(localName)) {
             Set s = new java.util.HashSet();
             s.add(content);
-            multiFont.setFamilyNames(s);
+            returnFont.setFamilyNames(s);
         } else if ("ttc-name".equals(localName) && isCID) {
             multiFont.setTTCName(content);
         } else if ("encoding".equals(localName)) {

Modified: xmlgraphics/fop/branches/fop-0_95/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/status.xml?rev=647403&r1=647402&r2=647403&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/status.xml (original)
+++ xmlgraphics/fop/branches/fop-0_95/status.xml Sat Apr 12 02:02:01 2008
@@ -59,6 +59,11 @@
         </action>
       -->
     <!--/release-->
+    <release version="0.95" date="TBD">
+      <action context="Fonts" dev="JM" type="fix">
+        Fixed NullPointerException when loading a TrueType font using XML font metric files.
+      </action>
+    </release>
     <release version="0.95beta" date="26 March 2008">
       <notes>
         <section>

Modified: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/StandardTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/StandardTestSuite.java?rev=647403&r1=647402&r2=647403&view=diff
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/StandardTestSuite.java (original)
+++ xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/StandardTestSuite.java Sat Apr 12 02:02:01 2008
@@ -22,6 +22,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.fop.fonts.TrueTypeAnsiTestCase;
 import org.apache.fop.render.pdf.PDFAConformanceTestCase;
 import org.apache.fop.render.pdf.PDFCMapTestCase;
 import org.apache.fop.render.pdf.PDFEncodingTestCase;
@@ -47,6 +48,7 @@
         suite.addTest(new TestSuite(PDFEncodingTestCase.class));
         suite.addTest(new TestSuite(PDFCMapTestCase.class));
         suite.addTest(new TestSuite(PDFsRGBSettingsTestCase.class));
+        suite.addTest(new TestSuite(TrueTypeAnsiTestCase.class));
         suite.addTest(RichTextFormatTestSuite.suite());
         //$JUnit-END$
         return suite;

Added: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java?rev=647403&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java (added)
+++ xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java Sat Apr 12 02:02:01 2008
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+ 
+package org.apache.fop.fonts;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.List;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.output.NullOutputStream;
+
+import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.fonts.apps.TTFReader;
+import org.apache.fop.render.pdf.PDFRenderer;
+
+/**
+ * Tests XML font metrics file generation and usage for WinAnsi mode.
+ */
+public class TrueTypeAnsiTestCase extends TestCase {
+    
+    /**
+     * Tests a TrueType font in WinAnsi mode.
+     * @throws Exception if an error occurs
+     */
+    public void testTrueTypeAnsi() throws Exception {
+        String fontFamily = "Gladiator Bold";
+        File ttfFile = new File("./test/resources/fonts/glb12.ttf");
+        File workDir = new File("./build/test-results");
+        if (!workDir.isDirectory()) {
+            assertTrue(workDir.mkdirs());
+        }
+        File metricsFile = new File(workDir, ttfFile.getName() + ".xml");
+        if (metricsFile.isFile()) {
+            assertTrue(metricsFile.delete());
+        }
+        
+        String[] args = new String[] {"-enc", "ansi",
+                ttfFile.getCanonicalPath(), metricsFile.getCanonicalPath()};
+        TTFReader.main(args);
+        assertTrue(metricsFile.isFile());
+        
+        FopFactory fopFactory = FopFactory.newInstance();
+        FOUserAgent ua = fopFactory.newFOUserAgent();
+        PDFRenderer renderer = new PDFRenderer();
+        renderer.setUserAgent(ua);
+        List fontList = new java.util.ArrayList();
+        List triplets = new java.util.ArrayList();
+        triplets.add(new FontTriplet(fontFamily, "normal", Font.WEIGHT_NORMAL));
+        EmbedFontInfo font = new EmbedFontInfo(
+                metricsFile.toURI().toASCIIString(),
+                true, triplets,
+                ttfFile.toURI().toASCIIString());
+        fontList.add(font);
+        renderer.addFontList(fontList);
+        
+        ua.setRendererOverride(renderer);
+        OutputStream out = new NullOutputStream();
+        
+        Fop fop = fopFactory.newFop(null, ua, out);
+        
+        TransformerFactory tFactory = TransformerFactory.newInstance();
+        Source src = new StreamSource(new StringReader(
+                "<root font-family='" + fontFamily + "'>Test!</root>"));
+        Result res = new SAXResult(fop.getDefaultHandler());
+        Transformer transformer = tFactory.newTransformer(
+                getSourceForResource(this, "fonttest.xsl"));
+        transformer.transform(src, res);
+    }
+
+    private static Source getSourceForResource(Object reference, String name) {
+        URL url = reference.getClass().getResource(name);
+        if (url == null) {
+            throw new NullPointerException("Resource not found: " + name);
+        }
+        return new StreamSource(url.toExternalForm());
+    }
+    
+}

Propchange: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/TrueTypeAnsiTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl?rev=647403&view=auto
==============================================================================
--- xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl (added)
+++ xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl Sat Apr 12 02:02:01 2008
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+	<xsl:output method="xml" indent="yes"/>
+
+	<xsl:template match="root">
+		<fo:root>
+			<fo:layout-master-set>
+				<fo:simple-page-master master-name="A4" page-height="29.7cm" page-width="21cm"
+					margin="2cm">
+					<fo:region-body/>
+				</fo:simple-page-master>
+			</fo:layout-master-set>
+			<fo:page-sequence master-reference="A4">
+				<fo:flow flow-name="xsl-region-body">
+					<fo:block font-family="{@font-family}">
+						<xsl:value-of select="."/>
+					</fo:block>
+				</fo:flow>
+			</fo:page-sequence>
+		</fo:root>
+	</xsl:template>
+</xsl:stylesheet>

Propchange: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/fop-0_95/test/java/org/apache/fop/fonts/fonttest.xsl
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org