File: TextObject.pm

package info (click to toggle)
libpdf-fromhtml-perl 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576 kB
  • sloc: perl: 4,876; makefile: 15
file content (56 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package PDF::FromHTML::Template::TextObject;

use strict;

BEGIN {
    use vars qw(@ISA);
    @ISA = qw(PDF::FromHTML::Template::Base);

    use PDF::FromHTML::Template::Base;

    use Encode;
}

# This is a helper object. It is not instantiated by the user,
# nor does it represent an XML object. Rather, certain elements,
# such as <textbox>, can use this object to do text with variable
# substitutions.

sub new
{
    my $class = shift;
    my $self = $class->SUPER::new(@_);

    $self->{STACK} = [] unless UNIVERSAL::isa($self->{STACK}, 'ARRAY');

    return $self;
}

sub resolve
{
    my $self = shift;
    my ($context) = @_;

    my $t = '';

    for my $tok (@{$self->{STACK}})
    {
        my $val = $tok;
        $val = $val->resolve($context)
            if PDF::FromHTML::Template::Factory::isa($val, 'VAR');

        my $encoding = $context->get($self, 'PDF_ENCODING');
        if ($encoding) {
            if (Encode::is_utf8($val)) {
                $val = Encode::encode($encoding,$val);
            }
        }

        $t .= $val;
    }

    return $t;
}

1;
__END__