本文整理汇总了Java中java.awt.font.TextLayout.getBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TextLayout.getBounds方法的具体用法?Java TextLayout.getBounds怎么用?Java TextLayout.getBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.TextLayout
的用法示例。
在下文中一共展示了TextLayout.getBounds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTest
import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
TLContext tlctx = (TLContext)ctx;
TextLayout tl = tlctx.tl;
Rectangle2D r;
do {
r = tl.getBounds();
} while (--numReps >= 0);
}
示例2: computeDimensions
import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void computeDimensions(Graphics g, Font font, FontMetrics fm) {
String s = text;
FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
width = fm.stringWidth(s);
ascent = fm.getAscent();
descent = fm.getDescent();
int[] xs = new int[s.length()];
int[] ys = new int[s.length()];
for (int i = 0; i < xs.length; i++) {
xs[i] = fm.stringWidth(s.substring(0, i + 1));
TextLayout lay = new TextLayout(s.substring(i, i + 1), font, frc);
Rectangle2D rect = lay.getBounds();
int asc = (int) Math.ceil(-rect.getMinY());
int desc = (int) Math.ceil(rect.getMaxY());
if (asc < 0)
asc = 0;
if (asc > 0xFFFF)
asc = 0xFFFF;
if (desc < 0)
desc = 0;
if (desc > 0xFFFF)
desc = 0xFFFF;
ys[i] = (asc << 16) | desc;
}
charX = xs;
charY = ys;
dimsKnown = true;
}
示例3: textLayoutDump
import java.awt.font.TextLayout; //导入方法依赖的package包/类
private static String textLayoutDump(TextLayout textLayout) {
return "\n TL.getAdvance()=" + textLayout.getAdvance() + // NOI18N
"\n TL.getBounds()=" + textLayout.getBounds() + // NOI18N
"\n TL: " + textLayout; // NOI18N
}
示例4: paintComponent
import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void paintComponent(Graphics g) {
updateSizes();
Graphics2D g2d = (Graphics2D) g;
chatDisplay.removeOldMessages();
Dimension size = getSize();
if (freeColClient.isMapEditor()) {
if (hasMap()) {
mapViewer.displayMap(g2d);
} else {
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
}
} else if (freeColClient.isInGame() && hasMap()) {
mapViewer.displayMap(g2d);
// Grey out the map if it is not my turn (and a multiplayer game).
if (!freeColClient.currentPlayerIsMyPlayer()) {
if (greyLayer == null) {
greyLayer = new GrayLayer(freeColClient);
}
if (greyLayer.getParent() == null) {
add(greyLayer, JLayeredPane.DRAG_LAYER);
}
greyLayer.setBounds(0, 0, size.width, size.height);
greyLayer.setPlayer(freeColClient.getGame().getCurrentPlayer());
} else {
if (greyLayer != null && greyLayer.getParent() != null) {
removeFromCanvas(greyLayer);
}
}
// paint chat display
chatDisplay.display(g2d, mapViewer.getImageLibrary(), size);
} else {
/* main menu */
// TODO: Check if its right to sometimes have an unfocused map
// ingame and end up here after clicking outside map.
final String bgImageKey = "image.flavor.Canvas.map";
if (ResourceManager.hasImageResource(bgImageKey)) {
// Get the background without scaling, to avoid wasting
// memory needlessly keeping an unbounded number of rescaled
// versions of the largest image in FreeCol, forever.
final Image bgImage = ResourceManager.getImage(bgImageKey);
// Draw background image with scaling.
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(bgImage, 0, 0, size.width, size.height, this);
String versionStr = "v. " + FreeCol.getVersion();
Font oldFont = g2d.getFont();
Color oldColor = g2d.getColor();
Font newFont = oldFont.deriveFont(Font.BOLD);
TextLayout layout = new TextLayout(versionStr, newFont,
g2d.getFontRenderContext());
Rectangle2D bounds = layout.getBounds();
float x = size.width - (float) bounds.getWidth() - 5;
float y = size.height - (float) bounds.getHeight();
g2d.setColor(Color.white);
layout.draw(g2d, x, y);
g2d.setFont(oldFont);
g2d.setColor(oldColor);
} else {
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, size.width, size.height);
}
}
}