mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
parent
d63647eb06
commit
c82e5d41f7
3 changed files with 63 additions and 36 deletions
|
@ -185,15 +185,14 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
||||||
* Attempts to apply the matrix to the content of item that it belongs to,
|
* Attempts to apply the matrix to the content of item that it belongs to,
|
||||||
* meaning its transformation is baked into the item's content or children.
|
* meaning its transformation is baked into the item's content or children.
|
||||||
*
|
*
|
||||||
* @param {Boolean} [recursively=true] controls whether to apply transformations
|
* @param {Boolean} [recursively=true] controls whether to apply
|
||||||
* recursively on children
|
* transformations recursively on children
|
||||||
* @return {Boolean} {@true if the matrix was applied}
|
* @return {Boolean} {@true if the matrix was applied}
|
||||||
*/
|
*/
|
||||||
apply: function(recursively, _setApplyMatrix) {
|
apply: function(recursively, _setApplyMatrix) {
|
||||||
var owner = this._owner;
|
var owner = this._owner;
|
||||||
if (owner) {
|
if (owner) {
|
||||||
owner.transform(null, true, Base.pick(recursively, true),
|
owner.transform(null, Base.pick(recursively, true), _setApplyMatrix);
|
||||||
_setApplyMatrix);
|
|
||||||
// If the matrix was successfully applied, it will be reset now.
|
// If the matrix was successfully applied, it will be reset now.
|
||||||
return this.isIdentity();
|
return this.isIdentity();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3509,19 +3509,22 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
// @param {String[]} flags array of any of the following: 'objects',
|
// @param {String[]} flags array of any of the following: 'objects',
|
||||||
// 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns',
|
// 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns',
|
||||||
// 'lines'. Default: ['objects', 'children']
|
// 'lines'. Default: ['objects', 'children']
|
||||||
transform: function(matrix, _applyMatrix, _applyRecursively,
|
transform: function(matrix, _applyRecursively, _setApplyMatrix) {
|
||||||
_setApplyMatrix) {
|
|
||||||
var _matrix = this._matrix,
|
var _matrix = this._matrix,
|
||||||
// If no matrix is provided, or the matrix is the identity, we might
|
|
||||||
// still have some work to do in case _applyMatrix is true
|
|
||||||
transformMatrix = matrix && !matrix.isIdentity(),
|
transformMatrix = matrix && !matrix.isIdentity(),
|
||||||
applyMatrix = (_applyMatrix || this._applyMatrix)
|
// If no matrix is provided, or the matrix is the identity, we might
|
||||||
|
// still have some work to do: _setApplyMatrix or _applyRecursively.
|
||||||
|
applyMatrix = (
|
||||||
|
_setApplyMatrix && this._canApplyMatrix ||
|
||||||
|
this._applyMatrix && (
|
||||||
// Don't apply _matrix if the result of concatenating with
|
// Don't apply _matrix if the result of concatenating with
|
||||||
// matrix would be identity.
|
// matrix would be identity.
|
||||||
&& ((!_matrix.isIdentity() || transformMatrix)
|
transformMatrix || !_matrix.isIdentity() ||
|
||||||
// Even if it's an identity matrix, we still need to
|
// Even if it's an identity matrix, we may still need to
|
||||||
// recursively apply the matrix to children.
|
// recursively apply the matrix to children.
|
||||||
|| _applyMatrix && _applyRecursively && this._children);
|
_applyRecursively && this._children
|
||||||
|
)
|
||||||
|
);
|
||||||
// Bail out if there is nothing to do.
|
// Bail out if there is nothing to do.
|
||||||
if (!transformMatrix && !applyMatrix)
|
if (!transformMatrix && !applyMatrix)
|
||||||
return this;
|
return this;
|
||||||
|
@ -3549,16 +3552,13 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
if (strokeColor)
|
if (strokeColor)
|
||||||
strokeColor.transform(matrix);
|
strokeColor.transform(matrix);
|
||||||
}
|
}
|
||||||
if (applyMatrix) {
|
|
||||||
// Set the internal _applyMatrix flag to true if we're told to do so.
|
|
||||||
if (_setApplyMatrix && this._canApplyMatrix)
|
|
||||||
this._applyMatrix = true;
|
|
||||||
// Call #_transformContent() now, if we need to directly apply the
|
// Call #_transformContent() now, if we need to directly apply the
|
||||||
// internal _matrix transformations to the item's content.
|
// internal _matrix transformations to the item's content.
|
||||||
// Application is not possible on Raster, PointText, SymbolItem, since
|
// Application is not possible on Raster, PointText, SymbolItem, since
|
||||||
// the matrix is where the actual transformation state is stored.
|
// the matrix is where the actual transformation state is stored.
|
||||||
if (this._applyMatrix && (applyMatrix = this._transformContent(_matrix,
|
|
||||||
_applyRecursively, _setApplyMatrix))) {
|
if (applyMatrix && (applyMatrix = this._transformContent(
|
||||||
|
_matrix, _applyRecursively, _setApplyMatrix))) {
|
||||||
// Pivot is provided in the parent's coordinate system, so transform
|
// Pivot is provided in the parent's coordinate system, so transform
|
||||||
// it along too.
|
// it along too.
|
||||||
var pivot = this._pivot;
|
var pivot = this._pivot;
|
||||||
|
@ -3567,7 +3567,10 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
// Reset the internal matrix to the identity transformation if
|
// Reset the internal matrix to the identity transformation if
|
||||||
// it was possible to apply it, but do not notify owner of change.
|
// it was possible to apply it, but do not notify owner of change.
|
||||||
_matrix.reset(true);
|
_matrix.reset(true);
|
||||||
}
|
// Set the internal _applyMatrix flag to true if we're told to
|
||||||
|
// do so
|
||||||
|
if (_setApplyMatrix && this._canApplyMatrix)
|
||||||
|
this._applyMatrix = true;
|
||||||
}
|
}
|
||||||
// Calling _changed will clear _bounds and _position, but depending
|
// Calling _changed will clear _bounds and _position, but depending
|
||||||
// on matrix we can calculate and set them again, so preserve them.
|
// on matrix we can calculate and set them again, so preserve them.
|
||||||
|
@ -3619,9 +3622,9 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
_transformContent: function(matrix, applyRecursively, setApplyMatrix) {
|
_transformContent: function(matrix, applyRecursively, setApplyMatrix) {
|
||||||
var children = this._children;
|
var children = this._children;
|
||||||
if (children) {
|
if (children) {
|
||||||
for (var i = 0, l = children.length; i < l; i++)
|
for (var i = 0, l = children.length; i < l; i++) {
|
||||||
children[i].transform(matrix, true, applyRecursively,
|
children[i].transform(matrix, applyRecursively, setApplyMatrix);
|
||||||
setApplyMatrix);
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -192,10 +192,35 @@ test(
|
||||||
|
|
||||||
test('group.matrix with parent matrix applied (#1711)', function() {
|
test('group.matrix with parent matrix applied (#1711)', function() {
|
||||||
var child = new Group({ applyMatrix: false });
|
var child = new Group({ applyMatrix: false });
|
||||||
var parent = new Group([child]);
|
var parent = new Group({ applyMatrix: true, children: [child] });
|
||||||
var scale = 1.1;
|
var scale = 1.1;
|
||||||
var initial = child.scaling.x;
|
var initial = child.scaling.x;
|
||||||
parent.scale(scale);
|
parent.scale(scale);
|
||||||
var final = child.scaling.x;
|
equals(child.scaling.x, initial * scale);
|
||||||
equals(final, initial * scale);
|
});
|
||||||
|
|
||||||
|
test('Nested group.matrix.apply(true, true) with matrices not applied', function() {
|
||||||
|
var path = new Path({ applyMatrix: false });
|
||||||
|
var group = new Group({ applyMatrix: false, children: [path] });
|
||||||
|
var parent = new Group({ applyMatrix: false, children: [group] });
|
||||||
|
var grandParent = new Group({ applyMatrix: false, children: [parent] });
|
||||||
|
equals(function() {
|
||||||
|
return grandParent.applyMatrix;
|
||||||
|
}, false);
|
||||||
|
equals(function() {
|
||||||
|
return group.applyMatrix;
|
||||||
|
}, false);
|
||||||
|
equals(function() {
|
||||||
|
return path.applyMatrix;
|
||||||
|
}, false);
|
||||||
|
grandParent.matrix.apply(true, true);
|
||||||
|
equals(function() {
|
||||||
|
return grandParent.applyMatrix;
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return group.applyMatrix;
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return path.applyMatrix;
|
||||||
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue