ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Number of pages by Lua of a figure to be inserted?
@ 2013-04-10 14:22 Procházka Lukáš Ing. - Pontex s. r. o.
  2013-04-10 15:38 ` Hans Hagen
  0 siblings, 1 reply; 3+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2013-04-10 14:22 UTC (permalink / raw)
  To: ConTeXt

Hello,

I need to identify number of pages by Lua of an image which is to be inserted.

The image can be of all various types supported by Ctx - e.g. .png, .pdf.

I've been using the following code so far (based on a mailing thread in the past):

----
function nOfPages(fn)
   local fig = figures.push{name = fn}
     local info = figures.identify()

     figures.check()

     local n = fig.used.pages
   figures.pop()

   return n
end
----

But the code above break Ctx in the case that the image doesn't exist.

I'd need to modify the solution somehow so to return 'nil' or 'false' (or a error message) in the case the file was not found.

How to do it?

TIA.

Best regards,

Lukas

(NB: Still "ConTeXt  ver: 2012.11.26 13:31 MKIV  fmt: 2012.11.27  int: english/english".)


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Number of pages by Lua of a figure to be inserted?
  2013-04-10 14:22 Number of pages by Lua of a figure to be inserted? Procházka Lukáš Ing. - Pontex s. r. o.
@ 2013-04-10 15:38 ` Hans Hagen
  2013-04-11  7:10   ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Hagen @ 2013-04-10 15:38 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 4/10/2013 4:22 PM, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
> Hello,
>
> I need to identify number of pages by Lua of an image which is to be
> inserted.
>
> The image can be of all various types supported by Ctx - e.g. .png, .pdf.
>
> I've been using the following code so far (based on a mailing thread in
> the past):
>
> ----
> function nOfPages(fn)
>    local fig = figures.push{name = fn}
>      local info = figures.identify()
>
>      figures.check()
>
>      local n = fig.used.pages

inspect(fig)

>    figures.pop()
>
>    return n
> end
> ----
>
> But the code above break Ctx in the case that the image doesn't exist.
>
> I'd need to modify the solution somehow so to return 'nil' or 'false'
> (or a error message) in the case the file was not found.
>
> How to do it?

there's a status table in fig

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Number of pages by Lua of a figure to be inserted?
  2013-04-10 15:38 ` Hans Hagen
@ 2013-04-11  7:10   ` Procházka Lukáš Ing. - Pontex s. r. o.
  0 siblings, 0 replies; 3+ messages in thread
From: Procházka Lukáš Ing. - Pontex s. r. o. @ 2013-04-11  7:10 UTC (permalink / raw)
  To: ConTeXt

[-- Attachment #1: Type: text/plain, Size: 1941 bytes --]

Hello,

thanks for the hint.

Could you please check my code?

The function is able to detect number of pages (tested with a .pdf, which works; I believe it will work with other figure formats, too).

When the file is not found, it doesn't break Ctx, which is good.

The problem is that once a file is not found, later calls to the function fail (means they return 'false'), too.
It seems like a figure being "hanging" somewhere or what; but I'm not able to find the bad place iin the code.

Note that the directory structure is:

t2.mkiv - file to be tested
T/Kn.pdf - file to be inserted (2 pages)

---- t2.mkiv
\startluacode
   nOfPages = function(fn)
     local n

     do
       local fig = figures.push{name = fn}
         local info = figures.identify()

--inspect(info)

         if info.status.status ~= 0 then
           figures.check() -- This may check all figures; I'm interested in the last figure only - any call improvement?

           n = fig.used.pages
         end

       figures.pop() -- I thought no figure should stay "hanging" due to this line
     end

     if not n then return false end

     return n
   end
\stopluacode

\starttext
   AAA

   \startluacode
     context(nOfPages("Kn.pdf") or "???") -- [1]
     -- When you comment the line above, later Ctx detects correctly 2 pages of 'Kn.pdf'.
   \stopluacode

   \setupexternalfigures[directory=T] % Find the 'Kn.pdf' in 'T/Kn.pdf'

   \startluacode
     context(nOfPages("Kn.pdf") or "???")
     -- Now, Ctx should find 'T/Kn.pdf' anyway and thus detect 2 pages of 'Kn.pdf'.
     -- This doesn't occure when [1] is on
   \stopluacode
\stoptext
----

Any idea?

TIA.

Best regards,

Lukas


-- 
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o.      [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 244 062 238
Fax: +420 244 461 038

[-- Attachment #2: t2.zip --]
[-- Type: application/zip, Size: 12850 bytes --]

[-- Attachment #3: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-11  7:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-10 14:22 Number of pages by Lua of a figure to be inserted? Procházka Lukáš Ing. - Pontex s. r. o.
2013-04-10 15:38 ` Hans Hagen
2013-04-11  7:10   ` Procházka Lukáš Ing. - Pontex s. r. o.

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).