| 1 | use Renard::Incunabula::Common::Setup; | ||
| 2 | package Intertangle::Taffeta::Style::Stroke; | ||
| 3 | # ABSTRACT: Stroke style | ||
| 4 | $Intertangle::Taffeta::Style::Stroke::VERSION = '0.001'; | ||
| 5 | use Moo; | ||
| 6 | use Renard::Incunabula::Common::Types qw(Bool); | ||
| 7 | use Intertangle::Taffeta::Types qw(Color Opacity Dimension); | ||
| 8 | |||
| 9 | has opacity => ( | ||
| 10 | is => 'ro', | ||
| 11 | predicate => 1, | ||
| 12 | default => sub { 1 }, | ||
| 13 | isa => Opacity, | ||
| 14 | ); | ||
| 15 | |||
| 16 | has color => ( | ||
| 17 | is => 'ro', | ||
| 18 | predicate => 1, | ||
| 19 | isa => Color, | ||
| 20 | ); | ||
| 21 | |||
| 22 | has width => ( | ||
| 23 | is => 'ro', | ||
| 24 | predicate => 1, | ||
| 25 | default => sub { 1 }, | ||
| 26 | isa => Dimension, | ||
| 27 | ); | ||
| 28 | |||
| 29 | method is_stroke_none() :ReturnType(Bool) { | ||
| 30 | return ! $self->has_color && ! $self->has_opacity; | ||
| 31 | } | ||
| 32 | |||
| 33 | method svg_style() { | ||
| 34 | my $data = {}; | ||
| 35 | |||
| 36 | if( $self->is_stroke_none ) { | ||
| 37 | $data->{stroke} = 'none'; | ||
| 38 | } elsif( $self->has_color ) { | ||
| 39 | $data->{stroke} = $self->color->svg_value; | ||
| 40 | } | ||
| 41 | |||
| 42 | if( $self->has_opacity ) { | ||
| 43 | $data->{'stroke-opacity'} = $self->opacity; | ||
| 44 | } | ||
| 45 | |||
| 46 | if( $self->has_width ) { | ||
| 47 | $data->{'stroke-width'} = $self->width; | ||
| 48 | } | ||
| 49 | |||
| 50 | $data; | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |