summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2010-12-02 21:57:14 +0000
committerdakkar <dakkar@thenautilus.net>2010-12-02 21:57:14 +0000
commite423da62532558968e1a66bc04c193ffffd38d43 (patch)
tree3abfabe318ab23ff0c243cc4b3fc2e0219dc7fe5 /lib
parentfix length for status, begin pango/cairo (diff)
downloadqr-builder-e423da62532558968e1a66bc04c193ffffd38d43.tar.gz
qr-builder-e423da62532558968e1a66bc04c193ffffd38d43.tar.bz2
qr-builder-e423da62532558968e1a66bc04c193ffffd38d43.zip
proper length measurement
also, fix vertical placement off-by-one
Diffstat (limited to 'lib')
-rw-r--r--lib/GridFiller/Chooser/Smarter.pm2
-rw-r--r--lib/GridFiller/Result/Pango.pm35
2 files changed, 36 insertions, 1 deletions
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 {