当前位置: 首页>>代码示例>>Java>>正文


Java FontMetrics.getAscent方法代码示例

本文整理汇总了Java中java.awt.FontMetrics.getAscent方法的典型用法代码示例。如果您正苦于以下问题:Java FontMetrics.getAscent方法的具体用法?Java FontMetrics.getAscent怎么用?Java FontMetrics.getAscent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.FontMetrics的用法示例。


在下文中一共展示了FontMetrics.getAscent方法的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;
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:31,代码来源:UnicodeFont.java

示例2: 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:MotifBorders.java

示例3: paintComponent

import java.awt.FontMetrics; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
    if (ad == null)
        return;

    g.drawImage(ad, 0, 0, X_SIZE, AD_HEIGHT, this);

    if (!labelText.equals("")) {
        final int xPadding = 3;

        FontMetrics metrics = getFontMetrics(getFont());

        int descent = metrics.getDescent();
        int ascent = metrics.getAscent();
        int leading = metrics.getLeading();
        int height = metrics.getHeight();

        g.setColor(new Color(255, 255, 200));
        g.fillRect(0, 0, metrics.stringWidth(labelText) + xPadding + xPadding, height);

        g.setColor(Color.black);
        g.drawString(labelText, xPadding, ascent + leading / 2);
    }
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:24,代码来源:ProgressWindow.java

示例4: 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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CompositionArea.java

示例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));
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:41,代码来源:GuiComponent.java

示例6: getPreferredSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
    FontMetrics fm = getTxtFontMetrics();
    int height = fm == null ?
            21 : fm.getAscent() + 2 * fm.getDescent() + 3;
    height += 1; //align with editor tabs
    Insets insets = c.getInsets();
    prefSize.height = height + insets.bottom + insets.top;
    return prefSize;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:AquaViewTabDisplayerUI.java

示例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() + 2;
    Insets insets = c.getInsets();
    prefSize.height = height + insets.bottom + insets.top;
    return prefSize;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:WinClassicViewTabDisplayerUI.java

示例8: getPreferredSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
    FontMetrics fm = getTxtFontMetrics();
    int height = fm == null ?
            21 : fm.getAscent() + 2 * fm.getDescent() + 4;
    Insets insets = c.getInsets();
    prefSize.height = height + insets.bottom + insets.top;
    return prefSize;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:MetalViewTabDisplayerUI.java

示例9: paintComponent

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
    Rectangle cp = g.getClipBounds();
    g.setColor(getBackground());
    g.fillRect(cp.x, cp.y, cp.width, cp.height);
    if (lines == null) {
        return;
    }
    g.setColor(getForeground());
    FontMetrics fontMetrics = textView.getFontMetrics(textView.getFont());
    int lineHeight = fontMetrics.getHeight();
    int descent = fontMetrics.getDescent();
    int offset = 0;
    try {
        Rectangle modelToView = textView.modelToView(0);
        offset = modelToView == null ? 0 : modelToView.y;
    } catch (BadLocationException ex) {
        LOG.log(Level.INFO, null, ex);
    }
    offset += lineHeight - fontMetrics.getAscent();

    int size = lines.getLineCount();
    int logLine = 0; // logical line (including wrapped lines)
    int nextLogLine;
    int firstVisibleLine = Math.max(0, getLineAtPosition(cp.y) - 1);
    int lastVisibleLine = getLastVisibleLine(cp, size);
    for (int i = firstVisibleLine; i < lastVisibleLine; i++) {
        if (!lines.isVisible(i)) {
            continue;
        }
        nextLogLine = findLogicalLineIndex(findNextVisibleLine(i), size);
        drawLineGraphics(g, i, logLine, nextLogLine, offset, lineHeight,
                descent);
        logLine = nextLogLine;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:FoldingSideBar.java

示例10: drawRange

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Writes text showing the range
 *
 * @param range the range to display, in whatever units returned
 * by the {@link MapGrid} containing the thread */
public void drawRange(Graphics g, int range) {
  Point mapArrow = map.componentCoordinates(arrow);
  Point mapAnchor = map.componentCoordinates(anchor);
  g.setColor(Color.black);
  g.setFont(RANGE_FONT);
  final FontMetrics fm = g.getFontMetrics();
  final StringBuilder buffer = new StringBuilder();
  int dummy = range;
  while (dummy >= 1) {
    dummy = dummy / 10;
    buffer.append("8");
  }
  if (buffer.length() == 0) {
    buffer.append("8");
  }
  String rangeMess = Resources.getString("LOS_Thread.range");
  int wid = fm.stringWidth(" "+rangeMess+"  "+buffer.toString());
  int hgt = fm.getAscent() + 2;
  int w = mapArrow.x - mapAnchor.x;
  int h = mapArrow.y - mapAnchor.y;
  int x0 = mapArrow.x + (int) ((wid / 2 + 20) * w / Math.sqrt(w * w + h * h));
  int y0 = mapArrow.y + (int) ((hgt / 2 + 20) * h / Math.sqrt(w * w + h * h));
  g.fillRect(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid, hgt);
  g.setColor(Color.white);
  g.drawString(rangeMess + " " + range,
               x0 - wid / 2 + fm.stringWidth(" "), y0 + hgt / 2);
  lastRangeRect = new Rectangle(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid+1, hgt+1);
  Point np = map.mapCoordinates(new Point(lastRangeRect.x, lastRangeRect.y));
  lastRangeRect.x = np.x;
  lastRangeRect.y = np.y;
  lastRange = String.valueOf(range);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:38,代码来源:LOS_Thread.java

示例11: getBounds

import java.awt.FontMetrics; //导入方法依赖的package包/类
@Override
public Bounds getBounds(Graphics g) {
	int x = field.getX();
	int y = field.getY();
	Font font = field.getFont();
	FontMetrics fm;
	if (font == null)
		fm = g.getFontMetrics();
	else
		fm = g.getFontMetrics(font);
	int width = fm.stringWidth(curText);
	int ascent = fm.getAscent();
	int descent = fm.getDescent();
	int height = ascent + descent;
	switch (field.getHAlign()) {
	case TextField.H_CENTER:
		x -= width / 2;
		break;
	case TextField.H_RIGHT:
		x -= width;
		break;
	default:
		break;
	}
	switch (field.getVAlign()) {
	case TextField.V_TOP:
		y += ascent;
		break;
	case TextField.V_CENTER:
		y += (ascent - descent) / 2;
		break;
	case TextField.V_BOTTOM:
		y -= descent;
		break;
	default:
		break;
	}
	return Bounds.create(x, y - ascent, width, height).add(field.getBounds(g)).expand(3);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:40,代码来源:TextFieldCaret.java

示例12: drawCenteredString

import java.awt.FontMetrics; //导入方法依赖的package包/类
protected void drawCenteredString(String s, int x, int y, int w, int h, Graphics g) {
     FontMetrics fm = g.getFontMetrics();
     x += (w - fm.stringWidth(s)) / 2;
     y += (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
     g.drawString(s, x, y);
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:7,代码来源:ImageExport.java

示例13: getBaseline

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException(
                "Width and height must be >= 0");
    }
    JLabel label = (JLabel)c;
    String text = label.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = label.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(label);
    FontMetrics fm = context.getComponent().getFontMetrics(
        context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(
        context, fm, label.getText(), label.getIcon(),
        label.getHorizontalAlignment(), label.getVerticalAlignment(),
        label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
        viewRect, iconRect, textRect, label.getIconTextGap());
    View view = (View)label.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width,
                                             textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    }
    else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:51,代码来源:SynthLabelUI.java

示例14: drawStringInRect

import java.awt.FontMetrics; //导入方法依赖的package包/类
static void drawStringInRect(JComponent c, Graphics g, String aString,
                                 int x, int y, int width, int height,
                                 int justification) {
        FontMetrics  fontMetrics;
        int          drawWidth, startX, startY, delta;

        if (g.getFont() == null) {
//            throw new InconsistencyException("No font set");
            return;
        }
        fontMetrics = SwingUtilities2.getFontMetrics(c, g);
        if (fontMetrics == null) {
//            throw new InconsistencyException("No metrics for Font " + font());
            return;
        }

        if (justification == CENTER) {
            drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
            if (drawWidth > width) {
                drawWidth = width;
            }
            startX = x + (width - drawWidth) / 2;
        } else if (justification == RIGHT) {
            drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
            if (drawWidth > width) {
                drawWidth = width;
            }
            startX = x + width - drawWidth;
        } else {
            startX = x;
        }

        delta = (height - fontMetrics.getAscent() - fontMetrics.getDescent()) / 2;
        if (delta < 0) {
            delta = 0;
        }

        startY = y + height - delta - fontMetrics.getDescent();

        SwingUtilities2.drawString(c, g, aString, startX, startY);
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:MotifGraphicsUtils.java

示例15: drawAct

import java.awt.FontMetrics; //导入方法依赖的package包/类
public static void drawAct(Graphics2D g2d, Point center, String title, String bodyText,
		boolean isExec, boolean isPend, boolean isPetri) {
	
	int leftX = center.x - Constants.ACTIVITY_WIDTH / 2;
	int rightX = center.x + Constants.ACTIVITY_WIDTH /2;
	int upperY = center.y - Constants.ACTIVITY_HEIGHT / 2;
	int lineY = upperY + Constants.HEADER_HEIGHT;
	
    // border
	g2d.setColor(Constants.ACTIVITY_BACKGROUND_COLOR);
	g2d.fillRect(leftX, upperY, Constants.ACTIVITY_WIDTH, Constants.ACTIVITY_HEIGHT);
	g2d.setColor(Color.BLACK);
	g2d.drawRect(leftX, upperY, Constants.ACTIVITY_WIDTH, Constants.ACTIVITY_HEIGHT);
	g2d.drawLine(leftX, lineY, rightX, lineY);
	
	// font
	g2d.setFont(Constants.BASIC_FONT);
	FontMetrics metrics = g2d.getFontMetrics(g2d.getFont());
	
	// title
    int xTitle = leftX + (Constants.ACTIVITY_WIDTH - metrics.stringWidth(title)) / 2;
    int yTitle = upperY + ((Constants.HEADER_HEIGHT - metrics.getHeight()) / 2) + metrics.getAscent();
    g2d.drawString(title, xTitle, yTitle);
	  
    // body text
    int xBody = leftX + (Constants.ACTIVITY_WIDTH - metrics.stringWidth(bodyText)) / 2;
    int yBody = upperY + Constants.LINE_HEIGHT + Constants.HEADER_HEIGHT + 9 + g2d.getFontMetrics().getHeight();
    g2d.drawString(bodyText, xBody, yBody);
    
    // checkmark
    if (isExec) {
    	g2d.setFont(Constants.CHECKMARK_FONT);
	    g2d.setColor(Constants.CHECKMARK_COLOR);
	    int xCheck = leftX + Constants.PETRI_MARGIN;
	    int yCheck = upperY + Constants.HEADER_HEIGHT + 20;
	    g2d.drawString(Constants.CHECKMARK_SYMB, xCheck, yCheck);
    }
    
    // exclamation mark
    if (isPend) {
    	g2d.setFont(Constants.EXCLAMATION_FONT);
	    g2d.setColor(Constants.EXCLAMATION_COLOR);
	    int xExclam = rightX - Constants.PETRI_MARGIN - 10;
	    int yExclam = upperY + Constants.HEADER_HEIGHT + 20;
	    g2d.drawString(Constants.EXCLAMATION_SYMB, xExclam, yExclam);
    }
    
    // Petri
    if (isPetri) {
    	g2d.setColor(Color.BLACK);
	    g2d.setFont(Constants.BASIC_FONT);
	    g2d.drawRect(leftX + Constants.PETRI_MARGIN, lineY + Constants.PETRI_MARGIN,
			Constants.ACTIVITY_WIDTH - 2 * Constants.PETRI_MARGIN, Constants.ACTIVITY_HEIGHT - Constants.HEADER_HEIGHT - 2 * Constants.PETRI_MARGIN);
    } 
}
 
开发者ID:tslaats,项目名称:SE2017-Team1,代码行数:56,代码来源:TestUtil.java


注:本文中的java.awt.FontMetrics.getAscent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。