Created attachment 118551 [details]
fix rotated strokes and images in Win32 printing surfaces
In Firefox, we noticed that when printing a PDF including rotations from pdf.js that both images and stroked paths would fail to show up in many print drivers.
We tracked this down to two bugs in cairo-win32-printing-surface.c.
The first bug is that stroked path are both being transformed by Cairo with the CTM, and then later again by supplying the CTM to GDI when StrokePath is called. Some print drivers ignore the transform and appear to work, others honor the transform and stuff fails to work, since the path is then double-transformed. So we just removed the big about supplying the transform to GDI and all is well again.
The second bug involves image patterns. StretchDIBits under some printing devices is simply broken if you give it a rotation transform. As a simple workaround that we found worked on all printer drivers we tested with, we just swap the X and Y axes of the image before giving it to StretchDIBits, so the rotation transform becomes a harmless scale and/or mirror that the drivers will honor.
Between these two, pdf.js printing resumed working for us.
The upstream Firefox bug report is here:
We've attached our patch that resolves the issue and it would be nice if we could get this upstreamed.
I've added some comments to the upstream bug.