Class PDF2Output
- java.lang.Object
-
- org.faceless.graph.output.Output
-
- org.faceless.graph.output.PDF2Output
-
public class PDF2Output extends Output
This class renders the graph to a PDF document defined using the Big Faceless PDF library, our companion product available from http://big.faceless.org/products/pdf. As you would expect, this is our recommended solution for rendering graphs to PDF documents. Here is an example which does just this, rendering a graph to a one-page PDF document:
Graph g = makeMyGraph(); // Left as exercise for the reader. PDF p = new PDF(); PDFPage page = p.newPage(PDF.PAGESIZE_A4); Output out = new PDFOutput(page, 100,100,400,400); out.render(g); p.render(new FileOutputStream("graph.pdf"));
Since version 1.0.3, this class no longer requires the AWT classes to run. Rather than being tied to the java.awt.Font class, developers now reference the fonts by name. Recognised fonts are:
- Helvetica
- Times
- Courier
- Symbol
- ZapfDingbats
- STSong
- MSung
- MHei
- HeiseiMin
- HeiseiKakuGo
- HYGoThic
- HYSMyeongJo
In addition, for backwards compatibility the names "monospaced", "serif" and "sans-serif" are mapped to Courier, Times and Helvetica respectively.
Custom fonts can be set using the setFontMap method, which replaces the getFontMap method defined in 1.0.2 and earlier.
-
-
Constructor Summary
Constructors Constructor Description PDF2Output(PDFPage p, float left, float top, float right, float bottom)
Create a new PDFOutput class to render the graph to the specified page.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canPattern()
Return true if this subclass out Output can handle pattern fills.boolean
canRotate()
Returns true if this subclass can handle rotated text (it can, so it does)BoundingBox
getCanvas()
Return the canvas as aBoundingBox
.Graph
getGraph()
Return the graph being rendered.BoundingBox
getTextBox(java.lang.String text, Style s)
Return the bounding box for given string in the specified style.void
line(double x1, double y1, double x2, double y2)
Draw a line from x1,y1 to x2,y2 on the canvas, in the current colourvoid
poly(java.lang.String name, double[] x, double[] y, int num)
Draw and fill a polygon on the canvas, in the current colour.void
render(Graph gr)
Render the Graph to this Output object.void
setColor(java.awt.Paint s)
Set the current pen, font and fill colourvoid
setFontMap(java.lang.String name, int style, PDFFont font)
Define a custom font for use with this output class.void
setLineDash(double on, double off, double phase)
Set the line dash patternvoid
setLineThickness(double thickness)
Set the line thickness (1 being default, 2 twice as thick, etc.) on platforms that support it.void
text(java.lang.String text, double x, double y, Style s)
Draw a line of text at the specified position in the specified style.-
Methods inherited from class org.faceless.graph.output.Output
getTextAnchor, rotate
-
-
-
-
Constructor Detail
-
PDF2Output
public PDF2Output(PDFPage p, float left, float top, float right, float bottom)
Create a new PDFOutput class to render the graph to the specified page. This class assumes that the page has the default canvas settings - i.e. it's measured in points from the bottom left of the page.
- Parameters:
p
- aPDFpage
object measured in points from the bottom-leftleft
- the left margin of the graph, in points from the left of the pagebottom
- the bottom margin of the graph, in points from the bottom of the pagewidth
- the width of the graph in pointsheight
- the height of the graph in points
-
-
Method Detail
-
canRotate
public final boolean canRotate()
Returns true if this subclass can handle rotated text (it can, so it does)
-
canPattern
public final boolean canPattern()
Description copied from class:Output
Return true if this subclass out Output can handle pattern fills.- Specified by:
canPattern
in classOutput
-
render
public void render(Graph gr)
Description copied from class:Output
Render the Graph to this Output object.
-
getGraph
public Graph getGraph()
Description copied from class:Output
Return the graph being rendered. For internal use.
-
getCanvas
public BoundingBox getCanvas()
Description copied from class:Output
Return the canvas as aBoundingBox
. The final graph will be sized to fit this box.
-
setLineThickness
public void setLineThickness(double thickness)
Description copied from class:Output
Set the line thickness (1 being default, 2 twice as thick, etc.) on platforms that support it.- Specified by:
setLineThickness
in classOutput
-
setLineDash
public void setLineDash(double on, double off, double phase)
Description copied from class:Output
Set the line dash pattern- Specified by:
setLineDash
in classOutput
-
setColor
public void setColor(java.awt.Paint s)
Description copied from class:Output
Set the current pen, font and fill colour
-
line
public void line(double x1, double y1, double x2, double y2)
Description copied from class:Output
Draw a line from x1,y1 to x2,y2 on the canvas, in the current colour
-
poly
public void poly(java.lang.String name, double[] x, double[] y, int num)
Description copied from class:Output
Draw and fill a polygon on the canvas, in the current colour. The corners of the polygon are specified by the arrays of X and Y values. The polygon has no borders, and is filled with the current colour. Subclasses should handle the cases where several of the points are the same.- Specified by:
poly
in classOutput
- Parameters:
name
- The name of the dataset that is being drawn. Not used in the current release, but will eventually be user for interaction with rendered graphsx
- the array of X co-ordinatesy
- the array of Y co-ordinatesnum
- the number of co-ordinates in the array
-
setFontMap
public void setFontMap(java.lang.String name, int style, PDFFont font)
Define a custom font for use with this output class. Here's an example:setFontMap("myfont", java.awt.Font.PLAIN, new OpenTypeFont("myfont.ttf", 1));
- Since:
- 1.0.3
-
getTextBox
public BoundingBox getTextBox(java.lang.String text, Style s)
Description copied from class:Output
Return the bounding box for given string in the specified style.- Specified by:
getTextBox
in classOutput
- Parameters:
text
- The string to return the size for.s
- The style to apply to the text before returning it's size. The aspects of the style that may affect this include font, rotation and alignment
-
-