Giter Club home page Giter Club logo

Comments (7)

gwwar avatar gwwar commented on September 16, 2024

Looks like width and height was not defined when you created a new C2S. If you open up dev tools on jsFiddle they'll show you the js errors. http://jsfiddle.net/5bbn59rs/5/

from canvas2svg.

cfsghost avatar cfsghost commented on September 16, 2024

any update for this issue?

from canvas2svg.

barberousse avatar barberousse commented on September 16, 2024

Am also getting this error with constructor call new Context({ document, width: 1920, height: 1080 })

from canvas2svg.

barberousse avatar barberousse commented on September 16, 2024

So, in my case the problem is with Line 383:

if ((style.svgAttr === "stroke" || style.svgAttr === "fill") && value.indexOf && value.indexOf("rgba") !== -1)

It appears that the logic doesn't expect to have to handle a CanvasGradient object as a value of fill, which is rather standard. This line should check that it's not dealing with a string first by testing for indexOf existence first.

from canvas2svg.

mudcube avatar mudcube commented on September 16, 2024

It's expecting a C2S CanvasGradient not a HTMLCanvasElement CanvasGradient. If you create your gradient using ctx.createLinearGradient or ctx.createRadialGradient method on the C2S instance you should not run into the issue.

from canvas2svg.

kasual1 avatar kasual1 commented on September 16, 2024

I ran into the same problem as @barberousse
Adding the following code to the already existing else-if clauses seems to fix this issue:

// other if statements...

// Add this before the last else-if clause
else if(style.apply.indexOf("stroke") !==-1 && value instanceof CanvasGradient) {
  this.__currentElement.setAttribute("stroke", format("url(#{id})", {id:value.__root.getAttribute("id")}));
}

// Last else-if clause
else if ((style.svgAttr === "stroke" || style.svgAttr === "fill") && value.indexOf("rgba") !== -1){
 // ...
}

Can someone confirm, that I'm on the right track?

from canvas2svg.

cmdcolin avatar cmdcolin commented on September 16, 2024

unrelated to original issue perhaps, but I ran into this same error message when I was passing an object to the fillStyle (object was a Color object from https://www.npmjs.com/package/color)

the HTML5 canvas API presumably stringifies this Color object automatically, but it caused a crash in canvas2svg (solution: just stringify manually before setting ctx.fillStyle)

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.