/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ // Hello World in JavaScript // Import standard OpenOffice.org API classes. For more information on // these classes and the OpenOffice.org API, see the OpenOffice.org // Developers Guide at: // https://api.libreoffice.org/ importClass(Packages.com.sun.star.uno.UnoRuntime); importClass(Packages.com.sun.star.text.XTextDocument); importClass(Packages.com.sun.star.text.XText); importClass(Packages.com.sun.star.text.XTextRange); importClass(Packages.com.sun.star.frame.XModel); importClass(Packages.com.sun.star.lang.XMultiServiceFactory); importClass(Packages.com.sun.star.text.XTextContent); importClass(Packages.com.sun.star.drawing.XDrawPageSupplier); importClass(Packages.com.sun.star.text.ControlCharacter); importClass(Packages.com.sun.star.text.XParagraphCursor); importClass(Packages.com.sun.star.awt.Size); importClass(Packages.com.sun.star.awt.Point); importClass(Packages.com.sun.star.drawing.XShape); importClass(Packages.com.sun.star.beans.XPropertySet); importClass(Packages.com.sun.star.text.TextContentAnchorType); importClass(Packages.com.sun.star.drawing.XShapes); importClass(Packages.com.sun.star.drawing.FillStyle); // Import XScriptContext class. An instance of this class is available // to all JavaScript scripts in the global variable "XSCRIPTCONTEXT". This // variable can be used to access the document for which this script // was invoked. // Methods available are: // XSCRIPTCONTEXT.getDocument() returns XModel // XSCRIPTCONTEXT.getInvocationContext() returns XScriptInvocationContext or NULL // XSCRIPTCONTEXT.getDesktop() returns XDesktop // XSCRIPTCONTEXT.getComponentContext() returns XComponentContext // For more information on using this class see the scripting // developer guides at: // https://api.libreoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml oDoc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext()); if ( !oDoc ) oDoc = XSCRIPTCONTEXT.getDocument(); xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc); xText = xTextDoc.getText(); oCursor = xText.createTextCursor(); xFactory = UnoRuntime.queryInterface(XMultiServiceFactory,oDoc); // Add 2 paragraph, and go to to one before the end oCursor.gotoEnd(false); xText.insertControlCharacter( oCursor, ControlCharacter.PARAGRAPH_BREAK, false); xText.insertControlCharacter( oCursor, ControlCharacter.PARAGRAPH_BREAK, false); xParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor,oCursor); xParagraphCursor.gotoPreviousParagraph(false); // Create the shape interfacws polyLine1 = xFactory.createInstance("com.sun.star.drawing.PolyLineShape"); xPolyLine1 = UnoRuntime.queryInterface(XShape, polyLine1); circle = xFactory.createInstance("com.sun.star.drawing.EllipseShape"); xCircle = UnoRuntime.queryInterface(XShape, circle); // Set sizes for shapes. aSize = Size(); aSize.Height=aSize.Width=2000; xPolyLine1.setSize(aSize); diameter=Math.round(2000*(2-Math.sqrt(2))); aSize.Height=aSize.Width=diameter; xCircle.setSize(aSize); // Set location of each shape aPoint = Point(); aPoint.X = 100; aPoint.Y = 100; xPolyLine1.setPosition(aPoint); aPoint.X = 2100-diameter; aPoint.Y = 100; xCircle.setPosition(aPoint); //ArrayObj=xFactory.createInstance("java.lang.reflect.Array");//[[{"X":100,"Y":1500},{"X":100,"Y":500}]]; polyLineCoords = java.lang.reflect.Array.newInstance(Point,[1,8]); polyLineCoords[0][0] = Point(0,1000); polyLineCoords[0][1] = Point(0,0); polyLineCoords[0][2] = Point(2000,0); polyLineCoords[0][3] = Point(2000,2000); polyLineCoords[0][4] = Point(0,2000); polyLineCoords[0][5] = Point(0,1000); polyLineCoords[0][6] = Point(1000,1000); polyLineCoords[0][7] = Point(1000,2000); xPolyLine1Props = UnoRuntime.queryInterface(XPropertySet,xPolyLine1); xPolyLine1Props.setPropertyValue("AnchorType",TextContentAnchorType.AT_PARAGRAPH); xPolyLine1Props.setPropertyValue("Geometry", polyLineCoords); xCircleProps = UnoRuntime.queryInterface(XPropertySet,xCircle); xCircleProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_PARAGRAPH); xCircleProps.setPropertyValue("FillStyle", FillStyle.NONE); // Use the XDrawPageSupplier interface from the document to add the // Draw Page xDrawPageSupplier=UnoRuntime.queryInterface(XDrawPageSupplier, oDoc); xShapes = UnoRuntime.queryInterface(XShapes,xDrawPageSupplier.getDrawPage()); xShapes.add(xPolyLine1); xShapes.add(xCircle);