| 1 |
% Copyright 2018 by Till Tantau |
| 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 |
\ProvidesFileRCS{pgfcoreimage.code.tex} |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
% Declare an image |
| 15 |
% |
| 16 |
% #1 = optional argument: width, height, page specification |
| 17 |
% #2 = name of the image for later use |
| 18 |
% #4 = filename without extension, automatic extensions are .pdf, |
| 19 |
% .jpg, and .png for PDF and .ps, .eps, .epsi for postscript. |
| 20 |
% |
| 21 |
% Description: |
| 22 |
% |
| 23 |
% This command declares an image file for later use. Even if the image |
| 24 |
% is used several times in the document, in PDF it will only be stored |
| 25 |
% once. |
| 26 |
% |
| 27 |
% Example: |
| 28 |
% |
| 29 |
% \pgfdeclareimage[width=2cm,page=2]{myimage}{imagefilename} |
| 30 |
|
| 31 |
\def\pgfdeclareimage{\pgfutil@ifnextchar[{\pgf@declareimage}{\pgf@declareimage[]}} |
| 32 |
\def\pgf@declareimage[#1]#2#3{% |
| 33 |
\pgfqkeys{/pgf/images}{height=,width=,page=,interpolate=false,mask=,#1}% |
| 34 |
% Try to find the file |
| 35 |
\gdef\pgf@filename{}% |
| 36 |
% If page= parameter is not empty, try that file first: |
| 37 |
\ifx\pgf@imagepage\pgfutil@empty% |
| 38 |
\else% |
| 39 |
\expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3.page\pgf@imagepage}% |
| 40 |
\fi% |
| 41 |
\ifx\pgf@filename\pgfutil@empty% |
| 42 |
\expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}% |
| 43 |
\else% |
| 44 |
\pgfkeys{/pgf/images/page=}% make page empty |
| 45 |
\fi% |
| 46 |
\ifx\pgf@filename\pgfutil@empty% |
| 47 |
\pgfwarning% |
| 48 |
{File "#3" not found when defining image "#2". |
| 49 |
Tried all extensions in "\pgfsys@imagesuffixlist"}% |
| 50 |
\pgf@declaredraftimage{#2}{#3}% |
| 51 |
\else% |
| 52 |
\ifpgf@draftmode% |
| 53 |
\pgf@declaredraftimage{#2}{#3}% |
| 54 |
\else% |
| 55 |
\pgfsys@defineimage% |
| 56 |
\fi% |
| 57 |
\fi% |
| 58 |
\expandafter\global\expandafter\let\csname pgf@image@#2!\endcsname=\pgf@image% |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
\pgfkeys{ |
| 63 |
/pgf/images/draft/.is if=pgf@draftmode, |
| 64 |
/pgf/images/draft/.default=true} |
| 65 |
\pgfkeys{/pgf/images/width/.estore in=\pgf@imagewidth} |
| 66 |
\pgfkeys{/pgf/images/height/.estore in=\pgf@imageheight} |
| 67 |
\pgfkeys{/pgf/images/page/.estore in=\pgf@imagepage} |
| 68 |
\pgfkeys{/pgf/images/interpolate/.cd,.code=\edef\pgf@imageinterpolate{#1},.default=true} |
| 69 |
\let\pgf@imageinterpolate\pgfutil@empty |
| 70 |
\pgfkeys{/pgf/images/mask/.code=% |
| 71 |
{% |
| 72 |
\edef\pgf@imagemask{#1}% |
| 73 |
\ifx\pgf@imagemask\pgfutil@empty% |
| 74 |
\else% |
| 75 |
\pgfutil@ifundefined{pgf@mask@#1}% |
| 76 |
{\pgferror{Undefined mask "#1".}% |
| 77 |
\edef\pgf@imagemask{}}% |
| 78 |
{\edef\pgf@imagemask{\csname pgf@mask@#1\endcsname}% |
| 79 |
}% |
| 80 |
\fi% |
| 81 |
}} |
| 82 |
|
| 83 |
|
| 84 |
\def\pgf@findfile#1:#2+#3{% |
| 85 |
\pgfutil@IfFileExists{#3#1}% |
| 86 |
{\xdef\pgf@filename{#3#1}}% |
| 87 |
{\def\pgf@mightbeempty{#2}% |
| 88 |
\ifx\pgf@mightbeempty\pgfutil@empty\else% |
| 89 |
\pgf@findfile#2+{#3}% |
| 90 |
\fi}} |
| 91 |
|
| 92 |
% #1: image name |
| 93 |
% #2: file name |
| 94 |
\def\pgf@declaredraftimage#1#2{% |
| 95 |
\ifx\pgf@imagewidth\pgfutil@empty% |
| 96 |
\pgfwarning{Missing width for image "#1" ("#2") in draft mode. Using 1cm instead}% |
| 97 |
\edef\pgf@imagewidth{1cm}% |
| 98 |
\fi% |
| 99 |
\ifx\pgf@imageheight\pgfutil@empty% |
| 100 |
\pgfwarning{Missing height for image "#1" ("#2") in draft mode. Using 1cm instead}% |
| 101 |
\edef\pgf@imageheight{1cm}% |
| 102 |
\fi% |
| 103 |
\ifx\pgf@imagepage\pgfutil@empty\else\edef\pgf@imagepagetext{ page \pgf@imagepage}\fi% |
| 104 |
\edef\pgf@image{% |
| 105 |
\hbox to \pgf@imagewidth{% |
| 106 |
\vrule\kern-0.4pt% |
| 107 |
\vbox to \pgf@imageheight{% |
| 108 |
\hrule\vfil% |
| 109 |
\hbox to \pgf@imagewidth{\hskip-10cm\hfil\noexpand\pgfutil@font@tiny#2\pgf@imagepage\hfil\hskip-10cm}% |
| 110 |
\vfil\hrule}% |
| 111 |
\kern-0.4pt\vrule}% |
| 112 |
}% |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
% Declare a soft mask |
| 118 |
% |
| 119 |
% #1 = optional argument: matte specification. default matte is |
| 120 |
% white. |
| 121 |
% #2 = name of the mask for later use |
| 122 |
% #3 = filename without extension, automatic extensions are .pdf, |
| 123 |
% .jpg, and .png for PDF. Postscript is not supported. |
| 124 |
% |
| 125 |
% Description: |
| 126 |
% |
| 127 |
% This command declares a soft mask for later masking an image. The |
| 128 |
% declared mask should be used together with an image of exactly the |
| 129 |
% same height/width if matte is defined. Matte should be the |
| 130 |
% preblended background color (see pdf spec for details). |
| 131 |
% |
| 132 |
% Example: |
| 133 |
% |
| 134 |
% \pgfdeclaremask[matte=white]{maskname}{maskfilename} |
| 135 |
% \pgfdeclareimage[mask=maskname]{image}{imagefilename} |
| 136 |
|
| 137 |
\def\pgfdeclaremask{\pgfutil@ifnextchar[\pgf@declaremask{\pgf@declaremask[]}} |
| 138 |
\def\pgf@declaremask[#1]#2#3{% |
| 139 |
\pgfqkeys{/pgf/images/mask}{matte={1 1 1},#1}% defaults |
| 140 |
\def\pgf@mask{}% |
| 141 |
% Try to find the file |
| 142 |
\gdef\pgf@filename{}% |
| 143 |
\expandafter\pgf@findfile\pgfsys@imagesuffixlist:+{#3}% |
| 144 |
\ifx\pgf@filename\pgfutil@empty% |
| 145 |
\pgfwarning% |
| 146 |
{File "#3" not found when defining mask "#2". |
| 147 |
Tried all extensions in "\pgfsys@imagesuffixlist"}% |
| 148 |
\else% |
| 149 |
\pgfsys@definemask% |
| 150 |
\fi% |
| 151 |
\expandafter\global\expandafter\let\csname pgf@mask@#2\endcsname=\pgf@mask% |
| 152 |
} |
| 153 |
|
| 154 |
\pgfkeys{/pgf/images/mask/matte/.cd,.estore in=\pgf@maskmatte,.value required} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
% Create an alias name for an image |
| 159 |
% |
| 160 |
% #1 = name of the alias |
| 161 |
% #2 = name of the original |
| 162 |
% |
| 163 |
% Example: |
| 164 |
% |
| 165 |
% \pgfdeclareimage{image}{1cm}{1cm}{filename |
| 166 |
% \pgfaliasimage{alias}{image} |
| 167 |
% \pgfuseimage{alias} |
| 168 |
|
| 169 |
\def\pgfaliasimage#1#2{% |
| 170 |
\expandafter\global\expandafter\let\expandafter\pgf@temp\expandafter=\csname pgf@image@#2!\endcsname% |
| 171 |
\expandafter\global\expandafter\let\csname pgf@image@#1!\endcsname=\pgf@temp% |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
% Use an image |
| 176 |
% |
| 177 |
% #1 = name of a previously declared image |
| 178 |
% |
| 179 |
% Example: |
| 180 |
% |
| 181 |
% \pgfputat{\pgforigin}{\pgfbox[left,base]{\pgfuseimage{myimage}}} |
| 182 |
|
| 183 |
\def\pgfuseimage#1{% |
| 184 |
\def\pgf@imagename{pgf@image@#1}% |
| 185 |
\pgf@tryextensions{\pgf@imagename}{\pgfalternateextension}% |
| 186 |
\expandafter\pgfutil@ifundefined\expandafter{\pgf@imagename}% |
| 187 |
{\pgferror{Undefined image "#1"}}% |
| 188 |
{{\leavevmode\csname\pgf@imagename\endcsname}}} |
| 189 |
|
| 190 |
\def\pgf@tryextensions#1#2{% |
| 191 |
\edef\pgf@args{[#2!]}\expandafter\pgf@@tryextensions\pgf@args{#1}} |
| 192 |
\def\pgf@@tryextensions[#1!#2]#3{% |
| 193 |
\expandafter\pgfutil@ifundefined\expandafter{#3#1!#2}% |
| 194 |
{\def\pgf@temp{#2}% |
| 195 |
\ifx\pgf@temp\pgfutil@empty% |
| 196 |
\edef#3{#3!}% |
| 197 |
\else% |
| 198 |
\pgf@@tryextensions[#2]{#3}% |
| 199 |
\fi}% |
| 200 |
{\edef#3{#3#1!#2}}} |
| 201 |
|
| 202 |
|
| 203 |
% Alternate image |
| 204 |
% |
| 205 |
% Description: |
| 206 |
% |
| 207 |
% When an image is used, pgf first attempts to use the image with the |
| 208 |
% alternate extension added. If this fails, the original image is |
| 209 |
% used. If the alternate extension contains ``!'', then the text up to |
| 210 |
% the ! is successively removed and the remainder is tried as an |
| 211 |
% alternate extension. |
| 212 |
% |
| 213 |
% Example: |
| 214 |
% |
| 215 |
% \def\pgfalternateextension{20!white} |
| 216 |
|
| 217 |
\def\pgfalternateextension{} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
% Directly insert an image |
| 222 |
% |
| 223 |
% #1 = optional argument: width, height, page specification |
| 224 |
% #2 = file name |
| 225 |
% |
| 226 |
% Description: |
| 227 |
% |
| 228 |
% Directly inserts an image without declaration. You can, however, |
| 229 |
% still access this image using the name pgflastimage. By using |
| 230 |
% pgfaliasimage, you can also save this image for later. |
| 231 |
% |
| 232 |
% Example: |
| 233 |
% |
| 234 |
% \pgfimage[height=2cm]{filename} |
| 235 |
|
| 236 |
\def\pgfimage{\pgfutil@ifnextchar[\pgf@imagecom{\pgf@imagecom[]}} |
| 237 |
\def\pgf@imagecom[#1]#2{% |
| 238 |
\pgfdeclareimage[#1]{pgflastimage}{#2}% |
| 239 |
\pgfuseimage{pgflastimage}} |
| 240 |
|
| 241 |
|
| 242 |
\endinput |