galaxy001 / canvas-text

Automatically exported from code.google.com/p/canvas-text
MIT License
0 stars 0 forks source link

canvas-text does not support context save and restore #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The three font properties (font, textAlign, textBaseline) should be included in 
save/restore operations on the canvas context. Assuming excanvas is already 
defined, a small change similar to the following will enable save/restore 
points to include font settings. Obviously, you could improve this for ordering 
robustness (this assume save and restore are already defined), but this is the 
basic idea.

  function copyFState(o1, o2) {
    o2.font = o1.font;
    o2.textAlign = o1.textAlign;
    o2.textBaseline = o1.textBaseline;
  }
  proto.save_am_ = proto.save;
  proto.save = function() {
    this.save_am_();
    var o = {},
      fStack = this.fStack_;
    copyFState(this, o);
    if (!fStack) {
      this.fStack_ = fStack = [];
    }
    fStack.push(o);
  }
  proto.restore_am_ = proto.restore;
  proto.restore = function() {
    copyFState(this.fStack_.pop(), this);
    this.restore_am_();
  }

Original issue reported on code.google.com by matt.cur...@predictix.com on 28 Mar 2011 at 10:27