org.foray.render.awt
Class AWTRenderer

java.lang.Object
  extended by org.foray.output.OutputTarget
      extended by org.foray.render.Renderer
          extended by org.foray.render.awt.AWTRenderer
All Implemented Interfaces:
Pageable, Printable, org.axsl.galley.RenderVisitor, org.axsl.output.OutputTarget, org.axsl.output.Renderer
Direct Known Subclasses:
AWTPrintRenderer

public class AWTRenderer
extends Renderer
implements Printable, Pageable

A Renderer that displays the document using AWT.


Field Summary
 
Fields inherited from class org.foray.render.Renderer
SHADING_WEIGHT_BLUE, SHADING_WEIGHT_GREEN, SHADING_WEIGHT_RED
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Constructor Summary
AWTRenderer(org.apache.commons.logging.Log logger, org.axsl.output.OutputConfiguration renderConfig)
          Constructor.
 
Method Summary
protected  void addRect(int x, int y, int w, int h, boolean drawAsOutline)
          Draw a filled rectangle in the current color.
protected  void addRect(int x, int y, int w, int h, float r, float g, float b)
          Draw a rectangle.
protected  void addRect(int x, int y, int w, int h, float r, float g, float b, float fr, float fg, float fb)
          Draw a filled rectangle.
protected  void drawFrame()
          Draws a frame around the page.
protected  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  void drawLine(int x1, int y1, int x2, int y2, int th, org.axsl.common.value.RuleStyle ruleStyle, Color strokeColor)
          Draw a line in the output document.
protected  void drawRectangle(int x, int y, int w, int h, Color strokeColor, Color fillColor)
          Draw a rectangle in the output document.
 int[] getFontSources()
           
 BufferedImage getLastRenderedPage()
          Return the last page rendered.
 int getNumberOfPages()
           
 org.axsl.output.OutputConfiguration getOutputConfiguration()
          Returns the output configuration for this renderer.
 int getPageCount()
          Retrieve the number of pages in this document.
 PageFormat getPageFormat(int pageIndex)
           
 int getPageNumber()
          Returns the current page number.
 Printable getPrintable(int pageIndex)
           
 double getScaleFactor()
          Returns the current scale factor.
protected  void markBorder(org.axsl.galley.BorderPaddingArea area)
          Marks the border, if any, for the given area.
 boolean outputStreamRequired()
           Subclasses that do not need an OutputStream should override this.
 int print(Graphics g, PageFormat pageFormat, int pageIndex)
           
 void removePage(int page)
          Removes a page from the list of processed pages.
 void render(org.axsl.galley.BookmarkTree area)
          Render the bookmark tree for this document.
 void render(org.axsl.galley.ExternalGraphicArea area)
           
 void render(org.axsl.galley.ForeignContentMath area)
          Render the MathML content of a ForeignObjectArea.
 void render(org.axsl.galley.ForeignContentSvg area)
          Render the SVG content of a ForeignObjectArea.
 void render(int aPageNumber)
          Renders a page.
 void render(org.axsl.galley.LeaderArea area)
           
 void render(org.axsl.galley.Page page)
           
 void render(org.axsl.galley.TextArea area)
           
protected  void renderPage(org.axsl.galley.Page page)
          Renders a given page.
protected  void renderSVGDocument(org.axsl.graphic.SvgGraphic graphic, Rectangle2D.Float contentRectangle, Rectangle2D.Float clipRectangle)
          Renders an SVG document.
protected  void renderTextDecoration(int x, int bl, int width, Font font, String text, boolean underline, boolean overline, boolean linethrough)
          Renders text with its text decoration.
 void renderTextSegment(org.axsl.galley.TextArea area, CharSequence text)
          Renders an arbitrary text chunk with attributes from an arbitrary Area.
 void resetTextCursor()
          Provides the Renderer with an opportunity to close any text objects that are in progress.
 void setComponent(Component parent)
          Sets parent component which is used to set up the font.
 void setPageHeight(int pageHeight)
          Sets the page height.
 void setPageNumber(int aValue)
          Sets the current page number.
 void setPageWidth(int pageWidth)
          Sets the page width.
 void setScaleFactor(double newScaleFactor)
          Sets the current scale factor.
 void startOutput()
           
 void stopOutput()
           
 
Methods inherited from class org.foray.render.Renderer
colorToFloat, convertMillipointRectangle, getAreaTree, getPixelsPerInch, markBackground, render, render, render, render, render, render, render, render, render, render, render, render, render, renderChildren, renderDocumentNodes, renderRegions, setGalley, shadingPercent, toPoints
 
