[glabels/vala] Workaround for pango kerning bug.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/vala] Workaround for pango kerning bug.
- Date: Thu, 22 May 2014 02:35:26 +0000 (UTC)
commit 0de454afee7a9f9da423c4af4b0ffe63974eb12d
Author: Jim Evins <evins snaught com>
Date: Wed May 21 22:33:20 2014 -0400
Workaround for pango kerning bug.
Fixes bug #698777. This is a workaround for pango-cairo bug #700592, which is
a regression of bug #341481 which was originally fixed back in 2009. This
workaround works by rendering the font at device scale rather than world scale.
To make this work the actual font size is manually scaled appropriately to
compensate for this.
glabels/label_object_text.vala | 38 ++++++++++++++++++++++++++++++--------
1 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/glabels/label_object_text.vala b/glabels/label_object_text.vala
index a27af10..99fa03e 100644
--- a/glabels/label_object_text.vala
+++ b/glabels/label_object_text.vala
@@ -436,7 +436,18 @@ namespace glabels
private void set_text_path( Cairo.Context cr, bool in_editor, MergeRecord? record )
{
+ /*
+ * Workaround for pango Bug#700592, which is a regression of Bug#341481.
+ * Render font at device scale and scale font size accordingly.
+ */
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ cr.device_to_user_distance( ref scale_x, ref scale_y );
+ scale_x = Math.fabs( scale_x );
+ scale_y = Math.fabs( scale_y );
+
cr.save();
+ cr.scale( scale_x, scale_y );
TextLines lines = get_lines();
string text = lines.expand( record );
@@ -463,13 +474,13 @@ namespace glabels
Pango.FontDescription desc = new Pango.FontDescription();
desc.set_family( font_family );
desc.set_weight( font_weight );
- desc.set_size( (int)(scaled_font_size * Pango.SCALE + 0.5) );
+ desc.set_size( (int)(scaled_font_size * Pango.SCALE/scale_x + 0.5) );
desc.set_style( style );
layout.set_font_description( desc );
layout.set_text( text, -1 );
- layout.set_spacing( (int)(scaled_font_size * (text_line_spacing-1) * Pango.SCALE +
0.5) );
- layout.set_width( (int)(w * Pango.SCALE + 0.5) );
+ layout.set_spacing( (int)(scaled_font_size * (text_line_spacing-1) *
Pango.SCALE/scale_x + 0.5) );
+ layout.set_width( (int)(w * Pango.SCALE/scale_x + 0.5) );
layout.set_wrap( Pango.WrapMode.WORD );
layout.set_alignment( text_alignment );
@@ -480,17 +491,17 @@ namespace glabels
switch (text_valignment)
{
case ValignType.CENTER:
- y = (h - ih) / 2;
+ y = (h/scale_x - ih) / 2;
break;
case ValignType.BOTTOM:
- y = h - ih;
+ y = h/scale_x - ih;
break;
default:
y = 0;
break;
}
- cr.move_to( TEXT_MARGIN, y );
+ cr.move_to( TEXT_MARGIN/scale_x, y );
Pango.cairo_layout_path( cr, layout );
cr.restore();
@@ -499,7 +510,18 @@ namespace glabels
private void set_empty_text_path( Cairo.Context cr )
{
+ /*
+ * Workaround for pango Bug#700592, which is a regression of Bug#341481.
+ * Render font at device scale and scale font size accordingly.
+ */
+ double scale_x = 1.0;
+ double scale_y = 1.0;
+ cr.device_to_user_distance( ref scale_x, ref scale_y );
+ scale_x = Math.fabs( scale_x );
+ scale_y = Math.fabs( scale_y );
+
cr.save();
+ cr.scale( scale_x, scale_y );
Pango.Layout layout = Pango.cairo_create_layout( cr );
@@ -511,13 +533,13 @@ namespace glabels
Pango.FontDescription desc = new Pango.FontDescription();
desc.set_family( "Sans" );
desc.set_weight( Pango.Weight.NORMAL );
- desc.set_size( (int)(12 * FONT_SCALE * Pango.SCALE) );
+ desc.set_size( (int)(12 * FONT_SCALE * Pango.SCALE/scale_x + 0.5) );
desc.set_style( Pango.Style.NORMAL );
layout.set_font_description( desc );
layout.set_text( _("Text"), -1 );
- cr.move_to( TEXT_MARGIN, 0 );
+ cr.move_to( TEXT_MARGIN/scale_x, 0 );
Pango.cairo_layout_path( cr, layout );
cr.restore();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]