diff options
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex | 297 |
1 files changed, 279 insertions, 18 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex index 5f7eba71c8c..3891d152987 100644 --- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex +++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-transparency.tex @@ -65,7 +65,7 @@ following options. \begin{codeexample}[] \begin{tikzpicture}[line width=1ex] \draw (0,0) -- (3,1); - \filldraw [fill=examplefill,draw opacity=0.5] (1,0) rectangle (2,1); + \filldraw [fill=yellow!80!black,draw opacity=0.5] (1,0) rectangle (2,1); \end{tikzpicture} \end{codeexample} \end{key} @@ -188,7 +188,7 @@ option |opacity| sets both at the same time. \end{key} -Note the following effect: If you setup a certain opacity for stroking +Note the following effect: If you set up a certain opacity for stroking or filling and you stroke or fill the same area twice, the effect accumulates: @@ -203,6 +203,185 @@ Often, this is exactly what you intend, but not always. You can use transparency groups, see the end of this section, to change this. + +\subsection{Blend Modes} +\label{section-blend-modes} + +A \emph{blend mode} specifies how colors mix when you paint on a +canvas. Normally, if you paint a red box on a green circle, the red +color will completely replace the green circle. However, in some +situations you might also wish the red color to somehow ``mix'' or +``blend'' with the green circle. We already saw that, using transparency, +we can draw something without completely obscuring the +background. \emph{Blending} is a similar operation, only here we mix +colors in more complicated ways. + +\emph{Note:} Blending is a rather ``advanced'' feature of +\textsc{pdf}. Most renderers, let alone printers, will have trouble +rendering blending correctly. + +\begin{key}{/tikz/blend mode=\meta{mode}} + Sets the current blend mode to \meta{mode}. Here \meta{mode} must be + one of the modes listed below. More details on these modes can also + be found in Section 7.2.4 of the \textsc{pdf} Specification, version 1.7. + + In the following example, the blend mode is only used and set inside + a transparency group (see also + Section~\ref{section-transparency-groups}). This is because most + renderers (viewing + programs) have trouble rendering blending correctly otherwise. For + instance, at the time of writing, the versions of Adobe's Reader and + Apple's Preview render the following drawing very differently, if + the transparency group is not used in the following example. + +\begin{codeexample}[] +\tikz { + \begin{scope}[transparency group] + \begin{scope}[blend mode=screen] + \fill[red!90!black] ( 90:.6) circle (1); + \fill[green!80!black] (210:.6) circle (1); + \fill[blue!90!black] (330:.6) circle (1); + \end{scope} + \end{scope} +} +\end{codeexample} + + Because of the trouble with rendering blending correctly outside + transparency groups, there is a special key that establishes a + transparency group and sets a blend mode simultaneously: + + \begin{key}{/tikz/blend group=\meta{mode}} + This key can only be used with a scope (like + |transparency group|). It will cause the current scope to become a + transparency group and, inside this group, the blend mode will be + set to \meta{mode}. + +\begin{codeexample}[] +\tikz [blend group=screen] { + \fill[red!90!black] ( 90:.6) circle (1); + \fill[green!80!black] (210:.6) circle (1); + \fill[blue!90!black] (330:.6) circle (1); +} +\end{codeexample} + \end{key} + + Here is an overview of the effects of the different available blend + modes. In the examples, we always have three circles drawn on + top of each other (as in the example code earlier): We start with a + triple of pure red, green, and blue. Below it, we have a triple of + light versions of these three colors (|red!50|, |green!50|, and + |blue!50|). Next comes the triple yellow, cyan, and magenta; again + with a triple of light versions below it. The large example consists + of three balls (produced using |ball color|) having the colors red, + green, and blue, are drawn on top of each other just like the + circles. + + \definecolor{rg}{rgb}{1,1,0} + \definecolor{gb}{rgb}{0,1,1} + \definecolor{br}{rgb}{1,0,1} + + \def\makeline#1#2#3{\leavevmode + \hbox to 4cm{#1\hss}\ \hbox to + 2cm{#2\hss}\ \begin{minipage}[t]{9cm}\raggedright#3\end{minipage}\par + \textcolor{black!25}{\hrule height1pt} + } + + \def\showmode#1#2{ + \makeline{ + \tikz [blend mode=#1,baseline=-.5ex] { + \fill[red] ( 90:.5em) circle (.75em); + \fill[green] (210:.5em) circle (.75em); + \fill[blue] (330:.5em) circle (.75em); + \scoped[yshift=-2.5em]{ + \fill[red!50] ( 90:.5em) circle (.75em); + \fill[green!50] (210:.5em) circle (.75em); + \fill[blue!50] (330:.5em) circle (.75em); + } + } + \tikz [blend mode=#1,baseline=-.5ex] { + \fill[rg] ( 90:.5em) circle (.75em); + \fill[gb] (210:.5em) circle (.75em); + \fill[br] (330:.5em) circle (.75em); + \scoped[yshift=-2.5em]{ + \fill[rg!50] ( 90:.5em) circle (.75em); + \fill[gb!50] (210:.5em) circle (.75em); + \fill[br!50] (330:.5em) circle (.75em); + } + } + \tikz [blend mode=#1,baseline=-.5ex+1.25em] { + \shade[ball color=red] ( 90:1em) circle (1.5em); + \shade[ball color=green] (210:1em) circle (1.5em); + \shade[ball color=blue] (330:1em) circle (1.5em); + }}{|#1|}{#2}} + + \medskip + \makeline{\emph{Example}}{\emph{Mode}}{\emph{Explanations quoted from Table 7.2 of the + \textsc{pdf} Specification, Version 1.7}} + \showmode{normal}{When painting a pixel with a some color (called + the ``source color''), the background color + (called the ``backdrop'') is completely ignored.} + \showmode{multiply}{Multiplies the backdrop and source color + values. The result color is always at least as dark as + either of the two constituent colors. Multiplying any color with + black produces black; multiplying with white leaves the original + color unchanged. Painting successive overlapping objects with a + color other than black or white produces progressively darker + colors.} + \showmode{screen}{Multiplies the complements of the backdrop and + source color values, then complements the result. The + result color is always + at least as light as either of the two constituent + colors. Screening any color with white produces white; screening + with black leaves the original color unchanged. The effect is + similar to projecting multiple photographic slides + simultaneously onto a single screen.} + \showmode{overlay}{Multiplies or screens the colors, depending on + the backdrop color value. Source colors overlay the backdrop + while preserving its highlights and shadows. The backdrop color + is not replaced but is mixed with the source color to reflect + the lightness or darkness of the backdrop.} + \showmode{darken}{Selects the darker of the backdrop and source + colors. The backdrop is replaced with the source where the + source is darker; otherwise, it is left unchanged.} + \showmode{lighten}{Selects the lighter of the backdrop and source + colors. The backdrop is replaced with the source where the + source is lighter; otherwise, it is left unchanged.} + \showmode{color dodge}{Brightens the backdrop color to reflect the + source color. Painting with black produces no changes.} + \showmode{color burn}{Darkens the backdrop color to reflect the + source color. Painting with white produces no change.} + \showmode{hard light}{Multiplies or screens the colors, depending + on the source color value. The effect is similar to shining a + harsh spotlight on the backdrop.} + \showmode{soft light}{Darkens or lightens the colors, depending on + the source color value. The effect is similar to shining a + diffused spotlight on the backdrop.} + \showmode{difference}{Subtracts the darker of the two constituent + colors from the lighter color. Painting with white inverts the + backdrop color; painting with black produces no change.} + \showmode{exclusion}{Produces an effect similar to that of the + Difference mode but lower in contrast. Painting with white + inverts the backdrop color; painting with black produces no + change.} + \showmode{hue}{Creates a color with the hue of the source color + and the saturation and luminosity of the backdrop color.} + \showmode{saturation}{Creates a color with the saturation of the + source color and the hue and luminosity of the backdrop + color. Painting with this mode in an area of the backdrop that + is a pure gray (no saturation) produces no change.} + \showmode{color}{Creates a color with the hue and saturation of + the source color and the luminosity of the backdrop color. This + preserves the gray levels of the backdrop and is useful for + coloring monochrome images or tinting color images.} + \showmode{luminosity}{Creates a color with the luminosity of the + source color and the hue and saturation of the backdrop + color. This produces an inverse effect to that of the Color + mode.} + +\end{key} + + + \subsection{Fadings} For complicated graphics, uniform transparency settings are not always @@ -220,7 +399,7 @@ How do we specify a fading? This is a bit of an art since the underlying mechanism is quite powerful, but a bit difficult to use. Let us start with a bit of terminology. A \emph{fading} specifies for -each point of an area to transparency of the point. This transparency +each point of an area the transparency of that point. This transparency can by any number between 0 and 1. A \emph{fading picture} is a normal graphic that, in a way to be described in a moment, determines the transparency of points inside the fading. Each fading has an @@ -236,7 +415,7 @@ opaque is the point in the fading. In particular, a white point of the fading picture is completely opaque in the fading and a black point of the fading picture is completely transparent in the fading. (The background of the fading picture is always transparent in the fading -as if the background where black.) +as if the background were black.) It is rather counter-intuitive that a \emph{white} pixel of the fading picture will be \emph{opaque} in the fading and a \emph{black} pixel @@ -244,7 +423,7 @@ will be \emph{transparent}. For this reason, \tikzname\ defines a color called |transparent| that is the same as |black|. The nice thing about this definition is that the color |transparent!|\meta{percentage} in the fading picture yields a -pixel that is \meta{percentage} per cent transparent in the fading. +pixel that is \meta{percentage} percent transparent in the fading. Turning a fading picture into a normal picture is achieved using the following commands, which are \emph{only defined in the library}, @@ -261,7 +440,7 @@ namely the library |fadings|. So, to use them, you have to say set the name of the fading. You \emph{must} provide this option. \end{key} - The following shading is 2cm by 2cm and changes gets more and more + The following shading is 2cm by 2cm and gets more and more transparent from left to right, but is 50\% transparent for a large circle in the middle. {\tikzexternaldisable @@ -303,6 +482,9 @@ namely the library |fadings|. So, to use them, you have to say \end{tikzpicture} \end{codeexample} }% + + The same effect can also be achieved using knockout groups, see + Section~\ref{section-transparency-groups}. \end{environment} \begin{plainenvironment}{{tikzfadingfrompicture}\oarg{options}} @@ -314,7 +496,7 @@ namely the library |fadings|. So, to use them, you have to say \end{contextenvironment} \begin{command}{\tikzfading\oarg{options}} - This command is used to define a fading similarly to that way a + This command is used to define a fading similarly to the way a shading is defined. In the \meta{options} you should \begin{enumerate} \item use the |name=|\meta{name} option to set a name for the fading, @@ -363,7 +545,7 @@ namely the library |fadings|. So, to use them, you have to say \subsubsection{Fading a Path} -Aa fading specifies for each pixel of a certain area how transparent +A fading specifies for each pixel of a certain area how transparent this pixel will be. The following options are used to install such a fading for the current scope or path. @@ -402,11 +584,11 @@ fading for the current scope or path. \begin{key}{/tikz/fit fading=\meta{boolean} (default true, initially true)} When set to |true|, the fading is shifted and resized (in exactly - the same way as a shading) so that is covers the current + the same way as a shading) so that it covers the current path. When set to |false|, the fading is only shifted so that it is centered on the path's center, but it is not resized. This can be useful for special-purpose fadings, for instance when you use a - fading to ``punsh out'' something. % TODOsp: punsh out --> punch out?? + fading to ``punch out'' something. \end{key} \begin{key}{/tikz/fading transform=\meta{transformation options}} @@ -444,7 +626,7 @@ fading for the current scope or path. \end{tikzpicture} \end{codeexample} - The |fade inside| of the following example more transparent in the middle than on the + The |fade inside| of the following example is more transparent in the middle than on the outside. \begin{codeexample}[] @@ -563,6 +745,7 @@ conjunction, see the end of this section. \subsection{Transparency Groups} +\label{section-transparency-groups} Consider the following cross and sign. They ``look wrong'' because we can see how they were constructed, while this is not really part of @@ -606,9 +789,9 @@ Transparency groups are used to render them correctly: \end{tikzpicture} \end{codeexample} -\begin{key}{/tikz/transparency group} +\begin{key}{/tikz/transparency group=\oarg{options}} This option can be given to a |scope|. It will have the following - effect: The scope's contents is stroked/filled + effect: The scope's contents is stroked\,/\penalty0\,filled ``ignoring any outside transparency.'' This means, all previous transparency settings are ignored (you can still set transparency inside the group, but never mind). For instance, in the forbidden @@ -623,15 +806,93 @@ Transparency groups are used to render them correctly: is just red at the end, so this red color will be blended with whatever is ``behind'' the group on the page. - Note that, depending on the driver, it is possible to directly put - objects in a transparency group that lie outside the picture. This - has to do with internal bounding box computations. - Section~\ref{section-transparency} explains how to sidestep this - problem. +\begin{codeexample}[] +\begin{tikzpicture} + \pattern[pattern=checkerboard,pattern color=black!15](-1,-1) rectangle (3,1); + \node at (0,0) [forbidden sign,line width=2ex,draw=red,fill=white] {Smoking}; + + \begin{scope}[transparency group,opacity=.5] + \node at (2,0) [forbidden sign,line width=2ex,draw=red,fill=white] + {Smoking}; + \end{scope} +\end{tikzpicture} +\end{codeexample} + + Note that in the example, the |opacity=.5| is not active inside the + transparency group: The group is only established at beginning of + the scope and all options given to the |{scope}| environment are set + before the group is established. To change the opacity \emph{inside} + the group, you need to open another scope inside it or use the + |opacity| key with a command inside the group: + +\begin{codeexample}[] +\begin{tikzpicture} + \pattern[pattern=checkerboard,pattern color=black!15](-1,-1) rectangle (3,1); + \node at (0,0) [forbidden sign,line width=2ex,draw=red,fill=white] {Smoking}; + + \begin{scope}[transparency group,opacity=.5] + \node (s) at (2,0) [forbidden sign,line width=2ex,draw=red,fill=white] + {Smoking}; + + \draw [opacity=.5, line width=2ex, blue] (1.2,0) -- (2.8,0); + \end{scope} +\end{tikzpicture} +\end{codeexample} + + The \meta{options} are a list of comma-separated options: + \begin{itemize} + \item \declare{|knockout|} When this option is given inside the + \meta{options}, the group becomes a so-called \emph{knockout} + group. This means, essentially, that inside the group everything + is painted as if the ``opacity'' of a line or area were just + another color channel. In particular, if you paint a pixel with + opacity $0$ inside a knockout group, this pixel becomes perfectly + transparent immediately. In contrast, painting a pixel with + something of opacity 0 normally has no effect. + + Not all renderers, let alone printers, will support + this. At the time of writing, Apple's Preview will not show the + following correctly (you should see the text \tikzname\ in the + middle): +\begin{codeexample}[] +\begin{tikzpicture} + \shade [left color=red,right color=blue] (-2,-1) rectangle (2,1); + \begin{scope}[transparency group=knockout] + \fill [white] (-1.9,-.9) rectangle (1.9,.9); + \node [opacity=0,font=\fontfamily{ptm}\fontsize{45}{45}\bfseries] + {Ti\emph{k}Z}; + \end{scope} +\end{tikzpicture} +\end{codeexample} + In the example, we first draw a large shading and then, inside the + transparency group ``overwrite'' most of this shading by a big + white rectangle. The interesting part is the text of the node, + which has opacity |0|. Normally, this would mean that nothing is + shown. However, in a knockout group, we ``paint'' the text with an + ``opacity zero'' color. The effect is that part of the totally + opaque white rectangle gets overwritten by a perfectly transparent + area (namely exactly the area taken up by the pixels of the + text). When this whole knockout group is then placed on top of the + shading, the shading will ``shine through'' at the knocked-out + pixels. + + \item \declare{|isolated|}|=false| A group can be isolated or + not. By default, they are isolated, since this is typically what you + want. For details on what isolated groups are, exactly, see + Section~7.3.4 of the \textsc{pdf} Specification, version 1.7. + \end{itemize} + + Note that when a transparency group is created, \tikzname\ must + correctly determine the size of the material inside the + group. Usually, this is no problem, but when you use things like + |overlay| or |transform canvas|, trouble may result. In this case, + please consult Section~\ref{section-transparency} on how to sidestep + this problem in such cases. \end{key} + %%% Local Variables: %%% mode: latex %%% TeX-master: "pgfmanual" |