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.pm45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/GridFiller/Result/Pango.pm b/lib/GridFiller/Result/Pango.pm
index 28c697b..a1df972 100644
--- a/lib/GridFiller/Result/Pango.pm
+++ b/lib/GridFiller/Result/Pango.pm
@@ -3,6 +3,7 @@ use Moose;
use namespace::autoclean;
use GridFiller::Constants ':directions';
use MooseX::Types::Moose qw(Int);
+use GridFiller::Types qw(FontDescrT FontOptT);
use Cairo;
use Pango;
use Carp;
@@ -77,6 +78,44 @@ sub _build__cairo_c {
return $cr;
}
+has font_description => (
+ is => 'ro',
+ isa => FontDescrT,
+ coerce => 1,
+ lazy_build => 1,
+ trigger => \&_adjust_font_description,
+);
+
+sub _build_font_description {
+ my ($self)=@_;
+
+ my $fd = Pango::FontDescription->from_string('Sans 10');
+ return $self->_adjust_font_description($fd);
+}
+
+sub _adjust_font_description {
+ my ($self,$fd) = @_;
+
+ $fd->set_absolute_size($self->cell_size * Pango->scale * 0.8);
+
+ return $fd;
+}
+
+has font_options => (
+ is => 'ro',
+ isa => FontOptT,
+ lazy_build => 1,
+);
+
+sub _build_font_options {
+ my ($self) = @_;
+
+ my $fo = Cairo::FontOptions->create();
+ $fo->set_hint_style('none');
+
+ return $fo;
+}
+
sub _put_squares {
my ($self,$cr) = @_;
@@ -113,6 +152,10 @@ sub layout_for_string {
my ($self,$string) = @_;
my $p = Pango::Cairo::create_layout($self->_cairo_c);
+ Pango::Cairo::Context::set_font_options($p->get_context,$self->font_options);
+ Pango::Cairo::update_context($self->_cairo_c,,$p->get_context);
+ $p->context_changed;
+ $p->set_font_description($self->font_description);
$p->set_text($string);
return $p;
@@ -187,6 +230,8 @@ sub place_word_at {
$cr->move_to($x,$y);
}
else {
+ $p->get_context->set_base_gravity('east');
+ $p->context_changed;
$y+=$adjustment;
$cr->move_to($x+$size,$y);
$cr->rotate($PI/2);