2.8 <GskRenderReplay>

Structure: <GskRenderReplay>

A facility to replay a <GskRenderNode> and its children, potentially modifying them.

This is a utility tool to walk a rendernode tree. The most powerful way is to provide a function via render-replay:set-node-filter to filter each individual node and then run render-replay:filter-node on the nodes you want to filter.

If you want to just walk the node tree and extract information without any modifications, you can also use render-node:get-children.

Here is a little example application that redacts text in a node file:

#include <gtk/gtk.h>

static GskRenderNode *
redact_nodes (GskRenderReplay *replay,
              GskRenderNode   *node,
              gpointer         user_data)
{
  GskRenderNode *result;

  if (gsk_render_node_get_node_type (node) == GSK_TEXT_NODE)
    {
      graphene_rect_t bounds;
      const GdkRGBA *color;

      gsk_render_node_get_bounds (node, &bounds);
      color = gsk_text_node_get_color (node);

      result = gsk_color_node_new (color, &bounds);
    }
  else
    {
      result = gsk_render_replay_default (replay, node);
    }

  return result;
}

int
main (int argc, char *argv[])
{
  GFile *file;
  GBytes *bytes;
  GskRenderNode *result, *node;
  GskRenderReplay *replay;

  gtk_init ();

  if (argc != 3)
    {
      g_print ("usage: %s INFILE OUTFILE\n", argv[0]);
      return 0;
    }

  file = g_file_new_for_commandline_arg (argv[1]);
  bytes = g_file_load_bytes (file, NULL, NULL, NULL);
  g_object_unref (file);
  if (bytes == NULL)
    return 1;

  node = gsk_render_node_deserialize (bytes, NULL, NULL);
  g_bytes_unref (bytes);
  if (node == NULL)
    return 1;

  replay = gsk_render_replay_new ();
  gsk_render_replay_set_node_filter (replay, redact_nodes, NULL, NULL);
  result = gsk_render_replay_filter_node (replay, node);
  gsk_render_replay_free (replay);

  if (!gsk_render_node_write_to_file (result, argv[2], NULL))
    return 1;

  gsk_render_node_unref (result);
  gsk_render_node_unref (node);

  return 0;
}

Procedures

Method: render-replay:default self node ⇒ %return
Method: default self node ⇒ %return

Replays the node using the default method.

The default method calls render-replay:filter-node on all its child nodes and the filter functions for all its properties. If none of them are changed, it returns the passed in node. Otherwise it constructs a new node with the changed children and properties.

It may not be possible to construct a new node when any of the callbacks return NULL. In that case, this function will return NULL, too.

self

Passed: a <GskRenderReplay>.

the replay

node

Passed: a <GskRenderNode>.

the node to replay

%return

Returned: a <GskRenderNode>, or #f.

The replayed node

Method: render-replay:filter-font self font ⇒ %return
Method: filter-font self font ⇒ %return

Filters a font using the current filter function.

self

Passed: a <GskRenderReplay>.

the replay

font

Passed: a <PangoFont>.

The font to filter

%return

Returned: a <PangoFont>.

the filtered font

Method: render-replay:filter-node self node ⇒ %return
Method: filter-node self node ⇒ %return

Replays a node using the replay’s filter function.

After the replay the node may be unchanged, or it may be removed, which will result in #f being returned.

If no filter node is set, render-replay:default is called instead.

self

Passed: a <GskRenderReplay>.

the replay

node

Passed: a <GskRenderNode>.

the node to replay

%return

Returned: a <GskRenderNode>, or #f.

The replayed node

Method: render-replay:filter-texture self texture ⇒ %return
Method: filter-texture self texture ⇒ %return

Filters a texture using the current filter function.

self

Passed: a <GskRenderReplay>.

the replay

texture

Passed: a <GdkTexture>.

The texture to filter

%return

Returned: a <GdkTexture>.

the filtered texture

Method: render-replay:free self
Method: free self

Frees a <GskRenderReplay>.

self

Passed: a <GskRenderReplay>.

the replay object to free

Procedure: render-replay:new ⇒ %return

Creates a new replay object to replay nodes.

%return

Returned: a <GskRenderReplay>.

A new replay object to replay nodes

Method: render-replay:set-font-filter self [filter]
Method: set-font-filter self [filter]

Sets a filter function to be called by render-replay:default for nodes that contain fonts.

You can call GskRenderReplay.filter_font to filter a font yourself.

self

Passed: a <GskRenderReplay>.

the replay

filter

Passed, or left out: a procedure, or #f.

the font filter function

See GskRenderReplayFontFilter for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to filter

user-destroy

Not passed: guile-gi supplies it.

destroy notify that will be called to release the user data parameter

See GDestroyNotify for how it is called.

Method: render-replay:set-node-filter self [filter]
Method: set-node-filter self [filter]

Sets the function to use as a node filter.

This is the most complex function to use for replaying nodes. It can either:

  • keep the node and just return it unchanged
  • create a replacement node and return that
  • discard the node by returning NULL
  • call render-replay:default to have the default handler run for this node, which calls your function on its children
self

Passed: a <GskRenderReplay>.

filter

Passed, or left out: a procedure, or #f.

the function to call to replay nodes

See GskRenderReplayNodeFilter for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to func

user-destroy

Not passed: guile-gi supplies it.

destroy notify that will be called to release the user data parameter

See GDestroyNotify for how it is called.

Method: render-replay:set-texture-filter self [filter]
Method: set-texture-filter self [filter]

Sets a filter function to be called by render-replay:default for nodes that contain textures.

You can call GskRenderReplay.filter_texture to filter a texture yourself.

self

Passed: a <GskRenderReplay>.

the replay

filter

Passed, or left out: a procedure, or #f.

the texture filter function

See GskRenderReplayTextureFilter for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to filter

user-destroy

Not passed: guile-gi supplies it.

destroy notify that will be called to release the user data parameter

See GDestroyNotify for how it is called.