|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph.output.Output
org.faceless.graph.output.PDF2Output
public class PDF2Output
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:
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 | |
---|---|
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 | |
---|---|
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 a BoundingBox . |
Graph |
getGraph()
Return the graph being rendered. |
BoundingBox |
getTextBox(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 colour |
void |
poly(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(Paint s)
Set the current pen, font and fill colour |
void |
setFontMap(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 pattern |
void |
setLineThickness(double thickness)
Set the line thickness (1 being default, 2 twice as thick, etc.) on platforms that support it. |
void |
text(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 java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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.
p
- a PDFpage
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 pointsMethod Detail |
---|
public final boolean canRotate()
canRotate
in class Output
public final boolean canPattern()
Output
canPattern
in class Output
public void render(Graph gr)
Output
render
in class Output
public Graph getGraph()
Output
getGraph
in class Output
public BoundingBox getCanvas()
Output
BoundingBox
. The final graph
will be sized to fit this box.
getCanvas
in class Output
public void setLineThickness(double thickness)
Output
setLineThickness
in class Output
public void setLineDash(double on, double off, double phase)
Output
setLineDash
in class Output
public void setColor(Paint s)
Output
setColor
in class Output
public void line(double x1, double y1, double x2, double y2)
Output
line
in class Output
public void poly(String name, double[] x, double[] y, int num)
Output
poly
in class Output
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 arraypublic void setFontMap(String name, int style, PDFFont font)
setFontMap("myfont", java.awt.Font.PLAIN, new OpenTypeFont("myfont.ttf", 1));
public BoundingBox getTextBox(String text, Style s)
Output
getTextBox
in class Output
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 alignmentpublic void text(String text, double x, double y, Style s)
Output
text
in class Output
text
- The line of text to draw.x
- The x position to place the text at, measured from the
left of the canvas.y
- The y position to place the text at, measured from the
bottom of the canvas.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |