mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Replace SVGTransform constants with their numeric values as well.
This commit is contained in:
parent
9fbe1260b2
commit
81f8c32d7b
1 changed files with 34 additions and 30 deletions
|
@ -127,8 +127,12 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
segments = path.getSegments(),
|
segments = path.getSegments(),
|
||||||
relative;
|
relative;
|
||||||
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
|
||||||
|
// with their actual numeric values. The comments keep reference
|
||||||
|
// to the original constants. Values were taken from:
|
||||||
|
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
||||||
var segment = list.getItem(i);
|
var segment = list.getItem(i);
|
||||||
if (segment.pathSegType === 0) // PATHSEG_UNKNOWN
|
if (segment.pathSegType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
|
||||||
continue;
|
continue;
|
||||||
if (segment.pathSegType % 2 == 1 && segments.length > 0) {
|
if (segment.pathSegType % 2 == 1 && segments.length > 0) {
|
||||||
relative = path.getLastSegment().getPoint();
|
relative = path.getLastSegment().getPoint();
|
||||||
|
@ -136,47 +140,43 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
relative = Point.create(0, 0);
|
relative = Point.create(0, 0);
|
||||||
}
|
}
|
||||||
var segmentTo = Point.create(segment.x, segment.y).add(relative);
|
var segmentTo = Point.create(segment.x, segment.y).add(relative);
|
||||||
// To shrink code, we replaced the long SVGPathSeg constants
|
|
||||||
// with their actual numeric values. The comments keep reference
|
|
||||||
// to the original constants. Values were taken from:
|
|
||||||
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
|
||||||
switch (segment.pathSegType) {
|
switch (segment.pathSegType) {
|
||||||
case 1: // PATHSEG_CLOSEPATH:
|
case 1: // SVGPathSeg.PATHSEG_CLOSEPATH:
|
||||||
path.closePath();
|
path.closePath();
|
||||||
break;
|
break;
|
||||||
case 2: // PATHSEG_MOVETO_ABS:
|
case 2: // SVGPathSeg.PATHSEG_MOVETO_ABS:
|
||||||
case 3: // PATHSEG_MOVETO_REL:
|
case 3: // SVGPathSeg.PATHSEG_MOVETO_REL:
|
||||||
path.moveTo(segmentTo);
|
path.moveTo(segmentTo);
|
||||||
break;
|
break;
|
||||||
case 4: // PATHSEG_LINETO_ABS:
|
case 4: // SVGPathSeg.PATHSEG_LINETO_ABS:
|
||||||
case 5: // PATHSEG_LINETO_REL:
|
case 5: // SVGPathSeg.PATHSEG_LINETO_REL:
|
||||||
case 12: // PATHSEG_LINETO_HORIZONTAL_ABS:
|
case 12: // SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
|
||||||
case 13: // PATHSEG_LINETO_HORIZONTAL_REL:
|
case 13: // SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
|
||||||
case 14: // PATHSEG_LINETO_VERTICAL_ABS:
|
case 14: // SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
|
||||||
case 15: // PATHSEG_LINETO_VERTICAL_REL:
|
case 15: // PATHSEG_LINETO_VERTICAL_REL:
|
||||||
path.lineTo(segmentTo);
|
path.lineTo(segmentTo);
|
||||||
break;
|
break;
|
||||||
case 6: // PATHSEG_CURVETO_CUBIC_ABS:
|
case 6: // SVGPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
|
||||||
case 7: // PATHSEG_CURVETO_CUBIC_REL:
|
case 7: // SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL:
|
||||||
path.cubicCurveTo(
|
path.cubicCurveTo(
|
||||||
relative.add(segment.x1, segment.y1),
|
relative.add(segment.x1, segment.y1),
|
||||||
relative.add(segment.x2, segment.y2),
|
relative.add(segment.x2, segment.y2),
|
||||||
segmentTo
|
segmentTo
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 8: // PATHSEG_CURVETO_QUADRATIC_ABS:
|
case 8: // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
|
||||||
case 9: // PATHSEG_CURVETO_QUADRATIC_REL:
|
case 9: // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
|
||||||
path.quadraticCurveTo(
|
path.quadraticCurveTo(
|
||||||
relative.add(segment.x1, segment.y1),
|
relative.add(segment.x1, segment.y1),
|
||||||
segmentTo
|
segmentTo
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
// TODO: Implement Arcs: ttp://www.w3.org/TR/SVG/implnote.html
|
// TODO: Implement Arcs: ttp://www.w3.org/TR/SVG/implnote.html
|
||||||
// case 10: // PATHSEG_ARC_ABS:
|
// case 10: // SVGPathSeg.PATHSEG_ARC_ABS:
|
||||||
// case 11: // PATHSEG_ARC_REL:
|
// case 11: // SVGPathSeg.PATHSEG_ARC_REL:
|
||||||
// break;
|
// break;
|
||||||
case 16: // PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
|
case 16: // SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
|
||||||
case 17: // PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
|
case 17: // SVGPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
|
||||||
var prev = list.getItem(i - 1),
|
var prev = list.getItem(i - 1),
|
||||||
last = path.getLastSegment().getPoint(),
|
last = path.getLastSegment().getPoint(),
|
||||||
control = last.add(last.subtract(
|
control = last.add(last.subtract(
|
||||||
|
@ -188,14 +188,14 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
relative.add(segment.x2, segment.y2),
|
relative.add(segment.x2, segment.y2),
|
||||||
segmentTo);
|
segmentTo);
|
||||||
break;
|
break;
|
||||||
case 18: // PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
|
case 18: // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
|
||||||
case 19: // PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
|
case 19: // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
|
||||||
var control,
|
var control,
|
||||||
j = i;
|
j = i;
|
||||||
for (; j >= 0; j--) {
|
for (; j >= 0; j--) {
|
||||||
var prev = list.getItem(j);
|
var prev = list.getItem(j);
|
||||||
if (prev.pathSegType === 8 || // PATHSEG_CURVETO_QUADRATIC_ABS
|
if (prev.pathSegType === 8 || // SVGPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS
|
||||||
prev.pathSegType === 9) { // 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(segments[j].getPoint());
|
||||||
|
@ -327,8 +327,12 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
var transforms = svg.transform.baseVal,
|
var transforms = svg.transform.baseVal,
|
||||||
matrix = new Matrix();
|
matrix = new Matrix();
|
||||||
for (var i = 0, l = transforms.numberOfItems; i < l; i++) {
|
for (var i = 0, l = transforms.numberOfItems; i < l; i++) {
|
||||||
|
// To shrink code, we replaced the long SVGTransform constants
|
||||||
|
// with their actual numeric values. The comments keep reference
|
||||||
|
// to the original constants. Values were taken from:
|
||||||
|
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGTransform.idl.html
|
||||||
var transform = transforms.getItem(i);
|
var transform = transforms.getItem(i);
|
||||||
if (transform.type === SVGTransform.SVG_TRANSFORM_UNKNOWN)
|
if (transform.type === 0) // SVGTransform.SVG_TRANSFORM_UNKNOWN
|
||||||
continue;
|
continue;
|
||||||
// Convert SVG Matrix to Paper Matrix.
|
// Convert SVG Matrix to Paper Matrix.
|
||||||
// TODO: Should this be moved to our Matrix constructor?
|
// TODO: Should this be moved to our Matrix constructor?
|
||||||
|
@ -339,20 +343,20 @@ var SvgImporter = this.SvgImporter = new function() {
|
||||||
d = mx.d;
|
d = mx.d;
|
||||||
switch (transform.type) {
|
switch (transform.type) {
|
||||||
// Compensate for SVG's theta rotation going the opposite direction
|
// Compensate for SVG's theta rotation going the opposite direction
|
||||||
case SVGTransform.SVG_TRANSFORM_MATRIX:
|
case 1: // SVGTransform.SVG_TRANSFORM_MATRIX
|
||||||
var tmp = b;
|
var tmp = b;
|
||||||
b = c;
|
b = c;
|
||||||
c = tmp;
|
c = tmp;
|
||||||
break;
|
break;
|
||||||
case SVGTransform.SVG_TRANSFORM_SKEWX:
|
case 5: // SVGTransform.SVG_TRANSFORM_SKEWX:
|
||||||
b = c;
|
b = c;
|
||||||
c = 0;
|
c = 0;
|
||||||
break;
|
break;
|
||||||
case SVGTransform.SVG_TRANSFORM_SKEWY:
|
case 6: // SVGTransform.SVG_TRANSFORM_SKEWY:
|
||||||
c = b;
|
c = b;
|
||||||
b = 0;
|
b = 0;
|
||||||
break;
|
break;
|
||||||
case SVGTransform.SVG_TRANSFORM_ROTATE:
|
case 4: // SVGTransform.SVG_TRANSFORM_ROTATE:
|
||||||
b = -b;
|
b = -b;
|
||||||
c = -c;
|
c = -c;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue