org.foray.render.ps
Class PSRenderer

java.lang.Object
  extended by org.foray.output.OutputTarget
      extended by org.foray.render.Renderer
          extended by org.foray.render.PrintRenderer
              extended by org.foray.render.ps.PSRenderer
All Implemented Interfaces:
org.axsl.galley.RenderVisitor, org.axsl.graphic.output.GraphicOutputContext, org.axsl.output.OutputTarget, org.axsl.output.Renderer

public class PSRenderer
extends PrintRenderer
implements org.axsl.graphic.output.GraphicOutputContext

Renderer that renders to PostScript.
This class currently generates PostScript Level 2 code. The only exception is the FlateEncode filter which is a Level 3 feature. The PostScript code generated follows the Document Structuring Conventions (DSC) version 3.0.


Field Summary
 
Fields inherited from class org.foray.render.Renderer
SHADING_WEIGHT_BLUE, SHADING_WEIGHT_GREEN, SHADING_WEIGHT_RED
 
Constructor Summary
PSRenderer(org.apache.commons.logging.Log logger, org.axsl.output.DocumentConfiguration renderConfig, org.axsl.ps.PsServer psServer)
          Constructor.
 
Method Summary
protected  void addFilledRect(int x, int y, int w, int h, Color col)
          Draw a filled rectangle.
protected  void comment(String comment)
          Write out a comment, iff comments are enabled.
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 drawImageClipped(org.axsl.galley.GraphicArea area, org.axsl.graphic.Graphic image, int x, int y, int clipW, int clipH)
          Draw a given image, clipping it to a given rectangle.
protected  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  void drawRectangle(int x, int y, int w, int h, Color strokeColor, Color fillColor)
          Draw a rectangle in the output document.
 byte[] epsToPostScript(org.axsl.graphic.EpsGraphic image, int x, int y, int w, int h)
          Converts an EPS graphic to the bytes that represent it in PostScript.
 String getFontName(org.axsl.font.FontUse fontUse)
           
 String getGradientName(org.axsl.common.Gradient gradient)
           
 org.axsl.output.DocumentConfiguration getOutputConfiguration()
          Returns the output configuration for this renderer.
 int getPSLevel()
          Returns the PostScript level being used.
 boolean isAutoRotateLandscape()
          Indicates whether auto-rotate landscape is active.
protected  void markBorder(org.axsl.galley.BorderPaddingArea area)
          Marks the border, if any, for the given area.
 void render(org.axsl.galley.BookmarkTree area)
          Render the bookmark tree for this document.
 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(org.axsl.galley.LeaderArea area)
          Render a line area to PostScript.
 void render(org.axsl.galley.Page page)
           
 void renderBitmap(org.axsl.graphic.Graphic img, int x, int y, int w, int h)
          Renders a raster image to PostScript.
 void renderEPS(org.axsl.graphic.EpsGraphic img, int x, int y, int w, int h)
          Write an EPS graphic.
protected  void renderSVGDocument(org.axsl.graphic.SvgGraphic svgGraphic, Rectangle2D contentRectangle, org.axsl.galley.Area area)
          Render an SVG document to PostScript.
 void renderTextSegment(org.axsl.galley.TextArea area, CharSequence text)
          render an image area to PostScript
 void resetTextCursor()
          Provides the Renderer with an opportunity to close any text objects that are in progress.
 void setAutoRotateLandscape(boolean value)
          Sets the flag indicating whether auto-rotate landscape is active.
 void setPSLevel(int level)
          Sets the PostScript Level to generate.
 void startOutput()
           
 void stopOutput()
           
 void useFont(PSFont psFont, int size)
          Sets the font and/or font size to be used.
protected  void write(String cmd)
          Write out a command, appending a linefeed.
protected  void writeFontDict()
          Write the font dictionary.
protected  void writeProcs()
          Write the document procedures.
protected  void writeRaw(CharSequence cmd)
          Write out a command (with no linefeed appended).
 
