Reference for the Mosaic class Graphics::SVG
|
The class Graphics::SVG provides functionality to store Scalable Vector Graphics (SVG) determined at the runtime of the application, it means the content is mutable. SVG is an XML-based vector image format for defining two-dimensional graphics. This content can thereupon be displayed by Views::SVG view or it can be rasterized inside an off-screen bitmap Graphics::SVGBitmap.
To specify the SVG content, simply assign the corresponding XML text as string to the property SVGString. The XML content is thereupon parsed and all associated views or SVG Bitmap objects are notified to update their appearance.
As soon as the evaluation is finished, a signal is sent to a slot method specified in the property OnUpdate. If the evaluation failed due to errors in the XML text, an additional signal is sent to the slot method stored in the property OnError. To query the status of the evaluation the methods GetSVGParserStatus() and GetSVGParserErrorPos() are available.
Since the content of SVG is scalable, this class provides a method CalcSize() to estimate the resulting size of the SVG image to fit inside a given area. This calculation involves 'width', 'height' and 'viewBox' attributes found inside the SVG content and it respects the aspect ratio of the SVG content.
method int32 GetSVGParserErrorPos();
The method GetSVGParserErrorPos() returns the position within the SVG XML text specified in the property SVGString at which an error (XML error, syntax error or out of memory error) has been encountered. The returned value indicates the character number within the string starting with the value 0 for the first character. If there is no error in the SVG XML text detected, or the error is not related to a position within the text, the method returns -1.
method Graphics::SVGParserStatus GetSVGParserStatus();
The method GetSVGParserStatus() returns the evaluation status of the XML text stored as string in the property SVGString. If the returned status indicates an error in the XML text, the position of the error can be queried using the method GetSVGParserErrorPos().
property slot OnError = null;
The property 'OnError' can refer to a slot method which will receive a signal when the evaluation of the SVG XML text specified in the property SVGString has failed for whatever reason.
To query the error code and the error position use the methods GetSVGParserStatus() and GetSVGParserErrorPos(). Please note, if the evaluation failed due to an error, the SVG content may be incomplete or empty depending on the location where the error was encountered.
property slot OnUpdate = null;
The property 'OnUpdate' can refer to a slot method which will receive a signal when the content of the SVG object has changed. This signal is sent regardless of the results of the SVG XML text evaluation.
To query the success of the evaluation use the method GetSVGParserStatus(). To directly react in case of an error you can assign the slot method to the property OnError. Please note, if the evaluation failed due to an error, the SVG content may be incomplete or empty depending on the location where the error was encountered.
property string SVGString = "";
The property 'SVGString' determines the SVG content as XML text. Changing this property causes the just assigned string to be evaluated as XML text. From this evaluation result SVG elements and their attributes relevant for the appearance of the SVG image.
As soon as the evaluation is finished, a signal is sent to a slot method specified in the property OnUpdate and all associated views and SVG Bitmap objects are notified to update their appearance.
If the evaluation failed due to errors in the XML text, an additional signal is sent to the slot method stored in the property OnError. Please note, depending on the error, the resulting SVG content may be incomplete or empty in such case.