Giter VIP home page Giter VIP logo

Comments (3)

jiayihu avatar jiayihu commented on May 14, 2024 1

For whoever is interested, this is a quick hotfix for the for ctx.save() issue with Paths:

const save = Context.prototype.save;
Context.prototype.save = function () {
  /**
   * @PATCH Keep the path as `__currentElement` so that `ctx.fill()` triggering `__applyCurrentDefaultPath`
   * won't error
   */
  if (this.__currentElement.nodeName === "path") {
    !this.prevented && (this.prevented = 0);
    this.prevented += 1;
    return;
  }

  save.call(this)
};

const restore = Context.prototype.restore;
Context.prototype.restore = function () {
  /** @PATCH Check if this `ctx.restore()` was prevented */
  if (this.__currentElement.nodeName === "path" && this.prevented) {
    this.prevented -= 1;
    return;
  }

  restore.call(this)
};

from canvas2svg.

mudcube avatar mudcube commented on May 14, 2024

Made some headway on this:
mudcube@c7df7fa

from canvas2svg.

Zamiell avatar Zamiell commented on May 14, 2024

I'm still getting the dreaded "Attempted to apply path command to node g" error, even on the latest version on master.

Apparently, the error occurs whenever you perform a ctx.save() immediately before a ctx.fill().
e.g.

const { document } = (new JSDOM('')).window;
const ctx = new C2S({
    document,
    width: 500,
    height: 500,
});
ctx.beginPath();
ctx.rect(20, 20, 150, 100);
ctx.fillStyle = "red";
ctx.save();
ctx.fill();

It will error out on the fill.
Also note that it isn't a node issue, because I get the exact same error when trying in a browser.
Does anyone have any ideas or workarounds?

from canvas2svg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.