@Override public Canvas scale(float x, float y) { bctx.scaleCTM(x, y); return this; }
@Override public Canvas scale(float x, float y) { bctx.scaleCTM(x, y); return this; }
public RoboCanvas(Graphics gfx, RoboCanvasImage image) { super(gfx, image); // if our size is invalid, we'll fail below at CGBitmapContext, so fail here more usefully if (width <= 0 || height <= 0) throw new IllegalArgumentException( "Invalid size " + width + "x" + height); states.addFirst(new RoboCanvasState()); bctx = image.bctx; // clear the canvas before we scale our bitmap context to avoid artifacts bctx.clearRect(new CGRect(0, 0, texWidth(), texHeight())); // CG coordinate system is OpenGL-style (0,0 in lower left); so we flip it Scale scale = image.scale(); bctx.translateCTM(0, scale.scaled(height)); bctx.scaleCTM(scale.factor, -scale.factor); }
@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(); }
@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(); }
public RoboCanvas(RoboGLContext ctx, float width, float height, boolean interpolate) { super(width, height); // if our size is invalid, we'll fail below at CGBitmapContext, so fail here more usefully if (width <= 0 || height <= 0) throw new IllegalArgumentException( "Invalid size " + width + "x" + height); states.addFirst(new RoboCanvasState()); this.ctx = ctx; // create our raw image data texWidth = ctx.scale.scaledCeil(width); texHeight = ctx.scale.scaledCeil(height); // create the bitmap context via which we'll render into it bctx = RoboGraphics.createCGBitmap(texWidth, texHeight); if (!interpolate) { bctx.setInterpolationQuality(CGInterpolationQuality.None); } // clear the canvas before we scale our bitmap context to avoid artifacts bctx.clearRect(new CGRect(0, 0, texWidth, texHeight)); // CG coordinate system is OpenGL-style (0,0 in lower left); so we flip it bctx.translateCTM(0, ctx.scale.scaled(height)); bctx.scaleCTM(ctx.scale.factor, -ctx.scale.factor); }
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 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 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; }