SVG path builder

master
谢桂纲 8 years ago
parent 0a08fb3487
commit 0afa7a9783

@ -1,9 +1,161 @@
namespace Canvas {
/**
* ``path``
* ``path``
*/
export class Path {
private pathStack: string[];
constructor() {
this.pathStack = [];
}
/**
* x,yM
* m"moveto"
* 线movetolineto
* movetopath
* 便
*
*/
public MoveTo(x: number, y: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`m ${x},${y}`);
} else {
this.pathStack.push(`M ${x},${y}`);
}
return this;
}
/**
* cpx,cpy线x,cpyHh
* x
* xcpy
*/
public HorizontalTo(x: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`h ${x}`);
} else {
this.pathStack.push(`H ${x}`);
}
return this;
}
/**
* cpxcpycpxy线V
* vy使
* ycpx,y.
*/
public VerticalTo(y: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`v ${y}`);
} else {
this.pathStack.push(`V ${y}`);
}
return this;
}
/**
* x,yL
* l
* 线
*
*/
public LineTo(x: number, y: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`l ${x} ${y}`);
} else {
this.pathStack.push(`L ${x} ${y}`);
}
return this;
}
/**
* 线x1y1xy
* 线x2y2
* 线C
* c
*
* xy
*/
public CurveTo(x1: number, y1: number, x2: number, y2: number, endX: number, endY: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`c ${x1} ${y1} ${x2} ${y2} ${endX} ${endY}`);
} else {
this.pathStack.push(`C ${x1} ${y1} ${x2} ${y2} ${endX} ${endY}`);
}
return this;
}
/**
* xy线
*
* C, c, S s
* x2y2
* 线S
* s
*
* 使xy
*/
public SmoothCurveTo(x2: number, y2: number, endX: number, endY: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`s ${x2} ${y2} ${endY} ${endY}`);
} else {
this.pathStack.push(`S ${x2} ${y2} ${endY} ${endY}`);
}
return this;
}
/**
* xyx1y1线
* Qq
* 线xy
*/
public QuadraticBelzier(x: number, y: number, endX: number, endY: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`q ${x} ${y} ${endX} ${endY}`);
} else {
this.pathStack.push(`Q ${x} ${y} ${endX} ${endY}`);
}
return this;
}
/**
* xy线线rxry
* 沿X
* cxcylarge-arc-flagsweep-flag
*/
public EllipticalArc(rX: number, rY: number, xrotation: number, flag1: number, flag2: number, x: number, y: number, relative: boolean = false): Path {
if (relative) {
this.pathStack.push(`a ${rX} ${rY} ${xrotation} ${flag1} ${flag2} ${x} ${y}`);
} else {
this.pathStack.push(`A ${rX} ${rY} ${xrotation} ${flag1} ${flag2} ${x} ${y}`);
}
return this;
}
/**
* ClosePath线
* 沿线
* ``Z````z``
*/
public ClosePath(): Path {
this.pathStack.push("Z");
return this;
}
d(): string {
return "";
return this.pathStack.join(" ");
}
}
}
Loading…
Cancel
Save