Graphics::Primitive::Driver::CairoPango::TextLayout - Text layout engine


Graphics-Primitive-Driver-CairoPango documentation Contained in the Graphics-Primitive-Driver-CairoPango distribution.

Index


Code Index:

NAME

Top

Graphics::Primitive::Driver::CairoPango::TextLayout - Text layout engine

SYNOPSIS

Top

    my $tl = $driver->get_textbox_layout($comp);
    ...

DESCRIPTION

Top

Implements Graphics::Primitive::Driver::TextLayout. Please refer to it's documentation for usage.

IMPLEMENTATION

Top

This text layout engine uses Pango to layout text.

AUTHOR

Top

Cory Watson, <gphat@cpan.org>

Infinity Interactive, http://www.iinteractive.com

BUGS

Top

Please report any bugs or feature requests to bug-geometry-primitive at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Geometry-Primitive. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


Graphics-Primitive-Driver-CairoPango documentation Contained in the Graphics-Primitive-Driver-CairoPango distribution.

package Graphics::Primitive::Driver::CairoPango::TextLayout;
use Moose;

use Graphics::Primitive::TextBox;

with 'Graphics::Primitive::Driver::TextLayout';

use Pango;

has '_layout' => (
    is => 'rw',
    isa => 'Pango::Layout',
);

sub slice {
    my ($self, $offset, $size) = @_;

    my $lay = $self->_layout;
    my $comp = $self->component;

    if(!defined($size) || ($size > $self->height && !$offset)) {
        # If there was no size or there was a size bigger than this textbox
        # with no offset, give them the whole shebang
        my $clone = $comp->clone;
        $clone->layout($self);
        $clone->minimum_width($self->width + $comp->outside_width);
        $clone->minimum_height($self->height + $comp->outside_height);
        $clone->width($self->width + $comp->outside_width);
        $clone->height($self->height + $comp->outside_height);
        return $clone;
    }

    my $lc = $lay->get_line_count;

    my $found = 0;
    my $using = $comp->outside_height;
    # This component is too big to fit!
    if($using >= $size) {
        return undef;
    }
    my @lines;

    my $start = undef;
    my $count = 0;
    for(my $i = 0; $i < $lc; $i++) {
        my $line = $lay->get_line_readonly($i);
        my ($ink, $log) = $line->get_pixel_extents;
        my $lh = $log->{height};

        last if (($lh + $using) > $size);
        if(($found + $using) >= $offset) {
            unless(defined($start)) {
                $start = $i;
            }
            $count++;
            $using += $lh;
        }
        $found += $lh;
    }

    # We didn't find any lines that fit, so just return nothing
    if($count == 0) {
        return undef;
    }

    return $comp->clone(
        height => $using,
        layout => $self,
        lines => { start => $start , count => $count },
        minimum_width => $self->width + $comp->outside_width,
        minimum_height => $using,
        prepared => 0,
        width => $self->width + $comp->outside_width,
    );
}

no Moose;
1;
__END__