Package java.awt.font

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


    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

    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

      {
        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

        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

        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

    }

    @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

            } else {
                graphics.setPaint(disabledColor);
            }

            FontRenderContext fontRenderContext = Platform.getFontRenderContext();
            LineMetrics lm = font.getLineMetrics("", fontRenderContext);
            float ascent = lm.getAscent();
            float lineHeight = lm.getHeight();

            float y = 0;
            switch (verticalAlignment) {
                case TOP: {
                    y = padding.top;
View Full Code Here

        System.out.println(font.getFontName() + "  " + size + ": " + fm.getHeight() + " = " + fm.getLeading() + " + " + fm.getAscent() + " + "
                + fm.getDescent());
        System.out.println("    " + fm.getMaxAscent() + " + " + fm.getMaxDescent());

        LineMetrics lm = fm.getLineMetrics("test", g);
       
        System.out.println("    " + lm.getLeading() + "    " + lm.getAscent() + " + " + lm.getDescent());

        return fm.getHeight() + 14;
    }
View Full Code Here

        return info;
      }
    }

    cpBuffer[0] = (char) (c & 0xFFFF);
    final LineMetrics lm = font.getLineMetrics(cpBuffer, 0, 1, frc);
    final float[] bls = lm.getBaselineOffsets();
    final int idx = lm.getBaselineIndex();

    if (info == null)
    {
      info = new BaselineInfo();
    }

    // The ascent is local - but we need the global baseline, relative to the
    // MaxAscent.
    final long maxAscent = getMaxAscent();
    final long ascent = FontStrictGeomUtility.toInternalValue(lm.getAscent());
    final long delta = maxAscent - ascent;
    info.setBaseline(BaselineInfo.MATHEMATICAL, delta + maxAscent - getXHeight());
    info.setBaseline(BaselineInfo.IDEOGRAPHIC, getMaxHeight());
    info.setBaseline(BaselineInfo.MIDDLE, maxAscent / 2);
View Full Code Here

TOP

Related Classes of java.awt.font.LineMetrics

Copyright © 2018 www.massapicom. 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.