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