[XeTeX] (x)dvipdfmx replaces link destinations with integers. Why?

Alexander Grahn A.Grahn at hzdr.de
Fri Sep 12 10:26:45 CEST 2014


Hello,

unlike other output drivers, (x)dvipdfmx translates link destination
strings, such as (testA), (testB) in

pdf:dest (testA) [@thispage /XYZ @xpos @ypos null]
pdf:dest (testB) [@thispage /XYZ @xpos @ypos null]

specials, into internally generated integer strings (0), (1), ... in
/Dests <</Names [...] >> and in Link annotations of the final PDF.

This is very annoying, because it prevents users from creating custom
Action dictionaries of subtype /GoTo used in other Annotation types and
triggers. As said before, the automatic destination string replacement
only works in /A <</S/GoTo /D (...)>> action dictionaries of /Link
Annotations, but not elsewhere where defective /GoTo actions are
produced. See the example below which implements a hyperlink macro with
formatted tip text (requires AR for display).

Could (x)dvipdfmx be changed to keep the original destination string?

Alexander

\documentclass[12pt,oneside]{book}

\usepackage{hyperref}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage:
%
% \hyperlinkWithTip{<destination>}[<linkcolour>]{<linktext>}[<tipboxcolour>]{<tiptext>}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{media9}
\usepackage{xcolor}
\usepackage{calc}
\usetikzlibrary{calc}

\ExplSyntaxOn
\let\tpPdfLink\mix_pdflink:nn
\let\tpPdfAnnot\mix_pdfannot:nnnn\def\tpPdfLastAnn{\g_mix_pdflastann_tl}
\let\tpPdfXform\mix_pdfxform:n\def\tpPdfLastXform{\g_mix_pdflastxform_tl}
\let\tpPdfObj\mix_pdfobj:nnn\def\tpPdfLastObj{\g_mix_pdflastobj_tl}
\ExplSyntaxOff

\makeatletter
\NewDocumentCommand{\hyperlinkWithTip}{mO{blue}mO{yellow!20}m}{{%
  \leavevmode%
  \tpPdfObj{}{dict}{/Type/OCG/Name (tipOCG.\thetcnt)%
    /Usage<</Print<</PrintState/OFF>>/Export<</ExportState/OFF>>>>%
  }%
  \xdef\@anim at ocgs{\@anim at ocgs\space\tpPdfLastObj}%
  \xdef\@anim at offocgs{\@anim at offocgs\space\tpPdfLastObj}%
  \edef\tpTipOcg{\tpPdfLastObj}%
  \tpPdfLink{%
    /Subtype/Screen%
    /AA<<%
      /E<</S/SetOCGState/State [/ON \tpTipOcg]>>%
      /X<</S/SetOCGState/State [/OFF \tpTipOcg]>>%
      /U<</S/SetOCGState/State [/OFF \tpTipOcg]/Next<</S/GoTo/D (#1)>>>>%
    >>%
  }{{\color{#2}#3}}%
  \sbox\tiptext{\fcolorbox{black}{#4}{#5}}%
  \edef\twd{\the\wd\tiptext}%
  \edef\tht{\the\dimexpr\ht\tiptext+\dp\tiptext\relax}%
  \measureremainder{\whatsleft}\tipshift=0pt%
  \ifdim\whatsleft<\twd\setlength\tipshift{\whatsleft-\twd}\fi%
  \tpPdfXform{\tiptext}%
  \raisebox{\heightof{#3}}[0pt][0pt]{\makebox[0pt][l]{\hspace{\tipshift}%
    \tpPdfAnnot{\twd}{\tht}{0pt}{%
      /Subtype/Widget/FT/Btn/Ff 65537/T (tip:\thetcnt)%
      /AP<</N \tpPdfLastXform>>%
      /MK<</TP 1/I \tpPdfLastXform/IF<</S/A/FB true/A [0.0 0.0]>>>>%
      /OC \tpTipOcg
    }%
    \xdef\@anim at fields{\@anim at fields\space\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}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

Lots of text. \hyperlinkWithTip{test}{Test}{To be explained on the next page.} this if you can.

Lots of text. Another \hyperlinkWithTip{testB}{test}{\parbox[b]{0.5\linewidth}{This is a longer text. Don't miss the explanation given on the next page.}} if you wish.
\newpage

\hypertarget{test}{Here's my link destination.}

\hypertarget{testB}{Yet another link destination.}

\end{document}


More information about the XeTeX mailing list