Git Product home page Git Product logo

svg2canvas's Introduction

Svg2canvas

Transform svg code to canvas path ##规则 svg里的路径一般形如 <path fill="#FFFFFF" d="M152.3,19.9c0-1.6,1.3-2.8,2.8-2.8s2.8,1.3,2.8,2.8S152.3,21.4,152.3,19.9z"/>

fill表示填充的颜色
d表示路径(path data)是一些字母和数字还有逗号减号的组合
例子中的d可以分为以下几个串
M(152.3,19.9)
c(0,-1.6,1.3,-2.8)
s(2.8,1.3,2.8,2.8)
S(152.3,21.4,152.3,19.9)
z()
注意当参数为负数的时候,前面的逗号会省略。

命令 名称 参数
M moveto  移动到 (x y)+
Z closepath  关闭路径 (none)
L lineto  画线到 (x y)+
H horizontal lineto  水平线到 x+
V vertical lineto  垂直线到 y+
C curveto  三次贝塞尔曲线到 (x1 y1 x2 y2 x y)+
S smooth curveto  光滑三次贝塞尔曲线到 (x2 y2 x y)+
Q quadratic Bézier curveto  二次贝塞尔曲线到 (x1 y1 x y)+
T smooth quadratic Bézier curveto  光滑二次贝塞尔曲线到 (x y)+
A elliptical arc  椭圆弧 (rx ry x-axis-rotation large-arc-flag sweep-flag x y)+
R Catmull-Rom curveto*  Catmull-Rom曲线 x1 y1 (x y)+
参考:深度掌握SVG路径path的贝塞尔曲线指令 By 张鑫旭
参考:超级权威的文档 By W3C

命令有大写和小写两种区分,大写表示绝对定位,小写表示相对于当前的坐标点定位。
这些命令都可以对应到canvas的方法:
M==moveTo(x,y)
Z==
L==lineTo(x,y)
H==lineTo(newX,oldY)
V==lineTo(oldX,newY)
C==bezierCurveTo(x1,y1,x2,y2,x,y)
S==bezierCurveTo(通过计算得到的x1,通过极端得到的y1,x2,y2,x,y)
Q==quadraticCurveTo(x1,y1,x,y)
T=quadraticCurveTo(通过计算得到的x1,通过极端得到的y1,x,y)
##待完善

  • 非path情况,如圆形,方形等
  • 动画
  • 每条path的颜色只能是纯色
  • path中的 Q T R A
  • 其他

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.