use of java.awt.font.TextLayout in project limelight by slagyr.
the class TextPanel method calculateDimensions.
private void calculateDimensions() {
consumedHeight = 0;
consumedWidth = 0;
synchronized (this) {
for (TextLayout layout : lines) {
consumedHeight += (layout.getAscent() + layout.getDescent() + layout.getLeading());
double lineWidth = widthOf(layout);
if (lineWidth > consumedWidth)
consumedWidth = lineWidth;
}
}
}
use of java.awt.font.TextLayout in project antlrworks by antlr.
the class GEngineGraphics method drawString.
public void drawString(Font font, String s, float x, float y, int align) {
getG2D().setFont(font);
TextLayout layout = new TextLayout(s, font, getG2D().getFontRenderContext());
float tx = Float.MIN_VALUE;
float ty = Float.MIN_VALUE;
switch(align) {
case GContext.ALIGN_CENTER:
tx = (float) (x - layout.getBounds().getWidth() * 0.5);
ty = (float) (y + layout.getBounds().getHeight() * 0.5);
break;
case GContext.ALIGN_CENTER_UP:
tx = (float) (x - layout.getBounds().getWidth() * 0.5);
ty = y;
break;
case GContext.ALIGN_RIGHT:
tx = (float) (x - layout.getBounds().getWidth());
ty = (float) (y + layout.getBounds().getHeight() * 0.5);
break;
case GContext.ALIGN_LEFT:
tx = x;
ty = (float) (y + layout.getBounds().getHeight() * 0.5);
break;
}
layout.draw(getG2D(), tx, ty - 1);
}
use of java.awt.font.TextLayout in project antlrworks by antlr.
the class GEngineGraphics method getStringPixelWidth.
public float getStringPixelWidth(Font font, String s) {
getG2D().setFont(font);
TextLayout layout = new TextLayout(s, getG2D().getFont(), getG2D().getFontRenderContext());
return (float) layout.getBounds().getWidth();
}
use of java.awt.font.TextLayout in project playn by threerings.
the class JavaTextLayout method layoutText.
public static JavaTextLayout[] layoutText(JavaGraphics gfx, String text, TextFormat format, TextWrap wrap) {
// normalize newlines in the text (Windows: CRLF -> LF, Mac OS pre-X: CR -> LF)
text = normalizeEOL(text);
// we do some fiddling to work around the fact that TextLayout chokes on the empty string
String ltext = text.length() == 0 ? " " : text;
// set up an attributed character iterator so that we can measure the text
AttributedString astring = new AttributedString(ltext);
if (format.font != null) {
astring.addAttribute(TextAttribute.FONT, ((JavaFont) format.font).jfont);
}
List<JavaTextLayout> layouts = new ArrayList<JavaTextLayout>();
FontRenderContext frc = format.antialias ? gfx.aaFontContext : gfx.aFontContext;
LineBreakMeasurer measurer = new LineBreakMeasurer(astring.getIterator(), frc);
int lastPos = ltext.length(), curPos = 0;
char eol = '\n';
while (curPos < lastPos) {
int nextRet = ltext.indexOf(eol, measurer.getPosition() + 1);
if (nextRet == -1) {
nextRet = lastPos;
}
TextLayout layout = measurer.nextLayout(wrap.width, nextRet, false);
int endPos = measurer.getPosition();
while (curPos < endPos && ltext.charAt(curPos) == eol) // skip over EOLs
curPos += 1;
layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout));
curPos = endPos;
}
return layouts.toArray(new JavaTextLayout[layouts.size()]);
}
use of java.awt.font.TextLayout in project binnavi by google.
the class ZyCaret method calcHitPosition.
private int calcHitPosition(final int caretPosition, final double x, final double y, final double zoomFactor) {
boolean switched = false;
int lp = m_mouse_pressed_y;
int lr = m_mouse_released_y;
if (lp > lr) {
lp = m_mouse_released_y;
lr = m_mouse_pressed_y;
switched = true;
}
final int linecount = m_content.getLineCount();
final double height = (float) m_content.getLineHeight();
int maxIndex = caretPosition;
for (int line = lp; line <= lr; line++) {
double deltaY = 0;
if (switched) {
deltaY = height * zoomFactor * line;
} else {
deltaY = -(height * zoomFactor * (linecount - line));
}
final TextLayout textLayout = m_content.getLineContent(line).getTextLayout();
final TextHitInfo hitInfo = textLayout.hitTestChar((float) x, (float) (y + deltaY), textLayout.getBounds());
final int insertionIndex = hitInfo.getInsertionIndex();
if ((caretPosition < insertionIndex) && (insertionIndex > maxIndex)) {
maxIndex = insertionIndex;
}
}
return maxIndex;
}
Aggregations