@Override public Font derive(float size) { return graphics.createFont(name, style, size); }
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; }
@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; } }