|
|
@ -36,7 +36,7 @@ sub new_event { ... } |
|
|
|
sub parse { |
|
|
|
sub parse { |
|
|
|
my ($self, $lines) = @_; |
|
|
|
my ($self, $lines) = @_; |
|
|
|
my $linenum = 0; |
|
|
|
my $linenum = 0; |
|
|
|
my $section; |
|
|
|
my ($section, $font); |
|
|
|
|
|
|
|
|
|
|
|
foreach my $line (@$lines) { |
|
|
|
foreach my $line (@$lines) { |
|
|
|
$linenum++; |
|
|
|
$linenum++; |
|
|
@ -46,7 +46,7 @@ sub parse { |
|
|
|
study $line; |
|
|
|
study $line; |
|
|
|
|
|
|
|
|
|
|
|
# check section switch |
|
|
|
# check section switch |
|
|
|
if ($line =~ m/^\s*\[\s*([a-z0-9+ ]+)\s*\]\s*$/io) { |
|
|
|
if (index($line, '[') >= 0 and $line =~ m/^\[([a-zA-Z0-9+ ]+)\]\s*$/o) { |
|
|
|
my $name = lc($1); |
|
|
|
my $name = lc($1); |
|
|
|
if ($name =~ m{script \s+ info}oix) { |
|
|
|
if ($name =~ m{script \s+ info}oix) { |
|
|
|
$section = 'header'; |
|
|
|
$section = 'header'; |
|
|
@ -67,25 +67,25 @@ sub parse { |
|
|
|
$self->log(debug => "section changed to [$section] at line $linenum"); |
|
|
|
$self->log(debug => "section changed to [$section] at line $linenum"); |
|
|
|
next; |
|
|
|
next; |
|
|
|
} |
|
|
|
} |
|
|
|
# |
|
|
|
# parse fonts data |
|
|
|
unless ($section) { |
|
|
|
|
|
|
|
$self->log(warn => "Line $linenum outside any section, skip"); |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ($section eq 'fonts') { |
|
|
|
if ($section eq 'fonts') { |
|
|
|
if ($line =~ m/^fontname:\s*(.*)/i) { |
|
|
|
if (index($line, 'fontname:') == 0) { |
|
|
|
my $font = Subtitle::SSA::File->new; |
|
|
|
$line =~ m/^fontname:\s*(.*)/o; |
|
|
|
|
|
|
|
$font = Subtitle::SSA::File->new; |
|
|
|
$font->type('font'); |
|
|
|
$font->type('font'); |
|
|
|
$font->name($1); |
|
|
|
$font->name($1); |
|
|
|
push @{ $self->{fonts} }, $font; |
|
|
|
push @{ $self->{fonts} }, $font; |
|
|
|
next; |
|
|
|
next; |
|
|
|
} |
|
|
|
} elsif ($font) { |
|
|
|
my $curr = $self->{fonts}->[-1] |
|
|
|
$font->add_uue_line($line); |
|
|
|
or next; # missing 'fontname' line? |
|
|
|
} # else: missing 'fontname' line, skip |
|
|
|
$curr->add_uue_line($line); |
|
|
|
|
|
|
|
next; |
|
|
|
next; |
|
|
|
} |
|
|
|
} |
|
|
|
# TODO: graphics section |
|
|
|
# TODO: graphics section |
|
|
|
|
|
|
|
unless ($section) { |
|
|
|
|
|
|
|
$self->log(warn => "Line $linenum outside any section, skip"); |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
# skip comments |
|
|
|
# skip comments |
|
|
|
next if $line =~ m{^ \s* ;}xo; |
|
|
|
next if $line =~ m{^ \s* ;}xo; |
|
|
|
if ($section eq 'header') { |
|
|
|
if ($section eq 'header') { |
|
|
|