I do not know if this is expected or not; this is probably a very dumb operator error, but consider the following MWE:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\pgfdeclareshape{sline}{
\anchor{center}{\pgfpointorigin}%
\behindbackgroundpath{
% \pgfsetcolor{.}% <- line B
% \pgfsetfillcolor{red}% <- line A
\pgfpathmoveto{\pgfpoint{-0.3cm}{0pt}}%
\pgfpathlineto{\pgfpoint{0.3cm}{0pt}}%
\pgfnode{circle}{center}{}{}{\pgfusepath{stroke,fill}}%
\pgftext[top,y=0.4cm]{zzz}%
\pgfusepath{draw}%
}
}
\begin{document}
Text
\begin{tikzpicture}[]
\draw[] (0,1) node [sline]{} (1,1) node{aaa};
\draw[blue, fill=green] (0,0) node [sline]{} (1,0) node{aaa};
\end{tikzpicture}
\end{document}
Which result in:
What is quite puzzling is the fact that "zzz" is following the fill color of the shape and not the stroke color. I tried to find something in the manual, to no avail.
What I would like is that the shape could follow the external "fill" parameter (either in the draw, or in the shape itself) but the text should follow the draw color, like "aaa" is doing (or at least following the external current color).
Uncommenting line B
gives the "fill and stroke as the current color", as expected (\pgfsetcolor
sets both stroke and fill):
...and uncommenting both line A and line B gives a fixed red fill and red text.
Commenting just line B gives:
In conclusion, it seems that the text created by \pgftext
is colored with the fill color and colored with the current color only if the fill color is undefined. Is this the expected behavior?
\pgftext
and normal text are colored with the fill color. You can play with this pdf literal example:\Huge text \pdfliteral page{q 2 Tr 1 0 0 rg 0 1 0 RG .5 w}text\pdfliteral page{Q} text
. Here2 Tr
sets the rendering mode to "fill, then stroke text" (the default is fill only),1 0 0 rg
sets the fill color red, and0 1 0 RG
sets the stroke color green.\pgftext
setting locally the color to the default one... is there something as\pgf@textcolor
defined if the user saysnode[blub, text=red]
?