215 |
GdkGraphics2D(GtkComponentPeer component) |
GdkGraphics2D(GtkComponentPeer component) |
216 |
{ |
{ |
217 |
this.component = component; |
this.component = component; |
218 |
|
|
|
setFont(new Font("SansSerif", Font.PLAIN, 12)); |
|
|
|
|
219 |
if (component.isRealized()) |
if (component.isRealized()) |
220 |
initComponentGraphics2D(); |
initComponentGraphics2D(); |
221 |
else |
else |
232 |
setTransform(new AffineTransform()); |
setTransform(new AffineTransform()); |
233 |
setStroke(new BasicStroke()); |
setStroke(new BasicStroke()); |
234 |
setRenderingHints(getDefaultHints()); |
setRenderingHints(getDefaultHints()); |
235 |
|
setFont(new Font("SansSerif", Font.PLAIN, 12)); |
236 |
|
|
237 |
stateStack = new Stack(); |
stateStack = new Stack(); |
238 |
} |
} |
1325 |
} |
} |
1326 |
|
|
1327 |
// these are the most accelerated painting paths |
// these are the most accelerated painting paths |
1328 |
native void cairoDrawGdkGlyphVector(GdkFontPeer f, GdkGlyphVector gv, |
native void cairoDrawGlyphVector(GdkFontPeer font, |
1329 |
float x, float y); |
float x, float y, int n, |
1330 |
|
int[] codes, float[] positions); |
|
native void cairoDrawGdkTextLayout(GdkFontPeer f, GdkTextLayout gl, float x, |
|
|
float y); |
|
1331 |
|
|
1332 |
native void cairoDrawString(GdkFontPeer f, String str, float x, float y); |
native void cairoDrawGdkTextLayout(GdkTextLayout gl, |
1333 |
|
float x, float y); |
1334 |
|
|
1335 |
GdkFontPeer getFontPeer() |
GdkFontPeer getFontPeer() |
1336 |
{ |
{ |
1337 |
return (GdkFontPeer) getFont().getPeer(); |
return (GdkFontPeer) getFont().getPeer(); |
1338 |
} |
} |
1339 |
|
|
|
public void drawGdkGlyphVector(GdkGlyphVector gv, float x, float y) |
|
|
{ |
|
|
cairoDrawGdkGlyphVector(getFontPeer(), gv, x, y); |
|
|
updateBufferedImage(); |
|
|
} |
|
|
|
|
1340 |
public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) |
public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) |
1341 |
{ |
{ |
1342 |
cairoDrawGdkTextLayout(getFontPeer(), gl, x, y); |
cairoDrawGdkTextLayout (gl, x, y); |
1343 |
updateBufferedImage(); |
updateBufferedImage (); |
1344 |
} |
} |
1345 |
|
|
1346 |
public void drawString(String str, float x, float y) |
public void drawString(String str, float x, float y) |
1347 |
{ |
{ |
1348 |
cairoDrawString(getFontPeer(), str, x, y); |
drawGlyphVector(getFont().createGlyphVector(null, str), x, y); |
1349 |
updateBufferedImage(); |
updateBufferedImage (); |
1350 |
} |
} |
1351 |
|
|
1352 |
public void drawString(String str, int x, int y) |
public void drawString(String str, int x, int y) |
1353 |
{ |
{ |
1354 |
drawString(str, (float) x, (float) y); |
drawString (str, (float) x, (float) y); |
1355 |
} |
} |
1356 |
|
|
1357 |
public void drawString(AttributedCharacterIterator ci, int x, int y) |
public void drawString(AttributedCharacterIterator ci, int x, int y) |
1358 |
{ |
{ |
1359 |
drawString(ci, (float) x, (float) y); |
drawString (ci, (float) x, (float) y); |
1360 |
} |
} |
1361 |
|
|
1362 |
public void drawGlyphVector(GlyphVector gv, float x, float y) |
public void drawGlyphVector(GlyphVector gv, float x, float y) |
1363 |
{ |
{ |
1364 |
if (gv instanceof GdkGlyphVector) |
int n = gv.getNumGlyphs (); |
1365 |
drawGdkGlyphVector((GdkGlyphVector) gv, x, y); |
int[] codes = gv.getGlyphCodes (0, n, null); |
1366 |
else |
float[] positions = gv.getGlyphPositions (0, n, null); |
1367 |
throw new java.lang.UnsupportedOperationException(); |
|
1368 |
|
setFont (gv.getFont ()); |
1369 |
|
cairoDrawGlyphVector (getFontPeer(), x, y, n, codes, positions); |
1370 |
|
updateBufferedImage (); |
1371 |
} |
} |
1372 |
|
|
1373 |
public void drawString(AttributedCharacterIterator ci, float x, float y) |
public void drawString(AttributedCharacterIterator ci, float x, float y) |
1374 |
{ |
{ |
1375 |
GlyphVector gv = font.createGlyphVector(getFontRenderContext(), ci); |
GlyphVector gv = getFont().createGlyphVector(getFontRenderContext(), ci); |
1376 |
drawGlyphVector(gv, x, y); |
drawGlyphVector(gv, x, y); |
1377 |
} |
} |
1378 |
|
|
1411 |
|
|
1412 |
public Font getFont() |
public Font getFont() |
1413 |
{ |
{ |
1414 |
|
if (font == null) |
1415 |
|
return new Font("SansSerif", Font.PLAIN, 12); |
1416 |
return font; |
return font; |
1417 |
} |
} |
1418 |
|
|
1422 |
|
|
1423 |
static native void releasePeerGraphicsResource(GdkFontPeer f); |
static native void releasePeerGraphicsResource(GdkFontPeer f); |
1424 |
|
|
|
static native void getPeerTextMetrics(GdkFontPeer f, String str, |
|
|
double[] metrics); |
|
|
|
|
|
static native void getPeerFontMetrics(GdkFontPeer f, double[] metrics); |
|
|
|
|
1425 |
public FontMetrics getFontMetrics() |
public FontMetrics getFontMetrics() |
1426 |
{ |
{ |
1427 |
// the reason we go via the toolkit here is to try to get |
return getFontMetrics(getFont()); |
|
// a cached object. the toolkit keeps such a cache. |
|
|
return Toolkit.getDefaultToolkit().getFontMetrics(font); |
|
1428 |
} |
} |
1429 |
|
|
1430 |
public FontMetrics getFontMetrics(Font f) |
public FontMetrics getFontMetrics(Font f) |
1447 |
public String toString() |
public String toString() |
1448 |
{ |
{ |
1449 |
return (getClass().getName() |
return (getClass().getName() |
1450 |
+ "[font=" + font.toString() |
+ "[font=" + getFont().toString() |
1451 |
+ ",color=" + fg.toString() |
+ ",color=" + fg.toString() |
1452 |
+ "]"); |
+ "]"); |
1453 |
} |
} |