The Service
com.sun.star.drawing.EllipseShape
service is responsible for circles and ellipses and supports the following services:
Fill properties com.sun.star.drawing.FillProperties Line properties com.sun.star.drawing.LineProperties Text properties com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties ) Shadow properties com.sun.star.drawing.ShadowProperties
In addition to these services, circles and ellipses also provide these properties:
CircleKind (Enum)
type of circle or ellipse (default values in accordance with com.sun.star.drawing.CircleKind
)
CircleStartAngle (Long)
start angle in tenths of a degree (only for circle or ellipse segments)
CircleEndAngle (Long)
end angle in tenths of a degree (only for circle or ellipse segments)
The CircleKind property determines if an object is a complete circle, a circular slice, or a section of a circle. The following values are available:
full circle or full ellipse
section of circle (partial circle whose interfaces are linked directly to one another) circle slice
The Structure of Drawings 169 The following example creates a circular slice with a 70 degree angle (produced from
difference between start angle of 20 degrees and end angle of 90 degrees)
Dim Doc As Object Dim Page As Object
Dim EllipseShape As Object
Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) EllipseShape = Doc.createInstance("com.sun.star.drawing.EllipseShape") EllipseShape.Size = Size EllipseShape.Position = Point EllipseShape.CircleStartAngle = 2000 EllipseShape.CircleEndAngle = 9000 EllipseShape.CircleKind = com.sun.star.drawing.CircleKind.SECTION Page.add(EllipseShape)
Lines
OpenOffice.org provides the
com.sun.star.drawing.LineShape
service for line objects. Line objects support all of the general formatting services with the exception of areas. The following are all of the properties that are associated with the LineShape service: Line properties com.sun.star.drawing.LineProperties Text properties com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and
The Structure of Drawings 170 com.sun.star.style.ParagraphProperties
)
Shadow properties
com.sun.star.drawing.ShadowProperties
The following example creates and formats a line with the help of the named properties. The origin of the line is specified in the Location property, whereas the coordinates listed in the Size property specify the end point of the line.
Dim Doc As Object Dim Page As Object Dim LineShape As Object
Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size Point.x = 1000 Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) LineShape = Doc.createInstance("com.sun.star.drawing.LineShape") LineShape.Size = Size LineShape.Position = Point Page.add(LineShape)
Polypolygon Shapes
OpenOffice.org also supports complex polygonal shapes through the com.sun.star.drawing.PolyPolygonShape
service. Strictly speaking, a PolyPolygon is not a simple polygon but a multiple polygon. Several independent lists containing corner points can therefore be specified and combined to form a complete object.
As with rectangle shapes, all the formatting properties of drawing objects are also provided for polypolygons:
Fill properties
com.sun.star.drawing.FillProperties
The Structure of Drawings 171 com.sun.star.drawing.LineProperties Text properties com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties ) Shadow properties com.sun.star.drawing.ShadowProperties
The PolyPolygonShape service also has a property that lets you define the coordinates of a polygon:
• PolyPolygon (Array) – field containing the coordinates of the polygon (double array with points of the
com.sun.star.awt.Point type)
The following example shows how you can define a triangle with the PolyPolygonShape service.
Dim Doc As Object Dim Page As Object
Dim PolyPolygonShape As Object Dim PolyPolygon As Variant
Dim Coordinates(2) As New com.sun.star.awt.Point Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0) PolyPolygonShape =
Doc.createInstance("com.sun.star.drawing.PolyPolygonShape") Page.add(PolyPolygonShape) ' Page.add must take place before the coordinates are set
Coordinates(0).x = 1000 Coordinates(1).x = 7500 Coordinates(2).x = 10000 Coordinates(0).y = 1000 Coordinates(1).y = 7500
The Structure of Drawings 172 Coordinates(2).y = 5000
PolyPolygonShape.PolyPolygon = Array(Coordinates())
Since the points of a polygon are defined as absolute values, you do not need to specify the size or the start position of a polygon. Instead, you need to create an array of the points, package this array in a second array (using the Array(Coordinates()) call), and then assign this array to the polygon. Before the corresponding call can be made, the polygon must be inserted into the document.
The double array in the definition allows you to create complex shapes by merging several polygons. For example, you can create a rectangle and then insert another rectangle inside it to create a hole in the original rectangle:
Dim Doc As Object Dim Page As Object
Dim PolyPolygonShape As Object Dim PolyPolygon As Variant
Dim Square1(3) As New com.sun.star.awt.Point Dim Square2(3) As New com.sun.star.awt.Point Dim Square3(3) As New com.sun.star.awt.Point Doc = StarDesktop.CurrentComponent
Page = Doc.drawPages(0) PolyPolygonShape =
Doc.createInstance("com.sun.star.drawing.PolyPolygonShape") Page.add(PolyPolygonShape) ' Page.add must take place before the coordinates are set
Square1(0).x = 5000 Square1(1).x = 10000 Square1(2).x = 10000 Square1(3).x = 5000 Square1(0).y = 5000 Square1(1).y = 5000 Square1(2).y = 10000 Square1(3).y = 10000 Square2(0).x = 6500 Square2(1).x = 8500 Square2(2).x = 8500 Square2(3).x = 6500 Square2(0).y = 6500 Square2(1).y = 6500 Square2(2).y = 8500
The Structure of Drawings 173 Square2(3).y = 8500 Square3(0).x = 6500 Square3(1).x = 8500 Square3(2).x = 8500 Square3(3).x = 6500 Square3(0).y = 9000 Square3(1).y = 9000 Square3(2).y = 9500 Square3(3).y = 9500
PolyPolygonShape.PolyPolygon = Array(Square1(), Square2(), Square3())
With respect as to which areas are filled and which areas are holes, OpenOffice.org applies a simple rule: the edge of the outer shape is always the outer border of the polypolygon. The next line inwards is the inner border of the shape and marks the transition to the first hole. If there is another line inwards, it marks the transition to a filled area.
Graphics
The last of the drawing elements presented here are graphic objects that are based on the com.sun.star.drawing.GraphicObjectShape
service. These can be used with any graphic within OpenOffice.org whose appearance can be adapted using a whole range of properties.
Graphic objects support two of the general formatting properties:
Text properties com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and com.sun.star.style.ParagraphProperties ) Shadow properties com.sun.star.drawing.ShadowProperties
Additional properties that are supported by graphic objects are:
GraphicURL (String)
URL of the graphic
AdjustLuminance (Short)
The Structure of Drawings 174
AdjustContrast (Short)
contrast as a percentage (negative values are also permitted)
AdjustRed (Short)
red value as a percentage (negative values are also permitted)
AdjustGreen (Short)
green value as a percentage (negative values are also permitted)
AdjustBlue (Short)
blue value as a percentage (negative values are also permitted)
Gamma (Short)
gamma value of a graphic
Transparency (Short)
transparency of a graphic as a percentage
GraphicColorMode (enum)
color mode, for example, standard, gray stages, black and white (default value in accordance with
com.sun.star.drawing.ColorMode )
The following example shows how to insert a page into a graphics object.Dim Doc As Object
Dim Page As Object
Dim GraphicObjectShape As Object Dim Point As New com.sun.star.awt.Point Dim Size As New com.sun.star.awt.Size
Point.x = 1000 ' specifications, insignificant because latter coordinates are binding
Point.y = 1000 Size.Width = 10000 Size.Height = 10000 Doc = StarDesktop.CurrentComponent Page = Doc.drawPages(0) GraphicObjectShape = Doc.createInstance("com.sun.star.drawing.GraphicObjectShape") GraphicObjectShape.Size = Size GraphicObjectShape.Position = Point GraphicObjectShape.GraphicURL = "file:///c:/test.jpg" GraphicObjectShape.AdjustBlue = -50 GraphicObjectShape.AdjustGreen = 5
The Structure of Drawings 175 GraphicObjectShape.AdjustBlue = 10 GraphicObjectShape.AdjustContrast = 20 GraphicObjectShape.AdjustLuminance = 50 GraphicObjectShape.Transparency = 40 GraphicObjectShape.GraphicColorMode = com.sun.star.drawing.ColorMode.STANDARD Page.add(GraphicObjectShape)
This code inserts the test.jpg graphic and adapts its appearance using the Adjust
properties. In this example, the graphics are depicted as 40 percent transparent with no other color conversions do not take place (GraphicColorMode = STANDARD).
Source: http://wiki.services.openoffice.org/w/index.php?title=Documentation/BASIC_ Guide/Structure_of_Drawings&oldid=105201
Principal Authors: Fpe, Ccornell