From 8dc36f09fa7b638249c462400324a6b811985e21 Mon Sep 17 00:00:00 2001 From: Seth Fitzsimmons Date: Mon, 29 Apr 2013 08:47:51 -0700 Subject: [PATCH] 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. --- Readme.md | 10 ++++++++ src/CanvasRenderingContext2d.cc | 43 +++++++++++++++++++++++++++++++++ src/CanvasRenderingContext2d.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/Readme.md b/Readme.md index a53e4d2..90e4841 100644 --- a/Readme.md +++ b/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: diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index d427dac..93bfdc1 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -141,6 +141,7 @@ Context2d::Initialize(Handle 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 prop, Local val, const Access } } +/* + * Get filter. + */ + +Handle +Context2d::GetFilter(Local prop, const AccessorInfo &info) { + HandleScope scope; + Context2d *context = ObjectWrap::Unwrap(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 prop, Local val, const AccessorInfo &info) { + String::AsciiValue str(val->ToString()); + Context2d *context = ObjectWrap::Unwrap(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. */ diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index a5136ce..f280cfe 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -126,6 +126,7 @@ class Context2d: public node::ObjectWrap { static Handle GetShadowBlur(Local prop, const AccessorInfo &info); static Handle GetAntiAlias(Local prop, const AccessorInfo &info); static Handle GetTextDrawingMode(Local prop, const AccessorInfo &info); + static Handle GetFilter(Local prop, const AccessorInfo &info); static void SetPatternQuality(Local prop, Local val, const AccessorInfo &info); static void SetGlobalCompositeOperation(Local prop, Local val, const AccessorInfo &info); static void SetGlobalAlpha(Local prop, Local val, const AccessorInfo &info); @@ -139,6 +140,7 @@ class Context2d: public node::ObjectWrap { static void SetShadowBlur(Local prop, Local val, const AccessorInfo &info); static void SetAntiAlias(Local prop, Local val, const AccessorInfo &info); static void SetTextDrawingMode(Local prop, Local val, const AccessorInfo &info); + static void SetFilter(Local prop, Local val, const AccessorInfo &info); inline void setContext(cairo_t *ctx) { _context = ctx; } inline cairo_t *context(){ return _context; } inline Canvas *canvas(){ return _canvas; }