本文整理汇总了Java中java.awt.font.LineMetrics.getDescent方法的典型用法代码示例。如果您正苦于以下问题:Java LineMetrics.getDescent方法的具体用法?Java LineMetrics.getDescent怎么用?Java LineMetrics.getDescent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.font.LineMetrics
的用法示例。
在下文中一共展示了LineMetrics.getDescent方法的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: drawHeaderOrFooterLine
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText,
String alignment) {
FontRenderContext fontRenderContext = g.getFontRenderContext();
LineMetrics lineMetrics = getHeaderFooterLineMetrics(g);
float lineHeight = lineMetrics.getHeight();
if (myPerformActualDrawing) {
headerText = convertHeaderText(headerText);
g.setFont(myHeaderFont);
g.setColor(Color.black);
float descent = lineMetrics.getDescent();
double width = myHeaderFont.getStringBounds(headerText, fontRenderContext).getWidth() + getCharWidth(g);
float yPos = (float) (lineHeight - descent + y);
if (PrintSettings.LEFT.equals(alignment)) {
drawStringToGraphics(g, headerText, x, yPos);
} else if (PrintSettings.CENTER.equals(alignment)) {
drawStringToGraphics(g, headerText, (float) (x + (w - width) / 2), yPos);
} else if (PrintSettings.RIGHT.equals(alignment)) {
drawStringToGraphics(g, headerText, (float) (x + w - width), yPos);
}
}
return lineHeight;
}
示例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;
final FontMetrics fm = g2.getFontMetrics(this.font);
final 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: paintLabel
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private void paintLabel(Graphics g, int cell, Rectangle cellBounds, @Nullable String label, int thumbnailHeight) {
if (!StringUtil.isEmpty(label)) {
final Color fg;
if (hasFocus() && cell == mySelectedIndex && (getImage(cell) != null || UIUtil.isUnderDarcula())) {
fg = UIUtil.getTreeSelectionForeground();
}
else {
fg = UIUtil.getTreeForeground();
}
GraphicsUtil.setupAntialiasing(g);
g.setColor(fg);
FontMetrics fontMetrics = g.getFontMetrics();
LineMetrics metrics = fontMetrics.getLineMetrics(label, g);
int width = fontMetrics.stringWidth(label);
int textBoxTop = myCellMargin.top + thumbnailHeight;
int cellBottom = cellBounds.height - myCellMargin.bottom;
int textY = cellBounds.y + (cellBottom + textBoxTop + (int)(metrics.getHeight() - metrics.getDescent())) / 2 ;
int textX = (cellBounds.width - myCellMargin.left - myCellMargin.right - width) / 2 + cellBounds.x + myCellMargin.left;
g.drawString(label, textX, textY);
}
}
示例7: 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;
}
示例8: paint
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
super.paint(g);
if(drawLine) {
LineMetrics m = getFont().getLineMetrics(getText(),frc);
Insets i = getInsets();
int descent = (int)m.getDescent()-4;
if(isEnabled()) {
g.setColor(getForeground());
} else {
g.setColor(SystemColor.textInactiveText);
}
g.drawLine(i.left,getHeight()-i.bottom-descent,getWidth()-i.right-1,getHeight()-i.bottom-descent);
}
}
示例9: 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;
}
示例10: 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);
}
}
示例11: createLegendItem
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
/**
* Creates a legend item
*
* @param graphics the graphics device.
* @param item the legend item.
* @param x the x coordinate.
* @param y the y coordinate.
*
* @return the legend item.
*/
private DrawableLegendItem createLegendItem(Graphics graphics,
LegendItem item, double x, double y) {
int innerGap = 2;
FontMetrics fm = graphics.getFontMetrics();
LineMetrics lm = fm.getLineMetrics(item.getLabel(), graphics);
float textHeight = lm.getHeight();
DrawableLegendItem drawable = new DrawableLegendItem(item);
float xloc = (float) (x + innerGap + 1.15f * textHeight);
float yloc = (float) (y + innerGap + (textHeight - lm.getLeading() - lm.getDescent()));
drawable.setLabelPosition(new Point2D.Float(xloc, yloc));
float boxDim = textHeight * 0.70f;
xloc = (float) (x + innerGap + 0.15f * textHeight);
yloc = (float) (y + innerGap + 0.15f * textHeight);
drawable.setMarker(new Rectangle2D.Float(xloc, yloc, boxDim, boxDim));
float width = (float) (drawable.getLabelPosition().getX() - x
+ fm.stringWidth(item.getLabel()) + 0.5 * textHeight);
float height = 2 * innerGap + textHeight;
drawable.setBounds(x, y, width, height);
return drawable;
}
示例12: adicRodape
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private void adicRodape(Graphics g, int iPag) {
Graphics2D g2d = ( Graphics2D ) g.create();
g2d.setPaint(Color.black);
g2d.setFont(mRodFont);
LineMetrics metrics = mRodFont.getLineMetrics(mDataStr, g2d.getFontRenderContext());
int iTamTexto = getFontMetrics(mRodFont).stringWidth(mDataStr);
int iPosYTexto = ( int ) ( iMY - metrics.getDescent() - metrics.getLeading() );
int iPosRodY = ( int ) ( iMY - metrics.getHeight() );
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(0, iPosRodY, iMX, iPosRodY);
g2d.drawString(( iPag + 1 ) + " de " + iNumPags, 0, iPosYTexto);
g2d.drawString(mDataStr, iMX - iTamTexto, iPosYTexto);
g2d.dispose();
}
示例13: 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);
}
示例14: getDescent
import java.awt.font.LineMetrics; //导入方法依赖的package包/类
private float getDescent(Graphics g) {
if (myDescent >= 0) {
return myDescent;
}
FontRenderContext fontRenderContext = ((Graphics2D) g).getFontRenderContext();
LineMetrics lineMetrics = myPlainFont.getLineMetrics(DEFAULT_MEASURE_HEIGHT_TEXT, fontRenderContext);
myDescent = lineMetrics.getDescent();
return myDescent;
}
示例15: 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);
}
}