Examples of LineMetrics


Examples of java.awt.font.LineMetrics

            Font font = new Font("Dialog", Font.PLAIN, 12);
            FontRenderContext frc = new FontRenderContext(null, false, false);
            final int count = 100;
        try {
            for (int i = 0; i < count; i++) {
                LineMetrics lm = font.getLineMetrics("", frc);
            }
        } catch (Exception e) {
            if (e.getMessage().indexOf("Error opening TrueType font file.") != -1){
                fail("NPE \"Error opening TrueType font file.\" caught.");
            }
View Full Code Here

Examples of java.awt.font.LineMetrics

    final FontRenderContext fontRenderContext = g2d.getFontRenderContext();
    final Font font = getFont();
    final Rectangle2D sb = font.getStringBounds(text, fontRenderContext);
    final int width = (int) sb.getWidth() + 4;

    final LineMetrics lineMetrics = font.getLineMetrics(text, fontRenderContext);
    final float ascent = lineMetrics.getAscent();
    final int height = (int) Math.ceil(lineMetrics.getHeight());

    g2d.setFont(font);
    final AffineTransform oldTransform = g2d.getTransform();

    g2d.setColor(getForeground());
View Full Code Here

Examples of java.awt.font.LineMetrics

  private void drawText(final Graphics2D g2d, final int x, final int y, final String text)
  {
    final FontRenderContext fontRenderContext = g2d.getFontRenderContext();
    final Font font = getFont();
    final LineMetrics lineMetrics = font.getLineMetrics(text, fontRenderContext);
    final float ascent = lineMetrics.getAscent();
    g2d.setFont(font);
    g2d.setColor(getForeground());
    g2d.drawString(text, x, y + ascent);
  }
View Full Code Here

Examples of java.awt.font.LineMetrics

    if (icon != null && text != null)
    {
      icon.paintIcon(this, g2, insets.left, insets.top);
      g2.setFont(getFont());
      final FontMetrics fontMetrics = g2.getFontMetrics();
      final LineMetrics lineMetrics = fontMetrics.getLineMetrics(text, g2);
      final float baseLine = lineMetrics.getAscent();
      final float iconWidth = icon.getIconWidth();
      final float textX = insets.left + gap + iconWidth;
      final float iconHeight = icon.getIconHeight();
      final float textY = insets.top + baseLine + (iconHeight - lineMetrics.getHeight());
      g2.drawString(text, textX, textY);
    }
    else if (icon != null)
    {
      icon.paintIcon(this, g2, insets.left, insets.top);
    }
    else if (text != null)
    {
      g2.setFont(getFont());
      final FontMetrics fontMetrics = g2.getFontMetrics();
      final LineMetrics lineMetrics = fontMetrics.getLineMetrics(text, g2);
      final float baseLine = lineMetrics.getAscent();
      final int textX = insets.left;
      final float textY = insets.top + baseLine;
      g2.drawString(text, textX, textY);
    }
View Full Code Here

Examples of java.awt.font.LineMetrics

    final FontRenderContext fontRenderContext = new FontRenderContext(null, false, false);
    final GlyphVector glyphs = font.createGlyphVector(fontRenderContext, text);
    final int width = (int) glyphs.getLogicalBounds().getWidth() + 4;
    //height = (int)glyphs.getLogicalBounds().getHeight();

    final LineMetrics lineMetrics = font.getLineMetrics(text, fontRenderContext);
    final float ascent = lineMetrics.getAscent();
    final int height = (int) Math.ceil(lineMetrics.getHeight());

    final int w = rotate == RotateTextIcon.CW || rotate == RotateTextIcon.CCW ? height : width;
    final int h = rotate == RotateTextIcon.CW || rotate == RotateTextIcon.CCW ? width : height;

    final BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
View Full Code Here

Examples of java.awt.font.LineMetrics

    g2.setFont(this.font);

    final FontRenderContext frc = g2.getFontRenderContext();
    final Font f = g2.getFont();
//    final FontMetrics fm = g2.getFontMetrics(f);
    final LineMetrics metrics = f.getLineMetrics(label, frc);
    final float ascent = metrics.getAscent();
    final float halfAscent = ascent / 2.0f;
    g2.drawString(label, (float) x, (float) (y + halfAscent));
  }
View Full Code Here

Examples of java.awt.font.LineMetrics

      {
        width = fm.stringWidth(text);
      }


      final LineMetrics metrics = f.getLineMetrics(text, frc);
      final float descent = metrics.getDescent();
      final float leading = metrics.getLeading();
      final float yAdj = -descent - leading + (float) (metrics.getHeight() / 2.0);
      final float xAdj = -width / 2.0f;
      g2.drawString(text, (float) (x + xAdj), (float) (y + yAdj));
    }
  }
View Full Code Here

Examples of java.awt.font.LineMetrics

        float preferredHeight;
        if (text != null) {
            int widthUpdated = width;
            FontRenderContext fontRenderContext = Platform.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("", fontRenderContext);
            float lineHeight = lm.getHeight();

            preferredHeight = lineHeight;

            int n = text.length();
            if (n > 0
View Full Code Here

Examples of java.awt.font.LineMetrics

        Label label = (Label)getComponent();
        String text = label.getText();

        FontRenderContext fontRenderContext = Platform.getFontRenderContext();

        LineMetrics lm = font.getLineMetrics("", fontRenderContext);
        int lineHeight = (int)Math.ceil(lm.getHeight());

        int preferredHeight = 0;
        int preferredWidth = 0;

        if (text != null && text.length() > 0) {
View Full Code Here

Examples of java.awt.font.LineMetrics

    }

    @Override
    public int getBaseline(int width, int height) {
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();
        LineMetrics lm = font.getLineMetrics("", fontRenderContext);
        float ascent = lm.getAscent();

        float textHeightLocal;
        if (wrapText) {
            textHeightLocal = Math.max(getPreferredHeight(width) - (padding.top + padding.bottom), 0);
        } else {
            textHeightLocal = (int)Math.ceil(lm.getHeight());
        }

        int baseline = -1;
        switch (verticalAlignment) {
            case TOP: {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.