All Packages Class Hierarchy This Package Previous Next Index
Class Acme.Psg
java.lang.Object
|
+----Acme.Psg
- public class Psg
- extends Object
A PostScript-like alternative to the Graphics class.
This class provides a functional equivalent of java.awt.Graphics,
but with a very PostScript-like interface. It implements the following
PostScript operators:
gsave grestore grestoreall initgraphics setlinewidth setcolor setgray
sethsbcolor setrgbcolor translate scale rotate transform dtransform
itransform idtransform
newpath moveto rmoveto lineto rlineto arc arcn curveto rcurveto closepath
flattenpath clippath pathbbox
erasepage fill stroke
rectfill rectstroke
findfont scalefont setfont
show stringwidth
Not only is this a more powerful rendering idiom than the standard
Graphics class, but it also makes it hellof easy to translate
PostScript graphics hacks into Java. Here's a
sample:
JavaSoft and Adobe are said to be working on a 2-D rendering API
similar to PostScript, and therefore similar to this. When that
comes out this class will probably be obsolete, so I don't plan
on doing any major improvements.
Fetch the software.
Fetch the entire Acme package.
-
Psg(Component)
- Constructor from Component.
-
Psg(Graphics)
- Constructor from Graphics.
-
arc(double, double, double, double, double)
- Append counterclockwise arc.
-
arcn(double, double, double, double, double)
- Append clockwise arc.
-
clippath()
- Set the current path to the clipping path.
-
closepath()
- Connect current path back to its starting point.
-
curveto(double, double, double, double, double, double)
- Append a Bezier cubic section.
-
dtransform_x(double, double)
- Transform (dx, dy) into a device-space x-distance.
-
dtransform_y(double, double)
- Transform (dx, dy) into a device-space y-distance.
-
erasepage()
- Paint the whole graphics area with the background color.
-
fill()
- Fill current path with current color.
-
flattenpath()
- Convert curves in the path to sequences of straight lines.
-
grestore()
- Restore the last Save()ed graphics state.
-
grestoreall()
- Pop to bottom-most graphics state.
-
gsave()
- Save the current graphics state onto a stack.
-
idtransform_x(int, int)
- Inverse transform (dx, dy) into a user-space x-distance.
-
idtransform_y(int, int)
- Inverse transform (dx, dy) into a user-space y-distance.
-
initgraphics()
- Reset graphics state.
-
itransform_x(int, int)
- Inverse transform (x, y) into a user-space x-coordinate.
-
itransform_y(int, int)
- Inverse transform (x, y) into a user-space y-coordinate.
-
lineto(double, double)
- Add a line to the path.
-
main(String[])
- Test program.
-
moveto(double, double)
- Set the current point.
-
newpath()
- Start a new, empty path.
-
pathbbox()
- Return the bounding box of the current path.
-
rcurveto(double, double, double, double, double, double)
- Relative curveto.
-
rectfill(double, double, double, double)
- Fill a rectangular path.
-
rectstroke(double, double, double, double)
- Stroke a rectangular path.
-
rlineto(double, double)
- Relative lineto().
-
rmoveto(double, double)
- Relative moveto().
-
rotate(double)
- Rotate graphics space.
-
scale(double, double)
- Scale graphics space.
-
setcolor(Color)
- Set the current color.
-
setfont(String, int, double)
- Set the current font to the specified name, style, and size.
-
setfontName(String)
- Set the current font to the specified name.
-
setfontSize(double)
- Set the current font to the specified size.
-
setfontStyle(int)
- Set the current font to the specified style.
-
setgray(float)
- Set the color to the specified gray value (0=black, 1=white).
-
sethsbcolor(float, float, float)
- Set the color from HSB coordinates.
-
setlinewidth(double)
- Set the current line width.
-
setrgbcolor(float, float, float)
- Set the color from RGB coordinates.
-
show(String)
- Paint a string starting at the current point.
-
stringwidth_x(String)
- Return the x-width of a string.
-
stroke()
- Draw lines along the current path.
-
transform_x(double, double)
- Transform (x, y) into a device-space x-coordinate.
-
transform_y(double, double)
- Transform (x, y) into a device-space y-coordinate.
-
translate(double, double)
- Translate graphics space.
Psg
public Psg(Component component)
- Constructor from Component.
This is the preferred way to make a Psg.
Psg
public Psg(Graphics graphics)
- Constructor from Graphics.
If you don't have a Component, you can create a Psg from a Graphics
instead, but this is not as good.
gsave
public void gsave()
- Save the current graphics state onto a stack.
grestore
public void grestore()
- Restore the last Save()ed graphics state.
grestoreall
public void grestoreall()
- Pop to bottom-most graphics state.
initgraphics
public void initgraphics()
- Reset graphics state.
setlinewidth
public void setlinewidth(double linewidth)
- Set the current line width.
setcolor
public void setcolor(Color color)
- Set the current color.
setgray
public void setgray(float grayVal)
- Set the color to the specified gray value (0=black, 1=white).
sethsbcolor
public void sethsbcolor(float hue,
float saturation,
float brightness)
- Set the color from HSB coordinates.
setrgbcolor
public void setrgbcolor(float r,
float g,
float b)
- Set the color from RGB coordinates.
translate
public void translate(double tx,
double ty)
- Translate graphics space.
scale
public void scale(double sx,
double sy)
- Scale graphics space.
rotate
public void rotate(double degrees)
- Rotate graphics space.
transform_x
public int transform_x(double x,
double y)
- Transform (x, y) into a device-space x-coordinate.
transform_y
public int transform_y(double x,
double y)
- Transform (x, y) into a device-space y-coordinate.
dtransform_x
public int dtransform_x(double dx,
double dy)
- Transform (dx, dy) into a device-space x-distance.
dtransform_y
public int dtransform_y(double dx,
double dy)
- Transform (dx, dy) into a device-space y-distance.
itransform_x
public double itransform_x(int x,
int y) throws PsgException
- Inverse transform (x, y) into a user-space x-coordinate.
- Throws: PsgException
- "undefined result"
itransform_y
public double itransform_y(int x,
int y) throws PsgException
- Inverse transform (x, y) into a user-space y-coordinate.
- Throws: PsgException
- "undefined result"
idtransform_x
public double idtransform_x(int dx,
int dy) throws PsgException
- Inverse transform (dx, dy) into a user-space x-distance.
- Throws: PsgException
- "undefined result"
idtransform_y
public double idtransform_y(int dx,
int dy) throws PsgException
- Inverse transform (dx, dy) into a user-space y-distance.
- Throws: PsgException
- "undefined result"
newpath
public void newpath()
- Start a new, empty path.
moveto
public void moveto(double x,
double y)
- Set the current point.
rmoveto
public void rmoveto(double dx,
double dy) throws PsgException
- Relative moveto().
- Throws: PsgException
- "no current point"
lineto
public void lineto(double x,
double y) throws PsgException
- Add a line to the path.
- Throws: PsgException
- "no current point"
rlineto
public void rlineto(double dx,
double dy) throws PsgException
- Relative lineto().
- Throws: PsgException
- "no current point"
arc
public void arc(double cx,
double cy,
double r,
double ang1,
double ang2)
- Append counterclockwise arc.
arcn
public void arcn(double cx,
double cy,
double r,
double ang1,
double ang2)
- Append clockwise arc.
curveto
public void curveto(double x1,
double y1,
double x2,
double y2,
double x3,
double y3) throws PsgException
- Append a Bezier cubic section.
- Throws: PsgException
- "no current point"
rcurveto
public void rcurveto(double dx1,
double dy1,
double dx2,
double dy2,
double dx3,
double dy3) throws PsgException
- Relative curveto.
- Throws: PsgException
- "no current point"
closepath
public void closepath()
- Connect current path back to its starting point.
flattenpath
public void flattenpath()
- Convert curves in the path to sequences of straight lines.
clippath
public void clippath() throws PsgException
- Set the current path to the clipping path.
- Throws: PsgException
- "undefined result"
pathbbox
public double[] pathbbox() throws PsgException
- Return the bounding box of the current path.
The return is in the form of a four-element array - element 0 is
llx, 1 is lly, 2 is urx, and 3 is ury.
- Throws: PsgException
- "no current point"
erasepage
public void erasepage()
- Paint the whole graphics area with the background color.
fill
public void fill()
- Fill current path with current color.
stroke
public void stroke()
- Draw lines along the current path.
rectfill
public void rectfill(double x,
double y,
double width,
double height)
- Fill a rectangular path.
rectstroke
public void rectstroke(double x,
double y,
double width,
double height)
- Stroke a rectangular path.
setfont
public void setfont(String name,
int style,
double size)
- Set the current font to the specified name, style, and size.
Similar to a PostScript findfont scalefont setfont sequence.
- Parameters:
- name - the name of the font - Dialog, Helvetica, TimesRoman, Courier
- style - some combination of Font.PLAIN, Font.BOLD, and Font.ITALIC
- size - how tall the font should be
setfontName
public void setfontName(String name)
- Set the current font to the specified name.
- Parameters:
- name - the name of the font - Dialog, Helvetica, TimesRoman, Courier
setfontStyle
public void setfontStyle(int style)
- Set the current font to the specified style.
- Parameters:
- style - some combination of Font.PLAIN, Font.BOLD, and Font.ITALIC
setfontSize
public void setfontSize(double size)
- Set the current font to the specified size.
- Parameters:
- size - how tall the font should be
show
public void show(String str) throws PsgException
- Paint a string starting at the current point.
Doesn't do rotation yet.
- Throws: PsgException
- "no current point"
stringwidth_x
public double stringwidth_x(String str) throws PsgException
- Return the x-width of a string.
Doesn't do rotation yet.
- Throws: PsgException
- "undefined result"
main
public static void main(String args[])
- Test program.
All Packages Class Hierarchy This Package Previous Next Index
ACME Java ACME Labs