Provides support for parsing and rendering SVG files.
The SVG class provides support for parsing SVG statements into a scene graph that consists of Vector objects and related constructs. The generated scene graph is accessible via the Scene and Viewport fields.
It is possible to parse SVG documents directly to the UI. Set the Target field with a vector to contain the SVG content and it will be structured in the existing scene graph.
Please refer to the W3C documentation on SVG for a complete reference to the attributes that can be applied to SVG elements.
The SVG class consists of the following fields:
Access | Name | Type | Comment | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Colour | STRING | Defines the default fill to use for currentColor references. | |||||||||
Set the Colour value to alter the default fill that is used for | |||||||||||
Flags | SVF | Optional flags. | |||||||||
| |||||||||||
Frame | INT | Forces the graphics to be drawn to a specific frame. | |||||||||
If this field is set to a valid frame number, the vector graphics will only be drawn when the frame of the container matches the Frame number in this field. When set to 0 (the default), the Vector will be drawn regardless of the container's frame number. | |||||||||||
FrameCallback | FUNCTION | Optional callback that is triggered whenever a new frame is prepared. | |||||||||
Referencing a function in this field will allow the client to receive a callback after the preparation of each animation frame (if the SVG object is being animated). This feature is commonly used to render the SVG document to a target Bitmap. Note that if the SVG document does not make use of any animation features then the function will never be called. The function prototype is | |||||||||||
FrameRate | INT | The maximum frame rate to use when animating a vector scene. | |||||||||
This field defines the maximum frame rate that will be used when a vector scene is animated. It is recommended that a value between 50 and 100 is used. It is important to note that while higher frame rates produce smoother animations, they also increase the CPU usage proportionately. For instance, a frame rate of 100 will use the CPU twice as much as a frame rate of 50. This will subsequently have an effect on power consumption. The recommended frame rate is 60, as this will match the majority of modern displays. | |||||||||||
Path | STRING | A path referring to an SVG file. | |||||||||
SVG data can be loaded from a file source by setting the Path field to an SVG file. | |||||||||||
Scene | OBJECTPTR | The VectorScene that manages the Target object is referenced here. | |||||||||
The Scene is a read-only field that assists in quickly finding the VectorScene that owns the Target object. | |||||||||||
Statement | STRING | A string containing SVG data. | |||||||||
SVG data can be loaded from a string by specifying it here prior to initialisation. If the Path field has been defined, it will take precedent and the Statement is ignored. Alternatively the DataFeed() action can be used to parse data on-the-fly after the SVG object is initialised. | |||||||||||
Target | OBJECTPTR | The container object for new SVG content can be declared here. | |||||||||
During the normal initialisation process, a new VectorViewport is created to host the SVG scene graph. By default, the viewport and its content is strictly owned by the SVG object unless a Target is defined to redirect the scene graph elsewhere. The provided Target can be any object class, as long as it forms part of a scene graph owned by a VectorScene object. It is recommended that the chosen target is a VectorViewport. The use of a Target will make the generated scene graph independent of the SVG object. Consequently, it is possible to terminate the SVG object without impacting the resources it created. If tracking back to the SVG object is still required, use the | |||||||||||
Title | STRING | The title of the SVG document. | |||||||||
The title of an SVG document is declared with a title element that can embedded anywhere in the document. In cases where a title has been specified, it will be possible to read it from this field. If no title is in the document then | |||||||||||
Viewport | OBJECTPTR | Returns the first viewport created by an SVG document. | |||||||||
This field simplifies the process of finding the first VectorViewport that was created by a loaded SVG document. |
The following actions are currently supported:
Name | Comment | |||||||
---|---|---|---|---|---|---|---|---|
Activate | Initiates playback of SVG animations. | |||||||
ERR acActivate(*Object) SVG documents that use animation features will remain static until they are activated with this action. The animation code will be processed in the background at the pre-defined FrameRate. The Scene will be redrawn automatically as each frame is processed. The client can hook into the animation cycle by setting the FrameCallback with a suitable function. | ||||||||
Deactivate | Stops all playback of SVG animations. | |||||||
Init | Initialise the SVG object. | |||||||
ERR InitObject(*Object) Initialising an SVG object will load an SVG source file if a Path has been specified. The default behaviour is to generate the content in a local Scene object, or alternatively the content can be redirected to an external VectorScene referred to by Target. | ||||||||
SaveImage | Saves the SVG document as a PNG image. | |||||||
ERR acSaveImage(*Object, OBJECTID Dest, CLASSID ClassID)
This action will render the SVG document to a bitmap and save the resulting image. The size of the image is determined by the VectorScene⇒PageWidth and VectorScene⇒PageHeight of the Scene, or if not defined, the default of 1920x1080 is applied. The image will be saved in PNG format by default, but can be changed by specifying an alternate | ||||||||
SaveToObject | Saves the SVG document to a data object. | |||||||
ERR acSaveToObject(*Object, OBJECTID Dest, CLASSID ClassID)
|
The following methods are currently supported:
Name | Comment | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ParseSymbol | Generate a vector scene graph from an SVG symbol, targeting a viewport. | ||||||||||||
ERR svg::ParseSymbol(OBJECTPTR Object, CSTRING ID, objVectorViewport * Viewport)
ParseSymbol() allows the symbols of a loaded SVG document to be processed post-initialisation. This is useful for utilising symbols in a way that is akin to running macros as required by the program. The | |||||||||||||
Render | Render the scene to a target Bitmap. | ||||||||||||
ERR svg::Render(OBJECTPTR Object, objBitmap * Bitmap, LONG X, LONG Y, LONG Width, LONG Height)
This method will render the vector scene directly to a target bitmap at coordinates |
SVG flags.
Name | Description |
---|---|
SVF::ALPHA | Generate an alpha channel in the rendered image. |
SVF::AUTOSCALE | In auto-resize mode, vector dimensions are scaled to the width and height of the vector page. The VectorScene⇒PageWidth and VectorScene⇒PageHeight must be set for this. |
SVF::ENFORCE_TRACKING | Enforce tracking of definition objects when a Target is used. |
Class Info | |
---|---|
ID | ID_SVG |
Category | GUI |
Include | modules/svg.h |
Version | 1 |