62 |
import java.awt.Toolkit; |
import java.awt.Toolkit; |
63 |
import java.awt.color.ColorSpace; |
import java.awt.color.ColorSpace; |
64 |
import java.awt.font.FontRenderContext; |
import java.awt.font.FontRenderContext; |
|
import java.awt.font.GlyphVector; |
|
65 |
import java.awt.font.GlyphJustificationInfo; |
import java.awt.font.GlyphJustificationInfo; |
66 |
|
import java.awt.font.GlyphVector; |
67 |
|
import java.awt.geom.AffineTransform; |
68 |
import java.awt.geom.Arc2D; |
import java.awt.geom.Arc2D; |
69 |
import java.awt.geom.GeneralPath; |
import java.awt.geom.GeneralPath; |
70 |
import java.awt.geom.NoninvertibleTransformException; |
import java.awt.geom.NoninvertibleTransformException; |
71 |
import java.awt.geom.PathIterator; |
import java.awt.geom.PathIterator; |
72 |
import java.awt.geom.Point2D; |
import java.awt.geom.Point2D; |
73 |
import java.awt.geom.Rectangle2D; |
import java.awt.geom.Rectangle2D; |
|
import java.awt.geom.AffineTransform; |
|
74 |
import java.awt.image.AffineTransformOp; |
import java.awt.image.AffineTransformOp; |
75 |
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
76 |
import java.awt.image.BufferedImageOp; |
import java.awt.image.BufferedImageOp; |
82 |
import java.awt.image.ImageConsumer; |
import java.awt.image.ImageConsumer; |
83 |
import java.awt.image.ImageObserver; |
import java.awt.image.ImageObserver; |
84 |
import java.awt.image.ImagingOpException; |
import java.awt.image.ImagingOpException; |
85 |
import java.awt.image.SampleModel; |
import java.awt.image.MultiPixelPackedSampleModel; |
86 |
import java.awt.image.Raster; |
import java.awt.image.Raster; |
87 |
import java.awt.image.RenderedImage; |
import java.awt.image.RenderedImage; |
88 |
|
import java.awt.image.SampleModel; |
89 |
import java.awt.image.WritableRaster; |
import java.awt.image.WritableRaster; |
|
import java.awt.image.renderable.RenderableImage; |
|
90 |
import java.awt.image.renderable.RenderContext; |
import java.awt.image.renderable.RenderContext; |
91 |
|
import java.awt.image.renderable.RenderableImage; |
92 |
import java.text.AttributedCharacterIterator; |
import java.text.AttributedCharacterIterator; |
93 |
import java.util.HashMap; |
import java.util.HashMap; |
94 |
import java.util.Map; |
import java.util.Map; |
96 |
|
|
97 |
public class GdkGraphics2D extends Graphics2D |
public class GdkGraphics2D extends Graphics2D |
98 |
{ |
{ |
|
|
|
99 |
////////////////////////////////////// |
////////////////////////////////////// |
100 |
////// State Management Methods ////// |
////// State Management Methods ////// |
101 |
////////////////////////////////////// |
////////////////////////////////////// |
102 |
|
static |
103 |
|
{ |
104 |
|
if (Configuration.INIT_LOAD_LIBRARY) |
105 |
|
System.loadLibrary("gtkpeer"); |
106 |
|
|
107 |
static |
if (GtkToolkit.useGraphics2D()) |
108 |
{ |
initStaticState(); |
109 |
if (Configuration.INIT_LOAD_LIBRARY) |
} |
|
{ |
|
|
System.loadLibrary("gtkpeer"); |
|
|
} |
|
110 |
|
|
111 |
if (GtkToolkit.useGraphics2D ()) |
static native void initStaticState(); |
|
initStaticState (); |
|
|
} |
|
|
native static void initStaticState (); |
|
|
private final int native_state = GtkGenericPeer.getUniqueInteger(); |
|
112 |
|
|
113 |
|
private final int native_state = GtkGenericPeer.getUniqueInteger(); |
114 |
private Paint paint; |
private Paint paint; |
115 |
private Stroke stroke; |
private Stroke stroke; |
116 |
private Color fg; |
private Color fg; |
118 |
private Shape clip; |
private Shape clip; |
119 |
private AffineTransform transform; |
private AffineTransform transform; |
120 |
private GtkComponentPeer component; |
private GtkComponentPeer component; |
121 |
private Font font; |
private Font font; |
122 |
private RenderingHints hints; |
private RenderingHints hints; |
123 |
private BufferedImage bimage; |
private BufferedImage bimage; |
|
|
|
124 |
private Composite comp; |
private Composite comp; |
|
|
|
125 |
private Stack stateStack; |
private Stack stateStack; |
|
|
|
|
native private void initState (GtkComponentPeer component); |
|
|
native private void initState (int width, int height); |
|
|
native private void copyState (GdkGraphics2D g); |
|
|
native public void dispose (); |
|
|
native private int[] getImagePixels(); |
|
|
native private void cairoSurfaceSetFilter(int filter); |
|
|
native void connectSignals (GtkComponentPeer component); |
|
126 |
|
|
127 |
public void finalize () |
private native void initState(GtkComponentPeer component); |
128 |
|
|
129 |
|
private native void initState(int width, int height); |
130 |
|
|
131 |
|
private native void copyState(GdkGraphics2D g); |
132 |
|
|
133 |
|
public native void dispose(); |
134 |
|
|
135 |
|
private native int[] getImagePixels(); |
136 |
|
|
137 |
|
private native void cairoSurfaceSetFilter(int filter); |
138 |
|
|
139 |
|
native void connectSignals(GtkComponentPeer component); |
140 |
|
|
141 |
|
public void finalize() |
142 |
{ |
{ |
143 |
dispose(); |
dispose(); |
144 |
} |
} |
145 |
|
|
146 |
public Graphics create () |
public Graphics create() |
147 |
{ |
{ |
148 |
return new GdkGraphics2D (this); |
return new GdkGraphics2D(this); |
149 |
} |
} |
150 |
|
|
151 |
public Graphics create (int x, int y, int width, int height) |
public Graphics create(int x, int y, int width, int height) |
152 |
{ |
{ |
153 |
return new GdkGraphics2D (width, height); |
return new GdkGraphics2D(width, height); |
154 |
} |
} |
155 |
|
|
156 |
GdkGraphics2D (GdkGraphics2D g) |
GdkGraphics2D(GdkGraphics2D g) |
157 |
{ |
{ |
158 |
paint = g.paint; |
paint = g.paint; |
159 |
stroke = g.stroke; |
stroke = g.stroke; |
160 |
setRenderingHints (g.hints); |
setRenderingHints(g.hints); |
161 |
|
|
162 |
if (g.fg.getAlpha() != -1) |
if (g.fg.getAlpha() != -1) |
163 |
fg = new Color (g.fg.getRed (), g.fg.getGreen (), |
fg = new Color(g.fg.getRed(), g.fg.getGreen(), g.fg.getBlue(), |
164 |
g.fg.getBlue (), g.fg.getAlpha ()); |
g.fg.getAlpha()); |
165 |
else |
else |
166 |
fg = new Color (g.fg.getRGB ()); |
fg = new Color(g.fg.getRGB()); |
167 |
|
|
168 |
if (g.bg.getAlpha() != -1) |
if (g.bg.getAlpha() != -1) |
169 |
bg = new Color(g.bg.getRed (), g.bg.getGreen (), |
bg = new Color(g.bg.getRed(), g.bg.getGreen(), g.bg.getBlue(), |
170 |
g.bg.getBlue (), g.bg.getAlpha ()); |
g.bg.getAlpha()); |
171 |
else |
else |
172 |
bg = new Color (g.bg.getRGB ()); |
bg = new Color(g.bg.getRGB()); |
173 |
|
|
174 |
if (g.clip == null) |
if (g.clip == null) |
175 |
clip = null; |
clip = null; |
176 |
else |
else |
177 |
clip = new Rectangle (g.getClipBounds ()); |
clip = new Rectangle(g.getClipBounds()); |
178 |
|
|
179 |
if (g.transform == null) |
if (g.transform == null) |
180 |
transform = new AffineTransform (); |
transform = new AffineTransform(); |
181 |
else |
else |
182 |
transform = new AffineTransform (g.transform); |
transform = new AffineTransform(g.transform); |
183 |
|
|
184 |
font = g.font; |
font = g.font; |
185 |
component = g.component; |
component = g.component; |
186 |
copyState (g); |
copyState(g); |
187 |
|
|
188 |
setColor (fg); |
setColor(fg); |
189 |
setBackground (bg); |
setBackground(bg); |
190 |
setPaint (paint); |
setPaint(paint); |
191 |
setStroke (stroke); |
setStroke(stroke); |
192 |
setTransform (transform); |
setTransform(transform); |
193 |
setClip (clip); |
setClip(clip); |
194 |
stateStack = new Stack(); |
stateStack = new Stack(); |
195 |
} |
} |
196 |
|
|
197 |
GdkGraphics2D (int width, int height) |
GdkGraphics2D(int width, int height) |
198 |
{ |
{ |
199 |
initState (width, height); |
initState(width, height); |
200 |
|
|
201 |
setColor(Color.black); |
setColor(Color.black); |
202 |
setBackground (Color.black); |
setBackground(Color.black); |
203 |
setPaint (getColor()); |
setPaint(getColor()); |
204 |
setFont (new Font("SansSerif", Font.PLAIN, 12)); |
setFont(new Font("SansSerif", Font.PLAIN, 12)); |
205 |
setTransform (new AffineTransform ()); |
setTransform(new AffineTransform()); |
206 |
setStroke (new BasicStroke ()); |
setStroke(new BasicStroke()); |
207 |
setRenderingHints (getDefaultHints()); |
setRenderingHints(getDefaultHints()); |
208 |
|
|
209 |
stateStack = new Stack(); |
stateStack = new Stack(); |
210 |
} |
} |
211 |
|
|
212 |
GdkGraphics2D (GtkComponentPeer component) |
GdkGraphics2D(GtkComponentPeer component) |
213 |
{ |
{ |
214 |
this.component = component; |
this.component = component; |
215 |
|
|
216 |
setFont (new Font("SansSerif", Font.PLAIN, 12)); |
setFont(new Font("SansSerif", Font.PLAIN, 12)); |
217 |
|
|
218 |
if (component.isRealized ()) |
if (component.isRealized()) |
219 |
initComponentGraphics2D (); |
initComponentGraphics2D(); |
220 |
else |
else |
221 |
connectSignals (component); |
connectSignals(component); |
222 |
} |
} |
223 |
|
|
224 |
void initComponentGraphics2D () |
void initComponentGraphics2D() |
225 |
{ |
{ |
226 |
initState (component); |
initState(component); |
227 |
|
|
228 |
setColor (component.awtComponent.getForeground ()); |
setColor(component.awtComponent.getForeground()); |
229 |
setBackground (component.awtComponent.getBackground ()); |
setBackground(component.awtComponent.getBackground()); |
230 |
setPaint (getColor()); |
setPaint(getColor()); |
231 |
setTransform (new AffineTransform ()); |
setTransform(new AffineTransform()); |
232 |
setStroke (new BasicStroke ()); |
setStroke(new BasicStroke()); |
233 |
setRenderingHints (getDefaultHints()); |
setRenderingHints(getDefaultHints()); |
234 |
|
|
235 |
stateStack = new Stack (); |
stateStack = new Stack(); |
236 |
} |
} |
237 |
|
|
238 |
GdkGraphics2D (BufferedImage bimage) |
GdkGraphics2D(BufferedImage bimage) |
239 |
{ |
{ |
240 |
|
this.bimage = bimage; |
241 |
this.bimage = bimage; |
initState(bimage.getWidth(), bimage.getHeight()); |
|
initState (bimage.getWidth(), bimage.getHeight()); |
|
242 |
|
|
243 |
setColor(Color.black); |
setColor(Color.black); |
244 |
setBackground (Color.black); |
setBackground(Color.black); |
245 |
setPaint (getColor()); |
setPaint(getColor()); |
246 |
setFont (new Font("SansSerif", Font.PLAIN, 12)); |
setFont(new Font("SansSerif", Font.PLAIN, 12)); |
247 |
setTransform (new AffineTransform ()); |
setTransform(new AffineTransform()); |
248 |
setStroke (new BasicStroke ()); |
setStroke(new BasicStroke()); |
249 |
setRenderingHints (getDefaultHints()); |
setRenderingHints(getDefaultHints()); |
250 |
|
|
251 |
stateStack = new Stack(); |
stateStack = new Stack(); |
252 |
|
|
253 |
// draw current buffered image to the pixmap associated |
// draw current buffered image to the pixmap associated |
254 |
// with it. |
// with it. |
255 |
|
drawImage(bimage, new AffineTransform(1, 0, 0, 1, 0, 0), bg, null); |
|
drawImage (bimage, new AffineTransform (1,0,0,1,0,0), bg, null); |
|
256 |
} |
} |
257 |
|
|
|
|
|
258 |
//////////////////////////////////// |
//////////////////////////////////// |
259 |
////// Native Drawing Methods ////// |
////// Native Drawing Methods ////// |
260 |
//////////////////////////////////// |
//////////////////////////////////// |
|
|
|
261 |
// GDK drawing methods |
// GDK drawing methods |
262 |
private native void gdkDrawDrawable (GdkGraphics2D other, int x, int y); |
private native void gdkDrawDrawable(GdkGraphics2D other, int x, int y); |
263 |
|
|
264 |
// drawing utility methods |
// drawing utility methods |
265 |
private native void drawPixels (int pixels[], int w, int h, int stride, double i2u[]); |
private native void drawPixels(int[] pixels, int w, int h, int stride, |
266 |
private native void setTexturePixels (int pixels[], int w, int h, int stride); |
double[] i2u); |
267 |
private native void setGradient (double x1, double y1, |
|
268 |
double x2, double y2, |
private native void setTexturePixels(int[] pixels, int w, int h, int stride); |
269 |
int r1, int g1, int b1, int a1, |
|
270 |
int r2, int g2, int b2, int a2, |
private native void setGradient(double x1, double y1, double x2, double y2, |
271 |
boolean cyclic); |
int r1, int g1, int b1, int a1, int r2, |
272 |
|
int g2, int b2, int a2, boolean cyclic); |
273 |
|
|
274 |
// simple passthroughs to cairo |
// simple passthroughs to cairo |
275 |
private native void cairoSave (); |
private native void cairoSave(); |
276 |
private native void cairoRestore (); |
|
277 |
private native void cairoSetMatrix (double m[]); |
private native void cairoRestore(); |
278 |
private native void cairoSetOperator (int cairoOperator); |
|
279 |
private native void cairoSetRGBColor (double red, double green, double blue); |
private native void cairoSetMatrix(double[] m); |
280 |
private native void cairoSetAlpha (double alpha); |
|
281 |
private native void cairoSetFillRule (int cairoFillRule); |
private native void cairoSetOperator(int cairoOperator); |
282 |
private native void cairoSetLineWidth (double width); |
|
283 |
private native void cairoSetLineCap (int cairoLineCap); |
private native void cairoSetRGBColor(double red, double green, double blue); |
284 |
private native void cairoSetLineJoin (int cairoLineJoin); |
|
285 |
private native void cairoSetDash (double dashes[], int ndash, double offset); |
private native void cairoSetAlpha(double alpha); |
286 |
private native void cairoSetMiterLimit (double limit); |
|
287 |
private native void cairoNewPath (); |
private native void cairoSetFillRule(int cairoFillRule); |
288 |
private native void cairoMoveTo (double x, double y); |
|
289 |
private native void cairoLineTo (double x, double y); |
private native void cairoSetLineWidth(double width); |
290 |
private native void cairoCurveTo (double x1, double y1, |
|
291 |
double x2, double y2, |
private native void cairoSetLineCap(int cairoLineCap); |
292 |
double x3, double y3); |
|
293 |
private native void cairoRelMoveTo (double dx, double dy); |
private native void cairoSetLineJoin(int cairoLineJoin); |
294 |
private native void cairoRelLineTo (double dx, double dy); |
|
295 |
private native void cairoRelCurveTo (double dx1, double dy1, |
private native void cairoSetDash(double[] dashes, int ndash, double offset); |
296 |
double dx2, double dy2, |
|
297 |
double dx3, double dy3); |
private native void cairoSetMiterLimit(double limit); |
298 |
private native void cairoRectangle (double x, double y, |
|
299 |
double width, double height); |
private native void cairoNewPath(); |
300 |
private native void cairoClosePath (); |
|
301 |
private native void cairoStroke (); |
private native void cairoMoveTo(double x, double y); |
302 |
private native void cairoFill (); |
|
303 |
private native void cairoClip (); |
private native void cairoLineTo(double x, double y); |
304 |
|
|
305 |
|
private native void cairoCurveTo(double x1, double y1, double x2, double y2, |
306 |
|
double x3, double y3); |
307 |
|
|
308 |
|
private native void cairoRelMoveTo(double dx, double dy); |
309 |
|
|
310 |
|
private native void cairoRelLineTo(double dx, double dy); |
311 |
|
|
312 |
|
private native void cairoRelCurveTo(double dx1, double dy1, double dx2, |
313 |
|
double dy2, double dx3, double dy3); |
314 |
|
|
315 |
|
private native void cairoRectangle(double x, double y, double width, |
316 |
|
double height); |
317 |
|
|
318 |
|
private native void cairoClosePath(); |
319 |
|
|
320 |
|
private native void cairoStroke(); |
321 |
|
|
322 |
|
private native void cairoFill(); |
323 |
|
|
324 |
|
private native void cairoClip(); |
325 |
|
|
326 |
///////////////////////////////////////////// |
///////////////////////////////////////////// |
327 |
////// General Drawing Support Methods ////// |
////// General Drawing Support Methods ////// |
328 |
///////////////////////////////////////////// |
///////////////////////////////////////////// |
329 |
|
private class DrawState |
330 |
|
{ |
331 |
|
private Paint paint; |
332 |
|
private Stroke stroke; |
333 |
|
private Color fg; |
334 |
|
private Color bg; |
335 |
|
private Shape clip; |
336 |
|
private AffineTransform transform; |
337 |
|
private Font font; |
338 |
|
private Composite comp; |
339 |
|
|
340 |
private class DrawState |
DrawState(GdkGraphics2D g) |
|
{ |
|
|
private Paint paint; |
|
|
private Stroke stroke; |
|
|
private Color fg; |
|
|
private Color bg; |
|
|
private Shape clip; |
|
|
private AffineTransform transform; |
|
|
private Font font; |
|
|
private Composite comp; |
|
|
DrawState (GdkGraphics2D g) |
|
|
{ |
|
|
this.paint = g.paint; |
|
|
this.stroke = g.stroke; |
|
|
this.fg = g.fg; |
|
|
this.bg = g.bg; |
|
|
this.clip = g.clip; |
|
|
if (g.transform != null) |
|
|
this.transform = (AffineTransform) g.transform.clone(); |
|
|
this.font = g.font; |
|
|
this.comp = g.comp; |
|
|
} |
|
|
public void restore(GdkGraphics2D g) |
|
|
{ |
|
|
g.paint = this.paint; |
|
|
g.stroke = this.stroke; |
|
|
g.fg = this.fg; |
|
|
g.bg = this.bg; |
|
|
g.clip = this.clip; |
|
|
g.transform = this.transform; |
|
|
g.font = this.font; |
|
|
g.comp = this.comp; |
|
|
} |
|
|
} |
|
|
|
|
|
private void stateSave () |
|
341 |
{ |
{ |
342 |
stateStack.push (new DrawState (this)); |
this.paint = g.paint; |
343 |
cairoSave (); |
this.stroke = g.stroke; |
344 |
|
this.fg = g.fg; |
345 |
|
this.bg = g.bg; |
346 |
|
this.clip = g.clip; |
347 |
|
if (g.transform != null) |
348 |
|
this.transform = (AffineTransform) g.transform.clone(); |
349 |
|
this.font = g.font; |
350 |
|
this.comp = g.comp; |
351 |
} |
} |
352 |
|
|
353 |
private void stateRestore () |
public void restore(GdkGraphics2D g) |
354 |
{ |
{ |
355 |
((DrawState)(stateStack.pop ())).restore (this); |
g.paint = this.paint; |
356 |
cairoRestore (); |
g.stroke = this.stroke; |
357 |
|
g.fg = this.fg; |
358 |
|
g.bg = this.bg; |
359 |
|
g.clip = this.clip; |
360 |
|
g.transform = this.transform; |
361 |
|
g.font = this.font; |
362 |
|
g.comp = this.comp; |
363 |
} |
} |
364 |
|
} |
365 |
|
|
366 |
|
private void stateSave() |
367 |
|
{ |
368 |
|
stateStack.push(new DrawState(this)); |
369 |
|
cairoSave(); |
370 |
|
} |
371 |
|
|
372 |
|
private void stateRestore() |
373 |
|
{ |
374 |
|
((DrawState) (stateStack.pop())).restore(this); |
375 |
|
cairoRestore(); |
376 |
|
} |
377 |
|
|
378 |
// Some operations (drawing rather than filling) require that their |
// Some operations (drawing rather than filling) require that their |
379 |
// coords be shifted to land on 0.5-pixel boundaries, in order to land on |
// coords be shifted to land on 0.5-pixel boundaries, in order to land on |
380 |
// "middle of pixel" coordinates and light up complete pixels. |
// "middle of pixel" coordinates and light up complete pixels. |
|
|
|
381 |
private boolean shiftDrawCalls = false; |
private boolean shiftDrawCalls = false; |
382 |
|
|
383 |
private final double shifted(double coord, boolean doShift) |
private final double shifted(double coord, boolean doShift) |
384 |
{ |
{ |
385 |
if (doShift) |
if (doShift) |
392 |
{ |
{ |
393 |
double x = 0; |
double x = 0; |
394 |
double y = 0; |
double y = 0; |
395 |
double coords[] = new double[6]; |
double[] coords = new double[6]; |
396 |
|
|
397 |
cairoSetFillRule (p.getWindingRule ()); |
cairoSetFillRule(p.getWindingRule()); |
398 |
for ( ; ! p.isDone (); p.next()) |
for (; ! p.isDone(); p.next()) |
399 |
{ |
{ |
400 |
int seg = p.currentSegment (coords); |
int seg = p.currentSegment(coords); |
401 |
switch(seg) |
switch (seg) |
402 |
{ |
{ |
403 |
|
case PathIterator.SEG_MOVETO: |
404 |
case PathIterator.SEG_MOVETO: |
x = shifted(coords[0], doShift); |
405 |
x = shifted(coords[0], doShift); |
y = shifted(coords[1], doShift); |
406 |
y = shifted(coords[1], doShift); |
cairoMoveTo(x, y); |
407 |
cairoMoveTo (x, y); |
break; |
408 |
break; |
case PathIterator.SEG_LINETO: |
409 |
|
x = shifted(coords[0], doShift); |
410 |
case PathIterator.SEG_LINETO: |
y = shifted(coords[1], doShift); |
411 |
x = shifted(coords[0], doShift); |
cairoLineTo(x, y); |
412 |
y = shifted(coords[1], doShift); |
break; |
413 |
cairoLineTo (x, y); |
case PathIterator.SEG_QUADTO: |
414 |
break; |
// splitting a quadratic bezier into a cubic: |
415 |
|
// see: http://pfaedit.sourceforge.net/bezier.html |
416 |
case PathIterator.SEG_QUADTO: |
double x1 = x + (2.0 / 3.0) * (shifted(coords[0], doShift) - x); |
417 |
|
double y1 = y + (2.0 / 3.0) * (shifted(coords[1], doShift) - y); |
418 |
// splitting a quadratic bezier into a cubic: |
|
419 |
// see: http://pfaedit.sourceforge.net/bezier.html |
double x2 = x1 + (1.0 / 3.0) * (shifted(coords[2], doShift) - x); |
420 |
|
double y2 = y1 + (1.0 / 3.0) * (shifted(coords[3], doShift) - y); |
421 |
double x1 = x + (2.0/3.0) * (shifted(coords[0], doShift) - x); |
|
422 |
double y1 = y + (2.0/3.0) * (shifted(coords[1], doShift) - y); |
x = shifted(coords[2], doShift); |
423 |
|
y = shifted(coords[3], doShift); |
424 |
double x2 = x1 + (1.0/3.0) * (shifted(coords[2], doShift) - x); |
cairoCurveTo(x1, y1, x2, y2, x, y); |
425 |
double y2 = y1 + (1.0/3.0) * (shifted(coords[3], doShift) - y); |
break; |
426 |
|
case PathIterator.SEG_CUBICTO: |
427 |
x = shifted(coords[2], doShift); |
x = shifted(coords[4], doShift); |
428 |
y = shifted(coords[3], doShift); |
y = shifted(coords[5], doShift); |
429 |
cairoCurveTo (x1, y1, |
cairoCurveTo(shifted(coords[0], doShift), |
430 |
x2, y2, |
shifted(coords[1], doShift), |
431 |
x, y); |
shifted(coords[2], doShift), |
432 |
break; |
shifted(coords[3], doShift), x, y); |
433 |
|
break; |
434 |
case PathIterator.SEG_CUBICTO: |
case PathIterator.SEG_CLOSE: |
435 |
x = shifted(coords[4], doShift); |
cairoClosePath(); |
436 |
y = shifted(coords[5], doShift); |
break; |
437 |
cairoCurveTo (shifted(coords[0], doShift), shifted(coords[1], doShift), |
} |
438 |
shifted(coords[2], doShift), shifted(coords[3], doShift), |
} |
|
x, y); |
|
|
break; |
|
|
|
|
|
case PathIterator.SEG_CLOSE: |
|
|
cairoClosePath (); |
|
|
break; |
|
|
} |
|
|
} |
|
439 |
} |
} |
440 |
|
|
|
|
|
441 |
private final Map getDefaultHints() |
private final Map getDefaultHints() |
442 |
{ |
{ |
443 |
HashMap defaultHints = new HashMap (); |
HashMap defaultHints = new HashMap(); |
444 |
|
|
445 |
defaultHints.put (RenderingHints.KEY_TEXT_ANTIALIASING, |
defaultHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
446 |
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); |
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); |
447 |
|
|
448 |
defaultHints.put (RenderingHints.KEY_STROKE_CONTROL, |
defaultHints.put(RenderingHints.KEY_STROKE_CONTROL, |
449 |
RenderingHints.VALUE_STROKE_DEFAULT); |
RenderingHints.VALUE_STROKE_DEFAULT); |
450 |
|
|
451 |
defaultHints.put (RenderingHints.KEY_FRACTIONALMETRICS, |
defaultHints.put(RenderingHints.KEY_FRACTIONALMETRICS, |
452 |
RenderingHints.VALUE_FRACTIONALMETRICS_OFF); |
RenderingHints.VALUE_FRACTIONALMETRICS_OFF); |
453 |
|
|
454 |
defaultHints.put (RenderingHints.KEY_ANTIALIASING, |
defaultHints.put(RenderingHints.KEY_ANTIALIASING, |
455 |
RenderingHints.VALUE_ANTIALIAS_OFF); |
RenderingHints.VALUE_ANTIALIAS_OFF); |
456 |
|
|
457 |
defaultHints.put (RenderingHints.KEY_RENDERING, |
defaultHints.put(RenderingHints.KEY_RENDERING, |
458 |
RenderingHints.VALUE_RENDER_DEFAULT); |
RenderingHints.VALUE_RENDER_DEFAULT); |
459 |
|
|
460 |
return defaultHints; |
return defaultHints; |
|
|
|
461 |
} |
} |
462 |
|
|
463 |
private final void updateBufferedImage() |
private final void updateBufferedImage() |
466 |
updateImagePixels(pixels); |
updateImagePixels(pixels); |
467 |
} |
} |
468 |
|
|
469 |
|
private final boolean isBufferedImageGraphics() |
|
private final boolean isBufferedImageGraphics () |
|
470 |
{ |
{ |
471 |
return bimage != null; |
return bimage != null; |
472 |
} |
} |
|
|
|
|
private final void updateImagePixels (int[] pixels) |
|
|
{ |
|
473 |
|
|
474 |
|
private final void updateImagePixels(int[] pixels) |
475 |
|
{ |
476 |
// This function can only be used if |
// This function can only be used if |
477 |
// this graphics object is used to draw into |
// this graphics object is used to draw into |
478 |
// buffered image |
// buffered image |
479 |
|
if (! isBufferedImageGraphics()) |
|
if (! isBufferedImageGraphics ()) |
|
480 |
return; |
return; |
481 |
|
|
482 |
WritableRaster raster = bimage.getRaster(); |
WritableRaster raster = bimage.getRaster(); |
483 |
DataBuffer db = raster.getDataBuffer (); |
DataBuffer db = raster.getDataBuffer(); |
484 |
|
|
485 |
// update pixels in the bufferedImage |
// update pixels in the bufferedImage |
486 |
|
if (raster.getSampleModel().getDataType() == DataBuffer.TYPE_INT |
487 |
if (raster.getSampleModel ().getDataType () == DataBuffer.TYPE_INT |
&& db instanceof DataBufferInt && db.getNumBanks() == 1) |
|
&& db instanceof DataBufferInt |
|
|
&& db.getNumBanks () == 1) |
|
488 |
{ |
{ |
489 |
|
// single bank, ARGB-ints buffer in sRGB space |
490 |
|
DataBufferInt dbi = (DataBufferInt) raster.getDataBuffer(); |
491 |
|
|
492 |
// single bank, ARGB-ints buffer in sRGB space |
for (int i = 0; i < pixels.length; i++) |
493 |
DataBufferInt dbi = (DataBufferInt) raster.getDataBuffer (); |
dbi.setElem(i, pixels[i]); |
|
|
|
|
for (int i=0; i < pixels.length; i++) |
|
|
dbi.setElem(i, pixels[i]); |
|
|
|
|
|
} |
|
|
else |
|
|
{ |
|
|
bimage.getRaster().setPixels (0, 0, raster.getWidth (), |
|
|
raster.getHeight (), pixels); |
|
494 |
} |
} |
495 |
|
else |
496 |
|
bimage.getRaster().setPixels(0, 0, raster.getWidth(), |
497 |
|
raster.getHeight(), pixels); |
498 |
} |
} |
499 |
|
|
500 |
|
private final boolean drawImage(Image img, AffineTransform xform, |
501 |
private final boolean drawImage(Image img, |
Color bgcolor, ImageObserver obs) |
|
AffineTransform xform, |
|
|
Color bgcolor, |
|
|
ImageObserver obs) |
|
502 |
{ |
{ |
|
|
|
503 |
if (img == null) |
if (img == null) |
504 |
return false; |
return false; |
505 |
|
|
506 |
if (img instanceof GtkOffScreenImage && |
if (img instanceof GtkOffScreenImage |
507 |
img.getGraphics () instanceof GdkGraphics2D && |
&& img.getGraphics() instanceof GdkGraphics2D |
508 |
(xform == null |
&& (xform == null || xform.getType() == AffineTransform.TYPE_IDENTITY |
509 |
|| xform.getType () == AffineTransform.TYPE_IDENTITY |
|| xform.getType() == AffineTransform.TYPE_TRANSLATION)) |
510 |
|| xform.getType () == AffineTransform.TYPE_TRANSLATION) |
{ |
511 |
) |
// we are being asked to flush a double buffer from Gdk |
512 |
{ |
GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics(); |
513 |
// we are being asked to flush a double buffer from Gdk |
gdkDrawDrawable(g2, (int) xform.getTranslateX(), |
514 |
GdkGraphics2D g2 = (GdkGraphics2D) img.getGraphics (); |
(int) xform.getTranslateY()); |
515 |
gdkDrawDrawable (g2, (int)xform.getTranslateX(), (int)xform.getTranslateY()); |
|
516 |
|
if (isBufferedImageGraphics()) |
517 |
if (isBufferedImageGraphics ()) |
updateBufferedImage(); |
518 |
updateBufferedImage(); |
|
519 |
|
return true; |
|
return true; |
|
|
} |
|
|
else |
|
|
{ |
|
|
|
|
|
// In this case, xform is an AffineTransform that transforms bounding |
|
|
// box of the specified image from image space to user space. However |
|
|
// when we pass this transform to cairo, cairo will use this transform |
|
|
// to map "user coordinates" to "pixel" coordinates, which is the |
|
|
// other way around. Therefore to get the "user -> pixel" transform |
|
|
// that cairo wants from "image -> user" transform that we currently |
|
|
// have, we will need to invert the transformation matrix. |
|
|
|
|
|
AffineTransform invertedXform = new AffineTransform(); |
|
|
|
|
|
try |
|
|
{ |
|
|
invertedXform = xform.createInverse(); |
|
|
if (img instanceof BufferedImage) |
|
|
{ |
|
|
// draw an image which has actually been loaded |
|
|
// into memory fully |
|
|
|
|
|
BufferedImage b = (BufferedImage) img; |
|
|
return drawRaster (b.getColorModel (), |
|
|
b.getData (), |
|
|
invertedXform, |
|
|
bgcolor); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return this.drawImage(GdkPixbufDecoder.createBufferedImage(img.getSource()), |
|
|
xform, bgcolor,obs); |
|
|
} |
|
|
} |
|
|
catch (NoninvertibleTransformException e) |
|
|
{ |
|
|
throw new ImagingOpException("Unable to invert transform " |
|
|
+ xform.toString()); |
|
|
} |
|
520 |
} |
} |
521 |
} |
else |
522 |
|
{ |
523 |
|
// In this case, xform is an AffineTransform that transforms bounding |
524 |
|
// box of the specified image from image space to user space. However |
525 |
|
// when we pass this transform to cairo, cairo will use this transform |
526 |
|
// to map "user coordinates" to "pixel" coordinates, which is the |
527 |
|
// other way around. Therefore to get the "user -> pixel" transform |
528 |
|
// that cairo wants from "image -> user" transform that we currently |
529 |
|
// have, we will need to invert the transformation matrix. |
530 |
|
AffineTransform invertedXform = new AffineTransform(); |
531 |
|
|
532 |
|
try |
533 |
|
{ |
534 |
|
invertedXform = xform.createInverse(); |
535 |
|
if (img instanceof BufferedImage) |
536 |
|
{ |
537 |
|
// draw an image which has actually been loaded |
538 |
|
// into memory fully |
539 |
|
BufferedImage b = (BufferedImage) img; |
540 |
|
return drawRaster(b.getColorModel(), b.getData(), |
541 |
|
invertedXform, bgcolor); |
542 |
|
} |
543 |
|
else |
544 |
|
return this.drawImage(GdkPixbufDecoder.createBufferedImage(img |
545 |
|
.getSource()), |
546 |
|
xform, bgcolor, obs); |
547 |
|
} |
548 |
|
catch (NoninvertibleTransformException e) |
549 |
|
{ |
550 |
|
throw new ImagingOpException("Unable to invert transform " |
551 |
|
+ xform.toString()); |
552 |
|
} |
553 |
|
} |
554 |
|
} |
555 |
|
|
556 |
////////////////////////////////////////////////// |
////////////////////////////////////////////////// |
557 |
////// Implementation of Graphics2D Methods ////// |
////// Implementation of Graphics2D Methods ////// |
558 |
////////////////////////////////////////////////// |
////////////////////////////////////////////////// |
559 |
|
public void draw(Shape s) |
|
public void draw (Shape s) |
|
560 |
{ |
{ |
561 |
|
if (stroke != null && ! (stroke instanceof BasicStroke)) |
|
if (stroke != null && |
|
|
!(stroke instanceof BasicStroke)) |
|
562 |
{ |
{ |
563 |
fill (stroke.createStrokedShape (s)); |
fill(stroke.createStrokedShape(s)); |
564 |
return; |
return; |
565 |
} |
} |
566 |
|
|
567 |
cairoNewPath (); |
cairoNewPath(); |
568 |
|
|
569 |
if (s instanceof Rectangle2D) |
if (s instanceof Rectangle2D) |
570 |
{ |
{ |
571 |
Rectangle2D r = (Rectangle2D)s; |
Rectangle2D r = (Rectangle2D) s; |
572 |
cairoRectangle (shifted(r.getX (), shiftDrawCalls), |
cairoRectangle(shifted(r.getX(), shiftDrawCalls), |
573 |
shifted(r.getY (), shiftDrawCalls), |
shifted(r.getY(), shiftDrawCalls), r.getWidth(), |
574 |
r.getWidth (), r.getHeight ()); |
r.getHeight()); |
575 |
} |
} |
576 |
else |
else |
577 |
walkPath (s.getPathIterator (null), shiftDrawCalls); |
walkPath(s.getPathIterator(null), shiftDrawCalls); |
578 |
cairoStroke (); |
cairoStroke(); |
579 |
|
|
580 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
581 |
updateBufferedImage(); |
updateBufferedImage(); |
582 |
} |
} |
583 |
|
|
584 |
public void fill (Shape s) |
public void fill(Shape s) |
585 |
{ |
{ |
586 |
cairoNewPath (); |
cairoNewPath(); |
587 |
if (s instanceof Rectangle2D) |
if (s instanceof Rectangle2D) |
588 |
{ |
{ |
589 |
Rectangle2D r = (Rectangle2D)s; |
Rectangle2D r = (Rectangle2D) s; |
590 |
cairoRectangle (r.getX (), r.getY (), r.getWidth (), r.getHeight ()); |
cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
591 |
} |
} |
592 |
else |
else |
593 |
walkPath (s.getPathIterator (null), false); |
walkPath(s.getPathIterator(null), false); |
594 |
cairoFill (); |
cairoFill(); |
|
|
|
|
if (isBufferedImageGraphics ()) |
|
|
updateBufferedImage(); |
|
595 |
|
|
596 |
|
if (isBufferedImageGraphics()) |
597 |
|
updateBufferedImage(); |
598 |
} |
} |
599 |
|
|
600 |
public void clip (Shape s) |
public void clip(Shape s) |
601 |
{ |
{ |
602 |
// update it |
// update it |
603 |
|
if (clip == null || s == null) |
604 |
|
clip = s; |
605 |
|
else if (s instanceof Rectangle2D && clip instanceof Rectangle2D) |
606 |
|
{ |
607 |
|
Rectangle2D r = (Rectangle2D) s; |
608 |
|
Rectangle2D curr = (Rectangle2D) clip; |
609 |
|
clip = curr.createIntersection(r); |
610 |
|
} |
611 |
|
else |
612 |
|
throw new UnsupportedOperationException(); |
613 |
|
|
614 |
if (clip == null || s == null) |
// draw it |
615 |
clip = s; |
if (clip != null) |
616 |
else if (s instanceof Rectangle2D |
{ |
617 |
&& clip instanceof Rectangle2D) |
cairoNewPath(); |
618 |
|
if (clip instanceof Rectangle2D) |
619 |
{ |
{ |
620 |
Rectangle2D r = (Rectangle2D)s; |
Rectangle2D r = (Rectangle2D) clip; |
621 |
Rectangle2D curr = (Rectangle2D)clip; |
cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
|
clip = curr.createIntersection (r); |
|
622 |
} |
} |
623 |
else |
else |
624 |
throw new UnsupportedOperationException (); |
walkPath(clip.getPathIterator(null), false); |
625 |
|
|
626 |
// draw it |
// cairoClosePath (); |
627 |
if (clip != null) |
cairoClip(); |
628 |
{ |
} |
|
cairoNewPath (); |
|
|
if (clip instanceof Rectangle2D) |
|
|
{ |
|
|
Rectangle2D r = (Rectangle2D)clip; |
|
|
cairoRectangle (r.getX (), r.getY (), |
|
|
r.getWidth (), r.getHeight ()); |
|
|
} |
|
|
else |
|
|
walkPath (clip.getPathIterator (null), false); |
|
|
// cairoClosePath (); |
|
|
cairoClip (); |
|
|
} |
|
629 |
} |
} |
630 |
|
|
631 |
public Paint getPaint () |
public Paint getPaint() |
632 |
{ |
{ |
633 |
return paint; |
return paint; |
634 |
} |
} |
635 |
|
|
636 |
public AffineTransform getTransform () |
public AffineTransform getTransform() |
637 |
{ |
{ |
638 |
return (AffineTransform) transform.clone (); |
return (AffineTransform) transform.clone(); |
639 |
} |
} |
640 |
|
|
641 |
public void setPaint (Paint p) |
public void setPaint(Paint p) |
642 |
{ |
{ |
643 |
if (paint == null) |
if (paint == null) |
644 |
return; |
return; |
645 |
|
|
646 |
paint = p; |
paint = p; |
647 |
if (paint instanceof Color) |
if (paint instanceof Color) |
648 |
{ |
setColor((Color) paint); |
|
setColor ((Color) paint); |
|
|
} |
|
649 |
else if (paint instanceof TexturePaint) |
else if (paint instanceof TexturePaint) |
650 |
{ |
{ |
651 |
TexturePaint tp = (TexturePaint) paint; |
TexturePaint tp = (TexturePaint) paint; |
652 |
BufferedImage img = tp.getImage (); |
BufferedImage img = tp.getImage(); |
|
|
|
|
// map the image to the anchor rectangle |
|
|
|
|
|
int width = (int) tp.getAnchorRect ().getWidth (); |
|
|
int height = (int) tp.getAnchorRect ().getHeight (); |
|
|
|
|
|
double scaleX = width / (double) img.getWidth (); |
|
|
double scaleY = width / (double) img.getHeight (); |
|
|
|
|
|
AffineTransform at = new AffineTransform (scaleX, 0, 0, scaleY, 0, 0); |
|
|
AffineTransformOp op = new AffineTransformOp (at, getRenderingHints()); |
|
|
BufferedImage texture = op.filter(img, null); |
|
|
int pixels[] = texture.getRGB (0, 0, width, height, null, 0, width); |
|
|
setTexturePixels (pixels, width, height, width); |
|
653 |
|
|
654 |
|
// map the image to the anchor rectangle |
655 |
|
int width = (int) tp.getAnchorRect().getWidth(); |
656 |
|
int height = (int) tp.getAnchorRect().getHeight(); |
657 |
|
|
658 |
|
double scaleX = width / (double) img.getWidth(); |
659 |
|
double scaleY = width / (double) img.getHeight(); |
660 |
|
|
661 |
|
AffineTransform at = new AffineTransform(scaleX, 0, 0, scaleY, 0, 0); |
662 |
|
AffineTransformOp op = new AffineTransformOp(at, getRenderingHints()); |
663 |
|
BufferedImage texture = op.filter(img, null); |
664 |
|
int[] pixels = texture.getRGB(0, 0, width, height, null, 0, width); |
665 |
|
setTexturePixels(pixels, width, height, width); |
666 |
} |
} |
667 |
else if (paint instanceof GradientPaint) |
else if (paint instanceof GradientPaint) |
668 |
{ |
{ |
669 |
GradientPaint gp = (GradientPaint) paint; |
GradientPaint gp = (GradientPaint) paint; |
670 |
Point2D p1 = gp.getPoint1 (); |
Point2D p1 = gp.getPoint1(); |
671 |
Point2D p2 = gp.getPoint2 (); |
Point2D p2 = gp.getPoint2(); |
672 |
Color c1 = gp.getColor1 (); |
Color c1 = gp.getColor1(); |
673 |
Color c2 = gp.getColor2 (); |
Color c2 = gp.getColor2(); |
674 |
setGradient (p1.getX (), p1.getY (), |
setGradient(p1.getX(), p1.getY(), p2.getX(), p2.getY(), c1.getRed(), |
675 |
p2.getX (), p2.getY (), |
c1.getGreen(), c1.getBlue(), c1.getAlpha(), c2.getRed(), |
676 |
c1.getRed (), c1.getGreen (), |
c2.getGreen(), c2.getBlue(), c2.getAlpha(), gp.isCyclic()); |
|
c1.getBlue (), c1.getAlpha (), |
|
|
c2.getRed (), c2.getGreen (), |
|
|
c2.getBlue (), c2.getAlpha (), |
|
|
gp.isCyclic ()); |
|
677 |
} |
} |
678 |
else |
else |
679 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
680 |
} |
} |
681 |
|
|
682 |
public void setTransform (AffineTransform tx) |
public void setTransform(AffineTransform tx) |
683 |
{ |
{ |
684 |
transform = tx; |
transform = tx; |
685 |
if (transform != null) |
if (transform != null) |
686 |
{ |
{ |
687 |
double m[] = new double[6]; |
double[] m = new double[6]; |
688 |
transform.getMatrix (m); |
transform.getMatrix(m); |
689 |
cairoSetMatrix (m); |
cairoSetMatrix(m); |
690 |
} |
} |
691 |
} |
} |
692 |
|
|
693 |
public void transform (AffineTransform tx) |
public void transform(AffineTransform tx) |
694 |
{ |
{ |
695 |
if (transform == null) |
if (transform == null) |
696 |
transform = new AffineTransform (tx); |
transform = new AffineTransform(tx); |
697 |
else |
else |
698 |
transform.concatenate (tx); |
transform.concatenate(tx); |
699 |
setTransform (transform); |
setTransform(transform); |
700 |
if (clip != null) |
if (clip != null) |
701 |
{ |
{ |
702 |
// FIXME: this should actuall try to transform the shape |
// FIXME: this should actuall try to transform the shape |
703 |
// rather than degrade to bounds. |
// rather than degrade to bounds. |
704 |
Rectangle2D r = clip.getBounds2D(); |
Rectangle2D r = clip.getBounds2D(); |
705 |
double[] coords = new double[] { r.getX(), r.getY(), |
double[] coords = new double[] |
706 |
r.getX() + r.getWidth(), |
{ |
707 |
r.getY() + r.getHeight() }; |
r.getX(), r.getY(), r.getX() + r.getWidth(), |
708 |
try |
r.getY() + r.getHeight() |
709 |
{ |
}; |
710 |
tx.createInverse().transform(coords, 0, coords, 0, 2); |
try |
711 |
r.setRect(coords[0], coords[1], |
{ |
712 |
coords[2] - coords[0], |
tx.createInverse().transform(coords, 0, coords, 0, 2); |
713 |
coords[3] - coords[1]); |
r.setRect(coords[0], coords[1], coords[2] - coords[0], |
714 |
clip = r; |
coords[3] - coords[1]); |
715 |
} |
clip = r; |
716 |
catch (java.awt.geom.NoninvertibleTransformException e) |
} |
717 |
{ |
catch (java.awt.geom.NoninvertibleTransformException e) |
718 |
} |
{ |
719 |
|
} |
720 |
} |
} |
721 |
} |
} |
722 |
|
|
723 |
public void rotate(double theta) |
public void rotate(double theta) |
724 |
{ |
{ |
725 |
transform (AffineTransform.getRotateInstance (theta)); |
transform(AffineTransform.getRotateInstance(theta)); |
726 |
} |
} |
727 |
|
|
728 |
public void rotate(double theta, double x, double y) |
public void rotate(double theta, double x, double y) |
729 |
{ |
{ |
730 |
transform (AffineTransform.getRotateInstance (theta, x, y)); |
transform(AffineTransform.getRotateInstance(theta, x, y)); |
731 |
} |
} |
732 |
|
|
733 |
public void scale(double sx, double sy) |
public void scale(double sx, double sy) |
734 |
{ |
{ |
735 |
transform (AffineTransform.getScaleInstance (sx, sy)); |
transform(AffineTransform.getScaleInstance(sx, sy)); |
736 |
} |
} |
737 |
|
|
738 |
public void translate (double tx, double ty) |
public void translate(double tx, double ty) |
739 |
{ |
{ |
740 |
transform (AffineTransform.getTranslateInstance (tx, ty)); |
transform(AffineTransform.getTranslateInstance(tx, ty)); |
741 |
} |
} |
742 |
|
|
743 |
public void translate (int x, int y) |
public void translate(int x, int y) |
744 |
{ |
{ |
745 |
translate ((double) x, (double) y); |
translate((double) x, (double) y); |
746 |
} |
} |
747 |
|
|
748 |
public void shear(double shearX, double shearY) |
public void shear(double shearX, double shearY) |
749 |
{ |
{ |
750 |
transform (AffineTransform.getShearInstance (shearX, shearY)); |
transform(AffineTransform.getShearInstance(shearX, shearY)); |
751 |
} |
} |
752 |
|
|
753 |
public Stroke getStroke() |
public Stroke getStroke() |
755 |
return stroke; |
return stroke; |
756 |
} |
} |
757 |
|
|
758 |
public void setStroke (Stroke st) |
public void setStroke(Stroke st) |
759 |
{ |
{ |
760 |
stroke = st; |
stroke = st; |
761 |
if (stroke instanceof BasicStroke) |
if (stroke instanceof BasicStroke) |
762 |
{ |
{ |
763 |
BasicStroke bs = (BasicStroke) stroke; |
BasicStroke bs = (BasicStroke) stroke; |
764 |
cairoSetLineCap (bs.getEndCap()); |
cairoSetLineCap(bs.getEndCap()); |
765 |
cairoSetLineWidth (bs.getLineWidth()); |
cairoSetLineWidth(bs.getLineWidth()); |
766 |
cairoSetLineJoin (bs.getLineJoin()); |
cairoSetLineJoin(bs.getLineJoin()); |
767 |
cairoSetMiterLimit (bs.getMiterLimit()); |
cairoSetMiterLimit(bs.getMiterLimit()); |
768 |
float dashes[] = bs.getDashArray(); |
float[] dashes = bs.getDashArray(); |
769 |
if (dashes != null) |
if (dashes != null) |
770 |
{ |
{ |
771 |
double double_dashes[] = new double[dashes.length]; |
double[] double_dashes = new double[dashes.length]; |
772 |
for (int i = 0; i < dashes.length; i++) |
for (int i = 0; i < dashes.length; i++) |
773 |
double_dashes[i] = dashes[i]; |
double_dashes[i] = dashes[i]; |
774 |
cairoSetDash (double_dashes, double_dashes.length, |
cairoSetDash(double_dashes, double_dashes.length, |
775 |
(double) bs.getDashPhase ()); |
(double) bs.getDashPhase()); |
776 |
} |
} |
777 |
} |
} |
778 |
} |
} |
779 |
|
|
|
|
|
780 |
//////////////////////////////////////////////// |
//////////////////////////////////////////////// |
781 |
////// Implementation of Graphics Methods ////// |
////// Implementation of Graphics Methods ////// |
782 |
//////////////////////////////////////////////// |
//////////////////////////////////////////////// |
783 |
|
public void setPaintMode() |
784 |
public void setPaintMode () |
{ |
785 |
{ |
setComposite(java.awt.AlphaComposite.SrcOver); |
|
setComposite (java.awt.AlphaComposite.SrcOver); |
|
786 |
} |
} |
787 |
|
|
788 |
public void setXORMode (Color c) |
public void setXORMode(Color c) |
789 |
{ |
{ |
790 |
setComposite (new gnu.java.awt.BitwiseXORComposite(c)); |
setComposite(new gnu.java.awt.BitwiseXORComposite(c)); |
791 |
} |
} |
792 |
|
|
793 |
public void setColor (Color c) |
public void setColor(Color c) |
794 |
{ |
{ |
795 |
if (c == null) |
if (c == null) |
796 |
c = Color.BLACK; |
c = Color.BLACK; |
797 |
|
|
798 |
fg = c; |
fg = c; |
799 |
paint = c; |
paint = c; |
800 |
cairoSetRGBColor (fg.getRed() / 255.0, |
cairoSetRGBColor(fg.getRed() / 255.0, fg.getGreen() / 255.0, |
801 |
fg.getGreen() / 255.0, |
fg.getBlue() / 255.0); |
802 |
fg.getBlue() / 255.0); |
cairoSetAlpha((fg.getAlpha() & 255) / 255.0); |
|
cairoSetAlpha ((fg.getAlpha() & 255) / 255.0); |
|
803 |
} |
} |
804 |
|
|
805 |
public Color getColor () |
public Color getColor() |
806 |
{ |
{ |
807 |
return fg; |
return fg; |
808 |
} |
} |
809 |
|
|
810 |
public void clipRect (int x, int y, int width, int height) |
public void clipRect(int x, int y, int width, int height) |
811 |
{ |
{ |
812 |
clip (new Rectangle (x, y, width, height)); |
clip(new Rectangle(x, y, width, height)); |
813 |
} |
} |
814 |
|
|
815 |
public Shape getClip () |
public Shape getClip() |
816 |
{ |
{ |
817 |
return getClipInDevSpace (); |
return getClipInDevSpace(); |
818 |
} |
} |
819 |
|
|
820 |
public Rectangle getClipBounds () |
public Rectangle getClipBounds() |
821 |
{ |
{ |
822 |
if (clip == null) |
if (clip == null) |
823 |
return null; |
return null; |
824 |
else |
else |
825 |
return clip.getBounds (); |
return clip.getBounds(); |
826 |
} |
} |
827 |
|
|
828 |
protected Rectangle2D getClipInDevSpace () |
protected Rectangle2D getClipInDevSpace() |
829 |
{ |
{ |
830 |
Rectangle2D uclip = clip.getBounds2D (); |
Rectangle2D uclip = clip.getBounds2D(); |
831 |
if (transform == null) |
if (transform == null) |
832 |
return uclip; |
return uclip; |
833 |
else |
else |
834 |
{ |
{ |
835 |
Point2D pos = transform.transform (new Point2D.Double(uclip.getX (), |
Point2D pos = transform.transform(new Point2D.Double(uclip.getX(), |
836 |
uclip.getY ()), |
uclip.getY()), |
837 |
(Point2D)null); |
(Point2D) null); |
838 |
Point2D extent = transform.deltaTransform (new Point2D.Double(uclip.getWidth (), |
Point2D extent = transform.deltaTransform(new Point2D.Double(uclip |
839 |
uclip.getHeight ()), |
.getWidth(), |
840 |
(Point2D)null); |
uclip |
841 |
return new Rectangle2D.Double (pos.getX (), pos.getY (), |
.getHeight()), |
842 |
extent.getX (), extent.getY ()); |
(Point2D) null); |
843 |
|
return new Rectangle2D.Double(pos.getX(), pos.getY(), extent.getX(), |
844 |
|
extent.getY()); |
845 |
} |
} |
846 |
} |
} |
847 |
|
|
848 |
public void setClip (int x, int y, int width, int height) |
public void setClip(int x, int y, int width, int height) |
849 |
{ |
{ |
850 |
setClip(new Rectangle2D.Double ((double)x, (double)y, |
setClip(new Rectangle2D.Double((double) x, (double) y, (double) width, |
851 |
(double)width, (double)height)); |
(double) height)); |
852 |
} |
} |
853 |
|
|
854 |
public void setClip (Shape s) |
public void setClip(Shape s) |
855 |
{ |
{ |
856 |
clip = s; |
clip = s; |
857 |
if (s != null) |
if (s != null) |
858 |
{ |
{ |
859 |
cairoNewPath (); |
cairoNewPath(); |
860 |
if (s instanceof Rectangle2D) |
if (s instanceof Rectangle2D) |
861 |
{ |
{ |
862 |
Rectangle2D r = (Rectangle2D)s; |
Rectangle2D r = (Rectangle2D) s; |
863 |
cairoRectangle (r.getX (), r.getY (), |
cairoRectangle(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
864 |
r.getWidth (), r.getHeight ()); |
} |
865 |
} |
else |
866 |
else |
walkPath(s.getPathIterator(null), false); |
867 |
walkPath (s.getPathIterator (null), false); |
|
868 |
// cairoClosePath (); |
// cairoClosePath (); |
869 |
cairoClip (); |
cairoClip(); |
870 |
} |
} |
871 |
} |
} |
872 |
|
|
873 |
private static BasicStroke draw3DRectStroke = new BasicStroke(); |
private static BasicStroke draw3DRectStroke = new BasicStroke(); |
874 |
|
|
875 |
public void draw3DRect(int x, int y, int width, |
public void draw3DRect(int x, int y, int width, int height, boolean raised) |
|
int height, boolean raised) |
|
876 |
{ |
{ |
877 |
Stroke tmp = stroke; |
Stroke tmp = stroke; |
878 |
setStroke(draw3DRectStroke); |
setStroke(draw3DRectStroke); |
879 |
super.draw3DRect(x, y, width, height, raised); |
super.draw3DRect(x, y, width, height, raised); |
880 |
setStroke(tmp); |
setStroke(tmp); |
881 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
882 |
updateBufferedImage(); |
updateBufferedImage(); |
883 |
} |
} |
884 |
|
|
885 |
public void fill3DRect(int x, int y, int width, |
public void fill3DRect(int x, int y, int width, int height, boolean raised) |
|
int height, boolean raised) |
|
886 |
{ |
{ |
887 |
Stroke tmp = stroke; |
Stroke tmp = stroke; |
888 |
setStroke(draw3DRectStroke); |
setStroke(draw3DRectStroke); |
889 |
super.fill3DRect(x, y, width, height, raised); |
super.fill3DRect(x, y, width, height, raised); |
890 |
setStroke(tmp); |
setStroke(tmp); |
891 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
892 |
updateBufferedImage(); |
updateBufferedImage(); |
893 |
} |
} |
894 |
|
|
895 |
|
public void drawRect(int x, int y, int width, int height) |
|
public void drawRect (int x, int y, int width, int height) |
|
896 |
{ |
{ |
897 |
draw(new Rectangle (x, y, width, height)); |
draw(new Rectangle(x, y, width, height)); |
898 |
} |
} |
899 |
|
|
900 |
public void fillRect (int x, int y, int width, int height) |
public void fillRect(int x, int y, int width, int height) |
901 |
{ |
{ |
902 |
cairoNewPath (); |
cairoNewPath(); |
903 |
cairoRectangle (x, y, width, height); |
cairoRectangle(x, y, width, height); |
904 |
cairoFill (); |
cairoFill(); |
905 |
} |
} |
906 |
|
|
907 |
public void clearRect (int x, int y, int width, int height) |
public void clearRect(int x, int y, int width, int height) |
908 |
{ |
{ |
909 |
cairoSetRGBColor (bg.getRed() / 255.0, |
cairoSetRGBColor(bg.getRed() / 255.0, bg.getGreen() / 255.0, |
910 |
bg.getGreen() / 255.0, |
bg.getBlue() / 255.0); |
911 |
bg.getBlue() / 255.0); |
cairoSetAlpha(1.0); |
912 |
cairoSetAlpha (1.0); |
cairoNewPath(); |
913 |
cairoNewPath (); |
cairoRectangle(x, y, width, height); |
914 |
cairoRectangle (x, y, width, height); |
cairoFill(); |
915 |
cairoFill (); |
setColor(fg); |
|
setColor (fg); |
|
|
|
|
|
if (isBufferedImageGraphics ()) |
|
|
updateBufferedImage(); |
|
916 |
|
|
917 |
|
if (isBufferedImageGraphics()) |
918 |
|
updateBufferedImage(); |
919 |
} |
} |
920 |
|
|
921 |
public void setBackground(Color c) |
public void setBackground(Color c) |
928 |
return bg; |
return bg; |
929 |
} |
} |
930 |
|
|
931 |
private final void doPolygon(int[] xPoints, int[] yPoints, int nPoints, |
private final void doPolygon(int[] xPoints, int[] yPoints, int nPoints, |
932 |
boolean close, boolean fill) |
boolean close, boolean fill) |
933 |
{ |
{ |
934 |
if (nPoints < 1) |
if (nPoints < 1) |
935 |
return; |
return; |
936 |
GeneralPath gp = new GeneralPath (PathIterator.WIND_EVEN_ODD); |
GeneralPath gp = new GeneralPath(PathIterator.WIND_EVEN_ODD); |
937 |
gp.moveTo ((float)xPoints[0], (float)yPoints[0]); |
gp.moveTo((float) xPoints[0], (float) yPoints[0]); |
938 |
for (int i = 1; i < nPoints; i++) |
for (int i = 1; i < nPoints; i++) |
939 |
gp.lineTo ((float)xPoints[i], (float)yPoints[i]); |
gp.lineTo((float) xPoints[i], (float) yPoints[i]); |
940 |
|
|
941 |
if (close) |
if (close) |
942 |
gp.closePath (); |
gp.closePath(); |
943 |
|
|
944 |
Shape sh = gp; |
Shape sh = gp; |
945 |
if (fill == false && |
if (fill == false && stroke != null && ! (stroke instanceof BasicStroke)) |
|
stroke != null && |
|
|
!(stroke instanceof BasicStroke)) |
|
946 |
{ |
{ |
947 |
sh = stroke.createStrokedShape (gp); |
sh = stroke.createStrokedShape(gp); |
948 |
fill = true; |
fill = true; |
949 |
} |
} |
950 |
|
|
951 |
if (fill) |
if (fill) |
952 |
fill (sh); |
fill(sh); |
953 |
else |
else |
954 |
draw (sh); |
draw(sh); |
955 |
} |
} |
956 |
|
|
957 |
public void drawLine (int x1, int y1, int x2, int y2) |
public void drawLine(int x1, int y1, int x2, int y2) |
958 |
{ |
{ |
959 |
int xp[] = new int[2]; |
int[] xp = new int[2]; |
960 |
int yp[] = new int[2]; |
int[] yp = new int[2]; |
961 |
|
|
962 |
xp[0] = x1; |
xp[0] = x1; |
963 |
xp[1] = x2; |
xp[1] = x2; |
964 |
yp[0] = y1; |
yp[0] = y1; |
965 |
yp[1] = y2; |
yp[1] = y2; |
966 |
|
|
967 |
doPolygon (xp, yp, 2, false, false); |
doPolygon(xp, yp, 2, false, false); |
968 |
} |
} |
969 |
|
|
970 |
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) |
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) |
971 |
{ |
{ |
972 |
doPolygon (xPoints, yPoints, nPoints, true, true); |
doPolygon(xPoints, yPoints, nPoints, true, true); |
973 |
} |
} |
974 |
|
|
975 |
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) |
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) |
976 |
{ |
{ |
977 |
doPolygon (xPoints, yPoints, nPoints, true, false); |
doPolygon(xPoints, yPoints, nPoints, true, false); |
978 |
} |
} |
979 |
|
|
980 |
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) |
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) |
981 |
{ |
{ |
982 |
doPolygon (xPoints, yPoints, nPoints, false, false); |
doPolygon(xPoints, yPoints, nPoints, false, false); |
983 |
} |
} |
984 |
|
|
985 |
private final boolean drawRaster (ColorModel cm, Raster r, |
private final boolean drawRaster(ColorModel cm, Raster r, |
986 |
AffineTransform imageToUser, |
AffineTransform imageToUser, Color bgcolor) |
|
Color bgcolor) |
|
987 |
{ |
{ |
988 |
if (r == null) |
if (r == null) |
989 |
return false; |
return false; |
990 |
|
|
991 |
SampleModel sm = r.getSampleModel (); |
SampleModel sm = r.getSampleModel(); |
992 |
DataBuffer db = r.getDataBuffer (); |
DataBuffer db = r.getDataBuffer(); |
993 |
|
|
994 |
if (db == null || sm == null) |
if (db == null || sm == null) |
995 |
return false; |
return false; |
996 |
|
|
997 |
if (cm == null) |
if (cm == null) |
998 |
cm = ColorModel.getRGBdefault (); |
cm = ColorModel.getRGBdefault(); |
999 |
|
|
1000 |
double[] i2u = new double[6]; |
double[] i2u = new double[6]; |
1001 |
if (imageToUser != null) |
if (imageToUser != null) |
1002 |
imageToUser.getMatrix(i2u); |
imageToUser.getMatrix(i2u); |
1003 |
else |
else |
1004 |
{ |
{ |
1005 |
i2u[0] = 1; i2u[1] = 0; |
i2u[0] = 1; |
1006 |
i2u[2] = 0; i2u[3] = 1; |
i2u[1] = 0; |
1007 |
i2u[4] = 0; i2u[5] = 0; |
i2u[2] = 0; |
1008 |
} |
i2u[3] = 1; |
1009 |
|
i2u[4] = 0; |
1010 |
int pixels[] = null; |
i2u[5] = 0; |
1011 |
|
} |
1012 |
if (sm.getDataType () == DataBuffer.TYPE_INT && |
|
1013 |
db instanceof DataBufferInt && |
int[] pixels = null; |
1014 |
db.getNumBanks () == 1) |
|
1015 |
{ |
if (sm.getDataType() == DataBuffer.TYPE_INT && db instanceof DataBufferInt |
1016 |
// single bank, ARGB-ints buffer in sRGB space |
&& db.getNumBanks() == 1) |
1017 |
DataBufferInt dbi = (DataBufferInt)db; |
{ |
1018 |
pixels = dbi.getData (); |
// single bank, ARGB-ints buffer in sRGB space |
1019 |
|
DataBufferInt dbi = (DataBufferInt) db; |
1020 |
|
pixels = dbi.getData(); |
1021 |
} |
} |
1022 |
else |
else |
|
pixels = r.getPixels (0, 0, r.getWidth (), r.getHeight (), pixels); |
|
|
|
|
|
ColorSpace cs = cm.getColorSpace (); |
|
|
if (cs != null && |
|
|
cs.getType () != ColorSpace.CS_sRGB) |
|
1023 |
{ |
{ |
1024 |
int pixels2[] = new int[pixels.length]; |
// FIXME: I don't think this code will work correctly with a non-RGB |
1025 |
for (int i = 0; i < pixels2.length; i++) |
// MultiPixelPackedSampleModel. Although this entire method should |
1026 |
pixels2[i] = cm.getRGB (pixels[i]); |
// probably be rewritten to better utilize Cairo's different supported |
1027 |
pixels = pixels2; |
// data formats. |
1028 |
|
if (sm instanceof MultiPixelPackedSampleModel) |
1029 |
|
{ |
1030 |
|
pixels = r.getPixels(0, 0, r.getWidth(), r.getHeight(), pixels); |
1031 |
|
for (int i = 0; i < pixels2.length; i++) |
1032 |
|
pixels[i] = cm.getRGB(pixels[i]); |
1033 |
|
} |
1034 |
|
else |
1035 |
|
{ |
1036 |
|
pixels = new int[r.getWidth() * r.getHeight()]; |
1037 |
|
for (int i = 0; i < pixels.length; i++) |
1038 |
|
pixels[i] = cm.getRGB(db.getElem(i)); |
1039 |
|
} |
1040 |
} |
} |
1041 |
|
|
1042 |
// change all transparent pixels in the image to the |
// change all transparent pixels in the image to the |
1043 |
// specified bgcolor |
// specified bgcolor |
1044 |
|
if (cm.hasAlpha()) |
1045 |
if (cm.hasAlpha()) |
{ |
1046 |
{ |
if (bgcolor != null && cm.hasAlpha()) |
1047 |
if (bgcolor != null) |
for (int i = 0; i < pixels.length; i++) |
1048 |
for (int i = 0; i < pixels.length; i++) |
{ |
1049 |
{ |
if (cm.getAlpha(pixels[i]) == 0) |
1050 |
if (cm.getAlpha (pixels[i]) == 0) |
pixels[i] = bgcolor.getRGB(); |
1051 |
pixels[i] = bgcolor.getRGB (); |
} |
1052 |
} |
} |
1053 |
} else |
else |
1054 |
for (int i = 0; i < pixels.length; i++) |
for (int i = 0; i < pixels.length; i++) |
1055 |
pixels[i] |= 0xFF000000; |
pixels[i] |= 0xFF000000; |
1056 |
|
|
1057 |
drawPixels (pixels, r.getWidth (), r.getHeight (), r.getWidth (), i2u); |
drawPixels(pixels, r.getWidth(), r.getHeight(), r.getWidth(), i2u); |
1058 |
|
|
1059 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
1060 |
updateBufferedImage(); |
updateBufferedImage(); |
1061 |
|
|
1062 |
return true; |
return true; |
1063 |
} |
} |
1064 |
|
|
1065 |
public void drawRenderedImage(RenderedImage image, |
public void drawRenderedImage(RenderedImage image, AffineTransform xform) |
|
AffineTransform xform) |
|
1066 |
{ |
{ |
1067 |
drawRaster (image.getColorModel(), image.getData(), xform, bg); |
drawRaster(image.getColorModel(), image.getData(), xform, bg); |
1068 |
} |
} |
1069 |
|
|
1070 |
public void drawRenderableImage(RenderableImage image, |
public void drawRenderableImage(RenderableImage image, AffineTransform xform) |
|
AffineTransform xform) |
|
1071 |
{ |
{ |
1072 |
drawRenderedImage (image.createRendering (new RenderContext (xform)), xform); |
drawRenderedImage(image.createRendering(new RenderContext(xform)), xform); |
1073 |
} |
} |
1074 |
|
|
1075 |
public boolean drawImage(Image img, |
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) |
|
AffineTransform xform, |
|
|
ImageObserver obs) |
|
1076 |
{ |
{ |
1077 |
return drawImage(img, xform, bg, obs); |
return drawImage(img, xform, bg, obs); |
1078 |
} |
} |
1079 |
|
|
1080 |
public void drawImage(BufferedImage image, |
public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y) |
|
BufferedImageOp op, |
|
|
int x, |
|
|
int y) |
|
1081 |
{ |
{ |
1082 |
Image filtered = op.filter(image, null); |
Image filtered = op.filter(image, null); |
1083 |
drawImage(filtered, new AffineTransform(1f,0f,0f,1f,x,y), bg, null); |
drawImage(filtered, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, null); |
1084 |
} |
} |
1085 |
|
|
1086 |
public boolean drawImage (Image img, int x, int y, |
public boolean drawImage(Image img, int x, int y, ImageObserver observer) |
|
ImageObserver observer) |
|
1087 |
{ |
{ |
1088 |
return drawImage(img, new AffineTransform(1f,0f,0f,1f,x,y), bg, observer); |
return drawImage(img, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, |
1089 |
|
observer); |
1090 |
} |
} |
1091 |
|
|
|
|
|
1092 |
/////////////////////////////////////////////// |
/////////////////////////////////////////////// |
1093 |
////// Unimplemented Stubs and Overloads ////// |
////// Unimplemented Stubs and Overloads ////// |
1094 |
/////////////////////////////////////////////// |
/////////////////////////////////////////////// |
1095 |
|
public boolean hit(Rectangle rect, Shape text, boolean onStroke) |
|
|
|
|
|
|
|
public boolean hit(Rectangle rect, Shape text, |
|
|
boolean onStroke) |
|
1096 |
{ |
{ |
1097 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
1098 |
} |
} |
1099 |
|
|
1100 |
public GraphicsConfiguration getDeviceConfiguration() |
public GraphicsConfiguration getDeviceConfiguration() |
1101 |
{ |
{ |
1102 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
1103 |
} |
} |
1104 |
|
|
1105 |
public void setComposite(Composite comp) |
public void setComposite(Composite comp) |
1108 |
|
|
1109 |
if (comp instanceof AlphaComposite) |
if (comp instanceof AlphaComposite) |
1110 |
{ |
{ |
1111 |
AlphaComposite a = (AlphaComposite) comp; |
AlphaComposite a = (AlphaComposite) comp; |
1112 |
cairoSetOperator(a.getRule()); |
cairoSetOperator(a.getRule()); |
1113 |
Color c = getColor(); |
Color c = getColor(); |
1114 |
setColor(new Color(c.getRed(), |
setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), |
1115 |
c.getGreen(), |
(int) (a.getAlpha() * ((float) c.getAlpha())))); |
|
c.getBlue(), |
|
|
(int) (a.getAlpha() * ((float) c.getAlpha())))); |
|
1116 |
} |
} |
1117 |
else |
else |
1118 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
1119 |
} |
} |
1120 |
|
|
1121 |
public void setRenderingHint(RenderingHints.Key hintKey, |
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) |
|
Object hintValue) |
|
1122 |
{ |
{ |
1123 |
hints.put (hintKey, hintValue); |
hints.put(hintKey, hintValue); |
1124 |
|
|
1125 |
if (hintKey.equals(RenderingHints.KEY_INTERPOLATION) |
if (hintKey.equals(RenderingHints.KEY_INTERPOLATION) |
1126 |
|| hintKey.equals(RenderingHints.KEY_ALPHA_INTERPOLATION)) |
|| hintKey.equals(RenderingHints.KEY_ALPHA_INTERPOLATION)) |
1127 |
{ |
{ |
1128 |
|
if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) |
1129 |
if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) |
cairoSurfaceSetFilter(0); |
1130 |
cairoSurfaceSetFilter(0); |
|
1131 |
|
else if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) |
1132 |
else if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) |
cairoSurfaceSetFilter(1); |
1133 |
cairoSurfaceSetFilter(1); |
|
1134 |
|
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) |
1135 |
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) |
cairoSurfaceSetFilter(2); |
1136 |
cairoSurfaceSetFilter(2); |
|
1137 |
|
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) |
1138 |
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) |
cairoSurfaceSetFilter(3); |
1139 |
cairoSurfaceSetFilter(3); |
|
1140 |
|
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) |
1141 |
else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) |
cairoSurfaceSetFilter(4); |
1142 |
cairoSurfaceSetFilter(4); |
} |
1143 |
|
|
1144 |
} |
shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) |
1145 |
|
|| hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); |
|
shiftDrawCalls = hints.containsValue (RenderingHints.VALUE_STROKE_NORMALIZE) |
|
|
|| hints.containsValue (RenderingHints.VALUE_STROKE_DEFAULT); |
|
|
|
|
1146 |
} |
} |
1147 |
|
|
1148 |
public Object getRenderingHint(RenderingHints.Key hintKey) |
public Object getRenderingHint(RenderingHints.Key hintKey) |
1149 |
{ |
{ |
1150 |
return hints.get (hintKey); |
return hints.get(hintKey); |
1151 |
} |
} |
1152 |
|
|
1153 |
public void setRenderingHints(Map hints) |
public void setRenderingHints(Map hints) |
1154 |
{ |
{ |
1155 |
this.hints = new RenderingHints (getDefaultHints ()); |
this.hints = new RenderingHints(getDefaultHints()); |
1156 |
this.hints.add (new RenderingHints (hints)); |
this.hints.add(new RenderingHints(hints)); |
1157 |
|
|
1158 |
if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) |
if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) |
1159 |
{ |
{ |
1160 |
if(hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) |
if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) |
1161 |
cairoSurfaceSetFilter(0); |
cairoSurfaceSetFilter(0); |
1162 |
|
|
1163 |
else if(hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) |
else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) |
1164 |
cairoSurfaceSetFilter(1); |
cairoSurfaceSetFilter(1); |
1165 |
} |
} |
1166 |
|
|
1167 |
if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) |
if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) |
1168 |
{ |
{ |
1169 |
if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) |
if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) |
1170 |
cairoSurfaceSetFilter(2); |
cairoSurfaceSetFilter(2); |
|
|
|
|
else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) |
|
|
cairoSurfaceSetFilter(3); |
|
|
|
|
|
else if(hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) |
|
|
cairoSurfaceSetFilter(4); |
|
|
} |
|
1171 |
|
|
1172 |
shiftDrawCalls = hints.containsValue (RenderingHints.VALUE_STROKE_NORMALIZE) |
else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) |
1173 |
|| hints.containsValue (RenderingHints.VALUE_STROKE_DEFAULT); |
cairoSurfaceSetFilter(3); |
1174 |
|
|
1175 |
|
else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) |
1176 |
|
cairoSurfaceSetFilter(4); |
1177 |
|
} |
1178 |
|
|
1179 |
|
shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) |
1180 |
|
|| hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); |
1181 |
} |
} |
1182 |
|
|
1183 |
public void addRenderingHints(Map hints) |
public void addRenderingHints(Map hints) |
1184 |
{ |
{ |
1185 |
this.hints.add (new RenderingHints (hints)); |
this.hints.add(new RenderingHints(hints)); |
1186 |
} |
} |
1187 |
|
|
1188 |
public RenderingHints getRenderingHints() |
public RenderingHints getRenderingHints() |
1198 |
return comp; |
return comp; |
1199 |
} |
} |
1200 |
|
|
1201 |
public FontRenderContext getFontRenderContext () |
public FontRenderContext getFontRenderContext() |
1202 |
{ |
{ |
1203 |
return new FontRenderContext (transform, true, true); |
return new FontRenderContext(transform, true, true); |
1204 |
} |
} |
1205 |
|
|
1206 |
public void copyArea (int x, int y, int width, int height, int dx, int dy) |
public void copyArea(int x, int y, int width, int height, int dx, int dy) |
1207 |
{ |
{ |
1208 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
1209 |
} |
} |
1210 |
|
|
1211 |
public void drawArc (int x, int y, int width, int height, |
public void drawArc(int x, int y, int width, int height, int startAngle, |
1212 |
int startAngle, int arcAngle) |
int arcAngle) |
1213 |
{ |
{ |
1214 |
draw (new Arc2D.Double((double)x, (double)y, |
draw(new Arc2D.Double((double) x, (double) y, (double) width, |
1215 |
(double)width, (double)height, |
(double) height, (double) startAngle, |
1216 |
(double)startAngle, (double)arcAngle, |
(double) arcAngle, Arc2D.OPEN)); |
|
Arc2D.OPEN)); |
|
1217 |
} |
} |
1218 |
|
|
1219 |
public boolean drawImage (Image img, int x, int y, Color bgcolor, |
public boolean drawImage(Image img, int x, int y, Color bgcolor, |
1220 |
ImageObserver observer) |
ImageObserver observer) |
1221 |
{ |
{ |
1222 |
return drawImage (img, x, y, img.getWidth (observer), |
return drawImage(img, x, y, img.getWidth(observer), |
1223 |
img.getHeight (observer), bgcolor, observer); |
img.getHeight(observer), bgcolor, observer); |
1224 |
} |
} |
1225 |
|
|
1226 |
public boolean drawImage (Image img, int x, int y, int width, int height, |
public boolean drawImage(Image img, int x, int y, int width, int height, |
1227 |
Color bgcolor, ImageObserver observer) |
Color bgcolor, ImageObserver observer) |
1228 |
{ |
{ |
1229 |
|
double scaleX = width / (double) img.getWidth(observer); |
1230 |
double scaleX = width / (double) img.getWidth (observer); |
double scaleY = height / (double) img.getHeight(observer); |
|
double scaleY = height / (double) img.getHeight (observer); |
|
|
|
|
|
return drawImage (img, |
|
|
new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), |
|
|
bgcolor, |
|
|
observer); |
|
1231 |
|
|
1232 |
|
return drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), |
1233 |
|
bgcolor, observer); |
1234 |
} |
} |
1235 |
|
|
1236 |
public boolean drawImage (Image img, int x, int y, int width, int height, |
public boolean drawImage(Image img, int x, int y, int width, int height, |
1237 |
ImageObserver observer) |
ImageObserver observer) |
1238 |
{ |
{ |
1239 |
|
return drawImage(img, x, y, width, height, bg, observer); |
|
return drawImage (img, x, y, width, height, bg, observer); |
|
|
|
|
1240 |
} |
} |
1241 |
|
|
1242 |
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, |
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, |
1243 |
int sx1, int sy1, int sx2, int sy2, |
int sx1, int sy1, int sx2, int sy2, Color bgcolor, |
1244 |
Color bgcolor, ImageObserver observer) |
ImageObserver observer) |
1245 |
{ |
{ |
|
|
|
1246 |
if (img == null) |
if (img == null) |
1247 |
return false; |
return false; |
1248 |
|
|
1249 |
Image subImage; |
Image subImage; |
1250 |
|
|
1251 |
int sourceWidth = sx2 - sx1; |
int sourceWidth = sx2 - sx1; |
1252 |
int sourceHeight = sy2 - sy1; |
int sourceHeight = sy2 - sy1; |
1253 |
|
|
1254 |
int destWidth = dx2 - dx1; |
int destWidth = dx2 - dx1; |
1255 |
int destHeight = dy2 - dy1; |
int destHeight = dy2 - dy1; |
1256 |
|
|
1257 |
double scaleX = destWidth / (double) sourceWidth; |
double scaleX = destWidth / (double) sourceWidth; |
1258 |
double scaleY = destHeight / (double) sourceHeight; |
double scaleY = destHeight / (double) sourceHeight; |
1259 |
|
|
1260 |
// Get the subimage of the source enclosed in the |
// Get the subimage of the source enclosed in the |
1261 |
// rectangle specified by sx1, sy1, sx2, sy2 |
// rectangle specified by sx1, sy1, sx2, sy2 |
|
|
|
1262 |
if (img instanceof BufferedImage) |
if (img instanceof BufferedImage) |
1263 |
{ |
{ |
1264 |
|
BufferedImage b = (BufferedImage) img; |
1265 |
|
subImage = b.getSubimage(sx1, sy1, sx2, sy2); |
1266 |
|
} |
1267 |
|
else |
1268 |
|
{ |
1269 |
|
// FIXME: This code currently doesn't work. Null Pointer |
1270 |
|
// exception is thrown in this case. This happens |
1271 |
|
// because img.getSource() always returns null, since source gets |
1272 |
|
// never initialized when it is created with the help of |
1273 |
|
// createImage(int width, int height). |
1274 |
|
CropImageFilter filter = new CropImageFilter(sx1, sx2, sx2, sy2); |
1275 |
|
FilteredImageSource src = new FilteredImageSource(img.getSource(), |
1276 |
|
filter); |
1277 |
|
|
1278 |
BufferedImage b = (BufferedImage) img; |
subImage = Toolkit.getDefaultToolkit().createImage(src); |
1279 |
subImage = b.getSubimage(sx1,sy1,sx2,sy2); |
} |
1280 |
} |
|
1281 |
else |
return drawImage(subImage, |
1282 |
{ |
new AffineTransform(scaleX, 0, 0, scaleY, dx1, dy1), |
1283 |
|
bgcolor, observer); |
1284 |
// FIXME: This code currently doesn't work. Null Pointer |
} |
|
// exception is thrown in this case. This happens |
|
|
// because img.getSource() always returns null, since source gets |
|
|
// never initialized when it is created with the help of |
|
|
// createImage(int width, int height). |
|
|
|
|
|
CropImageFilter filter = new CropImageFilter(sx1,sx2,sx2,sy2); |
|
|
FilteredImageSource src = new FilteredImageSource(img.getSource(), |
|
|
filter); |
|
|
|
|
|
subImage = Toolkit.getDefaultToolkit().createImage(src); |
|
|
} |
|
|
|
|
|
return drawImage(subImage, new AffineTransform(scaleX, 0, 0, |
|
|
scaleY, dx1, dy1), |
|
|
bgcolor, |
|
|
observer); |
|
|
} |
|
|
|
|
|
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2, |
|
|
int sx1, int sy1, int sx2, int sy2, |
|
|
ImageObserver observer) |
|
|
{ |
|
1285 |
|
|
1286 |
return drawImage (img, dx1, dy1, dx2, dy2, |
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, |
1287 |
sx1, sy1, sx2, sy2, bg, observer); |
int sx1, int sy1, int sx2, int sy2, |
1288 |
|
ImageObserver observer) |
1289 |
|
{ |
1290 |
|
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bg, observer); |
1291 |
} |
} |
1292 |
|
|
1293 |
public void drawOval(int x, int y, int width, int height) |
public void drawOval(int x, int y, int width, int height) |
1294 |
{ |
{ |
1295 |
drawArc (x, y, width, height, 0, 360); |
drawArc(x, y, width, height, 0, 360); |
1296 |
} |
} |
1297 |
|
|
1298 |
public void drawRoundRect(int x, int y, int width, int height, |
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, |
1299 |
int arcWidth, int arcHeight) |
int arcHeight) |
1300 |
{ |
{ |
1301 |
if (arcWidth > width) |
if (arcWidth > width) |
1302 |
arcWidth = width; |
arcWidth = width; |
1306 |
int xx = x + width - arcWidth; |
int xx = x + width - arcWidth; |
1307 |
int yy = y + height - arcHeight; |
int yy = y + height - arcHeight; |
1308 |
|
|
1309 |
drawArc (x, y, arcWidth, arcHeight, 90, 90); |
drawArc(x, y, arcWidth, arcHeight, 90, 90); |
1310 |
drawArc (xx, y, arcWidth, arcHeight, 0, 90); |
drawArc(xx, y, arcWidth, arcHeight, 0, 90); |
1311 |
drawArc (xx, yy, arcWidth, arcHeight, 270, 90); |
drawArc(xx, yy, arcWidth, arcHeight, 270, 90); |
1312 |
drawArc (x, yy, arcWidth, arcHeight, 180, 90); |
drawArc(x, yy, arcWidth, arcHeight, 180, 90); |
1313 |
|
|
1314 |
int y1 = y + arcHeight / 2; |
int y1 = y + arcHeight / 2; |
1315 |
int y2 = y + height - arcHeight / 2; |
int y2 = y + height - arcHeight / 2; |
1316 |
drawLine (x, y1, x, y2); |
drawLine(x, y1, x, y2); |
1317 |
drawLine (x + width, y1, x + width, y2); |
drawLine(x + width, y1, x + width, y2); |
1318 |
|
|
1319 |
int x1 = x + arcWidth / 2; |
int x1 = x + arcWidth / 2; |
1320 |
int x2 = x + width - arcWidth / 2; |
int x2 = x + width - arcWidth / 2; |
1321 |
drawLine (x1, y, x2, y); |
drawLine(x1, y, x2, y); |
1322 |
drawLine (x1, y + height, x2, y + height); |
drawLine(x1, y + height, x2, y + height); |
1323 |
} |
} |
1324 |
|
|
1325 |
// these are the most accelerated painting paths |
// these are the most accelerated painting paths |
1326 |
native void cairoDrawGdkGlyphVector (GdkFontPeer f, GdkGlyphVector gv, float x, float y); |
native void cairoDrawGdkGlyphVector(GdkFontPeer f, GdkGlyphVector gv, |
1327 |
native void cairoDrawGdkTextLayout (GdkFontPeer f, GdkTextLayout gl, float x, float y); |
float x, float y); |
1328 |
native void cairoDrawString (GdkFontPeer f, String str, float x, float y); |
|
1329 |
|
native void cairoDrawGdkTextLayout(GdkFontPeer f, GdkTextLayout gl, float x, |
1330 |
|
float y); |
1331 |
|
|
1332 |
GdkFontPeer getFontPeer() |
native void cairoDrawString(GdkFontPeer f, String str, float x, float y); |
1333 |
|
|
1334 |
|
GdkFontPeer getFontPeer() |
1335 |
{ |
{ |
1336 |
return (GdkFontPeer) getFont().getPeer(); |
return (GdkFontPeer) getFont().getPeer(); |
1337 |
} |
} |
1338 |
|
|
1339 |
public void drawGdkGlyphVector(GdkGlyphVector gv, float x, float y) |
public void drawGdkGlyphVector(GdkGlyphVector gv, float x, float y) |
1340 |
{ |
{ |
1341 |
cairoDrawGdkGlyphVector(getFontPeer(), gv, x, y); |
cairoDrawGdkGlyphVector(getFontPeer(), gv, x, y); |
1342 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
1343 |
updateBufferedImage(); |
updateBufferedImage(); |
1344 |
} |
} |
1345 |
|
|
1346 |
public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) |
public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) |
1347 |
{ |
{ |
1348 |
cairoDrawGdkTextLayout(getFontPeer(), gl, x, y); |
cairoDrawGdkTextLayout(getFontPeer(), gl, x, y); |
1349 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
1350 |
updateBufferedImage(); |
updateBufferedImage(); |
1351 |
} |
} |
1352 |
|
|
1353 |
public void drawString (String str, float x, float y) |
public void drawString(String str, float x, float y) |
1354 |
{ |
{ |
1355 |
cairoDrawString(getFontPeer(), str, x, y); |
cairoDrawString(getFontPeer(), str, x, y); |
1356 |
if (isBufferedImageGraphics ()) |
if (isBufferedImageGraphics()) |
1357 |
updateBufferedImage(); |
updateBufferedImage(); |
1358 |
} |
} |
1359 |
|
|
1360 |
public void drawString (String str, int x, int y) |
public void drawString(String str, int x, int y) |
1361 |
{ |
{ |
1362 |
drawString (str, (float)x, (float)y); |
drawString(str, (float) x, (float) y); |
1363 |
} |
} |
1364 |
|
|
1365 |
public void drawString (AttributedCharacterIterator ci, int x, int y) |
public void drawString(AttributedCharacterIterator ci, int x, int y) |
1366 |
{ |
{ |
1367 |
drawString (ci, (float)x, (float)y); |
drawString(ci, (float) x, (float) y); |
1368 |
} |
} |
1369 |
|
|
1370 |
public void drawGlyphVector (GlyphVector gv, float x, float y) |
public void drawGlyphVector(GlyphVector gv, float x, float y) |
1371 |
{ |
{ |
1372 |
if (gv instanceof GdkGlyphVector) |
if (gv instanceof GdkGlyphVector) |
1373 |
drawGdkGlyphVector((GdkGlyphVector)gv, x, y); |
drawGdkGlyphVector((GdkGlyphVector) gv, x, y); |
1374 |
else |
else |
1375 |
throw new java.lang.UnsupportedOperationException (); |
throw new java.lang.UnsupportedOperationException(); |
1376 |
} |
} |
1377 |
|
|
1378 |
public void drawString (AttributedCharacterIterator ci, float x, float y) |
public void drawString(AttributedCharacterIterator ci, float x, float y) |
1379 |
{ |
{ |
1380 |
GlyphVector gv = font.createGlyphVector (getFontRenderContext(), ci); |
GlyphVector gv = font.createGlyphVector(getFontRenderContext(), ci); |
1381 |
drawGlyphVector (gv, x, y); |
drawGlyphVector(gv, x, y); |
1382 |
} |
} |
1383 |
|
|
1384 |
public void fillArc (int x, int y, int width, int height, |
public void fillArc(int x, int y, int width, int height, int startAngle, |
1385 |
int startAngle, int arcAngle) |
int arcAngle) |
1386 |
{ |
{ |
1387 |
fill (new Arc2D.Double((double)x, (double)y, |
fill(new Arc2D.Double((double) x, (double) y, (double) width, |
1388 |
(double)width, (double)height, |
(double) height, (double) startAngle, |
1389 |
(double)startAngle, (double)arcAngle, |
(double) arcAngle, Arc2D.OPEN)); |
|
Arc2D.OPEN)); |
|
1390 |
} |
} |
1391 |
|
|
1392 |
public void fillOval(int x, int y, int width, int height) |
public void fillOval(int x, int y, int width, int height) |
1393 |
{ |
{ |
1394 |
fillArc (x, y, width, height, 0, 360); |
fillArc(x, y, width, height, 0, 360); |
1395 |
} |
} |
1396 |
|
|
1397 |
public void fillRoundRect (int x, int y, int width, int height, |
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, |
1398 |
int arcWidth, int arcHeight) |
int arcHeight) |
1399 |
{ |
{ |
1400 |
if (arcWidth > width) |
if (arcWidth > width) |
1401 |
arcWidth = width; |
arcWidth = width; |
1405 |
int xx = x + width - arcWidth; |
int xx = x + width - arcWidth; |
1406 |
int yy = y + height - arcHeight; |
int yy = y + height - arcHeight; |
1407 |
|
|
1408 |
fillArc (x, y, arcWidth, arcHeight, 90, 90); |
fillArc(x, y, arcWidth, arcHeight, 90, 90); |
1409 |
fillArc (xx, y, arcWidth, arcHeight, 0, 90); |
fillArc(xx, y, arcWidth, arcHeight, 0, 90); |
1410 |
fillArc (xx, yy, arcWidth, arcHeight, 270, 90); |
fillArc(xx, yy, arcWidth, arcHeight, 270, 90); |
1411 |
fillArc (x, yy, arcWidth, arcHeight, 180, 90); |
fillArc(x, yy, arcWidth, arcHeight, 180, 90); |
1412 |
|
|
1413 |
fillRect (x, y + arcHeight / 2, width, height - arcHeight + 1); |
fillRect(x, y + arcHeight / 2, width, height - arcHeight + 1); |
1414 |
fillRect (x + arcWidth / 2, y, width - arcWidth + 1, height); |
fillRect(x + arcWidth / 2, y, width - arcWidth + 1, height); |
1415 |
} |
} |
1416 |
|
|
1417 |
public Font getFont () |
public Font getFont() |
1418 |
{ |
{ |
1419 |
return font; |
return font; |
1420 |
} |
} |
1422 |
// Until such time as pango is happy to talk directly to cairo, we |
// Until such time as pango is happy to talk directly to cairo, we |
1423 |
// actually need to redirect some calls from the GtkFontPeer and |
// actually need to redirect some calls from the GtkFontPeer and |
1424 |
// GtkFontMetrics into the drawing kit and ask cairo ourselves. |
// GtkFontMetrics into the drawing kit and ask cairo ourselves. |
|
|
|
1425 |
static native void releasePeerGraphicsResource(GdkFontPeer f); |
static native void releasePeerGraphicsResource(GdkFontPeer f); |
|
static native void getPeerTextMetrics (GdkFontPeer f, String str, double [] metrics); |
|
|
static native void getPeerFontMetrics (GdkFontPeer f, double [] metrics); |
|
1426 |
|
|
1427 |
public FontMetrics getFontMetrics () |
static native void getPeerTextMetrics(GdkFontPeer f, String str, |
1428 |
|
double[] metrics); |
1429 |
|
|
1430 |
|
static native void getPeerFontMetrics(GdkFontPeer f, double[] metrics); |
1431 |
|
|
1432 |
|
public FontMetrics getFontMetrics() |
1433 |
{ |
{ |
1434 |
// the reason we go via the toolkit here is to try to get |
// the reason we go via the toolkit here is to try to get |
1435 |
// a cached object. the toolkit keeps such a cache. |
// a cached object. the toolkit keeps such a cache. |
1436 |
return Toolkit.getDefaultToolkit ().getFontMetrics (font); |
return Toolkit.getDefaultToolkit().getFontMetrics(font); |
1437 |
} |
} |
1438 |
|
|
1439 |
public FontMetrics getFontMetrics (Font f) |
public FontMetrics getFontMetrics(Font f) |
1440 |
{ |
{ |
1441 |
// the reason we go via the toolkit here is to try to get |
// the reason we go via the toolkit here is to try to get |
1442 |
// a cached object. the toolkit keeps such a cache. |
// a cached object. the toolkit keeps such a cache. |
1443 |
return Toolkit.getDefaultToolkit ().getFontMetrics (f); |
return Toolkit.getDefaultToolkit().getFontMetrics(f); |
1444 |
} |
} |
1445 |
|
|
1446 |
public void setFont (Font f) |
public void setFont(Font f) |
1447 |
{ |
{ |
1448 |
if (f.getPeer() instanceof GdkFontPeer) |
if (f.getPeer() instanceof GdkFontPeer) |
1449 |
font = f; |
font = f; |
1450 |
else |
else |
1451 |
font = |
font = ((ClasspathToolkit) (Toolkit.getDefaultToolkit())).getFont(f |
1452 |
((ClasspathToolkit)(Toolkit.getDefaultToolkit ())) |
.getName(), |
1453 |
.getFont (f.getName(), f.getAttributes ()); |
f |
1454 |
|
.getAttributes()); |
1455 |
} |
} |
1456 |
|
|
1457 |
public String toString() |
public String toString() |
1458 |
{ |
{ |
1459 |
return getClass ().getName () + |
return getClass().getName() + "[font=" + font.toString() + ",color=" |
1460 |
"[font=" + font.toString () + |
+ fg.toString() + "]"; |
|
",color=" + fg.toString () + "]"; |
|
1461 |
} |
} |
|
|
|
1462 |
} |
} |