Methods inherited from class org.foray.render.PrintRenderer
getFontSources, getOverlineYPosition, getThroughYPosition, getUnderlineYPosition, render, renderGenericSpace
 
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, render, renderChildren, renderDocumentNodes, renderRegions, setGalley, shadingPercent, toPoints
 
Methods inherited from class org.foray.output.OutputTarget
getApplicationName, getApplicationNameShort, getApplicationVersion, getDeveloperURLShort, getFontConsumer, getLogger, 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
outputStreamRequired, setApplicationName, setApplicationNameShort, setApplicationVersion, setDeveloperUrlShort, setFontConsumer, setOutputStream, setStrokeText
 

Constructor Detail

PSRenderer

public PSRenderer(org.apache.commons.logging.Log logger,
                  org.axsl.output.DocumentConfiguration renderConfig,
                  org.axsl.ps.PsServer psServer)
Constructor.

Parameters:
logger - The logger.
renderConfig - The configuration for this renderer.
psServer - The PostScript server to be used for this render process.
Method Detail

setPSLevel

public void setPSLevel(int level)
Sets the PostScript Level to generate.

Parameters:
level - You can specify either 2 or 3 for the PostScript Level

getPSLevel

public int getPSLevel()
Returns the PostScript level being used.

Returns:
The PostScript level being used.

setAutoRotateLandscape

public void setAutoRotateLandscape(boolean value)
Sets the flag indicating whether auto-rotate landscape is active.

Parameters:
value - The new auto-rotate landscape mode.

isAutoRotateLandscape

public boolean isAutoRotateLandscape()
Indicates whether auto-rotate landscape is active.

Returns:
True iff auto-rotate landscape is active.

write

protected void write(String cmd)
              throws IOException
Write out a command, appending a linefeed.

Parameters:
cmd - The PostScript command to write.
Throws:
IOException - For errors writing to output.

writeRaw

protected void writeRaw(CharSequence cmd)
                 throws IOException
Write out a command (with no linefeed appended).

Parameters:
cmd - The PostScript command to write.
Throws:
IOException - For errors writing to output.

comment

protected void comment(String comment)
                throws IOException
Write out a comment, iff comments are enabled.

Parameters:
comment - The comment to be written.
Throws:
IOException - For errors writing to output.

writeProcs

protected void writeProcs()
                   throws IOException
Write the document procedures.

Throws:
IOException - For errors writing to output.

writeFontDict

protected void writeFontDict()
                      throws IOException
Write the font dictionary.

Throws:
IOException - For errors writing to output.

drawLine

