summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/oberdiek/atfidvips.def
blob: 8ac4ea594c980b09e1ec6163e045d8179e46dc5f (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
%%
%% This is file `atfidvips.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% attachfile2.dtx  (with options: `dvips')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2005, 2006 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 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.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% This work consists of the main source file attachfile2.dtx
%% and the derived files
%%    attachfile2.sty, attachfile2.pdf, attachfile2.ins, attachfile2.drv,
%%    atfidvips.def, atfipdftex.def, pdfatfi.pl.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{atfipdftex.def}%
  [2007/04/11 v2.3 attachfile2 driver for dvips (HO)]%
\def\atfi@literal#1{%
  \special{ps:atfi_dict begin{#1}atfi_?pdfmark end}%
}

\def\atfi@header#1{%
  \special{! #1}%
}


\atfi@header{%
  userdict begin 20 dict dup /atfi_dict exch def end begin%
    /atfi_?pdfmark systemdict %
    dup/pdfmark known%
    {%
      /exec get def%
    }{%
      /pop get def%
    } ifelse%
    {%
      %
      % x y width height atfi_re ->
      languagelevel 2 ge {%
        /atfi_rectfill { rectfill } bind def%
        /atfi_rectstroke { rectstroke } bind def%
      }{%
        /atfi_rect {%
          /atfi_height exch def%
          /atfi_width exch def%
          /atfi_x exch def%
          /atfi_y exch def %
          newpath %
          atfi_x atfi_y moveto %
          atfi_x atfi_width add atfi_y lineto %
          atfi_x atfi_width add atfi_y atfi_height add lineto %
          atfi_x atfi_y atfi_height add lineto %
          closepath%
        } bind def%
        /atfi_rectfill {%
          atfi_rect fill%
        } bind def%
        /atfi_rectstroke {%
          atfi_rect stroke%
        } bind def%
      } ifelse%
      /atfi_curveto_v {%
        currentpoint 6 2 roll curveto%
      } bind def%
      /atfi_curveto_y {%
        2 copy curveto%
      } bind def%
      %
      % help macro for atfi_convert_date
      /atfi_two {%
        dup 10 lt%
        {%
          1 string cvs %
          exch 1 add exch%
        }{%
          2 string cvs%
        } ifelse %
        putinterval%
      } bind def%
      %
      % <seconds since 1970-01-01> atfi_convert_date -> (D:...Z)
      /atfi_convert_date {%
        dup%
        /atfi_days exch 3600 idiv 24 idiv def%
        % calc date part
        /atfi_year 1970 def%
        {%
          atfi_year 400 mod 0 eq %
          atfi_year 100 mod 0 ne %
          atfi_year 4   mod 0 eq %
          and or%
          {366} {365} ifelse %
          dup atfi_days lt%
          {%
            atfi_days exch sub /atfi_days exch def%
            /atfi_year atfi_year 1 add def%
          }{%
            exit%
          } ifelse%
        } loop%
        /atfi_month 1 def%
        /atfi_days atfi_days 1 add def %
        31 atfi_days lt%
        {%
          atfi_days 31 sub /atfi_days exch def%
          /atfi_month atfi_month 1 add def %
          366 eq {29} {28} ifelse dup atfi_days lt%
          {%
            atfi_days exch sub /atfi_days exch def%
            /atfi_month atfi_month 1 add def %
          31 atfi_days lt%
          {%
            atfi_days 31 sub /atfi_days exch def%
            /atfi_month atfi_month 1 add def %
          30 atfi_days lt%
          {%
            atfi_days 30 sub /atfi_days exch def%
            /atfi_month atfi_month 1 add def %
            31 atfi_days lt%
            {%
              atfi_days 31 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            30 atfi_days lt%
            {%
              atfi_days 30 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            31 atfi_days lt%
            {%
              atfi_days 31 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            31 atfi_days lt%
            {%
              atfi_days 31 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            30 atfi_days lt%
            {%
              atfi_days 30 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            31 atfi_days lt%
            {%
              atfi_days 31 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            30 atfi_days lt%
            {%
              atfi_days 30 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def %
            31 atfi_days lt%
            {%
              atfi_days 31 sub /atfi_days exch def%
              /atfi_month atfi_month 1 add def%
            } if%
            } if%
            } if%
            } if%
            } if%
            } if%
            } if%
            } if%
            } if%
            } if%
          } { pop } ifelse%
        }{ pop } ifelse %
        % calc time part
        3600 24 mul mod %
        dup 3600 idiv dup /atfi_hour exch def %
        3600 mul sub %
        dup 60 idiv dup /atfi_min exch def %
        60 mul sub %
        /atfi_sec exch def%
        (D:19700101000000Z)%
        dup 2  atfi_year 4 string cvs putinterval %
        dup 6  atfi_month atfi_two %
        dup 8  atfi_days  atfi_two %
        dup 10 atfi_hour  atfi_two %
        dup 12 atfi_min   atfi_two %
        dup 14 atfi_sec   atfi_two%
      } bind def %
      %
      % <filename> atfi_calc_checksum -> /CheckSum <checksum>
      % or returns nothing, if MD5Encode is not given
      false %
      languagelevel 2 ge {%
        (MD5Encode)%
        { pop true or }%
        (MD5Encode) length string%
        /Filter %
        resourceforall%
      } if%
      {%
        /atfi_calc_checksum {%
          /atfi_checksum 16 string def%
          /atfi_file exch (r) file def%
          /atfi_md5sum atfi_checksum /MD5Encode filter def %
          % not too efficient to read and write byte by byte,
          % using a buffer is probably faster
          atfi_size {%
            atfi_file read%
            {%
              atfi_md5sum exch write%
            } if%
          } repeat %
          atfi_md5sum closefile %
          atfi_file closefile%
          /CheckSum atfi_checksum%
        } bind def%
      }{%
        /atfi_calc_checksum { pop } bind def%
      } ifelse%
      %
      /atfi_pttobp { 72.27 div 72 mul } bind def%
      /atfi_pdftodvipsx { 72.27 div Resolution mul } bind def%
      /atfi_pdftodvipsy { 72.27 div VResolution mul } bind def%
      %
    } atfi_?pdfmark %
  end%
}

\def\atfi@GSAVE{gsave }
\def\atfi@GRESTORE{grestore }
\def\atfi@SETLINEWIDTH{setlinewidth }
\def\atfi@LINETO{lineto }
\def\atfi@MOVETO{moveto }
\def\atfi@STROKE{stroke }
\def\atfi@FILL{fill }
\def\atfi@FILLSTROKE#1#2{gsave #1 fill grestore #2 stroke }
\def\atfi@SETRGBCOLORSTROKE{setrgbcolor }
\def\atfi@SETRGBCOLORFILL{setrgbcolor }
\def\atfi@SETGRAYSTROKE{setgray }
\def\atfi@SETGRAYFILL{setgray }
\def\atfi@RECTFILL{atfi_rectfill }
\def\atfi@RECTSTROKEFILL#1#2#3{%
  #3%
  #1%
  gsave atfi_rectfill grestore %
  #2%
  #3%
  atfi_rectstroke %
  #1%
}
\def\atfi@SETMITERLIMIT{setmiterlimit }
\def\atfi@SETFLAT{setflat }
\def\atfi@SETLINECAP{setlinecap }
\def\atfi@CURVETO{curveto }
\def\atfi@CURVETOV{atfi_curveto_v }
\def\atfi@CURVETOY{atfi_curveto_y }
\def\atfi@CLOSEPATH{closepath }
\def\atfi@SETLINEJOIN{setlinejoin }


\newcounter{atfi@obj}
\renewcommand*{\theatfi@obj}{%
  {atfi_obj_\number\c@atfi@obj}%
}


\define@key{AtFi@file}{Size}{}

\def\atfi@embedfile#1{%
  \@ifundefined{atfi@fileobj@#1}{%
    \atfi@pdfstringdef\atfi@psfilename{#1}%
    \stepcounter{atfi@obj}%
    \expandafter\xdef\csname atfi@fileobj@#1\endcsname{\theatfi@obj}%
    \begingroup
      \let\atfi@params\@empty
      \@ifundefined{atfi@file@#1}{}{%
        \edef\x{\noexpand\setkeys{AtFi@file}{\@nameuse{atfi@file@#1}}}%
        \x
      }%
      \atfi@literal{%
        /atfi_filename(\atfi@psfilename)def %
        atfi_filename status%
        {%
          % ok: file found
          % save parameters of status command
          /atfi_created exch def%
          /atfi_referenced exch def%
          /atfi_size exch def %
          pop % drop parameter "pages" (storage space), never needed
          % ghostscript:
          %   created:       stat.st_ctime
          %   referenced:    stat.st_mtime
          %   stat.st_ctime: interpretion depends on operating system:
          %                  * unix: inode change time (not interesting)
          %                  * win32: probably creation time
          %                           --> /CreationDate
          %   stat.st_mtime: modification time --> /ModDate
          %   time values are seconds since 1970-01-01, GMT
          % TODO: ghostscript offers "getenv" for getting the value
          %       of an environment variable. That could be used to
          %       to detect windows and settingthe /CreationDate entry.
          % TODO: how are these values interpreted by other distiller
          %       programs?
          %
          [%
            /_objdef \theatfi@obj
            /type/stream%
          /OBJ pdfmark%
          [%
            \theatfi@obj
            <<%
              /Type/EmbeddedFile%
              \atfi@mimetype
              /Params%
              <<%
                \atfi@params
                %
                /Size atfi_size%
                %
                /product where%
                {%
                  pop %
                  % check for ghostscript
                  product (Ghostscript) search%
                  {%
                    pop pop pop %
                    % ghostscript is running
                    %
                    \ifatfi@creationdate
                    \else
                      false % TODO: test for windows
                      {%
                        /CreationDate atfi_created atfi_convert_date%
                      } if%
                    \fi
                    \ifatfi@moddate
                    \else
                      /ModDate atfi_referenced atfi_convert_date%
                    \fi
                  } if%
                  %
                  % look for MD5Encode filter and calculate CheckSum
                } if %
                \ifatfi@checksum
                \else
                  atfi_filename atfi_calc_checksum%
                \fi
              >>%
            >>%
          /PUT pdfmark%
          [%
            \theatfi@obj
            atfi_filename (r) file%
          /PUT pdfmark%
          [%
            \theatfi@obj
          /CLOSE pdfmark%
        }{%
          % error: file not found
          % currently nothing is done
        } ifelse%
      }%
    \endgroup
  }{%
    % file already embedded
  }%
}


\def\atfi@xform@icon{%
  \stepcounter{atfi@obj}%
  \edef\atfi@appearanceobj{\theatfi@obj}%
  \atfi@literal{%
    [%
      /_objdef \atfi@appearanceobj
      /BBox[%
        0 %
        0 %
        \strip@pt\wd\atfi@appearancebox\space atfi_pttobp %
        \strip@pt\dimexpr\dp\atfi@appearancebox
            +\ht\atfi@appearancebox\relax\space atfi_pttobp%
      ]%
    /BP pdfmark %
    \csname atfi@acro\atfi@icon@icon @data\endcsname
    [%
    /EP pdfmark%
  }%
}
\def\atfi@xform{%
  \stepcounter{atfi@obj}%
  \edef\atfi@appearanceobj{\theatfi@obj}%
  \begingroup
    \setbox0=\hbox{%
      \atfi@literal{%
        [%
          /_objdef \atfi@appearanceobj
          /BBox[%
            currentpoint %
              \strip@pt\dp\atfi@appearancebox\space sub %
            currentpoint %
              exch \strip@pt\wd\atfi@appearancebox\space add %
              exch \strip@pt\ht\atfi@appearancebox\space add%
          ]%
        /BP pdfmark %
        gsave %
        currentpoint %
        2 copy translate %
        72.27 Resolution div 72.27 VResolution div neg scale %
        exch neg exch neg translate%
      }%
      \usebox{\atfi@appearancebox}%
      \atfi@literal{%
        grestore%
        [%
        /EP pdfmark%
      }%
    }%
    % do not allocate any space for xobject definition
    \dp0=\z@
    \ht0=\z@
    \wd0=\z@
    \mbox{\usebox0}%
  \endgroup
}

\def\atfi@refxform#1{%
  \raisebox{-\atfi@appearancedepth}{%
    \atfi@literal{%
      gsave %
        currentpoint translate %
        Resolution 72 div VResolution neg 72 div scale%
        [#1 /SP pdfmark % hash-ok
      grestore%
    }%
    \makebox[\atfi@appearancewidth]{}%
  }%
  \rule{0pt}{\atfi@appearanceheight}%
}


\def\atfi@insert@file@annot#1{%
  \rule{0pt}{0pt}%
  \ifatfi@appearance
    \def\atfi@appearance@dict{%
      /AP<<%
        /N \atfi@appearanceobj
        /R \atfi@appearanceobj
        /D \atfi@appearanceobj
      >>%
    }%
  \else
    \let\atfi@appearance@dict\@empty
  \fi
  \@ifundefined{atfi@fsobj@#1}{%
    \stepcounter{atfi@obj}%
    \expandafter\xdef\csname atfi@fsobj@#1\endcsname{\theatfi@obj}%
    \atfi@pdfstringdef\atfi@file{#1}%
    \atfi@literal{%
      [%
        /_objdef \theatfi@obj
        /type/dict%
      /OBJ pdfmark%
      [%
        \theatfi@obj
        <<%
          /Type/Filespec%
          /F(\atfi@file)%
          /EF<<%
            /F \csname atfi@fileobj@#1\endcsname
          >>%
        >>%
      /PUT pdfmark%
    }%
  }{%
  }%
  \atfi@literal{%
    [%
      /Subtype/FileAttachment%
      \atfi@icon
      \atfi@color
      \atfi@author
      \atfi@date
      \atfi@annotname
      \atfi@description
      \atfi@subject
      \atfi@appearance@dict
      /F \theatfi@flags
      /FS \csname atfi@fsobj@#1\endcsname
      /Rect[%
        currentpoint %
          \strip@pt\dimexpr\atfi@scale\atfi@appearancedepth\relax
            \space atfi_pdftodvipsy add %
        currentpoint %
          exch \strip@pt\dimexpr\atfi@scale\atfi@appearancewidth\relax
            \space atfi_pdftodvipsx add %
          exch \strip@pt\dimexpr\atfi@scale\atfi@appearanceheight\relax
            \space atfi_pdftodvipsy sub %
      ]%
    /ANN pdfmark%
  }%
  \rule{0pt}{\atfi@appearanceheight}%
  \rule[-\atfi@appearancedepth]{0pt}{\atfi@appearancedepth}%
  \rule{\atfi@appearancewidth}{0pt}%
}

\endinput
%%
%% End of file `atfidvips.def'.