diff --git a/lib/Subtitle/SSA/Font.pm b/lib/Subtitle/SSA/Font.pm new file mode 100644 index 0000000..bf3d4ce --- /dev/null +++ b/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; diff --git a/lib/Subtitle/SSA/Media.pm b/lib/Subtitle/SSA/Media.pm deleted file mode 100644 index e69de29..0000000