summaryrefslogtreecommitdiff
path: root/tex/context/base/spec-tpd.tex
blob: 47fedb47e243efce1a379ba5c516bf1f67e4a764 (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
%D \module
%D   [       file=spec-tpd,
%D        version=1996.01.25,
%D          title=\CONTEXT\ Special Macros,
%D       subtitle=\PDFTEX,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See licen-en.pdf for 
%C details. 

% funny things: negative height by \pdfannot
%               immediate versus deferred

%D \macros
%D   {jobsuffix}
%D
%D Being one of the first typographical systems able to support
%D advances \PDF\ support, \TEX\ is also one of the first
%D systems to produce high quality \PDF\ code directly. Thanks
%D to Han The Thanh c.s. the \TEX\ community can leap forward
%D once again.
%D
%D One important characteristic of \PDFTEX\ is that is can
%D produce standard \DVI\ code as well as \PDF\ code. This
%D enables us to use one format file to support both output
%D formats.

%D All modules in this group use specials to tell drivers what
%D non||\TEX\ actions to take. Because from the \TEX\ point of
%D view, there is no difference between \DVI\ and \PDF, we
%D therefore only have to bend the \DVI\ driver support into
%D \PDF\ support. Technically spoken, specials no longer serve
%D a purpose, except from ending up as comment in the \PDF\
%D file.
%D
%D Before we continue we need to make sure if indeed those
%D \PDFTEX\ primitives are permitted. If no primitives are
%D available, we just stop reading any further.

\ifx\pdftexversion\undefined \endinput \else \unprotect \fi

%D For the time being \type {\pdfimage} is redefined in 
%D versions older than 12s. In the new syntax, the filename 
%D is surrounded by braces. 

\ifnum\pdftexversion<13
  \let\normalpdfimage\pdfimage
  \def\grabpdfimage#1#2{\normalpdfimage#1 #2\relax}
  \def\pdfimage#1#{\grabpdfimage{#1}}
\fi

%D We default to 300 dots per inch image resolution. 

\ifx\pdfimageresolution\undefined % < version 14
  \newcount\pdfimageresolution
\fi

\pdfimageresolution=300

%D Once we are sure that we're indeed supporting \PDFTEX, we
%D force \PDF\ output at the highest compression. For debugging
%D purposes one can set the compresslevel to~0. We also have to
%D make sure no other specials are supported, else \PDFTEX\
%D will keep on telling us that we're wrong. We also load the
%D general \PDF\ macros that are shared between this driver and
%D the \ACROBAT\ one. 

\startspecials[tpd][reset,fdf] 

%D This means that by saying
%D
%D \starttypen
%D \usespecials[tpd]
%D \stoptypen
%D
%D we get ourselves full \PDF\ output.

%D For some internal testing we need to know the output 
%D suffix. 

\def\jobsuffix{pdf} 

%D We don't use specials here, which means that we must flush
%D settings before the page is shipped out. 

\specialbasedsettingsfalse

%D Some more internal settings. 

\appendtoks \pdfoutput=0               \to \everyresetspecials

\pdfoutput       =1 % we reset that one with \everyresetspecials
\pdfcompresslevel=9 % apart from debugging, no reason for value 0

% \pdfthreadhoffset=\maxdimen
% \pdfthreadvoffset=\maxdimen

%D Just in case we mimmick specials, we have to make sure no
%D default specials end up in the process.

\let\defaultspecial=\gobbleoneargument

\appendtoks \let\defaultspecial\normalspecial \to \everyresetspecials

\let\PDFcode=\pdfliteral

%D \macros
%D   {dosetuppaper}
%D
%D If we don't set the paper size, \PDFTEX\ will certainly do
%D it in a way we don't want, therefore we need:

\definespecial\dosetuppaper#1#2#3%
  {\global\pdfpagewidth =#2\relax
   \global\pdfpageheight=#3\relax} 

%D \macros
%D   {doinsertfile}
%D
%D Graphics are not part of \TEX\ and therefore not part of the
%D \DVI\ standard. \PDF\ on the other hand has several graphic
%D primitives. During the multi||step process \TEX\
%D $\rightarrow$ \DVI\ $\rightarrow$ \POSTSCRIPT\ $\rightarrow$
%D \PDF\ one can insert graphics using specials. In \PDFTEX\
%D however there is only one step! This means that \PDFTEX\
%D itself has to do the inclusion.
%D
%D At the moment \PDFTEX\ supports inclusion of bitmap \PNG\
%D graphics as well as not too complicated \PDF\ code. Using
%D this last option, we are able to include both \METAPOST\ and
%D \PDF\ output produced by \GHOSTSCRIPT.
%D
%D We fall back on the generic \CONTEXT\ module supp-pdf to
%D accomplish \PDF\ inclusion. The methods implemented there
%D are hooked into both the figure placement mechanisms of
%D \CONTEXT\ and the specials inclusion mechanism.

\definespecial\doinsertfile#1#2#3#4#5#6#7#8#9%
  {\bgroup
   \dodoinsertfile{tpd}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}%
   \egroup}

%D Currently we support \type{pdf} for \PDF\ files, \type{mps}
%D for \METAPOST\ graphics, \type{png} and \type{jpg} for 
%D bitmap graphics.

\definefileinsertion{tpd}{mps}#1#2#3#4#5#6#7#8#9%
  {\hbox
     {\convertMPcolors{#1}%
      \scratchdimen=#3pt \PointsToReal{.01\scratchdimen}\xscale
      \scratchdimen=#4pt \PointsToReal{.01\scratchdimen}\yscale
      \convertMPtoPDF{#1}\xscale\yscale}}

%D The old, \TEX\ base \PDF\ insertion macro:
%D 
%D \starttypen
%D \def\dotpdinsertpdf#1#2#3#4#5#6#7#8#9%
%D   {\beforesplitstring#1\at.\to\filename
%D    \scratchdimen=#3pt \PointsToReal{.01\scratchdimen}\xscale
%D    \scratchdimen=#4pt \PointsToReal{.01\scratchdimen}\yscale
%D    \convertPDFtoPDF{\filename.pdf}\xscale\yscale{#5sp}{#6sp}{#7sp}{#8sp}}
%D \stoptypen
%D 
%D superseded by

\definefileinsertion{tpd}{pdf}{\dopdfimage}
\definefileinsertion{tpd}{png}{\dopdfimage}
\definefileinsertion{tpd}{jpg}{\dopdfimage}
% \definefileinsertion{tpd}{tif}{\dopdfimage} % unstable 

%D The main file insertion macro is as follows. Because 
%D \PDFTEX\ does not support arbitrary suffixes, we double 
%D check on a user supplied filename, because \PDFTEX\ chokes 
%D on unknown suffixes.

\def\doifvalidpdfimagefileelse#1%
  {\edef\filesuffix{#1}%
   \doloop
     {\@EA\aftersplitstring\filesuffix\at.\to\temp
      \ifx\temp\empty
        \exitloop
      \else
        \let\filesuffix\temp
      \fi}%
   \doiffileinsertionsupportedelse{\filesuffix}}

\def\dopdfimage#1#2#3#4#5#6#7#8#9%
  {\doiffileelse{#1}
     {\bgroup
      \doifvalidpdfimagefileelse{#1}
        {\pdfimage 
           \ifcase#7 \else \!!width  #7sp\fi
           \ifcase#8 \else \!!height #8sp\fi
           {#1}}
        {\framed[\c!breedte=#7sp,\c!hoogte=#8sp]{#1}}% 
      \egroup}
     {\framed[\c!breedte=#7sp,\c!hoogte=#8sp]{#1}}}

%D As we will see now, \PDFTEX\ not only directly supports 
%D \type{mps}, \type{png}, \type{pdf}, \type{jpg} but also 
%D \type{mov}. In \CONTEXT\ we support movie inserts in a way
%D similar to figure inclusion. The next macro calls the 
%D general \PDF\ one.

\def\setcurrentmovie#1%
  {\doglobal\increment\currentmovie}

\definefileinsertion{tpd}{mov}{\doPDFinsertmov}

%D \macros 
%D   {measureTPDfiguresizetrue}
%D
%D Because \PDFTEX\ measures the figure itself, we can use 
%D this feature to bypass the normal prescan. Watch the 
%D double check on the suffix. Else \PDFTEX\ would choke. 

\newif\ifmeasureTPDfiguresize \measureTPDfiguresizetrue 

\def\dogetTPDfiguresize#1#2#3#4#5#6%
  {\ifmeasureTPDfiguresize
      #3=\!!zeropoint
      #4=\!!zeropoint
      \doifvalidpdfimagefileelse{#2}
        {\global\setbox\foundexternalfigure=\vbox{\pdfimage{#2}}%
         #5=\wd\foundexternalfigure 
         #6=\ht\foundexternalfigure}
        {#5=\!!zeropoint
         #6=\!!zeropoint}%
   \else
     #1{#2}{#3}{#4}{#5}{#6}% \normaldogetfiguresize...
   \fi}

\let\normaldogetfiguresizepdf=\dogetfiguresizepdf
\let\normaldogetfiguresizepng=\dogetfiguresizepng
\let\normaldogetfiguresizetif=\dogetfiguresizetif
\let\normaldogetfiguresizejpg=\dogetfiguresizejpg

\def\dogetfiguresizepdf{\dogetTPDfiguresize\normaldogetfiguresizepdf}
\def\dogetfiguresizepng{\dogetTPDfiguresize\normaldogetfiguresizepng}
\def\dogetfiguresizetif{\dogetTPDfiguresize\normaldogetfiguresizetif}
\def\dogetfiguresizejpg{\dogetTPDfiguresize\normaldogetfiguresizejpg}

%D \macros
%D  {doovalbox}
%D
%D Drawing frames with round corners is inherited from the 
%D main module. 

\definespecial\doovalbox%
  {\doPDFovalbox}

%D \macros
%D   {dostartgraymode,dostopgraymode,
%D    dostartrgbcolormode,dostartcmykcolormode,dostartgraycolormode,
%D    dostopcolormode,
%D    dostartrotation,dostoprotation,
%D    dostartscaling,dostopscaling,        
%D    dostartmirroring,dostopmirroring,      
%D    dostartnegative,dostopnegative}       
%D
%D These are implemented in the main \PDF\ module. 

\definespecial\dostartgraymode      {\doPDFstartgraymode}
\definespecial\dostopgraymode       {\doPDFstopgraymode}
\definespecial\dostartrgbcolormode  {\doPDFstartrgbcolormode}
\definespecial\dostartcmykcolormode {\doPDFstartcmykcolormode}
\definespecial\dostartgraycolormode {\doPDFstartgraycolormode}
\definespecial\dostopcolormode      {\doPDFstopcolormode}
\definespecial\dostartrotation      {\doPDFstartrotation}      
\definespecial\dostoprotation       {\doPDFstoprotation}       
\definespecial\dostartscaling       {\doPDFstartscaling}       
\definespecial\dostopscaling        {\doPDFstopscaling}        
\definespecial\dostartmirroring     {\doPDFstartmirroring}     
\definespecial\dostopmirroring      {\doPDFstopmirroring}      
\definespecial\dostartnegative      {\doPDFstartnegative}      
\definespecial\dostopnegative       {\doPDFstopnegative}       

%D \macros
%D   {dosetupinteraction,
%D    dosetupopenaction,dosetupcloseaction}
%D
%D Nothing special is needed to enable \PDF\ commands and
%D interaction. We stick with a message.

\definespecial\dosetupinteraction%
  {\showmessage{\m!interactions}{21}{pdftex}}

\definespecial\dosetupopenaction {\doPDFsetupopenaction}
\definespecial\dosetupcloseaction{\doPDFsetupcloseaction}

%D \macros
%D   {doresetgotowhereever,
%D    dostartthisisrealpage,dostartthisislocation,
%D    dostartgotorealpage,dostartgotolocation,dostartgotoJS}
%D
%D The interactions macros are the core of this module. We
%D support both page destinations and named ones. We don't
%D need the \type{\stop}||alternatives. We also don't need
%D to set the special that sets the real page number.

\definespecial\doresetgotowhereever {\doPDFresetgotowhereever}
\definespecial\dostartthisislocation{\doPDFstartthisislocation}

%D When going to a location, we obey the time and space saving
%D boolean \type{\ifusepagedestination}. Named destinations are
%D stripped and made robust. This all happens in the macros
%D called for.

\definespecial\dostartgotolocation{\doPDFstartgotolocation}
\definespecial\dostartgotorealpage{\doPDFstartgotorealpage}
\definespecial\dostartgotoJS      {\doPDFstartgotoJS}

%D \macros
%D   {doflushJSpreamble}
%D
%D It does not make sense to duplicate common \JAVASCRIPT\
%D functions, and therefore they can be predefined and must be
%D output separately. Currently this special is not shared
%D with the \ACROBAT\ one, simply because \DISTILLER\ does not
%D yet support something \type{\pdfnames}.

% \oneJSpreamblefalse  % buggy in acrobat 

\definespecial\doflushJSpreamble#1% 
  {\bgroup
   \let\compositeJScode=\empty
   \def\docommando##1%
     {\edef\sanitizedJScode{\getJSpreamble{##1}}%
      \@EA\doPSsanitizeJScode\sanitizedJScode\to\sanitizedJScode
      \pdfobj {<< /S /JavaScript /JS (\sanitizedJScode) >>}%
      \edef\compositeJScode%
        {\compositeJScode\space (##1) \the\pdflastobj\space 0 R}}%
   \processcommalist[#1]\docommando
   \pdfobj{<< /Names [ \compositeJScode ] >>}%
   \pdfnames{/JavaScript \the\pdflastobj\space 0 R}%
   \egroup}

%D \macros
%D   {dostarthide,dostophide}
%D
%D Hiding parts of the document for printing is not yet
%D supported by \PDF\ and therefore \PDFTEX.

\definespecial\dostarthide{}
\definespecial\dostophide {}

%D \macros
%D   {dosetupscreen}
%D
%D Setting of the screen boundingbox involves some
%D calculations. Here we also take care of (non) full screen
%D startup. The dimensions are rounded. Because \PDFTEX\ and
%D \ACROBAT\ handle setting the page dimensions in a
%D different way, we do not share this special.

\definespecial\dosetupscreen{\doPDFsetupscreen\pdfpageheight}

%D \macros
%D   {dostartexecutecommand}
%D
%D \PDF\ viewers enable us to navigate using menus and shortcut
%D keys. These navigational tools can also be accessed by using
%D annotations. The next special takes care of inserting them.

\definespecial\dostartexecutecommand{\doPDFstartexecutecommand}

%D \macros
%D   {dosetupidentity}
%D
%D Documents can be tagged with an application accessible title
%D and subtitle, the authorname, a date, the creator, keywords
%D etc. For the moment \PDFTEX\ only supports the first three
%D of these.

\definespecial\dosetupidentity#1#2#3#4#5%
  {\bgroup
   \enablePDFdocencoding
   \pdfinfo
     {/Title (#1)
      /Subject (#2)
      /Author (#3)
      /Creator (#4)
      /Producer (pdfTeX)}%
   \egroup}

%D \macros
%D   {dostartrunprogam}
%D
%D We can run a program form within a document, although this
%D feature is rather weak, due to path problems and buggy
%D argument passing.

\definespecial\dostartrunprogram{\doPDFstartrunprogram}

%D \macros
%D   {dostartgotoprofile, dostopgotoprofile,
%D    dobeginofprofile, doendofprofile}
%D
%D \CONTEXT\ user profiles and version control fall back on
%D \PDF\ article threads. Unfortunately one cannot influence
%D the view yet in an (for me) acceptable way.

\definespecial\dostartgotoprofile{\doPDFstartgotoprofile}

%D Some day, I'll reimplement threading in a useful way.
%D Currently the viewers handle threads rather diffuse.

\definespecial\dobeginofprofile#1#2#3#4%
  {\setPDFdestination{#1}%
   \doifsomething{\PDFdestination}
     {\pdfthread name {\PDFdestination}}}

\definespecial\doendofprofile%
  {\pdfendthread}

%D \macros
%D  {doinsertbookmark}
%D
%D In \PDF\ bookmarks are the building blocks of a viewer
%D provided sort of table of contents. \TEX\ has to provide
%D the entry as well as the number of child entries. Strings
%D need to be sanatized as good as possible to suit the default
%D encoding. In \CONTEXT\ users can overrule this string by
%D supplying an alternative one. Look at the macro called for
%D to see how funny these bookmarks are defined.

\definespecial\doinsertbookmark{\doPDFinsertbookmark}

%D \macros
%D  {dostartobject,dostopobject,doinsertobject}
%D
%D Due to \PDF's object oriented character, we can include and
%D reuse objects. These can be compared with \TEX's boxes. The
%D \TEX\ counterpart is defined in the module \type{spec-dvi}.
%D We don't use the dimensions here.

% Forms can interfere with page dimension settings. Therefore
% calling macros can best postpone flushing.

\definespecial\dostartobject#1#2#3#4#5%
  {\bgroup
   \setbox\nextbox=\vbox\bgroup
     \def\dodostopobject%
       {\egroup
        %\immediate 
        \pdfform\nextbox
        \dosetobjectreference{#1}{#2}{\the\pdflastform}}}%

\definespecial\dostopobject%
  {\dodostopobject
   \egroup}

\definespecial\doinsertobject#1#2%
  {\bgroup
   \dogetobjectreference{#1}{#2}\PDFobjectreference
   \pdfrefform\PDFobjectreference
   \egroup}

%D \macros
%D   {dosetpagetransition}
%D
%D Page transitions only make sence in presentations. They are
%D passed as raw \PDF\ code to the page object. Take a look
%D at the implementation to get an impression of the rubish
%D passed on.

\definespecial\dosetpagetransition{\doPDFsetpagetransition}

%D The expansion is needed because else the \type{\pdfpageattr}
%D token list flushes an unexpanded \type{\csname}. The
%D \type{\global} is needed because the assignment can take
%D place deeply buried (for instance in the \type{\shipout}
%D box.

%D \macros 
%D   {doinsertcomment}
%D
%D Text annotation, or comments, are provided too:

\definespecial\doinsertcomment{\doPDFinsertcomment}

%D \macros
%D   {dopresetlinefield,dopresettextfield,
%D    dopresetchoicefield,dopresetpopupfield,dopresetcombofield,
%D    dopresetpushfield,dopresetcheckfield,
%D    dopresetradiofield,dopresetradiorecord}
%D
%D \PDF\ offers extensive field support. The next bunch of
%D definitions map the specials.

\definespecial\dopresetlinefield  {\doFDFpresetlinefield}
\definespecial\dopresettextfield  {\doFDFpresettextfield}
\definespecial\dopresetchoicefield{\doFDFpresetchoicefield}
\definespecial\dopresetpopupfield {\doFDFpresetpopupfield}
\definespecial\dopresetcombofield {\doFDFpresetcombofield}
\definespecial\dopresetpushfield  {\doFDFpresetpushfield}
\definespecial\dopresetcheckfield {\doFDFpresetcheckfield}
\definespecial\dopresetradiofield {\doFDFpresetradiofield}
\definespecial\dopresetradiorecord{\doFDFpresetradiorecord}

%D \macros
%D   {dodefinefieldset,dogetfieldset,doiffieldset}
%D 
%D Field sets, needed for reset and submit handling, are 
%D taken care of by:

\definespecial\dodefinefieldset{\doFDFdefinefieldset}
\definespecial\dogetfieldset   {\doFDFgetfieldset}
\definespecial\doiffieldset    {\doFDFiffieldset}

%D \macros 
%D   {doPDFdestination}
%D
%D Finally we implement some low level macros to deal with
%D flushing \PDF\ code. First we handle the named destinations.

\def\doPDFdestination name #1%
  {\pdfdest name {#1}\PDFpageviewkey}

%D \macros 
%D   {doPDFaction,doPDFannotation,doPDFtextannotation,
%D    ifsharePDFactions} 
%D 
%D Next we handle annotations. All link annotations are
%D implemented using the action dictionary. This enables us to
%D use multiple actions. The second macro is for instance 
%D used for movie inclusion. 

\newif\ifsharePDFactions \sharePDFactionstrue

% \def\doPDFaction width #1 height #2 action #3%
%   {\ifnum\similarreference=1
%      \ifsharePDFactions
%        \pdfobj{<<#3>>}\xdef\ lastPDFaction{\the\pdflastobj\space0 R}%
%      \else
%        \xdef\lastPDFaction{<<#3>>}%
%      \fi
%    \fi
%    \pdfannotlink
%      width #1sp height #2sp depth 0sp
%      user {/Subtype /Link 
%            /Border [0 0 0] 
%            /A \ifcase\similarreference<<#3>>\else\lastPDFaction\fi}%
%    \pdfendlink}

\def\doPDFaction width #1 height #2 action #3%
  {\ifcase\similarreference\relax
     \xdef\lastPDFaction{<<#3>>}%
   \or
     \ifsharePDFactions
       \pdfobj{<<#3>>}\xdef\lastPDFaction{\the\pdflastobj\space0 R}%
     \else
       \xdef\lastPDFaction{<<#3>>}%
     \fi
   \fi
   \ifcollectreferenceactions \else
     \pdfannotlink
       width #1sp height #2sp depth 0sp
       user {/Subtype /Link 
             /Border [0 0 0] 
             /A \lastPDFaction}%
     \pdfendlink
   \fi}

\def\doPDFannotation width #1 height #2 data #3%
  {\pdfannot width #1sp height -#2sp depth 0sp {#3}}

\def\doPDFtextannotation width #1 height #2 data #3%
  {\pdfannot width #1sp height #2sp depth 0sp {#3}}

%D \macros 
%D   {doPDFannotationobject} 
%D
%D For field support we need annotation objects. Although in
%D many cases we can do without indirect references (and use
%D the last annotation object number directly), we take the 
%D save route. 

\def\doPDFannotationobject class #1 name #2 width #3 height #4 data #5%
  {\pdfannot width #3sp height -#4sp depth 0sp {#5}%
   \dosetobjectreference{#1}{#2}{\the\pdflastannot}}

%D \macros 
%D   {doPDFaddtocatalog,doPDFpageattribute,doPDFpagesattribute}
%D
%D Next some simple ones. Watch the global directive and the 
%D expansion in the page attribute macro. 

\def\doPDFaddtocatalog%
  {\pdfcatalog}

\def\doPDFpageattribute#1%
  {\expanded{\global\pdfpageattr{\the\pdfpageattr#1}}}

\def\doPDFpagesattribute#1%
  {\expanded{\global\pdfpagesattr{\the\pdfpagesattr#1}}}

\def\doPDFresetattributes%
  {\global\pdfpageattr{}%
   \global\pdfpagesattr{}}

\appendtoks\doPDFresetattributes\to\everyaftershipout

%D \macros 
%D   {doPDFbookmark} 
%D
%D Well, isn't the next one ugly? Thanks to the \PDF\ 
%D standard. 

% obsolete cq. buggy in pdfTeX
%
% \def\doPDFbookmark level #1 n #2 text #3 page #4 open #5%
%   {\pdfoutline
%      goto page #4\space
%      \ifcase#2 \else count \ifcase#5-\fi#2 \fi
%      {#3}}

\def\doPDFbookmark level #1 n #2 text #3 page #4 open #5%
  {\pdfoutline
     user {<</S /GoTo /D [#4\PDFpageviewwrd]>>}%
     \ifcase#2 \else count \ifcase#5-\fi#2 \fi
     {#3}}

%D \macros 
%D   {doPDFdictionaryobject,doPDFarrayobject}
%D
%D Where \PDFTEX\ has only one object primitive, optionally a
%D stream one, \ACROBAT\ has several operators. 

\def\doPDFdictionaryobject class #1 name #2 data #3%
  {\flushatshipout
     {\pdfobj{<< #3 >>}\dosetobjectreference{#1}{#2}{\the\pdflastobj}}}

\def\doPDFarrayobject class #1 name #2 data #3%
  {\flushatshipout
     {\pdfobj{[ #3 ]}\dosetobjectreference{#1}{#2}{\the\pdflastobj}}}

%D \macros 
%D   {defaultobjectreference,doPDFgetobjectreference}
%D
%D Because in \PDFTEX\ we have to construct the object
%D references \type{N 0 R}, we can default to the non existing 
%D zero object number. 

\def\defaultobjectreference#1#2%
  {0}

\def\doPDFgetobjectreference#1#2#3%
  {\dogetobjectreference{#1}{#2}#3%
   \edef#3{\ifx#3\empty null\else#3\space0 R\fi}}

%D Now we can finish this module. 

\stopspecials

\protect

\endinput