From b4c7485154f73a1cf6b1fc78013f481c5f790c2d Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 22 Dec 2010 15:46:54 +0000 Subject: font choice, and proper vertical rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NOTE: hinting:none and antialias:full is needed to get Japanese displayed correctly… bug? --- lib/GridFiller/Result/Pango.pm | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lib/GridFiller/Result/Pango.pm') 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); -- cgit v1.2.3