/** * Creates a canvas image large enough to accommodate this text block and renders the lines into * it. The image will include padding around the edge to ensure that antialiasing has a bit of * extra space to do its work. */ public Canvas toCanvas(Graphics gfx, Align align, int fillColor) { float pad = 1/gfx.scale().factor; Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad); canvas.setFillColor(fillColor); fill(canvas, align, pad, pad); return canvas; } }
/** * Creates a canvas image large enough to accommodate this text block and renders the lines into * it. The image will include padding around the edge to ensure that antialiasing has a bit of * extra space to do its work. */ public Canvas toCanvas(Graphics gfx, Align align, int fillColor) { float pad = 1/gfx.scale().factor; Canvas canvas = gfx.createCanvas(bounds.width()+2*pad, bounds.height()+2*pad); canvas.setFillColor(fillColor); fill(canvas, align, pad, pad); return canvas; } }
@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; } }