LibreOffice provides a comprehensive and flexible API for drawing shapes through the com.sun.star.drawing module. This document outlines the different shape types available in the UNO API and how they are exposed to the AI assistant.
The most common and simple shapes are implemented as direct UNO classes. These include:
com.sun.star.drawing.RectangleShapecom.sun.star.drawing.EllipseShapecom.sun.star.drawing.TextShapecom.sun.star.drawing.LineShapecom.sun.star.drawing.ConnectorShape
These shapes are straightforward to instantiate and configure. They have dedicated properties for styling (e.g., FillColor, LineColor).
For more complex standard shapes like stars, smileys, arrows, and notably octagons, LibreOffice uses com.sun.star.drawing.CustomShape.
Instead of having a unique UNO class for every single geometric possibility (e.g., no OctagonShape), a CustomShape acts as a container whose geometry is defined by its properties.
To create one of these specific shapes:
- Instantiate
com.sun.star.drawing.CustomShape. - Add it to the drawing page.
- Configure its
CustomShapeGeometryproperty. This property accepts a sequence ofcom.sun.star.beans.PropertyValue. - Set a
PropertyValuewithName="Type"andValue="<shape_name>".
Commonly supported <shape_name> values include:
octagonstar5(5-pointed star)smileyheartcloudsunmoonup-arrowdiamondflowchart-process
By leveraging CustomShape, the AI assistant can draw a vast array of geometric figures and symbols without needing to specify complex paths.
For truly arbitrary shapes that don't fit into the predefined custom shape types, LibreOffice provides:
com.sun.star.drawing.PolyPolygonShape: A shape defined by an array of arrays of points (allowing for holes).com.sun.star.drawing.PolyLineShape: A line defined by multiple points.com.sun.star.drawing.PolyPolygonPathShape: Similar to PolyPolygon but using bezier paths.com.sun.star.drawing.PolyLinePathShape: A multi-segment bezier line.
These require specifying the Polygon or PolyPolygon properties, which expect an array of com.sun.star.awt.Point structures. (Note: Support for these advanced arbitrary polygon creations via AI tool calls may be implemented as a separate API in the future to keep standard shape creation simple and distinct).
The CreateShape tool unifies the simple and CustomShape UNO APIs into a single interface.
When the user requests a shape_type:
- Base Aliases: If it's a known simple alias (e.g.,
"rectangle","ellipse"), it maps to the corresponding base UNO shape (RectangleShape,EllipseShape). - UNO Classes: If it matches a specific UNO class name, it instantiates that class directly.
- Custom Shapes: If it's none of the above, the tool assumes the user is requesting a specific
CustomShapegeometry type (like"octagon"or"smiley"). It will instantiate aCustomShapeand apply the requested string to theTypegeometry property.
The tool's JSON schema summarizes CustomShape types by category (with a few examples each); the full set is defined by LibreOffice (see svx/source/customshapes/EnhancedCustomShapeTypeNames.cxx in LibreOffice core). Any valid type string from that catalog can be passed as shape_type.
Cross-document visual-object mechanics live in plugin/doc/visual_helpers.py. Writer, Calc, Draw, and Impress tools should reuse that module for safe UNO property access, document-kind detection, active draw-page lookup, graphic-object selection/listing, and common 1/100 mm unit conversions. App-specific behavior still belongs in the app modules, especially Writer text-cursor image insertion and Writer page-anchored shape quirks.