From: Keiron Liddle Date: Fri, 29 Nov 2002 09:18:20 +0000 (+0000) Subject: converted across understanding docs X-Git-Tag: Alt-Design-integration-base~297 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=016f7ba94daab63373016d35864fbcd1fa168fb7;p=xmlgraphics-fop.git converted across understanding docs git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195654 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/design/understanding/area_tree.xml b/src/documentation/content/xdocs/design/understanding/area_tree.xml new file mode 100644 index 000000000..35e207b12 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/area_tree.xml @@ -0,0 +1,126 @@ + + + + +
+ Area Tree +
+ + +
+ Area Tree +
+ Area Tree +

The Area Tree is an internal representation of the result document. This +is a set of java classes that can put together a set of objects that +represent the pages and their contents.

+

This information is created by the layout managers and is rendered to the +output using a renderer.

+

The Area Tree follows the description of the area tree in the XSL:FO +specification.

+

The Area Tree consists of a set of pages, the actual implemenation places +these in +a set of page sequences.

+
+ +
+ Pages +

A page consists of a page+viewport pair.

+

The PageViewPort and Page with the regions is created by the +LayoutMasterSet. The contents are then placed by the layout managers. Once +the layout of a page is complete then it is added to the Area Tree.

+

Inside the page is a set of RegionViewport+Region pairs for each region on +the page.

+ + +
+ Blocks +

Block level areas contain either other blocks or line areas (which is a +special block area).

+A block is either positoned or stacked with other block areas.

+
+ +
+ Inline Areas +

Inline areas are stacked in a line area. Inline areas are objects such as +character, viewport, inline-container, leader and space. A special inline +area Word is also used for a group of consecutive characters.

+

The image and instream foreign object areas are placed inside a viewport. +The leader (with use content) and unresolved page number areas are +resolved to other inline areas.

+

Once a LineArea is filled with inline areas then the inline areas need to +be aligned and adjusted to fill the line properly.

+
+ +
+ Traits + +

A trait is information associated with an area. This could be information +such as text colour or is-first.

+

Traits provide information about an area. The traits are derived from +properties on the formatting object or are generated during the layout +process. Many of the layout traits do not have actual values but can be +derived from the Area Tree. Other traits that apply when rendering the +areas are set on the area. Since setting the same value on every area +would use a lot of memory then the traits are derived from default or +parent values.

+

A dominant trait on a block area is set, for example font colour, so that +every line area with the same dominant value can derive it. The text +inline areas then get the font colour set on the inline area or from the +line area or from the block area.

+
+ +
+ Forward References +

The Area Tree maintains a set of mappings from the reference to pages.

+

The PageViewPort holds the list of forward references that need resolving +so that if a references is resolved during layout the page can be easily +found and then fixed. Once all the forward references are resolved then +the page is ready to be rendered.

+

To layout a page any areas that cannot be resolved need to reserve space. +Once the inline area is resolved then the complete line should be adjusted +to accomodate any change in space used by the area.

+
+ +
+ Caching +

We may need to cache pages due to forward references or when keeping all +pages.

+

This is done by serializing the Page. The PageViewport is retained to be +used as a key for page references and backward references. +The Page is serialized to an object stream and then all of the page +contents are released. The Page is then recoved by reading from the object +stream.

+

The PageViewport retains information about id areas for easy access.

+
+ +
+ Extensions +

The Area Tree holds the Output Document extensions. This is information +such as pdf bookmarks or other output document specific information that +is not handled by XSL:FO.

+

It is also possible to create custom areas that extend a normal area. The +actual data that is rendered could be set in a different way or depend on +resolving a forward reference.

+
+ +
+ Area Tree Handlers +

To handle different situations the handler for the Area Tree handles each +page as it is added.

+The RenderPagesModel sends the page directly to the renderer if the page +is ready to be rendered. Once a page is rendered it is discarded. +The StorePagesModel stores all the pages so that any page can be later +accessed.

+

The Area Tree retains the concept of page sequences (this is not in the +area tree in the spec) so that this information can be passed to the +renderer. This is useful for setting the title and organising the groups +of page sequences.

+
+ +
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/book.xml b/src/documentation/content/xdocs/design/understanding/book.xml new file mode 100644 index 000000000..1730ec446 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/book.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/documentation/content/xdocs/design/understanding/fo_tree.xml b/src/documentation/content/xdocs/design/understanding/fo_tree.xml new file mode 100644 index 000000000..a03be543c --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/fo_tree.xml @@ -0,0 +1,144 @@ + + + + +
+ FO Tree +
+ + +
+ FO Tree +

+ The FO Tree is a representation of the XSL:FO document. This + represents the Objectify step from the + spec. The Refinement step is part of reading + and using the properties which may happen immediately or + during the layout process. +

+ +

Each xml element is represented by a java object. For pagination the +classes are in org.apache.fop.fo.pagination.*, for elements in the flow +they are in org.apache.fop.fo.flow.* and some others are in +org.apache.fop.fo.*.

+ +

The base class for all objects in the tree is FONode. The base class for +all FO Objects is FObj.

+ +

There is a class for each element in the FO set. An object is created for +each element in the FO Tree. This object holds the properties for the FO +Object.

+ +

+ When the object is created it is setup. It is given its + element name, the FOUserAgent - for resolving properties + etc. - the logger and the attributes. The methods + handleAttributes() and + setuserAgent(), common to FONode, + are used in this process. The object will then be given any + text data or child elements. Then the end() + method is called. The end method is used by a number of + elements to indicate that it can do certain processing since + all the children have been added. +

+ +

Some validity checking is done during these steps. The user can be warned of the error and processing can continue if possible. +

+ +

+ The FO Tree is simply a heirarchy of java objects that + represent the fo elements from xml. The traversal is done by + the layout or structure process only in the flow elements. +

+ +
+ Properties + +

The XML attributes on each element are passed to the object. The objects +that represent FO objects then convert the attributes into properties. +

+ +

Since properties can be inherited the PropertyList class handles resolving +properties for a particular element. +All properties are specified in an XML file. Classes are created +automatically during the build process. +

+ +

In some cases the element may be moved to have a different parent, for +example markers, or the inheritance could be different, for example +initial property set.

+
+ +
+ Foreign XML + +

The base class for foreign XML is XMLObj. This class handles creating a +DOM Element and the setting of attributes. It also can create a DOM +Document if it is a top level element, class XMLElement. +This class must be extended for the namespace of the XML elements. For +unknown namespaces the class is UnknowXMLObj.

+ +

If some special processing is needed then the top level element can extend +the XMLObj. For example the SVGElement makes the special DOM required for +batik and gets the size of the svg. +

+ +

Foreign XML will usually be in an fo:instream-foreign-object, the XML will +be passed to the render as a DOM where the render will be able to handle +it. Other XML from an unknwon namespace will be ignored. +

+ +

By using element mappings it is possible to read other XML and either

+
  • set information on the area tree
  • +
  • create pseudo FO Objects that create areas in the area tree
  • +
  • create FO Objects
+
+ +
+ Unknown Elements +

If an element is in a known namespace but the element is unknown then an +Unknown object is created. This is mainly to provide information to the +user. +This could happen if the fo document contains an element from a different +version or the element is misspelt.

+
+ +
+ Page Masters +

+ The first elements in a document are the elements for the + page master setup. This is usually only a small number and + will be used throughout the document to create new pages. + These elements are kept as a factory to create the page and + appropriate regions whenever a new page is requested by the + layout. The objects in the FO Tree that represent these + elements are themselves the factory. The root element keeps + these objects as a factory for the page sequences. +

+
+ +
+ Flow +

The elements that are in the flow of the document are a set of elements +that is needed for the layout process. Each element is important in the +creation of areas.

+
+ +
+ Other Elements + +

