c91a7b
@@ -, +, @@ 
c91a7b
---
c91a7b
 src/libpaps.c | 40 +++++++++++++++++++++++++++++-----------
c91a7b
 1 file changed, 29 insertions(+), 11 deletions(-)
c91a7b
--- a/src/libpaps.c	
c91a7b
+++ a/src/libpaps.c	
c91a7b
@@ -251,7 +251,6 @@ gchar *paps_layout_line_to_postscript_strdup(paps_t *paps_,
c91a7b
 {
c91a7b
   paps_private_t *paps = (paps_private_t*)paps_;
c91a7b
   GString *layout_str = g_string_new("");
c91a7b
-  gchar *ret_str;
c91a7b
 
c91a7b
   add_line_to_postscript(paps,
c91a7b
 			 layout_str,
c91a7b
@@ -259,10 +258,7 @@ gchar *paps_layout_line_to_postscript_strdup(paps_t *paps_,
c91a7b
 			 pos_y,
c91a7b
 			 layout_line);
c91a7b
 
c91a7b
-  ret_str = layout_str->str;
c91a7b
-  g_string_free(layout_str, FALSE);
c91a7b
-
c91a7b
-  return ret_str;
c91a7b
+  return g_string_free(layout_str, FALSE);
c91a7b
 }
c91a7b
 
c91a7b
 static void
c91a7b
@@ -408,9 +404,26 @@ static void draw_contour(paps_private_t *paps,
c91a7b
 {
c91a7b
   GSList *runs_list;
c91a7b
   double scale = 72.0 / PANGO_SCALE  / PAPS_DPI; 
c91a7b
+  PangoGlyphUnit avg_width = 1;
c91a7b
 
c91a7b
   g_string_append(layout_str, "(");
c91a7b
-  
c91a7b
+
c91a7b
+  if (paps->cpi > 0.0L)
c91a7b
+    {
c91a7b
+      /* calculate approximate width per a character */
c91a7b
+      for (runs_list = pango_line->runs; runs_list != NULL; runs_list = g_slist_next(runs_list))
c91a7b
+	{
c91a7b
+	  PangoLayoutRun *run = runs_list->data;
c91a7b
+	  PangoGlyphString *glyphs = run->glyphs;
c91a7b
+	  int i;
c91a7b
+
c91a7b
+	  for (i = 0; i < glyphs->num_glyphs; i++)
c91a7b
+	    {
c91a7b
+	      if (glyphs->glyphs[i].glyph != PANGO_GLYPH_EMPTY)
c91a7b
+		avg_width = MAX (avg_width, glyphs->glyphs[i].geometry.width);
c91a7b
+	    }
c91a7b
+	}
c91a7b
+    }
c91a7b
   /* Loop over the runs and output font info */
c91a7b
   runs_list = pango_line->runs;
c91a7b
   double x_pos = line_start_pos_x;
c91a7b
@@ -433,11 +446,16 @@ static void draw_contour(paps_private_t *paps,
c91a7b
           glyph_pos_x = x_pos + 1.0*geometry.x_offset * scale;
c91a7b
           glyph_pos_y = line_start_pos_y - 1.0*geometry.y_offset * scale;
c91a7b
 
c91a7b
-	  if (paps->cpi > 0.0L) {
c91a7b
-		  x_pos += (1 / paps->cpi * 72.0);
c91a7b
-	  } else {
c91a7b
-		  x_pos += geometry.width * scale * paps->scale_x;
c91a7b
-	  }
c91a7b
+	  if (paps->cpi > 0.0L)
c91a7b
+	    {
c91a7b
+	      double n = ((double)geometry.width) / avg_width;
c91a7b
+
c91a7b
+	      x_pos += n * (1 / paps->cpi * 72.0);
c91a7b
+	    }
c91a7b
+	  else
c91a7b
+	    {
c91a7b
+	      x_pos += geometry.width * scale * paps->scale_x;
c91a7b
+	    }
c91a7b
 
c91a7b
           if (glyphs->glyphs[glyph_idx].glyph == PANGO_GLYPH_EMPTY)
c91a7b
             continue;
c91a7b
--