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


Java FontMetrics.getMaxAdvance方法代码示例

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


在下文中一共展示了FontMetrics.getMaxAdvance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

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

示例2: drawTickMarksAndLabels

import java.awt.FontMetrics; //导入方法依赖的package包/类
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, Rectangle2D plotArea, 
        Rectangle2D dataArea, RectangleEdge edge) {
    this.internalMarkerWhenTicksOverlap = false;
    AxisState ret = super.drawTickMarksAndLabels(g2, cursor, plotArea, dataArea, edge);
    
    // continue and separate the labels only if necessary
    if (!this.internalMarkerWhenTicksOverlap) {
        return ret;
    }
    
    double ol = getTickMarkOutsideLength();
    FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
    
    if (this.isVerticalTickLabels()) {
        ol = fm.getMaxAdvance(); 
    }
    else {
        ol = fm.getHeight();
    }
    
    double il = 0;
    if (isTickMarksVisible()) {
        float xx = (float) valueToJava2D(getRange().getUpperBound(), dataArea, edge);
        Line2D mark = null;
        g2.setStroke(getTickMarkStroke());
        g2.setPaint(getTickMarkPaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
        }
        g2.draw(mark);
    }
    return ret;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:43,代码来源:CyclicNumberAxis.java

示例3: drawTickMarksAndLabels

import java.awt.FontMetrics; //导入方法依赖的package包/类
/**
 * Draws the tick marks and labels.
 * 
 * @param g2  the graphics device.
 * @param cursor  the cursor.
 * @param plotArea  the plot area.
 * @param dataArea  the area inside the axes.
 * @param edge  the side on which the axis is displayed.
 * 
 * @return The axis state.
 */
protected AxisState drawTickMarksAndLabels(Graphics2D g2, double cursor, 
                                           Rectangle2D plotArea, 
                                           Rectangle2D dataArea, 
                                           RectangleEdge edge) {
    this.internalMarkerWhenTicksOverlap = false;
    AxisState ret = super.drawTickMarksAndLabels(
        g2, cursor, plotArea, dataArea, edge
    );
    
    // continue and separate the labels only if necessary
    if (!this.internalMarkerWhenTicksOverlap) {
        return ret;
    }
    
    double ol = getTickMarkOutsideLength();
    FontMetrics fm = g2.getFontMetrics(getTickLabelFont());
    
    if (isVerticalTickLabels()) {
        ol = fm.getMaxAdvance(); 
    }
    else {
        ol = fm.getHeight();
    }
    
    double il = 0;
    if (isTickMarksVisible()) {
        float xx = (float) valueToJava2D(
            getRange().getUpperBound(), dataArea, edge
        );
        Line2D mark = null;
        g2.setStroke(getTickMarkStroke());
        g2.setPaint(getTickMarkPaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(cursor - ol, xx, cursor + il, xx);
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(cursor + ol, xx, cursor - il, xx);
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(xx, cursor - ol, xx, cursor + il);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(xx, cursor + ol, xx, cursor - il);
        }
        g2.draw(mark);
    }
    return ret;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:60,代码来源:CyclicNumberAxis.java


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