+ The remaining FO Objects are things like page-sequence, + title and color-profile. These are handled by their parent + element; i.e. the root looks after the declarations and the + declarations maintains a list of colour profiles. The + page-sequences are direct descendents of root. +

+
+ +
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/images.xml b/src/documentation/content/xdocs/design/understanding/images.xml new file mode 100644 index 000000000..fc40a64d6 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/images.xml @@ -0,0 +1,135 @@ + + + + +
+ Images +
+ + +
+ Images in FOP + +

Images may only be needed to be loaded when the image is rendered to the +output or to find the dimensions.
+An image url may be invalid, this can be costly to find out so we need to +keep a list of invalid image urls.

+

We have a number of different caching schemes that are possible.

+

All images are referred to using the url given in the XSL:FO after +removing "url('')" wrapping. This does +not include any sort of resolving such as relative -> absolute. The +external graphic in the FO Tree and the image area in the Area Tree only +have the url as a reference. +The images are handled through a static interface in ImageFactory.

+ +
+ Threading + +

In a single threaded case with one document the image should be released +as soon as the renderer caches it. If there are multiple documents then +the images could be held in a weak cache in case another document needs to +load the same image.

+ +

In a multi threaded case many threads could be attempting to get the same +image. We need to make sure an image will only be loaded once at a +particular time. Once a particular document is finished then we can move +all the images to a common weak cache.

+
+ +
+ Caches +
+ LRU +

All images are in a common cache regardless of context. To limit the size +of the cache the LRU image is removed to keep the amount of memory used +low. Each image can supply the amount of data held in memory.

+
+ +
+ Context +

Images are cached according to the context, using the FOUserAgent as a key. +Once the context is finished the images are added to a common weak hashmap +so that other contexts can load these images or the data will be garbage +collected if required.

+

If images are to be used commonly then we cannot dispose of data in the +FopImage when cached by the renderer. Also if different contexts have +different base directories for resolving relative url's then the loading +and caching must be separate. We can have a cache that shares images among +all contexts or only loads an image for a context.

+
+ +

The cache uses an image loader so that it can synchronize the image +loading on an image by image basis. Finding and adding an image loader to +the cache is also synchronized to prevent thread problems.

+
+ +
+ Invalid Images + +

+If an image cannot be loaded for some reason, for example the url is +invalid or the image data is corrupt or an unknown type. Then it should +only attempt to load the image once. All other attempts to get the image +should return null so that it can be easily handled.
+This will prevent any extra processing or waiting.

+
+ +
+ Reading +

Once a stream is opened for the image url then a set of image readers is +used to determine what type of image it is. The reader can peek at the +image header or if necessary load the image. The reader can also get the +image size at this stage. +The reader then can provide the mime type to create the image object to +load the rest of the information.

+
+ +
+ Data + +

The data usually need for an image is the size and either a bitmap or the +original data. Images such as jpeg and eps can be embedded into the +document with the original data. SVG images are converted into a DOM which +needs to be rendered to the PDF. Other images such as gif, tiff etc. are +converted into a bitmap. +Data is loaded by the FopImage by calling load(type) where type is the type of data to load.

+
+ + +
+ Rendering + +

Different renderers need to have the information in different forms.

+ + +
+ PDF +
original data
JPG, EPS
+
bitmap
gif, tiff, bmp, png
+
other
SVG
+
+ +
+ PS +
bitmap
JPG, gif, tiff, bmp, png
+
other
SVG
+
+ +
+ awt +
bitmap
JPG, gif, tiff, bmp, png
+
other
SVG
+
+ +

The renderer uses the url to retrieve the image from the ImageFactory and +then load the required data depending on the image mime type. If the +renderer can insert the image into the document and use that data for all +future references of the same image then it can cache the reference in the +renderer and the image can be released from the image cache.

+
+
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/index.xml b/src/documentation/content/xdocs/design/understanding/index.xml new file mode 100644 index 000000000..7bf8aa822 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/index.xml @@ -0,0 +1,68 @@ + + + + +
+ Understanding FOP Design + Tutorial series about Design Approach to FOP +
+ + +
+ Introduction +

