This is an abstract implementation of Graphics2D on Cairo.
It should be subclassed for different Cairo contexts.
Note for subclassers: Apart from the constructor (see comments below),
The following abstract methods must be implemented:
Graphics create()
GraphicsConfiguration getDeviceConfiguration()
copyArea(int x, int y, int width, int height, int dx, int dy)
Also, dispose() must be overloaded to free any native datastructures
used by subclass and in addition call super.dispose() to free the
native cairographics2d structure and cairo_t.
cairoArc
protected void cairoArc(long pointer,
double x,
double y,
double radius,
double angle1,
double angle2)
Appends an arc to the current path
cairoClip
protected void cairoClip(long pointer)
Clip current path
cairoClosePath
protected void cairoClosePath(long pointer)
Close current path
cairoCurveTo
protected void cairoCurveTo(long pointer,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Cubic curve-to
cairoDrawGlyphVector
protected void cairoDrawGlyphVector(long pointer,
GdkFontPeer font,
float x,
float y,
int n,
int[] codes,
float[] positions,
long[] fontset)
cairoFill
protected void cairoFill(long pointer,
double alpha)
Fill current path
cairoLineTo
protected void cairoLineTo(long pointer,
double x,
double y)
lineTo
cairoMoveTo
protected void cairoMoveTo(long pointer,
double x,
double y)
moveTo
cairoNewPath
protected void cairoNewPath(long pointer)
New current path
cairoRectangle
protected void cairoRectangle(long pointer,
double x,
double y,
double width,
double height)
Appends a rectangle to the current path
cairoSave
protected void cairoSave(long pointer)
Save / restore a cairo path
cairoScale
protected void cairoScale(long pointer,
double x,
double y)
Scaling method
cairoSetAntialias
protected void cairoSetAntialias(long pointer,
boolean aa)
Set antialias.
cairoSetDash
protected void cairoSetDash(long pointer,
double[] dashes,
int ndash,
double offset)
Set the dash style
cairoSetFillRule
protected void cairoSetFillRule(long pointer,
int cairoFillRule)
Sets the current winding rule in Cairo
cairoSetLine
protected void cairoSetLine(long pointer,
double width,
int cap,
int join,
double miterLimit)
Set the line style, cap, join and miter limit.
Cap and join parameters are in the BasicStroke enumerations.
cairoSetMatrix
protected void cairoSetMatrix(long pointer,
double[] m)
Set the current transform matrix
cairoSetOperator
protected void cairoSetOperator(long pointer,
int cairoOperator)
Set the compositing operator
cairoSetRGBAColor
protected void cairoSetRGBAColor(long pointer,
double red,
double green,
double blue,
double alpha)
Sets the current color in RGBA as a 0.0-1.0 double
cairoStroke
protected void cairoStroke(long pointer)
Stroke current path
clearRect
public void clearRect(int x,
int y,
int width,
int height)
Note that the rest of the drawing methods go via fill() or draw() for the drawing,
although subclasses may with to overload these methods where context-specific
optimizations are possible (e.g. bitmaps and fillRect(int, int, int, int)
- clearRect in interface Graphics
copy
public void copy(CairoGraphics2D g,
long cairo_t_pointer)
Same as above, but copies the state of another CairoGraphics2D.
copyArea
public void copyArea(int ox,
int oy,
int owidth,
int oheight,
int odx,
int ody)
CopyArea - performs clipping to the native surface as a convenience
(requires getRealBounds). Then calls copyAreaImpl.
- copyArea in interface Graphics
copyAreaImpl
protected abstract void copyAreaImpl(int x,
int y,
int width,
int height,
int dx,
int dy)
dispose
public void dispose()
Disposes the native cairographics2d structure, including the
cairo_t and any gradient stuff, if allocated.
Subclasses should of course overload and call this if
they have additional native structures.
- dispose in interface Graphics
disposeNative
public void disposeNative(long pointer)
Dispose of allocate native resouces.
drawArc
public void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- drawArc in interface Graphics
drawCairoSurface
protected void drawCairoSurface(CairoSurface surface,
AffineTransform tx,
double alpha,
int interpolation)
Optimized method for drawing a CairoSurface onto this graphics context.
surface
- The surface to draw.tx
- The transformation matrix (cannot be null).alpha
- The alpha value to paint with ( 0 <= alpha <= 1).interpolation
- The interpolation type.
drawImage
public boolean drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer)
- drawImage in interface Graphics
drawPixels
protected void drawPixels(long pointer,
int[] pixels,
int w,
int h,
int stride,
double[] i2u,
double alpha,
int interpolation)
Draw pixels as an RGBA int matrix
w
- - widthh
- - heightstride
- - stride of the array widthi2u
- - affine transform array
drawPolygon
public void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolyline
public void drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
fillArc
public void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- fillArc in interface Graphics
fillPolygon
public void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
findStrokedBounds
protected Rectangle findStrokedBounds(Shape s)
Utility method to find the bounds of a shape, including the stroke width.
- the bounds of the shape, including stroke width
getBufferCM
protected ColorModel getBufferCM()
Returns the Color Model describing the buffer that this peer uses
for custom composites.
- ColorModel the ColorModel of the composite buffer in this peer.
getNativeCM
protected abstract ColorModel getNativeCM()
Returns the Colour Model describing the native, raw image data for this
specific peer.
- ColorModel the ColorModel of native data in this peer
getRealBounds
protected abstract Rectangle2D getRealBounds()
Find the bounds of this graphics context, in device space.
- the bounds in device-space
init
protected long init(long pointer)
Allocate the cairographics2d structure and set the cairo_t pointer in it.
pointer
- - a cairo_t pointer, casted to a long.
setCustomPaint
protected void setCustomPaint(Rectangle bounds)
Sets a custom paint
bounds
- the bounding box, in user space
setGradient
protected void setGradient(long pointer,
double x1,
double y1,
double x2,
double y2,
int r1,
int g1,
int b1,
int a1,
int r2,
int g2,
int b2,
int a2,
boolean cyclic)
setPaintPixels
protected void setPaintPixels(long pointer,
int[] pixels,
int w,
int h,
int stride,
boolean repeat,
int x,
int y)
setup
public void setup(long cairo_t_pointer)
Sets up the default values and allocates the native cairographics2d structure
cairo_t_pointer
- a native pointer to a cairo_t of the context.
toString
public String toString()
Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into
System.out.println()
and such.
It is typical, but not required, to ensure that this method
never completes abruptly with a
RuntimeException
.
This method will be called when performing string
concatenation with this object. If the result is
null
, string concatenation will instead
use
"null"
.
The default implementation returns
getClass().getName() + "@" +
Integer.toHexString(hashCode())
.
- toString in interface Graphics
- the String representing this Object, which may be null
translate
public void translate(double tx,
double ty)
Translate the system of the co-ordinates. As translation is a frequent
operation, it is done in an optimised way, unlike scaling and rotating.
- translate in interface Graphics2D
CairoGraphics2D.java --
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.