Is it possible to (correctly) use patterns inside a pgf shape definition ? For example, I try to define a shape as a rectangle filled with a pattern, like this
\usetikzlibrary{patterns}
\pgfdeclareshape{test shape}
{
\inheritsavedanchors[from=rectangle]
\inheritanchor[from=rectangle]{center}
\backgroundpath
{
\pgfsetfillpattern{north east lines}{.}
\pgfpathrectanglecorners{\pgfpoint{0}{0}}{\pgfpoint{1cm}{1cm}}
\pgfusepath{fill}
}
}
the problem is that \pgfsetfillpattern
needs a color argument :
\pgfsetfillpattern{pattern name}{pattern color}
I want this color to be the color used to draw paths, so I tried to use .
(the current color in the xcolor
package). It doesn't work as expected :
\begin{tikzpicture}
\node[draw=red,test shape] at (0,0) {};
\node[fill=red,test shape] at (2cm,0) {};
\node[color=red,test shape] at (4cm,0) {};
\end{tikzpicture}
produces two black shapes and a red one :
I would expect the first one to be red too. So I have two questions
- is it an easy solution to do it ?
- is it a good idea to use patterns inside a pgf shape ? (And if the answer is no, well, why and what to do instead ?)