From 0c05aa60f5bfa4b6f280aedec684c20aed793a90 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Jul 2008 21:12:28 +0930 Subject: [PATCH] PDF: Limit precision of Td operands As the translation is in text space, the full precision of a double for numbers close to zero is not required. Limit the precision to the same as for numbers > 1. --- src/cairo-pdf-operators.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c index 4aec095a0..da0191972 100644 --- a/src/cairo-pdf-operators.c +++ b/src/cairo-pdf-operators.c @@ -985,6 +985,8 @@ _cairo_pdf_operators_set_text_matrix (cairo_pdf_operators_t *pdf_operators, return _cairo_output_stream_get_status (pdf_operators->stream); } +#define TEXT_MATRIX_TOLERANCE 1e-6 + /* Set the translation components of the PDF text matrix to x, y. The * 'Td' operator is used to transform the text matrix. */ @@ -1009,6 +1011,10 @@ _cairo_pdf_operators_set_text_position (cairo_pdf_operators_t *pdf_operators, pdf_operators->text_matrix.x0 = x; pdf_operators->text_matrix.y0 = y; cairo_matrix_multiply (&translate, &pdf_operators->text_matrix, &inverse); + if (fabs(translate.x0) < TEXT_MATRIX_TOLERANCE) + translate.x0 = 0.0; + if (fabs(translate.y0) < TEXT_MATRIX_TOLERANCE) + translate.y0 = 0.0; _cairo_output_stream_printf (pdf_operators->stream, "%f %f Td\n", translate.x0,