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


Java TextLayout类代码示例

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


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

示例1: paint

import java.awt.font.TextLayout; //导入依赖的package包/类
@Override
public void paint(Graphics g) {
	Dimension d = vv.getSize();
	FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
	Font f = new Font("Times", Font.BOLD, 30);

	TextLayout tl = new TextLayout(str, f, frc);
	AffineTransform transform = new AffineTransform();
	transform.setToTranslation(d.width / 2, d.height / 2);
	transform.rotate(Math.toRadians(315));
	Shape shape = tl.getOutline(transform);
	g.translate(-shape.getBounds().width / 2,
			shape.getBounds().height / 2);
	g.setColor(Color.lightGray);
	((Graphics2D) g).draw(shape);
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:17,代码来源:LayerViewer.java

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

示例3: runTest

import java.awt.font.TextLayout; //导入依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    TextHitInfo[] hits = tlctx.hits;
    Rectangle2D lb = tlctx.lb;
    Shape s;
    if (hits.length < 3) {
        do {
            s = tl.getVisualHighlightShape(hits[0], hits[hits.length - 1], lb);
        } while (--numReps >= 0);
    } else {
        do {
            for (int i = 3; i < hits.length; ++i) {
                s = tl.getVisualHighlightShape(hits[i-3], hits[i], lb);
            }
        } while (--numReps >= 0);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TextMeasureTests.java

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

示例5: getRealAlloc

import java.awt.font.TextLayout; //导入依赖的package包/类
/**
     * Get real allocation (possibly not rectangular) of a part of layout.
     * <br>
     * It's used when rendering the text layout for filling background highlights of the view.
     *
     * @param length Total number of characters for which the allocation is computed.
     * @param alloc Allocation given by a parent view.
     * @return
     */
    public static Shape getRealAlloc(TextLayout textLayout, Rectangle2D textLayoutRect,
            TextHitInfo startHit, TextHitInfo endHit)
    {
        // Quick-fix to eliminate missing line in rendering italic "d" - more elaborate fix is needed
        textLayoutRect = new Rectangle2D.Double(textLayoutRect.getX(), textLayoutRect.getY(),
                textLayoutRect.getWidth() + 2, textLayoutRect.getHeight());
        Rectangle2D.Double zeroBasedRect = ViewUtils.shape2Bounds(textLayoutRect);
        zeroBasedRect.x = 0;
        zeroBasedRect.y = 0;
        Shape ret = textLayout.getVisualHighlightShape(startHit, endHit, zeroBasedRect);
        AffineTransform transform = AffineTransform.getTranslateInstance(
                textLayoutRect.getX(),
                textLayoutRect.getY()
        );
        ret = transform.createTransformedShape(ret);
        // The following gives bad result for some reason (works for layout but not for caret modelToView())
//        Shape ret2 = textLayout.getVisualHighlightShape(startHit.getCharIndex(), endHit.getCharIndex(), textLayoutRect);
        return ret;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:TextLayoutUtils.java

示例6: createPartTextLayout

import java.awt.font.TextLayout; //导入依赖的package包/类
TextLayout createPartTextLayout(int shift, int length) {
    checkTextLayoutValid();
    if (breakInfo == null) {
        breakInfo = new TextLayoutBreakInfo(textLayout.getCharacterCount());
    }
    TextLayout partTextLayout = breakInfo.findPartTextLayout(shift, length);
    if (partTextLayout == null) {
        DocumentView docView = getDocumentView();
        Document doc = docView.getDocument();
        CharSequence docText = DocumentUtilities.getText(doc);
        int startOffset = getStartOffset();
        String text = docText.subSequence(startOffset + shift, startOffset + shift + length).toString();
        if (docView.op.isNonPrintableCharactersVisible()) {
            text = text.replace(' ', DocumentViewOp.PRINTING_SPACE);
        }
        AttributeSet attrs = ViewUtils.getFirstAttributes(getAttributes());
        Font font = ViewUtils.getFont(attrs, docView.op.getDefaultFont());
        partTextLayout = docView.op.createTextLayout(text, font);
        breakInfo.add(shift, length, partTextLayout);
    }
    return partTextLayout;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HighlightsView.java

示例7: indexToView

import java.awt.font.TextLayout; //导入依赖的package包/类
static Shape indexToView(TextLayout textLayout, Rectangle2D textLayoutBounds,
            int index, Position.Bias bias, int maxIndex, Shape alloc)
   {
       if (textLayout == null) {
           return alloc; // Leave given bounds
       }
       assert (maxIndex <= textLayout.getCharacterCount()) : "textLayout.getCharacterCount()=" + // NOI18N
               textLayout.getCharacterCount() + " < maxIndex=" + maxIndex; // NOI18N
       // If offset is >getEndOffset() use view-end-offset - otherwise it would throw exception from textLayout.getCaretInfo()
int charIndex = Math.min(index, maxIndex);
       // When e.g. creating fold-preview the offset can be < startOffset
       charIndex = Math.max(charIndex, 0);
       TextHitInfo startHit;
       TextHitInfo endHit;
       if (bias == Position.Bias.Forward) {
           startHit = TextHitInfo.leading(charIndex);
       } else { // backward bias
           startHit = TextHitInfo.trailing(charIndex - 1);
       }
       endHit = (charIndex < maxIndex) ? TextHitInfo.trailing(charIndex) : startHit;
       if (textLayoutBounds == null) {
           textLayoutBounds = ViewUtils.shapeAsRect(alloc);
       }
       return TextLayoutUtils.getRealAlloc(textLayout, textLayoutBounds, startHit, endHit);
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:HighlightsViewUtils.java

示例8: getTextLayout

import java.awt.font.TextLayout; //导入依赖的package包/类
private TextLayout getTextLayout() {
    if (collapsedTextLayout == null) {
        EditorView.Parent parent = (EditorView.Parent) getParent();
        ViewRenderContext context = parent.getViewRenderContext();
        FontRenderContext frc = context.getFontRenderContext();
        assert (frc != null) : "Null FontRenderContext"; // NOI18N
        Font font = context.getRenderFont(component.getFont());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < indent; i++) {
            sb.append(' ');
        }
        sb.append("...");
        String text = sb.toString();
        collapsedTextLayout = new TextLayout(text, font, frc);
    }
    return collapsedTextLayout;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SkipLinesViewFactory.java

示例9: main

import java.awt.font.TextLayout; //导入依赖的package包/类
public static void main(String args[]) {

        Font font = new Font(Font.DIALOG, Font.PLAIN, 12);
        String text = "hello world";
        FontRenderContext frc = new FontRenderContext(null, false, false);
        TextLayout tl1 = new TextLayout(text, font, frc);
        TextLayout tl2 = new TextLayout(text, font, frc);
        if (tl1.equals(tl2) ||
            tl2.equals(tl1) ||
            tl1.equals((Object)tl2) ||
            tl2.equals((Object)tl1))
        {
             throw new RuntimeException("Equal TextLayouts");
        }
        if (!tl1.equals(tl1) ||
            !tl1.equals((Object)tl1))
        {
             throw new RuntimeException("Non-Equal TextLayouts");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TextLayoutEqualsTest.java

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

示例11: getPreferredSize

import java.awt.font.TextLayout; //导入依赖的package包/类
@Override
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null || tipText.isEmpty()) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(tipText)) {
        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);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:32,代码来源:FreeColToolTipUI.java

示例12: runTest

import java.awt.font.TextLayout; //导入依赖的package包/类
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    int len = tlctx.text.length();
    Rectangle2D lb = tlctx.lb;
    Shape s;
    if (len < 3) {
        do {
            s = tl.getLogicalHighlightShape(0, len, lb);
        } while (--numReps >= 0);
    } else {
        do {
            for (int i = 3; i < len; ++i) {
                s = tl.getLogicalHighlightShape(i-3, i, lb);
            }
        } while (--numReps >= 0);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:TextMeasureTests.java

示例13: getCaretRectangle

import java.awt.font.TextLayout; //导入依赖的package包/类
private Rectangle getCaretRectangle(TextHitInfo caret) {
    int caretLocation = 0;
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
    }
    Graphics g = getGraphics();
    FontMetrics metrics = null;
    try {
        metrics = g.getFontMetrics();
    } finally {
        g.dispose();
    }
    return new Rectangle(TEXT_ORIGIN_X + caretLocation,
                         TEXT_ORIGIN_Y - metrics.getAscent(),
                         0, metrics.getAscent() + metrics.getDescent());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:CompositionArea.java

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

示例15: computeDimensions

import java.awt.font.TextLayout; //导入依赖的package包/类
private void computeDimensions(Graphics g, Font font, FontMetrics fm) {
	String s = text;
	FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
	width = fm.stringWidth(s);
	ascent = fm.getAscent();
	descent = fm.getDescent();
	int[] xs = new int[s.length()];
	int[] ys = new int[s.length()];
	for (int i = 0; i < xs.length; i++) {
		xs[i] = fm.stringWidth(s.substring(0, i + 1));
		TextLayout lay = new TextLayout(s.substring(i, i + 1), font, frc);
		Rectangle2D rect = lay.getBounds();
		int asc = (int) Math.ceil(-rect.getMinY());
		int desc = (int) Math.ceil(rect.getMaxY());
		if (asc < 0)
			asc = 0;
		if (asc > 0xFFFF)
			asc = 0xFFFF;
		if (desc < 0)
			desc = 0;
		if (desc > 0xFFFF)
			desc = 0xFFFF;
		ys[i] = (asc << 16) | desc;
	}
	charX = xs;
	charY = ys;
	dimsKnown = true;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:29,代码来源:EditableLabel.java


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