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


Java TextLayout.getAdvance方法代码示例

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


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

示例1: getPreferredSpan

import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public float getPreferredSpan(int axis) {
    if (axis == View.X_AXIS) {
        String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
        float advance = 0;
        if (desc.length() > 0) {
            TextLayout textLayout = getTextLayout();
            if (textLayout == null) {
                return 0f;
            }
            advance = textLayout.getAdvance();
        }
        return advance + (2 * EXTRA_MARGIN_WIDTH);
    } else {
        EditorView.Parent parent = (EditorView.Parent) getParent();
        return (parent != null) ? parent.getViewRenderContext().getDefaultRowHeight() : 0f;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FoldView.java

示例2: render

import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public void render(final Graphics2D g) {
  if (this.displayedText == null || this.displayedText.isEmpty() || !Game.getRenderEngine().canRender(this.entity)) {
    return;
  }

  final Point2D location = Game.getCamera().getViewPortLocation(this.entity);
  RenderEngine.renderImage(g, this.bubble, new Point2D.Double(location.getX() + this.entity.getWidth() / 2.0 - this.textBoxWidth / 2.0 - PADDING, location.getY() - this.height - PADDING));

  g.setColor(SPEAK_FONT_COLOR);
  final FontRenderContext frc = g.getFontRenderContext();

  final String text = this.displayedText;
  final AttributedString styledText = new AttributedString(text);
  styledText.addAttribute(TextAttribute.FONT, this.font);
  final AttributedCharacterIterator iterator = styledText.getIterator();
  final LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
  measurer.setPosition(0);
  final float x = (float) Game.getCamera().getViewPortLocation(this.entity).getX() + this.entity.getWidth() / 2.0f - this.textBoxWidth / 2.0f;
  float y = (float) Game.getCamera().getViewPortLocation(this.entity).getY() - this.height;
  while (measurer.getPosition() < text.length()) {
    final TextLayout layout = measurer.nextLayout(this.textBoxWidth);

    y += layout.getAscent();
    final float dx = layout.isLeftToRight() ? 0 : this.textBoxWidth - layout.getAdvance();
    layout.draw(g, x + dx, y);
    y += layout.getDescent() + layout.getLeading();
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:30,代码来源:SpeechBubble.java

示例3: getPreferredSpan

import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public float getPreferredSpan(int axis) {
    TextLayout textLayout = getTextLayout();
    if (textLayout == null) {
        return 0f;
    }
    float span = (axis == View.X_AXIS)
        ? textLayout.getAdvance()
        : TextLayoutUtils.getHeight(textLayout);
    return span;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:HighlightsViewPart.java

示例4: getAvailableWidth

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
 * Get width available for display of child views. For non-wrap case it's Integer.MAX_VALUE
 * and for wrapping it's a display width or (if display width would become too narrow)
 * a width of four chars to not overflow the word wrapping algorithm.
 * @return 
 */
float getAvailableWidth() {
    if (!isAnyStatusBit(AVAILABLE_WIDTH_VALID)) {
        // Mark valid and assign early values to prevent stack overflow in getLineContinuationCharTextLayout()
        setStatusBits(AVAILABLE_WIDTH_VALID);
        availableWidth = Integer.MAX_VALUE;
        renderWrapWidth = availableWidth;
        TextLayout lineContTextLayout = getLineContinuationCharTextLayout();
        if (lineContTextLayout != null && (getLineWrapType() != LineWrapType.NONE)) {
            availableWidth = Math.max(getVisibleRect().width, 4 * getDefaultCharWidth() + lineContTextLayout.getAdvance());
            renderWrapWidth = availableWidth - lineContTextLayout.getAdvance();
        }
    }
    return availableWidth;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DocumentViewOp.java

示例5: getLayoutWidth

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private static float getLayoutWidth(String text, Font font, NumericShaper shaper) {
    HashMap map = new HashMap();
    map.put(TextAttribute.FONT, font);
    map.put(TextAttribute.NUMERIC_SHAPING, shaper);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    TextLayout layout = new TextLayout(text, map, frc);
    return layout.getAdvance();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:bug8132119.java

示例6: getStringBounds

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified {@code FontRenderContext}.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * specified array of characters in the specified
 * {@code FontRenderContext}.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than zero, or {@code limit} is greater than the
 *         length of {@code chars}, or {@code beginIndex}
 *         is greater than {@code limit}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:Font.java

示例7: getWidth

import java.awt.font.TextLayout; //导入方法依赖的package包/类
public float getWidth() {
    if (width < 0)
        for (TextLayout textLayout : layouts)
            if (textLayout.getAdvance() > width)
                width = textLayout.getAdvance();
    return width;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:8,代码来源:TextBounds.java

示例8: paint

import java.awt.font.TextLayout; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
    if (c.isOpaque()) {
        ImageLibrary.drawTiledImage("image.background.FreeColToolTip", g, c, null);
    }

    g.setColor(Color.BLACK); // FIXME: find out why this is necessary

    Graphics2D graphics = (Graphics2D)g;
    float x = margin;
    float y = margin;
    for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
        if (line.isEmpty()) {
            y += LEADING;
            continue;
        }
        AttributedCharacterIterator styledText =
            new AttributedString(line).getIterator();

        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            y += (layout.getAscent());
            float dx = layout.isLeftToRight() ?
                0 : (maximumWidth - layout.getAdvance());

            layout.draw(graphics, x + dx, y);
            y += layout.getDescent() + layout.getLeading();
        }
    }
 }
 
开发者ID:FreeCol,项目名称:freecol,代码行数:35,代码来源:FreeColToolTipUI.java

示例9: runTest

import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TLContext tlctx = (TLContext)ctx;
    TextLayout tl = tlctx.tl;
    double wid = 0;
    do {
        wid += tl.getAdvance();
    } while (--numReps >= 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:TextMeasureTests.java

示例10: getStringBounds

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:Font.java

示例11: drawText

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private void drawText( Graphics g, int w, int h ) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.white);
    g2.fillRect(0, 0, w, h);
    g2.setColor(Color.black);

    /// sets font, RenderingHints.
    setParams( g2 );

    /// If flag is set, recalculate fontMetrics and reset the scrollbar
    if ( updateFontMetrics || isPrinting ) {
        /// NOTE: re-calculates in case G2 transform
        /// is something other than NONE
        calcFontMetrics( g2, w, h );
        updateFontMetrics = false;
    }
    /// Calculate the amount of text that can be drawn...
    calcTextRange();

    /// Draw according to the set "Text to Use" mode
    if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
        int charToDraw = drawStart;
        if ( showGrid )
          drawGrid( g2 );

        for ( int i = 0; i < numCharDown && charToDraw <= drawEnd; i++ ) {
          for ( int j = 0; j < numCharAcross && charToDraw <= drawEnd; j++, charToDraw++ ) {
              int gridLocX = j * gridWidth + canvasInset_X;
              int gridLocY = i * gridHeight + canvasInset_Y;

              modeSpecificDrawChar( g2, charToDraw,
                                    gridLocX + gridWidth / 2,
                                    gridLocY + maxAscent );

          }
        }
    }
    else if ( textToUse == USER_TEXT ) {
        g2.drawRect( 0, 0, w - 1, h - 1 );
        for ( int i = drawStart; i <= drawEnd; i++ ) {
            int lineStartX = canvasInset_Y;
            int lineStartY = ( i - drawStart ) * gridHeight + maxAscent;
            modeSpecificDrawLine( g2, userText[i], lineStartX, lineStartY );
        }
    }
    else {
        float xPos, yPos = (float) canvasInset_Y;
        g2.drawRect( 0, 0, w - 1, h - 1 );
        for ( int i = drawStart; i <= drawEnd; i++ ) {
            TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i );
            xPos =
              oneLine.isLeftToRight() ?
              canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X );

            float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()};
            if (g2Transform != NONE) {
                AffineTransform at = getAffineTransform(g2Transform);
                at.transform( fmData, 0, fmData, 0, 3);
            }
            //yPos += oneLine.getAscent();
            yPos += fmData[1]; // ascent
            //oneLine.draw( g2, xPos, yPos );
            tlDrawLine( g2, oneLine, xPos, yPos );
            //yPos += oneLine.getDescent() + oneLine.getLeading();
            yPos += fmData[3] + fmData[5]; // descent + leading
        }
    }
    g2.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:70,代码来源:FontPanel.java

示例12: getWidth

import java.awt.font.TextLayout; //导入方法依赖的package包/类
/**
     * Compute a most appropriate width of the given text layout.
     */
    public static float getWidth(TextLayout textLayout, String textLayoutText, Font font) {
        // For italic fonts the textLayout.getAdvance() includes some extra horizontal space.
        // On the other hand index2X() for TL.getCharacterCount() is width along baseline
        // so when TL ends with e.g. 'd' char the end of 'd' char is cut off.
        float width;
        int tlLen = textLayoutText.length();
        if (!font.isItalic() ||
            tlLen == 0 ||
            Character.isWhitespace(textLayoutText.charAt(tlLen - 1)) ||
            Bidi.requiresBidi(textLayoutText.toCharArray(), 0, textLayoutText.length()))
        {
            width = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using TL.getAdvance()=" + width + // NOI18N
//                        textLayoutDump(textLayout) + 
                        '\n');
            }
        } else {
            // Compute pixel bounds (with frc being null - means use textLayout's frc; and with default bounds)
            Rectangle pixelBounds = textLayout.getPixelBounds(null, 0, 0);
            width = (float) pixelBounds.getMaxX();
            // On Mac OS X with retina displays the TL.getPixelBounds() give incorrect results. Luckily
            // TL.getAdvance() gives a correct result in that case.
            // Therefore use a minimum of both values (on all platforms).
            float tlAdvance = textLayout.getAdvance();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("TLUtils.getWidth(\"" + CharSequenceUtilities.debugText(textLayoutText) + // NOI18N
                        "\"): Using minimum of TL.getPixelBounds().getMaxX()=" + width + // NOI18N
                        " or TL.getAdvance()=" + tlAdvance +
                        textLayoutDump(textLayout) +
                        '\n');
            }
            width = Math.min(width, tlAdvance);
        }
        
        // For RTL text the hit-info of the first char is above the hit-info of ending char.
        // However textLayout.isLeftToRight() returns true in case of mixture of LTR and RTL text
        // in a single textLayout.
        
        // Ceil the width to avoid rendering artifacts.
        width = (float) Math.ceil(width);
        return width;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:48,代码来源:TextLayoutUtils.java

