@Override public Canvas save() { states.addFirst(new RoboCanvasState(currentState())); bctx.saveGState(); return this; }
@Override public Canvas save() { states.addFirst(new RoboCanvasState(currentState())); bctx.saveGState(); return this; }
@Override public void draw(Object ctx, float x, float y, float width, float height) { CGBitmapContext bctx = (CGBitmapContext)ctx; // pesky fiddling to cope with the fact that UIImages are flipped; TODO: make sure drawing a // canvas image on a canvas image does the right thing y += height; bctx.saveGState(); bctx.translateCTM(x, y); bctx.scaleCTM(1, -1); bctx.drawImage(new CGRect(0, 0, width, height), cgImage()); bctx.restoreGState(); }
@Override public void draw(CGBitmapContext bctx, float x, float y, float width, float height) { CGImage cgImage = cgImage(); // pesky fiddling to cope with the fact that UIImages are flipped; TODO: make sure drawing a // canvas image on a canvas image does the right thing y += height; bctx.saveGState(); bctx.translateCTM(x, y); bctx.scaleCTM(1, -1); bctx.drawImage(new CGRect(0, 0, width, height), cgImage); bctx.restoreGState(); }
private void paint(CGBitmapContext bctx, CTLine line, float x, float y) { bctx.saveGState(); bctx.translateCTM(x, y + ascent()); bctx.scaleCTM(1, -1); bctx.setShouldAntialias(format.antialias); bctx.setTextPosition(0, 0); line.draw(bctx); bctx.restoreGState(); }
private void paint(CGBitmapContext bctx, CTLine line, float x, float y) { bctx.saveGState(); bctx.translateCTM(x, y + ascent()); bctx.scaleCTM(1, -1); bctx.setShouldAntialias(format.antialias); bctx.setTextPosition(0, 0); line.draw(bctx); bctx.restoreGState(); }
@Override public Canvas fillRect(float x, float y, float width, float height) { RoboGradient gradient = currentState().gradient; if (gradient == null) { bctx.fillRect(new CGRect(x, y, width, height)); } else { bctx.saveGState(); bctx.clipToRect(new CGRect(x, y, width, height)); gradient.fill(bctx); bctx.restoreGState(); } isDirty = true; return this; }
@Override public Canvas drawText(String text, float x, float y) { bctx.saveGState(); bctx.translateCTM(x, y + RoboGraphics.defaultFont.ctFont.getDescent()); bctx.scaleCTM(1, -1); bctx.selectFont(RoboGraphics.defaultFont.iosName(), RoboGraphics.defaultFont.size(), CGTextEncoding.MacRoman); bctx.showTextAtPoint(0, 0, text); bctx.restoreGState(); isDirty = true; return this; }
@Override public Canvas fillRect(float x, float y, float width, float height) { RoboGradient gradient = currentState().gradient; if (gradient == null) { bctx.fillRect(new CGRect(x, y, width, height)); } else { bctx.saveGState(); bctx.clipToRect(new CGRect(x, y, width, height)); gradient.fill(bctx); bctx.restoreGState(); } isDirty = true; return this; }
@Override public Canvas drawText(String text, float x, float y) { CTFont font = RoboFont.resolveFont(null); // default font bctx.saveGState(); bctx.translateCTM(x, y + font.getDescent()); bctx.scaleCTM(1, -1); bctx.selectFont(font.getPostScriptName(), font.getSize(), CGTextEncoding.MacRoman); bctx.showTextAtPoint(0, 0, text); bctx.restoreGState(); isDirty = true; return this; }
@Override public void draw(CGBitmapContext bctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor sx *= scale.factor; sy *= scale.factor; sw *= scale.factor; sh *= scale.factor; CGImage cgImage = cgImage(); float iw = cgImage.getWidth(), ih = cgImage.getHeight(); float scaleX = dw/sw, scaleY = dh/sh; // pesky fiddling to cope with the fact that UIImages are flipped bctx.saveGState(); bctx.translateCTM(dx, dy+dh); bctx.scaleCTM(1, -1); bctx.clipToRect(new CGRect(0, 0, dw, dh)); bctx.translateCTM(-sx*scaleX, -(ih-(sy+sh))*scaleY); bctx.drawImage(new CGRect(0, 0, iw*scaleX, ih*scaleY), cgImage); bctx.restoreGState(); }
@Override public void draw(Object ctx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { // adjust our source rect to account for the scale factor sx *= scale.factor; sy *= scale.factor; sw *= scale.factor; sh *= scale.factor; CGImage image = cgImage(); CGBitmapContext bctx = (CGBitmapContext)ctx; float iw = image.getWidth(), ih = image.getHeight(); float scaleX = dw/sw, scaleY = dh/sh; // pesky fiddling to cope with the fact that UIImages are flipped bctx.saveGState(); bctx.translateCTM(dx, dy+dh); bctx.scaleCTM(1, -1); bctx.clipToRect(new CGRect(0, 0, dw, dh)); bctx.translateCTM(-sx*scaleX, -(ih-(sy+sh))*scaleY); bctx.drawImage(new CGRect(0, 0, iw*scaleX, ih*scaleY), image); bctx.restoreGState(); }
@Override public Canvas fillText(TextLayout layout, float x, float y) { RoboGradient gradient = currentState().gradient; RoboTextLayout ilayout = (RoboTextLayout) layout; if (gradient == null) { ilayout.fill(bctx, x, y, fillColor); } else { // draw our text into a fresh context so we can use it as a mask for the gradient CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth, texHeight); maskContext.clearRect(new CGRect(0, 0, texWidth, texHeight)); // scale the context based on our scale factor maskContext.scaleCTM(ctx.scale.factor, ctx.scale.factor); // fill the text into this temp context in white for use as a mask setFillColor(maskContext, 0xFFFFFFFF); ilayout.fill(maskContext, 0, 0, fillColor); // now fill the gradient, using our temp context as a mask bctx.saveGState(); bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage()); gradient.fill(bctx); bctx.restoreGState(); // finally free the temp context maskContext.dispose(); } isDirty = true; return this; }
@Override public Canvas fillText(TextLayout layout, float x, float y) { RoboGradient gradient = currentState().gradient; RoboTextLayout ilayout = (RoboTextLayout) layout; if (gradient == null) { ilayout.fill(bctx, x, y, fillColor); } else { // draw our text into a fresh context so we can use it as a mask for the gradient CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth(), texHeight()); maskContext.clearRect(new CGRect(0, 0, texWidth(), texHeight())); // scale the context based on our scale factor float scale = image.scale().factor; maskContext.scaleCTM(scale, scale); // fill the text into this temp context in white for use as a mask setFillColor(maskContext, 0xFFFFFFFF); ilayout.fill(maskContext, 0, 0, fillColor); // now fill the gradient, using our temp context as a mask bctx.saveGState(); bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage()); gradient.fill(bctx); bctx.restoreGState(); // finally free the temp context maskContext.dispose(); } isDirty = true; return this; }