In this example a rectangle is created automatically and a text is added to the rectangle.
With using the text cursor the text is coloured purple, set bold and is underlined.
/* 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 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, 1000))
xrectangle~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 10000, 5000))
xDrawPage~add(xrectangle)
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!")
cur = xTextCursor~{%see com.sun.star.beans.XPropertySet%xPropertySet}
cur~setPropertyValue("CharColor", box("int", "8968CD"x ~c2d)) -- set text colour purple
cur~setPropertyValue("CharHeight", box("float", "30")) -- set font size 30
cur~setPropertyValue("CharWeight", -
box("float", bsf.getConstant("{%see com.sun.star.awt.FontWeight}", "BOLD"))) -- set the font bold
cur~setPropertyValue("CharUnderline", -
box("short", bsf.getConstant("{%see com.sun.star.awt.FontUnderline}", "DOUBLE"))) -- double underline the text
Call syssleep 2
cur~setPropertyValue("CharCrossedOut", box("boolean", "TRUE")) -- text is crossed out
cur~setPropertyValue("CharFontName", "Times") -- change font to times new roman
cur~setPropertyValue("CharWordMode", box("boolean", "TRUE")) -- underline and strike-through properties are not applied to white spaces
Call syssleep 2
cur~setPropertyValue("CharCrossedOut", box("boolean", "FALSE"))
cur~setPropertyValue("CharUnderline", -
box("short", bsf.getConstant("{%see com.sun.star.awt.FontUnderline}", "NONE"))) -- text is not underlined
cur~setPropertyValue("CharShadowed", box("boolean", "TRUE")) -- set a text shadow
::requires UNO.cls -- get UNO support