Scalable Vector Graphics (SVG)
Views supports Scalable Vector Graphics (SVG). SVG is an XML-based vector image format for defining two-dimensional graphics.
Currently supported SVG features listed below:
-
Basic Shapes
-
Basic transformations
-
Units
-
Solid colors filling and stroking
-
Linear gradient
-
Radial gradient
-
Pattern
-
Mask
-
Clip path
-
Style sheet
-
Basic Image support
-
Basic Text support
Packaging
SVG core library (ilvsvgcore) and SVG bitmap streamer (ilvsvg).
API
Current SVG API:
-
IlvSVGStreamer class (ilviews/bitmaps/svg.h)
-
IlvSVGImporter class (ilviews/svg/IlvSVGImporter.h)
-
IlvSVGDevice class (ilviews/svg/IlvSVGDevice.h)
SVG Renderer
ilsvg library provides IlvSVGStreamer class for rendering SVG images so that SVG images can be used in the same way as PNGs or JPGs in Views applications.
SVG images used in scaling contexts, for example IlvZoomableTransparentIcon or CSS background), are rendered without loss of quality.
ilvsvg library depends on Cairo rendering library on Linux and GDI+ rendering library on Windows.
SVG Importer
ilsvgcore library provides IlvSVGImporter class for importing SVG shapes to Views graphics objects. The table below describes importing rules:
SVG element | stroke | fill |
---|---|---|
<rect> | IlvRectangle | IlvFilledRectangle |
<rect> with round corners | IlvRoundRectangle | IlvFilledRoundRectangle |
<circle> | IlvEllipse | IlvFilledEllipse |
<ellipse> | IlvEllipse | IlvFilledEllipse |
<line> | IlvLine | |
<polyline> | IlvPolyline | IlvPolygon |
<polygon> | IlvPolyline | IlvPolygon |
<path> | IlvSpline/IlvClosedSpline | IlvFilledSpline |
<text> | IlvZoomableLabel | |
<image> | IlvZoomableTransparentIcon |
Imported Views elements are grouped in an IlvGraphicSet if the SVG element is a complex path or SVG element has both a stroke and a fill.
SVG Exporter
Ilvsvgcore library provides the IlvSVGDevice class that allows you to export any selected region of a view to a text file in SVG format.
Like the IlvPSDevice, IlvSVGDevice is also derived from the IlvPort and redirects the drawing operations to an SVG dump during drawing.
It ensures that the output matches the expected visual result by automatically translating the drawing operations into the appropriate SVG code.
This makes it easy to save graphical content as a scalable vector graphic.
Limitation
The ilvsvg library is shipped only in shared library mode (dll_mda on Windows and shared on Linux).
Sample application
Refer to the SVG sample applications in $ILVHOME/samples/foundation/svg
Security notes
Views SVG lib has checks to prevent freezes (endless loops) and stack overflows caused due to recursion.
However, as processing SVG files can involve interpreting user-supplied code, it is recommended to use only trusted SVG files as input.