Debian Codegraph @

texmf-dist/tex/latex/graphics-def/xetex.def

raw
1 %% xetex.def
2 %% Copyright (C) 2005-2025 LaTeX3 Project, Jin-Hwan Cho, Shunsaku Hirata
3 %% (with contributions from many others)
4 %%
5 %% This work may be distributed and/or modified under the
6 %% conditions of the LaTeX Project Public License, either version 1.3c
7 %% of this license or (at your option) any later version.
8 %% The latest version of this license is in
9 %% http://www.latex-project.org/lppl.txt
10 %% and version 1.3c or later is part of all distributions of LaTeX
11 %% version 2005/12/01 or later.
12 %%
13 %% This work has the LPPL maintenance status `maintained'.
14 %%
15 %% The Current Maintainer of this work is the LaTeX3 Project.
16 %%
17 %% https://github.com/latex3/graphics-def/issues
18 %%
19 \ProvidesFile{xetex.def}
20 [2025/11/01 v5.0p Graphics/color driver for xetex]
21 \def\GPT@space{ }
22 \def\c@lor@arg#1{%
23 \dimen@#1\p@
24 \ifdim\dimen@<\z@\dimen@\maxdimen\fi
25 \ifdim\dimen@>\p@
26 \PackageError{color}{Argument `#1' not in range [0,1]}\@ehd
27 \fi}
28 \def\color@gray#1#2{%
29 \c@lor@arg{#2}%
30 \edef#1{gray #2}%
31 }
32 \def\color@cmyk#1#2{\c@lor@@cmyk#2\@@#1}
33 \def\c@lor@@cmyk#1,#2,#3,#4\@@#5{%
34 \c@lor@arg{#4}%
35 \c@lor@arg{#1}%
36 \c@lor@arg{#2}%
37 \c@lor@arg{#3}%
38 \edef#5{cmyk #1 #2 #3 #4}%
39 }
40 \def\color@rgb#1#2{\c@lor@@rgb#2\@@#1}
41 \def\c@lor@@rgb#1,#2,#3\@@#4{%
42 \c@lor@arg{#1}%
43 \c@lor@arg{#2}%
44 \c@lor@arg{#3}%
45 \edef#4{rgb #1 #2 #3}%
46 }
47 \def\color@RGB#1#2{\c@lor@@RGB#2\@@#1}
48 \def\c@lor@@RGB#1,#2,#3\@@#4{%
49 \c@lor@RGB@rgb{#1}\@tempa
50 \c@lor@RGB@rgb{#2}\@tempb
51 \c@lor@RGB@rgb{#3}\@tempc
52 \c@lor@@rgb\@tempa,\@tempb,\@tempc\@@#4%
53 }
54 \def\c@lor@RGB@rgb#1#2{%
55 \dimen@#1\p@
56 \divide\dimen@\@cclv
57 \edef#2{\strip@pt\dimen@}}
58 \def\color@hsb#1#2{\c@lor@@hsb#2\@@#1}
59 \def\c@lor@@hsb#1,#2,#3\@@#4{%
60 \c@lor@arg{#1}%
61 \c@lor@arg{#2}%
62 \c@lor@arg{#3}%
63 \edef#4{hsb #1 #2 #3}%
64 }
65 \def\color@named#1#2{\c@lor@@named#2,,\@@#1}
66 \def\c@lor@@named#1,#2,#3\@@#4{%
67 \@ifundefined{col@#1}%
68 {\PackageError{color}{Undefined color `#1'}\@ehd}%
69 {\edef#4{ #1}}%
70 }
71 \def\c@lor@to@ps#1 #2\@@{\csname c@lor@ps@#1\endcsname#2 \@@}
72 \def\c@lor@ps@#1 #2\@@{TeXDict begin #1 end}
73 \def\c@lor@ps@rgb#1\@@{#1 setrgbcolor}
74 \def\c@lor@ps@hsb#1\@@{#1 sethsbcolor}
75 \def\c@lor@ps@cmyk#1\@@{#1 setcmykcolor}
76 \def\c@lor@ps@gray#1\@@{#1 setgray}
77 \def\current@color{ Black}
78 \def\set@color{%
79 \special{color push \current@color
80 }\aftergroup\reset@color}
81 \def\reset@color{\special{%
82 color pop}}
83 \def\set@page@color{\special{%
84 background \current@color}}
85 \def\define@color@named#1#2{%
86 \expandafter\let\csname col@#1\endcsname\@nnil}
87 % white is special cased as "no background color" by dvipdfmx
88 \def\no@page@color{\special{background gray 1}}
89 \@ifundefined{Gin@decode}
90 {\let\Gin@decode\@empty}
91 {}
92 \@ifundefined{Gin@page}
93 {\let\Gin@page\@empty}
94 {}
95 \@ifundefined{Gin@pagebox}
96 {\def\Gin@pagebox{cropbox}}
97 {}
98 \@ifundefined{Gin@interpolate}
99 {\csname newif\endcsname\ifGin@interpolate}
100 {}
101 \def\Gread@pdf#1{%
102 \let\Gin@decode\@empty
103 \Gin@interpolatefalse
104 \Gread@@xetex\XeTeXpdffile
105 }
106 \def\Gread@bmp#1{%
107 \let\Gin@page\@empty
108 \let\Gin@pagebox\@empty
109 \Gread@@xetex\XeTeXpicfile
110 }
111 \def\Gread@@xetex#1{%
112 \IfFileExists{\[email protected]}%
113 {\Gread@eps{\[email protected]}}%
114 {\Gread@@xetex@aux#1}%
115 }
116 \def\Gread@@xetex@aux#1{%
117 \edef\Gin@attr@hash{%
118 \ifx\Gin@pagebox\@empty
119 \else
120 :\Gin@pagebox
121 \fi
122 \ifx\Gin@page\@empty
123 \else
124 :P\Gin@page
125 \fi
126 }%
127 \edef\Gin@@name{\Gin@base\Gin@ext}%
128 \@ifundefined{\Gin@@name\GPT@space height\Gin@attr@hash}%
129 {%
130 \setbox\@tempboxa=\hbox{%
131 #1"\Gin@@name"\GPT@space
132 \ifx\Gin@page\@empty\else page \Gin@page\fi
133 \ifx\Gin@pagebox\@empty\else\expandafter\Gread@@xetex@box\Gin@pagebox\fi
134 }%
135 \def\Gin@llx{0}\let\Gin@lly\Gin@llx
136 \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
137 \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
138 \expandafter\xdef\csname \Gin@@name\GPT@space height\Gin@attr@hash\endcsname
139 {\the\ht\@tempboxa}%
140 \expandafter\xdef\csname \Gin@@name\GPT@space width\Gin@attr@hash\endcsname
141 {\the\wd\@tempboxa}%
142 }{%
143 \def\Gin@llx{0}\let\Gin@lly\Gin@llx
144 \Gin@defaultbp\Gin@urx
145 {\csname \Gin@@name\GPT@space width\Gin@attr@hash\endcsname}%
146 \Gin@defaultbp\Gin@ury
147 {\csname \Gin@@name\GPT@space height\Gin@attr@hash\endcsname}%
148 }%
149 }
150 \def\Gread@@xetex@box#1box{#1}
151 \def\GPT@setup@scale{%
152 \def\@tempa{!}%
153 \ifx\Gin@scaley\@tempa
154 \let\Gin@scaley\Gin@scalex
155 \else
156 \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
157 \fi
158 }
159 \def\Ginclude@pdf#1{%
160 \GPT@setup@scale
161 \Gin@log{%
162 <use #1%
163 \ifx\Gin@page\@empty\else, page \Gin@page\fi
164 >%
165 }%
166 \hbox{%
167 \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
168 \@ifundefined{Gin@vllx}{%
169 \GPT@viewportfalse
170 % without viewport/trim clipping does not make sense
171 % for pdfTeX
172 \Gin@clipfalse
173 }{}%
174 \ifGin@clip
175 \if!\Gin@vllx\Gin@vlly\Gin@vurx\Gin@vury!%
176 \else
177 \let\GPT@clipend\GPT@DoClipEnd
178 \setbox\@tempboxa\hbox\bgroup
179 \fi
180 \fi
181 \ifGPT@viewport
182 \ifdim\Gin@vlly\p@=\z@
183 \else
184 \lower\Gin@vlly bp\hbox\bgroup
185 \fi
186 \ifdim\Gin@vllx\p@=\z@
187 \else
188 \hskip-\Gin@vllx bp\relax
189 \fi
190 \fi
191 \XeTeXpdffile"#1" %
192 \ifx\Gin@page\@empty\else page \Gin@page\fi
193 \ifx\Gin@pagebox\@empty\else\expandafter\Gread@@xetex@box\Gin@pagebox\fi
194 \ifGPT@viewport
195 \ifdim\Gin@vlly\p@=\z@
196 \else
197 \egroup
198 \fi
199 \GPT@clipend
200 \fi
201 }%
202 }%
203 }
204 \newif\ifGPT@viewport
205 \GPT@viewporttrue
206 \let\GPT@clipend\relax
207 \def\GPT@DoClipEnd{%
208 \egroup
209 \dp\@tempboxa\z@
210 % \Gin@urx and \Gin@ury already contain the correct values,
211 % so both cases viewport and trim can be handled together:
212 \dimen@\Gin@urx\p@
213 \advance\dimen@ -\Gin@llx\p@
214 \wd\@tempboxa\strip@pt\dimen@ bp\relax
215 \dimen@\Gin@ury\p@
216 \advance\dimen@ -\Gin@lly\p@
217 \ht\@tempboxa\strip@pt\dimen@ bp\relax
218 \GPT@clipbox\@tempboxa
219 \box\@tempboxa
220 }
221 \def\GPT@clipbox#1{%
222 \setbox#1=\hbox{%
223 \Gin@defaultbp\WIDTH{\wd#1}%
224 \Gin@defaultbp\DEPTH{\dp#1}%
225 \@tempdima\ht#1%
226 \advance\@tempdima\dp#1%
227 \Gin@defaultbp\TOTALHEIGHT{\@tempdima}%
228 \special{x:gsave}%
229 \special{%
230 pdf:literal
231 0 -\DEPTH\GPT@space \WIDTH\GPT@space \TOTALHEIGHT\GPT@space re W n
232 }%
233 \rlap{\box#1}%
234 \special{x:grestore}%
235 \hskip\wd#1%
236 }%
237 }
238 \def\Ginclude@bmp#1{%
239 \Gin@log{<#1>}%
240 \bgroup
241 \def\@tempa{!}%
242 \special{pdf:image\GPT@space
243 bbox\GPT@space\Gin@llx\GPT@space\Gin@lly\GPT@space\Gin@urx\GPT@space\Gin@ury\GPT@space
244 clip\GPT@space\ifGin@clip 1\else 0\fi\GPT@space
245 \ifx\Gin@scalex\@tempa\else width\GPT@space\the\Gin@req@width\GPT@space\fi
246 \ifx\Gin@scaley\@tempa\else height\GPT@space\the\Gin@req@height\GPT@space\fi
247 (#1)\GPT@space
248 \ifnum0%
249 \ifx\Gin@decode\@empty\else 1\fi
250 \ifGin@interpolate 1\fi
251 >0 %
252 <<%
253 \ifx\Gin@decode\@empty\else /Decode[\Gin@decode]\fi
254 \ifGin@interpolate /Interpolate true\fi
255 >>%
256 \fi
257 }%
258 \egroup
259 }
260 \newif\if@trim@vport
261 \def\Ginclude@eps#1{%
262 \Gin@log{<#1>}%
263 \bgroup
264 \ifx\Undefined\Gin@vllx\else\@trim@vporttrue\fi
265 \def\@tempa{!}%
266 \dimen@\Gin@urx\p@
267 \advance\dimen@ -\Gin@llx\p@
268 \if@trim@vport
269 \advance\dimen@ \Gin@vllx\p@
270 \fi
271 \edef\Gin@urx{\strip@pt\dimen@}%
272 \dimen@\Gin@ury\p@
273 \advance\dimen@ -\Gin@lly\p@
274 \if@trim@vport
275 \advance\dimen@ \Gin@vlly\p@
276 \fi
277 \edef\Gin@ury{\strip@pt\dimen@}%
278 \dimen@\Gin@req@width
279 \[email protected]%
280 \divide\dimen@\dimen@ii
281 \@tempdima\Gin@req@height
282 \divide\@tempdima\dimen@ii
283 \special{PSfile="#1"\GPT@space
284 \if@trim@vport
285 llx=\Gin@vllx\GPT@space
286 lly=\Gin@vlly\GPT@space
287 \fi
288 urx=\Gin@urx\GPT@space
289 ury=\Gin@ury\GPT@space
290 \ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi
291 \ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi
292 \ifGin@clip clip\fi}%
293 \egroup}
294 %
295 % In the above \Ginclude@eps, llx, lly, urx, and ury are translated to match
296 % the -dEPSCrop option for Ghostscript to convert eps to pdf.
297 % In the case of eps files created by MetaPost, the files are included
298 % directly without the help of Ghostscript. That is, we have to translate
299 % the origin accordingly if we use \Ginclude@eps for eps files created by
300 % MetaPost. In TeX Live 2015, the translation of the origin was the default.
301 % After TeX Live 2016, however, the translation of the origin is enabled only
302 % if the --mvorigin option is given for xdvipdfmx
303 % This may be a bit inconvenient, especially as
304 % xdvipdfmx is usually called as a pipe. Therefore we introduce a new suffix
305 % .mps(or .MPS) to support inclusion of eps files created by MetaPost without
306 % the option --mvorigin.
307 %
308 \def\Ginclude@mps#1{%
309 \Gin@log{<#1>}%
310 \bgroup
311 \def\@tempa{!}%
312 \dimen@\Gin@req@width
313 \[email protected]%
314 \divide\dimen@\dimen@ii
315 \@tempdima\Gin@req@height
316 \divide\@tempdima\dimen@ii
317 \special{PSfile="#1"\GPT@space
318 llx=\Gin@llx\GPT@space
319 lly=\Gin@lly\GPT@space
320 urx=\Gin@urx\GPT@space
321 ury=\Gin@ury\GPT@space
322 \ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi
323 \ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi
324 \ifGin@clip clip\fi}%
325 \egroup}
326 %
327 \def\Grot@start{%
328 \special{pdf:btrans rotate \Grot@angle}}
329 \def\Grot@end{\special{pdf:etrans}}
330
331 % 4.13 add support for ptex vertical writing mode
332 % inspired by pxtatescale package (Hironobu Yamashita)
333 \ifx\kanjiskip\@undefined
334 \def\Gscale@start{%
335 \special{pdf:btrans}%
336 \special{x:scale \Gscale@x\GPT@space\Gscale@y}%
337 }
338 \else
339 \edef\Gscale@start{%
340 \special{pdf:btrans}%
341 \special{x:scale
342 \expandafter\noexpand\csname iftdir\endcsname
343 \noexpand\Gscale@y\noexpand\GPT@space\noexpand\Gscale@x
344 \expandafter\noexpand\csname else\endcsname
345 \noexpand\Gscale@x\noexpand\GPT@space\noexpand\Gscale@y
346 \expandafter\noexpand\csname fi\endcsname}}
347 \fi
348 %
349 \def\Gscale@end{\special{pdf:etrans}}
350 \def\Gin@PS@raw#1{\special{ps: #1}}
351 \def\Gin@PS@restored#1{\special{" #1}}
352 \def\Gin@PS@literal@header#1{\AtBeginDvi{\special{! #1}}}
353 \def\Gin@PS@file@header#1{\AtBeginDvi{\special{header=#1}}}
354 \def\Gin@extensions{% order here is like pdftex.def, except for PS
355 .pdf,.PDF,.ai,.AI,%
356 .png,.PNG,.jpg,.JPG,.jpeg,.JPEG,.jp2,.JP2,.jpf,.JPF,.bmp,.BMP,%
357 .ps,.PS,.eps,.EPS,.mps,.MPS}
358 %
359 \@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}}
360 \@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}}
361 %
362 \@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}}
363 \@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}}
364 %
365 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
366 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
367 %
368 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
369 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
370 %
371 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
372 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
373 %
374 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
375 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
376 %
377 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
378 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
379 %
380 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
381 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
382 %
383 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
384 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
385 %
386 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
387 \@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}}
388 %
389 \@namedef{Gin@[email protected]}#1{{eps}{.ps}{#1}}
390 \@namedef{Gin@[email protected]}#1{{eps}{.ps}{#1}}
391 %
392 \@namedef{Gin@[email protected]}#1{{eps}{.eps}{#1}}
393 \@namedef{Gin@[email protected]}#1{{eps}{.eps}{#1}}
394 %
395 \@namedef{Gin@[email protected]}#1{{mps}{.mps}{#1}}
396 \@namedef{Gin@[email protected]}#1{{mps}{.mps}{#1}}
397 %
398 \@namedef{Gin@rule@*}#1{{eps}{\Gin@ext}{#1}}
399 \@ifundefined{ifGin@setpagesize}
400 {\expandafter\let\csname ifGin@setpagesize\expandafter\endcsname
401 \csname iftrue\endcsname}
402 {}
403 \@ifundefined{stockwidth}{\newdimen\stockwidth}{}
404 \@ifundefined{stockheight}{\newdimen\stockheight}{}
405 \ifGin@setpagesize
406 \ifx\paperwidth\@undefined\else
407 \AtBeginDocument{%
408 % If a package has changed \mag, assume it knows what it is doing
409 % and leave page size alone
410 \ifnum\mag=\@m
411 \ifdim\stockwidth>0pt\relax
412 \ifdim\stockheight>0pt\relax
413 \setlength{\pdfpagewidth}{\stockwidth}%
414 \setlength{\pdfpageheight}{\stockheight}%
415 \else
416 \ifdim\paperwidth>0pt\relax
417 \ifdim\paperheight>0pt\relax
418 \setlength{\pdfpagewidth}{\paperwidth}%
419 \setlength{\pdfpageheight}{\paperheight}%
420 \fi
421 \fi
422 \fi
423 \else
424 \ifdim\stockwidth=0pt\relax
425 \ifdim\paperwidth>0pt\relax
426 \ifdim\paperheight>0pt\relax
427 \setlength{\pdfpagewidth}{\paperwidth}%
428 \setlength{\pdfpageheight}{\paperheight}%
429 \fi
430 \fi
431 \fi
432 \fi
433 \fi
434 }
435 \fi
436 \fi
437 \endinput
438 % Conversion functions so the internal representation stays unchanged
439 \let\init@current@color\current@color
440 \def\convert@color#1{%
441 \ifx#1\init@current@color
442 \expandafter\convert@color@init
443 \else
444 \expandafter\convert@@color
445 \fi
446 #1%
447 }
448 \def\convert@color@init#1{0 g 0 G}
449 \def\convert@@color#1{%
450 \expandafter\expandafter\expandafter\convert@@@color#1\stop
451 }
452 \def\convert@@@color#1 #2\stop{%
453 \csname convert@color@#1\endcsname{#2}%
454 }
455 \def\convert@color@cmyk#1{#1 k #1 K}
456 \def\convert@color@gray#1{#1 g #1 G}
457 \def\convert@color@rgb#1{#1 rg #1 RG}
458 \def\convert@color@#1{%
459 \expandafter\expandafter\expandafter\convert@@color
460 \expandafter\expandafter\expandafter{\csname col@#1\endcsname}%
461 }
462 % Deal with named colors
463 \def\define@color@named#1#2{\expandafter\edef\csname col@#1\endcsname{#2}}
464 % Change the specials to use the stack
465 \ifdefined\main@pdfcolorstack\else
466 \chardef\main@pdfcolorstack=1 %
467 \ifx\AtBeginDvi\undefined
468 \long\def\@firstofone#1{#1}%
469 \expandafter\@firstofone
470 \else
471 \expandafter\AtBeginDvi
472 \fi
473 {\special{pdfcolorstackinit \the\main@pdfcolorstack\space page direct (0 g 0 G)}}
474 \fi
475 \def\@pdfcolorstack{\the\main@pdfcolorstack\space}
476 \def\set@color{%
477 \special{pdfcolorstack \@pdfcolorstack push (\convert@color\current@color)}%
478 \aftergroup \reset@color
479 }
480 \def\reset@color{%
481 \special{pdfcolorstack \@pdfcolorstack pop}%
482 }
483 % Reinsert stack color to over-ride built-in reinsertion of pdf:bc color
484 \def\Grot@end{\special{pdf:etrans}\special{pdfcolorstack \@pdfcolorstack current}}
485 \let\Gscale@end\Grot@end
486 \def\GPT@clipbox#1{%
487 \setbox#1=\hbox{%
488 \Gin@defaultbp\WIDTH{\wd#1}%
489 \Gin@defaultbp\DEPTH{\dp#1}%
490 \@tempdima\ht#1%
491 \advance\@tempdima\dp#1%
492 \Gin@defaultbp\TOTALHEIGHT{\@tempdima}%
493 \special{x:gsave}%
494 \special{%
495 pdf:literal
496 0 -\DEPTH\GPT@space \WIDTH\GPT@space \TOTALHEIGHT\GPT@space re W n
497 }%
498 \rlap{\box#1}%
499 \special{x:grestore}%
500 \special{pdfcolorstack \@pdfcolorstack current}%
501 \hskip\wd#1%
502 }%
503 }