You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.2 KiB
74 lines
1.2 KiB
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;
|
|
|