mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Simplify compound path support in SvgImporter a little.
This commit is contained in:
parent
07c0b6ce6a
commit
420e62e1dc
1 changed files with 12 additions and 14 deletions
|
@ -119,10 +119,9 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
path: function(svg) {
|
path: function(svg) {
|
||||||
var compoundPath,
|
var path = new Path(),
|
||||||
path = new Path(),
|
|
||||||
list = svg.pathSegList,
|
list = svg.pathSegList,
|
||||||
segments = path.getSegments();
|
compoundPath;
|
||||||
for (var i = 0, l = list.numberOfItems; i < l; i++) {
|
for (var i = 0, l = list.numberOfItems; i < l; i++) {
|
||||||
// To shrink code, we replaced the long SVGPathSeg constants
|
// To shrink code, we replaced the long SVGPathSeg constants
|
||||||
// with their actual numeric values. The comments keep reference
|
// with their actual numeric values. The comments keep reference
|
||||||
|
@ -131,7 +130,7 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
var segment = list.getItem(i);
|
var segment = list.getItem(i);
|
||||||
if (segment.pathSegType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
|
if (segment.pathSegType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
|
||||||
continue;
|
continue;
|
||||||
var relative = segment.pathSegType % 2 == 1 && segments.length
|
var relative = segment.pathSegType % 2 == 1 && !path.isEmpty()
|
||||||
? path.getLastSegment().getPoint()
|
? path.getLastSegment().getPoint()
|
||||||
: Point.create(0, 0);
|
: Point.create(0, 0);
|
||||||
var point = Point.create(segment.x, segment.y).add(relative);
|
var point = Point.create(segment.x, segment.y).add(relative);
|
||||||
|
@ -141,15 +140,14 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
break;
|
break;
|
||||||
case 2: // SVGPathSeg.PATHSEG_MOVETO_ABS:
|
case 2: // SVGPathSeg.PATHSEG_MOVETO_ABS:
|
||||||
case 3: // SVGPathSeg.PATHSEG_MOVETO_REL:
|
case 3: // SVGPathSeg.PATHSEG_MOVETO_REL:
|
||||||
if (path.segments.length || path.getParent() instanceof CompoundPath) {
|
if (!path.isEmpty() && !compoundPath) {
|
||||||
if (!compoundPath)
|
compoundPath = new CompoundPath([path]);
|
||||||
compoundPath = new CompoundPath([path]);
|
|
||||||
path = new Path([point]);
|
|
||||||
compoundPath.addChild(path);
|
|
||||||
segments = path.getSegments();
|
|
||||||
} else {
|
|
||||||
path.moveTo(point);
|
|
||||||
}
|
}
|
||||||
|
if (compoundPath) {
|
||||||
|
path = new Path();
|
||||||
|
compoundPath.addChild(path);
|
||||||
|
}
|
||||||
|
path.moveTo(point);
|
||||||
break;
|
break;
|
||||||
case 4: // SVGPathSeg.PATHSEG_LINETO_ABS:
|
case 4: // SVGPathSeg.PATHSEG_LINETO_ABS:
|
||||||
case 5: // SVGPathSeg.PATHSEG_LINETO_REL:
|
case 5: // SVGPathSeg.PATHSEG_LINETO_REL:
|
||||||
|
@ -201,12 +199,12 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
prev.pathSegType === 9) { // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL
|
prev.pathSegType === 9) { // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL
|
||||||
control = Point.create(prev.x1, prev.y1)
|
control = Point.create(prev.x1, prev.y1)
|
||||||
.subtract(prev.x, prev.y)
|
.subtract(prev.x, prev.y)
|
||||||
.add(segments[j].getPoint());
|
.add(path._segments[j].getPoint());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; j < i; ++j) {
|
for (; j < i; ++j) {
|
||||||
var anchor = segments[j].getPoint();
|
var anchor = path._segments[j].getPoint();
|
||||||
control = anchor.add(anchor.subtract(control));
|
control = anchor.add(anchor.subtract(control));
|
||||||
}
|
}
|
||||||
path.quadraticCurveTo(control, point);
|
path.quadraticCurveTo(control, point);
|
||||||
|
|
Loading…
Reference in a new issue