Author: jeremias
Date: Fri Feb 6 15:04:32 2009
New Revision: 741585
URL: http://svn.apache.org/viewvc?rev=741585&view=rev
Log:
Example for stamping with new IF.
Added:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
(contents, props changed)
- copied, changed from r741121,
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/atstamp.xsl
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/java/embedding/intermediate/ExampleStamp.java
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/java/embedding/intermediate/ExampleStamp.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/java/embedding/intermediate/ExampleStamp.java?rev=741585&r1=741584&r2=741585&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/java/embedding/intermediate/ExampleStamp.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/java/embedding/intermediate/ExampleStamp.java
Fri Feb 6 15:04:32 2009
@@ -28,16 +28,18 @@
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 @@
/**
* 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);
-
- //Iterate over all intermediate files
- AreaTreeParser parser = new AreaTreeParser();
- Source src = new StreamSource(atfile);
+ //Setup target handler
+ String mime = MimeConstants.MIME_PDF + ";mode=painter";
+ IFDocumentHandler targetHandler =
fopFactory.getRendererFactory().createDocumentHandler(
+ userAgent, mime);
+
+ //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 @@
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 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 @@
//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 @@
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!");
Copied:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
(from r741121,
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/atstamp.xsl)
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl?p2=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl&p1=xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/atstamp.xsl&r1=741121&r2=741585&rev=741585&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/atstamp.xsl
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
Fri Feb 6 15:04:32 2009
@@ -16,33 +16,24 @@
limitations under the License.
-->
<!-- $Id$ -->
-<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<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="flow">
+ <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... -->
- <block ipd="595275" bpd="841889" is-viewport-area="true"
left-position="0" top-position="0" ctm="[1.0 0.0 0.0 1.0 0.0 0.0]"
positioning="fixed">
- <block ipd="595275" bpd="841889" is-reference-area="true">
- <block ipd="595275" bpd="841889">
- <lineArea ipd="595275" bpd="841889">
- <viewport ipd="595275" bpd="841889" offset="0" pos="0 0 595275
841889">
- <foreignObject ipd="0" bpd="0" ns="http://www.w3.org/2000/svg">
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100
100">
- <g transform="rotate(-50 50 50)">
- <text x="50" y="60"
style="font-size:20;fill:#dfdfdf;stroke:none;font-family:sans-serif"
text-anchor="middle">SPECIMEN</text>
- </g>
- </svg>
- </foreignObject>
- </viewport>
- </lineArea>
- </block>
- </block>
- </block>
+ <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>
Propchange:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/examples/embedding/xml/xslt/ifstamp.xsl
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Fri Feb 6 15:04:32 2009
@@ -0,0 +1,3 @@
+/xmlgraphics/fop/branches/Temp_AFPGOCAResources/examples/embedding/xml/xslt/atstamp.xsl:630874-721418
+/xmlgraphics/fop/branches/fop-0_95/examples/embedding/xml/xslt/atstamp.xsl:684572,688085,688696
+/xmlgraphics/fop/trunk/examples/embedding/xml/xslt/atstamp.xsl:603620-741103
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]