CtrlO-PDF
view release on metacpan or search on metacpan
written to, and is the location that content will be positioned at the next
write. Note that the value is measured from the bottom of the page.
## set\_y\_position($pixels)
Sets the current Y position. See ["y\_position"](#y_position).
## move\_y\_position($pixels)
Moves the current Y position, relative to its current value. Positive values
will move the cursor up the page, negative values down. See ["y\_position"](#y_position).
## heading($text, %options)
Add a heading. If called on a new page, will automatically move the cursor down
to account for the heading's height (based on the assumption that one pixel
equals one point). Options available are:
- size _n_
`n` is the font size in points, **default 16**
- indent _n_
`n` is the amount (in points) to indent the text, **default 0**
lib/CtrlO/PDF.pm view on Meta::CPAN
has page_count => (
is => 'rw',
default => 0,
);
sub add_page
{ my $self = shift;
my $page = $self->pdf->page;
$page->mediabox(0, 0, $self->width, $self->height);
$self->_set_page($page);
$self->_set__y($self->_y_start_default); # Reset y cursor
# Flag that we have just started a new page. Because text is positioned from
# its bottom-left corner, we will need to move the cursor down further to
# account for the font size of the text, but we don't know that yet.
$self->_set_is_new_page(1);
$self->page_count($self->page_count + 1);
return $page;
}
=head2 is_new_page
Whether the current page is new with no content. When the heading or text
methods are called and this is true, additional top margin is added to account
lib/CtrlO/PDF.pm view on Meta::CPAN
sub set_y_position
{ my ($self, $y) = @_;
$y && $y =~ /^-?[0-9]+(\.[0-9]+)?$/
or croak "Invalid y value for set_y_position: $y";
$self->_set__y($y);
}
=head2 move_y_position($pixels)
Moves the current Y position, relative to its current value. Positive values
will move the cursor up the page, negative values down. See L</y_position>.
=cut
sub move_y_position
{ my ($self, $y) = @_;
$y && $y =~ /^-?[0-9]+(\.[0-9]+)?$/
or croak "Invalid y value for move_y_position: $y";
$self->_set__y($self->_y + $y);
}
lib/CtrlO/PDF.pm view on Meta::CPAN
builder => sub { $_[0]->_y_start_default },
);
sub _y_start_default
{ my $self = shift;
return $self->height - $self->margin_top;
}
=head2 heading($text, %options)
Add a heading. If called on a new page, will automatically move the cursor down
to account for the heading's height (based on the assumption that one pixel
equals one point). Options available are:
=over
=item size I<n>
C<n> is the font size in points, B<default 16>
=item indent I<n>
lib/CtrlO/PDF.pm view on Meta::CPAN
# Return the spacing above/below a line based on font size and line height
sub _line_spacing {
my ($self, $size) = @_;
my $spacing = $self->_line_height($size);
($spacing - $size) / 2;
}
sub heading
{ my ($self, $string, %options) = @_;
my $page = $self->page; # Ensure that page is built and cursor adjusted for first use
$page = $self->add_page if $self->_y < 150; # Make sure there is room for following paragraph text
my $size = $options{size} || 16;
if ($options{topmargin}) {
# Always let override take precedence
$self->_down($options{topmargin}) if $options{topmargin};
}
elsif ($self->is_new_page)
{
lib/CtrlO/PDF.pm view on Meta::CPAN
sub text
{ my ($self, $string, %options) = @_;
$string or return;
my $size = delete $options{size} || $self->font_size;
my $color = delete $options{color} || 'black';
my $format = delete $options{format} || 'none';
my $page = $self->page; # Ensure that page is built and cursor adjusted for first use
# Add new page if already at the bottom from previous operation (e.g.
# rendering table)
$page = $self->add_page
if $self->_y - $self->_line_height($size) < $self->margin_bottom;
my $text = $page->text;
my $grfx = $page->gfx;
my $x = $self->_x + ($options{indent} || 0),
my $height = $self->_y - $self->margin_bottom;
( run in 1.958 second using v1.01-cache-2.11-cpan-39bf76dae61 )