Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: SvgCtors

[534:14] static extends: object

Alternate constructors for Svg. Usage: SvgCtors.<name>(...). The primary constructor lives directly on Svg.

Methods

  • newFromBytes (object bytes)

    Parses the SVG data in @bytes and creates a paintable.

    • @p bytes is the data.
    • @r A new Svg.
  • newFromResource (string path)

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

    • @p path is the resource path.
    • @r A new Svg.

class: SvgMeta

[635:14] static extends: object

Generated metadata helpers for Svg class surfaces.

Methods

  • properties ()

    Returns property metadata for Svg.

    • @r A list.
  • signals ()

    Returns signal metadata for Svg.

    • @r A list.

class: Svg

[71:7] extends: object

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 [method@Gtk.Svg.set_frame_clock] to connect the paintable to a frame clock, and call [method@Gtk.Svg.play] after loading the SVG. The animation can be paused using [method@Gtk.Svg.pause]. To set the current state, use [method@Gtk.Svg.set_state]. ## 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 during parsing or rendering, connect to the [signal@Gtk.Svg::error] signal. For parsing errors in the GTK_SVG_ERROR domain, the functions [func@Gtk.SvgError.get_start], [func@Gtk.SvgError.get_end], [func@Gtk.SvgError.get_element] and [func@Gtk.SvgError.get_attribute] can be used to obtain information about where the error occurred. ## The supported subset of SVG The paintable supports much of SVG 2, including animations, with some exceptions. Among the graphical elements, <textPath> and <foreignObject> 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. The interactive aspects of SVG are supported by [class@Gtk.SvgWidget]. ## SVG Extensions The paintable supports a number of custom attributes that offer a convenient way to define states, transitions and animations. For example, defines the circle to be shown in states 0 and 1, and animates a segment of the circle. Note that the generated animations are implemented using standard SVG attributes (visibility, stroke-dasharray, stroke-dashoffset, pathLengthandfilter). 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 StateChange(...)condition in thebeginandendattributes of SVG animation elements. For example, <animate href='path1' attributeName='fill' begin='StateChange(1 2 3, 0)' 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 from states 1, 2, or 3. <image src="svg-renderer2.svg"> TheStateChange(...)condition triggers for upcoming state changes as well, to support fade-out transitions. For example, <animate href='path1' attributeName='opacity' begin='StateChange(0, 1 2 3) -300ms' dur='300ms' fill='freeze' from='1' to='0'/> will start a fade-out of path1 300ms before a transition from state 0 to 1, 2 or 3. In addition to thegpa:fillandgpa:strokeattributes, symbolic colors can also be specified as a custom paint server reference, like this:url(#gpa:warning). This works in fillandstrokeattributes, but also when specifying colors in SVG animation attributes liketoorvalues. 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' GtkSvg also allows to refer to symbolic colors like system colors in CSS, with names like SymbolicForeground, SymbolicSuccess, etc. These can be used whenever a color is required. In contrast to SVG 1.1 and 2.0, we allow the transformattribute to be animated with`.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • Svg ()

    Creates a new, empty SVG paintable.

  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asObject ()

    Wraps this handle as Object.

    • @r A Object object.
  • asPaintable ()

    Wraps this handle as Paintable.

    • @r A Paintable object.
  • asSymbolicPaintable ()

    Wraps this handle as SymbolicPaintable.

    • @r A SymbolicPaintable object.
  • connectSignal (string Name, CallbackObj)

    Connects one generated callback wrapper to a named signal.

    • @p Name is the signal name.
    • @p CallbackObj is the generated callback wrapper to connect.
    • @r The connected handler id.
  • disconnectSignalHandler (int HandlerId)

    Disconnects one retained signal handler id.

    • @p HandlerId is the signal handler id to disconnect.
    • @r None.
  • setOnError (callback Fn, UserData = null)

    Signals that an error occurred. Errors can occur both during parsing and during rendering. The expected error values are in the [error@Gtk.SvgError] 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.

    • @p Fn is the Aussom callback.
    • @p Fn is called with (Svg Self, Error Error).
    • @p UserData is retained and passed through to the generated callback wrapper when provided.
    • @r The connected handler id.
  • getProperty (string Name)

    Reads one generated property by name.

  • setProperty (string Name, Value)

    Writes one generated property by name.

  • setFeatures (string Value)

    Enabled features for this paintable. Note that features have to be set before loading SVG data to take effect.

    • @p Value is the new property value.
    • @r None.
  • setOverflow (string Value)

    Whether the rendering will be clipped to the bounds.

    • @p Value is the new property value.
    • @r None.
  • setPlaying (bool Value)

    Whether the paintable is currently animating its content. To set this property, use the [method@Gtk.Svg.play] and [method@Gtk.Svg.pause] functions.

    • @p Value is the new property value.
    • @r None.
  • setResource (string Value)

    Resource to load SVG data from. This property is meant to create a paintable from a resource in ui files.

    • @p Value is the new property value.
    • @r None.
  • setState (int Value)

    The current state of the renderer. This can be a number between 0 and 63.

    • @p Value is the new property value.
    • @r None.
  • setStylesheet (object Value)

    A CSS stylesheet to apply to the SVG.

    • @p Value is the new property value.
    • @r None.
  • setWeight (double Value)

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

    • @p Value is the new property value.
    • @r None.
  • get_features ()

    Returns the currently enabled features.

  • get_overflow ()

    Gets the current overflow value.

  • get_state ()

    Gets the current state of the paintable.

  • get_stylesheet ()

    Gets the CSS user stylesheet.

  • get_weight ()

    Gets the value of the weight property.

  • load_from_bytes (object bytes)

    Loads SVG content into an existing SVG paintable. To track errors while loading SVG content, connect to the [signal@Gtk.Svg::error] signal. This clears any previously loaded content.

    • @p bytes is the data to load.
    • @r None.
  • load_from_resource (string path)

    Loads SVG content into an existing SVG paintable. To track errors while loading SVG content, connect to the [signal@Gtk.Svg::error] signal. This clears any previously loaded content.

    • @p path is the resource path.
    • @r None.
  • pause ()

    Stop any playing animations and state transitions. SvgAnimations can be paused and started repeatedly.

    • @r None.
  • play ()

    Start playing animations and state transitions. SvgAnimations can be paused and started repeatedly.

    • @r None.
  • serialize ()

    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.

  • set_features (string features)

    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.

    • @p features is features to enable.
    • @r None.
  • set_frame_clock (object clock)

    Sets a frame clock. Without a frame clock, GtkSvg will not advance animations.

    • @p clock is the frame clock.
    • @r None.
  • set_overflow (string overflow)

    Sets whether the rendering will be clipped to the bounds. Clipping is expected for [iface@Gdk.Paintable] semantics, so this property should not be changed when using a GtkSvg as a paintable.

    • @p overflow is the new overflow value.
    • @r None.
  • set_state (int state)

    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.

    • @p state is the state to set, as a value between 0 and 63.
    • @r None.
  • set_stylesheet (object bytes)

    Sets a CSS user stylesheet to use. Note that styles are applied at load time, so this function must be called before loading SVG.

    • @p bytes is CSS data.
    • @r None.
  • set_weight (double weight)

    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.

    • @p weight is the font weight, as a value between -1 and 1000.
    • @r None.
  • write_to_file (string filename)

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

    • @p filename is the file to save to.

class: SvgErrorCallback

[564:7] extends: object

Generated low-level callback wrapper for GIR callback error.

Members

  • callbackObj
  • userFn
  • userData
  • hasUserData

Methods

  • SvgErrorCallback (callback Fn, UserData = null)

    Creates one native callback wrapper. The wrapper owns a trampoline that converts native pointers into generated wrapper objects before invoking Fn.

    • @p Fn is the Aussom callback implementation.
    • @p UserData is retained and passed through to Fn on each invocation when provided.
  • trampoline (nativeSelf, error, nativeUserData)

    Internal trampoline. Converts native pointer arguments into generated wrapper instances, then invokes the user's callback.

  • callback ()

    Returns the wrapped NativeCallback.

  • handle ()

    Returns the callback as a NativeHandle.

  • close ()

    Closes the underlying NativeCallback.

  • isClosed ()

    Returns true when the callback has been closed.