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


Java FontMetrics.getLeading方法代码示例

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


在下文中一共展示了FontMetrics.getLeading方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:j-dong,项目名称:trashjam2017,代码行数:31,代码来源:UnicodeFont.java

示例2: 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

示例3: getFontDimensions

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Figure out my font dimensions.
 */
private void getFontDimensions() {
    Graphics gr = getGraphics();
    FontMetrics fm = gr.getFontMetrics();
    maxDescent = fm.getMaxDescent();
    Rectangle2D bounds = fm.getMaxCharBounds(gr);
    int leading = fm.getLeading();
    textWidth = (int)Math.round(bounds.getWidth());
    // textHeight = (int)Math.round(bounds.getHeight()) - maxDescent;

    // This produces the same number, but works better for ugly
    // monospace.
    textHeight = fm.getMaxAscent() + maxDescent - leading;

    if (gotTerminus == true) {
        textHeight++;
    }

    if (getFontAdjustments() == false) {
        // We were unable to programmatically determine textAdjustX
        // and textAdjustY, so try some guesses based on VM vendor.
        String runtime = System.getProperty("java.runtime.name");
        if ((runtime != null) && (runtime.contains("Java(TM)"))) {
            textAdjustY = -1;
            textAdjustX = 0;
        }
    }
}
 
开发者ID:klamonte,项目名称:jermit,代码行数:31,代码来源:SwingScreen.java

示例4: _getHeight

import java.awt.FontMetrics; //导入方法依赖的package包/类
private int _getHeight(PaintContext context)
{
  // The curve width is proportional to the height of the button.
  // So, we first compute the height of the button.
  FontMetrics metrics = context.getFontMetrics(context.getPaintFont());
  int fontHeight = metrics.getHeight() - metrics.getLeading();
  int height =
    fontHeight +
    _TOP + _BOTTOM +
    _TEXT_TOP_MARGIN + _TEXT_BOTTOM_MARGIN;

  return height;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:14,代码来源:ButtonPainter.java

示例5: setTitleSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
void setTitleSize(FontMetrics fm) {
	if( !paintTitle ) {
		titleH = 0;
		return;
	}
	titleWidth = fm.stringWidth(title);
	titleY = fm.getLeading() + fm.getHeight();
	titleH = titleY + fm.getDescent();
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:10,代码来源:Ras2ToJPG.java

示例6: _getSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
private Dimension _getSize(
  PaintContext context,
  boolean      usePreferredSize
  )
{
  int width  = 0;
  int height = 0;

  Font font = context.getPaintFont();
  Graphics g = context.getPaintGraphics();

  if (font != null)
  {
    String      text    = (usePreferredSize
                            ? getStringData(context)
                            : getMinimumStringData(context));

    // Due to bug 1852105 (ANTIALIASED TEXT MAY SOMETIMES APPEAR BOLD),
    // we synchronize on the _FONT_LOCK object to serialize all text
    // rendering/measuring.  See comment in paint() method above for
    // more details.
    synchronized (_FONT_LOCK)
    {
      // Reset the font state before we do anything.
      _resetFont(g);

      // Now it should be safe to get/use the FontMetrics
      FontMetrics metrics = context.getFontMetrics(font);
      if ((metrics != null) && (text != null))
      {
        int numLines = _getNumberOfTextLines(text);

        if (numLines == 1)
        {
          text = StringUtils.getDisplayString(text, context);

          // get the string width
          width = _getStringWidth(text, metrics, g);
        }
        else
        {
          width = _getMaxLineWidth(context, text, metrics, g);
        }

        height = (numLines * metrics.getHeight()) - metrics.getLeading();
      }
    }
  }

  return new Dimension(width, height);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:52,代码来源:TextPainter.java

示例7: calcFontMetrics

import java.awt.FontMetrics; //导入方法依赖的package包/类
private void calcFontMetrics( Graphics2D g2d, int w, int h ) {
    FontMetrics fm;
    Graphics2D g2 = (Graphics2D)g2d.create();

    /// ABP
    if ( g2Transform != NONE && textToUse != FILE_TEXT ) {
        g2.setFont( g2.getFont().deriveFont( getAffineTransform( g2Transform )) );
        fm = g2.getFontMetrics();
    }
    else {
        fm = g2.getFontMetrics();
    }

    maxAscent = fm.getMaxAscent();
    maxDescent = fm.getMaxDescent();
    if (maxAscent == 0) maxAscent = 10;
    if (maxDescent == 0) maxDescent = 5;
    if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
        /// Give slight extra room for each character
        maxAscent += 3;
        maxDescent += 3;
        gridWidth = fm.getMaxAdvance() + 6;
        gridHeight = maxAscent + maxDescent;
        if ( force16Cols )
          numCharAcross = 16;
        else
          numCharAcross = ( w - 10 ) / gridWidth;
        numCharDown = ( h - 10 ) / gridHeight;

        canvasInset_X = ( w - numCharAcross * gridWidth ) / 2;
        canvasInset_Y = ( h - numCharDown * gridHeight ) / 2;
        if ( numCharDown == 0 || numCharAcross == 0 )
          throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );

        if ( !isPrinting )
          resetScrollbar( verticalBar.getValue() * numCharAcross );
    }
    else {
        maxDescent += fm.getLeading();
        canvasInset_X = 5;
        canvasInset_Y = 5;
        /// gridWidth and numCharAcross will not be used in this mode...
        gridHeight = maxAscent + maxDescent;
        numCharDown = ( h - canvasInset_Y * 2 ) / gridHeight;

        if ( numCharDown == 0 )
          throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
        /// If this is text loaded from file, prepares the LineBreak'ed
        /// text layout at this point
        if ( textToUse == FILE_TEXT ) {
            if ( !isPrinting )
              f2dt.fireChangeStatus( "LineBreaking Text... Please Wait", false );
            lineBreakTLs = new Vector();
            for ( int i = 0; i < fileText.length; i++ ) {
                AttributedString as =
                  new AttributedString( fileText[i], g2.getFont().getAttributes() );

                LineBreakMeasurer lbm =
                  new LineBreakMeasurer( as.getIterator(), g2.getFontRenderContext() );

                while ( lbm.getPosition() < fileText[i].length() )
                  lineBreakTLs.add( lbm.nextLayout( (float) w ));

            }
        }
        if ( !isPrinting )
          resetScrollbar( verticalBar.getValue() );
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:FontPanel.java

示例8: setAnotSize

import java.awt.FontMetrics; //导入方法依赖的package包/类
void setAnotSize(FontMetrics fm) {
	anotH = fm.getLeading() + fm.getHeight() + 5;
	anotY = fm.getLeading() + fm.getHeight();
	anotW = fm.getLeading() + fm.getHeight() + anotH;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:6,代码来源:Ras2ToJPG.java

示例9: lineToY

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Converts a line index to a y co-ordinate.
 * 
 * @param line
 *            The line
 */
public int lineToY(int line) {
	FontMetrics fm = painter.getFontMetrics();
	return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent());
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:11,代码来源:JEditTextArea.java


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