In this example the fillstyle of a shape is set gradient by setting the Fillstyle.
The GradientStyle can be set linear or radial.
/* 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 */
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, 1000))
xrectangle1~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 5000, 5000))
xDrawPage~add(xrectangle1) -- adds the rectangle to the draw document
/* colour the rectangle gradient linear */
xShapeProps1 = xrectangle1~{%see com.sun.star.beans.XPropertySet%XPropertySet}
oGradient = .bsf~new("{%see com.sun.star.awt.Gradient}")
oGradient~Style = bsf.getConstant("{%see com.sun.star.awt.GradientStyle}", "LINEAR")
oGradient~StartColor = 8526139
oGradient~EndColor = 238210238
oGradient~Angle = 450 -- angle of 45 degrees
oGradient~StartIntensity = 150
oGradient~EndIntensity = 150
oGradient~StepCount = 100 -- gradient with 100 sinlge colour steps
xShapeProps1~setPropertyValue("FillStyle", -
bsf.getConstant("{%see com.sun.star.drawing.FillStyle}", "GRADIENT"))
xShapeProps1~setPropertyValue("FillGradient", oGradient)
/* create a rectangle */
xrectangle2 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")~{%see com.sun.star.drawing.XShape%xshape}
xrectangle2~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 7000))
xrectangle2~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 5000, 5000))
xDrawPage~add(xrectangle2) -- adds the rectangle to the draw document
/* colour the rectangle gradient radial*/
xShapeProps2 = xrectangle2~{%see com.sun.star.beans.XPropertySet%XPropertySet}
o1Gradient = .bsf~new("{%see com.sun.star.awt.Gradient}")
o1Gradient~Style = bsf.getConstant("{%see com.sun.star.awt.GradientStyle}", "RADIAL")
o1Gradient~StartColor = 250235215
o1Gradient~EndColor = 255222173
o1Gradient~Angle = 500 -- angle of 50 degrees
o1Gradient~StartIntensity = 100
o1Gradient~EndIntensity = 50
o1Gradient~StepCount = 10 -- gradient with 10 sinlge colour steps
xShapeProps2~setPropertyValue("FillStyle", -
bsf.getConstant("{%see com.sun.star.drawing.FillStyle}", "GRADIENT"))
xShapeProps2~setPropertyValue("FillGradient", o1Gradient)
::requires UNO.cls -- get UNO support