From: Jeremias Maerki Date: Fri, 6 Feb 2009 16:27:13 +0000 (+0000) Subject: Updated intermediate format documentation. X-Git-Tag: fop-1_0~115^2~65 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3223617036061636f98c520b871078e3a0e0e0bf;p=xmlgraphics-fop.git Updated intermediate format documentation. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@741616 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/trunk/intermediate.xml b/src/documentation/content/xdocs/trunk/intermediate.xml index 4744185aa..75f3fe4c5 100644 --- a/src/documentation/content/xdocs/trunk/intermediate.xml +++ b/src/documentation/content/xdocs/trunk/intermediate.xml @@ -24,16 +24,24 @@ - Please note that the intermediate format is an advanced feature and can be ignored by most - users of Apache FOP. + Please note that the intermediate formats described here are + advanced features and can be ignored by most users of Apache FOP.
Introduction

- The intermediate format (IF) is a proprietary XML format that represents the area tree - generated by the layout engine. The area tree is conceptually defined in the + Apache FOP now provides two different so-called intermediate formats. The first one + (let's call it the area tree XML format) is basically a 1:1 XML representation of the FOP's + area tree generated by the layout engine. The area tree is conceptually defined in the XSL-FO specification in chapter 1.1.2. - The IF can be generated through the area tree XML Renderer (the XMLRenderer). + Even though the area tree is mentioned in the XSL-FO specification, this part is not + standardized. Therefore, the area tree XML format is a FOP-proprietary XML file format. + The area tree XML can be generated through the area tree XML Renderer (the XMLRenderer). +

+

+ The second intermediate format (which we shall it exactly that: the intermediate format) + is a recent addition which tries to meet a slightly different set of goals. It is highly + optimized for speed.

The intermediate format can be used to generate intermediate documents that are modified @@ -43,31 +51,78 @@ to a single output file.

+
+ Which Intermediate Format to choose? +

+ There are two formats to choose from, so the question which format to choose is obvious. + Here's a list of strengths and use cases for both formats: +

+
+ Area Tree XML (AT XML) +
    +
  • 1:1 representation of FOP's area tree in XML.
  • +
  • Contains more structure information than the new intermediate format.
  • +
  • Used in FOP's layout engine test suite for regression testing.
  • +
+
+
+ Intermediate Format (IF) +
    +
  • Highly optimized for speed.
  • +
  • Smaller XML files.
  • +
  • Easier to post-process.
  • +
  • XML Schema is available.
  • +
  • + Recommended for use cases where documents are formatted concurrently and later + concatenated to a single print job. +
  • +
+
+

+ Both formats have their use cases. You will need to choose for yourself which format is + suitable for your use case. +

+

+ More technical information about the two formats can be found on the + FOP Wiki. +

+
+
+ Architectural Overview +
+
- Usage of the Intermediate Format + Usage of the Area Tree XML format (AT XML)

- As already mentioned, the IF is generated by using the XMLRenderer (MIME type: - application/X-fop-areatree). So, you basically set the right MIME type for - the output format and process your FO files as if you would create a PDF file. However, there - is an important detail to consider: The various Renderers don't all use the same font sources. - To be able to create the right area tree for the ultimate output file, you need to create - the IF file using the right font setup. This is achieved by telling the XMLRenderer to mimic - another renderer. This is done by calling the XMLRenderer's mimicRenderer() method with an - instance of the ultimate target renderer as the single parameter. This has a consequence: An - IF file rendered with the Java2DRenderer may not look as expected when it was actually generated - for the PDF renderer. For renderers that use the same font setup, this restriction does not - apply (PDF and PS, for example). Generating the intermediate format file is the first step. + As already mentioned, the area tree XML format is generated by using the + XMLRenderer (MIME type: application/X-fop-areatree). + So, you basically set the right MIME type for the output format and process your FO files + as if you would create a PDF file.

- The second step is to reparse the IF file using the AreaTreeParser which is - found in the org.apache.fop.area package. The pages retrieved from the IF file are added to an - AreaTreeModel instance from where they are normally rendered using one of the available Renderer - implementations. You can find examples for the IF processing in the - examples/embedding - directory in the FOP distribution + However, there is an important detail to consider: The + various Renderers don't all use the same font sources. To be able to create the right + area tree for the ultimate output file, you need to create the area tree XML file using + the right font setup. This is achieved by telling the XMLRenderer to mimic another + renderer. This is done by calling the XMLRenderer's mimicRenderer() method with an + instance of the ultimate target renderer as the single parameter. This has a consequence: + An area tree XML file rendered with the Java2DRenderer may not look as expected when it + was actually generated for the PDF renderer. For renderers that use the same font setup, + this restriction does not apply (PDF and PS, for example). Generating the area tree XML + format file is the first step.

- The basic pattern to parse the IF format looks like this: + The second step is to reparse the file using the AreaTreeParser which is + found in the org.apache.fop.area package. The pages retrieved from the area tree XML file + are added to an AreaTreeModel instance from where they are normally rendered using one of + the available Renderer implementations. You can find examples for the area tree XML + processing in the + examples/embedding + directory in the FOP distribution. +

+

+ The basic pattern to parse the area tree XML format looks like this:

- This example simply reads an IF file and renders it to a PDF file. Please note, that in normal + This example simply reads an area tree file and renders it to a PDF file. Please note, that in normal FOP operation you're shielded from having to instantiate the FontInfo object yourself. This is normally a task of the AreaTreeHandler which is not present in this scenario. The same applies to the AreaTreeModel instance, in this case an instance of a subclass called @@ -105,7 +160,7 @@ try { is now finished.

- The intermediate format can also be used from the command-line + The area tree XML format can also be used from the command-line by using the "-atin" parameter for specifying the area tree XML as input file. You can also specify a "mimic renderer" by inserting a MIME type between "-at" and the output file.

@@ -113,8 +168,8 @@ try { Concatenating Documents

This initial example is obviously not very useful. It would be faster to create the PDF file - directly. As the ExampleConcat.java - example shows you can easily parse multiple IF files in a row and add the parsed pages to the + directly. As the ExampleConcat.java + example shows you can easily parse multiple area tree files in a row and add the parsed pages to the same AreaTreeModel instance which essentially concatenates all the input document to one single output document.

@@ -122,18 +177,22 @@ try {
Modifying Documents

- One of the most important use cases for the intermediate format is obviously modifying the area + One of the most important use cases for this format is obviously modifying the area tree XML before finally rendering it to the target format. You can easily use XSLT to process - the IF file according to your needs. Please note, that we will currently not formally describe - the intermediate format. You need to have a good understanding its structure so you don't + the AT XML file according to your needs. Please note, that we will currently not formally describe + the area tree XML format. You need to have a good understanding its structure so you don't create any non-parseable files. We may add an XML Schema and more detailed documentation at a later time. You're invited to help us with that.

+ + The area tree XML format is sensitive to changes in whitespace. If you're not careful, + the modified file may not render correctly. +
Advanced Use

- The generation of the intermediate format as well as it parsing process has been designed to allow + The generation of the area tree format as well as it parsing process has been designed to allow for maximum flexibility and optimization. Please note that you can call setTransformerHandler() on XMLRenderer to give the XMLRenderer your own TransformerHandler instance in case you would like to do custom serialization (to a W3C DOM, for example) and/or to directly modify the area tree using @@ -142,5 +201,134 @@ try {

+
+ Usage of the Intermediate Format (IF) +

+ The Intermediate Format (IF) is generated by the IFSerializer + (MIME type: application/X-fop-intermediate-format). + So, you basically set the right MIME type for the output format and process your FO files + as if you would create a PDF file. +

+

+ The IFSerializer is an implementation of the IFDocumentHandler and + IFPainter interfaces. The IFRenderer class is responsible + for converting FOP's area tree into calls against these two interfaces. +

+ +

+ As with the AT XML, there is an important detail to consider: The various output + implementations don't all use the same font sources. To be able + to create the right IF for the ultimate output file, you need to create the IF file using + the right font setup. This is achieved by telling the IFRenderer (responsible for + converting the area tree into calls to the IFDocumentHandler and IFPainter interfaces) + to mimic another renderer. This is done by calling the IFSerializer's + mimicDocumentHandler() method with an instance of the ultimate target document handler + as the single parameter. This has a consequence: An IF file rendered with the + Java2DDocumentHandler may not look as expected when it was actually generated for the PDF + implementation. For implementations that use the same font setup, + this restriction does not apply (PDF and PS, for example). Generating the Intermediate + Format file is the first step. +

+

+ The second step is to reparse the file using the IFParser which is + found in the org.apache.fop.render.intermediate package. The IFParser simply takes an + IFDocumentHandler instance against which it generates the appropriate calls. The IFParser + is implemented as a SAX ContentHandler so you're free to choose the method for + post-processing the IF file(s). You can use XSLT or write SAX- or DOM-based code to + manipulate the contents. You can find examples for the Intermediate Format + processing in the + examples/embedding + directory in the FOP distribution. +

+

+ The basic pattern to parse the intermediate format looks like this: +

+ +

+ This example simply reads an intermediate file and renders it to a PDF file. Here + IFParser.parse() is used, but you can also just get a SAX ContentHandler by using the + IFParser.getContentHandler() method. +

+
+ Concatenating Documents +

+ This initial example is obviously not very useful. It would be faster to create the PDF file + directly (without the intermediate step). As the + ExampleConcat.java + example shows you can easily parse multiple intermediate files in a row and use the + IFConcatenator class to concatenate page sequences from multiple source files to a single + output file. This particular example does the concatenation on the level of the + IFDocumentHandler interface. You could also do this in XSLT or using SAX on the XML level. + Whatever suits your process best. +

+
+
+ Modifying Documents +

+ One of the most important use cases for this format is obviously modifying the + intermediate format before finally rendering it to the target format. You can easily use + XSLT to process the IF file according to your needs. +

+

+ There is an XML Schema (located under + src/documentation/intermediate-format-ng) + that helps you verify that your modified content is correct. +

+

+ For certain output formats there's a caveat: Formats like AFP and PCL do not support + arbitrary transformations on the IF's "viewport" and "g" elements. Possible are + only rotations in 90 degree steps and translations. +

+
+
+ Advanced Use +

+ The generation of the intermediate format as well as it parsing process has been + designed to allow for maximum flexibility and optimization. So rather than just passing + in a StreamResult to IFSerializer's setResult() method, you can also use a SAXResult + or a DOMResult. And as you've already seen , the IFParser on the other side allows you + to retrieve a ContentHandler instance where you can manually send SAX events to to + start the parsing process (see getContentHandler()). +

+
+
diff --git a/src/documentation/resources/images/if-architecture-overview.png b/src/documentation/resources/images/if-architecture-overview.png new file mode 100644 index 000000000..ea83ea93a Binary files /dev/null and b/src/documentation/resources/images/if-architecture-overview.png differ