App-WIoZ

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

                            set_font => 'DejaVuSans,normal,bold');
        
    
    $fontname = $wioz->font->{font};
    $wioz->chg_font('LiberationSans,normal,bold');
    


## filename

file name output, extension `.png` or `.svg` will be added 

## svg

produce a svg output, default value

set to 0 to write a png

## scale

Scale for the Hilbert Curve granularity default to 10

Higer value produces better speed but more words recovery.

## basecolor

Base color for color theme, default to 882222

README.md  view on Meta::CPAN

## update_colors

Read words position from file and update colors.

Usage:

    $wioz->update_colors("file.sl.txt");

## do_layout

Compute words position, save result to svg or png image, save in `filename.sl.txt` words positions to update colors.

Usage :
   $wioz->do_layout(@words);

# Git

[https://github.com/yvesago/WIoZ/](https://github.com/yvesago/WIoZ/)

# AUTHORS

lib/App/WIoZ.pm  view on Meta::CPAN

has 'surface' => (
    is => 'rw', isa => 'Cairo::ImageSurface',
);

has 'svgsurface' => (
    is => 'rw', isa => 'Cairo::SvgSurface',
);

=head2 filename

file name output, extension C<.png> or C<.svg> will be added 

=cut

has 'filename' => (
    is => 'rw', isa => 'Str',
);

=head2 svg

produce a svg output, default value

set to 0 to write a png

=cut

has 'svg' => (
  is => 'ro', isa => 'Int', default => 1
);

has 'fcurve' => (
    is => 'rw', isa => 'Math::PlanePath',
);

lib/App/WIoZ.pm  view on Meta::CPAN


    foreach my $l (@L) {
        my ($show,$text,$size,$x,$y,$angle) = split /\t/,$l;
        #say "$text - $size - $angle";
        my $w = App::WIoZ::Word->new(text => $text, size => $size, angle => $angle, show => $show, color => $color[int(rand(12))], font => $self->font);
        my $newc = App::WIoZ::Point->new( x => $x, y => $y);
        $w->update_size($self,$size);
        $w->update_c($newc);
        $self->_show_word($w);
    }
    $self->_save_to_png if (!$self->svg);
}

=head2 do_layout

Compute words position, save result to svg or png image, save in C<filename.sl.txt> words positions to update colors.

Usage :
   $wioz->do_layout(@words);

=cut

sub do_layout {
    my ($self,@words) = @_;
    my $c = 0;
    my $current = undef;

lib/App/WIoZ.pm  view on Meta::CPAN


    # register used space
    map { if ($_) {push @{ $self->cused }, $_} } @ranges;

    # show
    $self->_show_word($w) if ($w->show);

    #$c++; last if $c > 2;
    }

    $self->_save_to_png if (!$self->svg);

    $self->_save_layout(@words);

}

sub _save_to_png {
        my $self = shift;
        $self->surface->write_to_png ($self->filename . '.png');
}

# Save words position to a file. Usefull to update colors.
sub _save_layout {
    my ($self, @words) = @_;
    my $fh;
    open $fh, '>:utf8', $self->filename . '.sl.txt';
    foreach my $w (@words) {
        print $fh $w->show."\t".$w->text."\t".$w->size."\t".$w->c->x."\t".$w->c->y."\t".$w->angle."\n";
    }

t/00-wioz.t  view on Meta::CPAN


# a new smallest svg image for tests
$wioz = App::WIoZ->new( height => 200, width => 200, font_min => 18, font_max => 64, filename => $dirname.'test'); 
my @words = $wioz->read_words($dirname.'test-words.txt'); 
isa_ok($words[0],'App::WIoZ::Word');

$wioz->do_layout(@words); # compute image
is(-f $dirname.'test.svg',1,"create image ".$dirname.'test.svg');
is(-f $dirname.'test.sl.txt',1,"save layout ".$dirname.'test.sl.txt');

# a new smallest png image for tests
$wioz = App::WIoZ->new( height => 200, width => 200, font_min => 18, font_max => 64,
        filename => $dirname.'test' , svg => 0,
        set_font => 'DejaVuSans,italic,normal');
is($wioz->font->{font},'DejaVuSans','set_font to DejaVuSans');


@words = $wioz->read_words($dirname.'test-words.txt'); 

is ($words[0]->font->{font},'DejaVuSans','word with DejaVuSans font');

$wioz->do_layout(@words); # compute image
is(-f $dirname.'test.png',1,"create image ".$dirname.'test.png');
is(-f $dirname.'test.sl.txt',1,"save layout ".$dirname.'test.sl.txt');

# update colorsa nd font
#$wioz->chg_font('strenuous,normal,normal');
$wioz->chg_font('LiberationSans,normal,bold');
is($wioz->font->{font},'LiberationSans','chg_font to LiberationSans');

$wioz->filename($dirname.'test2');
$wioz->update_colors($dirname.'test.sl.txt');
is(-f $dirname.'test2.png',1,"create image with new color ".$dirname.'test2.png');

# update colors
$wioz->filename($dirname.'test3');
$wioz->update_colors($dirname.'test.sl.txt');
is(-f $dirname.'test3.png',1,"create image with new color ".$dirname.'test3.png');

# test directory clean up
unlink $dirname.'test.sl.txt';
unlink $dirname.'test.svg';
unlink $dirname.'test.png';
unlink $dirname.'test2.png';
unlink $dirname.'test3.png';


$wioz = App::WIoZ->new( height => 300, font_min => 18, font_max => 64, set_font => 'DejaVuSans,normal,bold');



( run in 2.703 seconds using v1.01-cache-2.11-cpan-df04353d9ac )