|
|
@ -9,12 +9,7 @@ use base 'Subtitle::SSA::Record'; |
|
|
|
my @FIELDS_SSA = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding); |
|
|
|
my @FIELDS_SSA = qw(name fontname fontsize primarycolour secondarycolour tertiarycolour backcolour bold italic borderstyle outline shadow alignment marginl marginr marginv alphalevel encoding); |
|
|
|
my @FIELDS_ASS = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding); |
|
|
|
my @FIELDS_ASS = qw(name fontname fontsize primarycolour secondarycolour outlinecolour backcolour bold italic underline strikeout scalex scaley spacing angle borderstyle outline shadow alignment marginl marginr marginv encoding); |
|
|
|
|
|
|
|
|
|
|
|
# formats: |
|
|
|
# see parse() description for available type's |
|
|
|
# s - string, use as is |
|
|
|
|
|
|
|
# d - decimal, no-zero pad |
|
|
|
|
|
|
|
# b - boolean, 0 as false, -1 as true |
|
|
|
|
|
|
|
# f - float, 6.01 or 6 if no fractional part |
|
|
|
|
|
|
|
# x - hex-number, &H00AABBCC for ASS or decimal number for SSA |
|
|
|
|
|
|
|
my %FIELDS = ( |
|
|
|
my %FIELDS = ( |
|
|
|
name => { type => 's', value => 'Default', name => 'Name' }, |
|
|
|
name => { type => 's', value => 'Default', name => 'Name' }, |
|
|
|
fontname => { type => 's', value => 'Arial' , name => 'Fontname' }, |
|
|
|
fontname => { type => 's', value => 'Arial' , name => 'Fontname' }, |
|
|
@ -42,50 +37,6 @@ my %FIELDS = ( |
|
|
|
alphalevel => { type => 'd', value => 0, name => 'AlphaLevel' }, |
|
|
|
alphalevel => { type => 'd', value => 0, name => 'AlphaLevel' }, |
|
|
|
encoding => { type => 'd', value => 204, name => 'Encoding' }, |
|
|
|
encoding => { type => 'd', value => 204, name => 'Encoding' }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
my $PREFIX = 'Style'; |
|
|
|
sub parse { |
|
|
|
|
|
|
|
my ($self, $fields, $line) = @_; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return unless $fields and ref($fields) eq 'ARRAY'; |
|
|
|
|
|
|
|
return unless $line and $line =~ m{^Style:}oi; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chomp $line; |
|
|
|
|
|
|
|
$line =~ s{^style:\s+}{}oi; |
|
|
|
|
|
|
|
my @values = split /,\s*/o, $line; |
|
|
|
|
|
|
|
# check that values count match fields count |
|
|
|
|
|
|
|
return unless scalar @{ $fields } != scalar @values; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach my $field (@{ $fields }) { |
|
|
|
|
|
|
|
my $value = shift @values; |
|
|
|
|
|
|
|
$self->set($field => $value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub to_string { |
|
|
|
|
|
|
|
my ($self) = @_; |
|
|
|
|
|
|
|
my @fields = $self->fields(); |
|
|
|
|
|
|
|
my $string = "Style: "; |
|
|
|
|
|
|
|
my @values = (); |
|
|
|
|
|
|
|
foreach my $field (@fields) { |
|
|
|
|
|
|
|
my $d = $FIELD{$field}; |
|
|
|
|
|
|
|
my $v = $self->{$f} // $d->{value}; |
|
|
|
|
|
|
|
if ($d->{type} eq 'x') { |
|
|
|
|
|
|
|
$fmt = ($self->{_vers} eq 'ass') ? '&H%08X' : '%d'; |
|
|
|
|
|
|
|
$v = sprintf $fmt, $v; |
|
|
|
|
|
|
|
} elsif ($d->{type} eq 'f') { |
|
|
|
|
|
|
|
$v = sprintf "%.2f", $v; |
|
|
|
|
|
|
|
# hack: make decimal from float if fractional part is zero after round up |
|
|
|
|
|
|
|
$v =~ s{\.00$}{}oi; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
# use as is |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
push @values, $v; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$string .= join(',', @values); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $string; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1; |
|
|
|
1; |
|
|
|