From e423da62532558968e1a66bc04c193ffffd38d43 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 2 Dec 2010 21:57:14 +0000 Subject: proper length measurement also, fix vertical placement off-by-one --- lib/GridFiller/Chooser/Smarter.pm | 2 ++ lib/GridFiller/Result/Pango.pm | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/GridFiller/Chooser/Smarter.pm b/lib/GridFiller/Chooser/Smarter.pm index fd21dae..43ad530 100644 --- a/lib/GridFiller/Chooser/Smarter.pm +++ b/lib/GridFiller/Chooser/Smarter.pm @@ -16,6 +16,8 @@ sub find_place_for { my $length = $self->length->($word); + $self->log->debug("looking for $length of space"); + my @candidates; push @candidates, $self->_find_places_horiz($length); diff --git a/lib/GridFiller/Result/Pango.pm b/lib/GridFiller/Result/Pango.pm index 504f2a7..81eba04 100644 --- a/lib/GridFiller/Result/Pango.pm +++ b/lib/GridFiller/Result/Pango.pm @@ -83,6 +83,8 @@ sub _put_squares { my $size = $self->cell_size; + $cr->save; + $cr->rectangle(0,0,$self->_width,$self->_height); $cr->set_source_rgb(1,1,1); $cr->fill; @@ -101,15 +103,46 @@ sub _put_squares { $y+=$size; } + $cr->restore; + return; } +sub layout_for_word { + my ($self,$word) = @_; + + my $p = Pango::Cairo::create_layout($self->_cairo_c); + $p->set_text($word); + + return $p; +} + +my $PI=3.1415926; + sub place_word_at { my ($self, $word, $x, $y, $dir) = @_; $self->log->debug("Placing $word at ${x}:${y} ($dir)"); - $self->_cairo_c; + my $p = $self->layout_for_word($word); + my $size = $self->cell_size; + my $cr = $self->_cairo_c; + $x*=$size;$y*=$size; + + $cr->save; + if ($dir == $HORIZONTAL) { + $cr->move_to($x,$y); + } + else { + $cr->move_to($x+$size,$y); + $cr->rotate($PI/2); + } + Pango::Cairo::update_layout($cr,$p); + $cr->set_source_rgb(1,1,0); + Pango::Cairo::show_layout($cr,$p); + $cr->restore; + + return; } sub as_png { -- cgit v1.2.3