[dia/dia-0-97] Bug 573261 - Avoid font kerning problems with pangocairo(fc)



commit c807c3012a4b1f35b87de1972b006a13b36a2a86
Author: Hans Breuer <hans breuer org>
Date:   Fri Feb 14 19:23:44 2014 +0100

    Bug 573261 - Avoid font kerning problems with pangocairo(fc)
    
    There is a recurring bug with pangocairo related to kerning and font scaling.
    See: https://bugzilla.gnome.org/buglist.cgi?quicksearch=341481+573261+700592
    Rather than waiting for another fix let's try to implement the ultimate work
    around. With Pango-1.32 and HarfBuzz the kludge in Pango is gone and apparently
    substituted with a precision problem. If we now use huge fonts when talking
    to Pango and downscale these with cairo it should work with all Pango versions.
    
    Also add a sequence diagram used to understand the problem.
    
    (cherry picked from commit 226fb87f34d4b49e700fb9cb340b49b67fd59540)

 plug-ins/cairo/diacairo-renderer.c |   18 +++++++++++++++---
 samples/Self/pango-kerning-bug.dia |  Bin 0 -> 3089 bytes
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/cairo/diacairo-renderer.c b/plug-ins/cairo/diacairo-renderer.c
index 57f6184..079446e 100644
--- a/plug-ins/cairo/diacairo-renderer.c
+++ b/plug-ins/cairo/diacairo-renderer.c
@@ -315,6 +315,15 @@ set_fillstyle(DiaRenderer *self, FillStyle mode)
   DIAG_STATE(DIA_CAIRO_RENDERER (self)->cr)
 }
 
+/* There is a recurring bug with pangocairo related to kerning and font scaling.
+ * See: https://bugzilla.gnome.org/buglist.cgi?quicksearch=341481+573261+700592
+ * Rather than waiting for another fix let's try to implement the ultimate work
+ * around. With Pango-1.32 and HarfBuzz the kludge in Pango is gone and apparently
+ * substituted with a precision problem. If we now use huge fonts when talking
+ * to Pango and downscale these with cairo it should work with all Pango versions.
+ */
+#define FONT_SIZE_TWEAK (72.0)
+
 static void
 set_font(DiaRenderer *self, DiaFont *font, real height)
 {
@@ -327,7 +336,7 @@ set_font(DiaRenderer *self, DiaFont *font, real height)
 
 #ifdef HAVE_PANGOCAIRO_H
   /* select font and size */
-  pango_font_description_set_absolute_size (pfd, (int)(size * PANGO_SCALE));
+  pango_font_description_set_absolute_size (pfd, (int)(size * FONT_SIZE_TWEAK * PANGO_SCALE));
   pango_layout_set_font_description (renderer->layout, pfd);
   pango_font_description_free (pfd);
 #else
@@ -707,14 +716,17 @@ draw_string(DiaRenderer *self,
     pango_layout_iter_get_line_extents (iter, NULL, &extents);
     shift = alignment == ALIGN_CENTER ? PANGO_RBEARING(extents)/2 :
             alignment == ALIGN_RIGHT ? PANGO_RBEARING(extents) : 0;
+    shift /= FONT_SIZE_TWEAK;
+    bline /= FONT_SIZE_TWEAK;
     cairo_move_to (renderer->cr, pos->x - (double)shift / PANGO_SCALE, pos->y - (double)bline / PANGO_SCALE);
     pango_layout_iter_free (iter);
   }
   /* does this hide bug #341481? */
-  pango_cairo_update_context (renderer->cr, pango_layout_get_context (renderer->layout));
-  pango_layout_context_changed (renderer->layout);
+  cairo_scale (renderer->cr, 1.0/FONT_SIZE_TWEAK, 1.0/FONT_SIZE_TWEAK);
+  pango_cairo_update_layout (renderer->cr, renderer->layout);
 
   pango_cairo_show_layout (renderer->cr, renderer->layout);
+  /* restoring the previous scale */
   cairo_restore (renderer->cr);
 #else
   /* using the 'toy API' */
diff --git a/samples/Self/pango-kerning-bug.dia b/samples/Self/pango-kerning-bug.dia
new file mode 100644
index 0000000..55a6ff9
Binary files /dev/null and b/samples/Self/pango-kerning-bug.dia differ


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]