+ Welcome to the understanding series. This will be + a series of notes for developers to understand how FOP + works. We will + attempt to clarify the processes involved to go from xml(fo) + to pdf or other formats. Some areas will get more + complicated as we proceed. +

+ +
+ Overview +

FOP takes an xml file does its magic and then writes a document to a + stream.

+

xml -> [FOP] -> document

+

The document could be pdf, ps etc. or directed to a printer or the + screen. The principle remains the same. The xml document must be in the XSL:FO + format.

+

For convenience we provide a mechanism to handle XML+XSL as + input.

+

The xml document is always handled internally as SAX. The SAX events + are used to read the elements, attributes and text data of the FO document. + After the manipulation of the data the renderer writes out the pages in the + appropriate format. It may write as it goes, a page at a time or the whole + document at once. Once finished the document should contain all the data in the + chosen format ready for whatever use.

+
+
+ Stages +

The fo data goes through a few stages. Each piece + of data will generally go through the process in the same way but some + information may be used a number of times or in a different order. To reduce + memory one stage will start before the previous is completed.

+

SAX Handler -> FO Tree -> Layout Managers -> Area Tree + -> Render -> document

+

In the case of rtf, mif etc.
SAX Handler -> FO Tree -> + Structure Renderer -> document

+

The FO Tree is constructed from the xml document. It is an internal + representation of the xml document and it is like a DOM with some differences. + The Layout Managers use the FO Tree do their layout stuff and create an Area + Tree. The Area Tree is a representation of the final result. It is a + representation of a set of pages containing the text and other graphics. The + Area Tree is then given to a Renderer. The Renderer can read the Area Tree and + convert the information into the render format. For example the PDF Renderer + creates a PDF Document. For each page in the Area Tree the renderer creates a + PDF Page and places the contents of the page into the PDF Page. Once a PDF Page + is complete then it can be written to the output stream.

+

For the structure documents the Structure listener will read + directly from the FO Tree and create the document. These documents do not need + the layout process or the Area Tree.

+
+ +
+ +
+ diff --git a/src/documentation/content/xdocs/design/understanding/layout_managers.xml b/src/documentation/content/xdocs/design/understanding/layout_managers.xml new file mode 100644 index 000000000..a16f7eca4 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/layout_managers.xml @@ -0,0 +1,65 @@ + + + + +
+ Layout Managers +
+ +
+ Layout Managers + +

The role of the layout managers is to build the Area Tree by using the +information from the FO Tree. The layout managers decide where information +is placed in the area tree.

+

A layout manager is typically associated with an FO Object but not always.

+ +

The layout managers are in between the FO Tree and the Area Tree. They get +information from the FO Tree and create areas and build the pages. They +hold the state of the layout process as it builds up the areas and pages. +They also manage the handling of breaks and spacing between areas.

+ + +

FO Objects can have two types of properties, ones that relate to the layout and ones that relate to the rendering. THe layout related properties area used by the layout managers to determine how and where to create the areas. The render related properties should be passed through to the renderer in the most efficient way possible. +

+ +
+ Block Areas + +

When a block creating element is complete then it is possible to build the +block area and add it to the paprent.

+

A block area will contain either more block areas or line areas, which are +special block areas. The line areas are created by the LineLayoutManager +in which the inline areas flow into.

+

So a block area manager handles the lines or blocks as its children and +determines things like spacing and breaks.

+

In the case of tables and lists the blocks are stacked in a specific way +that needs to be handled by the layout manager.

+
+ +
+ Side Floats + +

Side floats alter the length of the inline progression dimension for the +current line and following lines for the size of the float.

+

This means that the float needs to be handled by the block layout manager +so that it can adjust the available inline progression dimension for the +relevant line areas.

+
+ +
+ Footnotes and Before Floats + +

