JavaTextLayout(String text, TextFormat format, TextLayout layout) { super(text, format, computeBounds(layout)); this.layout = layout; }
@Override public TextLayout layoutText(String text, TextFormat format) { return JavaTextLayout.layoutText(this, text, format); }
void fill(Graphics2D gfx, float x, float y) { paint(gfx, x, y, false); }
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) curPos += 1; // skip over EOLs layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout)); curPos = endPos; } return layouts.toArray(new JavaTextLayout[layouts.size()]); }
@Override public Canvas fillText(TextLayout layout, float x, float y) { currentState().prepareFill(g2d); ((JavaTextLayout)layout).fill(g2d, x, y); isDirty = true; return this; }
public static JavaTextLayout layoutText(JavaGraphics gfx, String text, TextFormat format) { // we do some fiddling to work around the fact that TextLayout chokes on the empty string AttributedString astring = new AttributedString(text.length() == 0 ? " " : text); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, ((JavaFont)format.font).jfont); } FontRenderContext frc = format.antialias ? gfx.aaFontContext : gfx.aFontContext; return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc)); }
@Override public Canvas strokeText(TextLayout layout, float x, float y) { currentState().prepareStroke(g2d); ((JavaTextLayout)layout).stroke(g2d, x, y); isDirty = true; return this; }
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) curPos += 1; // skip over EOLs layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout)); curPos = endPos; } return layouts.toArray(new JavaTextLayout[layouts.size()]); }
@Override public Canvas fillText(TextLayout layout, float x, float y) { currentState().prepareFill(gfx); ((JavaTextLayout)layout).fill(gfx, x, y); isDirty = true; return this; }
public static JavaTextLayout layoutText(JavaGraphics gfx, String text, TextFormat format) { // we do some fiddling to work around the fact that TextLayout chokes on the empty string AttributedString astring = new AttributedString(text.length() == 0 ? " " : text); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, ((JavaFont)format.font).jfont); } FontRenderContext frc = format.antialias ? gfx.aaFontContext : gfx.aFontContext; return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc)); }
@Override public Canvas strokeText(TextLayout layout, float x, float y) { currentState().prepareStroke(gfx); ((JavaTextLayout)layout).stroke(gfx, x, y); isDirty = true; return this; }
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, gfx.resolveFont(format.font)); } 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) curPos += 1; // skip over EOLs layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout)); curPos = endPos; } return layouts.toArray(new JavaTextLayout[layouts.size()]); }
@Override public TextLayout[] layoutText(String text, TextFormat format, TextWrap wrap) { return JavaTextLayout.layoutText(this, text, format, wrap); }
void stroke(Graphics2D gfx, float x, float y) { paint(gfx, x, y, true); }
@Override public Canvas fillText(TextLayout layout, float x, float y) { currentState().prepareFill(g2d); ((JavaTextLayout)layout).fill(g2d, x, y); isDirty = true; return this; }
public static JavaTextLayout layoutText (JavaGraphics gfx, String text, TextFormat format) { // we do some fiddling to work around the fact that TextLayout chokes on the empty string AttributedString astring = new AttributedString(text.length() == 0 ? " " : text); if (format.font != null) { astring.addAttribute(TextAttribute.FONT, gfx.resolveFont(format.font)); } FontRenderContext frc = format.antialias ? gfx.aaFontContext() : gfx.aFontContext(); return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc)); }
@Override public Canvas strokeText(TextLayout layout, float x, float y) { currentState().prepareStroke(gfx); ((JavaTextLayout)layout).stroke(gfx, x, y); isDirty = true; return this; }
JavaTextLayout(String text, TextFormat format, TextLayout layout) { super(text, format, computeBounds(layout)); this.layout = layout; }
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, gfx.resolveFont(format.font)); } 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) curPos += 1; // skip over EOLs layouts.add(new JavaTextLayout(ltext.substring(curPos, endPos), format, layout)); curPos = endPos; } return layouts.toArray(new JavaTextLayout[layouts.size()]); }
@Override public TextLayout[] layoutText(String text, TextFormat format, TextWrap wrap) { return JavaTextLayout.layoutText(this, text, format, wrap); }