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