xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r446640 - in /xmlgraphics/fop/trunk/test: java/org/apache/fop/ java/org/apache/fop/render/pdf/ xml/pdf-encoding/
Date Fri, 15 Sep 2006 15:43:47 GMT
Author: bdelacretaz
Date: Fri Sep 15 08:43:47 2006
New Revision: 446640

URL: http://svn.apache.org/viewvc?view=rev&rev=446640
Log:
PDFEncodingTestCase added, but test with custom font is disabled, fails (as expected, bugzilla
40467)

Added:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java   (with
props)
    xmlgraphics/fop/trunk/test/xml/pdf-encoding/
    xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf   (with props)
    xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-custom-font.fo
    xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-standard-font.fo
Modified:
    xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
    xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java?view=diff&rev=446640&r1=446639&r2=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/StandardTestSuite.java Fri Sep 15 08:43:47
2006
@@ -20,6 +20,7 @@
 package org.apache.fop;
 
 import org.apache.fop.render.pdf.PDFAConformanceTestCase;
+import org.apache.fop.render.pdf.PDFEncodingTestCase;
 import org.apache.fop.render.rtf.RichTextFormatTestSuite;
 
 import junit.framework.Test;
@@ -41,6 +42,7 @@
         suite.addTest(BasicDriverTestSuite.suite());
         suite.addTest(UtilityCodeTestSuite.suite());
         suite.addTest(new TestSuite(PDFAConformanceTestCase.class));
+        suite.addTest(new TestSuite(PDFEncodingTestCase.class));
         suite.addTest(RichTextFormatTestSuite.suite());
         //$JUnit-END$
         return suite;

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java?view=diff&rev=446640&r1=446639&r2=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java Fri Sep
15 08:43:47 2006
@@ -44,27 +44,41 @@
 
   protected BasePDFTestCase(String name) {
     super(name);
+    
+    final File uc = getUserConfigFile();
+    
+    try {
+      fopFactory.setUserConfig(uc);
+    } catch (Exception e) {
+      throw new RuntimeException("fopFactory.setUserConfig (" + uc.getAbsolutePath() + ")
failed: " + e.getMessage());
+    }
   }
   
   /**
    * Convert a test FO file to PDF
    * @param foFile the FO file
    * @param ua the preconfigured user agent
-   * @param dumpPdfFile if true, dumps the generated PDF file to a file name (foFile).pdf
and returns it as a File
+   * @param dumpPdfFile if true, dumps the generated PDF file to a file name (foFile).pdf
+   * @return the generated PDF data
    * @throws Exception if the conversion fails
    */
-  protected File convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) throws Exception
{
-      File outFile = null;
+  protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) throws Exception
{
       ByteArrayOutputStream baout = new ByteArrayOutputStream();
       Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, ua, baout);
       Transformer transformer = tFactory.newTransformer();
       Source src = new StreamSource(foFile);
       SAXResult res = new SAXResult(fop.getDefaultHandler());
       transformer.transform(src, res);
+      final byte[] result = baout.toByteArray();  
       if (dumpPdfFile) {
-          outFile = new File(foFile.getParentFile(), foFile.getName() + ".pdf");
-          FileUtils.writeByteArrayToFile(outFile, baout.toByteArray());
+          final File outFile = new File(foFile.getParentFile(), foFile.getName() + ".pdf");
+          FileUtils.writeByteArrayToFile(outFile, result);
       }
