Bezier Shapes

From Apache OpenOffice Wiki
Jump to: navigation, search



Draw supports three different kinds of Bezier curves: OpenBezierShape, ClosedBezierShape and PolyPolygonBezierShape. They are all controlled by com.sun.star.drawing.PolyPolygonBezierDescriptor which is made up of the following properties:

Properties of com.sun.star.drawing.PolyPolygonBezierDescriptor
PolygonKind [readonly] com.sun.star.drawing.PolygonKind. Type of the polygon. Possible values are:

LINE for a LineShape.

POLY for a PolyPolygonShape.

PLIN for a PolyLineShape.

PATHLINE for an OpenBezierShape.

PATHFILL for a ClosedBezierShape.

PolyPolygonBezier struct com.sun.star.drawing.PolyPolygonBezierCoords. These are the bezier points of the polygon. The struct members are Coordinates and Flags, which are both sequences of sequences. The Coordinates sequence contains com.sun.star.awt.Point structs and the Flags sequence contains com.sun.star.drawing.PolygonFlags enums. Point members are X and Y. Possible PolygonFlags values are:
  • NORMAL the point is normal, from the curve discussion view.
  • SMOOTH the point is smooth, the first derivation from the curve discussion view.
  • CONTROL the point is a control point, to control the curve from the user interface.
  • SYMMETRIC the point is symmetric, the second derivation from the curve discussion view.
Geometry com.sun.star.drawing.PolyPolygonBezierCoords. These are the untransformed bezier coordinates of the polygon. The property has the same type as PolyPolygonBezier.

The next Java example will demonstrate how to create a ClosedBezierShape that looks like the following picture.

Closed bezier shape
  XShape xPolyPolygonBezier = createShape( xComponent, 0, 0, 0, 0,
      "com.sun.star.drawing.ClosedBezierShape");
  // take care of the fact that the shape must have been added
  // to the page before it is possible to apply changes
  XShapes xShapes = (XShapes)UnoRuntime.queryInterface( XShapes.class, xDrawPage);
  xShapes.add(xPolyPolygonBezier);
  // now it is possible to edit the PropertySet
  XPropertySet xShapeProperties = (XPropertySet)UnoRuntime.queryInterface(
      XPropertySet.class, xPolyPolygonBezier);
  // The following values are exemplary and provokes that a PolyPolygon of
  // sixteen single polygons containing four points each is created. The
  // PolyPolygon total point count will be 64.
  // If control points are used they are allowed to appear as pair only,
  // before and after such pair has to be a normal point.
  // A bezier point sequence may look like
  // this (n=normal, c=control) : n c c n c c n n c c n
  int nPolygonCount = 16;
  int nPointCount = 4;
  int nWidth = 10000;
  int nHeight = 10000;
  PolyPolygonBezierCoords aCoords = new PolyPolygonBezierCoords();
  // allocating the outer sequence
  aCoords.Coordinates = new Point[nPolygonCount][];
  aCoords.Flags = new PolygonFlags[nPolygonCount][];
  int i, n, nY;
 
  // fill the inner point sequence now
  for (nY = 0, i = 0; i < nPolygonCount; i++, nY += nHeight / nPolygonCount) {
      // create a polygon using two normal and two control points
      // allocating the inner sequence
      Point[] pPolyPoints = new Point[nPointCount];
      PolygonFlags[]pPolyFlags = new PolygonFlags[nPointCount];
      for (n = 0; n < nPointCount; n++)
          pPolyPoints[n] = new Point();
      pPolyPoints[0].X = 0;
      pPolyPoints[0].Y = nY;
      pPolyFlags [0] = PolygonFlags.NORMAL;
      pPolyPoints[1].X = nWidth / 2;
      pPolyPoints[1].Y = nHeight;
      pPolyFlags[1] = PolygonFlags.CONTROL;
      pPolyPoints[2].X = nWidth / 2;
      pPolyPoints[2].Y = nHeight;
      pPolyFlags [2] = PolygonFlags.CONTROL;
      pPolyPoints[3].X = nWidth;
      pPolyPoints[3].Y = nY;
      pPolyFlags [3] = PolygonFlags.NORMAL;
      aCoords.Coordinates[i] = pPolyPoints;
      aCoords.Flags[i] = pPolyFlags;
  }
  try {
      xShapeProperties.setPropertyValue("PolyPolygonBezier", aCoords);
  } catch (Exception ex)
  {
  }
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages