本文整理汇总了Java中java.awt.font.LineMetrics.getAscent方法的典型用法代码示例。如果您正苦于以下问题:Java LineMetrics.getAscent方法的具体用法?Java LineMetrics.getAscent怎么用?Java LineMetrics.getAscent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.LineMetrics
的用法示例。
在下文中一共展示了LineMetrics.getAscent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintComponent
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, fpd.width, fpd.height);
g.setColor(Color.RED);
FontRenderContext frc = ((Graphics2D)g).getFontRenderContext();
LineMetrics lm = f.getLineMetrics(fps, frc);
int h = (int)(fpd.height - 20 - lm.getAscent());
g.drawLine(20, h, fpd.width - 20, h);
h = fpd.height - 20;
g.drawLine(20, h, fpd.width - 20, h);
h = (int)(fpd.height - 20 + lm.getDescent());
g.drawLine(20, h, fpd.width - 20, h);
g.setColor(Color.BLACK);
g.setFont(f);
g.drawString(fps, 50, fpd.height - 20);
}
示例2: getLogicalBounds
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
public Rectangle2D getLogicalBounds() {
setFRCTX();
initPositions();
LineMetrics lm = font.getLineMetrics("", frc);
float minX, minY, maxX, maxY;
// horiz only for now...
minX = 0;
minY = -lm.getAscent();
maxX = 0;
maxY = lm.getDescent() + lm.getLeading();
if (glyphs.length > 0) {
maxX = positions[positions.length - 2];
}
return new Rectangle2D.Float(minX, minY, maxX - minX, maxY - minY);
}
示例3: getLogicalBounds
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
@Override
public Rectangle2D getLogicalBounds() {
initPositions();
LineMetrics lm = font.getLineMetrics("", frc);
float minX, minY, maxX, maxY;
// horiz only for now...
minX = 0;
minY = -lm.getAscent();
maxX = 0;
maxY = lm.getDescent() + lm.getLeading();
if (glyphs.length() > 0) {
maxX = positions[positions.length - 2];
}
return new Rectangle2D.Float(minX, minY, maxX - minX, maxY - minY);
}
示例4: GVTLineMetrics
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* Constructs a GVTLineMetrics object based on the specified line metrics
* with a scale factor applied.
*
* @param lineMetrics The lineMetrics object that this metrics object will
* be based upon.
* @param scaleFactor The scale factor to apply to all metrics.
*/
public GVTLineMetrics(LineMetrics lineMetrics, float scaleFactor) {
this.ascent = lineMetrics.getAscent() * scaleFactor;
this.baselineIndex = lineMetrics.getBaselineIndex();
this.baselineOffsets = lineMetrics.getBaselineOffsets();
for (int i=0; i<baselineOffsets.length; i++) {
this.baselineOffsets[i] *= scaleFactor;
}
this.descent = lineMetrics.getDescent() * scaleFactor;
this.height = lineMetrics.getHeight() * scaleFactor;
this.leading = lineMetrics.getLeading();
this.numChars = lineMetrics.getNumChars();
this.strikethroughOffset =
lineMetrics.getStrikethroughOffset() * scaleFactor;
this.strikethroughThickness =
lineMetrics.getStrikethroughThickness() * scaleFactor;
this.underlineOffset = lineMetrics.getUnderlineOffset() * scaleFactor;
this.underlineThickness =
lineMetrics.getUnderlineThickness() * scaleFactor;
this.overlineOffset = -this.ascent;
this.overlineThickness = this.underlineThickness;
}
示例5: calculateBaselineOffset
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* Calculates the vertical offset between the baseline and the specified
* text anchor.
*
* @param g2 the graphics device.
* @param anchor the anchor.
*
* @return the offset.
*/
public float calculateBaselineOffset(Graphics2D g2, TextAnchor anchor) {
float result = 0.0f;
FontMetrics fm = g2.getFontMetrics(this.font);
LineMetrics lm = fm.getLineMetrics("ABCxyz", g2);
if (anchor.isTop()) {
result = lm.getAscent();
}
else if (anchor.isHalfAscent()) {
result = lm.getAscent() / 2.0f;
}
else if (anchor.isVerticalCenter()) {
result = lm.getAscent() / 2.0f - lm.getDescent() / 2.0f;
}
else if (anchor.isBottom()) {
result = -lm.getDescent() - lm.getLeading();
}
return result;
}
示例6: measureString
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private static int[] measureString(Font f,String s) {
int[] ret = new int[3];
if(dummyImg==null) {
dummyImg = new BufferedImage(8,8,BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)dummyImg.getGraphics();
//g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON);
frc = g.getFontRenderContext();
g.dispose();
}
LineMetrics lm = f.getLineMetrics(s,frc);
Rectangle2D bounds = f.getStringBounds(s, frc);
ret[0] = (int)(bounds.getWidth()+0.5);
ret[1] = (int)(bounds.getHeight()+0.5);
ret[2] = (int)(lm.getAscent()+0.5);
return ret;
}
示例7: paintComponent
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int h = getHeight();
int width = getWidth();
Polygon arrow = new Polygon();
// Polygon leftArrow = new Polygon();
// g2.drawImage(closed, PAD, 0, h, h, this);
g2.setFont(font);
FontRenderContext frc = g2.getFontRenderContext();
LineMetrics lm = font.getLineMetrics(title, frc);
float height = lm.getAscent() + lm.getDescent();
float x = OFFSET;
float y = (h + height) / 2 - lm.getDescent();
g2.drawString(title, x, y);
int th = ((int)height)-2;
if (selected) {
arrow.addPoint(width - 3*th/2 + 1, h/2 - th/4);
arrow.addPoint(width - th/2 - 1, h/2 - th/4);
arrow.addPoint(width - th, h/2 + th/4 );
g2.fillPolygon(arrow);
}
// g2.drawImage(open, PAD, 0, h, h, this);
else {
arrow.addPoint(width - 3*th/4, h/2 - (th-2)/2);
arrow.addPoint(width - 3*th/4, h/2 + (th-2)/2);
arrow.addPoint(width - 5*th/4, h /2);
g2.fillPolygon(arrow);
}
}
示例8: drawLabel
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* Draws the label for one axis.
*
* @param g2 the graphics device.
* @param plotArea the plot area
* @param value the value of the label (ignored).
* @param cat the category (zero-based index).
* @param startAngle the starting angle.
* @param extent the extent of the arc.
*/
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
int cat, double startAngle, double extent) {
FontRenderContext frc = g2.getFontRenderContext();
String label = null;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
// if series are in rows, then the categories are the column keys
label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
}
else {
// if series are in columns, then the categories are the row keys
label = this.labelGenerator.generateRowLabel(this.dataset, cat);
}
Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
double ascent = lm.getAscent();
Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
plotArea, startAngle);
Composite saveComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1.0f));
g2.setPaint(getLabelPaint());
g2.setFont(getLabelFont());
g2.drawString(label, (float) labelLocation.getX(),
(float) labelLocation.getY());
g2.setComposite(saveComposite);
}
示例9: drawLabel
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* Draws the label for one axis.
*
* @param g2 the graphics device.
* @param plotArea the plot area
* @param value the value of the label (ignored).
* @param cat the category (zero-based index).
* @param startAngle the starting angle.
* @param extent the extent of the arc.
*/
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
int cat, double startAngle, double extent) {
FontRenderContext frc = g2.getFontRenderContext();
String label;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
// if series are in rows, then the categories are the column keys
label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
}
else {
// if series are in columns, then the categories are the row keys
label = this.labelGenerator.generateRowLabel(this.dataset, cat);
}
Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
double ascent = lm.getAscent();
Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
plotArea, startAngle);
Composite saveComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
1.0f));
g2.setPaint(getLabelPaint());
g2.setFont(getLabelFont());
g2.drawString(label, (float) labelLocation.getX(),
(float) labelLocation.getY());
g2.setComposite(saveComposite);
}
示例10: drawText
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private void drawText(Graphics graphics)
{
GameTreePanel.Label labelMode = m_gameTreePanel.getLabelMode();
if (labelMode == GameTreePanel.Label.NONE)
return;
Move move = m_node.getMove();
int size = m_gameTreePanel.getNodeSize();
String text;
if (labelMode == GameTreePanel.Label.MOVE)
{
if (move.getPoint() == null)
return;
text = move.getPoint().toString();
}
else
text = Integer.toString(m_moveNumber);
FontMetrics fontMetrics = graphics.getFontMetrics();
LineMetrics lineMetrics = fontMetrics.getLineMetrics(text, graphics);
int textWidth = fontMetrics.stringWidth(text);
int ascent = (int)lineMetrics.getAscent();
int xText = (size - textWidth) / 2;
int yText = (ascent + size) / 2;
if (move.getColor() == BLACK)
graphics.setColor(Color.white);
else
graphics.setColor(Color.black);
graphics.drawString(text, xText, yText);
}
示例11: paintText
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
protected void paintText(Graphics2D g, GeneralPath bodyOutline) {
Font font = getFont();
String text = getText();
g.setFont(font);
FontRenderContext frc = g.getFontRenderContext();
Rectangle2D r = font.getStringBounds(text, frc);
LineMetrics lineMetrics = font.getLineMetrics(text, frc);
Rectangle2D shapeBounds = ShapeBounds.getBounds(bodyOutline);
float shapeCenterX = (float)shapeBounds.getCenterX();
float shapeCenterY = (float)shapeBounds.getCenterY();
float textX = (float)(shapeCenterX - r.getWidth()/2f);
float textY = (float)(shapeCenterY + lineMetrics.getAscent()/2f - lineMetrics.getDescent()/3f);
if(isTextShadowActive()) {
Paint paint = this.getTextPaint();
boolean isTextDark = true;
if(paint instanceof Color) {
Color color = (Color)paint;
isTextDark = (color.getRed()+color.getGreen()+color.getBlue())/3 < 120;
}
g.setColor( isTextDark ? new Color(255, 255, 255, 40) : new Color(0,0,0,40));
g.translate(0,1);
g.drawString(text, textX, textY);
g.translate(0,1);
g.drawString(text, textX, textY);
g.translate(0, -2);
}
g.setPaint(getTextPaint());
g.drawString(text, textX, textY);
}
示例12: paintComponent
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.setStroke(new BasicStroke(2));
for (int y = gate_table_row_height / 2; y < get_canvas_height(); y += gate_table_row_height) {
g2d.drawLine(0, y, get_canvas_width(), y);
}
for (int row = 0; row < table.get_row_count(); row++)
for (int col = 0; col < table.get_col_count(); col++) {
Gate gate = table.get_element(row, col);
if (gate != null) {
final int x = gate_table_col_width * col, y = gate_table_row_height * row,
gate_height = gate_table_row_height * (gate.get_ports_number() - 1) + gate_table_cell_size;
g2d.setStroke(new BasicStroke(1));
g2d.setColor(Color.WHITE);
g2d.fillRect(x + 1, y + 1, gate_table_cell_size - 1, gate_height - 1);
g2d.setColor(Color.BLACK);
g2d.drawRect(x, y, gate_table_cell_size, gate_height);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (gate.get_id().equals(Tools.CONTROL_ID))
dot_image.paintIcon(this, g2d, x, y);
else {
g2d.setFont(Tools.gate_font);
FontRenderContext frc = g2d.getFontRenderContext();
final int text_width = (int) Tools.gate_font.getStringBounds(gate.get_id(), frc).
getWidth();
LineMetrics lm = Tools.gate_font.getLineMetrics(gate.get_id(), frc);
final int text_height = (int) (lm.getAscent() + lm.getDescent());
final int text_x = x + (gate_table_cell_size - text_width) / 2,
text_y = (int) (y + (gate_height + text_height) / 2 - lm.getDescent());
// TODO add text cut-off
g2d.drawString(gate.get_id(), text_x, text_y);
}
}
}
if (handler.get_last_mouse_point() != null) {
g2d.setStroke(new BasicStroke(1));
final int x = handler.get_last_mouse_point().x - handler.get_last_mouse_point().x % gate_table_col_width,
y = handler.get_last_mouse_point().y - handler.get_last_mouse_point().y % gate_table_row_height;
Color inner_transparent = new Color(255, 0, 0, 255 / 4);
g2d.setColor(inner_transparent);
g2d.fillRect(x, y, gate_table_cell_size, gate_table_cell_size);
g2d.setColor(Color.RED);
g2d.drawRect(x, y, gate_table_cell_size, gate_table_cell_size);
}
}
示例13: deriveTextBoundsAnchorOffsets
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* A utility method that calculates the anchor offsets for a string.
* Normally, the (x, y) coordinate for drawing text is a point on the
* baseline at the left of the text string. If you add these offsets to
* (x, y) and draw the string, then the anchor point should coincide with
* the (x, y) point.
*
* @param g2 the graphics device (not <code>null</code>).
* @param text the text.
* @param anchor the anchor point.
* @param textBounds the text bounds (if not <code>null</code>, this
* object will be updated by this method to match the
* string bounds).
*
* @return The offsets.
*/
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2,
String text, TextAnchor anchor, Rectangle2D textBounds) {
float[] result = new float[3];
FontRenderContext frc = g2.getFontRenderContext();
Font f = g2.getFont();
FontMetrics fm = g2.getFontMetrics(f);
Rectangle2D bounds = getTextBounds(text, fm);
LineMetrics metrics = f.getLineMetrics(text, frc);
float ascent = metrics.getAscent();
result[2] = -ascent;
float halfAscent = ascent / 2.0f;
float descent = metrics.getDescent();
float leading = metrics.getLeading();
float xAdj = 0.0f;
float yAdj = 0.0f;
if (anchor.isHorizontalCenter()) {
xAdj = (float) -bounds.getWidth() / 2.0f;
}
else if (anchor.isRight()) {
xAdj = (float) -bounds.getWidth();
}
if (anchor.isTop()) {
yAdj = -descent - leading + (float) bounds.getHeight();
}
else if (anchor.isHalfAscent()) {
yAdj = halfAscent;
}
else if (anchor.isHorizontalCenter()) {
yAdj = -descent - leading + (float) (bounds.getHeight() / 2.0);
}
else if (anchor.isBaseline()) {
yAdj = 0.0f;
}
else if (anchor.isBottom()) {
yAdj = -metrics.getDescent() - metrics.getLeading();
}
if (textBounds != null) {
textBounds.setRect(bounds);
}
result[0] = xAdj;
result[1] = yAdj;
return result;
}
示例14: deriveTextBoundsAnchorOffsets
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* A utility method that calculates the anchor offsets for a string.
* Normally, the (x, y) coordinate for drawing text is a point on the
* baseline at the left of the text string. If you add these offsets to
* (x, y) and draw the string, then the anchor point should coincide with
* the (x, y) point.
*
* @param g2 the graphics device (not <code>null</code>).
* @param text the text.
* @param anchor the anchor point.
* @param textBounds the text bounds (if not <code>null</code>, this
* object will be updated by this method to match the
* string bounds).
*
* @return The offsets.
*/
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2,
String text, TextAnchor anchor, Rectangle2D textBounds) {
float[] result = new float[3];
FontRenderContext frc = g2.getFontRenderContext();
Font f = g2.getFont();
FontMetrics fm = g2.getFontMetrics(f);
Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
LineMetrics metrics = f.getLineMetrics(text, frc);
float ascent = metrics.getAscent();
result[2] = -ascent;
float halfAscent = ascent / 2.0f;
float descent = metrics.getDescent();
float leading = metrics.getLeading();
float xAdj = 0.0f;
float yAdj = 0.0f;
if (anchor.isHorizontalCenter()) {
xAdj = (float) -bounds.getWidth() / 2.0f;
}
else if (anchor.isRight()) {
xAdj = (float) -bounds.getWidth();
}
if (anchor.isTop()) {
yAdj = -descent - leading + (float) bounds.getHeight();
}
else if (anchor.isHalfAscent()) {
yAdj = halfAscent;
}
else if (anchor.isVerticalCenter()) {
yAdj = -descent - leading + (float) (bounds.getHeight() / 2.0);
}
else if (anchor.isBaseline()) {
yAdj = 0.0f;
}
else if (anchor.isBottom()) {
yAdj = -metrics.getDescent() - metrics.getLeading();
}
if (textBounds != null) {
textBounds.setRect(bounds);
}
result[0] = xAdj;
result[1] = yAdj;
return result;
}
示例15: deriveRotationAnchorOffsets
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* A utility method that calculates the rotation anchor offsets for a
* string. These offsets are relative to the text starting coordinate
* (<code>BASELINE_LEFT</code>).
*
* @param g2 the graphics device.
* @param text the text.
* @param anchor the anchor point.
*
* @return The offsets.
*/
private static float[] deriveRotationAnchorOffsets(Graphics2D g2,
String text, TextAnchor anchor) {
float[] result = new float[2];
FontRenderContext frc = g2.getFontRenderContext();
LineMetrics metrics = g2.getFont().getLineMetrics(text, frc);
FontMetrics fm = g2.getFontMetrics();
Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm);
float ascent = metrics.getAscent();
float halfAscent = ascent / 2.0f;
float descent = metrics.getDescent();
float leading = metrics.getLeading();
float xAdj = 0.0f;
float yAdj = 0.0f;
if (anchor.isLeft()) {
xAdj = 0.0f;
}
else if (anchor.isHorizontalCenter()) {
xAdj = (float) bounds.getWidth() / 2.0f;
}
else if (anchor.isRight()) {
xAdj = (float) bounds.getWidth();
}
if (anchor.isTop()) {
yAdj = descent + leading - (float) bounds.getHeight();
}
else if (anchor.isVerticalCenter()) {
yAdj = descent + leading - (float) (bounds.getHeight() / 2.0);
}
else if (anchor.isHalfAscent()) {
yAdj = -halfAscent;
}
else if (anchor.isBaseline()) {
yAdj = 0.0f;
}
else if (anchor.isBottom()) {
yAdj = metrics.getDescent() + metrics.getLeading();
}
result[0] = xAdj;
result[1] = yAdj;
return result;
}