summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/graphics-def/dvipdfmx.def
blob: 1d82661b1191ba58606343808a6cbf17ad7226d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
%% dvipdfmx.def
%% Copyright (C) 2005-2022 LaTeX3 Project, Jin-Hwan Cho, Shunsaku Hirata
%%                         (with contributions from many others)
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is the LaTeX3 Project.
%%
%% https://github.com/latex3/graphics-def/issues
%%
\ProvidesFile{dvipdfmx.def}
  [2022/04/16 v5.0l Graphics/color driver for dvipdfmx]
\def\GPT@space{ }
\def\c@lor@arg#1{%
  \dimen@#1\p@
  \ifdim\dimen@<\z@\dimen@\maxdimen\fi
  \ifdim\dimen@>\p@
    \PackageError{color}{Argument `#1' not in range [0,1]}\@ehd
  \fi}
\def\color@gray#1#2{%
  \c@lor@arg{#2}%
  \edef#1{gray #2}%
  }
\def\color@cmyk#1#2{\c@lor@@cmyk#2\@@#1}
\def\c@lor@@cmyk#1,#2,#3,#4\@@#5{%
  \c@lor@arg{#4}%
  \c@lor@arg{#1}%
  \c@lor@arg{#2}%
  \c@lor@arg{#3}%
  \edef#5{cmyk #1 #2 #3 #4}%
  }
\def\color@rgb#1#2{\c@lor@@rgb#2\@@#1}
\def\c@lor@@rgb#1,#2,#3\@@#4{%
  \c@lor@arg{#1}%
  \c@lor@arg{#2}%
  \c@lor@arg{#3}%
  \edef#4{rgb #1 #2 #3}%
  }
\def\color@RGB#1#2{\c@lor@@RGB#2\@@#1}
\def\c@lor@@RGB#1,#2,#3\@@#4{%
 \c@lor@RGB@rgb{#1}\@tempa
 \c@lor@RGB@rgb{#2}\@tempb
 \c@lor@RGB@rgb{#3}\@tempc
 \c@lor@@rgb\@tempa,\@tempb,\@tempc\@@#4%
  }
\def\c@lor@RGB@rgb#1#2{%
  \dimen@#1\p@
  \divide\dimen@\@cclv
  \edef#2{\strip@pt\dimen@}}
\def\color@hsb#1#2{\c@lor@@hsb#2\@@#1}
\def\c@lor@@hsb#1,#2,#3\@@#4{%
  \c@lor@arg{#1}%
  \c@lor@arg{#2}%
  \c@lor@arg{#3}%
  \edef#4{hsb #1 #2 #3}%
  }
\def\color@named#1#2{\c@lor@@named#2,,\@@#1}
\def\c@lor@@named#1,#2,#3\@@#4{%
  \@ifundefined{col@#1}%
    {\PackageError{color}{Undefined color `#1'}\@ehd}%
  {\edef#4{ #1}}%
  }
\def\c@lor@to@ps#1 #2\@@{\csname c@lor@ps@#1\endcsname#2 \@@}
\def\c@lor@ps@#1 #2\@@{TeXDict begin #1 end}
\def\c@lor@ps@rgb#1\@@{#1 setrgbcolor}
\def\c@lor@ps@hsb#1\@@{#1 sethsbcolor}
\def\c@lor@ps@cmyk#1\@@{#1 setcmykcolor}
\def\c@lor@ps@gray#1\@@{#1 setgray}
\def\current@color{ Black}
\def\set@color{%
 \special{color push  \current@color
                          }\aftergroup\reset@color}
\def\reset@color{\special{%
        color pop}}
\def\set@page@color{\special{%
        background \current@color}}
\def\define@color@named#1#2{%
  \expandafter\let\csname col@#1\endcsname\@nnil}
% white is special cased as "no background color" by dvipdfmx
\def\no@page@color{\special{background gray 1}}
\@ifundefined{Gin@decode}
  {\let\Gin@decode\@empty}
  {}
\@ifundefined{Gin@page}
  {\let\Gin@page\@empty}
  {}
\@ifundefined{Gin@pagebox}
  {\def\Gin@pagebox{cropbox}}
  {}
\@ifundefined{Gin@interpolate}
  {\csname newif\endcsname\ifGin@interpolate}
  {}
\def\Gread@pdf#1{%
  \Gread@generic{#1}\Gread@extractbb@aux
}
\def\Gread@extractbb@aux#1{%
  \ifeof\@inputcheck
    \immediate\openin\@inputcheck=%
      "|extractbb %
      \ifx\Gin@page\@empty\else -p \Gin@page\GPT@space\fi
      \ifx\Gin@pagebox\@empty\else -B \Gin@pagebox\GPT@space\fi
      -O \Gin@base\Gin@ext"%
  \fi
  \Gread@true
  \let\@tempb\Gread@false
  \ifeof\@inputcheck
    \@latex@error
      {Cannot run pipe command. Try --shell-escape^^J%
       (--enable-pipes in MikTeX) option}%
      {}%
  \else
    \loop
      \read\@inputcheck to\@tempa
      \ifeof\@inputcheck
        \Gread@false
      \else
        \expandafter\Gread@find@bb\@tempa:.\\%
      \fi
      \ifGread@
      \repeat
    \immediate\closein\@inputcheck
  \fi
}
\let\Gread@bmp\Gread@pdf
\def\Ginclude@pdf#1{%
  \let\Gin@decode\@empty
  \Gin@interpolatefalse
  \Ginclude@dvipdfmx{#1}{epdf}%
}
\def\Ginclude@bmp#1{%
  \let\Gin@page\@empty
  \let\Gin@pagebox\@empty
  \Ginclude@dvipdfmx{#1}{image}%
}
\def\Ginclude@dvipdfmx#1#2{%
  \Gin@log{<#1>}%
  \bgroup
  \def\@tempa{!}%
    \special{pdf:#2\GPT@space
      \ifx\Gin@page\@empty\else page\GPT@space\Gin@page\GPT@space\fi
      \ifx\Gin@pagebox\@empty\else pagebox\GPT@space\Gin@pagebox\GPT@space\fi
      bbox\GPT@space\Gin@llx\GPT@space\Gin@lly\GPT@space\Gin@urx\GPT@space\Gin@ury\GPT@space
      clip\GPT@space\ifGin@clip 1\else 0\fi\GPT@space
      \ifx\Gin@scalex\@tempa\else width\GPT@space\the\Gin@req@width\GPT@space\fi
      \ifx\Gin@scaley\@tempa\else height\GPT@space\the\Gin@req@height\GPT@space\fi
      (#1)\GPT@space
      \ifnum0%
        \ifx\Gin@decode\@empty\else 1\fi
        \ifGin@interpolate 1\fi
        >0 %
        <<%
          \ifx\Gin@decode\@empty\else /Decode[\Gin@decode]\fi
          \ifGin@interpolate /Interpolate true\fi
        >>%
      \fi
    }%
  \egroup}
\newif\if@trim@vport
\def\Ginclude@eps#1{%
  \Gin@log{<#1>}%
  \bgroup
  \ifx\Undefined\Gin@vllx\else\@trim@vporttrue\fi
  \def\@tempa{!}%
  \dimen@\Gin@urx\p@
  \advance\dimen@ -\Gin@llx\p@
  \if@trim@vport
  \advance\dimen@ \Gin@vllx\p@
  \fi
  \edef\Gin@urx{\strip@pt\dimen@}%
  \dimen@\Gin@ury\p@
  \advance\dimen@ -\Gin@lly\p@
  \if@trim@vport
  \advance\dimen@ \Gin@vlly\p@
  \fi
  \edef\Gin@ury{\strip@pt\dimen@}%
  \dimen@\Gin@req@width
  \dimen@ii.1bp%
  \divide\dimen@\dimen@ii
  \@tempdima\Gin@req@height
  \divide\@tempdima\dimen@ii
    \special{PSfile="#1"\GPT@space
      \if@trim@vport
      llx=\Gin@vllx\GPT@space
      lly=\Gin@vlly\GPT@space
      \fi
      urx=\Gin@urx\GPT@space
      ury=\Gin@ury\GPT@space
      \ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi
      \ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi
      \ifGin@clip clip\fi}%
  \egroup}
%
% In the above \Ginclude@eps, llx, lly, urx, and ury are translated to match
% the -dEPSCrop option for Ghostscript to convert eps to pdf.
% In the case of eps files created by MetaPost, the files are included
% directly without the help of Ghostscript. That is, we have to translate
% the origin accordingly if we use \Ginclude@eps for eps files created by
% MetaPost. In TeX Live 2015, the translation of the origin was the default.
% After TeX Live 2016, however, the translation of the origin is enabled only
% if the --mvorigin option is given for dvipdfmx or xdvipdfmx.
% This may be a bit inconvenient, especially in the case of XeTeX where
% xdvipdfmx is usually called as a pipe. Therefore we introduce a new suffix
% .mps(or .MPS) to support inclusion of eps files created by MetaPost without
% the option --mvorigin.
%
\def\Ginclude@mps#1{%
  \Gin@log{<#1>}%
  \bgroup
  \def\@tempa{!}%
  \dimen@\Gin@req@width
  \dimen@ii.1bp%
  \divide\dimen@\dimen@ii
  \@tempdima\Gin@req@height
  \divide\@tempdima\dimen@ii
    \special{PSfile="#1"\GPT@space
      llx=\Gin@llx\GPT@space
      lly=\Gin@lly\GPT@space
      urx=\Gin@urx\GPT@space
      ury=\Gin@ury\GPT@space
      \ifx\Gin@scalex\@tempa\else rwi=\number\dimen@\GPT@space\fi
      \ifx\Gin@scaley\@tempa\else rhi=\number\@tempdima\GPT@space\fi
      \ifGin@clip clip\fi}%
  \egroup}
%
\def\Grot@start{%
\special{pdf:btrans rotate \Grot@angle}}
\def\Grot@end{\special{pdf:etrans}}

% 4.13 add support for ptex vertical writing mode
% inspired by pxtatescale package (Hironobu Yamashita)
\ifx\kanjiskip\@undefined
\def\Gscale@start{%
  \special{pdf:btrans}%
  \special{x:scale \Gscale@x\GPT@space\Gscale@y}%
}
\else
\edef\Gscale@start{%
  \special{pdf:btrans}%
  \special{x:scale
  \expandafter\noexpand\csname iftdir\endcsname
    \noexpand\Gscale@y\noexpand\GPT@space\noexpand\Gscale@x
  \expandafter\noexpand\csname else\endcsname
    \noexpand\Gscale@x\noexpand\GPT@space\noexpand\Gscale@y
  \expandafter\noexpand\csname fi\endcsname}}
\fi
%
\def\Gscale@end{\special{pdf:etrans}}
\def\Gin@PS@raw#1{\special{ps: #1}}
\def\Gin@PS@restored#1{\special{" #1}}
\def\Gin@PS@literal@header#1{\AtBeginDvi{\special{! #1}}}
\def\Gin@PS@file@header#1{\AtBeginDvi{\special{header=#1}}}
\def\Gin@extensions{% order here is like xetex.def, except for PS
  .pdf,.PDF,.ai,.AI,%
  .png,.PNG,.jpg,.JPG,.jpeg,.JPEG,.jp2,.JP2,.jpf,.JPF,.bmp,.BMP,%
  .ps,.PS,.eps,.EPS,.mps,.MPS}
%
\@namedef{Gin@rule@.pdf}#1{{pdf}{.xbb}{#1}}
\@namedef{Gin@rule@.PDF}#1{{pdf}{.xbb}{#1}}
%
\@namedef{Gin@rule@.ai}#1{{pdf}{.xbb}{#1}}
\@namedef{Gin@rule@.AI}#1{{pdf}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jp2}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JP2}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jpf}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JPF}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.png}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.PNG}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jpg}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JPG}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jpeg}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JPEG}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jp2}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JP2}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.jpf}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.JPF}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.bmp}#1{{bmp}{.xbb}{#1}}
\@namedef{Gin@rule@.BMP}#1{{bmp}{.xbb}{#1}}
%
\@namedef{Gin@rule@.ps}#1{{eps}{.ps}{#1}}
\@namedef{Gin@rule@.PS}#1{{eps}{.ps}{#1}}
%
\@namedef{Gin@rule@.eps}#1{{eps}{.eps}{#1}}
\@namedef{Gin@rule@.EPS}#1{{eps}{.eps}{#1}}
%
\@namedef{Gin@rule@.mps}#1{{mps}{.mps}{#1}}
\@namedef{Gin@rule@.MPS}#1{{mps}{.mps}{#1}}
%
\@namedef{Gin@rule@*}#1{{eps}{\Gin@ext}{#1}}
\@ifundefined{ifGin@setpagesize}
{\expandafter\let\csname ifGin@setpagesize\expandafter\endcsname
\csname iftrue\endcsname}
{}
\ifGin@setpagesize
\ifx\paperwidth\@undefined\else
\AtBeginDocument{%
% If a package has changed \mag, assume it knows what it is doing
% and leave page size alone
\ifnum\mag=\@m
\AtBeginDvi{%
\begingroup
  \@ifundefined{stockwidth}{}
    {%
      \paperwidth\stockwidth
      \paperheight\stockheight
    }%
\ifdim\paperwidth>\z@
\ifdim\paperheight>\z@
\special{pdf:pagesize width \the\paperwidth\GPT@space height \the\paperheight}%
\fi
\fi
\endgroup}%
\fi
}
\fi
\fi
\endinput
% Conversion functions so the internal representation stays unchanged
\let\init@current@color\current@color
\def\convert@color#1{%
  \ifx#1\init@current@color
    \expandafter\convert@color@init
  \else
    \expandafter\convert@@color
  \fi
    #1%
}
\def\convert@color@init#1{0 g 0 G}
\def\convert@@color#1{%
  \expandafter\expandafter\expandafter\convert@@@color#1\stop
}
\def\convert@@@color#1 #2\stop{%
  \csname convert@color@#1\endcsname{#2}%
}
\def\convert@color@cmyk#1{#1 k #1 K}
\def\convert@color@gray#1{#1 g #1 G}
\def\convert@color@rgb#1{#1 rg #1 RG}
\def\convert@color@#1{%
  \expandafter\expandafter\expandafter\convert@@color
    \expandafter\expandafter\expandafter{\csname col@#1\endcsname}%
}
% Deal with named colors
\def\define@color@named#1#2{\expandafter\edef\csname col@#1\endcsname{#2}}
% Change the specials to use the stack
\ifdefined\main@pdfcolorstack\else
  \chardef\main@pdfcolorstack=1 %
  \ifx\AtBeginDvi\undefined
    \long\def\@firstofone#1{#1}%
    \expandafter\@firstofone
  \else
    \expandafter\AtBeginDvi
  \fi
    {\special{pdfcolorstackinit \the\main@pdfcolorstack\space page direct (0 g 0 G)}}
