SWF/Type/LINESTYLE.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 127 CC 15 SCAR 33.7
CC
15
Cov
0%
build
42.0
string
42.0
parse
30.0
CRAP 29.0
1 package IO::SWF::Type::LINESTYLE;
2  
3 use strict;
4 use warnings;
5  
6 use base 'IO::SWF::Type';
7  
8 use IO::SWF::Bit;
9 use IO::SWF::Type::RGB;
10 use IO::SWF::Type::RGBA;
11  
12 sub parse {
13 my ($reader, $opts_href) = @_;
14 my %opts = ref($opts_href) ? %{$opts_href} : ();
15  
16 my $tagCode = $opts{'tagCode'};
17 my $isMorph = ($tagCode == 46) || ($tagCode == 84) ? 1 : 0;
18 my %lineStyle = ();
19 if (!$isMorph) {
20 $lineStyle{'Width'} = $reader->getUI16LE();
21 if ($tagCode < 32 ) { # 32:DefineShape3
22 $lineStyle{'Color'} = IO::SWF::Type::RGB::parse($reader);
23 } else {
24 $lineStyle{'Color'} = IO::SWF::Type::RGBA::parse($reader);
25 }
26 } else {
27 $lineStyle{'StartWidth'} = $reader->getUI16LE();
28 $lineStyle{'EndWidth'} = $reader->getUI16LE();
29 $lineStyle{'StartColor'} = IO::SWF::Type::RGBA::parse($reader);
30 $lineStyle{'EndColor'} = IO::SWF::Type::RGBA::parse($reader);
31 }
32 return \%lineStyle;
33 }
34  
35 sub build {
36 my ($writer, $lineStyle_href, $opts_href) = @_;
37 my %lineStyle = ref($lineStyle_href) ? %{$lineStyle_href} : ();
38 my %opts = ref($opts_href) ? %{$opts_href} : ();
39  
40 my $tagCode = $opts{'tagCode'};
41 my $isMorph = ($tagCode == 46) || ($tagCode == 84) ? 1 : 0;
42 if (!$isMorph) {
43 $writer->putUI16LE($lineStyle{'Width'});
44 if ($tagCode < 32 ) { # 32:DefineShape3
45 IO::SWF::Type::RGB::build($writer, $lineStyle{'Color'});
46 } else {
47 IO::SWF::Type::RGBA::build($writer, $lineStyle{'Color'});
48 }
49 } else {
50 $writer->putUI16LE($lineStyle{'StartWidth'});
51 $writer->putUI16LE($lineStyle{'EndWidth'});
52 IO::SWF::Type::RGBA::build($writer, $lineStyle{'StartColor'});
53 IO::SWF::Type::RGBA::build($writer, $lineStyle{'EndColor'});
54 }
55 return 1;
56 }
57  
58 sub string {
59 my ($lineStyle_href, $opts_href) = @_;
60 my %lineStyle = ref($lineStyle_href) ? %{$lineStyle_href} : ();
61 my %opts = ref($opts_href) ? %{$opts_href} : ();
62  
63 my $tagCode = $opts{'tagCode'};
64 my $isMorph = ($tagCode == 46) || ($tagCode == 84) ? 1 : 0;
65 my $text = '';
66  
67 if (!$isMorph) {
68 my $width = $lineStyle{'Width'};
69 my $color_str;
70 if ($tagCode < 32 ) { # 32:DefineShape3
71 $color_str = IO::SWF::Type::RGB::string($lineStyle{'Color'});
72 } else {
73 $color_str = IO::SWF::Type::RGBA::string($lineStyle{'Color'});
74 }
75 $text .= "\tWitdh: $width Color: $color_str\n";
76 } else {
77 my $startWidth = $lineStyle{'StartWidth'};
78 my $endWidth = $lineStyle{'EndWidth'};
79 my $startColorStr = IO::SWF::Type::RGBA::string($lineStyle{'StartColor'});
80 my $endColorStr = IO::SWF::Type::RGBA::string($lineStyle{'EndColor'});
81 $text .= "\tWitdh: $startWidth => $endWidth Color: $startColorStr => $endColorStr\n";
82 }
83 return $text;
84 }
85  
86 1;