[NTG-context] [callbacks] proper registration, node subtypes
Hans Hagen
pragma at wxs.nl
Tue Jun 26 14:50:50 CEST 2012
On 26-6-2012 14:08, Philipp Gesang wrote:
> ···<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.)
it all depends on what callback you use ... you can try a finalizer
instead of a processor as processors normally are called once
-----------------------------------------------------------------
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
-----------------------------------------------------------------
More information about the ntg-context
mailing list