/** Test of splitLine method, of class ShapeHelper. */ @Test public void testSplitLine_Shape_double() { System.out.println("splitLine"); Path2D.Double line = new Path2D.Double() {}; line.moveTo(0, 0); line.lineTo(10, 10); line.lineTo(0, 20); line.lineTo(10, 30); line.lineTo(0, 40); double coords[] = new double[6]; List<Shape> result1 = ShapeHelper.splitLine(line, 28.28); for (Shape shp : result1) { PathIterator it = shp.getPathIterator(null); System.out.println("Shape: "); while (!it.isDone()) { it.currentSegment(coords); System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")"); it.next(); } } ; result1 = ShapeHelper.splitLine(line, 35.0); for (Shape shp : result1) { PathIterator it = shp.getPathIterator(null); System.out.println("Shape: "); while (!it.isDone()) { it.currentSegment(coords); System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")"); it.next(); } } result1 = ShapeHelper.splitLine(line, 70.0); for (Shape shp : result1) { PathIterator it = shp.getPathIterator(null); System.out.println("Shape: "); while (!it.isDone()) { it.currentSegment(coords); System.out.println("(" + coords[0] + ";" + " " + coords[1] + ")"); it.next(); } } }
@Test public void testGetPointAt() { Path2D.Double path = new Path2D.Double(); path.moveTo(10, 10); path.lineTo(20, 10); path.lineTo(20, 20); Double pointAt = ShapeHelper.getPointAt(path, 30); System.out.println("PT: " + pointAt.getX() + ";" + pointAt.getY()); assertEquals(pointAt.getX(), 20.0, 0.00001); assertEquals(pointAt.getY(), 30.0, 0.00001); path = new Path2D.Double(); }
public static void main(String args[]) { XComponent xDrawDoc = null; try { // get the remote office context of a running office (a new office // instance is started if necessary) com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); // suppress Presentation Autopilot when opening the document // properties are the same as described for // com.sun.star.document.MediaDescriptor PropertyValue[] pPropValues = new PropertyValue[1]; pPropValues[0] = new PropertyValue(); pPropValues[0].Name = "Silent"; pPropValues[0].Value = Boolean.TRUE; xDrawDoc = Helper.createDocument( xOfficeContext, "private:factory/simpress", "_blank", 0, pPropValues); XDrawPage xPage = PageHelper.getDrawPageByIndex(xDrawDoc, 0); XPropertySet xPagePropSet = UnoRuntime.queryInterface(XPropertySet.class, xPage); XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, xPage); XShape xShape = ShapeHelper.createShape( xDrawDoc, new Point(0, 0), new Size(10000, 2500), "com.sun.star.drawing.RectangleShape"); xShapes.add(xShape); XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xShape); 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); AffineTransform aNewMatrix1 = new AffineTransform(); aNewMatrix1.setToRotation(Math.PI / 180 * 15); aNewMatrix1.concatenate(aOriginalMatrix); AffineTransform aNewMatrix2 = new AffineTransform(); aNewMatrix2.setToTranslation(2000, 2000); aNewMatrix2.concatenate(aNewMatrix1); double aFlatMatrix[] = new double[6]; aNewMatrix2.getMatrix(aFlatMatrix); 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); } catch (Exception ex) { System.out.println(ex); } System.exit(0); }