summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/animate/animate.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-01-26 03:00:57 +0000
committerNorbert Preining <norbert@preining.info>2022-01-26 03:00:57 +0000
commitd36626add433e216b29d959884d3593baa216866 (patch)
tree66d46b20b551e605dfe8a3b1dc93889d388f9ce3 /macros/latex/contrib/animate/animate.sty
parent54e627ff3ae26ebf28688e2cf04b2ed9fb3a393b (diff)
CTAN sync 202201260300
Diffstat (limited to 'macros/latex/contrib/animate/animate.sty')
-rw-r--r--macros/latex/contrib/animate/animate.sty142
1 files changed, 81 insertions, 61 deletions
diff --git a/macros/latex/contrib/animate/animate.sty b/macros/latex/contrib/animate/animate.sty
index ff05e49d9c..fe5636586d 100644
--- a/macros/latex/contrib/animate/animate.sty
+++ b/macros/latex/contrib/animate/animate.sty
@@ -13,7 +13,7 @@
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
-\def\@anim@version{2022/01/21}
+\def\@anim@version{2022/01/25}
\ProvidesPackage{animate}
[\@anim@version\space PDF & SVG animations from files and inline graphics]
@@ -312,15 +312,15 @@
%helper macro that typesets graphics file into savebox
\if@anim@dvips
- \def\@anim@filebox#1#2{% dvips: no multi-page support
- \edef\@anim@curfile{[\@anim@gropts]{#1}}%
+ \def\@anim@filebox#1#2#3{% dvips: no multi-page support
+ \edef\@anim@curfile{[#3]{#1}}%
\global\setbox\@anim@box=\hbox{%
\expandafter\includegraphics\@anim@curfile}%
}
\else
%pdfTeX, LuaTeX, dvipdfmx, xetex, dvisvgm
- \def\@anim@filebox#1#2{%
- \edef\@anim@curfile{[\@anim@gropts,page=#2]{#1}}%
+ \def\@anim@filebox#1#2#3{%
+ \edef\@anim@curfile{[#3,page=#2]{#1}}%
\global\setbox\@anim@box=\hbox{%
\expandafter\includegraphics\@anim@curfile}%
}
@@ -346,37 +346,18 @@
}
%create Form XObject from graphics file
-\def\@anim@ximage#1#2#3#4{%#1:@anim@num, #2:@anim@curframe@zb, #3:filename,
- % #4: page number of multipage file
- \if@anim@dvisvgm%
- % with dvisvgm, final animation dims must be passed to includegraphics;
- % otherwise, final bbox of the document may be wrong, in particular in the
- % case of standalone animations with downscaled graphics
- \ifnum#2=\z@\relax%
- \@anim@filebox{#3}{#4}% store file in a box
- \@anim@scale\@anim@box% get final dimensions of animation widget
- %prevent later re-scaling
- \gdef\@anim@widtharg{\width}%
- \gdef\@anim@heightarg{\height}%
- \gdef\@anim@totheightarg{\totalheight}%
- \gdef\@anim@boxscale{\@ne}%
- %append final dims to inclusion opts, also used for the remaining files
- %of the current animation
- \xdef\@anim@gropts{\@anim@gropts%
- \ifx\@anim@gropts\@empty\else,\fi width=\@anim@animwidth%
- ,height=\@anim@animheight,totalheight=\@anim@animtotalheight}%
- \fi%
- \fi%
+\def\@anim@ximage#1#2#3#4#5{%#1:@anim@num, #2:@anim@curframe@zb, #3:filename,
+ % #4: page number of multipage file, #5 graphicx inclusion options
% fingerprint "<file chksum>.<page>.<graphicx opts>.<current document page>"
% of external graphics to prevent re-embedding
\edef\@anim@fingerprint{%
- \@anim@pdfmdfivesum{#3}.#4.\@anim@gropts%
+ \@anim@pdfmdfivesum{#3}.#4.#5%
\if@anim@dvisvgm.\@anim@abspage\fi%
}%
\edef\@anim@curxform{\@anim@getkeyval{xform:\@anim@fingerprint}}%
\ifthenelse{\equal{\@anim@curxform}{}}{%
% new "<file chksum>.<page>.<graphicx opts>"
- \@anim@filebox{#3}{#4}% store file in a box
+ \@anim@filebox{#3}{#4}{#5}% store file in a box
\@anim@newkey{natdims:\@anim@fingerprint}{%
{\the\wd\@anim@box}{\the\ht\@anim@box}{\the\dp\@anim@box}%
}%
@@ -408,6 +389,9 @@
\vrule width \z@ height \ht#3 depth \dp#3\hss}%
%determine final dims of animation widget
\@anim@scale{\@anim@measbox}%
+ \@anim@keytoaux{a#1.wdbp}{\strip@pt\dimexpr0.996264\dimexpr\@anim@animwidth}%
+ \@anim@keytoaux{a#1.htbp}{\strip@pt\dimexpr0.996264\dimexpr\@anim@animheight}%
+ \@anim@keytoaux{a#1.thtbp}{\strip@pt\dimexpr0.996264\dimexpr\@anim@animtotalheight}%
\fi%
%test if natural dimensions of the current frame differ from
%final widget size
@@ -476,32 +460,11 @@
\def\@anim@makeframe#1#2{%
%container box
\edef\@anim@tmpvar{\@anim@getkeyval{frmcontent@#2},}%
- \if@anim@dvisvgm%
- \global\setbox\@anim@box=\hbox to \@anim@animwidth{%
- \raise\@anim@animheight\hbox{%
- \special{dvisvgm:raw
- <g transform="translate({?x},{?y})"><svg overflow="hidden"
- width="\strip@pt\dimexpr0.996264\dimexpr\@anim@animwidth"
- height="\strip@pt\dimexpr0.996264\dimexpr\@anim@animtotalheight"
- viewBox="%
- {?x}
- {?(y-\strip@pt\dimexpr0.996264\dimexpr\@anim@animheight)}
- {?(\strip@pt\dimexpr0.996264\dimexpr\@anim@animwidth)}
- {?(\strip@pt\dimexpr0.996264\dimexpr\@anim@animtotalheight)}%
- ">%
- }%
- \vrule width \z@ height \@anim@animheight depth \@anim@animdepth%
- \expandafter\@anim@insertfrmcontent\@anim@tmpvar\@nil%
- \special{dvisvgm:raw </svg></g>}%
- }\hss%
- }%
- \else%
- \global\setbox\@anim@box=\hbox to \@anim@animwidth{%
- \vrule width \z@ height \@anim@animheight depth \@anim@animdepth%
- \expandafter\@anim@insertfrmcontent\@anim@tmpvar\@nil%
- \hss%
- }%
- \fi%
+ \global\setbox\@anim@box=\hbox to \@anim@animwidth{%
+ \vrule width \z@ height \@anim@animheight depth \@anim@animdepth%
+ \expandafter\@anim@insertfrmcontent\@anim@tmpvar\@nil%
+ \hss%
+ }%
%inside a `landscape' environment together with the icon and widget methods,
%the frame content needs to be rotated counter-clockwise by 90 deg
\ifnum\@anim@method>\@ne\else%
@@ -1487,6 +1450,11 @@
\@anim@getpagecount{\filename@area\filename@base}{\filename@ext}{%
\@anim@lastpage%
}%
+ \ifdefined\@anim@lastpage\else% double check multipage support
+ \setboolean{@anim@multipage}{false}%
+ \fi%
+ \fi%
+ \if@anim@multipage%
%we need it zero-based
\edef\@anim@lastpage{\the\numexpr\@anim@lastpage-\@ne\relax}%
\ifx\@anim@first\@empty%
@@ -1644,11 +1612,11 @@
\if@anim@draft%
\if@anim@multipage%
%store file in a box
- \@anim@filebox{\@anim@pathtofile}{\@anim@first}%
+ \@anim@filebox{\@anim@pathtofile}{\@anim@first}{\@anim@gropts}%
\else%
%get file name extension
\@anim@getpath{\@anim@base\@anim@first}{\@anim@ftype}%
- \@anim@filebox{\@anim@pathtofile}{1}%
+ \@anim@filebox{\@anim@pathtofile}{1}{\@anim@gropts}%
\fi%
\@anim@scale{\@anim@box}%
%draw draftbox according to dimensions of the first frame
@@ -1666,7 +1634,12 @@
\if@anim@export\if@anim@timeline%
\anim@export%
\fi\fi%
- %read all frames of the sequence
+ %make all frames of the sequence
+ \if@anim@dvisvgm\if@anim@timeline\else%
+ \ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@beginsvgclip{\the\@anim@num}%
+ \fi%
+ \fi\fi%
\loop\ifnum\@anim@curframe\@anim@relop\@anim@last\relax\else%
\if@anim@export\if@anim@timeline\else%
\anim@export%
@@ -1674,7 +1647,7 @@
\if@anim@multipage%
%embed graphics
\@anim@ximage{\the\@anim@num}{\the\@anim@curframe@zb}{%
- \@anim@pathtofile}{\the\@anim@curframe}%
+ \@anim@pathtofile}{\the\@anim@curframe}{\@anim@gropts}%
\else%
%get path to current file end its extension
\@anim@getpath{%
@@ -1682,7 +1655,7 @@
}{\@anim@ftype}%
%embed graphics
\@anim@ximage{\the\@anim@num}{\the\@anim@curframe@zb}{%
- \@anim@pathtofile}{1}%
+ \@anim@pathtofile}{1}{\@anim@gropts}%
\fi%
\if@anim@export\if@anim@timeline\else%
\endanim@export%
@@ -1690,12 +1663,25 @@
\global\advance\@anim@curframe by \@anim@every%
\global\advance\@anim@curframe@zb by \@ne%
\repeat%
+ \if@anim@dvisvgm\if@anim@timeline\else%
+ \ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@endsvgclip%
+ \fi%
+ \fi\fi%
\xdef\@anim@frames{\the\@anim@curframe@zb}% total number
\global\@anim@tmpcnt=\@anim@frames%
\global\advance\@anim@tmpcnt by -\@ne%
\xdef\@anim@maxframe{\the\@anim@tmpcnt}% highest frame index
%build timeline from optional timeline file
- \if@anim@timeline\@anim@buildtmln{\the\@anim@num}\fi%
+ \if@anim@timeline%
+ \if@anim@dvisvgm\ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@beginsvgclip{\the\@anim@num}%
+ \fi\fi%
+ \@anim@buildtmln{\the\@anim@num}%
+ \if@anim@dvisvgm\ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@endsvgclip%
+ \fi\fi%
+ \fi%
% if last frame used as poster, write frame num to aux file
\ifnum\@anim@poster=\@anim@mone\relax%
\@anim@keytoaux{a\the\@anim@num.poster}{\@anim@maxframe}%
@@ -2139,11 +2125,21 @@
\fi%
\let\newframe\@anim@@newframe%
\let\multiframe\@anim@multiframe%
+ \if@anim@dvisvgm\if@anim@timeline\else\if@anim@draft\else%
+ \ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@beginsvgclip{\the\@anim@num}%
+ \fi%
+ \fi\fi\fi%
\@anim@beginframe%
\ignorespaces%
}{%
\unskip%
\@anim@endframe{\the\@anim@num}{\the\@anim@curframe@zb}%
+ \if@anim@dvisvgm\if@anim@timeline\else\if@anim@draft\else%
+ \ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@endsvgclip%
+ \fi%
+ \fi\fi\fi%
\global\advance\@anim@curframe@zb by \@ne%
\if@anim@draft\else%
\xdef\@anim@frames{\the\@anim@curframe@zb}% total number
@@ -2151,7 +2147,15 @@
\global\advance\@anim@tmpcnt by -\@ne%
\xdef\@anim@maxframe{\the\@anim@tmpcnt}% highest frame index
%build timeline from optional timeline file
- \if@anim@timeline\@anim@buildtmln{\the\@anim@num}\fi%
+ \if@anim@timeline%
+ \if@anim@dvisvgm\ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@beginsvgclip{\the\@anim@num}%
+ \fi\fi%
+ \@anim@buildtmln{\the\@anim@num}%
+ \if@anim@dvisvgm\ifcsname a\the\@anim@num.htbp\endcsname%
+ \@anim@endsvgclip%
+ \fi\fi%
+ \fi%
%insert animation widget & controls
\if@anim@export\else%
% insert <script> part
@@ -2176,6 +2180,22 @@
\let\@anim@animateinline\animateinline
\def\animateinline{\@anim@sanitizeColon\@anim@animateinline}
+% clip animation to final dimensions (dvisvgm)
+\def\@anim@beginsvgclip#1{%
+ \special{dvisvgm:raw
+ <g transform="translate({?x},{?(y-\@anim@getkeyval{a#1.htbp})})">%
+ <svg overflow="hidden"
+ width="\@anim@getkeyval{a#1.wdbp}" height="\@anim@getkeyval{a#1.thtbp}"
+ viewBox="%
+ {?x} {?(y-\@anim@getkeyval{a#1.htbp})}
+ \@anim@getkeyval{a#1.wdbp} \@anim@getkeyval{a#1.thtbp}%
+ ">%
+ }%
+}%
+\def\@anim@endsvgclip{%
+ \special{dvisvgm:raw </svg></g>}%
+}
+
%usercommand for use within `animateinline' environment;
%terminates the current frame and starts a new one
\def\@anim@@newframe{% aliased to \newframe inside `animateinline'