本文整理汇总了Java中java.awt.Graphics2D.drawChars方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawChars方法的具体用法?Java Graphics2D.drawChars怎么用?Java Graphics2D.drawChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.drawChars方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintVisel
import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintVisel(Graphics2D g2) {
super.paintVisel(g2);
double labelX = (x+x2)/2,
labelY = (y+y2)/2;
g2.drawChars(label.toCharArray(),0,label.length(),(int)labelX,(int)(labelY+20));
}
示例2: paintImpl
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* Does the dirty-work of actually painting the token.
*/
protected float paintImpl(Token token, Graphics2D g, float x, float y,
RSyntaxTextArea host, TabExpander e, float clipStart,
boolean selected, boolean useSTC) {
int origX = (int)x;
int textOffs = token.getTextOffset();
char[] text = token.getTextArray();
int end = textOffs + token.length();
float nextX = x;
int flushLen = 0;
int flushIndex = textOffs;
Color fg = useSTC ? host.getSelectedTextColor() :
host.getForegroundForToken(token);
Color bg = selected ? null : host.getBackgroundForToken(token);
g.setFont(host.getFontForTokenType(token.getType()));
FontMetrics fm = host.getFontMetricsForTokenType(token.getType());
for (int i=textOffs; i<end; i++) {
switch (text[i]) {
case '\t':
nextX = e.nextTabStop(
x + fm.charsWidth(text, flushIndex,flushLen), 0);
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
}
if (flushLen > 0) {
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
flushLen = 0;
}
flushIndex = i + 1;
x = nextX;
break;
default:
flushLen += 1;
break;
}
}
nextX = x+fm.charsWidth(text, flushIndex,flushLen);
java.awt.Rectangle r = host.getMatchRectangle();
if (flushLen>0 && nextX>=clipStart) {
if (bg!=null) {
paintBackground(x,y, nextX-x,fm.getHeight(),
g, fm.getAscent(), host, bg);
if (token.length()==1 && r!=null && r.x==x) {
((RSyntaxTextAreaUI)host.getUI()).paintMatchedBracketImpl(
g, host, r);
}
}
g.setColor(fg);
g.drawChars(text, flushIndex, flushLen, (int)x,(int)y);
}
if (host.getUnderlineForToken(token)) {
g.setColor(fg);
int y2 = (int)(y+1);
g.drawLine(origX,y2, (int)nextX,y2);
}
// Don't check if it's whitespace - some TokenMakers may return types
// other than Token.WHITESPACE for spaces (such as Token.IDENTIFIER).
// This also allows us to paint tab lines for MLC's.
if (host.getPaintTabLines() && origX==host.getMargin().left) {// && isWhitespace()) {
paintTabLines(token, origX, (int)y, (int)nextX, g, e, host);
}
return nextX;
}
示例3: modeSpecificDrawLine
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void modeSpecificDrawLine( Graphics2D g2, String line,
int baseX, int baseY ) {
/// ABP - keep track of old tform, restore it later
AffineTransform oldTx = null;
oldTx = g2.getTransform();
g2.translate( baseX, baseY );
g2.transform( getAffineTransform( g2Transform ) );
switch ( drawMethod ) {
case DRAW_STRING:
g2.drawString( line, 0, 0 );
break;
case DRAW_CHARS:
g2.drawChars( line.toCharArray(), 0, line.length(), 0, 0 );
break;
case DRAW_BYTES:
try {
byte lineBytes[] = line.getBytes( "ISO-8859-1" );
g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 );
}
catch ( Exception e ) {
e.printStackTrace();
}
break;
case DRAW_GLYPHV:
GlyphVector gv =
testFont.createGlyphVector( g2.getFontRenderContext(), line );
g2.drawGlyphVector( gv, (float) 0, (float) 0 );
break;
case TL_DRAW:
TextLayout tl = new TextLayout( line, testFont,
g2.getFontRenderContext() );
tl.draw( g2, (float) 0, (float) 0 );
break;
case GV_OUTLINE:
GlyphVector gvo =
testFont.createGlyphVector( g2.getFontRenderContext(), line );
g2.draw( gvo.getOutline( (float) 0, (float) 0 ));
break;
case TL_OUTLINE:
TextLayout tlo =
new TextLayout( line, testFont,
g2.getFontRenderContext() );
AffineTransform at = new AffineTransform();
g2.draw( tlo.getOutline( at ));
}
/// ABP - restore old tform
g2.setTransform ( oldTx );
}
示例4: runTest
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void runTest() {
im = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = im.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, W, H);
g2d.setColor(Color.black);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
char[] chs = "Sample Text.".toCharArray();
int len = chs.length;
int x = 50, y = 100;
FontRenderContext frc = g2d.getFontRenderContext();
Font plain = new Font("Serif", Font.PLAIN, 48);
GlyphVector pgv = plain.layoutGlyphVector(frc, chs, 0, len, 0);
g2d.setFont(plain);
g2d.drawChars(chs, 0, len, x, y); y +=50;
g2d.drawGlyphVector(pgv, x, y); y += 50;
Rectangle2D plainStrBounds = plain.getStringBounds(chs, 0, len, frc);
Rectangle2D plainGVBounds = pgv.getLogicalBounds();
Font bold = new Font("Serif", Font.BOLD, 48);
GlyphVector bgv = bold.layoutGlyphVector(frc, chs, 0, len, 0);
Rectangle2D boldStrBounds = bold.getStringBounds(chs, 0, len, frc);
Rectangle2D boldGVBounds = bgv.getLogicalBounds();
g2d.setFont(bold);
g2d.drawChars(chs, 0, len, x, y); y +=50;
g2d.drawGlyphVector(bgv, x, y);
System.out.println("Plain String Bounds = " + plainStrBounds);
System.out.println("Bold String Bounds = " + boldStrBounds);
System.out.println("Plain GlyphVector Bounds = " + plainGVBounds);
System.out.println("Bold GlyphVector Bounds = " + boldGVBounds);
if (!plainStrBounds.equals(boldStrBounds) &&
plainGVBounds.equals(boldGVBounds))
{
System.out.println("Test failed: Plain GV bounds same as Bold");
if (!interactive) {
throw new RuntimeException("Plain GV bounds same as Bold");
}
}
}