Methods inherited from class org.foray.output.OutputTarget
getApplicationName, getApplicationNameShort, getApplicationVersion, getDeveloperURLShort, getFontConsumer, getLogger, getOutputStream, getStrokeSVGText, 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
setApplicationName, setApplicationNameShort, setApplicationVersion, setDeveloperUrlShort, setFontConsumer, setOutputStream, setStrokeText
 

Constructor Detail

AWTRenderer

public AWTRenderer(org.apache.commons.logging.Log logger,
                   org.axsl.output.OutputConfiguration renderConfig)
Constructor.

Parameters:
logger - The logger.
renderConfig - The configuration for this renderer.
Method Detail

setComponent

public void setComponent(Component parent)
Sets parent component which is used to set up the font. This is needed as FontSetup needs a live AWT component in order to generate valid font measures.

Parameters:
parent - the live AWT component reference

getPageNumber

public int getPageNumber()
Returns the current page number.

Returns:
The current page number.

setPageNumber

public void setPageNumber(int aValue)
Sets the current page number.

Parameters:
aValue - The new page number.

setScaleFactor

public void setScaleFactor(double newScaleFactor)
Sets the current scale factor.

Parameters:
newScaleFactor - The new scale factor.

getScaleFactor

public double getScaleFactor()
Returns the current scale factor.

Returns:
The current scale factor.

getLastRenderedPage

public BufferedImage getLastRenderedPage()
Return the last page rendered.

Returns:
The last page rendered.

drawLine

protected void drawLine(int x1,
                        int y1,
                        int x2,
                        int y2,
                        int th,
                        org.axsl.common.value.RuleStyle ruleStyle,
                        Color strokeColor)
Description copied from class: Renderer
Draw a line in the output document.

Specified by:
drawLine in class Renderer
Parameters:
x1 - The start x location in millipoints.
y1 - The start y location in millipoints.
x2 - The end x location in millipoints.
y2 - The end y location in millipoints.
th - The thickness in millipoints.
ruleStyle - The rule style.
strokeColor - The stroke color.

drawRectangle

protected void drawRectangle(int x,
                             int y,
                             int w,
                             int h,
                             Color strokeColor,
                             Color fillColor)
Description copied from class: Renderer
Draw a rectangle in the output document.

Specified by:
drawRectangle in class Renderer
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.

addRect

protected void addRect(int x,
                       int y,
                       int w,
                       int h,
                       float r,
                       float g,
                       float b)
Draw a rectangle.

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
r - the red component
g - the green component
b - the blue component

addRect

protected void addRect(int x,
                       int y,
                       int w,
                       int h,
                       float r,
                       float g,
                       float b,
                       float fr,
                       float fg,
                       float fb)
Draw a filled rectangle.

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
r - the red component of edges
g - the green component of edges
b - the blue component of edges
fr - the red component of the fill
fg - the green component of the fill
fb - the blue component of the fill

addRect

protected void addRect(int x,
                       int y,
                       int w,
                       int h,
                       boolean drawAsOutline)
Draw a filled rectangle in the current color. This is a helper function to correct integer rounding problems.

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
drawAsOutline - true for draw, false for fill

drawFrame

protected void drawFrame()
Draws a frame around the page.


getPageCount

public int getPageCount()
Retrieve the number of pages in this document.

Returns:
the number of pages

removePage

public void removePage(int page)
Removes a page from the list of processed pages.

Parameters:
page - The index to the page to be removed.

render

public void render(int aPageNumber)
            throws org.axsl.galley.GalleyVisitorException
Renders a page.

Parameters:
aPageNumber - The index to the page to be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

render

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

renderPage

protected void renderPage(org.axsl.galley.Page page)
                   throws org.axsl.galley.GalleyVisitorException
Renders a given page.

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

markBorder

protected void markBorder(org.axsl.galley.BorderPaddingArea area)
Description copied from class: Renderer
Marks the border, if any, for the given area.

Specified by:
markBorder in class Renderer
Parameters:
area - The area whose border is to be drawn.

drawGraphic

protected void drawGraphic(org.axsl.galley.GraphicArea area,
                           org.axsl.graphic.Graphic image,
                           Rectangle contentRectangle,
                           Rectangle clipRectangle)
Description copied from class: Renderer
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.

Specified by:
drawGraphic in class Renderer
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.
See Also:
Renderer.drawGraphic(GraphicArea, Graphic, Rectangle, Rectangle)

