File cairo-1.10.2-print.patch of Package mingw32-cairo
diff -Naur cairo-1.10.2.orig/src/cairo-win32-printing-surface.c cairo-1.10.2/src/cairo-win32-printing-surface.c
--- cairo-1.10.2.orig/src/cairo-win32-printing-surface.c 2010-12-25 15:21:34.000000000 +0100
+++ cairo-1.10.2/src/cairo-win32-printing-surface.c 2011-07-15 12:42:15.956451675 +0200
@@ -611,7 +611,7 @@
RECT clip;
const cairo_color_t *background_color;
const unsigned char *mime_data;
- unsigned long mime_size;
+ unsigned long mime_size = 0;
cairo_image_info_t mime_info;
cairo_bool_t use_mime;
DWORD mime_type;
@@ -726,6 +726,7 @@
}
oldmode = SetStretchBltMode(surface->dc, HALFTONE);
+ SetBrushOrgEx(surface->dc, 0, 0, NULL);
GetClipBox (surface->dc, &clip);
if (extend == CAIRO_EXTEND_REPEAT || extend == CAIRO_EXTEND_REFLECT) {
@@ -742,7 +743,7 @@
for (y_tile = top; y_tile < bottom; y_tile++) {
for (x_tile = left; x_tile < right; x_tile++) {
- if (!StretchDIBits (surface->dc,
+ int success = StretchDIBits (surface->dc,
x_tile*opaque_image->width,
y_tile*opaque_image->height,
opaque_image->width,
@@ -752,10 +753,40 @@
use_mime ? mime_info.width : opaque_image->width,
use_mime ? mime_info.height : opaque_image->height,
use_mime ? mime_data : opaque_image->data,
- &bi,
+ &bi,
DIB_RGB_COLORS,
- SRCCOPY))
- {
+ SRCCOPY);
+
+ if (!success && !use_mime) {
+ // Fallback for when StretchDIBits fails: devide up the
+ // bitmap source in strips and stretch the pieces individually.
+ const int maxstripsize = 128;
+ int todo, stripsize, strip;
+ strip = 0;
+ todo = opaque_image->height;
+ while (todo) {
+ stripsize = min(maxstripsize, todo);
+ bi.bmiHeader.biHeight = -stripsize;
+ success = StretchDIBits (surface->dc,
+ x_tile*opaque_image->width,
+ y_tile*opaque_image->height + strip*maxstripsize,
+ opaque_image->width,
+ stripsize,
+ 0,
+ 0,
+ opaque_image->width,
+ stripsize,
+ opaque_image->data +
+ opaque_image->width*strip*maxstripsize*(32/8),
+ &bi,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ if (!success) break;
+ todo -= stripsize;
+ strip++;
+ }
+ }
+ if (!success) {
status = _cairo_win32_print_gdi_error ("_cairo_win32_printing_surface_paint(StretchDIBits)");
goto CLEANUP_OPAQUE_IMAGE;
}