Flavio Poletti > Graphics-Potrace-0.1.0_03 > Graphics::Potrace::Vectorial

Download:
Graphics-Potrace-0.1.0_03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.1.0_03   Source   Latest Release: Graphics-Potrace-0.73

NAME ^

Graphics::Potrace::Vectorial - vectorial manipulator for Graphics::Potrace

VERSION ^

version 0.1.0_03

SYNOPSIS ^

   # See Graphics::Potrace for ways of obtaining a G::P::Vectorial

   # Get a Svg representation in a scalar variable
   my $svg = $vector->render('Svg');

   # Save Encapsulated Postscript to file
   $vector->export(Eps => file => '/tmp/foo.eps');

   # Need to fiddle with the internals?
   my $width = $vector->width();
   my $height = $vector->height();
   for my $group (@{$vector->list()}) {
      printf "group, sign: %s\n", $group->{sign};
      my $curve = $group->{curve};
      for my $segment (@$curve) {
         printf "begin: %lf %lf\n", @{$segment->{begin}};
         if ($segment->{type} eq 'bezier') {
            printf "u: %lf %lf\n", @{$segment->{u}};
            printf "v: %lf %lf\n", @{$segment->{v}};
         }
         else { # type is corner
            printf "corner: %lf %lf\n", @{$segment->{corner}};
         }
         printf "end: %lf %lf\n", @{$segment->{end}};
      }
   }

   # Yes, you also have the tree representation, but you will have
   # to figure out how to use it! Documentation patches are welcome :)

DESCRIPTION ^

Vectorial representation and manipulator, obtained as the result of the tracing activity. As such, Graphics::Potrace::Vectorial objects should be regarded mostly as read-only ones, but you can fiddle with them if you need to.

One of the goals of having the vector representation will probably be to save it into some format; the distribution comes with two default exporters:

So, if you want to save the vector into SVG file foo.svg you can do this:

   $vector->export(Svg => file => 'foo.svg');

Both Graphics::Potrace::Vectorial::Eps and Graphics::Potrace::Vectorial::Svg derive from Graphics::Potrace::Vectorial::Exporter; other exporters deriving from it will support at least file and fh parameters in order to allow you to do this:

   $vector->export($type, file => $filename);
   $vector->export($type, file => \my $text);
   $vector->export($type, fh   => $filehandle);

The first two will set a file where to save data (in the second case it will actually be a reference to a scalar for leveraging the internal perlfunc/open), the last will set a filehandle (e.g. a socket).

If you need a straight representation into a scalar, "render" is probably what you need:

   my $scalar = $vector->render($type);

As in the "export" case, you have to at least provide the $type of rendering that you need.

INTERFACE ^

create_exporter

   my $exporter = $vector->create_exporter($type, @args);

Factory (class) method to generate an exporter of the suitable $type. @args are passed over to the constructor of the relevant class.

The class is searched as Graphics::Potrace::Vectorial::$type and will arguably be a derivate class of Graphics::Potrace::Vectorial::Exporter.

export

   $vector->export($type, @args);

Export a representation of the vector according to $type and provided @args. This is equivalent to the following

   $vector->create_exporter($type, @args)->save($vector);

but more concise, see "create_exporter" for details.

has_height

    $vector->has_height() and print "has it!\n";

Returns a boolean value depending on the availability of "height". It is always true for objects created through the normal tracing process.

has_list

    $vector->has_list() and print "has it!\n";

Returns a boolean value depending on the availability of "list". It is always true for objects created through the normal tracing process.

has_tree

    $vector->has_tree() and print "has it!\n";

Returns a boolean value depending on the availability of "tree". It is always true for objects created through the normal tracing process.

has_width

    $vector->has_width() and print "has it!\n";

Returns a boolean value depending on the availability of "width". It is always true for objects created through the normal tracing process.

height

   my $height = $vector->height();

Returns the height of the vector representation. This is set equal to the height of the bitmap that led to the generation of the vector, so most of the times it will be larger than what strictly needed.

list

Returns a list of curves that - all together - form the whole vector. See http://potrace.sourceforge.net/potracelib.pdf for details on the list representation.

render

   my $scalar = $vector->export($type, @args);

Generate a representation of the vector according to $type and provided @args. This is equivalent to the following

   $vector->create_exporter($type, @args)->render($vector);

but more concise, see "create_exporter" for details.

tree

Returns a tree of curves that - all together - form the whole vector. See http://potrace.sourceforge.net/potracelib.pdf for details on the tree representation.

width

   my $width = $vector->width();

Returns the width of the vector representation. This is set equal to the width of the bitmap that led to the generation of the vector, so most of the times it will be larger than what strictly needed.

AUTHOR ^

Flavio Poletti <polettix@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2011 by Flavio Poletti polettix@cpan.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.

syntax highlighting: