-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with transparent fadings in cmyk colour model #1057
Comments
Before 65da52f there were no shadings in the CMYK colorspace. They were all RGB. |
At least for pdf.js and Poppler's cairo backend the underlying issue is that Luminosity softmasks are always calculated in RGB (independent of the colorspace specified for the transparency group) and the used CMYK to RGB conversion does not preserve black. I fear that this might not be fixable from PGF. |
@zauguin Thanks for all this information! This does indeed not sound very promising :( |
As a workaround you can switch to |
@hmenke Thanks for the suggestion. I'll look into this and see how far this gets me. Shall I close this issue as it is essentially a viewer issue or do you want to keep this around in case other users stumble over this as well? |
I remain very unconvinced about the tikz fading code. If I'm printing I flatten any transparent fadings. The above MWE still exhibits the same problems as issue #824 for me. And RGB does not help. I do admit that I made no attempt to deal with transparency in my CMYK and grayscale shading code. FWIW, these viewers display a transparent rectangle: Adobe*, mupdf, GhostScript. And in addition to @zauguin's comments, these viewers/libraries have trouble: chromium/pdfium, Scribus PDF library |
I reckon it would be useful to compare analogous PDF produced by Adobe Illustrator and whether this works across common viewers. Attached is a fading produced by Scribus that runs from 90% transparent Magenta through to 100% transparent Magenta. This displays correctly in all viewers (i.e., right hand side really is completely transparent) and doesn't crash Adobe Reader when converting to PostScript. If |
@dcpurton Thanks for investigating! I can confirm that your |
Perhaps at the very least, the pre-defined fadings should be declared in grayscale and a note added to the manual that any new fadings should be defined in grayscale. Even if RGB works, I think grayscale is probably a better choice. The colour model could be switched to gray at the beginning of e.g., diff --git a/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfadings.code.tex b/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfadings.code.tex
index bddc83cb..2b3dfde4 100644
--- a/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfadings.code.tex
+++ b/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibraryfadings.code.tex
@@ -18,11 +18,14 @@
\def\tikzfadingfrompicture{%
\begingroup%
\setbox\pgfpic=\hbox\bgroup%
+ \XC@sdef\pgf@saved@color@model{\XC@tgt@mod{natural}}%
+ \selectcolormodel{gray}
\tikzpicture%
}%
\def\endtikzfadingfrompicture{%
\global\let\tikz@smuggle=\tikz@fig@name%
\endtikzpicture
+ \selectcolormodel{\pgf@saved@color@model}%
\egroup%
\pgfdeclarefading{\tikz@smuggle}{\box\pgfpic}%
\endgroup%
@@ -37,11 +40,14 @@
\setbox\pgfpic=\hbox{%
\tikzset{#1}%
\global\let\tikz@smuggle=\tikz@fig@name%
+ \XC@sdef\pgf@saved@color@model{\XC@tgt@mod{natural}}%
+ \selectcolormodel{gray}
\tikz{%
\useasboundingbox(0,0) (100bp,100bp);
\node at (50bp,50bp) [rotate=\tikz@shade@angle]
{\pgfuseshading{\tikz@shading}};
}%
+ \selectcolormodel{\pgf@saved@color@model}%
}%
\pgfdeclarefading{\tikz@smuggle}{\box\pgfpic}%
}%
diff --git a/tex/generic/pgf/libraries/pgflibraryfadings.code.tex b/tex/generic/pgf/libraries/pgflibraryfadings.code.tex
index c8ce556b..ba08a46b 100644
--- a/tex/generic/pgf/libraries/pgflibraryfadings.code.tex
+++ b/tex/generic/pgf/libraries/pgflibraryfadings.code.tex
@@ -10,6 +10,11 @@
\ProvidesFileRCS{pgflibraryfadings.code.tex}
+% Fadings must be defined in grayscale
+
+\XC@sdef\pgf@saved@color@model{\XC@tgt@mod{natural}}%
+\selectcolormodel{gray}%
+
% Axial fadings
\pgfdeclarehorizontalshading{pgf@lib@fade@east}{100bp}
@@ -55,3 +60,5 @@
color(0pt)=(pgftransparent!100); color(21.25bp)=(pgftransparent!100); color(23.125bp)=(pgftransparent!0);
color(25bp)=(pgftransparent!100); color(50bp)=(pgftransparent!100)}%
\pgfdeclarefading{fuzzy ring 15 percent}{\pgfuseshading{tikz@lib@fade@fuzzy@15}}%
+
+\selectcolormodel{\pgf@saved@color@model}% This doesn't fix everything (in particular Adobe Reader still crashes for me and it won't help if you build your fading using the \documentclass{article}
\pagestyle{empty}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns}
\tikzfading[name=mymask,
left color=transparent!90,
right color=transparent!100]
\begin{document}
\begin{tikzpicture}
\path[fill=magenta, path fading=mymask] (0,0) rectangle (5,5);
\end{tikzpicture}
\begin{tikzpicture}
\path[fill=magenta, path fading=east] (0,0) rectangle (5,5);
\end{tikzpicture}
\begin{tikzfadingfrompicture}[name=fade right with circle]
\shade[left color=transparent!0,
right color=transparent!100] (0,0) rectangle (2,2);
\fill[transparent!50] (1,1) circle (0.7);
\end{tikzfadingfrompicture}
% Now we use the fading in another picture:
\begin{tikzpicture}
% Background
\fill [black!20] (-1.2,-1.2) rectangle (1.2,1.2);
\pattern [pattern=checkerboard,pattern color=black!30]
(-1.2,-1.2) rectangle (1.2,1.2);
\fill [path fading=fade right with circle,cyan] (-1,-1) rectangle (1,1);
\end{tikzpicture}
\end{document} |
OK, slight lie. Scribus and Inkscape (internal and Poppler/Cairo) still have problems importing this PDF. (Inkscape does not have problems importing the But everything else I test views it OK (Adobe*, Chromium, Firefox, GhostScript, mupdf, poppler based viewers). |
Not very surprised that inkscapes misbehaves :) I love the program, but it often does not cope well with transparency/fadings/shadings. I've had problems with pdfs from all kind of sources... |
Brief outline of the bug
Since commit 65da52f there seems to be a problem with transparent fadings if the cmyk colour model is used. In other colour models the following mwe would result in a transparent rectangle, but in cmyk it gives a baby pink shape.
Minimal working example (MWE)
(related issue from beamer josephwright/beamer#718 )
The text was updated successfully, but these errors were encountered: