forked from Qrrbrbirlbel/TikZ-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtikzlibrarypatterns.images.code.tex
51 lines (49 loc) · 1.86 KB
/
tikzlibrarypatterns.images.code.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% This is the TikZ library patterns.images
% Load with \usetikzlibrary{patterns.images}
%
% Macro:
% - \pgfSetupImageAsPattern[<opt arguments for \pgfdeclareimage>]{<name>}{<path/file>}
%
% Keys are:
% - use image as pattern=<name>
% - image as pattern=<opt arguments for \pgftext>
\newlength\qrr@pgf@iap@width
\newlength\qrr@pgf@iap@height
\def\pgfSetupImageAsPattern{\pgfutil@ifnextchar[\qrr@pgfSetupImageAsPattern{\qrr@pgfSetupImageAsPattern[]}}
\def\qrr@pgfSetupImageAsPattern[#1]#2#3{% #1 = options
% #2 = image name
% #3 = file name
\pgfdeclareimage[#1]{qrr@pgf@iap@#2}{#3}%
\sbox\pgfutil@tempboxa{\pgfuseimage{qrr@pgf@iap@#2}}%
\expandafter\edef\csname qrr@pgf@iap@#2@width\endcsname{\the\wd\pgfutil@tempboxa}%
\expandafter\edef\csname qrr@pgf@iap@#2@height\endcsname{\the\ht\pgfutil@tempboxa}%
}
\tikzset{
image as pattern/.code={
\edef\qrr@pgf@iap@options{#1}%
\pgfkeysalso{/tikz/path picture={%
\pgf@process{\pgfpointanchor{path picture bounding box}{north east}}%
\pgf@xa\pgf@x\pgf@ya\pgf@y
\pgf@process{\pgfpointanchor{path picture bounding box}{south west}}%
\pgf@xb\pgf@x\pgf@yb\pgf@y\pgf@yc\pgf@yb
\pgfutil@loop
{%
\pgfutil@loop
\expandafter\pgftext\expandafter[\qrr@pgf@iap@options,at=\pgfqpoint{\pgf@xb}{\pgf@yb}]{\pgfuseimage{qrr@pgf@iap@\qrr@pgf@iap@name}}%
\ifdim\pgf@yb<\pgf@ya
\advance\pgf@yb\qrr@pgf@iap@height
\pgfutil@repeat
}%
\ifdim\pgf@xb<\pgf@xa
\advance\pgf@xb\qrr@pgf@iap@width
\pgf@yb\pgf@yc
\pgfutil@repeat
}}%
},
use image as pattern/.code={%
\edef\qrr@pgf@iap@name{#1}%
\expandafter\qrr@pgf@iap@width\csname qrr@pgf@iap@#1@width\endcsname
\expandafter\qrr@pgf@iap@height\csname qrr@pgf@iap@#1@height\endcsname
}
}
\endinput