summaryrefslogtreecommitdiff
path: root/lib/GridFiller/Result/Pango.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GridFiller/Result/Pango.pm')
-rw-r--r--lib/GridFiller/Result/Pango.pm35
1 files changed, 34 insertions, 1 deletions
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 {