@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; }