Introduction
Statistics
Contact
Development
Disclaimer
Help
*
* 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/
mportClass(Packages.com.sun.star.uno.UnoRuntime);
mportClass(Packages.com.sun.star.text.XTextDocument);
mportClass(Packages.com.sun.star.text.XText);
mportClass(Packages.com.sun.star.text.XTextRange);
mportClass(Packages.com.sun.star.frame.XModel);
mportClass(Packages.com.sun.star.lang.XMultiServiceFactory);
mportClass(Packages.com.sun.star.text.XTextContent);
mportClass(Packages.com.sun.star.drawing.XDrawPageSupplier);
mportClass(Packages.com.sun.star.text.ControlCharacter);
mportClass(Packages.com.sun.star.text.XParagraphCursor);
mportClass(Packages.com.sun.star.awt.Size);
mportClass(Packages.com.sun.star.awt.Point);
mportClass(Packages.com.sun.star.drawing.XShape);
mportClass(Packages.com.sun.star.beans.XPropertySet);
mportClass(Packages.com.sun.star.text.TextContentAnchorType);
mportClass(Packages.com.sun.star.drawing.XShapes);
mportClass(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 N…
/ 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/Scripti…
Doc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext());
f ( !oDoc )
oDoc = XSCRIPTCONTEXT.getDocument();
TextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
Text = xTextDoc.getText();
Cursor = xText.createTextCursor();
Factory = UnoRuntime.queryInterface(XMultiServiceFactory,oDoc);
/ Add 2 paragraph, and go to to one before the end
Cursor.gotoEnd(false);
Text.insertControlCharacter(
oCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
Text.insertControlCharacter(
oCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
ParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor,oCursor);
ParagraphCursor.gotoPreviousParagraph(false);
/ Create the shape interfacws
olyLine1 = xFactory.createInstance("com.sun.star.drawing.PolyLineShape");
PolyLine1 = UnoRuntime.queryInterface(XShape, polyLine1);
ircle = xFactory.createInstance("com.sun.star.drawing.EllipseShape");
Circle = UnoRuntime.queryInterface(XShape, circle);
/ Set sizes for shapes.
Size = Size();
Size.Height=aSize.Width=2000;
PolyLine1.setSize(aSize);
iameter=Math.round(2000*(2-Math.sqrt(2)));
Size.Height=aSize.Width=diameter;
Circle.setSize(aSize);
/ Set location of each shape
Point = Point();
Point.X = 100;
Point.Y = 100;
PolyLine1.setPosition(aPoint);
Point.X = 2100-diameter;
Point.Y = 100;
Circle.setPosition(aPoint);
/ArrayObj=xFactory.createInstance("java.lang.reflect.Array");//[[{"X":100,"Y":1…
olyLineCoords = java.lang.reflect.Array.newInstance(Point,[1,8]);
olyLineCoords[0][0] = Point(0,1000);
olyLineCoords[0][1] = Point(0,0);
olyLineCoords[0][2] = Point(2000,0);
olyLineCoords[0][3] = Point(2000,2000);
olyLineCoords[0][4] = Point(0,2000);
olyLineCoords[0][5] = Point(0,1000);
olyLineCoords[0][6] = Point(1000,1000);
olyLineCoords[0][7] = Point(1000,2000);
PolyLine1Props = UnoRuntime.queryInterface(XPropertySet,xPolyLine1);
PolyLine1Props.setPropertyValue("AnchorType",TextContentAnchorType.AT_PARAGRAPH…
PolyLine1Props.setPropertyValue("Geometry", polyLineCoords);
CircleProps = UnoRuntime.queryInterface(XPropertySet,xCircle);
CircleProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_PARAGRAPH);
CircleProps.setPropertyValue("FillStyle", FillStyle.NONE);
/ Use the XDrawPageSupplier interface from the document to add the
/ Draw Page
DrawPageSupplier=UnoRuntime.queryInterface(XDrawPageSupplier, oDoc);
Shapes = UnoRuntime.queryInterface(XShapes,xDrawPageSupplier.getDrawPage());
Shapes.add(xPolyLine1);
Shapes.add(xCircle);