Graphics::Potrace::Vectorial::Exporter - vectorial exporter base class for Graphics::Potrace
This is a base class for building up vector exporters. One example of using this base class is shipped directly in the distribution as Graphics::Potrace::Vectorial::Svg.
You only need override one of two methods in order to implement your exporter: either "render" or "save".
Both receive a list of vectors to be rendered,
but are expected to behave differently: the former should return a textual representation of the exported stuff (e.g.
text containing the full contents of a SVG document),
the latter is supposed to
In this class these two methods are both defined in terms of the other, so that you can really override only one of them and get the other one for free.
One additional method that you can find useful is "boundaries": it will return the maximum width and height across the full list of vectors,
so that you can size the dimensions of your output representation properly (e.g.
height attributes in the
svg outer element).
Exporters deriving from this base class accept two different parameters for setting where the export can be performed: "fh" and "file". So you will always be able to call "create_exporter" in Graphics::Potrace::Vectorial like this:
my $e1 = $vector->create_exporter($type, file => $filename); my $e2 = $vector->create_exporter($type, file => \my $text); my $e3 = $vector->create_exporter($type, fh => $filehandle);
my ($width, $height) = $exporter->boundaries(@vectors);
This function returns the maximum width and height across the list of provided vectors. These should be Graphics::Potrace::Vectorial elements, but anything providing both
height methods will do.
Clear the value for the file, see "file".
Clear the value for the filehandle, see "fh".
my $other_exporter = $exporter->clone();
Create a replica of the exporter object. It does this by calling
new passing all the parameters already present, so you can override it if your needs are more sophisticated. Used by the default provided "render" in order to avoid clobbering the main object.
$exporter->file($filename); # some file in the filesystem $exporter->file(\my $text); # a variable to save to my $current = $exporter->file(); # getter
$exporter->fh($filehandle); my $fh = $exporter->fh();
Accessor to get/set a filehandle where "save" will send data.
It is automatically (and lazily) populated when you call the getter, so this will change what
has_fh will tell you (see "has_fh" for details).
Calling the getter will generate an exception if neither
file are set (you can test it with
$exporter->has_file() and print "has it!\n";
$exporter->has_fh() and print "has it!\n";
Returns a boolean value depending on the immediate availability of a filehandle for "save".
Note that a filehandle might be available to "save" even though the value returned is false, because it might be automatically populated in case there is a file (see "has_file" and "file"). This means that
has_fh might return different values depending on the evolution:
my $e = Graphics::Potrace::Vectorial::Exporter->new(); print "has it!\n" if $e->has_fh(); # does NOT print $e->file('/dev/null'); print "has it!\n" if $e->has_fh(); # does NOT print, again my $fh = $e->fh(); # opens "file" and sets the fh print "has it!\n" if $e->has_fh(); # does print now!
my $e = Graphics::Potrace::Vectorial::Exporter->new(%args);
Constructor, input arguments can be
fh passed in a key-value style.
my $text = $exporter->render(@vectors);
Produce a rendering of the provided
@vectors, e.g. the SVG document as a text in case of SVG. This method in this package uses "save" to do the heavy lifting, so you either have to override it or "save".
Flavio Poletti <email@example.com>
Copyright (C) 2011 by Flavio Poletti firstname.lastname@example.org.
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.