| 1 |
% \iffalse |
| 2 |
% -------------------------------------------------------------------- |
| 3 |
%<*utils> |
| 4 |
% \fi |
| 5 |
% |
| 6 |
% \subsubsection{Bounding boxes} |
| 7 |
% |
| 8 |
% Bounding box dimensions |
| 9 |
% |
| 10 |
% |
| 11 |
% \begin{macrocode} |
| 12 |
\newdimen\wg@bb@minx |
| 13 |
\newdimen\wg@bb@miny |
| 14 |
\newdimen\wg@bb@maxx |
| 15 |
\newdimen\wg@bb@maxy |
| 16 |
% \end{macrocode} |
| 17 |
% |
| 18 |
% |
| 19 |
% |
| 20 |
% Enable or disable bounding box tracking |
| 21 |
% |
| 22 |
% \begin{macrocode} |
| 23 |
\newif\ifwg@notrelevantforpathsize\wg@notrelevantforpathsizefalse |
| 24 |
% \end{macrocode} |
| 25 |
% |
| 26 |
% |
| 27 |
% \begin{Macro}{wg@resetbb} |
| 28 |
% Reset the bounding box tracking dimensions |
| 29 |
% |
| 30 |
% \begin{macrocode} |
| 31 |
\def\wg@resetbb{% |
| 32 |
\global\wg@bb@minx=16000pt\relax% |
| 33 |
\global\wg@bb@miny=16000pt\relax% |
| 34 |
\global\wg@bb@maxx=-16000pt\relax% |
| 35 |
\global\wg@bb@maxy=-16000pt\relax% |
| 36 |
} |
| 37 |
% \end{macrocode} |
| 38 |
% \end{Macro} |
| 39 |
% |
| 40 |
% \begin{Macro}{\old@pgf@protocolsize} |
| 41 |
% Save PGF's bounding box algorithm |
| 42 |
% |
| 43 |
% \begin{macrocode} |
| 44 |
\let\old@pgf@protocolsize\pgf@protocolsizes |
| 45 |
% \end{macrocode} |
| 46 |
% \end{Macro} |
| 47 |
% |
| 48 |
% \begin{Macro}{\wg@protocolsizes} |
| 49 |
% Our bounding box algorithm |
| 50 |
% |
| 51 |
% \begin{macrocode} |
| 52 |
\def\wg@protocolsizes#1#2{% |
| 53 |
\old@pgf@protocolsize{#1}{#2} |
| 54 |
\ifwg@notrelevantforpathsize\else% |
| 55 |
\ifdim#1<\wg@bb@minx\global\wg@bb@minx#1\fi% |
| 56 |
\ifdim#1>\wg@bb@maxx\global\wg@bb@maxx#1\fi% |
| 57 |
\ifdim#2<\wg@bb@miny\global\wg@bb@miny#2\fi% |
| 58 |
\ifdim#2>\wg@bb@maxy\global\wg@bb@maxy#2\fi% |
| 59 |
\fi |
| 60 |
} |
| 61 |
% \end{macrocode} |
| 62 |
% \end{Macro} |
| 63 |
% |
| 64 |
% % \begin{environment}{getbbl} |
| 65 |
% Environment that tracks the local bounding box |
| 66 |
% |
| 67 |
% \begin{macrocode} |
| 68 |
\newenvironment{getbbl}{% |
| 69 |
\wg@resetbb% |
| 70 |
\wg@notrelevantforpathsizefalse% |
| 71 |
\global\let\pgf@protocolsizes\wg@protocolsizes}{% |
| 72 |
\gdef\pgf@sh@ns@L{rectangle} |
| 73 |
\gdef\pgf@sh@np@L{% |
| 74 |
\def\southwest{\pgfqpoint{\the\wg@bb@minx}{\the\wg@bb@miny}}% |
| 75 |
\def\northeast{\pgfqpoint{\the\wg@bb@maxx}{\the\wg@bb@maxy}}% |
| 76 |
} |
| 77 |
\gdef\pgf@sh@nt@L{{1}{0}{0}{1}{0pt}{0pt}} |
| 78 |
\gdef\pgf@sh@pi@L{\pgfpictureid} |
| 79 |
\global\let\pgf@protocolsizes\old@pgf@protocolsize |
| 80 |
} |
| 81 |
% \end{macrocode} |
| 82 |
% \end{environment} |
| 83 |
% |
| 84 |
% \begin{environment}{getbb} |
| 85 |
% Environment to track global bounding box |
| 86 |
% |
| 87 |
% \begin{macrocode} |
| 88 |
\newenvironment{getbb}{% |
| 89 |
\wg@resetbb% |
| 90 |
\wg@notrelevantforpathsizefalse% |
| 91 |
\global\let\pgf@protocolsizes\wg@protocolsizes}{% |
| 92 |
\gdef\pgf@sh@ns@M{rectangle} |
| 93 |
\gdef\pgf@sh@np@M{% |
| 94 |
\def\southwest{\pgfqpoint{\the\wg@bb@minx}{\the\wg@bb@miny}}% |
| 95 |
\def\northeast{\pgfqpoint{\the\wg@bb@maxx}{\the\wg@bb@maxy}}% |
| 96 |
} |
| 97 |
\gdef\pgf@sh@nt@M{{1}{0}{0}{1}{0pt}{0pt}} |
| 98 |
% \pgfgettransform\pgf@temp% |
| 99 |
% \xdef\pgf@sh@nt@M{\pgf@temp} |
| 100 |
% \pgfgettransformentries{\wg@tmp@a}{\wg@tmp@b}{\wg@tmp@c}{\wg@tmp@d}{\pgf@temp}{\pgf@temp} |
| 101 |
% \message{^^JTransform of M: \meaning\pgf@temp} |
| 102 |
% \xdef\pgf@sh@nt@M{{\wg@tmp@a}{\wg@tmp@b}{\wg@tmp@c}{\wg@tmp@d}{0pt}{0pt}}% |
| 103 |
% \message{^^JTransform of M: \meaning\pgf@sh@nt@M} |
| 104 |
\gdef\pgf@sh@pi@M{\pgfpictureid} |
| 105 |
\global\let\pgf@protocolsizes\old@pgf@protocolsize |
| 106 |
} |
| 107 |
% \end{macrocode} |
| 108 |
% \end{environment} |
| 109 |
% |
| 110 |
% \iffalse |
| 111 |
% -------------------------------------------------------------------- |
| 112 |
% \fi |
| 113 |
% |
| 114 |
% \subsubsection{Some utilities to get bounding boxes and the like} |
| 115 |
% |
| 116 |
% |
| 117 |
% All coordinates, and such are recorded in centimetres. It is worth |
| 118 |
% remembering that the Tikz coordinate system has the $y$ axis point |
| 119 |
% upward, while typical image software has the $y$ axis point down. |
| 120 |
% \texttt{pdftocairo} typically assumes a 150 PPI (pixels-per-inch) |
| 121 |
% resolution. |
| 122 |
% |
| 123 |
% That means that scaling factor becomes |
| 124 |
% |
| 125 |
% $$ |
| 126 |
% \frac{150\mathrm{pixel}}{2.54\mathrm{cm}} = |
| 127 |
% 59.055\frac{\mathrm{pixel}}{\mathrm{cm}} |
| 128 |
% $$ |
| 129 |
% |
| 130 |
% \iffalse Using definition in terms of printers feet - the one to |
| 131 |
% use! |
| 132 |
% |
| 133 |
% PNG: 1674 x 1101 |
| 134 |
% PDF: "lower left": [-0.02107,-0.02107], |
| 135 |
% "upper right": [28.31705,18.60843] |
| 136 |
% Width: 28.31705+0.02107 = 28.33812 |
| 137 |
% Height: 18.60843+0.02107 = 18.62950 |
| 138 |
% Pixel / cm: 1674 / 28.33812 = 59.07237318495369488166 |
| 139 |
% 1101 / 18.62950 = 59.09981480984460130438 |
| 140 |
% Average = 59.08609399739914809302 |
| 141 |
% |
| 142 |
% Calculated = 150 / 2.54 = 59.05511811023622047244 |
| 143 |
% |
| 144 |
% Using 1/72.27 |
| 145 |
% |
| 146 |
% "lower left": [-0.02109,-0.02109], |
| 147 |
% "upper right": [28.321,18.61102] |
| 148 |
% Width: 28.321+0.02109=28.34209 |
| 149 |
% Height: 18.61102+0.02109=18.63211 |
| 150 |
% Pixel / cm: 1674 / 28.34209 = 59.06409866033168337267 |
| 151 |
% 1101 / 18.63211 = 59.09153606328000425072 |
| 152 |
% Average = 59.07781736180584381169 |
| 153 |
% \fi |
| 154 |
% |
| 155 |
% Since we want to write all dimensions in centimetres, we need to be |
| 156 |
% able to convert \texttt{pt} dimensions to centimetres. We make two |
| 157 |
% macros to do that for us. |
| 158 |
% |
| 159 |
% The exact definition of 1pt is |
| 160 |
% |
| 161 |
% $$1\,\mathrm{pt} = \frac{249}{250}12"\frac{1}{864}=\frac{83}{6000}1" |
| 162 |
% = 0.03513\overline{6}$$ |
| 163 |
% |
| 164 |
% \begin{macrocode} |
| 165 |
% 2.54 / 72.27 = .03514598035145980351 |
| 166 |
% \def\wg@pt@to@cm#1{\pgfmathparse{#1 * 0.0351460}} |
| 167 |
\def\wg@pt@to@cm#1{\pgfmathparse{#1 * 0.0351367}} |
| 168 |
\def\ptpoint@to@cm#1#2{% |
| 169 |
\wg@pt@to@cm{#1}\edef\x{\pgfmathresult}% |
| 170 |
\wg@pt@to@cm{#2}\edef\y{\pgfmathresult}} |
| 171 |
% \end{macrocode} |
| 172 |
% |
| 173 |
% The next macro gets an anchors coordinates and stores them (in units |
| 174 |
% of centimetres) in \cs{tmp@x} and \cs{tmp@y} |
| 175 |
% |
| 176 |
% \begin{macrocode} |
| 177 |
\def\wg@get@nchor#1#2{% |
| 178 |
\wg@dbg{2}{Get anchor coordinates #1.#2} |
| 179 |
\pgfpointanchor{#1}{#2}% |
| 180 |
\wg@dbg{2}{ `\the\pgf@x',`\the\pgf@y'} |
| 181 |
\pgfgetlastxy\tmp@x\tmp@y% |
| 182 |
\wg@dbg{2}{ `\tmp@x',`\tmp@y'} |
| 183 |
\wg@pt@to@cm{\tmp@x}\edef\tmp@x{\pgfmathresult} |
| 184 |
\wg@pt@to@cm{\tmp@y}\edef\tmp@y{\pgfmathresult} |
| 185 |
} |
| 186 |
% \end{macrocode} |
| 187 |
% |
| 188 |
% This does the same as above, but transform to the global coordinate |
| 189 |
% system. |
| 190 |
% |
| 191 |
% \begin{macrocode} |
| 192 |
\def\wg@get@global@nchor#1#2{% |
| 193 |
\pgfpointanchor{#1}{#2}% |
| 194 |
\pgfgetlastxy\tmp@x\tmp@y% |
| 195 |
\pgfpointtransformed{\pgfpoint{\tmp@x}{\tmp@y}} |
| 196 |
\pgf@xa=\pgf@x |
| 197 |
\pgf@ya=\pgf@y |
| 198 |
%% \message{^^JAnchor #1.#2 @ (\the\pgf@xa,\the\pgf@ya)} |
| 199 |
\wg@pt@to@cm{\the\pgf@xa}\edef\tmp@x{\pgfmathresult} |
| 200 |
\wg@pt@to@cm{\the\pgf@ya}\edef\tmp@y{\pgfmathresult} |
| 201 |
} |
| 202 |
% \end{macrocode} |
| 203 |
% |
| 204 |
% This records the bounding box given by a named node. The result is |
| 205 |
% stored in the macros \cs{llx}, \cs{lly}, \cs{urx}, and \cs{ury}. |
| 206 |
% |
| 207 |
% \begin{macrocode} |
| 208 |
\def\wg@get@bb#1{% |
| 209 |
\wg@get@nchor{#1}{south west} |
| 210 |
\edef\llx{\tmp@x} |
| 211 |
\edef\lly{\tmp@y} |
| 212 |
\wg@get@nchor{#1}{north east} |
| 213 |
\edef\urx{\tmp@x} |
| 214 |
\edef\ury{\tmp@y} |
| 215 |
} |
| 216 |
\def\wglogbb#1{% |
| 217 |
\wg@get@bb{#1}% |
| 218 |
\message{^^J`#1' BB: (\llx,\lly) x (\urx,\ury)^^J}} |
| 219 |
% \end{macrocode} |
| 220 |
% |
| 221 |
% |
| 222 |
% |
| 223 |
% \iffalse |
| 224 |
% -------------------------------------------------------------------- |
| 225 |
%</utils> |
| 226 |
%\fi |