|
|
@ -7,6 +7,7 @@ use utf8; |
|
|
|
use Subtitle::SSA::Header; |
|
|
|
use Subtitle::SSA::Header; |
|
|
|
use Subtitle::SSA::Style; |
|
|
|
use Subtitle::SSA::Style; |
|
|
|
use Subtitle::SSA::Event; |
|
|
|
use Subtitle::SSA::Event; |
|
|
|
|
|
|
|
use Subtitle::SSA::File; |
|
|
|
|
|
|
|
|
|
|
|
use Subtitle::Utils qw(:string); |
|
|
|
use Subtitle::Utils qw(:string); |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +24,7 @@ sub new { |
|
|
|
headers => {}, |
|
|
|
headers => {}, |
|
|
|
styles => [], |
|
|
|
styles => [], |
|
|
|
events => [], |
|
|
|
events => [], |
|
|
|
|
|
|
|
fonts => [], |
|
|
|
log => [], |
|
|
|
log => [], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -50,6 +52,8 @@ sub parse { |
|
|
|
$section = 'header'; |
|
|
|
$section = 'header'; |
|
|
|
} elsif ($name eq 'events') { |
|
|
|
} elsif ($name eq 'events') { |
|
|
|
$section = 'events'; |
|
|
|
$section = 'events'; |
|
|
|
|
|
|
|
} elsif ($name eq 'fonts') { |
|
|
|
|
|
|
|
$section = 'fonts'; |
|
|
|
} elsif ($name =~ m{v4(\+)? \s+ styles}oix) { |
|
|
|
} elsif ($name =~ m{v4(\+)? \s+ styles}oix) { |
|
|
|
$section = 'styles'; |
|
|
|
$section = 'styles'; |
|
|
|
unless ($self->{type}) { |
|
|
|
unless ($self->{type}) { |
|
|
@ -68,7 +72,7 @@ sub parse { |
|
|
|
$self->log(warn => "Line $linenum outside any section, skip"); |
|
|
|
$self->log(warn => "Line $linenum outside any section, skip"); |
|
|
|
next; |
|
|
|
next; |
|
|
|
} |
|
|
|
} |
|
|
|
# TODO: fonts section |
|
|
|
# TODO: graphics section |
|
|
|
# skip comments |
|
|
|
# skip comments |
|
|
|
next if $line =~ m{^ \s* ;}xo; |
|
|
|
next if $line =~ m{^ \s* ;}xo; |
|
|
|
if ($section eq 'header') { |
|
|
|
if ($section eq 'header') { |
|
|
@ -119,6 +123,19 @@ sub parse { |
|
|
|
} |
|
|
|
} |
|
|
|
next; |
|
|
|
next; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($section eq 'fonts') { |
|
|
|
|
|
|
|
if ($line =~ m/^fontname:\s*(.*)/i) { |
|
|
|
|
|
|
|
my $font = Subtitle::SSA::File->new; |
|
|
|
|
|
|
|
$font->type('font'); |
|
|
|
|
|
|
|
$font->name($1); |
|
|
|
|
|
|
|
push @{ $self->{fonts} }, $font; |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
my $curr = $self->{fonts}->[-1] |
|
|
|
|
|
|
|
or next; # missing 'fontname' line? |
|
|
|
|
|
|
|
$curr->parse_uue_line($line); |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
$self->log(warn => "unrecognized line at line $linenum: $line"); |
|
|
|
$self->log(warn => "unrecognized line at line $linenum: $line"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -158,7 +175,14 @@ sub build { |
|
|
|
} |
|
|
|
} |
|
|
|
push @lines, ""; |
|
|
|
push @lines, ""; |
|
|
|
|
|
|
|
|
|
|
|
# TODO: fonts |
|
|
|
if (scalar @{ $self->{fonts} } > 0) { |
|
|
|
|
|
|
|
push @lines, "[Fonts]"; |
|
|
|
|
|
|
|
foreach my $font (@{ $self->{fonts} }) { |
|
|
|
|
|
|
|
push @lines, $font->uue_block; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: graphics |
|
|
|
|
|
|
|
|
|
|
|
return join($self->{eol}, @lines); |
|
|
|
return join($self->{eol}, @lines); |
|
|
|
} |
|
|
|
} |
|
|
|