summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ocgtools/ocgtools.sty
blob: e49d4b67603e8e8da1bb9f32b2e809f706ec0adb (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
%%
%% This is file `ocgtools.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ocgtools.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2010 by Robert Marik <marik@mendelu.cz>
%% 
%% This file may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.2 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.2 or later is part of all distributions of LaTeX version
%% 1999/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{ocgtools}
    [2010/11/19 v0.8a ocgtools.dtx  file]
\def\ocgtools@msg{If this message does not disappear after a short time, the
  author either did not compile the \LaTeX{} file three times, or your
  PDF viewer does not support OCG. Use Adobe Reader!}

\def\ocgtextstart{\color{blue}}
\def\ocgtextend{}
\ifx\definecolor\undefined\RequirePackage{color}\fi
\ifx\href\undefined\RequirePackage[pdftex]{hyperref}\fi
\definecolor{ocgpaper}{rgb}{1,1,0.2}
\definecolor{ocgfontcolor}{rgb}{0,0,0}
\def\defaultocgpapercolor{ocgpaper}
\def\defaultocgfontcolor{ocgfontcolor}
\definecolor{ocgbg}{rgb}{0,0,0}
\RequirePackage{graphicx}
\RequirePackage{pifont}
\RequirePackage{ocg}
\RequirePackage{xkeyval}

\newif\if@ocgtools@insideminilayer
\def\ocgclosechar{{\color{red}\def\temp{red}%
   \ifx\temp\ocgt@@ls@bg\if@ocgtools@insideminilayer\color{black}\fi\fi
   \ding{56}}}

\RequirePackage{atbegshi}
\RequirePackage[pdftex]{eforms}
\newif\if@ocgtools@transparent\@ocgtools@transparentfalse
\DeclareOption{transparent}{\@ocgtools@transparenttrue}
\newif\if@ocgtools@insertvisible\@ocgtools@insertvisiblefalse
\def\ocgtools@initialvisibility{0}
\DeclareOption{insertvisible}{\@ocgtools@insertvisibletrue
   \def\ocgtools@initialvisibility{1}}
\newif\ifocg@hide@button\ocg@hide@buttontrue
\DeclareOption{nobutton}{\ocg@hide@buttonfalse}
\def\ocgtools@progressmsg{\lower \layerVshift\hbox to 0 pt{ %space
  \textField[\V{OCGtools: processing OCG's ...}\BG{1 1 1}
  \textColor{1 0 0} \textSize{10}]%
{ocgtoolsmsg}{6cm}{20pt}\hss}}%
\DeclareOption{noprogressmsg}{\let\ocgtools@progressmsg\relax}
\newif\if@ocgtools@minimouseover \@ocgtools@minimouseoverfalse
\DeclareOption{minimouseover}{\@ocgtools@minimouseovertrue}
\newif\if@ocgtools@mouseover \@ocgtools@mouseoverfalse
\DeclareOption{mouseover}{\@ocgtools@mouseovertrue \@ocgtools@minimouseovertrue}
\newif\if@ocgtools@pageclose \@ocgtools@pageclosetrue
\DeclareOption{nopageclose}{\@ocgtools@pageclosefalse}
\newif\if@ocgtools@inactive\@ocgtools@inactivefalse
\DeclareOption{inactive}{\@ocgtools@inactivetrue}
\DeclareOption{noocg}{\@ocgtools@inactivetrue}
\newif\if@ocgtools@active\@ocgtools@activefalse
\DeclareOption{active}{\@ocgtools@activetrue}

\ProcessOptions

\if@ocgtools@active\@ocgtools@inactivefalse\fi
\newdimen\layerHshift \layerHshift=-1in
\newdimen\layerVshift \layerVshift=0pt

\if@ocgtools@inactive
  \newcommand\ocgpicture[2][]{\leavevmode\includegraphics[#1]{#2}}
  \newcommand\ocgtext[3][0pt]{\leavevmode #2}
  \newcommand\ocgtoolsplacepicture[3]{}
  \newcommand\ocgtoolsplacetext[3]{}
  \newcommand\ocgtoolsplaceminitext[7]{}
  \newcommand\ocgminitext[3][0pt]{\leavevmode #2}%
  \let\ocgminitextlt\ocgminitext
  \let\ocgminitextrt\ocgminitext
  \let\ocgminitextlb\ocgminitext
  \let\ocgminitextrb\ocgminitext
  \PackageWarning{ocgtools}{Ocgtools inactive}%
\expandafter\endinput\fi

\def\ocgtools@JS#1{\JS{DirtyBeforeOCGtools=this.dirty; #1
  this.dirty=DirtyBeforeOCGtools;}}
\@ifpackageloaded{fancytooltips}{%
  \let\TooltipPageopencloseJS\relax
  \ifx\fancytooltips@pdfpageattrJS\undefined
  \def\@ocgtools@fancytooltips{var DirtyBeforeCloseTooltip=this.dirty;
    CloseTooltips(); this.dirty=DirtyBeforeCloseTooltip;}
  \else
  \let\@ocgtools@fancytooltips\fancytooltips@pdfpageattrJS
  \fi
  }{\def\@ocgtools@fancytooltips{}}

\edef\ocgtools@pdfpageattr{
/AA << /O << /S /JavaScript /JS
  (
  if (typeof(ocgtoolsOCGs)!="undefined"){
   var temp = ocgtoolsOCGs.length;
   \if@ocgtools@pageclose
   for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
     {
      ocgtoolsOCGs[i].state = false;
     }
   \fi
  }
  else {
    app.focusRect = false;
    var DirtyBeforeOCGtools=this.dirty;
    var iniocgtoolsOCGs = this.getOCGs();
    var ocgtoolsOCGs = [];
    for(var i=0; iniocgtoolsOCGs && i<iniocgtoolsOCGs.length;i++)
     {
     if(iniocgtoolsOCGs[i].name.substr(0,8) == "ocgtools")
        {
          ocgtoolsOCGs.push(iniocgtoolsOCGs[i]);
          \if@ocgtools@insertvisible
          iniocgtoolsOCGs[i].state=false;
          \fi
        }
     }
    iniocgtoolsOCGs[0].state=true;
    iniocgtoolsOCGs[0].state=false;
    \ifx\ocgtools@progressmsg\relax\relax\else
    this.getField("ocgtoolsmsg").hidden=true;
    this.dirty=false;
    \fi
    }
    \ifocg@hide@button
     this.getField("OcgtoolsBtn.HideButton.main").hidden = true;
     this.dirty=false;
    \fi
    \@ocgtools@fancytooltips
    )
    >> >>
}

\expandafter\global\expandafter\pdfpageattr\expandafter{\ocgtools@pdfpageattr}

\def\ocgtools@transparent{}
\if@ocgtools@transparent
\RequirePackage{transparent} \def\ocgtools@transparent{\transparent{0.4}}
\fi
\newif\ifocg@minitext@left
\newif\ifocg@minitext@bottom
\newcount\ocgtools@layercount
\newskip\ocgtools@left@skip
\newskip\ocgtools@bottom@skip
\newdimen\ocgtools@maxheight
\newdimen\ocgtools@maxwidth
\def\ocgtools@save@position{\pdfsavepos
\write\@auxout{\string\global\string\advance\string \layerVshift \the\pdflastypos sp\string\relax}%
\write\@auxout{\string\global\string\advance\string \layerHshift \the\pdflastxpos sp\string\relax}%
\global\let\ocgtools@save@position\relax
}

\newtoks\ocgtools@layer@toks
\ocgtools@layer@toks{\ocg@place@text{0}{1}{5cm}}
\newbox\ocgtools@box@a
\newbox\ocgtools@box@b
\newif\ifocg@page@contains@layer
\def\ocgtools@one{1}
\let\ocgtools@shipoutstart@hook\relax
\let\ocgtools@shipoutend@hook\relax
\AtBeginShipout{%
\expandafter\global\expandafter\pdfpageattr\expandafter{\ocgtools@pdfpageattr}
\setbox\AtBeginShipoutBox=\hbox{%
\ocgtools@shipoutstart@hook
\ocgtools@save@position
\hbox to 0 pt{\box\AtBeginShipoutBox\hss}\kern -1in\kern \layerHshift
\ocg@page@contains@layerfalse
\lower \layerVshift \hbox{\the\ocgtools@layer@toks}%
\ifocg@page@contains@layer
  \vbox to 0 pt{\kern -\paperheight \kern\layerVshift\hbox to 0 pt{\ocgtools@HideBtn\hss}\vss}%
\fi
\xdef\ocgtools@currpage{\thepage}%
\ifx\ocgtools@currpage\ocgtools@one
\ocgtools@progressmsg
\fi
\hss \ocgtools@shipoutend@hook%
\kern 1in \kern -\layerHshift%
}%
}
\ifx\ocgtools@AfterHideBtn\undefined\def\ocgtools@AfterHideBtn{}\fi
\def\ocgtools@HideBtn{\pushButton[\W{0}\BG{}\S{S}\BC{}\H{N}\F{\FHidden}\A{\ocgtools@JS{
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton").hidden = true; \fi
         \ocgtools@AfterHideBtn
       }}]{OcgtoolsBtn.HideButton.main}{\paperwidth}{\paperheight}}
\ifx\ocgtools@AfterHideMiniLayer\undefined\def\ocgtools@AfterHideMiniLayer{}\fi
\newcommand\ocgtools@HideMiniLayer[2][]
{\setbox\ocgtools@box@a=\hbox{{\ocgclosechar}}%
\hbox to \wd\ocgtools@box@a%
{\hbox{{\ocgclosechar}}\hss%
\hbox{\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
\F{\FHidden}\A{\ocgtools@JS{
    for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
    {
      if(ocgtoolsOCGs[i].name == "ocgtools#2")
      ocgtoolsOCGs[i].state = false;
    }
    this.getField("OcgtoolsBtn.HideButton.mini.#2").hidden = true;
    \ocgtools@AfterHideMiniLayer
    #1
  }}]%
{OcgtoolsBtn.HideButton.mini.#2}{\wd\ocgtools@box@a}{\ht\ocgtools@box@a}}}}
\ifx\ocgtools@AfterHideLayers\undefined\def\ocgtools@AfterHideLayers{}\fi
\newcommand\ocgtools@HideLayers[1]{%
\setbox\ocgtools@box@a=\hbox{{\ocgclosechar}}%
\hbox to \wd\ocgtools@box@a%
{\hbox{{\ocgclosechar}}\hss%
\hbox{\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
\F{\FHidden}\A{\ocgtools@JS{
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button
         this.getField("OcgtoolsBtn.HideButton.main").hidden = true;
         \fi
         \ocgtools@AfterHideLayers
       }}]%
     {OcgtoolsBtn.HideButton.corner.#1}{\wd\ocgtools@box@a}{\ht\ocgtools@box@a}}}}
\newcommand{\ocgtools@ToggleLayer}[2]{%
  % #1: layer name,
  % #2: link text
  \leavevmode%
  \pdfstartlink user {
    /Subtype /Link
    /Border [0 0 0]%
    /H /N
    /A <<
      /S/JavaScript
      /JS (
         DirtyBeforeOCGtools=this.dirty;
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = !ocgtoolsOCGs[i].state;
         else
         ocgtoolsOCGs[i].state = false;
         }
         \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton.main").hidden = false;\fi
         this.getField("OcgtoolsBtn.HideButton.corner").hidden = false;
         this.getField("OcgtoolsBtn.HideButton.corner.#1").setFocus();
         this.dirty=DirtyBeforeOCGtools;
      )
    >>
  }#2%
    \if@ocgtools@mouseover
  \hbox to 0 pt{\hss\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
  \A{\ocgtools@JS{
        var OpenedByMouseEnter#1=false;
        \ifocg@hide@button this.getField("OcgtoolsBtn.HideButton.main").hidden = false;\fi
        this.getField("OcgtoolsBtn.HideButton.corner").hidden = false;
        this.getField("OcgtoolsBtn.HideButton.corner.#1").setFocus();
        }}
  \AA{\AAMouseEnter{\ocgtools@JS{         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         var OpenedByMouseEnter#1=true;
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = true;
         else
         ocgtoolsOCGs[i].state = false;
         }
         }}
  \AAMouseExit{\ocgtools@JS{
        if (OpenedByMouseEnter#1)
         {for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         ocgtoolsOCGs[i].state = false;
         }}
         }}}]
    {OcgtoolsBtn.MaxiButton.#1}{8pt}{8pt}}%
  \fi
  \pdfendlink%
}

\newcommand{\ocgtools@ToggleMiniLayer}[4]{%
  % #1: layer name,
  % #2: link text
  % #3: js action if the layer is opened
  % #4: js action if the layer is closed
  \leavevmode%
  \pdfstartlink user {
    /Subtype /Link
    /Border [0 0 0]%
    /H /N
    /A <<
      /S/JavaScript
      /JS (
         DirtyBeforeOCGtools=this.dirty;
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         {
           if (ocgtoolsOCGs[i].state)
           {
             #4
             ocgtoolsOCGs[i].state = false;
           }
           else
           {
             #3
             ocgtoolsOCGs[i].state = true;
           }
         }
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden =
         !this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden;
         if (!this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden)
           {this.getField("OcgtoolsBtn.HideButton.mini.#1").setFocus();}
         this.dirty=DirtyBeforeOCGtools;
      )
    >>
  }#2%
  \if@ocgtools@minimouseover
  \hbox to 0 pt{\hss\pushButton[\W{0}\S{S}\BG{}\BC{}\H{N}%
  \A{\ocgtools@JS{
    var OpenedByMouseEnter#1=false;
    this.getField("OcgtoolsBtn.HideButton.mini.#1").setFocus();
   }}
  \AA{\AAMouseEnter{\ocgtools@JS{for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         var OpenedByMouseEnter#1=true;
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         {#3 ocgtoolsOCGs[i].state = true;}
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden = false;
         }}
  \AAMouseExit{\ocgtools@JS{
       if (OpenedByMouseEnter#1)
       {
         for(var i=0; ocgtoolsOCGs && i<ocgtoolsOCGs.length;i++)
         {
         if(ocgtoolsOCGs[i].name == "ocgtools#1")
         {#4 ocgtoolsOCGs[i].state = false; }
         }
         this.getField("OcgtoolsBtn.HideButton.mini.#1").hidden = true;
       }
       }}}]
    {OcgtoolsBtn.MiniButton.#1}{8pt}{8pt}}%
  \fi
  \pdfendlink%
}

\newwrite\posHandle
\def\posFile{\jobname.pos}
\def\posOpen{\openout\posHandle=\posFile}
\def\posClose{\closeout\posHandle}
\AtBeginDocument{\InputIfFileExists{\posFile}{}{}%
\ocgtools@maxheight=0.9\paperheight
\ocgtools@maxwidth=0.9\paperwidth
\expandafter\global\expandafter\def\csname ocgtools@textcontent@0\endcsname
{{\color{red}\bfseries\ocgtools@msg}}%
\posOpen}
\AtEndDocument{\posClose}

\newcommand\ocgpicture[2][]{%
\global\advance\ocgtools@layercount by 1%
\ocgtools@ToggleLayer{\the\ocgtools@layercount}%
{\leavevmode\includegraphics[#1]{#2}}%
\expandafter\write\expandafter\posHandle\expandafter{%
\expandafter\string\expandafter\ocgtoolsplacepicture\expandafter{%
\the\ocgtools@layercount}{\thepage}{#2}}%
}

\define@key{ocg@key}{width}[0pt]{\def\ocgt@@ls@width{#1}}
\define@key{ocg@key}{background}[ocgpaper]{\def\ocgt@@ls@bg{#1}}
\define@key{ocg@key}{bg}[ocgpaper]{\def\ocgt@@ls@bg{#1}}
\define@key{ocg@key}{color}[ocgfontcolor]{\def\ocgt@@ls@fg{#1}}
\define@key{ocg@key}{fg}[ocgfontcolor]{\def\ocgt@@ls@fg{#1}}
\define@key{ocg@key}{jsopen}[]{\def\ocgt@@ls@jsopen{#1}}
\define@key{ocg@key}{jsclose}[]{\def\ocgt@@ls@jsclose{#1}}

\newtoks\ocg@pdflastxpos\ocg@pdflastxpos{\the\pdflastxpos}
\newtoks\ocg@pdflastypos\ocg@pdflastypos{\the\pdflastypos}
\newtoks\ocg@pagetoks\ocg@pagetoks{\thepage}

\def\ocgtools@setdefault{\def\ocgt@@ls@bg{\defaultocgpapercolor}%
\def\ocgt@@ls@fg{\defaultocgfontcolor}%
\def\ocgt@@ls@width{0pt}\def\ocgt@@ls@jsopen{}%
\def\ocgt@@ls@jsclose{}%
}

\newcommand\ocgtext[3][0pt]{%
\ocgtools@setdefault
\setkeys*{ocg@key}{#1}%
\ifx\XKV@rm\empty\setkeys{ocg@key}{#1}\else\setkeys{ocg@key}{width=#1}\fi
\global\advance\ocgtools@layercount by 1%
\ocgtools@ToggleLayer{\the\ocgtools@layercount}%
{\leavevmode{\ocgtextstart #2\ocgtextend}}%
\edef\ocgtools@act{\write\posHandle{\noexpand\string\noexpand\ocgtoolsplacetext{\the\ocgtools@layercount}{\the\ocg@pagetoks}{width=\ocgt@@ls@width,bg=\ocgt@@ls@bg,fg=\ocgt@@ls@fg}}}%
\ocgtools@act
\expandafter\global\expandafter\def
\csname ocgtools@textcontent@\the\ocgtools@layercount\endcsname{#3}%
}

\newcommand\ocgminitextlt[3][0pt]{%
\ocg@minitext@bottomfalse\ocg@minitext@lefttrue
\do@ocg@minitext{#1}{#2}{#3}{lt}}%
\newcommand\ocgminitextrt[3][0pt]{%
\ocg@minitext@bottomfalse\ocg@minitext@leftfalse
\do@ocg@minitext{#1}{#2}{#3}{rt}}%
\newcommand\ocgminitextlb[3][0pt]{%
\ocg@minitext@bottomtrue\ocg@minitext@lefttrue
\do@ocg@minitext{#1}{#2}{#3}{lb}}%
\newcommand\ocgminitextrb[3][0pt]{%
\ocg@minitext@bottomtrue\ocg@minitext@leftfalse
\do@ocg@minitext{#1}{#2}{#3}{rb}}%
\let\ocgminitext\ocgminitextrt

\long\def\do@ocg@minitext#1#2#3#4{%
\ocgtools@setdefault
\setkeys*{ocg@key}{#1}%
\ifx\XKV@rm\empty\setkeys{ocg@key}{#1}\else\setkeys{ocg@key}{width=#1}\fi
\global\advance\ocgtools@layercount by 1\relax%
\leavevmode
\ifocg@minitext@left
  \ifocg@minitext@bottom
    \vbox to 0 pt{\kern 0.7\baselineskip\pdfsavepos\vss}%
  \else
    \vbox to 0 pt{\vss\pdfsavepos\kern 0.7\baselineskip}%
  \fi
\fi
\ocgtools@ToggleMiniLayer{\the\ocgtools@layercount}%
{{\ocgtextstart #2\ocgtextend}}{\ocgt@@ls@jsopen}{\ocgt@@ls@jsclose}%
\ifocg@minitext@left\else
  \ifocg@minitext@bottom
    \vbox to 0 pt{\kern 0.7\baselineskip\pdfsavepos\vss}%
  \else
    \vbox to 0 pt{\vss\pdfsavepos\kern 0.7\baselineskip}%
  \fi
\fi
\edef\ocgtools@act{\write\posHandle{\noexpand\string\noexpand\ocgtoolsplaceminitext{\the\ocgtools@layercount}{\the\ocg@pagetoks}{\the\ocg@pdflastxpos}{\the\ocg@pdflastypos}{}{width=\ocgt@@ls@width,bg=\ocgt@@ls@bg,fg=\ocgt@@ls@fg,jsopen={\ocgt@@ls@jsopen},jsclose={\ocgt@@ls@jsclose}}{#4}}}%
\ocgtools@act
\expandafter\global\expandafter\def
\csname ocgtools@minitextcontent@\the\ocgtools@layercount\endcsname{#3}%
}%

\newcommand\ocgtoolsplacepicture[3]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks \ocg@place@picture{#1}{#2}{#3}}}

\newcommand\ocgtoolsplacetext[3]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks\ocg@place@text{#1}{#2}{#3}}}

\newcommand\ocgtoolsplaceminitext[7]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks \ocg@place@minitext{#1}{#2}{#3}{#4}{#5}{#6}{#7}}}

\def\ocg@place@picture#1#2#3{\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\ifx\tempnumb\tempnuma
  \global\ocg@page@contains@layertrue
  \vbox to 0 pt{\vss\hbox to 0pt%
    {\hbox{\begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
          \ocgtools@drawpicture{#3}{#1}\end{ocg}}\hss}}%
\fi}

\def\ocg@place@text#1#2#3{\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\ifx\tempnumb\tempnuma
  \global\ocg@page@contains@layertrue
  \vbox to 0 pt{\vss\hbox to 0 pt{\hbox{%
    \begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
      \ocgtools@drawtext{#3}{\csname ocgtools@textcontent@#1\endcsname}{#1}%
    \end{ocg}}\hss}}%
\fi}

\long\def\ocg@place@minitext#1#2#3#4#5#6#7{%
\def\tempnuma{#2}\edef\tempnumb{\thepage}%
\def\ocg@placement{#7}%
\def\ocg@rb{rb}\def\ocg@lb{lb}\def\ocg@rt{rt}\def\ocg@lt{lt}%
\ocg@minitext@leftfalse\ocg@minitext@bottomfalse
\ifx\ocg@placement\ocg@lb
  \ocg@minitext@lefttrue\ocg@minitext@bottomtrue
\fi
\ifx\ocg@placement\ocg@rb
  \ocg@minitext@leftfalse\ocg@minitext@bottomtrue\fi
\ifx\ocg@placement\ocg@lt
  \ocg@minitext@lefttrue\ocg@minitext@bottomfalse
\fi
\ifx\tempnumb\tempnuma
  \ocgtools@left@skip=#3sp minus #3sp%
  \ocgtools@bottom@skip=#4sp%
  \setbox\ocgtools@box@a=\hbox{\begin{ocg}{ocgtools#1}{ocgtools#1}{\ocgtools@initialvisibility}%
  \ocgtools@drawminitext{#6}{\csname ocgtools@minitextcontent@#1\endcsname}{#1}
  \end{ocg}}%
  \ifocg@minitext@left
    \ifdim \ocgtools@left@skip>\wd\ocgtools@box@a
      \advance \ocgtools@left@skip by -\wd\ocgtools@box@a plus 0 pt minus -\wd\ocgtools@box@a
    \else
      \ocgtools@left@skip=0pt\relax
    \fi
  \fi
  \ifocg@minitext@bottom
    \advance \ocgtools@bottom@skip by -\ht\ocgtools@box@a
  \fi
  \hbox to 0 pt{\hbox to \paperwidth{\hskip \ocgtools@left@skip
  \vbox to 0 pt{\vss
  \vbox to \paperheight{\vskip 0 pt plus 1 fill
  \box\ocgtools@box@a\vskip \ocgtools@bottom@skip}
  }%
  \hskip 0 pt plus 1 fill}\hss}%
\fi
}

\let\ocgtools@pict@envelope\relax
\def\ocgtools@drawpicture#1#2{\vbox to \paperheight{\vbox to 0 pt{{%
\ocgtools@transparent\color{ocgbg}%
\hrule width \paperwidth height \paperheight}\vss}\vss
\hbox to \paperwidth{\hss
\setbox\ocgtools@box@a=\hbox{\ocgtools@pict@envelope{%
  \includegraphics[height=\ocgtools@maxheight]{#1}}}%
\ifdim\wd\ocgtools@box@a>\ocgtools@maxwidth
  \ocgtools@pict@envelope{\includegraphics[width=\ocgtools@maxwidth]{#1}}%
  \else \box\ocgtools@box@a
\fi
\hss}%
\vss
\hbox to \paperwidth {\hss\ocgtools@HideLayers{#2}}}}

\newdimen\ocg@textdimen
\let\ocgtools@text@envelope\relax
\long\def\ocgtools@drawtext#1#2#3{%
\ocgtools@setdefault
\setkeys*{ocg@key}{#1}%
\ifx\XKV@rm\empty\setkeys{ocg@key}{#1}\else\setkeys{ocg@key}{width=#1}\fi
\vbox to \paperheight{%
\vbox to 0 pt{{\ocgtools@transparent\color{ocgbg}%
\hrule width \paperwidth height \paperheight}\vss}\vss\hbox to \paperwidth
{\hss
\ifdim\ocgt@@ls@width=0pt
  \setbox\ocgtools@box@a=\hbox{\expandafter\colorbox\expandafter{\ocgt@@ls@bg}%
  {\expandafter\color\expandafter{\ocgt@@ls@fg}\ocgtools@text@envelope{#2}}}%
\else
  \setbox\ocgtools@box@a=\hbox{\expandafter\colorbox{\expandafter\ocgt@@ls@bg}%
    {\vbox{\hsize=\ocgt@@ls@width\relax\linewidth=\ocgt@@ls@width\relax
        \rightskip 0 pt plus 1 fil\relax
    \expandafter\color\expandafter{\ocgt@@ls@fg}\ocgtools@text@envelope{#2}}}}%
\fi
\setbox\ocgtools@box@b\hbox{\resizebox{!}{\ocgtools@maxheight}{\copy\ocgtools@box@a}}%
\ifdim\wd\ocgtools@box@b>\ocgtools@maxwidth
  \resizebox{\ocgtools@maxwidth}{!}{\box\ocgtools@box@a}
\else
  \box\ocgtools@box@b
\fi
\hss}%
\vss
\hbox to \paperwidth {\hss\ocgtools@HideLayers{#3}}%
}%
}

\def\ocg@empty{}

\let\ocgtools@minitext@envelope\relax
\newcommand\ocgtools@drawminitext[3]{%
\@ocgtools@insideminilayertrue
\ocgtools@setdefault
\setkeys*{ocg@key}{#1}%
\ifx\XKV@rm\empty\setkeys{ocg@key}{#1}\else\setkeys{ocg@key}{width=#1}\fi
\ifdim\ocgt@@ls@width=0pt
  \setbox\ocgtools@box@a=\hbox{\colorbox{\ocgt@@ls@bg}{\expandafter\color
      \expandafter{\ocgt@@ls@fg}\ocgtools@minitext@envelope{#2}\ }}%
\else  \setbox\ocgtools@box@a=\hbox{\colorbox{\ocgt@@ls@bg}%
  {\vbox{\hsize=\ocgt@@ls@width\relax\linewidth=\ocgt@@ls@width\relax
      \rightskip 0 pt plus 1 fil\relax
      \expandafter\color\expandafter{\ocgt@@ls@fg}\ocgtools@minitext@envelope{#2}}}}%
\fi
\def\temp{#3}%
\ifx\temp\ocg@empty
\box\ocgtools@box@a
\else
\hbox{\copy\ocgtools@box@a\raise\ht\ocgtools@box@a
\vbox to 0 pt{\hbox to 0 pt{\hss
\ocgtools@HideMiniLayer[\ocgt@@ls@jsclose]{#3}}\vss}}%
\fi
\@ocgtools@insideminilayerfalse
}

\endinput
%%
%% End of file `ocgtools.sty'.