org.foray.render
Class Renderer

java.lang.Object
  extended by org.foray.output.OutputTarget
      extended by org.foray.render.Renderer
All Implemented Interfaces:
org.axsl.galley.RenderVisitor, org.axsl.output.OutputTarget, org.axsl.output.Renderer
Direct Known Subclasses:
AWTRenderer, PrintRenderer, SVGRenderer, XMLRenderer

public abstract class Renderer
extends OutputTarget
implements org.axsl.output.Renderer, org.axsl.galley.RenderVisitor

Abstract base class for all renderers. Subclasses produce output in some format from an AreaTree or AreaTree fragment.


Field Summary
protected static float SHADING_WEIGHT_BLUE
          Magic-number constant used in the conversion of color to gray.
protected static float SHADING_WEIGHT_GREEN
          Magic-number constant used in the conversion of color to gray.
protected static float SHADING_WEIGHT_RED
          Magic-number constant used in the conversion of color to gray.
 
Constructor Summary
Renderer(org.apache.commons.logging.Log logger)
          Constructor.
 
Method Summary
protected static float colorToFloat(int integralColorComponent)
          Converts a color value in the range 0 - 255 to its floating-point equivalant, that is, a value in the range 0 - 1.
static Rectangle2D.Float convertMillipointRectangle(Rectangle input)
          Converts a Rectangle storing millipoints to one storing points.
protected abstract  void drawGraphic(org.axsl.galley.GraphicArea area, org.axsl.graphic.Graphic image, Rectangle contentRectangle, Rectangle clipRectangle)
          Renders a Graphic to a given contentRectangle, and clipping it to a given clip rectangle.
protected abstract  void drawLine(int startX, int startY, int endX, int endY, int thickness, org.axsl.common.value.RuleStyle ruleStyle, Color strokeColor)
          Draw a line in the output document.
protected abstract  void drawRectangle(int x, int y, int w, int h, Color strokeColor, Color fillColor)
          Draw a rectangle in the output document.
protected  org.axsl.galley.Galley getAreaTree()
          Returns the area tree being rendered.
 int getPixelsPerInch()
          The pixel density, per inch, that should be used to compute image sizes when only the number of pixels is known.
protected  void markBackground(org.axsl.galley.BackgroundArea area)
          Renders an area's background, both image and color.
protected abstract  void markBorder(org.axsl.galley.BorderPaddingArea area)
          Marks the border, if any, for the given area.
 void render(org.axsl.galley.Area node)
           
 void render(org.axsl.galley.AreaNode node)
           
 void render(org.axsl.galley.BeforeFloatArea area)
           
 void render(org.axsl.galley.BlockContainerArea area)
           
abstract  void render(org.axsl.galley.BookmarkTree bookmarkTree)
          Render the bookmark tree for this document.
 void render(org.axsl.galley.ExternalGraphicArea area)
           
 void render(org.axsl.galley.FootnoteArea area)
           
abstract  void render(org.axsl.galley.ForeignContentMath mathContent)
          Render the MathML content of a ForeignObjectArea.
abstract  void render(org.axsl.galley.ForeignContentSvg svgContent)
          Render the SVG content of a ForeignObjectArea.
 void render(org.axsl.galley.ForeignObjectArea area)
           
 void render(org.axsl.galley.InlineArea area)
           
 void render(org.axsl.galley.LineArea area)
           
 void render(org.axsl.galley.MainReferenceArea area)
           
 void render(org.axsl.galley.NormalBlockArea area)
           
abstract  void render(org.axsl.galley.Page page)
           
 void render(org.axsl.galley.RegionArea area)
           
 void render(org.axsl.galley.TableArea area)
           
 void render(org.axsl.galley.TableCellArea area)
           
 void renderChildren(org.axsl.galley.AreaNode area)
          Render the children of a given node.
protected  void renderDocumentNodes()
          Renders all of the non-area AreaNodes, i.e.
protected  void renderRegions(org.axsl.galley.Page page)
          Render a page's region areas.
abstract  void renderTextSegment(org.axsl.galley.TextArea area, CharSequence text)
          Renders an arbitrary text chunk with attributes from an arbitrary Area.
abstract  void resetTextCursor()
          Provides the Renderer with an opportunity to close any text objects that are in progress.
 void setGalley(org.axsl.galley.Galley areaTree)
          Sets the AreaTree to be rendered.