protected void drawLine(int startX,
                        int startY,
                        int endX,
                        int endY,
                        int thickness,
                        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:
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.

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.

addFilledRect

protected void addFilledRect(int x,
                             int y,
                             int w,
                             int h,
                             Color col)
                      throws IOException
Draw a filled rectangle.

Parameters:
x - The x coordinate of the rectangle.
y - The y coordinate of the rectangle.
w - The width of the rectangle.
h - The height of the rectangle.
col - The fill color.
Throws:
IOException - For errors writing to output.

render

public void render(org.axsl.galley.ForeignContentSvg area)
            throws org.axsl.galley.GalleyVisitorException
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.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

renderSVGDocument

protected void renderSVGDocument(org.axsl.graphic.SvgGraphic svgGraphic,
                                 Rectangle2D contentRectangle,
                                 org.axsl.galley.Area area)
                          throws IOException
Render an SVG document to PostScript.

Parameters:
svgGraphic - The SVG graphic to be rendered.
contentRectangle - The rectangle in which the content of the SVG should be rendered.
area - The area containing the graphic to be rendered.
Throws:
IOException - For errors writing to output.

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.

drawGraphic

protected void drawGraphic(org.axsl.galley.GraphicArea area,
                           org.axsl.graphic.Graphic image,
                           Rectangle contentRectangle,
                           Rectangle clipRectangle)
                    throws org.axsl.galley.GalleyVisitorException
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.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.
See Also:
Renderer.drawGraphic(GraphicArea, Graphic, Rectangle, Rectangle)

drawImageClipped

protected void drawImageClipped(org.axsl.galley.GraphicArea area,
                                org.axsl.graphic.Graphic image,
                                int x,
                                int y,
                                int clipW,
                                int clipH)
                         throws org.axsl.galley.GalleyVisitorException
Draw a given image, clipping it to a given rectangle.

Parameters:
area - The area containing the graphic.
image - The image to be drawn.
x - The x coordinate of the image.
y - The y coordinate of the image.
clipW - The width to which the image should be clipped.
clipH - The height to which the image should be clipped.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

renderEPS

public void renderEPS(org.axsl.graphic.EpsGraphic img,
                      int x,
                      int y,
                      int w,
                      int h)
               throws org.axsl.galley.GalleyVisitorException
Write an EPS graphic.

Parameters:
img - The EPS graphic to be drawn.
x - The x coordinate of the rectangle in which the graphic should be drawn.
y - The y coordinate of the rectangle in which the graphic should be drawn.
w - The width of the rectangle in which the graphic should be drawn.
h - The height of the rectangle in which the graphic should be drawn.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

epsToPostScript

public byte[] epsToPostScript(org.axsl.graphic.EpsGraphic image,
                              int x,
                              int y,
                              int w,
                              int h)
                       throws org.axsl.graphic.GraphicException
Converts an EPS graphic to the bytes that represent it in PostScript.

Parameters:
image - The EPS graphic to be converted.
x - The x coordinate of the rectangle in which the graphic should be drawn.
y - The y coordinate of the rectangle in which the graphic should be drawn.
w - The width of the rectangle in which the graphic should be drawn.
h - The height of the rectangle in which the graphic should be drawn.
Returns:
The byte array containing the graphic as PostScript.
Throws:
org.axsl.graphic.GraphicException - For errors processing the graphic.

renderBitmap

public void renderBitmap(org.axsl.graphic.Graphic img,
                         int x,
                         int y,
                         int w,
                         int h)
                  throws IOException
Renders a raster image to PostScript.

Parameters:
img - The image to be rendered.
x - The x coordinate of the rectangle in which the graphic should be drawn.
y - The y coordinate of the rectangle in which the graphic should be drawn.
w - The width of the rectangle in which the graphic should be drawn.
h - The height of the rectangle in which the graphic should be drawn.
Throws:
IOException - For errors writing to output.

renderTextSegment

public void renderTextSegment(org.axsl.galley.TextArea area,
                              CharSequence text)
                       throws org.axsl.galley.GalleyVisitorException
render an image area to PostScript

Specified by:
renderTextSegment in class Renderer
Parameters:
area - the area to render
text - The text content to be rendered.
Throws:
org.axsl.galley.GalleyVisitorException - For errors during rendering.

useFont

public void useFont(PSFont psFont,
                    int size)
             throws IOException
Sets the font and/or font size to be used.

Parameters:
psFont - The font to be used.
size - The font size to be used.
Throws:
IOException - For errors writing to output.

render

public void render(org.axsl.galley.LeaderArea area)
            throws org.axsl.galley.GalleyVisitorException
Render a line area to PostScript.

Specified by:
render in interface org.axsl.galley.RenderVisitor
Overrides:
render in class PrintRenderer
Parameters:
area - the area to render
Throws:
org.axsl.galley.GalleyVisitorException

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.

markBorder

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

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

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

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

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

getFontName

public String getFontName(org.axsl.font.FontUse fontUse)
Specified by:
getFontName in interface org.axsl.graphic.output.GraphicOutputContext

getGradientName

public String getGradientName(org.axsl.common.Gradient gradient)
Specified by:
getGradientName in interface org.axsl.graphic.output.GraphicOutputContext

getOutputConfiguration

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

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


Copyright © 2017. All rights reserved.