diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 6849172..9dacd7c 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -822,23 +822,29 @@ Context2d::StrokeText(const Arguments &args) { Context2d *context = ObjectWrap::Unwrap(args.This()); cairo_t *ctx = context->getContext(); - // Save path - cairo_save(ctx); - cairo_path_t *path = cairo_copy_path_flat(ctx); - cairo_new_path(ctx); - // Text path + context->savePath(); context->setTextPath(*str, x, y); SET_SOURCE(context->state->stroke); cairo_stroke(ctx); - - // Restore path - cairo_restore(ctx); - cairo_append_path(ctx, path); + context->restorePath(); return Undefined(); } +void +Context2d::savePath() { + cairo_save(_context); + _path = cairo_copy_path_flat(_context); + cairo_new_path(_context); +} + +void +Context2d::restorePath() { + cairo_restore(_context); + cairo_append_path(_context, _path); +} + void Context2d::setTextPath(const char *str, double x, double y) { // Text extents diff --git a/src/CanvasRenderingContext2d.h b/src/CanvasRenderingContext2d.h index 8c7fea7..aa2642b 100644 --- a/src/CanvasRenderingContext2d.h +++ b/src/CanvasRenderingContext2d.h @@ -101,6 +101,8 @@ class Context2d: public node::ObjectWrap { inline cairo_t *getContext(){ return _context; } inline Canvas *getCanvas(){ return _canvas; } void setTextPath(const char *str, double x, double y); + void savePath(); + void restorePath(); void saveState(); void restoreState(); @@ -111,6 +113,7 @@ class Context2d: public node::ObjectWrap { ~Context2d(); Canvas *_canvas; cairo_t *_context; + cairo_path_t *_path; }; #endif \ No newline at end of file