3

I'm am able to invert clipping regions (as discussed in this question) and to use node shapes for clipping (as discussed in this one), but I'd like to combine the two, and I don't see quite how to do that. The following two programs each do half of what I want, sort of.

First, inverted clipping using a manually drawn rectangle around my text node:

\documentclass[tikz,border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}[even odd rule]
    \draw node (a) {000};
    \clip[overlay]
        (current page.south west) rectangle (current page.north east)
        (a.south west) rectangle (a.north east)
        ;
    \fill[overlay, opacity=.2]
        (current page.south west) rectangle (current page.north east)
        ;
\end{tikzpicture}
\end{document}

This gives me:

enter image description here

Then, clipping using the actual path of a rounded rectangle node:

\documentclass[tikz,border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}[even odd rule]
    \pgfnode{rounded rectangle}{center}{000}{a}{\pgfusepath{clip}}
    \fill[overlay, opacity=.2]
        (current page.south west) rectangle (current page.north east)
        ;
\end{tikzpicture}
\end{tikzpicture}
\end{document}

This gives me:

enter image description here

What I'd like is the shape of the latter, but with the inverted clipping behavior of the former. Since the node path seems to be quite encapsulated and isolated, I'm not sure how to combine it with something else for even-odd clipping. I've also tried reconstructing the rounded rectangle drawing myself, using the PGF code, but that looks to be quite a bit of (quite possibly unnecessary) work.

Any tips?

  • Are you trying to achieve something like this? – Symbol 1 Nov 22 '16 at 20:58
  • Thanks! Yes, I guess that's the main usage. Very useful – I was not aware of the knockout option :-) So that might solve the practical problem, but the fact that it's based on viewer-/printer-dependent transparency is perhaps reason enough to still look for a clipping-based solution? – Magnus Lie Hetland Nov 30 '16 at 14:33
2
\documentclass[tikz,border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,shadings}

\begin{document}

\tikzset{
    clip even odd rule/.code={\pgfseteorule}, % Credit to Andrew Stacey 
    invclip/.style={
        clip,insert path=
            [clip even odd rule]{
                [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
            }
    }
}
\begin{tikzpicture}[even odd rule]
    \fill[shading=color wheel white center]circle(1);
    \node[rounded rectangle](a){000};
    \begin{pgfinterruptboundingbox}
        \csname pgf@sh@ma@a\endcsname
        \roundedrectanglepoints
        \clip[invclip](a.south west)arc(270:90:\radius+\outerysep)--(a.north east)arc(90:-90:\radius+\outerysep)--cycle;
    \end{pgfinterruptboundingbox}
    \draw(rand,rand)foreach\i in{0,...,99}{--(rand,rand)};
\end{tikzpicture}

\end{document}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.