Browse Source

Merge branch 'pattern-quality'

v1.x
Tj Holowaychuk 14 years ago
parent
commit
24887349b6
  1. 8
      Readme.md
  2. 37
      src/CanvasRenderingContext2d.cc
  3. 3
      src/CanvasRenderingContext2d.h

8
Readme.md

@ -90,6 +90,14 @@ or specify the mime type:
});
### CanvasRenderingContext2d#patternQuality
Given one of the values below will alter pattern (gradients, images, etc) render quality, defaults to _good_.
- fast
- good
- best
### Global Composite Operations
In addition to those specified and commonly implemented by browsers, the following have been added:

37
src/CanvasRenderingContext2d.cc

@ -94,6 +94,7 @@ Context2d::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "setStrokeColor", SetStrokeColor);
NODE_SET_PROTOTYPE_METHOD(constructor, "setFillPattern", SetFillPattern);
NODE_SET_PROTOTYPE_METHOD(constructor, "setStrokePattern", SetStrokePattern);
proto->SetAccessor(String::NewSymbol("patternQuality"), GetPatternQuality, SetPatternQuality);
proto->SetAccessor(String::NewSymbol("globalCompositeOperation"), GetGlobalCompositeOperation, SetGlobalCompositeOperation);
proto->SetAccessor(String::NewSymbol("globalAlpha"), GetGlobalAlpha, SetGlobalAlpha);
proto->SetAccessor(String::NewSymbol("shadowColor"), GetShadowColor, SetShadowColor);
@ -130,6 +131,7 @@ Context2d::Context2d(Canvas *canvas) {
state->fill = transparent;
state->stroke = transparent;
state->shadow = transparent_black;
state->patternQuality = CAIRO_FILTER_GOOD;
}
/*
@ -568,6 +570,7 @@ Context2d::DrawImage(const Arguments &args) {
// Paint
cairo_set_source_surface(ctx, src, dx, dy);
cairo_pattern_set_filter(cairo_get_source(ctx), context->state->patternQuality);
cairo_paint_with_alpha(ctx, context->state->globalAlpha);
cairo_restore(ctx);
@ -659,6 +662,40 @@ Context2d::GetGlobalCompositeOperation(Local<String> prop, const AccessorInfo &i
}
}
/*
* Set pattern quality.
*/
void
Context2d::SetPatternQuality(Local<String> prop, Local<Value> val, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
String::AsciiValue quality(val->ToString());
if (0 == strcmp("fast", *quality)) {
context->state->patternQuality = CAIRO_FILTER_FAST;
} else if (0 == strcmp("good", *quality)) {
context->state->patternQuality = CAIRO_FILTER_GOOD;
} else if (0 == strcmp("best", *quality)) {
context->state->patternQuality = CAIRO_FILTER_BEST;
}
}
/*
* Get pattern quality.
*/
Handle<Value>
Context2d::GetPatternQuality(Local<String> prop, const AccessorInfo &info) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
switch (context->state->patternQuality) {
case CAIRO_FILTER_FAST:
return String::New("fast");
case CAIRO_FILTER_BEST:
return String::New("best");
default:
return String::New("good");
}
}
/*
* Set global composite operation.
*/

3
src/CanvasRenderingContext2d.h

@ -22,6 +22,7 @@
typedef struct {
rgba_t fill;
rgba_t stroke;
cairo_filter_t patternQuality;
cairo_pattern_t *fillPattern;
cairo_pattern_t *strokePattern;
float globalAlpha;
@ -77,6 +78,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> Rect(const Arguments &args);
static Handle<Value> Arc(const Arguments &args);
static Handle<Value> ArcTo(const Arguments &args);
static Handle<Value> GetPatternQuality(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetGlobalCompositeOperation(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetGlobalAlpha(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetShadowColor(Local<String> prop, const AccessorInfo &info);
@ -90,6 +92,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> GetShadowOffsetY(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetShadowBlur(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetAntiAlias(Local<String> prop, const AccessorInfo &info);
static void SetPatternQuality(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetGlobalCompositeOperation(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetGlobalAlpha(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetShadowColor(Local<String> prop, Local<Value> val, const AccessorInfo &info);

Loading…
Cancel
Save