| 1 |
% Copyright 2022 by Qrrbrbirlbel |
| 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 Free Documentation License. |
| 7 |
% |
| 8 |
|
| 9 |
\unless\ifcsname tikzextset\endcsname |
| 10 |
\input tikzext-util.tex |
| 11 |
\fi |
| 12 |
|
| 13 |
\unless\ifcsname ifmemoizing\endcsname |
| 14 |
\expandafter\newif\csname ifmemoizing\endcsname |
| 15 |
\fi |
| 16 |
|
| 17 |
\def\tikzextspwrite#1#2#3{% |
| 18 |
\immediate\write\pgfutil@auxout{% |
| 19 |
\noexpand\expandafter\gdef |
| 20 |
\noexpand\csname tikzext@sp@#1\endcsname{{#2}{#3}}% |
| 21 |
}% |
| 22 |
} |
| 23 |
\def\tikzext@sp@savepicturesize{% |
| 24 |
\pgf@process{% |
| 25 |
\pgfpointdiff |
| 26 |
{\pgfpointanchor{current bounding box}{south west}}% |
| 27 |
{\pgfpointanchor{current bounding box}{north east}}}% |
| 28 |
\pgfutil@tempswafalse % is this the final size adjustment? |
| 29 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 30 |
\tikzext@sp@ifapproxequalto{\pgf@x}{\tikzext@sp@width}{% |
| 31 |
\tikzext@sp@ifapproxequalto{\pgf@y}{\tikzext@sp@height}{% |
| 32 |
% This freezes the picture size when the target is reached (Memoize or no). |
| 33 |
\pgf@x=\tikzext@sp@width\relax |
| 34 |
\pgf@y=\tikzext@sp@height\relax |
| 35 |
\pgfutil@tempswatrue |
| 36 |
}{}% |
| 37 |
}{}% |
| 38 |
}% |
| 39 |
\tikzextspwrite{\pgfpictureid}{\the\pgf@x}{\the\pgf@y}% |
| 40 |
\ifmemoizing |
| 41 |
\ifpgfutil@tempswa % the final adjustment, we won't abort |
| 42 |
% Let Memoize broadcast the picture size to .aux, so that we immediately |
| 43 |
% get the correct picture size if we don't load it anymore. |
| 44 |
\xtoksapp\mmzCCMemo{% |
| 45 |
\noexpand\tikzextspwrite{\pgfpictureid}{\the\pgf@x}{\the\pgf@y}% |
| 46 |
}% |
| 47 |
\else % we'll adjust the size some more, abort |
| 48 |
\mmzAbort |
| 49 |
\fi |
| 50 |
\fi |
| 51 |
} |
| 52 |
% |
| 53 |
% pgfmathapproxequalto checks against 0.0001, too precise for this |
| 54 |
% |
| 55 |
% SZ: I rewrote this (copying from pgfmathapproxequalto), so that the macro |
| 56 |
% doesn't destroy the given arguments. |
| 57 |
\def\tikzext@sp@ifapproxequalto#1#2{% |
| 58 |
\begingroup |
| 59 |
\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/tikz/ext/scale picture diff}}% |
| 60 |
\pgfmath@x=#1\relax |
| 61 |
\pgfmath@y=#2\relax |
| 62 |
\advance\pgfmath@x by-\pgfmath@y |
| 63 |
\ifdim\pgfmath@x<0pt\relax |
| 64 |
\multiply\pgfmath@x by-1\relax |
| 65 |
\fi |
| 66 |
\expandafter\endgroup |
| 67 |
\ifdim\pgfmath@x<\pgfutil@tempdima\relax |
| 68 |
\expandafter\pgfutil@firstoftwo |
| 69 |
\else |
| 70 |
\expandafter\pgfutil@secondoftwo |
| 71 |
\fi |
| 72 |
} |
| 73 |
|
| 74 |
\def\tikzext@sp@width{% |
| 75 |
\expandafter\expandafter\expandafter\pgfutil@firstoftwo |
| 76 |
\csname tikzext@sp@\pgfpictureid\endcsname |
| 77 |
} |
| 78 |
\def\tikzext@sp@height{% |
| 79 |
\expandafter\expandafter\expandafter\pgfutil@secondoftwo |
| 80 |
\csname tikzext@sp@\pgfpictureid\endcsname |
| 81 |
} |
| 82 |
|
| 83 |
\def\tikzextpicturewidth{% |
| 84 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{0pt}{\tikzext@sp@width}} |
| 85 |
\def\tikzextpictureheight{% |
| 86 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{0pt}{\tikzext@sp@height}} |
| 87 |
|
| 88 |
\def\tikzext@sp@init#1{% |
| 89 |
\pgfkeysvalueof{/tikz/execute at end picture/.@cmd}\tikzext@sp@savepicturesize\pgfeov |
| 90 |
\ifmemoizing |
| 91 |
\pgfkeysvalueof{/mmz/context/.@cmd}/tikz/ext/#1\pgfeov |
| 92 |
\fi |
| 93 |
} |
| 94 |
\tikzextset{ |
| 95 |
scale picture diff/.initial=+0.05pt, |
| 96 |
scale picture diff/.value to context/.try, |
| 97 |
%%% keep aspect ratio |
| 98 |
%% width and height |
| 99 |
minimum picture size/.code 2 args={% |
| 100 |
\tikzext@sp@init{minimum picture size=\the\dimexpr#1\relax\the\dimexpr#2\relax}% |
| 101 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 102 |
\pgfmathsetlength\pgf@xa{#1}% |
| 103 |
\pgfmathsetlength\pgf@ya{#2}% |
| 104 |
\def\tikz@tempa{0}% |
| 105 |
\def\tikz@temp{0}% |
| 106 |
\ifdim\tikzext@sp@width<\pgf@xa |
| 107 |
\pgfmathsetmacro\tikz@tempa{\pgf@xa/\tikzext@sp@width}% |
| 108 |
\fi |
| 109 |
\ifdim\tikzext@sp@height<\pgf@ya |
| 110 |
\pgfmathsetmacro\tikz@temp{\pgf@ya/\tikzext@sp@height}% |
| 111 |
\fi |
| 112 |
\ifdim\tikz@tempa pt>\tikz@temp pt |
| 113 |
\let\tikz@temp\tikz@tempa |
| 114 |
\fi |
| 115 |
\ifdim\tikz@temp pt>0pt |
| 116 |
\tikzset{scale/.expand once=\tikz@temp}% |
| 117 |
\fi |
| 118 |
}% |
| 119 |
}, |
| 120 |
maximum picture size/.code 2 args={% |
| 121 |
\tikzext@sp@init{maximum picture size=\the\dimexpr#1\relax\the\dimexpr#2\relax}% |
| 122 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 123 |
\pgfmathsetlength\pgf@xa{#1}% |
| 124 |
\pgfmathsetlength\pgf@ya{#2}% |
| 125 |
\def\tikz@tempa{0}% |
| 126 |
\def\tikz@temp{0}% |
| 127 |
\ifdim\tikzext@sp@width>\pgf@xa |
| 128 |
\pgfmathsetmacro\tikz@tempa{\pgf@xa/\tikzext@sp@width}% |
| 129 |
\fi |
| 130 |
\ifdim\tikzext@sp@height>\pgf@ya |
| 131 |
\pgfmathsetmacro\tikz@temp{\pgf@ya/\tikzext@sp@height}% |
| 132 |
\fi |
| 133 |
\ifdim\tikz@tempa pt<\tikz@temp pt |
| 134 |
\let\tikz@temp\tikz@tempa |
| 135 |
\fi |
| 136 |
\ifdim\tikz@temp pt>0pt |
| 137 |
\tikzset{scale/.expand once=\tikz@temp}% |
| 138 |
\fi |
| 139 |
}% |
| 140 |
}, |
| 141 |
%%% keep aspect ratio |
| 142 |
%% width |
| 143 |
picture width/.code={% |
| 144 |
\tikzext@sp@init{picture width=\the\dimexpr#1\relax}% |
| 145 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 146 |
\tikzset{scale={(#1)/\tikzext@sp@width}}% |
| 147 |
}% |
| 148 |
}, |
| 149 |
minimum picture width/.code={% |
| 150 |
\tikzext@sp@init{minimum picture width=\the\dimexpr#1\relax}% |
| 151 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 152 |
\pgfmathsetlength\pgf@xa{#1}% |
| 153 |
\ifdim\tikzext@sp@width<\pgf@xa |
| 154 |
\tikzset{scale={\pgf@xa/\tikzext@sp@width}} |
| 155 |
\fi |
| 156 |
}% |
| 157 |
}, |
| 158 |
maximum picture width/.code={% |
| 159 |
\tikzext@sp@init{maximum picture width=\the\dimexpr#1\relax}% |
| 160 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 161 |
\pgfmathsetlength\pgf@xa{#1}% |
| 162 |
\ifdim\tikzext@sp@width>\pgf@xa |
| 163 |
\tikzset{scale={\pgf@xa/\tikzext@sp@width}} |
| 164 |
\fi |
| 165 |
}% |
| 166 |
}, |
| 167 |
%%% xscale only |
| 168 |
%% width |
| 169 |
picture width*/.code={% |
| 170 |
\tikzext@sp@init{picture width*=\the\dimexpr#1\relax}% |
| 171 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 172 |
\tikzset{xscale={(#1)/\tikzext@sp@width}}% |
| 173 |
}% |
| 174 |
}, |
| 175 |
minimum picture width*/.code={% |
| 176 |
\tikzext@sp@init{minimum picture width*=\the\dimexpr#1\relax}% |
| 177 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 178 |
\pgfmathsetlength\pgf@xa{#1}% |
| 179 |
\ifdim\tikzext@sp@width<\pgf@xa |
| 180 |
\tikzset{xscale={\pgf@xa/\tikzext@sp@width}} |
| 181 |
\fi |
| 182 |
}% |
| 183 |
}, |
| 184 |
maximum picture width*/.code={% |
| 185 |
\tikzext@sp@init{maximum picture width*=\the\dimexpr#1\relax}% |
| 186 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 187 |
\pgfmathsetlength\pgf@xa{#1}% |
| 188 |
\ifdim\tikzext@sp@width>\pgf@xa |
| 189 |
\tikzset{xscale={\pgf@xa/\tikzext@sp@width}} |
| 190 |
\fi |
| 191 |
}% |
| 192 |
}, |
| 193 |
%%% keep aspect ratio |
| 194 |
%% height |
| 195 |
picture height/.code={% |
| 196 |
\tikzext@sp@init{picture height=\the\dimexpr#1\relax}% |
| 197 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 198 |
\tikzset{scale={(#1)/\tikzext@sp@height}}% |
| 199 |
}% |
| 200 |
}, |
| 201 |
minimum picture height/.code={% |
| 202 |
\tikzext@sp@init{minimum picture height=\the\dimexpr#1\relax}% |
| 203 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 204 |
\pgfmathsetlength\pgf@ya{#1}% |
| 205 |
\ifdim\tikzext@sp@height<\pgf@ya |
| 206 |
\tikzset{scale={\pgf@ya/\tikzext@sp@height}} |
| 207 |
\fi |
| 208 |
}% |
| 209 |
}, |
| 210 |
maximum picture height/.code={% |
| 211 |
\tikzext@sp@init{maximum picture height=\the\dimexpr#1\relax}% |
| 212 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 213 |
\pgfmathsetlength\pgf@ya{#1}% |
| 214 |
\ifdim\tikzext@sp@height>\pgf@ya |
| 215 |
\tikzset{scale={\pgf@ya/\tikzext@sp@height}} |
| 216 |
\fi |
| 217 |
}% |
| 218 |
}, |
| 219 |
%%% yscale only |
| 220 |
%% height |
| 221 |
picture height*/.code={% |
| 222 |
\tikzext@sp@init{picture height*=\the\dimexpr#1\relax}% |
| 223 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 224 |
\tikzset{yscale={(#1)/\tikzext@sp@height}}% |
| 225 |
}% |
| 226 |
}, |
| 227 |
minimum picture height*/.code={% |
| 228 |
\tikzext@sp@init{minimum picture height*=\the\dimexpr#1\relax}% |
| 229 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 230 |
\pgfmathsetlength\pgf@ya{#1}% |
| 231 |
\ifdim\tikzext@sp@height<\pgf@ya |
| 232 |
\tikzset{yscale={\pgf@ya/\tikzext@sp@height}} |
| 233 |
\fi |
| 234 |
}% |
| 235 |
}, |
| 236 |
maximum picture height*/.code={% |
| 237 |
\tikzext@sp@init{maximum picture height*=\the\dimexpr#1\relax}% |
| 238 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 239 |
\pgfmathsetlength\pgf@ya{#1}% |
| 240 |
\ifdim\tikzext@sp@height>\pgf@ya |
| 241 |
\tikzset{yscale={\pgf@ya/\tikzext@sp@height}} |
| 242 |
\fi |
| 243 |
}% |
| 244 |
}, |
| 245 |
%%% xscale or yscale |
| 246 |
picture size*/.code 2 args={% #1 = width, #2 = height |
| 247 |
\tikzext@sp@init{picture size*=\the\dimexpr#1\relax\the\dimexpr#2\relax}% |
| 248 |
\pgfutil@IfUndefined{tikzext@sp@\pgfpictureid}{}{% |
| 249 |
\tikzset{ |
| 250 |
xscale={(#1)/\tikzext@sp@width}, |
| 251 |
yscale={(#2)/\tikzext@sp@height}}% |
| 252 |
}% |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
%%% Compatibility |
| 257 |
\tikzextset{ |
| 258 |
/tikz-ext/compat/add library={scalepicture}{pre 0.6}, |
| 259 |
compat/scalepicture/warn/.append code=% |
| 260 |
% \pgfkeyssetvalue{/tikz/ext/compat/scalepicture@}{3}% |
| 261 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture width} {/tikz/ext/picture width}% |
| 262 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/minimum picture width} {/tikz/ext/minimum picture width}% |
| 263 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/maximum picture width} {/tikz/ext/maximum picture width}% |
| 264 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture height} {/tikz/ext/picture height}% |
| 265 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/minimum picture height} {/tikz/ext/minimum picture height}% |
| 266 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/maximum picture height} {/tikz/ext/maximum picture height}% |
| 267 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture size} {/tikz/ext/picture size}% |
| 268 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/minimum picture size} {/tikz/ext/minimum picture size}% |
| 269 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/maximum picture size} {/tikz/ext/maximum picture size}% |
| 270 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture width*} {/tikz/ext/picture width*}% |
| 271 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/minimum picture width*} {/tikz/ext/minimum picture width*}% |
| 272 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/maximum picture width*} {/tikz/ext/maximum picture width*}% |
| 273 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture height*} {/tikz/ext/picture height*}% |
| 274 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/minimum picture height*}{/tikz/ext/minimum picture height*}% |
| 275 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/maximum picture height*}{/tikz/ext/maximum picture height*}% |
| 276 |
\tikzextutil@compatwarning@key{scalepicture}{pre 0.6}{/tikz/picture size*} {/tikz/ext/picture size*},% |
| 277 |
compat/scalepicture/pre 0.6/.append code=% |
| 278 |
% \pgfkeyssetvalue{/tikz/ext/compat/scalepicture@}{2}% |
| 279 |
\pgfkeysdef{/tikz/picture width} {\pgfkeysvalueof{/tikz/ext/picture width/.@cmd}##1\pgfeov}% |
| 280 |
\pgfkeysdef{/tikz/minimum picture width} {\pgfkeysvalueof{/tikz/ext/minimum picture width/.@cmd}##1\pgfeov}% |
| 281 |
\pgfkeysdef{/tikz/maximum picture width} {\pgfkeysvalueof{/tikz/ext/maximum picture width/.@cmd}##1\pgfeov}% |
| 282 |
\pgfkeysdef{/tikz/picture height} {\pgfkeysvalueof{/tikz/ext/picture height/.@cmd}##1\pgfeov}% |
| 283 |
\pgfkeysdef{/tikz/minimum picture height} {\pgfkeysvalueof{/tikz/ext/minimum picture height/.@cmd}##1\pgfeov}% |
| 284 |
\pgfkeysdef{/tikz/maximum picture height} {\pgfkeysvalueof{/tikz/ext/maximum picture height/.@cmd}##1\pgfeov}% |
| 285 |
\pgfkeysdef{/tikz/picture size} {\pgfkeysvalueof{/tikz/ext/picture size/.@cmd}##1\pgfeov}% |
| 286 |
\pgfkeysdef{/tikz/minimum picture size} {\pgfkeysvalueof{/tikz/ext/minimum picture size/.@cmd}##1\pgfeov}% |
| 287 |
\pgfkeysdef{/tikz/maximum picture size} {\pgfkeysvalueof{/tikz/ext/maximum picture size/.@cmd}##1\pgfeov}% |
| 288 |
\pgfkeysdef{/tikz/picture width*} {\pgfkeysvalueof{/tikz/ext/picture width*/.@cmd}##1\pgfeov}% |
| 289 |
\pgfkeysdef{/tikz/minimum picture width*} {\pgfkeysvalueof{/tikz/ext/minimum picture width*/.@cmd}##1\pgfeov}% |
| 290 |
\pgfkeysdef{/tikz/maximum picture width*} {\pgfkeysvalueof{/tikz/ext/maximum picture width*/.@cmd}##1\pgfeov}% |
| 291 |
\pgfkeysdef{/tikz/picture height*} {\pgfkeysvalueof{/tikz/ext/picture height*/.@cmd}##1\pgfeov}% |
| 292 |
\pgfkeysdef{/tikz/minimum picture height*}{\pgfkeysvalueof{/tikz/ext/minimum picture height*/.@cmd}##1\pgfeov}% |
| 293 |
\pgfkeysdef{/tikz/maximum picture height*}{\pgfkeysvalueof{/tikz/ext/maximum picture height*/.@cmd}##1\pgfeov}% |
| 294 |
\pgfkeysdef{/tikz/picture size*} {\pgfkeysvalueof{/tikz/ext/picture size*/.@cmd}##1\pgfeov}, |
| 295 |
% compat/scalepicture/0.6/.append code=\pgfkeyssetvalue{/tikz/ext/compat/scalepicture@}{1}, |
| 296 |
% compat/scalepicture/newest/.append code=\pgfkeyssetvalue{/tikz/ext/compat/scalepicture@}{0}, |
| 297 |
compat/scalepicture/\pgfkeysvalueof{/tikz/ext/compat/scalepicture}% |
| 298 |
} |
| 299 |
\endinput |