Debian Codegraph @

texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarydecorations.text.code.tex

raw
1 % Copyright 2018 by Mark Wibrow
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 \usetikzlibrary{decorations}%
11 \usepgflibrary{decorations.text}%
12
13
14 % Code for the `text effects along path' decoration
15
16 % Some text constants
17 % To do: merge these with existing text constants
18 \def\tikz@lib@dec@te@space@text{space}%
19 \def\tikz@lib@dec@align@left@text{left}%
20 \def\tikz@lib@dec@align@right@text{right}%
21 \def\tikz@lib@dec@align@center@text{center}%
22 \def\tikz@lib@dec@te@none@text{none}%
23
24 % Some ifs
25 \newif\iftikz@lib@dec@te@pathfromtext%
26 \newif\iftikz@lib@dec@te@segmentfromwidth%
27 \newif\iftikz@lib@dec@te@scaletexttopath%
28 \newif\iftikz@lib@dec@te@fittexttopath%
29 \newif\iftikz@lib@dec@te@wordsep%
30 \newif\iftikz@lib@dec@te@finalletter%
31
32
33 % Utility macros
34 % To do: integrate with existing pgf macros
35 \def\tikz@lib@dec@te@addto@macro#1#2{%
36 \expandafter\def\expandafter#1\expandafter{#1#2}%
37 }%
38
39 \def\tikz@lib@dec@te@namelet#1#2{%
40 \expandafter\expandafter\expandafter\let\expandafter\expandafter\csname\expandafter#1\expandafter\endcsname\expandafter=\csname#2\endcsname%
41 }%
42
43 \def\tikz@lib@dec@te@advancecountmacro#1#2{%
44 \pgfutil@tempcnta=#1\relax%
45 \advance\pgfutil@tempcnta by#2\relax%
46 \edef#1{\the\pgfutil@tempcnta}%
47 }%
48
49 \def\tikz@lib@dec@te@advancedimenmacro#1#2{%
50 \pgf@x=#1\relax%
51 \advance\pgf@x by#2\relax%
52 \edef#1{\the\pgf@x}%
53 }%
54
55 % Macros for defining and updating text parameters
56 \def\tikz@lib@dec@te@start@parameters#1{%
57 \expandafter\let\csname tikz@lib@dec@te@character@#1\endcsname=\pgfutil@empty%
58 }%
59
60 \def\tikz@lib@dec@te@addto@parameters#1#2{%
61 \expandafter\tikz@lib@dec@te@addto@macro\expandafter%
62 {\csname tikz@lib@dec@te@character@#1\endcsname}{#2}%
63 }%
64 \def\tikz@lib@dec@te@addmacroto@parameters#1#2{%
65 \def\tikz@lib@dec@te@marshal{\expandafter\tikz@lib@dec@te@addto@macro\expandafter%
66 {\csname tikz@lib@dec@te@character@#1\endcsname}}%
67 \expandafter\tikz@lib@dec@te@marshal\expandafter{\expandafter\def\expandafter#2\expandafter{#2}}%
68 }%
69
70 \def\tikz@lib@dec@te@getparameters#1{\csname tikz@lib@dec@te@character@#1\endcsname}%
71
72
73
74 \let\tikz@lib@dec@te@textoptions=\pgfutil@empty
75 \let\tikz@lib@dec@te@widthoptions=\pgfutil@empty
76 \let\tikz@lib@dec@te@charactercountvar=\pgfutil@empty
77 \let\tikz@lib@dec@te@charactertotalvar=\pgfutil@empty
78 \let\tikz@lib@dec@te@lettercountvar=\pgfutil@empty
79 \let\tikz@lib@dec@te@lettertotalvar=\pgfutil@empty
80 \let\tikz@lib@dec@te@wordcountvar=\pgfutil@empty
81 \let\tikz@lib@dec@te@wordctotalvar=\pgfutil@empty
82 \let\tikz@lib@dec@te@transformtext=\pgfutil@empty%
83
84
85 % Keys... lots of them...
86 \pgfkeys{/pgf/decoration/text effects/.cd,
87 .unknown/.code={\let\tikz@lib@dec@te@key@tmp=\pgfkeyscurrentname%
88 \pgfkeysalso{/tikz/\tikz@lib@dec@te@key@tmp={#1}}},
89 path from text/.is if=tikz@lib@dec@te@pathfromtext,
90 path from text angle/.store in=\tikz@lib@dec@te@pathfromtextangle,
91 path from text angle=0,
92 fit text to path/.is if=tikz@lib@dec@te@fittexttopath,
93 characters/.style={/pgf/decoration/text effects/every character/.style={#1}},
94 characters/.append/.code={\pgfkeysalso{/pgf/decoration/text effects/every character/.append style={#1}}},
95 character widths/.code={\pgfkeysalso{/pgf/decoration/text effects/every character width/.style={#1}}},
96 character widths/.append/.code={\pgfkeysalso{/pgf/decoration/text effects/every character width/.append style={#1}}},
97 character count/.store in=\tikz@lib@dec@te@charactercountvar,
98 character count=,
99 character total/.store in=\tikz@lib@dec@te@charactertotalvar,
100 character total=,
101 letter count/.store in=\tikz@lib@dec@te@lettercountvar,
102 letter count=,
103 letter total/.store in=\tikz@lib@dec@te@lettertotalvar,
104 letter total=,
105 word count/.store in=\tikz@lib@dec@te@wordcountvar,
106 word count=,
107 word total/.store in=\tikz@lib@dec@te@wordtotalvar,
108 word total=,
109 %
110 style characters/.code args={#1 with #2}{\tikz@lib@dec@te@parse@stylecharacters{#1}{#2}},
111 text along path/.style={
112 inner xsep=0pt,
113 anchor=base,
114 transform shape
115 },
116 segment from width/.is if=tikz@lib@dec@te@segmentfromwidth,
117 segment from width=true,
118 word separator/.code={%
119 \def\tikz@lib@dec@te@tmp{#1}%
120 \ifx\tikz@lib@dec@te@tmp\tikz@lib@dec@te@space@text%
121 \let\tikz@lib@dec@te@wordsep=\tikz@lib@dec@te@spacetoken%
122 \else%
123 \def\tikz@lib@dec@te@wordsep{#1}
124 \fi},
125 word separator=space,
126 character command/.code={%
127 \def\tikz@lib@dec@te@tmp{#1}%
128 \ifx\tikz@lib@dec@te@tmp\pgfutil@empty%
129 \def\tikz@lib@dec@te@charactercommand{\tikz@lib@dec@te@charactertypesetonly}%
130 \else%
131 \def\tikz@lib@dec@te@charactercommand{#1}%
132 \fi%
133 },
134 character command=,
135 every character width/.style={/pgf/decoration/text effects/every character/.try},
136 every character/.style={},
137 reverse text/.code={\tikz@lib@dec@te@addto@macro\tikz@lib@dec@te@transformtext%
138 {\tikz@lib@dec@te@reversetext}},
139 group letters into words/.code={\tikz@lib@dec@te@addto@macro\tikz@lib@dec@te@transformtext%
140 {\tikz@lib@dec@te@groupletters}},
141 group letters/.code={\tikz@lib@dec@te@addto@macro\tikz@lib@dec@te@transformtext%
142 {\tikz@lib@dec@te@groupletters}},
143 replace characters/.code args={#1 with #2}{\tikz@lib@dec@te@parse@replacecharacters{#1}{#2}},
144 scale text to path/.is if=tikz@lib@dec@te@scaletexttopath,
145 fit text to path/.is if=tikz@lib@dec@te@fittexttopath,
146 repeat text/.store in=\tikz@lib@dec@te@repeattext,
147 repeat text/.default=-1,
148 repeat text=0,
149 }%
150
151
152 \def\tikz@lib@dec@te@charactertypesetonly#1{#1}%
153
154 \tikzset{%
155 text effects/.code={\pgfkeysalso{/pgf/decoration/text effects/.cd,#1}},
156 }%
157
158
159
160
161
162
163 % Prepare the decoration text
164 %
165 % This sets up all the character/letter/word, counts/totals
166 % and calculates the default width of the characters/text
167 % (which may be modified later).
168 %
169 \def\tikz@lib@dec@te@preparetext{%
170 % Step 1: scan all the characters in the decoration text
171 \let\tikz@lib@dec@te@text=\pgfdecorationtext%
172 \tikz@lib@dec@te@scancharacters{%
173 \expandafter\let\csname tikz@lib@dec@te@character@\tikz@lib@dec@te@scancount @token\endcsname=%
174 \tikz@lib@dec@te@character%
175 }%
176 \let\tikz@lib@dec@te@charactertotalcount=\tikz@lib@dec@te@scancount%
177 % Step 2: reverse and/or group characters/letters.
178 \ifx\tikz@lib@dec@te@transformtext\pgfutil@empty%
179 \else%
180 \tikz@lib@dec@te@transformtext%
181 \fi%
182 % Step 3: get the character/letter/word counts
183 \def\tikz@lib@dec@te@charactercount{0}%
184 \def\tikz@lib@dec@te@wordcount{0}%
185 \def\tikz@lib@dec@te@wordsepcount{0}%
186 \def\tikz@lib@dec@te@lettercount{0}%
187 \def\tikz@lib@dec@te@lastcharacter{0}%
188 \pgfmathloop%
189 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
190 \ifnum\tikz@lib@dec@te@lettercount>0\relax%
191 \tikz@lib@dec@te@addto@parameters{\tikz@lib@dec@te@lastcharactercount}{\tikz@lib@dec@te@finallettertrue}%
192 \fi
193 \else%
194 \expandafter\let\expandafter\tikz@lib@dec@te@character\expandafter=\csname tikz@lib@dec@te@character@\pgfmathcounter @token\endcsname%
195 \tikz@lib@dec@te@advancecountmacro{\tikz@lib@dec@te@charactercount}{1}%
196 \tikz@lib@dec@te@start@parameters{\tikz@lib@dec@te@charactercount}%
197 \tikz@lib@dec@te@addmacroto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@charactercount}%
198 \ifx\tikz@lib@dec@te@character\tikz@lib@dec@te@wordsep%
199 \tikz@lib@dec@te@advancecountmacro{\tikz@lib@dec@te@wordsepcount}{1}%
200 \ifnum\tikz@lib@dec@te@lettercount>0\relax%
201 \tikz@lib@dec@te@addto@parameters{\tikz@lib@dec@te@lastcharactercount}{\tikz@lib@dec@te@finallettertrue}%
202 \fi
203 \def\tikz@lib@dec@te@lettercount{0}%
204 \tikz@lib@dec@te@addto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@wordseptrue}%
205 \else
206 \ifnum\tikz@lib@dec@te@lettercount=0\relax%
207 \tikz@lib@dec@te@advancecountmacro\tikz@lib@dec@te@wordcount{1}%
208 \fi%
209 \tikz@lib@dec@te@addto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@finalletterfalse}%
210 \tikz@lib@dec@te@advancecountmacro{\tikz@lib@dec@te@lettercount}{1}%
211 \tikz@lib@dec@te@addto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@wordsepfalse}%
212 \expandafter\let\csname tikz@lib@dec@te@word \tikz@lib@dec@te@wordcount @lettercount\endcsname=\tikz@lib@dec@te@lettercount%
213 \fi%
214 \tikz@lib@dec@te@addmacroto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@lettercount}%
215 \tikz@lib@dec@te@addmacroto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@wordcount}%
216 \tikz@lib@dec@te@addmacroto@parameters{\tikz@lib@dec@te@charactercount}{\tikz@lib@dec@te@character}%
217 \let\tikz@lib@dec@te@lastcharactercount=\pgfmathcounter%
218 \repeatpgfmathloop%
219 \let\tikz@lib@dec@te@wordtotal=\tikz@lib@dec@te@wordcount%
220 % Step 4: add character/letter/word totals
221 \pgfmathloop
222 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
223 \else%
224 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@charactertotalcount}%
225 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@wordtotal}%
226 \expandafter\let\expandafter\tikz@lib@dec@te@lettertotalcount\expandafter=\csname tikz@lib@dec@te@word \tikz@lib@dec@te@wordcount @lettercount\endcsname%
227 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@lettertotalcount}%
228 \repeatpgfmathloop%
229 % Step 5: calculate the the text and character width
230 % but do not add to the parameters yet.
231 \def\tikz@lib@dec@te@textwidth{0pt}%
232 \pgfmathloop%
233 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
234 \else%
235 \def\tikz@lib@dec@te@characterwidth{0pt}%
236 \tikz@lib@dec@te@getcharacterwidth{\pgfmathcounter}%
237 \expandafter\let\csname tikz@lib@dec@te@character@\pgfmathcounter @width\endcsname=\tikz@lib@dec@te@characterwidth%
238 \pgf@x=\tikz@lib@dec@te@characterwidth\relax%
239 \pgf@x=0.5\pgf@x%
240 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @prewidth\endcsname{\the\pgf@x}%
241 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @postwidth\endcsname{\the\pgf@x}%
242 \tikz@lib@dec@te@advancedimenmacro{\tikz@lib@dec@te@textwidth}{\tikz@lib@dec@te@characterwidth}%
243 \repeatpgfmathloop%
244 }%
245
246 % Does the category code of the space matter?
247 \def\tikz@lib@dec@te@spacetoken{ }%
248
249 \let\tikz@lib@dec@te@wordsep=\tikz@lib@dec@te@spacetoken
250
251
252 % Scan and count the characters in \tikz@lib@dec@te@text
253 %
254 % Create macros \tikz@lib@dec@te@character@<n>@token containing
255 % the nth character.
256 %
257 % Total number of characters is store in
258 % \tikz@lib@dec@te@chractertotal@count
259 %
260 \def\tikz@lib@dec@te@scancharacters#1{%
261 \def\tikz@lib@dec@te@@@scancharacters@process{#1}%
262 \def\tikz@lib@dec@te@scancount{0}%
263 \expandafter\tikz@lib@dec@te@@scancharacters\tikz@lib@dec@te@text\tikz@lib@dec@te@scancharacters}%
264
265 \def\tikz@lib@dec@te@@scancharacters{%
266 \futurelet\tikz@lib@dec@te@token\tikz@lib@dec@te@@@scancharacters}%
267
268 \def\tikz@lib@dec@te@@@scancharacters{%
269 \ifx\tikz@lib@dec@te@token\tikz@lib@dec@te@scancharacters%
270 \let\tikz@lib@dec@te@next=\tikz@lib@dec@te@@@@scancharacters%
271 \else%
272 \tikz@lib@dec@te@advancecountmacro\tikz@lib@dec@te@scancount{1}%
273 \ifx\tikz@lib@dec@te@token\pgfutil@sptoken%
274 \let\tikz@lib@dec@te@next=\tikz@lib@dec@te@@@scancharacters@space%
275 \else%
276 \ifx\tikz@lib@dec@te@token\bgroup%
277 \let\tikz@lib@dec@te@next=\tikz@lib@dec@te@@@scancharacters@bgroup%
278 \else%
279 \let\tikz@lib@dec@te@next=\tikz@lib@dec@te@@@scancharacters@normal%
280 \fi%
281 \fi%
282 \fi%
283 \tikz@lib@dec@te@next%
284 }%
285
286 \def\tikz@lib@dec@te@@@scancharacters@space{%
287 \let\tikz@lib@dec@te@character=\tikz@lib@dec@te@spacetoken%
288 \tikz@lib@dec@te@@@scancharacters@process%
289 \pgfutil@ifnextchar x\tikz@lib@dec@te@@scancharacters\tikz@lib@dec@te@@scancharacters%
290 }%
291
292 \def\tikz@lib@dec@te@@@scancharacters@bgroup#1{%
293 \def\tikz@lib@dec@te@character{{#1}}%
294 \tikz@lib@dec@te@@@scancharacters@process%
295 \tikz@lib@dec@te@@scancharacters%
296 }%
297
298 \def\tikz@lib@dec@te@@@scancharacters@normal#1{%
299 \def\tikz@lib@dec@te@character{#1}%
300 \tikz@lib@dec@te@@@scancharacters@process%
301 \tikz@lib@dec@te@@scancharacters%
302 }%
303
304
305 \def\tikz@lib@dec@te@@@@scancharacters#1\tikz@lib@dec@te@scancharacters{}%
306
307
308 % Reverse the order of the scanned characters in the text
309 % (Actually reverse the ordering of the macros containing the characters)
310 \def\tikz@lib@dec@te@reversetext{%
311 \c@pgf@counta=\tikz@lib@dec@te@charactertotalcount%
312 \pgfmathloop%
313 \ifnum\pgfmathcounter>\c@pgf@counta%
314 \else%
315 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@tmp}{tikz@lib@dec@te@character@\pgfmathcounter @token}%
316 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@character@\pgfmathcounter @token}{tikz@lib@dec@te@character@\the\c@pgf@counta @token}%
317 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@character@\the\c@pgf@counta @token}{tikz@lib@dec@te@tmp}%
318 \advance\c@pgf@counta by-1\relax%
319 \repeatpgfmathloop%
320 }%
321
322 % Group letters (i.e., anything that isn't the word separator)
323 % as single characters (words).
324 \def\tikz@lib@dec@te@groupletters{%
325 \c@pgf@counta=0\relax%
326 \let\tikz@lib@dec@te@tmp=\pgfutil@empty%
327 \let\tikz@lib@dec@te@@tmp=\pgfutil@empty%
328 \pgfmathloop%
329 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
330 \ifx\tikz@lib@dec@te@@tmp\pgfutil@empty%
331 \else%
332 \advance\c@pgf@counta by1\relax%
333 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@character@\the\c@pgf@counta @token}{tikz@lib@dec@te@@tmp}%
334 \fi%
335 \else%
336 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@tmp}{tikz@lib@dec@te@character@\pgfmathcounter @token}%
337 \ifx\tikz@lib@dec@te@tmp\tikz@lib@dec@te@wordsep%
338 \advance\c@pgf@counta by1\relax%
339 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@character@\the\c@pgf@counta @token}{tikz@lib@dec@te@@tmp}%
340 \let\tikz@lib@dec@te@@tmp=\pgfutil@empty%
341 \advance\c@pgf@counta by1\relax%
342 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@character@\the\c@pgf@counta @token}{tikz@lib@dec@te@wordsep}%
343 \else%
344 \expandafter\tikz@lib@dec@te@addto@macro\expandafter{\expandafter\tikz@lib@dec@te@@tmp\expandafter}\expandafter{\tikz@lib@dec@te@tmp}%
345 \fi%
346 \repeatpgfmathloop%
347 \edef\tikz@lib@dec@te@charactertotalcount{\the\c@pgf@counta}%
348 }%
349
350
351 % Get width of node containing only the current character.
352 \def\tikz@lib@dec@te@getcharacterwidth#1{%
353 \csname tikz@lib@dec@te@character@#1\endcsname%
354 \tikz@lib@dec@te@getoptions{every character width/.try}%
355 \let\tikz@lib@dec@te@lastcharacterwidth=\tikz@lib@dec@te@characterwidth%
356 \pgfpositionnodelater\tikz@lib@dec@te@@getcharacterwidth%
357 \pgfutil@ifundefined{tikz@lib@dec@te@character@replacements@\meaning\tikz@lib@dec@te@character @code}{%
358 \expandafter\node\expandafter[\tikz@lib@dec@te@options,scale=\tikz@lib@dec@scaledcharacterwidthfactor]%
359 {\hbox{\tikz@lib@dec@te@charactercommand{\tikz@lib@dec@te@character}}};%
360 \let\tikz@lib@dec@te@characterwidth=\tikz@lib@dec@te@characterwidth@tmp%
361 }{%
362 \tikz@lib@dec@te@getcharacter@replacementwidth{\tikz@lib@dec@te@character}%
363 \let\tikz@lib@dec@te@characterwidth=\tikz@lib@dec@te@character@replacementwidth%
364 }%
365 }%
366
367 % Update the character parameters with the widths.
368 \def\tikz@lib@dec@te@addwidthstoparameters{%
369 \pgfmathloop%
370 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
371 \else%
372 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@characterwidth}{tikz@lib@dec@te@character@\pgfmathcounter @width}%
373 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@characterprewidth}{tikz@lib@dec@te@character@\pgfmathcounter @prewidth}%
374 \tikz@lib@dec@te@namelet{tikz@lib@dec@te@characterpostwidth}{tikz@lib@dec@te@character@\pgfmathcounter @postwidth}%
375 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@characterwidth}%
376 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@characterprewidth}%
377 \tikz@lib@dec@te@addmacroto@parameters{\pgfmathcounter}{\tikz@lib@dec@te@characterpostwidth}%
378 \repeatpgfmathloop%
379 }%
380
381 % Get the options to applied to a character node.
382
383 \def\tikz@lib@dec@te@addoptions#1{%
384 \expandafter\def\expandafter\tikz@lib@dec@te@options\expandafter{\tikz@lib@dec@te@options,#1}%
385 }%
386
387 \def\tikz@lib@dec@te@getoptions#1{%
388 \let\tikz@lib@dec@te@lastcharactercommand=\tikz@lib@dec@te@charactercommand%
389 \def\tikz@lib@dec@te@options{/pgf/decoration/text effects/.cd}%
390 \tikz@lib@dec@te@addoptions{#1}%
391 \let\tikzdecorationcharactercount=\tikz@lib@dec@te@charactercount%
392 \let\tikzdecorationcharactertotal=\tikz@lib@dec@te@charactertotalcount%
393 \let\tikzdecorationlettercount=\tikz@lib@dec@te@lettercount%
394 \let\tikzdecorationlettertotal=\tikz@lib@dec@te@lettertotalcount%
395 \let\tikzdecorationwordcount=\tikz@lib@dec@te@wordcount%
396 \let\tikzdecorationwordtotal=\tikz@lib@dec@te@wordtotal%
397 \let\tikzdecorationcharacter=\tikz@lib@dec@te@character%
398 %
399 % Define the count variables (if required)
400 \ifx\tikz@lib@dec@te@charactercountvar\pgfutil@empty%
401 \else%
402 \expandafter\let\tikz@lib@dec@te@charactercountvar=\tikz@lib@dec@te@charactercount%
403 \fi%
404 %
405 \ifx\tikz@lib@dec@te@charactertotalvar\pgfutil@empty%
406 \else%
407 \expandafter\let\tikz@lib@dec@te@charactertotalvar=\tikz@lib@dec@te@charactertotalcount%
408 \fi%
409 %
410 \ifx\tikz@lib@dec@te@wordcountvar\pgfutil@empty%
411 \else%
412 \expandafter\let\tikz@lib@dec@te@wordcountvar=\tikz@lib@dec@te@wordcount%
413 \fi%
414 %
415 \ifx\tikz@lib@dec@te@wordtotalvar\pgfutil@empty%
416 \else%
417 \expandafter\let\tikz@lib@dec@te@wordtotalvar=\tikz@lib@dec@te@wordtotal%
418 \fi%
419 %
420 \ifx\tikz@lib@dec@te@lettercountvar\pgfutil@empty%
421 \else%
422 \expandafter\let\tikz@lib@dec@te@lettercountvar=\tikz@lib@dec@te@lettercount%
423 \fi%
424 %
425 \ifx\tikz@lib@dec@te@lettertotalvar\pgfutil@empty%
426 \else%
427 \expandafter\let\tikz@lib@dec@te@lettertotalvar=\tikz@lib@dec@te@lettetotal%
428 \fi%
429 %
430 \edef\tikz@lib@dec@te@tmp{character \tikz@lib@dec@te@charactercount/.try,%
431 character {\meaning\tikz@lib@dec@te@character}/.try}%
432 \expandafter\tikz@lib@dec@te@addoptions\expandafter{\tikz@lib@dec@te@tmp}%
433 \ifx\tikz@lib@dec@te@character\tikz@lib@dec@te@wordsep%
434 \tikz@lib@dec@te@addoptions{/pgf/decoration/text effects/every word separator/.try}%
435 \else%
436 \ifnum\tikz@lib@dec@te@wordcount>0\relax%
437 \edef\tikz@lib@dec@te@tmp{every word/.try, word \tikz@lib@dec@te@wordcount/.try}%
438 \expandafter\tikz@lib@dec@te@addoptions\expandafter{\tikz@lib@dec@te@tmp}%
439 \ifnum\tikz@lib@dec@te@lettercount>0\relax%
440 \edef\tikz@lib@dec@te@tmp{every letter/.try,every \tikz@lib@dec@te@lettercount\space letter/.try}%
441 \expandafter\tikz@lib@dec@te@addoptions\expandafter{\tikz@lib@dec@te@tmp}%
442 \ifnum\tikz@lib@dec@te@lettercount=1\relax%
443 \edef\tikz@lib@dec@te@tmp{every first letter/.try}%
444 \expandafter\tikz@lib@dec@te@addoptions\expandafter{\tikz@lib@dec@te@tmp}%
445 \fi%
446 \iftikz@lib@dec@te@finalletter%
447 \tikz@lib@dec@te@addoptions{every final letter/.try}%
448 \fi%
449 \fi%
450 \fi%
451 \fi%
452 }%
453
454 % Called by `late positioning' of the node
455 % to get the width of the bounding box
456 % of a character.
457 \def\tikz@lib@dec@te@@getcharacterwidth{%
458 \iftikz@lib@dec@te@segmentfromwidth%
459 \pgf@x=\pgfpositionnodelatermaxx\relax%
460 \advance\pgf@x by-\pgfpositionnodelaterminx\relax%
461 \else%
462 \pgf@x=\pgfpositionnodelatermaxy\relax%
463 \advance\pgf@x by-\pgfpositionnodelaterminy\relax%
464 \fi%
465 \xdef\tikz@lib@dec@te@characterwidth@tmp{\the\pgf@x}%
466 }%
467
468
469 \def\tikz@lib@dec@te@drawcharacter{%
470 \csname tikz@lib@dec@te@character@\tikz@lib@dec@te@charactercount\endcsname%
471 \tikz@lib@dec@te@getoptions{every character/.try}%
472 \pgfpositionnodelater\relax%
473 \pgfutil@ifundefined{tikz@lib@dec@te@character@replacements@\meaning\tikz@lib@dec@te@character @code}{%
474 \expandafter\node\expandafter[\tikz@lib@dec@te@options, scale=\tikz@lib@dec@scaledcharacterwidthfactor]{\hbox{\tikz@lib@dec@te@charactercommand{\tikz@lib@dec@te@character}}};%
475 }{\tikz@lib@dec@te@drawcharacter@replacement{\tikz@lib@dec@te@character}}%
476 }%
477
478 % Replace the character #1 with a character@replacement
479 %
480 \def\tikz@lib@dec@te@drawcharacter@replacement#1{%
481 \pgfscope%
482 \expandafter\tikzset\expandafter{\tikz@lib@dec@te@options}%
483 \csname tikz@lib@dec@te@character@replacements@\meaning#1@code\endcsname%
484 \endpgfscope%
485 }%
486
487 % Get the width of the character@replacement associated with
488 % the character #1
489 %
490 \newbox\tikz@lib@dec@te@box
491 \def\tikz@lib@dec@te@getcharacter@replacementwidth#1{%
492 \pgfinterruptpicture%
493 \setbox\tikz@lib@dec@te@box=\hbox{%
494 \pgfpicture
495 \expandafter\tikzset\expandafter{\tikz@lib@dec@te@options}%
496 \csname tikz@lib@dec@te@character@replacements@\meaning#1@code\endcsname%
497 \endpgfpicture}%
498 \xdef\tikz@lib@dec@te@character@replacementwidth{\the\wd\tikz@lib@dec@te@box}%
499 \endpgfinterruptpicture%
500 }%
501
502 \def\tikz@lib@dec@scaledcharacterwidthfactor{1}%
503
504 % Set up the decoration
505 \def\tikz@lib@dec@te@state@setup@precomputation{%
506 \def\tikz@lib@te@alignshift{0pt}%
507 \iftikz@lib@dec@te@pathfromtext%
508 % The width of the text and characters has already been calculated.
509 \else%
510 \let\tikz@lib@dec@te@text=\pgfdecorationtext%
511 % Get the character tokens and the total number of characters.
512 \tikz@lib@dec@te@preparetext%
513 \iftikz@lib@dec@te@scaletexttopath%
514 % OK, *scaling* text to path is easy.
515 % Simply divide the path length by the text width to
516 % obtain the scaling factor which will be applied
517 % "at the last minute"...
518 \pgfmathdivide{\pgfdecoratedpathlength}{\tikz@lib@dec@te@textwidth}%
519 \let\tikz@lib@dec@scaledcharacterwidthfactor=\pgfmathresult%
520 \expandafter\pgfkeys\expandafter{\tikz@lib@dec@te@tmp}%
521 % ... and recalculate the (pre and post) widths.
522 \pgfmathloop
523 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount%
524 \else%
525 \pgf@x=\csname tikz@lib@dec@te@character@\pgfmathcounter @prewidth\endcsname\relax%
526 \pgf@x=\tikz@lib@dec@scaledcharacterwidthfactor\pgf@x%
527 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @prewidth\endcsname{\the\pgf@x}%
528 %
529 \pgf@x=\csname tikz@lib@dec@te@character@\pgfmathcounter @postwidth\endcsname\relax%
530 \pgf@x=\tikz@lib@dec@scaledcharacterwidthfactor\pgf@x%
531 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @postwidth\endcsname{\the\pgf@x}%
532 \repeatpgfmathloop%
533 % Update parameters with thewidths.
534 \tikz@lib@dec@te@addwidthstoparameters%
535 \let\tikz@lib@dec@te@textwidth=\pgfdecoratedpathlength%
536 \else%
537 \iftikz@lib@dec@te@fittexttopath%
538 % *Fitting* text is less easy.
539 % The pre and post width of all except the first and last characters
540 % must be recalculated.
541 % Only the post width of the first character and the pre width
542 % of the final character are scaled as these characters should be
543 % fixed and the start and end of the path, respectively.
544 %
545 % We hope that the decoration engine is accurate enough to position
546 % the last word correctly.
547 \pgf@x=\pgfdecoratedpathlength%
548 \pgf@xa=\csname tikz@lib@dec@te@character@1@postwidth\endcsname\relax%
549 \pgf@xb=\csname tikz@lib@dec@te@character@\tikz@lib@dec@te@charactertotalcount @prewidth\endcsname\relax%
550 \advance\pgf@x by-\pgf@xa%
551 \advance\pgf@x by-\pgf@xb%
552 \pgf@y=\tikz@lib@dec@te@textwidth\relax%
553 \advance\pgf@y by-\pgf@xa%
554 \advance\pgf@y by-\pgf@xb%
555 %
556 \pgfmathdivide{\the\pgf@x}{\the\pgf@y}%
557 \let\tikz@lib@dec@characterwidthscale=\pgfmathresult%
558 \pgfmathloop
559 \ifnum\pgfmathcounter>\tikz@lib@dec@te@charactertotalcount\relax%
560 \else%
561 \ifnum\pgfmathcounter>1\relax%
562 \pgf@x=\csname tikz@lib@dec@te@character@\pgfmathcounter @prewidth\endcsname\relax%
563 \pgf@x=\tikz@lib@dec@characterwidthscale\pgf@x%
564 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @prewidth\endcsname{\the\pgf@x}%
565 \fi%
566 \ifnum\pgfmathcounter<\tikz@lib@dec@te@charactertotalcount\relax%
567 \pgf@x=\csname tikz@lib@dec@te@character@\pgfmathcounter @postwidth\endcsname\relax%
568 \pgf@x=\tikz@lib@dec@characterwidthscale\pgf@x%
569 \expandafter\edef\csname tikz@lib@dec@te@character@\pgfmathcounter @postwidth\endcsname{\the\pgf@x}%
570 \fi%
571 \repeatpgfmathloop%
572 % Update parameters with widths.
573 \tikz@lib@dec@te@addwidthstoparameters%
574 \let\tikz@lib@dec@te@textwidth=\pgfdecoratedpathlength%
575 \else%
576 % Calculate the distance to move along the path for alignment.
577 \pgfkeysgetvalue{/pgf/decoration/text align/align}{\tikz@lib@dec@align}%
578 \ifx\tikz@lib@dec@align\tikz@lib@dec@align@center@text%
579 \pgf@x=\pgfdecoratedpathlength\relax%
580 \advance\pgf@x by-\tikz@lib@dec@te@textwidth\relax%
581 \ifdim\pgf@x<0pt\relax%
582 \pgf@x=0pt\relax%
583 \fi%
584 \divide\pgf@x by2\relax%
585 % Adjust the pre-width of the first character...
586 \pgf@xa=\csname tikz@lib@dec@te@character@1@prewidth\endcsname\relax%
587 \advance\pgf@xa by\pgf@x%
588 \expandafter\edef\csname tikz@lib@dec@te@character@1@prewidth\endcsname{\the\pgf@xa}%
589 % ...and the post-width of the last character.
590 \pgf@xa=\csname tikz@lib@dec@te@character@\tikz@lib@dec@te@charactertotalcount @postwidth\endcsname\relax%
591 \advance\pgf@xa by\pgf@x%
592 \expandafter\edef\csname tikz@lib@dec@te@character@\tikz@lib@dec@te@charactertotalcount @postwidth\endcsname{\the\pgf@xa}%
593 \else%
594 \ifx\tikz@lib@dec@align\tikz@lib@dec@align@right@text%
595 \pgf@x=\pgfdecoratedpathlength\relax%
596 \advance\pgf@x by-\tikz@lib@dec@te@textwidth\relax%
597 \ifdim\pgf@x<0pt\relax%
598 \pgf@x=0pt\relax%
599 \fi%
600 % Adjust the pre-width of the first character...
601 \pgf@xa=\csname tikz@lib@dec@te@character@1@prewidth\endcsname\relax%
602 \advance\pgf@xa by\pgf@x%
603 \expandafter\edef\csname tikz@lib@dec@te@character@1@prewidth\endcsname{\the\pgf@xa}%
604 \fi%
605 \fi%
606 \tikz@lib@dec@te@addwidthstoparameters%
607 \fi%
608 \fi%
609 \fi%
610 }%
611
612
613 % Evil hack into the decoration code.
614 %
615 % If the path contains single move to and the `path from text'
616 % key is set to true. The width of the text is calculated here
617 % and the (straight line) path automatically calculated.
618 %
619 \def\pgf@decorate@path@check@moveto#1{%
620 \expandafter\pgf@decorate@path@@check@moveto#1\pgf@decorate@stop\pgf@decorate@@stop}%
621
622 \def\pgf@decorate@token@stop{\pgf@decorate@stop}%
623 \def\pgf@decorate@path@@check@moveto#1#2#3#4\pgf@decorate@@stop#5#6{%
624 \def\pgf@decorate@temp{#4}%
625 \pgf@x=#2\relax%
626 \pgf@y=#3\relax%
627 \ifx\pgf@decorate@temp\pgf@decorate@token@stop%
628 \iftikz@lib@dec@te@pathfromtext%
629 % Get the start position...
630 \pgfextract@process\tikz@lib@dec@te@pathstart{}%
631 \tikz@lib@dec@te@preparetext%
632 \tikz@lib@dec@te@addwidthstoparameters%
633 % ... and create a lineto path of the correct length.
634 \pgfsetpath\pgfutil@empty%
635 \pgfpathmoveto{\tikz@lib@dec@te@pathstart}%
636 \pgfpathlineto{\pgfpointadd{\tikz@lib@dec@te@pathstart}%
637 {\pgfpointpolar{\tikz@lib@dec@te@pathfromtextangle}{\tikz@lib@dec@te@textwidth}}}%
638 \pgfgetpath\pgfdecoratedpath%
639 \pgfsetpath\pgfutil@empty%
640 \else%
641 #5%
642 \fi%
643 \else%
644 \tikz@lib@dec@te@pathfromtextfalse%
645 #6%
646 \fi%
647 }%
648
649
650 \pgfdeclaredecoration{text effects along path}{setup}{%
651 \state{setup}[width=+0pt, next state=scan, persistent precomputation={%
652 \tikz@lib@dec@te@state@setup@precomputation%
653 \def\tikz@lib@dec@te@charactercount{0}%
654 }]{}%
655 %
656 \state{scan}[width=+0pt, next state=pre token, persistent precomputation={%
657 \tikz@lib@dec@te@advancecountmacro\tikz@lib@dec@te@charactercount{1}%
658 % Usual switch to final state is based on distance.
659 % Here we also need it to be on the number of the
660 % current character.
661 \ifnum\tikz@lib@dec@te@charactercount>\tikz@lib@dec@te@charactertotalcount\relax%
662 \ifnum\tikz@lib@dec@te@repeattext=0\relax%
663 \def\pgf@decorate@next@state{final}%
664 \else%
665 \tikz@lib@dec@te@advancecountmacro\tikz@lib@dec@te@repeattext{-1}%
666 \def\tikz@lib@dec@te@charactercount{1}%
667 \fi%
668 \fi%
669 % Install parameters for this character.
670 \csname tikz@lib@dec@te@character@\tikz@lib@dec@te@charactercount\endcsname%
671 }]{}%
672 %
673 \state{pre token}[width=+\tikz@lib@dec@te@characterprewidth, next state=token]{}%
674 \state{token}[width=+0pt, next state=post token]
675 {%
676 \tikz@lib@dec@te@drawcharacter%
677 }%
678 \state{post token}[width=+\tikz@lib@dec@te@characterpostwidth, next state=scan]{}%
679 }%
680
681
682 % Parse styles for individual characters
683 % #1 a string of characters (e.g., aieou{\"U}{\"a"})
684 % #2 the options for to apply to each character.
685 %
686 \def\tikz@lib@dec@te@parse@stylecharacters#1#2{%
687 \def\tikz@lib@dec@te@text{#1}%
688 \tikz@lib@dec@te@scancharacters{%
689 \pgfkeysalso{/pgf/decoration/text effects/character {\meaning\tikz@lib@dec@te@character}/.style={#2}}%
690 }%
691 }%
692
693 % Parse replacement code for for individual characters
694 % #1 a string of characters (e.g., aieou{\"U}{\"a"})
695 % #2 the code to execute to each character.
696 %
697 \def\tikz@lib@dec@te@parse@replacecharacters#1#2{%
698 \def\tikz@lib@dec@te@text{#1}%
699 \tikz@lib@dec@te@scancharacters{%
700 \expandafter\def\csname tikz@lib@dec@te@character@replacements@\meaning\tikz@lib@dec@te@character @code\endcsname{#2}%
701 }%
702 }%
703
704 \endinput