use of playn.core.TextWrap in project playn by threerings.
the class SoundTest method addAction.
protected void addAction(String action) {
_actions.add(0, action);
if (_actions.size() > 10)
_actions.subList(10, _actions.size()).clear();
_actionsImage.canvas().clear();
StringBuilder buf = new StringBuilder();
for (String a : _actions) {
if (buf.length() > 0)
buf.append("\n");
buf.append(a);
}
_actionsImage.canvas().setFillColor(0xFF000000);
float y = 0;
for (TextLayout layout : graphics().layoutText(buf.toString(), TEXT_FMT, new TextWrap(300))) {
_actionsImage.canvas().fillText(layout, 0, y);
y += layout.ascent() + layout.descent() + layout.leading();
}
}
use of playn.core.TextWrap in project playn by threerings.
the class TextTest method makeTextImage.
protected Image makeTextImage() {
TextFormat format = new TextFormat(graphics().createFont(font.value(), style.value(), 24), true);
float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : graphics().width() * wrap.value() / 100;
TextBlock block = new TextBlock(graphics().layoutText(sample, format, new TextWrap(wrapWidth)));
float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height());
float pad = TextBlock.pad();
CanvasImage image = graphics().createImage(awidth + 2 * pad, aheight + 2 * pad);
image.canvas().translate(pad, pad);
image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight);
render(image.canvas(), block, align.value(), lineBounds.value());
return image;
}
use of playn.core.TextWrap in project playn by threerings.
the class ScaledTextTest method init.
@Override
public void init() {
String text = "The quick brown fox jumped over the lazy dog.";
TextFormat format = new TextFormat().withFont(graphics().createFont("Helvetica", Font.Style.PLAIN, 18));
TextBlock block = new TextBlock(graphics().layoutText(text, format, new TextWrap(100)));
float x = 5;
for (float scale : new float[] { 1f, 2f, 3f }) {
float swidth = block.bounds.width() * scale, sheight = block.bounds.height() * scale;
CanvasImage image = graphics().createImage(swidth, sheight);
image.canvas().setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth - 0.5f, sheight - 0.5f);
image.canvas().scale(scale, scale);
image.canvas().setFillColor(0xFF000000);
block.fill(image.canvas(), TextBlock.Align.RIGHT, 0, 0);
graphics().rootLayer().addAt(graphics().createImageLayer(image), x, 5);
addInfo(image, x + swidth / 2, sheight + 10);
x += swidth + 5;
}
}
Aggregations