[cairo-commit] 2 commits - src/cairo-pdf-operators.c test/stroke-ctm-caps-ps-ref.png

Adrian Johnson ajohnson at kemper.freedesktop.org
Fri Mar 14 02:29:35 PDT 2008


 src/cairo-pdf-operators.c       |   36 ++++++++++++++++++++++++++++--------
 test/stroke-ctm-caps-ps-ref.png |binary
 2 files changed, 28 insertions(+), 8 deletions(-)

New commits:
commit 0aef7c1a34b2522d400b5a1a74567a79696216c9
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Mar 10 22:19:52 2008 +1030

    PDF/PS: Optimize away the stroke ctm when not required
    
    The PDF/PS backends change the ctm to user space when emitting and
    stroking a path. When the user space ctm does not alter the pen shape
    we can avoid changing the ctm.
    
    This patch optimizes the most common case where the user ctm is
    [1 0 0 -1 0 y] due to conversion from cairo to PDF coordinates.

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 066a73f..bc22f79 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -575,7 +575,18 @@ _cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
 			     cairo_matrix_t		*ctm_inverse)
 {
     cairo_status_t status;
-    cairo_matrix_t m;
+    cairo_matrix_t m, path_transform;
+    cairo_bool_t has_ctm = TRUE;
+
+    /* Optimize away the stroke ctm when it does not affect the
+     * stroke. There are other ctm cases that could be optimized
+     * however this is the most common.
+     */
+    if (fabs(ctm->xx) == 1.0 && fabs(ctm->yy) == 1.0 &&
+	fabs(ctm->xy) == 0.0 && fabs(ctm->yx) == 0.0)
+    {
+	has_ctm = FALSE;
+    }
 
     status = _cairo_pdf_operators_emit_stroke_style (pdf_operators, style);
     if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
@@ -583,20 +594,29 @@ _cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
     if (status)
 	return status;
 
-    cairo_matrix_multiply (&m, ctm, &pdf_operators->cairo_to_pdf);
-    _cairo_output_stream_printf (pdf_operators->stream,
-				 "q %f %f %f %f %f %f cm\n",
-				 m.xx, m.yx, m.xy, m.yy,
-				 m.x0, m.y0);
+    if (has_ctm) {
+	cairo_matrix_multiply (&m, ctm, &pdf_operators->cairo_to_pdf);
+	path_transform = *ctm_inverse;
+	_cairo_output_stream_printf (pdf_operators->stream,
+				     "q %f %f %f %f %f %f cm\n",
+				     m.xx, m.yx, m.xy, m.yy,
+				     m.x0, m.y0);
+    } else {
+	path_transform = pdf_operators->cairo_to_pdf;
+    }
 
     status = _cairo_pdf_operators_emit_path (pdf_operators,
 					     path,
-					     ctm_inverse,
+					     &path_transform,
 					     style->line_cap);
     if (status)
 	return status;
 
-    _cairo_output_stream_printf (pdf_operators->stream, "S Q\n");
+    _cairo_output_stream_printf (pdf_operators->stream, "S");
+    if (has_ctm)
+	_cairo_output_stream_printf (pdf_operators->stream, " Q");
+
+    _cairo_output_stream_printf (pdf_operators->stream, "\n");
 
     return _cairo_output_stream_get_status (pdf_operators->stream);
 }
commit 2bd15d080c562bfcbced1f6bb586cc1e3cae4555
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Mar 14 19:46:15 2008 +1030

    Add PS reference image for stroke-ctm-caps

diff --git a/test/stroke-ctm-caps-ps-ref.png b/test/stroke-ctm-caps-ps-ref.png
new file mode 100644
index 0000000..63c1064
Binary files /dev/null and b/test/stroke-ctm-caps-ps-ref.png differ


More information about the cairo-commit mailing list