\fi
\def\@pdfcolorstack{\the\main@pdfcolorstack\space}
\def\set@color{%
  \special{pdfcolorstack \@pdfcolorstack push (\convert@color\current@color)}%
  \aftergroup \reset@color
}
\def\reset@color{%
  \special{pdfcolorstack \@pdfcolorstack pop}%
}
% Reinsert stack color to over-ride built-in reinsertion of pdf:bc color
\def\Grot@end{\special{pdf:etrans}\special{pdfcolorstack \@pdfcolorstack current}}
\let\Gscale@end\Grot@end
\def\GPT@clipbox#1{%
  \setbox#1=\hbox{%
    \Gin@defaultbp\WIDTH{\wd#1}%
    \Gin@defaultbp\DEPTH{\dp#1}%
    \@tempdima\ht#1%
    \advance\@tempdima\dp#1%
    \Gin@defaultbp\TOTALHEIGHT{\@tempdima}%
    \special{x:gsave}%
    \special{%
      pdf:literal
      0 -\DEPTH\GPT@space \WIDTH\GPT@space \TOTALHEIGHT\GPT@space re  W n
    }%
    \rlap{\box#1}%
    \special{x:grestore}%
    \special{pdfcolorstack \@pdfcolorstack current}%
    \hskip\wd#1%
  }%
}