%%
%% 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}
    [2011/01/25 v0.91 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
\def\ocgtools@transparent{}
\DeclareOptionX{transparent}[0.5]{\@ocgtools@transparenttrue\gdef\ocgtools@transparent{\transparent{#1}}}
\newif\if@ocgtools@insertvisible\@ocgtools@insertvisiblefalse
\def\ocgtools@initialvisibility{0}
\DeclareOptionX{insertvisible}{\@ocgtools@insertvisibletrue
   \def\ocgtools@initialvisibility{1}}
\newif\ifocg@hide@button\ocg@hide@buttontrue
\DeclareOptionX{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}}%
\DeclareOptionX{noprogressmsg}{\let\ocgtools@progressmsg\relax}
\newif\if@ocgtools@minimouseover \@ocgtools@minimouseoverfalse
\DeclareOptionX{minimouseover}{\@ocgtools@minimouseovertrue}
\newif\if@ocgtools@mouseover \@ocgtools@mouseoverfalse
\DeclareOptionX{mouseover}{\@ocgtools@mouseovertrue \@ocgtools@minimouseovertrue}
\newif\if@ocgtools@pageclose \@ocgtools@pageclosetrue
\DeclareOptionX{nopageclose}{\@ocgtools@pageclosefalse}
\newif\if@ocgtools@inactive\@ocgtools@inactivefalse
\DeclareOptionX{inactive}{\@ocgtools@inactivetrue}
\DeclareOptionX{noocg}{\@ocgtools@inactivetrue}
\newif\if@ocgtools@active\@ocgtools@activefalse
\DeclareOptionX{active}{\@ocgtools@activetrue}
\newif\if@ocgtools@fixcolor\@ocgtools@fixcolorfalse
\DeclareOptionX{fixcolor}{\@ocgtools@fixcolortrue}

\ProcessOptionsX

\if@ocgtools@transparent\else\@ocgtools@fixcolorfalse\fi

\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[4]{}
  \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}

\if@ocgtools@transparent
\RequirePackage{transparent}
\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{%
\if@ocgtools@fixcolor
\hbox to 0 pt{\resizebox{1pt}{!}{\includegraphics[width=0.7em]%
         {ocgtools-fixcolor.pdf}}\hss}%
\fi
\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}{#1}}%
}

\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[4]{%
\expandafter\global\expandafter\ocgtools@layer@toks\expandafter
{\the\ocgtools@layer@toks \ocg@place@picture{#1}{#2}{#3}{#4}}}

\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#4{\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}{#4}\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#3{\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[#3,width=!,height=\ocgtools@maxheight]{#1}}}%
\ifdim\wd\ocgtools@box@a>\ocgtools@maxwidth
  \ocgtools@pict@envelope{\includegraphics[#3,height=!,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'.
