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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
package PDF::FromHTML::Template::Container::Font;
use strict;
BEGIN {
use vars qw(@ISA);
@ISA = qw(PDF::FromHTML::Template::Container);
use PDF::FromHTML::Template::Container;
}
my @current_font = ();
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{EMBED} = 0 unless defined $self->{EMBED};
return $self;
}
sub render
{
my $self = shift;
my ($context) = @_;
my $p = $context->{PDF};
my $size = $context->get($self, 'H') ||
$context->get($self, 'SIZE') ||
die "Height not set by the time <font> was rendered", $/;
my $face = $context->get($self, 'FACE') ||
die "Face not set by the time <font> was rendered", $/;
my $font = $context->retrieve_font($face);
$font == -1 && die "Font not found for '$face' by the time <font> was rendered", $/;
$p->font($font, $size);
push @current_font, [ $font, $size ];
return 1 unless @{$self->{ELEMENTS}};
my $child_success = $self->iterate_over_children($context);
pop @current_font;
return $child_success unless @current_font;
$p->font(@{$current_font[-1]});
return $child_success;
}
sub mark_as_rendered {}
sub begin_page
{
my $self = shift;
my ($context) = @_;
my $face = $context->get($self, 'FACE') ||
die "Face not set by the time <font> was rendered", $/;
unless ($context->retrieve_font($face))
{
my $encoding = $context->get($self, 'PDF_ENCODING') || 'host';
my $font = $context->{PDF}->find_font(
$face,
$encoding,
$context->get($self, 'EMBED'),
) or die "Font not found for '$face' by the time <font> was rendered", $/;
$context->store_font($face, $font);
}
return $self->SUPER::begin_page($context);
}
1;
__END__
=head1 NAME
PDF::FromHTML::Template::Container::Font - Specify the font used for TEXTBOX nodes
=head1 NODE NAME
FONT
=head1 INHERITANCE
PDF::FromHTML::Template::Container
=head1 ATTRIBUTES
=over 4
=item * FACE - this is required. It must be a legal font face recognized by
PDFLib. (q.v. for more details)
=item * H - the point size of the font.
=back
=head1 CHILDREN
None
=head1 AFFECTS
The font used when rendering a TEXTBOX
=head1 DEPENDENCIES
None
=head1 USAGE
<font face="Times-Roman" h="8">
... Children will be rendered in 8-point TimesRoman font ...
</font>
Please note that not specifying a FONT tag will result in a PDFLib error when
the first TEXTBOX attempts to render. Since not all PDF documents involve text,
PDF::FromHTML::Template does not require a FONT tag.
(I might require a FONT tag if a TEXTBOX tag exists, but only after the non-
standard behavior of FONT is fixed. q.v. the NOTE below.)
=head1 NOTE
For backwards compatibility, a stand-alone FONT tag will be treated as if it is
the parent for all nodes until the end of the parent node. This behavior is
deprecated and will be removed in a future release.
<pagedef>
... Children here aren't affected by the FONT tag below ...
<font face="Times-Roman" h="8"/>
... Children here _ARE_ affected by the FONT tag above ...
</pagedef>
=head1 AUTHOR
Rob Kinyon (rkinyon@columbus.rr.com)
=head1 SEE ALSO
=cut
|