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