本文整理汇总了Java中java.awt.font.TextLayout.draw方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.draw方法的具体用法?Java TextLayout.draw怎么用?Java TextLayout.draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.TextLayout
的用法示例。
在下文中一共展示了TextLayout.draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawString
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawString(AttributedCharacterIterator iterator,
float x, float y) {
if (iterator == null) {
throw new NullPointerException("AttributedCharacterIterator is null");
}
if (iterator.getBeginIndex() == iterator.getEndIndex()) {
return; /* nothing to draw */
}
TextLayout tl = new TextLayout(iterator, getFontRenderContext());
tl.draw(this, x, y);
}
示例2: drawStringUsingShapes
import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void drawStringUsingShapes(AttributedCharacterIterator iterator, float x, float y) {
Stroke originalStroke = stroke;
Paint originalPaint = paint;
TextLayout textLayout = new TextLayout(iterator, getFontRenderContext());
textLayout.draw(this, x, y);
paint = originalPaint;
stroke = originalStroke;
}
示例3: render
import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public void render(final Graphics2D g) {
if (this.displayedText == null || this.displayedText.isEmpty() || !Game.getRenderEngine().canRender(this.entity)) {
return;
}
final Point2D location = Game.getCamera().getViewPortLocation(this.entity);
RenderEngine.renderImage(g, this.bubble, new Point2D.Double(location.getX() + this.entity.getWidth() / 2.0 - this.textBoxWidth / 2.0 - PADDING, location.getY() - this.height - PADDING));
g.setColor(SPEAK_FONT_COLOR);
final FontRenderContext frc = g.getFontRenderContext();
final String text = this.displayedText;
final AttributedString styledText = new AttributedString(text);
styledText.addAttribute(TextAttribute.FONT, this.font);
final AttributedCharacterIterator iterator = styledText.getIterator();
final LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
measurer.setPosition(0);
final float x = (float) Game.getCamera().getViewPortLocation(this.entity).getX() + this.entity.getWidth() / 2.0f - this.textBoxWidth / 2.0f;
float y = (float) Game.getCamera().getViewPortLocation(this.entity).getY() - this.height;
while (measurer.getPosition() < text.length()) {
final TextLayout layout = measurer.nextLayout(this.textBoxWidth);
y += layout.getAscent();
final float dx = layout.isLeftToRight() ? 0 : this.textBoxWidth - layout.getAdvance();
layout.draw(g, x + dx, y);
y += layout.getDescent() + layout.getLeading();
}
}
示例4: paint
import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
if (c.isOpaque()) {
ImageLibrary.drawTiledImage("image.background.FreeColToolTip", g, c, null);
}
g.setColor(Color.BLACK); // FIXME: find out why this is necessary
Graphics2D graphics = (Graphics2D)g;
float x = margin;
float y = margin;
for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
if (line.isEmpty()) {
y += LEADING;
continue;
}
AttributedCharacterIterator styledText =
new AttributedString(line).getIterator();
LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);
while (measurer.getPosition() < styledText.getEndIndex()) {
TextLayout layout = measurer.nextLayout(maximumWidth);
y += (layout.getAscent());
float dx = layout.isLeftToRight() ?
0 : (maximumWidth - layout.getAdvance());
layout.draw(graphics, x + dx, y);
y += layout.getDescent() + layout.getLeading();
}
}
}
示例5: paintTextLayout
import java.awt.font.TextLayout; //导入方法依赖的package包/类
static void paintTextLayout(Graphics2D g, Rectangle2D textLayoutBounds,
TextLayout textLayout, DocumentView docView)
{
float x = (float) textLayoutBounds.getX();
float ascentedY = (float) (textLayoutBounds.getY() + docView.op.getDefaultAscent());
// TextLayout is unable to do a partial render
// Both x and ascentedY should already be floor/ceil-ed
textLayout.draw(g, x, ascentedY);
}
示例6: tlDrawLine
import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void tlDrawLine( Graphics2D g2, TextLayout tl,
float baseX, float baseY ) {
/// ABP - keep track of old tform, restore it later
AffineTransform oldTx = null;
oldTx = g2.getTransform();
g2.translate( baseX, baseY );
g2.transform( getAffineTransform( g2Transform ) );
tl.draw( g2, (float) 0, (float) 0 );
/// ABP - restore old tform
g2.setTransform ( oldTx );
}
示例7: drawChars
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawChars(SunGraphics2D sg2d,
char data[], int offset, int length,
int ix, int iy)
{
FontInfo info = sg2d.getFontInfo();
float x, y;
if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
SurfaceData.outlineTextRenderer.drawChars(
sg2d, data, offset, length, ix, iy);
return;
}
if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
double origin[] = {ix + info.originX, iy + info.originY};
sg2d.transform.transform(origin, 0, origin, 0, 1);
x = (float) origin[0];
y = (float) origin[1];
} else {
x = ix + info.originX + sg2d.transX;
y = iy + info.originY + sg2d.transY;
}
GlyphList gl = GlyphList.getInstance();
if (gl.setFromChars(info, data, offset, length, x, y)) {
drawGlyphList(sg2d, gl);
gl.dispose();
} else {
gl.dispose(); // release this asap.
TextLayout tl = new TextLayout(new String(data, offset, length),
sg2d.getFont(),
sg2d.getFontRenderContext());
tl.draw(sg2d, ix, iy);
}
}
示例8: drawString
import java.awt.font.TextLayout; //导入方法依赖的package包/类
private static void drawString(Graphics2D g, Font font, String value, float x, float y) {
AttributedString str = new AttributedString(value);
str.addAttribute(TextAttribute.FOREGROUND, Color.BLACK);
str.addAttribute(TextAttribute.FONT, font);
FontRenderContext frc = new FontRenderContext(null, true, true);
TextLayout layout = new LineBreakMeasurer(str.getIterator(), frc).nextLayout(Integer.MAX_VALUE);
layout.draw(g, x, y);
}
示例9: paint
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void paint(Graphics g) {
super.paint(g);
g.setColor(getForeground());
TextLayout layout = composedTextLayout;
if (layout != null) {
layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
}
if (caret != null) {
Rectangle rectangle = getCaretRectangle(caret);
g.setXORMode(getBackground());
g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
g.setPaintMode();
}
}
示例10: drawString
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawString(AttributedCharacterIterator iterator,
float x, float y) {
if (iterator == null) {
throw
new NullPointerException("attributedcharacteriterator is null");
}
TextLayout layout =
new TextLayout(iterator, getFontRenderContext());
layout.draw(this, x, y);
}
示例11: drawString
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawString(String str, float x, float y) {
if (str.length() == 0) {
return;
}
TextLayout layout =
new TextLayout(str, getFont(), getFontRenderContext());
layout.draw(this, x, y);
}
示例12: paint
import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
if (allocBounds.intersects(clipBounds)) {
Font origFont = g.getFont();
Color origColor = g.getColor();
Color origBkColor = g.getBackground();
Shape origClip = g.getClip();
try {
// Leave component font
g.setBackground(getBackgroundColor());
int xInt = (int) allocBounds.getX();
int yInt = (int) allocBounds.getY();
int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
g.setColor(getBorderColor());
g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
g.setColor(getForegroundColor());
g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
g.clip(alloc);
TextLayout textLayout = getTextLayout();
if (textLayout != null) {
EditorView.Parent parent = (EditorView.Parent) getParent();
float ascent = parent.getViewRenderContext().getDefaultAscent();
String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
float y = (float) allocBounds.getY();
if (desc.length() > 0) {
textLayout.draw(g, x, y + ascent);
}
}
} finally {
g.setClip(origClip);
g.setBackground(origBkColor);
g.setColor(origColor);
g.setFont(origFont);
}
}
}
示例13: draw
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void draw(Graphics2D g, int align, int pos, float fRectHeight,
MovingArea area) {
float left = 0;
float fromY = 0;
if (pos == 1)
fromY += fRectHeight / 2 - height / 2;
else if (pos == 2)
fromY += fRectHeight;
if (fromY < 0)
fromY = 0;
int size = layouts.size();
for (int i = 0; i < size; i++) {
TextLayout textLayout = layouts.get(i);
if (align == Line.CENTER_ALIGN)
left = (float) maxWidth / 2f - textLayout.getAdvance() / 2f;
else if (align == Line.RIGHT_ALIGN)
left = (float) maxWidth - textLayout.getAdvance();
fromY += textLayout.getAscent();
if (fromY >= fRectHeight && i + 1 < size)
break;
if (fromY + textLayout.getAscent() + textLayout.getDescent()
// + textLayout.getLeading()
>= fRectHeight
&& i + 1 < size) {
// textLayout= textLayout.getJustifiedLayout(maxWidth-20);
textLayout.draw(g, left, fromY);
/*
* Color color = g.getColor(); g.setColor(new Color(120, 120,
* 120));
*
* g.drawString("(.)", left + textLayout.getAdvance() + (float)
* area.getIDoubleOrdinate(-0.0), fromY); g.setColor(color);
*/
break;
} else
textLayout.draw(g, left, fromY);
fromY += textLayout.getDescent() + textLayout.getLeading();
}
}
示例14: drawWithSel
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawWithSel(Graphics2D g, int align, int pos,
float fRectHeight, MovingArea area, int[][] found) {
float left = 0;
float fromY = 0;
if (pos == 1)
fromY += fRectHeight / 2 - height / 2;
else if (pos == 2)
fromY += fRectHeight;
if (fromY < 0)
fromY = 0;
int size = layouts.size();
in = false;
int selIndex = 0;
for (int i = 0; i < size; i++) {
TextLayout textLayout = layouts.get(i);
if (align == Line.CENTER_ALIGN)
left = (float) maxWidth / 2f - textLayout.getAdvance() / 2f;
else if (align == Line.RIGHT_ALIGN)
left = (float) maxWidth - textLayout.getAdvance();
fromY += textLayout.getAscent();
if (fromY >= fRectHeight && i + 1 < size)
break;
if (fromY + textLayout.getAscent() + textLayout.getDescent() >= fRectHeight
&& i + 1 < size) {
textLayout.draw(g, left, fromY);
selIndex = drawSels(g, found, selIndex, i, textLayout, left,
fromY);
break;
} else {
textLayout.draw(g, left, fromY);
selIndex = drawSels(g, found, selIndex, i, textLayout, left,
fromY);
}
fromY += textLayout.getDescent() + textLayout.getLeading();
}
}
示例15: drawString
import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
* Draws the text given by the specified iterator, using this
* graphics context's current color. The iterator has to specify a font
* for each character. The baseline of the
* first character is at position (<i>x</i>, <i>y</i>) in this
* graphics context's coordinate system.
* The rendering attributes applied include the clip, transform,
* paint or color, and composite attributes.
* For characters in script systems such as Hebrew and Arabic,
* the glyphs may be draw from right to left, in which case the
* coordinate supplied is the location of the leftmost character
* on the baseline.
* @param iterator the iterator whose text is to be drawn
* @param x,y the coordinates where the iterator's text should be drawn.
* @see #setPaint
* @see java.awt.Graphics#setColor
* @see #setTransform
* @see #setComposite
* @see #setClip
*/
public void drawString(AttributedCharacterIterator iterator,
float x, float y) {
if (iterator == null) {
throw new
NullPointerException("AttributedCharacterIterator is null");
}
TextLayout layout = new TextLayout(iterator, getFontRenderContext());
layout.draw(this, x, y);
}