Bug 63302

Summary: Mask problem in pdf
Product: cairo Reporter: m2broth <m2broth>
Component: pdf backendAssignee: Adrian Johnson <ajohnson>
Status: RESOLVED MOVED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium    
Version: 1.12.14   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: result of convert svg to pdf
svg
PDF output
test case
test case fixed to turn off interpolation
poppler quick hack

Description m2broth 2013-04-09 10:21:19 UTC
Created attachment 77658 [details]
result of convert svg to pdf

After conveting svg file to pdf using rsvg-convert, when i was opened pdf in Adobe Illustrator there are vector objects with transparenct. There are link of a bug http://i.piccy.info/i7/653f328a0dbeaf90674aee5b78857045/4-57-939/53122784/illustrator.png
Comment 1 Adrian Johnson 2013-04-09 14:10:27 UTC
The PDF file was created using 1.12.2. Please test with 1.2.14 as there have been a few bugs fixed since 1.12.2.

I will also need the SVG file.
Comment 2 m2broth 2013-04-09 14:13:12 UTC
Created attachment 77669 [details]
svg

svg
Comment 3 m2broth 2013-04-09 14:14:14 UTC
I was added svg file. 1.12.14 its version of rsvg-convert? how can i run new version on windows?
Comment 4 Adrian Johnson 2013-04-09 14:28:10 UTC
I used rsvg-convert to convert the svg to pdf. The pdf is displayed correctly by Adobe Reader, Evince, and Ghostscript.
Comment 5 m2broth 2013-04-09 14:29:03 UTC
But try open pdf file in adobe illustrator and you will see what about i speak
Comment 6 m2broth 2013-04-09 14:30:03 UTC
in the first comment i was provide link to screenshot of pdf file in ilustrator
Comment 7 Adrian Johnson 2013-04-09 14:32:30 UTC
I don't have Illustrator. Since the PDF renders correctly in acroread, evince, and ghostscript the bug must be in Illustrator.
Comment 8 m2broth 2013-04-09 14:40:31 UTC
Could you send me please your converted pdf file?
Comment 9 Adrian Johnson 2013-04-09 14:46:24 UTC
Created attachment 77672 [details]
PDF output
Comment 10 m2broth 2013-04-09 15:05:07 UTC
Thanks!
But your pdf file has same bug in illustrator. Could this be a problem with cairo?
Comment 11 m2broth 2013-04-09 15:09:05 UTC
TRy open file in Inkscape. There are same problem as in illustrator. I think the bug in conversion from svg to pdf
Comment 12 m2broth 2013-04-09 15:14:54 UTC
else illustrator rasterize output pdf
Comment 13 Joao S. O. Bueno 2015-07-25 06:11:23 UTC
This bug is present at 1.14.2 - I just detected it affecting GIMP's PDF export in all versions - 
https://bugzilla.gnome.org/show_bug.cgi?id=752819

And the original complaint, with example images at:
http://graphicdesign.stackexchange.com/questions/56710

I hope the fact it is reproducible using GIMP's PDF export makes it easier to track and fix, as there is no need of another minimal program to reproduce it.

(GIMP's plug-in use a call to cairo_paint_with_alpha, but I found out it also happens when calling simply cairo_paint)
Comment 14 Adrian Johnson 2015-10-18 04:47:06 UTC
I ran cairo-trace on rsvg-convert while convert the svg in comment 2 to pdf. It appears rsvg-convert is supplying the mask as a bitmap. I'm not sure why as cairo is capable of rendering the svg with all vector operations which would result in an all vector pdf. This would be the cause of the mask problem.

I need more info for the gimp issue in comment 13. eg a test case and sample pdf output.
Comment 15 Massimo 2015-10-19 07:17:05 UTC
Created attachment 118973 [details]
test case
Comment 16 Massimo 2015-10-19 07:18:33 UTC
(In reply to Massimo from comment #15)
> Created attachment 118973 [details]
> test case

The GIMP issue, as I understood it, is probably a poppler bug
where a raster surface is resampled using unpremultiplied
components and so suffering of color bleeding.
  
the black color attributed to completely transparent pixels
is used interpolating partly transparent pixels and appears
at the border of white shapes drawn above a white background.
  
The attached program saves a pdf that when opened in GIMP
is completely white if you set a resolution of 72 dpi, but
shows the grey arc shape when a different resolution is chosen.

Similarly behaves pdftocairo: the output of

pdftocairo -png -rx 72 -ry 72 bug-63302.pdf bug-63302.72-dpi

is completely white, whereas the output of

pdftocairo -png bug-63302.pdf bug-63302.150-dpi

shows the grey arc outline.
Comment 17 Adrian Johnson 2015-10-19 08:32:49 UTC
Created attachment 118974 [details]
test case fixed to turn off interpolation

The cairo pdf backend embeds images exactly as they are. There is no resampling done. The interpolation is being done by the pdf viewer. You can see the embedded images using pdfimages.

Attached is an updated version of the test case that causes the interpolate flag in the embedded image to be set to false. The problem is pdf viewers may ignore this flag. This can be seen in evince where at higher zoom levels the image is not interpolated and the gray pixels disappear. At lower magnification evince will turn on interpolation to match Adobe Reader behavior.

There really isn't anything that can be done in cairo. The cairo pdf backend is creating a pdf that reproduces the cairo drawing operations supplied to it. It is up to the viewer how it is rendered.

Possible (untested) workarounds:
- Use a higher resolution image
- Ensure the color image is larger than the mask.
Comment 18 Massimo 2015-10-20 10:57:36 UTC
Created attachment 118999 [details] [review]
poppler quick hack

This is a poppler quick hack that fixes the gimp issue

The idea is to combine the image and the soft mask in
image space (so with no resampling needed if they have
the same dimensions) and then paint the result on the
destination in destination space.

I don't have the poppler test suite so I don't know how
much it breaks, but firefox renders the output of my previous
test case completely white and so I think poppler could
do a better job as well.

PS: in the function modified by the quick hack if one of the
first two 'goto cleanup;' is executed 'maskPattern' is leaked.
Comment 19 GitLab Migration User 2018-08-25 13:35:58 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/89.

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.