當前位置: 首頁>>代碼示例>>Java>>正文


Java TextLayout.draw方法代碼示例

本文整理匯總了Java中java.awt.font.TextLayout.draw方法的典型用法代碼示例。如果您正苦於以下問題:Java TextLayout.draw方法的具體用法?Java TextLayout.draw怎麽用?Java TextLayout.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.font.TextLayout的用法示例。


在下文中一共展示了TextLayout.draw方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawString

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void drawString(AttributedCharacterIterator iterator,
                       float x, float y) {
    if (iterator == null) {
        throw new NullPointerException("AttributedCharacterIterator is null");
    }
    if (iterator.getBeginIndex() == iterator.getEndIndex()) {
        return; /* nothing to draw */
    }
    TextLayout tl = new TextLayout(iterator, getFontRenderContext());
    tl.draw(this, x, y);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:SunGraphics2D.java

示例2: drawStringUsingShapes

import java.awt.font.TextLayout; //導入方法依賴的package包/類
private void drawStringUsingShapes(AttributedCharacterIterator iterator, float x, float y) {
	Stroke originalStroke = stroke;
	Paint originalPaint = paint;
	TextLayout textLayout = new TextLayout(iterator, getFontRenderContext());
	textLayout.draw(this, x, y);
	paint = originalPaint;
	stroke = originalStroke;
}
 
開發者ID:rototor,項目名稱:pdfbox-graphics2d,代碼行數:9,代碼來源:PdfBoxGraphics2D.java

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

示例4: 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:wintertime,項目名稱:FreeCol,代碼行數:35,代碼來源:FreeColToolTipUI.java

示例5: paintTextLayout

import java.awt.font.TextLayout; //導入方法依賴的package包/類
static void paintTextLayout(Graphics2D g, Rectangle2D textLayoutBounds,
        TextLayout textLayout, DocumentView docView)
{
    float x = (float) textLayoutBounds.getX();
    float ascentedY = (float) (textLayoutBounds.getY() + docView.op.getDefaultAscent());
    // TextLayout is unable to do a partial render
    // Both x and ascentedY should already be floor/ceil-ed
    textLayout.draw(g, x, ascentedY);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:HighlightsViewUtils.java

示例6: tlDrawLine

import java.awt.font.TextLayout; //導入方法依賴的package包/類
private void tlDrawLine( Graphics2D g2, TextLayout tl,
                                   float baseX, float baseY ) {
    /// ABP - keep track of old tform, restore it later
    AffineTransform oldTx = null;
    oldTx = g2.getTransform();
    g2.translate( baseX, baseY );
    g2.transform( getAffineTransform( g2Transform ) );

    tl.draw( g2, (float) 0, (float) 0 );

    /// ABP - restore old tform
    g2.setTransform ( oldTx );

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:FontPanel.java

示例7: drawChars

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void drawChars(SunGraphics2D sg2d,
                      char data[], int offset, int length,
                      int ix, int iy)
{
    FontInfo info = sg2d.getFontInfo();
    float x, y;
    if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) {
        SurfaceData.outlineTextRenderer.drawChars(
                                    sg2d, data, offset, length, ix, iy);
        return;
    }
    if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        double origin[] = {ix + info.originX, iy + info.originY};
        sg2d.transform.transform(origin, 0, origin, 0, 1);
        x = (float) origin[0];
        y = (float) origin[1];
    } else {
        x = ix + info.originX + sg2d.transX;
        y = iy + info.originY + sg2d.transY;
    }
    GlyphList gl = GlyphList.getInstance();
    if (gl.setFromChars(info, data, offset, length, x, y)) {
        drawGlyphList(sg2d, gl);
        gl.dispose();
    } else {
        gl.dispose(); // release this asap.
        TextLayout tl = new TextLayout(new String(data, offset, length),
                                       sg2d.getFont(),
                                       sg2d.getFontRenderContext());
        tl.draw(sg2d, ix, iy);

    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:GlyphListPipe.java

示例8: drawString

import java.awt.font.TextLayout; //導入方法依賴的package包/類
private static void drawString(Graphics2D g, Font font, String value, float x, float y) {
    AttributedString str = new AttributedString(value);
    str.addAttribute(TextAttribute.FOREGROUND, Color.BLACK);
    str.addAttribute(TextAttribute.FONT, font);
    FontRenderContext frc = new FontRenderContext(null, true, true);
    TextLayout layout = new LineBreakMeasurer(str.getIterator(), frc).nextLayout(Integer.MAX_VALUE);
    layout.draw(g, x, y);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:GlyphVectorOutline.java

示例9: paint

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:CompositionArea.java

示例10: drawString

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void drawString(AttributedCharacterIterator iterator,
                       float x, float y) {
    if (iterator == null) {
        throw
            new NullPointerException("attributedcharacteriterator is null");
    }
    TextLayout layout =
        new TextLayout(iterator, getFontRenderContext());
    layout.draw(this, x, y);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:PathGraphics.java

示例11: drawString

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void drawString(String str, float x, float y) {
    if (str.length() == 0) {
        return;
    }
    TextLayout layout =
        new TextLayout(str, getFont(), getFontRenderContext());
    layout.draw(this, x, y);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:PathGraphics.java

示例12: paint

import java.awt.font.TextLayout; //導入方法依賴的package包/類
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
    if (allocBounds.intersects(clipBounds)) {
        Font origFont = g.getFont();
        Color origColor = g.getColor();
        Color origBkColor = g.getBackground();
        Shape origClip = g.getClip();
        try {
            // Leave component font
            
            g.setBackground(getBackgroundColor());

            int xInt = (int) allocBounds.getX();
            int yInt = (int) allocBounds.getY();
            int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
            int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
            g.setColor(getBorderColor());
            g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
            
            g.setColor(getForegroundColor());
            g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
            g.clip(alloc);
            TextLayout textLayout = getTextLayout();
            if (textLayout != null) {
                EditorView.Parent parent = (EditorView.Parent) getParent();
                float ascent = parent.getViewRenderContext().getDefaultAscent();
                String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
                float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
                float y = (float) allocBounds.getY();
                if (desc.length() > 0) {
                    
                    textLayout.draw(g, x, y + ascent);
                }
            }
        } finally {
            g.setClip(origClip);
            g.setBackground(origBkColor);
            g.setColor(origColor);
            g.setFont(origFont);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:44,代碼來源:FoldView.java

示例13: draw

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void draw(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);
/*
 * 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
            textLayout.draw(g, left, fromY);
        fromY += textLayout.getDescent() + textLayout.getLeading();
    }
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:47,代碼來源:TextBounds.java

示例14: drawWithSel

import java.awt.font.TextLayout; //導入方法依賴的package包/類
public void drawWithSel(Graphics2D g, int align, int pos,
                        float fRectHeight, MovingArea area, int[][] found) {
    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();
    in = false;
    int selIndex = 0;

    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() >= fRectHeight
                && i + 1 < size) {
            textLayout.draw(g, left, fromY);
            selIndex = drawSels(g, found, selIndex, i, textLayout, left,
                    fromY);
            break;
        } else {
            textLayout.draw(g, left, fromY);
            selIndex = drawSels(g, found, selIndex, i, textLayout, left,
                    fromY);
        }
        fromY += textLayout.getDescent() + textLayout.getLeading();
    }
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:44,代碼來源:TextBounds.java

示例15: drawString

import java.awt.font.TextLayout; //導入方法依賴的package包/類
/**
 * Draws the text given by the specified iterator, using this
 * graphics context's current color. The iterator has to specify a font
 * for each character. The baseline of the
 * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
 * graphics context's coordinate system.
 * The rendering attributes applied include the clip, transform,
 * paint or color, and composite attributes.
 * For characters in script systems such as Hebrew and Arabic,
 * the glyphs may be draw from right to left, in which case the
 * coordinate supplied is the location of the leftmost character
 * on the baseline.
 * @param iterator the iterator whose text is to be drawn
 * @param x,y the coordinates where the iterator's text should be drawn.
 * @see #setPaint
 * @see java.awt.Graphics#setColor
 * @see #setTransform
 * @see #setComposite
 * @see #setClip
 */
public void drawString(AttributedCharacterIterator iterator,
                                float x, float y) {
    if (iterator == null) {
        throw new
            NullPointerException("AttributedCharacterIterator is null");
    }

    TextLayout layout = new TextLayout(iterator, getFontRenderContext());
    layout.draw(this, x, y);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:PeekGraphics.java


注:本文中的java.awt.font.TextLayout.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。