EasyManua.ls Logo

Adobe 0046100128056 - InDesign - Mac - Working with Transformation Matrices

Adobe 0046100128056 - InDesign - Mac
209 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
CHAPTER 5: Working with Page Items Transforming Page Items 63
The following scripting example demonstrates the basic process of transforming a page item. (For the
complete script, see TransformExamples.)
//Rotate a rectangle "myRectangle" around its center point.
var myRotateMatrix =
app.transformationMatrices.add({counterclockwiseRotationAngle:27});
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor, myRotateMatrix);
//Scale a rectangle "myRectangle" around its center point.
var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:.5,
verticalScaleFactor:.5});
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor, myScaleMatrix);
//Shear a rectangle "myRectangle" around its center point.
var myShearMatrix =app.transformationMatrices.add({clockwiseShearAngle:30});
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates,
AnchorPoint.centerAnchor, myShearMatrix);
//Rotate a rectangle "myRectangle" around a specified ruler point ([72, 72]).
var myRotateMatrix =
app.transformationMatrices.add({counterclockwiseRotationAngle:27});
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates, [[72, 72],
AnchorPoint.topLeftAnchor], myRotateMatrix, undefined, true);
//Scale a rectangle "myRectangle" around a specified ruler point ([72, 72]).
var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:.5,
verticalScaleFactor:.5});
myRectangle.transform(CoordinateSpaces.pasteboardCoordinates, [[72, 72],
AnchorPoint.topLeftAnchor], myScaleMatrix, undefined, true);
For a script that “wraps” transformation routines in a series of easy-to-use functions, refer to the Transform
script.
Working with transformation matrices
A transformation matrix cannot be changed once it has been created, but a variety of methods can
interact with the transformation matrix to create a new transformation matrix based on the existing
transformation matrix. In the following examples, we show how to apply transformations to a
transformation matrix and replace the original matrix. (For the complete script, see TransformMatrix.)
//Scale a transformation matrix by 50% in both horizontal and vertical dimensions.
var myTransformationMatrix = myTransformationMatrix.scaleMatrix(.5, .5);
//Rotate a transformation matrix by 45 degrees.
myTransformationMatrix = myTransformationMatrix.rotateMatrix(45);
//Shear a transformation matrix by 15 degrees.
myTransformationMatrix = myTransformationMatrix.shearMatrix(15);
When you use the rotateMatrix method, you can use a sine or cosine value to transform the matrix,
rather than an angle in degrees, as shown in the RotateMatrix script.
//The following statements are equivalent
//(0.25881904510252 is the sine of 15 degrees; 0.96592582628907, the cosine).
myTransformationMatrix = myTransformationMatrix.rotateMatrix(15);
myTransformationMatrix = myTransformationMatrix.rotateMatrix(undefined,
0.96592582628907);
myTransformationMatrix = myTransformationMatrix.rotateMatrix(undefined, undefined,
0.25881904510252);
When you use the shearMatrixmethod, you can provide a slope, rather than an angle in degrees, as
shown in the ShearMatrix script.

Table of Contents

Related product manuals