aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-02-06 15:04:32 +0000
committerJeremias Maerki <jeremias@apache.org>2009-02-06 15:04:32 +0000
commitc3e361cc95e11e15e45f698943f85e528ef18592 (patch)
tree7a0b88bd3e284b01aa335ad54c103ff36af187eb /examples
parent5301aae80aeae45bef73bd80a2a4f08ab2bcda2e (diff)
downloadxmlgraphics-fop-c3e361cc95e11e15e45f698943f85e528ef18592.tar.gz
xmlgraphics-fop-c3e361cc95e11e15e45f698943f85e528ef18592.zip
Example for stamping with new IF.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@741585 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'examples')
-rw-r--r--examples/embedding/java/embedding/intermediate/ExampleStamp.java58
-rw-r--r--examples/embedding/xml/xslt/ifstamp.xsl49
2 files changed, 80 insertions, 27 deletions
diff --git a/examples/embedding/java/embedding/intermediate/ExampleStamp.java b/examples/embedding/java/embedding/intermediate/ExampleStamp.java
index c6123b718..42ea34137 100644
--- a/examples/embedding/java/embedding/intermediate/ExampleStamp.java
+++ b/examples/embedding/java/embedding/intermediate/ExampleStamp.java
@@ -28,16 +28,18 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.xml.sax.SAXException;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.area.AreaTreeModel;
-import org.apache.fop.area.AreaTreeParser;
-import org.apache.fop.area.RenderPagesModel;
-import org.apache.fop.fonts.FontInfo;
-import org.xml.sax.SAXException;
+import org.apache.fop.render.intermediate.IFDocumentHandler;
+import org.apache.fop.render.intermediate.IFException;
+import org.apache.fop.render.intermediate.IFParser;
+import org.apache.fop.render.intermediate.IFUtil;
import embedding.ExampleObj2XML;
import embedding.model.ProjectTeam;
@@ -53,30 +55,35 @@ public class ExampleStamp {
/**
* Stamps an intermediate file and renders it to a PDF file.
- * @param atfile the intermediate file (area tree XML)
+ * @param iffile the intermediate file (area tree XML)
* @param stampSheet the stylesheet that does the stamping
* @param pdffile the target PDF file
* @throws IOException In case of an I/O problem
* @throws TransformerException In case of a XSL transformation problem
* @throws SAXException In case of an XML-related problem
+ * @throws IFException if there was an IF-related error while creating the output file
*/
- public void stampToPDF(File atfile, File stampSheet, File pdffile)
- throws IOException, TransformerException, SAXException {
+ public void stampToPDF(File iffile, File stampSheet, File pdffile)
+ throws IOException, TransformerException, SAXException, IFException {
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
- //Setup fonts and user agent
- FontInfo fontInfo = new FontInfo();
+ //user agent
FOUserAgent userAgent = fopFactory.newFOUserAgent();
- //Construct the AreaTreeModel that will received the individual pages
- AreaTreeModel treeModel = new RenderPagesModel(userAgent,
- MimeConstants.MIME_PDF, fontInfo, out);
+ //Setup target handler
+ String mime = MimeConstants.MIME_PDF + ";mode=painter";
+ IFDocumentHandler targetHandler = fopFactory.getRendererFactory().createDocumentHandler(
+ userAgent, mime);
- //Iterate over all intermediate files
- AreaTreeParser parser = new AreaTreeParser();
- Source src = new StreamSource(atfile);
+ //Setup fonts
+ IFUtil.setupFonts(targetHandler);
+ targetHandler.setResult(new StreamResult(pdffile));
+
+ IFParser parser = new IFParser();
+
+ Source src = new StreamSource(iffile);
Source xslt = new StreamSource(stampSheet);
//Setup Transformer for XSLT processing
@@ -84,13 +91,10 @@ public class ExampleStamp {
Transformer transformer = tFactory.newTransformer(xslt);
//Send XSLT result to AreaTreeParser
- SAXResult res = new SAXResult(parser.getContentHandler(treeModel, userAgent));
+ SAXResult res = new SAXResult(parser.getContentHandler(targetHandler, userAgent));
//Start XSLT transformation and area tree parsing
transformer.transform(src, res);
-
- //Signal the end of the processing. The renderer can finalize the target document.
- treeModel.endDocument();
} finally {
out.close();
}
@@ -102,7 +106,7 @@ public class ExampleStamp {
*/
public static void main(String[] args) {
try {
- System.out.println("FOP ExampleConcat\n");
+ System.out.println("FOP ExampleConcat (for the Intermediate Format)\n");
//Setup directories
File baseDir = new File(".");
@@ -111,10 +115,10 @@ public class ExampleStamp {
//Setup output file
File xsltfile = new File(baseDir, "xml/xslt/projectteam2fo.xsl");
- File atfile = new File(outDir, "team.at.xml");
- File stampxsltfile = new File(baseDir, "xml/xslt/atstamp.xsl");
- File pdffile = new File(outDir, "ResultStamped.pdf");
- System.out.println("Intermediate file : " + atfile.getCanonicalPath());
+ File iffile = new File(outDir, "team.at.xml");
+ File stampxsltfile = new File(baseDir, "xml/xslt/ifstamp.xsl");
+ File pdffile = new File(outDir, "ResultIFStamped.pdf");
+ System.out.println("Intermediate file : " + iffile.getCanonicalPath());
System.out.println("Stamp XSLT: " + stampxsltfile.getCanonicalPath());
System.out.println("PDF Output File: " + pdffile.getCanonicalPath());
System.out.println();
@@ -125,11 +129,11 @@ public class ExampleStamp {
ExampleConcat concatapp = new ExampleConcat();
concatapp.convertToIntermediate(
team1.getSourceForProjectTeam(),
- new StreamSource(xsltfile), atfile);
+ new StreamSource(xsltfile), iffile);
//Stamp document and produce a PDF from the intermediate format
ExampleStamp app = new ExampleStamp();
- app.stampToPDF(atfile, stampxsltfile, pdffile);
+ app.stampToPDF(iffile, stampxsltfile, pdffile);
System.out.println("Success!");
diff --git a/examples/embedding/xml/xslt/ifstamp.xsl b/examples/embedding/xml/xslt/ifstamp.xsl
new file mode 100644
index 000000000..3402e2281
--- /dev/null
+++ b/examples/embedding/xml/xslt/ifstamp.xsl
@@ -0,0 +1,49 @@
+<?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.
+-->
+<!-- $Id$ -->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:if="http://xmlgraphics.apache.org/fop/intermediate">
+ <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
+ <!-- ========================= -->
+ <!-- stamping... -->
+ <!-- ========================= -->
+ <xsl:template match="if:content">
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+
+ <!-- Stamp a big "SPECIMEN" text over the whole page using an area tree fragment inserted at the right place... -->
+ <if:g transform="translate(100000, 750000) rotate(-55)">
+ <if:font family="sans-serif" style="normal" weight="400" variant="normal" size="160000"
+ color="#dfdfdf"/>
+ <if:text xml:space="preserve" x="0" y="0">SPECIMEN</if:text>
+ </if:g>
+ <!-- Note: The free transformation above will not work with AFP output. In such a case,
+ using an embedded SVG graphic is better. -->
+
+ <xsl:apply-templates select="child::*"/>
+ </xsl:copy>
+ </xsl:template>
+ <!-- ========================= -->
+ <!-- identity transformation -->
+ <!-- ========================= -->
+ <xsl:template match="@*|node()">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+</xsl:stylesheet>