Class

GtkSvg

unstable since: 4.22

Description [src]

final class Gtk.Svg : GObject.Object
  implements Gdk.Paintable, Gtk.SymbolicPaintable {
  /* No available fields */
}

A paintable implementation that renders (a subset of) SVG, with animations.

GtkSvg objects are created by parsing a subset of SVG, including SVG animations.

The 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. The special ‘empty’ state is always available. States can have animation, and the transition between different states can also be animated.

To find out what states a GtkSvg has, use gtk_svg_get_n_states(). To set the current state, use gtk_svg_set_state().

SVG Extensions

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.

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.

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(gpa:#warning) orange'

In contrast to SVG 1.1 and 2.0, we allow the transform attribute to be animated with <animate>.

The supported subset of SVG

The renderer does not support text or images, only paths. From the shape elements of SVG, only <circle>, <ellipse>, <rect> and <path> are supported, leaving out <line>, <polyline> and <polygon>.

In <defs>, only <clipPath>, <mask> and shapes are supported, not <filter>, gradients or other things.

The support for filters is limited to filter functions minus drop-shadow() plus a custom alpha-level() function, which implements one particular case of feComponentTransfer.

The transform-origin and transform-box attributes are not supported.

The 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 by, min and max attributes are not supported.

Lastly, there is no CSS support, and no interactivity.

Error handling

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, connect to the GtkSvg::error signal.

For errors in the GTK_SVG_ERROR domain, the functions gtk_svg_error_get_start(), gtk_svg_error_get_end(), gtk_svg_error_get_element() and gtk_svg_error_get_attribute() can be used to obtain information about where the error occurred.

Available since: 4.22

Hierarchy

hierarchy this GtkSvg implements_0 GdkPaintable this--implements_0 implements_1 GtkSymbolicPaintable this--implements_1 ancestor_0 GObject ancestor_0--this

Ancestors

Constructors

gtk_svg_new

Creates a new, empty SVG paintable.

unstable since: 4.22

gtk_svg_new_from_bytes

Parses the SVG data in bytes and creates a paintable.

unstable since: 4.22

gtk_svg_new_from_resource

Parses the SVG data in the resource and creates a paintable.

unstable since: 4.22

Instance methods

gtk_svg_get_n_states

Gets the number of states defined in the SVG.

unstable since: 4.22

gtk_svg_get_state

Gets the current state of the paintable.

unstable since: 4.22

gtk_svg_get_weight

Gets the value of the weight property.

unstable since: 4.22

gtk_svg_load_from_bytes

Loads SVG content into an existing SVG paintable.

unstable since: 4.22

gtk_svg_pause

Stop any playing animations.

unstable since: 4.22

gtk_svg_play

Start playing animations.

unstable since: 4.22

gtk_svg_serialize

Serializes the content of the renderer as SVG.

unstable since: 4.22

gtk_svg_set_frame_clock

Sets a frame clock.

unstable since: 4.22

gtk_svg_set_state

Sets the state of the paintable.

unstable since: 4.22

gtk_svg_set_weight

Sets the weight that is used when rendering.

unstable since: 4.22

gtk_svg_write_to_file

Serializes the paintable, and saves the result to a file.

unstable since: 4.22

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Methods inherited from GdkPaintable (9)
gdk_paintable_compute_concrete_size

Compute a concrete size for the GdkPaintable.

gdk_paintable_get_current_image

Gets an immutable paintable for the current contents displayed by paintable.

gdk_paintable_get_flags

Get flags for the paintable.

gdk_paintable_get_intrinsic_aspect_ratio

Gets the preferred aspect ratio the paintable would like to be displayed at.

gdk_paintable_get_intrinsic_height

Gets the preferred height the paintable would like to be displayed at.

gdk_paintable_get_intrinsic_width

Gets the preferred width the paintable would like to be displayed at.

gdk_paintable_invalidate_contents

Called by implementations of GdkPaintable to invalidate their contents.

gdk_paintable_invalidate_size

Called by implementations of GdkPaintable to invalidate their size.

gdk_paintable_snapshot

Snapshots the given paintable with the given width and height.

Methods inherited from GtkSymbolicPaintable (2)
gtk_symbolic_paintable_snapshot_symbolic

Snapshots the paintable with the given colors.

since: 4.6

gtk_symbolic_paintable_snapshot_with_weight

Snapshots the paintable with the given colors and weight.

unstable since: 4.22

Properties

Gtk.Svg:playing

Whether the paintable is currently animating its content.

unstable since: 4.22

Gtk.Svg:resource

Construct-only property to create a paintable from a resource in ui files.

unstable since: 4.22

Gtk.Svg:state

The current state of the renderer.

unstable since: 4.22

Gtk.Svg:weight

If not set to -1, this value overrides the weight used when rendering the paintable.

unstable since: 4.22

Signals

Gtk.Svg::error

Signals that an error occurred.

unstable since: 4.22

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Signals inherited from GdkPaintable (2)
GdkPaintable::invalidate-contents

Emitted when the contents of the paintable change.

GdkPaintable::invalidate-size

Emitted when the intrinsic size of the paintable changes.

Class structure

struct GtkSvgClass {
  GObjectClass parent_class;
  
}

No description available.

Class members
parent_class: GObjectClass

No description available.