未验证 提交 6876ac48 编写于 作者: P Preet 提交者: GitHub

Merge pull request #52 from pshihn/pathGen

added path-gen to generators
......@@ -1524,6 +1524,99 @@ class RoughGenerator {
return this._drawable('path', paths, o);
}
toPaths(drawable) {
const sets = drawable.sets || [];
const o = drawable.options || this.defaultOptions;
const paths = [];
for (const drawing of sets) {
let path = null;
switch (drawing.type) {
case 'path':
path = {
d: this.opsToPath(drawing),
stroke: o.stroke,
strokeWidth: o.strokeWidth,
fill: 'none'
};
break;
case 'fillPath':
path = {
d: this.opsToPath(drawing),
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'fillSketch':
path = this._fillSketch(drawing, o);
break;
case 'path2Dfill':
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'path2Dpattern': {
const size = drawing.size;
const pattern = {
x: 0, y: 0, width: 1, height: 1,
viewBox: `0 0 ${Math.round(size[0])} ${Math.round(size[1])}`,
patternUnits: 'objectBoundingBox',
path: this._fillSketch(drawing, o)
};
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
pattern: pattern
};
break;
}
}
if (path) {
paths.push(path);
}
}
return paths;
}
_fillSketch(drawing, o) {
let fweight = o.fillWeight;
if (fweight < 0) {
fweight = o.strokeWidth / 2;
}
return {
d: this.opsToPath(drawing),
stroke: o.fill,
strokeWidth: fweight,
fill: 'none'
};
}
opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
}
_computePathSize(d) {
let size = [0, 0];
if (self.document) {
......@@ -2083,25 +2176,7 @@ class RoughSVG {
}
_opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
return this.gen.opsToPath(drawing);
}
}
......
此差异已折叠。
......@@ -1527,6 +1527,99 @@ class RoughGenerator {
return this._drawable('path', paths, o);
}
toPaths(drawable) {
const sets = drawable.sets || [];
const o = drawable.options || this.defaultOptions;
const paths = [];
for (const drawing of sets) {
let path = null;
switch (drawing.type) {
case 'path':
path = {
d: this.opsToPath(drawing),
stroke: o.stroke,
strokeWidth: o.strokeWidth,
fill: 'none'
};
break;
case 'fillPath':
path = {
d: this.opsToPath(drawing),
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'fillSketch':
path = this._fillSketch(drawing, o);
break;
case 'path2Dfill':
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'path2Dpattern': {
const size = drawing.size;
const pattern = {
x: 0, y: 0, width: 1, height: 1,
viewBox: `0 0 ${Math.round(size[0])} ${Math.round(size[1])}`,
patternUnits: 'objectBoundingBox',
path: this._fillSketch(drawing, o)
};
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
pattern: pattern
};
break;
}
}
if (path) {
paths.push(path);
}
}
return paths;
}
_fillSketch(drawing, o) {
let fweight = o.fillWeight;
if (fweight < 0) {
fweight = o.strokeWidth / 2;
}
return {
d: this.opsToPath(drawing),
stroke: o.fill,
strokeWidth: fweight,
fill: 'none'
};
}
opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
}
_computePathSize(d) {
let size = [0, 0];
if (self.document) {
......@@ -2086,25 +2179,7 @@ class RoughSVG {
}
_opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
return this.gen.opsToPath(drawing);
}
}
......
此差异已折叠。
{
"name": "roughjs",
"version": "2.1.0",
"version": "2.1.1",
"description": "Create graphics using HTML Canvas or SVG with a hand-drawn, sketchy, appearance.",
"main": "dist/rough.umd.js",
"jsnext:main": "src/index.js",
......
......@@ -165,6 +165,99 @@ export class RoughGenerator {
return this._drawable('path', paths, o);
}
toPaths(drawable) {
const sets = drawable.sets || [];
const o = drawable.options || this.defaultOptions;
const paths = [];
for (const drawing of sets) {
let path = null;
switch (drawing.type) {
case 'path':
path = {
d: this.opsToPath(drawing),
stroke: o.stroke,
strokeWidth: o.strokeWidth,
fill: 'none'
};
break;
case 'fillPath':
path = {
d: this.opsToPath(drawing),
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'fillSketch':
path = this._fillSketch(drawing, o);
break;
case 'path2Dfill':
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
fill: o.fill
};
break;
case 'path2Dpattern': {
const size = drawing.size;
const pattern = {
x: 0, y: 0, width: 1, height: 1,
viewBox: `0 0 ${Math.round(size[0])} ${Math.round(size[1])}`,
patternUnits: 'objectBoundingBox',
path: this._fillSketch(drawing, o)
};
path = {
d: drawing.path,
stroke: 'none',
strokeWidth: 0,
pattern: pattern
};
break;
}
}
if (path) {
paths.push(path);
}
}
return paths;
}
_fillSketch(drawing, o) {
let fweight = o.fillWeight;
if (fweight < 0) {
fweight = o.strokeWidth / 2;
}
return {
d: this.opsToPath(drawing),
stroke: o.fill,
strokeWidth: fweight,
fill: 'none'
};
}
opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
}
_computePathSize(d) {
let size = [0, 0];
if (self.document) {
......
......@@ -154,25 +154,7 @@ export class RoughSVG {
}
_opsToPath(drawing) {
let path = '';
for (let item of drawing.ops) {
const data = item.data;
switch (item.op) {
case 'move':
path += `M${data[0]} ${data[1]} `;
break;
case 'bcurveTo':
path += `C${data[0]} ${data[1]}, ${data[2]} ${data[3]}, ${data[4]} ${data[5]} `;
break;
case 'qcurveTo':
path += `Q${data[0]} ${data[1]}, ${data[2]} ${data[3]} `;
break;
case 'lineTo':
path += `L${data[0]} ${data[1]} `;
break;
}
}
return path.trim();
return this.gen.opsToPath(drawing);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册