diff options
author | Karl Berry <karl@freefriends.org> | 2018-09-25 20:26:19 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-09-25 20:26:19 +0000 |
commit | 200dac99798d6f21c19080f7af67db478064fcb6 (patch) | |
tree | bc52928c3172c516288e31ba92c65d1ca3d1aa11 /Master/texmf-dist/tex/latex | |
parent | 6ced7aee72a4f6fba14102923db8c35d1e2a031e (diff) |
ocgx2 (25sep18)
git-svn-id: svn://tug.org/texlive/trunk@48759 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty | 211 |
1 files changed, 161 insertions, 50 deletions
diff --git a/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty b/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty index b3a287b3514..77ec3292ffe 100644 --- a/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty +++ b/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty @@ -20,6 +20,9 @@ % themselves placed on layers, compatibility with the animate and media9 % packages. % +% Re-implements hyperref's `ocgcolorlinks' option to produce coloured links +% that may wrap around line breaks and page breaks. +% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This work may be distributed and/or modified under the @@ -35,8 +38,8 @@ \RequirePackage{xparse} \RequirePackage{l3keys2e} -\def\g@ocgxii@date@tl{2018/06/27} -\def\g@ocgxii@version@tl{0.36} +\def\g@ocgxii@date@tl{2018/09/25} +\def\g@ocgxii@version@tl{0.37} \ProvidesExplPackage{ocgx2}{\g@ocgxii@date@tl}{\g@ocgxii@version@tl} {ports `ocgx' functionality to dvips+ps2pdf, xelatex and dvipdfmx} @@ -379,19 +382,19 @@ \ocgxii_ocglist_reset: \tl_set:Nx\l_ocgxii_opt_tl{#1}\tl_remove_all:Nn\l_ocgxii_opt_tl{~} \str_case_x:nnF{\l_ocgxii_opt_tl}{ - {triggerocg=onmouseup}{ + {onmouseup}{ \ocgxii_ocglist_build:Nn\l_ocgxii_u_list_tl{#2} } - {triggerocg=onmousedown}{ + {onmousedown}{ \ocgxii_ocglist_build:Nn\l_ocgxii_d_list_tl{#2} } - {triggerocg=onmouseenter}{ + {onmouseenter}{ \ocgxii_ocglist_build:Nn\l_ocgxii_e_list_tl{#2} } - {triggerocg=onmouseexit}{ + {onmouseexit}{ \ocgxii_ocglist_build:Nn\l_ocgxii_x_list_tl{#2} } - {triggerocg=allactions}{ + {onmouseall}{ \ocgxii_commalist_process:n{#2} } }{ @@ -403,7 +406,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % re-implement commands from ocgx.sty (all engines including ps2pdf [gs>=9.15]) -% adding optional `*` (arg 1) -> non-breakable link instead of plain (multiline) +% adding optional `*' (arg 1) -> non-breakable link instead of plain (multiline) % Link; % adding optional 2nd argument -> Button Widget (non-breakable) with one of % various mouse triggers (`troggerocgs` option from ocg-p) @@ -446,21 +449,21 @@ % %process *all* mouse triggers (e,d,u,x) \ocgxii_ocglist_process_idlist:nn{ - \IfValueTF{#2}{#2}{triggerocg=onmouseup} + \IfValueTF{#2}{#2}{onmouseup} }{#3} \tl_set_eq:NN\l_ocgxii_toswitch_e_tl\l_ocgxii_e_list_tl \tl_set_eq:NN\l_ocgxii_toswitch_x_tl\l_ocgxii_x_list_tl \tl_set_eq:NN\l_ocgxii_toswitch_d_tl\l_ocgxii_d_list_tl \tl_set_eq:NN\l_ocgxii_toswitch_u_tl\l_ocgxii_u_list_tl \ocgxii_ocglist_process_idlist:nn{ - \IfValueTF{#2}{#2}{triggerocg=onmouseup} + \IfValueTF{#2}{#2}{onmouseup} }{#4} \tl_set_eq:NN\l_ocgxii_toshow_e_tl\l_ocgxii_e_list_tl \tl_set_eq:NN\l_ocgxii_toshow_x_tl\l_ocgxii_x_list_tl \tl_set_eq:NN\l_ocgxii_toshow_d_tl\l_ocgxii_d_list_tl \tl_set_eq:NN\l_ocgxii_toshow_u_tl\l_ocgxii_u_list_tl \ocgxii_ocglist_process_idlist:nn{ - \IfValueTF{#2}{#2}{triggerocg=onmouseup} + \IfValueTF{#2}{#2}{onmouseup} }{#5} \tl_set_eq:NN\l_ocgxii_tohide_e_tl\l_ocgxii_e_list_tl \tl_set_eq:NN\l_ocgxii_tohide_x_tl\l_ocgxii_x_list_tl @@ -487,23 +490,39 @@ % (additional actions) dict /Subtype/Widget/Ff~65536/FT/Btn/BS<</W~0>> /T~(ocgx2@\int_use:N\g_ocgxii_widcount_int) + %treat mouse-up as mouse-click --> handle through /A dictionary + \str_if_eq_x:nnF{}{ + \l_ocgxii_toswitch_u_tl\l_ocgxii_toshow_u_tl\l_ocgxii_tohide_u_tl + }{ + /A <</S/SetOCGState/State [ + \str_if_eq:VnF\l_ocgxii_toswitch_u_tl{}{ + /Toggle~\l_ocgxii_toswitch_u_tl + } + \str_if_eq:VnF\l_ocgxii_toshow_u_tl{}{ + /ON~\l_ocgxii_toshow_u_tl + } + \str_if_eq:VnF\l_ocgxii_tohide_u_tl{}{ + /OFF~\l_ocgxii_tohide_u_tl + } + ]>> + } /AA << - \str_if_eq_x:nnF{}{ - \l_ocgxii_toswitch_u_tl\l_ocgxii_toshow_u_tl\l_ocgxii_tohide_u_tl - }{ - /U <</S/SetOCGState/State [ - \str_if_eq:VnF\l_ocgxii_toswitch_u_tl{}{ - /Toggle~\l_ocgxii_toswitch_u_tl - } - \str_if_eq:VnF\l_ocgxii_toshow_u_tl{}{ - /ON~\l_ocgxii_toshow_u_tl - } - \str_if_eq:VnF\l_ocgxii_tohide_u_tl{}{ - /OFF~\l_ocgxii_tohide_u_tl - } - ]>> - } - \str_if_eq_x:nnF{}{ + %\str_if_eq_x:nnF{}{ + % \l_ocgxii_toswitch_u_tl\l_ocgxii_toshow_u_tl\l_ocgxii_tohide_u_tl + %}{ + % /U <</S/SetOCGState/State [ + % \str_if_eq:VnF\l_ocgxii_toswitch_u_tl{}{ + % /Toggle~\l_ocgxii_toswitch_u_tl + % } + % \str_if_eq:VnF\l_ocgxii_toshow_u_tl{}{ + % /ON~\l_ocgxii_toshow_u_tl + % } + % \str_if_eq:VnF\l_ocgxii_tohide_u_tl{}{ + % /OFF~\l_ocgxii_tohide_u_tl + % } + % ]>> + %} + \str_if_eq_x:nnF{}{ % mouse-down \l_ocgxii_toswitch_d_tl\l_ocgxii_toshow_d_tl\l_ocgxii_tohide_d_tl }{ /D <</S/SetOCGState/State [ @@ -518,7 +537,7 @@ } ]>> } - \str_if_eq_x:nnF{}{ + \str_if_eq_x:nnF{}{ % mouse-enter \l_ocgxii_toswitch_e_tl\l_ocgxii_toshow_e_tl\l_ocgxii_tohide_e_tl }{ /E <</S/SetOCGState/State [ @@ -533,7 +552,7 @@ } ]>> } - \str_if_eq_x:nnF{}{ + \str_if_eq_x:nnF{}{ % mouse-exit \l_ocgxii_toswitch_x_tl\l_ocgxii_toshow_x_tl\l_ocgxii_tohide_x_tl }{ /X <</S/SetOCGState/State [ @@ -550,7 +569,7 @@ } >> }{ - %mouse-up only only needs annot with /Link subtype + %mouse-up alone may go with simple /Link annot /Subtype/Link /A <</S/SetOCGState /State [ @@ -600,10 +619,37 @@ } %mimic commands from ocg-p -\cs_new_protected:Npn\toggleocgs{\switchocg*} -\cs_new_protected:Npn\showocgs{\showocg*} -\cs_new_protected:Npn\hideocgs{\hideocg*} -\cs_new_protected:Npn\setocgs{\actionsocg*} +\keys_define:nn{ocgx2/ocgpcmd}{ + triggerocg .choices:nn = { + onmouseenter, onmouseexit, onmousedown, onmouseup, allactions + }{ + \str_if_eq_x:nnTF{\l_keys_choice_tl}{allactions}{ + \tl_set:Nn\l_ocgxii_trigger_tl{onmouseall} + }{ + \tl_set_eq:NN\l_ocgxii_trigger_tl\l_keys_choice_tl + } + } +} +\DeclareDocumentCommand\toggleocgs{O{} m +m}{ + \tl_clear_new:N\l_ocgxii_trigger_tl + \keys_set:nn{ocgx2/ocgpcmd}{#1} + \switchocg*[\l_ocgxii_trigger_tl]{#2}{#3} +} +\DeclareDocumentCommand\showocgs{O{} m +m}{ + \tl_clear_new:N\l_ocgxii_trigger_tl + \keys_set:nn{ocgx2/ocgpcmd}{#1} + \showocg*[\l_ocgxii_trigger_tl]{#2}{#3} +} +\DeclareDocumentCommand\hideocgs{O{} m +m}{ + \tl_clear_new:N\l_ocgxii_trigger_tl + \keys_set:nn{ocgx2/ocgpcmd}{#1} + \hideocg*[\l_ocgxii_trigger_tl]{#2}{#3} +} +\DeclareDocumentCommand\setocgs{O{} m m m +m}{ + \tl_clear_new:N\l_ocgxii_trigger_tl + \keys_set:nn{ocgx2/ocgpcmd}{#1} + \actionsocg*[\l_ocgxii_trigger_tl]{#2}{#3}{#4}{#5} +} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \cs_new_protected:Nn\ocgxii_process_ocgref:NN{ @@ -893,18 +939,32 @@ % TikZ related code follows (to be enabled with package option `tikz') \bool_if:NF\l_ocgxii_tikz_bool{\endinput} +\cs_set_eq:NN\ocgxii@trmspc\tl_trim_spaces:N \ExplSyntaxOff \RequirePackage{tikz} \usetikzlibrary{calc} +% helper, replaces all spaces in #1 with `_' +\def\ocgxii@cnvspc#1{\expandafter\ocgxii@@cnvspc#1 \@nil} +\def\ocgxii@@cnvspc#1 #2\@nil{#1\ifx\@nil#2\@nil\else_\ocgxii@@cnvspc#2\@nil\fi} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Copyright notice: The code that follows until the end of the file was -% taken from Paul Gaborit's `tikzlibraryocgx.code.tex' with a minor -% addition: +% taken in large parts from Paul Gaborit's `tikzlibraryocgx.code.tex' with +% some additions/fixes: +% +% - opts={...} allows ocg-environment options to be passed to a TikZ scope +% +% - TikZ objects to be turned into ocg switching links accept the additional +% key % -% opts={...} allows ocg-environment options to be passed to a TikZ scope +% trigger ocg = onmousenter | onmouseexit | onmousedown | onmouseup | +% onmouseall +% +% to react to various mouse gestures +% +% - switching links properly sized and working in scaled tikzpictures % -% Also, it was fixed to work correctly in scaled tikzpictures. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \tikzset{ ocg/.style={ocg/.cd,#1,/tikz/.cd}, @@ -935,20 +995,38 @@ /tikz/execute at end scope={\end{ocg}}, } }, + trigger ocg/.store in=\ocgxii@trigger, + trigger ocg/.value required, switch ocg/.style={ postaction={ path picture={ \path (path picture bounding box.south west) coordinate (p1) (path picture bounding box.north east) coordinate (p2) (p1) node[inner sep=0pt,anchor=south west,outer sep=0pt] {% - \switchocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}}; + \ifdefined\ocgxii@trigger% + \switchocg*[\ocgxii@trigger]{#1}{% + \tikz \useasboundingbox (p1) rectangle (p2);}% + \else% + \switchocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}% + \fi% + }; } } }, switch ocg with mark on/.style 2 args={ postaction={ - path picture={ - \begin{ocg}[showingui=false]{#1}{#1}{1} + path picture={% + \edef\ocgxii@argone{#1}%ocg ref for checkmark + \ocgxii@trmspc\ocgxii@argone% + \global\let\ocgxii@argone\ocgxii@argone% + %default ocg ref for checkmark, if nothing provided in #1 + \xdef\ocgxii@argtwo{#2.mark}% + \xdef\ocgxii@argtwo{\ocgxii@cnvspc{\ocgxii@argtwo}}% + \begin{ocg}[showingui=false]{% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else\ocgxii@argone\fi% + }{% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else\ocgxii@argone\fi% + }{on}% \draw (path picture bounding box.south west) -- @@ -957,15 +1035,27 @@ -- (path picture bounding box.north west) ; - \end{ocg} + \end{ocg}% }, - switch ocg={#1 #2} + switch ocg={% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else{\ocgxii@argone}\fi\space #2% + } } }, switch ocg with mark off/.style 2 args={ postaction={ - path picture={ - \begin{ocg}[showingui=false]{#1}{#1}{0} + path picture={% + \edef\ocgxii@argone{#1}%ocg ref for checkmark + \ocgxii@trmspc\ocgxii@argone% + \global\let\ocgxii@argone\ocgxii@argone% + %default ocg ref for checkmark, if nothing provided in #1 + \xdef\ocgxii@argtwo{#2.mark}% + \xdef\ocgxii@argtwo{\ocgxii@cnvspc{\ocgxii@argtwo}}% + \begin{ocg}[showingui=false]{% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else\ocgxii@argone\fi% + }{% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else\ocgxii@argone\fi% + }{off}% \draw (path picture bounding box.south west) -- @@ -974,9 +1064,11 @@ -- (path picture bounding box.north west) ; - \end{ocg} + \end{ocg}% }, - switch ocg={#1 #2} + switch ocg={% + \ifx\ocgxii@argone\@empty\ocgxii@argtwo\else{\ocgxii@argone}\fi\space #2% + } } }, show ocg/.style={ @@ -985,7 +1077,13 @@ \path (path picture bounding box.south west) coordinate (p1) (path picture bounding box.north east) coordinate (p2) (p1) node[inner sep=0pt,anchor=south west,outer sep=0pt] {% - \showocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}}; + \ifdefined\ocgxii@trigger% + \showocg*[\ocgxii@trigger]{#1}{% + \tikz \useasboundingbox (p1) rectangle (p2);}% + \else% + \showocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}% + \fi% + }; } } }, @@ -995,7 +1093,13 @@ \path (path picture bounding box.south west) coordinate (p1) (path picture bounding box.north east) coordinate (p2) (p1) node[inner sep=0pt,anchor=south west,outer sep=0pt] {% - \hideocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}}; + \ifdefined\ocgxii@trigger% + \hideocg*[\ocgxii@trigger]{#1}{% + \tikz \useasboundingbox (p1) rectangle (p2);}% + \else% + \hideocg*{#1}{\tikz \useasboundingbox (p1) rectangle (p2);}% + \fi% + }; } } }, @@ -1005,7 +1109,14 @@ \path (path picture bounding box.south west) coordinate (p1) (path picture bounding box.north east) coordinate (p2) (p1) node[inner sep=0pt,anchor=south west,outer sep=0pt] {% - \actionsocg*{#1}{#2}{#3}{\tikz \useasboundingbox (p1) rectangle (p2);}}; + \ifdefined\ocgxii@trigger% + \actionsocg*[\ocgxii@trigger]{#1}{#2}{#3}{% + \tikz \useasboundingbox (p1) rectangle (p2);}% + \else% + \actionsocg*{#1}{#2}{#3}{% + \tikz \useasboundingbox (p1) rectangle (p2);}% + \fi% + }; } } } |