Tikz-pgf – How to Scale and Clip a Path Simultaneously?

path-clippingpathsscopingtikz-pgf

Again, i started a question here, and i found the solution. But i think this method maybe useful for others.

The problem: i exported the TikZ code of one path from Inkscape; then, i wanted to use it in a tikzpicture. It's easy, if i put it in one other tikzpicture, scaling with x,y parameters, inside a \node. But i wanted to use the path for clipping, what is inpossible, if the path is inside a \node and tikzpicture, or an other \scope.

The exported path looks like this (for example):

\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(-80.842417,-451.55478)}]% layer1
 % path9658
  \path[draw=black,fill=black,miter limit=4.00,nonzero rule,line width=2.400pt]
(176.9112,753.3085) .. controls (175.1937,738.0045) and (80.1970,487.6617) ..
(82.4016,472.4964) .. controls (85.5629,452.1139) and (188.0374,667.3609) ..
(196.4229,648.5539) .. controls (204.3755,630.7243) and (242.5487,465.7141) ..
(258.1298,454.3997) .. controls (285.7640,437.3259) and (291.8933,586.8805) ..
(323.4463,583.2517) .. controls (380.2399,578.2668) and (378.0147,580.5031) ..
(434.9882,579.8586) .. controls (450.4961,579.6976) and (387.4331,461.0306) ..
(402.9416,460.9527) -- (556.6130,579.1701) -- (556.6130,579.1701) .. controls
(540.5924,579.1263) and (524.5716,579.1241) .. (508.5512,579.2478) .. controls
(451.6441,579.7674) and (548.2176,721.0517) .. (491.4945,726.0884) .. controls
(460.5044,729.6884) and (275.0470,592.3333) .. (247.7567,608.7835) .. controls
(232.2688,619.7789) and (435.5657,765.3166) .. (427.5294,782.8032) .. controls
(419.1556,801.4606) and (197.8962,687.4329) .. (194.9239,707.7216) .. controls
(192.8788,722.7147) and (191.3417,737.9821) .. (193.8339,753.0290) --
(176.9112,753.3085) -- cycle;
\end{scope}
\end{tikzpicture}

The question: how to scale and place the path to the expected size and position, and use it for clipping? Especially, how to make text nodes black outside, and white inside the path? I will answer my question as i found the solution, but i'm wondering if anybody knows other solution?

Best Answer

(See below: added stuff concerning scaling)

Here is a much simpler way to achieve part of what you are attempting: switching the color of the text over a background shape. I'm not concerned about the scaling of some imported path. This approach has the advantage that the text is only entered once. The idea is to use the environ package.

The code is

\documentclass{standalone}

\usepackage{tikz}

\usepackage{environ}

\NewEnviron{flipflop}{%
\begin{tikzpicture}
\node[anchor=center,inner sep=0pt,text width=7cm] at (0,0) {\BODY};
{\clip (0,0) circle[radius=2];
\node[anchor=center,fill=black,inner sep=0pt,text width=7cm]  at (0,0) {\color{white}\BODY};
}
\end{tikzpicture}}


\begin{document}

\begin{flipflop}
One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. ``What's happened to me?'' he thought.
\end{flipflop}


\end{document}

The result is

enter image description here

New stuff : The \clip command may be scaled and shifted. For example, if the line containg the `\clip``command is changed to

\clip[shift={(0,-2)},scale=2] (0,0) to[out=0,in=225] (1,1) to[out=45,in=270] (0.5,2) to[out=90,in=180] (-1,1) to[out=0,in=0] (0,0);

then the output is

enter image description here

If the scale is changed to 1:

\clip[shift={(0,-2)},scale=1] (0,0) to[out=0,in=225] (1,1) to[out=45,in=270] (0.5,2) to[out=90,in=180] (-1,1) to[out=0,in=0] (0,0);

Then the output is

enter image description here