當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。