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.


Constructor Index

 o Psg(Component)
Constructor from Component.
 o Psg(Graphics)
Constructor from Graphics.

Method Index

 o arc(double, double, double, double, double)
Append counterclockwise arc.
 o arcn(double, double, double, double, double)
Append clockwise arc.
 o clippath()
Set the current path to the clipping path.
 o closepath()
Connect current path back to its starting point.
 o curveto(double, double, double, double, double, double)
Append a Bezier cubic section.
 o dtransform_x(double, double)
Transform (dx, dy) into a device-space x-distance.
 o dtransform_y(double, double)
Transform (dx, dy) into a device-space y-distance.
 o erasepage()
Paint the whole graphics area with the background color.
 o fill()
Fill current path with current color.
 o flattenpath()
Convert curves in the path to sequences of straight lines.
 o grestore()
Restore the last Save()ed graphics state.
 o grestoreall()
Pop to bottom-most graphics state.
 o gsave()
Save the current graphics state onto a stack.
 o idtransform_x(int, int)
Inverse transform (dx, dy) into a user-space x-distance.
 o idtransform_y(int, int)
Inverse transform (dx, dy) into a user-space y-distance.
 o initgraphics()
Reset graphics state.
 o itransform_x(int, int)
Inverse transform (x, y) into a user-space x-coordinate.
 o itransform_y(int, int)
Inverse transform (x, y) into a user-space y-coordinate.
 o lineto(double, double)
Add a line to the path.
 o main(String[])
Test program.
 o moveto(double, double)
Set the current point.
 o newpath()
Start a new, empty path.
 o pathbbox()
Return the bounding box of the current path.
 o rcurveto(double, double, double, double, double, double)
Relative curveto.
 o rectfill(double, double, double, double)
Fill a rectangular path.
 o rectstroke(double, double, double, double)
Stroke a rectangular path.
 o rlineto(double, double)
Relative lineto().
 o rmoveto(double, double)
Relative moveto().
 o rotate(double)
Rotate graphics space.
 o scale(double, double)
Scale graphics space.
 o setcolor(Color)
Set the current color.
 o setfont(String, int, double)
Set the current font to the specified name, style, and size.
 o setfontName(String)
Set the current font to the specified name.
 o setfontSize(double)
Set the current font to the specified size.
 o setfontStyle(int)
Set the current font to the specified style.
 o setgray(float)
Set the color to the specified gray value (0=black, 1=white).
 o sethsbcolor(float, float, float)
Set the color from HSB coordinates.
 o setlinewidth(double)
Set the current line width.
 o setrgbcolor(float, float, float)
Set the color from RGB coordinates.
 o show(String)
Paint a string starting at the current point.
 o stringwidth_x(String)
Return the x-width of a string.
 o stroke()
Draw lines along the current path.
 o transform_x(double, double)
Transform (x, y) into a device-space x-coordinate.
 o transform_y(double, double)
Transform (x, y) into a device-space y-coordinate.
 o translate(double, double)
Translate graphics space.

Constructors

 o Psg
 public Psg(Component component)
Constructor from Component. This is the preferred way to make a Psg.

 o 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.

Methods

 o gsave
 public void gsave()
Save the current graphics state onto a stack.

 o grestore
 public void grestore()
Restore the last Save()ed graphics state.

 o grestoreall
 public void grestoreall()
Pop to bottom-most graphics state.

 o initgraphics
 public void initgraphics()
Reset graphics state.

 o setlinewidth
 public void setlinewidth(double linewidth)
Set the current line width.

 o setcolor
 public void setcolor(Color color)
Set the current color.

 o setgray
 public void setgray(float grayVal)
Set the color to the specified gray value (0=black, 1=white).

 o sethsbcolor
 public void sethsbcolor(float hue,
                         float saturation,
                         float brightness)
Set the color from HSB coordinates.

 o setrgbcolor
 public void setrgbcolor(float r,
                         float g,
                         float b)
Set the color from RGB coordinates.

 o translate
 public void translate(double tx,
                       double ty)
Translate graphics space.

 o scale
 public void scale(double sx,
                   double sy)
Scale graphics space.

 o rotate
 public void rotate(double degrees)
Rotate graphics space.

 o transform_x
 public int transform_x(double x,
                        double y)
Transform (x, y) into a device-space x-coordinate.

 o transform_y
 public int transform_y(double x,
                        double y)
Transform (x, y) into a device-space y-coordinate.

 o dtransform_x
 public int dtransform_x(double dx,
                         double dy)
Transform (dx, dy) into a device-space x-distance.

 o dtransform_y
 public int dtransform_y(double dx,
                         double dy)
Transform (dx, dy) into a device-space y-distance.

 o 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"
 o 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"
 o 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"
 o 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"
 o newpath
 public void newpath()
Start a new, empty path.

 o moveto
 public void moveto(double x,
                    double y)
Set the current point.

 o rmoveto
 public void rmoveto(double dx,
                     double dy) throws PsgException
Relative moveto().

Throws: PsgException
"no current point"
 o lineto
 public void lineto(double x,
                    double y) throws PsgException
Add a line to the path.

Throws: PsgException
"no current point"
 o rlineto
 public void rlineto(double dx,
                     double dy) throws PsgException
Relative lineto().

Throws: PsgException
"no current point"
 o arc
 public void arc(double cx,
                 double cy,
                 double r,
                 double ang1,
                 double ang2)
Append counterclockwise arc.

 o arcn
 public void arcn(double cx,
                  double cy,
                  double r,
                  double ang1,
                  double ang2)
Append clockwise arc.

 o 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"
 o 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"
 o closepath
 public void closepath()
Connect current path back to its starting point.

 o flattenpath
 public void flattenpath()
Convert curves in the path to sequences of straight lines.

 o clippath
 public void clippath() throws PsgException
Set the current path to the clipping path.

Throws: PsgException
"undefined result"
 o 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"
 o erasepage
 public void erasepage()
Paint the whole graphics area with the background color.

 o fill
 public void fill()
Fill current path with current color.

 o stroke
 public void stroke()
Draw lines along the current path.

 o rectfill
 public void rectfill(double x,
                      double y,
                      double width,
                      double height)
Fill a rectangular path.

 o rectstroke
 public void rectstroke(double x,
                        double y,
                        double width,
                        double height)
Stroke a rectangular path.

 o 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
 o 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
 o 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
 o setfontSize
 public void setfontSize(double size)
Set the current font to the specified size.

Parameters:
size - how tall the font should be
 o 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"
 o 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"
 o main
 public static void main(String args[])
Test program.


All Packages  Class Hierarchy  This Package  Previous  Next  Index

ACME Java  ACME Labs