Debian Codegraph @

texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_pgfcoreimage.code.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%% This file is a copy of some part of PGF/Tikz.
3 %%% It has been copied here to provide :
4 %%% - compatibility with older PGF versions
5 %%% - availability of PGF contributions by Christian Feuersaenger
6 %%% which are necessary or helpful for pgfplots.
7 %%%
8 %%% For reasons of simplicity, I have copied the whole file, including own contributions AND
9 %%% PGF parts. The copyrights are as they appear in PGF.
10 %%%
11 %%% Note that pgfplots has compatible licenses.
12 %%%
13 %%% This copy has been modified in the following ways:
14 %%% - nested \input commands have been updated
15 %%%
16 %
17 % Support for the contents of this file will NOT be done by the PGF/TikZ team.
18 % Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction
19 % with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything:
20 % This file comes without any warranty as the rest of pgfplots; there is no obligation for help.
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %%% Date of this copy: Mon Mar 22 16:42:03 CET 2010 %%%
23
24
25
26 % Copyright 2006 by Till Tantau
27 %
28 % This file may be distributed and/or modified
29 %
30 % 1. under the LaTeX Project Public License and/or
31 % 2. under the GNU Public License.
32 %
33 % See the file doc/generic/pgf/licenses/LICENSE for more details.
34
35 \ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcoreimage.code.tex,v 1.14 2010/03/19 09:50:32 ludewich Exp $
36
37
38
39 % Declare an image
40 %
41 % #1 = optional argument: width, height, page specification
42 % #2 = name of the image for later use
43 % #4 = filename without extension, automatic extensions are .pdf,
44 % .jpg, and .png for PDF and .ps, .eps, .epsi for postscript.
45 %
46 % Description:
47 %
48 % This command declares an image file for later use. Even if the image
49 % is used several times in the document, in PDF it will only be stored
50 % once.
51 %
52 % Example:
53 %
54 % \pgfdeclareimage[width=2cm,page=2]{myimage}{imagefilename}
55
56 \def\pgfdeclareimage{\pgfutil@ifnextchar[{\pgf@declareimage}{\pgf@declareimage[]}}
57 \def\pgf@declareimage[#1]#2#3{%
58 \pgfqkeys{/pgf/images}{height=,width=,page=,interpolate=false,mask=,#1}%
59 % Try to find the file
60 \gdef\pgf@filename{}%
61 % If page= parameter is not empty, try that file first:
62 \ifx\pgf@imagepage\pgfutil@empty%
63 \else%
64 \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3.page\pgf@imagepage}%
65 \fi%
66 \ifx\pgf@filename\pgfutil@empty%
67 \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}%
68 \else%
69 \pgfkeys{/pgf/images/page=}% make page empty
70 \fi%
71 \ifx\pgf@filename\pgfutil@empty%
72 \PackageWarning{pgf}%
73 {File "#3" not found when defining image "#2".\MessageBreak
74 Tried all extensions in "\pgfsys@imagesuffixlist"}%
75 \pgf@declaredraftimage{#2}{#3}%
76 \else%
77 \ifpgf@draftmode%
78 \pgf@declaredraftimage{#2}{#3}%
79 \else%
80 \pgfsys@defineimage%
81 \fi%
82 \fi%
83 \expandafter\global\expandafter\let\csname pgf@image@#2!\endcsname=\pgf@image%
84 }
85
86 \newif\ifpgfexternal@allow@aux
87
88 \pgfkeys{
89 /pgf/images/include external/.code={\pgfimage{#1}},
90 /pgf/images/aux in dpth/.is if=pgfexternal@allow@aux,
91 /pgf/images/aux in dpth/.default=true,
92 /pgf/images/draft/.is if=pgf@draftmode,
93 /pgf/images/draft/.default=true}
94 \pgfkeys{/pgf/images/width/.estore in=\pgf@imagewidth}
95 \pgfkeys{/pgf/images/height/.estore in=\pgf@imageheight}
96 \pgfkeys{/pgf/images/page/.estore in=\pgf@imagepage}
97 \pgfkeys{/pgf/images/interpolate/.cd,.code=\edef\pgf@imageinterpolate{#1},.default=true}
98 \pgfkeys{/pgf/images/mask/.code=%
99 {%
100 \edef\pgf@imagemask{#1}%
101 \ifx\pgf@imagemask\pgfutil@empty%
102 \else%
103 \pgfutil@ifundefined{pgf@mask@#1}%
104 {\PackageError{pgf}{Undefined mask "#1".}{}%
105 \edef\pgf@imagemask{}}%
106 {\edef\pgf@imagemask{\csname pgf@mask@#1\endcsname}%
107 }%
108 \fi%
109 }}
110
111
112 \def\pgf@findfile#1:#2+#3{%
113 \pgfutil@IfFileExists{#3#1}%
114 {\xdef\pgf@filename{#3#1}}%
115 {\def\pgf@mightbeempty{#2}%
116 \ifx\pgf@mightbeempty\pgfutil@empty\else%
117 \pgf@findfile#2+{#3}%
118 \fi}}
119
120 % #1: image name
121 % #2: file name
122 \def\pgf@declaredraftimage#1#2{%
123 \ifx\pgf@imagewidth\pgfutil@empty%
124 \PackageWarning{pgf}{Missing width for image "#1" ("#2") in draft mode.\MessageBreak Using 1cm instead}%
125 \edef\pgf@imagewidth{1cm}%
126 \fi%
127 \ifx\pgf@imageheight\pgfutil@empty%
128 \PackageWarning{pgf}{Missing height for image "#1" ("#2") in draft mode.\MessageBreak Using 1cm instead}%
129 \edef\pgf@imageheight{1cm}%
130 \fi%
131 \ifx\pgf@imagepage\pgfutil@empty\else\edef\pgf@imagepagetext{ page \pgf@imagepage}\fi%
132 \edef\pgf@image{%
133 \hbox to \pgf@imagewidth{%
134 \vrule\kern-0.4pt%
135 \vbox to \pgf@imageheight{%
136 \hrule\vfil%
137 \hbox to \pgf@imagewidth{\hskip-10cm\hfil\noexpand\tiny#2\pgf@imagepage\hfil\hskip-10cm}%
138 \vfil\hrule}%
139 \kern-0.4pt\vrule}%
140 }%
141 }
142
143
144
145 % Declare a soft mask
146 %
147 % #1 = optional argument: matte specification. default matte is
148 % white.
149 % #2 = name of the mask for later use
150 % #3 = filename without extension, automatic extensions are .pdf,
151 % .jpg, and .png for PDF. Postscript is not supported.
152 %
153 % Description:
154 %
155 % This command declares a soft mask for later masking an image. The
156 % declared mask should be used together with an image of exactly the
157 % same height/width if matte is defined. Matte should be the
158 % preblended background color (see pdf spec for details).
159 %
160 % Example:
161 %
162 % \pgfdeclaremask[matte=white]{maskname}{maskfilename}
163 % \pgfdeclareimage[mask=maskname]{image}{imagefilename}
164
165 \def\pgfdeclaremask{\pgfutil@ifnextchar[\pgf@declaremask{\pgf@declaremask[]}}
166 \def\pgf@declaremask[#1]#2#3{%
167 \pgfqkeys{/pgf/images/mask}{matte={1 1 1},#1}% defaults
168 \def\pgf@mask{}%
169 % Try to find the file
170 \gdef\pgf@filename{}%
171 \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}%
172 \ifx\pgf@filename\pgfutil@empty%
173 \PackageWarning{pgf}%
174 {File "#3" not found when defining mask "#2".\MessageBreak
175 Tried all extensions in "\pgfsys@imagesuffixlist"}%
176 \else%
177 \pgfsys@definemask{#2}%
178 \fi%
179 \expandafter\global\expandafter\let\csname pgf@mask@#2\endcsname=\pgf@mask%
180 }
181
182 \pgfkeys{/pgf/images/mask/matte/.cd,.estore in=\pgf@maskmatte,.value required}
183
184
185
186 % Create an alias name for an image
187 %
188 % #1 = name of the alias
189 % #2 = name of the original
190 %
191 % Example:
192 %
193 % \pgfdeclareimage{image}{1cm}{1cm}{filename
194 % \pgfaliasimage{alias}{image}
195 % \pgfuseimage{alias}
196
197 \def\pgfaliasimage#1#2{%
198 \expandafter\global\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@image@#2!\endcsname%
199 \expandafter\global\expandafter\let\csname pgf@image@#1!\endcsname=\pgf@temp%
200 }
201
202
203 % Use an image
204 %
205 % #1 = name of a previously declared image
206 %
207 % Example:
208 %
209 % \pgfputat{\pgforigin}{\pgfbox[left,base]{\pgfuseimage{myimage}}}
210
211 \def\pgfuseimage#1{%
212 \def\pgf@imagename{pgf@image@#1}%
213 \pgf@tryextensions{\pgf@imagename}{\pgfalternateextension}%
214 \expandafter\pgfutil@ifundefined\expandafter{\pgf@imagename}%
215 {\PackageError{pgf}{Undefined image "#1"}{}}%
216 {{\leavevmode\csname\pgf@imagename\endcsname}}}
217
218 \def\pgf@tryextensions#1#2{%
219 \edef\pgf@args{[#2!]}\expandafter\pgf@@tryextensions\pgf@args{#1}}
220 \def\pgf@@tryextensions[#1!#2]#3{%
221 \expandafter\pgfutil@ifundefined\expandafter{#3#1!#2}%
222 {\def\pgf@temp{#2}%
223 \ifx\pgf@temp\pgfutil@empty%
224 \edef#3{#3!}%
225 \else%
226 \pgf@@tryextensions[#2]{#3}%
227 \fi}%
228 {\edef#3{#3#1!#2}}}
229
230
231 % Alternate image
232 %
233 % Description:
234 %
235 % When an image is used, pgf first attempts to use the image with the
236 % alternate extension added. If this fails, the original image is
237 % used. If the alternate extension contains ``!'', then the text up to
238 % the ! is successively removed and the remainder is tried as an
239 % alternate extension.
240 %
241 % Example:
242 %
243 % \def\pgfalternateextension{20!white}
244
245 \def\pgfalternateextension{}
246
247
248
249 % Directly insert an image
250 %
251 % #1 = optional argument: width, height, page specification
252 % #2 = file name
253 %
254 % Description:
255 %
256 % Directly inserts an image without declaration. You can, however,
257 % still access this image using the name pgflastimage. By using
258 % pgfaliasimage, you can also save this image for later.
259 %
260 % Example:
261 %
262 % \pgfimage[height=2cm]{filename}
263
264 \def\pgfimage{\pgfutil@ifnextchar[\pgf@imagecom{\pgf@imagecom[]}}
265 \def\pgf@imagecom[#1]#2{%
266 \pgfdeclareimage[#1]{pgflastimage}{#2}%
267 \pgfuseimage{pgflastimage}}
268
269
270
271
272
273
274
275
276 % The external read/write mechanism is used as follows:
277 %
278 % In your document, you put a number or all of your pgfpicture (or
279 % tikzpicture) environments inside a pair of \beginpgfexternal and
280 % \endpgfexternal. The \beginpgfexternal gets one parameter called the
281 % graphics name.
282 %
283 % Once this is done, the next step is to declare the names of your
284 % graphics in the document at the beginning using the
285 % \pgfdeclaregraphicname command.
286 %
287 % Now, when you typeset your document, each time a \beginpgfexternal
288 % command is encountered, it will be checked whether the corresponding
289 % graphics file exists. If this is the case, it will be included and
290 % the code between \beginpgfexternal and \endpgfexternal is
291 % ignored. Otherwise, the code is executed normally.
292 %
293 % Things change when you run tex on your file with the \jobname set to
294 % the name of a decalred graphics name. In this case, only your
295 % graphic will be typeset, the rest of the document will be "thrown away".
296 % To be more precise, everything is gobbled up to the beginning
297 % of the first \beginpgfexternal with the given graphics name. Then,
298 % the content of the "environment" is put in a box (this "environment"
299 % need not contain a graphics, it may contain anything that can be put
300 % in a box). Then a single page is output whose size is exactly the
301 % size of the picture.
302 %
303 % So, once you have run tex repeatedly, each time with the jobname set
304 % to each of the graphics, you can then run tex on the whole document
305 % and this will cause all graphics to be included rather than begin
306 % typeset.
307 %
308 % Finally, once all the graphics have been created, you can also say
309 % \input pgfexternal.tex instead of including pgf/TikZ.
310
311
312 \newif\ifpgfexternalreadmainaux
313 \pgfexternalreadmainauxtrue
314
315 % Tells pgf which jobname is the name of the real file
316 %
317 % #1 = name
318 %
319 % Description:
320 %
321 % This command is used to tell pgf that the file named #1 should be
322 % typeset normally. If \jobname is not equal to #1, only
323 % the graphic called \jobname will be typeset.
324 %
325 % Example:
326 %
327 % \pgfrealjobname{survey}
328 %
329 % Note that afterwards, \jobname will be set to the argument. In our
330 % example, \jobname will be 'survey'. This is to accomplish
331 % compatibility with aux-file generation.
332
333 \def\pgfrealjobname#1{%
334 \global\let\pgfactualjobname=\jobname
335 \edef\pgf@tempa{\expandafter\string\csname #1\endcsname}%
336 \edef\pgf@tempb{\expandafter\string\csname\jobname\endcsname}%
337 \ifx\pgf@tempa\pgf@tempb%
338 \else%
339 \pgf@external@grabshipouttrue%
340 \pgfexternal@nofiles
341 \ifpgfexternalreadmainaux
342 % and reset the jobname. This should allow to handle any
343 % \label/\ref constructions which are stored in \jobname.aux (and
344 % which won't be found otherwise)
345 \gdef\jobname{#1}%
346 \fi
347 \ifpgfexternal@allow@aux
348 \csname newwrite\endcsname\w@pgfexternal@auxout
349 \fi
350 \fi%
351 \gdef\pgfrealjobname##1{}% avoid multiple calls.
352 }
353
354 \def\pgfexternal@nofiles{%
355 % replace \relax. The \nofiles macros does
356 % \let\makeglossary=\relax
357 % but the glossary.sty calls \renewcommand\makeglossary (which
358 % will fail if \makeglossary=\relax). Stupid, but it works.
359 \let\pgfexternal@nofiles@=\relax
360 \def\relax{\relax}%
361 %
362 % suppress generation of LaTeX .aux, .toc etc files.
363 % generation of these files is not thread-safe.
364 % the \csname \endcsname yields \relax if \nofiles doesn't exist.
365 \csname nofiles\endcsname
366 %
367 \let\relax=\pgfexternal@nofiles@
368 }%
369
370 \newif\ifpgf@external@grabshipout
371 \newbox\pgfexternal@startupbox
372
373 \AtBeginDocument{%
374 \ifpgf@external@grabshipout%
375 \global\let\pgfexternal@originalshipout=\shipout%
376 \global\def\shipout{\setbox\pgfpic=}%
377 \maxdeadcycles=10000%
378 % Ok, gather everything we have seen up to now in a box. This box
379 % will contain any specials that have been used.
380 {%
381 \output{\global\setbox\pgfexternal@startupbox=\vbox{\csname @begindvi\endcsname\unvbox255}}%
382 \hbox{}\eject%
383 }%
384 \fi%
385 }
386
387
388 % "Environment" for an external graphic.
389 %
390 % #1 = graphic name
391 %
392 % Example:
393 %
394 % \beginpgfgraphicnamed{main-graphic2}
395 % \begin{tikzpicture}
396 % ...
397 % \end{tikzpicture}
398 % \endpgfgraphicnamed
399
400 \def\pgf@externalbegin#1{%
401 % First, check whether we wish to grab this graphic:
402 \let\pgf@next=\pgf@external@normal%
403 \ifpgf@external@grabshipout%
404 \edef\pgf@tempa{\expandafter\string\csname #1\endcsname}%
405 \edef\pgf@tempb{\expandafter\string\csname\pgfactualjobname\endcsname}%
406 \ifx\pgf@tempa\pgf@tempb%
407 \let\pgf@next=\pgf@external@grab%
408 \fi%
409 \fi%
410 \pgf@next{#1}%
411 }
412
413
414 \AtBeginDocument{
415 \let\beginpgfgraphicnamed=\pgf@externalbegin% overwrite definition of pgfexternal.tex if necessary
416 \let\endpgfgraphicnamed=\unskip
417 }
418
419
420 % Normal operation: Include an external graphic instead of the
421 % picture, if such an external picture exists.
422 \def\pgf@external@normal#1{%
423 \let\pgf@filename=\pgfutil@empty%
424 \expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#1}%
425 \ifx\pgf@filename\pgfutil@empty%
426 % Ok, no such image... Just typeset the picture normally.
427 \let\pgf@next=\relax%
428 \else%
429 \let\pgf@next=\pgf@replacepicturebygraphic%
430 \fi%
431 \pgf@next%
432 }
433
434 \long\def\pgf@replacepicturebygraphic#1\endpgfgraphicnamed{%
435 \expandafter\pgfincludeexternalgraphics\expandafter{\pgf@filename}\unskip
436 }
437
438 % This is almost the same as \includegraphics{#1}, but it checks
439 % whether '#1.dpth' exists. In such case, it restores the boxes depth
440 % stored in #1.dpth.
441 %
442 % Furthermore, the .dpth file may contain .aux related information
443 % collected for the external graphics (references). They start after
444 % the first line (if any).
445 \def\pgfincludeexternalgraphics#1{%
446 \begingroup
447 \setbox1=\hbox{\pgfkeysvalueof{/pgf/images/include external/.@cmd}{#1}\pgfeov}%
448 %
449 \let\pgfincludeexternalgraphics@dp=\pgfutil@empty
450 \endlinechar=-1 % suppress white space at end
451 \catcode`\@=11
452 \openin\r@pgf@reada=#1.dpth
453 \pgfincludeexternalgraphics@read@dpth
454 \ifx\pgfincludeexternalgraphics@dp\pgfutil@empty
455 \box1
456 \else
457 \dimen0=\pgfincludeexternalgraphics@dp\relax
458 \hbox{\lower\dimen0 \box1 }%
459 \fi
460 \endgroup
461 }
462 %
463 % The .dpth consists of 0-N lines, where each is either a single
464 % dimension (the box' depth) or something which belongs to the .aux
465 % file (such lines will always start with a macro).
466 \def\pgfincludeexternalgraphics@read@dpth{%
467 \ifeof\r@pgf@reada
468 \closein\r@pgf@reada
469 \else
470 \read\r@pgf@reada to\pgfincludeexternalgraphics@auxline
471 \ifx\pgfincludeexternalgraphics@auxline\pgfutil@empty
472 \else
473 \expandafter\pgfincludeexternalgraphics@read@dpth@line\pgfincludeexternalgraphics@auxline\pgfincludeexternalgraphics@read@dpth@line@EOI
474 \fi
475 \expandafter\pgfincludeexternalgraphics@read@dpth
476 \fi
477 }%
478 \long\def\pgfincludeexternalgraphics@read@dpth@line#1#2\pgfincludeexternalgraphics@read@dpth@line@EOI{%
479 \ifcat\noexpand#1\relax
480 % Ah -- the first token is a control sequence. It belongs to
481 % the .aux file.
482 %
483 % #1#2\relax% do NOT set the information! many LaTeX commands don't support it (\label for example)
484 \pgfutil@ifundefined{if@filesw}{%
485 % sorry, .aux file support only for latex
486 }{%
487 % append to main .aux file (for forward references)
488 \if@filesw
489 {%
490 \toks0={#1#2}%
491 % believe it or not, but the
492 % \def\dpthimport{...}\dpthimport *makes* a
493 % difference! In ensures any occuring `##' characters
494 % are properly expanded to `#'.
495 \immediate\write\@auxout{\noexpand\def\noexpand\dpthimport{\the\toks0 }\noexpand\dpthimport }%
496 }%
497 \fi
498 }%
499 \else
500 \def\pgfincludeexternalgraphics@dp{#1#2}%
501 \fi
502 }%
503
504
505
506 % Grab operation: If jobname matches the graphic name, typeset this
507 % picture normall.
508 % REMARK:
509 % this method is also invoked from within the tikz external library.
510 \def\pgf@external@grab#1{%
511 \def\pgf@filename{#1}%
512 \ifpgfexternal@allow@aux
513 \begingroup
514 \pgf@external@init@aux@in@dpth
515 \fi
516 \setbox\pgfpic=\hbox\bgroup\bgroup%
517 \let\endpgfgraphicnamed=\pgf@externalend%
518 }
519
520 \let\pgf@external@@protected@write@orig=\protected@write
521 \long\def\pgf@external@@protected@write@immediate#1#2#3{%
522 \begingroup
523 \let\pgf@write@=\write
524 \def\write{\noexpand\immediate\pgf@write@}%
525 \pgf@external@@protected@write@orig{#1}{#2}{#3}%
526 \endgroup
527 }%
528
529 \def\pgf@external@init@aux@in@dpth{%
530 % tell LaTeX to write aux files...
531 \csname @fileswtrue\endcsname
532 % ... but redirect output to the .dpth file!
533 \immediate\openout\w@pgfexternal@auxout=\[email protected]
534 \let\@auxout=\w@pgfexternal@auxout
535 % ... and disable the correct page numbers. I can't get that
536 % (because the correct page number is only available in the
537 % shipout routine). Use immediate output:
538 \let\protected@write=\pgf@external@@protected@write@immediate
539 }%
540
541 % REMARK:
542 % this method is also invoked from within the tikz external library.
543 \def\pgf@externalend{%
544 \unskip\egroup\egroup%
545 {%
546 \parindent0pt % leave the space
547 % \leftmargin0pt%
548 % \rightmargin0pt%
549 \dimen0\ht\pgfpic%
550 \advance\dimen0\dp\pgfpic%
551 \ifdim\dp\pgfpic=0pt\relax
552 \else% store the picture's depth. Otherwise, it would be lost.
553 \ifpgfexternal@allow@aux
554 \immediate\write\@auxout{\the\dp\pgfpic}%
555 \immediate\closeout\@auxout
556 \else
557 \immediate\openout\pgf@plotwrite=\[email protected]
558 \immediate\write\pgf@plotwrite{\the\dp\pgfpic}%
559 \immediate\closeout\pgf@plotwrite
560 \fi
561 \fi
562 \pgfsys@papersize{\the\wd\pgfpic}{\the\dimen0}%
563 \setbox0=\vbox{%
564 \kern -1truein %
565 \hbox{%
566 \kern -1truein %
567 \hbox to0pt{%
568 \wd\pgfexternal@startupbox=0pt %
569 \ht\pgfexternal@startupbox=0pt %
570 \dp\pgfexternal@startupbox=0pt %
571 \box\pgfexternal@startupbox%
572 \pgfsys@atbegindocument\hss}%
573 \box\pgfpic%
574 \kern 1truein }%
575 \kern1truein }%
576 \pgfexternal@originalshipout\box0 %
577 }%
578 \ifpgfexternal@allow@aux
579 \endgroup
580 \fi
581 }
582
583
584 \endinput