summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pdftex-def/pdftex.def
blob: 9562d5d9dee1ec7e2968e024ca8fa33ea4c0d7d1 (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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
\ProvidesFile{pdftex.def}[2006/06/06 v0.03r Graphics/color for pdfTeX]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% LaTeX Colour and Graphics support for PDFTeX
%%
%% David Carlisle, Sebastian Rahtz, Hans Hagen and Heiko Oberdiek
%%
%% It may be used by specifying the pdftex option to any of the
%% supported packages, for example:
%%
%% \usepackage[pdftex]{graphicx}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% History
% ...
% 2000/04/20 v0.02s:
%  * gray color model directly supported (HO).
% 2000/05/02 v0.02t:
%  * \pagecolor supported (HO).
% 2000/05/12 v0.02u:
%  * support for multipage pdf files, option `page' added (HO).
% 2000/05/31 v0.02v:
%  * Option `page' is defined at begin document,
%    if package `keyval' is loaded after `pdftex.def'.
% 2000/06/16 v0.03a:
%  * Added Heiko to author list (DPC).
% 2000/08/31 v0.03b:
%  * support for alternate print images: option `print' added (HO).
%    * This feature is not supported by Ghostscript, xpdf, or AR3.
%    * The images should have the same dimensions/resolution.
%  * Two experimental options added (HO):
%    * `quiet': log messages are suppressed.
%    * `resolution': sets \pdfimageresolution.
%    Because these options are not supported by graphicx,
%    they have to be set after \usepackage{graphicx}, eg.
%      \setkeys{Gin}{quiet,resolution=300}
%    Option `quiet' (for pdftex) can be make known to graphic{s,x}
%    with this line in graphics.cfg:
%      \DeclareOption{quiet}{\let\Gin@log\@gobble}
%    Caution: both options are experimental and can be
%    change in next versions!
%  * \pdfpage{width,height} are only set, if \paperwidth
%    is defined (HO).
% 2000/09/04 v0.03c
%  * Redefinition of `natwidth' and `natheight' \AtBeginDocument (HO).
% 2000/09/14 v0.03d
%  * Fixes for `viewport' and `trim' (HO).
%  * Clip support added for viewport and trim (HO).
% 2000/09/14 v0.03e
%  * Options `bbllx', `bblly', `bburx', `bbury' disabled,
%    option `bb' redirected with a warning to `viewport' (HO).
% 2000/11/10 v0.03f
%  * Bug, that produces an error message, if package `graphics'
%    is used (introduced in 0.03d), fixed: If \Gin@vllx is not
%    defined (graphics), then clipping and the moves of options
%    viewport/trim are silently disabled (HO).
% 2001/05/25 v0.03g
%  * \pdfpagewidth and \pdfpageheight are not set to zero,
%    if \paperwidth and \paperheight are not set (HO).
% 2001/09/01 v0.03h
%  * Compatibilty for miniltx.tex, problems fixed:
%    \@ifpackageloaded, \PackageWarning, \PackageWarningNoLine,
%    \@currname.
% 2001/11/29 v0.03i
%  * Problem with \if@inlabel (plain format) fixed.
% 2002/06/18 v0.03j
%  * Contribution by P\'etiard Fran\c{c}ois <petiard@math.univ-fcomte.fr>:
%    Improvement of \Ginclude@mps (support of viewport and clip).
% 2002/06/19 v0.03k
%  * Correction by P\'etiard Fran\c{c}ois for \GPT@DoEndClip.
% 2005/06/15 v0.03l
%  * \usebox patch fixed (\aftergroup part removed) (HO).
% 2005/06/20 v0.03m
%  * .tif support is removed for pdfTeX >= 1.10a (HO).
% 2006/02/23 v0.03n
%  * Compatibility for plain-TeX: file can be loaded multiple times;
%    colorfix is not applied for undefined macros (HO).
% 2006/02/24 v0.03o
%  * Catcode protections mainly because of babel's shorthands (HO).
% 2006/03/02 v0.03p
%  * \pagecolor support for plain-TeX fixed (HO).
% 2006/05/17 v0.03q
%  * Error message if ConTeXt's supp-pdf.tex is missing and
%    support of MPS files is not available (Markus Kohm, HO).
% 2006/06/06 v0.03r
%  * \nopagecolor/\no@page@color added.
%
% prefix of internal commands for this file `pdftex.def':
%   \GPT@ (Graphics bundle PdfTex driver)

\expandafter\edef\csname GPT@endinput\endcsname{%
  \catcode33 \the\catcode33 % !
  \catcode34 \the\catcode34 % "
  \catcode39 \the\catcode39 % '
  \catcode42 \the\catcode42 % *
  \catcode44 \the\catcode44 % ,
  \catcode45 \the\catcode45 % -
  \catcode46 \the\catcode46 % .
  \catcode47 \the\catcode47 % /
  \catcode58 \the\catcode58 % :
  \catcode59 \the\catcode59 % ;
  \catcode60 \the\catcode60 % <
  \catcode61 \the\catcode61 % =
  \catcode62 \the\catcode62 % >
  \catcode63 \the\catcode63 % ?
  \catcode64 \the\catcode64 % @
  \catcode94 \the\catcode94 % ^
  \catcode96 \the\catcode96 % `
  \relax
  \noexpand\endinput
}
\catcode64 11 %
\@makeother\!
\@makeother\"
\@makeother\'
\@makeother\*
\@makeother\,
\@makeother\-
\@makeother\.
\@makeother\/
\@makeother\:
\@makeother\;
\@makeother\<
\@makeother\=
\@makeother\>
\@makeother\?
\@makeother\`
\catcode`\^=7 %

\ifx\pdftexversion\@undefined
  \def\driver@release{1}%
\else
  \ifnum\pdftexversion<12
    \def\driver@release{2}%
  \else
    \ifnum\pdftexversion<13
      \ifnum \expandafter `\pdftexrevision < `n
        \def\driver@release{3}%
      \else
        \def\driver@release{4}%
      \fi
    \else
      \ifnum\pdftexversion=13
        \def\driver@release{5}%
      \else
        \ifnum\pdftexversion=14
          \def\driver@release{6}%
        \else
          \ifnum\pdftexversion<110
            \def\driver@release{7}%
          \else
            % .tif support was dropped in pdfTeX 1.10a
            \def\driver@release{8}%
          \fi
        \fi
      \fi
    \fi
  \fi
\fi

% miniltx.tex does not define \PackageWarning, \PackageWarningNoLine, ...
\@ifundefined{PackageWarning}{%
  \def\PackageWarning#1#2{%
    \begingroup
      \newlinechar=10 %
      \def\MessageBreak{%
        ^^J(#1)\@spaces\@spaces\@spaces\@spaces
      }%
      \immediate\write16{^^JPackage #1 Warning: #2\on@line.^^J}%
    \endgroup
  }%
}{}
\@ifundefined{PackageWarningNoLine}{%
  \def\PackageWarningNoLine#1#2{%
    \PackageWarning{#1}{#2\@gobble}%
  }%
}{}
\@ifundefined{on@line}{%
  \def\on@line{ on input line \the\inputlineno}%
}{}
\@ifundefined{@spaces}{%
  \def\@spaces{\space\space\space\space}%
}{}
\@ifundefined{MessageBreak}{%
  \def\MessageBreak{^^J}%
  \def\GPT@error#1#2{%
    \begingroup
      \newlinechar=10\relax
      \edef\x{%
        \PackageError{graphics}{#1}{#2}%
      }%
      \x
    \endgroup
  }
}{%
  \def\GPT@error{\PackageError{graphics}}%
}
\def\GPT@warn{\PackageWarning{pdftex.def}}%
\ifx\Gin@log\@undefined
  \def\Gin@log{\message}
\fi

% Colour Support. The following models may be used.
%   * cmyk   supported directly.
%   * rgb    supported directly.
%   * RGB    converted to rgb by this file.
%   * gray   supported directly.
%   * named  converted to cmyk by this file.
%
\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@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{#1 #2 #3 #4 k #1 #2 #3 #4 K}%
}
\def\color@gray#1#2{%
  \c@lor@arg{#2}%
  \edef#1{#2 g #2 G}%
}
\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{#1 #2 #3 rg #1 #2 #3 RG}%
}
\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@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{\csname col@#1\endcsname}%
  }%
}

\def\set@color{%
  \pdfliteral{\current@color}%
  \aftergroup\reset@color
}
\def\reset@color{\pdfliteral{\current@color}}
\def\define@color@named#1#2{%
  \expandafter\edef\csname col@#1\endcsname{#2}%
}
\def\current@color{0 g 0 G}

% v0.02t: support for \pagecolor
% fixed in v0.02p by using a box register, see
% http://tug.org/pipermail/pdftex/2005-August/005916.html
%
% v0.03r: \nopagecolor/\no@page@color added.
\newif\ifGPT@pagecolor
\@ifundefined{nopagecolor}{%
  \def\nopagecolor{\no@page@color}%
}{}
\def\no@page@color{%
  \global\GPT@pagecolorfalse
}
\def\set@page@color{%
  \global\GPT@pagecolortrue
  \global\let\current@page@color\current@color
  \@ifundefined{GPT@outputbox}{%
    % \newbox is outer in plain
    \csname newbox\endcsname\GPT@outputbox
  }{}%
  \@ifundefined{GPTorg@shipout}{%
    \global\let\GPTorg@shipout\shipout
    \gdef\shipout{%
      \afterassignment\GPT@shipout
      \global\setbox\GPT@outputbox=%
    }%
    \gdef\GPT@shipout{%
      \ifvoid\GPT@outputbox\relax
         \aftergroup\GPT@@shipout
         \GPT@pageliteral
      \else
        \GPTorg@shipout\vbox{%
          \GPT@pageliteral
          \box\GPT@outputbox
        }%
      \fi
    }%
    \gdef\GPT@@shipout{%
      \GPTorg@shipout\box\GPT@outputbox\relax
    }%
    \gdef\GPT@pageliteral{%
      \ifGPT@pagecolor
        \pdfliteral direct{%
          q % gsave
          \current@page@color\space
          n % newpath
          0 0 \strip@pt\pdfpagewidth\space
          \strip@pt\pdfpageheight\space re % rectangle
          % there is no need to convert to bp
          f % fill
          Q% grestore
        }%
      \fi
    }%
  }{}%
}

% Need the `colorfix' modifications as no internal colour stack
% is maintained
%<*colorfix>
\AtBeginDocument{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname color\endcsname\relax
    % Without color we don't need any fixes.
  \else
    \@ifundefined{@ldc@l@r}{%
      \let\@ldc@l@r\color
      \def\color{%
        \@ifundefined{if@inlabel}{}{%
          \csname if@inlabel\expandafter\endcsname
          \expandafter\leavevmode\csname fi\endcsname
        }%
        \@ldc@l@r
      }%
    }{}%
    \@ifundefined{@lduseb@x}{%
      \begingroup\expandafter\expandafter\expandafter\endgroup
      \expandafter\ifx\csname usebox\endcsname\relax
      \else
        \let\@lduseb@x\usebox
        \def\usebox#1{\@lduseb@x{#1}\reset@color}%
      \fi
    }{}%
  \fi
}
%</colorfix>

%
% Graphic inclusion. Currently supports .png, .jpg, .mps and .pdf inclusion;
% .tif support is dropped since pdfTeX 1.10a.
% .mps is MetaPost output.
% .mps inclusion depends on loading a CONTEXT module by Hans Hagen;
% .pdf also needs a Context module unless pdftex 0.12n or later.
%
% PNG bitmaps may be scaled/rotated as usual
% by the graphics commands or keyword arguments.
%
% Note the magic in front of the file name after \pdfimage, to
% prevent it fouling up with file names starting with "depth".
\def\Gread@png#1{%
  \setbox\@tempboxa\hbox{\pdfimage\noexpand\noexpand\noexpand\@empty#1\relax}%
  \def\Gin@llx{0}\let\Gin@lly\Gin@llx
  \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
  \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
}

%
% support for
% * multipage pdf images (pdfTeX v0.14+)
% * alternate print image (bitmaps only)
%   * driver version>=5 (0.14)
%   * printed image can be resused, but not the base image,
%     because it's dictionary contains the additional key /Alternates.
%   * not supported by Ghostscript or xpdf.
% * option quiet
%
% \GPT@page: page number of pdf image or \@empty otherwise.
\let\GPT@page\@empty
% \GPT@print: file name for alternate image or \@empty otherwise.
\let\GPT@print\@empty
\begingroup
  \toks@{%
    \ifnum\driver@release>5
      \define@key{Gin}{page}{%
        \def\GPT@page{#1}%
      }%
      \define@key{Gin}{print}{%
        \def\GPT@print{#1}%
      }%
    \else
      \define@key{Gin}{page}{%
        \GPT@warn{%
          pdfTeX >= 0.14 required for option\MessageBreak `page'%
        }%
      }%
      \define@key{Gin}{print}{%
        \GPT@warn{%
          pdfTeX >= 0.14 required for option\MessageBreak `print'%
        }%
      }%
    \fi
    \define@key{Gin}{quiet}[]{%
      \let\Gin@log\@gobble
    }%
    \define@key{Gin}{resolution}{%
      \pdfimageresolution#1\relax
    }%
  }%
  \@ifundefined{define@key}{%
    \edef\x{\endgroup
      \noexpand\AtBeginDocument{%
        \noexpand\@ifundefined{define@key}{}{\the\toks@}%
      }%
    }\x
  }{%
    \expandafter\endgroup\the\toks@
  }

% redefinitions of some graphicx options:
\def\GPT@disable#1{%
  \GPT@warn{%
    Option `#1' is not supported, use\MessageBreak
    option `viewport' instead%
  }%
}
\def\GPT@fix{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname define@key\endcsname\relax
  \else
    \def\KV@Gin@bb{%
      \GPT@warn{%
        Option `bb' does not make sense,\MessageBreak
        using `viewport' instead%
      }%
      \KV@Gin@viewport
    }%
    \define@key{Gin}{bbllx}{\GPT@disable{bbllx}}%
    \define@key{Gin}{bblly}{\GPT@disable{bblly}}%
    \define@key{Gin}{bburx}{\GPT@disable{bburx}}%
    \define@key{Gin}{bbury}{\GPT@disable{bbury}}%
  \fi
}
\AtBeginDocument{\GPT@fix}

%
% mechanism for re-use of objects also
% allows us to get the size by deriving it from the initial storage;
% this works for all graphics types.
%
\@ifundefined{Gread@gobject}{%
  \csname newcount\endcsname\Gread@gobject
}{}
\def\GPT@ReusedName#1{%
  \ifx\GPT@print\@empty
    #1%
  \else
    \GPT@print
  \fi
}
\def\Gread@pdftex#1{%
  % Ensure that option `print' works only on bitmap images.
  \ifGPT@IsBitmap
  \else
    \ifx\GPT@print\@empty
    \else
      \GPT@warn{%
        Option `print' can only be used\MessageBreak
        for bitmap images%
      }%
      \let\GPT@print\@empty
    \fi
  \fi
  % If option `print' is set, the screen image object
  % will contain an additional /Alternate entry
  % and will therefore not be reused.
  \ifx\GPT@print\@empty
  \else
    \expandafter\expandafter\expandafter\@firstoftwo\expandafter\@gobbletwo
  \fi
  \@ifundefined{#1 image\GPT@page}{%
    \ifnum\driver@release>4
      \ifnum\driver@release>5
        \ifx\GPT@print\@empty
          \let\GPT@RuleAttr\@empty
        \else
          \@ifundefined{\GPT@print\space image\GPT@page}{%
            \immediate\pdfximage{\GPT@print}%
            \setbox\@tempboxa=\hbox{\pdfrefximage\pdflastximage}%
            \edef\GPT@PrintObj{\the\pdflastximage}%
            \expandafter\xdef\csname\GPT@print\space
              image\GPT@page\endcsname{\pdfrefximage\GPT@PrintObj}%
            \immediate\pdfobj{%
              [<<%
                /Image \GPT@PrintObj\space 0 R%
                /DefaultForPrinting true%
              >>]%
            }%
            \def\GPT@RuleAttr{%
              width\wd\@tempboxa height\ht\@tempboxa
              attr{/Alternates \the\pdflastobj\space 0 R}%
            }%
          }{%
            \edef\GPT@PrintObj{%
              \expandafter\expandafter\expandafter\@gobble
              \csname\GPT@print\space image\GPT@page\endcsname
            }%
            \immediate\pdfobj{%
              [<<%
                /Image \GPT@PrintObj \space 0 R%
                /DefaultForPrinting true%
              >>]%
            }%
            \def\GPT@RuleAttr{%
              width \csname\GPT@print\space width\GPT@page\endcsname
              height \csname\GPT@print\space height\GPT@page\endcsname
              attr{/Alternates \the\pdflastobj\space 0 R}%
            }%
          }%
        \fi
        \pdfximage \GPT@RuleAttr
        \ifx\GPT@page\@empty
        \else
          page \GPT@page
        \fi
        {#1}%
        \setbox\@tempboxa=\hbox{\pdfrefximage\pdflastximage}%
      \else
        \setbox\@tempboxa=\hbox{\pdfimage{#1}}%
      \fi
    \else
      \setbox\@tempboxa=\hbox{%
        \pdfimage\noexpand\noexpand\noexpand\@empty#1\relax
      }%
    \fi
    \def\Gin@llx{0}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
    \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
    \expandafter\xdef\csname\GPT@ReusedName{#1} width\GPT@page\endcsname{%
      \the\wd\@tempboxa
    }%
    \expandafter\xdef\csname\GPT@ReusedName{#1} height\GPT@page\endcsname{%
      \the\ht\@tempboxa
    }%
    \ifnum\driver@release>5
      \expandafter\xdef\csname #1 image\GPT@page
        \ifx\GPT@print\@empty\else!\fi\endcsname{%
        \pdfrefximage\the\pdflastximage
      }%
    \else
      \pdfform\@tempboxa
      \Gread@gobject=\pdflastform
      \expandafter\xdef\csname#1 image\endcsname{%
        \pdfrefform\the\Gread@gobject
      }%
    \fi
    \Gin@log{%
       <#1, id=%
       \ifnum\driver@release>5
         \the\pdflastximage
         \ifx\GPT@page\@empty\else , page=\GPT@page\fi
         \ifx\GPT@print\@empty
         \else
            , print=\GPT@print, id=\GPT@PrintObj
         \fi
       \else
         \the\Gread@gobject
       \fi
       , \the\wd\@tempboxa\space x \the\ht\@tempboxa
       >%
     }%
  }{%
    \def\Gin@llx{0}\let\Gin@lly\Gin@llx
    \Gin@defaultbp\Gin@urx{\csname#1 width\GPT@page\endcsname}%
    \Gin@defaultbp\Gin@ury{\csname#1 height\GPT@page\endcsname}%
  }%
}
\def\Ginclude@pdftex#1{%
  \def\@tempa{!}%
  \ifx\Gin@scaley\@tempa
    \let\Gin@scaley\Gin@scalex
  \else
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
  \fi
  \Gin@log{%
    <use #1%
    \ifx\GPT@page\@empty\else, page \GPT@page\fi
    >%
  }%
  \hbox{%
    \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
      \@ifundefined{Gin@vllx}{%
        \GPT@viewportfalse
        % without viewport/trim clipping does not make sense
        % for pdfTeX
        \Gin@clipfalse
      }{}%
      \ifGin@clip
        \ifnum\driver@release<6
          \GPT@warn{No clipping support in pdfTeX < 0.14}%
        \else
          \if!\Gin@vllx\Gin@vlly\Gin@vurx\Gin@vury!%
          \else
            \let\GPT@clipend\GPT@DoClipEnd
            \setbox\@tempboxa\hbox\bgroup
          \fi
        \fi
      \fi
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \lower\Gin@vlly bp\hbox\bgroup
        \fi
        \ifdim\Gin@vllx\p@=\z@
        \else
          \hskip-\Gin@vllx bp\relax
        \fi
      \fi
      \csname#1 image\GPT@page
        \ifx\GPT@print\@empty\else!\fi
      \endcsname
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \egroup
        \fi
        \GPT@clipend
      \fi
    }%
  }%
}
\newif\ifGPT@viewport
\GPT@viewporttrue
\let\GPT@clipend\relax
\def\GPT@DoClipEnd{%
  \egroup
  \dp\@tempboxa\z@
  % \Gin@urx and \Gin@ury already contain the correct values,
  % so both cases viewport and trim can be handled together:
  \dimen@\Gin@urx\p@
  % v0.03k \Gin@vllx replaced by \Gin@llx
  \advance\dimen@ -\Gin@llx\p@
  \wd\@tempboxa\strip@pt\dimen@ bp\relax
  \dimen@\Gin@ury\p@
  % v0.03k \Gin@vlly replaced by \Gin@lly
  \advance\dimen@ -\Gin@lly\p@
  \ht\@tempboxa\strip@pt\dimen@ bp\relax
  \pdfxform\@tempboxa
  \pdfrefxform\pdflastxform
}
\newif\ifGPT@IsBitmap
\def\Gread@pdfbitmap#1{%
  \GPT@IsBitmaptrue
  \Gread@pdftex{#1}%
  \GPT@IsBitmapfalse
}

\edef\Gread@MBox{/MediaBox}
\def\Gread@pdf#1{%
  \begingroup
    \@tempcnta\z@
    \loop
    \ifnum\@tempcnta<\@xxxii
      \catcode\@tempcnta14 %
      \advance\@tempcnta\@ne
    \repeat
    \catcode127=14 %
    \let\do\@makeother\dospecials\catcode`\ 10 %
    \catcode\endlinechar5 %
    \immediate\openin\@inputcheck#1 %
    \ifeof\@inputcheck
      \@latex@error{File `#1' not found}\@ehc
    \else
      \Gread@true
      \let\@tempb\Gread@false
      \loop
% v0.02e: use \. not \@tempa so the space is preserved before [
        \read\@inputcheck to\.%
        \ifeof\@inputcheck
          \Gread@false
        \else
          \expandafter\Gread@find@mbox\. []\\%
        \fi
      \ifGread@
      \repeat
      \immediate\closein\@inputcheck
    \fi
    \ifGin@bbox
    \else
      \@latex@error
      {Cannot determine size of graphic in #1 (no BoundingBox)}%
      \@ehc
      \gdef\@gtempa{0 0 72 72 }%
    \fi
  \endgroup
  \expandafter\Gread@parse@bb\@gtempa\\%
}
\long\def\Gread@find@mbox#1 [#2]#3\\{%
  \def\@tempa{#1}%
  \ifx\@tempa\Gread@MBox
    \gdef\@gtempa{#2 }%
    \@tempb
    \Gin@bboxtrue
  \fi
}
\def\Ginclude@png#1{%
  \hbox{%
% v0.02f add \@depth\z@ (from Sebastian)
    \pdfimage
      \@height\Gin@req@height \@width\Gin@req@width \@depth\z@
      \noexpand\noexpand\noexpand\@empty#1\relax
  }%
}

\def\Ginclude@mps#1{%
  \def\@tempa{!}%
  \ifx\Gin@scaley\@tempa
    \let\Gin@scaley\Gin@scalex
  \else
    \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
  \fi
  \hbox{%
    \Gscale@box{\Gin@scalex}[\Gin@scaley]{%
      \@ifundefined{Gin@vllx}{%
        \GPT@viewportfalse
        % without viewport/trim clipping does not make sense
        % for pdfTeX
        \Gin@clipfalse
      }{}%
      \ifGin@clip
        \ifnum\driver@release<6
          \GPT@warn{No clipping support in pdfTeX < 0.14}%
        \else
          \if!\Gin@vllx\Gin@vlly\Gin@vurx\Gin@vury!%
          \else
            \let\GPT@clipend\GPT@DoClipEnd
            \setbox\@tempboxa\hbox\bgroup
          \fi
        \fi
      \fi
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \lower\Gin@vlly bp\hbox\bgroup
        \fi
        \ifdim\Gin@vllx\p@=\z@
        \else
          \hskip-\Gin@vllx bp\relax
        \fi
      \fi
      \convertMPtoPDF{#1}{1}{1}%
      \ifGPT@viewport
        \ifdim\Gin@vlly\p@=\z@
        \else
          \egroup
        \fi
        \GPT@clipend
      \fi
    }%
  }%
}
\def\Gread@mps{\Gread@eps}
\ifnum\driver@release>5
  \let\Gread@tif\Gread@pdfbitmap
  \let\Ginclude@tif\Ginclude@pdftex
\fi
\ifnum\driver@release>3
  \let\Ginclude@png\Ginclude@pdftex
  \let\Ginclude@jpg\Ginclude@pdftex
  \let\Ginclude@pdf\Ginclude@pdftex
  \let\Gread@pdf\Gread@pdftex
  \let\Gread@png\Gread@pdfbitmap
  \let\Gread@jpg\Gread@pdfbitmap
\else
  \def\Ginclude@pdf#1{%
    \def\@tempa{!}%
    \ifx\Gin@scaley\@tempa
      \let\Gin@scaley\Gin@scalex
    \else
      \ifx\Gin@scalex\@tempa\let\Gin@scalex\Gin@scaley\fi
    \fi
    \hbox{%
      \convertPDFtoPDF{#1}{\Gin@scalex}{\Gin@scaley} {0bp} {0bp}%
      {\Gin@req@width}{\Gin@req@height}%
    }%
  }
\fi

% v0.02e: restrict the rules to just the types that pdftex can currently
% deal with.
\ifnum\driver@release>3
  \def\Gin@extensions{.png,.pdf,.jpg,.mps}
  \@namedef{Gin@rule@.jpg}#1{{jpg}{.jpg}{#1}}
  \ifnum\driver@release>5
    \ifnum\driver@release<8
      \def\Gin@extensions{.png,.pdf,.jpg,.mps,.tif}
      \@namedef{Gin@rule@.tif}#1{{tif}{.tif}{#1}}
    \fi
  \fi
\else
  \def\Gin@extensions{.png,.pdf,.mps}
\fi
\@namedef{Gin@rule@.png}#1{{png}{.png}{#1}}
\@namedef{Gin@rule@.mps}#1{{mps}{.mps}{#1}}
\@namedef{Gin@rule@.pdf}#1{{pdf}{.pdf}{#1}}


% Rotation
% slightly hacky, but set width of box 0 to 0pt otherwise
% the CTM gets restored in the wrong place.

% Patrick Daly found an error here with doubled minus signs when \Grot@sin is
% negative. Fixed.
\def\Grot@start{%
  \pdfliteral{ q
     \Grot@cos\space\Grot@sin\space\if-\Grot@sin\else-\Grot@sin\fi\space\Grot@cos\space
     0 0 cm%
  }%
  \wd\z@\z@
}

\def\Grot@end{\pdfliteral{ Q}}

% Scaling is OK, as graphics package does it right here.
\def\Gscale@start{%
  \pdfliteral{ q
    \Gscale@x\space0 0 \Gscale@y\space 0 0 cm%
  }%
}

\let\Gscale@end\Grot@end

% undo the trig.sty `optimisation' so that these 0 1 and -1 values
% get written out as digits, not unexpandable TeX primitives.
\AtBeginDocument{%
  \expandafter\def\csname sin(0)\endcsname{0}%
  \expandafter\def\csname cos(0)\endcsname{1}%
  \expandafter\def\csname sin(90)\endcsname{1}%
  \expandafter\def\csname cos(90)\endcsname{0}%
  \expandafter\def\csname sin(-90)\endcsname{-1}%
  \expandafter\def\csname cos(-90)\endcsname{0}%
  \expandafter\def\csname sin(180)\endcsname{0}%
  \expandafter\def\csname cos(180)\endcsname{-1}%
}

% Are we running under PDFTeX?
\ifx\pdfpageheight\@undefined
  \PackageWarningNoLine{%
    \@ifundefined{@currname}{pdftex.def}{\@currname}%
  }{%
    pdftex option does not work with standard TeX%
  }%
\else
  \ifx\paperwidth\@undefined
  \else
    \ifdim\paperheight=0pt\relax
    \else
      \pdfpageheight\paperheight
    \fi
    \ifdim\paperwidth=0pt\relax
    \else
      \pdfpagewidth\paperwidth
    \fi
  \fi
  \pdfoutput=1
\fi


% v0.02e: Restore catcodes of context letters.
% Not needed with current version of supp-pdf
% but protects against older versions.
% v0.03o: Catcode protection of '=' because of turkish.ldf.
\AtBeginDocument{%
  \edef\@tempa{%
    \catcode`\noexpand\=\the\catcode`\= %
    \catcode`\noexpand\!\the\catcode`\! %
    \catcode`\noexpand\@\the\catcode`\@ %
    \catcode`\noexpand\?\the\catcode`\? %
  }%
  \@makeother\=%
  \InputIfFileExists{supp-pdf}{}{}%
  % If supp-pdf.tex is not available, \convertMPtoPDF generates
  % an error message. \providecommand inside the third argument
  % of \InputIfFileExists will not work:
  % * \InputIfFileExists has problems with parameters (#1).
  % * Implementation of \providecommand is insufficient in miniltx.tex
  \@ifundefined{convertMPtoPDF}{%
    \newcommand*{\convertMPtoPDF}[3]{%
      \GPT@error{%
        Cannot convert #1 from MPS to PDF.\MessageBreak
        The support file `supp-pdf.tex' is missing%
      }{%
        The graphics driver for pdfTeX needs `supp-pdf.tex' (and `supp-mis.tex')%
        \MessageBreak
        to convert MP to PDF.\MessageBreak
        These files are part of ConTeXt and can also be found here:%
        \MessageBreak
        \space\space CTAN:macros/pdftex/graphics/supp-pdf.tex\MessageBreak
        \space\space CTAN:macros/pdftex/graphics/supp-mis.tex\MessageBreak
        You'll get more errors if you'll continue now.%
      }%
    }%
  }{}%
  \@tempa
}

% these seem to upset pdftex. ignore them. SPQR 1999/08/02
% allow for plain graphics, not graphicx.
% pdftex.def is loaded before the definition in graphicx,
% so do all the stuff \AtBeginDocument:
\AtBeginDocument{%
  \@ifundefined{define@key}{}{%
    \define@key{Gin}{natwidth}{}%
    \define@key{Gin}{natheight}{}%
  }%
}%
\GPT@endinput