ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Michal Vlasák via ntg-context" <ntg-context@ntg.nl>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>
Cc: "Michal Vlasák" <lahcim8@gmail.com>, "Pablo Rodriguez" <oinos@gmx.es>
Subject: Re: JavaScript in multimedia PDF
Date: Wed, 11 Aug 2021 22:40:17 +0200	[thread overview]
Message-ID: <CDGZ2Q1BM5SO.3T9VIY7VOUV99@phobos> (raw)
In-Reply-To: <0a0debc8-9175-245e-2a5f-04c63869f11f@gmx.es>

More context is in previous messages, but here is the patch for ConTeXt
to make scripting multimedia possible:

    --- a/tex/context/base/mkxl/lpdf-wid.lmt
    +++ b/tex/context/base/mkxl/lpdf-wid.lmt
    @@ -649,6 +649,7 @@ local function insertrenderingwindow(specification)
             Subtype = pdfconstant("Screen"),
             P       = pdfreference(pdfpagereference(page)),
             A       = a, -- needed in order to make the annotation clickable (i.e. don't bark)
    +        T       = pdfunicode(label), -- title (for JS)
             Border  = bs,
             C       = bc,
             AA      = actions,
    @@ -693,7 +694,7 @@ local function insertrendering(specification)
          --     }
          -- }
             local parameters = pdfdictionary {
    -            Type = pdfconstant(MediaPermissions),
    +            Type = pdfconstant("MediaPermissions"),
                 TF   = pdfstring("TEMPALWAYS"), -- TEMPNEVER TEMPEXTRACT TEMPACCESS TEMPALWAYS / needed for acrobat/wmp
             }
             local descriptor = pdfdictionary {
    @@ -723,7 +724,7 @@ local function insertrendering(specification)
             local rendition = pdfdictionary {
                 Type = pdfconstant("Rendition"),
                 S    = pdfconstant("MR"),
    -            N    = label,
    +            N    = pdfunicode(label),
                 C    = pdfreference(pdfflushobject(clip)),
             }
             mf[label] = pdfreference(pdfflushobject(rendition))
    @@ -761,6 +762,20 @@ function codeinjections.processrendering(label)
         end
     end
    
    +-- needed mapping for access from JS
    +local function flushrenderings()
    +    if next(mf) then
    +        local r = pdfarray()
    +        for label, reference in sortedhash(mf) do
    +            r[#r+1] = pdfunicode(label)
    +            r[#r+1] = reference -- already a reference
    +        end
    +        lpdf.addtonames("Renditions",pdfreference(pdfflushobject(pdfdictionary{ Names = r })))
    +    end
    +end
    +
    +lpdf.registerdocumentfinalizer(flushrenderings,"renderings")
    +
     function codeinjections.insertrenderingwindow(specification)
         local label = specification.label
         codeinjections.processrendering(label)

The patch is also be available here
https://github.com/vlasakm/context-mirror/commit/99f81beae0d13f1aecc20be187ada9eb88a2aa68
until it is applied (for full file download, which is available under
the three dots next to the file name).

The created Screen annotation will be given the title, that corresponds
to the second \placerenderingwindow parameter. So here:

    \definerenderingwindow[soundplace]
      [width=0pt, height=0pt]
    
    \useexternalrendering[mainsound][audio/mp3][sound.mp3][embed=yes]
    
    \placerenderingwindow[soundplace][mainsound]

both the screen annotation and rendition are available under the name
"mainsound". The name "soundplace" can be anything (even "mainsound"),
it doesn't propagate to the PDF file in any way.

And here is the patch required to make Pablo's example work:

    --- a/pablo.tex
    +++ b/pablo.tex
    @@ -7,8 +7,10 @@
     function GoToFirstSlide(label) {
     this.pageNum = 0 ;
     var rendition = this.media.getRendition(label) ;
    +var screen = this.media.getAnnot({nPage: 0, cAnnotTitle: label}) ;
     var player = app.media.openPlayer({
         rendition: rendition,
    +    annot: screen,
       });
     }

The second possibility I proposed previously is not as general, and
implementing it is not worth, until it is really needed (which I presume
won't happen).

Michal Vlasák
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2021-08-11 20:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08 18:22 Pablo Rodriguez via ntg-context
2021-08-08 21:00 ` Michal Vlasák via ntg-context
2021-08-09  6:32   ` Pablo Rodriguez via ntg-context
2021-08-10 21:52     ` Michal Vlasák via ntg-context
2021-08-11 13:59       ` Pablo Rodriguez via ntg-context
2021-08-11 20:40         ` Michal Vlasák via ntg-context [this message]
2021-08-11 22:55           ` Hans Hagen via ntg-context
2021-08-12  1:02             ` Michal Vlasák via ntg-context
2021-08-12 14:36               ` Pablo Rodriguez via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CDGZ2Q1BM5SO.3T9VIY7VOUV99@phobos \
    --to=ntg-context@ntg.nl \
    --cc=lahcim8@gmail.com \
    --cc=oinos@gmx.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).