···<date: 2012-06-26, Tuesday>···<from: Hans Hagen>···

> On 25-6-2012 16:50, Philipp Gesang wrote:
> >···<date: 2012-06-25, Monday>···<from: Hans Hagen>···
> >
> >>On 25-6-2012 15:39, Philipp Gesang wrote:
> >>
> >>>   - Does the difference wrt node subtype matter assuming I only
> >>>     (a) copy glyph nodes and (b) manipulate their .char field?
> >>
> >>not that much, it's just a state signal for font processing
> >
> >Good to know.
> >
> >>>Any insights on this matter would be greatly appreciated. Regards
> >>>Philipp
> >>
> >>it all depends on what you want to do
> >
> >Traverse the node list of a paragraph before line break from head
> >to tail in sequential order, recursing into sublists where they
> >appear. The callback removes and inserts nodes: which ones
> >depends on the nodes already processed (has a state).
> >
> >Using the previous example code,
> >
> >   \startfoo
> >     a\hbox{b}c
> >   \stopfoo
> >
> >should result in the traversal <glyph a>, <hlist ...>, <glyph c>.
> 
> \starttext
> 
> \startluacode
> 
> local function processnestedlist(head,n)
>     local current, done = head, false
>     while current do
>         local id = current.id
>         if id == nodes.nodecodes.hlist or id == nodes.nodecodes.vlist then
>             local _, d = processnestedlist(current.list,n)
>             if d then
>                 done = true
>             end
>         elseif id == nodes.nodecodes.hglue_code and current.leader then
>             local _, d = processnestedlist(current.leader,n)
>             if d then
>                 done = true
>             end
>         elseif id == nodes.nodecodes.glyph then -- todo: dics nodes
>             n = n + 1
>             print(n,utf.char(current.char))
>         end
>         current = current.next
>     end
>     return head, done, n
> end
> 
> 
> thirddata      = thirddata      or {}
> thirddata.test = thirddata.test or { }
> 
> thirddata.test.one = function(head)
>     local head, done, n = processnestedlist(head,0)
>     print("n of glyphs",n)
>     return head, done
> end
> 
> nodes.tasks.appendaction ("processors","before","thirddata.test.one")
> 
> \stopluacode
> 
> \ruledhbox to 10cm {\strut hello \ruledhbox{brave new} world
> \cleaders\hbox{!}\hfil}
> 
> \stoptext

First of all, thanks for the snippet. It’s insightful already wrt
to the fact that nodes.installattributehandler is considered
unnecessary. But the problem persists. With the code

  a\hbox{b}c

I get the following output:

  1   b
  n of glyphs 1
  1   a
  2   b
  2   c
  n of glyphs 2

So the sequence is <char b>, <char a>, <char b>, <char c> where
it should be <char a>, <char b>, <char c> --- the hbox is still
processed first, which I was attempting to avoid. (Also, the
invisible string “context” follows if the callback is active
until the end of file.)

Regards
Philipp


> 
> -----------------------------------------------------------------
>                                           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
> ___________________________________________________________________________________

-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

Attachment: pgp6BMUpkkmdU.pgp
Description: PGP signature

___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to