| CAM-PDF documentation | Contained in the CAM-PDF distribution. |
CAM::PDF::Renderer::TextFB - Framebuffer for CAM::PDF::Renderer::Text
See CAM::PDF.
See CAM::PDF::Renderer::Text.
This class is used solely to assist CAM::PDF::Renderer::Text.
Creates a new framebuffer.
Renders a string on the framebuffer.
Serializes the framebuffer into a single string that can be easily printed.
See CAM::PDF
| CAM-PDF documentation | Contained in the CAM-PDF distribution. |
package CAM::PDF::Renderer::TextFB; use 5.006; use warnings; use strict; use CAM::PDF; our $VERSION = '1.55';
sub new { my $pkg = shift; my $w = shift; my $h = shift; my $self = bless { w => $w, h => $h, fb =>[], }, $pkg; for my $r (0 .. $h-1) { $self->{fb}->[$r] = [(q{})x$w]; } return $self; }
sub add_string { my $self = shift; my $x = shift; my $y = shift; my $string = shift; CAM::PDF->asciify(\$string); my $fb = $self->{fb}; if (defined $fb->[$y]) { if (defined $fb->[$y]->[$x]) { $fb->[$y]->[$x] .= $string; } else { #print "bad 1\n"; $fb->[$y]->[$x] = $string; } } else { #print "bad 2\n"; $fb->[$y] = []; $fb->[$y]->[$x] = $string; } return; }
sub toString { my $self = shift; my @str; my $fb = $self->{fb}; for my $r (reverse 0 .. $#{$fb}) # PDF is bottom to top, we want top to bottom { my $row = $fb->[$r]; if ($row) { #print "r $r c ".@$row."\n"; #print '>'; for my $c (0 .. $#{$row}) { my $str = $row->[$c]; if (!defined $str || $str eq q{}) { $str = q{ }; } push @str, $str; } } else { #print "r $r c 0\n"; #print '>'; } push @str, "\n"; } return join q{}, @str; } 1; __END__