0

I'm trying to create a small fillable form and I have a small z-ordering problem, which I'm not able to solve on my own.

I create a 'tooltip' and the 'movetips' option is defined, so the tooltip will be displayed near to the mouse's actual position. This works as expected, but if I add a 'textField' after it, then the textField will be always over the pop-up window, which is clearly not what I want.

enter image description here

Relevant parts of the code:

\usepackage[filename=tips,mouseover,movetips]{fancytooltips}
\usepackage{eforms}

\begin{document}
...
\tooltip{\textcolor{black}{\textbf{E-mail:}}}{fmail}
\textField[\BC{0 0 1}\BG{0.98 0.92 0.73}\textColor{1 0 0}]{myText}{1.5in}{12bp}

I think there is no easy way to achieve the functionality I want (not provided by the packages, probably some JS hack could resolve the problem).

  • If it helps I also share my full codes: – SzGabor Sep 7 '16 at 20:16
1

An alternative \tooltip command taken from ->here<-, with an option added to specify x and y offsets of the tip box:

\tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}[<x offset>,<y offset>]

Moreover, the tip box can be moved around with the mouse.


\documentclass{article}

\usepackage{eforms}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% tooltips with LaTeX
%
% optimized for Adobe Reader (visible on mouse-over)
%     usage: \tooltip[<link colour>]{<link text>}[<tip box colour>]{<tip text>}[<x offset>,<y offset>]
%   non-draggable version:
%     usage: \tooltip*[<link colour>]{<link text>}[<tip box colour>]{<tip text>}[<x offset>,<y offset>]
%
% for Evince (visible on click, not draggable)
%   usage: \tooltip**[<link colour>]{<link text>}[<tip box colour>]{<tip text>}[<x offset>,<y offset>]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xparse,pdfbase,ocgbase}
\usepackage{xcolor,calc}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfLink\pbs_pdflink:nn
\let\tpPdfAnnot\pbs_pdfannot:nnnn\let\tpPdfLastAnn\pbs_pdflastann:
\let\tpAppendToFields\pbs_appendtofields:n
\def\tpPdfXform{\pbs_pdfxform:nnn{1}{1}}
\let\tpPdfLastXform\pbs_pdflastxform:
\let\cListSet\clist_set:Nn\let\cListItem\clist_item:Nn
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\tooltip}{ssO{blue}mO{yellow!20}mO{0pt,0pt}}{{%
  \leavevmode%
  \IfBooleanT{#1}{%
    \ocgbase@new@ocg{tipOCG.\thetcnt}{%
      /Print<</PrintState/OFF>>/Export<</ExportState/OFF>>%
    }{false}%
    \xdef\tpTipOcg{\ocgbase@last@ocg}%
  }%
  \tpPdfLink{%
    \IfBooleanTF{#2}{%
      /Subtype/Link/Border [0 0 0]/A <</S/SetOCGState/State [/Toggle \tpTipOcg]>>
    }{%
      /Subtype/Screen%
      \IfBooleanTF{#1}{%
        /AA<<%
          /E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
          /X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
        >>%
      }{
        /AA<<%
          /E<</S/JavaScript/JS(%
            var fd=this.getField('tip.\thetcnt');%
            \IfBooleanF{#1}{%
              if(typeof(click\thetcnt)=='undefined'){%
                var click\thetcnt=false;%
                var fdor\thetcnt=fd.rect;var dragging\thetcnt=false;%
              }%
            }%
            if(fd.display==display.hidden){%
              fd.delay=true;fd.display=display.visible;fd.delay=false;%
            }%
           this.dirty=false;%
          )>>%
          /X<</S/JavaScript/JS(%
            if(!click\thetcnt&&!dragging\thetcnt){fd.display=display.hidden;}%
            if(!dragging\thetcnt){click\thetcnt=false;}%
            this.dirty=false;%
          )>>%
          /U<</S/JavaScript/JS(click\thetcnt=true;this.dirty=false;)>>%
          /PC<</S/JavaScript/JS (%
            var fd=this.getField('tip.\thetcnt');%
            try{fd.rect=fdor\thetcnt;}catch(e){}%
            fd.display=display.hidden;this.dirty=false;%
          )>>%
          /PO<</S/JavaScript/JS(this.dirty=false;)>>%
        >>%
      }
    }%
  }{{\color{#3}#4}}%
  \cListSet\tpOffsets{#7}%
  \sbox\tiptext{\fcolorbox{black}{#5}{#6}}%
  \edef\twd{\the\wd\tiptext}%
  \edef\tht{\the\ht\tiptext}%
  \edef\tdp{\the\dp\tiptext}%
  \measureremainder{\whatsleft}\tipshift=0pt%
  \ifdim\whatsleft<\twd\setlength\tipshift{\whatsleft-\twd}%
  \else\addtolength\tipshift{\cListItem\tpOffsets{1}}\fi%
  \tpPdfXform{\tiptext}%
  \raisebox{\heightof{#4}+\tdp+\cListItem\tpOffsets{2}}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
    \tpPdfAnnot{\twd}{\tht}{\tdp}{%
      /Subtype/Widget/FT/Btn/T (tip.\thetcnt)%
      /AP<</N \tpPdfLastXform>>%
      /MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
      \IfBooleanTF{#1}{%
        /Ff 65537/OC \tpTipOcg%
      }{%
        /Ff 65536/F 3%
        /AA <<%
          /U <<%
            /S/JavaScript/JS(%
              var fd=event.target;%
              var mX=this.mouseX;var mY=this.mouseY;%
              var drag=function(){%
                var nX=this.mouseX;var nY=this.mouseY;%
                var dX=nX-mX;var dY=nY-mY;%
                var fdr=fd.rect;%
                fdr[0]+=dX;fdr[1]+=dY;fdr[2]+=dX;fdr[3]+=dY;%
                fd.rect=fdr;mX=nX;mY=nY;%
              };%
              if(!dragging\thetcnt){%
                dragging\thetcnt=true;Int=app.setInterval("drag()",1);%
              }%
              else{app.clearInterval(Int);dragging\thetcnt=false;}%
              this.dirty=false;%
            )%
          >>%
        >>%
      }%
    }%
    \tpAppendToFields{\tpPdfLastAnn}%
  }}%
  \stepcounter{tcnt}%
}}
\makeatother
\newsavebox\tiptext\newcounter{tcnt}
\newlength{\whatsleft}\newlength{\tipshift}
\newcommand{\measureremainder}[1]{%
  \begin{tikzpicture}[overlay,remember picture]
    \path let \p0 = (0,0), \p1 = (current page.east) in
      [/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
  \end{tikzpicture}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\parindent=0pt  %                                        tip offsets -------+---+
                %                                                           |   |                   
\begin{document}%                                                           Y   Y
\tooltip[black]{\textbf{E-mail: }}{e.\,g.: \texttt{myself@anonymous.org}}[-6ex,1ex]\textField[\BC{0 0 1}\BG{0.98 0.92 0.73}\textColor{1 0 0}]{myText}{1.5in}{12bp}
\end{document}
0

Thanks for your help. I managed to find a workaround (out-of-the-box solution), but still interested in latex only solution if exists.

pdf_reference_1.7 See section '8.4 Annotations'

The order of the annotations seems to define the z-order of Widget type annotations. So the simpliest solution is just to reorder the Annotations entry in our '.pdf' file. (uncompressed .pdf can be easily viewed/edited with a simple text editor). Simple script can be written that makes the reorder automatically.

Manual concrete example:

Original (content):

...
/Annots [ 18 0 R 19 0 R 21 0 R 22 0 R 23 0 R 41 0 R 28 0 R 24 0 R 25 0 R ]
...
28 0 obj
<<
/Type /Annot
/Rect [-0.996 -0.996 596.272 842.886]
/Subtype /Widget /F 6 /T (ikona.1) /FT /Btn /Ff 65536 /H /N /BS << /W 1 /S /S >> /MK << /TP 1 /IF <</A[1.0 1.0]/SW /B>> >> 
>>
endobj
...
25 0 obj
<<
/Type /Annot
/Rect [73.517 769.7 183.51 783.693]
/Subtype/Widget /T (myText) /FT/Tx /F 4/BS <</W 1/S/S>> /MK <</BC [0 0 1]/BG [0.98 0.92 0.73]>> /DA (/Helv 9 Tf 1 0 0 rg) /AA <<>>
>>
endobj

'ikona.1' is the pop-up tooltip and we can find our textfield by its name 'myText'. So all we need to do is move the object 25 ('myText') before object 28 ('ikona.1') in the row describing the Annotations.

Modify:

/Annots [ 18 0 R 19 0 R 21 0 R 22 0 R 23 0 R 41 0 R 28 0 R 24 0 R 25 0 R ]

To:

/Annots [ 18 0 R 19 0 R 21 0 R 22 0 R 23 0 R 41 0 R 25 0 R 28 0 R 24 0 R ]

Result: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.