Alex 'AdUser' Z
8 years ago
2 changed files with 74 additions and 0 deletions
@ -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; |
Loading…
Reference in new issue