texlive[48759] Master/texmf-dist: ocgx2 (25sep18)

commits+karl at tug.org commits+karl at tug.org
Tue Sep 25 22:26:19 CEST 2018


Revision: 48759
          http://tug.org/svn/texlive?view=revision&revision=48759
Author:   karl
Date:     2018-09-25 22:26:19 +0200 (Tue, 25 Sep 2018)
Log Message:
-----------
ocgx2 (25sep18)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/ocgx2/ChangeLog
    trunk/Master/texmf-dist/doc/latex/ocgx2/README
    trunk/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty

Modified: trunk/Master/texmf-dist/doc/latex/ocgx2/ChangeLog
===================================================================
--- trunk/Master/texmf-dist/doc/latex/ocgx2/ChangeLog	2018-09-25 20:26:08 UTC (rev 48758)
+++ trunk/Master/texmf-dist/doc/latex/ocgx2/ChangeLog	2018-09-25 20:26:19 UTC (rev 48759)
@@ -1,3 +1,7 @@
+2018-09-25
+	* v0.37: ocgx2.sty
+	* new: /tikz/trigger ocg={...} for various mouse triggers
+
 2018-06-27
 	* v0.36: ocgx2.sty
 	* fix: code of previous fix simplified

Modified: trunk/Master/texmf-dist/doc/latex/ocgx2/README
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty	2018-09-25 20:26:08 UTC (rev 48758)
+++ trunk/Master/texmf-dist/tex/latex/ocgx2/ocgx2.sty	2018-09-25 20:26:19 UTC (rev 48759)
@@ -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 at ocgxii@date at tl{2018/06/27}
-\def\g at ocgxii@version at tl{0.36}
+\def\g at ocgxii@date at tl{2018/09/25}
+\def\g at ocgxii@version at tl{0.37}
 
 \ProvidesExplPackage{ocgx2}{\g at ocgxii@date at tl}{\g at ocgxii@version at 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,7 +449,7 @@
   %
   %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
@@ -453,7 +456,7 @@
   \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
@@ -460,7 +463,7 @@
   \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 at trmspc\tl_trim_spaces:N
 \ExplSyntaxOff
 \RequirePackage{tikz}
 \usetikzlibrary{calc}
 
+% helper, replaces all spaces in #1 with `_'
+\def\ocgxii at 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 
+%  - opts={...} allows ocg-environment options to be passed to a TikZ scope
 %
-% Also, it was fixed to work correctly in scaled tikzpictures.
+%  - TikZ objects to be turned into ocg switching links accept the additional
+%    key
+%
+%      trigger ocg = onmousenter | onmouseexit | onmousedown | onmouseup |
+%                      onmouseall
+%
+%    to react to various mouse gestures
+%
+%  - switching links properly sized and working in scaled tikzpictures
+%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \tikzset{
   ocg/.style={ocg/.cd,#1,/tikz/.cd},
@@ -935,6 +995,8 @@
       /tikz/execute at end scope={\end{ocg}},
     }
   },
+  trigger ocg/.store in=\ocgxii at trigger,
+  trigger ocg/.value required,
   switch ocg/.style={
     postaction={
       path picture={
@@ -941,14 +1003,30 @@
         \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 at trigger%
+              \switchocg*[\ocgxii at 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 at argone{#1}%ocg ref for checkmark
+        \ocgxii at trmspc\ocgxii at argone%
+        \global\let\ocgxii at argone\ocgxii at argone%
+        %default ocg ref for checkmark, if nothing provided in #1
+        \xdef\ocgxii at argtwo{#2.mark}%
+        \xdef\ocgxii at argtwo{\ocgxii at cnvspc{\ocgxii at argtwo}}%
+        \begin{ocg}[showingui=false]{%
+          \ifx\ocgxii at argone\@empty\ocgxii at argtwo\else\ocgxii at argone\fi%
+        }{%
+          \ifx\ocgxii at argone\@empty\ocgxii at argtwo\else\ocgxii at 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 at argone\@empty\ocgxii at argtwo\else{\ocgxii at 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 at argone{#1}%ocg ref for checkmark
+        \ocgxii at trmspc\ocgxii at argone%
+        \global\let\ocgxii at argone\ocgxii at argone%
+        %default ocg ref for checkmark, if nothing provided in #1
+        \xdef\ocgxii at argtwo{#2.mark}%
+        \xdef\ocgxii at argtwo{\ocgxii at cnvspc{\ocgxii at argtwo}}%
+        \begin{ocg}[showingui=false]{%
+          \ifx\ocgxii at argone\@empty\ocgxii at argtwo\else\ocgxii at argone\fi%
+        }{%
+          \ifx\ocgxii at argone\@empty\ocgxii at argtwo\else\ocgxii at 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 at argone\@empty\ocgxii at argtwo\else{\ocgxii at 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 at trigger%
+              \showocg*[\ocgxii at 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 at trigger%
+              \hideocg*[\ocgxii at 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 at trigger%
+              \actionsocg*[\ocgxii at trigger]{#1}{#2}{#3}{%
+                \tikz \useasboundingbox (p1) rectangle (p2);}%
+            \else%
+              \actionsocg*{#1}{#2}{#3}{%
+                \tikz \useasboundingbox (p1) rectangle (p2);}%
+            \fi%
+          };
       }
     }
   }



More information about the tex-live-commits mailing list