示例13: textLayoutDump

import java.awt.font.TextLayout; //导入方法依赖的package包/类
private static String textLayoutDump(TextLayout textLayout) {
    return "\n  TL.getAdvance()=" + textLayout.getAdvance() + // NOI18N
            "\n  TL.getBounds()=" + textLayout.getBounds() + // NOI18N
            "\n  TL: " + textLayout; // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:TextLayoutUtils.java

示例14: toStringShort

import java.awt.font.TextLayout; //导入方法依赖的package包/类
public static String toStringShort(TextLayout textLayout) {
    return "[" + textLayout.getCharacterCount() + "]W=" + textLayout.getAdvance(); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:TextLayoutUtils.java

示例15: drawNative

import java.awt.font.TextLayout; //导入方法依赖的package包/类
public void drawNative(Graphics2D g, int align, int pos, float fRectHeight,
                       MovingArea area) {
    float left = 0;
    float fromY = 0;

    if (pos == 1)
        fromY += fRectHeight / 2 - height / 2;
    else if (pos == 2)
        fromY += fRectHeight;

    if (fromY < 0)
        fromY = 0;

    int size = layouts.size();

    for (int i = 0; i < size; i++) {
        TextLayout textLayout = layouts.get(i);
        if (align == Line.CENTER_ALIGN)
            left = (float) maxWidth / 2f - textLayout.getAdvance() / 2f;
        else if (align == Line.RIGHT_ALIGN)
            left = (float) maxWidth - textLayout.getAdvance();

        fromY += textLayout.getAscent();

        if (fromY >= fRectHeight && i + 1 < size)
            break;

        if (fromY + textLayout.getAscent() + textLayout.getDescent()
                // + textLayout.getLeading()
                >= fRectHeight
                && i + 1 < size) {
            // textLayout= textLayout.getJustifiedLayout(maxWidth-20);
            // textLayout.draw(g, left, fromY);
            g.drawString(texts.get(i), left, fromY);
            /*
             * Color color = g.getColor(); g.setColor(new Color(120, 120,
 * 120));
 * 
 * g.drawString("(.)", left + textLayout.getAdvance() + (float)
 * area.getIDoubleOrdinate(-0.0), fromY); g.setColor(color);
 */
            break;
        } else
            g.drawString(texts.get(i), left, fromY);
        // textLayout.draw(g, left, fromY);
        fromY += textLayout.getDescent() + textLayout.getLeading();
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:49,代码来源:TextBounds.java


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