Lutz Gehlen
and 2 contributors

NAME

SVG::Rasterize::TextNode - workaround to represent a text node

VERSION

Version 0.003002

DESCRIPTION

The Problem

According to the DOM specification which SVG::Rasterize uses to traverse SVG document trees, basically everything is a node including simple text. This means that if an SVG element contains text (e.g. a text or tspan element), the getChildNodes method is supposed to return not only the child elements, but also the character data (i.e. text) sections in this list of nodes. However, the getChildNodes method of the SVG::Element class in the SVG distribution only returns the child elements, no character data section.

SVG::Rasterize tries to support not only SVG object trees, but also DOM trees created by a generic XML parser. Due to the behaviour described above, these two scenarios have to be treated differently.

The Solution (or Workaround)

This class acts as a drop-in for a SVG node class representing a character data node. When parsing a SVG object tree, character data of the relevant elements are stored in such an object and pushed to the list of child nodes. Afterwards, the object tree can be accessed uniformly.

This process does not get around the problem that in an SVG::Element object cannot hold multiple character data sections and that it cannot store the order of such sections and child elements. However, this problem can only be solved within the SVG distribution (see RT#58153).

INTERFACE

The interface only implements (apart from the constructor) the minimal requirements of SVG::Rasterize, e.g. the following methods:

new

  $node = SVG::Rasterize::TextNode->new(%args)

Creates a new SVG::Rasterize::TextNode object and calls init(%args). If you subclass SVG::Rasterize::TextNode overload init, not new.

Supported arguments:

  • data (mandatory): a SCALAR as defined by Params::Validate, containing the text data.

init

See new for a description of the interface. If you overload init, your method should also call this one.

getNodeName

Returns #text.

getAttributes

Returns undef.

getChildNodes

Returns undef.

getData

Returns the text.

SEE ALSO

AUTHOR

Lutz Gehlen, <perl at lutzgehlen.de>

LICENSE AND COPYRIGHT

Copyright 2010 Lutz Gehlen.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.