PiscesRenderGraphicspublic abstract class PiscesRenderGraphics extends RenderContext All rendering in Perseus is done through the RenderGraphics class.
RenderGraphics is the combination of the traditional
Graphics2D API to the rendering engine and the notion of
graphical context found in SVG.
A RenderGraphics object proxies invocation to a Graphics2D
instance through its draw or fill method while capturing
the current rendering context state by implementing the
RenderContext interface.
Note A: the Java 2D graphic context values passed by the
RenderGraphics to the proxied Graphics2D correspond to
the CSS 2
actual values.
Note B: the initial values for the context properties (such
as color or fill) correspond to the CSS 2
initial values for these properties. |
Fields Summary |
---|
protected static final Transform | IDENTITYConstant used to handle setTransform(null) | protected PaintTarget | paintTargetThe PaintTarget is the object defining the extent of the target rendered
area. In some situations, this may be different than the primitive being
drawn. For example, the same paint target may apply to multiple
consecutive rendering calls. | protected Transform | paintTransformThe paintTransform defines the coordinate space into which the PaintDef
should do its computation. Note that a PaintDef may add additional transform
to the paintTransform, for example to account for objectBoundingBox paints
or for paints which accept additional transforms (such as LinearGradientPaintDef
which accepts a gradientTransform). | protected com.sun.pisces.PiscesRenderer | prThe associated PiscesRenderer. | protected com.sun.pisces.Transform6 | transformThe current transform. | protected boolean | needSetTransformTracks whether or not the current transform needs to be set. | protected com.sun.pisces.Transform6 | imageTransformThe image transform, used in drawImage | protected int | widthThe rendering extent along the x axis. | protected int | heightThe rendering extent along the y axis. | protected Tile | renderingTileThe current rendering tile. | protected Tile | primitiveTileThe current primitive tile, i.e., the one that should encompass the
rendering of the following rendering primitive(s). This is used to
account for round-off errors in bounds computation and cut-off rendering
to the computed bouds for each primitive. |
Constructors Summary |
---|
public PiscesRenderGraphics(com.sun.pisces.PiscesRenderer pr, int width, int height)Constructs a new PiscesRenderGraphics which will delegate painting
operations to a PiscesRenderer .
if (pr == null) {
throw new NullPointerException();
}
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException();
}
this.width = width;
this.height = height;
this.pr = pr;
setRenderingTile(null);
setPrimitiveTile(null);
|
Methods Summary |
---|
void | applyClip()Applies the intersection of the rendering tile and the primitive tile
int x = primitiveTile.x;
int y = primitiveTile.y;
int mx = primitiveTile.maxX;
int my = primitiveTile.maxY;
if (x < renderingTile.x) {
x = renderingTile.x;
}
if (y < renderingTile.y) {
y = renderingTile.y;
}
if (mx > renderingTile.maxX) {
mx = renderingTile.maxX;
}
if (my > renderingTile.maxY) {
my = renderingTile.maxY;
}
final int w = mx - x + 1;
final int h = my - y + 1;
if (w <= 0 || h <= 0) {
throw new IllegalArgumentException();
}
pr.setClip(x, y, w, h);
| public abstract void | clearRect(int x, int y, int width, int height, RGB clearColor)Clears the specified rectangle. IMPORTANT NOTE: the coordinates are in
device space. This method does not account for the current transformation
set on the RenderGraphics. It operates on the target pixels.
| public void | draw(Path path)Draws the input shape using a stroke
derived from the following properties:
- strokeWidth
- strokeDashArray
- strokeDashOffset
- strokeLineJoin
- strokeLineCap
fillOrDraw(path, stroke, getStrokeOpacityImpl(), false);
| public void | drawImage(RasterImage image, float dx, float dy, float dw, float dh)Draws the input Image at the specified location applying the
input transform to the image before drawing it onto the
proxied Graphics2D
// Don't process degenerate cases.
if (image == null
||
image.getWidth() <= 0
||
image.getHeight() <= 0
||
dw <= 0
||
dh <= 0) {
return;
}
int sw = image.getWidth();
int sh = image.getHeight();
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
// We compute the transform so that the rectangle (0, 0, sw, sh) is
// mapped to (dx, dy, dw, dh).
float scaleX = dw / sw;
float scaleY = dh / sh;
Transform6 imageTransform = new Transform6();
imageTransform.m00 = (int) (scaleX * 65536.0f);
imageTransform.m11 = (int) (scaleY * 65536.0f);
imageTransform.m02 = (int) (dx * 65536.0f);
imageTransform.m12 = (int) (dy * 65536.0f);
if (getOpacity() != 0.0f) {
pr.setTextureOpacity(getOpacity());
pr.setTexture(RendererBase.TYPE_INT_RGB,
image.getRGB(),
sw,
sh,
0,
sw,
imageTransform,
false);
pr.fillRect((int) (dx * 65536),
(int) (dy * 65536),
(int) (dw * 65536),
(int) (dh * 65536));
}
| public void | drawLine(float x1, float y1, float x2, float y2)
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
stroke.getPaintDef().setPaint(this, pr, getStrokeOpacityImpl());
pr.setStroke(strokeWidth,
getStrokeLineCap(),
getStrokeLineJoin(),
strokeMiterLimit,
strokeDashArray,
computeStrokeDashOffset());
pr.drawLine((int) (x1 * 65536),
(int) (y1 * 65536),
(int) (x2 * 65536),
(int) (y2 * 65536));
| public void | drawOval(float x, float y, float w, float h)
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
stroke.getPaintDef().setPaint(this, pr, getStrokeOpacityImpl());
pr.setStroke(strokeWidth,
getStrokeLineCap(),
getStrokeLineJoin(),
strokeMiterLimit,
strokeDashArray,
computeStrokeDashOffset());
pr.drawOval((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536));
| public void | drawRect(float x, float y, float w, float h, float aw, float ah)
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
stroke.getPaintDef().setPaint(this, pr, getStrokeOpacityImpl());
pr.setStroke(strokeWidth,
getStrokeLineCap(),
getStrokeLineJoin(),
strokeMiterLimit,
strokeDashArray,
computeStrokeDashOffset());
if (aw > 0 || ah > 0) {
pr.drawRoundRect((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536),
(int) (aw * 65536),
(int) (ah * 65536));
} else {
pr.drawRect((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536));
}
| public void | fill(Path path)fills the input shape with the current fill color.
fillOrDraw(path, fill, getFillOpacityImpl(), true);
| void | fillOrDraw(Path path, PaintServer paint, int opOpacity, boolean isFill)
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
paint.getPaintDef().setPaint(this, pr, opOpacity);
if (isFill) {
pr.setFill();
pr.beginRendering(getFillRule());
} else {
pr.setStroke(strokeWidth,
getStrokeLineCap(),
getStrokeLineJoin(),
strokeMiterLimit,
strokeDashArray,
computeStrokeDashOffset());
pr.beginRendering(WIND_NON_ZERO);
}
pr.setPathData(path.data, path.commands, path.nSegments);
pr.endRendering();
| public void | fillOval(float x, float y, float w, float h)
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
fill.getPaintDef().setPaint(this, pr, getFillOpacityImpl());
pr.fillOval((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536));
| public void | fillRect(float x, float y, float w, float h, float aw, float ah)Fills a rectangle.
if (needSetTransform) {
pr.setTransform(transform);
needSetTransform = false;
}
fill.getPaintDef().setPaint(this, pr, getFillOpacityImpl());
if (aw > 0 || ah > 0) {
pr.fillRoundRect((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536),
(int) (aw * 65536),
(int) (ah * 65536));
} else {
pr.fillRect((int) (x * 65536),
(int) (y * 65536),
(int) (w * 65536),
(int) (h * 65536));
}
| public Tile | getPrimitiveTile()
return primitiveTile;
| public Tile | getRenderingTile()
return renderingTile;
| public void | setPaintTarget(PaintTarget paintTarget)Sets the current PaintTarget.
this.paintTarget = paintTarget;
| public void | setPaintTransform(Transform paintTransform)Sets the current paintTransform.
this.paintTransform = paintTransform;
| public void | setPrimitiveTile(Tile primitiveTile)Sets the primitive tile, which is intersected with the rendering tile.
if (primitiveTile != null) {
this.primitiveTile.x = primitiveTile.x;
this.primitiveTile.y = primitiveTile.y;
this.primitiveTile.maxX = primitiveTile.maxX;
this.primitiveTile.maxY = primitiveTile.maxY;
} else {
this.primitiveTile.x = renderingTile.x;
this.primitiveTile.y = renderingTile.y;
this.primitiveTile.maxX = renderingTile.maxX;
this.primitiveTile.maxY = renderingTile.maxY;
}
applyClip();
| public void | setRenderingQuality(boolean isHigh)Turns the high quality rendering on or off.
if (isHigh) {
pr.setAntialiasing(true);
} else {
pr.setAntialiasing(false);
}
| public void | setRenderingTile(Tile renderingTile)Sets the current rendering tile to the rectangle specified by the given
tile. IMPORTANT NOTE: the tile is _not_ subject to the RenderGraphics'
transform. The clip is defined in device coordinates.
if (renderingTile != null) {
this.renderingTile.x = renderingTile.x;
this.renderingTile.y = renderingTile.y;
this.renderingTile.maxX = renderingTile.maxX;
this.renderingTile.maxY = renderingTile.maxY;
} else {
this.renderingTile.x = 0;
this.renderingTile.y = 0;
this.renderingTile.maxX = width - 1;
this.renderingTile.maxY = height - 1;
}
setPrimitiveTile(renderingTile);
| public void | setTransform(Transform newTransform)Setting the transform to null is equivalent to setting it
to identity.
needSetTransform = (setTransform(newTransform, transform) || needSetTransform);
needSetTransform = true;
| static boolean | setTransform(Transform newTransform, com.sun.pisces.Transform6 transform)Transfers the transform values from the input Perseus Transform
the the input Pisces Transform6.
if (newTransform == null) {
return setTransform(IDENTITY, transform);
}
int m00 = (int) (newTransform.m0 * 65536);
int m10 = (int) (newTransform.m1 * 65536);
int m01 = (int) (newTransform.m2 * 65536);
int m11 = (int) (newTransform.m3 * 65536);
int m02 = (int) (newTransform.m4 * 65536);
int m12 = (int) (newTransform.m5 * 65536);
// Check if new value is actually different from current
// transform setting.
if (m00 != transform.m00
||
m10 != transform.m10
||
m01 != transform.m01
||
m11 != transform.m11
||
m02 != transform.m02
||
m12 != transform.m12) {
// There is a change
transform.m00 = m00;
transform.m10 = m10;
transform.m01 = m01;
transform.m11 = m11;
transform.m02 = m02;
transform.m12 = m12;
return true;
}
return false;
|
|