render

public void render(org.axsl.galley.ExternalGraphicArea area)
Specified by:
render in interface org.axsl.galley.RenderVisitor
Overrides:
render in class Renderer

renderTextSegment

public void renderTextSegment(org.axsl.galley.TextArea area,
                              CharSequence text)
Description copied from class: Renderer
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.

Specified by:
renderTextSegment in class Renderer
Parameters:
area - An Area instance that contains the traits that should be used to render the text.
text - The text content to be rendered.

renderTextDecoration

protected void renderTextDecoration(int x,
                                    int bl,
                                    int width,
                                    Font font,
                                    String text,
                                    boolean underline,
                                    boolean overline,
                                    boolean linethrough)
Renders text with its text decoration.

Parameters:
x - The x coordinate of the location at which rendering should occur, in millipoints.
bl - The y coordinate of the location at which rendering should occur, in millipoints.
width - The width of the text, in millipoints.
font - The font to be used to draw the text.
text - The text to be written.
underline - True if the text should be underlined.
overline - True if the text should be overlined.
linethrough - True if the text should have a line drawn through it.

render

public void render(org.axsl.galley.LeaderArea area)
Specified by:
render in interface org.axsl.galley.RenderVisitor

render

public void render(org.axsl.galley.TextArea area)
Specified by:
render in interface org.axsl.galley.RenderVisitor

render

public void render(org.axsl.galley.ForeignContentSvg area)
Description copied from class: Renderer
Render the SVG content of a ForeignObjectArea.

Specified by:
render in class Renderer
Parameters:
area - The SVG content to be rendered.

renderSVGDocument

protected void renderSVGDocument(org.axsl.graphic.SvgGraphic graphic,
                                 Rectangle2D.Float contentRectangle,
                                 Rectangle2D.Float clipRectangle)
Renders an SVG document.

Parameters:
graphic - The SVG 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.

render

public void render(org.axsl.galley.ForeignContentMath area)
Description copied from class: Renderer
Render the MathML content of a ForeignObjectArea.

Specified by:
render in class Renderer
Parameters:
area - The MathML content to be rendered.

render

public void render(org.axsl.galley.BookmarkTree area)
Description copied from class: Renderer
Render the bookmark tree for this document.

Specified by:
render in class Renderer
Parameters:
area - The bookmark tree to be rendered.

print

public int print(Graphics g,
                 PageFormat pageFormat,
                 int pageIndex)
          throws PrinterException
Specified by:
print in interface Printable
Throws:
PrinterException

getNumberOfPages

public int getNumberOfPages()
Specified by:
getNumberOfPages in interface Pageable

getPageFormat

public PageFormat getPageFormat(int pageIndex)
Specified by:
getPageFormat in interface Pageable

getPrintable

public Printable getPrintable(int pageIndex)
Specified by:
getPrintable in interface Pageable

startOutput

public void startOutput()
                 throws org.axsl.output.OutputException
Specified by:
startOutput in interface org.axsl.output.OutputTarget
Throws:
org.axsl.output.OutputException

stopOutput

public void stopOutput()
                throws org.axsl.output.OutputException
Specified by:
stopOutput in interface org.axsl.output.OutputTarget
Throws:
org.axsl.output.OutputException

getFontSources

public int[] getFontSources()
Specified by:
getFontSources in interface org.axsl.output.OutputTarget

resetTextCursor

public void resetTextCursor()
Description copied from class: Renderer
Provides the Renderer with an opportunity to close any text objects that are in progress.

Specified by:
resetTextCursor in class Renderer

outputStreamRequired

public boolean outputStreamRequired()
Subclasses that do not need an OutputStream should override this.

Specified by:
outputStreamRequired in interface org.axsl.output.OutputTarget
Overrides:
outputStreamRequired in class OutputTarget
Returns:
False. This renderer does not require an OutputStream.

setPageWidth

public void setPageWidth(int pageWidth)
Sets the page width.

Parameters:
pageWidth - The pageWidth to set.

setPageHeight

public void setPageHeight(int pageHeight)
Sets the page height.

Parameters:
pageHeight - The pageHeight to set.

getOutputConfiguration

public org.axsl.output.OutputConfiguration getOutputConfiguration()
Description copied from class: OutputTarget
Returns the output configuration for this renderer.

Specified by:
getOutputConfiguration in class OutputTarget
Returns:
The output configuration for this renderer.


Copyright © 2017. All rights reserved.