本文整理匯總了Java中java.awt.font.TextLayout.isLeftToRight方法的典型用法代碼示例。如果您正苦於以下問題:Java TextLayout.isLeftToRight方法的具體用法?Java TextLayout.isLeftToRight怎麽用?Java TextLayout.isLeftToRight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.font.TextLayout
的用法示例。
在下文中一共展示了TextLayout.isLeftToRight方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
}
}
示例3: drawText
import java.awt.font.TextLayout; //導入方法依賴的package包/類
private void drawText( Graphics g, int w, int h ) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.white);
g2.fillRect(0, 0, w, h);
g2.setColor(Color.black);
/// sets font, RenderingHints.
setParams( g2 );
/// If flag is set, recalculate fontMetrics and reset the scrollbar
if ( updateFontMetrics || isPrinting ) {
/// NOTE: re-calculates in case G2 transform
/// is something other than NONE
calcFontMetrics( g2, w, h );
updateFontMetrics = false;
}
/// Calculate the amount of text that can be drawn...
calcTextRange();
/// Draw according to the set "Text to Use" mode
if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
int charToDraw = drawStart;
if ( showGrid )
drawGrid( g2 );
for ( int i = 0; i < numCharDown && charToDraw <= drawEnd; i++ ) {
for ( int j = 0; j < numCharAcross && charToDraw <= drawEnd; j++, charToDraw++ ) {
int gridLocX = j * gridWidth + canvasInset_X;
int gridLocY = i * gridHeight + canvasInset_Y;
modeSpecificDrawChar( g2, charToDraw,
gridLocX + gridWidth / 2,
gridLocY + maxAscent );
}
}
}
else if ( textToUse == USER_TEXT ) {
g2.drawRect( 0, 0, w - 1, h - 1 );
for ( int i = drawStart; i <= drawEnd; i++ ) {
int lineStartX = canvasInset_Y;
int lineStartY = ( i - drawStart ) * gridHeight + maxAscent;
modeSpecificDrawLine( g2, userText[i], lineStartX, lineStartY );
}
}
else {
float xPos, yPos = (float) canvasInset_Y;
g2.drawRect( 0, 0, w - 1, h - 1 );
for ( int i = drawStart; i <= drawEnd; i++ ) {
TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i );
xPos =
oneLine.isLeftToRight() ?
canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X );
float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()};
if (g2Transform != NONE) {
AffineTransform at = getAffineTransform(g2Transform);
at.transform( fmData, 0, fmData, 0, 3);
}
//yPos += oneLine.getAscent();
yPos += fmData[1]; // ascent
//oneLine.draw( g2, xPos, yPos );
tlDrawLine( g2, oneLine, xPos, yPos );
//yPos += oneLine.getDescent() + oneLine.getLeading();
yPos += fmData[3] + fmData[5]; // descent + leading
}
}
g2.dispose();
}