-      return outFile;
+      return result;
+  }
+  
+  /** get FOP config File */
+  protected File getUserConfigFile() {
+    return new File("test/test.xconf");
   }
 }

Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java?view=diff&rev=446640&r1=446639&r2=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
(original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
Fri Sep 15 08:43:47 2006
@@ -38,11 +38,6 @@
      */
     public PDFAConformanceTestCase(String name) {
         super(name);
-        try {
-            fopFactory.setUserConfig(new File("test/test.xconf"));
-        } catch (Exception e) {
-            throw new RuntimeException("Configuring the FopFactory failed: " + e.getMessage());
-        }
     }
 
     /** create an FOUserAgent for our tests */

Added: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java?view=auto&rev=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java (added)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java Fri
Sep 15 08:43:47 2006
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+
+package org.apache.fop.render.pdf;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import org.apache.fop.apps.FOUserAgent;
+
+/** Test that characters are correctly encoded in a generated PDF file */
+public class PDFEncodingTestCase extends BasePDFTestCase {
+  private File foBaseDir = new File("test/xml/pdf-encoding");
+  private final boolean dumpPDF = Boolean.getBoolean("PDFEncodingTestCase.dumpPDF");
+  
+  static final String INPUT_FILE = "test/xml/pdf-encoding/pdf-encoding-test.xconf";
+  static final String TEST_MARKER = "PDFE_TEST_MARK_";
+  
+  public PDFEncodingTestCase(String name) {
+    super(name);
+  }
+
+  /** create an FOUserAgent for our tests */
+  protected FOUserAgent getUserAgent() {
+    final FOUserAgent a = fopFactory.newFOUserAgent();
+    return a;
+  }
+
+  /** use our specific config */
+  protected File getUserConfigFile() {
+    return new File(INPUT_FILE);
+  }
+
+  
+  public void testPDFEncodingWithStandardFont() throws Exception {
+    
+    /*  If the PDF encoding is correct, a text dump of the generated PDF file contains this
(excerpts) 
+     *     ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ]
TJ
+     *     ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX)
] TJ
+     *  The following array is used to look for these patterns
+     */ 
+    final String testPatterns[] = {
+      TEST_MARKER + "1", "(Standard)",
+      TEST_MARKER + "2", "XX_\\351_XX",
+      TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX"
+    };
+
+    runTest("test-standard-font.fo",testPatterns);
+  }
+  
+  /* TODO test disabled for now, fails due (probably) do different PDF encoding when custom
font is used */  
+  public void DISABLED_testPDFEncodingWithCustomFont() throws Exception {
+    
+    /*  If the PDF encoding is correct, a text dump of the generated PDF file contains this
(excerpts) 
+     *     ...Tm [(PDFE_TEST_MARK_2:) ( ) (This) ( ) (is) ...(acute:) ( ) (XX_\351_XX) ]
TJ
+     *     ...Tm [(PDFE_TEST_MARK_3:) ( ) (This) ( ) (is) ...(letter:) ( ) (XX_\342\352\356\364\373_XX)
] TJ
+     *  The following array is used to look for these patterns
+     */ 
+    final String testPatterns[] = {
+      TEST_MARKER + "1", "(Gladiator)",
+      TEST_MARKER + "2", "XX_\\351_XX",
+      TEST_MARKER + "3", "XX_\\342\\352\\356\\364\\373_XX"
+    };
+
+    runTest("test-custom-font.fo",testPatterns);
+  }
+  
+  /** Test encoding using specified input file and test patterns array */
+  private void runTest(String inputFile,String [] testPatterns) throws Exception {
+    File foFile = new File(foBaseDir, inputFile);
+    byte[] pdfData = convertFO(foFile, getUserAgent(), dumpPDF);
+    checkEncoding(pdfData,testPatterns);
+  }
+  
+  /** Check character encodings in the generated PDF data, by reading text
+   *  lines identified by markers and checking their content 
+   * @throws IOException */
+  private void checkEncoding(byte[] pdf,String[] testPattern) throws IOException {
+    
+    int markersFound = 0;
+    final String input = new String(pdf);
+    int pos = 0;
+    if((pos=input.indexOf(TEST_MARKER)) >= 0) {
+      final StringTokenizer tk = new StringTokenizer(input.substring(pos),"\n");
+      
+      while(tk.hasMoreTokens()) {
+        final String line = tk.nextToken();
+        if(line.indexOf(TEST_MARKER) >=0) {
+          markersFound++;
+          for(int i=0; i < testPattern.length; i+=2) {
+            if(line.indexOf(testPattern[i]) >= 0) {
+              final String ref = testPattern[i+1];
+              final boolean patternFound = line.indexOf(ref) >= 0;
+              assertTrue("line containing '" + testPattern[i] + "' must contain '" + ref,patternFound);
+            }
+          }
+        }
+      }
+    }
+      
+    final int nMarkers = testPattern.length / 2;
+    assertEquals(nMarkers + " " + TEST_MARKER + " markers must be found",nMarkers,markersFound);
+  }
+}

Propchange: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFEncodingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf?view=auto&rev=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf (added)
+++ xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf Fri Sep 15 08:43:47
2006
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+
+<!--
+  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.
+-->
+
+<!--
+	FOP config for PDF encoding test: disable all output filters
+	and setup a custom font
+-->
+
+<fop version="1.0">
+  <renderers>
+    <renderer mime="application/pdf">
+      <!-- disable PDF text compression -->
+		  <filterList>
+        <value>null</value>
+      </filterList>
+      <filterList type="image">
+        <value>flate</value>
+        <value>ascii-85</value>
+      </filterList>
+      
+      <!-- use a custom font to show encoding problems -->
+      <fonts>
+        <font metrics-url="test/resources/fonts/glb12.ttf.xml" embed-url="test/resources/fonts/glb12.ttf">
+          <font-triplet name="Gladiator" style="normal" weight="normal"/>
+        </font>
+      </fonts>
+    </renderer>
+  </renderers>
+</fop>

Propchange: xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/trunk/test/xml/pdf-encoding/pdf-encoding-test.xconf
------------------------------------------------------------------------------
    svn:keywords = Id

Added: xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-custom-font.fo
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-custom-font.fo?view=auto&rev=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-custom-font.fo (added)
+++ xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-custom-font.fo Fri Sep 15 08:43:47 2006
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+	Minimal FO document used to test PDF encoding
+-->
+
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Gladiator">
+  <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>Testing PDF text encoding using the user-specified Gladiator font</fo:block>
+      <fo:block>PDFE_TEST_MARK_1: Hello Gladiator World!</fo:block>
+      <fo:block>PDFE_TEST_MARK_2: This is an e acute: XX_é_XX</fo:block>
+      <fo:block>PDFE_TEST_MARK_3: This is aeiou with circumflex on each letter: XX_âêîôû_XX</fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>

Added: xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-standard-font.fo
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-standard-font.fo?view=auto&rev=446640
==============================================================================
--- xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-standard-font.fo (added)
+++ xmlgraphics/fop/trunk/test/xml/pdf-encoding/test-standard-font.fo Fri Sep 15 08:43:47
2006
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+	Minimal FO document used to test PDF encoding
+-->
+
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
+  <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>Testing PDF text encoding using a standard FOP font</fo:block>
+      <fo:block>PDFE_TEST_MARK_1: Hello Standard World!</fo:block>
+      <fo:block>PDFE_TEST_MARK_2: This is an e acute: XX_é_XX</fo:block>
+      <fo:block>PDFE_TEST_MARK_3: This is aeiou with circumflex on each letter: XX_âêîôû_XX</fo:block>
+    </fo:flow>
+  </fo:page-sequence>
+</fo:root>



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


Mime
View raw message