Footnotes and Before Floats are placed in special areas in the body region +of the page. The size of these areas is determined by the content. This in +turn effects the available size of the main reference area that contains +the flow.

+

A layout manager handles the adding and removing of footnotes/floats, this in turn effects the available space in the main reference area.

+ +
+
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/pdf_library.xml b/src/documentation/content/xdocs/design/understanding/pdf_library.xml new file mode 100644 index 000000000..e7301f6b1 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/pdf_library.xml @@ -0,0 +1,76 @@ + + + + +
+ PDF Library +
+ + +
+ PDF Library + +

The PDF Library is an independant package of classes in FOP. These class +provide a simple way to construct documents and add the contents. The +classes are found in org.apache.fop.pdf.*.

+ +
+ PDF Document +

This is where most of the document is created and put together.

+

It sets up the header, trailer and resources. Each page is made and added to the document. +There are a number of methods that can be used to create/add certain PDF objects to the document.

+
+ +
+ Building PDF +

The PDF Document is built by creating a page for each page in the Area Tree.

+

This page then has all the contents added. + The page is then added to the document and available objects can be written to the output stream.

+

The contents of the page are things such as text, lines, images etc. +The PDFRenderer inserts the text directly into a pdf stream. +The text consists of markup to set fonts, set text position and add text.

+

Most of the simple pdf markup is inserted directly into a pdf stream. +Other more complex objects or commonly used objects are added through java classes. +Some pdf objects such as an image consists of two parts.

+

It has a separate object for the image data and another bit of markup to display the image in a certain position on the page. +

The java objects that represent a pdf object implement a method that returns the markup for inserting into a stream. +The method is: byte[] toPDF().

+ +
+
+ Features + +
+ Fonts +

Support for embedding fonts and using the default Acrobat fonts. +

+ +
+ Images +

Images can be inserted into a page. The image can either be inserted as a pixel map or directly insert a jpeg image. +

+ +
+ Stream Filters +

A number of filters are available to encode the pdf streams. These filters can compress the data or change it such as converting to hex. +

+ +
+ Links +

A pdf link can be added for an area on the page. This link can then point to an external destination or a position on any page in the document. +

+ +
+ Patterns +

The fill and stroke of graphical objects can be set with a colour, pattern or gradient. +

+ +

The are a number of other features for handling pdf markup relevent to creating PDF files for FOP.

+
+ +
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/properties.xml b/src/documentation/content/xdocs/design/understanding/properties.xml new file mode 100644 index 000000000..6261b3d8e --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/properties.xml @@ -0,0 +1,110 @@ + + + + +
+ Properties +
+ + +
+ Property Handling +

During XML Parsing, the FO tree is constructed. For each FO object (some +subclass of FObj), the tree builder then passes the list of all +attributes specified on the FO element to the handleAttrs method. This +method converts the attribute specifications into a PropertyList.

+

The actual work is done by a PropertyListBuilder (PLB for short). The +basic idea of the PLB is to handle each attribute in the list in turn, +find an appropriate "Maker" for it, call the Maker to convert the +attribute value into a Property object of the correct type, and store +that Property in the PropertyList.

+ +
+ Finding a Maker +

+The PLB finds a "Maker" for the property based on the attribute name and +the element name. Most Makers are generic and handle the attribute on +any element, but it's possible to set up an element-specific property +Maker. The attribute name to Maker mappings are automatically created +during the code generation phase by processing the XML property +description files.

+
+ +
+ Processing the attribute list +

The PLB first looks to see if the font-size property is specified, since +it sets up relative units which can be used in other property +specifications. Each attribute is then handled in turn. If the attribute +specifies part of a compound property such as space-before.optimum, the +PLB looks to see if the attribute list also contains the "base" property +(space-before in this case) and processes that first.

+
+
+ How the Property Maker works +

There is a family of Maker objects for each of the property datatypes, +such as Length, Number, Enumerated, Space, etc. But since each Property +has specific aspects such as whether it's inherited, its default value, +its corresponding properties, etc. there is usually a specific Maker for +each Property. All these Maker classes are created during the code +generation phase by processing (using XSLT) the XML property description +files to create Java classes.

