Difference between revisions of "Documentation/DevGuide/Drawings/Transforming"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (change a code view)
(Added Java syntax highlight)
Line 11: Line 11:
  
 
Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by {{PRODUCTNAME}}. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object. <!--[SOURCE:Drawing/ObjectTransformationDemo.java]-->  
 
Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by {{PRODUCTNAME}}. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object. <!--[SOURCE:Drawing/ObjectTransformationDemo.java]-->  
 
+
<source lang="java">
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
 
  // take the current tranformation matrix
 
  // take the current tranformation matrix
Line 38: Line 38:
 
  aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
 
  aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
 
  aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
 
  aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
  xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);
+
  xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);</source>
  
 
{{PDL1}}  
 
{{PDL1}}  
  
 
[[Category:Documentation/Developer's_Guide/Drawing_Documents_and_Presentation_Documents]]
 
[[Category:Documentation/Developer's_Guide/Drawing_Documents_and_Presentation_Documents]]

Revision as of 12:36, 13 January 2013




Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by OpenOffice.org. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object.

  XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
 // take the current tranformation matrix
 HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3)xPropSet.getPropertyValue("Transformation");
 java.awt.geom.AffineTransform aOriginalMatrix = 
 new java.awt.geom.AffineTransform(aHomogenMatrix3.Line1.Column1, 
                                  aHomogenMatrix3.Line2.Column1,
                                  aHomogenMatrix3.Line1.Column2, 
                                  aHomogenMatrix3.Line2.Column2,
                                  aHomogenMatrix3.Line1.Column3, 
                                  aHomogenMatrix3.Line2.Column3 );
 // rotate the object by 15 degrees
 AffineTransform aNewMatrix1 = new AffineTransform();
 aNewMatrix1.setToRotation(Math.toRadians(15));
 aNewMatrix1.concatenate(aOriginalMatrix);
 // and translate the object by 2cm on the x-axis
 AffineTransform aNewMatrix2 = new AffineTransform();
 aNewMatrix2.setToTranslation(2000, 0);
 aNewMatrix2.concatenate(aNewMatrix1);
 double aFlatMatrix[] = new double[6];aNewMatrix2.getMatrix(aFlatMatrix);
 // convert the flatMatrix to our HomogenMatrix3 structure
 aHomogenMatrix3.Line1.Column1 = aFlatMatrix[0];
 aHomogenMatrix3.Line2.Column1 = aFlatMatrix[1];
 aHomogenMatrix3.Line1.Column2 = aFlatMatrix[2];
 aHomogenMatrix3.Line2.Column2 = aFlatMatrix[3];
 aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
 aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
 xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages