Browse Source

+ Subtitle::SSA::Font

master
Alex 'AdUser' Z 8 years ago
parent
commit
27280f32cf
  1. 74
      lib/Subtitle/SSA/Font.pm
  2. 0
      lib/Subtitle/SSA/Media.pm

74
lib/Subtitle/SSA/Font.pm

@ -0,0 +1,74 @@
package Subtitle::SSA::Font;
use strict;
use warnings;
use utf8;
sub new {
my ($class, %opts) = @_;
my $self = {
_eol => "\n",
_data => '',
_name => $opts{name} // '',
_error => undef,
};
return bless($self, $class);
}
sub error {
my ($self, $text) = @_;
if (defined $text) {
$self->{_error} = $text;
return;
}
return $self->{_error};
}
sub parse {
my ($self, $line) = @_;
return unless $line;
chomp $line;
$self->error('not like uuencoded line')
if (length($line) > 80);
$self->{_data} .= $line;
return length($line);
}
sub save {
my ($self, $path) = @_;
open my $FH, '>', $path
or return $self->error("can't open file: $path -- $!");
print $FH pack("u*", $self->{_data});
close $FH;
return 1;
}
sub load {
my ($self, $path) = @_;
open my $FH, '<', $path
or return $self->error("can't open file: $path -- $!");
local $/ = undef;
$self->{_data} = unpack("u*", <$FH>);
close $FH;
return 1;
}
sub to_string {
my ($self) = @_;
my $out = "fontname: " . $self->{_name} . $self->{_eol};
my @lines = unpack("A80", $self->{_data});
$out .= join($self->{_eol}, @lines);
$out .= $self->{_eol};
return $out;
}
1;

0
lib/Subtitle/SSA/Media.pm

Loading…
Cancel
Save