| 1 |
% Copyright 2018 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{tikzlibraryfit.code.tex} |
| 11 |
|
| 12 |
\pgfqkeys{/tikz}{% |
| 13 |
fit/.code=\tikz@lib@fit{#1}, |
| 14 |
rotate fit/.code={% |
| 15 |
\pgfmathsetmacro\tikz@lib@fit@rotate{#1}% |
| 16 |
\pgfkeysalso{/tikz/rotate=\tikz@lib@fit@rotate}% |
| 17 |
}, |
| 18 |
}% |
| 19 |
|
| 20 |
\def\tikz@lib@fit@rotate{0}% |
| 21 |
|
| 22 |
\def\tikz@lib@fit#1{% |
| 23 |
\pgf@xb=-16000pt\relax% |
| 24 |
\pgf@xa=16000pt\relax% |
| 25 |
\pgf@yb=-16000pt\relax% |
| 26 |
\pgf@ya=16000pt\relax% |
| 27 |
% |
| 28 |
% Now iterate over the coordinates |
| 29 |
\tikz@lib@fit@scan#1\pgf@stop% |
| 30 |
% Now, let's see what has happened |
| 31 |
\ifdim\pgf@xa>\pgf@xa% |
| 32 |
% Nothing... Ok, let's just ignore this. |
| 33 |
\else% |
| 34 |
% Ok, compute center and width and height |
| 35 |
\pgf@x=\pgf@xb% |
| 36 |
\advance\pgf@x by-\pgf@xa% |
| 37 |
\pgf@y=\pgf@yb% |
| 38 |
\advance\pgf@y by-\pgf@ya% |
| 39 |
\advance\pgf@xa by.5\pgf@x% |
| 40 |
\advance\pgf@ya by.5\pgf@y% |
| 41 |
\ifdim\tikz@lib@fit@rotate pt=0pt\relax% |
| 42 |
{% |
| 43 |
\pgftransforminvert% |
| 44 |
\pgf@pos@transform{\pgf@xa}{\pgf@ya}% |
| 45 |
\global\pgf@xa\pgf@xa |
| 46 |
\global\pgf@ya\pgf@ya |
| 47 |
} |
| 48 |
\else% |
| 49 |
\pgf@xc=\pgf@x% |
| 50 |
\pgf@yc=\pgf@y% |
| 51 |
{% |
| 52 |
\pgf@xc=\pgf@xa% |
| 53 |
\pgf@yc=\pgf@ya% |
| 54 |
\pgftransforminvert% |
| 55 |
\pgf@pos@transform{\pgf@xc}{\pgf@yc}% |
| 56 |
\pgftransformreset% |
| 57 |
\pgftransformrotate{\tikz@lib@fit@rotate}% |
| 58 |
\pgf@pos@transform{\pgf@xc}{\pgf@yc}% |
| 59 |
\global\pgf@x=\pgf@xc% |
| 60 |
\global\pgf@y=\pgf@yc% |
| 61 |
}% |
| 62 |
\pgf@xa=\pgf@x% |
| 63 |
\pgf@ya=\pgf@y% |
| 64 |
\pgf@x=\pgf@xc% |
| 65 |
\pgf@y=\pgf@yc% |
| 66 |
\fi% |
| 67 |
\edef\tikz@node@at{\noexpand\pgfqpoint{\the\pgf@xa}{\the\pgf@ya}}% |
| 68 |
\pgfkeysalso{/tikz/anchor=center,/tikz/text badly centered}% |
| 69 |
\pgfkeysalso{/tikz/text width/.expanded=\the\pgf@x}% |
| 70 |
\pgf@x=\pgf@y% |
| 71 |
\pgf@y=.5\pgf@y% |
| 72 |
\pgfkeysalso{ |
| 73 |
/tikz/transform shape=false, |
| 74 |
/tikz/text height/.expanded=\the\[email protected]\dp\pgfnodeparttextbox, |
| 75 |
/tikz/text depth/.expanded=\the\pgf@x-\noexpand\the\ht\pgfnodeparttextbox}% |
| 76 |
\pgfkeysalso{every fit/.try}% |
| 77 |
\fi% |
| 78 |
}% |
| 79 |
|
| 80 |
\def\tikz@lib@fit@scan{% |
| 81 |
\pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble} |
| 82 |
{\tikz@scan@one@point\tikz@lib@fit@scan@handle}}% |
| 83 |
|
| 84 |
\def\tikz@lib@fit@scan@handle#1{% |
| 85 |
\iftikz@shapeborder% |
| 86 |
% Ok, fit all four external anchors, if they exist |
| 87 |
\tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{west}}% |
| 88 |
\tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{east}}% |
| 89 |
\tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{north}}% |
| 90 |
\tikz@lib@fit@adjust{\pgfpointanchor{\tikz@shapeborder@name}{south}}% |
| 91 |
\else% |
| 92 |
\tikz@lib@fit@adjust{#1}% |
| 93 |
\fi% |
| 94 |
\tikz@lib@fit@scan% |
| 95 |
}% |
| 96 |
|
| 97 |
\def\tikz@lib@fit@adjust#1{% |
| 98 |
\ifdim\tikz@lib@fit@rotate pt=0pt\relax% |
| 99 |
\pgf@process{\pgfpointtransformed{#1}}% |
| 100 |
\else% |
| 101 |
{% |
| 102 |
\pgf@process{\pgfpointtransformed{#1}}% |
| 103 |
\pgf@xc=\pgf@x% |
| 104 |
\pgf@yc=\pgf@y% |
| 105 |
\pgfgettransform\tikz@lib@fit@transform% |
| 106 |
\pgftransforminvert% |
| 107 |
\pgf@pos@transform{\pgf@xc}{\pgf@yc}% |
| 108 |
\pgftransformreset% |
| 109 |
\pgftransformrotate{-\tikz@lib@fit@rotate}% |
| 110 |
\pgf@pos@transform{\pgf@xc}{\pgf@yc}% |
| 111 |
\pgfsettransform\tikz@lib@fit@transform% |
| 112 |
\pgf@pos@transform{\pgf@xc}{\pgf@yc}% |
| 113 |
\global\pgf@x=\pgf@xc% |
| 114 |
\global\pgf@y=\pgf@yc% |
| 115 |
}% |
| 116 |
\fi% |
| 117 |
\ifdim\pgf@x<\pgf@xa% |
| 118 |
\pgf@xa=\pgf@x% |
| 119 |
\fi% |
| 120 |
\ifdim\pgf@y<\pgf@ya% |
| 121 |
\pgf@ya=\pgf@y% |
| 122 |
\fi% |
| 123 |
\ifdim\pgf@x>\pgf@xb% |
| 124 |
\pgf@xb=\pgf@x% |
| 125 |
\fi% |
| 126 |
\ifdim\pgf@y>\pgf@yb% |
| 127 |
\pgf@yb=\pgf@y% |
| 128 |
\fi% |
| 129 |
}% |
| 130 |
|
| 131 |
|
| 132 |
\endinput |