Browse Source

Added Context2d::hasShadow()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
9ed1a24b43
  1. 39
      src/CanvasRenderingContext2d.cc
  2. 1
      src/CanvasRenderingContext2d.h

39
src/CanvasRenderingContext2d.cc

@ -1041,9 +1041,34 @@ Context2d::FillRect(const Arguments &args) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(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;
}

1
src/CanvasRenderingContext2d.h

@ -100,6 +100,7 @@ class Context2d: public node::ObjectWrap {
static void SetShadowBlur(Local<String> prop, Local<Value> 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();

Loading…
Cancel
Save