| 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 |
% This is the TikZ library patterns.images |
| 9 |
% Load with \usetikzlibrary{ext.patterns.images} |
| 10 |
% |
| 11 |
% Macro: |
| 12 |
% - \pgfextsetupimageaspattern[<opt arguments for \pgfdeclareimage>]{<name>}{<path/file>} |
| 13 |
% |
| 14 |
% Keys are: |
| 15 |
% - use image as pattern=<name> |
| 16 |
% - image as pattern=<opt arguments for \pgftext> |
| 17 |
|
| 18 |
\unless\ifcsname tikzextset\endcsname |
| 19 |
\input tikzext-util.tex |
| 20 |
\fi |
| 21 |
|
| 22 |
\def\tikzextsetupimageaspattern{\pgfutil@ifnextchar[\tikzext@pgfsetupimageaspattern{\tikzext@pgfsetupimageaspattern[]}} |
| 23 |
\def\tikzext@pgfsetupimageaspattern[#1]#2#3{% #1 = options |
| 24 |
% #2 = image name |
| 25 |
% #3 = file name |
| 26 |
\pgfdeclareimage[#1]{tikzext@pgf@iap@#2}{#3}% |
| 27 |
\setbox\pgfutil@tempboxa\hbox{\pgfuseimage{tikzext@pgf@iap@#2}}% |
| 28 |
\expandafter\edef\csname tikzext@pgf@iap@#2@\endcsname{{\the\wd\pgfutil@tempboxa}{\the\ht\pgfutil@tempboxa}}% |
| 29 |
} |
| 30 |
\tikzextset{ |
| 31 |
image as pattern/name/.initial=, |
| 32 |
image as pattern/option/.style=, |
| 33 |
image as pattern/options/.style={/tikz/ext/image as pattern/option/.append style={#1}}, |
| 34 |
image as pattern/.default=, |
| 35 |
image as pattern/.code={ |
| 36 |
\pgfqkeys{/tikz/ext/image as pattern}{#1}% |
| 37 |
\pgfkeysgetvalue{/tikz/ext/image as pattern/name}\tikz@temp |
| 38 |
\pgfutil@ifxempty\tikz@temp{% |
| 39 |
\tikzerror{You need to specify a name for the ``image-pattern'' to be used.}% |
| 40 |
}{% |
| 41 |
\edef\tikz@tempa{\expandafter\expandafter\expandafter\pgfutil@firstoftwo\csname tikzext@pgf@iap@\tikz@temp @\endcsname}% |
| 42 |
\edef\tikz@tempb{\expandafter\expandafter\expandafter\pgfutil@secondoftwo\csname tikzext@pgf@iap@\tikz@temp @\endcsname}% |
| 43 |
\pgfkeysalso{/tikz/path picture={% |
| 44 |
\pgf@process{\pgfpointanchor{path picture bounding box}{north east}}% |
| 45 |
\pgf@xa\pgf@x\pgf@ya\pgf@y |
| 46 |
\pgf@process{\pgfpointanchor{path picture bounding box}{south west}}% |
| 47 |
\pgf@xb\pgf@x\pgf@yb\pgf@y\pgf@yc\pgf@yb |
| 48 |
\pgfutil@loop |
| 49 |
{% |
| 50 |
\pgfutil@loop |
| 51 |
\pgftext[/tikz/ext/image as pattern/option,at=\pgfqpoint{\pgf@xb}{\pgf@yb}]{\pgfuseimage{tikzext@pgf@iap@\tikz@temp}}% |
| 52 |
\ifdim\pgf@yb<\pgf@ya |
| 53 |
\advance\pgf@yb\tikz@tempb |
| 54 |
\pgfutil@repeat |
| 55 |
}% |
| 56 |
\ifdim\pgf@xb<\pgf@xa |
| 57 |
\advance\pgf@xb\tikz@tempa |
| 58 |
\pgf@yb\pgf@yc |
| 59 |
\pgfutil@repeat |
| 60 |
}}% |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
%%% Compatibility |
| 65 |
\tikzextset{ |
| 66 |
/tikz-ext/compat/add library={patterns.images}{pre 0.6}, |
| 67 |
compat/patterns.images/warn/.append code={% |
| 68 |
\tikzextutil@compatwarning@key{patterns.images}{pre 0.6}{/tikz/image as pattern}{/pgf/ext/image as pattern}% |
| 69 |
\tikzextutil@compatwarning@key{patterns.images}{pre 0.6}{/tikz/image as pattern/options}{/pgf/ext/image as pattern/options}% |
| 70 |
\tikzextutil@compatwarning@valuekey{patterns.images}{pre 0.6}{/tikz/image as pattern/name}{/tikz/ext/image as pattern/name}% |
| 71 |
\tikzextutil@compatwarning@cmd{patterns.images}{pre 0.6}{pgfsetupimageaspattern}{\tikzextsetupimageaspattern}{}% |
| 72 |
\pgfkeysaddvalue{/tikz/ext/image as pattern/option}{\pgfkeysalso{/tikz/image as pattern/option}}{}% |
| 73 |
}, |
| 74 |
compat/patterns.images/pre 0.6/.append code={% |
| 75 |
\pgfkeysdef{/tikz/image as pattern}{\pgfkeysvalueof{/tikz/ext/image as pattern/.@cmd}##1\pgfeov}% |
| 76 |
\pgfkeysdef{/tikz/image as pattern/options}{\pgfkeysvalueof{/tikz/ext/image as pattern/options/.@cmd}##1\pgfeov}% |
| 77 |
\pgfkeysdef{/tikz/image as pattern/name}{\pgfkeyssetvalue{/tikz/ext/image as pattern/name/.@cmd}##1\pgfeov}% |
| 78 |
\pgfkeyssetvalue{/tikz/image as pattern/name}{\pgfkeysvalueof{/tikz/ext/image as pattern/name}}% |
| 79 |
\pgfkeysaddvalue{/tikz/ext/image as pattern/option}{\pgfkeysalso{/tikz/image as pattern/option}}{}% |
| 80 |
\let\pgfsetupimageaspattern\tikzextsetupimageaspattern |
| 81 |
}, |
| 82 |
compat/patterns.images/\pgfkeysvalueof{/tikz/ext/compat/patterns.images}% |
| 83 |
} |
| 84 |
\endinput |