Drawing Shapes

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 15:37, 9 August 2021 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Writer uses the same drawing engine as Apache OpenOffice Impress and Apache OpenOffice Draw. The limitations are that in Writer only one drawpage can exist and 3D objects are not supported. All drawing shapes support these properties:

Properties of com.sun.star.drawing.Shape
ZOrder [optional] long - Is used to query or change the ZOrder of this Shape .
LayerID [optional] short - This is the ID of the layer to which this shape is attached.
LayerName [optional] string - This is the name of the layer to which this Shape is attached.
Printable [optional] boolean - If this is false, the shape is not visible on printer outputs.
MoveProtect [optional] boolean - When set to true, this shape cannot be moved interactively in the user interface.
Name [optional] string - This is the name of this shape.
SizeProtect [optional] boolean - When set to true, this shape may not be sized interactively in the user interface.
Style [optional] com.sun.star.style.XStyle. Determines the style for this shape.
Transformation [optional] com.sun.star.drawing.HomogenMatrix This property lets you get and set the transformation matrix for this shape. The transformation is a 3x3 blended matrix and can contain translation, rotation, shearing and scaling.
ShapeUserDefinedAttributes [optional] com.sun.star.container.XNameContainer. This property stores xml attributes. They are saved to and restored from automatic styles inside xml files.

In addition to the properties of the shapes natively supported by the drawing engine, the writer shape adds some properties, so that they are usable for text documents. These are defined in the service com.sun.star.text.Shape:

Properties of com.sun.star.text.Shape
AnchorPageNo short - Contains the number of the page where the objects are anchored.
AnchorFrame com.sun.star.text.XTextFrame. Contains the text frame the current frame is anchored to.
SurroundAnchorOnly boolean - Determines if the text of the paragraph in which the object is anchored, wraps around the object.
AnchorType [optional] com.sun.star.text.TextContentAnchorType. Specifies how the text content is attached to its surrounding text.
HoriOrient short - Determines the horizontal orientation of the object.
HoriOrientPosition long - Contains the horizontal position of the object (1/100 mm).
HoriOrientRelation short - Determines the environment of the object to which the orientation is related.
VertOrient short - Determines the vertical orientation of the object.
VertOrientPosition long - Contains the vertical position of the object (1/100 mm). Valid only if TextEmbeddedObject::VertOrient is VertOrientation::NONE.
VertOrientRelation short - Determines the environment of the object to which the orientation is related.
LeftMargin long - Contains the left margin of the object.
RightMargin long - Contains the right margin of the object.
TopMargin long - Contains the top margin of the object.
BottomMargin long - Contains the bottom margin of the object.
Surround [deprecated]. Determines the type of the surrounding text.
SurroundAnchorOnly boolean - Determines if the text of the paragraph in which the object is anchored, wraps around the object.
SurroundContour boolean - Determines if the text wraps around the contour of the object.
ContourOutside boolean - The text flows only around the contour of the object.
Opaque boolean - Determines if the object is opaque or transparent for text.
TextRange com.sun.star.text.XTextRange. Contains a text range where the shape should be anchored to.

The chapter Drawing Documents and Presentation Documents describes how to use shapes and the interface of the draw page.

A sample that creates and inserts drawing shapes:

  /** This method demonstrates how to create and manipulate shapes, and how to access the draw page
      of the document to insert shapes
  protected void DrawPageExample () {
      try {
          // Go to the end of the document
          // Insert two new paragraphs
          ControlCharacter.PARAGRAPH_BREAK, false);
              ControlCharacter.PARAGRAPH_BREAK, false);
          // Get the XParagraphCursor interface of our document cursor
          XParagraphCursor xParaCursor = (XParagraphCursor) 
              UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor);
          // Position the cursor in the 2nd paragraph
          // Create a RectangleShape using the document factory
          XShape xRect = (XShape) UnoRuntime.queryInterface( 
              XShape.class, mxDocFactory.createInstance(
          // Create an EllipseShape using the document factory
          XShape xEllipse = (XShape) UnoRuntime.queryInterface( 
              XShape.class, mxDocFactory.createInstance( 
          // Set the size of both the ellipse and the rectangle
          Size aSize = new Size();
          aSize.Height = 4000;
          aSize.Width = 10000;
          aSize.Height = 3000;
          aSize.Width = 6000;
          // Set the position of the Rectangle to the right of the ellipse
          Point aPoint = new Point();
          aPoint.X = 6100;
          aPoint.Y = 0;
          xRect.setPosition (aPoint);
          // Get the XPropertySet interfaces of both shapes
          XPropertySet xRectProps = (XPropertySet) UnoRuntime.queryInterface( 
              XPropertySet.class, xRect);
          XPropertySet xEllipseProps = (XPropertySet) UnoRuntime.queryInterface(
              XPropertySet.class, xEllipse);
          // And set the AnchorTypes of both shapes to 'AT_PARAGRAPH'
          xRectProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_PARAGRAPH);
          xEllipseProps.setPropertyValue("AnchorType", TextContentAnchorType.AT_PARAGRAPH);
          // Access the XDrawPageSupplier interface of the document
          XDrawPageSupplier xDrawPageSupplier = (XDrawPageSupplier) UnoRuntime.queryInterface(
              XDrawPageSupplier.class, mxDoc);
          // Get the XShapes interface of the draw page
          XShapes xShapes = (XShapes) UnoRuntime.queryInterface( 
              XShapes.class, xDrawPageSupplier.getDrawPage());
          // Add both shapes
          xShapes.add (xEllipse);
          xShapes.add (xRect);
          This doesn't work, I am assured that FME and AMA are fixing it.
          XShapes xGrouper = (XShapes) UnoRuntime.queryInterface( 
              XShapes.class, mxDocFactory.createInstance( 
          XShape xGrouperShape = (XShape) UnoRuntime.queryInterface(XShape.class, xGrouper);
          xShapes.add (xGrouperShape);
          xGrouper.add (xRect);
          xGrouper.add (xEllipse);
          XShapeGrouper xShapeGrouper = (XShapeGrouper) UnoRuntime.queryInterface(
              XShapeGrouper.class, xShapes);
          xShapeGrouper.group (xGrouper);
      } catch (Exception e) {
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages