本文整理汇总了Java中java.awt.FontMetrics.getDescent方法的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics.getDescent方法的具体用法?Java FontMetrics.getDescent怎么用?Java FontMetrics.getDescent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.FontMetrics
的用法示例。
在下文中一共展示了FontMetrics.getDescent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeFont
import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
* Initialise the font to be used based on configuration
*
* @param baseFont The AWT font to render
* @param size The point size of the font to generated
* @param bold True if the font should be rendered in bold typeface
* @param italic True if the font should be rendered in bold typeface
*/
private void initializeFont(Font baseFont, int size, boolean bold, boolean italic) {
Map attributes = baseFont.getAttributes();
attributes.put(TextAttribute.SIZE, new Float(size));
attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR);
attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR);
try {
attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField(
"KERNING_ON").get(null));
} catch (Exception ignored) {
}
font = baseFont.deriveFont(attributes);
FontMetrics metrics = GlyphPage.getScratchGraphics().getFontMetrics(font);
ascent = metrics.getAscent();
descent = metrics.getDescent();
leading = metrics.getLeading();
// Determine width of space glyph (getGlyphPixelBounds gives a width of zero).
char[] chars = " ".toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width;
}
示例2: renderHtml
import java.awt.FontMetrics; //导入方法依赖的package包/类
private void renderHtml(Fix f, Graphics g, Font defaultFont, Color defaultColor,
int width, int height, boolean selected) {
if (icon != null) {
// The image of the ImageIcon should already be loaded
// so no ImageObserver should be necessary
g.drawImage(ImageUtilities.icon2Image(icon), BEFORE_ICON_GAP, (height - icon.getIconHeight()) /2, this);
}
int iconWidth = BEFORE_ICON_GAP + icon.getIconWidth() + AFTER_ICON_GAP;
int textEnd = width - AFTER_ICON_GAP - subMenuIcon.getIconWidth() - AFTER_TEXT_GAP;
FontMetrics fm = g.getFontMetrics(defaultFont);
int textY = (height - fm.getHeight())/2 + fm.getHeight() - fm.getDescent();
// Render left text
if (textEnd > iconWidth) { // any space for left text?
HtmlRenderer.renderHTML(f.getText(), g, iconWidth, textY, textEnd, textY,
defaultFont, defaultColor, HtmlRenderer.STYLE_TRUNCATE, true);//, selected);
}
if (HintsControllerImpl.getSubfixes(f).iterator().hasNext()) {
paintArrowIcon(g, textEnd + AFTER_TEXT_GAP, (height - subMenuIcon.getIconHeight()) /2);
}
}
示例3: getCaretRectangle
import java.awt.FontMetrics; //导入方法依赖的package包/类
private Rectangle getCaretRectangle(TextHitInfo caret) {
int caretLocation = 0;
TextLayout layout = composedTextLayout;
if (layout != null) {
caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
}
Graphics g = getGraphics();
FontMetrics metrics = null;
try {
metrics = g.getFontMetrics();
} finally {
g.dispose();
}
return new Rectangle(TEXT_ORIGIN_X + caretLocation,
TEXT_ORIGIN_Y - metrics.getAscent(),
0, metrics.getAscent() + metrics.getDescent());
}
示例4: getBorderInsets
import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
* Reinitialize the insets parameter with this Border's current Insets.
* @param c the component for which this border insets value applies
* @param insets the object to be reinitialized
*/
public Insets getBorderInsets(Component c, Insets insets) {
if (!(c instanceof JPopupMenu)) {
return insets;
}
FontMetrics fm;
int descent = 0;
int ascent = 16;
String title = ((JPopupMenu)c).getLabel();
if (title == null) {
insets.left = insets.top = insets.right = insets.bottom = 0;
return insets;
}
fm = c.getFontMetrics(font);
if(fm != null) {
descent = fm.getDescent();
ascent = fm.getAscent();
}
insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
return insets;
}
示例5: renderText
import java.awt.FontMetrics; //导入方法依赖的package包/类
private void renderText(Graphics2D g) {
if (this.getText() == null || this.getText().isEmpty()) {
return;
}
final FontMetrics fm = g.getFontMetrics();
double defaultTextX;
double defaultTextY = fm.getAscent() + (this.getHeight() - (fm.getAscent() + fm.getDescent())) / 2;
switch (this.getTextAlign()) {
case LEFT:
defaultTextX = this.getTextXMargin();
break;
case RIGHT:
defaultTextX = this.getWidth() - this.getTextXMargin() - fm.stringWidth(this.getTextToRender(g));
break;
case CENTER:
default:
defaultTextX = this.getWidth() / 2 - fm.stringWidth(this.getTextToRender(g)) / 2.0;
break;
}
if (this.getTextY() == 0) {
this.setTextY(defaultTextY);
}
if (this.getTextX() == 0) {
this.setTextX(defaultTextX);
}
if (this.getTextAngle() == 0) {
if (this.drawTextShadow()) {
RenderEngine.drawTextWithShadow(g, this.getTextToRender(g), this.getX() + this.getTextX(), this.getY() + this.getTextY(), this.getTextShadowColor());
} else {
RenderEngine.drawText(g, this.getTextToRender(g), this.getX() + this.getTextX(), this.getY() + this.getTextY());
}
} else if (this.getTextAngle() == 90) {
RenderEngine.drawRotatedText(g, this.getX() + this.getTextX(), this.getY() + this.getTextY() - fm.stringWidth(this.getTextToRender(g)), this.getTextAngle(), this.getTextToRender(g));
} else {
RenderEngine.drawRotatedText(g, this.getX() + this.getTextX(), this.getY() + this.getTextY(), this.getTextAngle(), this.getTextToRender(g));
}
}
示例6: getMarkSize
import java.awt.FontMetrics; //导入方法依赖的package包/类
protected int getMarkSize(Graphics g){
if (g != null){
FontMetrics fm = g.getFontMetrics(getColoring().getFont());
if (fm != null){
int ret = fm.getAscent() - fm.getDescent();
return ret - ret%2;
}
}
return -1;
}
示例7: getPreferredSize
import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
FontMetrics fm = getTxtFontMetrics();
int height = fm == null ?
19 : fm.getAscent() + 2 * fm.getDescent() + 5;
Insets insets = c.getInsets();
prefSize.height = height + insets.bottom + insets.top;
return prefSize;
}
示例8: textRight
import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
* Write the given text string in the current font, right-aligned at (<em>x</em>, <em>y</em>).
*
* @param x the <em>x</em>-coordinate of the text
* @param y the <em>y</em>-coordinate of the text
* @param text the text to write
*/
public static void textRight(double x, double y, String text) {
if (text == null) throw new IllegalArgumentException();
offscreen.setFont(font);
FontMetrics metrics = offscreen.getFontMetrics();
double xs = scaleX(x);
double ys = scaleY(y);
int ws = metrics.stringWidth(text);
int hs = metrics.getDescent();
offscreen.drawString(text, (float) (xs - ws), (float) (ys + hs));
draw();
}
示例9: getPreferredSize
import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
FontMetrics fm = getTxtFontMetrics();
int height = fm == null ?
17 : fm.getAscent() + 2 * fm.getDescent() + 3;
Insets insets = c.getInsets();
prefSize.height = height + insets.bottom + insets.top;
return prefSize;
}
示例10: medidaV
import java.awt.FontMetrics; //导入方法依赖的package包/类
private void medidaV(Graphics2D g, int l, int t) {
FontMetrics fm = g.getFontMetrics();
String vl = dono.FormateUnidadeMedida(height);
int traco = width;
int xIni = l;// + (traco) / 2;
int xFim = xIni + traco;
int yIni = t;
int yFim = t + height;
int xLin = l + (width / 2);
g.drawLine(xIni, yIni, xFim, yIni);
g.drawLine(xIni, yFim, xFim, yFim);
g.drawLine(xLin, yIni, xLin, yFim);
int degrees = isInvertido() ? 90 : -90;
int desse = isInvertido() ? 0 : fm.stringWidth(vl);
//int centra = fm.getHeight() / 2 - fm.getDescent();
int centra = fm.getHeight() - fm.getDescent();
centra = isInvertido() ? -centra : centra;
AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
Font f = new Font(g.getFont().getName(), Font.BOLD, g.getFont().getSize());
Font f2 = g.getFont();
g.setFont(f.deriveFont(at));
yIni = yIni + (height - fm.stringWidth(vl)) / 2 + desse;
g.drawString(vl, xLin + centra, yIni);
g.setFont(f2);
}
示例11: computeDimensions
import java.awt.FontMetrics; //导入方法依赖的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;
}
示例12: renderHtml
import java.awt.FontMetrics; //导入方法依赖的package包/类
private static void renderHtml(ClipboardHistoryElement f, Graphics g, Font defaultFont, Color defaultColor,
int width, int height, boolean selected) {
int textEnd = width - AFTER_ICON_GAP - AFTER_TEXT_GAP;
FontMetrics fm = g.getFontMetrics(defaultFont);
int textY = (height - fm.getHeight())/2 + fm.getHeight() - fm.getDescent();
HtmlRenderer.renderHTML(f.getNumber() + " " + StringEscapeUtils.escapeHtml(f.getShortenText()), g, 1, textY, textEnd, textY, //NOI18N
defaultFont, defaultColor, HtmlRenderer.STYLE_TRUNCATE, true);//, selected);
}
示例13: paintBorder
import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
* Paints the border for the specified component with the
* specified position and size.
* @param c the component for which this border is being painted
* @param g the paint graphics
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
if (!(c instanceof JPopupMenu)) {
return;
}
Font origFont = g.getFont();
Color origColor = g.getColor();
JPopupMenu popup = (JPopupMenu)c;
String title = popup.getLabel();
if (title == null) {
return;
}
g.setFont(font);
FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
int fontHeight = fm.getHeight();
int descent = fm.getDescent();
int ascent = fm.getAscent();
Point textLoc = new Point();
int stringWidth = SwingUtilities2.stringWidth(popup, fm,
title);
textLoc.y = y + ascent + TEXT_SPACING;
textLoc.x = x + ((width - stringWidth) / 2);
g.setColor(background);
g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
g.setColor(foreground);
SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);
MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
width, GROOVE_HEIGHT,
shadowColor, highlightColor);
g.setFont(origFont);
g.setColor(origColor);
}
示例14: bordaLeftRigth
import java.awt.FontMetrics; //导入方法依赖的package包/类
public void bordaLeftRigth(Graphics2D g, boolean isrigth) {
FontMetrics fm = g.getFontMetrics();
String vl = FormateUnidadeMedida(H);
int pre_x = (isrigth ? getLeftWidth() : getLeft());
int traco = largTraco < margem ? largTraco : margem;
traco = (isrigth ? -traco : traco);
int xIni = pre_x + (isrigth ? -2 : 2);
int xFim = xIni + 2 * traco;
int yIni = getTop() + margem;
int yFim = getTopHeight() - margem;
int xLin = xIni;
// int pre_x = (isrigth ? getLeftWidth() - margem : getLeft());
// int traco = largTraco < margem ? largTraco : margem;
// int xIni = pre_x + (margem - traco) / 2;
// int xFim = xIni + traco;
// int yIni = getTop() + margem;
// int yFim = getTopHeight() - margem;
// int xLin = pre_x + margem / 2;
g.setColor(getCorRegua());
g.drawLine(xIni, yIni, xFim, yIni);
g.drawLine(xIni, yFim, xFim, yFim);
g.drawLine(xLin, yIni, xLin, yFim);
int blc = calculeSubEspaco(W);
int sr = yIni;
xFim -= traco;
int dv = modInteiro(blc);
int subblc = 0;
if (dv > 0) {
subblc = blc / dv;
}
while (sr < yFim) {
if (dv > 0) {
int a = blc - subblc;
while (a > 0) {
if (sr + a < yFim) {
g.drawLine(xIni, sr + a, xFim - traco / 2, sr + a);
}
a -= subblc;
}
}
g.drawLine(xIni, sr, xFim, sr);
sr += blc;
}
if (isMostrarTextoRegua()) {
int degrees = isrigth ? 90 : -90;
int desse = isrigth ? 0 : fm.stringWidth(vl);
int centra = fm.getHeight() / 2 - fm.getDescent();
centra = isrigth ? -centra : centra;
AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
Font f = new Font(getFont().getName(), Font.BOLD, getFont().getSize());
g.setFont(f.deriveFont(at));
g.setColor(getForeColor());
xLin = pre_x - (isrigth ? margem / 2 : -margem / 2);
yIni = yIni + (H - fm.stringWidth(vl)) / 2 + desse;
g.drawString(vl, xLin + centra, yIni);
g.setFont(getFont());
}
}
示例15: __getDialogPadding
import java.awt.FontMetrics; //导入方法依赖的package包/类
static ImmInsets __getDialogPadding()
{
if (_sDialogPadding != null)
return _sDialogPadding;
// Create a BufferedImage that we can use to rasterize some glyphs.
int width = 40;
int height = 40;
BufferedImage image = new BufferedImage(40,
40,
BufferedImage.TYPE_INT_ARGB);
// Get the Graphics object to use to draw into the image
Graphics g = image.getGraphics();
// Clear out the image
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// Render our glyphs
g.setColor(Color.black);
g.setFont(new Font("Dialog", Font.PLAIN, 12));
FontMetrics metrics = g.getFontMetrics();
int baseline = metrics.getAscent();
g.drawString("X", 0, baseline);
// Now that we have rendered the glyphs, we examine the
// image to see how many lines of padding we've got.
int top = 0;
for (int y = 0; y < height; y++)
{
if (!_isWhiteScanline(image, y, width))
{
top = y;
break;
}
}
// Just use the descent as the bottom padding
int bottom = metrics.getDescent();
_sDialogPadding = new ImmInsets(top, 0, bottom, 0);
// Clean up
g.dispose();
image.flush();
return _sDialogPadding;
}