Bug 71861

Summary: ImageMask disappears or gets wrong transform in SVG output
Product: cairo Reporter: Dmitry Shubin <dshubin>
Component: svg backendAssignee: Emmanuel Pacaud <emmanuel.pacaud>
Status: RESOLVED MOVED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium CC: coolwanglu
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Windows (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Problem PDF file, containing an ImageMask
Result SVG, shows as blank due to misplaced mask
PDF with ImageMask which displays well
Possible fix or workaround, in Cairo code
Result SVG created with patched code

Description Dmitry Shubin 2013-11-21 06:21:53 UTC
Created attachment 89559 [details]
Problem PDF file, containing an ImageMask

ImageMask's in PDF image disappear or get misplaced after conversion to SVG. The mask is present in SVG output, but has very incorrect coordinates. Only seems to affect image masks which are global, i.e. are not attached to other subimages within PDF. Not reproducible with conversion to PNG, PDF or PS.
Comment 1 Dmitry Shubin 2013-11-21 06:24:21 UTC
Created attachment 89560 [details]
Result SVG, shows as blank due to misplaced mask
Comment 2 Dmitry Shubin 2013-11-21 06:26:43 UTC
Created attachment 89561 [details]
PDF with ImageMask which displays well
Comment 3 Dmitry Shubin 2013-11-21 06:43:06 UTC
Created attachment 89562 [details] [review]
Possible fix or workaround, in Cairo code

I am not really sure if this is an actual fix, or only a hack which allows us to workaround the issue. This is also the reason why I report it to Poppler list and not Cairo. 

The patch shall be applied to Cairo source code, in \src directory. Tested with Cairo 1.10.2 and 1.12.14.

The issue is related to the ImageMask's parent element transform. If ImageMask's parent is an image, parent transform multiplied by mask's transform produces correct coordinates. However, if the ImageMask is global, its parent is a rectangle. In this case ImageMask's transform should be written to SVG as is, without multiplication to the parent's matrix.

The patch modifies the logic of saving masks from Cairo context to SVG. If mask's parent is an image, keep existing logic. If it is a rectangle, disregard parent's transformation matrix, and only use the mask's transformation matrix.
Comment 4 Dmitry Shubin 2013-11-21 06:50:01 UTC
Created attachment 89563 [details]
Result SVG created with patched code

Compare with the problem result img-X01122206-0001.svg to see the difference in the mask's matrix.
Comment 5 Adrian Johnson 2013-11-22 07:53:41 UTC
(In reply to comment #0)
> Not reproducible with conversion to PNG, PDF or PS.

If the bug only occurs in one of the cairo backends it is a cairo bug.
Comment 6 David Hedley 2014-09-22 21:06:23 UTC
Please note that this image mask bug is still present in Cairo 1.13.1.
Dmitry's patch seems to fix it for my test cases.
Any chance this patch can be integrated into the master branch for 1.13.1?
Comment 7 David Hedley 2014-09-22 21:11:47 UTC
*** Bug 82879 has been marked as a duplicate of this bug. ***
Comment 8 GitLab Migration User 2018-08-25 13:26:08 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/4.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.