Vector graphics in FastReport.Net 2019.4. Script
In the first part of the article we reviewed the innovations of FastReport.Net 2019.4 in terms of vector graphics. Now polylines and polygons can be constructed by Bezier curves. In this article, we will consider the possibility of creating curves using a report script.
Currently there are two ways to create curves from code: use a PolyLineObject object or load a polygon from an SVG.
As you know, any report object is available in the report script, so we can use PolyLineObject to set points and connect them to create a shape. Run the code before displaying the object, which means you need to create a BeforePrint event handler for the Polygon object. Let's look at a real example.
Add a Polygon object to the report page. In order not to create key points of the shape, just press Esc. In the object property inspector select Events. Create a BeforePrint event handler:
Let's write the following code in the handler:
As a result, we get a star:
In the example above, we calculated the coordinates to build the shape, but if you already have a list of coordinates, then simply add them to the collection of points: points.Add(new PolyLineObject.PolyPoint(x, y));
But what if the shape is much more complicated than the example above? The amount of code to create it will be too large. In this case, you can use the object SVG. For example, its path property. We can convert a set of elements of the svg image path into points and build a polygon using them. It is important to consider Bezier curves. How to do this, you will see below in the code:
This code will show us a star of this type:
In the list of type SvgPathSegmentList we place elements from the path tag of the SVG file. Then, we obtain the coordinates of the points and add them to the PolyLine object. In this example, we have displayed the object in straight line segments, but you can also use curves, for example:
SvgPathSegmentList list = builder.ConvertFromString ("m101.87775,57.26873c31.12829,-82.10042 153.08994,0 0,105.55768c-153.08994,-105.55768 -31.12829,-187.65809 0,-105.55768z") as SvgPathSegmentList;
As a result, we get:
It is necessary to take into account that the coordinate plane is the band on which the Polyline or Polygon object is located. Therefore, it does not matter where in the band you placed the object. It will be displayed according to the specified coordinates.
Using the second method we considered creating a polygon from a script, you will be able to display the previously created vector drawings. There is no need to spend a lot of time manually creating a polygon.