Class AbstractRenderer

  • All Implemented Interfaces:
    Constants, Renderer
    Direct Known Subclasses:
    PrintRenderer

    public abstract class AbstractRenderer
    extends java.lang.Object
    implements Renderer, Constants
    Abstract base class for all renderers. The Abstract renderer does all the top level processing of the area tree and adds some abstract methods to handle viewports. This keeps track of the current block and inline position.
    • Field Detail

      • log

        protected static final org.apache.commons.logging.Log log
        logging instance
      • userAgent

        protected FOUserAgent userAgent
        user agent
      • currentBPPosition

        protected int currentBPPosition
        block progression position
      • currentIPPosition

        protected int currentIPPosition
        inline progression position
      • containingBPPosition

        protected int containingBPPosition
        the block progression position of the containing block used for absolutely positioned blocks
      • containingIPPosition

        protected int containingIPPosition
        the inline progression position of the containing block used for absolutely positioned blocks
      • currentPageViewport

        protected PageViewport currentPageViewport
        the currently active PageViewport
    • Constructor Detail

      • AbstractRenderer

        public AbstractRenderer​(FOUserAgent userAgent)
        Parameters:
        userAgent - the user agent that contains configuration details. This cannot be null.
    • Method Detail

      • setupFontInfo

        public abstract void setupFontInfo​(FontInfo fontInfo)
                                    throws FOPException
        Set up the given FontInfo.
        Specified by:
        setupFontInfo in interface Renderer
        Parameters:
        fontInfo - The font information
        Throws:
        FOPException - if an error occurs while setting up the font info object
      • getUserAgent

        public FOUserAgent getUserAgent()
        Returns the associated user agent.
        Specified by:
        getUserAgent in interface Renderer
        Returns:
        the user agent
      • startRenderer

        public void startRenderer​(java.io.OutputStream outputStream)
                           throws java.io.IOException
        Initiates the rendering phase. This must only be called once for a rendering. If stopRenderer is called then this may be called again for a new document rendering.
        Specified by:
        startRenderer in interface Renderer
        Parameters:
        outputStream - The OutputStream to use for output
        Throws:
        java.io.IOException - If an I/O error occurs
      • stopRenderer

        public void stopRenderer()
                          throws java.io.IOException
        Signals the end of the rendering phase. The renderer should reset to an initial state and dispose of any resources for the completed rendering.
        Specified by:
        stopRenderer in interface Renderer
        Throws:
        java.io.IOException - If an I/O error occurs
      • supportsOutOfOrder

        public boolean supportsOutOfOrder()
        Check if this renderer supports out of order rendering. If this renderer supports out of order rendering then it means that the pages that are not ready will be prepared and a future page will be rendered.
        Specified by:
        supportsOutOfOrder in interface Renderer
        Returns:
        True if the renderer supports out of order rendering
      • setDocumentLocale

        public void setDocumentLocale​(java.util.Locale locale)
        Specified by:
        setDocumentLocale in interface Renderer
        Parameters:
        locale - Locale of the language
      • processOffDocumentItem

        public void processOffDocumentItem​(OffDocumentItem odi)
        Tells the renderer to process an item not explicitly placed on the document (e.g., PDF bookmarks). Note - not all renderers will process all off-document items.
        Specified by:
        processOffDocumentItem in interface Renderer
        Parameters:
        odi - The off-document item to be rendered
      • getImageAdapter

        public ImageAdapter getImageAdapter()
        Specified by:
        getImageAdapter in interface Renderer
        Returns:
        the adapter for painting RenderedImages (or null if not supported)
      • getCurrentPageViewport

        protected PageViewport getCurrentPageViewport()
        Returns:
        the current PageViewport or null, if none is active
      • preparePage

        public void preparePage​(PageViewport page)
        This is called if the renderer supports out of order rendering. The renderer should prepare the page so that a page further on in the set of pages can be rendered. The body of the page should not be rendered. The page will be rendered at a later time by the call to Renderer.renderPage(PageViewport).
        Specified by:
        preparePage in interface Renderer
        Parameters:
        page - The page viewport to use
      • convertTitleToString

        protected java.lang.String convertTitleToString​(LineArea title)
        Utility method to convert a page sequence title to a string. Some renderers may only be able to use a string title. A title is a sequence of inline areas that this method attempts to convert to an equivalent string.
        Parameters:
        title - The Title to convert
        Returns:
        An expanded string representing the title
      • startPageSequence

        public void startPageSequence​(LineArea seqTitle)
        Deprecated.
        Tells the renderer that a new page sequence starts.
        Specified by:
        startPageSequence in interface Renderer
        Parameters:
        seqTitle - The title of the page sequence
      • startPageSequence

        public void startPageSequence​(PageSequence pageSequence)
        Tells the renderer that a new page sequence starts.
        Specified by:
        startPageSequence in interface Renderer
        Parameters:
        pageSequence - the page sequence
      • renderPage

        public void renderPage​(PageViewport page)
                        throws java.io.IOException,
                               FOPException
        Tells the renderer to render a particular page. A renderer typically responds by packing up the current page and writing it immediately to the output device.
        Specified by:
        renderPage in interface Renderer
        Parameters:
        page - The page to be rendered
        Throws:
        java.io.IOException - if an I/O error occurs
        FOPException - if a FOP interal error occurs.
      • renderPageAreas

        protected void renderPageAreas​(Page page)
        Renders page areas.
        Parameters:
        page - The page whos page areas are to be rendered
      • renderRegionViewport

        protected void renderRegionViewport​(RegionViewport port)
        Renders a region viewport.

        The region may clip the area and it establishes a position from where the region is placed.

        Parameters:
        port - The region viewport to be rendered
      • startVParea

        protected abstract void startVParea​(CTM ctm,
                                            java.awt.Rectangle clippingRect)
        Establishes a new viewport area.
        Parameters:
        ctm - the coordinate transformation matrix to use
        clippingRect - the clipping rectangle if the viewport should be clipping, null if no clipping is performed.
      • endVParea

        protected abstract void endVParea()
        Signals exit from a viewport area. Subclasses can restore transformation matrices valid before the viewport area was started.
      • handleRegionTraits

        protected void handleRegionTraits​(RegionViewport rv)
        Handle the traits for a region This is used to draw the traits for the given page region. (See Sect. 6.4.1.2 of XSL-FO spec.)
        Parameters:
        rv - the RegionViewport whose region is to be drawn
      • renderRegion

        protected void renderRegion​(RegionReference region)
        Renders a region reference area.
        Parameters:
        region - The region reference area
      • renderBodyRegion

        protected void renderBodyRegion​(BodyRegion region)
        Renders a body region area.
        Parameters:
        region - The body region
      • renderBeforeFloat

        protected void renderBeforeFloat​(BeforeFloat bf)
        Renders a before float area.
        Parameters:
        bf - The before float area
      • renderFootnote

        protected void renderFootnote​(Footnote footnote)
        Renders a footnote
        Parameters:
        footnote - The footnote
      • renderMainReference

        protected void renderMainReference​(MainReference mr)
        Renders the main reference area.

        The main reference area contains a list of spans that are stacked on the page. The spans contain a list of normal flow reference areas that are positioned into columns.

        Parameters:
        mr - The main reference area
      • renderFlow

        protected void renderFlow​(NormalFlow flow)
        Renders a flow reference area.
        Parameters:
        flow - The flow reference area
      • handleBlockTraits

        protected void handleBlockTraits​(Block block)
        Handle block traits. This method is called when the correct ip and bp posiiton is set. This should be overridden to draw border and background traits for the block area.
        Parameters:
        block - the block area
      • renderBlockViewport

        protected void renderBlockViewport​(BlockViewport bv,
                                           java.util.List children)
        Renders a block viewport.
        Parameters:
        bv - The block viewport
        children - The children to render within the block viewport
      • renderReferenceArea

        protected abstract void renderReferenceArea​(Block block)
        Renders a block area that represents a reference area. The reference area establishes a new coordinate system.
        Parameters:
        block - the block area
      • renderBlocks

        protected void renderBlocks​(Block parent,
                                    java.util.List blocks)
        Renders a list of block areas.
        Parameters:
        parent - the parent block if the parent is a block, otherwise a null value.
        blocks - The block areas
      • renderBlock

        protected void renderBlock​(Block block)
        Renders a block area.
        Parameters:
        block - The block area
      • startLayer

        protected abstract void startLayer​(java.lang.String layer)
        Establish new optional content group layer.
        Parameters:
        layer - name of layer
      • endLayer

        protected abstract void endLayer()
        Finish current optional content group layer.
      • maybeStartLayer

        protected boolean maybeStartLayer​(Area area)
      • maybeEndLayer

        protected void maybeEndLayer​(Area area,
                                     boolean inNewLayer)
      • renderLineArea

        protected void renderLineArea​(LineArea line)
        Renders a line area.

        A line area may have grouped styling for its children such as underline, background.

        Parameters:
        line - The line area
      • renderInlineArea

        protected void renderInlineArea​(InlineArea inlineArea)
        Render the given InlineArea.
        Parameters:
        inlineArea - inline area text to render
      • renderInlineAreaBackAndBorders

        protected abstract void renderInlineAreaBackAndBorders​(InlineArea area)
        Common method to render the background and borders for any inline area. The all borders and padding are drawn outside the specified area.
        Parameters:
        area - the inline area for which the background, border and padding is to be rendered
      • renderInlineSpace

        protected void renderInlineSpace​(Space space)
        Render the given Space.
        Parameters:
        space - the space to render
      • renderLeader

        protected void renderLeader​(Leader area)
        Render the given Leader.
        Parameters:
        area - the leader to render
      • renderText

        protected void renderText​(TextArea text)
        Render the given TextArea.
        Parameters:
        text - the text to render
      • renderWord

        protected void renderWord​(WordArea word)
        Render the given WordArea.
        Parameters:
        word - the word to render
      • renderSpace

        protected void renderSpace​(SpaceArea space)
        Render the given SpaceArea.
        Parameters:
        space - the space to render
      • renderInlineParent

        protected void renderInlineParent​(InlineParent ip)
        Render the given InlineParent.
        Parameters:
        ip - the inline parent to render
      • renderInlineBlockParent

        protected void renderInlineBlockParent​(InlineBlockParent ibp)
        Render the given InlineBlockParent.
        Parameters:
        ibp - the inline block parent to render
      • renderInlineViewport

        protected void renderInlineViewport​(InlineViewport viewport)
        Render the given Viewport.
        Parameters:
        viewport - the viewport to render
      • renderImage

        public void renderImage​(Image image,
                                java.awt.geom.Rectangle2D pos)
        Renders an image area.
        Parameters:
        image - The image
        pos - The target position of the image (todo) Make renderImage() protected
      • renderContainer

        protected void renderContainer​(Container cont)
        Tells the renderer to render an inline container.
        Parameters:
        cont - The inline container area
      • renderForeignObject

        protected void renderForeignObject​(ForeignObject fo,
                                           java.awt.geom.Rectangle2D pos)
        Renders a foreign object area.
        Parameters:
        fo - The foreign object area
        pos - The target position of the foreign object (todo) Make renderForeignObject() protected
      • renderXML

        public void renderXML​(RendererContext ctx,
                              org.w3c.dom.Document doc,
                              java.lang.String namespace)
        Render the xml document with the given xml namespace. The Render Context is by the handle to render into the current rendering target.
        Parameters:
        ctx - rendering context
        doc - DOM Document containing the source document
        namespace - Namespace URI of the document
      • mptToPt

        protected java.awt.geom.AffineTransform mptToPt​(java.awt.geom.AffineTransform at)
        Converts a millipoint-based transformation matrix to points.
        Parameters:
        at - a millipoint-based transformation matrix
        Returns:
        a point-based transformation matrix
      • ptToMpt

        protected java.awt.geom.AffineTransform ptToMpt​(java.awt.geom.AffineTransform at)
        Converts a point-based transformation matrix to millipoints.
        Parameters:
        at - a point-based transformation matrix
        Returns:
        a millipoint-based transformation matrix