[cairo-commit] src/cairo-win32-printing-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Tue Mar 25 04:35:52 PDT 2008


 src/cairo-win32-printing-surface.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

New commits:
commit e9906ae2021904c8c3d3a4083786475c102196f7
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Tue Mar 25 21:56:19 2008 +1030

    Win32-Printing: Fix fallback resolution when DC ctm is not identity
    
    And also move the _cairo_surface_set_resolution() into
    _cairo_win32_printing_surface_start_page as the DC ctm may be changed
    between pages.
    
    This bug was found in Inkscape now that they are using the cairo
    win32-printing surface for printing on Windows.

diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c
index 0713ef7..d83b732 100644
--- a/src/cairo-win32-printing-surface.c
+++ b/src/cairo-win32-printing-surface.c
@@ -1419,6 +1419,9 @@ _cairo_win32_printing_surface_start_page (void *abstract_surface)
 {
     cairo_win32_surface_t *surface = abstract_surface;
     XFORM xform;
+    double x_res, y_res;
+    cairo_matrix_t inverse_ctm;
+    cairo_status_t status;
 
     SaveDC (surface->dc); /* Save application context first, before doing MWT */
 
@@ -1431,6 +1434,17 @@ _cairo_win32_printing_surface_start_page (void *abstract_surface)
     surface->ctm.x0 = xform.eDx;
     surface->ctm.y0 = xform.eDy;
     surface->has_ctm = !_cairo_matrix_is_identity (&surface->ctm);
+
+    inverse_ctm = surface->ctm;
+    status = cairo_matrix_invert (&inverse_ctm);
+    if (status)
+	return status;
+
+    x_res = (double) GetDeviceCaps(surface->dc, LOGPIXELSX);
+    y_res = (double) GetDeviceCaps(surface->dc, LOGPIXELSY);
+    cairo_matrix_transform_distance (&inverse_ctm, &x_res, &y_res);
+    _cairo_surface_set_resolution (&surface->base, x_res, y_res);
+
     if (!ModifyWorldTransform (surface->dc, NULL, MWT_IDENTITY))
 	return _cairo_win32_print_gdi_error ("_cairo_win32_printing_surface_start_page:ModifyWorldTransform");
 
@@ -1468,7 +1482,6 @@ cairo_surface_t *
 cairo_win32_printing_surface_create (HDC hdc)
 {
     cairo_win32_surface_t *surface;
-    int xr, yr;
     RECT rect;
 
     surface = malloc (sizeof (cairo_win32_surface_t));
@@ -1504,10 +1517,6 @@ cairo_win32_printing_surface_create (HDC hdc)
     _cairo_surface_init (&surface->base, &cairo_win32_printing_surface_backend,
                          CAIRO_CONTENT_COLOR_ALPHA);
 
-    xr = GetDeviceCaps(hdc, LOGPIXELSX);
-    yr = GetDeviceCaps(hdc, LOGPIXELSY);
-    _cairo_surface_set_resolution (&surface->base, (double) xr, (double) yr);
-
     return _cairo_paginated_surface_create (&surface->base,
                                             CAIRO_CONTENT_COLOR_ALPHA,
 					    surface->extents.width,


More information about the cairo-commit mailing list