當前位置: 首頁>>代碼示例>>Java>>正文


Java LineMetrics類代碼示例

本文整理匯總了Java中java.awt.font.LineMetrics的典型用法代碼示例。如果您正苦於以下問題:Java LineMetrics類的具體用法?Java LineMetrics怎麽用?Java LineMetrics使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LineMetrics類屬於java.awt.font包,在下文中一共展示了LineMetrics類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showTextOnStream

import java.awt.font.LineMetrics; //導入依賴的package包/類
private void showTextOnStream(IFontTextDrawerEnv env, PDPageContentStream contentStream, Font attributeFont,
		PDFont font, boolean isStrikeThrough, boolean isUnderline, boolean isLigatures, String text)
		throws IOException {
	if (isStrikeThrough || isUnderline) {
		// noinspection unused
		float stringWidth = font.getStringWidth(text);
		// noinspection unused
		LineMetrics lineMetrics = attributeFont.getLineMetrics(text, env.getFontRenderContext());
		/*
		 * TODO: We can not draw that yet, we must do that later. While in textmode its
		 * not possible to draw lines...
		 */
	}
	// noinspection StatementWithEmptyBody
	if (isLigatures) {
		/*
		 * No idea how to map this ...
		 */
	}
	contentStream.showText(text);
}
 
開發者ID:rototor,項目名稱:pdfbox-graphics2d,代碼行數:22,代碼來源:PdfBoxGraphics2DFontTextDrawer.java

示例2: 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:UnderlineTest.java

示例3: paintToRect

import java.awt.font.LineMetrics; //導入依賴的package包/類
public void paintToRect(Graphics2D g2d, int x, int y, int w, int h) {
  g2d = createGraphics(g2d,x,y,w,h);
  g2d.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
  Font font = g2d.getFont();
  FontMetrics fm = g2d.getFontMetrics();
  FontRenderContext frc = g2d.getFontRenderContext();
  LineMetrics lm = font.getLineMetrics(text,frc);
  //int fh = round(lm.getHeight());
  //int fa = round(lm.getAscent());
  int fd = round(lm.getDescent());
  int wt = fm.stringWidth(text);
  int xt = max(0,(w-wt)/2);
  int yt = h-1-2*fd;
  g2d.drawString(text,xt,yt);
  g2d.dispose();
}
 
開發者ID:MinesJTK,項目名稱:jtk,代碼行數:19,代碼來源:PlotPanel.java

示例4: 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:StandardGlyphVector.java

示例5: 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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:StandardGlyphVector.java

示例6: createImageWithOverlay

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * Add overlay text to the image and save as a .jpg file.
 *
 * @param  image        a java.awt.Image to add the text overlay to
 * @param  overlayText  The text to overlay onto the image
 * @return
 */
public static BufferedImage createImageWithOverlay(final Image image, final String[] overlayText) {

    // Copy BufferedImage and set .jpg file name
    final BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) bi.getGraphics();
    g.drawImage(image, 0, 0, null);
    final Font font = new Font("Monospaced", Font.PLAIN, 14);
    g.setFont(font);
    g.setColor(Color.CYAN);
    final FontRenderContext frc = g.getFontRenderContext();
    int x = 1;
    int n = 1;
    for (String s : overlayText) {
        LineMetrics lineMetrics = font.getLineMetrics(s, frc);
        float y = (lineMetrics.getHeight() + 1) * n + lineMetrics.getHeight();
        g.drawString(s, x, y);
        n++;
    }

    g.dispose();

    return bi;
}
 
開發者ID:mbari-media-management,項目名稱:vars-annotation,代碼行數:32,代碼來源:ImageArchiveServiceDecorator.java

示例7: drawStringInRect

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
                              String text) {

    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics(font);
    Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
    double x = bounds.getX();
    if (r.getWidth() < bounds.getWidth()) {
        x = x + (bounds.getWidth() - r.getWidth()) / 2;
    }
    LineMetrics metrics = font.getLineMetrics(text, g2.getFontRenderContext());
    g2.drawString(
        text, 
        (float) x, (float) (bounds.getMaxY() - this.bottomInnerGap - metrics.getDescent())
    );
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:25,代碼來源:MarkerAxisBand.java

示例8: drawStringInRect

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
                              String text) {

    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics(font);
    Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
    double x = bounds.getX();
    if (r.getWidth() < bounds.getWidth()) {
        x = x + (bounds.getWidth() - r.getWidth()) / 2;
    }
    LineMetrics metrics = font.getLineMetrics(
        text, g2.getFontRenderContext()
    );
    g2.drawString(
        text, (float) x, (float) (bounds.getMaxY() 
            - this.bottomInnerGap - metrics.getDescent())
    );
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:27,代碼來源:MarkerAxisBand.java

示例9: toString

import java.awt.font.LineMetrics; //導入依賴的package包/類
public String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append("{text=");
    for (int i = 0; i < length(); i++) {
        buf.append(aStrings[i].getIterator().current());
    }
    final String RS = "\n\t";
    buf.append(RS);
    for (int i = 0; i < length(); i++) {
        buf.append(bounds[i].toString());
        final String FS = " ";
        final LineMetrics m = metrics[i];
        // height = ascent + descent + leading
        buf.append(" ascent=").append(m.getAscent()).append(FS);
        buf.append("descent=").append(m.getDescent()).append(FS);
        buf.append("leading=").append(m.getLeading()).append(FS);

        buf.append(RS);
    }
    buf.append("}");
    return buf.toString();
}
 
開發者ID:pengqiuyuan,項目名稱:g2,代碼行數:23,代碼來源:ChangeableAttributedString.java

示例10: finishInit

import java.awt.font.LineMetrics; //導入依賴的package包/類
private void finishInit() {
  font = source.getFont();

  Map<TextAttribute, ?> atts = font.getAttributes();
  baseTX = AttributeValues.getBaselineTransform(atts);
  if (baseTX == null){
      cm = source.getCoreMetrics();
  } else {
    AffineTransform charTX = AttributeValues.getCharTransform(atts);
    if (charTX == null) {
        charTX = new AffineTransform();
    }
    font = font.deriveFont(charTX);

    LineMetrics lm = font.getLineMetrics(source.getChars(), source.getStart(),
        source.getStart() + source.getLength(), source.getFRC());
    cm = CoreMetrics.get(lm);
  }
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:20,代碼來源:ExtendedTextSourceLabel.java

示例11: drawStringInRect

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * A utility method that draws a string inside a rectangle.
 *
 * @param g2  the graphics device.
 * @param bounds  the rectangle.
 * @param font  the font.
 * @param text  the text.
 */
private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font,
                              String text) {

    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics(font);
    Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm);
    double x = bounds.getX();
    if (r.getWidth() < bounds.getWidth()) {
        x = x + (bounds.getWidth() - r.getWidth()) / 2;
    }
    LineMetrics metrics = font.getLineMetrics(
        text, g2.getFontRenderContext()
    );
    g2.drawString(
        text, (float) x, (float) (bounds.getMaxY()
            - this.bottomInnerGap - metrics.getDescent())
    );
}
 
開發者ID:mdzio,項目名稱:ccu-historian,代碼行數:27,代碼來源:MarkerAxisBand.java

示例12: 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;                                             
}
 
開發者ID:mdzio,項目名稱:ccu-historian,代碼行數:28,代碼來源:TextFragment.java

示例13: getTextBounds

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * Returns the bounds for the specified text.
 *
 * @param text  the text (<code>null</code> permitted).
 * @param g2  the graphics context (not <code>null</code>).
 * @param fm  the font metrics (not <code>null</code>).
 *
 * @return The text bounds (<code>null</code> if the <code>text</code>
 *         argument is <code>null</code>).
 */
public static Rectangle2D getTextBounds(String text, Graphics2D g2, 
        FontMetrics fm) {

    Rectangle2D bounds;
    if (TextUtilities.useFontMetricsGetStringBounds) {
        bounds = fm.getStringBounds(text, g2);
        // getStringBounds() can return incorrect height for some Unicode
        // characters...see bug parade 6183356, let's replace it with
        // something correct
        LineMetrics lm = fm.getFont().getLineMetrics(text,
                g2.getFontRenderContext());
        bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(),
                lm.getHeight());
    }
    else {
        double width = fm.stringWidth(text);
        double height = fm.getHeight();
        if (logger.isDebugEnabled()) {
            logger.debug("Height = " + height);
        }
        bounds = new Rectangle2D.Double(0.0, -fm.getAscent(), width,
                height);
    }
    return bounds;
}
 
開發者ID:mdzio,項目名稱:ccu-historian,代碼行數:36,代碼來源:TextUtilities.java

示例14: 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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:TextPainter.java

示例15: getTextBounds

import java.awt.font.LineMetrics; //導入依賴的package包/類
/**
 * Returns the bounds for the specified text.
 *
 * @param text  the text ({@code null} permitted).
 * @param g2  the graphics context (not {@code null}).
 * @param fm  the font metrics (not {@code null}).
 *
 * @return The text bounds ({@code null} if the {@code text}
 *         argument is {@code null}).
 */
public static Rectangle2D getTextBounds(String text, Graphics2D g2, 
        FontMetrics fm) {

    Rectangle2D bounds;
    if (TextUtils.useFontMetricsGetStringBounds) {
        bounds = fm.getStringBounds(text, g2);
        // getStringBounds() can return incorrect height for some Unicode
        // characters...see bug parade 6183356, let's replace it with
        // something correct
        LineMetrics lm = fm.getFont().getLineMetrics(text,
                g2.getFontRenderContext());
        bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(),
                lm.getHeight());
    }
    else {
        double width = fm.stringWidth(text);
        double height = fm.getHeight();
        bounds = new Rectangle2D.Double(0.0, -fm.getAscent(), width,
                height);
    }
    return bounds;
}
 
開發者ID:jfree,項目名稱:jfreechart,代碼行數:33,代碼來源:TextUtils.java


注:本文中的java.awt.font.LineMetrics類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。