diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index e6859c3..333f728 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1041,9 +1041,34 @@ Context2d::FillRect(const Arguments &args) { Context2d *context = ObjectWrap::Unwrap(args.This()); cairo_t *ctx = context->getContext(); cairo_new_path(ctx); + + cairo_rectangle(ctx, x, y, width, height); + context->savePath(); + + if (!context->hasShadow()) { + cairo_rectangle(ctx, x, y, width, height); + SET_SOURCE(context->state->fill); + cairo_fill(ctx); + return Undefined(); + } + + cairo_translate( + ctx + , context->state->shadowOffsetX + , context->state->shadowOffsetY); + cairo_rectangle(ctx, x, y, width, height); SET_SOURCE(context->state->fill); cairo_fill(ctx); + Canvas::blur(context->getCanvas()->getSurface(), context->state->shadowBlur); + + cairo_translate( + ctx + , -context->state->shadowOffsetX + , -context->state->shadowOffsetY); + + context->restorePath(); + cairo_fill(ctx); return Undefined(); } @@ -1134,3 +1159,17 @@ Context2d::Arc(const Arguments &args) { return Undefined(); } + +/* + * Check if the context has a drawable shadow. + * + * The spec states we mush have an alpha > 0, + * as well as either x or y offset, however most + * implementations render with offsets of 0 so + * we will only take alpha into consideration. + */ + +bool +Context2d::hasShadow() { + return state->shadow.a; +} \ No newline at end of file diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 2cd10e9..2b65615 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -100,6 +100,7 @@ class Context2d: public node::ObjectWrap { static void SetShadowBlur(Local prop, Local val, const AccessorInfo &info); inline cairo_t *getContext(){ return _context; } inline Canvas *getCanvas(){ return _canvas; } + bool hasShadow(); void setTextPath(const char *str, double x, double y); void savePath(); void restorePath();