| 1 |
%% dvipdfmx.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{dvipdfmx.def} |
| 20 |
[2025/09/29 v5.0n Graphics/color driver for dvipdfmx] |
| 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 |
\Gread@generic{#1}\Gread@extractbb@aux |
| 103 |
} |
| 104 |
\def\Gread@extractbb@aux#1{% |
| 105 |
\ifeof\@inputcheck |
| 106 |
\immediate\openin\@inputcheck=% |
| 107 |
"|extractbb % |
| 108 |
\ifx\Gin@page\@empty\else -p \Gin@page\GPT@space\fi |
| 109 |
\ifx\Gin@pagebox\@empty\else -B \Gin@pagebox\GPT@space\fi |
| 110 |
-O \Gin@base\Gin@ext"% |
| 111 |
\fi |
| 112 |
\Gread@true |
| 113 |
\let\@tempb\Gread@false |
| 114 |
\ifeof\@inputcheck |
| 115 |
\@latex@error |
| 116 |
{Cannot run pipe command. Try --shell-escape^^J% |
| 117 |
(--enable-pipes in MikTeX) option}% |
| 118 |
{}% |
| 119 |
\else |
| 120 |
\loop |
| 121 |
\read\@inputcheck to\@tempa |
| 122 |
\ifeof\@inputcheck |
| 123 |
\Gread@false |
| 124 |
\else |
| 125 |
\expandafter\Gread@find@bb\@tempa:.\\% |
| 126 |
\fi |
| 127 |
\ifGread@ |
| 128 |
\repeat |
| 129 |
\immediate\closein\@inputcheck |
| 130 |
\fi |
| 131 |
} |
| 132 |
\let\Gread@bmp\Gread@pdf |
| 133 |
\newif\ifGread@transgroup |
| 134 |
\def\Ginclude@pdf#1{% |
| 135 |
\let\Gin@decode\@empty |
| 136 |
\Gin@interpolatefalse |
| 137 |
\Gread@transgrouptrue |
| 138 |
\Ginclude@dvipdfmx{#1}% |
| 139 |
} |
| 140 |
\def\Ginclude@bmp#1{% |
| 141 |
\let\Gin@page\@empty |
| 142 |
\let\Gin@pagebox\@empty |
| 143 |
\Gread@transgroupfalse |
| 144 |
\Ginclude@dvipdfmx{#1}% |
| 145 |
} |
| 146 |
\def\Ginclude@dvipdfmx#1{% |
| 147 |
\Gin@log{<#1>}% |
| 148 |
\bgroup |
| 149 |
\def\@tempa{!}% |
| 150 |
\special{pdf:image\GPT@space |
| 151 |
\ifx\Gin@page\@empty\else page\GPT@space\Gin@page\GPT@space\fi |
| 152 |
\ifx\Gin@pagebox\@empty\else pagebox\GPT@space\Gin@pagebox\GPT@space\fi |
| 153 |
bbox\GPT@space\Gin@llx\GPT@space\Gin@lly\GPT@space\Gin@urx\GPT@space\Gin@ury\GPT@space |
| 154 |
clip\GPT@space\ifGin@clip 1\else 0\fi\GPT@space |
| 155 |
\ifx\Gin@scalex\@tempa\else width\GPT@space\the\Gin@req@width\GPT@space\fi |
| 156 |
\ifx\Gin@scaley\@tempa\else height\GPT@space\the\Gin@req@height\GPT@space\fi |
| 157 |
(#1)\GPT@space |
| 158 |
\ifnum0% |
| 159 |
\ifx\Gin@decode\@empty\else 1\fi |
| 160 |
\ifGin@interpolate 1\fi |
| 161 |
\ifGread@transgroup 1\fi |
| 162 |
>0 % |
| 163 |
<<% |
| 164 |
\ifx\Gin@decode\@empty\else /Decode[\Gin@decode]\fi |
| 165 |
\ifGread@transgroup/Group<</S/Transparency/K false/I false>>\fi |
| 166 |
\ifGin@interpolate /Interpolate true\fi |
| 167 |
>>% |
| 168 |
\fi |
| 169 |
}% |
| 170 |
\egroup} |
| 171 |
\newif\if@trim@vport |
| 172 |
\def\Ginclude@eps#1{% |
| 173 |
\Gin@log{<#1>}% |
| 174 |
\bgroup |
| 175 |
\ifx\Undefined\Gin@vllx\else\@trim@vporttrue\fi |
| 176 |
\def\@tempa{!}% |
| 177 |
\dimen@\Gin@urx\p@ |
| 178 |
\advance\dimen@ -\Gin@llx\p@ |
| 179 |
\if@trim@vport |
| 180 |
\advance\dimen@ \Gin@vllx\p@ |
| 181 |
\fi |
| 182 |
\edef\Gin@urx{\strip@pt\dimen@}% |
| 183 |
\dimen@\Gin@ury\p@ |
| 184 |
\advance\dimen@ -\Gin@lly\p@ |
| 185 |
\if@trim@vport |
| 186 |
\advance\dimen@ \Gin@vlly\p@ |
| 187 |
\fi |
| 188 |
\edef\Gin@ury{\strip@pt\dimen@}% |
| 189 |
\dimen@\Gin@req@width |
| 190 |
\[email protected]% |
| 191 |
\divide\dimen@\dimen@ii |
| 192 |
\@tempdima\Gin@req@height |
| 193 |
\divide\@tempdima\dimen@ii |
| 194 |
\special{PSfile="#1"\GPT@space |
| 195 |
\if@trim@vport |
| 196 |
llx=\Gin@vllx\GPT@space |
| 197 |
lly=\Gin@vlly\GPT@space |
| 198 |
\fi |
| 199 |
urx=\Gin@urx\GPT@space |
| 200 |
ury=\Gin@ury\GPT@space |
| 201 |
\ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi |
| 202 |
\ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi |
| 203 |
\ifGin@clip clip\fi}% |
| 204 |
\egroup} |
| 205 |
% |
| 206 |
% In the above \Ginclude@eps, llx, lly, urx, and ury are translated to match |
| 207 |
% the -dEPSCrop option for Ghostscript to convert eps to pdf. |
| 208 |
% In the case of eps files created by MetaPost, the files are included |
| 209 |
% directly without the help of Ghostscript. That is, we have to translate |
| 210 |
% the origin accordingly if we use \Ginclude@eps for eps files created by |
| 211 |
% MetaPost. In TeX Live 2015, the translation of the origin was the default. |
| 212 |
% After TeX Live 2016, however, the translation of the origin is enabled only |
| 213 |
% if the --mvorigin option is given for dvipdfmx or xdvipdfmx. |
| 214 |
% This may be a bit inconvenient, especially in the case of XeTeX where |
| 215 |
% xdvipdfmx is usually called as a pipe. Therefore we introduce a new suffix |
| 216 |
% .mps(or .MPS) to support inclusion of eps files created by MetaPost without |
| 217 |
% the option --mvorigin. |
| 218 |
% |
| 219 |
\def\Ginclude@mps#1{% |
| 220 |
\Gin@log{<#1>}% |
| 221 |
\bgroup |
| 222 |
\def\@tempa{!}% |
| 223 |
\dimen@\Gin@req@width |
| 224 |
\[email protected]% |
| 225 |
\divide\dimen@\dimen@ii |
| 226 |
\@tempdima\Gin@req@height |
| 227 |
\divide\@tempdima\dimen@ii |
| 228 |
\special{PSfile="#1"\GPT@space |
| 229 |
llx=\Gin@llx\GPT@space |
| 230 |
lly=\Gin@lly\GPT@space |
| 231 |
urx=\Gin@urx\GPT@space |
| 232 |
ury=\Gin@ury\GPT@space |
| 233 |
\ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi |
| 234 |
\ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi |
| 235 |
\ifGin@clip clip\fi}% |
| 236 |
\egroup} |
| 237 |
% |
| 238 |
\def\Grot@start{% |
| 239 |
\special{pdf:btrans rotate \Grot@angle}} |
| 240 |
\def\Grot@end{\special{pdf:etrans}} |
| 241 |
|
| 242 |
% 4.13 add support for ptex vertical writing mode |
| 243 |
% inspired by pxtatescale package (Hironobu Yamashita) |
| 244 |
\ifx\kanjiskip\@undefined |
| 245 |
\def\Gscale@start{% |
| 246 |
\special{pdf:btrans}% |
| 247 |
\special{x:scale \Gscale@x\GPT@space\Gscale@y}% |
| 248 |
} |
| 249 |
\else |
| 250 |
\edef\Gscale@start{% |
| 251 |
\special{pdf:btrans}% |
| 252 |
\special{x:scale |
| 253 |
\expandafter\noexpand\csname iftdir\endcsname |
| 254 |
\noexpand\Gscale@y\noexpand\GPT@space\noexpand\Gscale@x |
| 255 |
\expandafter\noexpand\csname else\endcsname |
| 256 |
\noexpand\Gscale@x\noexpand\GPT@space\noexpand\Gscale@y |
| 257 |
\expandafter\noexpand\csname fi\endcsname}} |
| 258 |
\fi |
| 259 |
% |
| 260 |
\def\Gscale@end{\special{pdf:etrans}} |
| 261 |
\def\Gin@PS@raw#1{\special{ps: #1}} |
| 262 |
\def\Gin@PS@restored#1{\special{" #1}} |
| 263 |
\def\Gin@PS@literal@header#1{\AtBeginDvi{\special{! #1}}} |
| 264 |
\def\Gin@PS@file@header#1{\AtBeginDvi{\special{header=#1}}} |
| 265 |
\def\Gin@extensions{% order here is like xetex.def, except for PS |
| 266 |
.pdf,.PDF,.ai,.AI,% |
| 267 |
.png,.PNG,.jpg,.JPG,.jpeg,.JPEG,.jp2,.JP2,.jpf,.JPF,.bmp,.BMP,% |
| 268 |
.ps,.PS,.eps,.EPS,.mps,.MPS} |
| 269 |
% |
| 270 |
\@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}} |
| 271 |
\@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}} |
| 272 |
% |
| 273 |
\@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}} |
| 274 |
\@namedef{Gin@[email protected]}#1{{pdf}{.xbb}{#1}} |
| 275 |
% |
| 276 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 277 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 278 |
% |
| 279 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 280 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 281 |
% |
| 282 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 283 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 284 |
% |
| 285 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 286 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 287 |
% |
| 288 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 289 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 290 |
% |
| 291 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 292 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 293 |
% |
| 294 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 295 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 296 |
% |
| 297 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 298 |
\@namedef{Gin@[email protected]}#1{{bmp}{.xbb}{#1}} |
| 299 |
% |
| 300 |
\@namedef{Gin@[email protected]}#1{{eps}{.ps}{#1}} |
| 301 |
\@namedef{Gin@[email protected]}#1{{eps}{.ps}{#1}} |
| 302 |
% |
| 303 |
\@namedef{Gin@[email protected]}#1{{eps}{.eps}{#1}} |
| 304 |
\@namedef{Gin@[email protected]}#1{{eps}{.eps}{#1}} |
| 305 |
% |
| 306 |
\@namedef{Gin@[email protected]}#1{{mps}{.mps}{#1}} |
| 307 |
\@namedef{Gin@[email protected]}#1{{mps}{.mps}{#1}} |
| 308 |
% |
| 309 |
\@namedef{Gin@rule@*}#1{{eps}{\Gin@ext}{#1}} |
| 310 |
\@ifundefined{ifGin@setpagesize} |
| 311 |
{\expandafter\let\csname ifGin@setpagesize\expandafter\endcsname |
| 312 |
\csname iftrue\endcsname} |
| 313 |
{} |
| 314 |
\@ifundefined{stockwidth}{\newdimen\stockwidth}{} |
| 315 |
\@ifundefined{stockheight}{\newdimen\stockheight}{} |
| 316 |
\ifGin@setpagesize |
| 317 |
\ifx\paperwidth\@undefined\else |
| 318 |
\AtBeginDocument{% |
| 319 |
% If a package has changed \mag, assume it knows what it is doing |
| 320 |
% and leave page size alone |
| 321 |
\ifnum\mag=\@m |
| 322 |
\AtBeginDvi{% |
| 323 |
\begingroup |
| 324 |
\ifdim\stockwidth>\z@ |
| 325 |
\ifdim\stockheight>\z@ |
| 326 |
\special{papersize=\the\stockwidth,\the\stockheight}% |
| 327 |
\else |
| 328 |
\ifdim\paperwidth>\z@ |
| 329 |
\ifdim\paperheight>\z@ |
| 330 |
\special{papersize=\the\paperwidth,\the\paperheight}% |
| 331 |
\fi |
| 332 |
\fi |
| 333 |
\fi |
| 334 |
\else |
| 335 |
\ifdim\stockwidth=\z@ |
| 336 |
\ifdim\paperwidth>\z@ |
| 337 |
\ifdim\paperheight>\z@ |
| 338 |
\special{papersize=\the\paperwidth,\the\paperheight}% |
| 339 |
\fi |
| 340 |
\fi |
| 341 |
\fi |
| 342 |
\fi |
| 343 |
\endgroup}% |
| 344 |
\fi |
| 345 |
} |
| 346 |
\fi |
| 347 |
\fi |
| 348 |
\endinput |
| 349 |
% Conversion functions so the internal representation stays unchanged |
| 350 |
\let\init@current@color\current@color |
| 351 |
\def\convert@color#1{% |
| 352 |
\ifx#1\init@current@color |
| 353 |
\expandafter\convert@color@init |
| 354 |
\else |
| 355 |
\expandafter\convert@@color |
| 356 |
\fi |
| 357 |
#1% |
| 358 |
} |
| 359 |
\def\convert@color@init#1{0 g 0 G} |
| 360 |
\def\convert@@color#1{% |
| 361 |
\expandafter\expandafter\expandafter\convert@@@color#1\stop |
| 362 |
} |
| 363 |
\def\convert@@@color#1 #2\stop{% |
| 364 |
\csname convert@color@#1\endcsname{#2}% |
| 365 |
} |
| 366 |
\def\convert@color@cmyk#1{#1 k #1 K} |
| 367 |
\def\convert@color@gray#1{#1 g #1 G} |
| 368 |
\def\convert@color@rgb#1{#1 rg #1 RG} |
| 369 |
\def\convert@color@#1{% |
| 370 |
\expandafter\expandafter\expandafter\convert@@color |
| 371 |
\expandafter\expandafter\expandafter{\csname col@#1\endcsname}% |
| 372 |
} |
| 373 |
% Deal with named colors |
| 374 |
\def\define@color@named#1#2{\expandafter\edef\csname col@#1\endcsname{#2}} |
| 375 |
% Change the specials to use the stack |
| 376 |
\ifdefined\main@pdfcolorstack\else |
| 377 |
\chardef\main@pdfcolorstack=1 % |
| 378 |
\ifx\AtBeginDvi\undefined |
| 379 |
\long\def\@firstofone#1{#1}% |
| 380 |
\expandafter\@firstofone |
| 381 |
\else |
| 382 |
\expandafter\AtBeginDvi |
| 383 |
\fi |
| 384 |
{\special{pdfcolorstackinit \the\main@pdfcolorstack\space page direct (0 g 0 G)}} |
| 385 |
\fi |
| 386 |
\def\@pdfcolorstack{\the\main@pdfcolorstack\space} |
| 387 |
\def\set@color{% |
| 388 |
\special{pdfcolorstack \@pdfcolorstack push (\convert@color\current@color)}% |
| 389 |
\aftergroup \reset@color |
| 390 |
} |
| 391 |
\def\reset@color{% |
| 392 |
\special{pdfcolorstack \@pdfcolorstack pop}% |
| 393 |
} |
| 394 |
% Reinsert stack color to over-ride built-in reinsertion of pdf:bc color |
| 395 |
\def\Grot@end{\special{pdf:etrans}\special{pdfcolorstack \@pdfcolorstack current}} |
| 396 |
\let\Gscale@end\Grot@end |
| 397 |
\def\GPT@clipbox#1{% |
| 398 |
\setbox#1=\hbox{% |
| 399 |
\Gin@defaultbp\WIDTH{\wd#1}% |
| 400 |
\Gin@defaultbp\DEPTH{\dp#1}% |
| 401 |
\@tempdima\ht#1% |
| 402 |
\advance\@tempdima\dp#1% |
| 403 |
\Gin@defaultbp\TOTALHEIGHT{\@tempdima}% |
| 404 |
\special{x:gsave}% |
| 405 |
\special{% |
| 406 |
pdf:literal |
| 407 |
0 -\DEPTH\GPT@space \WIDTH\GPT@space \TOTALHEIGHT\GPT@space re W n |
| 408 |
}% |
| 409 |
\rlap{\box#1}% |
| 410 |
\special{x:grestore}% |
| 411 |
\special{pdfcolorstack \@pdfcolorstack current}% |
| 412 |
\hskip\wd#1% |
| 413 |
}% |
| 414 |
} |