mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Simplify applyTransform() in SvgImport.
This commit is contained in:
parent
d280d65f82
commit
a677e905bf
2 changed files with 6 additions and 48 deletions
|
@ -508,41 +508,11 @@ new function() {
|
|||
* @param {Item} item a Paper.js item
|
||||
*/
|
||||
function applyTransform(item, svg, name) {
|
||||
var svgTransform = svg[name],
|
||||
transforms = svgTransform.baseVal,
|
||||
var transforms = svg[name].baseVal,
|
||||
matrix = new Matrix();
|
||||
for (var i = 0, l = transforms.numberOfItems; i < l; i++) {
|
||||
var transform = transforms.getItem(i);
|
||||
if (transform.type === /*#=*/ SVGTransform.SVG_TRANSFORM_UNKNOWN)
|
||||
continue;
|
||||
// Convert SVG Matrix to Paper Matrix.
|
||||
// TODO: Should this be moved to our Matrix constructor?
|
||||
var mx = transform.matrix,
|
||||
a = mx.a,
|
||||
b = mx.b,
|
||||
c = mx.c,
|
||||
d = mx.d;
|
||||
switch (transform.type) {
|
||||
// Compensate for SVG's theta rotation going the opposite direction
|
||||
case /*#=*/ SVGTransform.SVG_TRANSFORM_MATRIX:
|
||||
var tmp = b;
|
||||
b = c;
|
||||
c = tmp;
|
||||
break;
|
||||
case /*#=*/ SVGTransform.SVG_TRANSFORM_SKEWX:
|
||||
b = c;
|
||||
c = 0;
|
||||
break;
|
||||
case /*#=*/ SVGTransform.SVG_TRANSFORM_SKEWY:
|
||||
c = b;
|
||||
b = 0;
|
||||
break;
|
||||
case /*#=*/ SVGTransform.SVG_TRANSFORM_ROTATE:
|
||||
b = -b;
|
||||
c = -c;
|
||||
break;
|
||||
}
|
||||
matrix.concatenate(new Matrix(a, c, b, d, mx.e, mx.f));
|
||||
var mx = transforms.getItem(i).matrix;
|
||||
matrix.concatenate(new Matrix(mx.a, mx.b, mx.c, mx.d, mx.e, mx.f));
|
||||
}
|
||||
item.transform(matrix);
|
||||
}
|
||||
|
|
|
@ -15,13 +15,12 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* To shrink code, we automatically replace the long SVGPathSeg and SVGTransform
|
||||
* constants with their actual numeric values on preprocessing time, using
|
||||
* prepro statements.
|
||||
* To shrink code, we automatically replace the long SVGPathSeg constants with
|
||||
* their actual numeric values on preprocessing time, using prepro statements.
|
||||
* To do so, we need their values defined, which happens here.
|
||||
*/
|
||||
|
||||
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
||||
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
|
||||
var SVGPathSeg = {
|
||||
PATHSEG_UNKNOWN: 0,
|
||||
PATHSEG_CLOSEPATH: 1,
|
||||
|
@ -44,14 +43,3 @@ var SVGPathSeg = {
|
|||
PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: 18,
|
||||
PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: 19
|
||||
};
|
||||
|
||||
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGTransform.idl.html
|
||||
var SVGTransform = {
|
||||
SVG_TRANSFORM_UNKNOWN: 0,
|
||||
SVG_TRANSFORM_MATRIX: 1,
|
||||
SVG_TRANSFORM_TRANSLATE: 2,
|
||||
SVG_TRANSFORM_SCALE: 3,
|
||||
SVG_TRANSFORM_ROTATE: 4,
|
||||
SVG_TRANSFORM_SKEWX: 5,
|
||||
SVG_TRANSFORM_SKEWY: 6
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue