java.awt.font.LineMetrics#getDescent ( )源码实例Demo

下面列出了java.awt.font.LineMetrics#getDescent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: StandardGlyphVector.java
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);
}
 
源代码2 项目: TencentKona-8   文件: StandardGlyphVector.java
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 项目: jdk8u60   文件: StandardGlyphVector.java
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);
}
 
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);
}
 
源代码5 项目: Bytecoder   文件: StandardGlyphVector.java
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);
}
 
源代码6 项目: jdk8u-jdk   文件: StandardGlyphVector.java
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);
}
 
源代码7 项目: astor   文件: TextFragment.java
/**
 * 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 == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER
                                      || anchor == TextAnchor.TOP_RIGHT) {
        result = lm.getAscent();
    }
    else if (anchor == TextAnchor.BOTTOM_LEFT 
            || anchor == TextAnchor.BOTTOM_CENTER
            || anchor == TextAnchor.BOTTOM_RIGHT) {
        result = -lm.getDescent() - lm.getLeading();
    }
    return result;                                             
}
 
源代码8 项目: astor   文件: TextFragment.java
/**
 * 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 == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER
                                      || anchor == TextAnchor.TOP_RIGHT) {
        result = lm.getAscent();
    }
    else if (anchor == TextAnchor.BOTTOM_LEFT
            || anchor == TextAnchor.BOTTOM_CENTER
            || anchor == TextAnchor.BOTTOM_RIGHT) {
        result = -lm.getDescent() - lm.getLeading();
    }
    return result;
}
 
源代码9 项目: consulo   文件: TextPainter.java
private double drawHeaderOrFooterLine(Graphics2D g, double x, double y, double w, String headerText,
                                      String alignment) {
  headerText = convertHeaderText(headerText);
  g.setFont(myHeaderFont);
  g.setColor(Color.black);
  FontRenderContext fontRenderContext = g.getFontRenderContext();
  LineMetrics lineMetrics = getHeaderFooterLineMetrics(g);
  float lineHeight = lineMetrics.getHeight();
  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;
}
 
源代码10 项目: orson-charts   文件: TextUtils.java
/**
 * A utility method that calculates the anchor offsets for a string.
 * Normally, the {@code (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 {@code (x, y)} and draw the string, then the anchor point should 
 * coincide with the {@code (x, y)} point.
 *
 * @param g2  the graphics device (not {@code null}).
 * @param text  the text.
 * @param anchor  the anchor point ({@code null} not permitted).
 *
 * @return  The offsets.
 */
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2,
        String text, TextAnchor anchor) {

    float[] result = new float[2];
    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();
    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.isHalfHeight()) {
        yAdj = -descent - leading + (float) (bounds.getHeight() / 2.0);
    } else if (anchor.isBaseline()) {
        yAdj = 0.0f;
    } else if (anchor.isBottom()) {
        yAdj = -metrics.getDescent() - metrics.getLeading();
    }
    result[0] = xAdj;
    result[1] = yAdj;
    return result;
}
 
源代码11 项目: RipplePower   文件: FontStyleIcon.java
private void calcImageBufferSize() {
	GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
			.getDefaultConfiguration();

	BufferedImage buff = config.createCompatibleImage(1, 1, Transparency.TRANSLUCENT);
	Graphics2D g2 = buff.createGraphics();
	g2.setFont(font);

	LineMetrics lm = font.getLineMetrics(String.valueOf(icon), g2.getFontRenderContext());
	iconWidth = g2.getFontMetrics().charWidth(icon.getChar());
	iconHeight = (int) lm.getHeight();
	iconBaseline = (int) (lm.getHeight() - lm.getLeading() - lm.getDescent());
	g2.dispose();
}
 
源代码12 项目: pumpernickel   文件: TextBlock.java
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);
}
 
