« lib/PDF/FromHTML/Template/Container.pm
↑ Summary
lib/PDF/FromHTML/Template/Container/PdfTemplate.pm »
| 1 | package PDF::FromHTML::Template::Container::Font; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | use vars qw(@ISA); | ||
| 7 | @ISA = qw(PDF::FromHTML::Template::Container); | ||
| 8 | |||
| 9 | use PDF::FromHTML::Template::Container; | ||
| 10 | } | ||
| 11 | |||
| 12 | my @current_font = (); | ||
| 13 | |||
| 14 | sub new | ||
| 15 | { | ||
| 16 | my $class = shift; | ||
| 17 | my $self = $class->SUPER::new(@_); | ||
| 18 | |||
| 19 | $self->{EMBED} = 0 unless defined $self->{EMBED}; | ||
| 20 | |||
| 21 | return $self; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub render | ||
| 25 | { | ||
| 26 | my $self = shift; | ||
| 27 | my ($context) = @_; | ||
| 28 | my $p = $context->{PDF}; | ||
| 29 | |||
| 30 | my $size = $context->get($self, 'H') || | ||
| 31 | $context->get($self, 'SIZE') || | ||
| 32 | die "Height not set by the time <font> was rendered", $/; | ||
| 33 | my $face = $context->get($self, 'FACE') || | ||
| 34 | die "Face not set by the time <font> was rendered", $/; | ||
| 35 | |||
| 36 | my $font = $context->retrieve_font($face); | ||
| 37 | $font == -1 && die "Font not found for '$face' by the time <font> was rendered", $/; | ||
| 38 | |||
| 39 | $p->font($font, $size); | ||
| 40 | |||
| 41 | push @current_font, [ $font, $size ]; | ||
| 42 | |||
| 43 | return 1 unless @{$self->{ELEMENTS}}; | ||
| 44 | |||
| 45 | my $child_success = $self->iterate_over_children($context); | ||
| 46 | |||
| 47 | pop @current_font; | ||
| 48 | |||
| 49 | return $child_success unless @current_font; | ||
| 50 | |||
| 51 | $p->font(@{$current_font[-1]}); | ||
| 52 | |||
| 53 | return $child_success; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub mark_as_rendered {} | ||
| 57 | |||
| 58 | sub begin_page | ||
| 59 | { | ||
| 60 | my $self = shift; | ||
| 61 | my ($context) = @_; | ||
| 62 | |||
| 63 | my $face = $context->get($self, 'FACE') || | ||
| 64 | die "Face not set by the time <font> was rendered", $/; | ||
| 65 | |||
| 66 | unless ($context->retrieve_font($face)) | ||
| 67 | { | ||
| 68 | my $encoding = $context->get($self, 'PDF_ENCODING') || 'host'; | ||
| 69 | |||
| 70 | my $font = $context->{PDF}->find_font( | ||
| 71 | $face, | ||
| 72 | $encoding, | ||
| 73 | $context->get($self, 'EMBED'), | ||
| 74 | ) or die "Font not found for '$face' by the time <font> was rendered", $/; | ||
| 75 | |||
| 76 | $context->store_font($face, $font); | ||
| 77 | } | ||
| 78 | |||
| 79 | return $self->SUPER::begin_page($context); | ||
| 80 | } | ||
| 81 | |||
| 82 | 1; | ||
| 83 | __END__ |