# “unrotate” part of a \pgfdeclareshape

I was trying to work on a very nice question about building chips for circuitikz, and I have a problem. I reduced it to this MWE:

\documentclass[tikz, border=2mm]{standalone}

\pgfdeclareshape{chip}{
\savedanchor\center{\pgfpoint{0pt}{0pt}}
\anchor{center}{\center}
\backgroundpath{%
\pgfpathrectanglecorners{\pgfpoint{-.5cm}{-1cm}}%
{\pgfpoint{.5cm}{1cm}}%
\pgftext[right, at=\pgfpoint{.5cm}{0.5cm}]{\tiny 1\ }
\pgftext[right, at=\pgfpoint{.5cm}{-0.5cm}]{\tiny 12\ }
\pgftext[left, at=\pgfpoint{-.5cm}{0.5cm}]{\tiny\ 3}
\pgftext[left, at=\pgfpoint{-.5cm}{-0.5cm}]{\tiny\ 14}
}%
}

\begin{document}

\begin{tikzpicture}
\node [chip, draw] (A) {A};
\node [chip, draw, rotate=-90](B) at (2,2){B};
\node [chip, draw, rotate=-180](C) at (2,0){C};
\end{tikzpicture}

\end{document}


which produces the following thing:

Which is almost ok. The position of the labels (especially the small numbers) is ok, but --- is it possible to change the shape definition in order to unrotate them? Even if it's only for multiples of 90 degrees woyld be ok.

If there is a way to "read" the rotation from inside the shape, I could for example use ifs to have 4 cases, or something similar.

• Des not Mark Wibrows answer solve this? (If you want to continue along the path you outline here, you may want to save the point anchors of the text positions and then add \pgftransformresetnontranslations before adding the texts.) – marmot Feb 5 at 21:26
• @marmot, the cited answer adds the labels after drawing the pin numbers, outside the shape, while I'd like to have the numbers drawn automatically (in my full code, they're automatically drawn). The other idea could be nice... But I don't know how to use it. – Rmano Feb 5 at 21:37
• You want to "unrotate", ok. But what is your reference? The current node, the current path, the current scope, the current tikzpicture, the current box, the current page? – Paul Gaborit Feb 5 at 22:05
• \backgroundpath{% \pgfpathrectanglecorners{\pgfpoint{-.5cm}{-1cm}}% {\pgfpoint{.5cm}{1cm}}% \pgfcoordinate{RmanoTR}{\pgfpoint{.3cm}{0.5cm}} \pgfcoordinate{RmanoTL}{\pgfpoint{-.3cm}{0.5cm}} \pgfcoordinate{RmanoBR}{\pgfpoint{.3cm}{-0.5cm}} \pgfcoordinate{RmanoBL}{\pgfpoint{-.3cm}{-0.5cm}} \pgftransformresetnontranslations \pgftext[at=\pgfpointanchor{RmanoTR}{center}]{\tiny 1\ } \pgftext[at=\pgfpointanchor{RmanoBR}{center}]{\tiny 12\ } \pgftext[at=\pgfpointanchor{RmanoTL}{center}]{\tiny\ 3} \pgftext[at=\pgfpointanchor{RmanoBL}{center}]{\tiny\ 14} }%? – marmot Feb 5 at 22:13
• @PaulGaborit good question... I think the current tikzpicture would be nice. – Rmano Feb 5 at 22:35

Here is a proposal. The issue is that the keys right, left, top and bottom are discretized, meaning that the result won't look good for all possible rotation angles.

1. \pgfgettransformentries\a\b\temp\temp\temp\temp reads the entries of the rotation matrix out. Notice that this version of the answer assumes that you do not do any stretching. The rotation angle is computed.
2. Then the quadrant mod 2 is determined in order to toggle from right and left to top and bottom aligned texts.
3. The entries are "unrotated".

\documentclass[tikz, border=2mm]{standalone}

\pgfdeclareshape{chip}{
\savedanchor\center{\pgfpoint{0pt}{0pt}}
\anchor{center}{\center}
\backgroundpath{%
\pgfpathrectanglecorners{\pgfpoint{-.5cm}{-1cm}}%
{\pgfpoint{.5cm}{1cm}}%
\pgfgettransformentries\a\b\temp\temp\temp\temp
\pgfmathsetmacro{\rot}{-atan2(\b,\a)}
\pgftext[rotate=\rot,right, at=\pgfpoint{.5cm}{0.5cm}]{\tiny 1\ }
\pgftext[rotate=\rot,right, at=\pgfpoint{.5cm}{-0.5cm}]{\tiny 12\ }
\pgftext[rotate=\rot,left, at=\pgfpoint{-.5cm}{0.5cm}]{\tiny\ 3}
\pgftext[rotate=\rot,left, at=\pgfpoint{-.5cm}{-0.5cm}]{\tiny\ 14}
\or
\pgftext[rotate=\rot,top, at=\pgfpoint{.5cm}{0.45cm}]{\tiny 3\ }
\pgftext[rotate=\rot,bottom, at=\pgfpoint{.5cm}{-0.45cm}]{\tiny 1\ }
\pgftext[rotate=\rot,top, at=\pgfpoint{-.5cm}{0.45cm}]{\tiny\ 14}
\pgftext[rotate=\rot,bottom, at=\pgfpoint{-.5cm}{-0.45cm}]{\tiny\ 12}
\or
\pgftext[rotate=\rot,right, at=\pgfpoint{.5cm}{0.5cm}]{\tiny 14\ }
\pgftext[rotate=\rot,right, at=\pgfpoint{.5cm}{-0.5cm}]{\tiny 3\ }
\pgftext[rotate=\rot,left, at=\pgfpoint{-.5cm}{0.5cm}]{\tiny\ 12}
\pgftext[rotate=\rot,left, at=\pgfpoint{-.5cm}{-0.5cm}]{\tiny\ 1}
\or
\pgftext[rotate=\rot,top, at=\pgfpoint{.5cm}{0.45cm}]{\tiny 12\ }
\pgftext[rotate=\rot,bottom, at=\pgfpoint{.5cm}{-0.45cm}]{\tiny 14\ }
\pgftext[rotate=\rot,top, at=\pgfpoint{-.5cm}{0.45cm}]{\tiny\ 1}
\pgftext[rotate=\rot,bottom, at=\pgfpoint{-.5cm}{-0.45cm}]{\tiny\ 3}
\fi
}%
}

\begin{document}

\begin{tikzpicture}
\node [chip, draw] (A) {A};
\node [chip, draw, rotate=-90](B) at (2,2){B};
\node [chip, draw, rotate=-180](C) at (2,0){C};
\node [chip, draw, rotate=90](B) at (0,2){D};
\end{tikzpicture}

\end{document}


When reading the question, I was not sure if you want to "unrotate" the main labels as well. If you do, then one may need to use a different approach (I have not tried doing this).

• Thanks for the idea; almost there. The only problem is that this way the pin number's order is wrong - it should remain the same, as if the box is rotated rigidly. Probably I need to do the full 4 quadrants cases. – Rmano Feb 6 at 7:48
• @Rmano My bad. Originally I had four cases, which is why there was an \ifcase. I did not look carefully and thought one needs only two. Now I went back to 4 cases. – marmot Feb 6 at 15:42