源代码13 项目: SIMVA-SoS   文件: TextUtils.java
/**
 * 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 项目: ECG-Viewer   文件: TextUtils.java
/**
 * 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.
 *
 * @return  The offsets.
 */
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2,
        String text, TextAnchor anchor) {

    float[] result = new float[2];
    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();
    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();
    }
    result[0] = xAdj;
    result[1] = yAdj;
    return result;

}
 
源代码15 项目: buffer_bci   文件: TextUtils.java
/**
 * 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;
}
 
源代码16 项目: astor   文件: TextUtilities.java
/**
 * A utility method that calculates the rotation anchor offsets for a 
 * string.  These offsets are relative to the text starting coordinate 
 * (BASELINE_LEFT).
 *
 * @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 == TextAnchor.TOP_LEFT
            || anchor == TextAnchor.CENTER_LEFT
            || anchor == TextAnchor.BOTTOM_LEFT
            || anchor == TextAnchor.BASELINE_LEFT
            || anchor == TextAnchor.HALF_ASCENT_LEFT) {

        xAdj = 0.0f;

    }
    else if (anchor == TextAnchor.TOP_CENTER
            || anchor == TextAnchor.CENTER
            || anchor == TextAnchor.BOTTOM_CENTER
            || anchor == TextAnchor.BASELINE_CENTER
            || anchor == TextAnchor.HALF_ASCENT_CENTER) {

        xAdj = (float) bounds.getWidth() / 2.0f;

    }
    else if (anchor == TextAnchor.TOP_RIGHT
            || anchor == TextAnchor.CENTER_RIGHT
            || anchor == TextAnchor.BOTTOM_RIGHT
            || anchor == TextAnchor.BASELINE_RIGHT
            || anchor == TextAnchor.HALF_ASCENT_RIGHT) {

        xAdj = (float) bounds.getWidth();

    }

    if (anchor == TextAnchor.TOP_LEFT
            || anchor == TextAnchor.TOP_CENTER
            || anchor == TextAnchor.TOP_RIGHT) {

        yAdj = descent + leading - (float) bounds.getHeight();

    }
    else if (anchor == TextAnchor.CENTER_LEFT
            || anchor == TextAnchor.CENTER
            || anchor == TextAnchor.CENTER_RIGHT) {

        yAdj = descent + leading - (float) (bounds.getHeight() / 2.0);

    }
    else if (anchor == TextAnchor.HALF_ASCENT_LEFT
            || anchor == TextAnchor.HALF_ASCENT_CENTER
            || anchor == TextAnchor.HALF_ASCENT_RIGHT) {

        yAdj = -halfAscent;

    }
    else if (anchor == TextAnchor.BASELINE_LEFT
            || anchor == TextAnchor.BASELINE_CENTER
            || anchor == TextAnchor.BASELINE_RIGHT) {

        yAdj = 0.0f;

    }
    else if (anchor == TextAnchor.BOTTOM_LEFT
            || anchor == TextAnchor.BOTTOM_CENTER
            || anchor == TextAnchor.BOTTOM_RIGHT) {

        yAdj = metrics.getDescent() + metrics.getLeading();

    }
    result[0] = xAdj;
    result[1] = yAdj;
    return result;

}
 
源代码17 项目: buffer_bci   文件: TextUtils.java
/**
 * 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;
}
 
源代码18 项目: jrobin   文件: ImageWorker.java
double getFontHeight(Font font) {
    LineMetrics lm = font.getLineMetrics(DUMMY_TEXT, gd.getFontRenderContext());
    return lm.getAscent() + lm.getDescent();
}
 
源代码19 项目: ccu-historian   文件: TextUtilities.java
/**
 * 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.
 *
 * @return  The offsets.
 */
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2,
        String text, TextAnchor anchor) {

    float[] result = new float[2];
    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();
    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();
    }
    result[0] = xAdj;
    result[1] = yAdj;
    return result;

}
 
源代码20 项目: ccu-historian   文件: TextUtilities.java
/**
 * 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;

}