@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);
}
java类java.awt.font.TextLayout的实例源码
LayerViewer.java 文件源码
项目:alevin-svn2
阅读 25
收藏 0
点赞 0
评论 0
FoldView.java 文件源码
项目:incubator-netbeans
阅读 26
收藏 0
点赞 0
评论 0
@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;
}
}
TextMeasureTests.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
SunGraphics2D.java 文件源码
项目:jdk8u-jdk
阅读 28
收藏 0
点赞 0
评论 0
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);
}
TextLayoutUtils.java 文件源码
项目:incubator-netbeans
阅读 18
收藏 0
点赞 0
评论 0
/**
* 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;
}
HighlightsView.java 文件源码
项目:incubator-netbeans
阅读 18
收藏 0
点赞 0
评论 0
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;
}
HighlightsViewUtils.java 文件源码
项目:incubator-netbeans
阅读 22
收藏 0
点赞 0
评论 0
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);
}
SkipLinesViewFactory.java 文件源码
项目:incubator-netbeans
阅读 22
收藏 0
点赞 0
评论 0
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;
}
TextMeasureTests.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
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);
}
}
TextLayoutEqualsTest.java 文件源码
项目:openjdk-jdk10
阅读 20
收藏 0
点赞 0
评论 0
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");
}
}
PdfBoxGraphics2D.java 文件源码
项目:pdfbox-graphics2d
阅读 27
收藏 0
点赞 0
评论 0
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;
}
FreeColToolTipUI.java 文件源码
项目:FreeCol
阅读 28
收藏 0
点赞 0
评论 0
@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));
}
TextMeasureTests.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
TextMeasureTests.java 文件源码
项目:OpenJSharp
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
CompositionArea.java 文件源码
项目:jdk8u-jdk
阅读 25
收藏 0
点赞 0
评论 0
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());
}
CompositionArea.java 文件源码
项目:OpenJSharp
阅读 29
收藏 0
点赞 0
评论 0
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());
}
TextMeasureTests.java 文件源码
项目:jdk8u-jdk
阅读 15
收藏 0
点赞 0
评论 0
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);
}
}
SpeechBubble.java 文件源码
项目:litiengine
阅读 27
收藏 0
点赞 0
评论 0
@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();
}
}
EditableLabel.java 文件源码
项目:Logisim
阅读 25
收藏 0
点赞 0
评论 0
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;
}
PathGraphics.java 文件源码
项目:jdk8u-jdk
阅读 32
收藏 0
点赞 0
评论 0
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);
}
FoldView.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
static TextHitInfo x2RelOffset(TextLayout textLayout, float x) {
TextHitInfo hit;
x -= EXTRA_MARGIN_WIDTH;
if (x >= textLayout.getAdvance()) {
hit = TextHitInfo.trailing(textLayout.getCharacterCount());
} else {
hit = textLayout.hitTestChar(x, 0); // What about backward bias -> with higher offsets it may go back visually
}
return hit;
}
DrawGraphics.java 文件源码
项目:incubator-netbeans
阅读 22
收藏 0
点赞 0
评论 0
private static void drawStringTextLayout(JComponent c, Graphics g, String text, int x, int baselineY) {
if (!(g instanceof Graphics2D)) {
g.drawString(text, x, baselineY);
} else { // Graphics2D available
Graphics2D g2d = (Graphics2D)g;
FontRenderContext frc = g2d.getFontRenderContext();
TextLayout layout = new TextLayout(text, g2d.getFont(), frc);
layout.draw(g2d, x, baselineY);
}
}
GlyphGutter.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
protected int getLineNumberWidth() {
int newWidth = 0;
EditorUI eui = editorUI;
if (eui != null) {
/*
Insets insets = eui.getLineNumberMargin();
if (insets != null) {
newWidth += insets.left + insets.right;
}
*/
JTextComponent tc = eui.getComponent();
if (font != null && tc != null) {
Graphics g;
FontRenderContext frc;
FontMetrics fm;
if ((g = tc.getGraphics()) != null && (g instanceof Graphics2D) &&
(frc = ((Graphics2D)g).getFontRenderContext()) != null)
{
newWidth += new TextLayout(String.valueOf(highestLineNumber), font, frc).getAdvance();
} else if ((fm = getFontMetrics(font)) != null) {
// Use FontMetrics.stringWidth() as best approximation
newWidth += fm.stringWidth(String.valueOf(highestLineNumber));
}
}
}
return newWidth;
}
SunGraphics2D.java 文件源码
项目:jdk8u-jdk
阅读 24
收藏 0
点赞 0
评论 0
public void drawString(String str, int x, int y) {
if (str == null) {
throw new NullPointerException("String is null");
}
if (font.hasLayoutAttributes()) {
if (str.length() == 0) {
return;
}
new TextLayout(str, font, getFontRenderContext()).draw(this, x, y);
return;
}
try {
textpipe.drawString(this, str, x, y);
} catch (InvalidPipeException e) {
try {
revalidateAll();
textpipe.drawString(this, str, x, y);
} catch (InvalidPipeException e2) {
// Still catching the exception; we are not yet ready to
// validate the surfaceData correctly. Fail for now and
// try again next time around.
}
} finally {
surfaceData.markDirty();
}
}
TextMeasureTests.java 文件源码
项目:jdk8u-jdk
阅读 19
收藏 0
点赞 0
评论 0
public void runTest(Object ctx, int numReps) {
TLContext tlctx = (TLContext)ctx;
TextLayout tl = tlctx.tl;
Shape s;
do {
s = tl.getOutline(null);
} while (--numReps >= 0);
}
FontInfo.java 文件源码
项目:incubator-netbeans
阅读 23
收藏 0
点赞 0
评论 0
FontInfo(Font origFont, JTextComponent textComponent, FontRenderContext frc, float rowHeightCorrection, int textZoom) {
renderFont = (textZoom != 0)
? new Font(origFont.getName(), origFont.getStyle(), Math.max(origFont.getSize() + textZoom, 1))
: origFont;
char defaultChar = 'A';
String defaultCharText = String.valueOf(defaultChar);
TextLayout defaultCharTextLayout = new TextLayout(defaultCharText, renderFont, frc); // NOI18N
TextLayout rowHeightTextLayout = new TextLayout("A_|B", renderFont, frc);
// Round the ascent to eliminate long mantissa without any visible effect on rendering.
updateRowHeight(rowHeightTextLayout, rowHeightCorrection);
// Ceil fractions to whole numbers since this measure may be used for background rendering
charWidth = (float) Math.ceil(defaultCharTextLayout.getAdvance());
LineMetrics lineMetrics = renderFont.getLineMetrics(defaultCharText, frc);
underlineAndStrike[0] = lineMetrics.getUnderlineOffset() * rowHeightCorrection;
underlineAndStrike[1] = lineMetrics.getUnderlineThickness();
underlineAndStrike[2] = lineMetrics.getStrikethroughOffset() * rowHeightCorrection;
underlineAndStrike[3] = lineMetrics.getStrikethroughThickness();
if (LOG.isLoggable(Level.FINE)) {
FontMetrics fm = textComponent.getFontMetrics(origFont); // From original font
LOG.fine("Orig Font=" + origFont + // NOI18N
"\n " + this + ", charWidth=" + charWidth + ", textZoom=" + textZoom + // NOI18N
"\n rowHeightCorrection=" + rowHeightCorrection + // NOI18N
", underlineO/T=" + underlineAndStrike[0] + "/" + underlineAndStrike[1] + // NOI18N
", strikethroughO/T=" + underlineAndStrike[2] + "/" + underlineAndStrike[3] + // NOI18N
"\n FontMetrics (for comparison; without-RHC): fm-line-height=" + fm.getHeight() + // NOI18N
", fm-ascent,descent,leading=" + fm.getAscent() + "," + fm.getDescent() + "," + fm.getLeading() + // NOI18N
"\n"); // NOI18N
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "FontInfo creation stacktrace", new Exception()); // NOI18N
}
}
}
OutlineTextRenderer.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
public void drawString(SunGraphics2D g2d, String str, double x, double y) {
if ("".equals(str)) {
return; // TextLayout constructor throws IAE on "".
}
TextLayout tl = new TextLayout(str, g2d.getFont(),
g2d.getFontRenderContext());
Shape s = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
int textAAHint = g2d.getFontInfo().aaHint;
int prevaaHint = - 1;
if (textAAHint != SunHints.INTVAL_TEXT_ANTIALIAS_OFF &&
g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_ON;
g2d.validatePipe();
} else if (textAAHint == SunHints.INTVAL_TEXT_ANTIALIAS_OFF
&& g2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_OFF) {
prevaaHint = g2d.antialiasHint;
g2d.antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
g2d.validatePipe();
}
g2d.fill(s);
if (prevaaHint != -1) {
g2d.antialiasHint = prevaaHint;
g2d.validatePipe();
}
}
GlyphListPipe.java 文件源码
项目:jdk8u-jdk
阅读 27
收藏 0
点赞 0
评论 0
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);
}
}
DocumentViewOp.java 文件源码
项目:incubator-netbeans
阅读 32
收藏 0
点赞 0
评论 0
/**
* 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;
}
TextMeasureTests.java 文件源码
项目:openjdk-jdk10
阅读 17
收藏 0
点赞 0
评论 0
public void runTest(Object ctx, int numReps) {
TLContext tlctx = (TLContext)ctx;
TextLayout tl = tlctx.tl;
Rectangle2D r;
do {
r = tl.getBounds();
} while (--numReps >= 0);
}