Browse Source

Switch draw mode state to an enum.

v1.x
c-spencer 13 years ago
parent
commit
307fa29396
  1. 34
      src/CanvasRenderingContext2d.cc
  2. 7
      src/CanvasRenderingContext2d.h

34
src/CanvasRenderingContext2d.cc

@ -136,7 +136,7 @@ Context2d::Context2d(Canvas *canvas) {
state->stroke = transparent; state->stroke = transparent;
state->shadow = transparent_black; state->shadow = transparent_black;
state->patternQuality = CAIRO_FILTER_GOOD; state->patternQuality = CAIRO_FILTER_GOOD;
state->textDrawingPaths = true; state->textDrawingMode = TEXT_DRAW_PATHS;
} }
/* /*
@ -943,9 +943,9 @@ Context2d::GetTextDrawingMode(Local<String> prop, const AccessorInfo &info) {
HandleScope scope; HandleScope scope;
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
const char *mode; const char *mode;
if (context->state->textDrawingPaths) { if (context->state->textDrawingMode == TEXT_DRAW_PATHS) {
mode = "path"; mode = "path";
} else { } else if (context->state->textDrawingMode == TEXT_DRAW_GLYPHS) {
mode = "glyph"; mode = "glyph";
} }
return scope.Close(String::NewSymbol(mode)); return scope.Close(String::NewSymbol(mode));
@ -960,9 +960,9 @@ Context2d::SetTextDrawingMode(Local<String> prop, Local<Value> val, const Access
String::AsciiValue str(val->ToString()); String::AsciiValue str(val->ToString());
Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(info.This());
if (0 == strcmp("path", *str)) { if (0 == strcmp("path", *str)) {
context->state->textDrawingPaths = true; context->state->textDrawingMode = TEXT_DRAW_PATHS;
} else if (0 == strcmp("glyph", *str)) { } else if (0 == strcmp("glyph", *str)) {
context->state->textDrawingPaths = false; context->state->textDrawingMode = TEXT_DRAW_GLYPHS;
} }
} }
@ -1482,9 +1482,13 @@ Context2d::FillText(const Arguments &args) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
context->savePath(); context->savePath();
if (!context->state->textDrawingPaths) context->fill(); if (context->state->textDrawingMode == TEXT_DRAW_GLYPHS) {
context->setTextPath(*str, x, y); context->fill();
if (context->state->textDrawingPaths) context->fill(); context->setTextPath(*str, x, y);
} else if (context->state->textDrawingMode == TEXT_DRAW_PATHS) {
context->setTextPath(*str, x, y);
context->fill();
}
context->restorePath(); context->restorePath();
return Undefined(); return Undefined();
@ -1508,9 +1512,13 @@ Context2d::StrokeText(const Arguments &args) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
context->savePath(); context->savePath();
if (!context->state->textDrawingPaths) context->stroke(); if (context->state->textDrawingMode == TEXT_DRAW_GLYPHS) {
context->setTextPath(*str, x, y); context->stroke();
if (context->state->textDrawingPaths) context->stroke(); context->setTextPath(*str, x, y);
} else if (context->state->textDrawingMode == TEXT_DRAW_PATHS) {
context->setTextPath(*str, x, y);
context->stroke();
}
context->restorePath(); context->restorePath();
return Undefined(); return Undefined();
@ -1565,9 +1573,9 @@ Context2d::setTextPath(const char *str, double x, double y) {
} }
cairo_move_to(_context, x, y); cairo_move_to(_context, x, y);
if (state->textDrawingPaths) { if (state->textDrawingMode == TEXT_DRAW_PATHS) {
cairo_text_path(_context, str); cairo_text_path(_context, str);
} else { } else if (state->textDrawingMode == TEXT_DRAW_GLYPHS) {
cairo_show_text(_context, str); cairo_show_text(_context, str);
} }
} }

7
src/CanvasRenderingContext2d.h

@ -12,6 +12,11 @@
#include "Canvas.h" #include "Canvas.h"
#include "CanvasGradient.h" #include "CanvasGradient.h"
typedef enum {
TEXT_DRAW_PATHS,
TEXT_DRAW_GLYPHS
} canvas_draw_mode_t;
/* /*
* State struct. * State struct.
* *
@ -34,7 +39,7 @@ typedef struct {
int shadowBlur; int shadowBlur;
double shadowOffsetX; double shadowOffsetX;
double shadowOffsetY; double shadowOffsetY;
bool textDrawingPaths; canvas_draw_mode_t textDrawingMode;
} canvas_state_t; } canvas_state_t;
class Context2d: public node::ObjectWrap { class Context2d: public node::ObjectWrap {

Loading…
Cancel
Save