Browse Source

CanvasRenderingContext2d#filter

Like patternQuality, but applies to transformations effecting more than just
patternsi (i.e. the implicitly created pattern).

See
http://cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-set-filter
for more information.
v1.x
Seth Fitzsimmons 12 years ago
parent
commit
8dc36f09fa
  1. 10
      Readme.md
  2. 43
      src/CanvasRenderingContext2d.cc
  3. 2
      src/CanvasRenderingContext2d.h

10
Readme.md

@ -155,6 +155,16 @@ Defaults to _path_.
This property is tracked as part of the canvas state in save/restore.
### CanvasRenderingContext2d#filter
Like `patternQuality`, but applies to transformations effecting more than just patterns. Defaults to _good_.
- fast
- good
- best
- nearest
- bilinear
### Global Composite Operations
In addition to those specified and commonly implemented by browsers, the following have been added:

43
src/CanvasRenderingContext2d.cc

@ -141,6 +141,7 @@ Context2d::Initialize(Handle<Object> target) {
proto->SetAccessor(String::NewSymbol("shadowBlur"), GetShadowBlur, SetShadowBlur);
proto->SetAccessor(String::NewSymbol("antialias"), GetAntiAlias, SetAntiAlias);
proto->SetAccessor(String::NewSymbol("textDrawingMode"), GetTextDrawingMode, SetTextDrawingMode);
proto->SetAccessor(String::NewSymbol("filter"), GetFilter, SetFilter);
target->Set(String::NewSymbol("CanvasRenderingContext2d"), constructor->GetFunction());
}
@ -1015,6 +1016,48 @@ Context2d::SetTextDrawingMode(Local<String> prop, Local<Value> val, const Access
}
}
/*
* Get filter.
*/
Handle<Value>
Context2d::GetFilter(Local<String> prop, const AccessorInfo &info) {
HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
const char *filter;
switch (cairo_pattern_get_filter(cairo_get_source(context->context()))) {
case CAIRO_FILTER_FAST: filter = "fast"; break;
case CAIRO_FILTER_BEST: filter = "best"; break;
case CAIRO_FILTER_NEAREST: filter = "nearest"; break;
case CAIRO_FILTER_BILINEAR: filter = "bilinear"; break;
default: filter = "good";
}
return scope.Close(String::NewSymbol(filter));
}
/*
* Set filter.
*/
void
Context2d::SetFilter(Local<String> prop, Local<Value> val, const AccessorInfo &info) {
String::AsciiValue str(val->ToString());
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
cairo_filter_t filter;
if (0 == strcmp("fast", *str)) {
filter = CAIRO_FILTER_FAST;
} else if (0 == strcmp("best", *str)) {
filter = CAIRO_FILTER_BEST;
} else if (0 == strcmp("nearest", *str)) {
filter = CAIRO_FILTER_NEAREST;
} else if (0 == strcmp("bilinear", *str)) {
filter = CAIRO_FILTER_BILINEAR;
} else {
filter = CAIRO_FILTER_GOOD;
}
cairo_pattern_set_filter(cairo_get_source(context->context()), filter);
}
/*
* Get miter limit.
*/

2
src/CanvasRenderingContext2d.h

@ -126,6 +126,7 @@ class Context2d: public node::ObjectWrap {
static Handle<Value> GetShadowBlur(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetAntiAlias(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetTextDrawingMode(Local<String> prop, const AccessorInfo &info);
static Handle<Value> GetFilter(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);
@ -139,6 +140,7 @@ class Context2d: public node::ObjectWrap {
static void SetShadowBlur(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetAntiAlias(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetTextDrawingMode(Local<String> prop, Local<Value> val, const AccessorInfo &info);
static void SetFilter(Local<String> prop, Local<Value> val, const AccessorInfo &info);
inline void setContext(cairo_t *ctx) { _context = ctx; }
inline cairo_t *context(){ return _context; }
inline Canvas *canvas(){ return _canvas; }

Loading…
Cancel
Save