+ +

The Maker first checks for "keyword" values for a property. These are +things like "thin, medium, thick" for the border-width property. The +datatype is really a Length but it can be specified using these keywords +whose actual value is determined by the "User Agent" rather than being +specified in the XSL standard. For FOP, these values are currently +defined in foproperties.xml. The keyword value is just a string, so it +still needs to be parsed as described next.

+ +

The Maker also checks to see if the property is an Enumerated type and +then checks whether the value matches one of the specified enumeration +values.

+ +

Otherwise the Maker uses the property parser in the fo.expr package to +evaluate the attribute value and return a Property object. The parser +interprets the expression language and performs numeric operations and +function call evaluations.

+ +

If the returned Property value is of the correct type (specificed in +foproperties.xml, where else?), the Maker returns it. Otherwise, it may +be able to convert the returned type into the correct type.

+ +

Some kinds of property values can't be fully resolved during FO tree +building because they depend on layout information. This is the case of +length values specified as percentages and of the special +proportional-column-width(x) specification for table-column widths. +These are stored as special kinds of Length objects which are evaluated +during layout. Expressions involving "em" units which are relative to +font-size _are_ resolved during the FO tree building however.

+
+ +
+ Structure of the PropertyList +

The PropertyList extends HashMap and its basic function is to associate +Property value objects with Property names. The Property objects are all +subclasses of the base Property class. Each one simply contains a +reference to one of the property datatype objects. Property provides +accessors for all known datatypes and various subclasses override the +accessor(s) which are reasonable for the datatype they store.

+ +

The PropertyList itself provides various ways of looking up Property +values to handle such issues as inheritance and corresponding +properties.

+ +

The main logic is:
If the property is a writing-mode relative property (using start, end, +before or after in its name), the corresponding absolute property value +is returned if it's explicitly set on this FO.
Otherwise, the +writing-mode relative value is returned if it's explicitly set. If the +property is inherited, the process repeats using the PropertyList of the +FO's parent object. (This is easy because each PropertyList points to +the PropertyList of the nearest ancestor FO.) If the property isn't +inherited or no value is found at any level, the initial value is +returned.

+
+ +
+ +
+ diff --git a/src/documentation/content/xdocs/design/understanding/renderers.xml b/src/documentation/content/xdocs/design/understanding/renderers.xml new file mode 100644 index 000000000..cf98991b6 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/renderers.xml @@ -0,0 +1,131 @@ + + + + +
+ Renderers +
+ + +
+ Renderers + +
+ Renderers + +

A renderer is used to convert the Area Tree into the output document. +The renderer is given the tree one page at a time. All pages are supplied +in the order they appear in the document. In order to save memory it is +possble to render the pages out of order. Any page that is not reeady to +be rendered is setup by the renderer first so that it can reserve a space +or reference for when the page is ready to be rendered.

+

The AbstractRenderer does most of the work to iterate through the area +tree parts. This means that the most renderers simply need to implement +the specific parts with inserting text, images and lines. The methods can +easily be overridden to handle things in a different way or do some extra +processing.

+
+ +
+ Fonts +

The fonts are setup by the renderer being used. The font metrics are used +during the layout process to determine the size of characters.

+
+ +
+ Render Context +

The render context is used by handlers. It contains information about the +current state of the renderer. Such as the page, the position and any +other miscellanous objects that are required to draw into the page.

+
+ +
+ XML Handling + +

A document may contain information in the form of XML for an image or +instream foreign object. This XML is handled +through the user agent. A standard extension for PDF is the SVG handler.

+If there is XML in the SVG namespace it is given to the handler which +renders the SVG into the pdf document at the given location. +This separation means that other XML handlers can easily be added.

+
+ +
+ Extensions +

Document level extensions are handled with an extension handler. This +handles the information from the AreaTree and adds renders it to the +document. An example is the pdf bookmarks. This information first needs to +have all references resolved. Then the extension handler is ready to put +the information into the pdf document.

+
+ +
+Types + +
+ PDF +

This uses the PDFDocument classes to create a PDF document. This supports +out of order rendering as it is possible to reserve a pdf page object that +can be later filled. Most of the work is to insert text or create lines. +SVG is handled by the XML handler that uses the PDFGraphics2D and batik to +draw the svg into the pdf page.

+This also allows for font embedding.

+
+
+ SVG +

This creates a single svg document that contains all the pages rendered +with page sequences horizontally and pages vertically. This also adds +links between the pages so that it can be viewed by clicking on the page +to go to the next page.

+
+ +
+ TXT +

This simply outputs to a text document.

+
+ AWT +

This draws the pages into an AWT graphic.

+ +
+ PS and PCL +

Similar to PDF.

+ +
+ XML +

Creates an XML file that represents the AreaTree.

+
+
+ Print +

This prints the document using the java printing facitlities. The AWT +rendering is used to draw the pages onto the printjob. +

+
+
+ RTF and MIF +

These formats do not use this rendering mechanism.

+
+
+ +
+ Adding a Renderer +

It is also possible to add other renderers. The renderer simply needs to +implement the Renderer interface. The AbstractRenderer does most of what +is needed so it is better to extend this. This means that you only need to +implement the basic functionality such as text and lines. +

+
+ +
+ Multiple Renderers +

The layout of the document depends mainly on the font being used. +If two renderers have the same font metrics then it is possible to render +the Area Tree in each renderer. This can be handled by the AreaTree +Handler.

+
+ +
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/svg.xml b/src/documentation/content/xdocs/design/understanding/svg.xml new file mode 100644 index 000000000..74730dcd4 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/svg.xml @@ -0,0 +1,74 @@ + + + + +
+ SVG +
+ +
+ SVG +

SVG is rendered through Batik.

The XML from the XSL:FO document + is converted into an SVG DOM with batik. This DOM is then set as the Document + on the Foreign Object area in the Area Tree.

This DOM is then available to + be rendered by the renderer.

SVG is rendered in the renderers via an XMLHandler in the FOUserAgent. This XML handler is used to render the SVG. The + SVG is rendered by using batik. Batik converts the SVG DOM into an internal + structure that can be drawn into a Graphics2D. So for PDF we use a + PDFGraphics2D to draw into.

This creates the necessary PDF information to + create the SVG image in the PDF document.

Most of the work is done in the + PDFGraphics2D class. There are also a few bridges that are plugged into batik + to provide different behaviour for some SVG elements.

+
+ Text Drawing +

Normally batik converts text into a set of curved + shapes.

This is handled as any other shapes when rendering to the output. This + is not always desirable as the shapes have very fine curves. This can cause the + output to look a bit bad in PDF and PS (it can be drawn properly but is not by + default). These curves also require much more data than the original + text.

To handle this there is a PDFTextElementBridge that is set when + using the bridge in batik. If the text is simple enough for the text to be + drawn in the PDF as with all other text then this sets the TextPainter to use + the PDFTextPainter. This inserts the text directly into the PDF using the drawString method on the PDFGraphics2D.

Text is considered simple if the + font is available, the font size is useable and there are no tspans or other + complications. This can make the resulting PDF significantly + smaller.

+
+
+ PDF Links +

To support links in PDF another batik + element bridge is used. The PDFAElementBridge creates a PDFANode which inserts + a link into the PDF document via the PDFGraphics2D.

Since links are positioned on the page without any transforms then we need to transform the + coordinates of the link area so that they match the current position of the a + element area. This transform may also need to account for the svg being + positioned on the page.

+
+
+ Images +

Images are normally drawn + into the PDFGraphics2D. This then creates a bitmap of the image data that can + be inserted into the PDF document.

As PDF can support jpeg images then another + element bridge is used so that the jpeg can be directly inserted into the PDF.

