summaryrefslogtreecommitdiff
path: root/src/cairo-pdf-operators.c
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2008-03-18 22:29:59 +1030
committerAdrian Johnson <ajohnson@redneon.com>2008-03-20 18:15:10 +1030
commit158b32b60bc7e0f6488383c1d4f83203ffe97c98 (patch)
tree7e79f45f0b0768cadeccf4b439cafa367064b051 /src/cairo-pdf-operators.c
parent222041530cd5d7f1ef6b41ea1738bf395ef1678a (diff)
PDF: Reduce excess decimals in text position offsets
The numbers output in the TJ array for adjusting the horizontal position of the next glyph are in 1/1000 of the text space units. Rounding these numbers to an integer should still provide sufficient precision. We use the rounded numbers to update the text position in pdf-operators so subsequent numbers in the TJ array will compensate for the rounding error.
Diffstat (limited to 'src/cairo-pdf-operators.c')
-rw-r--r--src/cairo-pdf-operators.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 0c7ec581..9c14d619 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -887,10 +887,28 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t *pdf_operators,
} else {
if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
double delta = glyphs[i].x - Tm_x;
-
- _cairo_output_stream_printf (word_wrap_stream,
- "> %f <",
- -1000.0*delta/scaled_font->scale.xx);
+ int rounded_delta;
+
+ delta = -1000.0*delta/scaled_font->scale.xx;
+ /* As the delta is in 1/1000 of a unit of text
+ * space, rounding to an integer should still
+ * provide sufficient precision. We round the
+ * delta before adding to Tm_x so that we keep
+ * track of the accumulated rounding error in
+ * the PDF interpreter and compensate for it
+ * when calculating subsequent deltas.
+ */
+ rounded_delta = _cairo_lround (delta);
+ if (rounded_delta != 0) {
+ _cairo_output_stream_printf (word_wrap_stream,
+ "> %d <",
+ rounded_delta);
+ }
+
+ /* Convert the rounded delta back to cairo
+ * space before adding to the current text
+ * position. */
+ delta = rounded_delta*scaled_font->scale.xx/-1000.0;
Tm_x += delta;
}
_cairo_output_stream_printf (word_wrap_stream,