It derives from <GObject>.
A paintable implementation that renders SVG, with animations.
<GtkSvg> objects are created by parsing a subset of
SVG, including SVG animations.
<GtkSvg> fills or strokes paths with symbolic or fixed
colors. It can have multiple states, and paths can be included in a
subset of the states. States can have animations, and the transition
between different states can also be animated.
To show a static SVG image, it is enough to load the the SVG and use it like any other paintable.
To play an SVG animation, use svg:set-frame-clock to connect the paintable to a
frame clock, and call svg:play after loading the
SVG. The animation can be paused using svg:pause.
To set the current state, use svg:set-state.
Loading an SVG into <GtkSvg> will always produce a
(possibly empty) paintable. GTK will drop things that it can’t handle
and try to make sense of the rest.
To track errors during parsing or rendering, connect to the
svg:error signal.
For parsing errors in the GTK_SVG_ERROR domain, the functions
Gtk.SvgError.get_start, Gtk.SvgError.get_end,
svg-error:get-element and
svg-error:get-attribute can be used
to obtain information about where the error occurred.
The paintable supports much of SVG 2, with some exceptions.
Among the graphical elements, <textPath> and
<foreignObject> are not supported.
Among the structural elements, <a> and <view> are not
supported.
In the <filter> element, the following primitives are not
supported: feConvolveMatrix, feDiffuseLighting, feMorphology,
feSpecularLighting and feTurbulence.
Support for the mask attribute is limited to just a url referring
to the <mask> element by ID.
In animation elements, the parsing of begin and end
attributes is limited, and the min and max attributes are
not supported.
Lastly, there is only minimal CSS support (the style attribute, but not
<style>), and no interactivity.
The paintable supports a number of custom attributes that offer a convenient way to define states, transitions and animations. For example,
<circle cx=’5’ cy=’5’ r=’5’ gpa:states=’0 1’ gpa:animation-type=’automatic’ gpa:animation-direction=’segment’ gpa:animation-duration=’600ms’/>
defines the circle to be shown in states 0 and 1, and animates a segment of the circle.
<image src="svg-renderer1.svg">
Note that the generated animations are implemented using standard SVG
attributes (visibility, stroke-dasharray,
stroke-dashoffset‘, pathLength and filter). Setting
these attributes in your SVG is therefore going to interfere with
generated animations.
To connect general SVG animations to the states of the paintable, use
the custom gpa:states(...) condition in the begin and
end attributes of SVG animation elements. For example,
<animate href=’path1’ attributeName=’fill’ begin=’gpa:states(0).begin’ dur=’300ms’ fill=’freeze’ from=’black’ to=’magenta’/>
will make the fill color of path1 transition from black to magenta when the renderer enters state 0.
<image src="svg-renderer2.svg">
The gpa:states(...) condition triggers for upcoming state changes
as well, to support fade-out transitions. For example,
<animate href=’path1’ attributeName=’opacity’ begin=’gpa:states(0).end -300ms’ dur=’300ms’ fill=’freeze’ from=’1’ to=’0’/>
will start a fade-out of path1 300ms before state 0 ends.
A variant of the gpa:states(...) condition allows specifying both
before and after states:
<animate href=’path1’ attributeName=’opacity’ begin=’gpa:states(0, 1 2)’ dur=’300ms’ fill=’freeze’ from=’1’ to=’0’/>
will start the animation when the state changes from 0 to 1 or from 0 to 2, but not when it changes from 0 to 3.
In addition to the gpa:fill and gpa:stroke attributes,
symbolic colors can also be specified as a custom paint server
reference, like this: url(#gpa:warning). This works in
fill and stroke attributes, but also when specifying
colors in SVG animation attributes like to or values.
Note that the SVG syntax allows for a fallback RGB color to be specified after the url, for compatibility with other SVG consumers:
fill=’url(warning) orange’
In contrast to SVG 1.1 and 2.0, we allow the transform attribute
to be animated with <animate>.
Enabled features for this paintable.
Note that features have to be set before loading SVG data to take effect.
Its value is a <GtkSvgFeatures> (or, to set
it, a list of its symbols, or one of them).
Set it with (set! (svg:features self) value).
Whether the paintable is currently animating its content.
To set this property, use the svg:play and
svg:pause functions.
Its value is a boolean.
Set it with (set! (svg:playing self) value).
Resource to load SVG data from.
This property is meant to create a paintable from a resource in ui files.
Its value is a string, or #f.
Set it with (set! (svg:resource self) value).
The current state of the renderer.
This can be a number between 0 and 63.
Its value is an unsigned 32-bit integer.
Set it with (set! (svg:state self) value).
If not set to -1, this value overrides the weight used when rendering the paintable.
Its value is a real number.
Set it with (set! (svg:weight self) value).
Returns the currently enabled features.
Passed: a <GtkSvg>.
an SVG paintable
Returned: a <GtkSvgFeatures>.
the enabled features
Gets the current state of the paintable.
Passed: a <GtkSvg>.
an SVG paintable
Returned: an unsigned 32-bit integer.
the state
Returns a NULL-terminated array of state names, if available.
Note that the returned array and the strings contained in it will only
be valid until the <GtkSvg> is cleared or reloaded, so
if you want to keep it around, you should make a copy.
Passed: a <GtkSvg>.
an SVG paintable
Returned: a vector, each a string, or #f.
the state names
Returned: an unsigned 32-bit integer.
return location for the number of strings that are returned
Gets the value of the weight property.
Passed: a <GtkSvg>.
an SVG paintable
Returned: a real number.
the weight
Loads SVG content into an existing SVG paintable.
To track errors while loading SVG content, connect to the svg:error signal.
This clears any previously loaded content.
Loads SVG content into an existing SVG paintable.
To track errors while loading SVG content, connect to the svg:error signal.
This clears any previously loaded content.
Passed: a <GtkSvg>.
an SVG paintable
Passed: a string.
the resource path
Creates a new, empty SVG paintable.
Returned: a <GtkSvg>.
the paintable
Parses the SVG data in bytes and creates a paintable.
Parses the SVG data in the resource and creates a paintable.
Passed: a string.
the resource path
Returned: a <GtkSvg>.
the paintable
Stop any playing animations and state transitions.
Animations can be paused and started repeatedly.
Passed: a <GtkSvg>.
an SVG paintable
Start playing animations and state transitions.
Animations can be paused and started repeatedly.
Passed: a <GtkSvg>.
an SVG paintable
Serializes the content of the renderer as SVG.
The SVG will be similar to the orignally loaded one, but is not guaranteed to be 100% identical.
This function serializes the DOM, i.e. the results of parsing the SVG. It does not reflect the effect of applying animations.
Enables or disables features of the SVG paintable.
By default, all features are enabled.
Note that this call only has an effect before the SVG is loaded.
Passed: a <GtkSvg>.
an SVG paintable
Passed: a <GtkSvgFeatures>, or a list of its
symbols, or one of them.
features to enable
Sets a frame clock.
Without a frame clock, GtkSvg will not advance animations.
Passed: a <GtkSvg>.
an SVG paintable
Passed: a <GdkFrameClock>.
the frame clock
Sets the state of the paintable.
If the paintable is currently playing, the state change will apply transitions that are defined in the SVG. If the paintable is not playing, the state change will take effect instantaneously.
Passed: a <GtkSvg>.
an SVG paintable
Passed: an unsigned 32-bit integer.
the state to set, as a value between 0 and 63
Sets the weight that is used when rendering.
The weight affects the effective linewidth when stroking paths.
The default value of -1 means to use the font weight from CSS.
Passed: a <GtkSvg>.
an SVG paintable
Passed: a real number.
the font weight, as a value between -1 and 1000
Serializes the paintable, and saves the result to a file.
Passed: a <GtkSvg>.
an SVG paintable
Passed: a string.
the file to save to
Returned: a boolean.
true, unless an error occurred
Connect a handler with (connect object svg:error handler). It is
called as (handler self error).
Signals that an error occurred.
Errors can occur both during parsing and during rendering.
The expected error values are in the
<GtkSvgError> enumeration, context information
about the location of parsing errors can be obtained with the various
gtk_svg_error functions.
Parsing errors are never fatal, so the parsing will resume after the error. Errors may however cause parts of the given data or even all of it to not be parsed at all. So it is a useful idea to check that the parsing succeeds by connecting to this signal.
::: note This signal is emitted in the middle of parsing or rendering, and if you handle it, you must be careful. Logging the errors you receive is fine, but modifying the widget hierarchy or changing the paintable state definitively isn’t.
If in doubt, defer to an idle.