| 1 | package IO::SWF::Type::LINESTYLEARRAY; | ||
| 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::LINESTYLE; | ||
| 10 | |||
| 11 | sub parse { | ||
| 12 | my ($reader, $opts_href) = @_; | ||
| 13 | my %opts = ref($opts_href) ? %{$opts_href} : (); | ||
| 14 | |||
| 15 | my $tagCode = $opts{'tagCode'}; | ||
| 16 | my @lineStyles = (); | ||
| 17 | # LineStyle | ||
| 18 | my $lineStyleCount = $reader->getUI8(); | ||
| 19 | if (($tagCode > 2) && ($lineStyleCount == 0xff)) { | ||
| 20 | $lineStyleCount = $reader->getUI16LE(); | ||
| 21 | } | ||
| 22 | for (my $i = 0 ; $i < $lineStyleCount ; $i++) { | ||
| 23 | my $lineStyle = IO::SWF::Type::LINESTYLE::parse($reader, \%opts); | ||
| 24 | push @lineStyles, $lineStyle; | ||
| 25 | } | ||
| 26 | return \@lineStyles; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub build { | ||
| 30 | my ($writer, $lineStyles_aref, $opts_href) = @_; | ||
| 31 | my @lineStyles = ref($lineStyles_aref) ? @{$lineStyles_aref} : (); | ||
| 32 | my %opts = ref($opts_href) ? %{$opts_href} : (); | ||
| 33 | |||
| 34 | my $tagCode = $opts{'tagCode'}; | ||
| 35 | my $lineStyleCount = scalar(@lineStyles); | ||
| 36 | if ($lineStyleCount < 0xff) { | ||
| 37 | $writer->putUI8($lineStyleCount); | ||
| 38 | } else { | ||
| 39 | $writer->putUI8(0xff); | ||
| 40 | if ($tagCode > 2) { | ||
| 41 | $writer->putUI16LE($lineStyleCount); | ||
| 42 | } else { | ||
| 43 | $lineStyleCount = 0xff; # DefineShape(1) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | foreach my $lineStyle (@lineStyles) { | ||
| 47 | IO::SWF::Type::LINESTYLE::build($writer, $lineStyle, \%opts); | ||
| 48 | } | ||
| 49 | return 1; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub string { | ||
| 53 | my ($lineStyles_aref, $opts_href) = @_; | ||
| 54 | my @lineStyles = ref($lineStyles_aref) ? @{$lineStyles_aref} : (); | ||
| 55 | my %opts = ref($opts_href) ? %{$opts_href} : (); | ||
| 56 | |||
| 57 | my $tagCode = $opts{'tagCode'}; | ||
| 58 | my $text = ''; | ||
| 59 | foreach my $lineStyle (@lineStyles) { | ||
| 60 | $text .= IO::SWF::Type::LINESTYLE::string($lineStyle, \%opts); | ||
| 61 | } | ||
| 62 | return $text; | ||
| 63 | } | ||
| 64 | |||
| 65 | 1; |