public Texture wrapText(String text, float width, TextBlock.Align align) { TextLayout[] layouts = game.graphics.layoutText(text, TEXT_FMT, new TextWrap(width)); Canvas canvas = new TextBlock(layouts).toCanvas(game.graphics, align, 0xFF000000); return canvas.toTexture(); }
@Override public void init() { String text = "The quick brown fox jumped over the lazy dog."; TextFormat format = new TextFormat(new Font("Helvetica", 18)); TextBlock block = new TextBlock(game.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; Canvas canvas = game.graphics.createCanvas(swidth, sheight); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, swidth-0.5f, sheight-0.5f); canvas.scale(scale, scale); canvas.setFillColor(0xFF000000); block.fill(canvas, TextBlock.Align.RIGHT, 0, 0); game.rootLayer.addAt(new ImageLayer(canvas.toTexture()), x, 5); addInfo(canvas, x + swidth/2, sheight + 10); x += swidth + 5; } }
protected Texture makeTextImage() { TextFormat format = new TextFormat(new Font(font.value(), style.value(), 24)); float wrapWidth = wrap.value() == 0 ? Float.MAX_VALUE : game.graphics.viewSize.width()*wrap.value()/100; TextBlock block = new TextBlock( game.graphics.layoutText(sample, format, new TextWrap(wrapWidth))); float awidth = adjustWidth(block.bounds.width()), aheight = adjustHeight(block.bounds.height()); float pad = 1/game.graphics.scale().factor; Canvas canvas = game.graphics.createCanvas(awidth+2*pad, aheight+2*pad); canvas.translate(pad, pad); canvas.setStrokeColor(0xFFFFCCCC).strokeRect(0, 0, awidth, aheight); render(canvas, block, align.value(), lineBounds.value()); return canvas.toTexture(); }