21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Page.add(LineShape)<br />

Polypolygon Shapes<br />

The Structure of Drawings<br />

<strong>OpenOffice</strong>.<strong>org</strong> also supports complex polygonal shapes through the com.sun.star.drawing.PolyPolygonShape<br />

service. Strictly speaking, a PolyPolygon is not a simple polygon but a multiple polygon. Several independent lists<br />

containing corner points can therefore be specified and combined to form a complete object.<br />

As with rectangle shapes, all the formatting properties of drawing objects are also provided for polypolygons:<br />

Fill properties<br />

com.sun.star.drawing.FillProperties<br />

Line properties<br />

com.sun.star.drawing.LineProperties<br />

Text properties<br />

com.sun.star.drawing.Text (with com.sun.star.style.CharacterProperties and<br />

com.sun.star.style.ParagraphProperties)<br />

Shadow properties<br />

com.sun.star.drawing.ShadowProperties<br />

The PolyPolygonShape service also has a property that lets you define the coordinates of a polygon:<br />

PolyPolygon (Array) – field containing the coordinates of the polygon (double array with points of the<br />

com.sun.star.awt.Point type)<br />

The following example shows how you can define a triangle with the PolyPolygonShape service.<br />

Dim Doc As Object<br />

Dim Page As Object<br />

Dim PolyPolygonShape As Object<br />

Dim PolyPolygon As Variant<br />

Dim Coordinates(2) As New com.sun.star.awt.Point<br />

Doc = ThisComponent<br />

Page = Doc.DrawPages(0)<br />

PolyPolygonShape = Doc.createInstance("com.sun.star.drawing.PolyPolygonShape")<br />

Page.add(PolyPolygonShape) ' Page.add must take place before the coordinates are set<br />

Coordinates(0).x = 1000<br />

Coordinates(1).x = 7500<br />

Coordinates(2).x = 10000<br />

Coordinates(0).y = 1000<br />

Coordinates(1).y = 7500<br />

Coordinates(2).y = 5000<br />

PolyPolygonShape.PolyPolygon = Array(Coordinates())<br />

Since the points of a polygon are defined as absolute values, you do not need to specify the size or the start<br />

position of a polygon. Instead, you need to create an array of the points, package this array in a second array<br />

(using the Array(Coordinates()) call), and then assign this array to the polygon. Before the corresponding call<br />

can be made, the polygon must be inserted into the document.<br />

The double array in the definition allows you to create complex shapes by merging several polygons. For example,<br />

you can create a rectangle and then insert another rectangle inside it to create a hole in the original rectangle:<br />

Dim Doc As Object<br />

Dim Page As Object<br />

Dim PolyPolygonShape As Object<br />

Dim PolyPolygon As Variant<br />

Dim Square1(3) As New com.sun.star.awt.Point<br />

Dim Square2(3) As New com.sun.star.awt.Point<br />

Dim Square3(3) As New com.sun.star.awt.Point<br />

Doc = ThisComponent<br />

Page = Doc.DrawPages(0)<br />

PolyPolygonShape = Doc.createInstance("com.sun.star.drawing.PolyPolygonShape")<br />

Chapter 8 · Drawings and Presentations 123

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!