Browse Source

* Subtitle::SSA : fonts processing

master
Alex 'AdUser' Z 6 years ago
parent
commit
ad6cf36c05
  1. 28
      lib/Subtitle/SSA.pm

28
lib/Subtitle/SSA.pm

@ -7,6 +7,7 @@ use utf8;
use Subtitle::SSA::Header;
use Subtitle::SSA::Style;
use Subtitle::SSA::Event;
use Subtitle::SSA::File;
use Subtitle::Utils qw(:string);
@ -23,6 +24,7 @@ sub new {
headers => {},
styles => [],
events => [],
fonts => [],
log => [],
};
@ -50,6 +52,8 @@ sub parse {
$section = 'header';
} elsif ($name eq 'events') {
$section = 'events';
} elsif ($name eq 'fonts') {
$section = 'fonts';
} elsif ($name =~ m{v4(\+)? \s+ styles}oix) {
$section = 'styles';
unless ($self->{type}) {
@ -68,7 +72,7 @@ sub parse {
$self->log(warn => "Line $linenum outside any section, skip");
next;
}
# TODO: fonts section
# TODO: graphics section
# skip comments
next if $line =~ m{^ \s* ;}xo;
if ($section eq 'header') {
@ -119,6 +123,19 @@ sub parse {
}
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");
}
@ -158,7 +175,14 @@ sub build {
}
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);
}

Loading…
Cancel
Save