protected static int shadingPercent(Color color)
          Converts a color to a percentage of black.
static float toPoints(int millipoints)
          Converts millipoints to points.
 
Methods inherited from class org.foray.output.OutputTarget
getApplicationName, getApplicationNameShort, getApplicationVersion, getDeveloperURLShort, getFontConsumer, getLogger, getOutputConfiguration, getOutputStream, getStrokeSVGText, outputStreamRequired, setApplicationName, setApplicationNameShort, setApplicationVersion, setDeveloperUrlShort, setFontConsumer, setOutputStream, setStrokeText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.axsl.output.OutputTarget
getFontSources, outputStreamRequired, setApplicationName, setApplicationNameShort, setApplicationVersion, setDeveloperUrlShort, setFontConsumer, setOutputStream, setStrokeText, startOutput, stopOutput
 
Methods inherited from interface org.axsl.galley.RenderVisitor
render, render
 

Field Detail

SHADING_WEIGHT_RED

protected static final float SHADING_WEIGHT_RED
Magic-number constant used in the conversion of color to gray.

See Also:
Constant Field Values

SHADING_WEIGHT_GREEN

protected static final float SHADING_WEIGHT_GREEN
Magic-number constant used in the conversion of color to gray.

See Also:
Constant Field Values

SHADING_WEIGHT_BLUE

protected static final float SHADING_WEIGHT_BLUE
Magic-number constant used in the conversion of color to gray.

See Also:
Constant Field Values
Constructor Detail

Renderer

public Renderer(org.apache.commons.logging.Log logger)
Constructor.

Parameters:
logger - The logger.
Method Detail

setGalley

public void setGalley(org.axsl.galley.Galley areaTree)
Sets the AreaTree to be rendered.

Specified by:
setGalley in interface org.axsl.output.Renderer
Parameters:
areaTree - The AreaTree to be rendered.

render

public abstract void render(org.axsl.galley.Page page)
                     throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.output.Renderer
Throws:
org.axsl.galley.GalleyVisitorException

markBorder

protected abstract void markBorder(org.axsl.galley.BorderPaddingArea area)
                            throws org.axsl.galley.GalleyVisitorException
Marks the border, if any, for the given area.

Parameters:
area - The area whose border is to be drawn.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

markBackground

protected void markBackground(org.axsl.galley.BackgroundArea area)
                       throws org.axsl.galley.GalleyVisitorException
Renders an area's background, both image and color.

Parameters:
area - The area whose background should be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

getPixelsPerInch

public int getPixelsPerInch()
The pixel density, per inch, that should be used to compute image sizes when only the number of pixels is known.

Returns:
The pixel density, per inch.

drawLine

protected abstract void drawLine(int startX,
                                 int startY,
                                 int endX,
                                 int endY,
                                 int thickness,
                                 org.axsl.common.value.RuleStyle ruleStyle,
                                 Color strokeColor)
                          throws org.axsl.galley.GalleyVisitorException
Draw a line in the output document.

Parameters:
startX - The start x location in millipoints.
startY - The start y location in millipoints.
endX - The end x location in millipoints.
endY - The end y location in millipoints.
thickness - The thickness in millipoints.
ruleStyle - The rule style.
strokeColor - The stroke color.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

drawRectangle

protected abstract void drawRectangle(int x,
                                      int y,
                                      int w,
                                      int h,
                                      Color strokeColor,
                                      Color fillColor)
                               throws org.axsl.galley.GalleyVisitorException
Draw a rectangle in the output document.

Parameters:
x - The x position of left edge in millipoints.
y - The y position of top edge in millipoints.
w - The width in millipoints.
h - The height in millipoints.
strokeColor - The color to be used for the stroke. Stroked means a box will be drawn around the rectangle. Set to null if the rectangle should not be stroked.
fillColor - The color to be used for the fill. Set to null if the rectangle should not be filled.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

drawGraphic

protected abstract void drawGraphic(org.axsl.galley.GraphicArea area,
                                    org.axsl.graphic.Graphic image,
                                    Rectangle contentRectangle,
                                    Rectangle clipRectangle)
                             throws org.axsl.galley.GalleyVisitorException
Renders a Graphic to a given contentRectangle, and clipping it to a given clip rectangle. If the content rectangle is the same as the intrinsic dimensions of the image, no scaling is done.

Parameters:
area - The Area instance from which to obtain traits.
image - The graphic to be rendered.
contentRectangle - The rectangle to which the graphic should be scaled during drawing.
clipRectangle - The rectangle to which the content should be clipped after any scaling.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.
See Also:
drawGraphic(GraphicArea, Graphic, Rectangle, Rectangle)

render

public void render(org.axsl.galley.AreaNode node)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.Area node)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

renderRegions

protected void renderRegions(org.axsl.galley.Page page)
                      throws org.axsl.galley.GalleyVisitorException
Render a page's region areas.

Parameters:
page - The page whose regions should be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

public void render(org.axsl.galley.BlockContainerArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.RegionArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

renderChildren

public void renderChildren(org.axsl.galley.AreaNode area)
                    throws org.axsl.galley.GalleyVisitorException
Render the children of a given node.

Parameters:
area - The area whose children should be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

public void render(org.axsl.galley.NormalBlockArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public abstract void render(org.axsl.galley.ForeignContentSvg svgContent)
                     throws org.axsl.galley.GalleyVisitorException
Render the SVG content of a ForeignObjectArea.

Parameters:
svgContent - The SVG content to be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

public abstract void render(org.axsl.galley.ForeignContentMath mathContent)
                     throws org.axsl.galley.GalleyVisitorException
Render the MathML content of a ForeignObjectArea.

Parameters:
mathContent - The MathML content to be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

public void render(org.axsl.galley.ForeignObjectArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.ExternalGraphicArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.TableArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.TableCellArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

renderTextSegment

public abstract void renderTextSegment(org.axsl.galley.TextArea area,
                                       CharSequence text)
                                throws org.axsl.galley.GalleyVisitorException
Renders an arbitrary text chunk with attributes from an arbitrary Area. Of course, ordinarily, the text will come from the Area, but the caller should decide that.

Parameters:
area - An Area instance that contains the traits that should be used to render the text.
text - The text content to be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

public void render(org.axsl.galley.LineArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public abstract void render(org.axsl.galley.BookmarkTree bookmarkTree)
Render the bookmark tree for this document.

Parameters:
bookmarkTree - The bookmark tree to be rendered.

render

public void render(org.axsl.galley.FootnoteArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.BeforeFloatArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.MainReferenceArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

render

public void render(org.axsl.galley.InlineArea area)
            throws org.axsl.galley.GalleyVisitorException
Specified by:
render in interface org.axsl.galley.RenderVisitor
Throws:
org.axsl.galley.GalleyVisitorException

renderDocumentNodes

protected void renderDocumentNodes()
                            throws org.axsl.galley.GalleyVisitorException
Renders all of the non-area AreaNodes, i.e. those AreaTree nodes that are direct children of AreaTree instead of a PageCollection. This includes items like Destinations and Bookmarks.

Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

resetTextCursor

public abstract void resetTextCursor()
Provides the Renderer with an opportunity to close any text objects that are in progress.


convertMillipointRectangle

public static Rectangle2D.Float convertMillipointRectangle(Rectangle input)
Converts a Rectangle storing millipoints to one storing points.

Parameters:
input - A rectangle whose dimensions are stored as millipoints.
Returns:
A new rectangle whose dimensions are stored as points.

toPoints

public static float toPoints(int millipoints)
Converts millipoints to points.

Parameters:
millipoints - The millipoint value to be converted to points.
Returns:
The converted value in points.

colorToFloat

protected static float colorToFloat(int integralColorComponent)
Converts a color value in the range 0 - 255 to its floating-point equivalant, that is, a value in the range 0 - 1.

Parameters:
integralColorComponent - The integral color value to be converted, a value in the range 0 - 255.
Returns:
The floating point value, a value in the range 0 - 1.

shadingPercent

protected static int shadingPercent(Color color)
Converts a color to a percentage of black.

Parameters:
color - The color to be converted.
Returns:
A value in the range 0 to 100, representing a percentage of black for this color.

getAreaTree

protected org.axsl.galley.Galley getAreaTree()
Returns the area tree being rendered.

Returns:
The area tree being rendered.


Copyright © 2017. All rights reserved.