+
+
+ PDF Transcoder +

Batik provides a mechanism to + convert SVG into various formats. Through FOP we can convert an SVG document + into a single paged PDF document. The page contains the SVG drawn as best as + possible on the page. There is a PDFDocumentGraphics2D that creates a + standalone PDF document with a single page. This is then drawn into by batik in + the same way as with the PDFGraphics2D.

+
+
+ Other Outputs +

When rendering to AWT the SVG is simply drawn onto the + awt canvas using batik.

The PS Renderer uses a similar technique as the + PDF Renderer.

The SVG Renderer simply embeds the SVG inside an svg + element.

+
+ +
+ + +
+ diff --git a/src/documentation/content/xdocs/design/understanding/xml_parsing.xml b/src/documentation/content/xdocs/design/understanding/xml_parsing.xml new file mode 100644 index 000000000..3f8df95d4 --- /dev/null +++ b/src/documentation/content/xdocs/design/understanding/xml_parsing.xml @@ -0,0 +1,113 @@ + + + + +
+ XML Parsing +
+ + +
+ XML Parsing +

Since everyone knows the basics we can get + into the various stages starting with the XML handling.

+
+ XML Input +

FOP can take the input XML in a number of ways: +

+
    +
  • SAX Events through SAX Handler +
      +
    • + FOTreeBuilder is the SAX Handler which is + obtained through getContentHandler on + Driver. +
    • +
    +
  • +
  • + DOM which is converted into SAX Events +
      +
    • + The conversion of a DOM tree is done via the + render(Document) method on + Driver. +
    • +
    +
  • +
  • + data source which is parsed and converted into SAX Events +
      +
    • + The Driver can take an + InputSource as input. This can use a + Stream, String etc. +
    • +
    +
  • +
  • + XML+XSLT which is transformed using an XSLT Processor and + the result is fired as SAX Events +
      +
    • + XSLTInputHandler is used as an + InputSource in the + render(XMLReader, + InputSource) method on + Driver +
    • +
    +
  • +
+

The SAX Events which are fired on the SAX Handler, class + FOTreeBuilder, must represent an XSL:FO document. If not there will be an + error. Any problems with the XML being well formed are handled here.

+
+
+ Element Mappings +

The element mapping is a hashmap of all + the elements in a particular namespace. This makes it easy to create a + different object for each element. Element mappings are static to save on + memory.

To add an extension a developer can put in the classpath a jar + that contains the file /META-INF/services/org.apache.fop.fo.ElementMapping. + This must contain a line with the fully qualified name of a class that + implements the org.apache.fop.fo.ElementMapping interface. This will then be + loaded automatically at the start. Internal mappings are: FO, SVG and Extension + (pdf bookmarks)

+
+ Tree Building +

The SAX Events will fire all the information + for the document with start element, end element, text data etc. This + information is used to build up a representation of the FO document. To do this + for a namespace there is a set of element mappings. When an element + namepsace + mapping is found then it can create an object for that element. If the element + is not found then it creates a dummy object or a generic DOM for unknown + namespaces.

+

The object is then setup and then given attributes for the element. + For the FO Tree the attributes are converted into properties. The FO objects + use a property list mapping to convert the attributes into a list of properties + for the element. For other XML, for example SVG, a DOM of the XML is + constructed. This DOM can then be passed through to the renderer. Other element + mappings can be used in different ways, for example to create elements that + create areas during the layout process or setup information for the renderer + etc.

+

+ While the tree building is mainly about creating the FO Tree + there are some stages that can propagate to the renderer. At + the end of a page sequence we know that all pages in the + page sequence can be laid out without being effected by any + further XML. The significance of this is that the FO Tree + for the page sequence may be able to be disposed of. The + end of the XML document also tells us that we can finalise + the output document. (The layout of individual pages is + accomplished by the layout managers page at a time; + i.e. they do not need to wait for the end of the page + sequence. The page may not yet be complete, however, + containing forward page number references, for example.) +

+
+
+ +
+