Browse Source

Added Context2d::{save,restore}Path()

v1.x
Tj Holowaychuk 14 years ago
parent
commit
cd4d5da7c2
  1. 24
      src/CanvasRenderingContext2d.cc
  2. 3
      src/CanvasRenderingContext2d.h

24
src/CanvasRenderingContext2d.cc

@ -822,23 +822,29 @@ Context2d::StrokeText(const Arguments &args) {
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->getContext(); 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); context->setTextPath(*str, x, y);
SET_SOURCE(context->state->stroke); SET_SOURCE(context->state->stroke);
cairo_stroke(ctx); cairo_stroke(ctx);
context->restorePath();
// Restore path
cairo_restore(ctx);
cairo_append_path(ctx, path);
return Undefined(); 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 void
Context2d::setTextPath(const char *str, double x, double y) { Context2d::setTextPath(const char *str, double x, double y) {
// Text extents // Text extents

3
src/CanvasRenderingContext2d.h

@ -101,6 +101,8 @@ class Context2d: public node::ObjectWrap {
inline cairo_t *getContext(){ return _context; } inline cairo_t *getContext(){ return _context; }
inline Canvas *getCanvas(){ return _canvas; } inline Canvas *getCanvas(){ return _canvas; }
void setTextPath(const char *str, double x, double y); void setTextPath(const char *str, double x, double y);
void savePath();
void restorePath();
void saveState(); void saveState();
void restoreState(); void restoreState();
@ -111,6 +113,7 @@ class Context2d: public node::ObjectWrap {
~Context2d(); ~Context2d();
Canvas *_canvas; Canvas *_canvas;
cairo_t *_context; cairo_t *_context;
cairo_path_t *_path;
}; };
#endif #endif
Loading…
Cancel
Save