In this example the text is ajusted to the left and right side
and to the top and bottom of a created rectangle.
/* Retrieve the Desktop object, we need its XComponentLoader interface to load a new document */
oDesktop = UNO.createDesktop() -- get the UNO Desktop service object
xComponentLoader = oDesktop~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} -- get componentLoader interface
/* open the blank file */
url = "private:factory/sdraw"
xDrawComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, -
.UNO~noProps)
/* need document's factory to be able to insert created objects */
xDocumentFactory = xDrawComponent~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
/* get draw page by index */
xDrawPage = xDrawComponent~{%see com.sun.star.drawing.XDrawPagesSupplier%XDrawPagesSupplier}~getDrawPages~getByIndex(0)~{%see com.sun.star.drawing.XDrawPage%XDrawPage}
/* create a circle and add it to the shape */
xCircle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.EllipseShape}")~{%see com.sun.star.drawing.XShape%xShape}
xCircle~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 1000))
xCircle~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 5000, 5000))
xDrawPage~add(xCircle)
xCircle~{%see com.sun.star.text.XText%xText}~setString("I am a circle!") -- add text to the circle
/* create a Rectangle and add it to the shape */
xrectangle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")~{%see com.sun.star.drawing.XShape%xshape}
xrectangle~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 7000))
xrectangle~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 7000, 5000))
xDrawPage~add(xrectangle)
/* set the properties of the rectangle shape */
xShapeProps = xrectangle~{%see com.sun.star.beans.XPropertySet%XPropertySet}
xShapeProps~setPropertyValue("FillColor", box("int", "836FFF"x ~c2d))
xShapeProps~setPropertyValue("LineColor", box("int", "836FFF"x ~c2d))
/* text is displayed on the top edge of the shape*/
xShapeProps~setPropertyValue("TextVerticalAdjust", -
bsf.getConstant("{%see com.sun.star.drawing.TextVerticalAdjust}", "TOP"))
xText = xrectangle~{%see com.sun.star.text.XText%XText}
xTextCursor = xText~createTextCursor
xTextCursor~gotoEnd(.false)
xTextRange = xTextCursor~{%see com.sun.star.text.XTextRange%XTextRange}
xTextRange~setString("I am a rectangle!")
/* create a Rectangle and add it to the shape */
xrectangle1 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")~{%see com.sun.star.drawing.XShape%xshape}
xrectangle1~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 13000))
xrectangle1~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 10000, 5000))
xDrawPage~add(xrectangle1)
/* set the properties of the rectangle shape */
xShapeProps1 = xrectangle1~{%see com.sun.star.beans.XPropertySet%XPropertySet}
xShapeProps1~setPropertyValue("FillColor", box("int", "8968CD"x ~c2d))
xShapeProps1~setPropertyValue("LineColor", box("int", "8968CD"x ~c2d))
/* text is displayed on the left edge of the shape*/
xShapeProps1~setPropertyValue("TextHorizontalAdjust", -
bsf.getConstant("{%see com.sun.star.drawing.TextHorizontalAdjust}", "LEFT"))
xText = xrectangle1~{%see com.sun.star.text.XText%XText}
xTextCursor = xText~createTextCursor
xTextCursor~gotoEnd(.false)
xTextRange = xTextCursor~{%see com.sun.star.text.XTextRange%XTextRange}
xTextRange~setString("I am a rectangle!")
call syssleep 1
/* text is displayed on the bottom edge of the shape*/
xShapeProps~setPropertyValue("TextVerticalAdjust", -
bsf.getConstant("{%see com.sun.star.drawing.TextVerticalAdjust}", "BOTTOM"))
call syssleep 1
/* text is displayed on the right edge of the shape*/
xShapeProps1~setPropertyValue("TextHorizontalAdjust", -
bsf.getConstant("com.sun.star.drawing.TextHorizontalAdjust", "RIGHT"))
::requires UNO.cls -- get UNO support